typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
31 lines (30 loc) • 1.63 kB
TypeScript
import { type AnyData } from '../../data/dataTypes.ts';
import { type AnyWgslData, type BaseData, type WgslArray } from '../../data/wgslTypes.ts';
import type { TgpuNamable } from '../../shared/meta.ts';
import type { InferGPU } from '../../shared/repr.ts';
import type { TgpuSoul } from '../../shared/soul.ts';
import { $gpuValueOf, $internal, $soul } from '../../shared/symbols.ts';
export type DeepReadonly<T> = T extends {
[$internal]: unknown;
} ? T : T extends unknown[] ? ReadonlyArray<DeepReadonly<T[number]>> : T extends Record<string, unknown> ? {
readonly [K in keyof T]: DeepReadonly<T[K]>;
} : T;
export interface TgpuConstSoul<TDataType extends BaseData = BaseData> extends TgpuSoul<'const'> {
readonly dataType: TDataType;
readonly value: DeepReadonly<InferGPU<TDataType>>;
}
export interface TgpuConst<TDataType extends BaseData = BaseData> extends TgpuNamable {
readonly resourceType: 'const';
readonly [$gpuValueOf]: DeepReadonly<InferGPU<TDataType>>;
readonly $: DeepReadonly<InferGPU<TDataType>>;
readonly [$soul]: TgpuConstSoul<TDataType>;
readonly [$internal]: {
/** Makes it differentiable on the type level. Does not exist at runtime. */
dataType?: TDataType;
};
}
/**
* Creates a module constant with specified value.
*/
export declare function constant<TDataType extends AnyData>(dataType: TDataType, value: InferGPU<TDataType>): TgpuConst<TDataType>;
export declare function constant<TElement extends AnyWgslData>(dataType: (elementCount: number) => WgslArray<TElement>, value: InferGPU<WgslArray<TElement>>): TgpuConst<WgslArray<TElement>>;