| 1 |
/* |
| 2 |
* Copyright (c) 2019-2023, 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 mos_gpucontext_specific_next_xe.cpp |
| 24 |
//! \brief Container class for the Linux specific gpu context |
| 25 |
//! |
| 26 |
|
| 27 |
#include <unistd.h> |
| 28 |
#include "mos_gpucontext_specific_next_xe.h" |
| 29 |
#include "mos_context_specific_next.h" |
| 30 |
#include "mos_graphicsresource_specific_next.h" |
| 31 |
#include "mos_commandbuffer_specific_next.h" |
| 32 |
#include "mos_util_devult_specific_next.h" |
| 33 |
#include "mos_cmdbufmgr_next.h" |
| 34 |
#include "mos_os_virtualengine_next.h" |
| 35 |
#include "mos_interface.h" |
| 36 |
#include "mos_os_cp_interface_specific.h" |
| 37 |
|
| 38 |
#define MI_BATCHBUFFER_END 0x05000000 |
| 39 |
static pthread_mutex_t command_dump_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 40 |
|
| 41 |
|
| 42 |
GpuContextSpecificNextXe::~GpuContextSpecificNextXe() |
| 43 |
{ |
| 44 |
MOS_OS_FUNCTION_ENTER; |
| 45 |
} |
| 46 |
|
| 47 |
MOS_STATUS GpuContextSpecificNextXe::Init3DCtx(PMOS_CONTEXT osParameters, |
| 48 |
PMOS_GPUCTX_CREATOPTIONS createOption, |
| 49 |
unsigned int *nengine, |
| 50 |
void *engine_map) |
| 51 |
{ |
| 52 |
MOS_OS_FUNCTION_ENTER; |
| 53 |
|
| 54 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 55 |
|
| 56 |
__u16 engine_class = DRM_XE_ENGINE_CLASS_RENDER; |
| 57 |
__u64 caps = 0; |
| 58 |
uint8_t ctxWidth = 1; |
| 59 |
uint8_t numPlacement = 1; |
| 60 |
|
| 61 |
if (mos_query_engines(osParameters->bufmgr, engine_class, caps, nengine, engine_map)) |
| 62 |
{ |
| 63 |
MOS_OS_ASSERTMESSAGE("Failed to query engines."); |
| 64 |
return MOS_STATUS_UNKNOWN; |
| 65 |
} |
| 66 |
numPlacement = *nengine; |
| 67 |
|
| 68 |
m_i915Context[0] = mos_context_create_shared(osParameters->bufmgr, |
| 69 |
nullptr, //no need anymore, get vm_id from global |
| 70 |
0, |
| 71 |
m_bProtectedContext, // not support currently |
| 72 |
engine_map, |
| 73 |
ctxWidth, |
| 74 |
numPlacement, |
| 75 |
0); |
| 76 |
if (m_i915Context[0] == nullptr) |
| 77 |
{ |
| 78 |
MOS_OS_ASSERTMESSAGE("Failed to create context."); |
| 79 |
return MOS_STATUS_UNKNOWN; |
| 80 |
} |
| 81 |
m_i915Context[0]->pOsContext = osParameters; |
| 82 |
|
| 83 |
return eStatus; |
| 84 |
} |
| 85 |
|
| 86 |
MOS_STATUS GpuContextSpecificNextXe::InitComputeCtx(PMOS_CONTEXT osParameters, |
| 87 |
unsigned int *nengine, |
| 88 |
void *engine_map, |
| 89 |
MOS_GPU_NODE gpuNode, |
| 90 |
bool *isEngineSelectEnable) |
| 91 |
{ |
| 92 |
MOS_OS_FUNCTION_ENTER; |
| 93 |
|
| 94 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 95 |
|
| 96 |
__u16 engine_class = DRM_XE_ENGINE_CLASS_COMPUTE; |
| 97 |
__u64 caps = 0; |
| 98 |
uint8_t ctxWidth = 1; |
| 99 |
uint8_t numPlacement = 1; |
| 100 |
|
| 101 |
if (mos_query_engines(osParameters->bufmgr, engine_class, caps, nengine, engine_map)) |
| 102 |
{ |
| 103 |
MOS_OS_ASSERTMESSAGE("Failed to query engines."); |
| 104 |
return MOS_STATUS_UNKNOWN; |
| 105 |
} |
| 106 |
|
| 107 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 108 |
//Note: this debug function need to refine or override since different engine_map struct |
| 109 |
*isEngineSelectEnable = SelectEngineInstanceByUser(engine_map, nengine, m_engineInstanceSelect, gpuNode); |
| 110 |
#endif |
| 111 |
|
| 112 |
numPlacement = *nengine; |
| 113 |
m_i915Context[0] = mos_context_create_shared(osParameters->bufmgr, |
| 114 |
nullptr, |
| 115 |
0, |
| 116 |
m_bProtectedContext, |
| 117 |
engine_map, |
| 118 |
ctxWidth, |
| 119 |
numPlacement, |
| 120 |
0); |
| 121 |
if (m_i915Context[0] == nullptr) |
| 122 |
{ |
| 123 |
MOS_OS_ASSERTMESSAGE("Failed to create context."); |
| 124 |
return MOS_STATUS_UNKNOWN; |
| 125 |
} |
| 126 |
m_i915Context[0]->pOsContext = osParameters; |
| 127 |
|
| 128 |
return eStatus; |
| 129 |
} |
| 130 |
|
| 131 |
MOS_STATUS GpuContextSpecificNextXe::InitVdVeCtx(PMOS_CONTEXT osParameters, |
| 132 |
MOS_STREAM_HANDLE streamState, |
| 133 |
PMOS_GPUCTX_CREATOPTIONS createOption, |
| 134 |
unsigned int *nengine, |
| 135 |
void *engine_map, |
| 136 |
MOS_GPU_NODE gpuNode, |
| 137 |
bool *isEngineSelectEnable) |
| 138 |
{ |
| 139 |
MOS_OS_FUNCTION_ENTER; |
| 140 |
|
| 141 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 142 |
|
| 143 |
|
| 144 |
__u16 engine_class = (gpuNode == MOS_GPU_NODE_VE)? DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE : DRM_XE_ENGINE_CLASS_VIDEO_DECODE; |
| 145 |
__u64 caps = 0; |
| 146 |
uint8_t ctxWidth = 1; |
| 147 |
uint8_t numPlacement = 1; |
| 148 |
|
| 149 |
SetEngineQueryFlags(createOption, caps); |
| 150 |
|
| 151 |
if (mos_query_engines(osParameters->bufmgr, engine_class, caps, nengine, engine_map)) |
| 152 |
{ |
| 153 |
MOS_OS_ASSERTMESSAGE("Failed to query engines."); |
| 154 |
return MOS_STATUS_UNKNOWN; |
| 155 |
} |
| 156 |
|
| 157 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 158 |
*isEngineSelectEnable = SelectEngineInstanceByUser(engine_map, nengine, m_engineInstanceSelect, gpuNode); |
| 159 |
#endif |
| 160 |
|
| 161 |
numPlacement = *nengine; |
| 162 |
|
| 163 |
m_i915Context[0] = mos_context_create_shared(osParameters->bufmgr, |
| 164 |
nullptr, |
| 165 |
0, |
| 166 |
m_bProtectedContext, |
| 167 |
engine_map, |
| 168 |
ctxWidth, |
| 169 |
numPlacement, |
| 170 |
0); |
| 171 |
if (m_i915Context[0] == nullptr) |
| 172 |
{ |
| 173 |
MOS_OS_ASSERTMESSAGE("Failed to create context."); |
| 174 |
return MOS_STATUS_UNKNOWN; |
| 175 |
} |
| 176 |
|
| 177 |
m_i915Context[0]->pOsContext = osParameters; |
| 178 |
|
| 179 |
if (*nengine >= 2 && *nengine <= MAX_ENGINE_INSTANCE_NUM) |
| 180 |
{ |
| 181 |
//if ctxWidth > 1, numPlacement should always be 1 |
| 182 |
numPlacement = 1; |
| 183 |
streamState->bParallelSubmission = true; |
| 184 |
//create context with different width |
| 185 |
for(int i = 1; i < *nengine; i++) |
| 186 |
{ |
| 187 |
ctxWidth = i + 1; |
| 188 |
m_i915Context[i] = mos_context_create_shared(osParameters->bufmgr, |
| 189 |
nullptr, |
| 190 |
0, |
| 191 |
m_bProtectedContext, |
| 192 |
engine_map, |
| 193 |
ctxWidth, |
| 194 |
numPlacement, |
| 195 |
0); |
| 196 |
if (m_i915Context[i] == nullptr) |
| 197 |
{ |
| 198 |
MOS_OS_ASSERTMESSAGE("Failed to create context."); |
| 199 |
return MOS_STATUS_UNKNOWN; |
| 200 |
} |
| 201 |
m_i915Context[i]->pOsContext = osParameters; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
return eStatus; |
| 206 |
} |
| 207 |
|
| 208 |
MOS_STATUS GpuContextSpecificNextXe::InitBltCtx(PMOS_CONTEXT osParameters, |
| 209 |
unsigned int *nengine, |
| 210 |
void *engine_map) |
| 211 |
{ |
| 212 |
MOS_OS_FUNCTION_ENTER; |
| 213 |
|
| 214 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 215 |
|
| 216 |
__u16 engine_class = DRM_XE_ENGINE_CLASS_COPY; |
| 217 |
__u64 caps = 0; |
| 218 |
uint8_t ctxWidth = 1; |
| 219 |
uint8_t numPlacement = 1; |
| 220 |
|
| 221 |
if (mos_query_engines(osParameters->bufmgr, engine_class, caps, nengine, engine_map)) |
| 222 |
{ |
| 223 |
MOS_OS_ASSERTMESSAGE("Failed to query engines."); |
| 224 |
return MOS_STATUS_UNKNOWN; |
| 225 |
} |
| 226 |
numPlacement = *nengine; |
| 227 |
if (numPlacement >= 2) |
| 228 |
{ |
| 229 |
// only use BCS0. BCS8 is paging copy |
| 230 |
numPlacement = 1; |
| 231 |
} |
| 232 |
|
| 233 |
m_i915Context[0] = mos_context_create_shared(osParameters->bufmgr, |
| 234 |
nullptr, |
| 235 |
0, |
| 236 |
m_bProtectedContext, |
| 237 |
engine_map, |
| 238 |
ctxWidth, |
| 239 |
numPlacement, |
| 240 |
0); |
| 241 |
if (m_i915Context[0] == nullptr) |
| 242 |
{ |
| 243 |
MOS_OS_ASSERTMESSAGE("Failed to create context."); |
| 244 |
return MOS_STATUS_UNKNOWN; |
| 245 |
} |
| 246 |
m_i915Context[0]->pOsContext = osParameters; |
| 247 |
|
| 248 |
return eStatus; |
| 249 |
} |
| 250 |
|
| 251 |
MOS_STATUS GpuContextSpecificNextXe::PatchCommandBuffer( |
| 252 |
MOS_STREAM_HANDLE streamState, |
| 253 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 254 |
{ |
| 255 |
MOS_OS_FUNCTION_ENTER; |
| 256 |
|
| 257 |
auto perStreamParameters = (PMOS_CONTEXT)streamState->perStreamParameters; |
| 258 |
auto cmd_bo = cmdBuffer->OsResource.bo; |
| 259 |
std::vector<PMOS_RESOURCE> mappedResList; |
| 260 |
|
| 261 |
// Now, the patching will be done, based on the patch list. |
| 262 |
for (uint32_t patchIndex = 0; patchIndex < m_currentNumPatchLocations; patchIndex++) |
| 263 |
{ |
| 264 |
auto currentPatch = &m_patchLocationList[patchIndex]; |
| 265 |
MOS_OS_CHK_NULL_RETURN(currentPatch); |
| 266 |
|
| 267 |
/** |
| 268 |
* Indicate whether temCmdBo is cmdbuffer in vector of m_secondaryCmdBufs; |
| 269 |
* If yes, tempCmdBo is also a primary cmd bo for scalability; And in this case, we need to |
| 270 |
* update its execlist. |
| 271 |
* Otherwise if no and temCmdBo != cmdBuffer->OsResource.bo, it should be second level |
| 272 |
* batch buffer for primary cmdbuffer. And in this case, we should not update its execlist. |
| 273 |
*/ |
| 274 |
bool isSecondaryCmdBuf = false; |
| 275 |
auto tempCmdBo = currentPatch->cmdBo == nullptr ? cmd_bo : currentPatch->cmdBo; |
| 276 |
|
| 277 |
// Following are for Nested BB buffer, if it's nested BB, we need to ensure it's locked. |
| 278 |
if (tempCmdBo != cmd_bo) |
| 279 |
{ |
| 280 |
auto it = m_secondaryCmdBufs.begin(); |
| 281 |
while(it != m_secondaryCmdBufs.end()) |
| 282 |
{ |
| 283 |
if (it->second->OsResource.bo == tempCmdBo) |
| 284 |
{ |
| 285 |
isSecondaryCmdBuf = true; |
| 286 |
break; |
| 287 |
} |
| 288 |
it++; |
| 289 |
} |
| 290 |
|
| 291 |
for(auto allocIdx = 0; allocIdx < m_numAllocations && (!isSecondaryCmdBuf); allocIdx++) |
| 292 |
{ |
| 293 |
auto tempRes = (PMOS_RESOURCE)m_allocationList[allocIdx].hAllocation; |
| 294 |
if (tempCmdBo == tempRes->bo) |
| 295 |
{ |
| 296 |
GraphicsResourceNext::LockParams param; |
| 297 |
param.m_writeRequest = true; |
| 298 |
tempRes->pGfxResourceNext->Lock(m_osContext, param); |
| 299 |
mappedResList.push_back(tempRes); |
| 300 |
break; |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
// This is the resource for which patching will be done |
| 306 |
auto resource = (PMOS_RESOURCE)m_allocationList[currentPatch->AllocationIndex].hAllocation; |
| 307 |
MOS_OS_CHK_NULL_RETURN(resource); |
| 308 |
|
| 309 |
// For now, we'll assume the system memory's DRM bo pointer |
| 310 |
// is NULL. If nullptr is detected, then the resource has been |
| 311 |
// placed inside the command buffer's indirect state area. |
| 312 |
// We'll simply set alloc_bo to the command buffer's bo pointer. |
| 313 |
MOS_OS_ASSERT(resource->bo); |
| 314 |
|
| 315 |
auto alloc_bo = (resource->bo) ? resource->bo : tempCmdBo; |
| 316 |
|
| 317 |
MOS_OS_CHK_STATUS_RETURN(streamState->osCpInterface->PermeatePatchForHM( |
| 318 |
tempCmdBo->virt, |
| 319 |
currentPatch, |
| 320 |
resource)); |
| 321 |
|
| 322 |
uint64_t boOffset = alloc_bo->offset64; |
| 323 |
|
| 324 |
MOS_OS_CHK_NULL_RETURN(tempCmdBo->virt); |
| 325 |
|
| 326 |
if (perStreamParameters->bUse64BitRelocs) |
| 327 |
{ |
| 328 |
*((uint64_t *)((uint8_t *)tempCmdBo->virt + currentPatch->PatchOffset)) = |
| 329 |
boOffset + currentPatch->AllocationOffset; |
| 330 |
} |
| 331 |
else |
| 332 |
{ |
| 333 |
*((uint32_t *)((uint8_t *)tempCmdBo->virt + currentPatch->PatchOffset)) = |
| 334 |
boOffset + currentPatch->AllocationOffset; |
| 335 |
} |
| 336 |
|
| 337 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 338 |
{ |
| 339 |
uint32_t evtData[] = {alloc_bo->handle, currentPatch->uiWriteOperation, currentPatch->AllocationOffset}; |
| 340 |
MOS_TraceEventExt(EVENT_MOS_BATCH_SUBMIT, EVENT_TYPE_INFO, |
| 341 |
evtData, sizeof(evtData), |
| 342 |
&boOffset, sizeof(boOffset)); |
| 343 |
} |
| 344 |
#endif |
| 345 |
|
| 346 |
if(tempCmdBo != alloc_bo) |
| 347 |
{ |
| 348 |
// reuse this api to update exec list in cmd bo |
| 349 |
mos_bo_add_softpin_target(isSecondaryCmdBuf ? tempCmdBo : cmd_bo, alloc_bo, currentPatch->uiWriteOperation); |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
for(auto res: mappedResList) |
| 354 |
{ |
| 355 |
res->pGfxResourceNext->Unlock(m_osContext); |
| 356 |
} |
| 357 |
mappedResList.clear(); |
| 358 |
|
| 359 |
return MOS_STATUS_SUCCESS; |
| 360 |
} |
| 361 |
|
| 362 |
MOS_STATUS GpuContextSpecificNextXe::EndSubmitCommandBuffer( |
| 363 |
MOS_STREAM_HANDLE streamState, |
| 364 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 365 |
bool cmdBufMapIsReused) |
| 366 |
{ |
| 367 |
MOS_OS_FUNCTION_ENTER; |
| 368 |
|
| 369 |
auto it = m_secondaryCmdBufs.begin(); |
| 370 |
#if MOS_COMMAND_BUFFER_DUMP_SUPPORTED |
| 371 |
pthread_mutex_lock(&command_dump_mutex); |
| 372 |
if (streamState->dumpCommandBuffer) |
| 373 |
{ |
| 374 |
while(it != m_secondaryCmdBufs.end()) |
| 375 |
{ |
| 376 |
MosInterface::DumpCommandBuffer(streamState, it->second); |
| 377 |
it++; |
| 378 |
} |
| 379 |
} |
| 380 |
pthread_mutex_unlock(&command_dump_mutex); |
| 381 |
#endif // MOS_COMMAND_BUFFER_DUMP_SUPPORTED |
| 382 |
|
| 383 |
for (uint32_t patchIndex = 0; patchIndex < m_currentNumPatchLocations; patchIndex++) |
| 384 |
{ |
| 385 |
auto currentPatch = &m_patchLocationList[patchIndex]; |
| 386 |
MOS_OS_CHK_NULL_RETURN(currentPatch); |
| 387 |
|
| 388 |
// reuse this api to clear exec list in cmd bo |
| 389 |
if(currentPatch->cmdBo) |
| 390 |
mos_bo_clear_relocs(currentPatch->cmdBo, 0); |
| 391 |
} |
| 392 |
// Now, we can unmap the video command buffer, since we don't need CPU access anymore. |
| 393 |
if (!cmdBufMapIsReused && cmdBuffer->OsResource.pGfxResourceNext) |
| 394 |
{ |
| 395 |
cmdBuffer->OsResource.pGfxResourceNext->Unlock(m_osContext); |
| 396 |
} |
| 397 |
ClearSecondaryCmdBuffer(cmdBufMapIsReused); |
| 398 |
|
| 399 |
// Reset resource allocation |
| 400 |
m_numAllocations = 0; |
| 401 |
MosUtilities::MosZeroMemory(m_allocationList, sizeof(ALLOCATION_LIST) * m_maxNumAllocations); |
| 402 |
m_currentNumPatchLocations = 0; |
| 403 |
MosUtilities::MosZeroMemory(m_patchLocationList, sizeof(PATCHLOCATIONLIST) * m_maxNumAllocations); |
| 404 |
m_resCount = 0; |
| 405 |
|
| 406 |
MosUtilities::MosZeroMemory(m_writeModeList, sizeof(bool) * m_maxNumAllocations); |
| 407 |
|
| 408 |
return MOS_STATUS_SUCCESS; |
| 409 |
} |
| 410 |
|
| 411 |
MOS_STATUS GpuContextSpecificNextXe::SubmitCommandBuffer( |
| 412 |
MOS_STREAM_HANDLE streamState, |
| 413 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 414 |
bool nullRendering) |
| 415 |
{ |
| 416 |
MOS_OS_FUNCTION_ENTER; |
| 417 |
|
| 418 |
MOS_TraceEventExt(EVENT_MOS_BATCH_SUBMIT, EVENT_TYPE_START, nullptr, 0, nullptr, 0); |
| 419 |
|
| 420 |
MOS_OS_CHK_NULL_RETURN(streamState); |
| 421 |
auto perStreamParameters = (PMOS_CONTEXT)streamState->perStreamParameters; |
| 422 |
MOS_OS_CHK_NULL_RETURN(perStreamParameters); |
| 423 |
MOS_OS_CHK_NULL_RETURN(cmdBuffer); |
| 424 |
MOS_OS_CHK_NULL_RETURN(m_patchLocationList); |
| 425 |
|
| 426 |
MOS_GPU_NODE gpuNode = OSKMGetGpuNode(m_gpuContext); |
| 427 |
uint32_t execFlag = gpuNode; |
| 428 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 429 |
int32_t ret = 0; |
| 430 |
bool scalaEnabled = false; |
| 431 |
bool cmdBufMapIsReused = false; |
| 432 |
auto it = m_secondaryCmdBufs.begin(); |
| 433 |
|
| 434 |
m_cmdBufFlushed = true; |
| 435 |
auto cmd_bo = cmdBuffer->OsResource.bo; |
| 436 |
|
| 437 |
if (m_secondaryCmdBufs.size() >= 2) |
| 438 |
{ |
| 439 |
scalaEnabled = true; |
| 440 |
cmdBuffer->iSubmissionType = SUBMISSION_TYPE_MULTI_PIPE_MASTER; |
| 441 |
} |
| 442 |
|
| 443 |
// Patch cmdbuffer addr |
| 444 |
MOS_OS_CHK_STATUS_RETURN(PatchCommandBuffer(streamState, cmdBuffer)); |
| 445 |
|
| 446 |
int32_t perfData = perStreamParameters->pPerfData != nullptr ? *(int32_t *)(perStreamParameters->pPerfData) : 0; |
| 447 |
|
| 448 |
int32_t DR4 = perStreamParameters->uEnablePerfTag ? perfData : 0; |
| 449 |
|
| 450 |
if (gpuNode != I915_EXEC_RENDER && |
| 451 |
streamState->osCpInterface->IsTearDownHappen()) |
| 452 |
{ |
| 453 |
// skip PAK command when CP tear down happen to avoid of GPU hang |
| 454 |
// conditonal batch buffer start PoC is in progress |
| 455 |
} |
| 456 |
else if (nullRendering == false) |
| 457 |
{ |
| 458 |
UnlockPendingOcaBuffers(cmdBuffer, perStreamParameters); |
| 459 |
if (streamState->ctxBasedScheduling && m_i915Context[0] != nullptr) |
| 460 |
{ |
| 461 |
//For multipipe, FE, BEs bb are all in m_secondaryCmdBufs; |
| 462 |
//For single pipe, reuse m_secondaryCmdBufs and add cmdBuffer in it. |
| 463 |
if(!scalaEnabled) |
| 464 |
{ |
| 465 |
// Need to resue m_secondaryCmdBufs |
| 466 |
ClearSecondaryCmdBuffer(cmdBufMapIsReused); |
| 467 |
m_secondaryCmdBufs[0] = cmdBuffer; |
| 468 |
cmdBufMapIsReused = true; |
| 469 |
} |
| 470 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 471 |
// Dump CmdBuffer in trace before submit |
| 472 |
auto it = m_secondaryCmdBufs.begin(); |
| 473 |
while(it != m_secondaryCmdBufs.end()) |
| 474 |
{ |
| 475 |
MOS_TraceDumpExt("CmdBuffer", m_gpuContext, it->second->pCmdBase, it->second->iOffset); |
| 476 |
it++; |
| 477 |
} |
| 478 |
#endif |
| 479 |
ret = ParallelSubmitCommands(m_secondaryCmdBufs, |
| 480 |
perStreamParameters, |
| 481 |
execFlag, |
| 482 |
DR4); |
| 483 |
} |
| 484 |
|
| 485 |
if (ret != 0) |
| 486 |
{ |
| 487 |
eStatus = MOS_STATUS_UNKNOWN; |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 492 |
{ |
| 493 |
MOS_OS_ASSERTMESSAGE("Command buffer submission failed!"); |
| 494 |
} |
| 495 |
|
| 496 |
MosUtilDevUltSpecific::MOS_DEVULT_FuncCall(pfnUltGetCmdBuf, cmdBuffer); |
| 497 |
|
| 498 |
// Reset global variable |
| 499 |
MOS_OS_CHK_STATUS_RETURN(EndSubmitCommandBuffer(streamState, cmdBuffer, cmdBufMapIsReused)); |
| 500 |
|
| 501 |
MOS_TraceEventExt(EVENT_MOS_BATCH_SUBMIT, EVENT_TYPE_END, &eStatus, sizeof(eStatus), nullptr, 0); |
| 502 |
return eStatus; |
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* Both of single pipe and multi-pipe are submitted through this interface |
| 507 |
* FE and BE sync through bo.deps since they use different ctx |
| 508 |
*/ |
| 509 |
int32_t GpuContextSpecificNextXe::ParallelSubmitCommands( |
| 510 |
std::map<uint32_t, PMOS_COMMAND_BUFFER> secondaryCmdBufs, |
| 511 |
PMOS_CONTEXT osContext, |
| 512 |
uint32_t execFlag, |
| 513 |
int32_t dr4) |
| 514 |
{ |
| 515 |
MOS_OS_FUNCTION_ENTER; |
| 516 |
|
| 517 |
int32_t ret = 0; |
| 518 |
int fence = -1; |
| 519 |
auto it = m_secondaryCmdBufs.begin(); |
| 520 |
MOS_LINUX_BO *cmdBos[MAX_PARALLEN_CMD_BO_NUM]; |
| 521 |
int numBatch = 0; |
| 522 |
uint32_t batchBufferEndCmd = MI_BATCHBUFFER_END; |
| 523 |
|
| 524 |
MOS_LINUX_CONTEXT *queue = m_i915Context[0]; |
| 525 |
|
| 526 |
while(it != m_secondaryCmdBufs.end()) |
| 527 |
{ |
| 528 |
MapResourcesToAuxTable(it->second->OsResource.bo); |
| 529 |
// Add Batch buffer End Command |
| 530 |
if (MOS_FAILED(Mos_AddCommand( |
| 531 |
it->second, |
| 532 |
&batchBufferEndCmd, |
| 533 |
sizeof(uint32_t)))) |
| 534 |
{ |
| 535 |
MOS_OS_ASSERTMESSAGE("Inserting BB_END failed!"); |
| 536 |
return MOS_STATUS_UNKNOWN; |
| 537 |
} |
| 538 |
|
| 539 |
if(it->second->iSubmissionType & SUBMISSION_TYPE_MULTI_PIPE_ALONE |
| 540 |
|| it->second->iSubmissionType & SUBMISSION_TYPE_SINGLE_PIPE |
| 541 |
|| m_secondaryCmdBufs.size() == 1) |
| 542 |
{ |
| 543 |
queue = m_i915Context[0]; |
| 544 |
MOS_OS_CHK_NULL_RETURN(queue); |
| 545 |
numBatch = 1; |
| 546 |
cmdBos[0] = it->second->OsResource.bo; |
| 547 |
|
| 548 |
ret = mos_bo_context_exec3(cmdBos, |
| 549 |
numBatch, |
| 550 |
queue, |
| 551 |
nullptr, |
| 552 |
0, |
| 553 |
dr4, |
| 554 |
execFlag, // not used |
| 555 |
&fence); // not used |
| 556 |
cmdBos[0] = nullptr; |
| 557 |
numBatch = 0; |
| 558 |
} |
| 559 |
|
| 560 |
if((it->second->iSubmissionType & SUBMISSION_TYPE_MULTI_PIPE_MASTER) |
| 561 |
|| (it->second->iSubmissionType & SUBMISSION_TYPE_MULTI_PIPE_SLAVE)) |
| 562 |
{ |
| 563 |
cmdBos[numBatch++] = it->second->OsResource.bo; |
| 564 |
|
| 565 |
if(it->second->iSubmissionType & SUBMISSION_TYPE_MULTI_PIPE_FLAGS_LAST_PIPE) |
| 566 |
{ |
| 567 |
queue = m_i915Context[numBatch - 1]; |
| 568 |
MOS_OS_CHK_NULL_RETURN(queue); |
| 569 |
|
| 570 |
ret = mos_bo_context_exec3(cmdBos, |
| 571 |
numBatch, |
| 572 |
queue, |
| 573 |
nullptr, |
| 574 |
0, |
| 575 |
dr4, |
| 576 |
execFlag, |
| 577 |
&fence); |
| 578 |
|
| 579 |
for(int i = 0; i < numBatch; i++) |
| 580 |
{ |
| 581 |
cmdBos[i] = nullptr; |
| 582 |
} |
| 583 |
numBatch = 0; |
| 584 |
} |
| 585 |
} |
| 586 |
it++; |
| 587 |
} |
| 588 |
|
| 589 |
return ret; |
| 590 |
} |
| 591 |
|
| 592 |
void GpuContextSpecificNextXe::UpdatePriority(int32_t priority) |
| 593 |
{ |
| 594 |
MOS_OS_FUNCTION_ENTER; |
| 595 |
//Note: need to implement this bufmgr api to set exec queue property |
| 596 |
} |
| 597 |
|
| 598 |
MOS_STATUS GpuContextSpecificNextXe::ReportEngineInfo( |
| 599 |
void *engine_map, |
| 600 |
int engineNum, bool engineSelectEnable) |
| 601 |
{ |
| 602 |
MOS_UNUSED(engine_map); |
| 603 |
MOS_UNUSED(engineNum); |
| 604 |
MOS_UNUSED(engineSelectEnable); |
| 605 |
return MOS_STATUS_SUCCESS; |
| 606 |
} |
| 607 |
|
| 608 |
void GpuContextSpecificNextXe::ClearSecondaryCmdBuffer( |
| 609 |
bool cmdBufMapIsReused) |
| 610 |
{ |
| 611 |
auto it = m_secondaryCmdBufs.begin(); |
| 612 |
while (it != m_secondaryCmdBufs.end()) |
| 613 |
{ |
| 614 |
if (it->second->OsResource.pGfxResourceNext) |
| 615 |
{ |
| 616 |
it->second->OsResource.pGfxResourceNext->Unlock(m_osContext); |
| 617 |
} |
| 618 |
if (!cmdBufMapIsReused) |
| 619 |
{ |
| 620 |
MOS_FreeMemory(it->second); |
| 621 |
} |
| 622 |
it++; |
| 623 |
} |
| 624 |
m_secondaryCmdBufs.clear(); |
| 625 |
} |