Entry points and attributes
A stage is an attribute on a function declaration, @vertex, @fragment or @compute([…]). A function with no stage attribute is a helper. @compute takes dimensions as a list of numbers or named overrides, and numeric dimensions remain valid.
@vertex@vertexOne stage attribute per entry point, on its function declaration.
@fragment@fragmentA fragment entry may also return nothing, which is what a program that only writes to a storage binding does.
@compute @workgroup_size(64)@compute([64, 1, 1])The list is the workgroup size, one to three extents.
@location(0) uv: vec2<f32>uv: location<0, vec2>A location sits on an entry parameter, on a class field and on the return.
-> @builtin(position) vec4<f32>: vec4A return typed vec4 carries the position builtin on its own, so the smallest vertex shader needs no struct and no parameters.
@builtin(position) pos: vec4<f32>pos: builtin<"position">A struct return carries the position in a field and adds as many varyings beside it as the program wants.
-> @location(0) vec4<f32>: vec4A bare fragment return takes location 0 at any width, so f32, vec2, vec3 and vec4 are all draw-buffer formats. A struct return is the multiple-render-target form.
A vertex entry has to produce a position. A return typed vec4 carries the position builtin on its own, and a struct return carries it in a field and adds as many location<n, T> varyings as the program wants. A struct return with no position field, a void return and a bare type that is not a vec4 are each refused, naming the field or the type to write.
WGSL declares the value with a module-level override, and @workgroup_size can use its name. TypeShade can use the same override for the outer length of a workgroup array.
The vocabulary of builtin<N> is WGSL's, 18 names passed through as a string, so the WGSL attribute is the same id with no quotes around it. A typo is an error at the line the author wrote, since the type argument is a closed union of them. WGSL fixes the type of every id but one, so the type column shows the type each value has; only clip_distances takes a written type.
builtin<"vertex_index", T>u32builtin<"instance_index", T>u32builtin<"position", T>vec4<f32>builtin<"front_facing", T>boolbuiltin<"frag_depth", T>f32builtin<"sample_index", T>u32builtin<"sample_mask", T>u32builtin<"primitive_index", T>u32builtin<"local_invocation_id", T>vec3<u32>builtin<"local_invocation_index", T>u32builtin<"global_invocation_id", T>vec3<u32>builtin<"workgroup_id", T>vec3<u32>builtin<"num_workgroups", T>vec3<u32>builtin<"subgroup_invocation_id", T>u32builtin<"subgroup_size", T>u32builtin<"subgroup_id", T>u32builtin<"num_subgroups", T>u32builtin<"clip_distances", T>The one id with no fixed type. The array length is the author's.
Three names a GLSL author reaches for have no WGSL builtin behind them. The front end refuses each one at the declaration and lists the names it does take. The right column is the sentence the backends print after the attribute name, which says what to reach for instead.
@builtin(point_size)does not exist in WGSL — WebGPU point-list primitives are always 1px. Expand an instanced quad in the vertex stage instead
@builtin(point_coord)does not exist in WGSL — there is no point-sprite coordinate. Interpolate a @location(n) corner uv from the expanded quad instead
@builtin(frag_coord)does not exist in WGSL — the fragment-stage framebuffer coordinate (GLSL gl_FragCoord) is @builtin(position) on a fragment entry parameter.