| 1 | /* |
| 2 | * Copyright (c) 2020-2021, 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 decode_vp9_pipeline.cpp |
| 24 | //! \brief Defines the interface for vp9 decode pipeline |
| 25 | //! |
| 26 | #include "decode_vp9_pipeline.h" |
| 27 | #include "decode_utils.h" |
| 28 | #include "codechal_setting.h" |
| 29 | #include "decode_vp9_phase_single.h" |
| 30 | #include "decode_vp9_phase_front_end.h" |
| 31 | #include "decode_vp9_phase_back_end.h" |
| 32 | #include "decode_vp9_feature_manager.h" |
| 33 | #include "decode_vp9_buffer_update.h" |
| 34 | #include "decode_vp9_buffer_update_post.h" |
| 35 | #include "media_debug_fast_dump.h" |
| 36 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 37 | #include "decode_vp9_debug_packet.h" |
| 38 | #endif |
| 39 | |
| 40 | namespace decode |
| 41 | { |
| 42 | Vp9Pipeline::Vp9Pipeline( |
| 43 | CodechalHwInterfaceNext *hwInterface, |
| 44 | CodechalDebugInterface *debugInterface) |
| 45 | : DecodePipeline(hwInterface, debugInterface) |
| 46 | { |
| 47 | MOS_STATUS m_status = InitUserSetting(m_userSettingPtr); |
| 48 | } |
| 49 | |
| 50 | MOS_STATUS Vp9Pipeline::Initialize(void *settings) |
| 51 | { |
| 52 | DECODE_FUNC_CALL(); |
| 53 | DECODE_CHK_STATUS(DecodePipeline::Initialize(settings)); |
| 54 | |
| 55 | // Create basic GPU context |
| 56 | DecodeScalabilityPars scalPars; |
| 57 | MOS_ZeroMemory(&scalPars, sizeof(scalPars)); |
| 58 | DECODE_CHK_STATUS(m_mediaContext->SwitchContext(VdboxDecodeFunc, &scalPars, &m_scalability)); |
| 59 | m_decodeContext = m_osInterface->pfnGetGpuContext(m_osInterface); |
| 60 | m_decodeContextHandle = m_osInterface->CurrentGpuContextHandle; |
| 61 | |
| 62 | m_basicFeature = dynamic_cast<Vp9BasicFeature *>(m_featureManager->GetFeature(FeatureIDs::basicFeature)); |
| 63 | DECODE_CHK_NULL(m_basicFeature); |
| 64 | |
| 65 | auto *codecSettings = (CodechalSetting *)settings; |
| 66 | DECODE_CHK_NULL(codecSettings); |
| 67 | |
| 68 | auto *bufferUpdatePipeline = MOS_New(DecodeVp9BufferUpdate, this, m_task, m_numVdbox); |
| 69 | DECODE_CHK_NULL(bufferUpdatePipeline); |
| 70 | DECODE_CHK_STATUS(m_preSubPipeline->Register(*bufferUpdatePipeline)); |
| 71 | DECODE_CHK_STATUS(bufferUpdatePipeline->Init(*codecSettings)); |
| 72 | |
| 73 | if (m_osInterface->pfnIsMismatchOrderProgrammingSupported()) |
| 74 | { |
| 75 | auto *bufferPostUpdatePipeline = MOS_New(DecodeVp9BufferUpdatePost, this, m_task, m_numVdbox); |
| 76 | DECODE_CHK_NULL(bufferPostUpdatePipeline); |
| 77 | DECODE_CHK_STATUS(m_postSubPipeline->Register(*bufferPostUpdatePipeline)); |
| 78 | DECODE_CHK_STATUS(bufferPostUpdatePipeline->Init(*codecSettings)); |
| 79 | } |
| 80 | |
| 81 | return MOS_STATUS_SUCCESS; |
| 82 | } |
| 83 | |
| 84 | MOS_STATUS Vp9Pipeline::Prepare(void *params) |
| 85 | { |
| 86 | DECODE_FUNC_CALL(); |
| 87 | DECODE_CHK_NULL(params); |
| 88 | |
| 89 | auto basicFeature = dynamic_cast<Vp9BasicFeature *>(m_featureManager->GetFeature(FeatureIDs::basicFeature)); |
| 90 | DECODE_CHK_NULL(basicFeature); |
| 91 | DECODE_CHK_STATUS(DecodePipeline::Prepare(params)); |
| 92 | |
| 93 | return MOS_STATUS_SUCCESS; |
| 94 | } |
| 95 | |
| 96 | MOS_STATUS Vp9Pipeline::Uninitialize() |
| 97 | { |
| 98 | DECODE_FUNC_CALL(); |
| 99 | |
| 100 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 101 | // Report real tile frame count and virtual tile frame count |
| 102 | ReportUserSettingForDebug( |
| 103 | m_userSettingPtr, |
| 104 | "VT Decoded Count", |
| 105 | m_vtFrameCount, |
| 106 | MediaUserSetting::Group::Sequence); |
| 107 | #endif |
| 108 | |
| 109 | DECODE_CHK_STATUS(DestoryPhaseList()); |
| 110 | return DecodePipeline::Uninitialize(); |
| 111 | } |
| 112 | |
| 113 | MOS_STATUS Vp9Pipeline::UserFeatureReport() |
| 114 | { |
| 115 | DECODE_FUNC_CALL(); |
| 116 | DECODE_CHK_STATUS(DecodePipeline::UserFeatureReport()); |
| 117 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 118 | WriteUserFeature(__MEDIA_USER_FEATURE_VALUE_APOGEIOS_VP9D_ENABLE_ID, 1, m_osInterface->pOsContext); |
| 119 | #endif |
| 120 | |
| 121 | CODECHAL_DEBUG_TOOL( |
| 122 | if (m_mmcState != nullptr) { |
| 123 | m_mmcState->UpdateUserFeatureKey(&(m_basicFeature->m_destSurface)); |
| 124 | }) |
| 125 | |
| 126 | return MOS_STATUS_SUCCESS; |
| 127 | } |
| 128 | |
| 129 | MOS_STATUS Vp9Pipeline::Execute() |
| 130 | { |
| 131 | DECODE_FUNC_CALL(); |
| 132 | |
| 133 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 134 | if (GetDecodeMode() == virtualTileDecodeMode) |
| 135 | { |
| 136 | m_vtFrameCount++; |
| 137 | } |
| 138 | #endif |
| 139 | |
| 140 | for (auto &phase : m_phaseList) |
| 141 | { |
| 142 | DECODE_ASSERT(phase != nullptr); |
| 143 | if (phase->RequiresContextSwitch()) |
| 144 | { |
| 145 | // switch context |
| 146 | DecodeScalabilityOption *scalabOption = phase->GetDecodeScalabilityOption(); |
| 147 | DECODE_CHK_NULL(scalabOption); |
| 148 | DECODE_CHK_STATUS(m_mediaContext->SwitchContext(VdboxDecodeFunc, *scalabOption, &m_scalability)); |
| 149 | if (scalabOption->IsScalabilityOptionMatched(m_scalabOption)) |
| 150 | { |
| 151 | m_decodeContext = m_osInterface->pfnGetGpuContext(m_osInterface); |
| 152 | m_decodeContextHandle = m_osInterface->CurrentGpuContextHandle; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | StateParams stateProperty; |
| 157 | stateProperty.currentPipe = phase->GetPipe(); |
| 158 | stateProperty.currentPass = phase->GetPass(); |
| 159 | stateProperty.pipeIndexForSubmit = phase->GetPipe() + 1; |
| 160 | stateProperty.componentState = phase; |
| 161 | DECODE_CHK_STATUS(ActivatePacket(phase->GetPktId(), phase->ImmediateSubmit(), stateProperty)); |
| 162 | |
| 163 | if (phase->ImmediateSubmit()) |
| 164 | { |
| 165 | m_scalability->SetPassNumber(phase->GetPass() + 1); |
| 166 | DECODE_CHK_STATUS(ExecuteActivePackets()); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | return MOS_STATUS_SUCCESS; |
| 171 | } |
| 172 | |
| 173 | MOS_STATUS Vp9Pipeline::CreateFeatureManager() |
| 174 | { |
| 175 | DECODE_FUNC_CALL(); |
| 176 | m_featureManager = MOS_New(DecodeVp9FeatureManager, m_allocator, m_hwInterface, m_osInterface); |
| 177 | DECODE_CHK_NULL(m_featureManager); |
| 178 | return MOS_STATUS_SUCCESS; |
| 179 | } |
| 180 | |
| 181 | MOS_STATUS Vp9Pipeline::CreateSubPackets(DecodeSubPacketManager &subPacketManager, CodechalSetting &codecSettings) |
| 182 | { |
| 183 | DECODE_FUNC_CALL(); |
| 184 | |
| 185 | DECODE_CHK_STATUS(DecodePipeline::CreateSubPackets(subPacketManager, codecSettings)); |
| 186 | |
| 187 | return MOS_STATUS_SUCCESS; |
| 188 | } |
| 189 | |
| 190 | Vp9Pipeline::Vp9DecodeMode Vp9Pipeline::GetDecodeMode() |
| 191 | { |
| 192 | return m_decodeMode; |
| 193 | } |
| 194 | |
| 195 | MOS_STATUS Vp9Pipeline::InitContexOption(Vp9BasicFeature &basicFeature) |
| 196 | { |
| 197 | DecodeScalabilityPars scalPars; |
| 198 | MOS_ZeroMemory(&scalPars, sizeof(scalPars)); |
| 199 | |
| 200 | scalPars.usingHcp = true; |
| 201 | scalPars.enableVE = MOS_VE_SUPPORTED(m_osInterface); |
| 202 | scalPars.disableScalability = m_hwInterface->IsDisableScalability(); |
| 203 | scalPars.surfaceFormat = basicFeature.m_destSurface.Format; |
| 204 | scalPars.frameWidth = basicFeature.m_frameWidthAlignedMinBlk; |
| 205 | scalPars.frameHeight = basicFeature.m_frameHeightAlignedMinBlk; |
| 206 | scalPars.numVdbox = m_numVdbox; |
| 207 | if (m_osInterface->pfnIsMultipleCodecDevicesInUse(m_osInterface)) |
| 208 | { |
| 209 | scalPars.disableScalability = true; |
| 210 | } |
| 211 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 212 | if (m_osInterface->bHcpDecScalabilityMode == MOS_SCALABILITY_ENABLE_MODE_FALSE) |
| 213 | { |
| 214 | scalPars.disableScalability = true; |
| 215 | } |
| 216 | else if (m_osInterface->bHcpDecScalabilityMode == MOS_SCALABILITY_ENABLE_MODE_USER_FORCE) |
| 217 | { |
| 218 | scalPars.disableScalability = false; |
| 219 | } |
| 220 | scalPars.modeSwithThreshold1 = |
| 221 | ReadUserFeature(m_userSettingPtr, "HCP Decode Mode Switch TH1", MediaUserSetting::Group::Sequence).Get<uint32_t>(); |
| 222 | scalPars.modeSwithThreshold2 = |
| 223 | ReadUserFeature(m_userSettingPtr, "HCP Decode Mode Switch TH2", MediaUserSetting::Group::Sequence).Get<uint32_t>(); |
| 224 | scalPars.forceMultiPipe = |
| 225 | ReadUserFeature(m_userSettingPtr, "HCP Decode Always Frame Split", MediaUserSetting::Group::Sequence).Get<bool>(); |
| 226 | scalPars.userPipeNum = |
| 227 | ReadUserFeature(m_userSettingPtr, "HCP Decode User Pipe Num", MediaUserSetting::Group::Sequence).Get<uint8_t>(); |
| 228 | #endif |
| 229 | |
| 230 | #ifdef _DECODE_PROCESSING_SUPPORTED |
| 231 | DecodeDownSamplingFeature *downSamplingFeature = dynamic_cast<DecodeDownSamplingFeature *>( |
| 232 | m_featureManager->GetFeature(DecodeFeatureIDs::decodeDownSampling)); |
| 233 | if (downSamplingFeature != nullptr && downSamplingFeature->IsEnabled()) |
| 234 | { |
| 235 | scalPars.usingSfc = true; |
| 236 | if (!MEDIA_IS_SKU(m_skuTable, FtrSfcScalability)) |
| 237 | { |
| 238 | scalPars.disableScalability = true; |
| 239 | } |
| 240 | } |
| 241 | //Disable Scalability when histogram is enabled |
| 242 | if (downSamplingFeature != nullptr && (downSamplingFeature->m_histogramDestSurf || downSamplingFeature->m_histogramDebug)) |
| 243 | { |
| 244 | scalPars.disableScalability = true; |
| 245 | } |
| 246 | #endif |
| 247 | |
| 248 | if (MEDIA_IS_SKU(m_skuTable, FtrVirtualTileScalabilityDisable)) |
| 249 | { |
| 250 | scalPars.disableScalability = true; |
| 251 | scalPars.disableVirtualTile = true; |
| 252 | } |
| 253 | |
| 254 | DECODE_CHK_STATUS(m_scalabOption.SetScalabilityOption(&scalPars)); |
| 255 | return MOS_STATUS_SUCCESS; |
| 256 | } |
| 257 | |
| 258 | MOS_STATUS Vp9Pipeline::InitDecodeMode(ScalabilityMode scalabMode) |
| 259 | { |
| 260 | if (scalabMode == scalabilityVirtualTileMode) |
| 261 | { |
| 262 | m_decodeMode = virtualTileDecodeMode; |
| 263 | } |
| 264 | else if (scalabMode == scalabilitySingleMode) |
| 265 | { |
| 266 | m_decodeMode = baseDecodeMode; |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | return MOS_STATUS_INVALID_PARAMETER; |
| 271 | } |
| 272 | |
| 273 | return MOS_STATUS_SUCCESS; |
| 274 | } |
| 275 | |
| 276 | template <typename T> |
| 277 | MOS_STATUS Vp9Pipeline::CreatePhase(uint8_t pass, uint8_t pipe, uint8_t activePipeNum) |
| 278 | { |
| 279 | DECODE_FUNC_CALL(); |
| 280 | T *phase = MOS_New(T, *this, m_scalabOption); |
| 281 | DECODE_CHK_NULL(phase); |
| 282 | MOS_STATUS status = phase->Initialize(pass, pipe, activePipeNum); |
| 283 | if (status != MOS_STATUS_SUCCESS) |
| 284 | { |
| 285 | MOS_Delete(phase); |
| 286 | return status; |
| 287 | } |
| 288 | m_phaseList.push_back(phase); |
| 289 | return MOS_STATUS_SUCCESS; |
| 290 | } |
| 291 | |
| 292 | MOS_STATUS Vp9Pipeline::CreatePhaseList(const ScalabilityMode scalabMode, const uint8_t numPipe) |
| 293 | { |
| 294 | DECODE_FUNC_CALL(); |
| 295 | DECODE_ASSERT(m_phaseList.empty()); |
| 296 | |
| 297 | if (scalabMode == scalabilityVirtualTileMode) |
| 298 | { |
| 299 | DECODE_CHK_STATUS(CreatePhase<Vp9PhaseFrontEnd>()); |
| 300 | for (uint8_t i = 0; i < numPipe; i++) |
| 301 | { |
| 302 | DECODE_CHK_STATUS(CreatePhase<Vp9PhaseBackEnd>(0, i, numPipe)); |
| 303 | } |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | DECODE_CHK_STATUS(CreatePhase<Vp9PhaseSingle>()); |
| 308 | } |
| 309 | |
| 310 | return MOS_STATUS_SUCCESS; |
| 311 | } |
| 312 | |
| 313 | MOS_STATUS Vp9Pipeline::DestoryPhaseList() |
| 314 | { |
| 315 | for (auto &phase : m_phaseList) |
| 316 | { |
| 317 | MOS_Delete(phase); |
| 318 | } |
| 319 | m_phaseList.clear(); |
| 320 | return MOS_STATUS_SUCCESS; |
| 321 | } |
| 322 | |
| 323 | #if USE_CODECHAL_DEBUG_TOOL |
| 324 | MOS_STATUS Vp9Pipeline::DumpPicParams(CODEC_VP9_PIC_PARAMS *picParams) |
| 325 | { |
| 326 | CODECHAL_DEBUG_FUNCTION_ENTER; |
| 327 | |
| 328 | if (picParams == nullptr) |
| 329 | { |
| 330 | return MOS_STATUS_SUCCESS; |
| 331 | } |
| 332 | |
| 333 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrPicParams)) |
| 334 | { |
| 335 | const char *fileName = m_debugInterface->CreateFileName( |
| 336 | "_DEC", |
| 337 | CodechalDbgBufferType::bufPicParams, |
| 338 | CodechalDbgExtType::txt); |
| 339 | |
| 340 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 341 | { |
| 342 | MediaDebugFastDump::Dump( |
| 343 | (uint8_t *)picParams, |
| 344 | fileName, |
| 345 | sizeof(CODEC_VP9_PIC_PARAMS), |
| 346 | 0, |
| 347 | MediaDebugSerializer<CODEC_VP9_PIC_PARAMS>()); |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | DumpDecodeVp9PicParams(picParams, fileName); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return MOS_STATUS_SUCCESS; |
| 356 | } |
| 357 | |
| 358 | MOS_STATUS Vp9Pipeline::DumpSliceParams(CODEC_VP9_SLICE_PARAMS *slcParams) |
| 359 | { |
| 360 | CODECHAL_DEBUG_FUNCTION_ENTER; |
| 361 | |
| 362 | if (slcParams == nullptr) |
| 363 | { |
| 364 | return MOS_STATUS_SUCCESS; |
| 365 | } |
| 366 | |
| 367 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSlcParams)) |
| 368 | { |
| 369 | const char *fileName = m_debugInterface->CreateFileName( |
| 370 | "_DEC", |
| 371 | CodechalDbgBufferType::bufSlcParams, |
| 372 | CodechalDbgExtType::txt); |
| 373 | |
| 374 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 375 | { |
| 376 | MediaDebugFastDump::Dump( |
| 377 | (uint8_t *)slcParams, |
| 378 | fileName, |
| 379 | sizeof(CODEC_VP9_SLICE_PARAMS), |
| 380 | 0, |
| 381 | MediaDebugSerializer<CODEC_VP9_SLICE_PARAMS>()); |
| 382 | } |
| 383 | else |
| 384 | { |
| 385 | DumpDecodeVp9SliceParams(slcParams, fileName); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | return MOS_STATUS_SUCCESS; |
| 390 | } |
| 391 | |
| 392 | MOS_STATUS Vp9Pipeline::DumpSegmentParams(CODEC_VP9_SEGMENT_PARAMS *segmentParams) |
| 393 | { |
| 394 | CODECHAL_DEBUG_FUNCTION_ENTER; |
| 395 | |
| 396 | if (segmentParams == nullptr) |
| 397 | { |
| 398 | return MOS_STATUS_SUCCESS; |
| 399 | } |
| 400 | |
| 401 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSegmentParams)) |
| 402 | { |
| 403 | const char *fileName = m_debugInterface->CreateFileName( |
| 404 | "_DEC", |
| 405 | CodechalDbgBufferType::bufSegmentParams, |
| 406 | CodechalDbgExtType::txt); |
| 407 | |
| 408 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 409 | { |
| 410 | MediaDebugFastDump::Dump( |
| 411 | (uint8_t *)segmentParams, |
| 412 | fileName, |
| 413 | sizeof(CODEC_VP9_SEGMENT_PARAMS), |
| 414 | 0, |
| 415 | MediaDebugSerializer<CODEC_VP9_SEGMENT_PARAMS>()); |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | DumpDecodeVp9SegmentParams(segmentParams, fileName); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | return MOS_STATUS_SUCCESS; |
| 424 | } |
| 425 | #endif |
| 426 | |
| 427 | } // namespace decode |