compute.workgroupsFolded¶
Summary¶
compute.workgroupsFolded computes dispatch counts for a shader that can decode a flattened grid. It keeps ordinary counts when each axis fits the device limit and packs the logical workgroups across more physical axes when an axis would exceed the limit.
Syntax¶
workgroupsFolded(size: WorkgroupExtent, workgroupSize: WorkgroupExtent): WorkgroupCounts
// Standalone package export
workgroupsFolded(size: WorkgroupExtent, workgroupSize: WorkgroupExtent, maxWorkgroupsPerDimension?: number): WorkgroupCounts
const counts = wgpu.compute.workgroupsFolded(20_000_000, 256);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
size |
WorkgroupExtent |
Yes | Logical invocation counts along X, Y and Z. Each extent is a non-negative integer. |
workgroupSize |
WorkgroupExtent |
Yes | Positive integer sizes matching the shader and the rank of size. |
maxWorkgroupsPerDimension |
number |
No | Positive integer limit for the standalone function, default 65535. The instance method uses its device's limit. |
Returns¶
WorkgroupCounts - Physical dispatch counts [x, y, z]. An empty logical dimension yields [0, 1, 1]. An extent that cannot fit in the dispatch grid or exceeds 32-bit workgroup or invocation indexing throws.
Type Details¶
type WorkgroupExtent = number | readonly [number] | readonly [number, number] | readonly [number, number, number];
type WorkgroupCounts = readonly [number, number, number];
Example¶
import { workgroupsFolded } from "@zushah/wasmgpu";
console.log(workgroupsFolded([40, 3], [8, 1], 4)); // [4, 4, 1]
Notes¶
Linearize the physical workgroup ID as wid.x + nwg.x * (wid.y + nwg.y * wid.z) using num_workgroups for nwg. For 2D or 3D workloads, decode the linear ID in the logical grid using the original counts (ceiling division on each axis). Guard workgroups beyond the logical grid and invocations outside the requested extent.