UNPKG

typegpu

Version:

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

31 lines (30 loc) 877 B
import { dualImpl } from "../core/function/dualImpl.js"; import { stitch } from "../core/resolve/stitch.js"; import { isMatInstance, isVecInstance, WORKAROUND_getSchema } from "../data/wgslTypes.js"; export function cpuCopy(e) { if (isVecInstance(e) || isMatInstance(e)) { const schema = WORKAROUND_getSchema(e); return schema(e); } if (Array.isArray(e)) { return e.map(cpuCopy); } if (typeof e === 'object' && e !== null) { return Object.fromEntries(Object.entries(e).map(([key, value]) => [key, cpuCopy(value)])); } return e; } export const copy = dualImpl({ name: 'copy', signature: (arg) => { return { argTypes: [arg], returnType: arg, }; }, normalImpl: cpuCopy, codegenImpl(_ctx, [a]) { return stitch `${a}`; }, sideEffects: false, });