Debian Codegraph @

media_softlet/agnostic/common/codec/hal/dec/shared/pipeline/decode_pipeline.h

raw
1 /*
2 * Copyright (c) 2018-2025, 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_pipeline.h
24 //! \brief Defines the common interface for decode pipeline
25 //! \details The decode pipeline interface is further sub-divided by codec standard,
26 //! this file is for the base interface which is shared by all codecs.
27 //!
28 #ifndef __DECODE_PIPELINE_H__
29 #define __DECODE_PIPELINE_H__
30
31 #include "media_pipeline.h"
32
33 #include "codec_hw_next.h"
34 #include "codechal_debug.h"
35 #include "codec_def_decode.h"
36 #include "decode_allocator.h"
37 #include "decode_sub_pipeline_manager.h"
38 #include "decode_sub_packet_manager.h"
39 #include "decode_input_bitstream.h"
40 #include "decodecp_interface.h"
41 #include "decode_cp_bitstream.h"
42 #include "decode_mem_compression.h"
43 #include "decode_downsampling_feature.h"
44 #include "codechal_oca_debug.h"
45
46 namespace decode {
47
48 enum DecodePipeMode
49 {
50 decodePipeModeBegin = 0,
51 decodePipeModeProcess,
52 decodePipeModeEnd
53 };
54
55 struct DecodePipelineParams
56 {
57 CodechalDecodeParams *m_params = nullptr;
58 DecodePipeMode m_pipeMode = decodePipeModeBegin;
59 };
60
61 class DecodeSubPacket;
62 class DecodeSubPacketManager;
63
64 class DecodePipeline : public MediaPipeline
65 {
66 public:
67 //!
68 //! \brief DecodePipeline constructor
69 //! \param [in] hwInterface
70 //! Pointer to CodechalHwInterface
71 //! \param [in] debugInterface
72 //! Pointer to CodechalDebugInterface
73 //!
74 DecodePipeline(
75 CodechalHwInterfaceNext *hwInterface,
76 CodechalDebugInterface *debugInterface);
77
78 virtual ~DecodePipeline()
79 {
80 MOS_Delete(m_pCodechalOcaDumper);
81 };
82
83 //!
84 //! \brief Prepare interal parameters, should be invoked for each frame
85 //! \param [in] params
86 //! Pointer to the input parameters
87 //! \return MOS_STATUS
88 //! MOS_STATUS_SUCCESS if success, else fail reason
89 //!
90 virtual MOS_STATUS Prepare(void *params) override;
91
92 //!
93 //! \brief Indicates whether input bitstream is complete for current frame
94 //! \return bool
95 //! true for compelte, false for incompelte
96 //!
97 bool IsCompleteBitstream();
98
99 //!
100 //! \brief Help function to get sub packet
101 //!
102 //! \return Sub packet if success, else nullptr
103 //!
104 DecodeSubPacket* GetSubPacket(uint32_t subPacketId);
105
106 //!
107 //! \brief Get if SingleTaskPhaseSupported
108 //! \return bool
109 //! value of SingleTaskPhaseSupported
110 //!
111 bool IsSingleTaskPhaseSupported() { return m_singleTaskPhaseSupported; };
112
113 //!
114 //! \brief Get the resource allocator for decode
115 //! \return DecodeAllocator *
116 //! pointer of decode allocator
117 //!
118 DecodeAllocator *GetDecodeAllocator() const { return m_allocator; }
119
120 //!
121 //! \brief Get decode cp interface
122 //! \return DecodeCpInterface *
123 //! pointer of DecodeCpInterface
124 //!
125 DecodeCpInterface *GetDecodeCp() const { return m_decodecp; }
126
127 //!
128 //! \brief Get the debug interface
129 //! \return CodechalDebugInterface *
130 //! pointer of m_debugInterface
131 //!
132 CodechalDebugInterface *GetDebugInterface() const { return m_debugInterface; }
133
134 //!
135 //! \brief Get the HW interface
136 //! \return CodechalHwInterface *
137 //! pointer of m_hwInterface
138 //!
139 CodechalHwInterfaceNext *GetHwInterface() const { return m_hwInterface; }
140
141 //!
142 //! \brief Help function to get pipe number
143 //!
144 //! \return Pipe number
145 //!
146 virtual uint8_t GetPipeNum() { return m_scalability->GetPipeNumber(); }
147
148 //!
149 //! \brief Help function to get current pipe
150 //!
151 //! \return Pass index
152 //!
153 virtual uint8_t GetCurrentPipe() { return m_scalability->GetCurrentPipe(); }
154
155 //!
156 //! \brief Help function to check if current pipe is first pipe
157 //!
158 //! \return True if current pipe is first pipe, otherwise return false
159 //!
160 virtual bool IsFirstPipe()
161 {
162 return GetCurrentPipe() == 0 ? true : false;
163 }
164
165 //!
166 //! \brief Help function to check if current pipe is last pipe
167 //!
168 //! \return True if current pipe is last pipe, otherwise return false
169 //!
170 virtual bool IsLastPipe()
171 {
172 return GetCurrentPipe() == GetPipeNum() - 1 ? true : false;
173 }
174
175 //!
176 //! \brief Help function to get pass number
177 //!
178 //! \return Pass number
179 //!
180 virtual uint16_t GetPassNum() { return m_scalability->GetPassNumber(); }
181
182 //!
183 //! \brief Help function to get current pass
184 //!
185 //! \return Pass index
186 //!
187 virtual uint16_t GetCurrentPass() { return m_scalability->GetCurrentPass(); }
188
189 //!
190 //! \brief Help function to check if current PAK pass is first pass
191 //!
192 //! \return True if current PAK pass is first pass, otherwise return false
193 //!
194 virtual bool IsFirstPass()
195 {
196 return GetCurrentPass() == 0 ? true : false;
197 }
198
199 //!
200 //! \brief Help function to check if current PAK pass is last pass
201 //!
202 //! \return True if current PAK pass is last pass, otherwise return false
203 //!
204 virtual bool IsLastPass()
205 {
206 return GetCurrentPass() == GetPassNum() - 1 ? true : false;
207 }
208
209 //!
210 //! \brief Help function to get component state
211 //!
212 //! \return Point to component state
213 //!
214 virtual ComponentState *GetComponentState()
215 {
216 return m_scalability->GetComponentState();
217 }
218
219 //!
220 //! \brief Help function to check if phased submission mode
221 //!
222 //! \return True if phased submission mode, otherwise return false
223 //!
224 virtual bool IsPhasedSubmission()
225 {
226 return m_osInterface->phasedSubmission;
227 }
228
229 //!
230 //! \brief Help function to check if guc submission mode
231 //!
232 //! \return True if guc submission mode, otherwise return false
233 //!
234 virtual bool IsParallelSubmission()
235 {
236 return m_osInterface->bParallelSubmission;
237 }
238
239 #ifdef _DECODE_PROCESSING_SUPPORTED
240 //!
241 //! \brief Check if down sampling supported for current frame
242 //! \return Return if down sampling supported for current frame
243 //!
244 bool IsDownSamplingSupported();
245 #endif
246
247 //!
248 //! \brief Get dummy reference surface
249 //! \return Pointer of reference surface
250 //!
251 MOS_SURFACE* GetDummyReference();
252
253 //!
254 //! \brief Get dummy reference status
255 //! \return CODECHAL_DUMMY_REFERENCE_STATUS
256 //!
257 CODECHAL_DUMMY_REFERENCE_STATUS GetDummyReferenceStatus();
258
259 //!
260 //! \brief Set dummy reference status
261 //! \return void
262 //!
263 void SetDummyReferenceStatus(CODECHAL_DUMMY_REFERENCE_STATUS status);
264
265 //!
266 //! \brief Get mmc state
267 //! \return Pointer of mmc state
268 //!
269 DecodeMemComp *GetMmcState() { return m_mmcState; }
270
271 //!
272 //! \brief Get Wa table
273 //! \return Pointer of Wa table
274 //!
275 MEDIA_WA_TABLE *GetWaTable() { return m_waTable; }
276
277 //!
278 //! \brief Get Sku table
279 //! \return Pointer of SKU table
280 //!
281 MEDIA_FEATURE_TABLE *GetSkuTable() { return m_skuTable; }
282
283 DeclareDecodePacketId(hucCopyPacketId);
284 DeclareDecodePacketId(hucCpStreamOutPacketId);
285 DeclareDecodePacketId(predicationSubPacketId);
286 DeclareDecodePacketId(markerSubPacketId);
287 DeclareDecodePacketId(downSamplingSubPacketId);
288
289 //!
290 //! \brief Get decode context
291 //! \return decode context
292 //!
293 MOS_GPU_CONTEXT GetDecodeContext() { return m_decodeContext; }
294
295 //!
296 //! \brief Get decode context handle
297 //! \return decode context handle
298 //!
299 GPU_CONTEXT_HANDLE GetDecodeContextHandle() { return m_decodeContextHandle; }
300
301 //!
302 //! \brief Indicates whether current process pipe is first process pipe of current frame
303 //! \return bool
304 //! true for first process pipe, false for other process pipe
305 //!
306 bool IsFirstProcessPipe(const DecodePipelineParams &pipelineParams);
307
308 //!
309 //! \brief Gets oca dump interface.
310 //! \return CodechalOcaDumper
311 //! return oca debug interface
312 //!
313 CodechalOcaDumper *GetCodechalOcaDumper() { return m_pCodechalOcaDumper; }
314
315 //!
316 //! \brief Set decode short/long format during runtime.
317 //! \return MOS_STATUS
318 //! MOS_STATUS_SUCCESS if success, else fail reason
319 //!
320 virtual MOS_STATUS SetDecodeFormat(bool isShortFormat ){ return MOS_STATUS_UNIMPLEMENTED; };
321
322 //!
323 //! \brief CRC output enable. Returns false in release builds.
324 //! \return bool
325 //! true if enabled, else false
326 //!
327 bool GetMemDataAccessCrcOutputEnable()
328 {
329 #if (_DEBUG || _RELEASE_INTERNAL)
330 return m_memDataAccessCrcOutputEnable;
331 #else
332 return false;
333 #endif
334 }
335
336 #if (_DEBUG || _RELEASE_INTERNAL)
337 //!
338 //! \brief Read the CRC output enable regkey and update internal state.
339 //! Called from platform-specific debug packet ext Init() so that
340 //! CRC enable is only active on platforms that support it.
341 //!
342 void InitMemDataAccessCrcOutputEnable();
343
344 //!
345 //! \brief Get Vdbox command counter override value
346 //! \return uint32_t
347 //! command counter override value
348 //!
349 uint32_t GetVdboxCommandCounterOverride()
350 {
351 return m_vdboxCommandCounterOverride;
352 }
353 #endif
354
355 protected:
356 //!
357 //! \brief Initialize the decode pipeline
358 //! \param [in] settings
359 //! Pointer to the initialize settings
360 //! \return MOS_STATUS
361 //! MOS_STATUS_SUCCESS if success, else fail reason
362 //!
363 virtual MOS_STATUS Initialize(void *settings);
364
365 //!
366 //! \brief Uninitialize the decode pipeline
367 //! \return MOS_STATUS
368 //! MOS_STATUS_SUCCESS if success, else fail reason
369 //!
370 virtual MOS_STATUS Uninitialize();
371
372 //!
373 //! \brief User Feature Key Report
374 //! \return MOS_STATUS
375 //! MOS_STATUS_SUCCESS if success, else fail reason
376 //!
377 virtual MOS_STATUS UserFeatureReport() override;
378
379 //!
380 //! \brief Get the number of Vdbox
381 //! \return uint8_t
382 //! Return the number of Vdbox
383 //!
384 virtual uint8_t GetSystemVdboxNumber();
385
386 //!
387 //! \brief Create status report
388 //! \return MOS_STATUS
389 //! MOS_STATUS_SUCCESS if success, else fail reason
390 //!
391 virtual MOS_STATUS CreateStatusReport();
392
393 //!
394 //! \brief Finish the active packets execution
395 //! \return MOS_STATUS
396 //! MOS_STATUS_SUCCESS if success, else fail reason
397 //!
398 MOS_STATUS ExecuteActivePackets() override;
399
400 //!
401 //! \brief Create pre sub pipelines
402 //! \param [in] subPipelineManager
403 //! Point to subPipeline manager
404 //! \return MOS_STATUS
405 //! MOS_STATUS_SUCCESS if success, else fail reason
406 //!
407 virtual MOS_STATUS CreatePreSubPipeLines(DecodeSubPipelineManager &subPipelineManager);
408
409 //!
410 //! \brief Create Post sub pipelines
411 //! \param [in] subPipelineManager
412 //! Point to subPipeline manager
413 //! \return MOS_STATUS
414 //! MOS_STATUS_SUCCESS if success, else fail reason
415 //!
416 virtual MOS_STATUS CreatePostSubPipeLines(DecodeSubPipelineManager &subPipelineManager);
417
418 //!
419 //! \brief Create sub packets
420 //! \param [in] subPacketManager
421 //! Sub packet manager
422 //! \param [in] codecSettings
423 //! Codechal settings
424 //! \return MOS_STATUS
425 //! MOS_STATUS_SUCCESS if success, else fail reason
426 //!
427 virtual MOS_STATUS CreateSubPackets(DecodeSubPacketManager& subPacketManager, CodechalSetting &codecSettings);
428 //!
429 //! \brief Declare Regkeys in the scope of decode
430 //! \return MOS_STATUS
431 //! MOS_STATUS_SUCCESS if success, else fail reason
432 virtual MOS_STATUS InitUserSetting(MediaUserSettingSharedPtr userSettingPtr) override;
433
434 #if USE_CODECHAL_DEBUG_TOOL
435 #ifdef _DECODE_PROCESSING_SUPPORTED
436 MOS_STATUS DumpDownSamplingParams(DecodeDownSamplingFeature &downSamplingParams);
437 #endif
438
439 //!
440 //! \brief Dump Bitstream
441 //! \param [in] pBitstream
442 //! Bitstream Resource
443 //! \param [in] size
444 //! Bitstream Size
445 //! \param [in] offset
446 //! Bitstream Offset
447 //! \param [in] attrName
448 //! Bitstream Name
449 //! \return MOS_STATUS
450 //! MOS_STATUS_SUCCESS if success, else fail reason
451 //!
452 virtual MOS_STATUS DumpBitstream(PMOS_RESOURCE pBitstream, uint32_t size, uint32_t offset, const char* attrName = nullptr);
453
454 //!
455 //! \brief Add delay for dump render targets
456 //! \return MOS_STATUS
457 //! MOS_STATUS_SUCCESS if success, else fail reason
458 //!
459 virtual MOS_STATUS DelayForDumpOutput();
460
461 //!
462 //! \brief Dump render targets
463 //! \param [in] reportData
464 //! Decode report data
465 //! \return MOS_STATUS
466 //! MOS_STATUS_SUCCESS if success, else fail reason
467 //!
468 virtual MOS_STATUS DumpOutput(const DecodeStatusReportData& reportData);
469 #endif
470
471 #if (_DEBUG || _RELEASE_INTERNAL)
472 //!
473 //! \brief User feature key report for Vdbox IDs
474 //! \param [in] status
475 //! Status report from HW
476 //! \return MOS_STATUS
477 //! MOS_STATUS_SUCCESS if success, else fail reason
478 //!
479 MOS_STATUS ReportVdboxIds(const DecodeStatusMfx& status);
480
481 //!
482 //! \brief Earlier stop for hw error status
483 //! \param [in] status
484 //! Status report from HW
485 //! \return MOS_STATUS
486 //! MOS_STATUS_SUCCESS if success, else fail reason
487 //!
488 virtual MOS_STATUS HwStatusCheck(const DecodeStatusMfx &status)
489 {
490 return MOS_STATUS_SUCCESS;
491 }
492
493 #ifdef _DECODE_PROCESSING_SUPPORTED
494 //!
495 //! \brief User feature key report for Sfc Linear Usage Status
496 //! \param [in] status
497 //! Status report from HW
498 //! \return MOS_STATUS
499 //! MOS_STATUS_SUCCESS if success, else fail reason
500 //!
501 MOS_STATUS ReportSfcLinearSurfaceUsage(const DecodeStatusReportData &reportData);
502 #endif
503
504 //!
505 //! \brief Internal status check after each frame
506 //! \return MOS_STATUS
507 //! MOS_STATUS_SUCCESS if success, else fail reason
508 //!
509 virtual MOS_STATUS StatusCheck();
510 #endif
511
512 protected:
513 //!
514 //! \brief Create sub pipeline manager
515 //! \param [in] codecSettings
516 //! Point to codechal settings
517 //! \return MOS_STATUS
518 //! MOS_STATUS_SUCCESS if success, else fail reason
519 //!
520 MOS_STATUS CreateSubPipeLineManager(CodechalSetting* codecSettings);
521
522 //!
523 //! \brief Create sub packet manager
524 //! \param [in] codecSettings
525 //! Point to codechal settings
526 //! \return MOS_STATUS
527 //! MOS_STATUS_SUCCESS if success, else fail reason
528 //!
529 MOS_STATUS CreateSubPacketManager(CodechalSetting* codecSettings);
530
531 friend class DecodeSubPipelineManager;
532 friend class DecodeStreamOut;
533
534 CodechalHwInterfaceNext *m_hwInterface = nullptr; //!< Codechal HwInterface
535 CodechalOcaDumper *m_pCodechalOcaDumper = nullptr;
536 CodechalDebugInterface* m_debugInterface = nullptr; //!< Debug Interface
537 MediaTask * m_task = nullptr; //!< Command task
538
539 DecodeSubPipelineManager* m_preSubPipeline = nullptr; //!< PreExecution sub pipeline
540 DecodeSubPipelineManager *m_postSubPipeline = nullptr; //!< PostExecution sub pipeline
541 DecodeSubPacketManager* m_subPacketManager = nullptr; //!< Sub packet manager
542
543 DecodePipeMode m_pipeMode = decodePipeModeBegin; //!< pipe mode
544
545 DecodeAllocator * m_allocator = nullptr; //!< Resource allocator
546 DecodeInputBitstream* m_bitstream = nullptr; //!< Decode input bitstream
547 DecodeMemComp* m_mmcState = nullptr; //!< Decode mmc state
548 DecodeCpInterface* m_decodecp = nullptr; //!< DecodeCp interface
549 DecodeStreamOut* m_streamout = nullptr; //!< Decode input bitstream
550
551 uint8_t m_numVdbox = 0; //!< Number of Vdbox
552
553 bool m_singleTaskPhaseSupported = true; //!< Indicates whether sumbit packets in single phase
554
555 MOS_GPU_CONTEXT m_decodeContext = MOS_GPU_CONTEXT_INVALID_HANDLE; //!< decode context inuse
556 GPU_CONTEXT_HANDLE m_decodeContextHandle = MOS_GPU_CONTEXT_INVALID_HANDLE; //!< handle of decode context inuse
557
558 #if (_DEBUG || _RELEASE_INTERNAL)
559 uint32_t m_statusCheckCount = 0; //!< count for status check
560 uint32_t m_delayMiliseconds = 0; //!< miliseconds delay after each frame
561 uint32_t m_memDataAccessCrcOutputEnable = 0; //!< mem data access crc output enable
562 uint32_t m_vdboxCommandCounterOverride = 0; //!< vdbox command counter override
563 #endif
564
565 PMOS_SURFACE m_tempOutputSurf = nullptr;
566
567 MEDIA_CLASS_DEFINE_END(decode__DecodePipeline)
568 };
569
570 }//decode
571
572 #endif // !__DECODE_PIPELINE_H__