FuncDecl
이 페이지에서

FuncDecl

인터페이스, IR 분류

A ModuleDecl.funcs entry: a WGSL/GLSL function, either an ordinary helper or a pipeline entry point (stage set).

import type { FuncDecl } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

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 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;
}

설명

A ModuleDecl.funcs entry: a WGSL/GLSL function, either an ordinary helper or a pipeline entry point (stage set). This is the object fn builds: the FnHandle it returns mixes these fields onto itself, so it is at once a typed callable in other function bodies and, unwrapped, the plain FuncDecl that module({ funcs }) collects. Every backend (WGSL, GLSL, CPU) walks body directly.

인스턴스 속성

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[]

Stage and pipeline attributes emitted before fn, such as @compute or @workgroup_size(64). Empty for ordinary helper functions. This is the emitted spelling; stage and workgroupSize below are what reflect and the backends read first, with these strings as the fallback for a hand-built FuncDecl literal.

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

Structured pipeline stage. Set by fn()’s opts.stage.

workgroupSize선택 사항읽기 전용 number

Structured workgroup size for a compute stage: the x extent.

workgroupShape선택 사항읽기 전용 WorkgroupShape

The three workgroup extents of a compute stage, present when y or z is not 1. An absent shape is [workgroupSize, 1, 1]; read it through workgroupShapeOf.

portable선택 사항읽기 전용 boolean

Marks a compute entry as a portable kernel. Set by fn()’s opts.portable, which rejects it on any other stage with SD0110. A portable kernel emits on both backends: as a native @compute entry on WGSL, and through the lowerComputeToFragment rewrite on GLSL ES 3.00, which runs it as a fragment shader. The kernel must keep to the gather-only shape, where each invocation reads freely and stores exactly once to its own index of the output; any construct outside that shape fails validation with SD0111 on every emit, on both backends.

Structured only, with no attrs spelling: portable is not a WGSL attribute, so declaring it changes nothing in the emitted source.

kernel선택 사항읽기 전용 boolean

Marks a kernel function (Rule 8.22): an exported function, not an entry, that takes an array with no size. It runs on the host’s side of the call, which dispatches its loops, so the WGSL and GLSL backends leave it out of what they emit, and no function calls it (Rule 8.6). Its array parameters are the caller’s storage, passed by reference (Rule 8.23).

Structured only, with no attrs spelling: it is not a WGSL attribute.

retAttr선택 사항읽기 전용 string

Return-value attribute for a bare (non-struct) stage output, e.g. a fragment -> @location(0) vec4<f32>.

retBuiltin선택 사항읽기 전용 string

Structured builtin id when retAttr came from a builtin(name, type) FieldSpec. The spelling stays in retAttr; the id lives here so a backend can check it against its builtin vocabulary without re-parsing the attribute string.

opaque선택 사항읽기 전용 boolean

Keep this function’s body out of its call sites: the emit optimizer never inlines a call to it. fp64Lower sets it on every double-float helper it injects, because those bodies are error-free transformations that are algebraically trivial (e = b - (s - a) is 0 in real arithmetic), and flattening them hands the terms to passes and drivers that may legally cancel them.

It is a property of the declaration, so it survives every rename a production emit applies to the function’s name.

Structured only, with no attrs spelling (like portable above): it is not a WGSL attribute and changes nothing in the emitted source.

span선택 사항읽기 전용 SourceSpan

Where this function was declared in its authored "use typeshade" source: the whole declaration, from the first decorator or the export keyword through the closing brace. Absent on an EDSL-authored or pass-synthesised function. Read it with sourceSpanOf.

nameSpan선택 사항읽기 전용 SourceSpan

The span of just this function’s name in its authored source, so a stack frame can highlight the identifier rather than the whole body. Absent whenever span is.

allowEarlyReturn선택 사항읽기 전용 boolean

Documented deviation from the single-exit lint rule: when true, the rule skips this function because it has an intentional early return, such as a guard that skips an expensive loop. Use sparingly, with a comment stating why.

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

Documented lint deviations: rule ids whose diagnostics are suppressed for this function (the general form of allowEarlyReturn). Use sparingly, with a comment stating why.

함께 보기

소스

src/core/ir/nodes.ts, 588행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고