Skip to content

Recompiler: XCL_DIRECT_COMPACT_MIN=<n> takes big compute programs compact - #3479

Open
Foniass wants to merge 1 commit into
xcl-dev:mainfrom
Foniass:dxil-compact-min
Open

Foniass wants to merge 1 commit into
xcl-dev:mainfrom
Foniass:dxil-compact-min

Conversation

@Foniass

@Foniass Foniass commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Port of raylitebull's amd-dev commit 41dc012e. The direct translator picks the compact form only for size: from 10,000 instructions or 2,000 blocks, and only when most of the program repeats. On a big program below that, the driver's register allocation of the plain form can be the program's cost. amd-dev's case is the retail title's shadow-mask program (d9fac2f1d8f646fd, ~6,000 instructions, 20–139 ms a frame in the open world):

  • on RDNA4 its plain form takes 256 VGPRs and 18 KB of scratch per lane;
  • its compact form takes 215 VGPRs and no scratch.

XCL_DIRECT_COMPACT_MIN=<n>: a compute program of at least n reachable instructions takes the compact form whenever its table fits (compact::sized_plan), however little of it repeats. Otherwise the automatic choice applies as before. Unset by default, so nothing changes unless it is set. The caches key the value.

amd-dev's measurement (RX 9070 XT, the program patched past its early exits, ms per dispatch): plain 95.6, compact 24.7.

What is in it

  • crates/xcl/src/gpu/dxil/compact.rs: compact_min, sized_plan
  • crates/xcl/src/gpu/dxil/kernel.rs: the switch in the plan choice for compute programs, the test plumbing
  • crates/xcl/src/gpu/recomp/pso.rs: the value in both direct cache identities, test a_compact_size_is_another_direct_output
  • crates/xcl/src/gpu/dxil/compact_tests.rs: the commit's tests of the size choice and a GPU run against the plain form
  • Port: the conflicts were only the cache identities and test plumbing next to amd-dev-only switches (declared LDS, coherent per access, one-wave group IDs); only the XCL_DIRECT_COMPACT_MIN parts are taken.

Tested

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114) and AMD Radeon RDNA2 iGPU (driver 32.0.21030), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test -p xcl --lib -- gpu::dxil::compact_tests shader_cache_tests (5070 Ti): 47 passed, 0 failed
  • gpu::dxil::compact_tests on the iGPU: 15 passed, 1 failed. The failure is main's literal-table bug on AMD, fixed by Recompiler: compact literal indices are read from one table word on AMD #3473. The new tests pass there.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on f9935af, rebased on main 86e86fc (5070 Ti): 2892 passed, 0 failed, 51 ignored. SKIPPED: 28 notices, almost all no wave64 (the others: no D3D12 debug layer, heap windows off, driver cache needs Developer Mode). The narrower runs listed here are from before the rebase.
  • Retail title: 60 s smoke run below. The switch is unset there, as by default.

Regression run

main:

xcl-smoke v1
commit: 86e86fcb33f94fa5d0c809d9b50af7b84bf49cce
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1608 (PresentX 1608)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15766 MB

this PR:

xcl-smoke v1
commit: f9935af1647917d02a585dcdf160af0a5755d988
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1613 (PresentX 1613)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16400 MB

Not tested

  • With the switch set, in the title (the gain above is amd-dev's, on RDNA4); NVIDIA's register allocation of that program was not compared

AI use

  • Claude Code with Claude Opus 5.5: ported the commit to main (conflicts), ran the tests on both GPUs and the smoke runs, wrote this description.
  • Original code: raylitebull's amd-dev 41dc012e.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 30, 2026
…pact

The direct translator picks the compact form (each distinct block lowered
once, run from a table) only for size: from 10,000 instructions or 2,000
blocks, and only when most of the program repeats. Below that a big
program gets the plain form, whose register allocation in the driver can
be the program's cost. The title's shadow-mask program
(cs d9fac2f1d8f646fd, ~6,000 instructions, a light loop around nearly all
of it; 20-139 ms a frame in the open world) compiles on RDNA4 (RGA,
amdxc64 gfx1201, the run's heap windows) to 256 VGPRs and 18 KB of
scratch a lane, ~18,000 scratch loads and stores; its compact form to
215 VGPRs, 75 SGPRs and no scratch, 32,146 instead of 58,333
instructions.

XCL_DIRECT_COMPACT_MIN=<n>: a compute program of at least n reachable
instructions takes the compact form whenever its table fits, however
little of it repeats (compact::sized_plan); otherwise the automatic
choice as before. Unset by default; the caches key the value.

Measured on the GPU (RX 9070 XT, Adrenalin as installed, RDNA4 wave32;
the program patched past its early exits with a light mask of all ones,
zero memory, 40x40 groups of 4x8, one 32-light word; ms a dispatch):
plain 95.6 (8,192-dword LDS) / 80.0 (declared LDS), compact 24.7 / 4.0.

Port onto main: the conflicts were only the caches identities and the test
plumbing next to amd-dev-only switches (declared LDS, coherent per access,
one-wave group IDs); only the XCL_DIRECT_COMPACT_MIN parts are taken.

(cherry picked from commit 41dc012)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: 1c8b551
head: f9935af
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 1 failed, 51 ignored (base: 2909 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: hle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime. Not this PR: it is the shared-counter race #3551 fixes, and it passed alone 3 of 3 on this merge.
review: read the whole diff (4 files, +151 -3). No correctness problem found.

  • XCL_DIRECT_COMPACT_MIN=<n> (unset or 0: off) makes a compute program of at least n reachable instructions take sized_plan, the compact form when its table fits, before the automatic choice. Graphics and the default path are unchanged.
  • The value is in both direct cache identities (a_compact_size_is_another_direct_output), and the warm-settings key takes any XCL_ variable not on its exclusion list.
  • gpu::dxil::compact_tests:: plus a_compact_size_is_another_direct_output (17 tests): 3 of 3 runs passed. They include gpu_compute_compact_form_from_the_size_runs_as_the_plain_form on this wave32 GPU (not skipped).
  • gpu::dxil:: (310 tests) with XCL_DIRECT_COMPACT_MIN=100 and with =5000: 310 passed, 0 failed each.
  • Mutation: sized_plan ignoring the size (if false && insts(cfg) < min) fails a_compute_program_from_the_compact_size_takes_the_compact_form. Good. (The GPU parity test still passes then, as it should: the compact form is still right.)
  • No retail title on this machine: the shadow-mask program's speed-up was not measured here.
    performance: none by default (unset). When set, compute programs from that size take the compact form: the author's amd-dev numbers, not measured here.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 1, 2026
@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants