Standard library

Standard-library index

TinyFX embeds the source files in std/ into every program at compiler build time. They are ordinary TinyFX source, so their gpu functions are checked and lowered through the same VM/WGSL paths as application code. The standard library is always present; an import under /_std/ is accepted only as source organization and does not load a separate package.

This is a module map, not an exhaustive API listing. The generated operation reference is the source of truth for builtin and host signatures; the checked std/*.tfx files are the source of truth for standard-library function bodies.

Modules

Source filePublic surfacePurpose
bezier.tfxbezier::Quadratic/cubic curve evaluation and easing helpers.
color.tfxRoot color helpers and color::Color conversion, palette, and color utility functions.
env.tfxenv, camera/input/stats typesPer-frame environment state, camera types, and host-control wrappers.
image.tfximage::GPU image-sampling helpers, including a Gaussian tap helper.
math.tfxRoot helpersExtra GPU math, remapping, and screen-space helpers.
matrix.tfxmatrix::Right-handed, column-major WebGPU transform and projection builders.
meshx.tfxmesh:: additionsGPU procedural vertex-position helpers that complement native mesh operations.
model.tfxmodel::, ModelPartCPU helpers for enumerating loaded model parts.
noise.tfxnoise::GPU-compatible value, Perlin, simplex, fbm, Voronoi, and related noise.
options.tfxOption enumsClosed enum values for drawing, depth, texture formats, and paint composition.
profile.tfxProfileStatsThe public shape returned by profiling snapshots.
quat.tfxquat::Quaternion construction, composition, rotation, and conversion helpers.
sdf.tfxsdf::Signed-distance primitives and composition operations.
spatial.tfxspatial::Cantor, Hilbert, and Morton spatial encodings.
storage.tfxStorageResult, storage::Persistent JSON key-value wrappers with recoverable results.

The table is deliberately complete for embedded modules as of this checkout, but it does not enumerate every function. Empty structs with static methods are namespaces, hence source file meshx.tfx intentionally contributes to mesh::, not meshx::.

Options

options.tfx defines nominal enums rather than stringly typed renderer settings:

  • Blend selects color blend behavior.
  • DepthCompare selects a draw pass's depth comparison; its disabled member disables both depth testing and writes.
  • DepthConvention couples a projection convention with its automatic depth clear and default comparison.
  • TextureFormat selects storage for new textures.
  • PaintComposite selects Canvas2D composition for paint operations.

DepthConvention.standard uses the finite-far projection convention, an automatic clear value of 1, and DepthCompare.lessEqual by default. DepthConvention.reverseZ uses an infinite-far reverse-Z convention, an automatic clear value of 0, and DepthCompare.greaterEqual by default. A draw can explicitly override the comparison, but the convention remains the owner of automatic depth clears. Read drawing and depth before mixing explicit depth textures, feedback, and fragment depth.

The rgba* formats apply to texture2d<float4> and texture3d<float4>. TextureFormat.r16Float and TextureFormat.r32Float are single-channel color formats for texture2d<float> and texture3d<float>; scalar textures default to r32Float. r16Float supports portable filtering, rendering, and blending, but not storage writes. r32Float preserves full precision and supports portable storage writes, but uses nearest non-filtering sampling and does not offer portable blending. TextureFormat.depth32Float is only for texture2d<float> depth textures. See buffers and texture ownership for operation-specific limits.

Environment and profiling

env.tfx defines the env global the runtime updates before each frame. It contains time, input, camera state, screen size, and a non-blocking runtime metrics snapshot. Its camera configuration and stats-overlay wrappers are ordinary TinyFX methods over host operations. Runtime covers the frame lifecycle and input/camera ownership.

profile.tfx defines ProfileStats: inclusive CPU/GPU timing fields, render and compute partitions, a call count, and GPU-timestamp availability. The profile::latest("path") operation itself is compiler/runtime implemented; the result type remains ordinary standard-library source. Timings do not force a GPU wait: unavailable or incomplete GPU timing is represented by -1, while the availability flag says whether timestamp timing exists. See profiling.

Relationship to other APIs

The embedded standard library is not the entire public API. Builtins and host operations cover scalar/vector math, collections, shaders, textures, buffers, meshes, UI, assets, media, persistent storage, and platform operations. Their declarations are generated into the operation reference, which also marks CPU, GPU, fragment-only, and target-specific availability.

  • Language explains how names and standard-library imports fit into one program namespace.
  • Types explains option enums, ModelPart, and CPU/GPU data boundaries.
  • Functions explains gpu standard-library helpers and static namespace calls.
  • GPU programming explains standard-library use in shaders, draw passes, and kernels.
  • Assets and media explains models, textures, cameras, microphones, and video.
  • Runtime explains JSON persistence, application namespaces, quotas, and migration expectations.