1 /*
2 * Copyright (c) 2020, 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 #include "vp_pipeline_adapter.h"
23 #include "vp_platform_interface.h"
24 #include "vp_debug.h"
25 #include "vp_user_feature_control.h"
26
VpPipelineAdapter(vp::VpPlatformInterface & vpPlatformInterface,MOS_STATUS & eStatus)27 VpPipelineAdapter::VpPipelineAdapter(
28 vp::VpPlatformInterface &vpPlatformInterface,
29 MOS_STATUS &eStatus) :
30 VpPipelineAdapterBase(vpPlatformInterface, eStatus)
31 {
32 if (MOS_FAILED(eStatus))
33 {
34 MOS_OS_ASSERTMESSAGE("VpPipelineAdapter construct failed due to VphalStateG12Tgllp() returned failure: eStatus = %d.", eStatus);
35 return;
36 }
37 }
38
39 //!
40 //! \brief VpPipelineAdapter Destuctor
41 //! \details Destroys VpPipelineAdapter and all internal states and objects
42 //! \return void
43 //!
~VpPipelineAdapter()44 VpPipelineAdapter::~VpPipelineAdapter()
45 {
46 Destroy();
47 };
48
Init(const VpSettings * pVpHalSettings,VP_MHWINTERFACE vpMhwinterface)49 MOS_STATUS VpPipelineAdapter::Init(
50 const VpSettings *pVpHalSettings, VP_MHWINTERFACE vpMhwinterface)
51 {
52 VP_FUNC_CALL();
53
54 m_vpPipeline = std::make_shared<vp::VpPipeline>(vpMhwinterface.m_osInterface);
55 VP_PUBLIC_CHK_NULL_RETURN(m_vpPipeline);
56 VP_PUBLIC_CHK_NULL_RETURN(vpMhwinterface.m_renderHal);
57
58 vpMhwinterface.m_vpPlatformInterface = &m_vpPlatformInterface;
59
60 // Init Video processing settings
61 VP_SETTINGS settings;
62
63 MOS_ZeroMemory(&settings, sizeof(VP_SETTINGS));
64 settings.disableHdr = pVpHalSettings->disableHdr;
65 settings.disableDnDi = pVpHalSettings->disableDnDi;
66 settings.kernelUpdate = pVpHalSettings->kernelUpdate;
67 settings.veboxParallelExecution = pVpHalSettings->veboxParallelExecution;
68
69 vpMhwinterface.m_settings = (void *) &settings;
70
71 m_veboxItf = vpMhwinterface.m_vpPlatformInterface->GetMhwVeboxItf();
72 if (m_veboxItf)
73 {
74 const MHW_VEBOX_HEAP* veboxHeap = nullptr;
75 m_veboxItf->GetVeboxHeapInfo(&veboxHeap);
76 uint32_t uiNumInstances = m_veboxItf->GetVeboxNumInstances();
77
78 if (uiNumInstances > 0 &&
79 veboxHeap == nullptr)
80 {
81 // Allocate VEBOX Heap
82 VP_PUBLIC_CHK_STATUS_RETURN(m_veboxItf->CreateHeap());
83 }
84 }
85
86 RENDERHAL_SETTINGS RenderHalSettings;
87 RenderHalSettings.iMediaStates = pVpHalSettings->mediaStates;
88 VP_PUBLIC_CHK_STATUS_RETURN(vpMhwinterface.m_renderHal->pfnInitialize(vpMhwinterface.m_renderHal, &RenderHalSettings));
89 vpMhwinterface.m_renderHal->sseuTable = VpHalDefaultSSEUTable;
90
91 return m_vpPipeline->Init(&vpMhwinterface);
92 }
93
Execute(PVP_PIPELINE_PARAMS params,PRENDERHAL_INTERFACE renderHal)94 MOS_STATUS VpPipelineAdapter::Execute(PVP_PIPELINE_PARAMS params, PRENDERHAL_INTERFACE renderHal)
95 {
96 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
97 vp::VP_PARAMS vpParams = {};
98
99 VP_FUNC_CALL();
100 VP_PUBLIC_CHK_NULL_RETURN(renderHal);
101
102 vpParams.type = vp::PIPELINE_PARAM_TYPE_LEGACY;
103 vpParams.renderParams = params;
104
105 eStatus = m_vpPipeline->Prepare(&vpParams);
106 if (eStatus != MOS_STATUS_SUCCESS)
107 {
108 if (eStatus == MOS_STATUS_UNIMPLEMENTED)
109 {
110 VP_PUBLIC_NORMALMESSAGE("Features are UNIMPLEMENTED on APG now \n");
111 return eStatus;
112 }
113 else
114 {
115 VP_PUBLIC_CHK_STATUS_RETURN(eStatus);
116 }
117 }
118 VPHAL_DBG_OCA_DUMPER_SET_RENDER_PARAM(renderHal, params);
119
120 return m_vpPipeline->Execute();
121 }
122
Destroy()123 void VpPipelineAdapter::Destroy()
124 {
125 VP_FUNC_CALL();
126 if (m_vpPipeline)
127 {
128 m_vpPipeline->Destroy();
129 m_vpPipeline = nullptr;
130 }
131 }
132
Render(PCVPHAL_RENDER_PARAMS pcRenderParams)133 MOS_STATUS VpPipelineAdapter::Render(PCVPHAL_RENDER_PARAMS pcRenderParams)
134 {
135 VP_FUNC_CALL();
136
137 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
138 VP_PIPELINE_PARAMS params = {};
139
140 VP_PUBLIC_CHK_NULL_RETURN(pcRenderParams);
141 VP_PUBLIC_CHK_NULL_RETURN(m_vpPipeline);
142
143 if (1 == pcRenderParams->uSrcCount && pcRenderParams->uDstCount > 1)
144 {
145 for (uint32_t dstIndex = 0; dstIndex < pcRenderParams->uDstCount; ++dstIndex)
146 {
147 params = *(PVP_PIPELINE_PARAMS)pcRenderParams;
148 params.uDstCount = 1;
149 // update the first target point
150 params.pTarget[0] = pcRenderParams->pTarget[dstIndex];
151 params.pTarget[0]->b16UsrPtr = pcRenderParams->pTarget[dstIndex]->b16UsrPtr;
152 if (pcRenderParams->uDstCount > 1)
153 {
154 // for multi output, support different scaling ratio but doesn't support cropping.
155 params.pSrc[0]->rcDst.top = params.pTarget[0]->rcSrc.top;
156 params.pSrc[0]->rcDst.left = params.pTarget[0]->rcSrc.left;
157 params.pSrc[0]->rcDst.bottom = params.pTarget[0]->rcSrc.bottom;
158 params.pSrc[0]->rcDst.right = params.pTarget[0]->rcSrc.right;
159 }
160 // default render of video
161 params.bIsDefaultStream = true;
162
163 eStatus = Execute(¶ms);
164 if (MOS_FAILED(eStatus))
165 {
166 VP_PUBLIC_ASSERTMESSAGE("APG Execution failed with 0x%x for dstIndex %d \n", eStatus, dstIndex);
167 break;
168 }
169 }
170 }
171 else
172 {
173 params = *(PVP_PIPELINE_PARAMS)pcRenderParams;
174 // default render of video
175 params.bIsDefaultStream = true;
176
177 eStatus = Execute(¶ms);
178 }
179
180 if (eStatus == MOS_STATUS_SUCCESS)
181 {
182 m_bApgEnabled = true;
183 VP_PUBLIC_NORMALMESSAGE("APG Execution successfully, return \n");
184 return eStatus;
185 }
186 else
187 {
188 VP_PUBLIC_ASSERTMESSAGE("APG Execution failed with 0x%x, return \n", eStatus);
189 m_bApgEnabled = false;
190 return eStatus;
191 }
192 }
193