wgpu/api/
command_buffer.rs

1use crate::{
2    api::{impl_deferred_command_buffer_actions, SharedDeferredCommandBufferActions},
3    *,
4};
5
6/// Handle to a command buffer on the GPU.
7///
8/// A `CommandBuffer` represents a complete sequence of commands that may be submitted to a command
9/// queue with [`Queue::submit`]. A `CommandBuffer` is obtained by recording a series of commands to
10/// a [`CommandEncoder`] and then calling [`CommandEncoder::finish`].
11///
12/// Corresponds to [WebGPU `GPUCommandBuffer`](https://gpuweb.github.io/gpuweb/#command-buffer).
13#[derive(Debug)]
14pub struct CommandBuffer {
15    pub(crate) buffer: dispatch::DispatchCommandBuffer,
16    /// Deferred actions recorded at encode time, to run at Queue::submit.
17    pub(crate) actions: SharedDeferredCommandBufferActions,
18}
19#[cfg(send_sync)]
20static_assertions::assert_impl_all!(CommandBuffer: Send, Sync);
21
22impl CommandBuffer {
23    #[cfg(custom)]
24    /// Returns custom implementation of CommandBuffer (if custom backend and is internally T)
25    pub fn as_custom<T: custom::CommandBufferInterface>(&self) -> Option<&T> {
26        self.buffer.as_custom()
27    }
28
29    // Expose map_buffer_on_submit/on_submitted_work_done on CommandBuffer as well,
30    // so callers can schedule after finishing encoding.
31    impl_deferred_command_buffer_actions!();
32}