d3d12: compile a submission's pipelines on worker threads (RT-PIPELINE-COMPILE-WORKERS) #1547

Manually merged
github merged 2 commits from gh-pr/1547/head into gh-pr/1547/base 2026-11-26 09:56:11 +00:00
Owner

@⁠TheGeogeo on GitHub · 2026-11-25 04:07 UTC · original
TheGeogeo:perf/pipeline-compile-workers → main · +2139 −20 · 10 files · 2 commits · merged 2026-11-25 09:24 UTC

Claimed in the coordination issue as: RT-PIPELINE-COMPILE-WORKERS (#14)

What and why

Since #984 and #939 a graphics pipeline is compiled at its first draw and a compute pipeline at its first dispatch (unless the warm-up thread built it), and a draw that leaves an attachment unbound compiles a variant. All of that happens in prepare(), one pipeline after another on the thread that submits, with the resource lock held, so a submission that needs many new pipelines takes the sum of their compiles.

This compiles them side by side:

  • prepare() leaves a pipeline that is not built yet to PipelineCompiles, once per pipeline and variant. VulkanQueue::execute_now compiles them all on a bounded pool (runtime/src/pipeline_workers.h), the submitting thread among them, waits for all of them and then writes the command buffer. No draw or dispatch is left to a later frame or drawn with another pipeline.
  • The result is what prepare() would have returned had it built each one, in the order of the commands: a refused pipeline fails the list of a draw or an indirect dispatch and drops a dispatch (strict replay fails that too).
  • The resource lock is held while they compile, as it was while each compiled, so a pipeline state released meanwhile waits for the submission. The workers have ended before the session cache is read at device teardown.
  • LEONIDA_PIPELINE_THREADS=<n> sets the workers: unset, half the logical processors and at most 8; 0 keeps the path of before.
  • Graphics pipelines of 1 MiB of SPIR-V or more and compute pipelines over 128 KiB (LEONIDA_SERIAL_BIG_COMPILES) still compile one after another, beside the smaller ones: docs/pipeline_check.md measured 1.96 GB for one 5.7 MB module. big_compile itself is as it was (the finding in #14 is another topic).
  • The warm-up thread and LEONIDA_ASYNC_PIPELINES=1, which skips draws while one worker compiles, are not changed, and a pipeline in that mode is never left to the pool.

Nothing is compiled earlier than today.

Tested

Windows 11 (10.0.26300), MSVC 14.52, RelWithDebInfo, Visual Studio 18 2026 generator.

  • Synthetic measurement on main 2213d5cb, LEONIDA_COMPUTE_WARMUP=0 (new programs, never compiled before, so neither the process nor the driver's disk cache has seen them), first submission, three alternating runs, 8 workers:

    before after LEONIDA_PIPELINE_THREADS=0
    192 graphics pipelines 861 to 882 ms 126 to 143 ms 859 to 918 ms
    192 variants 856 to 863 ms 124 to 130 ms 864 to 872 ms
    96 compute pipelines 486 to 519 ms 74 to 81 ms 481 to 520 ms

    The second submission and CreatePipelineState take the same. The process holds about 50 MiB more (the driver keeps memory for each thread that compiles). Through one shared VkPipelineCache 192 graphics programs compile x4.9 faster with 8 threads and x7.3 with 16; with one cache per thread, merged, x5.5 and x9.2. Not measured again after the rebase onto main 5129be10.

  • New tests: pipeline_workers (the pool, CPU), replay_pipeline_compiles and _strict (3000 random submissions and fixed cases give the same result, pipelines, drops and compiles with and without the pool; CPU), d3d12_pipeline_workers and _eager (GPU: 48 graphics and 16 compute pipelines, the same bytes with 0, 1, 4 and 16 workers; refused compiles; two queues; pipeline states released and the device destroyed while a submission compiles). The GPU tests skip without a Vulkan device and below the 144-byte push constants.

  • Each new test fails for the changes that should fail it: 36 CPU and 15 GPU mutants (a dropped wait, lock, drain or dedup among them) all fail, the originals pass 30 repeated runs.

  • Full ctest of main 5129be10 and of this branch on it, compared test by test: 337 tests before (324 pass, 13 skip), 342 after (329, 13), no failure and no other status.

  • test_ctest_registration, test_docs_links, test_docs_cli_flags, test_text_write_line_endings, git diff --check and check_no_game_data.py pass.

Not run: the title. I do not have the package, so the effect on boot time and frame time is for someone who has it to measure. No Vulkan SDK here, so the Khronos validation layer did not run, and the d3d12 tests that need glslangValidator or llvm-mc were not built. Other GPUs were not run. The compile of one very large pipeline is not faster.

GPUs tested: NVIDIA GeForce RTX 3080, driver 621.24, Windows 11 (10.0.26300).

AI-assisted: yes (Claude Code)

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. (none added)
**@⁠TheGeogeo** on GitHub · 2026-11-25 04:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1547) `TheGeogeo:perf/pipeline-compile-workers` → `main` · +2139 −20 · 10 files · 2 commits · merged 2026-11-25 09:24 UTC Claimed in the coordination issue as: RT-PIPELINE-COMPILE-WORKERS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Since #984 and #939 a graphics pipeline is compiled at its first draw and a compute pipeline at its first dispatch (unless the warm-up thread built it), and a draw that leaves an attachment unbound compiles a variant. All of that happens in `prepare()`, one pipeline after another on the thread that submits, with the resource lock held, so a submission that needs many new pipelines takes the sum of their compiles. This compiles them side by side: - `prepare()` leaves a pipeline that is not built yet to `PipelineCompiles`, once per pipeline and variant. `VulkanQueue::execute_now` compiles them all on a bounded pool (`runtime/src/pipeline_workers.h`), the submitting thread among them, waits for all of them and then writes the command buffer. No draw or dispatch is left to a later frame or drawn with another pipeline. - The result is what `prepare()` would have returned had it built each one, in the order of the commands: a refused pipeline fails the list of a draw or an indirect dispatch and drops a dispatch (strict replay fails that too). - The resource lock is held while they compile, as it was while each compiled, so a pipeline state released meanwhile waits for the submission. The workers have ended before the session cache is read at device teardown. - `LEONIDA_PIPELINE_THREADS=<n>` sets the workers: unset, half the logical processors and at most 8; `0` keeps the path of before. - Graphics pipelines of 1 MiB of SPIR-V or more and compute pipelines over 128 KiB (`LEONIDA_SERIAL_BIG_COMPILES`) still compile one after another, beside the smaller ones: `docs/pipeline_check.md` measured 1.96 GB for one 5.7 MB module. `big_compile` itself is as it was (the finding in https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 is another topic). - The warm-up thread and `LEONIDA_ASYNC_PIPELINES=1`, which skips draws while one worker compiles, are not changed, and a pipeline in that mode is never left to the pool. Nothing is compiled earlier than today. ### Tested Windows 11 (10.0.26300), MSVC 14.52, RelWithDebInfo, Visual Studio 18 2026 generator. - Synthetic measurement on `main` 2213d5cb, `LEONIDA_COMPUTE_WARMUP=0` (new programs, never compiled before, so neither the process nor the driver's disk cache has seen them), first submission, three alternating runs, 8 workers: | | before | after | `LEONIDA_PIPELINE_THREADS=0` | |---|---|---|---| | 192 graphics pipelines | 861 to 882 ms | 126 to 143 ms | 859 to 918 ms | | 192 variants | 856 to 863 ms | 124 to 130 ms | 864 to 872 ms | | 96 compute pipelines | 486 to 519 ms | 74 to 81 ms | 481 to 520 ms | The second submission and `CreatePipelineState` take the same. The process holds about 50 MiB more (the driver keeps memory for each thread that compiles). Through one shared `VkPipelineCache` 192 graphics programs compile x4.9 faster with 8 threads and x7.3 with 16; with one cache per thread, merged, x5.5 and x9.2. Not measured again after the rebase onto `main` 5129be10. - New tests: `pipeline_workers` (the pool, CPU), `replay_pipeline_compiles` and `_strict` (3000 random submissions and fixed cases give the same result, pipelines, drops and compiles with and without the pool; CPU), `d3d12_pipeline_workers` and `_eager` (GPU: 48 graphics and 16 compute pipelines, the same bytes with 0, 1, 4 and 16 workers; refused compiles; two queues; pipeline states released and the device destroyed while a submission compiles). The GPU tests skip without a Vulkan device and below the 144-byte push constants. - Each new test fails for the changes that should fail it: 36 CPU and 15 GPU mutants (a dropped wait, lock, drain or dedup among them) all fail, the originals pass 30 repeated runs. - Full `ctest` of `main` 5129be10 and of this branch on it, compared test by test: 337 tests before (324 pass, 13 skip), 342 after (329, 13), no failure and no other status. - `test_ctest_registration`, `test_docs_links`, `test_docs_cli_flags`, `test_text_write_line_endings`, `git diff --check` and `check_no_game_data.py` pass. Not run: the title. I do not have the package, so the effect on boot time and frame time is for someone who has it to measure. No Vulkan SDK here, so the Khronos validation layer did not run, and the `d3d12` tests that need `glslangValidator` or `llvm-mc` were not built. Other GPUs were not run. The compile of one very large pipeline is not faster. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.24, Windows 11 (10.0.26300). AI-assisted: yes (Claude Code) ### 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (none added)
PipelineWorkers::run is a blocking parallel loop: the calling thread works on its own batch beside the workers, so a batch completes with no worker left and nothing outlives the call. CPU test: every job once and before run returns, no workers, exceptions, several callers, stop with jobs queued, and the LEONIDA_PIPELINE_THREADS text.
prepare() leaves the pipelines that are not built yet to PipelineCompiles, once per pipeline and variant. VulkanQueue::execute_now compiles them together on the device's workers with the resource lock held, places them in the prepared commands and then writes the command buffer, so every draw and dispatch has its own pipeline. A refused compile gives the result prepare() alone would have given. LEONIDA_PIPELINE_THREADS=0 keeps the path of before. Graphics pipelines of 1 MiB of SPIR-V or more and compute pipelines over 128 KiB compile one after another, and LEONIDA_ASYNC_PIPELINES keeps its own worker.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:10 +00:00
github manually merged commit 3e1c49e1bd into gh-pr/1547/base 2026-11-26 09:56:11 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-11-25 05:39 UTC · original

Retail check on an RTX 4070 Laptop (driver 32.0.15.9159, native Windows), main c7e82e26e + #1558, empty NVIDIA disk cache each run, the title's watchdog armed, A pressed every 15 s:

  • without #1547: 2 of 3 runs stall right after the first A on the landing screen (the submit lock held 15 s+, device-stall lines) and the title's hang watchdog ends them (+0x2215c35). With LEONIDA_TITLE_WATCHDOG=0 such a run recovers into the story load, so it is the compiles, not a deadlock;
  • with #1547: 2 of 2 runs go past that point into the story load (69-75 k slot-70 views). One was still running at 300 s; the other met the watchdog later, at 321 s in the story load, after 4 lock stalls. The big library compute programs that still compile one at a time are the likely remainder.

So on this laptop #1547 removes the landing-screen stall. No device loss in either #1547 run.

Measured with Claude Code.

**@⁠OreoFR** on GitHub · 2026-11-25 05:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1547#issuecomment-7153999451) Retail check on an RTX 4070 Laptop (driver 32.0.15.9159, native Windows), main `c7e82e26e` + #1558, empty NVIDIA disk cache each run, the title's watchdog armed, A pressed every 15 s: - **without #1547:** 2 of 3 runs stall right after the first A on the landing screen (the submit lock held 15 s+, `device-stall` lines) and the title's hang watchdog ends them (`+0x2215c35`). With `LEONIDA_TITLE_WATCHDOG=0` such a run recovers into the story load, so it is the compiles, not a deadlock; - **with #1547:** 2 of 2 runs go past that point into the story load (69-75 k slot-70 views). One was still running at 300 s; the other met the watchdog later, at 321 s in the story load, after 4 lock stalls. The big library compute programs that still compile one at a time are the likely remainder. So on this laptop #1547 removes the landing-screen stall. No device loss in either #1547 run. Measured with Claude Code.
Author
Owner

@⁠Snooozs on GitHub · 2026-11-25 06:40 UTC · original

Retail run with this on main 42537e7b6 + #1558, RTX 5060 Ti (NVIDIA 621.01), Windows 10 19045, Ryzen 7 7700, own copy, LEONIDA_TITLE_WATCHDOG=0: 3 of 3 runs reach the story load at 80 to 95 s and go on into the world phase; no stop points at the compile workers (details and the stops in #1608). I had a 2 GB library cache loaded and did not compare without this PR, so no timing claim. I read only the runtime diff's outline, not every line.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠Snooozs** on GitHub · 2026-11-25 06:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1547#issuecomment-7155036408) Retail run with this on `main` `42537e7b6` + #1558, RTX 5060 Ti (NVIDIA 621.01), Windows 10 19045, Ryzen 7 7700, own copy, `LEONIDA_TITLE_WATCHDOG=0`: 3 of 3 runs reach the story load at 80 to 95 s and go on into the world phase; no stop points at the compile workers (details and the stops in #1608). I had a 2 GB library cache loaded and did not compare without this PR, so no timing claim. I read only the runtime diff's outline, not every line. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 09:24 UTC · original

Merged. Reviewed and tested locally: no regressions. Thanks, and thanks to OreoFR and Snooozs for the retail runs.

  • Clean merge with current main. The claim in #14 predates the PR, and nobody else claimed this item.
  • Windows suite (clang-cl, under Wine, llvmpipe and an AMD iGPU): pipeline_workers, replay_pipeline_compiles, _strict, d3d12_pipeline_workers and _eager pass on both devices, and the full suite has no test going from pass to fail.
  • Read the lock order: compile jobs never take resource_mutex_, so holding it shared across PipelineWorkers::run is safe.
  • Minor, not blocking: a dispatch whose compile fails now goes through the rest of prepare() before it is dropped, where main dropped it at once. That looks harmless, but a line in the comment on build_pipelines would help.
  • #1577 (RT-PIPELINE-COMPILER-WORKERS) also edits runtime/CMakeLists.txt, so it may need a rebase now.
  • Checked on main 626d1281a + 3e1c49e1b: it merges cleanly; the semantic suite passes (487 files, 6,279 tests, 0 files failed); the 14 docs and writer tests pass; check_no_game_data.py is clean on the 10 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 09:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1547#issuecomment-7158290033) Merged. Reviewed and tested locally: no regressions. Thanks, and thanks to OreoFR and Snooozs for the retail runs. - Clean merge with current `main`. The claim in #14 predates the PR, and nobody else claimed this item. - Windows suite (clang-cl, under Wine, llvmpipe and an AMD iGPU): `pipeline_workers`, `replay_pipeline_compiles`, `_strict`, `d3d12_pipeline_workers` and `_eager` pass on both devices, and the full suite has no test going from pass to fail. - Read the lock order: compile jobs never take `resource_mutex_`, so holding it shared across `PipelineWorkers::run` is safe. - Minor, not blocking: a dispatch whose compile fails now goes through the rest of `prepare()` before it is dropped, where `main` dropped it at once. That looks harmless, but a line in the comment on `build_pipelines` would help. - #1577 (`RT-PIPELINE-COMPILER-WORKERS`) also edits `runtime/CMakeLists.txt`, so it may need a rebase now. - **Checked on `main` `626d1281a` + `3e1c49e1b`:** it merges cleanly; the semantic suite passes (487 files, 6,279 tests, 0 files failed); the 14 docs and writer tests pass; `check_no_game_data.py` is clean on the 10 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.