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