Piece Format Reference¶
A piece defines a portable unit of programmable graphics with piece.toml and up to three WGSL files (common.wgsl, derive.wgsl, draw.wgsl).
Library pieces, workspace pieces, and inline [[piece]] entries in a spec share one schema, one manifest validator, and one SHA-256 content hash.
The script scripts/generate_piece_reference.py generates this page from piece.h, pieces.h, piece_checks.cpp, and caliper-spec-v1.schema.json.
Continuous integration runs python scripts/generate_piece_reference.py --check and fails when this page drifts from those sources.
Run python3 scripts/generate_piece_reference.py --write after any change to piece limits, manifest schema keys, or check codes.
Schema Definitions¶
The canonical JSON Schema in src/builder/spec/schema/caliper-spec-v1.schema.json validates piece keys, types, patterns, and array bounds.
Tensor inputs accept element types f32, i32, u32, u8, u16, or distinct combinations joined by |.
Texture resources accept formats rgba8unorm, r8unorm, r32uint.
See Pieces for authoring workflows and MCP Command Reference for piece.* tools.
Manifest Root Keys¶
Top-level keys in piece.toml or an inline [[piece]] table.
| Key | Type | Required | Constraints |
|---|---|---|---|
name |
string |
Yes | pattern ^\[a-z\]\[a-z0-9_\]{0,31}$ |
version |
integer |
No | range 1 to 1000000 |
description |
string |
No | max length 256 |
inputs |
array of piece_input |
No | max items 8 |
params |
array of piece_param |
No | max items 16 |
resources |
array of piece_resource |
No | max items 8 |
imports |
array of string |
No | max items 8; item pattern ^\[a-z\]\[a-z0-9_\]{0,31}@\[1-9\]\[0-9\]{0,5}$ |
depends |
array of object |
No | max items 8 |
derive |
piece_derive |
No | None |
draw |
piece_draw |
No | None |
sample |
array of object |
No | max items 8 |
hash |
string |
No | pattern ^sha256:\[0-9a-f\]{64}$ |
files |
object |
No | None |
Input Table Keys¶
Keys of each [[inputs]] entry for derive tensors and draw buffer inputs.
| Key | Type | Required | Constraints |
|---|---|---|---|
name |
string |
Yes | pattern ^\[a-z\]\[a-z0-9_\]{0,31}$ |
kind |
string |
Yes | enum: tensor, buffer |
dtype |
string |
No | pattern ^(f32\|i32\|u32\|u8\|u16)(\\|(f32\|i32\|u32\|u8\|u16)){0,4}$ |
rank_min |
integer |
No | range 0 to 8 |
rank_max |
integer |
No | range 0 to 8 |
element |
string |
No | enum: f32, i32, u32, vec2<f32>, vec4<f32>, vec2<u32>, vec4<u32>, u8, u16 |
struct |
string |
No | pattern ^\[A-Z\]\[A-Za-z0-9_\]{0,31}$ |
fields |
array of string |
No | items 1 to 16; item pattern ^\[a-z_\]\[a-z0-9_\]{0,31}: (f32\|i32\|u32\|vec2<f32>\|vec4<f32>\|vec2<u32>\|vec4<u32>)$ |
title |
string |
No | length 1 to 256 |
optional |
boolean |
No | None |
Parameter Table Keys¶
Keys of each [[params]] entry in the generated Params uniform struct.
| Key | Type | Required | Constraints |
|---|---|---|---|
name |
string |
Yes | pattern ^\[a-z\]\[a-z0-9_\]{0,31}$ |
type |
string |
No | enum: f32, i32, u32 |
default |
number |
No | None |
min |
number |
No | None |
max |
number |
No | None |
title |
string |
No | length 1 to 256 |
Resource Table Keys¶
Keys of each [[resources]] entry for published or private buffers and textures.
| Key | Type | Required | Constraints |
|---|---|---|---|
id |
string |
Yes | pattern ^\[a-z\]\[a-z0-9_\]{0,31}$ |
kind |
string |
Yes | enum: buffer, texture |
element |
string |
No | enum: f32, i32, u32, vec2<f32>, vec4<f32>, vec2<u32>, vec4<u32>, u8, u16 |
struct |
string |
No | pattern ^\[A-Z\]\[A-Za-z0-9_\]{0,31}$ |
fields |
array of string |
No | items 1 to 16; item pattern ^\[a-z_\]\[a-z0-9_\]{0,31}: (f32\|i32\|u32\|vec2<f32>\|vec4<f32>\|vec2<u32>\|vec4<u32>)$ |
count |
integer |
No | range 1 to 134217728 |
counted |
boolean |
No | None |
width |
integer |
No | range 1 to 8192 |
height |
integer |
No | range 1 to 8192 |
format |
string |
No | enum: rgba8unorm, r8unorm, r32uint |
texels |
integer |
No | range 1 to 67108864 |
publish |
boolean |
No | None |
clear |
boolean |
No | None |
keep |
integer |
No | range 1 to 4096 |
Derive Table Keys¶
Keys of the [derive] compute table that runs in the producer on caliper.step().
| Key | Type | Required | Constraints |
|---|---|---|---|
passes |
array of object |
Yes | items 1 to 8 |
time_ms |
number |
No | range 0.01 to 50 |
memory_mb |
integer |
No | range 1 to 512 |
every |
integer |
No | range 1 to 10000 |
Draw Table Keys¶
Keys of the [draw] table that runs each viewer frame on Metal, Vulkan, or WebGPU.
| Key | Type | Required | Constraints |
|---|---|---|---|
camera |
string |
No | enum: orbit, pan_zoom, none |
buffers |
array of object |
No | max items 4 |
targets |
array of object |
No | max items 4 |
passes |
array of piece_draw_pass |
Yes | items 1 to 16 |
pick |
object |
No | None |
text |
object |
No | None |
frame_ms |
number |
No | range 0.1 to 16 |
memory_mb |
integer |
No | range 1 to 512 |
Draw Pass Keys¶
Keys of each [[draw.passes]] compute or render pass entry.
| Key | Type | Required | Constraints |
|---|---|---|---|
kind |
string |
Yes | enum: compute, render |
entry |
string |
No | pattern ^\[A-Za-z_\]\[A-Za-z0-9_\]{0,62}$ |
workgroups |
array of integer |
No | items 3 to 3 |
writes |
array of string |
No | max items 4; item pattern ^\[a-z\]\[a-z0-9_\]{0,31}$ |
vertex |
string |
No | pattern ^\[A-Za-z_\]\[A-Za-z0-9_\]{0,62}$ |
fragment |
string |
No | pattern ^\[A-Za-z_\]\[A-Za-z0-9_\]{0,62}$ |
target |
string |
No | pattern ^\[a-z\]\[a-z0-9_\]{0,31}$ |
reads |
array of string |
No | max items 4; item pattern ^\[a-z\]\[a-z0-9_\]{0,31}$ |
instances |
integer |
string |
No |
vertices |
integer |
No | range 1 to 65536 |
indices |
string |
No | pattern ^\[a-z\]\[a-z0-9_\]{0,31}$ |
topology |
string |
No | enum: triangle_list, triangle_strip, line_list, line_strip, point_list |
blend |
string |
No | enum: opaque, alpha, additive |
depth |
string |
No | enum: none, test, write |
pick |
boolean |
No | None |
Manifest Enumerations¶
The value types in src/builder/include/caliper_builder/spec/piece.h define fixed string enumerations for piece manifests and program pins.
| Enumeration | Allowed Values |
|---|---|
Quantitative Limits¶
Every limit in caliper_builder::spec::piece_limits (src/builder/include/caliper_builder/spec/piece.h) bounds memory, pass counts, and WebGPU bindings.
The manifest validator in src/builder/programs/piece_checks.cpp checks every product in 64-bit arithmetic before buffer allocation.
| Constant | Limit | Purpose |
|---|---|---|
kNameMax |
32 |
[a-z][a-z0-9_]{0,31} |
kVersionMax |
1,000,000 |
Piece limit |
kDescriptionMax |
256 |
Piece limit |
kInputs |
8 |
tensors and buffers that a piece reads |
kParams |
16 |
Piece limit |
kResources |
8 |
published or private resources of a piece |
kImports |
8 |
lib modules |
kDepends |
8 |
Piece limit |
kFields |
16 |
fields of one layout |
kStrideMax |
256 |
bytes of one element |
kCountMax |
33,554,432 |
elements of one buffer: 128 MiB of 4-byte elements |
kTextureSideMax |
8,192 |
pixels of one texture side: WebGPU's default |
kResourceBytesMax |
67,108,864 (64 MiB) |
bytes of one private resource or draw buffer |
kPublishedResourceBytesMax |
134,217,728 (128 MiB) |
Published buffers retain WebGPU's 128 MiB storage binding limit. Textures can hold every texel of an 8,192 by 8,192 RGBA8 or R32 image, 256 MiB. |
kPublishedTextureBytesMax |
268,435,456 (256 MiB) |
Piece limit |
kPublishedBytesMax |
536,870,912 (512 MiB) |
Bytes of all published resources of a piece together, 512 MiB: one version of each fits the step history's resource budget. A version above 8 MiB goes to a viewer in parts of 8 MiB, each while the viewer's queue holds at most 8 MiB and 64 KiB, half of the 16 MiB control queue of either sender (python/caliper/_programs.py, PUBLISHED_BYTES_MAX, PART_BYTES and RESOURCE_BACKLOG_BYTES). |
kKeepDefault |
256 |
kept versions of a resource in the step history |
kKeepMax |
4,096 |
Piece limit |
kDerivePasses |
8 |
Piece limit |
kDrawPasses |
16 |
Piece limit |
kDrawBuffers |
4 |
buffers that the draw half keeps between frames |
kTargets |
4 |
offscreen targets |
kFileBytes |
65,536 |
each WGSL file |
kSampleBytes |
1,048,576 (1 MiB) |
all sample files of a piece |
kInstancesMax |
4,194,304 |
Piece limit |
kVerticesMax |
65,536 |
vertices of one instance |
kWorkgroupsMax |
65,535 |
each of three dispatch counts |
kFrameMsDefault |
4.0 |
GPU time of the draw half in one frame |
kFrameMsMax |
16.0 |
Piece limit |
kDrawMemoryMbDefault |
64 |
resources, draw buffers and targets in the viewer |
kDrawMemoryMbMax |
512 |
Piece limit |
kPickFields |
8 |
Piece limit |
kStrings |
4,096 |
strings of the literal text table |
kBufferStrings |
8,224 |
reference nodes plus token labels |
kStringBytes |
64 |
Piece limit |
kLabels |
512 |
labels drawn in one frame, as place_labels |
Composed Module Bindings¶
Piece WGSL files never declare @group or @binding attributes because the composer generates all bindings from piece.toml.
The constants in src/builder/include/caliper_builder/programs/pieces.h fix the bind group and prelude layout across Metal, Vulkan, and WebGPU.
| Constant | Value | Binding Role |
|---|---|---|
kPreludeVersion |
1 |
Composer constant |
kGroupPrelude |
0 |
draw: the prelude and params; derive: caliper, params, shapes |
kGroupInputs |
1 |
derive: the tensors; draw: counts, resources, buffer inputs |
kGroupResources |
2 |
derive: resources and counters; draw: draw buffers, read targets |
kBindingView |
0 |
var<uniform> caliper_view: CaliperView |
kBindingSelection |
1 |
var<storage, read> caliper_selection |
kBindingLinear |
2 |
caliper_linear: sampler |
kBindingNearest |
3 |
caliper_nearest: sampler |
kBindingColormaps |
4 |
caliper_colormaps: texture_2d<f32> |
kBindingParams |
5 |
var<uniform> params: Params, when the piece has params |
kViewBytes |
288 |
the size of CaliperView |
kSelectedBytes |
32 |
the size of CaliperSelected |
kMaxSelected |
256 |
entries of caliper_selection |
Validation and Host Refusal Codes¶
The composer, manifest validator (piece_checks.cpp), WGSL reflection checker, and host runtimes return structured piece.* and program.* codes.
| Code | Constant | Stage | Condition |
|---|---|---|---|
program.not_built |
kProgramNotBuilt |
Composer and reflection | A part of programmable graphics that this build does not have yet. |
piece.bad_name |
kPieceBadName |
Composer and reflection | a name or version outside its form |
piece.bad_manifest |
kPieceBadManifest |
Manifest check | a key, count or value of piece.toml |
piece.bad_path |
kPieceBadPath |
Manifest check | a file outside its folder, a link, or another name |
piece.unknown_import |
kPieceUnknownImport |
Manifest check | no such lib module, or m::item names none |
piece.not_found |
kPieceNotFound |
Composer and reflection | a command names no such piece |
piece.missing |
kPieceMissing |
Composer and reflection | a program pins a piece that its source lacks |
piece.hash_mismatch |
kPieceHashMismatch |
Composer and reflection | the pinned hash differs from the piece's |
piece.exists |
kPieceExists |
Composer and reflection | that name and version exist in the workspace |
piece.read_only |
kPieceReadOnly |
Composer and reflection | a library piece |
piece.in_use |
kPieceInUse |
Composer and reflection | the open spec pins that version |
piece.bad_binding |
kPieceBadBinding |
Manifest check | an input unbound, or bound to another dtype, rank or layout |
piece.cycle |
kPieceCycle |
Manifest check | buffer inputs of programs form a cycle |
program.form_mixed |
kProgramFormMixed |
Composer and reflection | keys of the one-pass form and a pin |
program.bad_resource |
kProgramBadResource |
Manifest check | kind, count, size or a duplicate id |
program.bad_layout |
kProgramBadLayout |
Manifest check | a field's name or type, or a stride |
program.unknown_resource |
kProgramUnknownResource |
Manifest check | a pass, a pick or a text names none |
program.bad_pass |
kProgramBadPass |
Manifest check | a pass's kind, entry, target or values |
program.target_cycle |
kProgramTargetCycle |
Manifest check | a pass reads its own target, or before a write |
program.bad_pick |
kProgramBadPick |
Manifest check | the item map names no field or no pick pass |
program.bad_text |
kProgramBadText |
Manifest check | the text table's anchors or strings |
program.camera_conflict |
kProgramCameraConflict |
Composer and reflection | two programs of a panel select two cameras |
program.binding_not_allowed |
kProgramBindingNotAllowed |
Composer and reflection | a file declares @group or @binding |
program.reserved_name |
kProgramReservedName |
Composer and reflection | a caliper_ or Caliper name, or a name with "__" |
program.entry_stage |
kProgramEntryStage |
Composer and reflection | an entry point of the wrong stage, or none |
program.interface_mismatch |
kProgramInterfaceMismatch |
Composer and reflection | stage interfaces, or a fragment's outputs and its target, disagree |
program.over_web_limits |
kProgramOverWebLimits |
Manifest check | over a default limit of WebGPU |
program.workgroup_memory |
kProgramWorkgroupMemory |
Composer and reflection | a compute entry uses var<workgroup> |
program.resources_unavailable |
kProgramResourcesUnavailable |
Host runtime | no capability "resources" |
program.resource_too_large |
kProgramResourceTooLarge |
Host runtime | a version over its bytes |
program.draw_over_time |
kProgramDrawOverTime |
Host runtime | over frame_ms for 30 frames in a row |
program.draw_timeout |
kProgramDrawTimeout |
Host runtime | a frame not done after 1 s |
program.draw_over_memory |
kProgramDrawOverMemory |
Host runtime | over draw.memory_mb |
program.browser_refused |
kProgramBrowserRefused |
Host runtime | WebGPU refused a module or a pipeline |