Game dev
Saved & recent

Compute shader

Related terms: GPGPU, GPU compute

A shader that is not tied to drawing. It reads and writes plain buffers and textures, running the same small program on thousands of items at once.

It suits any job made of many independent pieces: particles, cloth, crowd movement, culling, terrain generation. A CPU has a few fast cores. A GPU has thousands of simple ones.

Further reading
Khronos: Vulkan compute shader tutorial
0 (0, 0) (1, 1) 0 (1, 1) 1 (1, 3) (1, −1) 1 (2, 2) 2 (2, 1) (0, 2) 2 (2, 3) 3 (4, 2) (−1, 0) 3 (3, 2) 4 (1, 0) (2, 0) 4 (3, 0) 5 (3, 4) (1, −1) 5 (4, 3) 6 (4, 0) (−1, 1) 6 (3, 1) 7 (0, 4) (1, 0) 7 (1, 4) 0 1 2 3 4 5 6 7 position velocity workgroup new position input records invocation output buffer
Two workgroups of four invocations update eight particle positions using p′ = p + vΔt and Δt = 1 s. Positions are in meters and velocities in m/s. Each global ID writes one output; this dispatch needs no padding. Many invocations can run in parallel, without a guaranteed execution order.

View in the full Game dev collection