Types
On this page

Types

A type is written where WGSL writes one, on a declaration, a parameter, a field and a return. The element type rides inside the name where WGSL takes a type argument, so vec3<u32> is vec3u and there is nothing in angle brackets to get wrong.

Scalars

WGSLTypeShade
f32
f32
i32
i32
u32
u32
bool
bool
f16

No type name in this surface. "enable f16" beside "use typeshade" emits WGSL's enable f16;, and the reflection names the capability a host requests as shader-f16, but there is still no f16 to declare a value with.

WGSL has no 64-bit float. The pass below rewrites the declaration before the writer sees it.

f64

A double has no WGSL type behind it. The declaration is written f64, and a pass rewrites every one into a pair of f32 lanes and a library of functions over them before the writer runs. A multiplication of two doubles reaches the WGSL as one call.

let d = df64_mul(vec2<f32>(uv.x, 0.0), vec2<f32>(u.a, 0.0), _fp64_g);

Vectors

WGSLTypeShade
vec3<f32>
vec3
vec3<f32>
vec3f
vec3<u32>
vec3u
vec3<i32>
vec3i
vec3<bool>
vec3b

WGSL has no 64-bit vector either, and the same pass rewrites this one.

vec3d

vec2 and vec4 read the same way as the three above. vec3 and vec3f are one type, and so are vec3d and vec3f64.

Matrices

WGSLTypeShade
mat2x2<f32>
mat2x2
mat2x3<f32>
mat2x3
mat2x4<f32>
mat2x4
mat3x2<f32>
mat3x2
mat3x3<f32>
mat3x3
mat3x4<f32>
mat3x4
mat4x2<f32>
mat4x2
mat4x3<f32>
mat4x3
mat4x4<f32>
mat4x4

A square matrix also answers to the short name both targets give it, so mat4 and mat4x4 are the same declaration. The C and the R mean what they mean in WGSL, columns then rows.

Arrays and atomics

WGSLTypeShade
array<f32, 4>
array<f32, 4>
array<f32, 2>
[f32, f32]
array<f32>
array<f32>
atomic<u32>
atomic<u32>
atomic<i32>
atomic<i32>

A tuple is a list of a length the type fixes, which is what an array of a known size is, so [f32, f32] and array<f32, 2> reach the same type. A runtime-sized array and an atomic each live in a storage binding.

Textures and samplers

WGSLTypeShade
texture_2d<f32>
texture_2d<f32>
texture_2d_array<f32>
texture_2d_array<f32>
texture_cube<f32>
texture_cube<f32>
texture_3d<f32>
texture_3d<f32>
texture_1d<f32>
texture_1d<f32>
texture_cube_array<f32>
texture_cube_array<f32>
texture_multisampled_2d<f32>
texture_multisampled_2d<f32>
texture_storage_2d<rgba8unorm, write>
texture_storage_2d<"rgba8unorm", "write">
texture_storage_2d_array<rgba8unorm, write>
texture_storage_2d_array<"rgba8unorm", "write">
texture_depth_2d
texture_depth_2d
texture_depth_2d_array
texture_depth_2d_array
texture_depth_cube
texture_depth_cube
texture_depth_cube_array
texture_depth_cube_array
texture_depth_multisampled_2d
texture_depth_multisampled_2d
sampler
sampler
sampler_comparison
sampler_comparison
texture_2d<u32>
texture_2d<u32>
texture_2d<i32>
texture_2d<i32>

A texture and a sampler are written bare, with no address-space wrapper, because a handle lives in no address space. A sampled texture takes f32, i32 or u32, and the element decides both the WGSL spelling and which reads apply to it. A storage texture takes a format and an access mode as string literal types, which tsc checks before this compiler does.

Edit this page Report a problem