rdna2spirv, lane_masks: handle lane-mask destinations and sources in s_bitset0/1_b32 (SHADER-BITSET32-MASK-AND-DST) #2355

Merged
ShotTechOp merged 1 commit from upstream-pr/2355 into main 2026-12-01 15:19:58 +00:00
ShotTechOp commented 2026-11-26 15:06:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ShotTechOp on 2026-11-26T15:06:03Z.


Item: SHADER-BITSET32-MASK-AND-DST

Problem

In tools/rdna2spirv.py, s_bitset0_b32 and s_bitset1_b32 always applied old & ~(1 << (b & 31)) / old | (1 << (b & 31)) directly to self.src_u(a[0]) and wrote back via self.dst(a[0], r), while tools/lane_masks.py dropped mask tracking for a[0] on both opcodes:

  1. When a[0] holds a lane mask (vcc_lo/vcc_hi holding a mask, or a mask SGPR tracked by lane_masks.py), each invocation holds only its own lane's bit (0 or 0xFFFFFFFF), so ORing 1 << k turned every inactive lane non-zero (activating all 32 lanes) and ANDing ~(1 << k) left the targeted lane non-zero (0xFFFFFFDF etc.).
  2. In tools/lane_masks.py, mutating a lane mask with s_bitset0/1_b32 dropped a[0] from state, causing downstream mask consumers (s_bcnt1_i32_b32, s_ff1_i32_b32, s_bcnt1_i32_b64, etc.) to read per-lane 0/0xFFFFFFFF as scalar data instead of collecting the wave mask.
  3. When the bit-index source a[1] holds a lane mask (e.g. s_bitset1_b32 s10, vcc_lo), self.src_u(a[1]) read each lane's 0/0xFFFFFFFF instead of the wave's 32-bit mask word, producing divergent per-lane shifts (bit 0 vs bit 31).

Fix

  • tools/lane_masks.py: Preserve MASK / MASK_LO / MASK_HI (and wave64 vcc mask status for vcc_lo/vcc_hi) when s_bitset0_b32 or s_bitset1_b32 mutates an existing lane mask; clear tracking to plain data when mutating non-mask or EITHER constants.
  • tools/rdna2spirv.py: Merge s_bitset0_b32 and s_bitset1_b32 into one handler. Materialize a lane-mask bit-index source via Gen.lane_mask_word. When self.holds_lane_mask(a[0]), compare wave_lane() against (b & 31) (or (b & 31) + 32 for a wave64 high half) and update only the addressed lane via Gen.put_mask (keeping the untouched half of EXEC/VCC in wave64 and updating %vcc_hi when a[0] is vcc_hi).
  • docs/design.md: Document the s_bitset0_b32/s_bitset1_b32 lane-mask contract row.
  • tests/semantic/test_bitset32_mask.py (and updated tests/semantic/test_scalar_alu_imm_bitset.py comment/loop): Add wave32, wave64, and --wave64-emulate tests for EXEC, VCC, mask SGPRs, and lane-mask bit-index sources.

Verification

AI-assisted: yes.
Environment: Windows 11, Python 3.12.10, CPU-only (no game files, no spirv-val, not GPU-verified).

  • GREEN (branch):
    • python -I tests/semantic/test_bitset32_mask.py -v -> 8/8 OK (wave32, wave64 native, --wave64-emulate)
    • python -I tests/semantic/test_scalar_alu_imm_bitset.py -> 17/17 OK
    • python -I tests/semantic/test_salu_bitset_b64.py -> 5/5 OK
    • python -I tests/semantic/test_salu_b32_lane_masks.py -> 8/8 OK (1 skipped: spirv-val absent)
    • python -I tests/test_lane_masks.py -> OK
    • python -I tests/test_text_write_line_endings.py -> 3/3 OK
    • python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_bitset32_mask.py tests/semantic/test_scalar_alu_imm_bitset.py -> 0
    • python -I scripts/check_no_game_data.py ... -> 0
    • git diff --check -> 0
  • RED control (origin/main fbf100b1):
    • Running tests/semantic/test_bitset32_mask.py against origin/main's tools/ fails 6/8 assertions (test_wave32_vcc_lo_and_mask_sgpr_bitset, test_wave64_vcc_and_mask_sgpr_halves_bitset native & emulate, test_lane_mask_bit_index_source_uses_wave_mask_word, and both LaneMasksBitset32Tests preservation checks).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5512451550 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355). Originally posted by [ShotTechOp](https://github.com/ShotTechOp) on 2026-11-26T15:06:03Z. --- Item: `SHADER-BITSET32-MASK-AND-DST` ### Problem In `tools/rdna2spirv.py`, `s_bitset0_b32` and `s_bitset1_b32` always applied `old & ~(1 << (b & 31))` / `old | (1 << (b & 31))` directly to `self.src_u(a[0])` and wrote back via `self.dst(a[0], r)`, while `tools/lane_masks.py` dropped mask tracking for `a[0]` on both opcodes: 1. When `a[0]` holds a lane mask (`vcc_lo`/`vcc_hi` holding a mask, or a mask SGPR tracked by `lane_masks.py`), each invocation holds only its own lane's bit (`0` or `0xFFFFFFFF`), so ORing `1 << k` turned every inactive lane non-zero (activating all 32 lanes) and ANDing `~(1 << k)` left the targeted lane non-zero (`0xFFFFFFDF` etc.). 2. In `tools/lane_masks.py`, mutating a lane mask with `s_bitset0/1_b32` dropped `a[0]` from `state`, causing downstream mask consumers (`s_bcnt1_i32_b32`, `s_ff1_i32_b32`, `s_bcnt1_i32_b64`, etc.) to read per-lane `0`/`0xFFFFFFFF` as scalar data instead of collecting the wave mask. 3. When the bit-index source `a[1]` holds a lane mask (e.g. `s_bitset1_b32 s10, vcc_lo`), `self.src_u(a[1])` read each lane's `0`/`0xFFFFFFFF` instead of the wave's 32-bit mask word, producing divergent per-lane shifts (bit 0 vs bit 31). ### Fix - **`tools/lane_masks.py`**: Preserve `MASK` / `MASK_LO` / `MASK_HI` (and wave64 `vcc` mask status for `vcc_lo`/`vcc_hi`) when `s_bitset0_b32` or `s_bitset1_b32` mutates an existing lane mask; clear tracking to plain data when mutating non-mask or `EITHER` constants. - **`tools/rdna2spirv.py`**: Merge `s_bitset0_b32` and `s_bitset1_b32` into one handler. Materialize a lane-mask bit-index source via `Gen.lane_mask_word`. When `self.holds_lane_mask(a[0])`, compare `wave_lane()` against `(b & 31)` (or `(b & 31) + 32` for a wave64 high half) and update only the addressed lane via `Gen.put_mask` (keeping the untouched half of EXEC/VCC in wave64 and updating `%vcc_hi` when `a[0]` is `vcc_hi`). - **`docs/design.md`**: Document the `s_bitset0_b32`/`s_bitset1_b32` lane-mask contract row. - **`tests/semantic/test_bitset32_mask.py`** (and updated `tests/semantic/test_scalar_alu_imm_bitset.py` comment/loop): Add wave32, wave64, and `--wave64-emulate` tests for EXEC, VCC, mask SGPRs, and lane-mask bit-index sources. ### Verification AI-assisted: yes. Environment: Windows 11, Python 3.12.10, CPU-only (no game files, no `spirv-val`, not GPU-verified). - **GREEN (branch)**: - `python -I tests/semantic/test_bitset32_mask.py -v` -> 8/8 OK (wave32, wave64 native, `--wave64-emulate`) - `python -I tests/semantic/test_scalar_alu_imm_bitset.py` -> 17/17 OK - `python -I tests/semantic/test_salu_bitset_b64.py` -> 5/5 OK - `python -I tests/semantic/test_salu_b32_lane_masks.py` -> 8/8 OK (1 skipped: `spirv-val` absent) - `python -I tests/test_lane_masks.py` -> OK - `python -I tests/test_text_write_line_endings.py` -> 3/3 OK - `python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_bitset32_mask.py tests/semantic/test_scalar_alu_imm_bitset.py` -> 0 - `python -I scripts/check_no_game_data.py ...` -> 0 - `git diff --check` -> 0 - **RED control (`origin/main` `fbf100b1`)**: - Running `tests/semantic/test_bitset32_mask.py` against `origin/main`'s `tools/` fails 6/8 assertions (`test_wave32_vcc_lo_and_mask_sgpr_bitset`, `test_wave64_vcc_and_mask_sgpr_halves_bitset` native & emulate, `test_lane_mask_bit_index_source_uses_wave_mask_word`, and both `LaneMasksBitset32Tests` preservation checks).
ecox982745 commented 2026-11-26 15:19:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-26T15:19:52Z.


The bit-set fix passed all 66 synthetic GPU dispatches on an RTX 4090 at 69726d1ce. The same inputs matched the CPU reference in 23 of 66 dispatches on parent fbf100b1b.

Compute mode Parent PR
Native wave32 9/21 21/21
Wave64 emulated on 32-lane subgroups 14/45 45/45

One case exposes the bug with a single active lane. Lane 0 sets VCC bit 0, then s_mov_b32 s10, vcc_lo saves the word 1. After s_bitset1_b32 s10, s10, the word should be 3 and its population count should be 2 in every lane. The parent returned 32 in lane 0 and 1 in lane 1. The PR returned 2 in all 32 lanes. The corresponding saved-high-half cases also passed in wave64 emulation.

The remaining probes covered setting and clearing EXEC and VCC bits, using either VCC half as the bit-index source, wrapped indices including 32 and 63, and ordinary scalar controls. I checked every output word and the untouched tail of each buffer. All 13 PR modules passed spirv-val --target-env vulkan1.2. The eight committed CPU tests also passed.

Windows 11, NVIDIA 616.64, Vulkan validation enabled, synthetic shader listings. AI-assisted verification by OpenAI Codex (GPT-6).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7196113305 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2355#issuecomment-7196113305). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-11-26T15:19:52Z. --- The bit-set fix passed all 66 synthetic GPU dispatches on an RTX 4090 at `69726d1ce`. The same inputs matched the CPU reference in 23 of 66 dispatches on parent `fbf100b1b`. | Compute mode | Parent | PR | | --- | ---: | ---: | | Native wave32 | 9/21 | 21/21 | | Wave64 emulated on 32-lane subgroups | 14/45 | 45/45 | One case exposes the bug with a single active lane. Lane 0 sets VCC bit 0, then `s_mov_b32 s10, vcc_lo` saves the word `1`. After `s_bitset1_b32 s10, s10`, the word should be `3` and its population count should be `2` in every lane. The parent returned `32` in lane 0 and `1` in lane 1. The PR returned `2` in all 32 lanes. The corresponding saved-high-half cases also passed in wave64 emulation. The remaining probes covered setting and clearing EXEC and VCC bits, using either VCC half as the bit-index source, wrapped indices including 32 and 63, and ordinary scalar controls. I checked every output word and the untouched tail of each buffer. All 13 PR modules passed `spirv-val --target-env vulkan1.2`. The eight committed CPU tests also passed. Windows 11, NVIDIA 616.64, Vulkan validation enabled, synthetic shader listings. AI-assisted verification by OpenAI Codex (GPT-6).
lixonik commented 2026-11-26 15:37:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:37:20Z.

Review: COMMENTED


Windows 11: 30/30 bitset semantic tests passed, including tracked lane-mask operands and the immediate-bitset cases. No findings.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6076878768 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#pullrequestreview-6076878768). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T15:37:20Z. **Review:** COMMENTED --- Windows 11: 30/30 bitset semantic tests passed, including tracked lane-mask operands and the immediate-bitset cases. No findings. AI-assisted.
wavehs commented 2026-11-26 18:26:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:26:55Z.

Review: COMMENTED


macOS arm64 check of #2355 (SHADER-BITSET32-MASK-AND-DST). Translator plus lane_masks.py and one semantic test; the GPU part is MoltenVK/Kosmickrisp.

Tested head 69726d1ce merged onto main bdbc7e923 as merge b56572d3e (clean; branch 21 commits behind, git merge-tree clean).

Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0.

The new test passes, and the control bites

  • python -I tests/semantic/test_bitset32_mask.py: Ran 8 tests ... OK at the head and after merging onto bdbc7e923; the updated tests/semantic/test_scalar_alu_imm_bitset.py still passes.
  • Negative control (test kept, tools/rdna2spirv.py and tools/lane_masks.py put back to main's): FAILED (failures=6) - mask bit-index source, wave32 vcc_lo + mask SGPR, wave64 VCC/SGPR halves in native and --wave64-emulate, and the two lane_masks checks that a mask kind survives. So both the emission and the tracking are pinned.

What I checked in the code

  • The mask path updates only the addressed lane: hit = (SubgroupLocalInvocationId == (S0 & 31) [+32 for a wave64 high half]), then put_mask writes 0 / ~0 or keeps the old per-lane bit. The untouched half of a wave64 EXEC/VCC is preserved, and SCC is not written, which matches the row and the ISA. The non-mask path keeps the old bit math, and s_bitset0_b32 now shares it with s_bitset1_b32 instead of a separate block.
  • The lane_masks.step addition keeps a mask kind on a mask destination and drops it to data otherwise.
  • Nit, not a failure: for a wave64 vcc_lo/vcc_hi write when state["vcc"] is a full MASK, step returns without changing the kind. Native reads go through the live %vcc/%vcc_hi, and the new wave64 test reads the result through s_bcnt1_i32_b64 vcc in both native and --wave64-emulate and passes, so I could not make it stale; a one-line comment saying why the full-mask kind is kept would save the next reader the same detour.

No regressions

  • Semantic suite: 500 files / 6,367 tests / 0 failed at main bdbc7e923; 501 files / 6,375 tests / 0 failed at the merge (+1 file, +8 tests).
  • GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, identical at main and the merge after normalising the per-run temp directory; same pre-existing failures (cs_fma_fused, cs_imgatomic_ext, ps_ssharp on MV; cs_bvh, cs_bvh32, cs_imgatomic_ext, ps_cndmask_sign_mods, ps_valu16_mad_sel on KK).

Finding
The mask-destination path has no GPU fixture. cs_w32_salu_ext.asm is the only fixture with s_bitset0/1_b32, and it runs them on plain SGPRs (s65, s66); cs_w32_salu64.asm has the _b64 form on scalar pairs. Nothing on a GPU writes a lane mask (exec_lo, vcc_lo/vcc_hi, a mask SGPR) with s_bitset and then counts the mask, so the put_mask/wave_lane half logic rests on the interpreter, which the doc row already says ("not GPU-verified"). Adding four stores to an existing cs_w32_* fixture (mask before, bitset, s_bcnt1, store) would cover it on any GPU, and would catch a wrong half split in wave64 the way cs_w64x_partial_scmp.asm does for compares.

python -I scripts/check_no_game_data.py on the changed files: clean. git diff --check: clean.

No game files. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6078969877 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#pullrequestreview-6078969877). Originally posted by [wavehs](https://github.com/wavehs) on 2026-11-26T18:26:55Z. **Review:** COMMENTED --- **macOS arm64 check of #2355** (SHADER-BITSET32-MASK-AND-DST). Translator plus `lane_masks.py` and one semantic test; the GPU part is MoltenVK/Kosmickrisp. Tested head `69726d1ce` merged onto `main` `bdbc7e923` as merge `b56572d3e` (clean; branch 21 commits behind, `git merge-tree` clean). Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0. **The new test passes, and the control bites** - `python -I tests/semantic/test_bitset32_mask.py`: `Ran 8 tests ... OK` at the head and after merging onto `bdbc7e923`; the updated `tests/semantic/test_scalar_alu_imm_bitset.py` still passes. - Negative control (test kept, `tools/rdna2spirv.py` and `tools/lane_masks.py` put back to `main`'s): `FAILED (failures=6)` - mask bit-index source, wave32 `vcc_lo` + mask SGPR, wave64 VCC/SGPR halves in native and `--wave64-emulate`, and the two `lane_masks` checks that a mask kind survives. So both the emission and the tracking are pinned. **What I checked in the code** - The mask path updates only the addressed lane: `hit = (SubgroupLocalInvocationId == (S0 & 31) [+32 for a wave64 high half])`, then `put_mask` writes 0 / ~0 or keeps the old per-lane bit. The untouched half of a wave64 EXEC/VCC is preserved, and SCC is not written, which matches the row and the ISA. The non-mask path keeps the old bit math, and `s_bitset0_b32` now shares it with `s_bitset1_b32` instead of a separate block. - The `lane_masks.step` addition keeps a mask kind on a mask destination and drops it to data otherwise. - Nit, not a failure: for a wave64 `vcc_lo`/`vcc_hi` write when `state["vcc"]` is a full `MASK`, `step` returns without changing the kind. Native reads go through the live `%vcc`/`%vcc_hi`, and the new wave64 test reads the result through `s_bcnt1_i32_b64 vcc` in both native and `--wave64-emulate` and passes, so I could not make it stale; a one-line comment saying why the full-mask kind is kept would save the next reader the same detour. **No regressions** - Semantic suite: 500 files / 6,367 tests / 0 failed at `main` `bdbc7e923`; 501 files / 6,375 tests / 0 failed at the merge (+1 file, +8 tests). - GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, identical at `main` and the merge after normalising the per-run temp directory; same pre-existing failures (`cs_fma_fused`, `cs_imgatomic_ext`, `ps_ssharp` on MV; `cs_bvh`, `cs_bvh32`, `cs_imgatomic_ext`, `ps_cndmask_sign_mods`, `ps_valu16_mad_sel` on KK). **Finding** The mask-destination path has no GPU fixture. `cs_w32_salu_ext.asm` is the only fixture with `s_bitset0/1_b32`, and it runs them on plain SGPRs (`s65`, `s66`); `cs_w32_salu64.asm` has the `_b64` form on scalar pairs. Nothing on a GPU writes a lane mask (`exec_lo`, `vcc_lo`/`vcc_hi`, a mask SGPR) with `s_bitset` and then counts the mask, so the `put_mask`/`wave_lane` half logic rests on the interpreter, which the doc row already says ("not GPU-verified"). Adding four stores to an existing `cs_w32_*` fixture (mask before, bitset, `s_bcnt1`, store) would cover it on any GPU, and would catch a wrong half split in wave64 the way `cs_w64x_partial_scmp.asm` does for compares. `python -I scripts/check_no_game_data.py` on the changed files: clean. `git diff --check`: clean. No game files. AI-assisted.
tiguan26 commented 2026-11-27 04:46:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:46:24Z.

Review: APPROVED


Approving 69726d1ce.

s_bitset0/1_b32 on a lane mask now follows the translator's mask model: a lane holds only its own bit, so setting or clearing bit n changes lane n's value alone (n + 32 for the high half in wave64), and the destination stays a tracked mask in lane_masks.step instead of being dropped to data. On plain data the two ops keep their shift-and-or/and-not form, now in one branch. The updated test_scalar_alu_imm_bitset.py case follows from that: these ops no longer clear mask tracking.

test_bitset32_mask.py 8 passed (4 subtests), test_scalar_alu_imm_bitset.py 17 passed (265 subtests). Merged onto main d1dff7949 together with #2397, #2416 and the other three of this series below (no conflicts), on Linux with Python 3.13. The full translator suite (run_semantic_tests.py tests/semantic) on that tree has only the 8 failures main has here (7 in test_fspx_dot4_op_sel_disasm, test_int32_to_f64), and tests/test_translate.py only main's own ps_sdwa_f16_const.asm (an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083599580 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#pullrequestreview-6083599580). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:46:24Z. **Review:** APPROVED --- Approving 69726d1ce. `s_bitset0/1_b32` on a lane mask now follows the translator's mask model: a lane holds only its own bit, so setting or clearing bit n changes lane n's value alone (n + 32 for the high half in wave64), and the destination stays a tracked mask in `lane_masks.step` instead of being dropped to data. On plain data the two ops keep their shift-and-or/and-not form, now in one branch. The updated `test_scalar_alu_imm_bitset.py` case follows from that: these ops no longer clear mask tracking. `test_bitset32_mask.py` 8 passed (4 subtests), `test_scalar_alu_imm_bitset.py` 17 passed (265 subtests). Merged onto `main` `d1dff7949` together with #2397, #2416 and the other three of this series below (no conflicts), on Linux with Python 3.13. The full translator suite (`run_semantic_tests.py tests/semantic`) on that tree has only the 8 failures `main` has here (7 in `test_fspx_dot4_op_sel_disasm`, `test_int32_to_f64`), and `tests/test_translate.py` only `main`'s own `ps_sdwa_f16_const.asm` (an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).
Tauwni commented 2026-11-27 15:37:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-27T15:37:02Z.


Tested 69726d1ce merged onto main ec91d695c on a Mac (profile S), where wave64 is always emulated on 32-wide subgroups: Apple M3, macOS 26.5.1, MoltenVK 1.4.2, KosmicKrisp and llvmpipe (Mesa 26.3.1). No game files.

scripts/run_gpu_tests.py, auto mode, test programs from main:

Driver main main + this PR
MoltenVK 196/269 196/269
MoltenVK, LEONIDA_W64_EMULATE=1 230/269 230/269
KosmicKrisp 191/269 191/269
llvmpipe 177/269 177/269

The failures are the same on both sides (the known ones: #1724, #1518 and #1774 on MoltenVK, #2229's on KosmicKrisp). The translator suite passes with no failures.

Evidence: MEASURED, 1 run each. This only shows that nothing changes on Apple drivers. It says nothing about the game.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7222274900 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2355#issuecomment-7222274900). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-27T15:37:02Z. --- Tested `69726d1ce` merged onto `main` `ec91d695c` on a Mac (profile S), where wave64 is always emulated on 32-wide subgroups: Apple M3, macOS 26.5.1, MoltenVK 1.4.2, KosmicKrisp and llvmpipe (Mesa 26.3.1). No game files. `scripts/run_gpu_tests.py`, auto mode, test programs from `main`: | Driver | `main` | `main` + this PR | |---|---|---| | MoltenVK | 196/269 | 196/269 | | MoltenVK, `LEONIDA_W64_EMULATE=1` | 230/269 | 230/269 | | KosmicKrisp | 191/269 | 191/269 | | llvmpipe | 177/269 | 177/269 | The failures are the same on both sides (the known ones: #1724, #1518 and #1774 on MoltenVK, #2229's on KosmicKrisp). The translator suite passes with no failures. Evidence: MEASURED, 1 run each. This only shows that nothing changes on Apple drivers. It says nothing about the game. AI-assisted (Claude Code, Claude Opus 5.5).
timbot103 commented 2026-11-28 03:21:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T03:21:01Z.

Review: CHANGES_REQUESTED


Verified head 69726d1ce on Windows 11 (semantic suites + dual-GPU control + live translation repros).

The straight-line mask destination/source handling passes its semantic suites (test_bitset32_mask.py 8/8, test_scalar_alu_imm_bitset.py 17/17, test_salu_bitset_b64.py 5/5, test_wave64_emulate_barriers.py 13/13) and cs_w32_salu_ext passes on both RTX 5080 and AMD Radeon.

Blocking finding — missing wave64_emulate_opt.py mask-reader classification causes translation crashes under --wave64-emulate:
s_bitset0_b32 / s_bitset1_b32 now call lane_mask_word for a tracked bit-index operand (including exec_lo and tracked mask SGPRs; tools/rdna2spirv.py:9287-9293), which under --wave64-emulate can invoke x_round and emit a workgroup barrier. However, tools/wave64_emulate_opt.py does not classify s_bitset0_b32 / s_bitset1_b32 as operand-1 mask readers (unlike s_flbit_* at tools/wave64_emulate_opt.py:81-86, 326-335, 1232-1247, 1469-1493). As a result, both the local execz fold and the sync-free multi-wave planner admit blocks containing that exchange, tripping hard translation assertions inside _translate:

  1. 64-thread s_cbranch_execz guard (v_cmp_lt_u32_e64 lanes 0..15 -> s_and_saveexec_b64 -> s_cbranch_execz -> s_bitset1_b32 s14, exec_lo):
    • Live repro on 69726d1ce:
      AssertionError: wave64 emulation: x_split inside a folded lane-local region (tools/rdna2spirv.py:18985).
  2. 128-thread divergent s_cbranch_scc0 guard (v_cmp_eq_u32_e64 s[6:7], v0, 5, wave-0-only branch executing s_bitset1_b32 s14, s6):
    • Live repro on 69726d1ce:
      AssertionError: wave64 emulation: unexpected OpControlBarrier in sync-free multi-wave block (tools/rdna2spirv.py:19100).

Requested fix: Register s_bitset0_b32 and s_bitset1_b32 alongside s_flbit_* for operand-1 mask-reader detection in tools/wave64_emulate_opt.py, and add both guarded --wave64-emulate regressions (single-wave execz fold + 128-thread multi-wave divergent branch).

No game data used. AI-assisted review (Codex static audit + Gemini live verification).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6095401391 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#pullrequestreview-6095401391). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T03:21:01Z. **Review:** CHANGES_REQUESTED --- Verified head `69726d1ce` on Windows 11 (semantic suites + dual-GPU control + live translation repros). The straight-line mask destination/source handling passes its semantic suites (`test_bitset32_mask.py` 8/8, `test_scalar_alu_imm_bitset.py` 17/17, `test_salu_bitset_b64.py` 5/5, `test_wave64_emulate_barriers.py` 13/13) and `cs_w32_salu_ext` passes on both RTX 5080 and AMD Radeon. **Blocking finding — missing `wave64_emulate_opt.py` mask-reader classification causes translation crashes under `--wave64-emulate`:** `s_bitset0_b32` / `s_bitset1_b32` now call `lane_mask_word` for a tracked bit-index operand (including `exec_lo` and tracked mask SGPRs; `tools/rdna2spirv.py:9287-9293`), which under `--wave64-emulate` can invoke `x_round` and emit a workgroup barrier. However, `tools/wave64_emulate_opt.py` does not classify `s_bitset0_b32` / `s_bitset1_b32` as operand-1 mask readers (unlike `s_flbit_*` at `tools/wave64_emulate_opt.py:81-86, 326-335, 1232-1247, 1469-1493`). As a result, both the local `execz` fold and the sync-free multi-wave planner admit blocks containing that exchange, tripping hard translation assertions inside `_translate`: 1. **64-thread `s_cbranch_execz` guard** (`v_cmp_lt_u32_e64` lanes 0..15 -> `s_and_saveexec_b64` -> `s_cbranch_execz` -> `s_bitset1_b32 s14, exec_lo`): - Live repro on `69726d1ce`: `AssertionError: wave64 emulation: x_split inside a folded lane-local region` (`tools/rdna2spirv.py:18985`). 2. **128-thread divergent `s_cbranch_scc0` guard** (`v_cmp_eq_u32_e64 s[6:7], v0, 5`, wave-0-only branch executing `s_bitset1_b32 s14, s6`): - Live repro on `69726d1ce`: `AssertionError: wave64 emulation: unexpected OpControlBarrier in sync-free multi-wave block` (`tools/rdna2spirv.py:19100`). **Requested fix:** Register `s_bitset0_b32` and `s_bitset1_b32` alongside `s_flbit_*` for operand-1 mask-reader detection in `tools/wave64_emulate_opt.py`, and add both guarded `--wave64-emulate` regressions (single-wave `execz` fold + 128-thread multi-wave divergent branch). No game data used. AI-assisted review (Codex static audit + Gemini live verification).
sodove commented 2026-11-28 09:15:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T09:15:40Z.


#2355 | head 69726d1ceca0b8579023c6aaf7bab95ed29891b0 | python3 -I tests/semantic/test_bitset32_mask.py -v, python3 -I tests/semantic/test_scalar_alu_imm_bitset.py -v | red: 25 tests, 6 assertion failures | green: 25 passed | Red → green

The added lane-mask cases failed on main while the pre-existing scalar bitset tests passed on both sides.

Pinned main 4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237122928 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#issuecomment-7237122928). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T09:15:40Z. --- #2355 | head `69726d1ceca0b8579023c6aaf7bab95ed29891b0` | `python3 -I tests/semantic/test_bitset32_mask.py -v`, `python3 -I tests/semantic/test_scalar_alu_imm_bitset.py -v` | red: 25 tests, 6 assertion failures | green: 25 passed | **Red → green** The added lane-mask cases failed on main while the pre-existing scalar bitset tests passed on both sides. Pinned main `4938673668d807bf365b61284bf22b1ff8d02cc4`, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7236982945).
zmasi commented 2026-11-28 11:18:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:18:22Z.


VERIFY-2355-VEGA20-RADV: five synthetic compute fixtures, same inputs and independent per-lane integer reference on 2d4735682 and on its merge with 69726d1ce. Both sets of modules dispatched on physical gfx906 / RADV Mesa 26.0.8, native subgroup 64. Main returned 685 wrong words out of 1,920; the merge returned 0/1,920 wrong.

Case Main wrong / checked Merge wrong / checked
VCC bit set/clear 298/448 0/448
Mask held in scalar registers 128/448 0/448
Mask used as the bit index 259/384 0/384
Ordinary scalar controls and EXEC cases 0/640 0/640

No unwritten results or changed guard words; zero Khronos validation errors or synchronization hazards. The PR’s eight targeted semantic tests and 17 adjacent scalar tests passed on the merge. The native evidence is for fixed wave64, not wave32 emulation.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238463965 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#issuecomment-7238463965). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:18:22Z. --- `VERIFY-2355-VEGA20-RADV`: five synthetic compute fixtures, same inputs and independent per-lane integer reference on `2d4735682` and on its merge with `69726d1ce`. Both sets of modules dispatched on physical gfx906 / RADV Mesa 26.0.8, native subgroup **64**. Main returned **685 wrong words out of 1,920**; the merge returned **0/1,920 wrong**. | Case | Main wrong / checked | Merge wrong / checked | |---|---:|---:| | VCC bit set/clear | 298/448 | 0/448 | | Mask held in scalar registers | 128/448 | 0/448 | | Mask used as the bit index | 259/384 | 0/384 | | Ordinary scalar controls and EXEC cases | 0/640 | 0/640 | No unwritten results or changed guard words; zero Khronos validation errors or synchronization hazards. The PR’s eight targeted semantic tests and 17 adjacent scalar tests passed on the merge. The native evidence is for fixed wave64, not wave32 emulation. AI-assisted.
OreoFR commented 2026-11-29 19:49:16 +00:00 (Migrated from github.com)

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


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 69726d1ce : green 8 OK, 0 skipped — but an open CHANGES_REQUESTED

  • Red: test_bitset32_mask.py 2/8, 6 failures. Green: 8/8, 0 skipped. test_scalar_alu_imm_bitset.py 17/17 on both sides (not discriminating).
  • 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: a docs/design.md row is added; no .asm fixture.
  • Blocking review: timbot103 CHANGES_REQUESTED (28/11, on this head, after the last commit): tools/wave64_emulate_opt.py does not classify s_bitset0/1_b32 as mask readers on operand 1, giving two AssertionErrors under --wave64-emulate ("x_split inside a folded lane-local region", "unexpected OpControlBarrier"); fix + two regression tests requested. Not addressed yet (I did not reproduce that case).
  • Diff: on a lane mask the update goes through Gen.put_mask and the index source through lane_mask_word. No game data.

Verdict: not mergeable until the CHANGES_REQUESTED is addressed (local tests all green).

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7261582191 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#issuecomment-7261582191). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T19:49:16Z. --- 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 69726d1ce : green 8 OK, 0 skipped — but an open CHANGES_REQUESTED - **Red**: `test_bitset32_mask.py` 2/8, 6 failures. **Green**: 8/8, 0 skipped. `test_scalar_alu_imm_bitset.py` 17/17 on both sides (not discriminating). - 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: a `docs/design.md` row is added; **no `.asm` fixture**. - **Blocking review**: timbot103 CHANGES_REQUESTED (28/11, on this head, after the last commit): `tools/wave64_emulate_opt.py` does not classify `s_bitset0/1_b32` as mask readers on operand 1, giving two AssertionErrors under `--wave64-emulate` ("x_split inside a folded lane-local region", "unexpected OpControlBarrier"); fix + two regression tests requested. Not addressed yet (I did not reproduce that case). - Diff: on a lane mask the update goes through `Gen.put_mask` and the index source through `lane_mask_word`. No game data. **Verdict: not mergeable until the CHANGES_REQUESTED is addressed** (local tests all green). AI-assisted: Claude Code
KelboLive commented 2026-11-30 17:36:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T17:36:23Z.


Independent check on Windows (not the author), at 69726d1ce.

  • tests/semantic/test_bitset32_mask.py: 8 tests OK
  • tests/semantic/test_scalar_alu_imm_bitset.py: 17 tests OK

Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8.

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7286569781 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#issuecomment-7286569781). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T17:36:23Z. --- Independent check on Windows (not the author), at `69726d1ce`. - `tests/semantic/test_bitset32_mask.py`: **8 tests OK** - `tests/semantic/test_scalar_alu_imm_bitset.py`: **17 tests OK** Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8. AI-assisted: yes (opencode).
kurrutako commented 2026-12-01 10:46:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kurrutako on 2026-12-01T10:46:56Z.


Tested locally on Windows 11 with Python 3.14 and SPIRV-Tools from Vulkan SDK 1.4.363.

On the PR head

  • tests/semantic/test_bitset32_mask.py: 8/8 pass on 69726d1.
  • On main cd73dda with only that test file copied in: 6 failures across 5 tests, so the test catches the bug.

Merged into current main locally

  • scripts/run_semantic_tests.py tests/semantic: 554 files, 0 failed.
  • Pytest over the 96 test files that import rdna2spirv/lane_masks: 2776 passed.
    • The other 2 (the test_feature_scan atomic-write tests) fail on this machine on plain main too.
  • Merges cleanly together with #2360, and the combined tree passes the semantic suite (555 files, 0 failed).

CI

  • The red checks are all outside this change, and they fail on #2360 as well:
    • the dpp llvm-mc failure in translator-tests and macos-python;
    • the vk_null_descriptor_test build in linux-gpu-tools;
    • cs_imgatomic_ext on macos;
    • Windows unittest/ctest.
  • Main is green now, so a rebase should clear them.

Behaviour change in the edited test: test_scalar_alu_imm_bitset.py no longer asserts that s_bitset0/1_b32 on a mask SGPR clears lane-mask tracking. This is intended.

AI-assisted (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7308708769 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#issuecomment-7308708769). Originally posted by [kurrutako](https://github.com/kurrutako) on 2026-12-01T10:46:56Z. --- Tested locally on Windows 11 with Python 3.14 and SPIRV-Tools from Vulkan SDK 1.4.363. **On the PR head** - `tests/semantic/test_bitset32_mask.py`: 8/8 pass on 69726d1. - On main cd73dda with only that test file copied in: 6 failures across 5 tests, so the test catches the bug. **Merged into current main locally** - `scripts/run_semantic_tests.py tests/semantic`: 554 files, 0 failed. - Pytest over the 96 test files that import rdna2spirv/lane_masks: 2776 passed. - The other 2 (the `test_feature_scan` atomic-write tests) fail on this machine on plain main too. - Merges cleanly together with #2360, and the combined tree passes the semantic suite (555 files, 0 failed). **CI** - The red checks are all outside this change, and they fail on #2360 as well: - the dpp llvm-mc failure in translator-tests and macos-python; - the `vk_null_descriptor_test` build in linux-gpu-tools; - cs_imgatomic_ext on macos; - Windows unittest/ctest. - Main is green now, so a rebase should clear them. **Behaviour change in the edited test:** `test_scalar_alu_imm_bitset.py` no longer asserts that `s_bitset0/1_b32` on a mask SGPR clears lane-mask tracking. This is intended. AI-assisted (Claude Code)
aslan2142 commented 2026-12-01 11:43:22 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed the diff against main: tools/lane_masks.py:271-279 and tools/rdna2spirv.py:9287-9325 cleanly preserve lane-mask tracking and update only the addressed lane bit (preserving the untouched wave64 half) for s_bitset0_b32/s_bitset1_b32 while materializing lane-mask bit-index sources via lane_mask_word, with thorough tests in tests/semantic/test_bitset32_mask.py and docs/design.md updated. Clean-room verified. Approving; please merge/rebase current main so CI runs green before merge.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130545103 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2355#pullrequestreview-6130545103). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:43:22Z. **Review:** APPROVED --- Reviewed the diff against `main`: `tools/lane_masks.py:271-279` and `tools/rdna2spirv.py:9287-9325` cleanly preserve lane-mask tracking and update only the addressed lane bit (preserving the untouched wave64 half) for `s_bitset0_b32`/`s_bitset1_b32` while materializing lane-mask bit-index sources via `lane_mask_word`, with thorough tests in `tests/semantic/test_bitset32_mask.py` and `docs/design.md` updated. Clean-room verified. Approving; please merge/rebase current `main` so CI runs green before merge. *(AI-assisted review.)*
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!2355
No description provided.