Repository navigation
Shaders: cap AMD preparation workers at the driver cache's parts - #3602
raylitebull wants to merge 3 commits into
Conversation
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>
|
Test report (not a merge-check: draft, 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>
|
Test report (not a merge-check: draft, 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>
|
Follow-up review (head 920cbaa, since e151a7c, diff read, not a merge-check):
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
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
ID3D12PipelineLibrary1off. AMD's DX12 driver keeps that cache in%LOCALAPPDATA%\AMD\DxcCachein 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 workerxcl.exeprocesses (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 runningxcl.exeprocesses) workers and gives eachworkers / processespipeline threads (rounded down), so the pipeline threads in all stay within the countworkers_forallowed 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 abovegraphics_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()) andapps/victory/src/warm.rs(PROCESSES = 8). No code was ported.What is in it
crates/xcl/src/shaders.rs:driver_cache_splitreads the switch once, with a OnceLock. It only acts whenXCL_PREPARE_WORKERSis unset and the adapter is AMD. It finds the vendor through DXGI the wayPipelines::for_adapterpicks the adapter, because there is no device yet at this point.others_of_this_executablecounts the other processes with this executable's file name from a ToolHelp snapshot.processes_for_driver_cachereturns 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_workersandgraphics_in_workerspass the thread count to their workers asXCL_PIPELINE_THREADSunless the user set it.driver_cache_processes_leave_parts_for_this_and_other_processes, next to theworkers_fortests.README.md: the switch, afterXCL_PREPARE_WORKERS.Known limits
xcl.exeprocesses run, the split gives 1 process. Compute pipelines are then built in the host with its ownpipeline_threads()default, asXCL_PREPARE_WORKERS=1does today; only the graphics worker gets the thread count. The host holds a cache part, so that stays where later runs read it.xcl runlauncher 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.XCL_PREPARE_WORKERS, vendor) reads the environment, a OnceLock, DXGI and ToolHelp, and has no test.processes − 1threads of the budget unused (15 workers → 8 processes × 1 thread). The AMD preparation timing decides whether to hand the remainder out.XCL_PIPELINE_THREADSwins: with the switch on it is used as is in each of the (at most 8) processes, soXCL_PIPELINE_THREADS=1gives 8 builds at once. The log line shows the value that applies.Tested
cargo check --workspace --all-targets --target x86_64-pc-windows-gnu(the project'stypecheckcommand) at e151a7c: finished with no errors and no warnings inshaders.rs.cargo build --workspaceok;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.Not tested
Regression run
(pending:
scripts/smoke.ps1onmain/amd-dev and on this PR's head)AI use