From dfe686bbc63a7e9e54feff0cddfff342e7367a26 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 23 Feb 2021 23:59:17 +0100 Subject: [PATCH] Added TextureFormatFeatures::filterable Can overwrite TextureSampleType::Float.filterable --- wgpu-core/src/device/mod.rs | 27 ++++++++++++++++----------- wgpu-core/src/instance.rs | 4 ++++ wgpu-core/src/swap_chain.rs | 1 + wgpu-types/src/lib.rs | 4 ++++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index e5b6c8de44..2fc5457cd2 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1440,21 +1440,26 @@ impl Device { view_samples: view.samples as u32, }); } - match (sample_type, format_info.sample_type) { - (Tst::Uint, Tst::Uint) | - (Tst::Sint, Tst::Sint) | - (Tst::Depth, Tst::Depth) | - // if we expect non-fiterable, accept anything float - (Tst::Float { filterable: false }, Tst::Float { .. }) | - // if we expect fiterable, require it - (Tst::Float { filterable: true }, Tst::Float { filterable: true }) | + match (sample_type, format_info.sample_type, view.format_features.filterable ) { + (Tst::Uint, Tst::Uint, ..) | + (Tst::Sint, Tst::Sint, ..) | + (Tst::Depth, Tst::Depth, ..) | + // if we expect non-filterable, accept anything float + (Tst::Float { filterable: false }, Tst::Float { .. }, ..) | + // if we expect filterable, require it + (Tst::Float { filterable: true }, Tst::Float { filterable: true }, ..) | + // if we expect filterable, also accept Float that is defined as unfilterable if filterable feature is explicitly enabled + // (only hit if wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES is enabled) + (Tst::Float { filterable: true }, Tst::Float { .. }, true) | // if we expect float, also accept depth - (Tst::Float { .. }, Tst::Depth) => {} - _ => return Err(Error::InvalidTextureSampleType { + (Tst::Float { .. }, Tst::Depth, ..) => {} + _ => { + return Err(Error::InvalidTextureSampleType { binding, layout_sample_type: sample_type, view_format: view.format, - }), + }) + }, } if view_dimension != view.dimension { return Err(Error::InvalidTextureDimension { diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index ebd7b23f5f..e772db9002 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -329,9 +329,13 @@ impl Adapter { flags |= wgt::TextureFormatFeatureFlags::STORAGE_READ_WRITE; } + let filterable = + texture_format_properties.contains(hal::format::ImageFeature::SAMPLED_LINEAR); + wgt::TextureFormatFeatures { allowed_usages, flags, + filterable, } } diff --git a/wgpu-core/src/swap_chain.rs b/wgpu-core/src/swap_chain.rs index f5bb3d3173..e8dfe31e26 100644 --- a/wgpu-core/src/swap_chain.rs +++ b/wgpu-core/src/swap_chain.rs @@ -187,6 +187,7 @@ impl Global { format_features: wgt::TextureFormatFeatures { allowed_usages: wgt::TextureUsage::RENDER_ATTACHMENT, flags: wgt::TextureFormatFeatureFlags::empty(), + filterable: false, }, dimension: wgt::TextureViewDimension::D2, extent: wgt::Extent3d { diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 84061706eb..447f702e3e 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -937,6 +937,9 @@ pub struct TextureFormatFeatures { pub allowed_usages: TextureUsage, /// Additional property flags for the format. pub flags: TextureFormatFeatureFlags, + /// If `filterable` is false, the texture can't be sampled with a filtering sampler. + /// This may overwrite TextureSampleType::Float.filterable + pub filterable: bool, } /// Information about a texture format. @@ -1492,6 +1495,7 @@ impl TextureFormat { guaranteed_format_features: TextureFormatFeatures { allowed_usages, flags: TextureFormatFeatureFlags::empty(), + filterable: sample_type == TextureSampleType::Float { filterable: true }, }, } }