Reflection
인터페이스, 리플렉션 분류
The target-neutral pipeline metadata reflect recovers from a module: bind-group layout, every bound struct's byte layout, the vertex-attribute layout if any (vertex), every entry point's signature (entries), specialization constants (overrides), the capabilities a host must activate before pipeline creation, and the host-provided globals the module expects (requires).
import type { Reflection } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface Reflection { readonly bindGroups: readonly BindGroup[]; readonly uniforms: readonly StructLayout[]; readonly storage: readonly StructLayout[]; readonly vertex?: VertexLayout; readonly entries: readonly EntryInfo[]; readonly overrides: readonly OverrideInfo[]; readonly requiredFeatures: readonly Capability[]; readonly requiredLanguageFeatures: readonly LanguageFeature[]; readonly requires: readonly ExternRequirement[];}설명
Each field’s own doc gives its shape. A host that takes its bind-group
layouts and byte offsets from a reflect() call on the same module it emits shader text
from keeps one table, so a struct field cannot sit at byte 20 in the shader and at byte 24
in the CPU packer.
인스턴스 속성
bindGroups읽기 전용readonly BindGroup[]uniforms읽기 전용readonly StructLayout[]std140 uniform-buffer struct layouts (one per uniform binding whose type is a struct).
storage읽기 전용readonly StructLayout[]std430 storage-buffer struct layouts.
vertex선택 사항읽기 전용VertexLayoutVertex attributes from the first
@vertexentry’s@locationinputs, its loose parameters and the located fields of its struct parameters, tightly packed in the order written: the layoutpackModule()and the manifest carry (Rule 6.8).entries읽기 전용readonly EntryInfo[]overrides읽기 전용readonly OverrideInfo[]Pipeline specialization constants: the names, types and defaults the host passes at pipeline creation (WGSL
constants, or the GLSL#defineheader). Always present; empty for a module that declares no overrides.requiredFeatures읽기 전용readonly Capability[]Every capability this module’s emit requires: the ones derived from the module’s shape (a storage binding needs
storageBuffer, a@computeentry needscompute, a multisampled texture load needsmsaaTextureLoad) plus everything the module declared inenables. Sorted and deduplicated. Always present; empty for a module that needs nothing.This is what a host must have active before it creates a pipeline for the module. The ids are neutral, because reflection takes a module and never a backend, so translate them for one target with
hostFeaturesFor:for (const ext of hostFeaturesFor(glslEs300Backend, reflect(m).requiredFeatures)) {if (!gl.getExtension(ext)) throw new Error(`WebGL2 lacks ${ext}`)}// WebGPU fixes its features at requestDevice, so do this at boot, before any pipeline:// requestDevice({// requiredFeatures: hostFeaturesFor(wgslBackend, reflect(m).requiredFeatures) })A capability the target backend cannot provide at all normally never reaches this loop in a usable pipeline, because emit for that backend already throws
UnsupportedFeatureError(SD0030) naming it. The exception isstorageBufferon GLSL ES 3.00: astoragebinding is emitted as a data texture there, so the module emits fine while reflection of the module as authored still reports the capability.hostFeaturesForskips every capability the backend has no host feature for, so the loop above is correct either way.requiredLanguageFeatures읽기 전용readonly LanguageFeature[]Every WGSL language extension this module needs (§50), sorted and deduplicated. Always present; empty for a module that needs none, which is most.
This is the
requiresaxis of WGSL, not theenableaxisrequiredFeaturesreports: a language extension changes what the WGSL text may say, and it is not requested atrequestDevice— it is either present in the browser’s WGSL implementation or not, so a host checks it againstnavigator.gpu.wgslLanguageFeaturesbefore it builds the module. GLSL ES 3.00 has no such axis, and the resource capability carrying each row is what fails a module closed on that target.Two rows today, and the writer directs only one of them — reporting a feature and writing
requiresfor it are separate decisions, each measured. A storage texture boundreadorread_write(or atextureBarriercall) needsreadonly_and_readwrite_storage_texturesto be a program at all, since core WGSL gives a storage texturewriteonly, and the directive is accepted by the Tint the gate runs, so it is emitted. The packed 4x8 integer family reportspacked_4x8_integer_dot_productand emits nothing: all eight builtins compile bare on the same Tint and the directive “changes nothing”, so writing it could only fail a module closed on a browser that lacks the name.for (const f of reflect(m).requiredLanguageFeatures) {if (!navigator.gpu.wgslLanguageFeatures.has(f)) throw new Error(`no WGSL ${f}`)}requires읽기 전용readonly ExternRequirement[]The host-provided globals this module references but does not declare: one entry per
externVardeclarator, reported so a composer can check them against what the host’s prelude actually supplies. Always present; empty for a module that expects nothing from its host. Host-provided functions (externFn) have no declaration to report here; therequireslist of an emitted fragment (emitFragment) covers those by walking call sites.
함께 보기
소스
src/core/reflect.ts, 597행, 커밋 c66579bf 기준