@@ -128,7 +128,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
128128 !this ->commandQueueDebugCmdsProgrammed &&
129129 device->getL0Debugger ();
130130 ctx.lockScratchController = lockScratchController;
131-
131+ ctx. lockCSR = &lockCSR;
132132 if (this ->isCopyOnlyCommandQueue ) {
133133 ret = this ->executeCommandListsCopyOnly (ctx, numCommandLists, phCommandLists, hFence, parentImmediateCommandlistLinearStream);
134134 } else if (this ->heaplessStateInitEnabled ) {
@@ -230,18 +230,13 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandListsRegularHeapless(
230230 this ->dispatchPatchPreambleEnding (ctx);
231231
232232 if (!ctx.containsParentImmediateStream ) {
233- this ->assignCsrTaskCountToFenceIfAvailable (hFence);
234- this ->dispatchTaskCountPostSyncRegular (ctx.isDispatchTaskCountPostSyncRequired , *streamForDispatch);
235-
236- auto submitResult = this ->prepareAndSubmitBatchBuffer (ctx, *streamForDispatch);
237- this ->updateTaskCountAndPostSync (ctx.isDispatchTaskCountPostSyncRequired , numCommandLists, commandListHandles);
238-
239- this ->csr ->makeSurfacePackNonResident (this ->csr ->getResidencyAllocations (), false );
240-
241- auto completionResult = this ->waitForCommandQueueCompletionAndCleanHeapContainer ();
242- retVal = this ->handleSubmissionAndCompletionResults (submitResult, completionResult);
243- this ->csr ->getResidencyAllocations ().clear ();
233+ retVal = handleNonParentImmediateStream (hFence, ctx, numCommandLists, commandListHandles, streamForDispatch, false );
234+ if (retVal != ZE_RESULT_SUCCESS) {
235+ return retVal;
236+ }
237+ retVal = this ->waitForCommandQueueCompletion (ctx);
244238 }
239+
245240 return retVal;
246241}
247242
@@ -458,21 +453,17 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandListsRegular(
458453 this ->csr ->setPreemptionMode (ctx.statePreemption );
459454
460455 if (!ctx.containsParentImmediateStream ) {
461- this ->assignCsrTaskCountToFenceIfAvailable (hFence);
462- this ->dispatchTaskCountPostSyncRegular (ctx.isDispatchTaskCountPostSyncRequired , *streamForDispatch);
463-
464- auto submitResult = this ->prepareAndSubmitBatchBuffer (ctx, *streamForDispatch);
465- this ->updateTaskCountAndPostSync (ctx.isDispatchTaskCountPostSyncRequired , numCommandLists, commandListHandles);
466-
467- this ->csr ->makeSurfacePackNonResident (this ->csr ->getResidencyAllocations (), false );
468-
469- auto completionResult = this ->waitForCommandQueueCompletionAndCleanHeapContainer ();
470- retVal = this ->handleSubmissionAndCompletionResults (submitResult, completionResult);
471- this ->csr ->getResidencyAllocations ().clear ();
456+ retVal = handleNonParentImmediateStream (hFence, ctx, numCommandLists, commandListHandles, streamForDispatch, false );
472457 }
473458
474459 this ->stateChanges .clear ();
475460 this ->currentStateChangeIndex = 0 ;
461+ if (retVal != ZE_RESULT_SUCCESS) {
462+ return retVal;
463+ }
464+ if (!ctx.containsParentImmediateStream ) {
465+ return this ->waitForCommandQueueCompletion (ctx);
466+ }
476467 return retVal;
477468}
478469
@@ -543,19 +534,12 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandListsCopyOnly(
543534 this ->makeCsrTagAllocationResident ();
544535
545536 if (!ctx.containsParentImmediateStream ) {
546- this ->assignCsrTaskCountToFenceIfAvailable (hFence);
547- this ->dispatchTaskCountPostSyncByMiFlushDw (ctx.isDispatchTaskCountPostSyncRequired , fenceRequired, *streamForDispatch);
548-
549- auto submitResult = this ->prepareAndSubmitBatchBuffer (ctx, *streamForDispatch);
550- this ->updateTaskCountAndPostSync (ctx.isDispatchTaskCountPostSyncRequired , numCommandLists, phCommandLists);
551-
552- this ->csr ->makeSurfacePackNonResident (this ->csr ->getResidencyAllocations (), false );
553-
554- auto completionResult = this ->waitForCommandQueueCompletionAndCleanHeapContainer ();
555- retVal = this ->handleSubmissionAndCompletionResults (submitResult, completionResult);
556- this ->csr ->getResidencyAllocations ().clear ();
537+ retVal = handleNonParentImmediateStream (hFence, ctx, numCommandLists, phCommandLists, streamForDispatch, fenceRequired);
538+ if (retVal != ZE_RESULT_SUCCESS) {
539+ return retVal;
540+ }
541+ retVal = this ->waitForCommandQueueCompletion (ctx);
557542 }
558-
559543 return retVal;
560544}
561545
@@ -1689,39 +1673,52 @@ void CommandQueueHw<gfxCoreFamily>::updateTaskCountAndPostSync(bool isDispatchTa
16891673}
16901674
16911675template <GFXCORE_FAMILY gfxCoreFamily>
1692- ze_result_t CommandQueueHw<gfxCoreFamily>::waitForCommandQueueCompletionAndCleanHeapContainer() {
1693-
1676+ ze_result_t CommandQueueHw<gfxCoreFamily>::waitForCommandQueueCompletion(CommandListExecutionContext &ctx) {
16941677 ze_result_t ret = ZE_RESULT_SUCCESS;
1695-
16961678 if (this ->isSynchronousMode ()) {
1679+ ctx.lockCSR ->unlock ();
16971680 if (const auto syncRet = this ->synchronize (std::numeric_limits<uint64_t >::max ()); syncRet == ZE_RESULT_ERROR_DEVICE_LOST) {
16981681 ret = syncRet;
16991682 }
17001683 }
1701- this ->heapContainer .clear ();
17021684
17031685 return ret;
17041686}
17051687
17061688template <GFXCORE_FAMILY gfxCoreFamily>
1707- ze_result_t CommandQueueHw<gfxCoreFamily>::handleSubmissionAndCompletionResults(
1708- NEO::SubmissionStatus submitRet,
1709- ze_result_t completionRet) {
1689+ ze_result_t CommandQueueHw<gfxCoreFamily>::handleNonParentImmediateStream(ze_fence_handle_t hFence, CommandListExecutionContext &ctx, uint32_t numCommandLists,
1690+ ze_command_list_handle_t *phCommandLists, NEO::LinearStream *streamForDispatch, bool isFenceRequired) {
1691+ this ->assignCsrTaskCountToFenceIfAvailable (hFence);
1692+ if (!this ->isCopyOnlyCommandQueue ) {
1693+ this ->dispatchTaskCountPostSyncRegular (ctx.isDispatchTaskCountPostSyncRequired , *streamForDispatch);
1694+ } else {
1695+ this ->dispatchTaskCountPostSyncByMiFlushDw (ctx.isDispatchTaskCountPostSyncRequired , isFenceRequired, *streamForDispatch);
1696+ }
1697+ auto submitResult = this ->prepareAndSubmitBatchBuffer (ctx, *streamForDispatch);
1698+ this ->updateTaskCountAndPostSync (ctx.isDispatchTaskCountPostSyncRequired , numCommandLists, phCommandLists);
17101699
1711- if ((submitRet != NEO::SubmissionStatus::success) || (completionRet == ZE_RESULT_ERROR_DEVICE_LOST)) {
1700+ this ->csr ->makeSurfacePackNonResident (this ->csr ->getResidencyAllocations (), false );
1701+
1702+ auto retVal = this ->handleSubmission (submitResult);
1703+ this ->csr ->getResidencyAllocations ().clear ();
1704+ this ->heapContainer .clear ();
1705+ return retVal;
1706+ }
1707+
1708+ template <GFXCORE_FAMILY gfxCoreFamily>
1709+ ze_result_t CommandQueueHw<gfxCoreFamily>::handleSubmission(
1710+ NEO::SubmissionStatus submitRet) {
1711+ if (submitRet != NEO::SubmissionStatus::success) {
17121712 for (auto &gfx : this ->csr ->getResidencyAllocations ()) {
17131713 if (this ->csr ->peekLatestFlushedTaskCount () == 0 ) {
17141714 gfx->releaseUsageInOsContext (this ->csr ->getOsContext ().getContextId ());
17151715 } else {
17161716 gfx->updateTaskCount (this ->csr ->peekLatestFlushedTaskCount (), this ->csr ->getOsContext ().getContextId ());
17171717 }
17181718 }
1719- if (completionRet != ZE_RESULT_ERROR_DEVICE_LOST) {
1720- completionRet = getErrorCodeForSubmissionStatus (submitRet);
1721- }
1719+ return getErrorCodeForSubmissionStatus (submitRet);
17221720 }
1723-
1724- return completionRet;
1721+ return ZE_RESULT_SUCCESS;
17251722}
17261723
17271724template <GFXCORE_FAMILY gfxCoreFamily>
0 commit comments