diff --git a/player/src/main.rs b/player/src/main.rs index 4a7ba5d2b5..3758a577da 100644 --- a/player/src/main.rs +++ b/player/src/main.rs @@ -275,19 +275,15 @@ impl GlobalExt for wgc::hub::Global { .map(|(binding, res)| wgc::binding_model::BindGroupEntry { binding: *binding, resource: match *res { - trace::BindingResource::Buffer { id, offset, size } => { - bm::BindingResource::Buffer(bm::BufferBinding { - buffer: id, - offset, - size, - }) + trace::BindingResource::Buffer(ref binding) => { + bm::BindingResource::Buffer(binding.clone()) } trace::BindingResource::Sampler(id) => bm::BindingResource::Sampler(id), - trace::BindingResource::TextureView(id) => { - bm::BindingResource::TextureView(id) + trace::BindingResource::TextureView(ref binding) => { + bm::BindingResource::TextureView(binding.clone()) } - trace::BindingResource::TextureViewArray(ref id_array) => { - bm::BindingResource::TextureViewArray(id_array) + trace::BindingResource::TextureViewArray(ref binding_array) => { + bm::BindingResource::TextureViewArray(binding_array) } }, }) diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 74ed59bf05..6a7f5c6a04 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -60,22 +60,31 @@ pub struct PipelineLayout { } #[repr(C)] -#[derive(Debug)] +#[derive(Clone, Debug, Hash, PartialEq)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] pub struct BufferBinding { - pub buffer: BufferId, + pub buffer_id: BufferId, pub offset: wgt::BufferAddress, pub size: wgt::BufferSize, } +#[repr(C)] +#[derive(Clone, Debug, Hash, PartialEq)] +#[cfg_attr(feature = "trace", derive(Serialize))] +#[cfg_attr(feature = "replay", derive(Deserialize))] +pub struct TextureBinding { + pub view_id: TextureViewId, + pub read_only_depth_stencil: bool, +} + // Note: Duplicated in wgpu-rs as BindingResource #[derive(Debug)] pub enum BindingResource<'a> { Buffer(BufferBinding), Sampler(SamplerId), - TextureView(TextureViewId), - TextureViewArray(&'a [TextureViewId]), + TextureView(TextureBinding), + TextureViewArray(&'a [TextureBinding]), } // Note: Duplicated in wgpu-rs as Binding diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 2e0eff92cc..7544a82d3e 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -27,7 +27,7 @@ use peek_poke::{Peek, PeekPoke, Poke}; use wgt::{ BufferAddress, BufferSize, BufferUsage, Color, DynamicOffset, IndexFormat, InputStepMode, LoadOp, RenderPassColorAttachmentDescriptorBase, - RenderPassDepthStencilAttachmentDescriptorBase, TextureUsage, BIND_BUFFER_ALIGNMENT, + RenderPassDepthStencilAttachmentDescriptorBase, StoreOp, TextureUsage, BIND_BUFFER_ALIGNMENT, }; use std::{borrow::Borrow, collections::hash_map::Entry, fmt, iter, mem, ops::Range, slice}; @@ -41,26 +41,22 @@ fn is_depth_stencil_read_only( desc: &RenderPassDepthStencilAttachmentDescriptor, aspects: hal::format::Aspects, ) -> bool { - if aspects.contains(hal::format::Aspects::DEPTH) { - if !desc.depth_read_only { - return false; - } - assert_eq!( - (desc.depth_load_op, desc.depth_store_op), - (wgt::LoadOp::Load, wgt::StoreOp::Store), - "Unable to clear read-only depth" - ); + if aspects.contains(hal::format::Aspects::DEPTH) && !desc.depth_read_only { + return false; } - if aspects.contains(hal::format::Aspects::STENCIL) { - if !desc.stencil_read_only { - return false; - } - assert_eq!( - (desc.stencil_load_op, desc.stencil_store_op), - (wgt::LoadOp::Load, wgt::StoreOp::Store), - "Unable to clear read-only stencil" - ); + assert_eq!( + (desc.depth_load_op, desc.depth_store_op), + (LoadOp::Load, StoreOp::Store), + "Unable to clear non-present/read-only depth" + ); + if aspects.contains(hal::format::Aspects::STENCIL) && !desc.stencil_read_only { + return false; } + assert_eq!( + (desc.stencil_load_op, desc.stencil_store_op), + (LoadOp::Load, StoreOp::Store), + "Unable to clear non-present/read-only stencil" + ); true } diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 09d24dad38..4e14561717 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1471,7 +1471,7 @@ impl Global { let buffer = used .buffers - .use_extend(&*buffer_guard, bb.buffer, (), internal_use) + .use_extend(&*buffer_guard, bb.buffer_id, (), internal_use) .unwrap(); assert!( buffer.usage.contains(pub_usage), @@ -1509,12 +1509,16 @@ impl Global { .unwrap(); SmallVec::from([hal::pso::Descriptor::Sampler(&sampler.raw)]) } - binding_model::BindingResource::TextureView(id) => { + binding_model::BindingResource::TextureView(ref tb) => { let (pub_usage, internal_use, image_layout) = match decl.ty { wgt::BindingType::SampledTexture { .. } => ( wgt::TextureUsage::SAMPLED, resource::TextureUse::SAMPLED, - hal::image::Layout::ShaderReadOnlyOptimal, + if tb.read_only_depth_stencil { + hal::image::Layout::DepthStencilReadOnlyOptimal + } else { + hal::image::Layout::ShaderReadOnlyOptimal + }, ), wgt::BindingType::StorageTexture { readonly, .. } => ( wgt::TextureUsage::STORAGE, @@ -1529,7 +1533,7 @@ impl Global { }; let view = used .views - .use_extend(&*texture_view_guard, id, (), ()) + .use_extend(&*texture_view_guard, tb.view_id, (), ()) .unwrap(); match view.inner { resource::TextureViewInner::Native { @@ -1553,6 +1557,13 @@ impl Global { texture.usage, pub_usage ); + assert!( + !tb.read_only_depth_stencil + || !texture + .full_range + .aspects + .contains(hal::format::Aspects::COLOR) + ); SmallVec::from([hal::pso::Descriptor::Image(raw, image_layout)]) } @@ -1578,20 +1589,19 @@ impl Global { ); } - let (pub_usage, internal_use, image_layout) = match decl.ty { + let (pub_usage, internal_use) = match decl.ty { wgt::BindingType::SampledTexture { .. } => ( wgt::TextureUsage::SAMPLED, resource::TextureUse::SAMPLED, - hal::image::Layout::ShaderReadOnlyOptimal, ), _ => panic!("Mismatched texture binding type in {:?}. Expected a type of SampledTextureArray", decl), }; bindings_array .iter() - .map(|id| { + .map(|tb| { let view = used .views - .use_extend(&*texture_view_guard, *id, (), ()) + .use_extend(&*texture_view_guard, tb.view_id, (), ()) .unwrap(); match view.inner { resource::TextureViewInner::Native { @@ -1616,6 +1626,15 @@ impl Global { pub_usage ); + let image_layout = if tb.read_only_depth_stencil { + assert!(!texture + .full_range + .aspects + .contains(hal::format::Aspects::COLOR)); + hal::image::Layout::DepthStencilReadOnlyOptimal + } else { + hal::image::Layout::ShaderReadOnlyOptimal + }; hal::pso::Descriptor::Image(raw, image_layout) } resource::TextureViewInner::SwapChain { .. } => panic!( @@ -1671,21 +1690,17 @@ impl Global { .iter() .map(|entry| { let res = match entry.resource { - binding_model::BindingResource::Buffer(ref b) => { - trace::BindingResource::Buffer { - id: b.buffer, - offset: b.offset, - size: b.size, - } + binding_model::BindingResource::Buffer(ref binding) => { + trace::BindingResource::Buffer(binding.clone()) } - binding_model::BindingResource::TextureView(id) => { - trace::BindingResource::TextureView(id) + binding_model::BindingResource::TextureView(ref binding) => { + trace::BindingResource::TextureView(binding.clone()) } binding_model::BindingResource::Sampler(id) => { trace::BindingResource::Sampler(id) } - binding_model::BindingResource::TextureViewArray(ref id_array) => { - trace::BindingResource::TextureViewArray(id_array.to_vec()) + binding_model::BindingResource::TextureViewArray(ref binding_array) => { + trace::BindingResource::TextureViewArray(binding_array.to_vec()) } }; (entry.binding, res) diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 0d2ece6e1e..2d14530038 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -17,14 +17,10 @@ pub const FILE_NAME: &str = "trace.ron"; #[cfg_attr(feature = "trace", derive(serde::Serialize))] #[cfg_attr(feature = "replay", derive(serde::Deserialize))] pub enum BindingResource { - Buffer { - id: id::BufferId, - offset: wgt::BufferAddress, - size: wgt::BufferSize, - }, + Buffer(crate::binding_model::BufferBinding), Sampler(id::SamplerId), - TextureView(id::TextureViewId), - TextureViewArray(Vec), + TextureView(crate::binding_model::TextureBinding), + TextureViewArray(Vec), } #[derive(Debug)] diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 1b345f64ea..2c7f710ac1 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -23,7 +23,7 @@ pub const BIND_BUFFER_ALIGNMENT: BufferAddress = 256; pub const COPY_BUFFER_ALIGNMENT: BufferAddress = 4; #[repr(transparent)] -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, Hash, PartialEq)] #[cfg_attr(feature = "peek-poke", derive(PeekPoke))] #[cfg_attr( feature = "trace",