render/compute pass descriptors work now with dyn types

This commit is contained in:
Andreas Reich 2024-07-17 09:51:53 +02:00
parent bdf6710d58
commit a47a0cb3d9
8 changed files with 53 additions and 53 deletions

View File

@ -1041,7 +1041,7 @@ impl<'d, A: HalApi> RenderPassInfo<'d, A> {
}
let mut color_attachments_hal =
ArrayVec::<Option<hal::ColorAttachment<A>>, { hal::MAX_COLOR_ATTACHMENTS }>::new();
ArrayVec::<Option<hal::ColorAttachment<_>>, { hal::MAX_COLOR_ATTACHMENTS }>::new();
for (index, attachment) in color_attachments.iter().enumerate() {
let at = if let Some(attachment) = attachment.as_ref() {
attachment

View File

@ -661,7 +661,10 @@ impl crate::CommandEncoder for super::CommandEncoder {
// render
unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor<super::Api>) {
unsafe fn begin_render_pass(
&mut self,
desc: &crate::RenderPassDescriptor<super::QuerySet, super::TextureView>,
) {
unsafe { self.begin_pass(super::PassKind::Render, desc.label) };
// Start timestamp if any (before all other commands but after debug marker)
@ -1130,7 +1133,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
unsafe fn begin_compute_pass<'a>(
&mut self,
desc: &crate::ComputePassDescriptor<'a, super::Api>,
desc: &crate::ComputePassDescriptor<'a, super::QuerySet>,
) {
unsafe { self.begin_pass(super::PassKind::Compute, desc.label) };

View File

@ -370,7 +370,8 @@ impl crate::CommandEncoder for Encoder {
// render
unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor<Api>) {}
unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor<Resource, Resource>) {
}
unsafe fn end_render_pass(&mut self) {}
unsafe fn set_bind_group(
@ -465,7 +466,7 @@ impl crate::CommandEncoder for Encoder {
// compute
unsafe fn begin_compute_pass(&mut self, desc: &crate::ComputePassDescriptor<Api>) {}
unsafe fn begin_compute_pass(&mut self, desc: &crate::ComputePassDescriptor<Resource>) {}
unsafe fn end_compute_pass(&mut self) {}
unsafe fn set_compute_pipeline(&mut self, pipeline: &Resource) {}

View File

@ -494,7 +494,10 @@ impl crate::CommandEncoder for super::CommandEncoder {
// render
unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor<super::Api>) {
unsafe fn begin_render_pass(
&mut self,
desc: &crate::RenderPassDescriptor<super::QuerySet, super::TextureView>,
) {
debug_assert!(self.state.end_of_pass_timestamp.is_none());
if let Some(ref t) = desc.timestamp_writes {
if let Some(index) = t.beginning_of_pass_write_index {
@ -1137,7 +1140,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
// compute
unsafe fn begin_compute_pass(&mut self, desc: &crate::ComputePassDescriptor<super::Api>) {
unsafe fn begin_compute_pass(&mut self, desc: &crate::ComputePassDescriptor<super::QuerySet>) {
debug_assert!(self.state.end_of_pass_timestamp.is_none());
if let Some(ref t) = desc.timestamp_writes {
if let Some(index) = t.beginning_of_pass_write_index {

View File

@ -1231,7 +1231,10 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
// render passes
// Begins a render pass, clears all active bindings.
unsafe fn begin_render_pass(&mut self, desc: &RenderPassDescriptor<Self::A>);
unsafe fn begin_render_pass(
&mut self,
desc: &RenderPassDescriptor<<Self::A as Api>::QuerySet, <Self::A as Api>::TextureView>,
);
unsafe fn end_render_pass(&mut self);
unsafe fn set_render_pipeline(&mut self, pipeline: &<Self::A as Api>::RenderPipeline);
@ -1298,7 +1301,10 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
// compute passes
// Begins a compute pass, clears all active bindings.
unsafe fn begin_compute_pass(&mut self, desc: &ComputePassDescriptor<Self::A>);
unsafe fn begin_compute_pass(
&mut self,
desc: &ComputePassDescriptor<<Self::A as Api>::QuerySet>,
);
unsafe fn end_compute_pass(&mut self);
unsafe fn set_compute_pipeline(&mut self, pipeline: &<Self::A as Api>::ComputePipeline);
@ -2028,47 +2034,25 @@ pub struct BufferTextureCopy {
pub size: CopyExtent,
}
#[derive(Debug)]
pub struct Attachment<'a, A: Api> {
pub view: &'a A::TextureView,
#[derive(Clone, Debug)]
pub struct Attachment<'a, T: DynTextureView + ?Sized> {
pub view: &'a T,
/// Contains either a single mutating usage as a target,
/// or a valid combination of read-only usages.
pub usage: TextureUses,
}
// Rust gets confused about the impl requirements for `A`
impl<A: Api> Clone for Attachment<'_, A> {
fn clone(&self) -> Self {
Self {
view: self.view,
usage: self.usage,
}
}
}
#[derive(Debug)]
pub struct ColorAttachment<'a, A: Api> {
pub target: Attachment<'a, A>,
pub resolve_target: Option<Attachment<'a, A>>,
#[derive(Clone, Debug)]
pub struct ColorAttachment<'a, T: DynTextureView + ?Sized> {
pub target: Attachment<'a, T>,
pub resolve_target: Option<Attachment<'a, T>>,
pub ops: AttachmentOps,
pub clear_value: wgt::Color,
}
// Rust gets confused about the impl requirements for `A`
impl<A: Api> Clone for ColorAttachment<'_, A> {
fn clone(&self) -> Self {
Self {
target: self.target.clone(),
resolve_target: self.resolve_target.clone(),
ops: self.ops,
clear_value: self.clear_value,
}
}
}
#[derive(Clone, Debug)]
pub struct DepthStencilAttachment<'a, A: Api> {
pub target: Attachment<'a, A>,
pub struct DepthStencilAttachment<'a, T: DynTextureView + ?Sized> {
pub target: Attachment<'a, T>,
pub depth_ops: AttachmentOps,
pub stencil_ops: AttachmentOps,
pub clear_value: (f32, u32),
@ -2082,21 +2066,21 @@ pub struct PassTimestampWrites<'a, Q: DynQuerySet + ?Sized> {
}
#[derive(Clone, Debug)]
pub struct RenderPassDescriptor<'a, A: Api> {
pub struct RenderPassDescriptor<'a, Q: DynQuerySet + ?Sized, T: DynTextureView + ?Sized> {
pub label: Label<'a>,
pub extent: wgt::Extent3d,
pub sample_count: u32,
pub color_attachments: &'a [Option<ColorAttachment<'a, A>>],
pub depth_stencil_attachment: Option<DepthStencilAttachment<'a, A>>,
pub color_attachments: &'a [Option<ColorAttachment<'a, T>>],
pub depth_stencil_attachment: Option<DepthStencilAttachment<'a, T>>,
pub multiview: Option<NonZeroU32>,
pub timestamp_writes: Option<PassTimestampWrites<'a, A::QuerySet>>,
pub occlusion_query_set: Option<&'a A::QuerySet>,
pub timestamp_writes: Option<PassTimestampWrites<'a, Q>>,
pub occlusion_query_set: Option<&'a Q>,
}
#[derive(Clone, Debug)]
pub struct ComputePassDescriptor<'a, A: Api> {
pub struct ComputePassDescriptor<'a, Q: DynQuerySet + ?Sized> {
pub label: Label<'a>,
pub timestamp_writes: Option<PassTimestampWrites<'a, A::QuerySet>>,
pub timestamp_writes: Option<PassTimestampWrites<'a, Q>>,
}
/// Stores the text of any validation errors that have occurred since

View File

@ -501,7 +501,10 @@ impl crate::CommandEncoder for super::CommandEncoder {
// render
unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor<super::Api>) {
unsafe fn begin_render_pass(
&mut self,
desc: &crate::RenderPassDescriptor<super::QuerySet, super::TextureView>,
) {
self.begin_pass();
self.state.index = None;
@ -1128,7 +1131,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
// compute
unsafe fn begin_compute_pass(&mut self, desc: &crate::ComputePassDescriptor<super::Api>) {
unsafe fn begin_compute_pass(&mut self, desc: &crate::ComputePassDescriptor<super::QuerySet>) {
self.begin_pass();
debug_assert!(self.state.blit.is_none());

View File

@ -644,7 +644,10 @@ impl crate::CommandEncoder for super::CommandEncoder {
}
// render
unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor<super::Api>) {
unsafe fn begin_render_pass(
&mut self,
desc: &crate::RenderPassDescriptor<super::QuerySet, super::TextureView>,
) {
let mut vk_clear_values =
ArrayVec::<vk::ClearValue, { super::MAX_TOTAL_ATTACHMENTS }>::new();
let mut vk_image_views = ArrayVec::<vk::ImageView, { super::MAX_TOTAL_ATTACHMENTS }>::new();
@ -1067,7 +1070,10 @@ impl crate::CommandEncoder for super::CommandEncoder {
// compute
unsafe fn begin_compute_pass(&mut self, desc: &crate::ComputePassDescriptor<'_, super::Api>) {
unsafe fn begin_compute_pass(
&mut self,
desc: &crate::ComputePassDescriptor<'_, super::QuerySet>,
) {
self.bind_point = vk::PipelineBindPoint::COMPUTE;
if let Some(label) = desc.label {
unsafe { self.begin_debug_marker(label) };

View File

@ -178,7 +178,7 @@ pub fn map_vk_surface_formats(sf: vk::SurfaceFormatKHR) -> Option<wgt::TextureFo
})
}
impl crate::Attachment<'_, super::Api> {
impl crate::Attachment<'_, super::TextureView> {
pub(super) fn make_attachment_key(
&self,
ops: crate::AttachmentOps,
@ -192,7 +192,7 @@ impl crate::Attachment<'_, super::Api> {
}
}
impl crate::ColorAttachment<'_, super::Api> {
impl crate::ColorAttachment<'_, super::TextureView> {
pub(super) unsafe fn make_vk_clear_color(&self) -> vk::ClearColorValue {
let cv = &self.clear_value;
match self