typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
150 lines (149 loc) • 14 kB
TypeScript
import { type v2f, type v2i, type v2u, type v3f, type v3i, type v3u, type v4f, type v4i, type v4u } from '../data/wgslTypes.ts';
import { type StorageTextureFormats, type TextureFormats } from '../core/texture/textureFormats.ts';
import type { $internal, $repr } from '../shared/symbols.ts';
import type { texture1d, texture2d, texture2dArray, texture3d, textureCube, textureCubeArray, textureDepth2d, textureDepth2dArray, textureDepthCube, textureDepthCubeArray, textureDepthMultisampled2d, textureExternal, textureMultisampled2d, textureStorage1d, textureStorage2d, textureStorage2dArray, textureStorage3d } from '../data/texture.ts';
import type { comparisonSampler, sampler } from '../data/sampler.ts';
declare function sampleCpu<T extends texture1d>(texture: T, sampler: sampler, coords: number): v4f;
declare function sampleCpu<T extends texture2d>(texture: T, sampler: sampler, coords: v2f, offset?: v2i): v4f;
declare function sampleCpu<T extends texture2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, offset?: v2i): v4f;
declare function sampleCpu<T extends texture3d | textureCube>(texture: T, sampler: sampler, coords: v3f): v4f;
declare function sampleCpu<T extends texture3d>(texture: T, sampler: sampler, coords: v3f, offset: v3i): v4f;
declare function sampleCpu<T extends textureCubeArray>(texture: T, sampler: sampler, coords: v3f, arrayIndex: number): v4f;
declare function sampleCpu<T extends textureDepth2d>(texture: T, sampler: sampler, coords: v2f, offset?: v2i): number;
declare function sampleCpu<T extends textureDepth2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, offset?: v2i): number;
declare function sampleCpu<T extends textureDepthCube>(texture: T, sampler: sampler, coords: v3f, arrayIndex?: number): number;
export declare const textureSample: import("../types.ts").DualFn<typeof sampleCpu>;
declare function sampleBiasCpu<T extends texture1d>(texture: T, sampler: sampler, coords: number, bias: number): v4f;
declare function sampleBiasCpu<T extends texture2d>(texture: T, sampler: sampler, coords: v2f, bias: number, offset?: v2i): v4f;
declare function sampleBiasCpu<T extends texture2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, bias: number, offset?: v2i): v4f;
declare function sampleBiasCpu<T extends texture3d | textureCube>(texture: T, sampler: sampler, coords: v3f, bias: number, offset?: v3i): v4f;
declare function sampleBiasCpu<T extends textureCubeArray>(texture: T, sampler: sampler, coords: v3f, arrayIndex: number, bias: number): v4f;
export declare const textureSampleBias: import("../types.ts").DualFn<typeof sampleBiasCpu>;
declare function sampleLevelCpu<T extends texture1d>(texture: T, sampler: sampler, coords: number, level: number): v4f;
declare function sampleLevelCpu<T extends texture2d>(texture: T, sampler: sampler, coords: v2f, level: number): v4f;
declare function sampleLevelCpu<T extends texture2d>(texture: T, sampler: sampler, coords: v2f, level: number, offset: v2i): v4f;
declare function sampleLevelCpu<T extends texture2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, level: number): v4f;
declare function sampleLevelCpu<T extends texture2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, level: number, offset: v2i): v4f;
declare function sampleLevelCpu<T extends texture3d | textureCube>(texture: T, sampler: sampler, coords: v3f, level: number): v4f;
declare function sampleLevelCpu<T extends texture3d>(texture: T, sampler: sampler, coords: v3f, level: number, offset: v3i): v4f;
declare function sampleLevelCpu<T extends textureCubeArray>(texture: T, sampler: sampler, coords: v3f, arrayIndex: number, level: number): v4f;
declare function sampleLevelCpu<T extends textureDepth2d>(texture: T, sampler: sampler, coords: v2f, level: number): number;
declare function sampleLevelCpu<T extends textureDepth2d>(texture: T, sampler: sampler, coords: v2f, level: number, offset: v2i): number;
declare function sampleLevelCpu<T extends textureDepth2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, level: number): number;
declare function sampleLevelCpu<T extends textureDepth2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, level: number, offset: v2i): number;
declare function sampleLevelCpu<T extends textureDepthCube>(texture: T, sampler: sampler, coords: v3f, level: number): number;
declare function sampleLevelCpu<T extends textureCubeArray>(texture: T, sampler: sampler, coords: v3f, arrayIndex: number, level: number): number;
export declare const textureSampleLevel: import("../types.ts").DualFn<typeof sampleLevelCpu>;
type PrimitiveToLoadedType = {
f32: v4f;
i32: v4i;
u32: v4u;
};
type TexelFormatToInstanceType<T extends StorageTextureFormats> = TextureFormats[T]['vectorType'][typeof $repr];
declare function textureLoadCpu<T extends texture1d>(texture: T, coords: number, level: number): PrimitiveToLoadedType[T[typeof $internal]['type']];
declare function textureLoadCpu<T extends texture2d>(texture: T, coords: v2i | v2u, level: number): PrimitiveToLoadedType[T[typeof $internal]['type']];
declare function textureLoadCpu<T extends texture2dArray>(texture: T, coords: v2i | v2u, arrayIndex: number, level: number): PrimitiveToLoadedType[T[typeof $internal]['type']];
declare function textureLoadCpu<T extends texture3d>(texture: T, coords: v3i | v3u, level: number): PrimitiveToLoadedType[T[typeof $internal]['type']];
declare function textureLoadCpu<T extends textureMultisampled2d>(texture: T, coords: v2i | v2u, sampleIndex: number): PrimitiveToLoadedType[T[typeof $internal]['type']];
declare function textureLoadCpu<T extends textureDepth2d>(texture: T, coords: v2i | v2u, level: number): number;
declare function textureLoadCpu<T extends textureDepth2dArray>(texture: T, coords: v2i | v2u, arrayIndex: number, level: number): number;
declare function textureLoadCpu<T extends textureDepthMultisampled2d>(texture: T, coords: v2i | v2u, sampleIndex: number): number;
declare function textureLoadCpu<T extends textureExternal>(texture: T, coords: v2i | v2u): v4f;
declare function textureLoadCpu<T extends textureStorage1d>(texture: T, coords: number): TexelFormatToInstanceType<T[typeof $internal][0]>;
declare function textureLoadCpu<T extends textureStorage2d>(texture: T, coords: v2i | v2u): TexelFormatToInstanceType<T[typeof $internal][0]>;
declare function textureLoadCpu<T extends textureStorage2dArray>(texture: T, coords: v2i | v2u, arrayIndex: number): TexelFormatToInstanceType<T[typeof $internal][0]>;
declare function textureLoadCpu<T extends textureStorage3d>(texture: T, coords: v3i | v3u): TexelFormatToInstanceType<T[typeof $internal][0]>;
export declare const textureLoad: import("../types.ts").DualFn<typeof textureLoadCpu>;
declare function textureStoreCpu<T extends textureStorage1d>(texture: T, coords: number, value: TexelFormatToInstanceType<T[typeof $internal][0]>): void;
declare function textureStoreCpu<T extends textureStorage2d>(texture: T, coords: v2i | v2u, value: TexelFormatToInstanceType<T[typeof $internal][0]>): void;
declare function textureStoreCpu<T extends textureStorage2dArray>(texture: T, coords: v2i | v2u, arrayIndex: number, value: TexelFormatToInstanceType<T[typeof $internal][0]>): void;
declare function textureStoreCpu<T extends textureStorage3d>(texture: T, coords: v3i | v3u, value: TexelFormatToInstanceType<T[typeof $internal][0]>): void;
export declare const textureStore: import("../types.ts").DualFn<typeof textureStoreCpu>;
declare function textureDimensionsCpu<T extends texture1d | textureStorage1d>(texture: T): number;
declare function textureDimensionsCpu<T extends texture1d>(texture: T, level: number): number;
declare function textureDimensionsCpu<T extends texture2d | texture2dArray | textureCube | textureCubeArray | textureStorage2d | textureStorage2dArray | textureExternal>(texture: T): v2u;
declare function textureDimensionsCpu<T extends texture2d | texture2dArray | textureCube | textureCubeArray>(texture: T, level: number): v2u;
declare function textureDimensionsCpu<T extends texture3d | textureStorage3d>(texture: T): v3u;
declare function textureDimensionsCpu<T extends texture3d>(texture: T, level: number): v3u;
export declare const textureDimensions: import("../types.ts").DualFn<typeof textureDimensionsCpu>;
type Gather2dArgs<T extends texture2d = texture2d> = [
component: number,
texture: T,
sampler: sampler,
coords: v2f,
offset?: v2i
];
type Gather2dArrayArgs<T extends texture2dArray = texture2dArray> = [
component: number,
texture: T,
sampler: sampler,
coords: v2f,
arrayIndex: number,
offset?: v2i
];
type GatherCubeArgs<T extends textureCube = textureCube> = [
component: number,
texture: T,
sampler: sampler,
coords: v3f
];
type GatherCubeArrayArgs<T extends textureCubeArray = textureCubeArray> = [
component: number,
texture: T,
sampler: sampler,
coords: v3f,
arrayIndex: number
];
type GatherDepth2dArgs = [texture: textureDepth2d, sampler: sampler, coords: v2f, offset?: v2i];
type GatherDepth2dArrayArgs = [
texture: textureDepth2dArray,
sampler: sampler,
coords: v2f,
arrayIndex: number,
offset?: v2i
];
type GatherDepthCubeArgs = [texture: textureDepthCube, sampler: sampler, coords: v3f];
type GatherDepthCubeArrayArgs = [
texture: textureDepthCubeArray,
sampler: sampler,
coords: v3f,
arrayIndex: number
];
type TextureGatherCpuFn = {
<T extends texture2d>(...args: Gather2dArgs<T>): PrimitiveToLoadedType[T[typeof $internal]['type']];
<T extends texture2dArray>(...args: Gather2dArrayArgs<T>): PrimitiveToLoadedType[T[typeof $internal]['type']];
<T extends textureCube>(...args: GatherCubeArgs<T>): PrimitiveToLoadedType[T[typeof $internal]['type']];
<T extends textureCubeArray>(...args: GatherCubeArrayArgs<T>): PrimitiveToLoadedType[T[typeof $internal]['type']];
(...args: GatherDepth2dArgs): v4f;
(...args: GatherDepth2dArrayArgs): v4f;
(...args: GatherDepthCubeArgs): v4f;
(...args: GatherDepthCubeArrayArgs): v4f;
};
export declare const textureGatherCpu: TextureGatherCpuFn;
export declare const textureGather: import("../types.ts").DualFn<TextureGatherCpuFn>;
declare function textureSampleCompareCpu<T extends textureDepth2d>(texture: T, sampler: comparisonSampler, coords: v2f, depthRef: number): number;
declare function textureSampleCompareCpu<T extends textureDepth2d>(texture: T, sampler: comparisonSampler, coords: v2f, depthRef: number, offset: v2i): number;
declare function textureSampleCompareCpu<T extends textureDepth2dArray>(texture: T, sampler: comparisonSampler, coords: v2f, arrayIndex: number, depthRef: number): number;
declare function textureSampleCompareCpu<T extends textureDepth2dArray>(texture: T, sampler: comparisonSampler, coords: v2f, arrayIndex: number, depthRef: number, offset: v2i): number;
declare function textureSampleCompareCpu<T extends textureDepthCube>(texture: T, sampler: comparisonSampler, coords: v3f, depthRef: number): number;
declare function textureSampleCompareCpu<T extends textureDepthCubeArray>(texture: T, sampler: comparisonSampler, coords: v3f, arrayIndex: number, depthRef: number): number;
export declare const textureSampleCompare: import("../types.ts").DualFn<typeof textureSampleCompareCpu>;
declare function textureSampleCompareLevelCpu<T extends textureDepth2d>(texture: T, sampler: comparisonSampler, coords: v2f, depthRef: number): number;
declare function textureSampleCompareLevelCpu<T extends textureDepth2d>(texture: T, sampler: comparisonSampler, coords: v2f, depthRef: number, offset: v2i): number;
declare function textureSampleCompareLevelCpu<T extends textureDepth2dArray>(texture: T, sampler: comparisonSampler, coords: v2f, arrayIndex: number, depthRef: number): number;
declare function textureSampleCompareLevelCpu<T extends textureDepth2dArray>(texture: T, sampler: comparisonSampler, coords: v2f, arrayIndex: number, depthRef: number, offset: v2i): number;
declare function textureSampleCompareLevelCpu<T extends textureDepthCube>(texture: T, sampler: comparisonSampler, coords: v3f, depthRef: number): number;
declare function textureSampleCompareLevelCpu<T extends textureDepthCubeArray>(texture: T, sampler: comparisonSampler, coords: v3f, arrayIndex: number, depthRef: number): number;
export declare const textureSampleCompareLevel: import("../types.ts").DualFn<typeof textureSampleCompareLevelCpu>;
declare function textureSampleBaseClampToEdgeCpu<T extends texture2d | textureExternal>(_texture: T, _sampler: sampler, _coords: v2f): v4f;
declare function sampleGradCpu<T extends texture2d>(texture: T, sampler: sampler, coords: v2f, ddx: v2f, ddy: v2f): v4f;
declare function sampleGradCpu<T extends texture2d>(texture: T, sampler: sampler, coords: v2f, ddx: v2f, ddy: v2f, offset: v2i): v4f;
declare function sampleGradCpu<T extends texture2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, ddx: v2f, ddy: v2f): v4f;
declare function sampleGradCpu<T extends texture2dArray>(texture: T, sampler: sampler, coords: v2f, arrayIndex: number, ddx: v2f, ddy: v2f, offset: v2i): v4f;
declare function sampleGradCpu<T extends texture3d>(texture: T, sampler: sampler, coords: v3f, ddx: v3f, ddy: v3f): v4f;
declare function sampleGradCpu<T extends texture3d>(texture: T, sampler: sampler, coords: v3f, ddx: v3f, ddy: v3f, offset: v3i): v4f;
declare function sampleGradCpu<T extends textureCube>(texture: T, sampler: sampler, coords: v3f, ddx: v3f, ddy: v3f): v4f;
declare function sampleGradCpu<T extends textureCubeArray>(texture: T, sampler: sampler, coords: v3f, arrayIndex: number, ddx: v3f, ddy: v3f): v4f;
export declare const textureSampleGrad: import("../types.ts").DualFn<typeof sampleGradCpu>;
export declare const textureSampleBaseClampToEdge: import("../types.ts").DualFn<typeof textureSampleBaseClampToEdgeCpu>;
export {};