wgpu_core/command/
render_command.rs

1use super::{DrawCommandFamily, Rect};
2#[cfg(feature = "serde")]
3use crate::command::serde_object_reference_struct;
4use crate::command::{ArcReferences, ReferenceType};
5use alloc::vec::Vec;
6use wgt::{BufferAddress, BufferSize, Color};
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: Option<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 immediate data to be written.
54        data: Vec<u32>,
55    },
56    Draw {
57        vertex_count: u32,
58        instance_count: u32,
59        first_vertex: u32,
60        first_instance: u32,
61    },
62    DrawIndexed {
63        index_count: u32,
64        instance_count: u32,
65        first_index: u32,
66        base_vertex: i32,
67        first_instance: u32,
68    },
69    DrawMeshTasks {
70        group_count_x: u32,
71        group_count_y: u32,
72        group_count_z: u32,
73    },
74    DrawIndirect {
75        buffer: R::Buffer,
76        offset: BufferAddress,
77        count: u32,
78        family: DrawCommandFamily,
79        /// This limit is only populated for commands in a finished [`RenderBundle`].
80        vertex_or_index_limit: Option<u64>,
81        /// This limit is only populated for commands in a finished [`RenderBundle`].
82        instance_limit: Option<u64>,
83    },
84    MultiDrawIndirectCount {
85        buffer: R::Buffer,
86        offset: BufferAddress,
87        count_buffer: R::Buffer,
88        count_buffer_offset: BufferAddress,
89        max_count: u32,
90        family: DrawCommandFamily,
91    },
92    PushDebugGroup {
93        color: u32,
94        len: usize,
95    },
96    PopDebugGroup,
97    InsertDebugMarker {
98        color: u32,
99        len: usize,
100    },
101    WriteTimestamp {
102        query_set: R::QuerySet,
103        query_index: u32,
104    },
105    BeginOcclusionQuery {
106        query_index: u32,
107    },
108    EndOcclusionQuery,
109    BeginPipelineStatisticsQuery {
110        query_set: R::QuerySet,
111        query_index: u32,
112    },
113    EndPipelineStatisticsQuery,
114    ExecuteBundle(R::RenderBundle),
115}
116
117/// Equivalent to `RenderCommand` with the Ids resolved into resource Arcs.
118///
119/// In a render pass, commands are stored in this format between when they are
120/// added to the pass, and when the pass is `end()`ed and the commands are
121/// replayed to the HAL encoder. Validation occurs when the pass is ended, which
122/// means that parameters stored in an `ArcRenderCommand` for a pass operation
123/// have generally not been validated.
124///
125/// In a render bundle, commands are stored in this format between when the bundle
126/// is `finish()`ed and when the bundle is executed. Validation occurs when the
127/// bundle is finished, which means that parameters stored in an `ArcRenderCommand`
128/// for a render bundle operation must have been validated.
129///
130/// cbindgen:ignore
131pub type ArcRenderCommand = RenderCommand<ArcReferences>;