pub struct ComputeBundle<B = BindGroup> { /* private fields */ }Expand description
A bundle of wgpu::ComputePipeline, its wgpu::BindGroupLayout
and optionally wgpu::BindGroup.
§Overview
This is an abstraction of a compute pipeline with its associated resources, so that any compute operations can be easily setup and dispatched.
It is recommended to use ComputeBundleBuilder to create a compute bundle
§Shader Format
The compute shader is suggested to be in the following form:
override workgroup_size: u32;
@compute @workgroup_size(workgroup_size)
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
let index = id.x;
if index >= arrayLength(&data) {
return;
}
// Do something with `data[index]`
}workgroup_sizeis an overridable variable of typeu32.- The entry point function (here
main) must have the@computeattribute and a@workgroup_size(workgroup_size)attribute. - The entry point function is suggested to have a parameter with
@builtin(global_invocation_id)attribute to get the global invocation ID for indexing into the data.
Implementations§
Source§impl<B> ComputeBundle<B>
impl<B> ComputeBundle<B>
Sourcepub fn create_bind_group<'a>(
&self,
device: &Device,
index: usize,
resources: impl IntoIterator<Item = BindingResource<'a>>,
) -> Option<BindGroup>
pub fn create_bind_group<'a>( &self, device: &Device, index: usize, resources: impl IntoIterator<Item = BindingResource<'a>>, ) -> Option<BindGroup>
Create the bind group at the given index.
index refers to the index in ComputeBundle::bind_group_layouts.
Returns None if the index is out of bounds.
As a good practice, if you are designing API for others to use, do not let the user create bind groups manually as they will have to make sure the binding resources match the layout.
Sourcepub fn workgroup_size(&self) -> u32
pub fn workgroup_size(&self) -> u32
Get the number of invocations in one workgroup.
Sourcepub fn bind_group_layouts(&self) -> &[BindGroupLayout]
pub fn bind_group_layouts(&self) -> &[BindGroupLayout]
Get the bind group layouts.
This corresponds to the bind_group_layout_descriptors provided
when creating the compute bundle.
Sourcepub fn pipeline(&self) -> &ComputePipeline
pub fn pipeline(&self) -> &ComputePipeline
Get the compute pipeline.
Sourcepub fn dispatch_with_bind_groups<'a>(
&self,
encoder: &mut CommandEncoder,
bind_groups: impl IntoIterator<Item = &'a BindGroup>,
count: u32,
)
pub fn dispatch_with_bind_groups<'a>( &self, encoder: &mut CommandEncoder, bind_groups: impl IntoIterator<Item = &'a BindGroup>, count: u32, )
Dispatch the compute bundle for count instances with provided bind group.
Each bind group in bind_groups corresponds to the bind group layout
at the same index in ComputeBundle::bind_group_layouts.
Source§impl ComputeBundle
impl ComputeBundle
Sourcepub fn new<'a, 'b>(
label: Option<&str>,
device: &Device,
bind_group_layout_descriptors: impl IntoIterator<Item = &'a BindGroupLayoutDescriptor<'a>>,
resources: impl IntoIterator<Item = impl IntoIterator<Item = BindingResource<'a>>>,
compilation_options: PipelineCompilationOptions<'_>,
shader_source: ShaderSource<'_>,
entry_point: &str,
workgroup_size: Option<u32>,
) -> Result<Self, ComputeBundleCreateError>
pub fn new<'a, 'b>( label: Option<&str>, device: &Device, bind_group_layout_descriptors: impl IntoIterator<Item = &'a BindGroupLayoutDescriptor<'a>>, resources: impl IntoIterator<Item = impl IntoIterator<Item = BindingResource<'a>>>, compilation_options: PipelineCompilationOptions<'_>, shader_source: ShaderSource<'_>, entry_point: &str, workgroup_size: Option<u32>, ) -> Result<Self, ComputeBundleCreateError>
Create a new compute bundle.
shader_source requires an overridable variable workgroup_size of u32, see docs of
ComputeBundle.
Sourcepub fn bind_groups(&self) -> &[BindGroup]
pub fn bind_groups(&self) -> &[BindGroup]
Get the bind groups.
Sourcepub fn dispatch(&self, encoder: &mut CommandEncoder, count: u32)
pub fn dispatch(&self, encoder: &mut CommandEncoder, count: u32)
Dispatch the compute bundle for count instances.
Sourcepub fn update_bind_group(
&mut self,
index: usize,
bind_group: BindGroup,
) -> Option<BindGroup>
pub fn update_bind_group( &mut self, index: usize, bind_group: BindGroup, ) -> Option<BindGroup>
Sourcepub fn update_bind_group_with_binding_resources<'a>(
&mut self,
device: &Device,
index: usize,
resources: impl IntoIterator<Item = BindingResource<'a>>,
) -> Option<BindGroup>
pub fn update_bind_group_with_binding_resources<'a>( &mut self, device: &Device, index: usize, resources: impl IntoIterator<Item = BindingResource<'a>>, ) -> Option<BindGroup>
Source§impl ComputeBundle<()>
impl ComputeBundle<()>
Sourcepub fn new_without_bind_groups<'a>(
label: Option<&str>,
device: &Device,
bind_group_layout_descriptors: impl IntoIterator<Item = &'a BindGroupLayoutDescriptor<'a>>,
compilation_options: PipelineCompilationOptions<'_>,
shader_source: ShaderSource<'_>,
entry_point: &str,
workgroup_size: Option<u32>,
) -> Result<Self, ComputeBundleCreateError>
pub fn new_without_bind_groups<'a>( label: Option<&str>, device: &Device, bind_group_layout_descriptors: impl IntoIterator<Item = &'a BindGroupLayoutDescriptor<'a>>, compilation_options: PipelineCompilationOptions<'_>, shader_source: ShaderSource<'_>, entry_point: &str, workgroup_size: Option<u32>, ) -> Result<Self, ComputeBundleCreateError>
Create a new compute bundle without internally managed bind group.
To create a bind group with layout matched to one of the layout in this compute bundle,
use the ComputeBundle::create_bind_group method.
Sourcepub fn dispatch<'a>(
&self,
encoder: &mut CommandEncoder,
count: u32,
bind_groups: impl IntoIterator<Item = &'a BindGroup>,
)
pub fn dispatch<'a>( &self, encoder: &mut CommandEncoder, count: u32, bind_groups: impl IntoIterator<Item = &'a BindGroup>, )
Dispatch the compute bundle for count instances.
Trait Implementations§
Source§impl<B: Clone> Clone for ComputeBundle<B>
impl<B: Clone> Clone for ComputeBundle<B>
Source§fn clone(&self) -> ComputeBundle<B>
fn clone(&self) -> ComputeBundle<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<B> Freeze for ComputeBundle<B>
impl<B = BindGroup> !RefUnwindSafe for ComputeBundle<B>
impl<B> Send for ComputeBundle<B>where
B: Send,
impl<B> Sync for ComputeBundle<B>where
B: Sync,
impl<B> Unpin for ComputeBundle<B>where
B: Unpin,
impl<B = BindGroup> !UnwindSafe for ComputeBundle<B>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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