d3d12: a pool of workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2077
Closed
leonida/mandy
MoonEyes wants to merge 0 commits from
feat/async-compile-pool into main
pull from: feat/async-compile-pool
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2077
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/async-compile-pool"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
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
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).
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).
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).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 with
scripts/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)
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)