xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/shared/media_debug_dumper.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2022, 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_dumper.h
24 //! \brief    Defines structures and functions of common dumpers for debugging
25 //!           This file contains the definition of structures and functions for
26 //!           surface dumper
27 //!
28 
29 #ifndef __MEDIA_DEBUG_DUMPER_H__
30 #define __MEDIA_DEBUG_DUMPER_H__
31 
32 #if (_DEBUG || _RELEASE_INTERNAL)
33 
34 #include "renderhal.h"
35 #include "mhw_vebox.h"
36 #include "mos_os.h"
37 #include "media_common_defs.h"
38 
39 #define USE_MEDIA_DEBUG_TOOL 1
40 #include "media_debug_utils.h"
41 
42 #if !defined(LINUX) && !defined(ANDROID)
43 #include "UmdStateSeparation.h"
44 #endif
45 
46 #define COMMON_DUMP_OUTPUT_FOLDER                           "\\Commondump\\"
47 
48 struct COMMON_SURF_DUMP_SURFACE_DEF
49 {
50     uint32_t   dwOffset;                                    //!< Offset from start of the plane
51     uint32_t   dwHeight;                                    //!< Height in rows
52     uint32_t   dwWidth;                                     //!< Width in bytes
53     uint32_t   dwPitch;                                     //!< Pitch in bytes
54 };
55 
56 enum COMMON_SURF_DUMP_LOCATION
57 {
58     COMMON_DUMP_TYPE_PRE_ALL,
59     COMMON_DUMP_TYPE_PRE_DNDI,
60     COMMON_DUMP_TYPE_POST_DNDI,
61     COMMON_DUMP_TYPE_PRE_COMP,
62     COMMON_DUMP_TYPE_POST_COMP,
63     COMMON_DUMP_TYPE_PRE_MEMDECOMP,
64     COMMON_DUMP_TYPE_POST_MEMDECOMP,
65     COMMON_DUMP_TYPE_VEBOX_DRIVERHEAP,
66     COMMON_DUMP_TYPE_VEBOX_KERNELHEAP,
67     COMMON_DUMP_TYPE_POST_ALL,
68     COMMON_DUMP_TYPE_INTERNAL
69 };
70 
71 typedef enum _MCPY_DIRECTION
72 {
73     mcpy_in = 1,
74     mcpy_out
75 } MCPY_DIRECTION;
76 
77 typedef enum _COMMON_SURFACE_TYPE
78 {
79     COMMON_SURF_NONE = 0,
80     COMMON_SURF_IN_BACKGROUND,
81     COMMON_SURF_IN_PRIMARY,
82     COMMON_SURF_IN_SUBSTREAM,
83     COMMON_SURF_IN_REFERENCE,
84     COMMON_SURF_OUT_RENDERTARGET,
85     COMMON_SURF_TYPE_COUNT  //!< Keep this line at the end
86 } COMMON_SURFACE_TYPE;
87 C_ASSERT(COMMON_SURF_TYPE_COUNT == 6);  //!< When adding, update assert & vphal_solo_scenario.cpp
88 
89 struct COMMON_SURF_DUMP_LOC
90 {
91     uint32_t                        DumpLocation;           //!< Dump location
92     COMMON_SURFACE_TYPE             SurfType;               //!< Type of this surface
93 };
94 
95 struct COMMON_SURF_DUMP_SPEC
96 {
97     char                        pcOutputPath[MAX_PATH];     //!< Path where dumps are written
98     COMMON_SURF_DUMP_LOC       *pDumpLocations;
99     uint32_t                    uiStartFrame;               //!< Frame to start dumping at
100     uint32_t                    uiEndFrame;                 //!< Frame to stop dumping at
101     int32_t                     iNumDumpLocs;               //!< Number of pipe stage dump locations
102     bool                        enableAuxDump;              //!< Enable aux data dump for compressed surface
103     bool                        enablePlaneDump;            //!< Enable surface dump by plane
104 };
105 
106 class CommonSurfaceDumper
107 {
108 public:
109     CommonSurfaceDumper(PMOS_INTERFACE pOsInterface);
110 
111     virtual ~CommonSurfaceDumper();
112 
113     virtual MOS_STATUS DumpSurfaceToFile(
114         PMOS_INTERFACE              pOsInterface,
115         PMOS_SURFACE                pSurface,
116         char                       *psPathPrefix,
117         uint64_t                    iCounter,
118         bool                        bLockSurface,
119         bool                        bNoDecompWhenLock,
120         uint8_t*                    pData);
121 
122     MOS_STATUS GetPlaneDefs(
123         PMOS_SURFACE                        pSurface,
124         COMMON_SURF_DUMP_SURFACE_DEF*       pPlanes,
125         uint32_t*                           pdwNumPlanes,
126         uint32_t*                           pdwSize,
127         bool                                auxEnable,
128         bool                                isDeswizzled);
129 
130     bool HasAuxSurf(
131         PMOS_RESOURCE               osResource);
132 
133     MOS_STATUS GetSurfaceDumpLocation(
134         char*          dumpLoc,
135         MCPY_DIRECTION mcpyDirection);
136 
137     char* WhitespaceTrim(
138         char*          ptr);
139 
140     MOS_STATUS SurfTypeStringToEnum(
141         char*                       pcSurfType,
142         COMMON_SURFACE_TYPE          *pSurfType);
143 
144     MOS_STATUS LocStringToEnum(
145         char*                       pcLocString,
146         uint32_t                    *pLocation);
147 
148     MOS_STATUS ProcessDumpLocations(
149         char*                      pcDumpLocData);
150 
151     MOS_STATUS ReAllocateSurface(
152         PMOS_INTERFACE  pOsInterface,
153         PMOS_SURFACE    pSurface,
154         PMOS_SURFACE    pSrcSurf,
155         PCCHAR          pSurfaceName,
156         MOS_GFXRES_TYPE defaultResType,
157         bool            useLinearResource);
158 
159     bool IsSyncFreeNeededForMMCSurface(
160         PMOS_INTERFACE  osInterface,
161         PMOS_SURFACE    surface);
162 
163     MOS_STATUS DumpSurfaceToFileEnd(
164         PMOS_INTERFACE  pOsInterface,
165         uint8_t        *pDst,
166         bool            isSurfaceLocked,
167         PMOS_RESOURCE   pLockedResource,
168         PMOS_SURFACE    pSurface);
169 
170     PMOS_INTERFACE                  m_osInterface;
171     COMMON_SURF_DUMP_SPEC           m_dumpSpec;
172     MediaUserSettingSharedPtr       m_userSettingPtr = nullptr;       // userSettingInstance
173     int32_t                         m_frameNum = 0;
174 
175 MEDIA_CLASS_DEFINE_END(CommonSurfaceDumper)
176 };
177 
178 class CommonDumperTool
179 {
180 public:
181     static void GetOsFilePath(
182         const char*                 pcFilePath,
183         char*                       pOsFilePath);
184 
185     static void StringToLower(
186         char*                       pcString);
187 
188     static const char * GetFormatStr(
189         MOS_FORMAT                  format);
190 
191 MEDIA_CLASS_DEFINE_END(CommonDumperTool)
192 };
193 
194 #endif // (!(_DEBUG || _RELEASE_INTERNAL) || EMUL)
195 
196 #endif // __MEDIA_DEBUG_DUMPER_H__
197