feat(types): add error::{ErrorType, WebGpuError} APIs

This commit is contained in:
Erich Gubler committed 2025-06-30 10:58:56 -04:00
1 parent c3922d53d7
commit c8752e5118
3 files changed
+50

No files matched your search

+3
View File
@@ -58,6 +58,9 @@ Bottom level categories:
- Add extra acceleration structure vertex formats. By @Vecvec in [#7580](https://github.com/gfx-rs/wgpu/pull/7580).
- Add acceleration structure limits. By @Vecvec in [#7845](https://github.com/gfx-rs/wgpu/pull/7845).
- Add support for clip-distances feature for Vulkan and GL backends. By @dzamkov in [#7730](https://github.com/gfx-rs/wgpu/pull/7730)
- Added `wgpu_types::error::{ErrorType, WebGpuError}` for classification of errors according to WebGPU's [`GPUError`]'s classification scheme. This allows users of `wgpu-core` to offload error classification onto the WGPU ecosystem, rather than having to do it themselves without sufficient information. By @ErichDonGubler in [#6547](https://github.com/gfx-rs/wgpu/pull/6547).
[`GPUError`]: https://www.w3.org/TR/webgpu/#gpuerror
#### Vulkan
+46
View File
@@ -0,0 +1,46 @@
//! Shared types for WebGPU errors. See also:
//! <https://gpuweb.github.io/gpuweb/#errors-and-debugging>
use crate::DeviceLostReason;
/// A classification of WebGPU error for implementers of the WebGPU API to use in their own error
/// layer(s).
///
/// Strongly correlates to the [`GPUError`] and [`GPUErrorFilter`] types in the WebGPU API, with an
/// additional [`Self::DeviceLost`] variant.
///
/// [`GPUError`]: https://gpuweb.github.io/gpuweb/#gpuerror
/// [`GPUErrorFilter`]: https://gpuweb.github.io/gpuweb/#enumdef-gpuerrorfilter
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum ErrorType {
/// A [`GPUInternalError`].
///
/// [`GPUInternalError`]: https://gpuweb.github.io/gpuweb/#gpuinternalerror
Internal,
/// A [`GPUOutOfMemoryError`].
///
/// [`GPUOutOfMemoryError`]: https://gpuweb.github.io/gpuweb/#gpuoutofmemoryerror
OutOfMemory,
/// A [`GPUValidationError`].
///
/// [`GPUValidationError`]: https://gpuweb.github.io/gpuweb/#gpuvalidationerror
Validation,
/// Indicates that device loss occurred. In JavaScript, this means the [`GPUDevice.lost`]
/// property should be `resolve`d.
///
/// [`GPUDevice.lost`]: https://www.w3.org/TR/webgpu/#dom-gpudevice-lost
DeviceLost {
/// The reason the device was lost.
reason: DeviceLostReason,
},
}
/// A trait for querying the [`ErrorType`] classification of an error.
///
/// This is intended to be used as a convenience by implementations of WebGPU to classify errors
/// returned by [`wgpu_core`](crate).
pub trait WebGpuError: core::error::Error + 'static {
/// Determine the classification of this error as a WebGPU [`ErrorType`].
fn webgpu_error_type(&self) -> ErrorType;
}
+1
View File
@@ -36,6 +36,7 @@ pub mod assertions;
mod cast_utils;
mod counters;
mod env;
pub mod error;
mod features;
pub mod instance;
pub mod math;