From 76c0334e5601151d96a5629bb4ee317f1bb8d8b9 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Mon, 21 Nov 2022 16:28:25 -0800 Subject: [PATCH] Introduce boxes and vectors to reduce Result sizes. The following error variants were large enough to trip Clippy's `result_large_err` lint: - RenderPassCompatibilityError::IncompatibleColorAttachment - CreateShaderModuleError::Validation Large error types are a problem, because they make the `Result` type large, requiring the program to copy around large numbers of bytes even in the success case. Since the failure case is rare, it's usually not a problem to just heap-allocate the contents to keep the `Ok` case small. --- .clippy.toml | 1 - CHANGELOG.md | 1 + wgpu-core/src/device/mod.rs | 13 +++++-------- wgpu-core/src/pipeline.rs | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 .clippy.toml diff --git a/.clippy.toml b/.clippy.toml deleted file mode 100644 index 1fdcf3e5ac..0000000000 --- a/.clippy.toml +++ /dev/null @@ -1 +0,0 @@ -large-error-threshold = 225 # bytes diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a9bc5f0fd..1385d77d74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ Bottom level categories: - Avoid panicking in some interactions with invalid resources by @nical in (#3094)[https://github.com/gfx-rs/wgpu/pull/3094] - Remove `wgpu_types::Features::DEPTH24PLUS_STENCIL8`, making `wgpu::TextureFormat::Depth24PlusStencil8` available on all backends. By @Healthire in (#3151)[https://github.com/gfx-rs/wgpu/pull/3151] - Fix an integer overflow in `queue_write_texture` by @nical in (#3146)[https://github.com/gfx-rs/wgpu/pull/3146] +- Make `RenderPassCompatibilityError` and `CreateShaderModuleError` not so huge. By @jimblandy in (#3226)[https://github.com/gfx-rs/wgpu/pull/3226] #### WebGPU diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 7a7e0be4c9..494fa41b7a 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -80,10 +80,7 @@ pub(crate) struct RenderPassContext { #[derive(Clone, Debug, Error)] pub enum RenderPassCompatibilityError { #[error("Incompatible color attachment: the renderpass expected {0:?} but was given {1:?}")] - IncompatibleColorAttachment( - ArrayVec, { hal::MAX_COLOR_ATTACHMENTS }>, - ArrayVec, { hal::MAX_COLOR_ATTACHMENTS }>, - ), + IncompatibleColorAttachment(Vec>, Vec>), #[error( "Incompatible depth-stencil attachment: the renderpass expected {0:?} but was given {1:?}" )] @@ -102,8 +99,8 @@ impl RenderPassContext { ) -> Result<(), RenderPassCompatibilityError> { if self.attachments.colors != other.attachments.colors { return Err(RenderPassCompatibilityError::IncompatibleColorAttachment( - self.attachments.colors.clone(), - other.attachments.colors.clone(), + self.attachments.colors.iter().cloned().collect(), + other.attachments.colors.iter().cloned().collect(), )); } if self.attachments.depth_stencil != other.attachments.depth_stencil { @@ -1245,7 +1242,7 @@ impl Device { pipeline::CreateShaderModuleError::Parsing(pipeline::ShaderError { source: code.to_string(), label: desc.label.as_ref().map(|l| l.to_string()), - inner, + inner: Box::new(inner), }) })?; (Cow::Owned(module), code.into_owned()) @@ -1308,7 +1305,7 @@ impl Device { pipeline::CreateShaderModuleError::Validation(pipeline::ShaderError { source, label: desc.label.as_ref().map(|l| l.to_string()), - inner, + inner: Box::new(inner), }) })?; let interface = diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 667b8b96ed..5c091e1d96 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -66,7 +66,7 @@ impl Resource for ShaderModule { pub struct ShaderError { pub source: String, pub label: Option, - pub inner: E, + pub inner: Box, } #[cfg(feature = "wgsl")] impl fmt::Display for ShaderError {