diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index d40168c6b3..ed82b7a580 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -834,6 +834,12 @@ impl Device { }, 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 Device { .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 Device { 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 Device { .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, diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index ebd9967362..23aab5c865 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -311,6 +311,8 @@ pub struct TextureView { 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, } diff --git a/wgpu-core/src/swap_chain.rs b/wgpu-core/src/swap_chain.rs index fcbfc7cbf1..262cb33213 100644 --- a/wgpu-core/src/swap_chain.rs +++ b/wgpu-core/src/swap_chain.rs @@ -195,6 +195,7 @@ impl Global { }, samples: 1, framebuffer_attachment: sc.framebuffer_attachment.clone(), + sampled_internal_use: resource::TextureUse::empty(), selector: TextureSelector { layers: 0..1, levels: 0..1,