Shaders: a constant branch through a folded block drops its untaken phi entry #2622
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!2622
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2622"
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?
@BastienRodz on GitHub · 2026-11-25 17:00 UTC · original
BastienRodz:shader/folded-phi-direct-edge-pr→main· +39 −1 · 1 files · 1 commits · openWhat's wrong
Plan::edge(286a00e) keeps a phi entry frombwhen one ofb's successors, followed through folded blocks, is the phi's block. Take a constant branchCondBr(true, empty, join)whose taken sideemptyis folded intoentry → join. The entry carried throughemptyis kept and written fromentry, but the entry for the untaken direct edgeentry → joinpasses as well (to(empty) == join). The phi then has two entries for its one predecessor, which is invalid IR.What the fix does
Plan::edgechecksb's own terminator, with constant branches taken as branches:successors(m.term(b)).contains(&x). A folded empty block still hasxas its successor, so its entry stays and is written from the block it was folded into (from/src, unchanged). The untaken direct edge no longer matches and is dropped. The existingPlan::edgetests (constant branch, never-taken back edge, empty-block folding) pass unchanged.Tests
New device-free
emit::bitcode::tests::a_constant_branch_through_a_folded_block_drops_the_direct_phi_entry:CondBr(true, empty, join)with an emptyemptyand a phi injoin. It checks thatemptyfolds, that its entry stays, and that the untaken direct entry goes.main(13f91ca) it fails:the untaken direct edge goes.emit::bitcode::testspass (13, 1 benchmark ignored). Run under Wine 10, x86_64-pc-windows-msvc.Not tested
No
dxil.dllhere, so not run through the validator, and no title shaders. How often lowering produces this shape (a guarded arm with nothing live behind a condition known to be constant) is not measured.Fixes #2621
AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.
🤖 Generated with Claude Code
@cloph-dsp on GitHub · 2026-11-25 17:30 UTC · original
Independent Windows verification of PR #2622 (head
1fcd4d4), device-free bitcode regression plus broader CPU/hardware suite.Toolchain: rustc/cargo 1.100.0, Windows MSVC (repo pins 1.98.1; no clippy or rustup used). Synthetic inputs only, no game data, no source edits, no competing PR.
cargo test --locked -p victory-shader --lib emit::bitcode::tests -- --test-threads=1: 13 passed, 1 ignored (bench), 260 filtered. The newa_constant_branch_through_a_folded_block_drops_the_direct_phi_entrypasses alongside the existing constant-branch, loop and empty-block folding controls.origin/main13f91ca: the new test name reports 0 tests (test absent).cargo test --locked -p victory-shader --lib -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index-> 267 passed, 3 failed, 3 ignored, 1 filtered. The three failures are hardware-specific and unrelated to this change:emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,emit::synthetic_tests::gathers_at_a_level_match_the_hardware. All three reproduce with identical assertions on unmodified base13f91ca.emit::memory_tests::heap_direct_texture_reads_mark_their_heap_indexterminates withSTATUS_ACCESS_VIOLATIONon both the PR head and unmodified base13f91ca, so it is environmental, not caused by this PR.No regression attributable to the PR found. AI-assisted (Hy4 flash).
@kotekompotek on GitHub · 2026-11-25 17:49 UTC · original
Reviewed: the fix is correct —
edge()must test literal successors, not plan-mapped ones. With a constantCondBr(t, empty, join),successors()returns only the taken edge, socontains(&x)is false for the dead direct edge (dropping its phi entry) while the folded-through edge still reports true. The oldto(s) == xform counted the folded path as a second edge from the same predecessor — exactly the duplicate-entry bug the test pins. CI green.@fuzeofficlal on GitHub · 2026-11-25 18:07 UTC · original
Tested
1fcd4d45merged cleanly ontomain(13f91ca) on Windows 11 with NVIDIA GeForce RTX 5090 (32.0.16.1656) and D3D12 WARP + Windows SDKdxil.dll:cargo test -p victory-shader --lib emit::bitcode::tests: 13 passed, 0 failed, 1 ignored (a_constant_branch_through_a_folded_block_drops_the_direct_phi_entrypasses)VICTORY_WARP=1 cargo test -p victory-shader --lib: 268 passed, 3 failed, 3 ignored (allbitcode,flow,memory,valu,semantics,lower, anddxil.dllvalidation tests pass; the 3 failures are the expected 32-lane/hardware-onlysynthetic_testsunder forced WARP)cargo clippy -p victory-shader --all-targets -- -D warnings: clean (0 warnings)Checked
Plan::edge(self.seen[b] && successors(m.term(b)).contains(&x)): cleanly handles both single and chained collapsed empty blocks while dropping untaken direct edges from constant branches.@andrewpozdnakov7-jpg on GitHub · 2026-11-25 18:16 UTC · original
I tested the emitted pixel shader against DXIL validator 1.9.2609 and drew it on WARP. On main
13f91caee2, validation reports two entries for one phi predecessor, with 0.25 and 0.75 both coming from the same block. On this PR at1fcd4d450b, the same shader validates and all four pixels read back as [0.25, 0, 0, 1]. I ran six paired checks across both debug settings.The bitcode tests passed 13 with one benchmark ignored; both draw tests passed. The serial shader suite moved from 267 passed, 4 failed, 3 ignored to 269 passed, 3 failed, 3 ignored. The three remaining failures are the same gather, permute, and edge-flagged mesh tests on both revisions. Strict shader Clippy and asset policy passed.
Test-only commit 0e74a15 is directly on your current head if you want the validator and pixel readback in addition to the existing structural test. Please retain the Git author if you cherry-pick it, or add this trailer if you fold it into another commit:
Co-authored-by: andrewpozdnakov7-jpg [email protected]
@BastienRodz on GitHub · 2026-11-25 18:17 UTC · original
Thanks for checking it end to end — the validator result on main (two entries for one predecessor, 0.25 and 0.75) and the readback on this head are exactly the before/after the PR claims.
I'll keep the PR to
bitcode.rsand its structural test, so it stays a one-file change. Your test lives inemit/rect.rsbeside the rectangle draws, and it needs a validator or a host device to say anything. If the maintainer would rather have the end-to-end check in this PR, I'll cherry-pick 0e74a15 with your authorship kept.@Marvisak on GitHub · 2026-11-25 22:19 UTC · original
Automated triage for the maintainers.
Recommended for a maintainer's look.
Plan::edgeincrates/victory-shader/src/emit/bitcode.rsnow asks whetherxis a successor ofb's own terminator instead of following successors through folded blocks. I checked thatModule::termalready turns a constantCondBrinto aBrto the taken side, so forCondBr(true, empty, join)withemptyfolded, the entry fromentry(the untaken direct edge) is dropped while the entry from the foldedemptystays and is written fromentry; onmainboth passed, giving the phi two entries for one predecessor. A reviewer in the thread confirmed the DXIL validator rejects the shader onmainand accepts it with this change. One-line fix plus a device-free test; merges cleanly, CIcheckpassing. Fixes #2621.Generated by Claude Code
@KainanP on GitHub · 2026-11-25 22:53 UTC · original
Measured against #2657 and #2692 with an end-to-end repro (DXIL validator plus a draw on RTX 4060, Intel UHD and WARP). The repro passes, your test fails on
mainand passes here, and there are no regressions, also onf3578e38. Recommended in the comparison: #2621 (AI-assisted)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.