Shader: propagate float values across selects/phis and cache bools across dominators #1397

Open
wbkepler wants to merge 1 commit from upstream-pr/1397 into main
wbkepler commented 2026-11-24 17:43:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T17:43:35Z.


Summary

Rebased cleanly onto upstream/main (ffe310e):

  • Adds Val::F32 in emit/lower.rs and infer_float_phis so float ALU results, float inputs/interpolations, non-d16 image/typed-buffer loads, guarded float writes, float v_mov_b32/v_cndmask_b32, and float-only SSA phis stay native f32 without eager f32<->i32 bitcast roundtrips.
  • Folds identity, constant i32<->f32/undef, and bitcast(bitcast(x)) roundtrips directly in bitcode::Module::cast, and constructs f32 constants directly in Lower::fsrc.
  • Tracks DXIL block immediate dominators (dxil_idom) from ir::idoms, guarded splits, and critical edges so Lower::boolean and Lower::atom reuse dominating i1 values without leaking across non-dominating sibling blocks.
  • Adds 3 unit and hardware/WARP execution tests verifying zero-bitcast float phi/select lowering, dominator bool caching, and sibling non-dominating branch execution parity.

Verification

  • cargo clippy -p victory-shader --all-targets — passed
  • cargo test -p victory-shader — passed
  • cargo xtask policy — passed
<!-- greyfinch-sync:Marvisak/VIctory:issue:5477331580 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1397). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T17:43:35Z. --- ## Summary Rebased cleanly onto `upstream/main` (`ffe310e`): - Adds `Val::F32` in `emit/lower.rs` and `infer_float_phis` so float ALU results, float inputs/interpolations, non-`d16` image/typed-buffer loads, guarded float writes, float `v_mov_b32`/`v_cndmask_b32`, and float-only SSA phis stay native `f32` without eager `f32<->i32` bitcast roundtrips. - Folds identity, constant `i32<->f32`/`undef`, and `bitcast(bitcast(x))` roundtrips directly in `bitcode::Module::cast`, and constructs `f32` constants directly in `Lower::fsrc`. - Tracks DXIL block immediate dominators (`dxil_idom`) from `ir::idoms`, guarded splits, and critical edges so `Lower::boolean` and `Lower::atom` reuse dominating `i1` values without leaking across non-dominating sibling blocks. - Adds 3 unit and hardware/WARP execution tests verifying zero-bitcast float phi/select lowering, dominator bool caching, and sibling non-dominating branch execution parity. ## Verification - `cargo clippy -p victory-shader --all-targets` — passed - `cargo test -p victory-shader` — passed - `cargo xtask policy` — passed
catminou4 commented 2026-11-24 17:52:37 +00:00 (Migrated from github.com)

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

Review: APPROVED


Float phi inference + bool caching across dominators. infer_float_phis is a proper lattice (Const/Float/Int, Int absorbing): only phis whose every reachable arg is float-or-const with at least one float producer become native float phis — inputs are classified conservatively (only f32 vertex attributes and Position), float producers enumerated by opcode/format, and plain mov/cndmask propagate kinds with guard-aware old-value reads. The 32-iteration fixpoint cap is fine for a height-3 lattice. The DXIL idom mapping for the bool cache looks right (IR idom -> dominator tail block, self skipped). Bitcast same-type no-op is trivially correct. +2 macOS tests green; the valu/diff runs on Windows are the real check for the cache. 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/diff_tests) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 98 passed, 0 failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6044528586 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1397#pullrequestreview-6044528586). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:52:37Z. **Review:** APPROVED --- Float phi inference + bool caching across dominators. infer_float_phis is a proper lattice (Const/Float/Int, Int absorbing): only phis whose every reachable arg is float-or-const with at least one float producer become native float phis — inputs are classified conservatively (only f32 vertex attributes and Position), float producers enumerated by opcode/format, and plain mov/cndmask propagate kinds with guard-aware old-value reads. The 32-iteration fixpoint cap is fine for a height-3 lattice. The DXIL idom mapping for the bool cache looks right (IR idom -> dominator tail block, self skipped). Bitcast same-type no-op is trivially correct. +2 macOS tests green; the valu/diff runs on Windows are the real check for the cache. 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/diff_tests) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 98 passed, 0 failed.
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:32Z.


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

Result: no count change against main.

Offline. I merged head a78fc2c 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:7142664786 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1397#issuecomment-7142664786). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:50:32Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head a78fc2c 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).
Marvisak commented 2026-11-25 02:06:01 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149529996 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1397#issuecomment-7149529996). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:25:25Z. --- <!-- victory-triage v1 head=a78fc2cb8f3a66de90528a2c49df59bb8a16bc4f verdict=needs-rebase at=2026-11-25T01:25:23Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
pablogonz12 commented 2026-11-27 17:21:53 +00:00 (Migrated from github.com)

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


I checked one program offline on an RX 9070 XT with RADV. On current main it failed SPIR-V validation (0/1 pipelines); on this PR head (a78fc2cb8), it translated, validated, and created a pipeline (1/1). The PR did not apply cleanly to current main, so I tested the PR head rather than an isolated application on that base; other base differences could contribute. Not tested on NVIDIA hardware.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224323305 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1397#issuecomment-7224323305). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-27T17:21:53Z. --- I checked one program offline on an RX 9070 XT with RADV. On current main it failed SPIR-V validation (0/1 pipelines); on this PR head (`a78fc2cb8`), it translated, validated, and created a pipeline (1/1). The PR did not apply cleanly to current main, so I tested the PR head rather than an isolated application on that base; other base differences could contribute. Not tested on NVIDIA hardware.
pablogonz12 commented 2026-11-27 17:22:22 +00:00 (Migrated from github.com)

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


On RDNA4/RADV, program 321 passes on this PR head (1/1), but the change conflicts with current main and needs a rebase before I can verify it on that base.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224332199 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1397#issuecomment-7224332199). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-27T17:22:22Z. --- On RDNA4/RADV, program 321 passes on this PR head (1/1), but the change conflicts with current main and needs a rebase before I can verify it on that base.
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/1397:upstream-pr/1397'
git switch 'upstream-pr/1397'

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/1397'
git switch 'upstream-pr/1397'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1397'
git switch 'upstream-pr/1397'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1397'
git switch 'main'
git merge --squash 'upstream-pr/1397'
git switch 'main'
git merge --ff-only 'upstream-pr/1397'
git switch 'main'
git merge 'upstream-pr/1397'
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!1397
No description provided.