Shaders: track per-lane export state across mixed pixel-shader joins #1472

Open
Texbirds wants to merge 1 commit from upstream-pr/1473 into main
Texbirds commented 2026-11-24 18:17:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-24T18:17:49Z.


Problem

In crates/victory-shader/src/emit/lower.rs, pixel-shader exit lowering tracked exported[b] as a single boolean (preds.all(exported_out)). When an exporting branch and a killed/non-exporting branch merge into a shared s_endpgm block b, exported[b] evaluates to false, and LaneExit::End emits dx.op.discard(true) unconditionally—discarding pixels that already exported valid color. Single-pass RPO evaluation can also under-approximate exported[b] across loop back-edges.

Fix

  • Replace exported: Vec<bool> with ExportState::{Never, Always, Dynamic(V)} computed via a fixpoint over reachable blocks (all and any paths having executed a done export).
  • Uniformly exported (Always) and uniformly killed (Never) exit blocks emit the exact same DXIL as before with zero extra overhead.
  • Mixed joins (Dynamic(phi)) allocate an i1 phi filled in fill_phis and emit dx.op.discard(!exported) at LaneExit::End, discarding only the lanes that never exported.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5477846779 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1473). Originally posted by [Texbirds](https://github.com/Texbirds) on 2026-11-24T18:17:49Z. --- ### Problem In `crates/victory-shader/src/emit/lower.rs`, pixel-shader exit lowering tracked `exported[b]` as a single boolean (`preds.all(exported_out)`). When an exporting branch and a killed/non-exporting branch merge into a shared `s_endpgm` block `b`, `exported[b]` evaluates to `false`, and `LaneExit::End` emits `dx.op.discard(true)` unconditionally—discarding pixels that already exported valid color. Single-pass RPO evaluation can also under-approximate `exported[b]` across loop back-edges. ### Fix - Replace `exported: Vec<bool>` with `ExportState::{Never, Always, Dynamic(V)}` computed via a fixpoint over reachable blocks (`all` and `any` paths having executed a `done` export). - Uniformly exported (`Always`) and uniformly killed (`Never`) exit blocks emit the exact same DXIL as before with zero extra overhead. - Mixed joins (`Dynamic(phi)`) allocate an `i1` phi filled in `fill_phis` and emit `dx.op.discard(!exported)` at `LaneExit::End`, discarding only the lanes that never exported.
catminou4 commented 2026-11-24 18:42:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T18:42:13Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and were not run here; lowering/structure coverage only.

Per-lane export state for mixed pixel-shader joins: exported becomes Never/Always/Dynamic(i1 phi) computed by all/any fixpoints over reachable preds (loop-safe, unlike the old single RPO pass), and LaneExit::End discards with xor(exported, true) so only non-exported lanes are killed at a mixed join. The phi is filled from each pred's state (has_done_export → true). Static review checks out; the behavior is only observable in execution tests (Windows-only) — please confirm with the valu suite before merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045233733 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1473#pullrequestreview-6045233733). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T18:42:13Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 96 passed, 0 failed. Execution/valu tests are `#[cfg(all(test, windows))]` and were not run here; lowering/structure coverage only. Per-lane export state for mixed pixel-shader joins: `exported` becomes `Never`/`Always`/`Dynamic(i1 phi)` computed by `all`/`any` fixpoints over reachable preds (loop-safe, unlike the old single RPO pass), and `LaneExit::End` discards with `xor(exported, true)` so only non-exported lanes are killed at a mixed join. The phi is filled from each pred's state (`has_done_export` → true). Static review checks out; the behavior is only observable in execution tests (Windows-only) — please confirm with the valu suite before merge.
sinan-cmyk commented 2026-11-24 21:03:25 +00:00 (Migrated from github.com)

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


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

Result: no count change against main.

Offline. I merged head 826a97f 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 120, 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:7143217496 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1473#issuecomment-7143217496). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:13:36Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 826a97f 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 120, 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 04:06:53 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Merge candidate.

In emit/lower.rs, the exported: Vec<bool> per block becomes ExportState::{Never, Always, Dynamic(i1 phi)}. It is computed by two fixpoints over reachable blocks: a greatest fixpoint for "every path exported" and a least one for "some path exported". LaneExit::End now discards only the lanes whose phi says they never exported, so it no longer kills every lane at a mixed join. Uniform exits emit the same DXIL as before. The phi incomings in fill_phis use the same tail/edges pattern as the other phis there. The two points from the earlier review are addressed: there is no xor on the kill value, and the new test mixed_export_join_discards_only_non_exporting_lanes draws on hardware and on WARP. It checks that skipped lanes are discarded and that exporting lanes keep their colour. The rebase onto 67e8ae1 only kept EntryAddress next to the new enum.

CI (check): passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151948860 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1473#issuecomment-7151948860). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:28:32Z. --- <!-- victory-triage v1 head=6d804953989fef73d22430d43c58a4a67084e509 verdict=merge-candidate at=2026-11-25T16:42:19Z --> Automated triage for the maintainers. **Merge candidate.** In `emit/lower.rs`, the `exported: Vec<bool>` per block becomes `ExportState::{Never, Always, Dynamic(i1 phi)}`. It is computed by two fixpoints over reachable blocks: a greatest fixpoint for "every path exported" and a least one for "some path exported". `LaneExit::End` now discards only the lanes whose phi says they never exported, so it no longer kills every lane at a mixed join. Uniform exits emit the same DXIL as before. The phi incomings in `fill_phis` use the same `tail`/`edges` pattern as the other phis there. The two points from the earlier review are addressed: there is no `xor` on the kill value, and the new test `mixed_export_join_discards_only_non_exporting_lanes` draws on hardware and on WARP. It checks that skipped lanes are discarded and that exporting lanes keep their colour. The rebase onto `67e8ae1` only kept `EntryAddress` next to the new enum. CI (`check`): passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Texbirds commented 2026-11-25 13:02:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T12:14:44Z.


Rebased onto main (940d32f) and addressed both triage points in 836ce81 (CI check is now passing):

  1. Removed xor on the kill condition: ExportState::Dynamic(V) now tracks killed: i1 directly (false from has_done_export / Always predecessors, true from Never predecessors) and passes the phi straight to dx.op.discard.
  2. Added an end-to-end execution test (mixed_export_join_discards_only_non_exporting_lanes): Models the console pattern where v_cmpx_lt_f32 narrows EXEC and s_cbranch_execz jumps past exp mrt0 ... done straight to a shared s_endpgm, creating a mixed join at the exit block. The test lowers the pixel shader, validates the DXIL with dxil.dll, and renders a 16×16 target on hardware + WARP verifying that lanes skipping the export (x < 4) are discarded ([0.0; 4]) while exporting lanes (x >= 4) keep their exported color ([1.0, 0.5, 0.0, 1.0]).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7162112437 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1473#issuecomment-7162112437). Originally posted by [Texbirds](https://github.com/Texbirds) on 2026-11-25T12:14:44Z. --- Rebased onto `main` (`940d32f`) and addressed both triage points in `836ce81` (CI `check` is now passing): 1. **Removed `xor` on the kill condition:** `ExportState::Dynamic(V)` now tracks `killed: i1` directly (`false` from `has_done_export` / `Always` predecessors, `true` from `Never` predecessors) and passes the phi straight to `dx.op.discard`. 2. **Added an end-to-end execution test (`mixed_export_join_discards_only_non_exporting_lanes`):** Models the console pattern where `v_cmpx_lt_f32` narrows `EXEC` and `s_cbranch_execz` jumps past `exp mrt0 ... done` straight to a shared `s_endpgm`, creating a mixed join at the exit block. The test lowers the pixel shader, validates the DXIL with `dxil.dll`, and renders a 16×16 target on hardware + WARP verifying that lanes skipping the export (`x < 4`) are discarded (`[0.0; 4]`) while exporting lanes (`x >= 4`) keep their exported color (`[1.0, 0.5, 0.0, 1.0]`).
Texbirds commented 2026-11-25 17:05:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T16:31:45Z.


Rebased onto main (67e8ae1) in 6d80495. The only conflict was the new EntryAddress type alias next to ExportState, and I kept both. ExportState, the kill phi and mixed_export_join_discards_only_non_exporting_lanes are unchanged from 836ce81.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7168124494 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1473#issuecomment-7168124494). Originally posted by [Texbirds](https://github.com/Texbirds) on 2026-11-25T16:31:45Z. --- Rebased onto `main` (`67e8ae1`) in `6d80495`. The only conflict was the new `EntryAddress` type alias next to `ExportState`, and I kept both. `ExportState`, the kill phi and `mixed_export_join_discards_only_non_exporting_lanes` are unchanged from `836ce81`.
fuzeofficlal commented 2026-11-26 18:47:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:47:26Z.

Review: APPROVED


Verified 6d804953989fef73d22430d43c58a4a67084e509 cleanly merged onto main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK dxil.dll):

  • CFG / PHI soundness: ExportState::{Never, Always, Dynamic(V)} (crates/victory-shader/src/emit/lower.rs:188-195, 1336-1392) computes the per-block export state via greatest/least fixpoints across reachable predecessors (including back-edges), fills killed: i1 PHIs directly through tail/edges without an xor, and emits no duplicate output stores at LaneExit::End.
  • Policy & size: emit/lower.rs reaches 523,916 B on 63bcca43 (only 372 B below the 524,288 B cap, so merge ordering with other lower.rs PRs or splitting tests out should be kept in mind). cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed (asset policy: 191 files ok).
  • Clippy & tests: cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features) is clean; emit::tests::mixed_export_join_discards_only_non_exporting_lanes (0.32s on RTX 5090), emit::tests:: (18 passed, 0 failed on both RTX 5090 and WARP), and emit::lower::tests:: (33 passed, 0 failed on both RTX 5090 and WARP) all pass.

Ready to merge (noting the tight 372 B headroom on emit/lower.rs).

<!-- greyfinch-sync:Marvisak/VIctory:review:6079150060 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1473#pullrequestreview-6079150060). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T18:47:26Z. **Review:** APPROVED --- Verified `6d804953989fef73d22430d43c58a4a67084e509` cleanly merged onto `main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK `dxil.dll`): - **CFG / PHI soundness**: `ExportState::{Never, Always, Dynamic(V)}` (`crates/victory-shader/src/emit/lower.rs:188-195, 1336-1392`) computes the per-block export state via greatest/least fixpoints across reachable predecessors (including back-edges), fills `killed: i1` PHIs directly through `tail`/`edges` without an `xor`, and emits no duplicate output stores at `LaneExit::End`. - **Policy & size**: `emit/lower.rs` reaches **523,916 B** on `63bcca43` (only **372 B** below the 524,288 B cap, so merge ordering with other `lower.rs` PRs or splitting tests out should be kept in mind). `cargo test -p xtask --locked policy::tests::repository_passes_policy`: `1 passed` (`asset policy: 191 files ok`). - **Clippy & tests**: `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`) is clean; `emit::tests::mixed_export_join_discards_only_non_exporting_lanes` (`0.32s` on RTX 5090), `emit::tests::` (`18 passed, 0 failed` on both RTX 5090 and WARP), and `emit::lower::tests::` (`33 passed, 0 failed` on both RTX 5090 and WARP) all pass. Ready to merge (noting the tight 372 B headroom on `emit/lower.rs`).
Dukestar69 commented 2026-11-27 00:32:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T00:32:12Z.

Review: APPROVED


LGTM — verified on Windows (RTX 5090 + WARP):

  • cargo test -p victory-shader --lib emit::tests:: passed (18/18, including the new mixed_export_join_discards_only_non_exporting_lanes)
  • cargo test -p victory-shader --lib emit::lower::tests:: passed (33/33)
  • The ExportState::{Never, Always, Dynamic(phi)} dataflow tracking cleanly avoids discarding already-exported lanes at mixed pixel-shader joins into s_endpgm
  • cargo clippy -p victory-shader --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6081980865 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1473#pullrequestreview-6081980865). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T00:32:12Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090 + WARP): - `cargo test -p victory-shader --lib emit::tests::` passed (18/18, including the new `mixed_export_join_discards_only_non_exporting_lanes`) - `cargo test -p victory-shader --lib emit::lower::tests::` passed (33/33) - The `ExportState::{Never, Always, Dynamic(phi)}` dataflow tracking cleanly avoids discarding already-exported lanes at mixed pixel-shader joins into `s_endpgm` - `cargo clippy -p victory-shader --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/1473:upstream-pr/1473'
git switch 'upstream-pr/1473'

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