ShaderType
On this page

ShaderType

Type in Types

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'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

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

Description

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.

See also

Source

src/core/ir/types.ts, line 201, at commit 26de7be8

Edit this page Report a problem