wgslLayout()
함수, 리플렉션 분류
Compute the byte layout of one struct under a LayoutKind: each field's offset, alignment and size, plus the struct's total size and alignment.
import { wgslLayout } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function wgslLayout( struct: StructDecl, layout: LayoutKind, structs: ReadonlyMap<string, StructDecl> = new Map(),): StructLayout매개변수
structStructDeclthe struct to lay out.
layoutLayoutKind'std140'for a uniform buffer,'std430'for a storage buffer.structs선택 사항ReadonlyMap<string, StructDecl>the structs a nested struct-typed field may refer to, by name. Defaults to a map holding only
structitself.
반환값
the StructLayout.
예외
Errorif a field’s type has no byte layout (a texture or a sampler), if a nested struct is not in
structs, or if amat2field is laid out under'std140'(seeLayoutKind).
설명
Under 'std140' the
struct’s and every nested array’s base alignment rounds up to 16; under 'std430' natural
alignment applies.
예제
예제
import { wgslLayout, vec3fT, f32T } from 'typeshade'
const light = { name: 'Light', fields: [{ name: 'pos', type: vec3fT }, { name: 'radius', type: f32T }] }wgslLayout(light, 'std140')// { name: 'Light', size: 16, align: 16, fields: [// { name: 'pos', type: 'vec3<f32>', offset: 0, align: 16, size: 12 },// { name: 'radius', type: 'f32', offset: 12, align: 4, size: 4 } ] }관련 가이드
함께 보기
소스
src/core/reflect.ts, 276행, 커밋 c66579bf 기준