Debian Codegraph @

media_softlet/agnostic/common/vp/hal/pipeline/vp_pipeline_adapter_base.cpp

raw
1 /*
2 * Copyright (c) 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_pipeline_adapter_base.cpp
24 //! \brief vp pipeline adapter base clarification
25 //! \details vp pipeline adapter base clarification inlcuding:
26 //! some marcro, enum, structure, function
27 //!
28 #include "vp_pipeline_adapter_base.h"
29 #include "media_interfaces_vphal.h"
30 #include "vp_platform_interface.h"
31 #include "vp_debug.h"
32 #include "vp_user_setting.h"
33 #include "renderhal_platform_interface.h"
34 #include "vp_user_feature_control.h"
35
36 VpPipelineAdapterBase::VpPipelineAdapterBase(
37 vp::VpPlatformInterface &vpPlatformInterface,
38 MOS_STATUS &eStatus,
39 bool clearViewMode) :
40 m_vpPlatformInterface(vpPlatformInterface)
41 {
42 m_osInterface = m_vpPlatformInterface.GetOsInterface();
43 if (m_osInterface)
44 {
45 m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
46 }
47 VpUserSetting::InitVpUserSetting(m_userSettingPtr, clearViewMode);
48
49 eStatus = MOS_STATUS_SUCCESS;
50 }
51
52 MOS_STATUS VpPipelineAdapterBase::GetVpMhwInterface(
53 VP_MHWINTERFACE &vpMhwinterface)
54 {
55 VP_FUNC_CALL();
56
57 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
58 bool sfcNeeded = false;
59 bool veboxNeeded = false;
60 std::shared_ptr<mhw::vebox::Itf> veboxItf = nullptr;
61 std::shared_ptr<mhw::sfc::Itf> sfcItf = nullptr;
62 std::shared_ptr<mhw::mi::Itf> miItf = nullptr;
63 m_osInterface = m_vpPlatformInterface.GetOsInterface();
64 if (m_osInterface == nullptr)
65 {
66 eStatus = MOS_STATUS_NULL_POINTER;
67 return eStatus;
68 }
69
70 // Initialize platform, sku, wa tables
71 m_osInterface->pfnGetPlatform(m_osInterface, &m_platform);
72 m_skuTable = m_osInterface->pfnGetSkuTable(m_osInterface);
73 m_waTable = m_osInterface->pfnGetWaTable(m_osInterface);
74
75 m_vprenderHal = (PRENDERHAL_INTERFACE)MOS_AllocAndZeroMemory(sizeof(*m_vprenderHal));
76 if (m_vprenderHal == nullptr)
77 {
78 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NULL_POINTER);
79 }
80
81 eStatus = RenderHal_InitInterface(
82 m_vprenderHal,
83 &m_cpInterface,
84 m_osInterface);
85
86 VPHAL_DBG_OCA_DUMPER_CREATE(m_vprenderHal);
87
88 if (MOS_FAILED(eStatus))
89 {
90 MOS_OS_ASSERTMESSAGE("VpPipelineAdapterBase construct failed due to base class returned failure: eStatus = %d.", eStatus);
91 return eStatus;
92 }
93
94 veboxNeeded = MEDIA_IS_SKU(m_skuTable, FtrVERing);
95 sfcNeeded = MEDIA_IS_SKU(m_skuTable, FtrSFCPipe);
96 SetMhwMiItf(m_vprenderHal->pRenderHalPltInterface->GetMhwMiItf());
97 if ((veboxNeeded || sfcNeeded) && !m_clearVideoViewMode)
98 {
99 eStatus = VphalDevice::CreateVPMhwInterfaces(sfcNeeded, veboxNeeded, veboxItf, sfcItf, miItf, m_osInterface);
100 if (eStatus == MOS_STATUS_SUCCESS)
101 {
102 SetMhwVeboxItf(veboxItf);
103 SetMhwSfcItf(sfcItf);
104 }
105 else
106 {
107 VP_PUBLIC_ASSERTMESSAGE("Allocate MhwInterfaces failed");
108 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NO_SPACE);
109 }
110 }
111
112 vpMhwinterface.m_platform = m_platform;
113 vpMhwinterface.m_waTable = m_waTable;
114 vpMhwinterface.m_skuTable = m_skuTable;
115 vpMhwinterface.m_osInterface = m_osInterface;
116 vpMhwinterface.m_renderHal = m_vprenderHal;
117 vpMhwinterface.m_cpInterface = m_cpInterface;
118 vpMhwinterface.m_statusTable = &m_statusTable;
119 m_vpPlatformInterface.SetMhwSfcItf(m_sfcItf);
120 m_vpPlatformInterface.SetMhwVeboxItf(m_veboxItf);
121 m_vpPlatformInterface.SetMhwMiItf(m_miItf);
122 vpMhwinterface.m_vpPlatformInterface = &m_vpPlatformInterface;
123
124 return eStatus;
125 }
126
127 VpPipelineAdapterBase::~VpPipelineAdapterBase()
128 {
129 MOS_STATUS eStatus;
130
131 // Wait for all cmd before destroy gpu resource
132 if (m_osInterface && m_osInterface->pfnWaitAllCmdCompletion && m_osInterface->bDeallocateOnExit)
133 {
134 VP_PUBLIC_NORMALMESSAGE("WaitAllCmdCompletion in VpPipelineAdapterBase::~VpPipelineAdapterBase");
135 m_osInterface->pfnWaitAllCmdCompletion(m_osInterface);
136 }
137
138 if (m_vprenderHal)
139 {
140 VPHAL_DBG_OCA_DUMPER_DESTORY(m_vprenderHal);
141 if (m_vprenderHal->pfnDestroy)
142 {
143 eStatus = m_vprenderHal->pfnDestroy(m_vprenderHal);
144 if (eStatus != MOS_STATUS_SUCCESS)
145 {
146 VP_PUBLIC_ASSERTMESSAGE("Failed to destroy RenderHal, eStatus:%d.\n", eStatus);
147 }
148 }
149 MOS_FreeMemory(m_vprenderHal);
150 }
151
152 if (m_cpInterface)
153 {
154 if (m_osInterface)
155 {
156 m_osInterface->pfnDeleteMhwCpInterface(m_cpInterface);
157 m_cpInterface = nullptr;
158 }
159 else
160 {
161 VP_PUBLIC_ASSERTMESSAGE("Failed to destroy cpInterface.");
162 }
163 }
164
165 if (m_sfcItf)
166 {
167 m_sfcItf = nullptr;
168 }
169
170 if (m_veboxItf)
171 {
172 eStatus = m_veboxItf->DestroyHeap();
173 m_veboxItf = nullptr;
174 }
175
176 // Destroy OS interface objects (CBs, etc)
177 if (m_osInterface)
178 {
179 if (m_osInterface->bDeallocateOnExit)
180 {
181 m_osInterface->pfnDestroy(m_osInterface, true);
182
183 // Deallocate OS interface structure (except if externally provided)
184 MOS_FreeMemory(m_osInterface);
185 }
186 }
187
188 vp::VpPlatformInterface *pIntf = &m_vpPlatformInterface;
189 MOS_Delete(pIntf);
190 }
191
192 //!
193 //! \brief Get Status Report
194 //! \details Get Status Report, will return back to app indicating if related frame id is done by gpu
195 //! \param [out] pQueryReport
196 //! Pointer to pQueryReport, the status query report array.
197 //! \param [in] wStatusNum
198 //! The size of array pQueryReport.
199 //! \return MOS_STATUS
200 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
201 MOS_STATUS VpPipelineAdapterBase::GetStatusReport(
202 PQUERY_STATUS_REPORT_APP pQueryReport,
203 uint16_t wStatusNum)
204 {
205 VP_FUNC_CALL();
206 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
207
208 #if (!EMUL) // this function is dummy for emul
209 uint32_t i;
210 uint32_t uiTableLen;
211 PVPHAL_STATUS_TABLE pStatusTable;
212 PMOS_CONTEXT pOsContext;
213 uint32_t uiIndex;
214 uint32_t uiNewHead;
215 PVPHAL_STATUS_ENTRY pStatusEntry;
216 bool bMarkNotReadyForRemains = false;
217
218 VP_PUBLIC_CHK_NULL(pQueryReport);
219 VP_PUBLIC_CHK_NULL(m_osInterface);
220 VP_PUBLIC_CHK_NULL(m_osInterface->pOsContext);
221
222 // it should be ok if we don't consider the null render
223 // eNullRender = m_pOsInterface->pfnGetNullHWRenderFlags(m_pOsInterface);
224
225 pOsContext = m_osInterface->pOsContext;
226 pStatusTable = &m_statusTable;
227 uiNewHead = pStatusTable->uiHead; // uiNewHead start from previous head value
228 // entry length from head to tail
229 if (pStatusTable->uiCurrent < pStatusTable->uiHead)
230 {
231 uiTableLen = pStatusTable->uiCurrent + VPHAL_STATUS_TABLE_MAX_SIZE - pStatusTable->uiHead;
232 }
233 else
234 {
235 uiTableLen = pStatusTable->uiCurrent - pStatusTable->uiHead;
236 }
237
238 // step 1 - update pStatusEntry from driver if command associated with the dwTag is done by gpu
239 for (i = 0; i < wStatusNum && i < uiTableLen; i++)
240 {
241 uint32_t dwGpuTag; // hardware tag updated by gpu command pipectl
242 bool bDoneByGpu;
243 bool bFailedOnSubmitCmd;
244
245 uiIndex = (pStatusTable->uiHead + i) & (VPHAL_STATUS_TABLE_MAX_SIZE - 1);
246 pStatusEntry = &pStatusTable->aTableEntries[uiIndex];
247
248 // for tasks using CM, different streamIndexes may be used
249 uint32_t oldStreamIndex = m_osInterface->streamIndex;
250 if (pStatusEntry->isStreamIndexSet)
251 {
252 m_osInterface->streamIndex = pStatusEntry->streamIndex;
253 }
254
255 if (bMarkNotReadyForRemains)
256 {
257 // the status is set as VPREP_NOTREADY while submitting commands
258 pQueryReport[i].dwStatus = pStatusEntry->dwStatus;
259 pQueryReport[i].StatusFeedBackID = pStatusEntry->StatusFeedBackID;
260 continue;
261 }
262
263 dwGpuTag = m_osInterface->pfnGetGpuStatusSyncTag(m_osInterface, pStatusEntry->GpuContextOrdinal);
264 bDoneByGpu = (dwGpuTag >= pStatusEntry->dwTag);
265 bFailedOnSubmitCmd = (pStatusEntry->dwStatus == VPREP_ERROR);
266
267 #if (_DEBUG || _RELEASE_INTERNAL)
268 MOS_NULL_RENDERING_FLAGS NullRender = m_osInterface->pfnGetNullHWRenderFlags(m_osInterface);
269 if (NullRender.Value != 0)
270 {
271 bDoneByGpu = true;
272 }
273 #endif
274
275 if (bFailedOnSubmitCmd)
276 {
277 uiNewHead = (uiIndex + 1) & (VPHAL_STATUS_TABLE_MAX_SIZE - 1);
278 }
279 else if (bDoneByGpu)
280 {
281 pStatusEntry->dwStatus = VPREP_OK;
282 uiNewHead = (uiIndex + 1) & (VPHAL_STATUS_TABLE_MAX_SIZE - 1);
283 }
284 else
285 { // here we have the first not ready entry.
286 #if (LINUX || ANDROID)
287 uiNewHead = (uiIndex + 1) & (VPHAL_STATUS_TABLE_MAX_SIZE - 1);
288 #else
289 uiNewHead = uiIndex;
290 #endif
291
292 bMarkNotReadyForRemains = true;
293 }
294
295 if (m_osInterface->pfnIsGPUHung(m_osInterface))
296 {
297 pStatusEntry->dwStatus = VPREP_NOTREADY;
298 }
299
300 pQueryReport[i].dwStatus = pStatusEntry->dwStatus;
301 pQueryReport[i].StatusFeedBackID = pStatusEntry->StatusFeedBackID;
302
303 if (pStatusEntry->isStreamIndexSet)
304 {
305 m_osInterface->streamIndex = oldStreamIndex;
306 }
307 }
308 pStatusTable->uiHead = uiNewHead;
309
310 // step 2 - mark VPREP_NOTAVAILABLE for unused entry
311 for (/* continue from previous i */; i < wStatusNum; i++)
312 {
313 pQueryReport[i].dwStatus = VPREP_NOTAVAILABLE;
314 pQueryReport[i].StatusFeedBackID = 0;
315 }
316
317 finish:
318 #else
319 MOS_UNUSED(pQueryReport);
320 MOS_UNUSED(wStatusNum);
321 #endif // end (!EMUL && !ANDROID)
322 return eStatus;
323 }
324
325 MOS_STATUS VpPipelineAdapterBase::GetStatusReportEntryLength(
326 uint32_t* puiLength)
327 {
328 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
329 #if(!EMUL) // this function is dummy for emul
330 PVPHAL_STATUS_TABLE pStatusTable;
331
332 VP_PUBLIC_CHK_NULL(puiLength);
333
334 pStatusTable = &m_statusTable;
335
336 // entry length from head to tail
337 if (pStatusTable->uiCurrent < pStatusTable->uiHead)
338 {
339 *puiLength = pStatusTable->uiCurrent + VPHAL_STATUS_TABLE_MAX_SIZE - pStatusTable->uiHead;
340 }
341 else
342 {
343 *puiLength = pStatusTable->uiCurrent - pStatusTable->uiHead;
344 }
345
346 finish:
347 #else
348 MOS_UNUSED(puiLength);
349 #endif
350 return eStatus;
351 }