Move RenderPass*AttachmentDescriptor types into core

This commit is contained in:
Gabriel Majeri
2020-07-13 20:48:40 +03:00
parent d7ee89018b
commit 39ed7a008c
3 changed files with 89 additions and 90 deletions

View File

@@ -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<id::TextureViewId>;
pub type DepthStencilAttachmentDescriptor =
RenderPassDepthStencilAttachmentDescriptorBase<id::TextureViewId>;
/// 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<V> {
/// 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<id::TextureViewId>,
/// What operations will be performed on this color attachment.
pub channel: PassChannel<Color>,
}
/// 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<f32>,
/// What operations will be performed on the stencil part of the attachment.
pub stencil: PassChannel<u32>,
}
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<T> {
pub x: T,
pub y: T,
@@ -72,14 +142,8 @@ pub struct Rect<T> {
#[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<RenderCommand>,
parent_id: id::CommandEncoderId,

View File

@@ -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<V>(channel: &wgt::PassChannel<V>) -> hal::pass::AttachmentOps {
pub fn map_load_store_ops<V>(channel: &PassChannel<V>) -> 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,
},
}
}

View File

@@ -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<V> {
/// 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<T> {
/// 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<T>,
/// Color channel.
pub channel: PassChannel<Color>,
}
/// Describes a depth/stencil attachment to a [`RenderPass`].
#[repr(C)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RenderPassDepthStencilAttachmentDescriptorBase<T> {
/// 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<f32>,
/// Stencil channel.
pub stencil: PassChannel<u32>,
}
/// Describes the attachments of a render pass.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RenderPassDescriptor<'a, C, D> {