| 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_jpeg_packet.cpp |
| 24 |
//! \brief Defines the interface for jpeg decode packet. |
| 25 |
//! |
| 26 |
|
| 27 |
#include "decode_jpeg_packet.h" |
| 28 |
#include "decode_utils.h" |
| 29 |
#include "decode_marker_packet.h" |
| 30 |
#include "decode_status_report_defs.h" |
| 31 |
#include "decode_predication_packet.h" |
| 32 |
#include "codechal_debug.h" |
| 33 |
|
| 34 |
namespace decode { |
| 35 |
|
| 36 |
MOS_STATUS JpegDecodePkt::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_jpegPipeline); |
| 43 |
DECODE_CHK_NULL(m_osInterface); |
| 44 |
|
| 45 |
DECODE_CHK_STATUS(CmdPacket::Init()); |
| 46 |
|
| 47 |
m_jpegBasicFeature = dynamic_cast<JpegBasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature)); |
| 48 |
DECODE_CHK_NULL(m_jpegBasicFeature); |
| 49 |
|
| 50 |
m_allocator = m_jpegPipeline->GetDecodeAllocator(); |
| 51 |
DECODE_CHK_NULL(m_allocator); |
| 52 |
|
| 53 |
DECODE_CHK_STATUS(m_statusReport->RegistObserver(this)); |
| 54 |
|
| 55 |
DecodeSubPacket* subPacket = m_jpegPipeline->GetSubPacket(DecodePacketId(m_jpegPipeline, jpegPictureSubPacketId)); |
| 56 |
m_picturePkt = dynamic_cast<JpegDecodePicPkt*>(subPacket); |
| 57 |
DECODE_CHK_NULL(m_picturePkt); |
| 58 |
DECODE_CHK_STATUS(m_picturePkt->CalculateCommandSize(m_pictureStatesSize, m_picturePatchListSize)); |
| 59 |
|
| 60 |
return MOS_STATUS_SUCCESS; |
| 61 |
} |
| 62 |
|
| 63 |
MOS_STATUS JpegDecodePkt::Prepare() |
| 64 |
{ |
| 65 |
DECODE_FUNC_CALL(); |
| 66 |
|
| 67 |
DECODE_CHK_NULL(m_jpegBasicFeature->m_jpegPicParams); |
| 68 |
m_jpegPicParams = m_jpegBasicFeature->m_jpegPicParams; |
| 69 |
|
| 70 |
return MOS_STATUS_SUCCESS; |
| 71 |
} |
| 72 |
|
| 73 |
MOS_STATUS JpegDecodePkt::Destroy() |
| 74 |
{ |
| 75 |
m_statusReport->UnregistObserver(this); |
| 76 |
|
| 77 |
return MOS_STATUS_SUCCESS; |
| 78 |
} |
| 79 |
|
| 80 |
void JpegDecodePkt::SetPerfTag(CODECHAL_MODE mode, uint16_t picCodingType) |
| 81 |
{ |
| 82 |
DECODE_FUNC_CALL(); |
| 83 |
|
| 84 |
uint16_t perfTag = ((mode << 4) & 0xF0) | (picCodingType & 0xF); |
| 85 |
m_osInterface->pfnIncPerfFrameID(m_osInterface); |
| 86 |
m_osInterface->pfnSetPerfTag(m_osInterface, perfTag); |
| 87 |
m_osInterface->pfnResetPerfBufferID(m_osInterface); |
| 88 |
} |
| 89 |
|
| 90 |
bool JpegDecodePkt::IsPrologRequired() |
| 91 |
{ |
| 92 |
return true; |
| 93 |
} |
| 94 |
|
| 95 |
MOS_STATUS JpegDecodePkt::AddForceWakeup(MOS_COMMAND_BUFFER& cmdBuffer) |
| 96 |
{ |
| 97 |
DECODE_FUNC_CALL(); |
| 98 |
// NativeFence sync BB may cause preemption and ring idle, so force wakeup after it |
| 99 |
DECODE_CHK_STATUS(AddNativeFenceSyncBBStartCmd(cmdBuffer)); |
| 100 |
|
| 101 |
auto &par = m_miItf->GETPAR_MI_FORCE_WAKEUP(); |
| 102 |
par = {}; |
| 103 |
par.bMFXPowerWellControl = true; |
| 104 |
par.bMFXPowerWellControlMask = true; |
| 105 |
par.bHEVCPowerWellControl = false; |
| 106 |
par.bHEVCPowerWellControlMask = true; |
| 107 |
|
| 108 |
DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FORCE_WAKEUP(&cmdBuffer)); |
| 109 |
|
| 110 |
return MOS_STATUS_SUCCESS; |
| 111 |
} |
| 112 |
|
| 113 |
MOS_STATUS JpegDecodePkt::SendPrologWithFrameTracking(MOS_COMMAND_BUFFER& cmdBuffer, bool frameTrackingRequested) |
| 114 |
{ |
| 115 |
DECODE_FUNC_CALL(); |
| 116 |
|
| 117 |
DecodeSubPacket* subPacket = m_jpegPipeline->GetSubPacket(DecodePacketId(m_jpegPipeline, markerSubPacketId)); |
| 118 |
DecodeMarkerPkt *makerPacket = dynamic_cast<DecodeMarkerPkt*>(subPacket); |
| 119 |
DECODE_CHK_NULL(makerPacket); |
| 120 |
DECODE_CHK_STATUS(makerPacket->Execute(cmdBuffer)); |
| 121 |
|
| 122 |
m_mmcState = m_jpegPipeline->GetMmcState(); |
| 123 |
bool isMmcEnabled = (m_mmcState != nullptr && m_mmcState->IsMmcEnabled()); |
| 124 |
if (isMmcEnabled) |
| 125 |
{ |
| 126 |
DECODE_CHK_STATUS(m_mmcState->SendPrologCmd(&cmdBuffer, false)); |
| 127 |
} |
| 128 |
|
| 129 |
MHW_GENERIC_PROLOG_PARAMS genericPrologParams; |
| 130 |
MOS_ZeroMemory(&genericPrologParams, sizeof(genericPrologParams)); |
| 131 |
genericPrologParams.pOsInterface = m_osInterface; |
| 132 |
genericPrologParams.pvMiInterface = nullptr; |
| 133 |
|
| 134 |
genericPrologParams.bMmcEnabled = isMmcEnabled; |
| 135 |
|
| 136 |
DECODE_CHK_STATUS(Mhw_SendGenericPrologCmdNext(&cmdBuffer, &genericPrologParams, m_miItf)); |
| 137 |
|
| 138 |
subPacket = m_jpegPipeline->GetSubPacket(DecodePacketId(m_jpegPipeline, predicationSubPacketId)); |
| 139 |
DecodePredicationPkt *predicationPacket = dynamic_cast<DecodePredicationPkt*>(subPacket); |
| 140 |
DECODE_CHK_NULL(predicationPacket); |
| 141 |
DECODE_CHK_STATUS(predicationPacket->Execute(cmdBuffer)); |
| 142 |
|
| 143 |
return MOS_STATUS_SUCCESS; |
| 144 |
} |
| 145 |
|
| 146 |
MOS_STATUS JpegDecodePkt::MiFlush(MOS_COMMAND_BUFFER & cmdBuffer) |
| 147 |
{ |
| 148 |
DECODE_FUNC_CALL(); |
| 149 |
|
| 150 |
auto &par = m_miItf->GETPAR_MI_FLUSH_DW(); |
| 151 |
par = {}; |
| 152 |
DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FLUSH_DW(&cmdBuffer)); |
| 153 |
|
| 154 |
return MOS_STATUS_SUCCESS; |
| 155 |
} |
| 156 |
|
| 157 |
MOS_STATUS JpegDecodePkt::Completed(void *mfxStatus, void *rcsStatus, void *statusReport) |
| 158 |
{ |
| 159 |
DECODE_FUNC_CALL(); |
| 160 |
|
| 161 |
DecodeStatusMfx *decodeStatusMfx = (DecodeStatusMfx *)mfxStatus; |
| 162 |
DecodeStatusReportData *statusReportData = (DecodeStatusReportData *)statusReport; |
| 163 |
auto mfxItf = std::static_pointer_cast<mhw::vdbox::mfx::Itf>(m_hwInterface->GetMfxInterfaceNext()); |
| 164 |
|
| 165 |
if (mfxItf && decodeStatusMfx && statusReportData) |
| 166 |
{ |
| 167 |
if ((decodeStatusMfx->m_mmioErrorStatusReg & mfxItf->GetMfxErrorFlagsMask()) != 0) |
| 168 |
{ |
| 169 |
statusReportData->codecStatus = CODECHAL_STATUS_ERROR; |
| 170 |
statusReportData->numMbsAffected = decodeStatusMfx->m_mmioMBCountReg & 0xFFFF; |
| 171 |
} |
| 172 |
DECODE_VERBOSEMESSAGE("Current Frame Index = %d", statusReportData->currDecodedPic.FrameIdx); |
| 173 |
} |
| 174 |
|
| 175 |
return MOS_STATUS_SUCCESS; |
| 176 |
} |
| 177 |
|
| 178 |
MOS_STATUS JpegDecodePkt::CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize) |
| 179 |
{ |
| 180 |
commandBufferSize = CalculateCommandBufferSize(); |
| 181 |
requestedPatchListSize = CalculatePatchListSize(); |
| 182 |
|
| 183 |
return MOS_STATUS_SUCCESS; |
| 184 |
} |
| 185 |
|
| 186 |
uint32_t JpegDecodePkt::CalculateCommandBufferSize() |
| 187 |
{ |
| 188 |
// slice/macroblock level commands are put into 2nd level BB. |
| 189 |
return (m_pictureStatesSize + COMMAND_BUFFER_RESERVED_SPACE); |
| 190 |
} |
| 191 |
|
| 192 |
uint32_t JpegDecodePkt::CalculatePatchListSize() |
| 193 |
{ |
| 194 |
if (!m_osInterface->bUsesPatchList) |
| 195 |
{ |
| 196 |
return 0; |
| 197 |
} |
| 198 |
|
| 199 |
return m_picturePatchListSize; |
| 200 |
} |
| 201 |
|
| 202 |
MOS_STATUS JpegDecodePkt::ReadMfxStatus(MediaStatusReport* statusReport, MOS_COMMAND_BUFFER& cmdBuffer) |
| 203 |
{ |
| 204 |
DECODE_FUNC_CALL(); |
| 205 |
|
| 206 |
DECODE_CHK_NULL(statusReport); |
| 207 |
|
| 208 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 209 |
MOS_RESOURCE* osResource = nullptr; |
| 210 |
uint32_t offset = 0; |
| 211 |
|
| 212 |
auto &par = m_miItf->GETPAR_MI_STORE_REGISTER_MEM(); |
| 213 |
par = {}; |
| 214 |
|
| 215 |
DECODE_CHK_NULL(m_hwInterface->GetVdencInterfaceNext()); |
| 216 |
auto mmioRegisters = m_hwInterface->GetVdencInterfaceNext()->GetMmioRegisters(MHW_VDBOX_NODE_1); |
| 217 |
|
| 218 |
DECODE_CHK_STATUS(statusReport->GetAddress(decode::DecodeStatusReportType::DecErrorStatusOffset, osResource, offset)); |
| 219 |
par.presStoreBuffer = osResource; |
| 220 |
par.dwOffset = offset; |
| 221 |
par.dwRegister = mmioRegisters->mfxErrorFlagsRegOffset; |
| 222 |
|
| 223 |
DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer)); |
| 224 |
|
| 225 |
DECODE_CHK_STATUS(statusReport->GetAddress(decode::DecodeStatusReportType::DecMBCountOffset, osResource, offset)); |
| 226 |
par.presStoreBuffer = osResource; |
| 227 |
par.dwOffset = offset; |
| 228 |
par.dwRegister = mmioRegisters->mfxMBCountRegOffset; |
| 229 |
|
| 230 |
DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer)); |
| 231 |
|
| 232 |
return MOS_STATUS_SUCCESS; |
| 233 |
} |
| 234 |
|
| 235 |
MOS_STATUS JpegDecodePkt::StartStatusReport(uint32_t srType, MOS_COMMAND_BUFFER* cmdBuffer) |
| 236 |
{ |
| 237 |
DECODE_FUNC_CALL(); |
| 238 |
|
| 239 |
DECODE_CHK_STATUS(MediaPacket::StartStatusReportNext(srType, cmdBuffer)); |
| 240 |
|
| 241 |
// no frame type for Jpeg decode, use I as default value here |
| 242 |
SetPerfTag(CODECHAL_DECODE_MODE_JPEG, I_TYPE); |
| 243 |
|
| 244 |
MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance(); |
| 245 |
DECODE_CHK_NULL(perfProfiler); |
| 246 |
DECODE_CHK_STATUS(perfProfiler->AddPerfCollectStartCmd( |
| 247 |
(void*)m_jpegPipeline, m_osInterface, m_miItf, cmdBuffer)); |
| 248 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 249 |
if (m_statusReport && m_statusReport->IsVdboxIdReportEnabled()) |
| 250 |
{ |
| 251 |
StoreEngineId(cmdBuffer, decode::DecodeStatusReportType::CsEngineIdOffset_0); |
| 252 |
} |
| 253 |
#endif |
| 254 |
return MOS_STATUS_SUCCESS; |
| 255 |
} |
| 256 |
|
| 257 |
MOS_STATUS JpegDecodePkt::EndStatusReport(uint32_t srType, MOS_COMMAND_BUFFER* cmdBuffer) |
| 258 |
{ |
| 259 |
DECODE_FUNC_CALL(); |
| 260 |
|
| 261 |
DECODE_CHK_NULL(cmdBuffer); |
| 262 |
DECODE_CHK_STATUS(ReadMfxStatus(m_statusReport, *cmdBuffer)); |
| 263 |
DECODE_CHK_STATUS(MediaPacket::EndStatusReportNext(srType, cmdBuffer)); |
| 264 |
|
| 265 |
MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance(); |
| 266 |
DECODE_CHK_NULL(perfProfiler); |
| 267 |
DECODE_CHK_STATUS(perfProfiler->AddPerfCollectEndCmd( |
| 268 |
(void*)m_jpegPipeline, m_osInterface, m_miItf, cmdBuffer)); |
| 269 |
|
| 270 |
DECODE_CHK_STATUS(MiFlush(*cmdBuffer)); |
| 271 |
|
| 272 |
return MOS_STATUS_SUCCESS; |
| 273 |
} |
| 274 |
|
| 275 |
} |