| 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_vp8_packet.cpp |
| 24 | //! \brief Defines the interface for vp8 decode packet |
| 25 | //! |
| 26 | #include "decode_vp8_packet.h" |
| 27 | #include "decode_status_report_defs.h" |
| 28 | #include "decode_predication_packet.h" |
| 29 | #include "decode_marker_packet.h" |
| 30 | |
| 31 | namespace decode |
| 32 | { |
| 33 | Vp8DecodePkt::Vp8DecodePkt(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterfaceNext *hwInterface) |
| 34 | : CmdPacket(task) |
| 35 | { |
| 36 | if (pipeline != nullptr) |
| 37 | { |
| 38 | m_statusReport = pipeline->GetStatusReportInstance(); |
| 39 | m_featureManager = pipeline->GetFeatureManager(); |
| 40 | m_vp8Pipeline = dynamic_cast<Vp8Pipeline *>(pipeline); |
| 41 | } |
| 42 | if (hwInterface != nullptr) |
| 43 | { |
| 44 | m_hwInterface = hwInterface; |
| 45 | m_miItf = std::static_pointer_cast<mhw::mi::Itf>(hwInterface->GetMiInterfaceNext()); |
| 46 | m_osInterface = hwInterface->GetOsInterface(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | MOS_STATUS Vp8DecodePkt::Init() |
| 51 | { |
| 52 | DECODE_FUNC_CALL(); |
| 53 | DECODE_CHK_NULL(m_statusReport); |
| 54 | DECODE_CHK_NULL(m_featureManager); |
| 55 | DECODE_CHK_NULL(m_vp8Pipeline); |
| 56 | DECODE_CHK_NULL(m_osInterface); |
| 57 | DECODE_CHK_NULL(m_miItf); |
| 58 | |
| 59 | DECODE_CHK_STATUS(CmdPacket::Init()); |
| 60 | |
| 61 | DecodeSubPacket *subPacket = m_vp8Pipeline->GetSubPacket(DecodePacketId(m_vp8Pipeline, vp8PictureSubPacketId)); |
| 62 | m_picturePkt = dynamic_cast<Vp8DecodePicPkt *>(subPacket); |
| 63 | DECODE_CHK_NULL(m_picturePkt); |
| 64 | DECODE_CHK_STATUS(m_picturePkt->CalculateCommandSize(m_pictureStatesSize, m_picturePatchListSize)); |
| 65 | |
| 66 | subPacket = m_vp8Pipeline->GetSubPacket(DecodePacketId(m_vp8Pipeline, vp8SliceSubPacketId)); |
| 67 | m_slicePkt = dynamic_cast<Vp8DecodeSlcPkt *>(subPacket); |
| 68 | DECODE_CHK_NULL(m_slicePkt); |
| 69 | DECODE_CHK_STATUS(m_slicePkt->CalculateCommandSize(m_sliceStatesSize, m_slicePatchListSize)); |
| 70 | |
| 71 | m_vp8BasicFeature = dynamic_cast<Vp8BasicFeature *>(m_featureManager->GetFeature(FeatureIDs::basicFeature)); |
| 72 | DECODE_CHK_NULL(m_vp8BasicFeature); |
| 73 | |
| 74 | m_allocator = m_vp8Pipeline->GetDecodeAllocator(); |
| 75 | DECODE_CHK_NULL(m_allocator); |
| 76 | |
| 77 | DECODE_CHK_STATUS(m_statusReport->RegistObserver(this)); |
| 78 | |
| 79 | return MOS_STATUS_SUCCESS; |
| 80 | } |
| 81 | |
| 82 | MOS_STATUS Vp8DecodePkt::Prepare() |
| 83 | { |
| 84 | DECODE_FUNC_CALL(); |
| 85 | |
| 86 | DECODE_CHK_NULL(m_vp8BasicFeature); |
| 87 | DECODE_CHK_NULL(m_vp8BasicFeature->m_vp8PicParams); |
| 88 | m_vp8PicParams = m_vp8BasicFeature->m_vp8PicParams; |
| 89 | |
| 90 | return MOS_STATUS_SUCCESS; |
| 91 | } |
| 92 | |
| 93 | MOS_STATUS Vp8DecodePkt::Destroy() |
| 94 | { |
| 95 | m_statusReport->UnregistObserver(this); |
| 96 | return MOS_STATUS_SUCCESS; |
| 97 | } |
| 98 | |
| 99 | void Vp8DecodePkt::SetPerfTag(CODECHAL_MODE mode, uint16_t picCodingType) |
| 100 | { |
| 101 | DECODE_FUNC_CALL(); |
| 102 | |
| 103 | uint16_t perfTag = ((mode << 4) & 0xF0) | (picCodingType & 0xF); |
| 104 | m_osInterface->pfnIncPerfFrameID(m_osInterface); |
| 105 | m_osInterface->pfnSetPerfTag(m_osInterface, perfTag); |
| 106 | m_osInterface->pfnResetPerfBufferID(m_osInterface); |
| 107 | } |
| 108 | |
| 109 | bool Vp8DecodePkt::IsPrologRequired() |
| 110 | { |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | MOS_STATUS Vp8DecodePkt::AddForceWakeup(MOS_COMMAND_BUFFER &cmdBuffer) |
| 115 | { |
| 116 | DECODE_FUNC_CALL(); |
| 117 | // NativeFence sync BB may cause preemption and ring idle, so force wakeup after it |
| 118 | DECODE_CHK_STATUS(AddNativeFenceSyncBBStartCmd(cmdBuffer)); |
| 119 | |
| 120 | auto &par = m_miItf->GETPAR_MI_FORCE_WAKEUP(); |
| 121 | MOS_ZeroMemory(&par, sizeof(par)); |
| 122 | par.bMFXPowerWellControl = true; |
| 123 | par.bMFXPowerWellControlMask = true; |
| 124 | par.bHEVCPowerWellControl = false; |
| 125 | par.bHEVCPowerWellControlMask = true; |
| 126 | |
| 127 | DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FORCE_WAKEUP(&cmdBuffer)); |
| 128 | return MOS_STATUS_SUCCESS; |
| 129 | } |
| 130 | |
| 131 | MOS_STATUS Vp8DecodePkt::SendPrologWithFrameTracking(MOS_COMMAND_BUFFER &cmdBuffer, bool frameTrackingRequested) |
| 132 | { |
| 133 | DecodeSubPacket *subPacket = m_vp8Pipeline->GetSubPacket(DecodePacketId(m_vp8Pipeline, markerSubPacketId)); |
| 134 | DecodeMarkerPkt *makerPacket = dynamic_cast<DecodeMarkerPkt *>(subPacket); |
| 135 | DECODE_CHK_NULL(makerPacket); |
| 136 | DECODE_CHK_STATUS(makerPacket->Execute(cmdBuffer)); |
| 137 | |
| 138 | m_mmcState = m_vp8Pipeline->GetMmcState(); |
| 139 | bool isMmcEnabled = (m_mmcState != nullptr && m_mmcState->IsMmcEnabled()); |
| 140 | if (isMmcEnabled) |
| 141 | { |
| 142 | DECODE_CHK_STATUS(m_mmcState->SendPrologCmd(&cmdBuffer, false)); |
| 143 | } |
| 144 | |
| 145 | MHW_GENERIC_PROLOG_PARAMS genericPrologParams; |
| 146 | MOS_ZeroMemory(&genericPrologParams, sizeof(genericPrologParams)); |
| 147 | genericPrologParams.pOsInterface = m_osInterface; |
| 148 | genericPrologParams.pvMiInterface = nullptr; |
| 149 | |
| 150 | genericPrologParams.bMmcEnabled = isMmcEnabled; |
| 151 | |
| 152 | DECODE_CHK_STATUS(Mhw_SendGenericPrologCmdNext(&cmdBuffer, &genericPrologParams, m_miItf)); |
| 153 | |
| 154 | subPacket = m_vp8Pipeline->GetSubPacket(DecodePacketId(m_vp8Pipeline, predicationSubPacketId)); |
| 155 | DecodePredicationPkt *predicationPacket = dynamic_cast<DecodePredicationPkt *>(subPacket); |
| 156 | DECODE_CHK_NULL(predicationPacket); |
| 157 | DECODE_CHK_STATUS(predicationPacket->Execute(cmdBuffer)); |
| 158 | |
| 159 | return MOS_STATUS_SUCCESS; |
| 160 | } |
| 161 | |
| 162 | MOS_STATUS Vp8DecodePkt::MiFlush(MOS_COMMAND_BUFFER &cmdBuffer) |
| 163 | { |
| 164 | DECODE_FUNC_CALL(); |
| 165 | |
| 166 | auto &par = m_miItf->GETPAR_MI_FLUSH_DW(); |
| 167 | MOS_ZeroMemory(&par, sizeof(par)); |
| 168 | DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FLUSH_DW(&cmdBuffer)); |
| 169 | |
| 170 | return MOS_STATUS_SUCCESS; |
| 171 | } |
| 172 | |
| 173 | MOS_STATUS Vp8DecodePkt::Completed(void *mfxStatus, void *rcsStatus, void *statusReport) |
| 174 | { |
| 175 | DECODE_FUNC_CALL(); |
| 176 | |
| 177 | DECODE_CHK_NULL(mfxStatus); |
| 178 | DECODE_CHK_NULL(statusReport); |
| 179 | |
| 180 | DecodeStatusMfx * decodeStatusMfx = (DecodeStatusMfx *)mfxStatus; |
| 181 | DecodeStatusReportData *statusReportData = (DecodeStatusReportData *)statusReport; |
| 182 | |
| 183 | auto hcpInterface = m_hwInterface->GetHcpInterfaceNext(); |
| 184 | if (hcpInterface != nullptr) |
| 185 | { |
| 186 | if ((decodeStatusMfx->m_mmioErrorStatusReg & hcpInterface->GetHcpCabacErrorFlagsMask()) != 0) |
| 187 | { |
| 188 | statusReportData->codecStatus = CODECHAL_STATUS_ERROR; |
| 189 | statusReportData->numMbsAffected = (decodeStatusMfx->m_mmioMBCountReg & 0xFFFC0000) >> 18; |
| 190 | } |
| 191 | |
| 192 | statusReportData->frameCrc = decodeStatusMfx->m_mmioFrameCrcReg; |
| 193 | } |
| 194 | |
| 195 | DECODE_VERBOSEMESSAGE("Index = %d", statusReportData->currDecodedPic.FrameIdx); |
| 196 | DECODE_VERBOSEMESSAGE("FrameCrc = 0x%x", statusReportData->frameCrc); |
| 197 | |
| 198 | return MOS_STATUS_SUCCESS; |
| 199 | } |
| 200 | |
| 201 | uint32_t Vp8DecodePkt::CalculateCommandBufferSize() |
| 202 | { |
| 203 | uint32_t commandBufferSize = 0; |
| 204 | commandBufferSize = m_pictureStatesSize + m_sliceStatesSize; |
| 205 | |
| 206 | return (commandBufferSize + COMMAND_BUFFER_RESERVED_SPACE); |
| 207 | } |
| 208 | |
| 209 | uint32_t Vp8DecodePkt::CalculatePatchListSize() |
| 210 | { |
| 211 | if (!m_osInterface->bUsesPatchList) |
| 212 | { |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | uint32_t requestedPatchListSize = 0; |
| 217 | requestedPatchListSize = m_picturePatchListSize + m_slicePatchListSize; |
| 218 | |
| 219 | return requestedPatchListSize; |
| 220 | } |
| 221 | |
| 222 | MOS_STATUS Vp8DecodePkt::CalculateCommandSize(uint32_t& commandBufferSize, uint32_t& requestedPatchListSize) |
| 223 | { |
| 224 | commandBufferSize = CalculateCommandBufferSize(); |
| 225 | requestedPatchListSize = CalculatePatchListSize(); |
| 226 | |
| 227 | return MOS_STATUS_SUCCESS; |
| 228 | } |
| 229 | |
| 230 | MOS_STATUS Vp8DecodePkt::ReadMfxStatus(MediaStatusReport* statusReport, MOS_COMMAND_BUFFER& cmdBuffer) |
| 231 | { |
| 232 | DECODE_FUNC_CALL(); |
| 233 | |
| 234 | DECODE_CHK_NULL(statusReport); |
| 235 | |
| 236 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 237 | MOS_RESOURCE* osResource = nullptr; |
| 238 | uint32_t offset = 0; |
| 239 | |
| 240 | auto &par = m_miItf->GETPAR_MI_STORE_REGISTER_MEM(); |
| 241 | MOS_ZeroMemory(&par, sizeof(par)); |
| 242 | |
| 243 | DECODE_CHK_NULL(m_hwInterface->GetVdencInterfaceNext()); |
| 244 | auto mmioRegisters = m_hwInterface->GetVdencInterfaceNext()->GetMmioRegisters(MHW_VDBOX_NODE_1); |
| 245 | |
| 246 | DECODE_CHK_STATUS(statusReport->GetAddress(decode::DecodeStatusReportType::DecErrorStatusOffset, osResource, offset)); |
| 247 | |
| 248 | par.presStoreBuffer = osResource; |
| 249 | par.dwOffset = offset; |
| 250 | par.dwRegister = mmioRegisters->mfxErrorFlagsRegOffset; |
| 251 | DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer)); |
| 252 | |
| 253 | |
| 254 | DECODE_CHK_STATUS(statusReport->GetAddress(decode::DecodeStatusReportType::DecMBCountOffset, osResource, offset)); |
| 255 | |
| 256 | par.presStoreBuffer = osResource; |
| 257 | par.dwOffset = offset; |
| 258 | par.dwRegister = mmioRegisters->mfxMBCountRegOffset; |
| 259 | DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer)); |
| 260 | |
| 261 | return MOS_STATUS_SUCCESS; |
| 262 | } |
| 263 | |
| 264 | MOS_STATUS Vp8DecodePkt::StartStatusReport(uint32_t srType, MOS_COMMAND_BUFFER *cmdBuffer) |
| 265 | { |
| 266 | DECODE_FUNC_CALL(); |
| 267 | DECODE_CHK_NULL(cmdBuffer); |
| 268 | DECODE_CHK_STATUS(MediaPacket::StartStatusReportNext(srType, cmdBuffer)); |
| 269 | |
| 270 | SetPerfTag(CODECHAL_DECODE_MODE_VP8VLD, m_vp8BasicFeature->m_pictureCodingType); |
| 271 | MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance(); |
| 272 | DECODE_CHK_NULL(perfProfiler); |
| 273 | DECODE_CHK_STATUS(perfProfiler->AddPerfCollectStartCmd( |
| 274 | (void *)m_vp8Pipeline, m_osInterface, m_miItf, cmdBuffer)); |
| 275 | |
| 276 | return MOS_STATUS_SUCCESS; |
| 277 | } |
| 278 | |
| 279 | MOS_STATUS Vp8DecodePkt::EndStatusReport(uint32_t srType, MOS_COMMAND_BUFFER *cmdBuffer) |
| 280 | { |
| 281 | DECODE_FUNC_CALL(); |
| 282 | DECODE_CHK_NULL(cmdBuffer); |
| 283 | DECODE_CHK_STATUS(ReadMfxStatus(m_statusReport, *cmdBuffer)); |
| 284 | DECODE_CHK_STATUS(MediaPacket::EndStatusReportNext(srType, cmdBuffer)); |
| 285 | |
| 286 | MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance(); |
| 287 | DECODE_CHK_NULL(perfProfiler); |
| 288 | DECODE_CHK_STATUS(perfProfiler->AddPerfCollectEndCmd( |
| 289 | (void *)m_vp8Pipeline, m_osInterface, m_miItf, cmdBuffer)); |
| 290 | |
| 291 | // Add Mi flush here to ensure end status tag flushed to memory earlier than completed count |
| 292 | DECODE_CHK_STATUS(MiFlush(*cmdBuffer)); |
| 293 | |
| 294 | return MOS_STATUS_SUCCESS; |
| 295 | } |
| 296 | |
| 297 | } // namespace decode |