victory-shader: lower all-zero and all-one constant lane masks #1057

Closed
bartikele wants to merge 1 commit from upstream-pr/1057 into main
bartikele commented 2026-11-24 15:21:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by bartikele on 2026-11-24T15:21:44Z.


Lowers \Atom::Constant(0)\ to \ alse\ and all-ones constant lane masks (\u64::MAX, or \u32::MAX\ in wave32) to \ rue\ without requiring \console_lanes\ or \WAVE_OPS.

Verified with \cargo clippy -p victory-shader --all-targets --locked -- -D warnings, \cargo test -p victory-shader --locked, \cargo xtask policy, and \ ictory translate --validate.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6585178496 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1057). Originally posted by [bartikele](https://github.com/bartikele) on 2026-11-24T15:21:44Z. --- Lowers \Atom::Constant(0)\ to \ alse\ and all-ones constant lane masks (\u64::MAX\, or \u32::MAX\ in wave32) to \ rue\ without requiring \console_lanes\ or \WAVE_OPS\. Verified with \cargo clippy -p victory-shader --all-targets --locked -- -D warnings\, \cargo test -p victory-shader --locked\, \cargo xtask policy\, and \ ictory translate --validate\.
DoubleD17 commented 2026-11-24 17:03:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DoubleD17 on 2026-11-24T16:26:37Z.

Review: COMMENTED


On a793ad8, the only producer of Atom::Constant in the current source masks its input to the wave width and returns a terminal boolean for zero or a full mask. The existing boolean lowering handles those terminals before looking up an atom, so the new Lower::atom branches are unreachable through that producer.

An independent classification model compared all 81 inline encodings and six boundary literals in wave32 and wave64 against bit-by-bit lane counts. All 174 cases agreed, and zero produced atoms matching the new branches. As a control, 0xFFFFFFFF classified as true in wave32 and as a partial mask in wave64. This was source inspection and a synthetic model. The PR was not executed and emitted DXIL was not measured. A shader-level test comparing ffe310e with a793ad8 would establish whether the emitted wave operations or shader requirements change.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:review:6043225364 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1057#pullrequestreview-6043225364). Originally posted by [DoubleD17](https://github.com/DoubleD17) on 2026-11-24T16:26:37Z. **Review:** COMMENTED --- On `a793ad8`, the only producer of `Atom::Constant` in the current source masks its input to the wave width and returns a terminal boolean for zero or a full mask. The existing boolean lowering handles those terminals before looking up an atom, so the new `Lower::atom` branches are unreachable through that producer. An independent classification model compared all 81 inline encodings and six boundary literals in wave32 and wave64 against bit-by-bit lane counts. All 174 cases agreed, and zero produced atoms matching the new branches. As a control, `0xFFFFFFFF` classified as true in wave32 and as a partial mask in wave64. This was source inspection and a synthetic model. The PR was not executed and emitted DXIL was not measured. A shader-level test comparing `ffe310e` with `a793ad8` would establish whether the emitted wave operations or shader requirements change. AI-assisted.
catminou4 commented 2026-11-24 17:03:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T16:28:53Z.

Review: APPROVED


Tiny, sound: all-zero/all-one lane-mask constants now fold to DXIL bool constants instead of a lane_bit computation. The wave64 vs wave32 all-ones split is correct (u64::MAX vs low-32 all-ones only when !wave64), and partial masks still take the console_lanes path. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p <crate> --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. victory-shader: 96 passed, 0 failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6043261525 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1057#pullrequestreview-6043261525). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T16:28:53Z. **Review:** APPROVED --- Tiny, sound: all-zero/all-one lane-mask constants now fold to DXIL bool constants instead of a lane_bit computation. The wave64 vs wave32 all-ones split is correct (u64::MAX vs low-32 all-ones only when !wave64), and partial masks still take the console_lanes path. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p <crate> --locked`. Shader execution tests (valu_tests/host) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. victory-shader: 96 passed, 0 failed.
shortselow-byte commented 2026-11-24 17:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T16:09:03Z.


This PR has no CI run yet, so I ran the CI's checks at head a793ad8 (on main ffe310e): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2). Workspace tests 342 passed, 0 failed (GPU tests on the AMD device and WARP); both clippy runs (default and --all-features) clean; cargo xtask policy ok.

The change reads right to me: 0 is no lane, u64::MAX is every lane, and u32::MAX counts as every lane only for a wave32 program (!native.wave64), so a wave64 mask of just the low 32 lanes still goes through the console_lanes path.

It adds no test, though. A small one that lowers a program comparing against an all-ones mask and checks that it no longer needs console_lanes or wave ops would keep this from regressing.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137199243 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1057#issuecomment-7137199243). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-24T16:09:03Z. --- This PR has no CI run yet, so I ran the CI's checks at head `a793ad8` (on `main` `ffe310e`): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2). Workspace tests 342 passed, 0 failed (GPU tests on the AMD device and WARP); both clippy runs (default and `--all-features`) clean; `cargo xtask policy` ok. The change reads right to me: 0 is no lane, `u64::MAX` is every lane, and `u32::MAX` counts as every lane only for a wave32 program (`!native.wave64`), so a wave64 mask of just the low 32 lanes still goes through the `console_lanes` path. It adds no test, though. A small one that lowers a program comparing against an all-ones mask and checks that it no longer needs `console_lanes` or wave ops would keep this from regressing.
Zipettte commented 2026-11-24 17:04:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T16:30:09Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at a793ad8: cargo test -p victory-shader passes, 120 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137764594 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1057#issuecomment-7137764594). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T16:30:09Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at a793ad8: `cargo test -p victory-shader` passes, 120 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
mercuryVM commented 2026-11-24 19:02:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T18:50:33Z.

Review: APPROVED


Tested a793ad8 on Windows 11, RTX 5070, MSVC: builds, cargo test --workspace --no-fail-fast 602 passed, 0 failed (on our fork main), with victory-shader single-threaded.

  • These two arms give exactly what the console_lanes arm below them computes for the same constants. Every lane's bit of 0 is clear, and every lane's bit of an all-ones mask is set: all 64 bits in wave64, the low 32 in wave32, where no console lane is past 31. So it's correct with or without console lanes, and it stops refusing these masks when console lanes are off.
  • In wave64 a mask of only the low 32 bits still falls through to the existing arms, as it must.
  • victory translate shaders.rpf --list (the user's own package, counts only) is unchanged by this PR on our fork's main, so none of the package's programs depended on it. That's not a problem, just a data point.
  • Nit: there's no test. A two-instruction program that branches on s_mov_b64 exec, -1, lowered with console_lanes off, would cover the new path.

Merged into our fork's main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6045348512 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1057#pullrequestreview-6045348512). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T18:50:33Z. **Review:** APPROVED --- Tested a793ad8 on Windows 11, RTX 5070, MSVC: builds, `cargo test --workspace --no-fail-fast` 602 passed, 0 failed (on our fork main), with victory-shader single-threaded. - These two arms give exactly what the `console_lanes` arm below them computes for the same constants. Every lane's bit of 0 is clear, and every lane's bit of an all-ones mask is set: all 64 bits in wave64, the low 32 in wave32, where no console lane is past 31. So it's correct with or without console lanes, and it stops refusing these masks when console lanes are off. - In wave64 a mask of only the low 32 bits still falls through to the existing arms, as it must. - `victory translate shaders.rpf --list` (the user's own package, counts only) is unchanged by this PR on our fork's main, so none of the package's programs depended on it. That's not a problem, just a data point. - Nit: there's no test. A two-instruction program that branches on `s_mov_b64 exec, -1`, lowered with `console_lanes` off, would cover the new path. Merged into our fork's main. AI-assisted (Claude Code).
avt0m4t48 commented 2026-11-24 20:03:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by avt0m4t48 on 2026-11-24T19:30:47Z.


I ran a synthetic before/after check for the regression requested above. Base translator ffe310e, then the four-line lower.rs diff from a793ad8, Rust 1.98.1 on Linux.

I prepended s_mov_b32 exec_lo (wave32) or s_mov_b64 exec (wave64) with each of 0, -1, and 5 to a synthetic pixel emitter fixture. Both branches emitted byte-identical DXIL for the four zero/all-ones combinations. Both still refused the two partial-mask combinations with a constant lane mask. No title data or GPU execution.

A separate structurer test confirmed why. On both wave widths, zero becomes Bool::FALSE, all-ones requires no guard, and only the partial-mask control produces Atom::Constant(5). The PR's new terminal-value cases therefore aren't exercised by these production translation paths. A shader that reaches the actual refusal would need a nontrivial constant mask or a different constructor.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142204466 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1057#issuecomment-7142204466). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-24T19:30:47Z. --- I ran a synthetic before/after check for the regression requested above. Base translator `ffe310e`, then the four-line `lower.rs` diff from `a793ad8`, Rust 1.98.1 on Linux. I prepended `s_mov_b32 exec_lo` (wave32) or `s_mov_b64 exec` (wave64) with each of `0`, `-1`, and `5` to a synthetic pixel emitter fixture. Both branches emitted byte-identical DXIL for the four zero/all-ones combinations. Both still refused the two partial-mask combinations with `a constant lane mask`. No title data or GPU execution. A separate structurer test confirmed why. On both wave widths, zero becomes `Bool::FALSE`, all-ones requires no guard, and only the partial-mask control produces `Atom::Constant(5)`. The PR's new terminal-value cases therefore aren't exercised by these production translation paths. A shader that reaches the actual refusal would need a nontrivial constant mask or a different constructor.
upstream-sync closed this pull request 2026-11-24 21:01:52 +00:00
bartikele commented 2026-11-24 21:03:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by bartikele on 2026-11-24T20:34:51Z.


Closing as redundant: as @DoubleD17 showed, \structure.rs\ already collapses all-zero and all-one masks to \Bool::FALSE\ / \Bool::TRUE, making these \Lower::atom\ arms unreachable (also confirmed on \shaders.rpf\ by @mercuryVM). Thanks to @DoubleD17, @catminou4, @mercuryVM, and @shortselow-byte for the thorough verification and review!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143765006 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1057#issuecomment-7143765006). Originally posted by [bartikele](https://github.com/bartikele) on 2026-11-24T20:34:51Z. --- Closing as redundant: as @DoubleD17 showed, \structure.rs\ already collapses all-zero and all-one masks to \Bool::FALSE\ / \Bool::TRUE\, making these \Lower::atom\ arms unreachable (also confirmed on \shaders.rpf\ by @mercuryVM). Thanks to @DoubleD17, @catminou4, @mercuryVM, and @shortselow-byte for the thorough verification and review!

Pull request closed

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!1057
No description provided.