victory-shader: resolve Structured::other and constant masks in v_cndmask_b32 #1221

Merged
bartikele merged 1 commit from upstream-pr/1221 into main 2026-11-25 00:21:49 +00:00
bartikele commented 2026-11-24 16:30:56 +00:00 (Migrated from github.com)

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


Expose Structured::other (masks resolved by structure that do not derive from EXEC or VALU, such as s_cselect, constants, and opaque scalar masks) without adding them to Structured::masks (so Lower::sop does not treat ordinary scalar data as lane masks).

In Lower::valu for v_cndmask_b32:

  • Fall back to self.x.st.other when src[2] is not in self.x.st.masks.
  • Handle Operand::Const inline constants (0, -1, and console-lane bitmasks).

Adds unit test emit::lower::tests::v_cndmask_accepts_uniform_and_constant_masks.

Tested with:

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings
  • cargo test -p victory-shader --locked
<!-- greyfinch-sync:Marvisak/VIctory:issue:6586562391 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1221). Originally posted by [bartikele](https://github.com/bartikele) on 2026-11-24T16:30:56Z. --- Expose `Structured::other` (masks resolved by `structure` that do not derive from `EXEC` or `VALU`, such as `s_cselect`, constants, and opaque scalar masks) without adding them to `Structured::masks` (so `Lower::sop` does not treat ordinary scalar data as lane masks). In `Lower::valu` for `v_cndmask_b32`: - Fall back to `self.x.st.other` when `src[2]` is not in `self.x.st.masks`. - Handle `Operand::Const` inline constants (`0`, `-1`, and console-lane bitmasks). Adds unit test `emit::lower::tests::v_cndmask_accepts_uniform_and_constant_masks`. Tested with: - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` - `cargo test -p victory-shader --locked`
MichaelSmithAI commented 2026-11-24 17:04:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T16:38:33Z.


Independent GPU check on 67c4f53, with an RTX 4090 under Wine and Microsoft DXIL validation. We assembled v_cndmask_b32_e64 v0, 7, 11, s6 for gfx1030 and ran it with one active lane for each of four scalar inputs (0, 1, 2, 3).

How the shader sets s6 Four readbacks
Compare the input to zero, then use s_cselect_b32 to select −1 or 0 11, 7, 7, 7
Copy the numeric input into s6 and select using lane zero’s bit 7, 11, 7, 11

Both results also matched on our comparison build containing #385. On ffe310e both shaders stopped before emission with “a select on an untracked mask”. The four values above are separate input cases. This fixture exercises bit zero only.

The direct-inline case has a separate coverage boundary. LLVM’s gfx1030 assembler rejected 0, −1 and 1 in the mask operand position, so our live tests used the scalar-register encoding. For #1119, the reported hash and refusal text leave the mask source unknown.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137983317 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7137983317). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T16:38:33Z. --- Independent GPU check on `67c4f53`, with an RTX 4090 under Wine and Microsoft DXIL validation. We assembled `v_cndmask_b32_e64 v0, 7, 11, s6` for gfx1030 and ran it with one active lane for each of four scalar inputs (0, 1, 2, 3). | How the shader sets s6 | Four readbacks | | --- | --- | | Compare the input to zero, then use `s_cselect_b32` to select −1 or 0 | 11, 7, 7, 7 | | Copy the numeric input into s6 and select using lane zero’s bit | 7, 11, 7, 11 | Both results also matched on our comparison build containing #385. On `ffe310e` both shaders stopped before emission with “a select on an untracked mask”. The four values above are separate input cases. This fixture exercises bit zero only. The direct-inline case has a separate coverage boundary. LLVM’s gfx1030 assembler rejected 0, −1 and 1 in the mask operand position, so our live tests used the scalar-register encoding. For #1119, the reported hash and refusal text leave the mask source unknown.
fuzeofficlal commented 2026-11-24 17:04:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:02:09Z.


One correctness caveat with exposing all of Structured::other directly to v_cndmask_b32: Lanes also records Atom::Opaque / arbitrary non-uniform bitmasks (for example s_lshl_b32 s2, 1, s0 or s_mov_b32 s2, 0x0000ffff, where v_cndmask_b32 selects bit (s2 >> lane_id) & 1 per lane) in other. Lowering those through self.boolean(m, c) treats the whole wave as taking the same scalar branch instead of refusing an untracked per-lane bitmask. Filtering self.b.support(m) to Atom::Uniform(_) atoms only (as in #1270) accepts s_cselect -1/0 and all-zero/all-ones constants while keeping per-lane bitmasks rejected.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138585312 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7138585312). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:02:09Z. --- One correctness caveat with exposing all of `Structured::other` directly to `v_cndmask_b32`: `Lanes` also records `Atom::Opaque` / arbitrary non-uniform bitmasks (for example `s_lshl_b32 s2, 1, s0` or `s_mov_b32 s2, 0x0000ffff`, where `v_cndmask_b32` selects bit `(s2 >> lane_id) & 1` per lane) in `other`. Lowering those through `self.boolean(m, c)` treats the whole wave as taking the same scalar branch instead of refusing an untracked per-lane bitmask. Filtering `self.b.support(m)` to `Atom::Uniform(_)` atoms only (as in #1270) accepts `s_cselect` `-1`/`0` and all-zero/all-ones constants while keeping per-lane bitmasks rejected.
bartikele commented 2026-11-24 18:05:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by bartikele on 2026-11-24T17:15:25Z.


Thanks for checking @fuzeofficlal! Note that Lower::boolean already differentiates the two cases:

  • Outside compute (!self.console_lanes, i.e., VS/PS/MS), Atom::Opaque(_) still fails with Err("an opaque lane mask") — it never collapses the wave to a single scalar branch.
  • In compute (self.console_lanes), Atom::Opaque(v) lowers via self.lane_bit(at, lo, hi), which extracts bit (v >> lane_id) & 1 per lane (matching the console's 32/64-bit per-lane bitmask semantics, as also verified by @MichaelSmithAI's s6 numeric bitmask test above).

So arbitrary non-uniform bitmasks in other are only accepted in compute where lane_bit is exact per lane, and rejected in graphics stages.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138921825 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7138921825). Originally posted by [bartikele](https://github.com/bartikele) on 2026-11-24T17:15:25Z. --- Thanks for checking @fuzeofficlal! Note that `Lower::boolean` already differentiates the two cases: - Outside compute (`!self.console_lanes`, i.e., VS/PS/MS), `Atom::Opaque(_)` still fails with `Err("an opaque lane mask")` — it never collapses the wave to a single scalar branch. - In compute (`self.console_lanes`), `Atom::Opaque(v)` lowers via `self.lane_bit(at, lo, hi)`, which extracts bit `(v >> lane_id) & 1` per lane (matching the console's 32/64-bit per-lane bitmask semantics, as also verified by @MichaelSmithAI's `s6` numeric bitmask test above). So arbitrary non-uniform bitmasks in `other` are only accepted in compute where `lane_bit` is exact per lane, and rejected in graphics stages.
pablogonz12 commented 2026-11-24 18:05:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T17:27:24Z.


Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 (main's host build fails without it: E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 666 / 768 656 656

No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you handle, so this is a no-regression result only (same 10 SPIR-V validation failures as the base).

Not tested: in-game.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139221149 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7139221149). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-24T17:27:24Z. --- Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main `ffe310e` plus #1017 (main's host build fails without it: `E0425 host_resource`), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped). | | translate | valid SPIR-V | RADV pipeline | |---|---|---|---| | base | 666 / 768 | 656 | 656 | | your head | 666 / 768 | 656 | 656 | No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you handle, so this is a no-regression result only (same 10 SPIR-V validation failures as the base). Not tested: in-game.
Zipettte commented 2026-11-24 18:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T17:59:50Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 67c4f53: cargo test -p victory-shader passes, 121 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:7140006619 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7140006619). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T17:59:50Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 67c4f53: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
sinan-cmyk commented 2026-11-24 20:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T19:50:36Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: +2 programs over main, 0 lost.

Offline. I merged head 67c4f53 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,726 with this PR.

Failure on main Gained
emit: a select on an untracked mask 2

Both are among the programs that #1319 gains. Another 205 programs move from "a select on an untracked mask" on to "a descriptor read only as data", the reason #1067 handles. So this PR may gain more stacked on #1402, and I'm measuring that.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142666549 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7142666549). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:50:36Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: +2 programs over `main`, 0 lost.** **Offline.** I merged head 67c4f53 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,726 with this PR. | Failure on `main` | Gained | |---|---| | emit: a select on an untracked mask | 2 | Both are among the programs that #1319 gains. Another 205 programs move from "a select on an untracked mask" on to "a descriptor read only as data", the reason #1067 handles. So this PR may gain more stacked on #1402, and I'm measuring that. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
sinan-cmyk commented 2026-11-24 21:03:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:31:02Z.


Stacked on #1402: no change

Result: 0 gained, 0 lost, and no failure reason changes on top of #1402. On main this PR gained 2 programs and moved 205 from "a select on an untracked mask" to "a descriptor read only as data" (earlier comment). #1402 already gains those programs through #1319, so nothing is left for this PR on this data.

The merge. The merge with #1402 conflicts in the v_cndmask_b32 arm of emit/lower.rs. #1402 moved that arm into a mask_cond helper. This PR rewrites the same arm: it falls back to Structured::other masks and accepts general constant masks. I kept the mask_cond call and added this PR's two cases in front of it at this call site, together with the WAVE_OPS flag that mask_cond sets before lane_bit. The structure.rs change merges cleanly. Tests: 138 passed, 0 failed, including v_cndmask_accepts_uniform_and_constant_masks.

Together with #1423 on #1402. One program that validates with #1423 alone fails again at "a lane-mask join of an untracked mask" (+213 instead of +214). On this data, this PR adds no gain on top of #1402 and costs that one program when stacked with #1423.

Method: victory translate --validate --list on shaders.rpf (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143666117 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7143666117). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:31:02Z. --- ### Stacked on #1402: no change **Result: 0 gained, 0 lost, and no failure reason changes on top of #1402.** On `main` this PR gained 2 programs and moved 205 from "a select on an untracked mask" to "a descriptor read only as data" ([earlier comment](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7142666549)). #1402 already gains those programs through #1319, so nothing is left for this PR on this data. **The merge.** The merge with #1402 conflicts in the `v_cndmask_b32` arm of `emit/lower.rs`. #1402 moved that arm into a `mask_cond` helper. This PR rewrites the same arm: it falls back to `Structured::other` masks and accepts general constant masks. I kept the `mask_cond` call and added this PR's two cases in front of it at this call site, together with the `WAVE_OPS` flag that `mask_cond` sets before `lane_bit`. The `structure.rs` change merges cleanly. Tests: 138 passed, 0 failed, including `v_cndmask_accepts_uniform_and_constant_masks`. **Together with #1423 on #1402.** One program that validates with #1423 alone fails again at "a lane-mask join of an untracked mask" (+213 instead of +214). On this data, this PR adds no gain on top of #1402 and costs that one program when stacked with #1423. Method: `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), dxil.dll 1.8.2502.11, compared program by program (25,889 programs). No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:05:58 +00:00
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!1221
No description provided.