typegpu 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{chunk-BYypO7fO.js → _virtual/_rolldown/runtime.js} +1 -1
- package/builtin.d.ts +50 -0
- package/builtin.js +37 -0
- package/common/fullScreenTriangle.d.ts +26 -0
- package/common/fullScreenTriangle.js +36 -0
- package/common/index.d.ts +2 -3
- package/common/index.js +3 -4
- package/core/buffer/buffer.d.ts +74 -0
- package/core/buffer/buffer.js +197 -0
- package/core/buffer/bufferShorthand.d.ts +48 -0
- package/core/buffer/bufferShorthand.js +49 -0
- package/core/buffer/bufferUsage.d.ts +45 -0
- package/core/buffer/bufferUsage.js +163 -0
- package/core/constant/tgpuConstant.d.ts +28 -0
- package/core/constant/tgpuConstant.js +67 -0
- package/core/declare/tgpuDeclare.d.ts +18 -0
- package/core/declare/tgpuDeclare.js +40 -0
- package/core/function/autoIO.d.ts +37 -0
- package/core/function/autoIO.js +87 -0
- package/core/function/comptime.d.ts +39 -0
- package/core/function/comptime.js +51 -0
- package/core/function/createCallableSchema.js +42 -0
- package/core/function/dualImpl.js +54 -0
- package/core/function/extractArgs.js +204 -0
- package/core/function/fnCore.js +79 -0
- package/core/function/fnTypes.d.ts +34 -0
- package/core/function/ioSchema.d.ts +10 -0
- package/core/function/ioSchema.js +30 -0
- package/core/function/shelllessImpl.d.ts +28 -0
- package/core/function/shelllessImpl.js +23 -0
- package/core/function/templateUtils.js +13 -0
- package/core/function/tgpuComputeFn.d.ts +49 -0
- package/core/function/tgpuComputeFn.js +62 -0
- package/core/function/tgpuFn.d.ts +52 -0
- package/core/function/tgpuFn.js +170 -0
- package/core/function/tgpuFragmentFn.d.ts +68 -0
- package/core/function/tgpuFragmentFn.js +68 -0
- package/core/function/tgpuVertexFn.d.ts +55 -0
- package/core/function/tgpuVertexFn.js +65 -0
- package/core/pipeline/applyPipelineState.js +37 -0
- package/core/pipeline/computePipeline.d.ts +58 -0
- package/core/pipeline/computePipeline.js +226 -0
- package/core/pipeline/connectAttachmentToShader.js +26 -0
- package/core/pipeline/connectTargetsToShader.js +29 -0
- package/core/pipeline/limitsOverflow.js +13 -0
- package/core/pipeline/renderPipeline.d.ts +266 -0
- package/core/pipeline/renderPipeline.js +471 -0
- package/core/pipeline/timeable.d.ts +23 -0
- package/core/pipeline/timeable.js +61 -0
- package/core/pipeline/typeGuards.js +29 -0
- package/core/querySet/querySet.d.ts +22 -0
- package/core/querySet/querySet.js +103 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +96 -0
- package/core/resolve/externals.d.ts +10 -0
- package/core/resolve/externals.js +58 -0
- package/core/resolve/namespace.d.ts +38 -0
- package/core/resolve/namespace.js +41 -0
- package/core/resolve/resolveData.js +146 -0
- package/core/resolve/stitch.js +25 -0
- package/core/resolve/tgpuResolve.d.ts +151 -0
- package/core/resolve/tgpuResolve.js +68 -0
- package/core/root/configurableImpl.js +18 -0
- package/core/root/init.d.ts +69 -0
- package/core/root/init.js +457 -0
- package/core/root/rootTypes.d.ts +622 -0
- package/core/sampler/sampler.d.ts +35 -0
- package/core/sampler/sampler.js +116 -0
- package/core/simulate/tgpuSimulate.d.ts +36 -0
- package/core/simulate/tgpuSimulate.js +76 -0
- package/core/slot/accessor.d.ts +13 -0
- package/core/slot/accessor.js +97 -0
- package/core/slot/internalSlots.js +7 -0
- package/core/slot/lazy.d.ts +6 -0
- package/core/slot/lazy.js +42 -0
- package/core/slot/slot.d.ts +6 -0
- package/core/slot/slot.js +40 -0
- package/core/slot/slotTypes.d.ts +92 -0
- package/core/slot/slotTypes.js +21 -0
- package/core/texture/externalTexture.d.ts +12 -0
- package/core/texture/externalTexture.js +48 -0
- package/core/texture/texture.d.ts +118 -0
- package/core/texture/texture.js +312 -0
- package/core/texture/textureFormats.d.ts +29 -0
- package/core/texture/textureFormats.js +99 -0
- package/core/texture/textureProps.d.ts +11 -0
- package/core/texture/textureUtils.js +224 -0
- package/core/texture/usageExtension.d.ts +21 -0
- package/core/texture/usageExtension.js +21 -0
- package/core/unroll/tgpuUnroll.d.ts +13 -0
- package/core/unroll/tgpuUnroll.js +36 -0
- package/core/valueProxyUtils.js +44 -0
- package/core/variable/tgpuVariable.d.ts +38 -0
- package/core/variable/tgpuVariable.js +101 -0
- package/core/vertexLayout/connectAttributesToShader.js +59 -0
- package/core/vertexLayout/vertexAttribute.d.ts +29 -0
- package/core/vertexLayout/vertexLayout.d.ts +19 -0
- package/core/vertexLayout/vertexLayout.js +103 -0
- package/data/alignIO.js +15 -0
- package/data/alignmentOf.d.ts +10 -0
- package/data/alignmentOf.js +88 -0
- package/data/array.d.ts +28 -0
- package/data/array.js +48 -0
- package/data/atomic.d.ts +15 -0
- package/data/atomic.js +25 -0
- package/data/attributes.d.ts +121 -0
- package/data/attributes.js +145 -0
- package/data/autoStruct.d.ts +3 -0
- package/data/autoStruct.js +83 -0
- package/data/compiledIO.js +231 -0
- package/data/dataIO.js +549 -0
- package/data/dataTypes.d.ts +115 -0
- package/data/dataTypes.js +97 -0
- package/data/deepEqual.d.ts +25 -0
- package/data/deepEqual.js +58 -0
- package/data/disarray.d.ts +34 -0
- package/data/disarray.js +52 -0
- package/data/getLongestContiguousPrefix.d.ts +10 -0
- package/data/getLongestContiguousPrefix.js +15 -0
- package/data/index.d.ts +26 -4
- package/data/index.js +27 -7
- package/data/instanceToSchema.d.ts +33 -0
- package/data/isContiguous.d.ts +10 -0
- package/data/isContiguous.js +15 -0
- package/data/matrix.d.ts +126 -0
- package/data/matrix.js +517 -0
- package/data/numberOps.js +24 -0
- package/data/numeric.d.ts +81 -0
- package/data/numeric.js +234 -0
- package/data/offsetUtils.d.ts +33 -0
- package/data/offsetUtils.js +167 -0
- package/data/offsets.js +36 -0
- package/data/partialIO.js +68 -0
- package/data/ptr.d.ts +12 -0
- package/data/ptr.js +46 -0
- package/data/ref.d.ts +37 -0
- package/data/ref.js +96 -0
- package/data/sampler.d.ts +107 -0
- package/data/sampler.js +26 -0
- package/data/schemaCallWrapper.js +32 -0
- package/data/schemaMemoryLayout.js +200 -0
- package/data/sizeOf.d.ts +10 -0
- package/data/sizeOf.js +15 -0
- package/data/snippet.d.ts +26 -0
- package/data/snippet.js +61 -0
- package/data/struct.d.ts +17 -0
- package/data/struct.js +46 -0
- package/data/texture.d.ts +292 -0
- package/{texture-BagDrrks.js → data/texture.js} +6 -3
- package/data/unstruct.d.ts +24 -0
- package/data/unstruct.js +43 -0
- package/data/vector.d.ts +191 -0
- package/data/vector.js +247 -0
- package/data/vectorImpl.js +516 -0
- package/data/vectorOps.js +664 -0
- package/data/vertexFormatData.d.ts +190 -0
- package/data/vertexFormatData.js +110 -0
- package/data/wgslTypes.d.ts +896 -0
- package/data/wgslTypes.js +215 -0
- package/errors.d.ts +44 -0
- package/errors.js +128 -0
- package/execMode.js +51 -0
- package/extension.d.ts +11 -0
- package/extension.js +18 -0
- package/getGPUValue.js +9 -0
- package/index.d.ts +40 -243
- package/index.js +19 -6318
- package/indexNamedExports.d.ts +38 -0
- package/mathUtils.js +13 -0
- package/memo.js +22 -0
- package/nameRegistry.d.ts +30 -0
- package/nameRegistry.js +449 -0
- package/package.js +5 -0
- package/package.json +23 -23
- package/resolutionCtx.d.ts +29 -0
- package/resolutionCtx.js +546 -0
- package/shared/env.js +13 -0
- package/shared/generators.js +14 -0
- package/shared/meta.d.ts +39 -0
- package/shared/meta.js +63 -0
- package/shared/repr.d.ts +108 -0
- package/shared/stringify.js +22 -0
- package/shared/symbols.d.ts +61 -0
- package/shared/symbols.js +71 -0
- package/shared/utilityTypes.d.ts +29 -0
- package/shared/utilityTypes.js +7 -0
- package/shared/vertexFormat.d.ts +70 -0
- package/shared/vertexFormat.js +64 -0
- package/std/array.d.ts +7 -0
- package/std/array.js +27 -0
- package/std/atomic.d.ts +19 -0
- package/std/atomic.js +113 -0
- package/std/bitcast.d.ts +10 -0
- package/std/bitcast.js +43 -0
- package/std/boolean.d.ts +127 -0
- package/std/boolean.js +274 -0
- package/std/derivative.d.ts +16 -0
- package/std/derivative.js +89 -0
- package/std/discard.d.ts +6 -0
- package/std/discard.js +16 -0
- package/std/extensions.d.ts +8 -0
- package/std/extensions.js +14 -0
- package/std/index.d.ts +15 -3
- package/std/index.js +16 -5
- package/std/matrix.d.ts +41 -0
- package/std/matrix.js +87 -0
- package/std/numeric.d.ts +254 -0
- package/std/numeric.js +847 -0
- package/std/operators.d.ts +48 -0
- package/std/operators.js +153 -0
- package/std/packing.d.ts +26 -0
- package/std/packing.js +86 -0
- package/std/subgroup.d.ts +47 -0
- package/std/subgroup.js +220 -0
- package/std/texture.d.ts +108 -0
- package/std/texture.js +197 -0
- package/tgpu.js +44 -0
- package/tgpuBindGroupLayout.d.ts +161 -0
- package/tgpuBindGroupLayout.js +271 -0
- package/tgpuUnstable.d.ts +48 -0
- package/tgpuUnstable.js +66 -0
- package/tgsl/accessIndex.js +45 -0
- package/tgsl/accessProp.js +113 -0
- package/tgsl/consoleLog/deserializers.js +117 -0
- package/tgsl/consoleLog/logGenerator.js +86 -0
- package/tgsl/consoleLog/serializers.js +225 -0
- package/tgsl/consoleLog/types.d.ts +54 -0
- package/tgsl/consoleLog/types.js +12 -0
- package/tgsl/conversion.js +200 -0
- package/tgsl/forOfUtils.js +45 -0
- package/tgsl/generationHelpers.d.ts +37 -0
- package/tgsl/generationHelpers.js +67 -0
- package/tgsl/math.js +45 -0
- package/tgsl/shaderGenerator.d.ts +18 -0
- package/tgsl/shellless.d.ts +11 -0
- package/tgsl/shellless.js +53 -0
- package/tgsl/wgslGenerator.js +585 -0
- package/types.d.ts +255 -0
- package/types.js +43 -0
- package/unwrapper.d.ts +27 -0
- package/wgslExtensions.d.ts +5 -0
- package/wgslExtensions.js +18 -0
- package/builtin-DdtWpk2t.js +0 -818
- package/builtin-DdtWpk2t.js.map +0 -1
- package/common/index.d.ts.map +0 -1
- package/common/index.js.map +0 -1
- package/data/index.d.ts.map +0 -1
- package/data/index.js.map +0 -1
- package/deepEqual-DQxK4vdp.js +0 -413
- package/deepEqual-DQxK4vdp.js.map +0 -1
- package/extensions-DIVuAfBM.js +0 -2032
- package/extensions-DIVuAfBM.js.map +0 -1
- package/fullScreenTriangle-CfFyQd_0.js +0 -543
- package/fullScreenTriangle-CfFyQd_0.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexNamedExports-oL6tyaJ9.d.ts +0 -5697
- package/indexNamedExports-oL6tyaJ9.d.ts.map +0 -1
- package/operators-d-PMVTo7.js +0 -4158
- package/operators-d-PMVTo7.js.map +0 -1
- package/std/index.d.ts.map +0 -1
- package/std/index.js.map +0 -1
- package/texture-BagDrrks.js.map +0 -1
package/shared/repr.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { $gpuRepr, $gpuValueOf, $invalidSchemaReason, $memIdent, $repr, $reprPartial, $validStorageSchema, $validUniformSchema, $validVertexSchema } from "./symbols.js";
|
|
2
|
+
import { Default } from "./utilityTypes.js";
|
|
3
|
+
import { U16, U32, WgslArray } from "../data/wgslTypes.js";
|
|
4
|
+
import { ViewDimensionToDimension } from "../core/texture/textureFormats.js";
|
|
5
|
+
import { WgslStorageTexture, WgslTexture } from "../data/texture.js";
|
|
6
|
+
import { TgpuTexture } from "../core/texture/texture.js";
|
|
7
|
+
import { Disarray, Undecorate } from "../data/dataTypes.js";
|
|
8
|
+
|
|
9
|
+
//#region src/shared/repr.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Extracts the inferred representation of a resource.
|
|
12
|
+
* For inferring types as seen by the GPU, see {@link InferGPU}
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* type A = Infer<F32> // => number
|
|
16
|
+
* type B = Infer<WgslArray<F32>> // => number[]
|
|
17
|
+
* type C = Infer<Atomic<U32>> // => number
|
|
18
|
+
*/
|
|
19
|
+
type Infer<T> = T extends {
|
|
20
|
+
readonly [$repr]: infer TRepr;
|
|
21
|
+
} ? TRepr : T;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts a sparse/partial inferred representation of a resource.
|
|
24
|
+
* Used by the `buffer.writePartial` API.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* type A = InferPartial<F32> // => number | undefined
|
|
28
|
+
* type B = InferPartial<WgslStruct<{ a: F32 }>> // => { a?: number | undefined }
|
|
29
|
+
* type C = InferPartial<WgslArray<F32>> // => { idx: number; value: number | undefined }[] | undefined
|
|
30
|
+
*/
|
|
31
|
+
type InferPartial<T> = T extends {
|
|
32
|
+
readonly [$reprPartial]: infer TRepr;
|
|
33
|
+
} ? TRepr : T extends {
|
|
34
|
+
readonly [$repr]: infer TRepr;
|
|
35
|
+
} ? TRepr | undefined : T;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts the inferred representation of a resource (as seen by the GPU).
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* type A = InferGPU<F32> // => number
|
|
41
|
+
* type B = InferGPU<WgslArray<F32>> // => number[]
|
|
42
|
+
* type C = InferGPU<Atomic<U32>> // => atomicU32
|
|
43
|
+
*/
|
|
44
|
+
type InferGPU<T> = T extends {
|
|
45
|
+
readonly [$gpuRepr]: infer TRepr;
|
|
46
|
+
} ? TRepr : Infer<T>;
|
|
47
|
+
type InferRecord<T extends Record<string | number | symbol, unknown>> = { [Key in keyof T]: Infer<T[Key]> };
|
|
48
|
+
type InferPartialRecord<T extends Record<string | number | symbol, unknown>> = { [Key in keyof T]?: InferPartial<T[Key]> };
|
|
49
|
+
type InferGPURecord<T extends Record<string | number | symbol, unknown>> = { [Key in keyof T]: InferGPU<T[Key]> };
|
|
50
|
+
type GPUValueOf<T> = T extends {
|
|
51
|
+
readonly [$gpuValueOf]: infer TValue;
|
|
52
|
+
} ? TValue : T;
|
|
53
|
+
type MemIdentity<T> = T extends {
|
|
54
|
+
readonly [$memIdent]: infer TMemIdent;
|
|
55
|
+
} ? TMemIdent : T;
|
|
56
|
+
type MemIdentityRecord<T extends Record<string | number | symbol, unknown>> = { [Key in keyof T]: MemIdentity<T[Key]> };
|
|
57
|
+
type IsValidStorageSchema<T> = (T extends {
|
|
58
|
+
readonly [$validStorageSchema]: true;
|
|
59
|
+
} ? true : false) extends false ? false : true;
|
|
60
|
+
type IsValidUniformSchema<T> = (T extends {
|
|
61
|
+
readonly [$validUniformSchema]: true;
|
|
62
|
+
} ? true : false) extends false ? false : true;
|
|
63
|
+
type IsValidVertexSchema<T> = (T extends {
|
|
64
|
+
readonly [$validVertexSchema]: true;
|
|
65
|
+
} ? true : false) extends false ? false : true;
|
|
66
|
+
/**
|
|
67
|
+
* Accepts only arrays (or disarrays) of u32 or u16.
|
|
68
|
+
*/
|
|
69
|
+
type IsValidIndexSchema<T> = Undecorate<T> extends WgslArray | Disarray ? Undecorate<Undecorate<T>['elementType']> extends U32 | U16 ? true : false : false;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a schema can be used in a buffer at all
|
|
72
|
+
*/
|
|
73
|
+
type IsValidBufferSchema<T> = IsValidStorageSchema<T> | IsValidUniformSchema<T> | IsValidVertexSchema<T> | IsValidIndexSchema<T> extends false ? false : true;
|
|
74
|
+
/**
|
|
75
|
+
* Validates if a texture can be used as sampled texture
|
|
76
|
+
*/
|
|
77
|
+
type IsValidSampledTextureUsage<TTexture extends TgpuTexture> = TTexture['usableAsSampled'] extends true ? true : {
|
|
78
|
+
readonly invalidSampled: "Texture not usable as sampled, call $usage('sampled') first";
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Validates if a texture can be used as storage texture
|
|
82
|
+
*/
|
|
83
|
+
type IsValidStorageTextureUsage<TTexture extends TgpuTexture> = TTexture['usableAsStorage'] extends true ? true : {
|
|
84
|
+
readonly invalidStorage: "Texture not usable as storage, call $usage('storage') first";
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Validates if a texture view dimension is compatible with the texture dimension
|
|
88
|
+
*/
|
|
89
|
+
type IsValidSubdimension<TTexture extends TgpuTexture, TSchema extends WgslTexture | WgslStorageTexture> = ViewDimensionToDimension[TSchema['dimension']] extends infer TVDim ? TVDim extends Default<TTexture['props']['dimension'], '2d'> ? true : {
|
|
90
|
+
readonly invalidViewDim: `Texture dimension '${Default<TTexture['props']['dimension'], '2d'>}' incompatible with view dimension '${TSchema['dimension']}'`;
|
|
91
|
+
} : never;
|
|
92
|
+
type IsValidStorageFormat<TTexture extends TgpuTexture, TSchema extends WgslStorageTexture> = TSchema['format'] extends TTexture['props']['format'] ? true : TTexture['props']['viewFormats'] extends readonly unknown[] ? TSchema['format'] extends TTexture['props']['viewFormats'][number] ? true : FormatError<TSchema, TTexture> : FormatError<TSchema, TTexture>;
|
|
93
|
+
type FormatError<TSchema extends WgslStorageTexture, TTexture extends TgpuTexture> = {
|
|
94
|
+
readonly invalidFormat: `Storage texture format '${TSchema['format']}' incompatible with texture format '${TTexture['props']['format']}'`;
|
|
95
|
+
};
|
|
96
|
+
type IsExactly<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
|
|
97
|
+
type SelfOrErrors<TSelf, T> = IsExactly<T, true> extends true ? TSelf : `(Error) ${T[Extract<keyof T, `invalid${string}`>] & string}`;
|
|
98
|
+
type ValidStorageUsage<TTexture extends TgpuTexture, TSchema extends WgslStorageTexture> = IsValidStorageTextureUsage<TTexture> & IsValidSubdimension<TTexture, TSchema> & IsValidStorageFormat<TTexture, TSchema>;
|
|
99
|
+
type ValidSampledUsage<TTexture extends TgpuTexture, TSchema extends WgslTexture> = IsValidSampledTextureUsage<TTexture> & IsValidSubdimension<TTexture, TSchema>;
|
|
100
|
+
/**
|
|
101
|
+
* Validates texture view schema against texture usage
|
|
102
|
+
*/
|
|
103
|
+
type ValidateTextureViewSchema<TTexture extends TgpuTexture, TSchema extends WgslTexture | WgslStorageTexture> = TSchema extends WgslStorageTexture ? SelfOrErrors<TSchema, ValidStorageUsage<TTexture, TSchema>> : TSchema extends WgslTexture ? SelfOrErrors<TSchema, ValidSampledUsage<TTexture, TSchema>> : never;
|
|
104
|
+
type ExtractInvalidSchemaError<T, TPrefix extends string = ''> = [T] extends [{
|
|
105
|
+
readonly [$invalidSchemaReason]: string;
|
|
106
|
+
}] ? `${TPrefix}${T[typeof $invalidSchemaReason]}` : never;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { ExtractInvalidSchemaError, GPUValueOf, Infer, InferGPU, InferGPURecord, InferPartial, InferPartialRecord, InferRecord, IsValidBufferSchema, IsValidIndexSchema, IsValidStorageSchema, IsValidUniformSchema, IsValidVertexSchema, MemIdentity, MemIdentityRecord, ValidateTextureViewSchema };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isMatInstance, isVecInstance } from "../data/wgslTypes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/stringify.ts
|
|
4
|
+
function safeStringify(item) {
|
|
5
|
+
const asString = String(item);
|
|
6
|
+
if (asString !== "[object Object]") return asString;
|
|
7
|
+
try {
|
|
8
|
+
return JSON.stringify(item);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.error("Error parsing JSON:", error);
|
|
11
|
+
return "<invalid json>";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function niceStringify(item) {
|
|
15
|
+
if (isVecInstance(item) || isMatInstance(item)) return item.toString();
|
|
16
|
+
if (Array.isArray(item)) return `[${item.map(niceStringify).join(", ")}]`;
|
|
17
|
+
if (item && typeof item === "object") return `{ ${Object.entries(item).map(([key, value]) => `${key}: ${niceStringify(value)}`).join(", ")} }`;
|
|
18
|
+
return String(item);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { niceStringify, safeStringify };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//#region src/shared/symbols.d.ts
|
|
2
|
+
declare const $internal: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* The getter to the value of this resource, accessible on the GPU
|
|
5
|
+
*/
|
|
6
|
+
declare const $gpuValueOf: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* If this symbol is present, this means that getName and setName
|
|
9
|
+
* will refer to object behind this property instead.
|
|
10
|
+
*/
|
|
11
|
+
declare const $getNameForward: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* Marks an object with slot-value bindings
|
|
14
|
+
*/
|
|
15
|
+
declare const $providing: unique symbol;
|
|
16
|
+
declare const $resolve: unique symbol;
|
|
17
|
+
/**
|
|
18
|
+
* A way for a schema to provide casting behavior, without the need to be explicitly
|
|
19
|
+
* callable by the end-user (e.g. vertex formats)
|
|
20
|
+
*/
|
|
21
|
+
declare const $cast: unique symbol;
|
|
22
|
+
/**
|
|
23
|
+
* Can be called on the GPU
|
|
24
|
+
*/
|
|
25
|
+
declare const $gpuCallable: unique symbol;
|
|
26
|
+
/**
|
|
27
|
+
* Type token for the inferred (CPU & GPU) representation of a resource
|
|
28
|
+
*/
|
|
29
|
+
declare const $repr: unique symbol;
|
|
30
|
+
/**
|
|
31
|
+
* Type token for the inferred (GPU-side) representation of a resource
|
|
32
|
+
* If present, it shadows the value of `$repr` for GPU-side inference.
|
|
33
|
+
*/
|
|
34
|
+
declare const $gpuRepr: unique symbol;
|
|
35
|
+
/**
|
|
36
|
+
* Type token for the inferred partial representation of a resource.
|
|
37
|
+
* If present, it shadows the value of `$repr` for use in partial IO.
|
|
38
|
+
*/
|
|
39
|
+
declare const $reprPartial: unique symbol;
|
|
40
|
+
/**
|
|
41
|
+
* Type token holding schemas that are identical in memory layout.
|
|
42
|
+
*/
|
|
43
|
+
declare const $memIdent: unique symbol;
|
|
44
|
+
/**
|
|
45
|
+
* Type token, signaling that a schema can be used in a storage buffer.
|
|
46
|
+
*/
|
|
47
|
+
declare const $validStorageSchema: unique symbol;
|
|
48
|
+
/**
|
|
49
|
+
* Type token, signaling that a schema can be used in a uniform buffer.
|
|
50
|
+
*/
|
|
51
|
+
declare const $validUniformSchema: unique symbol;
|
|
52
|
+
/**
|
|
53
|
+
* Type token, signaling that a schema can be used in a vertex buffer.
|
|
54
|
+
*/
|
|
55
|
+
declare const $validVertexSchema: unique symbol;
|
|
56
|
+
/**
|
|
57
|
+
* Type token, containing a reason for why the schema is invalid (if it is).
|
|
58
|
+
*/
|
|
59
|
+
declare const $invalidSchemaReason: unique symbol;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { $cast, $getNameForward, $gpuCallable, $gpuRepr, $gpuValueOf, $internal, $invalidSchemaReason, $memIdent, $providing, $repr, $reprPartial, $resolve, $validStorageSchema, $validUniformSchema, $validVertexSchema };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { version } from "../package.js";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/symbols.ts
|
|
4
|
+
const $internal = Symbol(`typegpu:${version}:$internal`);
|
|
5
|
+
/**
|
|
6
|
+
* The getter to the value of this resource, accessible on the GPU
|
|
7
|
+
*/
|
|
8
|
+
const $gpuValueOf = Symbol(`typegpu:${version}:$gpuValueOf`);
|
|
9
|
+
/**
|
|
10
|
+
* If this symbol is present, this means that getName and setName
|
|
11
|
+
* will refer to object behind this property instead.
|
|
12
|
+
*/
|
|
13
|
+
const $getNameForward = Symbol(`typegpu:${version}:$getNameForward`);
|
|
14
|
+
/**
|
|
15
|
+
* Marks an object with slot-value bindings
|
|
16
|
+
*/
|
|
17
|
+
const $providing = Symbol(`typegpu:${version}:$providing`);
|
|
18
|
+
/**
|
|
19
|
+
* Objects can provide the snippet that represents them.
|
|
20
|
+
*/
|
|
21
|
+
const $ownSnippet = Symbol(`typegpu:${version}:$ownSnippet`);
|
|
22
|
+
const $resolve = Symbol(`typegpu:${version}:$resolve`);
|
|
23
|
+
/**
|
|
24
|
+
* A way for a schema to provide casting behavior, without the need to be explicitly
|
|
25
|
+
* callable by the end-user (e.g. vertex formats)
|
|
26
|
+
*/
|
|
27
|
+
const $cast = Symbol(`typegpu:${version}:$cast`);
|
|
28
|
+
/**
|
|
29
|
+
* Can be called on the GPU
|
|
30
|
+
*/
|
|
31
|
+
const $gpuCallable = Symbol(`typegpu:${version}:$gpuCallable`);
|
|
32
|
+
/**
|
|
33
|
+
* Type token for the inferred (CPU & GPU) representation of a resource
|
|
34
|
+
*/
|
|
35
|
+
const $repr = Symbol(`typegpu:${version}:$repr`);
|
|
36
|
+
/**
|
|
37
|
+
* Type token for the inferred (GPU-side) representation of a resource
|
|
38
|
+
* If present, it shadows the value of `$repr` for GPU-side inference.
|
|
39
|
+
*/
|
|
40
|
+
const $gpuRepr = Symbol(`typegpu:${version}:$gpuRepr`);
|
|
41
|
+
/**
|
|
42
|
+
* Type token for the inferred partial representation of a resource.
|
|
43
|
+
* If present, it shadows the value of `$repr` for use in partial IO.
|
|
44
|
+
*/
|
|
45
|
+
const $reprPartial = Symbol(`typegpu:${version}:$reprPartial`);
|
|
46
|
+
/**
|
|
47
|
+
* Type token holding schemas that are identical in memory layout.
|
|
48
|
+
*/
|
|
49
|
+
const $memIdent = Symbol(`typegpu:${version}:$memIdent`);
|
|
50
|
+
/**
|
|
51
|
+
* Type token, signaling that a schema can be used in a storage buffer.
|
|
52
|
+
*/
|
|
53
|
+
const $validStorageSchema = Symbol(`typegpu:${version}:$invalidStorageSchema`);
|
|
54
|
+
/**
|
|
55
|
+
* Type token, signaling that a schema can be used in a uniform buffer.
|
|
56
|
+
*/
|
|
57
|
+
const $validUniformSchema = Symbol(`typegpu:${version}:$validUniformSchema`);
|
|
58
|
+
/**
|
|
59
|
+
* Type token, signaling that a schema can be used in a vertex buffer.
|
|
60
|
+
*/
|
|
61
|
+
const $validVertexSchema = Symbol(`typegpu:${version}:$validVertexSchema`);
|
|
62
|
+
/**
|
|
63
|
+
* Type token, containing a reason for why the schema is invalid (if it is).
|
|
64
|
+
*/
|
|
65
|
+
const $invalidSchemaReason = Symbol(`typegpu:${version}:$invalidSchemaReason`);
|
|
66
|
+
function isMarkedInternal(value) {
|
|
67
|
+
return !!value?.[$internal];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { $cast, $getNameForward, $gpuCallable, $gpuValueOf, $internal, $ownSnippet, $providing, $repr, $resolve, isMarkedInternal };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/shared/utilityTypes.d.ts
|
|
2
|
+
type Default<T, TDefault> = unknown extends T ? TDefault : T extends undefined ? TDefault : T;
|
|
3
|
+
type SwapNever<T, Replacement> = [T] extends [never] ? Replacement : T;
|
|
4
|
+
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
5
|
+
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
6
|
+
/**
|
|
7
|
+
* Utility type that merges a partial type with defaults, where defaults are used
|
|
8
|
+
* for properties not present in the partial type.
|
|
9
|
+
*/
|
|
10
|
+
type WithDefaults<TPartial, TDefaults> = Omit<TDefaults, keyof TPartial> & TPartial;
|
|
11
|
+
/**
|
|
12
|
+
* Removes properties from record type that extend `Prop`
|
|
13
|
+
*/
|
|
14
|
+
type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, { [Key in keyof T]: T[Key] extends Prop ? never : Key }[keyof T]>;
|
|
15
|
+
type NullableToOptional<T> = { [K in keyof T as T[K] extends null ? K : never]?: T[K] } & { [K in keyof T as T[K] extends null ? never : K]: T[K] };
|
|
16
|
+
/**
|
|
17
|
+
* The opposite of Readonly<T>
|
|
18
|
+
*/
|
|
19
|
+
type Mutable<T> = { -readonly [P in keyof T]: T[P] };
|
|
20
|
+
/**
|
|
21
|
+
* Source: https://code.lol/post/programming/higher-kinded-types/
|
|
22
|
+
*/
|
|
23
|
+
type Assume<T, U> = T extends U ? T : U;
|
|
24
|
+
/**
|
|
25
|
+
* Any typed array
|
|
26
|
+
*/
|
|
27
|
+
type TypedArray = Uint8Array | Uint16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Assume, Default, Mutable, NullableToOptional, OmitProps, Prettify, SwapNever, TypedArray, UnionToIntersection, WithDefaults };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/shared/vertexFormat.d.ts
|
|
2
|
+
declare const vertexFormats: readonly ["uint8", "uint8x2", "uint8x4", "sint8", "sint8x2", "sint8x4", "unorm8", "unorm8x2", "unorm8x4", "snorm8", "snorm8x2", "snorm8x4", "uint16", "uint16x2", "uint16x4", "sint16", "sint16x2", "sint16x4", "unorm16", "unorm16x2", "unorm16x4", "snorm16", "snorm16x2", "snorm16x4", "float16", "float16x2", "float16x4", "float32", "float32x2", "float32x3", "float32x4", "uint32", "uint32x2", "uint32x3", "uint32x4", "sint32", "sint32x2", "sint32x3", "sint32x4", "unorm10-10-10-2", "unorm8x4-bgra"];
|
|
3
|
+
type VertexFormat = (typeof vertexFormats)[number];
|
|
4
|
+
declare const kindToDefaultFormatMap: {
|
|
5
|
+
readonly f32: "float32";
|
|
6
|
+
readonly vec2f: "float32x2";
|
|
7
|
+
readonly vec3f: "float32x3";
|
|
8
|
+
readonly vec4f: "float32x4";
|
|
9
|
+
readonly f16: "float16";
|
|
10
|
+
readonly vec2h: "float16x2";
|
|
11
|
+
readonly vec4h: "float16x4";
|
|
12
|
+
readonly u32: "uint32";
|
|
13
|
+
readonly vec2u: "uint32x2";
|
|
14
|
+
readonly vec3u: "uint32x3";
|
|
15
|
+
readonly vec4u: "uint32x4";
|
|
16
|
+
readonly i32: "sint32";
|
|
17
|
+
readonly vec2i: "sint32x2";
|
|
18
|
+
readonly vec3i: "sint32x3";
|
|
19
|
+
readonly vec4i: "sint32x4";
|
|
20
|
+
};
|
|
21
|
+
type KindToDefaultFormatMap = typeof kindToDefaultFormatMap;
|
|
22
|
+
interface TgpuVertexAttrib<TFormat extends VertexFormat = VertexFormat> {
|
|
23
|
+
readonly format: TFormat;
|
|
24
|
+
readonly offset: number;
|
|
25
|
+
}
|
|
26
|
+
type AnyVertexAttribs = Record<string, TgpuVertexAttrib> | TgpuVertexAttrib;
|
|
27
|
+
/**
|
|
28
|
+
* All vertex attribute formats that can be interpreted as
|
|
29
|
+
* an single or multi component u32 in a shader.
|
|
30
|
+
* https://www.w3.org/TR/webgpu/#vertex-formats
|
|
31
|
+
*/
|
|
32
|
+
type U32CompatibleFormats = TgpuVertexAttrib<'uint8'> | TgpuVertexAttrib<'uint8x2'> | TgpuVertexAttrib<'uint8x4'> | TgpuVertexAttrib<'uint16'> | TgpuVertexAttrib<'uint16x2'> | TgpuVertexAttrib<'uint16x4'> | TgpuVertexAttrib<'uint32'> | TgpuVertexAttrib<'uint32x2'> | TgpuVertexAttrib<'uint32x3'> | TgpuVertexAttrib<'uint32x4'>;
|
|
33
|
+
/**
|
|
34
|
+
* All vertex attribute formats that can be interpreted as
|
|
35
|
+
* an single or multi component i32 in a shader.
|
|
36
|
+
* https://www.w3.org/TR/webgpu/#vertex-formats
|
|
37
|
+
*/
|
|
38
|
+
type I32CompatibleFormats = TgpuVertexAttrib<'sint8'> | TgpuVertexAttrib<'sint8x2'> | TgpuVertexAttrib<'sint8x4'> | TgpuVertexAttrib<'sint16'> | TgpuVertexAttrib<'sint16x2'> | TgpuVertexAttrib<'sint16x4'> | TgpuVertexAttrib<'sint32'> | TgpuVertexAttrib<'sint32x2'> | TgpuVertexAttrib<'sint32x3'> | TgpuVertexAttrib<'sint32x4'>;
|
|
39
|
+
/**
|
|
40
|
+
* All vertex attribute formats that can be interpreted as
|
|
41
|
+
* an single or multi component f32 in a shader.
|
|
42
|
+
* https://www.w3.org/TR/webgpu/#vertex-formats
|
|
43
|
+
*/
|
|
44
|
+
type F32CompatibleFormats = TgpuVertexAttrib<'unorm8'> | TgpuVertexAttrib<'unorm8x2'> | TgpuVertexAttrib<'unorm8x4'> | TgpuVertexAttrib<'snorm8'> | TgpuVertexAttrib<'snorm8x2'> | TgpuVertexAttrib<'snorm8x4'> | TgpuVertexAttrib<'unorm16'> | TgpuVertexAttrib<'unorm16x2'> | TgpuVertexAttrib<'unorm16x4'> | TgpuVertexAttrib<'snorm16'> | TgpuVertexAttrib<'snorm16x2'> | TgpuVertexAttrib<'snorm16x4'> | TgpuVertexAttrib<'float16'> | TgpuVertexAttrib<'float16x2'> | TgpuVertexAttrib<'float16x4'> | TgpuVertexAttrib<'float32'> | TgpuVertexAttrib<'float32x2'> | TgpuVertexAttrib<'float32x3'> | TgpuVertexAttrib<'float32x4'> | TgpuVertexAttrib<'unorm10-10-10-2'> | TgpuVertexAttrib<'unorm8x4-bgra'>;
|
|
45
|
+
/**
|
|
46
|
+
* All vertex attribute formats that can be interpreted as
|
|
47
|
+
* a single or multi component f16 in a shader. (same as f32 on the shader side)
|
|
48
|
+
* https://www.w3.org/TR/webgpu/#vertex-formats
|
|
49
|
+
*/
|
|
50
|
+
type F16CompatibleFormats = F32CompatibleFormats;
|
|
51
|
+
type KindToAcceptedAttribMap = {
|
|
52
|
+
u32: U32CompatibleFormats;
|
|
53
|
+
vec2u: U32CompatibleFormats;
|
|
54
|
+
vec3u: U32CompatibleFormats;
|
|
55
|
+
vec4u: U32CompatibleFormats;
|
|
56
|
+
i32: I32CompatibleFormats;
|
|
57
|
+
vec2i: I32CompatibleFormats;
|
|
58
|
+
vec3i: I32CompatibleFormats;
|
|
59
|
+
vec4i: I32CompatibleFormats;
|
|
60
|
+
f16: F16CompatibleFormats;
|
|
61
|
+
vec2h: F16CompatibleFormats;
|
|
62
|
+
vec3h: F16CompatibleFormats;
|
|
63
|
+
vec4h: F16CompatibleFormats;
|
|
64
|
+
f32: F32CompatibleFormats;
|
|
65
|
+
vec2f: F32CompatibleFormats;
|
|
66
|
+
vec3f: F32CompatibleFormats;
|
|
67
|
+
vec4f: F32CompatibleFormats;
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
export { AnyVertexAttribs, KindToAcceptedAttribMap, KindToDefaultFormatMap, TgpuVertexAttrib, VertexFormat };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/shared/vertexFormat.ts
|
|
2
|
+
const vertexFormats = [
|
|
3
|
+
"uint8",
|
|
4
|
+
"uint8x2",
|
|
5
|
+
"uint8x4",
|
|
6
|
+
"sint8",
|
|
7
|
+
"sint8x2",
|
|
8
|
+
"sint8x4",
|
|
9
|
+
"unorm8",
|
|
10
|
+
"unorm8x2",
|
|
11
|
+
"unorm8x4",
|
|
12
|
+
"snorm8",
|
|
13
|
+
"snorm8x2",
|
|
14
|
+
"snorm8x4",
|
|
15
|
+
"uint16",
|
|
16
|
+
"uint16x2",
|
|
17
|
+
"uint16x4",
|
|
18
|
+
"sint16",
|
|
19
|
+
"sint16x2",
|
|
20
|
+
"sint16x4",
|
|
21
|
+
"unorm16",
|
|
22
|
+
"unorm16x2",
|
|
23
|
+
"unorm16x4",
|
|
24
|
+
"snorm16",
|
|
25
|
+
"snorm16x2",
|
|
26
|
+
"snorm16x4",
|
|
27
|
+
"float16",
|
|
28
|
+
"float16x2",
|
|
29
|
+
"float16x4",
|
|
30
|
+
"float32",
|
|
31
|
+
"float32x2",
|
|
32
|
+
"float32x3",
|
|
33
|
+
"float32x4",
|
|
34
|
+
"uint32",
|
|
35
|
+
"uint32x2",
|
|
36
|
+
"uint32x3",
|
|
37
|
+
"uint32x4",
|
|
38
|
+
"sint32",
|
|
39
|
+
"sint32x2",
|
|
40
|
+
"sint32x3",
|
|
41
|
+
"sint32x4",
|
|
42
|
+
"unorm10-10-10-2",
|
|
43
|
+
"unorm8x4-bgra"
|
|
44
|
+
];
|
|
45
|
+
const kindToDefaultFormatMap = {
|
|
46
|
+
f32: "float32",
|
|
47
|
+
vec2f: "float32x2",
|
|
48
|
+
vec3f: "float32x3",
|
|
49
|
+
vec4f: "float32x4",
|
|
50
|
+
f16: "float16",
|
|
51
|
+
vec2h: "float16x2",
|
|
52
|
+
vec4h: "float16x4",
|
|
53
|
+
u32: "uint32",
|
|
54
|
+
vec2u: "uint32x2",
|
|
55
|
+
vec3u: "uint32x3",
|
|
56
|
+
vec4u: "uint32x4",
|
|
57
|
+
i32: "sint32",
|
|
58
|
+
vec2i: "sint32x2",
|
|
59
|
+
vec3i: "sint32x3",
|
|
60
|
+
vec4i: "sint32x4"
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { kindToDefaultFormatMap, vertexFormats };
|
package/std/array.d.ts
ADDED
package/std/array.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isPtr, isWgslArray } from "../data/wgslTypes.js";
|
|
2
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
3
|
+
import { ptrFn } from "../data/ptr.js";
|
|
4
|
+
import { isRef } from "../data/ref.js";
|
|
5
|
+
import { abstractInt, u32 } from "../data/numeric.js";
|
|
6
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
7
|
+
|
|
8
|
+
//#region src/std/array.ts
|
|
9
|
+
const sizeOfPointedToArray = (dataType) => isPtr(dataType) && isWgslArray(dataType.inner) ? dataType.inner.elementCount : 0;
|
|
10
|
+
const arrayLength = dualImpl({
|
|
11
|
+
name: "arrayLength",
|
|
12
|
+
signature: (arg) => {
|
|
13
|
+
const ptrArg = isPtr(arg) ? arg : ptrFn(arg);
|
|
14
|
+
return {
|
|
15
|
+
argTypes: [ptrArg],
|
|
16
|
+
returnType: sizeOfPointedToArray(ptrArg) > 0 ? abstractInt : u32
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
normalImpl: (a) => isRef(a) ? a.$.length : a.length,
|
|
20
|
+
codegenImpl(_ctx, [a]) {
|
|
21
|
+
const length = sizeOfPointedToArray(a.dataType);
|
|
22
|
+
return length > 0 ? `${length}` : stitch`arrayLength(${a})`;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { arrayLength };
|
package/std/atomic.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DualFn } from "../types.js";
|
|
2
|
+
import { atomicI32, atomicU32 } from "../data/wgslTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/atomic.d.ts
|
|
5
|
+
type AnyAtomic = atomicI32 | atomicU32;
|
|
6
|
+
declare const workgroupBarrier: DualFn<(...args: never[]) => unknown>;
|
|
7
|
+
declare const storageBarrier: DualFn<(...args: never[]) => unknown>;
|
|
8
|
+
declare const textureBarrier: DualFn<(...args: never[]) => unknown>;
|
|
9
|
+
declare const atomicLoad: DualFn<(<T extends AnyAtomic>(a: T) => number)>;
|
|
10
|
+
declare const atomicStore: DualFn<(<T extends AnyAtomic>(a: T, value: number) => void)>;
|
|
11
|
+
declare const atomicAdd: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
12
|
+
declare const atomicSub: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
13
|
+
declare const atomicMax: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
14
|
+
declare const atomicMin: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
15
|
+
declare const atomicAnd: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
16
|
+
declare const atomicOr: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
17
|
+
declare const atomicXor: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier };
|
package/std/atomic.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Void, isAtomic } from "../data/wgslTypes.js";
|
|
2
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
3
|
+
import { safeStringify } from "../shared/stringify.js";
|
|
4
|
+
import { i32, u32 } from "../data/numeric.js";
|
|
5
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
6
|
+
|
|
7
|
+
//#region src/std/atomic.ts
|
|
8
|
+
const workgroupBarrier = dualImpl({
|
|
9
|
+
name: "workgroupBarrier",
|
|
10
|
+
normalImpl: "workgroupBarrier is a no-op outside of CODEGEN mode.",
|
|
11
|
+
signature: {
|
|
12
|
+
argTypes: [],
|
|
13
|
+
returnType: Void
|
|
14
|
+
},
|
|
15
|
+
codegenImpl: () => "workgroupBarrier()"
|
|
16
|
+
});
|
|
17
|
+
const storageBarrier = dualImpl({
|
|
18
|
+
name: "storageBarrier",
|
|
19
|
+
normalImpl: "storageBarrier is a no-op outside of CODEGEN mode.",
|
|
20
|
+
signature: {
|
|
21
|
+
argTypes: [],
|
|
22
|
+
returnType: Void
|
|
23
|
+
},
|
|
24
|
+
codegenImpl: () => "storageBarrier()"
|
|
25
|
+
});
|
|
26
|
+
const textureBarrier = dualImpl({
|
|
27
|
+
name: "textureBarrier",
|
|
28
|
+
normalImpl: "textureBarrier is a no-op outside of CODEGEN mode.",
|
|
29
|
+
signature: {
|
|
30
|
+
argTypes: [],
|
|
31
|
+
returnType: Void
|
|
32
|
+
},
|
|
33
|
+
codegenImpl: () => "textureBarrier()"
|
|
34
|
+
});
|
|
35
|
+
const atomicNormalError = "Atomic operations are not supported outside of CODEGEN mode.";
|
|
36
|
+
const atomicLoad = dualImpl({
|
|
37
|
+
name: "atomicLoad",
|
|
38
|
+
normalImpl: atomicNormalError,
|
|
39
|
+
signature: (a) => {
|
|
40
|
+
if (!isAtomic(a)) throw new Error(`Invalid atomic type: ${safeStringify(a)}`);
|
|
41
|
+
return {
|
|
42
|
+
argTypes: [a],
|
|
43
|
+
returnType: a.inner
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
codegenImpl: (_ctx, [a]) => stitch`atomicLoad(&${a})`
|
|
47
|
+
});
|
|
48
|
+
const atomicActionSignature = (a) => {
|
|
49
|
+
if (!isAtomic(a)) throw new Error(`Invalid atomic type: ${safeStringify(a)}`);
|
|
50
|
+
return {
|
|
51
|
+
argTypes: [a, a.inner.type === "u32" ? u32 : i32],
|
|
52
|
+
returnType: Void
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const atomicOpSignature = (a) => {
|
|
56
|
+
if (!isAtomic(a)) throw new Error(`Invalid atomic type: ${safeStringify(a)}`);
|
|
57
|
+
const paramType = a.inner.type === "u32" ? u32 : i32;
|
|
58
|
+
return {
|
|
59
|
+
argTypes: [a, paramType],
|
|
60
|
+
returnType: paramType
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const atomicStore = dualImpl({
|
|
64
|
+
name: "atomicStore",
|
|
65
|
+
normalImpl: atomicNormalError,
|
|
66
|
+
signature: atomicActionSignature,
|
|
67
|
+
codegenImpl: (_ctx, [a, value]) => stitch`atomicStore(&${a}, ${value})`
|
|
68
|
+
});
|
|
69
|
+
const atomicAdd = dualImpl({
|
|
70
|
+
name: "atomicAdd",
|
|
71
|
+
normalImpl: atomicNormalError,
|
|
72
|
+
signature: atomicOpSignature,
|
|
73
|
+
codegenImpl: (_ctx, [a, value]) => stitch`atomicAdd(&${a}, ${value})`
|
|
74
|
+
});
|
|
75
|
+
const atomicSub = dualImpl({
|
|
76
|
+
name: "atomicSub",
|
|
77
|
+
normalImpl: atomicNormalError,
|
|
78
|
+
signature: atomicOpSignature,
|
|
79
|
+
codegenImpl: (_ctx, [a, value]) => stitch`atomicSub(&${a}, ${value})`
|
|
80
|
+
});
|
|
81
|
+
const atomicMax = dualImpl({
|
|
82
|
+
name: "atomicMax",
|
|
83
|
+
normalImpl: atomicNormalError,
|
|
84
|
+
signature: atomicOpSignature,
|
|
85
|
+
codegenImpl: (_ctx, [a, value]) => stitch`atomicMax(&${a}, ${value})`
|
|
86
|
+
});
|
|
87
|
+
const atomicMin = dualImpl({
|
|
88
|
+
name: "atomicMin",
|
|
89
|
+
normalImpl: atomicNormalError,
|
|
90
|
+
signature: atomicOpSignature,
|
|
91
|
+
codegenImpl: (_ctx, [a, value]) => stitch`atomicMin(&${a}, ${value})`
|
|
92
|
+
});
|
|
93
|
+
const atomicAnd = dualImpl({
|
|
94
|
+
name: "atomicAnd",
|
|
95
|
+
normalImpl: atomicNormalError,
|
|
96
|
+
signature: atomicOpSignature,
|
|
97
|
+
codegenImpl: (_ctx, [a, value]) => stitch`atomicAnd(&${a}, ${value})`
|
|
98
|
+
});
|
|
99
|
+
const atomicOr = dualImpl({
|
|
100
|
+
name: "atomicOr",
|
|
101
|
+
normalImpl: atomicNormalError,
|
|
102
|
+
signature: atomicOpSignature,
|
|
103
|
+
codegenImpl: (_ctx, [a, value]) => stitch`atomicOr(&${a}, ${value})`
|
|
104
|
+
});
|
|
105
|
+
const atomicXor = dualImpl({
|
|
106
|
+
name: "atomicXor",
|
|
107
|
+
normalImpl: atomicNormalError,
|
|
108
|
+
signature: atomicOpSignature,
|
|
109
|
+
codegenImpl: (_ctx, [a, value]) => stitch`atomicXor(&${a}, ${value})`
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier };
|
package/std/bitcast.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DualFn } from "../types.js";
|
|
2
|
+
import { v2f, v2i, v2u, v3f, v3i, v3u, v4f, v4i, v4u } from "../data/wgslTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/bitcast.d.ts
|
|
5
|
+
type BitcastU32toF32Overload = ((value: number) => number) & ((value: v2u) => v2f) & ((value: v3u) => v3f) & ((value: v4u) => v4f);
|
|
6
|
+
declare const bitcastU32toF32: DualFn<BitcastU32toF32Overload>;
|
|
7
|
+
type BitcastU32toI32Overload = ((value: number) => number) & ((value: v2u) => v2i) & ((value: v3u) => v3i) & ((value: v4u) => v4i);
|
|
8
|
+
declare const bitcastU32toI32: DualFn<BitcastU32toI32Overload>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { bitcastU32toF32, bitcastU32toI32 };
|
package/std/bitcast.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isVec } from "../data/wgslTypes.js";
|
|
2
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
3
|
+
import { unify } from "../tgsl/conversion.js";
|
|
4
|
+
import { f32, i32, u32 } from "../data/numeric.js";
|
|
5
|
+
import { vec2f, vec2i, vec3f, vec3i, vec4f, vec4i } from "../data/vector.js";
|
|
6
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
7
|
+
import { bitcastU32toF32Impl, bitcastU32toI32Impl } from "../data/numberOps.js";
|
|
8
|
+
import { VectorOps } from "../data/vectorOps.js";
|
|
9
|
+
|
|
10
|
+
//#region src/std/bitcast.ts
|
|
11
|
+
const bitcastU32toF32 = dualImpl({
|
|
12
|
+
name: "bitcastU32toF32",
|
|
13
|
+
normalImpl: ((value) => {
|
|
14
|
+
if (typeof value === "number") return bitcastU32toF32Impl(value);
|
|
15
|
+
return VectorOps.bitcastU32toF32[value.kind](value);
|
|
16
|
+
}),
|
|
17
|
+
codegenImpl: (_ctx, [n]) => stitch`bitcast<f32>(${n})`,
|
|
18
|
+
signature: (...arg) => {
|
|
19
|
+
const uargs = unify(arg, [u32]) ?? arg;
|
|
20
|
+
return {
|
|
21
|
+
argTypes: uargs,
|
|
22
|
+
returnType: isVec(uargs[0]) ? uargs[0].type === "vec2u" ? vec2f : uargs[0].type === "vec3u" ? vec3f : vec4f : f32
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const bitcastU32toI32 = dualImpl({
|
|
27
|
+
name: "bitcastU32toI32",
|
|
28
|
+
normalImpl: ((value) => {
|
|
29
|
+
if (typeof value === "number") return bitcastU32toI32Impl(value);
|
|
30
|
+
return VectorOps.bitcastU32toI32[value.kind](value);
|
|
31
|
+
}),
|
|
32
|
+
codegenImpl: (_ctx, [n]) => stitch`bitcast<i32>(${n})`,
|
|
33
|
+
signature: (...arg) => {
|
|
34
|
+
const uargs = unify(arg, [u32]) ?? arg;
|
|
35
|
+
return {
|
|
36
|
+
argTypes: uargs,
|
|
37
|
+
returnType: isVec(uargs[0]) ? uargs[0].type === "vec2u" ? vec2i : uargs[0].type === "vec3u" ? vec3i : vec4i : i32
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { bitcastU32toF32, bitcastU32toI32 };
|