{"id":"recipe--compute-start","name":"A compute shader works on data","owner":"yeho","package":"recipes","kind":"recipe","signature":"start.yh · compute example","description":"Distinguish a surface function from a dispatched compute kernel.","context":"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.","parameters":[],"returns":"","members":[],"tags":["cpu","gpu","recipe"],"updated":"2026-09-09","source":{"repository":"demonhunterlabs","path":"app/lib/yeho-walkthrough.ts"},"status":"complete-program","notes":["Run the eight-element example with the Metal provider, then run the same source with CPU oracle and compare every printed value."],"examples":[{"id":"program","title":"A compute shader works on data","description":"Distinguish a surface function from a dispatched compute kernel.","code":"[auto]\ncompute Fill(buffer of int output)\n{\n    int index = compute.index\n    if index >= output.count { return }\n    output[index] = 10 + index\n}\n\nbuffer of int output\noutput.Resize(8)\ncomputeTask job = dispatch Fill(output)\nwait job\nif job.failed { Console.Error(job.error.message) Process.Exit(1) }\nfor index from 0 < output.count { Console.Log(Text.From(output[index])) }","manifest":"manifestVersion = \"2\"\npackage = \"api.example.recipe__compute_start\"\nversion = \"0.1.0\"\nlanguageEdition = \"yeho-core-2026.1\"\n\n[app]\nkind = \"headless\"\n","tags":["gpu","cpu"],"run":"metal","expected":"10\n11\n12\n13\n14\n15\n16\n17","verification":"type checked","sha256":"0ea4d53982f10c2b2d929b4bd53beef70b339a5a577698134e9366bd1466275a","checked":"2026-09-09","diagnostic":"","observedOutput":null,"checkedBackend":null}],"searchTerms":[],"url":"https://demonhunterlabs.com/academy/api?item=recipe--compute-start","json":"https://demonhunterlabs.com/reference/items/recipe--compute-start.json","markdown":"https://demonhunterlabs.com/reference/text/recipe--compute-start.md"}
