Respect texture view aspect on creation

This commit is contained in:
Dzmitry Malyshau committed 2020-08-10 16:14:20 -04:00
1 parent 12352035f0
commit 1f5622a0b3
4 files changed
+32 -1

No files matched your search

+2
View File
@@ -91,6 +91,8 @@ pub enum CreateBindGroupError {
},
#[error("the given sampler is/is not a comparison sampler, while the layout type indicates otherwise")]
WrongSamplerComparison,
#[error("bound texture views can not have both depth and stencil aspects enabled")]
DepthStencilAspect,
}
#[derive(Clone, Debug, Error)]
+20 -1
View File
@@ -1348,8 +1348,20 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let end_layer = desc
.array_layer_count
.map_or(layer_end, |_| required_layer_count as u16);
let aspects = match desc.aspect {
wgt::TextureAspect::All => texture.full_range.aspects,
wgt::TextureAspect::DepthOnly => hal::format::Aspects::DEPTH,
wgt::TextureAspect::StencilOnly => hal::format::Aspects::STENCIL,
};
if !texture.full_range.aspects.contains(aspects) {
return Err(resource::CreateTextureViewError::InvalidAspect {
requested: aspects,
total: texture.full_range.aspects,
});
}
let range = hal::image::SubresourceRange {
aspects: texture.full_range.aspects,
aspects,
levels: desc.base_mip_level as u8..end_level,
layers: desc.base_array_layer as u16..end_layer,
};
@@ -2061,6 +2073,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
expected: "SampledTexture, ReadonlyStorageTexture or WriteonlyStorageTexture"
})
};
if view
.range
.aspects
.contains(hal::format::Aspects::DEPTH | hal::format::Aspects::STENCIL)
{
return Err(CreateBindGroupError::DepthStencilAspect);
}
match view.inner {
resource::TextureViewInner::Native {
ref raw,
+5
View File
@@ -276,6 +276,11 @@ pub enum CreateTextureViewError {
InvalidMipLevelCount { requested: u32, total: u8 },
#[error("TextureView array layer count + base array layer {requested} must be <= Texture depth/array layer count {total}")]
InvalidArrayLayerCount { requested: u32, total: u16 },
#[error("Aspect {requested:?} is not in the source texture ({total:?})")]
InvalidAspect {
requested: hal::format::Aspects,
total: hal::format::Aspects,
},
}
#[derive(Clone, Debug, Error)]
+5
View File
@@ -1780,6 +1780,11 @@ impl<'a> TextureViewDescriptor<Option<Cow<'a, str>>> {
}
impl<L> TextureViewDescriptor<L> {
pub fn aspect(&mut self, aspect: TextureAspect) -> &mut Self {
self.aspect = aspect;
self
}
pub fn base_mip_level(&mut self, base_mip_level: u32) -> &mut Self {
self.base_mip_level = base_mip_level;
self