Handle read-only storage + sampled combination

This commit is contained in:
Dzmitry Malyshau 2021-01-19 09:54:41 -05:00
parent 7f8c776a85
commit 618bd9e53a
3 changed files with 22 additions and 13 deletions

View File

@ -834,6 +834,12 @@ impl<B: GfxBackend> Device<B> {
},
samples: texture.kind.num_samples(),
framebuffer_attachment: texture.framebuffer_attachment.clone(),
// once a storage - forever a storage
sampled_internal_use: if texture.usage.contains(wgt::TextureUsage::STORAGE) {
resource::TextureUse::SAMPLED | resource::TextureUse::STORAGE_LOAD
} else {
resource::TextureUse::SAMPLED
},
selector,
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
})
@ -1360,7 +1366,7 @@ impl<B: GfxBackend> Device<B> {
.map_err(|_| Error::InvalidTextureView(id))?;
let (pub_usage, internal_use) = match decl.ty {
wgt::BindingType::Texture { .. } => {
(wgt::TextureUsage::SAMPLED, resource::TextureUse::SAMPLED)
(wgt::TextureUsage::SAMPLED, view.sampled_internal_use)
}
wgt::BindingType::StorageTexture { access, .. } => {
let internal_use = match access {
@ -1447,18 +1453,6 @@ impl<B: GfxBackend> Device<B> {
return Err(Error::SingleBindingExpected);
}
let (pub_usage, internal_use) = match decl.ty {
wgt::BindingType::Texture { .. } => {
(wgt::TextureUsage::SAMPLED, resource::TextureUse::SAMPLED)
}
_ => {
return Err(Error::WrongBindingType {
binding,
actual: decl.ty.clone(),
expected: "SampledTextureArray",
})
}
};
bindings_array
.iter()
.map(|&id| {
@ -1466,6 +1460,18 @@ impl<B: GfxBackend> Device<B> {
.views
.use_extend(&*texture_view_guard, id, (), ())
.map_err(|_| Error::InvalidTextureView(id))?;
let (pub_usage, internal_use) = match decl.ty {
wgt::BindingType::Texture { .. } => {
(wgt::TextureUsage::SAMPLED, view.sampled_internal_use)
}
_ => {
return Err(Error::WrongBindingType {
binding,
actual: decl.ty.clone(),
expected: "SampledTextureArray",
})
}
};
match view.inner {
resource::TextureViewInner::Native {
ref raw,

View File

@ -311,6 +311,8 @@ pub struct TextureView<B: hal::Backend> {
pub(crate) extent: wgt::Extent3d,
pub(crate) samples: hal::image::NumSamples,
pub(crate) framebuffer_attachment: hal::image::FramebufferAttachment,
/// Internal use of this texture view when used as `BindingType::Texture`.
pub(crate) sampled_internal_use: TextureUse,
pub(crate) selector: TextureSelector,
pub(crate) life_guard: LifeGuard,
}

View File

@ -195,6 +195,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
},
samples: 1,
framebuffer_attachment: sc.framebuffer_attachment.clone(),
sampled_internal_use: resource::TextureUse::empty(),
selector: TextureSelector {
layers: 0..1,
levels: 0..1,