typegpu 0.10.1 → 0.11.0-rc.1

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 (273) hide show
  1. package/_virtual/_rolldown/runtime.js +13 -0
  2. package/builtin.d.ts +50 -0
  3. package/builtin.js +35 -0
  4. package/common/fullScreenTriangle.d.ts +22 -0
  5. package/common/fullScreenTriangle.js +34 -0
  6. package/common/index.d.ts +4 -4
  7. package/common/index.js +8 -7
  8. package/common/writeSoA.d.ts +16 -0
  9. package/common/writeSoA.js +90 -0
  10. package/core/buffer/buffer.d.ts +79 -0
  11. package/core/buffer/buffer.js +246 -0
  12. package/core/buffer/bufferShorthand.d.ts +48 -0
  13. package/core/buffer/bufferShorthand.js +53 -0
  14. package/core/buffer/bufferUsage.d.ts +43 -0
  15. package/core/buffer/bufferUsage.js +165 -0
  16. package/core/constant/tgpuConstant.d.ts +29 -0
  17. package/core/constant/tgpuConstant.js +68 -0
  18. package/core/declare/tgpuDeclare.d.ts +18 -0
  19. package/core/declare/tgpuDeclare.js +39 -0
  20. package/core/function/autoIO.d.ts +38 -0
  21. package/core/function/autoIO.js +85 -0
  22. package/core/function/comptime.d.ts +39 -0
  23. package/core/function/comptime.js +49 -0
  24. package/core/function/createCallableSchema.js +40 -0
  25. package/core/function/dualImpl.js +52 -0
  26. package/core/function/entryInputRouter.js +39 -0
  27. package/core/function/extractArgs.js +204 -0
  28. package/core/function/fnCore.js +90 -0
  29. package/core/function/fnTypes.d.ts +40 -0
  30. package/core/function/ioSchema.d.ts +10 -0
  31. package/core/function/ioSchema.js +51 -0
  32. package/core/function/shelllessImpl.d.ts +28 -0
  33. package/core/function/shelllessImpl.js +21 -0
  34. package/core/function/templateUtils.js +12 -0
  35. package/core/function/tgpuComputeFn.d.ts +48 -0
  36. package/core/function/tgpuComputeFn.js +55 -0
  37. package/core/function/tgpuFn.d.ts +52 -0
  38. package/core/function/tgpuFn.js +168 -0
  39. package/core/function/tgpuFragmentFn.d.ts +72 -0
  40. package/core/function/tgpuFragmentFn.js +63 -0
  41. package/core/function/tgpuVertexFn.d.ts +59 -0
  42. package/core/function/tgpuVertexFn.js +59 -0
  43. package/core/pipeline/applyPipelineState.js +35 -0
  44. package/core/pipeline/computePipeline.d.ts +54 -0
  45. package/core/pipeline/computePipeline.js +227 -0
  46. package/core/pipeline/connectAttachmentToShader.js +24 -0
  47. package/core/pipeline/connectTargetsToShader.js +27 -0
  48. package/core/pipeline/limitsOverflow.js +12 -0
  49. package/core/pipeline/pipelineUtils.js +29 -0
  50. package/core/pipeline/renderPipeline.d.ts +284 -0
  51. package/core/pipeline/renderPipeline.js +489 -0
  52. package/core/pipeline/timeable.d.ts +20 -0
  53. package/core/pipeline/timeable.js +55 -0
  54. package/core/pipeline/typeGuards.js +27 -0
  55. package/core/querySet/querySet.d.ts +20 -0
  56. package/core/querySet/querySet.js +104 -0
  57. package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
  58. package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +94 -0
  59. package/core/resolve/externals.d.ts +8 -0
  60. package/core/resolve/externals.js +56 -0
  61. package/core/resolve/namespace.d.ts +38 -0
  62. package/core/resolve/namespace.js +39 -0
  63. package/core/resolve/resolveData.js +144 -0
  64. package/core/resolve/stitch.js +23 -0
  65. package/core/resolve/tgpuResolve.d.ts +153 -0
  66. package/core/resolve/tgpuResolve.js +66 -0
  67. package/core/root/configurableImpl.js +17 -0
  68. package/core/root/init.d.ts +64 -0
  69. package/core/root/init.js +464 -0
  70. package/core/root/rootTypes.d.ts +642 -0
  71. package/core/sampler/sampler.d.ts +31 -0
  72. package/core/sampler/sampler.js +116 -0
  73. package/core/simulate/tgpuSimulate.d.ts +36 -0
  74. package/core/simulate/tgpuSimulate.js +74 -0
  75. package/core/slot/accessor.d.ts +9 -0
  76. package/core/slot/accessor.js +95 -0
  77. package/core/slot/internalSlots.js +5 -0
  78. package/core/slot/lazy.d.ts +6 -0
  79. package/core/slot/lazy.js +40 -0
  80. package/core/slot/slot.d.ts +6 -0
  81. package/core/slot/slot.js +39 -0
  82. package/core/slot/slotTypes.d.ts +92 -0
  83. package/core/slot/slotTypes.js +19 -0
  84. package/core/texture/externalTexture.d.ts +6 -0
  85. package/core/texture/externalTexture.js +47 -0
  86. package/core/texture/texture.d.ts +114 -0
  87. package/core/texture/texture.js +314 -0
  88. package/core/texture/textureFormats.d.ts +29 -0
  89. package/core/texture/textureFormats.js +97 -0
  90. package/core/texture/textureProps.d.ts +11 -0
  91. package/core/texture/textureUtils.js +222 -0
  92. package/core/texture/usageExtension.d.ts +21 -0
  93. package/core/texture/usageExtension.js +19 -0
  94. package/core/unroll/tgpuUnroll.d.ts +68 -0
  95. package/core/unroll/tgpuUnroll.js +94 -0
  96. package/core/valueProxyUtils.js +42 -0
  97. package/core/variable/tgpuVariable.d.ts +38 -0
  98. package/core/variable/tgpuVariable.js +99 -0
  99. package/core/vertexLayout/connectAttributesToShader.js +57 -0
  100. package/core/vertexLayout/vertexAttribute.d.ts +29 -0
  101. package/core/vertexLayout/vertexLayout.d.ts +19 -0
  102. package/core/vertexLayout/vertexLayout.js +103 -0
  103. package/data/alignIO.js +14 -0
  104. package/data/alignmentOf.d.ts +9 -0
  105. package/data/alignmentOf.js +86 -0
  106. package/data/array.d.ts +26 -0
  107. package/data/array.js +46 -0
  108. package/data/atomic.d.ts +15 -0
  109. package/data/atomic.js +24 -0
  110. package/data/attributes.d.ts +121 -0
  111. package/data/attributes.js +145 -0
  112. package/data/autoStruct.d.ts +1 -0
  113. package/data/autoStruct.js +81 -0
  114. package/data/compiledIO.js +228 -0
  115. package/data/dataIO.js +556 -0
  116. package/data/dataTypes.d.ts +115 -0
  117. package/data/dataTypes.js +100 -0
  118. package/data/deepEqual.d.ts +25 -0
  119. package/data/deepEqual.js +56 -0
  120. package/data/disarray.d.ts +32 -0
  121. package/data/disarray.js +50 -0
  122. package/data/getLongestContiguousPrefix.d.ts +9 -0
  123. package/data/getLongestContiguousPrefix.js +13 -0
  124. package/data/index.d.ts +26 -4
  125. package/data/index.js +36 -9
  126. package/data/instanceToSchema.d.ts +33 -0
  127. package/data/isContiguous.d.ts +9 -0
  128. package/data/isContiguous.js +13 -0
  129. package/data/matrix.d.ts +124 -0
  130. package/data/matrix.js +531 -0
  131. package/data/numberOps.js +23 -0
  132. package/data/numeric.d.ts +81 -0
  133. package/data/numeric.js +221 -0
  134. package/data/offsetUtils.d.ts +33 -0
  135. package/data/offsetUtils.js +165 -0
  136. package/data/offsets.js +34 -0
  137. package/data/partialIO.js +113 -0
  138. package/data/ptr.d.ts +11 -0
  139. package/data/ptr.js +44 -0
  140. package/data/ref.d.ts +34 -0
  141. package/data/ref.js +94 -0
  142. package/data/sampler.d.ts +107 -0
  143. package/data/sampler.js +24 -0
  144. package/data/schemaCallWrapper.js +30 -0
  145. package/data/schemaMemoryLayout.js +198 -0
  146. package/data/sizeOf.d.ts +9 -0
  147. package/data/sizeOf.js +13 -0
  148. package/data/snippet.d.ts +26 -0
  149. package/data/snippet.js +70 -0
  150. package/data/struct.d.ts +17 -0
  151. package/data/struct.js +44 -0
  152. package/data/texture.d.ts +292 -0
  153. package/{texture-BagDrrks.js → data/texture.js} +6 -5
  154. package/data/unstruct.d.ts +24 -0
  155. package/data/unstruct.js +41 -0
  156. package/data/vector.d.ts +191 -0
  157. package/data/vector.js +239 -0
  158. package/data/vectorImpl.js +515 -0
  159. package/data/vectorOps.js +681 -0
  160. package/data/vertexFormatData.d.ts +190 -0
  161. package/data/vertexFormatData.js +109 -0
  162. package/data/wgslTypes.d.ts +924 -0
  163. package/data/wgslTypes.js +222 -0
  164. package/errors.d.ts +44 -0
  165. package/errors.js +131 -0
  166. package/execMode.js +49 -0
  167. package/extension.d.ts +11 -0
  168. package/extension.js +16 -0
  169. package/getGPUValue.js +7 -0
  170. package/index.d.ts +42 -243
  171. package/index.js +21 -6320
  172. package/indexNamedExports.d.ts +40 -0
  173. package/mathUtils.js +12 -0
  174. package/memo.js +22 -0
  175. package/nameRegistry.d.ts +30 -0
  176. package/nameRegistry.js +447 -0
  177. package/package.js +4 -0
  178. package/package.json +26 -26
  179. package/resolutionCtx.d.ts +19 -0
  180. package/resolutionCtx.js +612 -0
  181. package/shared/env.js +12 -0
  182. package/shared/generators.js +13 -0
  183. package/shared/meta.d.ts +39 -0
  184. package/shared/meta.js +61 -0
  185. package/shared/repr.d.ts +138 -0
  186. package/shared/stringify.js +20 -0
  187. package/shared/symbols.d.ts +70 -0
  188. package/shared/symbols.js +48 -0
  189. package/shared/utilityTypes.d.ts +33 -0
  190. package/shared/utilityTypes.js +6 -0
  191. package/shared/vertexFormat.d.ts +70 -0
  192. package/shared/vertexFormat.js +63 -0
  193. package/std/array.d.ts +7 -0
  194. package/std/array.js +25 -0
  195. package/std/atomic.d.ts +19 -0
  196. package/std/atomic.js +111 -0
  197. package/std/bitcast.d.ts +10 -0
  198. package/std/bitcast.js +41 -0
  199. package/std/boolean.d.ts +141 -0
  200. package/std/boolean.js +299 -0
  201. package/std/derivative.d.ts +16 -0
  202. package/std/derivative.js +87 -0
  203. package/std/discard.d.ts +6 -0
  204. package/std/discard.js +14 -0
  205. package/std/extensions.d.ts +6 -0
  206. package/std/extensions.js +12 -0
  207. package/std/index.d.ts +17 -4
  208. package/std/index.js +21 -7
  209. package/std/matrix.d.ts +41 -0
  210. package/std/matrix.js +85 -0
  211. package/std/numeric.d.ts +200 -0
  212. package/std/numeric.js +845 -0
  213. package/std/operators.d.ts +56 -0
  214. package/std/operators.js +227 -0
  215. package/std/packing.d.ts +26 -0
  216. package/std/packing.js +84 -0
  217. package/std/range.d.ts +24 -0
  218. package/std/range.js +38 -0
  219. package/std/subgroup.d.ts +47 -0
  220. package/std/subgroup.js +218 -0
  221. package/std/texture.d.ts +117 -0
  222. package/std/texture.js +207 -0
  223. package/tgpu.js +42 -0
  224. package/tgpuBindGroupLayout.d.ts +161 -0
  225. package/tgpuBindGroupLayout.js +272 -0
  226. package/tgpuUnstable.d.ts +48 -0
  227. package/tgpuUnstable.js +64 -0
  228. package/tgsl/accessIndex.js +43 -0
  229. package/tgsl/accessProp.js +115 -0
  230. package/tgsl/consoleLog/deserializers.js +115 -0
  231. package/tgsl/consoleLog/logGenerator.js +84 -0
  232. package/tgsl/consoleLog/serializers.js +223 -0
  233. package/tgsl/consoleLog/types.d.ts +52 -0
  234. package/tgsl/consoleLog/types.js +11 -0
  235. package/tgsl/conversion.js +198 -0
  236. package/tgsl/forOfUtils.js +71 -0
  237. package/tgsl/generationHelpers.d.ts +37 -0
  238. package/tgsl/generationHelpers.js +67 -0
  239. package/tgsl/math.js +43 -0
  240. package/tgsl/shaderGenerator.d.ts +20 -0
  241. package/tgsl/shaderGenerator_members.d.ts +2 -0
  242. package/tgsl/shaderGenerator_members.js +6 -0
  243. package/tgsl/shellless.d.ts +11 -0
  244. package/tgsl/shellless.js +46 -0
  245. package/tgsl/wgslGenerator.d.ts +36 -0
  246. package/tgsl/wgslGenerator.js +639 -0
  247. package/types.d.ts +265 -0
  248. package/types.js +43 -0
  249. package/unwrapper.d.ts +27 -0
  250. package/wgslExtensions.d.ts +5 -0
  251. package/wgslExtensions.js +17 -0
  252. package/builtin-DdtWpk2t.js +0 -818
  253. package/builtin-DdtWpk2t.js.map +0 -1
  254. package/chunk-BYypO7fO.js +0 -18
  255. package/common/index.d.ts.map +0 -1
  256. package/common/index.js.map +0 -1
  257. package/data/index.d.ts.map +0 -1
  258. package/data/index.js.map +0 -1
  259. package/deepEqual-DQxK4vdp.js +0 -413
  260. package/deepEqual-DQxK4vdp.js.map +0 -1
  261. package/extensions-DIVuAfBM.js +0 -2032
  262. package/extensions-DIVuAfBM.js.map +0 -1
  263. package/fullScreenTriangle-CfFyQd_0.js +0 -543
  264. package/fullScreenTriangle-CfFyQd_0.js.map +0 -1
  265. package/index.d.ts.map +0 -1
  266. package/index.js.map +0 -1
  267. package/indexNamedExports-oL6tyaJ9.d.ts +0 -5697
  268. package/indexNamedExports-oL6tyaJ9.d.ts.map +0 -1
  269. package/operators-d-PMVTo7.js +0 -4158
  270. package/operators-d-PMVTo7.js.map +0 -1
  271. package/std/index.d.ts.map +0 -1
  272. package/std/index.js.map +0 -1
  273. package/texture-BagDrrks.js.map +0 -1
@@ -0,0 +1,222 @@
1
+ import { $internal, isMarkedInternal } from "../shared/symbols.js";
2
+ import "tsover-runtime";
3
+ //#region src/data/wgslTypes.ts
4
+ const Void = {
5
+ [$internal]: {},
6
+ type: "void",
7
+ toString() {
8
+ return "void";
9
+ }
10
+ };
11
+ const wgslTypeLiterals = [
12
+ "bool",
13
+ "f32",
14
+ "f16",
15
+ "i32",
16
+ "u32",
17
+ "u16",
18
+ "vec2f",
19
+ "vec2h",
20
+ "vec2i",
21
+ "vec2u",
22
+ "vec2<bool>",
23
+ "vec3f",
24
+ "vec3h",
25
+ "vec3i",
26
+ "vec3u",
27
+ "vec3<bool>",
28
+ "vec4f",
29
+ "vec4h",
30
+ "vec4i",
31
+ "vec4u",
32
+ "vec4<bool>",
33
+ "mat2x2f",
34
+ "mat3x3f",
35
+ "mat4x4f",
36
+ "struct",
37
+ "array",
38
+ "ptr",
39
+ "atomic",
40
+ "decorated",
41
+ "abstractInt",
42
+ "abstractFloat",
43
+ "void",
44
+ "texture_1d",
45
+ "texture_storage_1d",
46
+ "texture_2d",
47
+ "texture_storage_2d",
48
+ "texture_multisampled_2d",
49
+ "texture_depth_2d",
50
+ "texture_depth_multisampled_2d",
51
+ "texture_2d_array",
52
+ "texture_storage_2d_array",
53
+ "texture_depth_2d_array",
54
+ "texture_cube",
55
+ "texture_depth_cube",
56
+ "texture_cube_array",
57
+ "texture_depth_cube_array",
58
+ "texture_3d",
59
+ "texture_storage_3d",
60
+ "texture_external",
61
+ "sampler",
62
+ "sampler_comparison"
63
+ ];
64
+ function isVecInstance(value) {
65
+ const v = value;
66
+ return isMarkedInternal(v) && typeof v.kind === "string" && v.kind.startsWith("vec");
67
+ }
68
+ function isVec2(value) {
69
+ const v = value;
70
+ return isMarkedInternal(v) && typeof v.type === "string" && v.type.startsWith("vec2");
71
+ }
72
+ function isVec3(value) {
73
+ const v = value;
74
+ return isMarkedInternal(v) && typeof v.type === "string" && v.type.startsWith("vec3");
75
+ }
76
+ function isVec4(value) {
77
+ const v = value;
78
+ return isMarkedInternal(v) && typeof v.type === "string" && v.type.startsWith("vec4");
79
+ }
80
+ function isVec(value) {
81
+ return isVec2(value) || isVec3(value) || isVec4(value);
82
+ }
83
+ function isVecBool(value) {
84
+ return isVec(value) && value.type.includes("b");
85
+ }
86
+ function isMatInstance(value) {
87
+ const v = value;
88
+ return isMarkedInternal(v) && typeof v.kind?.startsWith === "function" && v.kind.startsWith("mat");
89
+ }
90
+ function isMat2x2f(value) {
91
+ return isMarkedInternal(value) && value?.type === "mat2x2f";
92
+ }
93
+ function isMat3x3f(value) {
94
+ return isMarkedInternal(value) && value?.type === "mat3x3f";
95
+ }
96
+ function isMat4x4f(value) {
97
+ return isMarkedInternal(value) && value?.type === "mat4x4f";
98
+ }
99
+ function isMat(value) {
100
+ return isMat2x2f(value) || isMat3x3f(value) || isMat4x4f(value);
101
+ }
102
+ function isFloat32VecInstance(element) {
103
+ return isVecInstance(element) && [
104
+ "vec2f",
105
+ "vec3f",
106
+ "vec4f"
107
+ ].includes(element.kind);
108
+ }
109
+ function isInteger32VecInstance(value) {
110
+ return isVecInstance(value) && /[iu]$/.test(value.kind);
111
+ }
112
+ function isUint32VecInstance(value) {
113
+ return isVecInstance(value) && /[u]$/.test(value.kind);
114
+ }
115
+ function isWgslData(value) {
116
+ return isMarkedInternal(value) && wgslTypeLiterals.includes(value?.type);
117
+ }
118
+ /**
119
+ * Checks whether passed in value is an array schema,
120
+ * as opposed to, e.g., a disarray schema.
121
+ *
122
+ * Array schemas can be used to describe uniform and storage buffers,
123
+ * whereas disarray schemas cannot.
124
+ *
125
+ * @example
126
+ * isWgslArray(d.arrayOf(d.u32, 4)) // true
127
+ * isWgslArray(d.disarray(d.u32, 4)) // false
128
+ * isWgslArray(d.vec3f) // false
129
+ */
130
+ function isWgslArray(schema) {
131
+ return isMarkedInternal(schema) && schema?.type === "array";
132
+ }
133
+ /**
134
+ * Checks whether passed in value is a struct schema,
135
+ * as opposed to, e.g., an unstruct schema.
136
+ *
137
+ * Struct schemas can be used to describe uniform and storage buffers,
138
+ * whereas unstruct schemas cannot.
139
+ *
140
+ * @example
141
+ * isWgslStruct(d.struct({ a: d.u32 })) // true
142
+ * isWgslStruct(d.unstruct({ a: d.u32 })) // false
143
+ * isWgslStruct(d.vec3f) // false
144
+ */
145
+ function isWgslStruct(schema) {
146
+ return isMarkedInternal(schema) && schema?.type === "struct";
147
+ }
148
+ /**
149
+ * Checks whether passed in value is a pointer schema.
150
+ *
151
+ * @example
152
+ * isPtr(d.ptrFn(d.f32)) // true
153
+ * isPtr(d.ptrPrivate(d.f32)) // true
154
+ * isPtr(d.f32) // false
155
+ */
156
+ function isPtr(schema) {
157
+ return isMarkedInternal(schema) && schema?.type === "ptr";
158
+ }
159
+ /**
160
+ * Checks whether the passed in value is an atomic schema.
161
+ *
162
+ * @example
163
+ * isAtomic(d.atomic(d.u32)) // true
164
+ * isAtomic(d.u32) // false
165
+ */
166
+ function isAtomic(schema) {
167
+ return isMarkedInternal(schema) && schema?.type === "atomic";
168
+ }
169
+ function isAlignAttrib(value) {
170
+ return isMarkedInternal(value) && value?.type === "@align";
171
+ }
172
+ function isSizeAttrib(value) {
173
+ return isMarkedInternal(value) && value?.type === "@size";
174
+ }
175
+ function isLocationAttrib(value) {
176
+ return isMarkedInternal(value) && value?.type === "@location";
177
+ }
178
+ function isInterpolateAttrib(value) {
179
+ return isMarkedInternal(value) && value?.type === "@interpolate";
180
+ }
181
+ function isBuiltinAttrib(value) {
182
+ return isMarkedInternal(value) && value?.type === "@builtin";
183
+ }
184
+ function isDecorated(value) {
185
+ return isMarkedInternal(value) && value?.type === "decorated";
186
+ }
187
+ function isVoid(value) {
188
+ return isMarkedInternal(value) && value.type === "void";
189
+ }
190
+ function isBool(value) {
191
+ return isMarkedInternal(value) && value.type === "bool";
192
+ }
193
+ function isNumericSchema(schema) {
194
+ const type = schema?.type;
195
+ return isMarkedInternal(schema) && (type === "abstractInt" || type === "abstractFloat" || type === "f32" || type === "f16" || type === "i32" || type === "u32");
196
+ }
197
+ function isHalfPrecisionSchema(schema) {
198
+ const type = schema?.type;
199
+ return isMarkedInternal(schema) && (type === "f16" || type === "vec2h" || type === "vec3h" || type === "vec4h");
200
+ }
201
+ const ephemeralTypes = [
202
+ "abstractInt",
203
+ "abstractFloat",
204
+ "f32",
205
+ "f16",
206
+ "i32",
207
+ "u32",
208
+ "bool"
209
+ ];
210
+ /**
211
+ * Returns true for schemas that are not naturally referential in JS (primitives).
212
+ * @param schema
213
+ * @returns
214
+ */
215
+ function isNaturallyEphemeral(schema) {
216
+ return !isMarkedInternal(schema) || ephemeralTypes.includes(schema?.type);
217
+ }
218
+ function WORKAROUND_getSchema(vec) {
219
+ return vec.schema;
220
+ }
221
+ //#endregion
222
+ export { Void, WORKAROUND_getSchema, isAlignAttrib, isAtomic, isBool, isBuiltinAttrib, isDecorated, isFloat32VecInstance, isHalfPrecisionSchema, isInteger32VecInstance, isInterpolateAttrib, isLocationAttrib, isMat, isMat2x2f, isMat3x3f, isMatInstance, isNaturallyEphemeral, isNumericSchema, isPtr, isSizeAttrib, isUint32VecInstance, 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,131 @@
1
+ import { DEV, TEST } from "./shared/env.js";
2
+ import { getName, hasTinyestMetadata } from "./shared/meta.js";
3
+ //#region src/errors.ts
4
+ const prefix = "Invariant failed";
5
+ /**
6
+ * Inspired by: https://github.com/alexreardon/tiny-invariant/blob/master/src/tiny-invariant.ts
7
+ */
8
+ function invariant(condition, message) {
9
+ if (condition) return;
10
+ if (!DEV && !TEST) throw new Error(prefix);
11
+ const provided = typeof message === "function" ? message() : message;
12
+ const value = provided ? `${prefix}: ${provided}` : prefix;
13
+ throw new Error(value);
14
+ }
15
+ /**
16
+ * An error that happens during resolution of WGSL code.
17
+ * Contains a trace of all ancestor resolvables in
18
+ * which this error originated.
19
+ *
20
+ * @category Errors
21
+ */
22
+ var ResolutionError = class ResolutionError extends Error {
23
+ cause;
24
+ trace;
25
+ constructor(cause, trace) {
26
+ let entries = trace.map((ancestor) => `- ${hasTinyestMetadata(ancestor) ? `fn*:${getName(ancestor)}` : ancestor}`);
27
+ if (entries.length > 20) entries = [
28
+ ...entries.slice(0, 11),
29
+ "...",
30
+ ...entries.slice(-10)
31
+ ];
32
+ super(`Resolution of the following tree failed:\n${entries.join("\n")}: ${cause && typeof cause === "object" && "message" in cause ? cause.message : cause}`);
33
+ this.cause = cause;
34
+ this.trace = trace;
35
+ Object.setPrototypeOf(this, ResolutionError.prototype);
36
+ }
37
+ appendToTrace(ancestor) {
38
+ const newTrace = [ancestor, ...this.trace];
39
+ return new ResolutionError(this.cause, newTrace);
40
+ }
41
+ };
42
+ /**
43
+ * An error that happens during execution of TypeGPU functions.
44
+ * Contains a trace of all TypeGPU functions called along the way.
45
+ *
46
+ * @category Errors
47
+ */
48
+ var ExecutionError = class ExecutionError extends Error {
49
+ cause;
50
+ trace;
51
+ constructor(cause, trace) {
52
+ let entries = trace.map((ancestor) => `- ${ancestor}`);
53
+ if (entries.length > 20) entries = [
54
+ ...entries.slice(0, 11),
55
+ "...",
56
+ ...entries.slice(-10)
57
+ ];
58
+ super(`Execution of the following tree failed:\n${entries.join("\n")}: ${cause && typeof cause === "object" && "message" in cause ? cause.message : cause}`);
59
+ this.cause = cause;
60
+ this.trace = trace;
61
+ Object.setPrototypeOf(this, ExecutionError.prototype);
62
+ }
63
+ appendToTrace(ancestor) {
64
+ const newTrace = [ancestor, ...this.trace];
65
+ return new ExecutionError(this.cause, newTrace);
66
+ }
67
+ };
68
+ /**
69
+ * @category Errors
70
+ */
71
+ var MissingSlotValueError = class MissingSlotValueError extends Error {
72
+ slot;
73
+ constructor(slot) {
74
+ super(`Missing value for '${slot}'`);
75
+ this.slot = slot;
76
+ Object.setPrototypeOf(this, MissingSlotValueError.prototype);
77
+ }
78
+ };
79
+ /**
80
+ * @category Errors
81
+ */
82
+ var NotUniformError = class NotUniformError extends Error {
83
+ constructor(value) {
84
+ super(`Buffer '${getName(value) ?? "<unnamed>"}' is not bindable as a uniform. Use .$usage('uniform') to allow it.`);
85
+ Object.setPrototypeOf(this, NotUniformError.prototype);
86
+ }
87
+ };
88
+ var MissingLinksError = class MissingLinksError extends Error {
89
+ constructor(fnLabel, externalNames) {
90
+ super(`The function '${fnLabel ?? "<unnamed>"}' is missing links to the following external values: ${externalNames}.`);
91
+ Object.setPrototypeOf(this, MissingLinksError.prototype);
92
+ }
93
+ };
94
+ var MissingBindGroupsError = class MissingBindGroupsError extends Error {
95
+ constructor(layouts) {
96
+ super(`Missing bind groups for layouts: '${[...layouts].map((layout) => getName(layout) ?? "<unnamed>").join(", ")}'. Please provide it using pipeline.with(bindGroup).(...)`);
97
+ Object.setPrototypeOf(this, MissingBindGroupsError.prototype);
98
+ }
99
+ };
100
+ var MissingVertexBuffersError = class MissingVertexBuffersError extends Error {
101
+ constructor(layouts) {
102
+ super(`Missing vertex buffers for layouts: '${[...layouts].map((layout) => getName(layout) ?? "<unnamed>").join(", ")}'. Please provide it using pipeline.with(layout, buffer).(...)`);
103
+ Object.setPrototypeOf(this, MissingVertexBuffersError.prototype);
104
+ }
105
+ };
106
+ var IllegalVarAccessError = class IllegalVarAccessError extends Error {
107
+ constructor(msg) {
108
+ super(msg);
109
+ Object.setPrototypeOf(this, IllegalVarAccessError.prototype);
110
+ }
111
+ };
112
+ var IllegalBufferAccessError = class IllegalBufferAccessError extends Error {
113
+ constructor(msg) {
114
+ super(msg);
115
+ Object.setPrototypeOf(this, IllegalBufferAccessError.prototype);
116
+ }
117
+ };
118
+ var WgslTypeError = class WgslTypeError extends Error {
119
+ constructor(msg) {
120
+ super(msg);
121
+ Object.setPrototypeOf(this, WgslTypeError.prototype);
122
+ }
123
+ };
124
+ var SignatureNotSupportedError = class SignatureNotSupportedError extends Error {
125
+ constructor(actual, candidates) {
126
+ super(`Unsupported data types: ${actual.map((a) => a.type).join(", ")}. Supported types are: ${candidates.map((r) => r.type).join(", ")}.`);
127
+ Object.setPrototypeOf(this, SignatureNotSupportedError.prototype);
128
+ }
129
+ };
130
+ //#endregion
131
+ export { ExecutionError, IllegalBufferAccessError, IllegalVarAccessError, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, ResolutionError, SignatureNotSupportedError, WgslTypeError, invariant };
package/execMode.js ADDED
@@ -0,0 +1,49 @@
1
+ import { invariant } from "./errors.js";
2
+ import { NormalState } from "./types.js";
3
+ //#region src/execMode.ts
4
+ /**
5
+ * Used to track if the code we're currently
6
+ * executing is inside an executing TypeGPU function.
7
+ *
8
+ * Helpful for providing better error messages.
9
+ */
10
+ let insideTgpuFn = false;
11
+ function provideInsideTgpuFn(callback) {
12
+ if (insideTgpuFn) return callback();
13
+ try {
14
+ insideTgpuFn = true;
15
+ return callback();
16
+ } finally {
17
+ insideTgpuFn = false;
18
+ }
19
+ }
20
+ function isInsideTgpuFn() {
21
+ return insideTgpuFn;
22
+ }
23
+ let resolutionCtx;
24
+ function provideCtx(ctx, callback) {
25
+ invariant(resolutionCtx === void 0 || resolutionCtx === ctx, "Cannot nest context providers");
26
+ if (resolutionCtx === ctx) return callback();
27
+ resolutionCtx = ctx;
28
+ try {
29
+ return callback();
30
+ } finally {
31
+ resolutionCtx = void 0;
32
+ }
33
+ }
34
+ function getResolutionCtx() {
35
+ return resolutionCtx;
36
+ }
37
+ /**
38
+ * Applicable when code is being executed outside of any
39
+ * execution-altering APIs.
40
+ */
41
+ const topLevelState = new NormalState();
42
+ function getExecMode() {
43
+ return resolutionCtx?.mode ?? topLevelState;
44
+ }
45
+ function inCodegenMode() {
46
+ return resolutionCtx?.mode.type === "codegen";
47
+ }
48
+ //#endregion
49
+ 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,16 @@
1
+ import { getName } from "./shared/meta.js";
2
+ //#region src/extension.ts
3
+ function isUsableAsStorage(value) {
4
+ return !!value?.usableAsStorage;
5
+ }
6
+ /**
7
+ * @category Errors
8
+ */
9
+ var NotStorageError = class NotStorageError extends Error {
10
+ constructor(value) {
11
+ super(`Resource '${getName(value) ?? "<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`);
12
+ Object.setPrototypeOf(this, NotStorageError.prototype);
13
+ }
14
+ };
15
+ //#endregion
16
+ export { NotStorageError, isUsableAsStorage };
package/getGPUValue.js ADDED
@@ -0,0 +1,7 @@
1
+ import { $gpuValueOf } from "./shared/symbols.js";
2
+ //#region src/getGPUValue.ts
3
+ function getGPUValue(object) {
4
+ return object?.[$gpuValueOf];
5
+ }
6
+ //#endregion
7
+ export { getGPUValue };