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