diff --git a/CHANGELOG.md b/CHANGELOG.md index 570693fb7..5cea50ff5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,10 @@ Bottom level categories: - Fixed signed integer `%` (and `%=`) returning the wrong result for negative operands in the GLSL (OpenGL/GLES) backend, e.g. `-1 % 768` yielding `255` instead of `-1`. GLSL's `%` is undefined when either operand is negative, so signed remainder is now lowered as `a - b * (a / b)`, matching the SPIR-V, HLSL, and Metal backends. By @mstampfli in [#9687](https://github.com/gfx-rs/wgpu/pull/9687). +#### WebGPU + +- Recognize `GPUInternalError` when converting a WebGPU error, mapping it to `Error::Internal` instead of panicking with "Unexpected error". By @evilpies in [#9919](https://github.com/gfx-rs/wgpu/pull/9919). + ### Documentation #### General diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index fd111f869..0a791fe2f 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -79,6 +79,11 @@ impl crate::Error { source, description: js_error.message(), } + } else if let Some(js_error) = js_error.dyn_ref::() { + crate::Error::Internal { + source, + description: js_error.message(), + } } else if js_error.has_type::() { crate::Error::OutOfMemory { source } } else { diff --git a/wgpu/src/backend/webgpu/webgpu_sys/gen_GpuInternalError.rs b/wgpu/src/backend/webgpu/webgpu_sys/gen_GpuInternalError.rs new file mode 100644 index 000000000..352914dd4 --- /dev/null +++ b/wgpu/src/backend/webgpu/webgpu_sys/gen_GpuInternalError.rs @@ -0,0 +1,51 @@ +// DO NOT EDIT THIS FILE! +// +// This module part of a subset of web-sys that is used by wgpu's webgpu backend. +// +// These bindings are vendored into wgpu for the sole purpose of letting +// us pin the WebGPU backend to a specific version of the bindings, not +// to enable local changes. There are no provisions to preserve changes +// you make here the next time we re-vendor the bindings. +// +// The `web-sys` crate does not treat breaking changes to the WebGPU API +// as semver breaking changes, as WebGPU is "unstable". This means Cargo +// will not let us mix versions of `web-sys`, pinning WebGPU bindings to +// a specific version, while letting other bindings like WebGL get +// updated. Vendoring WebGPU was the workaround we chose. +// +// Vendoring also allows us to avoid building `web-sys` with +// `--cfg=web_sys_unstable_apis`, needed to get the WebGPU bindings. +// +// If you want to improve the generated code, please submit a PR to the https://github.com/wasm-bindgen/wasm-bindgen repository. +// +// This file was generated by the `cargo xtask vendor-web-sys --version 0.2.115` command. +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = GpuError , extends = :: js_sys :: Object , js_name = GPUInternalError , typescript_type = "GPUInternalError")] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `GpuInternalError` class."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUInternalError)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `GpuInternalError`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://wasm-bindgen.github.io/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub type GpuInternalError; + + #[wasm_bindgen(catch, constructor, js_class = "GPUInternalError")] + #[doc = "The `new GpuInternalError(..)` constructor, creating a new instance of `GpuInternalError`."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUInternalError/GPUInternalError)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `GpuInternalError`*"] + #[doc = ""] + #[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"] + #[doc = "[described in the `wasm-bindgen` guide](https://wasm-bindgen.github.io/wasm-bindgen/web-sys/unstable-apis.html)*"] + pub fn new(message: &str) -> Result; +} diff --git a/wgpu/src/backend/webgpu/webgpu_sys/mod.rs b/wgpu/src/backend/webgpu/webgpu_sys/mod.rs index 14a7fd2bd..7311d6d6f 100644 --- a/wgpu/src/backend/webgpu/webgpu_sys/mod.rs +++ b/wgpu/src/backend/webgpu/webgpu_sys/mod.rs @@ -162,6 +162,8 @@ mod gen_GpuMipmapFilterMode; pub use gen_GpuMipmapFilterMode::*; mod gen_GpuMultisampleState; pub use gen_GpuMultisampleState::*; +mod gen_GpuInternalError; +pub use gen_GpuInternalError::*; mod gen_GpuObjectDescriptorBase; pub use gen_GpuObjectDescriptorBase::*; mod gen_GpuOrigin2dDict; diff --git a/xtask/src/vendor_web_sys.rs b/xtask/src/vendor_web_sys.rs index 989882f04..e0a14561d 100644 --- a/xtask/src/vendor_web_sys.rs +++ b/xtask/src/vendor_web_sys.rs @@ -89,6 +89,7 @@ const WEB_SYS_FEATURES_NEEDED: &[&str] = &[ "gpu_map_mode", "GpuMipmapFilterMode", "GpuMultisampleState", + "GpuInternalError", "GpuObjectDescriptorBase", "GpuOrigin2dDict", "GpuOrigin3dDict",