diff --git a/player/src/main.rs b/player/src/main.rs index 3758a577da..1f6bb5fe0b 100644 --- a/player/src/main.rs +++ b/player/src/main.rs @@ -275,12 +275,16 @@ impl GlobalExt for wgc::hub::Global { .map(|(binding, res)| wgc::binding_model::BindGroupEntry { binding: *binding, resource: match *res { - trace::BindingResource::Buffer(ref binding) => { - bm::BindingResource::Buffer(binding.clone()) + trace::BindingResource::Buffer { id, offset, size } => { + bm::BindingResource::Buffer(bm::BufferBinding { + buffer_id: id, + offset, + size, + }) } trace::BindingResource::Sampler(id) => bm::BindingResource::Sampler(id), - trace::BindingResource::TextureView(ref binding) => { - bm::BindingResource::TextureView(binding.clone()) + trace::BindingResource::TextureView(id) => { + bm::BindingResource::TextureView(id) } 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 3620a17150..63d8b69f18 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -70,22 +70,13 @@ pub struct BufferBinding { 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(TextureBinding), - TextureViewArray(&'a [TextureBinding]), + TextureView(TextureViewId), + TextureViewArray(&'a [TextureViewId]), } // Note: Duplicated in wgpu-rs as Binding diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index dec551f12d..9f73aa7e8b 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -525,7 +525,8 @@ pub(crate) fn map_texture_state( W::UNINITIALIZED => return (A::empty(), L::Undefined), W::COPY_SRC => L::TransferSrcOptimal, W::COPY_DST => L::TransferDstOptimal, - W::SAMPLED => L::ShaderReadOnlyOptimal, + W::SAMPLED if is_color => L::ShaderReadOnlyOptimal, + W::SAMPLED => L::DepthStencilReadOnlyOptimal, W::ATTACHMENT_READ | W::ATTACHMENT_WRITE if is_color => L::ColorAttachmentOptimal, W::ATTACHMENT_READ => L::DepthStencilReadOnlyOptimal, W::ATTACHMENT_WRITE => L::DepthStencilAttachmentOptimal, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 50780b8cdd..267eb7f9ec 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1528,16 +1528,15 @@ impl Global { .unwrap(); SmallVec::from([hal::pso::Descriptor::Sampler(&sampler.raw)]) } - binding_model::BindingResource::TextureView(ref tb) => { - let (pub_usage, internal_use, image_layout) = match decl.ty { + binding_model::BindingResource::TextureView(id) => { + let view = used + .views + .use_extend(&*texture_view_guard, id, (), ()) + .unwrap(); + let (pub_usage, internal_use) = match decl.ty { wgt::BindingType::SampledTexture { .. } => ( wgt::TextureUsage::SAMPLED, resource::TextureUse::SAMPLED, - if tb.read_only_depth_stencil { - hal::image::Layout::DepthStencilReadOnlyOptimal - } else { - hal::image::Layout::ShaderReadOnlyOptimal - }, ), wgt::BindingType::StorageTexture { readonly, .. } => ( wgt::TextureUsage::STORAGE, @@ -1546,14 +1545,9 @@ impl Global { } else { resource::TextureUse::STORAGE_STORE }, - hal::image::Layout::General, ), _ => panic!("Mismatched texture binding type in {:?}. Expected a type of SampledTexture, ReadonlyStorageTexture or WriteonlyStorageTexture", decl), }; - let view = used - .views - .use_extend(&*texture_view_guard, tb.view_id, (), ()) - .unwrap(); match view.inner { resource::TextureViewInner::Native { ref raw, @@ -1576,14 +1570,8 @@ impl Global { texture.usage, pub_usage ); - assert!( - !tb.read_only_depth_stencil - || !texture - .full_range - .aspects - .contains(hal::format::Aspects::COLOR) - ); - + let image_layout = + conv::map_texture_state(internal_use, view.range.aspects).1; SmallVec::from([hal::pso::Descriptor::Image(raw, image_layout)]) } resource::TextureViewInner::SwapChain { .. } => { @@ -1620,10 +1608,10 @@ impl Global { }; bindings_array .iter() - .map(|tb| { + .map(|&id| { let view = used .views - .use_extend(&*texture_view_guard, tb.view_id, (), ()) + .use_extend(&*texture_view_guard, id, (), ()) .unwrap(); match view.inner { resource::TextureViewInner::Native { @@ -1647,16 +1635,11 @@ impl Global { texture.usage, 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 - }; + let image_layout = conv::map_texture_state( + internal_use, + view.range.aspects, + ) + .1; hal::pso::Descriptor::Image(raw, image_layout) } resource::TextureViewInner::SwapChain { .. } => panic!( @@ -1713,10 +1696,14 @@ impl Global { .map(|entry| { let res = match entry.resource { binding_model::BindingResource::Buffer(ref binding) => { - trace::BindingResource::Buffer(binding.clone()) + trace::BindingResource::Buffer { + id: binding.buffer_id, + offset: binding.offset, + size: binding.size, + } } - binding_model::BindingResource::TextureView(ref binding) => { - trace::BindingResource::TextureView(binding.clone()) + binding_model::BindingResource::TextureView(id) => { + trace::BindingResource::TextureView(id) } binding_model::BindingResource::Sampler(id) => { trace::BindingResource::Sampler(id) diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 2d14530038..0d2ece6e1e 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -17,10 +17,14 @@ 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(crate::binding_model::BufferBinding), + Buffer { + id: id::BufferId, + offset: wgt::BufferAddress, + size: wgt::BufferSize, + }, Sampler(id::SamplerId), - TextureView(crate::binding_model::TextureBinding), - TextureViewArray(Vec), + TextureView(id::TextureViewId), + TextureViewArray(Vec), } #[derive(Debug)]