xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/hw/vdbox/mhw_vdbox_vvcp_itf.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2022, 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_vvcp_itf.h
24 //! \brief    MHW VDBOX VVCP interface common base
25 //! \details
26 //!
27 
28 #ifndef __MHW_VDBOX_VVCP_ITF_H__
29 #define __MHW_VDBOX_VVCP_ITF_H__
30 
31 #include "mhw_itf.h"
32 #include "mhw_vdbox.h"
33 #include "mhw_cp_interface.h"
34 #include "mhw_vdbox_vvcp_cmdpar.h"
35 
36 // add all VVCP cmds here
37 #define _VVCP_CMD_DEF(DEF)             \
38     DEF(VVCP_VD_CONTROL_STATE);        \
39     DEF(VVCP_PIPE_MODE_SELECT);        \
40     DEF(VVCP_SURFACE_STATE);           \
41     DEF(VVCP_PIPE_BUF_ADDR_STATE);     \
42     DEF(VVCP_IND_OBJ_BASE_ADDR_STATE); \
43     DEF(VVCP_PIC_STATE);               \
44     DEF(VVCP_DPB_STATE);               \
45     DEF(VVCP_SLICE_STATE);             \
46     DEF(VVCP_BSD_OBJECT);              \
47     DEF(VVCP_REF_IDX_STATE);           \
48     DEF(VVCP_WEIGHTOFFSET_STATE);      \
49     DEF(VVCP_TILE_CODING);
50 
51 namespace mhw
52 {
53 namespace vdbox
54 {
55 namespace vvcp
56 {
57 
58 //!
59 //! \struct   MmioRegistersVvcp
60 //! \brief    MMIO registers VVCP
61 //!
62 struct MmioRegistersVvcp
63 {
64     //TODO: Enalbe VVC new mechanism for MMIO
65 };
66 
67 class Itf
68 {
69 public:
70     class ParSetting
71     {
72     public:
73         virtual ~ParSetting() = default;
74 
75         _VVCP_CMD_DEF(_MHW_SETPAR_DEF);
76     };
77 
78     virtual ~Itf() = default;
79 
80     //!
81     //! \brief    Set cacheability settings
82     //!
83     //! \param    [in] settings
84     //!           Cacheability settings
85     //!
86     //! \return   MOS_STATUS
87     //!           MOS_STATUS_SUCCESS if success, else fail reason
88     //!
89     virtual MOS_STATUS SetCacheabilitySettings(MHW_MEMORY_OBJECT_CONTROL_PARAMS settings[MOS_CODEC_RESOURCE_USAGE_END_CODEC]) = 0;
90 
91     //!
92     //! \brief    Get the required buffer size for VDBOX
93     //! \details  Internal function to get required buffer size for VVC codec
94     //!
95     //! \param    [in] bufferType
96     //!           VVC Buffer type
97     //! \param    [in, out] vvcpBufSizeParam
98     //!           VVCP buffer size parameters
99     //!
100     //! \return   MOS_STATUS
101     //!           MOS_STATUS_SUCCESS if success, else fail reason
102     //!
103     virtual MOS_STATUS GetVvcpBufSize(VvcpBufferType bufferType, VvcpBufferSizePar *vvcpBufSizeParam) = 0;
104 
105     //!
106     //! \brief    Judge if row store caching is supported, overall flag for VVCP
107     //!
108     //! \return   bool
109     //!           true if supported, else false
110     //!
111     virtual bool IsRowStoreCachingSupported() = 0;
112 
113     //!
114     //! \brief    Judge if row store cache of a particular buffer type is enabled
115     //!
116     //! \param    [in] bufferType
117     //!           VVC Buffer type
118     //!
119     //! \return   bool
120     //!           true if enabled, else false
121     //!
122     virtual bool IsBufferRowstoreCacheEnabled(VvcpBufferType bufferType) = 0;
123 
124     virtual MOS_STATUS GetRowstoreCachingAddrs(PMHW_VDBOX_ROWSTORE_PARAMS rowstoreParams) = 0;
125 
126     //!
127     //! \brief    Calculates the maximum size for VVCP picture level commands
128     //! \details  Client facing function to calculate the maximum size for VVCP picture level commands
129     //! \param    [out] commandsSize
130     //!           The maximum command buffer size
131     //! \param    [out] patchListSize
132     //!           The maximum command patch list size
133     //! \param    [in] params
134     //!           Indicate the command size parameters
135     //! \return   MOS_STATUS
136     //!           MOS_STATUS_SUCCESS if success, else fail reason
137     //!
138     virtual MOS_STATUS GetVvcpStateCmdSize(uint32_t *commandsSize, uint32_t *patchListSize, PMHW_VDBOX_STATE_CMDSIZE_PARAMS params) = 0;
139 
140     virtual MOS_STATUS GetVvcpSliceLvlCmdSize(uint32_t *sliceLvlCmdSize) = 0;
141 
142     //!
143     //! \brief    Calculates maximum size for VVCP primitive level commands
144     //! \details  Client facing function to calculate maximum size for VVCP primitive level commands
145     //! \param    [out] sliceCommandsSize
146     //!           The maximum command buffer size for slice
147     //! \param    [out] slicePatchListSize
148     //!           The maximum command patch list size for slice
149     //! \param    [out] tileCommandsSize
150     //!           The maximum command buffer size for tile
151     //! \param    [out] tilePatchListSize
152     //!           The maximum command patch list size for tile
153     //! \return   MOS_STATUS
154     //!           MOS_STATUS_SUCCESS if success, else fail reason
155     //! \return   MOS_STATUS
156     //!           MOS_STATUS_SUCCESS if success, else fail reason
157     //!
158     virtual MOS_STATUS GetVvcpPrimitiveCmdSize(
159         uint32_t *sliceCommandsSize,
160         uint32_t *slicePatchListSize,
161         uint32_t *tileCommandsSize,
162         uint32_t *tilePatchListSize) = 0;
163 
164     //!
165     //! \brief    Store VVCP ALF APS data to the given ALF buffer
166     //!
167     //! \param    [in, out] buffer
168     //!           Buffer to store ALF APS data
169     //! \param    [in] alfApsArray
170     //!           Pointer to VVC ALF data array
171     //! \param    [in] activeAlfMask
172     //!           Active ALF mask
173     //!
174     //! \return   MOS_STATUS
175     //!           MOS_STATUS_SUCCESS if success, else fail reason
176     //!
177     virtual MOS_STATUS SetAlfApsDataBuffer(uint32_t *buffer, CodecVvcAlfData *alfApsArray, uint8_t activeAlfMask) = 0;
178 
179     //!
180     //! \brief    Get mmio registers
181     //!
182     //! \param    [in] index
183     //!           mmio registers index
184     //!
185     //! \return   [out] MmioRegistersVvcp*
186     //!           VVC mmio registers
187     //!
188     //virtual MmioRegistersVvcp* GetMmioRegisters(MHW_VDBOX_NODE_IND index)
189     //{
190     //    // TODO: new mechanism for VVC MMIO.
191     //};
192 
193     //!
194     //! \brief    Determines if the slice is P slice
195     //! \param    [in] sliceType
196     //!           slice type
197     //! \return   bool
198     //!           True if it's P slice, otherwise return false
199     //!
IsVvcPSlice(uint8_t sliceType)200     inline bool IsVvcPSlice(uint8_t sliceType)
201     {
202         return (sliceType < MHW_ARRAY_SIZE(m_vvcBsdSliceType)) ? (m_vvcBsdSliceType[sliceType] == vvcSliceP) : false;
203     }
204 
205     //!
206     //! \brief    Determines if the slice is B slice
207     //! \param    [in] sliceType
208     //!           slice type
209     //! \return   bool
210     //!           True if it's B slice, otherwise return false
211     //!
IsVvcBSlice(uint8_t sliceType)212     inline bool IsVvcBSlice(uint8_t sliceType)
213     {
214         return (sliceType < MHW_ARRAY_SIZE(m_vvcBsdSliceType)) ? (m_vvcBsdSliceType[sliceType] == vvcSliceB) : false;
215     }
216 
217     //!
218     //! \brief    Determines if the slice is I slice
219     //! \param    [in] sliceType
220     //!           slice type
221     //! \return   bool
222     //!           True if it's I slice, otherwise return false
223     //!
IsVvcISlice(uint8_t sliceType)224     inline bool IsVvcISlice(uint8_t sliceType)
225     {
226         return (sliceType < MHW_ARRAY_SIZE(m_vvcBsdSliceType)) ? (m_vvcBsdSliceType[sliceType] == vvcSliceI) : false;
227     }
228 
GetMappedCoeff(uint32_t coeffValue)229     uint32_t GetMappedCoeff(uint32_t coeffValue)
230     {
231         uint32_t mappedCoeff = 0;
232         if(alfCoeffMap.find(coeffValue) != alfCoeffMap.end())
233         {
234             mappedCoeff = alfCoeffMap.find(coeffValue)->second;
235         }
236         return mappedCoeff;
237     }
238 
239     _VVCP_CMD_DEF(_MHW_CMD_ALL_DEF_FOR_ITF);
240 
241 private:
242     const VvcSliceType m_vvcBsdSliceType[3] =
243     {
244         vvcSliceB,
245         vvcSliceP,
246         vvcSliceI
247     };
248     const std::map<uint32_t, uint32_t> alfCoeffMap = {
249         {1, 1},
250         {2, 2},
251         {4, 3},
252         {8, 4},
253         {16, 5},
254         {32, 6},
255         {64, 7}
256     };
257 
258     MEDIA_CLASS_DEFINE_END(mhw__vdbox__vvcp__Itf)
259 };
260 
261 }  // namespace vvcp
262 }  // namespace vdbox
263 }  // namespace mhw
264 
265 #endif  // __MHW_VDBOX_VVCP_ITF_H__
266