---
title: "subgroupBallot: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점"
description: "ballot은 레인마다 비트 하나를 가진 vec4u를 모든 레인에 줍니다. 단어 i / 32의 비트 i가 레인 i의 bool입니다. 투표한 레인의 수를 countOneBits로 세거나, 처음 투표한 레인을 찾을 때 씁니다."
url: https://typeshade.dev/ko/reference/functions/subgroupBallot/
language: ko
---

# `subgroupBallot`

함수

ballot은 레인마다 비트 하나를 가진 `vec4u`를 모든 레인에 줍니다. 단어 i / 32의 비트 i가 레인 i의 bool입니다.

## 예제 비교

픽스처의 투표는 true, false, true, true로 비트 0, 2, 3이 켜져 13입니다. 레인 하나에서는 비트 0만 켜질 수 있습니다.

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

**예제 1`subgroupBallot(p)`**

**결과**

`vec4u(13, 0, 0, 0) in every lane: bit i is lane i`

**예제 2`subgroupBallot(p)`**

**결과**

`one lane (WebGL2, CPU oracle): vec4u(u32(p), 0, 0, 0)`

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

## 활용

투표한 레인의 수를 `countOneBits`로 세거나, 처음 투표한 레인을 찾을 때 씁니다.

## 입력 범위와 주의사항

모든 레인이 함께 도착해야 합니다. 서브그룹 크기를 넘는 비트는 0입니다.

셰이더의 입력 규칙과 정밀도는 [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/)
- [`subgroupBroadcast`](https://typeshade.dev/ko/reference/functions/subgroupBroadcast/)
- [`subgroupShuffle`](https://typeshade.dev/ko/reference/functions/subgroupShuffle/)

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

Returns a `vec4u` bitmask with one bit per lane of the subgroup, set where `pred` is true.

## 구문

```ts
declare function subgroupBallot(a0: bool): vec4u
```

## 매개변수

`a0`, `a1`처럼 자리로만 붙은 매개변수 이름은 앰비언트 파일이 만들어 낸 것입니다. 호출은 인자를 순서대로 넘기고 이름은 쓰지 않습니다.

- `a0` `bool`

## 반환값

`vec4u`

## 설명

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

`subgroupBallot(a)`

**GLSL ES 3.00**

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