rdna2spirv: fix plain-data VCC source and non-mask destinations in Gen.wqm (SHADER-WQM-DATA-VCC-AND-DST) #1977

Merged
ShotTechOp merged 1 commit from upstream-pr/1977 into main 2026-11-29 00:12:38 +00:00
ShotTechOp commented 2026-11-25 17:16:08 +00:00 (Migrated from github.com)

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


Claimed in #1608 as SHADER-WQM-DATA-VCC-AND-DST.

What and why

On the plain-data path of Gen.wqm() (tools/rdna2spirv.py, when self.holds_lane_mask(a[1]) is False), four operand combinations were miscompiled:

  1. s_wqm_b64 with plain 64-bit scalar data in vcc: fell into words = [self.src_u(src), self.cu(0)], dropping %vcc_hi to 0 (so vcc = (0, 0x80000000) produced (0, 0) with SCC = 0 instead of (0, 0xF0000000) with SCC = 1).
  2. s_wqm_b32 m0, sS: m0 fell into the else: mask-extract branch and stored a single lane's 0/0xFFFFFFFF bit into %m0 instead of the 32-bit WQM result.
  3. s_wqm_b32/s_wqm_b64 into plain-data vcc/vcc_lo/vcc_hi (e.g. s_wqm_b32 vcc_lo, s4, s_wqm_b32 vcc_hi, s5, s_wqm_b64 vcc, s[4:5]): tools/lane_masks.py clears vcc's mask state on plain-data writes, so subsequent reads treat %vcc / %vcc_hi as plain 32/64-bit scalar words, yet Gen.wqm() stored a single lane's bit into %vcc and left %vcc_hi untouched.
  4. s_wqm_b32/s_wqm_b64 into null: unnecessarily fell into the else: branch, emitting wave_lane() + OpBitFieldUExtract + put_mask(null, ...) instead of discarding the result while updating SCC.

Also replaced the inline OpBitFieldUExtract in the remaining mask-destination branch (exec and mask-valued vcc) with self._scalar_word_lane_bit(word, lane) (consistent with mask_src and avoiding the Intel UHD 770 16-bit constant offset bug noted in docs/design.md).

Changes

  • tools/rdna2spirv.py:
    • Added _wqm_dst_is_lane_mask() (matching vcc_half_keeps_mask()'s lane_masks.step check) so Gen.wqm() distinguishes mask-valued destinations (exec*, s_wqm_b64 vcc, <imm>, and mask-preserving wave64 vcc half writes) from plain-data vcc/vcc_lo/vcc_hi.
    • Loaded both %vcc and %vcc_hi for s_wqm_b64 of plain-data vcc (and (0, 0) for null).
    • Handled null, m0, and plain-data vcc/vcc_lo/vcc_hi destinations directly, and routed mask-valued destinations through _scalar_word_lane_bit().
  • docs/design.md:
    • Documented the plain-data vcc source and non-mask destination behaviour in the Whole-quad mode (s_wqm_b64 / s_wqm_b32) contract row.
  • tests/semantic/test_wqm_data_vcc_and_dst.py:
    • Covers plain-data vcc and null sources on s_wqm_b64, m0 destinations (wave32 and wave64), plain-data vcc_lo/vcc_hi/vcc destinations (b32 and b64), null destination (verifying no SubgroupLocalInvocationId / OpGroupNonUniform emission), and lane-mask controls (s_wqm_b64 vcc, 0x10 and s_wqm_b64 exec, s[4:5]).

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_wqm_data_vcc_and_dst.py -v
    • python -m unittest discover -s tests/semantic -p test_salu_wqm32.py
    • python -m unittest discover -s tests/semantic -p test_salu_wqm_b32.py
    • python -m unittest discover -s tests/semantic -p test_wave64_halves_wqm_uvote.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_wqm_data_vcc_and_dst.py
    • python -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_wqm_data_vcc_and_dst.py
    • git diff --check
  • Negative control against origin/main (tools/rdna2spirv.py at fe15534): tests/semantic/test_wqm_data_vcc_and_dst.py fails on origin/main (FAILED (failures=10, errors=1)): test_wqm_b32_into_m0_stores_full_word errors (Unsupported), test_wqm_b64_reads_plain_vcc_both_words fails all 3 non-zero high-word cases (dropping %vcc_hi to 0), and test_wqm_into_plain_data_vcc_preserves_words fails all 7 non-zero cases (storing per-lane 0/0xFFFFFFFF bits into %vcc instead of the WQM words); the exec/vcc lane-mask control passes.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5495846571 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1977). Originally posted by [ShotTechOp](https://github.com/ShotTechOp) on 2026-11-25T17:16:08Z. --- Claimed in #1608 as `SHADER-WQM-DATA-VCC-AND-DST`. ### What and why On the plain-data path of `Gen.wqm()` (`tools/rdna2spirv.py`, when `self.holds_lane_mask(a[1])` is `False`), four operand combinations were miscompiled: 1. **`s_wqm_b64` with plain 64-bit scalar data in `vcc`**: fell into `words = [self.src_u(src), self.cu(0)]`, dropping `%vcc_hi` to `0` (so `vcc = (0, 0x80000000)` produced `(0, 0)` with `SCC = 0` instead of `(0, 0xF0000000)` with `SCC = 1`). 2. **`s_wqm_b32 m0, sS`**: `m0` fell into the `else:` mask-extract branch and stored a single lane's `0`/`0xFFFFFFFF` bit into `%m0` instead of the 32-bit WQM result. 3. **`s_wqm_b32`/`s_wqm_b64` into plain-data `vcc`/`vcc_lo`/`vcc_hi`** (e.g. `s_wqm_b32 vcc_lo, s4`, `s_wqm_b32 vcc_hi, s5`, `s_wqm_b64 vcc, s[4:5]`): `tools/lane_masks.py` clears `vcc`'s mask state on plain-data writes, so subsequent reads treat `%vcc` / `%vcc_hi` as plain 32/64-bit scalar words, yet `Gen.wqm()` stored a single lane's bit into `%vcc` and left `%vcc_hi` untouched. 4. **`s_wqm_b32`/`s_wqm_b64` into `null`**: unnecessarily fell into the `else:` branch, emitting `wave_lane()` + `OpBitFieldUExtract` + `put_mask(null, ...)` instead of discarding the result while updating `SCC`. Also replaced the inline `OpBitFieldUExtract` in the remaining mask-destination branch (`exec` and mask-valued `vcc`) with `self._scalar_word_lane_bit(word, lane)` (consistent with `mask_src` and avoiding the Intel UHD 770 16-bit constant offset bug noted in `docs/design.md`). ### Changes - **`tools/rdna2spirv.py`**: - Added `_wqm_dst_is_lane_mask()` (matching `vcc_half_keeps_mask()`'s `lane_masks.step` check) so `Gen.wqm()` distinguishes mask-valued destinations (`exec*`, `s_wqm_b64 vcc, <imm>`, and mask-preserving wave64 `vcc` half writes) from plain-data `vcc`/`vcc_lo`/`vcc_hi`. - Loaded both `%vcc` and `%vcc_hi` for `s_wqm_b64` of plain-data `vcc` (and `(0, 0)` for `null`). - Handled `null`, `m0`, and plain-data `vcc`/`vcc_lo`/`vcc_hi` destinations directly, and routed mask-valued destinations through `_scalar_word_lane_bit()`. - **`docs/design.md`**: - Documented the plain-data `vcc` source and non-mask destination behaviour in the `Whole-quad mode (s_wqm_b64 / s_wqm_b32)` contract row. - **`tests/semantic/test_wqm_data_vcc_and_dst.py`**: - Covers plain-data `vcc` and `null` sources on `s_wqm_b64`, `m0` destinations (wave32 and wave64), plain-data `vcc_lo`/`vcc_hi`/`vcc` destinations (`b32` and `b64`), `null` destination (verifying no `SubgroupLocalInvocationId` / `OpGroupNonUniform` emission), and lane-mask controls (`s_wqm_b64 vcc, 0x10` and `s_wqm_b64 exec, s[4:5]`). ### 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_wqm_data_vcc_and_dst.py -v` - `python -m unittest discover -s tests/semantic -p test_salu_wqm32.py` - `python -m unittest discover -s tests/semantic -p test_salu_wqm_b32.py` - `python -m unittest discover -s tests/semantic -p test_wave64_halves_wqm_uvote.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_wqm_data_vcc_and_dst.py` - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py docs/design.md tests/semantic/test_wqm_data_vcc_and_dst.py` - `git diff --check` - **Negative control against `origin/main` (`tools/rdna2spirv.py` at `fe15534`)**: `tests/semantic/test_wqm_data_vcc_and_dst.py` fails on `origin/main` (`FAILED (failures=10, errors=1)`): `test_wqm_b32_into_m0_stores_full_word` errors (`Unsupported`), `test_wqm_b64_reads_plain_vcc_both_words` fails all 3 non-zero high-word cases (dropping `%vcc_hi` to 0), and `test_wqm_into_plain_data_vcc_preserves_words` fails all 7 non-zero cases (storing per-lane `0`/`0xFFFFFFFF` bits into `%vcc` instead of the WQM words); the `exec`/`vcc` lane-mask control passes.
zmasi commented 2026-11-28 12:21:56 +00:00 (Migrated from github.com)

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


Verified on physical gfx906, native subgroup 64 (RADV Mesa 26.0.8), with synchronization validation enabled. Same seven synthetic shaders and six input patterns on main d48a957bb and 3c4b6fb70 merged with it. With only bit 31 set in the high VCC word, main returned a zero high word and cleared SCC; the merge set exactly the top four bits and set SCC. Both builds preserved the source words.

Main matched 15/36 dispatched readbacks and returned 3,132 wrong words. It separately refused the M0-destination shader before dispatch. The merge matched 42/42 readbacks, including plain VCC sources and destinations, M0, null/SCC, and mask-to-data-to-mask transitions. The six mask controls returned byte-identical data on both builds. All guards stayed intact; no shader-run validation errors or synchronization hazards.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239176422 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1977#issuecomment-7239176422). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:21:56Z. --- Verified on physical gfx906, native subgroup 64 (RADV Mesa 26.0.8), with synchronization validation enabled. Same seven synthetic shaders and six input patterns on main `d48a957bb` and `3c4b6fb70` merged with it. With only bit 31 set in the high VCC word, main returned a zero high word and cleared SCC; the merge set exactly the top four bits and set SCC. Both builds preserved the source words. Main matched 15/36 dispatched readbacks and returned 3,132 wrong words. It separately refused the M0-destination shader before dispatch. The merge matched 42/42 readbacks, including plain VCC sources and destinations, M0, null/SCC, and mask-to-data-to-mask transitions. The six mask controls returned byte-identical data on both builds. All guards stayed intact; no shader-run validation errors or synchronization hazards. AI-assisted.
TheGeogeo commented 2026-11-29 00:00:30 +00:00 (Migrated from github.com)

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


Tested 3c4b6fb70 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_wqm_data_vcc_and_dst.py, 5 tests pass.
  • Red: with tools/rdna2spirv.py back to main, 10 failures and 1 error (e.g. [4294967295, 0, 1, 4294967295, 0] != [0, 4026531840, 1, 0, 4026531840]).

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:7247807937 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1977#issuecomment-7247807937). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T00:00:30Z. --- Tested `3c4b6fb70` 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_wqm_data_vcc_and_dst.py`, 5 tests pass. - Red: with `tools/rdna2spirv.py` back to `main`, 10 failures and 1 error (e.g. `[4294967295, 0, 1, 4294967295, 0] != [0, 4026531840, 1, 0, 4026531840]`). 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:12:41 +00:00 (Migrated from github.com)

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


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