Debian Codegraph @

media_softlet/agnostic/common/codec/hal/codechal_debug.h

raw
1 /*
2 * Copyright (c) 2011-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 codechal_debug.h
24 //! \brief Defines the debug interface shared by codec only.
25 //! \details The debug interface dumps output from Media based on in input config file.
26 //!
27 #ifndef __CODEC_DEBUG_H__
28 #define __CODEC_DEBUG_H__
29
30 #include "media_debug_interface.h"
31 #include "codec_hw_next.h"
32 #include "encode_status_report.h"
33 #include "codechal_event_debug.h"
34 #include "codec_def_decode_avc.h"
35 #include "codec_def_decode_av1.h"
36 #include "codec_def_decode_jpeg.h"
37 #include "codec_def_decode_mpeg2.h"
38 #include "codec_def_decode_vp8.h"
39
40 static uint32_t DecodeFrameIndex = 0;
41 static uint32_t DecodeOutputIndex = 0;
42
43 #if USE_MEDIA_DEBUG_TOOL
44
45 #define USE_CODECHAL_DEBUG_TOOL 1
46 #define CODECHAL_DEBUG_TOOL(expr) expr;
47
48 typedef struct _CODECHAL_DBG_CFG CODECHAL_DBG_CFG, *PCODECHAL_DBG_CFG;
49
50 namespace CodechalDbgFieldType = MediaDbgFieldType;
51 namespace CodechalDbgExtType = MediaDbgExtType;
52 namespace CodechalDbgSurfaceType = MediaDbgSurfaceType;
53 namespace CodechalDbgBufferType = MediaDbgBufferType;
54 namespace CodechalDbgAttr = MediaDbgAttr;
55
56 #define __MEDIA_USER_FEATURE_VALUE_DECODE_SFC_RGBFORMAT_OUTPUT_DEBUG "Decode SFC RGB Format Output"
57 #define __MEDIA_USER_FEATURE_VALUE_DECODE_SFC_LINEAR_OUTPUT_DEBUG "Decode SFC Linear Output Debug"
58 #define __MEDIA_USER_FEATURE_ENABLE_HW_DEBUG_HOOKS_DEBUG "Enable Media Debug Hooks"
59 #define __MEDIA_USER_FEATURE_VALUE_CODECHAL_FRAME_NUMBER_TO_STOP_DEBUG "Decode Stop To Frame"
60 #define __MEDIA_USER_FEATURE_VALUE_CODECHAL_ENABLE_SW_CRC_DEBUG "Enable SW CRC"
61 //------------------------------------------------------------------------------
62 // Macros specific to MOS_CODEC_SUBCOMP_DEBUG sub-comp
63 //------------------------------------------------------------------------------
64 #define CODECHAL_DEBUG_ASSERT(_expr) \
65 MOS_ASSERT(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _expr)
66
67 #define CODECHAL_DEBUG_ASSERTMESSAGE(_message, ...) \
68 MOS_ASSERTMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _message, ##__VA_ARGS__)
69
70 #define CODECHAL_DEBUG_WARNINGMESSAGE(_message, ...) \
71 MOS_WARNINGMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _message, ##__VA_ARGS__)
72
73 #define CODECHAL_DEBUG_NORMALMESSAGE(_message, ...) \
74 MOS_NORMALMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _message, ##__VA_ARGS__)
75
76 #define CODECHAL_DEBUG_VERBOSEMESSAGE(_message, ...) \
77 MOS_VERBOSEMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _message, ##__VA_ARGS__)
78
79 #define CODECHAL_DEBUG_FUNCTION_ENTER \
80 MOS_FUNCTION_ENTER(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG)
81
82 #define CODECHAL_DEBUG_CHK_STATUS(_stmt) \
83 MOS_CHK_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _stmt)
84
85 #define CODECHAL_DEBUG_CHK_STATUS_MESSAGE(_stmt, _message, ...) \
86 MOS_CHK_STATUS_MESSAGE_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _stmt, _message, ##__VA_ARGS__)
87
88 #define CODECHAL_DEBUG_CHK_NULL(_ptr) \
89 MOS_CHK_NULL_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _ptr)
90
91 #define CODECHAL_DEBUG_CHK_NULL_NO_STATUS(_ptr) \
92 MOS_CHK_NULL_NO_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DEBUG, _ptr)
93
94 enum CodechalHucRegionDumpType
95 {
96 hucRegionDumpDefault = 0,
97 hucRegionDumpInit = 1,
98 hucRegionDumpUpdate = 2,
99 hucRegionDumpLAUpdate = 3,
100 hucRegionDumpRegionLocked = 4,
101 hucRegionDumpCmdInitializer = 5,
102 hucRegionDumpPakIntegrate = 6,
103 hucRegionDumpHpu = 7,
104 hucRegionDumpBackAnnotation = 8,
105 hucRegionDumpHpuSuperFrame = 9
106 };
107
108 typedef struct _CODECHAL_ME_OUTPUT_PARAMS
109 {
110 PMOS_SURFACE psMeMvBuffer;
111 PMOS_SURFACE psMeBrcDistortionBuffer;
112 PMOS_SURFACE psMeDistortionBuffer;
113 PMOS_RESOURCE pResVdenStreamInBuffer;
114 bool b16xMeInUse;
115 bool b32xMeInUse;
116 bool bVdencStreamInInUse;
117 } CODECHAL_ME_OUTPUT_PARAMS, *PCODECHAL_ME_OUTPUT_PARAMS;
118
119 std::ostream &operator<<(std::ostream &oss, const CODEC_AVC_PIC_PARAMS &cr);
120 std::ostream &operator<<(std::ostream &oss, const CODEC_AVC_SF_SLICE_PARAMS &cr);
121 std::ostream &operator<<(std::ostream &oss, const CODEC_AVC_SLICE_PARAMS &cr);
122 std::ostream &operator<<(std::ostream &oss, const CODEC_AVC_IQ_MATRIX_PARAMS &cr);
123 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_PIC_PARAMS &cr);
124 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_EXT_PIC_PARAMS &cr);
125 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_SCC_PIC_PARAMS &cr);
126 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_SF_SLICE_PARAMS &cr);
127 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_SLICE_PARAMS &cr);
128 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_EXT_SLICE_PARAMS &cr);
129 std::ostream &operator<<(std::ostream &oss, const CODECHAL_HEVC_IQ_MATRIX_PARAMS &cr);
130 std::ostream &operator<<(std::ostream &oss, const CODEC_HEVC_SUBSET_PARAMS &cr);
131 std::ostream &operator<<(std::ostream &oss, const CODEC_VP9_PIC_PARAMS &cr);
132 std::ostream &operator<<(std::ostream &oss, const CODEC_VP9_SLICE_PARAMS &cr);
133 std::ostream &operator<<(std::ostream &oss, const CODEC_VP9_SEGMENT_PARAMS &cr);
134 std::ostream &operator<<(std::ostream &oss, const CodecAv1PicParams &cr);
135 std::ostream &operator<<(std::ostream &oss, const CodecAv1TileParams &cr);
136 std::ostream &operator<<(std::ostream &oss, const CodecDecodeJpegPicParams &cr);
137 std::ostream &operator<<(std::ostream &oss, const CodecDecodeJpegScanParameter &cr);
138 std::ostream &operator<<(std::ostream &oss, const CODECHAL_DECODE_JPEG_HUFFMAN_TABLE &cr);
139 std::ostream &operator<<(std::ostream &oss, const CodecJpegQuantMatrix &cr);
140 std::ostream &operator<<(std::ostream &oss, const CodecDecodeMpeg2PicParams &cr);
141 std::ostream &operator<<(std::ostream &oss, const CodecDecodeMpeg2SliceParams &cr);
142 std::ostream &operator<<(std::ostream &oss, const CodecDecodeMpeg2MbParams &cr);
143 std::ostream &operator<<(std::ostream &oss, const CodecMpeg2IqMatrix &cr);
144 std::ostream &operator<<(std::ostream &oss, const CODEC_VP8_PIC_PARAMS &cr);
145 std::ostream &operator<<(std::ostream &oss, const CODEC_VP8_SLICE_PARAMS &cr);
146 std::ostream &operator<<(std::ostream &oss, const CODEC_VP8_IQ_MATRIX_PARAMS &cr);
147
148 void DumpDecodeAvcPicParams(PCODEC_AVC_PIC_PARAMS picParams, std::string fileName);
149 void DumpDecodeAvcSliceParams(PCODEC_AVC_SLICE_PARAMS sliceParams, uint32_t numSlices, std::string fileName, bool shortFormatInUse);
150 void DumpDecodeAvcIQParams(PCODEC_AVC_IQ_MATRIX_PARAMS iqParams, std::string fileName);
151 void DumpDecodeHevcPicParams(PCODEC_HEVC_PIC_PARAMS picParams, std::string fileName);
152 void DumpDecodeHevcExtPicParams(PCODEC_HEVC_EXT_PIC_PARAMS extPicParams, std::string fileName);
153 void DumpDecodeHevcSccPicParams(PCODEC_HEVC_SCC_PIC_PARAMS sccPicParams, std::string fileName);
154 void DumpDecodeHevcSliceParams(PCODEC_HEVC_SLICE_PARAMS sliceParams, uint32_t numSlices, std::string fileName, bool shortFormatInUse);
155 void DumpDecodeHevcExtSliceParams(PCODEC_HEVC_EXT_SLICE_PARAMS extSliceParams, uint32_t numSlices, std::string fileName);
156 void DumpDecodeHevcIQParams(PCODECHAL_HEVC_IQ_MATRIX_PARAMS iqParams, std::string fileName);
157 void DumpDecodeHevcSubsetParams(PCODEC_HEVC_SUBSET_PARAMS subsetsParams, std::string fileName);
158 void DumpDecodeVp9PicParams(PCODEC_VP9_PIC_PARAMS picParams, std::string fileName);
159 void DumpDecodeVp9SliceParams(PCODEC_VP9_SLICE_PARAMS slcParams, std::string fileName);
160 void DumpDecodeVp9SegmentParams(PCODEC_VP9_SEGMENT_PARAMS segmentParams, std::string fileName);
161 void DumpDecodeAv1PicParams(CodecAv1PicParams *picParams, std::string fileName);
162 void DumpDecodeAv1TileParams(CodecAv1TileParams *tileParams, uint32_t tileNum, std::string fileName);
163 void DumpDecodeJpegPicParams(CodecDecodeJpegPicParams *picParams, std::string fileName);
164 void DumpDecodeJpegScanParams(CodecDecodeJpegScanParameter *scanParams, std::string fileName);
165 void DumpDecodeJpegHuffmanParams(PCODECHAL_DECODE_JPEG_HUFFMAN_TABLE huffmanTable, std::string fileName);
166 void DumpDecodeJpegIqParams(CodecJpegQuantMatrix *iqParams, std::string fileName);
167 void DumpDecodeMpeg2PicParams(CodecDecodeMpeg2PicParams *picParams, std::string fileName);
168 void DumpDecodeMpeg2SliceParams(CodecDecodeMpeg2SliceParams *sliceParams, uint32_t numSlices, std::string fileName);
169 void DumpDecodeMpeg2MbParams(CodecDecodeMpeg2MbParams *mbParams, uint32_t numMbs, std::string fileName);
170 void DumpDecodeMpeg2IqParams(CodecMpeg2IqMatrix *iqParams, std::string fileName);
171 void DumpDecodeVp8PicParams(PCODEC_VP8_PIC_PARAMS picParams, std::string fileName);
172 void DumpDecodeVp8SliceParams(PCODEC_VP8_SLICE_PARAMS sliceParams, std::string fileName);
173 void DumpDecodeVp8IqParams(PCODEC_VP8_IQ_MATRIX_PARAMS iqParams, std::string fileName);
174
175 class MediaDebugInterface;
176 class CodechalHwInterface;
177 class CodechalDebugInterface : public MediaDebugInterface
178 {
179 public:
180 CodechalDebugInterface();
181 virtual ~CodechalDebugInterface();
182
183 static CodechalDebugInterface* Create();
184
185 virtual MOS_STATUS Initialize(
186 CodechalHwInterface *hwInterface,
187 CODECHAL_FUNCTION codecFunction,
188 MediaCopyWrapper *mediaCopyWrapper = nullptr);
189
190 virtual MOS_STATUS Initialize(
191 CodechalHwInterfaceNext *hwInterface,
192 CODECHAL_FUNCTION codecFunction,
193 MediaCopyWrapper *mediaCopyWrapper = nullptr);
194
195 virtual MOS_STATUS DumpHucDmem(
196 PMOS_RESOURCE dmemResource,
197 uint32_t dmemSize,
198 uint32_t hucPassNum,
199 CodechalHucRegionDumpType dumpType);
200
201 virtual MOS_STATUS DumpHucRegion(
202 PMOS_RESOURCE region,
203 uint32_t regionOffset,
204 uint32_t regionSize,
205 uint32_t regionNum,
206 const char * regionName,
207 bool inputBuffer,
208 uint32_t hucPassNum,
209 CodechalHucRegionDumpType dumpType);
210
211 MOS_STATUS DetectCorruptionSw(std::vector<MOS_RESOURCE>& vResource, PMOS_RESOURCE frameCntRes, uint8_t *buf, uint32_t &size, uint32_t frameNum);
212
213 MOS_STATUS DetectCorruptionHw(void *hwInterface, PMOS_RESOURCE frameCntRes, uint32_t curIdx, uint32_t frameCrcOffset, std::vector<MOS_RESOURCE> &vStatusBuffer, PMOS_COMMAND_BUFFER pCmdBuffer, uint32_t frameNum);
214
215 MOS_STATUS StoreNumFrame(PMHW_MI_INTERFACE pMiInterface, PMOS_RESOURCE pResource, int32_t frameNum, PMOS_COMMAND_BUFFER pCmdBuffer);
216
217 MOS_STATUS DumpEncodeStatusReport(
218 const struct EncodeStatusReport *report);
219
220 MOS_STATUS DumpEncodeStatusReport(
221 const struct encode::EncodeStatusReportData *report);
222
223 void CheckGoldenReferenceExist();
224
225 MOS_STATUS DumpRgbDataOnYUVSurface(
226 PMOS_SURFACE surface,
227 const char *attrName,
228 const char *surfName,
229 CODECHAL_MEDIA_STATE_TYPE mediaState = CODECHAL_NUM_MEDIA_STATES,
230 uint32_t width_in = 0,
231 uint32_t height_in = 0);
232
233 MOS_STATUS DumpBltOutput(
234 PMOS_SURFACE surface,
235 const char *attrName) override;
236
237 virtual MOS_STATUS InitializeUserSetting() override;
238
239 bool DumpIsEnabled(
240 const char * attr,
241 CODECHAL_MEDIA_STATE_TYPE mediaState = CODECHAL_NUM_MEDIA_STATES);
242
243 MOS_STATUS SetFastDumpConfig(MediaCopyWrapper *mediaCopyWrapper);
244
245 const char *CreateFileName(
246 const char *funcName,
247 const char *bufType,
248 const char *extType);
249
250 MOS_STATUS DumpStringStream(
251 std::stringstream& ss,
252 const char* bufferName,
253 const char* attrName);
254
255 virtual MOS_STATUS DumpCmdBuffer(
256 PMOS_COMMAND_BUFFER cmdBuffer,
257 CODECHAL_MEDIA_STATE_TYPE mediaState,
258 const char * cmdName = nullptr);
259
260 MOS_STATUS Dump2ndLvlBatch(
261 PMHW_BATCH_BUFFER batchBuffer,
262 CODECHAL_MEDIA_STATE_TYPE mediaState,
263 const char * batchName = nullptr);
264
265 MOS_STATUS DumpCurbe(
266 CODECHAL_MEDIA_STATE_TYPE mediaState,
267 PMHW_KERNEL_STATE kernelState);
268
269 MOS_STATUS DumpMDFCurbe(
270 CODECHAL_MEDIA_STATE_TYPE mediaState,
271 uint8_t * curbeBuffer,
272 uint32_t curbeSize);
273
274 MOS_STATUS DumpKernelRegion(
275 CODECHAL_MEDIA_STATE_TYPE mediaState,
276 MHW_STATE_HEAP_TYPE stateHeapType,
277 PMHW_KERNEL_STATE kernelState);
278
279 MOS_STATUS DumpYUVSurfaceToBuffer(PMOS_SURFACE surface, uint8_t *buffer, uint32_t &size);
280
281 MOS_STATUS DumpYUVSurface(
282 PMOS_SURFACE surface,
283 const char * attrName,
284 const char * surfName,
285 CODECHAL_MEDIA_STATE_TYPE mediaState = CODECHAL_NUM_MEDIA_STATES,
286 uint32_t width_in = 0,
287 uint32_t height_in = 0);
288
289 virtual MOS_STATUS DumpBuffer(
290 PMOS_RESOURCE resource,
291 const char * attrName,
292 const char * bufferName,
293 uint32_t size,
294 uint32_t offset = 0,
295 CODECHAL_MEDIA_STATE_TYPE mediaState = CODECHAL_NUM_MEDIA_STATES);
296
297 virtual MOS_STATUS LoadBinaryToLockableBuffer(
298 PMOS_RESOURCE resource,
299 const char *attrName,
300 const char *bufferName,
301 uint32_t size,
302 uint32_t offset = 0,
303 CODECHAL_MEDIA_STATE_TYPE mediaState = CODECHAL_NUM_MEDIA_STATES);
304
305 MOS_STATUS DumpSurface(
306 PMOS_SURFACE surface,
307 const char * attrName,
308 const char * surfaceName,
309 CODECHAL_MEDIA_STATE_TYPE mediaState = CODECHAL_NUM_MEDIA_STATES);
310
311 MOS_STATUS DumpData(
312 void *data,
313 uint32_t size,
314 const char *attrName,
315 const char *bufferName);
316
317 MOS_STATUS DumpSurfaceInfo(
318 PMOS_SURFACE surface,
319 const char* surfaceName);
320
321 CodechalHwInterface *m_hwInterface = nullptr;
322 CodechalHwInterfaceNext *m_hwInterfaceNext = nullptr;
323 CODECHAL_FUNCTION m_codecFunction = CODECHAL_FUNCTION_INVALID;
324 PCODECHAL_DBG_CFG m_dbgCfgHead = nullptr;
325 CODEC_PICTURE m_currPic = {};
326
327 protected:
328 std::string SetOutputPathKey() override;
329 std::string InitDefaultOutput() override;
330 uint8_t *m_decodeOutputBuf = nullptr;
331 PLATFORM m_platform = {};
332
333 std::function<
334 MOS_STATUS(
335 PMOS_SURFACE surface,
336 const char *attrName,
337 const char *surfName,
338 CODECHAL_MEDIA_STATE_TYPE mediaState,
339 uint32_t width_in,
340 uint32_t height_in)>
341 m_dumpYUVSurface;
342
343 std::function<
344 MOS_STATUS(
345 PMOS_SURFACE surface,
346 const char *attrName,
347 const char *surfName,
348 CODECHAL_MEDIA_STATE_TYPE mediaState,
349 uint32_t width_in,
350 uint32_t height_in)>
351 m_dumpYUVSurfaceLegacy;
352
353 std::function<
354 MOS_STATUS(
355 PMOS_RESOURCE resource,
356 const char *attrName,
357 const char *bufferName,
358 uint32_t size,
359 uint32_t offset,
360 CODECHAL_MEDIA_STATE_TYPE mediaState)>
361 m_dumpBuffer;
362
363 std::function<
364 MOS_STATUS(
365 PMOS_RESOURCE resource,
366 const char *attrName,
367 const char *bufferName,
368 uint32_t size,
369 uint32_t offset,
370 CODECHAL_MEDIA_STATE_TYPE mediaState)>
371 m_dumpBufferLegacy;
372
373 private:
374 MOS_STATUS VDBypassCopyResource(PMOS_RESOURCE src, PMOS_RESOURCE dst);
375 MOS_STATUS AllocateLinearResource(
376 MOS_GFXRES_TYPE eType,
377 uint32_t dwWidth,
378 uint32_t dwHeight,
379 MOS_FORMAT eFormat,
380 PMOS_RESOURCE pResource,
381 bool bSystemMem = false,
382 bool bLockable = false) const;
383 MOS_STATUS FillResourceMemory(
384 MOS_RESOURCE &sResource,
385 uint32_t uiSize,
386 uint8_t ucValue);
387
388 MEDIA_CLASS_DEFINE_END(CodechalDebugInterface)
389 };
390 #else
391 #define USE_CODECHAL_DEBUG_TOOL 0
392 #define CODECHAL_DEBUG_TOOL(expr) ;
393
394 #endif // USE_MEDIA_DEBUG_TOOL
395 #endif /* __MEDIA_DEBUG_H__ */