Repository navigation
Recompiler: compact form also for branch-heavy programs of 2000+ blocks - #3263
Conversation
The direct DXIL writer emitted every record unabbreviated, so each operand took a full 6-bit VBR chunk plus the record header. Define LLVM DEFINE_ABBREV records for the hot function-block opcodes (binop without flags, cast, cmp2, vselect, extractval, 4-byte-aligned load / store, br, call, phi, gep) and for integer / f32 constants, and write the compact form's lookup tables as one CST_CODE_DATA record instead of an aggregate of interned integer constants. The records decode to the same operands, so the module means the same; only its encoding is smaller. Measured on the retail title with an RTX 5070 Ti (numbers in the PR). Ported from the bitcode-encoding part of amd-dev's f089a9d (cherry picked there from 46aecbf, raylitebull, Assisted-by: Antigravity (Gemini 4 Neon High)). Left out here: its dead-constant pruning (main already prunes, 09a65d6) and its IR / compact-form changes, which follow separately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… stores The compact form lowers each class of identical blocks once, but a block only joins a class when everything in it matches, and every class stores all SGPRs and SCC it wrote back to their slots. In large console programs the same buffer / SMEM / image access sits in many blocks with different ALU around it, so its long lowering was emitted once per block. On large programs (64 blocks or more): - a memory instruction that occurs more than once becomes a micro-block of its own, lowered once for all its occurrences; pure no-ops (s_nop, s_waitcnt*, s_clause, ...) are left out, and the empty jump blocks that leaves are bypassed; - blocks that differ only in one 32-bit literal, or only in where an s_getpc_b64 sits, share a class and read the literal / block PC from a packed table, when that saves at least 64 classes; - the successor field can index a pool of distinct taken targets (fallthrough = 0) when that is smaller than inline block numbers or offset pairs; the table limit rises from 12288 to 32768 words; - a backward liveness over s0..s105 and SCC gives each class the union of its blocks' live-out sets, and a class stores only what is live; the same liveness strips far-jump veneers (s_getpc_b64 + s_add_u32 + s_addc_u32 feeding a resolved s_setpc_b64) whose registers and SCC are dead at the target. Kernel-mode programs (the tests' ABI) keep every register live at the end. The use / def sets are conservative: s_movrel* reads every SGPR, conditional and read-modify-write SALU (s_cmov*, s_addk, s_mulk, s_bitset*) read their destination and s_cmov* does not kill it, and a wave32 VALU mask write defines only its low SGPR (from 33d1222, open as xcl-dev#2604). New here: SDWA sources with their S0 / S1 bit set are SGPR uses, as Lw::sources reads them; the ported code missed S1, so a v_add_nc_u32 sdwa reading s20 through VSRC1 left s20 dead and its store out. The micro-blocks and the liveness are one commit: on an RTX 5070 Ti the micro-blocks alone make the retail title's largest compute program (95cc13288a27a96e) one the driver refuses (E_OUTOFMEMORY); with the liveness it builds, and goes from 804 KB to 258 KB of DXIL. Ported from the compact-form and liveness parts of amd-dev's f089a9d (raylitebull, cherry-picked there from 46aecbf, Assisted-by: Antigravity (Gemini 4 Neon High)) and 33d1222 (Alp Pesen, Assisted-by: Antigravity (Gemini 4 Neon)). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compact::large() previously only checked reachable non-terminator instruction count (>= 20_000), ignoring both terminating branches and basic-block count. Branch-heavy unrolled compute shaders just below 20k non-terminator instructions (for example, cs 56c0cd3b82a00c6e) skipped compact lowering and emitted >2.6 MiB monolithic DXIL (~588k IR lines, ~32k blocks, ~36k PHIs), causing the driver compiler to commit >36 GiB of virtual memory and stall compilation. In compact form the same shader shrinks to ~160 KiB (~975 blocks, 108 PHIs). Lower the non-terminator threshold to 10_000 and add a reachable basic-block threshold (>= 2_000) in compact::large(); compact::wanted() still gates adoption on >70% deduplication and bounded table size. (cherry picked from commit 5399542) Port onto nvidia-dev: `large` is asked by automatic_plan here (this branch's form of `wanted`); its doc says so instead. (cherry picked from commit 9887b41) Ported to main (subject in the repo style). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
merge-check |
|
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) |
|
merge-check claim |
|
merge-check
|
|
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, #3250 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. |
KOLESNiii
left a comment
There was a problem hiding this comment.
Static review of e618b742 for the stack in the #3041 comparison.
The threshold change itself looks consistent with the tested intent. It makes more wave32 shaders eligible for compaction and therefore exposes an inherited correctness issue I found in #3261. The compact liveness pass can drop a live high SGPR store across a SAVEEXEC_B64 instruction because wave32 lowering writes only the low destination. This is new review evidence for the stack carried by this PR.
Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
|
Thanks for the review. Your 4 points are now handled in follow-ups, since this was merged:
Separately, the AMD iGPU also showed that the literal table read 0 on AMD (moombathepilot's #3261 finding). That fix is #3473. (Claude Code, Claude Opus 5.5, for Foniass) |
Takes the upstream sync after 5b0d5fa. Headline changes: - 8c9e83f/e618b742/16f2f5c1 (xcl-dev#3263): compact DXIL form for branch-heavy programs of 2000+ blocks, splitting repeated memory ops and dead SGPR stores; compact block PC/literal plumbing in lower.rs and kernel.rs. - 45dbd47 (xcl-dev#2341): per-lane compute size caps (MAX_INSTS 20,000, MAX_DXIL_BYTES 1 MiB) so giant compute programs fall back to compact. - a7f059b (xcl-dev#2148): SSA trivial-phi/0-pred-phi fixes; 1933324 (xcl-dev#2060): reject image_gather4h/8h instead of a 2x2 Gather; 0738c30 (xcl-dev#2369): dedupe concurrent stand-in creation and harden shell COM; e9d7aef (xcl-dev#2398): saturate 16-bit integer valu16 with CLAMP=1; 6376287 (xcl-dev#1878) dxbc digest rounds. Conflict resolutions: | file | resolution | | --- | --- | | gpu/dxil/lower_wide.rs | took upstream's 32-bit exact CLAMP lowering for the 16-bit integer adds/subs/mads and deleted our T-021 64-bit signed duplicate; kept our v_mul_lo_u16 CLAMP arm (upstream does not cover it) and all our T-124 wave64/OMOD changes; removed the now-unused sat_i16 helper from prelude.rs | | gpu/recomp/lower_dxil.rs | took upstream's MAX_INSTS/MAX_DXIL_BYTES cap and its size check; kept our marks thread-local propagation (marks::enabled / set_thread) in the per-lane thread | | gpu/dxil/core_tests.rs | not a merge conflict, but the direct CLAMP test asserted the removed lowering: now expects 3x icmp sgt/slt i32 for valu16, no IMax/IMin, and 3x icmp sgt/slt i64 for the wide signed mads | | hle/d3d12x/standin.rs | auto-merged upstream's concurrent dedupe and COM hardening; kept our mainline's immediate unref in Drop (our late_release exposes hold(), not hold_pipeline()) and upstream's new tests | | compact.rs, compact_tests.rs, recomp/ssa.rs, lower_image.rs, kernel.rs, lower.rs | upstream's changes; lower_image keeps our watertight ray/triangle alongside upstream's gather4h/8h rejection | Build (only possible target for this crate; native Linux fails on testgame-mw's raw-dylib and retour's stdcall): cargo build --release --workspace --locked --target x86_64-pc-windows-gnu Finished in 55.12s; 47.01s incremental after the dead-helper removal. Focused lib tests (Windows test binary under Wine, builtin DXGI, no GPU): gpu::dxil: 309 passed; 0 failed; 3 ignored; 80 SKIPPED gpu::recomp: 548 passed; 0 failed; 20 ignored; 320 SKIPPED hle::d3d12x::standin: 6 passed; 0 failed; 1 SKIPPED (no GPU or WARP) Direct sweep (xcl.exe under Wine, --sample 0 --threads 8): CS 1636/1636 GS 195/390 MS 8724/8724 PS 9511/9511 VS 2184/2184 total 22250/22445; the 195 unsupported are split-wave64 geometry (ES phase exchanges at group barriers). xcl-dev#2060 moved nothing here: the corpus has no image_gather4h/8h program in the direct set. coverage_gate.py --run-json --skip-recomp: "coverage gate: no regressions" (exit 0); baseline stays 22250/22445. Upstream commits keep their authors; this merge commit only records the resolutions.
Follow-ups to the compact form's review on xcl-dev#3263 (KOLESNiii): - Plan::words(), which the table limit is checked against, now counts the block-PC table and the literal index and pool tables, so a program can no longer take the form with more table words than MAX_TABLE_WORDS. A plan with a PC table and no block literal no longer emits empty literal tables. - The block-PC table gets the literal index table's fix: entries of a power-of-two width, read from one word (entry_bits). The two-word read is what AMD's driver got wrong for the literal index; the PC values themselves read right on AMD in the new test, so this one is for consistency, not a seen failure. - The comments said repeated memory ops split out at >= 4 occurrences; the code does it at >= 2. - Tests for code that had none: a GPU run of blocks that share a class through the PC table, dead far-jump veneers left out (all of them in a compute program, all but the last in the kernel form) and a GPU run of that kernel form against the plain one, and words() against the table sizes in the DXIL. On the retail title nothing changes: none of its 768 compute programs that reach the compact plan has a literal or PC table. One of them has a 16121-word plan (19840 blocks), over main's former 12288-word limit and under the 32768 one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow-ups to the compact form's review on xcl-dev#3263 (KOLESNiii): - Plan::words(), which the table limit is checked against, now counts the block-PC table and the literal index and pool tables, so a program can no longer take the form with more table words than MAX_TABLE_WORDS. A plan with a PC table and no block literal no longer emits empty literal tables. - The block-PC table gets the literal index table's fix: entries of a power-of-two width, read from one word (entry_bits). The two-word read is what AMD's driver got wrong for the literal index; the PC values themselves read right on AMD in the new test, so this one is for consistency, not a seen failure. - The comments said repeated memory ops split out at >= 4 occurrences; the code does it at >= 2. - Tests for code that had none: a GPU run of blocks that share a class through the PC table, dead far-jump veneers left out (all of them in a compute program, all but the last in the kernel form) and a GPU run of that kernel form against the plain one, and words() against the table sizes in the DXIL. On the retail title nothing changes: none of its 768 compute programs that reach the compact plan has a literal or PC table. One of them has a 16121-word plan (19840 blocks), over main's former 12288-word limit and under the 32768 one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 8d1bc67)
Note: the suite and smoke results below replace an earlier set that, by a test-setup mistake (shared cargo target directory), came from another PR's build. These were run with a forced rebuild of this head.
Stacked on #3261 (which is stacked on #3250); only the top commit (
e618b742) belongs here.amd-dev's
9887b414(Saksukella):compact::large()asked only for 20,000+ reachable non-terminator instructions, so branch-heavy unrolled compute programs just under that (e.g.56c0cd3b82a00c6e, about 32k blocks) stayed in the plain form and produced 2.6 MiB of DXIL. The NVIDIA / AMD driver then committed tens of GB to compile it. The threshold becomes 10,000 instructions or 2,000 reachable blocks;automatic_planstill asks for the repetition and the table limit before it takes the form.What is in it
crates/xcl/src/gpu/dxil/compact.rs:LARGE_INSTS = 10_000,LARGE_BLOCKS = 2_000inlarge()crates/xcl/src/gpu/dxil/compact_tests.rs:a_large_program_that_repeats_itself_takes_the_compact_formchecks 2500 / 500 copies (compact) and 400 (plain)Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on e618b74: 2609 passed, 4 failed, 49 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3:E_OUTOFMEMORYfromCreateComputePipelineStateat seeds 70 / 545 / 1019 / 1507, the same as on main on this machine; they pass on Kalmarv's RTX 5070 Ti, so they come from this machine's driver / setup, not the code. SKIPPED GPU tests: 30, almost allno wave64.-StartupTimeoutSeconds 3600for the cold pipeline rebuild new DXIL needs.Regression run
main:
this PR:
Not tested
AI use
9887b414(Saksukella, cherry-picked there from53995420); the subject is reworded to the repo's style.🤖 Generated with Claude Code