workgroupId
In a compute shader, provides the unique 3D coordinate (ID) of the current workgroup within the entire dispatch grid.
Core Advantages
Its core advantage is enabling data partitioning. It allows each workgroup to use its unique ID to calculate the starting offset of the data subset it should process within a large data buffer (like a texture or array), which is fundamental for large-scale parallel computing.
Common Uses
Image processing (e.g., applying filters, generating fractals)
Large-scale particle system updates
3D grid or volumetric data computation (e.g., fluid simulation)
How to adjust
`workgroupId` itself is read-only and cannot be adjusted directly. Its value and range are determined by the dispatch dimension parameters in the CPU-side call to `compute(dispatchX, dispatchY, dispatchZ)`. By changing these dispatch counts, you control the number and arrangement of workgroups, thereby indirectly affecting the `workgroupId` values within the shader.
Code Examples
1const globalInvocationId = workgroupId.mul( workgroupSize ).add( localInvocationId );
2const index = globalInvocationId.x;
3
4// Use the unique index to precisely read from and write to buffers
5outputBuffer.element( index ).assign( inputBuffer.element( index ).mul( 2.0 ) );