D3D12-PIPELINE-CREATE-LOCK-AMD: serialize driver PSO creation on AMD #2694
Closed
leonida/mandy
bobcatchris wants to merge 0 commits from
fix/d3d12-pipeline-create-lock-amd into main
pull from: fix/d3d12-pipeline-create-lock-amd
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2694
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/d3d12-pipeline-create-lock-amd"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Problem
On AMD RDNA 3 (RX 7900 XTX,
amdxc64.dll32.0.32029.2010, Windows 11), default 10-thread early pipeline compilation hits a deterministic driver crash (0xc0000005insideamdxc64.dllor0x887A0020DXGI_ERROR_DRIVER_INTERNAL_ERROR) when multiple pipeline worker threads callCreateGraphicsPipelineState/CreateComputePipelineState/CreatePipelineStateconcurrently:LEONIDA_LIBRARY_LOCK=1(which only locksLoad*Pipeline/StorePipeline, notcreate()).LEONIDA_PIPELINE_LIBRARY=0(bypassing the pipeline library completely).LEONIDA_PIPELINE_WORKERS=1avoids 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: backgroundEarlyorSlowdriver compiles (1-73 s on AMD) hold the create lock while draw-criticalScreen/Requestedpipelines wait behind them.Fix
In
d3d12/crates/leonida-gpu/src/pipeline/library.rsandd3d12/crates/leonida-gpu/src/pipeline/make.rs:should_serialize_create(env, vendor_id)+CreatePriority::{Screen, Requested, Early, Slow}+CreateGate(serialized adapters only; non-AMD adapters keep concurrentcreate()unlessLEONIDA_PIPELINE_CREATE_LOCK=1is set).Pending::make()scopeswith_create_priority(CreatePriority)soScreen>Requested>Early>Slowstrictly wins the AMD create lock once the active call finishes.create()call holds the serialized lock (create_busy()),Queue::pop_with(..., slow_blocked)avoids popping speculativeSlowjobs so worker threads stay free forScreen/Requested/Earlywork andworkers()re-wakes when the gate clears.Verification
10.0.26200), Ryzen 7 7800X3D, AMD Radeon RX 7900 XTX (gfx1100, driver32.0.32029.2010), pinnedrustc 1.98.1.cargo test -p leonida-gpu --lib pipeline: 36 passed, 0 failed, 7 ignored (ind3d12, 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.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)
Independent native Windows NVIDIA check of
29288a754on1d22590b9(tree1cb8f3801). Windows 11 build 26300, MSVC, Rust 1.98.1, RTX 4090 (NVIDIA 616.64). The exactpipeline::librarysubset 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).LEONIDA_PIPELINE_CREATE_LOCK=1Each 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
05c327bf3after the priority update. This merges cleanly with0ae217ceb(tree10728e5a5), 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.Independent Wine PSO check.
05c327bf3merged ontod367675c7(treef0308e20). 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.0x1002=00x1002=0dxgi.hideNvidiaGpu = False0x10de=1The 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
mainand #2694. The direct API check returned0x80070057for the empty slice andS_OKfor a null pointer with zero length. Combining #2654 at55ac5d337(tree82711e462) 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.
Native Windows cache persistence check on
e201dcd90(#2694) with55ac5d337(#2654) onf9f3ec4c6(combined treedf841387d). MSVC x64, Rust 1.98.1, RTX 4090 on NVIDIA 616.64, Windows 11 build 26300. The ten stockpipeline::library::testsall 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 withLEONIDA_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).
AMD Wine cache round-trip for #2694 + #2654. I tested
e201dcd90with55ac5d337onf9f3ec4c6(combined treedf841387d, 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 reported0x1002. 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.
LEONIDA_PIPELINE_CREATE_LOCK=05047d6a1)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.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 vendor0x1002, 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 Addressed in
163660640(after mergingmain, no rebase/force-push):d3d12/docs/switches.mdviapython -I tools/d3d12_switches.py --out d3d12/docs/switches.md(--checkpasses;LEONIDA_PIPELINE_CREATE_LOCKis now documented).notify_create_idle()invoked fromCreateGuard::drop()wheneverCREATINGis released (after droppingCREATING.stateso lock order staysQUEUE->CREATING.state), waking parked workers even after synchronous draw-thread creates (now()/masked_for).create_busy()to checkCREATING.is_busy()directly (avoiding callinghost()while holdingQUEUE.lock()), removed the now-redundant worker-loop wakeup branch, and addednext_defers_slow_while_create_gate_held_and_wakes_on_releaseto pin both deferral and gate-release wakeup.cargo test --locked -p leonida-gpu --lib pipeline(42 passed, 0 failed, 8 ignored),tools/d3d12_switches.py --check, andpython -I scripts/check_no_game_data.py(clean).AI-assisted: Gemini 4 Neon (including an independent read-only reviewer pass).
VERIFY-2694 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files
Verdict: PASS. The gate's logic is right, nothing that passed before fails now, and the new tests pass. Two properties of the design are worth the author's attention, though neither is a defect.
Head
16366064, base the currentmain85ec1d33, merge base27613ab6, 3 files, +288/−5:d3d12/crates/leonida-gpu/src/pipeline/library.rs,d3d12/crates/leonida-gpu/src/pipeline/make.rs,d3d12/docs/switches.md.1. What it changes
Concurrent
Create*PipelineStatecalls crash AMD's driver compiler (0xc0000005/0x887A0020insideamdxc64.dll), while the DXIL translation itself can stay parallel. The pull request puts the driver's calls behind a priority-ordered mutex, so an activeScreenorRequesteddraw does not sit in line behind queued backgroundEarlyorSlowprecompiles:A waiter goes in only when the gate is free and no waiter of a higher priority is queued; the priority itself is a thread-local with a reset guard (
with_create_priority), so the code that makes a pipeline says which kind it is. The gate is used only whenshould_serialize_createsays so — by default on AMD (VendorId == 0x1002), overridable withLEONIDA_PIPELINE_CREATE_LOCK=0|1.2. What I checked
CreateGuard'sDropsetsbusy = false, notifies all, and — when the guard is the globalCREATINGgate — callssuper::make::notify_create_idle(), so the "creation in progress" bookkeeping is cleared on the same path that frees the gate.state.waiting[..p]is the higher priorities (the enum ordersScreen = 0as most urgent), so aScreenwaiter ignores lower ones ✓ and aSlowwaiter yields to any queuedScreen/Requested/Early✓.should_serialize_createreadsLEONIDA_PIPELINE_CREATE_LOCKfirst ("0"→ off,"1"→ on), and otherwise serializes only on AMD's vendor id ✓.create_is_serialized()reads it once into aOnceLockand logs which adapter it saw ✓.create_busy()reads the gate directly rather than askingcrate::host::host(), because the callers holdQUEUE— the comment says so and the code does it ✓.3. Two properties worth stating in the pull request
Neither is a defect, and the author may well have them in mind:
Slowwaiter proceeds only when noScreen/Requested/Earlywaiter is queued, so a steady stream of screen-priority creations can keep the background precompiles waiting indefinitely. That is the point of the change ("active draws never sit in line behind queued background precompiles"), but the other side of it is that the background work may never finish while the game is busy. Whether that matters is a property of a run with the game.notify_allplus a priority-only test, so among waiters of the same priority the order is not FIFO — a late arrival can take the gate before an earlier one.4. What the tests do here
leonida-gpudoes not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it forx86_64-pc-windows-gnuand ran the tests under Wine 11.21.The red side (the merge base with only this pull request's tests) does not compile — the new test uses
CreatePriority, which the change introduces — so the base and the head were compared:watchtests that need Microsoft'sVirtualAlloc/VirtualQuerybehaviour, which Wine does not have5. What I did not check
Create*PipelineStatefaults insideamdxc64.dllon AMD; that needs an AMD card, and the fault and its fix are not reproducible here.AI-assisted: MiniMax M3.1 Flash.
Closing: this pull request no longer applies to current
main(merge conflict ind3d12/docs/switches.md), and open pull requests that have fallen out of step withmainare being closed so the list stays workable. If you still want this change, rebase it on currentmainand reopen it (or open a new pull request); it will be looked at again.AI-assisted (Claude Code).