GPU: keep host pipeline caches per adapter #2803
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2803
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2803"
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?
@yumaste on GitHub · 2026-11-25 20:59 UTC · original
yumaste:fix/pipeline-cache-by-adapter→main· +353 −40 · 1 files · 8 commits · openProblem
The host pipeline library and its prebuilt list are currently shared by all adapters. Switching between the integrated and discrete GPUs on a hybrid laptop makes D3D12 reject the other adapter's library. A subsequent save can overwrite the existing cache. #2637 and #2646 describe the related WARP case.
Change
Verification
19a1ddd: the diagnostics-enabledpipeline::suite under WARP passed 30 tests, with the all-adapters test ignored. Regressions cover late adapter lookup and a file sharing violation that clears before save. They check that both existing cache files stay intact. The WARP helper checks the adapter's software flag before creating a device. Both strict Clippy profiles and the asset policy passed.@fuzeofficlal on GitHub · 2026-11-25 21:20 UTC · original
Reviewed and verified
4a912966on Windows 11 (triple-adapter host: RTX 5090 + AMD Radeon + WARP) againstmain(13f91ca).Code review
GetAdapterLuid()only to look upDXGI_ADAPTER_DESC1viaEnumAdapterByLuid, then builds the directory strictly from hex PCI/software fields ({hardware|software}-{VendorId:04x}-{DeviceId:04x}-{SubSysId:08x}-{Revision:02x}), avoiding reboot-volatile LUIDs and adapter-name path injection.read_cachefalls back to roothost-pipelines.bin+prebuilt-pipelines.txtonNotFound,save()writes only intoadapters/<id>/viawrite_atomicallywithout clobbering legacy root files,early-pipelines.txtstays shared across adapters, andADAPTER/LIBRARYuseOnceLock.Verification (Windows 11,
rustc 1.98.1MSVC)pipeline::(--features diagnostics --test-threads=1): 18/18 passed on RTX 5090 and 18/18 passed on WARP.each_d3d12_device_uses_its_own_dxgi_adapterverified all 3 adapters on this machine:NVIDIA GeForce RTX 5090->adapters/hardware-10de-2b85-89ec1043-a1AMD Radeon(TM) Graphics->adapters/hardware-1002-13c0-88771043-c1Microsoft Basic Render Driver->adapters/software-1414-008c-00000000-00cargo clippy --locked -p victory-gpu --features diagnostics --all-targets -- -D warnings: 0 warnings;cargo xtask policy: 184 files ok; cleangit merge-treevs13f91caand#2801.@oni-swr on GitHub · 2026-11-25 21:21 UTC · original
Independent WARP/CPU verification of head
4a9129667ca5605f29c59abe44c42aba34e527b8, merged ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca(clean merge).Environment: Windows 11 Pro 26200, WARP only (
VICTORY_D3D12_WARP=1with--features diagnostics,VICTORY_WARP=1), Windows SDK 10.0.26100.0 x64dxil.dll1.8.2502.11.cargo test -j 4 -p victory-gpu --features diagnostics -- --skip each_d3d12_device_uses_its_own_dxgi_adapter: 199 passed, 0 failed, 1 ignored, 1 filtered out. The baseline was 198/0/1, plusadapter_caches_keep_their_own_library_and_prebuilt_list.each_d3d12_device_uses_its_own_dxgi_adapterwas not run as written, because it creates a D3D12 device on everyEnumAdapters1adapter. That means the physical GPU, whateverVICTORY_D3D12_WARPsays. I ran a local copy limited toEnumWarpAdapter, and it passed:Microsoft Basic Render Driver: cache\adapters\software-1414-008c-00000000-00, with the LUID round trip throughEnumAdapterByLuidmatching on WARP.read_cachenever falls back to the legacy root,adapter_caches_keep_their_own_library_and_prebuilt_listfails at the legacy assertion, so the test catches it.DeviceIdis dropped from theadapter_cache_dirkey, every test still passes. The fixtures differ by vendor (NVIDIA, Intel, WARP), so nothing exercises two adapters from one vendor, such as an Intel iGPU plus an Intel Arc card.cargo clippy -p victory-gpu --all-targets -- -D warningswas clean, with and without--all-features.cargo fmt --all --check: 898 hunks against 891 on the baseline. The 7 new hunks are in new code inpipeline/library.rs: two insave()(the one-linelet .. elseand the longtracing::warn!arm) and five in the new tests (theDXGI_ADAPTER_DESC1literals, oneassert_eq!, thelet Ok(..) elseand theeprintln!).Diff review:
host()orwarp_adapter(). Could it use only the software adapter, or be#[ignore]d or gated?DeviceIdpair toadapter_caches_keep_their_own_library_and_prebuilt_listwould pin down the key.rustfmton the new lines.NotFound, other errors give an empty cache, the early list stays shared, and the warning shows when no adapter is known.Not tested: physical GPU, hybrid-GPU machine, retail title.
AI use: Claude Code (Claude Opus 5.5)
@AurumCarlos on GitHub · 2026-11-25 21:23 UTC · original · edited 2026-11-25 21:29 UTC
Review notes: suggested fixes for
library.rsFive issues from a review of this PR, with a patch on top of
4a91296below.cache_dircaches a faileddevice_adapterresult (None) in a staticOnceLock, so it is never retried.savethen serializes the library and resetsaddedbut writes nothing; before this PR the library was always saved under the cache root. Fix: cache only a successful lookup, and when the adapter is unknown, save in the cache root as before (D3D12 still refuses another adapter's library on read).<cache>/pipelines/host-pipelines.binandprebuilt-pipelines.txtstayed on disk forever. Fix: once a library made from the legacy files (and accepted by D3D12) has been saved under its adapter folder, the legacy files are removed. A legacy library D3D12 rejected is left in place, so the other adapter of a hybrid laptop can still migrate it.eprintln!is removed.use_pipeline_cache. It now describes thedir/adapters/<kind>-<vendor>-<device>-<subsys>-<revision>layout and the root fallback.Verification (Linux, cross-compiled to
x86_64-pc-windows-gnuwith Rust 1.98.1 fromrust-toolchain.toml, llvm-mingw linker, tests run under Wine 11.22 Staging with D3D12 on a real AMD GPU):cargo clippy -p victory-gpu --lib --tests --locked --target x86_64-pc-windows-gnu -- -D warnings: passed.cargo test -p victory-gpu --lib --locked --target x86_64-pc-windows-gnu pipeline::library::tests -- --test-threads=1: 10 passed, includingeach_d3d12_device_uses_its_own_dxgi_adapterwith real D3D12 devices.savehave no dedicated test.Patch (applies on top of
4a91296)@AurumCarlos on GitHub · 2026-11-25 21:45 UTC · original
Review of
42cefd0andcb11009Thanks for the follow-up: the retried adapter lookup, the dirty state kept on write failures, the serialized saves and the same-vendor test (Intel iGPU vs Arc) cover most of the earlier notes. Three remaining points, with a patch on top of
cb11009below. This supersedes the patch in my previous comment, which no longer applies.savereturns as soon ascache_dir(dir)isNone, so on a setup whereCreateDXGIFactory2orEnumAdapterByLuidalways fails, every run starts with an empty library; main persisted it in<cache>/pipelines. The patch falls back to writing the library in the cache root in that case only (with a one-time warning). D3D12 still refuses another adapter's library on read, and older versions keep reading the root as before. If keeping the root strictly read-only is the intent, it may be worth stating in the PR that losing the cache in this case is the accepted cost.cache_dir(dir)was called insidelibrary.lock(), so while the adapter is unknown each save created a DXGI factory and enumerated adapters whilepipeline()andnote_prebuiltwaited. The patch looks it up before taking the lock.save. It still said the library and the early list are written together when pipelines were added; since42cefd0the early list is written on its own. The comment inread_cache("legacy files are never overwritten") is updated too, to match (1).Verification (Linux, cross-compiled to
x86_64-pc-windows-gnuwith Rust 1.98.1 fromrust-toolchain.toml, llvm-mingw linker, tests run under Wine 11.22 Staging with D3D12 on a real AMD GPU):cargo clippy -p victory-gpu --lib --tests --locked --target x86_64-pc-windows-gnu -- -D warnings: passed, oncb11009and with the patch.cargo test -p victory-gpu --lib --locked --target x86_64-pc-windows-gnu pipeline::library::tests -- --test-threads=1 --include-ignored: 11 passed, oncb11009and with the patch (includingwarp_device_uses_its_dxgi_adapterand the ignored all-adapters test).savehas no dedicated test.Patch (applies on top of
cb11009)@Marvisak on GitHub · 2026-11-25 23:24 UTC · original
Automated triage for the maintainers.
The host pipeline library and its prebuilt list are now kept per adapter, under
adapters/<kind>-<vendor>-<device>-<subsys>-<revision>, found withdevice_adapter/cache_dirincrates/victory-gpu/src/pipeline/library.rs. When there is no adapter cache yet, the legacy root files are read. The early list stays shared.saveis now serialised and puts the counts back when a write fails. I checked the legacy fallback inread_cache(only onNotFound) and the retried adapter lookup, and that the all-adapters device test is now#[ignore]d. One point is still open from the review thread. If the adapter lookup always fails,savewrites no library at all, wheremainsaved it in the cache root. That seems unlikely on Windows, but the maintainer may want the root fallback. CI (check) passes.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 21:16 UTC · original · reviewed
Sound design. Keyed by VendorId/DeviceId/SubSysId/Revision (+software kind) — stable across LUID changes, which is correctly noted as not a disk key. Read precedence is right: adapter dir hit wins, NotFound falls back to the legacy root library (migration path), other IO errors do not. The legacy root files are never overwritten, so an older binary keeps working. The real-hardware test enumerating every adapter incl. WARP and checking LUID roundtrip is the right verification.
EARLY_FILEstaying in root is consistent — its keys are adapter-independent. LGTM.@Dukestar69 on GitHub · 2026-11-26 02:48 UTC · original · approved these changes
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):cargo test -p victory-gpu --lib pipeline::library::tests: 13 passed, 0 failed, 1 ignored (including newadapter_caches_keep_their_own_library_and_prebuilt_listandwarp_device_uses_its_dxgi_adapter).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 13:24 UTC · original · requested changes
The LUID lookup is the right way to find the DXGI adapter for the actual D3D12 device, and the
adapters/{kind}-{vendor:04x}-{device:04x}-{subsys:08x}-{revision:02x}key withEARLY_FILEkept at the root andPREBUILT_FILEscoped per adapter makes sense.Two issues to fix before merging:
crates/victory-gpu/src/pipeline/library.rs:161-184, 196-218, 399-440):cache_dircaches the adapter in its ownOnceLock, separate fromLIBRARY. Ifdevice_adapterfails whenlibrary()initializes,LIBRARYstarts empty (or reads the legacy root), leavingADAPTERunset. If a latersave()succeeds in resolvingADAPTER, it can overwrite an existingadapters/<id>/host-pipelines.bin(andprebuilt-pipelines.txt) that this process never loaded. Please record the resolved target/load state alongsideLIBRARYinitialization so a recovered lookup cannot clobber an unloaded adapter cache, and add a regression test for that sequence.library.rs:662): Please checkDXGI_ADAPTER_FLAG_SOFTWAREonGetDesc1()before callingD3D12CreateDeviceinwarp_device_uses_its_dxgi_adapter, matchingcrates/victory-gpu/src/host.rs:286-304(sinceEnumWarpAdaptercan return a hardware adapter under Proton/Wine).Local verification on commit
a3f22422c7ba:xtask policy(191 files ok) andcargo clippy -p victory-gpu --all-targets(defaultand--all-features) pass. With--features diagnosticsandVICTORY_D3D12_DEBUG=1,pipeline::library::testspasses (13 passed, 0 failed, 1 ignored) on both RTX 5090 andVICTORY_D3D12_WARP=1, andeach_d3d12_device_uses_its_own_dxgi_adapter -- --ignoredpasses (1 passed), distinguishing RTX 5090 (hardware-10de-2b85-89ec1043-a1), AMD Radeon(TM) Graphics (hardware-1002-13c0-88771043-c1), and WARP (software-1414-008c-00000000-00).@yumaste on GitHub · 2026-11-26 13:31 UTC · original
Addressed the two requested changes in
1226f29. The library now holds the cache directory selected at load. If the lookup failed then, it cannot persist its in-memory library for that process, even if DXGI can identify the adapter later. The regression creates both cache files, simulates that sequence, and verifies both stay intact. Forcing the save to use the recovered directory makes the regression fail.The WARP test checks
DXGI_ADAPTER_FLAG_SOFTWAREbefore creating a device. Local WARP pipeline suite: 29 passed, 1 ignored. Strict Clippy and asset policy passed.@AurumCarlos on GitHub · 2026-11-26 14:08 UTC · original · reviewed
Following up on my earlier notes, now for
1226f29. Pinning the cache directory inSharedwhen the library opens is a clean answer to the "overwrite a cache that was never consulted" concern. It does reverse my first point from yesterday (a failed lookup now means the library is never saved for that process instead of retried), but with a better reason, since a later lookup could write over an adapter cache this process never read. I'm fine with that trade-off.A small follow-on:
cacheis alsoNonewhenDIRisn't set yet at the firstlibrary()call (root.and_then(|_| device_adapter(device))). Onmain,saverecomputed the directory fromDIRat save time, so a library opened beforeuse_pipeline_cachewould still be saved later. Now it won't be, and the warning says "adapter unavailable at load", which would send someone looking in the wrong place. Ifd3d12xalways sets the directory before the first pipeline, that's moot, but either adebug_assert!on that order or a warning that names which of the two was missing would make it clear.@fuzeofficlal on GitHub · 2026-11-26 14:15 UTC · original · approved these changes
Both items from the previous review are cleanly resolved:
Shared.cache(pipeline/library.rs:80, 190-243) locks in the adapter directory chosen at open time,save_library(:413-422) only writes to that fixed destination, anda_later_adapter_lookup_cannot_replace_an_unloaded_cachedirectly verifies that recovering DXGI adapter lookup later cannot overwrite an unloaded cache.warp_device()(:672-699) now checksDXGI_ADAPTER_FLAG_SOFTWAREbefore callingD3D12CreateDevice.Two minor non-blocking notes:
NotFound(e.g., a transient sharing violation),read_cacheopens an empty blob whileopen_cacheretainsSome(cache), so a later save could overwrite the unread file; worth keeping in mind if combined with #2129.pipeline/library.rs:204(root.zip(adapter).map(...)) exceedsrustfmt's 100-column wrap.Local verification at
1226f292(clean merge ontoorigin/main63bcca43):xtask policy(191 files ok),cargo clippy -p victory-gpu -p victory --all-targets(defaultand--all-features, 0 warnings),cargo test -p victory(18/18), andpipeline::librarytests underVICTORY_D3D12_DEBUG=1passed on RTX 5090 (14/14, 1 ignored), WARP (14/14, 1 ignored), and all enumerated adapters viaeach_d3d12_device_uses_its_own_dxgi_adapter(RTX 5090, AMD Radeon Graphics, and Microsoft Basic Render Driver). Approving.@yumaste on GitHub · 2026-11-26 14:22 UTC · original
3a3295anow records the reason when no adapter directory was consulted. A later save reports eithercache directory not configured at loadoradapter unavailable at load. The normal app run and prebuild paths configure the directory before starting pipeline work. The regression also checks both reasons. The WARP pipeline suite passed (29 passed, 1 ignored), along with all-targets/all-features Clippy.@yumaste on GitHub · 2026-11-26 14:28 UTC · original
Thanks for flagging the read-error case.
19a1dddkeeps the library in memory for the run when Windows reports a scoped library read error other thanNotFound. The regression opens an existing cache file with sharing disabled, loads while it is locked, unlocks it, then checks that a dirty in-memory library cannot overwrite either existing cache file. I also wrapped the cache path lookup. Under WARP, 30 pipeline tests passed and one was ignored. Both strict Clippy profiles passed.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.