| 1 |
/* |
| 2 |
* Copyright (c) 2011-2023, 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_vdenc_avc.h |
| 24 |
//! \brief This file defines the base C++ class/interface for AVC VDENC encoding |
| 25 |
//! to be used across CODECHAL components. |
| 26 |
//! |
| 27 |
|
| 28 |
#ifndef __CODECHAL_VDENC_AVC_H__ |
| 29 |
#define __CODECHAL_VDENC_AVC_H__ |
| 30 |
|
| 31 |
#include "codechal_encode_avc_base.h" |
| 32 |
#define CODECHAL_VDENC_AVC_MMIO_MFX_LRA_0_VMC240 0xF5F0EF00 |
| 33 |
#define CODECHAL_VDENC_AVC_MMIO_MFX_LRA_1_VMC240 0xFFFBFAF6 |
| 34 |
#define CODECHAL_VDENC_AVC_MMIO_MFX_LRA_2_VMC240 0x000002D3 |
| 35 |
#define CODECHAL_ENCODE_AVC_BRC_MIN_QP 1 |
| 36 |
#define CODECHAL_VDENC_AVC_MB_SLICE_TRHESHOLD 12 |
| 37 |
|
| 38 |
#define CODECHAL_VDENC_AVC_BRC_HUC_STATUS_REENCODE_MASK (1 << 31) |
| 39 |
#define CODECHAL_VDENC_AVC_BRC_HUC_STATUS_SKIP_FRAME_MASK (1 << 30) |
| 40 |
#define CODECHAL_VDENC_AVC_BRC_HUC_STATUS_ERROR_MASK (1 << 29) |
| 41 |
#define CODECHAL_VDENC_AVC_BRC_HUC_STATUS_SCENE_CHANGE_MASK (1 << 28) |
| 42 |
#define CODECHAL_VDENC_AVC_BRC_HUC_STATUS_ARITHMETIC_OVERFLOW_ERROR_MASK (1 << 27) |
| 43 |
#define CODECHAL_VDENC_AVC_BRC_HUC_STATUS_MEMORY_ACCESS_ERROR_MASK (1 << 26) |
| 44 |
#define CODECHAL_VDENC_AVC_BRC_HUC_STATUS_HISTORY_BUFFER_ERROR_MASK (1 << 25) |
| 45 |
#define CODECHAL_VDENC_AVC_BRC_HUC_STATUS_DMEM_ERROR_MASK (1 << 24) |
| 46 |
|
| 47 |
#define CODECHAL_VDENC_AVC_BRC_MIN_QP 10 |
| 48 |
#define CODECHAL_VDENC_AVC_CQP_NUM_OF_PASSES 1 // No standalone PAK IPCM pass for VDENC |
| 49 |
|
| 50 |
#define CODECHAL_VDENC_AVC_BRC_HISTORY_BUF_SIZE 0x1000 |
| 51 |
#define CODECHAL_VDENC_AVC_BRC_DEBUG_BUF_SIZE 0x1000 |
| 52 |
#define CODECHAL_VDENC_AVC_BRC_MB_BUDGET_SIZE 104 |
| 53 |
|
| 54 |
#define CODECHAL_VDENC_AVC_BRC_TOPQPDELTATHRFORADAPT2PASS 2 |
| 55 |
#define CODECHAL_VDENC_AVC_BRC_BOTQPDELTATHRFORADAPT2PASS 1 |
| 56 |
#define CODECHAL_VDENC_AVC_BRC_TOPFRMSZTHRFORADAPT2PASS 32 |
| 57 |
#define CODECHAL_VDENC_AVC_BRC_BOTFRMSZTHRFORADAPT2PASS 24 |
| 58 |
|
| 59 |
#define CODECHAL_VDENC_AVC_AVBR_TOPQPDELTATHRFORADAPT2PASS 2 |
| 60 |
#define CODECHAL_VDENC_AVC_AVBR_BOTQPDELTATHRFORADAPT2PASS 2 |
| 61 |
#define CODECHAL_VDENC_AVC_AVBR_TOPFRMSZTHRFORADAPT2PASS 48 |
| 62 |
#define CODECHAL_VDENC_AVC_AVBR_BOTFRMSZTHRFORADAPT2PASS 32 |
| 63 |
|
| 64 |
#define CODECHAL_VDENC_AVC_BRC_TOPQPDELTATHRFORADAPT2PASS_4K 5 |
| 65 |
#define CODECHAL_VDENC_AVC_BRC_BOTQPDELTATHRFORADAPT2PASS_4K 5 |
| 66 |
#define CODECHAL_VDENC_AVC_BRC_TOPFRMSZTHRFORADAPT2PASS_4K 80 |
| 67 |
#define CODECHAL_VDENC_AVC_BRC_BOTFRMSZTHRFORADAPT2PASS_4K 80 |
| 68 |
|
| 69 |
#define CODECHAL_VDENC_AVC_STATIC_FRAME_ZMV_PERCENT 80 |
| 70 |
#define CODECHAL_VDENC_AVC_STATIC_FRAME_INTRACOSTSCLRatioP 240 |
| 71 |
|
| 72 |
//dynamic deviation thresholds calculation |
| 73 |
#define CODECHAL_VDENC_AVC_N_DEV_THRESHLDS 8 |
| 74 |
#define CODECHAL_VDENC_AVC_DEV_STD_FPS 30. |
| 75 |
#define CODECHAL_VDENC_AVC_BPS_RATIO_LOW 0.1 |
| 76 |
#define CODECHAL_VDENC_AVC_BPS_RATIO_HIGH 3.5 |
| 77 |
#define CODECHAL_VDENC_AVC_POS_MULT_I 50 |
| 78 |
#define CODECHAL_VDENC_AVC_NEG_MULT_I -50 |
| 79 |
#define CODECHAL_VDENC_AVC_POS_MULT_PB 50 |
| 80 |
#define CODECHAL_VDENC_AVC_NEG_MULT_PB -50 |
| 81 |
#define CODECHAL_VDENC_AVC_POS_MULT_VBR 100 |
| 82 |
#define CODECHAL_VDENC_AVC_NEG_MULT_VBR -50 |
| 83 |
|
| 84 |
#define __CODEGEN_BITFIELD(l, h) (h) - (l) + 1 |
| 85 |
//! |
| 86 |
//! \brief CODECHAL_VDENC_STREAMIN_STATE |
| 87 |
//! \details |
| 88 |
//! |
| 89 |
//! |
| 90 |
struct CODECHAL_VDENC_STREAMIN_STATE |
| 91 |
{ |
| 92 |
union |
| 93 |
{ |
| 94 |
//!< DWORD 0 |
| 95 |
struct |
| 96 |
{ |
| 97 |
uint32_t RegionOfInterestRoiSelection : __CODEGEN_BITFIELD(0, 7); //!< Region of Interest (ROI) Selection |
| 98 |
uint32_t Forceintra : __CODEGEN_BITFIELD(8, 8); //!< FORCEINTRA |
| 99 |
uint32_t Forceskip : __CODEGEN_BITFIELD(9, 9); //!< FORCESKIP |
| 100 |
uint32_t Reserved10 : __CODEGEN_BITFIELD(10, 31); //!< Reserved |
| 101 |
}; |
| 102 |
uint32_t Value; |
| 103 |
} DW0; |
| 104 |
union |
| 105 |
{ |
| 106 |
//!< DWORD 1 |
| 107 |
struct |
| 108 |
{ |
| 109 |
uint32_t Qpprimey : __CODEGEN_BITFIELD(0, 7); //!< QPPRIMEY |
| 110 |
uint32_t Targetsizeinword : __CODEGEN_BITFIELD(8, 15); //!< TargetSizeInWord |
| 111 |
uint32_t Maxsizeinword : __CODEGEN_BITFIELD(16, 23); //!< MaxSizeInWord |
| 112 |
uint32_t Reserved56 : __CODEGEN_BITFIELD(24, 31); //!< Reserved |
| 113 |
}; |
| 114 |
uint32_t Value; |
| 115 |
} DW1; |
| 116 |
union |
| 117 |
{ |
| 118 |
//!< DWORD 2 |
| 119 |
struct |
| 120 |
{ |
| 121 |
uint32_t FwdPredictorX : __CODEGEN_BITFIELD(0, 15); //!< Fwd Predictor.X |
| 122 |
uint32_t FwdPredictorY : __CODEGEN_BITFIELD(16, 31); //!< Fwd Predictor.Y |
| 123 |
}; |
| 124 |
uint32_t Value; |
| 125 |
} DW2; |
| 126 |
union |
| 127 |
{ |
| 128 |
//!< DWORD 3 |
| 129 |
struct |
| 130 |
{ |
| 131 |
uint32_t BwdPredictorX : __CODEGEN_BITFIELD(0, 15); //!< Bwd Predictor.X |
| 132 |
uint32_t BwdPredictorY : __CODEGEN_BITFIELD(16, 31); //!< Bwd Predictor.Y |
| 133 |
}; |
| 134 |
uint32_t Value; |
| 135 |
} DW3; |
| 136 |
union |
| 137 |
{ |
| 138 |
//!< DWORD 4 |
| 139 |
struct |
| 140 |
{ |
| 141 |
uint32_t FwdRefid0 : __CODEGEN_BITFIELD(0, 3); //!< Fwd RefID0 |
| 142 |
uint32_t BwdRefid0 : __CODEGEN_BITFIELD(4, 7); //!< Bwd RefID0 |
| 143 |
uint32_t Reserved136 : __CODEGEN_BITFIELD(8, 31); //!< Reserved |
| 144 |
}; |
| 145 |
uint32_t Value; |
| 146 |
} DW4; |
| 147 |
|
| 148 |
uint32_t Reserved160[11]; //!< Reserved |
| 149 |
|
| 150 |
//! \name Local enumerations |
| 151 |
|
| 152 |
//! \brief FORCEINTRA |
| 153 |
//! \details |
| 154 |
//! This field specifies whether current macroblock should be coded as an |
| 155 |
//! intra macroblock. |
| 156 |
//! It is illegal to enable both ForceSkip and ForceIntra for |
| 157 |
//! the same macroblock. |
| 158 |
//! This should be disabled if Rolling-I is enabled in the |
| 159 |
//! VDEnc Image State. |
| 160 |
enum FORCEINTRA |
| 161 |
{ |
| 162 |
FORCEINTRA_DISABLE = 0, //!< VDEnc determined macroblock type |
| 163 |
FORCEINTRA_ENABLE = 1, //!< Force to be coded as an intra macroblock |
| 164 |
}; |
| 165 |
|
| 166 |
//! \brief FORCESKIP |
| 167 |
//! \details |
| 168 |
//! This field specifies whether current macroblock should be coded as a |
| 169 |
//! skipped macroblock. |
| 170 |
//! It is illegal to enable both ForceSkip and ForceIntra for |
| 171 |
//! the same macroblock. |
| 172 |
//! This should be disabled if Rolling-I is enabled in the |
| 173 |
//! VDEnc Image State. |
| 174 |
//! It is illegal to enable ForceSkip for I-Frames. |
| 175 |
enum FORCESKIP |
| 176 |
{ |
| 177 |
FORCESKIP_DISABLE = 0, //!< VDEnc determined macroblock type |
| 178 |
FORCESKIP_ENABLE = 1, //!< Force to be coded as a skipped macroblock |
| 179 |
}; |
| 180 |
|
| 181 |
//! \brief QPPRIMEY |
| 182 |
//! \details |
| 183 |
//! Quantization parameter for Y. |
| 184 |
enum QPPRIMEY |
| 185 |
{ |
| 186 |
QPPRIMEY_UNNAMED0 = 0, //!< No additional details |
| 187 |
QPPRIMEY_UNNAMED51 = 51, //!< No additional details |
| 188 |
}; |
| 189 |
|
| 190 |
CODECHAL_VDENC_STREAMIN_STATE() |
| 191 |
{ |
| 192 |
DW0.Value = 0; |
| 193 |
DW0.Forceintra = 0; |
| 194 |
DW0.Forceskip = 0; |
| 195 |
DW1.Value = 0; |
| 196 |
DW1.Qpprimey = 0; |
| 197 |
DW2.Value = 0; |
| 198 |
DW3.Value = 0; |
| 199 |
DW4.Value = 0; |
| 200 |
MOS_ZeroMemory(&Reserved160, sizeof(Reserved160)); |
| 201 |
} |
| 202 |
|
| 203 |
static const size_t dwSize = 16; |
| 204 |
static const size_t byteSize = 64; |
| 205 |
}; |
| 206 |
|
| 207 |
typedef struct _AVCVdencBRCCostantData |
| 208 |
{ |
| 209 |
uint8_t UPD_GlobalRateQPAdjTabI_U8[64]; |
| 210 |
uint8_t UPD_GlobalRateQPAdjTabP_U8[64]; |
| 211 |
uint8_t UPD_GlobalRateQPAdjTabB_U8[64]; |
| 212 |
uint8_t UPD_DistThreshldI_U8[10]; |
| 213 |
uint8_t UPD_DistThreshldP_U8[10]; |
| 214 |
uint8_t UPD_DistThreshldB_U8[10]; |
| 215 |
uint8_t UPD_DistQPAdjTabI_U8[81]; |
| 216 |
uint8_t UPD_DistQPAdjTabP_U8[81]; |
| 217 |
uint8_t UPD_DistQPAdjTabB_U8[81]; |
| 218 |
int8_t UPD_BufRateAdjTabI_S8[72]; |
| 219 |
int8_t UPD_BufRateAdjTabP_S8[72]; |
| 220 |
int8_t UPD_BufRateAdjTabB_S8[72]; |
| 221 |
uint8_t UPD_FrmSzMinTabP_U8[9]; |
| 222 |
uint8_t UPD_FrmSzMinTabB_U8[9]; |
| 223 |
uint8_t UPD_FrmSzMinTabI_U8[9]; |
| 224 |
uint8_t UPD_FrmSzMaxTabP_U8[9]; |
| 225 |
uint8_t UPD_FrmSzMaxTabB_U8[9]; |
| 226 |
uint8_t UPD_FrmSzMaxTabI_U8[9]; |
| 227 |
uint8_t UPD_FrmSzSCGTabP_U8[9]; |
| 228 |
uint8_t UPD_FrmSzSCGTabB_U8[9]; |
| 229 |
uint8_t UPD_FrmSzSCGTabI_U8[9]; |
| 230 |
// Cost Table 14*42 = 588 bytes |
| 231 |
uint8_t UPD_I_IntraNonPred[42]; |
| 232 |
uint8_t UPD_I_Intra16x16[42]; |
| 233 |
uint8_t UPD_I_Intra8x8[42]; |
| 234 |
uint8_t UPD_I_Intra4x4[42]; |
| 235 |
uint8_t UPD_I_IntraChroma[42]; |
| 236 |
uint8_t UPD_P_IntraNonPred[42]; |
| 237 |
uint8_t UPD_P_Intra16x16[42]; |
| 238 |
uint8_t UPD_P_Intra8x8[42]; |
| 239 |
uint8_t UPD_P_Intra4x4[42]; |
| 240 |
uint8_t UPD_P_IntraChroma[42]; |
| 241 |
uint8_t UPD_P_Inter16x8[42]; |
| 242 |
uint8_t UPD_P_Inter8x8[42]; |
| 243 |
uint8_t UPD_P_Inter16x16[42]; |
| 244 |
uint8_t UPD_P_RefId[42]; |
| 245 |
uint8_t UPD_HMEMVCost[8][42]; |
| 246 |
uint8_t RSVD[42]; |
| 247 |
} AVCVdencBRCCostantData, *PAVCVdencBRCCostantData; |
| 248 |
|
| 249 |
//! |
| 250 |
//! \class CodechalVdencAvcState |
| 251 |
//! \brief Codechal Vdenc Avc state |
| 252 |
//! |
| 253 |
class CodechalVdencAvcState : public CodechalEncodeAvcBase |
| 254 |
{ |
| 255 |
public: |
| 256 |
const bool m_perfModeEnabled[NUM_VDENC_TARGET_USAGE_MODES] = |
| 257 |
{ |
| 258 |
0, 0, 0, 0, 0, 0, 1, 1}; |
| 259 |
|
| 260 |
// VDEnc BRC Flag in BRC Init Kernel |
| 261 |
typedef enum _BRCFLAG |
| 262 |
{ |
| 263 |
BRCFLAG_ISICQ = 0x0000, |
| 264 |
BRCFLAG_ISCBR = 0x0010, |
| 265 |
BRCFLAG_ISVBR = 0x0020, |
| 266 |
BRCFLAG_ISVCM = 0x0040, |
| 267 |
BRCFLAG_ISLOWDELAY = 0x0080 |
| 268 |
} BRCFLAG; |
| 269 |
|
| 270 |
typedef enum _LutMode |
| 271 |
{ |
| 272 |
LutMode_INTRA_NONPRED = 0x00, // extra penalty for non-predicted modes |
| 273 |
LutMode_INTRA = 0x01, |
| 274 |
LutMode_INTRA_16x16 = 0x01, |
| 275 |
LutMode_INTRA_8x8 = 0x02, |
| 276 |
LutMode_INTRA_4x4 = 0x03, |
| 277 |
LutMode_INTER_BWD = 0x09, |
| 278 |
LutMode_REF_ID = 0x0A, |
| 279 |
LutMode_INTRA_CHROMA = 0x0B, |
| 280 |
LutMode_INTER = 0x08, |
| 281 |
LutMode_INTER_16x16 = 0x08, |
| 282 |
LutMode_INTER_16x8 = 0x04, |
| 283 |
LutMode_INTER_8x16 = 0x04, |
| 284 |
LutMode_INTER_8x8q = 0x05, |
| 285 |
LutMode_INTER_8x4q = 0x06, |
| 286 |
LutMode_INTER_4x8q = 0x06, |
| 287 |
LutMode_INTER_4x4q = 0x07, |
| 288 |
LutMode_INTER_16x8_FIELD = 0x06, |
| 289 |
LutMode_INTER_8x8_FIELD = 0x07 |
| 290 |
} LutMode; |
| 291 |
|
| 292 |
typedef struct _TLBAllocationParams |
| 293 |
{ |
| 294 |
PMOS_RESOURCE presTlbMmioBuffer; |
| 295 |
uint32_t dwMmioMfxLra0Override; |
| 296 |
uint32_t dwMmioMfxLra1Override; |
| 297 |
uint32_t dwMmioMfxLra2Override; |
| 298 |
} TLBAllocationParams, *PTLBAllocationParams; |
| 299 |
|
| 300 |
//! |
| 301 |
//! \brief Constructor |
| 302 |
//! |
| 303 |
CodechalVdencAvcState( |
| 304 |
CodechalHwInterface * hwInterface, |
| 305 |
CodechalDebugInterface *debugInterface, |
| 306 |
PCODECHAL_STANDARD_INFO standardInfo); |
| 307 |
|
| 308 |
//! |
| 309 |
//! \brief Copy constructor |
| 310 |
//! |
| 311 |
CodechalVdencAvcState(const CodechalVdencAvcState&) = delete; |
| 312 |
|
| 313 |
//! |
| 314 |
//! \brief Copy assignment operator |
| 315 |
//! |
| 316 |
CodechalVdencAvcState& operator=(const CodechalVdencAvcState&) = delete; |
| 317 |
|
| 318 |
//! |
| 319 |
//! \brief Destructor |
| 320 |
//! |
| 321 |
virtual ~CodechalVdencAvcState(); |
| 322 |
|
| 323 |
virtual MOS_STATUS Initialize( CodechalSetting * settings) override; |
| 324 |
|
| 325 |
virtual MOS_STATUS InitializePicture(const EncoderParams& params) override; |
| 326 |
|
| 327 |
virtual MOS_STATUS ExecuteKernelFunctions() override; |
| 328 |
|
| 329 |
virtual MOS_STATUS SendPrologWithFrameTracking( |
| 330 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 331 |
bool frameTracking, |
| 332 |
MHW_MI_MMIOREGISTERS *mmioRegister = nullptr) override; |
| 333 |
|
| 334 |
virtual MOS_STATUS ExecutePictureLevel() override; |
| 335 |
|
| 336 |
virtual MOS_STATUS ExecuteSliceLevel() override; |
| 337 |
|
| 338 |
virtual MOS_STATUS UserFeatureKeyReport() override; |
| 339 |
|
| 340 |
//! |
| 341 |
//! \brief Add VDENC_WALKER_STATE commands to command buffer |
| 342 |
//! |
| 343 |
//! \param [in, out] cmdBuffer |
| 344 |
//! Pointer to the command buffer |
| 345 |
//! |
| 346 |
//! \return MOS_STATUS |
| 347 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 348 |
//! |
| 349 |
virtual MOS_STATUS AddVdencWalkerStateCmd( |
| 350 |
PMOS_COMMAND_BUFFER cmdBuffer); |
| 351 |
|
| 352 |
//! |
| 353 |
//! \brief Initialize data members of AVC encoder instance |
| 354 |
//! |
| 355 |
//! \return void |
| 356 |
//! |
| 357 |
virtual void InitializeDataMember(); |
| 358 |
|
| 359 |
// state related funcs |
| 360 |
//! |
| 361 |
//! \brief Initialize encode state |
| 362 |
//! |
| 363 |
//! \return MOS_STATUS |
| 364 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 365 |
//! |
| 366 |
virtual MOS_STATUS InitializeState(); |
| 367 |
|
| 368 |
//! |
| 369 |
//! \brief Validate reference list L0 and L1. |
| 370 |
//! |
| 371 |
//! \param [in] params |
| 372 |
//! Pointer to CODECHAL_ENCODE_AVC_VALIDATE_NUM_REFS_PARAMS |
| 373 |
//! |
| 374 |
//! \return MOS_STATUS |
| 375 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 376 |
//! |
| 377 |
virtual MOS_STATUS ValidateNumReferences( PCODECHAL_ENCODE_AVC_VALIDATE_NUM_REFS_PARAMS params); |
| 378 |
|
| 379 |
//! |
| 380 |
//! \brief Set intra/inter rounding value. |
| 381 |
//! |
| 382 |
//! \param [in] rounding |
| 383 |
//! Pointer to CODECHAL_ENCODE_AVC_ROUNDING_PARAMS |
| 384 |
//! |
| 385 |
//! \param [out] sliceState |
| 386 |
//! Pointer to MHW_VDBOX_AVC_SLICE_STATE |
| 387 |
//! |
| 388 |
//! \return MOS_STATUS |
| 389 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 390 |
//! |
| 391 |
virtual MOS_STATUS SetRounding(PCODECHAL_ENCODE_AVC_ROUNDING_PARAMS param, PMHW_VDBOX_AVC_SLICE_STATE sliceState); |
| 392 |
|
| 393 |
//! |
| 394 |
//! \brief Get Skip Bias Adjustment. |
| 395 |
//! |
| 396 |
//! \param [in] sliceQP |
| 397 |
//! Slice QP. |
| 398 |
//! \param [in] gopRefDist |
| 399 |
//! GOP reference dist. |
| 400 |
//! \param [in] skipBiasAdjustmentEnable |
| 401 |
//! Adjustable or not. |
| 402 |
//! |
| 403 |
//! \return MOS_STATUS |
| 404 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 405 |
//! |
| 406 |
virtual MOS_STATUS GetSkipBiasAdjustment( |
| 407 |
uint8_t sliceQP, |
| 408 |
uint16_t gopRefDist, |
| 409 |
bool* skipBiasAdjustmentEnable); |
| 410 |
|
| 411 |
//! |
| 412 |
//! \brief Get Hme Supported Based On TU. |
| 413 |
//! |
| 414 |
//! \param [in] hmeLevel |
| 415 |
//! HME level |
| 416 |
//! \param [out] supported |
| 417 |
//! Supported or not |
| 418 |
//! |
| 419 |
//! \return MOS_STATUS |
| 420 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 421 |
//! |
| 422 |
virtual MOS_STATUS GetHmeSupportedBasedOnTU( |
| 423 |
HmeLevel hmeLevel, |
| 424 |
bool *supported); |
| 425 |
|
| 426 |
//! |
| 427 |
//! \brief Get Trellis Quantization mode/value enable or not. |
| 428 |
//! |
| 429 |
//! \param [in] params |
| 430 |
//! Pointer to CODECHAL_ENCODE_AVC_TQ_INPUT_PARAMS. |
| 431 |
//! \param [out] trellisQuantParams |
| 432 |
//! Pointer to CODECHAL_ENCODE_AVC_TQ_PARAMS, mode & value setup. |
| 433 |
//! |
| 434 |
//! \return MOS_STATUS |
| 435 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 436 |
//! |
| 437 |
virtual MOS_STATUS GetTrellisQuantization( |
| 438 |
PCODECHAL_ENCODE_AVC_TQ_INPUT_PARAMS params, |
| 439 |
PCODECHAL_ENCODE_AVC_TQ_PARAMS trellisQuantParams) |
| 440 |
{ |
| 441 |
return MOS_STATUS_SUCCESS; |
| 442 |
} |
| 443 |
|
| 444 |
//! |
| 445 |
//! \brief Init SFD(still frame detection) kernel state |
| 446 |
//! |
| 447 |
//! \return MOS_STATUS |
| 448 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 449 |
//! |
| 450 |
virtual MOS_STATUS InitKernelStateSFD(); |
| 451 |
|
| 452 |
//! |
| 453 |
//! \brief Get SFD kernel curbe data |
| 454 |
//! |
| 455 |
//! \param [in] params |
| 456 |
//! Pointer to CODECHAL_ENCODE_AVC_SFD_CURBE_PARAMS |
| 457 |
//! |
| 458 |
//! \return MOS_STATUS |
| 459 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 460 |
//! |
| 461 |
virtual MOS_STATUS SetCurbeSFD( PCODECHAL_ENCODE_AVC_SFD_CURBE_PARAMS params); |
| 462 |
|
| 463 |
//! |
| 464 |
//! \brief Set SFD kernel Surface state |
| 465 |
//! |
| 466 |
//! \param [in] cmdBuffer |
| 467 |
//! Cmd Buffer |
| 468 |
//! \param [in] params |
| 469 |
//! Pointer to CODECHAL_ENCODE_AVC_SFD_SURFACE_PARAMS |
| 470 |
//! |
| 471 |
//! \return MOS_STATUS |
| 472 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 473 |
//! |
| 474 |
virtual MOS_STATUS SendSFDSurfaces( |
| 475 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 476 |
PCODECHAL_ENCODE_AVC_SFD_SURFACE_PARAMS params); |
| 477 |
|
| 478 |
//! |
| 479 |
//! \brief Run SFD(still frame detection) kernel |
| 480 |
//! |
| 481 |
//! \return MOS_STATUS |
| 482 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 483 |
//! |
| 484 |
virtual MOS_STATUS SFDKernel(); |
| 485 |
|
| 486 |
//! |
| 487 |
//! \brief Set VDENC Dirty ROI StreamIn Surface state |
| 488 |
//! |
| 489 |
//! \param [in] vdencStreamIn |
| 490 |
//! StreamIn Surface Resource. |
| 491 |
//! |
| 492 |
//! \return MOS_STATUS |
| 493 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 494 |
//! |
| 495 |
virtual MOS_STATUS SetupDirtyROI( PMOS_RESOURCE vdencStreamIn); |
| 496 |
|
| 497 |
//! |
| 498 |
//! \brief Set VDENC HuC Brc InitReset state |
| 499 |
//! |
| 500 |
//! \return MOS_STATUS |
| 501 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 502 |
//! |
| 503 |
virtual MOS_STATUS SetDmemHuCBrcInitReset() = 0; |
| 504 |
|
| 505 |
//! |
| 506 |
//! \brief Set VDENC HuC Brc Update state |
| 507 |
//! |
| 508 |
//! \return MOS_STATUS |
| 509 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 510 |
//! |
| 511 |
virtual MOS_STATUS SetDmemHuCBrcUpdate() = 0; |
| 512 |
|
| 513 |
//! |
| 514 |
//! \brief VDENC Load Mv Cost based on QP |
| 515 |
//! |
| 516 |
//! \param [in] QP |
| 517 |
//! QP value |
| 518 |
//! |
| 519 |
//! \return MOS_STATUS |
| 520 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 521 |
//! |
| 522 |
virtual MOS_STATUS LoadMvCost( uint8_t QP) = 0; |
| 523 |
|
| 524 |
//! |
| 525 |
//! \brief VDENC Load HME Mv Cost based on QP |
| 526 |
//! |
| 527 |
//! \param [in] QP |
| 528 |
//! QP value |
| 529 |
//! |
| 530 |
//! \return MOS_STATUS |
| 531 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 532 |
//! |
| 533 |
virtual MOS_STATUS LoadHmeMvCost( uint8_t QP) = 0; |
| 534 |
|
| 535 |
//! |
| 536 |
//! \brief VDENC Load HME Mv Cost based on QP |
| 537 |
//! |
| 538 |
//! \param [in] seqParams |
| 539 |
//! QP value |
| 540 |
//! \param [in] HMEMVCostTable |
| 541 |
//! HME MV Cost Table |
| 542 |
//! \return MOS_STATUS |
| 543 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 544 |
//! |
| 545 |
virtual MOS_STATUS LoadHmeMvCostTable( |
| 546 |
PCODEC_AVC_ENCODE_SEQUENCE_PARAMS seqParams, |
| 547 |
uint8_t HMEMVCostTable[8][42]) = 0; |
| 548 |
|
| 549 |
//! |
| 550 |
//! \brief Set VDENC ROI StreamIn Surface state |
| 551 |
//! |
| 552 |
//! \param [in] picParams |
| 553 |
//! Pointer to CODEC_AVC_ENCODE_PIC_PARAMS. |
| 554 |
//! \param [in] vdencStreamIn |
| 555 |
//! StreamIn Surface Resource. |
| 556 |
//! |
| 557 |
//! \return MOS_STATUS |
| 558 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 559 |
//! |
| 560 |
virtual MOS_STATUS SetupROIStreamIn( |
| 561 |
PCODEC_AVC_ENCODE_PIC_PARAMS picParams, |
| 562 |
PCODEC_AVC_ENCODE_SLICE_PARAMS slcParams, |
| 563 |
PMOS_RESOURCE vdencStreamIn); |
| 564 |
|
| 565 |
//! |
| 566 |
//! \brief Set VDENC BRC ROI buffer |
| 567 |
//! |
| 568 |
//! \param [in] picParams |
| 569 |
//! Pointer to CODEC_AVC_ENCODE_PIC_PARAMS. |
| 570 |
//! \param [in] brcRoiBuffer |
| 571 |
//! BRC ROI Resource. |
| 572 |
//! |
| 573 |
//! \return MOS_STATUS |
| 574 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 575 |
//! |
| 576 |
MOS_STATUS SetupBrcROIBuffer( |
| 577 |
PCODEC_AVC_ENCODE_PIC_PARAMS picParams, |
| 578 |
PMOS_RESOURCE brcRoiBuffer); |
| 579 |
|
| 580 |
//! |
| 581 |
//! \brief Set VDENC ForceSkip StreamIn Surface state |
| 582 |
//! |
| 583 |
//! \param [in] picParams |
| 584 |
//! Pointer to CODEC_AVC_ENCODE_PIC_PARAMS. |
| 585 |
//! \param [in] vdencStreamIn |
| 586 |
//! StreamIn Surface Resource. |
| 587 |
//! |
| 588 |
//! \return MOS_STATUS |
| 589 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 590 |
//! |
| 591 |
MOS_STATUS SetupForceSkipStreamIn( |
| 592 |
PCODEC_AVC_ENCODE_PIC_PARAMS picParams, |
| 593 |
PMOS_RESOURCE vdencStreamIn); |
| 594 |
|
| 595 |
//! |
| 596 |
//! \brief Set VDENC StreamIn Surface for BRC Adaptive Region Boost |
| 597 |
//! |
| 598 |
//! \param [in] vdencStreamIn |
| 599 |
//! StreamIn Surface Resource. |
| 600 |
//! \param [in] boostIndex |
| 601 |
//! Region index for boosting. |
| 602 |
//! |
| 603 |
//! \return MOS_STATUS |
| 604 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 605 |
//! |
| 606 |
MOS_STATUS SetupRegionBoosting( |
| 607 |
PMOS_RESOURCE vdencStreamIn, |
| 608 |
uint16_t boostIndex); |
| 609 |
|
| 610 |
//! |
| 611 |
//! \brief Sort and set distinct delta QPs |
| 612 |
//! |
| 613 |
//! \return bool |
| 614 |
//! true if native ROI, otherwise false |
| 615 |
//! |
| 616 |
virtual bool ProcessRoiDeltaQp(); |
| 617 |
|
| 618 |
//! |
| 619 |
//! \brief Add store HUC_ERROR_STATUS register command in the command buffer |
| 620 |
//! |
| 621 |
//! \param [in] mmioRegisters |
| 622 |
//! Pointer to mmio huc register |
| 623 |
//! \param [in] cmdBuffer |
| 624 |
//! Pointer to the command buffer |
| 625 |
//! \param [in] addToEncodeStatus |
| 626 |
//! Flag to indicate whether huc error status will be stored in encode status buffer |
| 627 |
//! |
| 628 |
//! \return MOS_STATUS |
| 629 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 630 |
//! |
| 631 |
virtual MOS_STATUS AddHucOutputRegistersHandling( |
| 632 |
MmioRegistersHuc* mmioRegisters, |
| 633 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 634 |
bool addToEncodeStatus) |
| 635 |
{ |
| 636 |
// HUC store HUC_STATUS only starting with G11 |
| 637 |
return MOS_STATUS_SUCCESS; |
| 638 |
} |
| 639 |
|
| 640 |
virtual MOS_STATUS StoreHucErrorStatus(MmioRegistersHuc* mmioRegisters, PMOS_COMMAND_BUFFER cmdBuffer, bool addToEncodeStatus); |
| 641 |
|
| 642 |
//! |
| 643 |
//! \brief VDENC BRC InitReset HuC FW Cmd. |
| 644 |
//! |
| 645 |
//! \return MOS_STATUS |
| 646 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 647 |
//! |
| 648 |
virtual MOS_STATUS HuCBrcInitReset(); |
| 649 |
|
| 650 |
//! |
| 651 |
//! \brief VDENC BRC Update HuC FW Cmd. |
| 652 |
//! |
| 653 |
//! \return MOS_STATUS |
| 654 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 655 |
//! |
| 656 |
virtual MOS_STATUS HuCBrcUpdate(); |
| 657 |
|
| 658 |
//! |
| 659 |
//! \brief VDENC Loads Cost According To CodingType & QP. |
| 660 |
//! |
| 661 |
//! \param [in] pictureCodingType |
| 662 |
//! Picture encoding type. |
| 663 |
//! \param [in] QP |
| 664 |
//! QP value |
| 665 |
//! |
| 666 |
//! \return MOS_STATUS |
| 667 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 668 |
//! |
| 669 |
MOS_STATUS LoadCosts( |
| 670 |
uint16_t pictureCodingType, |
| 671 |
uint8_t QP); |
| 672 |
|
| 673 |
//! |
| 674 |
//! \brief VDENC using dummy stream object for HuC BRC FW. |
| 675 |
//! |
| 676 |
//! \param [in] cmdBuffer |
| 677 |
//! Command Buffer. |
| 678 |
//! |
| 679 |
//! \return MOS_STATUS |
| 680 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 681 |
//! |
| 682 |
virtual MOS_STATUS HuCBrcDummyStreamObject( PMOS_COMMAND_BUFFER cmdBuffer); |
| 683 |
|
| 684 |
//! |
| 685 |
//! \brief VDENC Set const date to HuC for BRC Update FW.. |
| 686 |
//! |
| 687 |
//! \return MOS_STATUS |
| 688 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 689 |
//! |
| 690 |
MOS_STATUS SetConstDataHuCBrcUpdate(); |
| 691 |
|
| 692 |
//! |
| 693 |
//! \brief VDENC Compute BRC Init QP.. |
| 694 |
//! \param [in] seqParams |
| 695 |
//! AVC VDENC encoder sequence params |
| 696 |
//! \param [in] initQP |
| 697 |
//! Pointer to Init QP |
| 698 |
//! \return MOS_STATUS |
| 699 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 700 |
//! |
| 701 |
MOS_STATUS ComputeBRCInitQP( |
| 702 |
PCODEC_AVC_ENCODE_SEQUENCE_PARAMS seqParams, |
| 703 |
int32_t* initQP); |
| 704 |
|
| 705 |
//! |
| 706 |
//! \brief VDENC Store HuC Status to Register.. |
| 707 |
//! \param [in] hwInterface |
| 708 |
//! HW Interface |
| 709 |
//! \param [in] cmdBuffer |
| 710 |
//! cmd buffer |
| 711 |
//! \return MOS_STATUS |
| 712 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 713 |
//! |
| 714 |
MOS_STATUS AvcVdencStoreHuCStatus2Register( |
| 715 |
CodechalHwInterface *hwInterface, |
| 716 |
PMOS_COMMAND_BUFFER cmdBuffer); |
| 717 |
|
| 718 |
//! |
| 719 |
//! \brief VDENC Set TLB allocation.. |
| 720 |
//! \param [in] cmdBuffer |
| 721 |
//! cmd buffer |
| 722 |
//! \param [in] params |
| 723 |
//! AVC VDENC TLB allocation params |
| 724 |
//! \return MOS_STATUS |
| 725 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 726 |
//! |
| 727 |
MOS_STATUS SetTLBAllocation( |
| 728 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 729 |
PTLBAllocationParams params); |
| 730 |
|
| 731 |
//! |
| 732 |
//! \brief VDENC Restore TLB allocation.. |
| 733 |
//! \param [in] cmdBuffer |
| 734 |
//! cmd buffer |
| 735 |
//! \param [in] tlbMmioBuffer |
| 736 |
//! PMOS resource params |
| 737 |
//! \return MOS_STATUS |
| 738 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 739 |
//! |
| 740 |
MOS_STATUS RestoreTLBAllocation( |
| 741 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 742 |
PMOS_RESOURCE tlbMmioBuffer); |
| 743 |
|
| 744 |
//! |
| 745 |
//! \brief Set VDENC HuC Brc InitReset state |
| 746 |
//! |
| 747 |
//! \param [in] hucVdencBrcInitDmem |
| 748 |
//! Point to BrcInitDmem of different Gen-x Platforms. |
| 749 |
//! |
| 750 |
//! \return MOS_STATUS |
| 751 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 752 |
//! |
| 753 |
template <class CODECHAL_VDENC_AVC_BRC_INIT_DMEM> |
| 754 |
MOS_STATUS SetDmemHuCBrcInitResetImpl( CODECHAL_VDENC_AVC_BRC_INIT_DMEM* hucVdencBrcInitDmem); |
| 755 |
|
| 756 |
//! |
| 757 |
//! \brief Set VDENC HuC Brc Update state |
| 758 |
//! |
| 759 |
//! \param [in] hucVDEncBrcDmem |
| 760 |
//! Point to BRC DMEM of different Gen-x Platforms. |
| 761 |
//! |
| 762 |
//! \return MOS_STATUS |
| 763 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 764 |
//! |
| 765 |
template <class CODECHAL_VDENC_AVC_BRC_UPDATE_DMEM> |
| 766 |
MOS_STATUS SetDmemHuCBrcUpdateImpl( CODECHAL_VDENC_AVC_BRC_UPDATE_DMEM* hucVDEncBrcDmem); |
| 767 |
|
| 768 |
//! |
| 769 |
//! \brief Functions to set parameter and execute ME kernel |
| 770 |
//! |
| 771 |
//! \return MOS_STATUS |
| 772 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 773 |
//! |
| 774 |
virtual MOS_STATUS ExecuteMeKernel(); |
| 775 |
|
| 776 |
virtual bool IsMBBRCControlEnabled(); |
| 777 |
|
| 778 |
MOS_STATUS SetCommonSliceState( |
| 779 |
CODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS &packSlcHeaderParams, |
| 780 |
MHW_VDBOX_AVC_SLICE_STATE & sliceState); |
| 781 |
|
| 782 |
MOS_STATUS SetSliceState( |
| 783 |
CODECHAL_ENCODE_AVC_PACK_SLC_HEADER_PARAMS &packSlcHeaderParams, |
| 784 |
MHW_VDBOX_AVC_SLICE_STATE & sliceState, |
| 785 |
uint16_t slcIdx); |
| 786 |
|
| 787 |
//! |
| 788 |
//! \brief Get AVC VDenc frame level status extention |
| 789 |
//! |
| 790 |
//! \param [in] cmdBuffer |
| 791 |
//! Point to MOS_COMMAND_BUFFER |
| 792 |
//! [in] StatusReportFeedbackNumber |
| 793 |
//! Status report number |
| 794 |
//! \return MOS_STATUS |
| 795 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 796 |
//! |
| 797 |
virtual MOS_STATUS GetAvcVdencFrameLevelStatusExt(uint32_t StatusReportFeedbackNumber, MOS_COMMAND_BUFFER *cmdBuffer) |
| 798 |
{ |
| 799 |
return MOS_STATUS_SUCCESS; |
| 800 |
}; |
| 801 |
|
| 802 |
protected: |
| 803 |
// AvcGeneraicState functions |
| 804 |
//! |
| 805 |
//! \brief AVC VDEnc State Initialization. |
| 806 |
//! |
| 807 |
//! \return MOS_STATUS |
| 808 |
//! MOS_STATUS_SUCCESS if success |
| 809 |
//! |
| 810 |
virtual MOS_STATUS Initialize() override; |
| 811 |
|
| 812 |
//! |
| 813 |
//! \brief Allocate VDENC necessary resources. |
| 814 |
//! |
| 815 |
//! \return MOS_STATUS |
| 816 |
//! MOS_STATUS_SUCCESS if success |
| 817 |
//! |
| 818 |
virtual MOS_STATUS AllocateResources() override; |
| 819 |
|
| 820 |
//! |
| 821 |
//! \brief Set Sequence Structures. |
| 822 |
//! |
| 823 |
//! \return MOS_STATUS |
| 824 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 825 |
//! |
| 826 |
virtual MOS_STATUS SetSequenceStructs() override; |
| 827 |
|
| 828 |
//! |
| 829 |
//! \brief Set Picture Structures |
| 830 |
//! |
| 831 |
//! \return MOS_STATUS |
| 832 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 833 |
//! |
| 834 |
virtual MOS_STATUS SetPictureStructs() override; |
| 835 |
|
| 836 |
//! |
| 837 |
//! \brief Set slice Structs |
| 838 |
//! |
| 839 |
//! \return MOS_STATUS |
| 840 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 841 |
//! |
| 842 |
virtual MOS_STATUS SetSliceStructs() override; |
| 843 |
|
| 844 |
//! |
| 845 |
//! \brief Initialize Encode ME kernel state |
| 846 |
//! |
| 847 |
//! \return MOS_STATUS |
| 848 |
//! MOS_STATUS_SUCCESS if success |
| 849 |
//! |
| 850 |
virtual MOS_STATUS InitKernelStateMe() override; |
| 851 |
|
| 852 |
//! |
| 853 |
//! \brief Set Encode ME kernel Curbe data. |
| 854 |
//! |
| 855 |
//! \param [in] params |
| 856 |
//! Pointer to the MeCurbeParams |
| 857 |
//! |
| 858 |
//! \return MOS_STATUS |
| 859 |
//! MOS_STATUS_SUCCESS if success |
| 860 |
//! |
| 861 |
virtual MOS_STATUS SetCurbeMe( MeCurbeParams* params) override; |
| 862 |
|
| 863 |
//! |
| 864 |
//! \brief Set Encode ME kernel Surfaces |
| 865 |
//! |
| 866 |
//! \param [in] cmdBuffer |
| 867 |
//! Pointer to the MOS_COMMAND_BUFFER |
| 868 |
//! \param [in] params |
| 869 |
//! Pointer to the CODECHAL_ME_SURFACE_PARAMS |
| 870 |
//! |
| 871 |
//! \return MOS_STATUS |
| 872 |
//! MOS_STATUS_SUCCESS if success |
| 873 |
//! |
| 874 |
virtual MOS_STATUS SendMeSurfaces( |
| 875 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 876 |
MeSurfaceParams* params) override; |
| 877 |
|
| 878 |
//! |
| 879 |
//! \brief Set MFX_PIPE_BUF_ADDR_STATE parameter |
| 880 |
//! |
| 881 |
//! \param [in] genericParam |
| 882 |
//! Input parameters |
| 883 |
//! \param [out] param |
| 884 |
//! reference to MHW_VDBOX_PIPE_BUF_ADDR_PARAMS |
| 885 |
//! |
| 886 |
//! \return MOS_STATUS |
| 887 |
//! MOS_STATUS_SUCCESS if success |
| 888 |
//! |
| 889 |
virtual MOS_STATUS SetMfxPipeBufAddrStateParams( |
| 890 |
CODECHAL_ENCODE_AVC_GENERIC_PICTURE_LEVEL_PARAMS genericParam, |
| 891 |
MHW_VDBOX_PIPE_BUF_ADDR_PARAMS& param) override; |
| 892 |
|
| 893 |
//! |
| 894 |
//! \brief Set MHW_VDBOX_VDENC_CQPT_STATE parameter |
| 895 |
//! |
| 896 |
//! \param [out] param |
| 897 |
//! reference to MHW_VDBOX_VDENC_CQPT_STATE_PARAMS |
| 898 |
//! |
| 899 |
//! \return void |
| 900 |
//! |
| 901 |
virtual void SetVdencCqptStateParams(MHW_VDBOX_VDENC_CQPT_STATE_PARAMS& param); |
| 902 |
|
| 903 |
//! |
| 904 |
//! \brief Set MFX_AVC_IMG_STATE parameter |
| 905 |
//! |
| 906 |
//! \param [out] param |
| 907 |
//! reference to MHW_VDBOX_AVC_IMG_PARAMS |
| 908 |
//! |
| 909 |
//! \return MOS_STATUS |
| 910 |
//! MOS_STATUS_SUCCESS if success |
| 911 |
//! |
| 912 |
virtual void SetMfxAvcImgStateParams(MHW_VDBOX_AVC_IMG_PARAMS& param) override; |
| 913 |
|
| 914 |
//! |
| 915 |
//! \brief Calculate Vdenc Commands Size |
| 916 |
//! |
| 917 |
//! \return MOS_STATUS |
| 918 |
//! MOS_STATUS_SUCCESS if success |
| 919 |
//! |
| 920 |
virtual MOS_STATUS CalculateVdencCommandsSize(); |
| 921 |
|
| 922 |
//! |
| 923 |
//! \brief Create MHW_VDBOX_STATE_CMDSIZE_PARAMS |
| 924 |
//! |
| 925 |
//! \return PMHW_VDBOX_STATE_CMDSIZE_PARAMS |
| 926 |
//! |
| 927 |
virtual PMHW_VDBOX_STATE_CMDSIZE_PARAMS CreateMhwVdboxStateCmdsizeParams(); |
| 928 |
|
| 929 |
//! |
| 930 |
//! \brief Create PMHW_VDBOX_AVC_IMG_PARAMS. |
| 931 |
//! |
| 932 |
//! \return PMHW_VDBOX_AVC_IMG_PARAMS |
| 933 |
//! |
| 934 |
virtual PMHW_VDBOX_AVC_IMG_PARAMS CreateMhwVdboxAvcImgParams(); |
| 935 |
|
| 936 |
//! |
| 937 |
//! \brief Create PMHW_VDBOX_VDENC_WALKER_STATE_PARAMS. |
| 938 |
//! |
| 939 |
//! \return PMHW_VDBOX_VDENC_WALKER_STATE_PARAMS |
| 940 |
//! |
| 941 |
virtual PMHW_VDBOX_VDENC_WALKER_STATE_PARAMS CreateMhwVdboxVdencWalkerStateParams(); |
| 942 |
|
| 943 |
virtual uint32_t GetBRCCostantDataSize() { return sizeof(AVCVdencBRCCostantData); } |
| 944 |
|
| 945 |
virtual uint32_t GetVdencBRCImgStateBufferSize() { return MOS_ALIGN_CEIL(m_hwInterface->m_vdencBrcImgStateBufferSize, CODECHAL_PAGE_SIZE); } |
| 946 |
|
| 947 |
virtual MOS_STATUS FillHucConstData(uint8_t *data, uint8_t picType); |
| 948 |
|
| 949 |
//! |
| 950 |
//! \brief Prepare HW MetaData buffer |
| 951 |
//! \details Prepare HW MetaData buffer. |
| 952 |
//! \param [in] presMetadataBuffer |
| 953 |
//! Pointer to allocated HW MetaData buffer |
| 954 |
//! [in] presSliceSizeStreamoutBuffer |
| 955 |
//! Pointer to m_pakSliceSizeStreamoutBuffer |
| 956 |
//! [in] cmdBuffer |
| 957 |
//! Pointer to primary cmd buffer |
| 958 |
//! \return MOS_STATUS |
| 959 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 960 |
//! |
| 961 |
virtual MOS_STATUS PrepareHWMetaData( |
| 962 |
PMOS_RESOURCE presMetadataBuffer, |
| 963 |
PMOS_RESOURCE presSliceSizeStreamoutBuffer, |
| 964 |
PMOS_COMMAND_BUFFER cmdBuffer) override; |
| 965 |
|
| 966 |
virtual MOS_STATUS AddVdencBrcImgBuffer( |
| 967 |
PMOS_RESOURCE vdencBrcImgBuffer, |
| 968 |
PMHW_VDBOX_AVC_IMG_PARAMS params); |
| 969 |
|
| 970 |
//! |
| 971 |
//! \brief Get Encode Status for Vulkan Query Pool |
| 972 |
//! \details Retrieve the necessary status and results for the Vulkan query pool |
| 973 |
//! from the status buffer, such as bitstream size, hardware encoding status, bitstream offset |
| 974 |
//! \param [in] queryFrameIndex |
| 975 |
//! The specified frame index |
| 976 |
//! [in] pData |
| 977 |
//! Points to the buffer passed by Vulkan for storing the results. |
| 978 |
//! [in] dataOffset |
| 979 |
//! Starting position for writing to pData |
| 980 |
//! [in] is64bit |
| 981 |
//! Whether each result is 64-bit, otherwise 32-bit. |
| 982 |
//! [in] reportStatus |
| 983 |
//! Whether the encode status needs to be returned |
| 984 |
//! [in] reportOffset |
| 985 |
//! Whether the bitstream offset needs to be returned |
| 986 |
//! [in] reportBitstream |
| 987 |
//! Whether the bitstream size needs to be returned |
| 988 |
//! \return MOS_STATUS |
| 989 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 990 |
//! |
| 991 |
virtual MOS_STATUS GetVulkanQueryPoolResults( |
| 992 |
uint32_t queryFrameIndex, |
| 993 |
void *pData, |
| 994 |
uint64_t dataOffset, |
| 995 |
bool is64bit, |
| 996 |
uint8_t reportStatus, |
| 997 |
bool reportOffset, |
| 998 |
bool reportBitstream) override; |
| 999 |
|
| 1000 |
//! |
| 1001 |
//! \brief Report Slice Size to MetaData buffer |
| 1002 |
//! \details Report Slice Size to MetaData buffer. |
| 1003 |
//! \param [in] presMetadataBuffer |
| 1004 |
//! Pointer to allocated HW MetaData buffer |
| 1005 |
//! [in] cmdBuffer |
| 1006 |
//! Pointer to primary cmd buffer |
| 1007 |
//! [in] slcCount |
| 1008 |
//! Current slice count |
| 1009 |
//! \return MOS_STATUS |
| 1010 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 1011 |
//! |
| 1012 |
virtual MOS_STATUS ReportSliceSizeMetaData( |
| 1013 |
PMOS_RESOURCE presMetadataBuffer, |
| 1014 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 1015 |
uint32_t slcCount); |
| 1016 |
|
| 1017 |
//! |
| 1018 |
//! \brief Add MI_STORE commands in the command buffer to update DMEM from other HW output buffer if needed |
| 1019 |
//! |
| 1020 |
//! \param [in] cmdBuffer |
| 1021 |
//! Pointer to the command buffer |
| 1022 |
//! |
| 1023 |
//! \return MOS_STATUS |
| 1024 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 1025 |
//! |
| 1026 |
virtual MOS_STATUS AddMiStoreForHWOutputToHucDmem(PMOS_COMMAND_BUFFER cmdBuffer) |
| 1027 |
{ |
| 1028 |
// Nothing to do |
| 1029 |
// HW store PAK statistics directly to DMEM resource |
| 1030 |
return MOS_STATUS_SUCCESS; |
| 1031 |
} |
| 1032 |
|
| 1033 |
virtual void SetBufferToStorePakStatistics(); |
| 1034 |
|
| 1035 |
virtual uint32_t GetCurrConstDataBufIdx(); |
| 1036 |
|
| 1037 |
protected: |
| 1038 |
bool m_vdencSinglePassEnable = false; //!< Enable VDEnc single pass |
| 1039 |
|
| 1040 |
MOS_RESOURCE m_vdencIntraRowStoreScratchBuffer; //!< Handle of intra row store surface |
| 1041 |
MOS_RESOURCE m_pakStatsBuffer; //!< Handle of PAK status buffer |
| 1042 |
MOS_RESOURCE m_pakStatsBufferFull[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; //!< Handle of PAK status buffer include PerMB and frame level. |
| 1043 |
MOS_RESOURCE m_vdencStatsBuffer; //!< Handle of VDEnc status buffer |
| 1044 |
MOS_RESOURCE m_vdencTlbMmioBuffer; //!< VDEnc TLB MMIO buffer |
| 1045 |
|
| 1046 |
uint32_t m_mmioMfxLra0Override = 0; //!< Override Register MFX_LRA_0 |
| 1047 |
uint32_t m_mmioMfxLra1Override = 0; //!< Override Register MFX_LRA_1 |
| 1048 |
uint32_t m_mmioMfxLra2Override = 0; //!< Override Register MFX_LRA_2 |
| 1049 |
|
| 1050 |
uint8_t *m_vdencModeCostTbl = nullptr; //!< Pointer to VDEnc Mode Cost Table |
| 1051 |
uint8_t *m_vdencMvCostTbl = nullptr; //!< Pointer to VDEnc MV Cost Table |
| 1052 |
uint8_t *m_vdencHmeMvCostTbl = nullptr; //!< Pointer to VDEnc HME MV Cost Table |
| 1053 |
|
| 1054 |
const uint16_t *m_vdencSSCThrsTblI = nullptr; //!< Pointer to VDEnc Slice size thresholds table for I picture |
| 1055 |
const uint16_t *m_vdencSSCThrsTblP = nullptr; //!< Pointer to VDEnc Slice size thresholds table for P picture |
| 1056 |
|
| 1057 |
// SEI |
| 1058 |
CodechalEncodeSeiData m_seiData; //!< Encode SEI data parameter. |
| 1059 |
uint32_t m_seiDataOffset; //!< Encode SEI data offset. |
| 1060 |
uint8_t * m_seiParamBuffer; //!< Encode SEI data buffer. |
| 1061 |
|
| 1062 |
bool m_brcInit; //!< BRC init enable flag. |
| 1063 |
bool m_brcReset; //!< BRC reset enable flag. |
| 1064 |
bool m_mbBrcEnabled; //!< MBBrc enable flag. |
| 1065 |
bool m_nonNativeBrcRoiSupported; //!< Non native ROI in BRC mode enable flag. |
| 1066 |
bool m_mbBrcUserFeatureKeyControl; //!< MBBRC user feature control enable flag. |
| 1067 |
double m_dBrcTargetSize; //!< BRC target size. |
| 1068 |
uint32_t m_trellis; //!< Trellis Number. |
| 1069 |
bool m_acceleratorHeaderPackingCaps; //!< Flag set by driver from driver caps. |
| 1070 |
|
| 1071 |
double m_dBrcInitCurrentTargetBufFullInBits; //!< BRC init current target buffer full in bits |
| 1072 |
double m_dBrcInitResetInputBitsPerFrame; //!< BrcInitReset Input Bits Per Frame |
| 1073 |
uint32_t m_brcInitResetBufSizeInBits; //!< BrcInitReset Buffer Size In Bits |
| 1074 |
uint32_t m_brcInitPreviousTargetBufFullInBits; //!< BRC Init Previous Target Buffer Full In Bits |
| 1075 |
|
| 1076 |
// Below values will be set if qp control params are sent by app |
| 1077 |
bool m_minMaxQpControlEnabled; //!< Flag to indicate if min/max QP feature is enabled or not. |
| 1078 |
uint8_t m_iMinQp; //!< I frame Minimum QP. |
| 1079 |
uint8_t m_iMaxQp; //!< I frame Maximum QP. |
| 1080 |
uint8_t m_pMinQp; //!< P frame Minimum QP. |
| 1081 |
uint8_t m_pMaxQp; //!< P frame Maximum QP. |
| 1082 |
bool m_pFrameMinMaxQpControl; //!< Indicates min/max QP values for P-frames are set separately or not. |
| 1083 |
|
| 1084 |
uint32_t m_skipFrameBufferSize; //!< size of skip frame packed data. |
| 1085 |
MOS_RESOURCE m_resSkipFrameBuffer; //!< copy skip frame packed data from DDI. |
| 1086 |
|
| 1087 |
// VDENC BRC Buffers |
| 1088 |
MOS_RESOURCE m_resVdencBrcUpdateDmemBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM][CODECHAL_VDENC_BRC_NUM_OF_PASSES]; //!< Brc Update DMEM Buffer Array. |
| 1089 |
MOS_RESOURCE m_resVdencBrcInitDmemBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; //!< Brc Init DMEM Buffer Array. |
| 1090 |
MOS_RESOURCE m_resVdencBrcImageStatesReadBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; //!< Read-only VDENC+PAK IMG STATE buffer. |
| 1091 |
MOS_RESOURCE m_resVdencBrcConstDataBuffer[CODECHAL_ENCODE_VDENC_BRC_CONST_BUFFER_NUM]; //!< BRC Const Data Buffer for each frame type. |
| 1092 |
MOS_RESOURCE m_resVdencBrcHistoryBuffer; //!< BRC History Buffer. |
| 1093 |
MOS_RESOURCE m_resVdencBrcRoiBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; //!< BRC ROI Buffer. |
| 1094 |
MOS_RESOURCE m_resVdencBrcDbgBuffer; //!< BRC Debug Buffer. |
| 1095 |
|
| 1096 |
// Static frame detection |
| 1097 |
bool m_staticFrameDetectionEnable; //!< Static frame detection enable. |
| 1098 |
MOS_RESOURCE m_resSfdOutputBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; //!< Array of SFDOutputBuffer. |
| 1099 |
MOS_RESOURCE m_resSfdCostTablePFrameBuffer; //!< SFD CostTable of P Frame. |
| 1100 |
MOS_RESOURCE m_resSfdCostTableBFrameBuffer; //!< SFD CostTable of B Frame. |
| 1101 |
MOS_RESOURCE m_resVdencSfdImageStateReadBuffer; //!< SFD ImageState Read Buffer. |
| 1102 |
PMHW_KERNEL_STATE m_sfdKernelState; //!< Point to SFD kernel state. |
| 1103 |
|
| 1104 |
// Generation Specific Support Flags & User Feature Key Reads |
| 1105 |
uint8_t m_mbBrcSupportCaps; //!< MbBrcSupport Capability. |
| 1106 |
bool m_ftqEnable; //!< FTQEnable |
| 1107 |
bool m_skipBiasAdjustmentSupported; //!< SkipBiasAdjustment support for P frame |
| 1108 |
bool m_sliceLevelReportSupported; //!< Slice Level Report support |
| 1109 |
bool m_brcRoiSupported; //!< BRC Roi Support Flag. |
| 1110 |
bool m_brcMotionAdaptiveEnable; //!< BRC motion adaptive optimization enabled. |
| 1111 |
|
| 1112 |
bool m_brcAdaptiveRegionBoostSupported; //!< ARB in BRC mode supported flag. |
| 1113 |
bool m_brcAdaptiveRegionBoostEnable; //!< ARB in BRC mode enable flag. |
| 1114 |
|
| 1115 |
bool m_roundingInterEnable; //!< RoundingInter Enable Flag. |
| 1116 |
bool m_adaptiveRoundingInterEnable; //!< Adaptive Rounding Inter Enable Flag. |
| 1117 |
uint32_t m_roundingInterP; //!< Rounding Inter for P frame. |
| 1118 |
|
| 1119 |
uint8_t m_vdEncModeCost[12]; //!< VDEnc Mode Cost Table. |
| 1120 |
uint8_t m_vdEncMvCost[8]; //!< VDEnc MV Cost Table. |
| 1121 |
uint8_t m_vdEncHmeMvCost[8]; //!< VDEnc HME MV Cost Table. |
| 1122 |
|
| 1123 |
uint32_t m_slidingWindowSize; //!< Slideing Window Size. |
| 1124 |
bool m_forceToSkipEnable; //!< Force to Skip Flag. |
| 1125 |
uint32_t m_vdencBrcInitDmemBufferSize; //!< Brc Init-Dmem Buffer Size. |
| 1126 |
uint32_t m_vdencBrcUpdateDmemBufferSize; //!< Brc Update-Dmem Buffer Size. |
| 1127 |
bool m_vdencStaticFrame; //!< Static Frame Indicator. |
| 1128 |
uint32_t m_vdencStaticRegionPct; //!< Ratio of Static Region in One Frame. |
| 1129 |
bool m_oneOnOneMapping = false; //!< Indicate if one on one ref index mapping is enabled |
| 1130 |
bool m_perMBStreamOutEnable; |
| 1131 |
|
| 1132 |
static const uint32_t TrellisQuantizationRounding[NUM_VDENC_TARGET_USAGE_MODES]; |
| 1133 |
static const bool TrellisQuantizationEnable[NUM_TARGET_USAGE_MODES]; |
| 1134 |
|
| 1135 |
static const uint32_t m_vdboxHucVdencBrcInitKernelDescriptor = 4; //!< Huc Vdenc Brc init kernel descriptor |
| 1136 |
static const uint32_t m_vdboxHucVdencBrcUpdateKernelDescriptor = 5; //!< Huc Vdenc Brc update kernel descriptor |
| 1137 |
|
| 1138 |
static constexpr uint8_t m_maxNumRoi = 16; //!< VDEnc maximum number of ROI supported (including non-ROI zone0) |
| 1139 |
static constexpr uint8_t m_maxNumBrcRoi = 8; //!< VDEnc maximum number of BRC ROI supported (including non-ROI zone0) |
| 1140 |
static constexpr uint8_t m_maxNumNativeRoi = 3; //!< Number of native ROI supported by VDEnc HW |
| 1141 |
|
| 1142 |
protected: |
| 1143 |
static const uint32_t SFD_OUTPUT_BUFFER_SIZE = 128; //!< SFD_OUTPUT_BUFFER_SIZE |
| 1144 |
static const uint32_t AVC_BRC_STATS_BUF_SIZE = 80; //!< VDENC BRC statistics buffer size |
| 1145 |
static const uint32_t AVC_BRC_PAK_STATS_BUF_SIZE = 204; //!< VDENC BRC PAK statistics buffer size |
| 1146 |
static const double BRC_DevThreshI0_FP_NEG[CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2]; //!< Negative BRC threshold for I frame |
| 1147 |
static const double BRC_DevThreshI0_FP_POS[CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2]; //!< Positive BRC threshold for I frame |
| 1148 |
static const double BRC_DevThreshPB0_FP_NEG[CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2]; //!< Negative BRC threshold for P/B frame |
| 1149 |
static const double BRC_DevThreshPB0_FP_POS[CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2]; //!< Positive BRC threshold for P/B frame |
| 1150 |
static const double BRC_DevThreshVBR0_NEG[CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2]; //!< Negative BRC threshold for VBR mode |
| 1151 |
static const double BRC_DevThreshVBR0_POS[CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2]; //!< Positive BRC threshold for VBR mode |
| 1152 |
static const int8_t BRC_LowDelay_DevThreshPB0_S8[8]; //!< Low Delay BRC threshold for P/B frame |
| 1153 |
static const int8_t BRC_LowDelay_DevThreshI0_S8[8]; //!< Low Delay BRC threshold for I frame |
| 1154 |
static const int8_t BRC_LowDelay_DevThreshVBR0_S8[8]; //!< Low Delay BRC threshold for VBR Mode |
| 1155 |
static const int8_t BRC_INIT_DistQPDelta_I8[4]; //!< Distortion QP Delta |
| 1156 |
static const uint8_t BRC_EstRateThreshP0_U8[7]; //!< Estimate Rate Thresh of P frame |
| 1157 |
static const uint8_t BRC_EstRateThreshI0_U8[7]; //!< Estimate Rate Thresh of I frame |
| 1158 |
static const uint16_t BRC_UPD_start_global_adjust_frame[4]; //!< Start Global Adjust Frame |
| 1159 |
static const uint8_t BRC_UPD_global_rate_ratio_threshold[7]; //!< Global Rate Ratio Threshold |
| 1160 |
static const uint8_t BRC_UPD_slwin_global_rate_ratio_threshold[7]; //!< Slide Window Global Rate Ratio Threshold |
| 1161 |
static const uint8_t BRC_UPD_start_global_adjust_mult[5]; //!< Start Global Adjust Multiply |
| 1162 |
static const uint8_t BRC_UPD_start_global_adjust_div[5]; //!< Start Global Adjust Division |
| 1163 |
static const int8_t BRC_UPD_global_rate_ratio_threshold_qp[8]; //!< Global Rate Ratio QP Threshold |
| 1164 |
static const uint32_t AVC_Mode_Cost[2][12][CODEC_AVC_NUM_QP]; //!< Mode Cost Table. |
| 1165 |
static const int8_t BRC_UPD_GlobalRateQPAdjTabI_U8[64]; //!< I Picture Global Rate QP Adjustment Table. |
| 1166 |
static const int8_t BRC_UPD_GlobalRateQPAdjTabP_U8[64]; //!< P Picture Global Rate QP Adjustment Table. |
| 1167 |
static const int8_t BRC_UPD_SlWinGlobalRateQPAdjTabP_U8[64]; //!< P picture Global Rate QP Adjustment Table for Sliding Window BRC |
| 1168 |
static const int8_t BRC_UPD_GlobalRateQPAdjTabB_U8[64]; //!< B Picture Global Rate QP Adjustment Table. |
| 1169 |
static const uint8_t BRC_UPD_DistThreshldI_U8[10]; //!< I Picture Distortion THreshold. |
| 1170 |
static const uint8_t BRC_UPD_DistThreshldP_U8[10]; //!< P Picture Distortion THreshold. |
| 1171 |
static const int8_t CBR_UPD_DistQPAdjTabI_U8[81]; //!< I Picture Distortion QP Adjustment Table under CBR Mode. |
| 1172 |
static const int8_t CBR_UPD_DistQPAdjTabP_U8[81]; //!< P Picture Distortion QP Adjustment Table under CBR Mode. |
| 1173 |
static const int8_t CBR_UPD_DistQPAdjTabB_U8[81]; //!< B Picture Distortion QP Adjustment Table under CBR Mode. |
| 1174 |
static const int8_t VBR_UPD_DistQPAdjTabI_U8[81]; //!< I Picture Distortion QP Adjustment Table under VBR Mode. |
| 1175 |
static const int8_t VBR_UPD_DistQPAdjTabP_U8[81]; //!< P Picture Distortion QP Adjustment Table under VBR Mode. |
| 1176 |
static const int8_t VBR_UPD_DistQPAdjTabB_U8[81]; //!< B Picture Distortion QP Adjustment Table under VBR Mode. |
| 1177 |
static const int8_t CBR_UPD_FrmSzAdjTabI_S8[72]; //!< I Picture Frame Size Adjustment Table under CBR Mode. |
| 1178 |
static const int8_t CBR_UPD_FrmSzAdjTabP_S8[72]; //!< P Picture Frame Size Adjustment Table under CBR Mode. |
| 1179 |
static const int8_t CBR_UPD_FrmSzAdjTabB_S8[72]; //!< B Picture Frame Size Adjustment Table under CBR Mode. |
| 1180 |
static const int8_t VBR_UPD_FrmSzAdjTabI_S8[72]; //!< I Picture Frame Size Adjustment Table under VBR Mode. |
| 1181 |
static const int8_t VBR_UPD_FrmSzAdjTabP_S8[72]; //!< P Picture Frame Size Adjustment Table under VBR Mode. |
| 1182 |
static const int8_t VBR_UPD_FrmSzAdjTabB_S8[72]; //!< B Picture Frame Size Adjustment Table under VBR Mode. |
| 1183 |
static const int8_t QVBR_UPD_FrmSzAdjTabP_S8[72]; //!< P Picture Frame Size Adjustment Table under QVBR Mode. |
| 1184 |
static const int8_t LOW_DELAY_UPD_FrmSzAdjTabI_S8[72]; //!< I Picture Frame Size Adjustment Table under Low Delay Mode. |
| 1185 |
static const int8_t LOW_DELAY_UPD_FrmSzAdjTabP_S8[72]; //!< P Picture Frame Size Adjustment Table under Low Delay Mode. |
| 1186 |
static const int8_t LOW_DELAY_UPD_FrmSzAdjTabB_S8[72]; //!< B Picture Frame Size Adjustment Table under Low Delay Mode. |
| 1187 |
static const uint8_t BRC_UPD_FrmSzMinTabP_U8[9]; //!< I Picture Minimum Frame Size Table. |
| 1188 |
static const uint8_t BRC_UPD_FrmSzMinTabI_U8[9]; //!< P Picture Minimum Frame Size Table. |
| 1189 |
static const uint8_t BRC_UPD_FrmSzMaxTabP_U8[9]; //!< I Picture Maximum Frame Size Table. |
| 1190 |
static const uint8_t BRC_UPD_FrmSzMaxTabI_U8[9]; //!< P Picture Maximum Frame Size Table. |
| 1191 |
static const uint8_t BRC_UPD_FrmSzSCGTabP_U8[9]; //!< |
| 1192 |
static const uint8_t BRC_UPD_FrmSzSCGTabI_U8[9]; //!< |
| 1193 |
|
| 1194 |
///< BRC Const Data. |
| 1195 |
static const uint8_t BRC_UPD_I_IntraNonPred[42]; //!< Cost Table for Intra Non-Prediction |
| 1196 |
static const uint8_t BRC_UPD_I_Intra8x8[42]; //!< Cost Table for Intra 8x8 |
| 1197 |
static const uint8_t BRC_UPD_I_Intra4x4[42]; //!< Cost Table for Intra 4x4 |
| 1198 |
static const uint8_t BRC_UPD_I_IntraChroma[42]; //!< Cost Table for Intra Chrome |
| 1199 |
static const uint8_t BRC_UPD_P_IntraNonPred[42]; //!< Cost Table for Intra Non-Prediction |
| 1200 |
static const uint8_t BRC_UPD_P_Intra16x16[42]; //!< Cost Table for Intra 16x16 |
| 1201 |
static const uint8_t BRC_UPD_P_Intra8x8[42]; //!< Cost Table for Intra 8x8 |
| 1202 |
static const uint8_t BRC_UPD_P_Intra4x4[42]; //!< Cost Table for Intra 4x4 |
| 1203 |
static const uint8_t BRC_UPD_P_Inter16x8[42]; //!< Cost Table for Inter 16x8 |
| 1204 |
static const uint8_t BRC_UPD_P_Inter8x8[42]; //!< Cost Table for Inter 8x8 |
| 1205 |
static const uint8_t BRC_UPD_P_Inter16x16[42]; //!< Cost Table for Inter 16x16 |
| 1206 |
static const uint8_t BRC_UPD_P_RefId[42]; //!< Cost Table for Reference Index |
| 1207 |
|
| 1208 |
static const bool SHMEEnabled[NUM_VDENC_TARGET_USAGE_MODES]; //!< SHME Enabled Query Table. |
| 1209 |
static const bool UHMEEnabled[NUM_VDENC_TARGET_USAGE_MODES]; //!< HME Enabled Query Table. |
| 1210 |
static const uint8_t MaxRefIdx0[NUM_VDENC_TARGET_USAGE_MODES]; //!< Max Reference Index Query Table. |
| 1211 |
static const uint8_t AdaptiveInterRoundingPWithoutB[CODEC_AVC_NUM_QP]; //!< InterRounding Table. |
| 1212 |
static const uint8_t AdaptiveInterRoundingP[CODEC_AVC_NUM_QP]; //!< InterRounding Table. |
| 1213 |
static const uint32_t InterRoundingP[NUM_TARGET_USAGE_MODES]; //!< P Picture InterRounding Table. |
| 1214 |
static const uint32_t InterRoundingB[NUM_TARGET_USAGE_MODES]; //!< B Picture InterRounding Table. |
| 1215 |
static const uint32_t InterRoundingBRef[NUM_TARGET_USAGE_MODES]; //!< B Ref Picture InterRounding Table. |
| 1216 |
static const uint8_t AdaptiveInterRoundingB[CODEC_AVC_NUM_QP]; //!< B Picture Adaptive InterRounding Table. |
| 1217 |
|
| 1218 |
static const uint16_t SliceSizeThrsholdsI[CODEC_AVC_NUM_QP]; //!< I picture slice size conformance thresholds table. |
| 1219 |
static const uint16_t SliceSizeThrsholdsP[CODEC_AVC_NUM_QP]; //!< P picture slice size conformance thresholds table. |
| 1220 |
|
| 1221 |
#if USE_CODECHAL_DEBUG_TOOL |
| 1222 |
protected: |
| 1223 |
virtual MOS_STATUS DumpHucBrcInit(); |
| 1224 |
|
| 1225 |
virtual MOS_STATUS DumpHucBrcUpdate(bool isInput); |
| 1226 |
|
| 1227 |
virtual MOS_STATUS DumpEncodeImgStats( |
| 1228 |
PMOS_COMMAND_BUFFER cmdbuffer); |
| 1229 |
|
| 1230 |
virtual uint32_t GetPakVDEncPassDumpSize(); |
| 1231 |
|
| 1232 |
virtual MOS_STATUS DumpSeqParFile() override; |
| 1233 |
virtual MOS_STATUS DumpFrameParFile() override; |
| 1234 |
|
| 1235 |
virtual MOS_STATUS PopulateHmeParam( |
| 1236 |
bool is16xMeEnabled, |
| 1237 |
bool is32xMeEnabled, |
| 1238 |
uint8_t meMethod, |
| 1239 |
void *cmd) override; |
| 1240 |
|
| 1241 |
virtual MOS_STATUS PopulateEncParam( |
| 1242 |
uint8_t meMethod, |
| 1243 |
void *cmd) override |
| 1244 |
{ |
| 1245 |
return MOS_STATUS_SUCCESS; |
| 1246 |
} |
| 1247 |
|
| 1248 |
//! |
| 1249 |
//! \brief Modify the frame and slice header size with fake header size |
| 1250 |
//! |
| 1251 |
//! \param [in] cmdBuffer |
| 1252 |
//! command buffer |
| 1253 |
//! |
| 1254 |
//! \return MOS_STATUS |
| 1255 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 1256 |
//! |
| 1257 |
virtual MOS_STATUS ModifyEncodedFrameSizeWithFakeHeaderSize( PMOS_COMMAND_BUFFER cmdBuffer); |
| 1258 |
#endif |
| 1259 |
}; |
| 1260 |
|
| 1261 |
// template functions for all gen-x platforms. |
| 1262 |
template <class CODECHAL_VDENC_AVC_BRC_INIT_DMEM> |
| 1263 |
MOS_STATUS CodechalVdencAvcState::SetDmemHuCBrcInitResetImpl(CODECHAL_VDENC_AVC_BRC_INIT_DMEM* hucVDEncBrcInitDmem) |
| 1264 |
{ |
| 1265 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1266 |
|
| 1267 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1268 |
|
| 1269 |
auto avcSeqParams = m_avcSeqParam; |
| 1270 |
if (avcSeqParams->FrameSizeTolerance == EFRAMESIZETOL_EXTREMELY_LOW) // Low Delay Mode |
| 1271 |
{ |
| 1272 |
avcSeqParams->MaxBitRate = avcSeqParams->TargetBitRate; |
| 1273 |
} |
| 1274 |
|
| 1275 |
m_dBrcInitResetInputBitsPerFrame = |
| 1276 |
((double)avcSeqParams->MaxBitRate * 100) / avcSeqParams->FramesPer100Sec; |
| 1277 |
m_dBrcInitCurrentTargetBufFullInBits = m_dBrcInitResetInputBitsPerFrame; |
| 1278 |
m_dBrcTargetSize = avcSeqParams->InitVBVBufferFullnessInBit; |
| 1279 |
|
| 1280 |
hucVDEncBrcInitDmem->BRCFunc_U8 = m_brcInit ? 0 : 2; // 0 for init, 2 for reset |
| 1281 |
|
| 1282 |
hucVDEncBrcInitDmem->INIT_FrameWidth_U16 = (uint16_t)m_frameWidth; |
| 1283 |
hucVDEncBrcInitDmem->INIT_FrameHeight_U16 = (uint16_t)m_frameHeight; |
| 1284 |
|
| 1285 |
hucVDEncBrcInitDmem->INIT_TargetBitrate_U32 = avcSeqParams->TargetBitRate; |
| 1286 |
hucVDEncBrcInitDmem->INIT_MinRate_U32 = avcSeqParams->MinBitRate; |
| 1287 |
hucVDEncBrcInitDmem->INIT_MaxRate_U32 = avcSeqParams->MaxBitRate; |
| 1288 |
hucVDEncBrcInitDmem->INIT_BufSize_U32 = avcSeqParams->VBVBufferSizeInBit; |
| 1289 |
hucVDEncBrcInitDmem->INIT_InitBufFull_U32 = avcSeqParams->InitVBVBufferFullnessInBit; |
| 1290 |
|
| 1291 |
if (hucVDEncBrcInitDmem->INIT_InitBufFull_U32 > avcSeqParams->VBVBufferSizeInBit) |
| 1292 |
hucVDEncBrcInitDmem->INIT_InitBufFull_U32 = avcSeqParams->VBVBufferSizeInBit; |
| 1293 |
|
| 1294 |
switch (avcSeqParams->RateControlMethod) |
| 1295 |
{ |
| 1296 |
case RATECONTROL_CBR: |
| 1297 |
hucVDEncBrcInitDmem->INIT_BRCFlag_U16 |= BRCFLAG_ISCBR; |
| 1298 |
break; |
| 1299 |
case RATECONTROL_VBR: |
| 1300 |
hucVDEncBrcInitDmem->INIT_BRCFlag_U16 |= BRCFLAG_ISVBR; |
| 1301 |
break; |
| 1302 |
case RATECONTROL_QVBR: |
| 1303 |
// QVBR will use VBR BRCFlag, triggered when ICQQualityFactor > 10 |
| 1304 |
hucVDEncBrcInitDmem->INIT_BRCFlag_U16 |= BRCFLAG_ISVBR; |
| 1305 |
break; |
| 1306 |
// Temp solution using AVBR for low delay case, before the BRC flag is added to DDI |
| 1307 |
case RATECONTROL_AVBR: |
| 1308 |
hucVDEncBrcInitDmem->INIT_BRCFlag_U16 |= BRCFLAG_ISLOWDELAY; |
| 1309 |
break; |
| 1310 |
case RATECONTROL_ICQ: |
| 1311 |
hucVDEncBrcInitDmem->INIT_BRCFlag_U16 |= BRCFLAG_ISICQ; |
| 1312 |
break; |
| 1313 |
case RATECONTROL_VCM: |
| 1314 |
hucVDEncBrcInitDmem->INIT_BRCFlag_U16 |= BRCFLAG_ISVCM; |
| 1315 |
break; |
| 1316 |
default: |
| 1317 |
break; |
| 1318 |
} |
| 1319 |
|
| 1320 |
if (avcSeqParams->FrameSizeTolerance == EFRAMESIZETOL_EXTREMELY_LOW) // Low Delay Mode |
| 1321 |
{ |
| 1322 |
hucVDEncBrcInitDmem->INIT_BRCFlag_U16 = BRCFLAG_ISLOWDELAY; |
| 1323 |
hucVDEncBrcInitDmem->INIT_LowDelayGoldenFrameBoost_U8 = 0; //get from ? |
| 1324 |
} |
| 1325 |
|
| 1326 |
hucVDEncBrcInitDmem->INIT_FrameRateM_U32 = avcSeqParams->FramesPer100Sec; |
| 1327 |
hucVDEncBrcInitDmem->INIT_FrameRateD_U32 = 100; |
| 1328 |
|
| 1329 |
uint32_t profileLevelMaxFrame; |
| 1330 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalAvcEncode_GetProfileLevelMaxFrameSize( |
| 1331 |
avcSeqParams, this, &profileLevelMaxFrame)); |
| 1332 |
|
| 1333 |
hucVDEncBrcInitDmem->INIT_ProfileLevelMaxFrame_U32 = profileLevelMaxFrame; |
| 1334 |
|
| 1335 |
if (avcSeqParams->GopRefDist >= avcSeqParams->GopPicSize && avcSeqParams->GopPicSize > 1) |
| 1336 |
{ |
| 1337 |
hucVDEncBrcInitDmem->INIT_GopP_U16 = 1; |
| 1338 |
hucVDEncBrcInitDmem->INIT_GopB_U16 = avcSeqParams->GopPicSize - 2; |
| 1339 |
} |
| 1340 |
else if (avcSeqParams->GopRefDist && (avcSeqParams->GopPicSize > 0)) |
| 1341 |
{ |
| 1342 |
// Their ratio is used in BRC kernel to detect mini GOP structure. Have to be multiple. |
| 1343 |
hucVDEncBrcInitDmem->INIT_GopP_U16 = (avcSeqParams->GopPicSize - 1) / avcSeqParams->GopRefDist; |
| 1344 |
hucVDEncBrcInitDmem->INIT_GopB_U16 = (avcSeqParams->GopRefDist - 1) * hucVDEncBrcInitDmem->INIT_GopP_U16; |
| 1345 |
} |
| 1346 |
|
| 1347 |
if (m_minMaxQpControlEnabled) |
| 1348 |
{ |
| 1349 |
// Convert range [1,51] to [10,51] for VDEnc due to HW limitation |
| 1350 |
hucVDEncBrcInitDmem->INIT_MinQP_U16 = MOS_MAX(m_iMinQp, 10); |
| 1351 |
hucVDEncBrcInitDmem->INIT_MaxQP_U16 = MOS_MAX(m_iMaxQp, 10); |
| 1352 |
} |
| 1353 |
else |
| 1354 |
{ |
| 1355 |
hucVDEncBrcInitDmem->INIT_MinQP_U16 = CODECHAL_VDENC_AVC_BRC_MIN_QP; // Setting values from arch spec |
| 1356 |
hucVDEncBrcInitDmem->INIT_MaxQP_U16 = CODECHAL_ENCODE_AVC_MAX_SLICE_QP; // Setting values from arch spec |
| 1357 |
} |
| 1358 |
|
| 1359 |
//dynamic deviation thresholds |
| 1360 |
double inputBitsPerFrame = ((double)avcSeqParams->MaxBitRate * (double)100) / (double)avcSeqParams->FramesPer100Sec; |
| 1361 |
double bps_ratio = inputBitsPerFrame / ((double)avcSeqParams->VBVBufferSizeInBit * 100 / avcSeqParams->FramesPer100Sec/*DEV_STD_FPS*/); |
| 1362 |
if (bps_ratio < CODECHAL_VDENC_AVC_BPS_RATIO_LOW) bps_ratio = CODECHAL_VDENC_AVC_BPS_RATIO_LOW; |
| 1363 |
if (bps_ratio > CODECHAL_VDENC_AVC_BPS_RATIO_HIGH) bps_ratio = CODECHAL_VDENC_AVC_BPS_RATIO_HIGH; |
| 1364 |
|
| 1365 |
if (avcSeqParams->FrameSizeTolerance == EFRAMESIZETOL_EXTREMELY_LOW) // Low Delay Mode |
| 1366 |
{ |
| 1367 |
MOS_SecureMemcpy(hucVDEncBrcInitDmem->INIT_DevThreshPB0_S8, 8 * sizeof(int8_t), (void*)BRC_LowDelay_DevThreshPB0_S8, 8 * sizeof(int8_t)); |
| 1368 |
MOS_SecureMemcpy(hucVDEncBrcInitDmem->INIT_DevThreshI0_S8, 8 * sizeof(int8_t), (void*)BRC_LowDelay_DevThreshI0_S8, 8 * sizeof(int8_t)); |
| 1369 |
MOS_SecureMemcpy(hucVDEncBrcInitDmem->INIT_DevThreshVBR0_S8, 8 * sizeof(int8_t), (void*)BRC_LowDelay_DevThreshVBR0_S8, 8 * sizeof(int8_t)); |
| 1370 |
} |
| 1371 |
else |
| 1372 |
{ |
| 1373 |
//dynamic deviation thresholds |
| 1374 |
for (int i = 0; i < CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2; i++) |
| 1375 |
{ |
| 1376 |
hucVDEncBrcInitDmem->INIT_DevThreshPB0_S8[i] = |
| 1377 |
(int8_t)(CODECHAL_VDENC_AVC_NEG_MULT_PB * pow(BRC_DevThreshPB0_FP_NEG[i], bps_ratio)); |
| 1378 |
hucVDEncBrcInitDmem->INIT_DevThreshPB0_S8[i + CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2] = |
| 1379 |
(int8_t)(CODECHAL_VDENC_AVC_POS_MULT_PB * pow(BRC_DevThreshPB0_FP_POS[i], bps_ratio)); |
| 1380 |
|
| 1381 |
hucVDEncBrcInitDmem->INIT_DevThreshI0_S8[i] = |
| 1382 |
(int8_t)(CODECHAL_VDENC_AVC_NEG_MULT_I * pow(BRC_DevThreshI0_FP_NEG[i], bps_ratio)); |
| 1383 |
hucVDEncBrcInitDmem->INIT_DevThreshI0_S8[i + CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2] = |
| 1384 |
(int8_t)(CODECHAL_VDENC_AVC_POS_MULT_I * pow(BRC_DevThreshI0_FP_POS[i], bps_ratio)); |
| 1385 |
|
| 1386 |
hucVDEncBrcInitDmem->INIT_DevThreshVBR0_S8[i] = |
| 1387 |
(int8_t)(CODECHAL_VDENC_AVC_NEG_MULT_VBR * pow(BRC_DevThreshVBR0_NEG[i], bps_ratio)); |
| 1388 |
hucVDEncBrcInitDmem->INIT_DevThreshVBR0_S8[i + CODECHAL_VDENC_AVC_N_DEV_THRESHLDS / 2] = |
| 1389 |
(int8_t)(CODECHAL_VDENC_AVC_POS_MULT_VBR * pow(BRC_DevThreshVBR0_POS[i], bps_ratio)); |
| 1390 |
} |
| 1391 |
} |
| 1392 |
|
| 1393 |
int32_t initQP; |
| 1394 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ComputeBRCInitQP(avcSeqParams, &initQP)); |
| 1395 |
|
| 1396 |
hucVDEncBrcInitDmem->INIT_InitQPIP = (uint8_t)initQP; |
| 1397 |
|
| 1398 |
// MBBRC control |
| 1399 |
if (IsMBBRCControlEnabled()) |
| 1400 |
{ |
| 1401 |
hucVDEncBrcInitDmem->INIT_MbQpCtrl_U8 = 1; |
| 1402 |
MOS_SecureMemcpy(hucVDEncBrcInitDmem->INIT_DistQPDelta_I8, 4 * sizeof(int8_t), (void*)BRC_INIT_DistQPDelta_I8, 4 * sizeof(int8_t)); |
| 1403 |
} |
| 1404 |
|
| 1405 |
hucVDEncBrcInitDmem->INIT_SliceSizeCtrlEn_U8 = avcSeqParams->EnableSliceLevelRateCtrl; // Enable slice size control |
| 1406 |
|
| 1407 |
hucVDEncBrcInitDmem->INIT_OscillationQpDelta_U8 = |
| 1408 |
((avcSeqParams->RateControlMethod == RATECONTROL_VCM) || (avcSeqParams->RateControlMethod == RATECONTROL_QVBR)) ? 16 : 0; |
| 1409 |
hucVDEncBrcInitDmem->INIT_HRDConformanceCheckDisable_U8 = |
| 1410 |
((avcSeqParams->RateControlMethod == RATECONTROL_VCM) || (avcSeqParams->RateControlMethod == RATECONTROL_AVBR)) ? 1 : 0; |
| 1411 |
|
| 1412 |
// Adaptive 2nd re-encode pass |
| 1413 |
if (m_picWidthInMb * m_picHeightInMb >= ((3840 * 2160) >> 8)) // >= 4K |
| 1414 |
{ |
| 1415 |
hucVDEncBrcInitDmem->INIT_TopQPDeltaThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_BRC_TOPQPDELTATHRFORADAPT2PASS_4K; |
| 1416 |
hucVDEncBrcInitDmem->INIT_BotQPDeltaThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_BRC_BOTQPDELTATHRFORADAPT2PASS_4K; |
| 1417 |
hucVDEncBrcInitDmem->INIT_TopFrmSzThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_BRC_TOPFRMSZTHRFORADAPT2PASS_4K; |
| 1418 |
hucVDEncBrcInitDmem->INIT_BotFrmSzThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_BRC_BOTFRMSZTHRFORADAPT2PASS_4K; |
| 1419 |
} |
| 1420 |
else |
| 1421 |
{ |
| 1422 |
if (avcSeqParams->RateControlMethod == RATECONTROL_AVBR) |
| 1423 |
{ |
| 1424 |
hucVDEncBrcInitDmem->INIT_TopQPDeltaThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_AVBR_TOPQPDELTATHRFORADAPT2PASS; |
| 1425 |
hucVDEncBrcInitDmem->INIT_BotQPDeltaThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_AVBR_BOTQPDELTATHRFORADAPT2PASS; |
| 1426 |
hucVDEncBrcInitDmem->INIT_TopFrmSzThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_AVBR_TOPFRMSZTHRFORADAPT2PASS; |
| 1427 |
hucVDEncBrcInitDmem->INIT_BotFrmSzThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_AVBR_BOTFRMSZTHRFORADAPT2PASS; |
| 1428 |
} |
| 1429 |
else |
| 1430 |
{ |
| 1431 |
hucVDEncBrcInitDmem->INIT_TopQPDeltaThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_BRC_TOPQPDELTATHRFORADAPT2PASS; |
| 1432 |
hucVDEncBrcInitDmem->INIT_BotQPDeltaThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_BRC_BOTQPDELTATHRFORADAPT2PASS; |
| 1433 |
hucVDEncBrcInitDmem->INIT_TopFrmSzThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_BRC_TOPFRMSZTHRFORADAPT2PASS; |
| 1434 |
hucVDEncBrcInitDmem->INIT_BotFrmSzThrForAdapt2Pass_U8 = CODECHAL_VDENC_AVC_BRC_BOTFRMSZTHRFORADAPT2PASS; |
| 1435 |
} |
| 1436 |
} |
| 1437 |
|
| 1438 |
hucVDEncBrcInitDmem->INIT_QPSelectForFirstPass_U8 = 1; |
| 1439 |
hucVDEncBrcInitDmem->INIT_MBHeaderCompensation_U8 = 1; |
| 1440 |
hucVDEncBrcInitDmem->INIT_DeltaQP_Adaptation_U8 = 1; |
| 1441 |
hucVDEncBrcInitDmem->INIT_MaxCRFQualityFactor_U8 = CODECHAL_ENCODE_AVC_MAX_ICQ_QUALITYFACTOR + 1; |
| 1442 |
|
| 1443 |
if (RATECONTROL_QVBR == avcSeqParams->RateControlMethod || RATECONTROL_ICQ == avcSeqParams->RateControlMethod) |
| 1444 |
{ |
| 1445 |
hucVDEncBrcInitDmem->INIT_CRFQualityFactor_U8 = (uint8_t)avcSeqParams->ICQQualityFactor; |
| 1446 |
hucVDEncBrcInitDmem->INIT_ScenarioInfo_U8 = (RATECONTROL_QVBR == avcSeqParams->RateControlMethod) ? 1 : 0; |
| 1447 |
} |
| 1448 |
|
| 1449 |
if (m_avcPicParam->NumDirtyROI) |
| 1450 |
{ |
| 1451 |
hucVDEncBrcInitDmem->INIT_ScenarioInfo_U8 = 1; //DISPLAYREMOTING |
| 1452 |
} |
| 1453 |
|
| 1454 |
if (avcSeqParams->FrameSizeTolerance == EFRAMESIZETOL_LOW) // Sliding Window BRC |
| 1455 |
{ |
| 1456 |
hucVDEncBrcInitDmem->INIT_SlidingWidowRCEnable_U8 = 1; |
| 1457 |
hucVDEncBrcInitDmem->INIT_SlidingWindowSize_U8 = (uint8_t)(avcSeqParams->FramesPer100Sec / 100); |
| 1458 |
hucVDEncBrcInitDmem->INIT_SlidingWindowMaxRateRatio_U8 = 120; |
| 1459 |
} |
| 1460 |
|
| 1461 |
MOS_SecureMemcpy(hucVDEncBrcInitDmem->INIT_EstRateThreshP0_U8, 7 * sizeof(uint8_t), (void*)BRC_EstRateThreshP0_U8, 7 * sizeof(uint8_t)); |
| 1462 |
MOS_SecureMemcpy(hucVDEncBrcInitDmem->INIT_EstRateThreshI0_U8, 7 * sizeof(uint8_t), (void*)BRC_EstRateThreshI0_U8, 7 * sizeof(uint8_t)); |
| 1463 |
|
| 1464 |
return eStatus; |
| 1465 |
} |
| 1466 |
|
| 1467 |
template <class CODECHAL_VDENC_AVC_BRC_UPDATE_DMEM> |
| 1468 |
MOS_STATUS CodechalVdencAvcState::SetDmemHuCBrcUpdateImpl(CODECHAL_VDENC_AVC_BRC_UPDATE_DMEM* hucVDEncBrcDmem) |
| 1469 |
{ |
| 1470 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1471 |
|
| 1472 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1473 |
|
| 1474 |
auto avcSeqParams = m_avcSeqParam; |
| 1475 |
auto avcPicParams = m_avcPicParam; |
| 1476 |
|
| 1477 |
hucVDEncBrcDmem->BRCFunc_U8 = 1; // Update:1 |
| 1478 |
|
| 1479 |
if (!m_brcInit && (m_currPass == 0)) |
| 1480 |
{ |
| 1481 |
m_brcInitPreviousTargetBufFullInBits = |
| 1482 |
(uint32_t)(m_dBrcInitCurrentTargetBufFullInBits + m_dBrcInitResetInputBitsPerFrame * m_numSkipFrames); |
| 1483 |
m_dBrcInitCurrentTargetBufFullInBits += m_dBrcInitResetInputBitsPerFrame * (1 + m_numSkipFrames); |
| 1484 |
m_dBrcTargetSize += m_dBrcInitResetInputBitsPerFrame * (1 + m_numSkipFrames); |
| 1485 |
} |
| 1486 |
|
| 1487 |
if (m_dBrcTargetSize > avcSeqParams->VBVBufferSizeInBit) |
| 1488 |
{ |
| 1489 |
m_dBrcTargetSize -= avcSeqParams->VBVBufferSizeInBit; |
| 1490 |
} |
| 1491 |
|
| 1492 |
hucVDEncBrcDmem->UPD_FRAMENUM_U32 = m_avcSliceParams->frame_num; |
| 1493 |
hucVDEncBrcDmem->UPD_TARGETSIZE_U32 = (uint32_t)(m_dBrcTargetSize); |
| 1494 |
hucVDEncBrcDmem->UPD_PeakTxBitsPerFrame_U32 = (uint32_t)(m_dBrcInitCurrentTargetBufFullInBits - m_brcInitPreviousTargetBufFullInBits); |
| 1495 |
|
| 1496 |
//Dynamic slice size control |
| 1497 |
if (avcSeqParams->EnableSliceLevelRateCtrl) |
| 1498 |
{ |
| 1499 |
hucVDEncBrcDmem->UPD_SLCSZ_TARGETSLCSZ_U16 = (uint16_t)avcPicParams->SliceSizeInBytes; // target slice size |
| 1500 |
hucVDEncBrcDmem->UPD_TargetSliceSize_U16 = (uint16_t)avcPicParams->SliceSizeInBytes; // set max slice size to be same as target slice size |
| 1501 |
hucVDEncBrcDmem->UPD_MaxNumSliceAllowed_U16 = (uint16_t)m_maxNumSlicesAllowed; |
| 1502 |
|
| 1503 |
for (uint8_t k = 0; k < 42; k++) |
| 1504 |
{ |
| 1505 |
hucVDEncBrcDmem->UPD_SLCSZ_UPD_THRDELTAI_U16[k] = MOS_MIN(avcPicParams->SliceSizeInBytes - 150, m_vdencSSCThrsTblI[k+10]); |
| 1506 |
hucVDEncBrcDmem->UPD_SLCSZ_UPD_THRDELTAP_U16[k] = MOS_MIN(avcPicParams->SliceSizeInBytes - 150, m_vdencSSCThrsTblP[k+10]); |
| 1507 |
} |
| 1508 |
} |
| 1509 |
else |
| 1510 |
{ |
| 1511 |
hucVDEncBrcDmem->UPD_SLCSZ_TARGETSLCSZ_U16 = 0; |
| 1512 |
hucVDEncBrcDmem->UPD_TargetSliceSize_U16 = 0; |
| 1513 |
hucVDEncBrcDmem->UPD_MaxNumSliceAllowed_U16 = 0; |
| 1514 |
|
| 1515 |
for (uint8_t k = 0; k < 42; k++) |
| 1516 |
{ |
| 1517 |
hucVDEncBrcDmem->UPD_SLCSZ_UPD_THRDELTAI_U16[k] = 0; |
| 1518 |
hucVDEncBrcDmem->UPD_SLCSZ_UPD_THRDELTAP_U16[k] = 0; |
| 1519 |
} |
| 1520 |
} |
| 1521 |
|
| 1522 |
if (avcSeqParams->FrameSizeTolerance == EFRAMESIZETOL_LOW) // Sliding Window BRC |
| 1523 |
{ |
| 1524 |
MOS_SecureMemcpy(hucVDEncBrcDmem->UPD_gRateRatioThreshold_U8, 7 * sizeof(uint8_t), (void*)BRC_UPD_slwin_global_rate_ratio_threshold, 7 * sizeof(uint8_t)); |
| 1525 |
} |
| 1526 |
else |
| 1527 |
{ |
| 1528 |
MOS_SecureMemcpy(hucVDEncBrcDmem->UPD_gRateRatioThreshold_U8, 7 * sizeof(uint8_t), (void*)BRC_UPD_global_rate_ratio_threshold, 7 * sizeof(uint8_t)); |
| 1529 |
} |
| 1530 |
|
| 1531 |
hucVDEncBrcDmem->UPD_CurrFrameType_U8 = (m_pictureCodingType + 1) % 3; // I:1, P:2, B:0 |
| 1532 |
|
| 1533 |
MOS_SecureMemcpy(hucVDEncBrcDmem->UPD_startGAdjFrame_U16, 4 * sizeof(uint16_t), (void*)BRC_UPD_start_global_adjust_frame, 4 * sizeof(uint16_t)); |
| 1534 |
|
| 1535 |
MOS_SecureMemcpy(hucVDEncBrcDmem->UPD_startGAdjMult_U8, 5 * sizeof(uint8_t), (void*)BRC_UPD_start_global_adjust_mult, 5 * sizeof(uint8_t)); |
| 1536 |
|
| 1537 |
MOS_SecureMemcpy(hucVDEncBrcDmem->UPD_startGAdjDiv_U8, 5 * sizeof(uint8_t), (void*)BRC_UPD_start_global_adjust_div, 5 * sizeof(uint8_t)); |
| 1538 |
|
| 1539 |
MOS_SecureMemcpy(hucVDEncBrcDmem->UPD_gRateRatioThresholdQP_U8, 8 * sizeof(uint8_t), (void*)BRC_UPD_global_rate_ratio_threshold_qp, 8 * sizeof(uint8_t)); |
| 1540 |
|
| 1541 |
hucVDEncBrcDmem->UPD_PAKPassNum_U8 = m_currPass; |
| 1542 |
hucVDEncBrcDmem->UPD_MaxNumPass_U8 = m_numPasses + 1; |
| 1543 |
|
| 1544 |
uint32_t numP = 0; |
| 1545 |
if (avcSeqParams->GopRefDist && (avcSeqParams->GopPicSize > 0)) |
| 1546 |
{ |
| 1547 |
numP = (avcSeqParams->GopPicSize - 1) / avcSeqParams->GopRefDist; |
| 1548 |
} |
| 1549 |
|
| 1550 |
for (int32_t i = 0; i < 2; i++) |
| 1551 |
{ |
| 1552 |
hucVDEncBrcDmem->UPD_SceneChgWidth_U8[i] = (uint8_t)MOS_MIN((numP + 1) / 5, 6); |
| 1553 |
} |
| 1554 |
|
| 1555 |
hucVDEncBrcDmem->UPD_SceneChgDetectEn_U8 = 1; |
| 1556 |
hucVDEncBrcDmem->UPD_SceneChgPrevIntraPctThreshold_U8 = 0x60; |
| 1557 |
hucVDEncBrcDmem->UPD_SceneChgCurIntraPctThreshold_U8 = 0xc0; |
| 1558 |
|
| 1559 |
hucVDEncBrcDmem->UPD_IPAverageCoeff_U8 = |
| 1560 |
(avcSeqParams->FrameSizeTolerance == EFRAMESIZETOL_EXTREMELY_LOW) ? 0 : 0x80; |
| 1561 |
|
| 1562 |
hucVDEncBrcDmem->UPD_CQP_FracQp_U8 = 0; |
| 1563 |
|
| 1564 |
if (avcSeqParams->RateControlMethod == RATECONTROL_ICQ) |
| 1565 |
{ |
| 1566 |
hucVDEncBrcDmem->UPD_CQP_QpValue_U8 = 18; //Cmodel suggested a few values to try: 18,20,26,30 |
| 1567 |
} |
| 1568 |
else |
| 1569 |
{ |
| 1570 |
hucVDEncBrcDmem->UPD_CQP_QpValue_U8 = 0; |
| 1571 |
} |
| 1572 |
|
| 1573 |
if (m_staticFrameDetectionInUse) |
| 1574 |
{ |
| 1575 |
hucVDEncBrcDmem->UPD_HMEDetectionEnable_U8 = 1; |
| 1576 |
} |
| 1577 |
else |
| 1578 |
{ |
| 1579 |
hucVDEncBrcDmem->UPD_HMEDetectionEnable_U8 = 0; |
| 1580 |
} |
| 1581 |
|
| 1582 |
// Skipped frame handling |
| 1583 |
if (m_numSkipFrames) |
| 1584 |
{ |
| 1585 |
// CP case: one or more frames with skip flag = 2 received and copied |
| 1586 |
hucVDEncBrcDmem->UPD_SkipFrameSize_U16 = (uint16_t)m_sizeSkipFrames; |
| 1587 |
hucVDEncBrcDmem->UPD_NumOfFramesSkipped_U16 = (uint16_t)m_numSkipFrames; |
| 1588 |
} |
| 1589 |
else if (FRAME_SKIP_NORMAL == m_skipFrameFlag) |
| 1590 |
{ |
| 1591 |
// non-CP case: use the num/size of skipped frames passed in by MSDK |
| 1592 |
hucVDEncBrcDmem->UPD_SkipFrameSize_U16 = (uint16_t)m_avcPicParam->SizeSkipFrames; |
| 1593 |
hucVDEncBrcDmem->UPD_NumOfFramesSkipped_U16 = (uint16_t)m_avcPicParam->NumSkipFrames; |
| 1594 |
} |
| 1595 |
else |
| 1596 |
{ |
| 1597 |
hucVDEncBrcDmem->UPD_SkipFrameSize_U16 = 0; |
| 1598 |
hucVDEncBrcDmem->UPD_NumOfFramesSkipped_U16 = 0; |
| 1599 |
} |
| 1600 |
|
| 1601 |
// HMECost enabled by default in CModel V11738+ |
| 1602 |
hucVDEncBrcDmem->UPD_HMECostEnable_U8 = 1; |
| 1603 |
|
| 1604 |
// ROI and static region pct parameters |
| 1605 |
// must be zero if they are not used |
| 1606 |
hucVDEncBrcDmem->UPD_RoiQpViaForceQp_U8 = 0; |
| 1607 |
hucVDEncBrcDmem->UPD_StaticRegionPct_U16 = 0; |
| 1608 |
hucVDEncBrcDmem->UPD_ROISource_U8 = 0; |
| 1609 |
if (avcPicParams->NumROI) |
| 1610 |
{ |
| 1611 |
CODECHAL_ENCODE_CHK_COND_RETURN(m_avcPicParam->NumROIDistinctDeltaQp > sizeof(hucVDEncBrcDmem->UPD_ROIQpDelta_I8) - 1, "Number of different ROI delta QP is greater that dmem roi array size"); |
| 1612 |
|
| 1613 |
hucVDEncBrcDmem->UPD_RoiQpViaForceQp_U8 = avcPicParams->bNativeROI ? 0 : 1; |
| 1614 |
for (uint8_t i = 0; i < m_avcPicParam->NumROIDistinctDeltaQp; i++) |
| 1615 |
{ |
| 1616 |
hucVDEncBrcDmem->UPD_ROIQpDelta_I8[i + 1] = m_avcPicParam->ROIDistinctDeltaQp[i]; |
| 1617 |
} |
| 1618 |
} |
| 1619 |
else if (avcPicParams->NumDirtyROI) |
| 1620 |
{ |
| 1621 |
hucVDEncBrcDmem->UPD_StaticRegionPct_U16 = (uint16_t)m_vdencStaticRegionPct; |
| 1622 |
if (m_mbBrcEnabled) |
| 1623 |
{ |
| 1624 |
hucVDEncBrcDmem->UPD_ROISource_U8 = 2; |
| 1625 |
} |
| 1626 |
} |
| 1627 |
|
| 1628 |
hucVDEncBrcDmem->UPD_SLBB_Size_U16 = (uint16_t)m_hwInterface->m_vdencBrcImgStateBufferSize; |
| 1629 |
|
| 1630 |
// reset skip frame statistics |
| 1631 |
m_numSkipFrames = 0; |
| 1632 |
m_sizeSkipFrames = 0; |
| 1633 |
|
| 1634 |
return eStatus; |
| 1635 |
} |
| 1636 |
|
| 1637 |
#endif // __CODECHAL_VDENC_AVC_H__ |