Skip to content

Recompiler: collapse empty trampolines and merge linear blocks in direct DXIL opt - #2194

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
zondy1i:dxil/opt-cfg-cleanup
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
zondy1i:dxil/opt-cfg-cleanup

Conversation

@zondy1i

@zondy1i zondy1i commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1269.

After DCE in gpu::dxil::module::opt, guarded lowering helpers and dead branches leave thousands of empty trampoline blocks ([Br(target)]), single-predecessor linear chains, and degenerate CondBr(c, t, t) / Switch terminators in the emitted DXIL.

What is in it

  • crates/xcl/src/gpu/dxil/module/opt.rs: add a fixed-point Module::simplify_cfg pass after DCE (opt-out via XCL_DXIL_NO_OPT=merge, orthogonal to dxil: fold constant CFG terminators after CSE #1818's constant-terminator folding):
    • Collapse degenerate CondBr(_, t, t) to Br(t) and strip Switch cases matching default, updating Op::Phi edge multiplicity to match.
    • Bypass empty trampoline blocks ([Br(t)], b != 0, t != b) whenever t's phis allow it without creating conflicting incoming values or inflating multi-predecessor phi tables (!target_has_phi || total_edges <= 1).
    • Merge single-predecessor linear blocks a -> b along unconditional branches, resolving single-input phis in b, updating def_block, and rewriting successor phis from b to a (including loop backedges).
    • Run a lightweight follow-up trivial-phi + DCE cleanup when CFG simplification changed terminators or phis.
  • Add 5 unit tests covering trampoline chains, phi-conflict preservation, degenerate CondBr/Switch collapse, loop-latch merge with header-phi rewriting, and the multi-predecessor phi guard.

Measured impact

  • Across all 2,682 compute programs from a retail shader pack (XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1, XCL_DXIL_NO_OPT=merge vs default): 2,682 / 2,682 strictly smaller, 0 larger (775,076,910 -> 774,508,202 B).
  • On the largest compute program (95cc13288a27a96e): basic blocks 23,619 -> 20,506 (-13.2%, -3,113 blocks), IR lines 513,461 -> 504,122 (-9,339 lines), DXIL 3,345,980 -> 3,332,628 B (-0.40%).

Tested

  • Windows 11, AMD Ryzen 5 7500F, 64 GB RAM, NVIDIA GeForce RTX 3060 Ti 8 GB (driver 621.01), Rust 1.100.0 MSVC, DXC/dxil 1.9.2602.17.
  • cargo test -p xcl --lib gpu::dxil -- --skip fuzz_validate_and_gpu: 123 passed, 0 failed, 3 ignored (including all 5 new opt::tests::simplify_cfg_* tests and GPU execution tests on RTX 3060 Ti).
  • xcl shaders <pack> --direct --validate --sample 1000 --max-bytes 0 --split 1 with XCL_HEAP_WINDOWS=1: 1,000 / 1,000 (100.0%) across CS (102), GS (18), MS (350), PS (440), VS (90) — 0 validator errors, 0 panics, 0 timeouts.

Not tested

  • AMD / Intel GPUs, Linux / vkd3d-proton, cold cache-off NVIDIA driver compile timings (Windows Developer Mode is disabled on this machine).

Regression run
Base (main):

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1580 (PresentX 1580)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15495 MB

PR (e64bd17):

xcl-smoke v1
commit: e64bd17bc43714c2b3ac940da33a7be84d30999c
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1542 (PresentX 1542)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15367 MB

AI use

  • Implemented, tested, and described with Antigravity (Gemini 4 Neon).

@DarkPanda69

Copy link
Copy Markdown

AMD run (listed as untested), paired against main, with the direct translator on for the whole GPU suite since this changes the optimizer every direct-DXIL program goes through.

Head e64bd17 applied on main 568e7db, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4, run on main and on this PR for each card:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010, native wave64) 583 passed, 3 failed, 22 ignored, 6 SKIPPED 588 passed, 3 failed, 22 ignored, 6 SKIPPED
RTX 3060 (32.0.16.1088, wave32, split wave64) 585 passed, 1 failed, 22 ignored, 23 SKIPPED 590 passed, 1 failed, 22 ignored, 23 SKIPPED

Per-test comparison: on both cards the only differences between the two runs are the 5 new simplify_cfg_* tests (all ok). No existing test changes result. The failures are the same on main: gpu_image_get_resinfo_1d_array on both cards (the direct-path bug #2046 fixes) and, on the RX 9070 XT only, the fuzz seeds 722 and 1599 tracked in #2115.

Not tested: driver compile time on AMD, a title with XCL_DIRECT_DXIL=1.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@NWProgramming00

Copy link
Copy Markdown

Independent run on NVIDIA and on an AMD GPU with native wave64 (the AMD part is listed as not tested). Exact head e64bd17, compared with its base 568e7db.

Hardware: Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB, and an AMD Radeon RDNA2 iGPU (gfx1036, native 64-lane waves) selected with XCL_ADAPTER=radeon. Release builds.

cargo build --release --workspace then cargo test --release --workspace --no-fail-fast -- --test-threads=4, each adapter with and without XCL_DIRECT_DXIL=all:

Adapter Mode base 568e7db PR e64bd17
RTX 5070 Ti default 1150 passed, 4 failed 1155 passed, 4 failed
RTX 5070 Ti XCL_DIRECT_DXIL=all 1148 passed, 6 failed 1153 passed, 6 failed
Radeon gfx1036 default 1153 passed, 1 failed 1158 passed, 1 failed
Radeon gfx1036 XCL_DIRECT_DXIL=all 1151 passed, 3 failed 1156 passed, 3 failed

Not tested: cold-cache NVIDIA driver compile times, and a title run.

AI use: Claude Code (Claude Opus 5.5) ran the suites, compared them with the base and wrote this comment.

@bielfreedom

Copy link
Copy Markdown

AMD Windows driver timing for #2194: on the RX 9070 XT, AMD's CreateComputePipelineState is about the same speed with this change, except one program that builds 16 % faster. This adds driver timing to DarkPanda69's GPU suite run on the same card.

Setup

  • GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010.
  • CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release.
  • Builds:
    • base 568e7db;
    • this PR at e64bd17.
  • Both builds carry a local patch that logs per-program DXIL size, record hash (fnv64) and per-CreateComputePipelineState time.

Method

  • XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0, XCL_PIPELINE_THREADS=1.
  • XCL_PSO_DISK_CACHE=0 and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name.
  • 26 retail compute programs, 6 KB to 1.0 MB of direct DXIL: the same set I used for Recompiler: direct DXIL emits a repeated scalar load once #2207.
  • 2 rounds, interleaved.
  • A watchdog killed a run at 24 GB.

26 programs (means of 2 rounds; all 104 builds succeeded, 0 refused)

base #2194 change
direct DXIL, total 8,598,156 B 8,590,924 B −0.08 %
driver, sum (r1 / r2) 271.4 / 271.4 s 268.2 / 267.8 s −1.3 %
driver run, process peak private 4.51–4.60 GB 4.60–4.78 GB about the same
  • All 26 programs are strictly smaller, matching your census. The cuts run from 16 B to 1.1 KB.
  • The other 25 programs stay within ±5 % of their driver time, or within a few ms on those under 0.1 s. The largest, 84eee477d68b6fdf (CS_RaytracingResolve), went 53.2 → 53.6 s.
  • One program stands out: 620491641aa9bad6, 17.9 → 15.1 s (−16 %). Its rounds were 17.93 / 17.90 s on base and 15.12 / 15.06 s on this PR. An earlier pair of base runs gave 17.7 s. Its DXIL shrinks by only 56 B, so the AMD compiler seems to react to the shape of the CFG rather than the size.

ActivateRays (95cc13288a27a96e), plain on this adapter, 1 run:

  • DXIL went 3,916,120 → 3,892,416 B (−0.6 %).
  • It still reached 24 GB after 157 s and was killed (base: 153 s).

Tests on this card (XCL_REQUIRE_GPU=1, XCL_ADAPTER=9070)

  • cargo test --release -p xcl --lib -- dxil::module::opt --test-threads=1: 6 passed, 0 failed.
  • That includes the 5 simplify_cfg_* tests.

Read / inference

  • On the native AMD Windows compiler this is close to neutral overall: −1.3 % on driver time, with no program measurably slower.
  • 620491641aa9bad6 is one of the two programs bobosneefdev reported as slow to build on AMD in [OFFICIAL] Looking for PRs with shaders optimization #1269, so the 16 % there is the part that matters on this vendor.

Not tested

  • The whole gpu:: suite on this build (DarkPanda69 covered it on this card).
  • The HLSL path.
  • XCL_HEAP_WINDOWS=1.
  • A title run.
  • RDNA2 and RDNA3.

AI use: Claude Code (Claude Opus 5.5) ran the measurements and tests and drafted this. The account owner is away; counts and timings only, no game data.

@raylitebull
raylitebull merged commit aaa931b into xcl-dev:main Nov 25, 2026
2 of 3 checks passed
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
…ean-up

simplify_cfg (xcl-dev#2194) bypasses an empty block that only jumps on, and the
latch blocks single_latch makes are such blocks: a block that had back
edges to two loop heads got both again, and the dxil-spirv in
vkd3d-proton segfaulted again on direct programs single_latch had fixed.
A block whose target comes no later in the reverse post-order is now
kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 25, 2026
…ean-up

simplify_cfg (xcl-dev#2194) bypasses an empty block that only jumps on, and the
latch blocks single_latch makes are such blocks: a block that had back
edges to two loop heads got both again, and the dxil-spirv in
vkd3d-proton segfaulted again on direct programs single_latch had fixed.
A block whose target comes no later in the reverse post-order is now
kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
Brings main to full parity with upstream/main (cdb0891), including:
- World rendering & gameplay: xcl-dev#1991, xcl-dev#1988, xcl-dev#1984, xcl-dev#2028, xcl-dev#2078
- Memory / VRAM / PSO: xcl-dev#1985, xcl-dev#2157, xcl-dev#2178, xcl-dev#2195, xcl-dev#2176, xcl-dev#1996, xcl-dev#1914
- Direct DXIL & shaders: xcl-dev#2120, xcl-dev#2174, xcl-dev#2194, xcl-dev#2207, xcl-dev#1951, xcl-dev#1973, xcl-dev#2156, xcl-dev#2064
- Preserves local Linux/Wine customizations: docs/linux.md, scripts/linux/*,
  in-process Wine XAsync (xgameruntime/api.rs), loader watchdog bypass, and
  Wine MEM_WRITE_WATCH bypass on coherent UMA windows (gpu/uma.rs).

Assisted-by: Antigravity (Gemini 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants