| 1 |
/* |
| 2 |
* Copyright (c) 2017, 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 codechal_utilities.h |
| 24 |
//! \brief Defines the common functions for codec. |
| 25 |
//! \details This modules implements utilities which are shared by encoder and decoder |
| 26 |
//! |
| 27 |
|
| 28 |
#ifndef __CODECHAL_UTILITIES_H__ |
| 29 |
#define __CODECHAL_UTILITIES_H__ |
| 30 |
|
| 31 |
#include "codechal_hw.h" |
| 32 |
#include "codec_def_common.h" |
| 33 |
|
| 34 |
class CodechalHwInterface; |
| 35 |
typedef struct _MHW_WALKER_PARAMS MHW_WALKER_PARAMS, *PMHW_WALKER_PARAMS; |
| 36 |
typedef struct _MHW_STATE_HEAP_INTERFACE MHW_STATE_HEAP_INTERFACE, *PMHW_STATE_HEAP_INTERFACE; |
| 37 |
typedef struct MHW_KERNEL_STATE *PMHW_KERNEL_STATE; |
| 38 |
typedef struct _MHW_RCS_SURFACE_PARAMS MHW_RCS_SURFACE_PARAMS, *PMHW_RCS_SURFACE_PARAMS; |
| 39 |
typedef struct _CODECHAL_SURFACE_CODEC_PARAMS CODECHAL_SURFACE_CODEC_PARAMS, *PCODECHAL_SURFACE_CODEC_PARAMS; |
| 40 |
|
| 41 |
typedef enum _CODECHAL_WALKER_DEGREE |
| 42 |
{ |
| 43 |
CODECHAL_NO_DEGREE, |
| 44 |
CODECHAL_45_DEGREE, |
| 45 |
CODECHAL_26_DEGREE, |
| 46 |
CODECHAL_46_DEGREE, // VP8 HybridPak2Pattern |
| 47 |
CODECHAL_26Z_DEGREE, // HEVC |
| 48 |
CODECHAL_45Z_DEGREE, // VP9 MB ENC I 16x16, P |
| 49 |
CODECHAL_26X_DEGREE, // HEVC |
| 50 |
CODECHAL_26ZX_DEGREE, // HEVC |
| 51 |
CODECHAL_45D_DEGREE, // HEVC 45 diamond walk pattern |
| 52 |
CODECHAL_45XD_DEGREE, // HEVC 45X diamond walk pattern |
| 53 |
CODECHAL_45X_DEGREE_ALT //HEVC 45X ALT walk pattern |
| 54 |
} CODECHAL_WALKER_DEGREE; |
| 55 |
|
| 56 |
typedef struct _CODECHAL_WALKER_CODEC_PARAMS |
| 57 |
{ |
| 58 |
uint32_t WalkerMode; |
| 59 |
bool bUseScoreboard; |
| 60 |
uint32_t dwResolutionX; |
| 61 |
uint32_t dwResolutionY; |
| 62 |
bool bNoDependency; |
| 63 |
CODECHAL_WALKER_DEGREE WalkerDegree; |
| 64 |
bool bUseVerticalRasterScan; |
| 65 |
uint32_t wPictureCodingType; |
| 66 |
bool bMbEncIFrameDistInUse; |
| 67 |
bool bMbaff; |
| 68 |
uint32_t bDirectSpatialMVPredFlag; |
| 69 |
bool bColorbitSupported; |
| 70 |
uint32_t dwNumSlices; |
| 71 |
uint16_t usSliceHeight; |
| 72 |
bool bGroupIdSelectSupported; |
| 73 |
uint8_t ucGroupId; |
| 74 |
uint32_t ScoreboardMask; |
| 75 |
uint16_t usTotalThreadNumPerLcu; //Used by Gen10 HEVC |
| 76 |
} CODECHAL_WALKER_CODEC_PARAMS, *PCODECHAL_WALKER_CODEC_PARAMS; |
| 77 |
|
| 78 |
typedef struct _CODECHAL_SURFACE_CODEC_PARAMS |
| 79 |
{ |
| 80 |
uint32_t Mode; |
| 81 |
bool bIs2DSurface; |
| 82 |
bool bUseUVPlane; |
| 83 |
bool bUseAdvState; |
| 84 |
bool bMediaBlockRW; |
| 85 |
bool bUse16UnormSurfaceFormat; // Force surface format to R16_UNORM |
| 86 |
bool bUse32UnormSurfaceFormat; // Force surface format to R32_UNORM |
| 87 |
bool bUseARGB8Format; // Force surface format to ARGB8 for Ds+Copy kernel |
| 88 |
bool bCheckCSC8Format; // Force surface format Y410/ARGB10/AYUV to R8*4 for Ds+Copy kernel |
| 89 |
bool bUse32UINTSurfaceFormat; |
| 90 |
bool bRenderTarget; |
| 91 |
bool bIsWritable; |
| 92 |
bool bUseHalfHeight; |
| 93 |
PMOS_SURFACE psSurface; // 2D surface parameters |
| 94 |
PMOS_RESOURCE presBuffer; // Buffer parameters |
| 95 |
uint32_t dwSize; // Buffer size |
| 96 |
uint32_t dwOffset; // Buffer offset |
| 97 |
uint32_t dwBindingTableOffset; // Binding table offset for given surface |
| 98 |
uint32_t dwUVBindingTableOffset; // Binding table offset for the UV plane |
| 99 |
uint32_t dwVerticalLineStride; |
| 100 |
uint32_t dwVerticalLineStrideOffset; |
| 101 |
uint8_t ucVDirection; |
| 102 |
uint32_t dwCacheabilityControl; |
| 103 |
bool bForceChromaFormat; |
| 104 |
uint32_t ChromaType; |
| 105 |
bool bRawSurface; |
| 106 |
uint8_t ucSurfaceStateId; |
| 107 |
|
| 108 |
uint32_t dwWidthInUse; |
| 109 |
uint32_t dwHeightInUse; |
| 110 |
|
| 111 |
} CODECHAL_SURFACE_CODEC_PARAMS, *PCODECHAL_SURFACE_CODEC_PARAMS; |
| 112 |
|
| 113 |
typedef struct _CODECHAL_KERNEL_HEADER |
| 114 |
{ |
| 115 |
union |
| 116 |
{ |
| 117 |
struct |
| 118 |
{ |
| 119 |
uint32_t : 6; |
| 120 |
uint32_t KernelStartPointer : 26; // GTT 31:6 |
| 121 |
}; |
| 122 |
struct |
| 123 |
{ |
| 124 |
uint32_t Value; |
| 125 |
}; |
| 126 |
}; |
| 127 |
} CODECHAL_KERNEL_HEADER, *PCODECHAL_KERNEL_HEADER; |
| 128 |
|
| 129 |
//! |
| 130 |
//! \brief Initialize media object walker parameters |
| 131 |
//! |
| 132 |
//! \param [in] hwInterface |
| 133 |
//! pointer to HW interface |
| 134 |
//! \param [in,out] walkerParams |
| 135 |
//! Pointer to MHW_WALKER_PARAM, which will be filled with media object walker parameters |
| 136 |
//! \param [in] walkerCodecParams |
| 137 |
//! Pointer to walkerCodecParams. Specify codec parameters |
| 138 |
//! |
| 139 |
//! \return MOS_STATUS |
| 140 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 141 |
//! |
| 142 |
MOS_STATUS CodecHalInitMediaObjectWalkerParams( |
| 143 |
CodechalHwInterface *hwInterface, |
| 144 |
PMHW_WALKER_PARAMS walkerParams, |
| 145 |
PCODECHAL_WALKER_CODEC_PARAMS walkerCodecParams); |
| 146 |
|
| 147 |
//! |
| 148 |
//! \brief Gets a kernel information for a specific KUID from the combined kernel |
| 149 |
//! \details Gets a kernel information for a specific KUID from the combined kernel |
| 150 |
//! |
| 151 |
//! \param [in] kernelBase |
| 152 |
//! The combined kernel |
| 153 |
//! \param [in] kernelUID |
| 154 |
//! The unique kernel identifier in the combined kernel |
| 155 |
//! \param [in,out] kernelBinary |
| 156 |
//! The binary of the kernel specified by dwKUID |
| 157 |
//! \param [in,out] size |
| 158 |
//! The size of the kernel specified by dwKUID |
| 159 |
//! |
| 160 |
//! \return MOS_STATUS |
| 161 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 162 |
//! |
| 163 |
MOS_STATUS CodecHalGetKernelBinaryAndSize( |
| 164 |
uint8_t* kernelBase, |
| 165 |
uint32_t kernelUID, |
| 166 |
uint8_t** kernelBinary, |
| 167 |
uint32_t* size); |
| 168 |
|
| 169 |
//! |
| 170 |
//! \brief Get the surface width in bytes |
| 171 |
//! \details Get the suface width in bytes |
| 172 |
//! |
| 173 |
//! \param [in] surface |
| 174 |
//! Surface pointer |
| 175 |
//! \param [out] widthInBytes |
| 176 |
//! Output the surface width |
| 177 |
//! |
| 178 |
//! \return void |
| 179 |
//! |
| 180 |
void CodecHal_GetSurfaceWidthInBytes( |
| 181 |
PMOS_SURFACE surface, |
| 182 |
uint32_t *widthInBytes); |
| 183 |
|
| 184 |
//! |
| 185 |
//! \brief Set RCS surface state |
| 186 |
//! \details Set RCS surface state |
| 187 |
//! |
| 188 |
//! \param [in] hwInterface |
| 189 |
//! CodechalHwInterface pointer |
| 190 |
//! \param [in,out] cmdBuffer |
| 191 |
//! MOS_COMMAND_BUFFER pointer |
| 192 |
//! \param [in] surfaceCodecParams |
| 193 |
//! CODECHAL_SURFACE_CODEC_PARAMS pointer. Return |
| 194 |
//! \param [in] kernelState |
| 195 |
//! MHW_KERNEL_STATE pointer |
| 196 |
//! |
| 197 |
//! \return MOS_STATUS |
| 198 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 199 |
//! |
| 200 |
MOS_STATUS CodecHalSetRcsSurfaceState( |
| 201 |
CodechalHwInterface *hwInterface, |
| 202 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 203 |
PCODECHAL_SURFACE_CODEC_PARAMS surfaceCodecParams, |
| 204 |
PMHW_KERNEL_STATE kernelState); |
| 205 |
|
| 206 |
//! |
| 207 |
//! \brief Get surface information |
| 208 |
//! |
| 209 |
//! \param [in] osInterface |
| 210 |
//! OS interface handle |
| 211 |
//! \param [in,out] surface |
| 212 |
//! Pointer to MOS_SURFACE. Specify the OsResource and return the surface info. |
| 213 |
//! |
| 214 |
//! \return MOS_STATUS |
| 215 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 216 |
//! |
| 217 |
MOS_STATUS CodecHalGetResourceInfo( |
| 218 |
PMOS_INTERFACE osInterface, |
| 219 |
PMOS_SURFACE surface); |
| 220 |
|
| 221 |
//! |
| 222 |
//! \brief Allocate data list with specific type and length |
| 223 |
//! |
| 224 |
//! \param [in,out] dataList |
| 225 |
//! Pointer to a type * pointer. Specify the address of the memory handles |
| 226 |
//! \param [in] length |
| 227 |
//! Specify the number of data members |
| 228 |
//! |
| 229 |
//! \return MOS_STATUS |
| 230 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 231 |
//! |
| 232 |
template <class type> |
| 233 |
MOS_STATUS CodecHalAllocateDataList(type **dataList, uint32_t length) |
| 234 |
{ |
| 235 |
type *ptr; |
| 236 |
ptr = (type *)MOS_AllocAndZeroMemory(sizeof(type) * length); |
| 237 |
if (ptr == nullptr) |
| 238 |
{ |
| 239 |
CODECHAL_PUBLIC_ASSERTMESSAGE("No memory to allocate CodecHal data list."); |
| 240 |
return MOS_STATUS_NO_SPACE; |
| 241 |
} |
| 242 |
for (uint32_t i = 0; i < length; i++) |
| 243 |
{ |
| 244 |
dataList[i] = &(ptr[i]); |
| 245 |
} |
| 246 |
return MOS_STATUS_SUCCESS; |
| 247 |
} |
| 248 |
|
| 249 |
//! |
| 250 |
//! \brief Free data list |
| 251 |
//! |
| 252 |
//! \param [in,out] dataList |
| 253 |
//! Pointer to a type * pointer. Specify the address of the memory handles |
| 254 |
//! \param [in] length |
| 255 |
//! Specify the number of data members |
| 256 |
//! |
| 257 |
//! \return MOS_STATUS |
| 258 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 259 |
//! |
| 260 |
template <class type> |
| 261 |
MOS_STATUS CodecHalFreeDataList(type **dataList, uint32_t length) |
| 262 |
{ |
| 263 |
type* ptr; |
| 264 |
ptr = dataList[0]; |
| 265 |
if (ptr) |
| 266 |
{ |
| 267 |
MOS_FreeMemory(ptr); |
| 268 |
} |
| 269 |
for (uint32_t i = 0; i < length; i++) |
| 270 |
{ |
| 271 |
dataList[i] = nullptr; |
| 272 |
} |
| 273 |
|
| 274 |
return MOS_STATUS_SUCCESS; |
| 275 |
} |
| 276 |
#endif |