[PR #1735] wave64_emulate_opt: guard 32-bit opposite-half and live-SCC mask barriers (SHADER-W64-FOLD-B32-MASK-BARRIERS) #1750

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

📋 Pull Request Information

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

Base: main ← Head: fix/w64-fold-b32-mask-barriers


📝 Commits (2)

  • 499b6bc wave64_emulate_opt: guard 32-bit opposite-half and live-SCC mask barriers (SHADER-W64-FOLD-B32-MASK-BARRIERS)
  • 85ab223 tests: check all 64 lanes in B32MaskBarrierTests EXECZ cases

📊 Changes

3 files changed (+312 additions, -68 deletions)

View changed files

📝 docs/design.md (+1 -0)
📝 tests/semantic/test_wave64_emulate_barriers.py (+195 -0)
📝 tools/wave64_emulate_opt.py (+116 -68)

📄 Description

Item ID: SHADER-W64-FOLD-B32-MASK-BARRIERS
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159451450
Depends on: none

Summary

Follow-up to @whoalin1's finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159165301): aligns tools/wave64_emulate_opt.py (_classify_block_body, find_local_exec_folds, _insn_may_barrier_with_meta, and _is_uniform_scc_safe) with all 32-bit wave64 lane-mask barrier/vote paths lowered by tools/rdna2spirv.py under --wave64-emulate.

Root cause

Three 32-bit mask paths in tools/rdna2spirv.py emit wave_mask / g_vote (x_round / x_split / OpControlBarrier) under --wave64-emulate, but were missed by tools/wave64_emulate_opt.py:

  1. Opposite-half _mask_b32_src (rdna2spirv.py:6095-6110) on s_mov_b32, s_cselect_b32, s_not_b32, and MASK_SOP2_B32 (independent of SCC liveness).
  2. Live-SCC scc_logic votes (rdna2spirv.py:6134-6156) on _SOP2_B32_LOGIC (s_and/or/xor/andn2/orn2/nand/nor/xnor/not_b32) when writing a mask destination (exec_lo/hi, or vcc_lo/hi with mask) or reading same-half / single-half lane-mask sources.
  3. Opposite-half wave_mask on s_*_saveexec_b32 / s_*_wrexec_b32 (rdna2spirv.py:11163-11215) when reading a high-half mask source or saving into exec_hi/vcc_hi (independent of SCC liveness).

Before this change, folding an s_cbranch_execz region containing any of these instructions tripped AssertionError: wave64 emulation: x_split inside a folded lane-local region, and multi-wave plan_structured_emulation misclassified wave-divergent guards containing them as inline_sync_free.

Changes

  • tools/wave64_emulate_opt.py:
    • Added _mask_half, _mask_b32_dst_half, and a single shared _mask_chk_may_barrier helper used by _classify_block_body, find_local_exec_folds, and _insn_may_barrier_with_meta.
    • Added _MASK_CHK_B32_MOV, _MASK_CHK_B32_LOGIC, _MASK_CHK_B32_CSELECT, and opposite-half checks on _ALL_SAVEEXEC_WREXEC _b32 ops.
    • Extended _is_uniform_scc_safe to also detect vcc_lo/vcc_hi mask writes via _mask_b32_dst_half.
    • Same-half dead-SCC 32-bit mask ops (e.g. s_and_b32 vcc_lo, vcc_lo, -1 with dead SCC) continue to fold with 0 barriers.
  • tests/semantic/test_wave64_emulate_barriers.py: added B32MaskBarrierTests covering unit barrier prediction, all 9 folded s_cbranch_execz cases (64-thread workgroup interpreter + spirv_asm.assemble), a same-half dead-SCC positive fold control, and a 128-thread multi-wave divergent guard test (reverse_order=False/True).
  • docs/design.md: added contract-table row for --wave64-emulate 32-bit opposite-half and live-SCC barrier guards.

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU-only on macOS; no Vulkan GPU, spirv-val, or retail game files)
  • python3 -I tests/semantic/test_wave64_emulate_barriers.py: 17/17 OK
  • python3 -I tests/semantic/test_wave64_emulate_opt.py: 33/33 OK
  • python3 -I tests/test_wave64_emulate_opt_cfg.py: 26/26 OK
  • python3 -I scripts/run_semantic_tests.py tests/semantic: 487 files, 6,283 tests, 0 files failed (76 s)
  • python3 -m compileall -q make_game.py tools tests: OK
  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK
  • python3 -I scripts/check_no_game_data.py tools/wave64_emulate_opt.py tests/semantic/test_wave64_emulate_barriers.py docs/design.md: OK
  • Mutation check (running B32MaskBarrierTests against unpatched main:tools/wave64_emulate_opt.py): 11 failures (all 9 folded s_cbranch_execz cases crash with AssertionError: wave64 emulation: x_split inside a folded lane-local region, plus the unit check and 128-thread multi-wave guard check).

🔄 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/1735 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/w64-fold-b32-mask-barriers` --- ### 📝 Commits (2) - [`499b6bc`](https://github.com/ubiquitarianism/leonida/commit/499b6bce3221b6a7edd4eae6f8dfb902cc16301d) wave64_emulate_opt: guard 32-bit opposite-half and live-SCC mask barriers (SHADER-W64-FOLD-B32-MASK-BARRIERS) - [`85ab223`](https://github.com/ubiquitarianism/leonida/commit/85ab223ed82f1b7dfc148187084b36bd052bfc2d) tests: check all 64 lanes in B32MaskBarrierTests EXECZ cases ### 📊 Changes **3 files changed** (+312 additions, -68 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -0) 📝 `tests/semantic/test_wave64_emulate_barriers.py` (+195 -0) 📝 `tools/wave64_emulate_opt.py` (+116 -68) </details> ### 📄 Description Item ID: SHADER-W64-FOLD-B32-MASK-BARRIERS Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159451450 Depends on: none ### Summary Follow-up to @whoalin1's finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159165301): aligns `tools/wave64_emulate_opt.py` (`_classify_block_body`, `find_local_exec_folds`, `_insn_may_barrier_with_meta`, and `_is_uniform_scc_safe`) with all 32-bit wave64 lane-mask barrier/vote paths lowered by `tools/rdna2spirv.py` under `--wave64-emulate`. ### Root cause Three 32-bit mask paths in `tools/rdna2spirv.py` emit `wave_mask` / `g_vote` (`x_round` / `x_split` / `OpControlBarrier`) under `--wave64-emulate`, but were missed by `tools/wave64_emulate_opt.py`: 1. **Opposite-half `_mask_b32_src` (`rdna2spirv.py:6095-6110`)** on `s_mov_b32`, `s_cselect_b32`, `s_not_b32`, and `MASK_SOP2_B32` (independent of SCC liveness). 2. **Live-SCC `scc_logic` votes (`rdna2spirv.py:6134-6156`)** on `_SOP2_B32_LOGIC` (`s_and/or/xor/andn2/orn2/nand/nor/xnor/not_b32`) when writing a mask destination (`exec_lo/hi`, or `vcc_lo/hi` with mask) or reading same-half / single-half lane-mask sources. 3. **Opposite-half `wave_mask` on `s_*_saveexec_b32` / `s_*_wrexec_b32` (`rdna2spirv.py:11163-11215`)** when reading a high-half mask source or saving into `exec_hi`/`vcc_hi` (independent of SCC liveness). Before this change, folding an `s_cbranch_execz` region containing any of these instructions tripped `AssertionError: wave64 emulation: x_split inside a folded lane-local region`, and multi-wave `plan_structured_emulation` misclassified wave-divergent guards containing them as `inline_sync_free`. ### Changes - `tools/wave64_emulate_opt.py`: - Added `_mask_half`, `_mask_b32_dst_half`, and a single shared `_mask_chk_may_barrier` helper used by `_classify_block_body`, `find_local_exec_folds`, and `_insn_may_barrier_with_meta`. - Added `_MASK_CHK_B32_MOV`, `_MASK_CHK_B32_LOGIC`, `_MASK_CHK_B32_CSELECT`, and opposite-half checks on `_ALL_SAVEEXEC_WREXEC` `_b32` ops. - Extended `_is_uniform_scc_safe` to also detect `vcc_lo`/`vcc_hi` mask writes via `_mask_b32_dst_half`. - Same-half dead-SCC 32-bit mask ops (e.g. `s_and_b32 vcc_lo, vcc_lo, -1` with dead SCC) continue to fold with 0 barriers. - `tests/semantic/test_wave64_emulate_barriers.py`: added `B32MaskBarrierTests` covering unit barrier prediction, all 9 folded `s_cbranch_execz` cases (64-thread workgroup interpreter + `spirv_asm.assemble`), a same-half dead-SCC positive fold control, and a 128-thread multi-wave divergent guard test (`reverse_order=False/True`). - `docs/design.md`: added contract-table row for `--wave64-emulate` 32-bit opposite-half and live-SCC barrier guards. ### Verification - AI-assisted: yes - GPUs tested: none (CPU-only on macOS; no Vulkan GPU, `spirv-val`, or retail game files) - `python3 -I tests/semantic/test_wave64_emulate_barriers.py`: 17/17 OK - `python3 -I tests/semantic/test_wave64_emulate_opt.py`: 33/33 OK - `python3 -I tests/test_wave64_emulate_opt_cfg.py`: 26/26 OK - `python3 -I scripts/run_semantic_tests.py tests/semantic`: **487 files, 6,283 tests, 0 files failed** (76 s) - `python3 -m compileall -q make_game.py tools tests`: OK - `python3 -I tests/test_text_write_line_endings.py`: 3/3 OK - `python3 -I scripts/check_no_game_data.py tools/wave64_emulate_opt.py tests/semantic/test_wave64_emulate_barriers.py docs/design.md`: OK - Mutation check (running `B32MaskBarrierTests` against unpatched `main:tools/wave64_emulate_opt.py`): **11 failures** (all 9 folded `s_cbranch_execz` cases crash with `AssertionError: wave64 emulation: x_split inside a folded lane-local region`, plus the unit check and 128-thread multi-wave guard check). --- <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#1750
No description provided.