---
title: "규칙 8.3: 함수와 진입점, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 8.3(함수와 진입점)입니다. A builtin WGSL confines by stage may be used in an entry of a permitted stage…"
url: https://typeshade.dev/ko/reference/rules/8-3/
language: ko
---

# 규칙 8.3

8장, 함수와 진입점 테스트

A builtin WGSL confines by stage may be used in an entry of a permitted stage, and in a helper that no entry of an excluded stage can reach. The derivatives, implicit-LOD sampling, and `discard` may be used in the fragment stage only. Barriers and workgroup memory may be used in the compute stage only. The atomic builtins may be used in the compute and fragment stages, and must not be used in the vertex stage.

규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

## 근거

the stage rule is Tint’s, and the call graph is how a helper inherits it.

## 출처

- [Derivative Built-in Functions](https://gpuweb.github.io/gpuweb/wgsl/#derivative-builtin-functions) (“must only be used in a fragment shader stage”);
- [Discard Statement](https://gpuweb.github.io/gpuweb/wgsl/#discard-statement);
- [Synchronization Built-in Functions](https://gpuweb.github.io/gpuweb/wgsl/#sync-builtin-functions) (“all synchronization functions must only be used in the compute shader stage”);
- [Address Spaces](https://gpuweb.github.io/gpuweb/wgsl/#address-space) (“variables in the workgroup address space must only be statically accessed in a compute shader stage”);
- [Atomic Built-in Functions](https://gpuweb.github.io/gpuweb/wgsl/#atomic-builtin-functions) (“atomic built-in functions must not be used in a vertex shader stage”, with no other stage restriction);
- surface §10, §24, and §25.

## 검증 방식

테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.

컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.

- the reachability check in `src/compiler/ts/stage-restrictions.ts` ([`TS8099`](https://typeshade.dev/ko/reference/errors/ts8099/) names the builtin, the helper, and the entry) for the fragment-only builtins;
- [`TS8033`](https://typeshade.dev/ko/reference/errors/ts8033/) for workgroup memory, and [`TS8034`](https://typeshade.dev/ko/reference/errors/ts8034/) for a barrier outside a compute entry (a barrier in a branch is [Rule 8.5](https://typeshade.dev/ko/reference/rules/8-5/)’s [`TS8052`](https://typeshade.dev/ko/reference/errors/ts8052/));
- `TS8099` for an atomic builtin in a `@vertex` entry or in a helper it reaches (`"atomicAdd" is only valid in a fragment or compute shader; "vs" is a vertex entry. WGSL allows an atomic built-in in a fragment or compute stage only.`), pinned by `src/compiler/ts/atomics.test.ts` (`refuses atomicAdd in a vertex entry`).

커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

- [`src/compiler/ts/atomics.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/atomics.test.ts#L1)
- [`src/compiler/ts/compute-stage-reachability.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/compute-stage-reachability.test.ts#L1)
- [`src/compiler/ts/lower/function.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/function.ts#L1)
- [`src/compiler/ts/stage-restrictions.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/stage-restrictions.ts#L1)

## 설명하는 절

커밋 af54ddad5의 언어 문서에서 이 규칙을 설명하는 절입니다.

- [§10 Builtins, casts and `discard`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#10-builtins-casts-and-discard)

## 적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

**[`TS8033`](https://typeshade.dev/ko/reference/errors/ts8033/) `MODULE_VAR`**

주소 공간이 허용하지 않는 곳에서 모듈 변수를 선언하거나 씁니다. 주소 공간 래퍼가 붙은 `const`, 초기값이 있는 `workgroup` 변수, 그 공간이 담을 수 없는 타입(텍스처, 런타임 크기 배열, 호출별 변수 안의 atomic), 상수가 아닌 초기값, 정점이나 프래그먼트 진입점이 닿는 `workgroup` 변수가 그렇습니다. 일반 최상위 `let`이 대신하게 된 `perInvocation<T>` 래퍼도 여기에 속합니다.

**[`TS8034`](https://typeshade.dev/ko/reference/errors/ts8034/) `BARRIER_PLACEMENT`**

배리어가 놓일 수 없는 곳의 `workgroupBarrier()`나 `storageBarrier()`입니다. 워크그룹이 없는 정점이나 프래그먼트 진입점 안이거나, 배리어는 문이므로 값으로 쓴 경우입니다. 호출들이 공유하지 않는 제어 흐름 아래의 배리어는 `UNIFORMITY`입니다.

**[`TS8052`](https://typeshade.dev/ko/reference/errors/ts8052/) `UNIFORMITY`**

배리어, `workgroupUniformLoad`, 그리고 컴파일러의 재작성이 닿지 못하는 도함수나 암묵적 LOD 샘플이 균일하지 않은 값에 대한 조건 아래에 있거나, 그런 조건 아래에서 실행한 `return`, `break`, `continue` 뒤에 있습니다([규칙 8.5](https://typeshade.dev/ko/reference/rules/8-5/)). 메시지가 작성자가 쓴 그대로의 값과 그 문장을 알려 줍니다.

**[`TS8099`](https://typeshade.dev/ko/reference/errors/ts8099/) `UNSUPPORTED`**

자기 코드를 받을 만하지 않은 진단을 위한 포괄 코드입니다. 순차 범위 뒤인 TS8099에 따로 둡니다.

## 함께 보기

- [규칙 8.2](https://typeshade.dev/ko/reference/rules/8-2/) 테스트
- [규칙 8.4](https://typeshade.dev/ko/reference/rules/8-4/) 테스트
- [규칙 8.5](https://typeshade.dev/ko/reference/rules/8-5/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

- [`docs/language-design.md:792`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L792) (설계 문서)
- [`reqs/rules/RULE-0803.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0803.md) (추적 항목)
