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.yfor (var i: i32 = 0; (i < n); i = (i + 1)) {for (let i: i32 = 0; i < n; i++)A for means what it means in TypeScript. The compiler records it as counted when it has an integer induction variable, a constant step, and an exit that compares the variable to a bound the body does not write; any other for is an open loop, as a while is. 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, and so is one whose arm is costly: a call of a function of the file, a texture read, or eight or more operations, so the arm not taken does not run.
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>,}interface VsIn { pos: location<0, 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 attribute is a helper of the module.