diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index ea7a24627f..6ca30a66c8 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -246,7 +246,7 @@ ze_result_t CommandListCoreFamily::initialize(Device *device, NEO this->l1CachePolicyData.init(productHelper); this->cmdListHeapAddressModel = L0GfxCoreHelper::getHeapAddressModel(rootDeviceEnvironment); this->dummyBlitWa.rootDeviceEnvironment = &(neoDevice->getRootDeviceEnvironmentRef()); - this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !isImmediateType()); + this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !(this->internalUsage && isImmediateType())); this->useOnlyGlobalTimestamps = gfxCoreHelper.useOnlyGlobalTimestamps(); this->maxFillPaternSizeForCopyEngine = productHelper.getMaxFillPaternSizeForCopyEngine(); this->heaplessModeEnabled = compilerProductHelper.isHeaplessModeEnabled(); diff --git a/level_zero/core/source/cmdqueue/cmdqueue.cpp b/level_zero/core/source/cmdqueue/cmdqueue.cpp index d1594e83ee..6a4cefd258 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue.cpp +++ b/level_zero/core/source/cmdqueue/cmdqueue.cpp @@ -98,7 +98,7 @@ ze_result_t CommandQueueImp::initialize(bool copyOnly, bool isInternal, bool imm auto &productHelper = rootDeviceEnvironment.getHelper(); this->doubleSbaWa = productHelper.isAdditionalStateBaseAddressWARequired(hwInfo); this->cmdListHeapAddressModel = L0GfxCoreHelper::getHeapAddressModel(rootDeviceEnvironment); - this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !immediateCmdListQueue); + this->dispatchCmdListBatchBufferAsPrimary = L0GfxCoreHelper::dispatchCmdListBatchBufferAsPrimary(rootDeviceEnvironment, !(internalUsage && immediateCmdListQueue)); auto &compilerProductHelper = rootDeviceEnvironment.getHelper(); this->heaplessModeEnabled = compilerProductHelper.isHeaplessModeEnabled(); this->heaplessStateInitEnabled = compilerProductHelper.isHeaplessStateInitEnabled(this->heaplessModeEnabled); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp index 592df5e9bd..022d8bf4f8 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp @@ -1729,14 +1729,14 @@ HWTEST2_F(CommandListCreateTests, givenPlatformNotSupportsSharedHeapsWhenImmedia using PrimaryBatchBufferCmdListTest = Test; -HWTEST_F(PrimaryBatchBufferCmdListTest, givenForcedPrimaryBatchBufferWhenRegularAndImmediateObjectCreatedThenRegularSetPrimaryFlagAndImmediateNot) { +HWTEST_F(PrimaryBatchBufferCmdListTest, givenForcedPrimaryBatchBufferWhenRegularAndImmediateObjectCreatedThenRegularAndImmediateSetPrimaryFlag) { EXPECT_TRUE(commandList->dispatchCmdListBatchBufferAsPrimary); EXPECT_TRUE(commandQueue->dispatchCmdListBatchBufferAsPrimary); - EXPECT_FALSE(commandListImmediate->dispatchCmdListBatchBufferAsPrimary); + EXPECT_TRUE(commandListImmediate->dispatchCmdListBatchBufferAsPrimary); ASSERT_NE(nullptr, commandListImmediate->cmdQImmediate); auto immediateCmdQueue = static_cast(commandListImmediate->cmdQImmediate); - EXPECT_FALSE(immediateCmdQueue->dispatchCmdListBatchBufferAsPrimary); + EXPECT_TRUE(immediateCmdQueue->dispatchCmdListBatchBufferAsPrimary); } HWTEST_F(PrimaryBatchBufferCmdListTest, givenPrimaryBatchBufferWhenAppendingKernelAndClosingCommandListThenExpectAlignedSpaceForBatchBufferStart) { @@ -1851,6 +1851,46 @@ HWTEST_F(PrimaryBatchBufferCmdListTest, givenRegularCmdListWhenFlushingThenPassS EXPECT_TRUE(ultCsr->latestFlushedBatchBuffer.hasStallingCmds); } +HWTEST_F(PrimaryBatchBufferCmdListTest, givenRegularCmdListWhenNoPreambleExpectedAndForceBbStartThenDispatchBbStart) { + using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; + + ze_group_count_t groupCount{1, 1, 1}; + CmdListKernelLaunchParams launchParams = {}; + auto result = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + result = commandList->close(); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + auto cmdListHandle = commandList->toHandle(); + + auto regularCmdBufferAllocation = commandList->getCmdContainer().getCommandStream()->getGraphicsAllocation(); + + // 1st dispatch can carry state preamble + result = commandQueue->executeCommandLists(1, &cmdListHandle, nullptr, true, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + auto &queueStream = commandQueue->commandStream; + + auto offsetBefore = queueStream.getUsed(); + commandQueue->triggerBbStartJump(); + result = commandQueue->executeCommandLists(1, &cmdListHandle, nullptr, true, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + auto offsetAfter = queueStream.getUsed(); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer( + cmdList, + ptrOffset(queueStream.getCpuBase(), offsetBefore), + offsetAfter - offsetBefore)); + ASSERT_NE(0u, cmdList.size()); + + auto firstCmdIt = cmdList.begin(); + auto bbStartCmd = genCmdCast(*firstCmdIt); + ASSERT_NE(nullptr, bbStartCmd); + + EXPECT_EQ(regularCmdBufferAllocation->getGpuAddress(), bbStartCmd->getBatchBufferStartAddress()); + EXPECT_EQ(MI_BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER::SECOND_LEVEL_BATCH_BUFFER_FIRST_LEVEL_BATCH, bbStartCmd->getSecondLevelBatchBuffer()); +} + HWTEST2_F(PrimaryBatchBufferCmdListTest, givenRelaxedOrderingAndRegularCmdListAndSubmittedToImmediateWhenFlushingThenPassStallingCmdsInfo, IsAtLeastXeHpcCore) { DebugManagerStateRestore restore; debugManager.flags.DirectSubmissionRelaxedOrdering.set(1);