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 immediates to values stored in [`BasePass::immediates_data`].
45    ///
46    /// See [`wgpu::RenderPass::set_immediates`] for a detailed explanation
47    /// of the restrictions these commands must satisfy.
48    SetImmediate {
49        /// The byte offset within the immediate data storage to write to.  This
50        /// must be a multiple of four.
51        offset: u32,
52
53        /// The number of bytes to write. This must be a multiple of four.
54        size_bytes: u32,
55
56        /// Index in [`BasePass::immediates_data`] of the start of the data
57        /// to be written.
58        ///
59        /// Note: this is not a byte offset like `offset`. Rather, it is the
60        /// index of the first `u32` element in `immediates_data` to read.
61        ///
62        /// `None` means zeros should be written to the destination range, and
63        /// there is no corresponding data in `immediates_data`. This is used
64        /// by render bundles, which explicitly clear out any state that
65        /// post-bundle code might see.
66        values_offset: Option<u32>,
67    },
68    Draw {
69        vertex_count: u32,
70        instance_count: u32,
71        first_vertex: u32,
72        first_instance: u32,
73    },
74    DrawIndexed {
75        index_count: u32,
76        instance_count: u32,
77        first_index: u32,
78        base_vertex: i32,
79        first_instance: u32,
80    },
81    DrawMeshTasks {
82        group_count_x: u32,
83        group_count_y: u32,
84        group_count_z: u32,
85    },
86    DrawIndirect {
87        buffer: R::Buffer,
88        offset: BufferAddress,
89        count: u32,
90        family: DrawCommandFamily,
91        /// This limit is only populated for commands in a finished [`RenderBundle`].
92        vertex_or_index_limit: Option<u64>,
93        /// This limit is only populated for commands in a finished [`RenderBundle`].
94        instance_limit: Option<u64>,
95    },
96    MultiDrawIndirectCount {
97        buffer: R::Buffer,
98        offset: BufferAddress,
99        count_buffer: R::Buffer,
100        count_buffer_offset: BufferAddress,
101        max_count: u32,
102        family: DrawCommandFamily,
103    },
104    PushDebugGroup {
105        color: u32,
106        len: usize,
107    },
108    PopDebugGroup,
109    InsertDebugMarker {
110        color: u32,
111        len: usize,
112    },
113    WriteTimestamp {
114        query_set: R::QuerySet,
115        query_index: u32,
116    },
117    BeginOcclusionQuery {
118        query_index: u32,
119    },
120    EndOcclusionQuery,
121    BeginPipelineStatisticsQuery {
122        query_set: R::QuerySet,
123        query_index: u32,
124    },
125    EndPipelineStatisticsQuery,
126    ExecuteBundle(R::RenderBundle),
127}
128
129/// Equivalent to `RenderCommand` with the Ids resolved into resource Arcs.
130///
131/// In a render pass, commands are stored in this format between when they are
132/// added to the pass, and when the pass is `end()`ed and the commands are
133/// replayed to the HAL encoder. Validation occurs when the pass is ended, which
134/// means that parameters stored in an `ArcRenderCommand` for a pass operation
135/// have generally not been validated.
136///
137/// In a render bundle, commands are stored in this format between when the bundle
138/// is `finish()`ed and when the bundle is executed. Validation occurs when the
139/// bundle is finished, which means that parameters stored in an `ArcRenderCommand`
140/// for a render bundle operation must have been validated.
141///
142/// cbindgen:ignore
143pub type ArcRenderCommand = RenderCommand<ArcReferences>;