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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1977
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/wqm-data-vcc-and-dst


📝 Commits (1)

  • 3c4b6fb rdna2spirv: fix plain-data VCC source and non-mask destinations in Gen.wqm

📊 Changes

3 files changed (+240 additions, -8 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/semantic/test_wqm_data_vcc_and_dst.py (+198 -0)
📝 tools/rdna2spirv.py (+41 -7)

📄 Description

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.

🔄 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/1977 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/wqm-data-vcc-and-dst` --- ### 📝 Commits (1) - [`3c4b6fb`](https://github.com/ubiquitarianism/leonida/commit/3c4b6fb707b0cec00c717a49b519ab92c77b531c) rdna2spirv: fix plain-data VCC source and non-mask destinations in Gen.wqm ### 📊 Changes **3 files changed** (+240 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/semantic/test_wqm_data_vcc_and_dst.py` (+198 -0) 📝 `tools/rdna2spirv.py` (+41 -7) </details> ### 📄 Description 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. --- <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#1985
No description provided.