typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
40 lines (39 loc) • 1.98 kB
TypeScript
import type { AnyData } from '../../data/dataTypes.ts';
import type { BaseData } 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 VariableScope = 'private' | 'workgroup';
export interface TgpuVarSoul<TScope extends VariableScope = VariableScope, TDataType extends BaseData = BaseData> extends TgpuSoul<'var'> {
readonly scope: TScope;
readonly dataType: TDataType;
readonly initialValue: InferGPU<TDataType> | undefined;
}
export interface TgpuVar<TScope extends VariableScope = VariableScope, TDataType extends BaseData = BaseData> extends TgpuNamable {
readonly resourceType: 'var';
readonly [$gpuValueOf]: InferGPU<TDataType>;
$: InferGPU<TDataType>;
readonly [$soul]: TgpuVarSoul<TScope, TDataType>;
readonly [$internal]: {
/** Makes it differentiable on the type level. Does not exist at runtime. */
dataType?: TDataType;
/** Makes it differentiable on the type level. Does not exist at runtime. */
scope?: TScope;
};
}
/**
* Defines a variable scoped to each entry function (private).
*
* @param dataType The schema of the held data's type
* @param initialValue If not provided, the variable will be initialized to the dataType's "zero-value".
*/
export declare function privateVar<TDataType extends AnyData>(dataType: TDataType, initialValue?: InferGPU<TDataType>): TgpuVar<'private', TDataType>;
/**
* Defines a variable scoped to the whole workgroup, shared between entry functions
* of the same invocation.
*
* @param dataType The schema of the held data's type
*/
export declare function workgroupVar<TDataType extends AnyData>(dataType: TDataType): TgpuVar<'workgroup', TDataType>;
export declare function isVariable(value: unknown): value is TgpuVar;