rdna2spirv, lane_masks: extract per-lane bits for m0 and scc/src_scc in mask_src and _maskable_b32 (SHADER-MASK-SRC-M0-SCC) #1996

Merged
ShotTechOp merged 1 commit from upstream-pr/1996 into main 2026-11-29 00:13:55 +00:00
ShotTechOp commented 2026-11-25 17:52:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ShotTechOp on 2026-11-25T17:52:11Z.


Claimed in #1608 as SHADER-MASK-SRC-M0-SCC.

What and why

  • _maskable_b32 in both tools/rdna2spirv.py and tools/lane_masks.py previously accepted only sgpr, imm, exec*, vcc*, and null, omitting m0 and scc/src_scc.
    • When a 32-bit bitwise or select op targeted exec_lo/exec_hi or vcc_lo/vcc_hi with m0 or src_scc (e.g., s_and_b32 exec_lo, exec_lo, m0, s_andn2_b32 exec_lo, exec_lo, m0, s_and_b32 vcc_lo, vcc_lo, m0, s_not_b32 vcc_lo, m0), sop2_b32_srcs / s_not_b32 fell back to raw src_u() instead of _mask_b32_src():
      1. On exec_lo/exec_hi destinations, r held raw non-zero bitmasks on active lanes whose bit in m0/src_scc was 0, so scc_logic (scc_any_half(r)) set SCC = 1 even when the resulting EXEC half was 0 (e.g., exec_lo = 0x2, m0 = 0x5 -> exec_lo & m0 == 0 still set SCC = 1).
      2. On vcc_lo/vcc_hi destinations, put_mask / dst stored that raw non-zero word into %vcc on lanes whose bit in m0 was 0 (corrupting subsequent v_cndmask_b32 and s_cbranch_vccz), and lane_masks.step dropped vcc from the mask state.
  • Gen.mask_src also raised Unsupported("mask operand") for m0 and scc/src_scc, breaking s_*_saveexec_b32 / s_*_wrexec_b32 / s_*_saveexec_b64 with m0 or src_scc.
  • Adding m0, scc, and src_scc to _maskable_b32 (both modules) and to Gen.mask_src (zero-extending bits 32..63 to 0 when wide and self.wave64) fixes both the silent miscompilations and the saveexec/wrexec rejections.
  • Added the contract row for m0 and scc/src_scc lane-mask sources in docs/design.md.

Testing

  • AI-assisted: yes.
  • Environment: Windows 11, Python 3.12 (no GPU / LLVM / SPIRV-Tools installed locally).
  • New regression suite: tests/semantic/test_mask_src_m0_scc.py — tests s_and_b32, s_andn2_b32, s_or_b32, s_xor_b32, s_not_b32 into exec_lo, exec_hi, vcc_lo, vcc_hi (wave32 and wave64), and s_and_saveexec_b32 / s_and_saveexec_b64 with m0 and src_scc, checking both per-lane mask values and SCC.
  • RED control on origin/main (b9320a1): tests/semantic/test_mask_src_m0_scc.py fails with FAILED (failures=19, errors=1) (proving wrong SCC on exec_lo/exec_hi, corrupted vcc_lo/vcc_hi lane bits, and Unsupported("mask operand") on s_and_saveexec_b32/b64).
  • GREEN checks on branch:
    • python -I tests/semantic/test_mask_src_m0_scc.py -v (3/3 OK)
    • python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py (9 ran, OK, 1 skipped)
    • python -m unittest discover -s tests/semantic -p test_mask_src_sgpr_const.py (7/7 OK)
    • python -m unittest discover -s tests/semantic -p test_wave64_vcc_half_write.py (7/7 OK)
    • python -m unittest discover -s tests -p "test_docs_*.py" (50/50 OK)
    • python -I tests/test_text_write_line_endings.py (3/3 OK)
    • python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_mask_src_m0_scc.py
    • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tools/lane_masks.py docs/design.md tests/semantic/test_mask_src_m0_scc.py
    • git diff --check
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5496374149 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1996). Originally posted by [ShotTechOp](https://github.com/ShotTechOp) on 2026-11-25T17:52:11Z. --- Claimed in #1608 as `SHADER-MASK-SRC-M0-SCC`. ## What and why - `_maskable_b32` in both `tools/rdna2spirv.py` and `tools/lane_masks.py` previously accepted only `sgpr`, `imm`, `exec*`, `vcc*`, and `null`, omitting `m0` and `scc`/`src_scc`. - When a 32-bit bitwise or select op targeted `exec_lo`/`exec_hi` or `vcc_lo`/`vcc_hi` with `m0` or `src_scc` (e.g., `s_and_b32 exec_lo, exec_lo, m0`, `s_andn2_b32 exec_lo, exec_lo, m0`, `s_and_b32 vcc_lo, vcc_lo, m0`, `s_not_b32 vcc_lo, m0`), `sop2_b32_srcs` / `s_not_b32` fell back to raw `src_u()` instead of `_mask_b32_src()`: 1. On `exec_lo`/`exec_hi` destinations, `r` held raw non-zero bitmasks on active lanes whose bit in `m0`/`src_scc` was `0`, so `scc_logic` (`scc_any_half(r)`) set `SCC = 1` even when the resulting `EXEC` half was `0` (e.g., `exec_lo = 0x2`, `m0 = 0x5` -> `exec_lo & m0 == 0` still set `SCC = 1`). 2. On `vcc_lo`/`vcc_hi` destinations, `put_mask` / `dst` stored that raw non-zero word into `%vcc` on lanes whose bit in `m0` was `0` (corrupting subsequent `v_cndmask_b32` and `s_cbranch_vccz`), and `lane_masks.step` dropped `vcc` from the mask state. - `Gen.mask_src` also raised `Unsupported("mask operand")` for `m0` and `scc`/`src_scc`, breaking `s_*_saveexec_b32` / `s_*_wrexec_b32` / `s_*_saveexec_b64` with `m0` or `src_scc`. - Adding `m0`, `scc`, and `src_scc` to `_maskable_b32` (both modules) and to `Gen.mask_src` (zero-extending bits `32..63` to `0` when `wide and self.wave64`) fixes both the silent miscompilations and the `saveexec`/`wrexec` rejections. - Added the contract row for `m0` and `scc`/`src_scc` lane-mask sources in `docs/design.md`. ## Testing - **AI-assisted**: yes. - **Environment**: Windows 11, Python 3.12 (no GPU / LLVM / SPIRV-Tools installed locally). - **New regression suite**: `tests/semantic/test_mask_src_m0_scc.py` — tests `s_and_b32`, `s_andn2_b32`, `s_or_b32`, `s_xor_b32`, `s_not_b32` into `exec_lo`, `exec_hi`, `vcc_lo`, `vcc_hi` (wave32 and wave64), and `s_and_saveexec_b32` / `s_and_saveexec_b64` with `m0` and `src_scc`, checking both per-lane mask values and `SCC`. - **RED control on `origin/main` (`b9320a1`)**: `tests/semantic/test_mask_src_m0_scc.py` fails with `FAILED (failures=19, errors=1)` (proving wrong `SCC` on `exec_lo`/`exec_hi`, corrupted `vcc_lo`/`vcc_hi` lane bits, and `Unsupported("mask operand")` on `s_and_saveexec_b32/b64`). - **GREEN checks on branch**: - `python -I tests/semantic/test_mask_src_m0_scc.py -v` (3/3 OK) - `python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py` (9 ran, OK, 1 skipped) - `python -m unittest discover -s tests/semantic -p test_mask_src_sgpr_const.py` (7/7 OK) - `python -m unittest discover -s tests/semantic -p test_wave64_vcc_half_write.py` (7/7 OK) - `python -m unittest discover -s tests -p "test_docs_*.py"` (50/50 OK) - `python -I tests/test_text_write_line_endings.py` (3/3 OK) - `python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_mask_src_m0_scc.py` - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tools/lane_masks.py docs/design.md tests/semantic/test_mask_src_m0_scc.py` - `git diff --check`
kirigayakazima commented 2026-11-28 06:00:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-28T06:00:24Z.


#1996 | head 01cd084222a375ea975da8241c79e4305f442869 | python -I -m unittest discover -s tests/semantic -p test_mask_src_m0_scc.py | red: FAILED (failures=19, errors=1; AssertionError + rdna2spirv.Unsupported) | green: 3/3 OK (2.949s) | full suite: 513/521 stdlib passed after standalone rerun of parallel-timeout test_merge_check.py (0 new failures), semantic 506 files / 6400 tests / 0 failed vs main 8994000b08 | Windows 11, Python 3.14.7, no game files | AI-assisted: yes, Antigravity (Gemini)

Details:

  • Red (PR test tests/semantic/test_mask_src_m0_scc.py on upstream/main 8994000b08): Ran 3 tests in 2.892s — FAILED (failures=19, errors=1): rdna2spirv.Unsupported: mask operand in test_saveexec_b32_and_b64_with_m0_and_src_scc, plus 10 AssertionError subtests in test_exec_b32_bitwise_with_m0_gives_exact_lanes_and_scc and 9 AssertionError failures in test_vcc_b32_bitwise_and_not_with_m0_and_scc.
  • Green (merged with upstream/main 8994000b08): Ran 3 tests in 2.949s — OK.
  • Repo checks: scripts/check_no_game_data.py -> 0; python -m compileall -q tools scripts tests -> 0; node --test tests/test_viewer_streaming.cjs -> 0.
  • Full stdlib & semantic suites: tests/test_*.py initially hit 1 parallel 90s worker timeout on tests/test_merge_check.py (which passed 24/24 OK in 44.549s when re-run standalone on the merged PR tree), giving 513/521 passed (33 skipped pytest/helper files; 0 new failures vs 8994000b08, same 8 pre-existing failures). Semantic suite: 506 files, 6400 tests, 0 files failed in 430 s with 16 jobs.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7235018883 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1996#issuecomment-7235018883). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-28T06:00:24Z. --- `#1996 | head 01cd084222a375ea975da8241c79e4305f442869 | python -I -m unittest discover -s tests/semantic -p test_mask_src_m0_scc.py | red: FAILED (failures=19, errors=1; AssertionError + rdna2spirv.Unsupported) | green: 3/3 OK (2.949s) | full suite: 513/521 stdlib passed after standalone rerun of parallel-timeout test_merge_check.py (0 new failures), semantic 506 files / 6400 tests / 0 failed vs main 8994000b08 | Windows 11, Python 3.14.7, no game files | AI-assisted: yes, Antigravity (Gemini)` Details: - **Red** (PR test `tests/semantic/test_mask_src_m0_scc.py` on `upstream/main` `8994000b08`): `Ran 3 tests in 2.892s — FAILED (failures=19, errors=1)`: `rdna2spirv.Unsupported: mask operand` in `test_saveexec_b32_and_b64_with_m0_and_src_scc`, plus 10 `AssertionError` subtests in `test_exec_b32_bitwise_with_m0_gives_exact_lanes_and_scc` and 9 `AssertionError` failures in `test_vcc_b32_bitwise_and_not_with_m0_and_scc`. - **Green** (merged with `upstream/main` `8994000b08`): `Ran 3 tests in 2.949s — OK`. - **Repo checks**: `scripts/check_no_game_data.py` -> `0`; `python -m compileall -q tools scripts tests` -> `0`; `node --test tests/test_viewer_streaming.cjs` -> `0`. - **Full stdlib & semantic suites**: `tests/test_*.py` initially hit 1 parallel 90s worker timeout on `tests/test_merge_check.py` (which passed `24/24 OK` in `44.549s` when re-run standalone on the merged PR tree), giving `513/521 passed` (`33` skipped pytest/helper files; `0` new failures vs `8994000b08`, same 8 pre-existing failures). Semantic suite: `506 files, 6400 tests, 0 files failed in 430 s with 16 jobs`.
zmasi commented 2026-11-28 12:41:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:41:49Z.


Physical gfx906, native subgroup 64, RADV Mesa 26.0.8 with synchronization validation. Same synthetic inputs on main d48a957bb and 01cd08422 merged with it: 65/90 GPU readbacks matched on main, 102/102 on the merge. With EXEC low = 2 and M0 = 5, their AND correctly left the low half empty on both builds, but main set SCC to 1. The merge returned SCC = 0 and preserved the upper half. Across the paired cases, 576 wrong SCC words and 180 wrong VCC predicate words went to zero. All 24 ordinary-SGPR controls matched byte for byte.

The 12 additional merge dispatches were the encodable src_scc 64-bit saveexec/wrexec forms; main refused both modules before dispatch. No hardware claim for 64-bit M0 (not encodable with the tested gfx1030 assembler) or 32-bit saveexec/wrexec (both translators rejected those fixtures with wave64 metadata). All accepted dispatches preserved their guards and reported no validation errors or synchronization hazards.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239404551 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1996#issuecomment-7239404551). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:41:49Z. --- Physical gfx906, native subgroup 64, RADV Mesa 26.0.8 with synchronization validation. Same synthetic inputs on main `d48a957bb` and `01cd08422` merged with it: 65/90 GPU readbacks matched on main, 102/102 on the merge. With EXEC low = 2 and M0 = 5, their AND correctly left the low half empty on both builds, but main set SCC to 1. The merge returned SCC = 0 and preserved the upper half. Across the paired cases, 576 wrong SCC words and 180 wrong VCC predicate words went to zero. All 24 ordinary-SGPR controls matched byte for byte. The 12 additional merge dispatches were the encodable `src_scc` 64-bit saveexec/wrexec forms; main refused both modules before dispatch. No hardware claim for 64-bit M0 (not encodable with the tested gfx1030 assembler) or 32-bit saveexec/wrexec (both translators rejected those fixtures with wave64 metadata). All accepted dispatches preserved their guards and reported no validation errors or synchronization hazards. AI-assisted.
TheGeogeo commented 2026-11-29 00:00:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:00:37Z.


Tested 01cd08422 merged (no commit) with main aa918e5d9. Python 3.12.4, Windows 11 10.0.26300, CPU only, with LLVM_MC (conda-forge llvm-tools) and SPIRV-Tools from the Vulkan SDK 1.4.363.1. check_no_game_data.py is clean.

  • Green: tests/semantic/test_mask_src_m0_scc.py, 3 tests pass.
  • Red: with tools/lane_masks.py and tools/rdna2spirv.py back to main, it fails (m0/scc lanes are not extracted per lane).

Overlap check across #1973, #1977, #1990, #1943, #1994, #1996 and #1803 (same translator area):

  • None is a stack or a duplicate. They are independent single commits, and each covers a different reader:
    • plain 64-bit VCC data: #1973 for the b64 bit ops, #1977 for s_wqm, #1990 for src64_data/is_mask_op;
    • per-lane bits from non-mask sources: #1943 for VCC data, #1994 for s_mov into exec_hi, #1996 for m0/scc;
    • #1803: wave32 lane slots.
  • The only textual conflict is docs/design.md, between #1990, #1943 and #1994.
  • With all 7 merged together on main (docs/design.md taken from main), each PR's own test file passes. The full semantic suite (scripts/run_semantic_tests.py tests/semantic -j 4, 528 files, 6513 tests) fails in 2 files:
    • test_valu_cvt_f16_int16_mods, which fails on plain main too;
    • test_wave64_emulate_opt, which comes from #1990 alone (see #1990).

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247809350 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1996#issuecomment-7247809350). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T00:00:37Z. --- Tested `01cd08422` merged (no commit) with `main` `aa918e5d9`. Python 3.12.4, Windows 11 10.0.26300, CPU only, with `LLVM_MC` (conda-forge llvm-tools) and SPIRV-Tools from the Vulkan SDK 1.4.363.1. `check_no_game_data.py` is clean. - Green: `tests/semantic/test_mask_src_m0_scc.py`, 3 tests pass. - Red: with `tools/lane_masks.py` and `tools/rdna2spirv.py` back to `main`, it fails (`m0`/`scc` lanes are not extracted per lane). Overlap check across #1973, #1977, #1990, #1943, #1994, #1996 and #1803 (same translator area): - None is a stack or a duplicate. They are independent single commits, and each covers a different reader: - plain 64-bit VCC data: #1973 for the b64 bit ops, #1977 for `s_wqm`, #1990 for `src64_data`/`is_mask_op`; - per-lane bits from non-mask sources: #1943 for VCC data, #1994 for `s_mov` into `exec_hi`, #1996 for `m0`/`scc`; - #1803: wave32 lane slots. - The only textual conflict is `docs/design.md`, between #1990, #1943 and #1994. - With all 7 merged together on `main` (`docs/design.md` taken from `main`), each PR's own test file passes. The full semantic suite (`scripts/run_semantic_tests.py tests/semantic -j 4`, 528 files, 6513 tests) fails in 2 files: - `test_valu_cvt_f16_int16_mods`, which fails on plain `main` too; - `test_wave64_emulate_opt`, which comes from #1990 alone (see #1990). No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 00:13:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T00:13:57Z.


Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto main 58a216c70 without conflict, and its test file(s) (tests/semantic/test_mask_src_m0_scc.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247968362 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1996#issuecomment-7247968362). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T00:13:57Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/1996#issuecomment-7247809350)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` 58a216c70 without conflict, and its test file(s) (`tests/semantic/test_mask_src_m0_scc.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1996
No description provided.