---
title: "storage: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점 | TypeShade"
description: "스토리지 선언은 셰이더 호출들이 인덱스로 접근하는 호스트 바인딩 버퍼를 나타냅니다. 큰 배열을 처리하거나 컴퓨트 결과를 기록할 때 사용합니다. 읽기·쓰기는 명시적으로 지정해야 합니다. 선언은 메모리를 할당하지 않으며 호스트가 버퍼를 제공합니다."
url: https://typeshade.dev/ko/reference/functions/storage/
language: ko
---

# `storage`

함수

스토리지 선언은 셰이더 호출들이 인덱스로 접근하는 호스트 바인딩 버퍼를 나타냅니다.

## 예제 비교

읽기는 선택한 원소를 반환합니다. 쓰기는 선택한 위치만 바꾸고 나머지 원소는 그대로 둡니다.

**모델의 전제**`declare const xs: storage<array<f32>, "read_write">;`

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

**결과**

`2`

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

**결과**

`[1, 7, 3]`

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

**결과**

`[0, 2, 3]`

예제는 설명용 계산 모델이며 GPU를 실행하지 않습니다. 정확한 호출 형식은 아래 컴파일러 참고 자료에서 설명합니다. 소수 결과는 표시할 때 반올림했습니다. 각 예제는 명시한 전제를 따릅니다. 실제 셰이더의 결과는 대상 언어의 정밀도와 실행 규칙에 따릅니다.

## 활용

큰 배열을 처리하거나 컴퓨트 결과를 기록할 때 사용합니다.

## 입력 범위와 주의사항

읽기·쓰기는 명시적으로 지정해야 합니다. 선언은 메모리를 할당하지 않으며 호스트가 버퍼를 제공합니다. 공유 쓰기는 소유권 분리, 원자 연산 또는 적절한 동기화가 필요합니다.

셰이더의 입력 규칙과 정밀도는 [WGSL](https://www.w3.org/TR/WGSL/)과 [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf)에서 규정합니다.

## 관련 함수

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

시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 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.

## 구문

```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>
```

매개변수나 반환 위치에 쓰인 `number`는 스칼라가 들어갈 자리입니다. 앰비언트 파일은 GPU 스칼라를 브랜드가 붙은 number로 선언하고 그 브랜드는 선택이라서, 리터럴도 브랜드가 붙은 스칼라도 이 자리에 들어갑니다.

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

타입으로 쓴 `number`는 쓰이는 곳을 보고 추론하며, `f32`, `i32`, `u32`는 너비를 고정합니다. 그 행과 컴파일러가 낸 결과는 [TypeScript에서](https://typeshade.dev/ko/guide/language/from-typescript/) 페이지에 있습니다.

시그니처에는 앰비언트 파일이 스스로 쓰려고 선언한 타입이 나올 수 있습니다. 아래가 그 선언입니다.

**`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] }`

## 매개변수

- `slot` 선택 사항 `number | { group?: number; binding?: number }`
- `binding` 선택 사항 `number`

## 반환값

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

## 설명

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

## 예제

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

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
