Create a compute instance. Note that this is supported on WebGPU only and is a no-op on other platforms.
The graphics device.
The compute shader.
Optionalname: string = 'Unnamed'The name of the compute instance, used for debugging only.
Deletes a shader parameter from the compute instance.
The name of the parameter to delete.
Returns the value of a shader parameter from the compute instance.
The name of the parameter to get.
The value of the specified parameter.
Sets a shader parameter on a compute instance.
The name of the parameter to set.
The value for the specified parameter.
Prepare the compute work dispatch.
X dimension of the grid of work-groups to dispatch.
Optionaly: numberY dimension of the grid of work-groups to dispatch.
Optionalz: numberZ dimension of the grid of work-groups to dispatch.
Prepare the compute work dispatch to use indirect parameters from a buffer. The dispatch parameters (x, y, z workgroup counts) are read from the buffer at the specified slot index.
When using the device's built-in buffer (buffer parameter is null), this method must be called each frame as slots are only valid for the current frame.
Slot index in the indirect dispatch buffer. When using the device's built-in buffer, obtain this by calling GraphicsDevice#getIndirectDispatchSlot.
Optionalbuffer: StorageBuffer | null = nullOptional custom storage buffer containing dispatch parameters. If not provided, uses the device's built-in GraphicsDevice#indirectDispatchBuffer. When providing a custom buffer, the user is responsible for its lifetime and contents.
// Reserve a slot in the indirect dispatch buffer
const slot = device.getIndirectDispatchSlot();
// First compute shader writes dispatch parameters to the buffer
prepareCompute.setParameter('indirectBuffer', device.indirectDispatchBuffer);
prepareCompute.setParameter('slot', slot);
prepareCompute.setupDispatch(1, 1, 1);
device.computeDispatch([prepareCompute]);
// Second compute shader uses indirect dispatch
processCompute.setupIndirectDispatch(slot);
device.computeDispatch([processCompute]);
A representation of a compute shader with the associated resources, that can be executed on the GPU. Only supported on WebGPU platform.