UNPKG

typegpu

Version:

A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.

34 lines (33 loc) 1.16 kB
import {} from "../../data/snippet.js"; import { $internal, $repr } from "../../shared/symbols.js"; import { isWgslStruct } from "../../data/wgslTypes.js"; /** * Routes `(input) => { input.x }` style property access to the correct WGSL * expression: positional args get a direct snippet, struct fields get * `structArgName.fieldName`. */ export class EntryInputRouter { [$internal] = {}; type = 'entry-input-router'; structArg; /** Maps schemaKey → { WGSL arg name, type } */ positionalArgsMap; constructor(structArg, positionalArgs) { this.structArg = structArg; this.positionalArgsMap = new Map(positionalArgs.map((a) => [a.schemaKey, a.arg])); } toString() { return 'entry-input-router'; } accessProp(propName) { const positionalEntry = this.positionalArgsMap.get(propName); if (positionalEntry) { return positionalEntry(); } const structSnippet = this.structArg?.(); if (structSnippet && isWgslStruct(structSnippet.dataType)) { return { target: structSnippet, prop: propName }; } return undefined; } }