Skip to content

Shaders: cap AMD preparation workers at the driver cache's parts - #3602

Draft
raylitebull wants to merge 3 commits into
amd-devfrom
capy/cap-amd-preparation-workers
Draft

raylitebull wants to merge 3 commits into
amd-devfrom
capy/cap-amd-preparation-workers

Conversation

@raylitebull

@raylitebull raylitebull commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

On AMD, XCL relies on the driver's own shader cache: its own driver-blob cache is off for vendor 0x1002 and amd-dev f33df5a turned ID3D12PipelineLibrary1 off. AMD's DX12 driver keeps that cache in %LOCALAPPDATA%\AMD\DxcCache in 10 parts per executable file name. Each process takes the first free part and keeps it, and a further process of the same executable gets a private cache that no later run reads. Shader preparation starts about cores − 4 worker xcl.exe processes (28 on a 32-thread CPU) with one pipeline thread each, so most of them compile into caches the title never reads. ReVIctory measured this on an RX 9070 XT (driver 32.0.32029.x): a 21-process warm left 4.5 GB in unread caches, and 20 of 117 slow pipelines were compiled again at run time (0.2–3.9 s each).

With XCL_PREPARE_DRIVER_CACHE=1 (off by default) and an AMD adapter, preparation starts at most min(8, 9 − other running xcl.exe processes) workers and gives each workers / processes pipeline threads (rounded down), so the pipeline threads in all stay within the count workers_for allowed for RAM and commit (28 workers: 8 processes × 3 threads). With the switch off, nothing changes.

Whether that keeps the same number of driver builds at once is not known. The comments at shaders.rs ~3390 and above graphics_in_workers (f383079) say the driver builds "about two pipelines at a time for one process". If that holds on AMD, 8 processes build about 16 pipelines at once where 28 processes built 28, so preparation may take longer in exchange for compiles that land in the cache later runs read. The AMD run decides it: preparation time and run-time slow compiles with the switch on and off.

The idea comes from ReVIctory (https://github.com/ReTerryDavis/ReVIctory, GPL-3.0-or-later, compatible since #3002): crates/victory-gpu/src/pipeline/known.rs (DRIVER_CACHE_PARTS, others_of_this_executable()) and apps/victory/src/warm.rs (PROCESSES = 8). No code was ported.

What is in it

  • crates/xcl/src/shaders.rs:
    • driver_cache_split reads the switch once, with a OnceLock. It only acts when XCL_PREPARE_WORKERS is unset and the adapter is AMD. It finds the vendor through DXGI the way Pipelines::for_adapter picks the adapter, because there is no device yet at this point.
    • others_of_this_executable counts the other processes with this executable's file name from a ToolHelp snapshot.
    • The pure policy function processes_for_driver_cache returns the process count and the threads per process, rounded down so the total never exceeds the worker budget. The split is logged once.
    • pipelines_in_workers and graphics_in_workers pass the thread count to their workers as XCL_PIPELINE_THREADS unless the user set it.
    • Unit test driver_cache_processes_leave_parts_for_this_and_other_processes, next to the workers_for tests.
  • README.md: the switch, after XCL_PREPARE_WORKERS.

Known limits

  • When 8 or more other xcl.exe processes run, the split gives 1 process. Compute pipelines are then built in the host with its own pipeline_threads() default, as XCL_PREPARE_WORKERS=1 does today; only the graphics worker gets the thread count. The host holds a cache part, so that stays where later runs read it.
  • The xcl run launcher is counted as another process. Its preflight creates a D3D12 device, but the driver appears to open its cache at a process's first pipeline, so the launcher probably holds no part and the cap is one process lower than needed while another copy of XCL runs. That errs on the safe side.
  • Only the pure split is unit-tested. The gating (switch, XCL_PREPARE_WORKERS, vendor) reads the environment, a OnceLock, DXGI and ToolHelp, and has no test.
  • Rounding the threads per process down can leave up to processes − 1 threads of the budget unused (15 workers → 8 processes × 1 thread). The AMD preparation timing decides whether to hand the remainder out.
  • A user-set XCL_PIPELINE_THREADS wins: with the switch on it is used as is in each of the (at most 8) processes, so XCL_PIPELINE_THREADS=1 gives 8 builds at once. The log line shows the value that applies.

Tested

  • Linux, cargo check --workspace --all-targets --target x86_64-pc-windows-gnu (the project's typecheck command) at e151a7c: finished with no errors and no warnings in shaders.rs.
  • CI "Build and test (Windows, no GPU)" passed at 49d6b34.
  • Foniass's run (his report, not mine), RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300, at 49d6b34 merged onto amd-dev 41aa60c: cargo build --workspace ok; cargo test --workspace --no-fail-fast -- --test-threads=4: 2962 passed, 9 failed, 49 ignored, 28 SKIPPED. The same tests fail on amd-dev alone on that card. The switch only acts on AMD adapters, so it did not run there. That run predates the round-down commit e151a7c.
  • Foniass's second run (his report), same hardware, at e151a7c merged onto amd-dev 41aa60c: build ok; 2962 passed, 9 failed, 49 ignored, 28 SKIPPED, the same 9 failures as on amd-dev alone; the updated split test passes. The switch did not run on that card.

Not tested

  • Not built for Windows (MSVC) by me, and I did not run the unit tests; Windows CI runs them on this PR.
  • Not run in a game or on AMD hardware, so it is unmeasured. The smoke blocks under Regression run follow after a Windows run.

Regression run
(pending: scripts/smoke.ps1 on main/amd-dev and on this PR's head)

AI use

Open in Capy

AMD's DX12 driver keeps its shader cache in %LOCALAPPDATA%\AMD\DxcCache
in 10 parts per executable file name. Each process takes the first free
part and keeps it; a further process of the same executable gets a
private cache that no later run reads. On AMD XCL relies on exactly
this cache (its own driver-blob cache is off for vendor 0x1002 and
amd-dev f33df5a turned ID3D12PipelineLibrary1 off), yet shader
preparation starts about cores - 4 worker xcl.exe processes (28 on a
32-thread CPU), each with one pipeline thread, so most of what they
compile is compiled again at run time. ReVIctory measured on an
RX 9070 XT (driver 32.0.32029.x) that a 21-process warm left 4.5 GB in
such unread caches and 20 of 117 slow pipelines were compiled again at
run time (0.2-3.9 s each).

With XCL_PREPARE_DRIVER_CACHE=1 (off by default) and an AMD adapter,
preparation starts at most min(8, 9 - other running processes of this
executable) worker processes and gives each enough pipeline threads
(XCL_PIPELINE_THREADS) to keep about the same parallelism in all.
XCL_PREPARE_WORKERS and XCL_PIPELINE_THREADS still win when set. The
split is logged once. Not yet measured on AMD hardware.

Idea from ReVIctory (GPL-3.0-or-later), crates/victory-gpu/src/
pipeline/known.rs (DRIVER_CACHE_PARTS, others_of_this_executable) and
apps/victory/src/warm.rs (PROCESSES = 8).

Assisted-by: Capy (Claude Opus 5.5)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added area:docs-ci Documentation, scripts, workflows, repo governance area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60c
head: 49d6b34
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2962 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60c alone on this card, so none is from this PR)
review: read the whole diff (+97/-6) against amd-dev. With XCL_PREPARE_DRIVER_CACHE=1 on an AMD adapter, the PR starts at most min(8, 9 − other xcl.exe processes) preparation workers and raises each worker's XCL_PIPELINE_THREADS so the total stays about the same; README documents the switch. Findings: (1) The parallelism premise contradicts the existing code note. The comments at shaders.rs ~3389 ("the driver builds about two pipelines at a time for one process, whatever the processors") and in the doc above graphics_in_workers say one process gets about 2 driver builds at once. If that holds, 8 processes with 4 threads each give about 16 builds at once instead of the 28 processes they replace, so the switch could make preparation slower. The description's "keep about the same parallelism" is unmeasured (no AMD run). (2) div_ceil goes over the memory-limited worker count. In processes_for_driver_cache (~3532), processes × threads can be up to processes − 1 above workers. For example, workers=9 becomes 8×2 = 16 builds at once and 28 becomes 32. When workers_for lowered the count for RAM or commit (2 GB / 3 GB per worker; the most comment says the biggest pipeline takes about 1.5 GB in the driver), this almost doubles the concurrent builds the budget allowed. The test asserts that this overshoot is accepted (processes * (threads - 1) < workers). (3) With one process, the thread count is not used for compute. When 8 or more other xcl.exe processes run, processes becomes 1. The workers > 1 && Input::Pack gate (~3391) then builds the pack in-process through precompile(..., None, ...), so the computed threads (the test's (12, 8) -> (1, 12)) never reach the compute pipelines. The host's own pipeline_threads() default applies instead. Only the graphics worker gets them. (4) The process count includes the launcher. Preparation runs in the host that spawn_host (launcher.rs ~460) starts from the same executable, so others_of_this_executable always counts the xcl run launcher. If the launcher never creates a D3D12 device (unverified), the cap drops one part early whenever another copy of XCL runs. (5) Only the pure split function is tested. Nothing tests the gating in driver_cache_split (the switch, XCL_PREPARE_WORKERS, the vendor), the XCL_PIPELINE_THREADS passed to compute and graphics workers, or the process count. The description says it was only typechecked with the GNU target on Linux, with no MSVC build, test run or smoke blocks. (6) A user-set XCL_PIPELINE_THREADS lowers the total. When it is set, the process count is still capped at 8 but the threads per process stay at the user's value, so XCL_PIPELINE_THREADS=1 quietly cuts 28 builds at once to 8. Only the log line shows it. Fine: with the switch off the default path is unchanged (the check returns before any DXGI or ToolHelp call, and threads=1 means no env is set). Non-AMD and WARP adapters and a set XCL_PREPARE_WORKERS return the unchanged values. adapter_vendor picks the adapter the way Pipelines::for_adapter does. The ToolHelp loop sets dwSize, closes the snapshot, skips itself and compares names case-insensitively. The later c.env correctly overrides the default "1" from worker_command, and the windows-sys ToolHelp feature is already enabled. The amd-dev claims match the code: f33df5a turns off ID3D12PipelineLibrary1 on AMD, and the driver-blob cache is off for vendor 0x1002. The size and scope fit one change.
performance: no smoke run. The switch only acts on AMD adapters, so a smoke run here wouldn't reach it.
assessment: merges cleanly into amd-dev, builds, and adds no test failure (the failing ones fail on amd-dev alone on this NVIDIA card); the new split test passes. The switch only acts on AMD adapters, so this NVIDIA run can't show the effect; the review findings stand, mainly whether 8 processes give fewer builds at once than the 28 they replace, and the thread count going over the memory-limited worker count
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

processes_for_driver_cache rounded the pipeline threads per process up,
so the processes times their threads could exceed the worker count
workers_for had already capped for RAM and commit (9 workers became
8 processes of 2 threads, 16 builds at once). Round down instead: the
total never exceeds that budget (28 workers: 8 x 3 = 24).

Found in Foniass's review of #3602.

Assisted-by: Capy (Claude Opus 5.5)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: draft, PR description red; merged onto amd-dev, the PR's base)
base: 41aa60c
head: e151a7c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2962 passed, 9 failed, 49 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60c alone on this card, so none is from this PR)
review: follow-up on e151a7c (+9/-8 since 49d6b34, the head of my test report above). The commit changes processes_for_driver_cache (shaders.rs ~3534) from workers.div_ceil(processes) to (workers / processes).max(1), so processes × threads is now at most workers, and rewrites the doc and test to match (~4841: 28 -> (8,3), 21 -> (8,2), new 9 -> (8,1); the loop now asserts processes*threads <= workers && processes*(threads+1) > workers). (1) Still open, and slightly worse: the comments at ~3389 and above exact_graphics_records (~3700) still say the driver builds about two pipelines at a time per process, so 8 processes probably give about 16 builds at once instead of the 28 they replace, and the PR now asks for 24 (28 workers) or 16 (21 workers); nothing is measured. (2) Fixed: floor division can no longer go above the RAM/commit budget, and the test now checks the total stays within workers. (3) Still open: with one process (others >= 8, or workers = 1), the workers > 1 && Input::Pack gate (~3391) still builds compute in-process through precompile(..., None, ...), so the computed threads (e.g. (1,12) for 12 workers) never reach compute; only graphics gets them (~3855). (4) Still open: others_of_this_executable (~3551) still counts any xcl.exe, including the xcl run launcher, so the usual launch can lose a cache part. (5) Still open: only the pure split is tested; driver_cache_split, the vendor check and the env handoff at ~3598 / ~3855 are not. (6) Still open: with XCL_PIPELINE_THREADS set, the children keep the user's value (~3598, ~3855) while the process count is still cut to <= 8, so XCL_PIPELINE_THREADS=1 lowers the total from 28 to 8 with only the log line at ~3526. New: (7) Flooring throws away up to processes − 1 of the budget. For 9-15 workers the split is always 8×1, so 15 workers give 8 builds at once (about 47 % fewer); not a correctness bug, but an unmeasured throughput loss with the switch on, and the doc ("as many pipelines at once in all as the workers asked for, never more", ~4836) overstates the "as many" half. Fine: no zero is possible (prepare_workers clamps to >= 1 and processes <= workers, so workers / processes >= 1), and with threads == 1 the children still get XCL_PIPELINE_THREADS=1 from worker_command (~3629).
performance: no smoke run. The switch only acts on AMD adapters, so a smoke run here wouldn't reach it.
assessment: on the new head, merges cleanly into amd-dev, builds, adds no test failure and the updated split test passes. Finding (2) is fixed; (1) and (3)-(6) are still open, and flooring now leaves part of the budget unused (7). The switch only acts on AMD adapters, so this NVIDIA run can't show its effect
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

Since the threads per process are rounded down, the split can leave up
to processes - 1 threads of the budget unused (15 workers: 8 x 1); the
test's doc claimed it gives as many pipelines at once as the workers.

Assisted-by: Capy (Claude Opus 5.5)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review (head 920cbaa, since e151a7c, diff read, not a merge-check):

  • The new commit only rewords the test's doc comment (shaders.rs ~4838: "no more pipelines at once in all than the workers asked for"), which answers the doc half of (7) in my report above. No code or assertion changed, so the run on e151a7c still stands for this head, and (1), (3)-(6) and the budget left unused by flooring (7) are still open.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

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

Labels

area:docs-ci Documentation, scripts, workflows, repo governance area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants