mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 23:41:01 +01:00
Validate filtering samplers at BG creation
This commit is contained in:
1 parent
6d7ef8b8fd
commit
92886b4995
3 files changed
+34
-4
No files matched your search
@@ -43,6 +43,8 @@ pub enum CreateBindGroupLayoutError {
|
||||
TooManyBindings(BindingTypeMaxCountError),
|
||||
}
|
||||
|
||||
//TODO: refactor this to move out `enum BindingError`.
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
pub enum CreateBindGroupError {
|
||||
#[error(transparent)]
|
||||
@@ -130,8 +132,18 @@ pub enum CreateBindGroupError {
|
||||
layout_format: wgt::TextureFormat,
|
||||
view_format: wgt::TextureFormat,
|
||||
},
|
||||
#[error("the given sampler is/is not a comparison sampler, while the layout type indicates otherwise")]
|
||||
WrongSamplerComparison,
|
||||
#[error("sampler binding {binding} expects comparison = {layout_cmp}, but given a sampler with comparison = {sampler_cmp}")]
|
||||
WrongSamplerComparison {
|
||||
binding: u32,
|
||||
layout_cmp: bool,
|
||||
sampler_cmp: bool,
|
||||
},
|
||||
#[error("sampler binding {binding} expects filtering = {layout_flt}, but given a sampler with filtering = {sampler_flt}")]
|
||||
WrongSamplerFiltering {
|
||||
binding: u32,
|
||||
layout_flt: bool,
|
||||
sampler_flt: bool,
|
||||
},
|
||||
#[error("bound texture views can not have both depth and stencil aspects enabled")]
|
||||
DepthStencilAspect,
|
||||
#[error("the adapter does not support simultaneous read + write storage texture access for the format {0:?}")]
|
||||
|
||||
@@ -940,6 +940,9 @@ impl<B: GfxBackend> Device<B> {
|
||||
Some(wgt::SamplerBorderColor::OpaqueWhite) => hal::image::BorderColor::OpaqueWhite,
|
||||
};
|
||||
|
||||
let filtering = [desc.min_filter, desc.mag_filter, desc.mipmap_filter]
|
||||
.contains(&wgt::FilterMode::Linear);
|
||||
|
||||
let info = hal::image::SamplerDesc {
|
||||
min_filter: conv::map_filter(desc.min_filter),
|
||||
mag_filter: conv::map_filter(desc.mag_filter),
|
||||
@@ -975,6 +978,7 @@ impl<B: GfxBackend> Device<B> {
|
||||
},
|
||||
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
|
||||
comparison: info.comparison.is_some(),
|
||||
filtering,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1412,7 +1416,7 @@ impl<B: GfxBackend> Device<B> {
|
||||
Br::Sampler(id) => {
|
||||
match decl.ty {
|
||||
wgt::BindingType::Sampler {
|
||||
filtering: _, //TODO!!!
|
||||
filtering,
|
||||
comparison,
|
||||
} => {
|
||||
let sampler = used
|
||||
@@ -1422,7 +1426,19 @@ impl<B: GfxBackend> Device<B> {
|
||||
|
||||
// Check the actual sampler to also (not) be a comparison sampler
|
||||
if sampler.comparison != comparison {
|
||||
return Err(Error::WrongSamplerComparison);
|
||||
return Err(Error::WrongSamplerComparison {
|
||||
binding,
|
||||
layout_cmp: comparison,
|
||||
sampler_cmp: sampler.comparison,
|
||||
});
|
||||
}
|
||||
// Check the actual sampler to be non-filtering, if required
|
||||
if filtering < sampler.filtering {
|
||||
return Err(Error::WrongSamplerFiltering {
|
||||
binding,
|
||||
layout_flt: filtering,
|
||||
sampler_flt: sampler.filtering,
|
||||
});
|
||||
}
|
||||
|
||||
SmallVec::from([hal::pso::Descriptor::Sampler(&sampler.raw)])
|
||||
|
||||
@@ -446,6 +446,8 @@ pub struct Sampler<B: hal::Backend> {
|
||||
pub(crate) life_guard: LifeGuard,
|
||||
/// `true` if this is a comparison sampler
|
||||
pub(crate) comparison: bool,
|
||||
/// `true` if this is a filtering sampler
|
||||
pub(crate) filtering: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
|
||||
Reference in new issue
Block a user