Skip to main content

ComputePass

Struct ComputePass 

Source
pub struct ComputePass<'f> { /* private fields */ }
Expand description

A compute pass wrapper that automatically returns the command buffer to the frame.

This struct mirrors RenderPass in its lifecycle management - it owns its encoder and pushes the command buffer to the frame when dropped.

Implementations§

Source§

impl<'f> ComputePass<'f>

Source

pub fn wgpu_pass(&mut self) -> &mut ComputePass<'static>

Get the underlying wgpu compute pass (mutable).

Source

pub fn wgpu_pass_ref(&self) -> &ComputePass<'static>

Get the underlying wgpu compute pass (immutable).

Source

pub fn raw_pass(&mut self) -> &mut ComputePass<'static>

Get raw access to the underlying wgpu compute pass.

This is an alias for wgpu_pass() for consistency with RenderPass::raw_pass().

Source

pub fn graphics(&self) -> &GraphicsContext

Get the graphics context.

Source

pub fn set_pipeline(&mut self, pipeline: &ComputePipeline)

Set the compute pipeline to use.

Source

pub fn set_bind_group( &mut self, index: u32, bind_group: &BindGroup, offsets: &[u32], )

Set a bind group.

Source

pub fn dispatch_workgroups(&mut self, x: u32, y: u32, z: u32)

Dispatch workgroups.

§Arguments
  • x - Number of workgroups in the X dimension
  • y - Number of workgroups in the Y dimension
  • z - Number of workgroups in the Z dimension
Source

pub fn dispatch_workgroups_1d(&mut self, x: u32)

Dispatch workgroups with a 1D configuration.

Equivalent to dispatch_workgroups(x, 1, 1).

Source

pub fn dispatch_workgroups_2d(&mut self, x: u32, y: u32)

Dispatch workgroups with a 2D configuration.

Equivalent to dispatch_workgroups(x, y, 1).

Source

pub fn dispatch_workgroups_indirect(&mut self, buffer: &Buffer, offset: u64)

Dispatch workgroups indirectly from a buffer.

The buffer should contain a DispatchIndirect struct:

#[repr(C)]
struct DispatchIndirect {
    x: u32,
    y: u32,
    z: u32,
}
Source

pub fn insert_debug_marker(&mut self, label: &str)

Insert a debug marker.

Source

pub fn push_debug_group(&mut self, label: &str)

Push a debug group.

Source

pub fn pop_debug_group(&mut self)

Pop a debug group.

Source

pub fn set_push_constants<T: Pod>(&mut self, offset: u32, data: &T)

Set push constants for the compute shader.

Push constants are a fast way to pass small amounts of data to shaders without using uniform buffers. They require the PUSH_CONSTANTS feature to be enabled on the device.

§Arguments
  • offset - Byte offset into the push constant range
  • data - Data to set (must be Pod for safe byte casting)
§Example
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct ComputeConstants {
    workgroup_count: u32,
    time: f32,
}

let constants = ComputeConstants {
    workgroup_count: 64,
    time: 1.5,
};

pass.set_push_constants(0, &constants);
Source

pub fn set_push_constants_raw(&mut self, offset: u32, data: &[u8])

Set push constants from raw bytes.

Use this when you need more control over the data layout.

Source

pub fn finish(self)

Finish the compute pass, pushing the command buffer to the frame.

Trait Implementations§

Source§

impl<'a> AsWgpu for ComputePass<'a>

Source§

type WgpuType = ComputePass<'static>

The underlying wgpu type.
Source§

fn as_wgpu(&self) -> &Self::WgpuType

Get a reference to the underlying wgpu type.
Source§

impl<'a> AsWgpuMut for ComputePass<'a>

Source§

fn as_wgpu_mut(&mut self) -> &mut Self::WgpuType

Get a mutable reference to the underlying wgpu type.
Source§

impl Drop for ComputePass<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'f> Freeze for ComputePass<'f>

§

impl<'f> !RefUnwindSafe for ComputePass<'f>

§

impl<'f> !Send for ComputePass<'f>

§

impl<'f> !Sync for ComputePass<'f>

§

impl<'f> Unpin for ComputePass<'f>

§

impl<'f> UnsafeUnpin for ComputePass<'f>

§

impl<'f> !UnwindSafe for ComputePass<'f>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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.
Source§

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.
Source§

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.
Source§

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.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more