d3d12: a pool of workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2077
Closed
MoonEyes wants to merge 7 commits from
upstream-pr/2077 into main
pull from: upstream-pr/2077
merge into: ProjectLeonida:main
ProjectLeonida:main
ProjectLeonida:claude/loop-total
ProjectLeonida:claude/pops-collision-seed
ProjectLeonida:claude/dstorage-hold-page-reads
ProjectLeonida:claude/host-image-copy-switch
ProjectLeonida:feat/gdk-lifecycle-window-hook
ProjectLeonida:claude/d16s8-uav-nvidia-fallback
ProjectLeonida:feat/mfplat-offline-shim
ProjectLeonida:claude/gameinput-slow-reader
ProjectLeonida:fix/rt-null-barrier-clear
ProjectLeonida:claude/depth-resolve-sample-positions
ProjectLeonida:integration/palmetto-parity
ProjectLeonida:claude/valu-literal-sext
ProjectLeonida:claude/slot74-pool-handle
ProjectLeonida:claude/rgb9e5-uint-alias-view
ProjectLeonida:claude/fssm-root-layout-tables
ProjectLeonida:feat/gdk-speech-display-lifecycle
ProjectLeonida:asset-audio-skip-current
ProjectLeonida:qemmhd/old-9940-rectangle-quad-lists
ProjectLeonida:feat/ws2-offline-shim
ProjectLeonida:qemmhd/rt-d16-unorm-uav
ProjectLeonida:feat/xs-device-stops-7-9
ProjectLeonida:qemmhd/rt-depth-same-base-shapes
ProjectLeonida:qemmhd/rt-lazy-attachment-variant
ProjectLeonida:feat/acphal-xma2-decoder
ProjectLeonida:asset-audio-skip
ProjectLeonida:codex/coord-claim-check-20261124-7e48
ProjectLeonida:feat/xs-frame-pacing-presentx
ProjectLeonida:feat/xs-device-vm-options
ProjectLeonida:old-pr/9844
ProjectLeonida:old-pr/9978
ProjectLeonida:old-pr/9815
ProjectLeonida:old-pr/10057
ProjectLeonida:old-pr/9874
ProjectLeonida:old-pr/9965
ProjectLeonida:old-pr/9863
ProjectLeonida:old-pr/10068
ProjectLeonida:old-pr/10066
ProjectLeonida:old-pr/10067
ProjectLeonida:old-pr/10007
ProjectLeonida:old-pr/10061
ProjectLeonida:old-pr/10065
ProjectLeonida:old-pr/10059
ProjectLeonida:old-pr/10063
ProjectLeonida:old-pr/10055
ProjectLeonida:old-pr/10062
ProjectLeonida:old-pr/10042
ProjectLeonida:old-pr/10041
ProjectLeonida:old-pr/10049
ProjectLeonida:old-pr/10047
ProjectLeonida:old-pr/10046
ProjectLeonida:old-pr/10045
ProjectLeonida:old-pr/10056
ProjectLeonida:old-pr/10043
ProjectLeonida:old-pr/10036
ProjectLeonida:old-pr/10034
ProjectLeonida:old-pr/9984
ProjectLeonida:old-pr/10052
ProjectLeonida:old-pr/10038
ProjectLeonida:old-pr/10033
ProjectLeonida:old-pr/10028
ProjectLeonida:old-pr/10050
ProjectLeonida:old-pr/9891
ProjectLeonida:old-pr/9889
ProjectLeonida:old-pr/10051
ProjectLeonida:old-pr/10019
ProjectLeonida:old-pr/10027
ProjectLeonida:old-pr/10029
ProjectLeonida:old-pr/10031
ProjectLeonida:old-pr/10026
ProjectLeonida:old-pr/9941
ProjectLeonida:old-pr/10030
ProjectLeonida:old-pr/10040
ProjectLeonida:old-pr/9990
ProjectLeonida:old-pr/10021
ProjectLeonida:old-pr/9962
ProjectLeonida:old-pr/10022
ProjectLeonida:old-pr/10020
ProjectLeonida:old-pr/10015
ProjectLeonida:old-pr/10025
ProjectLeonida:old-pr/9886
ProjectLeonida:old-pr/10048
ProjectLeonida:old-pr/10014
ProjectLeonida:old-pr/10011
ProjectLeonida:old-pr/9861
ProjectLeonida:old-pr/10010
ProjectLeonida:old-pr/10008
ProjectLeonida:old-pr/9860
ProjectLeonida:old-pr/10006
ProjectLeonida:old-pr/9920
ProjectLeonida:old-pr/9995
ProjectLeonida:old-pr/10000
ProjectLeonida:old-pr/10016
ProjectLeonida:old-pr/10004
ProjectLeonida:old-pr/10023
ProjectLeonida:old-pr/9982
ProjectLeonida:old-pr/9981
ProjectLeonida:old-pr/9983
ProjectLeonida:old-pr/9970
ProjectLeonida:old-pr/9969
ProjectLeonida:old-pr/9968
ProjectLeonida:old-pr/9971
ProjectLeonida:old-pr/9972
ProjectLeonida:old-pr/9942
ProjectLeonida:old-pr/9963
ProjectLeonida:old-pr/9960
ProjectLeonida:old-pr/9964
ProjectLeonida:old-pr/9985
ProjectLeonida:old-pr/9973
ProjectLeonida:old-pr/9862
ProjectLeonida:old-pr/9953
ProjectLeonida:old-pr/10017
ProjectLeonida:old-pr/9952
ProjectLeonida:old-pr/9955
ProjectLeonida:old-pr/9946
ProjectLeonida:old-pr/9954
ProjectLeonida:old-pr/9938
ProjectLeonida:old-pr/9956
ProjectLeonida:old-pr/9856
ProjectLeonida:old-pr/9947
ProjectLeonida:old-pr/9924
ProjectLeonida:old-pr/9961
ProjectLeonida:old-pr/9927
ProjectLeonida:old-pr/9979
ProjectLeonida:old-pr/10032
ProjectLeonida:old-pr/9926
ProjectLeonida:old-pr/5237
ProjectLeonida:old-pr/9951
ProjectLeonida:old-pr/9931
ProjectLeonida:old-pr/9902
ProjectLeonida:old-pr/9921
ProjectLeonida:old-pr/9994
ProjectLeonida:old-pr/9775
ProjectLeonida:old-pr/9768
ProjectLeonida:old-pr/9905
ProjectLeonida:old-pr/9936
ProjectLeonida:old-pr/9901
ProjectLeonida:old-pr/9904
ProjectLeonida:old-pr/9906
ProjectLeonida:old-pr/9988
ProjectLeonida:old-pr/9908
ProjectLeonida:old-pr/9909
ProjectLeonida:old-pr/9911
ProjectLeonida:old-pr/9912
ProjectLeonida:old-pr/9913
ProjectLeonida:old-pr/9887
ProjectLeonida:old-pr/9916
ProjectLeonida:old-pr/9919
ProjectLeonida:old-pr/9925
ProjectLeonida:old-pr/9933
ProjectLeonida:old-pr/9935
ProjectLeonida:old-pr/9918
ProjectLeonida:old-pr/9879
ProjectLeonida:old-pr/9880
ProjectLeonida:old-pr/9881
ProjectLeonida:old-pr/9996
ProjectLeonida:old-pr/9876
ProjectLeonida:old-pr/9892
ProjectLeonida:old-pr/9899
ProjectLeonida:old-pr/9915
ProjectLeonida:old-pr/9914
ProjectLeonida:old-pr/9872
ProjectLeonida:old-pr/9869
ProjectLeonida:old-pr/9866
ProjectLeonida:old-pr/9819
ProjectLeonida:old-pr/10012
ProjectLeonida:old-pr/9857
ProjectLeonida:old-pr/9893
ProjectLeonida:old-pr/9897
ProjectLeonida:old-pr/9928
ProjectLeonida:old-pr/9868
ProjectLeonida:old-pr/9917
ProjectLeonida:old-pr/9940
ProjectLeonida:old-pr/9873
ProjectLeonida:old-pr/9816
ProjectLeonida:old-pr/10009
ProjectLeonida:old-pr/9900
ProjectLeonida:old-pr/9966
ProjectLeonida:old-pr/9859
ProjectLeonida:old-pr/9843
ProjectLeonida:old-pr/9991
ProjectLeonida:old-pr/10058
ProjectLeonida:old-pr/9883
ProjectLeonida:old-pr/9838
ProjectLeonida:old-pr/9835
ProjectLeonida:old-pr/9959
ProjectLeonida:old-pr/9895
ProjectLeonida:old-pr/9837
ProjectLeonida:old-pr/9858
ProjectLeonida:old-pr/9865
ProjectLeonida:old-pr/9864
ProjectLeonida:old-pr/9840
ProjectLeonida:old-pr/9820
ProjectLeonida:old-pr/4669
ProjectLeonida:old-pr/9848
ProjectLeonida:old-pr/9850
ProjectLeonida:old-pr/9810
ProjectLeonida:old-pr/9799
ProjectLeonida:old-pr/9853
ProjectLeonida:old-pr/9875
ProjectLeonida:old-pr/9831
ProjectLeonida:old-pr/9796
ProjectLeonida:old-pr/9801
ProjectLeonida:old-pr/9813
ProjectLeonida:old-pr/9794
ProjectLeonida:old-pr/7417
ProjectLeonida:old-pr/9781
ProjectLeonida:old-pr/9806
ProjectLeonida:old-pr/9958
ProjectLeonida:old-pr/9809
ProjectLeonida:old-pr/9791
ProjectLeonida:old-pr/9792
ProjectLeonida:old-pr/10053
ProjectLeonida:old-pr/9784
ProjectLeonida:old-pr/9789
ProjectLeonida:old-pr/9849
ProjectLeonida:old-pr/9846
ProjectLeonida:old-pr/9773
ProjectLeonida:old-pr/9785
ProjectLeonida:old-pr/9803
ProjectLeonida:old-pr/9826
ProjectLeonida:old-pr/9839
ProjectLeonida:old-pr/9922
ProjectLeonida:old-pr/9948
ProjectLeonida:old-pr/7189
ProjectLeonida:old-pr/9957
ProjectLeonida:old-pr/9823
ProjectLeonida:old-pr/9807
ProjectLeonida:old-pr/9851
ProjectLeonida:old-pr/9774
ProjectLeonida:old-pr/9830
ProjectLeonida:old-pr/9836
ProjectLeonida:old-pr/9822
ProjectLeonida:old-pr/9783
ProjectLeonida:old-pr/9833
ProjectLeonida:old-pr/9890
ProjectLeonida:old-pr/9770
ProjectLeonida:old-pr/9769
ProjectLeonida:old-pr/9772
ProjectLeonida:old-pr/9787
ProjectLeonida:old-pr/9852
ProjectLeonida:old-pr/9834
ProjectLeonida:old-pr/9845
ProjectLeonida:old-pr/9871
ProjectLeonida:old-pr/9771
ProjectLeonida:old-pr/9776
ProjectLeonida:old-pr/10005
ProjectLeonida:old-pr/9949
ProjectLeonida:old-pr/9923
ProjectLeonida:old-pr/9805
ProjectLeonida:old-pr/9829
ProjectLeonida:old-pr/9790
ProjectLeonida:old-pr/9827
ProjectLeonida:old-pr/9929
ProjectLeonida:old-pr/9855
ProjectLeonida:old-pr/9934
ProjectLeonida:old-pr/9907
ProjectLeonida:old-pr/9910
ProjectLeonida:old-pr/9779
ProjectLeonida:old-pr/9780
ProjectLeonida:old-pr/9885
ProjectLeonida:old-pr/9882
ProjectLeonida:old-pr/9877
ProjectLeonida:old-pr/9998
ProjectLeonida:old-pr/4251
ProjectLeonida:old-pr/9987
ProjectLeonida:old-pr/9989
ProjectLeonida:old-pr/9950
ProjectLeonida:old-pr/9777
ProjectLeonida:old-pr/10044
ProjectLeonida:old-pr/9884
ProjectLeonida:old-pr/2906
ProjectLeonida:old-pr/5076
ProjectLeonida:old-pr/9937
ProjectLeonida:old-pr/9986
ProjectLeonida:old-pr/3014
ProjectLeonida:old-pr/9943
ProjectLeonida:old-pr/9939
ProjectLeonida:old-pr/4682
ProjectLeonida:old-pr/4765
No reviewers
Labels
Clear labels
No items
No labels
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.
Reference
ProjectLeonida/mandy!2077
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2077"
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?
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-25T19:39:37Z.
Claimed 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
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-25T19:58:13Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-25T21:00:46Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-25T21:19:36Z.
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).Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-25T21:46:21Z.
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)
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-26T07:12:53Z.
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