Skip to main content

Compute

Struct Compute 

Source
pub struct Compute { /* private fields */ }
Expand description

A compute pipeline asset, plus the bind group values (buffers/textures) it dispatches with — WGSL shader source and its bind group layout compile into a wgpu::ComputePipeline; many Computes sharing the same shader automatically share one compiled pipeline (see ComputePipelineCache). Dispatch it via Backend::dispatch_compute.

Implementations§

Source§

impl Compute

Source

pub fn new(shader_source: &'static str) -> Self

Source

pub fn with_label(self, label: &'static str) -> Self

Source

pub fn with_entry_point(self, entry: &'static str) -> Self

Source

pub fn with_entry(self, name: &'static str, kind: BindingKind) -> Self

Declares one of this pass’s own (group 0) bind group entries, at the next auto-assigned binding index — the low-level counterpart to the streamlined .texture(...)/.buffer(...)/etc. calls, for a kind one of those doesn’t produce (a dynamic-offset buffer, a non-default sample type). Pair it with the matching value-only .with_texture(...)/etc.

Source

pub fn with_entry_at( self, name: &'static str, binding: u32, kind: BindingKind, ) -> Self

Same as with_entry, pinning an explicit binding index instead of auto-assigning the next one.

Source

pub fn with_extra_group(self, group: GroupEntry) -> Self

Appends a bind group beyond this pass’s own (group 0) — typically GroupEntry::Global, a layout shared with other materials/computes via GlobalLayoutPool. Groups append in call order, starting at group 1.

Source

pub fn with_texture(self, name: &'static str, handle: Handle<Texture>) -> Self

Value-only counterpart to .texture(...) — see texture.

Source

pub fn with_texture_array( self, name: &'static str, handle: Handle<TextureArray>, ) -> Self

Value-only counterpart to .texture_array(...) — see texture.

Source

pub fn with_cubemap(self, name: &'static str, handle: Handle<Cubemap>) -> Self

Value-only counterpart to .cubemap(...) — see texture.

Source

pub fn with_texture_view(self, name: &'static str, view: TextureView) -> Self

Binds an already-built TextureView directly — e.g. one mip level from GPUTexture::get_view, or a standalone render target from Texture::empty. Unlike .with_texture/.with_texture_array/.with_cubemap, no Handle lookup happens at upload time — view must already exist.

Source

pub fn with_sampler(self, name: &'static str, kind: SamplerKind) -> Self

Value-only counterpart to .sampler(...) — see texture.

Source

pub fn with_uniform(self, name: &'static str, data: Vec<u8>) -> Self

Value-only counterpart to .uniform(...) — see texture.

Source

pub fn with_storage(self, name: &'static str, data: Vec<u8>) -> Self

Value-only counterpart to .storage(...) — see texture.

Source

pub fn with_uniform_value<T>(self, name: &'static str, value: &T) -> Self
where T: ShaderType + WriteInto,

Same as with_uniform, but takes a typed value instead of pre-packed bytes — uses encase to lay it out with correct WGSL uniform (std140) alignment. Value-only counterpart to .uniform_value(...).

Source

pub fn with_storage_value<T>(self, name: &'static str, value: &T) -> Self
where T: ShaderType + WriteInto,

Same as with_storage, but takes a typed value instead of pre-packed bytes — uses encase to lay it out with correct WGSL storage (std430) alignment. Value-only counterpart to .storage_value(...).

Source

pub fn texture(self, name: &'static str, handle: Handle<Texture>) -> Self

Declares a compute-visible texture_2d<f32> entry at the next auto-assigned binding index and binds handle to it — the streamlined one-call form of .with_entry(name, BindingKind::texture_2d(COMPUTE)) followed by .with_texture(name, handle). Reach for those two directly for a non-default sample type or an explicit binding index — visibility is always COMPUTE for a compute pass, so there’s no visibility to override here.

Source

pub fn texture_array( self, name: &'static str, handle: Handle<TextureArray>, ) -> Self

Streamlined form of .texture_array(...) — see texture.

Source

pub fn cubemap(self, name: &'static str, handle: Handle<Cubemap>) -> Self

Streamlined form of .cubemap(...) — see texture.

Source

pub fn sampler(self, name: &'static str, kind: SamplerKind) -> Self

Streamlined form of .sampler(...) — see texture.

Source

pub fn uniform(self, name: &'static str, data: Vec<u8>) -> Self

Streamlined form of .uniform(...) — see texture.

Source

pub fn storage(self, name: &'static str, data: Vec<u8>) -> Self

Streamlined form of .storage(...) (read-write — a compute pass binding a storage buffer usually means to write it) — see texture. Use .with_entry(...) + .with_storage(...) directly for a read-only one.

Source

pub fn uniform_value<T>(self, name: &'static str, value: &T) -> Self
where T: ShaderType + WriteInto,

Streamlined, typed form of .uniform(...) — declares the entry and binds an encase-laid-out value in one call. See texture.

Source

pub fn storage_value<T>(self, name: &'static str, value: &T) -> Self
where T: ShaderType + WriteInto,

Streamlined, typed form of .storage(...) (read-write) — see storage.

Source

pub fn with_buffer(self, name: &'static str, buffer: Buffer) -> Self

Binds an existing Buffer instead of uploading raw bytes — for a buffer another pass already wrote to. Unlike .with_uniform/ .with_storage, no buffer is created here; buffer must already carry the usage flags this binding needs.

Source

pub fn with_dynamic_buffer( self, name: &'static str, buffer: DynamicBuffer, ) -> Self

Binds an existing DynamicBuffer — the dynamic-offset counterpart to .with_buffer.

Source

pub fn with_param(self, name: &'static str, entry: BindingValue) -> Self

Source

pub fn build_asset( self, name: &str, assets: &mut Assets<Compute>, ) -> Handle<Compute>

Trait Implementations§

Source§

impl Asset<Backend> for Compute

Source§

type Deps<'a> = (Read<'a, GlobalLayoutPool>, Read<'a, ComputePipelineCache>, Read<'a, Assets<Texture>>, Read<'a, Assets<TextureArray>>, Read<'a, Assets<Cubemap>>, Read<'a, GlobalSamplers>)

Source§

fn upload<'a>( &self, backend: &Backend, deps: &Self::Deps<'a>, ) -> Option<GPUCompute>

Source§

impl AssetSource for Compute

Source§

impl Default for Compute

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Component for T
where T: Send + Sync + 'static,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

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