Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·originates fromworld 07158574-5…

compute

Public Luau surface over the `__compute` Internal FFI namespace — GPU compute pipelines.

byzero-proxy @ DESKTOP-DB3UJOJ·posted 4mo ago
What it does

compute Module

Public Luau surface over the __compute Internal FFI namespace — GPU compute pipelines.

Purpose

A compute shader is a .computeShader asset, and everything you do with one you do through a resolved reference to it. The asset owns its compiled program: the compile the reference asks for registers it, and removing the asset releases it. This module carries what the reference does not: the readback poll, the health reads, the GPU textures and samplers a dispatch binds by name, and the scene BVH.

Usage

local double = asset.resolve("@builtin::shaders.compute_double", "computeShader")

local scratch = double:createBuffer("data", { type = "f32", len = 64, usage = { "readback" } })
scratch:write({ 1.0, 2.0, 3.0, 4.0 })

double:dispatch({ buffers = { scratch }, workgroups = { 1, 1, 1 } })

local read = scratch:read(0, 16)
while not read:ready() do task.wait(0) end
local floats = read:result()

asset.resolve records your script's dependency on the shader — which is what carries the shader along when the world is packed, pulled or published.

Is it compiled yet?

compute.programState(ref) says where a shader's compiled program stands: "absent" (nothing held under this key and nothing in flight), "pending" (a registration or compile was asked for and has not reached the device — a recompile of a resident program reads pending too), "ready" (compiled and resident, so a dispatch binds it), or "failed", with the reason as a second return.

if compute.programState(shaderRef) == "ready" then
    shaderRef:dispatch({ buffers = { buf }, workgroups = { 1 } })
end

ref:compile() queues the compile and the pipeline is built on the render side frames later, so that call cannot answer this. A dispatch issued before the program is ready is held behind the compile and dropped if it never lands, and a readback taken then reports the buffer as it was.

Is anything broken?

compute.failing() lists every (shader, target) pair whose most recent dispatch failed, with the reason. An empty result means every dispatch the engine has been given is running. For one shader, ref:status() reports each of its targets, running or not.

for _, d in ipairs(compute.failing()) do
    print(d.shader, d.target, d.failures, d.lastError)
end

A dispatch is recorded into a command encoder frames after the call that asked for it returned, so the call answers that it queued the dispatch and these two answer what the dispatch did. A zero in any workgroups dimension is one of the things they report: it is refused, and a count computed from how much data there is passes through math.max(1, ...) so an empty set dispatches one workgroup rather than none.

Exports

  • Compute lists: list(key, entries), runList(key, slots?, label?), dropList(key). A list is an ordered run of dispatches (over buffers or typed resources) and buffer writes registered once and queued whole by one runList call, each value a run supplies named as a slot; see "Many dispatches as one call" in types/computeShader.
  • Health: programState, failing.
  • Readback: isReadbackReady, readbackState, getReadbackResult, getReadbackResultU32, getReadbackResultBytes. A handle answers a read itself — buf:read(offset, len) gives a Readback with ready, state and the three drains on it.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

global compute global-types module compute GPU compute pipelines — compile shaders, dispatch workgroups, read back results. Public Luau surface over the `__compute` Internal FFI namespace. A buffer belongs to the shader that owns it (`shaderRef:createBuffer`) or to the substrate (`substrate.createBuffer`), and reaches a dispatch as a handle. require modules/api/engine/compute

bufferKey(v: any, where: string, slot: string) → any

The key a `buffers` / `resources` entry names. A buffer handle contributes the name it was created under; a string passes through, which is how the engine-owned names (`@vertex`, `@vertex:<guid>`) reach the engine untouched.

argtypedescription
vany
wherestring
slotstring

countDispatches(n: number) → void

argtypedescription
nnumber

resolveBuffers(opts: any, where: string) → any

Resolve every buffer a dispatch names, leaving the caller's table untouched.

argtypedescription
optsany
wherestring

resolveComputeKey(ref: string | { [string]: any } | AssetRef) → any

The key the engine holds a shader's program under. For a `.computeShader` ASSET (identity string or a resolved handle) that is its stable guid, the key the assetType registers the compiled program under; a key `compute.program.compile` registered passes through unchanged.

argtypedescription
refstring | { [string]: any } | AssetRef

refusedDeclaration(ref: string | { [string]: any } | AssetRef) → string

Why the `bindings.yaml` of the `.computeShader` asset `ref` names was not read, when its compile refuses the file; nil for any other ref. The asset's `getBindings` runs the parse its compile runs, so it raises exactly when the compile refuses the declaration.

argtypedescription
refstring | { [string]: any } | AssetRef

holdInline(key: string, register: (string, any) → void

argtypedescription
keystring
register(string, any

programCaller( ) → string

suiteOwned(source: string) → boolean

Whether the chunk `source` names is a test suite's own, or user code: a compiled program that goes back with the world.

argtypedescription
sourcestring

buildBvh(instances: { any }, opts: { [string]: any }?) →

Build a bounding-volume hierarchy over the world-space triangles of a set of mesh instances and upload it as two named compute buffers — geometry never passes through the scripting heap. Each instance is `{ guid, transform, attributes? }`: `guid` names a mesh resident in the meshcpu store (materialise with `ref:load()` / `meshcpu.load`), `transform` is 16 numbers, row-major, translation in slots 4/8/12, and `attributes` is up to 40 floats stamped onto every triangle of that instance (surface colors, material ids, physics tags — whatever the consuming shader wants per-surface). Triangles pack 18 vec4 each (v0/v1/v2, n0/n1/n2, uvs, then 10 attribute vec4s — float slots 32.. carry the instance attributes, zero when absent) in BVH leaf order; nodes 2 vec4 each (min + first-or-left, max + leaf-tagged count-or-right). The triangle buffer is bound whole by the passes that trace it, so a scene whose triangle records pass the smaller of `renderer.deviceLimits().maxBufferBytes` and `maxStorageBindingBytes` is refused before anything is copied, the error naming the triangle count and the most this device holds. With `leaveOut = true` such a scene is built instead from the instances in the order given while their records fit, and each instance past that is left out whole before anything is copied, so a caller that names the instances most worth tracing first (the nearest a camera, say) keeps those. The most host memory the build holds at once (the gathered triangles beside the mesh copies, or beside the split order and nodes) is set aside before anything is copied, and a scene the engine has no memory left for (a browser engine's 4 GiB of linear memory, say) is refused with the MiB it needs and the MiB there is. Consumers: GI baking, ray-traced passes, GPU picking, navmesh and SDF generation. whether a scene too large for the device is built from the instances that fit rather than refused. trianglesLeftOut }` — `nodes` and `tris` are buffer handles the caller owns, passed to a dispatch like any other and destroyed when the hierarchy is done with; the last two count what `leaveOut` left out (0 when the scene fits). Or `(nil, err)` naming any non-resident guid, a scene too large for the device, or one too large for the memory left.

argtypedescription
instances{ any }Array of `{ guid, transform, attributes? }` mesh instances.
opts{ [string]: any }?Optional `{ maxLeaf?, leaveOut? }` — max triangles per leaf, and

examples

local bvh = compute.buildBvh(instances)
asset.resolve("raytrace", "computeShader"):dispatch({ buffers = { bvh.nodes, bvh.tris }, workgroups = { 64, 1, 1 } })

beginBvh(instances: { any }, opts: { [string]: any }?) →

Start the build `compute.buildBvh` runs, without running any of it. Takes the same instances and options and reports the same non-resident guids, and returns an id `compute.stepBvh` advances a bounded slice at a time and `compute.finishBvh` collects. Each mesh the instances name is copied as this is called — once per guid however many instances share it — so the CPU mesh may be unloaded on the next line and the build still finishes on the copy it holds. A scene too large for the device is refused here, before anything is copied, or with `leaveOut` built from the instances that fit, as `compute.buildBvh` builds it, and a scene the engine has no memory left for is refused here too. The host memory a build holds is the `compute.bvhBuilds` source of `memory.report()`, and leaving the world ends every build in flight, so a later `stepBvh` or `finishBvh` naming its id answers that it ended and why. `compute.buildBvhSliced` is the whole loop as one call. scene too large for the device, or one too large for the memory left.

argtypedescription
instances{ any }Array of `{ guid, transform, attributes? }` mesh instances.
opts{ [string]: any }?Optional `{ maxLeaf?, leaveOut? }`, as `compute.buildBvh` takes them.

examples

local id = compute.beginBvh(gather.instances)

stepBvh(id: number, budgetMs: number?) →

Advance a build by as many work units as `budgetMs` buys, and report whether it has finished: `"pending"` means there is work left, `"ready"` means `compute.finishBvh` will hand over the buffers, or answer why the build ended without them. The slices carry the hierarchy onto the GPU as well as building it, so a build that reads `"ready"` has already uploaded every byte of itself. A slice always runs at least one unit, so a budget of 0 advances the build by exactly one and the largest single unit sets the floor under a slice. (naming why when the engine ended it).

argtypedescription
idnumberBuild id from `compute.beginBvh`.
budgetMsnumber?Wall time this slice may spend, in milliseconds (default 4).

examples

while compute.stepBvh(id, 4) == "pending" do task.wait() end

finishBvh(id: number) →

Hand over a finished build's hierarchy as the same two buffers `compute.buildBvh` returns, and release the build. The slices put every byte of it on the GPU as they ran, so this costs the frame it is called in the handover and nothing of the scene. trianglesLeftOut }`, or `(nil, err)` when the id names no build, the build still has work left, or it ended with no hierarchy: naming the block of memory its split order or nodes could not be given, or the GPU buffers it could not open or write.

argtypedescription
idnumberBuild id from `compute.beginBvh`, stepped until `"ready"`.

examples

local built = compute.finishBvh(id)

cancelBvh(id: number) → boolean

Drop a build along with the triangles it has gathered.

argtypedescription
idnumberBuild id from `compute.beginBvh`.

examples

compute.cancelBvh(id)

bvhBuilds( ) →

What the builds started by `compute.beginBvh` and not yet finished are costing, oldest id first. Each row is `{ id, phase, triangles, units, slices, cpuMs, uploadedBytes, heldBytes }`: `phase` is `"gather"`, `"build"`, `"upload"` or `"ready"`, `triangles` how many have been gathered, `units` the work units run, `slices` the `compute.stepBvh` calls they ran in, `cpuMs` the wall time spent inside those calls, `uploadedBytes` how much of the hierarchy has reached the GPU, and `heldBytes` the host memory the build holds now, which `memory.report()` counts under `compute.bvhBuilds`.

examples

print(#compute.bvhBuilds(), "hierarchies in flight")

buildBvhSliced(instances: { any }, opts: { [string]: any }?) →

The hierarchy `compute.buildBvh` builds, spread over as many frames as it takes: a slice of the build per frame, so a scene's triangle count costs the frame loop `budgetMs` at a time instead of the whole build at once. Yields, so it is called from a task. The result is the same pair of buffers and the same counts `compute.buildBvh` returns. leaf, `leaveOut` as `compute.buildBvh` takes it, and the wall time one frame may spend on the build (default 4 ms). trianglesLeftOut }`, or `(nil, err)`.

argtypedescription
instances{ any }Array of `{ guid, transform, attributes? }` mesh instances.
opts{ [string]: any }?Optional `{ maxLeaf?, leaveOut?, budgetMs? }` — max triangles per

examples

local built, err = compute.buildBvhSliced(gather.instances, { budgetMs = 4 })

isReadbackReady(resultKey: string) → boolean

Check if a readback result is available without consuming it. Raises for a key this engine never issued, or whose result was already drained — `nil`/`false` already means "still in flight", so a mistyped key reports itself instead of polling forever. Use `readbackState()` to test that case without raising.

argtypedescription
resultKeystringThe `key` of the Readback `buf:read(offset, len)` returned.

readbackState(resultKey: string) → string

Where a readback key stands, without consuming it and without raising: `"pending"` (issued, GPU has not delivered), `"ready"` (delivered, waiting to be drained), `"failed"` (given up on, with the reason as a second return), or `"unknown"` (never issued by a buffer read, or already drained — a result is delivered once). Every read leaves `"pending"`: one the GPU does not answer inside the bound the engine holds it to reaches `"failed"` naming the buffer. A wait on `readbackState(key) ~= "pending"` therefore ends on what the read did, which a count of engine frames cannot say.

argtypedescription
resultKeystringThe `key` of the Readback `buf:read(offset, len)` returned.

examples

if compute.readbackState(key) == "ready" then ... end

readbackPromise(resultKey: string) → any

The promise that settles when a read-back reaches a terminal state, delivered or given up on. `task.await` it to wait for the read without polling: where the engine can wait on the device the coroutine resumes in the frame the device answered, so a task that reads, uses the answer and reads again does all of it in one frame; elsewhere it resumes on the next frame the answer reaches the engine. Answers nil when the read-back is not in flight (already delivered, failed, drained or never issued), and `readbackState()` then says which.

argtypedescription
resultKeystringThe `key` of the Readback `buf:read(offset, len)` returned.

examples

local promise = compute.readbackPromise(key); if promise then task.await(promise) end

getReadbackResult(resultKey: string) →

Poll for a completed read-back and return its bytes as a 1-indexed array of f32 values, nil if pending. The f32 reinterpretation applies to whatever the buffer holds: bytes written as u32 `1, 2, 3, 4` read back here as `1.4e-45, 2.8e-45, 4.2e-45, 5.6e-45` — use `getReadbackResultU32()` for those, or `getReadbackResultBytes()` for a `buffer` the rest of the buffer surface accepts. Result is consumed on retrieval, and polling a key that was never issued raises rather than reading as forever-pending.

argtypedescription
resultKeystringThe `key` of the Readback `buf:read(offset, len)` returned.

examples

local floats = compute.getReadbackResult(key)

getReadbackResultU32(resultKey: string) →

Poll for a completed read-back interpreting bytes as u32. Returns array of integer values if ready, nil if pending.

argtypedescription
resultKeystringThe `key` of the Readback `buf:read(offset, len)` returned.

copyBufferToTexture(bufferName: string, textureKey: string, width: number, height: number, format: string?, rowBytes: number?) → boolean

Copy a compute buffer into a cached GPU texture under `textureKey`, staying on the GPU. The path for an image a compute pass produced: the buffer holds tightly-packed rows in the format's texel layout, and the result is an ordinary cached texture — sample it from a material, or pack it into the shared feature-texture array. The copy reads rows 256-byte aligned: rows packed tight must be a multiple of 256 bytes (at `rgba16f`, any width that is a multiple of 32), and any other width is laid out with its rows padded to that alignment and `rowBytes` saying how far apart they are. The key names a live texture from this call until `destroyTexture` releases it, so a material slot given the key in the same tick binds what the copy writes. A `shaderRef:dispatchEx` sampling the key, queued after the copy, samples what the copy wrote when no `dispatchEx` earlier in the same tick writes the buffer it copies. past `width` texels — a multiple of 256 at least a row's texels long.

argtypedescription
bufferNamestringSource compute buffer.
textureKeystringCache key to register the texture under.
widthnumberTexture width in texels.
heightnumberTexture height in texels.
formatstring?Texel format: `"rgba16f"` (default), `"rgba32f"`, `"rgba8"`.
rowBytesnumber?Bytes from one row's start to the next when rows are padded

examples

compute.copyBufferToTexture("gi_resolved", "lm_wall", 128, 128)
compute.copyBufferToTexture("heights_packed", "heights", 300, 300, "rgba16f", 2560)

destroyTexture(textureKey: string) → boolean

Release the cached GPU texture `copyBufferToTexture` registered under `textureKey`, freeing its memory. Call it once the image is no longer sampled. Writing the same key again replaces the texture, so a key you keep re-using holds one allocation. A release queued after a `shaderRef:dispatchEx` that samples the key runs once that dispatch has sampled it.

argtypedescription
textureKeystringCache key the texture was registered under.

examples

compute.destroyTexture("lm_wall")

getReadbackResultBytes(resultKey: string) → buffer

Poll for a completed read-back and get its raw bytes as a `buffer`, copied once. The read counterpart of `buf:writeBytes`: read values out with `buffer.readf32` / `buffer.readu32`, or hand the buffer straight to `buf:write` — a payload that stays packed never becomes a table. Result is consumed on retrieval.

argtypedescription
resultKeystringThe `key` of the Readback `buf:read(offset, len)` returned.

examples

local bytes = compute.getReadbackResultBytes(key)
local firstTexel = buffer.readf32(bytes, 0)

createTexture3D(name: string, opts: { [string]: any }) → boolean

Create a 3D texture volume. opts: `{ width, height, depth, format?, storage? }`. A device rebuild makes it again under its name, holding the voxels the CPU last wrote into it (`compute.writeTexture3D`, `compute.writeFloatsTexture3D`; up to 8 MiB a texture and 64 MiB across them) while no shader has bound it where the shader may write it, and empty otherwise.

argtypedescription
namestringUnique volume name.
opts{ [string]: any }Dimensions + format (`r8`/`r16f`/`r32f`/`r32u`/`rgba8`/`rgba16f`/`rgba32f`).

writeTexture3D(name: string, data: buffer | string | { number }) → boolean

Upload raw bytes (u8) into a named 3D volume. A `buffer` or a binary string holds the volume's byte layout verbatim and crosses in one copy — the shape a file's voxel payload arrives in; an array carries one byte value (0..255) per entry.

argtypedescription
namestringVolume name.
databuffer | string | { number }Voxel bytes as a `buffer`, a binary string, or an array of bytes.

writeFloatsTexture3D(name: string, floats: { number }, formatOrOpts: (string | { [string]: any }) → void

Upload float values into a named 3D volume, packed via the given format (default rgba16f).

argtypedescription
namestring
floats{ number }
formatOrOpts(string | { [string]: any }

readTexture3D(name: string) → string

Start a GPU→CPU readback of a named 3D volume. Returns a result key to poll.

argtypedescription
namestring

destroyTexture3D(name: string) → boolean

Destroy a named 3D volume and free its GPU memory.

argtypedescription
namestring

textureForPlugin(name: string) → any

The texture this script created under `name` as a handle a script passes a plugin in a call. The handle holds the texture by an id of its own, never by the name: once the texture is destroyed the handle refuses, even when the name is made again. Only a texture made by `compute.createTexture3D` or `compute.createStorageTexture2D` can be handed over. hidden

argtypedescription
namestringThe texture's name.

createStorageTexture2D(name: string, opts: { [string]: any }) → boolean

Create a 2D storage texture (compute-writable render target). opts: `{ width, height, format? }`.

argtypedescription
namestring
opts{ [string]: any }

destroyStorageTexture2D(name: string) → boolean

Destroy a named 2D storage texture.

argtypedescription
namestring

createTextureHistory(name: string, opts: { [string]: any }) → boolean

Create a temporal history buffer (ping-pong textures) for a target. opts: `{ width, height, format? }`.

argtypedescription
namestring
opts{ [string]: any }

destroyTextureHistory(name: string) → boolean

Destroy a named texture-history buffer.

argtypedescription
namestring

createSampler(name: string, opts: { [string]: any }?) → boolean

Create a named GPU sampler. opts: filter/wrap settings.

argtypedescription
namestring
opts{ [string]: any }?

destroySampler(name: string) → boolean

Release a named sampler created by `compute.createSampler` and free it. The counterpart to that call, alongside `destroyTexture`, `destroyTexture3D`, `destroyStorageTexture2D` and `destroyTextureHistory`. The manager's own defaults (`linear_clamp`, `linear_repeat`, `nearest_clamp`) are kept for the session, since a compute pass binds them by name.

argtypedescription
namestringSampler name.

examples

compute.createSampler("soft", { filter = true }); compute.destroySampler("soft")

assertResourceKinds(what: string, opts: { [string]: any }?) → void

argtypedescription
whatstring
opts{ [string]: any }?

resolveListEntries(entries: { { [string]: any } }, where: string) → void

A list is an ordered run of dispatches and buffer writes registered once and queued whole by one call, so work that issues many dispatches a frame (a solver step, a pyramid of passes) pays for one call rather than one per dispatch. The list `entries` states, every shader reference as the key it dispatches under and every handle as the name it binds by. The caller's tables stay as they were.

argtypedescription
entries{ { [string]: any } }
wherestring

list(key: string, entries: { { [string]: any } }) → boolean

Register a compute list under `key`, replacing one already there: an ordered run of dispatches and buffer writes that `compute.runList(key)` queues whole in one call. A step that issues many dispatches every frame (a solver's passes, the levels of a pyramid) registers its dispatches once and runs them with one call, so a frame pays for one call rather than one per dispatch. A list registered in a tick runs from that tick's next `runList`. A dispatch entry is `{ program, buffers, workgroups, params?, slots?, when? }`, binding buffers as `shaderRef:dispatch` does, or `{ program, resources, workgroups, params?, slots?, when? }`, binding textures, storage textures, samplers, history sides, buffers and the scene depth as `shaderRef:dispatchEx` does, each resource `{ kind, name }`. `program` is a `.computeShader` reference. A write entry is `{ write = buffer, offset?, values, unsigned?, slots?, when? }`: `offset` in 32-bit words, `values` written as f32 (u32 when `unsigned`). `slots` names the values a run supplies: on a dispatch it maps a `params:` name to a slot (`slots = { dt = "dt" }`), on a write a value's place, from 1, to a slot (`slots = { [4] = "dt" }`). `when` names a slot a run gives 0 to leave the entry out, so one list holds the variants a run picks from (the two parities of a ping-pong, say). Every other value is the one the entry holds. The entries run in the list's order, and runs in the order they were queued: a write lands after the dispatches before it and ahead of the ones after it. caller owns (a buffer's or texture's name) so two systems never share one. dispatch binds, a resource naming nothing, `buffers` and `resources` both given, a zero workgroup count) raises, naming the entry. { program = advect, resources = { { kind = "texture3d", name = velA }, { kind = "storage3d", name = velB } }, workgroups = { 16, 16, 16 } }, { program = project, resources = { { kind = "texture3d", name = velB }, { kind = "storage3d", name = velA } }, workgroups = { 16, 16, 16 } }, })

argtypedescription
keystringThe key the list is registered under. Name it from something the
entries{ { [string]: any } }The dispatches and writes, in the order they run.

examples

compute.list(key, {
compute.list(key, { { program = blur, buffers = { src, dst }, workgroups = { 64 }, slots = { radius = "radius" } } })

runList(key: string, slots: { [string]: number }?, label: string?) → boolean

Queue the compute list registered under `key` with `compute.list`: every entry in order, each value an entry names a slot for taken from `slots`, every other value as the list holds it. One call, whatever the number of dispatches the list holds. While the GPU profiler is read, a run of a list over buffers is timed as one pass, the `compute.list:<label>` row of the gpu report; the dispatches of a list over `resources` are timed as `dispatchEx` dispatches are. keeps and rewrites each run costs nothing to build. logs an error and queues nothing; what each dispatch then did is in `shaderRef:status()` and `compute.failing()`.

argtypedescription
keystringThe list's key.
slots{ [string]: number }?The value of each slot for this run, by name. A table the caller
labelstring?The name the run's GPU time is reported under; the list's key when absent.

examples

compute.runList(key, { dt = 1 / 60 })

dropList(key: string) → boolean

Forget the compute list registered under `key`, for a system that is torn down. A list that is registered again under its key replaces the one there, with no drop first.

argtypedescription
keystringThe list's key.

examples

compute.dropList(key)

textureFormatBytes(format: string) → number

Bytes-per-voxel for a texture format string (`rgba16f`, `r8`, ...).

argtypedescription
formatstring

failing( ) →

Every compute dispatch whose most recent run FAILED, one record per `(shader, target)` pair. A dispatch is recorded into a command encoder frames after the call that asked for it returned, so a pass that stops running reports here rather than through that call's return value: each record carries the shader key, the target it writes (a mesh guid for a dispatch over vertices, the buffers it bound for one that writes only those), how many dispatches and failures it has had, and `lastError`. An empty result means every dispatch the engine has been given is running. lastFailedFrame?, lastError? }`.

examples

for _, d in ipairs(compute.failing()) do print(d.shader, d.lastError) end

programState(ref: string | { [string]: any } | AssetRef) →

Where a shader's compiled program stands. A registration is queued from script and the pipeline is built on the render side frames later, so the call that asked for the compile cannot say whether it produced a program: `"absent"` (the engine holds nothing under this key and nothing is in flight — never asked for, or released), `"pending"` (asked for, not on the device yet — a recompile of a resident program reads pending too, because what it produces is a different program from the one bound now), `"ready"` (compiled and resident, so a dispatch binds it), or `"failed"` (the most recent registration produced no program), returned with the reason as a second value. A `.computeShader` whose `bindings.yaml` its compile refuses reads `"failed"`, with the reason naming the file and the line, because no program is compiled from the file as it stands. Wait for `"ready"` before a dispatch whose result is read back, rather than for a count of frames. or the key `compute.program.compile` registered a program under. when `"failed"`.

argtypedescription
refstring | { [string]: any } | AssetRefA `.computeShader` identity/guid string, a resolved asset handle,

examples

if compute.programState(carve) == "ready" then carve:dispatch(opts) end

programSource(key: string) → string

The chunk that compiled the program registered under `key`, as `debug.info` names a chunk: a module's identity, a test suite's, an `execute` body's. The record is the key's for as long as a program stands under it, across a device rebuilt underneath it. A variant the ABI module compiles answers for the chunk that asked for it. A `.computeShader` asset's program is keyed by the asset's guid and answers for the `.computeShader` assetType, which compiles it for the asset and releases it when the asset goes.

argtypedescription
keystringThe key the program was registered under.

examples

if compute.programSource("blur") then print("compiled under a key") end

withIncludedModulesFiled(spec: any) → any

The spec an inline program is queued with: each `#include` that names a `.shaderModule` rewritten to that module's guid, and the module filed with the text the VFS serves for it now. The engine expands each `#include` from the modules filed at the moment the program is queued, so a program generated at runtime files the modules it names here, the way a shader asset's type files the ones its source names. An include naming an engine framework module reaches the expander as written.

argtypedescription
specany

listEntry(key: string, opts: { [string]: any }) → void

A dispatch as a compute list entry: its program, the names of the buffers it binds, its workgroups as three counts, and a copy of its params.

argtypedescription
keystring
opts{ [string]: any }

compile(key: string, spec: { [string]: any }) →

Register a compiled program under `key` from WGSL plus a declared binding schema. Each `#include` of the source that names a `.shaderModule` absolutely (a guid, an identity, an `@root::` or `@builtin::` path) reaches the compiler as that module's guid, with the module filed first from the text the VFS serves for it now. The engine then generates the `@group`/`@binding` declarations from the schema, expands the `#include`s, naga-validates, and registers the result. schema. A buffer binding stating `range = true` (or every array buffer binding, with `ranges = true`) takes a range of a buffer: a dispatch binds it with `zero_base_NAME` / `zero_len_NAME` in its params, and the body's `NAME[i]` and `arrayLength(&NAME)` address that range. One that states no range binds the whole buffer. when the schema or the module is one the device would refuse. hidden

argtypedescription
keystringThe key to register under.
spec{ [string]: any }`{ source, entryPoint?, bindings, params, ranges? }` — the parsed

destroy(key: string) → boolean

Release the program registered under `key`. hidden

argtypedescription
keystringThe program's key.

registered(key: string) → boolean

Whether a program compiled under `key` by `compute.program.compile` is still registered: false once it was destroyed by `compute.program.destroy` or closed by `compute.resetToBaseline`, and for a key nothing compiled. A table read, so a caller that keeps a program's name between uses can ask before every use instead of asking the engine; the device registers the program again after a rebuild. hidden

argtypedescription
keystringThe program's key.

examples

if not compute.program.registered(key) then compute.program.compile(key, spec) end

spec(key: string) →

The spec the program under `key` was compiled from (`compute.program.compile`): `{ source, entryPoint, bindings, params, ranges, ... }` as it was filed, each `#include` naming the module it reached. Compiling it under the same key in another engine makes the same program. A copy; nil for a key nothing compiled from a spec (a program registered from a shader asset included), or one destroyed. hidden

argtypedescription
keystringThe program's key.

examples

local spec = compute.program.spec(key)

forPlugin(key: string, bindings: number | { string }) → any

The program under `key` as a handle a script passes a plugin in a call, for it to dispatch over the GPU buffers and textures it was handed. `bindings` is how many storage buffers the shader binds, or the kind of each binding in declaration order as `bindings.yaml` spells them (`buffer`, `texture3d`, `storage3d`, `storage2d`). hidden

argtypedescription
keystringThe program's key.
bindingsnumber | { string }A count of buffers, or each binding's kind.

dispatch(key: string, opts: { [string]: any }) → boolean

Dispatch the program under `key` with one buffer per declared storage binding, in declaration order. program's `params:` uniform, by name, to this dispatch alone: two dispatches of one program in a frame each read their own, and a value left out reads what the program holds. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count with `math.max(1, math.ceil(n / 64))`. in `compute.program.status(key)`. hidden

argtypedescription
keystringThe program's key.
opts{ [string]: any }`{ buffers, workgroups, params? }`. `params` gives values of the

dispatches( ) → number

How many dispatches the running thread has queued since it began, a run of a compute list counting each dispatch the list holds. Two readings taken around a piece of work give what that work dispatched. hidden

record(fn: ({ { [string]: any } }, held: ?) →

Run `fn` and answer every `compute.program.dispatch` it made, in order, as the entries of a compute list: `{ program, buffers, workgroups, params }` each. The dispatches are queued as they always are; the answer is what `compute.program.list` takes to replay them. `fn` is handed the entries as they are made, so it can add `slots` to one it just dispatched. queues them, when it is run, in the order the entries stand with the writes the list holds. hidden

argtypedescription
fn({ { [string]: any } }The work to run, given the entries recorded so far.
held?True to record the dispatches without queueing them: the list that is registered from the answer is what

recording( ) → boolean

Whether the running thread is inside `compute.program.record`: a dispatch it queues now is kept as an entry of a list that names its buffers and queues them again. hidden

dispatchOnVertices(key: string, opts: { [string]: any }) → boolean

Dispatch the program under `key` over a mesh's vertices. The mesh `opts.model` names fills the shader's `vertices` binding, and `opts.buffers` fills the remaining storage bindings. the program's `params:` uniform to this dispatch alone. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count with `math.max(1, math.ceil(n / 64))`. in `compute.program.status(key)`. hidden

argtypedescription
keystringThe program's key.
opts{ [string]: any }`{ model, buffers?, workgroups, params? }`. `params` gives values of

dispatchEx(key: string, opts: { [string]: any }) → boolean

Dispatch the program under `key` with explicit resources — one `{ kind, name }` per declared binding, in declaration order. A zero in any workgroup dimension is refused and recorded as a dispatch failure — clamp a computed count with `math.max(1, math.ceil(n / 64))`. in `compute.program.status(key)`. hidden

argtypedescription
keystringThe program's key.
opts{ [string]: any }`{ resources, workgroups, params? }`.

list(key: string, entries: { { [string]: any } }) → boolean

Register the compute list under `key`, replacing one already there: an ordered run of dispatches and buffer writes that `runList` queues in one call, each value a run supplies named as a slot. `{ program, buffers, workgroups, params?, slots?, runs?, writes?, when? }`, `slots` mapping a param name to the slot that gives it its value. `runs` names the runs the dispatch reaches through a page it binds and `writes` the ones of those it writes: the list holds them standing (a replay over a run that was let go of is refused, not run) and moves the write revision of the ones it writes. A write is `{ write = bufferName, offset?, values, unsigned?, slots?, when? }`: `offset` in 32-bit words, `values` written as f32 (u32 when `unsigned`), `slots` mapping a value's place, from 1, to the slot that gives it. `when` names a slot: a run giving it 0 leaves the entry out. hidden

argtypedescription
keystringThe key to register the list under.
entries{ { [string]: any } }The dispatches and writes, in the order they run. A dispatch is

runList(key: string, slots: { [string]: number }?, label: string?) → boolean

Queue the compute list under `key`: every entry in order, each value an entry names a slot for taken from `slots`, every other value as the list holds it. While the GPU profiler is read the run is recorded as a compute pass of its own, and its GPU time is the `compute.list:<label>` row of the gpu report. hidden

argtypedescription
keystringThe list's key.
slots{ [string]: number }?The value of each slot for this run, by name.
labelstring?The name the run's GPU time is reported under; the list's key when absent.

listCost(key: string) →

What recording the runs of the compute list under `key` has cost the render side so far. A run is recorded on a frame after the one that queued it, so a cost read just after `runList` holds the runs before that one. many runs that was; nil when no list is registered under `key`. hidden

argtypedescription
keystringThe list's key.

dropList(key: string) → boolean

Forget the compute list under `key`. hidden

argtypedescription
keystringThe list's key.

setParam(key: string, prop: string, value: number) → boolean

Write one scalar of the program's `params:` uniform. A value set before the program's first compile is the value it starts with. hidden

argtypedescription
keystringThe program's key.
propstringParameter name as declared.
valuenumberNew scalar value.

status(key: string) →

What the engine did with the dispatches of the program under `key`, one record per target. hidden

argtypedescription
keystringThe program's key.

target(buffers: { string }) → string

The `target` a dispatch over `buffers` is recorded against in `compute.program.status`: the record its outcome lands in. A program several callers dispatch over their own buffers has one record per target, so this is how a caller picks out what became of its own dispatches. hidden

argtypedescription
buffers{ string }The buffer names the dispatch binds, in binding order.

examples

local mine = compute.program.target({ "positions", "out" })

observe( ) →

Every GPU resource the compute subsystem is holding right now — its storage and uniform buffers, its 3D textures, its 2D storage targets, its history pairs and its samplers — with what each one costs and which shader asked for it. This is the call to reach for when compute is holding memory and you do not know what, or when a key out of a dispatch failure needs matching against what exists. `resources` carries `key`, `kind` (`buffer` / `uniformBuffer` / `texture3d` / `storageTexture2d` / `textureHistory` / `sampler`), `owner` (`{ shader, name, serial }`, read off the key), `bytes`, `format`, `width`, `height`, `depth`, `usage` (the bits it was created with — `storage`, `copySrc`, `copyDst`, `vertex`, `index`, `indirect`, `uniform`, `sampled`, `sampler`) and `createdFrame`. `totals` is `{ count, bytes, byKind }`, what the rows sum to — and `totals.bytes` is the `compute` figure of `renderer.gpuMemory()`, read off the same registries. `published` is false when no renderer has published a reading yet, which is the engine saying it cannot answer rather than answering with nothing. The reading is the one the renderer published, republished on a frame where a registry gained or lost an entry: a resource created earlier in this same script is in the next reading, so wait a frame before asking about it, and `generation` moves when it arrives.

examples

local r = compute.observe()
print(r.totals.count, r.totals.bytes)
for _, res in ipairs(r.resources) do print(res.key, res.kind, res.bytes) end

resources(owner: any?) →

The resource rows on their own, optionally narrowed to what one shader owns. every resource compute holds. A value carrying no shader raises, so a narrowing that cannot be done reads as an error rather than as the whole inventory. A guid stands for itself, so resources outlive the asset that made them and stay reachable by their owner. Empty when the owner holds nothing.

argtypedescription
ownerany?A `.computeShader` ref, its guid, or its asset identity. Omit for

examples

for _, r in ipairs(compute.resources(shaderRef)) do print(r.key, r.bytes) end

diagnose(key: string) →

Whether a resource is filed under `key` right now, and when none is, which state the inventory says the key is in. A key out of a dispatch failure resolves here; a mistyped one reports why it does not. when one is filed under the key. `reason` is one of `compute.absentReasons()`. `current` names the live key when the owner holds a resource under the same name at a different serial.

argtypedescription
keystringThe resource key, verbatim.

examples

local d = compute.diagnose(key)
if not d.exists then print(d.reason, d.current) end

absentReasons( ) →

Every reason `compute.diagnose` reports, sorted. `resident` is the one that means the resource is there.

examples

for _, r in ipairs(compute.absentReasons()) do print(r) end

computeMark(generation: number?) → void

Internal: the mark `generation` names, with its index, or the newest.

argtypedescription
generationnumber?

markBaseline( ) → number

Record which compute resources are resident right now, and make that the point `compute.resetToBaseline` returns to. A caller that runs work in someone else's engine — a sweep of test suites sharing one, an editor tool driving a session — allocates as it goes: a pass builds the grid its quality asks for and keeps it, a shader files the uniform it was compiled with. Kept is right for a frame that draws again and wrong for the next caller, which then reads an inventory it did not make. This is how a caller says where its own allocations start. pass The resident keys are recorded as a mark above the marks before it. `compute.resetToBaseline` takes to restore to this mark.

examples

local mark = compute.markBaseline() -- then run, then compute.resetToBaseline(mark)

resetToBaseline(generation: number?) → number

Release every compute resource allocated since `compute.markBaseline`, except resources owned by standing render features. Restore the renderer baseline first so resources of nonbaseline features are released. Resources recorded by the mark are left where they are. Each kind this closes is one a caller allocated under a name it chose, so the next caller finds that name free. A storage buffer is such a resource and is not closed here: every one a caller can make is a substrate buffer, and `substrate.resetToBaseline` is what puts those back. A compiled shader's params uniform is not, and is left where it is: it is filed under its shader's guid, which no other caller can ask for, and it belongs to the `.computeShader` asset that compiled it, released when that is. pass Every texture, buffer texture, history and sampler allocated since the mark is closed; nothing the mark recorded is touched. it; the newest mark when omitted. The marks taken after it go with the reset.

argtypedescription
generationnumber?The mark to restore to, as `compute.markBaseline` returned

examples

local released = compute.resetToBaseline(mark)

releaseBaseline(generation: number) → boolean

Drop the mark `generation` names, and every mark taken after it, once the caller that took it is done resetting to it. It touches the marks alone.

argtypedescription
generationnumberThe mark to drop, as `compute.markBaseline` returned it.

examples

compute.releaseBaseline(mark) -- the run is over

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported on this asset or on the parts this page shows. Parts it leaves out are not counted here.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.