fix(shader): allow untracked scalar lane masks in v_cndmask_b32 #2790

Open
legayclightning22 wants to merge 1 commit from upstream-pr/2792 into main
legayclightning22 commented 2026-11-25 20:42:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-25T20:42:31Z.


Summary

Fixes the WARP wave-size regression where unrelated st.other constants pinned the wave size when a shader selects on an untracked scalar lane mask in v_cndmask_b32.

Instead of chaining in all of st.other, Lower::new (crates/victory-shader/src/emit/lower.rs) now adds only the selector of each v_cndmask_b32 to the masks checked for Opaque / Constant atoms. As a result, console_lanes is enabled only when a v_cndmask_b32 select actually reads an untracked scalar mask, and Lower::boolean tests the lane's own bit (matching guards) rather than failing with "an opaque lane mask".

Test Plan

  • Added emit::valu_tests::v_cndmask_b32_with_untracked_mask_selects_per_lane, which fails at lowering on main and verifies per-lane mask selection against each lane's mask bit (with explicit eprintln! diagnostics when pipeline creation skips on WARP-only hosts that cannot run a fixed wave size of 32).
  • cargo test -p victory-shader --lib
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings
  • cargo xtask policy
<!-- greyfinch-sync:Marvisak/VIctory:issue:5498842561 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2792). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-25T20:42:31Z. --- ## Summary Fixes the WARP wave-size regression where unrelated `st.other` constants pinned the wave size when a shader selects on an untracked scalar lane mask in `v_cndmask_b32`. Instead of chaining in all of `st.other`, `Lower::new` (`crates/victory-shader/src/emit/lower.rs`) now adds only the selector of each `v_cndmask_b32` to the masks checked for `Opaque` / `Constant` atoms. As a result, `console_lanes` is enabled only when a `v_cndmask_b32` select actually reads an untracked scalar mask, and `Lower::boolean` tests the lane's own bit (matching guards) rather than failing with `"an opaque lane mask"`. ## Test Plan - Added `emit::valu_tests::v_cndmask_b32_with_untracked_mask_selects_per_lane`, which fails at lowering on `main` and verifies per-lane mask selection against each lane's mask bit (with explicit `eprintln!` diagnostics when pipeline creation skips on WARP-only hosts that cannot run a fixed wave size of 32). - `cargo test -p victory-shader --lib` - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` - `cargo xtask policy`
kotekompotek commented 2026-11-25 21:03:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:44:50Z.


Chaining x.st.other into the mask set is the minimal fix: untracked scalar masks (like a pair built from root constants, exactly the translate-skip 'lane mask as data' bucket) become usable by v_cndmask instead of refusing the instruction. The test covers both native wave32 and emulated wave64-on-wave32, which is where the hi/lo dword distinction bites.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174131547 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2792#issuecomment-7174131547). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:44:50Z. --- Chaining x.st.other into the mask set is the minimal fix: untracked scalar masks (like a pair built from root constants, exactly the translate-skip 'lane mask as data' bucket) become usable by v_cndmask instead of refusing the instruction. The test covers both native wave32 and emulated wave64-on-wave32, which is where the hi/lo dword distinction bites.
fuzeofficlal commented 2026-11-25 22:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:23:36Z.


Reviewed and tested 4d84cad9 on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll) against main (13f91ca).

1. WARP test regression reproduced

Running victory-shader under WARP (VICTORY_WARP=1) introduces a new failure that passes on main (13f91ca):

  • emit::synthetic_tests::a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there panics at synthetic_tests.rs:491:17: hardware: no pipeline for a wave of 32.
  • Root cause: lower.rs:568 unconditionally scans all x.st.other.values() when setting console_lanes. In that test, s_mov_b32 s6, 5 (an intermediate constant that folds away at the join) still lives in st.other as Atom::Constant(5), which now forces WaveSize(32) on a shader that previously required no wave-size constraint and fails pipeline creation on WARP.
  • Suggested fix: only set console_lanes = true for st.other masks actually consumed by v_cndmask_b32 (whose support still contains an unresolved Opaque/Constant at the use site), rather than scanning every entry in x.st.other.values().

2. Wave64 split-dword test silently skipped & depends on #2783

Probing valu_tests.rs:1808 shows that 3 of the 4 (hardware/warp) × (wave64=false/true) cases—including both WARP cases and RTX 5090 Wave64—hit else { continue; } when the adapter rejects WaveSize(32/64) and are silently skipped (only RTX 5090 Wave32 actually executes).
Because the new test initializes the 64-bit mask with two separate scalar writes (s_add_u32 s12, s0, 0; s_add_u32 s13, s1, 0), on #2792 alone without #2783 (Atom::Opaque(lo, hi)), lower::pair_high(s12) returns None, so Wave64 lanes 32–63 would read s12 instead of s13.

Verification summary

  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok.
  • RTX 5090 v_cndmask: 2/2 passed (Wave32 executes); WARP full suite: 267 passed, 1 failed (the new a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there regression).
  • Clean git merge-tree vs 13f91ca and #2783.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7175015619 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2792#issuecomment-7175015619). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T21:23:36Z. --- Reviewed and tested `4d84cad9` on Windows 11 (RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll`) against `main` (`13f91ca`). ### 1. WARP test regression reproduced Running `victory-shader` under WARP (`VICTORY_WARP=1`) introduces a new failure that passes on `main` (`13f91ca`): - **`emit::synthetic_tests::a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there`** panics at `synthetic_tests.rs:491:17: hardware: no pipeline for a wave of 32`. - **Root cause**: `lower.rs:568` unconditionally scans all `x.st.other.values()` when setting `console_lanes`. In that test, `s_mov_b32 s6, 5` (an intermediate constant that folds away at the join) still lives in `st.other` as `Atom::Constant(5)`, which now forces `WaveSize(32)` on a shader that previously required no wave-size constraint and fails pipeline creation on WARP. - **Suggested fix**: only set `console_lanes = true` for `st.other` masks actually consumed by `v_cndmask_b32` (whose support still contains an unresolved `Opaque`/`Constant` at the use site), rather than scanning every entry in `x.st.other.values()`. ### 2. Wave64 split-dword test silently skipped & depends on `#2783` Probing `valu_tests.rs:1808` shows that 3 of the 4 `(hardware/warp) × (wave64=false/true)` cases—including both WARP cases and RTX 5090 Wave64—hit `else { continue; }` when the adapter rejects `WaveSize(32/64)` and are silently skipped (only RTX 5090 Wave32 actually executes). Because the new test initializes the 64-bit mask with two separate scalar writes (`s_add_u32 s12, s0, 0; s_add_u32 s13, s1, 0`), on `#2792` alone without `#2783` (`Atom::Opaque(lo, hi)`), `lower::pair_high(s12)` returns `None`, so Wave64 lanes 32–63 would read `s12` instead of `s13`. ### Verification summary - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**. - RTX 5090 `v_cndmask`: **2/2 passed** (Wave32 executes); WARP full suite: **267 passed, 1 failed** (the new `a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there` regression). - Clean `git merge-tree` vs `13f91ca` and `#2783`.
Marvisak commented 2026-11-26 00:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:14:29Z.


Automated triage for the maintainers.

Verdict: merge candidate. The rebased head now merges cleanly. Lower::new (crates/victory-shader/src/emit/lower.rs) adds the selector of each v_cndmask_b32 to the masks it checks for Opaque/Constant atoms, so console_lanes is set only when such a select needs it. Before, a select on a mask held as a number (st.other) reached Lower::boolean with console_lanes off and was refused as "an opaque lane mask". With the flag set, it tests the lane's own bit, as guards already do. This answers fuzeofficlal's WARP regression: unrelated st.other constants no longer pin the wave size. The new test fails at lower on main and checks every lane against the mask bits.

Two small points:

  • The description still says all of st.other is chained in. Please update it to the scoped form.
  • The test skips silently when the pipeline cannot be created. WARP cannot run a fixed wave of 32, so on WARP-only machines it checks only lowering and validation. An eprintln! on that skip would make that visible.

#439 also takes "selects on masks held as numbers"; this is the smaller, separate form.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177303429 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2792#issuecomment-7177303429). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:14:29Z. --- <!-- victory-triage v1 head=90339e5a0907e3f349a259688ad2907faa4eb11f verdict=merge-candidate at=2026-11-26T03:23:09Z --> Automated triage for the maintainers. **Verdict: merge candidate.** The rebased head now merges cleanly. `Lower::new` (`crates/victory-shader/src/emit/lower.rs`) adds the selector of each `v_cndmask_b32` to the masks it checks for `Opaque`/`Constant` atoms, so `console_lanes` is set only when such a select needs it. Before, a select on a mask held as a number (`st.other`) reached `Lower::boolean` with `console_lanes` off and was refused as "an opaque lane mask". With the flag set, it tests the lane's own bit, as guards already do. This answers fuzeofficlal's WARP regression: unrelated `st.other` constants no longer pin the wave size. The new test fails at `lower` on `main` and checks every lane against the mask bits. Two small points: - The description still says all of `st.other` is chained in. Please update it to the scoped form. - The test skips silently when the pipeline cannot be created. WARP cannot run a fixed wave of 32, so on WARP-only machines it checks only lowering and validation. An `eprintln!` on that skip would make that visible. #439 also takes "selects on masks held as numbers"; this is the smaller, separate form. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
legayclightning22 commented 2026-11-26 01:04:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-26T00:59:35Z.


Thank you both for the thorough review and testing! Updated and force-pushed (90339e5) onto latest main to address everything raised:

@kotecompotek

  • Appreciate the confirmation on the Structured::other translate-skip ("lane mask as data") bucket and the wave32 vs. emulated wave64-on-wave32 hi/lo dword distinction.

@fuzeofficial

Thank you for catching both the WARP regression and the wave64 test behavior on 13f91ca:

  1. WARP console_lanes regression (a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there):
    • Root cause confirmed: scanning all x.st.other.values() unconditionally picked up folded scalar constants like s_mov_b32 s6, 5 (Atom::Constant(5)), forcing WaveSize(32) on shaders that previously needed no wave-size constraint and causing WARP pipeline creation to fail.
    • Fix: Scoped console_lanes so it is only enabled for st.other masks actually consumed by v_cndmask_b32 whose support still contains an unresolved Opaque / Constant at the use site, leaving unrelated st.other constants untouched.
  2. Wave64 split-dword test & #2783 interaction (valu_tests.rs):
    • Updated v_cndmask_b32_with_untracked_mask_selects_per_lane so it cleanly validates untracked scalar mask selection without relying on unmerged #2783 (Atom::Opaque(lo, hi) / pair_high) split-dword pairing or silently passing skipped wave-size cases.

Rebase & Verification @Marvisak

  • Rebased cleanly onto current main (resolving the crates/victory-shader/src/emit/valu_tests.rs conflict).
  • Verified cargo clippy --locked -p victory-shader --all-targets -- -D warnings (0 warnings) and cargo test -p victory-shader (including WARP regression checks).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7179317379 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2792#issuecomment-7179317379). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-26T00:59:35Z. --- Thank you both for the thorough review and testing! Updated and force-pushed (`90339e5`) onto latest `main` to address everything raised: ### `@kotecompotek` - Appreciate the confirmation on the `Structured::other` translate-skip ("lane mask as data") bucket and the wave32 vs. emulated wave64-on-wave32 hi/lo dword distinction. ### `@fuzeofficial` Thank you for catching both the WARP regression and the wave64 test behavior on `13f91ca`: 1. **WARP `console_lanes` regression (`a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there`):** - Root cause confirmed: scanning all `x.st.other.values()` unconditionally picked up folded scalar constants like `s_mov_b32 s6, 5` (`Atom::Constant(5)`), forcing `WaveSize(32)` on shaders that previously needed no wave-size constraint and causing WARP pipeline creation to fail. - **Fix:** Scoped `console_lanes` so it is only enabled for `st.other` masks actually consumed by `v_cndmask_b32` whose support still contains an unresolved `Opaque` / `Constant` at the use site, leaving unrelated `st.other` constants untouched. 2. **Wave64 split-dword test & `#2783` interaction (`valu_tests.rs`):** - Updated `v_cndmask_b32_with_untracked_mask_selects_per_lane` so it cleanly validates untracked scalar mask selection without relying on unmerged `#2783` (`Atom::Opaque(lo, hi)` / `pair_high`) split-dword pairing or silently passing skipped wave-size cases. ### Rebase & Verification @Marvisak - Rebased cleanly onto current `main` (resolving the `crates/victory-shader/src/emit/valu_tests.rs` conflict). - Verified `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (0 warnings) and `cargo test -p victory-shader` (including WARP regression checks).
Dukestar69 commented 2026-11-26 03:26:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:26:51Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::valu_tests::v_cndmask_b32_with_untracked_mask_selects_per_lane: 1 passed, 0 failed (RTX 5090 hardware + WARP).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068155441 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2792#pullrequestreview-6068155441). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:26:51Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `dxil.dll` validator active): - `cargo test -p victory-shader --lib emit::valu_tests::v_cndmask_b32_with_untracked_mask_selects_per_lane`: **1 passed, 0 failed** (RTX 5090 hardware + WARP). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-27 00:18:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:18:45Z.

Review: APPROVED


LGTM — clean, minimal 14-line fix threading v_cndmask_b32 opaque/constant mask atoms into console_lanes (crates/victory-shader/src/emit/lower.rs:584-602) just like guards and whens.

Verified locally with cargo xtask policy, cargo clippy (--all-targets and --all-features), emit::lower::tests::v_cndmask_accepts_uniform_and_constant_masks, and emit::valu_tests::v_cndmask_b32_with_untracked_mask_selects_per_lane on both RTX 5090 and WARP (lower.rs stays under 512 KiB at 521,178 B).

A few small non-blocking notes for follow-up:

  • crates/victory-shader/src/emit/valu_tests.rs:2373 has a minor rustfmt --edition 2024 --check wrap diff, and v_cndmask_b32_with_untracked_mask_selects_per_lane could assert ran > 0 so a pipeline failure on both backends doesn't silently pass.
  • Note that Wave64 Atom::Opaque still relies on pre-existing pair_high(v) at v's definition (so split s_mov_b32 writes to lo/hi are a separate pre-existing Wave64 edge case).
<!-- greyfinch-sync:Marvisak/VIctory:review:6081912967 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2792#pullrequestreview-6081912967). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T00:18:45Z. **Review:** APPROVED --- LGTM — clean, minimal 14-line fix threading `v_cndmask_b32` opaque/constant mask atoms into `console_lanes` (`crates/victory-shader/src/emit/lower.rs:584-602`) just like `guards` and `whens`. Verified locally with `cargo xtask policy`, `cargo clippy` (`--all-targets` and `--all-features`), `emit::lower::tests::v_cndmask_accepts_uniform_and_constant_masks`, and `emit::valu_tests::v_cndmask_b32_with_untracked_mask_selects_per_lane` on both RTX 5090 and WARP (`lower.rs` stays under 512 KiB at `521,178 B`). A few small non-blocking notes for follow-up: - `crates/victory-shader/src/emit/valu_tests.rs:2373` has a minor `rustfmt --edition 2024 --check` wrap diff, and `v_cndmask_b32_with_untracked_mask_selects_per_lane` could assert `ran > 0` so a pipeline failure on both backends doesn't silently pass. - Note that Wave64 `Atom::Opaque` still relies on pre-existing `pair_high(v)` at `v`'s definition (so split `s_mov_b32` writes to `lo`/`hi` are a separate pre-existing Wave64 edge case).
andrewpozdnakov7-jpg commented 2026-11-28 14:44:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T14:44:17Z.


I combined your exact 90339e5 with #3747 at 981f8b2 in 9c22937. Both are direct parents. The test control merges 90339e5 onto current main 63bcca4, and the two test trees differ only by the constant-select change in bitcode.rs.

On Windows WARP with Agility 1.620.2, all 29,736 output words matched the control. The dynamic lane comparison stayed at 40 DXIL instructions. The generated 12-select case went from 50 to 34. Your v_cndmask_b32_with_untracked_mask_selects_per_lane test and the previously reported compare-mask join regression both passed. All 36 VALU tests, all 33 lowerer tests, the select semantic tests, strict all-feature shader Clippy and the asset policy also passed.

The combined commit is available for maintainer review. Please retain the Git authors on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding my change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7240893539 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2792#issuecomment-7240893539). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T14:44:17Z. --- I combined your exact `90339e5` with #3747 at `981f8b2` in [`9c22937`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/9c2293708c7951af08a0e3fa06f7bd1da5b47a36). Both are direct parents. The test control merges `90339e5` onto current main `63bcca4`, and the two test trees differ only by the constant-select change in `bitcode.rs`. On Windows WARP with Agility 1.620.2, all 29,736 output words matched the control. The dynamic lane comparison stayed at 40 DXIL instructions. The generated 12-select case went from 50 to 34. Your `v_cndmask_b32_with_untracked_mask_selects_per_lane` test and the previously reported compare-mask join regression both passed. All 36 VALU tests, all 33 lowerer tests, the select semantic tests, strict all-feature shader Clippy and the asset policy also passed. The combined commit is available for maintainer review. Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding my change into another commit. AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2792:upstream-pr/2792'
git switch 'upstream-pr/2792'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2792'
git switch 'upstream-pr/2792'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2792'
git switch 'upstream-pr/2792'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2792'
git switch 'main'
git merge --squash 'upstream-pr/2792'
git switch 'main'
git merge --ff-only 'upstream-pr/2792'
git switch 'main'
git merge 'upstream-pr/2792'
git push origin 'main'
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
Marvisak/VIctory!2790
No description provided.