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