---
title: "storageBarrier: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "한 워크그룹의 호출들이 도착할 때까지 기다리고 스토리지 메모리 접근의 순서를 맞춥니다. 스토리지 메모리에 함께 기록하는 단계와 그 값을 읽는 단계 사이에 사용합니다. 워크그룹의 모든 호출이 균일한 제어 흐름에서 배리어에 도착해야 합니다."
url: https://typeshade.dev/ko/reference/functions/storageBarrier/
language: ko
---

# `storageBarrier`

함수

한 워크그룹의 호출들이 도착할 때까지 기다리고 스토리지 메모리 접근의 순서를 맞춥니다.

## 예제 비교

같은 워크그룹에서는 배리어 전의 스토리지 메모리 쓰기가 배리어 후의 읽기보다 앞섭니다. 다른 워크그룹 사이에는 이 순서가 성립하지 않습니다.

**모델의 전제**`A, B ∈ workgroup W; C ∈ workgroup V; W ≠ V`

**예제 1`W: A.write → storageBarrier() → B.read`**

**결과**

`A.write ≺ B.read`

**예제 2`W: A.write → storageBarrier() → A.read`**

**결과**

`A.write ≺ A.read`

**예제 3`W.storageBarrier(); V.storageBarrier()`**

**결과**

`scope(W) ≠ scope(V)`

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

## 활용

스토리지 메모리에 함께 기록하는 단계와 그 값을 읽는 단계 사이에 사용합니다.

## 입력 범위와 주의사항

워크그룹의 모든 호출이 균일한 제어 흐름에서 배리어에 도착해야 합니다. 장치 전체의 배리어는 아닙니다. 이 컴파일러에서는 컴퓨트와 WebGPU 전용입니다.

셰이더의 입력 규칙과 정밀도는 [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)에서 규정합니다.

## 관련 함수

- [`workgroupBarrier`](https://typeshade.dev/ko/reference/functions/workgroupBarrier/)
- [`textureBarrier`](https://typeshade.dev/ko/reference/functions/textureBarrier/)
- [`workgroupUniformLoad`](https://typeshade.dev/ko/reference/functions/workgroupUniformLoad/)

시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 af54ddad5의 컴파일러가 쓴 영어 원문입니다.

Waits until every invocation of the workgroup has reached this line, and makes every write to storage before it visible to every invocation after it.

## 구문

```ts
declare function storageBarrier(): void
```

## 반환값

`void`

## 설명

A statement, in a compute entry or a helper and never inside an `if` or `switch`. On WebGL2 it cuts a phase of the pass program, when the entry reaches no texture ([Rule 8.24](https://typeshade.dev/ko/reference/rules/8-24/)); the CPU oracle runs the workgroup in lockstep through `dispatch`.

## 대상별 출력

**WGSL**

`storageBarrier()`

**GLSL ES 3.00**

이 대상에는 형태가 없습니다.

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
- [내장 함수 표](https://typeshade.dev/ko/guide/language/builtins/#barriers)
