Skip to content

Translator: barrier rounds for wave32 compute shaders whose s_barrier isn't in uniform control flow (SHADER-91 follow-up) - #930

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
BACONMANXDGOD:shader-barrier-rounds
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
BACONMANXDGOD:shader-barrier-rounds

Conversation

@BACONMANXDGOD

@BACONMANXDGOD BACONMANXDGOD commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-91 follow-up, barrier rounds (#634 (comment))

What and why

On RDNA every s_barrier counts against the same workgroup barrier, and a wave that has ended no longer counts. In SPIR-V an OpControlBarrier has to be reached by the whole workgroup in uniform control flow. On the native path the translator left the barrier where s_barrier is, and docs/design.md (SHADER-91, #708) noted that this isn't proven and named the fix: "a barrier-only round scheduler (the emulated loop without its cross-lane part) is the fix if a hang shows up."

A hang has shown up on Intel. On an Arrow Lake Xe-LPG iGPU (Windows driver 32.0.101.8132), cs_barrier_divergent loses the device on every run (vkQueueWaitIdle -> -4, VK_ERROR_DEVICE_LOST). On @kapitche's UHD 770 (101.6129) it hangs or writes nothing (#634).

  • needs_barrier_rounds: a native wave32 compute shader runs in rounds when an s_barrier sits anywhere but a top-level block of the structured tree. That means under a guard, in a loop, or anywhere in the dispatch loop. A top-level block is one every invocation runs, so a barrier there keeps the plain translation. Native wave64 cs and ms (AMD only) are unchanged. --wave64-emulate is unchanged too: it already has its own round loop.
  • bar_scheduler is the emulated loop without its cross-lane part:
    • s_barrier sets %x_bar and ends a segment (x_split). The rest of the block is a continuation segment, and SSA values cross it through x_spill, as under --wave64-emulate.
    • In a round, each invocation that isn't done runs its blocks through the switch over %pc until it reaches an s_barrier or the end.
    • The whole workgroup then meets at one OpControlBarrier, at the end of the round loop, with s_barrier's own semantics (workgroup, acquire-release, workgroup memory).
    • After a round every invocation is either done or waiting, so the barrier always releases the waiting ones. A wave that has ended doesn't hold the others, which is RDNA's rule.
    • A per-round count of the invocations not done ends the loop at 0. It lives in three Workgroup words, by round mod 3: invocation 0 clears the next round's word, which was last read two rounds earlier.
    • Cross-lane operations stay subgroup operations, as in the dispatch loop, because a wave's lanes run the same segment.
  • Corpus: in 1.0.2.1, 43 of the 55 wave32 cs shaders with s_barrier have one nested (@Spaghetih's count in Coordinating who works on what (3) (moved to #1006) #634), so those 43 now run in rounds. I don't have the game files to rerun the corpus. Under --wave64-emulate the same splitting and spilling already runs on every wave64 cs and ms shader, at more points than barriers.
  • docs/design.md: the "Workgroup barriers" row describes this, the GPU results, and what is still unproven (native wave64, AMD only).

Tested

Windows 11 26200, llvm-mc 23.1.6, Vulkan SDK 1.4.363, MSVC 19.44, main 4a36bb1. Two new fixtures, registered in check.py and run_gpu_tests.py like cs_barrier_divergent:

  • cs_barrier_early_end.asm: waves 1-3 end without an s_barrier while wave 0 waits at one, then reads what wave 3 wrote.
  • cs_barrier_loop.asm: wave w runs w + 1 iterations of add-to-LDS / s_barrier / read. The k-th barrier has to wait for every wave still running, so each read is 32 × (4 − k).
Fixture Intel Xe-LPG (101.8132), main Intel Xe-LPG, this PR RTX 5070 Ti Laptop (617.42), main RTX 5070 Ti, this PR
cs_barrier_divergent device lost PASS PASS PASS
cs_barrier_early_end device lost PASS PASS PASS
cs_barrier_loop device lost PASS PASS PASS

Whole run_gpu_tests.py with this PR: the GPU test shaders all translate and pass spirv-val (103/103; main 101/101). No test changes result except the three barrier fixtures:

main this PR
Xe-LPG native 62/100 (cs_barrier_divergent loses the device) 65/102
Xe-LPG LEONIDA_W64_EMULATE=1 83/100 (the same) 86/102
RTX 5070 Ti native 73/100 75/102, 0 failed
RTX 5070 Ti emulated not run 102/102

The Intel failures left on this branch are the ones #820 fixes (cs_exec64, cs_w32_permute, cs_wqm_w32, plus the emulated wave64 mask tests) and ps_bitmask_perm (#618). The same list fails on main. lds_fuzz --seed 1 --programs 50 --wave both matches main on both GPUs (Intel 39/50, RTX 43/50, the same programs).

Rebased onto main c63773d (which has #820; runtime rebuilt), with this PR: 114/114 shaders translate and pass spirv-val.

CPU: python -m pytest tests 3327 passed, 21 skipped, 1 xfailed, 0 failed on 4a36bb1, and 3867 passed, 30 skipped, 0 failed on c63773d. compileall is clean. New tests in tests/test_translate.py:

  • the three fixtures translate to "barrier rounds", with no OpControlBarrier among the blocks and the two that remain outside the round loop's body;
  • a barrier in a top-level block keeps the plain translation (one OpControlBarrier, no rounds);
  • a wave64 copy of cs_barrier_divergent stays structured natively, and under --wave64-emulate uses the emulated rounds.

Negative control: with main's rdna2spirv.py the four new rounds tests fail, the top-level one passes, and on the Intel iGPU each of the three fixtures loses the device (table above).

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed (GPU tests on an Intel Xe-LPG iGPU and an RTX 5070 Ti).

🤖 Generated with Claude Code

@dcastell1

dcastell1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 3c9e14f on an RTX 5090 (Blackwell), Windows 11 Pro 10.0.26300.9974, NVIDIA 621.24 / Vulkan 1.4.357, MSVC 14.44, llvm-mc 21.1.8 (WSL), SPIRV-Tools 2025.1, LEONIDA_W64_EMULATE=1, test programs rebuilt from this PR:

  • run_gpu_tests.py: 104 shaders: 104 translated, 104 pass spirv-val; 103/103 passed, 0 failed, 0 skipped.
  • New barrier fixtures: cs_barrier_early_end (127 126 125 124 123 122 121 120) and cs_barrier_loop (128 96 64 32 128 96 64 4008636142) pass, as does the existing cs_barrier_divergent.
  • This does not reproduce the Intel early-end hang; it is a no-regression result for the barrier-round scheduler on a 32-wide NVIDIA GPU.

No game files were used.

@quackottu quackottu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 3c9e14f on NVIDIA GeForce RTX 5070 (subgroup 32), driver 621.24, Windows 11 Pro (26300), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (built with scripts/build_llvm_mc.ps1), scripts/run_gpu_tests.py:

  • native: 76/103 passed, 27 skipped (main 8df277f here: 64/91 passed, 27 skipped, all wave64 tests needing a 64-wide subgroup)
  • LEONIDA_W64_EMULATE=1: 103/103 passed (main here: 91/91)
  • python -m unittest discover -s tests/semantic: Ran 1018 tests in 163.609s OK

@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 7dc3a7d on two GPUs: pass, native and emulated.

Windows 11 Home 10.0.26300, llvm-mc 21.1.8 (AMDGPU, native), Vulkan SDK 1.4.363.0, MSVC 14.44.35207, Python 3.14.7, VK_LOADER_LAYERS_DISABLE=~implicit~. One PC, two GPUs, picked with VK_LOADER_DRIVERS_SELECT: AMD Radeon iGPU of a Ryzen 7 9800X3D (RDNA2, AMD 2026.04.17, subgroup 32..64) and NVIDIA GeForce RTX 5070 (Blackwell, 617.42, subgroup 32).

scripts/run_gpu_tests.py: 104 shaders translated, 104 pass spirv-val.

AMD iGPU RTX 5070
native 103/103 passed 76/103 passed, 27 skipped (wave64)
LEONIDA_W64_EMULATE=1 103/103 passed 103/103 passed

cs_barrier_divergent and cs_barrier_early_end (127 126 125 124 123 122 121 120) and cs_barrier_loop (128 96 64 32 128 96 64 4008636142) pass in all four runs with the same words.

ctest with LEONIDA_VK_VALIDATION=1: RTX 5070 33/33; AMD iGPU 32/33. The AMD failure is d3d12_vulkan_device at D3D12_OPTIONS1 WaveLaneCountMax: ours 64, host 32, the two-GPU comparison bug fixed on main by #962, not this PR.

AI-assisted (Claude Code). No game files.

@Zombins2

Zombins2 commented Nov 22, 2026 •

Copy link
Copy Markdown

AI-assisted. No game files used.

Additional AMD/NVIDIA test evidence for PR #930: an old-translator control, repeated fixture launches, and a comparison of the synthetic suite's compiled modules.

Tested head 7dc3a7d against its parent dcd8ecf on Windows 11: AMD Radeon iGPU (AMD proprietary 26.10.1, subgroup 32..64) and RTX 5080 (616.92, subgroup 32), selected with VK_LOADER_DRIVERS_SELECT. Test programs were built from the parent with MSVC 19.50 / Ninja Release; llvm-mc 23.1.6.

  • Old-translator control: the parent's rdna2spirv.py with the PR's fixtures passed cs_barrier_divergent, cs_barrier_early_end and cs_barrier_loop on both GPUs. On AMD, direct vk_compute_test launches with VKC_SUBGROUP_SIZE=32 gave the expected eight output words in 300/300 launches per fixture, for each translator (1,800 launches total). No hang occurred in those launches. This does not reproduce the Intel hang on these two tested drivers/fixtures; it does not establish that the problem is Intel-only. The PR modules contain the scheduler round loop (one OpSwitch each); the controls contain none.
  • Compiled-output scope: among 113 common .spv files in the synthetic full-suite outputs, only cs_barrier_divergent.spv differs byte-for-byte in each mode (native and LEONIDA_W64_EMULATE=1). The PR adds cs_barrier_early_end.spv and cs_barrier_loop.spv. The compared wave64 compute and mesh outputs are unchanged. This is a suite comparison, not a game-shader corpus comparison.
  • Full AMD suite, native and emulated: PR 98 passed / 103 total, 5 skipped, 0 failed; parent 96 passed / 101 total, 5 skipped, 0 failed. The status differences are the two added fixtures. The skips are mesh tests requiring VK_EXT_mesh_shader.
  • tests/test_translate.py: 281 passed with the PR. With the old translator, 4 failed / 277 passed: three nested-barrier scheduling cases and the wave32-compute-only scheduling case fail; the top-level-barrier case still passes.

Caveat: the AMD runner repeat reported missing words in 2/30 PR fixture executions versus 0/30 controls. An earlier batch of direct launches (its log was later overwritten, so it isn't counted here) showed the same empty-output symptom with both the PR and control modules. The 3,800 later direct launches whose results are recorded all passed: 1,800 across the three fixtures, plus 2,000 interleaved PR/control launches of cs_barrier_divergent with subgroup size 32 requested and with the default setting (500 per translator per setting). Its cause remains unresolved; these results do not establish either a PR defect or a harness defect.

… isn't in uniform control flow (SHADER-91)

On RDNA every s_barrier counts against the same workgroup barrier and a wave that has ended no longer counts;
SPIR-V needs every OpControlBarrier reached by the whole workgroup in uniform control flow. A native wave32
compute shader whose s_barrier sits anywhere but a top-level block of the structured tree now runs in rounds,
the emulated wave64 loop without its cross-lane part: s_barrier ends a segment, each invocation runs until its
next s_barrier or the end, and the workgroup meets at one OpControlBarrier at the end of the round. A per-round
count of the invocations not done (three Workgroup words) ends the loop. Native wave64 cs and ms are unchanged.

Intel Arrow Lake Xe-LPG iGPU (32.0.101.8132): cs_barrier_divergent and the new cs_barrier_early_end and
cs_barrier_loop lose the device with the plain translation and pass with barrier rounds; all three pass on an
RTX 5070 Ti (617.42) either way. docs/design.md's Workgroup barriers row describes it.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ItsNotRexed
ItsNotRexed merged commit 1bc8459 into ItsNotRexed:main Nov 22, 2026
ItsNotRexed pushed a commit that referenced this pull request Nov 23, 2026
…arge

Native wave32 barrier rounds counted the invocations not done in %x_buf,
three Workgroup dwords (#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants