Repository navigation
Conversation
kotekompotek
left a comment
There was a problem hiding this comment.
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_FILE staying in root is consistent — its keys are adapter-independent. LGTM.
|
Reviewed and verified Code review
Verification (Windows 11,
|
|
Independent WARP/CPU verification of head Environment: Windows 11 Pro 26200, WARP only (
Diff review:
Not tested: physical GPU, hybrid-GPU machine, retail title. AI use: Claude Code (Claude Opus 5.5) |
Review notes: suggested fixes for
|
Keep the legacy cache available for older versions, preserve dirty state on save failures, and make physical adapter enumeration opt-in.
Review of 42cefd0 and cb11009Thanks 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
Verification (Linux, cross-compiled to
Patch (applies on top of cb11009)diff --git a/crates/victory-gpu/src/pipeline/library.rs b/crates/victory-gpu/src/pipeline/library.rs
index 73c58fb..f3bd730 100644
--- a/crates/victory-gpu/src/pipeline/library.rs
+++ b/crates/victory-gpu/src/pipeline/library.rs
@@ -160,7 +160,7 @@ fn read_cache(root: &Path, adapter: Option<&Path>) -> (Vec<u8>, Option<Vec<u8>>)
.map(|blob| (blob, std::fs::read(dir.join(PREBUILT_FILE)).ok()))
};
// A compatible legacy library can be reused when there is no adapter
- // library yet. The legacy files are never overwritten by the new layout.
+ // library yet. The root is written only when the adapter cannot be told.
match adapter.map(read) {
Some(Ok(cache)) => cache,
Some(Err(e)) if e.kind() != std::io::ErrorKind::NotFound => Default::default(),
@@ -351,8 +351,10 @@ thread_local! {
const { std::cell::Cell::new(None) };
}
-/// Writes the library and the early list if pipelines were added since the
-/// last save and `SAVE_EVERY` has passed (or `now`).
+/// Once `SAVE_EVERY` has passed (or `now`): writes the early list if it
+/// changed, and, on its own, the library and the pre-build's list if
+/// pipelines were added or that list changed (under the adapter's folder,
+/// or in `dir` when the adapter cannot be told).
pub(crate) fn save(now: bool) {
static LAST: Mutex<Option<std::time::Instant>> = Mutex::new(None);
const SAVE_EVERY: std::time::Duration = std::time::Duration::from_secs(20);
@@ -384,18 +386,21 @@ pub(crate) fn save(now: bool) {
}
let Some(library) = library() else { return };
- let (adapter, blob, prebuilt, added, prebuilt_changed) = {
+ // Looked up outside the library's lock: the lookup is retried while the
+ // adapter cannot be told. The library then goes in the cache root, as
+ // before adapter folders (the host still refuses another adapter's).
+ let adapter = cache_dir(dir).unwrap_or_else(|| {
+ static WARNED: std::sync::Once = std::sync::Once::new();
+ WARNED.call_once(|| {
+ tracing::warn!("adapter unavailable: host pipeline library saved in the cache root")
+ });
+ dir.clone()
+ });
+ let (blob, prebuilt, added, prebuilt_changed) = {
let mut l = library.lock().unwrap_or_else(|e| e.into_inner());
if l.added == 0 && !l.prebuilt_changed {
return;
}
- let Some(adapter) = cache_dir(dir) else {
- static WARNED: std::sync::Once = std::sync::Once::new();
- WARNED.call_once(|| {
- tracing::warn!("host pipeline library not saved: adapter unavailable")
- });
- return;
- };
// SAFETY: a buffer of the size the library asks for.
let bytes = unsafe {
let mut bytes = vec![0u8; l.library.GetSerializedSize()];
@@ -408,7 +413,7 @@ pub(crate) fn save(now: bool) {
// Kept beside the bytes it holds for (also when a run adds
// pipelines).
let prebuilt = (!l.prebuilt.is_empty()).then(|| list(&tag(&bytes), &l.prebuilt));
- (adapter, bytes, prebuilt, added, prebuilt_changed)
+ (bytes, prebuilt, added, prebuilt_changed)
}
Err(e) => {
tracing::warn!(error = %e, "host pipeline library not serialised"); |
|
Automated triage for the maintainers. The host pipeline library and its prebuilt list are now kept per adapter, under This is a recommendation for a maintainer to look, not an approval. Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 with EARLY_FILE kept at the root and PREBUILT_FILE scoped per adapter makes sense.
Two issues to fix before merging:
- Overwrite risk on transient adapter-lookup recovery (
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. - WARP test software check order (
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) and cargo clippy -p victory-gpu --all-targets (default and --all-features) pass. With --features diagnostics and VICTORY_D3D12_DEBUG=1, pipeline::library::tests passes (13 passed, 0 failed, 1 ignored) on both RTX 5090 and VICTORY_D3D12_WARP=1, and each_d3d12_device_uses_its_own_dxgi_adapter -- --ignored passes (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).
|
Addressed the two requested changes in The WARP test checks |
AurumCarlos
left a comment
There was a problem hiding this comment.
Following up on my earlier notes, now for 1226f29. Pinning the cache directory in Shared when 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: cache is also None when DIR isn't set yet at the first library() call (root.and_then(|_| device_adapter(device))). On main, save recomputed the directory from DIR at save time, so a library opened before use_pipeline_cache would 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. If d3d12x always sets the directory before the first pipeline, that's moot, but either a debug_assert! on that order or a warning that names which of the two was missing would make it clear.
fuzeofficlal
left a comment
There was a problem hiding this comment.
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:
- If an existing adapter cache file fails to read with an error other than
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. - The new line at
pipeline/library.rs:204(root.zip(adapter).map(...)) exceedsrustfmt's 100-column wrap.
Local verification at 1226f292 (clean merge onto origin/main 63bcca43): xtask policy (191 files ok), cargo clippy -p victory-gpu -p victory --all-targets (default and --all-features, 0 warnings), cargo test -p victory (18/18), and pipeline::library tests under VICTORY_D3D12_DEBUG=1 passed on RTX 5090 (14/14, 1 ignored), WARP (14/14, 1 ignored), and all enumerated adapters via each_d3d12_device_uses_its_own_dxgi_adapter (RTX 5090, AMD Radeon Graphics, and Microsoft Basic Render Driver). Approving.
|
|
|
Thanks for flagging the read-error case. |
…ter directory Marvisak#2336's test read `prebuilt-pipelines.txt` straight from the cache root. On this branch the library and its prebuilt list live in an adapter directory under `<SOURCE_HASH>` (Marvisak#2706, Marvisak#2803), so the read failed with "file not found" although the list was saved. The test now looks for the file below the cache root. The code under test is unchanged; under Wine (vkd3d-proton, Microsoft's d3dcompiler_47 for the test shaders) the test passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
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.