[d3d12] handle absence of Windows SDK (#6262)

This commit is contained in:
Teodor Tanasoaia 2024-09-13 15:56:26 +02:00 committed by GitHub
parent c2e0ad293f
commit ff52b86331
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 12 deletions

View File

@ -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;
}

View File

@ -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() }
}

View File

@ -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,
@ -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<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,
@ -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.