PlainStruct
인터페이스, 레이아웃 분류
The handle structDecl returns: a struct declared for something other than a stage's IO boundary, such as a storage-buffer element type (paired with storageBuffer) or a struct nested inside another struct.
import type { PlainStruct } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface PlainStruct<F extends Record<string, ShaderType>, 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<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }; of(node: ReadonlyNode): { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }; get<K extends keyof F & string>(node: ReadonlyNode, field: K): ReadonlyNode<KeyOf<F[K]>>; var(name?: string): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }; construct(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> }): Node<`struct:${N}`>;}설명
Fields are plain
ShaderTypes with no @location or @builtin attribute; IoStruct is the twin
that carries those. It has the same shape as IoStruct (.decl, .type, .of, .var,
.construct) plus a positional .get(node, field) reader.
인스턴스 속성
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<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }Typed field access on a struct value you hold as a raw node:
Seg.of(someNode).p0. A storage-buffer element does not need it, becausebuf.at(i)already returns this proxy. The view’s write capability follows the base: a mutable base givesNodefields, a read-only base givesReadonlyNodefields..$is the raw struct value, which can be passed on to a function that takes the struct.of(node: ReadonlyNode): { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }get<K extends keyof F & string>(node: ReadonlyNode, field: K): ReadonlyNode<KeyOf<F[K]>>Positional field access:
Seg.get(node, 'p0')is the same read asSeg.of(node).p0, with a wrong field name atscerror. It suits a call site that reads many fields through one shorthand (const g = Seg.get). It is a read accessor and returnsReadonlyNode.var(name?: string): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }Declare a
varof this struct and return its typed, mutable field proxy, asIoStruct.vardoes.construct(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> }): Node<`struct:${N}`>Build a value of this struct in one expression, keyed by field name and placed in declaration order, as
IoStruct.constructdoes.
함께 보기
소스
src/core/sot.ts, 481행, 커밋 c66579bf 기준