shaders: coalesce and inline wave64 x_round exchanges (SHADER-W64-XROUND-BARRIERS) #2119

Open
github-bot wants to merge 1 commit from github-bot/gh-2119 into main AGit
Owner

@⁠robot00f on GitHub · 2026-11-25 21:30 UTC · original
robot00f:perf/w64-xround-barriers → main · +1026 −178 · 7 files · 1 commits · draft

Claimed in the coordination issue as: SHADER-W64-XROUND-BARRIERS (#1608; follow-up to #1608 and #1608)

What and why

Coalesces wave-wide Workgroup exchanges and eliminates helper-call / modulo overhead in Gen.x_round (emulate_inline in tools/rdna2spirv.py) under --wave64-emulate on 32-wide GPUs, while keeping %x_buf byte-identical ((2*L + 6*W + 7) dwords):

  1. Division-free inline Gen._x_round_inline:
    • Drops the outlined %x_pre_*_fn OpFunctionCalls (CGSCC inliner cloning across hundreds of callsites increased NVVM compile time by +12% to +21% vs inline).
    • Cycles %x_it through 0..5 (lcm(2, 3) = 6, preserving both it & 1 parity and it % 3 ring-slot indexing) with zero OpUMods and omits the two dead scheduler-word reset OpAtomicStores on multi-wave workgroups whenever mini_blocks and tail_blocks are empty.
    • Narrows barrier memory semantics from 0x948 (ImageMemory | WorkgroupMemory | UniformMemory | AcquireRelease) to 0x108 (WorkgroupMemory | AcquireRelease) whenever "mem" is clean in x_dirty (and in x_order_barrier when only "lds" is dirty).
  2. Block-local Any-vote and first-lane caching (x_vcache, x_flcache, x_vkeys):
    • Shares Any votes and first-active-lane indices across scc_from_mask, branch_condition, wave_mask, v_readfirstlane_b32, and DPP fi:0 within a basic block, and preserves x_gen across internal OpSelectionMerge regions (buffer_load, buffer_store, ds_*, _emit_rfl_run) that do not write %active, %vcc, %vcc_hi, or %sgpr.
    • Derives Any from a cached (lo, hi) mask in 2 ALU ops ((lo | hi) != 0, 0 barriers, 0 atomics); when branch_condition reuses a cached Any vote while x_dirty is non-empty, emits a bare x_order_barrier() to preserve wave64_emulate_opt.py's sb_clears_dirty invariant.
    • Restricts x_vkeys registration in mask_dst to full-wave masks (n == 2 SGPR pairs and full vcc in wave64) so 32-bit half-mask writes never alias 64-bit x_vcache entries.
  3. Deferred SCC vote coalescing (_pending_scc_vote in emulate_inline):
    • Defers uncached scc_from_mask / scc_any_half votes until %scc is read/overwritten or a label/merge/barrier/branch/%pc store occurs.
    • Coalesces a pending SCC vote with a subsequent branch_condition on the same mask (1 OpAtomicOr, 1 barrier), with another 1-bit g_vote on a distinct mask (2 -> 1 barrier via 2-word bits=(p_bit, bit2)), with a data-only x_round (v_readlane_b32, ds_bpermute_b32, ds_swizzle_b32, quad_any, DPP fi:1, 2 -> 1 barrier via data + bits), or with x_order_barrier (2 -> 1 barrier), and drops the vote (0 barriers) if %scc is overwritten before being read.
  4. Batched contiguous v_readfirstlane_b32 runs (Gen._emit_rfl_run):
    • Establishes first once (0 barriers if already in x_flcache/x_mcache, else 1 round on item 0) and transfers up to 64 remaining values per wave from the single running lane wave_lane == first across one OpControlBarrier (4 -> 2 or 1 round barriers for V# scalarization, 8 -> 2 or 1 for T# scalarization, piggybacking any pending SCC vote into the same barrier).

NVVM ablation note (#1608): Reproducing the 192-VGPR unfolded binary if/else ScreenProbes shape on GTX 1050 Ti (sp_tree_156: 464.1 KiB, 156 barriers -> 4.168 s; sp_tree_324: 898.7 KiB, 324 barriers -> 12.224 s) and stripping all middle OpControlBarrier instructions (NO_BARS) leaves vkCreateComputePipelines time unchanged (12.13 s -> 12.22 s, and 4.91 s -> 4.88 s on 320-barrier loops). Thus the ~11 s baseline on pure unfolded saveexec trees is dominated by %pc-guarded OpSelectionMerge block splitting (SROA/Mem2Reg Phi webs across 192 VGPRs) + %x_pre_*_fn cloning rather than OpControlBarrier itself; where cross-lane votes, mask reads, and v_readfirstlane_b32 runs coalesce (probe_80 / probe_160), cutting exchange blocks in half cuts NVVM compile time by -68.5% to -69.6% (3.2x–3.3x faster).

Tested

  1. Cold vkCreateComputePipelines benchmarks (vk_pipeline_check --jobs 1, __GL_SHADER_DISK_CACHE=0, unique OpString nonce per trial, 3 trials each, exact origin/main vs this PR):

    Synthetic wave64 workload origin/main barriers / OpFunctionCall / OpUMod PR barriers / OpFunctionCall / OpUMod origin/main median (3 runs) PR median (3 runs) Delta
    probe_80 (80 live-SCC saveexec + execz + 4x readfirstlane + readlane blocks) 641 / 640 / 5 (555.0 KiB) 321 / 0 / 0 (554.8 KiB) 6.062 s ([6.369, 6.062, 6.030]) 1.907 s ([1.679, 2.144, 1.907]) -68.5% (3.18x)
    probe_160 (160 probe/waterfall blocks) 1,281 / 1,280 / 5 (1,100.9 KiB) 641 / 0 / 0 (1,101.9 KiB) 17.433 s ([17.338, 17.710, 17.433]) 5.296 s ([5.310, 5.296, 5.121]) -69.6% (3.29x)
    sp_tree_156 (192-VGPR unfolded binary if/else tree, dead-SCC votes only) 156 / 339 / 4 (464.1 KiB) 156 / 184 / 0 (529.8 KiB) 4.168 s ([4.168, 3.750, 4.587]) 3.649 s ([3.789, 3.635, 3.649]) -12.5%
    sp_tree_324 (192-VGPR unfolded binary if/else tree, dead-SCC votes only) 324 / 699 / 4 (898.7 KiB) 324 / 376 / 0 (1,036.5 KiB) 12.224 s ([14.261, 12.181, 12.224]) 11.479 s ([11.853, 11.479, 11.279]) -6.1%
  2. GPU execution (LEONIDA_W64_EMULATE=1, subgroup 32..32):

    • vk_compute_test cs_w64x_xround_coalesce.spv 1 dump: 3/3 runs 0 mismatches, out[0..7] = 147 308 1832 444 625 1335 2379 332.
    • All 24/24 wave64 compute test shaders (cs_dpp_w64, all 20 cs_w64x_*, cs_w64x_partial, cs_w64x_partial_scmp, cs_wave64_ballot, and cs_wavemask) translate, pass spirv-val, and match expected outputs before (23/23) and after (24/24).
  3. CPU semantic, translator, and repository checks:

    • python -I tests/semantic/test_wave64_xround_barriers.py (9/9, 40/64/128-thread forward & reverse workgroup interpreter + spirv-val)
    • python -I tests/semantic/test_wave64_emulate_opt.py (33/33), test_wave64_emulate_barriers.py (13/13), test_loop_ballot_barrier.py (15/15), test_cs_shared_memory_limit.py (15/15), test_w64x_scalar_load_order.py (5/5)
    • python -I tests/test_shader_checks.py (88/88), test_ci_registration.py (16/16), test_text_write_line_endings.py (3/3), test_docs_*.py, scripts/check_no_game_data.py (exit 0).

GPUs tested: NVIDIA GeForce GTX 1050 Ti (Pascal, 4 GB), driver 582.28, Vulkan 1.4.312, Windows 10 Pro 10.0.19045

AI-assisted: yes (Antigravity, Gemini 4 Carbon)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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.
**@⁠robot00f** on GitHub · 2026-11-25 21:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2119) `robot00f:perf/w64-xround-barriers` → `main` · +1026 −178 · 7 files · 1 commits · draft Claimed in the coordination issue as: `SHADER-W64-XROUND-BARRIERS` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608; follow-up to https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 and https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why Coalesces wave-wide Workgroup exchanges and eliminates helper-call / modulo overhead in `Gen.x_round` (`emulate_inline` in `tools/rdna2spirv.py`) under `--wave64-emulate` on 32-wide GPUs, while keeping `%x_buf` byte-identical (`(2*L + 6*W + 7)` dwords): 1. **Division-free inline `Gen._x_round_inline`:** - Drops the outlined `%x_pre_*_fn` `OpFunctionCall`s (CGSCC inliner cloning across hundreds of callsites increased NVVM compile time by `+12%` to `+21%` vs inline). - Cycles `%x_it` through `0..5` (`lcm(2, 3) = 6`, preserving both `it & 1` parity and `it % 3` ring-slot indexing) with **zero `OpUMod`s** and omits the two dead scheduler-word reset `OpAtomicStore`s on multi-wave workgroups whenever `mini_blocks` and `tail_blocks` are empty. - Narrows barrier memory semantics from `0x948` (`ImageMemory | WorkgroupMemory | UniformMemory | AcquireRelease`) to `0x108` (`WorkgroupMemory | AcquireRelease`) whenever `"mem"` is clean in `x_dirty` (and in `x_order_barrier` when only `"lds"` is dirty). 2. **Block-local `Any`-vote and first-lane caching (`x_vcache`, `x_flcache`, `x_vkeys`):** - Shares `Any` votes and first-active-lane indices across `scc_from_mask`, `branch_condition`, `wave_mask`, `v_readfirstlane_b32`, and DPP `fi:0` within a basic block, and preserves `x_gen` across internal `OpSelectionMerge` regions (`buffer_load`, `buffer_store`, `ds_*`, `_emit_rfl_run`) that do not write `%active`, `%vcc`, `%vcc_hi`, or `%sgpr`. - Derives `Any` from a cached `(lo, hi)` mask in 2 ALU ops (`(lo | hi) != 0`, `0` barriers, `0` atomics); when `branch_condition` reuses a cached `Any` vote while `x_dirty` is non-empty, emits a bare `x_order_barrier()` to preserve `wave64_emulate_opt.py`'s `sb_clears_dirty` invariant. - Restricts `x_vkeys` registration in `mask_dst` to full-wave masks (`n == 2` SGPR pairs and full `vcc` in wave64) so 32-bit half-mask writes never alias 64-bit `x_vcache` entries. 3. **Deferred SCC vote coalescing (`_pending_scc_vote` in `emulate_inline`):** - Defers uncached `scc_from_mask` / `scc_any_half` votes until `%scc` is read/overwritten or a label/merge/barrier/branch/`%pc` store occurs. - Coalesces a pending SCC vote with a subsequent `branch_condition` on the same mask (`1` `OpAtomicOr`, `1` barrier), with another 1-bit `g_vote` on a distinct mask (`2 -> 1` barrier via 2-word `bits=(p_bit, bit2)`), with a `data`-only `x_round` (`v_readlane_b32`, `ds_bpermute_b32`, `ds_swizzle_b32`, `quad_any`, DPP `fi:1`, `2 -> 1` barrier via `data + bits`), or with `x_order_barrier` (`2 -> 1` barrier), and drops the vote (`0` barriers) if `%scc` is overwritten before being read. 4. **Batched contiguous `v_readfirstlane_b32` runs (`Gen._emit_rfl_run`):** - Establishes `first` once (`0` barriers if already in `x_flcache`/`x_mcache`, else `1` round on item 0) and transfers up to 64 remaining values per wave from the single running lane `wave_lane == first` across **one** `OpControlBarrier` (`4 -> 2` or `1` round barriers for V# scalarization, `8 -> 2` or `1` for T# scalarization, piggybacking any pending SCC vote into the same barrier). **NVVM ablation note (`#1608`):** Reproducing the 192-VGPR unfolded binary `if/else` `ScreenProbes` shape on GTX 1050 Ti (`sp_tree_156`: `464.1 KiB`, `156` barriers -> `4.168 s`; `sp_tree_324`: `898.7 KiB`, `324` barriers -> `12.224 s`) and stripping all middle `OpControlBarrier` instructions (`NO_BARS`) leaves `vkCreateComputePipelines` time unchanged (`12.13 s -> 12.22 s`, and `4.91 s -> 4.88 s` on 320-barrier loops). Thus the ~11 s baseline on pure unfolded `saveexec` trees is dominated by `%pc`-guarded `OpSelectionMerge` block splitting (`SROA`/`Mem2Reg` Phi webs across 192 VGPRs) + `%x_pre_*_fn` cloning rather than `OpControlBarrier` itself; where cross-lane votes, mask reads, and `v_readfirstlane_b32` runs coalesce (`probe_80` / `probe_160`), cutting exchange blocks in half cuts NVVM compile time by **`-68.5%` to `-69.6%` (`3.2x`–`3.3x` faster)**. ### Tested 1. **Cold `vkCreateComputePipelines` benchmarks (`vk_pipeline_check --jobs 1`, `__GL_SHADER_DISK_CACHE=0`, unique `OpString` nonce per trial, 3 trials each, exact `origin/main` vs this PR):** | Synthetic wave64 workload | `origin/main` barriers / `OpFunctionCall` / `OpUMod` | PR barriers / `OpFunctionCall` / `OpUMod` | `origin/main` median (`3` runs) | PR median (`3` runs) | Delta | | --- | --- | --- | --- | --- | --- | | `probe_80` (80 live-SCC `saveexec` + `execz` + 4x `readfirstlane` + `readlane` blocks) | `641` / `640` / `5` (`555.0 KiB`) | `321` / `0` / `0` (`554.8 KiB`) | `6.062 s` (`[6.369, 6.062, 6.030]`) | `1.907 s` (`[1.679, 2.144, 1.907]`) | **`-68.5%`** (`3.18x`) | | `probe_160` (160 probe/waterfall blocks) | `1,281` / `1,280` / `5` (`1,100.9 KiB`) | `641` / `0` / `0` (`1,101.9 KiB`) | `17.433 s` (`[17.338, 17.710, 17.433]`) | `5.296 s` (`[5.310, 5.296, 5.121]`) | **`-69.6%`** (`3.29x`) | | `sp_tree_156` (192-VGPR unfolded binary `if/else` tree, dead-SCC votes only) | `156` / `339` / `4` (`464.1 KiB`) | `156` / `184` / `0` (`529.8 KiB`) | `4.168 s` (`[4.168, 3.750, 4.587]`) | `3.649 s` (`[3.789, 3.635, 3.649]`) | **`-12.5%`** | | `sp_tree_324` (192-VGPR unfolded binary `if/else` tree, dead-SCC votes only) | `324` / `699` / `4` (`898.7 KiB`) | `324` / `376` / `0` (`1,036.5 KiB`) | `12.224 s` (`[14.261, 12.181, 12.224]`) | `11.479 s` (`[11.853, 11.479, 11.279]`) | **`-6.1%`** | 2. **GPU execution (`LEONIDA_W64_EMULATE=1`, `subgroup 32..32`):** - `vk_compute_test cs_w64x_xround_coalesce.spv 1 dump`: **3/3 runs `0 mismatches`**, `out[0..7] = 147 308 1832 444 625 1335 2379 332`. - All **24/24** wave64 compute test shaders (`cs_dpp_w64`, all 20 `cs_w64x_*`, `cs_w64x_partial`, `cs_w64x_partial_scmp`, `cs_wave64_ballot`, and `cs_wavemask`) translate, pass `spirv-val`, and match expected outputs before (23/23) and after (24/24). 3. **CPU semantic, translator, and repository checks:** - `python -I tests/semantic/test_wave64_xround_barriers.py` (9/9, 40/64/128-thread forward & reverse workgroup interpreter + `spirv-val`) - `python -I tests/semantic/test_wave64_emulate_opt.py` (33/33), `test_wave64_emulate_barriers.py` (13/13), `test_loop_ballot_barrier.py` (15/15), `test_cs_shared_memory_limit.py` (15/15), `test_w64x_scalar_load_order.py` (5/5) - `python -I tests/test_shader_checks.py` (88/88), `test_ci_registration.py` (16/16), `test_text_write_line_endings.py` (3/3), `test_docs_*.py`, `scripts/check_no_game_data.py` (exit 0). GPUs tested: NVIDIA GeForce GTX 1050 Ti (Pascal, 4 GB), driver 582.28, Vulkan 1.4.312, Windows 10 Pro 10.0.19045 AI-assisted: yes (Antigravity, Gemini 4 Carbon) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
Coalesce redundant wave-wide Workgroup exchanges and remove helper-call /
modulo overhead in `Gen.x_round` (`emulate_inline` in `tools/rdna2spirv.py`)
for `--wave64-emulate` on 32-wide GPUs:

1. Inline division-free `Gen._x_round_inline`: emit inline `x_round` setup
   directly in `%main` without `%x_pre_*_fn` `OpFunctionCall`s, cycle `%x_it`
   through `0..5` (`lcm(2, 3) = 6`) with zero `OpUMod`s and omit dead
   scheduler-word reset `OpAtomicStore`s whenever `mini_blocks`/`tail_blocks`
   are empty, and narrow barrier semantics from `0x948` to `0x108`
   (`WorkgroupMemory`) whenever `"mem"` is clean in `x_dirty`.
2. Block-local `Any`-vote and first-lane caching (`x_vcache`, `x_flcache`,
   `x_vkeys`), preserved across `OpSelectionMerge` regions (`buffer_load`,
   `buffer_store`, `ds_*`) that do not write `%active`, `%vcc`, or `%sgpr`:
   share `Any` votes and first-active-lane indices across `scc_from_mask`,
   `branch_condition`, `wave_mask`, `v_readfirstlane_b32`, and DPP `fi:0`
   (deriving `Any` from `(lo | hi) != 0` with zero extra atomics, and
   issuing a bare `x_order_barrier` if memory became dirty before a cached
   voted branch).
3. Deferred SCC vote coalescing (`_pending_scc_vote` in `emulate_inline`):
   coalesce live-SCC mask votes into the next 1-bit vote
   (`s_cbranch_execz`/`vccz`), `data`-only `x_round` (`v_readlane_b32`,
   `ds_bpermute_b32`, `ds_swizzle_b32`), or `x_order_barrier` (`2 -> 1`
   barrier), or drop the deferred vote if `%scc` is overwritten unread.
4. Contiguous `v_readfirstlane_b32` batching (`Gen._emit_rfl_run`): once
   `first` is known, transfer up to 64 remaining values per wave from
   `wave_lane == first` across one `OpControlBarrier` (`8 -> 2` round
   barriers uncached, `8 -> 1` when `EXEC` is already cached).

Add `tests/semantic/test_wave64_xround_barriers.py` and synthetic GPU shader
`runtime/test/shaders/cs_w64x_xround_coalesce.asm`, and document the rules
and GTX 1050 Ti measurements in `docs/design.md`.

AI-assisted: yes (Antigravity, Gemini 4 Carbon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:18:32 +00:00
Author
Owner

@⁠JordanWebDev on GitHub · 2026-11-25 23:41 UTC · original · approved these changes

**@⁠JordanWebDev** on GitHub · 2026-11-25 23:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2119#pullrequestreview-6066540678) · **approved these changes**
Author
Owner

@⁠quartz-heron-58 on GitHub · 2026-11-26 01:13 UTC · original

Whole-corpus check of 72d722a on a retail boot, Windows 11, RTX 4080 16 GB (NVIDIA 621.24), 32 GB RAM. Tools were this head merged with #2102's head 8481605 (only docs/design.md conflicted; the three semantic test files test_wave64_xround_barriers, test_wave64_emulate_opt and test_loop_ballot_barrier pass on the merge: 9, 34, 15).

  • Retranslated my own copy's main corpus (26,503 programs) and graphics library (18,493) with --wave64-emulate, 16 shards each: same program counts as with #2102 alone, every shard's stderr empty. The compute library was not retranslated, and I did not run spirv-val over the output.
  • Two boots with that set (runtime: main b0f3d39 plus several open runtime PRs and local changes, so not a clean main): both get through the loading screens as before. One was stopped by my free-RAM guard at 237 s with no device loss. The other lost the device at 277 s, reported from a draw command with timeout-type fault addresses only, which is the same stop I had in 1 of 3 runs with #2102 alone.

So on this card: no translation regression seen across the corpus, and no visible change to the world-start device loss, which this PR does not claim to address. Not measured: frame time or barrier counts before and after.

AI-assisted (Claude Code).

**@⁠quartz-heron-58** on GitHub · 2026-11-26 01:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2119#issuecomment-7179557374) Whole-corpus check of 72d722a on a retail boot, Windows 11, RTX 4080 16 GB (NVIDIA 621.24), 32 GB RAM. Tools were this head merged with #2102's head 8481605 (only docs/design.md conflicted; the three semantic test files test_wave64_xround_barriers, test_wave64_emulate_opt and test_loop_ballot_barrier pass on the merge: 9, 34, 15). - Retranslated my own copy's main corpus (26,503 programs) and graphics library (18,493) with `--wave64-emulate`, 16 shards each: same program counts as with #2102 alone, every shard's stderr empty. The compute library was not retranslated, and I did not run spirv-val over the output. - Two boots with that set (runtime: main b0f3d39 plus several open runtime PRs and local changes, so not a clean main): both get through the loading screens as before. One was stopped by my free-RAM guard at 237 s with no device loss. The other lost the device at 277 s, reported from a draw command with timeout-type fault addresses only, which is the same stop I had in 1 of 3 runs with #2102 alone. So on this card: no translation regression seen across the corpus, and no visible change to the world-start device loss, which this PR does not claim to address. Not measured: frame time or barrier counts before and after. AI-assisted (Claude Code).
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-26 08:26 UTC · original

Verdict: not ready to merge yet (1 blocker, 1 request). The PR is still a draft, so this is early feedback.

  • Blocking: merged with current main, the PR's own test fails. test_cached_branch_condition_survives_buffer_store_and_orders_dirty_memory fails at tests/semantic/test_wave64_xround_barriers.py:244 (OpAtomicOr 3 != 2). It passes on the PR head alone.
  • Request (not blocking): the PR body's benchmarks were measured before main got its round fallback (translate() / barriers_under_control_flow, tools/rdna2spirv.py:18124 and :18881-18893 on main, merged with #2098 after this PR's base). In my sample 157 emulated programs now take that fallback and 66 keep the inline form. I did not check whether probe_80 / probe_160 take it. Could you re-run the table on current main?

Setup: PR head 72d722a11 (unchanged when rechecked just before writing this). The PR's merge base is 1bf5eeafd. Main is a73a57e13, 137 commits later, and 3 of the touched files changed in that range (tools/rdna2spirv.py, docs/design.md, tests/semantic/test_wave64_emulate_opt.py). Local merge of main into the PR: 9a64951cc, no conflicts (auto-merged in those 3 files). Windows 11 (10.0.26300), Python 3.14.0. llvm-mc --version reports "Ubuntu LLVM version 21.1.8" (runs through WSL). All tests ran on the CPU SPIR-V interpreter. No GPU was involved, and nothing ran in the game.

Tests

  • On main: test_wave64_emulate_opt 33/33, test_wave64_emulate_barriers 13/13, test_loop_ballot_barrier 15/15, test_w64x_scalar_load_order 5/5, test_cs_shared_memory_limit 15/15. test_wave64_xround_barriers does not exist on main.
  • On the PR head alone: test_wave64_xround_barriers 9/9.
  • On the merge: test_wave64_xround_barriers 8/9. The other five files give the same results as on main.
  • Why the merge fails:
    • Main now translates a program a second time as the round loop when its inline structured form leaves an OpControlBarrier under control flow.
    • In that test, block 1 keeps a load-to-store order barrier inside a %pc guard. So main's check sends the whole program to emulated wave64 rounds: emulate_plan is None, 2 barriers, 3 OpAtomicOr.
    • The test expects the inline plan: 4 barriers, 2 OpAtomicOr.
    • Main's own tools give the same result for this shape. The failure comes from the PR not being updated for main, not from a new bug in the PR.
  • Fix: either rework the shape so no barrier sits inside a guard, or assert the fallback (control_flow == "emulated wave64 rounds", barriers_under_control_flow(spv) false).
  • I did not run the full translator suite or test_lds_src2. On this machine test_lds_src2 also fails on main, because llvm-mc runs through WSL and cannot see the Windows temp folder (open PR #1733 addresses it). It does not count against this PR.
  • scripts/check_no_game_data.py on the 7 changed files: exit 0.

Mutation (the PR's tests against main's tools/)

  • test_wave64_xround_barriers: 8 of 9 tests fail, 11 failures counting subtests:
    • :153 (OpFunctionCall count)
    • :189 (OpUMod count)
    • :215 (barrier count)
    • :244 (OpAtomicOr count)
    • :302 (barrier count, all 4 subtests)
    • :331 (count of 0x108 barriers)
    • :361 (barrier count)
    • :425 (barrier count)
  • Only test_half_mask_write_does_not_alias_full_wave_vote_cache passes on main.
  • test_wave64_emulate_opt: 1 failure, at :1544 (assertNotIn("%x_pre_", spv)).
  • Every failure is a static count. None of the memory-result checks fails on main. That fits a pure optimization: main's output was already correct for these shapes.

Corpus (1-in-9 sample, --wave64-emulate, translator only)

  • Sample: 1,630 programs: 1,331 compute and mesh programs from the main corpus and 299 compute programs from the pipeline library.
    • Main corpus: 1,331 translated with both trees.
    • Library: 298 translated with both trees. One is refused by both (s_sethalt).
    • Of these, 1,303 are emulated wave64 programs.
  • spirv-val: all 1,629 valid with main, and all 1,629 valid with the merge.
  • Output changed in 1,298 programs (1,171 + 127). The control-flow mode changed in none.
  • 157 programs hit main's round fallback, the same count on both trees.
  • Rounds mode (1,237 programs):
    • static barrier count unchanged;
    • switch cases (rounds) went down in 10 programs and up in none;
    • size changed by at most +0.15%;
    • total OpAtomicOr 34,423 -> 26,921, total OpUMod 51,880 -> 44,378.
  • Structured mode (66 programs):
    • OpFunctionCall went down in 57;
    • static barriers went down in 2;
    • 38 programs got bigger: 5 by more than 5%, 2 by more than 10% (largest +17.3%);
    • OpUMod went up in 11 programs (largest 7 -> 36);
    • OpAtomicOr went up in 27 programs (largest 1 -> 53). These are inline copies of what the removed helper functions held once. The PR body's own sp_tree rows show the same growth (+14% and +15%).

Safety
Line numbers are for tools/rdna2spirv.py at the PR head.

  • Barrier semantics: 0x108 is used only when no ("mem", *) access is dirty. Buffer, global, flat, image load/store/atomic and scalar loads all count as "mem" (x_memory_order). An empty x_dirty in x_order_barrier keeps 0x948. I found no case where needed memory ordering is lost.
  • The mod-6 %x_it cycle is used only when _x_has_schedulers() is false (:5690). Modules with mini or tail schedulers keep OpUMod (:5666, :5712), so it % 3 and it & 1 stay in step with the scheduler loops.
  • Deferred SCC vote (emit, :474):
    • it is flushed before any label, merge, branch, barrier, %pc store or read of %scc;
    • it is dropped only on an OpStore %scc in the same straight run, which is correct because the old value is dead.
  • Batched v_readfirstlane (_emit_rfl_run, :5826):
    • one lane writes at most 64 words into its own wave's data slots (chunks of 64);
    • the data double buffer keeps the existing it & 1 parity;
    • EXEC == 0 falls back to lane 0, as on hardware.
  • The vote and first-lane caches are keyed by x_gen. The saved x_gen is restored after an internal selection only when that selection wrote no %active, %vcc, %vcc_hi or SGPR.

Suggestions

  1. Update the test at :244 for main's fallback, as described under Tests.
  2. Re-run the benchmark table on current main. Say how many real programs still get the inline form.
  3. Add a test that pins a structured-hybrid module with schedulers. That is the case where inlining copies OpUMod and atomics into every round instead of removing them.
  4. The scc_from_mask cache now also runs in rounds mode (if self.emulate:). No PR test covers that path in rounds mode. In my sample OpAtomicOr went down in 1,109 of the 1,237 rounds-mode programs.

Not covered by this review

  • No GPU run, no pipeline compile times, no frame times. The 3.2x NVVM figures are the author's numbers.
  • No full semantic suite, no tests/test_translate.py, no hand-written GPU tests (including cs_w64x_xround_coalesce).
  • No check of the PR head merged with #2102. quartz-heron-58's whole-corpus comment covers that combination. Their 9/9 is not in conflict with the failure above: #2102's head does not contain main's fallback yet.
  • Static counts only. More OpUMod and atomics in a structured program does not say whether it runs slower at run time or compiles slower.
  • The sample is 1 in 9, translator only, on a library translated with llvm-mc 21.1.8, which leaves about a third of the library programs out (see #1923).

AI-assisted: yes (Claude Code, Claude Opus 5.5, ran the tests and wrote this; a second agent checked this text)

**@⁠MoonEyes** on GitHub · 2026-11-26 08:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2119#issuecomment-7186586598) **Verdict: not ready to merge yet (1 blocker, 1 request).** The PR is still a draft, so this is early feedback. - **Blocking:** merged with current main, the PR's own test fails. `test_cached_branch_condition_survives_buffer_store_and_orders_dirty_memory` fails at `tests/semantic/test_wave64_xround_barriers.py:244` (`OpAtomicOr` 3 != 2). It passes on the PR head alone. - **Request (not blocking):** the PR body's benchmarks were measured before main got its round fallback (`translate()` / `barriers_under_control_flow`, `tools/rdna2spirv.py:18124` and `:18881-18893` on main, merged with #2098 after this PR's base). In my sample 157 emulated programs now take that fallback and 66 keep the inline form. I did not check whether `probe_80` / `probe_160` take it. Could you re-run the table on current main? **Setup:** PR head `72d722a11` (unchanged when rechecked just before writing this). The PR's merge base is `1bf5eeafd`. Main is `a73a57e13`, 137 commits later, and 3 of the touched files changed in that range (`tools/rdna2spirv.py`, `docs/design.md`, `tests/semantic/test_wave64_emulate_opt.py`). Local merge of main into the PR: `9a64951cc`, no conflicts (auto-merged in those 3 files). Windows 11 (10.0.26300), Python 3.14.0. `llvm-mc --version` reports "Ubuntu LLVM version 21.1.8" (runs through WSL). All tests ran on the CPU SPIR-V interpreter. No GPU was involved, and nothing ran in the game. **Tests** - On main: `test_wave64_emulate_opt` 33/33, `test_wave64_emulate_barriers` 13/13, `test_loop_ballot_barrier` 15/15, `test_w64x_scalar_load_order` 5/5, `test_cs_shared_memory_limit` 15/15. `test_wave64_xround_barriers` does not exist on main. - On the PR head alone: `test_wave64_xround_barriers` 9/9. - On the merge: `test_wave64_xround_barriers` 8/9. The other five files give the same results as on main. - Why the merge fails: - Main now translates a program a second time as the round loop when its inline structured form leaves an `OpControlBarrier` under control flow. - In that test, block 1 keeps a load-to-store order barrier inside a `%pc` guard. So main's check sends the whole program to `emulated wave64 rounds`: `emulate_plan` is `None`, 2 barriers, 3 `OpAtomicOr`. - The test expects the inline plan: 4 barriers, 2 `OpAtomicOr`. - Main's own tools give the same result for this shape. The failure comes from the PR not being updated for main, not from a new bug in the PR. - Fix: either rework the shape so no barrier sits inside a guard, or assert the fallback (`control_flow == "emulated wave64 rounds"`, `barriers_under_control_flow(spv)` false). - I did not run the full translator suite or `test_lds_src2`. On this machine `test_lds_src2` also fails on main, because `llvm-mc` runs through WSL and cannot see the Windows temp folder (open PR #1733 addresses it). It does not count against this PR. - `scripts/check_no_game_data.py` on the 7 changed files: exit 0. **Mutation (the PR's tests against main's `tools/`)** - `test_wave64_xround_barriers`: 8 of 9 tests fail, 11 failures counting subtests: - `:153` (`OpFunctionCall` count) - `:189` (`OpUMod` count) - `:215` (barrier count) - `:244` (`OpAtomicOr` count) - `:302` (barrier count, all 4 subtests) - `:331` (count of `0x108` barriers) - `:361` (barrier count) - `:425` (barrier count) - Only `test_half_mask_write_does_not_alias_full_wave_vote_cache` passes on main. - `test_wave64_emulate_opt`: 1 failure, at `:1544` (`assertNotIn("%x_pre_", spv)`). - Every failure is a static count. None of the memory-result checks fails on main. That fits a pure optimization: main's output was already correct for these shapes. **Corpus (1-in-9 sample, `--wave64-emulate`, translator only)** - Sample: 1,630 programs: 1,331 compute and mesh programs from the main corpus and 299 compute programs from the pipeline library. - Main corpus: 1,331 translated with both trees. - Library: 298 translated with both trees. One is refused by both (`s_sethalt`). - Of these, 1,303 are emulated wave64 programs. - `spirv-val`: all 1,629 valid with main, and all 1,629 valid with the merge. - Output changed in 1,298 programs (1,171 + 127). The control-flow mode changed in none. - 157 programs hit main's round fallback, the same count on both trees. - Rounds mode (1,237 programs): - static barrier count unchanged; - switch cases (rounds) went down in 10 programs and up in none; - size changed by at most +0.15%; - total `OpAtomicOr` 34,423 -> 26,921, total `OpUMod` 51,880 -> 44,378. - Structured mode (66 programs): - `OpFunctionCall` went down in 57; - static barriers went down in 2; - 38 programs got bigger: 5 by more than 5%, 2 by more than 10% (largest +17.3%); - `OpUMod` went up in 11 programs (largest 7 -> 36); - `OpAtomicOr` went up in 27 programs (largest 1 -> 53). These are inline copies of what the removed helper functions held once. The PR body's own `sp_tree` rows show the same growth (+14% and +15%). **Safety** Line numbers are for `tools/rdna2spirv.py` at the PR head. - Barrier semantics: `0x108` is used only when no `("mem", *)` access is dirty. Buffer, global, flat, image load/store/atomic and scalar loads all count as `"mem"` (`x_memory_order`). An empty `x_dirty` in `x_order_barrier` keeps `0x948`. I found no case where needed memory ordering is lost. - The mod-6 `%x_it` cycle is used only when `_x_has_schedulers()` is false (`:5690`). Modules with mini or tail schedulers keep `OpUMod` (`:5666`, `:5712`), so `it % 3` and `it & 1` stay in step with the scheduler loops. - Deferred SCC vote (`emit`, `:474`): - it is flushed before any label, merge, branch, barrier, `%pc` store or read of `%scc`; - it is dropped only on an `OpStore %scc` in the same straight run, which is correct because the old value is dead. - Batched `v_readfirstlane` (`_emit_rfl_run`, `:5826`): - one lane writes at most 64 words into its own wave's data slots (chunks of 64); - the data double buffer keeps the existing `it & 1` parity; - EXEC == 0 falls back to lane 0, as on hardware. - The vote and first-lane caches are keyed by `x_gen`. The saved `x_gen` is restored after an internal selection only when that selection wrote no `%active`, `%vcc`, `%vcc_hi` or SGPR. **Suggestions** 1. Update the test at `:244` for main's fallback, as described under Tests. 2. Re-run the benchmark table on current main. Say how many real programs still get the inline form. 3. Add a test that pins a structured-hybrid module with schedulers. That is the case where inlining copies `OpUMod` and atomics into every round instead of removing them. 4. The `scc_from_mask` cache now also runs in rounds mode (`if self.emulate:`). No PR test covers that path in rounds mode. In my sample `OpAtomicOr` went down in 1,109 of the 1,237 rounds-mode programs. **Not covered by this review** - No GPU run, no pipeline compile times, no frame times. The 3.2x NVVM figures are the author's numbers. - No full semantic suite, no `tests/test_translate.py`, no hand-written GPU tests (including `cs_w64x_xround_coalesce`). - No check of the PR head merged with #2102. quartz-heron-58's whole-corpus comment covers that combination. Their 9/9 is not in conflict with the failure above: #2102's head does not contain main's fallback yet. - Static counts only. More `OpUMod` and atomics in a structured program does not say whether it runs slower at run time or compiles slower. - The sample is 1 in 9, translator only, on a library translated with llvm-mc 21.1.8, which leaves about a third of the library programs out (see #1923). AI-assisted: yes (Claude Code, Claude Opus 5.5, ran the tests and wrote this; a second agent checked this text)
Author
Owner

@⁠ammonium231 on GitHub · 2026-11-26 09:06 UTC · original

RTX 3090 / 621.40: test_wave64_xround_barriers.py is 9/9 on this head (72d722a11) and 8/9 merged onto current main a73a57e13 (test_cached_branch_condition_survives_buffer_store_and_orders_dirty_memory, line 244, OpAtomicOr 3 != 2). probe_80/probe_160 take main's round fallback (2 barriers on both sides). Cold vk_pipeline_check --jobs 1, 3-trial median compile: probe_80 1.070s [1.07, 0.96, 1.09] -> 0.770s [0.77, 0.71, 0.77]; probe_160 3.050s [3.05, 3.13, 2.68] -> 2.020s [2.01, 2.13, 2.02].

**@⁠ammonium231** on GitHub · 2026-11-26 09:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2119#issuecomment-7187439875) RTX 3090 / 621.40: test_wave64_xround_barriers.py is 9/9 on this head (72d722a11) and 8/9 merged onto current main a73a57e13 (test_cached_branch_condition_survives_buffer_store_and_orders_dirty_memory, line 244, OpAtomicOr 3 != 2). probe_80/probe_160 take main's round fallback (2 barriers on both sides). Cold vk_pipeline_check --jobs 1, 3-trial median compile: probe_80 1.070s [1.07, 0.96, 1.09] -> 0.770s [0.77, 0.71, 0.77]; probe_160 3.050s [3.05, 3.13, 2.68] -> 2.020s [2.01, 2.13, 2.02].
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 13:55 UTC · original

Tested 72d722a11 merged onto main a73a57e13 (it merges cleanly), on an Apple M3 (macOS 26.5.1). I ran the full scripts/run_gpu_tests.py in auto mode, with test programs built from main. I tested the merge rather than the branch alone because a branch from before 9f98dcc61 fails ps_tex against main's vk_bindless_test (the tagged descriptor table), which says nothing about this change.

Driver main main + this PR
MoltenVK 1.4.2 195 pass, 70 skip 195 pass, 71 skip
MoltenVK, LEONIDA_W64_EMULATE=1 229 pass, 36 skip 230 pass, 36 skip
KosmicKrisp (Mesa 26.3.1) 190 pass, 73 skip 190 pass, 74 skip

The new cs_w64x_xround_coalesce passes under LEONIDA_W64_EMULATE=1 on MoltenVK (147 308 1832 444 625 1335 2379 332) and skips natively (no 64-wide subgroup), as expected on a Mac. No new failure. The ones left are the same on both sides: cs_fma_fused (#1724), ps_ssharp (#1774) and cs_imgatomic_ext (#1518) on MoltenVK; KosmicKrisp's (NAN)-constant fixtures (#2229) and cs_imgatomic_ext there.

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

**@⁠Tauwni** on GitHub · 2026-11-26 13:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2119#issuecomment-7194020991) Tested `72d722a11` merged onto `main` `a73a57e13` (it merges cleanly), on an Apple M3 (macOS 26.5.1). I ran the full `scripts/run_gpu_tests.py` in auto mode, with test programs built from `main`. I tested the merge rather than the branch alone because a branch from before `9f98dcc61` fails `ps_tex` against `main`'s `vk_bindless_test` (the tagged descriptor table), which says nothing about this change. | Driver | `main` | `main` + this PR | |---|---|---| | MoltenVK 1.4.2 | 195 pass, 70 skip | 195 pass, 71 skip | | MoltenVK, `LEONIDA_W64_EMULATE=1` | 229 pass, 36 skip | 230 pass, 36 skip | | KosmicKrisp (Mesa 26.3.1) | 190 pass, 73 skip | 190 pass, 74 skip | The new `cs_w64x_xround_coalesce` passes under `LEONIDA_W64_EMULATE=1` on MoltenVK (`147 308 1832 444 625 1335 2379 332`) and skips natively (no 64-wide subgroup), as expected on a Mac. No new failure. The ones left are the same on both sides: `cs_fma_fused` (#1724), `ps_ssharp` (#1774) and `cs_imgatomic_ext` (#1518) on MoltenVK; KosmicKrisp's `(NAN)`-constant fixtures (#2229) and `cs_imgatomic_ext` there. AI-assisted (Claude Code). No game data.
github-bot force-pushed github-bot/gh-2119 from 72d722a118 to 353d038742 2026-11-27 06:17:32 +00:00 Compare
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-27 11:00 UTC · original

Checked 353d0387 merged into main 2859d0c9, by Claude Code (AI-assisted) on my behalf. Linux, Mesa lavapipe.

One test fails after the merge: tests/semantic/test_bitcast_round_trip.py::test_helpers_return_the_source,
AttributeError: 'Gen' object has no attribute '_pending_scc_vote'. The test builds a Gen with Gen.__new__
(no __init__), and emit() now reads self._pending_scc_vote. Declaring the two new fields as class defaults
makes it pass (checked locally), e.g. right under class Gen::

_pending_scc_vote = None
_flushing_scc_vote = False

The rest of tests/semantic passes (501 files, 6,383 tests). Fuzzers on the merge, all equal to main on the same
seeds:

  • crosslane_fuzz.py --wave 64 --modes emulate --dpp --ext --seed 205 --programs 150: 143 match, 5 mismatch,
    2 hyp_only, the same programs as on main (all masks read as data, #1397/#1043);
  • lds_fuzz.py --wave 64 --emulate 150/150; valu_fuzz.py --family mem --wave 64 --emulate 120/120;
    valu_fuzz.py --family f16 --wave 64 --emulate 100/100; cf_diff.py --wave 64 300/300.

Not run: a hardware GPU, native wave32, the corpus.


Generated by Claude Code

**@⁠kawaii-shakal** on GitHub · 2026-11-27 11:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2119#issuecomment-7216570411) Checked 353d0387 merged into main 2859d0c9, by Claude Code (AI-assisted) on my behalf. Linux, Mesa lavapipe. One test fails after the merge: `tests/semantic/test_bitcast_round_trip.py::test_helpers_return_the_source`, `AttributeError: 'Gen' object has no attribute '_pending_scc_vote'`. The test builds a `Gen` with `Gen.__new__` (no `__init__`), and `emit()` now reads `self._pending_scc_vote`. Declaring the two new fields as class defaults makes it pass (checked locally), e.g. right under `class Gen:`: _pending_scc_vote = None _flushing_scc_vote = False The rest of `tests/semantic` passes (501 files, 6,383 tests). Fuzzers on the merge, all equal to main on the same seeds: - `crosslane_fuzz.py --wave 64 --modes emulate --dpp --ext --seed 205 --programs 150`: 143 match, 5 mismatch, 2 hyp_only, the same programs as on main (all masks read as data, #1397/#1043); - `lds_fuzz.py --wave 64 --emulate` 150/150; `valu_fuzz.py --family mem --wave 64 --emulate` 120/120; `valu_fuzz.py --family f16 --wave 64 --emulate` 100/100; `cf_diff.py --wave 64` 300/300. Not run: a hardware GPU, native wave32, the corpus. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Tauwni on GitHub · 2026-11-27 15:54 UTC · original

Confirming @⁠kawaii-shakal's finding on a Mac (macOS 26.5.1, Python 3.15.2), with this PR's tools/rdna2spirv.py on main ec91d695c:

  • tests/semantic/test_bitcast_round_trip.py fails ('Gen' object has no attribute '_pending_scc_vote') and passes on plain main.
  • With the two class defaults suggested above (_pending_scc_vote = None, _flushing_scc_vote = False under class Gen:), it passes. So does the whole translator suite: 503 files, 6396 tests, 0 failed.
  • Since this morning the PR conflicts with main (ec91d695c) in docs/design.md. At 2859d0c9b it merged cleanly.

My earlier comment here covered the GPU suite only, which is unchanged. This adds the translator suite.

MEASURED, 1 run each. AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠Tauwni** on GitHub · 2026-11-27 15:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2119#issuecomment-7222628580) Confirming @⁠kawaii-shakal's finding on a Mac (macOS 26.5.1, Python 3.15.2), with this PR's `tools/rdna2spirv.py` on `main` `ec91d695c`: - `tests/semantic/test_bitcast_round_trip.py` fails (`'Gen' object has no attribute '_pending_scc_vote'`) and passes on plain `main`. - With the two class defaults suggested above (`_pending_scc_vote = None`, `_flushing_scc_vote = False` under `class Gen:`), it passes. So does the whole translator suite: 503 files, 6396 tests, 0 failed. - Since this morning the PR **conflicts with `main`** (`ec91d695c`) in `docs/design.md`. At `2859d0c9b` it merged cleanly. My earlier comment here covered the GPU suite only, which is unchanged. This adds the translator suite. MEASURED, 1 run each. AI-assisted (Claude Code, Claude Opus 5.5).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2119/head:github-bot/gh-2119'
git switch 'github-bot/gh-2119'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2119'
git switch 'github-bot/gh-2119'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2119'
git switch 'github-bot/gh-2119'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2119'
git switch 'main'
git merge --squash 'github-bot/gh-2119'
git switch 'main'
git merge --ff-only 'github-bot/gh-2119'
git switch 'main'
git merge 'github-bot/gh-2119'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.