wgslLayout()
Function in Reflection
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'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function wgslLayout( struct: StructDecl, layout: LayoutKind, structs: ReadonlyMap<string, StructDecl> = new Map(),): StructLayoutParameters
structStructDeclthe struct to lay out.
layoutLayoutKind'std140'for a uniform buffer,'std430'for a storage buffer.structsoptionalReadonlyMap<string, StructDecl>the structs a nested struct-typed field may refer to, by name. Defaults to a map holding only
structitself.
Return value
the StructLayout.
Exceptions
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).
Description
Under 'std140' the
struct’s and every nested array’s base alignment rounds up to 16; under 'std430' natural
alignment applies.
Examples
Example
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 } ] }In the guide
See also
Source
src/core/reflect.ts, line 276, at commit 26de7be8