Debian Codegraph @

third_party/rust/wgpu-hal/src/auxil/dxgi/result.rs

raw
1 use windows::Win32::{Foundation, Graphics::Dxgi};
2
3 pub(crate) trait HResult<O> {
4 fn into_device_result(self, description: &str) -> Result<O, crate::DeviceError>;
5 }
6 impl<T> HResult<T> for windows::core::Result<T> {
7 fn into_device_result(self, description: &str) -> Result<T, crate::DeviceError> {
8 #![allow(unreachable_code)]
9
10 self.map_err(|err| {
11 log::error!("{} failed: {}", description, err);
12
13 match err.code() {
14 Foundation::E_OUTOFMEMORY => crate::DeviceError::OutOfMemory,
15 Dxgi::DXGI_ERROR_DEVICE_RESET | Dxgi::DXGI_ERROR_DEVICE_REMOVED => {
16 #[cfg(feature = "device_lost_panic")]
17 panic!("{description} failed: Device lost ({err})");
18 crate::DeviceError::Lost
19 }
20 _ => {
21 #[cfg(feature = "internal_error_panic")]
22 panic!("{description} failed: {err}");
23 crate::DeviceError::Unexpected
24 }
25 }
26 })
27 }
28 }