[PR #1043] rdna2spirv: a lane mask read as a number is the wave's mask word (SHADER-MASK-AS-DATA) #1081

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1043
Author: @thesubtleties
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: mask-as-data


📝 Commits (3)

  • 02d6293 rdna2spirv: a lane mask read as a number is the wave's mask word (SHADER-MASK-AS-DATA)
  • 68b964e lane_masks: follow a copied mask through VGPR copies before deciding how it is read (SHADER-MASK-AS-DATA)
  • 4d58a05 Merge main into mask-as-data (SHADER-MASK-AS-DATA)

📊 Changes

10 files changed (+307 additions, -18 deletions)

View changed files

📝 docs/design.md (+1 -0)
➕ tests/semantic/test_mask_as_data.py (+182 -0)
📝 tests/semantic/test_salu64_bitwise_data.py (+2 -2)
📝 tests/semantic/test_salu_movrels_lane_mask.py (+1 -1)
📝 tests/semantic/test_scselect_b64_data.py (+1 -1)
📝 tests/semantic/test_slot67_operand_forms.py (+1 -5)
📝 tools/lane_masks.py (+89 -5)
📝 tools/rdna2spirv.py (+21 -3)
📝 tools/wave32_pixel_scan.py (+3 -0)
📝 tools/wave64_emulate_opt.py (+6 -1)

📄 Description

Claimed in the coordination issue as: SHADER-MASK-AS-DATA

What and why

A lane mask is one word for the wave on hardware; the translator keeps each lane's own 0 / ~0. An op that read the mask as a number therefore got a different wrong value per lane, with no error: with mask 0x3ff, s_add_u32 d, mask, 1 was 0 or 1 and v_mov_b32 v, mask was 0 or ~0 (crosslane_fuzz.py "maskdata", the old #293). s_bcnt / s_ff / s_flbit already rebuild the word. This does the same for:

  • 32-bit integer SALU and VALU ops (lane_masks.NUMBER_READERS);
  • v_mov_b32 of a mask, when no v_readfirstlane_b32 or vector bitwise op reads that value as a mask. Each copy is followed forward, through VGPR-to-VGPR copies (second commit).

The emulation planner counts such an op as an exchange, it never joins an active run, and wave32_pixel_scan.py counts it as mask_word.

Partial on purpose. Not covered: the values excluded above (the v_mov / v_or3 / v_readfirstlane idiom needs each lane's own bit), compares, SDWA and DPP, and 16-bit, float and 64-bit ops.

Three existing tests changed: test_salu_movrels_lane_mask, test_scselect_b64_data and test_salu64_bitwise_data read a mask back with v_mov_b32 and expected the lane's own 0 / ~0; they now expect the mask word.

Tested

Measured on base 82a2aabc, then rebased; the semantic suite and the touched tests were rerun after the rebase.

  • New tests/semantic/test_mask_as_data.py (wave32, native wave64, partial EXEC, the through-a-VGPR idiom, emulated translation): fails on main, passes here.
  • run_semantic_tests.py: 0 files failed.
  • crosslane_fuzz.py, hard mismatches, main -> this PR; no program fails here that passed on main:
Run main first commit now
wave32 native, seed 880505 (300), 3080 and gfx1036 20 10 0
wave32 native, seed 991201 (250), 3080 13 7 4
wave32 native, seed 991202 (250), 3080 and gfx1036 21 16 4
wave64 emulated --ext, seed 880606 (300), 3080 and gfx1036 6 6 1
wave64 native --ext, seed 880707 (300), gfx1036 7 6 3

The 880xxx main rows were run on 98a977b4. With --no-maskdata there are no hard mismatches there on main. Correction: the first version of this text said the remaining mismatches were v_readfirstlane reads. Minimizing them showed most came from a plain VGPR-to-VGPR copy that the first commit counted as a mask read; the second commit fixes that. What is left on wave32 seeds 991201, 991202 and 993301 (11 mismatches, plus 4 programs with a hypothesis op) is now minimized on the 3080: every reduction contains a v_mov_b32 of a mask into a VGPR that a v_readfirstlane_b32 or a vector bitwise op then reads, the idiom this PR leaves alone. The shortest is v_cmp_ne_u32_e32 vcc_lo, 9, v6 / v_mov_b32_e32 v2, vcc_lo / v_readfirstlane_b32 s8, v2. The wave64 leftovers (seed 880606 emulated on the 3080, seed 880707 native on gfx1036) minimize to the same idiom. Caveat: two hard reductions stayed at 14 and 17 lines, where the pattern is present but not shown to be the cause, and the six programs with a hypothesis op (4 wave32, 2 wave64 native) are not explained.

  • cf_diff.py: 2,000 programs on the second commit (wave32 and wave64), 0 mismatches.
  • run_gpu_tests.py: per-test results identical to main: 3080 201/252, 3080 emulated 233/252, gfx1036 234/252, gfx1036 emulated 234/252; only the two known tfe fixtures fail (#31). Rerun on the second commit.
  • Not done: no RDNA2 measurement, no corpus run (I don't have the game), so translated / valid counts before and after, how many shaders change, and the cost of the extra subgroup ops are unknown. A corpus run by someone with a copy would be very useful before merging.

GPUs tested: NVIDIA RTX 3080 (620.73.04) and AMD RDNA2 iGPU gfx1036 (RADV, Mesa 26.3.1), CachyOS Linux 7.3.5

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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.

🔄 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/1043 **Author:** [@thesubtleties](https://github.com/thesubtleties) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `mask-as-data` --- ### 📝 Commits (3) - [`02d6293`](https://github.com/ubiquitarianism/leonida/commit/02d62939f62b5ed8d6a8835ed3f3030b4f843ae8) rdna2spirv: a lane mask read as a number is the wave's mask word (SHADER-MASK-AS-DATA) - [`68b964e`](https://github.com/ubiquitarianism/leonida/commit/68b964e4220da8d0e607e404719796acf6ce5862) lane_masks: follow a copied mask through VGPR copies before deciding how it is read (SHADER-MASK-AS-DATA) - [`4d58a05`](https://github.com/ubiquitarianism/leonida/commit/4d58a05d6026052e2f43330dee6ac493fe8aa9fc) Merge main into mask-as-data (SHADER-MASK-AS-DATA) ### 📊 Changes **10 files changed** (+307 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -0) ➕ `tests/semantic/test_mask_as_data.py` (+182 -0) 📝 `tests/semantic/test_salu64_bitwise_data.py` (+2 -2) 📝 `tests/semantic/test_salu_movrels_lane_mask.py` (+1 -1) 📝 `tests/semantic/test_scselect_b64_data.py` (+1 -1) 📝 `tests/semantic/test_slot67_operand_forms.py` (+1 -5) 📝 `tools/lane_masks.py` (+89 -5) 📝 `tools/rdna2spirv.py` (+21 -3) 📝 `tools/wave32_pixel_scan.py` (+3 -0) 📝 `tools/wave64_emulate_opt.py` (+6 -1) </details> ### 📄 Description Claimed in the coordination issue as: SHADER-MASK-AS-DATA ### What and why A lane mask is one word for the wave on hardware; the translator keeps each lane's own 0 / ~0. An op that read the mask as a number therefore got a different wrong value per lane, with no error: with mask `0x3ff`, `s_add_u32 d, mask, 1` was 0 or 1 and `v_mov_b32 v, mask` was 0 or ~0 (`crosslane_fuzz.py` "maskdata", the old #293). `s_bcnt` / `s_ff` / `s_flbit` already rebuild the word. This does the same for: - 32-bit integer SALU and VALU ops (`lane_masks.NUMBER_READERS`); - `v_mov_b32` of a mask, when no `v_readfirstlane_b32` or vector bitwise op reads that value as a mask. Each copy is followed forward, through VGPR-to-VGPR copies (second commit). The emulation planner counts such an op as an exchange, it never joins an active run, and `wave32_pixel_scan.py` counts it as `mask_word`. **Partial on purpose.** Not covered: the values excluded above (the v_mov / v_or3 / v_readfirstlane idiom needs each lane's own bit), compares, SDWA and DPP, and 16-bit, float and 64-bit ops. Three existing tests changed: `test_salu_movrels_lane_mask`, `test_scselect_b64_data` and `test_salu64_bitwise_data` read a mask back with `v_mov_b32` and expected the lane's own 0 / ~0; they now expect the mask word. ### Tested Measured on base `82a2aabc`, then rebased; the semantic suite and the touched tests were rerun after the rebase. - New `tests/semantic/test_mask_as_data.py` (wave32, native wave64, partial EXEC, the through-a-VGPR idiom, emulated translation): fails on `main`, passes here. - `run_semantic_tests.py`: 0 files failed. - `crosslane_fuzz.py`, hard mismatches, main -> this PR; no program fails here that passed on main: | Run | main | first commit | now | |---|---|---|---| | wave32 native, seed 880505 (300), 3080 and gfx1036 | 20 | 10 | **0** | | wave32 native, seed 991201 (250), 3080 | 13 | 7 | **4** | | wave32 native, seed 991202 (250), 3080 and gfx1036 | 21 | 16 | **4** | | wave64 emulated `--ext`, seed 880606 (300), 3080 and gfx1036 | 6 | 6 | **1** | | wave64 native `--ext`, seed 880707 (300), gfx1036 | 7 | 6 | **3** | The 880xxx main rows were run on `98a977b4`. With `--no-maskdata` there are no hard mismatches there on main. **Correction:** the first version of this text said the remaining mismatches were `v_readfirstlane` reads. Minimizing them showed most came from a plain VGPR-to-VGPR copy that the first commit counted as a mask read; the second commit fixes that. What is left on wave32 seeds 991201, 991202 and 993301 (11 mismatches, plus 4 programs with a hypothesis op) is now minimized on the 3080: every reduction contains a `v_mov_b32` of a mask into a VGPR that a `v_readfirstlane_b32` or a vector bitwise op then reads, the idiom this PR leaves alone. The shortest is `v_cmp_ne_u32_e32 vcc_lo, 9, v6` / `v_mov_b32_e32 v2, vcc_lo` / `v_readfirstlane_b32 s8, v2`. The wave64 leftovers (seed 880606 emulated on the 3080, seed 880707 native on gfx1036) minimize to the same idiom. Caveat: two hard reductions stayed at 14 and 17 lines, where the pattern is present but not shown to be the cause, and the six programs with a hypothesis op (4 wave32, 2 wave64 native) are not explained. - `cf_diff.py`: 2,000 programs on the second commit (wave32 and wave64), 0 mismatches. - `run_gpu_tests.py`: per-test results identical to main: 3080 201/252, 3080 emulated 233/252, gfx1036 234/252, gfx1036 emulated 234/252; only the two known tfe fixtures fail (#31). Rerun on the second commit. - Not done: no RDNA2 measurement, no corpus run (I don't have the game), so translated / valid counts before and after, how many shaders change, and the cost of the extra subgroup ops are unknown. A corpus run by someone with a copy would be very useful before merging. GPUs tested: NVIDIA RTX 3080 (620.73.04) and AMD RDNA2 iGPU gfx1036 (RADV, Mesa 26.3.1), CachyOS Linux 7.3.5 AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <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#1081
No description provided.