Builtins

Builtins

96 members

The math, vector and texture functions a shader calls, spelled once for both targets.

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

abs Function
abs(x): absolute value, component-wise.
acos Function
acos(x): arccosine of x, returning radians in [0, π], component-wise.
acosh Function
acosh(x): inverse hyperbolic cosine, component-wise.
add Function
a + b as a free function, the spelling for an expression whose left operand is a literal.
asin Function
asin(x): arcsine of x, returning radians in [-π/2, π/2], component-wise.
asinh Function
asinh(x): inverse hyperbolic sine, component-wise; defined over all reals.
atan Function
atan(x): single-argument arctangent, returning radians in (-π/2, π/2), component-wise.
atan2 Function
atan2(y, x): two-argument arctangent, resolving the full angle in [-π, π] from a (y, x) pair.
atanh Function
atanh(x): inverse hyperbolic tangent, component-wise.
bitcastF32 Function
Reinterpret the bit pattern of a u32 as an f32, the inverse of bitcastU32.
bitcastU32 Function
Reinterpret the bit pattern of an f32 as a u32.
ceil Function
ceil(x): round toward +∞, component-wise.
clamp Function
clamp(x, lo, hi): restricts x to [lo, hi], component-wise.
cos Function
cos(x): cosine of x in radians, component-wise.
cosh Function
cosh(x): hyperbolic cosine, component-wise; the even partner of sinh.
cross Function
cross(a, b): 3-D cross product of two vec3<f32> values.
degrees Function
degrees(rad): radians to degrees, component-wise, with the built-in's exact 180/π; the inverse of radians.
distance Function
distance(a, b): |a − b|, vector to scalar; the built-in form of length(a.sub(b)).
div Function
a / b as a free function, for a literal numerator: div(1, x) is the reciprocal, and emits (1.0 / x).
dot Function
dot(a, b): dot product, vector to scalar.
dpdx Function
dpdx(x): the screen-space partial derivative of x along the X axis, component-wise.
dpdy Function
dpdy(x): the screen-space partial derivative of x along the Y axis, component-wise; the partner of dpdx, with the same GPU-only and fragment-only constraints.
exp Function
exp(x): eˣ, component-wise. exp2 is the base-2 form.
exp2 Function
exp2(x): 2ˣ, component-wise; the inverse of log2.
f64FromParts Function
Assemble an f64 from its (hi, lo) f32 halves, the shader-side counterpart of splitF64 for a value that arrives as two f32 components.
f64GuardOne Function
The anti-fast-math guard value of the f64 emulation: a 1.0 the GPU compiler cannot see through, emitted per target as a texel fetch from the guard texture that fp64Guard declares.
f64Parts Function
The (hi, lo) pair of an f64 as a plain vec2<f32>, for storing an f64 into a vec2 buffer field or stage output.
floor Function
floor(x): round toward −∞, component-wise.
fma Function
fma(a, b, c): fused multiply-add, a·b + c.
fract Function
fract(x): fractional part, x − floor(x), component-wise.
fwidth Function
fwidth(x): abs(dpdx(x)) + abs(dpdy(x)), the screen-space derivative magnitude, component-wise.
insideRange Function
In-range predicate: x >= lo && x <= hi.
inverseSqrt Function
inverseSqrt(x): 1/√x, component-wise.
length Function
length(v): Euclidean vector magnitude, |v|.
log Function
log(x): natural logarithm, component-wise.
log2 Function
log2(x): base-2 logarithm, component-wise; the inverse of exp2.
madd Function
Multiply-add, a*b + c, written as the plain a.mul(b).add(c) chain.
mat2f64 Function
An emulated-double mat2x2<f64> constructor, column-major: one vec2<f64> argument per column, the same convention as WGSL's mat2x2.
mat3f64 Function
An emulated-double mat3x3<f64> constructor, column-major, the 3×3 sibling of mat2f64; that entry has the column-argument convention and the transform helpers.
mat4f64 Function
An emulated-double mat4x4<f64> constructor, column-major, the 4×4 sibling of mat2f64; that entry has the column-argument convention and the transform helpers.
max Function
max(a, b): component-wise maximum, the partner of min(/api/min/).
min Function
min(a, b): component-wise minimum.
mix Function
mix(a, b, t): linear interpolation a + t·(b − a), component-wise, keyed by a.
mod Function
Floor modulo: x - y * floor(x / y), with identical semantics on both targets.
mul Function
a * b as a free function, for a literal left operand: mul(2, x) emits (2.0 * x).
mulMat64 Function
matNxN<f64> × matNxN<f64> → matNxN<f64>: the emulated-double matrix product.
normalize Function
normalize(v): v/|v|, keeping the vector key.
optBarrier Function
An optimization barrier on one f32 value, the shader equivalent of C's volatile.
outsideRange Function
Out-of-range predicate: x < lo || x > hi.
pack2x16float Function
Pack a vec2<f32> into a u32 as two IEEE-754 binary16 (half) values, component 0 in the 16 low bits.
pack2x16snorm Function
Pack a vec2<f32> into a u32 as two 16-bit snorm values, ⌊0.5 + 32767·clamp(x, -1, 1)⌋ per component in two's complement, component 0 in the 16 low bits.
pack2x16unorm Function
Pack a vec2<f32> into a u32 as two 16-bit unorm values, ⌊0.5 + 65535·clamp(x, 0, 1)⌋ per component, component 0 in the 16 low bits.
pack4x8unorm Function
Pack a vec4<f32> into a u32 RGBA8.
pow Function
pow(a, b): a raised to the power b, component-wise.
radians Function
radians(deg): degrees to radians, component-wise, with the built-in's exact π/180.
round Function
round(x): nearest integer, ties to even, component-wise, on both targets.
saturate Function
saturate(x): clamp(x, 0, 1), component-wise, the standard normalized-range clamp for colour channels, interpolation factors and coverage.
select Function
select: the free-function form of ReadonlyNode.select.
sign Function
sign(x): -1, 0 or 1 per component, according to the sign of x.
sin Function
sin(x): sine of x in radians, component-wise.
sinh Function
sinh(x): hyperbolic sine, component-wise.
smoothstep Function
smoothstep(e0, e1, x): Hermite interpolation from 0 at x = e0 to 1 at x = e1, component-wise.
sqrt Function
sqrt(x): square root, component-wise.
step Function
step(edge, x): 0 where x < edge, else 1, component-wise.
sub Function
a - b as a free function.
tan Function
tan(x): tangent of x in radians, component-wise.
tanh Function
tanh(x): hyperbolic tangent, component-wise; sinh(x)/cosh(x), saturating to ±1 as x → ±∞.
textureDimensions Function
Texture extent in texels, as a vec2<u32>.
textureLoad Function
Load one texel from a 2D texture at integer coordinates, returning vec4<f32>, vec4<u32> or vec4<i32> to match the texture's element.
textureNumLayers Function
How many layers a 2D array texture has, as a u32.
textureSample Function
Sample a 2D texture, returning vec4<f32>.
textureSampleLevel Function
Sample a 2D texture at an explicit mip level, returning vec4<f32>.
toF32 Function
Convert to f32. On an f64 argument this is the explicit, precision-losing narrow, computed as the sum of the hi and lo halves; f64 never narrows implicitly.
toF64 Function
Widen f32 to f64, exactly (the result is the pair (x, 0.0)).
toI32 Function
Convert to i32: the explicit numeric cast, where i32(/api/i32/) builds a literal from a JS number.
toU32 Function
Convert to u32: the explicit numeric cast, where u32(/api/u32/) builds a literal from a JS number.
transformMat4 Function
mat4x4<f32> × vec4<f32> → vec4<f32>: the matrix-vector product, as in a model-view-projection transform.
transformMat64 Function
matNxN<f64> × vecN<f64> → vecN<f64>: the emulated-double matrix-vector product.
transpose64 Function
Transpose of an emulated-double matrix.
trunc Function
trunc(x): round toward zero, component-wise.
unpack2x16float Function
Unpack a u32 into a vec2<f32> of two binary16 (half) values, the exact inverse of pack2x16float.
unpack2x16snorm Function
Unpack a u32 of two 16-bit snorm values into a vec2<f32> in -1,1 (max per component), the inverse of pack2x16snorm.
unpack2x16unorm Function
Unpack a u32 of two 16-bit unorm values into a vec2<f32> in 0,1, the inverse of pack2x16unorm.
unpack4x8unorm Function
Unpack a u32 RGBA8 into a vec4<f32>.
vec2 Function
A vec2<f32> constructor, WGSL-style: vec2(x, y).
vec2f64 Function
An emulated-double vec2<f64> constructor.
vec2i Function
A vec2<i32> constructor, WGSL-style: vec2i(x, y).
vec2u Function
A vec2<u32> constructor, WGSL-style: vec2u(x, y).
vec3 Function
A vec3<f32> constructor, WGSL-style: vec3(x, y, z).
vec3f64 Function
An emulated-double vec3<f64> constructor, the three-component sibling of vec2f64; that entry has the splat, split and widen rules every vecNf64 constructor shares.
vec3i Function
A vec3<i32> constructor, WGSL-style: vec3i(x, y, z).
vec3u Function
A vec3<u32> constructor, WGSL-style: vec3u(x, y, z).
vec4 Function
A vec4<f32> constructor, WGSL-style: vec4.
vec4f64 Function
An emulated-double vec4<f64> constructor, the four-component sibling of vec2f64; that entry has the splat, split and widen rules every vecNf64 constructor shares.
vec4i Function
A vec4<i32> constructor, WGSL-style: vec4i.
vec4u Function
A vec4<u32> constructor, WGSL-style: vec4u.

Edit this page Report a problem