wgslLayout
이 페이지에서

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

매개변수

struct StructDecl

the struct to lay out.

layout LayoutKind

'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 struct itself.

반환값

StructLayout

the StructLayout.

예외

Error

if a field’s type has no byte layout (a texture or a sampler), if a nested struct is not in structs, or if a mat2 field is laid out under 'std140' (see LayoutKind).

설명

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 기준

이 페이지 편집 문제 보고