diff --git a/wgpu-hal/src/auxil/dxgi/factory.rs b/wgpu-hal/src/auxil/dxgi/factory.rs index bf806ab320..4b71abda37 100644 --- a/wgpu-hal/src/auxil/dxgi/factory.rs +++ b/wgpu-hal/src/auxil/dxgi/factory.rs @@ -138,7 +138,7 @@ pub fn create_factory( // The `DXGI_CREATE_FACTORY_DEBUG` flag is only allowed to be passed to // `CreateDXGIFactory2` if the debug interface is actually available. So // we check for whether it exists first. - if lib_dxgi.debug_interface1().is_ok() { + if let Ok(Some(_)) = lib_dxgi.debug_interface1() { factory_flags |= Dxgi::DXGI_CREATE_FACTORY_DEBUG; } diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index 7b6acc623a..31d0511d39 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -34,7 +34,7 @@ impl crate::Instance for super::Instance { .intersects(wgt::InstanceFlags::VALIDATION | wgt::InstanceFlags::GPU_BASED_VALIDATION) { // Enable debug layer - if let Ok(debug_controller) = lib_main.debug_interface() { + if let Ok(Some(debug_controller)) = lib_main.debug_interface() { if desc.flags.intersects(wgt::InstanceFlags::VALIDATION) { unsafe { debug_controller.EnableDebugLayer() } } diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index defeab1ada..0efb418135 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -190,7 +190,7 @@ impl D3D12Lib { blob.ok_or(crate::DeviceError::Unexpected) } - fn debug_interface(&self) -> Result { + fn debug_interface(&self) -> Result, crate::DeviceError> { // Calls windows::Win32::Graphics::Direct3D12::D3D12GetDebugInterface on d3d12.dll type Fun = extern "system" fn( riid: *const windows_core::GUID, @@ -200,11 +200,18 @@ impl D3D12Lib { let mut result__ = None; - (func)(&Direct3D12::ID3D12Debug::IID, <*mut _>::cast(&mut result__)) - .ok() - .into_device_result("GetDebugInterface")?; + let res = (func)(&Direct3D12::ID3D12Debug::IID, <*mut _>::cast(&mut result__)).ok(); - result__.ok_or(crate::DeviceError::Unexpected) + if let Err(ref err) = res { + match err.code() { + Dxgi::DXGI_ERROR_SDK_COMPONENT_MISSING => return Ok(None), + _ => {} + } + } + + res.into_device_result("GetDebugInterface")?; + + result__.ok_or(crate::DeviceError::Unexpected).map(Some) } } @@ -219,7 +226,7 @@ impl DxgiLib { } /// Will error with crate::DeviceError::Unexpected if DXGI 1.3 is not available. - pub fn debug_interface1(&self) -> Result { + pub fn debug_interface1(&self) -> Result, crate::DeviceError> { // Calls windows::Win32::Graphics::Dxgi::DXGIGetDebugInterface1 on dxgi.dll type Fun = extern "system" fn( flags: u32, @@ -230,11 +237,18 @@ impl DxgiLib { let mut result__ = None; - (func)(0, &Dxgi::IDXGIInfoQueue::IID, <*mut _>::cast(&mut result__)) - .ok() - .into_device_result("debug_interface1")?; + let res = (func)(0, &Dxgi::IDXGIInfoQueue::IID, <*mut _>::cast(&mut result__)).ok(); - result__.ok_or(crate::DeviceError::Unexpected) + if let Err(ref err) = res { + match err.code() { + Dxgi::DXGI_ERROR_SDK_COMPONENT_MISSING => return Ok(None), + _ => {} + } + } + + res.into_device_result("debug_interface1")?; + + result__.ok_or(crate::DeviceError::Unexpected).map(Some) } /// Will error with crate::DeviceError::Unexpected if DXGI 1.4 is not available.