Repository navigation
d3d12: discard stale pipeline libraries across driver updates and self-heal refused entries (D3D12-PIPELINE-LIBRARY-DRIVER-STAMP) - #2789
Conversation
…ne anew (D3D12-PIPELINE-LIBRARY-DRIVER-STAMP) After a driver update the host can make the pipeline library from the old driver's file and then refuse each of its pipelines when it is loaded (`E_INVALIDARG`, 0x80070057). `StorePipeline` answers the same for a name that is already in the library, so each such pipeline was compiled again in every run and every save wrote the old driver's pipelines back. Note the adapter and driver beside the library (`host-pipelines.driver`: vendor, device, subsystem and revision IDs and `Host::driver`). A library whose line names another adapter or driver is not handed to `CreatePipelineLibrary`: its files are deleted and the run starts an empty one. A file saved before the line was kept is loaded as before and noted with `older=1`. When one of its pipelines neither loads nor can be stored under its name (and no store of this run took the name), the run swaps to an empty library, stores the pipeline there, and the next save writes it over the file. The pipelines `places` keeps in the library go into the new one, and a mapped old file stays mapped for `trim` and `removal_note`. A library its line calls this driver's own is not swapped: a refused pipeline there is not another driver's. The library and its generation sit behind `RwLock<Active>`; `saving` stays beside it, so loads still go on while a save serialises. `LEONIDA_LIBRARY_DRIVER_CHECK=0` turns both off (on by default). Fixes ProjectLeonida#2781 AI-assisted: yes
…brary-driver-stamp
KelboLive
left a comment
There was a problem hiding this comment.
Verified here on the machine that has the problem: NVIDIA 0x2705 with the driver line captured, cargo test -p leonida-gpu --lib pipeline:: -> 47 passed, 7 ignored (16 new library tests, and the GPU ones really ran — one prints "loaded from the library begun anew in 0.009 ms"), tests/test_d3d12_switches.py 19 OK with the switch read as "on, 0 turns it off".
The mechanism does what it says for a pre-sidecar cache: stamp_of (library.rs:928) writes vendor/device/subsys/rev plus Host::driver() (host.rs:1373), open_in (:990) classifies it, a mismatch discards the pair through discard (:948), and on a refusal that also loses the store, stale() + begin_anew (:749, :767) swap in an empty library and save writes a clean file under this driver's stamp. Nothing refused is ever written back: serialisation only ever uses active.library.
Two notes.
- Say in the body that the first run after a poisoned cache still looks poisoned. A missing name is also
E_INVALIDARGon this device (the tests assert that after a swap), so the first run still logsmade … did not load it: 0x80070057for nearly every pipeline and still compiles all of them; the second run is the healed one. Otherwise testers (this machine included) will read the first run as the fix not working. - A real bug:
replace_librarytreats a failed removal ofhost-pipelines.nextas success (library.rs:1302-1308). If NEXT is held by something else — a casediscardalready documents — the rename succeeds, the removal fails silently, andnote(dir, &active, true)(:1246) writes this driver's plain stamp (:877-884). The next start then trusts the line,Blob::of(:263) renames the surviving other-driver NEXT over the library, the file loads asOrigin::Noted, andstale()never heals it. Reproduced with NEXT heldshare_mode(0): after the save the line names this driver while NEXT still exists, and the next run stays(0, Noted)after a refusal. Only write the plain stamp when NEXT is actually gone (or adopt NEXT before comparing the sidecar).
|
Independent Windows check of
AI-assisted: yes |
…brary-driver-stamp # Conflicts: # d3d12/crates/leonida-gpu/src/pipeline/library.rs
|
A heads-up for this pull request: the page of D3D12 switches ( Nothing checks that today, so the page has drifted before (it was a name behind when this was measured). A test that checks it is waiting to be opened (DOCS-SWITCHES-PAGE-CHECK), and it would make this pull request's CI red until the page is written again. One command does that: It writes the page with the names in it and nothing else; the diff is the new rows. |
…brary-driver-stamp
Refs ProjectLeonida#2781 AI-assisted: yes
|
Thanks for the heads-up @Neutron-0 — regenerated AI-assisted: Gemini 4 Carbon. |
|
Independent check of The test cases cover a differing driver note, refusal of a cached compute pipeline with the check off, saving and then reloading a rebuilt entry with the check on, and concurrent detection rebuilding the library only once. The revisions to the library state were synthetic. A native Windows driver upgrade was outside the run. AI-assisted with OpenAI Codex. |
…brary-driver-stamp # Conflicts: # d3d12/docs/switches.md
…brary-driver-stamp # Conflicts: # d3d12/docs/switches.md
…brary-driver-stamp # Conflicts: # d3d12/docs/switches.md
|
Independent check of
AI-assisted: Antigravity |
|
Independent verification on an RTX 4090, driver 621.24 (32.0.16.2124), Windows 11 - by the method in Applied on One thing worth knowing: a commit-by-commit cherry-pick of the range ( What it does here: What I could not test, and would not claim: the case the issue is about - a library written under one driver and opened under another. Downgrading this machine's driver is not something I will do to a working setup, so the 616.64 -> 621.01 transition is verified only through your own tests ( What that leaves as risk: the stamp is read from AI-assisted: yes - DeepSeek v4.1 (flash). Written with an AI assistant. |
…brary-driver-stamp # Conflicts: # d3d12/docs/switches.md
|
At 4cec236 I queried the production stamp(host) in three fresh Windows processes using one diagnostics build. The RTX 5070 returned vendor 0x10de, device 0x2f04, driver 9007199255791260. WARP returned vendor 0x1414, device 0x008c, driver 2814751477606228. Returning to the 5070 reproduced the complete first stamp byte for byte. I then exercised both on-disk mismatch tests on the 5070, substituting that measured WARP stamp in the test sidecar. With the check enabled, the ordinary case discarded the stale library, saved a rebuilt pipeline under the current stamp and loaded it on reopen. With an exclusive handle on the stale library file, the save could not replace it. The file was not relabeled as current, and reopening started with an empty library. Both tests reached the readback assertions; I added temporary test-only output to distinguish that from an early return. These are real D3D12 pipeline files in temporary directories, with deliberately mismatched metadata. No driver installation was changed. Codex-assisted. |
Summary
Fixes #2781 (
D3D12-PIPELINE-LIBRARY-DRIVER-STAMP).Across NVIDIA driver updates (
616.64 -> 621.01),ID3D12Device1::CreatePipelineLibrarycan accept the outerhost-pipelines.bincontainer at startup whileLoadGraphicsPipeline/LoadComputePipeline/LoadPipelinesubsequently reject every stored blob withE_INVALIDARG(0x80070057). Whenpipeline()recompiled each refused PSO (410–5,228 msper hitch) and calledStorePipeline(name, &pso),StorePipelinealso failed withE_INVALIDARGbecause anID3D12PipelineLibrarycannot overwrite an existing name — leavingadded == 0(or re-serializing the stale blobs back to disk) and keeping the mismatched driver's library alive until device removal (0x887A0005).This change adds two defense-in-depth layers inside
d3d12/crates/leonida-gpu/src/pipeline/library.rs, controlled byLEONIDA_LIBRARY_DRIVER_CHECK(on by default;LEONIDA_LIBRARY_DRIVER_CHECK=0restores the previous behavior):Proactive adapter & driver stamp sidecar (
host-pipelines.driver):vendor,device,subsys,revfromDXGI_ADAPTER_DESC1plusHost::driver()whendriver != 0) alongsidehost-pipelines.bin.open_in(), ifhost-pipelines.drivernames a different adapter or driver,host-pipelines.next,host-pipelines.bin, andhost-pipelines.driverare discarded upfront beforeCreatePipelineLibraryis called, and an empty library is started cleanly.<stamp> older=1on save until replaced, preservingOrigin::doubtful()for Layer 2.Reactive self-healing swap (
Library::keep/stale/begin_anew):RwLock<Active>(keepingsavingseparate soSerializenever blocks loads).Load*Pipelineon generationg,create()succeeds,StorePipeline(name, &pso)fails withE_INVALIDARGon the same generationgwithoutnamehaving been stored in this run (Seen::stored, guarded undersame_name(name)), and a fresh empty library acceptspso,begin_anew()atomically swaps in the fresh library, replays non-title static-sampler probe pipelines (Seen::besideforpipeline::places), retains any mappedBlobinLibrary::retired(releasing its working-set pages viaVirtualUnlocksotrim()andremoval_note()never see an unmapped view), and marks the library dirty (anew) sosavereplaceshost-pipelines.binand writes this driver's plain stamp.std::ptr::null()) toCreatePipelineLibrarywhenbytes.is_empty()(avoiding Rust's dangling0x1empty-slice pointer on VKD3D-Proton), uses unique staging filenames on save, and removes any stalehost-pipelines.nextwhen an in-place rename succeeds.Verification
Tested on Windows 11 (
10.0.26200), NVIDIA GeForce RTX 3090 (driver610.88, UMD32.0.16.1088), and D3D12 WARP (0x1414):16tests inpipeline::library::tests,47passed acrosspipeline::):with_the_check_off_a_refused_pipeline_is_made_in_every_run(reproduces repeated0x80070057on bothLoadComputePipelineandStorePipeline,added == 0, unchanged file across restarts whenLEONIDA_LIBRARY_DRIVER_CHECK=0).a_pipeline_neither_loaded_nor_replaced_begins_the_library_anew(verifies swap +0.005–0.015 mssubsequent loads across both mapped and held blobs).a_library_of_another_driver_is_not_handed_to_the_hostanda_library_of_another_driver_that_cannot_be_deleted_is_not_called_this_drivers.a_name_stored_in_this_run_does_not_begin_the_library_anew(4-thread barrier benign-race test),threads_that_find_it_out_together_begin_the_library_anew_once(8-thread single-swap race test), andpipelines_kept_beside_the_titles_go_into_the_library_begun_anew(placesprobe carry-over).cargo clippy -p leonida-gpu --all-targets --lockedand--features diagnostics --all-targets --locked:0warnings inlibrary.rs; single touched file (host.rsandmake.rsuntouched).python -I tests/test_d3d12_switches.py(19/19passed) andpython -I scripts/check_no_game_data.py(rc=0).AI-assisted: authored with Claude Fable 5.2, independently reviewed with Gemini 4 Neon (XHigh), and verified with Gemini 4 Carbon (High).