1 /*
2 * Copyright (c) 2021, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     decode_huc_s2l_packet.h
24 //! \brief    Defines the implementation of huc S2L packet
25 //!
26 
27 #ifndef __DECODE_HUC_S2L_PACKET_H__
28 #define __DECODE_HUC_S2L_PACKET_H__
29 
30 #include "media_cmd_packet.h"
31 #include "decode_huc.h"
32 #include "media_pipeline.h"
33 #include "codec_hw_next.h"
34 #include "decode_utils.h"
35 #include "decode_hevc_pipeline.h"
36 #include "decode_hevc_basic_feature.h"
37 
38 #include "mhw_vdbox_huc_cmdpar.h"
39 #include "mhw_vdbox_huc_itf.h"
40 #include "mhw_cmdpar.h"
41 
42 namespace decode
43 {
44     struct HucHevcS2lPicBss
45     {
46         uint32_t    pic_width_in_min_cbs_y;
47         uint32_t    pic_height_in_min_cbs_y;
48         uint8_t     log2_min_luma_coding_block_size_minus3;
49         uint8_t     log2_diff_max_min_luma_coding_block_size;
50         uint16_t    chroma_format_idc                           : 2;  //!< range 0..3
51         uint16_t    separate_colour_plane_flag                  : 1;
52         uint16_t    bit_depth_luma_minus8                       : 4;
53         uint16_t    bit_depth_chroma_minus8                     : 4;
54         uint16_t    log2_max_pic_order_cnt_lsb_minus4           : 4;  //!< range 0..12
55         uint16_t    sample_adaptive_offset_enabled_flag         : 1;
56         uint8_t     num_short_term_ref_pic_sets;                      //!< range 0..64
57         uint8_t     long_term_ref_pics_present_flag             : 1;
58         uint8_t     num_long_term_ref_pics_sps                  : 6;  //!< range 0..32
59         uint8_t     sps_temporal_mvp_enable_flag                : 1;
60 
61         uint8_t     num_ref_idx_l0_default_active_minus1        : 4;  //!< range 0..15
62         uint8_t     num_ref_idx_l1_default_active_minus1        : 4;  //!< range 0..15
63         int8_t      pic_init_qp_minus26;                              //!< range -62..25
64         uint8_t     dependent_slice_segments_enabled_flag       : 1;
65         uint8_t     cabac_init_present_flag                     : 1;
66         uint8_t     pps_slice_chroma_qp_offsets_present_flag    : 1;
67         uint8_t     weighted_pred_flag                          : 1;
68         uint8_t     weighted_bipred_flag                        : 1;
69         uint8_t     output_flag_present_flag                    : 1;
70         uint8_t     tiles_enabled_flag                          : 1;
71         uint8_t     entropy_coding_sync_enabled_flag            : 1;
72         uint8_t     loop_filter_across_slices_enabled_flag      : 1;
73         uint8_t     deblocking_filter_override_enabled_flag     : 1;
74         uint8_t     pic_disable_deblocking_filter_flag          : 1;
75         uint8_t     lists_modification_present_flag             : 1;
76         uint8_t     slice_segment_header_extension_present_flag : 1;
77         uint8_t     high_precision_offsets_enabled_flag         : 1;
78         uint8_t     chroma_qp_offset_list_enabled_flag          : 1;
79         uint8_t                                                 : 1;
80 
81         int32_t     CurrPicOrderCntVal;
82         int32_t     PicOrderCntValList[CODEC_MAX_NUM_REF_FRAME_HEVC];
83         uint8_t     RefPicSetStCurrBefore[8];
84         uint8_t     RefPicSetStCurrAfter[8];
85         uint8_t     RefPicSetLtCurr[8];
86         uint16_t    RefFieldPicFlag;
87         uint16_t    RefBottomFieldFlag;
88         int8_t      pps_beta_offset_div2;
89         int8_t      pps_tc_offset_div2;
90         uint16_t    StRPSBits;
91 
92         uint8_t     num_tile_columns_minus1;
93         uint8_t     num_tile_rows_minus1;
94         uint16_t    column_width[HEVC_NUM_MAX_TILE_COLUMN];
95         uint16_t    row_height[HEVC_NUM_MAX_TILE_ROW];
96 
97         uint16_t    NumSlices;
98         uint8_t     num_extra_slice_header_bits;
99         int8_t      RefIdxMapping[CODEC_MAX_NUM_REF_FRAME_HEVC];
100 
101         struct
102         {
103             uint8_t     reserve_0;
104             uint16_t    reserve_1;
105             uint32_t    reserve_2;
106             uint32_t    reserve_3;
107         } reserve;
108     };
109 
110     struct HucHevcS2lSliceBss
111     {
112         uint32_t    BSNALunitDataLocation;
113         uint32_t    SliceBytesInBuffer;
114 
115         struct
116         {
117             uint32_t    reserve_0;
118             uint32_t    reserve_1;
119             uint32_t    reserve_2;
120             uint32_t    reserve_3;
121         } reserve;
122     };
123 
124     class HucS2lPkt : public DecodeHucBasic, public mhw::vdbox::huc::Itf::ParSetting
125     {
126     public:
HucS2lPkt(MediaPipeline * pipeline,MediaTask * task,CodechalHwInterfaceNext * hwInterface)127         HucS2lPkt(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterfaceNext*hwInterface)
128             : DecodeHucBasic(pipeline, task, hwInterface)
129         {
130             if (pipeline != nullptr)
131             {
132                 m_statusReport = pipeline->GetStatusReportInstance();
133                 m_hevcPipeline = dynamic_cast<HevcPipeline *>(pipeline);
134             }
135         }
136 
~HucS2lPkt()137         virtual ~HucS2lPkt() {}
138 
139         //!
140         //! \brief  Initialize the media packet, allocate required resources
141         //! \return MOS_STATUS
142         //!         MOS_STATUS_SUCCESS if success, else fail reason
143         //!
144         virtual MOS_STATUS Init() override;
145 
146         //!
147         //! \brief  Prepare interal parameters, should be invoked for each frame
148         //! \return MOS_STATUS
149         //!         MOS_STATUS_SUCCESS if success, else fail reason
150         //!
151         virtual MOS_STATUS Prepare() override;
152 
153         //!
154         //! \brief  destroy interal resource, should be invoked for each frame
155         //! \return MOS_STATUS
156         //!         MOS_STATUS_SUCCESS if success, else fail reason
157         //!
158         virtual MOS_STATUS FreeResource();
159 
160         virtual MOS_STATUS Destroy() override;
161 
162         //!
163         //! \brief  Calculate Command Size
164         //!
165         //! \param  [in, out] commandBufferSize
166         //!         requested size
167         //! \param  [in, out] requestedPatchListSize
168         //!         requested size
169         //! \return MOS_STATUS
170         //!         status
171         //!
172         virtual MOS_STATUS CalculateCommandSize(
173             uint32_t &commandBufferSize,
174             uint32_t &requestedPatchListSize) override;
175 
176         //!
177         //! \brief  Get Packet Name
178         //! \return std::string
179         //!
GetPacketName()180         virtual std::string GetPacketName() override
181         {
182             return "S2L";
183         }
184 
185         virtual MHW_SETPAR_DECL_HDR(HUC_DMEM_STATE);
186         virtual MHW_SETPAR_DECL_HDR(HUC_IND_OBJ_BASE_ADDR_STATE);
187         virtual MHW_SETPAR_DECL_HDR(HUC_VIRTUAL_ADDR_STATE);
188 
189         virtual MOS_STATUS AddCmd_HUC_STREAM_OBJECT(MOS_COMMAND_BUFFER &cmdBuffer, CODEC_HEVC_SLICE_PARAMS sliceParams);
190         virtual MOS_STATUS AddCmd_HUC_START(MOS_COMMAND_BUFFER &cmdBuffer, bool laststreamobject);
191         virtual MOS_STATUS AddCmd_HUC_PIPE_MODE_SELECT(MOS_COMMAND_BUFFER &cmdBuffer);
192         virtual MOS_STATUS AddCmd_HUC_IMEM_STATE(MOS_COMMAND_BUFFER &cmdBuffer);
193 
194     protected:
195         //!
196         //! \brief  Calculate Command Buffer Size
197         //!
198         //! \return uint32_t
199         //!         Command buffer size calculated
200         //!
201         virtual uint32_t CalculateCommandBufferSize();
202 
203         //!
204         //! \brief  Calculate Patch List Size
205         //!
206         //! \return uint32_t
207         //!         Patchlist size calculated
208         //!
209         virtual uint32_t CalculatePatchListSize();
210 
211         virtual MOS_STATUS SetHucDmemPictureBss(HucHevcS2lPicBss &hucHevcS2LPicBss);
212         virtual MOS_STATUS SetHucDmemSliceBss(
213             HucHevcS2lSliceBss (&hucHevcS2LSliceBss)[CODECHAL_HEVC_MAX_NUM_SLICES_LVL_6]);
214         MOS_STATUS AddHucCpState(MOS_COMMAND_BUFFER &cmdBuffer, uint32_t index, CODEC_HEVC_SLICE_PARAMS &sliceParams);
215 
216 #if USE_CODECHAL_DEBUG_TOOL
217         virtual MOS_STATUS DumpHucS2l();
218 #endif
219 
220         static constexpr uint32_t m_vdboxHucHevcS2lKernelDescriptor = 1; //!< Huc HEVC S2L kernel descriptor
221 
222         HevcPipeline *             m_hevcPipeline      = nullptr; //!< Pointer to hevc pipeline
223         HevcBasicFeature *         m_hevcBasicFeature  = nullptr; //!< Pointer to hevc basic feature
224         PCODEC_HEVC_PIC_PARAMS     m_hevcPicParams     = nullptr; //!< Pointer to picture parameter
225         PCODEC_HEVC_EXT_PIC_PARAMS m_hevcRextPicParams = nullptr; //!< Extended pic params for Rext
226         PCODEC_HEVC_SLICE_PARAMS   m_hevcSliceParams   = nullptr; //!< Pointer to slice parameter
227         PCODEC_HEVC_SCC_PIC_PARAMS m_hevcSccPicParams  = nullptr; //!< Pic params for SCC
228 
229         MOS_BUFFER*                m_s2lDmemBuffer     = nullptr; //!< Resource of current DMEM buffer
230         MOS_BUFFER*                m_s2lControlTempMVRegionBuffer = nullptr;  //!< Point to RegionBuffer which controls temporal MV Buffer
231         uint32_t                   m_dmemBufferSize    = 0;       //!< Size of DMEM buffer
232         uint32_t                   m_dmemTransferSize  = 0;       //!< Transfer size of current DMEM buffer
233 
234         uint32_t                   m_pictureStatesSize    = 0;
235         uint32_t                   m_picturePatchListSize = 0;
236         uint32_t                   m_sliceStatesSize      = 0;
237         uint32_t                   m_slicePatchListSize   = 0;
238 
239         MEDIA_CLASS_DEFINE_END(decode__HucS2lPkt)
240     };
241 
242 }  // namespace decode
243 #endif
244