Shaders coalesce conditional branches to their fallthrough #1359
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!1359
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1359/head"
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?
@BaggyALPHA on GitHub · 2026-11-24 17:35 UTC · original
BaggyALPHA:fix/ssa-duplicate-branch-edge→main· +41 −4 · 1 files · 1 commits · closed without mergingAddresses item 7 (VIC-BT-007) in #1242. When a GFX10 conditional branch targets its own fallthrough, the IR now treats it as one jump before linking predecessors and constructing SSA. A join still preserves the distinct incoming values from other blocks.
The new synthetic regression failed before the fix and now checks the branch, the two distinct predecessors, and their incoming values. In a separate synthetic compute probe, Microsoft’s DXIL validator rejected upstream output because PHI entries did not match the CFG predecessors. It accepted the same input with this change. The shader crate passed 121 tests with one ignored on Windows WARP. Clippy with all targets and features and the asset-policy hook passed.
Integration with #1282: the current PR heads merge cleanly. The combined Windows shader library suite passed 122 tests with one ignored, including the IR single-edge regression here and the GPU readback regression in #1282. The SOPP fold in #1282 removes the redundant instruction, while this PR coalesces identical successors in the IR.
AI-assisted (Codex).
@adamdotpy on GitHub · 2026-11-24 20:50 UTC · original
Reviewed head
f2782f3locally (isolated worktree, fresh CARGO_TARGET_DIR).What it does: in
ir.rsbuild(), aFlow::Branch(t)whose taken and not-taken targets are the same block is lowered toExit::Jump(t)instead ofExit::Branch— one SSA edge at the join instead of two, while keeping the branch Inst itself, so it stays encoding-agnostic (works for both SOPP cbranch and any other branch encoding).Verified locally:
cargo test -p victory-shader --lib ir::— 7 passed / 0 failed, including the newa_conditional_branch_to_its_fallthrough_has_one_edgecargo test -p victory-shader --lib— 121 passed / 0 failed / 1 ignoredcargo clippy --all-targets --all-features --locked -- -D warnings— cleancargo build --release -p victory— okrustfmt --edition 2024 --check crates/victory-shader/src/ir.rs— 0 hunks (same as main)Findings, ranked:
cbranchInst at the encoding layer. The two are complementary, not redundant: #1359 fixes the IR-level edge duplication for every branch form, #1282 removes a dead instruction.ir.rsaround the branch handling, so expect a textual conflict with #1282 (and #1359's own sibling branch-to-fallthrough work); semantically they compose in either order — worth a one-line note on both PRs so the second merger rebases cleanly.taken == not_takenis the exact condition under which the branch is a no-op, and the new test covers the single-edge property directly.LGTM from my side.
@adamdotpy on GitHub · 2026-11-24 21:26 UTC · original
@mercuryVM thanks for the approval and especially the validator detail — the duplicate-predecessor phi (two incoming entries from one block, rejected by the DXIL validator) is exactly the failure mode the
Exit::Jumpfold removes; good to have it confirmed on RTX 5070 with the full workspace suite (638 passed).@Marvisak on GitHub · 2026-11-25 00:38 UTC · original
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #1282. Same fix as #1282 (a conditional branch to its own fallthrough gets one edge), done by coalescing in the exit match but leaving the branch instruction in a block whose exit is a Jump; #1282 drops the instruction and has the end-to-end GPU test.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
@sinan-cmyk on GitHub · 2026-11-25 01:48 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
f2782f3ontomainffe310e(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 121, 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).
Pull request closed