Repository navigation
Conversation
…direct DXIL Extend `gpu::dxil::module::opt` to fold remaining post-phi redundancies in direct-DXIL shaders without colliding with CFG-level folding or violating DXC validator shader-flag invariants: - Enable 64-bit integer constant/identity folding and DCE (`i64` arithmetic, shifts, `LShr(ZExt)` / `LShr(Or(ZExt, Shl(ZExt)))` window-high patterns, `Trunc(ZExt|SExt)`, and `i1` / `ZExt(i1)` compares) and clear `Feature::Int64Ops` in `Shader::infer_type_features` when no surviving instruction uses `i64`. - Fold finite constant `BitCast` (`i32 <-> f32`, `i16 <-> f16`, excluding NaN and Inf in both directions), reuse dominating `BitCast`s from CSE, collapse nested same-condition `Select` chains, and push `BitCast` through `Select` only when the `Select` has no surviving non-bitcast uses (preventing select duplication). - Canonicalize commutative integer binops (`Add`/`Mul`/`And`/`Or`/`Xor`) and integer `Cmp` predicates before dominator CSE, separate `XCL_DXIL_NO_OPT=fold` from `cse`, and expand flag-neutral `ReadNone` intrinsic DCE. - Add validator + RTX 4060 GPU execution parity tests (direct-DXIL cache invalidation is automatic via `XCL_DIRECT_DXIL_SOURCE_ID`). On a 252-program validated direct-DXIL corpus sample (100% across CS/GS/MS/PS/VS): -3.25% DXIL bytes (-397 KB, 252/252 shrank), -6.33% instructions, -28.74% bitcasts, -2.30% selects, -38.32% i64 ops, 0 validator errors (and 0 errors across 977 programs in a 1,000-record sample). Assisted-by: Google Antigravity (Gemini 4 Neon)
The direct translator writes a VGPR under EXEC as select(exec, new, old). A lane-local instruction under the same EXEC that reads the register, and whose own result is selected by that EXEC again, never observes the old arm. optimize() now tracks where each value is observed (unused, only where one condition holds, all lanes) and reads through such selects; DCE then drops the selects left without uses. Phis, memory, wave ops, derivatives and integer division observe all lanes. XCL_DXIL_NO_OPT=select leaves the pass out. Tests turn it off per thread; the translator thread takes the caller's setting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The select fold reads through select(exec, bitcast(f), old) to the bitcast, so a float operation that read the register through bitcast(select) now reads bitcast(bitcast(f)). The CSE peephole that folds such pairs ran before the fold, so they stayed (6,305 in one program of 110 k instructions). A linear pass after the fold maps bitcast(bitcast(x)) back to x when the types match (64-bit kept, as in the peephole); DCE drops the casts left without uses. Measured on the 802 programs in use at the crash (bound DXIL bytes): 239.44 MiB on main, 219.95 with the select fold, 212.88 with this. XCL_DXIL_NO_OPT=pairs leaves the pass out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent NVIDIA GPU check of Tested
Not tested: AMD or native hardware wave64, production title smoke, native driver blob size, memory use, or world-load time. AI use: Codex (GPT-6.2 Sol) reviewed the test setup, ran these commands, and drafted this report. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! — Devin |
|
RX 6800M focused GPU report for #2576: both new select/bitcast fold parity fixtures passed on the exact PR head. Setup: clean detached head Tested: Both fixtures compare folded and unfolded GPU results across all tested lanes/registers. The source always runs wave32 whole and split-wave64 forms, and conditionally runs native wave64 when Not tested: full workspace suite, title smoke pair, other GPU vendors, or a measured native-wave64-only run. No game files were used. AI use: Codex (GPT-6) and a Codex Luna subagent prepared the clean worktree, ran the focused tests, checked the counts and source-level form coverage, and wrote this report. |
|
AMD Windows driver timing for #2576 (the last two commits, on top of #1906): on the RX 9070 XT the EXEC-select fold cuts direct DXIL by 7.6 % over all 2,689 retail compute programs, and AMD's Setup
DXIL size, all 2,689 compute programs (translation only)
Driver time, 26 large programs, 3 interleaved rounds
Mean 80.5 → 76.0 s (−5.7 %). The PR was faster in every round, but by 1 % in the first, so read it as a modest gain. Per program, the larger ones gain the most; small ones move in both directions, within noise:
With the fold, the six split programs produce 47 pieces instead of 55. Not tested: heap windows, GPU output, and a title run. AI use: Claude Code (Claude Opus 5.5) built the binaries, ran the measurements and wrote this report; I posted it. |
|
Test report for Tested
Not tested: the suite, this PR's GPU tests or any correctness arm with these passes on; timing (build or dispatch); a title run; graphics; other GPUs. AI use: Claude Code. Claude Opus 5.5 wrote the size test, ran it and wrote this; Claude Fable 5.2 rechecked it. |
Stacked on #1906: review only the last two commits; this rebases onto main when #1906 lands.
The direct RDNA2 → DXIL translator writes a VGPR under EXEC as
select(exec, new, old). Two passes inModule::optimizeshrink the DXIL handed to the driver. Part of #1096.old. The pass tracks, per value, where it is observed (unused, only where one condition holds, all lanes) and reads through those selects; DCE drops the selects left without uses. Phis, memory, wave ops, derivatives and integer division observe all lanes and keep their selects.select(exec, bitcast(f), old)turns a float operation'sbitcast(select)operand intobitcast(bitcast(f)). The CSE peephole that folds such pairs runs before the select fold, so a linear pass after it mapsbitcast(bitcast(x))back toxwhen the types match (64-bit kept, as in the peephole).#1972 (@raylitebull) had the select-guard idea first (
propagate_select_guards). The fold here tracks observation per value and reaches more selects: on the bench below it saves 8.1 % of the bytes on main against 4.1 % for #1972, and #1972 adds 0.5 % on top of it. Our offer on #1972 (#1972 (comment)) to combine the two still stands. This PR came out of @Decodere's suggestion on #1906 to keep these passes separate from it.What is in it
Recompiler: fold direct DXIL EXEC selects no lane observes:fold_guarded_selectsandlane_localincrates/xcl/src/gpu/dxil/module/opt.rs, run after CSE (XCL_DXIL_NO_OPT=selectleaves it out);NO_SELECT_FOLD(tests only), handed to the translator thread inkernel.rs; unit testguarded_selects_fold_where_no_lane_sees_the_other_arm; GPU testgpu_select_fold_keeps_inactive_lanesincrates/xcl/src/gpu/dxil/select_tests.rs.Recompiler: fold the bitcast pairs the EXEC select fold leaves:fold_bitcast_pairsinmodule/opt.rs(XCL_DXIL_NO_OPT=pairs);NO_PAIR_FOLD(tests only); unit testbitcast_pairs_left_by_the_select_fold_fold(fails with the pass left out); GPU testgpu_bitcast_pair_fold_keeps_words.v_readlaneand DPP reads while lanes are off, NaN (quiet and signalling payloads), signed-zero, infinity and denormal operands, and sentinels in lanes that never run. They run in wave32 and wave64, whole and split, and the folded form must be smaller.Tested
Size, offline (no GPU): a release
xcl.exetranslates and binds the 802 compute programs that a retail title (title: ea3b5e4d) has in use at its device-memory crash.6d12f58a894e29d6That is −10.6 % bytes and −12.8 % instructions on top of Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906.
Native code on the NVIDIA driver, RTX 5070 Ti, measured on main with and without the select fold: 4 of the largest of these programs go from 3.60 to 3.40 MB of driver blob (−5.4 %). The bitcast-pair fold changes only the DXIL: on a synthetic chain of 512
v_mul_legacy_f32the driver's code is the same with and without it.Graphics, measured on main by our graphics size bench (runtime path,
XCL_DIRECT_DXIL=all): VS DXIL 30.41 → 26.73 MiB (−12.1 %), PS of the cold pipelines 104.41 → 94.73 MiB (−9.3 %), 0 failed translations.GPU tests at
71b76742, on an RTX 2060 (NVIDIA 595.91) under Wine 11.21 + vkd3d-proton master30b0eb9, DXC 1.9.2609, release test executables:select_tests module::opt: 11 passed, 0 failed, 0 ignored, no SKIPPED (maine1d84b7d: 7 / 0 / 0). Both new GPU tests ran on the GPU and passed.gpu::dxil --test-threads=4: 186 passed, 2 failed, 3 ignored (maine1d84b7d: 181 / 2 / 3). The same two tests fail on main on that stack:raw_loads_in_root_windows_respect_exec_and_bounds(memory-window gap of that Wine build) anddirected_reference_basics(fma precision under vkd3d). SKIPPED:dispatch_chain_native_wave64_builds_whole(no wave64).Whole suite at
71b76742on an RTX 5070 Ti (NVIDIA 610.74), Windows 11 Pro 26200, rustc 1.99.0, DXC 1.9.2609, debug:cargo test --workspace --no-fail-fast -- --test-threads=4: 1,428 passed, 0 failed, 46 ignored. 25 SKIPPED notices, none from the new tests: 21no wave64, 3 forms refused inf16_programs_on_the_gpu/f32_programs_on_the_gpu(gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics), 1no heap windows. Thenselect_tests --nocapture: both new GPU tests ran and passed.Output of a retail compute program (title: ea3b5e4d, program
6f3a2502a8d6b129) on the GPU, RTX 5070 Ti, native Windows D3D12, one seeded 8×16 group, guest wave64 split on wave32, full buffer and texture readback: main6d12f58a, main + the select fold, and main + both passes each change 2,048 words, 0 different from main, and match the expected 256/256 texels; two repeated main controls also match. DXIL 477,884 → 454,064 → 437,536 bytes. The pass code is this head's, except thatsimplify_optakes Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906's extra argument.Tested by others
71b7674on an RTX 3080 Ti (NVIDIA 621.35), Windows 11 26300, rustc 1.99.1, DXC 1.8.2502.11, debug.gpu_select_fold_keeps_inactive_laneswithXCL_DXIL_NO_OPT=pairs(the select fold on its own): 1 passed.gpu_bitcast_pair_fold_keeps_words: 1 passed.cargo test --workspace --no-fail-fast -- --test-threads=4: 1,428 passed, 0 failed, 46 ignored, 25 SKIPPED notices; both new GPU tests ran without a skip.cargo test -p xcl --lib: all passed, 0 failed, 26 ignored (no commit or pass count given).71b76742on an AMD Radeon RX 6800M (driver 30.0.13002.13003), Windows 11 26200, Rust 1.99.0, DXC 1.9.2609.5, debug,XCL_DIRECT_DXIL=1 XCL_REQUIRE_GPU=wave64:gpu_select_fold_keeps_inactive_lanes1 passed,gpu_bitcast_pair_fold_keeps_words1 passed, no SKIPPED line. The log does not show whether the native wave64 form ran.71b7674against Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906894e29d, both merged onto main08db802, on an AMD RX 9070 XT (driver 32.0.32029.2010), Windows 11, release, offlinexcl shaders --precompile --only cs --pipelineswith every build cold. Direct DXIL over all 2,689 retail compute programs: 875.1 → 808.7 MB (−7.6 % against Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906).CreateComputePipelineStateover 26 large programs, 3 interleaved rounds: mean 80.5 → 76.0 s (−5.7 %), 0 failed pipelines; faster in every round, but by 1 % in the first, which they read as a modest gain. The six split programs give 47 pieces instead of 55. Not covered by that run: heap windows, GPU output, a title run.GetCachedBlob) on an RTX 3060 (NVIDIA 617.14), Windows 11, debug, one run. Their tree is71b76742with Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906894e29d6, on mainb49be183with Recompiler: direct DXIL reads heap memory windows without a branch #2427, Recompiler: NVIDIA compute programs take flat heap windows by default #2428, Recompiler: an access may take its base address's window (XCL_WINDOW_NO_CARRY) #2496 and Recompiler: share scalar-load bodies in direct DXIL compute shaders #2567. 60 compute programs of one retail title, one pipeline each (XCL_DIRECT_SPLIT_INSTRUCTIONS=0), withXCL_DIRECT_DXIL=1,XCL_WINDOW_NO_CARRY=1,XCL_DXIL_OUTLINE=1, flat heap windows and translated caches off. The two passes,XCL_DXIL_NO_OPT=selectagainst unset in the same build: driver code 32.863 → 30.536 MB (−7.1 %; 54 programs smaller, 3 the same, 3 larger), DXIL 24.170 → 21.196 MB (−12.3 %), all 120 containers pass both validators, 60/60 pipelines built per arm. Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906's own folds come to about 0 there (−0.04 %, from two builds). Not covered by that run: the pair fold on its own, the suite or any correctness check with the passes on, timing, a title run, graphics.Regression run
Title smoke pair, 60 s each, RTX 5070 Ti, NVIDIA 610.74, release builds. The base side is Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906's head
894e29d6, the base of this stacked PR, not main. It ran after one warm-up run of the base and back to back with it, as one job beside a CPU-bound shader precompile on the same machine that was running at both ends of both sides. Frames 1,291 against 1,318 (98 %), peak commit 26,833 against 26,885 MB, no crash or device removal.Base, Recompiler: fold 64-bit ints, bitcast selects and commutative CSE in direct DXIL #1906's head
894e29d6:This head,
71b76742:Not tested
AI use
🤖 Generated with Claude Code