Skip to content

Conversation

@mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Jan 5, 2026

Fixes #8000

Add indirect compute dispatch support for WebGPU

Adds support for indirect compute dispatch on WebGPU, allowing compute shaders to generate dispatch parameters for subsequent compute shaders. This enables GPU-driven workloads where the number of workgroups is determined dynamically on the GPU without CPU readback.

New Public API

This closely resembles existing indirect drawing API.

GraphicsDevice

Property/Method Description
maxIndirectDispatchCount Maximum number of indirect dispatch slots per frame (default: 256)
getIndirectDispatchSlot(count?) Reserve slot(s) in the indirect dispatch buffer for the current frame
indirectDispatchBuffer Storage buffer for indirect dispatch parameters (WebGPU only, null on other platforms)

Compute

Method Description
setupIndirectDispatch(slotIndex, buffer?) Configure compute to read dispatch parameters from a buffer

Usage

// 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]);## Technical Details
  • Each indirect dispatch slot contains 3 × 32-bit values (x, y, z workgroup counts)
  • Built-in buffer slots are frame-stamped and validated to ensure setupIndirectDispatch is called each frame
  • Custom storage buffers can be provided for complex scheduling outside rendering frames

Example

New indirect-dispatch example demonstrates depth-based edge detection:

  1. Scan shader analyzes depth buffer and classifies tiles by depth discontinuity
  2. Writes tile counts to indirect dispatch buffer
  3. Effect shaders are indirectly dispatched to process only the relevant tiles
Screenshot 2026-01-05 at 15 10 18

@mvaligursky mvaligursky self-assigned this Jan 5, 2026
@mvaligursky mvaligursky added enhancement Request for a new feature area: graphics Graphics related issue area: examples labels Jan 5, 2026
@mvaligursky mvaligursky requested a review from a team January 5, 2026 15:18
@mvaligursky mvaligursky merged commit 2afdf36 into main Jan 5, 2026
7 checks passed
@mvaligursky mvaligursky deleted the mv-indirect-dispatch branch January 5, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: examples area: graphics Graphics related issue enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for dispatchWorkgroupsIndirect on WebGPU

3 participants