From ad423b9a2a8cb4ea1da15e7abae344b9d96b9c00 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 8 Jan 2023 00:13:10 -0500 Subject: [PATCH 1/2] Allow non-filtering integer texture sampling --- wgpu-core/src/validation.rs | 41 ++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index d190cbbfd9..dcc179fb8f 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -212,10 +212,10 @@ pub enum BindingError { #[derive(Clone, Debug, Error)] pub enum FilteringError { - #[error("integer textures can't be sampled")] + #[error("integer textures can't be sampled with a filtering sampler")] Integer, - #[error("non-filterable float texture")] - NonFilterable, + #[error("non-filterable float textures can't be sampled with a filtering sampler")] + Float, } #[derive(Clone, Debug, Error)] @@ -1049,27 +1049,22 @@ impl Interface { assert!(texture_layout.visibility.contains(stage_bit)); assert!(sampler_layout.visibility.contains(stage_bit)); - let error = match texture_layout.ty { - wgt::BindingType::Texture { - sample_type: wgt::TextureSampleType::Float { filterable }, - .. - } => match sampler_layout.ty { - wgt::BindingType::Sampler(wgt::SamplerBindingType::Filtering) - if !filterable => - { - Some(FilteringError::NonFilterable) - } - _ => None, - }, - wgt::BindingType::Texture { - sample_type: wgt::TextureSampleType::Sint, - .. + let sampler_filtering = matches!( + sampler_layout.ty, + wgt::BindingType::Sampler(wgt::SamplerBindingType::Filtering) + ); + let texture_sample_type = match texture_layout.ty { + BindingType::Texture { sample_type, .. } => sample_type, + _ => unreachable!(), + }; + + let error = match (sampler_filtering, texture_sample_type) { + (true, wgt::TextureSampleType::Float { filterable: false }) => { + Some(FilteringError::Float) } - | wgt::BindingType::Texture { - sample_type: wgt::TextureSampleType::Uint, - .. - } => Some(FilteringError::Integer), - _ => None, // unreachable, really + (true, wgt::TextureSampleType::Sint) => Some(FilteringError::Integer), + (true, wgt::TextureSampleType::Uint) => Some(FilteringError::Integer), + _ => None, }; if let Some(error) = error { From 5088134918f9c5bc9cceb44dd7e1ab6dd08325b4 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 8 Jan 2023 16:55:59 -0500 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2387b1cc4..d222b4d984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -173,6 +173,7 @@ Additionally `Surface::get_default_config` now returns an Option and returns Non - Check for invalid bitflag bits in wgpu-core and allow them to be captured/replayed by @nical in (#3229)[https://github.com/gfx-rs/wgpu/pull/3229] - Evaluate `gfx_select!`'s `#[cfg]` conditions at the right time. By @jimblandy in [#3253](https://github.com/gfx-rs/wgpu/pull/3253) - Improve error messages when binding bind group with dynamic offsets. By @cwfitzgerald in [#3294](https://github.com/gfx-rs/wgpu/pull/3294) +- Allow non-filtering sampling of integer textures. By @JMS55 in [#3362](https://github.com/gfx-rs/wgpu/pull/3362). #### Metal - Fix texture view creation with full-resource views when using an explicit `mip_level_count` or `array_layer_count`. By @cwfitzgerald in [#3323](https://github.com/gfx-rs/wgpu/pull/3323)