Skip to content

Recompiler: defer large per-lane compute shaders to compact direct DXIL - #2796

Open
Saksukella wants to merge 1 commit into
xcl-dev:amd-devfrom
Saksukella:fix/bound-3d-commit-memory
Open

Saksukella wants to merge 1 commit into
xcl-dev:amd-devfrom
Saksukella:fix/bound-3d-commit-memory

Conversation

@Saksukella

@Saksukella Saksukella commented Nov 26, 2026 •

Copy link
Copy Markdown

What is in it

  • Part 1 (7a8056fa, compact::large() block/instruction thresholds) was cherry-picked onto amd-dev in 53995420; this PR is rebased cleanly onto amd-dev (c32c91a3) with the remaining per-lane compact routing fix (960f4fc2):
  • crates/xcl/src/gpu/dxil/mod.rs, crates/xcl/src/gpu/recomp/lower_dxil.rs, crates/xcl/src/gpu/recomp/pso.rs:
    • Under XCL_PER_LANE=1, lower_dxil::compute_with() previously ran before gpu::dxil::kernel::translate_compute() and returned immediately on Ok(k), bypassing compact::large()/compact::plan() and split_compute(). As a result, branch-heavy unrolled compute shaders (for example, cs 56c0cd3b82a00c6e) still emitted 2,673,860 B monolithic DXIL (588,191 IR lines, 32,279 basic blocks, 36,143 PHIs) and triggered >36 GiB driver-compiler commit spikes under XCL_PER_LANE=1.
    • Defer large compute programs (compact::large(&cfg)) out of lower_dxil::compute_with() so they lower through compact/split direct DXIL (160,534 B, 31,585 IR lines, 975 blocks, 108 PHIs — 16.7x smaller), and fall back in pso.rs::direct_compute() to translate_compute_rodata() when per-lane DXIL exceeds 512 KiB and the compact/split alternative is smaller or split.
  • crates/xcl/src/gpu/dxil/compact_tests.rs:
    • Add CPU unit test per_lane_compute_defers_branch_heavy_program_to_compact_path confirming large branch-heavy compute programs defer from lower_dxil::compute_with.
  • Target branch: amd-dev.

Tested

  • Hardware: AMD Radeon RX 9070 XT (driver 32.0.32029.2010), 24-thread x86_64 CPU, 32 GB RAM, Windows; rustc 1.100.0 (0ef1bc386 2026-11-09); debug (tests) and release (xcl.exe).
  • cargo test -p xcl --lib gpu::dxil::compact -- --skip gpu_: 8 passed, 0 failed (1.52s), including per_lane_compute_defers_branch_heavy_program_to_compact_path.
  • Live 180s RX 9070 XT soak (XCL_DIRECT_DXIL=1, XCL_PER_LANE=1, XCL_RT_GATE=hold, no DXIL size cap):
    • cs 56c0cd3b82a00c6e lowered via compact form (direct DXIL compact form: 20965 blocks of 672 kinds), shrinking on-disk DXIL from 2,673,860 B to 160,534 B (16.7x smaller) with 0 driver refusals and no compile stall, dropping peak process commit from 63,298 MB to 34,190 MB (-29.1 GB / -46%, and 27.7–31.8 GB on amd-dev c32c91a3), with 0 device removals and 0 crashes.

Regression run

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19700 MB
xcl-smoke v1
commit: 960f4fc230fd610b2f64a448801edf9d2d4f7ca4
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1655 (PresentX 1655)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15221 MB

Not tested

  • NVIDIA and Intel GPU adapters (tested on AMD Radeon RX 9070 XT only).

AI use

  • Antigravity (Google Gemini): assisted with profiling the XCL_PER_LANE=1 compact-bypass commit spike on branch-heavy compute shaders, implementing the lower_dxil::compute_with() / pso.rs::direct_compute() deferral and unit test, rebasing cleanly onto amd-dev c32c91a3, and running local tests and smoke verification. All diffs and measurements were verified locally on hardware.

@ettehn

ettehn commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA check on 7a8056faf35e7c24d38e639ae893b89ff775a2c0. The only local change was a test probe using the existing synthetic repeated fixture. The default selection produced byte-identical output to the expected forced form in both cases.

Reachable blocks Non-terminators Default form Plain DXIL Compact DXIL
1,603 3,604 Plain 63,604 B 4,924 B
2,003 4,504 Compact 79,904 B 5,224 B

A single-block fixture independently confirmed the instruction gate: compact::large was false at 9,999 non-terminators and true at 10,000. Two existing small GPU tests confirmed plain/compact output parity and matching loop-budget behavior.

Windows 11 build 26200, Ryzen 9 8945HX, RTX 5070 Ti Laptop GPU (12 GB, driver 621.24), Rust 1.97.1 MSVC debug, DXC 1.8.2502.11, XCL_ADAPTER=NVIDIA XCL_REQUIRE_GPU=wave64:

cargo test --locked --offline -p xcl --lib -j 2 -- compact_threshold_probe a_large_program_that_repeats_itself_takes_the_compact_form gpu_compact_form_runs_as_the_plain_form gpu_compact_form_spends_the_loop_budget_as_the_plain_form --test-threads=1 --nocapture

4 passed, 0 failed, 0 ignored, no reported skips. The threshold fixtures were translated only. This run did not measure NVIDIA driver compile commit, run the full workspace suite, or launch a retail title.

OpenAI Codex assisted with the probe and verification. The exact model identifier was unavailable in this session.

@DarkPanda69

DarkPanda69 commented Nov 26, 2026 •

Copy link
Copy Markdown

Update for head 960f4fc: still passes on both cards. On the newer amd-dev c32c91a, gpu::dxil::compact plus the new test gives 13 passed, 0 failed, 0 SKIPPED on the RTX 3060 and the RX 9070 XT, per_lane_compute_defers_branch_heavy_program_to_compact_path ok on both.

Update for head efb6e48: same result on both cards. On amd-dev b5c0275, gpu::dxil::compact gives 12 passed, 0 failed, 0 SKIPPED on the RTX 3060 and the RX 9070 XT (11 without the PR), and the new per_lane_compute_defers_branch_heavy_program_to_compact_path passes by name on both.


NVIDIA run for the Not tested line, with the RX 9070 XT from the same PC.

Tested: pass, head 7a8056f applied on its base amd-dev b5c0275, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, card picked with XCL_ADAPTER.
cargo test -p xcl --lib -- gpu::dxil::compact --test-threads=4 --nocapture:

  • NVIDIA RTX 3060, driver 32.0.16.1088: 11 passed, 0 failed, 0 SKIPPED.
  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: 11 passed, 0 failed, 0 SKIPPED.

amd-dev without the PR gives the same counts on both cards.

Not tested: a title run or the cs 56c0cd3b82a00c6e driver compile on NVIDIA; Intel.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@Saksukella

Copy link
Copy Markdown
Author

Follow-up in \efb6e48e: during live \XCL_PER_LANE=1\ testing we found \lower_dxil::compute_with()\ in \pso.rs\ returned before \gpu::dxil::kernel::translate_compute(), bypassing \compact::large()\ and still emitting \2,673,860 B\ DXIL for \cs 56c0cd3b82a00c6e. Deferring \compact::large(&cfg)\ out of \lower_dxil::compute_with()\ (and falling back when per-lane DXIL exceeds \512 KiB\ and compact/split is smaller) now routes \cs 56c0cd3b82a00c6e\ through compact form at runtime (\160,534 B, \16.7x\ smaller), cutting 180s RX 9070 XT peak commit from \63,298 MB\ to \34,190 MB\ (-29.1 GB). Re-verified with \7/7\ CPU \compact\ tests and fresh 60s RX 9070 XT smoke (\1661\ frames, \60 61 60, \

@frozht

frozht commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Test report on a retail compute shader that crosses the new threshold but does not take the compact form. Linux/RADV, tested at head 7a8056fa (before efb6e48e), not on amd-dev.

Setup: RX 7900 XT 20 GB (gfx1100), Mesa 26.2.6 RADV, vkd3d-proton 30b0eb9b under Wine (wine-staging 11.22), Ryzen 9 5900X, 32 GB, Linux 7.3, release build (x86_64-pc-windows-gnu). Base: main b49be183 + #877, #684, #1993, #2127 (our Wine stack). 7a8056fa was cherry-picked on top (one conflict in compact.rs around automatic_plan, resolved by keeping main's automatic_plan), plus a local print of the compact decision inputs. Shader: retail title from #505, cs 84eee477d68b6fdf, built alone offline with xcl shaders <pack> --measure-pso and XCL_DIRECT_DXIL=1, under a 12 GB memory cap.

without #2796 with #2796 (7a8056fa)
reachable blocks / non-terminator insts 834 / 16,713 834 / 16,713
compact::large() false true (≥ 10,000 insts)
compact form adopted (wanted) – no (not repetitive enough)
direct DXIL whole 958,940 B 958,940 B, byte-identical
process peak memory (translate + RADV compile) 1.2 GB 1.5 GB (same DXIL; one run each)

So the lower threshold now asks wanted() about this shader, the dedup gate keeps it plain, and the output does not change. Nothing regresses for this shader. It also gets no benefit, but it does not need one: on the direct path RADV builds it in ~3.8 s.

For context, not about this PR: the same record through the default HLSL → DXC path (1,403,484 B DXIL) never finishes on RADV. ACO's register spiller grows past 12 GB within ~50 s, and a debug Mesa 26.2.6 build hits the spiller assert of https://gitlab.freedesktop.org/mesa/mesa/-/issues/15722. So the large-shader commit spikes the PR describes for AMD's Windows driver have a Linux counterpart on the HLSL path, which compact form does not reach.

Not tested: head efb6e48e and the XCL_PER_LANE path; the amd-dev base; Windows; the PR's unit tests (not run here); an in-game run with the PR.

AI use: Claude Code (Claude Opus 5.5) built the probe, ran the measurements and wrote this report. Numbers checked against the run logs before posting.

# Conflicts:
#	crates/xcl/src/gpu/recomp/pso.rs
@Saksukella
Saksukella force-pushed the fix/bound-3d-commit-memory branch from efb6e48 to 960f4fc Compare November 26, 2026 15:52
@Saksukella Saksukella changed the title DXIL: trigger compact form on branch-heavy shaders to prevent driver compile commit spikes Recompiler: defer large per-lane compute shaders to compact direct DXIL Nov 26, 2026
@Saksukella

Saksukella commented Nov 26, 2026 •

Copy link
Copy Markdown
Author

Rebased cleanly onto amd-dev (c32c91a3, which already picked up Part 1 7a8056fa in 53995420) at 960f4fc2.

This PR now contains only the remaining XCL_PER_LANE=1 deferral to compact/split direct DXIL (lower_dxil::compute_with() + pso.rs::direct_compute() fallback to translate_compute_rodata()), verified with 8/8 CPU compact tests and a fresh 60s RX 9070 XT smoke (1,655 frames, 60 60 60, 0 crashes, 0 device removals, 15,221 MB peak commit).

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the compact-DXIL and per-lane routing tests at 960f4fc on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu::dxil::compact_tests -- --test-threads=1
12 passed; 0 failed; 0 ignored; 0 measured; 1634 filtered out      (exit 0)

All 12 pass, including the new per_lane_compute_defers_branch_heavy_program_to_compact_path and five gpu_* tests that compile and run compact DXIL on the real adapter. This is the rebased head 960f4fc (targets amd-dev); the NVIDIA report from ettehn in the thread was on the earlier head 7a8056fa, and DarkPanda69 checked this head on other cards. This adds a desktop Blackwell part on driver 32.0.16.2124 with DXC 1.9.2609.5.

Not tested: the large branch-heavy program behind XCL_PER_LANE=1 from the description, the full workspace suite, a paired 60 s smoke run, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@bielfreedom

Copy link
Copy Markdown

AMD Windows data for #2796: on an RX 9070 XT, the new thresholds change one retail compute program out of 2,689. That program builds about 1.6× slower in AMD's driver and with 4× the peak memory. On main it is split into 11 pieces; the compact form replaces them with one whole program.

First, the branch. It now carries 256 commits against main (77+ files) and does not merge cleanly. I measured only this PR's own threshold commit (7a8056f): the compact::large change, applied by hand onto main b49be18. The newer 960f4fc defers large per-lane compute programs to the compact form. As far as I can tell, the per-lane path is the 32-lane-GPU one, which this native wave64 card does not take; I did not build it.

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.
  • Both builds carry a local timing patch in xcl shaders that writes every program's DXIL size and every CreateComputePipelineState time to a file.
  • Offline: xcl shaders <retail shaders.rpf> --precompile --only cs [--pipelines] with XCL_DIRECT_DXIL=1, XCL_PSO_DISK_CACHE=0, one driver thread, and a fresh translation cache and exe name per run, so every build is cold.

Which programs change, all 2,689 compute programs (translation only)

windows main this change programs changed
switch (default) 885,910,100 B 885,323,148 B 1: b6101d83892d44a5, 865,336 → 278,384 B
heap 728,930,968 B 728,461,444 B 1: the same program, 695,244 → 225,720 B

56c0cd3b82a00c6e, the example in the description, is already compact on main here, so it does not change.

Driver, b6101d83892d44a5 alone, switch windows, 2 interleaved rounds

build form pipelines driver time r1 / r2 peak memory
main split, 11 pieces 11 8.3 / 8.9 s 0.58 GB
this change compact, whole 1 13.1 / 14.0 s 2.48 GB

So on AMD this program was better off split. This looks like what #2810 describes for automatic compact lowering: the compact whole replaces a split plan that was available. One option is to leave the threshold alone for programs that already split.

Not tested: NVIDIA, GPU output, and a title run.

AI use: Claude Code (Claude Opus 5.5) built the binaries, ran the measurements and wrote this report; I posted it.

@Saksukella

Copy link
Copy Markdown
Author

Thanks for the thorough RX 9070 XT measurement! Two quick clarifications on the current PR head (960f4fc2):

  1. Base branch & diff: This PR targets amd-dev (not main) and is a single commit (960f4fc2, 2 files) cleanly on top of amd-dev (c32c91a3).
  2. Scope of 960f4fc2: The earlier compact::large threshold commit (7a8056f) is no longer in this PR — it was already picked into amd-dev as 53995420. What remains here is solely the XCL_PER_LANE=1 deferral (lower_dxil::compute_with() returning None for large branch-heavy programs so pso.rs::direct_compute() falls back to translate_compute_rodata()). When XCL_PER_LANE=1 is enabled (including on RX 9070 XT runs testing per-lane lowering), cs 56c0cd3b82a00c6e previously bypassed translate_compute_rodata() and emitted a 2.67 MB (32,279-block, 36,143-PHI) per-lane DXIL blob; with 960f4fc2 it takes the standard split/compact direct DXIL path (160 KB).

Your b6101d83892d44a5 finding (compact whole vs 11-piece split, matching #2810) is great data for the 53995420 threshold already on amd-dev, and is orthogonal to 960f4fc2 since 960f4fc2 defers directly to translate_compute_rodata()'s normal split/compact selection.

@bielfreedom

Copy link
Copy Markdown

Correction to my comment above. This PR's base is amd-dev, not main, so my note on 256 commits was wrong: against amd-dev it is one commit. The threshold change I measured is already on amd-dev as 53995420. I reran everything on amd-dev c32c91a, on the same RX 9070 XT, the same way.

53995420 on amd-dev (A/B by reverting it)

  • DXIL: with amd-dev's defaults, 1,616 compute programs are translated (XCL_RT_GATE=hold holds back 1,073). Again only b6101d83892d44a5 changes: plain 611,608 B → compact 171,240 B with switch windows, and 461,036 → 142,872 B with heap windows.
  • Driver, that program alone, switch windows, XCL_RT_GATE=0, 2 interleaved rounds:
amd-dev form pipelines driver time r1 / r2 peak memory
53995420 reverted split, 11 pieces 11 6.6 / 6.3 s 0.57 / 0.58 GB
as is compact, whole 1 6.2 / 6.3 s 1.25 GB

So on amd-dev the compact whole builds about as fast as the 11 pieces. The 1.6× slowdown I reported is main's compact form only. The peak memory still roughly doubles, which matters little at 1.25 GB.

This PR's own commit (960f4fc) on amd-dev: no DXIL byte changes on this native wave64 card, over the 1,616 programs translated by default, as expected for the per-lane path.

AI use: Claude Code (Claude Opus 5.5) built the binaries, ran the measurements and wrote this correction; I posted it.

@relativespace2K

Copy link
Copy Markdown

Tested - retail title on native Windows AMD RDNA2, PR head 960f4fc230fd610b2f64a448801edf9d2d4f7ca4 on amd-dev c32c91a3

Tool: OpenCode with DeepSeek V4.1 Flash 1017

  • AMD Radeon RX 6800 XT (16338 MiB), driver 32.0.21045.29003; Ryzen 5 5600, 31.9 GB;
    Windows 11 IoT Enterprise LTSC 26100; release build; DXC 1.9.2602.17.
  • cargo test --release -p xcl --lib -- gpu::dxil::compact --skip gpu_:
    8 passed, 0 failed, 0 ignored, 0 skipped, 1638 filtered out, including
    per_lane_compute_defers_branch_heavy_program_to_compact_path.
  • Game: retail title 1.0.2.1, two 240 s runs, XCL_PER_LANE=1 XCL_DIRECT_DXIL=1 plus
    XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_FRAME_DUMP=1 XCL_RUN_SECONDS=240, no other XCL_* variables;
    warm shader/pipeline caches; baseline first, PR second.
run presents peak commit local VRAM last present draws skipped driver compiles
amd-dev c32c91a3 1,823 27,043 MB 9,161 MB 105.7 s 5,937 10 / 84 s
PR 960f4fc2 1,779 26,941 MB 9,153 MB 104.2 s 6,736 9 / 75 s

The deferral fires on this title: the PR logs 7 large/branch-heavy compute program: deferring to per-instruction/compact direct DXIL lines between 116 s and 218 s; the baseline logs none.
Both trees then log direct DXIL compact form: 20965 blocks of 672 kinds (baseline 129.9 s,
PR 129.5 s). That is the compact form the report gives for cs 56c0cd3b82a00c6e, so on this
part the baseline already reaches it; the line itself does not name the shader.

Peak commit and presents are unchanged, so the 36+ GiB per-lane spike does not reproduce here:
the largest driver compile is 0.44 MB DXIL on the baseline and 0.36 MB on the PR, against the
2.6 MB DXIL in the report. Under XCL_PER_LANE=1 both trees skip many draws and stop
presenting around 105 s; the title still stalls on its loading screen, so there is no world or
FPS comparison. No crash, 0 failed pipelines, 0 DXIL failures, 0 errors. The baseline's last
frame dump was black (0 non-dark samples) and the PR's was not; both come from the stalled
screen, so I do not treat that as a regression.

Not tested: the standard non-per-lane path (this change only runs under XCL_PER_LANE),
NVIDIA/RDNA4, world/FPS, full workspace, debug build.

AI use: OpenCode with DeepSeek V4.1 Flash 1017 ran the tests, read the logs and wrote this comment; the figures and the deferral/compact lines were checked against the run logs.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants