Repository navigation
d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) - #2233
Conversation
…COMPILE-POOL) With LEONIDA_ASYNC_PIPELINES=1 every demanded build, the compute warm-up and the cache checkpoint ran on one general worker (plus a graphics-only one), so one long driver compile held every pipeline a submission asked for behind it, and their draws and dispatches were skipped meanwhile. PipelineCompiler now runs LEONIDA_COMPILE_THREADS workers (half the logical processors, 2 to 8). A worker takes the most urgent job it may: - demanded builds first, in the order they came, then warm-ups by size, then the checkpoint, which waits until no worker compiles; - large builds (compute over 128 KiB, graphics of 1 MiB or more) and warm-ups together take at most threads-1 workers, so one stays free for a small demanded build; at most LEONIDA_COMPILE_HEAVY_MAX large builds at once (default threads-1, 1 with LEONIDA_SERIAL_BIG_COMPILES=1), compute and graphics alike, each still within the memory gate; - warm-ups run one at a time, and none starts while a demanded build runs: each holds the compile gate for its whole create, and a submission waits for every create in flight; - one build of a PSO at a time, so after_running and the teardown rules hold. LEONIDA_COMPILE_THREADS=1 keeps the layout before the pool. The design is MoonEyes' (ProjectLeonida#2077), ported onto ProjectLeonida#2098's scheduler. Tests: d3d12_compile_pool (CPU, jobs held at gates: settings, a long build does not hold up a small demanded one, heavy count, free worker, warm-ups one at a time and after demanded builds, order, one job per PSO, release/cancel/ stop_for_exit with jobs in flight), and d3d12_compile_teardown also with one worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lixonik
left a comment
There was a problem hiding this comment.
The native Windows build passed d3d12_compile_pool, d3d12_compile_teardown and d3d12_compile_teardown_one_worker. I also checked the optional startup checkpoint with gated jobs in the real scheduler. No retail workload. AI-assisted.
| } | ||
| for (auto it = jobs_.begin(); it != jobs_.end(); ++it) { | ||
| const Job& job = it->second; | ||
| if (it->first == SIZE_MAX) { |
There was a problem hiding this comment.
[P3] Keep the checkpoint's second pressure check aware of running demands. Checkpoint admission is idle-only, but a priority-0 job can start on a second worker during the checkpoint's vkGetPipelineCacheData size query. I reproduced the transition with gated jobs: for the same demand, has_compile_waiter() is true with one worker and false with two once the second worker takes it. The second check in save_session_pipeline_cache then proceeds to the blob read even though the demand is active, which can contend again for the driver cache. Could the checkpoint's post-query check also recognize a running demand? The probe checks scheduling, without measuring driver latency.
There was a problem hiding this comment.
Thanks @lixonik, good catch, and thanks for the gated repro. Fixed in 2d56b68.
has_compile_waiter() now also returns true while a demanded build is running, not only while one is queued. The checkpoint asks it before and after the size query, so the second look now stops before the blob read when a demand started on another worker meanwhile. Only demanded builds needed adding: no warm-up can start in that window, since the running checkpoint is the one speculative job the pool allows.
Test: test_a_checkpoint_sees_a_demand_that_started_during_it in runtime/test/d3d12_compile_pool_test.cpp. Two workers; the checkpoint job checks the first look, then waits at a gate standing in for vkGetPipelineCacheData's size query; a demanded job starts on the second worker; the gate opens and the second look must be true. Before the fix it fails (second_look == 1), after it passes (9 runs of 9). d3d12_compile_teardown (pool and one worker), d3d12_big_compute*, d3d12_m4_compute and d3d12_pipeline_workers* still pass.
With LEONIDA_COMPILE_THREADS=1 the same now also holds for a demanded graphics build on the graphics-only worker, which the old check missed as well.
AI-assisted (Claude Code)
The startup cache checkpoint starts only when no compile worker is busy, but a demanded build can start on another worker while the checkpoint queries the cache size. has_compile_waiter() only looked at the queue, so the check after the size query went on to read the cache blob while that build ran. has_compile_waiter() now also answers true while a demanded build runs. New gated test in d3d12_compile_pool_test: the checkpoint waits at a gate standing in for the size query, a demanded build starts on the second worker, and the second look must see it. It fails without the fix. Reported by lixonik in review of ProjectLeonida#2233. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Test of a83f385 on a world-reaching recipe: RTX 4070 SUPER, NVIDIA 621.01, Windows 11, 64 GB. Counts only. Tree:
AI-assisted (Claude Code). |
|
Test report for this PR at head Setup: RTX 2070 SUPER, NVIDIA 616.56, Windows 11 Pro 26300, MSVC RelWithDebInfo via The cold boots have no session or seed cache and an empty journal. Each also has its own empty
What this shows on this GPU:
So on this machine the pool is safe to merge as it is. The win MoonEyes measured with the gate off comes with a device loss here. I would rather not run with I'm happy to run that follow-up, or a |
|
Correction to my report above, on the device loss with I linked it to the four parallel creates, and that is probably wrong. fiestorra's newest finding in #1608 gives a better explanation. It describes a world-load submission that never completes, a TDR at about 2 s, with no pipeline build anywhere in the run. azsekazvamdimitar avoids it on a 3090 by skipping the ray-hit shading programs. My gated boots never got far enough to hit it: about 700 submissions in 300 s. The ungated one got there: about 24,000 submissions, with the frame rate dropping from 165 s on. So the loss at 249.7 s is most likely the same GPU hang. What made the difference is how far the title got, not the pool. That changes the conclusion. The data does not show that parallel creates are unsafe on this card. The pool still looks safe to merge. Whether the gate can be dropped stays open until the hang is fixed. I'm trying a repeat with |
|
@HasiKe thank you for the thorough cold/warm comparison and the correction. The "warm-ups do not hold the gate" follow-up is up as #2275 (stacked on this PR). With the gate on, a submission now waits only for demanded creates. A warm-up's create does not hold it, but still never enters the driver while a submission is in it or waiting, and at most one warm-up is in the driver at once ( If you can repeat your cold boot on the RTX 2070 SUPER with the gate on, submissions per second while the warm-ups run would show whether it helps, and whether the device stays. CPU tests only on our side so far. AI-assisted (Claude Code) |
|
Code reading of Two builds of one graphics PSO on two workers, and its last Release. With one general worker plus the graphics worker (main's default,
Neither looks at In pool mode this cannot happen:
What the pool still serializes, as I read it. These are by design, and listed so the next reader doesn't have to find them:
So a demanded build can still wait behind a running warm-up of its own PSO, or behind one that holds the large-module budget. Docs:
The code reading was done with a second agent and checked against the source before writing this. AI-assisted (Claude Code, with Antigravity / Gemini 4 Neon). |
… worker With LEONIDA_COMPILE_THREADS=1 (the layout of main: one general worker and the graphics-only one) next_locked did not look at the owner, so two variants of one graphics PSO could build at once, one on each worker. A last Release meanwhile hands the PSO's deletion to the running build it finds first (after_running), and that worker deleted the PSO while the other was still in build() on it. The single-worker selection now skips a job whose PSO has a build running, as the pool already did. New test in d3d12_compile_pool_test: two graphics variants of one PSO with one worker plus the graphics worker; the second must not start while the first runs, another PSO's build still uses the free worker, and a last Release runs after the first build with the second dropped. It fails without the fix. Docs: the heavy count also bounds LEONIDA_SERIAL_BIG_COMPILES=0 on the workers; only compute creates pass the compile gate. Found by qhukz13 in review of ProjectLeonida#2233. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@qhukz13 thank you for the careful reading. The race is real, and Fix: Test:
Without the fix it fails 3 checks (variant 2 starts on the graphics worker). With it, it passes 8 of 8 repeats. After the merge of Docs, both points taken:
Your list of what the pool still serializes matches my reading.
AI-assisted (Claude Code) |
…te-warmup-free Brings ubiquitarianism#2233's one-build-per-PSO fix and current main. Conflicts in docs/d3d12_vulkan.md and d3d12_compile_pool_test.cpp's header, both kept. Also, from qhukz13's review of ubiquitarianism#2275: - test_a_driver_turn_passes_the_speculative_flag_to_the_gate: a DriverTurn made on a speculative job's thread lets a submission pass, and holds it otherwise. It fails when DriverTurn drops the flag. - Docs say what is affected today: compute warm-up creates (graphics builds never pass the gate; the checkpoint makes no create). The LEONIDA_COMPILE_GATE row now describes both 0 and 1. - test_a_checkpoint_sees_a_demand_that_started_during_it waits for the pool to be idle before its last check (it raced the job's removal). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…test's last check The demanded job leaves the running list only after its function returns, so has_compile_waiter() could still see it right after the log said it had finished (1 failure in 10 runs). Found while merging this into ubiquitarianism#2275. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pile-pool # Conflicts: # docs/d3d12_vulkan.md
qhukz13 claimed and fixed the same race for main in ubiquitarianism#2361 (RT-COMPILE-OWNER-RACE). The single-worker branch of next_locked now uses their code line for line, so whichever of the two lands second merges trivially. The pool branch is as before 9b8760d. No behaviour change; d3d12_compile_pool_test passes 5 of 5 repeats. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… doc note Resolve runtime/README.md conflict with ProjectLeonida#2220 (LEONIDA_PIPELINE_ORDER_LOG) and note in docs/d3d12_vulkan.md that LEONIDA_COMPILE_GATE=adaptive and 1 gate graphics creates as well (ProjectLeonida#2412).
|
Reviewed at Verified locally on
Merging. AI-assisted review (Antigravity, Gemini 4 Neon). |
Resolve runtime/README.md conflict after ProjectLeonida#2220 and ProjectLeonida#2233 landed on main.
… for them (RT-PIPELINE-PREWARM-ORDER phase 2) LEONIDA_PIPELINE_PREWARM_ORDER=<file> (or 1 for pipeline_order.log beside the session cache) reads the order log #2220 records. Of the runs recorded on this GPU, the one with the most records is used. When the title creates a PSO whose description key is in it, each recorded graphics or mesh variant is queued on the compile workers (#2233) as a warm-up at priority 1 + rank: after every demanded build, one warm-up at a time, none while a demanded build runs. Records are taken in order up to LEONIDA_PIPELINE_PREWARM_BUDGET_MS of recorded build time (default 300000) and LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES (4096). Compute records are left to the compute warm-up and the offline precompiler. A missing, garbled or other-GPU log is ignored with one message; damaged lines and the E lines a v1 reader does not know are skipped. New CPU test pipeline_prewarm: order kept, budget and entry limit, run choice, a missing or garbled log, E lines, and on the compile workers the recorded order and a demanded build overtaking the prewarms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-warmup-free Main now has ubiquitarianism#2233 (the compile pool) and the adaptive compile gate (ubiquitarianism#2412, ubiquitarianism#2462). The warm-up-free gate is ported onto it: a speculative create is an InDriver entry flagged speculative that submissions do not wait for, at most warmup_max in the driver at once, except one of a kind whose verdict is driver_holds, which is waited for as a demanded create is. submit_mutex_test checks that case too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed in the coordination issue as: RT-ASYNC-COMPILE-POOL (claim; released by MoonEyes after #2077 was closed)
What and why
With
LEONIDA_ASYNC_PIPELINES=1, every demanded build, the compute warm-up and the startup cache checkpoint run onPipelineCompiler's one general worker (plus #2098's graphics-only worker). One long driver compile therefore holds every pipeline a submission asked for behind it, and their draws and dispatches are skipped meanwhile. This ports MoonEyes' worker-pool design from #2077 onto #2098's scheduler (runtime/shims/d3d12_pipeline_compile.h), keeping its lifetime rules (after_running,cancel,running_here,release,stop_for_exit).PipelineCompilernow runsLEONIDA_COMPILE_THREADSworkers (default half the logical processors, 2 to 8). A worker takes the most urgent job it may:LEONIDA_COMPILE_HEAVY_MAXlarge builds at once (default threads-1; 1 withLEONIDA_SERIAL_BIG_COMPILES=1), compute and graphics alike. Each still takes its place at the memory gate (LEONIDA_BIG_COMPILE_BUDGET_MB). Graphics builds are counted by size even whenLEONIDA_SERIAL_BIG_COMPILES=0clearsgraphics_.large, so the async path follows the same knobs for both.runtime/src/vulkan_device_fault.h) makes every submission wait for each create in flight. With the gate on, their boot's submissions waited 142 s in all behind warm-ups of about 800 KB (5-13.5 s each). WithLEONIDA_COMPILE_GATE=0the same boot reached game state 3 at 130 s and ran 240 s with no fault. Running several warm-ups at once would lengthen those waits; so while the title asks for builds, only those builds are started.after_runningand the teardown rules hold as they were.vkGetPipelineCacheDatasize query.has_compile_waiter(), which the checkpoint asks before the query and again after it, now also answers true while a demanded build runs, not only while one is queued, so the checkpoint stops before the blob read. No warm-up can start in that window: the running checkpoint is the one speculative job allowed.LEONIDA_COMPILE_THREADS=1is the layout before the pool: one general worker and the graphics-only one (LEONIDA_GRAPHICS_COMPILE_WORKER), with the old job order.Not changed here, and still open: a submission still waits at the compile gate for every create in flight, including a warm-up already running. The pool shortens how long a demanded build waits behind another build. It does not stop the gate holding the title's thread, which is what ends brandostrong's synchronous runs at the 30 s watchdog. MoonEyes' two ideas (warm-ups not holding the gate; a cap on the wait) touch the gate itself and belong in a separate item.
Synchronous mode (
LEONIDA_ASYNC_PIPELINES=0, the default) and MoonEyes' finding of 10:31 in #1608 (large compute builds one after another, although the driver compiles about 3.7 times faster on 6 threads): there a build a dispatch asks for runs inside the submission, throughPipelineCompiles::build(runtime/src/vulkan_replay.h) and its memory budget, not on these workers. Only the compute warm-up and the checkpoint go throughPipelineCompilerin that mode, and warm-ups stay one at a time. So this pull request does not change that case; letting more large builds run at once there is a change toPipelineCompiles(or to the warm-up's one-at-a-time rule, which the compile-gate finding above argues against while the title submits) and belongs in its own item.A note on azsekazvamdimitar's report (#1608, 06:42) that graphics jobs of 1 MiB or more are always serial in
PipelineCompiles. On currentmain,graphics_.largeis false withLEONIDA_SERIAL_BIG_COMPILES=0, and otherwise the large ones share the memory budget. The serial builds they saw in the asynchronous path came from the single graphics worker, which this pool replaces.One build per PSO with
LEONIDA_COMPILE_THREADS=1(the general worker plus the graphics-only one): two variants of one graphics PSO could build at once there, one on each worker, and a last Release then deleted the PSO under the second (found by qhukz13). This is the same race qhukz13 claimed as RT-COMPILE-OWNER-RACE and fixes formainin #2361, which I missed. The single-worker branch ofnext_lockedhere now uses #2361's code line for line, so whichever of the two lands second merges trivially; if #2361 lands first, this pull request takes its version.Tested
New CPU test
d3d12_compile_pool(no device). Its jobs wait at gates the test opens, so each rule is checked while the jobs it is about are still running. It covers:release,cancelandstop_for_exitwith jobs running and queued.It passed 8 runs out of 8. Each rule was broken by hand in turn (7 mutants, before the checkpoint fix: checkpoint-when-idle, one job per PSO, the free worker, the heavy count, one warm-up, warm-ups behind demanded builds, waking idle workers), and the test failed for every one.
d3d12_compile_teardownruns with the pool, and as newd3d12_compile_teardown_one_workerwithLEONIDA_COMPILE_THREADS=1. Both pass, as dod3d12_big_compute(all 7 settings),d3d12_m4_compute,big_compile_gate,compile_helper,replay_pipeline_compiles*,pipeline_workersandd3d12_pipeline_workers*.Full runtime CTest,
-j 4(a boot was running on this machine). Everything passes except four:xs_proxy_mockandd3d12_multithreadfailed under that load and pass when rerun alone;xbox_present(presentVkResult -11) andd3d12_set_descriptor_heaps(line 353) fail the same way onupstream/maina73a57e without this change.python -I tests/test_docs_env_vars.py,test_ctest_registration.py,test_docs_repo_paths.py,test_text_write_line_endings.py,scripts/check_no_game_data.pyon the changed files: pass.Test-merged with the open PRs on the same code: runtime: verify offline compute pipeline journal hits (RT-NATIVE-COMPUTE-WARMUP) #2198, runtime: record the order of first pipeline requests (LEONIDA_PIPELINE_ORDER_LOG=1, RT-PIPELINE-PREWARM-ORDER phase 1) #2220 and make_game: harden crash reporting, WINE resolution, and vulkaninfo probing #2208 merge cleanly. d3d12: finish CompileActivity before checkpointing and retry deferred cache snapshots #1756 conflicts in
d3d12_vulkan_device.cpp, but it already conflicts withmainby itself. It also moves the checkpoint to priority 1, so whichever lands second must keep "checkpoint only when idle" keyed on the checkpoint, not onSIZE_MAX.No real boot was run with this change; the boot session will test it.
GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly.docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code