shader: issue BDA loads without a branch per access #1296
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1296
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1296/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@NeySlim on GitHub · 2026-10-09 10:52 UTC · original
NeySlim:perf/bda-branchless→main· +792 −108 · 12 files · 7 commits · closed without mergingDepends on #1294 (fault buffer summary): the deferred fault records use its
RecordBdaFault.Problem
Shaders that read guest memory through BDA (FLAT and GLOBAL loads, scalar loads from a computed address, buffer loads whose descriptor is read at run time) translate every dword through the page table. The emitted code branches on the page-table entry before the data load: a missing page skips the load and records a fault. The branch needs the entry, so each dword waits for its lookup, and the next load cannot issue before that. A shader that reads 100 dwords waits for 100 page-table lookups in sequence.
In God of War Ragnarök (PPSA08332) most of the expensive compute passes read their descriptors and data this way. In the compiled code of four of the hottest ones, each has 1072 to 1268 branches and 815 to 879
s_waitcnt, mostly from these lookups.Change
For addresses inside the cached range, the values read and the pages reported are unchanged.
Test
BdaLoadsLookUpPagesWithoutBranches:s_load_dwordx4from a computed address and a FLAT load from an unmapped page. The values and the fault are checked, and the SPIR-V keeps one checked lookup (the unaligned FLAT path) instead of six.IndirectBufferLoadsLookUpPagesWithoutBranches: the existing run-time descriptor case (11 descriptors, in and out of bounds, unbound) with no checked lookup left.FlatLoadOfInactiveLaneRecordsNoFault: a FLAT load from an unmapped page by a lane disabled in EXEC keeps the old value and records no fault (new harness fieldfault_free_pages).Validation
shader_recompiler_compute_tests, one case per process (with the fault buffer summary change): identical results to origin/main apart from the new passing cases. The 10 cases that already fail on origin/main with this driver fail the same way.s_waitcnt. Screenshots are unchanged.AI use
I used Claude Code (AI agent) to profile the GPU time and the compiled code of the hottest shaders, write the change and the tests, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-09 10:58 UTC · original · edited 2026-10-13 23:06 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
9672798b-5484-4ba3-98f1-f14d0400b63d📥 Commits
Reviewing files that changed from the base of the PR and between 5242e8c9e2a3eedeb70e8f7ee3fbbd5ddab9f09a and 09d6a7e95da3cbb2509d35c90058dba10695fb55.
📒 Files selected for processing: 5
src/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpptests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
Priority: ➖ Normal
Change: Refactor
Merge Risk: ⚪ Minimal · up to
09d6aThe previously identified GPU test setup issues are addressed, and the inspected BDA and fault-processing paths show no remaining merge-blocking issue.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 22.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 9 files. (2 skipped: 2 too large.)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -5457,0 +5644,4 @@"test pages share fault words");words.push_back(page >> 5);words.push_back(summary);scheduler.Current().Handle().updateBuffer(faults.Handle(), (page >> 5) * sizeof(u32),@coderabbitai[bot] on GitHub · 2026-10-09 10:58 UTC · original · edited 2026-10-09 11:39 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2804
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9330
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19817
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4618
Clear the fault buffer before writing the summary fixture.
Buffer::Bufferdoes not initialize device-local allocations.CheckFaultBufferSummarywrites only selected words beforeProcessFaultBuffer()scans the buffer. Unwritten summary words may therefore trigger unrelated bitmap scans.Suggested fix
✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-09 10:58 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
6c5da140-0e54-49a9-854d-a75ecc28d32e📥 Commits
Reviewing files that changed from the base of the PR and between
7b9997baeaand 1a0056db14f6e97a269ad02f1f65b7e405fa3e80.📒 Files selected for processing (10)
src/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/faultManager.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/shaders/fault_buffer_process.compsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpptests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.
@ -5457,0 +5644,4 @@"test pages share fault words");words.push_back(page >> 5);words.push_back(summary);scheduler.Current().Handle().updateBuffer(faults.Handle(), (page >> 5) * sizeof(u32),@NeySlim on GitHub · 2026-10-09 11:30 UTC · original
Agreed, and the gap was in the renderer too: the production fault buffer and the BDA page table were never cleared at creation. Both are now cleared when the buffer cache creates them, in #1294 (de6966b1 for the fault buffer in
FaultManager, ccfcb32a for the page table inBufferCache), each with its own submission because the command scheduler is not bound yet.FaultBufferStartsClearedandBdaPageTableStartsClearedcreate a renderer whose new device memory has every bit set, and fail without the clears.FaultBufferSummaryalso clears the buffer before writing its fixture, as suggested. This branch is rebased on top.@coderabbitai[bot] on GitHub · 2026-10-09 11:36 UTC · original · edited 2026-10-09 12:03 UTC
On
tests/ShaderRecompilerComputeTests.cppline 5261 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42457
Do not bind the temporary buffer to dedicated memory.
If VMA returns a dedicated allocation for a renderer buffer or image,
bindBufferMemorycannot bind the new temporary buffer to that allocation. The dirty-memory fixture can therefore fail during setup before it checks the cleared state.Fill the renderer allocation through its already-bound resource, or make the fixture handle dedicated allocations explicitly.
✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-09 11:36 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
e2537fca-4631-41e1-ae58-6c3575d2937c📥 Commits
Reviewing files that changed from the base of the PR and between 1a0056db14f6e97a269ad02f1f65b7e405fa3e80 and a67c0014f4de90e61264ec26ff563cf805725ff1.
📒 Files selected for processing (5)
src/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/faultManager.cppsrc/graphics/host_gpu/renderer/cache/streamBuffer.cppsrc/graphics/host_gpu/renderer/cache/streamBuffer.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.
@ -5457,0 +5644,4 @@"test pages share fault words");words.push_back(page >> 5);words.push_back(summary);scheduler.Current().Handle().updateBuffer(faults.Handle(), (page >> 5) * sizeof(u32),@coderabbitai[bot] on GitHub · 2026-10-09 11:39 UTC · original
🧩 Analysis chain
🏁 Script executed:
Length of output: 13430
@NeySlimThanks for the clarification. I verified thatCheckFaultBufferSummaryclears the full fault buffer before writing its fixture.Both constructors also clear their buffers with separate submissions. The dirty-memory regression tests are present; I did not run them.
✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-09 11:54 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 5261 (outdated):Right: the registered guest buffer (shader device address) gets a dedicated allocation, and the fixture bound a temporary buffer to it. Fixed in 7ed6cc3d: the test allocator now wraps
vkAllocateMemoryand poisons only memory allocated withoutVkMemoryDedicatedAllocateInfo. Its block size is large enough for the page table and the fault buffer to be block allocations, and both checks require a poisoned block that can hold their buffer. Both still fail without the clears.@coderabbitai[bot] on GitHub · 2026-10-09 12:03 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 5261 (outdated):@NeySlimThanks for fixing this in7ed6cc3d. Excluding memory allocated withVkMemoryDedicatedAllocateInfoaddresses the invalid temporary-buffer binding. Requiring a sufficiently large poisoned block keeps the initialization checks meaningful. Your reported failures without the clears confirm that the checks still detect missing initialization.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-19 19:09 UTC · original
Closing this one. Main now emits the raw indirect buffer loads as shared function bodies (
c1f6838e4), so the branch-free load would have to be redone on top of that rather than rebased. I'll come back with a new PR if the lookup chains still show up in the hot passes after that.Pull request closed