| 1 |
/* |
| 2 |
* Copyright (c) 2021-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 media_render_cmd_packet.h |
| 24 |
//! \brief Defines the interface for media render workload cmd packet |
| 25 |
//! \details The media cmd packet is dedicated for command buffer sequenece submit |
| 26 |
//! |
| 27 |
#ifndef __MEDIA_RENDER_CMD_PACKET_H__ |
| 28 |
#define __MEDIA_RENDER_CMD_PACKET_H__ |
| 29 |
|
| 30 |
#include <stdint.h> |
| 31 |
#include <set> |
| 32 |
#include "hal_kerneldll_next.h" |
| 33 |
#include "media_cmd_packet.h" |
| 34 |
#include "renderhal.h" |
| 35 |
|
| 36 |
class MediaFeatureManager; |
| 37 |
class MediaTask; |
| 38 |
class MhwCpInterface; |
| 39 |
|
| 40 |
#define RENDER_PACKET_CHK_NULL_RETURN(_ptr) \ |
| 41 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_HW, 0, _ptr) |
| 42 |
|
| 43 |
#define RENDER_PACKET_CHK_STATUS_RETURN(_stmt) \ |
| 44 |
MOS_CHK_STATUS_RETURN(MOS_COMPONENT_HW, 0, _stmt) |
| 45 |
|
| 46 |
#define RENDER_PACKET_CHK_STATUS_MESSAGE_RETURN(_stmt, _message, ...) \ |
| 47 |
MOS_CHK_STATUS_MESSAGE_RETURN(MOS_COMPONENT_HW, 0, _stmt, _message, ##__VA_ARGS__) |
| 48 |
|
| 49 |
#define RENDER_PACKET_ASSERTMESSAGE(_message, ...) \ |
| 50 |
MOS_ASSERTMESSAGE(MOS_COMPONENT_HW, 0, _message, ##__VA_ARGS__) |
| 51 |
|
| 52 |
#define RENDER_PACKET_WARNINGMESSAGE(_message, ...) \ |
| 53 |
MOS_WARNINGMESSAGE(MOS_COMPONENT_HW, 0, _message, ##__VA_ARGS__) |
| 54 |
|
| 55 |
#define RENDER_PACKET_NORMALMESSAGE(_message, ...) \ |
| 56 |
MOS_NORMALMESSAGE(MOS_COMPONENT_HW, 0, _message, ##__VA_ARGS__) |
| 57 |
|
| 58 |
#define RENDER_PACKET_VERBOSEMESSAGE(_message, ...) \ |
| 59 |
MOS_VERBOSEMESSAGE(MOS_COMPONENT_HW, 0, _message, ##__VA_ARGS__) |
| 60 |
|
| 61 |
#define RENDER_PACKET_ASSERT(_expr) \ |
| 62 |
MOS_ASSERT(MOS_COMPONENT_HW, 0, _expr) |
| 63 |
|
| 64 |
#define RENDER_PACKET_CHK_NULL_WITH_DESTROY_RETURN_VALUE(_ptr, destroyFunction) \ |
| 65 |
MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(MOS_COMPONENT_HW, 0, (nullptr == _ptr), destroyFunction, MOS_STATUS_NULL_POINTER, "error nullptr!") |
| 66 |
|
| 67 |
#define RENDER_PACKET_CHK_STATUS_WITH_DESTROY_RETURN_VALUE(_stmt, destroyFunction) \ |
| 68 |
{ \ |
| 69 |
MOS_STATUS sts = (MOS_STATUS)(_stmt); \ |
| 70 |
MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(MOS_COMPONENT_HW, 0, (MOS_STATUS_SUCCESS != sts), destroyFunction, sts, "error status!") \ |
| 71 |
} |
| 72 |
|
| 73 |
//! |
| 74 |
//! \brief Initialize MHW Kernel Param struct for loading Kernel |
| 75 |
//! |
| 76 |
#define INIT_MHW_KERNEL_PARAM(MhwKernelParam, _pKernelEntry) \ |
| 77 |
do \ |
| 78 |
{ \ |
| 79 |
MOS_ZeroMemory(&(MhwKernelParam), sizeof(MhwKernelParam)); \ |
| 80 |
(MhwKernelParam).pBinary = (_pKernelEntry)->pBinary; \ |
| 81 |
(MhwKernelParam).iSize = (_pKernelEntry)->iSize; \ |
| 82 |
(MhwKernelParam).iKUID = (_pKernelEntry)->iKUID; \ |
| 83 |
(MhwKernelParam).iKCID = (_pKernelEntry)->iKCID; \ |
| 84 |
(MhwKernelParam).iPaddingSize = (_pKernelEntry)->iPaddingSize; \ |
| 85 |
} while(0) |
| 86 |
|
| 87 |
typedef struct _PIPECONTRL_PARAMS |
| 88 |
{ |
| 89 |
bool bUpdateNeeded; |
| 90 |
bool bEnableDataPortFlush; |
| 91 |
bool bUnTypedDataPortCacheFlush; |
| 92 |
bool bFlushRenderTargetCache; |
| 93 |
bool bInvalidateTextureCache; |
| 94 |
} PIPECONTRL_PARAMS, *PPIPECONTRL_PARAMS; |
| 95 |
|
| 96 |
typedef struct _KERNEL_WALKER_PARAMS |
| 97 |
{ |
| 98 |
int32_t iBindingTable; |
| 99 |
int32_t iMediaID; |
| 100 |
int32_t iCurbeOffset; |
| 101 |
int32_t iCurbeLength; |
| 102 |
|
| 103 |
int32_t iBlocksX; |
| 104 |
int32_t iBlocksY; |
| 105 |
int32_t iBlocksZ; |
| 106 |
RECT alignedRect; |
| 107 |
PIPECONTRL_PARAMS pipeControlParams; |
| 108 |
bool isVerticalPattern; |
| 109 |
bool bSyncFlag; |
| 110 |
bool bFlushL1; |
| 111 |
bool isGroupStartInvolvedInGroupSize; // true if group start need be involved in the group size. |
| 112 |
bool calculateBlockXYByAlignedRect; // true if iBlocksX/iBlocksY is calculated by alignedRect in RenderCmdPacket instead of kernel object. |
| 113 |
bool forcePreferredSLMZero; // true if preferredSLM need force to 0. |
| 114 |
|
| 115 |
bool isEmitInlineParameter; |
| 116 |
uint32_t inlineDataLength; |
| 117 |
uint8_t* inlineData; |
| 118 |
|
| 119 |
uint32_t threadWidth; |
| 120 |
uint32_t threadHeight; |
| 121 |
uint32_t threadDepth; |
| 122 |
|
| 123 |
bool isGenerateLocalID; |
| 124 |
MHW_EMIT_LOCAL_MODE emitLocal; |
| 125 |
|
| 126 |
bool hasBarrier; |
| 127 |
uint32_t slmSize; |
| 128 |
|
| 129 |
uint32_t simdSize; |
| 130 |
|
| 131 |
uint32_t registersPerThread; |
| 132 |
|
| 133 |
PMHW_INDIRECT_STATE_RESOURCE_PARAMS curbeResourceList; |
| 134 |
uint32_t curbeResourceListSize; |
| 135 |
|
| 136 |
PMHW_INDIRECT_STATE_RESOURCE_PARAMS inlineResourceList; |
| 137 |
uint32_t inlineResourceListSize; |
| 138 |
}KERNEL_WALKER_PARAMS, * PKERNEL_WALKER_PARAMS; |
| 139 |
|
| 140 |
typedef struct _KERNEL_PACKET_RENDER_DATA |
| 141 |
{ |
| 142 |
// Kernel Information |
| 143 |
RENDERHAL_KERNEL_PARAM KernelParam; |
| 144 |
Kdll_CacheEntry KernelEntry; |
| 145 |
int32_t iCurbeLength; |
| 146 |
int32_t iInlineLength; |
| 147 |
int32_t iCurbeOffset; |
| 148 |
|
| 149 |
MHW_SAMPLER_STATE_PARAM SamplerStateParams; //!< Sampler State |
| 150 |
PMHW_AVS_PARAMS pAVSParameters; //!< AVS parameters |
| 151 |
MHW_SAMPLER_AVS_TABLE_PARAM mhwSamplerAvsTableParam; //!< params for AVS scaling 8x8 table |
| 152 |
|
| 153 |
// Media render state |
| 154 |
PRENDERHAL_MEDIA_STATE mediaState; |
| 155 |
|
| 156 |
int32_t bindingTable; |
| 157 |
uint32_t bindingTableEntry; |
| 158 |
int32_t mediaID; |
| 159 |
|
| 160 |
KERNEL_WALKER_PARAMS walkerParam; |
| 161 |
PMHW_VFE_SCOREBOARD scoreboardParams; |
| 162 |
|
| 163 |
int32_t kernelAllocationID; |
| 164 |
|
| 165 |
// Debug parameters |
| 166 |
// Kernel Used for current rendering |
| 167 |
char* pKernelName; |
| 168 |
} KERNEL_PACKET_RENDER_DATA, * PKERNEL_PACKET_RENDER_DATA; |
| 169 |
|
| 170 |
typedef enum _WALKER_TYPE |
| 171 |
{ |
| 172 |
WALKER_TYPE_DISABLED = 0, |
| 173 |
WALKER_TYPE_MEDIA, |
| 174 |
WALKER_TYPE_COMPUTE |
| 175 |
}WALKER_TYPE; |
| 176 |
|
| 177 |
//! |
| 178 |
//! \brief VPHAL SS/EU setting |
| 179 |
//! |
| 180 |
struct SseuSetting |
| 181 |
{ |
| 182 |
uint8_t numSlices; |
| 183 |
uint8_t numSubSlices; |
| 184 |
uint8_t numEUs; |
| 185 |
uint8_t reserved; // Place holder for frequency setting |
| 186 |
}; |
| 187 |
|
| 188 |
typedef struct _RENDERHAL_SURFACE_NEXT : public _RENDERHAL_SURFACE |
| 189 |
{ |
| 190 |
uint32_t Index; |
| 191 |
}RENDERHAL_SURFACE_NEXT, * PRENDERHAL_SURFACE_NEXT; |
| 192 |
|
| 193 |
using KERNEL_RENDER_DATA = std::map<uint32_t, KERNEL_PACKET_RENDER_DATA>; |
| 194 |
|
| 195 |
class RenderCmdPacket : virtual public CmdPacket, public mhw::mi::Itf::ParSetting |
| 196 |
{ |
| 197 |
public: |
| 198 |
RenderCmdPacket(MediaTask* task, PMOS_INTERFACE pOsInterface, RENDERHAL_INTERFACE* m_renderHal); |
| 199 |
|
| 200 |
virtual ~RenderCmdPacket(); |
| 201 |
virtual MOS_STATUS Init(); |
| 202 |
virtual MOS_STATUS Destroy(); |
| 203 |
virtual MOS_STATUS Submit(MOS_COMMAND_BUFFER* commandBuffer, uint8_t packetPhase = otherPacket); |
| 204 |
|
| 205 |
// Currently only support HDC read/write, for sampler enabling will be in next step |
| 206 |
// Step1 : render engine set up |
| 207 |
MOS_STATUS RenderEngineSetup(); |
| 208 |
|
| 209 |
// Step2: Kernel State Set up |
| 210 |
virtual MOS_STATUS KernelStateSetup( |
| 211 |
void *kernel) |
| 212 |
{ |
| 213 |
return MOS_STATUS_SUCCESS; |
| 214 |
} |
| 215 |
|
| 216 |
virtual uint32_t SetSurfaceForHwAccess( |
| 217 |
PMOS_SURFACE surface, |
| 218 |
PRENDERHAL_SURFACE_NEXT pRenderSurface, |
| 219 |
PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, |
| 220 |
bool bWrite, |
| 221 |
std::vector<RENDERHAL_STATE_LOCATION> &stateLocations); |
| 222 |
|
| 223 |
// Step3: RSS Setup, return index insert in binding table |
| 224 |
virtual uint32_t SetSurfaceForHwAccess( |
| 225 |
PMOS_SURFACE surface, |
| 226 |
PRENDERHAL_SURFACE_NEXT pRenderSurface, |
| 227 |
PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, |
| 228 |
bool bWrite); |
| 229 |
|
| 230 |
// Step3: RSS Setup with fixed binding index, return index insert in binding table |
| 231 |
virtual MOS_STATUS SetSurfaceForHwAccess( |
| 232 |
PMOS_SURFACE surface, |
| 233 |
PRENDERHAL_SURFACE_NEXT pRenderSurface, |
| 234 |
PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, |
| 235 |
uint32_t &bindingIndex, |
| 236 |
bool bWrite, |
| 237 |
PRENDERHAL_SURFACE_STATE_ENTRY *surfaceEntries = nullptr, |
| 238 |
uint32_t * numOfSurfaceEntries = nullptr); |
| 239 |
|
| 240 |
virtual MOS_STATUS SetSurfaceForHwAccess( |
| 241 |
PMOS_SURFACE surface, |
| 242 |
PRENDERHAL_SURFACE_NEXT pRenderSurface, |
| 243 |
PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, |
| 244 |
std::set<uint32_t> &bindingIndexes, |
| 245 |
bool bWrite, |
| 246 |
std::vector<RENDERHAL_STATE_LOCATION> &stateLocations, |
| 247 |
uint32_t capcityOfSurfaceEntries = 0, |
| 248 |
PRENDERHAL_SURFACE_STATE_ENTRY *surfaceEntries = nullptr, |
| 249 |
uint32_t *numOfSurfaceEntries = nullptr); |
| 250 |
|
| 251 |
virtual uint32_t SetBufferForHwAccess( |
| 252 |
PMOS_SURFACE buffer, |
| 253 |
PRENDERHAL_SURFACE_NEXT pRenderSurface, |
| 254 |
PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, |
| 255 |
bool bWrite, |
| 256 |
std::vector<RENDERHAL_STATE_LOCATION> &stateLocations); |
| 257 |
|
| 258 |
virtual uint32_t SetBufferForHwAccess( |
| 259 |
PMOS_SURFACE buffer, |
| 260 |
PRENDERHAL_SURFACE_NEXT pRenderSurface, |
| 261 |
PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, |
| 262 |
uint32_t bindingIndex, |
| 263 |
bool bWrite); |
| 264 |
|
| 265 |
virtual MOS_STATUS SetBufferForHwAccess( |
| 266 |
PMOS_SURFACE buffer, |
| 267 |
PRENDERHAL_SURFACE_NEXT pRenderSurface, |
| 268 |
PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, |
| 269 |
std::set<uint32_t> &bindingIndexes, |
| 270 |
bool bWrite, |
| 271 |
std::vector<RENDERHAL_STATE_LOCATION> &stateLocations); |
| 272 |
|
| 273 |
virtual uint32_t SetBufferForHwAccess( |
| 274 |
MOS_BUFFER buffer, |
| 275 |
PRENDERHAL_SURFACE_NEXT pRenderSurface, |
| 276 |
PRENDERHAL_SURFACE_STATE_PARAMS pSurfaceParams, |
| 277 |
bool bWrite); |
| 278 |
|
| 279 |
// Step4: Packet to prepare the curbe data Setup, then call packet to set it up |
| 280 |
// PData point to the Curbe prepared by packet |
| 281 |
MOS_STATUS SetupCurbe( |
| 282 |
void * pData, |
| 283 |
uint32_t curbeLength, |
| 284 |
uint32_t maximumNumberofThreads = 0); |
| 285 |
|
| 286 |
// Step6: different kernel have different media walker settings |
| 287 |
virtual MOS_STATUS SetupMediaWalker() |
| 288 |
{ |
| 289 |
return MOS_STATUS_SUCCESS; |
| 290 |
} |
| 291 |
|
| 292 |
MOS_STATUS PrepareMediaWalkerParams(KERNEL_WALKER_PARAMS params, MHW_WALKER_PARAMS &mediaWalker); |
| 293 |
|
| 294 |
MOS_STATUS PrepareComputeWalkerParams(KERNEL_WALKER_PARAMS params, MHW_GPGPU_WALKER_PARAMS &gpgpuWalker); |
| 295 |
|
| 296 |
bool m_isMultiBindingTables = false; |
| 297 |
|
| 298 |
bool m_isLargeSurfaceStateNeeded = false; |
| 299 |
|
| 300 |
bool m_isMultiKernelOneMediaState = false; |
| 301 |
|
| 302 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 303 |
virtual MOS_STATUS StallBatchBuffer( |
| 304 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 305 |
{ |
| 306 |
return MOS_STATUS_SUCCESS; |
| 307 |
} |
| 308 |
#endif |
| 309 |
|
| 310 |
protected: |
| 311 |
// Step5: Load Kernel |
| 312 |
virtual MOS_STATUS LoadKernel(); |
| 313 |
|
| 314 |
// for VPP usage, there are more data need to updated, create as virtual for future inplemention in VPP |
| 315 |
virtual MOS_STATUS InitRenderHalSurface( |
| 316 |
MOS_SURFACE surface, |
| 317 |
PRENDERHAL_SURFACE pRenderSurface); |
| 318 |
|
| 319 |
virtual MOS_STATUS InitRenderHalBuffer( |
| 320 |
MOS_BUFFER surface, |
| 321 |
PRENDERHAL_SURFACE pRenderSurface); |
| 322 |
|
| 323 |
virtual void OcaDumpDbgInfo(MOS_COMMAND_BUFFER &cmdBuffer, MOS_CONTEXT &mosContext) |
| 324 |
{ |
| 325 |
} |
| 326 |
|
| 327 |
virtual MOS_STATUS SetMediaFrameTracking(RENDERHAL_GENERIC_PROLOG_PARAMS &genericPrologParams) |
| 328 |
{ |
| 329 |
return MOS_STATUS_SUCCESS; |
| 330 |
} |
| 331 |
|
| 332 |
MOS_STATUS InitKernelEntry(); |
| 333 |
|
| 334 |
MOS_STATUS SetPowerMode( |
| 335 |
uint32_t KernelID); |
| 336 |
|
| 337 |
bool IsMiBBEndNeeded( |
| 338 |
PMOS_INTERFACE pOsInterface) |
| 339 |
{ |
| 340 |
// need to be remodify |
| 341 |
bool needed = true; |
| 342 |
|
| 343 |
return needed; |
| 344 |
} |
| 345 |
|
| 346 |
void ResetBindingTableEntry() |
| 347 |
{ |
| 348 |
m_renderData.bindingTableEntry = 0; |
| 349 |
} |
| 350 |
|
| 351 |
virtual void UpdateKernelConfigParam(RENDERHAL_KERNEL_PARAM &kernelParam); |
| 352 |
|
| 353 |
MOS_STATUS SendMultiKernelMediaStates(PRENDERHAL_INTERFACE pRenderHal, PMOS_COMMAND_BUFFER pCmdBuffer); |
| 354 |
|
| 355 |
protected: |
| 356 |
PRENDERHAL_INTERFACE m_renderHal = nullptr; |
| 357 |
MhwCpInterface* m_cpInterface = nullptr; |
| 358 |
MediaFeatureManager* m_featureManager = nullptr; |
| 359 |
|
| 360 |
// Perf |
| 361 |
VPHAL_PERFTAG PerfTag = VPHAL_NONE; // need to check the perf setting in codec |
| 362 |
|
| 363 |
// Kernel Render Data |
| 364 |
uint32_t m_kernelCount = 0; |
| 365 |
|
| 366 |
// Kernel Render Data |
| 367 |
KERNEL_PACKET_RENDER_DATA m_renderData = {}; |
| 368 |
|
| 369 |
// object walker: media walker/compute walker |
| 370 |
WALKER_TYPE m_walkerType = WALKER_TYPE_DISABLED; |
| 371 |
|
| 372 |
MHW_WALKER_PARAMS m_mediaWalkerParams = {}; |
| 373 |
|
| 374 |
MHW_GPGPU_WALKER_PARAMS m_gpgpuWalkerParams = {}; |
| 375 |
|
| 376 |
PMHW_BATCH_BUFFER pBatchBuffer = nullptr; |
| 377 |
|
| 378 |
MHW_PIPE_CONTROL_PARAMS m_pipeCtlParams = {}; |
| 379 |
|
| 380 |
MHW_MEDIA_STATE_FLUSH_PARAM m_flushParam = {}; |
| 381 |
uint32_t m_flushMode = 0; |
| 382 |
PMOS_RESOURCE m_presDest = nullptr; |
| 383 |
uint32_t m_postSyncOp = 0; |
| 384 |
uint32_t m_resourceOffset = 0; |
| 385 |
uint32_t m_dataDW1 = 0; |
| 386 |
uint32_t m_dataDW2 = 0; |
| 387 |
uint32_t m_genericMediaStateClear : 1; |
| 388 |
uint32_t m_IndirectStatePointersDisable : 1; |
| 389 |
uint32_t m_disableCSStall : 1; |
| 390 |
uint32_t m_bInvalidateTextureCache : 1; |
| 391 |
uint32_t m_bFlushRenderTargetCache : 1; |
| 392 |
uint32_t m_bInvalidateStateCache : 1; |
| 393 |
uint32_t m_bInvalidateConstantCache : 1; |
| 394 |
uint32_t m_bInvalidateVFECache : 1; |
| 395 |
uint32_t m_bInvalidateInstructionCache : 1; |
| 396 |
uint32_t m_bTlbInvalidate : 1; |
| 397 |
uint32_t m_bHdcPipelineFlush : 1; |
| 398 |
uint32_t m_bKernelFenceEnabled : 1; |
| 399 |
bool m_bFlushToGo = true; |
| 400 |
uint8_t m_ui8InterfaceDescriptorOffset = 0; |
| 401 |
|
| 402 |
uint32_t m_slmSize = 0; |
| 403 |
KERNEL_RENDER_DATA m_kernelRenderData = {}; // Only for MULTI_KERNELS_WITH_ONE_MEDIA_STATE case. |
| 404 |
|
| 405 |
MEDIA_CLASS_DEFINE_END(RenderCmdPacket) |
| 406 |
}; |
| 407 |
#endif // __MEDIA_RENDER_CMD_PACKET_H__ |