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

Closed
Vladimir-Human wants to merge 87 commits from upstream-pr/56 into main
Vladimir-Human commented 2026-11-26 00:26:00 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T00:26:00Z.


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)
<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5501613151 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/56). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T00:26:00Z. --- 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)
PastiiJay commented 2026-11-26 00:34:14 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T00:34:14Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7178892047 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7178892047). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T00:34:14Z. --- 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.
Vladimir-Human commented 2026-11-26 00:48:09 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T00:48:09Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7179127536 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7179127536). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T00:48:09Z. --- 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.
HandshakeHackin commented 2026-11-26 02:44:00 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-26T02:44:00Z.


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

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7181069689 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7181069689). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-26T02:44:00Z. --- 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)
HandshakeHackin commented 2026-11-26 04:40:01 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-26T04:40:01Z.


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

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7182795779 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7182795779). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-26T04:40:01Z. --- 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)
Vladimir-Human commented 2026-11-26 09:25:14 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T09:25:14Z.


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).
<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7187960816 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7187960816). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-26T09:25:14Z. --- 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`).
PastiiJay commented 2026-11-26 10:41:56 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T10:41:56Z.


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

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7189713439 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7189713439). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T10:41:56Z. --- Thanks @Vladimir-Human, both points from review look covered in `a7ed242`. We'll test it in game before merging.
Vladimir-Human commented 2026-11-28 18:09:02 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:09:02Z.


Superseded by #180 targeting stable-amd (v26.11.6): https://github.com/PastiiJay/klbf-lab/pull/180

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7243568950 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/56#issuecomment-7243568950). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:09:02Z. --- Superseded by #180 targeting `stable-amd` (`v26.11.6`): https://github.com/PastiiJay/klbf-lab/pull/180

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
PastiiJay/klbf-lab!56
No description provided.