ShaderType
타입, 타입 분류
DSL이 나타낼 수 있는 모든 값의 런타임 타입 기술자입니다. 단순한 데이터로 표현한 비교 가능한 판별 유니온(discriminated union)입니다. 그래서 이것을 switch (t.kind)로 나누면, 형태를 어떻게 처리할지 정해야 하는 모든 위치(typeKey, wgslLayout, 두 백엔드의 생성 순회 함수)에서 tsc가 빠짐없이 검사합니다.
import type { ShaderType } from 'typeshade'import type { ShaderType } from 'typeshade/core/ir'
설명은 커밋 af54ddad5의 검토된 컴파일러 문서를 번역한 것입니다. 시그니처와 예제 코드는 원문을 따르며, 필요한 경우 설명에 편집상 수정이 반영됩니다.
구문
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; /** Pipeline override used as this array's symbolic outer extent. `size` remains the * positive default extent for reflection and the CPU oracle. */ readonly sizeOverride?: string; } | { 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: 'collection'; readonly key: 'u32' | 'i32' | 'f32'; readonly value?: ShaderType; } | { readonly kind: 'void' };설명
객체 리터럴로 직접 만들지 않습니다. 이름이 붙은 상수(f32T, vec3fT, …)나 structT와 arrayT 생성자를 사용합니다. 이들은 KeyOf가 기대는 as const satisfies ShaderType 좁히기를 유지하며, 그 덕분에 string이 아닌 정확한 문자열 키를 얻습니다. typeKey는 어떤 ShaderType이든 런타임에 같은 키로 바꿉니다. KeyOf<T>는 이것의 타입 수준 짝입니다. 이 덕분에 Node는 키를 컴파일 시점의 팬텀 값으로 지니므로, 타입이 맞지 않으면 작성 코드를 실행할 때 SD0002가 던져지는 대신 tsc 오류가 됩니다.
함께 보기
소스
src/core/ir/types/shader-type.ts, 27행, 커밋 af54ddad5 기준