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 known error variants returned by D3D12CreateDevice #6241

Merged
merged 1 commit into from
Sep 9, 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/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
Loading