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 #include "vp_pipeline_adapter_legacy.h"
23 #include "vp_platform_interface.h"
24 #include "vp_debug.h"
25 #include "vp_user_feature_control.h"
26 
VpPipelineAdapterLegacy(vp::VpPlatformInterface & vpPlatformInterface,MOS_STATUS & eStatus)27 VpPipelineAdapterLegacy::VpPipelineAdapterLegacy(
28     vp::VpPlatformInterface     &vpPlatformInterface,
29     MOS_STATUS                  &eStatus):
30     m_vpPlatformInterface(vpPlatformInterface)
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 //!
~VpPipelineAdapterLegacy()44 VpPipelineAdapterLegacy::~VpPipelineAdapterLegacy()
45 {
46     Destroy();
47 };
48 
Init(const VphalSettings * pVpHalSettings,VP_MHWINTERFACE vpMhwinterface)49 MOS_STATUS VpPipelineAdapterLegacy::Init(
50     const VphalSettings *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     if (vpMhwinterface.m_veboxInterface)
72     {
73         m_veboxItf = std::static_pointer_cast<mhw::vebox::Itf>(vpMhwinterface.m_veboxInterface->GetNewVeboxInterface());
74     }
75 
76     if (m_veboxItf)
77     {
78         const MHW_VEBOX_HEAP* veboxHeap = nullptr;
79         m_veboxItf->GetVeboxHeapInfo(&veboxHeap);
80         uint32_t uiNumInstances = m_veboxItf->GetVeboxNumInstances();
81 
82         if (uiNumInstances > 0 &&
83             veboxHeap == nullptr)
84         {
85             // Allocate VEBOX Heap
86             VP_PUBLIC_CHK_STATUS_RETURN(m_veboxItf->CreateHeap());
87         }
88     }
89     else if (vpMhwinterface.m_veboxInterface &&
90         vpMhwinterface.m_veboxInterface->m_veboxSettings.uiNumInstances > 0 &&
91         vpMhwinterface.m_veboxInterface->m_veboxHeap == nullptr)
92     {
93         VP_PUBLIC_CHK_STATUS_RETURN(vpMhwinterface.m_veboxInterface->CreateHeap());
94     }
95 
96     return m_vpPipeline->Init(&vpMhwinterface);
97 }
98 
Execute(PVP_PIPELINE_PARAMS params,PRENDERHAL_INTERFACE renderHal)99 MOS_STATUS VpPipelineAdapterLegacy::Execute(PVP_PIPELINE_PARAMS params, PRENDERHAL_INTERFACE renderHal)
100 {
101     MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
102     vp::VP_PARAMS vpParams = {};
103 
104     VP_FUNC_CALL();
105     VP_PUBLIC_CHK_NULL_RETURN(renderHal);
106 
107     vpParams.type = vp::PIPELINE_PARAM_TYPE_LEGACY;
108     vpParams.renderParams = params;
109 
110     eStatus = m_vpPipeline->Prepare(&vpParams);
111     if (eStatus != MOS_STATUS_SUCCESS)
112     {
113         if (eStatus == MOS_STATUS_UNIMPLEMENTED)
114         {
115             VP_PUBLIC_NORMALMESSAGE("Features are UNIMPLEMENTED on APG now \n");
116             return eStatus;
117         }
118         else
119         {
120             VP_PUBLIC_CHK_STATUS_RETURN(eStatus);
121         }
122     }
123     VPHAL_DBG_OCA_DUMPER_SET_RENDER_PARAM(renderHal, params);
124 
125     return m_vpPipeline->Execute();
126 }
127 
Destroy()128 void VpPipelineAdapterLegacy::Destroy()
129 {
130     VP_FUNC_CALL();
131     if (m_vpPipeline)
132     {
133         m_vpPipeline->Destroy();
134         m_vpPipeline = nullptr;
135     }
136     vp::VpPlatformInterface *pIntf = &m_vpPlatformInterface;
137     MOS_Delete(pIntf);
138 }
139 
Render(PCVPHAL_RENDER_PARAMS pcRenderParams)140 MOS_STATUS VpPipelineAdapterLegacy::Render(PCVPHAL_RENDER_PARAMS pcRenderParams)
141 {
142     VP_FUNC_CALL();
143 
144     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
145     VP_PIPELINE_PARAMS params = {};
146 
147     VP_PUBLIC_CHK_NULL_RETURN(pcRenderParams);
148     VP_PUBLIC_CHK_NULL_RETURN(m_vpPipeline);
149 
150     params = *(PVP_PIPELINE_PARAMS)pcRenderParams;
151     // default render of video
152     params.bIsDefaultStream = true;
153 
154     eStatus = Execute(&params);
155 
156     if (eStatus == MOS_STATUS_SUCCESS)
157     {
158         m_bApgEnabled = true;
159         VP_PUBLIC_NORMALMESSAGE("APG Execution successfully, return \n");
160         return eStatus;
161     }
162     else
163     {
164         m_bApgEnabled = false;
165         return eStatus;
166     }
167 }
168