Debian Codegraph @

media_softlet/agnostic/common/shared/media_debug_interface.h

raw
1 /*
2 * Copyright (c) 2020-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 media_debug_interface.h
24 //! \brief Defines the debug interface shared by all of Media.
25 //! \details The debug interface dumps output from Media based on input config file.
26 //!
27 #ifndef __MEDIA_DEBUG_INTERFACE_H__
28 #define __MEDIA_DEBUG_INTERFACE_H__
29
30 #if ((_DEBUG || _RELEASE_INTERNAL))
31 #define USE_MEDIA_DEBUG_TOOL 1
32 #define MEDIA_DEBUG_TOOL(expr) expr;
33
34 #include "mhw_utilities.h"
35 #include "mhw_state_heap.h"
36 #include "mhw_cp_interface.h"
37 #include "media_debug_config_manager.h"
38 #include "media_debug_utils.h"
39 #include "media_copy_wrapper.h"
40 #include <sstream>
41 #include <fstream>
42 #include <functional>
43
44 using GoldenReferences = std::vector<std::vector<uint32_t>>;
45 class MediaDebugInterface
46 {
47 public:
48 MediaDebugInterface();
49 virtual ~MediaDebugInterface();
50
51 MOS_STATUS InitDumpLocation();
52
53 MOS_STATUS SetOutputFilePath();
54
55 virtual MOS_STATUS DumpUncompressedYUVSurface(
56 PMOS_SURFACE surface);
57
58 MOS_STATUS DumpMosSpecificResourceInfoToOfs(
59 PMOS_RESOURCE pOsResource,
60 std::ofstream &ofs);
61
62 MOS_STATUS DumpBufferInHexDwords(
63 uint8_t *data,
64 uint32_t size);
65
66 virtual MOS_STATUS DumpBltOutput(
67 PMOS_SURFACE surface,
68 const char * attrName);
69
70 MOS_STATUS DeleteCfgLinkNode(uint32_t frameIdx);
71
72 virtual MOS_STATUS InitCRCTable(uint32_t crcTable[256]);
73
74 virtual uint32_t CalculateCRC(
75 const void *buf,
76 size_t len,
77 uint32_t initial=0 );
78
79 virtual MOS_STATUS CaptureGoldenReference(uint8_t *buf, uint32_t size, uint32_t hwCrcValue=0);
80
81 virtual MOS_STATUS DumpGoldenReference();
82
83 virtual MOS_STATUS LoadGoldenReference();
84
85 MOS_STATUS SetSWCrcMode(bool swCrc);
86
87 MOS_STATUS SubmitDummyWorkload(MOS_COMMAND_BUFFER *pcmdBuffer, int32_t bNullRendering);
88
89 MOS_STATUS LockResource(uint32_t *semaData, PMOS_RESOURCE reSemaphore);
90
91 MOS_STATUS DumpToFile(const GoldenReferences &goldenReferences);
92
93 bool IsHwDebugHooksEnable() { return m_enableHwDebugHooks; }
94
95 void PackGoldenReferences(std::initializer_list<std::vector<uint32_t>> goldenReferences);
96
97 MOS_STATUS FillSemaResource(std::vector<uint32_t *> &vResource, std::vector<uint32_t> &data);
98
99 MOS_STATUS LockSemaResource(std::vector<uint32_t *> &vSemaData, std::vector<MOS_RESOURCE> &vResource);
100
101 int32_t GetStopFrameNumber() { return m_stopFrameNumber; }
102
103 std::vector<uint32_t> GetCrcGoldenReference() {return m_crcGoldenReference; }
104 std::string m_ddiFileName;
105 std::string m_outputFilePath;
106 std::string m_crcGoldenRefFileName;
107
108 MOS_SURFACE m_temp2DSurfForCopy = {};
109 PMOS_INTERFACE m_osInterface = nullptr;
110 MhwCpInterface *m_cpInterface = nullptr;
111 void *m_miInterface = nullptr;
112
113 MediaDbgFunction m_mediafunction = MEDIA_FUNCTION_DEFAULT;
114 uint32_t m_scaledBottomFieldOffset = 0;
115 uint16_t m_frameType = 0;
116 uint32_t m_sliceId = 0; // used for constructing debug file name
117 char m_fileName[MOS_MAX_PATH_LENGTH + 1];
118 char m_path[MOS_MAX_PATH_LENGTH + 1];
119 bool m_secondField = false;
120 bool m_hybridPakP1 = false;
121 bool m_hybridVp8EncodeBrcEnable = false;
122 bool m_hybridVp9EncodeEnable = false;
123 bool m_vdboxContextCreated = false;
124 bool m_enableHwDebugHooks = false;
125 bool m_goldenReferenceExist = false;
126 bool m_swCRC = false;
127 uint16_t m_preIndex = 0;
128 uint16_t m_refIndex = 0;
129 size_t m_DumpInputNum = 0;
130 size_t m_bufferDumpFrameNum = 0;
131 uint32_t m_decodeSurfDumpFrameNum = 0;
132 uint32_t m_streamId = 0;
133 uint32_t m_crcTable[256] ={0};
134 int32_t m_stopFrameNumber = -1;
135 std::vector<uint32_t> m_crcGoldenReference = {};
136 GoldenReferences m_goldenReferences = {};
137 uint32_t* m_semaData = nullptr;
138 MediaUserSettingSharedPtr m_userSettingPtr = nullptr;
139
140 protected:
141 MOS_STATUS ReAllocateSurface(
142 PMOS_SURFACE pSurface,
143 PMOS_SURFACE pSrcSurf,
144 PCCHAR pSurfaceName,
145 MOS_GFXRES_TYPE DefaultResType,
146 bool useLinearResource = false);
147
148 MOS_STATUS CopySurfaceData_Vdbox(
149 uint32_t dwDataSize,
150 PMOS_RESOURCE presSourceSurface,
151 PMOS_RESOURCE presCopiedSurface);
152
153 MOS_STATUS DumpBufferInBinary(
154 uint8_t *data,
155 uint32_t size);
156
157 MOS_STATUS LoadBufferInBinary(
158 uint8_t *data,
159 uint32_t size);
160
161 MOS_STATUS Dump2DBufferInBinary(
162 uint8_t *data,
163 uint32_t width,
164 uint32_t height,
165 uint32_t pitch);
166
167 virtual MOS_STATUS InitializeUserSetting() { return MOS_STATUS_SUCCESS; };
168
169 virtual std::string SetOutputPathKey() = 0;
170 virtual std::string InitDefaultOutput() = 0;
171
172 std::string m_outputFileName;
173 MediaDebugConfigMgr *m_configMgr = nullptr;
174
175 MEDIA_CLASS_DEFINE_END(MediaDebugInterface)
176 };
177
178 #else
179 #define USE_MEDIA_DEBUG_TOOL 0
180 #define MEDIA_DEBUG_TOOL(expr) ;
181
182 #endif // (_DEBUG || _RELEASE_INTERNAL)
183 #endif /* __MEDIA_DEBUG_INTERFACE_H__ */