docs / GPU Programming / Interactive Frames

Interactive frames — gpu frame

Everything so far launches once and finishes. gpu frame declares a kernel that re-runs every display frame — the construct behind every demo in the GPU Playground:

use system.io
use system.gpu

fn main()
    gpu let a = [0.0, 0.0, 0.0, 0.0]
    gpu var b = [0.0, 0.0, 0.0, 0.0]
    gpu frame i in 0..4:
        let t = frame.time
        let d = frame.dt
        b[i] = a[i] + t + d
    println("ok")

A frame kernel reads one immutable buffer (gpu let) and writes mutable ones (gpu var) — reading and writing the same buffer in one pass is a compile-time data-race error. Multi-pass frame graphs nest ordered gpu forall passes inside a gpu frame block. Each pass's read/write sets must be disjoint, and the compiler checks that per pass. The Game of Life (5 passes) and Fluid (pressure-solve chain) demos are the reference frame graphs.

Inside a frame body, the frame context carries per-frame inputs, delivered as one uniform block:

FieldTypeMeaning
frame.time / frame.dtf32Seconds since start / since last frame
frame.indexi32Frame counter
frame.mouse_x / frame.mouse_yf32Pointer position (normalized)
frame.mouse_downboolButton state
frame.drag_dx / frame.drag_dyf32Drag delta this frame
frame.wheelf32Scroll delta
frame.clicked / frame.double_clickedboolClick events