recipes · recipe ·

A compute shader works on data

Distinguish a surface function from a dispatched compute kernel.

cpugpurecipe

Our surface examples answer a material question at a position. A compute shader performs work over data. It can fill an image, move particles, filter values, or support a simulation without drawing a triangle. Yeho calls the dispatched function a compute function. Each invocation receives a compute.index. A buffer holds the values the invocations read or write. We will first give every invocation one independent output element.

start.yh · compute example

Status: complete-program

A compute shader works on data

Distinguish a surface function from a dispatched compute kernel.

gpu · cpu · type checked

[auto]
compute Fill(buffer of int output)
{
    int index = compute.index
    if index >= output.count { return }
    output[index] = 10 + index
}

buffer of int output
output.Resize(8)
computeTask job = dispatch Fill(output)
wait job
if job.failed { Console.Error(job.error.message) Process.Exit(1) }
for index from 0 < output.count { Console.Log(Text.From(output[index])) }
project.mech
manifestVersion = "2"
package = "api.example.recipe__compute_start"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"
Expected output
10
11
12
13
14
15
16
17
Notes and source

Run the eight-element example with the Metal provider, then run the same source with CPU oracle and compare every printed value.

demonhunterlabs/app/lib/yeho-walkthrough.ts