From 2c31414517c895a6225b1e72a2840484fe4d4a2a Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Thu, 15 Aug 2024 10:25:36 +0100 Subject: [PATCH] add an `Unexpected` variant to `DeviceError` --- wgpu-core/src/device/mod.rs | 1 + wgpu-core/src/instance.rs | 1 + wgpu-hal/src/lib.rs | 2 ++ wgpu-hal/src/vulkan/device.rs | 2 +- wgpu-hal/src/vulkan/mod.rs | 4 ++-- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index ac35ec7530..777dd262ab 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -404,6 +404,7 @@ impl From for DeviceError { hal::DeviceError::Lost => DeviceError::Lost, hal::DeviceError::OutOfMemory => DeviceError::OutOfMemory, hal::DeviceError::ResourceCreationFailed => DeviceError::ResourceCreationFailed, + hal::DeviceError::Unexpected => DeviceError::Lost, } } } diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index a71117cfe1..d23c6a65e8 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -342,6 +342,7 @@ impl Adapter { hal::DeviceError::Lost => RequestDeviceError::DeviceLost, hal::DeviceError::OutOfMemory => RequestDeviceError::OutOfMemory, hal::DeviceError::ResourceCreationFailed => RequestDeviceError::Internal, + hal::DeviceError::Unexpected => RequestDeviceError::DeviceLost, })?; self.create_device_and_queue_from_hal(open, desc, instance_flags, trace_path) diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 8f7db88450..b62a6b5962 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -314,6 +314,8 @@ pub enum DeviceError { Lost, #[error("Creation of a resource failed for a reason other than running out of memory.")] ResourceCreationFailed, + #[error("Unexpected error variant (driver implementation is at fault)")] + Unexpected, } #[derive(Clone, Debug, Eq, PartialEq, Error)] diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index ef02899a1d..689bc1b3ee 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -2559,7 +2559,7 @@ impl From for crate::DeviceError { } } -/// We usually map unexpected vulkan errors to the [`crate::DeviceError::Lost`] +/// We usually map unexpected vulkan errors to the [`crate::DeviceError::Unexpected`] /// variant to be more robust even in cases where the driver is not /// complying with the spec. /// diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index aa4b50f29c..3f3bd557e4 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -1266,14 +1266,14 @@ fn map_pipeline_err(err: vk::Result) -> crate::DeviceError { map_host_device_oom_err(err) } -/// Returns [`crate::DeviceError::Lost`] or panics if the `internal_error_panic` +/// Returns [`crate::DeviceError::Unexpected`] or panics if the `internal_error_panic` /// feature flag is enabled. fn get_unexpected_err(_err: vk::Result) -> crate::DeviceError { #[cfg(feature = "internal_error_panic")] panic!("Unexpected Vulkan error: {_err:?}"); #[allow(unreachable_code)] - crate::DeviceError::Lost + crate::DeviceError::Unexpected } /// Returns [`crate::DeviceError::OutOfMemory`] or panics if the `oom_panic`