---
title: "subgroupShuffleUp: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "셔플은 각 레인에 delta만큼 아래 레인의 값을 줍니다. 앞 레인의 값을 읽을 때 씁니다. 0보다 작은 레인은 정해지지 않은 값을 줍니다. 다른 레인을 읽는 것은 WebGL2와 오라클에서 결정론 보고서의 target 행입니다."
url: https://typeshade.dev/ko/reference/functions/subgroupShuffleUp/
language: ko
---

# `subgroupShuffleUp`

함수

셔플은 각 레인에 delta만큼 아래 레인의 값을 줍니다.

## 예제 비교

delta가 1이면 각 레인이 이전 레인을 읽습니다. 레인 0은 서브그룹 아래의 레인을 이름 지어 ?로 표시합니다. 레인 하나에서는 레인 자신의 값을 줍니다.

**모델의 전제**`subgroup of 4 lanes; x = [3, 1, 4, 1]; p = [true, false, true, true]`

**예제 1`subgroupShuffleUp(x, 1)`**

**결과**

`[?, 3, 1, 4] by lane`

**예제 2`subgroupShuffleUp(x, 1)`**

**결과**

`one lane (WebGL2, CPU oracle): x`

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

## 활용

앞 레인의 값을 읽을 때 씁니다.

## 입력 범위와 주의사항

0보다 작은 레인은 정해지지 않은 값을 줍니다. 다른 레인을 읽는 것은 WebGL2와 오라클에서 결정론 보고서의 target 행입니다.

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

## 관련 함수

- [`subgroupAdd`](https://typeshade.dev/ko/reference/functions/subgroupAdd/)
- [`subgroupElect`](https://typeshade.dev/ko/reference/functions/subgroupElect/)
- [`subgroupBallot`](https://typeshade.dev/ko/reference/functions/subgroupBallot/)
- [`subgroupBroadcast`](https://typeshade.dev/ko/reference/functions/subgroupBroadcast/)

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

Returns `e` from the lane `delta` below this one in the subgroup.

## 구문

```ts
declare function subgroupShuffleUp<V extends vec2 | vec3 | vec4 | vec2i | vec3i | vec4i | vec2u | vec3u | vec4u>(value: V, delta: u32): V
declare function subgroupShuffleUp<P0 extends number>(value: P0, delta: u32): ScalarOf<P0>
```

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

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

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

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

**`ScalarOf`**

`type ScalarOf<A, B = unknown, C = unknown> = unknown extends A ? number : [A] extends [boolean] ? bool : typeof f32Tag extends keyof A ? f32 : typeof i32Tag extends keyof A ? i32 : typeof u32Tag extends keyof A ? u32 : typeof f64Tag extends keyof A ? f64 : ScalarOf<B, C>`

## 매개변수

- `value` `V``P0`
- `delta` `u32`

## 반환값

`V``ScalarOf<P0>`

## 설명

On the CPU oracle and on WebGL2 a subgroup is one invocation ([Rule 11.21](https://typeshade.dev/ko/reference/rules/11-21/)), so it gives the lane's own value.

## 대상별 출력

**WGSL**

`subgroupShuffleUp(a, b)`

**GLSL ES 3.00**

`subgroupShuffleUp` is lowered to one lane before the GLSL writer runs (Rule 11.21)

## 함께 보기

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