Skip to content

rdna2spirv: wave32 VCC holding data, read as a lane mask, gives lane L bit L - #2206

Open
evilclanker9000 wants to merge 5 commits into
ItsNotRexed:mainfrom
evilclanker9000:fix/vcc-data-mask
Open

evilclanker9000 wants to merge 5 commits into
ItsNotRexed:mainfrom
evilclanker9000:fix/vcc-data-mask

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-VCC-DATA-MASK, #1902 (comment)

What and why

In a wave32 program, VCC that holds plain data (s_mov_b32 vcc_lo, 0xa, s_mov_b32 vcc_lo, s5 from a data SGPR, a load into VCC) and is then read as a lane mask selected every lane. Gen.mask_src already takes bit L of a data SGPR and of an immediate, but its VCC branch returned the raw %vcc word, so any non-zero value meant "all lanes on". The hardware reads VCC[L] for lane L.

wave32 hardware main
s_mov_b32 vcc_lo, 0xa / v_cndmask_b32_e32 v8, 0, v21, vcc_lo lanes 1, 3 all 32
s_mov_b32 vcc_lo, 0x80000001 / v_add_co_ci_u32_e32 carry-in lanes 0, 31 all 32
s_mov_b32 vcc_lo, 0xff0000 / s_and_saveexec_b32 s7, vcc_lo lanes 16-23 all 32

Change (tools/rdna2spirv.py, Gen.mask_src): in a wave32 program, when lane_masks.py does not certify VCC as a mask, lane L takes bit L of %vcc. A real mask is unchanged: it holds 0 or ~0 per lane, and bit L of that is the same 0 or 1. Wave64 is left as it was (lanes 32-63 would need %vcc_hi and a SHADER-10 tier); VCC read as data is #293's direction and not touched. This does not touch the SGPR / SOP2 parts of #1792.

Found by a scratch whole-wave differential checker (integer VALU, carry ops, compares and v_cndmask under random EXEC, translator + tests/semantic/spirv_wave_interp.py against an ISA model).

New contract row in docs/design.md.

Tested

Windows 11, LLVM 21 llvm-mc, VK_LOADER_LAYERS_DISABLE=~implicit~, one GPU at a time:

GPU Driver run_gpu_tests.py --filter cs_w32_vcc_data Without the change
NVIDIA GeForce RTX 5080 (subgroup 32) 616.92 PASS 258 1032 2 1052 0xffffff00 5 4104 781 FAIL 32 32 32 32 0xffffff00 5 32 32
AMD Radeon RDNA2 iGPU, Ryzen 9 9950X3D (subgroup 32..64) 26.10.1 PASS, same words FAIL, same words as on NVIDIA
  • New runtime/test/shaders/cs_w32_vcc_data.asm (wave32 dump, expected words derived from the ISA in its header), registered in check.py and run_gpu_tests.py, and as a tests/semantic fixture: LaneMaskConstants in test_value_semantics.py checks the words and a plain-Python derivation of them; it fails on main with the old words.
  • Negative control: the GPU test and the semantic test both fail with tools/rdna2spirv.py from main (table above).
  • python -m unittest discover -s tests/semantic: 1671 tests OK (2 skipped). python tests/semantic/regen_fixtures.py --check: clean. python -I tests/test_shader_checks.py: 60 tests OK.
  • No corpus count: I don't have the game files, so translated / spirv-val counts before and after are not measured. The change only adds code where a wave32 VCC that the lane-mask analysis does not certify is read as a mask.

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.

AI-assisted.

…L bit L

s_mov_b32 vcc_lo, 0xa (or a copy of a data SGPR, or a load into VCC)
followed by v_cndmask_b32 / a carry-in / s_and_saveexec_b32 on vcc_lo
selected every lane: Gen.mask_src returned the raw %vcc word, so any
non-zero value meant all lanes. In a wave32 program where lane_masks.py
does not certify VCC as a mask, lane L now takes bit L of it, as for a
data SGPR or an immediate. A real mask (0 or ~0 per lane) is unchanged.

GPU test cs_w32_vcc_data (RTX 5080 and Radeon RDNA2 iGPU), semantic
fixture and assertions, docs/design.md contract row.

AI-assisted.
@tumbione

Copy link
Copy Markdown
Contributor

Tested 06f3e41e on NVIDIA GeForce RTX 5090, driver 616.56, Windows 11 (10.0.26300): pass

llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. Test programs built with scripts/build_runtime.ps1 from 4eb6155d, this branch's merge base; the branch changes no C++ or CMake, so they match this commit.

Run Result
run_gpu_tests.py --filter cs_w32_vcc_data, 3 runs pass 3/3: 258 1032 2 1052 4294967040 5 4104 781
Negative control: tools/rdna2spirv.py from 4eb6155d fails as described: 32 32 32 32 4294967040 5 32 32; passes again with this branch's translator
Full run_gpu_tests.py 137/181 passed, 44 skipped, 0 failed (main 4eb6155d here: 136/180, 44 skipped)
LEONIDA_W64_EMULATE=1 run_gpu_tests.py --filter cs_ 87/91 passed, 4 skipped, 0 failed
python -I -m unittest discover -s tests/semantic 1671 tests OK (2 skipped)
tests/test_shader_checks.py, tests/test_lane_masks.py, regen_fixtures.py --check 60 OK, ok, exit 0

No game data involved. AI-assisted (Claude Code): it ran everything above on this machine.

@Rainmaker33

Copy link
Copy Markdown

Tested 06f3e41 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass.

The PR's diff applied cleanly to main 4eb6155. VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; harness programs from a CMake build of that main; overlay layers off.

  • scripts/run_gpu_tests.py: 137/181 pass, 44 skipped (wave64), no failures (main: 136/180). cs_w32_vcc_data: 258 1032 2 1052 4294967040 5 4104 781.
  • tests/semantic/test_value_semantics.py: OK.

@Yourrespawn

Copy link
Copy Markdown
Contributor

Tested 06f3e41e on NVIDIA GeForce RTX 4080 (Ada, subgroup 32..32), driver 617.14, Vulkan API 1.4.351, Windows 11 Pro 10.0.26200: pass.

  • run_gpu_tests.py native: the PR's own cs_w32_vcc_data PASS — 258 1032 2 1052 4294967040 5 4104 781 — the wave32 VCC[L]-per-lane semantics verified on real 32-lane hardware, alongside cs_dpp_mask and cs_w32_mask_imm still passing; suite 137/181 passed, 44 skipped (native wave64, expected on this 32-lane GPU)
  • Semantic suite: 1671 OK (Python 3.12.10)
  • valu_fuzz --family mem --programs 150 --seed 18 --emulate against the modified translator: 300/300 programs match (both wave sizes), 0 mismatches

AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine.

docs/design.md
runtime/test/shaders/check.py
scripts/run_gpu_tests.py

AI-assisted.
@tumbione

Copy link
Copy Markdown
Contributor

Retested the rebased head 0df0baa8 on NVIDIA GeForce RTX 5090, driver 616.56, Windows 11 (10.0.26300): pass

llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. Test programs built with scripts/build_runtime.ps1 from ec8ec4c9; nothing under runtime/ except test shaders differs between that commit, main 16282101 and this head, so they match.

Run Result
run_gpu_tests.py --filter cs_w32_vcc_data, 3 runs pass 3/3: 258 1032 2 1052 4294967040 5 4104 781
Full run_gpu_tests.py 144/190 passed, 46 skipped, 0 failed (main 16282101 here: 143/189, 46 skipped)
tests/test_shader_checks.py, regen_fixtures.py --check 69 OK, exit 0

No game data involved. AI-assisted (Claude Code): it ran everything above on this machine.

AAyberkU pushed a commit to AAyberkU/Leonida that referenced this pull request Nov 22, 2026
…U under random EXEC

Seeded integer VALU programs run on every lane of a wave32 or wave64 wave with EXEC rewritten between instructions: compares into SGPR masks and VCC, v_cmpx, v_cndmask on the masks, carry-out/carry-in forms, v_mad_u64/i64 with a mask carry-out, 16-bit op_sel half writes and 32-bit ops. A per-lane ISA model is compared with rdna2spirv run in tests/semantic/spirv_wave_interp.py, optionally with the hardware through tools/hw_oracle. Known divergences (VCC data read as a mask, ItsNotRexed#2206; a mask read as data, ItsNotRexed#293) only with --known.

AI-assisted.
runtime/test/shaders/check.py
scripts/run_gpu_tests.py
tests/semantic/regen_fixtures.py

AI-assisted.
@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested dceaa0a3 on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 26.11.2, Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), Python 3.12.10: pass.

Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. No game files.

run result
run_gpu_tests.py (whole suite, native wave64) 197/211, 14 skipped, 0 failed (main 49475796: 170/185)
same with LEONIDA_W64_EMULATE=1 197/211, 14 skipped, 0 failed
pytest tests/test_translate.py tests/test_shader_checks.py tests/test_run_gpu_tests.py 702 passed, 4 skipped, 286 subtests passed in 70.23s (0:01:10)
unittest discover -s tests/semantic -p test_value_semantics.py 39 OK
tests/semantic/regen_fixtures.py --check clean

This PR's shaders:

  • native: PASS cs_w32_vcc_data 258 1032 2 1052 4294967040 5 4104 781; emulated: PASS cs_w32_vcc_data 258 1032 2 1052 4294967040 5 4104 781

First RDNA4 run: cs_w32_vcc_data passes native and emulated, so a data VCC read as a lane mask selects lane L by bit L here as well.

AI-assisted (Claude Code); I checked the results.

@crastinator

Copy link
Copy Markdown
Contributor

Tested dceaa0a merged into main aa2988cc (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test passes natively: cs_w32_vcc_data (258 1032 2 1052 4294967040 5 4104 781).
  • Whole run_gpu_tests.py: 197/211 native, 197/211 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 47/47.
  • tests/semantic/test_value_semantics.py: 39 passed, 283 subtests passed.

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

docs/design.md
runtime/test/shaders/check.py
scripts/run_gpu_tests.py
tests/semantic/regen_fixtures.py

AI-assisted.
@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 66c412cf7d18924916d83a5dbfcd377d1f6ca471 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Verified cs_w32_vcc_data at 66c412cf7d18924916d83a5dbfcd377d1f6ca471 on Linux Vulkan (GeForce RTX 5090, NVIDIA 595.99.02). The stock wave32 fixture matched all eight words.

For the carry-in case I cleared bit 0 of VCC, changing 0x80000001 to 0x80000000 while keeping the expected output fixed. The runner exited 1. Direct readback showed only word 2 changed, from 2 (lanes 0 and 31) to 7937 (one lane, lowest index 31). Both shader variants passed SPIR-V validation.

AI-assisted verification.

AI-assisted verification.

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 66c412c merged onto main 561b65a (clean merge) on Apple M4, macOS 27.2.1, MoltenVK 1.4.2, Python 3.15.2 and 3.12.16: pass

  • The delta since the last checked head (dceaa0a) is only merges of main. The rule (tools/rdna2spirv.py:5732-5742 in the merged tree), the fixture and the expected words are unchanged.
  • The M4 has 32-wide subgroups, so the wave32 fixture runs natively. run_gpu_tests.py --filter cs_w32_vcc_data: PASS 3/3 258 1032 2 1052 4294967040 5 4104 781, and PASS with LEONIDA_W64_EMULATE=1. Runtime built from main 561b65a, because the PR changes no C++ or CMake under runtime/.
  • Full run_gpu_tests.py: 166/233 passed, 59 skipped, 8 failed. Main on this machine gives 165/232, 59 skipped, 8 failed. Every row matches main and the new cs_w32_vcc_data row passes. The 8 failures are main's own wrong values on Apple.
  • Semantic suite (python3.15 -I -B -m unittest discover -s tests/semantic): Ran 6150, OK (skipped=1, expected failures=1). That is the same as main 561b65a, with no failing ids on either side. The new case is a subtest of the existing LaneMaskConstants, so the count does not change.
  • test_value_semantics.py (41 OK, LaneMaskConstants 2/2), tests/test_shader_checks.py (82), test_run_gpu_tests.py (47), test_run_gpu_wavemask.py (6), test_lane_masks.py, test_docs_design_rows.py (4) and regen_fixtures.py --check all pass on both Pythons. compileall and git diff --check are clean.
  • Corpus slice --shard 0/64: 415/415 translated and 415/415 pass spirv-val, the same as main. 0 of 415 .spv differ.
  • Mutations in Gen.mask_src: LaneMaskConstants caught all four that change behaviour. I also ran three of them on the GPU fixture, and it failed each time.
    • Reverting the block gives the PR's old words 32 32 32 32 4294967040 5 32 32 on the M4.
    • Bit 0 for every lane: caught by the semantic test (not run on the GPU).
    • An inverted select gives 30 24 286 4 32 5 24 19 on the GPU.
    • Lane L reading bit L^1 gives 2 1032 258 1052 4294967040 5 4104 525 on the GPU.
    • Dropping the "vcc" not in self.cur_masks guard survives, as expected: a certified mask holds 0 or ~0 per lane, so bit L of it is the same. The guard only keeps the SPIR-V for certified masks unchanged.
  • Two small points, not blockers:
    • docs/design.md:424 says "as for a data SGPR or an immediate (row above)". After the merges, the row above is "64-bit constant vector compares" (line 423). The row it means is "Constant lane masks" at line 420, so name it.
    • tools/rdna2spirv.py:5739 shifts by wave_lane() unmasked. The SGPR and immediate branches of the same function shift by lane & 31. In a wave32 non-compute, non-pixel stage, wave_lane() is the raw subgroup lane (tools/rdna2spirv.py:4715-4716), which can be 32-63 on a 64-wide subgroup, and OpShiftRightLogical by 32 or more is undefined. Masking with 31, as at lines 5722 and 5754, would make the three branches the same.

AI-assisted.

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.

8 participants