mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-26 00:33:51 +00:00
Merge #716
716: Add RODS texture binding property r=cwfitzgerald a=kvark This is a follow-up to #712, which I screwed up right before it got in. Fortunately, we still need the code that went in, we just need a little bit more :) Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
commit
ad34c37127
@ -275,19 +275,15 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
|
||||
.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)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
@ -60,22 +60,31 @@ pub struct PipelineLayout<B: hal::Backend> {
|
||||
}
|
||||
|
||||
#[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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -1471,7 +1471,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
);
|
||||
}
|
||||
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
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<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.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)
|
||||
|
@ -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<id::TextureViewId>),
|
||||
TextureView(crate::binding_model::TextureBinding),
|
||||
TextureViewArray(Vec<crate::binding_model::TextureBinding>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user