Skip to content

dxil: fold constant CFG terminators after CSE - #1818

Open
mokkamokacaffe wants to merge 4 commits into
xcl-dev:mainfrom
mokkamokacaffe:codex/dxil-fold-constant-cfg
Open

mokkamokacaffe wants to merge 4 commits into
xcl-dev:mainfrom
mokkamokacaffe:codex/dxil-fold-constant-cfg

Conversation

@mokkamokacaffe

@mokkamokacaffe mokkamokacaffe commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Current scope at 28a28e63: #3268 landed the port of the CFG folding from this PR in 5b0d5fa3. The remaining diff against main adds two regression tests in shader.rs. The implementation history and predecessor results are preserved below. Port and attribution discussion

Part 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 constant CondBr and Switch terminators after CSE.
  • Propagate only branch/switch selector values proven on incoming edges; intersect facts at joins so contradictory paths are discarded.
  • Recompute reachability and predecessor edges, remove obsolete PHI inputs, and rerun trivial-PHI simplification while preserving loop backedges.
  • Add cfg to XCL_DXIL_NO_OPT for independent bisection.
  • crates/xcl/src/gpu/dxil/module.rs: compute double-extension use from surviving instructions after CFG cleanup, including live Fma calls.
  • crates/xcl/src/gpu/dxil/shader.rs: recompute Int64Ops, Doubles, and DoubleExtensions after optimization so removed wide operations cannot leave stale metadata.
  • Add focused tests for constants, dominated branches and switches, reconvergence, loop-carried PHIs, stale type-feature flags, and live FMA feature inference.

Tested

  • On predecessor 365148b against ea683a0, Anon64 reported a clean default smoke on RTX 3060 with direct DXIL disabled. With XCL_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 reruns

  • Windows no-GPU CI tested merge ddd8a46 (head 28a28e63 on main 3db0ee4e). Both remaining shader-feature tests passed. The library harness reported 2,654 passed, 1 failed and 29 ignored. The failure was hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline. A matched baseline for that failure is unreported. CI log

  • On predecessor 365148b against ea683a0, 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 controls

  • On 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 measurements

  • On 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-msvc passed in a Linux cross-check environment using a local lib.exe-compatible archive wrapper. This was compile-only; Windows test binaries were not executed.

  • git diff --check: passed on 673ab90c82584abfdd5e65bf61e199c373f5752d.

  • Historical predecessor 0561b6b, Windows 11 / NVIDIA RTX 3060: cargo test --workspace -- --test-threads=4 reported 1186 passed, 2 failed and 26 ignored before the lib test binary stopped. The two failures were fuzz_validate_and_gpu_1 seed 884 and fuzz_validate_and_gpu_2 seed 1417: declared flags 1048592, actual 16, exposing a stale Int64Ops bit after CFG folding. Predecessor 673ab90 adds 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

xcl-smoke v1
commit: 0fe06eb0f05459007ebfffc67bb9983acb3a832d
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 60
exit: 0x0
frames shown: 1584 (PresentX 1584)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16004 MB

PR

xcl-smoke v1
commit: c32c65e05d561f50713abc6b37bd6aada9ebb0ea
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 60
exit: 0x0
frames shown: 1413 (PresentX 1413)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16097 MB

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 on 673ab90c82584abfdd5e65bf61e199c373f5752d is pending.

main:

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14561 MB

PR predecessor:

xcl-smoke v1
commit: 0561b6b055371015409b25785fa03852bbb310c5
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14591 MB

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

  • OpenAI Codex (GPT-5) implemented the original path-fact pass and focused CFG tests.
  • OpenAI Codex (GPT-6.2 Astra Ultra) rebased the change onto current 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.
  • A GPL-3.0 project's reported behavior was considered as evidence only; no code was copied or adapted.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

Regression run for this PR: head 365148b, based on main ea683a0. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, back to back with the main run.

Default settings (the pair for Regression run):

main ea683a0:

xcl-smoke v1
commit: ea683a007da7f0319bbaf680a37717a582445ac3
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1488 (PresentX 1488)
presents per 2 s (last 3): 26 4 2
device removals: 0
crashes: 0
peak commit: 23201 MB

this PR:

xcl-smoke v1
commit: 365148bcc935ef04aeb9608debe0d72ba7db866f
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1602)
presents per 2 s (last 3): 49 55 33
device removals: 0
crashes: 0
peak commit: 20875 MB

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:

run frames crashes peak commit
main ea683a0 1455 0 24.6 GB
this PR, run 1 – 1 15.7 GB
this PR, run 2 1474 0 24.7 GB
this PR, run 3 1468 0 24.5 GB

Run 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

Copy link
Copy Markdown

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

Direct DXIL output Parent PR enabled PR with cfg disabled
Validated container, bytes 27,312 26,736 27,312
Basic blocks in the compute entry 119 119 119
Conditional branches 59 57 59
Conditional branches with a literal condition 2 0 2
Unconditional branches 59 61 59
PHI instructions 362 321 362

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 97da0d91b8994f85a62ab78625be8e07d6fbe8b33dd39577b8ebdc27472e1977. With the pass enabled, the digest was de665670b8e83bbc1361b9d18ca8dbbf5346e2f532fb8df4493a971ec4d04bc9.

Translation and driver timings

Milliseconds of CPU wall time, median [minimum–maximum] across 12 trials per configuration.

Measurement Parent PR enabled PR with cfg disabled
Direct DXIL translation, fixed executable paths 5.054 [4.847–5.450] 5.069 [4.880–5.532] 5.129 [4.783–5.828]
Driver PSO creation, fixed paths after warm-up 0.555 [0.542–0.589] 0.561 [0.550–0.813] 0.567 [0.546–0.768]
Direct DXIL translation, fresh path per trial 5.309 [5.015–5.484] 5.329 [5.148–5.970] 5.194 [5.053–5.576]
Driver PSO creation, fresh path per trial 144.046 [142.445–153.179] 144.630 [141.881–146.185] 143.863 [142.506–151.147]

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.

  • Trials. Each sample ran in a fresh process. Each series used all six possible orders twice. The fixed-path series excluded one warm-up per variant. Each fresh-path invocation used a copy of its build executable in a separate directory. The enabled and disabled PR arms used the same binary. In total there were 72 measured invocations and three warm-ups.
  • DXIL timer. Timed the release-build kernel::translate_compute call 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.
  • Driver timer. Timed the synchronous ID3D12Device::CreateComputePipelineState call after device and root-signature creation. The application supplied no cached PSO blob. Disabling the implicit driver cache returned 0x887A002D in 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 0x7f7fffff after 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_ray instructions, at 0x01C8 and 0x0880, 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

  • Revisions. Immediate parent ea683a007da7f0319bbaf680a37717a582445ac3 and PR head 365148b. Separate target directories, locked dependencies, release profile and identical measurement code. XCL_DXIL_NO_OPT was unset for the parent and enabled PR. The third configuration set only XCL_DXIL_NO_OPT=cfg.
  • Input. deferred_tiled:CS_LaserLightShadowRaytracing_c3ab3042_Wrapped, inflated-record FNV-1a-64 7118f495493c73af, 3,332 program bytes, 642 decoded instructions and 32 × 1 × 1 threads.
  • System. NVIDIA GeForce RTX 4090, driver 621.24, AMD Ryzen 7 5800X3D, Windows 11 build 26300.10075, Rust 1.99.1, Windows SDK 10.0.26100.0, DXC and DXIL validator 1.9.2602.17. Tested on 24 November 2026.
  • Focused tests. The PR's three optimizer tests passed on Windows in release mode, covering constant conditional branches, constant switches and preservation of a loop-carried PHI edge. The filter excluded 864 other tests.

AI disclosure. Codex prepared the harness, ran the tests and drafted this report.

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 365148b (on its base ea683a0).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_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.
  • The new tests ran and passed: constant_conditional_removes_edge_and_trivial_phi, constant_switch_keeps_only_the_selected_predecessor, edge_trim_keeps_a_loop_phi_backedge.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, 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).
  • On NVIDIA, --skip leaves out five tests where this PR's base has them. They fail on main 689f2db too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns their skips into failures. These are heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (follow-up on #1651). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@pvfreis pvfreis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 365148b merged onto main 689f2db (no conflict, tree 46747484).

  1. CONFIRMED (run): three fuzz tests fail on the merged tree and pass on main here (RTX 3060). fuzz_tests.rs came with #1679, after this head, so the runs on ea683a0 cannot see it.

    test (first failing seed) validator
    fuzz_validate_and_gpu_0 (33) error: Flags must match usage. / Flags declared=1572948, actual=1572884
    fuzz_validate_and_gpu_1 (641) Flags declared=84, actual=20
    fuzz_validate_and_gpu_2 (1103) Flags declared=80, actual=16

    These are validator rejections, separate from the GPU failures reported on main in #1679 (AMD, RTX 5060 Ti).

    The difference is always 64, bit 6, DoubleExtensions. uses_double_extensions (module.rs:1394 on the merged tree) scans all of self.insts, including the instructions of the blocks the new step empties (opt.rs:535); insts_use_type next to it scans self.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::require only adds, and Lw::f64ty, Lw::i64, v_cvt_f64_i32 (lower_wide.rs:875), Shader::binary on i64/f64 and the wave ops call it while building, so a flag whose only user is in an emptied block stays declared (removable refuses those for this reason). One way is to derive the flags from the remaining blocks after optimize. Each test stops at its first bad seed, so rerun all four. The flag code is the same at ea683a0. The block scan is also proposed in #1894 (item 2) and made by the draft #1544; neither covers the require flags.

    cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4, debug, RTX 3060, DXC 1.9.2602.17, isolated session: main 974 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.

  2. CONFIRMED (read): TRANSLATOR_VERSION needs a value above main's 7. main went 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 says gpu/dxil is not in build.rs's source hash, so with the same DXC and backend a cache written by main at 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.

@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

7c44c94 (same tree as 1a52a27, which is what ran; on main 689f2db; sandbox, debug, RTX 3060): 976 passed, 3 failed, 45 ignored; 689f2db alone 974 / 1 / 45 (the same e2e). DoubleExtensions and the version point are settled. Two failures remain, the require case I had read but not run:

  • fuzz_validate_and_gpu_1 seed 884, _2 seed 1417: Flags declared=1048592, actual=16: bit 20, Int64Ops, set by Shader::require while building an i64 instruction in a block the fold then empties. _0 and _3 pass.

main is now 20cf130 (#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

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@ivall

ivall commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

A measurement on whether this pass finds anything in the programs it is meant for. I did not run this head (it conflicts with main in opt.rs and kernel.rs); I put the same step into main 9633138 as a local prototype: after each optimize round, constant CondBr / Switch terminators 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.

record constant terminators, fold only fold + branch conditions known below the branch
95cc13288a27a96e 0 (23,516 blocks, 12,694 branches) 0, DXIL the same bytes (2,401,953 B file)
ef008c0f04b6261a 0 1, 957,141 → 957,101 B
742a41ceb422beb5 0 1, 962,829 → 962,797 B
33743bd6d1e45443 0 1, 872,249 → 872,229 B

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, 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.

@mokkamokacaffe
mokkamokacaffe force-pushed the codex/dxil-fold-constant-cfg branch 2 times, most recently from a7cc735 to 0561b6b Compare November 25, 2026 11:59
@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 0561b6b0 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 1a0bbe3a, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14561 MB
xcl-smoke v1
commit: 0561b6b055371015409b25785fa03852bbb310c5
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14591 MB

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

Copy link
Copy Markdown

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)
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

raylitebull added a commit that referenced this pull request Nov 25, 2026
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)
@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

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)
@mokkamokacaffe
mokkamokacaffe force-pushed the codex/dxil-fold-constant-cfg branch from 0561b6b to 673ab90 Compare November 26, 2026 11:22
koboshchan pushed a commit to koboshchan/xcl that referenced this pull request Nov 26, 2026
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)
raylitebull added a commit to raylitebull/xcl that referenced this pull request Nov 28, 2026
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>
Foniass pushed a commit to Foniass/xcl that referenced this pull request Nov 29, 2026
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>
Foniass pushed a commit to Foniass/xcl that referenced this pull request Nov 29, 2026
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>
@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@Foniass

Foniass commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

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 main, it could go in a smaller PR on top. Otherwise this one can be closed.

(Claude Code, Claude Opus 5.5, for Foniass)

@mokkamokacaffe

Copy link
Copy Markdown
Contributor Author

@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 mokkamokacaffe as 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 mokkamokacaffe as 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.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 28a28e6

The CFG folding this PR started with is on main: #3268 ported it (04df590, merged in 5b0d5fa). The diff against main is now only the two tests in shader.rs (type_feature_tests). Main's dead_branch_i64_and_heap_handle_do_not_leave_stale_shader_flags already covers the Int64Ops half of the first test. The Doubles / DoubleExtensions checks 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 goal:world-load Bears on the retail title getting past world loading gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants