Repository navigation
Recompiler: direct DXIL optimizer runs to a fixed point with new passes - #3269
Conversation
68c84c2 to
b97cdff
Compare
|
merge-check |
b97cdff to
4a8217a
Compare
|
merge-check Re-verified updated head
|
4a8217a to
568e938
Compare
568e938 to
e01151a
Compare
|
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 Setup
Results (DXIL bytes, cold
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: #2088 (comment) |
|
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:
This PR in the build: the whole stack, #3266 Run: retail game, 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
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. |
The IR part of amd-dev's DXIL size work. optimize() now repeats its passes (up to 4 times) while one of them still changes the function, and gains: - intra-block store-to-load forwarding and dead-store elimination for non-escaping scalar allocas (mostly the compact form's register slots), and removal of stores to allocas nothing loads; - hoisting of repeated constant-argument ReadNone intrinsics (e.g. dx.op.groupId) to the entry block; createHandleFromHeap stays unshared and annotateHandle / getDimensions stay block-local; - branch facts in the dominator-tree CSE: below a branch on c, c is known (and a switch case's value), so dominated compares fold; - in-place collapse of chained selects on the same condition; - removal of adjacent barriers the first one already covers; - in lanes.rs / prelude.rs / lower_valu.rs: constant EXEC lane-bit folds, single-instruction IEEE f32 compares, and constant fast paths for XCL_RDNA_FLOAT's FRC and legacy mul / fma. New XCL_DXIL_NO_OPT names: alloca, facts, hoist, barrier. Ported to main: the loop keeps main's passes (fold_guarded_selects, the trivial-phi pass after simplify_cfg) and main's back-edge check in every trivial-phi pass (positions recomputed after hoisting, CFG folding and merging; layout_positions). The XCL_HEAP_WINDOWS default flip of the original commit is left out. Needs the live double-ext scan of the commit below (xcl-dev#3266): without it, f64 ops the new passes remove leave DoubleExtensions declared and the validator rejects the module (fuzz seed 33). Ported from the IR part of amd-dev's f089a9d (raylitebull, cherry-picked there from 46aecbf, Assisted-by: Antigravity (Gemini 4 Neon High)). The native Frc of the XCL_RDNA_FLOAT fast path keeps the 0x3F7FFFFF clamp of the old lowering: on NVIDIA Frc rounds a tiny negative input to 1.0, which RDNA never returns (gpu_fract_f32_edges and f32_programs_on_the_gpu failed without it; the original commit was only run on AMD). main's lanes::ps_ballot_tests::direct_ps_mask_and_scc_counts_live_lanes_only split a block with a dead s_add so block-local CSE kept two identical waveActiveBallot(true) calls apart; the fixed-point loop runs CSE again after simplify_cfg merged that block away and folds them (correct: one block, no discard between). The test now exports the skipped s14, so its split stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e01151a to
a899ec9
Compare
KOLESNiii
left a comment
There was a problem hiding this comment.
Static review of e01151a2 for 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.0 by runtime +0.0 can 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 paths
The 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 4a8217a7 in the measured stack and were checked in e01151a2.
Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
|
merge-check claim |
|
merge-check |
Keeps upstream's DXIL IR cuts (xcl-dev#3500-xcl-dev#3503/xcl-dev#3495-xcl-dev#3499: sampler waterfall, descriptor windows, split-wave64 mask exchange, per-lane exec, direct PS masks, quad shuffles, packed/normalized buffer decode, commit-aware compiles), xcl-dev#3269 fixed-point optimizer, xcl-dev#3154 compact compute prologue, xcl-dev#2123 split atomic add, xcl-dev#2070 offline 64 MB stacks, xcl-dev#3442 split-whole, xcl-dev#1319 root-constant bounds, xcl-dev#3356 late Reset releases, xcl-dev#1322 empty-BVH/NaN rays, xcl-dev#2753 3-D texture sizing, XMA/VFS/TLS/loader fixes. Resolutions: - real.rs: union of T-156 res_release pinning with upstream's InListReset and abi_rs_for_stages; dropped upstream's warm_graphics (T-095 removed that path); kept ComputeBuild::IndirectChain for our split-chain variant. - dispatch_chain.rs: kept our IndirectBuild split-chain architecture (the T-095 port removed the preload/whole-worker machinery upstream builds on); ported upstream's huge-PSO refusal log. - pso_async.rs: took upstream's commit-aware build_pieces/build_scoped and WORKER_STACK, removed the preload/backlog subsystem our port does not have (and its tests), kept our profile_is_series_s. - late_release.rs: took upstream's Dead enum, Busy/InListReset and hold_pipeline/hold_heap/hold_unmap, with our vram release path (no recycle pool). - emit.rs: upstream's additions moved into emit/memory.rs (ADD_TID_ENABLE), emit/exp.rs (misc-vector layer/viewport), emit/mimg.rs (SampleCmp with bias gradients), emit/valu.rs (abs/neg on shift/align), emit.rs out_struct. - bind.rs: root-constant bounds clamp + its test; kept our bool execute_indirect API. - bvh.rs: our grow/tri_ret/watertight model plus upstream's empty-root bounds and NaN-ray refusal. - kernel.rs: upstream's mask/waterfall/rodata cuts plus our lanes_upper. - shaders.rs: upstream's worker stack helpers and mesh/GS precompile paths, with our PipelineJob record identity. - eh.rs: upstream's CLWB TF guard + test, our termination test. - lower.rs test: 574bda4 makes wave32 SALU words compute S_WQM without quad lanes; assert that and keep the wave64 refusal.
…faults own10 skips the alloca/facts/hoist/barrier passes and runs one round by default, so the three tests of those passes saw them skipped and failed on the RTX 3060 Ti suite. A test-only thread-local (WITH_3269) gives those tests xcl-dev#3269's defaults without touching the process environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaZV7vMq866ni7pGnJC2Ew
a899ec9 (xcl-dev#3269) lowered the direct translator's f32 compares (f16 ones go through f32) to one `fcmp` each, without the explicit NaN tests of xcl-dev#46. Three GPU tests fail on an RX 6700 XT (32.0.21045.29003) since then: gpu_f32_compares_with_nan, gpu_float_compares_random and f32_programs_on_the_gpu. They pass on its parent 5b0d5fa. The DXIL is right, the driver is not. It takes `fcmp one` (v_cmp_lg) for `une`, so a NaN operand gives true, and it gives the second of two compares of the same operands that differ only in ordered / unordered (`olt` and `ult`) the first one's result, in either order. Two plain fcmps in a kernel without any wave operation show it: 36 of the 182 ordered pairs of predicates are wrong on that card and 0 on WARP, the same with XCL_DXIL_NO_OPT=all, so no optimizer pass takes part. xcl-dev#46 had found the second form on RDNA3 and an RDNA2 iGPU. Splitting only `lg` into `olt | ogt` leaves 16 pairs wrong and the three tests failing. The explicit tests do not depend on what the driver makes of an fcmp of a NaN. They cost 1.65 % more DXIL over 567 sampled programs of a retail title. The new test reads the predicates from the disassembly, so it fails without an AMD card too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#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(de915b5) 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=4on a899ec9 (rebased onto main 5b0d5fa): 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 Recompiler: fix Direct DXIL live double-ext scan and movrel VGPR range #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