shader: lower 32-bit scalar operations on wave64 lane-mask halves when read as data #423

Open
opened 2026-11-27 17:37:09 +00:00 by Sheffy007 · 2 comments
Sheffy007 commented 2026-11-27 17:37:09 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T17:37:09Z.


Problem

In world runs on main (#4 refusal table: 9 | 9 | 0 | a lane mask holding lanes elsewhere read as data: written by a scalar instruction of the other width), 9 distinct wave64 compute shaders fail in Lower::mask_number (crates/victory-shader/src/emit/lower.rs:2819-2824).

structure tracks wave64 lane masks whose low and/or high 32-bit halves are written or updated by 32-bit scalar ALU instructions (s_mov_b32, s_movk_i32, s_not_b32, s_and_b32, s_or_b32, s_xor_b32, s_andn2_b32, s_orn2_b32, s_cselect_b32, s_cmov_b32, s_cmovk_i32, etc.). However:

  1. Lower::sop treats every scalar write in st.masks or st.highs as a deferred lane mask (Val::Missing("a lane mask read as data")), and when a consumer later reads either half as data (s_bcnt1_i32_b64, s_ff1_i32_b64, v_mov_b32, uniform joins, lockstep, etc.), Lower::mask_number requires _b64 and refuses 32-bit SOP writers with written by a scalar instruction of the other width.
  2. In addition, st.highs maps hi -> lo one-to-one: when a 64-bit write (lo0, hi0) is followed by a partial 32-bit update (lo1, hi0) of only the low half, st.highs[&hi0] is overwritten with lo1, causing mask_dword(hi0) to inspect lo1's 32-bit writer instead of hi0's own 64-bit writer.
  3. In Lower::sop, pair only checked st.masks.contains_key(&lo) when recording mask_scc, dropping SCC of a 32-bit mask operation on a high half in st.highs.

Plan

  • Evaluate 32-bit (dwords == 1, non-EXEC-writing) scalar ALU writers of wave64 mask halves directly in mask_dword (mask_half_number / half_ballots), while keeping s_*_saveexec_b32 / s_*_wrexec_b32 in wave64 and _b64 in wave32 refused as before.
  • Resolve 64-bit writers' high halves (writes[1]) and high-dword phis against their own paired low value before falling back to st.highs, so partial 32-bit updates to lo do not clobber hi's lookup.
  • Record mask_scc for 32-bit mask operations on high-half dwords (self.is_mask(Some(lo))).
  • Add lowering tests in mask_tests.rs and an end-to-end Metal GPU compute test in split_wave_tests.rs.

Refs #4, #258

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6651681410 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/423). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T17:37:09Z. --- ## Problem In world runs on `main` (#4 refusal table: `9 | 9 | 0 | a lane mask holding lanes elsewhere read as data: written by a scalar instruction of the other width`), 9 distinct wave64 compute shaders fail in `Lower::mask_number` (`crates/victory-shader/src/emit/lower.rs:2819-2824`). `structure` tracks wave64 lane masks whose low and/or high 32-bit halves are written or updated by 32-bit scalar ALU instructions (`s_mov_b32`, `s_movk_i32`, `s_not_b32`, `s_and_b32`, `s_or_b32`, `s_xor_b32`, `s_andn2_b32`, `s_orn2_b32`, `s_cselect_b32`, `s_cmov_b32`, `s_cmovk_i32`, etc.). However: 1. `Lower::sop` treats every scalar write in `st.masks` or `st.highs` as a deferred lane mask (`Val::Missing("a lane mask read as data")`), and when a consumer later reads either half as data (`s_bcnt1_i32_b64`, `s_ff1_i32_b64`, `v_mov_b32`, uniform joins, `lockstep`, etc.), `Lower::mask_number` requires `_b64` and refuses 32-bit SOP writers with `written by a scalar instruction of the other width`. 2. In addition, `st.highs` maps `hi -> lo` one-to-one: when a 64-bit write `(lo0, hi0)` is followed by a partial 32-bit update `(lo1, hi0)` of only the low half, `st.highs[&hi0]` is overwritten with `lo1`, causing `mask_dword(hi0)` to inspect `lo1`'s 32-bit writer instead of `hi0`'s own 64-bit writer. 3. In `Lower::sop`, `pair` only checked `st.masks.contains_key(&lo)` when recording `mask_scc`, dropping `SCC` of a 32-bit mask operation on a high half in `st.highs`. ## Plan - Evaluate 32-bit (`dwords == 1`, non-`EXEC`-writing) scalar ALU writers of wave64 mask halves directly in `mask_dword` (`mask_half_number` / `half_ballots`), while keeping `s_*_saveexec_b32` / `s_*_wrexec_b32` in wave64 and `_b64` in wave32 refused as before. - Resolve 64-bit writers' high halves (`writes[1]`) and high-dword phis against their own paired low value before falling back to `st.highs`, so partial 32-bit updates to `lo` do not clobber `hi`'s lookup. - Record `mask_scc` for 32-bit mask operations on high-half dwords (`self.is_mask(Some(lo))`). - Add lowering tests in `mask_tests.rs` and an end-to-end Metal GPU compute test in `split_wave_tests.rs`. Refs #4, #258
Sheffy007 commented 2026-11-27 17:37:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T17:37:11Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7224605497 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/423#issuecomment-7224605497). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T17:37:11Z. --- /claim
github-actions[bot] commented 2026-11-27 17:37:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T17:37:20Z.


Claimed by @Sheffy007. Open a draft pull request with Refs #423 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7224608371 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/423#issuecomment-7224608371). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T17:37:20Z. --- Claimed by @Sheffy007. Open a draft pull request with `Refs #423` in its description within 24 hours, or the claim expires.
Sign in to join this conversation.
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
LakshanSivakumar/Native-Victory-macOS#423
No description provided.