diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index 8ba78ef90f..be423f1996 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -399,3 +399,4 @@ UseTileMemoryBankInVirtualMemoryCreation = -1 DisableScratchPages = 0 ForceAllResourcesUncached = 0 ForcePreParserEnabledForMiArbCheck = -1 +BatchBufferStartPrepatchingWaEnabled = -1 \ No newline at end of file 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 a1ef972d69..92ffbcc365 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -94,13 +94,21 @@ 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(); + } + *patchLocation = commandStream.getSpace(sizeof(MI_BATCH_BUFFER_START)); auto bbStart = reinterpret_cast(*patchLocation); MI_BATCH_BUFFER_START cmd = {}; - addBatchBufferStart(&cmd, 0ull, false); + + addBatchBufferStart(&cmd, startAddress, false); *bbStart = cmd; } else { - PreemptionHelper::programStateSipEndWa(commandStream, device); + if (!EngineHelpers::isBcs(osContext->getEngineType())) { + PreemptionHelper::programStateSipEndWa(commandStream, device); + } this->addBatchBufferEnd(commandStream, patchLocation); } } @@ -1091,16 +1099,7 @@ uint32_t CommandStreamReceiverHw::flushBcsTask(const BlitPropertiesCo } void *endingCmdPtr = nullptr; - if (blitterDirectSubmission) { - endingCmdPtr = commandStream.getSpace(0); - EncodeBatchBufferStartOrEnd::programBatchBufferStart(&commandStream, - 0ull, - false); - } else { - auto batchBufferEnd = reinterpret_cast( - commandStream.getSpace(sizeof(MI_BATCH_BUFFER_END))); - *batchBufferEnd = GfxFamily::cmdInitBatchBufferEnd; - } + programEndingCmd(commandStream, device, &endingCmdPtr, blitterDirectSubmission); EncodeNoop::alignToCacheLine(commandStream); diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index b38a7c0646..0d0a3eb4f2 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -195,6 +195,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverridePatIndex, -1, "-1: default, >=0: PatInde DECLARE_DEBUG_VARIABLE(int32_t, UseTileMemoryBankInVirtualMemoryCreation, -1, "-1: default - on, 0: do not assign tile memory bank to virtual memory space, 1: assign tile memory bank to virtual memory space") DECLARE_DEBUG_VARIABLE(int32_t, OverrideTimestampEvents, -1, "-1: default (based on user settings), 0: Force disable timestamp events (no timestamps will be reported), 1: Force enable timestamp events") DECLARE_DEBUG_VARIABLE(int32_t, ForcePreParserEnabledForMiArbCheck, -1, "-1: default , 0: PreParser disabled, 1: PreParser enabled") +DECLARE_DEBUG_VARIABLE(int32_t, BatchBufferStartPrepatchingWaEnabled, -1, "-1: default , 0: disabled, 1: enabled. WA applies valid VA pointing to 'self' instead of 0x0. This mitigates incorrect VA preparsing.") DECLARE_DEBUG_VARIABLE(bool, DisableScratchPages, false, "Disable scratch pages during VM creations") /*LOGGING FLAGS*/ DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level") 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 37ad85918c..34832bb5c7 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 @@ -617,6 +617,46 @@ HWTEST_F(DirectSubmissionTest, givenDirectSubmissionAvailableWhenProgrammingEndi 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); + mockCsr->commandStream.replaceGraphicsAllocation(&mockAllocation); + 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)); + + auto bbStartCmd = reinterpret_cast(mockCsr->commandStream.getCpuBase()); + + EXPECT_EQ(mockCsr->commandStream.getGraphicsAllocation()->getGpuAddress(), bbStartCmd->getBatchBufferStartAddress()); + + mockCsr->commandStream.replaceGraphicsAllocation(nullptr); +} + HWTEST_F(DirectSubmissionTest, givenDirectSubmissionDiagnosticNotAvailableWhenDiagnosticRegistryIsUsedThenDoNotEnableDiagnostic) { using Dispatcher = RenderDispatcher;