diff --git a/CHANGELOG.md b/CHANGELOG.md index ea52db5be..cd8b793a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,7 @@ By @teoxoy in [#9351](https://github.com/gfx-rs/wgpu/pull/9351). - `Buffer::get_mapped_range` and variants now return `Result<_, MapRangeError>>` instead of panicking, in line with WebGPU spec. By @atlv24 in [#9281](https://github.com/gfx-rs/wgpu/pull/9281). - Passthrough shaders now require a list of entry points when being created. by @inner-daemons in [#9064](https://github.com/gfx-rs/wgpu/pull/9064). - BREAKING: The `dispatch` and `dispatch_indirect` methods on pass and bundle encoders have been renamed to `dispatch_workgroups` and `dispatch_workgroups_indirect`, respectively, to match the WebGPU spec. By @ErichDonGubler in [#9362](https://github.com/gfx-rs/wgpu/pull/9362). +- `LoadOp::DontCare` can no longer be deserialized, and the `LoadOpDontCare` token no longer implements `Default`. This ensures that `DontCare` can only be used with `unsafe`, as intended. By @kpreid in [#9428](https://github.com/gfx-rs/wgpu/pull/9428). #### Validation diff --git a/Cargo.lock b/Cargo.lock index c3d03ce5e..0855cb2be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4975,6 +4975,7 @@ dependencies = [ "raw-window-handle", "serde", "serde_json", + "static_assertions", "web-sys", ] diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index 998f2568c..7c62d605c 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -59,6 +59,7 @@ serde = { workspace = true, default-features = false, features = [ "alloc", "derive", ], optional = true } +static_assertions.workspace = true [target.'cfg(target_arch = "wasm32")'.dependencies] js-sys = { workspace = true, optional = true, default-features = false } diff --git a/wgpu-types/src/render.rs b/wgpu-types/src/render.rs index 337a34a15..cbf8a7d89 100644 --- a/wgpu-types/src/render.rs +++ b/wgpu-types/src/render.rs @@ -739,7 +739,8 @@ pub enum LoadOp { /// /// - All pixels in the render target must be written to before /// any read or a [`StoreOp::Store`] occurs. - DontCare(#[cfg_attr(feature = "serde", serde(skip))] LoadOpDontCare) = 2, + #[cfg_attr(feature = "serde", serde(skip))] // unsafe to use, so cannot be (de)serialized + DontCare(LoadOpDontCare) = 2, } impl LoadOp { diff --git a/wgpu-types/src/tokens.rs b/wgpu-types/src/tokens.rs index 9102d40b6..89ade7a6f 100644 --- a/wgpu-types/src/tokens.rs +++ b/wgpu-types/src/tokens.rs @@ -45,7 +45,14 @@ impl ExperimentalFeatures { } /// Token of the user agreeing to use [`LoadOp::DontCare`](crate::LoadOp::DontCare). -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +// +// Maintenance note: This type MUST NOT implement Default, Deserialize, or anything else which +// allows safely constructing it. This differs from `ExperimentalFeatures` because it doesn't have +// an "enabled" flag, because its role is to prevent its container (an enum variant) from being +// constructed at all. We could change that if necessary (e.g. perhaps for the wgpu trace/player), +// but if we did, we would have to give `LoadOp::DontCare` a specific fallback behavior when the +// token is disabled/invalid. +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct LoadOpDontCare { // Private to prevent construction outside of the unsafe // enabled() function. @@ -72,3 +79,7 @@ impl LoadOpDontCare { Self { _private: () } } } + +static_assertions::assert_not_impl_any!(LoadOpDontCare: Default); +#[cfg(feature = "serde")] +static_assertions::assert_not_impl_any!(LoadOpDontCare: serde::Deserialize<'static>);