Statements and expressions
The statements are TypeScript's, and each one means what the WGSL beside it means. The emitted text comes from one file compiled at build time, so the parentheses and the folded constants are the writer's own.
let a = (uv.x * 2.0);const a = uv.x * 2.A WGSL let is a value that stays as it was, which is what const says in TypeScript.
var b: f32 = uv.y;let b = uv.yA WGSL var is a local that changes. let b: f32 with no initializer declares one and leaves the value for a later assignment; WGSL zeroes it and GLSL leaves it undefined, so assign before you read (Rule 7.6not yet enforced by the compiler).
for (var i: i32 = 0; (i < 4); i = (i + 1)) {for (let i: i32 = 0; i < 4; i++)A for is counted: an integer induction variable, a constant step, and an exit that compares it to a bound the body does not write. The start and the bound may be runtime values, and no trip count is too many. The step may be +=, -=, *= or /=.
for (var _w: i32 = 0; (w < 4); _w = (_w + 1)) {while (w < 4)A while takes the place of loop. It is an open loop: it ends when its condition fails, or at a break or a return, and while (true) needs one of the two in its body.
switch i32(b) {switch (i32(b))Each case ends with break, which a WGSL case does without and the lowering drops. A case whose end is reachable would run on into the next case in TypeScript, so it is refused (TS8017). The last case needs no break. A label is an integer constant that may appear once. Two labels stacked over one body are one case with two selectors, case 0, 1: on WGSL.
let c = select(b, a, (uv.x > 0.5));const c = uv.x > 0.5 ? a : bWGSL has no ternary, so a scalar or vector conditional becomes select, whose first argument is the arm the condition does not choose. A conditional on a struct or an array is hoisted into a slot and an if, since neither target has an operator for that.
bump(u32(b));bump(u32(b))A function called for what it does, with its result dropped.
_ = atomicAdd(&counter, 1u);atomicAdd(counter, 1)A value-returning builtin dropped the same way takes the phony assignment, because Tint reads every such builtin as @must_use.
discard;discardThe same word, and the same statement.
struct VsIn { @location(0) pos: vec3<f32>,}class VsIn { @location(0) pos: vec3 }A WGSL struct is a class. A type alias of an object shape and an interface both reach the same declaration.
fn bump(i: u32) {function bump(i: u32): voidA function with no stage decorator is a helper of the module.