use core::{convert::Infallible, num::NonZero}; use alloc::{string::String, sync::Arc, vec::Vec}; #[cfg(feature = "serde")] use macro_rules_attribute::{apply, attribute_alias}; use crate::{ command::ColorAttachments, id, instance::Surface, resource::{Buffer, QuerySet, Texture}, }; pub trait ReferenceType { type Buffer: Clone + core::fmt::Debug; type Surface: Clone; // Surface does not implement Debug, although it probably could. type Texture: Clone + core::fmt::Debug; type TextureView: Clone + core::fmt::Debug; type ExternalTexture: Clone + core::fmt::Debug; type QuerySet: Clone + core::fmt::Debug; type BindGroup: Clone + core::fmt::Debug; type RenderPipeline: Clone + core::fmt::Debug; type RenderBundle: Clone + core::fmt::Debug; type ComputePipeline: Clone + core::fmt::Debug; type Blas: Clone + core::fmt::Debug; type Tlas: Clone + core::fmt::Debug; } /// Reference wgpu objects via numeric IDs assigned by [`crate::identity::IdentityManager`]. #[derive(Clone, Debug)] pub struct IdReferences; /// Reference wgpu objects via the integer value of pointers. /// /// This is used for trace recording and playback. Recording stores the pointer /// value of `Arc` references in the trace. Playback uses the integer values /// as keys to a `HashMap`. #[cfg(any(feature = "trace", feature = "replay"))] #[doc(hidden)] #[derive(Clone, Debug)] pub struct PointerReferences; /// Reference wgpu objects via `Arc`s. #[derive(Clone, Debug)] pub struct ArcReferences; impl ReferenceType for IdReferences { type Buffer = id::BufferId; type Surface = id::SurfaceId; type Texture = id::TextureId; type TextureView = id::TextureViewId; type ExternalTexture = id::ExternalTextureId; type QuerySet = id::QuerySetId; type BindGroup = id::BindGroupId; type RenderPipeline = id::RenderPipelineId; type RenderBundle = id::RenderBundleId; type ComputePipeline = id::ComputePipelineId; type Blas = id::BlasId; type Tlas = id::TlasId; } #[cfg(any(feature = "trace", feature = "replay"))] impl ReferenceType for PointerReferences { type Buffer = id::PointerId; type Surface = id::PointerId; type Texture = id::PointerId; type TextureView = id::PointerId; type ExternalTexture = id::PointerId; type QuerySet = id::PointerId; type BindGroup = id::PointerId; type RenderPipeline = id::PointerId; type RenderBundle = id::PointerId; type ComputePipeline = id::PointerId; type Blas = id::PointerId; type Tlas = id::PointerId; } impl ReferenceType for ArcReferences { type Buffer = Arc; type Surface = Arc; type Texture = Arc; type TextureView = Arc; type ExternalTexture = Arc; type QuerySet = Arc; type BindGroup = Arc; type RenderPipeline = Arc; type RenderBundle = Arc; type ComputePipeline = Arc; type Blas = Arc; type Tlas = Arc; } #[cfg(feature = "serde")] attribute_alias! { #[apply(serde_object_reference_struct)] = #[derive(serde::Serialize, serde::Deserialize)] #[serde(bound = "R::Buffer: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::Surface: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::Texture: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::TextureView: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::ExternalTexture: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::QuerySet: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::BindGroup: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::RenderPipeline: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::RenderBundle: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::ComputePipeline: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::Blas: serde::Serialize + for<'d> serde::Deserialize<'d>,\ R::Tlas: serde::Serialize + for<'d> serde::Deserialize<'d>,\ wgt::BufferTransition: serde::Serialize + for<'d> serde::Deserialize<'d>,\ wgt::TextureTransition: serde::Serialize + for<'d> serde::Deserialize<'d>" )]; } #[derive(Clone, Debug)] #[cfg_attr(feature = "serde", apply(serde_object_reference_struct))] pub enum Command { CopyBufferToBuffer { src: R::Buffer, src_offset: wgt::BufferAddress, dst: R::Buffer, dst_offset: wgt::BufferAddress, size: Option, }, CopyBufferToTexture { src: wgt::TexelCopyBufferInfo, dst: wgt::TexelCopyTextureInfo, size: wgt::Extent3d, }, CopyTextureToBuffer { src: wgt::TexelCopyTextureInfo, dst: wgt::TexelCopyBufferInfo, size: wgt::Extent3d, }, CopyTextureToTexture { src: wgt::TexelCopyTextureInfo, dst: wgt::TexelCopyTextureInfo, size: wgt::Extent3d, }, ClearBuffer { dst: R::Buffer, offset: wgt::BufferAddress, size: Option, }, ClearTexture { dst: R::Texture, subresource_range: wgt::ImageSubresourceRange, }, WriteTimestamp { query_set: R::QuerySet, query_index: u32, }, ResolveQuerySet { query_set: R::QuerySet, start_query: u32, query_count: u32, destination: R::Buffer, destination_offset: wgt::BufferAddress, }, PushDebugGroup(String), PopDebugGroup, InsertDebugMarker(String), RunComputePass { pass: crate::command::BasePass, Infallible>, timestamp_writes: Option>, }, RunRenderPass { pass: crate::command::BasePass, Infallible>, color_attachments: ColorAttachments, depth_stencil_attachment: Option>, timestamp_writes: Option>, occlusion_query_set: Option, multiview_mask: Option>, }, BuildAccelerationStructures { blas: Vec>, tlas: Vec>, }, TransitionResources { buffer_transitions: Vec>, texture_transitions: Vec>, }, } pub type ArcCommand = Command;