pub struct IndirectDispatchBuffer { /* private fields */ }Expand description
A GPU buffer that holds one or more DispatchIndirectArgs slots for use
with wgpu::ComputePass::dispatch_workgroups_indirect.
Each slot occupies exactly 12 bytes (the size of one
DispatchIndirectArgs). The buffer is created with
INDIRECT | COPY_DST | STORAGE usages so it can both receive CPU-side
writes and be written by a preceding compute shader pass.
§Multi-slot layout
Offset 0 12 24 36 …
├──────┼──────┼──────┤
│ [0] │ [1] │ [2] │ …
└──────┴──────┴──────┘
12 B 12 B 12 BThe active slot for a dispatch is selected via IndirectDispatchBuffer::offset
(defaults to slot 0) and can be overridden by calling
IndirectDispatchBuffer::update_at to write to a specific slot and then
constructing a view with the desired byte offset — or by creating separate
buffers for each independently-driven dispatch.
Implementations§
Source§impl IndirectDispatchBuffer
impl IndirectDispatchBuffer
Sourcepub fn new(ctx: &GpuContext, args: DispatchIndirectArgs) -> GpuResult<Self>
pub fn new(ctx: &GpuContext, args: DispatchIndirectArgs) -> GpuResult<Self>
Create a single-slot indirect dispatch buffer initialised with args.
The buffer is 12 bytes and supports INDIRECT | COPY_DST | STORAGE
usages.
§Errors
Returns GpuError::InvalidKernelParams if the device rejects the
buffer descriptor (should not happen in practice).
Sourcepub fn new_with_capacity(
ctx: &GpuContext,
max_dispatches: u32,
) -> GpuResult<Self>
pub fn new_with_capacity( ctx: &GpuContext, max_dispatches: u32, ) -> GpuResult<Self>
Create a multi-slot indirect dispatch buffer with max_dispatches
slots, all initialised to zero.
The total buffer size is 12 * max_dispatches bytes. Each slot can be
written individually via IndirectDispatchBuffer::update_at.
§Errors
Returns GpuError::InvalidKernelParams if max_dispatches is 0.
Sourcepub fn update(&self, ctx: &GpuContext, args: DispatchIndirectArgs)
pub fn update(&self, ctx: &GpuContext, args: DispatchIndirectArgs)
Overwrite slot 0 with new dispatch arguments.
This is a CPU-side write using queue.write_buffer; the data is
uploaded before the next queue.submit.
Sourcepub fn update_at(
&self,
ctx: &GpuContext,
slot_idx: u32,
args: DispatchIndirectArgs,
) -> GpuResult<()>
pub fn update_at( &self, ctx: &GpuContext, slot_idx: u32, args: DispatchIndirectArgs, ) -> GpuResult<()>
Overwrite a specific slot (0-indexed) with new dispatch arguments.
§Errors
Returns GpuError::InvalidKernelParams if slot_idx >= capacity.
Sourcepub fn buffer(&self) -> &Buffer
pub fn buffer(&self) -> &Buffer
Return a reference to the underlying wgpu::Buffer.
Sourcepub fn offset(&self) -> BufferAddress
pub fn offset(&self) -> BufferAddress
Return the byte offset of slot 0 within the buffer.
This is the value passed as the second argument to
ComputePass::dispatch_workgroups_indirect.