From 6b859a15d894b9b172a866091c948bc894941234 Mon Sep 17 00:00:00 2001 From: DevJac Date: Wed, 25 Oct 2023 23:36:32 -0600 Subject: [PATCH] Improve error message: "Format Bgra8UnormSrgb can't be multisampled" (#4294) Co-authored-by: Connor Fitzgerald --- wgpu-core/src/device/resource.rs | 32 ++++++++++++++++++++++++++++++-- wgpu-core/src/pipeline.rs | 8 ++++---- wgpu-core/src/resource.rs | 4 ++-- wgpu-types/src/lib.rs | 9 +++++++++ 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index fd85fd6a77..a2160b9ee5 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -662,6 +662,14 @@ impl Device { return Err(CreateTextureError::InvalidSampleCount( desc.sample_count, desc.format, + desc.format + .guaranteed_format_features(self.features) + .flags + .supported_sample_counts(), + adapter + .get_texture_format_features(desc.format) + .flags + .supported_sample_counts(), )); }; } @@ -2815,7 +2823,18 @@ impl Device { .flags .sample_count_supported(desc.multisample.count) { - break Some(pipeline::ColorStateError::FormatNotMultisampled(cs.format)); + break Some(pipeline::ColorStateError::InvalidSampleCount( + desc.multisample.count, + cs.format, + cs.format + .guaranteed_format_features(self.features) + .flags + .supported_sample_counts(), + adapter + .get_texture_format_features(cs.format) + .flags + .supported_sample_counts(), + )); } if let Some(blend_mode) = cs.blend { for factor in [ @@ -2870,8 +2889,17 @@ impl Device { .flags .sample_count_supported(desc.multisample.count) { - break Some(pipeline::DepthStencilStateError::FormatNotMultisampled( + break Some(pipeline::DepthStencilStateError::InvalidSampleCount( + desc.multisample.count, ds.format, + ds.format + .guaranteed_format_features(self.features) + .flags + .supported_sample_counts(), + adapter + .get_texture_format_features(ds.format) + .flags + .supported_sample_counts(), )); } diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index c78a79820d..bfab15b2f5 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -299,8 +299,8 @@ pub enum ColorStateError { FormatNotBlendable(wgt::TextureFormat), #[error("Format {0:?} does not have a color aspect")] FormatNotColor(wgt::TextureFormat), - #[error("Format {0:?} can't be multisampled")] - FormatNotMultisampled(wgt::TextureFormat), + #[error("Sample count {0} is not supported by format {1:?} on this device. The WebGPU spec guarentees {2:?} samples are supported by this format. With the TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES feature your device supports {3:?}.")] + InvalidSampleCount(u32, wgt::TextureFormat, Vec, Vec), #[error("Output format {pipeline} is incompatible with the shader {shader}")] IncompatibleFormat { pipeline: validation::NumericType, @@ -321,8 +321,8 @@ pub enum DepthStencilStateError { FormatNotDepth(wgt::TextureFormat), #[error("Format {0:?} does not have a stencil aspect, but stencil test/write is enabled")] FormatNotStencil(wgt::TextureFormat), - #[error("Format {0:?} can't be multisampled")] - FormatNotMultisampled(wgt::TextureFormat), + #[error("Sample count {0} is not supported by format {1:?} on this device. The WebGPU spec guarentees {2:?} samples are supported by this format. With the TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES feature your device supports {3:?}.")] + InvalidSampleCount(u32, wgt::TextureFormat, Vec, Vec), } #[derive(Clone, Debug, Error)] diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index c0977b80ef..4ff8f539a8 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -579,8 +579,8 @@ pub enum CreateTextureError { InvalidMultisampledStorageBinding, #[error("Format {0:?} does not support multisampling")] InvalidMultisampledFormat(wgt::TextureFormat), - #[error("Sample count {0} is not supported by format {1:?} on this device. It may be supported by your adapter through the TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES feature.")] - InvalidSampleCount(u32, wgt::TextureFormat), + #[error("Sample count {0} is not supported by format {1:?} on this device. The WebGPU spec guarentees {2:?} samples are supported by this format. With the TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES feature your device supports {3:?}.")] + InvalidSampleCount(u32, wgt::TextureFormat, Vec, Vec), #[error("Multisampled textures must have RENDER_ATTACHMENT usage")] MultisampledNotRenderAttachment, #[error("Texture format {0:?} can't be used due to missing features")] diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 82989598ef..9d5b10f37b 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2097,6 +2097,15 @@ impl TextureFormatFeatureFlags { _ => false, } } + + /// A `Vec` of supported sample counts. + pub fn supported_sample_counts(&self) -> Vec { + let all_possible_sample_counts: [u32; 5] = [1, 2, 4, 8, 16]; + all_possible_sample_counts + .into_iter() + .filter(|&sc| self.sample_count_supported(sc)) + .collect() + } } impl_bitflags!(TextureFormatFeatureFlags);