Recompiler: direct DXIL emits a repeated scalar load once #2207

Manually merged
github merged 1 commit from gh-pr/2207/head into gh-pr/2207/base 2026-11-26 05:23:15 +00:00
Owner

@⁠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 UTC

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 889 buffer_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. An s_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 no s_barrier. What may write registers is read from the encoding and taken wider where it is not plain (s_movrel*, s_setreg and unknown operand types: all registers). A program with s_call_b64 is 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.
  • Tests in 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_readfirstlane into 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 one rawBufferLoad fewer 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 on main 568e7db).

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1156 passed, 4 failed, 46 ignored. On main (cbc296a, same crates as 568e7db) 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 tests test_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 of f16_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:

    program DXIL
    the biggest compute program (333 596 B of code) 3 916 120 → 2 414 940 B
    a ray-tracing resolve variant 965 748 → 911 716 B
    another one 1 025 520 → 967 588 B
  • 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_DXIL unset). The PR's first run, the first of its executable on this machine, had 561 frames; this block is its second run.

main:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: AMD Radeon RX 6700 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 727 (PresentX 728)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16976 MB

PR:

xcl-smoke v1
commit: 482cb1267db971259c67cb264b4be2ae28ed5a36
gpu: AMD Radeon RX 6700 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 680 (PresentX 681)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19476 MB

Not tested

  • The smoke runs do not reach the code this changes: the direct translator is off by default.
  • NVIDIA / Intel, 32-lane waves (the analysis does not depend on the wave size; the GPU tests ran in wave64 here).
  • Programs in the compact form (#2034) are not changed.

AI use

  • Claude Code with Claude Fable 5.2 (the analysis, the lowering and the tests) and Claude Opus 5.5 (the rebase onto main, the measurements, the runs and this description).

🤖 Generated with Claude Code

**@⁠madaraXor** on GitHub · 2026-11-25 09:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/2207) `madaraXor:dxil-repeated-scalar-loads` → `main` · +405 −0 · 5 files · 1 commits · merged 2026-11-25 10:45 UTC 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 889 `buffer_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. An `s_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 no `s_barrier`. What may write registers is read from the encoding and taken wider where it is not plain (`s_movrel*`, `s_setreg` and unknown operand types: all registers). A program with `s_call_b64` is 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. - Tests in `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_readfirstlane` into 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 one `rawBufferLoad` fewer 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 on `main` `568e7db`). - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1156 passed, 4 failed, 46 ignored. On `main` (`cbc296a`, same crates as `568e7db`) 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 tests `test_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 of `f16_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: | program | DXIL | |---|---| | the biggest compute program (333 596 B of code) | 3 916 120 → 2 414 940 B | | a ray-tracing resolve variant | 965 748 → 911 716 B | | another one | 1 025 520 → 967 588 B | - 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_DXIL` unset). The PR's first run, the first of its executable on this machine, had 561 frames; this block is its second run. main: ``` xcl-smoke v1 commit: cbc296ab65a2661a61e3e2da109134bcd5319f60 gpu: AMD Radeon RX 6700 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 727 (PresentX 728) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16976 MB ``` PR: ``` xcl-smoke v1 commit: 482cb1267db971259c67cb264b4be2ae28ed5a36 gpu: AMD Radeon RX 6700 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 680 (PresentX 681) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19476 MB ``` **Not tested** - The smoke runs do not reach the code this changes: the direct translator is off by default. - NVIDIA / Intel, 32-lane waves (the analysis does not depend on the wave size; the GPU tests ran in wave64 here). - Programs in the compact form (#2034) are not changed. **AI use** - Claude Code with Claude Fable 5.2 (the analysis, the lowering and the tests) and Claude Opus 5.5 (the rebase onto `main`, the measurements, the runs and this description). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:23:12 +00:00
github manually merged commit 482cb1267d into gh-pr/2207/base 2026-11-26 05:23:15 +00:00
Author
Owner

@⁠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 main with the direct translator on for the whole GPU suite.

Head 482cb12 applied on main 568e7db, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4, on main and on this PR for each card:

main this PR
RTX 3060 (32.0.16.1088, wave32 only, split wave64) 585 passed, 1 failed, 22 ignored, 23 SKIPPED 591 passed, 1 failed, 22 ignored, 23 SKIPPED
RX 9070 XT (RDNA4, 32.0.32029.2010, native wave64) 583 passed, 3 failed, 22 ignored, 6 SKIPPED 589 passed, 3 failed, 22 ignored, 6 SKIPPED

Per-test comparison: on both cards the only differences are the 6 new gpu::dxil::reload::tests (all ok, the_translator_emits_a_repeated_load_once included). No existing test changes result or skip state. The failures are the same on main: gpu_image_get_resinfo_1d_array on 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.

**@⁠DarkPanda69** on GitHub · 2026-11-25 10:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2207#issuecomment-7159239169) NVIDIA with 32-lane waves (listed as untested), plus the RX 9070 XT, paired against `main` with the direct translator on for the whole GPU suite. Head `482cb12` applied on `main` `568e7db`, debug, Windows 11 Pro 26200, `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4`, on `main` and on this PR for each card: | | `main` | this PR | |---|---|---| | RTX 3060 (32.0.16.1088, wave32 only, split wave64) | 585 passed, 1 failed, 22 ignored, 23 SKIPPED | 591 passed, 1 failed, 22 ignored, 23 SKIPPED | | RX 9070 XT (RDNA4, 32.0.32029.2010, native wave64) | 583 passed, 3 failed, 22 ignored, 6 SKIPPED | 589 passed, 3 failed, 22 ignored, 6 SKIPPED | Per-test comparison: on both cards the only differences are the 6 new `gpu::dxil::reload::tests` (all ok, `the_translator_emits_a_repeated_load_once` included). No existing test changes result or skip state. The failures are the same on `main`: `gpu_image_get_resinfo_1d_array` on 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.
Author
Owner

@⁠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

  • GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010.
  • CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release.
  • Builds:
    • base 568e7db;
    • this PR at 482cb12.
  • Both builds carry a local patch that logs per-program DXIL size, record hash (fnv64) and per-CreateComputePipelineState time.

Method

  • XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0, XCL_PIPELINE_THREADS=1.
  • XCL_PSO_DISK_CACHE=0 and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name.
  • 26 retail compute programs, 6 KB to 1.0 MB of direct DXIL. They are the 24 I used for earlier PRs, plus 84eee477d68b6fdf (CS_RaytracingResolve) and 620491641aa9bad6, the two the AMD reports in #1269 named.
  • 2 rounds, interleaved.
  • A watchdog killed a run at 24 GB.

26 programs (means of 2 rounds; all 104 builds succeeded, 0 refused)

base #2207 change
direct DXIL, total 8,598,156 B 8,293,796 B −3.5 %
driver, sum (r1 / r2) 269.0 / 267.4 s 251.1 / 250.8 s −6.4 %
driver run, process peak private 4.45–4.60 GB 4.07 GB −10 %
  • 12 of the 26 programs change, all the ones of 280 KB or more. 14 smaller ones are byte-identical, and their driver times stay within ±4 %.

The changed programs:

program DXIL base → PR driver base → PR faster
84eee477d68b6fdf CS_RaytracingResolve 1,025,520 → 967,588 B 52.7 → 49.5 s 6 %
ed2f8fa2e996c6a6 917,300 → 886,088 B 43.8 → 41.8 s 5 %
b3618a0fd76af79c 905,768 → 859,884 B 43.6 → 39.1 s 10 %
c6f8ee0f53ed5709 829,532 → 806,284 B 36.3 → 34.7 s 4 %
d8435f454a510270 791,532 → 750,792 B 33.6 → 30.2 s 10 %
6d1e4583f8129771 658,092 → 634,984 B 8.2 → 7.9 s 3 %
7c08ec6429245b8e 569,696 → 544,920 B 7.4 → 6.7 s 10 %
620491641aa9bad6 387,784 → 377,688 B 17.7 → 17.0 s 4 %
4 programs of 280–370 KB −3 to −4 % 12.9 → 12.0 s 7 %

ActivateRays (95cc13288a27a96e), which main keeps plain on this adapter, 1 run each:

build direct DXIL AMD driver
base 3,916,120 B 24 GB after 153 s, killed
#2207 2,414,940 B (−38 %) 24 GB after 155 s, killed

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.
  • That includes the_translator_emits_a_repeated_load_once.

Read / inference

  • A modest but consistent win on the native AMD Windows compiler. The gain scales with program size, up to 10 % on the largest, and no program got slower.
  • It should stack with #2107's split on the same programs, since the pieces are smaller. I haven't measured the two together.

Not tested

  • The whole gpu:: suite with XCL_DIRECT_DXIL=1.
  • GPU output of the changed programs.
  • The HLSL path.
  • A title run.
  • RDNA2 and RDNA3.

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.

**@⁠bielfreedom** on GitHub · 2026-11-25 10:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2207#issuecomment-7159510824) **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** - GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010. - CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release. - Builds: - base `568e7db`; - this PR at `482cb12`. - Both builds carry a local patch that logs per-program DXIL size, record hash (`fnv64`) and per-`CreateComputePipelineState` time. **Method** - `XCL_DIRECT_DXIL=1`, `XCL_HEAP_WINDOWS=0`, `XCL_PIPELINE_THREADS=1`. - `XCL_PSO_DISK_CACHE=0` and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name. - 26 retail compute programs, 6 KB to 1.0 MB of direct DXIL. They are the 24 I used for earlier PRs, plus `84eee477d68b6fdf` (`CS_RaytracingResolve`) and `620491641aa9bad6`, the two the AMD reports in #1269 named. - 2 rounds, interleaved. - A watchdog killed a run at 24 GB. **26 programs** (means of 2 rounds; all 104 builds succeeded, 0 refused) | | base | #2207 | change | |---|---:|---:|---:| | direct DXIL, total | 8,598,156 B | 8,293,796 B | −3.5 % | | driver, sum (r1 / r2) | 269.0 / 267.4 s | **251.1 / 250.8 s** | **−6.4 %** | | driver run, process peak private | 4.45–4.60 GB | 4.07 GB | −10 % | - 12 of the 26 programs change, all the ones of 280 KB or more. 14 smaller ones are byte-identical, and their driver times stay within ±4 %. The changed programs: | program | DXIL base → PR | driver base → PR | faster | |---|---:|---:|---:| | `84eee477d68b6fdf` `CS_RaytracingResolve` | 1,025,520 → 967,588 B | 52.7 → **49.5 s** | 6 % | | `ed2f8fa2e996c6a6` | 917,300 → 886,088 B | 43.8 → 41.8 s | 5 % | | `b3618a0fd76af79c` | 905,768 → 859,884 B | 43.6 → 39.1 s | 10 % | | `c6f8ee0f53ed5709` | 829,532 → 806,284 B | 36.3 → 34.7 s | 4 % | | `d8435f454a510270` | 791,532 → 750,792 B | 33.6 → 30.2 s | 10 % | | `6d1e4583f8129771` | 658,092 → 634,984 B | 8.2 → 7.9 s | 3 % | | `7c08ec6429245b8e` | 569,696 → 544,920 B | 7.4 → 6.7 s | 10 % | | `620491641aa9bad6` | 387,784 → 377,688 B | 17.7 → 17.0 s | 4 % | | 4 programs of 280–370 KB | −3 to −4 % | 12.9 → 12.0 s | 7 % | **ActivateRays (`95cc13288a27a96e`)**, which `main` keeps plain on this adapter, 1 run each: | build | direct DXIL | AMD driver | |---|---:|---| | base | 3,916,120 B | 24 GB after 153 s, killed | | #2207 | **2,414,940 B (−38 %)** | 24 GB after 155 s, killed | 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**. - That includes `the_translator_emits_a_repeated_load_once`. **Read / inference** - A modest but consistent win on the native AMD Windows compiler. The gain scales with program size, up to 10 % on the largest, and no program got slower. - It should stack with #2107's split on the same programs, since the pieces are smaller. I haven't measured the two together. **Not tested** - The whole `gpu::` suite with `XCL_DIRECT_DXIL=1`. - GPU output of the changed programs. - The HLSL path. - A title run. - RDNA2 and RDNA3. 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.