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
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { $internal, isMarkedInternal } from "../shared/symbols.js";
|
|
2
|
+
import "tsover-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/data/wgslTypes.ts
|
|
5
|
+
const Void = {
|
|
6
|
+
[$internal]: {},
|
|
7
|
+
type: "void",
|
|
8
|
+
toString() {
|
|
9
|
+
return "void";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const wgslTypeLiterals = [
|
|
13
|
+
"bool",
|
|
14
|
+
"f32",
|
|
15
|
+
"f16",
|
|
16
|
+
"i32",
|
|
17
|
+
"u32",
|
|
18
|
+
"u16",
|
|
19
|
+
"vec2f",
|
|
20
|
+
"vec2h",
|
|
21
|
+
"vec2i",
|
|
22
|
+
"vec2u",
|
|
23
|
+
"vec2<bool>",
|
|
24
|
+
"vec3f",
|
|
25
|
+
"vec3h",
|
|
26
|
+
"vec3i",
|
|
27
|
+
"vec3u",
|
|
28
|
+
"vec3<bool>",
|
|
29
|
+
"vec4f",
|
|
30
|
+
"vec4h",
|
|
31
|
+
"vec4i",
|
|
32
|
+
"vec4u",
|
|
33
|
+
"vec4<bool>",
|
|
34
|
+
"mat2x2f",
|
|
35
|
+
"mat3x3f",
|
|
36
|
+
"mat4x4f",
|
|
37
|
+
"struct",
|
|
38
|
+
"array",
|
|
39
|
+
"ptr",
|
|
40
|
+
"atomic",
|
|
41
|
+
"decorated",
|
|
42
|
+
"abstractInt",
|
|
43
|
+
"abstractFloat",
|
|
44
|
+
"void",
|
|
45
|
+
"texture_1d",
|
|
46
|
+
"texture_storage_1d",
|
|
47
|
+
"texture_2d",
|
|
48
|
+
"texture_storage_2d",
|
|
49
|
+
"texture_multisampled_2d",
|
|
50
|
+
"texture_depth_2d",
|
|
51
|
+
"texture_depth_multisampled_2d",
|
|
52
|
+
"texture_2d_array",
|
|
53
|
+
"texture_storage_2d_array",
|
|
54
|
+
"texture_depth_2d_array",
|
|
55
|
+
"texture_cube",
|
|
56
|
+
"texture_depth_cube",
|
|
57
|
+
"texture_cube_array",
|
|
58
|
+
"texture_depth_cube_array",
|
|
59
|
+
"texture_3d",
|
|
60
|
+
"texture_storage_3d",
|
|
61
|
+
"texture_external",
|
|
62
|
+
"sampler",
|
|
63
|
+
"sampler_comparison"
|
|
64
|
+
];
|
|
65
|
+
function isVecInstance(value) {
|
|
66
|
+
const v = value;
|
|
67
|
+
return isMarkedInternal(v) && typeof v.kind === "string" && v.kind.startsWith("vec");
|
|
68
|
+
}
|
|
69
|
+
function isVec2(value) {
|
|
70
|
+
const v = value;
|
|
71
|
+
return isMarkedInternal(v) && typeof v.type === "string" && v.type.startsWith("vec2");
|
|
72
|
+
}
|
|
73
|
+
function isVec3(value) {
|
|
74
|
+
const v = value;
|
|
75
|
+
return isMarkedInternal(v) && typeof v.type === "string" && v.type.startsWith("vec3");
|
|
76
|
+
}
|
|
77
|
+
function isVec4(value) {
|
|
78
|
+
const v = value;
|
|
79
|
+
return isMarkedInternal(v) && typeof v.type === "string" && v.type.startsWith("vec4");
|
|
80
|
+
}
|
|
81
|
+
function isVec(value) {
|
|
82
|
+
return isVec2(value) || isVec3(value) || isVec4(value);
|
|
83
|
+
}
|
|
84
|
+
function isVecBool(value) {
|
|
85
|
+
return isVec(value) && value.type.includes("b");
|
|
86
|
+
}
|
|
87
|
+
function isMatInstance(value) {
|
|
88
|
+
const v = value;
|
|
89
|
+
return isMarkedInternal(v) && typeof v.kind?.startsWith === "function" && v.kind.startsWith("mat");
|
|
90
|
+
}
|
|
91
|
+
function isMat2x2f(value) {
|
|
92
|
+
return isMarkedInternal(value) && value?.type === "mat2x2f";
|
|
93
|
+
}
|
|
94
|
+
function isMat3x3f(value) {
|
|
95
|
+
return isMarkedInternal(value) && value?.type === "mat3x3f";
|
|
96
|
+
}
|
|
97
|
+
function isMat4x4f(value) {
|
|
98
|
+
return isMarkedInternal(value) && value?.type === "mat4x4f";
|
|
99
|
+
}
|
|
100
|
+
function isMat(value) {
|
|
101
|
+
return isMat2x2f(value) || isMat3x3f(value) || isMat4x4f(value);
|
|
102
|
+
}
|
|
103
|
+
function isFloat32VecInstance(element) {
|
|
104
|
+
return isVecInstance(element) && [
|
|
105
|
+
"vec2f",
|
|
106
|
+
"vec3f",
|
|
107
|
+
"vec4f"
|
|
108
|
+
].includes(element.kind);
|
|
109
|
+
}
|
|
110
|
+
function isWgslData(value) {
|
|
111
|
+
return isMarkedInternal(value) && wgslTypeLiterals.includes(value?.type);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Checks whether passed in value is an array schema,
|
|
115
|
+
* as opposed to, e.g., a disarray schema.
|
|
116
|
+
*
|
|
117
|
+
* Array schemas can be used to describe uniform and storage buffers,
|
|
118
|
+
* whereas disarray schemas cannot.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* isWgslArray(d.arrayOf(d.u32, 4)) // true
|
|
122
|
+
* isWgslArray(d.disarray(d.u32, 4)) // false
|
|
123
|
+
* isWgslArray(d.vec3f) // false
|
|
124
|
+
*/
|
|
125
|
+
function isWgslArray(schema) {
|
|
126
|
+
return isMarkedInternal(schema) && schema?.type === "array";
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Checks whether passed in value is a struct schema,
|
|
130
|
+
* as opposed to, e.g., an unstruct schema.
|
|
131
|
+
*
|
|
132
|
+
* Struct schemas can be used to describe uniform and storage buffers,
|
|
133
|
+
* whereas unstruct schemas cannot.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* isWgslStruct(d.struct({ a: d.u32 })) // true
|
|
137
|
+
* isWgslStruct(d.unstruct({ a: d.u32 })) // false
|
|
138
|
+
* isWgslStruct(d.vec3f) // false
|
|
139
|
+
*/
|
|
140
|
+
function isWgslStruct(schema) {
|
|
141
|
+
return isMarkedInternal(schema) && schema?.type === "struct";
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Checks whether passed in value is a pointer schema.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* isPtr(d.ptrFn(d.f32)) // true
|
|
148
|
+
* isPtr(d.ptrPrivate(d.f32)) // true
|
|
149
|
+
* isPtr(d.f32) // false
|
|
150
|
+
*/
|
|
151
|
+
function isPtr(schema) {
|
|
152
|
+
return isMarkedInternal(schema) && schema?.type === "ptr";
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Checks whether the passed in value is an atomic schema.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* isAtomic(d.atomic(d.u32)) // true
|
|
159
|
+
* isAtomic(d.u32) // false
|
|
160
|
+
*/
|
|
161
|
+
function isAtomic(schema) {
|
|
162
|
+
return isMarkedInternal(schema) && schema?.type === "atomic";
|
|
163
|
+
}
|
|
164
|
+
function isAlignAttrib(value) {
|
|
165
|
+
return isMarkedInternal(value) && value?.type === "@align";
|
|
166
|
+
}
|
|
167
|
+
function isSizeAttrib(value) {
|
|
168
|
+
return isMarkedInternal(value) && value?.type === "@size";
|
|
169
|
+
}
|
|
170
|
+
function isLocationAttrib(value) {
|
|
171
|
+
return isMarkedInternal(value) && value?.type === "@location";
|
|
172
|
+
}
|
|
173
|
+
function isInterpolateAttrib(value) {
|
|
174
|
+
return isMarkedInternal(value) && value?.type === "@interpolate";
|
|
175
|
+
}
|
|
176
|
+
function isBuiltinAttrib(value) {
|
|
177
|
+
return isMarkedInternal(value) && value?.type === "@builtin";
|
|
178
|
+
}
|
|
179
|
+
function isDecorated(value) {
|
|
180
|
+
return isMarkedInternal(value) && value?.type === "decorated";
|
|
181
|
+
}
|
|
182
|
+
function isVoid(value) {
|
|
183
|
+
return isMarkedInternal(value) && value.type === "void";
|
|
184
|
+
}
|
|
185
|
+
function isNumericSchema(schema) {
|
|
186
|
+
const type = schema?.type;
|
|
187
|
+
return isMarkedInternal(schema) && (type === "abstractInt" || type === "abstractFloat" || type === "f32" || type === "f16" || type === "i32" || type === "u32");
|
|
188
|
+
}
|
|
189
|
+
function isHalfPrecisionSchema(schema) {
|
|
190
|
+
const type = schema?.type;
|
|
191
|
+
return isMarkedInternal(schema) && (type === "f16" || type === "vec2h" || type === "vec3h" || type === "vec4h");
|
|
192
|
+
}
|
|
193
|
+
const ephemeralTypes = [
|
|
194
|
+
"abstractInt",
|
|
195
|
+
"abstractFloat",
|
|
196
|
+
"f32",
|
|
197
|
+
"f16",
|
|
198
|
+
"i32",
|
|
199
|
+
"u32",
|
|
200
|
+
"bool"
|
|
201
|
+
];
|
|
202
|
+
/**
|
|
203
|
+
* Returns true for schemas that are not naturally referential in JS (primitives).
|
|
204
|
+
* @param schema
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
function isNaturallyEphemeral(schema) {
|
|
208
|
+
return !isMarkedInternal(schema) || ephemeralTypes.includes(schema?.type);
|
|
209
|
+
}
|
|
210
|
+
function WORKAROUND_getSchema(vec) {
|
|
211
|
+
return vec.schema;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
//#endregion
|
|
215
|
+
export { Void, WORKAROUND_getSchema, isAlignAttrib, isAtomic, isBuiltinAttrib, isDecorated, isFloat32VecInstance, isHalfPrecisionSchema, isInterpolateAttrib, isLocationAttrib, isMat, isMat2x2f, isMat3x3f, isMatInstance, isNaturallyEphemeral, isNumericSchema, isPtr, isSizeAttrib, isVec, isVecBool, isVecInstance, isVoid, isWgslArray, isWgslData, isWgslStruct };
|
package/errors.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TgpuSlot } from "./core/slot/slotTypes.js";
|
|
2
|
+
import { TgpuVertexLayout } from "./core/vertexLayout/vertexLayout.js";
|
|
3
|
+
import { TgpuBindGroupLayout } from "./tgpuBindGroupLayout.js";
|
|
4
|
+
import { TgpuBuffer } from "./core/buffer/buffer.js";
|
|
5
|
+
import { BaseData } from "./data/wgslTypes.js";
|
|
6
|
+
|
|
7
|
+
//#region src/errors.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* An error that happens during resolution of WGSL code.
|
|
10
|
+
* Contains a trace of all ancestor resolvables in
|
|
11
|
+
* which this error originated.
|
|
12
|
+
*
|
|
13
|
+
* @category Errors
|
|
14
|
+
*/
|
|
15
|
+
declare class ResolutionError extends Error {
|
|
16
|
+
readonly cause: unknown;
|
|
17
|
+
readonly trace: unknown[];
|
|
18
|
+
constructor(cause: unknown, trace: unknown[]);
|
|
19
|
+
appendToTrace(ancestor: unknown): ResolutionError;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @category Errors
|
|
23
|
+
*/
|
|
24
|
+
declare class MissingSlotValueError extends Error {
|
|
25
|
+
readonly slot: TgpuSlot<unknown>;
|
|
26
|
+
constructor(slot: TgpuSlot<unknown>);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @category Errors
|
|
30
|
+
*/
|
|
31
|
+
declare class NotUniformError extends Error {
|
|
32
|
+
constructor(value: TgpuBuffer<BaseData>);
|
|
33
|
+
}
|
|
34
|
+
declare class MissingLinksError extends Error {
|
|
35
|
+
constructor(fnLabel: string | undefined, externalNames: string[]);
|
|
36
|
+
}
|
|
37
|
+
declare class MissingBindGroupsError extends Error {
|
|
38
|
+
constructor(layouts: Iterable<TgpuBindGroupLayout>);
|
|
39
|
+
}
|
|
40
|
+
declare class MissingVertexBuffersError extends Error {
|
|
41
|
+
constructor(layouts: Iterable<TgpuVertexLayout>);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError };
|
package/errors.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { DEV, TEST } from "./shared/env.js";
|
|
2
|
+
import { getName, hasTinyestMetadata } from "./shared/meta.js";
|
|
3
|
+
|
|
4
|
+
//#region src/errors.ts
|
|
5
|
+
const prefix = "Invariant failed";
|
|
6
|
+
/**
|
|
7
|
+
* Inspired by: https://github.com/alexreardon/tiny-invariant/blob/master/src/tiny-invariant.ts
|
|
8
|
+
*/
|
|
9
|
+
function invariant(condition, message) {
|
|
10
|
+
if (condition) return;
|
|
11
|
+
if (!DEV && !TEST) throw new Error(prefix);
|
|
12
|
+
const provided = typeof message === "function" ? message() : message;
|
|
13
|
+
const value = provided ? `${prefix}: ${provided}` : prefix;
|
|
14
|
+
throw new Error(value);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An error that happens during resolution of WGSL code.
|
|
18
|
+
* Contains a trace of all ancestor resolvables in
|
|
19
|
+
* which this error originated.
|
|
20
|
+
*
|
|
21
|
+
* @category Errors
|
|
22
|
+
*/
|
|
23
|
+
var ResolutionError = class ResolutionError extends Error {
|
|
24
|
+
constructor(cause, trace) {
|
|
25
|
+
let entries = trace.map((ancestor) => `- ${hasTinyestMetadata(ancestor) ? `fn*:${getName(ancestor)}` : ancestor}`);
|
|
26
|
+
if (entries.length > 20) entries = [
|
|
27
|
+
...entries.slice(0, 11),
|
|
28
|
+
"...",
|
|
29
|
+
...entries.slice(-10)
|
|
30
|
+
];
|
|
31
|
+
super(`Resolution of the following tree failed:\n${entries.join("\n")}: ${cause && typeof cause === "object" && "message" in cause ? cause.message : cause}`);
|
|
32
|
+
this.cause = cause;
|
|
33
|
+
this.trace = trace;
|
|
34
|
+
Object.setPrototypeOf(this, ResolutionError.prototype);
|
|
35
|
+
}
|
|
36
|
+
appendToTrace(ancestor) {
|
|
37
|
+
const newTrace = [ancestor, ...this.trace];
|
|
38
|
+
return new ResolutionError(this.cause, newTrace);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* An error that happens during execution of TypeGPU functions.
|
|
43
|
+
* Contains a trace of all TypeGPU functions called along the way.
|
|
44
|
+
*
|
|
45
|
+
* @category Errors
|
|
46
|
+
*/
|
|
47
|
+
var ExecutionError = class ExecutionError extends Error {
|
|
48
|
+
constructor(cause, trace) {
|
|
49
|
+
let entries = trace.map((ancestor) => `- ${ancestor}`);
|
|
50
|
+
if (entries.length > 20) entries = [
|
|
51
|
+
...entries.slice(0, 11),
|
|
52
|
+
"...",
|
|
53
|
+
...entries.slice(-10)
|
|
54
|
+
];
|
|
55
|
+
super(`Execution of the following tree failed:\n${entries.join("\n")}: ${cause && typeof cause === "object" && "message" in cause ? cause.message : cause}`);
|
|
56
|
+
this.cause = cause;
|
|
57
|
+
this.trace = trace;
|
|
58
|
+
Object.setPrototypeOf(this, ExecutionError.prototype);
|
|
59
|
+
}
|
|
60
|
+
appendToTrace(ancestor) {
|
|
61
|
+
const newTrace = [ancestor, ...this.trace];
|
|
62
|
+
return new ExecutionError(this.cause, newTrace);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* @category Errors
|
|
67
|
+
*/
|
|
68
|
+
var MissingSlotValueError = class MissingSlotValueError extends Error {
|
|
69
|
+
constructor(slot) {
|
|
70
|
+
super(`Missing value for '${slot}'`);
|
|
71
|
+
this.slot = slot;
|
|
72
|
+
Object.setPrototypeOf(this, MissingSlotValueError.prototype);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* @category Errors
|
|
77
|
+
*/
|
|
78
|
+
var NotUniformError = class NotUniformError extends Error {
|
|
79
|
+
constructor(value) {
|
|
80
|
+
super(`Buffer '${getName(value) ?? "<unnamed>"}' is not bindable as a uniform. Use .$usage('uniform') to allow it.`);
|
|
81
|
+
Object.setPrototypeOf(this, NotUniformError.prototype);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var MissingLinksError = class MissingLinksError extends Error {
|
|
85
|
+
constructor(fnLabel, externalNames) {
|
|
86
|
+
super(`The function '${fnLabel ?? "<unnamed>"}' is missing links to the following external values: ${externalNames}.`);
|
|
87
|
+
Object.setPrototypeOf(this, MissingLinksError.prototype);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var MissingBindGroupsError = class MissingBindGroupsError extends Error {
|
|
91
|
+
constructor(layouts) {
|
|
92
|
+
super(`Missing bind groups for layouts: '${[...layouts].map((layout) => getName(layout) ?? "<unnamed>").join(", ")}'. Please provide it using pipeline.with(bindGroup).(...)`);
|
|
93
|
+
Object.setPrototypeOf(this, MissingBindGroupsError.prototype);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var MissingVertexBuffersError = class MissingVertexBuffersError extends Error {
|
|
97
|
+
constructor(layouts) {
|
|
98
|
+
super(`Missing vertex buffers for layouts: '${[...layouts].map((layout) => getName(layout) ?? "<unnamed>").join(", ")}'. Please provide it using pipeline.with(layout, buffer).(...)`);
|
|
99
|
+
Object.setPrototypeOf(this, MissingVertexBuffersError.prototype);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var IllegalVarAccessError = class IllegalVarAccessError extends Error {
|
|
103
|
+
constructor(msg) {
|
|
104
|
+
super(msg);
|
|
105
|
+
Object.setPrototypeOf(this, IllegalVarAccessError.prototype);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var IllegalBufferAccessError = class IllegalBufferAccessError extends Error {
|
|
109
|
+
constructor(msg) {
|
|
110
|
+
super(msg);
|
|
111
|
+
Object.setPrototypeOf(this, IllegalBufferAccessError.prototype);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var WgslTypeError = class WgslTypeError extends Error {
|
|
115
|
+
constructor(msg) {
|
|
116
|
+
super(msg);
|
|
117
|
+
Object.setPrototypeOf(this, WgslTypeError.prototype);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var SignatureNotSupportedError = class SignatureNotSupportedError extends Error {
|
|
121
|
+
constructor(actual, candidates) {
|
|
122
|
+
super(`Unsupported data types: ${actual.map((a) => a.type).join(", ")}. Supported types are: ${candidates.map((r) => r.type).join(", ")}.`);
|
|
123
|
+
Object.setPrototypeOf(this, SignatureNotSupportedError.prototype);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { ExecutionError, IllegalBufferAccessError, IllegalVarAccessError, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, SignatureNotSupportedError, WgslTypeError, invariant };
|
package/execMode.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { invariant } from "./errors.js";
|
|
2
|
+
import { NormalState } from "./types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/execMode.ts
|
|
5
|
+
/**
|
|
6
|
+
* Used to track if the code we're currently
|
|
7
|
+
* executing is inside an executing TypeGPU function.
|
|
8
|
+
*
|
|
9
|
+
* Helpful for providing better error messages.
|
|
10
|
+
*/
|
|
11
|
+
let insideTgpuFn = false;
|
|
12
|
+
function provideInsideTgpuFn(callback) {
|
|
13
|
+
if (insideTgpuFn) return callback();
|
|
14
|
+
try {
|
|
15
|
+
insideTgpuFn = true;
|
|
16
|
+
return callback();
|
|
17
|
+
} finally {
|
|
18
|
+
insideTgpuFn = false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function isInsideTgpuFn() {
|
|
22
|
+
return insideTgpuFn;
|
|
23
|
+
}
|
|
24
|
+
let resolutionCtx;
|
|
25
|
+
function provideCtx(ctx, callback) {
|
|
26
|
+
invariant(resolutionCtx === void 0 || resolutionCtx === ctx, "Cannot nest context providers");
|
|
27
|
+
if (resolutionCtx === ctx) return callback();
|
|
28
|
+
resolutionCtx = ctx;
|
|
29
|
+
try {
|
|
30
|
+
return callback();
|
|
31
|
+
} finally {
|
|
32
|
+
resolutionCtx = void 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function getResolutionCtx() {
|
|
36
|
+
return resolutionCtx;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Applicable when code is being executed outside of any
|
|
40
|
+
* execution-altering APIs.
|
|
41
|
+
*/
|
|
42
|
+
const topLevelState = new NormalState();
|
|
43
|
+
function getExecMode() {
|
|
44
|
+
return resolutionCtx?.mode ?? topLevelState;
|
|
45
|
+
}
|
|
46
|
+
function inCodegenMode() {
|
|
47
|
+
return resolutionCtx?.mode.type === "codegen";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { getExecMode, getResolutionCtx, inCodegenMode, isInsideTgpuFn, provideCtx, provideInsideTgpuFn, topLevelState };
|
package/extension.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/extension.d.ts
|
|
2
|
+
interface StorageFlag {
|
|
3
|
+
usableAsStorage: true;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use StorageFlag instead.
|
|
7
|
+
*/
|
|
8
|
+
type Storage = StorageFlag;
|
|
9
|
+
declare function isUsableAsStorage<T>(value: T): value is T & StorageFlag;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Storage, StorageFlag, isUsableAsStorage };
|
package/extension.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getName } from "./shared/meta.js";
|
|
2
|
+
|
|
3
|
+
//#region src/extension.ts
|
|
4
|
+
function isUsableAsStorage(value) {
|
|
5
|
+
return !!value?.usableAsStorage;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @category Errors
|
|
9
|
+
*/
|
|
10
|
+
var NotStorageError = class NotStorageError extends Error {
|
|
11
|
+
constructor(value) {
|
|
12
|
+
super(`Resource '${getName(value) ?? "<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`);
|
|
13
|
+
Object.setPrototypeOf(this, NotStorageError.prototype);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { NotStorageError, isUsableAsStorage };
|