diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 94475d2956..31f7d6d8d9 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -24,16 +24,85 @@ use crate::{ use arrayvec::ArrayVec; use hal::command::CommandBuffer as _; use wgt::{ - BufferAddress, BufferSize, BufferUsage, Color, IndexFormat, InputStepMode, LoadOp, - RenderPassColorAttachmentDescriptorBase, RenderPassDepthStencilAttachmentDescriptorBase, - StoreOp, TextureUsage, + BufferAddress, BufferSize, BufferUsage, Color, IndexFormat, InputStepMode, TextureUsage, }; +#[cfg(any(feature = "serial-pass", feature = "replay"))] +use serde::Deserialize; +#[cfg(any(feature = "serial-pass", feature = "trace"))] +use serde::Serialize; + use std::{borrow::Borrow, collections::hash_map::Entry, fmt, iter, ops::Range, str}; -pub type ColorAttachmentDescriptor = RenderPassColorAttachmentDescriptorBase; -pub type DepthStencilAttachmentDescriptor = - RenderPassDepthStencilAttachmentDescriptorBase; +/// Operation to perform to the output attachment at the start of a renderpass. +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] +#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +pub enum LoadOp { + /// Clear the output attachment with the clear color. Clearing is faster than loading. + Clear = 0, + /// Do not clear output attachment. + Load = 1, +} + +/// Operation to perform to the output attachment at the end of a renderpass. +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] +#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +pub enum StoreOp { + /// Clear the render target. If you don't care about the contents of the target, this can be faster. + Clear = 0, + /// Store the result of the renderpass. + Store = 1, +} + +/// Describes an individual channel within a render pass, such as color, depth, or stencil. +#[repr(C)] +#[derive(Clone, Debug)] +#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] +#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +pub struct PassChannel { + /// Operation to perform to the output attachment at the start of a renderpass. This must be clear if it + /// is the first renderpass rendering to a swap chain image. + pub load_op: LoadOp, + /// Operation to perform to the output attachment at the end of a renderpass. + pub store_op: StoreOp, + /// If load_op is [`LoadOp::Clear`], the attachement will be cleared to this color. + pub clear_value: V, + /// If true, the relevant channel is not changed by a renderpass, and the corresponding attachment + /// can be used inside the pass by other read-only usages. + pub read_only: bool, +} + +/// Describes a color attachment to a render pass. +#[repr(C)] +#[derive(Clone, Debug)] +#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] +#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +pub struct ColorAttachmentDescriptor { + /// The view to use as an attachment. + pub attachment: id::TextureViewId, + /// The view that will receive the resolved output if multisampling is used. + pub resolve_target: Option, + /// What operations will be performed on this color attachment. + pub channel: PassChannel, +} + +/// Describes a depth/stencil attachment to a render pass. +#[repr(C)] +#[derive(Clone, Debug)] +#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] +#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] +pub struct DepthStencilAttachmentDescriptor { + /// The view to use as an attachment. + pub attachment: id::TextureViewId, + /// What operations will be performed on the depth part of the attachment. + pub depth: PassChannel, + /// What operations will be performed on the stencil part of the attachment. + pub stencil: PassChannel, +} fn is_depth_stencil_read_only( desc: &DepthStencilAttachmentDescriptor, @@ -62,7 +131,8 @@ pub type RenderPassDescriptor<'a> = wgt::RenderPassDescriptor<'a, ColorAttachmentDescriptor, &'a DepthStencilAttachmentDescriptor>; #[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] +#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] pub struct Rect { pub x: T, pub y: T, @@ -72,14 +142,8 @@ pub struct Rect { #[doc(hidden)] #[derive(Clone, Copy, Debug)] -#[cfg_attr( - any(feature = "serial-pass", feature = "trace"), - derive(serde::Serialize) -)] -#[cfg_attr( - any(feature = "serial-pass", feature = "replay"), - derive(serde::Deserialize) -)] +#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] +#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] pub enum RenderCommand { SetBindGroup { index: u8, @@ -147,7 +211,7 @@ pub enum RenderCommand { ExecuteBundle(id::RenderBundleId), } -#[cfg_attr(feature = "serial-pass", derive(serde::Deserialize, serde::Serialize))] +#[cfg_attr(feature = "serial-pass", derive(Deserialize, Serialize))] pub struct RenderPass { base: BasePass, parent_id: id::CommandEncoderId, diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index 6f37bcff82..0b15c42823 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -2,7 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use crate::{resource, PrivateFeatures}; +use crate::{ + command::{LoadOp, PassChannel, StoreOp}, + resource, PrivateFeatures, +}; pub fn map_buffer_usage(usage: wgt::BufferUsage) -> (hal::buffer::Usage, hal::memory::Properties) { use hal::buffer::Usage as U; @@ -572,15 +575,15 @@ pub(crate) fn map_texture_state( (access, layout) } -pub fn map_load_store_ops(channel: &wgt::PassChannel) -> hal::pass::AttachmentOps { +pub fn map_load_store_ops(channel: &PassChannel) -> hal::pass::AttachmentOps { hal::pass::AttachmentOps { load: match channel.load_op { - wgt::LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear, - wgt::LoadOp::Load => hal::pass::AttachmentLoadOp::Load, + LoadOp::Clear => hal::pass::AttachmentLoadOp::Clear, + LoadOp::Load => hal::pass::AttachmentLoadOp::Load, }, store: match channel.store_op { - wgt::StoreOp::Clear => hal::pass::AttachmentStoreOp::DontCare, //TODO! - wgt::StoreOp::Store => hal::pass::AttachmentStoreOp::Store, + StoreOp::Clear => hal::pass::AttachmentStoreOp::DontCare, //TODO! + StoreOp::Store => hal::pass::AttachmentStoreOp::Store, }, } } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index c8711a9d7a..048a393a2d 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1077,74 +1077,6 @@ pub enum SwapChainStatus { OutOfMemory, } -/// Operation to perform to the output attachment at the start of a renderpass. -#[repr(C)] -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum LoadOp { - /// Clear the output attachment with the clear color. Clearing is faster than loading. - Clear = 0, - /// Do not clear output attachment. - Load = 1, -} - -/// Operation to perform to the output attachment at the end of a renderpass. -#[repr(C)] -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum StoreOp { - /// Clear the render target. If you don't care about the contents of the target, this can be faster. - Clear = 0, - /// Store the result of the renderpass. - Store = 1, -} - -/// Describes an individual channel within a render pass, such as color, depth, or stencil. -#[repr(C)] -#[derive(Clone, Debug)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct PassChannel { - /// Operation to perform to the output attachment at the start of a renderpass. This must be clear if it - /// is the first renderpass rendering to a swap chain image. - pub load_op: LoadOp, - /// Operation to perform to the output attachment at the end of a renderpass. - pub store_op: StoreOp, - /// If load_op is [`LoadOp::Clear`], the attachement will be cleared to this color. - pub clear_value: V, - /// If true, the relevant channel is not changed by a renderpass, and the corresponding attachment - /// can be used inside the pass by other read-only usages. - pub read_only: bool, -} - -/// Describes a color attachment to a [`RenderPass`]. -#[repr(C)] -#[derive(Clone, Debug)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct RenderPassColorAttachmentDescriptorBase { - /// Texture attachment to render to. Must contain [`TextureUsage::OUTPUT_ATTACHMENT`]. - pub attachment: T, - /// MSAA resolve target. Must contain [`TextureUsage::OUTPUT_ATTACHMENT`]. Must be `None` if - /// attachment has 1 sample (does not have MSAA). This is not mandatory for rendering with multisampling, - /// you can choose to resolve later or manually. - pub resolve_target: Option, - /// Color channel. - pub channel: PassChannel, -} - -/// Describes a depth/stencil attachment to a [`RenderPass`]. -#[repr(C)] -#[derive(Clone, Debug)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct RenderPassDepthStencilAttachmentDescriptorBase { - /// Texture attachment to render to. Must contain [`TextureUsage::OUTPUT_ATTACHMENT`] and be a valid - /// texture type for a depth/stencil attachment. - pub attachment: T, - /// Depth channel. - pub depth: PassChannel, - /// Stencil channel. - pub stencil: PassChannel, -} - /// Describes the attachments of a render pass. #[derive(Clone, Debug, Default, PartialEq)] pub struct RenderPassDescriptor<'a, C, D> {