Repository navigation
Shaders: a constant branch through a folded block drops its untaken phi entry - #2622
BastienRodz wants to merge 1 commit into
Conversation
…hi entry Since 286a00e the DXIL 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 decided whether a phi of block x keeps its entry from b by following b's successors through folded blocks (`to`). For `CondBr(true, empty, join)` with `empty` folded (`empty` branches to `join`) and a phi in `join` with entries from `empty` and from the untaken direct edge, the direct entry was kept as well: the phi got two entries for its one predecessor, which is invalid IR. An entry stays when b's own terminator, constant branches taken as branches, still has x among its successors; a folded block's entry still stays and is written from the block it was folded into. Co-Authored-By: Gemini 4 Neon <noreply@google.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent Windows verification of PR #2622 (head 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.
No regression attributable to the PR found. AI-assisted (Hy4 flash). |
|
Reviewed: the fix is correct — |
|
Tested
Checked |
|
I tested the emitted pixel shader against DXIL validator 1.9.2609 and drew it on WARP. On main 13f91ca, validation reports two entries for one phi predecessor, with 0.25 and 0.75 both coming from the same block. On this PR at 1fcd4d4, 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 andrewpozdnakov7-jpg@users.noreply.github.com |
|
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 |
…t per slot Applied manually (context drifted upstream): Once version of the mirror() warning, past_heap_step fn + test removed. Marvisak#2622 skipped as not-applicable (no Plan machinery locally).
…k drops its untaken phi entry
|
Automated triage for the maintainers. Recommended for a maintainer's look. Generated by Claude Code |
|
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 |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:
- Diff review:
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).
…k drops its untaken phi entry
fuzeofficlal
left a comment
There was a problem hiding this comment.
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.- Verified
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. - Passed
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).- Extending the new test (
bitcode.rs:1529) with a two-block empty latch chain would also exercise transitiveto()/src()remapping directly.
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