[PR #2077] [CLOSED] d3d12: a pool of workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2083

Closed
opened 2026-11-26 21:19:58 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2077
Author: @MoonEyes
Created: 11/25/2026
Status: ❌ Closed

Base: main ← Head: feat/async-compile-pool


📝 Commits (7)

  • 4aa21d1 runtime: large compiles wait for memory in arrival order, demand before speculative (RT-BIG-COMPUTE-BUDGET)
  • aa8018b d3d12: large pipelines compile side by side within a memory budget (RT-BIG-COMPUTE-BUDGET)
  • 7f81254 local base: #1889 (RT-BIG-COMPUTE-BUDGET, not part of this change)
  • 93c4654 d3d12: a pool of workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL)
  • 2465003 Merge remote-tracking branch 'origin/main' into feat/async-compile-pool
  • eacb44f docs: the compile pool keeps a worker for a demanded build that is not heavy, not for any small one
  • 044d9ba Merge remote-tracking branch 'origin/main' into feat/async-compile-pool

📊 Changes

17 files changed (+3708 additions, -278 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+53 -9)
📝 docs/pipeline_check.md (+1 -1)
📝 runtime/CMakeLists.txt (+70 -2)
📝 runtime/README.md (+4 -1)
📝 runtime/shims/d3d12_pipeline_compile.h (+181 -33)
📝 runtime/shims/d3d12_vulkan_device.cpp (+84 -17)
➕ runtime/src/large_module_gate.h (+275 -0)
📝 runtime/src/vulkan_backend.h (+15 -1)
📝 runtime/src/vulkan_replay.h (+60 -14)
➕ runtime/test/big_compile_gate_test.cpp (+426 -0)
➕ runtime/test/big_compute_module.h (+298 -0)
➕ runtime/test/d3d12_big_compute_test.cpp (+1007 -0)
➕ runtime/test/d3d12_compile_pool_test.cpp (+352 -0)
📝 runtime/test/d3d12_compile_teardown_test.cpp (+25 -11)
📝 runtime/test/large_module_gate.h (+2 -179)
➕ runtime/test/pipeline_compiler_pool_test.cpp (+561 -0)
📝 runtime/test/replay_pipeline_compiles_test.cpp (+294 -10)

📄 Description

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 every LEONIDA_ASYNC_PIPELINES=1 build, 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.

  • At each device loss (4 traced runs, DadaCap's mesh branch, asynchronous compilation) the only pipeline being compiled was a mesh pipeline a draw asked for.
  • With synchronous compilation (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.
  • The three ScreenProbes compute modules (ActivateRays, ActivateProbes, ActivateProbesTarget) take the NVIDIA driver 30 to 32 minutes each, and compiling all three in parallel makes NVVM fail.
  • Early in the world, compilation is only 11% of frame time (8 s of 72 s).

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_THREADS workers: unset, half the logical processors, at least 2 and at most 8. 1 is the one thread there was, with the same order of jobs.
  • At most N-1 workers are in heavy builds at a time (the warm-up's, and demanded builds of large modules: compute over 128 KiB, anything of 1 MiB or more), so one worker is always left for a build that is not heavy. Graphics pipelines under 1 MiB (mesh pipelines of a few hundred KiB, for one) are not heavy: N of them can still hold every worker.
  • One very large build (1 MiB of SPIR-V or more) at a time, demanded or speculative: LEONIDA_COMPILE_HEAVY_MAX (default 1, 0 for 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.
  • One job of a PSO at a time, which keeps after_running, delete this and the lifetime rules of #1723 as they are.
  • A checkpoint starts only when no worker is in a build, and has_compile_waiter() now counts a build that is running on another worker.
  • A running checkpoint takes a worker too.
  • Large builds wait at the gate of #1889 inside their job, unchanged, and count as heavy while they wait.

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=1 gives 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

  • The pool makes skips fewer and shorter. It does not remove them: a draw or dispatch is still skipped for as long as its own pipeline takes to compile, so the device loss above can still happen. Not tested in the game.
  • The very large limit is tested with made-up jobs only, not against the NVVM failure.
  • A long module still takes as long. With the limit of one, very large builds queue behind each other.
  • With several workers the pipelines become ready in an order that differs from run to run.
  • The driver holds about 50 MiB for each thread that compiles.
  • With N builds in flight, pipeline_cache.session.bin is 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_exit may detach N threads instead of one when its wait runs out.
  • The checkpoint waits for an empty queue and for every worker to be out of its build (as on main, where one thread made these the same thing); #1756 changes that.
  • The "heavy" threshold (compute over 128 KiB, 1 MiB or more for the rest) is a setting that can be tuned later: graphics pipelines between 128 KiB and 1 MiB are not heavy and can occupy all N workers.
  • LEONIDA_COMPILE_THREADS=1 on 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_teardown with the default, 1 and 4 workers: its Gate now holds every worker.
  • d3d12_big_compute_warmup is #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 main e18b59a5b merged in: 31 of 31 (before the pool, on #1889 alone with -R "compile|pipeline|big_compute|d3d12_compute", 24 of 25: big_compile_gate timed out on a loaded machine and passes alone). tests/test_docs_*.py: 50 passed.
  • Synthetic run, 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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2077 **Author:** [@MoonEyes](https://github.com/MoonEyes) **Created:** 11/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/async-compile-pool` --- ### 📝 Commits (7) - [`4aa21d1`](https://github.com/ubiquitarianism/leonida/commit/4aa21d1a83f4a7954ca79111fffb0d4aba674bf2) runtime: large compiles wait for memory in arrival order, demand before speculative (RT-BIG-COMPUTE-BUDGET) - [`aa8018b`](https://github.com/ubiquitarianism/leonida/commit/aa8018b7ff164efff848666c3c4205a60adbbed5) d3d12: large pipelines compile side by side within a memory budget (RT-BIG-COMPUTE-BUDGET) - [`7f81254`](https://github.com/ubiquitarianism/leonida/commit/7f8125406acd65994df70955b4dec12f4b683d7b) local base: #1889 (RT-BIG-COMPUTE-BUDGET, not part of this change) - [`93c4654`](https://github.com/ubiquitarianism/leonida/commit/93c46542818737f850c3025c890f53f606c9817f) d3d12: a pool of workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) - [`2465003`](https://github.com/ubiquitarianism/leonida/commit/2465003d62be458c06ae7017784ab03d20b3c46c) Merge remote-tracking branch 'origin/main' into feat/async-compile-pool - [`eacb44f`](https://github.com/ubiquitarianism/leonida/commit/eacb44fe7541df1c1aca84dc8a16029416c2cfbd) docs: the compile pool keeps a worker for a demanded build that is not heavy, not for any small one - [`044d9ba`](https://github.com/ubiquitarianism/leonida/commit/044d9ba580ee64c16ebdcae37689549b2e1a391c) Merge remote-tracking branch 'origin/main' into feat/async-compile-pool ### 📊 Changes **17 files changed** (+3708 additions, -278 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+53 -9) 📝 `docs/pipeline_check.md` (+1 -1) 📝 `runtime/CMakeLists.txt` (+70 -2) 📝 `runtime/README.md` (+4 -1) 📝 `runtime/shims/d3d12_pipeline_compile.h` (+181 -33) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+84 -17) ➕ `runtime/src/large_module_gate.h` (+275 -0) 📝 `runtime/src/vulkan_backend.h` (+15 -1) 📝 `runtime/src/vulkan_replay.h` (+60 -14) ➕ `runtime/test/big_compile_gate_test.cpp` (+426 -0) ➕ `runtime/test/big_compute_module.h` (+298 -0) ➕ `runtime/test/d3d12_big_compute_test.cpp` (+1007 -0) ➕ `runtime/test/d3d12_compile_pool_test.cpp` (+352 -0) 📝 `runtime/test/d3d12_compile_teardown_test.cpp` (+25 -11) 📝 `runtime/test/large_module_gate.h` (+2 -179) ➕ `runtime/test/pipeline_compiler_pool_test.cpp` (+561 -0) 📝 `runtime/test/replay_pipeline_compiles_test.cpp` (+294 -10) </details> ### 📄 Description 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 every `LEONIDA_ASYNC_PIPELINES=1` build, 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. - At each device loss (4 traced runs, DadaCap's mesh branch, asynchronous compilation) the only pipeline being compiled was a mesh pipeline a draw asked for. - With synchronous compilation (`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. - The three ScreenProbes compute modules (ActivateRays, ActivateProbes, ActivateProbesTarget) take the NVIDIA driver 30 to 32 minutes each, and compiling all three in parallel makes NVVM fail. - Early in the world, compilation is only 11% of frame time (8 s of 72 s). 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_THREADS` workers: unset, half the logical processors, at least 2 and at most 8. `1` is the one thread there was, with the same order of jobs. - At most N-1 workers are in heavy builds at a time (the warm-up's, and demanded builds of large modules: compute over 128 KiB, anything of 1 MiB or more), so one worker is always left for a build that is not heavy. Graphics pipelines under 1 MiB (mesh pipelines of a few hundred KiB, for one) are not heavy: N of them can still hold every worker. - One very large build (1 MiB of SPIR-V or more) at a time, demanded or speculative: `LEONIDA_COMPILE_HEAVY_MAX` (default 1, `0` for 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. - One job of a PSO at a time, which keeps `after_running`, `delete this` and the lifetime rules of #1723 as they are. - A checkpoint starts only when no worker is in a build, and `has_compile_waiter()` now counts a build that is running on another worker. - A running checkpoint takes a worker too. - Large builds wait at the gate of #1889 inside their job, unchanged, and count as heavy while they wait. 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=1` gives 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 - The pool makes skips fewer and shorter. It does not remove them: a draw or dispatch is still skipped for as long as its own pipeline takes to compile, so the device loss above can still happen. Not tested in the game. - The very large limit is tested with made-up jobs only, not against the NVVM failure. - A long module still takes as long. With the limit of one, very large builds queue behind each other. - With several workers the pipelines become ready in an order that differs from run to run. - The driver holds about 50 MiB for each thread that compiles. - With N builds in flight, `pipeline_cache.session.bin` is 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_exit` may detach N threads instead of one when its wait runs out. - The checkpoint waits for an empty queue and for every worker to be out of its build (as on main, where one thread made these the same thing); #1756 changes that. - The "heavy" threshold (compute over 128 KiB, 1 MiB or more for the rest) is a setting that can be tuned later: graphics pipelines between 128 KiB and 1 MiB are not heavy and can occupy all N workers. - `LEONIDA_COMPILE_THREADS=1` on 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_teardown` with the default, 1 and 4 workers: its `Gate` now holds every worker. - `d3d12_big_compute_warmup` is #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 main `e18b59a5b` merged in: 31 of 31 (before the pool, on #1889 alone with `-R "compile|pipeline|big_compute|d3d12_compute"`, 24 of 25: `big_compile_gate` timed out on a loaded machine and passes alone). `tests/test_docs_*.py`: 50 passed. - Synthetic run, `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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:19:58 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#2083
No description provided.