compute_abi
The kernel ABI of a `.computeShader`. A `bindings.yaml` that uses the ABI extensions is lowered to the plain bindings and WGSL the engine compiles; this module parses, lowers, compiles variants, allocates outputs, packs column tables and dispatches.
compute_abi Module
The kernel ABI of a .computeShader. A bindings.yaml that uses the ABI
extensions is lowered to the plain bindings and WGSL the engine compiles; this
module parses, lowers, compiles variants, allocates outputs, packs column tables
and dispatches.
Purpose
A kernel is one asset that serves many shapes of data. bindings.yaml states:
bindings:
- { name: cols, kind: columns, access: read }
- { name: src, kind: buffer, access: read, element: T }
- { name: dst, kind: buffer, access: read_write, element: T, count: "len(src)" }
- { name: hits, kind: buffer, access: read_write, element: vec4<f32>, capacity: "n * 4", append: true }
specialize:
- { name: T, options: [f32, i32, vec2<f32>, vec3<f32>, vec4<f32>] }
- { name: FOLD, options: [add, min, max, mean, set] }
- { name: BODY, kind: source }
determinism: exact
-
columns: a table of columns in one storage binding (header: the column count, then four words a column: first word, lanes, count, kind). WGSL reads it throughNAME_count(c),NAME_lanes(c),NAME_f32/i32/u32(c, i, lane),NAME_vec2/3/4(c, i);access: read_writeaddsNAME_set_*. Columns named at specialization are constantsNAME_col_<column>. -
count/capacity: the size, in elements, of an output the host allocates. The expression usesn(the dispatch size), the shader's params,len(binding),max,min,ceil,floorand+ - * / ( ). -
live: true: on an output ofcount: "n", the output carries the live count its dispatch ran over (the count thedomain_countbinding was handed), so a reader of it takes the live elements only. -
append: true: the output carries a live counter,NAME_count, bound right after it.NAME_store(slot, v),NAME_set_count(n),NAME_count_value(),NAME_capacity()are generated.NAME_append(v)(unordered, atomic) is generated fordeterminism: float_orderonly. -
specialize: compile-time parameters. Type options becomealias NAME = type;, named options becomeconst NAME: u32plusNAME_<option>, andkind: sourceparameters replace the identifier with text. -
whenon a binding: a condition over the specialization options,NAME=optionorNAME=option|option. The binding exists in the variants whose option holds and is left out of the others. Terms separated by spaces all hold (COUNT=device STAGE=table); alternatives separated by;hold when any one does (COUNT=plain; COUNT=device STAGE=table). Two bindings may share a name when their conditions never hold together. -
// @when NAME option option...// @endin the WGSL: the lines between them stay in the variants where the specializationNAMEtakes one of the options and are blanked in the others (the lines keep their numbers). Blocks may nest. Code that reads a binding a variant leaves out sits in such a block. -
bits: trueon a binding states that its words are raw bits (an f32 held in a u32 word, an atomic word): a column of another element type bound to a read binding that states it is bound as it is, where an i32, u32 or f32 read binding takes a column of another element type cast by value. -
determinism:exactorfloat_order. Anexactshader that callsNAME_appendis refused. -
workgroup: the workgroup size the body declares (default 64). -
page/column: a kernel binds each arena page once and reaches the runs standing in it by offset.- { name: PA, kind: page, access: read_write, atomic: false }is one storage binding of u32 words (atomic: true:atomic<u32>words);- { name: pos, kind: column, page: PA, element: vec3<f32>, access: read }is a run of the page, with no binding of its own. A kernel of thirty columns over three pages has three bindings, whatever the runs' offsets are. A column getsNAME_len(),NAME_get(i),NAME_word(w)and, unlessaccess: read,NAME_set(i, v)andNAME_set_word(w, v); an index pastNAME_len()reaches the last element. On anatomic: truepage a one-lane column also getsNAME_atomic_exchange,NAME_atomic_minandNAME_atomic_max, the integer onesNAME_atomic_add,_and,_or,_xor, and an f32 columnNAME_atomic_add(compare-and-swap loops where the hardware has no atomic). Each column adds the paramscol_base_NAME(the word its run starts at in the page) andcol_len_NAME(its elements).abi.pageBinding(lowered, { [column] = handle | name })answers the page each page binding takes and those params, fromsubstrate.placement, and raises when the columns of one page binding stand in different pages. Runs made insideproc.substrate.withPageGroup(key, fn)stand in pages the group owns, in the order they were made, so work that asks for the same shapes in the same order binds the same pages every play. A buffer of its own (not an arena run) is a page of one column. At most eight pages bind in one kernel (the storage-buffer cap).
Every scalar or vector buffer binding gets NAME_get(i), NAME_len() and, unless access: read, NAME_set(i, v). A vec3 element is stored as a flat scalar array, matching a column of vec3 that is 12 bytes an element. zero_n() is the dispatch size.
Usage
local abi = require("@builtin::modules.compute_abi")
local schema = abi.parse(bindingsYaml)
local program = abi.program({ key = "my_kernel", schema = schema, wgsl = body })
local variant = program:variant({ specialize = { T = "vec3<f32>" } })
local run = variant:run({ n = 4, inputs = { src = srcBuffer } })
local values = abi.read(run.outputs.dst.buffer)
A computeShader asset reference exposes the same through ref:program().
API
| Function | Does |
|---|---|
abi.parse(text) | bindings.yaml to { bindings, params, specialize, determinism, workgroup }; a text parses to one schema, the same table each time it is read |
abi.isExtended(schema) | whether the schema uses an extension |
abi.lower(schema, wgsl, spec) | the lowered source, bindings, params and host slots |
abi.compile(key, lowered, label) | compile a lowered variant once, answering its dispatch key |
abi.program(def) | a program; program:variant(spec) lowers and compiles a variant. A program over the schema and source of the one standing under its key is that program, with the variants it has lowered |
variant:run(env) | allocate outputs, bind, dispatch; answers the outputs and live counters. env.outputs[binding] is a buffer (or { buffer, count?, capacity?, counter? }) the dispatch writes in place of an allocation; an appended output given one keeps the count its counter holds. The first run of a variant waits for its program to be built, so a read of an output asked for after the run sees what the dispatch wrote |
abi.table(columns, opts) | pack columns into one buffer for a columns binding |
abi.evaluate(text, vars, lengths) | evaluate a count expression |
abi.read(buffer, asU32?) | read a buffer back, waiting for the frames it takes |
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2module compute_abi require modules/compute_abi The kernel ABI of a `.computeShader`: the `bindings.yaml` extensions (`columns` bindings, output `count` / `capacity` / `append` with a live counter, `specialize` compile-time parameters, `determinism`), lowered to the plain bindings and WGSL the engine compiles, and the host side that allocates outputs, packs column tables and dispatches a variant.
listEntries(doc: any, key: string, file: string) → void
The mapping entries of the list `doc[key]` holds, in order. A key the file does not state holds no entries; a key holding anything but a list of mappings is refused, naming the file and the key.
| arg | type | description |
|---|---|---|
| doc | any | |
| key | string | |
| file | string |
namedEntries(doc: any, key: string, file: string) → void
The entries of `doc[key]` that carry a `name`.
| arg | type | description |
|---|---|---|
| doc | any | |
| key | string | |
| file | string |
parseText(content: string, file: string) → void
| arg | type | description |
|---|---|---|
| content | string | |
| file | string |
parse(content: string, file: string?) →
Parse `bindings.yaml` into `{ bindings, params, specialize, determinism, workgroup }`. A binding without a `kind` is a `buffer`. Every YAML list form reads: flow mappings, block mappings and flow lists. Raises, naming `file`, on text the YAML decoder refuses (with the line) and on a list key holding anything but a list of mappings (with the key).
| arg | type | description |
|---|---|---|
| content | string | The text of `bindings.yaml`. |
| file | string? | The file named in an error; `bindings.yaml` when omitted. |
examples
local schema = abi.parse(vfs.read(path .. "/bindings.yaml"), path .. "/bindings.yaml")
isExtended(schema: { [string]: any }) → boolean
Whether a schema uses any extension, which is what makes a shader lowered rather than compiled as written. `capacity` or `append`, a `specialize` list or a `determinism`.
| arg | type | description |
|---|---|---|
| schema | { [string]: any } | A parsed schema. |
examples
if abi.isExtended(schema) then ... end
elementInfo(element: string) → void
The lane count and scalar of a WGSL element: f32 -> 1, f32; vec3<i32> -> 3, i32.
| arg | type | description |
|---|---|---|
| element | string |
isWgslType(text: string) → boolean
| arg | type | description |
|---|---|---|
| text | string |
replaceIdentifier(text: string, name: string, with: string) → string
| arg | type | description |
|---|---|---|
| text | string | |
| name | string | |
| with | string |
fnv(text: string) → string
| arg | type | description |
|---|---|---|
| text | string |
resolveSpecialize(schema: { [string]: any }, given: { [string]: any }?) → void
The value each specialization parameter takes: the caller's, else the declared `default`, else the first option. A `source` parameter takes its declared `default` text, and has none otherwise.
| arg | type | description |
|---|---|---|
| schema | { [string]: any } | |
| given | { [string]: any }? |
conditionHolds(condition: string, values: { [string]: any }, what: string) → boolean
A `when` condition names the options of specialization parameters. `NAME=option` or `NAME=option|option` holds where the variant takes one of the options; terms separated by spaces all hold together (`COUNT=device STAGE=table`); alternatives separated by `;` hold when any of them does (`COUNT=plain; STAGE=heads`).
| arg | type | description |
|---|---|---|
| condition | string | |
| values | { [string]: any } | |
| what | string |
applyGuards(text: string, values: { [string]: any }) → string
Lines between `// @when <condition>` and `// @end` stay where the condition holds for the variant (the terms of `conditionHolds`, written as `// @when STAGE heads table`: one specialization and the options it takes) and are blanked where it does not. The directive lines are blanked too, so every other line keeps its number. A block may hold blocks of its own.
| arg | type | description |
|---|---|---|
| text | string | |
| values | { [string]: any } |
settle( ) → void
substituteSpecialization(text: string, values: { [string]: any }) → string
Types replace their identifier in the code of `text` (the part of a line before a `//` comment), and source parameters are put in last, so the text a source brings is never scanned for another parameter's name.
| arg | type | description |
|---|---|---|
| text | string | |
| values | { [string]: any } |
genSpecialization(values: { [string]: any }) → void
| arg | type | description |
|---|---|---|
| values | { [string]: any } |
directName(name: string, index: number) → string
The name of the extra binding that holds the `index`th direct column of the `columns` binding `name`.
| arg | type | description |
|---|---|---|
| name | string | |
| index | number |
genColumns(b: { [string]: any }, names: { string }?, writable: boolean, direct: { number }?) → void
| arg | type | description |
|---|---|---|
| b | { [string]: any } | |
| names | { string }? | |
| writable | boolean | |
| direct | { number }? |
add(s: string) → void
| arg | type | description |
|---|---|---|
| s | string |
readAt(word: string) → string
A direct column is read from the binding of its own run at the word its element lands at; every other column is read from the table at the word its header states.
| arg | type | description |
|---|---|---|
| word | string |
columnBaseParam(column: string) → string
The params a column states where its run stands in its page: the word it starts at and how many elements it holds.
| arg | type | description |
|---|---|---|
| column | string |
columnLenParam(column: string) → string
| arg | type | description |
|---|---|---|
| column | string |
fromWord(scalar: string, word: string) → string
The WGSL that turns the u32 word a page holds into a scalar of `scalar`, and back.
| arg | type | description |
|---|---|---|
| scalar | string | |
| word | string |
toWord(scalar: string, value: string) → string
| arg | type | description |
|---|---|---|
| scalar | string | |
| value | string |
load(index: string) → string
| arg | type | description |
|---|---|---|
| index | string |
store(index: string, word: string) → string
| arg | type | description |
|---|---|---|
| index | string | |
| word | string |
op(name: string, native: string) → void
| arg | type | description |
|---|---|---|
| name | string | |
| native | string |
cas(name: string, combine: string) → void
A min, max or an f32 add is a compare-and-swap loop over the word: the native atomic orders u32 only.
| arg | type | description |
|---|---|---|
| name | string | |
| combine | string |
genBuffer(name: string, element: string, lanes: number, scalar: string, writable: boolean) → void
| arg | type | description |
|---|---|---|
| name | string | |
| element | string | |
| lanes | number | |
| scalar | string | |
| writable | boolean |
accessorLines(name: string, element: string, lanes: number?, writable: boolean) →
The lines `lower` generates for one `buffer` binding: its length, its read and, when it is written, its write.
| arg | type | description |
|---|---|---|
| name | string | The binding's name. |
| element | string | The element type as the schema states it after specialization (`vec3<f32>`). |
| lanes | number? | How many scalars the element holds. |
| writable | boolean | Whether the binding is written. |
examples
local lines = abi.accessorLines("src", "vec3<f32>", 3, false)fingerprint(text: string) → string
A fingerprint of a text, the one lowered variants and fused kernels are keyed by.
| arg | type | description |
|---|---|---|
| text | string | Any text. |
examples
local tag = abi.fingerprint(source)
directLimit(schema: { [string]: any }, binding: string) → number
How many columns of the `columns` binding `binding` a variant can bind directly, each as a binding of its own run: the storage buffers a shader stage holds on every device, less the buffers the schema's other bindings take and the binding's own table.
| arg | type | description |
|---|---|---|
| schema | { [string]: any } | A parsed schema. |
| binding | string | The name of a `columns` binding that reads. |
examples
local limit = abi.directLimit(schema, "cols")
directPlan(columns: { { [string]: any } }, limit: number) →
The column slots, in increasing order, that a table of `columns` takes as direct columns: the first `limit` columns that name a device buffer and hold no values of their own. A dispatch binds each buffer at one slot, so a column whose buffer an earlier direct column holds stays in the table.
| arg | type | description |
|---|---|---|
| columns | { { [string]: any } } | The array `abi.table` is given. |
| limit | number | How many direct columns the variant can bind (`abi.directLimit`). |
examples
local direct = abi.directPlan(columns, abi.directLimit(schema, "cols"))
lower(schema: { [string]: any }, wgsl: string, spec: { [string]: any }?) →
Lower a shader's extensions to the bindings and WGSL the engine compiles. `direct` names, per read `columns` binding, the column slots read from a binding of their own run (`NAME_d0`, `NAME_d1`, ... after the table), so those columns are not copied into the table. `slots` lists what the host binds, one per lowered binding, in order.
| arg | type | description |
|---|---|---|
| schema | { [string]: any } | A parsed schema. |
| wgsl | string | The shader body, with its `#include` literals already canonicalized. |
| spec | { [string]: any }? | `{ specialize = { NAME = value }, columns = { [binding] = { names } }, direct = { [binding] = { slot } } }`. |
examples
local lowered = abi.lower(schema, wgsl, { specialize = { T = "vec3<f32>" } })pageBinding(lowered: { [string]: any }, runs: { [string]: any }) →
What a dispatch of a lowered kernel with `page` and `column` bindings binds: the arena page each `page` binding names and the base and length of each column's run in it. `runs` maps each column name to a buffer handle or name. A column's run stands in one arena page (`substrate.placement`); every column the kernel declares in one page binding must stand in one page, and a column outside an arena page (a buffer of its own) is a page of one column. A column in another page than the rest of its binding, or a page two bindings name, raises naming both: the kernel is lowered for the partition of columns it was given, and a partition that differs is a different kernel. `signature` is the partition of columns into pages, the text two plays share when they place their runs alike; `runs` names the runs the columns stand in and `writes` the ones a column declared written.
| arg | type | description |
|---|---|---|
| lowered | { [string]: any } | A value from `lower`. |
| runs | { [string]: any } | `{ [column] = handle | name }`. |
examples
local bound = abi.pageBinding(lowered, { pos = positions, vel = velocities })pageEntry(key: string, lowered: { [string]: any }, runs: { [string]: any }, opts: { [string]: any }) →
The entry of a compute list (`compute.program.list`) that dispatches a page-bound kernel over `runs`: the program, the pages it binds, the base and length of each column, and the runs it reaches through those pages, with the ones its column declarations write. A list holding the entry keeps those runs standing and moves the write revision of the ones the kernel writes, so a replay never runs over a run that was let go of, and what reads a written run sees it changed. buffer of each non-page binding, `slots` and `when` are a list entry's.
| arg | type | description |
|---|---|---|
| key | string | The key `compile` answered for the kernel. |
| lowered | { [string]: any } | A value from `lower`. |
| runs | { [string]: any } | `{ [column] = handle | name }`. |
| opts | { [string]: any } | `{ workgroups, params?, buffers?, slots?, when? }` — `params` are the kernel's own, `buffers` names the |
examples
compute.program.list("step", { abi.pageEntry(key, lowered, runs, { workgroups = { 1, 1, 1 } }) })mint(what: string) → string
A tag no other buffer this module made carries: the clock alone repeats within one tick of it, and a name that is already a buffer of another size is refused by the substrate.
| arg | type | description |
|---|---|---|
| what | string |
allocationCount( ) → number
lowerSignature(lowered: { [string]: any }) → string
| arg | type | description |
|---|---|---|
| lowered | { [string]: any } |
keyOf(baseKey: string, lowered: { [string]: any }) → string
The key `compile` registers a lowered variant under, without compiling it.
| arg | type | description |
|---|---|---|
| baseKey | string | The shader's registration key. |
| lowered | { [string]: any } | A value from `lower`. |
examples
local key = abi.keyOf(guid, lowered)
compile(baseKey: string, lowered: { [string]: any }, label: string?) → string
Compile a lowered variant under `<baseKey>#<hash of what it lowered to>`; one variant compiles once. device would refuse), with its reason.
| arg | type | description |
|---|---|---|
| baseKey | string | The shader's registration key. |
| lowered | { [string]: any } | A value from `lower`. |
| label | string? | The name profiling rows carry. |
examples
local key = abi.compile(guid, lowered, "kernels.map")
compiledSince(since: number) →
What `compile` registered after the count stood at `since` (`compileCount`), oldest first, for the latest 4096 compiles: each variant's label and the key it is dispatched under (`loweredOf(key)` reads what it lowered to).
| arg | type | description |
|---|---|---|
| since | number | A count `compileCount` answered. |
examples
local before = abi.compileCount(); work(); for _, c in ipairs(abi.compiledSince(before)) do print(c.label) end
loweredOf(key: string) →
What `compile` lowered the program under `key` from: `{ lowered, label, base }`, the `lowered` value `lower` answered (its `source`, `bindings`, `params`, `slots`, `workgroup` and `fusion`). Nil for a key this module did not compile, or one compiled before the device was rebuilt.
| arg | type | description |
|---|---|---|
| key | string | A key `compile` answered. |
examples
local made = abi.loweredOf(entry.program)
allocationCount( ) → number
How many device buffers this module has made (a table of columns, an output, a live counter) since the module state began; the buffers a kernel dispatch allocates are in it.
examples
local before = abi.allocationCount()
compileCount( ) → number
How many variants `compile` has registered since the module state began: a count that grows while the same work repeats says the work asks for a program of its own each time.
examples
local before = abi.compileCount()
release(baseKey: string) → number
Release every variant `compile` registered under `baseKey`, and the program `program` made for it: each variant's compiled program and params uniform are destroyed, and the next `compile` of one registers it again. The teardown of a shader whose asset is gone.
| arg | type | description |
|---|---|---|
| baseKey | string | The shader's registration key. |
examples
local released = abi.release(guid)
forget( ) → void
Forget every compiled variant, so the next `compile` of each registers it again; for a device that was rebuilt.
awaitState(readState: (, label: ?, frames: ?, seconds: ?) →
Wait, in a thread that can yield, until `readState()` stops answering "pending", and raise when it answers "failed" (at once, with its reason) or is still pending once both `frames` engine frames and `seconds` of the engine's real clock have passed. The rule `awaitProgram` waits by, over any state reader.
| arg | type | description |
|---|---|---|
| readState | ( | Answers the state and, for "failed", the reason: `compute.programState(key)` for a program. |
| label | ? | The name an error carries. |
| frames | ? | The frames the wait lasts at least. |
| seconds | ? | The seconds the wait lasts at least. |
examples
abi.awaitState(function() return compute.programState(key) end, "fused chain", 1800, 30)
awaitProgram(key: string, label: string) → void
| arg | type | description |
|---|---|---|
| key | string | |
| label | string |
tokenize(text: string) → void
`count: "n * 4"`: numbers, names, + - * / ( ), and the calls len(binding), max, min, ceil, floor. Names are the dispatch size `n`, the shader's params, and the values the caller passes.
| arg | type | description |
|---|---|---|
| text | string |
evaluate(text: string, vars: { [string]: number }, lengths: (string) → void
| arg | type | description |
|---|---|---|
| text | string | |
| vars | { [string]: number } | |
| lengths | (string |
peek( ) → string
take( ) → string
primary( ) → number
term( ) → number
expr( ) → void
evaluate(text: string, vars: { [string]: number }, lengths: (string) →
Evaluate a `count` / `capacity` expression.
| arg | type | description |
|---|---|---|
| text | string | The expression. |
| vars | { [string]: number } | The names it may use, with their values. |
| lengths | (string | `len(binding)`: the element count of a bound run. |
examples
abi.evaluate("n * 4", { n = 10 }, function() return 0 end) --> 40wordsOf(payload: any) → void
| arg | type | description |
|---|---|---|
| payload | any |
observeWrites(fn: (any) →
Hear the writes the host makes into device buffers: `fn(entry)` is called with each write as a compute list entry. Every call returns a function that stops listening.
| arg | type | description |
|---|---|---|
| fn | (any | Called with `{ write = bufferName, offset = words?, values, unsigned? }`. |
examples
local stop = abi.observeWrites(function(entry) entries[#entries + 1] = entry end)
noteWrite(name: string, method: string, payload: any, offset: number?) → void
Tell whoever is recording that the host wrote `payload` into the device buffer `name`.
| arg | type | description |
|---|---|---|
| name | string | The buffer's name. |
| method | string | `write` (words as f32, `offset` in words), `writeU32` or `writeBytes` (`offset` in bytes). |
| payload | any | What was handed to the buffer's method. |
| offset | number? | The method's offset argument. |
examples
abi.noteWrite(handle.name, "writeU32", { 0 })ensureCopyProgram( ) → void
wordCopyProgram( ) → string
copyWords(src: string, dst: string, words: number, first: number?) → boolean
Queue a word-for-word copy of the first `words` words of the buffer `src` into the buffer `dst`, from word `first` on.
| arg | type | description |
|---|---|---|
| src | string | The source buffer's name. |
| dst | string | The destination buffer's name. |
| words | number | How many words. |
| first | number? | The word of `dst` the first one lands at. Default 0. |
examples
abi.copyWords(a:bufferName(), b:bufferName(), 64)
wordCopyOf(entry: any) →
The source and destination of a recorded dispatch that is a `copyWords` from word 0: the copy of the first `words` words of `src` into the same words of `dst`. Nil for any other entry.
| arg | type | description |
|---|---|---|
| entry | any | An entry of a recorded list. |
examples
local src, dst = abi.wordCopyOf(entry)
ensurePackProgram(sources: number) → string
The program that copies `sources` buffers, 2 to PACK_SOURCES.
| arg | type | description |
|---|---|---|
| sources | number |
packInto(dst: string, pending: { { buffer: string, words: number, first: number } }) → void
Queue the copies of `pending` (`{ buffer, words, first }`) into `dst`, up to PACK_SOURCES to a dispatch. A dispatch binds each buffer at one slot, so a buffer a group already holds starts the next group.
| arg | type | description |
|---|---|---|
| dst | string | |
| pending | { { buffer: string, words: number, first: number } } |
names(self: any) → void
The names of the table's columns, in slot order.
| arg | type | description |
|---|---|---|
| self | any |
slot(self: any, name: string) → number
The slot a named column holds.
| arg | type | description |
|---|---|---|
| self | any | |
| name | string |
buffer(self: any) → any
The GPU buffer holding the table.
| arg | type | description |
|---|---|---|
| self | any |
directs(self: any) →
The column slots the table binds as direct columns, and the names of the buffers they are read from, in the order a variant binds them.
| arg | type | description |
|---|---|---|
| self | any |
repack(self: any) → void
Copy the device buffers the table was packed from into it again, where they stand now: what a rewrite of those buffers in place leaves the table to read. The numbers it was given on the CPU stay as written.
| arg | type | description |
|---|---|---|
| self | any |
examples
cols:repack()
release(self: any) → void
Free the table's buffer.
| arg | type | description |
|---|---|---|
| self | any |
table(columns: { { [string]: any } }, opts: { [string]: any }?) → any
Pack columns into one buffer a `columns` binding reads. `values` are numbers a column holds, element after element (lanes contiguous); `buffer` is a GPU buffer whose words are copied in on the device. and the 0-based slots of the columns a variant binds as direct columns (`abi.directPlan`). A direct column is not copied: its `buffer` is bound beside the table, and the table holds its header alone. `class` (`"effect"` or `"persistent"`) makes the table a run of the device arenas, in the pages of the page group `group` and held for `owner` (`substrate.createBuffer`), which the substrate names in place of `name`.
| arg | type | description |
|---|---|---|
| columns | { { [string]: any } } | An array of `{ name, kind = "f32" | "i32" | "u32", lanes?, count, values? | buffer? }`. |
| opts | { [string]: any }? | `{ name = string, direct = { slot }, class?, group?, owner? }`: the name the buffer is created under, |
examples
local t = abi.table({ { name = "a", kind = "f32", count = 4, values = { 1, 2, 3, 4 } } }, { name = "cols" })program(def: { [string]: any }) → any
A shader's ABI, ready to specialize and dispatch. the parsed schema, the shader body, and a function that resolves the `#include` literals of the lowered source.
| arg | type | description |
|---|---|---|
| def | { [string]: any } | `{ key, label?, schema, wgsl, canonicalize? }`: the registration key, |
examples
local program = abi.program({ key = guid, schema = schema, wgsl = wgsl })specKey(spec: { [string]: any }?) → string
The variant for a specialization: lowered and compiled once.
| arg | type | description |
|---|---|---|
| spec | { [string]: any }? | `{ specialize = { NAME = value }, columns = { [binding] = { names } }, direct = { [binding] = { slot } } }`. |
examples
local v = program:variant({ specialize = { T = "vec3<f32>" } })directLimit(self: any, binding: string) → number
How many columns of the `columns` binding `binding` a variant of this program can bind directly (`abi.directLimit`).
| arg | type | description |
|---|---|---|
| self | any | |
| binding | string | The name of a `columns` binding that reads. |
examples
local limit = program:directLimit("cols")directLimitOf(program: any, binding: string) → number
`Program.directLimit` for a program made by an earlier load of this module.
| arg | type | description |
|---|---|---|
| program | any | A program from `abi.program`. |
| binding | string | The name of a `columns` binding that reads. |
examples
local limit = abi.directLimitOf(program, "cols")
standing(v: any) → string
The key `v` dispatches under, with a program standing behind it: a variant whose program the engine let go of since it was compiled (a program destroyed by name, a test suite's reset of the programs its chunk compiled, `release`) is compiled again under the same key from what it lowered.
| arg | type | description |
|---|---|---|
| v | any |
variant(self: any, spec: { [string]: any }?) → any
| arg | type | description |
|---|---|---|
| self | any | |
| spec | { [string]: any }? |
bufferName(v: any) → string
| arg | type | description |
|---|---|---|
| v | any |
bufferLength(v: any) → number
| arg | type | description |
|---|---|---|
| v | any |
run(self: any, env: { [string]: any }) →
Dispatch the variant over `env.n` elements. `n` is the element count; `params` sets the shader's own params; `values` adds names to count expressions; `class` (`"effect"` or `"persistent"`) makes every buffer the run allocates a run of the device arenas, in the pages of the page group `group` and held for `owner` (`substrate.createBuffer`). Outputs with `count` or `capacity` are allocated here, except those `outputs` names: `outputs[binding]` is a buffer (or `{ buffer, count?, capacity?, counter? }`) the dispatch writes in place, and an appended output given one needs its `counter`, whose count the dispatch keeps appending to. The first run of a variant waits for its program to be built, so a read of an output asked for after the run sees what the dispatch wrote. An appended output's `counter` is the buffer holding its live count.
| arg | type | description |
|---|---|---|
| self | any | |
| env | { [string]: any } | `{ n, inputs = { [binding] = buffer | name | table }, outputs?, params?, values?, class?, group?, owner? }`: |
examples
local r = variant:run({ n = 10, inputs = { src = src } })lengthOf(name: string) → number
| arg | type | description |
|---|---|---|
| name | string |
read(handle: any, asU32: boolean?) →
Read a buffer's words back, waiting for the frames the read takes.
| arg | type | description |
|---|---|---|
| handle | any | A buffer handle created with `usage = { "readback" }`. |
| asU32 | boolean? | Answer the words as u32 (default f32). |
examples
local values = abi.read(out.buffer)
Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Showing up to 3 levels deep. Open a part to see what it holds further down.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
These counts cover only the parts this page shows. Problems on the parts it leaves out are not counted here.
Inside
1 problem across 1 itemagent_score is exposed.+ 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".
Scoped to this part · feeds back into the world's score.