[PR #1397] rdna2spirv: a VALU data read of a lane-mask operand yields the wave's mask word #1427

Open
opened 2026-11-26 20:21:13 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1397
Author: @whoalin1
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: mask-regs-data-read


📝 Commits (5)

  • 63f6683 translator: a VALU data read of a lane-mask operand yields the wave's mask word
  • 77f23d0 translator: gate mask-word gathers on EXEC coverage; scalar mask number reads
  • b83f9d2 translator: s_mov copies of EXEC keep the narrowing's tag through SGPR round-trips
  • ec8b961 rdna2spirv: the wave mask gather is stored before it is read, so every lane runs it (SHADER-WAVEMASK-EAGER)
  • e3e119a translator: lane-mask data reads gather the wave word under narrowed EXEC

📊 Changes

14 files changed (+670 additions, -41 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 runtime/test/shaders/check.py (+7 -3)
➕ runtime/test/shaders/cs_exec_copy.asm (+40 -0)
📝 scripts/run_gpu_tests.py (+7 -3)
📝 tests/semantic/README.md (+3 -0)
➕ tests/semantic/fixtures/disasm/cs_exec_copy.s (+26 -0)
📝 tests/semantic/test_lane_masks_vector_bitwise.py (+280 -13)
📝 tests/semantic/test_salu64_bitwise_data.py (+4 -2)
📝 tests/semantic/test_salu_movrels_lane_mask.py (+3 -1)
📝 tests/semantic/test_scselect_b64_data.py (+3 -1)
📝 tests/semantic/test_slot67_operand_forms.py (+1 -3)
➕ tests/semantic/test_wave_mask_eager.py (+140 -0)
📝 tools/rdna2spirv.py (+148 -13)
📝 tools/wave64_emulate_opt.py (+7 -1)

📄 Description

Claimed in the coordination issue: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7147335368

Depends on: #953

What

A lane mask (EXEC/VCC or a mask-tracked SGPR) that an instruction reads as a 32-bit value — for example v_mov_b32 of it into a plain VGPR, or a scalar number reader such as s_add_u32 s20, s10, K — must produce the wave's mask word. Hardware SGPRs hold that wave-wide word; the translator previously produced each lane's own 0/~0 bit in the VALU path.

This pull request now:

  • materializes the wave mask word for lane-mask data reads (src_u / lane_mask_word), while mask consumers keep extracting the lane bit through mask_src;
  • keeps word-materializing readers out of lane-local if (active) runs, since the gather is a cross-lane operation;
  • handles scalar mask number readers and mask-holding VGPR copies/reads;
  • gathers the word even when EXEC is narrowed. EXEC narrowing is data in the translator's model, not SPIR-V control flow. The earlier EXEC-coverage gate could not prove independent-SGPR restore idioms and still produced the wrong per-lane bit for the narrowed-EXEC fuzz family, so the gate and its CFG provenance analysis are removed;
  • includes the eager wave-mask store from #953 (authorship preserved) because it is the mechanism that keeps lowering from moving the subgroup gather into an EXEC-selected arm on MoltenVK/SPIRV-Cross.

docs/design.md records the contract. Semantic coverage includes narrowed SGPR/VCC reads, independent all-ones SGPR EXEC restore, EXEC round trips, scalar readers, vector-bitwise mask composition, native/emulated wave64 structure, and the eager-gather shape.

Tested

  • python -I scripts/run_semantic_tests.py tests/semantic — 488 files, 6298 tests, 0 files failed; compileall clean; tests/test_lane_masks.py passed.
  • GPU, NVIDIA RTX 4070 SUPER, Windows 11 (VK_LOADER_DRIVERS_SELECT=*nv-vk*): tools/crosslane_fuzz.py --programs 200 --seed 7 --wave 32 --modes native — 199 match / 1 mismatch / 0 hypothesis-only versus 186 / 9 / 5 at ba315fbf1. The remaining cs_xl32_700032 minimizes to an inactive-EXEC write-predication case (v_cmpx + maskdata v_mov + v_xor), distinct from the narrowed-EXEC mask-word family and already present before this change.
  • NVIDIA seed 102 (--programs 106) � 105 match / 1 mismatch / 0 hypothesis-only versus 100 / 3 / 3 at ba315fbf1. The remaining cs_xl32_10200411 is an EXEC-zero/readfirstlane control-flow case. AMD evidence is reported in the pull-request comments; no game files were used.

AI-assisted (SWE-2.1 Max).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1397 **Author:** [@whoalin1](https://github.com/whoalin1) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `mask-regs-data-read` --- ### 📝 Commits (5) - [`63f6683`](https://github.com/ubiquitarianism/leonida/commit/63f668391bbc5ee0c1cc78915d1d72fa6f4991c5) translator: a VALU data read of a lane-mask operand yields the wave's mask word - [`77f23d0`](https://github.com/ubiquitarianism/leonida/commit/77f23d0588d0ac6bd729325c027900dbe658279d) translator: gate mask-word gathers on EXEC coverage; scalar mask number reads - [`b83f9d2`](https://github.com/ubiquitarianism/leonida/commit/b83f9d29cac22070abcdd9c0e84dd0fffbe60a3b) translator: s_mov copies of EXEC keep the narrowing's tag through SGPR round-trips - [`ec8b961`](https://github.com/ubiquitarianism/leonida/commit/ec8b9619078867af5c8647c4e8937228a0d048c4) rdna2spirv: the wave mask gather is stored before it is read, so every lane runs it (SHADER-WAVEMASK-EAGER) - [`e3e119a`](https://github.com/ubiquitarianism/leonida/commit/e3e119a46fd791bb41e80ef3837893baa2ef35d8) translator: lane-mask data reads gather the wave word under narrowed EXEC ### 📊 Changes **14 files changed** (+670 additions, -41 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `runtime/test/shaders/check.py` (+7 -3) ➕ `runtime/test/shaders/cs_exec_copy.asm` (+40 -0) 📝 `scripts/run_gpu_tests.py` (+7 -3) 📝 `tests/semantic/README.md` (+3 -0) ➕ `tests/semantic/fixtures/disasm/cs_exec_copy.s` (+26 -0) 📝 `tests/semantic/test_lane_masks_vector_bitwise.py` (+280 -13) 📝 `tests/semantic/test_salu64_bitwise_data.py` (+4 -2) 📝 `tests/semantic/test_salu_movrels_lane_mask.py` (+3 -1) 📝 `tests/semantic/test_scselect_b64_data.py` (+3 -1) 📝 `tests/semantic/test_slot67_operand_forms.py` (+1 -3) ➕ `tests/semantic/test_wave_mask_eager.py` (+140 -0) 📝 `tools/rdna2spirv.py` (+148 -13) 📝 `tools/wave64_emulate_opt.py` (+7 -1) </details> ### 📄 Description Claimed in the coordination issue: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7147335368 Depends on: #953 ## What A lane mask (EXEC/VCC or a mask-tracked SGPR) that an instruction reads **as a 32-bit value** — for example `v_mov_b32` of it into a plain VGPR, or a scalar number reader such as `s_add_u32 s20, s10, K` — must produce the wave's mask word. Hardware SGPRs hold that wave-wide word; the translator previously produced each lane's own `0`/`~0` bit in the VALU path. This pull request now: - materializes the wave mask word for lane-mask data reads (`src_u` / `lane_mask_word`), while mask consumers keep extracting the lane bit through `mask_src`; - keeps word-materializing readers out of lane-local `if (active)` runs, since the gather is a cross-lane operation; - handles scalar mask number readers and mask-holding VGPR copies/reads; - gathers the word even when EXEC is narrowed. EXEC narrowing is data in the translator's model, not SPIR-V control flow. The earlier EXEC-coverage gate could not prove independent-SGPR restore idioms and still produced the wrong per-lane bit for the narrowed-EXEC fuzz family, so the gate and its CFG provenance analysis are removed; - includes the eager wave-mask store from #953 (authorship preserved) because it is the mechanism that keeps lowering from moving the subgroup gather into an EXEC-selected arm on MoltenVK/SPIRV-Cross. `docs/design.md` records the contract. Semantic coverage includes narrowed SGPR/VCC reads, independent all-ones SGPR EXEC restore, EXEC round trips, scalar readers, vector-bitwise mask composition, native/emulated wave64 structure, and the eager-gather shape. ## Tested - `python -I scripts/run_semantic_tests.py tests/semantic` — **488 files, 6298 tests, 0 files failed**; `compileall` clean; `tests/test_lane_masks.py` passed. - GPU, NVIDIA RTX 4070 SUPER, Windows 11 (`VK_LOADER_DRIVERS_SELECT=*nv-vk*`): `tools/crosslane_fuzz.py --programs 200 --seed 7 --wave 32 --modes native` — **199 match / 1 mismatch / 0 hypothesis-only** versus 186 / 9 / 5 at `ba315fbf1`. The remaining `cs_xl32_700032` minimizes to an inactive-EXEC write-predication case (`v_cmpx` + maskdata `v_mov` + `v_xor`), distinct from the narrowed-EXEC mask-word family and already present before this change. - NVIDIA seed 102 (`--programs 106`) � **105 match / 1 mismatch / 0 hypothesis-only** versus 100 / 3 / 3 at `ba315fbf1`. The remaining `cs_xl32_10200411` is an EXEC-zero/readfirstlane control-flow case. AMD evidence is reported in the pull-request comments; no game files were used. AI-assisted (SWE-2.1 Max). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1427
No description provided.