gpu: prove indexed buffer writes disjoint from scalar reads #1747
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!1747
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1747/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?
@kewalker on GitHub · 2026-10-20 03:19 UTC · original
kewalker:codex/demons-souls-indexed-write-overlap→main· +270 −2 · 6 files · 4 commits · closed without mergingFixes #1660.
Demon's Souls (PPSA01342) stops at
scalar resource reads overlap a shader buffer writebecause the renderer treats the complete writable buffer binding as a write footprint. In shader72c9c6d90df9ab3d, a scalar loop count is read from bytes 0–3 whileBUFFER_ATOMIC_ADDwrites a four-byte field at64 * index + 24. Those accesses are disjoint even when the 32-bit index arithmetic wraps.Track constant byte offsets and widths for raw DWORD stores and 32-bit integer-add atomics. For aligned, direct, unswizzled buffers with power-of-two strides, check scalar reads against the possible write residues. Unknown offsets, unsupported operations, formatting, lane addition, indirect aliases, and unsupported strides retain the conservative full-buffer check. Existing invalid-range, image-write, and address-write checks remain active. Buffer ownership and synchronization still cover the full binding.
I reviewed the code and the fix and tested it locally. The startup crash previously stopped after 111 compute shaders. With the fix, I passed that crash and reached gameplay in Demon’s Souls. This confirms startup-to-gameplay progress on my setup.
Validation:
resource_tracking_testsandresource_materialization_testsagainst this isolated main-based branch.scalar_buffer_write_bindingsregression throughRenderExecutor::CommitBindings: the disjoint header read succeeds, while a read of the atomic field retains the fatal overlap guard. Registered it with CTest.0cad4672. The standalone PR excludes the unrelated integration/FPS changes.I also merged upstream
mainthrough4644c529. The resolution preserves upstream�s fixed-offsetwrite_extentbound alongside the indexed-write proof. After rebuilding the merged branch, the caller regression passes for disjoint fixed and indexed writes, and both overlapping cases retain the fatal guard. Removing the indexed proof still reproduces the header-read failure. Both resource suites and the renderer compilation check pass. Gameplay validation above was performed before this merge; I have not repeated the game run on the merged branch.Related: #1403. This change retains the same-dispatch overlap guard and permits accesses only when their byte ranges can be proven disjoint.
@kewalker on GitHub · 2026-10-20 03:23 UTC · original
@Nmzik could you review this fix when you have a chance? I tested it locally and reached gameplay in Demon's Souls.
@coderabbitai[bot] on GitHub · 2026-10-20 03:27 UTC · original · edited 2026-10-21 10:30 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
a750bd5a-b1c8-4c91-b5cb-4d6c22dabc48📥 Commits
Reviewing files that changed from the base of the PR and between
29d7b557cband930d50b208.📒 Files selected for processing: 6
CMakeLists.txtsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.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.
📝 Walkthrough
Buffer resources now store supported indexed write patterns and unknown-pattern state.
BufferResource::WritesOverlapchecks queried reads conservatively.CommitBindingsreports scalar-resource read overlap only when both bounded ranges and recorded write patterns overlap. Tests cover indexed footprints, unsupported modes, aliases, disjoint reads, overlapping reads, and subprocess failure cases. CTest now runs the scalar-buffer overlap contract.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to
930d5The change lets disjoint scalar reads proceed past indexed buffer writes while keeping the conservative overlap check for unproven cases. Tests exercise the real commit path, and no concrete merge-blocking risk remains.
Pre-merge checks:
4 ·
1
#1660identifies the scalar-read versus shader-buffer-write failure. The PR adds indexed write-pattern tracking for supported raw DWORD stores and 32-bit integer-add atomics. `RenderExecutor::Co…#1660. No…Full details: Linked Issues check
Explanation
Issue
#1660identifies the scalar-read versus shader-buffer-write failure. The PR adds indexed write-pattern tracking for supported raw DWORD stores and 32-bit integer-add atomics.RenderExecutor::CommitBindingsapplies the bounded-range andWritesOverlapchecks. Unsupported cases retain conservative checking. Existing safety checks remain active.ResourceTrackingTestsandShaderRecompilerComputeTestscover disjoint, overlapping, wrapped, multiple-writer, and fallback cases. The reported gameplay run uses PPSA01342, while issue#1660lists PPSA01341, so that runtime report does not independently verify the issue's exact serial. The coding requirements are implemented and tested.Full details: Out of Scope Changes check
Explanation
The changes are limited to indexed buffer write tracking, descriptor overlap validation, focused documentation, regression tests, and CTest registration. These changes directly support issue
#1660. No unrelated feature or behavior change is demonstrated.Full details: Docstring Coverage
Explanation
Docstring coverage is 53.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 4 files. (2 skipped: 1 unsupported, 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-20 03:37 UTC · original · reviewed
🧹 Nitpick comments: 1
ℹ️ Review info
⚙️ Run configuration
2452ab62-1418-4ef4-84b5-06a45446035e📥 Commits
Reviewing files that changed from the base of the PR and between
dfeb99f97dandc2529858ff.📒 Files selected for processing: 4
src/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.cpp🚧 Files skipped from review as they are similar to previous changes: 4
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@Nawid3333 on GitHub · 2026-10-20 14:17 UTC · original
@kewalker @Nmzik both this PR and my #1630 say "Fixes #1660" (Demon's Souls,
scalar resource reads overlap a shader buffer write), so I compared them on the shader from kavg13's #1591 log (CS 0x02632cb15eb8128d, PPSA01341). Its shape looks like the one described here: a count read from bytes 0-3 of a buffer that the same dispatch updates withBUFFER_ATOMIC_ADDat record * stride + 24. The log has no buffer descriptor, so the stride of that buffer is unknown.I rebuilt the shader from the log's listing and ran Kyty's recompiler on it on the CPU, then applied CommitBindings' overlap rule (with this PR's
BufferResource::WritesOverlapwhen applied), all on0cad4672:0cad4672So the two take different routes: this PR keeps the captured read and proves the written bytes disjoint, which needs a power-of-two stride; #1630 stops capturing a read of a value the shader itself writes when it only decides a branch. This PR also covers reads that are not branch decisions, which #1630 does not touch (like UFC 6's record count in #1738). For PPSA01341 the result depends on the real stride, so both may be needed.
Game runs so far: volan3 got past the error on PPSA01341 with #1630 (#821), and you got past it on PPSA01342 with this PR. I can share the reconstruction test if it helps.
Pull request closed