Skip to content

Tests: cs_imm_mask, constants as wave64 lane masks and as 64-bit data (s_ff0_i32_b64 of -1 included) - #1409

Open
intelshadow wants to merge 1 commit into
ItsNotRexed:mainfrom
intelshadow:fix/imm-lane-masks
Open

intelshadow wants to merge 1 commit into
ItsNotRexed:mainfrom
intelshadow:fix/imm-lane-masks

Conversation

@intelshadow

@intelshadow intelshadow commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Regression test for constant lane masks. Claimed in #374. AI-assisted (Claude Code). No game files.

This PR started as a translator fix. #1367 and later changes on main now fix all of it, including s_ff0/1_i32_b64 of a negative constant, which read only the low word until 2026-11-22 (s_ff0_i32_b64 of -1 gave 32). So it is now test-only: nothing on main tests s_ff0_i32_b64 of a negative constant, and this test pins it together with the 64-bit EXEC constants.

  • runtime/test/shaders/cs_imm_mask.asm: wave64, exact on any subgroup size, so it's in WAVE32_DUMPS and runs without --require-wave64. Expected 1 100 111 10 60 0 4294967295 64, derived in its header. Word 6 is s_ff0_i32_b64 of -1.
  • Registered in check.py and run_gpu_tests.py.
  • tests/semantic/test_imm_lane_masks.py runs it across every lane on one 64-wide and two 32-wide subgroups. It passes on main.

The same fixture passed on GPUs in the comments below: AMD Radeon AI PRO R9700, RX 6800, an RDNA2 iGPU, RTX 5070, RTX 5090, RTX 3060 Ti and RTX 5070 Ti. Several of those runs also showed it failing with the old translator.

🤖 Generated with Claude Code

@alvaro-marquez-cobos

Copy link
Copy Markdown
Contributor

Tested 0bea8a1 on Windows x64, AMD Radeon AI PRO R9700, Vulkan 26.11.2 (LLPC). The CPU regression passes for both subgroup sizes. The synthetic cs_imm_mask GPU check passes all eight expected words on the PR. With the same fixture and runner and only the translator restored to c2967a5, it fails; both translations pass spirv-val. AI-assisted.

@EchoTD

EchoTD commented Nov 22, 2026

Copy link
Copy Markdown

Tested 0bea8a1 on AMD Radeon RX 6800 (RDNA2, RADV NAVI21, Mesa 26.3.1, Vulkan 1.4.363), Arch Linux container on Linux 7.2.15: pass. Corpus count from my own copy of the game (1.0.2.1) below.

Overlap with #1367. #1367 (Vonsek, merged into main at 11:25 UTC; this PR was opened at 11:08 UTC) changes the same mask_src immediate path, and this PR now conflicts with main. I ran this PR's test files on current main bb2e184 with main's translator unchanged:

  • cs_imm_mask on the RX 6800, native and LEONIDA_W64_EMULATE=1: 1 100 111 10 60 0 32 64. Only word 7 differs from the expected 4294967295. Per the test's header that word is s_ff0_i32_b64 of -1.
  • test_imm_lane_masks.py on main gives [1, 100, 111, 10, 60, 0, 32, 64] for both subgroup sizes (64 and 32), failing on word 7 only.
  • Main's own cs_w32_mask_imm and cs_w64_mask_imm pass in both modes.

So of this PR's checks, only the s_ff0_i32_b64 immediate one still fails on main. I didn't test whether the rest of this PR's translator change does anything beyond what #1367 already does.

This PR's head (0bea8a1)

  • run_gpu_tests.py: 136/136 passed native, 136/136 with LEONIDA_W64_EMULATE=1. cs_imm_mask: 1 100 111 10 60 0 4294967295 64 in both.
  • build.py: 133 shaders built and pass spirv-val, including cs_imm_mask (llvm-mc 23.1.5 assembles s_and_b64 exec, exec, 6, s_bcnt0_i32_b64 and s_ff0_i32_b64). check.py: 124 of 127 pass, 3 skipped, cs_imm_mask ok.
  • Control (this PR's tree with only its tools/rdna2spirv.py hunk reversed, which is c2967a5's translator, same blob): cs_imm_mask gives 1 1 1 1 0 32 32 32, as the PR body says.
  • unittest discover -s tests/semantic: 1195 OK.

Corpus count (26,503 shaders, disassembled with main c603b8f's tools; counts only):

  • 64-bit SALU with exec as the destination operand and an immediate source: every immediate is 0 or -1 (s_mov_b64 exec, -1 ×9,282; s_cselect_b64 exec with -1 ×195; s_bfm_b64 exec with a 0 offset ×195).
  • s_*_saveexec_b64 with an immediate source: 2,247 are s_or_saveexec_b64 with -1, and 12 in 11 shaders have other values (s_and/s_andn1/s_nand/s_nor). I didn't check whether those 12 sit in reachable code.
  • v_cndmask_b32_e64 with an immediate mask operand: 0.
  • s_bcnt0/1_i32_b64, s_ff0/1_i32_b64: 2,017, none with an immediate source.
  • Immediates other than 0 / -1 anywhere mask_src might read one (any s_*_b64 operand, an s_*_b32 that names exec/vcc, the v_cndmask mask or the carry-in): 357 shaders, which include the 11 above. Most of these immediates are data operands (s_lshl_b64 2,392, s_lshr_b64 332, s_mov_b32 708).
  • Those 357 translated with this PR and with the control (--no-asm, as make_game.py runs it): 357 / 357 translated and pass spirv-val on both sides, all 357 .spv byte-identical, identical index metadata.

My selection is a text match on operand positions, not the translator's own classification. I didn't translate the other 26,146 shaders.

AI-assisted (Claude Code). The game files were mounted read-only into a podman container with no network. The disassembly and the translations stayed on my machine. Nothing from them is quoted here.

@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 0bea8a1 (118 behind main) on two GPUs: Windows 11 Home 10.0.26300, Python 3.14.7, llvm-mc 21.1.8, Vulkan SDK 1.4.363.0, main's harness build (bb2e184, MSVC 14.44), LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~.

scripts/run_gpu_tests.py result cs_imm_mask
AMD Radeon RDNA2 iGPU (Ryzen 7 9800X3D, 32.0.21042.62), native wave64 136/136 PASS 1 100 111 10 60 0 4294967295 64
RTX 5070 (617.42), LEONIDA_W64_EMULATE=1 136/136 PASS, same words

pytest tests/semantic/test_imm_lane_masks.py: 1 passed, 2 subtests. No validation messages.

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

@intelshadow

Copy link
Copy Markdown
Contributor Author

Thanks @alvaro-marquez-cobos and @EchoTD for the GPU runs, and EchoTD for the corpus count.

You're right that #1367 covers most of this PR, and main has since fixed the wave32 32-bit mask case I had added too. I've rebased onto main and reduced the PR to the one case that still fails there: s_ff0/1_i32_b64 of a constant reads only the low word, which is word 6 of cs_imm_mask, as you measured. The description is updated. As your count shows, the game never uses that form, so this is correctness only; feel free to close it if you'd rather not carry it.

@intelshadow intelshadow changed the title Translator: an immediate read as a lane mask gives each lane its own bit; 64-bit immediates keep their high word Translator: s_ff0/1_i32_b64 of a constant reads its 64 bits (follow-up to #1367) Nov 22, 2026
intelshadow added a commit to intelshadow/Leonida that referenced this pull request Nov 22, 2026
…ane ops (wave32 and wave64)

The family crosslane_fuzz.py checks on a GPU, checked on the CPU so it can
run where the translator tests run. The reference is cf_ref.WaveMachine
(FUZZ-8) extended with what it leaves out: v_readlane, v_readfirstlane,
v_writelane, ds_bpermute_b32, v_permlane16/x16 (FI = 0 as measured in ItsNotRexed#374),
s_bcnt0/1 and s_ff0/1 (b32/b64) and s_not. The translated SPIR-V runs on
spirv_mini_interp.run_workgroup, the whole wave in one subgroup, and every
dword every lane stores is compared.

Known gaps on main are opt-in: --masks-as-data (ItsNotRexed#210) and
--permlane-partial (SHADER-74, ItsNotRexed#580). tests/test_wave_diff.py: hand-derived
reference cases, canaries and a short seeded run on both wave sizes.

Depends on ItsNotRexed#1409 (the default run finds its case on main).

AI-assisted.

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

Copy link
Copy Markdown
Contributor

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

Confirmed the 64-bit immediate fix on Linux RTX 5090 (595.99.02) at 5af118b290986be5db99ade16cf77e32960c96f8. I used the same submitted cs_imm_mask fixture and Vulkan harness for both runs, with wave64 emulation disabled. The control used the translator from parent 4c52ce27, verified by its Git blob hash. Both modules passed spirv-val; direct dispatch confirmed a 32-wide compute subgroup.

Translator Eight GPU readback words
Parent 1 100 111 10 60 0 32 64
PR head 1 100 111 10 60 0 4294967295 64

Only word 6 changed. For s_ff0_i32_b64 with inline -1, all 64 bits are set, so the expected result is 0xffffffff. The stock runner failed the parent and passed the PR head.

AI-assisted verification.

@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 5af118b2 (the rebased head) on NVIDIA GeForce RTX 3060 Ti (subgroup 32..32), driver 580.173.02, Linux (kernel 6.18), Python 3.14: pass.

  • scripts/run_gpu_tests.py: 165/211 passed, 46 skipped, 0 failed. cs_imm_mask prints 1 100 111 10 60 0 4294967295 64, the expected words (word 6 = -1).
  • ctest: 47/47 passed.
  • pytest tests/semantic/test_imm_lane_masks.py: 1 passed, 2 subtests passed. With tools/ from the merge base (4c52ce2): 2 failed.

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

@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 5af118b2 (merge base 4c52ce27) on an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56, Windows 11 10.0.26300. Translator and fixtures from this head; runtime test programs built from main aa2988cc (MSVC 19.44, Vulkan-Headers fetched by CMake, loader from the NVIDIA driver); spirv-as/spirv-val and llvm-mc 21 from WSL Ubuntu: pass.

  • scripts/run_gpu_tests.py: 165/211 passed, 46 skipped (wave64 programs on a 32-wide GPU), 0 failed.
  • Diffed test by test against main aa2988cc (164/210, 46 skipped): every main result is the same here.
  • New: cs_imm_mask PASS (1 100 111 10 60 0 4294967295 64).

Not run: LEONIDA_W64_EMULATE=1, other vendors, Linux. No game files.

AI-assisted (Claude Code).

… (s_ff0_i32_b64 of -1 included)

A regression test for ItsNotRexed#1367's constant lane masks and for s_ff0/1_i32_b64
of a negative constant, which read only the low word until 2026-11-22
(s_ff0_i32_b64 of -1 gave 32). Both are fixed on main; nothing else tests
s_ff0 of a negative constant.

runtime/test/shaders/cs_imm_mask.asm: wave64, exact on any subgroup size,
expected 1 100 111 10 60 0 4294967295 64. Registered in check.py and
run_gpu_tests.py; tests/semantic/test_imm_lane_masks.py runs it on one
64-wide and two 32-wide subgroups.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@intelshadow intelshadow changed the title Translator: s_ff0/1_i32_b64 of a constant reads its 64 bits (follow-up to #1367) Tests: cs_imm_mask, constants as wave64 lane masks and as 64-bit data (s_ff0_i32_b64 of -1 included) Nov 23, 2026
@intelshadow

Copy link
Copy Markdown
Contributor Author

Update: main now fixes s_ff0_i32_b64 of -1 by itself, so this PR no longer changes the translator. I've reduced it to the regression test (cs_imm_mask and its semantic test), since nothing on main tests that case yet. Thanks again to everyone who ran it on hardware: @alvaro-marquez-cobos, @EchoTD, @UlteriorMotive00, @tylerstraub, @TreXito and @tunczzz.

intelshadow added a commit to intelshadow/Leonida that referenced this pull request Nov 23, 2026
…ane ops (wave32 and wave64)

The family crosslane_fuzz.py checks on a GPU, checked on the CPU so it can
run where the translator tests run. The reference is cf_ref.WaveMachine
(FUZZ-8) extended with what it leaves out: v_readlane, v_readfirstlane,
v_writelane, ds_bpermute_b32, v_permlane16/x16 (FI = 0 as measured in ItsNotRexed#374),
s_bcnt0/1 and s_ff0/1 (b32/b64) and s_not. The translated SPIR-V runs on
spirv_mini_interp.run_workgroup, the whole wave in one subgroup, and every
dword every lane stores is compared.

Known gaps on main are opt-in: --masks-as-data (ItsNotRexed#210) and
--permlane-partial (SHADER-74, ItsNotRexed#580). tests/test_wave_diff.py: hand-derived
reference cases, canaries and a short seeded run on both wave sizes.

Depends on ItsNotRexed#1409 (the default run finds its case on main).

AI-assisted.

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

ricardotanaka commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested the test-only head 54660243 (03:50 UTC) merged onto current main 3eb4410b (clean) on AMD Radeon RX 7600 (RDNA 3, subgroup 32..64, AMD 26.11.2 LLPC), Windows 11 Pro 26200: pass. Both modes, as in the earlier runs on 0bea8a1.

  • scripts/run_gpu_tests.py --filter cs_imm_mask with LEONIDA_VK_VALIDATION=1: natively and with LEONIDA_W64_EMULATE=1, both PASS cs_imm_mask 1 100 111 10 60 0 4294967295 64 (word 6 = -1).
  • python -I -m unittest discover -s tests/semantic -p test_imm_lane_masks.py: OK.

AI-assisted (Claude Code).

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested 5466024344c48dc04d90fac8a95b355281a79b11 on AMD Radeon Pro V540 (RDNA1, Navi 12; RADV/Mesa 25.2.8-0ubuntu0.24.04.4, Ubuntu 24.04.4, Linux 7.0.0-31-generic, Vulkan 1.4.318). This box is described as gfx1012; tools/hw_oracle reports gfx1011 for this Navi 12 part. Cards pinned with DRI_PRIME=pci-0000_1c_00_0! and pci-0000_1f_00_0! (one process each).

  • Command: python3 -I scripts/run_gpu_tests.py --filter cs_imm_mask --build runtime/build/linux: 1/1 passed (1 100 111 10 60 0 4294967295 64) on both cards, and also with LEONIDA_W64_EMULATE=1.
  • Command: python3 -I scripts/run_gpu_tests.py --build runtime/build/linux: 189/218 passed, 27 skipped, 2 failed on both cards (222 shaders translated, 222 pass spirv-val); with emulation also 189/218. Current upstream/main 7b7d73f8 in a separate worktree with the same toolchain: 188/217 passed, 27 skipped, 2 failed — one extra passing test, no regression.
  • The two failures (cs_signed_zero_nan, cs_w32_salu64) are pre-existing with identical words on main.
  • Toolchain note: built with Khronos Vulkan-Headers 1.4.335 locally (-DVulkan_INCLUDE_DIR=...) because this head's vk_harness uses VK_KHR_pipeline_binary; Ubuntu 24.04's 1.3.275 headers cannot compile it. GCC 13.3.0, llvm-mc 21.1.8, SPIRV-Tools 2026.1.

Counts and pass/fail only; no game data. No code changes.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 5466024 merged with main 2d3369a on Linux (Python 3.12.16) and Windows 11 (Python 3.13.1): pass.

  • -I -m unittest discover -s tests/semantic -p test_imm_lane_masks.py: 1 test OK on both. pytest tests/test_shader_checks.py tests/test_run_gpu_tests.py: 83 + 41 passed (Linux); tests/test_docs_*.py all pass (Linux 30 tests via pytest, Windows 30 via unittest); Windows shader_checks 83 and run_gpu_tests 41 OK.
  • Negative control (test-only PR, so a mutation): in tools/rdna2spirv.py the s_ff0/s_ff1_i32_b64 constant branch changed back to lo, hi = self.mask_src(a[1]), self.cu(0) (low word only): the test fails for both subgroup sizes (word 6 is 32 instead of 4294967295). Reverted afterwards.
  • The GPU side (cs_imm_mask on a device) was not run.

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