pub struct CommandBuffer { /* private fields */ }Expand description
One in-flight wgpu::CommandEncoder, handed to a renderer under a strict
borrowing contract.
§Invariant
A renderer handed this encoder records only render passes and staged uploads; it never submits, never begins a pass it does not end before returning, holds no borrow past return; the caller may record its own passes before and after and submit once. Exception: glyph-atlas uploads may submit their OWN encoder so atlas content is committed before the scene pass reads it (vello_hybrid render/wgpu/mod.rs:428-430).
A staged upload may leave one more thing on the encoder: the deferred
re-map of the staging slot it was copied from
(wgpu::CommandEncoder::map_buffer_on_submit, see crate::staging).
It runs only when the caller submits, after the caller’s own work in the
same submission, and is dropped harmlessly with an encoder that is never
submitted — it asks nothing of the caller beyond the one submit.
A caller recording depth-writing passes of its own around a renderer’s owes the module-level two caller rules on top of this: depth-clear ownership, with the comparison, direction and extent that ride along with it.
Implementations§
Source§impl CommandBuffer
impl CommandBuffer
Sourcepub fn new(device: &Device, label: Option<&str>) -> Self
pub fn new(device: &Device, label: Option<&str>) -> Self
Begins recording a fresh command buffer on device.
Sourcepub fn render_pass<'e>(
&'e mut self,
target: &RenderTarget<'_>,
label: Option<&str>,
) -> RenderPass<'e>
pub fn render_pass<'e>( &'e mut self, target: &RenderTarget<'_>, label: Option<&str>, ) -> RenderPass<'e>
Begins a render pass over target’s color and depth attachments.
The returned wgpu::RenderPass borrows this buffer’s encoder; per the
type-level invariant, a caller must end it (drop it, or call .end())
before recording anything else through Self::encoder_mut, starting
another pass, or calling Self::finish.
Sourcepub fn encoder_mut(&mut self) -> &mut CommandEncoder
pub fn encoder_mut(&mut self) -> &mut CommandEncoder
The borrowing seam: direct mutable access to the underlying encoder for recording this type does not model — a staged buffer/texture upload, or a pass shape this crate does not own.
A caller reaching for this still owes the type-level invariant: no submit, and no pass left open across a return.
Sourcepub fn finish(self) -> CommandBuffer
pub fn finish(self) -> CommandBuffer
Ends recording and hands back the finished wgpu::CommandBuffer for
the caller to submit — once, alongside anything else it recorded
before or after this buffer’s own passes.