typegpu 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts","../src/errors.ts","../src/data/vector.ts","../src/callable.ts","../src/data/alignIO.ts","../src/mathUtils.ts"],"names":["isResolvable","value","isGPUBuffer","RecursiveDataTypeError","_RecursiveDataTypeError","Measurer","f32","i32","u32","CallableImpl","__publicField","alignIO","io","baseAlignment","currentPos","bitMask","offset","alignIO_default","VecSchemaImpl","unitType","byteAlignment","length","label","make","makeFromScalar","args","_a","values","ctx","output","element","input","_","_value","measurer","reference","prop","Swizzle2Impl","vec2Impl","x","y","vec2fImpl","_vec2fImpl","vec2iImpl","_vec2iImpl","vec2uImpl","_vec2uImpl","Swizzle3Impl","vec3Impl","z","vec3fImpl","_vec3fImpl","vec3iImpl","_vec3iImpl","vec3uImpl","_vec3uImpl","Swizzle4Impl","vec4Impl","w","vec4fImpl","_vec4fImpl","vec4iImpl","_vec4iImpl","vec4uImpl","_vec4uImpl","vec2f","vec2i","vec2u","vec3f","vec3i","vec3u","vec4f","vec4i","vec4u","roundUp","modulo","invBitMask"],"mappings":"0uBA+CO,SAASA,EAAaC,EAAyC,CACpE,MACE,CAAC,CAACA,IACD,OAAOA,GAAU,UAAY,OAAOA,GAAU,aAC/C,YAAaA,CAEjB,CAkNO,SAASC,EAAYD,EAAoC,CAC9D,MACE,CAAC,CAACA,GACF,OAAOA,GAAU,UACjB,mBAAoBA,GACpB,aAAcA,CAElB,CC7NO,IAAME,EAAN,MAAMC,UAA+B,KAAM,CAChD,aAAc,CACZ,MAAM,2CAA2C,EAGjD,OAAO,eAAe,KAAMA,EAAuB,SAAS,CAC9D,CACF,ECxDA,OAOE,YAAAC,EAEA,OAAAC,EACA,OAAAC,EACA,OAAAC,MACK,eCZA,IAAeC,EAAf,cAGG,QAAS,CAGjB,aAAc,CAUZ,MAAM,UAAW,mCAAmC,EAZtDC,EAAA,eAeE,YAAK,OAAS,KAAK,KAAK,IAAI,EA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,EACR,MAAO,QACP,KAAM,CAACiC,EAAGC,EAAGS,EAAGS,IAAM,IAAIC,EAAUpB,EAAGC,EAAGS,EAAGS,CAAC,EAC9C,eAAiBnB,GAAM,IAAIoB,EAAUpB,EAAGA,EAAGA,EAAGA,CAAC,CACjD,CAAC,EAOYiC,GAAQ,IAAItD,EAAc,CACrC,SAAUX,EACV,cAAe,GACf,OAAQ,EACR,MAAO,QACP,KAAM,CAACgC,EAAGC,EAAGS,EAAGS,IAAM,IAAIG,EAAUtB,EAAGC,EAAGS,EAAGS,CAAC,EAC9C,eAAiBnB,GAAM,IAAIsB,EAAUtB,EAAGA,EAAGA,EAAGA,CAAC,CACjD,CAAC,EAOYkC,GAAQ,IAAIvD,EAAc,CACrC,SAAUV,EACV,cAAe,GACf,OAAQ,EACR,MAAO,QACP,KAAM,CAAC+B,EAAGC,EAAGS,EAAGS,IAAM,IAAIK,EAAUxB,EAAGC,EAAGS,EAAGS,CAAC,EAC9C,eAAiBnB,GAAM,IAAIwB,EAAUxB,EAAGA,EAAGA,EAAGA,CAAC,CACjD,CAAC,EGnhBM,IAAMmC,GAAU,CAACzE,EAAe0E,IAAmB,CACxD,IAAM5D,EAAU4D,EAAS,EACnBC,EAAa,CAAC7D,EACpB,OAAQd,EAAQc,GAA0Bd,EAAQ2E,GAAcD,EAA/B1E,CACnC","sourcesContent":["import type { ISchema, Parsed } from 'typed-binary';\nimport type { F32, I32, U32, Vec4f, Vec4i, Vec4u } from './data';\nimport type { Builtin } from './wgslBuiltin';\nimport type { TgpuIdentifier } from './wgslIdentifier';\nimport type { TgpuPlum } from './wgslPlum';\n\nexport type Wgsl = string | number | TgpuResolvable | symbol | boolean;\n\n/**\n * Passed into each resolvable item. All sibling items share a resolution ctx,\n * and a new resolution ctx is made when going down each level in the tree.\n */\nexport interface ResolutionCtx {\n /**\n * Slots that were used by items resolved by this context.\n */\n readonly usedSlots: Iterable<TgpuSlot<unknown>>;\n\n addDeclaration(item: TgpuResolvable): void;\n addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;\n addRenderResource(\n resource: TgpuRenderResource,\n identifier: TgpuIdentifier,\n ): void;\n addBuiltin(builtin: Builtin): void;\n nameFor(token: TgpuResolvable): string;\n /**\n * Unwraps all layers of slot indirection and returns the concrete value if available.\n * @throws {MissingSlotValueError}\n */\n unwrap<T>(eventual: Eventual<T>): T;\n resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;\n}\n\nexport interface TgpuResolvable {\n readonly label?: string | undefined;\n resolve(ctx: ResolutionCtx): string;\n}\n\n/**\n * Can be assigned a name. Not to be confused with\n * being able to HAVE a name.\n */\nexport interface TgpuNamable {\n $name(label?: string | undefined): this;\n}\n\nexport function isResolvable(value: unknown): value is TgpuResolvable {\n return (\n !!value &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'resolve' in value\n );\n}\n\nexport function isNamable(value: unknown): value is TgpuNamable {\n return (\n !!value &&\n (typeof value === 'object' || typeof value === 'function') &&\n '$name' in value\n );\n}\n\nexport function isWgsl(value: unknown): value is Wgsl {\n return (\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'string' ||\n isResolvable(value)\n );\n}\n\nexport interface TgpuSlot<T> extends TgpuNamable {\n readonly __brand: 'TgpuSlot';\n\n readonly defaultValue: T | undefined;\n\n readonly label?: string | undefined;\n /**\n * Used to determine if code generated using either value `a` or `b` in place\n * of the slot will be equivalent. Defaults to `Object.is`.\n */\n areEqual(a: T, b: T): boolean;\n}\n\nexport function isSlot<T>(value: unknown | TgpuSlot<T>): value is TgpuSlot<T> {\n return (value as TgpuSlot<T>).__brand === 'TgpuSlot';\n}\n\n/**\n * Represents a value that is available at resolution time.\n */\nexport type Eventual<T> = T | TgpuSlot<T>;\n\nexport type EventualGetter = <T>(value: Eventual<T>) => T;\n\nexport type InlineResolve = (get: EventualGetter) => Wgsl;\n\nexport interface TgpuResolvableSlot<T extends Wgsl>\n extends TgpuResolvable,\n TgpuSlot<T> {}\n\nexport type SlotValuePair<T> = [TgpuSlot<T>, T];\n\nexport interface TgpuAllocatable<TData extends AnyTgpuData = AnyTgpuData> {\n /**\n * The data type this allocatable was constructed with.\n * It informs the size and format of data in both JS and\n * binary.\n */\n readonly dataType: TData;\n readonly initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined;\n readonly flags: GPUBufferUsageFlags;\n}\n\nexport function isAllocatable(value: unknown): value is TgpuAllocatable {\n return (\n !!value &&\n typeof value === 'object' &&\n 'dataType' in value &&\n 'flags' in value\n );\n}\n\nexport interface TgpuBindable<\n TData extends AnyTgpuData = AnyTgpuData,\n TUsage extends BufferUsage = BufferUsage,\n> extends TgpuResolvable {\n readonly allocatable: TgpuAllocatable<TData>;\n readonly usage: TUsage;\n}\n\nexport type TgpuSamplerType = 'sampler' | 'sampler_comparison';\nexport type TgpuTypedTextureType =\n | 'texture_1d'\n | 'texture_2d'\n | 'texture_2d_array'\n | 'texture_3d'\n | 'texture_cube'\n | 'texture_cube_array'\n | 'texture_multisampled_2d';\nexport type TgpuDepthTextureType =\n | 'texture_depth_2d'\n | 'texture_depth_2d_array'\n | 'texture_depth_cube'\n | 'texture_depth_cube_array'\n | 'texture_depth_multisampled_2d';\nexport type TgpuStorageTextureType =\n | 'texture_storage_1d'\n | 'texture_storage_2d'\n | 'texture_storage_2d_array'\n | 'texture_storage_3d';\nexport type TgpuExternalTextureType = 'texture_external';\n\nexport type TgpuRenderResourceType =\n | TgpuSamplerType\n | TgpuTypedTextureType\n | TgpuDepthTextureType\n | TgpuStorageTextureType\n | TgpuExternalTextureType;\n\nexport interface TgpuRenderResource extends TgpuResolvable {\n readonly type: TgpuRenderResourceType;\n}\n\nexport type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';\nexport type TextureUsage = 'sampled' | 'storage';\nexport type StorageTextureAccess = 'read' | 'write' | 'read_write';\n\nexport type StorageTextureParams = {\n type: TgpuStorageTextureType;\n access: StorageTextureAccess;\n descriptor?: GPUTextureViewDescriptor;\n};\nexport type SampledTextureParams = {\n type: TgpuTypedTextureType;\n dataType: TextureScalarFormat;\n descriptor?: GPUTextureViewDescriptor;\n};\n\nexport function isSamplerType(\n type: TgpuRenderResourceType,\n): type is TgpuSamplerType {\n return type === 'sampler' || type === 'sampler_comparison';\n}\n\nexport function isTypedTextureType(\n type: TgpuRenderResourceType,\n): type is TgpuTypedTextureType {\n return [\n 'texture_1d',\n 'texture_2d',\n 'texture_2d_array',\n 'texture_3d',\n 'texture_cube',\n 'texture_cube_array',\n 'texture_multisampled_2d',\n ].includes(type);\n}\n\nexport function isDepthTextureType(\n type: TgpuRenderResourceType,\n): type is TgpuDepthTextureType {\n return [\n 'texture_depth_2d',\n 'texture_depth_2d_array',\n 'texture_depth_cube',\n 'texture_depth_cube_array',\n 'texture_depth_multisampled_2d',\n ].includes(type);\n}\n\nexport function isStorageTextureType(\n type: TgpuRenderResourceType,\n): type is TgpuStorageTextureType {\n return [\n 'texture_storage_1d',\n 'texture_storage_2d',\n 'texture_storage_2d_array',\n 'texture_storage_3d',\n ].includes(type);\n}\n\nexport function isExternalTextureType(\n type: TgpuRenderResourceType,\n): type is TgpuExternalTextureType {\n return type === 'texture_external';\n}\n\nexport interface TgpuData<TInner> extends ISchema<TInner>, TgpuResolvable {\n readonly byteAlignment: number;\n readonly size: number;\n}\n\nexport type AnyTgpuData = TgpuData<unknown>;\nexport type TextureScalarFormat = U32 | I32 | F32;\nexport type TexelFormat = Vec4u | Vec4i | Vec4f;\n\nexport interface TgpuPointer<\n TScope extends 'function',\n TInner extends AnyTgpuData,\n> {\n readonly scope: TScope;\n readonly pointsTo: TInner;\n}\n\n/**\n * A virtual representation of a WGSL value.\n */\nexport type TgpuValue<TDataType> = {\n readonly __dataType: TDataType;\n};\n\nexport type AnyTgpuPointer = TgpuPointer<'function', AnyTgpuData>;\n\nexport type TgpuFnArgument = AnyTgpuPointer | AnyTgpuData;\n\nexport function isPointer(\n value: AnyTgpuPointer | AnyTgpuData,\n): value is AnyTgpuPointer {\n return 'pointsTo' in value;\n}\n\nexport function isGPUBuffer(value: unknown): value is GPUBuffer {\n return (\n !!value &&\n typeof value === 'object' &&\n 'getMappedRange' in value &&\n 'mapAsync' in value\n );\n}\n","import type { TgpuResolvable, TgpuSlot } from './types';\n\n/**\n * An error that happens during resolution of WGSL code.\n * Contains a trace of all ancestor resolvables in\n * which this error originated.\n *\n * @category Errors\n */\nexport class ResolutionError extends Error {\n constructor(\n public readonly cause: unknown,\n public readonly trace: TgpuResolvable[],\n ) {\n let entries = trace.map((ancestor) => `- ${ancestor}`);\n\n // Showing only the root and leaf nodes.\n if (entries.length > 20) {\n entries = [...entries.slice(0, 11), '...', ...entries.slice(-10)];\n }\n\n super(`Resolution of the following tree failed: \\n${entries.join('\\n')}`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, ResolutionError.prototype);\n }\n\n appendToTrace(ancestor: TgpuResolvable): ResolutionError {\n const newTrace = [ancestor, ...this.trace];\n\n return new ResolutionError(this.cause, newTrace);\n }\n}\n\n/**\n * @category Errors\n */\nexport class MissingSlotValueError extends Error {\n constructor(public readonly slot: TgpuSlot<unknown>) {\n super(`Missing value for '${slot}'`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, MissingSlotValueError.prototype);\n }\n}\n\n/**\n * @category Errors\n */\nexport class RecursiveDataTypeError extends Error {\n constructor() {\n super('Recursive types are not supported in WGSL');\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, RecursiveDataTypeError.prototype);\n }\n}\n","import {\n type IMeasurer,\n type IRefResolver,\n type ISchema,\n type ISerialInput,\n type ISerialOutput,\n type MaxValue,\n Measurer,\n type Parsed,\n f32,\n i32,\n u32,\n} from 'typed-binary';\nimport { CallableImpl } from '../callable';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { TgpuData } from '../types';\nimport alignIO from './alignIO';\n\n// --------------\n// Implementation\n// --------------\n\ninterface VecSchemaOptions<T> {\n unitType: ISchema<number>;\n byteAlignment: number;\n length: number;\n label: string;\n make: (...args: number[]) => T;\n makeFromScalar: (value: number) => T;\n}\n\nclass VecSchemaImpl<T extends vecBase>\n extends CallableImpl<number[], T>\n implements TgpuData<T>\n{\n readonly __unwrapped!: T; // type-token, not available at runtime\n\n readonly unitType: ISchema<number>;\n readonly byteAlignment;\n readonly length;\n readonly size;\n readonly label;\n public get expressionCode() {\n return this.label;\n }\n readonly make: (...args: number[]) => T;\n readonly makeFromScalar: (value: number) => T;\n\n constructor({\n unitType,\n byteAlignment,\n length,\n label,\n make,\n makeFromScalar,\n }: VecSchemaOptions<T>) {\n super();\n this.unitType = unitType;\n this.byteAlignment = byteAlignment;\n this.length = length;\n this.size = length * 4;\n this.label = label;\n this.make = make;\n this.makeFromScalar = makeFromScalar;\n }\n\n _call(...args: number[]): T {\n const values = args; // TODO: Allow users to pass in vectors that fill part of the values.\n\n if (values.length <= 1) {\n return this.makeFromScalar(values[0] ?? 0);\n }\n\n if (values.length === this.length) {\n return this.make(...values);\n }\n\n throw new Error(\n `'${this.label}' constructor called with invalid number of arguments.`,\n );\n }\n\n resolveReferences(ctx: IRefResolver): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: Parsed<T>): void {\n alignIO(output, this.byteAlignment);\n for (const element of value) {\n this.unitType.write(output, element);\n }\n }\n\n read(input: ISerialInput): Parsed<T> {\n alignIO(input, this.byteAlignment);\n return this.make(\n ...Array.from({ length: this.length }).map((_) =>\n this.unitType.read(input),\n ),\n ) as Parsed<T>;\n }\n\n measure(\n _value: Parsed<T> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment);\n return measurer.add(this.size);\n }\n\n seekProperty(\n reference: Parsed<T> | MaxValue,\n prop: never,\n ): { bufferOffset: number; schema: ISchema<unknown> } | null {\n throw new Error('Method not implemented.');\n }\n\n resolve(): string {\n return this.label;\n }\n}\n\nabstract class Swizzle2Impl<T2> {\n abstract make2(x: number, y: number): T2;\n\n abstract readonly x: number;\n abstract readonly y: number;\n\n get xx(): T2 {\n return this.make2(this.x, this.x);\n }\n\n get xy(): T2 {\n return this.make2(this.x, this.y);\n }\n\n get yx(): T2 {\n return this.make2(this.y, this.x);\n }\n\n get yy(): T2 {\n return this.make2(this.y, this.y);\n }\n}\n\nabstract class vec2Impl<T2> extends Swizzle2Impl<T2> implements vec2 {\n constructor(\n public x: number,\n public y: number,\n ) {\n super();\n }\n\n *[Symbol.iterator]() {\n yield this.x;\n yield this.y;\n }\n}\n\nclass vec2fImpl extends vec2Impl<vec2f> implements vec2f {\n readonly kind = 'vec2f';\n\n make2(x: number, y: number): vec2f {\n return new vec2fImpl(x, y);\n }\n}\n\nclass vec2iImpl extends vec2Impl<vec2i> implements vec2i {\n readonly kind = 'vec2i';\n\n make2(x: number, y: number): vec2i {\n return new vec2iImpl(x, y);\n }\n}\n\nclass vec2uImpl extends vec2Impl<vec2u> implements vec2u {\n readonly kind = 'vec2u';\n\n make2(x: number, y: number): vec2u {\n return new vec2uImpl(x, y);\n }\n}\n\nabstract class Swizzle3Impl<T2, T3> extends Swizzle2Impl<T2> {\n abstract make3(x: number, y: number, z: number): T3;\n\n abstract readonly z: number;\n}\n\nabstract class vec3Impl<T2, T3> extends Swizzle3Impl<T2, T3> implements vec3 {\n constructor(\n public x: number,\n public y: number,\n public z: number,\n ) {\n super();\n }\n\n *[Symbol.iterator]() {\n yield this.x;\n yield this.y;\n yield this.z;\n }\n}\n\nclass vec3fImpl extends vec3Impl<vec2f, vec3f> implements vec3f {\n readonly kind = 'vec3f';\n\n make2(x: number, y: number): vec2f {\n return new vec2fImpl(x, y);\n }\n\n make3(x: number, y: number, z: number): vec3f {\n return new vec3fImpl(x, y, z);\n }\n}\n\nclass vec3iImpl extends vec3Impl<vec2i, vec3i> implements vec3i {\n readonly kind = 'vec3i';\n\n make2(x: number, y: number): vec2i {\n return new vec2iImpl(x, y);\n }\n\n make3(x: number, y: number, z: number): vec3i {\n return new vec3iImpl(x, y, z);\n }\n}\n\nclass vec3uImpl extends vec3Impl<vec2u, vec3u> implements vec3u {\n readonly kind = 'vec3u';\n\n make2(x: number, y: number): vec2u {\n return new vec2uImpl(x, y);\n }\n\n make3(x: number, y: number, z: number): vec3u {\n return new vec3uImpl(x, y, z);\n }\n}\n\nabstract class Swizzle4Impl<T2, T3, T4> extends Swizzle3Impl<T2, T3> {\n abstract make4(x: number, y: number, z: number, w: number): T4;\n\n abstract readonly w: number;\n}\n\nabstract class vec4Impl<T2, T3, T4>\n extends Swizzle4Impl<T2, T3, T4>\n implements vec4\n{\n constructor(\n public x: number,\n public y: number,\n public z: number,\n public w: number,\n ) {\n super();\n }\n\n *[Symbol.iterator]() {\n yield this.x;\n yield this.y;\n yield this.z;\n yield this.w;\n }\n}\n\nclass vec4fImpl extends vec4Impl<vec2f, vec3f, vec4f> implements vec4f {\n readonly kind = 'vec4f';\n\n make2(x: number, y: number): vec2f {\n return new vec2fImpl(x, y);\n }\n\n make3(x: number, y: number, z: number): vec3f {\n return new vec3fImpl(x, y, z);\n }\n\n make4(x: number, y: number, z: number, w: number): vec4f {\n return new vec4fImpl(x, y, z, w);\n }\n}\n\nclass vec4iImpl extends vec4Impl<vec2i, vec3i, vec4i> implements vec4i {\n readonly kind = 'vec4i';\n\n make2(x: number, y: number): vec2i {\n return new vec2iImpl(x, y);\n }\n\n make3(x: number, y: number, z: number): vec3i {\n return new vec3iImpl(x, y, z);\n }\n\n make4(x: number, y: number, z: number, w: number): vec4i {\n return new vec4iImpl(x, y, z, w);\n }\n}\n\nclass vec4uImpl extends vec4Impl<vec2u, vec3u, vec4u> implements vec4u {\n readonly kind = 'vec4u';\n\n make2(x: number, y: number): vec2u {\n return new vec2uImpl(x, y);\n }\n\n make3(x: number, y: number, z: number): vec3u {\n return new vec3uImpl(x, y, z);\n }\n\n make4(x: number, y: number, z: number, w: number): vec4u {\n return new vec4uImpl(x, y, z, w);\n }\n}\n\ninterface Swizzle2<T2> {\n readonly xx: T2; // TODO: Create setter\n readonly xy: T2; // TODO: Create setter\n readonly yx: T2; // TODO: Create setter\n readonly yy: T2; // TODO: Create setter\n}\n\ninterface Swizzle3<T2, T3> extends Swizzle2<T2> {\n // TODO: Implement\n}\n\ninterface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3> {\n // TODO: Implement\n}\n\ninterface vec2 {\n x: number;\n y: number;\n [Symbol.iterator](): Iterator<number>;\n}\n\ninterface vec3 {\n x: number;\n y: number;\n z: number;\n [Symbol.iterator](): Iterator<number>;\n}\n\ninterface vec4 {\n x: number;\n y: number;\n z: number;\n w: number;\n [Symbol.iterator](): Iterator<number>;\n}\n\n// ----------\n// Public API\n// ----------\n\nexport type VecKind =\n | 'vec2f'\n | 'vec2i'\n | 'vec2u'\n | 'vec3f'\n | 'vec3i'\n | 'vec3u'\n | 'vec4f'\n | 'vec4i'\n | 'vec4u';\n\nexport interface vecBase {\n kind: VecKind;\n [Symbol.iterator](): Iterator<number>;\n}\n\nexport interface vec2f extends vec2, Swizzle2<vec2f> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec2f';\n}\nexport interface vec2i extends vec2, Swizzle2<vec2i> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec2i';\n}\nexport interface vec2u extends vec2, Swizzle2<vec2u> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec2u';\n}\n\nexport interface vec3f extends vec3, Swizzle3<vec2f, vec3f> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec3f';\n}\nexport interface vec3i extends vec3, Swizzle3<vec2i, vec3i> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec3i';\n}\nexport interface vec3u extends vec3, Swizzle3<vec2u, vec3u> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec3u';\n}\n\nexport interface vec4f extends vec4, Swizzle4<vec2f, vec3f, vec4f> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec4f';\n}\nexport interface vec4i extends vec4, Swizzle4<vec2i, vec3i, vec4i> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec4i';\n}\nexport interface vec4u extends vec4, Swizzle4<vec2u, vec3u, vec4u> {\n /** use to distinguish between vectors of the same size on the type level */\n kind: 'vec4u';\n}\n\nexport type Vec2f = TgpuData<vec2f> &\n ((x: number, y: number) => vec2f) &\n ((xy: number) => vec2f) &\n (() => vec2f);\n\nexport const vec2f = new VecSchemaImpl({\n unitType: f32,\n byteAlignment: 8,\n length: 2,\n label: 'vec2f',\n make: (x: number, y: number) => new vec2fImpl(x, y),\n makeFromScalar: (x) => new vec2fImpl(x, x),\n}) as unknown as Vec2f;\n\nexport type Vec2i = TgpuData<vec2i> &\n ((x: number, y: number) => vec2i) &\n ((xy: number) => vec2i) &\n (() => vec2i);\n\nexport const vec2i = new VecSchemaImpl({\n unitType: i32,\n byteAlignment: 8,\n length: 2,\n label: 'vec2i',\n make: (x: number, y: number) => new vec2iImpl(x, y),\n makeFromScalar: (x) => new vec2iImpl(x, x),\n}) as unknown as Vec2i;\n\nexport type Vec2u = TgpuData<vec2u> &\n ((x: number, y: number) => vec2u) &\n ((xy: number) => vec2u) &\n (() => vec2u);\n\nexport const vec2u = new VecSchemaImpl({\n unitType: u32,\n byteAlignment: 8,\n length: 2,\n label: 'vec2u',\n make: (x: number, y: number) => new vec2uImpl(x, y),\n makeFromScalar: (x) => new vec2uImpl(x, x),\n}) as unknown as Vec2u;\n\nexport type Vec3f = TgpuData<vec3f> &\n ((x: number, y: number, z: number) => vec3f) &\n ((xyz: number) => vec3f) &\n (() => vec3f);\n\nexport const vec3f = new VecSchemaImpl({\n unitType: f32,\n byteAlignment: 16,\n length: 3,\n label: 'vec3f',\n make: (x, y, z) => new vec3fImpl(x, y, z),\n makeFromScalar: (x) => new vec3fImpl(x, x, x),\n}) as unknown as Vec3f;\n\nexport type Vec3i = TgpuData<vec3i> &\n ((x: number, y: number, z: number) => vec3i) &\n ((xyz: number) => vec3i) &\n (() => vec3i);\n\nexport const vec3i = new VecSchemaImpl({\n unitType: i32,\n byteAlignment: 16,\n length: 3,\n label: 'vec3i',\n make: (x, y, z) => new vec3iImpl(x, y, z),\n makeFromScalar: (x) => new vec3iImpl(x, x, x),\n}) as unknown as Vec3i;\n\nexport type Vec3u = TgpuData<vec3u> &\n ((x: number, y: number, z: number) => vec3u) &\n ((xyz: number) => vec3u) &\n (() => vec3u);\n\nexport const vec3u = new VecSchemaImpl({\n unitType: u32,\n byteAlignment: 16,\n length: 3,\n label: 'vec3u',\n make: (x, y, z) => new vec3uImpl(x, y, z),\n makeFromScalar: (x) => new vec3uImpl(x, x, x),\n}) as unknown as Vec3u;\n\nexport type Vec4f = TgpuData<vec4f> &\n ((x: number, y: number, z: number, w: number) => vec4f) &\n ((xyzw: number) => vec4f) &\n (() => vec4f);\n\nexport const vec4f = new VecSchemaImpl({\n unitType: f32,\n byteAlignment: 16,\n length: 4,\n label: 'vec4f',\n make: (x, y, z, w) => new vec4fImpl(x, y, z, w),\n makeFromScalar: (x) => new vec4fImpl(x, x, x, x),\n}) as unknown as Vec4f;\n\nexport type Vec4i = TgpuData<vec4i> &\n ((x: number, y: number, z: number, w: number) => vec4i) &\n ((xyzw: number) => vec4i) &\n (() => vec4i);\n\nexport const vec4i = new VecSchemaImpl({\n unitType: i32,\n byteAlignment: 16,\n length: 4,\n label: 'vec4i',\n make: (x, y, z, w) => new vec4iImpl(x, y, z, w),\n makeFromScalar: (x) => new vec4iImpl(x, x, x, x),\n}) as unknown as Vec4i;\n\nexport type Vec4u = TgpuData<vec4u> &\n ((x: number, y: number, z: number, w: number) => vec4u) &\n ((xyzw: number) => vec4u) &\n (() => vec4u);\n\nexport const vec4u = new VecSchemaImpl({\n unitType: u32,\n byteAlignment: 16,\n length: 4,\n label: 'vec4u',\n make: (x, y, z, w) => new vec4uImpl(x, y, z, w),\n makeFromScalar: (x) => new vec4uImpl(x, x, x, x),\n}) as unknown as Vec4u;\n","export abstract class CallableImpl<\n TArgs extends [...unknown[]],\n TReturn,\n> extends Function {\n _bound: CallableImpl<TArgs, TReturn>;\n\n constructor() {\n // We create a new Function object using `super`, with a `this` reference\n // to itself (the Function object) provided by binding it to `this`,\n // then returning the bound Function object (which is a wrapper around the\n // the original `this`/Function object). We then also have to store\n // a reference to the bound Function object, as `_bound` on the unbound `this`,\n // so the bound function has access to the new bound object.\n // Pro: Works well, doesn't rely on deprecated features.\n // Con: A little convoluted, and requires wrapping `this` in a bound object.\n\n super('...args', 'return this._bound._call(...args)');\n // Or without the spread/rest operator:\n // super('return this._bound._call.apply(this._bound, arguments)')\n this._bound = this.bind(this);\n\n // biome-ignore lint/correctness/noConstructorReturn: <quirks of creating a custom callable>\n return this._bound;\n }\n\n abstract _call(...args: TArgs): TReturn;\n}\n\nexport type Callable<TArgs extends [...unknown[]], TReturn> = (\n ...args: TArgs\n) => TReturn;\n\nexport type AsCallable<T, TArgs extends [...unknown[]], TReturn> = T &\n Callable<TArgs, TReturn>;\n","import type { IMeasurer, ISerialInput, ISerialOutput } from 'typed-binary';\n\n/**\n * @param io the IO to align\n * @param baseAlignment must be power of 2\n */\nfunction alignIO(\n io: ISerialInput | ISerialOutput | IMeasurer,\n baseAlignment: number,\n) {\n const currentPos = 'size' in io ? io.size : io.currentByteOffset;\n\n const bitMask = baseAlignment - 1;\n const offset = currentPos & bitMask;\n\n if ('skipBytes' in io) {\n io.skipBytes((baseAlignment - offset) & bitMask);\n } else {\n io.add((baseAlignment - offset) & bitMask);\n }\n}\n\nexport default alignIO;\n","/**\n * @param value\n * @param modulo has to be power of 2\n */\nexport const roundUp = (value: number, modulo: number) => {\n const bitMask = modulo - 1;\n const invBitMask = ~bitMask;\n return (value & bitMask) === 0 ? value : (value & invBitMask) + modulo;\n};\n"]}
@@ -1,202 +0,0 @@
1
- import { ISchema, Parsed } from 'typed-binary';
2
-
3
- interface Swizzle2<T2> {
4
- readonly xx: T2;
5
- readonly xy: T2;
6
- readonly yx: T2;
7
- readonly yy: T2;
8
- }
9
- interface Swizzle3<T2, T3> extends Swizzle2<T2> {
10
- }
11
- interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3> {
12
- }
13
- interface vec2 {
14
- x: number;
15
- y: number;
16
- [Symbol.iterator](): Iterator<number>;
17
- }
18
- interface vec3 {
19
- x: number;
20
- y: number;
21
- z: number;
22
- [Symbol.iterator](): Iterator<number>;
23
- }
24
- interface vec4 {
25
- x: number;
26
- y: number;
27
- z: number;
28
- w: number;
29
- [Symbol.iterator](): Iterator<number>;
30
- }
31
- type VecKind = 'vec2f' | 'vec2i' | 'vec2u' | 'vec3f' | 'vec3i' | 'vec3u' | 'vec4f' | 'vec4i' | 'vec4u';
32
- interface vecBase {
33
- kind: VecKind;
34
- [Symbol.iterator](): Iterator<number>;
35
- }
36
- type Vec2f = TgpuData<vec2f> & ((x: number, y: number) => vec2f) & ((xy: number) => vec2f) & (() => vec2f);
37
- interface vec2f extends vec2, Swizzle2<vec2f> {
38
- /** use to distinguish between vectors of the same size on the type level */
39
- kind: 'vec2f';
40
- }
41
- declare const vec2f: Vec2f;
42
- type Vec2i = TgpuData<vec2i> & ((x: number, y: number) => vec2i) & ((xy: number) => vec2i) & (() => vec2i);
43
- interface vec2i extends vec2, Swizzle2<vec2i> {
44
- /** use to distinguish between vectors of the same size on the type level */
45
- kind: 'vec2i';
46
- }
47
- declare const vec2i: Vec2i;
48
- type Vec2u = TgpuData<vec2u> & ((x: number, y: number) => vec2u) & ((xy: number) => vec2u) & (() => vec2u);
49
- interface vec2u extends vec2, Swizzle2<vec2u> {
50
- /** use to distinguish between vectors of the same size on the type level */
51
- kind: 'vec2u';
52
- }
53
- declare const vec2u: Vec2u;
54
- type Vec3f = TgpuData<vec3f> & ((x: number, y: number, z: number) => vec3f) & ((xyz: number) => vec3f) & (() => vec3f);
55
- interface vec3f extends vec3, Swizzle3<vec2f, vec3f> {
56
- /** use to distinguish between vectors of the same size on the type level */
57
- kind: 'vec3f';
58
- }
59
- declare const vec3f: Vec3f;
60
- type Vec3i = TgpuData<vec3i> & ((x: number, y: number, z: number) => vec3i) & ((xyz: number) => vec3i) & (() => vec3i);
61
- interface vec3i extends vec3, Swizzle3<vec2i, vec3i> {
62
- /** use to distinguish between vectors of the same size on the type level */
63
- kind: 'vec3i';
64
- }
65
- declare const vec3i: Vec3i;
66
- type Vec3u = TgpuData<vec3u> & ((x: number, y: number, z: number) => vec3u) & ((xyz: number) => vec3u) & (() => vec3u);
67
- interface vec3u extends vec3, Swizzle3<vec2u, vec3u> {
68
- /** use to distinguish between vectors of the same size on the type level */
69
- kind: 'vec3u';
70
- }
71
- declare const vec3u: Vec3u;
72
- type Vec4f = TgpuData<vec4f> & ((x: number, y: number, z: number, w: number) => vec4f) & ((xyzw: number) => vec4f) & (() => vec4f);
73
- interface vec4f extends vec4, Swizzle4<vec2f, vec3f, vec4f> {
74
- /** use to distinguish between vectors of the same size on the type level */
75
- kind: 'vec4f';
76
- }
77
- declare const vec4f: Vec4f;
78
- type Vec4i = TgpuData<vec4i> & ((x: number, y: number, z: number, w: number) => vec4i) & ((xyzw: number) => vec4i) & (() => vec4i);
79
- interface vec4i extends vec4, Swizzle4<vec2i, vec3i, vec4i> {
80
- /** use to distinguish between vectors of the same size on the type level */
81
- kind: 'vec4i';
82
- }
83
- declare const vec4i: Vec4i;
84
- type Vec4u = TgpuData<vec4u> & ((x: number, y: number, z: number, w: number) => vec4u) & ((xyzw: number) => vec4u) & (() => vec4u);
85
- interface vec4u extends vec4, Swizzle4<vec2u, vec3u, vec4u> {
86
- /** use to distinguish between vectors of the same size on the type level */
87
- kind: 'vec4u';
88
- }
89
- declare const vec4u: Vec4u;
90
-
91
- /**
92
- * Helpful when creating new Resolvable types. For internal use.
93
- */
94
- declare class TgpuIdentifier implements TgpuResolvable, TgpuNamable {
95
- label?: string | undefined;
96
- $name(label: string | undefined): this;
97
- resolve(ctx: ResolutionCtx): string;
98
- toString(): string;
99
- }
100
-
101
- interface Builtin {
102
- symbol: symbol;
103
- name: string;
104
- stage: 'vertex' | 'fragment' | 'compute';
105
- direction: 'input' | 'output';
106
- identifier: TgpuIdentifier;
107
- }
108
-
109
- type Getter = <T>(plum: TgpuPlum<T>) => T;
110
- interface TgpuPlum<TValue = unknown> extends TgpuNamable {
111
- readonly __brand: 'TgpuPlum';
112
- /**
113
- * Computes the value of this plum. Circumvents the store
114
- * memoization, so use with care.
115
- */
116
- compute(get: Getter): TValue;
117
- }
118
-
119
- type Wgsl = string | number | TgpuResolvable | symbol | boolean;
120
- /**
121
- * Passed into each resolvable item. All sibling items share a resolution ctx,
122
- * and a new resolution ctx is made when going down each level in the tree.
123
- */
124
- interface ResolutionCtx {
125
- /**
126
- * Slots that were used by items resolved by this context.
127
- */
128
- readonly usedSlots: Iterable<TgpuSlot<unknown>>;
129
- addDeclaration(item: TgpuResolvable): void;
130
- addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;
131
- addRenderResource(resource: TgpuRenderResource, identifier: TgpuIdentifier): void;
132
- addBuiltin(builtin: Builtin): void;
133
- nameFor(token: TgpuResolvable): string;
134
- /**
135
- * Unwraps all layers of slot indirection and returns the concrete value if available.
136
- * @throws {MissingSlotValueError}
137
- */
138
- unwrap<T>(eventual: Eventual<T>): T;
139
- resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
140
- }
141
- interface TgpuResolvable {
142
- readonly label?: string | undefined;
143
- resolve(ctx: ResolutionCtx): string;
144
- }
145
- /**
146
- * Can be assigned a name. Not to be confused with
147
- * being able to HAVE a name.
148
- */
149
- interface TgpuNamable {
150
- $name(label?: string | undefined): this;
151
- }
152
- interface TgpuSlot<T> extends TgpuNamable {
153
- readonly __brand: 'TgpuSlot';
154
- readonly defaultValue: T | undefined;
155
- readonly label?: string | undefined;
156
- /**
157
- * Used to determine if code generated using either value `a` or `b` in place
158
- * of the slot will be equivalent. Defaults to `Object.is`.
159
- */
160
- areEqual(a: T, b: T): boolean;
161
- }
162
- /**
163
- * Represents a value that is available at resolution time.
164
- */
165
- type Eventual<T> = T | TgpuSlot<T>;
166
- type SlotValuePair<T> = [TgpuSlot<T>, T];
167
- interface TgpuAllocatable<TData extends AnyTgpuData = AnyTgpuData> {
168
- /**
169
- * The data type this allocatable was constructed with.
170
- * It informs the size and format of data in both JS and
171
- * binary.
172
- */
173
- readonly dataType: TData;
174
- readonly initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined;
175
- readonly flags: GPUBufferUsageFlags;
176
- }
177
- interface TgpuBindable<TData extends AnyTgpuData = AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuResolvable {
178
- readonly allocatable: TgpuAllocatable<TData>;
179
- readonly usage: TUsage;
180
- }
181
- type TgpuSamplerType = 'sampler' | 'sampler_comparison';
182
- type TgpuTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
183
- type TgpuDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
184
- type TgpuStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
185
- type TgpuExternalTextureType = 'texture_external';
186
- type TgpuRenderResourceType = TgpuSamplerType | TgpuTypedTextureType | TgpuDepthTextureType | TgpuStorageTextureType | TgpuExternalTextureType;
187
- interface TgpuRenderResource extends TgpuResolvable {
188
- readonly type: TgpuRenderResourceType;
189
- }
190
- type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
191
- interface TgpuData<TInner> extends ISchema<TInner>, TgpuResolvable {
192
- readonly byteAlignment: number;
193
- readonly size: number;
194
- }
195
- type AnyTgpuData = TgpuData<unknown>;
196
- type TexelFormat = Vec4u | Vec4i | Vec4f;
197
- interface TgpuPointer<TScope extends 'function', TInner extends AnyTgpuData> {
198
- readonly scope: TScope;
199
- readonly pointsTo: TInner;
200
- }
201
-
202
- export { type AnyTgpuData as A, type ResolutionCtx as R, type TgpuAllocatable as T, type VecKind as V, type TgpuNamable as a, type TgpuPlum as b, vec3f as c, vec3i as d, vec3u as e, type TgpuData as f, type TexelFormat as g, vec2f as h, vec4f as i, type TgpuPointer as j, vec2i as k, vec2u as l, vec4i as m, vec4u as n, type Vec2f as o, type Vec2i as p, type Vec2u as q, type Vec3f as r, type Vec3i as s, type Vec3u as t, type Vec4f as u, type vecBase as v, type Vec4i as w, type Vec4u as x };
@@ -1,202 +0,0 @@
1
- import { ISchema, Parsed } from 'typed-binary';
2
-
3
- interface Swizzle2<T2> {
4
- readonly xx: T2;
5
- readonly xy: T2;
6
- readonly yx: T2;
7
- readonly yy: T2;
8
- }
9
- interface Swizzle3<T2, T3> extends Swizzle2<T2> {
10
- }
11
- interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3> {
12
- }
13
- interface vec2 {
14
- x: number;
15
- y: number;
16
- [Symbol.iterator](): Iterator<number>;
17
- }
18
- interface vec3 {
19
- x: number;
20
- y: number;
21
- z: number;
22
- [Symbol.iterator](): Iterator<number>;
23
- }
24
- interface vec4 {
25
- x: number;
26
- y: number;
27
- z: number;
28
- w: number;
29
- [Symbol.iterator](): Iterator<number>;
30
- }
31
- type VecKind = 'vec2f' | 'vec2i' | 'vec2u' | 'vec3f' | 'vec3i' | 'vec3u' | 'vec4f' | 'vec4i' | 'vec4u';
32
- interface vecBase {
33
- kind: VecKind;
34
- [Symbol.iterator](): Iterator<number>;
35
- }
36
- type Vec2f = TgpuData<vec2f> & ((x: number, y: number) => vec2f) & ((xy: number) => vec2f) & (() => vec2f);
37
- interface vec2f extends vec2, Swizzle2<vec2f> {
38
- /** use to distinguish between vectors of the same size on the type level */
39
- kind: 'vec2f';
40
- }
41
- declare const vec2f: Vec2f;
42
- type Vec2i = TgpuData<vec2i> & ((x: number, y: number) => vec2i) & ((xy: number) => vec2i) & (() => vec2i);
43
- interface vec2i extends vec2, Swizzle2<vec2i> {
44
- /** use to distinguish between vectors of the same size on the type level */
45
- kind: 'vec2i';
46
- }
47
- declare const vec2i: Vec2i;
48
- type Vec2u = TgpuData<vec2u> & ((x: number, y: number) => vec2u) & ((xy: number) => vec2u) & (() => vec2u);
49
- interface vec2u extends vec2, Swizzle2<vec2u> {
50
- /** use to distinguish between vectors of the same size on the type level */
51
- kind: 'vec2u';
52
- }
53
- declare const vec2u: Vec2u;
54
- type Vec3f = TgpuData<vec3f> & ((x: number, y: number, z: number) => vec3f) & ((xyz: number) => vec3f) & (() => vec3f);
55
- interface vec3f extends vec3, Swizzle3<vec2f, vec3f> {
56
- /** use to distinguish between vectors of the same size on the type level */
57
- kind: 'vec3f';
58
- }
59
- declare const vec3f: Vec3f;
60
- type Vec3i = TgpuData<vec3i> & ((x: number, y: number, z: number) => vec3i) & ((xyz: number) => vec3i) & (() => vec3i);
61
- interface vec3i extends vec3, Swizzle3<vec2i, vec3i> {
62
- /** use to distinguish between vectors of the same size on the type level */
63
- kind: 'vec3i';
64
- }
65
- declare const vec3i: Vec3i;
66
- type Vec3u = TgpuData<vec3u> & ((x: number, y: number, z: number) => vec3u) & ((xyz: number) => vec3u) & (() => vec3u);
67
- interface vec3u extends vec3, Swizzle3<vec2u, vec3u> {
68
- /** use to distinguish between vectors of the same size on the type level */
69
- kind: 'vec3u';
70
- }
71
- declare const vec3u: Vec3u;
72
- type Vec4f = TgpuData<vec4f> & ((x: number, y: number, z: number, w: number) => vec4f) & ((xyzw: number) => vec4f) & (() => vec4f);
73
- interface vec4f extends vec4, Swizzle4<vec2f, vec3f, vec4f> {
74
- /** use to distinguish between vectors of the same size on the type level */
75
- kind: 'vec4f';
76
- }
77
- declare const vec4f: Vec4f;
78
- type Vec4i = TgpuData<vec4i> & ((x: number, y: number, z: number, w: number) => vec4i) & ((xyzw: number) => vec4i) & (() => vec4i);
79
- interface vec4i extends vec4, Swizzle4<vec2i, vec3i, vec4i> {
80
- /** use to distinguish between vectors of the same size on the type level */
81
- kind: 'vec4i';
82
- }
83
- declare const vec4i: Vec4i;
84
- type Vec4u = TgpuData<vec4u> & ((x: number, y: number, z: number, w: number) => vec4u) & ((xyzw: number) => vec4u) & (() => vec4u);
85
- interface vec4u extends vec4, Swizzle4<vec2u, vec3u, vec4u> {
86
- /** use to distinguish between vectors of the same size on the type level */
87
- kind: 'vec4u';
88
- }
89
- declare const vec4u: Vec4u;
90
-
91
- /**
92
- * Helpful when creating new Resolvable types. For internal use.
93
- */
94
- declare class TgpuIdentifier implements TgpuResolvable, TgpuNamable {
95
- label?: string | undefined;
96
- $name(label: string | undefined): this;
97
- resolve(ctx: ResolutionCtx): string;
98
- toString(): string;
99
- }
100
-
101
- interface Builtin {
102
- symbol: symbol;
103
- name: string;
104
- stage: 'vertex' | 'fragment' | 'compute';
105
- direction: 'input' | 'output';
106
- identifier: TgpuIdentifier;
107
- }
108
-
109
- type Getter = <T>(plum: TgpuPlum<T>) => T;
110
- interface TgpuPlum<TValue = unknown> extends TgpuNamable {
111
- readonly __brand: 'TgpuPlum';
112
- /**
113
- * Computes the value of this plum. Circumvents the store
114
- * memoization, so use with care.
115
- */
116
- compute(get: Getter): TValue;
117
- }
118
-
119
- type Wgsl = string | number | TgpuResolvable | symbol | boolean;
120
- /**
121
- * Passed into each resolvable item. All sibling items share a resolution ctx,
122
- * and a new resolution ctx is made when going down each level in the tree.
123
- */
124
- interface ResolutionCtx {
125
- /**
126
- * Slots that were used by items resolved by this context.
127
- */
128
- readonly usedSlots: Iterable<TgpuSlot<unknown>>;
129
- addDeclaration(item: TgpuResolvable): void;
130
- addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;
131
- addRenderResource(resource: TgpuRenderResource, identifier: TgpuIdentifier): void;
132
- addBuiltin(builtin: Builtin): void;
133
- nameFor(token: TgpuResolvable): string;
134
- /**
135
- * Unwraps all layers of slot indirection and returns the concrete value if available.
136
- * @throws {MissingSlotValueError}
137
- */
138
- unwrap<T>(eventual: Eventual<T>): T;
139
- resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
140
- }
141
- interface TgpuResolvable {
142
- readonly label?: string | undefined;
143
- resolve(ctx: ResolutionCtx): string;
144
- }
145
- /**
146
- * Can be assigned a name. Not to be confused with
147
- * being able to HAVE a name.
148
- */
149
- interface TgpuNamable {
150
- $name(label?: string | undefined): this;
151
- }
152
- interface TgpuSlot<T> extends TgpuNamable {
153
- readonly __brand: 'TgpuSlot';
154
- readonly defaultValue: T | undefined;
155
- readonly label?: string | undefined;
156
- /**
157
- * Used to determine if code generated using either value `a` or `b` in place
158
- * of the slot will be equivalent. Defaults to `Object.is`.
159
- */
160
- areEqual(a: T, b: T): boolean;
161
- }
162
- /**
163
- * Represents a value that is available at resolution time.
164
- */
165
- type Eventual<T> = T | TgpuSlot<T>;
166
- type SlotValuePair<T> = [TgpuSlot<T>, T];
167
- interface TgpuAllocatable<TData extends AnyTgpuData = AnyTgpuData> {
168
- /**
169
- * The data type this allocatable was constructed with.
170
- * It informs the size and format of data in both JS and
171
- * binary.
172
- */
173
- readonly dataType: TData;
174
- readonly initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined;
175
- readonly flags: GPUBufferUsageFlags;
176
- }
177
- interface TgpuBindable<TData extends AnyTgpuData = AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuResolvable {
178
- readonly allocatable: TgpuAllocatable<TData>;
179
- readonly usage: TUsage;
180
- }
181
- type TgpuSamplerType = 'sampler' | 'sampler_comparison';
182
- type TgpuTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
183
- type TgpuDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
184
- type TgpuStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
185
- type TgpuExternalTextureType = 'texture_external';
186
- type TgpuRenderResourceType = TgpuSamplerType | TgpuTypedTextureType | TgpuDepthTextureType | TgpuStorageTextureType | TgpuExternalTextureType;
187
- interface TgpuRenderResource extends TgpuResolvable {
188
- readonly type: TgpuRenderResourceType;
189
- }
190
- type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
191
- interface TgpuData<TInner> extends ISchema<TInner>, TgpuResolvable {
192
- readonly byteAlignment: number;
193
- readonly size: number;
194
- }
195
- type AnyTgpuData = TgpuData<unknown>;
196
- type TexelFormat = Vec4u | Vec4i | Vec4f;
197
- interface TgpuPointer<TScope extends 'function', TInner extends AnyTgpuData> {
198
- readonly scope: TScope;
199
- readonly pointsTo: TInner;
200
- }
201
-
202
- export { type AnyTgpuData as A, type ResolutionCtx as R, type TgpuAllocatable as T, type VecKind as V, type TgpuNamable as a, type TgpuPlum as b, vec3f as c, vec3i as d, vec3u as e, type TgpuData as f, type TexelFormat as g, vec2f as h, vec4f as i, type TgpuPointer as j, vec2i as k, vec2u as l, vec4i as m, vec4u as n, type Vec2f as o, type Vec2i as p, type Vec2u as q, type Vec3f as r, type Vec3i as s, type Vec3u as t, type Vec4f as u, type vecBase as v, type Vec4i as w, type Vec4u as x };