Builtins
96 members
IR builder functions for math, vector and texture operations. Each returns an IR node. A shader file calls the builtins that the language reference lists.
The signature, the description and the examples come from the compiler's own source at commit af54ddad5.
-
absFunction abs(x): absolute value, component-wise.-
acosFunction acos(x): arccosine of x, returning radians in [0, π], component-wise.-
acoshFunction acosh(x): inverse hyperbolic cosine, component-wise.-
addFunction - a + b as a free function, the spelling for an expression whose left operand is a literal.
-
asinFunction asin(x): arcsine of x, returning radians in [-π/2, π/2], component-wise.-
asinhFunction asinh(x): inverse hyperbolic sine, component-wise; defined over all reals.-
atanFunction atan(x): single-argument arctangent, returning radians in (-π/2, π/2), component-wise.-
atan2Function atan2(y, x): two-argument arctangent, resolving the full angle in [-π, π] from a (y, x) pair.-
atanhFunction atanh(x): inverse hyperbolic tangent, component-wise.-
bitcastF32Function - Reinterpret the bit pattern of a
u32as anf32, the inverse of bitcastU32. -
bitcastU32Function - Reinterpret the bit pattern of an
f32as au32. -
ceilFunction ceil(x): round toward +∞, component-wise.-
clampFunction clamp(x, lo, hi): restricts x to [lo, hi], component-wise.-
cosFunction cos(x): cosine of x in radians, component-wise.-
coshFunction cosh(x): hyperbolic cosine, component-wise; the even partner of sinh.-
crossFunction cross(a, b): 3-D cross product of twovec3<f32>values.-
degreesFunction degrees(rad): radians to degrees, component-wise, with the built-in's exact 180/π; the inverse of radians.-
distanceFunction distance(a, b): |a − b|, vector to scalar; the built-in form of length(a.sub(b)).-
divFunction - a / b as a free function, for a literal numerator: div(1, x) is the reciprocal, and emits (1.0 / x).
-
dotFunction dot(a, b): dot product, vector to scalar.-
dpdxFunction dpdx(x): the screen-space partial derivative of x along the X axis, component-wise.-
dpdyFunction 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.-
expFunction exp(x): eˣ, component-wise.exp2is the base-2 form.-
exp2Function exp2(x): 2ˣ, component-wise; the inverse oflog2.-
f64FromPartsFunction - Assemble an
f64from its (hi, lo)f32halves, the shader-side counterpart of splitF64 for a value that arrives as twof32components. -
f64GuardOneFunction - The anti-fast-math guard value of the
f64emulation: a 1.0 the GPU compiler cannot see through, emitted per target as a texel fetch from the guard texture that fp64Guard declares. -
f64PartsFunction - The (hi, lo) pair of an
f64as a plainvec2<f32>, for storing anf64into avec2buffer field or stage output. -
floorFunction floor(x): round toward −∞, component-wise.-
fmaFunction fma(a, b, c): multiply-add, a·b + c, component-wise for vectors.-
fractFunction fract(x): fractional part, x −floor(x), component-wise.-
fwidthFunction fwidth(x): abs(dpdx(x)) + abs(dpdy(x)), the screen-space derivative magnitude, component-wise.-
insideRangeFunction - In-range predicate: x >= lo && x <= hi.
-
inverseSqrtFunction inverseSqrt(x): 1/√x, component-wise.-
lengthFunction length(v): Euclidean vector magnitude, |v|.-
logFunction log(x): natural logarithm, component-wise.-
log2Function log2(x): base-2 logarithm, component-wise; the inverse ofexp2.-
maddFunction - Multiply-add, a*b + c, written as the plain a.mul(b).add(c) chain.
-
mat2f64Function - An emulated-double
mat2x2<f64>constructor, column-major: onevec2<f64>argument per column, the same convention as WGSL'smat2x2. -
mat3f64Function - 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. -
mat4f64Function - 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. -
maxFunction max(a, b): component-wise maximum, the partner ofmin(/api/min/).-
minFunction min(a, b): component-wise minimum.-
mixFunction mix(a, b, t): linear interpolation a + t·(b − a), component-wise, keyed by a.-
modFunction - Floor modulo: x - y *
floor(x / y), with identical semantics on both targets. -
mulFunction - a * b as a free function, for a literal left operand: mul(2, x) emits (2.0 * x).
-
mulMat64Function - matNxN<
f64> × matNxN<f64> → matNxN<f64>: the emulated-double matrix product. -
normalizeFunction normalize(v): v/|v|, keeping the vector key.-
optBarrierFunction - An optimization barrier on one
f32value, the shader equivalent of C's volatile. -
outsideRangeFunction - Out-of-range predicate: x < lo || x > hi.
-
pack2x16floatFunction - Pack a
vec2<f32>into au32as two IEEE-754 binary16 (half) values, component 0 in the 16 low bits. -
pack2x16snormFunction - Pack a
vec2<f32>into au32as 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. -
pack2x16unormFunction - Pack a
vec2<f32>into au32as two 16-bit unorm values, ⌊0.5 + 65535·clamp(x, 0, 1)⌋ per component, component 0 in the 16 low bits. -
pack4x8unormFunction - Pack a
vec4<f32>into au32RGBA8. -
powFunction - pow(a, b): a raised to the power b, component-wise.
-
radiansFunction radians(deg): degrees to radians, component-wise, with the built-in's exact π/180.-
roundFunction round(x): nearest integer, ties to even, component-wise, on both targets.-
saturateFunction saturate(x):clamp(x, 0, 1), component-wise, the standard normalized-range clamp for colour channels, interpolation factors and coverage.-
selectFunction - select: the free-function form of ReadonlyNode.select.
-
signFunction sign(x): -1, 0 or 1 per component, according to the sign of x.-
sinFunction sin(x): sine of x in radians, component-wise.-
sinhFunction sinh(x): hyperbolic sine, component-wise.-
smoothstepFunction smoothstep(e0, e1, x): Hermite interpolation from 0 at x = e0 to 1 at x = e1, component-wise.-
sqrtFunction sqrt(x): square root, component-wise.-
stepFunction step(edge, x): 0 where x < edge, else 1, component-wise.-
subFunction - a - b as a free function.
-
tanFunction tan(x): tangent of x in radians, component-wise.-
tanhFunction tanh(x): hyperbolic tangent, component-wise;sinh(x)/cosh(x), saturating to ±1 as x → ±∞.-
textureDimensionsFunction - Texture extent in texels, as a
vec2<u32>. -
textureLoadFunction - Load one texel from a 2D texture at integer coordinates, returning
vec4<f32>,vec4<u32>orvec4<i32>to match the texture's element. -
textureNumLayersFunction - How many layers a 2D array texture has, as a
u32. -
textureSampleFunction - Sample a 2D texture, returning
vec4<f32>. -
textureSampleLevelFunction - Sample a 2D texture at an explicit mip level, returning
vec4<f32>. -
toF32Function - Convert to
f32. On anf64argument this is the explicit, precision-losing narrow, computed as the sum of the hi and lo halves;f64never narrows implicitly. -
toF64Function - Widen
f32tof64, exactly (the result is the pair (x, 0.0)). -
toI32Function - Convert to
i32: the explicit numeric cast, wherei32(/api/i32/) builds a literal from a JS number. -
toU32Function - Convert to
u32: the explicit numeric cast, whereu32(/api/u32/) builds a literal from a JS number. -
transformMat4Function mat4x4<f32>×vec4<f32>→vec4<f32>: the matrix-vector product, as in a model-view-projection transform.-
transformMat64Function - matNxN<
f64> × vecN<f64> → vecN<f64>: the emulated-double matrix-vector product. -
transpose64Function - Transpose of an emulated-double matrix.
-
truncFunction trunc(x): round toward zero, component-wise.-
unpack2x16floatFunction - Unpack a
u32into avec2<f32>of two binary16 (half) values, the exact inverse ofpack2x16float. -
unpack2x16snormFunction - Unpack a
u32of two 16-bit snorm values into avec2<f32>in -1,1 (max per component), the inverse ofpack2x16snorm. -
unpack2x16unormFunction - Unpack a
u32of two 16-bit unorm values into avec2<f32>in 0,1, the inverse ofpack2x16unorm. -
unpack4x8unormFunction - Unpack a
u32RGBA8 into avec4<f32>. -
vec2Function - A
vec2<f32>constructor, WGSL-style:vec2(x, y). -
vec2f64Function - An emulated-double
vec2<f64>constructor. -
vec2iFunction - A
vec2<i32>constructor, WGSL-style:vec2i(x, y). -
vec2uFunction - A
vec2<u32>constructor, WGSL-style:vec2u(x, y). -
vec3Function - A
vec3<f32>constructor, WGSL-style:vec3(x, y, z). -
vec3f64Function - An emulated-double
vec3<f64>constructor, the three-component sibling ofvec2f64; that entry has the splat, split and widen rules every vecNf64 constructor shares. -
vec3iFunction - A
vec3<i32>constructor, WGSL-style:vec3i(x, y, z). -
vec3uFunction - A
vec3<u32>constructor, WGSL-style:vec3u(x, y, z). -
vec4Function - A
vec4<f32>constructor, WGSL-style:vec4. -
vec4f64Function - An emulated-double
vec4<f64>constructor, the four-component sibling ofvec2f64; that entry has the splat, split and widen rules every vecNf64 constructor shares. -
vec4iFunction - A
vec4<i32>constructor, WGSL-style:vec4i. -
vec4uFunction - A
vec4<u32>constructor, WGSL-style:vec4u.