From 9274ac3205fa9ecb46c165cf106f546fea2d2b47 Mon Sep 17 00:00:00 2001 From: Willy <11591782+WillyboPeep@users.noreply.github.com> Date: Tue, 24 Nov 2026 09:55:20 -0600 Subject: [PATCH] D3D12.X: say why no GPU made a device with the debug layer on With XCL_D3D12_DEBUG a debug layer of another SDK version than the D3D12 runtime makes every device fail with E_INVALIDARG; only the runtime's debug output names the cause (887a002d, "D3D12 SDKLayers dll does not match the D3D12SDKVersion of D3D12 Core dll"). XCL dropped each GPU's error, logged WARP's alone and went on with the fallback device, so the debug-layer e2e test failed with twelve D3D12.X failures in the test title. Each GPU's error is now logged before WARP is tried, and with the debug layer on a warning names both DLLs and their versions. The e2e test skips on that warning. Seen on Windows 11 26300 with the inbox D3D12Core 10.0.26100.10068 (Windows Update) beside the Graphics Tools' d3d12SDKLayers 10.0.26100.1. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/gpu/recomp/dxc.rs | 2 +- crates/xcl/src/hle/d3d12x/real.rs | 56 ++++++++++++++++++++++++++++--- crates/xcl/tests/e2e.rs | 10 ++++-- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/dxc.rs b/crates/xcl/src/gpu/recomp/dxc.rs index 907511e63c..14418d6998 100644 --- a/crates/xcl/src/gpu/recomp/dxc.rs +++ b/crates/xcl/src/gpu/recomp/dxc.rs @@ -34,7 +34,7 @@ fn parse_version(s: &str) -> Option<[u32; 4]> { } /// The version resource of a file. -fn file_version(path: &Path) -> Option<[u32; 4]> { +pub(crate) fn file_version(path: &Path) -> Option<[u32; 4]> { use windows_sys::Win32::Storage::FileSystem::{GetFileVersionInfoSizeW, GetFileVersionInfoW, VerQueryValueW, VS_FIXEDFILEINFO}; let name = crate::util::wide(&path.to_string_lossy()); unsafe { diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index f1ea87c8ba..9ee7bc1334 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -499,6 +499,8 @@ pub fn init() -> Result { let factory: IDXGIFactory6 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).map_err(|e| format!("DXGI: {e}"))?; let mut device: Option = None; let mut name = String::new(); + // why each GPU made no device: otherwise only WARP's error is told + let mut refused: Vec = Vec::new(); let sel = crate::gpu::adapter::Selector::from_env_or(&cfg.d3d12_adapter); if sel != crate::gpu::adapter::Selector::Warp { let mut list = crate::gpu::adapter::candidates(&factory, &sel); @@ -507,16 +509,25 @@ pub fn init() -> Result { list = crate::gpu::adapter::candidates(&factory, &crate::gpu::adapter::Selector::Auto); } for (adapter, desc) in list { - if let Ok(dev) = crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0) { - device = Some(dev); - name = format!("{} ({} MiB VRAM)", crate::gpu::adapter::name(&desc), desc.DedicatedVideoMemory >> 20); - break; + match crate::gpu::agility::create_device(&adapter, D3D_FEATURE_LEVEL_12_0) { + Ok(dev) => { + device = Some(dev); + name = format!("{} ({} MiB VRAM)", crate::gpu::adapter::name(&desc), desc.DedicatedVideoMemory >> 20); + break; + } + Err(e) => refused.push(format!("{}: {e}", crate::gpu::adapter::name(&desc))), } } } + if debug && device.is_none() && !refused.is_empty() { + crate::xlog_warn!("{}", debug_layer_mismatch()); + } let device = match device { Some(d) => d, None => { + if !refused.is_empty() { + crate::xlog_warn!("D3D12: no device on the GPU ({}) – trying WARP", refused.join("; ")); + } let warp: IDXGIAdapter = factory.EnumWarpAdapter().map_err(|e| format!("WARP: {e}"))?; let d = crate::gpu::agility::create_device(&warp, D3D_FEATURE_LEVEL_11_0) .map_err(|e| format!("D3D12 device (WARP): {e}"))?; @@ -541,6 +552,43 @@ pub fn init() -> Result { } } +/// The warning when no GPU makes a device with the debug layer on. A debug layer of another SDK +/// version than the D3D12 runtime does that: every device fails with `E_INVALIDARG`, and only +/// the runtime's debug output says why (`887a002d`, "D3D12 SDKLayers dll does not match the +/// D3D12SDKVersion of D3D12 Core dll"), so a run went on with the fallback device and named +/// WARP's error alone. Seen with the inbox D3D12Core 10.0.26100.10068 (updated by Windows +/// Update) next to the Graphics Tools' d3d12SDKLayers 10.0.26100.1. +fn debug_layer_mismatch() -> String { + let core = loaded_d3d12_core(); + format!( + "D3D12: with the debug layer on (XCL_D3D12_DEBUG) no GPU made a device; the usual cause is a debug layer of another SDK version than the D3D12 runtime ({}; {}) – update the Graphics Tools optional feature, or run without XCL_D3D12_DEBUG", + dll_version(&core.with_file_name("d3d12SDKLayers.dll")), + dll_version(&core) + ) +} + +/// The `D3D12Core.dll` this process loaded (the inbox one or an Agility SDK's); the debug layer +/// it takes is the `d3d12SDKLayers.dll` beside it, unloaded again when no device was made. +fn loaded_d3d12_core() -> std::path::PathBuf { + use windows_sys::Win32::System::LibraryLoader::{GetModuleFileNameW, GetModuleHandleW}; + let h = unsafe { GetModuleHandleW(crate::util::wide("D3D12Core.dll").as_ptr()) }; + let mut buf = [0u16; 520]; + let n = if h.is_null() { 0 } else { (unsafe { GetModuleFileNameW(h, buf.as_mut_ptr(), buf.len() as u32) }) as usize }; + if n == 0 { + return std::path::PathBuf::from(std::env::var_os("SystemRoot").unwrap_or_else(|| r"C:\Windows".into())).join("System32").join("D3D12Core.dll"); + } + std::path::PathBuf::from(String::from_utf16_lossy(&buf[..n])) +} + +/// A DLL's file version and path, for the log. +fn dll_version(path: &std::path::Path) -> String { + let name = path.file_name().unwrap_or_default().to_string_lossy(); + match crate::gpu::recomp::dxc::file_version(path) { + Some(v) => format!("{name} {}.{}.{}.{} ({})", v[0], v[1], v[2], v[3], path.display()), + None => format!("{name}: no version resource ({})", path.display()), + } +} + /// A debug layer message: errors and warnings into the log – the first 8 of each message id /// (3 000 in all). One cap for all of them (200) was used up in seconds by two per-frame state /// errors of a retail game, long before the message that came with its device removal. diff --git a/crates/xcl/tests/e2e.rs b/crates/xcl/tests/e2e.rs index 3c541449cf..bab0be21fb 100644 --- a/crates/xcl/tests/e2e.rs +++ b/crates/xcl/tests/e2e.rs @@ -243,7 +243,8 @@ fn test_title_runs_and_game_folder_is_untouched() { /// no root signature on the PC list – console SetGraphicsRootSignature binds nothing there – /// which the debug layer reports on every GPU and WARP faults on. No copy reads a buffer in /// another state than COPY_SOURCE either. Needs the debug layer -/// (Graphics Tools) and the system XGameRuntime, as the run above does; skipped without them. +/// (Graphics Tools) and the system XGameRuntime, as the run above does; skipped without them, +/// and when the debug layer is of another SDK version than the D3D12 runtime (no device then). #[test] fn test_title_draws_with_a_root_signature_under_the_debug_layer() { let sys = PathBuf::from(std::env::var_os("SystemRoot").unwrap_or_else(|| r"C:\Windows".into())).join("System32"); @@ -265,8 +266,13 @@ fn test_title_draws_with_a_root_signature_under_the_debug_layer() { } let out = Command::new(&xcl).arg("run").arg(&game).arg("--").arg("--hello").env("XCL_DATA_ROOT", &data).env("XCL_D3D12_DEBUG", "1").output().expect("spawn xcl"); let stdout = String::from_utf8_lossy(&out.stdout); + let log = std::fs::read_to_string(data.join("XCL.TestTitle").join("logs").join("xcl.log")).unwrap_or_default(); + // a debug layer of another SDK version than the D3D12 runtime makes no device at all + if log.contains("with the debug layer on (XCL_D3D12_DEBUG) no GPU made a device") { + eprintln!("SKIPPED test_title_draws_with_a_root_signature_under_the_debug_layer: no GPU made a device with the debug layer on (see the warning in xcl.log)"); + return; + } assert!(stdout.contains("xcl_testtitle: done, failures: 0"), "the test title did not run to the end:\n{stdout}"); - let log = std::fs::read_to_string(data.join("XCL.TestTitle").join("logs").join("xcl.log")).unwrap(); assert!(log.contains("D3D12: debug layer enabled"), "the debug layer did not come up"); let bad: Vec<&str> = log.lines().filter(|l| l.contains("No root signature has been set")).collect(); assert!(bad.is_empty(), "{} draws without a root signature, first: {}", bad.len(), bad[0]);