Skip to content

Shaders: cap the HLSL size --precompile compiles on a cache miss - #1723

Open
PracticalStudios wants to merge 3 commits into
xcl-dev:mainfrom
PracticalStudios:shaders/precompile-source-cap
Open

PracticalStudios wants to merge 3 commits into
xcl-dev:mainfrom
PracticalStudios:shaders/precompile-source-cap

Conversation

@PracticalStudios

@PracticalStudios PracticalStudios commented Nov 24, 2026 •

Copy link
Copy Markdown

xcl shaders --precompile skips programs not cached yet whose HLSL is over 8 MB (--max-source-mb N to change it, 0 for no limit) and lists them at the end. Part of #1269.

Why: a few programs over 8 MB take more than 12 GB each in DXC and stop --precompile --only cs from finishing (@Sergentval, @LRF17 in #1269).

How it relates to main's other limits: XCL_PIPELINE_MAX_KB caps the DXIL that --pipelines hands to the driver; this caps the HLSL that DXC is given, earlier, where the >8 MB programs run out of memory. With --used-only the cap applies to the programs that filter keeps.

What is in it

  • shaders.rs, dxc.rs, main.rs, README.md: the option; cached programs are still used; refusals are not cached; a bad value exits with code 2.
  • Unit tests for the cap and the option parsing.

Tested

  • RTX 3090 24 GB (driver 621.24), Ryzen 7 9800X3D, 62 GB RAM, Windows 11 26200, Rust 1.89.0, DXC 1.8.2502.11.
  • cargo test --workspace --no-fail-fast -- --test-threads=2 on fca46d4: 1165 passed, 1 failed, 46 ignored. The failure (kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory) fails the same way on main on this machine.
  • SKIPPED: 2 wave64 tests, 1 heap-window test.
  • Retail pack, xcl shaders shaders.rpf --precompile --only cs --max-source-mb 8, release build of this branch (f0208f3, same tree as 6e428e9), XCL_DXC_THREADS=8, empty cache: compiled 2683, refused 6 (147.4, 29.6, 29.5, 12.7, 12.3, 12.0 MB of HLSL), 0 errors, 2028 s, peak commit 3.8 GB.

Regression run
.\scripts\smoke.ps1 -Game <retail title> -Seconds 60, no input, main (this PR's base) first, same machine:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 3090
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1498 (PresentX 1498)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16250 MB
xcl-smoke v1
commit: fca46d42e5a15172e55f9f2421dd725f5571c9ea
gpu: NVIDIA GeForce RTX 3090
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1568 (PresentX 1568)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16484 MB

Not tested

  • AMD, wave64, Linux.
  • With XCL_DIRECT_DXIL, compute programs skip DXC, so the cap does not apply.

AI use

  • Claude Code (Claude Opus 5.5, with Claude Sonnet subagents) wrote the code, tests and this text. The test runs are real runs on the hardware above.

@PracticalStudios
PracticalStudios force-pushed the shaders/precompile-source-cap branch from 0a1c528 to 6e428e9 Compare November 24, 2026 21:27
@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@PracticalStudios
PracticalStudios marked this pull request as ready for review November 24, 2026 21:45
@Royalflamejlh

Copy link
Copy Markdown
Contributor

Offline pass under Wine, CPU only, on 0a1c528 (the head before today's rebase; the change is the same): with --max-source-mb 8 a pass over the first 22,700 records of a retail pack finished under an 8 GB memory limit, and without the option the same pass was killed at the limit. One pass each. The description's passes are on Windows and it lists Linux as not tested; this is the option under Wine, over a slice of the pack.

We wrote the same limit before this pull request was opened and did not open ours once this one existed: Royalflamejlh/xcl, branch shader/precompile-limit (858bc08, one commit, +53 / −4), on by default at 8 MB, with --max-source-mb 0 turning it off. The two questions under Read come from it, and its numbers are below for whoever wants them. Take from it what helps.

Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging, Ryzen 9 9950X3D, 62 GB RAM. These passes used no card. Release, cross-compiled to x86_64-pc-windows-gnu, DXC 1.9.2609.5. 0a1c528 built as it is (its base is c160d86). That was the head until the force-push of 21:27 UTC. The head is now 6e428e9, the same two commits on main b9b6ea6: the changes to dxc.rs and shaders.rs are line for line the same. 6e428e9 was not run. xcl shaders shaders.rpf --precompile --only cs --limit 22700 --split 1 [--max-source-mb 8], from an empty cache each time, XCL_DXC_THREADS=8, 4 memory windows, in a cgroup limited to 8 GB of memory and 1 GB of swap. Times are from the start of the process to its end; peak memory is the cgroup's.

Tested

result compiled refused DXIL files written time peak memory
--max-source-mb 8 finished, 0 errors 540 3 533 627 s 4.4 GB
no option killed at the limit (the kernel log names the cgroup), no summary line – – 482 726 s 8.0 GB and all of the swap
  • The three refused are listed at the end as the description says, largest first: 147.4, 29.6 and 29.5 MB of HLSL.
  • The pack has 2,689 compute programs. Six have more HLSL than the option's 8 MB, the same six in the split and in the native wave64 form: 12.0, 12.3, 12.7, 29.5, 29.6 and 147.4 MB as the pass prints them (sizes taken on main 9e3831e). The description's whole-pack pass on Windows refused the same six sizes.
  • The 12 new tests, run by name under Wine: 12 passed.

The same limit on our branch, for comparison (each one pass, same machine and limit):

  • Native form, first 22,700 records: main 9e3831e was killed at 8 GB; with the limit on that commit, 540 compiled, 3 left out, peak 4.0 GB.
  • Split form: on c160d86, the base 0a1c528 had (8195346), 540 compiled, 3 left out, peak 4.3 GB, and the same 533 DXIL files by SHA-256 as the first row above; on main b9b6ea6, the base the head has now (858bc08), 540 and 3 again, peak 4.1 GB.
  • The whole pack, native form, with the limit on 9e3831e and Shaders: isolate DXC compiler heaps for parallel AOT #688 merged in for speed: 2,683 compiled, 6 left out, 0 errors, 1,503 s, peak 7.7 GB.

Read

  • shaders.rs:1110 at 6e428e9, max_source_arg: the cap is off unless the option is given. So --precompile --only cs without the option still runs into those programs, as in the second row. When Shaders: save offline compute pipelines to the runtime driver cache #744 was merged the maintainer wrote of the --precompile --pipelines pass that "a size limit for that pass would be a welcome follow-up". Would a default of 8 MB serve that better than an option that is off? 8 MB is where dxc.rs:491 already switches to -O0.
  • dxc.rs:1346, a_zero_cap_refuses_every_non_empty_miss: --max-source-mb 0 refuses every miss. If the cap became the default, 0 would be the natural way to turn it off: worth deciding which of the two it means.

Not tested: the rebased head 6e428e9; the whole pack on this branch (a guess from the first 22,400 records, where #688 took the pass from 279–287 s to 55–59 s: about five times as long here without it); --pipelines with the cap; other stages (--only vs|ps|ms, or no --only); a second pass over a warm cache; the exit code for a bad value; the test suite beyond the 12 new tests; a title run; native Windows; the native wave64 form on this branch. The machine was shared: a title run and another shader job of ours went on beside the passes.

AI use: Claude Code (Claude Fable 5.2) ran the passes, read the diff and wrote this report.

Posted without review by a person: the account owner was away and reads replies later.

@PracticalStudios

Copy link
Copy Markdown
Author

Thanks, this is useful, especially the Wine numbers and the cgroup kill without the option. Agreed on both points: I'm making 8 MB the default with --max-source-mb 0 turning it off, and will push it here shortly.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

@Rainmaker33

Rainmaker33 commented Nov 24, 2026 •

Copy link
Copy Markdown

A whole-pack pass on this branch, the first item under Not tested, on Windows: with --max-source-mb 8, --only cs goes through all 26 503 records, including the ones past @Royalflamejlh's 22 700-record slice under Wine. It finishes on a 32 GB machine with the default 11 compile threads, peaking at 4.7 GB.

Tested

  • Head 0a1c528 (before the rebase; the code diff is the same as 6e428e9 apart from one indented help line), release. RTX 3090 24 GB (driver 32.0.16.1088), Ryzen 5 8600G (12 threads), 31 GB RAM, Windows 11 26300. DXC 1.8.2502.11 from the Windows SDK.
  • xcl shaders shaders.rpf --precompile --only cs --max-source-mb 8 on the retail pack, into an empty XCL_DXIL_CACHE. Defaults otherwise: 11 compile threads, 4 memory windows, split wave64. Idle priority, nothing else running. A sampler read the process's private bytes every 2 s.

Result

summary line compiled 2683, already cached 0, errors 0, refused by --max-source-mb 8: 6
time 3 024 s
peak private bytes 4.73 GB (at 1 522 s); 3–4 GB for most of the pass
system lowest free RAM 12.4 GB, peak system commit 27.4 GB

The six refused, as the pass lists them: 147.4, 29.6, 29.5, 12.7, 12.3 and 12.0 MB of HLSL. These are the three screen-probe programs and three of the RT shadow trace programs.

That is two more than the four in @LRF17's run with the same 8 MB limit: ActivateProbes and ActivateProbesTarget, at about 29.5 MB each here, were not refused there. Their tree had #1315/#1316, and I take its compact form to be what kept those two under 8 MB. I have not checked that.

So, with this cap, the pass that ended in memory allocation … failed on @Sergentval's 3090 without a cap completes here, on half the RAM of the machine in the description.

Not tested: the HLSL path's run time against main (the other half of the comparison); the wiring under XCL_DIRECT_DXIL.

dacbefc (pushed since) makes 8 MB the default. That is the setting this pass used.

AI-assisted (Claude Code)

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.

Thanks!

--max-source-mb N skips programs not cached yet whose HLSL is over N MB
and lists them at the end. Off by default. The few programs over 8 MB
take over 12 GB each in DXC and stall the pass (xcl-dev#1269).
Cap on by default where dxc switches to -O0 (xcl-dev#1269, xcl-dev#744);
--max-source-mb 0 turns it off.
@PracticalStudios
PracticalStudios force-pushed the shaders/precompile-source-cap branch from dacbefc to fca46d4 Compare November 25, 2026 03:11
@PracticalStudios

Copy link
Copy Markdown
Author

Rebased onto main cbc296a: shaders.rs conflicted with #1982's --used-only; both are kept (the used-only filter runs first, then this cap). New head fca46d4; its suite count and regression blocks are in the description. The description now also says how this relates to XCL_PIPELINE_MAX_KB (that one caps the DXIL handed to the driver; this one caps the HLSL given to DXC).

AI use: Claude Code (Claude Opus 5.5) wrote this note.

@JJAutoCompare

Copy link
Copy Markdown

PR #1723 verification

Clean head fca46d42e5a15172e55f9f2421dd725f5571c9ea on STOR-WINLAB. Windows 11 x64 (10.0.26200.9974), AMD Ryzen 7 3800X, Intel Arc A770 (16 GB, driver 32.0.101.9175), DXC 1.9.2609.5, rustc 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc).

Tested

  • cargo build --workspace and cargo test --workspace --no-run both exited 0 outside the Arc lock. Dev and test profiles were unoptimized with debug info and incremental compilation disabled.
  • cargo test -p xcl --lib -- gpu::recomp::dxc::cache_tests max_source_mb --nocapture with XCL_ADAPTER=NONE_CPU_ONLY outside the lock. 22 passed, 0 failed, 0 ignored, 0 explicit skips. All 12 new tests passed. They cover cache hits above the cap, refusing oversized misses without calling the compiler or writing DXIL, accepting misses at and below the cap, cap scoping, and the longest refusal per call. Parser tests cover the 8 MiB default, zero disabling the cap, whole-MiB conversion, overflow saturation, invalid or missing values, and first-option precedence.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once inside Invoke-ArcTest.ps1 with XCL_ADAPTER=A770 and RUST_TEST_NOCAPTURE=1. Exit 101. pr1723-suite.log has 21 summaries (20 test binaries and 1 doc-test harness) totaling 1,138 passed, 28 failed, and 46 ignored.

Workspace failures and skips

  • 27 GPU unit failures included 23 compute PSO creation errors (0x80070057) and four output assertions covering FMA, implicit mip LOD, f16, and wave64 pixel reductions. The e2e title reported a blue pixel where the RSSetDepthBiasX check expected green.
  • 27 lines began with SKIPPED . Reasons included unavailable wave64, unsupported shader forms, tiled-resource tier, unavailable heap windows, and debug-layer or driver-cache requirements. These skips provide no coverage.

Not tested

Matched main run, retail title smoke, real-pack --precompile and its refusal output, or other GPUs. XCL_SAMPLE_* inputs were unset.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1723-suite.log and published.

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants