ShaderType
이 페이지에서

ShaderType

타입, 타입 분류

The runtime type descriptor for every value the DSL can represent: a plain, comparable discriminated union, so a switch (t.kind) over it is exhaustively checked by tsc at every site that must decide what to do with a shape (typeKey, wgslLayout, both backends' emit walkers).

import type { ShaderType } from 'typeshade'

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

구문

type ShaderType =
| { readonly kind: 'scalar'; readonly scalar: Scalar }
| { readonly kind: 'f64' }
| { readonly kind: 'vec64'; readonly n: 2 | 3 | 4 }
| { readonly kind: 'vec'; readonly n: 2 | 3 | 4; readonly elem: 'f32' | 'i32' | 'u32' | 'bool' }
| {
readonly kind: 'mat';
readonly cols: 2 | 3 | 4;
readonly rows: 2 | 3 | 4;
readonly elem: 'f32' | 'f64';
}
| { readonly kind: 'struct'; readonly name: string }
| { readonly kind: 'array'; readonly elem: ShaderType; readonly size?: number }
| { readonly kind: 'atomic'; readonly elem: 'u32' | 'i32' }
| {
readonly kind: 'texture';
readonly dim: '2d' | '2d-array' | 'cube' | '3d' | '1d' | 'cube-array' | '2d-ms';
readonly elem: TextureElem;
}
| {
readonly kind: 'storage-texture';
readonly dim: '2d' | '2d-array';
readonly format: StorageTextureFormat;
readonly access: StorageTextureAccess;
}
| {
readonly kind: 'depth-texture';
readonly dim: '2d' | '2d-array' | 'cube' | 'cube-array' | '2d-ms';
}
| { readonly kind: 'sampler' }
| { readonly kind: 'sampler-comparison' }
| { readonly kind: 'void' };

설명

Do not build one as an object literal. Use the named constants (f32T, vec3fT, …) or the structT and arrayT constructors, which keep the as const satisfies ShaderType narrowing that KeyOf depends on to resolve a precise string key instead of string. typeKey turns any ShaderType into that same key at runtime; KeyOf<T> is its type-level mirror, which lets Node carry the key as a compile-time phantom so a type mismatch is a tsc error instead of an SD0002 thrown when the authoring code runs.

함께 보기

소스

src/core/ir/types.ts, 201행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고