Shaders: a constant branch through a folded block drops its untaken phi entry #2620
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2622"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T17:00:23Z.
What's wrong
Plan::edge(286a00e) keeps a phi entry frombwhen one ofb's successors, followed through folded blocks, is the phi's block. Take a constant branchCondBr(true, empty, join)whose taken sideemptyis folded intoentry → join. The entry carried throughemptyis kept and written fromentry, but the entry for the untaken direct edgeentry → joinpasses as well (to(empty) == join). The phi then has two entries for its one predecessor, which is invalid IR.What the fix does
Plan::edgechecksb's own terminator, with constant branches taken as branches:successors(m.term(b)).contains(&x). A folded empty block still hasxas its successor, so its entry stays and is written from the block it was folded into (from/src, unchanged). The untaken direct edge no longer matches and is dropped. The existingPlan::edgetests (constant branch, never-taken back edge, empty-block folding) pass unchanged.Tests
New device-free
emit::bitcode::tests::a_constant_branch_through_a_folded_block_drops_the_direct_phi_entry:CondBr(true, empty, join)with an emptyemptyand a phi injoin. It checks thatemptyfolds, that its entry stays, and that the untaken direct entry goes.main(13f91ca) it fails:the untaken direct edge goes.emit::bitcode::testspass (13, 1 benchmark ignored). Run under Wine 10, x86_64-pc-windows-msvc.Not tested
No
dxil.dllhere, so not run through the validator, and no title shaders. How often lowering produces this shape (a guarded arm with nothing live behind a condition known to be constant) is not measured.Fixes #2621
AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T17:30:22Z.
Independent Windows verification of PR #2622 (head
1fcd4d4), device-free bitcode regression plus broader CPU/hardware suite.Toolchain: rustc/cargo 1.100.0, Windows MSVC (repo pins 1.98.1; no clippy or rustup used). Synthetic inputs only, no game data, no source edits, no competing PR.
cargo test --locked -p victory-shader --lib emit::bitcode::tests -- --test-threads=1: 13 passed, 1 ignored (bench), 260 filtered. The newa_constant_branch_through_a_folded_block_drops_the_direct_phi_entrypasses alongside the existing constant-branch, loop and empty-block folding controls.origin/main13f91ca: the new test name reports 0 tests (test absent).cargo test --locked -p victory-shader --lib -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index-> 267 passed, 3 failed, 3 ignored, 1 filtered. The three failures are hardware-specific and unrelated to this change:emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,emit::synthetic_tests::gathers_at_a_level_match_the_hardware. All three reproduce with identical assertions on unmodified base13f91ca.emit::memory_tests::heap_direct_texture_reads_mark_their_heap_indexterminates withSTATUS_ACCESS_VIOLATIONon both the PR head and unmodified base13f91ca, so it is environmental, not caused by this PR.No regression attributable to the PR found. AI-assisted (Hy4 flash).
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:49:22Z.
Reviewed: the fix is correct —
edge()must test literal successors, not plan-mapped ones. With a constantCondBr(t, empty, join),successors()returns only the taken edge, socontains(&x)is false for the dead direct edge (dropping its phi entry) while the folded-through edge still reports true. The oldto(s) == xform counted the folded path as a second edge from the same predecessor — exactly the duplicate-entry bug the test pins. CI green.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T18:07:19Z.
Tested
1fcd4d45merged cleanly ontomain(13f91ca) on Windows 11 with NVIDIA GeForce RTX 5090 (32.0.16.1656) and D3D12 WARP + Windows SDKdxil.dll:cargo test -p victory-shader --lib emit::bitcode::tests: 13 passed, 0 failed, 1 ignored (a_constant_branch_through_a_folded_block_drops_the_direct_phi_entrypasses)VICTORY_WARP=1 cargo test -p victory-shader --lib: 268 passed, 3 failed, 3 ignored (allbitcode,flow,memory,valu,semantics,lower, anddxil.dllvalidation tests pass; the 3 failures are the expected 32-lane/hardware-onlysynthetic_testsunder forced WARP)cargo clippy -p victory-shader --all-targets -- -D warnings: clean (0 warnings)Checked
Plan::edge(self.seen[b] && successors(m.term(b)).contains(&x)): cleanly handles both single and chained collapsed empty blocks while dropping untaken direct edges from constant branches.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T18:16:41Z.
I tested the emitted pixel shader against DXIL validator 1.9.2609 and drew it on WARP. On main
13f91caee2, validation reports two entries for one phi predecessor, with 0.25 and 0.75 both coming from the same block. On this PR at1fcd4d450b, the same shader validates and all four pixels read back as [0.25, 0, 0, 1]. I ran six paired checks across both debug settings.The bitcode tests passed 13 with one benchmark ignored; both draw tests passed. The serial shader suite moved from 267 passed, 4 failed, 3 ignored to 269 passed, 3 failed, 3 ignored. The three remaining failures are the same gather, permute, and edge-flagged mesh tests on both revisions. Strict shader Clippy and asset policy passed.
Test-only commit 0e74a15 is directly on your current head if you want the validator and pixel readback in addition to the existing structural test. Please retain the Git author if you cherry-pick it, or add this trailer if you fold it into another commit:
Co-authored-by: andrewpozdnakov7-jpg [email protected]
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T18:17:10Z.
Thanks for checking it end to end — the validator result on main (two entries for one predecessor, 0.25 and 0.75) and the readback on this head are exactly the before/after the PR claims.
I'll keep the PR to
bitcode.rsand its structural test, so it stays a one-file change. Your test lives inemit/rect.rsbeside the rectangle draws, and it needs a validator or a host device to say anything. If the maintainer would rather have the end-to-end check in this PR, I'll cherry-pick 0e74a15 with your authorship kept.upstream-sync referenced this pull request2026-11-25 23:06:08 +00:00
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:19:13Z.
Automated triage for the maintainers.
Recommended for a maintainer's look.
Plan::edgeincrates/victory-shader/src/emit/bitcode.rsnow asks whetherxis a successor ofb's own terminator instead of following successors through folded blocks. I checked thatModule::termalready turns a constantCondBrinto aBrto the taken side, so forCondBr(true, empty, join)withemptyfolded, the entry fromentry(the untaken direct edge) is dropped while the entry from the foldedemptystays and is written fromentry; onmainboth passed, giving the phi two entries for one predecessor. A reviewer in the thread confirmed the DXIL validator rejects the shader onmainand accepts it with this change. One-line fix plus a device-free test; merges cleanly, CIcheckpassing. Fixes #2621.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-25T22:53:57Z.
Measured against #2657 and #2692 with an end-to-end repro (DXIL validator plus a draw on RTX 4060, Intel UHD and WARP). The repro passes, your test fails on
mainand passes here, and there are no regressions, also onf3578e38. Recommended in the comparison: https://github.com/Marvisak/VIctory/issues/2621#issuecomment-7176908733 (AI-assisted)Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:14:46Z.
Review: APPROVED
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64:Plan::edgepreviously checkedsuccessors(m.term(b)).iter().any(|&s| self.to(s) == x), which misclassified an untaken direct edge from a constant branch as live whenever its taken branch went through an empty block that folded intox. Switching tosuccessors(m.term(b)).contains(&x)cleanly fixes the duplicate-predecessor phi emission without affecting folded-block edges.cargo test -p victory-shader emit::bitcode::tests: 13 passed, 0 failed (includinga_constant_branch_through_a_folded_block_drops_the_direct_phi_entry).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:49:22Z.
Review: APPROVED
Reviewed at
1fcd4d450b0a5c0ede77beef50e0381b9a969f0a— APPROVE.Verification
cargo xtask policy(191 files ok),cargo clippy -p victory-shader --all-targets --all-features -- -D warnings, andrustfmt --edition 2024 --check(zero new formatting diffs) all passed.Plan::edge(crates/victory-shader/src/emit/bitcode.rs:1073) across multi-level folded block chains (P -> A -> B -> J), loop backedges, and theplan()fold guard:to()/src()keep folded phi incoming edges paired with their surviving predecessor while dropping untaken direct edges after constant branch simplification. Unlike full liveness pruning,live()is unchanged here, souses()and emitted shader flags stay consistent for DXIL validation.emit::bitcode::tests(13/13, 1 benchmark ignored, includinga_constant_branch_through_a_folded_block_drops_the_direct_phi_entry),emit::shader::tests(1/1),emit::lower::tests(33/33), andemit::tests::constant_color_validates.Non-blocking notes
kept()(bitcode.rs:622) still scans allOp::Phioperands regardless ofplan.edge(harmless for current lowering, which does not place internal globals directly in phi incoming slots).bitcode.rs:1529) with a two-block empty latch chain would also exercise transitiveto()/src()remapping directly.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.