IoStruct
인터페이스, 레이아웃 분류
The handle ioStruct returns: a struct that crosses a stage boundary, whose fields carry @builtin or @location attributes.
import type { IoStruct } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface IoStruct<F extends Record<string, FieldSpec>, N extends string = string> { readonly decl: StructDecl; readonly type: { readonly kind: 'struct'; readonly name: N }; of(node: Node): { readonly [K in keyof F]-?: Node<KeyOf<NonNullable<F[K]>['type']>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }; of(node: ReadonlyNode): { readonly [K in keyof F]-?: ReadonlyNode<KeyOf<NonNullable<F[K]>['type']>>; } & { readonly $: ReadonlyNode<`struct:${N}`>; }; var(name?: string): { readonly [K in keyof F]-?: Node<KeyOf<NonNullable<F[K]>['type']>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }; construct(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<NonNullable<F[K]>['type']>>; }): Node<`struct:${N}`>;}설명
The handle ioStruct returns: a struct that crosses a stage boundary (a vertex
output, a fragment input, a compute IO record), whose fields carry @builtin or
@location attributes. It bundles the StructDecl for module({ structs }), the struct’s
ShaderType, a typed field-read proxy for any node of this shape, and a one-expression
constructor. Use PlainStruct for a struct that never crosses a stage boundary (a
storage-buffer element, a nested struct); its fields carry no attribute, which is the only
difference between the two.
인스턴스 속성
decl읽기 전용StructDeclThe struct declaration, for
module({ structs }).type읽기 전용{ readonly kind: 'struct'; readonly name: N }The struct’s
ShaderType, carrying the name as a literal so every value built from this handle has the exactstruct:${N}keytypeKeyproduces.
인스턴스 메서드
of(node: Node): { readonly [K in keyof F]-?: Node<KeyOf<NonNullable<F[K]>['type']>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }Typed field access on a value of this struct:
VsOut.of(node).uvis the same member read asmember(node, 'uv', <its type>), with the field name and type checked. The view’s write capability follows the base: a mutable base (aVar) givesNodefields, which accept.assign(...); a read-only base (a parameter, aLet) givesReadonlyNodefields..$is the raw struct value. A field spread in conditionally (...(cond ? { pick } : {})) is typed as present, so optional output fields stay plain.of(node: ReadonlyNode): { readonly [K in keyof F]-?: ReadonlyNode<KeyOf<NonNullable<F[K]>['type']>>; } & { readonly $: ReadonlyNode<`struct:${N}`>; }var(name?: string): { readonly [K in keyof F]-?: Node<KeyOf<NonNullable<F[K]>['type']>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }Declare a
varof this struct and return its typed field proxy in one step:const o = VsOut.var(). Assign fields witho.uv.assign(...)and return or forward the raw value witho.$.namepins the emitted WGSL identifier.construct(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<NonNullable<F[K]>['type']>>; }): Node<`struct:${N}`>Build a value of this struct in one expression, keyed by field name. Values are placed in field-declaration order, and a missing or wrong field is a
tscerror.
함께 보기
소스
src/core/sot.ts, 338행, 커밋 c66579bf 기준