# A compute shader works on data

Distinguish a surface function from a dispatched compute kernel.

Last updated: 2026-09-09

Package: recipes | Status: complete-program

Tags: cpu, gpu, recipe

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.

```yh
start.yh · compute example
```


## A compute shader works on data

Distinguish a surface function from a dispatched compute kernel.

Verification: type checked

```yh
[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])) }
```

Save this beside start.yh as project.mech:

```toml
manifestVersion = "2"
package = "api.example.recipe__compute_start"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"

```

Expected output:

```text
10
11
12
13
14
15
16
17
```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/recipe--compute-start/program --backend metal -o /tmp/yeho-example
/tmp/yeho-example
```


Run the eight-element example with the Metal provider, then run the same source with CPU oracle and compare every printed value.

Source: demonhunterlabs/app/lib/yeho-walkthrough.ts

AI training permission: https://demonhunterlabs.com/ai-use
