Specifying a Pointer
A pointer type in WGSL is parameterized. It defines not only the type of data being pointed to, but also where that data lives and what access permissions are allowed.
A pointer type is written in one of two ways:
ptr<AS, T, AM>(with an explicit access mode)ptr<AS, T>(relying on the default access mode)
Where:
- AS is the Address Space (e.g.
function,private,workgroup,uniform,storage). - T is the Store Type (e.g.
f32,u32,vec3f). This represents the underlying concrete type of the value being stored in memory. - AM is the Access Mode (e.g.
read,read_write).
When to Specify the Access Mode
The access mode AM is optional for most address spaces, as they have strict default behaviors. In fact, WGSL compilers require you to only specify the access mode when the address space AS is storage.
For all other address spaces, you must omit the access mode—the compiler will implicitly use the default access mode of that address space.
Address Space Reference Matrix
The following reference matrix summarizes how WGSL address spaces, memory tiers, and access modes combine:
| Address Space (AS) | Default Access Mode | Allowed Access Modes | Hardware Tier | Typical Store Types (T) |
|---|---|---|---|---|
| function | read_write | read_write only |
Core Registers / L1 | Any constructible type |
| private | read_write | read_write only |
Core Registers / L1 | Any constructible type |
| workgroup | read_write | read_write only |
On-Chip LDS | Any constructible type |
| uniform | read | read only |
Global VRAM (Cached) | Host-shareable structures, arrays |
| storage | read | read, read_write | Global VRAM (Uncached) | Host-shareable structures, runtime arrays |
Code Examples
In the accompanying shader code editor, we use alias definitions to inspect valid and invalid pointer declarations.
Notice how alias ptr_to_f32_in_storage_buffer_rw = ptr<storage, i32, read_write> is completely legal because it targets storage, while adding a read access mode to a private pointer will fail shader compilation!
/* * Copyright ©2026 Michael R. Bernstein. All new modifications licensed under Apache 2.0. * Upstream lineage ©2023 governed by original BSD 3-Clause. See README.md. */ alias ptr_to_i32_in_workgroup = ptr<workgroup, i32>; alias ptr_to_u32_in_function = ptr<function, u32>; alias ptr_to_f32_in_private = ptr<private, f32>; alias ptr_to_vector_in_uniform = ptr<uniform, vec4f>; alias ptr_to_f32_in_storage_buffer_r = ptr<storage, i32, read>; alias ptr_to_f32_in_storage_buffer_default = ptr<storage, i32>; // Same as 'read' alias ptr_to_f32_in_storage_buffer_rw = ptr<storage, i32, read_write>; //alias bad1 = ptr<private,bool,read>; // Error: only 'storage' can have access mode //alias bad2= ptr<storage,i32,write>; // Error: 'write' not valid for storage