renderer: check scalar reads against the bytes a shader buffer write can reach #1738
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!1738
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1738/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?
@0xcrstn on GitHub · 2026-10-19 23:46 UTC · original
0xcrstn:fix/ufc6-scalar-read-write-range→main· +315 −9 · 6 files · 2 commits · closed without mergingGame and problem
EA SPORTS UFC 6 (PPSA23566, 01.004.000), Windows 11, RTX 5090 (driver 617.42), with a save that boots straight to the main menu. About 40-70 s after start the emulator exits with:
On
mainthe game hits the GPU fault that #1737 fixes before it gets this far. The exit is still onmain: with that fault avoided by skipping the one shader that triggers it (a diagnostic build, no #1737),mainstops here too, 2 of 2 runs at the same point.Cause
I logged every stage, read and written buffer at the exit:
0x940345cace0f5304, reading and writing.0x34of a 56-byte struct:s_load_dword s18, s[4:5], 0x34(pc 0x000c). The value becomes the record count of four other buffers.s[4:7], stride 56, 1 record, so the bound range is 56 bytes.s[4:7]in the shader binary arebuffer_atomic_addat offset 0x24 (pc 0x0334),buffer_store_dwordat 0x28 (pc 0x0368) andbuffer_atomic_addat 0x2c (pc 0x03cc), all with offen=0, idxen=0 and soffset 0. They cover bytes 0x24-0x2f.No write can reach the dword at 0x34.
CommitBindingsexits because it treats the descriptor's whole bound range as written.Change
ResourceTrackingrecords, per buffer, the bytes its writes can reach relative to the descriptor base (written_begin/written_end), when every write has index 0 and constant VGPR and SGPR offsets. That is the addressCalculateBufferAddresscomputes. Any other write, and any formatted store, marks the range dynamic.written_slack).CommitBindingsgathers each written buffer's range once per draw or dispatch (AppendShaderBufferWrites) and compares specialization reads with it. It falls back to the whole bound range when the V# has ADD_TID or swizzle, the range is dynamic, or the range does not fit the bound range. The check is therefore unchanged for every write it cannot bound. The image/attachment and address-write checks are untouched.For UFC 6 the gathered write range is 0x21-0x33 and the read is 0x34-0x37.
This is narrower than #1403, which skips the check for any compute dispatch reading its own writes; its author offered "narrower write ranges, per-dword tracking" as an alternative. The two don't conflict. #1285 changes the same loop for performance; the gathered ranges are what a merged-range list would consume. The
FindBufferssentinel path (NumRecords == UINT32_MAX) keeps its own check unchanged; UFC 6 does not reach it.Testing
CheckBufferWrittenRangesinShaderRecompilerComputeTests.cpp:It fails without the tracking, without the slack, and with the descriptor looked up by slot.
shader_recompiler_compute_tests: all cases pass (Windows, clang-cl, RTX 5090).AI use
Claude Code did the investigation (diagnostic logging, shader binary decoding, IR reading), wrote the change and the test, ran the tests and the scripted game runs, and ran the CodeRabbit, Codex and Claude reviews (the Codex review found the 64-bit atomic alignment case, now fixed). I reviewed the evidence and the change and played the game on the integration build.
@coderabbitai[bot] on GitHub · 2026-10-19 23:53 UTC · original · edited 2026-10-20 00:16 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
a380fb40-0d97-4761-b598-925bc7b83b6d📥 Commits
Reviewing files that changed from the base of the PR and between
0fbf0d2827and598f6b01d5.📒 Files selected for processing: 1
tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
📝 Walkthrough
The change records shader buffer write bounds, slack, and dynamic status during resource tracking. Prepared bindings derive valid shader buffer write ranges and use them to check scalar specialization reads for overlap. Tests cover constant and dynamic writes, range narrowing, fallback cases, buffer gathering, and scalar-read overlap handling.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
598f6The new checks cover the intended overlap behavior, and no merge-blocking issue is identified.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 5 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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-19 23:53 UTC · original · reviewed
🧹 Nitpick comments: 1
ℹ️ Review info
⚙️ Run configuration
a9d03ed4-f386-4d38-85a7-ef72af74819b📥 Commits
Reviewing files that changed from the base of the PR and between
0cad4672e9and0fbf0d2827.📒 Files selected for processing: 6
src/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/descriptors.hsrc/graphics/host_gpu/renderer/render.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@0xcrstn on GitHub · 2026-10-20 00:16 UTC · original
@coderabbitai Thanks, agreed that
CheckBufferWrittenRangesonly checked the narrowed range directly and would not catchCommitBindingsmisusing the gathered writes. Addressed in598f6b01:ScalarReadBufferWriteRangecommits a compute stage throughCommitBindingswith the shape of UFC 6 shader0x940345cace0f5304: constant-offset writes at+0x24..+0x30, and a scalar read at+0x34that must commit.+0x28must exit with the overlap error. This runs in a child process on Windows (--scalar-read-overlap-death, exit code 321) and throughExpectFatalelsewhere.Checked on Windows (RTX 5090), on this branch:
ShaderBufferWrittenRangedisabled, the+0x34read exits withscalar resource reads overlap a shader buffer write.CommitBindingsignoring the gathered writes, the+0x28read no longer exits and the test fails.shader_recompiler_compute_testssuite passes.The Linux
ExpectFatalpath is not compiled or run yet.The test and these checks were written and run by Claude Code (an AI agent) at my direction; I reviewed the results.
@coderabbitai[bot] on GitHub · 2026-10-20 00:17 UTC · original
🧩 Analysis chain
🏁 Script executed:
Length of output: 11211
@0xcrstnThanks for the fix and the detailed validation. I checked the test code. It callsCommitBindingsfor both the non-overlapping read at+0x34and the overlapping read at+0x28. It also runs in the default suite.Your reported Windows mutation checks cover both failure modes from the original concern. This addresses the integration-coverage gap. The Linux
ExpectFatalpath remains unverified; I did not build or run the tests.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
You are interacting with an AI system.
@theantipopau on GitHub · 2026-10-20 00:49 UTC · original · approved these changes
Checked the soundness-critical parts: defaults (begin=MAX, end=0) force the whole-range fallback for untracked buffers; the gather guards dynamic ranges, empty ranges, past-the-end ranges (end+slack > size) and address underflow (address < slack); widening by slack is conservative (can only preserve exits, never skip a real overlap); narrowing applies only to fully-bounded writes with constant index-0 offsets, and ADD_TID/swizzle/formatted stores stay dynamic. The UFC 6 numbers check out (writes 0x24-0x30 + slack 3 = 0x21-0x33 vs read at 0x34). Test covers 32-bit, 64-bit, dynamic, ADD_TID, swizzle, past-the-end, and descriptor-slot aliasing.
@Crispy81 on GitHub · 2026-10-20 10:10 UTC · original
"scalar resource reads overlap a shader buffer write in src/graphics/host_gpu/renderer/pipeline/descriptors.cpp:961"
I've seen a stack of games, including RE Engine games and Little Nightmares games with this exact error, so am keen to see this merged.
@Nmzik on GitHub · 2026-10-21 19:41 UTC · original
Superseded by
68d0ba5a8.Pull request closed