| 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 | #include "vp_common_cache_settings.h" |
| 27 | |
| 28 | VpPipelineAdapter::VpPipelineAdapter( |
| 29 | vp::VpPlatformInterface &vpPlatformInterface, |
| 30 | MOS_STATUS &eStatus) : |
| 31 | VpPipelineAdapterBase(vpPlatformInterface, eStatus) |
| 32 | { |
| 33 | if (MOS_FAILED(eStatus)) |
| 34 | { |
| 35 | MOS_OS_ASSERTMESSAGE("VpPipelineAdapter construct failed due to VphalStateG12Tgllp() returned failure: eStatus = %d.", eStatus); |
| 36 | return; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | //! |
| 41 | //! \brief VpPipelineAdapter Destuctor |
| 42 | //! \details Destroys VpPipelineAdapter and all internal states and objects |
| 43 | //! \return void |
| 44 | //! |
| 45 | VpPipelineAdapter::~VpPipelineAdapter() |
| 46 | { |
| 47 | Destroy(); |
| 48 | }; |
| 49 | |
| 50 | MOS_STATUS VpPipelineAdapter::Init( |
| 51 | const VpSettings *pVpHalSettings, VP_MHWINTERFACE vpMhwinterface) |
| 52 | { |
| 53 | VP_FUNC_CALL(); |
| 54 | |
| 55 | m_vpPipeline = std::make_shared<vp::VpPipeline>(vpMhwinterface.m_osInterface); |
| 56 | VP_PUBLIC_CHK_NULL_RETURN(m_vpPipeline); |
| 57 | VP_PUBLIC_CHK_NULL_RETURN(vpMhwinterface.m_renderHal); |
| 58 | |
| 59 | vpMhwinterface.m_vpPlatformInterface = &m_vpPlatformInterface; |
| 60 | |
| 61 | // Init Video processing settings |
| 62 | VP_SETTINGS settings; |
| 63 | |
| 64 | MOS_ZeroMemory(&settings, sizeof(VP_SETTINGS)); |
| 65 | settings.disableHdr = pVpHalSettings->disableHdr; |
| 66 | settings.disableDnDi = pVpHalSettings->disableDnDi; |
| 67 | settings.kernelUpdate = pVpHalSettings->kernelUpdate; |
| 68 | settings.veboxParallelExecution = pVpHalSettings->veboxParallelExecution; |
| 69 | |
| 70 | vpMhwinterface.m_settings = (void *) &settings; |
| 71 | |
| 72 | m_veboxItf = vpMhwinterface.m_vpPlatformInterface->GetMhwVeboxItf(); |
| 73 | if (m_veboxItf) |
| 74 | { |
| 75 | const MHW_VEBOX_HEAP* veboxHeap = nullptr; |
| 76 | m_veboxItf->GetVeboxHeapInfo(&veboxHeap); |
| 77 | uint32_t uiNumInstances = m_veboxItf->GetVeboxNumInstances(); |
| 78 | |
| 79 | if (uiNumInstances > 0 && |
| 80 | veboxHeap == nullptr) |
| 81 | { |
| 82 | // Allocate VEBOX Heap |
| 83 | VP_PUBLIC_CHK_STATUS_RETURN(m_veboxItf->CreateHeap()); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | RENDERHAL_SETTINGS RenderHalSettings; |
| 88 | RenderHalSettings.iMediaStates = pVpHalSettings->mediaStates; |
| 89 | VP_PUBLIC_CHK_STATUS_RETURN(vpMhwinterface.m_renderHal->pfnInitialize(vpMhwinterface.m_renderHal, &RenderHalSettings)); |
| 90 | if (m_vpPlatformInterface.GetKernelConfig() && |
| 91 | m_vpPlatformInterface.GetKernelConfig()->GetRenderEnlargeOverwriteParams().needOverwrite) |
| 92 | { |
| 93 | VP_PUBLIC_CHK_STATUS_RETURN(vpMhwinterface.m_renderHal->pfnOverwriteEnlargedHeapParams(vpMhwinterface.m_renderHal, m_vpPlatformInterface.GetKernelConfig()->GetRenderEnlargeOverwriteParams().params)); |
| 94 | } |
| 95 | vpMhwinterface.m_renderHal->sseuTable = VpHalDefaultSSEUTable; |
| 96 | |
| 97 | return m_vpPipeline->Init(&vpMhwinterface); |
| 98 | } |
| 99 | |
| 100 | MOS_STATUS VpPipelineAdapter::Execute(PVP_PIPELINE_PARAMS params, PRENDERHAL_INTERFACE renderHal) |
| 101 | { |
| 102 | MOS_STATUS eStatus = MOS_STATUS_UNKNOWN; |
| 103 | vp::VP_PARAMS vpParams = {}; |
| 104 | |
| 105 | VP_FUNC_CALL(); |
| 106 | VP_PUBLIC_CHK_NULL_RETURN(renderHal); |
| 107 | |
| 108 | vpParams.type = vp::PIPELINE_PARAM_TYPE_LEGACY; |
| 109 | vpParams.renderParams = params; |
| 110 | |
| 111 | eStatus = m_vpPipeline->Prepare(&vpParams); |
| 112 | if (eStatus != MOS_STATUS_SUCCESS) |
| 113 | { |
| 114 | if (eStatus == MOS_STATUS_UNIMPLEMENTED) |
| 115 | { |
| 116 | VP_PUBLIC_NORMALMESSAGE("Features are UNIMPLEMENTED on APG now \n"); |
| 117 | return eStatus; |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | VP_PUBLIC_CHK_STATUS_RETURN(eStatus); |
| 122 | } |
| 123 | } |
| 124 | VPHAL_DBG_OCA_DUMPER_SET_RENDER_PARAM(renderHal, params); |
| 125 | |
| 126 | return m_vpPipeline->Execute(); |
| 127 | } |
| 128 | |
| 129 | void VpPipelineAdapter::Destroy() |
| 130 | { |
| 131 | VP_FUNC_CALL(); |
| 132 | if (m_vpPipeline) |
| 133 | { |
| 134 | m_vpPipeline->Destroy(); |
| 135 | m_vpPipeline = nullptr; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | MOS_STATUS VpPipelineAdapter::Render(PCVPHAL_RENDER_PARAMS pcRenderParams) |
| 140 | { |
| 141 | VP_FUNC_CALL(); |
| 142 | |
| 143 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 144 | VP_PIPELINE_PARAMS params = {}; |
| 145 | |
| 146 | VP_PUBLIC_CHK_NULL_RETURN(pcRenderParams); |
| 147 | VP_PUBLIC_CHK_NULL_RETURN(m_vpPipeline); |
| 148 | |
| 149 | if (1 == pcRenderParams->uSrcCount && pcRenderParams->uDstCount > 1) |
| 150 | { |
| 151 | for (uint32_t dstIndex = 0; dstIndex < pcRenderParams->uDstCount; ++dstIndex) |
| 152 | { |
| 153 | params = *(PVP_PIPELINE_PARAMS)pcRenderParams; |
| 154 | params.uDstCount = 1; |
| 155 | // update the first target point |
| 156 | params.pTarget[0] = pcRenderParams->pTarget[dstIndex]; |
| 157 | params.pTarget[0]->b16UsrPtr = pcRenderParams->pTarget[dstIndex]->b16UsrPtr; |
| 158 | if (pcRenderParams->uDstCount > 1) |
| 159 | { |
| 160 | // for multi output, support different scaling ratio but doesn't support cropping. |
| 161 | params.pSrc[0]->rcDst.top = params.pTarget[0]->rcSrc.top; |
| 162 | params.pSrc[0]->rcDst.left = params.pTarget[0]->rcSrc.left; |
| 163 | params.pSrc[0]->rcDst.bottom = params.pTarget[0]->rcSrc.bottom; |
| 164 | params.pSrc[0]->rcDst.right = params.pTarget[0]->rcSrc.right; |
| 165 | } |
| 166 | // default render of video |
| 167 | params.bIsDefaultStream = true; |
| 168 | |
| 169 | eStatus = Execute(¶ms); |
| 170 | if (MOS_FAILED(eStatus)) |
| 171 | { |
| 172 | VP_PUBLIC_ASSERTMESSAGE("APG Execution failed with 0x%x for dstIndex %d \n", eStatus, dstIndex); |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | params = *(PVP_PIPELINE_PARAMS)pcRenderParams; |
| 180 | // default render of video |
| 181 | params.bIsDefaultStream = true; |
| 182 | |
| 183 | eStatus = Execute(¶ms); |
| 184 | } |
| 185 | |
| 186 | if (eStatus == MOS_STATUS_SUCCESS) |
| 187 | { |
| 188 | m_bApgEnabled = true; |
| 189 | VP_PUBLIC_NORMALMESSAGE("APG Execution successfully, return \n"); |
| 190 | return eStatus; |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | VP_PUBLIC_ASSERTMESSAGE("APG Execution failed with 0x%x, return \n", eStatus); |
| 195 | m_bApgEnabled = false; |
| 196 | return eStatus; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | MOS_STATUS VpPipelineAdapter::Allocate( |
| 201 | const VpSettings *pVpHalSettings) |
| 202 | { |
| 203 | VP_FUNC_CALL(); |
| 204 | |
| 205 | VP_MHWINTERFACE vpMhwinterface = {}; //!< vp Mhw Interface |
| 206 | MOS_STATUS status = GetVpMhwInterface(vpMhwinterface); |
| 207 | if (MOS_FAILED(status)) |
| 208 | { |
| 209 | return status; |
| 210 | } |
| 211 | |
| 212 | VP_PUBLIC_CHK_STATUS_RETURN(RegisterCacheSettings()); |
| 213 | |
| 214 | return Init(pVpHalSettings, vpMhwinterface); |
| 215 | } |
| 216 | |
| 217 | MOS_STATUS VpPipelineAdapter::RegisterCacheSettings() |
| 218 | { |
| 219 | VP_FUNC_CALL(); |
| 220 | bool res = m_osInterface->pfnInsertCacheSetting(CACHE_COMPONENT_VP, &g_vp_cacheSettings); |
| 221 | |
| 222 | if (res == false) |
| 223 | { |
| 224 | VP_PUBLIC_ASSERTMESSAGE("CacheTables insert failed"); |
| 225 | VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED); |
| 226 | } |
| 227 | return MOS_STATUS_SUCCESS; |
| 228 | } |
| 229 | |
| 230 | MOS_STATUS VpPipelineAdapter::GetStatusReport( |
| 231 | PQUERY_STATUS_REPORT_APP pQueryReport, |
| 232 | uint16_t numStatus) |
| 233 | { |
| 234 | VP_FUNC_CALL(); |
| 235 | |
| 236 | return VpPipelineAdapterBase::GetStatusReport(pQueryReport, numStatus); |
| 237 | } |
| 238 | |
| 239 | VphalFeatureReport *VpPipelineAdapter::GetRenderFeatureReport() |
| 240 | { |
| 241 | VP_FUNC_CALL(); |
| 242 | |
| 243 | return m_vpPipeline == nullptr ? nullptr : m_vpPipeline->GetFeatureReport(); |
| 244 | } |
| 245 | |
| 246 | MOS_STATUS VpPipelineAdapter::Execute(PVP_PIPELINE_PARAMS params) |
| 247 | { |
| 248 | VP_FUNC_CALL(); |
| 249 | |
| 250 | return Execute(params, m_vprenderHal); |
| 251 | } |