wgpu_core/command/render_command.rs
1use wgt::{BufferAddress, BufferSize, Color};
2
3use super::{DrawCommandFamily, Rect};
4#[cfg(feature = "serde")]
5use crate::command::serde_object_reference_struct;
6use crate::command::{ArcReferences, ReferenceType};
7
8#[cfg(feature = "serde")]
9use macro_rules_attribute::apply;
10
11/// cbindgen:ignore
12#[doc(hidden)]
13#[derive(Clone, Debug)]
14#[cfg_attr(feature = "serde", apply(serde_object_reference_struct))]
15pub enum RenderCommand<R: ReferenceType> {
16 SetBindGroup {
17 index: u32,
18 num_dynamic_offsets: usize,
19 bind_group: Option<R::BindGroup>,
20 },
21 SetPipeline(R::RenderPipeline),
22 SetIndexBuffer {
23 buffer: R::Buffer,
24 index_format: wgt::IndexFormat,
25 offset: BufferAddress,
26 size: Option<BufferSize>,
27 },
28 SetVertexBuffer {
29 slot: u32,
30 buffer: R::Buffer,
31 offset: BufferAddress,
32 size: Option<BufferSize>,
33 },
34 SetBlendConstant(Color),
35 SetStencilReference(u32),
36 SetViewport {
37 rect: Rect<f32>,
38 //TODO: use half-float to reduce the size?
39 depth_min: f32,
40 depth_max: f32,
41 },
42 SetScissor(Rect<u32>),
43
44 /// Set a range of push constants to values stored in [`BasePass::push_constant_data`].
45 ///
46 /// See [`wgpu::RenderPass::set_push_constants`] for a detailed explanation
47 /// of the restrictions these commands must satisfy.
48 SetPushConstant {
49 /// Which stages we are setting push constant values for.
50 stages: wgt::ShaderStages,
51
52 /// The byte offset within the push constant storage to write to. This
53 /// must be a multiple of four.
54 offset: u32,
55
56 /// The number of bytes to write. This must be a multiple of four.
57 size_bytes: u32,
58
59 /// Index in [`BasePass::push_constant_data`] of the start of the data
60 /// to be written.
61 ///
62 /// Note: this is not a byte offset like `offset`. Rather, it is the
63 /// index of the first `u32` element in `push_constant_data` to read.
64 ///
65 /// `None` means zeros should be written to the destination range, and
66 /// there is no corresponding data in `push_constant_data`. This is used
67 /// by render bundles, which explicitly clear out any state that
68 /// post-bundle code might see.
69 values_offset: Option<u32>,
70 },
71 Draw {
72 vertex_count: u32,
73 instance_count: u32,
74 first_vertex: u32,
75 first_instance: u32,
76 },
77 DrawIndexed {
78 index_count: u32,
79 instance_count: u32,
80 first_index: u32,
81 base_vertex: i32,
82 first_instance: u32,
83 },
84 DrawMeshTasks {
85 group_count_x: u32,
86 group_count_y: u32,
87 group_count_z: u32,
88 },
89 DrawIndirect {
90 buffer: R::Buffer,
91 offset: BufferAddress,
92 count: u32,
93 family: DrawCommandFamily,
94 /// This limit is only populated for commands in a finished [`RenderBundle`].
95 vertex_or_index_limit: Option<u64>,
96 /// This limit is only populated for commands in a finished [`RenderBundle`].
97 instance_limit: Option<u64>,
98 },
99 MultiDrawIndirectCount {
100 buffer: R::Buffer,
101 offset: BufferAddress,
102 count_buffer: R::Buffer,
103 count_buffer_offset: BufferAddress,
104 max_count: u32,
105 family: DrawCommandFamily,
106 },
107 PushDebugGroup {
108 color: u32,
109 len: usize,
110 },
111 PopDebugGroup,
112 InsertDebugMarker {
113 color: u32,
114 len: usize,
115 },
116 WriteTimestamp {
117 query_set: R::QuerySet,
118 query_index: u32,
119 },
120 BeginOcclusionQuery {
121 query_index: u32,
122 },
123 EndOcclusionQuery,
124 BeginPipelineStatisticsQuery {
125 query_set: R::QuerySet,
126 query_index: u32,
127 },
128 EndPipelineStatisticsQuery,
129 ExecuteBundle(R::RenderBundle),
130}
131
132/// Equivalent to `RenderCommand` with the Ids resolved into resource Arcs.
133///
134/// In a render pass, commands are stored in this format between when they are
135/// added to the pass, and when the pass is `end()`ed and the commands are
136/// replayed to the HAL encoder. Validation occurs when the pass is ended, which
137/// means that parameters stored in an `ArcRenderCommand` for a pass operation
138/// have generally not been validated.
139///
140/// In a render bundle, commands are stored in this format between when the bundle
141/// is `finish()`ed and when the bundle is executed. Validation occurs when the
142/// bundle is finished, which means that parameters stored in an `ArcRenderCommand`
143/// for a render bundle operation must have been validated.
144///
145/// cbindgen:ignore
146pub type ArcRenderCommand = RenderCommand<ArcReferences>;