1 /*
2 * Copyright (c) 2020, 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     mhw_vdbox_avp_interface.h
24 //! \brief    MHW interface for constructing AVP commands for the Vdbox engine
25 //! \details  Defines the interfaces for constructing MHW Vdbox AVP commands across all platforms
26 //!
27 
28 #ifndef _MHW_VDBOX_AVP_INTERFACE_H_
29 #define _MHW_VDBOX_AVP_INTERFACE_H_
30 
31 #include "mhw_vdbox.h"
32 #include "mhw_mi.h"
33 #include "codec_def_decode_av1.h"
34 
35 struct MhwVdboxAvpTileCodingParams
36 {
37     uint16_t                        m_tileId;
38     uint16_t                        m_tgTileNum;  //!< Tile ID in its Tile group
39     uint16_t                        m_tileGroupId;
40 
41     uint16_t                        m_tileColPositionInSb;
42     uint16_t                        m_tileRowPositionInSb;
43 
44     uint16_t                        m_tileWidthInSbMinus1;              //!< Tile width minus 1 in SB unit
45     uint16_t                        m_tileHeightInSbMinus1;             //!< Tile height minus 1 in SB unit
46 
47     bool                            m_tileRowIndependentFlag;
48     bool                            m_firstTileInAFrame;
49     bool                            m_isLastTileOfColumn;
50     bool                            m_isLastTileOfRow;
51     bool                            m_isFirstTileOfTileGroup;
52     bool                            m_isLastTileOfTileGroup;
53     bool                            m_isLastTileOfFrame;
54     bool                            m_disableCdfUpdateFlag;
55     bool                            m_disableFrameContextUpdateFlag;
56 
57     uint8_t                         m_numOfActiveBePipes;
58     uint16_t                        m_numOfTileColumnsInFrame;
59     uint16_t                        m_numOfTileRowsInFrame;
60     uint16_t                        m_outputDecodedTileColumnPositionInSBUnit;
61     uint16_t                        m_outputDecodedTileRowPositionInSBUnit;
62 };
63 
64 struct MhwVdboxAvpPicStateParams
65 {
66     // Decode
67     CodecAv1PicParams               *m_picParams;
68     PCODEC_REF_LIST_AV1             *m_refList;
69 
70     union
71     {
72         struct
73         {
74             uint8_t                 m_keyFrame      : 1;        // [0..1]
75             uint8_t                 m_intraOnly     : 1;        // [0..1]
76             uint8_t                 m_display       : 1;        // [0..1]
77             uint8_t                 m_reservedField : 5;        // [0]
78         } m_fields;
79         uint8_t                     m_value;
80     } m_prevFrameParams;
81 
82     uint32_t                        m_prevFrmWidth;
83     uint32_t                        m_prevFrmHeight;
84 
85     //driver internally
86     uint8_t                         m_referenceFrameSignBias[8];
87     int8_t                          m_skipModeFrame[2]; //offset to LAST_FRAME, should be sign value
88     uint32_t                        m_lumaPlaneXStepQn;
89     uint32_t                        m_lumaPlaneX0Qn;
90     uint32_t                        m_chromaPlaneXStepQn;
91     uint32_t                        m_chromaPlaneX0Qn;
92 
93     uint8_t                         m_refOrderHints[7];
94     uint8_t                         m_savedRefOrderHints[7][7];
95     uint8_t                         m_refMaskMfProj;
96 };
97 
98 struct MhwVdboxAvpPakInsertObjParams
99 {
100     PBSBuffer pBsBuffer;
101     // also reuse dwBitSize for passing SrcDataEndingBitInclusion when (pEncoder->bLastPicInStream || pEncoder->bLastPicInSeq)
102     uint32_t          dwBitSize;
103     uint32_t          dwOffset;
104     uint32_t          uiSkipEmulationCheckCount;
105     bool              bLastPicInSeq;
106     bool              bLastPicInStream;
107     bool              m_lastHeader;
108     bool              bEmulationByteBitsInsert;
109     bool              bSetLastPicInStreamData;
110     bool              bSliceHeaderIndicator;
111     bool              bHeaderLengthExcludeFrmSize;
112     uint32_t *        pdwMpeg2PicHeaderTotalBufferSize;
113     uint32_t *        pdwMpeg2PicHeaderDataStartOffset;
114     bool              bResetBitstreamStartingPos;
115     uint32_t          m_endOfHeaderInsertion;
116     uint32_t          dwLastPicInSeqData;
117     uint32_t          dwLastPicInStreamData;
118     PMHW_BATCH_BUFFER pBatchBufferForPakSlices;
119     bool              bVdencInUse;
120 };
121 
122 struct MhwVdboxAvpSegmentStateParams
123 {
124     CodecAv1SegmentsParams          *m_av1SegmentParams;
125     uint8_t                         m_currentSegmentId;
126 };
127 
128 struct MhwVdboxAvpBsdParams
129 {
130     uint32_t                        m_bsdDataLength;
131     uint32_t                        m_bsdDataStartOffset;
132 };
133 
134 class MhwVdboxAvpPipeBufAddrParams
135 {
136 public:
137     uint32_t                    m_mode                                                      = 0;
138 
139     MOS_RESOURCE                *m_references[8]                                            = {};       //!< Reference Frame Buffer
140     MOS_SURFACE                 *m_decodedPic                                               = nullptr;  //!< Decoded Output Frame Buffer
141     MOS_RESOURCE                *m_intrabcDecodedOutputFrameBuffer                          = nullptr;  //!< IntraBC Decoded output frame buffer
142     MOS_RESOURCE                *m_cdfTableInitializationBuffer                             = nullptr;  //!< CDF Tables Initialization Buffer
143     uint32_t                    m_cdfTableInitializationBufferOffset                        = 0;        //!< CDF Tables Initialization Buffer Size
144     MOS_RESOURCE                *m_cdfTableBwdAdaptationBuffer                              = nullptr;  //!< CDF Tables Backward Adaptation Buffer
145 
146     MOS_RESOURCE                *m_segmentIdReadBuffer                                      = nullptr;  //!< AV1 Segment ID Read Buffer
147     MOS_RESOURCE                *m_segmentIdWriteBuffer                                     = nullptr;  //!< AV1 Segment ID Write Buffer
148     MOS_RESOURCE                *m_colMvTemporalBuffer[9]                                   = {};       //!< Collocated MV temporal buffer
149     MOS_RESOURCE                *m_curMvTemporalBuffer                                      = nullptr;  //!< Current MV temporal buffer
150     MOS_RESOURCE                *m_bitstreamDecoderEncoderLineRowstoreReadWriteBuffer       = nullptr;  //!< Handle of Bitstream Decode Line Rowstore buffer, can be programmed to use Local Media Storage VMM instead of Memory
151     MOS_RESOURCE                *m_bitstreamDecoderEncoderTileLineRowstoreReadWriteBuffer   = nullptr;  //!< Handle of Bitstream Decode Tile Line buffer
152     MOS_RESOURCE                *m_intraPredictionLineRowstoreReadWriteBuffer               = nullptr;  //!< Handle of Intra Prediction Line Rowstore Read/Write Buffer
153     MOS_RESOURCE                *m_intraPredictionTileLineRowstoreReadWriteBuffer           = nullptr;  //!< Handle of Intra Prediction Tile Line Rowstore Read/Write Buffer
154     MOS_RESOURCE                *m_spatialMotionVectorLineReadWriteBuffer                   = nullptr;  //!< Handle of Spatial Motion Vector Line rowstore buffer, can be programmed to use Local Media Storage VMM instead of Memory
155     MOS_RESOURCE                *m_spatialMotionVectorCodingTileLineReadWriteBuffer         = nullptr;  //!< Handle of Spatial Motion Vector Tile Line buffer
156     MOS_RESOURCE                *m_loopRestorationMetaTileColumnReadWriteBuffer             = nullptr;  //!< Loop Restoration Meta Tile Column Read/Write Buffer Address
157     MOS_RESOURCE                *m_loopRestorationFilterTileReadWriteLineYBuffer            = nullptr;  //!< Loop Restoration Filter Tile Read/Write Line Y Buffer Address
158     MOS_RESOURCE                *m_loopRestorationFilterTileReadWriteLineUBuffer            = nullptr;  //!< Loop Restoration Filter Tile Read/Write Line U Buffer Address
159     MOS_RESOURCE                *m_loopRestorationFilterTileReadWriteLineVBuffer            = nullptr;  //!< Loop Restoration Filter Tile Read/Write Line V Buffer Address
160     MOS_RESOURCE                *m_deblockerFilterLineReadWriteYBuffer                      = nullptr;  //!< Deblocker Filter Line Read/Write Y Buffer Address
161     MOS_RESOURCE                *m_deblockerFilterLineReadWriteUBuffer                      = nullptr;  //!< Deblocker Filter Line Read/Write U Buffer Address
162     MOS_RESOURCE                *m_deblockerFilterLineReadWriteVBuffer                      = nullptr;  //!< Deblocker Filter Line Read/Write V Buffer Address
163     MOS_RESOURCE                *m_deblockerFilterTileLineReadWriteYBuffer                  = nullptr;  //!< Deblocker Filter Tile Line Read/Write Y Buffer Address
164     MOS_RESOURCE                *m_deblockerFilterTileLineReadWriteVBuffer                  = nullptr;  //!< Deblocker Filter Tile Line Read/Write V Buffer Address
165     MOS_RESOURCE                *m_deblockerFilterTileLineReadWriteUBuffer                  = nullptr;  //!< Deblocker Filter Tile Line Read/Write U Buffer Address
166     MOS_RESOURCE                *m_deblockerFilterTileColumnReadWriteYBuffer                = nullptr;  //!< Deblocker Filter Tile Column Read/Write Y Buffer Address
167     MOS_RESOURCE                *m_deblockerFilterTileColumnReadWriteUBuffer                = nullptr;  //!< Deblocker Filter Tile Column Read/Write U Buffer Address
168     MOS_RESOURCE                *m_deblockerFilterTileColumnReadWriteVBuffer                = nullptr;  //!< Deblocker Filter Tile Column Read/Write V Buffer Address
169     MOS_RESOURCE                *m_cdefFilterLineReadWriteBuffer                            = nullptr;  //!< CDEF Filter Line Read/Write Y Buffer Address
170     MOS_RESOURCE                *m_cdefFilterTileLineReadWriteBuffer                        = nullptr;  //!< CDEF Filter Tile Line Read/Write Y Buffer Address
171     MOS_RESOURCE                *m_cdefFilterTileColumnReadWriteBuffer                      = nullptr;  //!< CDEF Filter Tile Column Read/Write Y Buffer Address
172     MOS_RESOURCE                *m_cdefFilterMetaTileLineReadWriteBuffer                    = nullptr;  //!< CDEF Filter Meta Tile Line Read/Write Buffer Address
173     MOS_RESOURCE                *m_cdefFilterMetaTileColumnReadWriteBuffer                  = nullptr;  //!< CDEF Filter Meta Tile Column Read/Write Buffer Address
174     MOS_RESOURCE                *m_cdefFilterTopLeftCornerReadWriteBuffer                   = nullptr;  //!< CDEF Filter Top-Left Corner Read/Write Buffer Address
175     MOS_RESOURCE                *m_superResTileColumnReadWriteYBuffer                       = nullptr;  //!< Super-Res Tile Column Read/Write Y Buffer Address
176     MOS_RESOURCE                *m_superResTileColumnReadWriteUBuffer                       = nullptr;  //!< Super-Res Tile Column Read/Write U Buffer Address
177     MOS_RESOURCE                *m_superResTileColumnReadWriteVBuffer                       = nullptr;  //!< Super-Res Tile Column Read/Write V Buffer Address
178     MOS_RESOURCE                *m_loopRestorationFilterTileColumnReadWriteYBuffer          = nullptr;  //!< Loop Restoration Filter Tile Column Read/Write Y Buffer Address
179     MOS_RESOURCE                *m_loopRestorationFilterTileColumnReadWriteUBuffer          = nullptr;  //!< Loop Restoration Filter Tile Column Read/Write U Buffer Address
180     MOS_RESOURCE                *m_loopRestorationFilterTileColumnReadWriteVBuffer          = nullptr;  //!< Loop Restoration Filter Tile Column Read/Write V Buffer Address
181     MOS_RESOURCE                *m_decodedFrameStatusErrorBuffer                            = nullptr;  //!< Decoded Frame Status/Error Buffer Base Address
182     MOS_RESOURCE                *m_decodedBlockDataStreamoutBuffer                          = nullptr;  //!< Decoded Block Data Streamout Buffer Address
183 
184     //MMC supported
185     MOS_MEMCOMP_STATE           m_preDeblockSurfMmcState                                    = {};
186     MOS_MEMCOMP_STATE           m_streamOutBufMmcState                                      = {};
187     MOS_MEMCOMP_STATE           m_rawSurfMmcState                                           = {};
188 
189     virtual void Initialize();
190     //!
191     //! \brief    Destructor
192     //!
~MhwVdboxAvpPipeBufAddrParams()193     virtual ~MhwVdboxAvpPipeBufAddrParams() { }
194 };
195 
196 struct MhwVdboxAvpBufferSizeParams
197 {
198     uint8_t                         m_bitDepthIdc;
199     uint32_t                        m_picWidth;                // picWidth in SB
200     uint32_t                        m_picHeight;               // picHeight in SB
201     uint32_t                        m_tileWidth;               // tileWidth in SB
202     uint32_t                        m_bufferSize;
203     bool                            m_isSb128x128;
204     uint32_t                        m_curFrameTileNum;
205     uint32_t                        m_numTileCol;
206     uint8_t                         m_numOfActivePipes;
207 };
208 
209 struct MhwVdboxAvpBufferReallocParams
210 {
211     uint8_t                         m_bitDepthIdc;
212     uint16_t                        m_prevFrameTileNum;
213     uint16_t                        m_curFrameTileNum;
214     bool                            m_isSb128x128;
215     uint32_t                        m_tileWidth;
216     uint32_t                        m_numTileCol;
217     uint32_t                        m_numTileColAllocated;
218     uint32_t                        m_picWidth;
219     uint32_t                        m_picHeight;
220     uint32_t                        m_picWidthAlloced;
221     uint32_t                        m_picHeightAlloced;
222     uint32_t                        m_bufferSizeAlloced;
223     bool                            m_needBiggerSize;
224 };
225 
226 //NOTE: When changing MhwVdboxAvpInternalBufferType, please change CodecAv1BufferSize[][][]/CodecAv1BufferSizeExt[][][] accordingly!!!
227 enum MhwVdboxAvpInternalBufferType
228 {
229     segmentIdBuf        = 0,    //!< segment ID temporal buffers
230     mvTemporalBuf,              //!< MV temporal buffers of both current and collocated
231     bsdLineBuf,                 //!< bitstream decode line buffer
232     bsdTileLineBuf,             //!< bitstream decode tile line buffer
233     intraPredLine,              //!< intra prediction line buffer
234     intraPredTileLine,
235     spatialMvLineBuf,
236     spatialMvTileLineBuf,
237     lrMetaTileCol,              //!< Loop Restoration Meta Tile Column Read/Write Buffer Address
238     lrTileLineY,                //!< Loop Restoration Filter Tile Read/Write Line Y Buffer Address
239     lrTileLineU,                //!< Loop Restoration Filter Tile Read/Write Line U Buffer Address
240     lrTileLineV,                //!< Loop Restoration Filter Tile Read/Write Line V Buffer Address
241     deblockLineYBuf,
242     deblockLineUBuf,
243     deblockLineVBuf,
244     deblockTileLineYBuf,
245     deblockTileLineVBuf,
246     deblockTileLineUBuf,
247     deblockTileColYBuf,
248     deblockTileColUBuf,
249     deblockTileColVBuf,
250     cdefLineBuf,
251     cdefTileLineBuf,
252     cdefTileColBuf,
253     cdefMetaTileLine,
254     cdefMetaTileCol,
255     cdefTopLeftCornerBuf,
256     superResTileColYBuf,
257     superResTileColUBuf,
258     superResTileColVBuf,
259     lrTileColYBuf,
260     lrTileColUBuf,
261     lrTileColVBuf,
262     frameStatusErrBuf,
263     dbdStreamoutBuf,
264     fgTileColBuf,
265     fgSampleTmpBuf,
266     lrTileColAlignBuf,
267     tileSzStreamOutBuf,
268     tileStatStreamOutBuf,
269     cuStreamoutBuf,
270     sseLineBuf,
271     sseTileLineBuf,
272     avpInternalBufMax
273 };
274 
275 //AVP internal buffer size table [buffer_index][bitdepthIdc][IsSb128x128]
276 static const uint8_t CodecAv1BufferSize[avpInternalBufMax][2][2] =
277 {
278     { 2 ,   8   ,   2   ,   8 }, //segmentIdBuf,
279     { 4 ,   16  ,   4   ,    16 }, //mvTemporalBuf,
280     { 2 ,   4   ,   2   ,    4 }, //bsdLineBuf,
281     { 2 ,   4   ,   2   ,    4 }, //bsdTileLineBuf,
282     { 2 ,   4   ,   4   ,    8 }, //intraPredLine,
283     { 2 ,   4   ,   4   ,    8 }, //intraPredTileLine,
284     { 4 ,   8   ,   4   ,    8 }, //spatialMvLineBuf,
285     { 4 ,   8   ,   4   ,    8 }, //spatialMvTileLineBuf,
286     { 1 ,   1   ,   1   ,    1 }, //lrMetaTileCol,
287     { 7 ,   7   ,   7   ,    7 }, //lrTileLineY,
288     { 5 ,   5   ,   5   ,    5 }, //lrTileLineU,
289     { 5 ,   5   ,   5   ,    5 }, //lrTileLineV,
290     { 9 ,   17  ,   11  ,    21 }, //deblockLineYBuf,
291     { 3 ,   4   ,   3   ,    5 }, //deblockLineUBuf,
292     { 3 ,   4   ,   3   ,    5 }, //deblockLineVBuf,
293     { 9 ,   17  ,   11  ,    21 }, //deblockTileLineYBuf,
294     { 3 ,   4   ,   3   ,    5 }, //deblockTileLineVBuf,
295     { 3 ,   4   ,   3   ,    5 }, //deblockTileLineUBuf,
296     { 8 ,   16  ,   10  ,    20 }, //deblockTileColYBuf,
297     { 2 ,   4   ,   3   ,    5 }, //deblockTileColUBuf,
298     { 2 ,   4   ,   3   ,    5 }, //deblockTileColVBuf,
299     { 8 ,   16  ,   10  ,    20 }, //cdefLineBuf,
300     { 8 ,   16  ,   10  ,    20 }, //cdefTileLineBuf,
301     { 8 ,   16  ,   10  ,    20 }, //cdefTileColBuf,
302     { 1 ,   1   ,   1   ,    1 }, //cdefMetaTileLine,
303     { 1 ,   1   ,   1   ,    1 }, //cdefMetaTileCol,
304     { 1 ,   1   ,   1   ,    1 }, //cdefTopLeftCornerBuf,
305     { 22,   44  ,   29  ,    58 }, //superResTileColYBuf,
306     { 8 ,   16  ,   10  ,    20 }, //superResTileColUBuf,
307     { 8 ,   16  ,   10  ,    20 }, //superResTileColVBuf,
308     { 9 ,   17  ,   11  ,    22 }, //lrTileColYBuf,
309     { 5 ,   9   ,   6   ,    12 }, //lrTileColUBuf,
310     { 5 ,   9   ,   6   ,    12 }, //lrTileColVBuf,
311     { 0 ,   0   ,   0   ,    0 }, //frameStatusErrBuf,
312     { 0 ,   0   ,   0   ,    0 }, //dbdStreamoutBuf,
313     { 2 ,   4   ,   3   ,    5 }, //fgTileColBuf
314     { 96,   96  ,   192 ,    192 },//fgSampleTmpBuf
315     { 4,    8   ,   5   ,    10 }, //lrTileColAlignBuf
316 };
317 
318 static const uint8_t CodecAv1BufferSizeExt[avpInternalBufMax][2][2] =
319 {
320     { 0 ,    0    ,    0    ,    0 }, //segmentIdBuf,
321     { 0 ,    0    ,    0    ,    0 }, //mvTemporalBuf,
322     { 0 ,    0    ,    0    ,    0 }, //bsdLineBuf,
323     { 0 ,    0    ,    0    ,    0 }, //bsdTileLineBuf,
324     { 0 ,    0    ,    0    ,    0 }, //intraPredLine,
325     { 0 ,    0    ,    0    ,    0 }, //intraPredTileLine,
326     { 0 ,    0    ,    0    ,    0 }, //spatialMvLineBuf,
327     { 0 ,    0    ,    0    ,    0 }, //spatialMvTileLineBuf,
328     { 1 ,    1    ,    1    ,    1 }, //lrMetaTileCol,
329     { 0 ,    0    ,    0    ,    0 }, //lrTileLineY,
330     { 0 ,    0    ,    0    ,    0 }, //lrTileLineU,
331     { 0 ,    0    ,    0    ,    0 }, //lrTileLineV,
332     { 0 ,    0    ,    0    ,    0 }, //deblockLineYBuf,
333     { 0 ,    0    ,    0    ,    0 }, //deblockLineUBuf,
334     { 0 ,    0    ,    0    ,    0 }, //deblockLineVBuf,
335     { 0 ,    0    ,    0    ,    0 }, //deblockTileLineYBuf,
336     { 0 ,    0    ,    0    ,    0 }, //deblockTileLineVBuf,
337     { 0 ,    0    ,    0    ,    0 }, //deblockTileLineUBuf,
338     { 0 ,    0    ,    0    ,    0 }, //deblockTileColYBuf,
339     { 0 ,    0    ,    0    ,    0 }, //deblockTileColUBuf,
340     { 0 ,    0    ,    0    ,    0 }, //deblockTileColVBuf,
341     { 1 ,    1    ,    2    ,    2 }, //cdefLineBuf,
342     { 1 ,    1    ,    2    ,    2 }, //cdefTileLineBuf,
343     { 1 ,    1    ,    2    ,    2 }, //cdefTileColBuf,
344     { 0 ,    0    ,    0    ,    0 }, //cdefMetaTileLine,
345     { 1 ,    1    ,    1    ,    1 }, //cdefMetaTileCol,
346     { 0 ,    0    ,    0    ,    0 }, //cdefTopLeftCornerBuf,
347     { 22,    44   ,    29   ,    58 }, //superResTileColYBuf,
348     { 8 ,    16   ,    10   ,    20 }, //superResTileColUBuf,
349     { 8 ,    16   ,    10   ,    20 }, //superResTileColVBuf,
350     { 2 ,    2    ,    2    ,    2 }, //lrTileColYBuf,
351     { 1 ,    1    ,    1    ,    1 }, //lrTileColUBuf,
352     { 1 ,    1    ,    1    ,    1 }, //lrTileColVBuf,
353     { 0 ,    0    ,    0    ,    0 }, //frameStatusErrBuf,
354     { 0 ,    0    ,    0    ,    0 }, //dbdStreamoutBuf,
355     { 1 ,    1    ,    1    ,    1 }, //fgTileColBuf,
356     { 0 ,    0    ,    0    ,    0 }, //fgSampleTmpBuf,
357     { 1 ,    1    ,    1    ,    1 }, //lrTileColAlignBuf,
358 };
359 
360 //!
361 //! \struct   MmioRegistersAvp
362 //! \brief    MMIO registers AVP
363 //!
364 struct MmioRegistersAvp
365 {
366     uint32_t                   avpAv1BitstreamByteCountTileRegOffset         = 0;
367     uint32_t                   avpAv1BitstreamByteCountTileNoHeaderRegOffset = 0;
368     uint32_t                   avpAv1CabacBinCountTileRegOffset              = 0;
369     uint32_t                   avpAv1CabacInsertionCountRegOffset            = 0;
370     uint32_t                   avpAv1MinSizePaddingCountRegOffset            = 0;
371     uint32_t                   avpAv1ImageStatusMaskRegOffset                = 0;
372     uint32_t                   avpAv1ImageStatusControlRegOffset             = 0;
373     uint32_t                   avpAv1QpStatusCountRegOffset                  = 0;
374     uint32_t                   avpAv1DecErrorStatusAddrRegOffset             = 0;
375 };
376 
377 //!  MHW Vdbox Avp interface
378 /*!
379 This class defines the interfaces for constructing Vdbox Avp commands across all platforms
380 */
381 class MhwVdboxAvpInterface
382 {
383 protected:
384     PMOS_INTERFACE              m_osInterface = nullptr;         //!< Pointer to OS interface
385     MhwMiInterface              *m_miInterface = nullptr;        //!< Pointer to MI interface
386     MhwCpInterface              *m_cpInterface = nullptr;        //!< Pointer to CP interface
387     MEDIA_FEATURE_TABLE         *m_skuTable  = nullptr;          //!< Pointer to SKU table
388     MEDIA_WA_TABLE              *m_waTable   = nullptr;          //!< Pointer to WA table
389     bool                        m_decodeInUse = false;           //!< Flag to indicate if the interface is for decoder or encoder use
390 
391     MHW_MEMORY_OBJECT_CONTROL_PARAMS m_cacheabilitySettings[MOS_CODEC_RESOURCE_USAGE_END_CODEC] = {};    //!< Cacheability settings
392     MmioRegistersAvp                 m_mmioRegisters[MHW_VDBOX_NODE_MAX]                        = {};    //!< AVP mmio registers
393     bool                             m_rowstoreCachingSupported                                 = false; //!< Flag to indicate if row store cache is supported
394 
395     MHW_VDBOX_ROWSTORE_CACHE    m_btdlRowstoreCache = {};         //! Bitstream Decoder/Encode Line Rowstore (BTDL)
396     MHW_VDBOX_ROWSTORE_CACHE    m_smvlRowstoreCache = {};         //! Spatial Motion Vector Line Rowstore (SMVL)
397     MHW_VDBOX_ROWSTORE_CACHE    m_ipdlRowstoreCache = {};         //! Intra Prediction Line Rowstore (IPDL)
398     MHW_VDBOX_ROWSTORE_CACHE    m_dflyRowstoreCache = {};         //! Deblocker Filter Line Y Buffer (DFLY)
399     MHW_VDBOX_ROWSTORE_CACHE    m_dfluRowstoreCache = {};         //! Deblocker Filter Line U Buffe (DFLU)
400     MHW_VDBOX_ROWSTORE_CACHE    m_dflvRowstoreCache = {};         //! Deblocker Filter Line V Buffe (DFLV)
401     MHW_VDBOX_ROWSTORE_CACHE    m_cdefRowstoreCache = {};         //! CDEF Filter Line Buffer (CDEF)
402 
403     std::shared_ptr<void> m_avpItfNew = nullptr;
404 
405 #if MOS_EVENT_TRACE_DUMP_SUPPORTED
406     bool bMMCReported = false;
407 #endif
408     //!
409     //! \brief    Constructor
410     //!
411     MhwVdboxAvpInterface(
412         PMOS_INTERFACE osInterface,
413         MhwMiInterface *miInterface,
414         MhwCpInterface *cpInterface,
415         bool decodeInUse);
416 
417     //!
418     //! \brief    Add a resource to the command buffer
419     //! \details  Internal function to add either a graphics address of a resource or
420     //!           add the resource to the patch list for the requested buffer
421     //!
422     //! \param    [in] osInterface
423     //!           OS interface
424     //! \param    [in] cmdBuffer
425     //!           Command buffer to which resource is added
426     //! \param    [in] params
427     //!           Parameters necessary to add the resource
428     //!
429     //! \return   MOS_STATUS
430     //!           MOS_STATUS_SUCCESS if success, else fail reason
431     //!
432     MOS_STATUS(*AddResourceToCmd) (
433         PMOS_INTERFACE osInterface,
434         PMOS_COMMAND_BUFFER cmdBuffer,
435         PMHW_RESOURCE_PARAMS params);
436 
437 public:
438     //!
439     //! \brief    Destructor
440     //!
~MhwVdboxAvpInterface()441     virtual ~MhwVdboxAvpInterface() {}
442 
443     //!
444     //! \brief    Get new AVP interface, temporal solution before switching from
445     //!           old interface to new one
446     //!
447     //! \return   pointer to new AVP interface
448     //!
GetNewAvpInterface()449     virtual std::shared_ptr<void> GetNewAvpInterface() { return nullptr; }
450 
451     //!
452     //! \brief    Judge if row store caching supported
453     //!
454     //! \return   bool
455     //!           true if supported, else false
456     //!
IsRowStoreCachingSupported()457     inline bool IsRowStoreCachingSupported()
458     {
459         return m_rowstoreCachingSupported;
460     }
461 
462     //!
463     //! \brief    Judge if AV1 Bitstream Decoder/Encode Line Rowstore (BTDL) caching enabled
464     //!
465     //! \return   bool
466     //!           true if enabled, else false
467     //!
IsBtdlRowstoreCacheEnabled()468     inline bool IsBtdlRowstoreCacheEnabled()
469     {
470         return m_btdlRowstoreCache.bEnabled ? true : false;
471     }
472 
473     //!
474     //! \brief    Judge if AV1 Spatial Motion Vector Line Rowstore caching enabled
475     //!
476     //! \return   bool
477     //!           true if enabled, else false
478     //!
IsSmvlRowstoreCacheEnabled()479     inline bool IsSmvlRowstoreCacheEnabled()
480     {
481         return m_smvlRowstoreCache.bEnabled ? true : false;
482     }
483 
484     //!
485     //! \brief    Judge if AV1 Intra Prediction Line Rowstore (IPDL) caching enabled
486     //!
487     //! \return   bool
488     //!           true if enabled, else false
489     //!
IsIpdlRowstoreCacheEnabled()490     inline bool IsIpdlRowstoreCacheEnabled()
491     {
492         return m_ipdlRowstoreCache.bEnabled ? true : false;
493     }
494 
495     //!
496     //! \brief    Judge if AV1 Deblocker Filter Line Y Buffer (DFLY) caching enabled
497     //!
498     //! \return   bool
499     //!           true if enabled, else false
500     //!
IsDflyRowstoreCacheEnabled()501     inline bool IsDflyRowstoreCacheEnabled()
502     {
503         return m_dflyRowstoreCache.bEnabled ? true : false;
504     }
505 
506     //!
507     //! \brief    Judge if AV1 Deblocker Filter Line U Buffe (DFLU) caching enabled
508     //!
509     //! \return   bool
510     //!           true if enabled, else false
511     //!
IsDfluRowstoreCacheEnabled()512     inline bool IsDfluRowstoreCacheEnabled()
513     {
514         return m_dfluRowstoreCache.bEnabled ? true : false;
515     }
516 
517 
518     //!
519     //! \brief    Judge if AV1 Deblocker Filter Line V Buffe (DFLV) caching enabled
520     //!
521     //! \return   bool
522     //!           true if enabled, else false
523     //!
IsDflvRowstoreCacheEnabled()524     inline bool IsDflvRowstoreCacheEnabled()
525     {
526         return m_dflvRowstoreCache.bEnabled ? true : false;
527     }
528 
529     //!
530     //! \brief    Judge if AV1 CDEF Filter Line Buffer (CDEF) caching enabled
531     //!
532     //! \return   bool
533     //!           true if enabled, else false
534     //!
IsCdefRowstoreCacheEnabled()535     inline bool IsCdefRowstoreCacheEnabled()
536     {
537         return m_cdefRowstoreCache.bEnabled ? true : false;
538     }
539 
540     //!
541     //! \brief    Get mmio registers
542     //!
543     //! \param    [in] index
544     //!           mmio registers index.
545     //!
546     //! \return   [out] MmioRegistersAvp*
547     //!           mmio registers got.
548     //!
GetMmioRegisters(MHW_VDBOX_NODE_IND index)549     inline MmioRegistersAvp* GetMmioRegisters(MHW_VDBOX_NODE_IND index)
550     {
551         if (index < MHW_VDBOX_NODE_MAX)
552         {
553             return &m_mmioRegisters[index];
554         }
555         else
556         {
557             MHW_ASSERT("index is out of range!");
558             return &m_mmioRegisters[MHW_VDBOX_NODE_1];
559         }
560     }
561 
562     //!
563     //! \brief    Set cacheability settings
564     //!
565     //! \param    [in] cacheabilitySettings
566     //!           Cacheability settings
567     //!
568     //! \return   MOS_STATUS
569     //!           MOS_STATUS_SUCCESS if success, else fail reason
570     //!
SetCacheabilitySettings(MHW_MEMORY_OBJECT_CONTROL_PARAMS cacheabilitySettings[MOS_CODEC_RESOURCE_USAGE_END_CODEC])571     MOS_STATUS SetCacheabilitySettings(
572         MHW_MEMORY_OBJECT_CONTROL_PARAMS cacheabilitySettings[MOS_CODEC_RESOURCE_USAGE_END_CODEC])
573     {
574         MHW_FUNCTION_ENTER;
575 
576         uint32_t size = MOS_CODEC_RESOURCE_USAGE_END_CODEC * sizeof(MHW_MEMORY_OBJECT_CONTROL_PARAMS);
577         MOS_STATUS eStatus = MOS_SecureMemcpy(m_cacheabilitySettings, size,
578             cacheabilitySettings, size);
579 
580         return eStatus;
581     }
582 
583     //!
584     //! \brief    Calculates the maximum size for AVP picture level commands
585     //! \details  Client facing function to calculate the maximum size for AVP picture level commands
586     //! \param    [out] commandsSize
587     //!           The maximum command buffer size
588     //! \param    [out] patchListSize
589     //!           The maximum command patch list size
590     //! \param    [in] params
591     //!           Indicate the command size parameters
592     //! \return   MOS_STATUS
593     //!           MOS_STATUS_SUCCESS if success, else fail reason
594     //!
595     virtual MOS_STATUS GetAvpStateCommandSize(
596         uint32_t                        *commandsSize,
597         uint32_t                        *patchListSize,
598         PMHW_VDBOX_STATE_CMDSIZE_PARAMS params) = 0;
599 
600     //!
601     //! \brief    Calculates maximum size for AVP slice/MB level commands
602     //! \details  Client facing function to calculate maximum size for AVP slice/MB level commands
603     //! \param    [out] commandsSize
604     //!            The maximum command buffer size
605     //! \param    [out] patchListSize
606     //!           The maximum command patch list size
607     //! \return   MOS_STATUS
608     //!           MOS_STATUS_SUCCESS if success, else fail reason
609     //!
610     virtual MOS_STATUS GetAvpPrimitiveCommandSize(
611         uint32_t                        *commandsSize,
612         uint32_t                        *patchListSize) = 0;
613 
614     //!
615     //! \brief    Get the required buffer size for VDBOX
616     //! \details  Internal function to judge if buffer realloc is needed for AV1 codec
617     //!
618     //! \param    [in] bufferType
619     //!           AV1 Buffer type
620     //! \param    [in, out] reallocParam
621     //!           AVP Re-allocate parameters
622     //!
623     //! \return   MOS_STATUS
624     //!           MOS_STATUS_SUCCESS if success, else fail reason
625     //!
626     virtual MOS_STATUS IsAv1BufferReallocNeeded(
627         MhwVdboxAvpInternalBufferType   bufferType,
628         MhwVdboxAvpBufferReallocParams  *reallocParam) = 0;
629 
630     //!
631     //! \brief    Get the required buffer size for VDBOX
632     //! \details  Internal function to get required buffer size for AV1 codec
633     //!
634     //! \param    [in] bufferType
635     //!           AV1 Buffer type
636     //! \param    [in, out] avpBufSizeParam
637     //!           AVP buffer size parameters
638     //!
639     //! \return   MOS_STATUS
640     //!           MOS_STATUS_SUCCESS if success, else fail reason
641     //!
642     virtual MOS_STATUS GetAv1BufferSize(
643         MhwVdboxAvpInternalBufferType       bufferType,
644         MhwVdboxAvpBufferSizeParams    *avpBufSizeParam) = 0;
645 
646     //!
647     //! \brief    Adds AVP Surface State command in command buffer
648     //! \details  Client facing function to add AVP Surface State command in command buffer
649     //!
650     //! \param    [in] cmdBuffer
651     //!           Command buffer to which HW command is added
652     //! \param    [in] params
653     //!           Params structure used to populate the HW command
654     //!
655     //! \return   MOS_STATUS
656     //!           MOS_STATUS_SUCCESS if success, else fail reason
657     //!
658     virtual MOS_STATUS AddAvpSurfaceCmd(
659         PMOS_COMMAND_BUFFER                  cmdBuffer,
660         PMHW_VDBOX_SURFACE_PARAMS            params);
661 
662     //!
663     //! \brief    Adds AVP Segment State command in command buffer
664     //! \details  Client facing function to add AVP Segment State command in command buffer
665     //!
666     //! \param    [in] cmdBuffer
667     //!           Command buffer to which HW command is added
668     //! \param    [in] params
669     //!           Params structure used to populate the HW command
670     //!
671     //! \return   MOS_STATUS
672     //!           MOS_STATUS_SUCCESS if success, else fail reason
673     //!
674     virtual MOS_STATUS AddAvpSegmentStateCmd(
675         PMOS_COMMAND_BUFFER                 cmdBuffer,
676         MhwVdboxAvpSegmentStateParams       *params) = 0;
677 
678     //!
679     //! \brief    Programs base address of rowstore scratch buffers
680     //! \details  Internal function to get base address of rowstore scratch buffers
681     //!
682     //! \param    [in] rowstoreParams
683     //!           Rowstore parameters
684     //!
685     //! \return   MOS_STATUS
686     //!           MOS_STATUS_SUCCESS if success, else fail reason
687     //!
688     virtual MOS_STATUS GetRowstoreCachingAddrs(
689         PMHW_VDBOX_ROWSTORE_PARAMS rowstoreParams) = 0;
690 
691     //!
692     //! \brief    Adds AVP Pipe Pipe Mode Select command in command buffer
693     //!
694     //! \param    [in] cmdBuffer
695     //!           Command buffer to which HW command is added
696     //! \param    [in] params
697     //!           Params structure used to populate the HW command
698     //!
699     //! \return   MOS_STATUS
700     //!           MOS_STATUS_SUCCESS if success, else fail reason
701     //!
702     virtual MOS_STATUS AddAvpPipeModeSelectCmd(
703         PMOS_COMMAND_BUFFER                  cmdBuffer,
704         PMHW_VDBOX_PIPE_MODE_SELECT_PARAMS   params) = 0;
705 
706     //!
707     //! \brief    Adds AVP Surface State command for decode in command buffer
708     //!
709     //! \param    [in] cmdBuffer
710     //!           Command buffer to which HW command is added
711     //! \param    [in] params
712     //!           Params structure used to populate the HW command
713     //!
714     //! \return   MOS_STATUS
715     //!           MOS_STATUS_SUCCESS if success, else fail reason
716     //!
717     virtual MOS_STATUS AddAvpDecodeSurfaceStateCmd(
718         PMOS_COMMAND_BUFFER                  cmdBuffer,
719         PMHW_VDBOX_SURFACE_PARAMS            params) = 0;
720 
721     //!
722     //! \brief    Adds AVP Pipe Buffer Address State command in command buffer
723     //!
724     //! \param    [in] cmdBuffer
725     //!           Command buffer to which HW command is added
726     //! \param    [in] params
727     //!           Params structure used to populate the HW command
728     //!
729     //! \return   MOS_STATUS
730     //!           MOS_STATUS_SUCCESS if success, else fail reason
731     //!
732     virtual MOS_STATUS AddAvpPipeBufAddrCmd(
733         PMOS_COMMAND_BUFFER                  cmdBuffer,
734         MhwVdboxAvpPipeBufAddrParams         *params) = 0;
735 
736     //!
737     //! \brief    Adds AVP Indirect Object Base Address State command in command buffer
738     //!
739     //! \param    [in] cmdBuffer
740     //!           Command buffer to which HW command is added
741     //! \param    [in] params
742     //!           Params structure used to populate the HW command
743     //!
744     //! \return   MOS_STATUS
745     //!           MOS_STATUS_SUCCESS if success, else fail reason
746     //!
747     virtual MOS_STATUS AddAvpIndObjBaseAddrCmd(
748         PMOS_COMMAND_BUFFER                  cmdBuffer,
749         PMHW_VDBOX_IND_OBJ_BASE_ADDR_PARAMS  params) = 0;
750 
751     //!
752     //! \brief    Adds AVP picture State command for decode in command buffer
753     //!
754     //! \param    [in] cmdBuffer
755     //!           Command buffer to which HW command is added
756     //! \param    [in]  batchBuffer
757     //!           Batch buffer to which HW command is added
758     //! \param    [in] params
759     //!           Params structure used to populate the HW command
760     //!
761     //! \return   MOS_STATUS
762     //!           MOS_STATUS_SUCCESS if success, else fail reason
763     //!
764     virtual MOS_STATUS AddAvpDecodePicStateCmd(
765         PMOS_COMMAND_BUFFER                 cmdBuffer,
766         MhwVdboxAvpPicStateParams           *params) = 0;
767 
768     //!
769     //! \brief    Adds AVP BSD object state command in command buffer
770     //!
771     //! \param    [in] cmdBuffer
772     //!           Command buffer to which HW command is added
773     //! \param    [in] params
774     //!           Params structure used to populate the HW command
775     //!
776     //! \return   MOS_STATUS
777     //!           MOS_STATUS_SUCCESS if success, else fail reason
778     //!
779     virtual MOS_STATUS AddAvpBsdObjectCmd(
780         PMOS_COMMAND_BUFFER              cmdBuffer,
781         PMHW_BATCH_BUFFER                batchBuffer,
782         MhwVdboxAvpBsdParams             *params) = 0;
783 
784     //!
785     //! \brief    Adds AVP tile coding command in command buffer for decoder
786     //!
787     //! \param    [in] cmdBuffer
788     //!           Command buffer to which HW command is added
789     //! \param    [in] params
790     //!           Params structure used to populate the HW command
791     //!
792     //! \return   MOS_STATUS
793     //!           MOS_STATUS_SUCCESS if success, else fail reason
794     //!
795     virtual MOS_STATUS AddAvpDecodeTileCodingCmd(
796         PMOS_COMMAND_BUFFER             cmdBuffer,
797         PMHW_BATCH_BUFFER               batchBuffer,
798         MhwVdboxAvpTileCodingParams     *params) = 0;
799 
800     //!
801     //! \brief    Adds AVP tile coding command in command buffer when Large Scale Tile decoding is supported
802     //!
803     //! \param    [in] cmdBuffer
804     //!           Command buffer to which HW command is added
805     //! \param    [in] params
806     //!           Params structure used to populate the HW command
807     //!
808     //! \return   MOS_STATUS
809     //!           MOS_STATUS_SUCCESS if success, else fail reason
810     //!
811     virtual MOS_STATUS AddAvpDecodeTileCodingCmdLst(
812         PMOS_COMMAND_BUFFER          cmdBuffer,
813         PMHW_BATCH_BUFFER            batchBuffer,
814         MhwVdboxAvpTileCodingParams *params) = 0;
815 
816     //!
817     //! \brief    Adds AVP tile coding command in command buffer
818     //!
819     //! \param    [in] cmdBuffer
820     //!           Command buffer to which HW command is added
821     //! \param    [in] params
822     //!           Params structure used to populate the HW command
823     //!
824     //! \return   MOS_STATUS
825     //!           MOS_STATUS_SUCCESS if success, else fail reason
826     //!
827     virtual MOS_STATUS AddAvpTileCodingCmd(
828         PMOS_COMMAND_BUFFER                 cmdBuffer,
829         PMHW_BATCH_BUFFER                   batchBuffer,
830         MhwVdboxAvpTileCodingParams         *params) = 0;
831 
832     //!
833     //! \brief    Adds AVP Inloop Filter State command for decode in command buffer
834     //!
835     //! \param    [in] cmdBuffer
836     //!           Command buffer to which HW command is added
837     //! \param    [in] params
838     //!           Params structure used to populate the HW command
839     //!
840     //! \return   MOS_STATUS
841     //!           MOS_STATUS_SUCCESS if success, else fail reason
842     //!
843     virtual MOS_STATUS AddAvpInloopFilterStateCmd(
844         PMOS_COMMAND_BUFFER                  cmdBuffer,
845         MhwVdboxAvpPicStateParams            *params) = 0;
846 
847     //!
848     //! \brief    Adds AVP Inter Prediction State command
849     //! \details  function to add AVP Inter Prediction State command in command buffer
850     //!
851     //! \param    [in] cmdBuffer
852     //!           Command buffer to which HW command is added
853     //! \param    [in] params
854     //!           Params structure used to populate the HW command
855     //!
856     //! \return   MOS_STATUS
857     //!           MOS_STATUS_SUCCESS if success, else fail reason
858     //!
859     virtual MOS_STATUS AddAvpInterPredStateCmd(
860         PMOS_COMMAND_BUFFER                  cmdBuffer,
861         MhwVdboxAvpPicStateParams            *params) = 0;
862 };
863 
864 #endif
865