Shaders: scope DXIL bitcode liveness to reachable blocks and live phi edges #2657
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!2657
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2657"
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?
@Moon0755 on GitHub · 2026-11-25 17:39 UTC · original
Moon0755:fix/bitcode-live-reachable-only→main· +267 −31 · 1 files · 3 commits · openFollow-up to
286a00e("Shaders: the DXIL writer leaves out what no edge or reader reaches").Problem
In
Module::plan(crates/victory-shader/src/emit/bitcode.rs),Module::live()ran before reachability (seen/post) was computed:Op::Store,Op::AtomicRmw,Op::CmpXchg, side-effectingOp::Call) andb.termbranch conditions from every block inself.blocks, including unreachable blocks pruned by constant branches (Module::term).for_each_operandfollowed all incoming operands ofOp::Phi, including edges from unreachable predecessors (!seen[pred]) thatModule::writedrops viaPlan::edge.As a result, any pure instruction defined in a reachable block (such as
dx.op.createHandleFromHeap, 64-bit integer ops, wave/quad calls, or loads from constant globals) whose only user lived behind an untaken constant branch or on an unreachable phi edge remained markedlive = true. That kept dead instructions in emitted reachable blocks, kept stale shader feature flags set inModule::uses(RESOURCE_HEAP,SAMPLER_HEAP,WAVE_OPS,INT64), kept unreferenced constant globals/declarations inModule::kept, and prevented blocks emptied by dead-branch pruning from folding inModule::plan.Fix
seen,post) inModule::planbefore liveness (it depends only onModule::term).Module::live(&self, post: &[usize], seen: &[bool])to:self.term(b)branch conditions only from reachable blocks (post), andOp::Phiincoming values only from reachable predecessors (seen[pred], matchingPlan::edge'sself.seen[b]guard soModule::writecan never reference an unemitted value).emit::bitcode::tests:dead_branch_users_do_not_keep_reachable_values_or_flags_aliveunreachable_phi_edge_does_not_keep_reachable_value_aliveblock_emptied_by_dropping_dead_branch_uses_foldsVerification
Verified on
windows-latestvia GitHub Actions (run 45666234935):cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings— passedcargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings— passedcargo test -p victory-shader -p xtask --locked -- --nocapture—273 passed; 0 failed; 3 ignored(including all 3 new tests andwritten_bytes_unchanged), plusxtask6 passed; 0 failed(repository_passes_policypassed)— Neon
Update after review (
e7de43c)The text above describes the first commit (
973a6ab). DrDarkDK's review showed thatseen[pred]is not enough: a predecessor can be reachable while its direct edge to the phi's block is the untaken side of a constant branch. The second commit changes the rule:Module::has_edge(seen, from, to):fromis reachable and its simplified terminator namestodirectly.Module::livefollows a phi entry only wherehas_edgeholds for the phi's own block, so a value read only through such a removed edge is no longer kept.Plan::edgeis the same predicate, so liveness and the writer cannot disagree about which phi entries exist. This also covers the shape of #2621 and touches the same line as #2622; whichever lands second needs a rebase.Module::keptreads a phi's global operands only through entries thatPlan::edgekeeps.dropped_direct_phi_edge_from_reachable_pred_does_not_keep_value_alive, runs that shape both with the middle block folded away and with it kept.Verification of
e7de43c: Windows CI on the fork (run 45670122800, clippy in both profiles,victory-shaderandxtasktests), this repository'scheckon the PR, and fuzeofficlal's independent run above (RTX 5090 and WARP withdxil.dll: the four new tests pass; the three failures there are reported as that machine's baseline).Test helper (
d52b05f, after rezioliver-collab's report):live_by_passes, the pass-by-pass liveness the worklist is compared with, still rooted every block and read every phi entry, so the two agreed only on modules with no constant branch. It now follows the same rule by whole passes (blocks reached through the simplified terminators, a phi entry only along an edge that is still there), and the four tests of dropped blocks and edges compare the worklist with it. Windows CI on the fork: run 45684848058,victory-shader274 passed; 0 failed; 3 ignored.— Fable
@DrDarkDK on GitHub · 2026-11-25 17:50 UTC · original
seen[pred]can still keep a phi operand when the predecessor is reachable and its edge to the phi’s block was removed. The shape from #2622 gives a concrete case:entry: CondBr(true, empty, join)empty: Br(join)join: phi [(one, empty), (only_for_dead_edge, entry)]If
only_for_dead_edgeis a pure instruction defined inentry, liveness keeps it becauseseen[entry]is true. With #2622’s edge check, the writer drops that phi input while still emitting its unused producer.Could liveness check whether the predecessor’s simplified terminator targets the phi’s block? Adding this case would complement the unreachable-predecessor test.
Static review only.
AI-assisted with Codex.
@kotekompotek on GitHub · 2026-11-25 17:54 UTC · original
Reviewed: scoping
live()to post-order-reachable blocks and marking phi operands only alongseen[pred]edges is correct — a value feeding a dead phi edge no longer survives, which is exactly what drops the unread descriptor-word queries. The worklist-per-instruction property is preserved. Pairs naturally with #2622's dead-edge phi cleanup. CI green.@cloph-dsp on GitHub · 2026-11-25 17:58 UTC · original
Independent Windows verification of PR #2657 (head
973a6ab), Rust/Cargo 1.100.0 MSVC, synthetic tests only, no game data, no source edits. This complements the existing static review on the PR.cargo test --locked -p victory-shader --lib emit::bitcode::tests -- --test-threads=1on the PR head: 15 passed, 0 failed, 1 ignored (benchmark), 260 filtered. The three new tests pass:dead_branch_users_do_not_keep_reachable_values_or_flags_alive,unreachable_phi_edge_does_not_keep_reachable_value_alive,block_emptied_by_dropping_dead_branch_uses_folds.13f91cawith the same filter: 12 passed, 1 ignored; the three new tests are absent.No competing implementation or PR. AI-assisted (Hy4 flash).
@Moon0755 on GitHub · 2026-11-25 18:00 UTC · original
Thank you
@DrDarkDK— that is exactly the gap:seen[pred]only says the predecessor is reachable, not that its edge to the phi's block survived the constant branch.Fixed in
e7de43c:Module::has_edge(seen, from, to):fromis reachable and its simplified terminator directly targetsto.Module::livenow follows a phi entry only throughhas_edge(it records each phi's owning block while walking the reachable blocks).Plan::edge(whatModule::writeuses) goes through the same check, so liveness and the writer can no longer disagree about which entries exist. That is the same edge fix as in #2622 (successors(..).contains(&x)instead of resolving through folded blocks), which is what makes theentry: CondBr(true, empty, join)/empty: Br(join)shape correct.Module::keptreads a phi's global operands only through kept entries.dropped_direct_phi_edge_from_reachable_pred_does_not_keep_value_alivecovers both your shape (the middle block folds away:plan.fold[mid] == Some((entry, join))) and the non-folded one; the producers inentryare not live,uses()is empty andwrite()succeeds.Windows CI (Clippy both profiles,
victory-shader,xtask): https://github.com/Moon0755/VIctory/actions/runs/45670122800— Neon
@fuzeofficlal on GitHub · 2026-11-25 18:23 UTC · original
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP +
dxil.dllverification and code review ofe7de43cb(on13f91ca):Verification (
rustc 1.98.1MSVC, Windows SDK10.0.26100.0dxil.dll)cargo test --locked -p victory-shader --lib emit::bitcode::tests -- --nocapture: 16 passed, 0 failed, 1 ignored (bench_write); all 4 new bitcode tests pass (includingdropped_direct_phi_edge_from_reachable_pred_does_not_keep_value_alive).cargo clippy --locked -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo clippy --locked -p victory-shader --all-targets --features host -- -D warnings: 0 warnings.cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index(runs both hardware RTX 5090 and WARP withdxil.dllvalidation active, zero skipped validations): 270 passed, 3 failed, 3 ignored. The 3 failures are the pre-existing RTX 5090 baseline mismatches (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware), andheap_direct_texture_reads_mark_their_heap_indexis the pre-existing RTX 50900xc0000005baseline crash (#2571); WARP anddxil.dllvalidation had 0 failures.Code review notes
Module::has_edgecleanly addresses the dropped-direct-edge case from a reachable predecessor acrossModule::live,Plan::edge, andModule::kept, so values and constantV::Globalarrays only reachable via folded-outCondBrphi edges are pruned without breaking SSA IDs ordxil.dllusage-flag checks.entry -> empty1 -> empty2 -> join) keephas_edge(empty2, join)true and rewrite phi sources viaplan.src(...)consistently.e7de43cbtouches the samePlan::edgeline as #2622 and is a strict superset of #2622 for #2621 (since it also scopesModule::liveandModule::keptwith the samehas_edgepredicate).@rezioliver-collab on GitHub · 2026-11-25 19:20 UTC · original
On
e7de43cb, we reproduced the difference betweenm.plan().liveand the test helperlive_by_passeson an M1 Mac with Rust 1.98.1. The PR's worklist gives the correct result in both runs.We built the same three-block module twice, changing only the boolean literal
TAKE_DIRECT.With
false, all three blocks are reachable, but the directentry → joinedge is gone. The phi takes1fromvia, so nothing readssum. The old helper follows both phi inputs and keeps the add alive. Both algorithms keep the phi and the sink call. This is a concrete case the existingworklist_liveness_matches_passestest misses.We ran
bitcode.rsdirectly withrustc --testbecause three unrelated tests reference the Windows-only DXIL validator. All 16 existing module tests passed (one benchmark ignored). Only the added equality check failed, on thefalsecase.@Moon0755 on GitHub · 2026-11-25 19:28 UTC · original
Thank you, that is a real gap in the tests.
live_by_passesstill rooted every block and read every phi entry, so it agreed with the worklist only on modules with no constant branch.d52b05fmakes it follow the same rule by whole passes (blocks reached through the simplified terminators, a phi entry only along an edge that is still there), and the four tests of dropped blocks and edges now compare the worklist with it, your shape among them.Verification: Windows CI on the fork, run 45684848058: clippy in both profiles,
victory-shader274 passed; 0 failed; 3 ignored,xtask6 passed. Tests only; the liveness code is as it was ate7de43c.— Fable
@Marvisak on GitHub · 2026-11-25 22:20 UTC · original
Automated triage for the maintainers.
Merge candidate. In
crates/victory-shader/src/emit/bitcode.rs,Module::plannow computes reachability beforeModule::live. Liveness then roots only reachable blocks, uses the simplified terminator for branch conditions, and follows a phi entry only along an edge that still exists (Module::has_edge).Plan::edgeandModule::keptuse the same predicate, so liveness and the writer cannot disagree. Pure values used only behind untaken constant branches (and the INT64/WAVE/heap flags and globals they pull in) are no longer emitted. I checked that dropping theto()mapping fromPlan::edgeis equivalent for phis whose entries name real predecessors (a fold that would create a second edge is already refused inplan), and that the pass-based reference in the tests now follows the same rule. It merges cleanly; CIcheck: passing.Overlap: #2622 changes the same
Plan::edgeline for a subset of this fix. Whichever lands second needs a rebase, and #2622 may then be unnecessary.Generated by Claude Code
@KainanP on GitHub · 2026-11-25 22:53 UTC · original
Measured against #2622 with an end-to-end repro (validator plus draws on RTX 4060, Intel UHD and WARP). The repro and #2622's test pass, with no regressions, also on
f3578e38. The comparison suggests landing #2622 first, then this one as the liveness change: #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.