xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/vp/hal/utils/vp_debug.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 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     vp_debug.cpp
24 //! \brief    Implementation of functions for debugging VPHAL
25 //! \details  This file contains the Implementation of functions for
26 //!           surface dumper, hw state dumper, perf counter dumper, and render
27 //!           parameter dumper
28 //!
29 #include "vp_debug.h"
30 
31 // Max number of source info to be dumped into OCA.
32 #define MAX_NUMBER_OF_SOURCE_INFO_IN_OCA_BUFFER 8
33 // Max number of target info to be dumped into OCA.
34 #define MAX_NUMBER_OF_TARGET_INFO_IN_OCA_BUFFER 4
35 
VphalOcaDumper()36 VphalOcaDumper::VphalOcaDumper()
37 {
38 }
39 
~VphalOcaDumper()40 VphalOcaDumper::~VphalOcaDumper()
41 {
42     MOS_DeleteArray(m_pOcaRenderParam);
43 }
44 
Delete(void * & p)45 void VphalOcaDumper::Delete(void *&p)
46 {
47     VphalOcaDumper *pOcaDumpter =  (VphalOcaDumper *)p;
48     MOS_Delete(pOcaDumpter);
49     p = nullptr;
50 }
51 
SetRenderParam(VPHAL_RENDER_PARAMS * pRenderParams)52 void VphalOcaDumper::SetRenderParam(VPHAL_RENDER_PARAMS *pRenderParams)
53 {
54     if (nullptr == pRenderParams)
55     {
56         return;
57     }
58 
59     uint32_t uSrcCountDumped = MOS_MIN(pRenderParams->uSrcCount, MAX_NUMBER_OF_SOURCE_INFO_IN_OCA_BUFFER);
60     uint32_t uDstCountDumped = MOS_MIN(pRenderParams->uDstCount, MAX_NUMBER_OF_TARGET_INFO_IN_OCA_BUFFER);
61 
62     uint32_t size = sizeof(VPHAL_OCA_RENDER_PARAM) + uSrcCountDumped * sizeof(VPHAL_OCA_SOURCE_INFO) +
63         uDstCountDumped * sizeof(VPHAL_OCA_TARGET_INFO);
64     uint32_t allocSize = size;
65 
66     if (m_pOcaRenderParam)
67     {
68         if (allocSize > m_pOcaRenderParam->Header.allocSize)
69         {
70             MOS_DeleteArray(m_pOcaRenderParam);
71         }
72         else
73         {
74             // Reuse previous buffer.
75             allocSize = m_pOcaRenderParam->Header.allocSize;
76         }
77     }
78 
79     if (nullptr == m_pOcaRenderParam)
80     {
81         m_pOcaRenderParam = (VPHAL_OCA_RENDER_PARAM *)MOS_NewArray(char, allocSize);
82         if (nullptr == m_pOcaRenderParam)
83         {
84             return;
85         }
86     }
87     MOS_ZeroMemory(m_pOcaRenderParam, size);
88 
89     m_pOcaRenderParam->Header.size          = size;
90     m_pOcaRenderParam->Header.allocSize     = allocSize;
91     m_pOcaRenderParam->Component            = pRenderParams->Component;
92 
93     if (pRenderParams->uSrcCount > 0 && pRenderParams->pSrc[0])
94     {
95         m_pOcaRenderParam->FrameID = pRenderParams->pSrc[0]->FrameID;
96     }
97 
98     m_pOcaRenderParam->Pid = MosUtilities::MosGetPid();
99 
100     m_pOcaRenderParam->uSrcCount = pRenderParams->uSrcCount;
101     m_pOcaRenderParam->uDstCount = pRenderParams->uDstCount;
102     m_pOcaRenderParam->uSrcCountDumped = uSrcCountDumped;
103     m_pOcaRenderParam->uDstCountDumped = uDstCountDumped;
104 
105     if (pRenderParams->pColorFillParams)
106     {
107         m_pOcaRenderParam->ColorFillParams.params = *pRenderParams->pColorFillParams;
108         m_pOcaRenderParam->ColorFillParams.bValid = true;
109     }
110 
111     uint32_t offset = sizeof(VPHAL_OCA_RENDER_PARAM);
112     VPHAL_OCA_SOURCE_INFO *pSource = uSrcCountDumped > 0 ? (VPHAL_OCA_SOURCE_INFO *)((char*)m_pOcaRenderParam + offset) : nullptr;
113     offset += uSrcCountDumped * sizeof(VPHAL_OCA_SOURCE_INFO);
114     VPHAL_OCA_TARGET_INFO *pTarget = uDstCountDumped > 0 ? (VPHAL_OCA_TARGET_INFO *)((char*)m_pOcaRenderParam + offset) : nullptr;
115 
116     if (pSource)
117     {
118         for (uint32_t i = 0; i < uSrcCountDumped; ++i)
119         {
120             if (pRenderParams->pSrc[i])
121             {
122                 InitSourceInfo(pSource[i], *(VPHAL_SURFACE *)pRenderParams->pSrc[i]);
123             }
124         }
125     }
126 
127     if (pTarget)
128     {
129         for (uint32_t i = 0; i < uDstCountDumped; ++i)
130         {
131             if (pRenderParams->pTarget[i])
132             {
133                 InitTargetInfo(pTarget[i], *(VPHAL_SURFACE *)pRenderParams->pTarget[i]);
134             }
135         }
136     }
137 }
138 
InitSurfInfo(VPHAL_OCA_SURFACE_INFO & surfInfo,VPHAL_SURFACE & surf)139 void VphalOcaDumper::InitSurfInfo(VPHAL_OCA_SURFACE_INFO &surfInfo, VPHAL_SURFACE &surf)
140 {
141     surfInfo.Format        = surf.Format;
142     surfInfo.SurfType      = surf.SurfType;
143     surfInfo.SampleType    = surf.SampleType;
144     surfInfo.ColorSpace    = surf.ColorSpace;
145     surfInfo.ScalingMode   = surf.ScalingMode;
146     surfInfo.TileType      = surf.TileType;
147     surfInfo.dwWidth       = surf.dwWidth;
148     surfInfo.dwHeight      = surf.dwHeight;
149     surfInfo.dwPitch       = surf.dwPitch;
150     surfInfo.rcSrc         = surf.rcSrc;
151     surfInfo.rcDst         = surf.rcDst;
152 }
153 
InitSourceInfo(VPHAL_OCA_SOURCE_INFO & sourceInfo,VPHAL_SURFACE & source)154 void VphalOcaDumper::InitSourceInfo(VPHAL_OCA_SOURCE_INFO &sourceInfo, VPHAL_SURFACE &source)
155 {
156     InitSurfInfo(sourceInfo.surfInfo, source);
157     sourceInfo.Rotation         = source.Rotation;
158     sourceInfo.iPalette         = source.iPalette;
159     sourceInfo.PaletteParams    = source.Palette;
160 
161     if (source.pBlendingParams)
162     {
163         sourceInfo.BlendingParams.params = *source.pBlendingParams;
164         sourceInfo.BlendingParams.bValid = true;
165     }
166 
167     if (source.pLumaKeyParams)
168     {
169         sourceInfo.LumaKeyParams.params = *source.pLumaKeyParams;
170         sourceInfo.LumaKeyParams.bValid = true;
171     }
172 
173     if (source.pProcampParams)
174     {
175         sourceInfo.ProcampParams.params = *source.pProcampParams;
176         sourceInfo.ProcampParams.bValid = true;
177     }
178 
179     if (source.pIEFParams)
180     {
181         sourceInfo.IEFParams.params = *source.pIEFParams;
182         sourceInfo.IEFParams.bValid = true;
183     }
184 
185     if (source.pDeinterlaceParams)
186     {
187         sourceInfo.DIParams.params = *source.pDeinterlaceParams;
188         sourceInfo.DIParams.bValid = true;
189     }
190 
191     if (source.pDenoiseParams)
192     {
193         sourceInfo.DNParams.params = *source.pDenoiseParams;
194         sourceInfo.DNParams.bValid = true;
195     }
196 
197     if (source.pColorPipeParams)
198     {
199         sourceInfo.ColorPipeParams.params = *source.pColorPipeParams;
200         sourceInfo.ColorPipeParams.bValid = true;
201     }
202 
203     if (source.uBwdRefCount > 0)
204     {
205         sourceInfo.BwdRefInfo.uBwdRefCount  = source.uBwdRefCount;
206         sourceInfo.BwdRefInfo.bValid        = true;
207     }
208 
209     if (source.uFwdRefCount > 0)
210     {
211         sourceInfo.FwdRefInfo.uFwdRefCount  = source.uFwdRefCount;
212         sourceInfo.FwdRefInfo.bValid        = true;
213     }
214 
215     if (source.pHDRParams)
216     {
217         sourceInfo.HDRParams.params = *source.pHDRParams;
218         sourceInfo.HDRParams.bValid = true;
219     }
220 }
221 
InitTargetInfo(VPHAL_OCA_TARGET_INFO & targetInfo,VPHAL_SURFACE & target)222 void VphalOcaDumper::InitTargetInfo(VPHAL_OCA_TARGET_INFO &targetInfo, VPHAL_SURFACE &target)
223 {
224     InitSurfInfo(targetInfo.surfInfo, target);
225 
226     if (target.pHDRParams)
227     {
228         targetInfo.HDRParams.params = *target.pHDRParams;
229         targetInfo.HDRParams.bValid = true;
230     }
231 }
232