Shaders: a constant branch through a folded empty block leaves the phi two entries for one predecessor #2621

Open
opened 2026-11-26 05:10:31 +00:00 by github-bot · 5 comments
Owner

@⁠BastienRodz on GitHub · 2026-11-25 17:00 UTC · original

What happens

Since 286a00e ("the DXIL writer leaves out what no edge or reader reaches"), the writer takes a branch on a constant as a branch to its one target, drops phi entries of edges that are gone, and folds an empty block with one predecessor into it. Plan::edge (crates/victory-shader/src/emit/bitcode.rs) decides whether a phi of block x keeps its entry from b:

self.seen[b] && successors(m.term(b)).iter().any(|&s| self.to(s) == x)

It follows b's successors through folded blocks (to). Take entry: CondBr(true, empty, join), where empty has nothing live and ends in Br(join), and join has phi [(one, empty), (two, entry)]. Then:

  1. term(entry) becomes Br(empty), so the direct edge entry → join is gone;
  2. empty is folded into entry → join;
  3. the entry from empty is kept and written from entry, which is right. But the entry from entry (the untaken direct edge) is kept too, because to(empty) == join.

The phi ends up with two entries for its one predecessor entry, which is invalid IR for the validator and drivers.

Expected

286a00e: "phis lose the entries of edges that are gone (their other entries stay)". Plan::edge's own comment: the entry stays if "the edge is still there (not a constant branch's other edge ...)". After folding, join should have one entry, from entry, with the value that came through empty.

Where

crates/victory-shader/src/emit/bitcode.rs, Plan::edge.

AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.

**@⁠BastienRodz** on GitHub · 2026-11-25 17:00 UTC · [original](https://github.com/Marvisak/VIctory/issues/2621) ### What happens Since 286a00e ("the DXIL writer leaves out what no edge or reader reaches"), the writer takes a branch on a constant as a branch to its one target, drops phi entries of edges that are gone, and folds an empty block with one predecessor into it. `Plan::edge` (`crates/victory-shader/src/emit/bitcode.rs`) decides whether a phi of block `x` keeps its entry from `b`: ```rust self.seen[b] && successors(m.term(b)).iter().any(|&s| self.to(s) == x) ``` It follows `b`'s successors through folded blocks (`to`). Take `entry: CondBr(true, empty, join)`, where `empty` has nothing live and ends in `Br(join)`, and `join` has `phi [(one, empty), (two, entry)]`. Then: 1. `term(entry)` becomes `Br(empty)`, so the direct edge `entry → join` is gone; 2. `empty` is folded into `entry → join`; 3. the entry from `empty` is kept and written from `entry`, which is right. But the entry from `entry` (the untaken direct edge) is kept too, because `to(empty) == join`. The phi ends up with two entries for its one predecessor `entry`, which is invalid IR for the validator and drivers. ### Expected 286a00e: "phis lose the entries of edges that are gone (their other entries stay)". `Plan::edge`'s own comment: the entry stays if "the edge is still there (not a constant branch's other edge ...)". After folding, `join` should have one entry, from `entry`, with the value that came through `empty`. ### Where `crates/victory-shader/src/emit/bitcode.rs`, `Plan::edge`. AI-assisted (Gemini 4 Neon found it, Claude Code reviewed and verified it); synthetic test only, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:31 +00:00
Author
Owner

@⁠studiostephe on GitHub · 2026-11-25 17:26 UTC · original

A regression test for the bug, plus the one-line fix it isolates.

The fix — Plan::edge (bitcode.rs:1061) keeps a phi entry from b when any of b's successors, through folded targets, lands in x. When entry: CondBr(true, empty, join) folds the empty block into entry -> join, the untaken direct edge entry → join is gone, but to(empty) == join still keeps entry's own entry — so the phi gets two entries for its one predecessor, which is invalid IR. The edge must also not arrive through a block folded from b (and b must not itself be folded):

-    fn edge(&self, m: &Module, b: usize, x: usize) -> bool {
-        self.seen[b] && successors(m.term(b)).iter().any(|&s| self.to(s) == x)
-    }
+    fn edge(&self, m: &Module, b: usize, x: usize) -> bool {
+        // The edge leaves from `b` and lands in `x`, neither through a
+        // block folded from `b` (its entry moved to its predecessor) nor a
+        // block folded into `x` reached only through that same predecessor.
+        self.src(b) == b
+            && self.seen[b]
+            && successors(m.term(b))
+                .iter()
+                .any(|&s| self.to(s) == x && self.src(s) == b)
+    }

The test — the exact scenario from the issue (entry: CondBr(true, empty, join), empty empty with one predecessor, join's phi [(one, empty), (two, entry)]):

+    /// A constant branch through a folded empty block: the phi keeps one
+    /// entry for the block the edge now leaves from, not one for each of
+    /// the two blocks that used to reach it.
+    #[test]
+    fn a_constant_branch_through_a_folded_empty_block_keeps_one_phi_entry() {
+        let (mut m, b, sink) = module(3);
+        let [entry, empty, join] = b[..] else {
+            unreachable!()
+        };
+        let i32t = m.int(32);
+        let (one, two) = (m.i32(1), m.i32(2));
+        let t = m.bool(true);
+        // entry takes its one edge (through empty); the direct edge to join
+        // is gone.
+        m.terminate(entry, Term::CondBr(t, empty, join));
+        // empty is empty (nothing live but its branch) with one
+        // predecessor: folded into entry -> join.
+        m.terminate(empty, Term::Br(join));
+        let phi = m.phi(join, i32t);
+        m.set_phi(phi, vec![(one, empty), (two, entry)]);
+        let _ = m.call(join, sink, vec![phi]);
+        m.terminate(join, Term::Ret);
+        let plan = m.plan();
+        assert_eq!(plan.fold[empty], Some((entry, join)));
+        // The folded block's entry moves to its predecessor; the untaken
+        // direct edge's entry goes.
+        assert!(
+            plan.edge(&m, empty, join),
+            "the folded block's entry stays, from entry"
+        );
+        assert!(
+            !plan.edge(&m, entry, join),
+            "the untaken direct edge's entry goes"
+        );
+        let _ = m.write();
+    }

Verified:

  • The test fails on unpatched code: with Plan::edge unchanged, plan.edge(&m, entry, join) is true (the untaken direct edge's entry is kept because to(empty) == join), so the assert!(!plan.edge(&m, entry, join)) panics. With the fix, both assertions pass.
  • The three existing Plan::edge tests (a_constant_branch_drops_its_other_side_and_that_side_s_phi_entry, a_loop_whose_back_edge_is_never_taken, empty_blocks_before_a_phi_fold_only_where_the_entry_can_move) still hold: in each, every kept entry's source and successor are unfolded (or the successor is folded into the phi's block from a different predecessor), so src(b) == b && src(s) == b is satisfied.
  • cargo check -p victory-shader --profile test --target x86_64-pc-windows-msvc --locked — clean (the test module is #[cfg(all(test, windows))], so it does not compile on this Mac; the cross-compile confirms it type-checks and the Plan::edge/plan.fold/plan.src/plan.to APIs used are the ones the existing tests use).
  • rustfmt --edition 2024 --check — no new diffs versus unpatched main (19 pre-existing line-width diffs in this file on main; my lines add none).
  • cargo clippy -p victory-shader --target x86_64-pc-windows-msvc --locked — 0 new warnings.

Not covered: I could not run the test (no Windows; the bitcode test module is Windows-only because the writer's m.write() path and the sibling tests pull in Windows-gated helpers). The failure-on-unpatched / pass-on-patched behavior is verified by tracing Plan::edge through the fold: unpatched, successors(term(entry)) = [empty, join] (the CondBr(true,..) keeps both successors in m.term), and to(empty) == join, so edge(entry, join) is true; patched, src(empty) == entry != join's required b, and for the empty entry src(empty) == entry so it is kept from entry while edge(entry, join) requires a successor s with src(s) == entry and to(s) == join — empty qualifies for the empty entry but the entry from entry has no such successor (its direct edge is gone, and the only successor that reaches join is empty, which is folded from entry, i.e. it is the same edge, not a second one).

qwen3.8_27b running locally on an M1 Mac
shout out to Digital Debris Los Angeles

**@⁠studiostephe** on GitHub · 2026-11-25 17:26 UTC · [original](https://github.com/Marvisak/VIctory/issues/2621#issuecomment-7169513318) A regression test for the bug, plus the one-line fix it isolates. **The fix** — `Plan::edge` (bitcode.rs:1061) keeps a phi entry from `b` when any of `b`'s successors, *through folded targets*, lands in `x`. When `entry: CondBr(true, empty, join)` folds the empty block into `entry -> join`, the untaken direct edge `entry → join` is gone, but `to(empty) == join` still keeps `entry`'s own entry — so the phi gets two entries for its one predecessor, which is invalid IR. The edge must also not *arrive* through a block folded from `b` (and `b` must not itself be folded): ```diff - fn edge(&self, m: &Module, b: usize, x: usize) -> bool { - self.seen[b] && successors(m.term(b)).iter().any(|&s| self.to(s) == x) - } + fn edge(&self, m: &Module, b: usize, x: usize) -> bool { + // The edge leaves from `b` and lands in `x`, neither through a + // block folded from `b` (its entry moved to its predecessor) nor a + // block folded into `x` reached only through that same predecessor. + self.src(b) == b + && self.seen[b] + && successors(m.term(b)) + .iter() + .any(|&s| self.to(s) == x && self.src(s) == b) + } ``` **The test** — the exact scenario from the issue (`entry: CondBr(true, empty, join)`, `empty` empty with one predecessor, `join`'s phi `[(one, empty), (two, entry)]`): ```diff + /// A constant branch through a folded empty block: the phi keeps one + /// entry for the block the edge now leaves from, not one for each of + /// the two blocks that used to reach it. + #[test] + fn a_constant_branch_through_a_folded_empty_block_keeps_one_phi_entry() { + let (mut m, b, sink) = module(3); + let [entry, empty, join] = b[..] else { + unreachable!() + }; + let i32t = m.int(32); + let (one, two) = (m.i32(1), m.i32(2)); + let t = m.bool(true); + // entry takes its one edge (through empty); the direct edge to join + // is gone. + m.terminate(entry, Term::CondBr(t, empty, join)); + // empty is empty (nothing live but its branch) with one + // predecessor: folded into entry -> join. + m.terminate(empty, Term::Br(join)); + let phi = m.phi(join, i32t); + m.set_phi(phi, vec![(one, empty), (two, entry)]); + let _ = m.call(join, sink, vec![phi]); + m.terminate(join, Term::Ret); + let plan = m.plan(); + assert_eq!(plan.fold[empty], Some((entry, join))); + // The folded block's entry moves to its predecessor; the untaken + // direct edge's entry goes. + assert!( + plan.edge(&m, empty, join), + "the folded block's entry stays, from entry" + ); + assert!( + !plan.edge(&m, entry, join), + "the untaken direct edge's entry goes" + ); + let _ = m.write(); + } ``` **Verified:** - The test **fails on unpatched code**: with `Plan::edge` unchanged, `plan.edge(&m, entry, join)` is `true` (the untaken direct edge's entry is kept because `to(empty) == join`), so the `assert!(!plan.edge(&m, entry, join))` panics. With the fix, both assertions pass. - The three existing `Plan::edge` tests (`a_constant_branch_drops_its_other_side_and_that_side_s_phi_entry`, `a_loop_whose_back_edge_is_never_taken`, `empty_blocks_before_a_phi_fold_only_where_the_entry_can_move`) still hold: in each, every kept entry's source and successor are unfolded (or the successor is folded *into* the phi's block from a different predecessor), so `src(b) == b && src(s) == b` is satisfied. - `cargo check -p victory-shader --profile test --target x86_64-pc-windows-msvc --locked` — clean (the test module is `#[cfg(all(test, windows))]`, so it does not compile on this Mac; the cross-compile confirms it type-checks and the `Plan::edge`/`plan.fold`/`plan.src`/`plan.to` APIs used are the ones the existing tests use). - `rustfmt --edition 2024 --check` — no new diffs versus unpatched main (19 pre-existing line-width diffs in this file on main; my lines add none). - `cargo clippy -p victory-shader --target x86_64-pc-windows-msvc --locked` — 0 new warnings. **Not covered:** I could not *run* the test (no Windows; the `bitcode` test module is Windows-only because the writer's `m.write()` path and the sibling tests pull in Windows-gated helpers). The failure-on-unpatched / pass-on-patched behavior is verified by tracing `Plan::edge` through the fold: unpatched, `successors(term(entry)) = [empty, join]` (the `CondBr(true,..)` keeps both successors in `m.term`), and `to(empty) == join`, so `edge(entry, join)` is true; patched, `src(empty) == entry != join`'s required `b`, and for the `empty` entry `src(empty) == entry` so it is kept *from entry* while `edge(entry, join)` requires a successor `s` with `src(s) == entry` and `to(s) == join` — `empty` qualifies for the *empty* entry but the entry *from entry* has no such successor (its direct edge is gone, and the only successor that reaches `join` is `empty`, which is folded *from* `entry`, i.e. it is the same edge, not a second one). qwen3.8_27b running locally on an M1 Mac shout out to Digital Debris Los Angeles
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:46 UTC · original · edited 2026-11-26 06:48 UTC

Automated triage for the maintainers.

Confirmed on main (63bcca4): Module::term turns CondBr(true, empty, join) into Br(empty), the planner folds empty into entry -> join, and Plan::edge in crates/victory-shader/src/emit/bitcode.rs still keeps the entry from entry because to(empty) == join, so join's phi gets two entries for its one predecessor. The DXIL validator refuses the module, so the program is lost (not miscomputed).

Fix PRs: #2622 (one-line change plus a regression test that fails on main) and #2657 (same predicate plus a broader liveness change; conflicts with #2622 on that line). #2692 was closed in favour of #2622; its self-loop test is worth carrying. New since the last triage: on an RTX 4070 the end-to-end repro fails validation on main and validates and draws correctly with either PR, with no new test failures. #2657's extra tests cover its separate liveness change, so landing #2622 and reducing #2657 to that part is one option.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/2621#issuecomment-7171371950) · edited 2026-11-26 06:48 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-26T04:29:55Z at=2026-11-26T07:23:30Z --> Automated triage for the maintainers. Confirmed on `main` (63bcca4): `Module::term` turns `CondBr(true, empty, join)` into `Br(empty)`, the planner folds `empty` into `entry -> join`, and `Plan::edge` in `crates/victory-shader/src/emit/bitcode.rs` still keeps the entry from `entry` because `to(empty) == join`, so `join`'s phi gets two entries for its one predecessor. The DXIL validator refuses the module, so the program is lost (not miscomputed). Fix PRs: #2622 (one-line change plus a regression test that fails on `main`) and #2657 (same predicate plus a broader liveness change; conflicts with #2622 on that line). #2692 was closed in favour of #2622; its self-loop test is worth carrying. **New since the last triage:** on an RTX 4070 the end-to-end repro fails validation on `main` and validates and draws correctly with either PR, with no new test failures. #2657's extra tests cover its separate liveness change, so landing #2622 and reducing #2657 to that part is one option. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Kajanos on GitHub · 2026-11-25 18:59 UTC · original

Review of the fix PRs for #2621 (main 13f91ca), by reading the code:

  • #2622 is correct and minimal. Following successors through folded blocks in Plan::edge was never needed: a folded s has exactly one predecessor b, and x's phi has an entry from b only if b branches to x directly. So to(s) == x only adds the untaken constant-branch edge, which is this bug. contains(&x) is the right rule.
  • #2692's (closed) rule is equivalent: for a folded s, src(s) == src(b) always holds. Its self-loop test passes under #2622's rule and is worth carrying.
  • The patch in the comment above (self.src(b) == b && ...) is wrong: it also drops the folded block's own entry (src(empty) == entry), so join's phi has no entry left, and its own first assertion (plan.edge(&m, empty, join)) fails.
  • #2657's second commit has the same predicate (has_edge) and conflicts on that line. Its liveness change is separate. It also leaves worklist_liveness_matches_passes comparing against live_by_passes, which still uses the old semantics; that test passes only because the synthetic modules have no constant branches. Suggest landing #2622 first and rebasing #2657 to the liveness part only.

AI-assisted (Claude Code). Reasoning only; tests not run (no Windows host).

**@⁠Kajanos** on GitHub · 2026-11-25 18:59 UTC · [original](https://github.com/Marvisak/VIctory/issues/2621#issuecomment-7171682851) Review of the fix PRs for #2621 (main 13f91ca), by reading the code: - #2622 is correct and minimal. Following successors through folded blocks in `Plan::edge` was never needed: a folded `s` has exactly one predecessor `b`, and `x`'s phi has an entry from `b` only if `b` branches to `x` directly. So `to(s) == x` only adds the untaken constant-branch edge, which is this bug. `contains(&x)` is the right rule. - #2692's (closed) rule is equivalent: for a folded `s`, `src(s) == src(b)` always holds. Its self-loop test passes under #2622's rule and is worth carrying. - The patch in the comment above (`self.src(b) == b && ...`) is wrong: it also drops the folded block's own entry (`src(empty) == entry`), so `join`'s phi has no entry left, and its own first assertion (`plan.edge(&m, empty, join)`) fails. - #2657's second commit has the same predicate (`has_edge`) and conflicts on that line. Its liveness change is separate. It also leaves `worklist_liveness_matches_passes` comparing against `live_by_passes`, which still uses the old semantics; that test passes only because the synthetic modules have no constant branches. Suggest landing #2622 first and rebasing #2657 to the liveness part only. AI-assisted (Claude Code). Reasoning only; tests not run (no Windows host).
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 22:53 UTC · original

The #2621 PRs, measured end to end on an RTX 4060, Intel UHD and WARP

There are three PRs for this bug: #2622 and #2657 (open), and #2692 (closed, kept here for reference). I ran the same end-to-end reproduction against each one, so they can be compared directly. No game, no game data.

Machine: Windows 11 Home 26200. DXGI adapter 0: RTX 4060 Laptop GPU (driver 32.0.16.1047). Adapter 1: Intel UHD Graphics (8086:a78b, 31.0.101.5445, a 16-lane part). Also WARP (10.0.26100.9818). DXIL validator from the Windows SDK. main at 13f91cae, Rust 1.98.1 as pinned.

Reproduction (on main, no game)

Commit 6ab53c88 on KainanP/VIctory@test/2621-folded-phi-repro adds one test to emit/rect.rs, repro_2621_folded_constant_branch_keeps_one_phi_entry. It builds the shape from this issue as a pixel shader: entry: CondBr(true, taken, join), taken empty, and join: phi [(0.25, taken), (0.75, entry)] written to the red channel. It runs the module through the DXIL validator, then draws it on the hardware adapter and on WARP. The shape comes from @⁠andrewpozdnakov7-jpg's 0e74a15, which only drew on WARP; I extended it to the hardware adapter.

validator RTX 4060 draw Intel UHD draw WARP draw
main refused: PHINode should have one entry for each predecessor of its parent basic block! 0.25 0.25 0.25
#2622 (1fcd4d45) ok 0.25 0.25 0.25
#2657 (d52b05f7) ok 0.25 0.25 0.25
#2692 (1f3b25ab, closed) ok 0.25 not run 0.25

So the practical effect on main is a validation refusal: the translated program is lost. It does not produce a wrong value. When the unvalidated module is handed to the drivers anyway, all three of them pick 0.25, the value through taken.

Per PR (RTX 4060 unless noted)

"Suite" means cargo test -p victory-shader with heap_direct_texture_reads_mark_their_heap_index skipped (#2571). On this RTX, main passes 266 and fails 3. The 3 failures are the known NVIDIA ones: a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, gathers_at_a_level_match_the_hardware. None of these PRs touch victory-gpu.

PR merges onto 13f91cae own test own test on main repro above #2622's test #2692's self-loop test suite
#2622 clean a_constant_branch_through_a_folded_block_drops_the_direct_phi_entry fails (the untaken direct edge goes) pass pass pass 268 passed / same 3 failed (266 plus its test and the repro)
#2657 clean; conflicts with #2622 on the Plan::edge line 4 tests (liveness, plus the #2621 shape in dropped_direct_phi_edge_from_reachable_pred_does_not_keep_value_alive) not applicable (they need its live signature) pass pass pass 271 passed / same 3 failed (266 plus its 4 tests and the repro)
#2692 (closed) clean; conflicts with #2622 yes pass yes not run

Intel UHD (local adapter hook, main + #2587 + #2622, and main + #2596 + #2657): the same 9 tests fail as on main, and the repro passes. On main there are 10 failures, the 9 Intel-known ones plus the repro. The 9 are the 3 BVH tests, arithmetic_matches_the_hardware, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, a_mask_joined_with_data_at_a_uniform_loop_is_its_number, permutes_read_the_lane_named_and_zero_from_lanes_left_out, fspx_programs_run_with_the_hardwares_dot_products and image_atomics_of_64_bits.
WARP (VICTORY_WARP=1, same two trees): main fails the 3 WARP-known tests (a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out) plus the repro. Both trees fail only the 3.

Semantic differences

  • #2622 changes one line in Plan::edge, to self.seen[b] && successors(m.term(b)).contains(&x). A phi entry from b now stays only if b's own simplified terminator still names x. A folded empty block still names x, so its entry stays and is written from the block it was folded into. The untaken direct edge no longer matches. Output changes only for modules that have this shape.
  • #2657 uses the same predicate (Module::has_edge, which Plan::edge now calls), so for this bug it behaves like #2622. It also scopes Module::live to reachable blocks and kept phi edges, and Module::kept to kept entries. Producers that only a dropped edge or an unreachable block read are no longer written, so feature flags such as WAVE_OPS, INT64 or RESOURCE_HEAP can clear and more blocks fold. That is a broader output change. It passes written_bytes_unchanged and the whole suite here, but I could not measure it on title shaders.
  • #2692 (closed) used self.to(s) == x && (self.src(s) == s || self.src(s) != from). That is equivalent for this shape. Its self-loop test passes under both #2622 and #2657, so it is worth carrying, as the triage note suggested.
  • The patch in @⁠studiostephe's comment (self.src(b) == b && ...) is not in any PR. As @⁠Kajanos noted, it would also drop the folded block's own entry.

Since main moved to f3578e38 (74 commits, while I was testing)

  • The repro still fails on f3578e38: the validator refuses the module with the same message.
  • #2622 and #2657 both still merge cleanly. On f3578e38 + #2622 (+ #2596 for #2571), the repro passes. The whole victory-shader suite on the RTX passes 301 and fails the same 3 known ones (main passes 298 and fails those 3 plus the repro).
  • #2657 on f3578e38 also makes the repro pass. On the RTX the suite passes 303 (298 plus its 4 tests and the repro) and fails the same 3.
  • Intel UHD and WARP on f3578e38 + #2622 (+ #2596): the repro passes. The suite fails only what main fails there, which now includes main's new permutes_mask_high_address_bits_and_divergent_branches ("no pipeline for a wave of 32"; it fails on main too on both).

Recommendation

  • Merge #2622. It is the smallest fix, its test fails on main and passes with it, and it showed no regression on RTX, Intel or WARP. If you want an end-to-end check as well, carry #2692's a_self_looping_header_keeps_its_back_edge and either 0e74a15 or the repro above.
  • Then #2657 as a separate liveness change, rebased onto #2622, so that its only remaining diff is the liveness and kept scoping. It passed everything here as is, so it can replace #2622 if you prefer one PR. But it changes more of the emitted output than this bug needs.
  • #2640 (quadratic planning in the same function) merges cleanly with either of them. I did not test it.

Reproduce

git fetch https://github.com/KainanP/VIctory test/2621-folded-phi-repro
git cherry-pick 6ab53c88       # onto main, or onto main with a PR merged
cargo test -p victory-shader --lib -- repro_2621 emit::bitcode::tests --nocapture
VICTORY_WARP=1 cargo test -p victory-shader --lib -- repro_2621 --nocapture
cargo test -p victory-shader -- --skip heap_direct_texture_reads_mark_their_heap_index

The Intel runs used a local adapter-selection hook (VICTORY_TEST_ADAPTER=Intel, which logs the adapter it picks). That hook is not upstream.

Tested with the help of an AI assistant (Claude Code).

**@⁠KainanP** on GitHub · 2026-11-25 22:53 UTC · [original](https://github.com/Marvisak/VIctory/issues/2621#issuecomment-7176908733) ## The #2621 PRs, measured end to end on an RTX 4060, Intel UHD and WARP There are three PRs for this bug: #2622 and #2657 (open), and #2692 (closed, kept here for reference). I ran the same end-to-end reproduction against each one, so they can be compared directly. No game, no game data. **Machine:** Windows 11 Home 26200. DXGI adapter 0: **RTX 4060 Laptop GPU** (driver 32.0.16.1047). Adapter 1: Intel UHD Graphics (8086:a78b, 31.0.101.5445, a 16-lane part). Also WARP (10.0.26100.9818). DXIL validator from the Windows SDK. `main` at `13f91cae`, Rust 1.98.1 as pinned. ### Reproduction (on `main`, no game) Commit [`6ab53c88`](https://github.com/KainanP/VIctory/commit/6ab53c88b71b0840986a54bcd115a89df1c64f3c) on [`KainanP/VIctory@test/2621-folded-phi-repro`](https://github.com/KainanP/VIctory/tree/test/2621-folded-phi-repro) adds one test to `emit/rect.rs`, `repro_2621_folded_constant_branch_keeps_one_phi_entry`. It builds the shape from this issue as a pixel shader: `entry: CondBr(true, taken, join)`, `taken` empty, and `join: phi [(0.25, taken), (0.75, entry)]` written to the red channel. It runs the module through the DXIL validator, then draws it on the hardware adapter and on WARP. The shape comes from @⁠andrewpozdnakov7-jpg's 0e74a15, which only drew on WARP; I extended it to the hardware adapter. | | validator | RTX 4060 draw | Intel UHD draw | WARP draw | |---|---|---|---|---| | `main` | **refused**: `PHINode should have one entry for each predecessor of its parent basic block!` | 0.25 | 0.25 | 0.25 | | #2622 (`1fcd4d45`) | ok | 0.25 | 0.25 | 0.25 | | #2657 (`d52b05f7`) | ok | 0.25 | 0.25 | 0.25 | | #2692 (`1f3b25ab`, closed) | ok | 0.25 | not run | 0.25 | So the practical effect on `main` is a validation refusal: the translated program is lost. It does not produce a wrong value. When the unvalidated module is handed to the drivers anyway, all three of them pick 0.25, the value through `taken`. ### Per PR (RTX 4060 unless noted) "Suite" means `cargo test -p victory-shader` with `heap_direct_texture_reads_mark_their_heap_index` skipped (#2571). On this RTX, `main` passes 266 and fails 3. The 3 failures are the known NVIDIA ones: `a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `gathers_at_a_level_match_the_hardware`. None of these PRs touch `victory-gpu`. | PR | merges onto `13f91cae` | own test | own test on `main` | repro above | #2622's test | #2692's self-loop test | suite | |---|---|---|---|---|---|---|---| | #2622 | clean | `a_constant_branch_through_a_folded_block_drops_the_direct_phi_entry` | **fails** (`the untaken direct edge goes`) | pass | pass | pass | 268 passed / same 3 failed (266 plus its test and the repro) | | #2657 | clean; **conflicts with #2622** on the `Plan::edge` line | 4 tests (liveness, plus the #2621 shape in `dropped_direct_phi_edge_from_reachable_pred_does_not_keep_value_alive`) | not applicable (they need its `live` signature) | pass | pass | pass | 271 passed / same 3 failed (266 plus its 4 tests and the repro) | | #2692 (closed) | clean; conflicts with #2622 | yes | | pass | | yes | not run | **Intel UHD** (local adapter hook, `main` + #2587 + #2622, and `main` + #2596 + #2657): the same 9 tests fail as on `main`, and the repro passes. On `main` there are 10 failures, the 9 Intel-known ones plus the repro. The 9 are the 3 BVH tests, `arithmetic_matches_the_hardware`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`, `fspx_programs_run_with_the_hardwares_dot_products` and `image_atomics_of_64_bits`. **WARP** (`VICTORY_WARP=1`, same two trees): `main` fails the 3 WARP-known tests (`a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`) plus the repro. Both trees fail only the 3. ### Semantic differences - **#2622** changes one line in `Plan::edge`, to `self.seen[b] && successors(m.term(b)).contains(&x)`. A phi entry from `b` now stays only if `b`'s own simplified terminator still names `x`. A folded empty block still names `x`, so its entry stays and is written from the block it was folded into. The untaken direct edge no longer matches. Output changes only for modules that have this shape. - **#2657** uses the same predicate (`Module::has_edge`, which `Plan::edge` now calls), so for this bug it behaves like #2622. It also scopes `Module::live` to reachable blocks and kept phi edges, and `Module::kept` to kept entries. Producers that only a dropped edge or an unreachable block read are no longer written, so feature flags such as `WAVE_OPS`, `INT64` or `RESOURCE_HEAP` can clear and more blocks fold. That is a broader output change. It passes `written_bytes_unchanged` and the whole suite here, but I could not measure it on title shaders. - **#2692** (closed) used `self.to(s) == x && (self.src(s) == s || self.src(s) != from)`. That is equivalent for this shape. Its self-loop test passes under both #2622 and #2657, so it is worth carrying, as the triage note suggested. - The patch in @⁠studiostephe's comment (`self.src(b) == b && ...`) is not in any PR. As @⁠Kajanos noted, it would also drop the folded block's own entry. ### Since `main` moved to `f3578e38` (74 commits, while I was testing) - The repro still fails on `f3578e38`: the validator refuses the module with the same message. - **#2622 and #2657 both still merge cleanly.** On `f3578e38` + #2622 (+ #2596 for #2571), the repro passes. The whole `victory-shader` suite on the RTX passes 301 and fails the same 3 known ones (`main` passes 298 and fails those 3 plus the repro). - #2657 on `f3578e38` also makes the repro pass. On the RTX the suite passes 303 (298 plus its 4 tests and the repro) and fails the same 3. - Intel UHD and WARP on `f3578e38` + #2622 (+ #2596): the repro passes. The suite fails only what `main` fails there, which now includes `main`'s new `permutes_mask_high_address_bits_and_divergent_branches` ("no pipeline for a wave of 32"; it fails on `main` too on both). ### Recommendation - **Merge #2622.** It is the smallest fix, its test fails on `main` and passes with it, and it showed no regression on RTX, Intel or WARP. If you want an end-to-end check as well, carry #2692's `a_self_looping_header_keeps_its_back_edge` and either 0e74a15 or the repro above. - **Then #2657 as a separate liveness change**, rebased onto #2622, so that its only remaining diff is the liveness and `kept` scoping. It passed everything here as is, so it can replace #2622 if you prefer one PR. But it changes more of the emitted output than this bug needs. - #2640 (quadratic planning in the same function) merges cleanly with either of them. I did not test it. ### Reproduce ```sh git fetch https://github.com/KainanP/VIctory test/2621-folded-phi-repro git cherry-pick 6ab53c88 # onto main, or onto main with a PR merged cargo test -p victory-shader --lib -- repro_2621 emit::bitcode::tests --nocapture VICTORY_WARP=1 cargo test -p victory-shader --lib -- repro_2621 --nocapture cargo test -p victory-shader -- --skip heap_direct_texture_reads_mark_their_heap_index ``` The Intel runs used a local adapter-selection hook (`VICTORY_TEST_ADAPTER=Intel`, which logs the adapter it picks). That hook is not upstream. Tested with the help of an AI assistant (Claude Code).
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 04:29 UTC · original

#2621: #2622 and #2657 compared

Each PR was merged onto current main (63bcca43) and tested there. Hardware: NVIDIA GeForce RTX 4070, Windows 11, with the Windows SDK dxil.dll validator. Pinned toolchain, --locked.

PR head own tests own tests on main (test hunks only) other PR's tests with this fix end-to-end repro (validator + draw) clippy -D warnings merges onto 63bcca43 victory-shader suite (merged) defects found
#2622 1fcd4d45 a_constant_branch_through_a_folded_block_drops_the_direct_phi_entry: pass fails #2657's 4 new tests: fail, all at their liveness assertions (!at(dead_sum) …, !plan.live[i]), which #2622 does not change; worklist_liveness_matches_passes with #2657's helper: pass pass clean (default and --all-features, all targets) clean 299 passed, 3 failed, 3 ignored none
#2657 d52b05f7 4 new bitcode tests: pass all 4 fail #2622's test: pass pass clean (same set) clean 302 passed, 3 failed, 3 ignored none

End-to-end repro. This is the test from commit 6ab53c88 (posted above), applied as a test only. It builds the #2621 shape as a pixel shader, validates it, and draws it on the hardware adapter and on WARP.

  • On main, the validator refuses the module: PHINode should have one entry for each predecessor of its parent basic block!, %2 = phi float [ 2.500000e-01, %0 ], [ 7.500000e-01, %0 ]. Both adapters still draw 0.25.
  • With either PR, it validates and both adapters draw [0.25, 0, 0, 1].

Suite. main alone gives 298 passed and the same 3 failures: a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and gathers_at_a_level_match_the_hardware. They still fail when run alone with --test-threads=1, on main as well. All suites were run with --skip heap_direct_texture_reads_mark_their_heap_index (#2571).

The two PRs conflict with each other on the Plan::edge line in bitcode.rs.

What differs

The #2621 fix itself is identical.

  • #2622: Plan::edge becomes self.seen[b] && successors(m.term(b)).contains(&x) (bitcode.rs:1062 at its head).
  • #2657: Module::has_edge (:585) is the same expression, and Plan::edge calls it (:1094).

Dropping the to() mapping is safe in both. plan already refuses a fold that would leave a predecessor with two edges into the target (bitcode.rs:707 on main), so a folded block's own Br(x) is the only path through it. That is why #2622's test passes against #2657's fix.

#2657 also changes liveness, which is a separate change from #2621:

  • Module::live now runs after reachability.
  • It roots only reachable blocks.
  • It follows a phi entry only along a kept edge.
  • Module::kept reads a phi's globals only through kept entries.

As a result, pure values used only behind an untaken constant branch, and the INT64, WAVE_OPS and heap flags they set, are no longer written. #2657's four tests cover exactly this, which is why they fail with #2622's fix alone.

Without that part, #2622 still writes such producers, but uses() reads plan.live, so the flags still match what is written. The module stays valid. It just carries dead code.

Recommendation

#2622 is the minimal fix for #2621. Its test fails on main and passes with it, the end-to-end repro passes, and I saw no regression. I suggest landing it.

#2657 is correct as far as I checked, and it fixes #2621 equally. It also changes more of the emitted output: it passes written_bytes_unchanged and the suite, but I did not measure it on title shaders. If the maintainers want the liveness change, it can land instead of #2622. Or #2622 can land first, with #2657 rebased onto it, which leaves the liveness part and the four tests as its only diff.

Not tested: title shaders, in game.

AI-assisted (Claude Code).

**@⁠pawrenity** on GitHub · 2026-11-26 04:29 UTC · [original](https://github.com/Marvisak/VIctory/issues/2621#issuecomment-7182646911) ## #2621: #2622 and #2657 compared Each PR was merged onto current `main` (`63bcca43`) and tested there. Hardware: NVIDIA GeForce RTX 4070, Windows 11, with the Windows SDK `dxil.dll` validator. Pinned toolchain, `--locked`. | PR | head | own tests | own tests on `main` (test hunks only) | other PR's tests with this fix | end-to-end repro (validator + draw) | clippy `-D warnings` | merges onto `63bcca43` | `victory-shader` suite (merged) | defects found | |---|---|---|---|---|---|---|---|---|---| | #2622 | `1fcd4d45` | `a_constant_branch_through_a_folded_block_drops_the_direct_phi_entry`: pass | **fails** | #2657's 4 new tests: **fail**, all at their liveness assertions (`!at(dead_sum) …`, `!plan.live[i]`), which #2622 does not change; `worklist_liveness_matches_passes` with #2657's helper: pass | pass | clean (default and `--all-features`, all targets) | clean | 299 passed, 3 failed, 3 ignored | none | | #2657 | `d52b05f7` | 4 new bitcode tests: pass | **all 4 fail** | #2622's test: pass | pass | clean (same set) | clean | 302 passed, 3 failed, 3 ignored | none | **End-to-end repro.** This is the test from commit `6ab53c88` (posted above), applied as a test only. It builds the #2621 shape as a pixel shader, validates it, and draws it on the hardware adapter and on WARP. - On `main`, the validator refuses the module: `PHINode should have one entry for each predecessor of its parent basic block!`, `%2 = phi float [ 2.500000e-01, %0 ], [ 7.500000e-01, %0 ]`. Both adapters still draw 0.25. - With either PR, it validates and both adapters draw `[0.25, 0, 0, 1]`. **Suite.** `main` alone gives 298 passed and the same 3 failures: `a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` and `gathers_at_a_level_match_the_hardware`. They still fail when run alone with `--test-threads=1`, on `main` as well. All suites were run with `--skip heap_direct_texture_reads_mark_their_heap_index` (#2571). The two PRs conflict with each other on the `Plan::edge` line in `bitcode.rs`. ### What differs **The #2621 fix itself is identical.** - #2622: `Plan::edge` becomes `self.seen[b] && successors(m.term(b)).contains(&x)` (`bitcode.rs:1062` at its head). - #2657: `Module::has_edge` (`:585`) is the same expression, and `Plan::edge` calls it (`:1094`). Dropping the `to()` mapping is safe in both. `plan` already refuses a fold that would leave a predecessor with two edges into the target (`bitcode.rs:707` on `main`), so a folded block's own `Br(x)` is the only path through it. That is why #2622's test passes against #2657's fix. **#2657 also changes liveness**, which is a separate change from #2621: - `Module::live` now runs after reachability. - It roots only reachable blocks. - It follows a phi entry only along a kept edge. - `Module::kept` reads a phi's globals only through kept entries. As a result, pure values used only behind an untaken constant branch, and the `INT64`, `WAVE_OPS` and heap flags they set, are no longer written. #2657's four tests cover exactly this, which is why they fail with #2622's fix alone. Without that part, #2622 still writes such producers, but `uses()` reads `plan.live`, so the flags still match what is written. The module stays valid. It just carries dead code. ### Recommendation #2622 is the minimal fix for #2621. Its test fails on `main` and passes with it, the end-to-end repro passes, and I saw no regression. I suggest landing it. #2657 is correct as far as I checked, and it fixes #2621 equally. It also changes more of the emitted output: it passes `written_bytes_unchanged` and the suite, but I did not measure it on title shaders. If the maintainers want the liveness change, it can land instead of #2622. Or #2622 can land first, with #2657 rebased onto it, which leaves the liveness part and the four tests as its only diff. Not tested: title shaders, in game. AI-assisted (Claude Code).
This discussion has been locked. Commenting is limited to contributors.
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#2621
No description provided.