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

Manually merged
github merged 1 commit from gh-pr/1221/head into gh-pr/1221/base 2026-11-26 04:24:11 +00:00
Owner

@⁠bartikele on GitHub · 2026-11-24 16:30 UTC · original
bartikele:shader-cndmask-other-masks → main · +53 −7 · 2 files · 1 commits · merged 2026-11-25 00:21 UTC

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
**@⁠bartikele** on GitHub · 2026-11-24 16:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1221) `bartikele:shader-cndmask-other-masks` → `main` · +53 −7 · 2 files · 1 commits · merged 2026-11-25 00:21 UTC 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`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:24:09 +00:00
github manually merged commit 67c4f53109 into gh-pr/1221/base 2026-11-26 04:24:11 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 16:38 UTC · original

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.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 16:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7137983317) 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 17:02 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7138585312) 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.
Author
Owner

@⁠bartikele on GitHub · 2026-11-24 17:15 UTC · original

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.

**@⁠bartikele** on GitHub · 2026-11-24 17:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7138921825) 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.
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 17:27 UTC · original

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.

**@⁠pablogonz12** on GitHub · 2026-11-24 17:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7139221149) 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.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 17:59 UTC · original

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).

**@⁠Zipettte** on GitHub · 2026-11-24 17:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7140006619) 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)._
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 19:50 UTC · original

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** on GitHub · 2026-11-24 19:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7142666549) ### 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).
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:31 UTC · original

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).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1221#issuecomment-7143666117) ### 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://git.gtahub.st/github/Marvisak--VIctory/pulls/1221)). #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).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1221
No description provided.