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

Open
github-bot wants to merge 1 commit from github-bot/gh-1977 into main AGit
Owner

@⁠ShotTechOp on GitHub · 2026-11-25 17:16 UTC · original
ShotTechOp:fix/wqm-data-vcc-and-dst → main · +240 −8 · 3 files · 1 commits · open

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.
**@⁠ShotTechOp** on GitHub · 2026-11-25 17:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1977) `ShotTechOp:fix/wqm-data-vcc-and-dst` → `main` · +240 −8 · 3 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:13:25 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1977/head:github-bot/gh-1977'
git switch 'github-bot/gh-1977'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1977'
git switch 'github-bot/gh-1977'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1977'
git switch 'github-bot/gh-1977'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1977'
git switch 'main'
git merge --squash 'github-bot/gh-1977'
git switch 'main'
git merge --ff-only 'github-bot/gh-1977'
git switch 'main'
git merge 'github-bot/gh-1977'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.