1 /* 2 * Copyright (c) 2017-2019, 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_decode_hevc_g12.h 24 //! \brief Defines the decode interface extension for HEVC. 25 //! \details Defines all types, macros, and functions required by CodecHal for GEN11 HEVC decoding. Definitions are not externally facing. 26 //! This file should not be included except in codechal_decode_hevc_*.c/h. 27 //! 28 29 #ifndef __CODECHAL_DECODER_HEVC__G12_H__ 30 #define __CODECHAL_DECODER_HEVC__G12_H__ 31 32 #include "codechal_decode_hevc.h" 33 #include "codechal_decode_scalability_g12.h" 34 #include "codechal_decode_singlepipe_virtualengine.h" 35 #include "mhw_vdbox_g12_X.h" 36 #include "codec_def_decode_hevc.h" 37 38 // HEVC SCC Intra Block Copy Mode 39 #define CodecHalDecodeIsSCCIBCMode(hevcSccPicParams) \ 40 (hevcSccPicParams ? hevcSccPicParams->PicSCCExtensionFlags.fields.pps_curr_pic_ref_enabled_flag : false) 41 42 // HEVC SCC Palette Mode 43 #define CodecHalDecodeIsSCCPLTMode(hevcSccPicParams) \ 44 (hevcSccPicParams ? hevcSccPicParams->PicSCCExtensionFlags.fields.palette_mode_enabled_flag : false) 45 46 // HEVC SCC Adaptive Colour Transform Mode 47 #define CodecHalDecodeIsSCCACTMode(hevcSccPicParams) \ 48 (hevcSccPicParams ? hevcSccPicParams->PicSCCExtensionFlags.fields.residual_adaptive_colour_transform_enabled_flag : false) 49 50 // HEVC Wave front Parallel Processing 51 #define CodecHalDecodeIsWPPMode(hevcPicParams) \ 52 (hevcPicParams ? hevcPicParams->entropy_coding_sync_enabled_flag : false) 53 54 #define CodecHalDecodeNeedsTileDecoding(hevcPicParams, hevcSccPicParams) \ 55 (hevcPicParams ? (hevcPicParams->tiles_enabled_flag \ 56 && (CodecHalDecodeIsSCCIBCMode(hevcSccPicParams) \ 57 || CodecHalDecodeIsSCCPLTMode(hevcSccPicParams) \ 58 || CodecHalDecodeIsWPPMode(hevcPicParams))) : false) 59 60 struct HUC_HEVC_S2L_PIC_BSS_G12 : public HUC_HEVC_S2L_PIC_BSS 61 { 62 uint8_t IsRealTileEnable; 63 uint8_t NumScalablePipes; 64 uint8_t IsSCCIBCMode; 65 uint8_t IsSCCPLTMode; 66 uint8_t MVRControlIdc; 67 uint8_t UseSliceACTOffset; 68 int8_t pps_act_y_qp_offset; 69 int8_t pps_act_cb_qp_offset; 70 int8_t pps_act_cr_qp_offset; 71 uint8_t PredictorPaletteSize; 72 uint16_t PredictorPaletteEntries[3][128]; 73 uint32_t BatchBufferSize; 74 }; 75 typedef struct HUC_HEVC_S2L_PIC_BSS_G12 *PHUC_HEVC_S2L_PIC_BSS_G12; 76 77 struct HUC_HEVC_S2L_BSS_G12 78 { 79 // Platfrom information 80 uint32_t ProductFamily; 81 uint16_t RevId; 82 83 // Flag to indicate if create dummy HCP_REF_IDX_STATE or not 84 uint32_t DummyRefIdxState; 85 86 //Flag to indicate if insert dummy HCP_VD_CONTROL_STATE or not 87 uint32_t DummyVDControlState; 88 89 //Flag to indicate if insert MFX_WAIT and VD_PIPELINE_FLUSH for Scalability 90 uint32_t WaTileFlushScalability; 91 92 // Picture level DMEM data 93 HUC_HEVC_S2L_PIC_BSS_G12 PictureBss; 94 95 // Slice level DMEM data 96 HUC_HEVC_S2L_SLICE_BSS SliceBss[CODECHAL_HEVC_MAX_NUM_SLICES_LVL_6]; 97 }; 98 typedef struct HUC_HEVC_S2L_BSS_G12 *PHUC_HEVC_S2L_BSS_G12; 99 100 class HevcDecodeSliceLongG12; 101 102 class CodechalDecodeHevcG12 : public CodechalDecodeHevc 103 { 104 friend class HevcDecodeSliceLongG12; 105 106 public: 107 //! 108 //! \brief Allocate and initialize HEVC decoder standard 109 //! \param [in] settings 110 //! Pointer to CodechalSetting 111 //! \return MOS_STATUS 112 //! MOS_STATUS_SUCCESS if success, else fail reason 113 //! 114 MOS_STATUS AllocateStandard ( 115 CodechalSetting * settings) override; 116 117 //! 118 //! \brief Constructor 119 //! \param [in] hwInterface 120 //! Hardware interface 121 //! \param [in] debugInterface 122 //! Debug interface 123 //! \param [in] standardInfo 124 //! The information of decode standard for this instance 125 //! 126 CodechalDecodeHevcG12( 127 CodechalHwInterface *hwInterface, 128 CodechalDebugInterface* debugInterface, 129 PCODECHAL_STANDARD_INFO standardInfo); 130 131 //! 132 //! \brief Copy constructor 133 //! 134 CodechalDecodeHevcG12(const CodechalDecodeHevcG12&) = delete; 135 136 //! 137 //! \brief Copy assignment operator 138 //! 139 CodechalDecodeHevcG12& operator=(const CodechalDecodeHevcG12&) = delete; 140 141 //! 142 //! \brief Destructor 143 //! 144 ~CodechalDecodeHevcG12 (); 145 146 //! 147 //! \brief Intialize HEVC decode mode 148 //! \details For dynamic mode switch support 149 //! 150 //! \return MOS_STATUS 151 //! MOS_STATUS_SUCCESS if success, else fail reason 152 //! 153 virtual MOS_STATUS InitializeDecodeMode(); 154 155 //! 156 //! \brief Set states for each frame to prepare for GEN12 HEVC decode 157 //! \return MOS_STATUS 158 //! MOS_STATUS_SUCCESS if success, else fail reason 159 //! 160 MOS_STATUS SetFrameStates () override; 161 162 //! 163 //! \brief HEVC decoder state level function 164 //! \details State level function for GEN12 HEVC decoder 165 //! 166 //! \return MOS_STATUS 167 //! MOS_STATUS_SUCCESS if success, else fail reason 168 //! 169 MOS_STATUS DecodeStateLevel () override; 170 171 //! 172 //! \brief HEVC decoder primitive level function 173 //! \details Primitive level function for GEN specific HEVC decoder 174 //! 175 //! \return MOS_STATUS 176 //! MOS_STATUS_SUCCESS if success, else fail reason 177 //! 178 MOS_STATUS DecodePrimitiveLevel () override; 179 180 //! 181 //! \brief Allocate variable sized resources 182 //! \details Allocate variable sized resources in HEVC decode driver 183 //! \return MOS_STATUS 184 //! MOS_STATUS_SUCCESS if success, else fail reason 185 //! 186 MOS_STATUS AllocateResourcesVariableSizes (); 187 188 //! 189 //! \brief Get the Huc Dmem resource size 190 //! \details Return the Huc Dmem resource size in bytes. 191 //! 192 //! \param None 193 //! 194 //! \return uint32_t 195 //! the size of Dmem resource 196 //! 197 uint32_t GetDmemBufferSize() override; 198 199 //! 200 //! \brief Set S2L picture level Dmem parameters 201 //! \details Set S2L HuC Dmem picture level paramters 202 //! 203 //! \param [out] hucHevcS2LPicBss 204 //! Pointer to S2L Dmem picture Bss paramters 205 //! 206 //! \return MOS_STATUS 207 //! MOS_STATUS_SUCCESS if success, else fail reason 208 //! 209 MOS_STATUS SetHucDmemS2LPictureBss( 210 PHUC_HEVC_S2L_PIC_BSS hucHevcS2LPicBss) override; 211 212 //! 213 //! \brief Setup HuC DMEM buffer 214 //! \details Setup HuC DMEM buffer in HEVC decode driver 215 //! 216 //! \param [in] dmemBuffer 217 //! Pointer to HuC DMEM resource buffer 218 //! 219 //! \return MOS_STATUS 220 //! MOS_STATUS_SUCCESS if success, else fail reason 221 //! 222 MOS_STATUS SetHucDmemParams( 223 PMOS_RESOURCE dmemBuffer) override; 224 225 //! 226 //! \brief Determine Decode Phase 227 //! \details Determine decode phase in hevc decode 228 //! 229 //! \return MOS_STATUS 230 //! MOS_STATUS_SUCCESS if success, else fail reason 231 //! 232 MOS_STATUS DetermineDecodePhase (); 233 234 //! 235 //! \brief Send S2L picture level commands 236 //! \details Send S2L picture level commands in HEVC decode driver 237 //! 238 //! \return MOS_STATUS 239 //! MOS_STATUS_SUCCESS if success, else fail reason 240 //! 241 MOS_STATUS SendPictureS2L () override; 242 243 //! 244 //! \brief Initialize the picture level MHW parameters for long format 245 //! \details Initialize the picture level MHW parameters for long format in HEVC decode driver 246 //! 247 //! \return MOS_STATUS 248 //! MOS_STATUS_SUCCESS if success, else fail reason 249 //! 250 MOS_STATUS InitPicLongFormatMhwParams() override; 251 252 //! 253 //! \brief Add long format picture level commands to command buffer 254 //! \details Add long format picture level commands to command buffer in HEVC decode driver 255 //! 256 //! \param [out] cmdBufferInUse 257 //! Pointer to Command buffer 258 //! \param [in] picMhwParams 259 //! Pointer to the picture level MHW parameters 260 //! 261 //! \return MOS_STATUS 262 //! MOS_STATUS_SUCCESS if success, else fail reason 263 //! 264 MOS_STATUS AddPictureLongFormatCmds( 265 PMOS_COMMAND_BUFFER cmdBufferInUse, 266 PIC_LONG_FORMAT_MHW_PARAMS *picMhwParams) override; 267 268 //! 269 //! \brief Send long format picture level commands 270 //! \details Send long format picture level commands in HEVC decode driver 271 //! 272 //! \return MOS_STATUS 273 //! MOS_STATUS_SUCCESS if success, else fail reason 274 //! 275 MOS_STATUS SendPictureLongFormat () override; 276 277 278 //! 279 //! \brief Send short format HuCStart Command for slices 280 //! \details Send short format HuCStart Command for slices in HEVC decode driver 281 //! 282 //! \return MOS_STATUS 283 //! MOS_STATUS_SUCCESS if success, else fail reason 284 //! 285 MOS_STATUS SendShortSlices(PMOS_COMMAND_BUFFER cmdBuffer); 286 287 //! 288 //! \brief Send vdbox flush cmds for S2L HuC cmds 289 //! \details Send vdbox flush cmds for S2L HuC cmds 290 //! 291 //! \param [out] cmdBuffer 292 //! Pointer to Command buffer 293 //! \param [in] primCmdBuffer 294 //! Reference to Primary Command buffer 295 //! \param [in] scdryCmdBuffer 296 //! Reference to Secondary Command buffer 297 //! \param [in] renderingFlags 298 //! Rendering flags 299 //! 300 //! \return MOS_STATUS 301 //! MOS_STATUS_SUCCESS if success, else fail reason 302 //! 303 MOS_STATUS SendHucFlush( 304 PMOS_COMMAND_BUFFER cmdBuffer, 305 MOS_COMMAND_BUFFER &primCmdBuffer, 306 MOS_COMMAND_BUFFER &scdryCmdBuffer, 307 uint32_t renderingFlags); 308 309 //! 310 //! \brief Send flush pipe commands 311 //! \details Send flush pipe commands for each pipe in HEVC decode driver 312 //! 313 //! \param [in] cmdBufferInUse 314 //! Pointer to current using command buffer 315 //! 316 //! \return MOS_STATUS 317 //! MOS_STATUS_SUCCESS if success, else fail reason 318 //! 319 MOS_STATUS AddPipeEpilog( 320 PMOS_COMMAND_BUFFER cmdBufferInUse, 321 MOS_COMMAND_BUFFER &scdryCmdBuffer); 322 323 MOS_STATUS CalcDownsamplingParams( 324 void *picParams, 325 uint32_t *refSurfWidth, 326 uint32_t *refSurfHeight, 327 MOS_FORMAT *format, 328 uint8_t *frameIdx) override; 329 330 MOS_STATUS InitMmcState() override; 331 332 PCODEC_HEVC_EXT_PIC_PARAMS m_hevcExtPicParams; // Extended pic params for Rext 333 PCODEC_HEVC_EXT_SLICE_PARAMS m_hevcExtSliceParams; // Extended slice params for Rext 334 PCODEC_HEVC_SCC_PIC_PARAMS m_hevcSccPicParams; // Pic params for SCC 335 PCODEC_HEVC_SUBSET_PARAMS m_hevcSubsetParams; //!< Hevc subset params for tile entrypoint offset 336 337 #if USE_CODECHAL_DEBUG_TOOL 338 MOS_STATUS DumpPicParams( 339 PCODEC_HEVC_PIC_PARAMS picParams, 340 PCODEC_HEVC_EXT_PIC_PARAMS extPicParams, 341 PCODEC_HEVC_SCC_PIC_PARAMS sccPicParams); 342 343 MOS_STATUS DumpSliceParams( 344 PCODEC_HEVC_SLICE_PARAMS sliceParams, 345 PCODEC_HEVC_EXT_SLICE_PARAMS extSliceParams, 346 uint32_t numSlices, 347 bool shortFormatInUse); 348 349 MOS_STATUS DumpSubsetsParams( 350 PCODEC_HEVC_SUBSET_PARAMS subsetsParams); 351 #endif 352 353 protected: 354 //! 355 //! \brief Set And Populate VE Hint parameters 356 //! \details Set Virtual Engine hint parameter and populate it to primary cmd buffer attributes 357 //! \param [in] primCmdBuf 358 //! Pointer to primary cmd buffer 359 //! \return MOS_STATUS 360 //! MOS_STATUS_SUCCESS if success, else fail reason 361 //! 362 MOS_STATUS SetAndPopulateVEHintParams( 363 PMOS_COMMAND_BUFFER primCmdBuf); 364 365 //! 366 //! \brief Determine if need to send prolog with frame tracking 367 //! \param [in] sendPrologWithFrameTracking 368 //! Pointer to bool type flag 369 //! \return MOS_STATUS 370 //! MOS_STATUS_SUCCESS if success, else fail reason 371 //! 372 MOS_STATUS DetermineSendProlgwithFrmTracking( 373 bool *sendPrologWithFrameTracking); 374 375 //! 376 //! \brief Allocate internal buffer as reference 377 //! \details Allocate reference resource before loop filter for SCC IBC mode 378 //! 379 MOS_STATUS AllocateResourceRefBefLoopFilter(); 380 381 //! 382 //! \brief Check LCU Size 383 //! \details Check LCU Size for HEVC decode driver 384 //! \return MOS_STATUS 385 //! MOS_STATUS_SUCCESS if success, else fail reason 386 //! 387 MOS_STATUS CheckLCUSize(); 388 389 MOS_STATUS SetGpuCtxCreatOption(CodechalSetting *settings) override; 390 391 private: 392 //! 393 //! \brief Calculate command buffer size needed for picture level and slice level commands 394 //! \param [out] requestedSize 395 //! Return command buffer size for picture level and slice level command 396 //! \param [out] additionalSizeNeeded 397 //! Return additianl size needed 398 //! \param [out] requestedPatchListSize 399 //! return patch list size used in this command buffer 400 //! \return None 401 //! 402 void CalcRequestedSpace( 403 uint32_t &requestedSize, 404 uint32_t &additionalSizeNeeded, 405 uint32_t &requestedPatchListSize) override; 406 407 //! 408 //! \brief The virtual function for decode standard to override the requested space size 409 //! \param [in] requestedSize 410 //! The intial request size computed by picture level and slice level 411 //! \return The final requested space size 412 //! 413 uint32_t RequestedSpaceSize(uint32_t requestedSize) override; 414 415 //! 416 //! \brief The virtual function for decode standard to override the extra requested space size 417 //! \param [in] requestedSize 418 //! The intial request size computed by picture level and slice level 419 //! \param [in] additionalSizeNeeded 420 //! The additional request size for command buffer 421 //! \return The extra requested space size 422 //! 423 virtual MOS_STATUS VerifyExtraSpace( 424 uint32_t requestedSize, 425 uint32_t additionalSizeNeeded) override; 426 427 //! 428 //! \brief Utility function to allocate internal histogram surface 429 //! 430 //! \return MOS_STATUS 431 //! MOS_STATUS_SUCCESS if success, else fail reason 432 //! 433 MOS_STATUS AllocateHistogramSurface(); 434 435 protected: 436 bool m_isRealTile = false; //!< If real tile decode mode enabled 437 bool m_isVirtualTile = false; //!< If virtual tile decode mode enabled 438 uint16_t m_ctbSize = 0; //!< Max coding tree block size 439 uint32_t m_frameSizeMaxAlloced = 0; //!< Max Frame size used for buffer allocation in past frames 440 441 bool m_isSeparateTileDecoding = false; //!< Single pipe tile decoding for IBC/PAL 442 MOS_SURFACE m_resRefBeforeLoopFilter; //!< For SCC IBC 443 bool m_twoVersionsOfCurrDecPicFlag = false; //!< Flag for SCC IBC mode 444 uint8_t m_IBCRefIdx = 0; //!< Reference ID for IBC mode 445 446 //! \Hcp state level command buffer size is required 447 uint32_t m_HcpStateCmdBufferSizeNeeded = 0; 448 //! \Hcp state level patch list size is required 449 uint32_t m_HcpPatchListSizeNeeded = 0; 450 //! \Huc state level command buffer size is required 451 uint32_t m_HucStateCmdBufferSizeNeeded = 0; 452 //! \Huc state level patch list size is required 453 uint32_t m_HucPatchListSizeNeeded = 0; 454 //! \Huc Primitive level command buffer size is required 455 uint32_t m_HucPrimitiveCmdBufferSizeNeeded = 0; 456 //! \Huc Primitive level patch list size is required 457 uint32_t m_HucPrimitivePatchListSizeNeeded = 0; 458 //! \CP Primitive level command buffer size is required 459 uint32_t m_CpPrimitiveCmdBufferSizeNeeded = 0; 460 //! \CP Primitive level patch list size is required 461 uint32_t m_CpPrimitivePatchListSizeNeeded = 0; 462 #if (_DEBUG || _RELEASE_INTERNAL) 463 uint32_t m_rtFrameCount; //!< frame count for real tile decoding 464 uint32_t m_vtFrameCount; //!< frame count for virtual tile decoding 465 uint32_t m_spFrameCount; //!< frame count for single pipe decoding 466 467 bool m_histogramDebug = true; //!< Internal histogram buffer debug 468 #endif 469 470 PMOS_SURFACE m_histogramSurface = nullptr; //!< Internal histogram buffer 471 PCODECHAL_DECODE_SINGLEPIPE_VIRTUALENGINE_STATE m_sinlgePipeVeState; //!< single pipe virtual engine state 472 PCODECHAL_DECODE_SCALABILITY_STATE_G12 m_scalabilityState; //!< Scalability state 473 }; 474 #endif // __CODECHAL_DECODER_HEVC__G12_H__ 475