Repository navigation
Recompiler: compact form splits out repeated memory ops and dead SGPR stores - #3261
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>
|
merge-check |
|
merge-check base: 0fe06eb head: 16f2f5c merge: clean. The trial merge includes #3250 (e13ccd7), the PR head’s parent. No later stack slices were added. build: tests:
review: Read the compact-form changes and the stacked bitcode prerequisite. The GPU failure occurs at the compact output assertion, before the comparison against the plain path. The isolated runs report 401 blocks of 4 kinds. The cause of the missing SGPR 1 accumulation is unconfirmed. performance: 60-second
These are startup smoke results. Gameplay and visual parity were not checked. The cold PSO check with verdict: not yet: the new compact-form GPU test returns the wrong scalar accumulator on RX 7800 XT in both native and forced split wave64. hardware / tool and model: Radeon RX 7800 XT (32.0.32029.2010), Ryzen 7 5700X3D, Windows 11 Home build 26300, Rust 1.100.0 x86_64-pc-windows-msvc, DXC 1.9.2602.17. Codex (GPT-6, exact variant unavailable) verified refs, inspected the diffs, ran the build, tests and smokes, and drafted this report. Reviewed by the posting user before submission. |
KOLESNiii
left a comment
There was a problem hiding this comment.
Static review of 16f2f5c1 for the stack in the #3041 comparison.
Wave32 liveness can drop a live SGPR store. inst_sreg_scc_use_def treats the destination of S_AND_SAVEEXEC_B64 s[4:5], ??? as a two-register definition. Wave32 lowering writes only s4. If one compact block writes s5 and its successor reads s5 after the save, liveness can drop the first block's store and the successor then reads stale data. A wave32 compact/plain comparison with that cross-block dependency would cover the case.
Plan::words() also omits the new PC and literal tables, so the 32,768-word limit can admit a larger plan.
Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
|
Thanks for the RX 7800 XT run. It caught a real bug that NVIDIA can't show. I reproduced it on an RDNA2 iGPU: the compact form read every parameterized literal as 0. The cause is the two-word read of the literal's pool index, which AMD's driver gets wrong when the result indexes the next table. The same DXIL is right on NVIDIA. This PR was merged before the fix, so the fix is #3473. A rerun of (Claude Code, Claude Opus 5.5, for Foniass) |
|
@Prime1997 @Foniass: a regression on What happens. The title's largest compute program, The same tree with only
Why it was easy to miss. The program builds fine ("5 made, 0 refused"), and it only runs once the world is drawn, which the 60-second smoke run doesn't reach on this title. A suggestion for translator changes. A change in It may also help if translator changes come from, or are checked by, someone who can load the world themselves. Meanwhile we run AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash. |
|
A correction to the scope of my comment above: this removal looks specific to RTX 50-series cards, not NVIDIA in general. throny ran So the same compact program runs on Ada and never finishes on Blackwell, which may help find the fault (a difference in how the two driver generations compile it). The revert / #3516 results above are unchanged; they just apply to RTX 50-series cards. AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash. |
The compact form (xcl-dev#3261) gives each block of a parameterized class its literal through two tables: a bit-packed index per block (xcl_lit_idx) and the pool of distinct literals (xcl_lit_pool). An index could straddle two words of xcl_lit_idx and was read with a two-word funnel extraction. AMD's driver (an RX 7800 XT, 32.0.32029, and a Ryzen 7800X3D's RDNA2 iGPU, 32.0.21030) gets the pool index wrong from that extraction: gpu_compact_form_with_micro_blocks_and_literal_table_runs_ as_the_plain_form read 0 for every literal (s1 = 0 instead of 10045), in native and split wave64. The same DXIL runs correctly on NVIDIA, and the index is right when used as a value; only its use as the next table's index goes wrong (with a clamp, it read the last pool entry). The index width is now a power of two, so an index never straddles two words and the lookup reads one word. The table grows at most 2x (an 8-bit index stays 8 bits; 9 bits take 16). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compact form (xcl-dev#3261) gives each block of a parameterized class its literal through two tables: a bit-packed index per block (xcl_lit_idx) and the pool of distinct literals (xcl_lit_pool). An index could straddle two words of xcl_lit_idx and was read with a two-word funnel extraction. AMD's driver (an RX 7800 XT, 32.0.32029, and a Ryzen 7800X3D's RDNA2 iGPU, 32.0.21030) gets the pool index wrong from that extraction: gpu_compact_form_with_micro_blocks_and_literal_table_runs_ as_the_plain_form read 0 for every literal (s1 = 0 instead of 10045), in native and split wave64. The same DXIL runs correctly on NVIDIA, and the index is right when used as a value; only its use as the next table's index goes wrong (with a clamp, it read the last pool entry). The index width is now a power of two, so an index never straddles two words and the lookup reads one word. The table grows at most 2x (an 8-bit index stays 8 bits; 9 bits take 16). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 12d4f35)
…2,288 words take the plain form xcl-dev#3261 raised the most table words a program may need to take the compact form from 12,288 to 32,768. On the retail title one program then takes it whose tables need 16,121 words (19,840 blocks of 1,471 kinds, record 95cc13288a27a96e); on RTX 50-series cards its Dispatch never finishes and the device is removed at the first world frame (DRED: the Dispatch after that program). With the limit at 12,288 the program takes the plain form and runs (BBareth, xcl-dev#505). The limit goes back to 12,288 on NVIDIA adapters only. On AMD the plain form of that program is the costly one (an RX 7900 XT report on xcl-dev#505: a driver compile of minutes refused with E_OUTOFMEMORY), so other adapters keep 32,768. The vendor is that of the main adapter, noted where the title's device and the launch preparation's are made, so both pick the same limit and the same cache identity. XCL_COMPACT_TABLE_WORDS sets the limit on any adapter (1 to 32,768); a limit other than 32,768 goes into the translated cache identity with the nesting tag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…2,288 words take the plain form xcl-dev#3261 raised the most table words a program may need to take the compact form from 12,288 to 32,768. On the retail title one program then takes it whose tables need 16,121 words (19,840 blocks of 1,471 kinds, record 95cc13288a27a96e); on RTX 50-series cards its Dispatch never finishes and the device is removed at the first world frame (DRED: the Dispatch after that program). With the limit at 12,288 the program takes the plain form and runs (BBareth, xcl-dev#505). The limit goes back to 12,288 on NVIDIA adapters only. On AMD the plain form of that program is the costly one (an RX 7900 XT report on xcl-dev#505: a driver compile of minutes refused with E_OUTOFMEMORY), so other adapters keep 32,768. The vendor is that of the main adapter, noted where the title's device and the launch preparation's are made, so both pick the same limit and the same cache identity. XCL_COMPACT_TABLE_WORDS sets the limit on any adapter (1 to 32,768); a limit other than 32,768 goes into the translated cache identity with the nesting tag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Checked: xcl-dev#3516, including Foniass merge-check 7305483219 (cache identity is requested before device creation).
Stacked on #3250; only the top commit (
16f2f5c1) belongs here.Second part of moving amd-dev's direct DXIL size work (
f089a9df) to main: the compact form's micro-blocks and SGPR liveness. This is where the NVIDIA driver's compile time goes down. On large programs (64 blocks or more), a memory instruction that occurs more than once becomes its own micro-block and is lowered once. Blocks that differ only in one literal ors_getpc_b64position share a class. Successors can come from a target pool. A backward SGPR/SCC liveness drops stores of registers no later block reads, and strips dead far-jump veneers.What is in it
crates/xcl/src/gpu/dxil/compact.rs: micro-blocks, no-op stripping and empty-block bypass, literal / block-PC tables,NextEnc::TargetPool, table limit 12288 to 32768 words, liveness (inst_sreg_scc_use_def,compute_live_out, far-jump veneer stripping, per-class store elision)crates/xcl/src/gpu/dxil/lower.rs,kernel.rs:compact_lit/compact_blk_pcfor the parameterized literal ands_getpc_b6433d1222d(open as DXIL: fix compact SGPR liveness for RMW/CMOV SALU and Wave32 masks #2604, which cannot land on main without this code):s_cmov*/s_addk/s_mulk/s_bitset*read their destination, wave32 VALU mask writes define one SGPRS1set are SGPR uses (the port only handledS0), so an SGPR read through SDWAVSRC1no longer has its store dropped. Test:sdwa_sgpr_sources_are_uses(fails without the fix)repeated_loads_split_into_micro_blocks_and_literals_into_a_tableandgpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form(a 200-copy program with a repeateds_load, a per-copy literal and early outs; compact against plain on the GPU)Why one commit, and why over 800 lines
On an RTX 5070 Ti, the micro-blocks without the liveness make the retail title's largest compute program (
95cc13288a27a96e) a pipeline the NVIDIA driver refuses withE_OUTOFMEMORY. With the liveness it builds. So the two halves can't be separate PRs or separate commits without a broken state in between. Of the 890 changed lines, about 200 are tests.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on 16f2f5c: 2607 passed, 6 failed, 49 ignoredgpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3:E_OUTOFMEMORYfromCreateComputePipelineStateon this card, the same on main. They pass on Kalmarv's RTX 5070 Ti, so they come from this machine's driver / setup, not the code.test_title_runs_and_game_folder_is_untouchedandincomplete_discovered_corpus_blocks_headless_title_entry, because the test title was not built in that worktree; aftercargo build --workspace,cargo test -p xcl --test e2e: 5 passed, 0 failedno wave64; alsotwo_pass_binds_set_the_shared_view_heap(no heap windows) andpso_measurement_compiles_an_exact_synthetic_record(cannot disable the driver cache); the new GPU compact test ranxcl shaders --direct --sample 0 --max-bytes 0) with Recompiler: encode direct DXIL with bitcode abbreviations #3250 and with this PR: 16307 programs, 5 change (only large ones take the micro-block form):95cc13288a27a96e: 784 KB to 251 KB56c0cd3b82a00c6e: 449 KB to 291 KB958400d2caf07244: 405 KB to 253 KB--precompile --only cs --pipelines --records <the 5>): 5 made, 0 refusedRegression run
The PR's run used
-StartupTimeoutSeconds 3600: new DXIL means the title's shader preparation rebuilds its pipelines before the timed minute.main:
this PR:
Not tested
AI use
f089a9df, merged in33d1222d, found and fixed the SDWAS1gap, wrote the new tests, found the A-without-B refusal on NVIDIA, ran the tests, measurements and smoke runs above, wrote this descriptionf089a9df(raylitebull, from46aecbf7, written with Antigravity (Gemini 4 Neon High)) and33d1222d(Alp Pesen, Antigravity (Gemini 4 Neon))🤖 Generated with Claude Code