Skip to content

Shaders: --precompile --processes N builds in N processes - #1502

Draft
tycosnh wants to merge 1 commit into
xcl-dev:mainfrom
tycosnh:shaders-precompile-processes
Draft

tycosnh wants to merge 1 commit into
xcl-dev:mainfrom
tycosnh:shaders-precompile-processes

Conversation

@tycosnh

@tycosnh tycosnh commented Nov 24, 2026

Copy link
Copy Markdown

Requested by Edison · project thread

xcl shaders --precompile --pipelines builds compute pipelines in one process, and NVIDIA's driver builds about one pipeline at a time per process however many threads ask: on an RTX 4090 with 12 pipeline threads, 2 threads were busy and the CPU sat at 28 %. --processes N runs the precompile in N processes of xcl shaders, each taking every N-th record (--shard k/N) and sharing the DXIL and driver-blob caches. On the same 343 compute programs from cold caches, 4 processes took 765 s against 2 060 s for one. Part of #1269.

What is in it

  • crates/xcl/src/shaders.rs: --shard k/n (a process takes records k, k + n, …; the others count as done) and --processes N (starts N children with --shard k/N, gives each its share of the DXC threads and 2 pipeline threads unless XCL_DXC_THREADS / XCL_PIPELINE_THREADS are set, waits, returns the first failing child's exit code). Unit test shards_split_the_records_and_drop_processes.
  • crates/xcl/tests/gpu_compute_e2e.rs: offline_compute_pipelines_split_over_processes: two programs, --processes 2, each child builds one pipeline and the shared cache gets two driver blobs.
  • README.md: the option on the --precompile line.

Tested

  • RTX 4090 (driver 621.24), Ryzen 7 9800X3D, 31 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 MSVC, release.
  • cargo test --release --workspace -- --test-threads=4 at c65e2c8: 722 passed, 1 failed, 21 ignored. The failure is launcher::tests::console_detection (console_imports of the test exe gives None); it fails the same way on main b7aa9f3 here. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • cargo test --release -p xcl --test gpu_compute_e2e offline_compute: 2 passed (the new test and Shaders: save offline compute pipelines to the runtime driver cache #744's).
  • Retail shaders.rpf (26 503 records), --precompile --pipelines --only cs --limit 22500, each run into its own empty XCL_DXIL_CACHE (and --windows 3 / --windows 5 so the driver's own cache could not carry over between the two): one process 343 programs in 2 060 s; --processes 4 the same 343 (86 / 85 / 86 / 86) in 765 s. Driver blobs after 5 / 10 / 20 min: one process 149 / 219 / 231, four 251 / 326 / 336.

Regression run

main:

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: NVIDIA GeForce RTX 4090
title: retail game
seconds: 60
exit: 0x0
frames shown: 1151 (PresentX 1151)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17010 MB

PR:

xcl-smoke v1
commit: c65e2c8b459dd4ac45ff427b3e89abbb5ef707df
gpu: NVIDIA GeForce RTX 4090
title: retail game
seconds: 60
exit: 0x0
frames shown: 1664 (PresentX 1664)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17111 MB

The title run does not reach the changed code (it is the xcl shaders CLI); it is the regression check the rules ask for.

Not tested

  • AMD and Intel GPUs, and Linux / Wine (whether their drivers also build one pipeline at a time per process).
  • The whole pack with --processes: a few programs make the driver's build run for a very long time and grow past tens of GB (one passed 54 GB here without finishing); with several processes at once that needs RAM to spare. Not handled in this PR.

AI use

  • Claude Code with Claude Opus 5.5: wrote the change, the tests and this description, and ran the tests and measurements on the hardware above.

🤖 Generated with Claude Code

NVIDIA's driver builds about one compute pipeline at a time in a process,
however many threads ask: on an RTX 4090 (driver 621.24) --pipelines with 12
pipeline threads kept 2 threads busy at 28 % CPU. Four processes, each with
every fourth record and the shared DXIL and driver-blob caches, made about
3.7x the driver blobs in the same time.

--processes N starts N copies of xcl shaders with --shard k/N (records k,
k + N, ...), gives each its share of the DXC threads and 2 pipeline threads
unless XCL_DXC_THREADS / XCL_PIPELINE_THREADS are set, and returns the first
failing process's exit code.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vitor127wt

Copy link
Copy Markdown

A9 (nv-linux) — Offline PSO parallelism on the RTX 5070 Ti

I tested clean head c65e2c8b459dd4ac45ff427b3e89abbb5ef707df under Wine with eight isolated Series 1.0.2.1 compute records (127,416–251,140 B of DXIL apiece). All modes used the same precompiled DXIL, four memory windows and split wave64. The benchmark ran twice, with the cold-mode order reversed in the second round.

Mode Cold wall time Cold peak cgroup memory Blob-only restore wall time Vulkan reuse on restore
1 process × 1 PSO thread 20.28–20.61 s 0.92–1.03 GiB 1.04–1.06 s 8/8 in both rounds
1 process × 4 PSO threads 8.19–8.23 s 0.94–0.98 GiB 5.15–5.44 s 5/8 and 6/8
4 processes × 1 PSO thread each 9.23–9.36 s 1.70–1.73 GiB 2.20–2.21 s 8/8 in both rounds

All runs made eight pipelines, zero refused. The four-process runs showed four shards and two pipelines made per shard. The cold runs reported zero XCL driver cache hits. The restore runs reported eight hits and retrieved all eight SPIR-V modules from their blobs. With four threads, Vulkan feedback still recorded three recompilations in the first restore and two in the second. I crossed the caches in both directions (serial build → four-thread restore and four-thread build → serial restore). All four crossed runs recorded six Vulkan hits and two recompilations, with eight XCL hits.

I ran xcl shaders <eight records> --precompile --only cs --windows 4 --split 1 --pipelines, adding --processes 4 for the last row. I set XCL_PIPELINE_THREADS to 1, 4, and 1 respectively, and kept XCL_DXC_THREADS=2. Each cold run started with an empty XCL driver subdirectory and a copy of the same DXIL cache. Each restore kept that run’s XCL blobs. XCL_PSO_DISK_CACHE=1, VKD3D_SHADER_CACHE_PATH=0, __GL_SHADER_DISK_CACHE=0, VKD3D_CONFIG=pipeline_library_log; fresh Wine process per run. The DXIL hashes matched across all runs, and each cold/restore pair had eight unchanged blob hashes. Time is whole command wall time. Memory is the peak charge of the Linux cgroup for the command and its workers (8 GiB cap, no swap).

RTX 5070 Ti 16 GB, NVIDIA Linux driver 620.73.04, Ryzen 7 9700X, CachyOS x86-64 7.3.5-2-cachyos, Wine 11.22, vkd3d-proton ec20719452e916b with dxil-spirv 7c04863, Windows DXC 1.9.2609.5, Windows MSVC release cross-build. These results cover the eight-record offline batch.

AI use — Codex (GPT-6 family, exact variant unavailable) built the PR, ran the tests, checked the logs and hashes, and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main in crates/xcl/src/shaders.rs — needs a rebase before it can be tested.

@kole07139

Copy link
Copy Markdown

A full-pack driver pass with --processes, RTX 3070 8 GB / 32 GB RAM: the per-process limits add up across the children, and on 32 GB that ends the pass early. With 3 processes and the three pipelines over 4 MB of DXIL left out, it finishes: 2 686 pipelines in 179 min, 9.6 GB peak.

The goal was the AOT recipe for #1269: precompile every compute pipeline of the retail pack, then run the title on those caches. This comment is about one thing #1502 changes: how much memory the precompile takes when it runs as several processes.

Setup

driver pass children × XCL_PIPELINE_THREADS end time peak commit lowest free commit
6 processes 6 × 2 stopped at the 2 GB floor 4.7 min 15.5 GB 1.9 GB
3 processes 3 × 2 stopped at the 2 GB floor 52.5 min 17.4 GB 1.3 GB
3 processes, pipelines over 4 MB of DXIL skipped ¹ 3 × 2 finished: 895 + 896 + 895 made, 0 refused, 3 skipped 179 min 9.6 GB 9.0 GB

¹ A local patch, not for upstream: an env var makes Pipelines::make return before the build when the DXIL is over N MB. It skipped three pipelines of 5 611 564, 5 780 072 and 5 974 868 B of DXIL.

  • main now has the same idea as XCL_PIPELINE_MAX_KB (from Shaders: size-based admission for big compute driver compiles #1774), with an 8 MiB default.

  • These three are under that default. On this machine, with 3 processes, the pass that finished needed the equivalent of XCL_PIPELINE_MAX_KB=4096.

  • In the 3-process pass that stopped, commit went from 7.4 to 12.0 GB in 10 s at 2 938 s, then climbed to the floor.

  • I do not log the time or memory of each pipeline, so the table shows only that skipping those three let the pass finish. It does not show that they caused the rise.

  • @einfachama's single-process pipelines pass (7149418411, 4 pipeline threads) lists the three largest compute programs at 5.0–5.3 MB and peaked at 13.1 GB. That is consistent with a few multi-MB programs in the driver at once filling a 32 GB machine.

Code reading (c65e2c8, and #1660 at c4a169e)

  • Each child is its own xcl shaders … --shard k/N.
  • So N processes allow:
    • 2 × N driver builds at once, with no check of the system's free commit before a build;
    • N enormous DXC compiles at once.
  • wait_for_memory does read the system's ullAvailPageFile, but each process adds only its own compiles to what it needs.
  • What I am not sure of: whether the parent should share one limit with its children, for example a named semaphore, or check free commit before each driver build. That is the author's call.
  • A smaller option, after the rebase: the children leave the programs over a few MB to a final pass in the parent alone. Shaders: --pipelines makes programs of 4 MB DXIL or more last, by name #1279 already orders them last.
  • D3D12.X: integration branch that reaches the in-world HUD on NVIDIA (reference, not for merge) #2057's XCL_PRECOMPILE_SLICE=i/n runs into the same per-process limit. It ran with 24 processes on a 128 GB machine.

Not tested

AI use: Claude Code (Claude Opus 5.5) ran the passes, read the code and wrote this comment. I checked each point before posting.

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.

5 participants