Skip to content

Commit

Permalink
[d3d12] handle known error variants returned by D3D12CreateDevice (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy authored Sep 9, 2024
1 parent fb0cb1e commit 0553729
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl super::Adapter {
profiling::scope!("ID3D12Device::create_device");
library
.create_device(&adapter, Direct3D::D3D_FEATURE_LEVEL_11_0)
.ok()?
.ok()??
};

profiling::scope!("feature queries");
Expand Down
21 changes: 15 additions & 6 deletions wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl D3D12Lib {
&self,
adapter: &DxgiAdapter,
feature_level: Direct3D::D3D_FEATURE_LEVEL,
) -> Result<Direct3D12::ID3D12Device, crate::DeviceError> {
) -> Result<Option<Direct3D12::ID3D12Device>, crate::DeviceError> {
// Calls windows::Win32::Graphics::Direct3D12::D3D12CreateDevice on d3d12.dll
type Fun = extern "system" fn(
padapter: *mut core::ffi::c_void,
Expand All @@ -118,19 +118,28 @@ impl D3D12Lib {
) -> windows_core::HRESULT;
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"D3D12CreateDevice\0") }?;

let mut result__ = None;
let mut result__: Option<Direct3D12::ID3D12Device> = None;

(func)(
let res = (func)(
adapter.as_raw(),
feature_level,
// TODO: Generic?
&Direct3D12::ID3D12Device::IID,
<*mut _>::cast(&mut result__),
)
.ok()
.into_device_result("Device creation")?;
.ok();

result__.ok_or(crate::DeviceError::Unexpected)
if let Err(ref err) = res {
match err.code() {
Dxgi::DXGI_ERROR_UNSUPPORTED => return Ok(None),
Dxgi::DXGI_ERROR_DRIVER_INTERNAL_ERROR => return Err(crate::DeviceError::Lost),
_ => {}
}
}

res.into_device_result("Device creation")?;

result__.ok_or(crate::DeviceError::Unexpected).map(Some)
}

fn serialize_root_signature(
Expand Down

0 comments on commit 0553729

Please sign in to comment.