xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/vp/hal/vphal_debug.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2011-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      vphal_debug.h
24 //! \brief
25 //!
26 //!
27 //! \file     vphal_debug.h
28 //! \brief    Definition of structures and functions for debugging VPHAL
29 //! \details  This file contains the definition of structures and functions for
30 //!           surface dumper, hw state dumper, perf counter dumper, and render
31 //!           parameter dumper
32 //!
33 #ifndef __VPHAL_DEBUG_H__
34 #define __VPHAL_DEBUG_H__
35 
36 #if (_DEBUG || _RELEASE_INTERNAL)
37 
38 #include "renderhal_legacy.h"
39 #include "mhw_vebox.h"
40 #include "vphal_common.h"
41 #if !defined(LINUX) && !defined(ANDROID)
42 #include "UmdStateSeparation.h"
43 #endif
44 
45 //==<DEFINITIONS>===============================================================
46 #define MAX_NAME_LEN            100
47 
48 #define VPHAL_DBG_DUMP_OUTPUT_FOLDER                "\\vphaldump\\"
49 
50 #define VPHAL_DBG_SURF_DUMP_MANUAL_TRIGGER_DEFAULT_NOT_SET (-1)
51 #define VPHAL_DBG_SURF_DUMP_MANUAL_TRIGGER_STARTED (1)
52 #define VPHAL_DBG_SURF_DUMP_MANUAL_TRIGGER_STOPPED (0)
53 
54 //------------------------------------------------------------------------------
55 // Dump macro.  Simply calls the dump function.  defined as null in production
56 //------------------------------------------------------------------------------
57 #define VPHAL_DBG_SURFACE_DUMP(dumper, surf, frameCntr, layerCntr, loc)         \
58     VPHAL_DEBUG_CHK_STATUS(dumper->DumpSurface(surf, frameCntr, layerCntr, loc));
59 
60 //------------------------------------------------------------------------------
61 // Dump array of surfaces
62 //------------------------------------------------------------------------------
63 #define VPHAL_DBG_SURFACE_PTRS_DUMP(                                            \
64     dumper, surfs, maxCntr, numCntr, frameCntr, loc)                            \
65     VPHAL_DEBUG_CHK_STATUS(dumper->DumpSurfaceArray(                            \
66         surfs, maxCntr, numCntr, frameCntr, loc));
67 
68 //------------------------------------------------------------------------------
69 // Create macro for dumper.  Allocates and initializes.
70 //    Potential leak if renderer not destroyed properly. However, cannot add a
71 //    free here since renderer is not initialized to null (0)
72 //------------------------------------------------------------------------------
73 #define VPHAL_DBG_SURF_DUMP_CREATE()                                            \
74     m_surfaceDumper = MOS_New(VphalSurfaceDumper, m_pOsInterface);              \
75     if (m_surfaceDumper)                                                        \
76         m_surfaceDumper->GetSurfaceDumpSpec();
77 
78 //------------------------------------------------------------------------------
79 // Destroy macro for dumper.  Frees and sets to null.
80 //------------------------------------------------------------------------------
81 #define VPHAL_DBG_SURF_DUMP_DESTORY(surfaceDumper)                              \
82     MOS_Delete(surfaceDumper);                                                  \
83     surfaceDumper = nullptr;
84 
85 #define VPHAL_DBG_STATE_DUMPPER_CREATE()                                        \
86     pRenderHal->pStateDumper = MOS_New(VphalHwStateDumper, pRenderHal);         \
87     if (pRenderHal->pStateDumper)                                               \
88         ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                    \
89             GetStateDumpSpec();
90 
91 #define VPHAL_DBG_STATE_DUMPPER_DESTORY(pStateDumper)                           \
92     VphalHwStateDumper::Delete(pStateDumper);                                   \
93     pStateDumper = nullptr;
94 
95 #define VPHAL_DBG_STATE_DUMP_SET_CURRENT_FRAME_COUNT(uiFrameCounter)            \
96     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
97         m_dumpSpec.uiCurrentFrame = uiFrameCounter;
98 
99 #define VPHAL_DBG_STATE_DUMPPER_SET_CURRENT_STAGE(uiCurrentStage)               \
100     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
101         iDebugStage = uiCurrentStage;                                           \
102     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
103         iPhase = 0;
104 
105 #define VPHAL_DBG_STATE_DUMPPER_SET_CURRENT_PHASE(uiCurrentPhase)               \
106     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
107         iPhase = uiCurrentPhase;
108 
109 #define VPHAL_DBG_STATE_DUMPPER_DUMP_COMMAND_BUFFER(pRenderHal, pCmdBuffer)     \
110     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
111     DumpCommandBuffer(pCmdBuffer);
112 
113 #define VPHAL_DBG_STATE_DUMPPER_DUMP_GSH(pRenderHal)                            \
114     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
115     DumpGSH();
116 
117 #define VPHAL_DBG_STATE_DUMPPER_DUMP_SSH(pRenderHal)                            \
118     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
119     DumpSSH();
120 
121 #define VPHAL_DBG_STATE_DUMPPER_DUMP_BATCH_BUFFER(pRenderHal, pBatchBuffer)     \
122     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
123     DumpBatchBuffer(pBatchBuffer);
124 
125 #define VPHAL_DBG_STATE_DUMPPER_DUMP_VEBOX_STATES(pRenderHal, pVeboxState)      \
126     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
127     DumpVeboxState(pVeboxState);
128 
129 #define VPHAL_DBG_STATE_DUMPPER_DUMP_VEBOX_STATISTICS(pRenderHal, pVeboxState, pStatSlice0Base, pStatSlice1Base)   \
130     ((VphalHwStateDumper*)(pRenderHal->pStateDumper)) ->                        \
131     DumpStatistics(pVeboxState, pStatSlice0Base, pStatSlice1Base);
132 
133 //------------------------------------------------------------------------------
134 // Create macro for vphal parameters dumper.  Allocates and initializes.
135 //------------------------------------------------------------------------------
136 #define VPHAL_DBG_PARAMETERS_DUMPPER_CREATE()                                   \
137     m_parameterDumper = MOS_New(VphalParameterDumper, m_pOsInterface);          \
138     if (m_parameterDumper)                                                      \
139         m_parameterDumper->GetParametersDumpSpec();
140 
141 //------------------------------------------------------------------------------
142 // Destroy macro for dumper.  Frees and sets to null.
143 //------------------------------------------------------------------------------
144 #define VPHAL_DBG_PARAMETERS_DUMPPER_DESTORY(parameterDumper)                 \
145     MOS_Delete(parameterDumper);                                              \
146     parameterDumper = nullptr;
147 
148 //------------------------------------------------------------------------------
149 // Dump macro for dumper.  Dump vphal parameters.
150 //------------------------------------------------------------------------------
151 #define VPHAL_DBG_PARAMETERS_DUMPPER_DUMP_XML(pRenderParams)                    \
152     m_parameterDumper->DumpToXML(                                               \
153         uiFrameCounter,                                                         \
154         m_surfaceDumper->m_dumpSpec.pcOutputPath,                               \
155         pRenderParams);
156 
157 //------------------------------------------------------------------------------
158 // Dump macro for dumper.  Dump Sku and workaround information.
159 //------------------------------------------------------------------------------
160 #define SkuWaTable_DUMPPER_DUMP_XML(skuTable, waTable) \
161     m_parameterDumper->SkuWa_DumpToXML(                \
162         skuTable,                                      \
163         waTable);
164 
165 //!
166 //! Structure VPHAL_DBG_SURF_DUMP_SURFACE_DEF
167 //! \brief    Plane definition
168 //! \details  Plane information including offset, height, width, pitch
169 //!
170 struct VPHAL_DBG_SURF_DUMP_SURFACE_DEF
171 {
172     uint32_t   dwOffset;                                                           //!< Offset from start of the plane
173     uint32_t   dwHeight;                                                           //!< Height in rows
174     uint32_t   dwWidth;                                                            //!< Width in bytes
175     uint32_t   dwPitch;                                                            //!< Pitch in bytes
176 };
177 
178 //!
179 //! \brief Dump locations as enum
180 //!
181 enum VPHAL_DBG_SURF_DUMP_LOCATION
182 {
183     VPHAL_DBG_DUMP_TYPE_PRE_ALL,
184     VPHAL_DBG_DUMP_TYPE_PRE_DNDI,
185     VPHAL_DBG_DUMP_TYPE_POST_DNDI,
186     VPHAL_DBG_DUMP_TYPE_PRE_COMP,
187     VPHAL_DBG_DUMP_TYPE_POST_COMP,
188     VPHAL_DBG_DUMP_TYPE_PRE_MEMDECOMP,
189     VPHAL_DBG_DUMP_TYPE_POST_MEMDECOMP,
190     VPHAL_DBG_DUMP_TYPE_POST_ALL
191 };
192 
193 //!
194 //! Structure VPHAL_DBG_SURF_DUMP_LOC
195 //! \brief    Specification for a single pipeline location dump
196 //! \details  Specification for a single pipeline location dump
197 //!
198 struct VPHAL_DBG_SURF_DUMP_LOC
199 {
200     uint32_t                        DumpLocation;                               //!< Dump location
201     VPHAL_SURFACE_TYPE              SurfType;                                   //!< Type of this surface
202 };
203 
204 //!
205 //! Structure VPHAL_DBG_SURF_DUMP_SPEC
206 //! \brief    All information about a surface dump specification
207 //! \details  All information about a surface dump specification
208 //!
209 struct VPHAL_DBG_SURF_DUMP_SPEC
210 {
211     char                          pcOutputPath[MAX_PATH];                       //!< Path where dumps are written
212     VPHAL_DBG_SURF_DUMP_LOC       *pDumpLocations;                              //!< Locations in post-processing pipeline to dump at
213     uint32_t                      uiStartFrame;                                 //!< Frame to start dumping at
214     uint32_t                      uiEndFrame;                                   //!< Frame to stop dumping at
215     int32_t                       iNumDumpLocs;                                 //!< Number of pipe stage dump locations
216     bool                          enableAuxDump;                                //!< Enable aux data dump for compressed surface
217     bool                          enablePlaneDump;                              //!< Enable surface dump by plane
218 };
219 
220 //!
221 //! Structure PVPHAL_DBG_PFIELD_LAYOUT
222 //! \brief    Debug Field Structure
223 //! \details  Debug Field Structure
224 //!
225 struct VPHAL_DBG_FIELD_LAYOUT
226 {
227     char                     pcName[MAX_NAME_LEN];
228     uint32_t                 dwOffset;
229     uint32_t                 dwSize;
230     uint32_t                 uiNumber;
231     char                     pcStructName[MAX_NAME_LEN];
232     VPHAL_DBG_FIELD_LAYOUT   *pChildLayout;
233     uint32_t                 uiNumChildren;
234 
235 };
236 
237 //!
238 //! \brief Render stage in VPHAL
239 //!
240 enum  VPHAL_DEBUG_STAGE
241 {
242     VPHAL_DBG_STAGE_NULL,
243     VPHAL_DBG_STAGE_DNDI,
244     VPHAL_DBG_STAGE_VEBOX,
245     VPHAL_DBG_STAGE_COMP
246 };
247 
248 //!
249 //! \brief HW state buffer in VPHAL
250 //!
251 enum VPHAL_DBG_DUMP_TYPE
252 {
253     VPHAL_DBG_DUMP_TYPE_GSH,
254     VPHAL_DBG_DUMP_TYPE_SSH,
255     VPHAL_DBG_DUMP_TYPE_BB,
256     VPHAL_DBG_DUMP_TYPE_CB,
257 };
258 
259 //!
260 //! Structure VPHAL_DBG_GSH_DUMP_LOC
261 //! \brief    Specification for GSH location dump
262 //! \details  Specification for GSH location dump
263 //!
264 struct VPHAL_DBG_GSH_DUMP_LOC
265 {
266     uint32_t            DumpStage;            //!< Which stage the data should be dumped, used for GSH.
267 };
268 
269 //!
270 //! Structure VPHAL_DBG_SSH_DUMP_LOC
271 //! \brief    Specification for SSH location dump
272 //! \details  Specification for SSH location dump
273 //!
274 struct VPHAL_DBG_SSH_DUMP_LOC
275 {
276     uint32_t            DumpStage;            //!< Which stage the data should be dumped, used for SSH.
277 };
278 
279 //!
280 //! Structure VPHAL_DBG_BB_DUMP_LOC
281 //! \brief    Specification for BB location dump
282 //! \details  Specification for BB location dump
283 //!
284 struct VPHAL_DBG_BB_DUMP_LOC
285 {
286     uint32_t            DumpStage;            //!< Which stage the data should be dumped, used for batch buffer.
287 };
288 
289 //!
290 //! Structure VPHAL_DBG_CB_DUMP_LOC
291 //! \brief    Specification for cmd buffer location dump
292 //! \details  Specification for cmd buffer location dump
293 //!
294 struct VPHAL_DBG_CB_DUMP_LOC
295 {
296     uint32_t            DumpStage;            //!< Which stage the data should be dumped, used for Command buffer.
297 };
298 
299 //!
300 //! Structure VPHAL_DBG_VEBOXSTATE_DUMP_LOC
301 //! \brief    Specification for Vebox state location dump
302 //! \details  Specification for Vebox state location dump
303 //!
304 struct VPHAL_DBG_VEBOXSTATE_DUMP_LOC
305 {
306     uint32_t            DumpStage;            //!< Which stage the data should be dumped, used for Vebox state.
307 };
308 
309 //!
310 //! Structure VPHAL_DBG_STATISTICS_DUMP_LOC
311 //! \brief    Specification for Statistics location dump
312 //! \details  Specification for Statistics location dump
313 //!
314 struct VPHAL_DBG_STATISTICS_DUMP_LOC
315 {
316     uint32_t            DumpStage;            //!< Which stage the data should be dumped, used for Statistics.
317 };
318 
319 //!
320 //! Structure VPHAL_DBG_GSH_DUMP_SPEC
321 //! \brief    All information about GSH dump specification
322 //! \details  All information about GSH dump specification
323 //!
324 struct VPHAL_DBG_GSH_DUMP_SPEC
325 {
326     int32_t                         iNumDumpLocs;                                 //!< Number of pipe stage dump locations
327     VPHAL_DBG_GSH_DUMP_LOC          *pDumpLocations;                              //!< Locations in post-processing pipeline to dump at
328 };
329 
330 //!
331 //! Structure VPHAL_DBG_SSH_DUMP_SPEC
332 //! \brief    All information about SSH dump specification
333 //! \details  All information about SSH dump specification
334 //!
335 struct VPHAL_DBG_SSH_DUMP_SPEC
336 {
337     int32_t                         iNumDumpLocs;                                 //!< Number of pipe stage dump locations
338     VPHAL_DBG_SSH_DUMP_LOC          *pDumpLocations;                              //!< Locations in post-processing pipeline to dump at
339 };
340 
341 //!
342 //! Structure VPHAL_DBG_BB_DUMP_SPEC
343 //! \brief    All information about batch buffer dump specification
344 //! \details  All information about batch buffer dump specification
345 //!
346 struct VPHAL_DBG_BB_DUMP_SPEC
347 {
348     int32_t                         iNumDumpLocs;                                 //!< Number of pipe stage dump locations
349     VPHAL_DBG_BB_DUMP_LOC           *pDumpLocations;                              //!< Locations in post-processing pipeline to dump at
350 };
351 
352 //!
353 //! Structure PVPHAL_DBG_CB_DUMP_SPEC
354 //! \brief    All information about cmd buffer dump specification
355 //! \details  All information about cmd buffer dump specification
356 //!
357 struct VPHAL_DBG_CB_DUMP_SPEC
358 {
359     int32_t                         iNumDumpLocs;                                 //!< Number of pipe stage dump locations
360     VPHAL_DBG_CB_DUMP_LOC           *pDumpLocations;                              //!< Locations in post-processing pipeline to dump at
361 };
362 
363 //!
364 //! Structure PVPHAL_DBG_VEBOXSTATE_DUMP_SPEC
365 //! \brief    All information about Vebox state dump specification
366 //! \details  All information about Vebox state dump specification
367 //!
368 struct VPHAL_DBG_VEBOXSTATE_DUMP_SPEC
369 {
370     int32_t                             iNumDumpLocs;                             //!< Number of pipe stage dump locations
371     VPHAL_DBG_VEBOXSTATE_DUMP_LOC       *pDumpLocations;                          //!< Locations in post-processing pipeline to dump at
372 };
373 
374 //!
375 //! Structure PVPHAL_DBG_STATISTICS_DUMP_SPEC
376 //! \brief    All information about Statistics dump specification
377 //! \details  All information about Statistics dump specification
378 //!
379 struct VPHAL_DBG_STATISTICS_DUMP_SPEC
380 {
381     int32_t                             iNumDumpLocs;                             //!< Number of pipe stage dump locations
382     VPHAL_DBG_STATISTICS_DUMP_LOC       *pDumpLocations;                          //!< Locations in post-processing pipeline to dump at
383 };
384 
385 //!
386 //! Structure VPHAL_DBG_DUMP_SPEC
387 //! \brief    All information about state dump specification
388 //! \details  All information about state dump specification
389 //!
390 struct VPHAL_DBG_DUMP_SPEC
391 {
392     char                                   pcOutputPath[MAX_PATH];                //!< Path where dumps are written
393     uint64_t                               uiStartFrame;                          //!< Frame to start dumping at
394     uint64_t                               uiEndFrame;                            //!< Frame to stop dumping at
395     uint32_t                               uiCurrentFrame;
396     VPHAL_DBG_GSH_DUMP_SPEC                *pGSHDumpSpec;
397     VPHAL_DBG_SSH_DUMP_SPEC                *pSSHDumpSpec;
398     VPHAL_DBG_BB_DUMP_SPEC                 *pBBDumpSpec;
399     VPHAL_DBG_CB_DUMP_SPEC                 *pCBDumpSpec;
400     VPHAL_DBG_VEBOXSTATE_DUMP_SPEC         *pVeboxStateDumpSpec;
401     VPHAL_DBG_STATISTICS_DUMP_SPEC         *pStatisticsDumpSpec;
402     uint32_t                               enableStateDump;  // Enable state dump
403 };
404 //-------------------------------------------------------------------------------
405 // All information about parameters output dump
406 //-------------------------------------------------------------------------------
407 struct VPHAL_DBG_PARAMS_DUMP_SPEC
408 {
409     char                       outFileLocation[MAX_PATH];                         // Location where dump files need to be stored
410     uint32_t                   uiStartFrame;                                      // Start frame for dumping
411     uint32_t                   uiEndFrame;                                        // End Frame for dumping
412     uint32_t                   enableSkuWaDump;                                   // Enable sku and wa info dump
413 };
414 
415 //==<FUNCTIONS>=================================================================
416 //!
417 //! Class VphalSurfaceDumper
418 //! \brief VPHAL Surface Dumper definition
419 //!
420 class VphalSurfaceDumper
421 {
422 public:
423     //!
424     //! \brief    Dump a surface into a file
425     //! \details  Dump a surface into a file, called by VpHalDbg_SurfaceDumperDump
426     //!           File name will be generated based on surface format, width,
427     //!           height, pitch, iCounter and psPathPrefix. For example, if the
428     //!           psPathPrefix is /dump/primary, then file will be created under
429     //!           /dump/ and file name will start as primary_
430     //! \param    [in] pOsInterface
431     //!           The pointer to OS interface
432     //! \param    [in] pSurface
433     //!           The pointer to the surface to be dumped
434     //! \param    [in] psPathPrefix
435     //!           The prefix of the file path which the surface will dump to
436     //! \param    [in] iCounter
437     //!           The counter that tells which render this surface belongs to
438     //! \param    [in] bLockSurface
439     //!           True if need to lock the surface
440     //! \param    [in] bNoDecompWhenLock
441     //!           True if force not to do decompress when Lock
442     //! \param    [in] pData
443     //!           non-null if caller already locked the surface byitself
444     //! \return   MOS_STATUS
445     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
446     //!
447     virtual MOS_STATUS DumpSurfaceToFile(
448         PMOS_INTERFACE              pOsInterface,
449         PVPHAL_SURFACE              pSurface,
450         const char                  *psPathPrefix,
451         uint64_t                    iCounter,
452         bool                        bLockSurface,
453         bool                        bNoDecompWhenLock,
454         uint8_t*                    pData);
455 
456     VPHAL_DBG_SURF_DUMP_SPEC    m_dumpSpec;
457 
458     //!
459     //! \brief    VphalSurfaceDumper constuctor
460     //!
461     VphalSurfaceDumper(PMOS_INTERFACE pOsInterface);
462 
463     //!
464     //! \brief    VphalSurfaceDumper destuctor
465     //!
466     virtual ~VphalSurfaceDumper();
467 
468     //!
469     //! \brief    Dump a surface
470     //! \details  Dump a surface according to the surface dumper spec
471     //! \param    [in] pSurf
472     //!           The pointer to the surface to be dumped
473     //! \param    [in] uiFrameNumber
474     //!           The counter that tells which render this surface belongs to
475     //! \param    [in] uiCounter
476     //!           The counter that tells which layer this surface belongs to
477     //! \param    [in] Location
478     //!           The render stage, e.g. preall, predndi, postdndi ...
479     //! \return   MOS_STATUS
480     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
481     //!
482     virtual MOS_STATUS DumpSurface(
483         PVPHAL_SURFACE                  pSurf,
484         uint32_t                        uiFrameNumber,
485         uint32_t                        uiCounter,
486         uint32_t                        Location);
487 
488     // VpHalDbg_SurfaceDumperDumpPtrs
489     //!
490     //! \brief    Dump all surfaces in surface array
491     //! \details  Dump all surfaces in surface array according to the surface
492     //!           dumper spec
493     //! \param    [in] ppSurfaces
494     //!           The pointer to surface array to be dumped
495     //! \param    [in] uiMaxSurfaces
496     //!           The max number of surfaces supported in VPHAL
497     //! \param    [in] uiNumSurfaces
498     //!           The number of surfaces to be dumped
499     //! \param    [in] uint32_t uiFrameNumber
500     //!           The counter that tells which render this surface belongs to
501     //! \param    [in] Location
502     //!           The render stage, e.g. preall, predndi, postdndi ...
503     //! \return   MOS_STATUS
504     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
505     //!
506     MOS_STATUS DumpSurfaceArray(
507         PVPHAL_SURFACE                  *ppSurfaces,
508         uint32_t                        uiMaxSurfaces,
509         uint32_t                        uiNumSurfaces,
510         uint32_t                        uiFrameNumber,
511         uint32_t                        Location);
512 
513     //!
514     //! \brief    Query the register to get surface dump specification.
515     //! \return   void
516     //!
517     void GetSurfaceDumpSpec();
518 
519 protected:
520     //!
521     //! \brief    Convert a string to loc enum type
522     //! \param    [in] pcLocString
523     //!           Pointer to the string to be converted
524     //! \param    [out] pLocation
525     //!           Enum type
526     //! \return   MOS_STATUS
527     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
528     //!
529     virtual MOS_STATUS LocStringToEnum(
530         char*                           pcLocString,
531         uint32_t                        *pLocation);
532 
533     //!
534     //! \brief    Converts an enum for loc type to a string
535     //! \param    [in] Location
536     //!           Enum type to be converted
537     //! \param    [out] pcLocString
538     //!           Location as a string -- must be allocated before sent in
539     //! \return   MOS_STATUS
540     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
541     //!
542     virtual MOS_STATUS EnumToLocString(
543         uint32_t                        Location,
544         char*                           pcLocString);
545 
546     //!
547     //! \brief    Check if an osResource have aux surf
548     //! \param    [in] osResource
549     //!           Pointer to MOS Resource
550     //! \return   bool
551     //!           Return true if has aux surf, otherwise false
552     //!
553     bool HasAuxSurf(
554         PMOS_RESOURCE                   osResource);
555 
556     PMOS_INTERFACE              m_osInterface;
557     char                        m_dumpPrefix[MAX_PATH];     // Called frequently, so avoid repeated stack resizing with member data
558     char                        m_dumpLoc[MAX_PATH];        // to avoid recursive call from diff owner but sharing the same buffer
559     static uint32_t             m_frameNumInVp;             // For use when vp dump its compressed surface, override the frame number given from MediaVeboxDecompState
560     static char                 m_dumpLocInVp[MAX_PATH];    // For use when vp dump its compressed surface, to distinguish each vp loc's pre/post decomp
561     MediaUserSettingSharedPtr   m_userSettingPtr = nullptr; // userSettingInstance
562 
563 private:
564 
565     //!
566     //! \brief    Get plane information of a surface
567     //! \details  Get plane information of a surface, e.g. offset of each plane,
568     //!           number of planes, total size of the surface
569     //! \param    [in] pSurface
570     //!           The pointer to the surface
571     //! \param    [out] pPlanes
572     //!           The pointer to the plane information of the surface
573     //! \param    [out] pdwNumPlanes
574     //!           Number of planes of the surface
575     //! \param    [out] pdwSize
576     //!           The total size of the surface
577     //! \param    [in] auxEnable
578     //!           Whether aux dump is enabled
579     //! \param    [in] isDeswizzled
580     //!           Whether deswizzleing is considered. If yes, uv offset should remove paddings
581     //! \return   MOS_STATUS
582     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
583     //!
584     MOS_STATUS GetPlaneDefs(
585         PVPHAL_SURFACE                      pSurface,
586         VPHAL_DBG_SURF_DUMP_SURFACE_DEF     *pPlanes,
587         uint32_t*                           pdwNumPlanes,
588         uint32_t*                           pdwSize,
589         bool                                auxEnable,
590         bool                                isDeswizzled);
591 
592     //!
593     //! \brief    Parse dump location
594     //! \details  Take dump location strings and break down into individual post-
595     //!           processing pipeline locations and surface types.
596     //! \param    [in] pcDumpLocData
597     //!           String containing all dump locations
598     //! \return   MOS_STATUS
599     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
600     //!
601     MOS_STATUS ProcessDumpLocations(
602         char*                      pcDumpLocData);
603 
604     //!
605     //! \brief    Convert a string to surf enum type
606     //! \param    [in] pcSurfType
607     //!           The pointer to string to be converted
608     //! \param    [out] pSurfType
609     //!           Enum version of string
610     //! \return   MOS_STATUS
611     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
612     //!
613     MOS_STATUS SurfTypeStringToEnum(
614         char*                       pcSurfType,
615         VPHAL_SURFACE_TYPE          *pSurfType);
616 
617     //!
618     //! \brief    Removes white space from a C-string
619     //! \param    [in] ptr
620     //!           String to be trimmed
621     //! \return   char*
622     //!           String after trim
623     //!
624     char* WhitespaceTrim(
625         char*                       ptr);
626 };
627 
628 typedef class VPHAL_VEBOX_STATE *PVPHAL_VEBOX_STATE;
629 
630 //!
631 //! Class VphalHwStateDumper
632 //! \brief HW State Dumper definition
633 //!
634 class VphalHwStateDumper
635 {
636 public:
637     VPHAL_DBG_DUMP_SPEC         m_dumpSpec;
638     int32_t                     iDebugStage;        // dnuv, dndi, compostion ...
639     int32_t                     iPhase;
640 
641     //!
642     //! \brief    VphalHwStateDumper destuctor
643     //!
Delete(void * dumper)644     static void Delete(void * dumper)
645     {
646         VphalHwStateDumper * hwStateDumper = (VphalHwStateDumper*) dumper;
647         MOS_Delete(hwStateDumper);
648     };
649 
650     //!
651     //! \brief    VphalHwStateDumper constuctor
652     //!
653     VphalHwStateDumper(PRENDERHAL_INTERFACE pRenderHal);
654 
655     //!
656     //! \brief    VphalHwStateDumper destuctor
657     //!
658     virtual ~VphalHwStateDumper();
659 
660     //!
661     //! \brief    Query the register to get dump state spec.
662     //! \return   void
663     //!
664     void GetStateDumpSpec();
665 
666     //!
667     //! \brief    Dumps GSH
668     //! \return   void
669     //!
670     void DumpGSH();
671 
672     //!
673     //! \brief    Dumps SSH
674     //! \return   void
675     //!
676     void DumpSSH();
677 
678     //!
679     //! \brief    Dump batch buffer
680     //! \param    [in] pBatchBuffer
681     //!           Pointer to batch buffer
682     //! \return   void
683     //!
684     void DumpBatchBuffer(
685         PMHW_BATCH_BUFFER           pBatchBuffer);
686 
687     //!
688     //! \brief    Dumps Command buffer
689     //! \param    [in] pCommandBuffer
690     //!           Pointer to command buffer
691     //! \return   void
692     //!
693     void DumpCommandBuffer(
694         PMOS_COMMAND_BUFFER         pCommandBuffer);
695 
696     //!
697     //! \brief    Dumps Vebox State
698     //! \details  Dumps Vebox State
699     //! \param    [in] pVeboxState
700     //!           Pointer to Vebox state
701     //! \return   void
702     //!
703     void DumpVeboxState(
704         PVPHAL_VEBOX_STATE                       pVeboxState);
705 
706     //!
707     //! \brief    Dumps Statistics
708     //! \param    [in] pVeboxState
709     //!           Pointer to DNDI state
710     //! \param    [in] pStat0Base
711     //!           Base address of Statistics 0
712     //! \param    [in] pStat1Base
713     //!           Base address of Statistics 1
714     //! \return   void
715     //!
716     void DumpStatistics(
717         void*                       pVeboxState,
718         uint8_t*                    pStat0Base,
719         uint8_t*                    pStat1Base);
720 
721 protected:
722     //!
723     //! \brief    Converts an enum for stage type to a string
724     //! \param    [in] Location
725     //!           VPHAL debug stage
726     //! \param    [out] pcLocString
727     //!           Location as a string -- must be allocated before sent in
728     //! \return   MOS_STATUS
729     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
730     //!
731     virtual MOS_STATUS EnumToLocString(
732         VPHAL_DEBUG_STAGE          Location,
733         char*                      pcLocString);
734 
735     //!
736     //! \brief    Convert a string to state enum type
737     //! \param    [in] pcStateType
738     //!           The pointer to string to be converted
739     //! \param    [out] pStateType
740     //!           Enum version of string
741     //! \return   MOS_STATUS
742     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
743     //!
744     virtual MOS_STATUS StateTypeStringToEnum(
745         char*                         pcStateType,
746         uint32_t                      *pStateType);
747 
748 private:
749     PRENDERHAL_INTERFACE            m_renderHal;
750     PMOS_INTERFACE                  m_osInterface;
751     PMHW_RENDER_STATE_SIZES         m_hwSizes;
752     PRENDERHAL_STATE_HEAP           m_stateHeap;
753     PRENDERHAL_STATE_HEAP_SETTINGS  m_stateHeapSettings;
754     MediaUserSettingSharedPtr       m_userSettingPtr = nullptr;  // userSettingInstance
755     //!
756     //! \brief    Take dump location strings and break down into individual
757     //!           post-processing pipeline locations and state types.
758     //! \details  Take dump location strings and break down into individual
759     //!           post-processing pipeline locations and state types.
760     //! \param    [in] pcDumpLocData
761     //!           String containing all dump locations
762     //! \return   MOS_STATUS
763     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
764     //!
765     MOS_STATUS ProcessDumpStateLocations(
766         char*                      pcDumpLocData);
767 
768     //!
769     //! \brief    Dumps binary contents for vebox Statistics
770     //! \param    [in] pVeboxState
771     //!           Pointer to DNDI state
772     //! \param    [in] pStat0Base
773     //!           Base address of Statistics 0
774     //! \param    [in] pStat1Base
775     //!           Base address of Statistics 1
776     //! \param    [in] pcFileLoc
777     //!           Structure name (becomes part of output file)
778     //! \param    [in] iID
779     //!           ID for dumping multiple of the same struct in the same place
780     //! \return   MOS_STATUS
781     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
782     //!
783     MOS_STATUS DumpStatisticsBinary(
784         PVPHAL_VEBOX_STATE      pVeboxState,
785         uint8_t*                pStat0Base,
786         uint8_t*                pStat1Base,
787         const char*             pcFileLoc,
788         int32_t                 iID);
789 
790     //!
791     //! \brief    Dumps binary contents and XML for GSH
792     //! \param    [in] pcFileLoc
793     //!           Structure name (becomes part of output file)
794     //! \param    [in] iID
795     //!           ID for dumping multiple of the same struct in the same place
796     //! \return   MOS_STATUS
797     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
798     //!
799     MOS_STATUS DumpGshBinary(
800         const char*          pcFileLoc,
801         int32_t              iID);
802 
803     //!
804     //! \brief    Define GSH layout.
805     //! \details  Define GSH layout according to GSH structure
806     //! \param    [out] ppGshLayout
807     //!           Layout of GSH
808     //! \param    [out] puiNumGSHFields
809     //!           Number of top-level fields in GSH
810     //! \return   MOS_STATUS
811     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
812     //!
813     MOS_STATUS DefGsh(
814         VPHAL_DBG_FIELD_LAYOUT*  *ppGshLayout,
815         uint32_t*                puiNumGSHFields);
816 
817     //!
818     //! \brief    Dumps binary contents and XML for SSH
819     //! \param    [in] pcFileLoc
820     //!           Structure name (becomes part of output file)
821     //! \param    [in] iID
822     //!           ID for dumping multiple of the same struct in the same place
823     //! \return   MOS_STATUS
824     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
825     //!
826     MOS_STATUS DumpSshBinary(
827         const char*          pcFileLoc,
828         int32_t              iID);
829 
830     //!
831     //! \brief    Define SSH layout.
832     //! \details  Define SSH layout according to SSH structure
833     //! \param    [out] ppSshLayout
834     //!           Layout of SSH
835     //! \param    [out] puiNumSSHFields
836     //!           Number of top-level fields in SSH
837     //! \return   MOS_STATUS
838     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
839     //!
840     MOS_STATUS DefSsh(
841         VPHAL_DBG_FIELD_LAYOUT*  *ppSshLayout,
842         uint32_t*                puiNumSSHFields);
843 
844     //!
845     //! \brief    Dumps binary contents and XML for BB
846     //! \param    [in] pBatchBuffer
847     //!           Pointer to buffer
848     //! \param    [in] pcFileLoc
849     //!           Structure name (becomes part of output file)
850     //! \param    [in] iID
851     //!           ID for dumping multiple of the same struct in the same place
852     //! \return   MOS_STATUS
853     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
854     //!
855     MOS_STATUS DumpBatchBufferBinary(
856         PMHW_BATCH_BUFFER            pBatchBuffer,
857         const char*                  pcFileLoc,
858         int32_t                      iID);
859 
860     //!
861     //! \brief    Dumps binary contents and XML for CMB
862     //! \param    [in] pCmd_buff
863     //!           Command buffer
864     //! \param    [in] pcFileLoc
865     //!           Structure name (becomes part of output file)
866     //! \param    [in] iID
867     //!           ID for dumping multiple of the same struct in the same place
868     //! \return   MOS_STATUS
869     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
870     //!
871     MOS_STATUS DumpCommandBufferBinary(
872         PMOS_COMMAND_BUFFER          pCmd_buff,
873         const char*                  pcFileLoc,
874         int32_t                      iID);
875 
876     //!
877     //! \brief    Dumps binary contents  for VeboxState
878     //! \details  Dumps binary contents  for VeboxState
879     //! \param    [in] pVeboxInterface
880     //!           Pointer to Vebox Interface
881     //! \param    [in] pcFileLoc
882     //!           Structure name (becomes part of output file)
883     //! \param    [in] iID
884     //!           ID for dumping multiple of the same struct in the same place
885     //! \return   MOS_STATUS
886     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
887     //!
888     MOS_STATUS DumpVeboxStateBinary(
889         PMHW_VEBOX_INTERFACE         pVeboxInterface,
890         const char*                  pcFileLoc,
891         int32_t                      iID);
892 
893     //!
894     //! \brief    Dumps binary contents of data structure to a file
895     //! \param    [in] fields
896     //!           Top level fields (for calculating size)
897     //! \param    [in] uiNumFields
898     //!           Size of previous array
899     //! \param    [in] pvStructToDump
900     //!           Pointer to structure in memory
901     //! \param    [in] pcPath
902     //!           Path of output file
903     //! \param    [in] pcName
904     //!           Structure name (becomes part of output file)
905     //! \param    [in] iID
906     //!           ID for dumping multiple of the same struct in the same place
907     //! \return   MOS_STATUS
908     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
909     //!
910     MOS_STATUS DumpBinaryStruct(
911         VPHAL_DBG_FIELD_LAYOUT*      fields,
912         uint32_t                     uiNumFields,
913         void                         *pvStructToDump,
914         char*                        pcPath,
915         PCCHAR                       pcName,
916         int32_t                      iID);
917 
918     //!
919     //! \brief    Dump a field heap to the string
920     //! \details  For num fields specified in parLayout, output XML header/footer
921     //!           and call dump_subfields to handle lower hierarchy levels for each
922     //!           e.g. N media states
923     //! \param    [in,out] ppcOutContents
924     //!           Pointer to string for structure descriptions
925     //! \param    [in] parLayout
926     //!           Pointer to parent layout description
927     //! \return   MOS_STATUS
928     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
929     //!
930     MOS_STATUS DumpFieldHeap(
931         char                        **ppcOutContents,
932         VPHAL_DBG_FIELD_LAYOUT*     parLayout);
933 
934     //!
935     //! \brief    Dump sub field to the string
936     //! \details  Dump next level in the hierarchy based on its type (struct, etc.)
937     //! \param    [in,out] ppcOutContents
938     //!           Pointer to string for structure descriptions
939     //! \param    [in] pParLayout
940     //!           Pointer to parent layout description
941     //! \param    [in] pChildLayout
942     //!           Pointer to current layout description (child of previous)
943     //! \param    [in] uiNumChild
944     //!           Number of children
945     //! \return   MOS_STATUS
946     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
947     //!
948     MOS_STATUS DumpSubfields(
949         char                        **ppcOutContents,
950         VPHAL_DBG_FIELD_LAYOUT*     pParLayout,
951         VPHAL_DBG_FIELD_LAYOUT*     pChildLayout,
952         uint32_t                    uiNumChild);
953 
954     //!
955     //! \brief    Dump field to the string
956     //! \details  Dump subfields as well as header and footer for pLayout
957     //! \param    [in,out] ppcOutContents
958     //!           Pointer to string for structure descriptions
959     //! \param    [in] pLayout
960     //!           Layout of this field
961     //! \return   MOS_STATUS
962     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
963     //!
964     MOS_STATUS DumpField(
965         char                        **ppcOutContents,
966         VPHAL_DBG_FIELD_LAYOUT*     pLayout);
967 
968     //!
969     //! \brief    Print xml header
970     //! \details  Print xml header based on parameters.
971     //! \param    [in,out] ppcOutContents
972     //!           Pointer to string for structure descriptions
973     //! \param    [in] pcName
974     //!           Name of field
975     //! \param    [in] ulLoc
976     //!           Offset of field from beginning of parent
977     //! \param    [in] ulSize
978     //!           Size of field in bytes
979     //! \param    [in] bIsByte
980     //!           True if unit is bytes (loc and size)
981     //! \param    [in] bHasCont
982     //!           True if has subfields
983     //! \param    [in] bStruct
984     //!           Has sub-fields/contents
985     //! \return   MOS_STATUS
986     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
987     //!
988     MOS_STATUS DumpXmlFieldHeader(
989         char                        **ppcOutContents,
990         char                        *pcName,
991         uint32_t                    ulLoc,
992         uint32_t                    ulSize,
993         bool                        bIsByte,
994         bool                        bHasCont,
995         bool                        bStruct);
996 
997     //!
998     //! \brief    Print xml footer.
999     //! \param    [in,out] ppcOutContents
1000     //!           Pointer to string for structure descriptions
1001     //! \param    [in] bHasCont
1002     //!           Has sub-fields/contents
1003     //! \return   MOS_STATUS
1004     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1005     //!
1006     MOS_STATUS DumpXmlFieldFooter(
1007         char                        **ppcOutContents,
1008         bool                        bHasCont);
1009 
1010     //!
1011     //! \brief    Dump a dword to the string
1012     //! \details  For each uint32_t, i, specified by dwSizeField, output XML for DWi.
1013     //! \param    [in,out] ppcOutContents
1014     //!           Pointer to string for structure descriptions
1015     //! \param    [in] dwSizeField
1016     //!           Size of field in bytes
1017     //! \return   MOS_STATUS
1018     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1019     //!
1020     MOS_STATUS DumpDwords(
1021         char                        **ppcOutContents,
1022         uint32_t                    dwSizeField);
1023 
1024     //!
1025     //! \brief    Frees layout memory
1026     //! \details  Frees layout memory as well as all subfields recursively
1027     //! \param    [in] pLayout
1028     //!           Layout to free
1029     //! \param    [in] uiNumFields
1030     //!           Number of fields in layout
1031     //! \return   void
1032     //!
1033     void FreeLayout(
1034         VPHAL_DBG_FIELD_LAYOUT*     pLayout,
1035         uint32_t                    uiNumFields);
1036 
1037     //!
1038     //! \brief    Checks for a properly formed path and fixes errors if it can
1039     //! \param    [in/out] ppcPath
1040     //!           Pointer to string of file path
1041     //! \return   MOS_STATUS
1042     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1043     //!
1044     MOS_STATUS CheckPath(
1045         char                        **ppcPath);
1046 
1047     //!
1048     //! \brief    Get last field index
1049     //! \details  Finds the index info fl[] that has the highest offset
1050     //! \param    [in] fl[]
1051     //!           Pointer to array of fields layouts
1052     //! \param    [in] uiNumFields
1053     //!           Number of fields
1054     //! \param    [out] puiLastIndex
1055     //!           Pointer to int which holds index of last field (last according to offset)
1056     //! \return   void
1057     //!
1058     void GetLastFieldIndex(
1059         VPHAL_DBG_FIELD_LAYOUT      fl[],
1060         uint32_t                    uiNumFields,
1061         uint32_t                    *uiLastIndex);
1062 
1063 };
1064 
1065 //!
1066 //! Class VphalPArameerDumper
1067 //! \brief RenderParameter Dumper definition
1068 //!
1069 class VphalParameterDumper
1070 {
1071 public:
1072     VPHAL_DBG_PARAMS_DUMP_SPEC  m_dumpSpec;
1073 
1074     //!
1075     //! \brief    VphalParameterDumper constuctor
1076     //!
1077     VphalParameterDumper(PMOS_INTERFACE pOsInterface);
1078 
1079     //!
1080     //! \brief    Get VPHAL Parameters Dump Spec
1081     //! \param    [in] pDumpSpec
1082     //!           parameter dump spec
1083     //! \param    [in] pOsInterface
1084     //!           OS interface
1085     //! \return   void
1086     //!
1087     void GetParametersDumpSpec();
1088 
1089     //!
1090     //! \brief    VphalParameterDumper destuctor
1091     //!
1092     virtual ~VphalParameterDumper();
1093 
1094     //!
1095     //! \brief    Dumps the Render Parameters to XML File
1096     //! \param    [in] uiFrameCounter
1097     //!           frame counter
1098     //! \param    [in] pcOutputPath
1099     //!           Surface dump output path
1100     //! \param    [in] pRenderParams
1101     //!           Render parameter to be dumped
1102     //! \return   MOS_STATUS
1103     //!
1104     virtual MOS_STATUS DumpToXML(
1105         uint32_t                    uiFrameCounter,
1106         char                        *pcOutputPath,
1107         PVPHAL_RENDER_PARAMS        pRenderParams);
1108 
1109     //!
1110     //! \brief    Dumps Sku and Workaround information to XML File
1111     //!
1112     virtual MOS_STATUS SkuWa_DumpToXML(
1113         MEDIA_FEATURE_TABLE        *skuTable,
1114         MEDIA_WA_TABLE             *waTable);
1115 
1116 protected:
1117     //!
1118     //! \brief    Dumps the source Surface Parameters
1119     //! \param    [in] uiFrameCounter
1120     //!           frame counter
1121     //! \param    [in] pcOutputPath
1122     //!           Surface dump output path
1123     //! \param    [in] pSrc
1124     //!           source Surface to be dumped
1125     //! \param    [in] index
1126     //!           index of source Surface
1127     //! \param    [in/out] pcOutContents
1128     //!           output string buffer
1129     //! \return   MOS_STATUS
1130     //!
1131     virtual MOS_STATUS DumpSourceSurface(
1132         uint32_t                        uiFrameCounter,
1133         char                            *pcOutputPath,
1134         PVPHAL_SURFACE                  pSrc,
1135         uint32_t                        index,
1136         char*                           &pcOutContents);
1137 
1138     //!
1139     //! \brief    Dumps the target Surface Parameters
1140     //! \param    [in] uiFrameCounter
1141     //!           frame counter
1142     //! \param    [in] pcOutputPath
1143     //!           Surface dump output path
1144     //! \param    [in] pSrc
1145     //!           target Surface to be dumped
1146     //! \param    [in] index
1147     //!           index of target Surface
1148     //! \param    [in/out] pcOutContents
1149     //!           output string buffer
1150     //! \return   MOS_STATUS
1151     //!
1152     virtual MOS_STATUS DumpTargetSurface(
1153         uint32_t                        uiFrameCounter,
1154         char                            *pcOutputPath,
1155         PVPHAL_SURFACE                  pTarget,
1156         uint32_t                        index,
1157         char*                           &pcOutContents);
1158 
1159     //!
1160     //! \brief    Dumps the target Surface Parameters
1161     //! \param    [in] uiFrameCounter
1162     //!           frame counter
1163     //! \param    [in] pcOutputPath
1164     //!           Surface dump output path
1165     //! \param    [in] pRenderParams
1166     //!           Render parameter to be dumped
1167     //! \param    [in/out] pcOutContents
1168     //!           output string buffer
1169     //! \return   MOS_STATUS
1170     //!
1171     virtual MOS_STATUS DumpRenderParameter(
1172         uint32_t                        uiFrameCounter,
1173         char                            *pcOutputPath,
1174         PVPHAL_RENDER_PARAMS            pRenderParams,
1175         char*                           &pcOutContents);
1176 
1177     //!
1178     //! \brief    Gets Debug Component String
1179     //! \param    [in] component
1180     //!           Mos component
1181     //! \return   const char *
1182     //!           String of the Component
1183     //!
1184     virtual const char * GetComponentStr(
1185         MOS_COMPONENT             component);
1186 
1187     virtual char *GetDumpSpecLocation();
1188 
1189     virtual bool GetDumpSpecSkuWaDumpEnable();
1190 
1191 private:
1192     PMOS_INTERFACE  m_osInterface;
1193     MediaUserSettingSharedPtr m_userSettingPtr = nullptr;  // userSettingInstance
1194     //!
1195     //! \brief    Gets Debug Whole Format String
1196     //! \param    [in] format
1197     //!           Mos format
1198     //! \return   const char *
1199     //!           String of the whole format sucha as Format_NV12
1200     //!
1201     const char * GetWholeFormatStr(MOS_FORMAT format);
1202 
1203     //!
1204     //! \brief    Gets Debug Tile Type String
1205     //! \param    [in] format
1206     //!           Mos tile type
1207     //! \return   const char *
1208     //!           String of the tile type
1209     //!
1210     const char * GetTileTypeStr(MOS_TILE_TYPE tile_type);
1211 
1212     //!
1213     //! \brief    Gets Debug Surface Type String
1214     //! \param    [in] component
1215     //!           Mos component
1216     //! \return   const char *
1217     //!           String of the component
1218     //!
1219     const char * GetSurfaceTypeStr(VPHAL_SURFACE_TYPE surface_type);
1220 
1221     //!
1222     //! \brief    Gets Debug Sample Type String
1223     //! \param    [in] sample type
1224     //!           vphal sample type
1225     //! \return   const char *
1226     //!           String of the vphal sample type
1227     //!
1228     const char * GetSampleTypeStr(VPHAL_SAMPLE_TYPE sample_type);
1229 
1230     //!
1231     //! \brief    Gets Debug Color Type String
1232     //! \param    [in] Color type
1233     //!           vphal color type
1234     //! \return   const char *
1235     //!           String of the vphal color type
1236     //!
1237     const char * GetColorSpaceStr(VPHAL_CSPACE color_space);
1238 
1239     //!
1240     //! \brief    Gets Debug Blend Type String
1241     //! \param    [in] Blend type
1242     //!           vphal blend type
1243     //! \return   const char *
1244     //!           String of the vphal color type
1245     //!
1246     const char * GetBlendTypeStr(VPHAL_BLEND_TYPE blend_type);
1247 
1248     //!
1249     //! \brief    Gets Debug Palette Type String
1250     //! \param    [in] palette type
1251     //!           vphal palette type
1252     //! \return   const char *
1253     //!           String of vphal palette type
1254     //!
1255     const char * GetPaletteTypeStr(VPHAL_PALETTE_TYPE palette_type);
1256 
1257     //!
1258     //! \brief    Gets Debug Scaling Mode String
1259     //! \param    [in] scaling mode
1260     //!           vphal scaling mode
1261     //! \return   const char *
1262     //!           String of vphal scaling mode
1263     //!
1264     const char * GetScalingModeStr(VPHAL_SCALING_MODE scaling_mode);
1265 
1266     //!
1267     //! \brief    Gets Debug Rotation Mode String
1268     //! \param    [in] rotation mode
1269     //!           vphal rotation mode
1270     //! \return   const char *
1271     //!           String of vphal rotation mode
1272     //!
1273     const char * GetRotationModeStr(VPHAL_ROTATION rotation_mode);
1274 
1275     //!
1276     //! \brief    Gets Debug Deinterlace Mode String
1277     //! \param    [in] deinterlace mode
1278     //!           vphal deinterlace mode
1279     //! \return   const char *
1280     //!           String of vphal deinterlace mode
1281     //!
1282     const char * GetDIModeStr(VPHAL_DI_MODE di_mode);
1283 
1284     //!
1285     //! \brief    Gets Debug Denoise Mode String
1286     //! \param    [in] denoise level
1287     //!           vphal denoise level
1288     //! \return   const char *
1289     //!           String of vphal denoise level
1290     //!
1291     const char * GetDenoiseModeStr(VPHAL_NOISELEVEL noise_level);
1292 
1293     //!
1294     //! \brief    Gets Debug HVS Denoise Mode String
1295     //! \param    [in] hvs denoise mode
1296     //!           vphal hvsdn mode
1297     //! \return   const char *
1298     //!           String of vphal hvs denoise mode
1299     //!
1300     const char *GetHVSDenoiseModeStr(VPHAL_HVSDN_MODE hvs_dn_mode);
1301 };
1302 
1303 //!
1304 //! Class VphalDumperTool
1305 //! \brief Dumper Tool class definition
1306 //!
1307 class VphalDumperTool
1308 {
1309 public:
1310     //!
1311     //! \brief    Get a file path in current OS
1312     //! \details  Covert a file path to a path that can be recognized in current OS.
1313     //!           File path may be different in different OS.
1314     //! \param    [in] pcFilePath
1315     //            Input string of the file path to be converted
1316     //! \param    [out] pOsFilePath
1317     //!           Converted file path
1318     //! \return   void
1319     //!
1320     static void GetOsFilePath(
1321         const char* pcFilePath,
1322         char*       pOsFilePath);
1323 
1324     //!
1325     //! \brief    Convert a string to an all lower case version
1326     //! \param    [in/out] pcString
1327     //!           The pointer to string to be converted
1328     //! \return   void
1329     //!
1330     static void StringToLower(
1331         char*                       pcString);
1332 
1333     //!
1334     //! \brief    Append to the string
1335     //! \details  Adds second arg to end of first arg.  Works like sprintf, but
1336     //!           optimized for this special use.
1337     //! \param    [in] bFirst
1338     //!           True if this is the first call to this function for next param.
1339     //!           Note that multiple strings cannot be appended at the same time.
1340     //!           They should be appended one by one, e.g. pcBigString2 can be appended
1341     //!           after you finish appending pcBigString1.
1342     //! \param    [in/out] ppcBigString
1343     //!           Pointer to string for that is appended to
1344     //! \param    [in] pcToAppendFmt
1345     //!           String format for appended part
1346     //! \param    [in] ...
1347     //!           Fields to fill in for appended part
1348     //! \return   MOS_STATUS
1349     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1350     //!
1351     static MOS_STATUS AppendString(
1352         bool   bFirst,
1353         char   **ppcBigString,
1354         PCCHAR pcToAppendFmt,
1355         ...);
1356 
1357     //!
1358     //! \brief    Write Frame
1359     //! \details  Debug function to write intermediate output to C:\dump
1360     //! \param    [in] pOsInterface
1361     //!           Pointer to OS interface
1362     //! \param    [in] pSurface
1363     //!           Pointer to surface that will be read from
1364     //! \param    [in] fileName
1365     //!           File to be written to
1366     //! \param    [in] iCounter
1367     //!           Frame ID and cycle counter
1368     //! \return   void
1369     //!
1370     static void WriteFrame(
1371         PMOS_INTERFACE  pOsInterface,
1372         PVPHAL_SURFACE  pSurface,
1373         PCCHAR          fileName,
1374         uint64_t        iCounter);
1375 
1376     //!
1377     //! \brief    Returns the Size of the surface in bytes
1378     //! \param    [in] pSurface
1379     //!           The pointer to the surface
1380     //! \param    [int] iBpp
1381     //!           Number of bits per pixel
1382     //! \param    [out] piWidthInBytes
1383     //!           Width of the surface
1384     //! \param    [out] piHeightInRows
1385     //!           Height of the surface
1386     //! \return   MOS_STATUS
1387     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
1388     //!
1389     static MOS_STATUS GetSurfaceSize(
1390         PVPHAL_SURFACE              pSurface,
1391         uint32_t                    iBpp,
1392         uint32_t*                   piWidthInBytes,
1393         uint32_t*                   piHeightInRows);
1394 
1395     //!
1396     //! \brief    Gets Debug Format String
1397     //! \param    [in] format
1398     //!           Mos format
1399     //! \return   const char *
1400     //!           String of the format
1401     //!
1402     static const char * GetFormatStr(
1403         MOS_FORMAT                format);
1404 
1405 };
1406 
1407 #else
1408 
1409 #define VPHAL_DBG_SURFACE_DUMP(dumper, surf, frameCntr, layerCntr, loc)
1410 #define VPHAL_DBG_SURFACE_PTRS_DUMP(                                            \
1411     dumper, surfs, maxCntr, numCntr, frameCntr, loc)
1412 #define VPHAL_DBG_SURF_DUMP_CREATE()
1413 #define VPHAL_DBG_SURF_DUMP_DESTORY(surfaceDumper)
1414 #define VPHAL_DBG_STATE_DUMPPER_CREATE()
1415 #define VPHAL_DBG_STATE_DUMPPER_DESTORY(pStateDumper)
1416 #define VPHAL_DBG_STATE_DUMP_SET_CURRENT_FRAME_COUNT(uiFrameCounter)
1417 #define VPHAL_DBG_STATE_DUMPPER_SET_CURRENT_STAGE(uiCurrentStage)
1418 #define VPHAL_DBG_STATE_DUMPPER_SET_CURRENT_PHASE(uiCurrentPhase)
1419 #define VPHAL_DBG_STATE_DUMPPER_DUMP_COMMAND_BUFFER(pRenderHal, pCmdBuffer)
1420 #define VPHAL_DBG_STATE_DUMPPER_DUMP_GSH(pRenderHal)
1421 #define VPHAL_DBG_STATE_DUMPPER_DUMP_SSH(pRenderHal)
1422 #define VPHAL_DBG_STATE_DUMPPER_DUMP_BATCH_BUFFER(pRenderHal, pBatchBuffer)
1423 #define VPHAL_DBG_STATE_DUMPPER_DUMP_VEBOX_STATES(pRenderHal, pVeboxState)
1424 #define VPHAL_DBG_STATE_DUMPPER_DUMP_VEBOX_STATISTICS(pRenderHal, pVeboxState, pStatSlice0Base, pStatSlice1Base)
1425 #define VPHAL_DBG_PARAMETERS_DUMPPER_CREATE()
1426 #define VPHAL_DBG_PARAMETERS_DUMPPER_DESTORY(pParametersDumpSpec)
1427 #define VPHAL_DBG_PARAMETERS_DUMPPER_DUMP_XML(pRenderParams)
1428 #define SkuWaTable_DUMPPER_DUMP_XML(skuTable, waTable)
1429 
1430 #endif // (!(_DEBUG || _RELEASE_INTERNAL) || EMUL)
1431 
1432 #endif  // __VPHAL_DEBUG_H__
1433