Recompiler: direct DXIL emits a repeated scalar load once #2207
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2207
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2207/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@madaraXor on GitHub · 2026-11-25 09:39 UTC · original
madaraXor:dxil-repeated-scalar-loads→main· +405 −0 · 5 files · 1 commits · merged 2026-11-25 10:45 UTCThe 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 #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, #2170),hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory(#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 #1834, 17 s with both. The title's world load ran with it in a dozen runs; where those end is #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
@DarkPanda69 on GitHub · 2026-11-25 10:06 UTC · original
NVIDIA with 32-lane waves (listed as untested), plus the RX 9070 XT, paired against
mainwith the direct translator on for the whole GPU suite.Head
482cb12applied onmain568e7db, debug, Windows 11 Pro 26200,XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4, onmainand on this PR for each card:mainPer-test comparison: on both cards the only differences are the 6 new
gpu::dxil::reload::tests(all ok,the_translator_emits_a_repeated_load_onceincluded). No existing test changes result or skip state. The failures are the same onmain:gpu_image_get_resinfo_1d_arrayon both cards (the direct-path bug #2046 fixes) and, on the RX 9070 XT only, the fuzz seeds 722 and 1599 tracked in #2115.Not tested: a title with
XCL_DIRECT_DXIL=1, GPU time.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@bielfreedom on GitHub · 2026-11-25 10:18 UTC · original
AMD Windows driver data for #2207: on the RX 9070 XT, the programs it changes build 4–10 % faster in AMD's
CreateComputePipelineState. ActivateRays' plain DXIL shrinks by 38 %, but it still passes 24 GB.Setup
568e7db;482cb12.fnv64) and per-CreateComputePipelineStatetime.Method
XCL_DIRECT_DXIL=1,XCL_HEAP_WINDOWS=0,XCL_PIPELINE_THREADS=1.XCL_PSO_DISK_CACHE=0and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name.84eee477d68b6fdf(CS_RaytracingResolve) and620491641aa9bad6, the two the AMD reports in #1269 named.26 programs (means of 2 rounds; all 104 builds succeeded, 0 refused)
The changed programs:
84eee477d68b6fdfCS_RaytracingResolveed2f8fa2e996c6a6b3618a0fd76af79cc6f8ee0f53ed5709d8435f454a5102706d1e4583f81297717c08ec6429245b8e620491641aa9bad6ActivateRays (
95cc13288a27a96e), whichmainkeeps plain on this adapter, 1 run each: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 (
XCL_REQUIRE_GPU=1,XCL_ADAPTER=9070)cargo test --release -p xcl --lib -- reload --test-threads=1: 6 passed, 0 failed.the_translator_emits_a_repeated_load_once.Read / inference
Not tested
gpu::suite withXCL_DIRECT_DXIL=1.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.