Repository navigation
dxil: fold constant CFG terminators after CSE - #1818
mokkamokacaffe wants to merge 4 commits into
Conversation
|
Regression run for this PR: head Default settings (the pair for Regression run): main this PR: No device removals or crashes; 108 % of main's frames, 90 % of its peak commit. With default settings the direct path is off, so these runs do not reach this PR's code. With
Run 1 crashed at 36.7 s with an access violation in Not tested: the whole suite; a world-loading run with the direct path. Written with Claude Code (Claude Opus 5.5) from runs on this machine. |
RTX 4090 — direct DXIL and GPU readbackFor #1269, we tested the same retail compute shader and readback fixtures used in the RTX 4090 test of #1800. On What changed in the compiled shader
These counts come from the Windows SDK disassembly of the final containers. Both constant branches became unconditional. The entry had 119 basic blocks and zero switches in all three configurations. The parent and disabled containers shared SHA-256 Translation and driver timingsMilliseconds of CPU wall time, median [minimum–maximum] across 12 trials per configuration.
With a fresh executable path, the enabled PR's driver median was 0.584 ms higher than the parent's. The PR was faster in six of the 12 matched rounds. All three ranges overlap.
GPU correctnessFull shader. Each configuration dispatched the original shader with a zero activity mask, an active mask and empty root, and an active mask and box32 root containing four invalid children. All 32 output words held the expected miss value Instruction readback. Both original 20-byte Reproduction details
AI disclosure. Codex prepared the harness, ran the tests and drafted this report. |
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
pvfreis
left a comment
There was a problem hiding this comment.
Review of 365148b merged onto main 689f2db (no conflict, tree 46747484).
-
CONFIRMED (run): three fuzz tests fail on the merged tree and pass on
mainhere (RTX 3060).fuzz_tests.rscame with #1679, after this head, so the runs onea683a0cannot see it.test (first failing seed) validator fuzz_validate_and_gpu_0(33)error: Flags must match usage./Flags declared=1572948, actual=1572884fuzz_validate_and_gpu_1(641)Flags declared=84, actual=20fuzz_validate_and_gpu_2(1103)Flags declared=80, actual=16These are validator rejections, separate from the GPU failures reported on
mainin #1679 (AMD, RTX 5060 Ti).The difference is always 64, bit 6,
DoubleExtensions.uses_double_extensions(module.rs:1394on the merged tree) scans all ofself.insts, including the instructions of the blocks the new step empties (opt.rs:535);insts_use_typenext to it scansself.blocks. A dropped int -> double cast therefore still declares the flag. Scanning the blocks there should clear the flag for these three seeds (not run) but not the general case. Read, not run:Shader::requireonly adds, andLw::f64ty,Lw::i64,v_cvt_f64_i32(lower_wide.rs:875),Shader::binaryon i64/f64 and the wave ops call it while building, so a flag whose only user is in an emptied block stays declared (removablerefuses those for this reason). One way is to derive the flags from the remaining blocks afteroptimize. Each test stops at its first bad seed, so rerun all four. The flag code is the same atea683a0. The block scan is also proposed in #1894 (item 2) and made by the draft #1544; neither covers therequireflags.cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4, debug, RTX 3060, DXC 1.9.2602.17, isolated session:main974 passed, 1 failed, 45 ignored; merged 974 passed, 4 failed, 45 ignored. The shared failure is the e2e title test (no swap chain there). The three new tests pass; 22 identical SKIPPED lines. -
CONFIRMED (read):
TRANSLATOR_VERSIONneeds a value abovemain's 7.mainwent to 7 in #1679 (kernel.rs:40), this PR also goes 6 -> 7, so the merge keeps 7 without a conflict. The comment above the constant saysgpu/dxilis not in build.rs's source hash, so with the same DXC and backend a cache written bymainat 7 would keep serving the unfolded containers. Only direct DXIL (XCL_DIRECT_DXIL) is affected.
Not tested: AMD, wave64, a title.
Review by Claude Code (Claude Opus 5.5), checked with Claude Fable 5.2; each point checked by a person before posting.
365148b to
1a52a27
Compare
1a52a27 to
7c44c94
Compare
|
Run and written with Claude Code (Claude Opus 5.5), checked with Claude Fable 5.2; each point checked by a person before posting. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
7c44c94 to
16df11c
Compare
|
A measurement on whether this pass finds anything in the programs it is meant for. I did not run this head (it conflicts with
So on these four there is nothing to fold in the per-instruction form. It may still help other programs: I did not run the whole pack. Before this is rebased, a count over the pack (how many programs change, and by how much) would show whether it is worth it. AMD RDNA4, native wave64, AI use: Claude Code (Claude Opus 5.5) wrote the prototype, ran it and wrote this on the maintainer's behalf. |
a7cc735 to
0561b6b
Compare
|
Regression run of Against the limits in CONTRIBUTING.md: 100 % of AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, AI use: Claude Code (Claude Opus 5.5) built both trees and ran |
|
Full Windows workspace run (listed under Not tested). Two fuzz tests fail on this head and pass on its base. Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5 (validator from the same release), debug build. Head 0561b6b, base main 1a0bbe3. Result: cargo test --workspace -- --test-threads=4: 1186 passed, 2 failed, 26 ignored (the lib binary stopped at the failures, so later binaries did not run). gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (fuzz_tests.rs:1152) gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_2 AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report, checked by a person before posting |
Port #1818's constant-CFG terminator and path-fact folding onto Direct DXIL and fix the stale shader-flag validation gap that blocked it: 1. Resolve CSE and trivial-PHI replacements before CFG folding, propagate dominating branch/switch path facts (bounded to 16 RPO passes so large shaders stay linear), fold constant CondBr/Switch terminators, drop newly unreachable blocks and obsolete PHI edges (preserving loop backedges), and rerun trivial-PHI simplification (opt-out via XCL_DXIL_NO_OPT=cfg). 2. Reconcile Int64Ops, Doubles, DoubleExtensions (including f64 FMA), ResourceHeapIndexing, SamplerHeapIndexing, AtomicInt64*, and TypedUavLoadAdditionalFormats in Shader::infer_type_features() against surviving reachable instructions after optimize(), preventing stale shader flags when dead branches are pruned. Adds unit tests covering constant branches/switches, dominated branch facts, reconvergence, loop PHI backedges, and pruned i64/heap shader flags. Assisted-by: Antigravity (Gemini 4 Neon High)
|
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current |
Fold branch and switch terminators both after ordinary constant simplification and when every incoming control-flow edge proves the selector value. Facts are intersected at joins and bounded to branch selectors, so contradictory paths do not leak through reconvergence. Recompute type-derived shader flags from surviving instructions after CFG folding so removed wide operations cannot leave stale metadata. Assisted-by: OpenAI Codex (GPT-5) Assisted-by: OpenAI Codex (GPT-6.2 Astra Ultra)
0561b6b to
673ab90
Compare
Port xcl-dev#1818's constant-CFG terminator and path-fact folding onto Direct DXIL and fix the stale shader-flag validation gap that blocked it: 1. Resolve CSE and trivial-PHI replacements before CFG folding, propagate dominating branch/switch path facts (bounded to 16 RPO passes so large shaders stay linear), fold constant CondBr/Switch terminators, drop newly unreachable blocks and obsolete PHI edges (preserving loop backedges), and rerun trivial-PHI simplification (opt-out via XCL_DXIL_NO_OPT=cfg). 2. Reconcile Int64Ops, Doubles, DoubleExtensions (including f64 FMA), ResourceHeapIndexing, SamplerHeapIndexing, AtomicInt64*, and TypedUavLoadAdditionalFormats in Shader::infer_type_features() against surviving reachable instructions after optimize(), preventing stale shader flags when dead branches are pruned. Adds unit tests covering constant branches/switches, dominated branch facts, reconvergence, loop PHI backedges, and pruned i64/heap shader flags. Assisted-by: Antigravity (Gemini 4 Neon High)
Port xcl-dev#1818's constant-CFG terminator and path-fact folding onto Direct DXIL and fix the stale shader-flag validation gap that blocked it: 1. Resolve CSE and trivial-PHI replacements before CFG folding, propagate dominating branch/switch path facts (bounded to 16 RPO passes so large shaders stay linear), fold constant CondBr/Switch terminators, drop newly unreachable blocks and obsolete PHI edges (preserving loop backedges), and rerun trivial-PHI simplification (opt-out via XCL_DXIL_NO_OPT=cfg). 2. Reconcile Int64Ops, Doubles, DoubleExtensions (including f64 FMA), ResourceHeapIndexing, SamplerHeapIndexing, AtomicInt64*, and TypedUavLoadAdditionalFormats in Shader::infer_type_features() against surviving reachable instructions after optimize(), preventing stale shader flags when dead branches are pruned. Adds unit tests covering constant branches/switches, dominated branch facts, reconvergence, loop PHI backedges, and pruned i64/heap shader flags. Assisted-by: Antigravity (Gemini 4 Neon High) (cherry picked from commit f4b0706) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port xcl-dev#1818's constant-CFG terminator and path-fact folding onto Direct DXIL and fix the stale shader-flag validation gap that blocked it: 1. Resolve CSE and trivial-PHI replacements before CFG folding, propagate dominating branch/switch path facts (bounded to 16 RPO passes so large shaders stay linear), fold constant CondBr/Switch terminators, drop newly unreachable blocks and obsolete PHI edges (preserving loop backedges), and rerun trivial-PHI simplification (opt-out via XCL_DXIL_NO_OPT=cfg). 2. Reconcile Int64Ops, Doubles, DoubleExtensions (including f64 FMA), ResourceHeapIndexing, SamplerHeapIndexing, AtomicInt64*, and TypedUavLoadAdditionalFormats in Shader::infer_type_features() against surviving reachable instructions after optimize(), preventing stale shader flags when dead branches are pruned. Adds unit tests covering constant branches/switches, dominated branch facts, reconvergence, loop PHI backedges, and pruned i64/heap shader flags. Assisted-by: Antigravity (Gemini 4 Neon High) (cherry picked from commit f4b0706) (cherry picked from commit 3c54e55) Ported to main: simplify_phis keeps main's back-edge check (5a984e0: a phi is not replaced by a value defined after it in the layout), with positions recomputed after the CFG fold; XCL_DXIL_NO_OPT lists both main's select and this cfg pass; main's tests stay next to the new ones. Review fixes (xcl-dev#3268): a cmpxchg is typed as its { T, i1 } pair, so the live scan now takes T from the compared value and keeps AtomicInt64GroupShared for a 64-bit group-shared cmpxchg; and a folded CondBr(c, t, t) or a switch with several cases to one block keeps one phi entry per remaining edge (drop_phi_edges, as simplify_cfg does), not one per case. Both have a test that fails without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port xcl-dev#1818's constant-CFG terminator and path-fact folding onto Direct DXIL and fix the stale shader-flag validation gap that blocked it: 1. Resolve CSE and trivial-PHI replacements before CFG folding, propagate dominating branch/switch path facts (bounded to 16 RPO passes so large shaders stay linear), fold constant CondBr/Switch terminators, drop newly unreachable blocks and obsolete PHI edges (preserving loop backedges), and rerun trivial-PHI simplification (opt-out via XCL_DXIL_NO_OPT=cfg). 2. Reconcile Int64Ops, Doubles, DoubleExtensions (including f64 FMA), ResourceHeapIndexing, SamplerHeapIndexing, AtomicInt64*, and TypedUavLoadAdditionalFormats in Shader::infer_type_features() against surviving reachable instructions after optimize(), preventing stale shader flags when dead branches are pruned. Adds unit tests covering constant branches/switches, dominated branch facts, reconvergence, loop PHI backedges, and pruned i64/heap shader flags. Assisted-by: Antigravity (Gemini 4 Neon High) (cherry picked from commit f4b0706) (cherry picked from commit 3c54e55) Ported to main: simplify_phis keeps main's back-edge check (5a984e0: a phi is not replaced by a value defined after it in the layout), with positions recomputed after the CFG fold; XCL_DXIL_NO_OPT lists both main's select and this cfg pass; main's tests stay next to the new ones. Review fixes (xcl-dev#3268): a cmpxchg is typed as its { T, i1 } pair, so the live scan now takes T from the compared value and keeps AtomicInt64GroupShared for a 64-bit group-shared cmpxchg; and a folded CondBr(c, t, t) or a switch with several cases to one block keeps one phi entry per remaining edge (drop_phi_edges, as simplify_cfg does), not one per case. Both have a test that fails without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
For the record: #3268 (merged, 5b0d5fa) folds constant CFG terminators in direct DXIL and recomputes the live shader flags, which covers this PR. If something here is still missing on (Claude Code, Claude Opus 5.5, for Foniass) |
|
@Foniass, thanks for the update, for carrying the port through review, and for crediting this PR in #3268. I appreciate the additional shader-flag coverage and the fixes for group-shared atomics and duplicate PHI edges. Before we close this out, could you and the maintainers help correct the Git authorship for the part that came from #1818? My original commit records What I'd like preserved in the commit record is |
|
The CFG folding this PR started with is on main: #3268 ported it ( AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Current scope at
28a28e63: #3268 landed the port of the CFG folding from this PR in5b0d5fa3. The remaining diff against main adds two regression tests inshader.rs. The implementation history and predecessor results are preserved below. Port and attribution discussionPart of #1269.
Direct-DXIL branch conditions can become constants after CSE, or be known from the control-flow edge that reaches a block. The optimizer previously retained both CFG arms, keeping dead blocks, terminators and PHI inputs in the emitted DXIL. This pass folds those branches conservatively, cleans the resulting graph, and recomputes type-derived shader flags from the surviving instructions.
What is in it
crates/xcl/src/gpu/dxil/module/opt.rs: fold constantCondBrandSwitchterminators after CSE.cfgtoXCL_DXIL_NO_OPTfor independent bisection.crates/xcl/src/gpu/dxil/module.rs: compute double-extension use from surviving instructions after CFG cleanup, including liveFmacalls.crates/xcl/src/gpu/dxil/shader.rs: recomputeInt64Ops,Doubles, andDoubleExtensionsafter optimization so removed wide operations cannot leave stale metadata.Tested
On predecessor
365148bagainstea683a0, Anon64 reported a clean default smoke on RTX 3060 with direct DXIL disabled. WithXCL_DIRECT_DXIL=1, one PR run crashed at 36.7 seconds on a texture-detile thread. Two repeats on the same build completed. The cause was unconfirmed. Controls, crash and rerunsWindows no-GPU CI tested merge
ddd8a46(head28a28e63on main3db0ee4e). Both remaining shader-feature tests passed. The library harness reported 2,654 passed, 1 failed and 29 ignored. The failure washle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline. A matched baseline for that failure is unreported. CI logOn predecessor
365148bagainstea683a0, minimalhipster990 measured one compute shader on an RTX 4090. Folding removed two conditional branches and 41 PHIs, reducing DXIL by 576 bytes. Disabling the pass reproduced the parent bytes. GPU readbacks matched across all three configurations. Twelve matched rounds per condition showed no consistent timing gain. Measurement and controlsOn the same predecessor, futurepro62 reported 893 passes on RTX 5070 Ti with five explicit filters and 894 on an RDNA2 iGPU, both with 0 failures and 42 ignored. The report lists the capability skips. ivall separately tested a prototype on main
9633138: branch facts changed three of four sampled translations on RDNA4. Workspace results · Prototype measurementsOn
c32c65e0, the Windows workspace passed 2,749 tests (49 ignored). All four DXIL fuzz batches and the loop-phi regression passed. The paired retail blocks are below.Rebased head
673ab90c82584abfdd5e65bf61e199c373f5752d:cargo check -p xcl --tests --target x86_64-pc-windows-msvcpassed in a Linux cross-check environment using a locallib.exe-compatible archive wrapper. This was compile-only; Windows test binaries were not executed.git diff --check: passed on673ab90c82584abfdd5e65bf61e199c373f5752d.Historical predecessor
0561b6b, Windows 11 / NVIDIA RTX 3060:cargo test --workspace -- --test-threads=4reported 1186 passed, 2 failed and 26 ignored before the lib test binary stopped. The two failures werefuzz_validate_and_gpu_1seed 884 andfuzz_validate_and_gpu_2seed 1417: declared flags1048592, actual16, exposing a staleInt64Opsbit after CFG folding. Predecessor673ab90adds the metadata fix and focused regression coverage; the exact fuzz seeds still require a Windows/GPU rerun.Historical standalone optimizer harness on the predecessor: 16 passed, 0 failed, 0 ignored, including the focused CFG tests.
Regression run
Historical smoke pair for predecessor
c32c65e0. Conflict repair on pinned main 0fe06eb, PR head c32c65e. Workspace: 2749 passed, 0 failed, 49 ignored, 27 explicit SKIPPED lines. The focused DXIL suite separately passed 275 with 3 ignored, including all four fuzz batches and the backedge-order regression. The first merge candidate failed the backedge test. The published repair preserves the serialization-order guard when simplifying phis after CFG folding. Other local validation overlapped the smoke; frame counts are regression evidence only. Both release smokes used separate empty XCL caches and XCL_PREPARE=0 on the same RTX 4080 SUPER. OpenAI Codex reconciled the changes, ran validation, and prepared this update.Main
PR
Earlier regression evidence (historical):
The following paired retail smoke passed on predecessor
0561b6b. It is retained as historical evidence but no longer satisfies the exact-head requirement after the rebase and shader-flag fix. A new PR-head run on673ab90c82584abfdd5e65bf61e199c373f5752dis pending.main:
PR predecessor:
The predecessor produced 100.2% of main frames and 100.2% of main peak commit, with no crash or device removal. It does not validate the new head.
Not tested
A clean retail smoke on current head
28a28e63. The description check requires an exact-head block.The exact Windows/GPU fuzz reproductions for seeds 884 and 1417 on
673ab90.AMD and NVIDIA shader-pack translation or cold PSO measurements on the current head.
AI use
main, preserved the newer optimizer work, diagnosed the stale shader-feature metadata from the independent fuzz report, implemented the type-feature reconciliation and tests, ran the Windows-target compile check, and drafted this updated description.