StructField
Interface in IR
One field of a StructDecl: a plain data member of a uniform or storage struct, or, in a vertex/fragment I/O struct, a member carrying a @builtin or @location attribute.
import type { StructField } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
interface StructField { readonly name: string; readonly type: ShaderType; readonly attr?: string; readonly location?: number; readonly builtin?: string; readonly interpolate?: string; readonly blendSrc?: number; readonly size?: number; readonly align?: number;}Description
Build these with builtin and location, which fill both
attr and the structured builtin/location fields. The GLSL backend ignores attr
and reads location/builtin directly: GLSL ES 3.00 has no struct-field attribute
syntax, so an I/O struct is flattened into individual in/out globals keyed off
those fields.
Instance properties
nameread onlystringtyperead onlyShaderTypeattroptionalread onlystringOptional WGSL field attribute(s) for I/O structs, e.g.
@builtin(position),@location(0),@location(0) @interpolate(flat). This is the emitted spelling; the structured fields below (location,builtin,interpolate) are what the backends read. They never re-parse this string.locationoptionalread onlynumberStructured
@location(n). Set bylocation.builtinoptionalread onlystringStructured
@builtin(name). Set bybuiltin.interpolateoptionalread onlystringStructured
@interpolate(mode)(set alongsidelocation).blendSrcoptionalread onlynumberStructured
@blend_src(0|1)on a fragment output (§53): the two colours a dual-source blend mixes, which both sit at@location(0). It derives thedualSourceBlendingcapability, and GLSL ES 3.00 has no second source, so a module carrying one fails closed there.sizeoptionalread onlynumberThe byte size WGSL’s
@size(n)gives this field, when the field’s own type is smaller. Set by the uniform-layout pass (§51) and by nothing else: it is how the wrapper struct that gives a uniform array its 16-byte element stride is spelled,struct _Pad16_f32 { @size(16) v: f32, }. It is not an author attribute —@sizeon a field is still refused at the front end, becausereflect’s layout engine does not read this, and an attribute the emit honoured while reflection ignored it is the very emit-versus-reflection disagreement §51 exists to close. The WGSL writer emits it; GLSL ES 3.00 has no equivalent, and no module reaches that writer carrying one (the pass runs on the WGSL side alone).alignoptionalread onlynumberThe byte alignment WGSL’s
@align(n)gives this field. Set by the uniform-layout pass (§51) and by nothing else, for the same reasonsizeis, and it is the other half of the same fix:@size(16)on a wrapper’s field gives the array element its 16-byte stride, and@align(16)on the member holding that array gives the array its 16-byte offset. With the stride fixed but the member unaligned the array lands at offset 4, which is the offsetreflect()does not report; Chromium 141 states it outright (the offset of a struct member of type 'array<_Pad16_f32, 3>' in address space 'uniform' must be a multiple of 16 bytes, but 'xs' is currently at offset 4), and an implementation withuniform_buffer_standard_layoutaccepts the same text while laying it out differently from what reflection reports.
See also
Source
src/core/ir/nodes.ts, line 442, at commit 26de7be8