shader: accept scalar loads that precede a dispatch's own buffer writes #1253
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!1253
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1253/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?
@TheCruZ on GitHub · 2026-10-08 20:04 UTC · original
pr/scalar-read-before-own-write→main· +331 −8 · 8 files · 1 commits · closed without mergingSummary
Fixes the emulator exiting with
scalar resource reads overlap a shader buffer writewhen a Fidelity mode (ray tracing) save of Grand Theft Auto V (PPSA04263) is loaded. The failing dispatch is the BVH build compute shadercs 9df701ab41f8ed18.Problem
The shader
S_LOADs the flags dword at offset0x18of aPSR_BVHLheader, then sets a bit in that same dword withBUFFER_ATOMIC_OR_X2through a V# over the header, and traps when bit 4 of the loaded value is set. Since branch reachability is refreshed from scalar reads, that load is a specialization read captured at dispatch time, andCommitBindingsexits whenever a specialization read overlaps a buffer that any bound shader writes.Here the overlap is harmless: each wave issues the load before its own writes to the buffer, so the dispatch-time snapshot is a value the load observes on hardware.
Change
RawReadSlot), inResourceSnapshot::specialization_read_slots(SrtRuntime::read_slotis set by the walker around each load).SrtReadsAfterBufferWritesrecords for each slot and each such load the written buffers whose stores or atomics may precede it in program order (loops included; a load the analysis did not see counts as following every write); they are kept inCompiledShaderInfo.CommitBindingsaccepts an overlap with the reading shader's own buffer only whenSpecializationReadFollowsBufferWritesays no write to that buffer can precede the read. Loads that follow a write to the buffer, overlaps with other stages' buffers and overlaps with images still exit as before.Upstream
ec3e48cd(written compute descriptors read without an alias proof) does not cover this case: here the read is a specialization read of branch reachability, not a descriptor.Testing
resource_tracking_tests: newTestScalarReadBeforeOwnBufferWritebuilds the BVH header pattern with the read before the write (accepted), the write before the read (rejected) and the write in a loop back to the read (rejected), and checks that an earlier store to another buffer is still reported and that a load the analysis did not see is treated as following the writes. Passes.resource_materialization_tests,memory_tracker_tests,page_manager_tests,shader_cfg_tests,virtual_memory_allocation_testsand the default run ofshader_recompiler_compute_testspass.AI usage
AI (Claude Opus 5.5) was used to investigate the issue and to implement the change. I reviewed the code, understand it, tested it as described above, and wrote this description myself, in general fully tested the game while doing few missions and playing in-game with my GTA V fork, i will be bringing PRs here after test them enough.
@coderabbitai[bot] on GitHub · 2026-10-08 20:09 UTC · original · edited 2026-10-08 21:12 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
e894c118-8574-47c8-ab26-686330f5d402📥 Commits
Reviewing files that changed from the base of the PR and between 19a1258a4213a382aaacc3639e03f0cbea8a2095 and
0e3c6c87f6.📒 Files selected for processing (2)
src/graphics/shader/recompiler/ir/Program.cpptests/ResourceTrackingTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
📝 Walkthrough
Walkthrough
The change records the slot for each specialization read, analyzes possible buffer writes before SRT and raw reads, and stores the results in compiled shader metadata. Renderer binding checks use this ordering information for same-stage buffer overlaps. Added tests cover read-first, write-first, and loop execution orders.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
0e3c6The previously reported raw-read overlap risk is fixed at the reviewed head. No actionable merge-blocking issue remains from the supplied evidence.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.@coderabbitai[bot] on GitHub · 2026-10-08 20:09 UTC · original · edited 2026-10-08 21:14 UTC
On
src/graphics/shader/recompiler/ir/Program.cppline 315 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Track
LoadBufferU32raw reads. Treat a raw-read slot with no analysis entry as following a write.SrtWalker::EvaluateRawRead(SrtWalker.cpp Lines 530-532) assignsRawReadSlot(index)to every unflattened raw read. That includesLoadBufferU32reads, and the capture records those reads throughCaptureStrictRead.This loop fills
raw_afteronly forLoadAddressU32andReadConstBuffer. For aLoadBufferU32memory index,raw_reads_after_buffer_writes[index]keeps the empty vector fromraw->assign(...).SpecializationReadFollowsBufferWritepasses the size check for that index. It then searches an empty list and returnsfalse, which means "no write precedes this read".Consequence: in
CommitBindings(descriptors.cpp Lines 1041-1043), the check now skips the exit when a same-stageLoadBufferU32specialization read overlaps a buffer the shader writes earlier. Before this change, every such overlap exited. Now the snapshot can be stale with no diagnostic.The same failure applies to any raw-read index that the final IR no longer contains. The query returns "safe" when it has no data, so the default is not conservative.
Fix:
ValueOpcode::LoadBufferU32in the raw-read branch.std::optional, or keep a separate analyzed flag. Returntruefrom the query when an entry was not analyzed.Proposed fix for the raw-read branch
Also mark entries that were never analyzed as conservative. For example, fill all buffer indices into raw entries whose
raw_after[memory]stayed empty because no instruction with that index was visited.📝 Committable suggestion
✅ Confirmed as addressed by @TheCruZ
@coderabbitai[bot] on GitHub · 2026-10-08 20:09 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
c34ea8aa-3b24-479e-8f0c-76c458271d04📥 Commits
Reviewing files that changed from the base of the PR and between
2f4b8a335dand 19a1258a4213a382aaacc3639e03f0cbea8a2095.📒 Files selected for processing (8)
src/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/shader/recompiler/ir/Program.cppsrc/graphics/shader/recompiler/ir/ResourceSnapshot.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.htests/ResourceTrackingTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@TheCruZ on GitHub · 2026-10-08 21:08 UTC · original
On
src/graphics/shader/recompiler/ir/Program.cppline 315 (outdated):Fixed in
0e3c6c8:LoadBufferU32is recorded like the other raw reads, and a raw-read index the analysis never saw now lists every written buffer, soSpecializationReadFollowsBufferWriteis conservative when it has no data.TestScalarReadBeforeOwnBufferWritechecks the unanalyzed case.@coderabbitai[bot] on GitHub · 2026-10-08 21:14 UTC · original
On
src/graphics/shader/recompiler/ir/Program.cppline 315 (outdated):@TheCruZ, thanks for the fix. The provided code recordsLoadBufferU32raw reads and fills unanalyzed entries with every buffer index. This makesSpecializationReadFollowsBufferWriteconservative when analysis data is missing and addresses both parts of the finding.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.
@Crispy81 on GitHub · 2026-10-08 22:27 UTC · original · edited 2026-10-08 22:28 UTC
Out of curiosity, would this PR cover:
scalar resource reads overlap a shader buffer write
in D:\a\KytyPS5\KytyPS5\src\graphics\host_gpu\renderer\pipeline\descriptors.cpp:1038
or is it a separate issue?? I've seen this error on a few games.
@tv7 on GitHub · 2026-10-10 13:32 UTC · original
Another title that stops on this error: SILENT HILL: Townfall (PPSA33286 v02.003.000), Windows 11, RTX 3070 (driver 617.14).
307fdcf: exits about 5 s after start withscalar resource reads overlap a shader buffer write(descriptors.cpp:978), black window, 1 VS / 30 CS compiled.buffer descriptor is not a valid runtime value(ResourceTracking.cpp:506, compute0xb9da5e64f4c5b10a), which is unrelated to this PR.Full logs and details: #1373
Tested and written with Claude (AI assistant) on my machine.
Pull request closed