typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
36 lines (35 loc) • 1.94 kB
TypeScript
import { type TgpuComptime } from '../core/function/comptime.ts';
import type { AnyWgslData, Decorated, Location, WgslArray } from './wgslTypes.ts';
type ForbiddenDecoratedArrayElement<T> = T extends Decorated<infer _, infer Attribs> ? Attribs[number] extends Location ? never : T : never;
interface WgslArrayConstructor {
/**
* @deprecated Error: Arrays cannot hold decorated types other than @location.
* Wrap align/size in a struct instead, e.g. d.arrayOf(d.struct({ value: d.align(16, d.u32) }), n).
*/
<TElement extends AnyWgslData>(elementType: ForbiddenDecoratedArrayElement<TElement>, elementCount?: number): 'Error: Arrays cannot hold decorated types other than @location. Wrap it in a struct instead, e.g. d.arrayOf(d.struct({ value: d.align(16, d.u32) }), n).';
<TElement extends AnyWgslData>(elementType: TElement): (elementCount: number) => WgslArray<TElement>;
<TElement extends AnyWgslData>(elementType: TElement, elementCount: number): WgslArray<TElement>;
}
/**
* Creates an array schema that can be used to construct gpu buffers.
* Describes arrays with fixed-size length, storing elements of the same type.
*
* The only decoration allowed on element types is `d.location`. Decorators like
* `d.align` and `d.size` cannot be applied directly — wrap them in a struct instead,
* e.g. `d.arrayOf(d.struct({ value: d.align(16, d.u32) }), n)`.
*
* @example
* const LENGTH = 3;
* const array = d.arrayOf(d.u32, LENGTH);
*
* If `elementCount` is not specified, a partially applied function is returned.
* @example
* const array = d.arrayOf(d.vec3f);
* // ^? (n: number) => WgslArray<d.Vec3f>
*
* @param elementType The type of elements in the array.
* @param elementCount The number of elements in the array.
* @throws If `elementType` is decorated with anything other than `d.location`.
*/
export declare const arrayOf: TgpuComptime<WgslArrayConstructor>;
export {};