Built-in functions are predeclared and provided by the implementation, so they are always available in a WGSL module. Each one is a family of overloads with the same name, told apart by the number, order and types of their parameters. All arguments are evaluated before the function runs. The groups follow section 17 of the W3C specification. Each row gives the function name, its overloads in brief and a one-sentence meaning.
The overloads use the specification’s placeholders. T and S stand for types listed after the signature. vecN<S> is a vector of N components of type S. AbstractInt and AbstractFloat are the abstract numeric types. Many numeric functions are component-wise: given a vector, they work on each component separately.
Constructors
A value constructor creates a value of a given type. It has the same spelling as the type, or a type alias for it, so vec4<f32>(1.0) and f32(x) are both constructor calls (§17.1). A constructor copies a value of the same type, builds a composite from its components, or converts from another type. Called with no arguments, a concrete constructible type gives its zero value: bool() is false, i32() is 0i, u32() is 0u, f32() is 0.0f and f16() is 0.0h. For vectors and matrices the component type may be left out, as in vec3(1.0, 2.0, 3.0), and is then inferred from the arguments.
| Function | Overloads | Meaning |
|---|---|---|
| Zero value | T() -> TT is a concrete constructible type | Constructs the zero value of T. |
array | array<T, N>(e1: T, …, eN: T)array(e1: T, …, eN: T) | Constructs an array from its elements. |
bool | bool(e: T) -> boolT is a scalar type | Constructs a bool value. |
f16 | f16(e: T) -> f16T is a scalar type | Constructs an f16 value. |
f32 | f32(e: T) -> f32T is a concrete scalar type | Constructs an f32 value. |
i32 | i32(e: T) -> i32T is a scalar type | Constructs an i32 value. |
u32 | u32(e: T) -> u32T is a scalar type | Constructs a u32 value. |
mat2x2 … mat4x4 | matCxR<T>(e: matCxR<S>)matCxR<T>(v1: vecR<T>, …, vC: vecR<T>)matCxR<T>(e1: T, …, eCR: T)T is AbstractFloat, f16 or f32 | Constructs a column-major matrix with C columns and R rows: from another matrix, from column vectors, or from all its elements. There are nine: mat2x2, mat2x3, mat2x4, mat3x2, mat3x3, mat3x4, mat4x2, mat4x3 and mat4x4. |
| Structures | S(e1: T1, …, eN: TN) -> SS is a constructible structure type with members of types T1 … TN | Constructs a structure of type S from its members. |
vec2 | vec2<T>(e: T)vec2<T>(e: vec2<S>)vec2<T>(e1: T, e2: T)vec2() | Constructs a two-component vector: one value in every component, a converted vector, or one value per component. vec2() is vec2(0,0). |
vec3 | vec3<T>(e: T)vec3<T>(e: vec3<S>)vec3<T>(e1: T, e2: T, e3: T)vec3<T>(v1: vec2<T>, e1: T)vec3<T>(e1: T, v1: vec2<T>)vec3() | Constructs a three-component vector from scalars and smaller vectors, taken in order. vec3() is vec3(0,0,0). |
vec4 | vec4<T>(e: T)vec4<T>(e: vec4<S>)vec4<T>(e1: T, e2: T, e3: T, e4: T)vec4<T>(e1: T, v1: vec2<T>, e2: T)vec4<T>(e1: T, e2: T, v1: vec2<T>)vec4<T>(v1: vec2<T>, v2: vec2<T>)vec4<T>(v1: vec2<T>, e1: T, e2: T)vec4<T>(v1: vec3<T>, e1: T)vec4<T>(e1: T, v1: vec3<T>)vec4() | Constructs a four-component vector from scalars and smaller vectors, taken in order. vec4() is vec4(0,0,0,0). |
Bit reinterpretation
| Function | Overloads | Meaning |
|---|---|---|
bitcast | bitcast<T>(e: T) -> Tbitcast<T>(e: S) -> Tbitcast<vecN<T>>(e: vecN<S>) -> vecN<T>bitcast<u32>(e: AbstractInt) -> u32bitcast<T>(e: vec2<f16>) -> Tbitcast<vec2<T>>(e: vec4<f16>) -> vec2<T>bitcast<vec2<f16>>(e: T) -> vec2<f16>bitcast<vec4<f16>>(e: vec2<T>) -> vec4<f16>S and T are i32, u32 or f32 | Reinterprets the bits of e as type T without changing them. Two f16 values fill the same 32 bits as one i32, u32 or f32. |
Logical
| Function | Overloads | Meaning |
|---|---|---|
all | all(e: vecN<bool>) -> boolall(e: bool) -> bool | True if every component of e is true. For a scalar it returns e. |
any | any(e: vecN<bool>) -> boolany(e: bool) -> bool | True if any component of e is true. For a scalar it returns e. |
select | select(f: T, t: T, cond: bool) -> Tselect(f: vecN<T>, t: vecN<T>, cond: vecN<bool>) -> vecN<T> | Returns t when cond is true and f otherwise, component by component for a vector condition. |
Array
| Function | Overloads | Meaning |
|---|---|---|
arrayLength | arrayLength(p: ptr<AS, array<E>, AM>) -> u32AS is storage, uniform or workgroup; AM is read or read_write | Returns the number of elements in a runtime-sized array. AS can only be uniform or workgroup when the pointer comes from bufferView or bufferArrayView. |
Numeric
Unless a row says otherwise, S is AbstractFloat, f32 or f16, and T is S or vecN<S>. “Integer” below means T is i32, u32, vecN<i32> or vecN<u32>. Angles are in radians.
| Function | Overloads | Meaning |
|---|---|---|
abs | abs(e: T) -> TS is AbstractInt, AbstractFloat, i32, u32, f32 or f16 | The absolute value of e. |
acos | acos(e: T) -> T | The principal value of the inverse cosine of e. |
acosh | acosh(x: T) -> T | The inverse hyperbolic cosine of x, as a hyperbolic angle. |
asin | asin(e: T) -> T | The principal value of the inverse sine of e. |
asinh | asinh(y: T) -> T | The inverse hyperbolic sine of y, as a hyperbolic angle. |
atan | atan(e: T) -> T | The principal value of the inverse tangent of e. |
atanh | atanh(t: T) -> T | The inverse hyperbolic tangent of t, as a hyperbolic angle. |
atan2 | atan2(y: T, x: T) -> T | An angle in [−π, π] whose tangent is y ÷ x. |
ceil | ceil(e: T) -> T | The ceiling of e. |
clamp | clamp(e: T, low: T, high: T) -> TS is AbstractInt, AbstractFloat, i32, u32, f32 or f16 | Restricts e to the range from low to high. |
cos | cos(e: T) -> T | The cosine of e. |
cosh | cosh(a: T) -> T | The hyperbolic cosine of a. |
countLeadingZeros | countLeadingZeros(e: T) -> TInteger | The number of consecutive 0 bits from the most significant bit. |
countOneBits | countOneBits(e: T) -> TInteger | The number of 1 bits in e. |
countTrailingZeros | countTrailingZeros(e: T) -> TInteger | The number of consecutive 0 bits from the least significant bit. |
cross | cross(a: vec3<T>, b: vec3<T>) -> vec3<T>T is AbstractFloat, f32 or f16 | The cross product of two three-component vectors. |
degrees | degrees(e1: T) -> T | Converts radians to degrees. |
determinant | determinant(e: matCxC<T>) -> TT is AbstractFloat, f32 or f16 | The determinant of a square matrix. |
distance | distance(e1: T, e2: T) -> S | The distance between e1 and e2, that is length(e1 - e2). |
dot | dot(e1: vecN<T>, e2: vecN<T>) -> TT is AbstractInt, AbstractFloat, i32, u32, f32 or f16 | The dot product of two vectors. |
dot4U8Packed | dot4U8Packed(e1: u32, e2: u32) -> u32 | Treats each argument as four unsigned 8-bit integers and returns their unsigned dot product. |
dot4I8Packed | dot4I8Packed(e1: u32, e2: u32) -> i32 | Treats each argument as four signed 8-bit integers and returns their signed dot product. |
exp | exp(e1: T) -> T | The natural exponentiation of e1, ee1. |
exp2 | exp2(e: T) -> T | 2 raised to the power e. |
extractBits (signed) | extractBits(e: T, offset: u32, count: u32) -> TT is i32 or vecN<i32> | Reads count bits from offset, with sign extension. |
extractBits (unsigned) | extractBits(e: T, offset: u32, count: u32) -> TT is u32 or vecN<u32> | Reads count bits from offset, without sign extension. |
faceForward | faceForward(e1: T, e2: T, e3: T) -> TT is vecN<AbstractFloat>, vecN<f32> or vecN<f16> | Returns e1 if dot(e2, e3) is negative, and -e1 otherwise. |
firstLeadingBit (signed) | firstLeadingBit(e: T) -> TT is i32 or vecN<i32> | The position of the most significant bit that differs from the sign bit, or −1 if e is 0 or −1. |
firstLeadingBit (unsigned) | firstLeadingBit(e: T) -> TT is u32 or vecN<u32> | The position of the most significant 1 bit, or T(-1) if e is zero. |
firstTrailingBit | firstTrailingBit(e: T) -> TInteger | The position of the least significant 1 bit, or T(-1) if e is zero. |
floor | floor(e: T) -> T | The floor of e. |
fma | fma(e1: T, e2: T, e3: T) -> T | Returns e1 * e2 + e3. |
fract | fract(e: T) -> T | The fractional part of e, computed as e - floor(e). |
frexp | frexp(e: T) -> __frexp_result_f32and likewise __frexp_result_f16, __frexp_result_abstract, __frexp_result_vecN_f32, __frexp_result_vecN_f16, __frexp_result_vecN_abstract | Splits e, or each component, into a fraction and an exponent. |
insertBits | insertBits(e: T, newbits: T, offset: u32, count: u32) -> TInteger | Sets count bits of e from offset to bits taken from newbits. |
inverseSqrt | inverseSqrt(e: T) -> T | The reciprocal of sqrt(e). |
ldexp | ldexp(e1: T, e2: I) -> TI is AbstractInt, i32, vecN<AbstractInt> or vecN<i32>, a vector only if T is | Returns e1 × 2e2. |
length | length(e: T) -> S | The length of e. |
log | log(e: T) -> T | The natural logarithm of e. |
log2 | log2(e: T) -> T | The base-2 logarithm of e. |
max | max(e1: T, e2: T) -> TS is AbstractInt, AbstractFloat, i32, u32, f32 or f16 | Returns e2 if e1 is less than e2, and e1 otherwise. |
min | min(e1: T, e2: T) -> TS is AbstractInt, AbstractFloat, i32, u32, f32 or f16 | Returns e2 if e2 is less than e1, and e1 otherwise. |
mix | mix(e1: T, e2: T, e3: T) -> Tmix(e1: T2, e2: T2, e3: T) -> T2T2 is vecN<T> | The linear blend e1 * (T(1) - e3) + e2 * e3. The second form uses one scalar factor for every component. |
modf | modf(e: T) -> __modf_result_f32and likewise __modf_result_f16, __modf_result_abstract, __modf_result_vecN_f32, __modf_result_vecN_f16, __modf_result_vecN_abstract | Splits e, or each component, into fractional and whole number parts. |
normalize | normalize(e: vecN<T>) -> vecN<T>T is AbstractFloat, f32 or f16 | A unit vector in the same direction as e. |
pow | pow(e1: T, e2: T) -> T | e1 raised to the power e2. |
quantizeToF16 | quantizeToF16(e: T) -> TT is f32 or vecN<f32> | Rounds an f32 as if converted to IEEE-754 binary16 and back to binary32. |
radians | radians(e1: T) -> T | Converts degrees to radians. |
reflect | reflect(e1: T, e2: T) -> TT is vecN<AbstractFloat>, vecN<f32> or vecN<f16> | The reflection direction e1 - 2 * dot(e2, e1) * e2 for incident vector e1 and surface orientation e2. |
refract | refract(e1: T, e2: T, e3: I) -> TT is vecN<I>; I is AbstractFloat, f32 or f16 | The refraction vector for incident vector e1, surface normal e2 and ratio of refractive indices e3. |
reverseBits | reverseBits(e: T) -> TInteger | Reverses the bits: bit k of the result is bit 31 − k of e. |
round | round(e: T) -> T | The nearest whole number, with halves rounded to the even number. |
saturate | saturate(e: T) -> T | Returns clamp(e, 0.0, 1.0). |
sign | sign(e: T) -> TS is AbstractInt, AbstractFloat, i32, f32 or f16 | 1 when e is positive, 0 when zero and −1 when negative. |
sin | sin(e: T) -> T | The sine of e. |
sinh | sinh(a: T) -> T | The hyperbolic sine of a. |
smoothstep | smoothstep(edge0: T, edge1: T, x: T) -> T | Smooth Hermite interpolation between 0 and 1 as x moves from edge0 to edge1. |
sqrt | sqrt(e: T) -> T | The square root of e. |
step | step(edge: T, x: T) -> T | 1.0 if edge ≤ x, and 0.0 otherwise. |
tan | tan(e: T) -> T | The tangent of e. |
tanh | tanh(a: T) -> T | The hyperbolic tangent of a. |
transpose | transpose(e: matRxC<T>) -> matCxR<T>T is AbstractFloat, f32 or f16 | The transpose of a matrix. |
trunc | trunc(e: T) -> T | The nearest whole number whose absolute value is less than or equal to that of e. |
Derivative
Derivative functions must only be used in the fragment shader stage. A call triggers a derivative_uniformity diagnostic if uniformity analysis cannot prove it is in uniform control flow. For all nine, T is f32 or vecN<f32>.
| Function | Overloads | Meaning |
|---|---|---|
dpdx | dpdx(e: T) -> T | Partial derivative of e with respect to window x coordinates, the same as either dpdxFine(e) or dpdxCoarse(e). |
dpdxCoarse | dpdxCoarse(e: T) -> T | Partial derivative in x, using local differences. |
dpdxFine | dpdxFine(e: T) -> T | Partial derivative in x from the values in the same quad: e1 − e0 for quad IDs 0 and 1, otherwise e3 − e2. |
dpdy | dpdy(e: T) -> T | Partial derivative of e with respect to window y coordinates, the same as either dpdyFine(e) or dpdyCoarse(e). |
dpdyCoarse | dpdyCoarse(e: T) -> T | Partial derivative in y, using local differences. |
dpdyFine | dpdyFine(e: T) -> T | Partial derivative in y from the values in the same quad: e2 − e0 for quad IDs 0 and 2, otherwise e3 − e1. |
fwidth | fwidth(e: T) -> T | Returns abs(dpdx(e)) + abs(dpdy(e)). |
fwidthCoarse | fwidthCoarse(e: T) -> T | Returns abs(dpdxCoarse(e)) + abs(dpdyCoarse(e)). |
fwidthFine | fwidthFine(e: T) -> T | Returns abs(dpdxFine(e)) + abs(dpdyFine(e)). |
Texture
Texture functions take a texture t, and for sampling a sampler s. Coordinates coords are f32 values for sampling and gathering, and i32 or u32 texel positions (C) for loading and storing. array_index selects a layer of an arrayed texture, level a mip level and offset an i32 vector of texel offsets. The overload lists are long, so each row gives the parameter shapes and the texture types accepted.
| Function | Overloads | Meaning |
|---|---|---|
textureDimensions | textureDimensions(t: T) -> u32, vec2<u32> or vec3<u32>textureDimensions(t: T, level: L)T is any 1D, 2D, 2D array, cube, cube array, 3D, multisampled, depth, storage or external texture; L is i32 or u32 | The dimensions of a texture, or of one of its mip levels, in texels. |
textureGather | textureGather(component: C, t, s: sampler, coords [, array_index] [, offset]) -> vec4<ST>textureGather(t, s: sampler, coords [, array_index] [, offset]) -> vec4<f32>t is texture_2d<ST>, texture_2d_array<ST>, texture_cube<ST>, texture_cube_array<ST>, or one of the depth textures texture_depth_2d, texture_depth_2d_array, texture_depth_cube, texture_depth_cube_array | Reads from a 2D, 2D array, cube or cube array texture and computes a four-component vector. |
textureGatherCompare | textureGatherCompare(t, s: sampler_comparison, coords [, array_index], depth_ref: f32 [, offset]) -> vec4<f32>t is texture_depth_2d, texture_depth_2d_array, texture_depth_cube or texture_depth_cube_array | Compares four texels of a depth texture against depth_ref and collects the results in one vector. |
textureLoad | textureLoad(t, coords [, array_index], level: L) -> vec4<ST> or f32textureLoad(t, coords, sample_index: S) for multisampled texturestextureLoad(t: texture_external, coords: vec2<C>) -> vec4<f32>textureLoad(t: texture_storage_…<F, AM>, coords [, array_index]) -> vec4<CF>C and L are i32 or u32; AM is read or read_write | Reads a single texel without sampling or filtering. |
textureNumLayers | textureNumLayers(t: T) -> u32T is texture_2d_array<ST>, texture_cube_array<ST>, texture_depth_2d_array, texture_depth_cube_array or texture_storage_2d_array<F, A> | The number of layers (elements) of an arrayed texture. |
textureNumLevels | textureNumLevels(t: T) -> u32T is a sampled 1D, 2D, 2D array, 3D, cube or cube array texture, or a non-multisampled depth texture | The number of mip levels of a texture. |
textureNumSamples | textureNumSamples(t: T) -> u32T is texture_multisampled_2d<ST> or texture_depth_multisampled_2d | The number of samples per texel in a multisampled texture. |
textureSample | textureSample(t, s: sampler, coords [, array_index] [, offset]) -> vec4<f32> or f32t is texture_1d<f32>, texture_2d<f32>, texture_2d_array<f32>, texture_3d<f32>, texture_cube<f32>, texture_cube_array<f32> or a non-multisampled depth texture | Samples a texture. |
textureSampleBias | textureSampleBias(t, s: sampler, coords [, array_index], bias [, offset]) -> vec4<f32>t is texture_2d<f32>, texture_2d_array<f32>, texture_3d<f32>, texture_cube<f32> or texture_cube_array<f32> | Samples a texture with a bias to the mip level. |
textureSampleCompare | textureSampleCompare(t, s: sampler_comparison, coords [, array_index], depth_ref [, offset]) -> f32t is a non-multisampled depth texture | Samples a depth texture and compares the sampled depth values against a reference value. |
textureSampleCompareLevel | The same shapes as textureSampleCompare | Like textureSampleCompare, but always samples mip level 0, computes no derivatives, need not be in uniform control flow, and may be used in any shader stage. |
textureSampleGrad | textureSampleGrad(t, s: sampler, coords [, array_index], ddx, ddy [, offset]) -> vec4<f32>t is texture_2d<f32>, texture_2d_array<f32>, texture_3d<f32>, texture_cube<f32> or texture_cube_array<f32> | Samples a texture using explicit gradients. |
textureSampleLevel | textureSampleLevel(t, s: sampler, coords [, array_index], level [, offset]) -> vec4<f32> or f32t is a sampled f32 texture of any dimension or a non-multisampled depth texture | Samples a texture using an explicit mip level. |
textureSampleBaseClampToEdge | textureSampleBaseClampToEdge(t: T, s: sampler, coords: vec2<f32>) -> vec4<f32>T is texture_2d<f32> or texture_external | Samples a texture view at its base level, with coordinates clamped to the edge. |
textureStore | textureStore(t: texture_storage_1d<F, AM>, coords: C, value: vec4<CF>)and the same for texture_storage_2d, texture_storage_2d_array (with array_index) and texture_storage_3d | Writes a single texel to a storage texture. |
Atomic
Atomic functions are the only operations allowed on atomic types. They use relaxed memory ordering, so ordering is only guaranteed among atomic operations on the same memory location. They must not be used in the vertex shader stage. The address space AS must be storage or workgroup, and unless noted T is u32 or i32. Below, p stands for atomic_ptr: ptr<AS, atomic<T>, read_write>.
| Function | Overloads | Meaning |
|---|---|---|
atomicLoad | atomicLoad(p) -> T | Atomically loads the value without modifying it. |
atomicStore | atomicStore(p, v: T) | Atomically stores v. |
atomicAdd | atomicAdd(p, v: T) -> T | Atomically adds v and returns the original value. |
atomicSub | atomicSub(p, v: T) -> T | Atomically subtracts v and returns the original value. |
atomicMax | atomicMax(p, v: T) -> T | Atomically keeps the maximum of the stored value and v, and returns the original value. |
atomicMin | atomicMin(p, v: T) -> T | Atomically keeps the minimum of the stored value and v, and returns the original value. |
atomicAnd | atomicAnd(p, v: T) -> T | Atomic bitwise AND with v, returning the original value. |
atomicOr | atomicOr(p, v: T) -> T | Atomic bitwise OR with v, returning the original value. |
atomicXor | atomicXor(p, v: T) -> T | Atomic bitwise XOR with v, returning the original value. |
atomicExchange | atomicExchange(p, v: T) -> T | Atomically stores v and returns the original value. |
atomicCompareExchangeWeak | atomicCompareExchangeWeak(p, cmp: T, v: T) -> __atomic_compare_exchange_result<T> | Stores v only if the original value equals cmp, and returns a structure of old_value and exchanged. |
atomicStoreMin | atomicStoreMin(atomic_ptr: ptr<storage, atomic<vec2<u32>>, read_write>, v: vec2<u32>) | Atomically performs a 64-bit unsigned integer minimum with v. Requires the atomic_vec2u_min_max feature. |
atomicStoreMax | atomicStoreMax(atomic_ptr: ptr<storage, atomic<vec2<u32>>, read_write>, v: vec2<u32>) | Atomically performs a 64-bit unsigned integer maximum with v. Requires the atomic_vec2u_min_max feature. |
Data packing
Packing functions encode values in data formats that have no matching WGSL type, so many values can be written densely to memory.
| Function | Overloads | Meaning |
|---|---|---|
pack4x8snorm | pack4x8snorm(e: vec4<f32>) -> u32 | Converts four normalised floats to 8-bit signed integers and combines them into one u32. |
pack4x8unorm | pack4x8unorm(e: vec4<f32>) -> u32 | Converts four normalised floats to 8-bit unsigned integers and combines them into one u32. |
pack4xI8 | pack4xI8(e: vec4<i32>) -> u32 | Packs the lower 8 bits of each component into a u32, dropping the other bits. |
pack4xU8 | pack4xU8(e: vec4<u32>) -> u32 | Packs the lower 8 bits of each component into a u32, dropping the other bits. |
pack4xI8Clamp | pack4xI8Clamp(e: vec4<i32>) -> u32 | Clamps each component to [−128, 127], then packs the lower 8 bits of each into a u32. |
pack4xU8Clamp | pack4xU8Clamp(e: vec4<u32>) -> u32 | Clamps each component to [0, 255], then packs the lower 8 bits of each into a u32. |
pack2x16snorm | pack2x16snorm(e: vec2<f32>) -> u32 | Converts two normalised floats to 16-bit signed integers and combines them into one u32. |
pack2x16unorm | pack2x16unorm(e: vec2<f32>) -> u32 | Converts two normalised floats to 16-bit unsigned integers and combines them into one u32. |
pack2x16float | pack2x16float(e: vec2<f32>) -> u32 | Converts two floats to half precision and combines them into one u32. |
Data unpacking
Unpacking functions decode the same densely packed formats when reading from memory.
| Function | Overloads | Meaning |
|---|---|---|
unpack4x8snorm | unpack4x8snorm(e: u32) -> vec4<f32> | Splits 32 bits into four 8-bit chunks and reads each as a signed normalised float. |
unpack4x8unorm | unpack4x8unorm(e: u32) -> vec4<f32> | Splits 32 bits into four 8-bit chunks and reads each as an unsigned normalised float. |
unpack4xI8 | unpack4xI8(e: u32) -> vec4<i32> | Reads e as four 8-bit signed integers. |
unpack4xU8 | unpack4xU8(e: u32) -> vec4<u32> | Reads e as four 8-bit unsigned integers. |
unpack2x16snorm | unpack2x16snorm(e: u32) -> vec2<f32> | Splits 32 bits into two 16-bit chunks and reads each as a signed normalised float. |
unpack2x16unorm | unpack2x16unorm(e: u32) -> vec2<f32> | Splits 32 bits into two 16-bit chunks and reads each as an unsigned normalised float. |
unpack2x16float | unpack2x16float(e: u32) -> vec2<f32> | Splits 32 bits into two 16-bit chunks and reads each as a float. |
Synchronisation
Every synchronisation function executes a control barrier with Acquire/Release memory ordering, at workgroup memory and execution scope. They must only be used in the compute shader stage and in uniform control flow.
| Function | Overloads | Meaning |
|---|---|---|
storageBarrier | storageBarrier() | A control barrier affecting memory and atomic operations in the storage address space. |
textureBarrier | textureBarrier() | A control barrier affecting memory operations in the handle address space. |
workgroupBarrier | workgroupBarrier() | A control barrier affecting memory and atomic operations in the workgroup address space. |
workgroupUniformLoad | workgroupUniformLoad(p: ptr<workgroup, T>) -> TworkgroupUniformLoad(p: ptr<workgroup, atomic<T>, read_write>) -> TT is a concrete constructible type | Returns the value pointed to by p to all invocations in the workgroup, loading it atomically in the second form. |
Subgroup
Subgroup functions need the subgroups enable-extension. They must only be used in the fragment or compute shader stage, and trigger a subgroup_uniformity diagnostic if the call cannot be proved to be in uniform control flow. Below, “numeric” means T is a concrete numeric scalar or vector, and “integer” means T is i32, u32, vecN<i32> or vecN<u32>. I is u32 or i32. All results are over the active invocations in the subgroup.
| Function | Overloads | Meaning |
|---|---|---|
subgroupAdd | subgroupAdd(e: T) -> TNumeric | The sum of e. |
subgroupExclusiveAdd | subgroupExclusiveAdd(e: T) -> TNumeric | The sum of e over invocations with a lower subgroup invocation ID. |
subgroupInclusiveAdd | subgroupInclusiveAdd(e: T) -> TNumeric | The sum of e over invocations with a lower or equal subgroup invocation ID. |
subgroupAll | subgroupAll(e: bool) -> bool | True if e is true for all active invocations. |
subgroupAnd | subgroupAnd(e: T) -> TInteger | The bitwise AND of e. |
subgroupAny | subgroupAny(e: bool) -> bool | True if e is true for any active invocation. |
subgroupBallot | subgroupBallot(pred: bool) -> vec4<u32> | A bitmask of the active invocations for which pred is true. |
subgroupBroadcast | subgroupBroadcast(e: T, id: I) -> TNumeric | The value of e from the invocation whose subgroup invocation ID is id, given to all active invocations. |
subgroupBroadcastFirst | subgroupBroadcastFirst(e: T) -> TNumeric | The value of e from the active invocation with the lowest subgroup invocation ID. |
subgroupElect | subgroupElect() -> bool | True for the active invocation with the lowest subgroup invocation ID. |
subgroupMax | subgroupMax(e: T) -> TNumeric | The maximum value of e. |
subgroupMin | subgroupMin(e: T) -> TNumeric | The minimum value of e. |
subgroupMul | subgroupMul(e: T) -> TNumeric | The product of e. |
subgroupExclusiveMul | subgroupExclusiveMul(e: T) -> TNumeric | The product of e over invocations with a lower subgroup invocation ID. |
subgroupInclusiveMul | subgroupInclusiveMul(e: T) -> TNumeric | The product of e over invocations with a lower or equal subgroup invocation ID. |
subgroupOr | subgroupOr(e: T) -> TInteger | The bitwise OR of e. |
subgroupShuffle | subgroupShuffle(e: T, id: I) -> TNumeric | The value of e from the invocation whose subgroup invocation ID is id. |
subgroupShuffleDown | subgroupShuffleDown(e: T, delta: u32) -> TNumeric | The value of e from the invocation with ID subgroup_invocation_id + delta. |
subgroupShuffleUp | subgroupShuffleUp(e: T, delta: u32) -> TNumeric | The value of e from the invocation with ID subgroup_invocation_id - delta. |
subgroupShuffleXor | subgroupShuffleXor(e: T, mask: u32) -> TNumeric | The value of e from the invocation with ID subgroup_invocation_id ^ mask. |
subgroupXor | subgroupXor(e: T) -> TInteger | The bitwise XOR of e. |
Quad
Quad operations exchange values between invocations in the same quad. They have the same stage and uniformity rules as subgroup functions. T is a concrete numeric scalar or vector, and I is u32 or i32.
| Function | Overloads | Meaning |
|---|---|---|
quadBroadcast | quadBroadcast(e: T, id: I) -> T | The value of e from the invocation whose quad invocation ID is id, given to all active invocations in the quad. |
quadSwapDiagonal | quadSwapDiagonal(e: T) -> T | The value of e from the invocation in the quad with the opposite coordinates. |
quadSwapX | quadSwapX(e: T) -> T | The value of e from the invocation in the quad sharing the same X dimension. |
quadSwapY | quadSwapY(e: T) -> T | The value of e from the invocation in the quad sharing the same Y dimension. |
Buffer view
These functions require the buffer_view language feature. They take a pointer to a buffer, and bufferView and bufferArrayView reinterpret its opaque data as another host-shareable type. AS is storage, uniform or workgroup, and AM is an access mode valid for it.
| Function | Overloads | Meaning |
|---|---|---|
bufferView | bufferView<T>(p: ptr<AS, buffer, AM>, offset: I) -> ptr<AS, T, AM>bufferView<T>(p: ptr<AS, buffer<N>, AM>, offset: I) -> ptr<AS, T, AM>T is host-shareable and is not and does not contain an atomic or buffer type | Reinterprets the memory offset bytes from the start of p as type T. |
bufferArrayView | bufferArrayView<T>(p: ptr<AS, buffer, AM>, offset: OI, size: SI) -> ptr<AS, T, AM>and the same with buffer<N>T is host-shareable without a fixed footprint | Reinterprets size bytes of memory, offset bytes from the start of p, as type T. |
bufferLength | bufferLength(p: ptr<AS, buffer, AM>) -> u32bufferLength(p: ptr<AS, buffer<N>, AM>) -> u32 | The minimum buffer size seen during interprocedural analysis, or the size of the WebGPU GPUBuffer if only runtime-sized buffers were seen. |
Sources
- WebGPU Shading Language – W3C Candidate Recommendation Draft, 6 November 2026: section 17, built-in functions.