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

Open
github-bot wants to merge 1 commit from github-bot/gh-1473 into main AGit
Owner

@⁠Texbirds on GitHub · 2026-11-24 18:17 UTC · original
Texbirds:fix/shader-mixed-export-discard → main · +201 −19 · 2 files · 1 commits · open

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.
**@⁠Texbirds** on GitHub · 2026-11-24 18:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1473) `Texbirds:fix/shader-mixed-export-discard` → `main` · +201 −19 · 2 files · 1 commits · open ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:06 +00:00
Author
Owner

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

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

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1473#issuecomment-7143217496) ### 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:28 UTC · original · edited 2026-11-25 16:44 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 03:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1473#issuecomment-7151948860) · edited 2026-11-25 16:44 UTC <!-- 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)_
Author
Owner

@⁠Texbirds on GitHub · 2026-11-25 12:14 UTC · original

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** on GitHub · 2026-11-25 12:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1473#issuecomment-7162112437) 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]`).
Author
Owner

@⁠Texbirds on GitHub · 2026-11-25 16:31 UTC · original

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.

**@⁠Texbirds** on GitHub · 2026-11-25 16:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1473#issuecomment-7168124494) 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`.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 18:42 UTC · original · approved these changes

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.

**@⁠catminou4** on GitHub · 2026-11-24 18:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1473#pullrequestreview-6045233733) · **approved these changes** 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:47 UTC · original · approved these changes

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

**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1473#pullrequestreview-6079150060) · **approved these changes** 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`).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1473/head:github-bot/gh-1473'
git switch 'github-bot/gh-1473'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1473'
git switch 'github-bot/gh-1473'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1473'
git switch 'github-bot/gh-1473'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1473'
git switch 'main'
git merge --squash 'github-bot/gh-1473'
git switch 'main'
git merge --ff-only 'github-bot/gh-1473'
git switch 'main'
git merge 'github-bot/gh-1473'
git push origin 'main'
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!1473
No description provided.