Shaders: guard both back edges when a conditional branch targets two … #1540
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!1540
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1540"
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?
@Texbirds on GitHub · 2026-11-24 18:58 UTC · original
Texbirds:fix/shader-dual-backedge-loop-counter→main· +97 −24 · 1 files · 1 commits · openProblem
In
crates/victory-shader/src/emit/lower.rs,LaneExit::Branchhandles loop-counter increments withif back(self, taken) { ... } else if back(self, not_taken) { ... }, and the subsequententer_looppass skips any target whereback(self, to)is true.When both arms of a conditional branch are back edges (for example, an inner loop latch placed before an outer loop header where
takencontinues the inner loop andnot_takenfalls straight back into the outer loop header),not_takennever callscount_iteration: itsLOOP_LIMITcounter phi is missing its incoming edge from that block (producing invalid DXIL) and that back edge has no iteration cap.Fix
takenandnot_takenare back edges (and distinct), emit dedicated per-edge guard blocks recorded inself.edges[(b, to)]that each increment and bound their target header's counter before branching to the header orabort_block().taken == not_takenis a back edge, emit a single bounded back-edge branch directly to the header orabort_block().dual_back_edge_branch_counts_both_loop_headersverifying both loop headers receive all counter-phi incoming edges and pass DXIL validation whendxil.dllis present.Verification
windows-latestCI (cargo clippydefault +--all-featuresandcargo test --workspace --locked).@sinan-cmyk on GitHub · 2026-11-24 19:33 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count changes against
main, and the tests pass on Ada.Offline. I merged head 1ccae2d 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 on both, 0 gained, 0 lost. No program changes its failure reason either.This is the expected result for a correctness 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).
@Marvisak on GitHub · 2026-11-25 01:30 UTC · original · edited 2026-11-26 00:25 UTC
Automated triage for the maintainers.
Merge candidate. The rebase onto
mainis clean, and the logic is as reviewed before. InLaneExit::Branch(crates/victory-shader/src/emit/lower.rs), when both arms of a conditional branch are back edges, each arm now gets its own guard block. That block counts the iteration for its own header throughcount_iteration_fromand branches to the header or toabort_block(), and it is recorded inself.edgesso the header's other phis see it as the predecessor. When both arms go to the same header, there is a single guarded branch. Previously thenot_takenheader's counter phi was missing an incoming edge, and that edge had no iteration cap.dual_back_edge_branch_counts_both_loop_headerschecks that all four counter-phi edges exist and that the DXIL validates.On your reply: confirmed. It merges cleanly with current
main. One thing for the maintainers: with this PR merged,emit/lower.rsis 524,196 bytes, only 92 bytes under the 524,288-byte limit inxtask/src/policy.rs. #1271 and #1315 also grow that file, so only one of them can land beforelower.rsis split.CI: passing (
check).Generated by Claude Code
@Texbirds on GitHub · 2026-11-25 22:46 UTC · original
Rebased cleanly onto
main(f3578e3) inf207efe. The conflicts were only adjacent#[cfg(test)]fields onLowered(uses_lane_index/has_half_wave_mask) and the newds_bpermute_*tests incrates/victory-shader/src/emit/lower.rs; the dual back-edge guard logic anddual_back_edge_branch_counts_both_loop_headerstest are unchanged.@fuzeofficlal on GitHub · 2026-11-26 00:44 UTC · original
Code review and RTX 5090 + WARP + DXIL verification at head
f207efe21429merged cleanly ontomain(63bcca43c6a0):crates/victory-shader/src/emit/lower.rs:10195-10220):LaneExit::Branchare back edges (self.counters.contains_key(&to) && self.rpo[to] <= self.rpo[b]): thetaken == not_takencase guards once directly fromself.cur(avoiding double-increment), whiletaken != not_takenallocates dedicated edge blocks checking each target's loop counter againstLOOP_LIMITand registersself.edges.insert((b, to), edge).self.edgesconsumers inlower.rs(lines 5490, 5631, 5695, 10877, 10940): every one resolves predecessors viaself.edges.get(&(q, b)).copied().unwrap_or(qb), keeping data/mask/descriptor/counter phis at both loop headers consistent without resetting back-edge counters viaenter_loop.lower.rsbudget warning:main(63bcca43),crates/victory-shader/src/emit/lower.rsreaches524,196bytes — only92bytes below the524,288-bytextask policylimit. Worth noting for merge ordering alongside otherlower.rsPRs (or trimming a few lines of comments / extracting a helper if anotherlower.rsPR lands first).dxil.dll10.0.26100.0,VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy -p victory-shader --all-targets -- -D warnings(default +--all-features): 0 warningsemit::lower::tests emit::tests structure::tests: 64/64 passed (1 ignored:bench_bools) on both RTX 5090 and WARP.Logic and DXIL validation look solid (just watch the 92 B headroom in
lower.rs); LGTM.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.