Skip to content

Commit

Permalink
Improve error message: "Format Bgra8UnormSrgb can't be multisampled" (#…
Browse files Browse the repository at this point in the history
…4294)

Co-authored-by: Connor Fitzgerald <[email protected]>
  • Loading branch information
DevJac and cwfitzgerald authored Oct 26, 2023
1 parent e54289b commit 6b859a1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
32 changes: 30 additions & 2 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,14 @@ impl<A: HalApi> Device<A> {
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(),
));
};
}
Expand Down Expand Up @@ -2815,7 +2823,18 @@ impl<A: HalApi> Device<A> {
.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 [
Expand Down Expand Up @@ -2870,8 +2889,17 @@ impl<A: HalApi> Device<A> {
.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(),
));
}

Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>, Vec<u32>),
#[error("Output format {pipeline} is incompatible with the shader {shader}")]
IncompatibleFormat {
pipeline: validation::NumericType,
Expand All @@ -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<u32>, Vec<u32>),
}

#[derive(Clone, Debug, Error)]
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>, Vec<u32>),
#[error("Multisampled textures must have RENDER_ATTACHMENT usage")]
MultisampledNotRenderAttachment,
#[error("Texture format {0:?} can't be used due to missing features")]
Expand Down
9 changes: 9 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,15 @@ impl TextureFormatFeatureFlags {
_ => false,
}
}

/// A `Vec` of supported sample counts.
pub fn supported_sample_counts(&self) -> Vec<u32> {
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);
Expand Down

0 comments on commit 6b859a1

Please sign in to comment.