Builtin functions
On this page

Builtin functions

A builtin is a function the GPU already has. A call carries one neutral name through the compiler, and each backend writes its own spelling for that name, so the call is written once and emitted twice. The registry holds 190 names.

How to read a row

The first column is the name the call carries, with a placeholder argument in each position it takes. The next two are the text the WGSL backend and the GLSL ES 3.00 backend write for that call, run from the compiler's own spelling table at the pinned commit. 44 of the names are spelled the same way on both targets, and 64 have no GLSL ES 3.00 form of their own, where the cell carries the compiler's own message: the writer has none, or a pass rewrites the call before the writer runs (the subgroup functions, which GLSL runs as one invocation). 27 answer to a Math. name as well, which the last column of the maths and cast tables shows. WGSL vs GLSL ES 3.00 compiles one shader to both targets and lists where they differ.

A few of these names are chosen by the compiler and never written by hand. A layered texture read, a depth comparison, a storage fetch and a texel read at an unsigned coordinate each take a name of their own, so the argument order of a call never depends on the texture it landed on. An abs of an unsigned value and an integer dot take one too, because GLSL ES 3.00 has no overload for either.

A name the file declares

A function the file declares wins over a builtin of the same name. Such a name meant the author's own function before it was a builtin, and an addition does not change what a program already means.

Maths

TypeShadeWGSLGLSL ES 3.00Math name
abs(a)
abs(a)
Math.abs
absU(a)
abs(a)
a
acos(a)
acos(a)
Math.acos
acosh(a)
acosh(a)
Math.acosh
all(a)
all(a)
any(a)
any(a)
asin(a)
asin(a)
Math.asin
asinh(a)
asinh(a)
Math.asinh
atan(a)
atan(a)
Math.atan
atan2(a, b)
atan(a, b)
Math.atan2
atanh(a)
atanh(a)
Math.atanh
ceil(a)
ceil(a)
Math.ceil
clamp(a, b, c)
clamp(a, b, c)
cos(a)
cos(a)
Math.cos
cosh(a)
cosh(a)
Math.cosh
degrees(a)
degrees(a)
exp(a)
exp(a)
Math.exp
exp2(a)
exp2(a)
floor(a)
floor(a)
Math.floor
fma(a, b, c)
((a) * (b) + (c))
fract(a)
fract(a)
inverseSqrt(a)
inversesqrt(a)
ldexp(a, b)
(a * intBitsToFloat(((b >> 1) + 127) << 23) * intBitsToFloat(((b - (b >> 1)) + 127) << 23))
log(a)
log(a)
Math.log
log2(a)
log2(a)
Math.log2
max(a, b)
max(a, b)
Math.max
min(a, b)
min(a, b)
Math.min
mix(a, b, c)
mix(a, b, c)
(a - b * floor(a / b))
mod(a, b)
pow(a, b)
pow(a, b)
Math.pow
quantizeToF16(a)
unpackHalf2x16(packHalf2x16(vec2(a, 0.0))).x
quantizeToF16Vec2(a)
quantizeToF16(a)
vec2(unpackHalf2x16(packHalf2x16(vec2(a.x, 0.0))).x, unpackHalf2x16(packHalf2x16(vec2(a.y, 0.0))).x)
quantizeToF16Vec3(a)
quantizeToF16(a)
vec3(unpackHalf2x16(packHalf2x16(vec2(a.x, 0.0))).x, unpackHalf2x16(packHalf2x16(vec2(a.y, 0.0))).x, unpackHalf2x16(packHalf2x16(vec2(a.z, 0.0))).x)
quantizeToF16Vec4(a)
quantizeToF16(a)
vec4(unpackHalf2x16(packHalf2x16(vec2(a.x, 0.0))).x, unpackHalf2x16(packHalf2x16(vec2(a.y, 0.0))).x, unpackHalf2x16(packHalf2x16(vec2(a.z, 0.0))).x, unpackHalf2x16(packHalf2x16(vec2(a.w, 0.0))).x)
radians(a)
radians(a)
round(a)
roundEven(a)
Math.round
saturate(a)
clamp(a, 0.0, 1.0)
select(a, b, c)
(c ? b : a)
sign(a)
sign(a)
Math.sign
sin(a)
sin(a)
Math.sin
sinh(a)
sinh(a)
Math.sinh
smoothstep(a, b, c)
smoothstep(a, b, c)
sqrt(a)
sqrt(a)
Math.sqrt
step(a, b)
step(a, b)
tan(a)
tan(a)
Math.tan
tanh(a)
tanh(a)
Math.tanh
trunc(a)
trunc(a)
Math.trunc

Geometry

TypeShadeWGSLGLSL ES 3.00
cross(a, b)
cross(a, b)
determinant(a)
determinant(a)
distance(a, b)
distance(a, b)
dot(a, b)
dot(a, b)
dotI(a, b)
dot(a, b)
_idot(a, b)
dotU(a, b)
dot(a, b)
_idot(a, b)
faceForward(a, b, c)
faceforward(a, b, c)
length(a)
length(a)
normalize(a)
normalize(a)
reflect(a, b)
reflect(a, b)
refract(a, b, c)
refract(a, b, c)
transpose(a)
transpose(a)

Derivatives

TypeShadeWGSLGLSL ES 3.00
dpdx(a)
dFdx(a)
dpdxCoarse(a)
dFdx(a)
dpdxFine(a)
dFdx(a)
dpdy(a)
dFdy(a)
dpdyCoarse(a)
dFdy(a)
dpdyFine(a)
dFdy(a)
fwidth(a)
fwidth(a)
fwidthCoarse(a)
fwidth(a)
fwidthFine(a)
fwidth(a)

Bit operations

TypeShadeWGSLGLSL ES 3.00
countLeadingZeros(a)
_clz(a)
countOneBits(a)
_popcnt(a)
countTrailingZeros(a)
_ctz(a)
dot4I8Packed(a, b)

dot4I8Packed is not supported yet on the WebGL2 tier

dot4U8Packed(a, b)

dot4U8Packed is not supported yet on the WebGL2 tier

extractBits(a, b, c)
_xbits(a, b, c)
firstLeadingBit(a)
_msb(a)
firstTrailingBit(a)
_lsb(a)
insertBits(a, b, c, d)
_ibits(a, b, c, d)
reverseBits(a)
_brev(a)

GLSL ES 3.00 has none of the bit builtins, so the column above names a small function the GLSL writer defines over the shifts, masks and comparisons that target does have. A module that calls none of them carries none of the definitions.

Packing

TypeShadeWGSLGLSL ES 3.00
pack2x16float(a)
packHalf2x16(a)
pack2x16snorm(a)
packSnorm2x16(a)
pack2x16unorm(a)
packUnorm2x16(a)
pack4x8snorm(a)
(uint(int(floor(0.5 + clamp(a.x, -1.0, 1.0) * 127.0)) & 0xFF) | (uint(int(floor(0.5 + clamp(a.y, -1.0, 1.0) * 127.0)) & 0xFF) << 8) | (uint(int(floor(0.5 + clamp(a.z, -1.0, 1.0) * 127.0)) & 0xFF) << 16) | (uint(int(floor(0.5 + clamp(a.w, -1.0, 1.0) * 127.0)) & 0xFF) << 24))
pack4x8unorm(a)
(uint(floor(0.5 + clamp(a.x, 0.0, 1.0) * 255.0)) | (uint(floor(0.5 + clamp(a.y, 0.0, 1.0) * 255.0)) << 8) | (uint(floor(0.5 + clamp(a.z, 0.0, 1.0) * 255.0)) << 16) | (uint(floor(0.5 + clamp(a.w, 0.0, 1.0) * 255.0)) << 24))
pack4xI8(a)

pack4xI8 is not supported yet on the WebGL2 tier

pack4xI8Clamp(a)

pack4xI8Clamp is not supported yet on the WebGL2 tier

pack4xU8(a)

pack4xU8 is not supported yet on the WebGL2 tier

pack4xU8Clamp(a)

pack4xU8Clamp is not supported yet on the WebGL2 tier

unpack2x16float(a)
unpackHalf2x16(a)
unpack2x16snorm(a)
unpackSnorm2x16(a)
unpack2x16unorm(a)
unpackUnorm2x16(a)
unpack4x8snorm(a)
max(vec4(ivec4(uvec4(a, a >> 8, a >> 16, a >> 24) << 24) >> 24) / 127.0, vec4(-1.0))
unpack4x8unorm(a)
(vec4(uvec4(a, a >> 8, a >> 16, a >> 24) & 0xFFu) / 255.0)
unpack4xI8(a)

unpack4xI8 is not supported yet on the WebGL2 tier

unpack4xU8(a)

unpack4xU8 is not supported yet on the WebGL2 tier

Casts

TypeShadeWGSLGLSL ES 3.00Math name
bitcast<f32>(a)
uintBitsToFloat(a)
bitcast<u32>(a)
floatBitsToUint(a)
bitcastVec2F32(a)
bitcast<vec2<f32>>(a)
uintBitsToFloat(a)
bitcastVec2U32(a)
bitcast<vec2<u32>>(a)
floatBitsToUint(a)
bitcastVec3F32(a)
bitcast<vec3<f32>>(a)
uintBitsToFloat(a)
bitcastVec3U32(a)
bitcast<vec3<u32>>(a)
floatBitsToUint(a)
bitcastVec4F32(a)
bitcast<vec4<f32>>(a)
uintBitsToFloat(a)
bitcastVec4U32(a)
bitcast<vec4<u32>>(a)
floatBitsToUint(a)
f32(a)
float(a)
Math.fround
i32(a)
int(a)
u32(a)
uint(a)

Textures and storage

TypeShadeWGSLGLSL ES 3.00
arrayLength(a)
arrayLength(&a)

arrayLength is not supported yet on the WebGL2 tier (Rule 10.5)

storageFetchF32(a, b)
storageFetchF32(a, b)
_sfetch(a, int(b))
storageFetchI32(a, b)
storageFetchI32(a, b)
_sfetchI(a, int(b))
storageFetchU32(a, b)
storageFetchU32(a, b)
_sfetchU(a, int(b))
textureDimensions(a)
uvec2(textureSize(a, 0))
textureDimensions1d(a)
textureDimensions(a)

textureDimensions on a texture_1d is not supported yet on the WebGL2 tier (Rule 10.5)

textureDimensions3d(a)
textureDimensions(a)
uvec3(textureSize(a, 0))
textureDimensionsMs(a)
textureDimensions(a)

textureDimensions on a multisampled texture is not supported yet on the WebGL2 tier (Rule 10.5)

textureGather(a, b, c, d)

textureGather is not supported yet on the WebGL2 tier (Rule 10.5)

textureGatherArray(a, b, c, d, e)
textureGather(a, b, c, d, e)

textureGather is not supported yet on the WebGL2 tier (Rule 10.5)

textureGatherCompare(a, b, c, d)

textureGatherCompare is not supported yet on the WebGL2 tier (Rule 10.5)

textureGatherCompareArray(a, b, c, d, e)
textureGatherCompare(a, b, c, d, e)

textureGatherCompare is not supported yet on the WebGL2 tier (Rule 10.5)

textureGatherDepth(a, b, c)
textureGather(a, b, c)

textureGather is not supported yet on the WebGL2 tier (Rule 10.5)

textureGatherDepthArray(a, b, c, d)
textureGather(a, b, c, d)

textureGather is not supported yet on the WebGL2 tier (Rule 10.5)

textureLoad(a, b, c)
texelFetch(a, b, int(c))
textureLoad3dU(a, b, c)
textureLoad(a, b, c)
texelFetch(a, ivec3(b), int(c))
textureLoadArray(a, b, c, d)
textureLoad(a, b, c, d)
texelFetch(a, ivec3(b, int(c)), int(d))
textureLoadArrayU(a, b, c, d)
textureLoad(a, b, c, d)
texelFetch(a, ivec3(ivec2(b), int(c)), int(d))
textureLoadDepthMs(a, b, c)
textureLoad(a, b, c)

a multisampled depth load is not supported yet on the WebGL2 tier (Rule 10.5)

textureLoadMs(a, b, c)
textureLoad(a, b, c)

a multisampled load is not supported yet on the WebGL2 tier (Rule 10.5)

textureLoadU(a, b, c)
textureLoad(a, b, c)
texelFetch(a, ivec2(b), int(c))
textureNumLayers(a)
uint(textureSize(a, 0).z)
textureNumLayersStorage(a)
textureNumLayers(a)

a storage texture is not supported yet on the WebGL2 tier (Rule 10.5)

textureNumSamples(a)

textureNumSamples is not supported yet on the WebGL2 tier (Rule 10.5)

textureSample(a, b, c)
texture(a, c)
textureSampleArray(a, b, c, d)
textureSample(a, b, c, d)
texture(a, vec3(c, float(d)))
textureSampleBias(a, b, c, d)
texture(a, c, d)
textureSampleBiasArray(a, b, c, d, e)
textureSampleBias(a, b, c, d, e)
texture(a, vec3(c, float(d)), e)
textureSampleBiasCubeArray(a, b, c, d, e)
textureSampleBias(a, b, c, d, e)

textureSampleBias on a cube array is not supported yet on the WebGL2 tier (Rule 10.5)

textureSampleCompare(a, b, c, d)
texture(a, vec3(c, d))
textureSampleCompareArray(a, b, c, d, e)
textureSampleCompare(a, b, c, d, e)
texture(a, vec4(c, float(d), e))
textureSampleCompareCube(a, b, c, d)
textureSampleCompare(a, b, c, d)
texture(a, vec4(c, d))
textureSampleCompareCubeArray(a, b, c, d, e)
textureSampleCompare(a, b, c, d, e)

textureSampleCompare on a cube array is not supported yet on the WebGL2 tier (Rule 10.5)

textureSampleCompareLevel(a, b, c, d)
textureLod(a, vec3(c, d), 0.0)
textureSampleCompareLevelArray(a, b, c, d, e)
textureSampleCompareLevel(a, b, c, d, e)
textureGrad(a, vec4(c, float(d), e), vec2(0.0), vec2(0.0))
textureSampleCompareLevelCube(a, b, c, d)
textureSampleCompareLevel(a, b, c, d)
textureGrad(a, vec4(c, d), vec3(0.0), vec3(0.0))
textureSampleCompareLevelCubeArray(a, b, c, d, e)
textureSampleCompareLevel(a, b, c, d, e)

textureSampleCompareLevel on a cube array is not supported yet on the WebGL2 tier (Rule 10.5)

textureSampleCubeArray(a, b, c, d)
textureSample(a, b, c, d)

textureSample on a cube array is not supported yet on the WebGL2 tier (Rule 10.5)

textureSampleGrad(a, b, c, d, e)
textureGrad(a, c, d, e)
textureSampleGradArray(a, b, c, d, e, f)
textureSampleGrad(a, b, c, d, e, f)
textureGrad(a, vec3(c, float(d)), e, f)
textureSampleGradCubeArray(a, b, c, d, e, f)
textureSampleGrad(a, b, c, d, e, f)

textureSampleGrad on a cube array is not supported yet on the WebGL2 tier (Rule 10.5)

textureSampleLevel(a, b, c, d)
textureLod(a, c, d)
textureSampleLevelArray(a, b, c, d, e)
textureSampleLevel(a, b, c, d, e)
textureLod(a, vec3(c, float(d)), e)
textureSampleLevelCubeArray(a, b, c, d, e)
textureSampleLevel(a, b, c, d, e)

textureSampleLevel on a cube array is not supported yet on the WebGL2 tier (Rule 10.5)

textureStore(a, b, c)

textureStore is not supported yet on the WebGL2 tier (Rule 10.5)

Atomics

TypeShadeWGSLGLSL ES 3.00
atomicAdd(&a, b)

atomicAdd is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

atomicAnd(&a, b)

atomicAnd is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

atomicCompareExchangeWeak(&a, b, c)

atomicCompareExchangeWeak is not supported yet in a GLSL ES 3.00 stage (Rule 10.5)

atomicExchange(&a, b)

No form on this target.

atomicLoad(&a)

atomicLoad is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

atomicMax(&a, b)

atomicMax is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

atomicMin(&a, b)

atomicMin is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

atomicOr(&a, b)

atomicOr is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

atomicStore(&a, b)

atomicStore is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

atomicSub(&a, b)

atomicSub is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

atomicXor(&a, b)

atomicXor is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a @compute entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

Barriers

TypeShadeWGSLGLSL ES 3.00
storageBarrier()

No form on this target.

textureBarrier()

textureBarrier is not supported yet in a GLSL ES 3.00 stage (Rule 10.5)

workgroupBarrier()

No form on this target.

workgroupUniformLoad(&a)

workgroupUniformLoad is not supported yet in a GLSL ES 3.00 stage (Rule 10.5)

Subgroups

TypeShadeWGSLGLSL ES 3.00
subgroupAdd(a)

subgroupAdd is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupAll(a)

subgroupAll is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupAnd(a)

subgroupAnd is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupAny(a)

subgroupAny is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupBallot(a)

subgroupBallot is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupBroadcast(a, b)

subgroupBroadcast is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupBroadcastFirst(a)

subgroupBroadcastFirst is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupElect()

subgroupElect is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupExclusiveAdd(a)

subgroupExclusiveAdd is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupExclusiveMul(a)

subgroupExclusiveMul is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupInclusiveAdd(a)

subgroupInclusiveAdd is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupInclusiveMul(a)

subgroupInclusiveMul is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupMax(a)

subgroupMax is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupMin(a)

subgroupMin is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupMul(a)

subgroupMul is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupOr(a)

subgroupOr is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupShuffle(a, b)

subgroupShuffle is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupShuffleDown(a, b)

subgroupShuffleDown is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupShuffleUp(a, b)

subgroupShuffleUp is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupShuffleXor(a, b)

subgroupShuffleXor is lowered to one lane before the GLSL writer runs (Rule 11.21)

subgroupXor(a)

subgroupXor is lowered to one lane before the GLSL writer runs (Rule 11.21)

Emulated double

TypeShadeWGSLGLSL ES 3.00

Rewritten into a pair of f32 lanes before either backend runs.

Rewritten into a pair of f32 lanes before either backend runs.

Rewritten into a pair of f32 lanes before either backend runs.

Rewritten into a pair of f32 lanes before either backend runs.

f64Guard()
textureLoad(_fp64, vec2<i32>(0, 0), 0).x
texelFetch(_fp64, ivec2(0, 0), 0).x

Rewritten into a pair of f32 lanes before either backend runs.

Rewritten into a pair of f32 lanes before either backend runs.

GLSL helper functions

A storage buffer has no GLSL ES 3.00 form, so a read of one is rewritten into a read from a data texture. These are the functions that read stands for, and the GLSL writer emits the definition of each one a module calls.

BuiltinGLSL function
storageFetchF32
_sfetch
storageFetchU32
_sfetchU
storageFetchI32
_sfetchI

Every row on this page is read from the spelling registry at the pinned commit, and none of it is typed here.

Edit this page Report a problem