gpu: allow compute dispatches to read buffers they write through scalar loads #1403
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!1403
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1403"
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?
@ReverendOzmund on GitHub · 2026-10-11 07:02 UTC · original
ReverendOzmund:fix/compute-self-overlap→main· +13 −2 · 1 files · 4 commits · openHalo: Campaign Evolved (PPSA28038) stops at
scalar resource reads overlap a shader buffer write(descriptors.cpp) right when the menu narration prompt comes up. added logging to see what was overlapping and its a single compute shader overlapping itself:so its one dispatch reading a dword at offset 0x18 of a 256 byte buffer it also writes (looks like a small control/counter block)
this skips the check only when the writer is the same compute stage as the reader. reasoning: on hardware those scalar loads go through the scalar cache which isnt coherent with the dispatch's own vector writes, so the value at dispatch start (what the specialization captured) is a valid result, and the next dispatch re-materializes from memory anyway. cross stage overlaps, image writes and address writes all still EXIT like before
i know this check is there on purpose so if youd rather handle it differently (narrower write ranges, per-dword tracking etc) happy to change it
testing
ai
used claude to add the diagnostics, work out what was overlapping and write the fix. i ran all the testing myself
@ReverendOzmund on GitHub · 2026-10-11 07:03 UTC · original
same shader hits it on 3 different 256 byte buffers (1051b10000, 1050ae0000, 1024220000), always reading offset 0x18, so it looks like a per-instance control block not a one off
@ReverendOzmund on GitHub · 2026-10-11 07:04 UTC · original
@coderabbitai[bot] on GitHub · 2026-10-11 07:05 UTC · original · edited 2026-10-11 09:53 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
f0acc520-9d9e-4fe8-bfc4-1eeb3b3d8c4e📥 Commits
Reviewing files that changed from the base of the PR and between
7ee598b4c7andf26b1d7e62.📒 Files selected for processing (1)
src/graphics/host_gpu/renderer/pipeline/descriptors.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
📝 Walkthrough
📝 Walkthrough
Walkthrough
FindBufferspermits sentinel-sized buffer writes to overlap scalar reads from the same compute stage.CommitBindingsskips scalar-read overlap checks against buffer writes from the same compute dispatch. Both functions retain checks for other stages;CommitBindingsalso retains checks for image and attachment writes.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
a9e73The targeted same-dispatch reads can proceed when their descriptors fit the device limits, while the other overlap checks remain. No material new user-facing risk is established.
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.@ -973,0 +980,4 @@// writes, so the value captured at dispatch start is a valid result. The next// dispatch re-materializes its specialization from memory, so the writes are still// observed from then on.if (writer == reader && program.stage == ShaderType::Compute) continue;@coderabbitai[bot] on GitHub · 2026-10-11 07:05 UTC · original · edited 2026-10-11 07:19 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Apply the compute exception before
FindBuffershandles sentinel writes.If a writable buffer has
NumRecords()==UINT32_MAXand overlaps a specialization read,FindBuffersruns first. It can exit on the overlap or truncate the write range at the read address, so this exception cannot preserve the full same-dispatch write range. Update that earlier check to allow same-stage compute overlaps while retaining cross-stage checks. The compute path insrc/graphics/host_gpu/renderer/renderCompute.cpp, Lines 337–356, callsFindBuffersbeforeCommitBindings.✅ Addressed in commit
7ee598b@coderabbitai[bot] on GitHub · 2026-10-11 07:05 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
0bad9939-d60d-49d6-a45e-d5b6940013f9📥 Commits
Reviewing files that changed from the base of the PR and between
730e1a3cf3anda9d34f7074.📒 Files selected for processing (1)
src/graphics/host_gpu/renderer/pipeline/descriptors.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -973,0 +980,4 @@// writes, so the value captured at dispatch start is a valid result. The next// dispatch re-materializes its specialization from memory, so the writes are still// observed from then on.if (writer == reader && program.stage == ShaderType::Compute) continue;@ReverendOzmund on GitHub · 2026-10-11 07:10 UTC · original
good catch, the sentinel range path in FindBuffers had the same check. applied the same same-stage compute exception there so both places agree. halo didnt hit that path so its just for consistency, retested halo + shader_recompiler_compute_tests still pass
@coderabbitai[bot] on GitHub · 2026-10-11 07:14 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
0f2eda76-44a4-472f-b0fc-889023d638f8📥 Commits
Reviewing files that changed from the base of the PR and between
a9d34f7074and7ee598b4c7.📒 Files selected for processing (1)
src/graphics/host_gpu/renderer/pipeline/descriptors.cpp🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@ -973,0 +980,4 @@// writes, so the value captured at dispatch start is a valid result. The next// dispatch re-materializes its specialization from memory, so the writes are still// observed from then on.if (writer == reader && program.stage == ShaderType::Compute) continue;@coderabbitai[bot] on GitHub · 2026-10-11 07:20 UTC · original
@ReverendOzmundThanks for the fix and retesting.FindBuffersnow applies the same-stage compute exception before it bounds sentinel write ranges. Cross-stage checks remain intact, so this addresses 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.
@ReverendOzmund on GitHub · 2026-10-11 07:26 UTC · original
fyi the windows failure here is from main not this PR,
smallis a windows sdk macro (b7b335a). fix is up in #1404@ReverendOzmund on GitHub · 2026-10-11 07:38 UTC · original
fair point on the sentinel range, skipping own reads entirely let the range grow past what it was before. changed it so own compute reads after the buffer start still end the range like before (so it can never get bigger than it used to), and only the overlap-at-start case that used to EXIT is allowed. range splitting would be a bigger change so leaving that for the maintainers if they want it. retested halo + shader_recompiler_compute_tests, both fine
@theantipopau on GitHub · 2026-10-11 07:40 UTC · original
Cross-checked this against the recompiler side (
58b2295clocal checkout) — thanks for the quick Halo repro, this unblocksscalar resource reads overlap a shader buffer writefor self-reads that are architecturally valid on GCN.A few code-level notes from reading the diff against the current head of
main:1. The
gpu_scalar_readsBDA path is unaffected (good).FindBdaBuffers(snapshot.gpu_scalar_reads)inFindBuffersruns before the sentinel loop and doesn't consultspecialization_reads, so GPU-side scalar loads (theLoadAddressU32plan from commit 58b2295cb8) still get made resident unconditionally per stage. Only the host-side scalar-read plan (specialization_reads) sees the skip.2.
writer == reader && Computeskip is keyed on pointer identity ofPreparedBindings. That's fine for a single dispatch, but note in the staggered case where the same compute program is bound twice in one command sequence (e.g.prepared_bindingscontaining two entries of the same runtime), the skip only fires when they alias. Worth a brief comment in the PR that aliasing two different dispatches of the same shader still enforces the overlap check — that's the semantics you want.3. Coderabbit's ClampRangeSize note looks real but is unrelated to the skip condition.
ClampRangeSize(address, size)at descriptors.cpp:842 already clamps down to host-mapped size beforeNativeStorageBufferruns thesize > maxStorageBufferRange/adjustmentchecks. If a sentinel write range (that reaches theelsebranch instead of the sentinel path) is what the note is about, that's outside this diff — worth filing separately.4. On the "skip only when
writer == readerandstage == Compute" rationale — matches the SAROS pattern inResourceTracking.cpp(line ~811): shader-side atomics through GPU scalar loads deliberately keep their payload off the host recall plan for exactly this reason; the value at dispatch start is well-defined. Same reasoning applies here for scalar reads that overlap self-writes when the shader is re-specialized per dispatch anyway.If CI turns green (the current Windows failure is a pre-existing
const auto smallRPC macro collision introduced byb7b335aon main — see #1404 for the unrelated fix), this is good to merge from my side. Nice find on always reading offset 0x18 across three different buffer addresses; that matches a per-instance control-counter pattern (a workgroup index table, likely).@ReverendOzmund on GitHub · 2026-10-11 07:43 UTC · original
thanks for the thorough look
on 2, yeah thats intended. the skip only fires when writer and reader are literally the same PreparedBindings, so two different dispatches of the same shader (or the same program bound twice in one sequence) still go through the overlap check like before. only a dispatch reading its own writes gets the pass
on 3, agreed its separate. the latest commit keeps own reads after the buffer start ending the sentinel range like before so this PR cant make that range any bigger than it already was
windows should go green once #1404 is in
@theantipopau on GitHub · 2026-10-12 10:18 UTC · original · approved these changes
Re-checked against main (merge-base
f3836bb8) after the sentinel-range revision:has_address_writesEXIT and the image/attachment overlap EXIT still run unconditionally ahead of the new skip, so the only loosened case is the exact self-pair (writer == reader, pointer identity on PreparedBindings), and two different stages binding the same compute program still enforce the check.own_compute_readsonly suppresses the EXIT below the range start; theread_address > addressbranch still shrinks the sentinel range at the first own read above the buffer base, so a shifted table keeps bounding it and the range can't grow past what it was before. Own reads below the start no longer abort — which is the Halo control/counter case.Windows CI was pre-existing
smallmacro fallout (fixed by #1404) and is now green on all three platforms with this head (run 38129958667). LGTM.@ReverendOzmund on GitHub · 2026-10-12 12:05 UTC · original
thanks for the thorough re-check! appreciate you going through the sentinel range bit too
@ReverendOzmund on GitHub · 2026-10-18 07:43 UTC · original
re-tested on latest main (
37df7f3) + #1365, still needed for halo to get to the title screen on linux. merges clean, no conflicts(used claude to help with this, tested it myself)
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.