1use core::{convert::Infallible, num::NonZero};
2
3use alloc::{string::String, sync::Arc, vec::Vec};
4#[cfg(feature = "serde")]
5use macro_rules_attribute::{apply, attribute_alias};
6
7use crate::{
8 command::ColorAttachments,
9 instance::Surface,
10 resource::{Buffer, QuerySet, Texture},
11};
12
13pub trait ReferenceType {
14 type Buffer: Clone + core::fmt::Debug;
15 type Surface: Clone; type Texture: Clone + core::fmt::Debug;
17 type TextureView: Clone + core::fmt::Debug;
18 type ExternalTexture: Clone + core::fmt::Debug;
19 type QuerySet: Clone + core::fmt::Debug;
20 type BindGroup: Clone + core::fmt::Debug;
21 type RenderPipeline: Clone + core::fmt::Debug;
22 type RenderBundle: Clone + core::fmt::Debug;
23 type ComputePipeline: Clone + core::fmt::Debug;
24 type RayTracingPipeline: Clone + core::fmt::Debug;
25 type Blas: Clone + core::fmt::Debug;
26 type Tlas: Clone + core::fmt::Debug;
27}
28
29#[cfg(any(feature = "trace", feature = "replay"))]
35#[doc(hidden)]
36#[derive(Clone, Debug)]
37pub struct PointerReferences;
38
39#[derive(Clone, Debug)]
41pub struct ArcReferences;
42
43#[cfg(any(feature = "trace", feature = "replay"))]
44impl ReferenceType for PointerReferences {
45 type Buffer = crate::id::PointerId<crate::id::markers::Buffer>;
46 type Surface = crate::id::PointerId<crate::id::markers::Surface>;
47 type Texture = crate::id::PointerId<crate::id::markers::Texture>;
48 type TextureView = crate::id::PointerId<crate::id::markers::TextureView>;
49 type ExternalTexture = crate::id::PointerId<crate::id::markers::ExternalTexture>;
50 type QuerySet = crate::id::PointerId<crate::id::markers::QuerySet>;
51 type BindGroup = crate::id::PointerId<crate::id::markers::BindGroup>;
52 type RenderPipeline = crate::id::PointerId<crate::id::markers::RenderPipeline>;
53 type RenderBundle = crate::id::PointerId<crate::id::markers::RenderBundle>;
54 type ComputePipeline = crate::id::PointerId<crate::id::markers::ComputePipeline>;
55 type RayTracingPipeline = crate::id::PointerId<crate::id::markers::RayTracingPipeline>;
56 type Blas = crate::id::PointerId<crate::id::markers::Blas>;
57 type Tlas = crate::id::PointerId<crate::id::markers::Tlas>;
58}
59
60impl ReferenceType for ArcReferences {
61 type Buffer = Arc<Buffer>;
62 type Surface = Arc<Surface>;
63 type Texture = Arc<Texture>;
64 type TextureView = Arc<crate::resource::TextureView>;
65 type ExternalTexture = Arc<crate::resource::ExternalTexture>;
66 type QuerySet = Arc<QuerySet>;
67 type BindGroup = Arc<crate::binding_model::BindGroup>;
68 type RenderPipeline = Arc<crate::pipeline::RenderPipeline>;
69 type RenderBundle = Arc<crate::command::RenderBundle>;
70 type ComputePipeline = Arc<crate::pipeline::ComputePipeline>;
71 type RayTracingPipeline = Arc<crate::ray_tracing_pipeline::RayTracingPipeline>;
72 type Blas = Arc<crate::resource::Blas>;
73 type Tlas = Arc<crate::resource::Tlas>;
74}
75
76#[cfg(feature = "serde")]
77attribute_alias! {
78 #[apply(serde_object_reference_struct)] =
79 #[derive(serde::Serialize, serde::Deserialize)]
80 #[serde(bound =
81 "R::Buffer: serde::Serialize + for<'d> serde::Deserialize<'d>,\
82 R::Surface: serde::Serialize + for<'d> serde::Deserialize<'d>,\
83 R::Texture: serde::Serialize + for<'d> serde::Deserialize<'d>,\
84 R::TextureView: serde::Serialize + for<'d> serde::Deserialize<'d>,\
85 R::ExternalTexture: serde::Serialize + for<'d> serde::Deserialize<'d>,\
86 R::QuerySet: serde::Serialize + for<'d> serde::Deserialize<'d>,\
87 R::BindGroup: serde::Serialize + for<'d> serde::Deserialize<'d>,\
88 R::RenderPipeline: serde::Serialize + for<'d> serde::Deserialize<'d>,\
89 R::RenderBundle: serde::Serialize + for<'d> serde::Deserialize<'d>,\
90 R::ComputePipeline: serde::Serialize + for<'d> serde::Deserialize<'d>,\
91 R::RayTracingPipeline: serde::Serialize + for<'d> serde::Deserialize<'d>,\
92 R::Blas: serde::Serialize + for<'d> serde::Deserialize<'d>,\
93 R::Tlas: serde::Serialize + for<'d> serde::Deserialize<'d>,\
94 wgt::BufferTransition<R::Buffer>: serde::Serialize + for<'d> serde::Deserialize<'d>,\
95 wgt::TextureTransition<R::Texture>: serde::Serialize + for<'d> serde::Deserialize<'d>"
96 )];
97}
98
99#[derive(Clone, Debug)]
100#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
101pub enum Command<R: ReferenceType> {
102 CopyBufferToBuffer {
103 src: R::Buffer,
104 src_offset: wgt::BufferAddress,
105 dst: R::Buffer,
106 dst_offset: wgt::BufferAddress,
107 size: Option<wgt::BufferAddress>,
108 },
109 CopyBufferToTexture {
110 src: wgt::TexelCopyBufferInfo<R::Buffer>,
111 dst: wgt::TexelCopyTextureInfo<R::Texture>,
112 size: wgt::Extent3d,
113 },
114 CopyTextureToBuffer {
115 src: wgt::TexelCopyTextureInfo<R::Texture>,
116 dst: wgt::TexelCopyBufferInfo<R::Buffer>,
117 size: wgt::Extent3d,
118 },
119 CopyTextureToTexture {
120 src: wgt::TexelCopyTextureInfo<R::Texture>,
121 dst: wgt::TexelCopyTextureInfo<R::Texture>,
122 size: wgt::Extent3d,
123 },
124 ClearBuffer {
125 dst: R::Buffer,
126 offset: wgt::BufferAddress,
127 size: Option<wgt::BufferAddress>,
128 },
129 ClearTexture {
130 dst: R::Texture,
131 subresource_range: wgt::ImageSubresourceRange,
132 },
133 WriteTimestamp {
134 query_set: R::QuerySet,
135 query_index: u32,
136 },
137 ResolveQuerySet {
138 query_set: R::QuerySet,
139 start_query: u32,
140 query_count: u32,
141 destination: R::Buffer,
142 destination_offset: wgt::BufferAddress,
143 },
144 PushDebugGroup(String),
145 PopDebugGroup,
146 InsertDebugMarker(String),
147 RunComputePass {
148 pass: crate::command::BasePass<crate::command::ComputeCommand<R>, Infallible>,
149 timestamp_writes: Option<crate::command::PassTimestampWrites<R::QuerySet>>,
150 },
151 RunRayTracingPass {
152 pass: crate::command::BasePass<crate::command::RayTracingCommand<R>, Infallible>,
153 },
154 RunRenderPass {
155 pass: crate::command::BasePass<crate::command::RenderCommand<R>, Infallible>,
156 color_attachments: ColorAttachments<R::TextureView>,
157 depth_stencil_attachment:
158 Option<crate::command::ResolvedRenderPassDepthStencilAttachment<R::TextureView>>,
159 timestamp_writes: Option<crate::command::PassTimestampWrites<R::QuerySet>>,
160 occlusion_query_set: Option<R::QuerySet>,
161 multiview_mask: Option<NonZero<u32>>,
162 },
163 BuildAccelerationStructures {
164 blas: Vec<crate::ray_tracing::OwnedBlasBuildEntry<R>>,
165 tlas: Vec<crate::ray_tracing::OwnedTlasPackage<R>>,
166 },
167 TransitionResources {
168 buffer_transitions: Vec<wgt::BufferTransition<R::Buffer>>,
169 texture_transitions: Vec<wgt::TextureTransition<R::Texture>>,
170 },
171}
172
173pub type ArcCommand = Command<ArcReferences>;