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

# `workgroupBarrier`

함수

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

**다른 언어의 관련 이름**

관련 연산은 인수, 지원 범위와 의미가 다를 수 있습니다. 다른 언어의 이름을 TypeShade 별칭으로 사용할 수는 없습니다. 지원하는 형태와 제한은 대상 언어에 따라 다릅니다.

- GLSL: `barrier`
- HLSL: `GroupMemoryBarrierWithGroupSync`

[대상별 출력](https://typeshade.dev/ko/reference/functions/workgroupBarrier/#targets)

## 예제 비교

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

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

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

**결과**

`A.write ≺ B.read`

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

**결과**

`A.write ≺ A.read`

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

**결과**

`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)에서 규정합니다.

## 관련 함수

- [`storageBarrier`](https://typeshade.dev/ko/reference/functions/storageBarrier/)
- [`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 workgroup memory before it visible to every invocation after it.

## 구문

```ts
declare function workgroupBarrier(): 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**

`workgroupBarrier()`

**GLSL ES 3.00**

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

## 예제

- [`path/parallel-sum/parallel-sum.shade.ts`](https://typeshade.dev/ko/guide/examples/parallel-sum/)
- [`gallery/compute-sync/compute-sync.shade.ts`](https://typeshade.dev/ko/guide/examples/compute-sync/)
- [`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-tile-2d/workgroup-tile-2d.shade.ts`](https://typeshade.dev/ko/guide/examples/workgroup-tile-2d/)

## 함께 보기

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