home/ atoms/ webgpu-storage-buffer

Storage buffers are large, compute-shader-writable GPU buffers declared var<storage> in WGSL, contrasting with size-limited read-only uniforms

Storage buffers (GPUBufferUsage.STORAGE) differ from uniform buffers in three key ways: (1) they can be very large with no practical size limit; (2) they support dynamically-sized arrays in WGSL (array<u32> without a fixed count); (3) they can be written by compute shaders with var<storage, read_write>. Read-only access uses var<storage>. Storage buffers are the right choice for simulation state, large data sets, and any buffer a compute shader outputs to. They require explicit bind group layout entries when mixing with compute pipelines.

Examples

WGSL: @group(0) @binding(1) var<storage> cellStateIn: array<u32>; (read-only) @group(0) @binding(2) var<storage, read_write> cellStateOut: array<u32>; (read-write for compute)

Assessment

A simulation needs a 1024-element array of u32 values that a compute shader writes to. Why does a uniform buffer fail here? Write the WGSL declaration for the writable storage binding.

“Storage buffers are general-use buffers that can be read and written to in compu”
corpus · your-first-webgpu-app-google-codelab · chunk 15