Shaders: lower v_cndmask_b32 selects on uniform scalar masks #1270

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/1270 into main
fuzeofficlal commented 2026-11-24 16:58:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T16:58:23Z.


Fixes #1115.

Summary

v_cndmask_b32 driven by a uniform scalar condition (s_cselect_b32 / s_cselect_b64 choosing between -1 and 0, or all-zero / all-ones scalar constants) is currently refused as "a select on an untracked mask" because Lanes only exports per-lane masks in Structured::masks.

  • Export non-derived v_cndmask_b32 masks whose ROBDD support references only Atom::Uniform(_) (including constant Bool::FALSE / Bool::TRUE and NULL) in Structured::uniform_selects, keyed by the destination SSA value of the select.
  • Keep uniform select masks out of Structured::masks / highs so subsequent scalar ALU uses of the same SGPR (e.g. s_xor_b32) do not trip reads_mask_as_data, and reject Wave64 pairs whose upper half was overwritten or arbitrary non-mask bit patterns (e.g. s_lshl_b32).
  • Lower matching selects directly through a scalar i1 condition in every shader stage without requiring waveGetLaneIndex or WAVE_OPS.

Verification

  • Unit tests in structure.rs and emit/lower.rs covering Wave32/Wave64 s_cselect -1, 0 / 0, -1, constants 0 / -1, scalar reuse of the mask SGPR with wave_ops == false, and continued refusal of shifted / half-clobbered masks.
  • Synthetic Wave32/Wave64 compute readback tests (uniform_select_masks_match_rdna2) validated with dxil.dll and executed on NVIDIA GeForce RTX 5090 and D3D12 WARP.
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings and cargo xtask policy pass.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587066174 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1270). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T16:58:23Z. --- Fixes #1115. ### Summary `v_cndmask_b32` driven by a uniform scalar condition (`s_cselect_b32` / `s_cselect_b64` choosing between `-1` and `0`, or all-zero / all-ones scalar constants) is currently refused as `"a select on an untracked mask"` because `Lanes` only exports per-lane masks in `Structured::masks`. - Export non-derived `v_cndmask_b32` masks whose ROBDD support references only `Atom::Uniform(_)` (including constant `Bool::FALSE` / `Bool::TRUE` and `NULL`) in `Structured::uniform_selects`, keyed by the destination SSA value of the select. - Keep uniform select masks out of `Structured::masks` / `highs` so subsequent scalar ALU uses of the same SGPR (e.g. `s_xor_b32`) do not trip `reads_mask_as_data`, and reject Wave64 pairs whose upper half was overwritten or arbitrary non-mask bit patterns (e.g. `s_lshl_b32`). - Lower matching selects directly through a scalar `i1` condition in every shader stage without requiring `waveGetLaneIndex` or `WAVE_OPS`. ### Verification - Unit tests in `structure.rs` and `emit/lower.rs` covering Wave32/Wave64 `s_cselect -1, 0` / `0, -1`, constants `0` / `-1`, scalar reuse of the mask SGPR with `wave_ops == false`, and continued refusal of shifted / half-clobbered masks. - Synthetic Wave32/Wave64 compute readback tests (`uniform_select_masks_match_rdna2`) validated with `dxil.dll` and executed on **NVIDIA GeForce RTX 5090** and **D3D12 WARP**. - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings` and `cargo xtask policy` pass.
catminou4 commented 2026-11-24 18:04:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:06:54Z.

Review: APPROVED


v_cndmask_b32 selects on wave-uniform scalar masks (s_cmp/s_cselect/s_mov of uniform values) no longer need lane_index/wave ops: structure.rs tracks uniform_selects and lower.rs consults them by destination value. The five wave32 cases + wave64 cases pin no-WAVE_OPS, and the s_xor_b32 case pins that later scalar ALU use of the mask does not re-trigger reads_mask_as_data. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 98 passed, 0 failed. Note: touches the same v_cndmask arm as #1084 (approved earlier) — whichever lands second will need a rebase; the two are complementary (uniform-select tracking vs untracked-mask lane-bit fallback).

<!-- greyfinch-sync:Marvisak/VIctory:review:6043853480 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1270#pullrequestreview-6043853480). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:06:54Z. **Review:** APPROVED --- v_cndmask_b32 selects on wave-uniform scalar masks (s_cmp/s_cselect/s_mov of uniform values) no longer need lane_index/wave ops: structure.rs tracks uniform_selects and lower.rs consults them by destination value. The five wave32 cases + wave64 cases pin no-WAVE_OPS, and the s_xor_b32 case pins that later scalar ALU use of the mask does not re-trigger reads_mask_as_data. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p victory-shader --locked`. Shader execution tests (valu_tests/host) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 98 passed, 0 failed. Note: touches the same v_cndmask arm as #1084 (approved earlier) — whichever lands second will need a rebase; the two are complementary (uniform-select tracking vs untracked-mask lane-bit fallback).
pablogonz12 commented 2026-11-24 18:05:37 +00:00 (Migrated from github.com)

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


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 — the uniform-mask selects in this capture were not refused before, so this is a no-regression result only.

Not tested: in-game.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138947393 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1270#issuecomment-7138947393). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-24T17:16:27Z. --- 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 — the uniform-mask selects in this capture were not refused before, so this is a no-regression result only. Not tested: in-game.
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:30Z.


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

Result: no count change against main.

Offline. I merged head 77eafaa 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,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 123, 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:7142664155 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1270#issuecomment-7142664155). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:50:30Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 77eafaa 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,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 123, 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).
upstream-sync closed this pull request 2026-11-25 01:06:06 +00:00
Marvisak commented 2026-11-25 01:08:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:36:20Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

v_cndmask_b32 on masks built by uniform s_cselect or constants: main's structure.rs tracks these (0b35b7fe, 8af04727; world programs on 'a select on an untracked mask' 288 to 0).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148686388 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1270#issuecomment-7148686388). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:36:20Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. v_cndmask_b32 on masks built by uniform s_cselect or constants: main's structure.rs tracks these (0b35b7fe, 8af04727; world programs on 'a select on an untracked mask' 288 to 0). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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