| 1 |
/* |
| 2 |
* Copyright (c) 2020-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 encode_vp9_pak.h |
| 24 |
//! \brief Defines the common interface for vp9 vdenc\pak features |
| 25 |
//! |
| 26 |
#ifndef __ENCODE_VP9_PAK_H__ |
| 27 |
#define __ENCODE_VP9_PAK_H__ |
| 28 |
|
| 29 |
#include "media_cmd_packet.h" |
| 30 |
#include "encode_pipeline.h" |
| 31 |
#include "encode_vp9_basic_feature.h" |
| 32 |
#include "encode_vp9_pipeline.h" |
| 33 |
|
| 34 |
#include "media_pipeline.h" |
| 35 |
#include "encode_utils.h" |
| 36 |
|
| 37 |
namespace encode |
| 38 |
{ |
| 39 |
#define CODECHAL_ENCODE_VP9_MAX_NUM_HCP_PIPE 4 |
| 40 |
#define CODECHAL_VP9_ENCODE_RECYCLED_BUFFER_NUM (CODECHAL_ENCODE_RECYCLED_BUFFER_NUM * CODECHAL_ENCODE_VP9_MAX_NUM_HCP_PIPE) // for salability, need 1 buffer per pipe, |
| 41 |
//! |
| 42 |
//! \struct CU_DATA |
| 43 |
//! \brief CU data |
| 44 |
//! |
| 45 |
struct CU_DATA |
| 46 |
{ |
| 47 |
// DW0 |
| 48 |
uint32_t cu_size : 2; |
| 49 |
uint32_t Res_DW0_2_3 : 2; |
| 50 |
uint32_t cu_part_mode : 2; // 0=2Nx2N,1=2NxN,2=Nx2N,3=NxN(8x8 only) |
| 51 |
uint32_t Res_DW0_6_7 : 2; |
| 52 |
uint32_t intra_chroma_mode0 : 4; // 0=DC,1=V,2=H,3=TM,4=D45,5=D135,6=D117,7=D153,8=D207,9=D63 |
| 53 |
uint32_t Res_DW0_12_15 : 4; |
| 54 |
uint32_t intra_chroma_mode1 : 4; // 0=DC,1=V,2=H,3=TM,4=D45,5=D135,6=D117,7=D153,8=D207,9=D63 |
| 55 |
uint32_t cu_pred_mode0 : 1; // 1=Intra,0=Inter |
| 56 |
uint32_t cu_pred_mode1 : 1; |
| 57 |
uint32_t Res_DW0_23_22 : 2; |
| 58 |
uint32_t interpred_comp0 : 1; // 0=single,1=compound |
| 59 |
uint32_t interpred_comp1 : 1; |
| 60 |
uint32_t Res_DW0_31_26 : 6; |
| 61 |
|
| 62 |
//DW1 |
| 63 |
uint32_t intra_mode0 : 4; // 0=DC,1=V,2=H,3=TM,4=D45,5=D135,6=D117,7=D153,8=D207,9=D63 |
| 64 |
uint32_t Res_DW1_4_7 : 4; |
| 65 |
uint32_t intra_mode1 : 4; // 0=DC,1=V,2=H,3=TM,4=D45,5=D135,6=D117,7=D153,8=D207,9=D63 |
| 66 |
uint32_t Res_DW1_12_15 : 4; |
| 67 |
uint32_t intra_mode2 : 4; // 0=DC,1=V,2=H,3=TM,4=D45,5=D135,6=D117,7=D153,8=D207,9=D63 |
| 68 |
uint32_t Res_DW1_20_23 : 4; |
| 69 |
uint32_t intra_mode3 : 4; // 0=DC,1=V,2=H,3=TM,4=D45,5=D135,6=D117,7=D153,8=D207,9=D63 |
| 70 |
uint32_t Res_DW1_28_31 : 4; |
| 71 |
|
| 72 |
//DW2 |
| 73 |
int16_t mvx_l0_part0 : 16; |
| 74 |
int16_t mvy_l0_part0 : 16; |
| 75 |
|
| 76 |
//DW3 |
| 77 |
int16_t mvx_l0_part1 : 16; |
| 78 |
int16_t mvy_l0_part1 : 16; |
| 79 |
|
| 80 |
//DW4 |
| 81 |
int16_t mvx_l0_part2 : 16; |
| 82 |
int16_t mvy_l0_part2 : 16; |
| 83 |
|
| 84 |
//DW5 |
| 85 |
int16_t mvx_l0_part3 : 16; |
| 86 |
int16_t mvy_l0_part3 : 16; |
| 87 |
|
| 88 |
//DW6 |
| 89 |
int16_t mvx_l1_part0 : 16; |
| 90 |
int16_t mvy_l1_part0 : 16; |
| 91 |
|
| 92 |
//DW7 |
| 93 |
int16_t mvx_l1_part1 : 16; |
| 94 |
int16_t mvy_l1_part1 : 16; |
| 95 |
|
| 96 |
//DW8 |
| 97 |
int16_t mvx_l1_part2 : 16; |
| 98 |
int16_t mvy_l1_part2 : 16; |
| 99 |
|
| 100 |
//DW9 |
| 101 |
int16_t mvx_l1_part3 : 16; |
| 102 |
int16_t mvy_l1_part3 : 16; |
| 103 |
|
| 104 |
//DW10 |
| 105 |
uint32_t refframe_part0_l0 : 2; // 0=intra,1=last,2=golden,3=altref |
| 106 |
uint32_t Res_DW10_2_3 : 2; |
| 107 |
uint32_t refframe_part1_l0 : 2; // 0=intra,1=last,2=golden,3=altref |
| 108 |
uint32_t Res_DW10_6_7 : 2; |
| 109 |
uint32_t refframe_part0_l1 : 2; // 0=intra,1=last,2=golden,3=altref |
| 110 |
uint32_t Res_DW10_10_11 : 2; |
| 111 |
uint32_t refframe_part1_l1 : 2; // 0=intra,1=last,2=golden,3=altref |
| 112 |
uint32_t Res_DW10_14_15 : 2; |
| 113 |
uint32_t round_part0 : 3; |
| 114 |
uint32_t Res_DW10_19 : 1; |
| 115 |
uint32_t round_part1 : 3; |
| 116 |
uint32_t Res_DW10_23_31 : 9; |
| 117 |
|
| 118 |
//DW11 |
| 119 |
uint32_t tu_size0 : 2; |
| 120 |
uint32_t tu_size1 : 2; |
| 121 |
uint32_t Res_DW11_4_13 : 10; |
| 122 |
uint32_t segidx_pred0 : 1; |
| 123 |
uint32_t segidx_pred1 : 1; |
| 124 |
uint32_t segidx_part0 : 3; |
| 125 |
uint32_t segidx_part1 : 3; |
| 126 |
uint32_t mc_filtertype_part0 : 2; |
| 127 |
uint32_t mc_filtertype_part1 : 2; |
| 128 |
uint32_t Res_DW11_26_31 : 6; |
| 129 |
|
| 130 |
uint32_t Res_DW12 : 32; |
| 131 |
|
| 132 |
uint32_t Res_DW13 : 32; |
| 133 |
|
| 134 |
uint32_t Res_DW14 : 32; |
| 135 |
|
| 136 |
uint32_t Res_DW15 : 32; |
| 137 |
|
| 138 |
}; |
| 139 |
C_ASSERT(MOS_BYTES_TO_DWORDS(sizeof(CU_DATA)) == 16); |
| 140 |
|
| 141 |
class Vp9EncodePak : public MediaFeature, |
| 142 |
public mhw::vdbox::huc::Itf::ParSetting, |
| 143 |
public mhw::vdbox::hcp::Itf::ParSetting, |
| 144 |
public mhw::vdbox::vdenc::Itf::ParSetting |
| 145 |
{ |
| 146 |
public: |
| 147 |
//! |
| 148 |
//! \brief Vp9EncodePak feature constructor |
| 149 |
//! |
| 150 |
//! \param [in] featureManager |
| 151 |
//! Pointer to MediaFeatureManager |
| 152 |
//! \param [in] allocator |
| 153 |
//! Pointer to EncodeAllocator |
| 154 |
//! \param [in] hwInterface |
| 155 |
//! Pointer to CodechalHwInterface |
| 156 |
//! \param [in] constSettings |
| 157 |
//! Pointer to const settings |
| 158 |
//! |
| 159 |
Vp9EncodePak( |
| 160 |
MediaFeatureManager *featureManager, |
| 161 |
EncodeAllocator *allocator, |
| 162 |
CodechalHwInterfaceNext *hwInterface, |
| 163 |
void *constSettings); |
| 164 |
|
| 165 |
//! |
| 166 |
//! \brief Vp9EncodePak feature destructor |
| 167 |
//! |
| 168 |
virtual ~Vp9EncodePak() {} |
| 169 |
|
| 170 |
//! |
| 171 |
//! \brief Init vdenc pak features related parameter |
| 172 |
//! \param [in] settings |
| 173 |
//! Pointer to settings |
| 174 |
//! \return MOS_STATUS |
| 175 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 176 |
//! |
| 177 |
MOS_STATUS Init(void *settings) override; |
| 178 |
|
| 179 |
//! |
| 180 |
//! \brief Update vdenc pak features related parameter |
| 181 |
//! \param [in] params |
| 182 |
//! Pointer to parameters |
| 183 |
//! \return MOS_STATUS |
| 184 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 185 |
//! |
| 186 |
MOS_STATUS Update(void *params) override; |
| 187 |
|
| 188 |
//! |
| 189 |
//! \brief Set regions for brc update |
| 190 |
//! \param [in] params |
| 191 |
//! Pointer to parameters |
| 192 |
//! \param [in] currPass |
| 193 |
//! current pass |
| 194 |
//! \return MOS_STATUS |
| 195 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 196 |
//! |
| 197 |
MOS_STATUS SetRegionsForBrcUpdate( |
| 198 |
mhw::vdbox::huc::HUC_VIRTUAL_ADDR_STATE_PAR ¶ms, |
| 199 |
uint32_t currPass) const; |
| 200 |
|
| 201 |
//! |
| 202 |
//! \brief Set regions for huc prob |
| 203 |
//! \param [in] params |
| 204 |
//! Pointer to parameters |
| 205 |
//! \param [in] currPass |
| 206 |
//! current pass |
| 207 |
//! \return MOS_STATUS |
| 208 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 209 |
//! |
| 210 |
MOS_STATUS SetRegionsForHucProb( |
| 211 |
mhw::vdbox::huc::HUC_VIRTUAL_ADDR_STATE_PAR ¶ms, |
| 212 |
uint32_t currPass) const; |
| 213 |
|
| 214 |
//! |
| 215 |
//! \brief Construct pic state batch buffer |
| 216 |
//! \param [in] pipeline |
| 217 |
//! Pointer to the pipeline |
| 218 |
//! \return MOS_STATUS |
| 219 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 220 |
//! |
| 221 |
MOS_STATUS ConstructPicStateBatchBuffer( |
| 222 |
EncodePipeline *pipeline); |
| 223 |
|
| 224 |
//! |
| 225 |
//! \brief Construct pak insert object batch buffer |
| 226 |
//! \return MOS_STATUS |
| 227 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 228 |
//! |
| 229 |
MOS_STATUS ConstructPakInsertObjBatchBuffer(); |
| 230 |
|
| 231 |
//! |
| 232 |
//! \brief Set huc pak insert object batch buffer |
| 233 |
//! \param [in, out] secondLevelBatchBuffer |
| 234 |
//! Pointer to huc pak insert object batch buffer |
| 235 |
//! \return MOS_STATUS |
| 236 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 237 |
//! |
| 238 |
MOS_STATUS SetHucPakInsertObjBatchBuffer( |
| 239 |
MHW_BATCH_BUFFER &secondLevelBatchBuffer); |
| 240 |
|
| 241 |
//! |
| 242 |
//! \brief Set vdenc second level batch buffer |
| 243 |
//! \param [in] currPass |
| 244 |
//! Current pass |
| 245 |
//! \param [in, out] secondLevelBatchBuffer |
| 246 |
//! Second level batch buffer |
| 247 |
//! \return MOS_STATUS |
| 248 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 249 |
//! |
| 250 |
virtual MOS_STATUS SetVdencSecondLevelBatchBuffer( |
| 251 |
uint32_t currPass, |
| 252 |
MHW_BATCH_BUFFER &secondLevelBatchBuffer); |
| 253 |
|
| 254 |
//! |
| 255 |
//! \brief Get vdenc picture state second level batch buffer size |
| 256 |
//! \param [out] size |
| 257 |
//! Vdenc picture state second level batch buffer size |
| 258 |
//! \return MOS_STATUS |
| 259 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 260 |
//! |
| 261 |
virtual MOS_STATUS GetVdencPictureState2ndLevelBatchBufferSize( |
| 262 |
uint32_t &size); |
| 263 |
|
| 264 |
//! |
| 265 |
//! \brief Update parameters |
| 266 |
//! \return MOS_STATUS |
| 267 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 268 |
//! |
| 269 |
virtual MOS_STATUS UpdateParameters(); |
| 270 |
|
| 271 |
//! |
| 272 |
//! \brief Pak construct picture state batch buffer |
| 273 |
//! |
| 274 |
//! \param [in] picStateBuffer |
| 275 |
//! Pointer to MOS surface |
| 276 |
//! |
| 277 |
//! \return MOS_STATUS |
| 278 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 279 |
//! |
| 280 |
MOS_STATUS PakConstructPicStateBatchBuffer( |
| 281 |
PMOS_RESOURCE picStateBuffer); |
| 282 |
|
| 283 |
//! |
| 284 |
//! \brief Get compressed header buffer |
| 285 |
//! \return Pointer to the buffer |
| 286 |
//! |
| 287 |
PMOS_RESOURCE GetCompressedHeaderBuffer(); |
| 288 |
|
| 289 |
//! |
| 290 |
//! \brief MHW parameters declaration |
| 291 |
//! |
| 292 |
MHW_SETPAR_DECL_HDR(HCP_PAK_INSERT_OBJECT); |
| 293 |
MHW_SETPAR_DECL_HDR(HCP_IND_OBJ_BASE_ADDR_STATE); |
| 294 |
MHW_SETPAR_DECL_HDR(HCP_PIPE_BUF_ADDR_STATE); |
| 295 |
|
| 296 |
protected: |
| 297 |
|
| 298 |
//! \brief Allocate feature related resources |
| 299 |
//! \return MOS_STATUS |
| 300 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 301 |
//! |
| 302 |
MOS_STATUS AllocateResources() override; |
| 303 |
|
| 304 |
//! |
| 305 |
//! \brief Prepare PAK object and CU record for dynamic scaling |
| 306 |
//! \return MOS_STATUS |
| 307 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 308 |
//! |
| 309 |
MOS_STATUS PreparePakObjAndCuRecord(); |
| 310 |
|
| 311 |
//! |
| 312 |
//! \brief Add the VDenc CMD1 command. |
| 313 |
//! \param [in] cmdBuffer |
| 314 |
//! The command buffer which is allocated by caller |
| 315 |
//! \return MOS_STATUS |
| 316 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 317 |
//! |
| 318 |
virtual MOS_STATUS AddVdencCmd1Command( |
| 319 |
MOS_COMMAND_BUFFER &cmdBuffer); |
| 320 |
|
| 321 |
//! |
| 322 |
//! \brief Add the VDenc CMD2 command. |
| 323 |
//! \param [in] cmdBuffer |
| 324 |
//! The command buffer which is allocated by caller |
| 325 |
//! \return MOS_STATUS |
| 326 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 327 |
//! |
| 328 |
MOS_STATUS AddVdencCmd2Command( |
| 329 |
MOS_COMMAND_BUFFER &cmdBuffer); |
| 330 |
|
| 331 |
//! |
| 332 |
//! \brief Calculate QP Lambda values |
| 333 |
//! \param sadQpLambda |
| 334 |
//! SAD QP Lambda value |
| 335 |
//! \param rdQpLambda |
| 336 |
//! RD QP Lambda value |
| 337 |
//! \return MOS_STATUS |
| 338 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 339 |
//! |
| 340 |
void CalculateQpLambdaValues(double &sadQpLambda, double &rdQpLambda); |
| 341 |
|
| 342 |
CodechalHwInterfaceNext * m_hwInterface = nullptr; |
| 343 |
EncodeAllocator * m_allocator = nullptr; |
| 344 |
Vp9BasicFeature * m_basicFeature = nullptr; |
| 345 |
|
| 346 |
std::shared_ptr<mhw::vdbox::hcp::Itf> m_hcpInterfaceNew = nullptr; |
| 347 |
std::shared_ptr<mhw::vdbox::vdenc::Itf> m_vdencInterfaceNew = nullptr; |
| 348 |
std::shared_ptr<mhw::mi::Itf> m_miItf = nullptr; |
| 349 |
|
| 350 |
// Picture state resources |
| 351 |
bool m_picState2ndLevelBBConstructed[3]; //!< Indicated picture state 2nd level batch buffer has been contructed |
| 352 |
uint32_t m_vdencPicStateSecondLevelBatchBufferSize = 0; //!< VDENC picture state second level batch buffer size |
| 353 |
uint16_t m_vdencPictureState2ndLevelBBIndex = 0; |
| 354 |
uint16_t m_lastVdencPictureState2ndLevelBBIndex = 0; |
| 355 |
|
| 356 |
MOS_RESOURCE m_resVdencPictureState2ndLevelBatchBufferRead[3][CODECHAL_VP9_ENCODE_RECYCLED_BUFFER_NUM] = {0}; |
| 357 |
MOS_RESOURCE m_resVdencPictureState2ndLevelBatchBufferWrite[CODECHAL_VP9_ENCODE_RECYCLED_BUFFER_NUM] = {0}; |
| 358 |
|
| 359 |
// Vdenc/Pak resources |
| 360 |
MOS_RESOURCE m_resHucPakInsertUncompressedHeaderReadBuffer[CODECHAL_ENCODE_RECYCLED_BUFFER_NUM] = {0}; //!< Huc VP9 pak insert uncompressed header read buffer |
| 361 |
MOS_RESOURCE m_resHucPakInsertUncompressedHeaderWriteBuffer = {0}; //!< Huc VP9 pak insert uncompressed header write buffer |
| 362 |
|
| 363 |
MOS_RESOURCE m_resCompressedHeaderBuffer = {0}; //!< Compressed heander buffer |
| 364 |
MOS_RESOURCE m_resVdencDataExtensionBuffer = {0}; //!< Data extension buffer |
| 365 |
|
| 366 |
// PAK resources |
| 367 |
PMOS_RESOURCE m_resMetadataLineBuffer = nullptr; //!< Metadata line data buffer |
| 368 |
PMOS_RESOURCE m_resMetadataTileLineBuffer = nullptr; //!< Metadata tile line data buffer |
| 369 |
PMOS_RESOURCE m_resMetadataTileColumnBuffer = nullptr; //!< Metadata tile column data buffer |
| 370 |
|
| 371 |
// DYS |
| 372 |
MOS_RESOURCE m_resVdencDysPictureState2ndLevelBatchBuffer = {0}; |
| 373 |
|
| 374 |
MEDIA_CLASS_DEFINE_END(encode__Vp9EncodePak) |
| 375 |
}; |
| 376 |
|
| 377 |
} // namespace encode |
| 378 |
|
| 379 |
#endif // __ENCODE_VP9_PAK_H__ |