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:
| Field | Type | Meaning |
|---|---|---|
frame.time / frame.dt | f32 | Seconds since start / since last frame |
frame.index | i32 | Frame counter |
frame.mouse_x / frame.mouse_y | f32 | Pointer position (normalized) |
frame.mouse_down | bool | Button state |
frame.drag_dx / frame.drag_dy | f32 | Drag delta this frame |
frame.wheel | f32 | Scroll delta |
frame.clicked / frame.double_clicked | bool | Click events |