| 1 |
/* |
| 2 |
* Copyright (c) 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_av1_packet.cpp |
| 24 |
//! \brief Defines the interface for av1 decode packet |
| 25 |
//! |
| 26 |
#include "decode_av1_packet.h" |
| 27 |
#include "decode_status_report_defs.h" |
| 28 |
#include "decode_predication_packet.h" |
| 29 |
#include "decode_marker_packet.h" |
| 30 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 31 |
#include "decode_av1_debug_packet.h" |
| 32 |
#endif |
| 33 |
|
| 34 |
namespace decode { |
| 35 |
|
| 36 |
MOS_STATUS Av1DecodePkt::Init() |
| 37 |
{ |
| 38 |
DECODE_FUNC_CALL(); |
| 39 |
DECODE_CHK_NULL(m_miItf); |
| 40 |
DECODE_CHK_NULL(m_statusReport); |
| 41 |
DECODE_CHK_NULL(m_featureManager); |
| 42 |
DECODE_CHK_NULL(m_av1Pipeline); |
| 43 |
DECODE_CHK_NULL(m_osInterface); |
| 44 |
|
| 45 |
DECODE_CHK_STATUS(CmdPacket::Init()); |
| 46 |
|
| 47 |
m_av1BasicFeature = dynamic_cast<Av1BasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature)); |
| 48 |
DECODE_CHK_NULL(m_av1BasicFeature); |
| 49 |
|
| 50 |
m_allocator = m_av1Pipeline->GetDecodeAllocator(); |
| 51 |
DECODE_CHK_NULL(m_allocator); |
| 52 |
|
| 53 |
DECODE_CHK_STATUS(m_statusReport->RegistObserver(this)); |
| 54 |
|
| 55 |
DecodeSubPacket* subPacket = m_av1Pipeline->GetSubPacket(DecodePacketId(m_av1Pipeline, av1PictureSubPacketId)); |
| 56 |
|
| 57 |
m_picturePkt = dynamic_cast<Av1DecodePicPkt*>(subPacket); |
| 58 |
DECODE_CHK_NULL(m_picturePkt); |
| 59 |
DECODE_CHK_STATUS(m_picturePkt->CalculateCommandSize(m_pictureStatesSize, m_picturePatchListSize)); |
| 60 |
|
| 61 |
subPacket = m_av1Pipeline->GetSubPacket(DecodePacketId(m_av1Pipeline, av1TileSubPacketId)); |
| 62 |
m_tilePkt = dynamic_cast<Av1DecodeTilePkt*>(subPacket); |
| 63 |
DECODE_CHK_NULL(m_tilePkt); |
| 64 |
DECODE_CHK_STATUS(m_tilePkt->CalculateCommandSize(m_tileStatesSize, m_tilePatchListSize)); |
| 65 |
|
| 66 |
m_secondLevelBBArray = m_allocator->AllocateBatchBufferArray( |
| 67 |
m_pictureStatesSize, 1, CODEC_NUM_AV1_SECOND_BB, true, lockableVideoMem); |
| 68 |
DECODE_CHK_NULL(m_secondLevelBBArray); |
| 69 |
|
| 70 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 71 |
// Initialize debug packet |
| 72 |
DecodeSubPacket* debugSubPacket = m_av1Pipeline->GetSubPacket(DecodePacketId(m_av1Pipeline, av1DebugSubPacketId)); |
| 73 |
if (debugSubPacket != nullptr) |
| 74 |
{ |
| 75 |
Av1DecodeDebugPkt* debugPkt = dynamic_cast<Av1DecodeDebugPkt*>(debugSubPacket); |
| 76 |
if (debugPkt != nullptr) |
| 77 |
{ |
| 78 |
m_av1DebugPkt = debugPkt; |
| 79 |
DECODE_CHK_STATUS(m_av1DebugPkt->Init()); |
| 80 |
} |
| 81 |
} |
| 82 |
#endif |
| 83 |
|
| 84 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 85 |
subPacket = m_av1Pipeline->GetSubPacket(DecodePacketId(m_av1Pipeline, av1DecodeAqmId)); |
| 86 |
if (subPacket != nullptr) |
| 87 |
{ |
| 88 |
m_aqmPkt = dynamic_cast<Av1DecodeAqmPkt*>(subPacket); |
| 89 |
if (m_aqmPkt != nullptr) |
| 90 |
{ |
| 91 |
DECODE_CHK_STATUS(m_aqmPkt->CalculateCommandSize(m_aqmStatesSize, m_aqmPatchListSize)); |
| 92 |
} |
| 93 |
} |
| 94 |
#endif |
| 95 |
|
| 96 |
return MOS_STATUS_SUCCESS; |
| 97 |
} |
| 98 |
|
| 99 |
MOS_STATUS Av1DecodePkt::Prepare() |
| 100 |
{ |
| 101 |
DECODE_FUNC_CALL(); |
| 102 |
|
| 103 |
DECODE_CHK_NULL(m_av1BasicFeature->m_av1PicParams); |
| 104 |
m_av1PicParams = m_av1BasicFeature->m_av1PicParams; |
| 105 |
|
| 106 |
return MOS_STATUS_SUCCESS; |
| 107 |
} |
| 108 |
|
| 109 |
MOS_STATUS Av1DecodePkt::Destroy() |
| 110 |
{ |
| 111 |
m_statusReport->UnregistObserver(this); |
| 112 |
if (m_allocator != nullptr) |
| 113 |
{ |
| 114 |
DECODE_CHK_STATUS(m_allocator->Destroy(m_secondLevelBBArray)); |
| 115 |
} |
| 116 |
|
| 117 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 118 |
// Destroy debug packet |
| 119 |
if (m_av1DebugPkt != nullptr) |
| 120 |
{ |
| 121 |
DECODE_CHK_STATUS(m_av1DebugPkt->Destroy()); |
| 122 |
} |
| 123 |
#endif |
| 124 |
|
| 125 |
return MOS_STATUS_SUCCESS; |
| 126 |
} |
| 127 |
|
| 128 |
void Av1DecodePkt::SetPerfTag(CODECHAL_MODE mode, uint16_t picCodingType) |
| 129 |
{ |
| 130 |
DECODE_FUNC_CALL(); |
| 131 |
|
| 132 |
uint16_t perfTag = ((mode << 4) & 0xF0) | (picCodingType & 0xF); |
| 133 |
m_osInterface->pfnIncPerfFrameID(m_osInterface); |
| 134 |
m_osInterface->pfnSetPerfTag(m_osInterface, perfTag); |
| 135 |
m_osInterface->pfnResetPerfBufferID(m_osInterface); |
| 136 |
} |
| 137 |
|
| 138 |
bool Av1DecodePkt::IsPrologRequired() |
| 139 |
{ |
| 140 |
return true; // if ScalableMode, should set to false. |
| 141 |
} |
| 142 |
|
| 143 |
MOS_STATUS Av1DecodePkt::AddForceWakeup(MOS_COMMAND_BUFFER& cmdBuffer) |
| 144 |
{ |
| 145 |
DECODE_FUNC_CALL(); |
| 146 |
// NativeFence sync BB may cause preemption and ring idle, so force wakeup after it |
| 147 |
DECODE_CHK_STATUS(AddNativeFenceSyncBBStartCmd(cmdBuffer)); |
| 148 |
|
| 149 |
auto &par = m_miItf->GETPAR_MI_FORCE_WAKEUP(); |
| 150 |
MOS_ZeroMemory(&par, sizeof(mhw::mi::MI_FORCE_WAKEUP_PAR)); |
| 151 |
par.bMFXPowerWellControl = false; |
| 152 |
par.bMFXPowerWellControlMask = true; |
| 153 |
par.bHEVCPowerWellControl = true; |
| 154 |
par.bHEVCPowerWellControlMask = true; |
| 155 |
|
| 156 |
DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FORCE_WAKEUP(&cmdBuffer)); |
| 157 |
|
| 158 |
return MOS_STATUS_SUCCESS; |
| 159 |
} |
| 160 |
|
| 161 |
MOS_STATUS Av1DecodePkt::SendPrologWithFrameTracking(MOS_COMMAND_BUFFER& cmdBuffer, bool frameTrackingRequested) |
| 162 |
{ |
| 163 |
DecodeSubPacket* subPacket = m_av1Pipeline->GetSubPacket(DecodePacketId(m_av1Pipeline, markerSubPacketId)); |
| 164 |
DecodeMarkerPkt *makerPacket = dynamic_cast<DecodeMarkerPkt*>(subPacket); |
| 165 |
DECODE_CHK_NULL(makerPacket); |
| 166 |
DECODE_CHK_STATUS(makerPacket->Execute(cmdBuffer)); |
| 167 |
|
| 168 |
m_mmcState = m_av1Pipeline->GetMmcState(); |
| 169 |
bool isMmcEnabled = (m_mmcState != nullptr && m_mmcState->IsMmcEnabled()); |
| 170 |
if (isMmcEnabled) |
| 171 |
{ |
| 172 |
DECODE_CHK_STATUS(m_mmcState->SendPrologCmd(&cmdBuffer, false)); |
| 173 |
} |
| 174 |
|
| 175 |
MHW_GENERIC_PROLOG_PARAMS genericPrologParams; |
| 176 |
MOS_ZeroMemory(&genericPrologParams, sizeof(genericPrologParams)); |
| 177 |
genericPrologParams.pOsInterface = m_osInterface; |
| 178 |
genericPrologParams.pvMiInterface = nullptr; |
| 179 |
|
| 180 |
genericPrologParams.bMmcEnabled = isMmcEnabled; |
| 181 |
|
| 182 |
DECODE_CHK_STATUS(Mhw_SendGenericPrologCmdNext(&cmdBuffer, &genericPrologParams, m_miItf)); |
| 183 |
|
| 184 |
subPacket = m_av1Pipeline->GetSubPacket(DecodePacketId(m_av1Pipeline, predicationSubPacketId)); |
| 185 |
DecodePredicationPkt *predicationPacket = dynamic_cast<DecodePredicationPkt*>(subPacket); |
| 186 |
DECODE_CHK_NULL(predicationPacket); |
| 187 |
DECODE_CHK_STATUS(predicationPacket->Execute(cmdBuffer)); |
| 188 |
|
| 189 |
return MOS_STATUS_SUCCESS; |
| 190 |
} |
| 191 |
|
| 192 |
MOS_STATUS Av1DecodePkt::VdPipelineFlush(MOS_COMMAND_BUFFER & cmdBuffer) |
| 193 |
{ |
| 194 |
DECODE_FUNC_CALL(); |
| 195 |
|
| 196 |
auto &par = m_vdencItf->GETPAR_VD_PIPELINE_FLUSH(); |
| 197 |
par = {}; |
| 198 |
par.waitDoneAV1 = 1; |
| 199 |
par.flushAV1 = 1; |
| 200 |
par.waitDoneVDCmdMsgParser = 1; |
| 201 |
m_vdencItf->ADDCMD_VD_PIPELINE_FLUSH(&cmdBuffer); |
| 202 |
|
| 203 |
return MOS_STATUS_SUCCESS; |
| 204 |
} |
| 205 |
|
| 206 |
MOS_STATUS Av1DecodePkt::MiFlush(MOS_COMMAND_BUFFER & cmdBuffer) |
| 207 |
{ |
| 208 |
DECODE_FUNC_CALL(); |
| 209 |
|
| 210 |
auto &par = m_miItf->GETPAR_MI_FLUSH_DW(); |
| 211 |
MOS_ZeroMemory(&par, sizeof(mhw::mi::MI_FLUSH_DW_PAR)); |
| 212 |
|
| 213 |
// Add Video Pipeline Cache Invalidate when CRC output is enabled |
| 214 |
if (m_av1Pipeline && m_av1Pipeline->GetMemDataAccessCrcOutputEnable()) |
| 215 |
{ |
| 216 |
par.bVideoPipelineCacheInvalidate = true; |
| 217 |
} |
| 218 |
|
| 219 |
DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FLUSH_DW(&cmdBuffer)); |
| 220 |
|
| 221 |
return MOS_STATUS_SUCCESS; |
| 222 |
} |
| 223 |
|
| 224 |
MOS_STATUS Av1DecodePkt::Completed(void *mfxStatus, void *rcsStatus, void *statusReport) |
| 225 |
{ |
| 226 |
DECODE_FUNC_CALL(); |
| 227 |
|
| 228 |
DECODE_CHK_NULL(mfxStatus); |
| 229 |
DECODE_CHK_NULL(statusReport); |
| 230 |
DECODE_CHK_NULL(m_av1BasicFeature); |
| 231 |
|
| 232 |
DecodeStatusMfx * decodeStatusMfx = (DecodeStatusMfx *)mfxStatus; |
| 233 |
DecodeStatusReportData *statusReportData = (DecodeStatusReportData *)statusReport; |
| 234 |
DECODE_VERBOSEMESSAGE("Current Frame Index = %d", statusReportData->currDecodedPic.FrameIdx); |
| 235 |
|
| 236 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 237 |
// Complete debug packet operations |
| 238 |
if (m_av1DebugPkt != nullptr) |
| 239 |
{ |
| 240 |
DECODE_CHK_STATUS(m_av1DebugPkt->Completed(mfxStatus)); |
| 241 |
} |
| 242 |
#endif |
| 243 |
|
| 244 |
return MOS_STATUS_SUCCESS; |
| 245 |
} |
| 246 |
|
| 247 |
MOS_STATUS Av1DecodePkt::CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize) |
| 248 |
{ |
| 249 |
commandBufferSize = CalculateCommandBufferSize(); |
| 250 |
requestedPatchListSize = CalculatePatchListSize(); |
| 251 |
return MOS_STATUS_SUCCESS; |
| 252 |
} |
| 253 |
|
| 254 |
uint32_t Av1DecodePkt::CalculateCommandBufferSize() |
| 255 |
{ |
| 256 |
uint32_t commandBufferSize = 0; |
| 257 |
|
| 258 |
commandBufferSize = m_pictureStatesSize + m_tileStatesSize; |
| 259 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 260 |
commandBufferSize += m_aqmStatesSize; |
| 261 |
#endif |
| 262 |
|
| 263 |
return (commandBufferSize + COMMAND_BUFFER_RESERVED_SPACE); |
| 264 |
} |
| 265 |
|
| 266 |
uint32_t Av1DecodePkt::CalculatePatchListSize() |
| 267 |
{ |
| 268 |
if (!m_osInterface->bUsesPatchList) |
| 269 |
{ |
| 270 |
return 0; |
| 271 |
} |
| 272 |
|
| 273 |
uint32_t requestedPatchListSize = 0; |
| 274 |
|
| 275 |
requestedPatchListSize = m_picturePatchListSize + m_tilePatchListSize; |
| 276 |
#ifdef _DECODE_PROCESSING_SUPPORTED |
| 277 |
requestedPatchListSize += m_aqmPatchListSize; |
| 278 |
#endif |
| 279 |
|
| 280 |
return requestedPatchListSize; |
| 281 |
} |
| 282 |
|
| 283 |
MOS_STATUS Av1DecodePkt::ReadAvpStatus(MediaStatusReport* statusReport, MOS_COMMAND_BUFFER& cmdBuffer) |
| 284 |
{ |
| 285 |
DECODE_FUNC_CALL(); |
| 286 |
|
| 287 |
DECODE_CHK_NULL(statusReport); |
| 288 |
|
| 289 |
if (!m_osInterface->bSimIsActive) |
| 290 |
{ |
| 291 |
MOS_RESOURCE* osResource = nullptr; |
| 292 |
uint32_t offset = 0; |
| 293 |
|
| 294 |
auto &par = m_miItf->GETPAR_MI_STORE_REGISTER_MEM(); |
| 295 |
MOS_ZeroMemory(&par, sizeof(mhw::mi::MI_STORE_REGISTER_MEM_PAR)); |
| 296 |
|
| 297 |
DECODE_CHK_NULL(m_hwInterface->GetAvpInterfaceNext()); |
| 298 |
auto mmioRegistersAvp = m_hwInterface->GetAvpInterfaceNext()->GetMmioRegisters(MHW_VDBOX_NODE_1); |
| 299 |
|
| 300 |
DECODE_CHK_STATUS(statusReport->GetAddress(decode::DecodeStatusReportType::DecErrorStatusOffset, osResource, offset)); |
| 301 |
par.presStoreBuffer = osResource; |
| 302 |
par.dwOffset = offset; |
| 303 |
par.dwRegister = mmioRegistersAvp->avpAv1DecErrorStatusAddrRegOffset; |
| 304 |
|
| 305 |
DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer)); |
| 306 |
} |
| 307 |
|
| 308 |
return MOS_STATUS_SUCCESS; |
| 309 |
} |
| 310 |
|
| 311 |
MOS_STATUS Av1DecodePkt::StartStatusReport(uint32_t srType, MOS_COMMAND_BUFFER* cmdBuffer) |
| 312 |
{ |
| 313 |
DECODE_FUNC_CALL(); |
| 314 |
|
| 315 |
DECODE_CHK_STATUS(MediaPacket::StartStatusReportNext(srType, cmdBuffer)); |
| 316 |
|
| 317 |
SetPerfTag(CODECHAL_DECODE_MODE_AV1VLD, m_av1BasicFeature->m_pictureCodingType); |
| 318 |
MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance(); |
| 319 |
DECODE_CHK_NULL(perfProfiler); |
| 320 |
DECODE_CHK_STATUS(perfProfiler->AddPerfCollectStartCmd( |
| 321 |
(void*)m_av1Pipeline, m_osInterface, m_miItf, cmdBuffer)); |
| 322 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 323 |
if (m_statusReport && m_statusReport->IsVdboxIdReportEnabled()) |
| 324 |
{ |
| 325 |
StoreEngineId(cmdBuffer, decode::DecodeStatusReportType::CsEngineIdOffset_0); |
| 326 |
} |
| 327 |
// Add command counter commands for debug |
| 328 |
if (m_av1DebugPkt != nullptr) |
| 329 |
{ |
| 330 |
DECODE_CHK_STATUS(m_av1DebugPkt->AddCommandCounterCmds(*cmdBuffer, m_statusReport)); |
| 331 |
} |
| 332 |
#endif |
| 333 |
return MOS_STATUS_SUCCESS; |
| 334 |
} |
| 335 |
|
| 336 |
MOS_STATUS Av1DecodePkt::EndStatusReport(uint32_t srType, MOS_COMMAND_BUFFER* cmdBuffer) |
| 337 |
{ |
| 338 |
DECODE_FUNC_CALL(); |
| 339 |
|
| 340 |
DECODE_CHK_NULL(cmdBuffer); |
| 341 |
DECODE_CHK_STATUS(ReadAvpStatus( m_statusReport, *cmdBuffer)); |
| 342 |
DECODE_CHK_STATUS(MediaPacket::EndStatusReportNext(srType, cmdBuffer)); |
| 343 |
|
| 344 |
MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance(); |
| 345 |
DECODE_CHK_NULL(perfProfiler); |
| 346 |
DECODE_CHK_STATUS(perfProfiler->AddPerfCollectEndCmd( |
| 347 |
(void*)m_av1Pipeline, m_osInterface, m_miItf, cmdBuffer)); |
| 348 |
|
| 349 |
// Add Mi flush here to ensure end status tag flushed to memory earlier than completed count |
| 350 |
DECODE_CHK_STATUS(MiFlush(*cmdBuffer)); |
| 351 |
|
| 352 |
return MOS_STATUS_SUCCESS; |
| 353 |
} |
| 354 |
|
| 355 |
MOS_STATUS Av1DecodePkt::StatusReportPerTile(MOS_COMMAND_BUFFER *cmdBuffer, int16_t idx) |
| 356 |
{ |
| 357 |
DECODE_FUNC_CALL(); |
| 358 |
|
| 359 |
DECODE_CHK_NULL(cmdBuffer); |
| 360 |
|
| 361 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 362 |
// Call debug packet ExecutePerTile for per-tile status reporting |
| 363 |
if (m_av1DebugPkt != nullptr) |
| 364 |
{ |
| 365 |
DECODE_CHK_STATUS(m_av1DebugPkt->ExecutePerTile(*cmdBuffer, idx)); |
| 366 |
} |
| 367 |
#endif |
| 368 |
|
| 369 |
return MOS_STATUS_SUCCESS; |
| 370 |
} |
| 371 |
|
| 372 |
MOS_STATUS Av1DecodePkt::InitPicLevelCmdBuffer(MHW_BATCH_BUFFER &batchBuffer, uint8_t *batchBufBase) |
| 373 |
{ |
| 374 |
DECODE_FUNC_CALL(); |
| 375 |
|
| 376 |
auto &cmdBuffer = m_picCmdBuffer; |
| 377 |
MOS_ZeroMemory(&cmdBuffer, sizeof(MOS_COMMAND_BUFFER)); |
| 378 |
cmdBuffer.pCmdBase = (uint32_t*)batchBufBase; |
| 379 |
cmdBuffer.pCmdPtr = cmdBuffer.pCmdBase; |
| 380 |
cmdBuffer.iRemaining = batchBuffer.iSize; |
| 381 |
cmdBuffer.OsResource = batchBuffer.OsResource; |
| 382 |
|
| 383 |
return MOS_STATUS_SUCCESS; |
| 384 |
} |
| 385 |
|
| 386 |
} |