From 2e2e163235ff6988673723ccfcd1108d7c26e75b Mon Sep 17 00:00:00 2001 From: fiestorra Date: Tue, 1 Dec 2026 23:47:57 +0100 Subject: [PATCH 1/2] test: the crate's device tests ask the card with memory of its own, not the default one Every `#[test]` in this crate that makes a D3D12 device goes through `host()`, which called `D3D12CreateDevice(None, ..)` - "Windows' default card". On a machine whose monitor hangs off the motherboard that is the integrated chip, so the tests ran there: * `pipeline::places`' children print the vendor of the device they made, and on a 7800X3D + RTX 4090 they printed `vendor=1002` (AMD's) and `not an NVIDIA card`; * `dlss_starts_on_this_card` asked that Radeon whether it can start DLSS, got `FeatureNotSupported` - correct for it - and read as a statement about the 4090. Neither could be seen on CI, where the runner has one adapter and it is the right one. Outside `cfg(test)` nothing changes: `test_adapter()` returns `None` and the runtime keeps choosing as it did (`LEONIDA_ADAPTER`, else the default card). In a test build it picks the adapter with the most `DedicatedVideoMemory` that is not software - the card a game would be run on, whatever its vendor. Measured on `main` 1fff69129 + this change, RTX 4090 / driver 621.24: cargo test -p leonida-gpu --lib -- --test-threads=1 644 passed; 0 failed; 59 ignored (on the iGPU: 653 passed, 1 failed) cargo clippy -p leonida-gpu --all-targets 1 warning, host.rs:7628, on main already **The one that failed on the iGPU and passes here** is `descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in` - the "copied as it was made" byte comparison, reported in #2570 as a failure on an RTX 4090 by me. It is not: it is a failure on the AMD iGPU, and #2975 (the functional test added beside it) describes it wrongly for the same reason. **Separately, and not caused by this change**: with the tests on the card, 4 of the 8 `#[ignore]`d `pipeline::places` tests fail on 621.24 (they pass vacuously on an iGPU, which is how this went unnoticed). Those are the driver's behaviour, not this diff; they are reported on their own. Written with an AI assistant. --- d3d12/crates/leonida-gpu/src/host.rs | 45 ++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/d3d12/crates/leonida-gpu/src/host.rs b/d3d12/crates/leonida-gpu/src/host.rs index 513b2f0283..735e77aa77 100644 --- a/d3d12/crates/leonida-gpu/src/host.rs +++ b/d3d12/crates/leonida-gpu/src/host.rs @@ -1489,7 +1489,7 @@ fn create() -> windows::core::Result { let adapter = warp_adapter()?; D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device)?; tracing::info!("host device on the software adapter (WARP)"); - } else if let Some(adapter) = chosen_adapter() { + } else if let Some(adapter) = chosen_adapter().or_else(|| test_adapter()) { D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device)?; crate::tdr::log(); } else { @@ -1644,6 +1644,48 @@ fn chosen_adapter() -> Option { } } +/// The card a test's device is made on: the one with the most memory of its own. +/// +/// `D3D12CreateDevice(None, ..)` makes the device on Windows' default adapter, and on a +/// machine whose monitor hangs off the motherboard that is the integrated chip. Every +/// device test then runs on that chip and the card the tests are about is never asked - +/// measured on a 7800X3D with an RTX 4090 (2026-12-01): the `places` tests printed +/// `vendor=1002` (AMD's) and said "not an NVIDIA card", and `dlss_starts_on_this_card` +/// asked the Radeon whether it can start DLSS. Outside `cfg(test)` this is `None`, so the +/// runtime's own choice of adapter is untouched. +fn test_adapter() -> Option { + if !cfg!(test) { + return None; + } + // SAFETY: plain DXGI adapter queries. + unsafe { + let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).ok()?; + let mut best: Option<(u64, IDXGIAdapter1)> = None; + for i in 0.. { + let Ok(adapter) = factory.EnumAdapters1(i) else { break }; + let Ok(desc) = adapter.GetDesc1() else { continue }; + if desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0 { + continue; + } + let memory = desc.DedicatedVideoMemory as u64; + let better = match &best { + None => true, + Some((most, _)) => memory > *most, + }; + if better { + best = Some((memory, adapter)); + } + } + if let Some((memory, _)) = &best { + tracing::info!( + memory_mb = memory / (1024 * 1024), + "a test's device is made on the card with the most memory of its own" + ); + } + best.map(|(_, adapter)| adapter) + } +} + pub(crate) fn warp_adapter() -> windows::core::Result { // SAFETY: plain DXGI adapter queries. unsafe { @@ -15900,4 +15942,3 @@ mod gate_tests { } } } - From 9e1e95930d34f61b8d7aedb31948b2f8e03c484f Mon Sep 17 00:00:00 2001 From: fiestorra Date: Tue, 1 Dec 2026 23:57:58 +0100 Subject: [PATCH 2/2] test: prefer no card when a test asked for the software adapter andrew-ai measured the places child making its early root signatures on the card's LUID while \host\ went to the Microsoft Basic Render Driver once LEONIDA_D3D12_WARP was set: two devices in one run, where the test's premise is that they are one. \ est_adapter()\ now returns None when that switch is on, so nothing is preferred and the switch means what it says. Verified that it changes nothing otherwise: the suite is 644 passed / 0 failed with the card, as before. --- d3d12/crates/leonida-gpu/src/host.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/d3d12/crates/leonida-gpu/src/host.rs b/d3d12/crates/leonida-gpu/src/host.rs index 735e77aa77..1b473b09c3 100644 --- a/d3d12/crates/leonida-gpu/src/host.rs +++ b/d3d12/crates/leonida-gpu/src/host.rs @@ -1489,7 +1489,7 @@ fn create() -> windows::core::Result { let adapter = warp_adapter()?; D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device)?; tracing::info!("host device on the software adapter (WARP)"); - } else if let Some(adapter) = chosen_adapter().or_else(|| test_adapter()) { + } else if let Some(adapter) = chosen_adapter().or_else(test_adapter) { D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut device)?; crate::tdr::log(); } else { @@ -1657,6 +1657,16 @@ fn test_adapter() -> Option { if !cfg!(test) { return None; } + // A test that asked for the software adapter (`LEONIDA_D3D12_WARP`, diagnostics) wants + // every device on it. The `places` tests' steps have to be the same device as the + // host's, and that switch sends `host` to WARP: with a card preferred here, `make=` and + // `pipe=` would still make theirs on the card and the run would mix two devices + // (andrew-ai measured it: with the switch on, `make=20,21` on an RTX 5070's LUID and + // `host` on the Microsoft Basic Render Driver's). Preferring nothing leaves the switch + // meaning what it says. + if cfg!(feature = "diagnostics") && crate::switch::on("LEONIDA_D3D12_WARP") { + return None; + } // SAFETY: plain DXGI adapter queries. unsafe { let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).ok()?;