diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index 1feecb5874..6624b91650 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -449,8 +449,14 @@ ze_result_t CommandQueueHw::executeCommandLists( csr->makeResident(*csr->getTagAllocation()); void *endingCmd = nullptr; if (directSubmissionEnabled) { + auto offset = ptrDiff(child.getCpuBase(), commandStream->getCpuBase()) + child.getUsed(); + uint64_t startAddress = commandStream->getGraphicsAllocation()->getGpuAddress() + offset; + if (NEO::DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.get() == 0) { + startAddress = 0; + } + endingCmd = child.getSpace(0); - NEO::EncodeBatchBufferStartOrEnd::programBatchBufferStart(&child, 0ull, false); + NEO::EncodeBatchBufferStartOrEnd::programBatchBufferStart(&child, startAddress, false); } else { MI_BATCH_BUFFER_END cmd = GfxFamily::cmdInitBatchBufferEnd; auto buffer = child.getSpaceForCmd(); diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp index a3451beb8b..c24e24b71e 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp @@ -1971,6 +1971,90 @@ HWTEST2_F(ExecuteCommandListTests, givenTwoCommandQueuesHavingTwoB2BCommandLists commandQueue1->destroy(); } +HWTEST_F(ExecuteCommandListTests, givenDirectSubmissionEnabledWhenExecutingCmdListThenSetNonZeroBatchBufferStartAddress) { + using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; + ze_command_queue_desc_t desc = {}; + NEO::CommandStreamReceiver *csr; + device->getCsrForOrdinalAndIndex(&csr, 0u, 0u); + static_cast *>(csr)->directSubmissionAvailable = true; + ze_result_t returnValue; + auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, + device, + csr, + &desc, + false, + false, + returnValue)); + auto commandList = std::unique_ptr(whitebox_cast(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue))); + commandList->setCommandListPerThreadPrivateScratchSize(0u); + auto commandListHandle = commandList->toHandle(); + + commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); + + auto usedSpaceAfter = commandQueue->commandStream->getUsed(); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter)); + + auto bbStartCmds = findAll(cmdList.begin(), cmdList.end()); + + ASSERT_EQ(2u, bbStartCmds.size()); + + for (auto &cmd : bbStartCmds) { + auto bbStart = genCmdCast(*cmd); + + EXPECT_NE(0u, bbStart->getBatchBufferStartAddress()); + } + + commandQueue->destroy(); +} + +HWTEST_F(ExecuteCommandListTests, givenDirectSubmissionEnabledAndDebugFlagSetWhenExecutingCmdListThenSetZeroBatchBufferStartAddress) { + DebugManagerStateRestore restore; + NEO::DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.set(0); + + using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; + ze_command_queue_desc_t desc = {}; + NEO::CommandStreamReceiver *csr; + device->getCsrForOrdinalAndIndex(&csr, 0u, 0u); + static_cast *>(csr)->directSubmissionAvailable = true; + ze_result_t returnValue; + auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, + device, + csr, + &desc, + false, + false, + returnValue)); + auto commandList = std::unique_ptr(whitebox_cast(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue))); + commandList->setCommandListPerThreadPrivateScratchSize(0u); + auto commandListHandle = commandList->toHandle(); + + commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); + + auto usedSpaceAfter = commandQueue->commandStream->getUsed(); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), 0), usedSpaceAfter)); + + auto bbStartCmds = findAll(cmdList.begin(), cmdList.end()); + + EXPECT_EQ(2u, bbStartCmds.size()); + + for (auto &cmd : bbStartCmds) { + auto bbStart = genCmdCast(*cmd); + if (cmd == bbStartCmds.back()) { + EXPECT_EQ(0u, bbStart->getBatchBufferStartAddress()); + } else { + EXPECT_NE(0u, bbStart->getBatchBufferStartAddress()); + } + } + + commandQueue->destroy(); +} + TEST_F(CommandQueueCreate, givenOverrideCmdQueueSyncModeToDefaultWhenCommandQueueIsCreatedWithSynchronousModeThenDefaultModeIsSelected) { DebugManagerStateRestore restore; NEO::DebugManager.flags.OverrideCmdQueueSynchronousMode.set(0);