dxil: fold constant CFG terminators after CSE #1808
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-11-24T21:11:47Z.
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 main0fe06eb0f0, PR headc32c65e05d. 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.Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T21:26:41Z.
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.
Imported from ivall/xcl. Originally posted by minimalhipster990 on 2026-11-24T21:32:56Z.
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.
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T22:48:12Z.
Review: COMMENTED
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.
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T22:37:14Z.
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
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T23:34:51Z.
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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T00:39:31Z.
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!
Imported from ivall/xcl. Originally posted by ivall on 2026-11-25T11:35:33Z.
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.
Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T13:44:37Z.
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.Imported from ivall/xcl. Originally posted by jennydeth on 2026-11-25T14:13:49Z.
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
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T06:19:57Z.
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.Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T22:29:08Z.
For the record: #3268 (merged,
5b0d5fa3) folds constant CFG terminators in direct DXIL and recomputes the live shader flags, which covers this PR. If something here is still missing onmain, it could go in a smaller PR on top. Otherwise this one can be closed.(Claude Code, Claude Opus 5.5, for Foniass)
Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-11-29T23:27:49Z.
@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
mokkamokacaffeas the author of the CFG and path-fact folding. The merged port links back here in its message, but my account is absent from its Git author and co-author fields.What I'd like preserved in the commit record is
mokkamokacaffeas author of the original implementation, with raylitebull and Foniass credited for the port and their additions, and the existing AI disclosures retained. Separate commits for the original and follow-on work would also reflect that accurately. Since the combined commit is already on main, could you let me know what correction the project can support without rewriting shared history? Happy to help get the attribution right for everyone.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:53:11Z.
Triage (#1607) – head
28a28e6The CFG folding this PR started with is on main: #3268 ported it (
04df590, merged in5b0d5fa). The diff against main is now only the two tests inshader.rs(type_feature_tests). Main'sdead_branch_i64_and_heap_handle_do_not_leave_stale_shader_flagsalready covers theInt64Opshalf of the first test. TheDoubles/DoubleExtensionschecks and the live-FMA test are not on main.The title and description still describe the folding pass. They should say that the PR only adds tests now.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.