Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions d3d12/crates/leonida-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ fn create() -> windows::core::Result<Host> {
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 {
Expand Down Expand Up @@ -1644,6 +1644,58 @@ fn chosen_adapter() -> Option<IDXGIAdapter1> {
}
}

/// 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<IDXGIAdapter1> {
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()?;
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<IDXGIAdapter> {
// SAFETY: plain DXGI adapter queries.
unsafe {
Expand Down Expand Up @@ -15900,4 +15952,3 @@ mod gate_tests {
}
}
}

Loading