← WebGPU: buffer_view feature

v153 · enabled by default · wgsl built-in function

bufferView

Limited availability

  • Chrome · enabled by default 153
  • Edge · not separately reported
  • Firefox · no signal
  • Safari · closed without a position

Requires the buffer_view WGSL language extension — see the feature overview for detection and the full compatibility story.

Reinterprets the memory view starting offset bytes into a buffer pointer as the host-shareable type T, returning a normal pointer to T covering [offset, bufferLength(p)). It is effectively a single-shot pointer reinterpret cast — the only way to read or write the contents of an opaque buffer value.

syntax

Two overloads (verbatim from WGSL §17.14.1) — one for runtime-sized, one for fixed-size buffer pointers; both are @must_use:

@must_use fn bufferView<T>(p : ptr<AS, buffer, AM>, offset : I) -> ptr<AS, T, AM>

@must_use fn bufferView<T>(p : ptr<AS, buffer<N>, AM>, offset : I) -> ptr<AS, T, AM>

The helper definition that drives validation (§17.14):

Source: WGSL §17.14 Buffer View Built-in Functions (fetched 2026-07-29)

inputs

ParameterTypeContract
T (template)typeHost-shareable; must not be or contain an atomic type or a buffer type (MSL cannot cast non-atomic to atomic; views cannot chain); must satisfy the address-space layout constraints for AS
pptr<AS, buffer> or ptr<AS, buffer<N>>AS ∈ {storage, uniform, workgroup}; AM must be a valid access mode for AS (normal address-space restrictions apply — e.g. uniform is read-only)
offsetIu32 or i32Byte offset into the buffer. For i32: shader-creation error if a const-expression < 0; pipeline-creation error if an override-expression < 0; otherwise an indeterminate value may be used. Alignment rules below
Source: WGSL §17.14.1 preconditions

outputs

A ptr<AS, T, AM> usable like any other pointer. Formally: if the memory locations associated with p are in the range [0, bufferLength(p)), then the memory locations associated with the result are in the range [offset, bufferLength(p)) with store type T. When T has no fixed footprint (a runtime-sized array or a struct ending in one), the runtime element count derives from the buffer binding per WGSL §13.3.4, and arrayLength on the result reports it (arrayLength's AS may be uniform or workgroup only when its argument derives from bufferView/bufferArrayView§17.4.1 note).

Source: WGSL §17.14.1 description; WGSL §13.3.4

errors

ConditionBehavior
MinTypeSize(T) + offset > bufferLength(p)An invalid pointer is returned (runtime path); the proposal's design note: this eliminates some in-bounds behavior but keeps implementations simple
MinTypeSize(T) > N (fixed-size buffer)Shader-creation error
MinTypeSize(T) + offset > N (fixed-size buffer)Shader-creation error if offset is a const-expression; pipeline-creation error if an override-expression
offset % RequiredAlignOf(T, AS) != 0Shader-creation error (const-expression offset) / pipeline-creation error (override-expression offset); otherwise the implementation uses offset & ~(RequiredAlignOf(T, AS) - 1) — it rounds the offset down to alignment
Negative offset (i32)Shader-creation error (const-expression) / pipeline-creation error (override-expression) / indeterminate value may be used (otherwise)
T atomic, containing an atomic, or a buffer type; or T violating AS layout constraintsValidation error (precondition failure)

Size checks are performed interprocedurally, so user size reductions through function parameters are respected; the check also computes the minimum buffer size the binding must provide. The alignment-rounding rule interacts with the uniform_buffer_standard_layout language feature.

Source: WGSL §17.14.1; proposal — bufferView

context and exposure

Source: WGSL §17.14; proposal — function parameters

lifecycle

  1. Declaration — a buffer variable is declared in storage/uniform/workgroup (see type rules); for storage/uniform it binds a GPUBuffer via a bind group.
  2. ReinterpretationbufferView converts the buffer pointer at a byte offset; validation happens at shader creation (const), pipeline creation (override), or produces an invalid pointer (runtime).
  3. Use — the result pointer is dereferenced/read/written like any pointer of ptr<AS, T, AM>; subsequent arrayLength calls account for the view's offset.
  4. No state, cancellation, or cleanup: the function is a pure pointer reinterpretation with @must_use semantics.
Source: WGSL §17.14; proposal

examples

Reading a packed header word and then viewing the tail as a typed array (pattern from the proposal):

requires buffer_view;

@group(0) @binding(0) var<storage> packed_data : buffer;

fn read_header_and_tail() {
  // View byte 0 as a u32 count.
  let count = *bufferView<u32>(&packed_data, 0);

  // View the remainder as an array of f32 starting at byte 4.
  let values = bufferView<array<f32>>(&packed_data, 4);

  let first = values[0];       // normal pointer indexing
  let n = arrayLength(&*values); // runtime element count from the binding
}
Source: usage pattern per the proposal motivating example; signatures per WGSL §17.14.1

browser compatibility

Interim table (no BCD key for the feature or this built-in; compiled from primary sources, 2026-07-29):

BrowserSupportEvidence
ChromeEnabled by default 153 (desktop, Android, WebView)milestone=153 listing (“Enabled by default”)
EdgeNot separately reportedChromium-based; no separate position
FirefoxNo signalmozilla/standards-positions #1205
SafariClosed without a positionWebKit/standards-positions #294
Source: chromestatus.com/feature/5094091886034944

security and privacy

Source: WGSL §17.14; proposal — safety design

see also