Debian Codegraph @

media_softlet/agnostic/common/codec/hal/dec/av1/pipeline/decode_av1_pipeline.cpp

raw
1 /*
2 * Copyright (c) 2019-2024, 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_pipeline.cpp
24 //! \brief Defines the interface for av1 decode pipeline
25 //!
26 #include "decode_av1_pipeline.h"
27 #include "decode_utils.h"
28 #include "codechal_setting.h"
29 #include "decode_av1_feature_manager.h"
30 #include "decode_huc_packet_creator_base.h"
31 #include "media_debug_fast_dump.h"
32 #if (_DEBUG || _RELEASE_INTERNAL)
33 #include "decode_av1_debug_packet.h"
34 #endif
35
36 namespace decode {
37
38 Av1Pipeline::Av1Pipeline(
39 CodechalHwInterfaceNext* hwInterface,
40 CodechalDebugInterface *debugInterface)
41 : DecodePipeline(hwInterface, debugInterface)
42 {
43 MOS_STATUS m_status = InitUserSetting(m_userSettingPtr);
44 }
45
46 MOS_STATUS Av1Pipeline::Initialize(void *settings)
47 {
48 DECODE_FUNC_CALL();
49 DECODE_CHK_STATUS(DecodePipeline::Initialize(settings));
50
51 // Create basic GPU context
52 if (m_osInterface->pfnIsMismatchOrderProgrammingSupported())
53 {
54 DecodeScalabilityPars scalPars;
55 MOS_ZeroMemory(&scalPars, sizeof(scalPars));
56 DECODE_CHK_STATUS(m_mediaContext->SwitchContext(VdboxDecodeFunc, &scalPars, &m_scalability));
57 m_decodeContext = m_osInterface->pfnGetGpuContext(m_osInterface);
58 m_decodeContextHandle = m_osInterface->CurrentGpuContextHandle;
59 }
60
61 HucPacketCreatorBase *hucPktCreator = dynamic_cast<HucPacketCreatorBase *>(this);
62 DECODE_CHK_NULL(hucPktCreator);
63
64 auto *codecSettings = (CodechalSetting*)settings;
65 DECODE_CHK_NULL(codecSettings);
66
67 bool forceTileBasedDecodingRead = 0;
68 #if (_DEBUG || _RELEASE_INTERNAL)
69 forceTileBasedDecodingRead = ReadUserFeature(m_userSettingPtr, "Force Av1 Tile Based Decode", MediaUserSetting::Group::Sequence).Get<bool>();
70 #endif
71 m_forceTileBasedDecoding = forceTileBasedDecodingRead;
72
73 return MOS_STATUS_SUCCESS;
74 }
75
76 MOS_STATUS Av1Pipeline::Prepare(void *params)
77 {
78 DECODE_FUNC_CALL();
79 DECODE_CHK_NULL(params);
80
81 auto basicFeature = dynamic_cast<Av1BasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
82 DECODE_CHK_NULL(basicFeature);
83 DECODE_CHK_STATUS(DecodePipeline::Prepare(params));
84
85 return MOS_STATUS_SUCCESS;
86 }
87
88 MOS_STATUS Av1Pipeline::Uninitialize()
89 {
90 DECODE_FUNC_CALL();
91
92 return DecodePipeline::Uninitialize();
93 }
94
95 MOS_STATUS Av1Pipeline::UserFeatureReport()
96 {
97 DECODE_FUNC_CALL();
98 DECODE_CHK_STATUS(DecodePipeline::UserFeatureReport());
99 #if (_DEBUG || _RELEASE_INTERNAL)
100 WriteUserFeature(__MEDIA_USER_FEATURE_VALUE_APOGEIOS_AV1D_ENABLE_ID, 1, m_osInterface->pOsContext);
101 #endif
102 return MOS_STATUS_SUCCESS;
103 }
104
105 MOS_STATUS Av1Pipeline::ActivateDecodePackets()
106 {
107 DECODE_FUNC_CALL();
108
109 bool immediateSubmit = true;
110
111 if (m_isFirstTileInFrm)
112 {
113 m_isFirstTileInFrm = false;
114 }
115
116 if (!m_forceTileBasedDecoding)
117 {
118 immediateSubmit = false;
119 }
120
121 for (uint16_t curPass = 0; curPass < GetPassNum(); curPass++)
122 {
123 DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(this, av1DecodePacketId), immediateSubmit, curPass, 0));
124 }
125
126 return MOS_STATUS_SUCCESS;
127 }
128
129 bool Av1Pipeline::FrameBasedDecodingInUse()
130 {
131 auto basicFeature = dynamic_cast<Av1BasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
132
133 bool isframeBasedDecodingUsed = false;
134
135 if (basicFeature != nullptr)
136 {
137 isframeBasedDecodingUsed = ((basicFeature->m_av1PicParams->m_loopRestorationFlags.m_fields.m_yframeRestorationType > 0) &
138 ((basicFeature->m_av1PicParams->m_loopRestorationFlags.m_fields.m_cbframeRestorationType |
139 basicFeature->m_av1PicParams->m_loopRestorationFlags.m_fields.m_crframeRestorationType) > 0) &&
140 basicFeature->m_av1PicParams->m_picInfoFlags.m_fields.m_useSuperres && MEDIA_IS_WA(GetWaTable(), Wa_1409820462)
141 || !m_forceTileBasedDecoding);
142 }
143 return isframeBasedDecodingUsed;
144 }
145
146 MOS_STATUS Av1Pipeline::CreateFeatureManager()
147 {
148 DECODE_FUNC_CALL();
149 m_featureManager = MOS_New(DecodeAv1FeatureManager, m_allocator, m_hwInterface, m_osInterface);
150 DECODE_CHK_NULL(m_featureManager);
151 return MOS_STATUS_SUCCESS;
152 }
153
154 MOS_STATUS Av1Pipeline::CreateSubPackets(DecodeSubPacketManager &subPacketManager, CodechalSetting &codecSettings)
155 {
156 DECODE_FUNC_CALL();
157
158 DECODE_CHK_STATUS(DecodePipeline::CreateSubPackets(subPacketManager, codecSettings));
159
160 return MOS_STATUS_SUCCESS;
161 }
162
163 Av1Pipeline::Av1DecodeMode Av1Pipeline::GetDecodeMode()
164 {
165 return m_decodeMode;
166 }
167
168 #if USE_CODECHAL_DEBUG_TOOL
169 MOS_STATUS Av1Pipeline::DumpParams(Av1BasicFeature &basicFeature)
170 {
171 m_debugInterface->m_frameType = basicFeature.m_av1PicParams->m_picInfoFlags.m_fields.m_frameType ? P_TYPE : I_TYPE;
172 m_debugInterface->m_bufferDumpFrameNum = basicFeature.m_frameNum;
173
174 DECODE_CHK_STATUS(DumpPicParams(basicFeature.m_av1PicParams));
175 DECODE_CHK_STATUS(DumpTileParams(basicFeature.m_av1TileParams, basicFeature.m_tileCoding.m_numTiles));
176 DECODE_CHK_STATUS(DumpBitstream(&basicFeature.m_resDataBuffer.OsResource, basicFeature.m_dataSize, 0));
177
178 return MOS_STATUS_SUCCESS;
179 }
180
181 MOS_STATUS Av1Pipeline::DumpPicParams(CodecAv1PicParams *picParams)
182 {
183 CODECHAL_DEBUG_FUNCTION_ENTER;
184
185 if (picParams == nullptr)
186 {
187 return MOS_STATUS_SUCCESS;
188 }
189
190 if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrPicParams))
191 {
192 const char *fileName = m_debugInterface->CreateFileName(
193 "DEC",
194 CodechalDbgBufferType::bufPicParams,
195 CodechalDbgExtType::txt);
196
197 if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump))
198 {
199 MediaDebugFastDump::Dump(
200 (uint8_t *)picParams,
201 fileName,
202 sizeof(CodecAv1PicParams),
203 0,
204 MediaDebugSerializer<CodecAv1PicParams>());
205 }
206 else
207 {
208 DumpDecodeAv1PicParams(picParams, fileName);
209 }
210 }
211
212 return MOS_STATUS_SUCCESS;
213 }
214
215 MOS_STATUS Av1Pipeline::DumpTileParams(CodecAv1TileParams *tileParams, uint32_t tileNum)
216 {
217 CODECHAL_DEBUG_FUNCTION_ENTER;
218
219 if (tileParams == nullptr)
220 {
221 return MOS_STATUS_SUCCESS;
222 }
223
224 if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSlcParams))
225 {
226 const char *fileName = m_debugInterface->CreateFileName(
227 "DEC",
228 "TileParams",
229 CodechalDbgExtType::txt);
230
231 if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump))
232 {
233 MediaDebugFastDump::Dump(
234 (uint8_t *)tileParams,
235 fileName,
236 sizeof(CodecAv1TileParams) * tileNum,
237 0,
238 MediaDebugSerializer<CodecAv1TileParams>());
239 }
240 else
241 {
242 DumpDecodeAv1TileParams(tileParams, tileNum, fileName);
243 }
244 }
245
246 return MOS_STATUS_SUCCESS;
247 }
248 #endif
249
250 }