Skip to content

Commit

Permalink
add an Unexpected variant to DeviceError
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Aug 15, 2024
1 parent f5c21ee commit 4922360
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl From<hal::DeviceError> for DeviceError {
hal::DeviceError::Lost => DeviceError::Lost,
hal::DeviceError::OutOfMemory => DeviceError::OutOfMemory,
hal::DeviceError::ResourceCreationFailed => DeviceError::ResourceCreationFailed,
hal::DeviceError::Unexpected => DeviceError::Lost,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ impl From<gpu_descriptor::AllocationError> 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.
///
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 4922360

Please sign in to comment.