mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #723
723: Always use DepthStencilReadOnlyOptimal for sampled depth r=kvark a=kvark **Connections** This is a follow-up to #712 that reverts the API changes but also fixes our internal logic to work better. **Description** It solves the problem of image layouts by always using a RODS layout on depth images, when sampled. **Testing** Tested on https://github.com/gfx-rs/wgpu-rs/pull/375 Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
This commit is contained in:
@@ -275,12 +275,16 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
|
||||
.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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1528,16 +1528,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
} 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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.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)
|
||||
|
||||
@@ -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<crate::binding_model::TextureBinding>),
|
||||
TextureView(id::TextureViewId),
|
||||
TextureViewArray(Vec<id::TextureViewId>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
Reference in New Issue
Block a user