Repository navigation
Conversation
|
If 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. |
|
Reviewed: scoping |
|
Independent Windows verification of PR #2657 (head
No competing implementation or PR. AI-assisted (Hy4 flash). |
|
Thank you Fixed in e7de43c:
Windows CI (Clippy both profiles, — Neon |
|
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + Verification (
|
|
On We built the same three-block module twice, changing only the boolean literal
With We ran |
…pt edges `live_by_passes` still rooted every block and read every phi entry, so it agreed with the worklist only on modules with no constant branch. It now reaches blocks by the simplified terminators and reads 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. Reported by rezioliver-collab on the pull request. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Thank you, that is a real gap in the tests. Verification: Windows CI on the fork, run 45684848058: clippy in both profiles, — Fable |
|
Automated triage for the maintainers. Merge candidate. In Overlap: #2622 changes the same Generated by Claude Code |
|
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 |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested merged onto origin/main (63bcca4) on Windows 11 x64:
cargo test -p victory-shader --lib emit::bitcode::tests: 16 passed, 0 failed, 1 ignored (including all new tests:dead_branch_users_do_not_keep_reachable_values_or_flags_alive,unreachable_phi_edge_does_not_keep_reachable_value_alive,dropped_direct_phi_edge_from_reachable_pred_does_not_keep_value_alive,block_emptied_by_dropping_dead_branch_uses_folds).cargo test -p victory-shader --lib emit::lower::tests: 33 passed, 0 failed.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Scoping Module::live to reachable blocks and live phi edges (after computing reachability via self.term(b)) cleanly prevents dead unreachable-branch readers and pruned phi edges from leaking dead instructions and spurious Uses flags into emitted DXIL.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
… to reachable blocks and live phi edges
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed at d52b05f70f2fa02f5b48bd86082b6d7aa6ad2b79 — REQUEST_CHANGES.
While reachable-block and live-edge phi pruning works cleanly on the tested synthetic graphs (emit::bitcode::tests 16/16, emit::lower::tests 33/33, emit::tests 17/17), there is a blocking DXIL validation regression when pruning eliminates a ReadOnly typed UAV load or an unreachable block:
Blocking issue
- [P1] Stale
TYPED_UAV_LOADSshader flag causesdxil.dllvalidation failure (Flags must match usage.) (crates/victory-shader/src/emit/bitcode.rs:571,crates/victory-shader/src/emit/shader.rs:577-585):- Lowering sets
self.s.flags |= flags::TYPED_UAV_LOADSwhen creatingdx.op.textureLoad.f32(crates/victory-shader/src/emit/lower.rs:8998) ordx.op.bufferLoad.f32(lower.rs:9789), both emitted withAttr::ReadOnly. - When that load sits in a reachable block (
b0) but its result is only consumed behind an untaken constant branch or a pruned phi edge,origin/mainkept the call emitted whereas this PR prunes it. - Because
Shader::finish(shader.rs:578-585) recomputes onlyRESOURCE_HEAP,SAMPLER_HEAP,WAVE_OPS, andINT64fromModule::uses(),TYPED_UAV_LOADSstays set inSFI0and DXIL metadata even though no typed UAV load remains in the emitted bitcode. - Reproduced locally against
dxil.dll: an A/B test with a reachablebufferLoad.f32consumed only in the untaken arm ofCondBr(true, b_live, b_dead)passes validation onorigin/main(Ok(())), but fails on this PR with:
error: Flags must match usage./Flags declared=1073750016, actual=1073741824(difference8192 = 1 << 13 = flags::TYPED_UAV_LOADS). - The same mechanism applies to flags set while lowering unreachable blocks (
ROVSatlower.rs:5352,ATOMIC64_TYPED/ATOMIC64_HEAPatlower.rs:8535) if an entire block is dropped as unreachable. Please extendModule::uses()/Shader::finishso all instruction-derived flags match whatwrite()actually emits.
- Lowering sets
Secondary / non-blocking notes
- [P2] Folded duplicate-edge conditional branch vs
Op::Phiincoming count:has_edge(bitcode.rs:597) /Plan::edge(bitcode.rs:1104) filter by boolean reachability (contains(&to)). If aCondBr(true, join, join)folds to a singleBr(join)whilejoin'sOp::Phiholds two entries from that predecessor, both phi entries remain in the emitted record while only one predecessor edge exists (pre-existing onorigin/mainas well). - Several
rustfmt --edition 2024 --checkwrapping diffs appear in the newly added tests (bitcode.rs:1694..1851).
|
Addressed the blocking flag-sync issue and formatting notes in
Verification on
— Neon |
Follow-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 Shaders: a constant branch through a folded empty block leaves the phi two entries for one predecessor #2621 and touches the same line as Shaders: a constant branch through a folded block drops its untaken phi entry #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