dxil: fold constant CFG terminators after CSE #1818
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1818
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1818"
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?
@mokkamokacaffe on GitHub · 2026-11-24 21:11 UTC · original
mokkamokacaffe:codex/dxil-fold-constant-cfg→main· +435 −67 · 3 files · 1 commits · openPart 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
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.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. Current head673ab90adds the metadata fix and focused regression coverage; the exact fuzz seeds still require a Windows/GPU rerun.Regression run
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
673ab90.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.@Anon64 on GitHub · 2026-11-24 21:26 UTC · original
Regression run for this PR: head
365148b, based onmainea683a0. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s, back to back with themainrun.Default settings (the pair for Regression run):
main
ea683a0: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
XCL_DIRECT_DXIL=1, so that the changed pass runs:mainea683a0Run 1 crashed at 36.7 s with an access violation in
VCRUNTIME140.dll, reading unmapped memory on a texture-detile thread:gpu::tiling::Chain::detile_level(tiling.rs:438) ←title_textures::subresources(title_textures.rs:1182). I don't think it comes from this PR: the stack is in texture upload, not in the DXIL optimiser, and two reruns of the same build were clean. It looks more like the race in #1359. I'm noting it here because it happened in a run of this PR's head.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.
@minimalhipster990 on GitHub · 2026-11-24 21:32 UTC · original
RTX 4090 — direct DXIL and GPU readback
For #1269, we tested the same retail compute shader and readback fixtures used in the RTX 4090 test of #1800. On
CS_LaserLightShadowRaytracing, the new control-flow pass removed both constant conditional branches and 41 PHI instructions. The validated DXIL container shrank by 576 bytes (2.11%). Disabling only the new pass reproduced the parent's container byte for byte. All three configurations passed the GPU readback checks. Across 12 matched rounds per condition, we observed no consistent reduction in translation or driver time on this shader.What changed in the compiled shader
cfgdisabledThese 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
97da0d91b8994f85a62ab78625be8e07d6fbe8b33dd39577b8ebdc27472e1977. With the pass enabled, the digest wasde665670b8e83bbc1361b9d18ca8dbbf5346e2f532fb8df4493a971ec4d04bc9.Translation and driver timings
Milliseconds of CPU wall time, median [minimum–maximum] across 12 trials per configuration.
cfgdisabledWith 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.
kernel::translate_computecall using direct DXIL, wave32 and one memory window. Archive I/O, shader selection, validation, device setup and dispatch were outside the timer. Every timed container passed explicit validation and reproduced its configuration's reference FNV-1a-64 digest.ID3D12Device::CreateComputePipelineStatecall after device and root-signature creation. The application supplied no cached PSO blob. Disabling the implicit driver cache returned0x887A002Din every timed process. Fresh paths consistently reproduced long first-use PSO creation times. The cache state inside the driver was unobservable, so fully cold compiler cost remains unverified. These CPU timings do not measure dispatch or frame time.GPU correctness
Full 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
0x7f7fffffafter each dispatch. Comparing the entire 20 KiB buffer against expectations gave zero differing words across nine full-shader checks. A separate coverage probe after the first BVH site preserved all 32 sentinels in the empty-box case and allowed all 32 writes in the two controls for every configuration.Instruction readback. Both original 20-byte
image_bvh_intersect_rayinstructions, at0x01C8and0x0880, were replayed with their original register operands. Four-child box32 and box16 cases covered sorting on and off, hits, distance clipping, grazing rays and misses. All 1,024 output words per configuration matched the geometric expectations and a separate HLSL + DXC GPU run bit for bit. Readbacks also matched across configurations. The second BVH site has instruction-replay coverage only. Full-shader tests used controlled inputs, and gameplay rendering was outside this benchmark.Reproduction details
ea683a007da7f0319bbaf680a37717a582445ac3and PR head 365148b. Separate target directories, locked dependencies, release profile and identical measurement code.XCL_DXIL_NO_OPTwas unset for the parent and enabled PR. The third configuration set onlyXCL_DXIL_NO_OPT=cfg.deferred_tiled:CS_LaserLightShadowRaytracing_c3ab3042_Wrapped, inflated-record FNV-1a-647118f495493c73af, 3,332 program bytes, 642 decoded instructions and 32 × 1 × 1 threads.AI disclosure. Codex prepared the harness, ran the tests and drafted this report.
@futurepro62 on GitHub · 2026-11-24 22:37 UTC · original · edited 2026-11-24 22:54 UTC
Full-suite run, since this PR has no test report yet. Tested exact head
365148b(on its baseea683a0).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu: 893 passed, 0 failed, 42 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.constant_conditional_removes_edge_and_trivial_phi,constant_switch_keeps_only_the_selected_predecessor,edge_trim_keeps_a_loop_phi_backedge.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 894 passed, 0 failed, 42 ignored. SKIPPED:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out five tests where this PR's base has them. They fail on main689f2dbtoo, not because of this PR: underXCL_REQUIRE_GPU=mesh,runner::skip_testturns their skips into failures. These areheap_window_out_of_memory_falls_back_to_the_switch_form(#1651) and the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests (follow-up on #1651). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
@pvfreis on GitHub · 2026-11-24 23:34 UTC · original
7c44c94(same tree as1a52a27, which is what ran; onmain689f2db; sandbox, debug, RTX 3060): 976 passed, 3 failed, 45 ignored;689f2dbalone 974 / 1 / 45 (the same e2e).DoubleExtensionsand the version point are settled. Two failures remain, therequirecase I had read but not run:fuzz_validate_and_gpu_1seed 884,_2seed 1417:Flags declared=1048592, actual=16: bit 20,Int64Ops, set byShader::requirewhile building an i64 instruction in a block the fold then empties._0and_3pass.mainis now20cf130(#1900, two MSAA files, none of yours); I have not run on it.Run and written with Claude Code (Claude Opus 5.5), checked with Claude Fable 5.2; each point checked by a person before posting.
@DavidM1911 on GitHub · 2026-11-25 00:39 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@ivall on GitHub · 2026-11-25 11:35 UTC · original
A measurement on whether this pass finds anything in the programs it is meant for. I did not run this head (it conflicts with
maininopt.rsandkernel.rs); I put the same step intomain9633138as a local prototype: after eachoptimizeround, constantCondBr/Switchterminators folded, unreachable blocks dropped, up to 4 rounds. A second switch also used what a branch tells about its condition in the blocks below it.95cc13288a27a96eef008c0f04b6261a742a41ceb422beb533743bd6d1e45443So 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,
XCL_DIRECT_DXIL=1,XCL_DIRECT_COMPACT=0, 4 memory windows, translation only.AI use: Claude Code (Claude Opus 5.5) wrote the prototype, ran it and wrote this on the maintainer's behalf.
@Toons29 on GitHub · 2026-11-25 13:44 UTC · original
Regression run of
0561b6b0on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon1a0bbe3a, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 100 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.@jennydeth on GitHub · 2026-11-25 14:13 UTC · original
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 main1a0bbe3.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)
seed 884: validator rejected the module:
error: Flags must match usage.
note: Flags declared=1048592, actual=16
gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_2
seed 1417: validator rejected the module:
error: Flags must match usage.
note: Flags declared=1048592, actual=16
Reproduced with cargo test -p xcl --lib -- fuzz_validate_and_gpu (same two seeds). The same filter on main
1a0bbe3: 4 passed, 0 failed. The module declares flag bit 0x100000 that its code no longer uses; my guess (not checked) is that the CFG folding removes the instruction that set it without recomputing the flags.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report, checked by a person before posting
@DavidM1911 on GitHub · 2026-11-26 06:19 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.@pvfreis on GitHub · 2026-11-24 22:48 UTC · original · reviewed
Review of
365148bmerged ontomain689f2db(no conflict, tree46747484).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.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.
0561b6b055to673ab90c82View 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.