Shaders: fold conditional branches to their fallthrough #1282
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!1282
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1282/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?
@EatCodeSleep2 on GitHub · 2026-11-24 17:07 UTC · original
EatCodeSleep2:fix/shader-branch-to-fallthrough-1242→main· +31 −1 · 2 files · 1 commits · merged 2026-11-25 00:21 UTCSummary
A conditional SOPP branch whose target is the following instruction contributes a single unconditional edge before SSA construction. This prevents duplicate predecessor entries when that edge enters a join, so emitted DXIL phi nodes match the control flow. The fold applies only to SOPP branches, since scalar calls use the same internal flow variant and write a return address.
Refs #1242, finding VIC-BT-007.
Verification
PHI node entries do not match predecessors.cargo clippy --locked -p victory-shader --all-targets -- -D warningspassed.AI-assisted. No game files used.
@geiyiliyabumo on GitHub · 2026-11-24 17:25 UTC · original
Independent verification of \
1ed26e5\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:Code audit looks clean: gating the fold on \machine.encoding == gfx10::Encoding::Sopp\ excludes \s_swappc_b64\ / calls with register side effects while cleanly collapsing redundant fallthrough conditional branches into a single \Exit::Jump\ edge.
AI-assisted; synthetic tests only, no game files.
@adamdotpy on GitHub · 2026-11-24 17:45 UTC · original
Reviewed at head
1ed26e5(worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:1. The fold is semantically sound. In
ir::build(ir.rs:176), a SOPP conditional branch whose target is the next instruction led to the same block either way, so it is a no-op; the PR turns the block's exit intoExit::Jump(fallthrough)and drops the instruction. I verified the guard cannot misfire:Flow::Branchis produced only bys_cbranch_*(Encoding::Sopp,gfx10/mod.rs:144) ands_call_b64(Encoding::Sopk, line 145) — the encoding check excludes the call, whose return-address write is modelled infields.rs:216. And all six GFX10s_cbranch_*opcodes are read-only ineffects()(ir.rsSopp arm: they pushScc/Vcc/Execinto reads only), so dropping the instruction loses no register effect.2. What the fold fixes: previously such a branch created a
Exit::Branch { taken, not_taken }with both targets the same block plus a redundantInst, i.e. a duplicate self-edge at the join; the fold leaves a single jump edge, which is what the phi construction expects.3. Hardware evidence on this machine. The new
a_branch_to_fallthrough_keeps_both_values_at_a_joinruns on the GPU throughrun_cases: withs_cbranch_scc1 -> +2around ans2 = 0/s2 = 1pair and a trailings_cbranch_scc1 -> +0(the folded one), both inputs[7,7]and[7,5]produce the rightv0 = (s0 == s1): 1 passed / 0 failed. Fullcargo test -p victory-shader --lib: 121 passed / 0 failed / 1 ignored.4. Checks:
cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warningsclean;cargo build --release -p victorybuilds;rustfmt --edition 2024 --check—ir.rsclean, one hunk in the new test code atvalu_tests.rs:219(main's file is clean), cosmetic only since CI has no fmt job.5. One behavioral note, not a defect: the guard fires before
effects(), so the four debug-onlys_cbranch_cdbg*opcodes (whicheffects()would refuse as unsupported) are now silently dropped when they target fallthrough instead of being refused. They are condition reads with no register effects, so dropping a branch-to-fallthrough is still a no-op; the only change is that such a shader now translates instead of refusing. Fine for debug branches, just noting the acceptance widened slightly.Nothing found that would block this.