typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
19 lines (18 loc) • 786 B
JavaScript
import { stitch } from "../core/resolve/stitch.js";
import { isUnstruct, undecorate } from "../data/dataTypes.js";
import { snip } from "../data/snippet.js";
import { isWgslStruct } from "../data/wgslTypes.js";
import { invariant } from "../errors.js";
/**
* This function is separate from `accessProp` to avoid a circular dependency.
*/
export function accessStructProp(target, propName) {
invariant(isWgslStruct(target.dataType) || isUnstruct(target.dataType), 'Expected snippet type to be struct/unstruct.');
let propType = target.dataType.propTypes[propName];
if (!propType) {
return undefined;
}
propType = undecorate(propType);
return snip(stitch `${target}.${propName}`, propType,
/* origin */ target.origin, target.possibleSideEffects);
}