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
package/data/matrix.js ADDED
@@ -0,0 +1,517 @@
1
+ import { $internal, $resolve } from "../shared/symbols.js";
2
+ import { isVec } from "./wgslTypes.js";
3
+ import { snip } from "./snippet.js";
4
+ import { stitch } from "../core/resolve/stitch.js";
5
+ import { callableSchema } from "../core/function/createCallableSchema.js";
6
+ import { f32 } from "./numeric.js";
7
+ import { vec2f, vec3f, vec4f } from "./vector.js";
8
+ import { dualImpl } from "../core/function/dualImpl.js";
9
+ import { comptime } from "../core/function/comptime.js";
10
+
11
+ //#region src/data/matrix.ts
12
+ var MatBase = class {};
13
+ function createMatSchema(options) {
14
+ const construct = callableSchema({
15
+ name: options.type,
16
+ normalImpl: (...args) => {
17
+ const elements = [];
18
+ for (const arg of args) if (typeof arg === "number") elements.push(arg);
19
+ else for (let i = 0; i < arg.length; ++i) elements.push(arg[i]);
20
+ if (elements.length !== 0 && elements.length !== options.columns * options.rows) throw new Error(`'${options.type}' constructor called with invalid number of arguments.`);
21
+ for (let i = elements.length; i < options.columns * options.rows; ++i) elements.push(0);
22
+ return new options.MatImpl(...elements);
23
+ },
24
+ signature: (...args) => ({
25
+ argTypes: args.map((arg) => isVec(arg) ? arg : f32),
26
+ returnType: schema
27
+ }),
28
+ codegenImpl: (_ctx, args) => stitch`${options.type}(${args})`
29
+ });
30
+ const schema = Object.assign(construct, {
31
+ [$internal]: {},
32
+ type: options.type,
33
+ primitive: f32,
34
+ identity: identityFunctions[options.columns],
35
+ translation: options.columns === 4 ? translation4 : void 0,
36
+ scaling: options.columns === 4 ? scaling4 : void 0,
37
+ rotationX: options.columns === 4 ? rotationX4 : void 0,
38
+ rotationY: options.columns === 4 ? rotationY4 : void 0,
39
+ rotationZ: options.columns === 4 ? rotationZ4 : void 0
40
+ });
41
+ options.MatImpl.prototype.schema = schema;
42
+ return schema;
43
+ }
44
+ var mat2x2Impl = class extends MatBase {
45
+ [$internal] = true;
46
+ columns;
47
+ length = 4;
48
+ constructor(...elements) {
49
+ super();
50
+ this.columns = [this.makeColumn(elements[0], elements[1]), this.makeColumn(elements[2], elements[3])];
51
+ }
52
+ get 0() {
53
+ return this.columns[0].x;
54
+ }
55
+ get 1() {
56
+ return this.columns[0].y;
57
+ }
58
+ get 2() {
59
+ return this.columns[1].x;
60
+ }
61
+ get 3() {
62
+ return this.columns[1].y;
63
+ }
64
+ set 0(value) {
65
+ this.columns[0].x = value;
66
+ }
67
+ set 1(value) {
68
+ this.columns[0].y = value;
69
+ }
70
+ set 2(value) {
71
+ this.columns[1].x = value;
72
+ }
73
+ set 3(value) {
74
+ this.columns[1].y = value;
75
+ }
76
+ *[Symbol.iterator]() {
77
+ yield this[0];
78
+ yield this[1];
79
+ yield this[2];
80
+ yield this[3];
81
+ }
82
+ [$resolve]() {
83
+ return snip(`${this.kind}(${Array.from({ length: this.length }).map((_, i) => this[i]).join(", ")})`, mat2x2f, "runtime");
84
+ }
85
+ toString() {
86
+ return this[$resolve]().value;
87
+ }
88
+ };
89
+ var mat2x2fImpl = class extends mat2x2Impl {
90
+ kind = "mat2x2f";
91
+ makeColumn(e0, e1) {
92
+ return vec2f(e0, e1);
93
+ }
94
+ };
95
+ var mat3x3Impl = class extends MatBase {
96
+ [$internal] = true;
97
+ columns;
98
+ length = 12;
99
+ constructor(...elements) {
100
+ super();
101
+ this.columns = [
102
+ this.makeColumn(elements[0], elements[1], elements[2]),
103
+ this.makeColumn(elements[3], elements[4], elements[5]),
104
+ this.makeColumn(elements[6], elements[7], elements[8])
105
+ ];
106
+ }
107
+ get 0() {
108
+ return this.columns[0].x;
109
+ }
110
+ get 1() {
111
+ return this.columns[0].y;
112
+ }
113
+ get 2() {
114
+ return this.columns[0].z;
115
+ }
116
+ get 3() {
117
+ return 0;
118
+ }
119
+ get 4() {
120
+ return this.columns[1].x;
121
+ }
122
+ get 5() {
123
+ return this.columns[1].y;
124
+ }
125
+ get 6() {
126
+ return this.columns[1].z;
127
+ }
128
+ get 7() {
129
+ return 0;
130
+ }
131
+ get 8() {
132
+ return this.columns[2].x;
133
+ }
134
+ get 9() {
135
+ return this.columns[2].y;
136
+ }
137
+ get 10() {
138
+ return this.columns[2].z;
139
+ }
140
+ get 11() {
141
+ return 0;
142
+ }
143
+ set 0(value) {
144
+ this.columns[0].x = value;
145
+ }
146
+ set 1(value) {
147
+ this.columns[0].y = value;
148
+ }
149
+ set 2(value) {
150
+ this.columns[0].z = value;
151
+ }
152
+ set 3(_) {}
153
+ set 4(value) {
154
+ this.columns[1].x = value;
155
+ }
156
+ set 5(value) {
157
+ this.columns[1].y = value;
158
+ }
159
+ set 6(value) {
160
+ this.columns[1].z = value;
161
+ }
162
+ set 7(_) {}
163
+ set 8(value) {
164
+ this.columns[2].x = value;
165
+ }
166
+ set 9(value) {
167
+ this.columns[2].y = value;
168
+ }
169
+ set 10(value) {
170
+ this.columns[2].z = value;
171
+ }
172
+ set 11(_) {}
173
+ *[Symbol.iterator]() {
174
+ for (let i = 0; i < 12; i++) yield this[i];
175
+ }
176
+ [$resolve]() {
177
+ return snip(`${this.kind}(${this[0]}, ${this[1]}, ${this[2]}, ${this[4]}, ${this[5]}, ${this[6]}, ${this[8]}, ${this[9]}, ${this[10]})`, mat3x3f, "runtime");
178
+ }
179
+ toString() {
180
+ return this[$resolve]().value;
181
+ }
182
+ };
183
+ var mat3x3fImpl = class extends mat3x3Impl {
184
+ kind = "mat3x3f";
185
+ makeColumn(x, y, z) {
186
+ return vec3f(x, y, z);
187
+ }
188
+ };
189
+ var mat4x4Impl = class extends MatBase {
190
+ [$internal] = true;
191
+ columns;
192
+ constructor(...elements) {
193
+ super();
194
+ this.columns = [
195
+ this.makeColumn(elements[0], elements[1], elements[2], elements[3]),
196
+ this.makeColumn(elements[4], elements[5], elements[6], elements[7]),
197
+ this.makeColumn(elements[8], elements[9], elements[10], elements[11]),
198
+ this.makeColumn(elements[12], elements[13], elements[14], elements[15])
199
+ ];
200
+ }
201
+ length = 16;
202
+ get 0() {
203
+ return this.columns[0].x;
204
+ }
205
+ get 1() {
206
+ return this.columns[0].y;
207
+ }
208
+ get 2() {
209
+ return this.columns[0].z;
210
+ }
211
+ get 3() {
212
+ return this.columns[0].w;
213
+ }
214
+ get 4() {
215
+ return this.columns[1].x;
216
+ }
217
+ get 5() {
218
+ return this.columns[1].y;
219
+ }
220
+ get 6() {
221
+ return this.columns[1].z;
222
+ }
223
+ get 7() {
224
+ return this.columns[1].w;
225
+ }
226
+ get 8() {
227
+ return this.columns[2].x;
228
+ }
229
+ get 9() {
230
+ return this.columns[2].y;
231
+ }
232
+ get 10() {
233
+ return this.columns[2].z;
234
+ }
235
+ get 11() {
236
+ return this.columns[2].w;
237
+ }
238
+ get 12() {
239
+ return this.columns[3].x;
240
+ }
241
+ get 13() {
242
+ return this.columns[3].y;
243
+ }
244
+ get 14() {
245
+ return this.columns[3].z;
246
+ }
247
+ get 15() {
248
+ return this.columns[3].w;
249
+ }
250
+ set 0(value) {
251
+ this.columns[0].x = value;
252
+ }
253
+ set 1(value) {
254
+ this.columns[0].y = value;
255
+ }
256
+ set 2(value) {
257
+ this.columns[0].z = value;
258
+ }
259
+ set 3(value) {
260
+ this.columns[0].w = value;
261
+ }
262
+ set 4(value) {
263
+ this.columns[1].x = value;
264
+ }
265
+ set 5(value) {
266
+ this.columns[1].y = value;
267
+ }
268
+ set 6(value) {
269
+ this.columns[1].z = value;
270
+ }
271
+ set 7(value) {
272
+ this.columns[1].w = value;
273
+ }
274
+ set 8(value) {
275
+ this.columns[2].x = value;
276
+ }
277
+ set 9(value) {
278
+ this.columns[2].y = value;
279
+ }
280
+ set 10(value) {
281
+ this.columns[2].z = value;
282
+ }
283
+ set 11(value) {
284
+ this.columns[2].w = value;
285
+ }
286
+ set 12(value) {
287
+ this.columns[3].x = value;
288
+ }
289
+ set 13(value) {
290
+ this.columns[3].y = value;
291
+ }
292
+ set 14(value) {
293
+ this.columns[3].z = value;
294
+ }
295
+ set 15(value) {
296
+ this.columns[3].w = value;
297
+ }
298
+ *[Symbol.iterator]() {
299
+ for (let i = 0; i < 16; i++) yield this[i];
300
+ }
301
+ [$resolve]() {
302
+ return snip(`${this.kind}(${Array.from({ length: this.length }).map((_, i) => this[i]).join(", ")})`, mat4x4f, "runtime");
303
+ }
304
+ toString() {
305
+ return this[$resolve]().value;
306
+ }
307
+ };
308
+ var mat4x4fImpl = class extends mat4x4Impl {
309
+ kind = "mat4x4f";
310
+ makeColumn(x, y, z, w) {
311
+ return vec4f(x, y, z, w);
312
+ }
313
+ };
314
+ /**
315
+ * Returns a 2-by-2 identity matrix.
316
+ * @returns {m2x2f} The result matrix.
317
+ */
318
+ const identity2 = comptime(() => mat2x2f(1, 0, 0, 1)).$name("identity2");
319
+ /**
320
+ * Returns a 3-by-3 identity matrix.
321
+ * @returns {m3x3f} The result matrix.
322
+ */
323
+ const identity3 = comptime(() => mat3x3f(1, 0, 0, 0, 1, 0, 0, 0, 1)).$name("identity3");
324
+ /**
325
+ * Returns a 4-by-4 identity matrix.
326
+ * @returns {m4x4f} The result matrix.
327
+ */
328
+ const identity4 = comptime(() => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)).$name("identity4");
329
+ const identityFunctions = {
330
+ 2: identity2,
331
+ 3: identity3,
332
+ 4: identity4
333
+ };
334
+ /**
335
+ * Creates a 4-by-4 matrix which translates by the given vector v.
336
+ * @param {v3f} vector - The vector by which to translate.
337
+ * @returns {m4x4f} The translation matrix.
338
+ */
339
+ const translation4 = dualImpl({
340
+ name: "translation4",
341
+ normalImpl: (vector) => mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, vector.x, vector.y, vector.z, 1),
342
+ get signature() {
343
+ return {
344
+ argTypes: [vec3f],
345
+ returnType: mat4x4f
346
+ };
347
+ },
348
+ codegenImpl: (_ctx, [v]) => stitch`mat4x4f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, ${v}.x, ${v}.y, ${v}.z, 1)`
349
+ });
350
+ /**
351
+ * Creates a 4-by-4 matrix which scales in each dimension by an amount given by the corresponding entry in the given vector.
352
+ * @param {v3f} vector - A vector of three entries specifying the factor by which to scale in each dimension.
353
+ * @returns {m4x4f} The scaling matrix.
354
+ */
355
+ const scaling4 = dualImpl({
356
+ name: "scaling4",
357
+ normalImpl: (vector) => mat4x4f(vector.x, 0, 0, 0, 0, vector.y, 0, 0, 0, 0, vector.z, 0, 0, 0, 0, 1),
358
+ get signature() {
359
+ return {
360
+ argTypes: [vec3f],
361
+ returnType: mat4x4f
362
+ };
363
+ },
364
+ codegenImpl: (_ctx, [v]) => stitch`mat4x4f(${v}.x, 0, 0, 0, 0, ${v}.y, 0, 0, 0, 0, ${v}.z, 0, 0, 0, 0, 1)`
365
+ });
366
+ /**
367
+ * Creates a 4-by-4 matrix which rotates around the x-axis by the given angle.
368
+ * @param {number} angle - The angle by which to rotate (in radians).
369
+ * @returns {m4x4f} The rotation matrix.
370
+ */
371
+ const rotationX4 = dualImpl({
372
+ name: "rotationX4",
373
+ normalImpl: (a) => mat4x4f(1, 0, 0, 0, 0, Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1),
374
+ get signature() {
375
+ return {
376
+ argTypes: [f32],
377
+ returnType: mat4x4f
378
+ };
379
+ },
380
+ codegenImpl: (_ctx, [a]) => stitch`mat4x4f(1, 0, 0, 0, 0, cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1)`
381
+ });
382
+ /**
383
+ * Creates a 4-by-4 matrix which rotates around the y-axis by the given angle.
384
+ * @param {number} angle - The angle by which to rotate (in radians).
385
+ * @returns {m4x4f} The rotation matrix.
386
+ */
387
+ const rotationY4 = dualImpl({
388
+ name: "rotationY4",
389
+ normalImpl: (a) => mat4x4f(Math.cos(a), 0, -Math.sin(a), 0, 0, 1, 0, 0, Math.sin(a), 0, Math.cos(a), 0, 0, 0, 0, 1),
390
+ get signature() {
391
+ return {
392
+ argTypes: [f32],
393
+ returnType: mat4x4f
394
+ };
395
+ },
396
+ codegenImpl: (_ctx, [a]) => stitch`mat4x4f(cos(${a}), 0, -sin(${a}), 0, 0, 1, 0, 0, sin(${a}), 0, cos(${a}), 0, 0, 0, 0, 1)`
397
+ });
398
+ /**
399
+ * Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
400
+ * @param {number} angle - The angle by which to rotate (in radians).
401
+ * @returns {m4x4f} The rotation matrix.
402
+ */
403
+ const rotationZ4 = dualImpl({
404
+ name: "rotationZ4",
405
+ normalImpl: (a) => mat4x4f(Math.cos(a), Math.sin(a), 0, 0, -Math.sin(a), Math.cos(a), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),
406
+ get signature() {
407
+ return {
408
+ argTypes: [f32],
409
+ returnType: mat4x4f
410
+ };
411
+ },
412
+ codegenImpl: (_ctx, [a]) => stitch`mat4x4f(cos(${a}), sin(${a}), 0, 0, -sin(${a}), cos(${a}), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)`
413
+ });
414
+ /**
415
+ * Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.
416
+ * Also a constructor function for this matrix type.
417
+ *
418
+ * @example
419
+ * const zero2x2 = mat2x2f(); // filled with zeros
420
+ *
421
+ * @example
422
+ * const mat = mat2x2f(0, 1, 2, 3);
423
+ * mat.columns[0] // vec2f(0, 1)
424
+ * mat.columns[1] // vec2f(2, 3)
425
+ *
426
+ * @example
427
+ * const mat = mat2x2f(
428
+ * vec2f(0, 1), // column 0
429
+ * vec2f(1, 2), // column 1
430
+ * );
431
+ *
432
+ * @example
433
+ * const buffer = root.createBuffer(d.mat2x2f, d.mat2x2f(0, 1, 2, 3)); // buffer holding a d.mat2x2f value, with an initial value of ((0, 1), (2, 3))
434
+ */
435
+ const mat2x2f = createMatSchema({
436
+ type: "mat2x2f",
437
+ rows: 2,
438
+ columns: 2,
439
+ MatImpl: mat2x2fImpl
440
+ });
441
+ /**
442
+ * Schema representing mat3x3f - a matrix with 3 rows and 3 columns, with elements of type f32.
443
+ * Also a constructor function for this matrix type.
444
+ *
445
+ * @example
446
+ * const zero3x3 = mat3x3f(); // filled with zeros
447
+ *
448
+ * @example
449
+ * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8);
450
+ * mat.columns[0] // vec3f(0, 1, 2)
451
+ * mat.columns[1] // vec3f(3, 4, 5)
452
+ * mat.columns[2] // vec3f(6, 7, 8)
453
+ *
454
+ * @example
455
+ * const mat = mat3x3f(
456
+ * vec3f(0, 1, 2), // column 0
457
+ * vec3f(2, 3, 4), // column 1
458
+ * vec3f(5, 6, 7), // column 2
459
+ * );
460
+ *
461
+ * @example
462
+ * const buffer = root.createBuffer(d.mat3x3f, d.mat3x3f()); // buffer holding a d.mat3x3f value, with an initial value of mat3x3f filled with zeros
463
+ */
464
+ const mat3x3f = createMatSchema({
465
+ type: "mat3x3f",
466
+ rows: 3,
467
+ columns: 3,
468
+ MatImpl: mat3x3fImpl
469
+ });
470
+ /**
471
+ * Schema representing mat4x4f - a matrix with 4 rows and 4 columns, with elements of type f32.
472
+ * Also a constructor function for this matrix type.
473
+ *
474
+ * @example
475
+ * const zero4x4 = mat4x4f(); // filled with zeros
476
+ *
477
+ * @example
478
+ * const mat = mat4x4f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
479
+ * mat.columns[0] // vec4f(0, 1, 2, 3)
480
+ * mat.columns[1] // vec4f(4, 5, 6, 7)
481
+ * mat.columns[2] // vec4f(8, 9, 10, 11)
482
+ * mat.columns[3] // vec4f(12, 13, 14, 15)
483
+ *
484
+ * @example
485
+ * const mat = mat4x4f(
486
+ * vec4f(0, 1, 2, 3), // column 0
487
+ * vec4f(4, 5, 6, 7), // column 1
488
+ * vec4f(8, 9, 10, 11), // column 2
489
+ * vec4f(12, 13, 14, 15), // column 3
490
+ * );
491
+ *
492
+ * @example
493
+ * const buffer = root.createBuffer(d.mat4x4f, d.mat4x4f()); // buffer holding a d.mat4x4f value, with an initial value of mat4x4f filled with zeros
494
+ */
495
+ const mat4x4f = createMatSchema({
496
+ type: "mat4x4f",
497
+ rows: 4,
498
+ columns: 4,
499
+ MatImpl: mat4x4fImpl
500
+ });
501
+ function matToArray(mat) {
502
+ if (mat.kind === "mat3x3f") return [
503
+ mat[0],
504
+ mat[1],
505
+ mat[2],
506
+ mat[4],
507
+ mat[5],
508
+ mat[6],
509
+ mat[8],
510
+ mat[9],
511
+ mat[10]
512
+ ];
513
+ return Array.from({ length: mat.length }).map((_, idx) => mat[idx]);
514
+ }
515
+
516
+ //#endregion
517
+ export { MatBase, identity2, identity3, identity4, mat2x2f, mat3x3f, mat4x4f, matToArray, rotationX4, rotationY4, rotationZ4, scaling4, translation4 };
@@ -0,0 +1,24 @@
1
+ //#region src/data/numberOps.ts
2
+ const smoothstepScalar = (edge0, edge1, x) => {
3
+ if (edge0 === edge1) return 0;
4
+ const t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
5
+ return t * t * (3 - 2 * t);
6
+ };
7
+ const clamp = (value, low, high) => Math.min(Math.max(low, value), high);
8
+ const divInteger = (lhs, rhs) => {
9
+ if (rhs === 0) return lhs;
10
+ return Math.trunc(lhs / rhs);
11
+ };
12
+ function bitcastU32toF32Impl(n) {
13
+ const dataView = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(4));
14
+ dataView.setUint32(0, n, true);
15
+ return dataView.getFloat32(0, true);
16
+ }
17
+ function bitcastU32toI32Impl(n) {
18
+ const dataView = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(4));
19
+ dataView.setUint32(0, n, true);
20
+ return dataView.getInt32(0, true);
21
+ }
22
+
23
+ //#endregion
24
+ export { bitcastU32toF32Impl, bitcastU32toI32Impl, clamp, divInteger, smoothstepScalar };
@@ -0,0 +1,81 @@
1
+ import { Bool, F16, F32, I32, U16, U32 } from "./wgslTypes.js";
2
+
3
+ //#region src/data/numeric.d.ts
4
+ /**
5
+ * A schema that represents a boolean value. (equivalent to `bool` in WGSL)
6
+ *
7
+ * Can also be called to cast a value to a bool in accordance with WGSL casting rules.
8
+ *
9
+ * @example
10
+ * const value = bool(); // false
11
+ * @example
12
+ * const value = bool(0); // false
13
+ * @example
14
+ * const value = bool(-0); // false
15
+ * @example
16
+ * const value = bool(21.37); // true
17
+ */
18
+ declare const bool: Bool;
19
+ /**
20
+ * A schema that represents an unsigned 32-bit integer value. (equivalent to `u32` in WGSL)
21
+ *
22
+ * Can also be called to cast a value to an u32 in accordance with WGSL casting rules.
23
+ *
24
+ * @example
25
+ * const value = u32(); // 0
26
+ * @example
27
+ * const value = u32(7); // 7
28
+ * @example
29
+ * const value = u32(3.14); // 3
30
+ * @example
31
+ * const value = u32(-1); // 4294967295
32
+ * @example
33
+ * const value = u32(-3.1); // 0
34
+ */
35
+ declare const u32: U32;
36
+ declare const u16: U16;
37
+ /**
38
+ * A schema that represents a signed 32-bit integer value. (equivalent to `i32` in WGSL)
39
+ *
40
+ * Can also be called to cast a value to an i32 in accordance with WGSL casting rules.
41
+ *
42
+ * @example
43
+ * const value = i32(); // 0
44
+ * @example
45
+ * const value = i32(3.14); // 3
46
+ * @example
47
+ * const value = i32(-3.9); // -3
48
+ * @example
49
+ * const value = i32(10000000000) // 1410065408
50
+ */
51
+ declare const i32: I32;
52
+ /**
53
+ * A schema that represents a 32-bit float value. (equivalent to `f32` in WGSL)
54
+ *
55
+ * Can also be called to cast a value to an f32.
56
+ *
57
+ * @example
58
+ * const value = f32(); // 0
59
+ * @example
60
+ * const value = f32(1.23); // 1.23
61
+ * @example
62
+ * const value = f32(true); // 1
63
+ */
64
+ declare const f32: F32;
65
+ /**
66
+ * A schema that represents a 16-bit float value. (equivalent to `f16` in WGSL)
67
+ *
68
+ * Can also be called to cast a value to an f16.
69
+ *
70
+ * @example
71
+ * const value = f16(); // 0
72
+ * @example
73
+ * const value = f32(1.23); // 1.23
74
+ * @example
75
+ * const value = f16(true); // 1
76
+ * @example
77
+ * const value = f16(21877.5); // 21872
78
+ */
79
+ declare const f16: F16;
80
+ //#endregion
81
+ export { bool, f16, f32, i32, u16, u32 };