Repository navigation
SHADER-579: barrier-round count borrows an LDS word so a full 32 KiB LDS stays at 32,768 B - #3245
Conversation
…arge Native wave32 barrier rounds counted the invocations not done in %x_buf, three Workgroup dwords (ItsNotRexed#930). With a full 32 KiB LDS that made 32,780 B, 12 bytes over the 32,768 B maxComputeSharedMemorySize of the AMD Windows and Intel drivers, so the SHADER-309 runtime check refused the pipeline. When the shader uses its LDS and the array plus 12 bytes is over 16,384 B (the Vulkan minimum), the count now borrows LDS word 0 between rounds: invocation 0 saves and clears it, the invocations not done add 1, all read it, invocation 0 restores it, each step behind a workgroup barrier while no shader code runs. Smaller shaders keep %x_buf and one barrier per round. A 32 KiB LDS round shader is now exactly 32,768 B. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested 81ee035 on Windows 11 with an RTX 4070 (driver 621.01, native wave32). I translated the PR’s ring-shift and early-exit shaders with a 32 KiB shared-memory cap. All four modules passed spirv-val for Vulkan 1.2. The ring shift returned all 64 expected words with 8, 16 and 32 KiB of LDS, including the value read back from LDS word 0. In the 32 KiB early-exit case, lanes 0–31 returned 2 and lanes 32–63 returned 4. Each case matched on five GPU runs. Both 32 KiB modules used exactly 32,768 bytes of Workgroup memory. AI-assisted |
|
As offered in #3047: tested 81ee035 against its base 1628210 with my own 1.0.2.1 corpus, on the two 32 KiB devices. AMD RX 9070 XT (32.0.32029.2010) and Intel UHD 770 (101.7092), both Translation, all 77 compute shaders with 16 KiB of LDS or more (native):
GPU,
The UHD 770's
AI-assisted (Claude Code); no game data in this comment. |
YaBulochka
left a comment
There was a problem hiding this comment.
Ran the new test on a clean worktree of 81ee0357: python3 -m pytest -q tests/semantic/test_cs_barrier_counts_lds.py -> 8 passed, 5 subtests passed. It collects cleanly beside the existing semantic tests and only touches rdna2spirv.py plus the docs row.
Read the rule as well: the 16,384 B threshold (the Vulkan minimum) is the right side to be conservative on, since a device that reports exactly the minimum would otherwise get a module it cannot run, and borrowing one LDS word only when the array is large keeps the common case untouched. No blocker from this side; I have not run a full corpus translation of this branch.
|
Tested The PR's own programs on real hardware.
Whole suite. Linux runtime built from the branch (CMake + Ninja, GCC, RelWithDebInfo), Code read: the save, clear, count, read and restore sequence between barriers A and E matches Tools: llvm-mc 21.1.8, SPIRV-Tools 2026.1, CMake 4.2.3, Python 3.14.4. AI-assisted (Claude Code). The probe script isn't part of the PR. It runs only the PR's own synthetic programs, no game files. |
|
Coordination note from SHADER-638: we reproduced the separate Wave64 full-LDS refusal (65,536 B guest LDS plus 8,604 B exchange for a synthetic 1,024-invocation group). We are prototyping exchange staging/capture at a uniform scheduler boundary with guest LDS save/restore, preserving all guest bytes and SHADER-309 accounting. Your native barrier-round path remains yours and unchanged; we will check integration with #3245 and declare a dependency if shared helpers are reused. Unlike a single counter, Wave64 values currently live across rounds, so proving every consumer's capture timing is the first gate. CPU-only investigation so far; no claim of GPU or retail support yet. AI-assisted. |
Conflicts: fit_shared_memory (main now shrinks to the RSRC2 allocation with bounds-checked LDS; kept that, still without the 12 bytes when the barrier-round count goes into the LDS) and docs/design.md (main's rows, with the SHADER-579 references and row re-applied). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SHADER-579 (claimed in #3047).
What and why
Native wave32 compute shaders whose
s_barrieris not in uniform control flow run in barrier rounds (SHADER-91,bar_scheduler). The round loop counts the invocations not done in%x_buf, three Workgroup dwords (#930). On top of a full 32 KiB LDS that came to 32,780 B, 12 bytes over the 32,768 BmaxComputeSharedMemorySizeof the AMD Windows (RX 9070 XT) and Intel (UHD 770) drivers. The runtime check from SHADER-309 then refused those pipelines: 2 native wave32 cs in towade's corpus run.Design
New rule
Gen.bar_counts_in_lds(). When the shader uses its LDS and the LDS array plus 12 bytes is over 16,384 B (the Vulkan minimum limit; in practice an array of 16, 32 or 64 KiB), there is no%x_buf. The count borrows LDS word 0 at the end of each round (bar_scheduler_tail):s_barrier's own). After it every invocation is done or waits, so no shader code runs until the next round.The shader sees its LDS bit for bit as before. The extra barriers are in uniform control flow, at a point where the whole workgroup already waits, so the barrier semantics don't change. The cost is 4 more
OpControlBarriers per round, in these large-LDS round shaders only. The initial clear and its barrier before round 0 go away.Below the threshold,
%x_bufstays: 12 bytes fit every device, and there's still 1 barrier per round. A shader that never touches its LDS also keeps%x_buf, because there's no array to borrow from (12 B in all). The wave64 emulation's%x_buf(SHADER-562's area) is untouched.SHADER-309 accounting is kept:
x_buf_bytes()returns 0 in this mode, solds_bytesis still the module's whole Workgroup total.assemblebounds check is unchanged.fit_shared_memoryno longer reserves the 12 bytes when they'll go into the LDS, so a full LDS keeps its power-of-two array.Result: a 32 KiB LDS wave32 round shader is now exactly 32,768 B (was 32,780 B). A 64 KiB one is 65,536 B; before, it was shrunk with
OpUMod, or refused when the need filled the array.Rejected alternatives:
needs_barrier_roundsadds them only when a barrier is not at the top level.ds_*addresses. The save/restore above needs no such proof.No
Depends on. This builds onmain's SHADER-309 code (fit_shared_memory,lds_bytes), not on ce7a348's bounds checks. It touchesfit_shared_memory, so a small merge conflict with #1882 is possible.docs/design.md: new contract row "Barrier-round count in LDS (SHADER-579)". The SHADER-309 and "Workgroup barriers" rows point to it.Testing
python -I -m unittest discover -s tests/semantic -p test_cs_barrier_counts_lds.py: 8 tests, OK. This is a new file. It covers:lds_bytes: 32 KiB →{%lds: 32768}, 32 KiB under--max-shared-memory 32768(not shrunk), 64 KiB → 65,536 B;test_loop_ballot_barrier.py, whose LDS starts as 0xDEADBEEF, in both wave orders: a ring shift across 10 barriers that reads LDS word 0, and an early-ending wave;%x_bufwith 2 barriers in the module;%x_buf;-p test_cs_shared_memory_limit.py: 8 tests, OK.-p test_loop_ballot_barrier.py: 15 tests, OK.-p test_barrier_control.py: 17 tests, OK.-p "test*.py": 4150 tests, OK (4 skipped).git diff --check: clean.No GPU run was done by the author, and
spirv-valwasn't available locally. @towade offered to run this on the RX 9070 XT and the UHD 770 (32 KiB limit), the two devices that refused the 32,780 B modules.AI-assisted (Claude Code).
🤖 Generated with Claude Code