Skip to content

Commit 79fedd5

Browse files
Add BB_START prepatching WA - disabled by default
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent 1b4319f commit 79fedd5

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,4 @@ UseTileMemoryBankInVirtualMemoryCreation = -1
399399
DisableScratchPages = 0
400400
ForceAllResourcesUncached = 0
401401
ForcePreParserEnabledForMiArbCheck = -1
402+
BatchBufferStartPrepatchingWaEnabled = -1

shared/source/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,21 @@ inline void CommandStreamReceiverHw<GfxFamily>::addBatchBufferEnd(LinearStream &
9494
template <typename GfxFamily>
9595
inline void CommandStreamReceiverHw<GfxFamily>::programEndingCmd(LinearStream &commandStream, Device &device, void **patchLocation, bool directSubmissionEnabled) {
9696
if (directSubmissionEnabled) {
97+
uint64_t startAddress = 0;
98+
if (DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.get() == 1) {
99+
startAddress = commandStream.getGraphicsAllocation()->getGpuAddress() + commandStream.getUsed();
100+
}
101+
97102
*patchLocation = commandStream.getSpace(sizeof(MI_BATCH_BUFFER_START));
98103
auto bbStart = reinterpret_cast<MI_BATCH_BUFFER_START *>(*patchLocation);
99104
MI_BATCH_BUFFER_START cmd = {};
100-
addBatchBufferStart(&cmd, 0ull, false);
105+
106+
addBatchBufferStart(&cmd, startAddress, false);
101107
*bbStart = cmd;
102108
} else {
103-
PreemptionHelper::programStateSipEndWa<GfxFamily>(commandStream, device);
109+
if (!EngineHelpers::isBcs(osContext->getEngineType())) {
110+
PreemptionHelper::programStateSipEndWa<GfxFamily>(commandStream, device);
111+
}
104112
this->addBatchBufferEnd(commandStream, patchLocation);
105113
}
106114
}
@@ -1091,16 +1099,7 @@ uint32_t CommandStreamReceiverHw<GfxFamily>::flushBcsTask(const BlitPropertiesCo
10911099
}
10921100

10931101
void *endingCmdPtr = nullptr;
1094-
if (blitterDirectSubmission) {
1095-
endingCmdPtr = commandStream.getSpace(0);
1096-
EncodeBatchBufferStartOrEnd<GfxFamily>::programBatchBufferStart(&commandStream,
1097-
0ull,
1098-
false);
1099-
} else {
1100-
auto batchBufferEnd = reinterpret_cast<MI_BATCH_BUFFER_END *>(
1101-
commandStream.getSpace(sizeof(MI_BATCH_BUFFER_END)));
1102-
*batchBufferEnd = GfxFamily::cmdInitBatchBufferEnd;
1103-
}
1102+
programEndingCmd(commandStream, device, &endingCmdPtr, blitterDirectSubmission);
11041103

11051104
EncodeNoop<GfxFamily>::alignToCacheLine(commandStream);
11061105

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverridePatIndex, -1, "-1: default, >=0: PatInde
195195
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")
196196
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")
197197
DECLARE_DEBUG_VARIABLE(int32_t, ForcePreParserEnabledForMiArbCheck, -1, "-1: default , 0: PreParser disabled, 1: PreParser enabled")
198+
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.")
198199
DECLARE_DEBUG_VARIABLE(bool, DisableScratchPages, false, "Disable scratch pages during VM creations")
199200
/*LOGGING FLAGS*/
200201
DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level")

shared/test/unit_test/direct_submission/direct_submission_tests_1.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,46 @@ HWTEST_F(DirectSubmissionTest, givenDirectSubmissionAvailableWhenProgrammingEndi
617617
EXPECT_EQ(expectedSize, mockCsr->getCmdSizeForEpilogue(dispatchFlags));
618618
}
619619

620+
HWTEST_F(DirectSubmissionTest, givenDebugFlagSetWhenProgrammingEndingCommandThenUseNonZeroBatchBufferStart) {
621+
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START;
622+
623+
DebugManagerStateRestore restorer;
624+
625+
DebugManager.flags.BatchBufferStartPrepatchingWaEnabled.set(1);
626+
627+
MockGraphicsAllocation mockAllocation;
628+
629+
int32_t executionStamp = 0;
630+
std::unique_ptr<MockCsr<FamilyType>> mockCsr = std::make_unique<MockCsr<FamilyType>>(executionStamp, *pDevice->executionEnvironment,
631+
pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
632+
633+
mockCsr->setupContext(*osContext);
634+
mockCsr->directSubmissionAvailable = true;
635+
bool ret = mockCsr->isDirectSubmissionEnabled();
636+
EXPECT_TRUE(ret);
637+
638+
void *location = nullptr;
639+
uint8_t buffer[128];
640+
mockCsr->commandStream.replaceBuffer(&buffer[0], 128u);
641+
mockCsr->commandStream.replaceGraphicsAllocation(&mockAllocation);
642+
auto &device = *pDevice;
643+
mockCsr->programEndingCmd(mockCsr->commandStream, device, &location, ret);
644+
EXPECT_EQ(sizeof(MI_BATCH_BUFFER_START), mockCsr->commandStream.getUsed());
645+
646+
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
647+
dispatchFlags.epilogueRequired = true;
648+
size_t expectedSize = sizeof(MI_BATCH_BUFFER_START) +
649+
mockCsr->getCmdSizeForEpilogueCommands(dispatchFlags);
650+
expectedSize = alignUp(expectedSize, MemoryConstants::cacheLineSize);
651+
EXPECT_EQ(expectedSize, mockCsr->getCmdSizeForEpilogue(dispatchFlags));
652+
653+
auto bbStartCmd = reinterpret_cast<MI_BATCH_BUFFER_START *>(mockCsr->commandStream.getCpuBase());
654+
655+
EXPECT_EQ(mockCsr->commandStream.getGraphicsAllocation()->getGpuAddress(), bbStartCmd->getBatchBufferStartAddress());
656+
657+
mockCsr->commandStream.replaceGraphicsAllocation(nullptr);
658+
}
659+
620660
HWTEST_F(DirectSubmissionTest,
621661
givenDirectSubmissionDiagnosticNotAvailableWhenDiagnosticRegistryIsUsedThenDoNotEnableDiagnostic) {
622662
using Dispatcher = RenderDispatcher<FamilyType>;

0 commit comments

Comments
 (0)