gpu/pipeline: adapter-keyed PSO cache filenames and atomic rename (1/4 of #51) #56

Open
github-bot wants to merge 2 commits from github-bot/gh-56 into beta AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 00:26 UTC · original
Vladimir-Human:perf/split-adapter-pso-cache → beta · +707 −47 · 1 files · 2 commits · open

Part 1/4 of the split requested on #51, cleanly branched from beta (78ad5711).

Scope

  • Touches only crates/victory-gpu/src/pipeline/library.rs.
  • Keys pipeline library filenames by AdapterKey (VendorId, DeviceId, Revision, and is_software; GetAdapterLuid is used only to locate the matching DXGI adapter, and SubSysId is not part of the key) so WARP/iGPU/dGPU runs never overwrite or load an incompatible adapter's cache blob.
  • Recognizes Microsoft Basic Render Driver (VendorId == 0x1414 && DeviceId == 0x008c) as software (-sw) in addition to DXGI_ADAPTER_FLAG_SOFTWARE, so default Basic Render Driver runs (Flags == 0) share the -sw cache with explicit WARP (Flags == 0x2) and never fall back to an unsuffixed legacy host-pipelines.bin.
  • Uses per-process, per-save unique temporary filenames (.tmp.<pid>.<seq> via std::process::id() and an atomic sequence counter) + atomic rename/replace when persisting the library and early-pipelines.txt, so concurrent processes saving either distinct or identical adapter keys in the same cache directory never clobber each other's temporary file before rename.
  • Preserves read-only fallback from legacy host-pipelines.bin for hardware adapters without ever touching or reading it from software adapters.
  • Completely independent of Parts 2-4 (zero file or symbol overlap).

Verification

  • cargo test -p victory-gpu: 159 passed; 0 failed; 3 ignored (includes all 9 pipeline::library::tests::* tests: adapter_keys_produce_distinct_filenames_for_hardware_and_software, basic_render_driver_without_software_flag_isolates_from_legacy_and_shares_warp_cache, temp_files_are_unique_across_calls_and_processes, legacy_fallback_reads_hardware_cache_and_never_touches_it_on_warp, warp_save_does_not_discard_hardware_pipeline_library, etc.)
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --all-features --lib pipeline::library -- --test-threads=1: 9 passed; 0 failed
  • cargo clippy -p victory-gpu --all-targets: 0 warnings in crates/victory-gpu/src/pipeline/library.rs
  • cargo run -p xtask -- policy --staged: passed (library.rs is 65,140 bytes)
**@⁠Vladimir-Human** on GitHub · 2026-11-26 00:26 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/56) `Vladimir-Human:perf/split-adapter-pso-cache` → `beta` · +707 −47 · 1 files · 2 commits · open Part 1/4 of the split requested on #51, cleanly branched from `beta` (`78ad5711`). ### Scope - Touches **only** `crates/victory-gpu/src/pipeline/library.rs`. - Keys pipeline library filenames by `AdapterKey` (`VendorId`, `DeviceId`, `Revision`, and `is_software`; `GetAdapterLuid` is used only to locate the matching DXGI adapter, and `SubSysId` is not part of the key) so WARP/iGPU/dGPU runs never overwrite or load an incompatible adapter's cache blob. - Recognizes Microsoft Basic Render Driver (`VendorId == 0x1414 && DeviceId == 0x008c`) as software (`-sw`) in addition to `DXGI_ADAPTER_FLAG_SOFTWARE`, so default Basic Render Driver runs (`Flags == 0`) share the `-sw` cache with explicit WARP (`Flags == 0x2`) and never fall back to an unsuffixed legacy `host-pipelines.bin`. - Uses per-process, per-save unique temporary filenames (`.tmp.<pid>.<seq>` via `std::process::id()` and an atomic sequence counter) + atomic rename/replace when persisting the library and `early-pipelines.txt`, so concurrent processes saving either distinct or identical adapter keys in the same cache directory never clobber each other's temporary file before rename. - Preserves read-only fallback from legacy `host-pipelines.bin` for hardware adapters without ever touching or reading it from software adapters. - Completely independent of Parts 2-4 (zero file or symbol overlap). ### Verification - `cargo test -p victory-gpu`: `159 passed; 0 failed; 3 ignored` (includes all 9 `pipeline::library::tests::*` tests: `adapter_keys_produce_distinct_filenames_for_hardware_and_software`, `basic_render_driver_without_software_flag_isolates_from_legacy_and_shares_warp_cache`, `temp_files_are_unique_across_calls_and_processes`, `legacy_fallback_reads_hardware_cache_and_never_touches_it_on_warp`, `warp_save_does_not_discard_hardware_pipeline_library`, etc.) - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --all-features --lib pipeline::library -- --test-threads=1`: `9 passed; 0 failed` - `cargo clippy -p victory-gpu --all-targets`: 0 warnings in `crates/victory-gpu/src/pipeline/library.rs` - `cargo run -p xtask -- policy --staged`: passed (`library.rs` is 65,140 bytes)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:53:52 +00:00
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-26 00:34 UTC · original

Got it, part 1/4 is in the queue. One detail: the code still keys the filename on vendor, device, revision and the software flag (the LUID is only used to find the adapter), while the description lists SubSysId and AdapterLuid too, so the summary could use the same fix as #51.

**@⁠PastiiJay** on GitHub · 2026-11-26 00:34 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7178892047) Got it, part 1/4 is in the queue. One detail: the code still keys the filename on vendor, device, revision and the software flag (the LUID is only used to find the adapter), while the description lists SubSysId and AdapterLuid too, so the summary could use the same fix as #51.
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 00:48 UTC · original

Good catch, thanks @⁠PastiiJay — updated the PR #56 description to list only (VendorId, DeviceId, Revision, is_software) in the filename key and note that AdapterLuid is only used to look up the DXGI adapter.

**@⁠Vladimir-Human** on GitHub · 2026-11-26 00:48 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7179127536) Good catch, thanks @⁠PastiiJay — updated the PR #56 description to list only `(VendorId, DeviceId, Revision, is_software)` in the filename key and note that `AdapterLuid` is only used to look up the DXGI adapter.
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-26 02:44 UTC · original

I compared the split with the version we tested earlier. pipeline/library.rs is byte-for-byte identical in 356690c and 7d31a81 (Git blob 9d948988). The earlier Windows WARP save/reopen run covered this file, including preserving both synthetic hardware and legacy cache files. Windows run

One detail for the PR description: two processes saving the same adapter key in the same cache directory derive the same .tmp path. The test verified isolation between hardware and WARP. I’d narrow the concurrent-exit claim to distinct adapter keys unless there’s a separate same-key writer test. Filename construction · Save path

**@⁠HandshakeHackin** on GitHub · 2026-11-26 02:44 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7181069689) I compared the split with the version we tested earlier. `pipeline/library.rs` is byte-for-byte identical in `356690c` and `7d31a81` (Git blob `9d948988`). The earlier Windows WARP save/reopen run covered this file, including preserving both synthetic hardware and legacy cache files. [Windows run](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45707827754) One detail for the PR description: two processes saving the same adapter key in the same cache directory derive the same `.tmp` path. The test verified isolation between hardware and WARP. I’d narrow the concurrent-exit claim to distinct adapter keys unless there’s a separate same-key writer test. [Filename construction](https://github.com/PastiiJay/klbf-lab/blob/356690c87817ddc643b10f28452a5a0e75c028f4/crates/victory-gpu/src/pipeline/library.rs#L478-L502) · [Save path](https://github.com/PastiiJay/klbf-lab/blob/356690c87817ddc643b10f28452a5a0e75c028f4/crates/victory-gpu/src/pipeline/library.rs#L760-L795)
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-26 04:40 UTC · original

I found a cache-isolation case with the default Microsoft Basic Render Driver on native Windows. DXGI returned 1414:008c with flags 0x0 for the default device and the same IDs with flags 0x2 for explicit WARP. On 356690c, the default device got the -hw filename and opened all 30 bytes of a synthetic unsuffixed legacy file. Explicit WARP got -sw and read zero bytes. Before

The attached commit recognizes the Basic Render Driver by its PCI ID as well as the software flag. Both devices then selected -sw and read zero legacy bytes. All seven library tests passed. I also checked that sharing this key works on the runner. A compute pipeline saved on one device reopened by name on the other, in both directions, with mapped and buffered storage (four cache hits). Cherry-pick 91ef4c9 · After · Cache round trips

**@⁠HandshakeHackin** on GitHub · 2026-11-26 04:40 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7182795779) I found a cache-isolation case with the default Microsoft Basic Render Driver on native Windows. DXGI returned `1414:008c` with flags `0x0` for the default device and the same IDs with flags `0x2` for explicit WARP. On `356690c`, the default device got the `-hw` filename and opened all 30 bytes of a synthetic unsuffixed legacy file. Explicit WARP got `-sw` and read zero bytes. [Before](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45755822131/job/139694070784) The attached commit recognizes the Basic Render Driver by its PCI ID as well as the software flag. Both devices then selected `-sw` and read zero legacy bytes. All seven library tests passed. I also checked that sharing this key works on the runner. A compute pipeline saved on one device reopened by name on the other, in both directions, with mapped and buffered storage (four cache hits). [Cherry-pick `91ef4c9`](https://github.com/HandshakeHackin/klbf-lab/commit/91ef4c9e465e50312894682c87da5677a37a6427) · [After](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45755822131/job/139694070471) · [Cache round trips](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45756241892/job/139695414273)
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 09:25 UTC · original

Pushed a7ed242 addressing all findings on #56:

  1. Microsoft Basic Render Driver (1414:008c with Flags == 0) -> -sw (@⁠HandshakeHackin):

    • Added AdapterKey::from_dxgi(vendor, device, revision, flags) which marks VendorId == 0x1414 && DeviceId == 0x008c as software = true alongside DXGI_ADAPTER_FLAG_SOFTWARE.
    • Default Basic Render Driver (Flags = 0) and explicit WARP (Flags = 0x2) now produce the exact same host-pipelines-1414-008c-rXX-sw.{bin,next} filenames with legacy_fallback = false, so neither ever opens an unsuffixed legacy host-pipelines.bin.
    • Covered by basic_render_driver_without_software_flag_isolates_from_legacy_and_shares_warp_cache and updated adapter_keys_produce_distinct_filenames_for_hardware_and_software.
  2. Per-process / per-save unique .tmp.<pid>.<seq> paths (@⁠HandshakeHackin):

    • Replaced the static .tmp filename in LibraryFiles with LibraryFiles::temp_file() using tmp.<pid>.<seq> (std::process::id() + an atomic TMP_SEQ counter), generated per save in save() and cleaned up on rename failure.
    • Applied the same unique_tmp_suffix() scheme and failure cleanup to write_atomically (early-pipelines.txt).
    • Covered by temp_files_are_unique_across_calls_and_processes (spawns a child process + 8 concurrent threads / 128 calls).
  3. PR summary alignment (@⁠PastiiJay, @⁠HandshakeHackin):

    • Refreshed the PR #56 description to explicitly match AdapterKey (VendorId, DeviceId, Revision, is_software, with GetAdapterLuid only for DXGI adapter lookup and no SubSysId), document Basic Render Driver 1414:008c -sw handling, describe .tmp.<pid>.<seq> temp-file isolation, and update verification results (159 passed; 0 failed; 3 ignored and 9 passed; 0 failed under VICTORY_D3D12_DEBUG=1).
**@⁠Vladimir-Human** on GitHub · 2026-11-26 09:25 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7187960816) Pushed `a7ed242` addressing all findings on #56: 1. **Microsoft Basic Render Driver (`1414:008c` with `Flags == 0`) -> `-sw`** (@⁠HandshakeHackin): - Added `AdapterKey::from_dxgi(vendor, device, revision, flags)` which marks `VendorId == 0x1414 && DeviceId == 0x008c` as `software = true` alongside `DXGI_ADAPTER_FLAG_SOFTWARE`. - Default Basic Render Driver (`Flags = 0`) and explicit WARP (`Flags = 0x2`) now produce the exact same `host-pipelines-1414-008c-rXX-sw.{bin,next}` filenames with `legacy_fallback = false`, so neither ever opens an unsuffixed legacy `host-pipelines.bin`. - Covered by `basic_render_driver_without_software_flag_isolates_from_legacy_and_shares_warp_cache` and updated `adapter_keys_produce_distinct_filenames_for_hardware_and_software`. 2. **Per-process / per-save unique `.tmp.<pid>.<seq>` paths** (@⁠HandshakeHackin): - Replaced the static `.tmp` filename in `LibraryFiles` with `LibraryFiles::temp_file()` using `tmp.<pid>.<seq>` (`std::process::id()` + an atomic `TMP_SEQ` counter), generated per save in `save()` and cleaned up on rename failure. - Applied the same `unique_tmp_suffix()` scheme and failure cleanup to `write_atomically` (`early-pipelines.txt`). - Covered by `temp_files_are_unique_across_calls_and_processes` (spawns a child process + 8 concurrent threads / 128 calls). 3. **PR summary alignment** (@⁠PastiiJay, @⁠HandshakeHackin): - Refreshed the PR #56 description to explicitly match `AdapterKey` (`VendorId`, `DeviceId`, `Revision`, `is_software`, with `GetAdapterLuid` only for DXGI adapter lookup and no `SubSysId`), document Basic Render Driver `1414:008c` `-sw` handling, describe `.tmp.<pid>.<seq>` temp-file isolation, and update verification results (`159 passed; 0 failed; 3 ignored` and `9 passed; 0 failed` under `VICTORY_D3D12_DEBUG=1`).
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-26 10:41 UTC · original

Thanks @⁠Vladimir-Human, both points from review look covered in a7ed242. We'll test it in game before merging.

**@⁠PastiiJay** on GitHub · 2026-11-26 10:41 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7189713439) Thanks @⁠Vladimir-Human, both points from review look covered in `a7ed242`. We'll test it in game before merging.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/56/head:github-bot/gh-56'
git switch 'github-bot/gh-56'

Merge

Merge the changes and update on Forgejo.
git switch 'beta'
git merge --no-ff 'github-bot/gh-56'
git switch 'github-bot/gh-56'
git rebase 'beta'
git switch 'beta'
git merge --ff-only 'github-bot/gh-56'
git switch 'github-bot/gh-56'
git rebase 'beta'
git switch 'beta'
git merge --no-ff 'github-bot/gh-56'
git switch 'beta'
git merge --squash 'github-bot/gh-56'
git switch 'beta'
git merge --ff-only 'github-bot/gh-56'
git switch 'beta'
git merge 'github-bot/gh-56'
git push origin 'beta'
This discussion has been locked. Commenting is limited to contributors.
No description provided.