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

Open
Foniass wants to merge 1 commit from upstream-pr/3479 into main
Foniass commented 2026-11-30 00:00:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-30T00:00:26Z.


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 #3473. The new tests pass there.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on f9935af1, rebased on main 86e86fcb (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

<!-- greyfinch-sync:ivall/xcl:issue:5556572300 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3479). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-30T00:00:26Z. --- 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 #3473. The new tests pass there. - `cargo test --workspace --no-fail-fast -- --test-threads=4` on f9935af1, rebased on main 86e86fcb (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](https://claude.com/claude-code)
fromthemoonx commented 2026-12-01 23:07:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T23:07:26Z.


merge-check
base: 1c8b551475
head: f9935af164
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)
<!-- greyfinch-sync:ivall/xcl:comment:7328851676 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3479#issuecomment-7328851676). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-01T23:07:26Z. --- merge-check base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: f9935af1647917d02a585dcdf160af0a5755d988 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)
bmjask commented 2026-12-02 14:13:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:13:01Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7348178373 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3479#issuecomment-7348178373). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:13:01Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3479:upstream-pr/3479'
git switch 'upstream-pr/3479'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3479'
git switch 'upstream-pr/3479'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3479'
git switch 'upstream-pr/3479'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3479'
git switch 'main'
git merge --squash 'upstream-pr/3479'
git switch 'main'
git merge --ff-only 'upstream-pr/3479'
git switch 'main'
git merge 'upstream-pr/3479'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3479
No description provided.