xref: /aosp_15_r20/external/intel-media-driver/media_common/agnostic/common/vp/hal/vp_common.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2022-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     vp_common.h
24 //! \brief    clarify common utilities for vphal
25 //! \details  clarify common utilities for vphal including:
26 //!           some marcro, enum, union, structure, function
27 //!
28 #ifndef __VP_COMMON_H__
29 #define __VP_COMMON_H__
30 
31 #if EMUL || VPHAL_LIB
32 
33 #include "support.h"
34 
35 #endif  // EMUL || VPHAL_LIB
36 
37 #include "mos_os.h"
38 #include "vp_common_hdr.h"
39 #include "media_common_defs.h"
40 #include "vp_common_defs.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 //! \brief  Surface cache attributes
47 //!
48 #define VPHAL_SET_SURF_MEMOBJCTL(VpField, GmmUsageEnum)                                                                      \
49     {                                                                                                                        \
50         Usage      = GmmUsageEnum;                                                                                           \
51         MemObjCtrl = pOsInterface->pfnCachePolicyGetMemoryObject(Usage, pOsInterface->pfnGetGmmClientContext(pOsInterface)); \
52         VpField    = MemObjCtrl.DwordValue;                                                                                  \
53     }
54 
55 //!
56 //! \def WITHIN_BOUNDS(a, min, max)
57 //! Calcualte if \a a within the range of  [\a min, \a max].
58 //!
59 #define WITHIN_BOUNDS(a, min, max) (((a) >= (min)) && ((a) <= (max)))
60 
61 //!
62 //! \def SAME_SIZE_RECT(rect1, rect2)
63 //! Compare if the size of two rectangles is the same
64 //!
65 #define SAME_SIZE_RECT(rect1, rect2)                                   \
66     (((rect1).right - (rect1).left == (rect2).right - (rect2).left) && \
67         ((rect1).bottom - (rect1).top == (rect2).bottom - (rect2).top))
68 
69 //!
70 //! \def IS_YUV_FULL_RANGE(_a)
71 //! Check if YUV full range
72 //!
73 #define IS_YUV_FULL_RANGE(_a) (_a == CSpace_BT601_FullRange ||     \
74                                _a == CSpace_BT709_FullRange ||     \
75                                _a == CSpace_BT601Gray_FullRange || \
76                                _a == CSpace_BT2020_FullRange)
77 
78 //! Structure VPHAL_SURFACE
79 //! \brief DDI-VPHAL surface definition
80 //!
81 struct VPHAL_SURFACE
82 {
83     // Color Information
84     VPHAL_CSPACE  ColorSpace    = CSpace_None;  //!<Color Space
85     bool          ExtendedGamut = false;        //!<Extended Gamut Flag
86     int32_t       iPalette      = 0;            //!<Palette Allocation
87     VPHAL_PALETTE Palette       = {};           //!<Palette data
88 
89     // Rendering parameters
90     RECT                   rcSrc           = {0, 0, 0, 0};  //!< Source rectangle
91     RECT                   rcDst           = {0, 0, 0, 0};  //!< Destination rectangle
92     RECT                   rcMaxSrc        = {0, 0, 0, 0};  //!< Max source rectangle
93     PVPHAL_BLENDING_PARAMS pBlendingParams = nullptr;       //!< Blending parameters
94     PVPHAL_LUMAKEY_PARAMS  pLumaKeyParams  = nullptr;       //!< Luma keying parameters
95     PVPHAL_PROCAMP_PARAMS  pProcampParams  = nullptr;
96     ;                                                //!< Procamp parameters
97     PVPHAL_IEF_PARAMS pIEFParams         = nullptr;  //!< IEF parameters
98     bool              bCalculatingAlpha  = false;    //!< Alpha calculation parameters
99     bool              bQueryVariance     = false;    //!< enable variance query
100     bool              bDirectionalScalar = false;    //!< Vebox Directional Scalar
101     bool              bFastColorFill     = false;    //!< enable fast color fill without copy surface
102     bool              bMaxRectChanged    = false;    //!< indicate rcMaxSrc been updated
103     bool              b16UsrPtr          = false;    //!< is 16 byte aligned system linear memory.
104     bool              bVEBOXCroppingUsed = false;    //!< Vebox crop case need use rcSrc as vebox input.
105     bool              bXORComp           = false;    //!< is mono-chroma composite mode.
106 
107     // Interlaced Scaling
108     bool                bInterlacedScaling    = false;          //!< Interlaced scaling
109     bool                bFieldWeaving         = false;          //!< Field Weaving
110     VPHAL_ISCALING_TYPE InterlacedScalingType = ISCALING_NONE;  //!< Interlaced scaling type for new interlaced scaling mode
111 
112     // Advanced Processing
113     PVPHAL_DI_PARAMS        pDeinterlaceParams = nullptr;
114     PVPHAL_DENOISE_PARAMS   pDenoiseParams     = nullptr;  //!< Denoise
115     PVPHAL_COLORPIPE_PARAMS pColorPipeParams   = nullptr;  //!< ColorPipe
116 
117     // Frame ID and reference samples -> for advanced processing
118     int32_t        FrameID      = 0;
119     uint32_t       uFwdRefCount = 0;
120     uint32_t       uBwdRefCount = 0;
121     PVPHAL_SURFACE pFwdRef      = nullptr;
122     PVPHAL_SURFACE pBwdRef      = nullptr;
123 
124     // VPHAL_SURFACE Linked list
125     PVPHAL_SURFACE pNext = nullptr;
126 
127     //--------------------------------------
128     // FIELDS TO BE SETUP BY VPHAL int32_tERNALLY
129     //--------------------------------------
130     uint32_t                 dwWidth                   = 0;                         //!<  Surface width
131     uint32_t                 dwHeight                  = 0;                         //!<  Surface height
132     uint32_t                 dwPitch                   = 0;                         //!<  Surface pitch
133     uint32_t                 dwYPitch                  = 0;                         //!<  Surface Y plane pitch
134     uint32_t                 dwUPitch                  = 0;                         //!<  Surface U plane pitch
135     uint32_t                 dwVPitch                  = 0;                         //!<  Surface V plane pitch
136     MOS_TILE_TYPE            TileType                  = MOS_TILE_X;                //!<  Tile Type
137     MOS_TILE_MODE_GMM        TileModeGMM               = MOS_TILE_LINEAR_GMM;       //!<  Tile Mode from GMM Definition
138     bool                     bGMMTileEnabled           = false;                     //!<  GMM Tile Mode Flag
139     bool                     bOverlay                  = false;                     //!<  Overlay Surface
140     bool                     bFlipChain                = false;                     //!<  FlipChain Surface
141     VPHAL_PLANE_OFFSET       YPlaneOffset              = {0, 0, 0, 0};              //!<  Y surface plane offset
142     VPHAL_PLANE_OFFSET       UPlaneOffset              = {0, 0, 0, 0};              //!<  U surface plane offset
143     VPHAL_PLANE_OFFSET       VPlaneOffset              = {0, 0, 0, 0};              //!<  V surface plane offset
144     int32_t                  iLayerID                  = 0;                         //!<  Layer index (0-based index)
145     VPHAL_SCALING_MODE       ScalingMode               = VPHAL_SCALING_NEAREST;     //!<  Scaling Mode
146     VPHAL_SCALING_PREFERENCE ScalingPreference         = VPHAL_SCALING_PREFER_SFC;  //!<  Scaling preference
147     bool                     bIEF                      = false;                     //!<  IEF flag
148     uint32_t                 dwSlicePitch              = 0;                         //!<  SlicePitch of a 3D surface(GT-PIN support)
149 
150     //--------------------------------------
151     // FIELDS TO BE PROVIDED BY DDI
152     //--------------------------------------
153     // Sample information
154     MOS_FORMAT         Format     = Format_None;              //!<  Surface format
155     VPHAL_SURFACE_TYPE SurfType   = SURF_NONE;                //!<  Surface type (context)
156     VPHAL_SAMPLE_TYPE  SampleType = SAMPLE_PROGRESSIVE;       //!<  Interlaced/Progressive sample type
157     uint32_t           dwDepth    = 0;                        //!<  Surface depth
158     MOS_S3D_CHANNEL    Channel    = MOS_S3D_NONE;             //!<  Channel
159     uint32_t           dwOffset   = 0;                        //!<  Surface Offset (Y/Base)
160     MOS_RESOURCE       OsResource = {};                       //!<  Surface resource
161     VPHAL_ROTATION     Rotation   = VPHAL_ROTATION_IDENTITY;  //!<  0: 0 degree, 1: 90 degree, 2: 180 degree, 3: 270 degreee
162 
163     // Chroma siting
164     uint32_t ChromaSiting  = CHROMA_SITING_NONE;
165     bool     bChromaSiting = false;  //!<  Chromasiting flag
166 
167     // Surface compression mode, enable flags
168     bool bCompressible = false;  // The surface is compressible, means there are additional 128 bit for MMC no matter it is compressed or not
169     // The bIsCompressed in surface allocation structure should use this flag to initialize to allocate a compressible surface
170     bool                  bIsCompressed     = false;  // The surface is compressed, VEBox output can only support horizontal mode, but input can be horizontal / vertical
171     MOS_RESOURCE_MMC_MODE CompressionMode   = MOS_MMC_DISABLED;
172     uint32_t              CompressionFormat = 0;
173 
174     //Surface cache Usage
175     uint32_t CacheSetting = 0;
176 #if (_DEBUG || _RELEASE_INTERNAL)
177     uint32_t oldCacheSetting = 0;
178 #endif
179 
180     bool bUseSampleUnorm    = false;  //!<  true: sample unorm is used, false: DScaler or AVS is used.
181     bool bUseSamplerLumakey = false;  //!<  true: sampler lumakey is used, false: lumakey is disabled or EU computed lumakey is used.
182     //------------------------------------------
183     // HDR related parameters, provided by DDI
184     //------------------------------------------
185     PVPHAL_HDR_PARAMS pHDRParams            = nullptr;
186     VPHAL_GAMMA_TYPE  GammaType             = VPHAL_GAMMA_NONE;  //!<Gamma Type
187     bool              bPreAPGWorkloadEnable = false;             //!< Previous Surface Execution Path
188 
189     // 3DLUT parameters
190     PVPHAL_3DLUT_PARAMS p3DLutParams = nullptr;  //!< 3DLut Mapping Params
191 
192     PVPHAL_GAMUT_PARAMS pGamutParams       = nullptr;  //!< Gamut Compression & Expansion
193 };
194 
195 //!
196 //! \brief  VEBOX IECP parameters
197 //!
198 class VPHAL_VEBOX_IECP_PARAMS
199 {
200 public:
201     PVPHAL_COLORPIPE_PARAMS pColorPipeParams;
202     PVPHAL_PROCAMP_PARAMS   pProcAmpParams;
203     MOS_FORMAT              dstFormat;
204     MOS_FORMAT              srcFormat;
205 
206     // CSC params
207     bool     bCSCEnable;      // Enable CSC transform
208     float *  pfCscCoeff;      // [3x3] CSC Coeff matrix
209     float *  pfCscInOffset;   // [3x1] CSC Input Offset matrix
210     float *  pfCscOutOffset;  // [3x1] CSC Output Offset matrix
211     bool     bAlphaEnable;    // Alpha Enable Param
212     uint16_t wAlphaValue;     // Color Pipe Alpha Value
213 
214     // Front End CSC params
215     bool   bFeCSCEnable;      // Enable Front End CSC transform
216     float *pfFeCscCoeff;      // [3x3] Front End CSC Coeff matrix
217     float *pfFeCscInOffset;   // [3x1] Front End CSC Input Offset matrix
218     float *pfFeCscOutOffset;  // [3x1] Front End CSC Output Offset matrix
219 
VPHAL_VEBOX_IECP_PARAMS()220     VPHAL_VEBOX_IECP_PARAMS()
221     {
222         pColorPipeParams = nullptr;
223         pProcAmpParams   = nullptr;
224         dstFormat        = Format_Any;
225         srcFormat        = Format_Any;
226         bCSCEnable       = false;
227         pfCscCoeff       = nullptr;
228         pfCscInOffset    = nullptr;
229         pfCscOutOffset   = nullptr;
230         bAlphaEnable     = false;
231         wAlphaValue      = 0;
232 
233         bFeCSCEnable     = false;
234         pfFeCscCoeff     = nullptr;
235         pfFeCscInOffset  = nullptr;
236         pfFeCscOutOffset = nullptr;
237     }
~VPHAL_VEBOX_IECP_PARAMS()238     virtual ~VPHAL_VEBOX_IECP_PARAMS()
239     {
240         pColorPipeParams = nullptr;
241         pProcAmpParams   = nullptr;
242     }
Init()243     virtual void Init()
244     {
245         pColorPipeParams = nullptr;
246         pProcAmpParams   = nullptr;
247 
248         dstFormat = Format_Any;
249         srcFormat = Format_Any;
250 
251         bCSCEnable     = false;
252         pfCscCoeff     = nullptr;
253         pfCscInOffset  = nullptr;
254         pfCscOutOffset = nullptr;
255         bAlphaEnable   = false;
256         wAlphaValue    = 0;
257     }
GetExtParams()258     virtual void *GetExtParams() { return nullptr; }
259 };
260 
261 //!
262 //! \brief    Initial the Type/TileType fields in Alloc Params structure
263 //! \details  Initial the Type/TileType fields in Alloc Params structure
264 //!           - Use the last type from GMM resource
265 //! \param    [in, out] pAllocParams
266 //!           Pointer to MOS_ALLOC_GFXRES_PARAMS
267 //! \param    [in] pSurface
268 //!           Pointer to VPHAL_SURFACE
269 //! \param    [in] DefaultResType
270 //!           Expected Resource Type
271 //! \param    [in] DefaultTileType
272 //!           Expected Surface Tile Type
273 //!
274 void VpHal_AllocParamsInitType(
275     PMOS_ALLOC_GFXRES_PARAMS pAllocParams,
276     PVPHAL_SURFACE           pSurface,
277     MOS_GFXRES_TYPE          DefaultResType,
278     MOS_TILE_TYPE            DefaultTileType);
279 
280 //!
281 //! \brief    Get Surface Info from OsResource
282 //! \details  Update surface info in PVPHAL_SURFACE based on allocated OsResource
283 //! \param    [in] pOsInterface
284 //!           Pointer to MOS_INTERFACE
285 //! \param    [in] pInfo
286 //!           Pointer to VPHAL_GET_SURFACE_INFO
287 //! \param    [in,out] pSurface
288 //!           Pointer to VPHAL_SURFACE
289 //! \return   MOS_STATUS
290 //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
291 //!
292 MOS_STATUS VpHal_GetSurfaceInfo(
293     PMOS_INTERFACE          pOsInterface,
294     PVPHAL_GET_SURFACE_INFO pInfo,
295     PVPHAL_SURFACE          pSurface);
296 
297 //!
298 //! \brief
299 //! \details  Get CSC matrix in a form usable by Vebox, SFC and IECP kernels
300 //! \param    [in] SrcCspace
301 //!           Source Cspace
302 //! \param    [in] DstCspace
303 //!           Destination Cspace
304 //! \param    [out] pfCscCoeff
305 //!           [3x3] Coefficients matrix
306 //! \param    [out] pfCscInOffset
307 //!           [3x1] Input Offset matrix
308 //! \param    [out] pfCscOutOffset
309 //!           [3x1] Output Offset matrix
310 //! \return   void
311 //!
312 void VpHal_GetCscMatrix(
313     VPHAL_CSPACE SrcCspace,
314     VPHAL_CSPACE DstCspace,
315     float *      pfCscCoeff,
316     float *      pfCscInOffset,
317     float *      pfCscOutOffset);
318 
319 //! \brief    Transfer float type to half precision float type
320 //! \details  Transfer float type to half precision float (16bit) type
321 //! \param    [in] fInput
322 //!           input FP32 number
323 //! \return   uint16_t
324 //!           half precision float value in bit
325 //!
326 uint16_t VpHal_FloatToHalfFloat(
327     float fInput);
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif  // __VP_COMMON_H__
334