rdna2spirv: preserve %vcc_hi on plain-data s_mov_b64 from vcc and support null operands (SHADER-MOV64-VCC-DATA-AND-NULL) #1983

Closed
ShotTechOp wants to merge 1 commit from upstream-pr/1983 into main
ShotTechOp commented 2026-11-25 17:23:27 +00:00 (Migrated from github.com)

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


Claimed in #1608 as SHADER-MOV64-VCC-DATA-AND-NULL.

What and why

In Gen.mov64() (tools/rdna2spirv.py), s_mov_b64 had two gaps:

  1. Silent high-word corruption on s_mov_b64 s[D:D+1], vcc when vcc holds plain 64-bit scalar data:
    • mov64() unconditionally duplicated %vcc into both halves (lo = hi = OpLoad %uint %vcc), assuming vcc always held a per-lane mask.
    • When vcc holds plain 64-bit scalar data (not self.holds_lane_mask(s), e.g. written via s_mov_b32 vcc_lo, ...; s_mov_b32 vcc_hi, ...), s_mov_b64 s[6:7], vcc silently overwrote s7 with %vcc instead of %vcc_hi.
  2. null source / destination rejected:
    • s_mov_b64 s[6:7], null raised Unsupported("s_mov_b64 source") instead of writing (0, 0), and s_mov_b64 null, <src> raised Unsupported("s_mov_b64 destination") instead of validating the source and discarding the write (matching s_not_b64 / dst64_data(..., allow_null=True)).

Changes

  • tools/rdna2spirv.py:
    • In Gen.mov64(), check self.holds_lane_mask(s) when s is vcc: keep lo = hi = OpLoad %uint %vcc for lane masks, and load both %vcc and %vcc_hi when vcc holds plain scalar data.
    • Accept null as a source ((0, 0), also seeding sgpr_imm with 0) and as a discard destination (after validating the source operand).
  • docs/design.md:
    • Documented the s_mov_b64 null and plain-data vcc contract in the Null mask source row.
  • tests/semantic/test_mov64_vcc_data_and_null.py:
    • Covers s_mov_b64 s[6:7], vcc with plain 64-bit data in both wave64 and FSPX wave32, vcc transitioning from a lane mask to plain data, s_mov_b64 s[6:7], null, s_mov_b64 null, <valid> + invalid source rejection, and a real lane-mask vcc control.

Verification

  • AI-assisted: yes.
  • Environment: Windows 11 (Python 3.12.10, CPU-only / spirv_mini_interp; no GPU, LLVM, or SPIRV-Tools installed locally).
  • Tests run (all GREEN):
    • python -I tests/semantic/test_mov64_vcc_data_and_null.py -v
    • python -m unittest discover -s tests/semantic -p test_salu64_bitwise_data.py
    • python -m unittest discover -s tests/semantic -p test_fspx_wave_size.py
    • python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py
    • python -m unittest discover -s tests -p "test_docs_*.py"
    • python -I tests/test_text_write_line_endings.py
    • python -m compileall -q tools/rdna2spirv.py tests/semantic/test_mov64_vcc_data_and_null.py
    • python -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_mov64_vcc_data_and_null.py
    • git diff --check
  • Negative control against origin/main (tools/rdna2spirv.py at fe15534): tests/semantic/test_mov64_vcc_data_and_null.py fails on origin/main across all 3 bug tests (s_mov_b64 s[6:7], vcc returns [lo, lo] instead of [lo, hi] across all 12 wave64/wave32/transition subtests, and s_mov_b64 s[6:7], null raises Unsupported: s_mov_b64 source), while the lane-mask control passes.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5495955285 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1983). Originally posted by [ShotTechOp](https://github.com/ShotTechOp) on 2026-11-25T17:23:27Z. --- Claimed in #1608 as `SHADER-MOV64-VCC-DATA-AND-NULL`. ### What and why In `Gen.mov64()` (`tools/rdna2spirv.py`), `s_mov_b64` had two gaps: 1. **Silent high-word corruption on `s_mov_b64 s[D:D+1], vcc` when `vcc` holds plain 64-bit scalar data**: - `mov64()` unconditionally duplicated `%vcc` into both halves (`lo = hi = OpLoad %uint %vcc`), assuming `vcc` always held a per-lane mask. - When `vcc` holds plain 64-bit scalar data (`not self.holds_lane_mask(s)`, e.g. written via `s_mov_b32 vcc_lo, ...; s_mov_b32 vcc_hi, ...`), `s_mov_b64 s[6:7], vcc` silently overwrote `s7` with `%vcc` instead of `%vcc_hi`. 2. **`null` source / destination rejected**: - `s_mov_b64 s[6:7], null` raised `Unsupported("s_mov_b64 source")` instead of writing `(0, 0)`, and `s_mov_b64 null, <src>` raised `Unsupported("s_mov_b64 destination")` instead of validating the source and discarding the write (matching `s_not_b64` / `dst64_data(..., allow_null=True)`). ### Changes - **`tools/rdna2spirv.py`**: - In `Gen.mov64()`, check `self.holds_lane_mask(s)` when `s` is `vcc`: keep `lo = hi = OpLoad %uint %vcc` for lane masks, and load both `%vcc` and `%vcc_hi` when `vcc` holds plain scalar data. - Accept `null` as a source (`(0, 0)`, also seeding `sgpr_imm` with `0`) and as a discard destination (after validating the source operand). - **`docs/design.md`**: - Documented the `s_mov_b64` `null` and plain-data `vcc` contract in the `Null mask source` row. - **`tests/semantic/test_mov64_vcc_data_and_null.py`**: - Covers `s_mov_b64 s[6:7], vcc` with plain 64-bit data in both wave64 and FSPX wave32, `vcc` transitioning from a lane mask to plain data, `s_mov_b64 s[6:7], null`, `s_mov_b64 null, <valid>` + invalid source rejection, and a real lane-mask `vcc` control. ### Verification - **AI-assisted**: yes. - **Environment**: Windows 11 (Python 3.12.10, CPU-only / `spirv_mini_interp`; no GPU, LLVM, or SPIRV-Tools installed locally). - **Tests run (all GREEN)**: - `python -I tests/semantic/test_mov64_vcc_data_and_null.py -v` - `python -m unittest discover -s tests/semantic -p test_salu64_bitwise_data.py` - `python -m unittest discover -s tests/semantic -p test_fspx_wave_size.py` - `python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py` - `python -m unittest discover -s tests -p "test_docs_*.py"` - `python -I tests/test_text_write_line_endings.py` - `python -m compileall -q tools/rdna2spirv.py tests/semantic/test_mov64_vcc_data_and_null.py` - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_mov64_vcc_data_and_null.py` - `git diff --check` - **Negative control against `origin/main` (`tools/rdna2spirv.py` at `fe15534`)**: `tests/semantic/test_mov64_vcc_data_and_null.py` fails on `origin/main` across all 3 bug tests (`s_mov_b64 s[6:7], vcc` returns `[lo, lo]` instead of `[lo, hi]` across all 12 wave64/wave32/transition subtests, and `s_mov_b64 s[6:7], null` raises `Unsupported: s_mov_b64 source`), while the lane-mask control passes.
zmasi commented 2026-11-28 12:32:20 +00:00 (Migrated from github.com)

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


#1983 | head 8ad6efc6a103e7dd88db3a8ada7107087bbd1ac2 (merged cleanly onto main d48a957bb9988afce424552a3c0c8d01ef12320f) | Windows 11 (10.0.26200), CPython 3.12.10, llvm-mc (gfx1013), spirv-val (1.4.363.1), NVIDIA GeForce RTX 3090 (Vulkan 1.4.341, driver 610.88, subgroup 32..32, LEONIDA_VK_VALIDATION=1)

  • Red on main (d48a957bb9988afce424552a3c0c8d01ef12320f):
    • tests/semantic/test_mov64_vcc_data_and_null.py: FAILED (failures=12, errors=1) (s_mov_b64 s[6:7], vcc duplicates %vcc into both dwords and null source/destination raises Unsupported).
    • Live RTX 3090 vk_compute_test (--wave64-emulate, LEONIDA_VK_VALIDATION=1) on s_mov_b32 vcc_lo, 0x11223344; s_mov_b32 vcc_hi, 0x55667788; s_mov_b64 s[6:7], vcc: dumps 0x11223344 0x11223344 (%vcc_hi lost).
  • Green on PR + main:
    • python -I tests/semantic/test_mov64_vcc_data_and_null.py -v: 4/4 test methods (12/12 subtests) pass (OK).
    • Live RTX 3090 vk_compute_test (--wave64-emulate, LEONIDA_VK_VALIDATION=1, spirv-val clean) exercising s_mov_b64 s[6:7], vcc on 0x55667788_11223344, s_mov_b64 s[8:9], null, and s_mov_b64 null, vcc: 1 groups x 64: 0 mismatches, out[0..3] = 0x11223344 0x55667788 0x00000000 0x00000000 (0 Khronos validation errors).
    • scripts/check_no_game_data.py, test_docs_encoding.py, and test_text_write_line_endings.py: pass (0 CRLF).
  • Non-blocking edge-case note: s_mov_b64 vcc, null followed by s_mov_b64 s[6:7], vcc currently yields [0x0, <stale %vcc_hi>] because tools/lane_masks.py (kind()) returns None for special: null (dropping "vcc" from cur_masks) while s_mov_b64 into vcc (tools/rdna2spirv.py line 1843) only stores 0 to %vcc and leaves %vcc_hi untouched.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239296223 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1983#issuecomment-7239296223). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:32:20Z. --- #1983 | head `8ad6efc6a103e7dd88db3a8ada7107087bbd1ac2` (merged cleanly onto `main` `d48a957bb9988afce424552a3c0c8d01ef12320f`) | Windows 11 (`10.0.26200`), CPython `3.12.10`, `llvm-mc` (`gfx1013`), `spirv-val` (`1.4.363.1`), NVIDIA GeForce RTX 3090 (Vulkan `1.4.341`, driver `610.88`, `subgroup 32..32`, `LEONIDA_VK_VALIDATION=1`) - **Red on `main` (`d48a957bb9988afce424552a3c0c8d01ef12320f`)**: - `tests/semantic/test_mov64_vcc_data_and_null.py`: `FAILED (failures=12, errors=1)` (`s_mov_b64 s[6:7], vcc` duplicates `%vcc` into both dwords and `null` source/destination raises `Unsupported`). - Live RTX 3090 `vk_compute_test` (`--wave64-emulate`, `LEONIDA_VK_VALIDATION=1`) on `s_mov_b32 vcc_lo, 0x11223344; s_mov_b32 vcc_hi, 0x55667788; s_mov_b64 s[6:7], vcc`: dumps `0x11223344 0x11223344` (`%vcc_hi` lost). - **Green on `PR + main`**: - `python -I tests/semantic/test_mov64_vcc_data_and_null.py -v`: `4/4` test methods (`12/12` subtests) pass (`OK`). - Live RTX 3090 `vk_compute_test` (`--wave64-emulate`, `LEONIDA_VK_VALIDATION=1`, `spirv-val` clean) exercising `s_mov_b64 s[6:7], vcc` on `0x55667788_11223344`, `s_mov_b64 s[8:9], null`, and `s_mov_b64 null, vcc`: `1 groups x 64: 0 mismatches`, `out[0..3] = 0x11223344 0x55667788 0x00000000 0x00000000` (`0` Khronos validation errors). - `scripts/check_no_game_data.py`, `test_docs_encoding.py`, and `test_text_write_line_endings.py`: pass (`0` CRLF). - **Non-blocking edge-case note**: `s_mov_b64 vcc, null` followed by `s_mov_b64 s[6:7], vcc` currently yields `[0x0, <stale %vcc_hi>]` because `tools/lane_masks.py` (`kind()`) returns `None` for `special: null` (dropping `"vcc"` from `cur_masks`) while `s_mov_b64` into `vcc` (`tools/rdna2spirv.py` line 1843) only stores `0` to `%vcc` and leaves `%vcc_hi` untouched. AI-assisted.
zmasi commented 2026-11-28 13:10:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T13:10:53Z.


Tested dependency: land #1943 before #1983, or include its VCC-write fix. The compare-path regression I saw with #1983 alone disappears with #1943 present. I regenerated the same inputs on main d48a957bb, adding #1943 c82d668d0 before #1983 8ad6efc6a. The CPU interpreter and all 24 physical gfx906 readbacks on the combined tree agreed byte for byte (RADV Mesa 26.0.8, native subgroup 64, synchronization validation).

Dependency check #1983 alone #1943 + #1983
Compare-mask / plain-data branch join 5/8 8/8
Clear a prefilled VCC with null, then copy both words 1/8 8/8
SGPR pair to VCC and back, checking scalar words as well as predicates and carry 0/8 0/8

On the round trip, #1943 fixes all predicate, carry-result and carry-out rows that regressed with #1983 alone. What remains wrong is the scalar value: after a single 64-bit write into VCC, the low and high words read from VCC or copied back to the SGPR pair still contain per-lane mask values rather than the original two scalar words. This scalar round-trip problem was already present on main. The join and prefilled-null cases are good tests of the dependency; the raw scalar round trip needs its own test.

For context, the original broader comparison was 19/64 matching readbacks on main vs 54/88 on #1983 alone (three null-related modules newly accepted). The combined tree was tested on the three cases above, not the full matrix. Guards held; no shader-run validation errors or synchronization hazards.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239751867 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1983#issuecomment-7239751867). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T13:10:53Z. --- **Tested dependency: land #1943 before #1983, or include its VCC-write fix.** The compare-path regression I saw with #1983 alone disappears with #1943 present. I regenerated the same inputs on main `d48a957bb`, adding #1943 `c82d668d0` before #1983 `8ad6efc6a`. The CPU interpreter and all 24 physical gfx906 readbacks on the combined tree agreed byte for byte (RADV Mesa 26.0.8, native subgroup 64, synchronization validation). | Dependency check | #1983 alone | #1943 + #1983 | |---|---:|---:| | Compare-mask / plain-data branch join | 5/8 | 8/8 | | Clear a prefilled VCC with null, then copy both words | 1/8 | 8/8 | | SGPR pair to VCC and back, checking scalar words as well as predicates and carry | 0/8 | 0/8 | On the round trip, #1943 fixes all predicate, carry-result and carry-out rows that regressed with #1983 alone. What remains wrong is the scalar value: after a single 64-bit write into VCC, the low and high words read from VCC or copied back to the SGPR pair still contain per-lane mask values rather than the original two scalar words. This scalar round-trip problem was already present on main. The join and prefilled-null cases are good tests of the dependency; the raw scalar round trip needs its own test. For context, the original broader comparison was 19/64 matching readbacks on main vs 54/88 on #1983 alone (three null-related modules newly accepted). The combined tree was tested on the three cases above, not the full matrix. Guards held; no shader-run validation errors or synchronization hazards. AI-assisted.
OreoFR commented 2026-11-29 19:49:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T19:49:15Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS, Python 3.12.16, spirv-tools + llvm-mc, main 0e8737f2a (merges cleanly; does not force a rebase of #2566 at cfd12b24f), PR head 8ad6efc6a : red 12 failures + 1 error / green 4 OK, 0 skipped

  • Red: test_mov64_vcc_data_and_null.py 0/4 (12 failures + 1 error). Green: 4/4, 0 skipped. The dependency on #1943 is resolved (merged).
  • Full semantic suite (scripts/run_semantic_tests.py tests/semantic) and the CI translator-tests pytest selection on main and on the merge: identical to main (main: only test_interp_computed_ij_fallback x2; translator-tests 2047 OK / 19 skipped). No new failure.
  • Rule check: the "Null mask source" row of docs/design.md is extended, but there is no .asm fixture under tests/semantic/ (CPU check through the Python test only).
  • Reviews: none.
  • Diff: with a null destination the value is read then dropped; a vcc that does not carry a lane mask loads %vcc and %vcc_hi. No game data.

Verdict: READY on tests; missing the .asm fixture the repo asks for a translator rule.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7261581781 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1983#issuecomment-7261581781). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T19:49:15Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS, Python 3.12.16, spirv-tools + llvm-mc, main 0e8737f2a (merges cleanly; does not force a rebase of #2566 at cfd12b24f), PR head 8ad6efc6a : red 12 failures + 1 error / green 4 OK, 0 skipped - **Red**: `test_mov64_vcc_data_and_null.py` 0/4 (12 failures + 1 error). **Green**: 4/4, 0 skipped. The dependency on #1943 is resolved (merged). - Full semantic suite (`scripts/run_semantic_tests.py tests/semantic`) and the CI translator-tests pytest selection on main and on the merge: identical to main (main: only `test_interp_computed_ij_fallback` x2; translator-tests 2047 OK / 19 skipped). No new failure. - Rule check: the "Null mask source" row of `docs/design.md` is extended, but **there is no `.asm` fixture under `tests/semantic/`** (CPU check through the Python test only). - Reviews: none. - Diff: with a null destination the value is read then dropped; a `vcc` that does not carry a lane mask loads `%vcc` and `%vcc_hi`. No game data. **Verdict: READY on tests; missing the `.asm` fixture the repo asks for a translator rule.** AI-assisted: Claude Code
aslan2142 commented 2026-12-01 11:43:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:43:12Z.

Review: CHANGES_REQUESTED


Reviewed the diff against main: the s_mov_b64 plain-data vcc (%vcc_hi) and null source/destination handling in tools/rdna2spirv.py:1845-1878 looks clean on its own, but CI is currently red across multiple jobs and independent testing noted a compare-path regression when applied without #1943's VCC-write fix. Please rebase/merge current main (and coordinate/include the VCC-write prerequisite if still needed) so CI passes cleanly.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130542348 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1983#pullrequestreview-6130542348). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:43:12Z. **Review:** CHANGES_REQUESTED --- Reviewed the diff against `main`: the `s_mov_b64` plain-data `vcc` (`%vcc_hi`) and `null` source/destination handling in `tools/rdna2spirv.py:1845-1878` looks clean on its own, but CI is currently red across multiple jobs and independent testing noted a compare-path regression when applied without `#1943`'s VCC-write fix. Please rebase/merge current `main` (and coordinate/include the VCC-write prerequisite if still needed) so CI passes cleanly. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:40:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:40:31Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318011653 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1983#issuecomment-7318011653). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:40:31Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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!1983
No description provided.