[PR #1577] [CLOSED] d3d12: parallel PipelineCompiler workers with reserved demand lane (RT-PIPELINE-COMPILER-WORKERS) #1597

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

📋 Pull Request Information

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

Base: main ← Head: feat/pipeline-compiler-workers


📝 Commits (1)

  • b9ce8f2 d3d12: parallel PipelineCompiler workers with reserved demand lane (RT-PIPELINE-COMPILER-WORKERS)

📊 Changes

3 files changed (+268 additions, -9 deletions)

View changed files

📝 runtime/CMakeLists.txt (+9 -0)
📝 runtime/shims/d3d12_pipeline_compile.h (+62 -9)
➕ runtime/test/pipeline_compiler_test.cpp (+197 -0)

📄 Description

Claimed in the coordination issue as: RT-PIPELINE-COMPILER-WORKERS (addresses unclaimed finding 7150502283 on #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 left PipelineCompiler / d3d12_pipeline_compile.h separate).

What and why

rt::d3d12::PipelineCompiler in runtime/shims/d3d12_pipeline_compile.h previously ran a single THREAD_PRIORITY_BELOW_NORMAL worker for both speculative compute warmup and demanded async builds (LEONIDA_ASYNC_PIPELINES=1). As noted in finding 7150502283 on #14, a long driver compile in that single worker stalls every other queued pipeline build behind it.

This change upgrades PipelineCompiler to a bounded worker pool while preserving existing single-worker semantics when requested:

  • Configurable worker count (LEONIDA_COMPILE_THREADS, 1..32): defaults to 2..6 workers based on std::thread::hardware_concurrency() (>=18 -> 6, >=12 -> 4, >=6 -> 3, else 2). LEONIDA_COMPILE_THREADS=1 preserves the strict single-worker behavior.
  • Demand-lane reservation (workers >= 2): demanded builds (priority == 0) can run across all N workers; speculative warmup jobs (0 < priority < SIZE_MAX) are capped at N - 1 concurrent workers so at least one worker remains available for demanded builds without starving behind warmup.
  • Idle checkpoint & waiter accounting: SIZE_MAX idle checkpoints wait until running_ == 0, and has_compile_waiter() counts in-flight compile jobs (compile_running_ > 0) in addition to queued non-checkpoint jobs so cache checkpoints back off cleanly.
  • Safe standalone instances: explicit PipelineCompiler(unsigned workers = 0) constructor and joining destructor enable isolated unit tests while instance() stays a process-lifetime singleton.

Per-PSO variants_mutex_, big_compile serialization (>128 KiB), std::atomic<unsigned> active_compiles, publication mutex, and driver-synchronized VkPipelineCache (created without EXTERNALLY_SYNCHRONIZED_BIT) already guard concurrent compilation across call sites in d3d12_vulkan_device.cpp.

Tested

  • Cross-compiled new runtime/test/pipeline_compiler_test.cpp with clang-cl --target=x86_64-pc-windows-msvc /std:c++20 /O2 /W4 /permissive- /utf-8 (0 warnings in d3d12_pipeline_compile.h and pipeline_compiler_test.cpp) and ran under Wine 11.22 on Arch Linux (Intel Core i7-12700):
    • test_worker_count_config (hardware concurrency tiers + valid/invalid LEONIDA_COMPILE_THREADS values)
    • 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 fills N-1 workers and caps further warmup)
    • test_checkpoint_waits_for_idle (has_compile_waiter() reflects in-flight compiles; SIZE_MAX checkpoint runs only after active compiles finish)
    • test_single_worker_strict_order (workers=1 drains 0, smallest warmup, then SIZE_MAX)
    • Result: 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

  • 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: no translator change)

🔄 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/1577 **Author:** [@madhyn](https://github.com/madhyn) **Created:** 11/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/pipeline-compiler-workers` --- ### 📝 Commits (1) - [`b9ce8f2`](https://github.com/ubiquitarianism/leonida/commit/b9ce8f26c16a7848b06eb7357085c53f4071cec9) d3d12: parallel PipelineCompiler workers with reserved demand lane (RT-PIPELINE-COMPILER-WORKERS) ### 📊 Changes **3 files changed** (+268 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+9 -0) 📝 `runtime/shims/d3d12_pipeline_compile.h` (+62 -9) ➕ `runtime/test/pipeline_compiler_test.cpp` (+197 -0) </details> ### 📄 Description Claimed in the coordination issue as: `RT-PIPELINE-COMPILER-WORKERS` (addresses unclaimed finding `7150502283` on #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 left `PipelineCompiler` / `d3d12_pipeline_compile.h` separate). ### What and why `rt::d3d12::PipelineCompiler` in `runtime/shims/d3d12_pipeline_compile.h` previously ran a single `THREAD_PRIORITY_BELOW_NORMAL` worker for both speculative compute warmup and demanded async builds (`LEONIDA_ASYNC_PIPELINES=1`). As noted in finding `7150502283` on #14, a long driver compile in that single worker stalls every other queued pipeline build behind it. This change upgrades `PipelineCompiler` to a bounded worker pool while preserving existing single-worker semantics when requested: - **Configurable worker count (`LEONIDA_COMPILE_THREADS`, `1..32`):** defaults to 2..6 workers based on `std::thread::hardware_concurrency()` (`>=18 -> 6`, `>=12 -> 4`, `>=6 -> 3`, else `2`). `LEONIDA_COMPILE_THREADS=1` preserves the strict single-worker behavior. - **Demand-lane reservation (`workers >= 2`):** demanded builds (`priority == 0`) can run across all `N` workers; speculative warmup jobs (`0 < priority < SIZE_MAX`) are capped at `N - 1` concurrent workers so at least one worker remains available for demanded builds without starving behind warmup. - **Idle checkpoint & waiter accounting:** `SIZE_MAX` idle checkpoints wait until `running_ == 0`, and `has_compile_waiter()` counts in-flight compile jobs (`compile_running_ > 0`) in addition to queued non-checkpoint jobs so cache checkpoints back off cleanly. - **Safe standalone instances:** explicit `PipelineCompiler(unsigned workers = 0)` constructor and joining destructor enable isolated unit tests while `instance()` stays a process-lifetime singleton. Per-PSO `variants_mutex_`, `big_compile` serialization (`>128 KiB`), `std::atomic<unsigned> active_compiles`, `publication` mutex, and driver-synchronized `VkPipelineCache` (created without `EXTERNALLY_SYNCHRONIZED_BIT`) already guard concurrent compilation across call sites in `d3d12_vulkan_device.cpp`. ### Tested - Cross-compiled new `runtime/test/pipeline_compiler_test.cpp` with `clang-cl --target=x86_64-pc-windows-msvc /std:c++20 /O2 /W4 /permissive- /utf-8` (0 warnings in `d3d12_pipeline_compile.h` and `pipeline_compiler_test.cpp`) and ran under Wine 11.22 on Arch Linux (Intel Core i7-12700): - `test_worker_count_config` (hardware concurrency tiers + valid/invalid `LEONIDA_COMPILE_THREADS` values) - `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 fills `N-1` workers and caps further warmup) - `test_checkpoint_waits_for_idle` (`has_compile_waiter()` reflects in-flight compiles; `SIZE_MAX` checkpoint runs only after active compiles finish) - `test_single_worker_strict_order` (`workers=1` drains `0`, smallest warmup, then `SIZE_MAX`) - Result: `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 - [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. (n/a: no translator change) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:21:48 +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#1597
No description provided.