---
title: "FuncDecl: TypeShade 셰이더 API의 IR 분류 인터페이스 참조 문서"
description: "FuncDecl, TypeShade API의 IR 분류에 속하는 인터페이스입니다. ModuleDecl.funcs 항목입니다. WGSL/GLSL 함수이며, 일반 헬퍼 함수이거나 파이프라인 진입점(stage가 설정된 함수)입니다."
url: https://typeshade.dev/ko/api/funcdecl/
language: ko
---

# `FuncDecl`

인터페이스, IR 분류

ModuleDecl.funcs 항목입니다. WGSL/GLSL 함수이며, 일반 헬퍼 함수이거나 파이프라인 진입점(stage가 설정된 함수)입니다.

`import type { FuncDecl } from 'typeshade'`
`import type { FuncDecl } from 'typeshade/core/ir'`

설명은 커밋 af54ddad5의 검토된 컴파일러 문서를 번역한 것입니다. 시그니처와 예제 코드는 원문을 따르며, 필요한 경우 설명에 편집상 수정이 반영됩니다.

## 구문

```ts
interface FuncDecl {
  readonly name: string;
  readonly params: readonly { name: string; type: ShaderType; builtin?: string; location?: number; interpolate?: string; attr?: string; /** How the function takes this parameter. Absent is by value, which is every parameter * but one that the callee writes through to the caller's own value. `'inout'` says it * does: GLSL ES 3.00 spells that `inout T name`, WGSL a pointer. * * The IR says WHICH parameters are written, not how a target spells it, because the two * targets do not agree on that. GLSL's `inout` is copy-in/copy-out and takes any l-value * argument; WGSL's pointer is a reference and carries the ADDRESS SPACE in its type, so a * function taking `ptr<function, T>` cannot be handed `&buf[i]`. The WGSL backend's own * pass makes one copy of the function per address space its calls use; nothing about * that reaches here, and GLSL emits the one function. */ mode?: 'inout'; }[];
  readonly ret: ShaderType;
  readonly body: readonly Stmt[];
  readonly attrs?: readonly string[];
  readonly stage?: 'vertex' | 'fragment' | 'compute';
  readonly workgroupSize?: number;
  readonly workgroupShape?: WorkgroupShape;
  readonly workgroupSizeOverrides?: readonly [ string | undefined, string | undefined, string | undefined, ];
  readonly portable?: boolean;
  readonly kernel?: boolean;
  readonly retAttr?: string;
  readonly retBuiltin?: string;
  readonly opaque?: boolean;
  readonly span?: SourceSpan;
  readonly nameSpan?: SourceSpan;
  readonly allowEarlyReturn?: boolean;
  readonly lintDisable?: readonly string[];
  readonly [ASSEMBLED_AS]?: string;
}
```

## 설명

`ModuleDecl.funcs` 항목입니다. WGSL/GLSL 함수이며, 일반 헬퍼 함수이거나 파이프라인 진입점(`stage`가 설정된 함수)입니다. 이 객체는 [`fn`](https://typeshade.dev/ko/api/fn/)이 만듭니다. 그것이 반환하는 [`FnHandle`](https://typeshade.dev/ko/api/fnhandle/)은 이 필드들을 자기 자신에 섞어 넣습니다. 그래서 같은 객체는 다른 함수 본문에서 타입이 지정된 호출 대상이 되고, 감싸지 않으면 `module({ funcs })`가 모으는 일반 `FuncDecl`이 됩니다. 모든 백엔드(WGSL, GLSL, CPU)가 `body`를 직접 순회합니다.

## 인스턴스 속성

**`name` 읽기 전용 `string`**

**`params` 읽기 전용 ``readonly { name: string; type: ShaderType; builtin?: string; location?: number; interpolate?: string; attr?: string; /** How the function takes this parameter. Absent is by value, which is every parameter * but one that the callee writes through to the caller's own value. `'inout'` says it * does: GLSL ES 3.00 spells that `inout T name`, WGSL a pointer. * * The IR says WHICH parameters are written, not how a target spells it, because the two * targets do not agree on that. GLSL's `inout` is copy-in/copy-out and takes any l-value * argument; WGSL's pointer is a reference and carries the ADDRESS SPACE in its type, so a * function taking `ptr<function, T>` cannot be handed `&buf[i]`. The WGSL backend's own * pass makes one copy of the function per address space its calls use; nothing about * that reaches here, and GLSL emits the one function. */ mode?: 'inout'; }[]``**

**`ret` 읽기 전용 `ShaderType`**

**`body` 읽기 전용 `readonly Stmt[]`**

**`attrs` 선택 사항 읽기 전용 `readonly string[]`**

`fn` 앞에 생성되는 스테이지와 파이프라인 속성입니다. 예를 들어 `@compute`나 `@workgroup_size(64)`가 여기에 해당합니다. 일반 헬퍼 함수에서는 비어 있습니다. 이 문자열은 생성되는 표기입니다. 아래의 `stage`와 `workgroupSize`는 [`reflect`](https://typeshade.dev/ko/api/reflect/)와 백엔드가 먼저 읽는 값이고, 손으로 만든 `FuncDecl` 리터럴에서는 이 문자열이 대체값으로 쓰입니다.

**`stage` 선택 사항 읽기 전용 `'vertex' | 'fragment' | 'compute'`**

구조화된 파이프라인 스테이지입니다. `fn()`의 `opts.stage`로 설정됩니다.

**`workgroupSize` 선택 사항 읽기 전용 `number`**

컴퓨트 스테이지의 구조화된 워크그룹 크기이며, `x` 방향 크기입니다.

**`workgroupShape` 선택 사항 읽기 전용 `WorkgroupShape`**

컴퓨트 스테이지의 워크그룹 세 방향 크기입니다. `y`나 `z`가 1이 아닐 때 이 값이 있습니다. 이 값이 없으면 형태는 `[workgroupSize, 1, 1]`입니다. [`workgroupShapeOf`](https://typeshade.dev/ko/api/workgroupshapeof/)를 통해 읽습니다.

**`workgroupSizeOverrides` 선택 사항 읽기 전용 `readonly [ string | undefined, string | undefined, string | undefined, ]`**

대응하는 워크그룹 형태 축을 특수화하는 오버라이드 식별자입니다. 숫자형 `workgroupShape`는 각 오버라이드가 선언한 기본값을 그대로 유지합니다.

**`portable` 선택 사항 읽기 전용 `boolean`**

컴퓨트 진입점을 이식 가능한 커널로 표시합니다. `fn()`의 `opts.portable`로 설정되며, 다른 스테이지에서는 [`SD0110`](https://typeshade.dev/ko/reference/errors/sd0110/)으로 거부됩니다.

이식 가능한 커널은 두 백엔드 모두에서 생성됩니다. WGSL에서는 `@compute` 진입점으로 직접 생성됩니다. GLSL ES 3.00에서는 [`lowerComputeToFragment`](https://typeshade.dev/ko/api/lowercomputetofragment/) 재작성을 거쳐 프래그먼트 셰이더로 실행됩니다.

커널은 gather 전용 모양을 지켜야 합니다. 각 호출은 다른 위치의 값을 자유롭게 읽고, 자기 출력 인덱스에 정확히 한 번만 씁니다. 이 모양을 벗어나는 구문은 두 백엔드 모두에서 어느 생성 시점이든 [`SD0111`](https://typeshade.dev/ko/reference/errors/sd0111/)로 검증에 실패합니다.

구조화된 필드로만 쓰며 `attrs` 표기는 없습니다. `portable`은 WGSL 속성이 아니므로, 선언해도 생성된 소스는 바뀌지 않습니다.

**`kernel` 선택 사항 읽기 전용 `boolean`**

커널 함수를 표시한다([규칙 8.22](https://typeshade.dev/ko/reference/rules/8-22/)). 크기 없는 배열을 받는 내보내기 함수이며, 진입점은 아닙니다. 커널은 호출하는 쪽의 호스트에서 실행되며, 그 호스트가 루프를 디스패치합니다. 그래서 WGSL과 GLSL 백엔드는 생성 결과에서 커널을 뺍니다. 어떤 함수도 커널을 호출하지 않는다([규칙 8.6](https://typeshade.dev/ko/reference/rules/8-6/)). 커널의 배열 매개변수는 호출하는 쪽의 스토리지이며, 참조로 전달된다([규칙 8.23](https://typeshade.dev/ko/reference/rules/8-23/)).

구조화된 필드로만 있으며 `attrs` 표기가 없습니다. WGSL 속성이 아닙니다.

**`retAttr` 선택 사항 읽기 전용 `string`**

구조체로 감싸지 않은 스테이지 출력의 반환값 속성입니다. 예를 들어 프래그먼트 스테이지의 `-> @location(0) vec4<f32>`가 여기에 해당합니다.

**`retBuiltin` 선택 사항 읽기 전용 `string`**

`retAttr`가 [`FieldSpec`](https://typeshade.dev/ko/api/fieldspec/)의 `builtin(name, type)`에서 왔을 때 쓰는 구조화된 빌트인 id입니다. 표기는 `retAttr`에 남고, id는 이곳에 있습니다. 그래서 백엔드가 속성 문자열을 다시 파싱하지 않고도 자기 빌트인 어휘와 대조할 수 있습니다.

**`opaque` 선택 사항 읽기 전용 `boolean`**

이 함수의 본문을 호출 지점에 넣지 않습니다. 생성 최적화기는 이 함수의 호출을 인라인하지 않습니다. [`fp64Lower`](https://typeshade.dev/ko/api/fp64lower/)는 주입하는 모든 배정밀도 헬퍼에 이 값을 설정합니다. 그 본문은 오류 없는 변환이며 대수적으로 자명하다(`e = b - (s - a)`는 실수 산술에서 0입니다). 그래서 본문을 펼치면, 항을 합법적으로 소거할 수 있는 패스와 드라이버에 항을 넘기게 됩니다.

이 값은 선언의 속성이므로, 생성 과정이 함수 이름에 적용하는 이름 변경을 모두 거쳐도 유지됩니다.

구조화된 필드로만 쓰며 (위의 `portable`처럼) `attrs` 표기는 없습니다. WGSL 속성이 아니므로 생성된 소스를 바꾸지 않습니다.

**`span` 선택 사항 읽기 전용 `SourceSpan`**

이 함수가 작성된 `"use typeshade"` 소스에서 선언된 위치입니다. 선언 전체를 가리키며, 첫 데코레이터나 `export` 키워드부터 닫는 중괄호까지입니다. EDSL로 작성된 함수나 패스가 합성한 함수에는 없습니다. [`sourceSpanOf`](https://typeshade.dev/ko/api/sourcespanof/)로 읽습니다.

**`nameSpan` 선택 사항 읽기 전용 `SourceSpan`**

작성된 소스에서 이 함수의 이름만 차지하는 범위입니다. 그래서 스택 프레임이 본문 전체 대신 식별자를 강조할 수 있습니다. `span`이 없을 때는 이 값도 항상 없습니다.

**`allowEarlyReturn` 선택 사항 읽기 전용 `boolean`**

단일 종료 린트 규칙에서 문서로 기록된 예외입니다. 값이 true이면 이 함수에 의도된 조기 반환이 있으므로 린트 규칙이 이 함수를 건너뜁니다. 예를 들어 비싼 루프를 건너뛰는 가드가 이에 해당합니다. 사용을 제한하고, 이유를 밝히는 주석을 함께 작성합니다.

**`lintDisable` 선택 사항 읽기 전용 `readonly string[]`**

문서로 기록된 린트 예외입니다. 이 함수에서 진단이 억제되는 규칙 id 목록입니다. `allowEarlyReturn`의 일반형입니다. 사용을 제한하고, 이유를 밝히는 주석을 함께 작성합니다.

## 함께 보기

- [`fn`](https://typeshade.dev/ko/api/fn/)
- [`FnHandle`](https://typeshade.dev/ko/api/fnhandle/)
- [`reflect`](https://typeshade.dev/ko/api/reflect/)
- [`workgroupShapeOf`](https://typeshade.dev/ko/api/workgroupshapeof/)
- [`lowerComputeToFragment`](https://typeshade.dev/ko/api/lowercomputetofragment/)
- [`FieldSpec`](https://typeshade.dev/ko/api/fieldspec/)
- [`fp64Lower`](https://typeshade.dev/ko/api/fp64lower/)
- [`sourceSpanOf`](https://typeshade.dev/ko/api/sourcespanof/)
- [`module`](https://typeshade.dev/ko/api/module/)

## 소스

[`src/core/ir/nodes.ts`, 402행](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/nodes.ts#L402), 커밋 af54ddad5 기준
