UNPKG

typegpu

Version:

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

57 lines (56 loc) 3.33 kB
import type { AnyVertexInputBuiltin, AnyVertexOutputBuiltin, OmitBuiltins } from '../../builtin.ts'; import type { UndecorateRecord } from '../../data/dataTypes.ts'; import type { BaseData, Decorated, Interpolate, Location } from '../../data/wgslTypes.ts'; import { type TgpuNamable } from '../../shared/meta.ts'; import { $internal } from '../../shared/symbols.ts'; import type { Prettify } from '../../shared/utilityTypes.ts'; import type { _AutoVertexIn, AnyAutoCustoms, AutoVertexOut } from './autoIO.ts'; import type { BaseIOData, InferIO, IORecord } from './fnTypes.ts'; import { type IOLayoutToSchema } from './ioSchema.ts'; type VertexInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, Location[]> | AnyVertexInputBuiltin>; type VertexOutConstrained = IORecord<BaseIOData | Decorated<BaseIOData, (Location | Interpolate)[]> | AnyVertexOutputBuiltin>; /** * Describes a vertex entry function signature (its arguments, return type and attributes) */ type TgpuVertexFnShellHeader<VertexIn extends TgpuVertexFn.In, VertexOut extends TgpuVertexFn.Out> = { readonly in: VertexIn | undefined; readonly out: VertexOut; readonly argTypes: [IOLayoutToSchema<VertexIn>] | []; readonly entryPoint: 'vertex'; }; type CleanIO<T> = T extends Record<string, BaseData> ? Prettify<UndecorateRecord<OmitBuiltins<T>>> : Prettify<UndecorateRecord<OmitBuiltins<{ a: T; }>>> extends { a: infer Result; } ? Result : never; /** * Describes a vertex entry function signature (its arguments, return type and attributes). * Allows creating tgpu vertex functions by calling this shell * and passing the implementation (as WGSL string or JS function) as the argument. */ export interface TgpuVertexFnShell<out TIn extends TgpuVertexFn.In, out TOut extends TgpuVertexFn.Out> extends TgpuVertexFnShellHeader<TIn, TOut> { (implementation: (input: InferIO<TIn>, out: IOLayoutToSchema<TOut>) => InferIO<TOut>): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>; (implementation: string): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>; (strings: TemplateStringsArray, ...values: unknown[]): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>; } export interface TgpuVertexFn<in VertexIn extends TgpuVertexFn.In = Record<string, never>, out VertexOut extends TgpuVertexFn.Out = TgpuVertexFn.Out> extends TgpuNamable { readonly [$internal]: true; readonly shell: TgpuVertexFnShellHeader<VertexIn, VertexOut>; $uses(dependencyMap: Record<string, unknown>): this; } export declare namespace TgpuVertexFn { type In = BaseData | Record<string, BaseData>; type Out = Record<string, BaseData>; type AutoIn<T> = _AutoVertexIn<T>; type AutoOut<T extends AnyAutoCustoms = AnyAutoCustoms> = AutoVertexOut<T>; type AutoInEmpty = _AutoVertexIn<Record<string, never>>; } export declare function vertexFn<VertexOut extends VertexOutConstrained>(options: { out: VertexOut; }): TgpuVertexFnShell<{}, VertexOut>; export declare function vertexFn<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(options: { in: VertexIn; out: VertexOut; }): TgpuVertexFnShell<VertexIn, VertexOut>; export declare function isTgpuVertexFn<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(value: unknown): value is TgpuVertexFn<VertexIn, VertexOut>; export {};