diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp index 5328b55a44..07418cc641 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp @@ -1405,7 +1405,7 @@ HWTEST_F(BcsTests, givenBlitterDirectSubmissionEnabledWhenProgrammingBlitterThen MI_BATCH_BUFFER_START *bbStart = hwParser.getCommand(); ASSERT_NE(nullptr, bbStart); EXPECT_EQ(csr.latestFlushedBatchBuffer.endCmdPtr, bbStart); - EXPECT_EQ(0ull, bbStart->getBatchBufferStartAddress()); + EXPECT_NE(0ull, bbStart->getBatchBufferStartAddress()); } HWTEST_F(BcsTests, givenBlitterDirectSubmissionEnabledWhenFlushTagUpdateThenBatchBufferStartIsProgrammed) { diff --git a/shared/source/command_stream/command_stream_receiver_hw_base.inl b/shared/source/command_stream/command_stream_receiver_hw_base.inl index 92ffbcc365..c04d1b1a40 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -94,9 +94,9 @@ inline void CommandStreamReceiverHw::addBatchBufferEnd(LinearStream & template inline void CommandStreamReceiverHw::programEndingCmd(LinearStream &commandStream, Device &device, void **patchLocation, bool directSubmissionEnabled) { if (directSubmissionEnabled) { - uint64_t startAddress = 0; - if (DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.get() == 1) { - startAddress = commandStream.getGraphicsAllocation()->getGpuAddress() + commandStream.getUsed(); + uint64_t startAddress = commandStream.getGraphicsAllocation()->getGpuAddress() + commandStream.getUsed(); + if (DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.get() == 0) { + startAddress = 0; } *patchLocation = commandStream.getSpace(sizeof(MI_BATCH_BUFFER_START)); diff --git a/shared/test/unit_test/direct_submission/direct_submission_tests_1.cpp b/shared/test/unit_test/direct_submission/direct_submission_tests_1.cpp index 34832bb5c7..648b4c715c 100644 --- a/shared/test/unit_test/direct_submission/direct_submission_tests_1.cpp +++ b/shared/test/unit_test/direct_submission/direct_submission_tests_1.cpp @@ -602,39 +602,8 @@ HWTEST_F(DirectSubmissionTest, givenDirectSubmissionAvailableWhenProgrammingEndi bool ret = mockCsr->isDirectSubmissionEnabled(); EXPECT_TRUE(ret); - void *location = nullptr; - uint8_t buffer[128]; - mockCsr->commandStream.replaceBuffer(&buffer[0], 128u); - auto &device = *pDevice; - mockCsr->programEndingCmd(mockCsr->commandStream, device, &location, ret); - EXPECT_EQ(sizeof(MI_BATCH_BUFFER_START), mockCsr->commandStream.getUsed()); - - DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags(); - dispatchFlags.epilogueRequired = true; - size_t expectedSize = sizeof(MI_BATCH_BUFFER_START) + - mockCsr->getCmdSizeForEpilogueCommands(dispatchFlags); - expectedSize = alignUp(expectedSize, MemoryConstants::cacheLineSize); - EXPECT_EQ(expectedSize, mockCsr->getCmdSizeForEpilogue(dispatchFlags)); -} - -HWTEST_F(DirectSubmissionTest, givenDebugFlagSetWhenProgrammingEndingCommandThenUseNonZeroBatchBufferStart) { - using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; - - DebugManagerStateRestore restorer; - - DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.set(1); - MockGraphicsAllocation mockAllocation; - int32_t executionStamp = 0; - std::unique_ptr> mockCsr = std::make_unique>(executionStamp, *pDevice->executionEnvironment, - pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield()); - - mockCsr->setupContext(*osContext); - mockCsr->directSubmissionAvailable = true; - bool ret = mockCsr->isDirectSubmissionEnabled(); - EXPECT_TRUE(ret); - void *location = nullptr; uint8_t buffer[128]; mockCsr->commandStream.replaceBuffer(&buffer[0], 128u); @@ -650,13 +619,51 @@ HWTEST_F(DirectSubmissionTest, givenDebugFlagSetWhenProgrammingEndingCommandThen expectedSize = alignUp(expectedSize, MemoryConstants::cacheLineSize); EXPECT_EQ(expectedSize, mockCsr->getCmdSizeForEpilogue(dispatchFlags)); - auto bbStartCmd = reinterpret_cast(mockCsr->commandStream.getCpuBase()); - - EXPECT_EQ(mockCsr->commandStream.getGraphicsAllocation()->getGpuAddress(), bbStartCmd->getBatchBufferStartAddress()); - mockCsr->commandStream.replaceGraphicsAllocation(nullptr); } +HWTEST_F(DirectSubmissionTest, givenDebugFlagSetWhenProgrammingEndingCommandThenUseCorrectBatchBufferStartValue) { + using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; + + DebugManagerStateRestore restorer; + MockGraphicsAllocation mockAllocation; + int32_t executionStamp = 0; + + std::unique_ptr> mockCsr = std::make_unique>(executionStamp, *pDevice->executionEnvironment, + pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield()); + + mockCsr->setupContext(*osContext); + mockCsr->directSubmissionAvailable = true; + bool ret = mockCsr->isDirectSubmissionEnabled(); + EXPECT_TRUE(ret); + + void *location = nullptr; + + uint8_t buffer[256] = {}; + auto &cmdStream = mockCsr->commandStream; + cmdStream.replaceBuffer(&buffer[0], 256); + cmdStream.replaceGraphicsAllocation(&mockAllocation); + auto &device = *pDevice; + + for (int32_t value : {-1, 0, 1}) { + DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.set(value); + + auto currectBbStartCmd = reinterpret_cast(cmdStream.getSpace(0)); + uint64_t expectedGpuVa = cmdStream.getGraphicsAllocation()->getGpuAddress() + cmdStream.getUsed(); + + mockCsr->programEndingCmd(cmdStream, device, &location, ret); + EncodeNoop::alignToCacheLine(cmdStream); + + if (value == 0) { + EXPECT_EQ(0u, currectBbStartCmd->getBatchBufferStartAddress()); + } else { + EXPECT_EQ(expectedGpuVa, currectBbStartCmd->getBatchBufferStartAddress()); + } + } + + cmdStream.replaceGraphicsAllocation(nullptr); +} + HWTEST_F(DirectSubmissionTest, givenDirectSubmissionDiagnosticNotAvailableWhenDiagnosticRegistryIsUsedThenDoNotEnableDiagnostic) { using Dispatcher = RenderDispatcher;