Skip to content

Commit 5d4b861

Browse files
authored
d3d12: Include device removal reason when ERROR_DEVICE_REMOVED is raised (#262)
Our "painful" `Error::Internal(String)` design for useful errors makes it impossible for downstream crates to retrieve the original `HRESULT` and match on it as necessary to action on stringified error codes like `DXGI_ERROR_DEVICE_REMOVED`, which print: ID3D12Device::CreatePlacedResource failed: The GPU device instance has been suspended. Use GetDeviceRemovedReason to determine the appropriate action. (0x887A0005) Without rearchitecting our `Error` type, the nicest middle ground is anyway for `gpu-allocator` to already add the error message from `GetDeviceRemovedReason()` to the `Result` so that downstream crates can immediately see in their error messages _why_ the device is or was removed/suspended when they make an allocation.
1 parent 33fa052 commit 5d4b861

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/d3d12/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use std::{
99
use log::{debug, warn, Level};
1010
use windows::Win32::{
1111
Foundation::E_OUTOFMEMORY,
12-
Graphics::{Direct3D12::*, Dxgi::Common::DXGI_FORMAT},
12+
Graphics::{
13+
Direct3D12::*,
14+
Dxgi::{Common::DXGI_FORMAT, DXGI_ERROR_DEVICE_REMOVED},
15+
},
1316
};
1417

1518
#[cfg(feature = "public-winapi")]
@@ -954,6 +957,12 @@ impl Allocator {
954957
}
955958
}
956959
} {
960+
if e.code() == DXGI_ERROR_DEVICE_REMOVED {
961+
return Err(AllocationError::Internal(format!(
962+
"ID3D12Device::CreateCommittedResource DEVICE_REMOVED: {:?}",
963+
unsafe { self.device.GetDeviceRemovedReason() }
964+
)));
965+
}
957966
return Err(AllocationError::Internal(format!(
958967
"ID3D12Device::CreateCommittedResource failed: {}",
959968
e
@@ -1064,6 +1073,12 @@ impl Allocator {
10641073
}
10651074
}
10661075
} {
1076+
if e.code() == DXGI_ERROR_DEVICE_REMOVED {
1077+
return Err(AllocationError::Internal(format!(
1078+
"ID3D12Device::CreatePlacedResource DEVICE_REMOVED: {:?}",
1079+
unsafe { self.device.GetDeviceRemovedReason() }
1080+
)));
1081+
}
10671082
return Err(AllocationError::Internal(format!(
10681083
"ID3D12Device::CreatePlacedResource failed: {}",
10691084
e

0 commit comments

Comments
 (0)