| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#ifndef __ENCODE_HEVC_BRC_H__ |
| 27 |
#define __ENCODE_HEVC_BRC_H__ |
| 28 |
|
| 29 |
#include "media_feature.h" |
| 30 |
#include "encode_allocator.h" |
| 31 |
#include "codec_hw_next.h" |
| 32 |
#include "encode_recycle_resource.h" |
| 33 |
#include "encode_basic_feature.h" |
| 34 |
#include "mhw_vdbox_vdenc_itf.h" |
| 35 |
#include "mhw_vdbox_hcp_itf.h" |
| 36 |
#include "mhw_vdbox_huc_itf.h" |
| 37 |
|
| 38 |
namespace encode |
| 39 |
{ |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
struct CodechalVdencHevcPakInfo |
| 45 |
{ |
| 46 |
uint32_t FrameByteCount; |
| 47 |
uint8_t PAKPassNum; |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
struct HevcVdencBrcBuffers |
| 55 |
{ |
| 56 |
PMOS_RESOURCE resBrcPakStatisticBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM]; |
| 57 |
uint32_t currBrcPakStasIdxForRead; |
| 58 |
uint32_t currBrcPakStasIdxForWrite; |
| 59 |
}; |
| 60 |
|
| 61 |
struct VdencHevcHucBrcInitDmem |
| 62 |
{ |
| 63 |
uint32_t BRCFunc_U32; |
| 64 |
uint32_t UserMaxFrame; |
| 65 |
uint32_t InitBufFull_U32; |
| 66 |
uint32_t BufSize_U32; |
| 67 |
uint32_t TargetBitrate_U32; |
| 68 |
uint32_t MaxRate_U32; |
| 69 |
uint32_t MinRate_U32; |
| 70 |
uint32_t FrameRateM_U32; |
| 71 |
uint32_t FrameRateD_U32; |
| 72 |
uint32_t LumaLog2WeightDenom_U32; |
| 73 |
uint32_t ChromaLog2WeightDenom_U32; |
| 74 |
uint8_t BRCFlag : 7; |
| 75 |
uint8_t SSCFlag : 1; |
| 76 |
uint8_t Reserved; |
| 77 |
uint16_t GopP_U16; |
| 78 |
uint16_t GopB_U16; |
| 79 |
uint16_t FrameWidth_U16; |
| 80 |
uint16_t FrameHeight_U16; |
| 81 |
uint16_t GopB1_U16; |
| 82 |
uint16_t GopB2_U16; |
| 83 |
uint8_t MinQP_U8; |
| 84 |
uint8_t MaxQP_U8; |
| 85 |
uint8_t MaxBRCLevel_U8; |
| 86 |
uint8_t LumaBitDepth_U8; |
| 87 |
uint8_t ChromaBitDepth_U8; |
| 88 |
uint8_t CuQpCtrl_U8; |
| 89 |
|
| 90 |
uint8_t RSVD0[4]; |
| 91 |
int8_t DevThreshPB0_S8[8]; |
| 92 |
int8_t DevThreshVBR0_S8[8]; |
| 93 |
int8_t DevThreshI0_S8[8]; |
| 94 |
int8_t InstRateThreshP0_S8[4]; |
| 95 |
int8_t InstRateThreshB0_S8[4]; |
| 96 |
int8_t InstRateThreshI0_S8[4]; |
| 97 |
uint8_t LowDelayMode_U8; |
| 98 |
uint8_t InitQPIP_U8; |
| 99 |
uint8_t InitQPB_U8; |
| 100 |
uint8_t QPDeltaThrForAdapt2Pass_U8; |
| 101 |
uint8_t TopFrmSzThrForAdapt2Pass_U8; |
| 102 |
uint8_t BotFrmSzThrForAdapt2Pass_U8; |
| 103 |
uint8_t QPSelectForFirstPass_U8; |
| 104 |
uint8_t MBHeaderCompensation_U8; |
| 105 |
uint8_t OverShootCarryFlag_U8; |
| 106 |
uint8_t OverShootSkipFramePct_U8; |
| 107 |
uint8_t EstRateThreshP0_U8[7]; |
| 108 |
uint8_t EstRateThreshB0_U8[7]; |
| 109 |
|
| 110 |
uint8_t EstRateThreshI0_U8[7]; |
| 111 |
uint8_t QPP_U8; |
| 112 |
uint8_t StreamInSurfaceEnable_U8; |
| 113 |
uint8_t StreamInROIEnable_U8; |
| 114 |
uint8_t TimingBudget_Enable_U8; |
| 115 |
uint8_t TopQPDeltaThrForAdapt2Pass_U8; |
| 116 |
uint8_t BotQPDeltaThrForAdapt2Pass_U8; |
| 117 |
uint8_t RESERVED; |
| 118 |
uint8_t NetworkTraceEnable_U8; |
| 119 |
uint8_t LowDelaySceneChangeXFrameSizeEnable_U8; |
| 120 |
uint32_t ACQP_U32; |
| 121 |
uint32_t SlidingWindow_Size_U32; |
| 122 |
|
| 123 |
uint8_t SLIDINGWINDOW_MaxRateRatio; |
| 124 |
uint8_t LookaheadDepth_U8; |
| 125 |
int8_t CbQPOffset; |
| 126 |
int8_t CrQPOffset; |
| 127 |
|
| 128 |
uint32_t ProfileLevelMaxFramePB_U32; |
| 129 |
|
| 130 |
|
| 131 |
uint16_t SlideWindowRC; |
| 132 |
uint16_t MaxLogCUSize; |
| 133 |
|
| 134 |
uint16_t FrameWidthInLCU; |
| 135 |
uint16_t FrameHeightInLCU; |
| 136 |
|
| 137 |
uint8_t BRCPyramidEnable_U8; |
| 138 |
uint8_t LongTermRefEnable_U8; |
| 139 |
uint16_t LongTermRefInterval_U16; |
| 140 |
uint8_t LongTermRefMsdk_U8; |
| 141 |
uint8_t IsLowDelay_U8; |
| 142 |
uint16_t RSVD3; |
| 143 |
uint32_t RSVD1[4]; |
| 144 |
}; |
| 145 |
C_ASSERT(192 == sizeof(VdencHevcHucBrcInitDmem)); |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
struct EncodeReadBrcPakStatsParams |
| 152 |
{ |
| 153 |
CodechalHwInterfaceNext *pHwInterface; |
| 154 |
PMOS_RESOURCE presBrcPakStatisticBuffer; |
| 155 |
PMOS_RESOURCE presStatusBuffer; |
| 156 |
uint32_t dwStatusBufNumPassesOffset; |
| 157 |
uint8_t ucPass; |
| 158 |
MOS_GPU_CONTEXT VideoContext; |
| 159 |
}; |
| 160 |
|
| 161 |
class HEVCEncodeBRC : public MediaFeature, public mhw::vdbox::vdenc::Itf::ParSetting, public mhw::vdbox::hcp::Itf::ParSetting, public mhw::vdbox::huc::Itf::ParSetting |
| 162 |
{ |
| 163 |
public: |
| 164 |
HEVCEncodeBRC(MediaFeatureManager *featureManager, EncodeAllocator *allocator, CodechalHwInterfaceNext *hwInterface, void *constSettings); |
| 165 |
|
| 166 |
virtual ~HEVCEncodeBRC(); |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
MOS_STATUS Init(void *settings) override; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
MOS_STATUS Update(void *params) override; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
void SetACQPStatus(bool isEnabled) { m_hevcVDEncAcqpEnabled = isEnabled; } |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
bool IsACQPEnabled() { return m_hevcVDEncAcqpEnabled; } |
| 201 |
|
| 202 |
uint8_t RateControlMethod(){ return m_rcMode; } |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
bool IsBRCEnabled() { return m_brcEnabled; } |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
void DisableBrcInitReset() { m_brcInit = m_brcReset = false; }; |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
bool IsBRCInit() { return m_brcInit; } |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
virtual bool IsBRCInitRequired() { return m_vdencHucUsed & (m_brcInit || m_brcReset); } |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
virtual bool IsBRCUpdateRequired() { return m_vdencHucUsed; } |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
bool IsVdencHucUsed() const { return m_vdencHucUsed; } |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
bool IsRateControlBrc(uint8_t rc) |
| 258 |
{ |
| 259 |
return (rc == RATECONTROL_CBR) || |
| 260 |
(rc == RATECONTROL_VBR) || |
| 261 |
(rc == RATECONTROL_AVBR) || |
| 262 |
(rc == RATECONTROL_VCM) || |
| 263 |
(rc == RATECONTROL_QVBR) || |
| 264 |
(rc == RATECONTROL_ICQ); |
| 265 |
} |
| 266 |
|
| 267 |
PMHW_BATCH_BUFFER GetVdenc2ndLevelBatchBuffer(uint32_t currRecycledBufIdx) { |
| 268 |
return &m_vdenc2ndLevelBatchBuffer[currRecycledBufIdx]; |
| 269 |
}; |
| 270 |
|
| 271 |
MOS_STATUS GetBrcDataBuffer(MOS_RESOURCE *&buffer); |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
MOS_STATUS SetDmemForUpdate(void *params); |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
MOS_STATUS SetConstForUpdate(void *params); |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
MOS_STATUS SetConstLambdaForUpdate(void *params, bool lambdaType = false); |
| 301 |
|
| 302 |
MOS_STATUS SetHevcDepthBasedLambda( |
| 303 |
PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams, |
| 304 |
PCODEC_HEVC_ENCODE_PICTURE_PARAMS hevcPicParams, |
| 305 |
uint8_t qp, |
| 306 |
uint16_t & SADQPLambda, |
| 307 |
uint16_t & RDQPLambda); |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
MOS_STATUS SetDmemForInit(void *params); |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
virtual MOS_STATUS SetReadBrcPakStatsParams( |
| 334 |
uint8_t ucPass, |
| 335 |
uint32_t offset, |
| 336 |
PMOS_RESOURCE osResource, |
| 337 |
EncodeReadBrcPakStatsParams &readBrcPakStatsParams); |
| 338 |
|
| 339 |
HevcVdencBrcBuffers* GetHevcVdencBrcBuffers() |
| 340 |
{ |
| 341 |
return &m_vdencBrcBuffers; |
| 342 |
}; |
| 343 |
|
| 344 |
PMOS_RESOURCE GetHevcVdenc2ndLevelBatchBuffer(uint32_t currRecycledBufIdx) |
| 345 |
{ |
| 346 |
return &m_vdenc2ndLevelBatchBuffer[currRecycledBufIdx].OsResource; |
| 347 |
}; |
| 348 |
|
| 349 |
MOS_STATUS SetVdencBatchBufferState( |
| 350 |
const uint32_t currRecycledBufIdx, |
| 351 |
const uint32_t slcIdx, |
| 352 |
PMHW_BATCH_BUFFER &vdencBatchBuffer, |
| 353 |
bool & vdencHucUsed); |
| 354 |
|
| 355 |
MHW_SETPAR_DECL_HDR(VDENC_PIPE_MODE_SELECT); |
| 356 |
|
| 357 |
MHW_SETPAR_DECL_HDR(VDENC_CMD2); |
| 358 |
|
| 359 |
MHW_SETPAR_DECL_HDR(HCP_PIPE_MODE_SELECT); |
| 360 |
|
| 361 |
MHW_SETPAR_DECL_HDR(HUC_VIRTUAL_ADDR_STATE); |
| 362 |
|
| 363 |
MOS_STATUS SetCurrRecycledBufIdx(const uint8_t index); |
| 364 |
|
| 365 |
protected: |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
virtual MOS_STATUS AllocateResources() override; |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
virtual MOS_STATUS UpdateBrcResources(void *params); |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
virtual MOS_STATUS FreeBrcResources(); |
| 385 |
|
| 386 |
MOS_STATUS SetBrcSettings(void *params); |
| 387 |
|
| 388 |
MOS_STATUS SetAcqpSettings(void *params); |
| 389 |
|
| 390 |
void ComputeVDEncInitQP(int32_t& initQPIP, int32_t& initQPB); |
| 391 |
|
| 392 |
void SetLcuBrc(); |
| 393 |
|
| 394 |
MOS_STATUS SetSequenceStructs(); |
| 395 |
|
| 396 |
|
| 397 |
static constexpr uint32_t m_brcHistoryBufSize = 6092; |
| 398 |
static constexpr uint32_t m_vdencBRCStatsBufferSize = 1216; |
| 399 |
static constexpr uint32_t m_deltaQpRoiBufferSize = 65536; |
| 400 |
static constexpr uint32_t m_brcDebugBufSize = 0x1000; |
| 401 |
static constexpr uint32_t m_roiStreamInBufferSize = 65536 * CODECHAL_CACHELINE_SIZE; |
| 402 |
|
| 403 |
const uint32_t m_brc_kbps = 1000; |
| 404 |
|
| 405 |
CodechalHwInterfaceNext *m_hwInterface = nullptr; |
| 406 |
EncodeAllocator *m_allocator = nullptr; |
| 407 |
HevcBasicFeature *m_basicFeature = nullptr; |
| 408 |
|
| 409 |
uint8_t m_rcMode = 0; |
| 410 |
|
| 411 |
bool m_brcInit = true; |
| 412 |
bool m_brcReset = false; |
| 413 |
bool m_brcEnabled = false; |
| 414 |
bool m_lcuBrcEnabled = false; |
| 415 |
bool m_hevcVDEncAcqpEnabled = false; |
| 416 |
bool m_vdencBrcEnabled = false; |
| 417 |
bool m_vdencHucUsed = false; |
| 418 |
bool m_fastPakEnable = true; |
| 419 |
|
| 420 |
|
| 421 |
MHW_BATCH_BUFFER m_vdenc2ndLevelBatchBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {}; |
| 422 |
MOS_RESOURCE m_vdencOutputROIStreaminBuffer = {}; |
| 423 |
MOS_RESOURCE m_vdencBrcDbgBuffer = {}; |
| 424 |
MOS_RESOURCE m_resBrcDataBuffer = {}; |
| 425 |
HevcVdencBrcBuffers m_vdencBrcBuffers = {}; |
| 426 |
uint16_t *m_rdLambdaArray = nullptr; |
| 427 |
uint16_t *m_sadLambdaArray = nullptr; |
| 428 |
|
| 429 |
MHW_VDBOX_NODE_IND m_vdboxIndex = MHW_VDBOX_NODE_1; |
| 430 |
uint32_t m_currRecycledBufIdx = 0; |
| 431 |
|
| 432 |
MEDIA_CLASS_DEFINE_END(encode__HEVCEncodeBRC) |
| 433 |
}; |
| 434 |
|
| 435 |
} |
| 436 |
|
| 437 |
#endif |