Module Sarek_codegen.Sarek_wgsl_abi

WGSL kernel ABI descriptor.

Describes the binding layout of a Sarek-generated WGSL compute shader in a plain data structure that can be serialized to JSON. The shape mirrors the binding assignments produced by Sarek_ir_wgsl.gen_bindings exactly, so the JavaScript WebGPU runner can bind buffers and pack the uniform struct without parsing the shader source.

All field names go through the same escape_wgsl_name transformation used by the code generator, so ABI names are identical to the names in the emitted WGSL.

JSON serialization is hand-rolled (no yojson) so sarek_codegen stays FFI-free.

type element_type =
  1. | F32
  2. | I32
  3. | U32

WGSL scalar type of a storage-buffer element or uniform field.

type buffer = {
  1. name : string;
    (*

    Escaped WGSL identifier.

    *)
  2. binding : int;
    (*

    @binding index (0-based, vector order).

    *)
  3. element_type : element_type;
  4. access : string;
    (*

    Always "read_write" for storage buffers.

    *)
}

A storage buffer binding (one per vector parameter, in declaration order).

type field_kind =
  1. | Length of string
    (*

    sarek_<vec>_length — carries the element count of vector <vec>.

    *)
  2. | Scalar
    (*

    A user scalar parameter.

    *)

Kind of a field inside the Params uniform struct.

type field = {
  1. name : string;
    (*

    Escaped WGSL identifier.

    *)
  2. field_type : element_type;
  3. offset : int;
    (*

    Byte offset inside the struct (4 bytes per field).

    *)
  4. kind : field_kind;
}

A single field inside the Params uniform struct.

type params = {
  1. binding : int;
  2. byte_size : int;
  3. fields : field list;
}

The Params uniform struct binding.

Present whenever there is at least one vector or scalar parameter (mirrors gen_bindings). The binding index equals the number of vector buffers. byte_size is the total number of fields × 4 rounded up to 16 (WebGPU minimum uniform buffer binding-size alignment).

type t = {
  1. kernel_name : string;
  2. workgroup_size : int * int * int;
  3. buffers : buffer list;
  4. params : params option;
}

Complete ABI descriptor for one kernel.

val to_json : t -> string

to_json abi returns a JSON string representing abi.

Hand-rolled output — no external dependencies. The shape matches the ABI JSON contract documented in the implementer sub-brief.