Shaders coalesce conditional branches to their fallthrough #1359
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1359"
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 BaggyALPHA on 2026-11-24T17:35:39Z.
Addresses 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).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:42:37Z.
Review: APPROVED
Conditional branch whose taken and fallthrough successors coincide now becomes Exit::Jump (one SSA edge instead of two). The ir.rs test pins the diamond-chain case: preds stay [1,2] with correct phi args, so semantics are preserved. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main
ffe310e,cargo test -p <crate> --locked. Shader execution tests (valu_tests/host/diff_tests) are#[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. victory-shader: 97 passed, 0 failed (test runs on macOS).Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:10:03Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.Coalesces a conditional branch whose two successors are the same block into a single Jump, so SSA sees one incoming edge instead of a degenerate branch. The test builds the exact shape (s_cbranch_scc1 to the fallthrough) and asserts the join has one live phi with the right args. Clean ir.rs fix; macOS test included.
Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T20:50:13Z.
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.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T21:21:34Z.
Review: APPROVED
Tested
f2782f3on Windows 11, RTX 5070, MSVC: builds,cargo test --workspace --no-fail-fast638 passed, 0 failed (on our fork main), with victory-shader single-threaded.a_conditional_branch_to_its_fallthrough_has_one_edgepasses.Branchit made that block a duplicate predecessor, so phis got two incoming entries from one block, which the DXIL validator rejects.buildbefore predecessors and SSA are computed is the right place. The test checks the join keeps exactly its two distinct predecessors and the right phi arguments.Merged into our fork's main.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T21:26:56Z.
@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).Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:38:30Z.
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.
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:48:34Z.
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