d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2233
Open
github-bot
wants to merge 2 commits from
github-bot/gh-2233 into main
AGit
pull from: github-bot/gh-2233
merge into: github:main
github:main
github:docs/animation-merge-remnants
github:docs/story-dedup-and-cli
github:docs/restofworld-merge-remnants
github:docs/gamedata-dedup-tables
github:docs/textures-bcpack-tables-and-cli
github:docs/exe-fail-fast-shims-sync
github:fix/address-guard-wraparound-parity
github:fix/cvt-f16-denorm-and-clamp
github:docs/pso-cache-scope-note
github:docs/viewer-readme
github:docs/textures-arrays-dds-preview
github:docs/conformance-readme-status
github:fix/docs-validators-fences-urls
github:claude/loop-total
github:claude/pops-collision-seed
github:claude/dstorage-hold-page-reads
github:claude/host-image-copy-switch
github:feat/gdk-lifecycle-window-hook
github:claude/d16s8-uav-nvidia-fallback
github:feat/mfplat-offline-shim
github:claude/gameinput-slow-reader
github:fix/rt-null-barrier-clear
github:claude/depth-resolve-sample-positions
github:integration/palmetto-parity
github:claude/valu-literal-sext
github:claude/slot74-pool-handle
github:claude/rgb9e5-uint-alias-view
github:claude/fssm-root-layout-tables
github:feat/gdk-speech-display-lifecycle
github:asset-audio-skip-current
github:qemmhd/old-9940-rectangle-quad-lists
github:feat/ws2-offline-shim
github:qemmhd/rt-d16-unorm-uav
github:feat/xs-device-stops-7-9
github:qemmhd/rt-depth-same-base-shapes
github:qemmhd/rt-lazy-attachment-variant
github:feat/acphal-xma2-decoder
github:asset-audio-skip
github:codex/coord-claim-check-20261124-7e48
github:feat/xs-frame-pacing-presentx
github:feat/xs-device-vm-options
github:old-pr/9844
github:old-pr/9978
github:old-pr/9815
github:old-pr/10057
github:old-pr/9874
github:old-pr/9965
github:old-pr/9863
github:old-pr/10068
github:old-pr/10066
github:old-pr/10067
github:old-pr/10007
github:old-pr/10061
github:old-pr/10065
github:old-pr/10059
github:old-pr/10063
github:old-pr/10055
github:old-pr/10062
github:old-pr/10042
github:old-pr/10041
github:old-pr/10049
github:old-pr/10047
github:old-pr/10046
github:old-pr/10045
github:old-pr/10056
github:old-pr/10043
github:old-pr/10036
github:old-pr/10034
github:old-pr/9984
github:old-pr/10052
github:old-pr/10038
github:old-pr/10033
github:old-pr/10028
github:old-pr/10050
github:old-pr/9891
github:old-pr/9889
github:old-pr/10051
github:old-pr/10019
github:old-pr/10027
github:old-pr/10029
github:old-pr/10031
github:old-pr/10026
github:old-pr/9941
github:old-pr/10030
github:old-pr/10040
github:old-pr/9990
github:old-pr/10021
github:old-pr/9962
github:old-pr/10022
github:old-pr/10020
github:old-pr/10015
github:old-pr/10025
github:old-pr/9886
github:old-pr/10048
github:old-pr/10014
github:old-pr/10011
github:old-pr/9861
github:old-pr/10010
github:old-pr/10008
github:old-pr/9860
github:old-pr/10006
github:old-pr/9920
github:old-pr/9995
github:old-pr/10000
github:old-pr/10016
github:old-pr/10004
github:old-pr/10023
github:old-pr/9982
github:old-pr/9981
github:old-pr/9983
github:old-pr/9970
github:old-pr/9969
github:old-pr/9968
github:old-pr/9971
github:old-pr/9972
github:old-pr/9942
github:old-pr/9963
github:old-pr/9960
github:old-pr/9964
github:old-pr/9985
github:old-pr/9973
github:old-pr/9862
github:old-pr/9953
github:old-pr/10017
github:old-pr/9952
github:old-pr/9955
github:old-pr/9946
github:old-pr/9954
github:old-pr/9938
github:old-pr/9956
github:old-pr/9856
github:old-pr/9947
github:old-pr/9924
github:old-pr/9961
github:old-pr/9927
github:old-pr/9979
github:old-pr/10032
github:old-pr/9926
github:old-pr/5237
github:old-pr/9951
github:old-pr/9931
github:old-pr/9902
github:old-pr/9921
github:old-pr/9994
github:old-pr/9775
github:old-pr/9768
github:old-pr/9905
github:old-pr/9936
github:old-pr/9901
github:old-pr/9904
github:old-pr/9906
github:old-pr/9988
github:old-pr/9908
github:old-pr/9909
github:old-pr/9911
github:old-pr/9912
github:old-pr/9913
github:old-pr/9887
github:old-pr/9916
github:old-pr/9919
github:old-pr/9925
github:old-pr/9933
github:old-pr/9935
github:old-pr/9918
github:old-pr/9879
github:old-pr/9880
github:old-pr/9881
github:old-pr/9996
github:old-pr/9876
github:old-pr/9892
github:old-pr/9899
github:old-pr/9915
github:old-pr/9914
github:old-pr/9872
github:old-pr/9869
github:old-pr/9866
github:old-pr/9819
github:old-pr/10012
github:old-pr/9857
github:old-pr/9893
github:old-pr/9897
github:old-pr/9928
github:old-pr/9868
github:old-pr/9917
github:old-pr/9940
github:old-pr/9873
github:old-pr/9816
github:old-pr/10009
github:old-pr/9900
github:old-pr/9966
github:old-pr/9859
github:old-pr/9843
github:old-pr/9991
github:old-pr/10058
github:old-pr/9883
github:old-pr/9838
github:old-pr/9835
github:old-pr/9959
github:old-pr/9895
github:old-pr/9837
github:old-pr/9858
github:old-pr/9865
github:old-pr/9864
github:old-pr/9840
github:old-pr/9820
github:old-pr/4669
github:old-pr/9848
github:old-pr/9850
github:old-pr/9810
github:old-pr/9799
github:old-pr/9853
github:old-pr/9875
github:old-pr/9831
github:old-pr/9796
github:old-pr/9801
github:old-pr/9813
github:old-pr/9794
github:old-pr/7417
github:old-pr/9781
github:old-pr/9806
github:old-pr/9958
github:old-pr/9809
github:old-pr/9791
github:old-pr/9792
github:old-pr/10053
github:old-pr/9784
github:old-pr/9789
github:old-pr/9849
github:old-pr/9846
github:old-pr/9773
github:old-pr/9785
github:old-pr/9803
github:old-pr/9826
github:old-pr/9839
github:old-pr/9922
github:old-pr/9948
github:old-pr/7189
github:old-pr/9957
github:old-pr/9823
github:old-pr/9807
github:old-pr/9851
github:old-pr/9774
github:old-pr/9830
github:old-pr/9836
github:old-pr/9822
github:old-pr/9783
github:old-pr/9833
github:old-pr/9890
github:old-pr/9770
github:old-pr/9769
github:old-pr/9772
github:old-pr/9787
github:old-pr/9852
github:old-pr/9834
github:old-pr/9845
github:old-pr/9871
github:old-pr/9771
github:old-pr/9776
github:old-pr/10005
github:old-pr/9949
github:old-pr/9923
github:old-pr/9805
github:old-pr/9829
github:old-pr/9790
github:old-pr/9827
github:old-pr/9929
github:old-pr/9855
github:old-pr/9934
github:old-pr/9907
github:old-pr/9910
github:old-pr/9779
github:old-pr/9780
github:old-pr/9885
github:old-pr/9882
github:old-pr/9877
github:old-pr/9998
github:old-pr/4251
github:old-pr/9987
github:old-pr/9989
github:old-pr/9950
github:old-pr/9777
github:old-pr/10044
github:old-pr/9884
github:old-pr/2906
github:old-pr/5076
github:old-pr/9937
github:old-pr/9986
github:old-pr/3014
github:old-pr/9943
github:old-pr/9939
github:old-pr/4682
github:old-pr/4765
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
bug
Something isn't working
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
question
Further information is requested
wontfix
This will not be worked on
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2233
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2233"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Tyrannys on GitHub · 2026-11-26 09:21 UTC · original
Tyrannys:claude/rt-async-compile-pool→main· +710 −44 · 6 files · 2 commits · openClaimed 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.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/maina73a57e13without 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: #2198, #2220 and #2208 merge cleanly. #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: NVIDIA GeForce RTX 4070 SUPER, 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
@lixonik on GitHub · 2026-11-26 10:37 UTC · original · reviewed
The native Windows build passed
d3d12_compile_pool,d3d12_compile_teardownandd3d12_compile_teardown_one_worker. I also checked the optional startup checkpoint with gated jobs in the real scheduler. No retail workload. AI-assisted.@ -426,0 +541,4 @@}for (auto it = jobs_.begin(); it != jobs_.end(); ++it) {const Job& job = it->second;if (it->first == SIZE_MAX) {@lixonik on GitHub · 2026-11-26 10:37 UTC · original
[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
vkGetPipelineCacheDatasize 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 insave_session_pipeline_cachethen 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.@ -426,0 +541,4 @@}for (auto it = jobs_.begin(); it != jobs_.end(); ++it) {const Job& job = it->second;if (it->first == SIZE_MAX) {@Tyrannys on GitHub · 2026-11-26 10:53 UTC · original
Thanks @lixonik, good catch, and thanks for the gated repro. Fixed in
2d56b685a.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_itinruntime/test/d3d12_compile_pool_test.cpp. Two workers; the checkpoint job checks the first look, then waits at a gate standing in forvkGetPipelineCacheData'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_computeandd3d12_pipeline_workers*still pass.With
LEONIDA_COMPILE_THREADS=1the 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)
@Tyrannys on GitHub · 2026-11-26 10:57 UTC · original
Test of
a83f38508on a world-reaching recipe: RTX 4070 SUPER, NVIDIA 621.01, Windows 11, 64 GB. Counts only.Tree:
maina73a57e13+ #1851 #1905 #1957 #1886 #1894 #1914 #1882 #2195 #2113 #1592 #2097. The pool runs add this PR (clean merge).d3d12_compile_pool_test: PASS.Recipe (as in my #1608 comment of 09:00):
LEONIDA_COMPILE_GATE=0, a local skip list of the 724 library compute programs of 2 MiB or more,LEONIDA_RT_AS=off,LEONIDA_DEVICE_FAULT=0, the watchdog kicked,LEONIDA_COMPILE_WORKERS=6, warm offline and heavy caches, 1,800 s, the same 21-press script.LEONIDA_COMPILE_THREADSleft at its default.AI-assisted (Claude Code).
@HasiKe on GitHub · 2026-11-26 11:37 UTC · original
Test report for this PR at head
2d56b685a. I merged it locally onmaina73a57e13together with #2195, becausemainalone aborts at startup on this machine. AI-assisted (Claude Code).Setup: RTX 2070 SUPER, NVIDIA 616.56, Windows 11 Pro 26300, MSVC RelWithDebInfo via
scripts/build_runtime.ps1 -FetchSdl3, my own 1.0.2.1 package. Every boot ran 300 s withLEONIDA_ASYNC_PIPELINES=1, the keyboard pad,LEONIDA_TITLE_WATCHDOG=0with the kick RVAs,LEONIDA_CONSOLE_FIX_US=0and 4096 MB title windows and arena.d3d12_compile_pool_testpasses.The cold boots have no session or seed cache and an empty journal. Each also has its own empty
__GL_SHADER_DISK_CACHE_PATH, so the driver cache does not warm the second run.main+#2195main+#2195LEONIDA_COMPILE_GATE=0What this shows on this GPU:
submit-handofflines andwait 0.00in the submit phases. So that cause is my reading, not a measurement.LEONIDA_COMPILE_GATE=0the title moves on to about 200 submissions/s and 100 frames/s from 65 s on. It then demands 98 builds, and the pool runs them in parallel: 49 dispatch, up to 30.7 s each; 49 draw, up to 16.8 s each. At 249.7 s the device is lost.vkGetSemaphoreCounterValuereturnsVK_ERROR_DEVICE_LOST, andnvlddmkmlogs event 153 (TDR) in the same minute. Right before the loss, fourdraw-workercreates were in flight on four threads while the title kept submitting. This is the case the gate was added for, and it matches the device losses fiestorra reports in #1608 on an RTX 4090. One boot only, so it is not proof that parallel creates cause the TDR.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
LEONIDA_COMPILE_GATE=0until the "warm-ups do not hold the gate" follow-up exists. That follow-up looks like the change that would actually let a cold boot get going.I'm happy to run that follow-up, or a
LEONIDA_COMPILE_THREADS/LEONIDA_COMPILE_HEAVY_MAXsweep with the gate off, on this card. Logs stay local: they name game shaders.@HasiKe on GitHub · 2026-11-26 11:47 UTC · original
Correction to my report above, on the device loss with
LEONIDA_COMPILE_GATE=0. AI-assisted (Claude Code).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
LEONIDA_DEVICE_FAULT=2next, to see whether NVIDIA's checkpoints name the submission and pipeline. I'll post the result in #1608.@Tyrannys on GitHub · 2026-11-26 12:06 UTC · original
@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 (
LEONIDA_COMPILE_GATE_WARMUP_MAX, default 1).LEONIDA_COMPILE_GATE_WARMUPS=1gives the old behaviour for an A/B;LEONIDA_COMPILE_GATE=0is unchanged.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)
@qhukz13 on GitHub · 2026-11-26 14:29 UTC · original
Code reading of
2d56b685a(no build here yet). One finding I think matters beyond this PR: the pool closes a race thatmainhas by default, but theLEONIDA_COMPILE_THREADS=1fallback keeps it.Two builds of one graphics PSO on two workers, and its last Release. With one general worker plus the graphics worker (main's default,
LEONIDA_GRAPHICS_COMPILE_WORKERon),next_lockeddoes this:jobs_.begin(), which can be a graphics job;Neither looks at
owner(d3d12_pipeline_compile.h:531-534here, the same lines on main). So two variants of one graphics PSO can be built at once, one on each worker. If the title releases that PSO meanwhile,PipelineState::last_releasecallsafter_running(compile_owner(), [this] { delete this; ... }).after_runningattaches the deletion to the firstRunningentry of that owner and returns (d3d12_pipeline_compile.h:387-399). That worker deletes the PSO as soon as its own job returns. The other worker is still insidebuild()on the same object, or waiting on itsvariants_mutex_.In pool mode this cannot happen:
next_lockedskips any job whose owner already has a running job (548-549). WithLEONIDA_COMPILE_THREADS=1the old selection, and the race with it, come back. Either of these would remove it:after_runningattachinglastto the last running job of the owner instead of the first.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:
threads - 1workers, so one stays free for small demanded builds;variants_mutex_, the large-module memory budget, andDriverTurn/CompileTurnfor compute.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:
runtime/README.md:331saysLEONIDA_SERIAL_BIG_COMPILES=0lets all large compiles run side by side. The pool still caps them atLEONIDA_COMPILE_HEAVY_MAX(d3d12_pipeline_compile.h:551).DriverTurn; graphicsbuild()does not.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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.