Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d3d12] handle absence of Windows SDK #6262

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion wgpu-hal/src/auxil/dxgi/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
Expand Down
34 changes: 24 additions & 10 deletions wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl D3D12Lib {
blob.ok_or(crate::DeviceError::Unexpected)
}

fn debug_interface(&self) -> Result<Direct3D12::ID3D12Debug, crate::DeviceError> {
fn debug_interface(&self) -> Result<Option<Direct3D12::ID3D12Debug>, crate::DeviceError> {
// Calls windows::Win32::Graphics::Direct3D12::D3D12GetDebugInterface on d3d12.dll
type Fun = extern "system" fn(
riid: *const windows_core::GUID,
Expand All @@ -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)
}
}

Expand All @@ -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<Dxgi::IDXGIInfoQueue, crate::DeviceError> {
pub fn debug_interface1(&self) -> Result<Option<Dxgi::IDXGIInfoQueue>, crate::DeviceError> {
// Calls windows::Win32::Graphics::Dxgi::DXGIGetDebugInterface1 on dxgi.dll
type Fun = extern "system" fn(
flags: u32,
Expand All @@ -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.
Expand Down
Loading