xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/Xe_M/Xe_XPM/vp/hal/vphal_debug_xe_xpm.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*===================== begin_copyright_notice ==================================
2 
3 # Copyright (c) 2020-2021, Intel Corporation
4 
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 # OTHER DEALINGS IN THE SOFTWARE.
22 
23 ======================= end_copyright_notice ==================================*/
24 //!
25 //! \file     vphal_debug_xe_xpm.c
26 //! \details  This file contains the Implementation of extention functions for
27 //!           surface dumper, hw state dumper, perf counter dumper, and render
28 //!           parameter dumper
29 //!
30 #include "vphal_debug_xe_xpm.h"
31 #include "vp_hal_ddi_utils.h"
32 
33 #if (_DEBUG || _RELEASE_INTERNAL)
34 
35 //==<Dump Surface>==============================================================
36 
VphalSurfaceDumperXe_Xpm(PMOS_INTERFACE pOsInterface)37 VphalSurfaceDumperXe_Xpm::VphalSurfaceDumperXe_Xpm(PMOS_INTERFACE pOsInterface):
38     VphalSurfaceDumper(pOsInterface)
39 {
40 #if !EMUL
41     pBltState = MOS_New(BltStateXe_Xpm, m_osInterface);
42     if (pBltState && pBltState->m_mhwInterfaces == nullptr)
43     {
44         VPHAL_DEBUG_ASSERTMESSAGE("MhwInterfaces create factory failed!");
45         MOS_Delete(pBltState);
46         pBltState = nullptr;
47     }
48 #endif
49 }
50 
~VphalSurfaceDumperXe_Xpm()51 VphalSurfaceDumperXe_Xpm::~VphalSurfaceDumperXe_Xpm()
52 {
53 #if !EMUL
54     if (pBltState)
55     {
56         MOS_Delete(pBltState);
57         pBltState = nullptr;
58     }
59 #endif
60 }
61 
GetBltState()62 BltStateXe_Xpm *VphalSurfaceDumperXe_Xpm::GetBltState()
63 {
64     return pBltState;
65 }
66 
DumpSurfaceToFile(PMOS_INTERFACE pOsInterface,PVPHAL_SURFACE pSurface,const char * psPathPrefix,uint64_t iCounter,bool bLockSurface,bool bNoDecompWhenLock,uint8_t * pData)67 MOS_STATUS VphalSurfaceDumperXe_Xpm::DumpSurfaceToFile(
68     PMOS_INTERFACE          pOsInterface,
69     PVPHAL_SURFACE          pSurface,
70     const char*             psPathPrefix,
71     uint64_t                iCounter,
72     bool                    bLockSurface,
73     bool                    bNoDecompWhenLock,
74     uint8_t*                pData)
75 {
76 #if !EMUL
77     if (MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrFlatPhysCCS) && m_dumpSpec.enableAuxDump)
78     {
79         return DumpCompressedSurface(
80             m_osInterface,
81             pSurface,
82             m_dumpPrefix,
83             iCounter,
84             true);
85     }
86     else
87 #endif
88     {
89         return VphalSurfaceDumper::DumpSurfaceToFile(
90             m_osInterface,
91             pSurface,
92             m_dumpPrefix,
93             iCounter,
94             true,
95             bNoDecompWhenLock,
96             pData);
97     }
98 }
99 
100 #if !EMUL
DumpCompressedSurface(PMOS_INTERFACE pOsInterface,PVPHAL_SURFACE pSurface,const char * psPathPrefix,uint64_t iCounter,bool bLockSurface)101 MOS_STATUS VphalSurfaceDumperXe_Xpm::DumpCompressedSurface(
102     PMOS_INTERFACE pOsInterface,
103     PVPHAL_SURFACE pSurface,
104     const char *   psPathPrefix,
105     uint64_t       iCounter,
106     bool           bLockSurface)
107 {
108     MOS_STATUS eStatus;
109     char       sPath[MAX_PATH], sOsPath[MAX_PATH];
110 
111     VPHAL_DEBUG_ASSERT(pSurface);
112     VPHAL_DEBUG_ASSERT(pOsInterface);
113     VPHAL_DEBUG_ASSERT(psPathPrefix);
114 
115     eStatus = MOS_STATUS_SUCCESS;
116     MOS_ZeroMemory(sPath, MAX_PATH);
117     MOS_ZeroMemory(sOsPath, MAX_PATH);
118 
119     MOS_SURFACE surface = VpHalDDIUtils::ConvertVphalSurfaceToMosSurface(pSurface);
120     VPHAL_DEBUG_CHK_STATUS(pBltState->LockSurface(&surface));
121 
122     // dump main surface
123     MOS_SecureStringPrint(
124         sPath,
125         MAX_PATH,
126         sizeof(sPath),
127         "%s_f[%03lld]_w[%d]_h[%d]_p[%d].%s",
128         psPathPrefix,
129         iCounter,
130         pSurface->dwWidth,
131         pSurface->dwHeight,
132         pSurface->dwPitch,
133         VphalDumperTool::GetFormatStr(pSurface->Format));
134     VphalDumperTool::GetOsFilePath(sPath, sOsPath);
135     VPHAL_DEBUG_CHK_NULL(pBltState->GetMainSurfaceData())
136     VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(sOsPath, pBltState->GetMainSurfaceData(), pBltState->GetMainSurfaceSize()));
137 
138     MOS_ZeroMemory(sPath, MAX_PATH);
139     MOS_ZeroMemory(sOsPath, MAX_PATH);
140     // dump aux
141     MOS_SecureStringPrint(
142         sPath,
143         MAX_PATH,
144         sizeof(sPath),
145         "%s_f[%03lld]_w[%d]_h[%d]_p[%d].aux",
146         psPathPrefix,
147         iCounter,
148         pBltState->GetAuxSize(),
149         1,
150         pBltState->GetAuxSize());
151     VphalDumperTool::GetOsFilePath(sPath, sOsPath);
152     VPHAL_DEBUG_CHK_NULL(pBltState->GetAuxData());
153     VPHAL_DEBUG_CHK_STATUS(MosUtilities::MosWriteFileFromPtr(sOsPath, pBltState->GetAuxData(), pBltState->GetAuxSize()));
154 
155 finish:
156     pBltState->UnLockSurface();
157     return eStatus;
158 }
159 #endif
160 #endif // (_DEBUG || _RELEASE_INTERNAL)
161