Skip to content

D3D12-PIPELINE-CREATE-LOCK-AMD: serialize driver PSO creation on AMD - #2694

Open
bobcatchris wants to merge 5 commits into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-pipeline-create-lock-amd
Open

bobcatchris wants to merge 5 commits into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-pipeline-create-lock-amd

Conversation

@bobcatchris

@bobcatchris bobcatchris commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On AMD RDNA 3 (RX 7900 XTX, amdxc64.dll 32.0.32029.2010, Windows 11), default 10-thread early pipeline compilation hits a deterministic driver crash (0xc0000005 inside amdxc64.dll or 0x887A0020 DXGI_ERROR_DRIVER_INTERNAL_ERROR) when multiple pipeline worker threads call CreateGraphicsPipelineState / CreateComputePipelineState / CreatePipelineState concurrently:

  • Still crashes with LEONIDA_LIBRARY_LOCK=1 (which only locks Load*Pipeline / StorePipeline, not create()).
  • Still crashes with LEONIDA_PIPELINE_LIBRARY=0 (bypassing the pipeline library completely).
  • Setting LEONIDA_PIPELINE_WORKERS=1 avoids the crash, but sacrifices all parallel DXIL shader translation across CPU cores.

In addition, an unprioritized global Mutex<()> can cause priority inversion during cutscenes / new camera angles: background Early or Slow driver compiles (1-73 s on AMD) hold the create lock while draw-critical Screen / Requested pipelines wait behind them.

Fix

In d3d12/crates/leonida-gpu/src/pipeline/library.rs and d3d12/crates/leonida-gpu/src/pipeline/make.rs:

  • Add should_serialize_create(env, vendor_id) + CreatePriority::{Screen, Requested, Early, Slow} + CreateGate (serialized adapters only; non-AMD adapters keep concurrent create() unless LEONIDA_PIPELINE_CREATE_LOCK=1 is set).
  • Pending::make() scopes with_create_priority(CreatePriority) so Screen > Requested > Early > Slow strictly wins the AMD create lock once the active call finishes.
  • While a driver create() call holds the serialized lock (create_busy()), Queue::pop_with(..., slow_blocked) avoids popping speculative Slow jobs so worker threads stay free for Screen / Requested / Early work and workers() re-wakes when the gate clears.

Verification

  • Hardware/OS: Windows 11 Pro (10.0.26200), Ryzen 7 7800X3D, AMD Radeon RX 7900 XTX (gfx1100, driver 32.0.32029.2010), pinned rustc 1.98.1.
  • cargo test -p leonida-gpu --lib pipeline: 36 passed, 0 failed, 7 ignored (in d3d12, covering priority ordering and concurrent serialization tests).
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/pipeline/library.rs d3d12/crates/leonida-gpu/src/pipeline/make.rs: PASS.
  • Live RX 7900 XTX launch with 10 pipeline workers: logs serializing host pipeline state creation (LEONIDA_PIPELINE_CREATE_LOCK) vendor=Some("0x1002") and runs cleanly with 0 refused pipelines.

Claimed in #2570 as D3D12-PIPELINE-CREATE-LOCK-AMD.
AI-assisted: Antigravity (Gemini 4 Neon)

@ecox982745

ecox982745 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Independent native Windows NVIDIA check of 29288a754 on 1d22590b9 (tree 1cb8f3801). Windows 11 build 26300, MSVC, Rust 1.98.1, RTX 4090 (NVIDIA 616.64). The exact pipeline::library subset passed 8/8.

I added a local probe that sends eight concurrent requests through pipeline(), each creating a real D3D12 compute PSO from a tiny synthetic Shader Model 6.0 shader. DXGI confirmed the adapter. I tested both no library key and eight fresh library keys (eight observed load attempts and eight subsequent creates).

Setting Peak callbacks, no key Peak callbacks, library miss Successful PSOs per path
Default, variable unset 8 8 8/8
LEONIDA_PIPELINE_CREATE_LOCK=1 1 1 8/8

Each condition passed in three repeat processes. Peak counts measure entry into the application's creation callbacks. This verifies the NVIDIA path and override with synthetic PSOs. AMD driver reproduction, GPU dispatch, and gameplay were outside this check.

AI-assisted with OpenAI Codex (GPT-6.2 Sol).
Retest on 05c327bf3 after the priority update. This merges cleanly with 0ae217ceb (tree 10728e5a5), which includes merged #2662. The exact library filter passed 9/9, including the new gate priority test. The pipeline worker filter passed 8/8, and the paired shader filter passed 22/22 with host coverage. On the RTX 4090 the same synthetic PSO probe completed 8/8 creates per path, with peak application callback concurrency 8 under the default setting and 1 with the lock forced. Both the no-key and fresh library-miss paths were exercised.

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent Wine PSO check. 05c327bf3 merged onto d367675c7 (tree f0308e20). CachyOS, Wine 11.22, VKD3D-Proton 3.1.0 (0bb64c56c8f0dcc), Rust 1.98.1, x64 MSVC target. Four workers created real D3D12 compute PSOs from a synthetic shader. The counts are peak entries into the application's create callback.

Physical GPU DXGI vendor seen by Mandy Peak, lock env unset Peak, explicit override
AMD Radeon Graphics, RADV 26.3.1 0x1002 1 4 with =0
RTX 4070 SUPER, NVIDIA 620.73.04, DXVK defaults in this test 0x1002 1 4 with =0
Same RTX with dxgi.hideNvidiaGpu = False 0x10de 4 1 with =1

The same peak held with no library key and after fresh library misses. Each path created 4/4 PSOs and all four stored keys reloaded. In this Wine setup the default follows the vendor DXGI reports, so it can serialize on physical NVIDIA hardware. DXVK option.

The test used a seeded empty library on #2694 alone. On AMD, the existing empty-library test failed on both main and #2694. The direct API check returned 0x80070057 for the empty slice and S_OK for a null pointer with zero length. Combining #2654 at 55ac5d337 (tree 82711e462) passed all 18 checked-in library and worker tests on AMD and reproduced the same peaks and reloads with a fresh library, without the seed. VKD3D-Proton input check.

Synthetic PSO creation only. AI-assisted with OpenAI Codex.

@bobcatchris
bobcatchris force-pushed the fix/d3d12-pipeline-create-lock-amd branch from 05c327b to e201dcd Compare November 30, 2026 11:21
@ecox982745

Copy link
Copy Markdown
Contributor

Native Windows cache persistence check on e201dcd90 (#2694) with 55ac5d337 (#2654) on f9f3ec4c6 (combined tree df841387d). MSVC x64, Rust 1.98.1, RTX 4090 on NVIDIA 616.64, Windows 11 build 26300. The ten stock pipeline::library::tests all passed.

I used an isolated cache directory per run and a tiny synthetic compute shader. Eight threads looked up distinct names through the production pipeline library. I ran three cold processes per lock setting. Each made all eight PSOs and saved a nonempty host-pipelines.bin. For each cold cache, two fresh processes reopened it, one with the lock unset and one with LEONIDA_PIPELINE_CREATE_LOCK=1. All 12 warm processes found all eight keys, ran zero creation callbacks, and left the library file byte-identical. DXGI confirmed the RTX 4090, and the probe checked the effective lock setting in each process.

This adds native Windows save and cross-process reload coverage to the earlier concurrency and Wine tests. Synthetic compute PSOs only. AI-assisted with OpenAI Codex (GPT-6.2 Sol).

@merzleckeier

Copy link
Copy Markdown
Contributor

AMD Wine cache round-trip for #2694 + #2654. I tested e201dcd90 with 55ac5d337 on f9f3ec4c6 (combined tree df841387d, same tree as the native RTX 4090 check). Windows x64 MSVC-target Rust 1.98.1, Wine 11.22, VKD3D-Proton 3.1.0 (0bb64c56c8f0dcc), Radeon 610M on RADV 26.3.1. DXGI reported 0x1002. The VKD3D and Mesa shader disk caches were disabled.

MEASURED. All 10 stock library tests passed. In the synthetic probe, eight threads requested distinct named compute PSOs through the production pipeline library. Every cold run started with an empty cache directory. I reopened each saved cache in two fresh Wine processes, one per lock policy.

Process Runs per policy Default AMD lock LEONIDA_PIPELINE_CREATE_LOCK=0
Cold, both PRs 3 8 created and stored, peak 1 create callback 8 created and stored, peak 8 callbacks
Warm, both PRs 6 8 library hits, 0 create callbacks 8 library hits, 0 create callbacks
Cold control, only #2694 (5047d6a1) 3 8 created, library unavailable, no cache file 8 created, library unavailable, no cache file

Each combined cold run saved a 3,176-byte host-pipelines.bin. Its SHA-256 stayed identical after both warm runs, across all six caches. Peak measures application callback entries. The unlocked probe synchronizes callbacks before the driver call. The first Wine prefix initialization timed out before tests. The results above are from the complete run with a newly initialized prefix. A second agent checked the raw logs and file hashes. Synthetic compute only, AI-assisted.

…IPELINE-CREATE-LOCK-AMD)

On AMD RDNA 3 (RX 7900 XTX, amdxc64.dll 32.0.32029.2010), calling
ID3D12Device::Create{Graphics,Compute}PipelineState / CreatePipelineState
concurrently across the default 10 pipeline worker threads triggers an
access violation in amdxc64.dll (0xc0000005) or DXGI_ERROR_DRIVER_INTERNAL_ERROR
(0x887A0020) even when LEONIDA_LIBRARY_LOCK=1 or LEONIDA_PIPELINE_LIBRARY=0.

Serialize only the final driver Create*PipelineState call under an AMD-only
mutex (VendorId == 0x1002, overridable via LEONIDA_PIPELINE_CREATE_LOCK=0|1)
while keeping all worker threads translating DXIL shaders in parallel.
Other GPU vendors (NVIDIA, Intel, WARP) remain unlocked by default.

AI-assisted: Antigravity (Gemini 4 Neon)
AI-assisted: Antigravity (Gemini 4 Neon)
AI-assisted: Antigravity (Gemini 4 Neon)

# Conflicts:
#	d3d12/crates/leonida-gpu/src/pipeline/make.rs
@merzleckeier

Copy link
Copy Markdown
Contributor

Offscreen driver-call check of the pipeline creation gate at 1e0e249f + c95183fd8. Four threads entered the production pipeline helper and each created a real synthetic compute PSO. On AMD RADV the peak inside the create callback was 1 by default and 4 with the lock forced off. With DXGI reporting the RTX 4070 SUPER as NVIDIA, the peak was 4 by default and 1 with the lock forced on. In an extra default DXVK run the same NVIDIA hardware appeared to the application as vendor 0x1002, so the AMD default took effect and the peak was 1. The three gate unit tests passed on both GPUs. The existing rejected-library-blob check failed identically on base and PR under this Wine/vkd3d setup. This run measures the gate around offscreen compute creation. Native Windows AMD and gameplay remain open.

AI-assisted with OpenAI Codex.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 1e0e249f, and also merged onto today's main (the branch is 402 commits behind): merge-tree is clean, the merged tree passes cargo test -p leonida-gpu --lib pipeline (41 passed / 0 failed / 8 ignored), and neither touched file adds a clippy warning. The gate, the AMD-only vendor policy and the Screen > Requested > Early > Slow ordering all match the claim (library.rs:482, :532, :728, make.rs:198, :729), and both title-PSO create sites are inside the gate — the two other Create*PipelineState calls are device-init/offline, not worker-concurrent.

Mutations: the vendor guard and the !slow_blocked deferral are both caught. Replacing create_busy() with false in next() (make.rs:775) survives all 40 tests — the deferral wiring is untested, because the unit tests never have a host, so create_is_serialized() is always false. A stub-gate test (or a seam that lets the test pretend a create is in flight) would cover it; the same applies to the re-wake branch at :830.

Two more things:

  1. A create held by a draw thread never notifies. now()/masked_for can run p.make() synchronously on the draw thread, but only make.rs:765 and :836 call AVAILABLE.notify_all(), so workers parked on a slow-only queue can sleep until the next enqueue. Notifying on gate release would close that.
  2. Regenerate the switches page: python -I tools/d3d12_switches.py --check d3d12/docs/switches.md passes on main alone but fails after merging this branch, missing LEONIDA_PIPELINE_CREATE_LOCK. The PR adds the switch and its row is absent from the merged tree.

The AMD crash itself cannot be reproduced here (no AMD GPU and no title data), so that half rests on the reporters' hardware logs — the code-level evidence above is what this box can check.

@bobcatchris

Copy link
Copy Markdown
Contributor Author

@KelboLive Addressed in 163660640 (after merging main, no rebase/force-push):

  • Regenerated d3d12/docs/switches.md via python -I tools/d3d12_switches.py --out d3d12/docs/switches.md (--check passes; LEONIDA_PIPELINE_CREATE_LOCK is now documented).
  • Added notify_create_idle() invoked from CreateGuard::drop() whenever CREATING is released (after dropping CREATING.state so lock order stays QUEUE -> CREATING.state), waking parked workers even after synchronous draw-thread creates (now()/masked_for).
  • Simplified create_busy() to check CREATING.is_busy() directly (avoiding calling host() while holding QUEUE.lock()), removed the now-redundant worker-loop wakeup branch, and added next_defers_slow_while_create_gate_held_and_wakes_on_release to pin both deferral and gate-release wakeup.
  • Verified locally on Windows (Rust 1.98.1): cargo test --locked -p leonida-gpu --lib pipeline (42 passed, 0 failed, 8 ignored), tools/d3d12_switches.py --check, and python -I scripts/check_no_game_data.py (clean).

AI-assisted: Gemini 4 Neon (including an independent read-only reviewer pass).

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.

4 participants