---
title: "storage: shader function examples, uses and input limits"
description: "A storage declaration describes a host-bound buffer that shader invocations can index. Use it for processing large arrays and writing compute results."
url: https://typeshade.dev/reference/functions/storage/
language: en
---

# `storage`

Function

A storage declaration describes a host-bound buffer that shader invocations can index.

## Compare examples

A read returns the selected element. A write changes only the selected location and leaves the other elements unchanged.

**Model assumptions**`declare const xs: storage<array<f32>, "read_write">;`

**Example 1`host: xs = [1, 2, 3]; shader: xs[1]`**

**Result**

`2`

**Example 2`host: xs = [1, 2, 3]; shader: xs[1] = 7`**

**Result**

`[1, 7, 3]`

**Example 3`host: xs = [1, 2, 3]; shader: xs[0] = 0`**

**Result**

`[0, 2, 3]`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it for processing large arrays and writing compute results.

## Inputs and limits

Read-write access must be explicit. The declaration allocates nothing; the host supplies the buffer. Shared writes need ownership, atomics, or suitable synchronization.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`uniform`](https://typeshade.dev/reference/functions/uniform/)
- [`atomicAdd`](https://typeshade.dev/reference/functions/atomicAdd/)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Declares a storage binding of type T; use `declare const name: storage<T>` for read-only or `declare const name: storage<T, "read_write">` for read-write access.

## Syntax

```ts
declare function storage<T, A extends StorageBufferAccess = 'read_write'>(slot?: number | { group?: number; binding?: number }, binding?: number): A extends 'read_write' ? T : ReadView<T>
```

A `number` in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

`type f32 = number & { readonly [f32Tag]?: true }`

A `number` you write as a type is inferred from its uses, and `f32`, `i32` and `u32` fix a width; [the TypeScript constructs page](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

A signature may name a type the ambient file declares for its own use. These are those declarations.

**`StorageBufferAccess`**

`type StorageBufferAccess = 'read' | 'read_write'`

**`ReadView`**

`type ReadView<T> = T extends number | boolean ? T : T extends (...args: never[]) => unknown ? T : { readonly [K in keyof T]: K extends string | number ? ReadView<T[K]> : T[K] }`

## Parameters

- `slot` optional `number | { group?: number; binding?: number }`
- `binding` optional `number`

## Return value

`A extends 'read_write' ? T : ReadView<T>`

## Description

The access mode is part of the type, as it is in WGSL (`var<storage, read_write>`); the declaration is always `declare const`.

## Examples

- [`path/double-array/double-array.shade.ts`](https://typeshade.dev/guide/examples/double-array/)
- [`path/image-blur/image-blur.shade.ts`](https://typeshade.dev/guide/examples/image-blur/)
- [`path/parallel-sum/parallel-sum.shade.ts`](https://typeshade.dev/guide/examples/parallel-sum/)
- [`path/histogram/histogram.shade.ts`](https://typeshade.dev/guide/examples/histogram/)
- [`gallery/array-length/array-length.shade.ts`](https://typeshade.dev/guide/examples/array-length/)
- [`gallery/atomic-histogram/atomic-histogram.shade.ts`](https://typeshade.dev/guide/examples/atomic-histogram/)
- [`gallery/compute-reduction-twin/compute-reduction-twin.shade.ts`](https://typeshade.dev/guide/examples/compute-reduction-twin/)
- [`gallery/compute-sync/compute-sync.shade.ts`](https://typeshade.dev/guide/examples/compute-sync/)
- [`gallery/gpu-console/gpu-console.shade.ts`](https://typeshade.dev/guide/examples/gpu-console/)
- [`gallery/particle-step/particle-step.shade.ts`](https://typeshade.dev/guide/examples/particle-step/)
- [`gallery/subgroup-reduce/subgroup-reduce.shade.ts`](https://typeshade.dev/guide/examples/subgroup-reduce/)
- [`gallery/workgroup-override/workgroup-override.shade.ts`](https://typeshade.dev/guide/examples/workgroup-override/)
- [`gallery/workgroup-reduce/workgroup-reduce.shade.ts`](https://typeshade.dev/guide/examples/workgroup-reduce/)
- [`gallery/workgroup-scratch/workgroup-scratch.shade.ts`](https://typeshade.dev/guide/examples/workgroup-scratch/)
- [`gallery/workgroup-tile-2d/workgroup-tile-2d.shade.ts`](https://typeshade.dev/guide/examples/workgroup-tile-2d/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
