pub struct CommandBuffer {
pub label: String,
/* private fields */
}Expand description
Record commands for the GPU, spawn render/compute passes, and submit once finished. Guard rails ensure pipelines/buffers are set before draws/dispatches.
§Examples
Clear a surface:
use wde_wgpu::{
command_buffer::{Color, CommandBuffer, LoadOp, RenderPassColorAttachment, StoreOp},
instance::RenderInstanceData,
texture::TextureView,
};
let mut cmd = CommandBuffer::new(instance, "frame");
{
cmd.create_render_pass("clear", |pass| {
pass.add_color_attachment(RenderPassColorAttachment {
texture: Some(view),
load: LoadOp::Clear(Color::BLACK),
store: StoreOp::Store,
});
});
}
cmd.submit(instance);Dispatch compute work:
use wde_wgpu::{command_buffer::CommandBuffer, compute_pass::WComputePass, compute_pipeline::ComputePipeline};
let mut cmd = CommandBuffer::new(instance, "compute");
{
let mut pass: WComputePass = cmd.create_compute_pass("cull");
pass.set_pipeline(pipeline).unwrap().set_bind_group(0, bind).dispatch(4, 1, 1).unwrap();
}
cmd.submit(instance);Fields§
§label: StringImplementations§
Source§impl CommandBuffer
impl CommandBuffer
Sourcepub fn new(instance: &RenderInstanceData<'_>, label: &str) -> CommandBuffer
pub fn new(instance: &RenderInstanceData<'_>, label: &str) -> CommandBuffer
Create a new command buffer.
§Arguments
instance- The render instance.label- The label of the command buffer.
Sourcepub fn create_render_pass<'pass>(
&'pass mut self,
label: &str,
builder_func: impl FnOnce(&mut RenderPassBuilder<'pass>) -> Result<(), String>,
) -> Result<RenderPassInstance<'pass>, String>
pub fn create_render_pass<'pass>( &'pass mut self, label: &str, builder_func: impl FnOnce(&mut RenderPassBuilder<'pass>) -> Result<(), String>, ) -> Result<RenderPassInstance<'pass>, String>
Create a new render pass.
§Arguments
label- The label of the render pass.builder_func- The function to build the render pass. This function should returnOk(())if the render pass was built successfully, andErr(String)otherwise. If the function returnsErr, the render pass will not be created.
Sourcepub fn create_compute_pass<'pass>(
&'pass mut self,
label: &str,
) -> WComputePass<'pass>
pub fn create_compute_pass<'pass>( &'pass mut self, label: &str, ) -> WComputePass<'pass>
Sourcepub fn submit(self, instance: &RenderInstanceData<'_>)
pub fn submit(self, instance: &RenderInstanceData<'_>)
Sourcepub fn copy_buffer_to_buffer(&mut self, source: &Buffer, destination: &Buffer)
pub fn copy_buffer_to_buffer(&mut self, source: &Buffer, destination: &Buffer)
Copy a buffer to another buffer.
Please use the copy_from_buffer method of the buffer to copy data.
§Arguments
source- The source buffer.destination- The destination buffer.
Sourcepub fn copy_buffer_to_buffer_offset(
&mut self,
source: &Buffer,
destination: &Buffer,
source_offset: u64,
destination_offset: u64,
size: u64,
)
pub fn copy_buffer_to_buffer_offset( &mut self, source: &Buffer, destination: &Buffer, source_offset: u64, destination_offset: u64, size: u64, )
Copy a buffer to another buffer with offsets.
Please use the copy_from_buffer method of the buffer to copy data.
§Arguments
source- The source buffer.destination- The destination buffer.source_offset- The offset in the source buffer.destination_offset- The offset in the destination buffer.size- The size to copy.
Sourcepub fn copy_texture_to_buffer(
&mut self,
source: &Texture,
destination: &Buffer,
size: Extent3d,
)
pub fn copy_texture_to_buffer( &mut self, source: &Texture, destination: &Buffer, size: Extent3d, )
Copy a texture to a buffer.
Please use the copy_from_texture method of the buffer to copy data.
§Arguments
source- The source texture.destination- The destination buffer.size- The size of the texture.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CommandBuffer
impl !RefUnwindSafe for CommandBuffer
impl Send for CommandBuffer
impl Sync for CommandBuffer
impl Unpin for CommandBuffer
impl !UnwindSafe for CommandBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.