Skip to content

Translator: a lane mask read as data gives the wave's bits (SHADER-21 part 1, #210) - #293

Open
simonbronk wants to merge 5 commits into
ItsNotRexed:mainfrom
simonbronk:translator/mask-as-data
Open

simonbronk wants to merge 5 commits into
ItsNotRexed:mainfrom
simonbronk:translator/mask-as-data

Conversation

@simonbronk

@simonbronk simonbronk commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Depends on: #2231

SHADER-21, part 1 (#210): a lane mask read as plain data now gives the wave's bits, not this lane's bool.

The translator keeps one bit per lane in a register holding a lane mask (0 or 0xffffffff). Hardware has the whole mask there. Any instruction that reads such a register as a value got the lane's bool instead. Examples: v_mov_b32 v1, s20 followed by a store; s_lshr_b32 or s_and_b32 …, 0xff of a mask; an s_mov_b64 copy read back with v_mov_b32; v_readlane of a parked mask; exec_lo/vcc_hi used as values. #210 measured this on NVIDIA with emulation. The tests below show the same result on AMD with native wave64, and in wave32.

Change

  • tools/lane_masks.py: new data_reads(ins, state), called from analyse(..., reads=). It finds registers that hold a mask but that an instruction reads as data. These stay one bit per lane:
    • mask readers: s_bcnt*, s_ff*, v_mbcnt*, s_cmp*, s_bitcmp*;
    • copies, parking, and bitwise ops whose result is still a mask;
    • saveexec;
    • the v_cndmask selector and carry-ins;
    • writes to EXEC or VCC.
  • tools/rdna2spirv.py:
    • Gathering the bits. mask_as_data gathers each half (OpGroupNonUniformBitwiseOr, or the emulated wave64 round) before the instruction emits anything. load_reg and src_u return that word for those registers. wave_mask is split so wave_bits can be reused.
    • 64-bit data. s_and/or/xor/andn2/orn2_b64 and s_cselect_b64 on data now compute each register of the pair. Before, they wrote the low word into both, so s_or_b64 s[56:57], s[2:3], 1 lost the high word even with no mask involved.
    • mask_src reads the raw register. This keeps the v_cndmask selector a mask when the same register is also a value operand.
    • exec_lo writes turn on a lane when that lane's bit is set ((v >> (lane & 31)) & 1). For a one-bit-per-lane value this is the same as non-zero. Without it, a mask combined with data and moved to EXEC would turn on every lane.
  • docs/design.md: a "Lane mask read as data" contract row, with covered cases and known gaps.

Tests

New GPU tests, each failing on main (measured on the AMD iGPU):

Shader What it reads as data main This PR
cs_wm_as_data (wave64) v_mov_b32 and store, s_mov_b64 copy, s_lshr_b32, s_and_b32, writelane/readlane, s_lshr_b64, v_add_nc_u32, s_add_u32 0 0 0 0 0 0 1 3 0xfafafafa 0xfafafafa 0x7d7d7d7d 0xfa 0xfafafafa 0xafafafaf 0xfafafafb 0xfafafafd
cs_wm_as_data2 (wave64) exec_lo, exec_hi, vcc_hi, a v_cndmask value, s_or_b32, after v_readfirstlane; plus s_bcnt1 and a mask-selected v_cndmask, unchanged 0xffffffff 0 0xffffffff 0xffffffff 24 2 0xffffffff 0xffffffff 0xffff0000 0x10000 0xff 0xff 24 2 0xffff0001 0xffff0000
cs_wm_as_data32 (wave32) v_mov_b32 and store, s_lshr_b32, s_lshl_b32 + s_add_u32, v_or_b32 0 0 0xff00 0 0xfafafafa 0xfafafaf 0xfafbf900 0xfafafafa
cs_wm_as_data64 (wave64) s_and_b64, s_xor_b64 and s_cselect_b64 of a mask with a data pair; s_or_b64 of data; v_cndmask with s20 as value and s[20:21] as selector 0 0 0xf0f0f0f 0xf0f0f0f 0 0 0xffffffff 0 0xa0a0a0a 0xfa00fa00 0xf5f5f5f5 0x5fa05fa 0xfafafafa 0xfafafafa 0xff00ff00 0xfafafafa
cs_wm_as_exec (wave64) s_and_b32 of a mask and data, then s_mov_b32 exec_lo 0 1 0 1 1 1 1 1 0 1 0 1 0 0 0 0

Each is registered in check.py and run_gpu_tests.py. tests/test_lane_masks.py adds test_data_reads for the classification. tests/test_shader_checks.py learns about wave32 dump tests other than cs_store.

Windows 11, LLVM 21.1.8 llvm-mc, GPU picked with VK_LOADER_DRIVERS_SELECT:

GPU Driver Mode run_gpu_tests.py check.py
AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2), subgroup 32..64 AMD 25.10.36 native 53/54 passed, 1 skipped 47 of 49 pass, 2 skipped
same same LEONIDA_W64_EMULATE=1 53/54 passed, 1 skipped 47 of 49 pass, 2 skipped
NVIDIA GeForce RTX 5070, subgroup 32 621.24 native 30/54 passed, 24 skipped (wave64) 25 of 49 pass, 24 skipped
same same LEONIDA_W64_EMULATE=1 52/54 passed, 2 skipped 47 of 49 pass, 2 skipped

The skips are the same as on main: wave64 tests without a 64-wide subgroup, mesh shaders build.py doesn't build, and ps_vcc_x2, which runs only in the interpreter. Results:

  • python -m pytest tests -q with LLVM_MC set: 1478 passed, 6 skipped, 1 xfailed.
  • python -I -m unittest discover -s tests/semantic: OK.
  • python -m compileall -q make_game.py tools tests: clean.

Scope and gaps

Rebased on #2231 (2026-11-22). #2231 makes a wave64 v_cmp_*_e64 / carry-out SDST printed as one SGPR the pair. Without it, about 99% of this PR's wave-bit gathers were for pairs that are really masks (98,882 in 9,326 shaders on an older main; 775 in 46 with the fix). tests/semantic/test_salu_movrels_lane_mask.py (SHADER-284, added to main since) expected the old behaviour for its control: a mask copy read by v_mov_b32 gave this lane's bit. That control now expects the wave's bits (5), as on hardware. After the rebase: semantic suite 1647 OK; run_gpu_tests.py 170/179 passed, 9 skipped, on both AMD 25.10.36 (native) and RTX 5070 621.24 (LEONIDA_W64_EMULATE=1); the skips are the same as on main.

Rebased on main 1628210 with #2290 merged (2026-11-22, head 004e31f). #2290 (SHADER-21 part 2) made a v_mov_b32 copy of a mask into a VGPR an EXEC-gated write. Combined with this PR, that broke #2290's cs_mask_vgpr_exec on both GPUs: the mask was gathered at the store, so the old words of the lanes EXEC had left off counted as set bits and were overwritten. The copy now reads its mask source as data, gathered at the v_mov_b32, as hardware writes the wave's bits to the active lanes. The VGPR holds plain data from there on. A new GPU test, cs_mask_vgpr_exec2 (wave32), uses a mask that differs per lane: lanes 0-3 get 0x1f and lanes 4-31 keep 0xdeadbeef; main gives 0xffffffff in lanes 0-3. tests/test_lane_masks.py follows the new shape.

After that rebase:

  • semantic suite: 4145 OK;
  • run_gpu_tests.py: 181/196 passed, 15 skipped, on AMD 25.10.36 (native) and RTX 5070 621.24 (LEONIDA_W64_EMULATE=1); the skips are the same as on main;
  • crosslane_fuzz.py --wave both --w64-native on the AMD iGPU, seeds 5 and 6 (--dpp, 50 programs) and 9001 (150): 0 non-hypothesis mismatches in every mode. main 1628210 has 2/1/1, 1/0/0 and 4/3/3 (wave32 native / wave64 emulate / wave64 native).

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

🤖 Generated with Claude Code

@tylerstraub

Copy link
Copy Markdown
Contributor

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

I built the Vulkan harness from this head on Ubuntu 26.04.1 LTS and ran scripts/run_gpu_tests.py --filter cs_wm_as_ in separate clean work directories. All five synthetic shaders translated and passed spirv-val in each mode.

Mode GPU readback
LEONIDA_W64_EMULATE=0 The wave32 fixture cs_wm_as_data32 returned fafafafa 0fafafaf fafbf900 fafafafa (hex). The other four fixtures skipped because the device lacks native 64-wide compute subgroups.
LEONIDA_W64_EMULATE=1 All five fixtures matched their expected words, including both halves in cs_wm_as_data64. The EXEC-write fixture cs_wm_as_exec returned 0 1 0 1 0 0 0 0.

Coverage is limited to the five compute fixtures on the PR head. The requested corpus comparison remains open.

AI-assisted verification.

@crastinator

Copy link
Copy Markdown
Contributor

Ran this on a second AMD GPU with native wave64: RX 6700 XT (RDNA2, RADV NAVI22, Mesa 26.3.1, Linux). PR head f721e5f on 36ace71.

Run cs_wm_as_data _data2 _data32 _data64 _exec Suite
check.py, native ok ok ok ok ok 47 of 49 pass, 2 skipped (mesh fixtures build.py doesn't build)
check.py, LEONIDA_W64_EMULATE=1 ok ok ok ok ok 47 of 49 pass, 2 skipped
run_gpu_tests.py, native PASS PASS PASS PASS PASS 53/54, 1 skipped (ps_vcc_x2, #247)
run_gpu_tests.py, emulated PASS PASS PASS PASS PASS 53/54, 1 skipped
  • Words. Every word matches the "This PR" column in the description.
  • Subgroup size. RADV's api_subgroup_size is 64 on the native cs_wm_as_data run. Forced to 32 under emulation, it gives the same words.
  • Control. The same five .asm translated with main's translator give your "main" column word for word on this card, so the tests also catch the bug on RDNA2.
  • Other checks. build.py: 50 translated, 50 pass spirv-val. test_lane_masks.py, test_shader_checks.py and test_translate.py: 149 passed, 2 skipped.

AI-assisted (Claude Code): it ran the checks and wrote this summary. No game files.

@Aminecsmc

Copy link
Copy Markdown
Contributor

Tested f721e5f (as pushed) on NVIDIA GeForce RTX 3050 Laptop GPU (Ampere, subgroup 32), driver 610.91, Windows 11 build 26300: pass. AI-assisted (Claude Code).

  • run_gpu_tests.py, native: 55/55 translated, 55/55 pass spirv-val. 30/54 pass, 24 skipped (wave64), 0 fail. cs_wm_as_data32 PASS: 0xfafafafa 0xfafafaf 0xfafbf900 0xfafafafa.
  • With LEONIDA_W64_EMULATE=1 --filter cs_wm_as: 5/5 pass:
    • cs_wm_as_data: 0xfafafafa 0xfafafafa 0x7d7d7d7d 0xfa 0xfafafafa 0xafafafaf 0xfafafafb 0xfafafafd
    • cs_wm_as_data2: 0xffff0000 0x10000 0xff 0xff 0x18 0x2 0xffff0001 0xffff0000
    • cs_wm_as_data32: 0xfafafafa 0xfafafaf 0xfafbf900 0xfafafafa
    • cs_wm_as_data64: 0xa0a0a0a 0xfa00fa00 0xf5f5f5f5 0x5fa05fa 0xfafafafa 0xfafafafa 0xff00ff00 0xfafafafa
    • cs_wm_as_exec: 0 1 0 1 0 0 0 0
  • unittest discover -s tests/semantic: 388 OK.
  • Note: it conflicts with current main (d937b7f) in docs/design.md, check.py, run_gpu_tests.py and tools/rdna2spirv.py, so it needs a rebase before merging. These results are for the pushed head.

Toolchain: MSVC 14.44, Vulkan SDK 1.4.363 / SPIRV-Tools v2026.4, llvm-mc 21.1.8 (built with scripts/build_llvm_mc.ps1).

@baptisteba

baptisteba commented Nov 21, 2026 •

Copy link
Copy Markdown

Code read and CPU tests on f721e5f (no GPU run): pass, with concerns below.

Commands:

  • python -m compileall -q tools tests: clean
  • python -I tests/test_lane_masks.py: ok (includes test_data_reads)
  • python -I tests/test_shader_checks.py: 10 tests, OK
  • python -I -m unittest discover -s tests/semantic: 388 tests, OK
  • Hand-written pixel-shader snippets translated with this branch, with the merge-base (36ace71) and with current main, comparing the emitted SPIR-V.
  • The five cs_wm_as_* GPU tests were not run here, and no corpus slice.

Findings:

  1. Rebase needed. git merge-tree against current main reports conflicts in docs/design.md, runtime/test/shaders/check.py, scripts/run_gpu_tests.py and tools/rdna2spirv.py (GitHub also shows the branch as conflicting). In rdna2spirv.py, main's wave_mask() now carries an emulation cache (key / x_gen / x_tok / x_mcache) inside the function this PR splits into wave_mask / wave_bits, so the split needs redoing and the emulated runs repeating.

  2. tools/lane_masks.py:208 (data_reads, bitwise ops): a mask combined with a register the analysis calls data is gathered, then consumed as a per-lane mask. For v_cmp_gt_u32 s0, 5, v0 / s_and_b32 s1, s0, s7 / v_cndmask_b32 v4, v1, v2, s1 with s7 unknown, this branch emits two OpGroupNonUniformBitwiseOr for s0, stores wave_bits & s7 in s1, and the selector still tests s1 != 0 (merge-base and main emit no subgroup op and keep the lane's own bit). If s7 is a per-lane mask the analysis missed (it only accepts a mask written on every path), a lane whose own bit is clear selects as true when any lane's bit is set; before this change a missed mask was harmless. This is a hypothesis: I could not build such a miss from instructions the translator accepts, and I have no corpus. A --limit/--shard comparison plus a count of data_reads hits by kind would settle it.

  3. tools/rdna2spirv.py:369 (dst, exec_lo): a non-constant exec_lo write outside compute/mesh now loads the subgroup lane. For s_and_b32 s1, s0, exec_lo / s_mov_b32 exec_lo, s1 / s_or_b32 exec_lo, exec_lo, s0 in a pixel shader, merge-base and main emit no GroupNonUniform capability and no %sg_lane; this branch adds the capability and two %sg_lane loads. With the usual s_and_saveexec_b32 form the capability is already there on main (saveexec's OpGroupNonUniformAny), so only the lane load is new. Results are unchanged, since the value is this lane's 0/~0. Not blocking; could the bit test be limited to values that were gathered as data, so shaders with no other subgroup op keep none?

  4. Minor (both reproduced by translating a snippet):

    • tools/rdna2spirv.py:1859: s_and_b32 s41, s21, s7 / s_mov_b32 exec_hi, s41 goes through exec_half_write, which still tests the register for non-zero, so the high-half twin of cs_wm_as_exec turns on all of lanes 32-63. Not in the design.md gap list, which names only the 64-bit s_mov_b64 exec write.
    • tools/rdna2spirv.py:1708 (data64): s_and_b64 s[40:41], s[20:21], 0xff is classified as a data read and both halves are gathered (four OpGroupNonUniformBitwiseOr), but the literal is outside data64's -16..64 range, so the instruction falls through to the mask path and reads the raw register. Same result as main, with unused gathers.

Fable 5.2 AI Assisted review

@VictorJulianiR

Copy link
Copy Markdown
Contributor

SHADER-84 follow-up to the RTX 5090 wave32 report. I checked what the memory fuzzer expects and compared the translator before and after this PR.

On the reporter's baseline 91b36cf, an independent packed-bit oracle agreed with the fuzzer on all 76 wave-level mask reads in the 50 seed-1 programs. Of those reads, 52 had partial EXEC and 24 had full EXEC. Substituting each lane's Boolean for the packed scalar changed the final output of exactly 13 programs (864 words). The predicted zero-based indices are 4, 7, 12, 13, 16, 19, 23, 27, 29, 31, 41, 45, 46. The hardware report gives a count but no indices. CPU oracle and per-program output

I also ran three synthetic compute cases on Mesa llvmpipe, subgroup size 8. The fixtures verify the eight contributing lanes share a subgroup. For EXEC 0xa5, after restoring EXEC, the expected move, shift and AND results were 0xa5, 0x14, 0xa5 on every lane. Both the reporter's baseline and this PR's parent (36ace71) matched 0/8 lanes. The PR head (f721e5f) matched 8/8. An all-true 0xff case also went from 0/8 to 8/8. The all-false control matched 8/8 on all three revisions. All fixtures passed spirv-val. Vulkan readbacks for all revisions

This isolates a translator defect that produces the reported failure count. Can someone with the original 32-wide setup compare its failing indices or replay the 50 programs on this PR after its rebase? That would tell us whether it accounts for the entire hardware report.

AI-assisted. All inputs were synthetic.

@poke900310-lgtm

Copy link
Copy Markdown

I ran the corpus comparison asked for above, plus the suite on RDNA4: RX 9070 XT (gfx1201, native 64-wide subgroups), driver 32.0.32015.16001, Windows 11, native llvm-mc 21. PR head f721e5f vs merge-base 36ace71.
Corpus, all 26,503 shaders, rdna2spirv.py --shard i/4: before 26,503 translated / 26,503 pass spirv-val, after 26,503 / 26,503. No regression in either count.
The SPIR-V changes in 11,843 modules (changed/total): ps w64 6,503/10,031, ms w64 1,869/9,282, cs w32 1,457/1,829, ps w32 1,127/2,070, cs w64 627/860, vs w64 259/1,149, vs w32 1/1,087, gs 0/195.
8,893 of them gain mask-as-data gathers (OpGroupNonUniformBitwiseOr), and 3,229 of those gain 17 or more. Size growth over the changed modules is a median of 0.5% and a max of 21.5%. 6,299 of the 8,893 are wave64 PS. Per your scope note, those are exact on a 64-wide subgroup or with --wave64-emulate, and on 32-wide GPUs they stay with SHADER-10.
2,541 wave32 modules (1,414 CS, 1,127 PS) change only through the exec_lo per-bit write, with no new gather. 72 wave32 PS gain the GroupNonUniform capability where they had none. That's baptisteba's point 3 at corpus scale.
409 wave64 modules change with neither new gathers nor the exec_lo path. I haven't traced which rule moves them, so I'm only reporting the count.
GPU, run_gpu_tests.py native: 55/55 spirv-val, 53/54 pass, 1 skipped (ps_vcc_x2). All five cs_wm_as_* match the description word for word. With LEONIDA_W64_EMULATE=1: 53/54, same words.
Against main at ee97b84, git merge-tree also conflicts in tests/test_shader_checks.py, which makes 5 files.
AI-assisted, run on my own machine.

ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
Runs each FUZZ-7 program natively on the AMD GPU in wave32 and native
wave64, with its real group size and EXEC setup, every thread storing its
14 words, and compares them with the model. hw_oracle gains raw kernels
(own stores), per-kernel workgroup size and wave64 code objects; the
launcher takes name:threads:words tokens.

24,000 programs on gfx1150: 0 mismatches; the permlane FI=0 and DPP8
inactive-source hypotheses hold on the hardware too. Translator mismatches
all trace to masks read as data (#293) and permlane (#580).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ErSlimShady99

Copy link
Copy Markdown

Replay of crosslane_fuzz.py --seed 1 (default 100 programs, wave32 native + wave64 emulated) on a 32-wide NVIDIA, as asked above.

GPU:      NVIDIA GeForce RTX 4070 Ti SUPER (Ada), driver 621.14, subgroup 32..32, Windows 11 Pro 26H2
main:     c63773d
PR #293:  f721e5f (not rebased)
Method:   generator, harness and vk_compute_test from main; only the translator swapped
          via --translator <worktree>/tools/rdna2spirv.py, so all four runs use identical programs

                           wave32 native     wave64 emulate
main                       11 mismatch       12 mismatch
main --no-maskdata          0 mismatch        0 mismatch
PR #293                    21 mismatch       12 mismatch
PR #293 --no-maskdata      11 mismatch        0 mismatch
(hypothesis-only programs identical between main and PR in every run)
  • On main, every non-hypothesis mismatch involves maskdata; with --no-maskdata main is clean on 32-wide hardware in both modes.
  • The PR head fixes none of the 23 maskdata programs (same IDs fail before and after): cs_xl32_100003/7/23/39/57/61/71/75/77/81/91, cs_xl64_100008/14/24/26/34/36/50/62/72/74/78/94.
  • The 10 programs that fail only with the PR in wave32 native all contain writelane_w32hi (cs_xl32_100009/13/27/29/55/59/63/69/85/101). The PR tree predates main's cs_w32_lane_wrap work, so this is most likely the missing rebase rather than a PR defect.
  • Caveat: an old translator against main's harness; an interface change between them could account for part of the difference. Happy to rerun the same seed once the PR is rebased.

No game data used. AI-assisted test execution and reporting.

@ICUMADETHIS

Copy link
Copy Markdown
Contributor

Fuzzer check of f721e5f on Windows 11, NVIDIA GeForce RTX 2080 Ti (Turing, 32-wide subgroups), driver 621.14, with one case worth re-checking after the rebase.

The same 200 programs (tools/crosslane_fuzz.py from main 426023a, --seed 2080 --programs 200 --wave both) were translated with this PR's base 36ace71 and with its head f721e5f (--translator). Pass/fail is identical for every program: 107 fail at both commits, and 96 of them print the same wrong words. So on these programs the head doesn't change the outcome of the fuzzer's mask-as-data op (v_mov_b32 vN, s<mask> or vcc_lo/hi), which the new contract row lists as covered.

Minimizing the head's wave32 failures (--minimize, first 12 programs) gives three cases. Two are v_writelane with a lane select of 239 or 104, the wave32 lane-wrap that main fixed after this branch, so they aren't this PR's. The third is in this PR's class:

s_mov_b32 exec_lo, 0x41f65
v_cmp_eq_u32_e64 vcc_lo, v7, v6
v_mov_b32_e32 v7, vcc_lo

It runs in a 20-thread group, so a partial wave. The base is 1,396 commits behind main, so this may come from the old base rather than from this change. That's why it's worth re-running after the rebase. On main without this PR, --no-maskdata takes this seed's real mismatches from 47 to 0, so every remaining one is in this PR's class: crosslane_fuzz.py --seed 2080 --programs 200 on the rebased head would show it directly.

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

@simonbronk

Copy link
Copy Markdown
Contributor Author

Rebased on main (f85582e): head is now 7874f5f (e8b9464, 7874f5f).

Conflicts resolved

  • wave_mask: kept main's emulated-wave64 cache (key / x_mcache); the exchange itself moved to wave_bits(mine), which mask_as_data also uses.
  • 64-bit SALU: main now has its own data path (src64_data / dst64_data), so I dropped this PR's duplicate (data64 / words64). The one change left is that a pair op whose lane-mask sources are read as data (mask_data64) takes main's data path instead of the per-lane mask path.
  • exec_lo write (baptisteba's point 3, and a wave64 bug): lanes 0-31 take bit lane & 31; in wave64, lanes 32-63 now keep their EXEC (exec_half_write). Before this, lanes 32-63 got the low word's bit.
  • Changed expectations in other contributors' tests: tests/semantic/test_salu64_bitwise_data.py and test_scselect_b64_data.py (wave32 cases) expected v_mov_b32 vN, s<mask> to give the lane's bool. With this PR it gives the wave's bits, as hardware does (Translator: wave64 lane masks used as integers read back as per-lane bools; wave64 inferred from mnemonics #210). The new expected words are 0x3ff / 0xffff0000 and the per-op word.

Tested on Windows 11 with native llvm-mc 21.1.8:

  • run_gpu_tests.py: 138/138 on an AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2, AMD 25.10.36, native wave64). Also 138/138 on an NVIDIA RTX 5070 (621.24) with LEONIDA_W64_EMULATE=1.
  • The five cs_wm_as_* fixtures fail 0/5 with main's translator on both GPUs and pass 5/5 with this head.
  • unittest discover -s tests/semantic: 1178 OK.
  • pytest tests --ignore=tests/semantic -k "not swizzle": the same failures as main (test_tile_probe, no numpy here).

Fuzzer, honestly: crosslane_fuzz.py --wave both on the RTX 5070:

seed 1 w32 seed 1 w64 emu seed 2080 ×200 w32 w64 emu
main 11 12 25 22
this PR 10 12 25 22
  • The 10 writelane_w32hi failures @ErSlimShady99 saw came from the missing rebase, and they are gone.
  • This PR does not fix the fuzzer's maskdata class. Every minimized case has a partial EXEC around the compare or the copy, for example v_cmp_ge_u32_e64 s20, v5, v1 / s_mov_b32 exec_lo, 0x22359 / v_mov_b32 v2, s20, and @ICUMADETHIS's exec_lo 0x41f65 case. The inactive lanes come back as 0 or 0xffffffff, where hardware keeps the old VGPR.
  • Hypothesis: a mask written to a VGPR ignores EXEC (write_all_lanes / mask_writes, from before this PR). This is not confirmed, and it is left for part 2. It is listed under Known gaps in the design.md row.

baptisteba's point 2 (a mask ANDed with an unknown register, then used as a selector): still a hypothesis. I found no such case in the fuzzer runs. A corpus count of data_reads hits by kind would settle it; I have no corpus slice on this machine yet.

@esteban-dcp: the rebase is done, so TEST-88 (valu_fuzz.py --family wave --seed 1 on 32-wide) can run on 7874f5f.

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

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.
AAyberkU pushed a commit to AAyberkU/Leonida that referenced this pull request Nov 22, 2026
… every encoding and source kind

A separate ISA model for 55 integer opcodes (VOP1/VOP2 as e32 and e64, VOP3-only ops, VOPC e64 + v_cndmask) with VGPR, SGPR, inline, float-inline and literal sources within the encoding and constant-bus rules, compared one lane at a time with rdna2spirv run in tests/semantic/spirv_mini_interp.py, optionally with the hardware through tools/hw_oracle. A mask read as data (ItsNotRexed#293) only with --known.

AI-assisted.
@TheMrBeez

Copy link
Copy Markdown

Correction to my comment above (now edited): the vcc_hi & 1 failure I reported was my harness's fault (test shaders without a wave64 marker were translated as wave32). Rerun as true wave64, this head matches the hardware in all seven cases. Sorry for the noise.

simonbronk and others added 5 commits November 22, 2026 22:04
The corpus is disassembled for gfx1013 without +wavefrontsize64, so the 64-bit
SDST of a wave64 v_cmp_*_e64 or carry-out prints as one register
(v_cmp_gt_f32_e64 s0, ...) while the wave writes s[0:1]. lane_masks.py took it
as s0 alone, so s1 was unknown and a later s_and_b64 / s_or_b64 of two compare
results took the 64-bit data path: SCC was each lane's own bit instead of the
wave's vote, and s_bcnt1_i32_b64 of it counted data bits.

lane_masks.step/analyse take the shader's wave size; mask_sdst widens a
one-register VALU mask destination to the pair in wave64. rdna2spirv's
valu_mask_dst writes both registers: since 804f4ae a pair read as a wave64
mask takes lanes 32-63 from the high register, which the one-register write
left stale.

Corpus (26,503 shaders): one-register SDSTs in 18,866 of 23,839 wave64
shaders; 18,868 translate differently, all wave64; the same 26,501 still
translate and pass spirv-val as on main. New GPU test cs_w64_sdst_pair (corpus form) and
tests/semantic/test_w64_sdst_pair.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… part 1, ItsNotRexed#210)

A register holding a lane mask keeps only this lane's bit (0 or ~0). When an
instruction reads it as a plain value (a VALU source, store data, s_lshr /
s_and with a constant, s_lshr_b64, s_add, exec_lo/hi or vcc_lo/hi as a value),
hardware sees the whole wave's mask; the translation saw the lane's bool.

lane_masks.data_reads finds those reads, leaving mask readers (bcnt, ff1,
mbcnt, cmp, bitcmp), copies, mask-to-mask bitwise ops, saveexec, the
v_cndmask selector, carry-ins and EXEC/VCC writes alone. The translator
gathers each half with OpGroupNonUniformBitwiseOr (or the emulated wave64
round) before the instruction and returns it from load_reg / src_u.

New GPU tests cs_wm_as_data, cs_wm_as_data2 (wave64) and cs_wm_as_data32
(wave32), all failing before; data_reads unit tests; design.md row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…exec_lo takes the lane's bit

Follow-up to the lane-mask-as-data change (ItsNotRexed#210), rebased on main's 64-bit
SALU data path (src64_data / dst64_data):
- s_and/or/xor/andn2/orn2_b64 and s_cselect_b64 whose lane-mask sources are
  read as data (mask_data64) take main's data path on both words instead of
  the per-lane mask path.
- mask_src reads the raw register, so the v_cndmask selector stays a mask
  when the same register is also a value operand.
- A register written to exec_lo turns on the lanes 0-31 whose bit is set
  (the same as non-zero for a one-bit-per-lane mask), so a mask combined
  with data and moved to EXEC no longer turns on every lane; in wave64
  lanes 32-63 keep their EXEC (exec_half_write).
- tests/semantic: test_salu64_bitwise_data and test_scselect_b64_data
  expected v_mov_b32 vN, s<mask> to give the lane's bool; it gives the
  wave's bits (ItsNotRexed#210).

New GPU tests cs_wm_as_data64 and cs_wm_as_exec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… gathered when read as data

A mask copied into a VGPR (v_mov_b32 v7, s16) and then given data in one lane (v_writelane_b32 v7, s15, 27)
was gathered as the wave's bits when read as data, so lane 27's data set bit 27 in every lane. Mark such a
VGPR (and VGPR copies of it) so data_reads reads it lane by lane, as main does (crosslane_fuzz seed 6,
cs_xl32_600042, which passed on main and failed with this PR).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its at the copy

With ItsNotRexed#2290 merged, a v_mov_b32 copy of a mask into a VGPR is an EXEC-gated
write, so lanes EXEC leaves off keep their old VGPR. Gathering the mask at a
later read (the store) then took those lanes' old words as set bits and
overwrote them: cs_mask_vgpr_exec failed on AMD and on the RTX 5070.

Hardware writes the wave's bits to the active lanes, so the copy now reads its
mask source as data (lane_masks.data_reads) and the VGPR holds data from there
on. cs_mask_vgpr_exec2 uses a mask that differs per lane: lanes 0-3 get 0x1f,
lanes 4-31 keep 0xdeadbeef; main gives 0xffffffff in lanes 0-3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHADER-188: CPU bisection and RTX 5070 (616.56) confirm original seed 1 programs 100007/100008 now match main f847748 after #2290. On main a 60-program run still has four ordinary mismatches: 100014/100023/100026/100034. In CPU replay, replacing a single v_mov mask source with its expected scalar word eliminated all 30/31/44/58 wrong words respectively. Exact #293 head 1c9faf7 and its base 6a6704d both have 6 native wave32 and 8 emulated wave64 ordinary mismatches across 60 programs; head changes some output words but not the failing IDs. Not a merged-main test. No rejected programs or harness errors. Main semantic suite: 7322 tests, one expected failure. AI-assisted synthetic validation.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHADER-21 integration handoff at 1c9faf7. Main f847748 plus current #2231 (8276a25) merges cleanly. Replaying the first #293-only commit 14cfce2 onto that tree conflicts in six files. Please preserve both per-instruction EITHER and reads tracking in analyse(), and cur_either plus mask_as_data() during emission, along with #2231's widened destination writes. An author rebase would unblock the RTX comparison. No integrated GPU result. AI-assisted.

@simonbronk
simonbronk force-pushed the translator/mask-as-data branch from 1c9faf7 to 004e31f Compare November 22, 2026 21:32
@simonbronk

Copy link
Copy Markdown
Contributor Author

Rebased on main 1628210 (004e31f), which now has #2290. @1TrickOmen, this touches your test, so here's what happened.

#2290 and this PR together broke cs_mask_vgpr_exec on the AMD iGPU and on the RTX 5070: every lane got 0xffffffff, where lanes 4-7 should keep 0xdeadbeef. After #2290, a v_mov_b32 copy of a mask into a VGPR is EXEC-gated, as on hardware. This PR gathered that VGPR's bits only later, at the store, so the old words of the lanes EXEC had left off counted as set bits, and the gathered word overwrote them.

Fix (004e31f): gather at the copy. Hardware writes the wave's bits to the active lanes, so v_mov_b32 vN, <mask SGPR / VCC / EXEC> now reads its source as data (lane_masks.data_reads), and the VGPR holds plain data from there on. A later v_readfirstlane of it, used as a mask, takes each lane's bit through main's path for an SGPR not known to hold a mask (#1792).

cs_mask_vgpr_exec can't tell these apart, because its mask is 0xffffffff either way. The new cs_mask_vgpr_exec2 uses vcc_lo = lanes 0-4 under EXEC = lanes 0-3:

translator lanes 0-3 lanes 4-7
main 1628210 0xffffffff 0xdeadbeef
this PR 0x1f 0xdeadbeef

That gives the same result on AMD (native) and on the RTX 5070 (LEONIDA_W64_EMULATE=1).

Rechecked on the rebased head:

  • run_gpu_tests.py: 181/196 passed, 15 skipped, on both GPUs;
  • semantic suite: 4145 OK;
  • corpus: 26,501/26,501 translate and pass spirv-val, the same as main.

@bvtterbroot @Dom-in, here is the fuzz rerun against the new main: crosslane_fuzz.py --wave both --w64-native on the AMD iGPU (driver 25.10.36). Non-hypothesis mismatches:

seed wave32 native wave64 emulate wave64 native
5 (--dpp, 50) 0 (main 2) 0 (1) 0 (1)
6 (--dpp, 50) 0 (1) 0 (0) 0 (0)
9001 (150) 0 (4) 0 (3) 0 (3)

The "other cause" I mentioned earlier was this interaction: gathering a VGPR whose lanes EXEC had left off. The gap that is left is listed in the body and in design.md: a mask computed in the vector unit (v_or_b32 vN, s20, s22, written in every lane) under a partial EXEC.

AI-assisted (Claude Code). Counts only, no game data.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated head 004e31f includes #2231 at 8276a25 and merges cleanly with f847748. Integrated tree 7dcb89ba2e39a7400c6d1b3f9db2b6d1dbdcd9b5 passed CPU interpreter replay for all four later SHADER-188 seeds (prior main mismatching words 30,31,44,58; integrated 0 each), plus original controls 100007/100008 and nine handwritten predicates. RTX comparison queued on this exact tree. AI-assisted, synthetic inputs.

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

GPU result for this PR on an RTX 4070 (NVIDIA 621.01), Windows 11, llvm-mc 23.1.6, main f847748, applied with git apply --3way (translator only, head 004e31fb). crosslane_fuzz.py --programs 60 --seed 1: on main 4 real mismatches (cs_xl32_100023, cs_xl64_100014, cs_xl64_100026, cs_xl64_100034; wave32 native 1, wave64 emulate 3); with this PR: 0 mismatches (wave32 21 match / 9 hyp_only, wave64 24 match / 6 hyp_only), exit 0. The 4 programs reduce to 3-5 instructions: a v_mov_b32 vD, <mask> (or v_readfirstlane_b32 of the VGPR it filled) under partial EXEC, or v_mov_b32 v, vcc_lo with a mixed mask (also under full EXEC), which on main gives the lane's own bit. This is the SHADER-188 case (v_cmp_*_e64 s[N:M] under partial EXEC). Not run: this PR's own tests, other GPUs, native wave64. AI-assisted.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integrated RTX result for SHADER-21/188 on tree 7dcb89ba2e39a7400c6d1b3f9db2b6d1dbdcd9b5 (includes #2231). On RTX 5070 driver 616.56 all six tracked seeds matched. Seed 1, 60 synthetic programs, 30 per mode (native wave32/emulated wave64): 45 exact, 15 hypothesis-flagged differences on the same seeds as main, zero unflagged differences versus four on main. Eight-program prefix: seven exact, one flagged. No rejects, skips or harness errors. A hypothesis flag does not identify the cause. AI-assisted.

@ErSlimShady99

Copy link
Copy Markdown

Tested 004e31f on RTX 4070 Ti SUPER (Ada), driver 621.14, Windows 11 Pro 26H2: pass.

Follow-up to my earlier replay on the old head, same method: crosslane_fuzz.py --seed 1 (100 programs, wave32 native + wave64 emulated), generator/harness/vk_compute_test from main, only the translator swapped via --translator.

                            wave32 native     wave64 emulate
main aa2988cc               3 mismatch        3 mismatch
main --no-maskdata          0                 0
PR #293 004e31fb            0                 0
PR #293 --no-maskdata       0                 0
(hypothesis-only programs identical between main and PR: 28 / 31 without maskdata)
  • The PR fixes all six maskdata mismatches left on main: cs_xl32_100023/75/77, cs_xl64_100014/26/34.
  • No new mismatches; the writelane_w32hi failures from my earlier run on f721e5f are gone after the rebase, as expected.
  • 0 rejected, 0 harness errors in all four runs.

No game data used. AI-assisted test execution and reporting.

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.