Compute Shaders
Compute shaders are a special type of shader that allow you to dispatch work in a non-drawing context. You can use compute shaders to do things like:
- Generate meshes
- Generate textures
- Do physics calculations
- Do AI calculations
- Do any other kind of calculation that can be parallelized
compute(groupCount: int3, shd: shader)
Compute shaders are dispatched by providing a group count and a shader.
The group count defines how many groups of threads will be dispatched. Each group has a size of threads defined in the shader block (shader <16, 16, 1>
will have 16x16x1 threads per group).
In other words:
If we define a shader with: shader<16, 16, 1>
, and call compute((2, 1, 1), shader <16, 16, 1> { ... })
:
- 16x16x1 threads will be dispatched in the first group on the x axis
- 16x16x1 threads will be dispatched in the second group on the x axis