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