typegpu 0.10.0 → 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.
Files changed (263) hide show
  1. package/{chunk-BYypO7fO.js → _virtual/_rolldown/runtime.js} +1 -1
  2. package/builtin.d.ts +50 -0
  3. package/builtin.js +37 -0
  4. package/common/fullScreenTriangle.d.ts +26 -0
  5. package/common/fullScreenTriangle.js +36 -0
  6. package/common/index.d.ts +2 -3
  7. package/common/index.js +3 -4
  8. package/core/buffer/buffer.d.ts +74 -0
  9. package/core/buffer/buffer.js +197 -0
  10. package/core/buffer/bufferShorthand.d.ts +48 -0
  11. package/core/buffer/bufferShorthand.js +49 -0
  12. package/core/buffer/bufferUsage.d.ts +45 -0
  13. package/core/buffer/bufferUsage.js +163 -0
  14. package/core/constant/tgpuConstant.d.ts +28 -0
  15. package/core/constant/tgpuConstant.js +67 -0
  16. package/core/declare/tgpuDeclare.d.ts +18 -0
  17. package/core/declare/tgpuDeclare.js +40 -0
  18. package/core/function/autoIO.d.ts +37 -0
  19. package/core/function/autoIO.js +87 -0
  20. package/core/function/comptime.d.ts +39 -0
  21. package/core/function/comptime.js +51 -0
  22. package/core/function/createCallableSchema.js +42 -0
  23. package/core/function/dualImpl.js +54 -0
  24. package/core/function/extractArgs.js +204 -0
  25. package/core/function/fnCore.js +79 -0
  26. package/core/function/fnTypes.d.ts +34 -0
  27. package/core/function/ioSchema.d.ts +10 -0
  28. package/core/function/ioSchema.js +30 -0
  29. package/core/function/shelllessImpl.d.ts +28 -0
  30. package/core/function/shelllessImpl.js +23 -0
  31. package/core/function/templateUtils.js +13 -0
  32. package/core/function/tgpuComputeFn.d.ts +49 -0
  33. package/core/function/tgpuComputeFn.js +62 -0
  34. package/core/function/tgpuFn.d.ts +52 -0
  35. package/core/function/tgpuFn.js +170 -0
  36. package/core/function/tgpuFragmentFn.d.ts +68 -0
  37. package/core/function/tgpuFragmentFn.js +68 -0
  38. package/core/function/tgpuVertexFn.d.ts +55 -0
  39. package/core/function/tgpuVertexFn.js +65 -0
  40. package/core/pipeline/applyPipelineState.js +37 -0
  41. package/core/pipeline/computePipeline.d.ts +58 -0
  42. package/core/pipeline/computePipeline.js +226 -0
  43. package/core/pipeline/connectAttachmentToShader.js +26 -0
  44. package/core/pipeline/connectTargetsToShader.js +29 -0
  45. package/core/pipeline/limitsOverflow.js +13 -0
  46. package/core/pipeline/renderPipeline.d.ts +266 -0
  47. package/core/pipeline/renderPipeline.js +471 -0
  48. package/core/pipeline/timeable.d.ts +23 -0
  49. package/core/pipeline/timeable.js +61 -0
  50. package/core/pipeline/typeGuards.js +29 -0
  51. package/core/querySet/querySet.d.ts +22 -0
  52. package/core/querySet/querySet.js +103 -0
  53. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
  54. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +96 -0
  55. package/core/resolve/externals.d.ts +10 -0
  56. package/core/resolve/externals.js +58 -0
  57. package/core/resolve/namespace.d.ts +38 -0
  58. package/core/resolve/namespace.js +41 -0
  59. package/core/resolve/resolveData.js +146 -0
  60. package/core/resolve/stitch.js +25 -0
  61. package/core/resolve/tgpuResolve.d.ts +151 -0
  62. package/core/resolve/tgpuResolve.js +68 -0
  63. package/core/root/configurableImpl.js +18 -0
  64. package/core/root/init.d.ts +69 -0
  65. package/core/root/init.js +457 -0
  66. package/core/root/rootTypes.d.ts +622 -0
  67. package/core/sampler/sampler.d.ts +35 -0
  68. package/core/sampler/sampler.js +116 -0
  69. package/core/simulate/tgpuSimulate.d.ts +36 -0
  70. package/core/simulate/tgpuSimulate.js +76 -0
  71. package/core/slot/accessor.d.ts +13 -0
  72. package/core/slot/accessor.js +97 -0
  73. package/core/slot/internalSlots.js +7 -0
  74. package/core/slot/lazy.d.ts +6 -0
  75. package/core/slot/lazy.js +42 -0
  76. package/core/slot/slot.d.ts +6 -0
  77. package/core/slot/slot.js +40 -0
  78. package/core/slot/slotTypes.d.ts +92 -0
  79. package/core/slot/slotTypes.js +21 -0
  80. package/core/texture/externalTexture.d.ts +12 -0
  81. package/core/texture/externalTexture.js +48 -0
  82. package/core/texture/texture.d.ts +118 -0
  83. package/core/texture/texture.js +312 -0
  84. package/core/texture/textureFormats.d.ts +29 -0
  85. package/core/texture/textureFormats.js +99 -0
  86. package/core/texture/textureProps.d.ts +11 -0
  87. package/core/texture/textureUtils.js +224 -0
  88. package/core/texture/usageExtension.d.ts +21 -0
  89. package/core/texture/usageExtension.js +21 -0
  90. package/core/unroll/tgpuUnroll.d.ts +13 -0
  91. package/core/unroll/tgpuUnroll.js +36 -0
  92. package/core/valueProxyUtils.js +44 -0
  93. package/core/variable/tgpuVariable.d.ts +38 -0
  94. package/core/variable/tgpuVariable.js +101 -0
  95. package/core/vertexLayout/connectAttributesToShader.js +59 -0
  96. package/core/vertexLayout/vertexAttribute.d.ts +29 -0
  97. package/core/vertexLayout/vertexLayout.d.ts +19 -0
  98. package/core/vertexLayout/vertexLayout.js +103 -0
  99. package/data/alignIO.js +15 -0
  100. package/data/alignmentOf.d.ts +10 -0
  101. package/data/alignmentOf.js +88 -0
  102. package/data/array.d.ts +28 -0
  103. package/data/array.js +48 -0
  104. package/data/atomic.d.ts +15 -0
  105. package/data/atomic.js +25 -0
  106. package/data/attributes.d.ts +121 -0
  107. package/data/attributes.js +145 -0
  108. package/data/autoStruct.d.ts +3 -0
  109. package/data/autoStruct.js +83 -0
  110. package/data/compiledIO.js +231 -0
  111. package/data/dataIO.js +549 -0
  112. package/data/dataTypes.d.ts +115 -0
  113. package/data/dataTypes.js +97 -0
  114. package/data/deepEqual.d.ts +25 -0
  115. package/data/deepEqual.js +58 -0
  116. package/data/disarray.d.ts +34 -0
  117. package/data/disarray.js +52 -0
  118. package/data/getLongestContiguousPrefix.d.ts +10 -0
  119. package/data/getLongestContiguousPrefix.js +15 -0
  120. package/data/index.d.ts +26 -4
  121. package/data/index.js +27 -7
  122. package/data/instanceToSchema.d.ts +33 -0
  123. package/data/isContiguous.d.ts +10 -0
  124. package/data/isContiguous.js +15 -0
  125. package/data/matrix.d.ts +126 -0
  126. package/data/matrix.js +517 -0
  127. package/data/numberOps.js +24 -0
  128. package/data/numeric.d.ts +81 -0
  129. package/data/numeric.js +234 -0
  130. package/data/offsetUtils.d.ts +33 -0
  131. package/data/offsetUtils.js +167 -0
  132. package/data/offsets.js +36 -0
  133. package/data/partialIO.js +68 -0
  134. package/data/ptr.d.ts +12 -0
  135. package/data/ptr.js +46 -0
  136. package/data/ref.d.ts +37 -0
  137. package/data/ref.js +96 -0
  138. package/data/sampler.d.ts +107 -0
  139. package/data/sampler.js +26 -0
  140. package/data/schemaCallWrapper.js +32 -0
  141. package/data/schemaMemoryLayout.js +200 -0
  142. package/data/sizeOf.d.ts +10 -0
  143. package/data/sizeOf.js +15 -0
  144. package/data/snippet.d.ts +26 -0
  145. package/data/snippet.js +61 -0
  146. package/data/struct.d.ts +17 -0
  147. package/data/struct.js +46 -0
  148. package/data/texture.d.ts +292 -0
  149. package/{texture-Dg5ybJro.js → data/texture.js} +6 -3
  150. package/data/unstruct.d.ts +24 -0
  151. package/data/unstruct.js +43 -0
  152. package/data/vector.d.ts +191 -0
  153. package/data/vector.js +247 -0
  154. package/data/vectorImpl.js +516 -0
  155. package/data/vectorOps.js +664 -0
  156. package/data/vertexFormatData.d.ts +190 -0
  157. package/data/vertexFormatData.js +110 -0
  158. package/data/wgslTypes.d.ts +896 -0
  159. package/data/wgslTypes.js +215 -0
  160. package/errors.d.ts +44 -0
  161. package/errors.js +128 -0
  162. package/execMode.js +51 -0
  163. package/extension.d.ts +11 -0
  164. package/extension.js +18 -0
  165. package/getGPUValue.js +9 -0
  166. package/index.d.ts +40 -243
  167. package/index.js +19 -6318
  168. package/indexNamedExports.d.ts +38 -0
  169. package/mathUtils.js +13 -0
  170. package/memo.js +22 -0
  171. package/nameRegistry.d.ts +30 -0
  172. package/nameRegistry.js +449 -0
  173. package/package.js +5 -0
  174. package/package.json +23 -23
  175. package/resolutionCtx.d.ts +29 -0
  176. package/resolutionCtx.js +546 -0
  177. package/shared/env.js +13 -0
  178. package/shared/generators.js +14 -0
  179. package/shared/meta.d.ts +39 -0
  180. package/shared/meta.js +63 -0
  181. package/shared/repr.d.ts +108 -0
  182. package/shared/stringify.js +22 -0
  183. package/shared/symbols.d.ts +61 -0
  184. package/shared/symbols.js +71 -0
  185. package/shared/utilityTypes.d.ts +29 -0
  186. package/shared/utilityTypes.js +7 -0
  187. package/shared/vertexFormat.d.ts +70 -0
  188. package/shared/vertexFormat.js +64 -0
  189. package/std/array.d.ts +7 -0
  190. package/std/array.js +27 -0
  191. package/std/atomic.d.ts +19 -0
  192. package/std/atomic.js +113 -0
  193. package/std/bitcast.d.ts +10 -0
  194. package/std/bitcast.js +43 -0
  195. package/std/boolean.d.ts +127 -0
  196. package/std/boolean.js +274 -0
  197. package/std/derivative.d.ts +16 -0
  198. package/std/derivative.js +89 -0
  199. package/std/discard.d.ts +6 -0
  200. package/std/discard.js +16 -0
  201. package/std/extensions.d.ts +8 -0
  202. package/std/extensions.js +14 -0
  203. package/std/index.d.ts +15 -3
  204. package/std/index.js +16 -5
  205. package/std/matrix.d.ts +41 -0
  206. package/std/matrix.js +87 -0
  207. package/std/numeric.d.ts +254 -0
  208. package/std/numeric.js +847 -0
  209. package/std/operators.d.ts +48 -0
  210. package/std/operators.js +153 -0
  211. package/std/packing.d.ts +26 -0
  212. package/std/packing.js +86 -0
  213. package/std/subgroup.d.ts +47 -0
  214. package/std/subgroup.js +220 -0
  215. package/std/texture.d.ts +108 -0
  216. package/std/texture.js +197 -0
  217. package/tgpu.js +44 -0
  218. package/tgpuBindGroupLayout.d.ts +161 -0
  219. package/tgpuBindGroupLayout.js +271 -0
  220. package/tgpuUnstable.d.ts +48 -0
  221. package/tgpuUnstable.js +66 -0
  222. package/tgsl/accessIndex.js +45 -0
  223. package/tgsl/accessProp.js +113 -0
  224. package/tgsl/consoleLog/deserializers.js +117 -0
  225. package/tgsl/consoleLog/logGenerator.js +86 -0
  226. package/tgsl/consoleLog/serializers.js +225 -0
  227. package/tgsl/consoleLog/types.d.ts +54 -0
  228. package/tgsl/consoleLog/types.js +12 -0
  229. package/tgsl/conversion.js +200 -0
  230. package/tgsl/forOfUtils.js +45 -0
  231. package/tgsl/generationHelpers.d.ts +37 -0
  232. package/tgsl/generationHelpers.js +67 -0
  233. package/tgsl/math.js +45 -0
  234. package/tgsl/shaderGenerator.d.ts +18 -0
  235. package/tgsl/shellless.d.ts +11 -0
  236. package/tgsl/shellless.js +53 -0
  237. package/tgsl/wgslGenerator.js +585 -0
  238. package/types.d.ts +255 -0
  239. package/types.js +43 -0
  240. package/unwrapper.d.ts +27 -0
  241. package/wgslExtensions.d.ts +5 -0
  242. package/wgslExtensions.js +18 -0
  243. package/builtin-ClEnM-Ye.js +0 -818
  244. package/builtin-ClEnM-Ye.js.map +0 -1
  245. package/common/index.d.ts.map +0 -1
  246. package/common/index.js.map +0 -1
  247. package/data/index.d.ts.map +0 -1
  248. package/data/index.js.map +0 -1
  249. package/deepEqual-yZXvaV2C.js +0 -413
  250. package/deepEqual-yZXvaV2C.js.map +0 -1
  251. package/extensions-0SFbU9FH.js +0 -2032
  252. package/extensions-0SFbU9FH.js.map +0 -1
  253. package/fullScreenTriangle-MdLGaAMR.js +0 -543
  254. package/fullScreenTriangle-MdLGaAMR.js.map +0 -1
  255. package/index.d.ts.map +0 -1
  256. package/index.js.map +0 -1
  257. package/indexNamedExports-Cdy7USiY.d.ts +0 -5696
  258. package/indexNamedExports-Cdy7USiY.d.ts.map +0 -1
  259. package/operators-HTxa_0k9.js +0 -4156
  260. package/operators-HTxa_0k9.js.map +0 -1
  261. package/std/index.d.ts.map +0 -1
  262. package/std/index.js.map +0 -1
  263. package/texture-Dg5ybJro.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 };
package/getGPUValue.js ADDED
@@ -0,0 +1,9 @@
1
+ import { $gpuValueOf } from "./shared/symbols.js";
2
+
3
+ //#region src/getGPUValue.ts
4
+ function getGPUValue(object) {
5
+ return object?.[$gpuValueOf];
6
+ }
7
+
8
+ //#endregion
9
+ export { getGPUValue };