CompileResult
이 페이지에서

CompileResult

인터페이스, 작성 분류

What compile() returns.

import type { CompileResult } from 'typeshade'

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

구문

interface CompileResult {
readonly diagnostics: readonly TsCompilerDiagnostic[];
readonly module: ModuleDecl;
readonly wgsl?: string;
readonly glsl?: { readonly vertex: string; readonly fragment: string };
readonly determinism: readonly DeterminismEntry[];
readonly eval: (name: string, args?: readonly unknown[]) => unknown;
readonly console?: ConsoleLog;
}

설명

The one rule behind every optional field: shader text and a runnable oracle exist only for a program that compiled with no error diagnostic. A caller that reads wgsl without checking diagnostics gets undefined, never text for a program that did not compile.

인스턴스 속성

diagnostics읽기 전용 readonly TsCompilerDiagnostic[]

Every diagnostic the front end and the backends produced, in the order they were found. A "use typeshade"-less file has exactly one, TS8001 (MISSING_DIRECTIVE); a parse error has only TS8030 (SYNTAX) entries; a backend that threw on a program the front end accepted adds one TS8015 (BACKEND) entry anchored on the file’s first statement: an error when the WGSL emitter threw, a warning when only the GLSL emitter threw on a vertex+fragment module (a compute entry next to the render pair, a storage binding the GLSL emulation cannot spell). A program with no error entry compiled.

module읽기 전용 ModuleDecl

The lowered IR module: the consts, structs, bindings and functions the front end built. Always present. When diagnostics has an error the module is partial (the front end stops lowering a declaration at its first error and may drop it), so it is for inspection and diagnostics tooling, not for emitting.

wgsl선택 사항읽기 전용 string

The module’s WGSL. undefined when any diagnostic has category error, including a BACKEND error from a WGSL emitter that threw. Present otherwise, even for a module with no functions (a file of consts or structs emits their declarations), and kept when only the GLSL emitter failed: the WGSL is the program, GLSL a second target of it.

glsl선택 사항읽기 전용 { readonly vertex: string; readonly fragment: string }

The module’s GLSL ES 3.00 vertex and fragment programs. Present when no diagnostic has category error and the GLSL emitter took the module; a module with only one render stage still gets both programs (the missing stage is a header-only program). A module the GLSL backend refuses gets undefined here while wgsl is still present: silently for a compute-only module, which GLSL ES 3.00 has no stage for, and with the throw recorded as a BACKEND warning for a module with a @vertex or @fragment entry.

determinism읽기 전용 readonly DeterminismEntry[]

The operations in module whose result may differ by driver: a builtin WGSL §15.7.4 gives a ULP or absolute bound (sin, exp, atan2, /), one inherited from a formula the driver may reassociate or fuse (pow, mix, fma, fract, the matrix products), a derivative, a filtered texture read or gather, an operation the GLSL ES 3.00 spelling may answer differently (ldexp, the pack builtins), and every emulated f64 arithmetic operator and bounded builtin, each with the spec’s bound in words, its count and where it occurs. Empty when every operation has one answer, so a GPU result and the CPU oracle can differ only by the oracle’s own rounding. Computed on the front end’s IR even when diagnostics has an error, since a partial module still says what it uses. See determinismReport.

eval읽기 전용 (name: string, args?: readonly unknown[]) => unknown

Run one function of the module on the CPU oracle: eval('fs') calls the fragment entry with no arguments, eval('add', [1, 2]) a helper with two. When diagnostics has an error, every call throws an Error naming the first error diagnostic (file, line and message), so a host that ignores diagnostics cannot run a broken shader on the oracle. It also throws for a function name the module does not have.

console선택 사항읽기 전용 ConsoleLog

Where the WGSL records its console calls and what each entry of the buffer means, under console: 'gpu': the slot of the _console storage buffer and the site table decodeConsole reads. undefined when the option is 'cpu', when the module did not compile, or when no call is recorded. Surface §66.

함께 보기

소스

src/compiler/ts/compile.ts, 20행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고