structDecl()
함수, 레이아웃 분류
Declare a plain struct: one that never crosses a stage boundary.
import { structDecl } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function structDecl<F extends Record<string, ShaderType>, N extends string>( name: N, fields: F,): PlainStruct<F, N>매개변수
nameN extends stringthe emitted struct name.
fieldsF extends Record<string, ShaderType>the field map, each value a plain shader type.
반환값
PlainStruct<F, N>
the PlainStruct handle described above.
설명
Declare a plain struct: one that never crosses a stage boundary. That is a storage-buffer
element type, or a struct nested inside another struct. Fields are plain shader types with
no @location or @builtin attribute, which is the whole difference from
ioStruct.
The returned handle carries:
.declformodule({ structs }), or pass the handle inuses..typefor the struct’s shader type, which is what a parameter, a nested field or astorageBufferelement takes..of(node).fieldfor typed field reads off a value you hold as a raw node, and.get(node, 'field')for the positional spelling of the same read, which suits a call site that reads many fields through one shorthand..var(name)for a mutablevarof the struct, and.construct({ ... })for the one-expression build, exactly asioStructhas them.
As a storage-buffer element type it is the argument storageBuffer takes, and
buf.at(i) then returns this struct’s field proxy directly, with no .of step.
예제
예제
import { structDecl, storageBuffer, u32T, vec2fT } from 'typeshade'
const ShapeSegment = structDecl('ShapeSegment', { kind: u32T, p0: vec2fT, p1: vec2fT })const segments = storageBuffer('segments', ShapeSegment, { group: 0, binding: 9, access: 'read' })
segments.at(i).p0 // Node<'vec2<f32>'>ShapeSegment.get(someNode, 'kind') // the same read, positionally관련 가이드
함께 보기
소스
src/core/sot.ts, 552행, 커밋 c66579bf 기준