UNPKG

typegpu

Version:

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

38 lines (37 loc) 1.31 kB
import { type TgpuNamable } from '../../shared/meta.ts'; import { $getNameForward, $internal } from '../../shared/symbols.ts'; import { type DualFn } from '../../types.ts'; type AnyFn = (...args: never[]) => unknown; export type TgpuComptime<T extends AnyFn = AnyFn> = DualFn<T> & TgpuNamable & { [$getNameForward]: unknown; [$internal]: { isComptime: true; }; }; export declare function isComptimeFn(value: unknown): value is TgpuComptime; /** * Creates a version of `func` that can called safely in a TypeGPU function to * precompute and inject a value into the final shader code. * * Note how the function passed into `comptime` doesn't have to be marked with * 'use gpu'. That's because the function doesn't execute on the GPU, it gets * executed before the shader code gets sent to the GPU. * * @example * ```ts * const color = tgpu.comptime((int: number) => { * const r = (int >> 16) & 0xff; * const g = (int >> 8) & 0xff; * const b = int & 0xff; * return d.vec3f(r / 255, g / 255, b / 255); * }); * * const material = (diffuse: d.v3f): d.v3f => { * 'use gpu'; * const albedo = color(0xff00ff); * return albedo.mul(diffuse); * }; * ``` */ export declare function comptime<T extends (...args: never[]) => unknown>(func: T): TgpuComptime<T>; export {};