1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::{
api::{impl_deferred_command_buffer_actions, SharedDeferredCommandBufferActions},
*,
};
/// Handle to a command buffer on the GPU.
///
/// A `CommandBuffer` represents a complete sequence of commands that may be submitted to a command
/// queue with [`Queue::submit`]. A `CommandBuffer` is obtained by recording a series of commands to
/// a [`CommandEncoder`] and then calling [`CommandEncoder::finish`].
///
/// Corresponds to [WebGPU `GPUCommandBuffer`](https://gpuweb.github.io/gpuweb/#command-buffer).
#[derive(Debug)]
pub struct CommandBuffer {
pub(crate) buffer: dispatch::DispatchCommandBuffer,
/// Deferred actions recorded at encode time, to run at Queue::submit.
pub(crate) actions: SharedDeferredCommandBufferActions,
}
#[cfg(send_sync)]
static_assertions::assert_impl_all!(CommandBuffer: Send, Sync);
impl CommandBuffer {
#[cfg(custom)]
/// Returns custom implementation of CommandBuffer (if custom backend and is internally T)
pub fn as_custom<T: custom::CommandBufferInterface>(&self) -> Option<&T> {
self.buffer.as_custom()
}
// Expose map_buffer_on_submit/on_submitted_work_done on CommandBuffer as well,
// so callers can schedule after finishing encoding.
impl_deferred_command_buffer_actions!();
}
#[cfg(wgpu_core)]
impl CommandBuffer {
/// Create a new command buffer of wgpu from a wgpu-core command buffer.
///
/// # Arguments
///
/// - `core_buffer` - wgpu-core command buffer.
pub fn from_core(core_buffer: alloc::sync::Arc<wgc::command::CommandBuffer>) -> Self {
Self {
buffer: crate::backend::wgpu_core::CoreCommandBuffer::from_core(core_buffer).into(),
actions: SharedDeferredCommandBufferActions::default(),
}
}
/// Returns the underlying wgpu-core command buffer if this `CommandBuffer` is on the wgpu-core backend, otherwise `None`.
pub fn as_core(&self) -> Option<alloc::sync::Arc<wgc::command::CommandBuffer>> {
self.buffer.as_core_opt().map(|cb| cb.as_core())
}
}