Repository navigation
d3d12: parallel PipelineCompiler workers with reserved demand lane (RT-PIPELINE-COMPILER-WORKERS) - #1577
d3d12: parallel PipelineCompiler workers with reserved demand lane (RT-PIPELINE-COMPILER-WORKERS)#1577madhyn wants to merge 1 commit into
Conversation
…T-PIPELINE-COMPILER-WORKERS) Upgrade rt::d3d12::PipelineCompiler from a single below-normal worker to a bounded worker pool (LEONIDA_COMPILE_THREADS, default 2..6 by hardware concurrency; 1 preserves the single-worker path). With two or more workers, speculative compute warmup is capped at N-1 concurrent jobs so at least one worker stays reserved for demanded priority-0 builds, and SIZE_MAX idle checkpoints wait until no compile jobs are running. Also count in-flight compile jobs in has_compile_waiter(). Add unit tests in runtime/test/pipeline_compiler_test.cpp covering parallel demanded builds, demand-lane reservation, idle checkpoint ordering, single-worker priority order, and LEONIDA_COMPILE_THREADS parsing.
|
One real-boot observation, n=1 and with a caveat (Windows 11, RTX 4070 SUPER, NVIDIA 621.24; main c7e82e2 + #1558 + this PR at b9ce8f2, with a fresh pipeline cache folder and the title's hang watchdog left on). Right after the first ExecuteIndirect at world start, the D3D12 call stream stopped for about 30 s while four pipeline-library compute pipelines of about 1.0 MB each built one after another (14.2 + 3.0 + 7.4 + 7.0 s = 31.6 s), and the watchdog ended the process. So when one submission needs several uncompiled pipelines in a row, the reserved demand lane still serves them in sequence on the submitting thread. Each demand build blocks before the next one starts. The case of building a submission's pipelines side by side, which #1547 targets, might need to be combined with this. Caveat: each cold boot compiles a different subset of the library (no overlap between four runs' build lists), and four large builds lining up at world start happened in 3 of 6 runs tonight with or without either PR. So one run can't rank the PRs. I'll repeat it with more runs per arm and post counts. AI-assisted (Claude Code, Claude Opus 5.5). |
|
Native Windows run of this PR's unit test: Windows 11, 16 threads, NVIDIA RTX 4060 (610.88), MSVC (VS 2026 Community), main
One review note on what the extra workers can reach. On AI-assisted (Claude Code). No game files. |
|
Closing this one. Since #1547 was merged and #1723 brought in the new PipelineCompiler lifetime model (cancel / after_running / retain-release / stop_for_exit), this pool design doesn't fit the current main anymore. As @QemmHD and @minimob1337 pointed out (thanks to both for testing and reviewing), the process-wide big_compile gate still serializes large modules no matter how many workers there are, so the extra workers would gain little. A priority-aware big_compile gate, so demanded builds don't wait behind warm-up, would be a better follow-up as its own small PR. |
Claimed in the coordination issue as:
RT-PIPELINE-COMPILER-WORKERS(addresses unclaimed finding7150502283on #14; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 file overlap with #1547, which explicitly leftPipelineCompiler/d3d12_pipeline_compile.hseparate).What and why
rt::d3d12::PipelineCompilerinruntime/shims/d3d12_pipeline_compile.hpreviously ran a singleTHREAD_PRIORITY_BELOW_NORMALworker for both speculative compute warmup and demanded async builds (LEONIDA_ASYNC_PIPELINES=1). As noted in finding7150502283on #14, a long driver compile in that single worker stalls every other queued pipeline build behind it.This change upgrades
PipelineCompilerto a bounded worker pool while preserving existing single-worker semantics when requested:LEONIDA_COMPILE_THREADS,1..32): defaults to 2..6 workers based onstd::thread::hardware_concurrency()(>=18 -> 6,>=12 -> 4,>=6 -> 3, else2).LEONIDA_COMPILE_THREADS=1preserves the strict single-worker behavior.workers >= 2): demanded builds (priority == 0) can run across allNworkers; speculative warmup jobs (0 < priority < SIZE_MAX) are capped atN - 1concurrent workers so at least one worker remains available for demanded builds without starving behind warmup.SIZE_MAXidle checkpoints wait untilrunning_ == 0, andhas_compile_waiter()counts in-flight compile jobs (compile_running_ > 0) in addition to queued non-checkpoint jobs so cache checkpoints back off cleanly.PipelineCompiler(unsigned workers = 0)constructor and joining destructor enable isolated unit tests whileinstance()stays a process-lifetime singleton.Per-PSO
variants_mutex_,big_compileserialization (>128 KiB),std::atomic<unsigned> active_compiles,publicationmutex, and driver-synchronizedVkPipelineCache(created withoutEXTERNALLY_SYNCHRONIZED_BIT) already guard concurrent compilation across call sites ind3d12_vulkan_device.cpp.Tested
runtime/test/pipeline_compiler_test.cppwithclang-cl --target=x86_64-pc-windows-msvc /std:c++20 /O2 /W4 /permissive- /utf-8(0 warnings ind3d12_pipeline_compile.handpipeline_compiler_test.cpp) and ran under Wine 11.22 on Arch Linux (Intel Core i7-12700):test_worker_count_config(hardware concurrency tiers + valid/invalidLEONIDA_COMPILE_THREADSvalues)test_parallel_demand(2 demanded jobs reach a barrier concurrently on a 2-worker pool)test_demand_lane_reserved(demanded job finishes immediately while speculative warmup fillsN-1workers and caps further warmup)test_checkpoint_waits_for_idle(has_compile_waiter()reflects in-flight compiles;SIZE_MAXcheckpoint runs only after active compiles finish)test_single_worker_strict_order(workers=1drains0, smallest warmup, thenSIZE_MAX)pipeline_compiler: all checks passed(17/17 checks).python3 scripts/check_no_game_data.py: passed.GPUs tested: n/a for unit test (CPU scheduler test); also exercised with live Vulkan pipeline compilation on NVIDIA GeForce RTX 3060 Ti (8 GB, NVIDIA Linux driver + Wine 11.22, Arch Linux x86_64).
AI-assisted: yes (Antigravity)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)