StructField
이 페이지에서

StructField

인터페이스, 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'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

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;
}

설명

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.

인스턴스 속성

name읽기 전용 string
type읽기 전용 ShaderType
attr선택 사항읽기 전용 string

Optional 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.

location선택 사항읽기 전용 number

Structured @location(n). Set by location.

builtin선택 사항읽기 전용 string

Structured @builtin(name). Set by builtin.

interpolate선택 사항읽기 전용 string

Structured @interpolate(mode) (set alongside location).

blendSrc선택 사항읽기 전용 number

Structured @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 the dualSourceBlending capability, and GLSL ES 3.00 has no second source, so a module carrying one fails closed there.

size선택 사항읽기 전용 number

The 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 — @size on a field is still refused at the front end, because reflect’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).

align선택 사항읽기 전용 number

The byte alignment WGSL’s @align(n) gives this field. Set by the uniform-layout pass (§51) and by nothing else, for the same reason size is, 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 offset reflect() 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 with uniform_buffer_standard_layout accepts the same text while laying it out differently from what reflection reports.

함께 보기

소스

src/core/ir/nodes.ts, 442행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고