d3d12: a pool of workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2077
Closed
github-bot
wants to merge 7 commits from
gh-pr/2077/head into gh-pr/2077/base
pull from: gh-pr/2077/head
merge into: github:gh-pr/2077/base
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!2077
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2077/head"
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?
@MoonEyes on GitHub · 2026-11-25 19:39 UTC · original
MoonEyes:feat/async-compile-pool→main· +3708 −278 · 17 files · 7 commits · closed without mergingClaimed in the coordination issue as: RT-ASYNC-COMPILE-POOL (#1608, comment 7169077699)
Depends on: #1889 (the memory gate for large pipelines), #1756 (conflicts: both change has_compile_waiter; whichever lands second rebases). This branch is #1889 plus the pool commit and a doc fix, with main merged in; review the commits after #1889's head (
aa8018b7f).What and why
rt::d3d12::PipelineCompiler(runtime/shims/d3d12_pipeline_compile.h) runs everyLEONIDA_ASYNC_PIPELINES=1build, the compute warm-up and the cache checkpoint on one below-normal thread. One long driver compile holds every pipeline a submission asked for behind it, and their draws and dispatches are skipped meanwhile.In-game observations (reported by OreoFR on the project Discord, quoted with his permission)
Numbers as OreoFR reported them; I did not measure them and they are not reproduced here.
replay_skips=0) the device holds after the world starts: 6,191 indirect draws recorded at 176 s, then 11,211 later in the same run.Hypothesis, which OreoFR is checking and which is not confirmed: a dispatch skipped because its pipeline is not ready may leave a later compute looping, waiting for a value that never comes.
This pool reduces skips and compile walls. It does not reduce the per-frame cost in steady state.
Change
LEONIDA_COMPILE_THREADSworkers: unset, half the logical processors, at least 2 and at most 8.1is the one thread there was, with the same order of jobs.LEONIDA_COMPILE_HEAVY_MAX(default 1,0for no limit of its own). This is on top of the memory gate, which admits what fits the free memory and would let the three ScreenProbes modules in together.after_running,delete thisand the lifetime rules of #1723 as they are.has_compile_waiter()now counts a build that is running on another worker.It continues the idea of #1577 by madhyn (closed by its author) on the current lifetime model, with the priority-aware gate that #1577 was missing.
Beyond the claim
The claim (#1608, comment 7169077699) said "half the logical processors, at most 8". This sets a minimum of 2, so that 2 or 3 logical processors still leave a worker for demanded builds;
LEONIDA_COMPILE_THREADS=1gives the one thread.LEONIDA_COMPILE_HEAVY_MAX(one build of 1 MiB of SPIR-V or more at a time) was not in the claim: it was added after OreoFR's report of NVVM failing when the three ScreenProbes modules compile together.Limits
pipeline_cache.session.binis more often skipped at device teardown (~Device does not write it while a build is active); the exit write of #1950 waits 1 s, then writes the pipelines finished so far.stop_for_exitmay detach N threads instead of one when its wait runs out.LEONIDA_COMPILE_THREADS=1on this branch stands for main in the measurements; main itself was not measured.Credit: OreoFR for the in-game measurements, DadaCap for the mesh branch used in the traced runs, madhyn for the idea of #1577.
Tested
pipeline_compiler_pool(new, no GPU): the rules with made-up jobs. 17 mutants, each removing or weakening one rule (reserved worker, one job per PSO, checkpoint at rest, the very large limit, the wake-up, the settings), all fail it.d3d12_compile_pool(new, GPU; default, 1 and 4 workers): a large module's build held in flight; with several workers 64 small pipelines are built and their dispatches store the right values meanwhile, with one worker none is.d3d12_compile_teardownwith the default, 1 and 4 workers: itsGatenow holds every worker.d3d12_big_compute_warmupis #1889's test (TheGeogeo), changed here because it assumed one warm-up thread and failed with the pool (once in ctest, then 3 of 6 runs): the warm-up threads are now the compiler's threads, taken from the job probe; "module 0 enters first" is checked only with one worker; and the "place is taken" check counts large creations only, since the warm-up's small ones may start on the other workers. The order check (the submission's four large builds between two of the warm-up's) is unchanged. If #1889 changes this test, this commit rebases on it.ctest -R "compile|pipeline|big_compute|d3d12_compute|session", with maine18b59a5bmerged in: 31 of 31 (before the pool, on #1889 alone with-R "compile|pipeline|big_compute|d3d12_compute", 24 of 25:big_compile_gatetimed out on a loaded machine and passes alone).tests/test_docs_*.py: 50 passed.d3d12_compile_pool_test measure 4194304 200 <seed>(one 4 MiB module the driver takes 92 to 173 s over, then 200 modules of 12 KiB, two alternating runs each, on a machine that was building other things): the 200 are ready after 1.3 and 6.9 s with 6 workers, after 99 and 152 s with one thread. Peak commit 714 and 720 MiB against 645 and 681.GPUs tested: NVIDIA GeForce RTX 4060, driver 610.88, Windows 11
AI-assisted: yes (Claude Code wrote the code, the tests and this text; the game measurements are OreoFR's).
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)🤖 Generated with Claude Code
@OreoFR on GitHub · 2026-11-25 19:58 UTC · original
Numbers from my side for why the pool matters on NVIDIA (RTX 4070 Laptop 8 GB, 621.40, retail, traced with
LEONIDA_TRACE_PIPELINE_COMPILE=1):lib_cs_01646in 115 s andlib_cs_01631in 116 s. Every run hit a different set of them at the world start: 17 distinct library compute modules over 60 s so far, between 3.2 and 5.9 MB of SPIR-V.gta6rt.exeby default, so every new build dir started cold here. With #1914 (pipeline_cache.heavy.bin, written while the game runs) andLEONIDA_PIPELINE_CACHE_DIRpointing every build at one folder, a module is compiled once per machine: a second run reloaded 20 MB of heavy cache and did not rebuild any of the four slow builds the first run had done.So pool + #1914 + one shared cache dir covers it: the first boot compiles side by side, and the boots after it pay nothing.
This branch (
044d9ba58) on the same machine:d3d12_compile_pool(default, one thread, four threads),d3d12_compile_teardown(default, one thread, four threads) andpipeline_compiler_poolall pass, 7 of 7. A retail boot with it follows.Counts and program names only. AI-assisted (Claude Code).
@DadaCap on GitHub · 2026-11-25 21:00 UTC · original
Three game runs with this PR (head
044d9ba58), asked for on Discord. One run each.Build: main
db1a22d29+ our local tree (including #429, #1592, #1756, #1957, #1972) + this PR + #1914, same executable for all three. Machine: RTX 5080 16 GB, NVIDIA 621.24, Windows 11, 64 GB.LEONIDA_SERIAL_BIG_COMPILES=0, warm session cache (1.87 GB), mesh modules from #2102.LEONIDA_ASYNC_PIPELINESLEONIDA_COMPILE_THREADSWhat the two losses share: a READ_INVALID (type 1, precision 4096, pages
0x4a4a05000and0x4bdb7d000) and the same faulting instruction address,0x200024e20(type 6).AI-assisted (Claude Code, Claude Opus 5.5).
@DadaCap on GitHub · 2026-11-25 21:19 UTC · original
Addition to my table above: a later sync run (m79,
LEONIDA_ASYNC_PIPELINESunset, our tree without this PR and without #1914, same shaders) also lost the device, at about 230 s in the world, with a READ_INVALID (page0x4b531e000) and the same faulting instruction address0x200024e20(plus0x200025dd0). No draw or dispatch is skipped there. So that fault needs neither skips nor the pool; with one run each, the table does not show that async causes it, only that it came earlier in the two async runs. I have not mapped the instruction address to a program. AI-assisted (Claude Code, Claude Opus 5.5).@MoonEyes on GitHub · 2026-11-25 21:46 UTC · original
In-game A/B on one binary, from my own box (RTX 4060 desktop, 12 logical processors, driver 610.88, Windows 11). Same executable (this branch at
044d9ba58), two 300 s boots withscripts/windows-boot/boot.ps1,LEONIDA_ASYNC_PIPELINES=1,LEONIDA_DEVICE_TYPE=7, a fresh pipeline-cache folder per run. OnlyLEONIDA_COMPILE_THREADSdiffers:LEONIDA_COMPILE_THREADS=1So on this machine the two runs present the same number of frames, and the pool run reaches game=3 session=3 (the landing screen) about 50 s sooner (states are sampled every 5 s). Almost every compile in these runs is the warm-up's (1,093 of 1,099 in the pool run, 900 of 906 in the 1-thread run; 5 from draws and 1 from a dispatch in each), so this boot barely exercises the reserved lane for demanded builds.
Limits: one run of each, one machine. The 1-thread run went first, and a ctest run of another checkout was going during its first 190 s or so, not during the pool run, so part of the 50 s may be that load. An earlier pool run of the same executable, made before the 1-thread run and while a build was running, reached the same state at 145 s, so run order alone does not explain the gap; that run presented 2,340 frames, so frame counts move by about 12% between runs. The driver's shader cache was already warm from earlier boots. The graphics pipeline library (#1592) is not built here (0 fspx_gfx): the game's mesh pipeline streams (12,244 per run) are accepted but none shows up among the traced compiles, and every build of 2 s or more is a compute pipeline. Counts only, no logs.
AI-assisted: yes (Claude Code ran the boots and read the digests; I reviewed it)
@MoonEyes on GitHub · 2026-11-26 07:12 UTC · original
Closing this one. #2098 changed the same scheduler another way: a graphics worker, the compile helper and the compile gate. This branch is built on the single thread from before and conflicts with main in 12 places of
d3d12_pipeline_compile.h.My later runs did not show the 50 s gain again: run-to-run noise on my machine (RTX 4060) is about 50 s. As I read the compile gate, more builds at once also means a submission waits for the longest of them.
If demanded builds still queue on main with the helper on, I will claim a small follow-up on top of #2098. Thanks to everyone who tested this.
AI-assisted: yes (Claude Code, Claude Fable 5.2, read both trees and wrote this)
Pull request closed