From 1dca7b4f40b5e96132722dc783ed7eeee0d8b5af Mon Sep 17 00:00:00 2001 From: Scott Schuster Date: Wed, 7 Oct 2026 16:07:13 -0500 Subject: [PATCH] perf(recompiler): load the written-page slot before the CAS note_bda_write ran a device-scope compare-exchange on every probe, also when the slot already held the page. The table lives in host-visible memory, so each BDA store paid an atomic across PCIe, and nearly every store hits a page an earlier store noted. Load the slot first and only compare-exchange when it does not hold the page. The slots probed, the pages recorded and the overflow report are unchanged. DOOM (PPSA99666) presents through a compute kernel that stores about two million pixels through raw pointers per frame: 248 ms per dispatch before, 8.1 ms after, on an RTX 5070 Ti. Co-Authored-By: Claude Opus 5.5 --- .../recompiler/SpirvBackend/src/SpirvBdaLookup.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp b/core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp index 24da16879..d69bbb7f0 100644 --- a/core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp +++ b/core/shader/recompiler/SpirvBackend/src/SpirvBdaLookup.cpp @@ -153,10 +153,16 @@ static std::uint32_t DefineBdaNoteWrite(SpirvEmitterState& state) { state.module.AddFunction(spv::OpBranchConditional, searching, body, merge); EmitLabel(state, body); const auto slot = binary(spv::OpIAdd, u32, constant(BdaAbi::WrittenSlotsWord), binary(spv::OpBitwiseAnd, u32, binary(spv::OpIAdd, u32, hash, probe), constant(BdaAbi::WrittenPageSlots - 1u))); - const auto previous = state.module.AllocateId(); - state.module.AddFunction(spv::OpAtomicCompareExchange, u32, previous, BdaWord(state, state.faultBufferVariable, slot), scope, relaxed, relaxed, page, constant(0u)); - const auto taken = binary(spv::OpLogicalOr, boolean, binary(spv::OpIEqual, boolean, previous, constant(0u)), binary(spv::OpIEqual, boolean, previous, page)); - state.module.AddFunction(spv::OpStore, done, taken); + const auto current = state.module.AllocateId(); + state.module.AddFunction(spv::OpAtomicLoad, u32, current, BdaWord(state, state.faultBufferVariable, slot), scope, relaxed); + const auto held = binary(spv::OpIEqual, boolean, current, page); + state.module.AddFunction(spv::OpStore, done, held); + EmitIfCondition(state, Unary(state, spv::OpLogicalNot, boolean, held), [&] { + const auto previous = state.module.AllocateId(); + state.module.AddFunction(spv::OpAtomicCompareExchange, u32, previous, BdaWord(state, state.faultBufferVariable, slot), scope, relaxed, relaxed, page, constant(0u)); + const auto taken = binary(spv::OpLogicalOr, boolean, binary(spv::OpIEqual, boolean, previous, constant(0u)), binary(spv::OpIEqual, boolean, previous, page)); + state.module.AddFunction(spv::OpStore, done, taken); + }); state.module.AddFunction(spv::OpBranch, continuation); EmitLabel(state, continuation); state.module.AddFunction(spv::OpStore, counter, binary(spv::OpIAdd, u32, probe, constant(1u)));