rdna2spirv: extract per-lane bits when reading plain scalar data in VCC as a lane mask (SHADER-VCC-DATA-MASK-SRC) #1943

Merged
ShotTechOp merged 1 commit from upstream-pr/1943 into main 2026-11-29 00:13:13 +00:00
ShotTechOp commented 2026-11-25 16:23:25 +00:00 (Migrated from github.com)

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


Claimed as SHADER-VCC-DATA-MASK-SRC in #1608.

What changed and why

When VCC (vcc / vcc_lo / vcc_hi) is written as plain scalar data (e.g. s_mov_b32 vcc_lo, K, s_mov_b32 vcc_hi, K, SGPR copies, or scalar ALU/loads) and left uncertified by tools/lane_masks.py, reading it as a lane mask through Gen.mask_src() (v_cndmask_b32, v_add_co_ci_u32, s_*_saveexec_*, s_mov_b32 exec_lo, vcc_lo, s_and_b32 exec_hi, exec_hi, vcc_hi, etc.) was broken in both wave32 and wave64:

  1. Wave32 (tools/rdna2spirv.py, Gen.mask_src):
    • _scalar_word_lane_bit() extraction for vcc / vcc_lo was gated on self.wave32_vcc_pointer (only set when the shader had s_load_* ..., vcc).
    • In any other wave32 shader, s_mov_b32 vcc_lo, 0x00000002 followed by v_cndmask_b32_e64 v6, 3, 5, vcc_lo returned raw 0x2 instead of bit lane & 31, enabling every lane instead of lane 1 alone.
  2. Wave64 (tools/rdna2spirv.py, Gen.mask_src, Gen.mask_dst, Gen.mov64, Gen.put_mask):
    • mask_src() loaded only %vcc and returned it raw without loading %vcc_hi for lanes 32..63 or extracting bit lane & 31. So s_mov_b32 vcc_lo, 0 + s_mov_b32 vcc_hi, 0x80000001 saw 0 on all 64 lanes, and s_mov_b32 vcc_lo, 0x2 saw non-zero on all 64 lanes.
    • Wave64 32-bit vcc_hi plain-data mask reads (e.g. s_and_b32 exec_hi, exec_hi, vcc_hi) also loaded %vcc instead of %vcc_hi.
    • Certified wave64 64-bit mask writes to vcc (mask_dst, mov64, and high-half put_mask) now mirror this lane's 0 / ~0 bit into %vcc_hi (matching how mask_dst already mirrors SGPR pairs into both s[r] and s[r+1]), so a control-flow join between a certified v_cmp mask and a plain-data vcc_lo/vcc_hi write (or s_mov_b64 vcc, s[4:5] from uncertified data SGPRs) stays exact on all 64 lanes on every path.

Fix:

  • tools/rdna2spirv.py:
    • Gen.mask_src: when not self.holds_lane_mask(a) for vcc/vcc_lo/vcc_hi, extract bit lane & 31 via _scalar_word_lane_bit() unconditionally (wave32 vcc/vcc_lo from %vcc; wave64 32-bit vcc_hi from %vcc_hi; wave64 64-bit vcc from %vcc for lanes 0..31 and %vcc_hi for lanes 32..63, matching the SGPR-pair fallback right above it). Certified masks still load %vcc directly with zero extra instructions.
    • Gen.mask_dst / Gen.mov64 / Gen.put_mask: mirror wave64 vcc per-lane mask writes into %vcc_hi (wave32 %vcc_hi remains untouched as an independent SGPR).
  • docs/design.md: document plain-data VCC lane-bit extraction in the Constant lane masks (Gen.mask_src immediates) contract row.
  • tests/semantic/test_vcc_data_mask_src.py: add wave32, wave64, and --wave64-emulate execution tests (v_cndmask_b32, v_add_co_ci_u32, s_and_saveexec_b32, s_and_b32 exec_hi, ..., vcc_hi, s_mov_b64 vcc, s[4:5], and wave64 certified-mask/plain-data CFG join), each assembled with tools/spirv_asm.py.

Negative control (RED on origin/main b0f3d39 -> GREEN on this branch)

  • LEONIDA_TOOLS_DIR=<origin/main tools> python -I tests/semantic/test_vcc_data_mask_src.py: FAILED (9 failures across 5 of 6 tests) — wave32 vcc_lo cndmask/carry-in selected all 32 lanes, wave64 vcc_lo/vcc_hi cndmask (native + --wave64-emulate) and carry-in ignored %vcc_hi and selected all/no lanes, wave64 vcc_hi half-mask read read %vcc, and the wave64 CFG join failed on the plain-data branch.
  • On this branch: 6/6 OK.

Tests run (Windows 11, Python 3.12.10, CPU / standard library only; no GPU or game files)

  • python -I tests/semantic/test_vcc_data_mask_src.py -v -> 6/6 OK (also python -m unittest discover -s tests/semantic -p test_vcc_data_mask_src.py -> OK)
  • python -I tests/semantic/test_wave64_vcc_half_write.py -> 7/7 OK
  • python -I tests/semantic/test_wave64_vcc_data_branch.py -> 5/5 OK
  • python -I tests/semantic/test_vcmp_dst_wave32_vcchi.py -> 7/7 OK
  • python -I tests/semantic/test_sload_vcc_base.py -> 5/5 OK
  • python -I tests/semantic/test_control_flow_vcc.py -> 24/24 OK
  • python -I tests/semantic/test_vcc_tuple_fallback.py -> 5/5 OK
  • python -I tests/semantic/test_mask_src_sgpr_const.py -> 7/7 OK
  • python -I tests/semantic/test_salu_b32_lane_masks.py -> 9/9 OK (1 skip)
  • python -I tests/semantic/test_salu64_bitwise_data.py -> 11/11 OK
  • python -m unittest discover -s tests/semantic -p test_exec_computed.py -> 2/2 OK
  • python -m unittest discover -s tests/semantic -p test_value_semantics.py -> 41/41 OK
  • python -I tests/test_lane_masks.py -> OK
  • python -I tests/test_wint_diff.py -> 29/29 OK
  • python -I tests/test_text_write_line_endings.py -> 3/3 OK
  • All 12 tests/test_docs_*.py suites + all GroupNonUniform semantic tests -> OK
  • python -m compileall -q tools/rdna2spirv.py tests/semantic/test_vcc_data_mask_src.py -> OK
  • python -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_vcc_data_mask_src.py -> OK
  • git diff --check -> clean

AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5495029503 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1943). Originally posted by [ShotTechOp](https://github.com/ShotTechOp) on 2026-11-25T16:23:25Z. --- Claimed as `SHADER-VCC-DATA-MASK-SRC` in #1608. ### What changed and why When VCC (`vcc` / `vcc_lo` / `vcc_hi`) is written as plain scalar data (e.g. `s_mov_b32 vcc_lo, K`, `s_mov_b32 vcc_hi, K`, SGPR copies, or scalar ALU/loads) and left uncertified by `tools/lane_masks.py`, reading it as a lane mask through `Gen.mask_src()` (`v_cndmask_b32`, `v_add_co_ci_u32`, `s_*_saveexec_*`, `s_mov_b32 exec_lo, vcc_lo`, `s_and_b32 exec_hi, exec_hi, vcc_hi`, etc.) was broken in both wave32 and wave64: 1. **Wave32 (`tools/rdna2spirv.py`, `Gen.mask_src`)**: - `_scalar_word_lane_bit()` extraction for `vcc` / `vcc_lo` was gated on `self.wave32_vcc_pointer` (only set when the shader had `s_load_* ..., vcc`). - In any other wave32 shader, `s_mov_b32 vcc_lo, 0x00000002` followed by `v_cndmask_b32_e64 v6, 3, 5, vcc_lo` returned raw `0x2` instead of bit `lane & 31`, enabling **every** lane instead of lane 1 alone. 2. **Wave64 (`tools/rdna2spirv.py`, `Gen.mask_src`, `Gen.mask_dst`, `Gen.mov64`, `Gen.put_mask`)**: - `mask_src()` loaded only `%vcc` and returned it raw without loading `%vcc_hi` for lanes 32..63 or extracting bit `lane & 31`. So `s_mov_b32 vcc_lo, 0` + `s_mov_b32 vcc_hi, 0x80000001` saw `0` on all 64 lanes, and `s_mov_b32 vcc_lo, 0x2` saw non-zero on all 64 lanes. - Wave64 32-bit `vcc_hi` plain-data mask reads (e.g. `s_and_b32 exec_hi, exec_hi, vcc_hi`) also loaded `%vcc` instead of `%vcc_hi`. - Certified wave64 64-bit mask writes to `vcc` (`mask_dst`, `mov64`, and high-half `put_mask`) now mirror this lane's `0` / `~0` bit into `%vcc_hi` (matching how `mask_dst` already mirrors SGPR pairs into both `s[r]` and `s[r+1]`), so a control-flow join between a certified `v_cmp` mask and a plain-data `vcc_lo`/`vcc_hi` write (or `s_mov_b64 vcc, s[4:5]` from uncertified data SGPRs) stays exact on all 64 lanes on every path. **Fix:** - `tools/rdna2spirv.py`: - `Gen.mask_src`: when `not self.holds_lane_mask(a)` for `vcc`/`vcc_lo`/`vcc_hi`, extract bit `lane & 31` via `_scalar_word_lane_bit()` unconditionally (wave32 `vcc`/`vcc_lo` from `%vcc`; wave64 32-bit `vcc_hi` from `%vcc_hi`; wave64 64-bit `vcc` from `%vcc` for lanes 0..31 and `%vcc_hi` for lanes 32..63, matching the SGPR-pair fallback right above it). Certified masks still load `%vcc` directly with zero extra instructions. - `Gen.mask_dst` / `Gen.mov64` / `Gen.put_mask`: mirror wave64 `vcc` per-lane mask writes into `%vcc_hi` (wave32 `%vcc_hi` remains untouched as an independent SGPR). - `docs/design.md`: document plain-data VCC lane-bit extraction in the `Constant lane masks (Gen.mask_src immediates)` contract row. - `tests/semantic/test_vcc_data_mask_src.py`: add wave32, wave64, and `--wave64-emulate` execution tests (`v_cndmask_b32`, `v_add_co_ci_u32`, `s_and_saveexec_b32`, `s_and_b32 exec_hi, ..., vcc_hi`, `s_mov_b64 vcc, s[4:5]`, and wave64 certified-mask/plain-data CFG join), each assembled with `tools/spirv_asm.py`. ### Negative control (RED on `origin/main` `b0f3d39` -> GREEN on this branch) - `LEONIDA_TOOLS_DIR=<origin/main tools> python -I tests/semantic/test_vcc_data_mask_src.py`: **FAILED (9 failures across 5 of 6 tests)** — wave32 `vcc_lo` cndmask/carry-in selected all 32 lanes, wave64 `vcc_lo`/`vcc_hi` cndmask (native + `--wave64-emulate`) and carry-in ignored `%vcc_hi` and selected all/no lanes, wave64 `vcc_hi` half-mask read read `%vcc`, and the wave64 CFG join failed on the plain-data branch. - On this branch: **6/6 OK**. ### Tests run (Windows 11, Python 3.12.10, CPU / standard library only; no GPU or game files) - `python -I tests/semantic/test_vcc_data_mask_src.py -v` -> 6/6 OK (also `python -m unittest discover -s tests/semantic -p test_vcc_data_mask_src.py` -> OK) - `python -I tests/semantic/test_wave64_vcc_half_write.py` -> 7/7 OK - `python -I tests/semantic/test_wave64_vcc_data_branch.py` -> 5/5 OK - `python -I tests/semantic/test_vcmp_dst_wave32_vcchi.py` -> 7/7 OK - `python -I tests/semantic/test_sload_vcc_base.py` -> 5/5 OK - `python -I tests/semantic/test_control_flow_vcc.py` -> 24/24 OK - `python -I tests/semantic/test_vcc_tuple_fallback.py` -> 5/5 OK - `python -I tests/semantic/test_mask_src_sgpr_const.py` -> 7/7 OK - `python -I tests/semantic/test_salu_b32_lane_masks.py` -> 9/9 OK (1 skip) - `python -I tests/semantic/test_salu64_bitwise_data.py` -> 11/11 OK - `python -m unittest discover -s tests/semantic -p test_exec_computed.py` -> 2/2 OK - `python -m unittest discover -s tests/semantic -p test_value_semantics.py` -> 41/41 OK - `python -I tests/test_lane_masks.py` -> OK - `python -I tests/test_wint_diff.py` -> 29/29 OK - `python -I tests/test_text_write_line_endings.py` -> 3/3 OK - All 12 `tests/test_docs_*.py` suites + all `GroupNonUniform` semantic tests -> OK - `python -m compileall -q tools/rdna2spirv.py tests/semantic/test_vcc_data_mask_src.py` -> OK - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_vcc_data_mask_src.py` -> OK - `git diff --check` -> clean AI-assisted: yes.
efeekrb commented 2026-11-25 17:45:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by efeekrb on 2026-11-25T17:45:18Z.


Tested on an NVIDIA GeForce RTX 4060 Laptop GPU (NVIDIA 610.78), Windows 11 build 26300, with an Intel UHD iGPU also present (LEONIDA_VK_DEVICE=4060). This PR's diff applies cleanly to main at 24a29f8 (where the test programs were built) and to main at b9320a118 (git apply --check).

  • Unit tests with the PR applied: tests/semantic/test_vcc_data_mask_src.py ran 6 tests, OK.
  • run_gpu_tests.py, full suite, with the PR applied: 274/274 shaders translated and pass spirv-val. Native 209/264 passed, 54 skipped, 1 failed; LEONIDA_W64_EMULATE=1 243/264 passed, 20 skipped, 1 failed. The one failure is cs_imgatomic_ext (the one #1518 addresses), and the counts are identical to main at 24a29f8 without this PR.

So no change on this GPU in either mode. The suite shows no regression; it does not tell whether a fixture exercises the rule this PR changes. No game files; counts and pass/fail lines only. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7169952252 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1943#issuecomment-7169952252). Originally posted by [efeekrb](https://github.com/efeekrb) on 2026-11-25T17:45:18Z. --- Tested on an NVIDIA GeForce RTX 4060 Laptop GPU (NVIDIA 610.78), Windows 11 build 26300, with an Intel UHD iGPU also present (`LEONIDA_VK_DEVICE=4060`). This PR's diff applies cleanly to `main` at `24a29f8` (where the test programs were built) and to `main` at `b9320a118` (`git apply --check`). - Unit tests with the PR applied: `tests/semantic/test_vcc_data_mask_src.py` ran 6 tests, OK. - `run_gpu_tests.py`, full suite, with the PR applied: 274/274 shaders translated and pass spirv-val. Native 209/264 passed, 54 skipped, 1 failed; `LEONIDA_W64_EMULATE=1` 243/264 passed, 20 skipped, 1 failed. The one failure is `cs_imgatomic_ext` (the one #1518 addresses), and the counts are identical to `main` at `24a29f8` without this PR. So no change on this GPU in either mode. The suite shows no regression; it does not tell whether a fixture exercises the rule this PR changes. No game files; counts and pass/fail lines only. AI-assisted (Claude Code).
zmasi commented 2026-11-28 12:39:41 +00:00 (Migrated from github.com)

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


Verified on physical gfx906, native subgroup 64 (RADV Mesa 26.0.8), with synchronization validation enabled. Same nine compute shaders and seven inputs against main d48a957bb and c82d668d0 merged with it. With bits 0 and 31 set in the high VCC word only, main selected no lanes; the merge selected exactly lanes 32 and 63. Moving those bits to the low word made main select all 64 lanes; the merge selected only 0 and 31.

Matching GPU readbacks went from 36/63 to 63/63 (1,398 wrong data words to zero). This includes carry-in, EXEC high-half reads and both paths of joins between compare-generated masks and plain VCC data. The SGPR-pair move and compare-generated-mask controls passed on both. All 18 modules passed spirv-val; all guards matched and no shader dispatch reported a validation error or synchronization hazard.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239380385 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1943#issuecomment-7239380385). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:39:41Z. --- Verified on physical gfx906, native subgroup 64 (RADV Mesa 26.0.8), with synchronization validation enabled. Same nine compute shaders and seven inputs against main `d48a957bb` and `c82d668d0` merged with it. With bits 0 and 31 set in the high VCC word only, main selected no lanes; the merge selected exactly lanes 32 and 63. Moving those bits to the low word made main select all 64 lanes; the merge selected only 0 and 31. Matching GPU readbacks went from 36/63 to 63/63 (1,398 wrong data words to zero). This includes carry-in, EXEC high-half reads and both paths of joins between compare-generated masks and plain VCC data. The SGPR-pair move and compare-generated-mask controls passed on both. All 18 modules passed `spirv-val`; all guards matched and no shader dispatch reported a validation error or synchronization hazard. AI-assisted.
TheGeogeo commented 2026-11-29 00:00:33 +00:00 (Migrated from github.com)

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


Tested c82d668d0 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_vcc_data_mask_src.py, 6 tests pass.
  • Red: with tools/rdna2spirv.py back to main, it fails (plain VCC data read as a lane mask: the lanes keep 9 where 1 is expected).

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:7247808654 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1943#issuecomment-7247808654). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T00:00:33Z. --- Tested `c82d668d0` 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_vcc_data_mask_src.py`, 6 tests pass. - Red: with `tools/rdna2spirv.py` back to `main`, it fails (plain VCC data read as a lane mask: the lanes keep `9` where `1` is expected). 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:16 +00:00 (Migrated from github.com)

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


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 e81999180 without conflict, and its test file(s) (tests/semantic/test_vcc_data_mask_src.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:7247959897 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1943#issuecomment-7247959897). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T00:13:16Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/1943#issuecomment-7247808654)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` e81999180 without conflict, and its test file(s) (`tests/semantic/test_vcc_data_mask_src.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!1943
No description provided.