1 /*
2 * Copyright (c) 2020-2021, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     vp_debug_interface.cpp
24 //! \brief    Defines the debug interface shared by vp only.
25 //! \details  The debug interface dumps output from Media based on in input config file.
26 //!
27 
28 #include "vp_debug_interface.h"
29 #if USE_VP_DEBUG_TOOL
30 #include "vp_debug_config_manager.h"
31 
VpDebugInterface()32 VpDebugInterface::VpDebugInterface()
33 {
34     memset(m_fileName, 0, sizeof(m_fileName));
35     memset(m_path, 0, sizeof(m_path));
36 }
37 
~VpDebugInterface()38 VpDebugInterface::~VpDebugInterface()
39 {
40     // Destroy surface dumper
41     VP_SURF_DUMP_DESTORY(m_surfaceDumper);
42     // Destroy vphal parameter dump
43     VP_PARAMETERS_DUMPPER_DESTORY(m_parameterDumper);
44 
45     if (nullptr != m_configMgr)
46     {
47         MOS_Delete(m_configMgr);
48     }
49 }
50 
Initialize(PMOS_INTERFACE pOsInterface)51 MOS_STATUS VpDebugInterface::Initialize(PMOS_INTERFACE pOsInterface)
52 {
53     VP_FUNC_CALL();
54 
55     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
56     VP_DEBUG_FUNCTION_ENTER;
57 
58     VP_DEBUG_CHK_NULL_RETURN(pOsInterface);
59     m_osInterface = pOsInterface;
60 
61     m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
62     //dump loctaion is vpdump
63     MediaDebugInterface::SetOutputFilePath();
64 
65     m_configMgr = MOS_New(VpDebugConfigMgr, this, m_outputFilePath);
66     VP_DEBUG_CHK_NULL_RETURN(m_configMgr);
67     m_configMgr->ParseConfig(m_osInterface->pOsContext);
68 
69     MediaDebugInterface::InitDumpLocation();
70 
71     // Initialize Surface Dumper
72     VP_SURF_DUMP_CREATE(m_surfaceDumper);
73     VP_DEBUG_CHK_NULL_RETURN(m_surfaceDumper);
74     // Initialize Parameter Dumper
75     VP_PARAMETERS_DUMPPER_CREATE(m_parameterDumper);
76     VP_DEBUG_CHK_NULL_RETURN(m_parameterDumper);
77 
78     return eStatus;
79 }
80 
DumpToXML(PVPHAL_RENDER_PARAMS pRenderParams,uint32_t framecounter)81 void VpDebugInterface::DumpToXML(PVPHAL_RENDER_PARAMS pRenderParams, uint32_t framecounter)
82 {
83     VP_FUNC_CALL();
84 
85     if (m_surfaceDumper && m_parameterDumper)
86     {
87         m_parameterDumper->DumpToXML(
88             framecounter,
89             m_surfaceDumper->m_dumpSpec.pcOutputPath,
90             pRenderParams);
91     }
92 }
93 
SkuWa_DumpToXML(MEDIA_FEATURE_TABLE * skuTable,MEDIA_WA_TABLE * waTable)94 void VpDebugInterface::SkuWa_DumpToXML(MEDIA_FEATURE_TABLE *skuTable, MEDIA_WA_TABLE *waTable)
95 {
96     VP_FUNC_CALL();
97 
98     if (m_parameterDumper)
99     {
100         m_parameterDumper->SkuWa_DumpToXML(
101             skuTable,
102             waTable);
103     }
104 }
105 
DumpVpSurface(PVPHAL_SURFACE pSurf,uint32_t uiFrameNumber,uint32_t uiCounter,uint32_t Location,uint32_t uiDDI)106 MOS_STATUS VpDebugInterface::DumpVpSurface(
107     PVPHAL_SURFACE pSurf,
108     uint32_t       uiFrameNumber,
109     uint32_t       uiCounter,
110     uint32_t       Location,
111     uint32_t       uiDDI)
112 {
113     VP_FUNC_CALL();
114 
115     VP_DEBUG_CHK_NULL_RETURN(m_surfaceDumper)
116     return m_surfaceDumper->DumpSurface(
117         pSurf,
118         uiFrameNumber,
119         uiCounter,
120         Location,
121         uiDDI);
122 }
123 
DumpVpSurface(PVP_SURFACE pSurf,uint32_t uiFrameNumber,uint32_t uiCounter,uint32_t Location,uint32_t uiDDI)124 MOS_STATUS VpDebugInterface::DumpVpSurface(
125     PVP_SURFACE    pSurf,
126     uint32_t       uiFrameNumber,
127     uint32_t       uiCounter,
128     uint32_t       Location,
129     uint32_t       uiDDI)
130 {
131     VP_FUNC_CALL();
132 
133     VP_DEBUG_CHK_NULL_RETURN(m_surfaceDumper)
134     return m_surfaceDumper->DumpSurface(
135         pSurf,
136         uiFrameNumber,
137         uiCounter,
138         Location,
139         uiDDI);
140 }
141 
DumpVpSurfaceArray(PVPHAL_SURFACE * ppSurfaces,uint32_t uiMaxSurfaces,uint32_t uiNumSurfaces,uint32_t uiFrameNumber,uint32_t Location,uint32_t uiDDI)142 MOS_STATUS VpDebugInterface::DumpVpSurfaceArray(
143     PVPHAL_SURFACE                  *ppSurfaces,
144     uint32_t                        uiMaxSurfaces,
145     uint32_t                        uiNumSurfaces,
146     uint32_t                        uiFrameNumber,
147     uint32_t                        Location,
148     uint32_t                        uiDDI)
149 {
150     VP_FUNC_CALL();
151 
152     VP_DEBUG_CHK_NULL_RETURN(m_surfaceDumper)
153     return m_surfaceDumper->DumpSurfaceArray(
154         ppSurfaces,
155         uiMaxSurfaces,
156         uiNumSurfaces,
157         uiFrameNumber,
158         Location,
159         uiDDI);
160 }
161 
SetOutputPathKey()162 std::string VpDebugInterface::SetOutputPathKey()
163 {
164     VP_FUNC_CALL();
165 
166     return __VPHAL_DBG_SURF_DUMP_OUTFILE_KEY_NAME;
167 }
168 
InitDefaultOutput()169 std::string VpDebugInterface::InitDefaultOutput()
170 {
171     VP_FUNC_CALL();
172 
173     m_outputFilePath.append(MEDIA_DEBUG_VPHAL_DUMP_OUTPUT_FOLDER);
174     return SetOutputPathKey();
175 }
176 
177 #endif  // USE_VP_DEBUG_INTERFACE
178 
179