Skip to content

d3d12: compile pool defaults to 2 large builds and sizes from the affinity mask - #2651

Closed
Tyrannys wants to merge 2 commits into
ProjectLeonida:mainfrom
Tyrannys:claude/compile-pool-load-stall
Closed

Tyrannys wants to merge 2 commits into
ProjectLeonida:mainfrom
Tyrannys:claude/compile-pool-load-stall

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: COMPILE-POOL-SAFE-DEFAULT (#1608 (comment)). Found by z3r0rc (#1608 (comment)).

What and why

#2233's compile pool runs 8 workers by default, and lets threads-1 = 7 of them build large modules at once. z3r0rc bisected a story-load stall under Wine to exactly that PR:

  • With the defaults, the load slows from ~50-79 submissions/s to 0.1-0.5/s at about 5,100 submissions and never recovers, so the title's 300 s stall guard fires.
  • With LEONIDA_COMPILE_THREADS=1, the same build lives to the end of the run.

Our own native Windows boots (8 workers, 7 large) show the same knee, milder:

  • 8 runs from a 43-47/s plateau down to 0.06-0.6/s, starting at 5,013-5,717 submissions.
  • The troughs last 15-60 s and recover in 20-60 s. One run had a 118 s gap between submission reports.

A CPU stress run of PipelineCompiler rules out the queue itself:

  • The setup: 1 worker vs 8, 20,000 warm-ups queued, and 8 demanded builds at every submission.
  • Both ran at ~1,990 submissions/s, with the same cost per submit (~2 µs, 0.2 ms at worst).
  • So the stall is not a lost wake-up or a priority bug in the queue. What changed is how many builds run in the driver and on the host at once.

This PR is the safe default; the root cause is still open:

  • Large builds: LEONIDA_COMPILE_HEAVY_MAX now defaults to 2 (1 with two workers). That is the most the general worker and the graphics-only worker could run before the pool. An explicit count still wins, so LEONIDA_COMPILE_HEAVY_MAX=7 gives the old behavior.
  • Worker count: the default is half the processors in the process's affinity mask (GetProcessAffinityMask), still 2 to 8. It was half of std::thread::hardware_concurrency(), the machine's count. A process limited to 4 of 32 processors now starts 2 workers, not 8. The pool's startup line also prints the processor count.
  • Follow-up: whether the memory gate's budget is right under Wine and in containers (it reads GlobalMemoryStatusEx). That waits for z3r0rc's A/Bs (LEONIDA_COMPILE_HEAVY_MAX=1, LEONIDA_COMPILE_THREADS=2, LEONIDA_BIG_COMPILE_BUDGET_MB=4096).

Docs: docs/d3d12_vulkan.md and runtime/README.md give the new defaults and why.

Tested

  • d3d12_compile_pool_test covers the new settings:
    • 16 processors give 8 workers and 2 large builds; an explicit 7 is kept.
    • With LEONIDA_SERIAL_BIG_COMPILES=1, 1 large build.
    • An affinity mask of 4 out of 32 processors gives 2 workers; 6 processors give 3 workers and 2 large builds.
    • An unreadable mask falls back to the machine's count.
    • All the existing scheduling cases still pass.
  • d3d12_compile_teardown_test passes.
  • MSVC 17, Release. No game data.
  • Under Linux/Wine by @zmasi (Coordinating who works on what (continued from #14) #1608 (comment)): all three CTests pass on gfx906 / RADV with validation and sync validation clean. With real process masks, 4 allowed processors gave 2 workers and 1 large build and 16 gave 8 and 2, against 8 and 7 on the parent on the same 32-processor host.
  • Not yet tested in a boot. z3r0rc offered to test it under Wine, and we will A/B it on Windows after our current boots.

GPUs tested: RTX 4070 SUPER (d3d12_compile_teardown_test); the pool test is CPU only.

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.

🤖 Generated with Claude Code

Tyrannys and others added 2 commits November 28, 2026 00:16
…inity mask

With ProjectLeonida#2233's defaults (8 workers, threads-1 = 7 large builds at once), a
story load under Wine slowed from ~50-79 submissions/s to 0.1-0.5/s at
about 5,100 submissions and never recovered, so the title's 300 s stall
guard fired; with LEONIDA_COMPILE_THREADS=1 the same build lived
(z3r0rc, ProjectLeonida#1608). Native Windows boots show the same knee at ~5,000-5,700
submissions, with troughs of 0.06-0.6/s that recover in 20-60 s.

A CPU stress run of PipelineCompiler (1 vs 8 workers, 20,000 warm-ups
queued, demanded builds at every submission) queued at the same rate
both ways, so the queue itself is not the stall; what changed is how
many builds run in the driver and on the host at once.

- LEONIDA_COMPILE_HEAVY_MAX defaults to 2 (1 with two workers), the
  most the general and graphics-only workers could run before the pool.
  An explicit count still wins.
- The default worker count is half the processors in the process's
  affinity mask, not the machine's count, so a process limited to some
  processors does not start more workers than it can run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…zed from

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@merzleckeier

Copy link
Copy Markdown
Contributor

Independent Wine retest of cb68d1ac (GitHub merge 6a954d86 onto 452d1d1b). Win64 clang-cl 23.1.5 Release (/MD), Wine 11.22. Synthetic fixtures only.

MEASURED, scheduler capacity. I submitted eight large-class and eight small-class callbacks to the real PipelineCompiler, with separate gates that held running jobs until their counts could be read. The uninstrumented pool test passed 3/3 per revision. Every configuration below was exercised three times, and all 42 capacity probes completed all 16 jobs with zero drops.

Default configuration Base workers / large limit PR workers / large limit
All 16 logical CPUs 8 / 7 8 / 2
Linux taskset -c 1,3,5,7,9,11 8 / 7 3 / 2
Linux taskset -c 8,10,12,14 8 / 7 2 / 1
Win32 SetProcessAffinityMask(0x5500) after unrestricted startup 8 / 7 2 / 1
Linux taskset -c 13 8 / 7 2 / 1

On all 16 CPUs, the base ran seven parked large callbacks alongside one small callback. The PR ran two large and six small callbacks concurrently. An explicit 8/7 restored the base result even with LEONIDA_SERIAL_BIG_COMPILES=1. Serial alone produced 8/1. An explicit 4/7 clamped to 4/3. These runs exercise scheduling with held jobs.

MEASURED, GPU teardown. The unmodified teardown fixture completed 3/3 per revision per GPU on RTX 4070 SUPER (620.73.04) and Radeon Raphael (RADV 26.3.1). I enabled Khronos validation in the host loader because the layer was unavailable to the test inside Wine. Each run reported the same vkCreateDevice-ppEnabledExtensionNames-01387 diagnostic for missing VK_KHR_external_memory_fd required by VK_EXT_external_memory_dma_buf, on both revisions and GPUs. Story-load behavior remains open.

AI-assisted with OpenAI Codex.

@fiestorra

Copy link
Copy Markdown
Contributor

Verified on main 452d1d1b6, Windows 11, Ninja + RelWithDebInfo, RTX 4090:

git merge-tree origin/main refs/pull/2651/head   -> clean
cherry-pick be588dae, cb68d1ac                   -> clean
cmake --build … --target d3d12_compile_pool_test -> built
d3d12_compile_pool_test.exe                      -> exit 0, PASS d3d12_compile_pool

The header change compiles through the shim (that target links it), and the test the pull request extends passes with the change rather than instead of it: runtime/test/d3d12_compile_pool_test.cpp is +19/-2 in this diff, so it exercises the new sizing.

What the two commits do, in their own words: the pool now defaults to 2 large builds and sizes itself from the affinity mask, and its startup line names the processors it was sized from - which is the part I would have wanted the first time a pool size was questioned in a log.

Not tested: the full runtime build (gta6rt) and any run of the title - I built the test target only, because that is what carries the change; and the affinity-mask sizing was exercised on this machine's single CPU group, so a multi-group box is not covered by what I ran.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor

Independent verification on this machine (Windows 11, MSVC 19.44.35226), and the honest result is "builds and passes, but the negative control is impossible by design" - which is itself informative here.

1. It applies. merge-tree clean; the two commits cherry-pick onto main 1d22590b9 without a conflict. Four files, 57 insertions(+), 14 deletions(-).

2. It builds and passes, three times:

cmake --build runtime/build-ninja --target d3d12_compile_pool_test   -> linked
d3d12_compile_pool_test.exe                                          -> exit 0, 0, 0, "PASS d3d12_compile_pool"

3. The negative control does not work the way it usually does, and the reason is worth stating. Reverting only runtime/shims/d3d12_pipeline_compile.h to main and rebuilding fails to compile:

d3d12_compile_pool_test.cpp(166): error C2039: 'affinity_…' is not a member of …
d3d12_compile_pool_test.cpp(166): error C3861: 'affinity_…' identifier not found
d3d12_compile_pool_test.cpp(174): error C3…

The test asserts on pool.affinity_…, the per-group sizing this PR adds, so the test cannot exist without the code - there is no "old behaviour" to run it against. That is a cleaner coupling than a numeric assertion, but it means the usual "revert the source and watch it fail" check is unavailable; what it proves is that the test exercises the new API, not that the new defaults are right.

A measurement error I made and caught: my first attempt at that control ran the previous binary - the build had failed and I suppressed the output, so exit 0 came from the old executable. Comparing the .exe timestamp (unchanged, 06:28:09) is what exposed it. Recording it because "the test still passes" was one sentence from being published.

What I did not test: the behaviour the defaults actually change. heavy going from threads-1 to 2, and threads deriving from the affinity mask instead of the machine's count, are decisions about compile throughput under the title; the test checks the numbers the constructor produces, not what the pool does with a real shader load. Someone with the game and a story load has the measurement that matters.

Written with an AI assistant.

@KelboLive

Copy link
Copy Markdown

Independent check on Windows (not the author), at cb68d1ac7.

  • Configured the branch's runtime and built d3d12_compile_pool_test (MSVC 14.52.37025, Windows SDK 10.0.26100).
  • Ran it: PASS d3d12_compile_pool — exit 0.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711.

Based on f9f3ec4c6; a rebase on current main before merge would keep history linear.

AI-assisted: yes (opencode).

@merzleckeier

Copy link
Copy Markdown
Contributor

Follow-up check of the compile pool together with the background budget. I merged cb68d1ac and #2786 (8a583eb05) onto ed867d7b2. A synthetic fixture used the actual PipelineCompiler and LargeModuleGate, with the 16-CPU pool configuration (8 workers, 2 large slots) and gate budget 100. With #2651 alone, background estimates 35 + 35 both entered using the existing demand classification. A synchronous foreground estimate of 50 had to wait. With both PRs, the first background job entered, the second waited under the background gate, and the foreground job entered before either background job was released. A small queued job completed in both arms. Both observations held in 3/3 fresh Windows-binary runs per arm under Wine 11.22. The callbacks are synthetic and this measures ordering, without driver compiler or frame-time measurements.

AI-assisted with OpenAI Codex.

@aslan2142

Copy link
Copy Markdown
Collaborator

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

@aslan2142 aslan2142 closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants