---
title: "atomicSub: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점 | TypeShade"
description: "공유 정수에서 값을 빼고 갱신 전의 값을 돌려줍니다. 남은 작업 수를 추적할 때 사용합니다. 모델은 부호 없는 정수에 연산 하나를 순서대로 적용합니다. 실제 호출 순서는 정해져 있지 않습니다. 원자성은 다른 메모리를 동기화하지 않습니다."
url: https://typeshade.dev/ko/reference/functions/atomicSub/
language: ko
---

# `atomicSub`

함수

공유 정수에서 값을 빼고 갱신 전의 값을 돌려줍니다.

## 예제 비교

반환값은 뺄셈 전의 값입니다. 부호 없는 정수에서 영보다 작아지는 차는 순환합니다.

**모델의 전제**`location: atomic<u32>`

**예제 1`atomicSub(location, 3)`**

**연산 전 저장값**

`5`

**반환값**

`5`

**연산 후 저장값**

`2`

**예제 2`atomicSub(location, 1)`**

**연산 전 저장값**

`0`

**반환값**

`0`

**연산 후 저장값**

`4294967295`

**예제 3`atomicSub(location, 1)`**

**연산 전 저장값**

`4294967295`

**반환값**

`4294967295`

**연산 후 저장값**

`4294967294`

예제는 설명용 계산 모델이며 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)에서 규정합니다.

## 관련 함수

- [`atomicLoad`](https://typeshade.dev/ko/reference/functions/atomicLoad/)
- [`atomicStore`](https://typeshade.dev/ko/reference/functions/atomicStore/)
- [`atomicAdd`](https://typeshade.dev/ko/reference/functions/atomicAdd/)
- [`atomicMin`](https://typeshade.dev/ko/reference/functions/atomicMin/)
- [`atomicMax`](https://typeshade.dev/ko/reference/functions/atomicMax/)

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

Subtracts `value` from the atomic location as one indivisible step and returns the value it held before.

## 구문

```ts
declare function atomicSub<T extends u32 | i32>(location: atomic<T>, value: T): T
```

## 매개변수

- `location` `atomic<T>`
- `value` `T`

## 반환값

`T`

## 설명

Wraps at 32 bits. Compiles to `atomicSub(&bins[i], v)` on WGSL; the GLSL lowering in a render entry is not supported yet ([Rule 10.5](https://typeshade.dev/ko/reference/rules/10-5/)), and a `@compute` entry that reaches no texture runs on WebGL2 as its pass program ([Rule 8.24](https://typeshade.dev/ko/reference/rules/8-24/), [Rule 11.8](https://typeshade.dev/ko/reference/rules/11-8/)).

## 대상별 출력

**WGSL**

`atomicSub(&a, b)`

**GLSL ES 3.00**

`atomicSub` is not supported yet in a GLSL ES 3.00 stage (Rule 10.5); a `@compute` entry that reaches no texture runs it on WebGL2 as its pass program (Rule 11.8)

## 함께 보기

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