Repository navigation
Recompiler: direct DXIL emits a repeated scalar load once - #2207
Conversation
The console's compiler reloads a descriptor from its table before each use. To the direct translator every load is a value of its own, so what is derived from a descriptor is derived again per load. A retail title's CS_ScreenProbes_ActivateRays (333 596 B of code, 76 699 instructions) loads one buffer descriptor 2 399 times from one table slot; 1 888 of its 1 889 buffer_load_format_x read that buffer, and the decode of its format (183 IR instructions per load before the optimizer) was 57 % of the module. gpu::dxil::reload is an available-expressions analysis over the CFG: an s_load_dword* (no GLC / DLC) is a repeat where the same load has run on every path and since then no instruction wrote the SGPRs of its address or any memory, and there was no s_barrier. A repeat is not emitted: its registers get the earlier values through SSA variables, and the format caches keyed on the descriptor hit. Compute programs and kernels only, in the plain form (the compact form shares a block's code between blocks, where what is available differs). ActivateRays, 4 windows as a switch: 3 916 120 -> 2 414 940 B of DXIL. Two ray-tracing resolve programs: 965 748 -> 911 716 B and 1 025 520 -> 967 588 B. All 26 696 programs of the title's pack translate and validate. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
NVIDIA with 32-lane waves (listed as untested), plus the RX 9070 XT, paired against Head
Per-test comparison: on both cards the only differences are the 6 new Not tested: a title with |
|
AMD Windows driver data for #2207: on the RX 9070 XT, the programs it changes build 4–10 % faster in AMD's Setup
Method
26 programs (means of 2 rounds; all 104 builds succeeded, 0 refused)
The changed programs:
ActivateRays (
The repeated-descriptor decode is a large share of this program, as your description says for the biggest one. Removing it doesn't change how fast the AMD compiler's memory grows on it. Tests on this card (
Read / inference
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the measurements and tests and drafted this. The account owner is away; counts and timings only, no game data. |
Brings main to full parity with upstream/main (cdb0891), including: - World rendering & gameplay: xcl-dev#1991, xcl-dev#1988, xcl-dev#1984, xcl-dev#2028, xcl-dev#2078 - Memory / VRAM / PSO: xcl-dev#1985, xcl-dev#2157, xcl-dev#2178, xcl-dev#2195, xcl-dev#2176, xcl-dev#1996, xcl-dev#1914 - Direct DXIL & shaders: xcl-dev#2120, xcl-dev#2174, xcl-dev#2194, xcl-dev#2207, xcl-dev#1951, xcl-dev#1973, xcl-dev#2156, xcl-dev#2064 - Preserves local Linux/Wine customizations: docs/linux.md, scripts/linux/*, in-process Wine XAsync (xgameruntime/api.rs), loader watchdog bypass, and Wine MEM_WRITE_WATCH bypass on coherent UMA windows (gpu/uma.rs). Assisted-by: Antigravity (Gemini 4)
The console's compiler reloads a descriptor from its table before each use, wherever its registers were needed for something else meanwhile. To the direct translator each
s_load_dword*is a value of its own, so everything derived from the descriptor is derived again per load. In a retail title's biggest compute program (333 596 B of code), one buffer descriptor is loaded 2 399 times from one table slot, and the decode of its typed-buffer format, done again for each of the 1 889buffer_load_format_x, was 57 % of the module. With this change a load the program repeats is not emitted: its registers keep the first load's values, and the format caches keyed on the descriptor (Lw::fmt_desc_cache) hit. Part of #505 and #1269 (driver compile time of the huge compute programs).What is in it
crates/xcl/src/gpu/dxil/reload.rs(new): an available-expressions analysis over the CFG. Ans_load_dword*without GLC / DLC is a repeat where the same load (same base and offset registers, offset, size) has run on every path, and since then no instruction wrote the SGPRs of its address or any memory, and there was nos_barrier. What may write registers is read from the encoding and taken wider where it is not plain (s_movrel*,s_setregand unknown operand types: all registers). A program withs_call_b64is left alone. Each load gets a slot of SSA variables (VAR_RELOAD).crates/xcl/src/gpu/dxil/kernel.rs,lower.rs,lower_mem.rs,mod.rs: compute programs and kernels in the plain form only (the compact form of Recompiler: direct DXIL lowers a repeating compute program's blocks once #2034 emits one block's code for blocks where what is available differs; graphics stages enter their code by edges the CFG does not hold). A first load stores its registers to its slot; a repeat reads them back instead of loading.reload.rs: the analysis (a repeat after a straight line; ended by a write to the base or offset register, a 64-bit write reaching it,v_readfirstlaneinto it, a store, a buffer atomic, an image store,s_barrier; GLC loads and loads that overwrite their own base left alone; available after a join only when every path has it, around a loop's back edge only without a store in the body), the direct translation of a small program (valid DXIL with onerawBufferLoadfewer for the repeat, and loaded again after a store), and a check that every output operand type of the instruction tables is one the analysis knows.Tested
AMD Radeon RX 6700 XT 12 GB (RDNA2, driver 32.0.21045), Ryzen 5 5600X, 16 GB RAM, Windows 10 22H2 (19045), rustc 1.90.0; debug tests, release for the rest. On
482cb12(this commit onmain568e7db).cargo test --workspace --no-fail-fast -- --test-threads=4: 1156 passed, 4 failed, 46 ignored. Onmain(cbc296a, same crates as568e7db) in the same session: 1149 passed, 5 failed, 46 ignored. The 4 fail on both:gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 540, Tests: reduce fuzz seed 540, an RDNA2-only sext i1 -> i64 failure #2170),hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory(Tests: align XMemVirtualQuery buffers and verify CPU flags #650), and the e2e teststest_title_runs_and_game_folder_is_untouched,test_title_draws_with_a_root_signature_under_the_debug_layer;main's fifth,vram::tests::d32s8_targets_take_their_own_size_of_video_memory, passed in the PR's run. SKIPPED on both: the six per-lane cases off16_programs_on_the_gpu/f32_programs_on_the_gpu(refused),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).The retail title's shader pack through the direct translator with validation (
xcl shaders <pack> --direct --sample 0 --validate --max-bytes 400000): all 26 696 programs translate and validate (2 687 CS, 390 GS, 9 282 MS, 12 101 PS, 2 236 VS; the 2 over 400 000 B of code not sampled).DXIL of single programs (
--direct --hash H --dump, 4 windows as a switch),main→ this PR:The retail title, on a local tree with this change and other open PRs,
XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1: the driver compile (cache off) of a ray-tracing resolve variant took 23 s without this change and dxil: collapse forward s_cbranch_execz regions and make read-only loads branchless #1834, 17 s with both. The title's world load ran with it in a dozen runs; where those end is Retail title 1.0.2.1: GPU hang / crash at +0x23cf683 when the story loads (RTX 3070 Ti) #675, in a draw this does not change.Regression run
scripts/smoke.ps1, 60 s, release builds, the default settings (XCL_DIRECT_DXILunset). The PR's first run, the first of its executable on this machine, had 561 frames; this block is its second run.main:
PR:
Not tested
AI use
main, the measurements, the runs and this description).🤖 Generated with Claude Code