Debian Codegraph @

media_softlet/agnostic/common/codec/hal/dec/hevc/packet/decode_hevc_packet.cpp

raw
1 /*
2 * Copyright (c) 2022-2023, 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_hevc_packet.cpp
24 //! \brief Defines the interface for hevc decode packet
25 //!
26 #include "decode_hevc_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_nullhw_proxy_test_packet.h"
32 #include "decode_hevc_debug_packet.h"
33 #endif
34 namespace decode {
35
36 MOS_STATUS HevcDecodePkt::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_hevcPipeline);
43 DECODE_CHK_NULL(m_osInterface);
44
45 DECODE_CHK_STATUS(CmdPacket::Init());
46
47 m_hevcBasicFeature = dynamic_cast<HevcBasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
48 DECODE_CHK_NULL(m_hevcBasicFeature);
49
50 m_allocator = m_hevcPipeline->GetDecodeAllocator();
51 DECODE_CHK_NULL(m_allocator);
52
53 #if (_DEBUG || _RELEASE_INTERNAL)
54 if (m_osInterface->bNullHwIsEnabled)
55 {
56 auto nullhwProxy = DecodeNullHWProxyTestPkt::Instance();
57 DECODE_CHK_NULL(nullhwProxy);
58 nullhwProxy->Init(m_hevcPipeline, m_osInterface);
59 }
60 #endif
61
62 #if (_DEBUG || _RELEASE_INTERNAL)
63 // Initialize debug packet
64 DecodeSubPacket* subPacket = m_hevcPipeline->GetSubPacket(
65 DecodePacketId(m_hevcPipeline, hevcDebugSubPacketId));
66 m_debugPkt = dynamic_cast<HevcDecodeDebugPkt*>(subPacket);
67 if (m_debugPkt != nullptr)
68 {
69 DECODE_CHK_STATUS(m_debugPkt->Init());
70 }
71 #endif
72
73 return MOS_STATUS_SUCCESS;
74 }
75
76 MOS_STATUS HevcDecodePkt::Destroy()
77 {
78 #if (_DEBUG || _RELEASE_INTERNAL)
79 if (m_osInterface->bNullHwIsEnabled)
80 {
81 auto nullhwProxy = DecodeNullHWProxyTestPkt::Instance();
82 DECODE_CHK_NULL(nullhwProxy);
83 DECODE_CHK_STATUS(nullhwProxy->Destory());
84 }
85 #endif
86
87 #if (_DEBUG || _RELEASE_INTERNAL)
88 // Destroy debug packet
89 if (m_debugPkt != nullptr)
90 {
91 DECODE_CHK_STATUS(m_debugPkt->Destroy());
92 }
93 #endif
94
95 return MOS_STATUS_SUCCESS;
96 }
97
98 MOS_STATUS HevcDecodePkt::Prepare()
99 {
100 DECODE_FUNC_CALL();
101
102 m_phase = static_cast<DecodePhase *>(m_hevcPipeline->GetComponentState());
103 DECODE_CHK_NULL(m_phase);
104
105 DECODE_CHK_NULL(m_hevcBasicFeature);
106 DECODE_CHK_NULL(m_hevcBasicFeature->m_hevcPicParams);
107 m_hevcPicParams = m_hevcBasicFeature->m_hevcPicParams;
108
109 return MOS_STATUS_SUCCESS;
110 }
111
112 void HevcDecodePkt::SetPerfTag(CODECHAL_MODE mode, uint16_t picCodingType)
113 {
114 DECODE_FUNC_CALL();
115
116 uint16_t perfTag = ((mode << 4) & 0xF0) | (picCodingType & 0xF);
117 m_osInterface->pfnIncPerfFrameID(m_osInterface);
118 m_osInterface->pfnSetPerfTag(m_osInterface, perfTag);
119 m_osInterface->pfnResetPerfBufferID(m_osInterface);
120 }
121
122 MOS_STATUS HevcDecodePkt::AddForceWakeup(MOS_COMMAND_BUFFER& cmdBuffer)
123 {
124 DECODE_FUNC_CALL();
125 // NativeFence sync BB may cause preemption and ring idle, so force wakeup after it
126 DECODE_CHK_STATUS(AddNativeFenceSyncBBStartCmd(cmdBuffer));
127
128 auto &par = m_miItf->GETPAR_MI_FORCE_WAKEUP();
129 par = {};
130 par.bMFXPowerWellControl = false;
131 par.bMFXPowerWellControlMask = true;
132 par.bHEVCPowerWellControl = true;
133 par.bHEVCPowerWellControlMask = true;
134
135 DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FORCE_WAKEUP(&cmdBuffer));
136
137 return MOS_STATUS_SUCCESS;
138 }
139
140 MOS_STATUS HevcDecodePkt::SendPrologWithFrameTracking(MOS_COMMAND_BUFFER& cmdBuffer, bool frameTrackingRequested)
141 {
142 DecodeSubPacket* subPacket = m_hevcPipeline->GetSubPacket(DecodePacketId(m_hevcPipeline, markerSubPacketId));
143 DecodeMarkerPkt *makerPacket = dynamic_cast<DecodeMarkerPkt*>(subPacket);
144 DECODE_CHK_NULL(makerPacket);
145 DECODE_CHK_STATUS(makerPacket->Execute(cmdBuffer));
146
147 DecodeMemComp *mmcState = m_hevcPipeline->GetMmcState();
148 bool isMmcEnabled = (mmcState != nullptr && mmcState->IsMmcEnabled());
149 if (isMmcEnabled)
150 {
151 DECODE_CHK_STATUS(mmcState->SendPrologCmd(&cmdBuffer, false));
152 }
153
154 MHW_GENERIC_PROLOG_PARAMS genericPrologParams;
155 MOS_ZeroMemory(&genericPrologParams, sizeof(genericPrologParams));
156 genericPrologParams.pOsInterface = m_osInterface;
157 genericPrologParams.pvMiInterface = nullptr;
158
159 genericPrologParams.bMmcEnabled = isMmcEnabled;
160
161 DECODE_CHK_STATUS(Mhw_SendGenericPrologCmdNext(&cmdBuffer, &genericPrologParams, m_miItf));
162
163 subPacket = m_hevcPipeline->GetSubPacket(DecodePacketId(m_hevcPipeline, predicationSubPacketId));
164 DecodePredicationPkt *predicationPacket = dynamic_cast<DecodePredicationPkt*>(subPacket);
165 DECODE_CHK_NULL(predicationPacket);
166 DECODE_CHK_STATUS(predicationPacket->Execute(cmdBuffer));
167
168 return MOS_STATUS_SUCCESS;
169 }
170
171 MOS_STATUS HevcDecodePkt::MiFlush(MOS_COMMAND_BUFFER & cmdBuffer)
172 {
173 DECODE_FUNC_CALL();
174
175 auto &par = m_miItf->GETPAR_MI_FLUSH_DW();
176 par = {};
177 DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FLUSH_DW(&cmdBuffer));
178
179 return MOS_STATUS_SUCCESS;
180 }
181
182 MOS_STATUS HevcDecodePkt::Completed(void *mfxStatus, void *rcsStatus, void *statusReport)
183 {
184 DECODE_FUNC_CALL();
185
186 DECODE_CHK_NULL(mfxStatus);
187 DECODE_CHK_NULL(statusReport);
188
189 DecodeStatusMfx * decodeStatusMfx = (DecodeStatusMfx *)mfxStatus;
190 DecodeStatusReportData *statusReportData = (DecodeStatusReportData *)statusReport;
191
192 std::shared_ptr<mhw::vdbox::hcp::Itf> hcpItf = std::static_pointer_cast<mhw::vdbox::hcp::Itf>(m_hwInterface->GetHcpInterfaceNext());
193 if (hcpItf != nullptr)
194 {
195 if ((decodeStatusMfx->m_mmioErrorStatusReg & hcpItf->GetHcpCabacErrorFlagsMask()) != 0)
196 {
197 statusReportData->codecStatus = CODECHAL_STATUS_ERROR;
198 statusReportData->numMbsAffected = (decodeStatusMfx->m_mmioMBCountReg & 0xFFFC0000) >> 18;
199 }
200
201 statusReportData->frameCrc = decodeStatusMfx->m_mmioFrameCrcReg;
202 }
203
204 DECODE_VERBOSEMESSAGE("Index = %d", statusReportData->currDecodedPic.FrameIdx);
205 DECODE_VERBOSEMESSAGE("FrameCrc = 0x%x", statusReportData->frameCrc);
206
207 #if (_DEBUG || _RELEASE_INTERNAL)
208 // Call debug packet completion handling for HCP debug functionality
209 if (m_debugPkt != nullptr)
210 {
211 DECODE_CHK_STATUS(m_debugPkt->Completed(mfxStatus));
212 }
213 #endif
214
215 return MOS_STATUS_SUCCESS;
216 }
217
218 MOS_STATUS HevcDecodePkt::ReadVdboxId(MOS_COMMAND_BUFFER &cmdBuffer)
219 {
220 DECODE_FUNC_CALL();
221 DECODE_CHK_NULL(m_phase);
222 DECODE_CHK_NULL(m_statusReport);
223
224 uint8_t curPipe = m_phase->GetPipe();
225 DECODE_CHK_COND(curPipe >= csInstanceIdMax, "Invalid pipe index.");
226 uint32_t csEngineIdOffsetIdx = decode::DecodeStatusReportType::CsEngineIdOffset_0 + curPipe;
227
228 auto &par = m_miItf->GETPAR_MI_STORE_REGISTER_MEM();
229 par = {};
230
231 auto mmioRegistersHcp = m_hwInterface->GetHcpInterfaceNext()->GetMmioRegisters(MHW_VDBOX_NODE_1);
232
233 MOS_RESOURCE* osResource = nullptr;
234 uint32_t offset = 0;
235 DECODE_CHK_STATUS(m_statusReport->GetAddress(csEngineIdOffsetIdx, osResource, offset));
236 par.presStoreBuffer = osResource;
237 par.dwOffset = offset;
238 par.dwRegister = mmioRegistersHcp->csEngineIdOffset;
239
240 DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer));
241
242 return MOS_STATUS_SUCCESS;
243 }
244
245 MOS_STATUS HevcDecodePkt::ReadHcpStatus(MediaStatusReport* statusReport, MOS_COMMAND_BUFFER& cmdBuffer)
246 {
247 DECODE_FUNC_CALL();
248 DECODE_CHK_NULL(statusReport);
249
250 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
251 MOS_RESOURCE *osResource = nullptr;
252 uint32_t offset = 0;
253
254 auto &par = m_miItf->GETPAR_MI_STORE_REGISTER_MEM();
255
256 par = {};
257
258 auto mmioRegistersHcp = m_hwInterface->GetHcpInterfaceNext()->GetMmioRegisters(MHW_VDBOX_NODE_1);
259
260 DECODE_CHK_STATUS(statusReport->GetAddress(decode::DecodeStatusReportType::DecErrorStatusOffset, osResource, offset));
261 par.presStoreBuffer = osResource;
262 par.dwOffset = offset;
263 par.dwRegister = mmioRegistersHcp->hcpCabacStatusRegOffset;
264
265 DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer));
266
267 // Skip CRC MMIO register read when CRC output is enabled
268 // When CRC debug mode is enabled, debug packet Execute() handles CRC data collection via HCP_MEM_DATA_ACCESS
269 if (!m_hevcPipeline->GetMemDataAccessCrcOutputEnable())
270 {
271 DECODE_CHK_STATUS(statusReport->GetAddress(decode::DecodeStatusReportType::DecFrameCrcOffset, osResource, offset));
272 par.presStoreBuffer = osResource;
273 par.dwOffset = offset;
274 par.dwRegister = mmioRegistersHcp->hcpFrameCrcRegOffset;
275
276 DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer));
277 }
278
279 DECODE_CHK_STATUS(statusReport->GetAddress(decode::DecodeStatusReportType::DecMBCountOffset, osResource, offset));
280 par.presStoreBuffer = osResource;
281 par.dwOffset = offset;
282 par.dwRegister = mmioRegistersHcp->hcpDecStatusRegOffset;
283
284 DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_STORE_REGISTER_MEM(&cmdBuffer));
285
286 return eStatus;
287 }
288
289 MOS_STATUS HevcDecodePkt::StartStatusReport(uint32_t srType, MOS_COMMAND_BUFFER* cmdBuffer)
290 {
291 DECODE_FUNC_CALL();
292 DECODE_CHK_NULL(cmdBuffer);
293 DECODE_CHK_NULL(m_hevcPipeline);
294 DECODE_CHK_NULL(m_osInterface);
295
296 SetPerfTag(CODECHAL_DECODE_MODE_HEVCVLD, m_hevcBasicFeature->m_pictureCodingType);
297
298 MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance();
299 DECODE_CHK_NULL(perfProfiler);
300 DECODE_CHK_STATUS(perfProfiler->AddPerfCollectStartCmd((void *)m_hevcPipeline, m_osInterface, m_miItf, cmdBuffer));
301
302 #if (_DEBUG || _RELEASE_INTERNAL)
303 if (m_statusReport && m_statusReport->IsVdboxIdReportEnabled())
304 {
305 DECODE_CHK_NULL(m_phase);
306 StoreEngineId(cmdBuffer, decode::DecodeStatusReportType::CsEngineIdOffset_0, m_phase->GetPipe());
307 }
308 if (m_osInterface->bNullHwIsEnabled)
309 {
310 DecodeNullHWProxyTestPkt *nullhwProxy = DecodeNullHWProxyTestPkt::Instance();
311 DECODE_CHK_NULL(nullhwProxy);
312 nullhwProxy->AddNullHwProxyCmd(m_hevcPipeline, m_osInterface, cmdBuffer);
313 }
314 // Add command counter commands for debug
315 if (m_debugPkt != nullptr)
316 {
317 DECODE_CHK_STATUS(m_debugPkt->AddCommandCounterCmds(*cmdBuffer, m_statusReport));
318 }
319 #endif
320
321 DECODE_CHK_STATUS(MediaPacket::StartStatusReportNext(srType, cmdBuffer));
322
323 return MOS_STATUS_SUCCESS;
324 }
325
326 MOS_STATUS HevcDecodePkt::EndStatusReport(uint32_t srType, MOS_COMMAND_BUFFER* cmdBuffer)
327 {
328 DECODE_FUNC_CALL();
329 DECODE_CHK_NULL(cmdBuffer);
330 #if (_DEBUG || _RELEASE_INTERNAL)
331 // Execute debug packet BEFORE ReadHcpStatus when CRC output is enabled
332 // This ensures CRC data and MI_FLUSH commands from debug packet are inserted before status reads
333 if (m_debugPkt != nullptr)
334 {
335 DECODE_CHK_STATUS(m_debugPkt->Execute(*cmdBuffer, m_statusReport));
336 }
337 #endif
338 DECODE_CHK_STATUS(ReadHcpStatus(m_statusReport, *cmdBuffer));
339 DECODE_CHK_STATUS(MediaPacket::EndStatusReportNext(srType, cmdBuffer));
340
341 MediaPerfProfiler *perfProfiler = MediaPerfProfiler::Instance();
342 DECODE_CHK_NULL(perfProfiler);
343 DECODE_CHK_STATUS(perfProfiler->AddPerfCollectEndCmd((void*)m_hevcPipeline, m_osInterface, m_miItf, cmdBuffer));
344
345 // Add Mi flush here to ensure end status tag flushed to memory earlier than completed count
346 DECODE_CHK_STATUS(MiFlush(*cmdBuffer));
347
348 return MOS_STATUS_SUCCESS;
349 }
350
351 MOS_STATUS HevcDecodePkt::EnsureAllCommandsExecuted(MOS_COMMAND_BUFFER &cmdBuffer)
352 {
353 DECODE_FUNC_CALL();
354
355 // Send MI_FLUSH command
356 auto &par = m_miItf->GETPAR_MI_FLUSH_DW();
357 par = {};
358
359 // Add Video Pipeline Cache Invalidate when CRC output is enabled
360 if (m_hevcPipeline && m_hevcPipeline->GetMemDataAccessCrcOutputEnable())
361 {
362 par.bVideoPipelineCacheInvalidate = true;
363 }
364
365 DECODE_CHK_NULL(m_hevcPipeline);
366 auto *skuTable = m_hevcPipeline->GetSkuTable();
367 if (skuTable && MEDIA_IS_SKU(skuTable, FtrEnablePPCFlush))
368 {
369 // Add PPC fulsh
370 par.bEnablePPCFlush = true;
371 }
372 DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FLUSH_DW(&cmdBuffer));
373
374 return MOS_STATUS_SUCCESS;
375 }
376
377 #if USE_CODECHAL_DEBUG_TOOL
378 MOS_STATUS HevcDecodePkt::DumpSecondaryCommandBuffer(MOS_COMMAND_BUFFER &cmdBuffer)
379 {
380 DECODE_ASSERT(m_phase != nullptr);
381 CodechalDebugInterface *debugInterface = m_hevcPipeline->GetDebugInterface();
382 DECODE_CHK_NULL(debugInterface);
383 std::string cmdName = "DEC_secondary_" + std::to_string(m_phase->GetCmdBufIndex());
384 DECODE_CHK_STATUS(debugInterface->DumpCmdBuffer(
385 &cmdBuffer, CODECHAL_NUM_MEDIA_STATES, cmdName.c_str()));
386
387 return MOS_STATUS_SUCCESS;
388 }
389 #endif
390
391 }