Recompiler: direct DXIL optimizer runs to a fixed point with new passes #3269
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3269"
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 Foniass on 2026-11-29T02:29:16Z.
#3266 and #3268 are merged; this PR is now one commit (
a899ec90) on main5b0d5fa3. It includes #3268's review fixes (the fold's phi edges, the 64-bitcmpxchgflag), which are on main.Rebased for a test on newer main: main's
lanes::ps_ballot_tests::direct_ps_mask_and_scc_counts_live_lanes_only(de915b5a) split a block with a deads_add, so that block-local CSE kept two identicalwaveActiveBallot(true)calls apart. This PR's fixed-point loop runs CSE again aftersimplify_cfghas merged that block away, and folds them. That fold is correct (one block, no discard between), but the test then counts 1 ballot instead of 2 (the CI failure on568e9380). The test now exports the skippeds14, so its split stays; that is the only change to it.The IR part of amd-dev's direct DXIL size work (
f089a9df, "shrink emitted shaders 4.5x-5.4x"); the bitcode part is #3250 and the compact-form part is #3261.optimize()now repeats its passes, up to 4 times, while one of them still changes the function. It gains:createHandleFromHeapunshared,annotateHandle/getDimensionsblock-local)XCL_RDNA_FLOAT's FRC and legacy mul / fmaXCL_DXIL_NO_OPTgainsalloca,facts,hoistandbarrier.What is in it
crates/xcl/src/gpu/dxil/module/opt.rs: the passes,optimize()rebuilt as the fixed-point loop,layout_positions, three new tests (local_alloca_store_load_forwarding_and_dse,hoist_entry_readnone_and_keep_heap_handles_unshared,redundant_barriers_eliminated_within_block)crates/xcl/src/gpu/dxil/lanes.rs,prelude.rs,lower_valu.rs,module.rs(const_f32);lanes.rsalso has the test change abovefold_guarded_selects, the trivial-phi pass aftersimplify_cfg, and main's back-edge check in every trivial-phi pass. The original commit'sXCL_HEAP_WINDOWSdefault flip is left out (two NVIDIA setups failed with heap windows on, per the amd-dev port).NVIDIA fix in this port: with
XCL_RDNA_FLOAT(on by default) the original commit lowersv_fract_f32to a bare nativeFrc. On NVIDIAFrcof a tiny negative input returns 1.0, which RDNA never does (it clamps to0x3F7FFFFF):gpu_fract_f32_edgesandf32_programs_on_the_gpufailed every run. The port keeps the nativeFrcand its result keeps the old clamp. The original was only run on AMD.Why it needs #3266, and size
Without #3266's live double-ext scan, the new passes remove f64 ops but
DoubleExtensionsstays declared, and the validator rejects the module (fuzz_validate_and_gpu_0, seed 33). With it, the fuzz tests pass. The change is 886 + 245 lines: the new passes share the rewrittenoptimize()loop. It could be split into the loop plus one PR per pass if a reviewer prefers.#3265 (merged): amd-dev's
f089a9dfalso changed #3265's testraw_buffer_oob_check_guards_32bit_wraparound(the atomic'sOFFSETfrom 16 to 20). On main, which has #3265, the test passes unchanged with this PR.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4ona899ec90(rebased onto main5b0d5fa3): 2779 passed, 0 failed, 49 ignored. SKIPPED GPU tests: 45 distinct notices, almost allno wave64.-StartupTimeoutSeconds 3600for the cold pipeline rebuild new DXIL needs.Regression run
main:
this PR:
Not tested
AI use
f089a9df, merged itsoptimize()with main's, found the dependency on #3266 (seed 33), adapted main's ballot test, ran the tests and the smoke run above, wrote this description.f089a9df(raylitebull, from46aecbf7, written with Antigravity (Gemini 4 Neon High)).🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T03:23:09Z.
merge-check
base:
fa204595a4head:
b97cdff57cmerge: clean onto main (stacked on #3266 + #3268) and with the full 8-PR stack.
build: cargo build --workspace -> ok; cargo build --release -p xcl -> ok.
tests: In the clean 8-PR stack on main
fa204595with DXC 1.9.2609.5 and default env:cargo test -p xcl --lib --no-fail-fast -- --test-threads=4-> 2483 passed, 3 failed, 29 ignored; failing:gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(f32 rounding, wave32: lane 0 v9: 0x3f800000 against 0x3f7fffff),gpu::recomp::tests::gpu_fract_f32_edges(lane 6: fract(-0.000000029802322) below 1.0: left 1065353216 right 1065353215), andhle::kernelx::tests::a_page_whose_move_fails_stays_mapped_where_it_was(parallel flake). Re-running all 3 withXCL_RDNA_FLOAT=0passed (3 passed; 0 failedin 0.90 s), and the 7-PR stack without #3269 passed all 2620 workspace tests with default env. 150 sxcl-smoke(ea3b5e4d,XCL_PREPARE=0, RTX 5070 Ti) on the combined 8-PR stack:exit: 0x0,2096frames shown,0device removals,0crashes,0display System events,32049 MBpeak commit.review: finding in
crates/xcl/src/gpu/dxil/prelude.rs:rdna_float_enabled()(XCL_RDNA_FLOAT) defaults totrue, which lowersfract_fto a singledx.op.unary(Frc). On NVIDIA RTX 5070 Ti,dx.op.unary(Frc)returns1.0f(0x3f800000) instead of0x3f7fffffforfract(-2^-25), failing bothf32_programs_on_the_gpuandgpu_fract_f32_edges. Either keepfract_f's< 1.0clamp (defaultingXCL_RDNA_FLOAToff on non-RDNA / by default) or drop theFrcshortcut from default lowering.performance: positive IR shrink from the optimizer passes when
XCL_RDNA_FLOAT=0(8-PR smoke 2096 frames, 32049 MB peak commit), but default-onFrcbreaks f32v_fract_f32precision on NVIDIA.verdict: not yet:
XCL_RDNA_FLOATdefaults to on inprelude.rs, breakingfract_fon NVIDIA RTX 5070 Ti (f32_programs_on_the_gpuandgpu_fract_f32_edgesfail with0x3f800000vs0x3f7fffff; both pass withXCL_RDNA_FLOAT=0).hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (wave32 only), Windows 11, DXC 1.9.2609.5 via XCL_DXC_DIR; Antigravity (Gemini 3.5 Pro) ran the merges, builds, workspace test suites, 150 s title smokes, diff reviews, and drafted this check.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T06:39:32Z.
merge-check
base:
fa204595head:
4a8217a7verdict: safe to merge
Re-verified updated head
4a8217a7(fast-forward ontoorigin/mainfa204595, NVIDIA GeForce RTX 5070 Ti, DXC 1.9.2609.5, defaultXCL_RDNA_FLOATenabled):gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: 1 passed, 0 failed (0.69 s) — the0x3F7FFFFFclamp on nativeFrcfixes the previous NVIDIA failure.gpu::recomp::tests::gpu_fract_f32_edges: 1 passed, 0 failed (0.36 s).gpu::dxil::: 241 passed, 0 failed, 3 ignored (8.10 s, includingfuzz_validate_and_gpu_0..3).xcl --lib: 2477 passed, 0 failed, 29 ignored (5 parallel-contention tests re-verified 5/5 with--test-threads=1; 2 knownmain#3187uma_drivermixed-window tests skipped).Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T19:32:43Z.
Test report: cold driver compile time with this stack on an RTX 2070 SUPER (Turing, 8 GB). One run per record, so read it as a direction.
I merged both of Foniass's stacks onto
main0fe06eb0(#3250 → #3261 → #3263 and this PR's #3266 → #3268 → #3269; they merge without conflicts) and compared that build withmain. The numbers are for both stacks together: I did not measure them separately.Setup
xcl shaders <retail game's shaders.rpf> --measure-pso <record> --repeat 1: the driver's shader caches are turned off (ShaderCacheControl, Developer Mode), so every build is cold. One compile at a time, through a local exclusive queue.Results (DXIL bytes, cold
CreateComputePipelineStates)mainXCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=195cc13288a27a96e2e1d03fbed9d95eb958400d2caf0724456c0cd3b82a00c6e1d4ecf4cb407d4fe95cc…, the program #3261 names: 4.8× less DXIL and 5.1× faster to build cold here.958400d2…and56c0cd3b…: about half. The plain-form programs (2e1d…,1d4e…) shrink 27–32 % but build barely faster; heap windows help those instead, so the two are complementary.E_OUTOFMEMORY).Not tested: the stacks separately; the suite and a title run of the merged build (only pipeline builds); whether the image is the same; AMD.
AI use: Claude Code (Claude Opus 5.5) merged and built the stacks, ran the queued job and wrote this report.
Context: why DXIL size matters for cold compilation. On this title, compute programs whose whole DXIL is 512 KiB or larger are 27 % of the 2,730 compute programs but about 95 % of a cold full preparation's compute driver work (driver time weighted as size^1.6, fitted to 1,340 cold compiles on this card). So size reductions count almost only on those programs. Breakdown by size band: https://github.com/xcl-dev/xcl/issues/2088#issuecomment-7262349510
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T21:42:55Z.
Test report: full startup shader preparation, cold cache, with #3442 + the #3263 stack + the #3269 stack together
One run of a build that combines these three PRs. It shows what they do together; it does not say how much each one contributes.
Build:
a96b183c, local merge of 4465c886 (main3b6a91ed+ #3318 #3321 #3323 #3325 #3328 #3330 #3332 #3336 #3364 #3377 + #3241 + #3242) with:4511c6e5;e13ccd7f, #326116f2f5c1, #3263e618b742);a343eafc, #3268527a8b26, #32694a8217a7).cargo build --release -p xcl. Also set:XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1(stands in for #2428, which does not merge onto this set).This PR in the build: the whole stack, #3266
a343eafc, #3268527a8b26, #32694a8217a7(the head is nowe01151a2, which differs).Run: retail game,
XCL_PREPARE_ALL=1(all 26,503 records),XCL_RUN_SECONDS=180(ends 180 s after the title starts),XCL_ACTIVITY=1. Cold XCL cache:XCL_DXIL_CACHEpointed at a new, empty folder, so no translation, DXC output or driver blob was reused.Compared with: the same retail game and settings on 4465c886 alone (the base above, without the three PRs and without the heap switches), run earlier today with a warm cache: it started with 48,305 translations, 44,556 DXIL files and 13,051 driver blobs, and reused about half of its driver blobs.
Not tested / limits
30122062) and #3269 (nowe01151a2, with #3268 now64f666c0) have changed since, so this report is for the commits listed above.Hardware: NVIDIA GeForce RTX 2070 SUPER 8 GB (driver 621.40), AMD Ryzen 5 3600XT, 32 GB, Windows 11 Home build 26300, rustc 1.100.1.
Tool and model: Claude Code (Claude Opus 5.5): two sessions on this machine ran the queued runs; this one extracted the numbers from their logs and wrote this report.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T22:39:26Z.
Review: COMMENTED
Static review of
e01151a2for the stack in the #3041 comparison.Legacy floating-point fast paths can change signed-zero results. One known finite nonzero operand removes both zero checks. For instance, multiplying literal
-1.0by runtime+0.0can yield-0.0, where the prior legacy lowering returned+0.0. The FMA fast path can similarly bypass returning the exact addend when the runtime operand is zero. Keep the check for any operand that can still be zero. Float fast pathsThe scalar alloca pass can also delete an initializing store if its only load uses a trivial pointer PHI. The load is still keyed by the PHI when liveness is counted. Later operand rewriting exposes a load from the now-uninitialized alloca. I found no current shader-lowering caller that constructs this IR pattern. Store elimination
Both findings apply to
4a8217a7in the measured stack and were checked ine01151a2.Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
Imported from ivall/xcl. Originally posted by jsalzy on 2026-11-30T03:38:17Z.
merge-check claim
head:
a899ec90b5Imported from ivall/xcl. Originally posted by jsalzy on 2026-11-30T03:54:56Z.
merge-check
base:
f97120dc19head:
a899ec90b5merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2843 passed, 1 failed, 51 ignored; SKIPPED: 25 (22 no wave64 on this GPU; 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (gpu_two_pass_cache_e2e.rs:584 "releasing the title PSOs releases their two-pass state", left 1, right 0, in its warm child run; cargo also prints the child's result, so its total reads 2 failed), passes on base this time but is unstable on this machine: the same assertion failed in 4 of 17 suite runs tonight, twice on main alone. Main alone at
f97120d: 2841 passed, 0 failed, 51 ignored. The PR's three new tests pass, and so do f32_programs_on_the_gpu (wave32 parts; wave64 skipped) and gpu_fract_f32_edges on this NVIDIA card, the two the first check saw fail on an RTX 5070 Ti atb97cdff.review: one finding, then the rest reads right. (1) XCL_RDNA_FLOAT (default on) gives mul_legacy and fma_legacy a fast path that returns a plain fmul / fmad as soon as ONE operand is a finite non-zero constant, dropping the == 0 test of the other operand. That test is not redundant: mul_legacy(-2.0, x) with x = +0.0 gives +0.0 on main and -0.0 with the fast path; fma_legacy(2.0, x, -0.0) with x = 0 gives -0.0 on main and +0.0; and a subnormal constant (x != 0.0 in Rust) is taken as non-zero although the GPU flushes it to zero. No test covers a one-constant legacy multiply with a zero operand. #2262 (older, open) changes the same functions but keeps the compare for the unknown operand and excludes subnormals; the two conflict in prelude.rs. (2) The rest, whole diff read: the passes repeat up to 4 times while one still changes the function; scalar-alloca forwarding and dead-store removal only touch non-escaping single-element allocas and stay inside a block; branch facts go only into a block whose single predecessor branches on the condition and stay within its dominator subtree; the entry hoist takes only groupId / threadId / flattenedThreadIdInGroup / createHandleFromBinding with entry-available arguments and leaves heap handles, annotateHandle and getDimensions in their blocks (minor: the doc comments of hoist_entry_readnone still say it hoists createHandleFromHeap / annotateHandle); a barrier is dropped only when an equal or stronger one precedes it in the block with no store, atomic, non-constant load or non-ReadNone call between; CSE's block-local table is cleared after dx.op.discard. f32 compares become single ordered / unordered fcmp (mapping checked: nlt -> UGE, nge -> ULT, nlg -> UEQ, lg -> ONE). #1860 (open) also edits opt.rs's CFG clean-up; not a duplicate.
performance: every pass removes or merges instructions, so the DXIL gets smaller; translation time can rise (up to 4 optimizer rounds per program), not measured here.
verdict: not yet: in the XCL_RDNA_FLOAT fast path of mul_legacy / fma_legacy, take plain fmul / fmad only when both operands are known non-zero normals (or keep the == 0 test of the unknown operand, as #2262 does), and settle the overlap with #2262.
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.