wgpu/api/
command_buffer.rs

1use std::{sync::Arc, thread};
2
3use crate::*;
4
5/// Handle to a command buffer on the GPU.
6///
7/// A `CommandBuffer` represents a complete sequence of commands that may be submitted to a command
8/// queue with [`Queue::submit`]. A `CommandBuffer` is obtained by recording a series of commands to
9/// a [`CommandEncoder`] and then calling [`CommandEncoder::finish`].
10///
11/// Corresponds to [WebGPU `GPUCommandBuffer`](https://gpuweb.github.io/gpuweb/#command-buffer).
12#[derive(Debug)]
13pub struct CommandBuffer {
14    pub(crate) context: Arc<C>,
15    pub(crate) data: Option<Box<Data>>,
16}
17#[cfg(send_sync)]
18static_assertions::assert_impl_all!(CommandBuffer: Send, Sync);
19
20impl Drop for CommandBuffer {
21    fn drop(&mut self) {
22        if !thread::panicking() {
23            if let Some(data) = self.data.take() {
24                self.context.command_buffer_drop(data.as_ref());
25            }
26        }
27    }
28}