xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/vp/hal/vphal_debug.c (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2011-2022, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file      vphal_debug.c
24 //! \brief
25 //!
26 //!
27 //! \file     vphal_debug.c
28 //! \brief    Implementation of functions for debugging VPHAL
29 //! \details  This file contains the Implementation of functions for
30 //!           surface dumper, hw state dumper, perf counter dumper, and render
31 //!           parameter dumper
32 //!
33 #include "vphal_debug.h"
34 #if (_DEBUG || _RELEASE_INTERNAL)
35 #include <stdio.h>
36 #include "vphal.h"
37 #include "mhw_vebox.h"
38 #include "mos_os.h"
39 
40 #include "vphal_render_vebox_base.h"
41 
42 #include "renderhal_platform_interface.h"
43 
44 #include "ctype.h"     // isupper, tolower, toupper
45 
46 #define ALLOC_GRANULARITY                           5000000
47 
48 //==<Dump Surface>==============================================================
49 #define VPHAL_DBG_SURF_DUMP_OUTFILE_KEY_NAME        "outfileLocation"
50 #define VPHAL_DBG_SURF_DUMP_LOCATION_KEY_NAME       "dumpLocations"
51 #define VPHAL_DBG_SURF_DUMP_START_FRAME_KEY_NAME    "startFrame"
52 #define VPHAL_DBG_SURF_DUMP_END_FRAME_KEY_NAME      "endFrame"
53 #define VPHAL_DBG_SURF_DUMP_MAX_DATA_LEN            200
54 #define VPHAL_DBG_SURF_DUMP_TYPE_BACKGROUND         "background"
55 #define VPHAL_DBG_SURF_DUMP_TYPE_PRIMARY            "primary"
56 #define VPHAL_DBG_SURF_DUMP_TYPE_SUBSTREAM          "substream"
57 #define VPHAL_DBG_SURF_DUMP_TYPE_REFERENCE          "reference"
58 #define VPHAL_DBG_SURF_DUMP_TYPE_RENDERTARGET       "rendertarget"
59 #define VPHAL_DBG_SURF_DUMP_LOC_PREALL              "preall"
60 #define VPHAL_DBG_SURF_DUMP_LOC_PREDNDI             "predndi"
61 #define VPHAL_DBG_SURF_DUMP_LOC_POSTDNDI            "postdndi"
62 #define VPHAL_DBG_SURF_DUMP_LOC_PRECOMP             "precomp"
63 #define VPHAL_DBG_SURF_DUMP_LOC_POSTCOMP            "postcomp"
64 #define VPHAL_DBG_SURF_DUMP_LOC_PREMEMDECOMP        "prememdecomp"
65 #define VPHAL_DBG_SURF_DUMP_LOC_POSTMEMDECOMP       "postmemdecomp"
66 #define VPHAL_DBG_SURF_DUMP_LOC_POSTALL             "postall"
67 
68 #define VPHAL_DBG_STATE_DUMP_OUTFILE_KEY_NAME        "outfileLocation"
69 #define VPHAL_DBG_STATE_DUMP_LOCATION_KEY_NAME       "dumpLocations"
70 #define VPHAL_DBG_STATE_DUMP_START_FRAME_KEY_NAME    "startFrame"
71 #define VPHAL_DBG_STATE_DUMP_END_FRAME_KEY_NAME      "endFrame"
72 
73 #define VPHAL_DBG_STATE_DUMP_LOC_DNDI                "dndi"
74 #define VPHAL_DBG_STATE_DUMP_LOC_VEBOX               "vebox"
75 #define VPHAL_DBG_STATE_DUMP_LOC_COMP                "comp"
76 
77 #define VPHAL_DBG_GSH_DUMP_TYPE                      "GSH"
78 #define VPHAL_DBG_SSH_DUMP_TYPE                      "SSH"
79 #define VPHAL_DBG_BB_DUMP_TYPE                       "BB"
80 #define VPHAL_DBG_CB_DUMP_TYPE                       "CB"
81 #define VPHAL_DBG_VEBOXSTATE_DUMP_TYPE               "VeboxState"
82 #define VPHAL_DBG_STATISTICS_DUMP_TYPE               "Statistics"
83 
84 #define ALLOCLIST_SIZE                              15
85 #define VPHAL_VEBOX_STATISTICS_SIZE_MAX             (288 * 4)        //!< Max Statistics size
86 #define MAX_DW_STRLEN                               7
87 #define KERNEL_FIELD_NAME                           "Kernel"
88 #define VPDEBUG_VERSION                             "1.0"
89 #define XMLHEADER                                   "<?xml version=\"1.0\"?>\r\n"
90 
91 //==<Dump Render Parameters>====================================================
92 #define VPHAL_DBG_PARAMS_DUMP_OUTFILE_KEY_NAME      "outxmlLocation"
93 #define VPHAL_DBG_PARAMS_DUMP_START_FRAME_KEY_NAME  "startxmlFrame"
94 #define VPHAL_DBG_PARAMS_DUMP_END_FRAME_KEY_NAME    "endxmlFrame"
95 
GetOsFilePath(const char * pcFilePath,char * pOsFilePath)96 void VphalDumperTool::GetOsFilePath(
97     const char* pcFilePath,
98     char*       pOsFilePath)
99 {
100     MOS_SecureMemcpy(pOsFilePath, MAX_PATH, (void*)pcFilePath, strlen(pcFilePath));
101 }
102 
GetPlaneDefs(PVPHAL_SURFACE pSurface,VPHAL_DBG_SURF_DUMP_SURFACE_DEF * pPlanes,uint32_t * pdwNumPlanes,uint32_t * pdwSize,bool auxEnable,bool isDeswizzled)103 MOS_STATUS VphalSurfaceDumper::GetPlaneDefs(
104     PVPHAL_SURFACE                    pSurface,
105     VPHAL_DBG_SURF_DUMP_SURFACE_DEF   *pPlanes,
106     uint32_t                          *pdwNumPlanes,
107     uint32_t                          *pdwSize,
108     bool                              auxEnable,
109     bool                              isDeswizzled)
110 {
111     MOS_STATUS      eStatus;
112     uint32_t        i;
113     bool            PaddingEnable = false;
114 
115     eStatus = MOS_STATUS_SUCCESS;
116 
117     // Caller should supply this much!
118     MOS_ZeroMemory(pPlanes, sizeof(VPHAL_DBG_SURF_DUMP_SURFACE_DEF) * 3);
119 
120     switch (pSurface->Format)
121     {
122     case Format_AI44:
123     case Format_IA44:
124     case Format_A4L4:
125     case Format_P8:
126     case Format_L8:
127     case Format_A8:
128     case Format_Buffer:
129     case Format_STMM:
130     case Format_IRW4:
131     case Format_IRW5:
132     case Format_IRW6:
133     case Format_IRW7:
134     case Format_RAW:
135     case Format_Y8:
136     case Format_R8UN:
137         *pdwNumPlanes = 1;
138 
139         pPlanes[0].dwWidth  = pSurface->dwWidth;
140         pPlanes[0].dwHeight = pSurface->dwHeight;
141         pPlanes[0].dwPitch  = pSurface->dwPitch;
142         break;
143 
144     case Format_R5G6B5:
145     case Format_A8P8:
146     case Format_A8L8:
147     case Format_YUY2:
148     case Format_YUYV:
149     case Format_YVYU:
150     case Format_UYVY:
151     case Format_VYUY:
152     case Format_IRW0:
153     case Format_IRW1:
154     case Format_IRW2:
155     case Format_IRW3:
156     case Format_V8U8:
157     case Format_R16F:
158     case Format_R16UN:
159     case Format_Y16S:
160     case Format_Y16U:
161         *pdwNumPlanes = 1;
162 
163         pPlanes[0].dwWidth  = pSurface->dwWidth * 2;
164         pPlanes[0].dwHeight = pSurface->dwHeight;
165         pPlanes[0].dwPitch  = pSurface->dwPitch;
166         break;
167 
168     case Format_R32U:
169     case Format_R32F:
170     case Format_A8R8G8B8:
171     case Format_X8R8G8B8:
172     case Format_A8B8G8R8:
173     case Format_X8B8G8R8:
174     case Format_R8G8B8:
175     case Format_AYUV:
176     case Format_AUYV:
177     case Format_R10G10B10A2:
178     case Format_B10G10R10A2:
179     case Format_Y410:
180         *pdwNumPlanes = 1;
181 
182         pPlanes[0].dwWidth  = pSurface->dwWidth * 4;
183         pPlanes[0].dwHeight = pSurface->dwHeight;
184         pPlanes[0].dwPitch  = pSurface->dwPitch;
185         break;
186 
187     case Format_Y416:
188     case Format_A16B16G16R16:
189     case Format_A16R16G16B16:
190     case Format_A16B16G16R16F:
191     case Format_A16R16G16B16F:
192         *pdwNumPlanes = 1;
193 
194         pPlanes[0].dwWidth  = pSurface->dwWidth * 8;
195         pPlanes[0].dwHeight = pSurface->dwHeight;
196         pPlanes[0].dwPitch  = pSurface->dwPitch;
197         break;
198 
199     case Format_NV12:
200         *pdwNumPlanes = 2;
201 
202         pPlanes[0].dwWidth  = pSurface->dwWidth;
203         pPlanes[0].dwHeight = pSurface->dwHeight;
204         pPlanes[0].dwPitch  = pSurface->dwPitch;
205 
206         pPlanes[1].dwWidth  = pPlanes[0].dwWidth;
207         pPlanes[1].dwHeight = pPlanes[0].dwHeight / 2;
208         pPlanes[1].dwPitch  = pSurface->dwPitch;
209         break;
210 
211     case Format_P010:
212     case Format_P016:
213         *pdwNumPlanes = 2;
214 
215         pPlanes[0].dwWidth  = pSurface->dwWidth * 2;
216         pPlanes[0].dwHeight = pSurface->dwHeight;
217         pPlanes[0].dwPitch  = pSurface->dwPitch;
218 
219         pPlanes[1].dwWidth  = pPlanes[0].dwWidth;
220         pPlanes[1].dwHeight = pPlanes[0].dwHeight / 2;
221         pPlanes[1].dwPitch  = pSurface->dwPitch;
222         break;
223 
224     case Format_IMC2:
225     case Format_IMC4:
226         *pdwNumPlanes = 2;
227 
228         pPlanes[0].dwWidth  = pSurface->dwWidth;
229         pPlanes[0].dwHeight = pSurface->dwHeight;
230         pPlanes[0].dwPitch  = pSurface->dwPitch;
231 
232         pPlanes[1].dwWidth  = pPlanes[0].dwWidth;
233         pPlanes[1].dwHeight = pPlanes[0].dwHeight / 2;
234         pPlanes[1].dwPitch  = pPlanes[0].dwPitch;
235         break;
236 
237     case Format_YVU9:
238         *pdwNumPlanes = 3;
239 
240         pPlanes[0].dwWidth  = pSurface->dwWidth;
241         pPlanes[0].dwHeight = pSurface->dwHeight;
242         pPlanes[0].dwPitch  = pSurface->dwPitch;
243 
244         pPlanes[1].dwWidth  = pPlanes[0].dwWidth / 4;
245         pPlanes[1].dwHeight = pPlanes[0].dwHeight / 4;
246         pPlanes[1].dwPitch  = pPlanes[0].dwPitch;
247 
248         pPlanes[2].dwWidth  = pPlanes[0].dwWidth / 4;
249         pPlanes[2].dwHeight = pPlanes[0].dwHeight / 4;
250         pPlanes[2].dwPitch  = pPlanes[0].dwPitch;
251         break;
252 
253     case Format_IMC1:
254     case Format_IMC3:
255         *pdwNumPlanes = 3;
256 
257         pPlanes[0].dwWidth  = pSurface->dwWidth;
258         pPlanes[0].dwHeight = pSurface->dwHeight;
259         pPlanes[0].dwPitch  = pSurface->dwPitch;
260 
261         pPlanes[1].dwWidth  = pPlanes[0].dwWidth / 2;
262         pPlanes[1].dwHeight = pPlanes[0].dwHeight / 2;
263         pPlanes[1].dwPitch  = pPlanes[0].dwPitch;
264 
265         pPlanes[2].dwWidth  = pPlanes[0].dwWidth / 2;
266         pPlanes[2].dwHeight = pPlanes[0].dwHeight / 2;
267         pPlanes[2].dwPitch  = pPlanes[0].dwPitch;
268         break;
269 
270     case Format_I420:
271     case Format_IYUV:
272     case Format_YV12:
273         *pdwNumPlanes = 3;
274 
275         pPlanes[0].dwWidth  = pSurface->dwWidth;
276         pPlanes[0].dwHeight = pSurface->dwHeight;
277         pPlanes[0].dwPitch  = pSurface->dwPitch;
278 
279         pPlanes[1].dwWidth  = pPlanes[0].dwWidth / 2;
280         pPlanes[1].dwHeight = pPlanes[0].dwHeight / 2;
281         pPlanes[1].dwPitch  = pPlanes[0].dwPitch / 2;
282 
283         pPlanes[2].dwWidth  = pPlanes[0].dwWidth / 2;
284         pPlanes[2].dwHeight = pPlanes[0].dwHeight / 2;
285         pPlanes[2].dwPitch  = pPlanes[0].dwPitch / 2;
286         break;
287     case Format_400P:
288         *pdwNumPlanes = 1;
289 
290         pPlanes[0].dwWidth  = pSurface->dwWidth;
291         pPlanes[0].dwHeight = pSurface->dwHeight;
292         pPlanes[0].dwPitch  = pSurface->dwPitch;
293         break;
294 
295     case Format_411P:
296         *pdwNumPlanes = 3;
297 
298         pPlanes[0].dwWidth  = pSurface->dwWidth;
299         pPlanes[0].dwHeight = pSurface->dwHeight;
300         pPlanes[0].dwPitch  = pSurface->dwPitch;
301 
302         pPlanes[1].dwWidth  = pPlanes[0].dwWidth / 4;
303         pPlanes[1].dwHeight = pPlanes[0].dwHeight;
304         pPlanes[1].dwPitch  = pPlanes[0].dwPitch;
305 
306         pPlanes[2].dwWidth  = pPlanes[0].dwWidth / 4;
307         pPlanes[2].dwHeight = pPlanes[0].dwHeight;
308         pPlanes[2].dwPitch  = pPlanes[0].dwPitch;
309         break;
310 
311     case Format_411R:
312         *pdwNumPlanes = 3;
313 
314         pPlanes[0].dwWidth  = pSurface->dwWidth;
315         pPlanes[0].dwHeight = pSurface->dwHeight;
316         pPlanes[0].dwPitch  = pSurface->dwPitch;
317 
318         pPlanes[1].dwWidth  = pPlanes[0].dwWidth;
319         pPlanes[1].dwHeight = pPlanes[0].dwHeight / 4;
320         pPlanes[1].dwPitch  = pPlanes[0].dwPitch;
321 
322         pPlanes[2].dwWidth  = pPlanes[0].dwWidth;
323         pPlanes[2].dwHeight = pPlanes[0].dwHeight / 4;
324         pPlanes[2].dwPitch  = pPlanes[0].dwPitch;
325         break;
326 
327     case Format_422H:
328         *pdwNumPlanes = 3;
329 
330         pPlanes[0].dwWidth  = pSurface->dwWidth;
331         pPlanes[0].dwHeight = pSurface->dwHeight;
332         pPlanes[0].dwPitch  = pSurface->dwPitch;
333 
334         pPlanes[1].dwWidth  = pPlanes[0].dwWidth / 2;
335         pPlanes[1].dwHeight = pPlanes[0].dwHeight;
336         pPlanes[1].dwPitch  = pPlanes[0].dwPitch;
337 
338         pPlanes[2].dwWidth  = pPlanes[0].dwWidth / 2;
339         pPlanes[2].dwHeight = pPlanes[0].dwHeight;
340         pPlanes[2].dwPitch  = pPlanes[0].dwPitch;
341         break;
342 
343     case Format_422V:
344         *pdwNumPlanes = 3;
345 
346         pPlanes[0].dwWidth  = pSurface->dwWidth;
347         pPlanes[0].dwHeight = pSurface->dwHeight;
348         pPlanes[0].dwPitch  = pSurface->dwPitch;
349 
350         pPlanes[1].dwWidth  = pPlanes[0].dwWidth;
351         pPlanes[1].dwHeight = pPlanes[0].dwHeight / 2;
352         pPlanes[1].dwPitch  = pPlanes[0].dwPitch;
353 
354         pPlanes[2].dwWidth  = pPlanes[0].dwWidth;
355         pPlanes[2].dwHeight = pPlanes[0].dwHeight / 2;
356         pPlanes[2].dwPitch  = pPlanes[0].dwPitch;
357         break;
358 
359     case Format_444P:
360     case Format_RGBP:
361     case Format_BGRP:
362         *pdwNumPlanes = 3;
363 
364         pPlanes[0].dwWidth  = pSurface->dwWidth;
365         pPlanes[0].dwHeight = pSurface->dwHeight;
366         pPlanes[0].dwPitch  = pSurface->dwPitch;
367 
368         pPlanes[1].dwWidth  = pPlanes[0].dwWidth;
369         pPlanes[1].dwHeight = pPlanes[0].dwHeight;
370         pPlanes[1].dwPitch  = pPlanes[0].dwPitch;
371 
372         pPlanes[2].dwWidth  = pPlanes[0].dwWidth;
373         pPlanes[2].dwHeight = pPlanes[0].dwHeight;
374         pPlanes[2].dwPitch  = pPlanes[0].dwPitch;
375         break;
376 
377     case Format_Y210:
378     case Format_Y216:
379         *pdwNumPlanes = 1;
380 
381         pPlanes[0].dwWidth  = pSurface->dwWidth * 4;
382         pPlanes[0].dwHeight = pSurface->dwHeight;
383         pPlanes[0].dwPitch  = pSurface->dwPitch;
384         break;
385 
386     case Format_P210:
387     case Format_P216:
388         *pdwNumPlanes = 2;
389 
390         pPlanes[0].dwWidth  = pSurface->dwWidth * 2;
391         pPlanes[0].dwHeight = pSurface->dwHeight;
392         pPlanes[0].dwPitch  = pSurface->dwPitch;
393 
394         pPlanes[1].dwWidth  = pSurface->dwWidth * 2;
395         pPlanes[1].dwHeight = pSurface->dwHeight;
396         pPlanes[1].dwPitch  = pSurface->dwPitch;
397         break;
398 
399     default:
400         VPHAL_DEBUG_NORMALMESSAGE("input format is unclear for driver, using default 1 plane setting");
401         *pdwNumPlanes = 1;
402         pPlanes[0].dwWidth = pSurface->dwWidth;
403         pPlanes[0].dwHeight = pSurface->dwHeight;
404         pPlanes[0].dwPitch = pSurface->dwPitch;
405         break;
406     }
407 
408     // For Deswizzled surfaces, Mos_Specific_LockResource() already do the de-padding between Y and UV surf.
409     // so, don't use the info of U/V PlaneOffset, as the padding is already removed.
410     for (i = 0; i < *pdwNumPlanes; i++)
411     {
412         switch (i)
413         {
414         case 0:
415             pPlanes[i].dwOffset = pSurface->YPlaneOffset.iSurfaceOffset +
416                 (pSurface->YPlaneOffset.iYOffset * pSurface->dwPitch) +
417                 pSurface->YPlaneOffset.iXOffset;
418             break;
419         case 1:
420             if (pSurface->Format == Format_YV12)
421             {
422                 pPlanes[i].dwOffset = (isDeswizzled ? pPlanes[0].dwPitch * pPlanes[0].dwHeight + pPlanes[0].dwOffset : pSurface->VPlaneOffset.iSurfaceOffset) +
423                     (pSurface->VPlaneOffset.iYOffset * pSurface->dwPitch) +
424                     pSurface->VPlaneOffset.iXOffset;
425             }
426             else
427             {
428                 pPlanes[i].dwOffset = (isDeswizzled ? pPlanes[0].dwPitch * pPlanes[0].dwHeight + pPlanes[0].dwOffset : pSurface->UPlaneOffset.iSurfaceOffset) +
429                     (pSurface->UPlaneOffset.iYOffset * pSurface->dwPitch) +
430                     pSurface->UPlaneOffset.iXOffset;
431             }
432             break;
433         case 2:
434             if (pSurface->Format == Format_YV12)
435             {
436                 pPlanes[i].dwOffset = (isDeswizzled ? pPlanes[1].dwOffset + pPlanes[1].dwPitch * pPlanes[1].dwHeight : pSurface->UPlaneOffset.iSurfaceOffset) +
437                     (pSurface->UPlaneOffset.iYOffset * pSurface->dwPitch) +
438                     pSurface->UPlaneOffset.iXOffset;
439             }
440             else
441             {
442                 pPlanes[i].dwOffset = (isDeswizzled ? pPlanes[1].dwOffset + pPlanes[1].dwPitch * pPlanes[1].dwHeight : pSurface->VPlaneOffset.iSurfaceOffset) +
443                     (pSurface->VPlaneOffset.iYOffset * pSurface->dwPitch) +
444                     pSurface->VPlaneOffset.iXOffset;
445             }
446             break;
447         default:
448             VPHAL_DEBUG_ASSERTMESSAGE("More than 3 planes not supported.");
449         }
450     }
451 
452     //compressed surface need 32 align on height
453     if (auxEnable && !isDeswizzled)
454     {
455         for (i = 0; i < *pdwNumPlanes; i++)
456         {
457             pPlanes[i].dwHeight = MOS_ALIGN_CEIL(pPlanes[i].dwHeight, 32);
458         }
459     }
460 
461     // For uncompressed surface, padding data is not needed. For compressed surface, padding data is needed for offline check
462     if (auxEnable)
463     {
464         *pdwSize = (pPlanes[0].dwPitch * pPlanes[0].dwHeight) +
465                    (pPlanes[1].dwPitch * pPlanes[1].dwHeight) +
466                    (pPlanes[2].dwPitch * pPlanes[2].dwHeight);
467     }
468     else
469     {
470         *pdwSize = (pPlanes[0].dwWidth * pPlanes[0].dwHeight) +
471                    (pPlanes[1].dwWidth * pPlanes[1].dwHeight) +
472                    (pPlanes[2].dwWidth * pPlanes[2].dwHeight);
473     }
474 
475     return eStatus;
476 }
477 
HasAuxSurf(PMOS_RESOURCE osResource)478 bool VphalSurfaceDumper::HasAuxSurf(
479     PMOS_RESOURCE    osResource)
480 {
481     bool    hasAuxSurf = false;
482 #if !EMUL
483     GMM_RESOURCE_FLAG                   gmmFlags;
484 
485     MOS_ZeroMemory(&gmmFlags, sizeof(gmmFlags));
486     gmmFlags    = osResource->pGmmResInfo->GetResFlags();
487     hasAuxSurf  = (gmmFlags.Gpu.MMC && gmmFlags.Gpu.UnifiedAuxSurface) ||
488                   (gmmFlags.Gpu.CCS && gmmFlags.Gpu.UnifiedAuxSurface && gmmFlags.Info.MediaCompressed);
489 #endif
490     return hasAuxSurf;
491 }
492 
DumpSurfaceToFile(PMOS_INTERFACE pOsInterface,PVPHAL_SURFACE pSurface,const char * psPathPrefix,uint64_t iCounter,bool bLockSurface,bool bNoDecompWhenLock,uint8_t * pData)493 MOS_STATUS VphalSurfaceDumper::DumpSurfaceToFile(
494     PMOS_INTERFACE          pOsInterface,
495     PVPHAL_SURFACE          pSurface,
496     const char              *psPathPrefix,
497     uint64_t                iCounter,
498     bool                    bLockSurface,
499     bool                    bNoDecompWhenLock,
500     uint8_t*                pData)
501 {
502     MOS_STATUS                          eStatus;
503     bool                                isSurfaceLocked;
504     char                                sPath[MAX_PATH], sOsPath[MAX_PATH];
505     uint8_t                             *pDst, *pTmpSrc, *pTmpDst;
506     uint32_t                            dwNumPlanes, dwSize, j, i;
507     VPHAL_DBG_SURF_DUMP_SURFACE_DEF     planes[3];
508     uint32_t                            dstPlaneOffset[3] = {0};
509     MOS_LOCK_PARAMS                     LockFlags;
510     MOS_USER_FEATURE_VALUE_WRITE_DATA   UserFeatureWriteData;
511     bool                                hasAuxSurf;
512     bool                                enableAuxDump;
513     bool                                enablePlaneDump = false;
514     PMOS_RESOURCE                       pLockedResource = nullptr;
515     PVPHAL_SURFACE                      temp2DSurfForCopy = nullptr;
516     VPHAL_DEBUG_ASSERT(pSurface);
517     VPHAL_DEBUG_ASSERT(pOsInterface);
518     VPHAL_DEBUG_ASSERT(psPathPrefix);
519 
520     eStatus         = MOS_STATUS_SUCCESS;
521     isSurfaceLocked = false;
522     hasAuxSurf      = false;
523     pDst            = nullptr;
524     enableAuxDump   = m_dumpSpec.enableAuxDump;
525     MOS_ZeroMemory(sPath,   MAX_PATH);
526     MOS_ZeroMemory(sOsPath, MAX_PATH);
527     dwNumPlanes = 0;
528     enablePlaneDump = m_dumpSpec.enablePlaneDump;
529 
530     if (pSurface->dwDepth == 0)
531     {
532         pSurface->dwDepth = 1;
533     }
534 
535     hasAuxSurf = HasAuxSurf(&pSurface->OsResource);
536 
537     // get plane definitions
538     VPHAL_DEBUG_CHK_STATUS(GetPlaneDefs(
539         pSurface,
540         planes,
541         &dwNumPlanes,
542         &dwSize,
543         hasAuxSurf, //(hasAuxSurf && enableAuxDump),
544         !enableAuxDump));// !(hasAuxSurf && enableAuxDump)));
545 
546     if (bLockSurface)
547     {
548         // Caller should not give pData when it expect the function to lock surf
549         VPHAL_DEBUG_ASSERT(pData = nullptr);
550 
551         LockFlags.Value     = 0;
552         LockFlags.ReadOnly  = 1;
553 
554         // If aux data exist and enable aux dump, no swizzle and no decompress
555         if (hasAuxSurf && enableAuxDump)
556         {
557             LockFlags.TiledAsTiled = 1;
558             LockFlags.NoDecompress = 1;
559         }
560 
561         if (bNoDecompWhenLock)
562         {
563             LockFlags.NoDecompress = 1;
564         }
565 
566         bool isPlanar = false;
567 
568         isPlanar = (pSurface->Format == Format_NV12) || (pSurface->Format == Format_P010) || (pSurface->Format == Format_P016);
569         if (isPlanar && pSurface->TileType != MOS_TILE_LINEAR)
570         {
571             bool bAllocated;
572 
573             temp2DSurfForCopy = (PVPHAL_SURFACE)MOS_AllocAndZeroMemory(sizeof(VPHAL_SURFACE));
574             VPHAL_DEBUG_CHK_NULL(temp2DSurfForCopy);
575             VPHAL_RENDER_CHK_STATUS(VpHal_ReAllocateSurface(
576                 pOsInterface,
577                 temp2DSurfForCopy,
578                 "Temp2DSurfForSurfDumper",
579                 pSurface->Format,
580                 MOS_GFXRES_2D,
581                 MOS_TILE_LINEAR,
582                 pSurface->dwWidth,
583                 pSurface->dwHeight,
584                 false,
585                 MOS_MMC_DISABLED,
586                 &bAllocated));
587 
588             m_osInterface->pfnDoubleBufferCopyResource(
589                 m_osInterface,
590                 &pSurface->OsResource,
591                 &temp2DSurfForCopy->OsResource,
592                 false);
593 
594             pData = (uint8_t *)pOsInterface->pfnLockResource(
595                 pOsInterface,
596                 &temp2DSurfForCopy->OsResource,
597                 &LockFlags);
598             pLockedResource = &temp2DSurfForCopy->OsResource;
599 
600             // get plane definitions
601             VPHAL_DEBUG_CHK_STATUS(GetPlaneDefs(
602                 temp2DSurfForCopy,
603                 planes,
604                 &dwNumPlanes,
605                 &dwSize,
606                 hasAuxSurf,        //(hasAuxSurf && enableAuxDump),
607                 !enableAuxDump));  // !(hasAuxSurf && enableAuxDump)));
608         }
609         else
610         {
611             pData = (uint8_t *)pOsInterface->pfnLockResource(
612                 pOsInterface,
613                 &pSurface->OsResource,
614                 &LockFlags);
615             pLockedResource = &pSurface->OsResource;
616         }
617         VPHAL_DEBUG_CHK_NULL(pData);
618 
619         // Write error to user feauture key
620         eStatus = ReportUserSettingForDebug(
621             m_userSettingPtr,
622             __VPHAL_DBG_SURF_DUMPER_RESOURCE_LOCK,
623             1,
624             MediaUserSetting::Group::Device);
625 
626         VPHAL_DEBUG_ASSERT(eStatus == MOS_STATUS_SUCCESS);
627         isSurfaceLocked = true;
628     }
629 
630     MOS_SecureStringPrint(
631         sPath,
632         MAX_PATH,
633         sizeof(sPath),
634         "%s_f[%03lld]_w[%d]_h[%d]_p[%d].%s",
635         psPathPrefix,
636         iCounter,
637         pSurface->dwWidth,
638         pSurface->dwHeight,
639         pSurface->dwPitch,
640         VphalDumperTool::GetFormatStr(pSurface->Format));
641 
642     VphalDumperTool::GetOsFilePath(sPath, sOsPath);
643 
644     pDst = (uint8_t*)MOS_AllocAndZeroMemory(dwSize);
645     VPHAL_DEBUG_CHK_NULL(pDst);
646     VPHAL_DEBUG_CHK_NULL(pData);
647     pTmpSrc = pData;
648     pTmpDst = pDst;
649 
650     for (j = 0; j < dwNumPlanes; j++)
651     {
652         pTmpSrc = pData + planes[j].dwOffset;
653         for (i = 0; i < planes[j].dwHeight; i++)
654         {
655             if (hasAuxSurf && enableAuxDump)
656             {
657                 MOS_SecureMemcpy(
658                     pTmpDst,
659                     planes[j].dwPitch,
660                     pTmpSrc,
661                     planes[j].dwPitch);
662 
663                 pTmpSrc += planes[j].dwPitch;
664                 pTmpDst += planes[j].dwPitch;
665 
666                 dstPlaneOffset[j+1] += planes[j].dwPitch;
667             }
668             else
669             {
670                 MOS_SecureMemcpy(
671                     pTmpDst,
672                     planes[j].dwWidth,
673                     pTmpSrc,
674                     planes[j].dwWidth);
675 
676                 pTmpSrc += planes[j].dwPitch;
677                 pTmpDst += planes[j].dwWidth;
678 
679                 dstPlaneOffset[j+1] += planes[j].dwWidth;
680             }
681         }
682 
683         //if more than 1 plane, dump each plane's surface for offline analysis
684         if (enablePlaneDump)
685         {
686             if ((dwNumPlanes > 1) && (dwNumPlanes <= 3))
687             {
688                 char sPlanePath[MAX_PATH], sPlaneOsPath[MAX_PATH];
689                 MOS_ZeroMemory(sPlanePath, MAX_PATH);
690                 MOS_ZeroMemory(sPlaneOsPath, MAX_PATH);
691 
692                 MOS_SecureStringPrint(
693                     sPlanePath,
694                     MAX_PATH,
695                     sizeof(sPlanePath),
696                     "%s_f[%03lld]_w[%d]_h[%d]_p[%d].%s",
697                     psPathPrefix,
698                     iCounter,
699                     planes[j].dwWidth,
700                     planes[j].dwHeight,
701                     planes[j].dwPitch,
702                     (j == 0 ? "Y" : ((dwNumPlanes == 2) ? "UV" : ((j == 1) ? "U" : "V"))));
703 
704                 VphalDumperTool::GetOsFilePath(sPlanePath, sPlaneOsPath);
705 
706                 VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(sPlaneOsPath, pDst + dstPlaneOffset[j], dstPlaneOffset[j + 1]));
707             }
708             else
709             {
710                 VPHAL_DEBUG_ASSERTMESSAGE("More than 3 planes not supported during plane dump.");
711             }
712         }
713     }
714 
715     VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(sOsPath, pDst, dwSize));
716 
717 #if !EMUL
718     // Dump Aux surface data
719     if (hasAuxSurf && enableAuxDump)
720     {
721         uint32_t    resourceIndex;
722         bool        isPlanar;
723         uint8_t    *auxDataY;
724         uint8_t    *auxDataUV;
725         uint32_t    auxSizeY;
726         uint32_t    auxSizeUV;
727         uint8_t    *pSurfaceBase;
728 
729         resourceIndex = 0;
730         pSurfaceBase  = pData;
731         isPlanar      = (pOsInterface->pfnGetGmmClientContext(pOsInterface)->IsPlanar(pSurface->OsResource.pGmmResInfo->GetResourceFormat()) != 0);
732         auxDataY      = (uint8_t*)pSurfaceBase + pSurface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_Y_CCS);
733         auxDataUV     = (uint8_t*)pSurfaceBase + pSurface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_UV_CCS);
734         if (isPlanar)
735         {
736             auxSizeY = (uint32_t)(pSurface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_UV_CCS) -
737                 pSurface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_Y_CCS));
738         }else
739         {
740             auxSizeY = (uint32_t)(pSurface->OsResource.pGmmResInfo->GetSizeAuxSurface(GMM_AUX_CCS));
741         }
742 
743         auxSizeUV = (uint32_t)(pSurface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_COMP_STATE) -
744             pSurface->OsResource.pGmmResInfo->GetPlanarAuxOffset(resourceIndex, GMM_AUX_UV_CCS));
745 
746         if (auxSizeUV == 0)
747         {
748             auxSizeUV = (uint32_t)(pSurface->OsResource.pGmmResInfo->GetSizeAuxSurface(GMM_AUX_SURF)) /
749                 (pSurface->OsResource.pGmmResInfo)->GetArraySize() - auxSizeY;
750         }
751 
752         // Dump Y Aux data
753         MOS_SecureStringPrint(
754             sPath,
755             MAX_PATH,
756             sizeof(sPath),
757             "%s_f[%03lld]_w[%d]_h[%d]_p[%d].Yaux",
758             psPathPrefix,
759             iCounter,
760             pSurface->dwWidth,
761             pSurface->dwHeight,
762             pSurface->dwPitch);
763 
764         VphalDumperTool::GetOsFilePath(sPath, sOsPath);
765 
766         uint8_t  *pDstAux = (uint8_t*)MOS_AllocAndZeroMemory(auxSizeY);
767         VPHAL_DEBUG_CHK_NULL(pDstAux);
768 
769         MOS_SecureMemcpy(
770             pDstAux,
771             auxSizeY,
772             auxDataY,
773             auxSizeY);
774 
775         VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(sOsPath, pDstAux, auxSizeY));
776         MOS_SafeFreeMemory(pDstAux);
777 
778         if (auxSizeUV && isPlanar)
779         {
780             // Dump UV Aux data
781             MOS_SecureStringPrint(
782                 sPath,
783                 MAX_PATH,
784                 sizeof(sPath),
785                 "%s_f[%03lld]_w[%d]_h[%d]_p[%d].UVaux",
786                 psPathPrefix,
787                 iCounter,
788                 pSurface->dwWidth,
789                 pSurface->dwHeight,
790                 pSurface->dwPitch);
791 
792             VphalDumperTool::GetOsFilePath(sPath, sOsPath);
793 
794             uint8_t  *pDstUVAux = (uint8_t*)MOS_AllocAndZeroMemory(auxSizeUV);
795             VPHAL_DEBUG_CHK_NULL(pDstUVAux);
796 
797             MOS_SecureMemcpy(
798                 pDstUVAux,
799                 auxSizeUV,
800                 auxDataUV,
801                 auxSizeUV);
802 
803             VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(sOsPath, pDstUVAux, auxSizeUV));
804             MOS_SafeFreeMemory(pDstUVAux);
805         }
806     }
807 #endif
808 
809 finish:
810     MOS_SafeFreeMemory(pDst);
811 
812     if (isSurfaceLocked && pLockedResource != nullptr)
813     {
814         eStatus = (MOS_STATUS)pOsInterface->pfnUnlockResource(pOsInterface, pLockedResource);
815         VPHAL_DEBUG_ASSERT(eStatus == MOS_STATUS_SUCCESS);
816     }
817     if (temp2DSurfForCopy)
818     {
819         MOS_GFXRES_FREE_FLAGS resFreeFlags = {0};
820         if (IsSyncFreeNeededForMMCSurface(temp2DSurfForCopy, pOsInterface))
821         {
822             resFreeFlags.SynchronousDestroy = 1;
823         }
824         pOsInterface->pfnFreeResourceWithFlag(pOsInterface, &(temp2DSurfForCopy->OsResource), resFreeFlags.Value);
825     }
826     MOS_SafeFreeMemory(temp2DSurfForCopy);
827 
828     return eStatus;
829 }
830 
DefGsh(VPHAL_DBG_FIELD_LAYOUT ** ppGshLayout,uint32_t * puiNumGSHFields)831 MOS_STATUS VphalHwStateDumper::DefGsh(
832     VPHAL_DBG_FIELD_LAYOUT*  *ppGshLayout,
833     uint32_t*                puiNumGSHFields)
834 {
835     MOS_STATUS                      eStatus;
836     PRENDERHAL_STATE_HEAP           pStateHeap;
837     PRENDERHAL_STATE_HEAP_SETTINGS  pStateHeapSettings;
838     uint32_t                        i;
839     uint32_t                        j;
840 
841     // MEDIA STATE LAYOUT
842     VPHAL_DBG_FIELD_LAYOUT*         pmediaStateLayout;
843     uint32_t                        uiNumMediaStateFields;
844 
845     // GSH SAMPLER STATE LAYOUT
846     VPHAL_DBG_FIELD_LAYOUT*         psamplerStateLayout;
847     uint32_t                        uiNumSamplerStateFields;
848 
849     eStatus             = MOS_STATUS_SUCCESS;
850     pStateHeap          = m_stateHeap;
851     pStateHeapSettings  = m_stateHeapSettings;
852 
853     // GSH LAYOUT
854     *puiNumGSHFields = 4;
855     (*ppGshLayout) = (VPHAL_DBG_FIELD_LAYOUT*)MOS_AllocAndZeroMemory(
856                         sizeof(VPHAL_DBG_FIELD_LAYOUT) *
857                                                             (*puiNumGSHFields));
858     VPHAL_DEBUG_CHK_NULL((*ppGshLayout));
859     i = 0;
860 
861     MOS_SecureStringPrint((*ppGshLayout)[i].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Sync/Perf Tags (SY)");
862     (*ppGshLayout)[i].dwOffset      = pStateHeap->dwOffsetSync;
863     (*ppGshLayout)[i].dwSize        = pStateHeap->dwSizeSync;
864     (*ppGshLayout)[i].uiNumber      = 1;
865     (*ppGshLayout)[i].pChildLayout  = nullptr;
866     (*ppGshLayout)[i].uiNumChildren = 0;
867     MOS_SecureStringPrint((*ppGshLayout)[i++].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "");
868 
869     MOS_SecureStringPrint((*ppGshLayout)[i].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Media State");
870     (*ppGshLayout)[i].dwOffset      = pStateHeap->pMediaStates->dwOffset;
871     (*ppGshLayout)[i].dwSize        = pStateHeap->dwOffsetMediaID +
872                                       pStateHeapSettings->iMediaIDs *
873                                       pStateHeap->dwSizeMediaID;
874     (*ppGshLayout)[i].uiNumber      = pStateHeapSettings->iMediaStateHeaps;
875     // MEDIA STATE LAYOUT -- Indented to make hierarchy clear
876     {
877         uiNumMediaStateFields = 6;
878         pmediaStateLayout = (VPHAL_DBG_FIELD_LAYOUT*)MOS_AllocAndZeroMemory(
879                                 sizeof(VPHAL_DBG_FIELD_LAYOUT) *
880                                                    uiNumMediaStateFields);
881         VPHAL_DEBUG_CHK_NULL(pmediaStateLayout);
882         j = 0;
883 
884         MOS_SecureStringPrint(pmediaStateLayout[j].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "CURBE Data");
885         pmediaStateLayout[j].dwOffset      = pStateHeap->dwOffsetCurbe;
886         pmediaStateLayout[j].dwSize        = pStateHeap->dwSizeCurbe;
887         pmediaStateLayout[j].uiNumber      = 1;
888         pmediaStateLayout[j].pChildLayout  = nullptr;
889         pmediaStateLayout[j].uiNumChildren = 0;
890         MOS_SecureStringPrint(pmediaStateLayout[j++].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "");
891 
892         MOS_SecureStringPrint(pmediaStateLayout[j].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Sampler States for MID");
893         pmediaStateLayout[j].dwOffset      = pStateHeap->dwOffsetSampler;
894         pmediaStateLayout[j].dwSize        = m_hwSizes->dwSizeSamplerState *
895                                              pStateHeapSettings->iSamplers;
896         pmediaStateLayout[j].uiNumber      = pStateHeapSettings->iMediaIDs;
897         // GSH SAMPLER STATE LAYOUT -- Indented to make hierarchy clear
898         {
899             uiNumSamplerStateFields = 1;
900             psamplerStateLayout = (VPHAL_DBG_FIELD_LAYOUT*)MOS_AllocAndZeroMemory(
901                                sizeof(VPHAL_DBG_FIELD_LAYOUT) * uiNumSamplerStateFields);
902             VPHAL_DEBUG_CHK_NULL(psamplerStateLayout);
903 
904             MOS_SecureStringPrint(psamplerStateLayout[0].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Sampler State");
905             psamplerStateLayout[0].dwOffset      = 0;
906             psamplerStateLayout[0].dwSize        = m_hwSizes->dwSizeSamplerState;
907             psamplerStateLayout[0].uiNumber      = pStateHeapSettings->iSamplers;
908             psamplerStateLayout[0].pChildLayout  = nullptr;
909             psamplerStateLayout[0].uiNumChildren = 0;
910             MOS_SecureStringPrint(psamplerStateLayout[0].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_SAMPLER_STATE_");
911         }
912 
913         pmediaStateLayout[j].pChildLayout  = psamplerStateLayout;
914         pmediaStateLayout[j].uiNumChildren = uiNumSamplerStateFields;
915         MOS_SecureStringPrint(pmediaStateLayout[j++].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "");
916 
917         MOS_SecureStringPrint(pmediaStateLayout[j].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Sampler 8x8 Table");
918         pmediaStateLayout[j].dwOffset      = pStateHeap->dwOffsetSamplerAVS;
919         pmediaStateLayout[j].dwSize        = pStateHeap->dwSizeSamplerAVS;
920         pmediaStateLayout[j].uiNumber      = pStateHeapSettings->iSamplersAVS;
921         pmediaStateLayout[j].pChildLayout  = nullptr;
922         pmediaStateLayout[j].uiNumChildren = 0;
923         MOS_SecureStringPrint(pmediaStateLayout[j++].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_SAMPLER_8x8_STATE_TABLE_");
924 
925         MOS_SecureStringPrint(pmediaStateLayout[j].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Media ID");
926         pmediaStateLayout[j].dwOffset      = pStateHeap->dwOffsetMediaID;
927         pmediaStateLayout[j].dwSize        = pStateHeap->dwSizeMediaID;
928         pmediaStateLayout[j].uiNumber      = pStateHeapSettings->iMediaIDs;
929         pmediaStateLayout[j].pChildLayout  = nullptr;
930         pmediaStateLayout[j].uiNumChildren = 0;
931         MOS_SecureStringPrint(pmediaStateLayout[j++].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_INTERFACE_DESCRIPTOR_DATA_");
932     }
933 
934     (*ppGshLayout)[i].pChildLayout  = pmediaStateLayout;
935     (*ppGshLayout)[i].uiNumChildren = uiNumMediaStateFields;
936     MOS_SecureStringPrint((*ppGshLayout)[i++].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "");
937 
938     MOS_SecureStringPrint((*ppGshLayout)[i].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Kernel");
939     (*ppGshLayout)[i].dwOffset      = pStateHeap->dwKernelBase;
940     (*ppGshLayout)[i].dwSize        = pStateHeap->iKernelSize / pStateHeapSettings->iKernelCount;
941     (*ppGshLayout)[i].uiNumber      = pStateHeapSettings->iKernelCount;
942     (*ppGshLayout)[i].pChildLayout  = nullptr;
943     (*ppGshLayout)[i].uiNumChildren = 0;
944     MOS_SecureStringPrint((*ppGshLayout)[i++].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "");
945 
946 finish:
947     return eStatus;
948 }
949 
DefSsh(VPHAL_DBG_FIELD_LAYOUT ** ppSshLayout,uint32_t * puiNumSSHFields)950 MOS_STATUS VphalHwStateDumper::DefSsh(
951     VPHAL_DBG_FIELD_LAYOUT*  *ppSshLayout,
952     uint32_t*                puiNumSSHFields)
953 {
954     MOS_STATUS                      eStatus;
955     PRENDERHAL_STATE_HEAP           pStateHeap;
956     PRENDERHAL_STATE_HEAP_SETTINGS  pStateHeapSettings;
957     uint32_t                        i;
958     int32_t                         k;
959 
960     // BINDING TABLE LAYOUT
961     VPHAL_DBG_FIELD_LAYOUT*         pbtLayout;
962     uint32_t                        uiNumBTFields;
963 
964     eStatus   = MOS_STATUS_SUCCESS;
965     pStateHeap          = m_stateHeap;
966     pStateHeapSettings  = m_stateHeapSettings;
967 
968     // SSH LAYOUT
969     (*puiNumSSHFields) = 1 + pStateHeapSettings->iSurfaceStates;
970     (*ppSshLayout) = (VPHAL_DBG_FIELD_LAYOUT*)MOS_AllocAndZeroMemory(sizeof(VPHAL_DBG_FIELD_LAYOUT) *
971                                                             (*puiNumSSHFields));
972     VPHAL_DEBUG_CHK_NULL((*ppSshLayout));
973     i = 0;
974 
975     MOS_SecureStringPrint((*ppSshLayout)[i].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Binding Table");
976     (*ppSshLayout)[i].dwOffset      = pStateHeap->iBindingTableOffset;
977     (*ppSshLayout)[i].dwSize        = pStateHeap->iBindingTableSize;
978     (*ppSshLayout)[i].uiNumber      = pStateHeapSettings->iBindingTables;
979     // BINDING TABLE LAYOUT -- Indented to make hierarchy clear
980     {
981         pbtLayout = (VPHAL_DBG_FIELD_LAYOUT*)MOS_AllocAndZeroMemory(sizeof(VPHAL_DBG_FIELD_LAYOUT) * 1);
982         VPHAL_DEBUG_CHK_NULL(pbtLayout);
983         uiNumBTFields = 1;
984         MOS_SecureStringPrint(pbtLayout[0].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Binding Index");
985         pbtLayout[0].dwOffset      = pStateHeap->iBindingTableOffset;
986         pbtLayout[0].dwSize        = pStateHeap->iBindingTableSize / pStateHeapSettings->iSurfacesPerBT;
987         pbtLayout[0].uiNumber      = pStateHeapSettings->iSurfacesPerBT;
988         pbtLayout[0].pChildLayout  = nullptr;
989         pbtLayout[0].uiNumChildren = 0;
990         MOS_SecureStringPrint(pbtLayout[0].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_BINDING_TABLE_STATE_");
991     }
992 
993     (*ppSshLayout)[i].pChildLayout  = pbtLayout;
994     (*ppSshLayout)[i].uiNumChildren = 1;
995     MOS_SecureStringPrint((*ppSshLayout)[i++].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "");
996 
997     for (k = 0; k < pStateHeapSettings->iSurfaceStates; k++)
998     {// Not indented to make hierarchy levels clear
999     MOS_SecureStringPrint((*ppSshLayout)[i+k].pcName, MAX_NAME_LEN, MAX_NAME_LEN, "Surface State %d", k);
1000     (*ppSshLayout)[i+k].dwOffset      = pStateHeap->iSurfaceStateOffset +
1001                                         m_renderHal->pRenderHalPltInterface->GetSurfaceStateCmdSize() * k;
1002     (*ppSshLayout)[i+k].dwSize        = m_renderHal->pRenderHalPltInterface->GetSurfaceStateCmdSize();
1003     (*ppSshLayout)[i+k].uiNumber      = 1;
1004     (*ppSshLayout)[i+k].pChildLayout  = nullptr;
1005     (*ppSshLayout)[i+k].uiNumChildren = 0;
1006 
1007     switch(pStateHeap->pSurfaceEntry[k].Type)
1008     {
1009         case RENDERHAL_SURFACE_TYPE_G8:
1010             MOS_SecureStringPrint((*ppSshLayout)[i+k].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_SURFACE_STATE_G8");
1011             break;
1012         case RENDERHAL_SURFACE_TYPE_G9:
1013             MOS_SecureStringPrint((*ppSshLayout)[i+k].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_SURFACE_STATE_G9");
1014             break;
1015         case RENDERHAL_SURFACE_TYPE_G10:
1016             MOS_SecureStringPrint((*ppSshLayout)[i+k].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_SURFACE_STATE_G10");
1017             break;
1018         case RENDERHAL_SURFACE_TYPE_ADV_G8:
1019             MOS_SecureStringPrint((*ppSshLayout)[i+k].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_SURFACE_STATE_ADV_G8");
1020             break;
1021         case RENDERHAL_SURFACE_TYPE_ADV_G9:
1022             MOS_SecureStringPrint((*ppSshLayout)[i+k].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_SURFACE_STATE_ADV_G9");
1023             break;
1024         case RENDERHAL_SURFACE_TYPE_ADV_G10:
1025             MOS_SecureStringPrint((*ppSshLayout)[i+k].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "_SURFACE_STATE_ADV_G10");
1026             break;
1027         case RENDERHAL_SURFACE_TYPE_INVALID:
1028             MOS_SecureStringPrint((*ppSshLayout)[i+k].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "No surface");
1029             break;
1030         default:
1031             // When type is zero, its un-initialized, so just show string of DW
1032             VPHAL_DEBUG_ASSERT(0);
1033             MOS_SecureStringPrint((*ppSshLayout)[i+k].pcStructName, MAX_NAME_LEN, MAX_NAME_LEN, "");
1034             break;
1035     } // Not indented to make hierarchy clear
1036     }
1037 
1038 finish:
1039     return eStatus;
1040 }
1041 
FreeLayout(VPHAL_DBG_FIELD_LAYOUT * pLayout,uint32_t uiNumFields)1042 void VphalHwStateDumper::FreeLayout(
1043     VPHAL_DBG_FIELD_LAYOUT   *pLayout,
1044     uint32_t                 uiNumFields)
1045 {
1046     uint32_t    i;
1047 
1048     for (i = 0; i < uiNumFields; i++)
1049     {
1050         if (pLayout[i].pChildLayout != nullptr)
1051         {
1052             FreeLayout(pLayout[i].pChildLayout, pLayout[i].uiNumChildren);
1053         }
1054     }
1055     MOS_SafeFreeMemory(pLayout);
1056 }
1057 
DumpXmlFieldHeader(char ** ppcOutContents,char * pcName,uint32_t ulLoc,uint32_t ulSize,bool bIsByte,bool bHasCont,bool bStruct)1058 MOS_STATUS VphalHwStateDumper::DumpXmlFieldHeader(
1059     char        **ppcOutContents,
1060     char        *pcName,
1061     uint32_t    ulLoc,
1062     uint32_t    ulSize,
1063     bool        bIsByte,
1064     bool        bHasCont,
1065     bool        bStruct)
1066 {
1067     MOS_STATUS eStatus;
1068 
1069     MOS_UNUSED(bHasCont);
1070 
1071     eStatus = MOS_STATUS_SUCCESS;
1072 
1073     if (!ppcOutContents)
1074     {
1075         eStatus = MOS_STATUS_INVALID_PARAMETER;
1076         goto finish;
1077     }
1078 
1079     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, ppcOutContents,
1080         "<FIELD%s><NAME>%s</NAME><LOC>0x%x</LOC><SIZE unit=\"%s\">0x%x</SIZE>\r\n",
1081         bStruct ? " struct=\"TRUE\"" : "", pcName, ulLoc,
1082         bIsByte ? "byte" : "bit", ulSize));
1083 
1084 finish:
1085     return eStatus;
1086 }
1087 
DumpXmlFieldFooter(char ** ppcOutContents,bool bHasCont)1088 MOS_STATUS VphalHwStateDumper::DumpXmlFieldFooter(
1089     char   **ppcOutContents,
1090     bool   bHasCont)
1091 {
1092     MOS_STATUS eStatus;
1093 
1094     MOS_UNUSED(bHasCont);
1095 
1096     eStatus = MOS_STATUS_SUCCESS;
1097 
1098     if (!ppcOutContents)
1099     {
1100         eStatus = MOS_STATUS_INVALID_PARAMETER;
1101         goto finish;
1102     }
1103 
1104     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, ppcOutContents, "</FIELD>\r\n"));
1105 
1106 finish:
1107     return eStatus;
1108 }
1109 
DumpDwords(char ** ppcOutContents,uint32_t dwSizeField)1110 MOS_STATUS VphalHwStateDumper::DumpDwords(
1111     char      **ppcOutContents,
1112     uint32_t  dwSizeField)
1113 {
1114     MOS_STATUS  eStatus;
1115     char*       pcName;
1116     int32_t     iNumFields;
1117     int32_t     iDWSize;
1118     int32_t     iOffset;
1119     int32_t     i;
1120 
1121     eStatus    = MOS_STATUS_SUCCESS;
1122     pcName     = nullptr;
1123     iNumFields = 0;
1124     iDWSize    = 0;
1125     iOffset    = 0;
1126     i          = 0;
1127 
1128     if (!ppcOutContents)
1129     {
1130         eStatus = MOS_STATUS_INVALID_PARAMETER;
1131         goto finish;
1132     }
1133 
1134     VPHAL_DEBUG_ASSERT(dwSizeField % sizeof(uint32_t) == 0);
1135 
1136     pcName = (char*)MOS_AllocAndZeroMemory(MAX_DW_STRLEN);
1137     VPHAL_DEBUG_CHK_NULL(pcName);
1138 
1139     iNumFields = MOS_BYTES_TO_DWORDS(dwSizeField);//Change macro to >> 2 if optimizer doesn't
1140     iDWSize    = sizeof(uint32_t);
1141 
1142     for (i = 0; i < iNumFields; i++)
1143     {
1144         MOS_SecureStringPrint(pcName, MAX_DW_STRLEN, MAX_DW_STRLEN, "DW%d", i);
1145         VPHAL_DEBUG_CHK_STATUS(DumpXmlFieldHeader(ppcOutContents, pcName, iOffset,
1146                                                iDWSize, true, false, false));
1147         VPHAL_DEBUG_CHK_STATUS(DumpXmlFieldFooter(ppcOutContents, false));;
1148         iOffset += iDWSize;
1149     }
1150 
1151 finish:
1152     MOS_SafeFreeMemory(pcName);
1153     return eStatus;
1154 }
1155 
DumpFieldHeap(char ** ppcOutContents,VPHAL_DBG_FIELD_LAYOUT * parLayout)1156 MOS_STATUS VphalHwStateDumper::DumpFieldHeap(
1157     char                     **ppcOutContents,
1158     VPHAL_DBG_FIELD_LAYOUT   *parLayout)
1159 {
1160     MOS_STATUS  eStatus;
1161     char*       pcName;
1162     int32_t     iOffset;
1163     uint32_t    i;
1164 
1165     eStatus = MOS_STATUS_SUCCESS;
1166     pcName  = nullptr;
1167     iOffset = 0;
1168     i       = 0;
1169 
1170     if (!ppcOutContents || !parLayout)
1171     {
1172         eStatus = MOS_STATUS_INVALID_PARAMETER;
1173         goto finish;
1174     }
1175 
1176     pcName = (char*)MOS_AllocAndZeroMemory(MAX_NAME_LEN);
1177     VPHAL_DEBUG_CHK_NULL(pcName);
1178 
1179     // For each instance of this field type
1180     for (i = 0; i < parLayout->uiNumber; i++)
1181     {
1182         MOS_SecureStringPrint(pcName, MAX_NAME_LEN, MAX_NAME_LEN, "%s %d", parLayout->pcName, i);
1183         VPHAL_DEBUG_CHK_STATUS(DumpXmlFieldHeader(ppcOutContents, pcName, iOffset,
1184                                                parLayout->dwSize, true, true,
1185                                                false));
1186         VPHAL_DEBUG_CHK_STATUS(DumpSubfields(ppcOutContents, parLayout, parLayout->pChildLayout,
1187                                         parLayout->uiNumChildren));
1188         VPHAL_DEBUG_CHK_STATUS(DumpXmlFieldFooter(ppcOutContents, true));
1189         iOffset += parLayout->dwSize;
1190     }
1191 
1192 finish:
1193     MOS_SafeFreeMemory(pcName);
1194     return eStatus;
1195 }
1196 
DumpSubfields(char ** ppcOutContents,VPHAL_DBG_FIELD_LAYOUT * pParLayout,VPHAL_DBG_FIELD_LAYOUT * pChildLayout,uint32_t uiNumChild)1197 MOS_STATUS VphalHwStateDumper::DumpSubfields(
1198     char                     **ppcOutContents,
1199     VPHAL_DBG_FIELD_LAYOUT*  pParLayout,
1200     VPHAL_DBG_FIELD_LAYOUT*  pChildLayout,
1201     uint32_t                 uiNumChild)
1202 {
1203     MOS_STATUS  eStatus;
1204     uint32_t    i;
1205 
1206     eStatus = MOS_STATUS_SUCCESS;
1207     i       = 0;
1208 
1209     if (!ppcOutContents || (!pParLayout && uiNumChild == 0) ||
1210         (!pChildLayout && uiNumChild > 0))
1211     {
1212         eStatus = MOS_STATUS_INVALID_PARAMETER;
1213         goto finish;
1214     }
1215 
1216     if (uiNumChild > 0)
1217     {
1218         for (i = 0; i < uiNumChild; i++)
1219         {
1220             if (pChildLayout[i].uiNumber > 0)
1221             {
1222                 VPHAL_DEBUG_CHK_STATUS(DumpField(ppcOutContents, &(pChildLayout[i])));
1223             }// end if exists
1224         }// end for each field
1225     }// if has fields
1226     else if (pParLayout->pcStructName[0] != '\0')
1227     {
1228         // second last param is not zero in such cases as 8x8 table
1229         // (arrays, multi structs) -- this is now handled by indirect recursion
1230 
1231         VPHAL_DEBUG_CHK_STATUS(DumpXmlFieldHeader(ppcOutContents, pParLayout->pcStructName,
1232                                                0, pParLayout->dwSize, true,
1233                                                false, true));
1234         VPHAL_DEBUG_CHK_STATUS(DumpXmlFieldFooter(ppcOutContents, false));
1235     }
1236     else
1237     {
1238         // Skip uint32_t dumping for kernel section
1239         if (strcmp(pParLayout->pcName, KERNEL_FIELD_NAME) != 0)
1240         {
1241             VPHAL_DEBUG_CHK_STATUS(DumpDwords(ppcOutContents, pParLayout->dwSize));
1242         }
1243     }
1244 
1245 finish:
1246     return eStatus;
1247 }
1248 
DumpField(char ** ppcOutContents,VPHAL_DBG_FIELD_LAYOUT * pLayout)1249 MOS_STATUS VphalHwStateDumper::DumpField(
1250     char                     **ppcOutContents,
1251     VPHAL_DBG_FIELD_LAYOUT*  pLayout)
1252 {
1253     MOS_STATUS  eStatus;
1254     char*       pcName;
1255 
1256     eStatus = MOS_STATUS_SUCCESS;
1257     pcName  = nullptr;
1258 
1259     if (!ppcOutContents || !pLayout)
1260     {
1261         eStatus = MOS_STATUS_INVALID_PARAMETER;
1262         goto finish;
1263     }
1264 
1265     // Header
1266     pcName = (char*)MOS_AllocAndZeroMemory(MAX_NAME_LEN);
1267     VPHAL_DEBUG_CHK_NULL(pcName);
1268 
1269     if (pLayout->uiNumber > 1)
1270     {
1271         MOS_SecureStringPrint(pcName, MAX_NAME_LEN, MAX_NAME_LEN, "%s Heap", pLayout->pcName);
1272     }
1273     else
1274     {
1275         MOS_SecureStringPrint(pcName, MAX_NAME_LEN, MAX_NAME_LEN, "%s", pLayout->pcName);
1276     }
1277     VPHAL_DEBUG_CHK_STATUS(DumpXmlFieldHeader(ppcOutContents, pcName, pLayout->dwOffset,
1278                                            pLayout->dwSize * pLayout->uiNumber,
1279                                            true, true, false));
1280 
1281     // Contents
1282     if (pLayout->uiNumber > 1)
1283     {
1284         VPHAL_DEBUG_CHK_STATUS(DumpFieldHeap(ppcOutContents, pLayout));
1285     }
1286     else
1287     {
1288         VPHAL_DEBUG_CHK_STATUS(DumpSubfields(ppcOutContents, pLayout, pLayout->pChildLayout,
1289                                         pLayout->uiNumChildren));
1290     }
1291 
1292     // footer
1293     VPHAL_DEBUG_CHK_STATUS(DumpXmlFieldFooter(ppcOutContents, true));
1294 
1295 finish:
1296     return eStatus;
1297 }
1298 
GetLastFieldIndex(VPHAL_DBG_FIELD_LAYOUT fl[],uint32_t uiNumFields,uint32_t * puiLastIndex)1299 void VphalHwStateDumper::GetLastFieldIndex(
1300     VPHAL_DBG_FIELD_LAYOUT  fl[],
1301     uint32_t                uiNumFields,
1302     uint32_t                *puiLastIndex)
1303 {
1304     uint32_t    i;
1305 
1306     i  = 0;
1307 
1308     if (uiNumFields < 1)
1309     {
1310         puiLastIndex = nullptr;
1311     }
1312     else
1313     {
1314         *puiLastIndex = 0;
1315         for (i = 1; i < uiNumFields; i++)
1316         {
1317             if (fl[i].dwOffset > fl[*puiLastIndex].dwOffset)
1318             {
1319                 *puiLastIndex = i;
1320             }
1321         }
1322     }
1323 }
1324 
CheckPath(char ** ppcPath)1325 MOS_STATUS VphalHwStateDumper::CheckPath(
1326     char* *ppcPath)
1327 {
1328     MOS_STATUS  eStatus;
1329     size_t      iStrLen;
1330     char*       pcTmpPtr;
1331 
1332     eStatus  = MOS_STATUS_SUCCESS;
1333     iStrLen  = 0;
1334     pcTmpPtr = nullptr;
1335 
1336     if (!ppcPath || !*ppcPath)
1337     {
1338         eStatus = MOS_STATUS_INVALID_PARAMETER;
1339         goto finish;
1340     }
1341 
1342     iStrLen = strlen(*ppcPath);
1343     if (iStrLen > 1)
1344     {
1345         if (((*ppcPath)[iStrLen - 1] == '\\') || ((*ppcPath)[iStrLen - 1] == '/'))
1346         {
1347             (*ppcPath)[iStrLen - 1] = '\0';
1348         }
1349     }
1350 
1351 finish:
1352     return eStatus;
1353 }
1354 
WhitespaceTrim(char * ptr)1355 char* VphalSurfaceDumper::WhitespaceTrim(
1356     char*   ptr)
1357 {
1358     char*    pcTemp;                             // pointer to temp string to remove spces
1359 
1360     VPHAL_DEBUG_ASSERT(ptr);
1361 
1362     if(strlen(ptr) == 0)
1363     {
1364         goto finish;
1365     }
1366 
1367     //remove left spaces
1368     while (*ptr == ' ' || *ptr == '\t')
1369     {
1370         ptr++;
1371     }
1372 
1373     //remove right spaces
1374     pcTemp = ptr + strlen(ptr)-1;
1375     while(*pcTemp == ' '|| *pcTemp == '\t')
1376     {
1377         pcTemp--;
1378     }
1379     *(++pcTemp) = '\0';
1380 
1381 finish:
1382     return ptr;
1383 }
1384 
1385 //------------------------------------------------------------------------------
1386 //
1387 //    TOP LEVEL FUNCTIONS
1388 // These are for dumping structures and binary data.
1389 // Many of these will be called directly from the driver.
1390 //
1391 //------------------------------------------------------------------------------
1392 
DumpBinaryStruct(VPHAL_DBG_FIELD_LAYOUT * fields,uint32_t uiNumFields,void * pvStructToDump,char * pcPath,PCCHAR pcName,int32_t iID)1393 MOS_STATUS VphalHwStateDumper::DumpBinaryStruct(
1394     VPHAL_DBG_FIELD_LAYOUT*  fields,
1395     uint32_t                 uiNumFields,
1396     void                     *pvStructToDump,
1397     char*                    pcPath,
1398     PCCHAR                   pcName,
1399     int32_t                  iID)
1400 {
1401     MOS_STATUS  eStatus;
1402     uint32_t    lLastFieldOffset;
1403     uint32_t    lLastFieldSize;
1404     uint32_t    lSize;
1405     uint32_t    uiLastIndex;
1406     int32_t     iStrLenPath;
1407     int32_t     iStrLenName;
1408     char*       pcOutFileName;
1409     char*       pcOutContents;
1410     char        pcTargetFileName[MAX_PATH];
1411 
1412     eStatus          = MOS_STATUS_SUCCESS;
1413     lLastFieldOffset = 0;
1414     lLastFieldSize   = 0;
1415     lSize            = 0;
1416     uiLastIndex      = 0;
1417     iStrLenPath      = 0;
1418     iStrLenName      = 0;
1419     pcOutFileName    = nullptr;
1420     pcOutContents    = nullptr;
1421     memset(pcTargetFileName, '\0', MAX_PATH);
1422 
1423     VPHAL_DEBUG_CHK_STATUS(VphalHwStateDumper::CheckPath(&pcPath));
1424 
1425     pcOutFileName = (char*)MOS_AllocAndZeroMemory(sizeof(char) * MAX_PATH);
1426     VPHAL_DEBUG_CHK_NULL(pcOutFileName);
1427     MOS_SecureStringPrint(pcOutFileName, MAX_PATH, MAX_PATH, "%s%s_%d.bin", pcPath, pcName, iID);
1428 
1429     GetLastFieldIndex(fields, uiNumFields, &uiLastIndex);
1430     lLastFieldOffset = fields[uiLastIndex].dwOffset;
1431     lLastFieldSize   = fields[uiLastIndex].dwSize;
1432     lSize            = lLastFieldOffset + lLastFieldSize;
1433 
1434     VphalDumperTool::GetOsFilePath(pcOutFileName, pcTargetFileName);
1435     VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(pcTargetFileName, pvStructToDump, lSize));
1436 
1437 finish:
1438     MOS_SafeFreeMemory(pcOutFileName);
1439     MOS_SafeFreeMemory(pcOutContents);
1440     return eStatus;
1441 }
1442 
DumpBatchBufferBinary(PMHW_BATCH_BUFFER pBatchBuffer,const char * pcFileLoc,int32_t iID)1443 MOS_STATUS VphalHwStateDumper::DumpBatchBufferBinary(
1444     PMHW_BATCH_BUFFER    pBatchBuffer,
1445     const char*          pcFileLoc,
1446     int32_t              iID)
1447 {
1448     MOS_STATUS             eStatus;
1449     VPHAL_DBG_FIELD_LAYOUT field;
1450     char*                  pcPath;
1451     size_t                 iStrLen;
1452     bool                   bLockNeeded;
1453 
1454     eStatus     = MOS_STATUS_SUCCESS;
1455     pcPath      = nullptr;
1456     iStrLen     = 0;
1457     bLockNeeded = false;
1458 
1459     if (!pBatchBuffer->pData)
1460     {
1461         bLockNeeded = true;
1462         VPHAL_DEBUG_CHK_STATUS(m_renderHal->pfnLockBB(m_renderHal, pBatchBuffer));
1463     }
1464 
1465     iStrLen = strlen(pcFileLoc) + 1;
1466 
1467     field.dwOffset      = 0;
1468     field.uiNumChildren = 0;
1469     field.uiNumber      = 1;
1470 
1471     pcPath = (char*)MOS_AllocAndZeroMemory(sizeof(char) * iStrLen);
1472     VPHAL_DEBUG_CHK_NULL(pcPath);
1473     MOS_SecureStringPrint(pcPath, iStrLen, iStrLen, "%s", pcFileLoc);
1474     VPHAL_DEBUG_CHK_STATUS(VphalHwStateDumper::CheckPath(&pcPath));
1475 
1476     field.dwSize = pBatchBuffer->iSize;
1477     VPHAL_DEBUG_CHK_STATUS(DumpBinaryStruct(&field, 1,
1478                                         pBatchBuffer->pData,
1479                                         pcPath, "BB", iID));
1480 
1481     if (bLockNeeded)
1482     {
1483         VPHAL_DEBUG_CHK_STATUS(m_renderHal->pfnUnlockBB(m_renderHal, pBatchBuffer));
1484     }
1485 
1486 finish:
1487     MOS_SafeFreeMemory(pcPath);
1488     return eStatus;
1489 }
1490 
DumpCommandBufferBinary(PMOS_COMMAND_BUFFER pCmd_buff,const char * pcFileLoc,int32_t iID)1491 MOS_STATUS VphalHwStateDumper::DumpCommandBufferBinary(
1492     PMOS_COMMAND_BUFFER    pCmd_buff,
1493     const char*            pcFileLoc,
1494     int32_t                iID)
1495 {
1496     /*
1497         MOS_COMMAND_BUFFER
1498 
1499     DW0,DW1,DW2,DW3,DW4,DW5,DW6,      ...
1500     /-------------------------------------------------------------------------\
1501     |   |   |   |   |   |   |                                                 |
1502     |   |   |   |   |   |   |         ....                                    |
1503     |   |   |   |   |   |   |                                                 |
1504     |   |   |   |   |   |   |                                                 |
1505     \-------------------------------------------------------------------------/
1506     |\_________________/|\___________________________________________________/
1507     |        |          |                           |
1508 pCmdBase  iOffset    pCmdPtr                      iRemaining
1509 
1510     pCmdBase  : First command in the buffer
1511     pCmdPtr   : End of current command (place to put next command)
1512     iOffset   : Space being used by commands (pCmdPtr - pCmdBase)
1513     iRemaining: Space left for comments till end of buffer
1514     */
1515 
1516     MOS_STATUS             eStatus;
1517     VPHAL_DBG_FIELD_LAYOUT field;
1518     char*                  pcPath;
1519     size_t                 iStrLen;
1520 
1521     eStatus = MOS_STATUS_SUCCESS;
1522     pcPath  = nullptr;
1523     iStrLen = strlen(pcFileLoc) + 1;
1524 
1525     field.dwOffset      = 0;
1526     field.uiNumber      = 1;
1527     field.uiNumChildren = 0;
1528     field.dwSize        = pCmd_buff->iOffset;
1529 
1530     pcPath = (char*)MOS_AllocAndZeroMemory(sizeof(char) * iStrLen);
1531     VPHAL_DEBUG_CHK_NULL(pcPath);
1532     MOS_SecureStringPrint(pcPath, iStrLen, iStrLen, "%s", pcFileLoc);
1533     VPHAL_DEBUG_CHK_STATUS(VphalHwStateDumper::CheckPath(&pcPath));
1534 
1535     VPHAL_DEBUG_CHK_STATUS(DumpBinaryStruct(&field, 1,
1536                                         pCmd_buff->pCmdBase,
1537                                         pcPath, "CMB", iID));
1538 
1539 finish:
1540     MOS_SafeFreeMemory(pcPath);
1541     return eStatus;
1542 }
1543 
DumpGshBinary(const char * pcFileLoc,int32_t iID)1544 MOS_STATUS VphalHwStateDumper::DumpGshBinary(
1545     const char*          pcFileLoc,
1546     int32_t              iID)
1547 {
1548     MOS_STATUS                      eStatus;
1549     uint32_t                        dwSizeMS;
1550     size_t                          iStrLen;
1551     char*                           pcPath;
1552     char*                           pcOutFileName;
1553     char*                           pcOutContents;
1554     char*                           pcTargetFileName;
1555     PRENDERHAL_STATE_HEAP           pStateHeap;
1556     PRENDERHAL_STATE_HEAP_SETTINGS  pStateHeapSettings;
1557 
1558     // GSH LAYOUT
1559     VPHAL_DBG_FIELD_LAYOUT* pGshLayout = nullptr;
1560     uint32_t                uiNumGSHFields = 0;
1561 
1562     eStatus             = MOS_STATUS_SUCCESS;
1563     dwSizeMS            = 0;
1564     iStrLen             = 0;
1565     pcPath              = nullptr;
1566     pcOutFileName       = nullptr;
1567     pcOutContents       = nullptr;
1568     pcTargetFileName    = nullptr;
1569     pStateHeap          = nullptr;
1570     pStateHeapSettings  = nullptr;
1571 
1572     pcTargetFileName = (char*)MOS_AllocAndZeroMemory(MAX_PATH);
1573     VPHAL_DEBUG_CHK_NULL(pcTargetFileName);
1574     memset(pcTargetFileName, '\0', MAX_PATH);
1575 
1576     pStateHeap          = m_stateHeap;
1577     pStateHeapSettings  = m_stateHeapSettings;
1578 
1579     iStrLen = strlen(pcFileLoc) + 1;
1580     pcPath = (char*)MOS_AllocAndZeroMemory(sizeof(char) * iStrLen);
1581     VPHAL_DEBUG_CHK_NULL(pcPath);
1582     MOS_SecureStringPrint(pcPath, iStrLen, iStrLen, "%s", pcFileLoc);
1583     VPHAL_DEBUG_CHK_STATUS(VphalHwStateDumper::CheckPath(&pcPath));
1584 
1585     pcOutFileName = (char*)MOS_AllocAndZeroMemory(sizeof(char) * MAX_PATH);
1586     VPHAL_DEBUG_CHK_NULL(pcOutFileName);
1587     MOS_SecureStringPrint(pcOutFileName, MAX_PATH, MAX_PATH, "%sGSH_%d.xml", pcPath, iID);
1588 
1589     VPHAL_DEBUG_CHK_STATUS(DefGsh(&pGshLayout, &uiNumGSHFields));
1590 
1591     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(true, &pcOutContents, XMLHEADER));
1592     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents,
1593                                   "<GSH><NAME>GSH</NAME><LOC>0x%x</LOC><VERSION>%s</VERSION>\r\n",
1594                                   (uintptr_t)pStateHeap->pGshBuffer, VPDEBUG_VERSION));
1595 
1596     VPHAL_DEBUG_CHK_STATUS(DumpSubfields(&pcOutContents, nullptr, pGshLayout, uiNumGSHFields));
1597 
1598     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "</GSH>\r\n"));
1599     VphalDumperTool::GetOsFilePath(pcOutFileName, pcTargetFileName);
1600     iStrLen = strlen(pcOutContents);
1601     if(iStrLen > ULONG_MAX)
1602     {
1603         eStatus = MOS_STATUS_UNKNOWN;
1604         goto finish;
1605     }
1606     dwSizeMS = (uint32_t)iStrLen;
1607     VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(pcTargetFileName,
1608                                                     pcOutContents,
1609                                                     dwSizeMS));
1610 
1611     VPHAL_DEBUG_CHK_STATUS(DumpBinaryStruct(pGshLayout,
1612                                         uiNumGSHFields, pStateHeap->pGshBuffer,
1613                                         pcPath, "GSH", iID));
1614 
1615 finish:
1616     MOS_SafeFreeMemory(pcPath);
1617     MOS_SafeFreeMemory(pcTargetFileName);
1618     MOS_SafeFreeMemory(pcOutFileName);
1619     MOS_SafeFreeMemory(pcOutContents);
1620     FreeLayout(pGshLayout, uiNumGSHFields);
1621     return eStatus;
1622 }
1623 
DumpSshBinary(const char * pcFileLoc,int32_t iID)1624 MOS_STATUS VphalHwStateDumper::DumpSshBinary(
1625     const char*          pcFileLoc,
1626     int32_t              iID)
1627 {
1628     MOS_STATUS                      eStatus;
1629     size_t                          iStrLen;
1630     int32_t                         i;
1631     char*                           pcPath;
1632     char*                           pcOutFileName;
1633     char*                           pcOutContents;
1634     char*                           pcTargetFileName;
1635     uint32_t                        dwSizeMS;
1636     PRENDERHAL_STATE_HEAP           pStateHeap;
1637     PRENDERHAL_STATE_HEAP_SETTINGS  pStateHeapSettings;
1638 
1639     // SSH LAYOUT
1640     uint32_t                        uiNumSSHFields = 0;
1641     VPHAL_DBG_FIELD_LAYOUT*         pSshLayout = nullptr;
1642 
1643     eStatus          = MOS_STATUS_SUCCESS;
1644     iStrLen          = 0;
1645     i                = 0;
1646     pcPath           = nullptr;
1647     pcOutFileName    = nullptr;
1648     pcOutContents    = nullptr;
1649     pcTargetFileName = nullptr;
1650     dwSizeMS         = 0;
1651 
1652     pcTargetFileName = (char*)MOS_AllocAndZeroMemory(MAX_PATH);
1653     VPHAL_DEBUG_CHK_NULL(pcTargetFileName);
1654     memset(pcTargetFileName, '\0', MAX_PATH);
1655 
1656     pStateHeap          = m_stateHeap;
1657     pStateHeapSettings  = m_stateHeapSettings;
1658 
1659     iStrLen = strlen(pcFileLoc) + 1;
1660     pcPath = (char*)MOS_AllocAndZeroMemory(sizeof(char) * iStrLen);
1661     VPHAL_DEBUG_CHK_NULL(pcPath);
1662     MOS_SecureStringPrint(pcPath, iStrLen, iStrLen, "%s", pcFileLoc);
1663     VPHAL_DEBUG_CHK_STATUS(VphalHwStateDumper::CheckPath(&pcPath));
1664 
1665     pcOutFileName = (char*)MOS_AllocAndZeroMemory(sizeof(char) * (iStrLen + 20));
1666     VPHAL_DEBUG_CHK_NULL(pcOutFileName);
1667     MOS_SecureStringPrint(pcOutFileName, iStrLen + 20, iStrLen + 20, "%sSSH_%d.xml", pcPath, iID);
1668 
1669     VPHAL_DEBUG_CHK_STATUS(DefSsh(&pSshLayout, &uiNumSSHFields));
1670 
1671     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(true, &pcOutContents, XMLHEADER));
1672     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents,
1673                                   "<SSH><NAME>SSH</NAME><LOC>0x%x</LOC><VERSION>%s</VERSION>\r\n",
1674                                   (uintptr_t)pStateHeap->pSshBuffer, VPDEBUG_VERSION));
1675 
1676     VPHAL_DEBUG_CHK_STATUS(DumpSubfields(&pcOutContents, nullptr, pSshLayout,
1677                                     uiNumSSHFields));
1678 
1679     VphalDumperTool::AppendString(false, &pcOutContents, "</SSH>\r\n");
1680 
1681     VphalDumperTool::GetOsFilePath(pcOutFileName, pcTargetFileName);
1682     iStrLen = strlen(pcOutContents);
1683     if(iStrLen > ULONG_MAX)
1684     {
1685         eStatus = MOS_STATUS_UNKNOWN;
1686         goto finish;
1687     }
1688     dwSizeMS = (uint32_t)iStrLen;
1689     VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(pcTargetFileName,
1690                                                     pcOutContents,
1691                                                     dwSizeMS));
1692 
1693     VPHAL_DEBUG_CHK_STATUS(DumpBinaryStruct(pSshLayout,
1694                                         uiNumSSHFields, pStateHeap->pSshBuffer,
1695                                         pcPath, "SSH", iID));
1696 
1697 finish:
1698     MOS_SafeFreeMemory(pcPath);
1699     MOS_SafeFreeMemory(pcOutFileName);
1700     MOS_SafeFreeMemory(pcOutContents);
1701     FreeLayout(pSshLayout, uiNumSSHFields);
1702     return eStatus;
1703 }
1704 
DumpVeboxStateBinary(PMHW_VEBOX_INTERFACE pVeboxInterface,const char * pcFileLoc,int32_t iID)1705 MOS_STATUS VphalHwStateDumper::DumpVeboxStateBinary(
1706     PMHW_VEBOX_INTERFACE pVeboxInterface,
1707     const char*          pcFileLoc,
1708     int32_t              iID)
1709 {
1710     MOS_STATUS             eStatus;
1711     VPHAL_DBG_FIELD_LAYOUT field;
1712     char*                  pcPath;
1713     size_t                 iStrLen;
1714     const MHW_VEBOX_HEAP   *pVeboxHeap = nullptr;
1715 
1716     eStatus      = MOS_STATUS_SUCCESS;
1717     pcPath      = nullptr;
1718     iStrLen     = strlen(pcFileLoc) + 1;
1719 
1720     VPHAL_DEBUG_CHK_STATUS(pVeboxInterface->GetVeboxHeapInfo(
1721                                 &pVeboxHeap));
1722     VPHAL_DEBUG_CHK_NULL(pVeboxHeap);
1723 
1724     field.dwOffset      = 0;
1725     field.uiNumChildren = 0;
1726     field.uiNumber      = 1;
1727 
1728     pcPath = (char*)MOS_AllocAndZeroMemory(sizeof(char) * iStrLen);
1729     VPHAL_DEBUG_CHK_NULL(pcPath);
1730     MOS_SecureStringPrint(pcPath, iStrLen, iStrLen, "%s", pcFileLoc);
1731 
1732     field.dwSize = pVeboxHeap->uiInstanceSize;
1733 
1734     VPHAL_DEBUG_CHK_STATUS(DumpBinaryStruct(&field, 1,
1735                                         (pVeboxHeap->pLockedDriverResourceMem +pVeboxHeap->uiCurState * pVeboxHeap->uiInstanceSize) ,
1736                                         pcPath, nullptr, iID));
1737 
1738 finish:
1739     MOS_SafeFreeMemory(pcPath);
1740     return eStatus;
1741 }
1742 
DumpStatisticsBinary(PVPHAL_VEBOX_STATE pVeboxState,uint8_t * pStat0Base,uint8_t * pStat1Base,const char * pcFileLoc,int32_t iID)1743 MOS_STATUS VphalHwStateDumper::DumpStatisticsBinary(
1744     PVPHAL_VEBOX_STATE      pVeboxState,
1745     uint8_t*                pStat0Base,
1746     uint8_t*                pStat1Base,
1747     const char*             pcFileLoc,
1748     int32_t                 iID)
1749 {
1750     MOS_STATUS              eStatus;
1751     VPHAL_DBG_FIELD_LAYOUT  field;
1752     size_t                  iStrLen;
1753     char*                   pcOutFileName0;
1754     char*                   pcOutFileName1;
1755     int32_t                 dwWidth,dwHeight;
1756     void                    *pState0, *pState1;
1757 
1758     eStatus        = MOS_STATUS_SUCCESS;
1759     iStrLen        = 0;
1760     pcOutFileName0 = nullptr;
1761     pcOutFileName1 = nullptr;
1762     iStrLen        = strlen(pcFileLoc) + 4;
1763     pState0        = (void*)(pStat0Base);
1764     pState1        = (void*)(pStat1Base);
1765 
1766     pcOutFileName0 = (char*)MOS_AllocAndZeroMemory(sizeof(char) * iStrLen);
1767     VPHAL_DEBUG_CHK_NULL(pcOutFileName0);
1768     MOS_SecureStringPrint(pcOutFileName0, iStrLen, iStrLen, "%s[slice0]", pcFileLoc);
1769 
1770     pcOutFileName1 = (char*)MOS_AllocAndZeroMemory(sizeof(char) * iStrLen);
1771     VPHAL_DEBUG_CHK_NULL(pcOutFileName1);
1772     MOS_SecureStringPrint(pcOutFileName1, iStrLen, iStrLen, "%s[slice1]", pcFileLoc);
1773 
1774     field.dwOffset      = 0;
1775     field.uiNumChildren = 0;
1776     field.uiNumber      = 1;
1777 
1778     dwWidth      = MOS_ALIGN_CEIL(pVeboxState->m_currentSurface->dwWidth, 64);
1779     dwHeight     = MOS_ROUNDUP_DIVIDE(pVeboxState->m_currentSurface->dwHeight, 4) +
1780                    MOS_ROUNDUP_DIVIDE(VPHAL_VEBOX_STATISTICS_SIZE_MAX * sizeof(uint32_t), dwWidth);
1781     field.dwSize = dwWidth * dwHeight;
1782 
1783     VPHAL_DEBUG_CHK_STATUS(DumpBinaryStruct(&field, 1,
1784                                         pState0 , pcOutFileName0, nullptr, iID));
1785     VPHAL_DEBUG_CHK_STATUS(DumpBinaryStruct(&field, 1,
1786                                         pState1 , pcOutFileName1, nullptr, iID));
1787 
1788 finish:
1789     MOS_SafeFreeMemory(pcOutFileName0);
1790     MOS_SafeFreeMemory(pcOutFileName1);
1791 
1792     return eStatus;
1793 }
1794 
StringToLower(char * pcString)1795 void VphalDumperTool::StringToLower(
1796     char* pcString)
1797 {
1798     size_t stStrLen;                                                           // length of string
1799     size_t i;                                                                  // loop iterator
1800 
1801     stStrLen = strlen(pcString);
1802     for (i = 0; i < stStrLen; i++)
1803     {
1804         if (isupper(pcString[i]))
1805         {
1806             pcString[i] = (char)tolower(pcString[i]);
1807         }
1808     }
1809 }
1810 
LocStringToEnum(char * pcLocString,uint32_t * pLocation)1811 MOS_STATUS VphalSurfaceDumper::LocStringToEnum(
1812     char*                           pcLocString,
1813     uint32_t                        *pLocation)
1814 {
1815     MOS_STATUS eStatus;
1816 
1817     eStatus = MOS_STATUS_SUCCESS;
1818 
1819     VphalDumperTool::StringToLower(pcLocString);
1820     if (strcmp(pcLocString,      VPHAL_DBG_SURF_DUMP_LOC_PREALL)   == 0)
1821     {
1822         *pLocation = VPHAL_DBG_DUMP_TYPE_PRE_ALL;
1823     }
1824     else if (strcmp(pcLocString, VPHAL_DBG_SURF_DUMP_LOC_PREDNDI)  == 0)
1825     {
1826         *pLocation = VPHAL_DBG_DUMP_TYPE_PRE_DNDI;
1827     }
1828     else if (strcmp(pcLocString, VPHAL_DBG_SURF_DUMP_LOC_POSTDNDI) == 0)
1829     {
1830         *pLocation = VPHAL_DBG_DUMP_TYPE_POST_DNDI;
1831     }
1832     else if (strcmp(pcLocString, VPHAL_DBG_SURF_DUMP_LOC_PRECOMP)  == 0)
1833     {
1834         *pLocation = VPHAL_DBG_DUMP_TYPE_PRE_COMP;
1835     }
1836     else if (strcmp(pcLocString, VPHAL_DBG_SURF_DUMP_LOC_POSTCOMP) == 0)
1837     {
1838         *pLocation = VPHAL_DBG_DUMP_TYPE_POST_COMP;
1839     }
1840     else if (strcmp(pcLocString, VPHAL_DBG_SURF_DUMP_LOC_PREMEMDECOMP) == 0)
1841     {
1842         *pLocation = VPHAL_DBG_DUMP_TYPE_PRE_MEMDECOMP;
1843     }
1844     else if (strcmp(pcLocString, VPHAL_DBG_SURF_DUMP_LOC_POSTMEMDECOMP) == 0)
1845     {
1846         *pLocation = VPHAL_DBG_DUMP_TYPE_POST_MEMDECOMP;
1847     }
1848     else if (strcmp(pcLocString, VPHAL_DBG_SURF_DUMP_LOC_POSTALL)  == 0)
1849     {
1850         *pLocation = VPHAL_DBG_DUMP_TYPE_POST_ALL;
1851     }
1852     else
1853     {
1854         VPHAL_DEBUG_NORMALMESSAGE("Unknown dump location \"%s\".", pcLocString);
1855         eStatus = MOS_STATUS_UNKNOWN;
1856         goto finish;
1857     }
1858 
1859 finish:
1860     return eStatus;
1861 }
1862 
EnumToLocString(uint32_t Location,char * pcLocString)1863 MOS_STATUS VphalSurfaceDumper::EnumToLocString(
1864     uint32_t                        Location,
1865     char*                           pcLocString)
1866 {
1867     MOS_STATUS  eStatus;
1868     uint32_t    i;
1869     size_t      stStrLen;
1870 
1871     eStatus = MOS_STATUS_SUCCESS;
1872 
1873     if (pcLocString == nullptr)
1874     {
1875         eStatus = MOS_STATUS_INVALID_PARAMETER;
1876         goto finish;
1877     }
1878 
1879     switch (Location)
1880     {
1881         case VPHAL_DBG_DUMP_TYPE_PRE_ALL:
1882             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_SURF_DUMP_LOC_PREALL);
1883             break;
1884         case VPHAL_DBG_DUMP_TYPE_PRE_DNDI:
1885             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_SURF_DUMP_LOC_PREDNDI);
1886             break;
1887         case VPHAL_DBG_DUMP_TYPE_POST_DNDI:
1888             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_SURF_DUMP_LOC_POSTDNDI);
1889             break;
1890         case VPHAL_DBG_DUMP_TYPE_PRE_COMP:
1891             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_SURF_DUMP_LOC_PRECOMP);
1892             break;
1893         case VPHAL_DBG_DUMP_TYPE_POST_COMP:
1894             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_SURF_DUMP_LOC_POSTCOMP);
1895             break;
1896         case VPHAL_DBG_DUMP_TYPE_PRE_MEMDECOMP:
1897             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_SURF_DUMP_LOC_PREMEMDECOMP);
1898             break;
1899         case VPHAL_DBG_DUMP_TYPE_POST_MEMDECOMP:
1900             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_SURF_DUMP_LOC_POSTMEMDECOMP);
1901             break;
1902         case VPHAL_DBG_DUMP_TYPE_POST_ALL:
1903             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_SURF_DUMP_LOC_POSTALL);
1904             break;
1905         default:
1906             VPHAL_DEBUG_ASSERTMESSAGE("Unknown dump location \"%d\".", Location);
1907             eStatus = MOS_STATUS_UNKNOWN;
1908             goto finish;
1909     } // end switch
1910 
1911     stStrLen = strlen(pcLocString);
1912     VPHAL_DEBUG_ASSERT(stStrLen > 1);          // assert b/c invalid access if <= 1
1913     i = pcLocString[1] == 'r' ? 3 : 4; // If pre, start i at 3, else 4
1914     // Maybe should add error case in case macros get changed later?
1915     for (; i < stStrLen; i++)
1916     {
1917         pcLocString[i] = (char)toupper(pcLocString[i]);
1918     }
1919 
1920 finish:
1921     return eStatus;
1922 }
1923 
EnumToLocString(VPHAL_DEBUG_STAGE Location,char * pcLocString)1924 MOS_STATUS VphalHwStateDumper::EnumToLocString(
1925     VPHAL_DEBUG_STAGE          Location,
1926     char*                      pcLocString)
1927 {
1928     MOS_STATUS  eStatus;
1929     uint32_t    i;
1930     size_t      stStrLen;
1931 
1932     eStatus = MOS_STATUS_SUCCESS;
1933 
1934     if (pcLocString == nullptr)
1935     {
1936         eStatus = MOS_STATUS_INVALID_PARAMETER;
1937         goto finish;
1938     }
1939 
1940     switch (Location)
1941     {
1942         case VPHAL_DBG_STAGE_DNDI:
1943             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_STATE_DUMP_LOC_DNDI);
1944             break;
1945         case VPHAL_DBG_STAGE_VEBOX:
1946             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_STATE_DUMP_LOC_VEBOX);
1947             break;
1948         case VPHAL_DBG_STAGE_COMP:
1949             MOS_SecureStringPrint(pcLocString, MAX_PATH, MAX_PATH, VPHAL_DBG_STATE_DUMP_LOC_COMP);
1950             break;
1951         default:
1952             VPHAL_DEBUG_NORMALMESSAGE("Unknown dump location \"%d\".", Location);
1953             eStatus = MOS_STATUS_UNKNOWN;
1954             goto finish;
1955     } // end switch
1956 
1957     stStrLen = strlen(pcLocString);
1958     for (i=0; i < stStrLen; i++)
1959     {
1960         pcLocString[i] = (char)toupper(pcLocString[i]);
1961     }
1962 
1963 finish:
1964     return eStatus;
1965 }
1966 
SurfTypeStringToEnum(char * pcSurfType,VPHAL_SURFACE_TYPE * pSurfType)1967 MOS_STATUS VphalSurfaceDumper::SurfTypeStringToEnum(
1968     char*                         pcSurfType,
1969     VPHAL_SURFACE_TYPE            *pSurfType)
1970 {
1971     MOS_STATUS eStatus;
1972 
1973     eStatus = MOS_STATUS_SUCCESS;
1974     VphalDumperTool::StringToLower(pcSurfType);
1975     if (strcmp(pcSurfType,      VPHAL_DBG_SURF_DUMP_TYPE_BACKGROUND)   == 0)
1976     {
1977         *pSurfType = SURF_IN_BACKGROUND;
1978     }
1979     else if (strcmp(pcSurfType, VPHAL_DBG_SURF_DUMP_TYPE_PRIMARY)      == 0)
1980     {
1981         *pSurfType = SURF_IN_PRIMARY;
1982     }
1983     else if (strcmp(pcSurfType, VPHAL_DBG_SURF_DUMP_TYPE_SUBSTREAM)    == 0)
1984     {
1985         *pSurfType = SURF_IN_SUBSTREAM;
1986     }
1987     else if (strcmp(pcSurfType, VPHAL_DBG_SURF_DUMP_TYPE_REFERENCE)    == 0)
1988     {
1989         *pSurfType = SURF_IN_REFERENCE;
1990     }
1991     else if (strcmp(pcSurfType, VPHAL_DBG_SURF_DUMP_TYPE_RENDERTARGET) == 0)
1992     {
1993         *pSurfType = SURF_OUT_RENDERTARGET;
1994     }
1995     else
1996     {
1997         VPHAL_DEBUG_ASSERTMESSAGE("Unknown surface type \"%s\".", pcSurfType);
1998         eStatus = MOS_STATUS_UNKNOWN;
1999         goto finish;
2000     }
2001 
2002 finish:
2003     return eStatus;
2004 }
2005 
StateTypeStringToEnum(char * pcStateType,uint32_t * pStateType)2006 MOS_STATUS VphalHwStateDumper::StateTypeStringToEnum(
2007     char*                         pcStateType,
2008     uint32_t                      *pStateType)
2009 {
2010     MOS_STATUS eStatus;
2011 
2012     eStatus = MOS_STATUS_SUCCESS;
2013     VphalDumperTool::StringToLower(pcStateType);
2014     if (strcmp(pcStateType, VPHAL_DBG_STATE_DUMP_LOC_DNDI)   == 0)
2015     {
2016         *pStateType = VPHAL_DBG_STAGE_DNDI;
2017     }
2018     else if (strcmp(pcStateType, VPHAL_DBG_STATE_DUMP_LOC_VEBOX)  == 0)
2019     {
2020         *pStateType = VPHAL_DBG_STAGE_VEBOX;
2021     }
2022     else if (strcmp(pcStateType, VPHAL_DBG_STATE_DUMP_LOC_COMP)   == 0)
2023     {
2024         *pStateType = VPHAL_DBG_STAGE_COMP;
2025     }
2026     else
2027     {
2028         VPHAL_DEBUG_NORMALMESSAGE("Unknown surface type \"%s\".", pcStateType);
2029         eStatus = MOS_STATUS_UNKNOWN;
2030         goto finish;
2031     }
2032 
2033 finish:
2034     return eStatus;
2035 }
2036 
ProcessDumpLocations(char * pcDumpLocData)2037 MOS_STATUS VphalSurfaceDumper::ProcessDumpLocations(
2038     char*                      pcDumpLocData)
2039 {
2040     MOS_STATUS  eStatus;
2041     char*       pcCommaLoc;                                                        // pointer to next comma in dump location string
2042     char*       pcCurrToken;                                                       // pointer to current token in a string
2043     char*       pcColonLoc;                                                        // pointer to next colon in location string
2044     int32_t     iNumStrings;                                                       // number of dump locations
2045     int32_t     i;                                                                 // loop iteration counter
2046     VPHAL_DBG_SURF_DUMP_SPEC    *pDumpSpec = &m_dumpSpec;
2047 
2048     eStatus      = MOS_STATUS_SUCCESS;
2049     iNumStrings  = 0;
2050 
2051     if (strlen(pcDumpLocData) > 0)
2052     {
2053         // Count number of strings in key data
2054         // If non empty string, there is at least one value
2055         iNumStrings++;
2056         // Count the rest
2057         pcCommaLoc = pcDumpLocData;
2058         while ((pcCommaLoc = strchr(pcCommaLoc + 1, ',')) != nullptr)
2059         {
2060             iNumStrings++;
2061         }
2062 
2063         // Set number of strings and allocate space for them
2064         pDumpSpec->iNumDumpLocs = iNumStrings;
2065         pDumpSpec->pDumpLocations = (VPHAL_DBG_SURF_DUMP_LOC*)MOS_AllocAndZeroMemory(
2066                     sizeof(VPHAL_DBG_SURF_DUMP_LOC) * pDumpSpec->iNumDumpLocs);
2067         pcCurrToken = pcDumpLocData;
2068 
2069         // Determine each part of the string
2070         for (i = 0; i < pDumpSpec->iNumDumpLocs; i++)
2071         {
2072             pcCommaLoc = strchr(pcCurrToken, ',');
2073             if (pcCommaLoc != nullptr)
2074             {
2075                 *pcCommaLoc = '\0';
2076             }
2077 
2078             // Handle surface type
2079             pcColonLoc = strchr(pcCurrToken, ':');
2080             if (pcColonLoc == nullptr)
2081             {
2082                 // Dump all
2083                 pDumpSpec->pDumpLocations[i].SurfType = SURF_NONE;
2084             }
2085             else
2086             {
2087                 // Remove surface type from dump location
2088                 *pcColonLoc = '\0';
2089                 // Set surface type
2090                 pcColonLoc++;
2091 
2092                 pcColonLoc = WhitespaceTrim(pcColonLoc);
2093                 VPHAL_DEBUG_CHK_STATUS(SurfTypeStringToEnum(pcColonLoc,
2094                                     &(pDumpSpec->pDumpLocations[i].SurfType)));
2095             }
2096 
2097             //trim the whitespaces from dump location
2098             pcCurrToken = WhitespaceTrim(pcCurrToken);
2099 
2100             VPHAL_DEBUG_CHK_STATUS(LocStringToEnum(pcCurrToken,
2101                                 &(pDumpSpec->pDumpLocations[i].DumpLocation)));
2102             if (pcCommaLoc != nullptr)
2103             {
2104                 pcCurrToken = pcCommaLoc + 1;
2105             }
2106         } // end for each part of the string
2107     } // if data length > 0
2108 finish:
2109     return eStatus;
2110 }
2111 
GetSurfaceDumpSpec()2112 void VphalSurfaceDumper::GetSurfaceDumpSpec()
2113 {
2114     MOS_STATUS                      eStatus = MOS_STATUS_SUCCESS;
2115     char                            pcDumpLocData[VPHAL_DBG_SURF_DUMP_MAX_DATA_LEN];
2116     VPHAL_DBG_SURF_DUMP_SPEC        *pDumpSpec = &m_dumpSpec;
2117     MediaUserSetting::Value         outValue;
2118 
2119     pDumpSpec->uiStartFrame    = 0xFFFFFFFF;
2120     pDumpSpec->uiEndFrame      = 0;
2121     pDumpSpec->pcOutputPath[0] = '\0';
2122     pcDumpLocData[0]           = '\0';
2123 
2124     // Get start frame
2125     // if start frame is not got assign a default value of 0
2126     ReadUserSettingForDebug(
2127         m_userSettingPtr,
2128         pDumpSpec->uiStartFrame,
2129         __VPHAL_DBG_SURF_DUMP_START_FRAME_KEY_NAME,
2130         MediaUserSetting::Group::Device);
2131 
2132     // Get end frame
2133     // if end frame is not got assign a default value of max
2134     ReadUserSettingForDebug(
2135         m_userSettingPtr,
2136         pDumpSpec->uiEndFrame,
2137         __VPHAL_DBG_SURF_DUMP_END_FRAME_KEY_NAME,
2138         MediaUserSetting::Group::Device);
2139 
2140     // Get out file path
2141     ReadUserSettingForDebug(
2142         m_userSettingPtr,
2143         outValue,
2144         __VPHAL_DBG_SURF_DUMP_OUTFILE_KEY_NAME,
2145         MediaUserSetting::Group::Device);
2146 
2147     if (outValue.ConstString().size() > 0 && outValue.ConstString().size() < MOS_USER_CONTROL_MAX_DATA_SIZE)
2148     {
2149         // Copy the Output path
2150         MOS_SecureMemcpy(
2151             pDumpSpec->pcOutputPath,
2152             MAX_PATH,
2153             outValue.ConstString().c_str(),
2154             outValue.ConstString().size());
2155     }
2156 #if !defined(LINUX) && !defined(ANDROID)
2157     else
2158     {
2159         std::string vphalDumpFilePath;
2160 
2161         // Use state separation APIs to obtain appropriate storage location
2162         if (SUCCEEDED(GetDriverPersistentStorageLocation(vphalDumpFilePath)))
2163         {
2164             std::string m_outputFilePath;
2165 
2166             m_outputFilePath = vphalDumpFilePath.c_str();
2167             m_outputFilePath.append(VPHAL_DBG_DUMP_OUTPUT_FOLDER);
2168 
2169             // Copy the Output path
2170             MOS_SecureMemcpy(
2171                 pDumpSpec->pcOutputPath,
2172                 MAX_PATH,
2173                 m_outputFilePath.c_str(),
2174                 m_outputFilePath.size());
2175 
2176             ReportUserSettingForDebug(m_userSettingPtr, __VPHAL_DBG_DUMP_OUTPUT_DIRECTORY, m_outputFilePath, MediaUserSetting::Group::Sequence);
2177         }
2178     }
2179 #endif
2180 
2181     // Get dump locations
2182     outValue = "";
2183     eStatus = ReadUserSettingForDebug(
2184         m_userSettingPtr,
2185         outValue,
2186         __VPHAL_DBG_SURF_DUMP_LOCATION_KEY_NAME,
2187         MediaUserSetting::Group::Device);
2188     if (outValue.ConstString().size() > 0 && outValue.ConstString().size() < MOS_USER_CONTROL_MAX_DATA_SIZE
2189         && pDumpSpec->pcOutputPath[0] != '\0')
2190     {
2191         VPHAL_DEBUG_CHK_STATUS(ProcessDumpLocations(const_cast<char*>(outValue.ConstString().c_str())));
2192     }
2193 
2194     // Get enableAuxDump
2195     ReadUserSettingForDebug(
2196         m_userSettingPtr,
2197         pDumpSpec->enableAuxDump,
2198         __VPHAL_DBG_SURF_DUMP_ENABLE_AUX_DUMP,
2199         MediaUserSetting::Group::Device);
2200 
2201     // Get plane dump enabled flag
2202     ReadUserSettingForDebug(
2203         m_userSettingPtr,
2204         pDumpSpec->enablePlaneDump,
2205         __VPHAL_DBG_SURF_DUMPER_ENABLE_PLANE_DUMP,
2206         MediaUserSetting::Group::Device);
2207 
2208 finish:
2209     if ((eStatus != MOS_STATUS_SUCCESS) || pDumpSpec->pcOutputPath[0] == '\0')
2210     {
2211         pDumpSpec->uiStartFrame = 1;
2212         pDumpSpec->uiEndFrame   = 0;
2213     }
2214     return;
2215 }
2216 
ProcessDumpStateLocations(char * pcDumpLocData)2217 MOS_STATUS VphalHwStateDumper::ProcessDumpStateLocations(
2218     char*                      pcDumpLocData)
2219 {
2220     MOS_STATUS  eStatus;
2221     char*       pcCommaLoc;                                                        // pointer to next comma in dump location string
2222     char*       pcCurrToken;                                                       // pointer to current token in a string
2223     char*       pcRender;                                                          //pointer to video process type string
2224     int32_t     iNumStrings;                                                       // number of dump locations
2225     int32_t     iNumDumpLocs;
2226     int32_t     i = 0;
2227     VPHAL_DBG_DUMP_SPEC         *pDumpSpec = &m_dumpSpec;
2228 
2229     eStatus      = MOS_STATUS_SUCCESS;
2230     iNumStrings  = 0;
2231 
2232     if (strlen(pcDumpLocData) > 0)
2233     {
2234         // Count number of strings in key data
2235         // If non empty string, there is at least one value
2236         iNumStrings++;
2237 
2238         // Count the rest
2239         pcCommaLoc = pcDumpLocData;
2240         while ((pcCommaLoc = strchr(pcCommaLoc + 1, ';')) != nullptr)
2241         {
2242             iNumStrings++;
2243         }
2244 
2245         //calucate the number of GSH,SSH,CB,SB,VeboxState.
2246         pcCurrToken = pcDumpLocData;
2247 
2248         while(iNumStrings !=0)
2249         {
2250             pcCommaLoc = strchr(pcCurrToken, ';');
2251             if (pcCommaLoc != nullptr)
2252             {
2253                 *pcCommaLoc = '\0';
2254             }
2255 
2256             pcRender = strchr(pcCurrToken, ':');
2257 
2258             if (pcRender != nullptr)
2259             {
2260                 iNumDumpLocs = 1;
2261                 pcRender = pcRender + 1;
2262                 while ((pcRender = strchr(pcRender + 1, ',')) != nullptr)
2263                 {
2264                     iNumDumpLocs++;
2265                 }
2266             }
2267             else
2268             {
2269                 iNumDumpLocs = 1;
2270             }
2271 
2272             if (!strncmp(pcCurrToken, "GSH", 3))
2273             {
2274                 pDumpSpec->pGSHDumpSpec = (VPHAL_DBG_GSH_DUMP_SPEC*)MOS_AllocAndZeroMemory(
2275                 sizeof(VPHAL_DBG_GSH_DUMP_SPEC));
2276                 pDumpSpec->pGSHDumpSpec->iNumDumpLocs=iNumDumpLocs;
2277                 pDumpSpec->pGSHDumpSpec->pDumpLocations = (VPHAL_DBG_GSH_DUMP_LOC*)MOS_AllocAndZeroMemory(
2278                 sizeof(VPHAL_DBG_GSH_DUMP_LOC)*iNumDumpLocs);
2279 
2280                 pcCurrToken = pcCurrToken+4;
2281                 i           = 0;
2282 
2283                 while(iNumDumpLocs!=0)
2284                 {
2285                     pcRender = strchr(pcCurrToken, ',');
2286                     if (pcRender != nullptr)
2287                     {
2288                         *pcRender = '\0';
2289                     }
2290 
2291                     if(i<pDumpSpec->pGSHDumpSpec->iNumDumpLocs)
2292                     {
2293                         VPHAL_DEBUG_CHK_STATUS(StateTypeStringToEnum(pcCurrToken,
2294                                 &(pDumpSpec->pGSHDumpSpec->pDumpLocations[i].DumpStage)));
2295                         i++;
2296                     }
2297 
2298                     if (pcRender != nullptr)
2299                     {
2300                         pcCurrToken = pcRender + 1;
2301                     }
2302                     iNumDumpLocs--;
2303                 }
2304             }
2305             else if (!strncmp(pcCurrToken, "SSH", 3))
2306             {
2307                 pDumpSpec->pSSHDumpSpec = (VPHAL_DBG_SSH_DUMP_SPEC*)MOS_AllocAndZeroMemory(
2308                 sizeof(VPHAL_DBG_SSH_DUMP_SPEC));
2309                 pDumpSpec->pSSHDumpSpec->iNumDumpLocs=iNumDumpLocs;
2310                 pDumpSpec->pSSHDumpSpec->pDumpLocations = (VPHAL_DBG_SSH_DUMP_LOC*)MOS_AllocAndZeroMemory(
2311                 sizeof(VPHAL_DBG_SSH_DUMP_LOC)*iNumDumpLocs);
2312 
2313                 pcCurrToken = pcCurrToken+4;
2314                 i           = 0;
2315 
2316                 while(iNumDumpLocs!=0)
2317                 {
2318                     pcRender = strchr(pcCurrToken, ',');
2319                     if (pcRender != nullptr)
2320                     {
2321                         *pcRender = '\0';
2322                     }
2323 
2324                     if(i<pDumpSpec->pSSHDumpSpec->iNumDumpLocs)
2325                     {
2326                         VPHAL_DEBUG_CHK_STATUS(StateTypeStringToEnum(pcCurrToken,
2327                                 &(pDumpSpec->pSSHDumpSpec->pDumpLocations[i].DumpStage)));
2328                         i++;
2329                     }
2330 
2331                     if(pcRender != nullptr)
2332                     {
2333                         pcCurrToken = pcRender + 1;
2334                     }
2335                     iNumDumpLocs--;
2336                 }
2337             }
2338             else if (!strncmp(pcCurrToken, "BB", 2))
2339             {
2340                 pDumpSpec->pBBDumpSpec = (VPHAL_DBG_BB_DUMP_SPEC*)MOS_AllocAndZeroMemory(
2341                 sizeof(VPHAL_DBG_BB_DUMP_SPEC));
2342                 pDumpSpec->pBBDumpSpec->iNumDumpLocs=iNumDumpLocs;
2343                 pDumpSpec->pBBDumpSpec->pDumpLocations = (VPHAL_DBG_BB_DUMP_LOC*)MOS_AllocAndZeroMemory(
2344                 sizeof(VPHAL_DBG_BB_DUMP_LOC)*iNumDumpLocs);
2345 
2346                 pcCurrToken = pcCurrToken+3;
2347                 i           = 0;
2348 
2349                 while(iNumDumpLocs!=0)
2350                 {
2351                     pcRender = strchr(pcCurrToken, ',');
2352                     if (pcRender != nullptr)
2353                     {
2354                         *pcRender = '\0';
2355                     }
2356 
2357                     if(i<pDumpSpec->pBBDumpSpec->iNumDumpLocs)
2358                     {
2359                         VPHAL_DEBUG_CHK_STATUS(StateTypeStringToEnum(pcCurrToken,
2360                                 &(pDumpSpec->pBBDumpSpec->pDumpLocations[i].DumpStage)));
2361                         i++;
2362                     }
2363 
2364                     if(pcRender != nullptr)
2365                     {
2366                         pcCurrToken = pcRender + 1;
2367                     }
2368                     iNumDumpLocs--;
2369                 }
2370             }
2371             else if (!strncmp(pcCurrToken, "CB", 2))
2372             {
2373                 pDumpSpec->pCBDumpSpec = (VPHAL_DBG_CB_DUMP_SPEC*)MOS_AllocAndZeroMemory(
2374                 sizeof(VPHAL_DBG_CB_DUMP_SPEC));
2375                 pDumpSpec->pCBDumpSpec->iNumDumpLocs=iNumDumpLocs;
2376                 pDumpSpec->pCBDumpSpec->pDumpLocations = (VPHAL_DBG_CB_DUMP_LOC*)MOS_AllocAndZeroMemory(
2377                 sizeof(VPHAL_DBG_CB_DUMP_LOC)*iNumDumpLocs);
2378 
2379                 pcCurrToken = pcCurrToken+3;
2380                 i           = 0;
2381 
2382                 while(iNumDumpLocs!=0)
2383                 {
2384                     pcRender = strchr(pcCurrToken, ',');
2385                     if (pcRender != nullptr)
2386                     {
2387                        *pcRender = '\0';
2388                     }
2389 
2390                     if(i<pDumpSpec->pCBDumpSpec->iNumDumpLocs)
2391                     {
2392                        VPHAL_DEBUG_CHK_STATUS(StateTypeStringToEnum(pcCurrToken,
2393                                &(pDumpSpec->pCBDumpSpec->pDumpLocations[i].DumpStage)));
2394                        i++;
2395                     }
2396 
2397                     if (pcRender != nullptr)
2398                     {
2399                        pcCurrToken = pcRender + 1;
2400                     }
2401                     iNumDumpLocs--;
2402                 }
2403             }
2404             else if (!strncmp(pcCurrToken, "VeboxState", 10))
2405             {
2406                 pDumpSpec->pVeboxStateDumpSpec = (VPHAL_DBG_VEBOXSTATE_DUMP_SPEC*)MOS_AllocAndZeroMemory(
2407                 sizeof(VPHAL_DBG_VEBOXSTATE_DUMP_SPEC));
2408                 pDumpSpec->pVeboxStateDumpSpec->iNumDumpLocs=iNumDumpLocs;
2409                 pDumpSpec->pVeboxStateDumpSpec->pDumpLocations = (VPHAL_DBG_VEBOXSTATE_DUMP_LOC*)MOS_AllocAndZeroMemory(
2410                 sizeof(VPHAL_DBG_VEBOXSTATE_DUMP_LOC)*iNumDumpLocs);
2411 
2412                 pDumpSpec->pVeboxStateDumpSpec->pDumpLocations->DumpStage=VPHAL_DBG_STAGE_VEBOX;
2413                 pcCurrToken = pcCurrToken+11;
2414 
2415             }
2416             else if (!strncmp(pcCurrToken, "Statistics", 10))
2417             {
2418                 pDumpSpec->pStatisticsDumpSpec = (VPHAL_DBG_STATISTICS_DUMP_SPEC*)MOS_AllocAndZeroMemory(
2419                 sizeof(VPHAL_DBG_STATISTICS_DUMP_SPEC));
2420                 pDumpSpec->pStatisticsDumpSpec->iNumDumpLocs=iNumDumpLocs;
2421                 pDumpSpec->pStatisticsDumpSpec->pDumpLocations = (VPHAL_DBG_STATISTICS_DUMP_LOC*)MOS_AllocAndZeroMemory(
2422                 sizeof(VPHAL_DBG_STATISTICS_DUMP_LOC)*iNumDumpLocs);
2423 
2424                 pDumpSpec->pVeboxStateDumpSpec->pDumpLocations->DumpStage=VPHAL_DBG_STAGE_VEBOX;
2425                 pcCurrToken = pcCurrToken+11;
2426             }
2427 
2428             if (pcCommaLoc != nullptr)
2429             {
2430                 pcCurrToken = pcCommaLoc + 1;
2431             }
2432             iNumStrings--;
2433 
2434         }
2435     } // if data length > 0
2436 
2437 finish:
2438     return eStatus;
2439 }
2440 
GetStateDumpSpec()2441 void VphalHwStateDumper::GetStateDumpSpec()
2442 {
2443     MOS_STATUS                      eStatus = MOS_STATUS_SUCCESS;
2444     char                            pcDumpLocData[VPHAL_DBG_SURF_DUMP_MAX_DATA_LEN];
2445     VPHAL_DBG_DUMP_SPEC             *pDumpSpec = &m_dumpSpec;
2446     MediaUserSetting::Value         outValue;
2447 
2448     pDumpSpec->uiStartFrame    = 0xFFFFFFFF;
2449     pDumpSpec->uiEndFrame      = 0;
2450     pDumpSpec->pcOutputPath[0] = '\0';
2451     pcDumpLocData[0]           = '\0';
2452 
2453     // Get enableStateDump
2454     // when enableStateDump = true will enable State dump, use the same outputfile path and dump locations as surface dump
2455     ReadUserSettingForDebug(
2456         m_userSettingPtr,
2457         pDumpSpec->enableStateDump,
2458         __VPHAL_DBG_STATE_DUMP_ENABLE,
2459         MediaUserSetting::Group::Device);
2460 
2461     if (pDumpSpec->enableStateDump == false)
2462     {
2463         goto finish;
2464     }
2465 
2466     // Get start frame
2467     // if start frame is not got assign a default value of 0
2468     ReadUserSettingForDebug(
2469         m_userSettingPtr,
2470         pDumpSpec->uiStartFrame,
2471         __VPHAL_DBG_SURF_DUMP_START_FRAME_KEY_NAME,
2472         MediaUserSetting::Group::Device);
2473 
2474     // Get end frame
2475     // if end frame is not got assign a default value of max
2476     ReadUserSettingForDebug(
2477         m_userSettingPtr,
2478         pDumpSpec->uiEndFrame,
2479         __VPHAL_DBG_SURF_DUMP_END_FRAME_KEY_NAME,
2480         MediaUserSetting::Group::Device);
2481 
2482     // Get out file path
2483     ReadUserSettingForDebug(
2484         m_userSettingPtr,
2485         outValue,
2486         __VPHAL_DBG_SURF_DUMP_OUTFILE_KEY_NAME,
2487         MediaUserSetting::Group::Device);
2488 
2489     if (outValue.ConstString().size() > 0 && outValue.ConstString().size() < MOS_USER_CONTROL_MAX_DATA_SIZE)
2490     {
2491         // Copy the Output path
2492         MOS_SecureMemcpy(
2493             pDumpSpec->pcOutputPath,
2494             MAX_PATH,
2495             outValue.ConstString().c_str(),
2496             outValue.ConstString().size());
2497     }
2498 #if !defined(LINUX) && !defined(ANDROID)
2499     else
2500     {
2501         std::string vphalDumpFilePath;
2502 
2503         // Use state separation APIs to obtain appropriate storage location
2504         if (SUCCEEDED(GetDriverPersistentStorageLocation(vphalDumpFilePath)))
2505         {
2506             std::string m_outputFilePath;
2507 
2508             m_outputFilePath = vphalDumpFilePath.c_str();
2509             m_outputFilePath.append(VPHAL_DBG_DUMP_OUTPUT_FOLDER);
2510 
2511             // Copy the Output path
2512             MOS_SecureMemcpy(
2513                 pDumpSpec->pcOutputPath,
2514                 MAX_PATH,
2515                 m_outputFilePath.c_str(),
2516                 m_outputFilePath.size());
2517 
2518             ReportUserSettingForDebug(m_userSettingPtr, __VPHAL_DBG_DUMP_OUTPUT_DIRECTORY, m_outputFilePath, MediaUserSetting::Group::Sequence);
2519         }
2520     }
2521 #endif
2522 
2523     // Get dump locations
2524     outValue = "";
2525     ReadUserSettingForDebug(
2526         m_userSettingPtr,
2527         outValue,
2528         __VPHAL_DBG_SURF_DUMP_LOCATION_KEY_NAME,
2529         MediaUserSetting::Group::Device);
2530 
2531     if (outValue.ConstString().size() > 0 && outValue.ConstString().size() < MOS_USER_CONTROL_MAX_DATA_SIZE
2532         && pDumpSpec->pcOutputPath[0] != '\0')
2533     {
2534         VPHAL_DEBUG_CHK_STATUS(ProcessDumpStateLocations(const_cast<char *>(outValue.ConstString().c_str())));
2535     }
2536 
2537 finish:
2538     if ((eStatus != MOS_STATUS_SUCCESS) || (pDumpSpec->pcOutputPath[0] == '\0'))
2539     {
2540         pDumpSpec->uiStartFrame = 1;
2541         pDumpSpec->uiEndFrame   = 0;
2542     }
2543     return;
2544 }
2545 
VphalSurfaceDumper(PMOS_INTERFACE pOsInterface)2546 VphalSurfaceDumper::VphalSurfaceDumper(PMOS_INTERFACE pOsInterface) :
2547     m_dumpSpec(),
2548     m_osInterface(pOsInterface)
2549 {
2550     if (m_osInterface)
2551     {
2552         m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
2553     }
2554 }
2555 
~VphalSurfaceDumper()2556 VphalSurfaceDumper::~VphalSurfaceDumper()
2557 {
2558     MOS_SafeFreeMemory(m_dumpSpec.pDumpLocations);
2559 }
2560 
VphalHwStateDumper(PRENDERHAL_INTERFACE pRenderHal)2561 VphalHwStateDumper::VphalHwStateDumper(PRENDERHAL_INTERFACE pRenderHal) :
2562     m_dumpSpec(),
2563     iDebugStage(0),
2564     iPhase(0),
2565     m_renderHal(pRenderHal),
2566     m_osInterface(pRenderHal->pOsInterface),
2567     m_hwSizes(pRenderHal->pHwSizes),
2568     m_stateHeap(pRenderHal->pStateHeap),
2569     m_stateHeapSettings(&pRenderHal->StateHeapSettings)
2570 {
2571     if (m_osInterface)
2572     {
2573         m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
2574     }
2575 }
2576 
~VphalHwStateDumper()2577 VphalHwStateDumper::~VphalHwStateDumper()
2578 {
2579     VPHAL_DBG_DUMP_SPEC *pDumpSpec = &m_dumpSpec;
2580 
2581     if (pDumpSpec != nullptr)
2582     {
2583         if(pDumpSpec->pGSHDumpSpec != nullptr)
2584             MOS_SafeFreeMemory(pDumpSpec->pGSHDumpSpec->pDumpLocations);
2585         if(pDumpSpec->pSSHDumpSpec != nullptr)
2586             MOS_SafeFreeMemory(pDumpSpec->pSSHDumpSpec->pDumpLocations);
2587         if(pDumpSpec->pBBDumpSpec != nullptr)
2588             MOS_SafeFreeMemory(pDumpSpec->pBBDumpSpec->pDumpLocations);
2589         if(pDumpSpec->pCBDumpSpec != nullptr)
2590             MOS_SafeFreeMemory(pDumpSpec->pCBDumpSpec->pDumpLocations);
2591         if(pDumpSpec->pVeboxStateDumpSpec != nullptr)
2592             MOS_SafeFreeMemory(pDumpSpec->pVeboxStateDumpSpec->pDumpLocations);
2593         if(pDumpSpec->pStatisticsDumpSpec != nullptr)
2594             MOS_SafeFreeMemory(pDumpSpec->pStatisticsDumpSpec->pDumpLocations);
2595 
2596         MOS_SafeFreeMemory(pDumpSpec->pGSHDumpSpec);
2597         MOS_SafeFreeMemory(pDumpSpec->pSSHDumpSpec);
2598         MOS_SafeFreeMemory(pDumpSpec->pBBDumpSpec);
2599         MOS_SafeFreeMemory(pDumpSpec->pCBDumpSpec);
2600         MOS_SafeFreeMemory(pDumpSpec->pVeboxStateDumpSpec);
2601         MOS_SafeFreeMemory(pDumpSpec->pStatisticsDumpSpec);
2602     }
2603 }
2604 
2605 uint32_t VphalSurfaceDumper::m_frameNumInVp = 0xffffffff;
2606 char     VphalSurfaceDumper::m_dumpLocInVp[MAX_PATH];
2607 
DumpSurface(PVPHAL_SURFACE pSurf,uint32_t uiFrameNumber,uint32_t uiCounter,uint32_t Location)2608 MOS_STATUS VphalSurfaceDumper::DumpSurface(
2609     PVPHAL_SURFACE                  pSurf,
2610     uint32_t                        uiFrameNumber,
2611     uint32_t                        uiCounter,
2612     uint32_t                        Location)
2613 {
2614     int32_t VphalSurfDumpManualTrigger = VPHAL_DBG_SURF_DUMP_MANUAL_TRIGGER_DEFAULT_NOT_SET;
2615 
2616     MOS_STATUS                 eStatus;
2617     int32_t                    i;
2618     VPHAL_DBG_SURF_DUMP_SPEC*  pDumpSpec = &m_dumpSpec;
2619     bool                       isDumpFromDecomp;
2620     bool                       orgDumpAuxEnable;
2621     uint32_t                   pid = MosUtilities::MosGetPid();
2622     uint64_t                   timestamp  = 0;
2623     MosUtilities::MosQueryPerformanceCounter(&timestamp);
2624 
2625     eStatus             = MOS_STATUS_SUCCESS;
2626     i                   = 0;
2627     isDumpFromDecomp    = (Location == VPHAL_DBG_DUMP_TYPE_PRE_MEMDECOMP || Location == VPHAL_DBG_DUMP_TYPE_POST_MEMDECOMP);
2628 
2629     orgDumpAuxEnable    = m_dumpSpec.enableAuxDump;
2630     if ((Location == VPHAL_DBG_DUMP_TYPE_PRE_MEMDECOMP) ||
2631         (Location == VPHAL_DBG_DUMP_TYPE_POST_MEMDECOMP && m_frameNumInVp != 0xffffffff))
2632     {
2633         // For PreMemDecomp, dump without aux is meaningless
2634         // and, if we don't turn on aux dump, the surface will be deswizzled,
2635         // while Mos_Specific_LockResource() will perform deswilling to temp buffer and then copy to locked buffer
2636         // This will break the compressed surface.
2637         // So, we cannot dump compressed surf with deswizzling under current implementation.
2638         // And, for PostMemDecomp, although aux surf should be zero, we can dump it out for comparison.
2639         // Besides, we don't need to deswizzle as the original dump from VP (preAll etc) will do the deswizzling
2640         // For pre/post mem decomp from Codec/3D, doing deswizzling might help to check the result visually
2641         m_dumpSpec.enableAuxDump = true;
2642     }
2643 
2644     if (m_frameNumInVp != 0xffffffff && isDumpFromDecomp)
2645     {
2646         // override the uiFrameNumer as it is during Vphal dumping its surface and already in lock and decomp phase
2647         uiFrameNumber = m_frameNumInVp;
2648     }
2649 
2650     if (!isDumpFromDecomp)
2651     {
2652         m_frameNumInVp      = uiFrameNumber;
2653     }
2654 
2655     // Get if manual triggered build
2656     ReadUserSettingForDebug(
2657         m_userSettingPtr,
2658         VphalSurfDumpManualTrigger,
2659         __VPHAL_DBG_SURF_DUMP_MANUAL_TRIGGER_KEY_NAME,
2660         MediaUserSetting::Group::Device);
2661 
2662     if (VphalSurfDumpManualTrigger != VPHAL_DBG_SURF_DUMP_MANUAL_TRIGGER_DEFAULT_NOT_SET)
2663     {
2664         if (VphalSurfDumpManualTrigger == VPHAL_DBG_SURF_DUMP_MANUAL_TRIGGER_STARTED)
2665         {
2666             VPHAL_DEBUG_NORMALMESSAGE("Dump manaul trigger enabled, dump started: %d \n", VphalSurfDumpManualTrigger);
2667 
2668             for (i = 0; i < pDumpSpec->iNumDumpLocs; i++)
2669             {
2670                 if (pDumpSpec->pDumpLocations[i].DumpLocation == Location &&      // should dump at this pipeline location AND
2671                     (pDumpSpec->pDumpLocations[i].SurfType == pSurf->SurfType ||  // should dump for this surface type OR
2672                         pDumpSpec->pDumpLocations[i].SurfType == SURF_NONE))      // should dump for any surface type
2673                 {
2674                     VPHAL_DEBUG_CHK_STATUS(EnumToLocString(Location, m_dumpLoc));
2675                     if (!isDumpFromDecomp && pSurf->bIsCompressed)
2676                     {
2677                         EnumToLocString(Location, m_dumpLocInVp);
2678                     }
2679 
2680                     if (!isDumpFromDecomp || m_dumpLocInVp[0] == 0)
2681                     {
2682                         MOS_SecureStringPrint(m_dumpPrefix, MAX_PATH, MAX_PATH, "%s/surfdump_pid[%d]_loc[%s]_lyr[%d]_ts[%lld]", pDumpSpec->pcOutputPath, pid, m_dumpLoc, uiCounter, timestamp);
2683                     }
2684                     else
2685                     {
2686                         MOS_SecureStringPrint(m_dumpPrefix, MAX_PATH, MAX_PATH, "%s/surfdump_pid[%d]_loc[%s_%s]_lyr[%d]_ts[%lld]", pDumpSpec->pcOutputPath, pid, m_dumpLocInVp, m_dumpLoc, uiCounter, timestamp);
2687                     }
2688 
2689                     DumpSurfaceToFile(
2690                         m_osInterface,
2691                         pSurf,
2692                         m_dumpPrefix,
2693                         uiFrameNumber,
2694                         true,
2695                         isDumpFromDecomp,
2696                         nullptr);
2697                     break;
2698                 }
2699             }
2700         }
2701         else if (VphalSurfDumpManualTrigger == VPHAL_DBG_SURF_DUMP_MANUAL_TRIGGER_STOPPED)
2702         {
2703             VPHAL_DEBUG_NORMALMESSAGE("Dump manaul trigger enabled, dump stopped: %d \n", VphalSurfDumpManualTrigger);
2704         }
2705         else
2706         {
2707             VPHAL_DEBUG_NORMALMESSAGE("Dump manaul trigger flag: %d \n", VphalSurfDumpManualTrigger);
2708         }
2709     }
2710     else if (pDumpSpec->uiStartFrame <= uiFrameNumber &&
2711              uiFrameNumber <= pDumpSpec->uiEndFrame)
2712     {
2713         for (i = 0; i < pDumpSpec->iNumDumpLocs; i++)
2714         {
2715             if (pDumpSpec->pDumpLocations[i].DumpLocation == Location &&        // should dump at this pipeline location AND
2716                 (pDumpSpec->pDumpLocations[i].SurfType == pSurf->SurfType ||    // should dump for this surface type OR
2717                  pDumpSpec->pDumpLocations[i].SurfType == SURF_NONE))           // should dump for any surface type
2718             {
2719                 VPHAL_DEBUG_CHK_STATUS(EnumToLocString(Location, m_dumpLoc));
2720                 if (!isDumpFromDecomp && pSurf->bIsCompressed)
2721                 {
2722                     EnumToLocString(Location, m_dumpLocInVp);
2723                 }
2724 
2725                 if (!isDumpFromDecomp || m_dumpLocInVp[0] == 0)
2726                 {
2727                     MOS_SecureStringPrint(m_dumpPrefix, MAX_PATH, MAX_PATH, "%s/surfdump_pid[%d]_loc[%s]_lyr[%d]_ts[%lld]",
2728                         pDumpSpec->pcOutputPath, pid, m_dumpLoc, uiCounter, timestamp);
2729                 }
2730                 else
2731                 {
2732                     MOS_SecureStringPrint(m_dumpPrefix, MAX_PATH, MAX_PATH, "%s/surfdump_pid[%d]_loc[%s_%s]_lyr[%d]_ts[%lld]",
2733                         pDumpSpec->pcOutputPath, pid, m_dumpLocInVp, m_dumpLoc, uiCounter, timestamp);
2734                 }
2735 
2736                 DumpSurfaceToFile(
2737                     m_osInterface,
2738                     pSurf,
2739                     m_dumpPrefix,
2740                     uiFrameNumber,
2741                     true,
2742                     isDumpFromDecomp,
2743                     nullptr);
2744                 break;
2745             }
2746         }
2747     }
2748     else
2749     {
2750         VPHAL_DEBUG_VERBOSEMESSAGE("No surface dumpped, VphalSurfDumpManualTrigger: %d, uiStartFrame: %d,  uiEndFrame: %d\n", VphalSurfDumpManualTrigger, pDumpSpec->uiStartFrame, pDumpSpec->uiEndFrame);
2751     }
2752 
2753 finish:
2754     if (!isDumpFromDecomp)
2755     {
2756         m_frameNumInVp      = 0xffffffff;
2757         m_dumpLocInVp[0]    = 0;
2758     }
2759     m_dumpSpec.enableAuxDump = orgDumpAuxEnable;
2760 
2761     return eStatus;
2762 }
2763 
DumpSurfaceArray(PVPHAL_SURFACE * ppSurfaces,uint32_t uiMaxSurfaces,uint32_t uiNumSurfaces,uint32_t uiFrameNumber,uint32_t Location)2764 MOS_STATUS VphalSurfaceDumper::DumpSurfaceArray(
2765     PVPHAL_SURFACE                  *ppSurfaces,
2766     uint32_t                        uiMaxSurfaces,
2767     uint32_t                        uiNumSurfaces,
2768     uint32_t                        uiFrameNumber,
2769     uint32_t                        Location)
2770 {
2771     MOS_STATUS      eStatus;
2772     uint32_t        uiIndex;
2773     uint32_t        uiLayer;
2774 
2775     //---------------------------------------------------
2776     VPHAL_DEBUG_ASSERT(ppSurfaces);
2777     //---------------------------------------------------
2778 
2779     eStatus = MOS_STATUS_SUCCESS;
2780 
2781     for (uiIndex = 0, uiLayer = 0;
2782          uiLayer < uiNumSurfaces && uiIndex < uiMaxSurfaces; uiIndex++)
2783     {
2784         if (ppSurfaces[uiIndex])
2785         {
2786             VPHAL_DEBUG_ASSERT(!Mos_ResourceIsNull(&ppSurfaces[uiIndex]->OsResource));
2787 
2788             VPHAL_DEBUG_CHK_STATUS(DumpSurface(
2789                 ppSurfaces[uiIndex],
2790                 uiFrameNumber,
2791                 uiLayer,
2792                 Location));
2793 
2794             uiLayer++;
2795         }
2796     }
2797 
2798 finish:
2799     return eStatus;
2800 }
2801 
DumpGSH()2802 void VphalHwStateDumper::DumpGSH()
2803 {
2804     MOS_STATUS            eStatus;
2805     int32_t               iIndex;
2806     uint64_t              uiPhase;
2807     VPHAL_DBG_DUMP_SPEC*  pDumpSpec;
2808     VPHAL_DEBUG_STAGE     Location;
2809 
2810     char pcDumpPrefix[MAX_PATH];
2811     char pcDumpLoc[MAX_PATH];
2812 
2813     Location  = (VPHAL_DEBUG_STAGE)iDebugStage;
2814     uiPhase   = iPhase;
2815     pDumpSpec = &m_dumpSpec;
2816     if ((pDumpSpec->pGSHDumpSpec == nullptr)                          ||
2817         (pDumpSpec->pGSHDumpSpec->pDumpLocations == nullptr)          ||
2818         (pDumpSpec->pGSHDumpSpec->pDumpLocations->DumpStage == 0))
2819     {
2820         goto finish;
2821     }
2822     MOS_ZeroMemory(pcDumpPrefix, MAX_PATH);
2823     MOS_ZeroMemory(pcDumpLoc,    MAX_PATH);
2824 
2825     if(pDumpSpec->uiStartFrame <= pDumpSpec->uiCurrentFrame &&
2826         pDumpSpec->uiCurrentFrame <= pDumpSpec->uiEndFrame)
2827     {
2828         for (iIndex= 0; iIndex< pDumpSpec->pGSHDumpSpec->iNumDumpLocs; iIndex++)
2829         {
2830             if (pDumpSpec->pGSHDumpSpec->pDumpLocations[iIndex].DumpStage == Location)
2831             {
2832                 VPHAL_DEBUG_CHK_STATUS(EnumToLocString(Location, pcDumpLoc));
2833                 MOS_SecureStringPrint(pcDumpPrefix, MAX_PATH, MAX_PATH, "%s/GSH_dump_loc[%s]_[%lld]",
2834                     pDumpSpec->pcOutputPath, pcDumpLoc, uiPhase);
2835 
2836                 DumpGshBinary(
2837                     pcDumpPrefix,
2838                     pDumpSpec->uiCurrentFrame);
2839 
2840               break;
2841             }
2842         }
2843     }
2844 
2845 finish:
2846     return;
2847 
2848 }
2849 
DumpSSH()2850 void VphalHwStateDumper::DumpSSH()
2851 {
2852     MOS_STATUS            eStatus;
2853     int32_t               iIndex;
2854     uint64_t              uiPhase;
2855     VPHAL_DBG_DUMP_SPEC*  pDumpSpec;
2856     VPHAL_DEBUG_STAGE     Location;
2857 
2858     char  pcDumpPrefix[MAX_PATH];
2859     char  pcDumpLoc[MAX_PATH];
2860 
2861     Location  = (VPHAL_DEBUG_STAGE)iDebugStage;
2862     uiPhase   = iPhase;
2863     pDumpSpec = &m_dumpSpec;
2864     if ((pDumpSpec->pSSHDumpSpec == nullptr)                          ||
2865         (pDumpSpec->pSSHDumpSpec->pDumpLocations == nullptr)          ||
2866         (pDumpSpec->pSSHDumpSpec->pDumpLocations->DumpStage == 0))
2867     {
2868         goto finish;
2869     }
2870 
2871     MOS_ZeroMemory(pcDumpPrefix, MAX_PATH);
2872     MOS_ZeroMemory(pcDumpLoc,    MAX_PATH);
2873 
2874     if(pDumpSpec->uiStartFrame <= pDumpSpec->uiCurrentFrame &&
2875         pDumpSpec->uiCurrentFrame <= pDumpSpec->uiEndFrame)
2876     {
2877         for (iIndex= 0; iIndex< pDumpSpec->pSSHDumpSpec->iNumDumpLocs; iIndex++)
2878         {
2879             if (pDumpSpec->pSSHDumpSpec->pDumpLocations[iIndex].DumpStage == Location)
2880             {
2881                 VPHAL_DEBUG_CHK_STATUS(EnumToLocString(Location, pcDumpLoc));
2882                 MOS_SecureStringPrint(pcDumpPrefix, MAX_PATH, MAX_PATH, "%s/SSH_dump_loc[%s]_[%lld]",
2883                     pDumpSpec->pcOutputPath, pcDumpLoc, uiPhase);
2884 
2885                 DumpSshBinary(
2886                     pcDumpPrefix,
2887                     pDumpSpec->uiCurrentFrame);
2888                 break;
2889             }
2890         }
2891     }
2892 
2893 finish:
2894     return;
2895 
2896 }
2897 
DumpBatchBuffer(PMHW_BATCH_BUFFER pBatchBuffer)2898 void VphalHwStateDumper::DumpBatchBuffer(
2899     PMHW_BATCH_BUFFER    pBatchBuffer)
2900 {
2901     MOS_STATUS           eStatus;
2902     int32_t              iIndex;
2903     uint64_t             uiPhase;
2904     VPHAL_DBG_DUMP_SPEC* pDumpSpec;
2905     VPHAL_DEBUG_STAGE    Location;
2906 
2907     char  pcDumpPrefix[MAX_PATH];
2908     char  pcDumpLoc[MAX_PATH];
2909 
2910     Location  = (VPHAL_DEBUG_STAGE)iDebugStage;
2911     uiPhase   = iPhase;
2912     pDumpSpec = &m_dumpSpec;
2913     if ((pDumpSpec->pBBDumpSpec == nullptr)                          ||
2914         (pDumpSpec->pBBDumpSpec->pDumpLocations == nullptr)          ||
2915         (pDumpSpec->pBBDumpSpec->pDumpLocations->DumpStage == 0))
2916     {
2917         goto finish;
2918     }
2919 
2920     MOS_ZeroMemory(pcDumpPrefix, MAX_PATH);
2921     MOS_ZeroMemory(pcDumpLoc,    MAX_PATH);
2922 
2923     if(pDumpSpec->uiStartFrame <= pDumpSpec->uiCurrentFrame &&
2924         pDumpSpec->uiCurrentFrame <= pDumpSpec->uiEndFrame)
2925     {
2926         for (iIndex= 0; iIndex< pDumpSpec->pBBDumpSpec->iNumDumpLocs; iIndex++)
2927         {
2928             if (pDumpSpec->pBBDumpSpec->pDumpLocations[iIndex].DumpStage == Location)
2929             {
2930                 VPHAL_DEBUG_CHK_STATUS(EnumToLocString(Location, pcDumpLoc));
2931                 MOS_SecureStringPrint(pcDumpPrefix, MAX_PATH, MAX_PATH, "%s/BB_dump_loc[%s]_[%lld]",
2932                     pDumpSpec->pcOutputPath, pcDumpLoc, uiPhase);
2933 
2934                 DumpBatchBufferBinary(
2935                     pBatchBuffer,
2936                     pcDumpPrefix,
2937                     pDumpSpec->uiCurrentFrame);
2938                 break;
2939             }
2940         }
2941     }
2942 
2943 finish:
2944     return;
2945 }
2946 
DumpCommandBuffer(PMOS_COMMAND_BUFFER pCommandBuffer)2947 void VphalHwStateDumper::DumpCommandBuffer(
2948     PMOS_COMMAND_BUFFER       pCommandBuffer)
2949 {
2950     MOS_STATUS           eStatus;
2951     int32_t              iIndex;
2952     uint64_t             uiPhase;
2953     VPHAL_DBG_DUMP_SPEC* pDumpSpec;
2954     VPHAL_DEBUG_STAGE    Location;
2955 
2956     char  pcDumpPrefix[MAX_PATH];
2957     char  pcDumpLoc[MAX_PATH];
2958 
2959     Location  = (VPHAL_DEBUG_STAGE)iDebugStage;
2960     uiPhase   = iPhase;
2961     pDumpSpec = &m_dumpSpec;
2962     if ((pDumpSpec->pCBDumpSpec == nullptr)                          ||
2963         (pDumpSpec->pCBDumpSpec->pDumpLocations == nullptr)          ||
2964         (pDumpSpec->pCBDumpSpec->pDumpLocations->DumpStage == 0))
2965     {
2966         goto finish;
2967     }
2968 
2969     MOS_ZeroMemory(pcDumpPrefix, MAX_PATH);
2970     MOS_ZeroMemory(pcDumpLoc,    MAX_PATH);
2971 
2972     if(pDumpSpec->uiStartFrame <= pDumpSpec->uiCurrentFrame &&
2973         pDumpSpec->uiCurrentFrame <= pDumpSpec->uiEndFrame)
2974     {
2975         for (iIndex= 0; iIndex< pDumpSpec->pCBDumpSpec->iNumDumpLocs; iIndex++)
2976         {
2977             if (pDumpSpec->pCBDumpSpec->pDumpLocations[iIndex].DumpStage == Location)
2978             {
2979                 VPHAL_DEBUG_CHK_STATUS(EnumToLocString(Location, pcDumpLoc));
2980                 MOS_SecureStringPrint(pcDumpPrefix, MAX_PATH, MAX_PATH, "%s/CB_dump_loc[%s]_[%lld]",
2981                     pDumpSpec->pcOutputPath, pcDumpLoc,  uiPhase);
2982 
2983                 DumpCommandBufferBinary(
2984                     pCommandBuffer,
2985                     pcDumpPrefix,
2986                     pDumpSpec->uiCurrentFrame);
2987                 break;
2988             }
2989         }
2990     }
2991 
2992  finish:
2993     return;
2994 }
2995 
DumpVeboxState(PVPHAL_VEBOX_STATE pVeboxState)2996 void VphalHwStateDumper::DumpVeboxState(PVPHAL_VEBOX_STATE pVeboxState)
2997 {
2998     MOS_STATUS           eStatus;
2999     int32_t              iIndex;
3000     uint64_t             uiPhase;
3001     VPHAL_DBG_DUMP_SPEC* pDumpSpec;
3002     VPHAL_DEBUG_STAGE    Location;
3003     PVPHAL_VEBOX_STATE   pVeboxRndrState = (PVPHAL_VEBOX_STATE)pVeboxState;
3004 
3005     char  pcDumpPrefix[MAX_PATH];
3006     char  pcDumpLoc[MAX_PATH];
3007 
3008     Location  = (VPHAL_DEBUG_STAGE)iDebugStage;
3009     uiPhase   = iPhase;
3010     pDumpSpec = &m_dumpSpec;
3011     if ((pDumpSpec->pVeboxStateDumpSpec == nullptr)                          ||
3012         (pDumpSpec->pVeboxStateDumpSpec->pDumpLocations == nullptr)          ||
3013         (pDumpSpec->pVeboxStateDumpSpec->pDumpLocations->DumpStage == 0))
3014     {
3015         goto finish;
3016     }
3017 
3018     MOS_ZeroMemory(pcDumpPrefix, MAX_PATH);
3019     MOS_ZeroMemory(pcDumpLoc,    MAX_PATH);
3020 
3021     if(pDumpSpec->uiStartFrame <= pDumpSpec->uiCurrentFrame &&
3022         pDumpSpec->uiCurrentFrame <= pDumpSpec->uiEndFrame)
3023     {
3024         for (iIndex= 0; iIndex< pDumpSpec->pVeboxStateDumpSpec->iNumDumpLocs; iIndex++)
3025         {
3026             if (pDumpSpec->pVeboxStateDumpSpec->pDumpLocations[iIndex].DumpStage == Location)
3027             {
3028                 VPHAL_DEBUG_CHK_STATUS(EnumToLocString(Location, pcDumpLoc));
3029                 MOS_SecureStringPrint(pcDumpPrefix, MAX_PATH, MAX_PATH, "%s/VeboxState_dump_loc[%s]_",
3030                     pDumpSpec->pcOutputPath,pcDumpLoc);
3031 
3032                 DumpVeboxStateBinary(
3033                     pVeboxRndrState->m_pVeboxInterface,
3034                     pcDumpPrefix,
3035                     pDumpSpec->uiCurrentFrame);
3036                 break;
3037             }
3038         }
3039     }
3040 
3041 finish:
3042     return;
3043 }
3044 
DumpStatistics(void * pVeboxState,uint8_t * pStat0Base,uint8_t * pStat1Base)3045 void VphalHwStateDumper::DumpStatistics(
3046     void*                       pVeboxState,
3047     uint8_t*                    pStat0Base,
3048     uint8_t*                    pStat1Base)
3049 {
3050     MOS_STATUS           eStatus;
3051     int32_t              iIndex;
3052     uint64_t             uiPhase;
3053     VPHAL_DBG_DUMP_SPEC* pDumpSpec;
3054     VPHAL_DEBUG_STAGE    Location;
3055 
3056     char  pcDumpPrefix[MAX_PATH];
3057     char  pcDumpLoc[MAX_PATH];
3058 
3059     Location  = (VPHAL_DEBUG_STAGE)iDebugStage;
3060     uiPhase   = iPhase;
3061     pDumpSpec = &m_dumpSpec;
3062     if ((pDumpSpec->pStatisticsDumpSpec == nullptr)                          ||
3063         (pDumpSpec->pStatisticsDumpSpec->pDumpLocations == nullptr)          ||
3064         (pDumpSpec->pStatisticsDumpSpec->pDumpLocations->DumpStage == 0))
3065     {
3066         goto finish;
3067     }
3068 
3069     MOS_ZeroMemory(pcDumpPrefix, MAX_PATH);
3070     MOS_ZeroMemory(pcDumpLoc,    MAX_PATH);
3071 
3072     if(pDumpSpec->uiStartFrame <= pDumpSpec->uiCurrentFrame &&
3073         pDumpSpec->uiCurrentFrame <= pDumpSpec->uiEndFrame)
3074     {
3075         for (iIndex= 0; iIndex< pDumpSpec->pStatisticsDumpSpec->iNumDumpLocs; iIndex++)
3076         {
3077             if (pDumpSpec->pStatisticsDumpSpec->pDumpLocations[iIndex].DumpStage == Location)
3078             {
3079                 VPHAL_DEBUG_CHK_STATUS(EnumToLocString(Location, pcDumpLoc));
3080                 MOS_SecureStringPrint(pcDumpPrefix, MAX_PATH, MAX_PATH, "%s/Statistics_dump_loc[%s]_",
3081                     pDumpSpec->pcOutputPath,pcDumpLoc);
3082 
3083                 DumpStatisticsBinary(
3084                     (PVPHAL_VEBOX_STATE)pVeboxState,
3085                     pStat0Base,
3086                     pStat1Base,
3087                     pcDumpPrefix,
3088                     pDumpSpec->uiCurrentFrame);
3089                 break;
3090             }
3091         }
3092     }
3093 
3094 finish:
3095     return;
3096 }
3097 
GetParametersDumpSpec()3098 void VphalParameterDumper::GetParametersDumpSpec()
3099 {
3100     MOS_STATUS                      eStatus = MOS_STATUS_SUCCESS;
3101     bool                            bDumpEnabled;
3102     VPHAL_DBG_PARAMS_DUMP_SPEC      *pDumpSpec = &m_dumpSpec;
3103     MediaUserSetting::Value         outValue;
3104 
3105     pDumpSpec->uiStartFrame       = 0xFFFFFFFF;
3106     pDumpSpec->uiEndFrame         = 0;
3107     pDumpSpec->outFileLocation[0] = '\0';
3108     bDumpEnabled                  = false;
3109     // Get start frame
3110     // if start frame is not got assign a default value of 0
3111     ReadUserSettingForDebug(
3112         m_userSettingPtr,
3113         pDumpSpec->uiStartFrame,
3114         __VPHAL_DBG_PARAM_DUMP_START_FRAME_KEY_NAME,
3115         MediaUserSetting::Group::Sequence);
3116 
3117     // Get end frame
3118     // if end frame is not got assign a default value of max
3119     ReadUserSettingForDebug(
3120         m_userSettingPtr,
3121         pDumpSpec->uiEndFrame,
3122         __VPHAL_DBG_PARAM_DUMP_END_FRAME_KEY_NAME,
3123         MediaUserSetting::Group::Sequence);
3124 
3125     // Get out file path
3126     ReadUserSettingForDebug(
3127         m_userSettingPtr,
3128         outValue,
3129         __VPHAL_DBG_PARAM_DUMP_OUTFILE_KEY_NAME,
3130         MediaUserSetting::Group::Sequence);
3131     if (outValue.ConstString().size() > 0 && outValue.ConstString().size() < MOS_USER_CONTROL_MAX_DATA_SIZE)
3132     {
3133         // Copy the Output path
3134         MOS_SecureMemcpy(
3135             pDumpSpec->outFileLocation,
3136             MAX_PATH,
3137             outValue.ConstString().c_str(),
3138             outValue.ConstString().size());
3139         bDumpEnabled = true;
3140     }
3141 #if !defined(LINUX) && !defined(ANDROID)
3142     else
3143     {
3144         std::string vphalDumpFilePath;
3145 
3146         // Use state separation APIs to obtain appropriate storage location
3147         if (SUCCEEDED(GetDriverPersistentStorageLocation(vphalDumpFilePath)))
3148         {
3149             std::string m_outputFilePath;
3150 
3151             m_outputFilePath = vphalDumpFilePath.c_str();
3152             m_outputFilePath.append(VPHAL_DBG_DUMP_OUTPUT_FOLDER);
3153 
3154             // Copy the Output path
3155             MOS_SecureMemcpy(
3156                 pDumpSpec->outFileLocation,
3157                 MAX_PATH,
3158                 m_outputFilePath.c_str(),
3159                 m_outputFilePath.size());
3160 
3161             ReportUserSettingForDebug(m_userSettingPtr, __VPHAL_DBG_DUMP_OUTPUT_DIRECTORY, m_outputFilePath, MediaUserSetting::Group::Sequence);
3162 
3163             bDumpEnabled = true;
3164         }
3165     }
3166 #endif
3167 
3168     // Get enableSkuWaDump
3169     ReadUserSettingForDebug(
3170         m_userSettingPtr,
3171         pDumpSpec->enableSkuWaDump,
3172         __VPHAL_DBG_PARA_DUMP_ENABLE_SKUWA_DUMP,
3173         MediaUserSetting::Group::Sequence);
3174 
3175     if ((eStatus != MOS_STATUS_SUCCESS) || (!bDumpEnabled))
3176     {
3177         pDumpSpec->uiStartFrame = 1;
3178         pDumpSpec->uiEndFrame = 0;
3179     }
3180 }
3181 
DumpSourceSurface(uint32_t uiFrameCounter,char * pcOutputPath,PVPHAL_SURFACE pSrc,uint32_t index,char * & pcOutContents)3182 MOS_STATUS VphalParameterDumper::DumpSourceSurface(
3183     uint32_t                        uiFrameCounter,
3184     char                            *pcOutputPath,
3185     PVPHAL_SURFACE                  pSrc,
3186     uint32_t                        index,
3187     char*                           &pcOutContents)
3188 {
3189     MOS_STATUS                      eStatus;
3190     char                            sSurfaceFilePath[MAX_PATH] = { 0 }, sOsSurfaceFilePath[MAX_PATH] = { 0 };
3191 
3192     eStatus               = MOS_STATUS_SUCCESS;
3193 
3194     //Color Information
3195     {
3196         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<!-- Color Information -->\n"));
3197         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_CSPACE>%s</VPHAL_CSPACE>\n",             GetColorSpaceStr(pSrc->ColorSpace)));
3198         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<EXTENDED_GAMUT></EXTENDED_GAMUT>\n"));
3199         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<PALETTE_ALLOCATION>%d</PALETTE_ALLOCATION>\n", (pSrc->iPalette)));
3200         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<PALETTE_DATA>\n"));
3201         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<PALETTE_DATA_TYPE>%s</PALETTE_DATA_TYPE>\n", GetPaletteTypeStr(pSrc->Palette.PaletteType)));
3202         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<VPHAL_CSPACE>%s</VPHAL_CSPACE>\n",           GetColorSpaceStr(pSrc->Palette.ColorSpace)));
3203         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<HAS_ALPHA>%d</HAS_ALPHA>\n",                 pSrc->Palette.bHasAlpha ? 1 : 0));
3204         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<TOTAL_ENTRIES>%d</TOTAL_ENTRIES>\n",         pSrc->Palette.iTotalEntries));
3205         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<NUM_ENTRIES>%d</NUM_ENTRIES>\n",             pSrc->Palette.iNumEntries));
3206         for (int nIndex = 0; nIndex < pSrc->Palette.iTotalEntries; nIndex++)
3207         {
3208             if (pSrc->Palette.pPalette8)
3209             {
3210                 VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<PVPHAL_COLOR_SAMPLE>%08x</PVPHAL_COLOR_SAMPLE>\n", pSrc->Palette.pPalette8[nIndex].dwValue));
3211             }
3212         }
3213         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</PALETTE_DATA>\n"));
3214 
3215         //Rendering parameters
3216         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<!-- Rendering parameters -->\n"));
3217         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_BLENDING_PARAMS>\n"));
3218         if (pSrc->pBlendingParams)
3219         {
3220             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<VPHAL_BLEND_TYPE>%s</VPHAL_BLEND_TYPE>\n", GetBlendTypeStr(pSrc->pBlendingParams->BlendType)));
3221             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ALPHA type=\"real\">%.3f</ALPHA>\n",       pSrc->pBlendingParams->fAlpha));
3222         }
3223         else
3224         {
3225             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ALPHA type=\"real\"></ALPHA>\n"));
3226         }
3227         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_BLENDING_PARAMS>\n"));
3228 
3229         //Luma key params
3230         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_LUMAKEY_PARAMS>\n"));
3231         if (pSrc->pLumaKeyParams)
3232         {
3233             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<LUMA_LOW>%d</LUMA_LOW>\n", pSrc->pLumaKeyParams->LumaLow));
3234             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<LUMA_HIGH>%d</LUMA_HIGH>\n", pSrc->pLumaKeyParams->LumaHigh));
3235         }
3236         else
3237         {
3238             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<LUMA_LOW></LUMA_LOW>\n"));
3239             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<LUMA_HIGH></LUMA_HIGH>\n"));
3240         }
3241         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_LUMAKEY_PARAMS>\n"));
3242 
3243         //ChromaSitting params
3244         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_CHROMASITTING_PARAMS>\n"));
3245         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CHROMA_SITING_HORZ_LEFT>%d</CHROMA_SITING_HORZ_LEFT>\n", (pSrc->ChromaSiting & CHROMA_SITING_HORZ_LEFT) == CHROMA_SITING_HORZ_LEFT ? 1 : 0));
3246         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CHROMA_SITING_HORZ_CENTER>%d</CHROMA_SITING_HORZ_CENTER>\n", (pSrc->ChromaSiting & CHROMA_SITING_HORZ_CENTER) == CHROMA_SITING_HORZ_CENTER ? 1 : 0));
3247         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CHROMA_SITING_HORZ_RIGHT>%d</CHROMA_SITING_HORZ_RIGHT>\n", (pSrc->ChromaSiting & CHROMA_SITING_HORZ_RIGHT) == CHROMA_SITING_HORZ_RIGHT ? 1 : 0));
3248         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CHROMA_SITING_VERT_TOP>%d</CHROMA_SITING_VERT_TOP>\n", (pSrc->ChromaSiting & CHROMA_SITING_VERT_TOP) == CHROMA_SITING_VERT_TOP ? 1 : 0));
3249         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CHROMA_SITING_VERT_CENTER>%d</CHROMA_SITING_VERT_CENTER>\n", (pSrc->ChromaSiting & CHROMA_SITING_VERT_CENTER) == CHROMA_SITING_VERT_CENTER ? 1 : 0));
3250         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CHROMA_SITING_VERT_BOTTOM>%d</CHROMA_SITING_VERT_BOTTOM>\n", (pSrc->ChromaSiting & CHROMA_SITING_VERT_BOTTOM) == CHROMA_SITING_VERT_BOTTOM ? 1 : 0));
3251         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_CHROMASITTING_PARAMS>\n"));
3252 
3253         //Propcamp params
3254         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_PROCAMP_PARAMS>\n"));
3255         if (pSrc->pProcampParams)
3256         {
3257             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLED>%d</ENABLED>\n",                       (pSrc->pProcampParams->bEnabled ? 1 : 0)));
3258             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<BRIGHTNESS type=\"real\">%.3f</BRIGHTNESS>\n", pSrc->pProcampParams->fBrightness));
3259             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CONTRAST type=\"real\">%.3f</CONTRAST>\n",     pSrc->pProcampParams->fContrast));
3260             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<HUE type=\"real\">%.3f</HUE>\n",               pSrc->pProcampParams->fHue));
3261             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<SATURATION type=\"real\">%.3f</SATURATION>\n", pSrc->pProcampParams->fSaturation));
3262         }
3263         else
3264         {
3265             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLED></ENABLED>\n"));
3266             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<BRIGHTNESS type=\"real\"></BRIGHTNESS>\n"));
3267             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CONTRAST type=\"real\"></CONTRAST>\n"));
3268             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<HUE type=\"real\"></HUE>\n"));
3269             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<SATURATION type=\"real\"></SATURATION>\n"));
3270         }
3271         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_PROCAMP_PARAMS>\n"));
3272 
3273         //IEF parameter
3274         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_IEF_PARAMS>\n"));
3275         if (pSrc->pIEFParams)
3276         {
3277             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<IEFFACTOR type = \"real\">%.3f</IEFFACTOR>\n", pSrc->pIEFParams->fIEFFactor));
3278         }
3279         else
3280         {
3281             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<IEFFACTOR type = \"real\"></IEFFACTOR>\n"));
3282         }
3283         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_IEF_PARAMS>\n"));
3284 
3285         //Advanced processing
3286         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<!-- Advanced processing -->\n"));
3287         //DI
3288         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_DI_PARAMS>\n"));
3289         if (pSrc->pDeinterlaceParams)
3290         {
3291             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<DIMODE>%s</DIMODE>\n",             GetDIModeStr(pSrc->pDeinterlaceParams->DIMode)));
3292             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<ENABLE_FMD>%d</ENABLE_FMD>\n",     (pSrc->pDeinterlaceParams->bEnableFMD ? 1 : 0)));
3293             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<SINGLE_FIELD>%d</SINGLE_FIELD>\n", (pSrc->pDeinterlaceParams->bSingleField ? 1 : 0)));
3294         }
3295         else
3296         {
3297             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<DIMODE></DIMODE>\n"));
3298             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<ENABLE_FMD></ENABLE_FMD>\n"));
3299             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<SINGLE_FIELD></SINGLE_FIELD>\n"));
3300         }
3301         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_DI_PARAMS>\n"));
3302         //Denoise
3303         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_DENOISE_PARAMS>\n"));
3304         if (pSrc->pDenoiseParams)
3305         {
3306             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_LUMA>%d</ENABLE_LUMA>\n",         (pSrc->pDenoiseParams->bEnableLuma ? 1 : 0)));
3307             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_CHROMA>%d</ENABLE_CHROMA>\n",     (pSrc->pDenoiseParams->bEnableChroma ? 1 : 0)));
3308             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<AUTO_DETECT>%d</AUTO_DETECT>\n",         (pSrc->pDenoiseParams->bAutoDetect ? 1 : 0)));
3309             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<DENOISE_FACTOR>%.3f</DENOISE_FACTOR>\n", (pSrc->pDenoiseParams->fDenoiseFactor)));
3310             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<NOISE_LEVEL>%s</NOISE_LEVEL>\n", GetDenoiseModeStr(pSrc->pDenoiseParams->NoiseLevel)));
3311             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_HVS_DENOISE>%d</ENABLE_HVS_DENOISE>\n", (pSrc->pDenoiseParams->bEnableHVSDenoise ? 1 : 0)));
3312             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<HVS_DENOISE_QP>%d</HVS_DENOISE_QP>\n", (pSrc->pDenoiseParams->HVSDenoise.QP)));
3313             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<HVS_DENOISE_STRENGTH>%d</HVS_DENOISE_STRENGTH>\n", (pSrc->pDenoiseParams->HVSDenoise.Strength)));
3314             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<HVS_DENOISE_MODE>%s</HVS_DENOISE_MODE>\n", GetHVSDenoiseModeStr(pSrc->pDenoiseParams->HVSDenoise.Mode)));
3315         }
3316         else
3317         {
3318             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_LUMA></ENABLE_LUMA>\n"));
3319             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_CHROMA></ENABLE_CHROMA>\n"));
3320             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<AUTO_DETECT></AUTO_DETECT>\n"));
3321             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<DENOISE_FACTOR></DENOISE_FACTOR>\n"));
3322         }
3323         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_DENOISE_PARAMS>\n"));
3324         //ColorPipe
3325         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_COLORPIPE_PARAMS>\n"));
3326         if (pSrc->pColorPipeParams)
3327         {
3328             VPHAL_TCC_PARAMS TccParams = pSrc->pColorPipeParams->TccParams;
3329             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_ACE>%d</ENABLE_ACE>\n",                (pSrc->pColorPipeParams->bEnableACE ? 1 : 0)));
3330             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_STE>%d</ENABLE_STE>\n",                (pSrc->pColorPipeParams->bEnableSTE ? 1 : 0)));
3331             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_TCC>%d</ENABLE_TCC>\n",                (pSrc->pColorPipeParams->bEnableTCC ? 1 : 0)));
3332             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ACE_LEVEL>%d</ACE_LEVEL>\n",                  (pSrc->pColorPipeParams->dwAceLevel)));
3333             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ACE_STRENGHTH>%d</ACE_STRENGHTH>\n",          (pSrc->pColorPipeParams->dwAceStrength)));
3334             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<STE_PARAMS>\n"));
3335             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t\t<STE_FACTOR>%d</STE_FACTOR>\n",              (pSrc->pColorPipeParams->SteParams.dwSTEFactor)));
3336             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t</STE_PARAMS>\n"));
3337             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<TCC_PARAMS>%d,%d,%d,%d,%d,%d</TCC_PARAMS>\n", TccParams.Blue, TccParams.Cyan, TccParams.Green, TccParams.Magenta, TccParams.Red, TccParams.Yellow));
3338         }
3339         else
3340         {
3341             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_ACE></ENABLE_ACE>\n"));
3342             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_STE></ENABLE_STE>\n"));
3343             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ENABLE_TCC></ENABLE_TCC>\n"));
3344             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<ACE_LEVEL></ACE_LEVEL>\n"));
3345             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<STE_PARAMS></STE_PARAMS>\n"));
3346             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<TCC_PARAMS></TCC_PARAMS>\n"));
3347         }
3348         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_COLORPIPE_PARAMS>\n"));
3349         //Gamut
3350         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_GAMUT_PARAMS>\n"));
3351         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<GCOMP_MODE></GCOMP_MODE>\n"));
3352         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_GAMUT_PARAMS>\n"));
3353 
3354         //Sample information
3355         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<!-- Sample information -->\n"));
3356         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_FORMAT>%s</VPHAL_FORMAT>\n",             GetWholeFormatStr(pSrc->Format)));
3357         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_SURFACE_TYPE>%s</VPHAL_SURFACE_TYPE>\n", GetSurfaceTypeStr(pSrc->SurfType)));
3358         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_SAMPLE_TYPE>%s</VPHAL_SAMPLE_TYPE>\n",   GetSampleTypeStr(pSrc->SampleType)));
3359         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_SCALING_MODE>%s</VPHAL_SCALING_MODE>\n", GetScalingModeStr(pSrc->ScalingMode)));
3360         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_ROTATION_MODE>%s</VPHAL_ROTATION_MODE>\n", GetRotationModeStr(pSrc->Rotation)));
3361         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<RCSRC>%d,%d,%d,%d</RCSRC>\n",                  pSrc->rcSrc.left, pSrc->rcSrc.top, pSrc->rcSrc.right, pSrc->rcSrc.bottom));
3362         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<RCDST>%d,%d,%d,%d</RCDST>\n",                  pSrc->rcDst.left, pSrc->rcDst.top, pSrc->rcDst.right, pSrc->rcDst.bottom));
3363 
3364         //Basic information
3365         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<!-- Basic information -->\n"));
3366         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_TILE_TYPE>%s</VPHAL_TILE_TYPE>\n", GetTileTypeStr(pSrc->TileType)));
3367         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<WIDTH>%d</WIDTH>\n",                     pSrc->dwWidth));
3368         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<HEIGHT>%d</HEIGHT>\n",                   pSrc->dwHeight));
3369         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<PITCH>%d</PITCH>\n",                     pSrc->dwPitch));
3370         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<SIZE>%d</SIZE>\n",                       pSrc->dwPitch * pSrc->dwHeight));
3371 
3372         //Surface content initialization
3373         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<!-- Surface content initialization -->\n"));
3374         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<DATA>\n"));
3375         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<DEFAULT_COLOR type=\"integer\">0x000000FF</DEFAULT_COLOR>\n"));
3376         if (pcOutputPath)
3377         {
3378             memset(sSurfaceFilePath, 0, MAX_PATH);
3379             memset(sOsSurfaceFilePath, 0, MAX_PATH);
3380 
3381             MOS_SecureStringPrint(sSurfaceFilePath, MAX_PATH, MAX_PATH, "%s%csurfdump_loc[preALL]_lyr[%d]_f[%03d]_w[%d]_h[%d]_p[%d].%s",
3382                 pcOutputPath, MOS_DIR_SEPERATOR, index, uiFrameCounter, pSrc->dwWidth, pSrc->dwHeight, pSrc->dwPitch, VphalDumperTool::GetFormatStr(pSrc->Format));
3383             VphalDumperTool::GetOsFilePath(sSurfaceFilePath, sOsSurfaceFilePath);
3384         }
3385         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<FILE>%s</FILE>\n", sOsSurfaceFilePath));
3386         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</DATA>\n"));
3387         // get backward reference
3388         if (pSrc->pBwdRef)
3389         {
3390             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<BACKREFDATA>\n"));
3391             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<DEFAULT_COLOR type=\"integer\">0x000000FF</DEFAULT_COLOR>\n"));
3392             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<Num>%d</Num>\n", pSrc->uBwdRefCount));
3393             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<FILE></FILE>\n"));
3394             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</BACKREFDATA>\n"));
3395         }
3396         // get forward reference
3397         if (pSrc->pFwdRef)
3398         {
3399             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<FWDREFDATA>\n"));
3400             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<Num>%d</Num>\n", pSrc->uFwdRefCount));
3401             VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</FWDREFDATA>\n"));
3402         }
3403     }
3404 
3405     finish:
3406         return eStatus;
3407 }
3408 
DumpTargetSurface(uint32_t uiFrameCounter,char * pcOutputPath,PVPHAL_SURFACE pTarget,uint32_t index,char * & pcOutContents)3409 MOS_STATUS VphalParameterDumper::DumpTargetSurface(
3410     uint32_t                        uiFrameCounter,
3411     char                            *pcOutputPath,
3412     PVPHAL_SURFACE                  pTarget,
3413     uint32_t                        index,
3414     char*                           &pcOutContents)
3415 {
3416     MOS_STATUS                      eStatus;
3417 
3418     eStatus = MOS_STATUS_SUCCESS;
3419 
3420     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<VPHAL_FORMAT>%s</VPHAL_FORMAT>\n",             VphalParameterDumper::GetWholeFormatStr(pTarget->Format)));
3421     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<VPHAL_SURFACE_TYPE>%s</VPHAL_SURFACE_TYPE>\n", VphalParameterDumper::GetSurfaceTypeStr(pTarget->SurfType)));
3422     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<VPHAL_SAMPLE_TYPE>%s</VPHAL_SAMPLE_TYPE>\n",   GetSampleTypeStr(pTarget->SampleType)));
3423     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<VPHAL_CSPACE>%s</VPHAL_CSPACE>\n",             GetColorSpaceStr(pTarget->ColorSpace)));
3424     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<VPHAL_SCALING_MODE>%s</VPHAL_SCALING_MODE>\n", GetScalingModeStr(pTarget->ScalingMode)));
3425     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<VPHAL_TILE_TYPE>%s</VPHAL_TILE_TYPE>\n",       GetTileTypeStr(pTarget->TileType)));
3426     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<WIDTH>%d</WIDTH>\n",                           pTarget->dwWidth));
3427     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<HEIGHT>%d</HEIGHT>\n",                         pTarget->dwHeight));
3428     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<PITCH>%d</PITCH>\n",                           pTarget->dwPitch));
3429     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<SIZE>%d</SIZE>\n",                             pTarget->dwPitch*pTarget->dwHeight));
3430     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<RCSRC>%d,%d,%d,%d</RCSRC>\n",                    pTarget->rcSrc.left, pTarget->rcSrc.top, pTarget->rcSrc.right, pTarget->rcSrc.bottom));
3431     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<RCDST>%d,%d,%d,%d</RCDST>\n",                    pTarget->rcDst.left, pTarget->rcDst.top, pTarget->rcDst.right, pTarget->rcDst.bottom));
3432     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<DATA>\n"));
3433     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t\t<DEFAULT_COLOR type=\"integer\">0x000000FF</DEFAULT_COLOR>\n"));
3434     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t\t<FILE></FILE>\n"));
3435     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t</DATA>\n"));
3436 
3437 finish:
3438     return eStatus;
3439 }
3440 
DumpRenderParameter(uint32_t uiFrameCounter,char * pcOutputPath,PVPHAL_RENDER_PARAMS pRenderParams,char * & pcOutContents)3441 MOS_STATUS VphalParameterDumper::DumpRenderParameter(
3442     uint32_t                        uiFrameCounter,
3443     char                            *pcOutputPath,
3444     PVPHAL_RENDER_PARAMS            pRenderParams,
3445     char*                           &pcOutContents)
3446 {
3447     MOS_STATUS                      eStatus;
3448 
3449     eStatus = MOS_STATUS_SUCCESS;
3450 
3451     if (pRenderParams->pTarget[0])
3452     {
3453         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_SURFACE_TARGET>\n"));
3454         VPHAL_DEBUG_CHK_STATUS(DumpTargetSurface(
3455             uiFrameCounter,
3456             pcOutputPath,
3457             pRenderParams->pTarget[0],
3458             0,
3459             pcOutContents));
3460         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_SURFACE_TARGET>\n"));
3461     }
3462     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<SRC_COUNT>%d</SRC_COUNT>\n", pRenderParams->uSrcCount));
3463 
3464     //Color fill
3465     if (pRenderParams->pColorFillParams)
3466     {
3467         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_COLORFILL_PARAMS>\n"));
3468         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<bYCbCr>%d</bYCbCr>\n", pRenderParams->pColorFillParams->bYCbCr));
3469         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<COLOR type=\"integer\">%08x</COLOR>\n", pRenderParams->pColorFillParams->Color));
3470         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t\t<CSPACE>%s</CSPACE>\n", GetColorSpaceStr(pRenderParams->pColorFillParams->CSpace)));
3471         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t</VPHAL_COLORFILL_PARAMS>\n"));
3472     }
3473 
3474     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t\t<VPHAL_COMPONENT>%s</VPHAL_COMPONENT>\n", GetComponentStr(pRenderParams->Component)));
3475 
3476 finish:
3477     return eStatus;
3478 }
3479 
DumpToXML(uint32_t uiFrameCounter,char * pcOutputPath,PVPHAL_RENDER_PARAMS pRenderParams)3480 MOS_STATUS VphalParameterDumper::DumpToXML(
3481     uint32_t                        uiFrameCounter,
3482     char                            *pcOutputPath,
3483     PVPHAL_RENDER_PARAMS            pRenderParams)
3484 {
3485     char                            sPath[MAX_PATH] = { 0 }, sOsPath[MAX_PATH] = { 0 };
3486     MOS_STATUS                      eStatus;
3487     char*                           pcOutContents;
3488     uint32_t                        dwStrLen = 0;
3489     FILE                            *fpOutXML;
3490     char*                           pCurFrameFileName;
3491     char*                           pBwdFrameFileName;
3492     VPHAL_DBG_PARAMS_DUMP_SPEC      *pParamsDumpSpec = &m_dumpSpec;
3493 
3494     eStatus               = MOS_STATUS_SUCCESS;
3495     dwStrLen              = 0;
3496     pcOutContents         = nullptr;
3497     fpOutXML              = nullptr;
3498     pCurFrameFileName     = nullptr;
3499     pBwdFrameFileName     = nullptr;
3500 
3501     VPHAL_DEBUG_CHK_NULL(pRenderParams);
3502     VPHAL_DEBUG_CHK_NULL(pParamsDumpSpec);
3503 
3504     if ((pParamsDumpSpec->uiEndFrame < pParamsDumpSpec->uiStartFrame) || strlen(pParamsDumpSpec->outFileLocation) == 0)
3505         goto finish;
3506 
3507     // Create a processing instruction element.
3508     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(true, &pcOutContents,  "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"));
3509     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\n"));
3510     // Create the root element.
3511     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "<VPHAL_SCENARIO>\n"));
3512     // General infomation
3513     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<ID>%d</ID>\n", MosUtilities::MosGetPid()));
3514 
3515     VPHAL_DEBUG_CHK_NULL(pRenderParams->pSrc[0]);
3516     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<DESCRIPTION>%d</DESCRIPTION>\n", pRenderParams->pSrc[0]->FrameID));
3517     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<!-- Number of frames to render -->\n"));
3518     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<FRAME_COUNT type = \"integer\">1</FRAME_COUNT>\n"));
3519     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<!-- 60i or 30p BLT -->\n"));
3520     if ((pRenderParams->uSrcCount > 0) &&
3521         (pRenderParams->pSrc[0]->SampleType != SAMPLE_PROGRESSIVE))
3522     {
3523         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<BLT_TYPE>60i</BLT_TYPE>\n"));
3524     }
3525     else
3526     {
3527         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<BLT_TYPE>30p</BLT_TYPE>\n"));
3528     }
3529 
3530     // Surface
3531     for (uint32_t i = 0; i < pRenderParams->uSrcCount; i++)
3532     {
3533         if (pRenderParams->pSrc[i] == nullptr)
3534             continue;
3535 
3536         //surface infomation
3537         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<!-- Input surface definitions -->\n"));
3538         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<VPHAL_SURFACE>\n"));
3539 
3540         VPHAL_DEBUG_CHK_STATUS(DumpSourceSurface(
3541             uiFrameCounter,
3542             pcOutputPath,
3543             pRenderParams->pSrc[i],
3544             i,
3545             pcOutContents));
3546         VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t</VPHAL_SURFACE>\n"));
3547     }
3548 
3549     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<!-- Rendering parameters -->\n"));
3550     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t<VPHAL_RENDER_PARAMS>\n"));
3551 
3552     VPHAL_DEBUG_CHK_STATUS(DumpRenderParameter(
3553         uiFrameCounter,
3554         pcOutputPath,
3555         pRenderParams,
3556         pcOutContents));
3557 
3558     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "\t</VPHAL_RENDER_PARAMS>\n"));
3559     VPHAL_DEBUG_CHK_STATUS(VphalDumperTool::AppendString(false, &pcOutContents, "</VPHAL_SCENARIO>\n"));
3560 
3561     MOS_SecureStringPrint(sPath, MAX_PATH, MAX_PATH, "%s%cparam_dump[%d].xml", pParamsDumpSpec->outFileLocation, MOS_DIR_SEPERATOR, uiFrameCounter);
3562 
3563     VphalDumperTool::GetOsFilePath(sPath, sOsPath);
3564 
3565     VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(sOsPath, pcOutContents, strlen(pcOutContents)));
3566 finish:
3567     if (pcOutContents)
3568     {
3569         MOS_FreeMemory(pcOutContents);
3570         pcOutContents = nullptr;
3571     }
3572     return eStatus;
3573 }
3574 
VphalParameterDumper(PMOS_INTERFACE pOsInterface)3575 VphalParameterDumper::VphalParameterDumper(PMOS_INTERFACE pOsInterface) :
3576     m_dumpSpec(),
3577     m_osInterface(pOsInterface)
3578 {
3579     if (m_osInterface)
3580     {
3581         m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
3582     }
3583 }
3584 
~VphalParameterDumper()3585 VphalParameterDumper::~VphalParameterDumper()
3586 {
3587 }
3588 
GetFormatStr(MOS_FORMAT format)3589 const char * VphalDumperTool::GetFormatStr(MOS_FORMAT format)
3590 {
3591     switch (format)
3592     {
3593         case Format_A8R8G8B8    : return _T("argb");
3594         case Format_X8R8G8B8    : return _T("xrgb");
3595         case Format_A8B8G8R8    : return _T("abgr");
3596         case Format_X8B8G8R8    : return _T("xbgr");
3597         case Format_A16R16G16B16: return _T("argb16");
3598         case Format_A16B16G16R16: return _T("abgr16");
3599         case Format_R5G6B5      : return _T("rgb16");
3600         case Format_R8G8B8      : return _T("rgb24");
3601         case Format_R32U        : return _T("r32u");
3602         case Format_RGBP        : return _T("rgbp");
3603         case Format_BGRP        : return _T("bgrp");
3604         case Format_R32F        : return _T("r32f");
3605         case Format_YUY2        : return _T("yuy2");
3606         case Format_YUYV        : return _T("yuyv");
3607         case Format_YVYU        : return _T("yvyu");
3608         case Format_UYVY        : return _T("uyvy");
3609         case Format_VYUY        : return _T("vyuy");
3610         case Format_Y416        : return _T("y416");
3611         case Format_AYUV        : return _T("ayuv");
3612         case Format_AUYV        : return _T("auyv");
3613         case Format_NV12        : return _T("nv12");
3614         case Format_NV11        : return _T("nv11");
3615         case Format_P208        : return _T("p208");
3616         case Format_IMC1        : return _T("imc1");
3617         case Format_IMC2        : return _T("imc2");
3618         case Format_IMC3        : return _T("imc3");
3619         case Format_IMC4        : return _T("imc4");
3620         case Format_422H        : return _T("422h");
3621         case Format_422V        : return _T("422v");
3622         case Format_444P        : return _T("444p");
3623         case Format_411P        : return _T("411p");
3624         case Format_411R        : return _T("411r");
3625         case Format_400P        : return _T("400p");
3626         case Format_I420        : return _T("i420");
3627         case Format_IYUV        : return _T("iyuv");
3628         case Format_YV12        : return _T("yv12");
3629         case Format_YVU9        : return _T("yvu9");
3630         case Format_AI44        : return _T("ai44");
3631         case Format_IA44        : return _T("ia44");
3632         case Format_P8          : return _T("P8");
3633         case Format_STMM        : return _T("stmm");
3634         case Format_Buffer      : return _T("buff");
3635         case Format_RAW         : return _T("buff");
3636         case Format_PAL         : return _T("pal");
3637         case Format_A8P8        : return _T("a8p8");
3638         case Format_A8          : return _T("a8");
3639         case Format_L8          : return _T("l8");
3640         case Format_A4L4        : return _T("a4l4");
3641         case Format_A8L8        : return _T("a8l8");
3642         case Format_V8U8        : return _T("v8u8");
3643         case Format_IRW0        : return _T("irw0");
3644         case Format_IRW1        : return _T("irw1");
3645         case Format_IRW2        : return _T("irw2");
3646         case Format_IRW3        : return _T("irw3");
3647         case Format_R10G10B10A2 : return _T("r10g10b10a2");
3648         case Format_B10G10R10A2 : return _T("b10g10r10a2");
3649         case Format_P010        : return _T("p010");
3650         case Format_P016        : return _T("p016");
3651         case Format_R16F        : return _T("r16f");
3652         case Format_Y210        : return _T("y210");
3653         case Format_Y216        : return _T("y216");
3654         case Format_Y410        : return _T("y410");
3655         case Format_P210        : return _T("p210");
3656         case Format_P216        : return _T("p216");
3657         case Format_A16B16G16R16F : return _T("abgr16_float");
3658         case Format_A16R16G16B16F : return _T("argb16_float");
3659         default                 : return _T("Err");
3660     }
3661 
3662     return nullptr;
3663 }
3664 
GetSurfaceSize(PVPHAL_SURFACE pSurface,uint32_t iBpp,uint32_t * piWidthInBytes,uint32_t * piHeightInRows)3665 MOS_STATUS VphalDumperTool::GetSurfaceSize(
3666     PVPHAL_SURFACE          pSurface,
3667     uint32_t                iBpp,
3668     uint32_t*               piWidthInBytes,
3669     uint32_t*               piHeightInRows)
3670 {
3671     MOS_STATUS  eStatus;
3672     uint32_t    iWidthInBytes;
3673     uint32_t    iHeightInRows;
3674 
3675     //-------------------------------------------
3676     VPHAL_DEBUG_ASSERT(pSurface->dwWidth >= 1);
3677     VPHAL_DEBUG_ASSERT(pSurface->dwHeight >= 1);
3678     VPHAL_DEBUG_ASSERT(pSurface->dwPitch >= 1);
3679     //-------------------------------------------
3680 
3681     eStatus = MOS_STATUS_SUCCESS;
3682 
3683     switch (pSurface->Format)
3684     {
3685         // Packed Formats
3686         case Format_A8R8G8B8:
3687         case Format_X8R8G8B8:
3688         case Format_A8B8G8R8:
3689         case Format_X8B8G8R8:
3690         case Format_R5G6B5:
3691         case Format_R8G8B8:
3692         case Format_R32U:
3693         case Format_R32F:
3694         case Format_AYUV:
3695         case Format_YUY2:
3696         case Format_YUYV:
3697         case Format_YVYU:
3698         case Format_UYVY:
3699         case Format_VYUY:
3700         case Format_AI44:
3701         case Format_IA44:
3702         case Format_P8:
3703         case Format_A8P8:
3704         case Format_A8:
3705         case Format_L8:
3706         case Format_A4L4:
3707         case Format_A8L8:
3708         case Format_V8U8:
3709         case Format_R10G10B10A2:
3710         case Format_B10G10R10A2:
3711         case Format_Y210:
3712         case Format_Y216:
3713         case Format_Y410:
3714         case Format_Y416:
3715         case Format_R16F:
3716             iWidthInBytes = pSurface->dwWidth * iBpp / 8;
3717             iHeightInRows = pSurface->dwHeight;
3718             break;
3719 
3720         // 4:2:0 (12-bits per pixel)
3721         // IMC1                           // IMC3
3722         // ----------------->             // ----------------->
3723         // ________________________       // ________________________
3724         //|Y0|Y1|                  |      //|Y0|Y1|                  |
3725         //|__|__|                  |      //|__|__|                  |
3726         //|                        |      //|                        |
3727         //|                        |      //|                        |
3728         //|                        |      //|                        |
3729         //|                        |      //|                        |
3730         //|                        |      //|                        |
3731         //|________________________|      //|________________________|
3732         //|V0|V1|      |           |      //|U0|U1|      |           |
3733         //|__|__|      |           |      //|__|__|      |           |
3734         //|            |           |      //|            |           |
3735         //|____________|  PAD      |      //|____________|  PAD      |
3736         //|U0|U1|      |           |      //|V0|V1|      |           |
3737         //|__|__|      |           |      //|__|__|      |           |
3738         //|            |           |      //|            |           |
3739         //|____________|___________|      //|____________|___________|
3740         case Format_IMC1:
3741         case Format_IMC3:
3742             iWidthInBytes = pSurface->dwWidth;
3743             iHeightInRows = pSurface->dwHeight * 2;
3744             break;
3745 
3746         // 4:0:0 (8-bits per pixel)
3747         // 400P
3748         // ----------------->
3749         // ________________________
3750         //|Y0|Y1|                  |
3751         //|__|__|                  |
3752         //|                        |
3753         //|                        |
3754         //|                        |
3755         //|                        |
3756         //|                        |
3757         //|________________________|
3758         case Format_400P:
3759         case Format_Buffer:
3760         case Format_RAW:
3761             iWidthInBytes = pSurface->dwWidth;
3762             iHeightInRows = pSurface->dwHeight;
3763             break;
3764 
3765         // 4:1:1 (12-bits per pixel)      // 4:2:2 (16-bits per pixel)
3766         // 411P                           // 422H
3767         // ----------------->             // ----------------->
3768         // ________________________       // ________________________
3769         //|Y0|Y1|                  |      //|Y0|Y1|                  |
3770         //|__|__|                  |      //|__|__|                  |
3771         //|                        |      //|                        |
3772         //|                        |      //|                        |
3773         //|                        |      //|                        |
3774         //|                        |      //|                        |
3775         //|                        |      //|                        |
3776         //|________________________|      //|________________________|
3777         //|U0|U1||                 |      //|U0|U1|      |           |
3778         //|__|__||                 |      //|__|__|      |           |
3779         //|      |                 |      //|            |           |
3780         //|      |      PAD        |      //|            |    PAD    |
3781         //|      |                 |      //|            |           |
3782         //|      |                 |      //|            |           |
3783         //|      |                 |      //|            |           |
3784         //|______|_________________|      //|____________|___________|
3785         //|V0|V1||                 |      //|V0|V1|      |           |
3786         //|__|__||                 |      //|__|__|      |           |
3787         //|      |                 |      //|            |           |
3788         //|      |      PAD        |      //|            |    PAD    |
3789         //|      |                 |      //|            |           |
3790         //|      |                 |      //|            |           |
3791         //|      |                 |      //|            |           |
3792         //|______|_________________|      //|____________|___________|
3793 
3794         // 4:4:4 (24-bits per pixel)
3795         // 444P
3796         // ----------------->
3797         // ________________________
3798         //|Y0|Y1|                  |
3799         //|__|__|                  |
3800         //|                        |
3801         //|                        |
3802         //|                        |
3803         //|                        |
3804         //|                        |
3805         //|________________________|
3806         //|U0|U1|                  |
3807         //|__|__|                  |
3808         //|                        |
3809         //|                        |
3810         //|                        |
3811         //|                        |
3812         //|                        |
3813         //|________________________|
3814         //|V0|V1|                  |
3815         //|__|__|                  |
3816         //|                        |
3817         //|                        |
3818         //|                        |
3819         //|                        |
3820         //|                        |
3821         //|________________________|
3822 
3823         // 4:4:4 (24-bits per pixel)
3824         // RGBP
3825         // ----------------->
3826         // ________________________
3827         //|R0|R1|                  |
3828         //|__|__|                  |
3829         //|                        |
3830         //|                        |
3831         //|                        |
3832         //|                        |
3833         //|                        |
3834         //|________________________|
3835         //|G0|G1|                  |
3836         //|__|__|                  |
3837         //|                        |
3838         //|                        |
3839         //|                        |
3840         //|                        |
3841         //|                        |
3842         //|________________________|
3843         //|B0|B1|                  |
3844         //|__|__|                  |
3845         //|                        |
3846         //|                        |
3847         //|                        |
3848         //|                        |
3849         //|                        |
3850         //|________________________|
3851         case Format_RGBP:
3852 
3853         // 4:4:4 (24-bits per pixel)
3854         // BGRP
3855         // ----------------->
3856         // ________________________
3857         //|B0|B1|                  |
3858         //|__|__|                  |
3859         //|                        |
3860         //|                        |
3861         //|                        |
3862         //|                        |
3863         //|                        |
3864         //|________________________|
3865         //|G0|G1|                  |
3866         //|__|__|                  |
3867         //|                        |
3868         //|                        |
3869         //|                        |
3870         //|                        |
3871         //|                        |
3872         //|________________________|
3873         //|R0|R1|                  |
3874         //|__|__|                  |
3875         //|                        |
3876         //|                        |
3877         //|                        |
3878         //|                        |
3879         //|                        |
3880         //|________________________|
3881         case Format_BGRP:
3882         case Format_411P:
3883         case Format_422H:
3884         case Format_444P:
3885             iWidthInBytes = pSurface->dwWidth;
3886             iHeightInRows = pSurface->dwHeight * 3;
3887             break;
3888 
3889         // 4:1:1 (12-bits per pixel)
3890         // 411R
3891         // ----------------->
3892         // ________________________
3893         //|Y0|Y1|                  |
3894         //|__|__|                  |
3895         //|                        |
3896         //|                        |
3897         //|                        |
3898         //|                        |
3899         //|                        |
3900         //|________________________|
3901         //|U0|U1|                  |
3902         //|__|__|                  |
3903         //|________________________|
3904         //|V0|V1|                  |
3905         //|__|__|                  |
3906         //|________________________|
3907         case Format_411R:
3908             iWidthInBytes = pSurface->dwWidth;
3909             iHeightInRows = (pSurface->dwHeight * 3) / 2;
3910             break;
3911 
3912         // 4:2:2V (16-bits per pixel)
3913         // 422V
3914         // ----------------->
3915         // ________________________
3916         //|Y0|Y1|                  |
3917         //|__|__|                  |
3918         //|                        |
3919         //|                        |
3920         //|                        |
3921         //|                        |
3922         //|                        |
3923         //|________________________|
3924         //|U0|U1|                  |
3925         //|__|__|                  |
3926         //|                        |
3927         //|________________________|
3928         //|V0|V1|                  |
3929         //|__|__|                  |
3930         //|                        |
3931         //|________________________|
3932         case Format_422V:
3933             iWidthInBytes = pSurface->dwWidth;
3934             iHeightInRows = pSurface->dwHeight * 2;
3935             break;
3936 
3937         // 4:2:0 (12-bits per pixel)
3938         // IMC2                          // IMC4
3939         // ----------------->            // ----------------->
3940         // ________________________      // ________________________
3941         //|Y0|Y1|                  |     //|Y0|Y1|                  |
3942         //|__|__|                  |     //|__|__|                  |
3943         //|                        |     //|                        |
3944         //|                        |     //|                        |
3945         //|                        |     //|                        |
3946         //|                        |     //|                        |
3947         //|                        |     //|                        |
3948         //|________________________|     //|________________________|
3949         //|V0|V1|      |U0|U1|     |     //|U0|U1|      |V0|V1|     |
3950         //|__|__|      |__|__|     |     //|__|__|      |__|__|     |
3951         //|            |           |     //|            |           |
3952         //|____________|___________|     //|____________|___________|
3953 
3954         // NV12                          // YV12
3955         // ----------------->            // ----------------->
3956         // ________________________      // ________________________
3957         //|Y0|Y1|                  |     //|Y0|Y1|                  |
3958         //|__|__|                  |     //|__|__|                  |
3959         //|                        |     //|                        |
3960         //|                        |     //|                        |
3961         //|                        |     //|                        |
3962         //|                        |     //|                        |
3963         //|                        |     //|                        |
3964         //|________________________|     //|________________________|
3965         //|U0|V0|U1|V1|            |     //|V0|V1|                  |
3966         //|__|__|__|__|            |     //|__|__|__________________|
3967         //|                        |     //|U0|U1|                  |
3968         //|________________________|     //|__|__|__________________|
3969 
3970         case Format_IMC2:
3971         case Format_IMC4:
3972         case Format_NV12:
3973         case Format_YV12:
3974         case Format_I420:
3975         case Format_IYUV:
3976         case Format_YVU9:
3977             iWidthInBytes = pSurface->dwWidth;
3978             iHeightInRows = pSurface->dwHeight * iBpp / 8;
3979             break;
3980 
3981         case Format_P010:
3982         case Format_P016:
3983             iWidthInBytes = pSurface->dwWidth * 2;
3984             iHeightInRows = pSurface->dwHeight * 3 / 2;
3985             break;
3986 
3987         case Format_A16R16G16B16:
3988         case Format_A16B16G16R16:
3989             iWidthInBytes = pSurface->dwWidth * 8;
3990             iHeightInRows = pSurface->dwHeight;
3991             break;
3992 
3993         case Format_P210:
3994         case Format_P216:
3995             iWidthInBytes = pSurface->dwWidth * 2;
3996             iHeightInRows = pSurface->dwHeight * 2;
3997 
3998         default:
3999             VPHAL_DEBUG_ASSERTMESSAGE("Format %d not supported.", pSurface->Format);
4000             eStatus = MOS_STATUS_UNKNOWN;
4001             goto finish;
4002     }
4003 
4004     *piWidthInBytes = iWidthInBytes;
4005     *piHeightInRows = iHeightInRows;
4006 
4007 finish:
4008     return eStatus;
4009 }
4010 
AppendString(bool bFirst,char ** ppcBigString,PCCHAR pcToAppendFmt,...)4011 MOS_STATUS VphalDumperTool::AppendString(
4012     bool   bFirst,
4013     char*  *ppcBigString,
4014     PCCHAR pcToAppendFmt,
4015     ...)
4016 {
4017     static size_t stTotalStrLen = 0;
4018     static size_t stTotalAlloc  = 0;
4019 
4020     MOS_STATUS  eStatus;
4021     size_t      stStrLenOld;
4022     size_t      stStrLenToAppend;
4023     char*       pcToAppend;
4024     char*       pcTmpPtr;
4025     va_list     argList;
4026 
4027     eStatus          = MOS_STATUS_SUCCESS;
4028     stStrLenToAppend = 0;
4029     stStrLenOld      = 0;
4030     pcTmpPtr         = nullptr;
4031     pcToAppend       = (char*)MOS_AllocAndZeroMemory(sizeof(char) * ALLOC_GRANULARITY);
4032 
4033     if (bFirst)
4034     {
4035         stTotalStrLen = 0;
4036         stTotalAlloc  = 0;
4037     }
4038 
4039     stStrLenOld = stTotalStrLen;
4040 
4041     if (ppcBigString == nullptr || pcToAppendFmt == nullptr || (int)strlen(pcToAppendFmt) < 0)
4042     {
4043         eStatus = MOS_STATUS_INVALID_PARAMETER;
4044         goto finish;
4045     }
4046 
4047     va_start(argList, pcToAppendFmt);
4048     MosUtilities::MosSecureVStringPrint(pcToAppend, ALLOC_GRANULARITY, ALLOC_GRANULARITY, pcToAppendFmt, argList);
4049     va_end(argList);
4050 
4051     stStrLenToAppend = strlen(pcToAppend);
4052 
4053     if (*ppcBigString == nullptr)
4054     {
4055         stTotalStrLen = stStrLenToAppend + 1;
4056         stTotalAlloc  = MOS_ALIGN_CEIL(stStrLenToAppend, ALLOC_GRANULARITY);
4057         *ppcBigString = (char*)MOS_AllocAndZeroMemory(stTotalAlloc);
4058         VPHAL_DEBUG_CHK_NULL(*ppcBigString);
4059         *ppcBigString[0] = '\0';
4060         stStrLenOld++;
4061     }
4062     else
4063     {
4064         stTotalStrLen += stStrLenToAppend;
4065         if (stTotalStrLen >= stTotalAlloc)
4066         {
4067             stTotalAlloc = MOS_ALIGN_CEIL(stTotalStrLen, ALLOC_GRANULARITY);
4068             // Below should be equivalent to *ppcBigString = (char*)realloc(*ppcBigString, stTotalAlloc);
4069             pcTmpPtr = *ppcBigString;
4070             *ppcBigString = (char*)MOS_AllocAndZeroMemory(stTotalAlloc);
4071             VPHAL_DEBUG_CHK_NULL(*ppcBigString);
4072             MOS_SecureStringPrint(*ppcBigString, stTotalAlloc, stTotalAlloc, "%s", pcTmpPtr);
4073             MOS_FreeMemory(pcTmpPtr);
4074         }
4075     }
4076     MOS_SecureMemcpy(
4077         (char*)(((uintptr_t)(*ppcBigString)) + stStrLenOld - 1),
4078         stStrLenToAppend + 1,
4079         pcToAppend,
4080         stStrLenToAppend + 1);
4081 
4082 finish:
4083     MOS_FreeMemory(pcToAppend);
4084     return eStatus;
4085 }
4086 
WriteFrame(PMOS_INTERFACE pOsInterface,PVPHAL_SURFACE pSurface,PCCHAR fileName,uint64_t iCounter)4087 void VphalDumperTool::WriteFrame(
4088     PMOS_INTERFACE          pOsInterface,
4089     PVPHAL_SURFACE          pSurface,
4090     PCCHAR                  fileName,
4091     uint64_t                iCounter)
4092 {
4093     uint8_t*                pData;
4094     char                    sPath[MAX_PATH];
4095     char                    sOsPath[MAX_PATH];
4096     uint8_t*                pDst;
4097     uint8_t*                pTmpDst;
4098     uint8_t*                pTmpSrc;
4099     uint32_t                iWidthInBytes;
4100     uint32_t                iHeightInRows;
4101     uint32_t                iBpp;
4102     uint32_t                iSize;
4103     uint32_t                iY;
4104     MOS_LOCK_PARAMS         LockFlags;
4105 
4106     pDst = nullptr;
4107     MOS_ZeroMemory(sPath, MAX_PATH);
4108     MOS_ZeroMemory(sOsPath, MAX_PATH);
4109 
4110     // get bits per pixel for the format
4111     pOsInterface->pfnGetBitsPerPixel(pOsInterface, pSurface->Format, &iBpp);
4112 
4113     VphalDumperTool::GetSurfaceSize(
4114         pSurface,
4115         iBpp,
4116         &iWidthInBytes,
4117         &iHeightInRows);
4118 
4119     iSize = iWidthInBytes * iHeightInRows;
4120 
4121     // Write original image to file
4122     MOS_ZeroMemory(&LockFlags, sizeof(MOS_LOCK_PARAMS));
4123 
4124     LockFlags.ReadOnly = 1;
4125 
4126     pData = (uint8_t*)pOsInterface->pfnLockResource(
4127         pOsInterface,
4128         &pSurface->OsResource,
4129         &LockFlags);
4130     if (pData == nullptr)
4131     {
4132         VPHAL_DEBUG_ASSERTMESSAGE("pData == nullptr.");
4133         return;
4134     }
4135 
4136     MOS_SecureStringPrint(
4137         sPath,
4138         MAX_PATH,
4139         sizeof(sPath),
4140         "c:\\dump\\f[%08I64x]_%s_w[%d]_h[%d]_p[%d].%s",
4141         iCounter,
4142         fileName,
4143         pSurface->dwWidth,
4144         pSurface->dwHeight,
4145         pSurface->dwPitch,
4146         VphalDumperTool::GetFormatStr(pSurface->Format));
4147 
4148     MOS_SecureMemcpy(sOsPath, MAX_PATH, sPath, strlen(sPath));
4149 
4150     // Write the data to file
4151     if (pSurface->dwPitch == iWidthInBytes)
4152     {
4153         MosUtilities::MosWriteFileFromPtr((const char *)sOsPath, pData, iSize);
4154     }
4155     else
4156     {
4157         pDst = (uint8_t*)MOS_AllocAndZeroMemory(iSize);
4158         pTmpSrc = pData;
4159         pTmpDst = pDst;
4160 
4161         for (iY = 0; iY < iHeightInRows; iY++)
4162         {
4163             MOS_SecureMemcpy(pTmpDst, iSize, pTmpSrc, iWidthInBytes);
4164             pTmpSrc += pSurface->dwPitch;
4165             pTmpDst += iWidthInBytes;
4166         }
4167 
4168         MosUtilities::MosWriteFileFromPtr((const char *)sOsPath, pDst, iSize);
4169     }
4170 
4171     if (pDst)
4172     {
4173         MOS_FreeMemory(pDst);
4174     }
4175 
4176     pOsInterface->pfnUnlockResource(
4177         pOsInterface,
4178         &pSurface->OsResource);
4179 }
4180 
GetComponentStr(MOS_COMPONENT component)4181 const char * VphalParameterDumper::GetComponentStr(MOS_COMPONENT component)
4182 {
4183     switch (component)
4184     {
4185     case COMPONENT_UNKNOWN:         return _T("COMPONENT_UNKNOWN");
4186     case COMPONENT_LibVA:           return _T("COMPONENT_LibVA");
4187     case COMPONENT_VPreP:           return _T("COMPONENT_VPreP");
4188     case COMPONENT_EMULATION:       return _T("COMPONENT_EMULATION");
4189     case COMPONENT_CM:              return _T("COMPONENT_CM");
4190     case COMPONENT_Encode:          return _T("COMPONENT_Encode");
4191     case COMPONENT_Decode:          return _T("COMPONENT_Decode");
4192     default:                        return _T("Err");
4193     }
4194 
4195     return nullptr;
4196 }
4197 
GetWholeFormatStr(MOS_FORMAT format)4198 const char * VphalParameterDumper::GetWholeFormatStr(MOS_FORMAT format)
4199 {
4200     switch (format)
4201     {
4202     case Format_Invalid:            return _T("Format_Invalid");
4203     case Format_Source:             return _T("Format_Source");
4204     case Format_420O:               return _T("Format_420O");
4205     case Format_RGB_Swap:           return _T("Format_RGB_Swap");
4206     case Format_RGB_No_Swap:        return _T("Format_RGB_No_Swap");
4207     case Format_RGB:                return _T("Format_RGB");
4208     case Format_RGB32:              return _T("Format_RGB32");
4209     case Format_PA:                 return _T("Format_PA");
4210     case Format_PL2:                return _T("Format_PL2");
4211     case Format_PL2_UnAligned:      return _T("Format_PL2_UnAligned");
4212     case Format_PL3:                return _T("Format_PL3");
4213     case Format_PL3_RGB:            return _T("Format_PL3_RGB");
4214     case Format_PAL:                return _T("Format_PA_T(");
4215 
4216     case Format_None:               return _T("Format_None");
4217     case Format_Any:                return _T("Format_Any");
4218     case Format_A8R8G8B8:           return _T("Format_A8R8G8B8");
4219     case Format_X8R8G8B8:           return _T("Format_X8R8G8B8");
4220     case Format_A8B8G8R8:           return _T("Format_A8B8G8R8");
4221     case Format_X8B8G8R8:           return _T("Format_X8B8G8R8");
4222     case Format_A16B16G16R16:       return _T("Format_A16B16G16R16");
4223     case Format_A16R16G16B16:       return _T("Format_A16R16G16B16");
4224     case Format_R5G6B5:             return _T("Format_R5G6B5");
4225     case Format_R8G8B8:             return _T("Format_R8G8B8");
4226     case Format_R32U:               return _T("Format_R32U");
4227     case Format_R32F:               return _T("Format_R32F");
4228     case Format_RGBP:               return _T("Format_RGBP");
4229     case Format_BGRP:               return _T("Format_BGRP");
4230 
4231     case Format_YUY2:               return _T("Format_YUY2");
4232     case Format_YUYV:               return _T("Format_YUYV");
4233     case Format_YVYU:               return _T("Format_YVYU");
4234     case Format_UYVY:               return _T("Format_UYVY");
4235     case Format_VYUY:               return _T("Format_VYUY");
4236 
4237     case Format_Y416:               return _T("Format_Y416");
4238     case Format_AYUV:               return _T("Format_AYUV");
4239     case Format_AUYV:               return _T("Format_AUYV");
4240     case Format_400P:               return _T("Format_400P");
4241     case Format_NV12:               return _T("Format_NV12");
4242     case Format_NV12_UnAligned:     return _T("Format_NV12_UnAligned");
4243     case Format_NV21:               return _T("Format_NV21");
4244     case Format_NV11:               return _T("Format_NV11");
4245     case Format_NV11_UnAligned:     return _T("Format_NV11_UnAligned");
4246     case Format_P208:               return _T("Format_P208");
4247     case Format_P208_UnAligned:     return _T("Format_P208_UnAligned");
4248     case Format_IMC1:               return _T("Format_IMC1");
4249     case Format_IMC2:               return _T("Format_IMC2");
4250     case Format_IMC3:               return _T("Format_IMC3");
4251     case Format_IMC4:               return _T("Format_IMC4");
4252     case Format_422H:               return _T("Format_422H");
4253     case Format_422V:               return _T("Format_422V");
4254     case Format_444P:               return _T("Format_444P");
4255     case Format_411P:               return _T("Format_411P");
4256     case Format_411R:               return _T("Format_411R");
4257     case Format_I420:               return _T("Format_I420");
4258     case Format_IYUV:               return _T("Format_IYUV");
4259     case Format_YV12:               return _T("Format_YV12");
4260     case Format_YVU9:               return _T("Format_YVU9");
4261     case Format_AI44:               return _T("Format_AI44");
4262     case Format_IA44:               return _T("Format_IA44");
4263     case Format_P8:                 return _T("Format_P8");
4264     case Format_A8P8:               return _T("Format_A8P8");
4265     case Format_A8:                 return _T("Format_A8");
4266     case Format_L8:                 return _T("Format_L8");
4267     case Format_A4L4:               return _T("Format_A4L4");
4268     case Format_A8L8:               return _T("Format_A8L8");
4269     case Format_IRW0:               return _T("Format_IRW0");
4270     case Format_IRW1:               return _T("Format_IRW1");
4271     case Format_IRW2:               return _T("Format_IRW2");
4272     case Format_IRW3:               return _T("Format_IRW3");
4273     case Format_IRW4:               return _T("Format_IRW4");
4274     case Format_IRW5:               return _T("Format_IRW5");
4275     case Format_IRW6:               return _T("Format_IRW6");
4276     case Format_IRW7:               return _T("Format_IRW7");
4277     case Format_STMM:               return _T("Format_STMM");
4278     case Format_Buffer:             return _T("Format_Buffer");
4279     case Format_Buffer_2D:          return _T("Format_Buffer_2D");
4280     case Format_V8U8:               return _T("Format_V8U8");
4281     case Format_R32S:               return _T("Format_R32S");
4282     case Format_R8U:                return _T("Format_R8U");
4283     case Format_R8G8UN:             return _T("Format_R8G8UN");
4284     case Format_R8G8SN:             return _T("Format_R8G8SN");
4285     case Format_G8R8_G8B8:          return _T("Format_G8R8_G8B8");
4286     case Format_R16U:               return _T("Format_R16U");
4287     case Format_R16S:               return _T("Format_R16S");
4288     case Format_R16UN:              return _T("Format_R16UN");
4289     case Format_RAW:                return _T("Format_RAW");
4290     case Format_Y8:                 return _T("Format_Y8");
4291     case Format_Y1:                 return _T("Format_Y1");
4292     case Format_Y16U:               return _T("Format_Y16U");
4293     case Format_Y16S:               return _T("Format_Y16S");
4294     case Format_L16:                return _T("Format_L16");
4295     case Format_D16:                return _T("Format_D16");
4296     case Format_R10G10B10A2:        return _T("Format_R10G10B10A2");
4297     case Format_B10G10R10A2:        return _T("Format_B10G10R10A2");
4298     case Format_P016:               return _T("Format_P016");
4299     case Format_P010:               return _T("Format_P010");
4300     case Format_Y210:               return _T("Format_Y210");
4301     case Format_Y216:               return _T("Fomrat_Y216");
4302     case Format_Y410:               return _T("Format_Y410");
4303     case Format_YV12_Planar:        return _T("Format_YV12_Planar");
4304     case Format_P210:               return _T("Format_P210");
4305     case Format_P216:               return _T("Format_P216");
4306     case Format_Count:              return _T("Format_Count");
4307     default:                        return _T("Err");
4308     }
4309 
4310     return nullptr;
4311 }
4312 
GetTileTypeStr(MOS_TILE_TYPE tile_type)4313 const char * VphalParameterDumper::GetTileTypeStr(MOS_TILE_TYPE tile_type)
4314 {
4315     switch (tile_type)
4316     {
4317     case MOS_TILE_X:            return _T("MOS_TILE_X");
4318     case MOS_TILE_Y:            return _T("MOS_TILE_Y");
4319     case MOS_TILE_LINEAR:       return _T("MOS_TILE_LINEAR");
4320     case MOS_TILE_INVALID:      return _T("MOS_TILE_INVALID");
4321     default:                    return _T("Err");
4322     }
4323 
4324     return nullptr;
4325 }
4326 
GetSurfaceTypeStr(VPHAL_SURFACE_TYPE surface_type)4327 const char * VphalParameterDumper::GetSurfaceTypeStr(VPHAL_SURFACE_TYPE surface_type)
4328 {
4329     switch (surface_type)
4330     {
4331     case SURF_NONE:             return _T("SURF_NONE");
4332     case SURF_IN_BACKGROUND:    return _T("SURF_IN_BACKGROUND");
4333     case SURF_IN_PRIMARY:       return _T("SURF_IN_PRIMARY");
4334     case SURF_IN_SUBSTREAM:     return _T("SURF_IN_SUBSTREAM");
4335     case SURF_IN_REFERENCE:     return _T("SURF_IN_REFERENCE");
4336     case SURF_OUT_RENDERTARGET: return _T("SURF_OUT_RENDERTARGET");
4337     case SURF_TYPE_COUNT:       return _T("SURF_TYPE_COUNT");
4338     default: return _T("Err");
4339     }
4340 
4341     return nullptr;
4342 }
4343 
GetSampleTypeStr(VPHAL_SAMPLE_TYPE sample_type)4344 const char * VphalParameterDumper::GetSampleTypeStr(VPHAL_SAMPLE_TYPE sample_type)
4345 {
4346     switch (sample_type)
4347     {
4348     case SAMPLE_PROGRESSIVE:                                 return _T("SAMPLE_PROGRESSIVE");
4349     case SAMPLE_SINGLE_TOP_FIELD:                            return _T("SAMPLE_SINGLE_TOP_FIELD");
4350     case SAMPLE_SINGLE_BOTTOM_FIELD:                         return _T("SAMPLE_SINGLE_BOTTOM_FIELD");
4351     case SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD:            return _T("SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD");
4352     case SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD:         return _T("SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD");
4353     case SAMPLE_INTERLEAVED_ODD_FIRST_TOP_FIELD:             return _T("SAMPLE_INTERLEAVED_ODD_FIRST_TOP_FIELD");
4354     case SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD:          return _T("SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD");
4355     case SAMPLE_INVALID:                                     return _T("SAMPLE_INVALID");
4356     default:                                                 return _T("Err");
4357     }
4358 
4359     return nullptr;
4360 }
4361 
GetColorSpaceStr(VPHAL_CSPACE color_space)4362 const char * VphalParameterDumper::GetColorSpaceStr(VPHAL_CSPACE color_space)
4363 {
4364     switch (color_space)
4365     {
4366     case CSpace_None:                      return _T("CSpace_None");
4367     case CSpace_Source:                    return _T("CSpace_Source");
4368     case CSpace_RGB:                       return _T("CSpace_RGB");
4369     case CSpace_YUV:                       return _T("CSpace_YUV");
4370     case CSpace_Gray:                      return _T("CSpace_Gray");
4371     case CSpace_Any:                       return _T("CSpace_Any");
4372     case CSpace_sRGB:                      return _T("CSpace_sRGB");
4373     case CSpace_stRGB:                     return _T("CSpace_stRGB");
4374     case CSpace_BT601:                     return _T("CSpace_BT601");
4375     case CSpace_BT601_FullRange:           return _T("CSpace_BT601_FullRange");
4376     case CSpace_BT709:                     return _T("CSpace_BT709");
4377     case CSpace_BT709_FullRange:           return _T("CSpace_BT709_FullRange");
4378     case CSpace_xvYCC601:                  return _T("CSpace_xvYCC601");
4379     case CSpace_xvYCC709:                  return _T("CSpace_xvYCC709");
4380     case CSpace_BT601Gray:                 return _T("CSpace_BT601Gray");
4381     case CSpace_BT601Gray_FullRange:       return _T("CSpace_BT601Gray_FullRange");
4382     case CSpace_BT2020:                    return _T("CSpace_BT2020");
4383     case CSpace_BT2020_FullRange:          return _T("CSpace_BT2020_FullRange");
4384     case CSpace_BT2020_RGB:                return _T("CSpace_BT2020_RGB");
4385     case CSpace_BT2020_stRGB:              return _T("CSpace_BT2020_stRGB");
4386     case CSpace_Count:                     return _T("CSpace_Count");
4387     default:                               return _T("Err");
4388     }
4389 
4390     return nullptr;
4391 }
4392 
GetBlendTypeStr(VPHAL_BLEND_TYPE blend_type)4393 const char * VphalParameterDumper::GetBlendTypeStr(VPHAL_BLEND_TYPE blend_type)
4394 {
4395     switch (blend_type)
4396     {
4397     case BLEND_NONE:               return _T("BLEND_NONE");
4398     case BLEND_SOURCE:             return _T("BLEND_SOURCE");
4399     case BLEND_PARTIAL:            return _T("BLEND_PARTIAL");
4400     case BLEND_CONSTANT:           return _T("BLEND_CONSTANT");
4401     case BLEND_CONSTANT_SOURCE:    return _T("BLEND_CONSTANT_SOURCE");
4402     case BLEND_CONSTANT_PARTIAL:   return _T("BLEND_CONSTANT_PARTIAL");
4403     default:                       return _T("Err");
4404     }
4405 
4406     return nullptr;
4407 }
4408 
GetPaletteTypeStr(VPHAL_PALETTE_TYPE palette_type)4409 const char * VphalParameterDumper::GetPaletteTypeStr(VPHAL_PALETTE_TYPE palette_type)
4410 {
4411     switch (palette_type)
4412     {
4413     case VPHAL_PALETTE_NONE:          return _T("VPHAL_PALETTE_NONE");
4414     case VPHAL_PALETTE_YCbCr_8:       return _T("VPHAL_PALETTE_YCbCr_8");
4415     case VPHAL_PALETTE_ARGB_8:        return _T("VPHAL_PALETTE_ARGB_8");
4416     case VPHAL_PALETTE_AVYU_8:        return _T("VPHAL_PALETTE_AVYU_8");
4417     default:                          return _T("Err");
4418     }
4419 
4420     return nullptr;
4421 }
4422 
GetScalingModeStr(VPHAL_SCALING_MODE scaling_mode)4423 const char * VphalParameterDumper::GetScalingModeStr(VPHAL_SCALING_MODE scaling_mode)
4424 {
4425     switch (scaling_mode)
4426     {
4427     case VPHAL_SCALING_NEAREST:         return _T("VPHAL_SCALING_NEAREST");
4428     case VPHAL_SCALING_BILINEAR:        return _T("VPHAL_SCALING_BILINEAR");
4429     case VPHAL_SCALING_AVS:             return _T("VPHAL_SCALING_AVS");
4430     case VPHAL_SCALING_ADV_QUALITY:     return _T("VPHAL_SCALING_ADV_QUALITY");
4431     default:                            return _T("Err");
4432     }
4433 
4434     return nullptr;
4435 }
4436 
GetRotationModeStr(VPHAL_ROTATION rotation_mode)4437 const char * VphalParameterDumper::GetRotationModeStr(VPHAL_ROTATION rotation_mode)
4438 {
4439     switch (rotation_mode)
4440     {
4441     case VPHAL_ROTATION_IDENTITY:               return _T("VPHAL_ROTATION_IDENTITY");
4442     case VPHAL_ROTATION_90:                     return _T("VPHAL_ROTATION_90");
4443     case VPHAL_ROTATION_180:                    return _T("VPHAL_ROTATION_180");
4444     case VPHAL_ROTATION_270:                    return _T("VPHAL_ROTATION_270");
4445     case VPHAL_MIRROR_HORIZONTAL:               return _T("VPHAL_MIRROR_HORIZONTAL");
4446     case VPHAL_MIRROR_VERTICAL:                 return _T("VPHAL_MIRROR_VERTICAL");
4447     case VPHAL_ROTATE_90_MIRROR_VERTICAL:       return _T("VPHAL_ROTATE_90_MIRROR_VERTICAL");
4448     case VPHAL_ROTATE_90_MIRROR_HORIZONTAL:     return _T("VPHAL_ROTATE_90_MIRROR_HORIZONTAL");
4449 
4450     default:                                    return _T("Err");
4451     }
4452 
4453     return nullptr;
4454 }
4455 
GetDIModeStr(VPHAL_DI_MODE di_mode)4456 const char * VphalParameterDumper::GetDIModeStr(VPHAL_DI_MODE di_mode)
4457 {
4458     switch (di_mode)
4459     {
4460     case DI_MODE_BOB:         return _T("DI_MODE_BOB");
4461     case DI_MODE_ADI:         return _T("DI_MODE_ADI");
4462     default:                  return _T("Err");
4463     }
4464 
4465     return nullptr;
4466 }
4467 
GetDenoiseModeStr(VPHAL_NOISELEVEL noise_level)4468 const char * VphalParameterDumper::GetDenoiseModeStr(VPHAL_NOISELEVEL noise_level)
4469 {
4470     switch (noise_level)
4471     {
4472     case NOISELEVEL_DEFAULT:         return _T("NOISELEVEL_DEFAULT");
4473     case NOISELEVEL_VC1_HD:          return _T("NOISELEVEL_VC1_HD");
4474     default:                         return _T("Err");
4475     }
4476 
4477     return nullptr;
4478 }
4479 
GetHVSDenoiseModeStr(VPHAL_HVSDN_MODE hvs_dn_mode)4480 const char *VphalParameterDumper::GetHVSDenoiseModeStr(VPHAL_HVSDN_MODE hvs_dn_mode)
4481 {
4482     switch (hvs_dn_mode)
4483     {
4484     case HVSDENOISE_AUTO_BDRATE:     return _T("HVSDENOISE_AUTO_BDRATE");
4485     case HVSDENOISE_AUTO_SUBJECTIVE: return _T("HVSDENOISE_AUTO_SUBJECTIVE");
4486     case HVSDENOISE_MANUAL:          return _T("HVSDENOISE_MANUAL");
4487     default:                         return _T("Err");
4488     }
4489 
4490     return nullptr;
4491 }
4492 
GetDumpSpecLocation()4493 char *VphalParameterDumper::GetDumpSpecLocation()
4494 {
4495     return m_dumpSpec.outFileLocation;
4496 }
GetDumpSpecSkuWaDumpEnable()4497 bool VphalParameterDumper::GetDumpSpecSkuWaDumpEnable()
4498 {
4499     return m_dumpSpec.enableSkuWaDump;
4500 }
4501 
4502 #endif // (_DEBUG || _RELEASE_INTERNAL)