| 1 | /* Copyright (c) 2020-2022, Intel Corporation |
| 2 | * |
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | * copy of this software and associated documentation files (the "Software"), |
| 5 | * to deal in the Software without restriction, including without limitation |
| 6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 7 | * and/or sell copies of the Software, and to permit persons to whom the |
| 8 | * Software is furnished to do so, subject to the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included |
| 11 | * in all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 14 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 16 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 17 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 18 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 19 | * OTHER DEALINGS IN THE SOFTWARE. |
| 20 | */ |
| 21 | //! |
| 22 | //! \file vp_render_kernelset.cpp |
| 23 | //! \brief The header file of the base class of kernel set |
| 24 | //! \details The kernel set will include kernel generation from binary. |
| 25 | //! It's responsible for setting up HW states and generating the SFC |
| 26 | //! commands. |
| 27 | //! |
| 28 | #include "vp_kernelset.h" |
| 29 | #include "vp_render_fc_kernel.h" |
| 30 | #include "vp_render_ocl_fc_kernel.h" |
| 31 | #include "vp_render_vebox_hdr_3dlut_kernel.h" |
| 32 | #include "vp_render_vebox_hvs_kernel.h" |
| 33 | #include "vp_render_hdr_kernel.h" |
| 34 | #include "vp_render_hdrlite_kernel.h" |
| 35 | #include "vp_render_vebox_hdr_3dlut_ocl_kernel.h" |
| 36 | #include "vp_render_ai_kernel.h" |
| 37 | |
| 38 | using namespace vp; |
| 39 | |
| 40 | VpKernelSet::VpKernelSet(PVP_MHWINTERFACE hwInterface, PVpAllocator allocator) : |
| 41 | m_hwInterface(hwInterface), |
| 42 | m_allocator(allocator) |
| 43 | { |
| 44 | if (hwInterface) |
| 45 | { |
| 46 | m_pKernelPool = &hwInterface->m_vpPlatformInterface->GetKernelPool(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | MOS_STATUS VpKernelSet::GetVpRenderKernel(std::string kernalName, VpRenderKernel &vpKernel) |
| 51 | { |
| 52 | VP_FUNC_CALL(); |
| 53 | |
| 54 | auto it = m_pKernelPool->find(kernalName); |
| 55 | |
| 56 | if (m_pKernelPool->end() == it) |
| 57 | { |
| 58 | VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER); |
| 59 | } |
| 60 | |
| 61 | vpKernel = it->second; |
| 62 | return MOS_STATUS_SUCCESS; |
| 63 | } |
| 64 | |
| 65 | MOS_STATUS VpKernelSet::GetKernelInfo(std::string kernelName, uint32_t kuid, uint32_t& size, void*& kernel) |
| 66 | { |
| 67 | VP_FUNC_CALL(); |
| 68 | |
| 69 | VP_RENDER_CHK_NULL_RETURN(m_pKernelPool); |
| 70 | auto it = m_pKernelPool->find(kernelName); |
| 71 | |
| 72 | if (m_pKernelPool->end() == it) |
| 73 | { |
| 74 | VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER); |
| 75 | } |
| 76 | |
| 77 | Kdll_State* kernelState = it->second.GetKdllState(); |
| 78 | |
| 79 | if (kernelState) |
| 80 | { |
| 81 | // For FC case, the kernel binary and size are gotten during GetKernelEntry. |
| 82 | if (IDR_VP_EOT == kuid) |
| 83 | { |
| 84 | size = 0; |
| 85 | kernel = nullptr; |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | size = kernelState->ComponentKernelCache.pCacheEntries[kuid].iSize; |
| 90 | kernel = kernelState->ComponentKernelCache.pCacheEntries[kuid].pBinary; |
| 91 | } |
| 92 | return MOS_STATUS_SUCCESS; |
| 93 | } |
| 94 | else if (kernelName == VpRenderKernel::s_kernelNameNonAdvKernels) |
| 95 | { |
| 96 | VP_PUBLIC_ASSERTMESSAGE("Kernel State not inplenmented, return error"); |
| 97 | return MOS_STATUS_UNINITIALIZED; |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | size = it->second.GetKernelSize(); |
| 102 | kernel = (void*)it->second.GetKernelBinPointer(); |
| 103 | return MOS_STATUS_SUCCESS; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // For Adv kernel |
| 108 | MOS_STATUS VpKernelSet::FindAndInitKernelObj(VpRenderKernelObj* kernelObj) |
| 109 | { |
| 110 | VP_FUNC_CALL(); |
| 111 | |
| 112 | VP_RENDER_CHK_NULL_RETURN(kernelObj); |
| 113 | VP_RENDER_CHK_NULL_RETURN(m_pKernelPool); |
| 114 | |
| 115 | bool bFind = false; |
| 116 | VP_RENDER_CHK_STATUS_RETURN(m_hwInterface->m_vpPlatformInterface->InitializeDelayedKernels(kernelObj->GetKernelType())); |
| 117 | |
| 118 | if (m_pKernelPool) |
| 119 | { |
| 120 | auto it = m_pKernelPool->find(kernelObj->GetKernelName()); |
| 121 | if (m_pKernelPool->end() != it) |
| 122 | { |
| 123 | auto &kernel = it->second; |
| 124 | VP_RENDER_CHK_STATUS_RETURN(kernelObj->Init(kernel)); |
| 125 | bFind = true; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | if (!bFind) |
| 130 | { |
| 131 | VP_RENDER_ASSERTMESSAGE("The kernel is not found!"); |
| 132 | return MOS_STATUS_INVALID_PARAMETER; |
| 133 | } |
| 134 | |
| 135 | return MOS_STATUS_SUCCESS; |
| 136 | } |
| 137 | |
| 138 | MOS_STATUS VpKernelSet::CreateSingleKernelObject( |
| 139 | VpRenderKernelObj *&kernel, |
| 140 | VpKernelID kernelId, |
| 141 | KernelIndex kernelIndex, |
| 142 | std::string kernelName) |
| 143 | { |
| 144 | VP_FUNC_CALL(); |
| 145 | kernel = nullptr; |
| 146 | switch ((uint32_t)kernelId) |
| 147 | { |
| 148 | case kernelCombinedFc: |
| 149 | kernel = (VpRenderKernelObj*)MOS_New(VpRenderFcKernel, m_hwInterface, m_allocator); |
| 150 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 151 | break; |
| 152 | case kernelOclFcCommon: |
| 153 | case kernelOclFcFP: |
| 154 | case kernelOclFc420PL3Input: |
| 155 | case kernelOclFc420PL3Output: |
| 156 | case kernelOclFc444PL3Input: |
| 157 | case kernelOclFc444PL3Output: |
| 158 | case kernelOclFc422HVInput: |
| 159 | kernel = (VpRenderKernelObj *)MOS_New(VpRenderOclFcKernel, m_hwInterface, kernelId, kernelIndex, m_allocator); |
| 160 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 161 | break; |
| 162 | case kernelHdr3DLutCalc: |
| 163 | if (m_pKernelPool->find(VP_HDR_KERNEL_NAME_L0) != m_pKernelPool->end()) |
| 164 | { |
| 165 | VP_RENDER_NORMALMESSAGE("HDR 3dlut kernel use l0 hdr_3dlut_l0 kernel"); |
| 166 | kernel = (VpRenderKernelObj *)MOS_New(VpRenderHdr3DLutKernel, m_hwInterface, m_allocator); |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | VP_RENDER_NORMALMESSAGE("HDR 3dlut kernel use isa hdr_3dlut kernel"); |
| 171 | kernel = (VpRenderKernelObj *)MOS_New(VpRenderHdr3DLutKernelCM, m_hwInterface, kernelId, kernelIndex, m_allocator); |
| 172 | } |
| 173 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 174 | break; |
| 175 | case kernelHdr3DLutCalcOcl: |
| 176 | VP_RENDER_NORMALMESSAGE("HDR 3dlut kernel use ocl fillLutTable_3dlut kernel"); |
| 177 | kernel = (VpRenderKernelObj *)MOS_New(VpRenderHdr3DLutOclKernel, m_hwInterface, m_allocator); |
| 178 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 179 | break; |
| 180 | case kernelHVSCalc: |
| 181 | kernel = (VpRenderKernelObj *)MOS_New(VpRenderHVSKernel, m_hwInterface, kernelId, kernelIndex, m_allocator); |
| 182 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 183 | break; |
| 184 | case kernelHdrMandatory: |
| 185 | kernel = (VpRenderKernelObj *)MOS_New(VpRenderHdrKernel, m_hwInterface, m_allocator); |
| 186 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 187 | break; |
| 188 | case kernelHdrMandatoryLite: |
| 189 | kernel = (VpRenderKernelObj *)MOS_New(VpRenderHDRLITEKernel, m_hwInterface, kernelId, kernelIndex, m_allocator); |
| 190 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 191 | break; |
| 192 | case kernelAiCommon: |
| 193 | kernel = (VpRenderKernelObj *)MOS_New(VpRenderAiKernel, m_hwInterface, kernelName, kernelIndex, m_allocator); |
| 194 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 195 | break; |
| 196 | default: |
| 197 | VP_RENDER_ASSERTMESSAGE("No supported kernel, return"); |
| 198 | return MOS_STATUS_UNIMPLEMENTED; |
| 199 | } |
| 200 | |
| 201 | return MOS_STATUS_SUCCESS; |
| 202 | } |
| 203 | |
| 204 | MOS_STATUS VpKernelSet::CreateKernelObjects( |
| 205 | KERNEL_PARAMS_LIST& kernelParams, |
| 206 | VP_SURFACE_GROUP& surfacesGroup, |
| 207 | KERNEL_SAMPLER_STATE_GROUP& samplerStateGroup, |
| 208 | KERNEL_CONFIGS& kernelConfigs, |
| 209 | KERNEL_OBJECTS& kernelObjs, |
| 210 | VP_RENDER_CACHE_CNTL& surfMemCacheCtl, |
| 211 | VP_PACKET_SHARED_CONTEXT *sharedContext) |
| 212 | { |
| 213 | VP_FUNC_CALL(); |
| 214 | |
| 215 | VpRenderKernelObj* kernel = nullptr; |
| 216 | |
| 217 | auto VpStatusHandler = [&] (MOS_STATUS status) |
| 218 | { |
| 219 | if (MOS_FAILED(status)) |
| 220 | { |
| 221 | if (kernel) |
| 222 | { |
| 223 | auto it = m_cachedKernels.find(kernel->GetKernelId()); |
| 224 | if (it != m_cachedKernels.end() && it->second == kernel) |
| 225 | { |
| 226 | m_cachedKernels.erase(it); |
| 227 | } |
| 228 | MOS_Delete(kernel); |
| 229 | } |
| 230 | } |
| 231 | return status; |
| 232 | }; |
| 233 | |
| 234 | kernelObjs.clear(); |
| 235 | |
| 236 | for (uint32_t kernelIndex = 0; kernelIndex < kernelParams.size(); ++kernelIndex) |
| 237 | { |
| 238 | auto it = m_cachedKernels.find(kernelParams[kernelIndex].kernelId); |
| 239 | if (m_cachedKernels.end() == it) |
| 240 | { |
| 241 | VP_RENDER_CHK_STATUS_RETURN(CreateSingleKernelObject( |
| 242 | kernel, |
| 243 | kernelParams[kernelIndex].kernelId, |
| 244 | kernelIndex, |
| 245 | kernelParams[kernelIndex].kernelName)); |
| 246 | if (kernel->IsKernelCached()) |
| 247 | { |
| 248 | m_cachedKernels.insert(std::make_pair(kernelParams[kernelIndex].kernelId, kernel)); |
| 249 | } |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | kernel = it->second; |
| 254 | } |
| 255 | |
| 256 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 257 | |
| 258 | if (!kernel->IsAdvKernel()) |
| 259 | { |
| 260 | void* binary = nullptr; |
| 261 | uint32_t kernelSize = 0; |
| 262 | |
| 263 | VP_RENDER_CHK_NULL_RETURN(kernel); |
| 264 | |
| 265 | VP_RENDER_CHK_STATUS_RETURN(VpStatusHandler(GetKernelInfo(kernel->GetKernelName(), kernel->GetKernelBinaryID(), kernelSize, binary))); |
| 266 | |
| 267 | VP_RENDER_CHK_STATUS_RETURN(VpStatusHandler(kernel->InitKernel(binary, kernelSize, kernelConfigs, surfacesGroup, surfMemCacheCtl))); |
| 268 | |
| 269 | kernelObjs.emplace(kernelIndex, kernel); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | VP_RENDER_CHK_STATUS_RETURN(VpStatusHandler(FindAndInitKernelObj(kernel))); |
| 274 | |
| 275 | VP_RENDER_CHK_STATUS_RETURN(VpStatusHandler(kernel->SetKernelConfigs(kernelParams[kernelIndex], surfacesGroup, samplerStateGroup, kernelConfigs, sharedContext))); |
| 276 | |
| 277 | kernelObjs.emplace(kernelIndex, kernel); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | kernelParams.clear(); |
| 282 | |
| 283 | if (kernelObjs.empty()) |
| 284 | { |
| 285 | VP_RENDER_ASSERTMESSAGE("Kernel Object Fail, return Error"); |
| 286 | return MOS_STATUS_NULL_POINTER; |
| 287 | } |
| 288 | |
| 289 | return MOS_STATUS_SUCCESS; |
| 290 | } |