[PR #2233] d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) #2236

Open
opened 2026-11-26 21:20:31 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2233
Author: @Tyrannys
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: claude/rt-async-compile-pool


📝 Commits (2)

  • a83f385 d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL)
  • 2d56b68 d3d12: the checkpoint's second look also sees a running demanded build

📊 Changes

6 files changed (+710 additions, -44 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+15 -0)
📝 runtime/CMakeLists.txt (+12 -0)
📝 runtime/README.md (+3 -1)
📝 runtime/shims/d3d12_pipeline_compile.h (+174 -40)
📝 runtime/shims/d3d12_vulkan_device.cpp (+7 -3)
➕ runtime/test/d3d12_compile_pool_test.cpp (+499 -0)

📄 Description

Claimed 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 on PipelineCompiler'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).

PipelineCompiler now runs LEONIDA_COMPILE_THREADS workers (default half the logical processors, 2 to 8). A worker takes the most urgent job it may:

  • Order: demanded builds first, in the order they came, then warm-ups by module size, then the checkpoint, which now waits until no worker compiles.
  • A free worker for small demanded builds: large builds (compute over 128 KiB, graphics of 1 MiB of SPIR-V or more) and warm-ups together take at most threads-1 workers.
  • Heavy count: at most LEONIDA_COMPILE_HEAVY_MAX large builds at once (default threads-1; 1 with LEONIDA_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 when LEONIDA_SERIAL_BIG_COMPILES=0 clears graphics_.large, so the async path follows the same knobs for both.
  • Warm-ups behind demanded builds: warm-ups run one at a time, as on the single worker, and none starts while a demanded build runs. MoonEyes found in #1608 (07:32 today) that the default compile gate (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). With LEONIDA_COMPILE_GATE=0 the 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.
  • One build of a PSO at a time, so after_running and the teardown rules hold as they were.
  • The checkpoint backs off from a running demand too (review by lixonik): the checkpoint starts only when no worker compiles, but a demanded build can start on another worker during its vkGetPipelineCacheData size 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=1 is 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, through PipelineCompiles::build (runtime/src/vulkan_replay.h) and its memory budget, not on these workers. Only the compute warm-up and the checkpoint go through PipelineCompiler in 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 to PipelineCompiles (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 current main, graphics_.large is false with LEONIDA_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:

    • the settings parse;
    • a long large build does not hold up a small demanded one, while with one worker it still does (the old behaviour);
    • the heavy count, and the worker left free;
    • warm-ups one at a time, and none while a demanded build runs;
    • demanded builds before warm-ups before the checkpoint;
    • one job per PSO;
    • a checkpoint's second look seeing a demanded build that started on another worker during it (lixonik's case: it failed before the fix and passes after);
    • a finished job waking the idle workers;
    • the last release, cancel and stop_for_exit with 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_teardown runs with the pool, and as new d3d12_compile_teardown_one_worker with LEONIDA_COMPILE_THREADS=1. Both pass, as do d3d12_big_compute (all 7 settings), d3d12_m4_compute, big_compile_gate, compile_helper, replay_pipeline_compiles*, pipeline_workers and d3d12_pipeline_workers*.

  • Full runtime CTest, -j 4 (a boot was running on this machine). Everything passes except four:

    • xs_proxy_mock and d3d12_multithread failed under that load and pass when rerun alone;
    • xbox_present (present VkResult -11) and d3d12_set_descriptor_heaps (line 353) fail the same way on upstream/main a73a57e13 without 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.py on 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 with main by itself. It also moves the checkpoint to priority 1, so whichever lands second must keep "checkpoint only when idle" keyed on the checkpoint, not on SIZE_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

  • Based on current main and merges cleanly.
  • 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: no translator change)

🤖 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/2233 **Author:** [@Tyrannys](https://github.com/Tyrannys) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `claude/rt-async-compile-pool` --- ### 📝 Commits (2) - [`a83f385`](https://github.com/ubiquitarianism/leonida/commit/a83f38508f535a2de95a15f91071139de2c26fee) d3d12: a pool of compile workers for the pipeline compiler (RT-ASYNC-COMPILE-POOL) - [`2d56b68`](https://github.com/ubiquitarianism/leonida/commit/2d56b685ac69d0447cb5bb560e132ad354d8779d) d3d12: the checkpoint's second look also sees a running demanded build ### 📊 Changes **6 files changed** (+710 additions, -44 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+15 -0) 📝 `runtime/CMakeLists.txt` (+12 -0) 📝 `runtime/README.md` (+3 -1) 📝 `runtime/shims/d3d12_pipeline_compile.h` (+174 -40) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+7 -3) ➕ `runtime/test/d3d12_compile_pool_test.cpp` (+499 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-ASYNC-COMPILE-POOL ([claim](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7185530691); 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 on `PipelineCompiler`'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`). `PipelineCompiler` now runs `LEONIDA_COMPILE_THREADS` workers (default half the logical processors, 2 to 8). A worker takes the most urgent job it may: - **Order:** demanded builds first, in the order they came, then warm-ups by module size, then the checkpoint, which now waits until no worker compiles. - **A free worker for small demanded builds:** large builds (compute over 128 KiB, graphics of 1 MiB of SPIR-V or more) and warm-ups together take at most threads-1 workers. - **Heavy count:** at most `LEONIDA_COMPILE_HEAVY_MAX` large builds at once (default threads-1; 1 with `LEONIDA_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 when `LEONIDA_SERIAL_BIG_COMPILES=0` clears `graphics_.large`, so the async path follows the same knobs for both. - **Warm-ups behind demanded builds:** warm-ups run one at a time, as on the single worker, and none starts while a demanded build runs. MoonEyes found in #1608 (07:32 today) that the default compile gate (`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). With `LEONIDA_COMPILE_GATE=0` the 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. - **One build of a PSO at a time**, so `after_running` and the teardown rules hold as they were. - **The checkpoint backs off from a running demand too** (review by lixonik): the checkpoint starts only when no worker compiles, but a demanded build can start on another worker during its `vkGetPipelineCacheData` size 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=1` is 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, through `PipelineCompiles::build` (`runtime/src/vulkan_replay.h`) and its memory budget, not on these workers. Only the compute warm-up and the checkpoint go through `PipelineCompiler` in 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 to `PipelineCompiles` (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 current `main`, `graphics_.large` is false with `LEONIDA_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: - the settings parse; - a long large build does not hold up a small demanded one, while with one worker it still does (the old behaviour); - the heavy count, and the worker left free; - warm-ups one at a time, and none while a demanded build runs; - demanded builds before warm-ups before the checkpoint; - one job per PSO; - a checkpoint's second look seeing a demanded build that started on another worker during it (lixonik's case: it failed before the fix and passes after); - a finished job waking the idle workers; - the last `release`, `cancel` and `stop_for_exit` with 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_teardown` runs with the pool, and as new `d3d12_compile_teardown_one_worker` with `LEONIDA_COMPILE_THREADS=1`. Both pass, as do `d3d12_big_compute` (all 7 settings), `d3d12_m4_compute`, `big_compile_gate`, `compile_helper`, `replay_pipeline_compiles*`, `pipeline_workers` and `d3d12_pipeline_workers*`. - Full runtime CTest, `-j 4` (a boot was running on this machine). Everything passes except four: - `xs_proxy_mock` and `d3d12_multithread` failed under that load and pass when rerun alone; - `xbox_present` (present `VkResult -11`) and `d3d12_set_descriptor_heaps` (line 353) fail the same way on `upstream/main` a73a57e13 without 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.py` on 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 with `main` by itself. It also moves the checkpoint to priority 1, so whichever lands second must keep "checkpoint only when idle" keyed on the checkpoint, not on `SIZE_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 - [x] Based on current `main` and merges cleanly. - [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: no translator change) 🤖 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>
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#2236
No description provided.