UNPKG

typegpu

Version:

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

48 lines (47 loc) 2.22 kB
import type { AnyComputeBuiltin } from '../../builtin.ts'; import { Void } from '../../data/wgslTypes.ts'; import { type TgpuNamable } from '../../shared/meta.ts'; import { $internal } from '../../shared/symbols.ts'; import type { InferIO, IORecord } from './fnTypes.ts'; /** * Describes a compute entry function signature (its arguments, return type and workgroup size) */ type TgpuComputeFnShellHeader<ComputeIn extends IORecord<AnyComputeBuiltin>> = { readonly argTypes: ComputeIn[keyof ComputeIn][]; readonly returnType: Void; readonly workgroupSize: number[]; readonly entryPoint: 'compute'; }; /** * Describes a compute entry function signature (its arguments, return type and workgroup size). * Allows creating tgpu compute functions by calling this shell * and passing the implementation (as WGSL string or JS function) as the argument. */ export type TgpuComputeFnShell<ComputeIn extends IORecord<AnyComputeBuiltin>> = TgpuComputeFnShellHeader<ComputeIn> & /** * Creates a type-safe implementation of this signature */ ((implementation: (input: InferIO<ComputeIn>) => undefined) => TgpuComputeFn<ComputeIn>) & /** * @param implementation * Raw WGSL function implementation with header and body * without `fn` keyword and function name * e.g. `"(x: f32) -> f32 { return x; }"`; */ ((implementation: string) => TgpuComputeFn<ComputeIn>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuComputeFn<ComputeIn>); export interface TgpuComputeFn<ComputeIn extends IORecord<AnyComputeBuiltin> = any> extends TgpuNamable { readonly [$internal]: true; readonly shell: TgpuComputeFnShellHeader<ComputeIn>; $uses(dependencyMap: Record<string, unknown>): this; } export interface ComputeFnOptions { workgroupSize: number[]; } export declare function computeFn(options: { workgroupSize: number[]; }): TgpuComputeFnShell<{}>; export declare function computeFn<ComputeIn extends IORecord<AnyComputeBuiltin>>(options: { in: ComputeIn; workgroupSize: number[]; }): TgpuComputeFnShell<ComputeIn>; export declare function isTgpuComputeFn<ComputeIn extends IORecord<AnyComputeBuiltin>>(value: unknown): value is TgpuComputeFn<ComputeIn>; export {};