Shaders: collapse duplicate branch targets and dedup phi predecessors #1460
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1460
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1460"
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?
@piyonchu on GitHub · 2026-11-24 18:12 UTC · original
piyonchu:fix/lower-duplicate-critical-edge→main· +132 −12 · 2 files · 1 commits · openSummary
Fixes invalid DXIL
phinodes when a structured branch (LaneExit::Branch) has identicaltakenandnot_takentargets (VIC-BT-007).Cause
When a degenerate conditional branch had
taken == not_taken,Lower::exitlowered it as a conditional branch to the same target and created duplicate outgoing control-flow edges, causing DXILphinodes in the successor to repeat the same predecessor block and fail DXIL validation (PHI node entries do not match predecessors!).Change
crates/victory-shader/src/emit/lower.rs:LaneExit::Branch { taken, not_taken, .. } if taken == not_takeninLower::exitthrough the samejumppath asLaneExit::Jump(handling both counted back-edges viaCondBrand forward jumps viaBr).phientries inSource::Phi(immediate samplers),uniform_heap_index,Source::LanePhi,data_phis, andpending_masks, matching the single collapsedBr.duplicate_branch_target_back_edge_produces_valid_dxiltesting a counted back-edge whose degenerateBranchtargets the loop header twice with duplicate IR predecessors.crates/victory-shader/src/emit/valu_tests.rs:duplicate_branch_target_critical_edge_produces_valid_dxilverifying DXIL validation and execution on hardware/WARP when a branch'stakenand fallthrough target the same join block.Verification
Rebased onto
main(13f91ca, commit954ef58):cargo clippy -p victory-shader --all-targets -- -D warnings -A clippy::needless_range_loop -A deprecated: pass.cargo test -p victory-shader --lib duplicate_branch_target: 2 passed, 0 failed.cargo test -p xtask: 6 passed, 0 failed.git diff --check upstream/main..HEAD: clean.AI-assisted; no proprietary game files used.
Shaders: keep distinct critical-edge blocks for duplicate branch targetsto Shaders: collapse duplicate branch targets and dedup phi predecessors@geiyiliyabumo on GitHub · 2026-11-24 18:21 UTC · original
Tested commit \f443c2\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, SM 6.6) + WARP:
One edge case noticed during code audit:
AI-assisted; synthetic tests only, no game files.
@piyonchu on GitHub · 2026-11-24 19:00 UTC · original · edited 2026-11-24 19:45 UTC
Thanks for catching the counted back-edge case, @geiyiliyabumo. Collapsed
LaneExit::Branch { taken, not_taken, .. } if taken == not_takento theJumppath inLower::exit(with incoming DXIL block deduplication acrossSource::Phi,Source::LanePhi,data_phis, andpending_masks), restored single-entryedges, and addedduplicate_branch_target_back_edge_produces_valid_dxilcovering a counted back-edge withtaken == not_taken. Re-ranvictory-shader(121 passed, 0 failed, 1 ignored), workspaceclippy(default and--all-features), andxtaskpolicy checks.@sinan-cmyk on GitHub · 2026-11-24 20:43 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head 667de6e onto
mainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 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 --libpassed 122, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 03:28 UTC · original · edited 2026-11-26 03:25 UTC
Automated triage for the maintainers.
Verdict: merge candidate (as before the rebase). Thanks for rebasing; the branch merges cleanly into current
mainagain.crates/victory-shader/src/emit/lower.rs:Lower::exitnow lowers aLaneExit::Branchwhosetaken == not_takenthrough the same path asLaneExit::Jump(counted back-edgeCondBror plainBr), and the five phi builders (Source::Phi,uniform_heap_index,Source::LanePhi,data_phis,pending_masks) skip a repeated incoming block, so the single collapsed edge gets one phi entry. That matches DXIL's one-entry-per-predecessor rule, and the duplicated IR predecessor carries the same register state on both edges, so dropping the second entry loses nothing. Both tests (forward join invalu_tests.rs, counted back-edge inlower.rs) cover the two shapes.mainhas no equivalent handling.Minor: the title still says "keep distinct critical-edge blocks", but the change now collapses the branch; worth retitling.
CI: passing (
check).Generated by Claude Code
@piyonchu on GitHub · 2026-11-25 04:00 UTC · original
Updated PR
#1460(2c0aeeb):Lower::exitcollapsingLaneExit::Branchwithtaken == not_takentojump+ predecessor deduplication inSource::Phi,Source::LanePhi,data_phis, andpending_masks, withedges: HashMap/Lower::edge_blockreferences removed).main(940d32f, addingview_marks: falseinduplicate_branch_target_back_edge_produces_valid_dxil) so CI runs cleanly on the latest head.cargo clippy,cargo test -p victory-shader --lib duplicate_branch_target2/2 passed,cargo test -p xtask6/6 passed).@piyonchu on GitHub · 2026-11-25 19:48 UTC · original
Rebased onto
main(13f91ca, commit954ef58), keeping predecessor-block deduplication acrossSource::Phi/uniform_heap_index/Source::LanePhi/data_phis/pending_masksalongsidejoin_handlesandno_mask_lane_on_edge, updated the PR description, and re-verified (cargo clippy,cargo test -p victory-shader --lib duplicate_branch_target2/2 passed,cargo test -p xtask6/6 passed).@piyonchu on GitHub · 2026-11-26 02:45 UTC · original
Rebased onto latest
main(63bcca4, head commit67c7011) to resolve the EOF test conflicts incrates/victory-shader/src/emit/lower.rsandcrates/victory-shader/src/emit/valu_tests.rs.Verified locally after rebase:
cargo clippy -p victory-shader --all-targets -- -D warnings -A clippy::needless_range_loop -A deprecatedcargo test -p victory-shader --lib duplicate_branch_target(2 passed, 0 failed)cargo test -p xtask(6 passed, 0 failed)@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.Edge-splitting blocks are now kept per predecessor occurrence (
HashMap<(from,to), Vec<usize>>) so duplicate targets from one branch (e.g.s_cbranchwith taken == not_taken) each get their own edge block;edge_blockpicks the occurrence index consistently infill_phisand both descriptor-join paths. The valu testduplicate_branch_target_critical_edge_produces_valid_dxilcovers the case (Windows-only). 96 passed on macOS.@fuzeofficlal on GitHub · 2026-11-26 16:02 UTC · original · approved these changes
Collapsing
LaneExit::Branch { taken, not_taken } if taken == not_takenthroughjump()cleanly preserves loop-counter checks on back edges and avoids duplicate counter entries on forward entries, and deduplicating repeated DXIL predecessors across the five PHI construction paths matches the current SSA invariant (same outgoing register values per(q, block)).A few non-blocking notes worth considering for follow-up or before stacking with other
lower.rsPRs:emit/lower.rsreaches524,223B (65B below the524,288B policy cap); movingduplicate_branch_target_back_edge_produces_valid_dxil(~2.8 KB) out oflower.rsinto a test module would free up headroom so it does not trip the cap when combined with other shader PRs.valu_tests.rs,s_cbranch_scc0 +0is already folded toExit::Jumpinir.rsbefore structurization, so only the back-edge unit test exercises the new branch arm.Local verification at
67c70115(and merged cleanly ontoorigin/main63bcca43):xtask policy(191 files ok),cargo clippy -p victory-shader --all-targets(default and--all-features),emit::lower::(34/34),emit::valu_testson RTX 5090 and WARP (36/36), andduplicate_branch_target_*on RTX 5090 and WARP (2/2) all passed.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.