Skip to content

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

Open
Vonsek wants to merge 6 commits into
ItsNotRexed:mainfrom
Vonsek:claude/w64-vcc-data-mask
Open

Vonsek wants to merge 6 commits into
ItsNotRexed:mainfrom
Vonsek:claude/w64-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-W64-VCC-DATA, #2300 (comment)

Depends on: #2206 (this branch is #2206's commit, a merge of main, and one new commit, 82b48eb)

What and why

#2206 fixed wave32: a VCC holding data, read as a lane mask, gives lane L bit L. Wave64 (native and --wave64-emulate) still read the raw %vcc word in every lane. %vcc holds the vcc_lo word after s_mov_b32 vcc_lo, K, so any non-zero vcc_lo selected all 64 lanes, and vcc_hi (kept in %vcc_hi) was ignored. The hardware reads VCC[L] for lane L.

wave64 hardware before
s_mov_b32 vcc_lo, 0xa; s_mov_b32 vcc_hi, 0x30000 / v_cndmask_b32_e32 ..., vcc lanes 1, 3, 48, 49 all 64
vcc_lo = 0x80000001, vcc_hi = 1 / v_add_co_ci_u32_e32 carry-in lanes 0, 31, 32 all 64
vcc_lo = 0, vcc_hi = 0x100 / v_cndmask_b32_e32 lane 40 none
vcc_lo = 0xff0000, vcc_hi = 0xf / s_and_saveexec_b64 s[8:9], vcc lanes 16-23, 32-35 lanes 0-39

Change (tools/rdna2spirv.py):

  • Gen.mask_src, wave64, VCC not certified by lane_masks.py: lanes 0-31 take bit L of %vcc (the vcc_lo word, or the 0 / ~0 a missed mask left there). Lanes 32-63 take bit L-32 of %vcc_hi when it holds VCC[63:32]. Otherwise they read %vcc as before, because a whole-VCC write (v_cmp, a carry-out, s_mov_b64 vcc, ...) puts each lane's bit there.
  • vcc_hi_fresh(blocks, succ): a small forward dataflow pass, run next to the lane-mask analysis. It returns the instructions before which, on every path, the last write to VCC's high half went to %vcc_hi (a write to vcc_hi or a 64-bit scalar load into VCC) and not to the whole VCC.
  • --wave64-emulate: the wave_mask cache key for VCC now includes the %vcc_hi store and the flag, and OpStore %vcc_hi is tracked like %vcc.

lane_masks.py, Gen.dst and the half-mask write paths are unchanged (#2221 / #2352 work there). New contract row in docs/design.md, and #2206's row now points to it.

Not covered: vcc_lo written as data right after a whole-VCC data write (s_mov_b64 vcc, s[4:5] then s_mov_b32 vcc_lo, K). Gen.dst stores the word in all 64 lanes there, so lanes 32-63 keep the old behaviour. Also not covered: a wave64 VS/PS/GS on 32-wide subgroups (SHADER-10).

Tested

Windows 11, LLVM 21 llvm-mc, VK_LOADER_LAYERS_DISABLE=~implicit~, one GPU at a time. New test runtime/test/shaders/cs_w64_vcc_data.asm, with the expected words derived by hand from the ISA in its header. Its out[5] (a compare) and out[7] (s_mov_b64 vcc of a data pair) are controls.

GPU Driver Mode run_gpu_tests.py --filter cs_w64_vcc_data tools/rdna2spirv.py from #2206
AMD Radeon RDNA2 iGPU, Ryzen 9 9950X3D (subgroup 32..64) 26.10.1 native wave64 (subgroup 64) PASS 260 1033 3 1068 10241 40 4108 800 FAIL 64 64 64 32 0xffffff00 40 40 800
same 26.10.1 LEONIDA_W64_EMULATE=1 PASS, same words not run
NVIDIA GeForce RTX 5080 (subgroup 32) 616.92 LEONIDA_W64_EMULATE=1 PASS, same words FAIL, same words as the Radeon
  • Negative control: with vcc_hi_fresh sabotaged so that a write to vcc_hi no longer marks %vcc_hi as current (one line), the test fails on both GPUs and in the semantic test with 290 1064 34 1052 0xffffff00 40 4112 800.
  • Semantic: LaneMaskConstants in tests/semantic/test_value_semantics.py runs the fixture over 64 lanes. It checks the words against a plain-Python reference (VCC = vcc_hi << 32 | vcc_lo, lane L reads bit L) and that they differ from the old words. It fails without the change.
  • python -m unittest discover -s tests/semantic: 2567 tests OK. python tests/semantic/regen_fixtures.py --check: clean. python -I tests/test_shader_checks.py: 60 OK. python -I tests/test_run_gpu_tests.py: 30 OK.
  • No corpus count: I don't have the game files. The change only adds code where a wave64 VCC that the lane-mask analysis does not certify is read as a 64-bit 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.
…L bit L

In a wave64 program (native or --wave64-emulate) a VCC written as data
(s_mov_b32 vcc_lo, K / s_mov_b32 vcc_hi, K, a load into VCC) and read as a
lane mask by v_cndmask_b32, a carry-in or s_and_saveexec_b64 used the raw
vcc_lo word in every lane, so any non-zero vcc_lo selected all 64 lanes and
vcc_hi was ignored.

Gen.mask_src now gives lanes 0-31 bit L of %vcc and lanes 32-63 bit L-32 of
%vcc_hi where a new dataflow pass (vcc_hi_fresh) shows %vcc_hi holds
VCC[63:32] on every path; after a whole-VCC write lanes 32-63 keep reading
%vcc as before. GPU test cs_w64_vcc_data with hand-derived words, semantic
fixture, docs/design.md row.

AI-assisted.
@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent RTX 5070 / Windows check at 82b48eb (driver 621.24, wave64 emulation on 32-wide subgroups). The PR fixture produced the expected eight words, and all the modules below passed Vulkan 1.2 SPIR-V validation.

I found a mixed-predecessor case at a scalar branch join. This is separate from the straight-line whole-VCC-write-then-low-half-write limitation in the description. With s4 holding TGID_X and 64 lanes per group:

s_mov_b32 s6, 2
s_mov_b32 s7, 8
s_mov_b32 vcc_lo, 2
s_cmp_eq_u32 s4, 0
s_cbranch_scc1 2
s_mov_b64 vcc, s[6:7]
s_branch 1
s_mov_b32 vcc_hi, 4
v_mov_b32_e32 v2, 1
v_cndmask_b32_e32 v3, 0, v2, vcc

I stored v3 per lane. Group 0 should select lanes 1 and 34 and instead selects 1 and every lane from 32 to 63. Group 1 correctly selects 1 and 35. Running either write as a straight-line control selected its two expected lanes in both groups.

The static merge in vcc_hi_fresh gives this join a single false state because one predecessor writes the high half and the other writes full VCC. The high-half path then loses its live %vcc_hi; upper lanes consume the nonzero raw %vcc left by the earlier low-half write. A join state that distinguishes mixed provenance would let the translator preserve the representation across that join or reject the case explicitly.

@Rainmaker33

Copy link
Copy Markdown

Tested 82b48eb 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 4947579. 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: 140/187 pass, 47 skipped, no failures. cs_w32_vcc_data: 258 1032 2 1052 4294967040 5 4104 781. cs_w64_vcc_data skips natively.
  • With LEONIDA_W64_EMULATE=1 --filter cs_w64_vcc_data: pass, 260 1033 3 1068 10241 40 4108 800.
  • tests/semantic/test_value_semantics.py: OK.

@LloydNicholson

Copy link
Copy Markdown
Contributor

Tested 82b48eb on an RX 9060 XT (RDNA4, GFX1200), RADV Mesa 27.0.0-devel, Nobara Linux (Fedora 44): pass

This adds native wave64 on RADV and RDNA4 to the Windows RDNA2 and RTX runs already here. Setup: llvm-mc 22.1.8 and SPIRV-Tools 2026.1. The runtime was built from the PR head with GCC and pinned with LEONIDA_VK_DEVICE=9060.

  • run_gpu_tests.py --filter cs_w64_vcc_data:
    • Native wave64 (subgroup 64): PASS 260 1033 3 1068 10241 40 4108 800.
    • LEONIDA_W64_EMULATE=1: PASS, the same words.
    • Both match the words in the description.
  • Red, then green: with tools/rdna2spirv.py from HEAD~1 (rdna2spirv: wave32 VCC holding data, read as a lane mask, gives lane L bit L #2206 merged with main, without 82b48eb), the same native run fails with 64 64 64 32 4294967040 40 40 800. That's 0xffffff00 in word 4, the same words as the "before" column.
  • Full run_gpu_tests.py: 172/187 passed, 15 skipped, 0 failed, both native and with LEONIDA_W64_EMULATE=1. The two extra tests compared with main 4947579 (170/185 on this machine) are this PR's cs_w32_vcc_data and cs_w64_vcc_data.
  • Other checks:
    • python -m unittest discover -s tests/semantic: OK.
    • tests/semantic/regen_fixtures.py --check: clean (exit 0).
    • tests/test_shader_checks.py and tests/test_run_gpu_tests.py: OK.

I didn't run @duudiis's branch-join case, and didn't repeat the vcc_hi_fresh sabotage control.

AI-assisted (Claude Code).

@sebeuh

sebeuh commented Nov 22, 2026

Copy link
Copy Markdown

Tested 82b48eb (PR head, as is) on AMD Radeon RX 7900 XTX (RDNA3), AMD driver 26.11.2 (LLPC), Vulkan 1.4.359, subgroup 32..64, Windows 11 [26300.9974]: pass.

  • Native wave64: cs_w32_vcc_data and cs_w64_vcc_data both pass.
    cs_w32_vcc_data: 258 1032 2 1052 4294967040 5 4104 781
    cs_w64_vcc_data: 260 1033 3 1068 10241 40 4108 800
  • LEONIDA_W64_EMULATE=1 --filter cs_w64_vcc_data (emulated, same GPU): pass, same words as native.
  • Full scripts/run_gpu_tests.py: 172/187 pass, 15 skipped (14 run by d3d12_* tests, ps_w64x_readlane because the driver cannot require a 64-wide fragment subgroup), 0 failures.
  • The native words are identical to the emulated words reported on the RTX 3090 above (Rainmaker33), so native wave64 and the emulation agree on this fixture.

Setup: VS 2022, Vulkan SDK 1.4.341.1, llvm-mc 21.1.8 (WSL Ubuntu), harness programs built from main 4947579, no game files.
Not covered by this run: the mixed-predecessor join case reported by duudiis above.

Drafted with help from an AI assistant; the commands were run by me.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (MSVC 14.51, llvm-mc 23.1.6): cs_w32_vcc_data passes with identical words on the RTX 4080 SUPER and the Intel UHD 770 (258 1032 2 1052 4294967040 5 4104 781). cs_w64_vcc_data skips on both (no 64-wide compute subgroup), so the wave64 half needs an AMD GPU.

@dimi1engineer

Copy link
Copy Markdown

Tested 82b48eb on NVIDIA RTX 2060 (Turing, subgroup 32..32), driver 615.71.09, Ubuntu 24.04 (Docker, llvm-mc 21.1.8): pass.

Adding two things not covered above:

  • With LEONIDA_W64_EMULATE=1 set for both build.py and check.py, cs_w64_vcc_data passes on this 32-wide GPU (260 1033 3 1068 10241 40 4108 800); natively it skips, as on the 4080 SUPER.
  • Negative control: with main's tools/rdna2spirv.py the same fixtures fail (cs_w32_vcc_data gives 32 in the lane-count words, cs_w64_vcc_data emulated gives 64 64 64), and tests/semantic has 2 failures, so both tests catch the bug.

No regressions vs main: check.py 161/165 and run_gpu_tests 172/187 emulated.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 82b48eb on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 140/187 passed, 47 skipped, 0 failed. main 4947579 gives 139/185, 46 skipped, 0 failed. All 192 test shaders translate and pass spirv-val.
  • New GPU tests: cs_w32_vcc_data PASS, cs_w64_vcc_data SKIP.
  • tests/semantic/test_value_semantics.py: ran 31 tests in 1.935s; OK.

AI-assisted (Claude Code).

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

AI-assisted.
docs/design.md
tools/rdna2spirv.py

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

AI-assisted.
@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested 61222ee (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

No game files. AI-assisted.

@lunarminus

Copy link
Copy Markdown

Tested 61222ee9 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • Merges cleanly. The PR changes no C++ or CMake, so the GPU test programs are a Linux build of d0835dd9, not rebuilt.
  • Full scripts/run_gpu_tests.py: 198/212 passed, 14 skipped, 0 failed, both native wave64 and with LEONIDA_W64_EMULATE=1. 216 shaders translated and all pass spirv-val.
  • Per-test comparison with d0835dd9 without the PR: that run gives 196/210, 14 skipped, in both modes. All 210 shared tests have the same PASS/FAIL/SKIP result. The two extra tests are this PR's fixtures, which pass in both modes with the expected words:
    • cs_w32_vcc_data: 258 1032 2 1052 4294967040 5 4104 781
    • cs_w64_vcc_data: 260 1033 3 1068 10241 40 4108 800
  • The emulated cs_w64_vcc_data SPIR-V differs from the native one, so the emulated run really went through --wave64-emulate.
  • Red, then green: with main d0835dd9's tools/rdna2spirv.py (which also lacks rdna2spirv: wave32 VCC holding data, read as a lane mask, gives lane L bit L #2206), both fixtures fail in both modes:
    • cs_w32_vcc_data: 32 32 32 32 4294967040 5 32 32
    • cs_w64_vcc_data: 64 64 64 64 4294967040 40 64 800
  • CPU tests:
    • tests/semantic/test_value_semantics.py (AMDGPU clang/llvm-mc 23.1.5): 39 tests OK, including LaneMaskConstants.
    • tests/semantic/regen_fixtures.py --check: clean (exit 0).
    • tests/test_shader_checks.py: 75 OK.
    • tests/test_run_gpu_tests.py: 40 OK.
  • Not run: @duudiis's mixed-predecessor branch-join case, the full tests/semantic suite and the vcc_hi_fresh sabotage control.

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.

10 participants