Repository navigation
d3d12: compile a submission's pipelines on worker threads (RT-PIPELINE-COMPILE-WORKERS) - #1547
Conversation
…PILE-WORKERS) 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.
…E-COMPILE-WORKERS) 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.
|
Retail check on an RTX 4070 Laptop (driver 32.0.15.9159, native Windows), main
So on this laptop #1547 removes the landing-screen stall. No device loss in either #1547 run. Measured with Claude Code. |
|
Retail run with this on AI-assisted (Claude Code, Claude Opus 5.5). |
|
Merged. Reviewed and tested locally: no regressions. Thanks, and thanks to OreoFR and Snooozs for the retail runs.
AI-assisted (Claude Code, Claude Opus 5.5). |
…-fallback Merging. **Why merged** - Fixes the NVIDIA startup stop that #939 introduced. Slot 133 asks for a D16S8 (format 118) depth texture with unordered access. On NVIDIA, `pc_format()` maps it to D24S8 and the depth provider refuses UAV on that, so the boot died early. With this PR the refusal is logged once and the texture is made without UAV, i.e. the pre-#939 stand-in. - Independent real-boot confirmations past the stop, each against the same build without the PR stopping there: - RTX 4070 SUPER, Windows 11; - RTX 5060 Ti, Windows 10 (Snooozs); - RTX 3070 Ti, Wine 11.22 (djrolfes); - RTX 3080 Ti, Wine 11.17 (slauko: 603 s, no exception); - RTX 3090, Proton (azsekazvamdimitar). - On AMD (adrianmjim, RX 7900 XT) the native path is untouched and the related tests pass, including a GPU without D24S8 that falls back to D32S8. - Re-tested here merged onto 3de22a1 (after #1547) on an RTX 4070 SUPER, and the merge onto the current main (57ba40b, which only adds #1493's translator change) is also clean: - fresh RelWithDebInfo build; - full ctest 410/411, where the only failure is `d3d12_depth_resolve`, the known NVIDIA MFAA sample-position case fixed by #1505; - the PR's 16 related tests pass, also with `LEONIDA_VK_VALIDATION=1`; - the consistency set is the same as main. **Why it's good** - It's a narrow fallback, used only when the provider refuses. Consoles and GPUs that accept the format keep the native path. - It comes with tests for the refused and accepted cases. - It unblocks every NVIDIA tester at the same spot. **Known and separate:** the slot 133 stand-in leaks about 60 Vulkan objects at device teardown under validation. That leak predates this PR and is reported in #1608. Full D16S8 UAV semantics on NVIDIA remain a follow-up. AI-assisted (Claude Code, Claude Opus 5.5).
Claimed in the coordination issue as: RT-PIPELINE-COMPILE-WORKERS (#14 (comment))
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 toPipelineCompiles, once per pipeline and variant.VulkanQueue::execute_nowcompiles 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.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).LEONIDA_PIPELINE_THREADS=<n>sets the workers: unset, half the logical processors and at most 8;0keeps the path of before.LEONIDA_SERIAL_BIG_COMPILES) still compile one after another, beside the smaller ones:docs/pipeline_check.mdmeasured 1.96 GB for one 5.7 MB module.big_compileitself is as it was (the finding in Coordinating who works on what #14 (comment) is another topic).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
main2213d5c,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:LEONIDA_PIPELINE_THREADS=0The second submission and
CreatePipelineStatetake the same. The process holds about 50 MiB more (the driver keeps memory for each thread that compiles). Through one sharedVkPipelineCache192 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 ontomain5129be1.New tests:
pipeline_workers(the pool, CPU),replay_pipeline_compilesand_strict(3000 random submissions and fixed cases give the same result, pipelines, drops and compiles with and without the pool; CPU),d3d12_pipeline_workersand_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
ctestofmain5129be1 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 --checkandcheck_no_game_data.pypass.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
d3d12tests that needglslangValidatororllvm-mcwere 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (none added)