shader: load coherent words with device-scope atomic loads #1613
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!1613
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1613/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?
@Nawid3333 on GitHub · 2026-10-17 17:28 UTC · original
Nawid3333:shader/atomic-coherent-loads→main· +20 −8 · 2 files · 4 commits · closed without mergingFixes #1600.
BufferWorkgroupPublicationWave32/Wave64hang on the Ryzen 7600X iGPU (RDNA2, AMD's non-LLPC compiler): the poll of the predecessor's published word is anOpLoad ... Volatileinside the loop, and that compiler moves it in front of the loop, so every workgroup from ticket 1 on spins on a stale value. In the Vulkan memory model a non-atomic load of a word that another invocation stores at the same time is a data race ("If there does not exist a location-ordered relation between X and Y ... then there is a data race", for X and Y that are "not mutually-ordered atomic operations"), so a compiler may treat the value as loop-invariant.Volatiledoesn't change that, and neither doMakePointerVisible|NonPrivatePointer(measured in #1600).Change: coherent (GLC or DLC) word loads from storage buffers and from global memory are emitted as
OpAtomicLoadat device scope with relaxed semantics: read at the device level, no ordering. Loads through the 8- and 16-bit buffer views stay volatile loads. Stores are unchanged, so the publishing store is still a plain store; the pair is not race-free in the spec's terms, but the poll can no longer be treated as a plain load and stays in the loop.What the compilers make of it (ISA checked): LLPC on the RX 9070 XT emits the same
buffer_load_b32 ... scope:SCOPE_DEVas for the volatile load; the iGPU's compiler emitsbuffer_atomic_addof 0 inside the loop, so on that GPU a coherent load becomes a read-modify-write that adds nothing. Cost in a load-heavy benchmark where every load is coherent (64M strided loads from a 16 MiB host-visible buffer per dispatch, median of 20): RX 9070 XT 5.39 ms before, 5.37 ms after; iGPU 5.42 ms before, 8.80 ms after. The other option from #1600 (volatile load followed by an acquire barrier) took 11.81 ms on the iGPU in the same benchmark.Tests
763d3be3:BufferWorkgroupPublicationWave32/Wave64go from fail to pass on the iGPU (they pass on the RX 9070 XT before and after); every other compute entry and the 30 graphics cases keep their status. The named cases give no validation-layer messages. With the volatile load restored (a local mutant), they fail again in every configuration.BufferWorkgroupPublication(including itsStoreCompletionPublicationcases),BufferLoadsGpuSelectedDescriptors, the non-formatted cases ofBufferLoadGpuSelectedDescriptorsandFlatLoadDlcCapturedrequiredVolatilein the SPIR-V; they now requireOpAtomicLoad.shader_cfg_tests(not run by CI) passes.d8b08a0fmerges main4919fdb6(the only conflict was therequired_spirvline ofBufferLoadsGpuSelectedDescriptors, nowif (!formatted) ... OpAtomicLoad) and drops the code comment aboveEmitCoherentLoad. On it,shader_cfg_testspasses, andshader_recompiler_compute_testson the RX 9070 XT gives the same results as on main:GuardedWaterfallBufferRecordsandSharedIndirectBufferLoadspass;GpuSelectedFormattedRgba16StoreandBufferStoreFormatXAddTidUsesLaneIndexfail on both (to reachSharedIndirectBufferLoads,--indirect-buffer-onlyran with the first of these skipped locally).d8b08a0f.If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it measured this on my PC (driver 26.8.1, Windows 11), wrote the change and ran the tests.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-17 17:35 UTC · original · edited 2026-10-30 20:10 UTC
Walkthrough
Coherent reads in
LoadBdaDwordand volatile-only reads inLoadWordInBoundsnow use device-scopeOpAtomicLoadinstructions with no memory semantics. Non-coherentLoadBdaDwordreads continue to use aligned ordinary loads. Five compute test expectations now check forOpAtomicLoadinstead of volatile load text.Suggested reviewers:
shadowbeat070Change: Bug fix · Severity of issue fixed: Medium
Merge Risk:
Moderate · up to
d8b08Polling and publication still use mismatched atomicity, so cross-workgroup publication may remain unsynchronized; resolve this before merging.
Pre-merge checks:
4 ·
1
#1600requires a coding fix so that the polling load of BufferWorkgroupPublicationWave32/Wave64 stays inside the loop on the iGPU. The reviewed head implements option 1 of the issue. In spirvEmi…Full details: Linked Issues check
Explanation
Issue
#1600requires a coding fix so that the polling load of BufferWorkgroupPublicationWave32/Wave64 stays inside the loop on the iGPU. The reviewed head implements option 1 of the issue. In spirvEmitterMemory.cpp, the new EmitCoherentLoad emits OpAtomicLoad at ScopeDevice with MemorySemanticsMaskNone (relaxed). LoadBdaDword calls it for coherent global-memory words. LoadWordInBounds calls it when memory_access equals MemoryAccessVolatileMask. Noncoherent BDA loads keep the aligned OpLoad. Stores are unchanged. Subword (8/16-bit) paths are not modified and remain volatile. The updated tests in ShaderRecompilerComputeTests.cpp (BufferWorkgroupPublication, BufferLoadsGpuSelectedDescriptors, BufferLoadGpuSelectedDescriptors, FlatLoadDlcCaptured, CheckGuardedWaterfallBufferRecords) require OpAtomicLoad. The Wave32/Wave64 runtime results on the iGPU are reported by the author. I did not run the tests. The code evidence supports the change, so the requirement is met.Full details: Out of Scope Changes check
Explanation
Whole-PR diff against the merge base contains two files. spirvEmitterMemory.cpp adds EmitCoherentLoad and routes coherent word loads through it. These changes implement the issue. ShaderRecompilerComputeTests.cpp changes only the required_spirv expectations from Volatile to OpAtomicLoad in the five cases tied to coherent word loads. These are supporting test updates required by the new code. No unrelated change is shown. The non-coherent BDA path, the subword paths, and store emission are unchanged, which matches the stated scope.
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 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.@ -170,0 +170,4 @@void EmitCoherentLoad(EmitterState& state, uint32_t value, uint32_t pointer) {state.builder.AddFunction(spv::OpAtomicLoad, TypeU32(state), value, pointer,ConstantU32(state, spv::ScopeDevice),ConstantU32(state, spv::MemorySemanticsMaskNone));@coderabbitai[bot] on GitHub · 2026-10-17 17:35 UTC · original · edited 2026-10-17 17:38 UTC
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10227
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41987
🌐 Web query:
official SPIR-V Vulkan memory model atomic load non-atomic store data race MemoryModelGLSL450💡 Result:
🌐 Web query:
official SPIR-V GLSL450 memory model atomic load non-atomic store volatile coherent synchronization💡 Result:
🌐 Web query:
site:registry.khronos.org OpenGL Shading Language 4.60 coherent volatile memory barrier inter shader invocation buffer synchronization💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42272
Use a matching atomic publication store.
BufferWorkgroupPublicationWave32andBufferWorkgroupPublicationWave64poll a coherent buffer word withOpAtomicLoad, but the publisher writes it with a non-atomicOpStore.MemoryModelGLSL450does not make these accesses interchangeable.CoherentandVolatiledo not provide ordering.The ticket
OpAtomicIAdddoes not establish a publication edge. Buffer atomics useMemorySemanticsMaskNoneandScopeWorkgroup, while the publication spans workgroups.Emit a matching device-scope
OpAtomicStorefor coherent word stores. Use release semantics for the store and acquire semantics for the load when the word publishes other memory.@coderabbitai[bot] on GitHub · 2026-10-17 17:35 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
5b2cf18e-9165-4cca-b525-128dfc5c2498📥 Commits
Reviewing files that changed from the base of the PR and between
763d3be3a9and72881d74ee.📒 Files selected for processing: 2
src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpptests/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.
@ -170,0 +170,4 @@void EmitCoherentLoad(EmitterState& state, uint32_t value, uint32_t pointer) {state.builder.AddFunction(spv::OpAtomicLoad, TypeU32(state), value, pointer,ConstantU32(state, spv::ScopeDevice),ConstantU32(state, spv::MemorySemanticsMaskNone));@Nawid3333 on GitHub · 2026-10-17 17:38 UTC · original
Thanks. The publishing store in these tests is a plain
buffer_store_dwordwithout GLC or DLC (RDNA2 stores write through to L2 anyway, which the test relies on), so turning coherent stores intoOpAtomicStorewouldn't make the publisher atomic; that would take every buffer store. This PR leaves stores as they are and only stops the poll from being treated as a plain load, as the description says. The ticket'sOpAtomicIAdduses device scope (%uint_1); Kyty uses workgroup scope only for LDS atomics.@ -170,0 +170,4 @@void EmitCoherentLoad(EmitterState& state, uint32_t value, uint32_t pointer) {state.builder.AddFunction(spv::OpAtomicLoad, TypeU32(state), value, pointer,ConstantU32(state, spv::ScopeDevice),ConstantU32(state, spv::MemorySemanticsMaskNone));@coderabbitai[bot] on GitHub · 2026-10-17 17:39 UTC · original
@Nawid3333 Thanks for the clarification. My scope claim was wrong:
EmitAtomic32uses device scope for buffer atomics and workgroup scope for LDS atomics.My proposed fix also missed the publisher. Because that
buffer_store_dwordhas neither GLC nor DLC, converting only coherent stores toOpAtomicStorewould leave it unchanged.I withdraw this finding. This PR prevents the coherent poll from being treated as a plain load; it does not claim to establish a fully atomic publication protocol.
✏️ Learnings added
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-17 23:09 UTC · original
RADV data point: Radeon 8060S (RDNA 3.5), Mesa 26.2.4, against
763d3be3.BufferWorkgroupPublicationWave32/Wave64already pass on main here: ACO keeps the poll in the loop (buffer_load_b32 ... offen glc), and with this PR it emits exactly the same ISA, no atomic. One difference in the suite:CheckGuardedWaterfallBufferRecordspasses on main and fails with the PR at the SPIR-V check ("missing required text: Volatile"); itsrequired_spirvstill listsVolatile.@Nawid3333 on GitHub · 2026-10-18 04:15 UTC · original
Thanks, you're right: this PR turns that check's GLC load into an
OpAtomicLoad, so itsrequired_spirvhad to change. I pushed a commit that expectsOpAtomicLoadthere, and the check passes with the PR on my RX 9070 XT and Ryzen 7600X iGPU. I missed it because my per-case test runner covered only 32 of the 115 standalone checks that the full run executes. It now covers all of them, and none of the other 84 changes with the PR on the RX 9070 XT or the 7600X iGPU. Good to know that ACO emits the same ISA with the PR, so it costs nothing on RADV.Written with Claude Code (AI): it fixed the check and reran the tests on my PC; I read this comment before posting it.
@coderabbitai[bot] on GitHub · 2026-10-30 20:10 UTC · original · reviewed
986e74db-7975-4975-99ee-1d55c50416d8Reviewing files that changed from the base of the PR and between
41c6a15584andd8b08a0ff1.src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@Nawid3333 on GitHub · 2026-10-30 20:18 UTC · original
About CodeRabbit's outside-diff comment on
LoadIndirectFormattedX: that gap is on main too. Main'sLoadIndirectFormattedXcallsLoadBdaDwordwithoutcoherent, so a coherent formatted X load through a GPU-selected descriptor gets neitherVolatilenor an atomic load there, and this PR doesn't change that path. The formatted GPU-selected test cases use non-GLC loads, so covering it would also need a new formatted GLC case. I'd rather keep this PR to the loads it changes; I can do the formatted path separately if you want it.Pull request closed