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