Skip to content

Translator: an SGPR holding data read as a lane mask gives each lane its bit (SHADER-200) - #1875

Closed
Pipodi wants to merge 4 commits into
ItsNotRexed:mainfrom
Pipodi:shader200-mask-src
Closed

Pipodi wants to merge 4 commits into
ItsNotRexed:mainfrom
Pipodi:shader200-mask-src

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-200

Depends on: none (builds on #1367, merged; see the note on #293 below)

What and why

Gen.mask_src read an SGPR that lane_masks.py doesn't certify as a lane mask as "all lanes on" whenever the value was nonzero. The hardware reads bit L of the mask for lane L. An SGPR holding plain data (an SMEM-loaded bitmask combined with EXEC/VCC, or a register that is data on some paths) therefore turned on every lane where it should have turned on only the lanes whose bits are set.

The new row is in the docs/design.md contract table.

Tested

  • GPU, RTX 4090, driver 617.42, Windows 11:
    • New tests cs_w32_mask_sgpr and cs_w64_mask_sgpr (wave64 with LEONIDA_W64_EMULATE=1) fail on main and pass with this change.
    • They cover lanes 0-31 and 32-63, a v_cndmask mask pair whose lanes 40-47 come from s5, and a mask ANDed with data.
    • All 11 --filter mask tests pass with emulation, including Translator: a constant lane mask gives lane L its bit L (mask_src immediates) #1367's cs_w32/w64_mask_imm. Without emulation the wave64 tests skip: this device has no 64-wide compute subgroups.
    • The GPU tests use an explicit s[4:5]. The sN listing-syntax widening is covered by a CPU test and the llvm-mc encoding check above.
  • CPU:
    • tests/semantic/test_mask_src_data_sgpr.py: wave32, wave64 pairs, a b32 read in wave64, a mask ANDed with data, certified masks unchanged, and v_cndmask listing syntax.
    • test_wave64_halves.py: test_c_data_sgpr_as_lane_mask.
    • Fixtures generated with regen_fixtures.py, and --check passes.
    • unittest discover -s tests/semantic: 1,581 OK. pytest tests: 5,903 passed, 91 skipped; 7 failures (test_cf_ref exec_hi, test_make_game_assets_pools, test_world_names) fail on main 003e781 the same way.
  • Corpus: 26,503 shaders, base main 003e781, LLVM 23.1.5:
    • Base: RESULT OK: 26503 shaders: 26487 translated, 26487 pass spirv-val.
    • Change: RESULT OK: 26503 shaders: 26487 translated, 26487 pass spirv-val. The 16 untranslated shaders are the same on both sides (main's).
    • 0 lost, 0 new.
    • Wave64 count 21,538 in both runs, no flips.
    • 13,502 .spv change, the shaders that read an uncertified SGPR as a mask (13,518 on the earlier base, where all 26,503 translated); 12,985 are byte-identical.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The new fixtures are generated from our hand-written GPU test .asm; only counts are given.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed (GPU test, llvm-mc encoding, corpus count).

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

Pipodi and others added 4 commits November 22, 2026 15:15
mask_src returned an SGPR's raw value as this lane's mask, so plain
wave-uniform data read as all lanes on whenever non-zero. Take bit
'lane' of it (r+1 for lanes 32-63 of a wave64 pair) unless
lane_masks.py certified the register. Adds a design.md row and CPU
tests for wave32 and wave64.

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

Add cs_w32_mask_sgpr and cs_w64_mask_sgpr GPU tests (check.py, run_gpu_tests.py),
move the CPU tests onto generated fixtures, add a mask-and-data pair test, and
test that --wave64-emulate translates the same bit test (the interpreter cannot
run the emulated form). Comment the single-SGPR wave64 case. Rewrite the
design.md row: ISA semantics, CPU and GPU tests, corpus counts, ItsNotRexed#293 note and
the subgroup-size contract for graphics stages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…:N+1]

The corpus listing prints the VOP3 mask operand of v_cndmask in wave32 syntax
(sN, like vcc_lo) in wave64 shaders too, where the hardware reads the 64-bit
pair. Every single-SGPR site that reached the data-SGPR bit test in wave64
was this operand; lanes 32-63 now take their bit from r+1 instead of r.
Certified masks are read as before. CPU tests for listing syntax and for a
certified single register; design.md row updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-10 tier C; test and doc fixes

A b32 (wide=False) read in wave64 takes bit lane mod 32 of r. A 32-lane half cannot read r+1 for the
high half, so wave64_halves.py reports mask-data for a data SGPR as the mask of v_cndmask / v_addc_co.
design.md row lists the listing-syntax test and no longer calls the sN widening GPU-tested; asm
comments name lanes 4-11, 20-23 and 28-31; dead emulate scaffolding removed from the test.

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

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested c5bea9e (base 003e781) on AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, driver 26.10.1, subgroups 32..64, wave64 native) and NVIDIA RTX 5080 (616.92, subgroups 32), Windows 11: pass.

Commands (runtime built from main 003e781, translator from this head): python -I scripts/run_gpu_tests.py --build <build> --work <dir> --filter mask, with LEONIDA_VK_DEVICE=radeon / =5080, with and without LEONIDA_W64_EMULATE=1.

  • radeon, native wave64: 11/11 passed (incl. cs_w32_mask_sgpr, cs_w64_mask_sgpr, cs_w64_mask_imm, cs_w64x_mask_reuse*, ps_bitmask_perm, ps_scc_mask32).
  • radeon, LEONIDA_W64_EMULATE=1: 11/11 passed.
  • 5080, native: 5/11 passed, 6 skipped (no 64-wide compute subgroup).
  • 5080, LEONIDA_W64_EMULATE=1: 11/11 passed.
  • Red on main: with tools/rdna2spirv.py and tools/wave64_halves.py taken from 003e781 and the PR's tests kept, --filter mask_sgpr with emulation fails 0/2 on both GPUs (cs_w32_mask_sgpr 32 32 32 ... , cs_w64_mask_sgpr 64 4294967040 ...), and passes 2/2 with the PR's translator.
  • python -I -m unittest discover -s tests/semantic: 1581 tests OK.

Remarks: the native wave64 pass on the Radeon is the useful addition to the RTX 4090 result in the description, since there the wave64 tests skip without emulation. Diff of mask_src and the v_cndmask pair widening read; no concerns.

AI-assisted.

@Pipodi

Pipodi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Vonsek, that's the missing half: on the RTX 4090 the wave64 tests only ran under emulation, so your native wave64 11/11 on RDNA2 (and red on main for both mask_sgpr tests) is the hardware check for the r+1 upper half.

AI-assisted (Claude Code).

@Rainmaker33

Copy link
Copy Markdown

Tested c5bea9e 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 6a6704d. VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; overlay layers off. Harness programs from a CMake build of that main.

  • scripts/run_gpu_tests.py: 134/175 pass, 41 skipped (wave64), no failures. main gives 133/173.
    • cs_w32_mask_sgpr: 16 1028 24 4294967040 32 1040 8 4104.
    • cs_w64_mask_sgpr skips natively.
  • With LEONIDA_W64_EMULATE=1 --filter mask_sgpr: 2/2 pass. cs_w64_mask_sgpr: 32 8193 4294967040 64 1048 4120 24 25.

@whoalin1

Copy link
Copy Markdown
Contributor

Tested c5bea9e (base 003e781) on Windows 11 (build 26200): pass.

  • NVIDIA GeForce RTX 4070 SUPER (Ada), driver 610.88, subgroup 32..32
    • native: 131/172 passed, 41 skipped, 0 failed. cs_w32_mask_sgpr PASS; cs_w64_mask_sgpr SKIP (no 64-wide subgroup)
    • LEONIDA_W64_EMULATE=1: 163/172 passed, 9 skipped, 0 failed. Both mask_sgpr tests PASS
  • AMD Radeon Graphics (Ryzen 5 7600 iGPU, RDNA2), AMD driver 24.10.24, subgroup 32..64, wave64 native: 144/172 passed, 27 skipped, 1 failed. Both mask_sgpr tests PASS. The one failure is ms_clip, and it fails the same way with tools/rdna2spirv.py reverted to 003e781, so it isn't from this PR (I'll look at it separately).
  • Red without the change: this head with only tools/rdna2spirv.py reverted to 003e781, RTX 4070 SUPER, LEONIDA_W64_EMULATE=1, --filter mask: cs_w32_mask_sgpr FAIL (32 32 32 4294967040 32 32 16 2072) and cs_w64_mask_sgpr FAIL (64 4294967040 4294967040 64 64 2104 40 64); the other 9 pass.
  • CPU: python -m unittest discover -s tests/semantic 1581 OK; tests/semantic/test_mask_src_data_sgpr.py 13 OK; tests/semantic/test_wave64_halves.py 58 OK.

Runtime and test programs built from this head (scripts\build_runtime.ps1, MSVC 14.44, Windows SDK 10.0.26100); llvm-mc 21.1.8 (WSL Ubuntu 26.04); SPIRV-Tools v2026.4; Python 3.14.4. python -I scripts/run_gpu_tests.py per GPU with VK_LOADER_DRIVERS_SELECT and LEONIDA_VK_DEVICE, VK_LOADER_LAYERS_DISABLE=~implicit~.

AI-assisted (Claude Code).

@Yourrespawn

Copy link
Copy Markdown
Contributor

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

  • Semantic suite: 1581 OK (Python 3.12.10), including the new SHADER-200 tests
  • run_gpu_tests.py native: 131/172 passed, 41 skipped (native wave64, expected on this 32-lane GPU)
  • run_gpu_tests.py LEONIDA_W64_EMULATE=1: 163/172 passed, 9 skipped — the lane-mask paths run emulated here and stay clean
  • valu_fuzz --family mem --programs 150 --seed 12 --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.

@ItsNotRexed

Copy link
Copy Markdown
Owner

Thanks. #1792 is merged and gives each lane its own bit when a constant in an SGPR is read as a lane mask, so I'm closing this as a duplicate.

@Pipodi

Pipodi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, agreed: #1792 has the mask_src core. Checked against main 4eb6155: three parts of this PR are still missing there, so I'll open them as a small follow-up from main (SHADER-200) instead of reopening this one:

  • The wave64 VOP3 v_cndmask_b32 mask printed as sN. The listing prints that operand in wave32 syntax (as it prints vcc_lo), but in wave64 the hardware reads the pair s[N:N+1], so lanes 32-63 should take their bit from sN+1. On main they still read bit lane-32 of sN. That is 24,138 sites in 5,365 wave64 shaders of the corpus. This PR's test_wave64_cndmask_listing_syntax fails on main (12 of the 13 tests in test_mask_src_data_sgpr.py pass there).
  • SHADER-10: wave64_halves.py reports a data SGPR used as a lane mask as mask-data (tier C).
  • The GPU tests cs_w32_mask_sgpr / cs_w64_mask_sgpr, which @Vonsek, @Rainmaker33, @whoalin1 and @Yourrespawn ran above.

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