Repository navigation
Conversation
… wave with subgroup barriers (opt-in) RDNA2 runs a wave in lockstep, so shaders exchange LDS data between lanes with only s_waitcnt in between; SPIR-V orders nothing between invocations without a barrier. With --lds-wave-order on (default off, output unchanged), conflicting LDS accesses that no s_barrier orders get an OpControlBarrier at Subgroup scope (AcquireRelease|WorkgroupMemory), found by data flow over the blocks; skipped behind SCC branches that may split a wave64 subgroup and in --wave64-emulate. Adds GPU tests cs_lds_wave_exchange / cs_w64x_lds_wave_exchange, semantic tests and the design.md row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dcastell1
left a comment
There was a problem hiding this comment.
Hardware and CPU run on this branch (RTX 5090, 621.24, Windows 11, LEONIDA_W64_EMULATE=1, all six vk_*_test programs rebuilt from the PR tree):
PASS cs_lds_wave_exchange 512 groups x 64: 0 mismatches
PASS cs_w64x_lds_wave_exchange 512 groups x 64: 0 mismatches
147/147 passed
CPU side: tests/semantic → 1369 tests OK (2 skips) including the 31 in test_lds_wave_order.py; tests/test_shader_checks.py → 46 passed, 181 subtests; tests/test_translate.py skips without a build fixture here.
So the opt-in orders the LDS exchange on a 32-wide subgroup without touching the default path (main's 146 + this one). The --lds-wave-order flag being opt-in is the right call given the extra subgroup barriers.
|
Tested b913e79 on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass. This is a 32-wide check for the "AMD + 32-wide GPU" list. Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.
0 failures in every run. AI-assisted run (Claude). Counts only, no game files involved. |
|
Tested b913e79 on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 32.0.32029.2010 (Vulkan driver 2.0.416), Windows 11 Pro 10.0.26300, MSVC 19.44.35228, llvm-mc 21.1.8 (WSL), SPIRV-Tools v2026.4: pass. This is the AMD half of the "AMD + 32-wide GPU" check, next to the GTX 1660 above.
The same results came from its predecessor #1564 (1f9b84a) on AI-assisted (Claude Code); no game files. |
|
Carried over from #1564: I tested its head 1f9b84a, the commit this PR rebases. That's the same 12 files and line counts, and Tested 1f9b84a on Windows 11, on two GPUs: pass. Both are new architecture/OS points for this PR: native RDNA2 wave64 on the AMD Windows driver, and Blackwell on Windows.
AI-assisted (Claude Code). |
|
Tested b913e79 on Linux 6.8 (Python 3.12.3, CPU only, semantic interpreter; no llvm-mc, spirv-val or GPU here, so the GPU tests and the byte-identity claim were not re-run).
Two things I found, neither a problem with the default ( 1. The two-address exchanges are not classified, so they get no barrier.
On current 2. "Atomic after atomic: the memory model orders those" holds per access, not for the program order. Two atomics on one dword cannot race, but nothing says lane 1's first instruction runs before lane 0's second. Two lanes, one dword starting at 0,
AI-assisted review. |
|
Tested
Tools: llvm-mc 21.1.8 with AMDGPU target, SPIRV-Tools 2026.1, GCC 13.3.0, Python 3.12.3. No code was edited or pushed; only synthetic fixtures were used. AI-assisted. |
# Conflicts: # scripts/run_gpu_tests.py # tests/test_shader_checks.py
# Conflicts: # tests/test_shader_checks.py
|
Tested
No game files. AI-assisted (Claude Code). |
# Conflicts: # tests/test_shader_checks.py
# Conflicts: # docs/design.md
|
Tested Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows
With One note: AI-assisted (Claude Code); I checked the results. |
|
Superseded by #2345: the same change as one commit, rebased onto main after the latest merge round. It conflicted in tools/rdna2spirv.py, and I can't force-push, so it's on a new branch. All test results from here are carried over; thanks @Itschotsch, @dcastell1, @bobcatchris, @crastinator, @zneel and @josevictorp. |
Rebased onto
mainafter #1541 (SHADER-10) landed: one commit, replacing #1564, which conflicted intools/rdna2spirv.py. I rebased it rather than mergingmainin, as asked for that file. The conflicts were all "keep both": options, globals and index fields. Re-run on the rebased commit:test_translate/test_shader_checks/test_wave64_halves_fixtures/test_tool_stdout_encoding492 passed, 2 skipped; semantictest_lds_wave_order31 OK andtest_wave64_halves57 OK.Carried over from #1564: @Itschotsch tested
1f9b84aon an RTX 4090 (Linux, 595.99.02): pass, with the option both off and on, and 0 mismatches incs_lds_wave_exchange. Thanks.What and why
Adds an opt-in translator option,
--lds-wave-order off|on. The default isoff, and output is unchanged.LEONIDA_LDS_WAVE_ORDER=1turns it on forruntime/test/shaders/build.py. Claimed in #1218.The problem: RDNA2 runs a wave in lockstep with an in-order LDS queue. Shaders therefore write LDS in one lane and read it in another with only
s_waitcnt lgkmcnt(0), or nothing, in between. Reductions, prefix sums and transposes all do this. SPIR-V and the Vulkan memory model order nothing between two invocations without a barrier or an atomic. A compiler may reorder the accesses, and a GPU with independent thread scheduling may have the lanes of a subgroup at different instructions. Prior art, facts only: shadPS4 #5285 saw RADV reorder such reads.What
ondoes: a native compute or mesh shader (not--wave64-emulate) gets anOpControlBarrier Subgroup Subgroup AcquireRelease|WorkgroupMemorybefore an LDS access that conflicts with an earlier, still unordered one. "Unordered" means nos_barrierand no earlier subgroup barrier sits between them. The conflicting pairs are RAW, WAR, WAW, and atomic vs plain; atomic after atomic needs no barrier. The unordered set is a forward data flow over the blocks, so a loop-carried pair and a join are handled.Where it emits nothing:
ds_bpermute,ds_permuteandds_swizzle;s_barrier;scc_logictakes a lane's own bit for a 32-bit op on one half of a lane mask).With
on, the index recordslds_wave_order, the number of barriers emitted.docs/design.mdhas the row, with the spec text quoted.Tested
cs_lds_wave_exchange(wave32) andcs_w64x_lds_wave_exchange(wave64, including the other half) run 512 groups × 256 rounds of four dependent exchanges; every thread must store 0. Thecheck.pylab on an RTX 5070 Laptop and a Radeon 880M passes on both, with the default and withLEONIDA_LDS_WAVE_ORDER=1.lds_fuzz(seed 1, 100 programs, wave both), native and--emulate, on both GPUs: no mismatch.tests/semantic/test_lds_wave_order.py(31 tests): barrier placement, no barrier where none is needed, default off unchanged vs on, the metadata, a loop-carried pair, a join, and the wave64 SCC exception.test_translate+test_shader_checks+tests/semantic: 1705 passed, 2 skipped (ms_f16_pack). The nested-barrier test ran and wasn't skipped. Tools were llvm-mc and spirv-val. This run was on the pre-rebase base. After the rebase onto currentmain, the LDS, barrier-round and shader-check tests pass (88).off, all 137 test shaders are byte-identical tomain.Honest limits
The race did not reproduce in 100 runs per variant on an RTX 5070 Laptop and a Radeon 880M (wave32 and native wave64). The SPIR-V is racy by the memory model, but these drivers kept program order. The tests pass with and without the option, so they show no benefit, only that it is harmless on these GPUs. There was no measurable cost either.
Intel is untested. Nested barriers lose the device on Xe-LPG; see the "Workgroup barriers" row.
The spec is ambiguous.
OpControlBarrierin non-uniform control flow is "defined by the client API". The current text dropped that sentence.GLSL_EXT_split_barriersays Subgroup-scope barriers need not be in uniform control flow under Vulkan.Hence the wave64 SCC exception and the opt-in default. Quotes and links are in
docs/design.md.Not done: skipping the barrier when a lane provably reads only its own slot.
Checklist
docs/design.mdrow (rule, why, source, how tested)AI-assisted (Claude Code).
🤖 Generated with Claude Code