1 /*
2 * Copyright (c) 2021-2024, 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_vvc_pipeline.h
24 //! \brief    Defines the interface for vvc decode pipeline
25 //!
26 #ifndef __DECODE_VVC_PIPELINE_H__
27 #define __DECODE_VVC_PIPELINE_H__
28 
29 #include "decode_pipeline.h"
30 #include "codec_def_decode_vvc.h"
31 #include "decode_vvc_basic_feature.h"
32 #include "media_cmd_packet.h"
33 #include "media_debug_utils.h"
34 
35 namespace decode
36 {
37     class VvcDecodePkt;
38     class VvcPipeline : public DecodePipeline
39     {
40     public:
41         //!
42         //! \brief  DecodePipeline constructor
43         //! \param  [in] hwInterface
44         //!         Pointer to CodechalHwInterface
45         //! \param  [in] debugInterface
46         //!         Pointer to CodechalDebugInterface
47         //!
48         VvcPipeline(
49             CodechalHwInterfaceNext *   hwInterface,
50             CodechalDebugInterface *debugInterface);
51 
~VvcPipeline()52         virtual ~VvcPipeline() {}
53 
54         //!
55         //! \brief  Prepare interal parameters, should be invoked for each frame
56         //! \param  [in] params
57         //!         Pointer to the input parameters
58         //! \return MOS_STATUS
59         //!         MOS_STATUS_SUCCESS if success, else fail reason
60         //!
61         virtual MOS_STATUS Prepare(void *params) final;
62 
63         //!
64         //! \brief  Finish the execution for each frame
65         //! \return MOS_STATUS
66         //!         MOS_STATUS_SUCCESS if success, else fail reason
67         //!
68         virtual MOS_STATUS Execute() final;
69 
70         virtual MOS_STATUS GetStatusReport(void *status, uint16_t numStatus) override;
71 
72         uint32_t GetCompletedReport();
73 
74         virtual MOS_STATUS Destroy() override;
75 
76         MHW_BATCH_BUFFER *GetSliceLvlCmdBuffer();
77 
78         PMHW_BATCH_BUFFER GetTileLvlCmdBuffer();
GetSliceLvlBufSize()79         uint32_t          GetSliceLvlBufSize() { return m_sliceLvlBufSize; }
GetTileLvlBufSize()80         uint32_t          GetTileLvlBufSize() { return m_tileLvlBufSize; }
81 
82         DeclareDecodePacketId(vvcDecodePacketId);
83         DeclareDecodePacketId(vvcDecodeS2LPktId);
84         DeclareDecodePacketId(vvcPictureSubPacketId);
85         DeclareDecodePacketId(vvcSliceSubPacketId);
86         DeclareDecodePacketId(vvcCpSubPacketId);
87 
88     protected:
89         virtual MOS_STATUS Initialize(void *settings) override;
90         virtual MOS_STATUS Uninitialize() override;
91 
92         //!
93         //! \brief  User Feature Key Report
94         //! \return MOS_STATUS
95         //!         MOS_STATUS_SUCCESS if success, else fail reason
96         //!
97         virtual MOS_STATUS UserFeatureReport() override;
98 
99         //!
100         //! \brief  Create sub packets
101         //! \param  [in] codecSettings
102         //!         Codechal settings
103         //! \return MOS_STATUS
104         //!         MOS_STATUS_SUCCESS if success, else fail reason
105         //!
106         virtual MOS_STATUS CreateSubPackets(DecodeSubPacketManager& subPacketManager, CodechalSetting &codecSettings) override;
107 
108         //!
109         //! \brief  Initialize media context for decode pipeline
110         //! \return MOS_STATUS
111         //!         MOS_STATUS_SUCCESS if success, else fail reason
112         //!
113         MOS_STATUS InitContext();
114 
115         //!
116         //! \brief    Initialize MMC state
117         //!
118         //! \return   MOS_STATUS
119         //!           MOS_STATUS_SUCCESS if success
120         //!
121         virtual MOS_STATUS InitMmcState();
122 
123 
124     #if USE_CODECHAL_DEBUG_TOOL
125         //! \brief    Dump the parameters
126         //!
127         //! \return   MOS_STATUS
128         //!           MOS_STATUS_SUCCESS if success, else fail reason
129         //!
130         MOS_STATUS DumpParams(VvcBasicFeature &basicFeature);
131 
132         //! \brief    Dump the picture parameters
133         //!
134         //! \param    [in] picParams
135         //!           Pointer to CodecVvcPicParams
136         //!
137         //! \return   MOS_STATUS
138         //!           MOS_STATUS_SUCCESS if success, else fail reason
139         //!
140         MOS_STATUS DumpPicParams(
141             CodecVvcPicParams *picParams,
142             bool shortFormatInUse);
143 
144         //! \brief    Dump the APS ALF parameters
145         //!
146         //! \param    [in] alfDataBuf
147         //!           Pointer to an array of CodecVvcAlfData
148         //! \param    [in] numAlf
149         //!           Number of ALF
150         //!
151         //! \return   MOS_STATUS
152         //!           MOS_STATUS_SUCCESS if success, else fail reason
153         //!
154         MOS_STATUS DumpApsAlfData(
155             CodecVvcAlfData *alfDataBuf,
156             uint32_t        numAlf);
157 
158         //! \brief    Dump the APS ALF parameters
159         //!
160         //! \param    [in] lmcsDataBuf
161         //!           Pointer to an array of CodecVvcLmcsData
162         //! \param    [in] numLmcs
163         //!           Number of LMCS
164         //!
165         //! \return   MOS_STATUS
166         //!           MOS_STATUS_SUCCESS if success, else fail reason
167         //!
168         MOS_STATUS DumpApsLmcsData(
169             CodecVvcLmcsData *lmcsDataBuf,
170             uint32_t         numLmcs);
171 
172         //! \brief    Dump the APS quant matrix parameters
173         //!
174         //! \param    [in] quantMatrixBuf
175         //!           Pointer to an array of CodecVvcQmData
176         //! \param    [in] numScalingList
177         //!           Number of scaling list
178         //!
179         //! \return   MOS_STATUS
180         //!           MOS_STATUS_SUCCESS if success, else fail reason
181         //!
182         MOS_STATUS DumpApsQuantMatrix(
183             CodecVvcQmData *quantMatrixBuf,
184             uint32_t       numScalingList);
185 
186         //! \brief    Dump the tile parameters
187         //!
188         //! \param    [in] tileParams
189         //!           Pointer to an array of CodecVvcTileParam
190         //! \param    [in] numElements
191         //!           Number of dimention value
192         //!
193         //! \return   MOS_STATUS
194         //!           MOS_STATUS_SUCCESS if success, else fail reason
195         //!
196         MOS_STATUS DumpTileParams(
197             CodecVvcTileParam *tileParams,
198             uint32_t          numElements);
199 
200         //! \brief    Dump the subpic parameters
201         //!
202         //! \param    [in] subpicParamsBuf
203         //!           Pointer to an array of CodecVvcSubpicParam
204         //! \param    [in] numSubpics
205         //!           Number of subpics
206         //!
207         //! \return   MOS_STATUS
208         //!           MOS_STATUS_SUCCESS if success, else fail reason
209         //!
210         MOS_STATUS DumpSubpicParams(
211             CodecVvcSubpicParam *subpicParamsBuf,
212             uint32_t            numSubpics);
213 
214         //! \brief    Dump the slice parameters
215         //!
216         //! \param    [in] sliceStructParamsBuf
217         //!           Pointer to an array of CodecVvcSliceStructure
218         //! \param    [in] numSlcStruct
219         //!           Number of slice structs
220         //!
221         //! \return   MOS_STATUS
222         //!           MOS_STATUS_SUCCESS if success, else fail reason
223         //!
224         MOS_STATUS DumpSliceStructParams(
225             CodecVvcSliceStructure *sliceStructParamsBuf,
226             uint32_t               numSlcStruct);
227 
228         //! \brief    Dump the RPL parameters
229         //!
230         //! \param    [in] rplParams
231         //!           Pointer to an array of CodecVvcRplStructure
232         //! \param    [in] numRpls
233         //!           Number of RPLs
234         //!
235         //! \return   MOS_STATUS
236         //!           MOS_STATUS_SUCCESS if success, else fail reason
237         //!
238         MOS_STATUS DumpRplStructParams(
239             CodecVvcRplStructure *rplParams,
240             uint32_t             numRpls,
241             bool                 shortFormatInUse);
242 
243         //! \brief    Dump the slice control parameters
244         //!
245         //! \param    [in] sliceParams
246         //!           Pointer to an array of CodecVvcSliceParams
247         //! \param    [in] numSlices
248         //!           Number of slices
249         //! \param    [in] shortFormatInUse
250         //!           short format flag
251         //!
252         //! \return   MOS_STATUS
253         //!           MOS_STATUS_SUCCESS if success, else fail reason
254         //!
255         MOS_STATUS DumpSliceParams(
256             CodecVvcSliceParams* sliceParams,
257             uint32_t             numSlices,
258             bool                 shortFormatInUse);
259     #endif
260 
261         //!
262         //! \brief  Active decode packets
263         //! \return MOS_STATUS
264         //!         MOS_STATUS_SUCCESS if success, else fail reason
265         //!
266         MOS_STATUS ActivateDecodePackets();
267 
268         //!
269         //! \brief  Create VVC Decode feature manager for Gen12
270         //! \return MOS_STATUS
271         //!         MOS_STATUS_SUCCESS if success, else fail reason
272         //!
273         MOS_STATUS CreateFeatureManager() override;
274 
275         MOS_STATUS AllocateResources(VvcBasicFeature &basicFeature);
276 
277 
278 
279     private:
280         CodechalHwInterfaceNext* m_hwInterface = nullptr;
281 
282 
283     protected:
284         VvcBasicFeature *m_basicFeature = nullptr;              //!< VVC Basic Feature
285         uint16_t        m_passNum          = 1;                 //!< Decode pass number
286         bool            m_isFirstSliceInFrm = true;             //!< First tile in the first frame
287         BatchBufferArray *m_sliceLevelBBArray = nullptr;        //!< Point to slice level batch buffer
288         BatchBufferArray *m_tileLevelBBArray  = nullptr;          //!< Pointer to third level batch buffer
289         uint32_t          m_sliceLvlBufSize   = 0;
290         uint32_t          m_tileLvlBufSize    = 0;
291         VvcDecodePkt     *m_vvcDecodePkt      = nullptr;  //!< VVC decode packet
292         CmdPacket        *m_vvcDecodeS2LPkt   = nullptr;  //!< VVC decode S2L packet
293 
294     MEDIA_CLASS_DEFINE_END(decode__VvcPipeline)
295     };
296 
297 #if USE_CODECHAL_DEBUG_TOOL
298     void DumpDecodeVvcPicParams(CodecVvcPicParams *picParams, std::string fileName, bool shortFormatInUse);
299     void DumpDecodeVvcAlfParams(CodecVvcAlfData *alfDataBuf, uint32_t numAlf, std::string fileName);
300     void DumpDecodeVvcLmcsParams(CodecVvcLmcsData *lmcsDataBuf, uint32_t numLmcs, std::string fileName);
301     void DumpDecodeVvcIqParams(CodecVvcQmData *quantMatrixBuf, uint32_t numScalingList, std::string fileName);
302     void DumpDecodeVvcTileParams(CodecVvcTileParam *tileParams, uint32_t numElements, std::string fileName);
303     void DumpDecodeVvcSubpicParams(CodecVvcSubpicParam *subpicParamsBuf, uint32_t numSubpics, std::string fileName);
304     void DumpDecodeVvcSliceStructureParams(CodecVvcSliceStructure *sliceStructParamsBuf, uint32_t numSlcStruct, std::string fileName);
305     void DumpDecodeVvcRplStructureParams(CodecVvcRplStructure *rplParams, uint32_t numRpls, std::string fileName);
306     void DumpDecodeVvcSliceParams(CodecVvcSliceParams *sliceParams, uint32_t numSlices, std::string fileName, bool shortFormatInUse);
307 #endif
308 }
309 #endif // !__DECODE_VVC_PIPELINE_H__
310