Skip to content

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

Open
Vonsek wants to merge 4 commits into
ItsNotRexed:mainfrom
Vonsek:fix/vcc-data-mask
Open

Vonsek wants to merge 4 commits into
ItsNotRexed:mainfrom
Vonsek:fix/vcc-data-mask

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

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).

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