| 1 |
/* |
| 2 |
* Copyright (c) 2025, 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_render_ai_kernel.cpp |
| 24 |
//! \brief ai kernel obj which used in by mediapipline. |
| 25 |
//! \details ai kernel obj which used in by mediapipline. |
| 26 |
//! |
| 27 |
|
| 28 |
#include "vp_render_ai_kernel.h" |
| 29 |
|
| 30 |
using namespace vp; |
| 31 |
|
| 32 |
#define AI_BINDLESS_NEAREST_SAMPLER_INDEX 0 |
| 33 |
#define AI_BINDLESS_BILIEAR_SAMPLER_INDEX 1 |
| 34 |
|
| 35 |
std::map<std::string, VpKernelID> VpRenderAiKernel::m_kernelBiniaryIdMap; |
| 36 |
VpKernelID VpRenderAiKernel::m_currentBiniaryID = VpKernelID(kernelAiCommon); |
| 37 |
|
| 38 |
VpRenderAiKernel::VpRenderAiKernel(PVP_MHWINTERFACE hwInterface, std::string kernelName, uint32_t kernelIndex, PVpAllocator allocator) : VpRenderKernelObj(hwInterface, VpKernelID(kernelAiCommon), kernelIndex, kernelName, allocator) |
| 39 |
{ |
| 40 |
m_renderHal = hwInterface ? hwInterface->m_renderHal : nullptr; |
| 41 |
m_kernelIndex = kernelIndex; |
| 42 |
m_isAdvKernel = true; |
| 43 |
m_useIndependentSamplerGroup = true; |
| 44 |
|
| 45 |
VpKernelID kernelBinaryID = VpKernelID(kernelAiCommon); |
| 46 |
auto handle = m_kernelBiniaryIdMap.find(kernelName); |
| 47 |
if (m_kernelBiniaryIdMap.find(kernelName) == m_kernelBiniaryIdMap.end()) |
| 48 |
{ |
| 49 |
handle = m_kernelBiniaryIdMap.insert(std::make_pair(kernelName, m_currentBiniaryID)).first; |
| 50 |
m_currentBiniaryID = VpKernelID(m_currentBiniaryID + 1); |
| 51 |
} |
| 52 |
if (handle == m_kernelBiniaryIdMap.end()) |
| 53 |
{ |
| 54 |
VP_PUBLIC_ASSERTMESSAGE("m_kernelBiniaryIdMap insert failure, this may cause kernel instruction wrong"); |
| 55 |
} |
| 56 |
else |
| 57 |
{ |
| 58 |
kernelBinaryID = handle->second; |
| 59 |
} |
| 60 |
m_kernelBinaryID = VP_ADV_KERNEL_BINARY_ID(kernelBinaryID); |
| 61 |
} |
| 62 |
|
| 63 |
VpRenderAiKernel::~VpRenderAiKernel() |
| 64 |
{ |
| 65 |
MOS_SafeFreeMemory(m_curbe); |
| 66 |
m_curbe = nullptr; |
| 67 |
} |
| 68 |
|
| 69 |
MOS_STATUS VpRenderAiKernel::Init(VpRenderKernel &kernel) |
| 70 |
{ |
| 71 |
VP_FUNC_CALL(); |
| 72 |
|
| 73 |
VP_RENDER_NORMALMESSAGE("Initializing AI krn %s", kernel.GetKernelName().c_str()); |
| 74 |
|
| 75 |
m_kernelSize = kernel.GetKernelSize(); |
| 76 |
|
| 77 |
uint8_t *pKernelBin = (uint8_t *)kernel.GetKernelBinPointer(); |
| 78 |
VP_RENDER_CHK_NULL_RETURN(pKernelBin); |
| 79 |
|
| 80 |
m_kernelBinary = pKernelBin + kernel.GetKernelBinOffset(); |
| 81 |
|
| 82 |
m_kernelArgs.clear(); |
| 83 |
for (auto &arg : kernel.GetKernelArgs()) |
| 84 |
{ |
| 85 |
arg.pData = nullptr; |
| 86 |
m_kernelArgs.insert(std::make_pair(arg.uIndex, arg)); |
| 87 |
} |
| 88 |
|
| 89 |
m_kernelBtis = kernel.GetKernelBtis(); |
| 90 |
|
| 91 |
m_kernelEnv = kernel.GetKernelExeEnv(); |
| 92 |
|
| 93 |
m_kernelPerThreadArgInfo = kernel.GetKernelPerThreadArgInfo(); |
| 94 |
|
| 95 |
m_curbeLocation.size = kernel.GetCurbeSize(); |
| 96 |
|
| 97 |
m_inlineData.resize(m_kernelEnv.uInlineDataPayloadSize); |
| 98 |
|
| 99 |
return MOS_STATUS_SUCCESS; |
| 100 |
} |
| 101 |
|
| 102 |
MOS_STATUS VpRenderAiKernel::SetSamplerStates(KERNEL_SAMPLER_STATE_GROUP &samplerStateGroup) |
| 103 |
{ |
| 104 |
VP_FUNC_CALL(); |
| 105 |
|
| 106 |
if (m_kernelEnv.bHasSample) |
| 107 |
{ |
| 108 |
samplerStateGroup.clear(); |
| 109 |
|
| 110 |
MHW_SAMPLER_STATE_PARAM samplerStateParam = {}; |
| 111 |
samplerStateParam.Unorm.SamplerFilterMode = MHW_SAMPLER_FILTER_BILINEAR; |
| 112 |
samplerStateParam.Unorm.MagFilter = MHW_GFX3DSTATE_MAPFILTER_LINEAR; |
| 113 |
samplerStateParam.Unorm.MinFilter = MHW_GFX3DSTATE_MAPFILTER_LINEAR; |
| 114 |
samplerStateParam.Unorm.AddressU = MHW_GFX3DSTATE_TEXCOORDMODE_CLAMP; |
| 115 |
samplerStateParam.Unorm.AddressV = MHW_GFX3DSTATE_TEXCOORDMODE_CLAMP; |
| 116 |
samplerStateParam.Unorm.AddressW = MHW_GFX3DSTATE_TEXCOORDMODE_CLAMP; |
| 117 |
samplerStateParam.bInUse = true; |
| 118 |
samplerStateParam.SamplerType = MHW_SAMPLER_TYPE_3D; |
| 119 |
if (m_linearSamplerIndex >= 0) |
| 120 |
{ |
| 121 |
VP_RENDER_NORMALMESSAGE("Bilinear Sampler Set on Sampler Index %d", m_linearSamplerIndex); |
| 122 |
samplerStateGroup.insert(std::make_pair(m_linearSamplerIndex, samplerStateParam)); |
| 123 |
} |
| 124 |
else |
| 125 |
{ |
| 126 |
VP_RENDER_NORMALMESSAGE("Bilinear Sampler NOT SET for Invalid Index %d", m_linearSamplerIndex); |
| 127 |
} |
| 128 |
|
| 129 |
samplerStateParam = {}; |
| 130 |
samplerStateParam.Unorm.SamplerFilterMode = MHW_SAMPLER_FILTER_NEAREST; |
| 131 |
samplerStateParam.Unorm.MagFilter = MHW_GFX3DSTATE_MAPFILTER_NEAREST; |
| 132 |
samplerStateParam.Unorm.MinFilter = MHW_GFX3DSTATE_MAPFILTER_NEAREST; |
| 133 |
samplerStateParam.Unorm.AddressU = MHW_GFX3DSTATE_TEXCOORDMODE_CLAMP; |
| 134 |
samplerStateParam.Unorm.AddressV = MHW_GFX3DSTATE_TEXCOORDMODE_CLAMP; |
| 135 |
samplerStateParam.Unorm.AddressW = MHW_GFX3DSTATE_TEXCOORDMODE_CLAMP; |
| 136 |
samplerStateParam.bInUse = true; |
| 137 |
samplerStateParam.SamplerType = MHW_SAMPLER_TYPE_3D; |
| 138 |
if (m_nearestSamplerIndex >= 0) |
| 139 |
{ |
| 140 |
VP_RENDER_NORMALMESSAGE("Nearest Sampler Set on Sampler Index %d", m_nearestSamplerIndex); |
| 141 |
samplerStateGroup.insert(std::make_pair(m_nearestSamplerIndex, samplerStateParam)); |
| 142 |
} |
| 143 |
else |
| 144 |
{ |
| 145 |
VP_RENDER_NORMALMESSAGE("Nearest Sampler NOT SET for Invalid Index %d", m_nearestSamplerIndex); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
return MOS_STATUS_SUCCESS; |
| 150 |
} |
| 151 |
|
| 152 |
MOS_STATUS VpRenderAiKernel::SetKernelArgs(KERNEL_ARGS &kernelArgs, VP_PACKET_SHARED_CONTEXT *sharedContext) |
| 153 |
{ |
| 154 |
VP_FUNC_CALL(); |
| 155 |
|
| 156 |
for (KRN_ARG &srcArg : kernelArgs) |
| 157 |
{ |
| 158 |
auto handle = m_kernelArgs.find(srcArg.uIndex); |
| 159 |
|
| 160 |
if (handle != m_kernelArgs.end()) |
| 161 |
{ |
| 162 |
if (srcArg.eArgKind == ARG_KIND_GENERAL || srcArg.eArgKind == ARG_KIND_INLINE) |
| 163 |
{ |
| 164 |
KRN_ARG &dstArg = handle->second; |
| 165 |
if (srcArg.pData == nullptr) |
| 166 |
{ |
| 167 |
VP_RENDER_ASSERTMESSAGE("The Kernel Argument General Data is null! KernelName %s, argIndex %d", m_kernelName.c_str(), dstArg.uIndex); |
| 168 |
return MOS_STATUS_INVALID_PARAMETER; |
| 169 |
} |
| 170 |
else |
| 171 |
{ |
| 172 |
dstArg.eArgKind = srcArg.eArgKind; |
| 173 |
dstArg.pData = srcArg.pData; |
| 174 |
srcArg.pData = nullptr; |
| 175 |
} |
| 176 |
} |
| 177 |
else if (srcArg.eArgKind == ARG_KIND_SURFACE && srcArg.addressMode == AddressingModeStateless) |
| 178 |
{ |
| 179 |
KRN_ARG &dstArg = handle->second; |
| 180 |
//leave it to SetStatelessSurface() to handle, because here m_surfaceGroup is still nullptr now |
| 181 |
dstArg.pData = srcArg.pData; |
| 182 |
srcArg.pData = nullptr; |
| 183 |
} |
| 184 |
else if (srcArg.eArgKind == ARG_KIND_SAMPLER) |
| 185 |
{ |
| 186 |
KRN_ARG &dstArg = handle->second; |
| 187 |
if (srcArg.pData == nullptr) |
| 188 |
{ |
| 189 |
VP_RENDER_ASSERTMESSAGE("The Kernel Argument Sampler Data is null! KernelName %s, argIndex %d", m_kernelName.c_str(), dstArg.uIndex); |
| 190 |
return MOS_STATUS_INVALID_PARAMETER; |
| 191 |
} |
| 192 |
else |
| 193 |
{ |
| 194 |
if (dstArg.addressMode == AddressingModeBindless) |
| 195 |
{ |
| 196 |
m_linearSamplerIndex = AI_BINDLESS_BILIEAR_SAMPLER_INDEX; |
| 197 |
m_nearestSamplerIndex = AI_BINDLESS_NEAREST_SAMPLER_INDEX; |
| 198 |
dstArg.pData = srcArg.pData; |
| 199 |
srcArg.pData = nullptr; |
| 200 |
} |
| 201 |
else |
| 202 |
{ |
| 203 |
if (*(uint32_t *)srcArg.pData == MHW_SAMPLER_FILTER_BILINEAR) |
| 204 |
{ |
| 205 |
m_linearSamplerIndex = dstArg.uOffsetInPayload; |
| 206 |
srcArg.pData = nullptr; |
| 207 |
} |
| 208 |
else if (*(uint32_t *)srcArg.pData == MHW_SAMPLER_FILTER_NEAREST) |
| 209 |
{ |
| 210 |
m_nearestSamplerIndex = dstArg.uOffsetInPayload; |
| 211 |
srcArg.pData = nullptr; |
| 212 |
} |
| 213 |
else |
| 214 |
{ |
| 215 |
VP_RENDER_ASSERTMESSAGE("The Kernel Argument Sampler Data is INVALID TYPE! KernelName %s, argIndex %d, type %d", m_kernelName.c_str(), dstArg.uIndex, *(uint32_t *)srcArg.pData); |
| 216 |
return MOS_STATUS_INVALID_PARAMETER; |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
if (srcArg.pData != nullptr) |
| 224 |
{ |
| 225 |
srcArg.pData = nullptr; |
| 226 |
VP_RENDER_ASSERTMESSAGE("The Kernel Argument is set but not used. KernelName %s, argIndex %d", m_kernelName.c_str(), srcArg.uIndex); |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
return MOS_STATUS_SUCCESS; |
| 231 |
} |
| 232 |
|
| 233 |
MOS_STATUS VpRenderAiKernel::GetCurbeState(void *&curbe, uint32_t &curbeLength) |
| 234 |
{ |
| 235 |
VP_FUNC_CALL(); |
| 236 |
m_curbeResourceList.clear(); |
| 237 |
curbeLength = m_curbeLocation.size; |
| 238 |
|
| 239 |
bool isLocalIdGeneratedByRuntime = IsLocalIdGeneratedByRuntime(m_kernelEnv, m_kernelPerThreadArgInfo, m_walkerParam.threadWidth, m_walkerParam.threadHeight, m_walkerParam.threadDepth); |
| 240 |
if (isLocalIdGeneratedByRuntime) |
| 241 |
{ |
| 242 |
VP_RENDER_CHK_STATUS_RETURN(PaddingPerThreadCurbe(curbeLength, m_walkerParam.threadWidth, m_walkerParam.threadHeight, m_walkerParam.threadDepth)); |
| 243 |
} |
| 244 |
|
| 245 |
VP_RENDER_NORMALMESSAGE("KernelID %d, Kernel Name %s, Curbe Size %d\n", m_kernelId, m_kernelName.c_str(), curbeLength); |
| 246 |
|
| 247 |
if (curbeLength == 0) |
| 248 |
{ |
| 249 |
VP_RENDER_NORMALMESSAGE("Skip Allocate Curbe for its Size is 0"); |
| 250 |
curbe = nullptr; |
| 251 |
return MOS_STATUS_SUCCESS; |
| 252 |
} |
| 253 |
|
| 254 |
uint8_t *pCurbe = (uint8_t *)MOS_AllocAndZeroMemory(curbeLength); |
| 255 |
VP_RENDER_CHK_NULL_RETURN(pCurbe); |
| 256 |
MOS_FreeMemAndSetNull(m_curbe); |
| 257 |
m_curbe = pCurbe; |
| 258 |
|
| 259 |
for (auto &handle : m_kernelArgs) |
| 260 |
{ |
| 261 |
KRN_ARG &arg = handle.second; |
| 262 |
switch (arg.eArgKind) |
| 263 |
{ |
| 264 |
case ARG_KIND_GENERAL: |
| 265 |
if (arg.pData != nullptr) |
| 266 |
{ |
| 267 |
MOS_SecureMemcpy(pCurbe + arg.uOffsetInPayload, arg.uSize, arg.pData, arg.uSize); |
| 268 |
VP_RENDER_NORMALMESSAGE("Setting Curbe State KernelName %s, index %d , value %d, argKind %d", m_kernelName.c_str(), arg.uIndex, *(uint32_t *)arg.pData, arg.eArgKind); |
| 269 |
} |
| 270 |
else |
| 271 |
{ |
| 272 |
VP_RENDER_NORMALMESSAGE("KernelName %s, index %d, argKind %d is empty", m_kernelName.c_str(), arg.uIndex, arg.eArgKind); |
| 273 |
} |
| 274 |
break; |
| 275 |
case ARG_KIND_SURFACE: |
| 276 |
if (arg.addressMode == AddressingModeBindless) |
| 277 |
{ |
| 278 |
// this is bindless surface |
| 279 |
VP_PUBLIC_CHK_STATUS_RETURN(SetBindlessSurfaceStateToResourceList(arg)); |
| 280 |
VP_RENDER_NORMALMESSAGE("Setting Curbe State Bindless Surface KernelID %d, index %d, argKind %d", m_kernelId, arg.uIndex, arg.eArgKind); |
| 281 |
} |
| 282 |
else if (arg.addressMode == AddressingModeStateless) |
| 283 |
{ |
| 284 |
if (arg.pData != nullptr) |
| 285 |
{ |
| 286 |
VP_PUBLIC_CHK_NULL_RETURN(m_surfaceGroup); |
| 287 |
SURFACE_PARAMS &surfaceParam = *(SURFACE_PARAMS *)arg.pData; |
| 288 |
if (surfaceParam.surfType == SurfaceTypeSubPlane || surfaceParam.surfType == SurfaceTypeInvalid) |
| 289 |
{ |
| 290 |
VP_RENDER_NORMALMESSAGE("Will skip stateless surface argIndex %d for its surf type is set as %d", arg.uIndex, surfaceParam.surfType); |
| 291 |
arg.pData = nullptr; |
| 292 |
continue; |
| 293 |
} |
| 294 |
auto surfHandle = m_surfaceGroup->find(surfaceParam.surfType); |
| 295 |
VP_PUBLIC_CHK_NOT_FOUND_RETURN(surfHandle, m_surfaceGroup); |
| 296 |
VP_PUBLIC_CHK_NULL_RETURN(surfHandle->second); |
| 297 |
VP_PUBLIC_CHK_NULL_RETURN(surfHandle->second->osSurface); |
| 298 |
|
| 299 |
MHW_INDIRECT_STATE_RESOURCE_PARAMS params = {}; |
| 300 |
params.isWrite = surfaceParam.isOutput; |
| 301 |
params.resource = &surfHandle->second->osSurface->OsResource; |
| 302 |
params.stateOffset = arg.uOffsetInPayload; |
| 303 |
m_curbeResourceList.push_back(params); |
| 304 |
VP_RENDER_NORMALMESSAGE("Setting Stateless Curbe State KernelName %s, index %d , surfType %d, argKind %d", m_kernelName.c_str(), arg.uIndex, surfaceParam.surfType, arg.eArgKind); |
| 305 |
} |
| 306 |
else |
| 307 |
{ |
| 308 |
VP_RENDER_NORMALMESSAGE("KernelName %s, index %d, argKind %d is empty", m_kernelName.c_str(), arg.uIndex, arg.eArgKind); |
| 309 |
} |
| 310 |
} |
| 311 |
else |
| 312 |
{ |
| 313 |
VP_RENDER_NORMALMESSAGE("KernelName %s, index %d, argKind %d will is BTI surface", m_kernelName.c_str(), arg.uIndex, arg.eArgKind); |
| 314 |
} |
| 315 |
break; |
| 316 |
case ARG_KIND_INLINE: |
| 317 |
break; |
| 318 |
case ARG_KIND_SAMPLER: |
| 319 |
if (arg.addressMode == AddressingModeBindless) |
| 320 |
{ |
| 321 |
VP_RENDER_CHK_NULL_RETURN(arg.pData); |
| 322 |
uint32_t samplerIndex = (*(uint32_t *)arg.pData == MHW_SAMPLER_FILTER_NEAREST) ? AI_BINDLESS_NEAREST_SAMPLER_INDEX : AI_BINDLESS_BILIEAR_SAMPLER_INDEX; |
| 323 |
VP_RENDER_CHK_STATUS_RETURN(SetBindlessSamplerToResourceList(arg, samplerIndex)); |
| 324 |
VP_RENDER_NORMALMESSAGE("Setting Curbe State Bindless Sampler KernelID %d, index %d, argKind %d", m_kernelId, arg.uIndex, arg.eArgKind); |
| 325 |
} |
| 326 |
break; |
| 327 |
default: |
| 328 |
VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
if (isLocalIdGeneratedByRuntime) |
| 333 |
{ |
| 334 |
VP_RENDER_CHK_STATUS_RETURN(SetPerThreadCurbe(pCurbe, m_curbeLocation.size, curbeLength, m_kernelPerThreadArgInfo, m_walkerParam.threadWidth, m_walkerParam.threadHeight, m_walkerParam.threadDepth)); |
| 335 |
} |
| 336 |
|
| 337 |
curbe = pCurbe; |
| 338 |
|
| 339 |
return MOS_STATUS_SUCCESS; |
| 340 |
} |
| 341 |
|
| 342 |
MOS_STATUS VpRenderAiKernel::GetKernelSurfaceParam(bool isBTI, SURFACE_PARAMS &surfParam, KERNEL_SURFACE_STATE_PARAM &kernelSurfaceParam) |
| 343 |
{ |
| 344 |
MOS_ZeroMemory(&kernelSurfaceParam, sizeof(KERNEL_SURFACE_STATE_PARAM)); |
| 345 |
kernelSurfaceParam.surfaceOverwriteParams.updatedRenderSurfaces = true; |
| 346 |
kernelSurfaceParam.surfaceOverwriteParams.bindedKernel = isBTI; |
| 347 |
PRENDERHAL_SURFACE_STATE_PARAMS pRenderSurfaceParams = &kernelSurfaceParam.surfaceOverwriteParams.renderSurfaceParams; |
| 348 |
pRenderSurfaceParams->bAVS = false; |
| 349 |
pRenderSurfaceParams->Boundary = RENDERHAL_SS_BOUNDARY_ORIGINAL; |
| 350 |
pRenderSurfaceParams->b2PlaneNV12NeededByKernel = true; |
| 351 |
pRenderSurfaceParams->forceCommonSurfaceMessage = true; |
| 352 |
MOS_HW_RESOURCE_DEF resourceType = MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER; |
| 353 |
SurfaceType surfType = surfParam.surfType; |
| 354 |
|
| 355 |
if (surfParam.combineChannelY) |
| 356 |
{ |
| 357 |
pRenderSurfaceParams->combineChannelY = true; |
| 358 |
} |
| 359 |
pRenderSurfaceParams->isOutput = surfParam.isOutput; |
| 360 |
pRenderSurfaceParams->usePackedPlanar = surfParam.usePackedPlanar; |
| 361 |
|
| 362 |
auto surf = m_surfaceGroup->find(surfType); |
| 363 |
if (m_surfaceGroup->end() == surf) |
| 364 |
{ |
| 365 |
VP_RENDER_ASSERTMESSAGE("surf was not found %d", surfType); |
| 366 |
VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_NULL_POINTER); |
| 367 |
} |
| 368 |
VP_RENDER_CHK_NULL_RETURN(surf->second); |
| 369 |
VP_RENDER_CHK_NULL_RETURN(surf->second->osSurface); |
| 370 |
|
| 371 |
pRenderSurfaceParams->MemObjCtl = (m_renderHal->pOsInterface->pfnCachePolicyGetMemoryObject( |
| 372 |
resourceType, |
| 373 |
m_renderHal->pOsInterface->pfnGetGmmClientContext(m_renderHal->pOsInterface))) |
| 374 |
.DwordValue; |
| 375 |
pRenderSurfaceParams->Component = COMPONENT_VPCommon; |
| 376 |
|
| 377 |
if (surfParam.needVerticalStirde) |
| 378 |
{ |
| 379 |
switch (surf->second->SampleType) |
| 380 |
{ |
| 381 |
case SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD: |
| 382 |
case SAMPLE_INTERLEAVED_ODD_FIRST_TOP_FIELD: |
| 383 |
pRenderSurfaceParams->bVertStride = true; |
| 384 |
pRenderSurfaceParams->bVertStrideOffs = 0; |
| 385 |
break; |
| 386 |
case SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD: |
| 387 |
case SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD: |
| 388 |
pRenderSurfaceParams->bVertStride = true; |
| 389 |
pRenderSurfaceParams->bVertStrideOffs = 1; |
| 390 |
break; |
| 391 |
default: |
| 392 |
pRenderSurfaceParams->bVertStride = false; |
| 393 |
pRenderSurfaceParams->bVertStrideOffs = 0; |
| 394 |
break; |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
if (surf->second->osSurface->Format == Format_Buffer || surf->second->osSurface->Format == Format_RAW) |
| 399 |
{ |
| 400 |
kernelSurfaceParam.surfaceOverwriteParams.updatedSurfaceParams = true; |
| 401 |
kernelSurfaceParam.surfaceOverwriteParams.bufferResource = true; |
| 402 |
} |
| 403 |
|
| 404 |
return MOS_STATUS_SUCCESS; |
| 405 |
} |
| 406 |
|
| 407 |
MOS_STATUS VpRenderAiKernel::SetupSurfaceState() |
| 408 |
{ |
| 409 |
VP_FUNC_CALL(); |
| 410 |
|
| 411 |
KERNEL_SURFACE_STATE_PARAM kernelSurfaceParam; |
| 412 |
m_surfaceState.clear(); |
| 413 |
for (auto it = m_kernelBtis.begin(); it != m_kernelBtis.end(); ++it) |
| 414 |
{ |
| 415 |
uint32_t argIndex = it->first; |
| 416 |
uint32_t bti = it->second; |
| 417 |
VP_RENDER_NORMALMESSAGE("Setting Surface State for AI Kernel. KernelName %s, layer %d, argIndex %d , bti %d", m_kernelName.c_str(), m_kernelIndex, argIndex, bti); |
| 418 |
|
| 419 |
auto surfHandle = m_argIndexSurfMap.find(argIndex); |
| 420 |
VP_PUBLIC_CHK_NOT_FOUND_RETURN(surfHandle, &m_argIndexSurfMap); |
| 421 |
SURFACE_PARAMS &surfParam = surfHandle->second; |
| 422 |
SurfaceType surfType = surfParam.surfType; |
| 423 |
|
| 424 |
if (surfType == SurfaceTypeSubPlane || surfType == SurfaceTypeInvalid) |
| 425 |
{ |
| 426 |
VP_RENDER_NORMALMESSAGE("Will skip surface argIndex %d, bti %d for its surf type is set as %d", argIndex, bti, surfType); |
| 427 |
continue; |
| 428 |
} |
| 429 |
|
| 430 |
if (m_surfaceState.find(surfType) != m_surfaceState.end()) |
| 431 |
{ |
| 432 |
UpdateCurbeBindingIndex(surfType, bti); |
| 433 |
continue; |
| 434 |
} |
| 435 |
|
| 436 |
VP_PUBLIC_CHK_STATUS_RETURN(GetKernelSurfaceParam(true, surfParam, kernelSurfaceParam)); |
| 437 |
|
| 438 |
m_surfaceState.insert(std::make_pair(surfType, kernelSurfaceParam)); |
| 439 |
|
| 440 |
UpdateCurbeBindingIndex(surfType, bti); |
| 441 |
} |
| 442 |
|
| 443 |
for (auto &handle : m_kernelArgs) |
| 444 |
{ |
| 445 |
KRN_ARG &arg = handle.second; |
| 446 |
|
| 447 |
if (arg.addressMode != AddressingModeBindless || arg.eArgKind != ARG_KIND_SURFACE) |
| 448 |
{ |
| 449 |
continue; |
| 450 |
} |
| 451 |
uint32_t argIndex = arg.uIndex; |
| 452 |
auto surfHandle = m_argIndexSurfMap.find(argIndex); |
| 453 |
VP_PUBLIC_CHK_NOT_FOUND_RETURN(surfHandle, &m_argIndexSurfMap); |
| 454 |
SURFACE_PARAMS &surfParam = surfHandle->second; |
| 455 |
SurfaceType surfType = surfParam.surfType; |
| 456 |
if (surfParam.planeIndex != 0 || surfType == SurfaceTypeSubPlane || surfType == SurfaceTypeInvalid) |
| 457 |
{ |
| 458 |
VP_RENDER_NORMALMESSAGE("Will skip bindless surface argIndex %d for its planeIndex is set as %d, surfType %d", argIndex, surfParam.planeIndex, surfType); |
| 459 |
continue; |
| 460 |
} |
| 461 |
if (m_surfaceState.find(surfType) != m_surfaceState.end()) |
| 462 |
{ |
| 463 |
continue; |
| 464 |
} |
| 465 |
|
| 466 |
VP_PUBLIC_CHK_STATUS_RETURN(GetKernelSurfaceParam(false, surfParam, kernelSurfaceParam)); |
| 467 |
|
| 468 |
m_surfaceState.insert(std::make_pair(surfType, kernelSurfaceParam)); |
| 469 |
} |
| 470 |
|
| 471 |
return MOS_STATUS_SUCCESS; |
| 472 |
} |
| 473 |
|
| 474 |
MOS_STATUS VpRenderAiKernel::GetInlineData(uint8_t *inlineData) |
| 475 |
{ |
| 476 |
for (auto &handle : m_kernelArgs) |
| 477 |
{ |
| 478 |
KRN_ARG &arg = handle.second; |
| 479 |
if (arg.eArgKind == ARG_KIND_INLINE) |
| 480 |
{ |
| 481 |
if (arg.addressMode == AddressingModeStateless) |
| 482 |
{ |
| 483 |
if (arg.pData != nullptr) |
| 484 |
{ |
| 485 |
VP_PUBLIC_CHK_NULL_RETURN(m_surfaceGroup); |
| 486 |
SURFACE_PARAMS surfParam = *((SURFACE_PARAMS *)arg.pData); |
| 487 |
auto it = m_surfaceGroup->find(surfParam.surfType); |
| 488 |
VP_PUBLIC_CHK_NOT_FOUND_RETURN(it, m_surfaceGroup); |
| 489 |
PVP_SURFACE surface = it->second; |
| 490 |
VP_PUBLIC_CHK_NULL_RETURN(surface); |
| 491 |
VP_PUBLIC_CHK_NULL_RETURN(surface->osSurface); |
| 492 |
|
| 493 |
MHW_INDIRECT_STATE_RESOURCE_PARAMS params = {}; |
| 494 |
params.isWrite = surfParam.isOutput; |
| 495 |
params.resource = &surface->osSurface->OsResource; |
| 496 |
params.stateOffset = arg.uOffsetInPayload; |
| 497 |
m_inlineResourceList.push_back(params); |
| 498 |
VP_RENDER_NORMALMESSAGE("Setting Stateless Inline Data Statelss Surface KernelID %d, index %d , surfType %d, argKind %d", m_kernelId, arg.uIndex, *(uint32_t *)arg.pData, arg.eArgKind); |
| 499 |
} |
| 500 |
else |
| 501 |
{ |
| 502 |
VP_RENDER_ASSERTMESSAGE("KernelID %d, index %d, argKind %d Stateless Surface is empty", m_kernelId, arg.uIndex, arg.eArgKind); |
| 503 |
} |
| 504 |
} |
| 505 |
else |
| 506 |
{ |
| 507 |
VP_PUBLIC_CHK_STATUS_RETURN(SetInlineDataParameter(arg, inlineData)); |
| 508 |
} |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
return MOS_STATUS_SUCCESS; |
| 513 |
} |
| 514 |
|
| 515 |
MOS_STATUS VpRenderAiKernel::GetWalkerSetting(KERNEL_WALKER_PARAMS &walkerParam, KERNEL_PACKET_RENDER_DATA &renderData) |
| 516 |
{ |
| 517 |
VP_FUNC_CALL(); |
| 518 |
|
| 519 |
if (m_renderHal && m_renderHal->isBindlessHeapInUse) |
| 520 |
{ |
| 521 |
VP_PUBLIC_CHK_STATUS_RETURN(GetInlineData(m_inlineData.data())); |
| 522 |
} |
| 523 |
|
| 524 |
walkerParam = m_walkerParam; |
| 525 |
|
| 526 |
walkerParam.iBindingTable = renderData.bindingTable; |
| 527 |
walkerParam.iMediaID = renderData.mediaID; |
| 528 |
walkerParam.iCurbeOffset = renderData.iCurbeOffset; |
| 529 |
// Should use renderData.iCurbeLength instead of kernelSettings.CURBE_Length. |
| 530 |
// kernelSettings.CURBE_Length is 32 aligned with 5 bits shift. |
| 531 |
// renderData.iCurbeLength is RENDERHAL_CURBE_BLOCK_ALIGN(64) aligned. |
| 532 |
walkerParam.iCurbeLength = renderData.iCurbeLength; |
| 533 |
|
| 534 |
walkerParam.curbeResourceList = m_curbeResourceList.data(); |
| 535 |
walkerParam.curbeResourceListSize = m_curbeResourceList.size(); |
| 536 |
walkerParam.inlineResourceList = m_inlineResourceList.data(); |
| 537 |
walkerParam.inlineResourceListSize = m_inlineResourceList.size(); |
| 538 |
|
| 539 |
return MOS_STATUS_SUCCESS; |
| 540 |
} |
| 541 |
|
| 542 |
// Only for Adv kernels. |
| 543 |
MOS_STATUS VpRenderAiKernel::SetWalkerSetting(KERNEL_THREAD_SPACE &threadSpace, bool bSyncFlag, bool flushL1) |
| 544 |
{ |
| 545 |
VP_FUNC_CALL(); |
| 546 |
MOS_ZeroMemory(&m_walkerParam, sizeof(KERNEL_WALKER_PARAMS)); |
| 547 |
|
| 548 |
m_walkerParam.iBlocksX = threadSpace.uWidth; |
| 549 |
m_walkerParam.iBlocksY = threadSpace.uHeight; |
| 550 |
m_walkerParam.iBlocksZ = threadSpace.uDepth; |
| 551 |
m_walkerParam.threadWidth = threadSpace.uLocalWidth; |
| 552 |
m_walkerParam.threadHeight = threadSpace.uLocalHeight; |
| 553 |
m_walkerParam.threadDepth = 1; |
| 554 |
m_walkerParam.isVerticalPattern = false; |
| 555 |
m_walkerParam.bSyncFlag = bSyncFlag; |
| 556 |
m_walkerParam.simdSize = m_kernelEnv.uSimdSize; |
| 557 |
|
| 558 |
m_walkerParam.pipeControlParams.bUpdateNeeded = true; |
| 559 |
m_walkerParam.pipeControlParams.bEnableDataPortFlush = true; |
| 560 |
m_walkerParam.pipeControlParams.bUnTypedDataPortCacheFlush = true; |
| 561 |
m_walkerParam.pipeControlParams.bFlushRenderTargetCache = false; |
| 562 |
m_walkerParam.pipeControlParams.bInvalidateTextureCache = false; |
| 563 |
|
| 564 |
if (m_renderHal == nullptr || m_renderHal->isBindlessHeapInUse == false) |
| 565 |
{ |
| 566 |
VP_PUBLIC_CHK_STATUS_RETURN(GetInlineData(m_inlineData.data())); |
| 567 |
} |
| 568 |
m_walkerParam.inlineDataLength = m_inlineData.size(); |
| 569 |
m_walkerParam.inlineData = m_inlineData.data(); |
| 570 |
|
| 571 |
m_walkerParam.slmSize = m_kernelEnv.uiSlmSize; |
| 572 |
m_walkerParam.hasBarrier = (m_kernelEnv.uBarrierCount > 0); |
| 573 |
|
| 574 |
m_walkerParam.isEmitInlineParameter = m_kernelEnv.uInlineDataPayloadSize > 0; |
| 575 |
|
| 576 |
if (m_kernelEnv.uSimdSize != 1 && m_kernelPerThreadArgInfo.localIdSize > 0) |
| 577 |
{ |
| 578 |
if (m_kernelEnv.bHasDPAS) |
| 579 |
{ |
| 580 |
m_walkerParam.isGenerateLocalID = false; |
| 581 |
m_walkerParam.emitLocal = MHW_EMIT_LOCAL_NONE; |
| 582 |
} |
| 583 |
else |
| 584 |
{ |
| 585 |
m_walkerParam.isGenerateLocalID = true; |
| 586 |
m_walkerParam.emitLocal = MHW_EMIT_LOCAL_XYZ; |
| 587 |
} |
| 588 |
} |
| 589 |
m_walkerParam.registersPerThread = m_kernelEnv.uGrfCount; |
| 590 |
|
| 591 |
return MOS_STATUS_SUCCESS; |
| 592 |
} |
| 593 |
|
| 594 |
MOS_STATUS VpRenderAiKernel::SetKernelConfigs(KERNEL_CONFIGS &kernelConfigs) |
| 595 |
{ |
| 596 |
VP_FUNC_CALL(); |
| 597 |
|
| 598 |
auto handle = kernelConfigs.find(m_kernelId); |
| 599 |
VP_PUBLIC_CHK_NOT_FOUND_RETURN(handle, &kernelConfigs); |
| 600 |
|
| 601 |
AI_KERNEL_CONFIG *kernelConfig = (AI_KERNEL_CONFIG *)handle->second; |
| 602 |
VP_PUBLIC_CHK_NULL_RETURN(kernelConfig); |
| 603 |
|
| 604 |
m_kernelConfig = *kernelConfig; |
| 605 |
|
| 606 |
return MOS_STATUS_SUCCESS; |
| 607 |
} |
| 608 |
|
| 609 |
MOS_STATUS VpRenderAiKernel::SetPerfTag() |
| 610 |
{ |
| 611 |
auto pOsInterface = m_hwInterface->m_osInterface; |
| 612 |
VP_RENDER_CHK_NULL_RETURN(pOsInterface); |
| 613 |
VP_RENDER_CHK_NULL_RETURN(pOsInterface->pfnSetPerfTag); |
| 614 |
|
| 615 |
pOsInterface->pfnSetPerfTag(pOsInterface, m_kernelConfig.perfTag); |
| 616 |
|
| 617 |
return MOS_STATUS_SUCCESS; |
| 618 |
} |
| 619 |
|
| 620 |
uint32_t VpRenderAiKernel::GetLargeGrfMode() |
| 621 |
{ |
| 622 |
if (m_kernelEnv.uGrfCount >= 256) |
| 623 |
{ |
| 624 |
return 1; |
| 625 |
} |
| 626 |
else |
| 627 |
{ |
| 628 |
return 0; |
| 629 |
} |
| 630 |
} |
| 631 |
|
| 632 |
void VpRenderAiKernel::OcaDumpKernelInfo(MOS_COMMAND_BUFFER &cmdBuffer, MOS_CONTEXT &mosContext) |
| 633 |
{ |
| 634 |
HalOcaInterfaceNext::DumpVpKernelInfo(cmdBuffer, (MOS_CONTEXT_HANDLE)&mosContext, m_kernelId, 0, nullptr, m_kernelConfig.featureType); |
| 635 |
} |