Skip to content

rdna2spirv, lane_masks: fix wave64 split SGPR-pair masks, emulate x_mcache, and b64 mask+imm tracking (SHADER-371) - #2222

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
TheAirborneCoder:loop-ballot-split-sgpr
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
TheAirborneCoder:loop-ballot-split-sgpr

Conversation

@TheAirborneCoder

Copy link
Copy Markdown
Contributor

Item: SHADER-371 (claimed in #1902 (comment), tracked in #2078)

Summary

Fixes four wave64 lane-mask / --wave64-emulate bugs found by whole-workgroup loop-ballot & barrier testing (keeping disjoint diff hunks from #615, #663, #1999, #2000, and SHADER-370):

  1. --wave64-emulate wave_mask x_mcache high-dword invalidation (tools/rdna2spirv.py):
    • Gen.wave_mask previously keyed self.x_mcache only on self.x_tok of ("sgpr", a["r"]) (the low dword). When s[r+1] was rewritten between two 64-bit mask reads in the same block (for example s_bcnt1_i32_b64 s6, s[14:15]; s_mov_b32 s15, 0; s_bcnt1_i32_b64 s7, s[14:15]), the second read reused the stale cached (lo, hi) exchange instead of starting a new exchange.
    • wave_mask now keys x_mcache on tuple(self.x_tok.get(("sgpr", a["r"] + i), ("start", a["r"] + i)) for i in range(a.get("n", 1))).
  2. Wave64 split SGPR-pair masks (tools/rdna2spirv.py, tools/lane_masks.py):
    • When a 64-bit SGPR pair s[r:r+1] has its two halves written separately (MASK_LO/MASK_HI, or one mask half paired with a 0/-1 EITHER constant, including across loop back-edges), Gen.holds_lane_mask now matches lane_masks.kind() (using analyse(..., include_either=True)), and Gen.mask_src selects s[r+1] for wave_lane() >= 32 and s[r] for < 32 instead of reading s[r] on all 64 lanes.
  3. _b64 mask + immediate tracking (tools/lane_masks.py):
  4. Wave64 v_mbcnt_lo_u32_b32 / v_mbcnt_hi_u32_b32 half-mask selection (tools/rdna2spirv.py):
    • Uses self.mask_half(a[1]) when known in wave64 so v_mbcnt_lo_u32_b32 on vcc_hi (MASK_HI) reads wave_mask(a[1])[1] and v_mbcnt_hi_u32_b32 on vcc_lo/exec_lo (MASK_LO) reads wave_mask(a[1])[0].
  5. Tests & docs:
    • Added tests/semantic/test_loop_ballot_barrier.py (15 synthetic whole-workgroup semantic tests covering divergent loop ballots, loop-carried split SGPR pairs, x_mcache high-dword invalidation, _b64 mask+immediate ops, v_mbcnt half-mask selection, and uniform loop s_barrier across native wave32, native wave64, and --wave64-emulate) and test_b64_mask_imm_and_include_either in tests/test_lane_masks.py.
    • Updated the Wave64 mask ballot row in docs/design.md.

Testing (AI-assisted)

Tested on Windows 11 (Python 3.14, CPU semantic interpreter; zero game data committed):

  • python -m compileall -q make_game.py tools tests — OK
  • python -I make_game.py --help — OK
  • python -I tests/test_lane_masks.py — OK
  • python -I tests/semantic/test_loop_ballot_barrier.py -v — 15/15 OK
  • python -I tests/semantic/test_mask_src_sgpr_const.py — 7/7 OK
  • python -I tests/semantic/test_scalar_bitcmp.py — 21/21 OK
  • python -I tests/semantic/test_scalar_alu_shifts.py — 22/22 OK
  • python -m unittest discover -s tests/semantic -p "test_wave64_*.py" — 82/82 OK
  • python -I tests/test_docs_links.py — 5/5 OK
  • python -I tests/test_text_write_line_endings.py — 2/2 OK

@MeNoSkills

Copy link
Copy Markdown
Contributor

Regression check of 804f4aef on two GPUs, Windows 10 Pro 10.0.19045, llvm-mc 23.1.6, Python 3.12, runtime test programs built from main 4eb6155d (the PR does not touch runtime/): pass, no regression.

  • run_gpu_tests.py on AMD Radeon Graphics (Ryzen 7 9700X iGPU, RDNA2, driver 24.30.18, native wave64): 167/180 passed, 13 skipped, no FAIL (same as main).
  • run_gpu_tests.py on NVIDIA GeForce RTX 4070 Ti (driver 621.24, subgroup 32): 136/180 passed, 44 skipped, no FAIL (same as main).
  • python -m unittest discover -s tests/semantic: 1686 tests OK (1647 on main+Translator: a wave64 VALU mask SDST printed as one SGPR is the SGPR pair #2231). tests/test_lane_masks.py: OK.

As with #2221, the new rules (split SGPR-pair masks, x_mcache emulation, b64 mask+imm) are CPU-checked by tests/semantic/test_loop_ballot_barrier.py; no existing GPU test changed, so this is a no-regression result only. AI-assisted (Claude Code).

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

GPU check on an AMD Radeon RX 9070 (RDNA4, gfx1201, 32..64 subgroups, so native wave64 too), Windows 11, Vulkan SDK 1.4.363. Tested head 804f4ae merged onto main 4947579 (clean merge).

scripts/run_gpu_tests.py: native: 170/185 passed, 15 skipped | emulated: 170/185 passed, 15 skipped, 0 failures. The skips are the run by d3d12_*_test shaders plus ps_w64x_readlane (no 64-wide fragment subgroup on this device), the same set as main.

AI-assisted (Claude Code); runs on my machine.

@shadshuvo

Copy link
Copy Markdown

Independent verification on AMD Radeon RX 7800 XT (Vulkan 1.4.359 / driver 24.20.19.05 / Windows 11): pass.

Tested 804f4aeff7241b9a63572bcc75f17e8cddea2248 (clean merge into main 49475796):

  • python -m unittest tests/semantic/test_loop_ballot_barrier.py: 15/15 pass
  • python tests/test_lane_masks.py: ok
  • python -m unittest discover -s tests/semantic: 1,686/1,686 pass (0 failures, 2 skipped)
  • python -m compileall -q make_game.py tools tests: ok
  • python -I make_game.py --help: ok

Code read:

  • The x_mcache tuple token keying (tuple(self.x_tok.get(("sgpr", a["r"] + i), ("start", a["r"] + i)) for i in range(a.get("n", 1)))) cleanly resolves the high-dword rewrite stale-cache bug in Gen.wave_mask.
  • mask_src 32-lane half-selection (OpUGreaterThanEqual %bool wave_lane 32 selecting hi vs lo) correctly handles split SGPR-pair lane masks.
  • lane_masks.analyse(..., include_either=True) properly tracks constant 0/-1 halves paired with active lane mask halves across blocks.

AI-assisted.

@smowlyy

smowlyy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 804f4ae on Windows 11 Home 26300: pass, no failures on either GPU. AI-assisted (Claude Code).

Hardware: AMD Ryzen 5 7600X; iGPU AMD Radeon(TM) Graphics (RDNA2, subgroup 32..64), AMD driver 24.10.24 (Vulkan driver 2.0.302); NVIDIA GeForce RTX 5060 Ti, driver 610.88 (subgroup 32..32). MSVC 14.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, Python 3.12.10. Test programs built at 804f4ae with scripts\build_runtime.ps1. Implicit layers off. No game files.

python -I scripts/run_gpu_tests.py, whole suite:

device mode result
Radeon iGPU native wave64 87/180 passed, 93 skipped, 0 failed
Radeon iGPU LEONIDA_W64_EMULATE=1 87/180 passed, 93 skipped, 0 failed
RTX 5060 Ti native 136/180 passed, 44 skipped (wave64), 0 failed
RTX 5060 Ti LEONIDA_W64_EMULATE=1 167/180 passed, 13 skipped, 0 failed

On the iGPU, 77 of the skips are its 128-byte push-constant limit (#2048 isn't in this base), so the native wave64 run judges fewer tests there than on a desktop RDNA2 card.

  • python -m unittest discover -s tests/semantic: 1686 tests OK.
  • python -I tests/test_lane_masks.py and python -I tests/test_shader_checks.py: OK.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 804f4ae on Windows 11 (26200) on both GPUs of a two-GPU PC: pass. I ran scripts/run_gpu_tests.py from this PR (llvm-mc 21.1.8, SPIRV-Tools from the Vulkan SDK tools) against a fresh runtime build of main 4eb6155.

  • AMD Radeon RDNA2 iGPU (gfx1036), AMD Windows driver 32.0.21045.16010, native wave64 (subgroup 32..64): 167/180 passed, 13 skipped, 0 failed.
  • NVIDIA GeForce RTX 5080 (616.92) with LEONIDA_W64_EMULATE=1 (--wave64-emulate, subgroup 32): 167/180 passed, 13 skipped, 0 failed.
  • tests/test_lane_masks.py and tests/semantic/test_loop_ballot_barrier.py: OK.

A first run against a stale build of mine failed ps_imgatomic. Rebuilt on main it passes on both GPUs, with and without this PR, so it was my harness, not this change. No game files. AI-assisted check (Claude Code), Vonsek3.

@ItsNotRexed
ItsNotRexed merged commit b1836f2 into ItsNotRexed:main Nov 22, 2026
4 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
…4 mask ballot row

The 06451e4 tree had two Wave64 mask ballot rows (the old short one and the
PR #2222 superset); the ec8ec4c row dedup merged them into one row but kept
three subset sentences from the old row after their supersets: the short
lane_masks.py sentence (without the _b64-immediates/#1792 clause), the short
s_bcnt/s_ff reconstruct sentence (without the v_mbcnt/mask_half clause), and
the short RX 9070 XT GPU-checked sentence (2 test files instead of 4, without
the CPU-checked parenthetical). Removing the three subset sentences restores
the row byte-identical to the PR #2222 superset row. No code change.
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.

7 participants