@wonderyard/vivarium 0.1.0

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.
@@ -0,0 +1,4348 @@
1
+ import { a as Pa, j as Sa, U as Q, o as Ia, c as mn, C as ka, u as Ma, p as Aa, b as Ft, l as Et, s as Oa, K as Qt, r as Ga, d as Ba, V as $e, e as re, h as D, Z as lr, f as Oe, t as kr, g as Mr } from "../compiler-CEYR17Vv.js";
2
+ import { a8 as de, $ as Ae, a9 as We, U as f, aa as Fa, ab as Ca, ac as Na, ad as La, ae as Da, af as Wa, ag as za, ah as ze, ai as J, l as Ya, aj as yn, m as Ra, F as Re, p as dr, w as cr, ak as qa, al as ja, J as pr, T as wn, am as gn, x as bn, d as Va, f as ut, u as lt, e as ie, y as be, an as vn, ao as _n, ap as xn, aq as Ja, c as Za, ar as Tn, as as Xa, at as Qa, au as Ka, av as Ha, aw as es, ax as ts, ay as rs, az as ns, aA as as, aB as ss, aC as is, aD as os, aE as us, aF as ls, aG as ds, aH as cs, aI as ps, aJ as hs, aK as fs, aL as ms, aM as ys, aN as $n, aO as ws, V as m, aP as gs, aQ as bs, aR as vs, aS as _s, aT as xs, aU as Ts, aV as $s, aW as Es, aX as Us, aY as Ps, aZ as Ss, a_ as Is, a$ as ks, b0 as Ms, b1 as As, b2 as Os, b3 as Gs, b4 as Bs, b5 as En, b6 as _, b7 as Ke, b8 as K, a3 as ne, b9 as Un, ba as S, bb as He, bc as Ue, R as Ut, bd as Pn, X as O, be as et, bf as te, bg as ue, bh as Fs, bi as Sn, i as c, bj as j, t as g, h as F, bk as Cs, bl as Ar, bm as Me, bn as Or, bo as Gr, bp as Ns, N as ht, bq as Ls, I as Ds, br as Ws, H as Vt, bs as Pt, bt as zs, bu as tt, bv as C, bw as hr, bx as St, by as Br, bz as rt, bA as Y, bB as Ys, bC as In, bD as Pe, bE as Ct, bF as d, o as u, bG as Rs, Y as qs, bH as js, W as Vs, bI as Js, bJ as Zs, bK as p, a as kn, bL as Fr, bM as Nt, bN as fr, bO as Mn, bP as Xs, bQ as Qs, bR as Ks, bS as Hs, bT as Kt, bU as De, D as ei, bV as Cr, bW as Nr, B as ti, bX as ri, bY as ni, bZ as ai, b_ as Lr, b$ as It, c0 as E, q as M, c1 as Z, c2 as ft, E as Dr, c3 as kt, Q as mr, k as A, c4 as yr, c5 as wr, c6 as gr, c7 as br, c8 as si, c9 as vr, r as I, j as An, ca as ii, cb as oi, cc as ui, cd as li, ce as di, cf as Ht, a6 as _e, A as Ve, a4 as Wr, a5 as ci, a2 as pi, a1 as hi } from "../constants-Ry69vZz5.js";
3
+ const W = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4
+ __proto__: null,
5
+ Void: de,
6
+ align: Pa,
7
+ alignmentOf: Sa,
8
+ arrayOf: Q,
9
+ atomic: Ia,
10
+ bool: Ae,
11
+ builtin: mn,
12
+ disarrayOf: ka,
13
+ f16: We,
14
+ f32: f,
15
+ float16: Fa,
16
+ float16x2: Ca,
17
+ float16x4: Na,
18
+ float32: La,
19
+ float32x2: Da,
20
+ float32x3: Wa,
21
+ float32x4: za,
22
+ formatToWGSLType: ze,
23
+ i32: J,
24
+ interpolate: Ma,
25
+ invariant: Aa,
26
+ isAlignAttrib: Ya,
27
+ isAtomic: yn,
28
+ isBuiltin: Ft,
29
+ isBuiltinAttrib: Ra,
30
+ isData: Re,
31
+ isDecorated: dr,
32
+ isDisarray: cr,
33
+ isInterpolateAttrib: qa,
34
+ isLocationAttrib: ja,
35
+ isLooseData: pr,
36
+ isLooseDecorated: wn,
37
+ isPackedData: gn,
38
+ isPtr: bn,
39
+ isSizeAttrib: Va,
40
+ isUnstruct: ut,
41
+ isWgslArray: lt,
42
+ isWgslData: ie,
43
+ isWgslStruct: be,
44
+ location: Et,
45
+ mat2x2f: vn,
46
+ mat3x3f: _n,
47
+ mat4x4f: xn,
48
+ matToArray: Ja,
49
+ packedFormats: Za,
50
+ ptrFn: Tn,
51
+ ptrHandle: Xa,
52
+ ptrPrivate: Qa,
53
+ ptrStorage: Ka,
54
+ ptrUniform: Ha,
55
+ ptrWorkgroup: es,
56
+ sint16: ts,
57
+ sint16x2: rs,
58
+ sint16x4: ns,
59
+ sint32: as,
60
+ sint32x2: ss,
61
+ sint32x3: is,
62
+ sint32x4: os,
63
+ sint8: us,
64
+ sint8x2: ls,
65
+ sint8x4: ds,
66
+ size: Oa,
67
+ sizeOf: Qt,
68
+ snorm16: cs,
69
+ snorm16x2: ps,
70
+ snorm16x4: hs,
71
+ snorm8: fs,
72
+ snorm8x2: ms,
73
+ snorm8x4: ys,
74
+ struct: $n,
75
+ u16: ws,
76
+ u32: m,
77
+ uint16: gs,
78
+ uint16x2: bs,
79
+ uint16x4: vs,
80
+ uint32: _s,
81
+ uint32x2: xs,
82
+ uint32x3: Ts,
83
+ uint32x4: $s,
84
+ uint8: Es,
85
+ uint8x2: Us,
86
+ uint8x4: Ps,
87
+ unorm10_10_10_2: Ss,
88
+ unorm16: Is,
89
+ unorm16x2: ks,
90
+ unorm16x4: Ms,
91
+ unorm8: As,
92
+ unorm8x2: Os,
93
+ unorm8x4: Gs,
94
+ unorm8x4_bgra: Bs,
95
+ unstruct: Ga,
96
+ vec2b: En,
97
+ vec2f: _,
98
+ vec2h: Ke,
99
+ vec2i: K,
100
+ vec2u: ne,
101
+ vec3b: Un,
102
+ vec3f: S,
103
+ vec3h: He,
104
+ vec3i: Ue,
105
+ vec3u: Ut,
106
+ vec4b: Pn,
107
+ vec4f: O,
108
+ vec4h: et,
109
+ vec4i: te,
110
+ vec4u: ue
111
+ }, Symbol.toStringTag, { value: "Module" }));
112
+ var On = Object.defineProperty, fi = (e, t, r) => t in e ? On(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, mi = (e, t) => {
113
+ for (var r in t)
114
+ On(e, r, { get: t[r], enumerable: !0 });
115
+ }, U = (e, t, r) => fi(e, typeof t != "symbol" ? t + "" : t, r), yi = {};
116
+ mi(yi, {
117
+ BufferReader: () => Ee,
118
+ BufferWriter: () => Se,
119
+ MaxValue: () => R,
120
+ Measurer: () => N,
121
+ UnresolvedReferenceError: () => ke,
122
+ ValidationError: () => Lt,
123
+ arrayOf: () => _i,
124
+ bool: () => Ti,
125
+ byte: () => Ii,
126
+ chars: () => Yi,
127
+ concat: () => Vi,
128
+ dynamicArrayOf: () => Zi,
129
+ f16: () => Li,
130
+ f32: () => Wi,
131
+ f32Array: () => po,
132
+ f64Array: () => ho,
133
+ generic: () => qi,
134
+ genericEnum: () => ji,
135
+ i16: () => Mi,
136
+ i16Array: () => lo,
137
+ i32: () => Bi,
138
+ i32Array: () => co,
139
+ i8: () => Pi,
140
+ i8Array: () => uo,
141
+ keyed: () => Ki,
142
+ object: () => Ri,
143
+ optional: () => eo,
144
+ string: () => Ei,
145
+ tupleOf: () => no,
146
+ u16: () => Oi,
147
+ u16Array: () => io,
148
+ u32: () => Ci,
149
+ u32Array: () => oo,
150
+ u8: () => Nn,
151
+ u8Array: () => ao,
152
+ u8ClampedArray: () => so
153
+ });
154
+ var ke = class Gn extends Error {
155
+ constructor(t) {
156
+ super(t), Object.setPrototypeOf(this, Gn.prototype);
157
+ }
158
+ }, Lt = class Bn extends Error {
159
+ constructor(t) {
160
+ super(t), Object.setPrototypeOf(this, Bn.prototype);
161
+ }
162
+ }, wi = class {
163
+ constructor() {
164
+ U(this, "size", Number.NaN), U(this, "unbounded", this), U(this, "isUnbounded", !0);
165
+ }
166
+ add() {
167
+ return this;
168
+ }
169
+ fork() {
170
+ return this;
171
+ }
172
+ }, gi = new wi(), N = class Fn {
173
+ constructor() {
174
+ U(this, "size", 0), U(this, "unbounded", gi), U(this, "isUnbounded", !1);
175
+ }
176
+ add(t) {
177
+ return this.size += t, this;
178
+ }
179
+ fork() {
180
+ const t = new Fn();
181
+ return t.size = this.size, t;
182
+ }
183
+ }, R = Symbol(
184
+ "The biggest (in amount of bytes needed) value a schema can represent"
185
+ ), X = class {
186
+ constructor() {
187
+ U(this, "__unwrapped");
188
+ }
189
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
190
+ resolveReferences(e) {
191
+ }
192
+ seekProperty(e, t) {
193
+ return null;
194
+ }
195
+ }, bi = class {
196
+ constructor(e) {
197
+ this.key = e;
198
+ }
199
+ }, Ze = {
200
+ STRING: "string",
201
+ ENUM: "enum"
202
+ }, vi = class extends X {
203
+ constructor(e, t) {
204
+ super(), this._unstableElementSchema = e, this.length = t, U(this, "elementSchema"), this.elementSchema = e;
205
+ }
206
+ resolveReferences(e) {
207
+ this.elementSchema = e.resolve(this._unstableElementSchema);
208
+ }
209
+ write(e, t) {
210
+ if (t.length !== this.length)
211
+ throw new Lt(
212
+ `Expected array of length ${this.length}, got ${t.length}`
213
+ );
214
+ for (const r of t)
215
+ this.elementSchema.write(e, r);
216
+ }
217
+ read(e) {
218
+ const t = [];
219
+ for (let r = 0; r < this.length; ++r)
220
+ t.push(this.elementSchema.read(e));
221
+ return t;
222
+ }
223
+ /**
224
+ * Returns the maximum number of bytes this schema can take up.
225
+ *
226
+ * Returns `NaN` if the schema is unbounded. If you would like to know
227
+ * how many bytes a particular value encoding will take up, use `.measure(value)`.
228
+ *
229
+ * Alias for `.measure(MaxValue).size`
230
+ */
231
+ get maxSize() {
232
+ return this.elementSchema.measure(R).size * this.length;
233
+ }
234
+ measure(e, t = new N()) {
235
+ for (let r = 0; r < this.length; ++r)
236
+ this.elementSchema.measure(
237
+ e === R ? R : e[r],
238
+ t
239
+ );
240
+ return t;
241
+ }
242
+ };
243
+ // @__NO_SIDE_EFFECTS__
244
+ function _i(e, t) {
245
+ return new vi(e, t);
246
+ }
247
+ var xi = class extends X {
248
+ constructor() {
249
+ super(...arguments), U(this, "maxSize", 1);
250
+ }
251
+ read(e) {
252
+ return e.readBool();
253
+ }
254
+ write(e, t) {
255
+ e.writeBool(t);
256
+ }
257
+ measure(e, t = new N()) {
258
+ return t.add(1);
259
+ }
260
+ }, Ti = new xi(), Cn = class Je extends X {
261
+ static get _encoder() {
262
+ return Je._cachedEncoder || (Je._cachedEncoder = new TextEncoder()), Je._cachedEncoder;
263
+ }
264
+ read(t) {
265
+ return t.readString();
266
+ }
267
+ write(t, r) {
268
+ t.writeString(r);
269
+ }
270
+ measure(t, r = new N()) {
271
+ if (t === R)
272
+ return r.unbounded;
273
+ const n = Je._encoder.encode(t);
274
+ return r.add(n.byteLength + 1);
275
+ }
276
+ };
277
+ U(Cn, "_cachedEncoder");
278
+ var $i = Cn, Ei = new $i(), Ui = class extends X {
279
+ constructor() {
280
+ super(...arguments), U(this, "maxSize", 1);
281
+ }
282
+ read(e) {
283
+ return e.readInt8();
284
+ }
285
+ write(e, t) {
286
+ e.writeInt8(t);
287
+ }
288
+ measure(e, t = new N()) {
289
+ return t.add(1);
290
+ }
291
+ }, Pi = new Ui(), Si = class extends X {
292
+ constructor() {
293
+ super(...arguments), U(this, "maxSize", 1);
294
+ }
295
+ read(e) {
296
+ return e.readUint8();
297
+ }
298
+ write(e, t) {
299
+ e.writeUint8(t);
300
+ }
301
+ measure(e, t = new N()) {
302
+ return t.add(1);
303
+ }
304
+ }, Nn = new Si(), Ii = Nn, ki = class extends X {
305
+ constructor() {
306
+ super(...arguments), U(this, "maxSize", 2);
307
+ }
308
+ read(e) {
309
+ return e.readInt16();
310
+ }
311
+ write(e, t) {
312
+ e.writeInt16(t);
313
+ }
314
+ measure(e, t = new N()) {
315
+ return t.add(2);
316
+ }
317
+ }, Mi = new ki(), Ai = class extends X {
318
+ constructor() {
319
+ super(...arguments), U(this, "maxSize", 2);
320
+ }
321
+ read(e) {
322
+ return e.readUint16();
323
+ }
324
+ write(e, t) {
325
+ e.writeUint16(t);
326
+ }
327
+ measure(e, t = new N()) {
328
+ return t.add(2);
329
+ }
330
+ }, Oi = new Ai(), Gi = class extends X {
331
+ constructor() {
332
+ super(...arguments), U(this, "maxSize", 4);
333
+ }
334
+ read(e) {
335
+ return e.readInt32();
336
+ }
337
+ write(e, t) {
338
+ e.writeInt32(t);
339
+ }
340
+ measure(e, t = new N()) {
341
+ return t.add(4);
342
+ }
343
+ }, Bi = new Gi(), Fi = class extends X {
344
+ constructor() {
345
+ super(...arguments), U(this, "maxSize", 4);
346
+ }
347
+ read(e) {
348
+ return e.readUint32();
349
+ }
350
+ write(e, t) {
351
+ e.writeUint32(t);
352
+ }
353
+ measure(e, t = new N()) {
354
+ return t.add(4);
355
+ }
356
+ }, Ci = new Fi(), Ni = class extends X {
357
+ constructor() {
358
+ super(...arguments), U(this, "maxSize", 2);
359
+ }
360
+ read(e) {
361
+ return e.readFloat16();
362
+ }
363
+ write(e, t) {
364
+ e.writeFloat16(t);
365
+ }
366
+ measure(e, t = new N()) {
367
+ return t.add(2);
368
+ }
369
+ }, Li = new Ni(), Di = class extends X {
370
+ constructor() {
371
+ super(...arguments), U(this, "maxSize", 4);
372
+ }
373
+ read(e) {
374
+ return e.readFloat32();
375
+ }
376
+ write(e, t) {
377
+ e.writeFloat32(t);
378
+ }
379
+ measure(e, t = new N()) {
380
+ return t.add(4);
381
+ }
382
+ }, Wi = new Di(), zi = class extends X {
383
+ constructor(e) {
384
+ super(), this.length = e;
385
+ }
386
+ write(e, t) {
387
+ if (t.length !== this.length)
388
+ throw new Lt(
389
+ `Expected char-string of length ${this.length}, got ${t.length}`
390
+ );
391
+ for (let r = 0; r < t.length; ++r)
392
+ e.writeUint8(t.charCodeAt(r));
393
+ }
394
+ read(e) {
395
+ let t = "";
396
+ for (let r = 0; r < this.length; ++r)
397
+ t += String.fromCharCode(e.readByte());
398
+ return t;
399
+ }
400
+ measure(e, t = new N()) {
401
+ return t.add(this.length);
402
+ }
403
+ };
404
+ // @__NO_SIDE_EFFECTS__
405
+ function Yi(e) {
406
+ return new zi(e);
407
+ }
408
+ // @__NO_SIDE_EFFECTS__
409
+ function Te(e) {
410
+ return Object.entries(e);
411
+ }
412
+ // @__NO_SIDE_EFFECTS__
413
+ function Ln(e, t) {
414
+ const r = {};
415
+ for (const [n, a] of /* @__PURE__ */ Te(t))
416
+ r[n] = e.resolve(a);
417
+ return r;
418
+ }
419
+ var _r = class extends X {
420
+ constructor(e) {
421
+ super(), this._properties = e, U(this, "properties"), this.properties = e;
422
+ }
423
+ resolveReferences(e) {
424
+ this.properties = /* @__PURE__ */ Ln(e, this._properties);
425
+ }
426
+ write(e, t) {
427
+ for (const [r, n] of /* @__PURE__ */ Te(this.properties))
428
+ n.write(e, t[r]);
429
+ }
430
+ read(e) {
431
+ const t = {};
432
+ for (const [r, n] of /* @__PURE__ */ Te(this.properties))
433
+ t[r] = n.read(e);
434
+ return t;
435
+ }
436
+ /**
437
+ * The maximum number of bytes this schema can take up.
438
+ *
439
+ * Is `NaN` if the schema is unbounded. If you would like to know
440
+ * how many bytes a particular value encoding will take up, use `.measure(value)`.
441
+ *
442
+ * Alias for `.measure(MaxValue).size`
443
+ */
444
+ get maxSize() {
445
+ const e = new N();
446
+ for (const t of Object.values(this.properties))
447
+ t.measure(R, e);
448
+ return e.size;
449
+ }
450
+ measure(e, t = new N()) {
451
+ for (const [r, n] of /* @__PURE__ */ Te(this.properties))
452
+ n.measure(
453
+ e === R ? R : e[r],
454
+ t
455
+ );
456
+ return t;
457
+ }
458
+ seekProperty(e, t) {
459
+ let r = 0;
460
+ for (const [n, a] of /* @__PURE__ */ Te(this.properties)) {
461
+ if (n === t)
462
+ return {
463
+ bufferOffset: r,
464
+ schema: a
465
+ };
466
+ r += a.measure(e).size;
467
+ }
468
+ return null;
469
+ }
470
+ };
471
+ // @__NO_SIDE_EFFECTS__
472
+ function Ri(e) {
473
+ return new _r(e);
474
+ }
475
+ var Dn = class extends X {
476
+ constructor(e, t, r) {
477
+ super(), this.keyedBy = e, this._subTypeMap = r, U(this, "_baseObject"), U(this, "subTypeMap"), this._baseObject = new _r(t), this.subTypeMap = r;
478
+ }
479
+ resolveReferences(e) {
480
+ this._baseObject.resolveReferences(e), this.subTypeMap = /* @__PURE__ */ Ln(e, this._subTypeMap);
481
+ }
482
+ write(e, t) {
483
+ const r = t.type, n = this.subTypeMap[r] || null;
484
+ if (n === null)
485
+ throw new Error(
486
+ `Unknown sub-type '${r.toString()}' in among '${JSON.stringify(
487
+ Object.keys(this.subTypeMap)
488
+ )}'`
489
+ );
490
+ this.keyedBy === Ze.ENUM ? e.writeUint8(t.type) : e.writeString(t.type), this._baseObject.write(e, t);
491
+ for (const [a, s] of /* @__PURE__ */ Te(
492
+ n.properties
493
+ ))
494
+ s.write(e, t[a]);
495
+ }
496
+ read(e) {
497
+ const t = this.keyedBy === Ze.ENUM ? e.readByte() : e.readString(), r = this.subTypeMap[t] || null;
498
+ if (r === null)
499
+ throw new Error(
500
+ `Unknown sub-type '${t}' in among '${JSON.stringify(
501
+ Object.keys(this.subTypeMap)
502
+ )}'`
503
+ );
504
+ const n = this._baseObject.read(e);
505
+ if (n.type = t, r !== null)
506
+ for (const [a, s] of /* @__PURE__ */ Te(
507
+ r.properties
508
+ ))
509
+ n[a] = s.read(e);
510
+ return n;
511
+ }
512
+ measure(e, t = new N()) {
513
+ if (this._baseObject.measure(
514
+ e,
515
+ t
516
+ ), this.keyedBy === Ze.ENUM)
517
+ t.add(1);
518
+ else if (e !== R)
519
+ t.add(e.type.length + 1);
520
+ else
521
+ return t.unbounded;
522
+ if (e === R) {
523
+ const r = Object.values(this.subTypeMap).map((n) => {
524
+ const a = t.fork();
525
+ for (const s of Object.values(n.properties))
526
+ s.measure(R, a);
527
+ return [n, a.size];
528
+ }).reduce((n, a) => n[1] > a[1] ? n : a)[0];
529
+ for (const n of Object.values(r.properties))
530
+ n.measure(R, t);
531
+ } else {
532
+ const r = e.type, n = this.subTypeMap[r] || null;
533
+ if (n === null)
534
+ throw new Error(
535
+ `Unknown sub-type '${r.toString()}', expected one of '${JSON.stringify(
536
+ Object.keys(this.subTypeMap)
537
+ )}'`
538
+ );
539
+ for (const [a, s] of /* @__PURE__ */ Te(n.properties))
540
+ s.measure(e[a], t);
541
+ }
542
+ return t;
543
+ }
544
+ };
545
+ // @__NO_SIDE_EFFECTS__
546
+ function qi(e, t) {
547
+ return new Dn(Ze.STRING, e, t);
548
+ }
549
+ // @__NO_SIDE_EFFECTS__
550
+ function ji(e, t) {
551
+ return new Dn(Ze.ENUM, e, t);
552
+ }
553
+ // @__NO_SIDE_EFFECTS__
554
+ function Vi(e) {
555
+ return new _r(
556
+ Object.fromEntries(
557
+ e.flatMap(({ properties: t }) => Object.entries(t))
558
+ )
559
+ );
560
+ }
561
+ var Ji = class extends X {
562
+ constructor(e) {
563
+ super(), this._unstableElementType = e, U(this, "elementType"), this.elementType = e;
564
+ }
565
+ resolveReferences(e) {
566
+ this.elementType = e.resolve(this._unstableElementType);
567
+ }
568
+ write(e, t) {
569
+ e.writeUint32(t.length);
570
+ for (const r of t)
571
+ this.elementType.write(e, r);
572
+ }
573
+ read(e) {
574
+ const t = [], r = e.readUint32();
575
+ for (let n = 0; n < r; ++n)
576
+ t.push(this.elementType.read(e));
577
+ return t;
578
+ }
579
+ /**
580
+ * The maximum number of bytes this schema can take up.
581
+ *
582
+ * Is `NaN` if the schema is unbounded. If you would like to know
583
+ * how many bytes a particular value encoding will take up, use `.measure(value)`.
584
+ *
585
+ * Alias for `.measure(MaxValue).size`
586
+ */
587
+ get maxSize() {
588
+ return this.measure(R).size;
589
+ }
590
+ measure(e, t = new N()) {
591
+ if (e === R)
592
+ return t.unbounded;
593
+ t.add(4);
594
+ for (const r of e)
595
+ this.elementType.measure(r, t);
596
+ return t;
597
+ }
598
+ seekProperty(e, t) {
599
+ if (typeof t == "symbol")
600
+ return null;
601
+ const r = Number.parseInt(String(t), 10);
602
+ if (Number.isNaN(r))
603
+ return null;
604
+ if (e === R)
605
+ return {
606
+ bufferOffset: this.elementType.measure(R).size * r,
607
+ schema: this.elementType
608
+ };
609
+ if (r >= e.length)
610
+ return null;
611
+ const n = new N();
612
+ for (let a = 0; a < r; ++a)
613
+ this.elementType.measure(e[a], n);
614
+ return {
615
+ bufferOffset: n.size,
616
+ schema: this.elementType
617
+ };
618
+ }
619
+ };
620
+ // @__NO_SIDE_EFFECTS__
621
+ function Zi(e) {
622
+ return new Ji(e);
623
+ }
624
+ var Wn = class {
625
+ constructor(e) {
626
+ U(this, "__unwrapped"), U(this, "ref"), this.ref = new bi(e);
627
+ }
628
+ resolveReferences() {
629
+ throw new ke(
630
+ "Tried to resolve a reference directly. Do it through a RefResolver instead."
631
+ );
632
+ }
633
+ read() {
634
+ throw new ke(
635
+ "Tried to read a reference directly. Resolve it instead."
636
+ );
637
+ }
638
+ write() {
639
+ throw new ke(
640
+ "Tried to write a reference directly. Resolve it instead."
641
+ );
642
+ }
643
+ measure() {
644
+ throw new ke(
645
+ "Tried to measure size of a reference directly. Resolve it instead."
646
+ );
647
+ }
648
+ seekProperty() {
649
+ throw new ke(
650
+ "Tried to seek property of a reference directly. Resolve it instead."
651
+ );
652
+ }
653
+ }, Xi = class {
654
+ constructor() {
655
+ U(this, "registry", {});
656
+ }
657
+ hasKey(e) {
658
+ return this.registry[e] !== void 0;
659
+ }
660
+ register(e, t) {
661
+ this.registry[e] = t;
662
+ }
663
+ resolve(e) {
664
+ if (e instanceof Wn) {
665
+ const r = e.ref.key;
666
+ if (this.registry[r] !== void 0)
667
+ return this.registry[r];
668
+ throw new ke(
669
+ `Couldn't resolve reference to ${r}. Unknown key.`
670
+ );
671
+ }
672
+ return e.resolveReferences(this), e;
673
+ }
674
+ }, Qi = class {
675
+ constructor(e, t) {
676
+ this.key = e, U(this, "__unwrapped"), U(this, "__keyDefinition"), U(this, "innerType"), this.innerType = t(new Wn(e)), this.resolveReferences(new Xi());
677
+ }
678
+ resolveReferences(e) {
679
+ e.hasKey(this.key) || (e.register(this.key, this.innerType), this.innerType.resolveReferences(e));
680
+ }
681
+ read(e) {
682
+ return this.innerType.read(e);
683
+ }
684
+ write(e, t) {
685
+ this.innerType.write(e, t);
686
+ }
687
+ /**
688
+ * The maximum number of bytes this schema can take up.
689
+ *
690
+ * Is `NaN` if the schema is unbounded. If you would like to know
691
+ * how many bytes a particular value encoding will take up, use `.measure(value)`.
692
+ *
693
+ * Alias for `.measure(MaxValue).size`
694
+ */
695
+ get maxSize() {
696
+ return this.measure(R).size;
697
+ }
698
+ measure(e, t = new N()) {
699
+ return this.innerType.measure(e, t);
700
+ }
701
+ seekProperty(e, t) {
702
+ return this.innerType.seekProperty(e, t);
703
+ }
704
+ };
705
+ // @__NO_SIDE_EFFECTS__
706
+ function Ki(e, t) {
707
+ return new Qi(e, t);
708
+ }
709
+ var Hi = class extends X {
710
+ constructor(e) {
711
+ super(), this._innerUnstableSchema = e, U(this, "innerSchema"), this.innerSchema = e;
712
+ }
713
+ resolveReferences(e) {
714
+ this.innerSchema = e.resolve(this._innerUnstableSchema);
715
+ }
716
+ write(e, t) {
717
+ t != null ? (e.writeBool(!0), this.innerSchema.write(e, t)) : e.writeBool(!1);
718
+ }
719
+ read(e) {
720
+ if (e.readBool())
721
+ return this.innerSchema.read(e);
722
+ }
723
+ /**
724
+ * The maximum number of bytes this schema can take up.
725
+ *
726
+ * Is `NaN` if the schema is unbounded. If you would like to know
727
+ * how many bytes a particular value encoding will take up, use `.measure(value)`.
728
+ *
729
+ * Alias for `.measure(MaxValue).size`
730
+ */
731
+ get maxSize() {
732
+ return this.measure(R).size;
733
+ }
734
+ measure(e, t = new N()) {
735
+ return e !== void 0 && this.innerSchema.measure(e, t), t.add(1);
736
+ }
737
+ };
738
+ // @__NO_SIDE_EFFECTS__
739
+ function eo(e) {
740
+ return new Hi(e);
741
+ }
742
+ // @__NO_SIDE_EFFECTS__
743
+ function to(e, t) {
744
+ return t.map((r) => e.resolve(r));
745
+ }
746
+ var ro = class extends X {
747
+ constructor(e) {
748
+ super(), this._unstableSchemas = e, U(this, "schemas"), this.schemas = e;
749
+ }
750
+ resolveReferences(e) {
751
+ this.schemas = /* @__PURE__ */ to(e, this._unstableSchemas);
752
+ }
753
+ write(e, t) {
754
+ if (t.length !== this.schemas.length)
755
+ throw new Lt(
756
+ `Expected tuple of length ${this.schemas.length}, got ${t.length}`
757
+ );
758
+ for (let r = 0; r < this.schemas.length; ++r)
759
+ this.schemas[r].write(e, t[r]);
760
+ }
761
+ read(e) {
762
+ const t = [];
763
+ for (let r = 0; r < this.schemas.length; ++r)
764
+ t.push(
765
+ this.schemas[r].read(e)
766
+ );
767
+ return t;
768
+ }
769
+ /**
770
+ * The maximum number of bytes this schema can take up.
771
+ *
772
+ * Is `NaN` if the schema is unbounded. If you would like to know
773
+ * how many bytes a particular value encoding will take up, use `.measure(value)`.
774
+ *
775
+ * Alias for `.measure(MaxValue).size`
776
+ */
777
+ get maxSize() {
778
+ return this.measure(R).size;
779
+ }
780
+ measure(e, t = new N()) {
781
+ for (let r = 0; r < this.schemas.length; ++r)
782
+ this.schemas[r].measure(
783
+ e === R ? R : e[r],
784
+ t
785
+ );
786
+ return t;
787
+ }
788
+ };
789
+ // @__NO_SIDE_EFFECTS__
790
+ function no(e) {
791
+ return new ro(e);
792
+ }
793
+ var ve = class extends X {
794
+ constructor(e, t) {
795
+ super(), this.length = e, this._arrayConstructor = t, U(this, "byteLength"), this.byteLength = e * t.BYTES_PER_ELEMENT;
796
+ }
797
+ write(e, t) {
798
+ e.writeSlice(t);
799
+ }
800
+ read(e) {
801
+ const t = new ArrayBuffer(this.byteLength), r = new this._arrayConstructor(t, 0, this.length);
802
+ return e.readSlice(r, 0, this.byteLength), r;
803
+ }
804
+ measure(e, t = new N()) {
805
+ return t.add(this.byteLength);
806
+ }
807
+ }, ao = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Uint8Array), so = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Uint8ClampedArray), io = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Uint16Array), oo = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Uint32Array), uo = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Int8Array), lo = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Int16Array), co = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Int32Array), po = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Float32Array), ho = /* @__NO_SIDE_EFFECTS__ */ (e) => new ve(e, Float64Array);
808
+ // @__NO_SIDE_EFFECTS__
809
+ function fo() {
810
+ const e = new Uint8Array(4), t = new Uint32Array(e.buffer);
811
+ return t[0] = 1, e[0] === 0;
812
+ }
813
+ // @__NO_SIDE_EFFECTS__
814
+ function zn() {
815
+ return /* @__PURE__ */ fo() ? "big" : "little";
816
+ }
817
+ // @__NO_SIDE_EFFECTS__
818
+ function xr(e) {
819
+ let t = 0, r = e;
820
+ return r && "buffer" in r && "byteOffset" in r && (t += r.byteOffset, r = r.buffer), { buffer: r, byteOffset: t, byteLength: e.byteLength };
821
+ }
822
+ var Yn = class {
823
+ constructor(e, t) {
824
+ U(this, "dataView"), U(this, "littleEndian"), U(this, "byteOffset", 0), U(this, "endianness");
825
+ const { byteOffset: r = 0, endianness: n = "system" } = t ?? {};
826
+ this.byteOffset = r;
827
+ const a = /* @__PURE__ */ zn();
828
+ this.endianness = n === "system" ? a : n, this.littleEndian = this.endianness === "little";
829
+ const s = /* @__PURE__ */ xr(e);
830
+ this.byteOffset += s.byteOffset, this.dataView = new DataView(s.buffer);
831
+ }
832
+ get currentByteOffset() {
833
+ return this.byteOffset;
834
+ }
835
+ seekTo(e) {
836
+ this.byteOffset = e;
837
+ }
838
+ skipBytes(e) {
839
+ this.byteOffset += e;
840
+ }
841
+ };
842
+ function mo(e) {
843
+ if (e === 0) return 0;
844
+ if (Number.isNaN(e)) return 32256;
845
+ if (!Number.isFinite(e)) return e > 0 ? 31744 : 64512;
846
+ const t = e < 0 ? 1 : 0, r = Math.abs(e), n = Math.floor(Math.log2(r)), a = r / 2 ** n - 1, s = n + 15, i = Math.floor(a * 1024);
847
+ return t << 15 | s << 10 | i;
848
+ }
849
+ function yo(e) {
850
+ const t = (e & 32768) >> 15, r = (e & 31744) >> 10, n = e & 1023;
851
+ return r === 0 ? t === 0 ? n / 1024 : -n / 1024 : r === 31 ? n === 0 ? t === 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY : Number.NaN : (t === 0 ? 1 : -1) * (1 + n / 1024) * 2 ** (r - 15);
852
+ }
853
+ var Ee = class extends Yn {
854
+ constructor() {
855
+ super(...arguments), U(this, "_cachedTextDecoder");
856
+ }
857
+ get _textDecoder() {
858
+ return this._cachedTextDecoder || (this._cachedTextDecoder = new TextDecoder(void 0, { fatal: !0 })), this._cachedTextDecoder;
859
+ }
860
+ readBool() {
861
+ return this.dataView.getUint8(this.byteOffset++) !== 0;
862
+ }
863
+ readByte() {
864
+ return this.dataView.getUint8(this.byteOffset++);
865
+ }
866
+ readInt8() {
867
+ return this.dataView.getInt8(this.byteOffset++);
868
+ }
869
+ readUint8() {
870
+ return this.dataView.getUint8(this.byteOffset++);
871
+ }
872
+ readInt16() {
873
+ const e = this.dataView.getInt16(this.byteOffset, this.littleEndian);
874
+ return this.byteOffset += 2, e;
875
+ }
876
+ readUint16() {
877
+ const e = this.dataView.getUint16(this.byteOffset, this.littleEndian);
878
+ return this.byteOffset += 2, e;
879
+ }
880
+ readInt32() {
881
+ const e = this.dataView.getInt32(this.byteOffset, this.littleEndian);
882
+ return this.byteOffset += 4, e;
883
+ }
884
+ readUint32() {
885
+ const e = this.dataView.getUint32(this.byteOffset, this.littleEndian);
886
+ return this.byteOffset += 4, e;
887
+ }
888
+ readFloat16() {
889
+ const e = this.dataView.getUint16(this.byteOffset, this.littleEndian);
890
+ return this.byteOffset += 2, yo(e);
891
+ }
892
+ readFloat32() {
893
+ const e = this.dataView.getFloat32(this.byteOffset, this.littleEndian);
894
+ return this.byteOffset += 4, e;
895
+ }
896
+ readString() {
897
+ let e = 0;
898
+ for (; this.byteOffset + e < this.dataView.byteLength && this.dataView.getUint8(this.byteOffset + e++) !== 0; )
899
+ ;
900
+ const t = this._textDecoder.decode(
901
+ new Uint8Array(this.dataView.buffer, this.byteOffset, e - 1)
902
+ );
903
+ return this.byteOffset += e, t;
904
+ }
905
+ readSlice(e, t, r) {
906
+ const n = /* @__PURE__ */ xr(e), a = new Uint8Array(
907
+ n.buffer,
908
+ n.byteOffset + t
909
+ );
910
+ for (let s = 0; s < r; ++s)
911
+ a[s] = this.dataView.getUint8(this.byteOffset++);
912
+ }
913
+ }, Se = class extends Yn {
914
+ constructor() {
915
+ super(...arguments), U(this, "_cachedTextEncoder");
916
+ }
917
+ get _textEncoder() {
918
+ return this._cachedTextEncoder || (this._cachedTextEncoder = new TextEncoder()), this._cachedTextEncoder;
919
+ }
920
+ writeBool(e) {
921
+ this.dataView.setUint8(this.byteOffset++, e ? 1 : 0);
922
+ }
923
+ writeByte(e) {
924
+ this.dataView.setUint8(this.byteOffset++, e);
925
+ }
926
+ writeInt8(e) {
927
+ this.dataView.setInt8(this.byteOffset++, e);
928
+ }
929
+ writeUint8(e) {
930
+ this.dataView.setUint8(this.byteOffset++, e);
931
+ }
932
+ writeInt16(e) {
933
+ this.dataView.setInt16(this.byteOffset, e, this.littleEndian), this.byteOffset += 2;
934
+ }
935
+ writeUint16(e) {
936
+ this.dataView.setUint16(this.byteOffset, e, this.littleEndian), this.byteOffset += 2;
937
+ }
938
+ writeInt32(e) {
939
+ this.dataView.setInt32(this.byteOffset, e, this.littleEndian), this.byteOffset += 4;
940
+ }
941
+ writeUint32(e) {
942
+ this.dataView.setUint32(this.byteOffset, e, this.littleEndian), this.byteOffset += 4;
943
+ }
944
+ writeFloat16(e) {
945
+ this.dataView.setUint16(
946
+ this.byteOffset,
947
+ mo(e),
948
+ this.littleEndian
949
+ ), this.byteOffset += 2;
950
+ }
951
+ writeFloat32(e) {
952
+ this.dataView.setFloat32(this.byteOffset, e, this.littleEndian), this.byteOffset += 4;
953
+ }
954
+ writeString(e) {
955
+ const t = this._textEncoder.encodeInto(
956
+ e,
957
+ new Uint8Array(this.dataView.buffer, this.byteOffset)
958
+ );
959
+ this.byteOffset += t.written, this.dataView.setUint8(this.byteOffset++, 0);
960
+ }
961
+ writeSlice(e) {
962
+ const t = /* @__PURE__ */ xr(e), r = new Uint8Array(
963
+ t.buffer,
964
+ t.byteOffset,
965
+ t.byteLength
966
+ );
967
+ for (const n of r)
968
+ this.dataView.setUint8(this.byteOffset++, n);
969
+ }
970
+ };
971
+ function wo(e) {
972
+ if (typeof e?.[j] == "function") return e[j].bind(e);
973
+ }
974
+ var qe = { get(e, t) {
975
+ if (t in e) return Reflect.get(e, t);
976
+ if (t !== Me) return t === "toString" || t === Symbol.toStringTag || t === Symbol.toPrimitive ? () => e.toString() : new Proxy({ [c]: !0, "~resolve": (r) => `${r.resolve(e)}.${String(t)}`, toString: () => `.value(...).${String(t)}:${g(e) ?? "<unnamed>"}`, [C]: Vs(e[C], String(t)) }, qe);
977
+ } };
978
+ function Tr(e, t) {
979
+ let r = t, n;
980
+ for (; n = wo(r); ) r = n(e);
981
+ return r;
982
+ }
983
+ function go(e, t) {
984
+ return new bo(e, t);
985
+ }
986
+ var bo = class {
987
+ constructor(t, r) {
988
+ this.dataType = t, this.#e = r;
989
+ }
990
+ [c] = {};
991
+ #e;
992
+ $name(t) {
993
+ return F(this, t), this;
994
+ }
995
+ "~resolve"(t) {
996
+ let r = t.names.makeUnique(g(this)), n = t.resolve(this.#e, this.dataType), a = t.resolve(this.dataType);
997
+ return t.addDeclaration(`const ${r}: ${a} = ${n};`), r;
998
+ }
999
+ toString() {
1000
+ return `const:${g(this) ?? "<unnamed>"}`;
1001
+ }
1002
+ [j]() {
1003
+ return new Proxy({ [c]: !0, "~resolve": (t) => t.resolve(this), toString: () => `.value:${g(this) ?? "<unnamed>"}`, [C]: this.dataType }, qe);
1004
+ }
1005
+ get value() {
1006
+ return hr() ? this[j]() : this.#e;
1007
+ }
1008
+ get $() {
1009
+ return this.value;
1010
+ }
1011
+ };
1012
+ function Xe(e, t) {
1013
+ for (let [r, n] of Object.entries(t)) e[r] = n, Ct(n) && g(n) === void 0 && n.$name(r);
1014
+ }
1015
+ function vo(e, t, r) {
1016
+ let n = [...e.matchAll(/:\s*(?<arg>.*?)\s*[,)]/g)].map((a) => a ? a[1] : void 0);
1017
+ r(Object.fromEntries(t.flatMap((a, s) => {
1018
+ let i = n ? n[s] : void 0;
1019
+ return be(a) && i !== void 0 ? [[i, a]] : [];
1020
+ })));
1021
+ }
1022
+ function Rn(e, t, r) {
1023
+ let n = e.match(/->\s(?<output>[\w\d_]+)\s{/), a = n ? n[1]?.trim() : void 0;
1024
+ be(t) && a && !/\s/g.test(a) && r({ [a]: t });
1025
+ }
1026
+ function _o(e) {
1027
+ return new RegExp(`(?<![\\w\\$_.])${e.replaceAll(".", "\\.").replaceAll("$", "\\$")}(?![\\w\\$_])`, "g");
1028
+ }
1029
+ function Dt(e, t, r) {
1030
+ return Object.entries(t).reduce((n, [a, s]) => js(s) || pr(s) ? n.replaceAll(_o(a), e.resolve(s)) : s !== null && typeof s == "object" ? ([...r.matchAll(new RegExp(`${a.replaceAll(".", "\\.").replaceAll("$", "\\$")}\\.(?<prop>.*?)(?![\\w\\$_])`, "g"))].map((i) => i[1]) ?? []).reduce((i, l) => l && l in s ? Dt(e, { [`${a}.${l}`]: s[l] }, i) : i, n) : n, r);
1031
+ }
1032
+ function xo(e) {
1033
+ return new To(e);
1034
+ }
1035
+ var To = class {
1036
+ constructor(t) {
1037
+ this.declaration = t;
1038
+ }
1039
+ [c] = !0;
1040
+ externalsToApply = [];
1041
+ $uses(t) {
1042
+ return this.externalsToApply.push(t), this;
1043
+ }
1044
+ "~resolve"(t) {
1045
+ let r = {};
1046
+ for (let a of this.externalsToApply) Xe(r, a);
1047
+ let n = Dt(t, r, this.declaration);
1048
+ return t.addDeclaration(n), "";
1049
+ }
1050
+ toString() {
1051
+ return `declare: ${this.declaration}`;
1052
+ }
1053
+ };
1054
+ function $o(e) {
1055
+ let { strippedCode: t, argRange: r } = Eo(e), n = new qn(t);
1056
+ n.consume("(");
1057
+ let a = [];
1058
+ for (; !n.isAt(")"); ) {
1059
+ let i = [];
1060
+ for (; n.isAt("@"); ) n.parseUntil(zr, Yr), n.consume(")"), i.push(n.lastParsed);
1061
+ n.parseUntil(Po);
1062
+ let l = n.lastParsed, o;
1063
+ n.isAt(":") && (n.consume(":"), n.parseUntil(So, ko), o = n.lastParsed), a.push({ identifier: l, attributes: i, type: o }), n.isAt(",") && n.consume(",");
1064
+ }
1065
+ n.consume(")");
1066
+ let s;
1067
+ if (n.isAt("->")) {
1068
+ n.consume("->");
1069
+ let i = [];
1070
+ for (; n.isAt("@"); ) n.parseUntil(zr, Yr), n.consume(")"), i.push(n.lastParsed);
1071
+ s = { type: n.str.slice(n.pos), attributes: i };
1072
+ }
1073
+ return { args: a, ret: s, range: { begin: r[0], end: r[1] } };
1074
+ }
1075
+ function Eo(e) {
1076
+ let t = new qn(e), r = "", n;
1077
+ for (; !t.isFinished(); ) {
1078
+ if (t.isAt(Uo)) {
1079
+ t.advanceBy(1);
1080
+ continue;
1081
+ }
1082
+ if (t.isAt("//")) {
1083
+ t.consume("//"), t.parseUntil(jn), t.advanceBy(1);
1084
+ continue;
1085
+ }
1086
+ if (t.isAt("/*")) {
1087
+ t.parseUntil(Io, Mo), t.consume("*/");
1088
+ continue;
1089
+ }
1090
+ if (t.isAt("{")) return { strippedCode: r, argRange: [n, t.pos] };
1091
+ t.isAt("(") && n === void 0 && (n = t.pos), n !== void 0 && (r += t.str[t.pos]), t.advanceBy(1);
1092
+ }
1093
+ throw new Error("Invalid wgsl code!");
1094
+ }
1095
+ var qn = class {
1096
+ constructor(t) {
1097
+ this.str = t, this.#t = 0;
1098
+ }
1099
+ #e;
1100
+ #t;
1101
+ get pos() {
1102
+ return this.#t;
1103
+ }
1104
+ get lastParsed() {
1105
+ if (this.#e === void 0) throw new Error("Parse was not called yet!");
1106
+ return this.str.slice(this.#e, this.pos);
1107
+ }
1108
+ isFinished() {
1109
+ return this.#t >= this.str.length;
1110
+ }
1111
+ isAt(t) {
1112
+ if (typeof t == "string") {
1113
+ for (let r = 0; r < t.length; r++) if (this.str[this.#t + r] !== t[r]) return !1;
1114
+ return !0;
1115
+ }
1116
+ for (let r of t) if (this.isAt(r)) return !0;
1117
+ return !1;
1118
+ }
1119
+ parseUntil(t, r) {
1120
+ this.#e = this.#t;
1121
+ let n = 0;
1122
+ for (; this.#t < this.str.length; ) {
1123
+ if (r && this.isAt(r[0]) && (n += 1), r && this.isAt(r[1]) && (n -= 1), n === 0 && this.isAt(t)) return this.#t;
1124
+ this.#t += 1;
1125
+ }
1126
+ throw new Error("Reached the end of the string without finding a match!");
1127
+ }
1128
+ advanceBy(t) {
1129
+ this.#t += t;
1130
+ }
1131
+ consume(t) {
1132
+ if (!this.isAt(t)) throw new Error(`Expected '${t}' at position ${this.#t}, but found '${this.str.slice(this.#t, this.#t + t.length)}'`);
1133
+ this.advanceBy(t.length);
1134
+ }
1135
+ }, jn = /* @__PURE__ */ new Set([`
1136
+ `, "\v", "\f", "\r", "…", "\u2028", "\u2029"]), Uo = /* @__PURE__ */ new Set([...jn, " ", " ", "‎", "‏"]), zr = /* @__PURE__ */ new Set([")"]), Po = /* @__PURE__ */ new Set([":", ",", ")"]), So = /* @__PURE__ */ new Set([",", ")"]), Io = /* @__PURE__ */ new Set(["*/"]), Yr = ["(", ")"], ko = ["<", ">"], Mo = ["/*", "*/"];
1137
+ function Wt(e, t = "") {
1138
+ let r = [], n = { applyExternals(s) {
1139
+ r.push(s);
1140
+ }, resolve(s, i, l) {
1141
+ let o = {};
1142
+ for (let h of r) Xe(o, h);
1143
+ let y = s.names.makeUnique(g(this));
1144
+ if (typeof e == "string") {
1145
+ let h = Dt(s, o, e), w = "", b = "";
1146
+ if (t !== "") {
1147
+ let v = be(i[0]) ? `(in: ${s.resolve(i[0])})` : "()", x = ie(l) ? lr(l) : "", P = l !== de ? be(l) ? `-> ${s.resolve(l)}` : `-> ${x !== "" ? x : "@location(0)"} ${s.resolve(l)}` : "";
1148
+ w = `${v} ${P} `, b = h;
1149
+ } else {
1150
+ let v = $o(h);
1151
+ if (v.args.length !== i.length) throw new Error(`WGSL implementation has ${v.args.length} arguments, while the shell has ${i.length} arguments.`);
1152
+ let x = v.args.map(($, k) => `${$.identifier}: ${Rr(s, `parameter ${$.identifier}`, $.type, i[k])}`).join(", "), P = l === de ? "" : `-> ${Rr(s, "return type", v.ret?.type, l)}`;
1153
+ w = `(${x}) ${P}`, b = h.slice(v.range.end);
1154
+ }
1155
+ s.addDeclaration(`${t}fn ${y}${w}${b}`);
1156
+ } else {
1157
+ let h = Qs(e);
1158
+ if (h?.externals) {
1159
+ let $ = Object.fromEntries(Object.entries(h.externals).filter(([k]) => !(k in o)));
1160
+ Xe(o, $);
1161
+ }
1162
+ let w = h?.ast;
1163
+ if (!w) throw new Error("Missing metadata for tgpu.fn function body (either missing 'kernel' directive, or misconfigured `unplugin-typegpu`)");
1164
+ let b = w.externalNames.filter(($) => !($ in o));
1165
+ if (b.length > 0) throw new Ks(g(this), b);
1166
+ let v = w.params[1];
1167
+ v && v.type === "i" && t !== "" && Xe(o, { [v.name]: Hs(l) });
1168
+ let { head: x, body: P } = s.fnToWgsl({ args: i.map(($, k) => u(w.params[k]?.type === kr.identifier ? w.params[k].name : `_arg_${k}`, $)), argAliases: Object.fromEntries(w.params.flatMap(($, k) => $.type === kr.destructuredObject ? $.props.map(({ name: L, alias: ee }) => [ee, u(`_arg_${k}.${L}`, i[k].propTypes[L])]) : [])), returnType: l, body: w.body, externalMap: o });
1169
+ s.addDeclaration(`${t}fn ${y}${s.resolve(x)}${s.resolve(P)}`);
1170
+ }
1171
+ return y;
1172
+ } }, a = g(e);
1173
+ return a !== void 0 && F(n, a), n;
1174
+ }
1175
+ function Rr(e, t, r, n) {
1176
+ let a = e.resolve(n).replace(/\s/g, "");
1177
+ if (!r) return a;
1178
+ let s = r.replace(/\s/g, "");
1179
+ if (s !== a) throw new Error(`Type mismatch between TGPU shell and WGSL code string: ${t}, JS type "${a}", WGSL type "${s}".`);
1180
+ return r;
1181
+ }
1182
+ function Ao(e, t = {}) {
1183
+ let r = 0, n = /* @__PURE__ */ new Set();
1184
+ return Object.fromEntries(Object.entries(e ?? {}).map(([a, s]) => {
1185
+ let i = Pe(s);
1186
+ if (i !== void 0) {
1187
+ if (n.has(i)) throw new Error("Duplicate custom location attributes found");
1188
+ n.add(i);
1189
+ }
1190
+ return [a, s];
1191
+ }).map(([a, s]) => {
1192
+ if (Ft(s)) return [a, s];
1193
+ if (Pe(s) !== void 0) return [a, s];
1194
+ if (t[a]) return [a, Et(t[a], s)];
1195
+ for (; n.has(r); ) r++;
1196
+ return [a, Et(r++, s)];
1197
+ }));
1198
+ }
1199
+ function dt(e, t = {}) {
1200
+ return Re(e) ? In(e) || Pe(e) !== void 0 ? e : Et(0, e) : $n(Ao(e, t));
1201
+ }
1202
+ function zt(e, ...t) {
1203
+ return Oo(e) ? Go(e, ...t) : e;
1204
+ }
1205
+ function Oo(e) {
1206
+ return Array.isArray(e) && "raw" in e && Array.isArray(e.raw) && e.raw.every((t) => typeof t == "string");
1207
+ }
1208
+ function Go(e, ...t) {
1209
+ return e.slice(1).reduce((r, n, a) => `${r}${t[a]}${n}`, e[0]);
1210
+ }
1211
+ function Bo(e) {
1212
+ let t = { argTypes: e.in && Object.keys(e.in).length !== 0 ? [dt(e.in)] : [], returnType: de, workgroupSize: [e.workgroupSize[0] ?? 1, e.workgroupSize[1] ?? 1, e.workgroupSize[2] ?? 1], isEntry: !0 }, r = (n, ...a) => Fo(t, e.workgroupSize, zt(n, ...a));
1213
+ return Object.assign(Object.assign(r, t), { does: r });
1214
+ }
1215
+ function Fo(e, t, r) {
1216
+ let n = Wt(r, `@compute @workgroup_size(${t.join(", ")}) `), a = e.argTypes[0];
1217
+ return { shell: e, $uses(s) {
1218
+ return n.applyExternals(s), this;
1219
+ }, [c]: !0, [Y]: n, $name(s) {
1220
+ return F(n, s), Ct(a) && a.$name(`${s}_Input`), this;
1221
+ }, "~resolve"(s) {
1222
+ return n.resolve(s, e.argTypes, e.returnType);
1223
+ }, toString() {
1224
+ return `computeFn:${g(n) ?? "<unnamed>"}`;
1225
+ } };
1226
+ }
1227
+ function qr(e, t) {
1228
+ let r = { [c]: !0, argTypes: e, returnType: t ?? de, isEntry: !1 };
1229
+ return Object.assign((n, ...a) => Lo(r, zt(n, ...a)), r);
1230
+ }
1231
+ function Co(e) {
1232
+ return !!e?.[c] && e?.resourceType === "function";
1233
+ }
1234
+ function No([e, t]) {
1235
+ return `${g(e) ?? "<unnamed>"}=${t}`;
1236
+ }
1237
+ function Lo(e, t) {
1238
+ let r = Wt(t, ""), n = { shell: e, resourceType: "function", $uses(i) {
1239
+ return r.applyExternals(i), this;
1240
+ }, [Y]: r, $name(i) {
1241
+ return F(r, i), this;
1242
+ }, with(i, l) {
1243
+ return Vn(s, [[Nt(i) ? i.slot : i, l]]);
1244
+ }, "~resolve"(i) {
1245
+ return typeof t == "string" && (vo(t, e.argTypes, r.applyExternals), Rn(t, e.returnType, r.applyExternals)), r.resolve(i, e.argTypes, e.returnType);
1246
+ } }, a = d((...i) => Rs(() => {
1247
+ try {
1248
+ if (typeof t == "string") throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");
1249
+ let l = i.map((o, y) => kn(e.argTypes[y], o));
1250
+ return t(...l);
1251
+ } catch (l) {
1252
+ throw l instanceof Fr ? l.appendToTrace(s) : new Fr(l, [s]);
1253
+ }
1254
+ }), (...i) => u(new Jn(s, i), e.returnType), "tgpuFnCall", e.argTypes), s = Object.assign(a, n);
1255
+ return s[c].implementation = t, Object.defineProperty(s, "toString", { value() {
1256
+ return `fn:${g(r) ?? "<unnamed>"}`;
1257
+ } }), s;
1258
+ }
1259
+ function Vn(e, t) {
1260
+ let r = { resourceType: "function", shell: e.shell, [Me]: { inner: e, pairs: t }, $uses(s) {
1261
+ return e.$uses(s), this;
1262
+ }, [Y]: e, $name(s) {
1263
+ return e.$name(s), this;
1264
+ }, with(s, i) {
1265
+ return Vn(a, [...t, [Nt(s) ? s.slot : s, i]]);
1266
+ } }, n = d((...s) => e(...s), (...s) => u(new Jn(a, s), e.shell.returnType), "tgpuFnCall", e.shell.argTypes), a = Object.assign(n, r);
1267
+ return a[c].implementation = e[c].implementation, Object.defineProperty(a, "toString", { value() {
1268
+ return `fn:${g(e) ?? "<unnamed>"}[${t.map(No).join(", ")}]`;
1269
+ } }), a[c].implementation = e[c].implementation, a;
1270
+ }
1271
+ var Jn = class {
1272
+ [c] = !0;
1273
+ [Y];
1274
+ #e;
1275
+ #t;
1276
+ constructor(t, r) {
1277
+ this.#e = t, this.#t = r, this[Y] = t;
1278
+ }
1279
+ "~resolve"(t) {
1280
+ return t.withResetIndentLevel(() => p`${t.resolve(this.#e)}(${this.#t})`);
1281
+ }
1282
+ toString() {
1283
+ return `call:${g(this) ?? "<unnamed>"}`;
1284
+ }
1285
+ };
1286
+ function Do(e) {
1287
+ let t = { in: e.in, out: e.out, returnType: dt(e.out), isEntry: !0 }, r = (n, ...a) => Wo(t, zt(n, ...a));
1288
+ return Object.assign(Object.assign(r, t), { does: r });
1289
+ }
1290
+ function Wo(e, t) {
1291
+ let r = Wt(t, "@fragment "), n = e.returnType;
1292
+ return typeof t == "string" && Rn(t, n, (a) => r.applyExternals(a)), { shell: e, outputType: n, $uses(a) {
1293
+ return r.applyExternals(a), this;
1294
+ }, [c]: !0, [Y]: r, $name(a) {
1295
+ return F(r, a), Ct(n) && n.$name(`${a}_Output`), this;
1296
+ }, "~resolve"(a) {
1297
+ let s = e.in ? dt(e.in, a.varyingLocations).$name(`${g(this) ?? ""}_Input`) : void 0;
1298
+ return s && r.applyExternals({ In: s }), r.applyExternals({ Out: n }), r.resolve(a, s ? [s] : [], e.returnType);
1299
+ }, toString() {
1300
+ return `fragmentFn:${g(r) ?? "<unnamed>"}`;
1301
+ } };
1302
+ }
1303
+ function zo(e) {
1304
+ if (Object.keys(e.out).length === 0) throw new Error("A vertexFn output cannot be empty since it must include the 'position' builtin.");
1305
+ let t = { in: e.in, out: e.out, argTypes: e.in && Object.keys(e.in).length !== 0 ? [dt(e.in)] : [], isEntry: !0 }, r = (n, ...a) => Yo(t, zt(n, ...a));
1306
+ return Object.assign(Object.assign(r, t), { does: r });
1307
+ }
1308
+ function Yo(e, t) {
1309
+ let r = Wt(t, "@vertex "), n = e.argTypes[0];
1310
+ return { shell: e, $uses(a) {
1311
+ return r.applyExternals(a), this;
1312
+ }, [c]: !0, [Y]: r, $name(a) {
1313
+ return F(r, a), Ct(n) && n.$name(`${a}_Input`), this;
1314
+ }, "~resolve"(a) {
1315
+ let s = dt(e.out, a.varyingLocations).$name(`${g(this) ?? ""}_Output`);
1316
+ return typeof t == "string" && (n && r.applyExternals({ In: n }), r.applyExternals({ Out: s })), r.resolve(a, e.argTypes, s);
1317
+ }, toString() {
1318
+ return `vertexFn:${g(r) ?? "<unnamed>"}`;
1319
+ } };
1320
+ }
1321
+ var $r = class {
1322
+ lastUniqueId = 0;
1323
+ makeUnique(e) {
1324
+ let t;
1325
+ return e ? (t = e.replaceAll(/\s/g, "_"), t = t.replaceAll(/[^\w\d]/g, "")) : t = "item", `${t}_${this.lastUniqueId++}`;
1326
+ }
1327
+ }, Yt = class {
1328
+ _usedNames = /* @__PURE__ */ new Set();
1329
+ makeUnique(t) {
1330
+ if (t === void 0) throw new Error("Unnamed item found when using a strict name registry");
1331
+ let r = 0, n = t;
1332
+ for (; this._usedNames.has(n); ) r++, n = `${t}_${r}`;
1333
+ return this._usedNames.add(n), n;
1334
+ }
1335
+ };
1336
+ function Rt(e) {
1337
+ return typeof e?.format == "string";
1338
+ }
1339
+ function Ro(e, t) {
1340
+ let r = [];
1341
+ if (Re(e)) {
1342
+ if (!Rt(t)) throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");
1343
+ return r.push(t._layout), { usedVertexLayouts: r, bufferDefinitions: [{ arrayStride: t._layout.stride, stepMode: t._layout.stepMode, attributes: [{ format: t.format, offset: t.offset, shaderLocation: Pe(e) ?? 0 }] }] };
1344
+ }
1345
+ let n = [], a = /* @__PURE__ */ new WeakMap(), s = 0;
1346
+ for (let [i, l] of Object.entries(e)) {
1347
+ if (Ft(l)) continue;
1348
+ let o = t[i];
1349
+ if (!o) throw new Error(`An attribute by the name of '${i}' was not provided to the shader.`);
1350
+ let y = o._layout, h = a.get(y);
1351
+ h || (r.push(y), h = [], n.push({ arrayStride: y.stride, stepMode: y.stepMode, attributes: h }), a.set(y, h)), s = Pe(l) ?? s, h.push({ format: o.format, offset: o.offset, shaderLocation: s++ });
1352
+ }
1353
+ return { usedVertexLayouts: r, bufferDefinitions: n };
1354
+ }
1355
+ var qo = ["bool", "f32", "f16", "i32", "u32", "vec2f", "vec3f", "vec4f", "vec2h", "vec3h", "vec4h", "vec2i", "vec3i", "vec4i", "vec2u", "vec3u", "vec4u", "vec2<bool>", "vec3<bool>", "vec4<bool>", "mat2x2f", "mat3x3f", "mat4x4f"];
1356
+ function jo(e) {
1357
+ return qo.includes(e.type);
1358
+ }
1359
+ function er(e, [t, r]) {
1360
+ return ` ${lr(r)}${t}: ${e.resolve(r)},
1361
+ `;
1362
+ }
1363
+ function Vo(e, t) {
1364
+ if (t[c].isAbstruct) throw new Error("Cannot resolve abstract struct types to WGSL.");
1365
+ let r = e.names.makeUnique(g(t));
1366
+ return e.addDeclaration(`struct ${r} {
1367
+ ${Object.entries(t.propTypes).map((n) => er(e, n)).join("")}}`), r;
1368
+ }
1369
+ function Jo(e, t) {
1370
+ let r = e.names.makeUnique(g(t));
1371
+ return e.addDeclaration(`struct ${r} {
1372
+ ${Object.entries(t.propTypes).map((n) => Rt(n[1]) ? er(e, [n[0], ze[n[1].format]]) : er(e, n)).join("")}
1373
+ }`), r;
1374
+ }
1375
+ function Zo(e, t) {
1376
+ let r = e.resolve(t.elementType);
1377
+ return t.elementCount === 0 ? `array<${r}>` : `array<${r}, ${t.elementCount}>`;
1378
+ }
1379
+ function Xo(e, t) {
1380
+ let r = e.resolve(Rt(t.elementType) ? ze[t.elementType.format] : t.elementType);
1381
+ return t.elementCount === 0 ? `array<${r}>` : `array<${r}, ${t.elementCount}>`;
1382
+ }
1383
+ function Zn(e, t) {
1384
+ if (pr(t)) return t.type === "unstruct" ? Jo(e, t) : t.type === "disarray" ? Xo(e, t) : t.type === "loose-decorated" ? e.resolve(Rt(t.inner) ? ze[t.inner.format] : t.inner) : e.resolve(ze[t.type]);
1385
+ if (jo(t)) return t.type;
1386
+ if (t.type === "struct") return Vo(e, t);
1387
+ if (t.type === "array") return Zo(e, t);
1388
+ if (t.type === "atomic") return `atomic<${Zn(e, t.inner)}>`;
1389
+ if (t.type === "decorated") return e.resolve(t.inner);
1390
+ if (t.type === "ptr") return t.addressSpace === "storage" ? `ptr<storage, ${e.resolve(t.inner)}, ${t.access === "read-write" ? "read_write" : t.access}>` : `ptr<${t.addressSpace}, ${e.resolve(t.inner)}>`;
1391
+ if (t.type === "abstractInt" || t.type === "abstractFloat" || t.type === "void" || t.type === "u16") throw new Error(`${t.type} has no representation in WGSL`);
1392
+ rt(t, "resolveData");
1393
+ }
1394
+ var Xn = class tr {
1395
+ constructor(t) {
1396
+ this.bindings = t;
1397
+ }
1398
+ with(t, r) {
1399
+ return new tr([...this.bindings, [Nt(t) ? t.slot : t, r]]);
1400
+ }
1401
+ pipe(t) {
1402
+ let r = t(this);
1403
+ return new tr([...this.bindings, ...r.bindings]);
1404
+ }
1405
+ };
1406
+ function* Qo(e) {
1407
+ let t = 0;
1408
+ for (; ; ) e.has(t) || (yield t), t++;
1409
+ }
1410
+ function Ko(e, t) {
1411
+ let r = "size" in e ? e.size : e.currentByteOffset, n = t - 1, a = r & n;
1412
+ "skipBytes" in e ? e.skipBytes(t - a & n) : e.add(t - a & n);
1413
+ }
1414
+ var V = Ko, jr = /* @__PURE__ */ new WeakMap();
1415
+ function Qn(e) {
1416
+ let t = jr.get(e);
1417
+ if (t) return t;
1418
+ let r = new N(), n = {}, a;
1419
+ for (let s in e.propTypes) {
1420
+ let i = e.propTypes[s];
1421
+ if (i === void 0) throw new Error(`Property ${s} is undefined in struct`);
1422
+ let l = r.size;
1423
+ V(r, ut(e) ? Oe(i) : re(i)), a && (a.padding = r.size - l);
1424
+ let o = D(i);
1425
+ n[s] = { offset: r.size, size: o }, a = n[s], r.add(o);
1426
+ }
1427
+ return a && (a.padding = $e(D(e), re(e)) - r.size), jr.set(e, n), n;
1428
+ }
1429
+ var Ho = (() => {
1430
+ try {
1431
+ return new Function("return true"), !0;
1432
+ } catch {
1433
+ return !1;
1434
+ }
1435
+ })(), Jt = /* @__PURE__ */ new WeakMap(), mt = { u32: "u32", vec2u: "u32", vec3u: "u32", vec4u: "u32", u16: "u16", i32: "i32", vec2i: "i32", vec3i: "i32", vec4i: "i32", f32: "f32", vec2f: "f32", vec3f: "f32", vec4f: "f32", f16: "f16", vec2h: "f16", vec3h: "f16", vec4h: "f16", mat2x2f: "f32", mat3x3f: "f32", mat4x4f: "f32" }, eu = { uint8: "u8", uint8x2: "u8", uint8x4: "u8", sint8: "i8", sint8x2: "i8", sint8x4: "i8", unorm8: "u8", unorm8x2: "u8", unorm8x4: "u8", snorm8: "i8", snorm8x2: "i8", snorm8x4: "i8", uint16: "u16", uint16x2: "u16", uint16x4: "u16", sint16: "i16", sint16x2: "i16", sint16x4: "i16", unorm16: "u16", unorm16x2: "u16", unorm16x4: "u16", snorm16: "i16", snorm16x2: "i16", snorm16x4: "i16", float16: "f16", float16x2: "f16", float16x4: "f16", float32: "f32", float32x2: "f32", float32x3: "f32", float32x4: "f32", uint32: "u32", uint32x2: "u32", uint32x3: "u32", uint32x4: "u32", sint32: "i32", sint32x2: "i32", sint32x3: "i32", sint32x4: "i32" }, yt = { u32: "setUint32", i32: "setInt32", f32: "setFloat32", u16: "setUint16", i16: "setInt16", f16: "setFloat16", u8: "setUint8", i8: "setInt8" }, tu = { unorm8: (e) => `Math.round(${e} * 255)`, unorm8x2: (e) => `Math.round(${e} * 255)`, unorm8x4: (e) => `Math.round(${e} * 255)`, snorm8: (e) => `Math.round(${e} * 127)`, snorm8x2: (e) => `Math.round(${e} * 127)`, snorm8x4: (e) => `Math.round(${e} * 127)`, unorm16: (e) => `Math.round(${e} * 65535)`, unorm16x2: (e) => `Math.round(${e} * 65535)`, unorm16x4: (e) => `Math.round(${e} * 65535)`, snorm16: (e) => `Math.round(${e} * 32767)`, snorm16x2: (e) => `Math.round(${e} * 32767)`, snorm16x4: (e) => `Math.round(${e} * 32767)` }, Vr = { "unorm10-10-10-2": { writeFunction: "setUint32", generator: (e, t) => `output.setUint32(${e}, ((${t}.x*1023&0x3FF)<<22)|((${t}.y*1023&0x3FF)<<12)|((${t}.z*1023&0x3FF)<<2)|(${t}.w*3&3), littleEndian);
1436
+ ` }, "unorm8x4-bgra": { writeFunction: "setUint8", generator: (e, t) => {
1437
+ let r = ["z", "y", "x", "w"], n = "";
1438
+ for (let a = 0; a < 4; a++) n += `output.setUint8((${e} + ${a}), Math.round(${t}.${r[a]} * 255), littleEndian);
1439
+ `;
1440
+ return n;
1441
+ } } };
1442
+ function bt(e, t, r) {
1443
+ if (yn(e) || dr(e)) return bt(e.inner, t, r);
1444
+ if (be(e) || ut(e)) {
1445
+ let a = Qn(e), s = "";
1446
+ for (let [i, l] of Object.entries(a)) {
1447
+ let o = e.propTypes[i];
1448
+ o && (s += bt(o, `(${t} + ${l.offset})`, `${r}.${i}`));
1449
+ }
1450
+ return s;
1451
+ }
1452
+ if (lt(e) || cr(e)) {
1453
+ let a = $e(D(e.elementType), re(e)), s = "";
1454
+ return s += `for (let i = 0; i < ${e.elementCount}; i++) {
1455
+ `, s += bt(e.elementType, `(${t} + i * ${a})`, `${r}[i]`), s += `}
1456
+ `, s;
1457
+ }
1458
+ if (ei(e)) {
1459
+ let a = mt[e.type], s = "", i = yt[a], l = ["x", "y", "z", "w"], o = Cr(e) ? 2 : Nr(e) ? 3 : 4;
1460
+ for (let y = 0; y < o; y++) s += `output.${i}((${t} + ${y * 4}), ${r}.${l[y]}, littleEndian);
1461
+ `;
1462
+ return s;
1463
+ }
1464
+ if (ti(e)) {
1465
+ let a = mt[e.type], s = yt[a], i = ri(e) ? 2 : ni(e) ? 3 : 4, l = i * i, o = $e(i * 4, 8), y = "";
1466
+ for (let h = 0; h < l; h++) {
1467
+ let w = Math.floor(h / i), b = h % i, v = w * o + b * 4;
1468
+ y += `output.${s}((${t} + ${v}), ${r}.columns[${w}].${["x", "y", "z", "w"][b]}, littleEndian);
1469
+ `;
1470
+ }
1471
+ return y;
1472
+ }
1473
+ if (gn(e)) {
1474
+ let a = e.type;
1475
+ if (a in Vr) return Vr[a].generator(t, r);
1476
+ let s = eu[a], i = yt[s], l = ze[a], o = ai(l) ? 4 : Nr(l) ? 3 : Cr(l) ? 2 : 1, y = s === "u8" || s === "i8" ? 1 : s === "u16" || s === "i16" || s === "f16" ? 2 : 4, h = ["x", "y", "z", "w"], w = tu[a], b = "";
1477
+ for (let v = 0; v < o; v++) {
1478
+ let x = o === 1 ? r : `${r}.${h[v]}`, P = w ? w(x) : x;
1479
+ b += `output.${i}((${t} + ${v * y}), ${P}, littleEndian);
1480
+ `;
1481
+ }
1482
+ return b;
1483
+ }
1484
+ if (!Object.hasOwn(mt, e.type)) throw new Error(`Primitive ${e.type} is unsupported by compiled writer`);
1485
+ let n = mt[e.type];
1486
+ return `output.${yt[n]}(${t}, ${r}, littleEndian);
1487
+ `;
1488
+ }
1489
+ function Jr(e) {
1490
+ if (!Ho) {
1491
+ console.warn("This environment does not allow eval - using default writer as fallback");
1492
+ return;
1493
+ }
1494
+ if (Jt.has(e)) return Jt.get(e);
1495
+ try {
1496
+ let t = bt(e, "offset", "value"), r = new Function("output", "offset", "value", "littleEndian=true", t);
1497
+ return Jt.set(e, r), r;
1498
+ } catch (t) {
1499
+ console.warn(`Failed to compile writer for schema: ${e}
1500
+ Reason: ${t instanceof Error ? t.message : String(t)}
1501
+ Falling back to default writer`);
1502
+ }
1503
+ }
1504
+ var Le = { bool() {
1505
+ throw new Error("Booleans are not host-shareable");
1506
+ }, f32(e, t, r) {
1507
+ e.writeFloat32(r);
1508
+ }, f16(e, t, r) {
1509
+ e.writeFloat16(r);
1510
+ }, i32(e, t, r) {
1511
+ e.writeInt32(r);
1512
+ }, u32(e, t, r) {
1513
+ e.writeUint32(r);
1514
+ }, u16(e, t, r) {
1515
+ e.writeUint16(r);
1516
+ }, vec2f(e, t, r) {
1517
+ e.writeFloat32(r.x), e.writeFloat32(r.y);
1518
+ }, vec2h(e, t, r) {
1519
+ e.writeFloat16(r.x), e.writeFloat16(r.y);
1520
+ }, vec2i(e, t, r) {
1521
+ e.writeInt32(r.x), e.writeInt32(r.y);
1522
+ }, vec2u(e, t, r) {
1523
+ e.writeUint32(r.x), e.writeUint32(r.y);
1524
+ }, "vec2<bool>"() {
1525
+ throw new Error("Booleans are not host-shareable");
1526
+ }, vec3f(e, t, r) {
1527
+ e.writeFloat32(r.x), e.writeFloat32(r.y), e.writeFloat32(r.z);
1528
+ }, vec3h(e, t, r) {
1529
+ e.writeFloat16(r.x), e.writeFloat16(r.y), e.writeFloat16(r.z);
1530
+ }, vec3i(e, t, r) {
1531
+ e.writeInt32(r.x), e.writeInt32(r.y), e.writeInt32(r.z);
1532
+ }, vec3u(e, t, r) {
1533
+ e.writeUint32(r.x), e.writeUint32(r.y), e.writeUint32(r.z);
1534
+ }, "vec3<bool>"() {
1535
+ throw new Error("Booleans are not host-shareable");
1536
+ }, vec4f(e, t, r) {
1537
+ e.writeFloat32(r.x), e.writeFloat32(r.y), e.writeFloat32(r.z), e.writeFloat32(r.w);
1538
+ }, vec4h(e, t, r) {
1539
+ e.writeFloat16(r.x), e.writeFloat16(r.y), e.writeFloat16(r.z), e.writeFloat16(r.w);
1540
+ }, vec4i(e, t, r) {
1541
+ e.writeInt32(r.x), e.writeInt32(r.y), e.writeInt32(r.z), e.writeInt32(r.w);
1542
+ }, vec4u(e, t, r) {
1543
+ e.writeUint32(r.x), e.writeUint32(r.y), e.writeUint32(r.z), e.writeUint32(r.w);
1544
+ }, "vec4<bool>"() {
1545
+ throw new Error("Booleans are not host-shareable");
1546
+ }, mat2x2f(e, t, r) {
1547
+ for (let n = 0; n < r.length; ++n) e.writeFloat32(r[n]);
1548
+ }, mat3x3f(e, t, r) {
1549
+ for (let n = 0; n < r.length; ++n) e.writeFloat32(r[n]);
1550
+ }, mat4x4f(e, t, r) {
1551
+ for (let n = 0; n < r.length; ++n) e.writeFloat32(r[n]);
1552
+ }, struct(e, t, r) {
1553
+ let n = re(t);
1554
+ V(e, n);
1555
+ for (let [a, s] of Object.entries(t.propTypes)) V(e, re(s)), nt(e, s, r[a]);
1556
+ V(e, n);
1557
+ }, array(e, t, r) {
1558
+ if (t.elementCount === 0) throw new Error("Cannot write using a runtime-sized schema.");
1559
+ let n = re(t);
1560
+ V(e, n);
1561
+ let a = e.currentByteOffset;
1562
+ for (let s = 0; s < Math.min(t.elementCount, r.length); s++) V(e, n), nt(e, t.elementType, r[s]);
1563
+ e.seekTo(a + D(t));
1564
+ }, ptr() {
1565
+ throw new Error("Pointers are not host-shareable");
1566
+ }, atomic(e, t, r) {
1567
+ Le[t.inner.type]?.(e, t, r);
1568
+ }, decorated(e, t, r) {
1569
+ let n = Oe(t);
1570
+ V(e, n);
1571
+ let a = e.currentByteOffset;
1572
+ Le[t.inner?.type]?.(e, t.inner, r), e.seekTo(a + D(t));
1573
+ }, uint8(e, t, r) {
1574
+ e.writeUint8(r);
1575
+ }, uint8x2(e, t, r) {
1576
+ e.writeUint8(r.x), e.writeUint8(r.y);
1577
+ }, uint8x4(e, t, r) {
1578
+ e.writeUint8(r.x), e.writeUint8(r.y), e.writeUint8(r.z), e.writeUint8(r.w);
1579
+ }, sint8(e, t, r) {
1580
+ e.writeInt8(r);
1581
+ }, sint8x2(e, t, r) {
1582
+ e.writeInt8(r.x), e.writeInt8(r.y);
1583
+ }, sint8x4(e, t, r) {
1584
+ e.writeInt8(r.x), e.writeInt8(r.y), e.writeInt8(r.z), e.writeInt8(r.w);
1585
+ }, unorm8(e, t, r) {
1586
+ e.writeUint8(Math.round(r * 255));
1587
+ }, unorm8x2(e, t, r) {
1588
+ e.writeUint8(Math.round(r.x * 255)), e.writeUint8(Math.round(r.y * 255));
1589
+ }, unorm8x4(e, t, r) {
1590
+ e.writeUint8(Math.round(r.x * 255)), e.writeUint8(Math.round(r.y * 255)), e.writeUint8(Math.round(r.z * 255)), e.writeUint8(Math.round(r.w * 255));
1591
+ }, snorm8(e, t, r) {
1592
+ e.writeInt8(Math.round(r * 127));
1593
+ }, snorm8x2(e, t, r) {
1594
+ e.writeInt8(Math.round(r.x * 127)), e.writeInt8(Math.round(r.y * 127));
1595
+ }, snorm8x4(e, t, r) {
1596
+ e.writeInt8(Math.round(r.x * 127)), e.writeInt8(Math.round(r.y * 127)), e.writeInt8(Math.round(r.z * 127)), e.writeInt8(Math.round(r.w * 127));
1597
+ }, uint16(e, t, r) {
1598
+ e.writeUint16(r);
1599
+ }, uint16x2(e, t, r) {
1600
+ e.writeUint16(r.x), e.writeUint16(r.y);
1601
+ }, uint16x4(e, t, r) {
1602
+ e.writeUint16(r.x), e.writeUint16(r.y), e.writeUint16(r.z), e.writeUint16(r.w);
1603
+ }, sint16(e, t, r) {
1604
+ e.writeInt16(r);
1605
+ }, sint16x2(e, t, r) {
1606
+ e.writeInt16(r.x), e.writeInt16(r.y);
1607
+ }, sint16x4(e, t, r) {
1608
+ e.writeInt16(r.x), e.writeInt16(r.y), e.writeInt16(r.z), e.writeInt16(r.w);
1609
+ }, unorm16(e, t, r) {
1610
+ e.writeUint16(r * 65535);
1611
+ }, unorm16x2(e, t, r) {
1612
+ e.writeUint16(r.x * 65535), e.writeUint16(r.y * 65535);
1613
+ }, unorm16x4(e, t, r) {
1614
+ e.writeUint16(r.x * 65535), e.writeUint16(r.y * 65535), e.writeUint16(r.z * 65535), e.writeUint16(r.w * 65535);
1615
+ }, snorm16(e, t, r) {
1616
+ e.writeInt16(Math.round(r * 32767));
1617
+ }, snorm16x2(e, t, r) {
1618
+ e.writeInt16(Math.round(r.x * 32767)), e.writeInt16(Math.round(r.y * 32767));
1619
+ }, snorm16x4(e, t, r) {
1620
+ e.writeInt16(Math.round(r.x * 32767)), e.writeInt16(Math.round(r.y * 32767)), e.writeInt16(Math.round(r.z * 32767)), e.writeInt16(Math.round(r.w * 32767));
1621
+ }, float16(e, t, r) {
1622
+ e.writeFloat16(r);
1623
+ }, float16x2(e, t, r) {
1624
+ e.writeFloat16(r.x), e.writeFloat16(r.y);
1625
+ }, float16x4(e, t, r) {
1626
+ e.writeFloat16(r.x), e.writeFloat16(r.y), e.writeFloat16(r.z), e.writeFloat16(r.w);
1627
+ }, float32(e, t, r) {
1628
+ e.writeFloat32(r);
1629
+ }, float32x2(e, t, r) {
1630
+ e.writeFloat32(r.x), e.writeFloat32(r.y);
1631
+ }, float32x3(e, t, r) {
1632
+ e.writeFloat32(r.x), e.writeFloat32(r.y), e.writeFloat32(r.z);
1633
+ }, float32x4(e, t, r) {
1634
+ e.writeFloat32(r.x), e.writeFloat32(r.y), e.writeFloat32(r.z), e.writeFloat32(r.w);
1635
+ }, uint32(e, t, r) {
1636
+ e.writeUint32(r);
1637
+ }, uint32x2(e, t, r) {
1638
+ e.writeUint32(r.x), e.writeUint32(r.y);
1639
+ }, uint32x3(e, t, r) {
1640
+ e.writeUint32(r.x), e.writeUint32(r.y), e.writeUint32(r.z);
1641
+ }, uint32x4(e, t, r) {
1642
+ e.writeUint32(r.x), e.writeUint32(r.y), e.writeUint32(r.z), e.writeUint32(r.w);
1643
+ }, sint32(e, t, r) {
1644
+ e.writeInt32(r);
1645
+ }, sint32x2(e, t, r) {
1646
+ e.writeInt32(r.x), e.writeInt32(r.y);
1647
+ }, sint32x3(e, t, r) {
1648
+ e.writeInt32(r.x), e.writeInt32(r.y), e.writeInt32(r.z);
1649
+ }, sint32x4(e, t, r) {
1650
+ e.writeInt32(r.x), e.writeInt32(r.y), e.writeInt32(r.z), e.writeInt32(r.w);
1651
+ }, "unorm10-10-10-2"(e, t, r) {
1652
+ let n = 0;
1653
+ n |= (r.x * 1023 & 1023) << 22, n |= (r.y * 1023 & 1023) << 12, n |= (r.z * 1023 & 1023) << 2, n |= r.w * 3 & 3, e.writeUint32(n);
1654
+ }, "unorm8x4-bgra"(e, t, r) {
1655
+ e.writeUint8(r.z * 255), e.writeUint8(r.y * 255), e.writeUint8(r.x * 255), e.writeUint8(r.w * 255);
1656
+ }, disarray(e, t, r) {
1657
+ let n = re(t);
1658
+ V(e, n);
1659
+ let a = e.currentByteOffset;
1660
+ for (let s = 0; s < Math.min(t.elementCount, r.length); s++) V(e, n), Le[t.elementType?.type]?.(e, t.elementType, r[s]);
1661
+ e.seekTo(a + D(t));
1662
+ }, unstruct(e, t, r) {
1663
+ let n = t.propTypes;
1664
+ for (let [a, s] of Object.entries(n)) Le[s.type]?.(e, s, r[a]);
1665
+ }, "loose-decorated"(e, t, r) {
1666
+ let n = Oe(t);
1667
+ V(e, n);
1668
+ let a = e.currentByteOffset, s = Le[t.inner?.type];
1669
+ return s?.(e, t.inner, r), e.seekTo(a + D(t)), r;
1670
+ } };
1671
+ function nt(e, t, r) {
1672
+ let n = Le[t.type];
1673
+ if (!n) throw new Error(`Cannot write data of type '${t.type}'.`);
1674
+ n(e, t, r);
1675
+ }
1676
+ var ru = { bool() {
1677
+ throw new Error("Booleans are not host-shareable");
1678
+ }, f32(e) {
1679
+ return e.readFloat32();
1680
+ }, f16(e) {
1681
+ return e.readFloat16();
1682
+ }, i32(e) {
1683
+ return e.readInt32();
1684
+ }, u32(e) {
1685
+ return e.readUint32();
1686
+ }, u16(e) {
1687
+ return e.readUint16();
1688
+ }, vec2f(e) {
1689
+ return _(e.readFloat32(), e.readFloat32());
1690
+ }, vec3f(e) {
1691
+ return S(e.readFloat32(), e.readFloat32(), e.readFloat32());
1692
+ }, vec4f(e) {
1693
+ return O(e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32());
1694
+ }, vec2h(e) {
1695
+ return Ke(e.readFloat16(), e.readFloat16());
1696
+ }, vec3h(e) {
1697
+ return He(e.readFloat16(), e.readFloat16(), e.readFloat16());
1698
+ }, vec4h(e) {
1699
+ return et(e.readFloat16(), e.readFloat16(), e.readFloat16(), e.readFloat16());
1700
+ }, vec2i(e) {
1701
+ return K(e.readInt32(), e.readInt32());
1702
+ }, vec3i(e) {
1703
+ return Ue(e.readInt32(), e.readInt32(), e.readInt32());
1704
+ }, vec4i(e) {
1705
+ return te(e.readInt32(), e.readInt32(), e.readInt32(), e.readInt32());
1706
+ }, vec2u(e) {
1707
+ return ne(e.readUint32(), e.readUint32());
1708
+ }, vec3u(e) {
1709
+ return Ut(e.readUint32(), e.readUint32(), e.readUint32());
1710
+ }, vec4u(e) {
1711
+ return ue(e.readUint32(), e.readUint32(), e.readUint32(), e.readUint32());
1712
+ }, "vec2<bool>"() {
1713
+ throw new Error("Booleans are not host-shareable");
1714
+ }, "vec3<bool>"() {
1715
+ throw new Error("Booleans are not host-shareable");
1716
+ }, "vec4<bool>"() {
1717
+ throw new Error("Booleans are not host-shareable");
1718
+ }, mat2x2f(e) {
1719
+ return vn(e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32());
1720
+ }, mat3x3f(e) {
1721
+ let t = () => {
1722
+ let r = e.readFloat32();
1723
+ return e.readFloat32(), r;
1724
+ };
1725
+ return _n(e.readFloat32(), e.readFloat32(), t(), e.readFloat32(), e.readFloat32(), t(), e.readFloat32(), e.readFloat32(), t());
1726
+ }, mat4x4f(e) {
1727
+ return xn(e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32());
1728
+ }, struct(e, t) {
1729
+ let r = re(t);
1730
+ V(e, r);
1731
+ let n = {}, a = t.propTypes;
1732
+ for (let [s, i] of Object.entries(a)) V(e, re(i)), n[s] = ce(e, i);
1733
+ return V(e, r), n;
1734
+ }, array(e, t) {
1735
+ if (t.elementCount === 0) throw new Error("Cannot read using a runtime-sized schema.");
1736
+ let r = re(t), n = [];
1737
+ for (let a = 0; a < t.elementCount; a++) {
1738
+ V(e, r);
1739
+ let s = t.elementType, i = ce(e, s);
1740
+ n.push(i);
1741
+ }
1742
+ return V(e, r), n;
1743
+ }, ptr() {
1744
+ throw new Error("Pointers are not host-shareable");
1745
+ }, atomic(e, t) {
1746
+ return ce(e, t.inner);
1747
+ }, decorated(e, t) {
1748
+ let r = Oe(t);
1749
+ V(e, r);
1750
+ let n = e.currentByteOffset, a = ce(e, t.inner);
1751
+ return e.seekTo(n + D(t)), a;
1752
+ }, uint8: (e) => e.readUint8(), uint8x2: (e) => ne(e.readUint8(), e.readUint8()), uint8x4: (e) => ue(e.readUint8(), e.readUint8(), e.readUint8(), e.readUint8()), sint8: (e) => e.readInt8(), sint8x2: (e) => K(e.readInt8(), e.readInt8()), sint8x4: (e) => te(e.readInt8(), e.readInt8(), e.readInt8(), e.readInt8()), unorm8: (e) => e.readUint8() / 255, unorm8x2: (e) => _(e.readUint8() / 255, e.readUint8() / 255), unorm8x4: (e) => O(e.readUint8() / 255, e.readUint8() / 255, e.readUint8() / 255, e.readUint8() / 255), snorm8: (e) => e.readInt8() / 127, snorm8x2: (e) => _(e.readInt8() / 127, e.readInt8() / 127), snorm8x4: (e) => O(e.readInt8() / 127, e.readInt8() / 127, e.readInt8() / 127, e.readInt8() / 127), uint16: (e) => e.readUint16(), uint16x2: (e) => ne(e.readUint16(), e.readUint16()), uint16x4: (e) => ue(e.readUint16(), e.readUint16(), e.readUint16(), e.readUint16()), sint16: (e) => e.readInt16(), sint16x2: (e) => K(e.readInt16(), e.readInt16()), sint16x4: (e) => te(e.readInt16(), e.readInt16(), e.readInt16(), e.readInt16()), unorm16: (e) => e.readUint16() / 65535, unorm16x2: (e) => _(e.readUint16() / 65535, e.readUint16() / 65535), unorm16x4: (e) => O(e.readUint16() / 65535, e.readUint16() / 65535, e.readUint16() / 65535, e.readUint16() / 65535), snorm16: (e) => e.readInt16() / 32767, snorm16x2: (e) => _(e.readInt16() / 32767, e.readInt16() / 32767), snorm16x4: (e) => O(e.readInt16() / 32767, e.readInt16() / 32767, e.readInt16() / 32767, e.readInt16() / 32767), float16(e) {
1753
+ return e.readFloat16();
1754
+ }, float16x2: (e) => _(e.readFloat16(), e.readFloat16()), float16x4: (e) => O(e.readFloat16(), e.readFloat16(), e.readFloat16(), e.readFloat16()), float32: (e) => e.readFloat32(), float32x2: (e) => _(e.readFloat32(), e.readFloat32()), float32x3: (e) => S(e.readFloat32(), e.readFloat32(), e.readFloat32()), float32x4: (e) => O(e.readFloat32(), e.readFloat32(), e.readFloat32(), e.readFloat32()), uint32: (e) => e.readUint32(), uint32x2: (e) => ne(e.readUint32(), e.readUint32()), uint32x3: (e) => Ut(e.readUint32(), e.readUint32(), e.readUint32()), uint32x4: (e) => ue(e.readUint32(), e.readUint32(), e.readUint32(), e.readUint32()), sint32: (e) => e.readInt32(), sint32x2: (e) => K(e.readInt32(), e.readInt32()), sint32x3: (e) => Ue(e.readInt32(), e.readInt32(), e.readInt32()), sint32x4: (e) => te(e.readInt32(), e.readInt32(), e.readInt32(), e.readInt32()), "unorm10-10-10-2"(e) {
1755
+ let t = e.readUint32(), r = (t >> 22) / 1023, n = (t >> 12 & 1023) / 1023, a = (t >> 2 & 1023) / 1023, s = (t & 3) / 3;
1756
+ return O(r, n, a, s);
1757
+ }, "unorm8x4-bgra"(e) {
1758
+ let t = e.readByte() / 255, r = e.readByte() / 255, n = e.readByte() / 255, a = e.readByte() / 255;
1759
+ return O(n, r, t, a);
1760
+ }, unstruct(e, t) {
1761
+ let r = {}, n = t.propTypes;
1762
+ for (let [a, s] of Object.entries(n)) r[a] = ce(e, s);
1763
+ return r;
1764
+ }, disarray(e, t) {
1765
+ let r = re(t), n = [];
1766
+ for (let a = 0; a < t.elementCount; a++) V(e, r), n.push(ce(e, t.elementType));
1767
+ return V(e, r), n;
1768
+ }, "loose-decorated"(e, t) {
1769
+ V(e, Oe(t));
1770
+ let r = e.currentByteOffset, n = ce(e, t.inner);
1771
+ return e.seekTo(r + D(t)), n;
1772
+ } };
1773
+ function ce(e, t) {
1774
+ let r = ru[t.type];
1775
+ if (!r) throw new Error(`Cannot read data of type '${t.type}'.`);
1776
+ return r(e, t);
1777
+ }
1778
+ function nu(e, t) {
1779
+ let r = D(e);
1780
+ if (r === 0 || t === void 0 || t === null) return [];
1781
+ let n = new ArrayBuffer(r), a = new Se(n), s = [];
1782
+ function i(y, h, w, b) {
1783
+ if (h != null) {
1784
+ if (be(y) || ut(y)) {
1785
+ let v = Qn(y);
1786
+ for (let [x, P] of Object.entries(v)) {
1787
+ let $ = y.propTypes[x];
1788
+ if (!$) continue;
1789
+ let k = h[x];
1790
+ k !== void 0 && i($, k, w + P.offset, P.padding ?? b);
1791
+ }
1792
+ return;
1793
+ }
1794
+ if (lt(y) || cr(y)) {
1795
+ let v = y, x = $e(D(v.elementType), re(v.elementType));
1796
+ if (!Array.isArray(h)) throw new Error("Partial value for array must be an array");
1797
+ let P = h ?? [];
1798
+ P.sort(($, k) => $.idx - k.idx);
1799
+ for (let { idx: $, value: k } of P) i(v.elementType, k, w + $ * x, x - D(v.elementType));
1800
+ } else {
1801
+ let v = D(y);
1802
+ a.seekTo(w), nt(a, y, h), s.push({ start: w, end: w + v, padding: b });
1803
+ }
1804
+ }
1805
+ }
1806
+ if (i(e, t, 0), s.length === 0) return [];
1807
+ let l = [], o = s[0];
1808
+ for (let y = 1; y < s.length; y++) {
1809
+ let h = s[y];
1810
+ if (!h || !o) throw new Error("Internal error: missing segment");
1811
+ h.start === o.end + (o.padding ?? 0) ? (o.end = h.end, o.padding = h.padding) : (l.push({ data: new Uint8Array(n, o.start, o.end - o.start) }), o = h);
1812
+ }
1813
+ if (!o) throw new Error("Internal error: missing segment");
1814
+ return l.push({ data: new Uint8Array(n, o.start, o.end - o.start) }), l;
1815
+ }
1816
+ function Mt(e) {
1817
+ return !!e?.usableAsStorage;
1818
+ }
1819
+ var Zr = class Kn extends Error {
1820
+ constructor(t) {
1821
+ super(`Resource '${g(t) ?? "<unnamed>"}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`), Object.setPrototypeOf(this, Kn.prototype);
1822
+ }
1823
+ };
1824
+ function Hn(e) {
1825
+ return !!e.usableAsUniform;
1826
+ }
1827
+ var ea = { uniform: "uniform", mutable: "storage, read_write", readonly: "storage, read" }, Er = class {
1828
+ constructor(t, r) {
1829
+ this.usage = t, this.buffer = r, this[c] = { dataType: r.dataType }, this[Y] = r;
1830
+ }
1831
+ resourceType = "buffer-usage";
1832
+ [c];
1833
+ [Y];
1834
+ $name(t) {
1835
+ return this.buffer.$name(t), this;
1836
+ }
1837
+ "~resolve"(t) {
1838
+ let r = t.names.makeUnique(g(this)), { group: n, binding: a } = t.allocateFixedEntry(this.usage === "uniform" ? { uniform: this.buffer.dataType } : { storage: this.buffer.dataType, access: this.usage }, this.buffer), s = ea[this.usage];
1839
+ return t.addDeclaration(`@group(${n}) @binding(${a}) var<${s}> ${r}: ${t.resolve(this.buffer.dataType)};`), r;
1840
+ }
1841
+ toString() {
1842
+ return `${this.usage}:${g(this) ?? "<unnamed>"}`;
1843
+ }
1844
+ [j]() {
1845
+ return new Proxy({ [c]: !0, "~resolve": (t) => t.resolve(this), toString: () => `.value:${g(this) ?? "<unnamed>"}`, [C]: this.buffer.dataType }, qe);
1846
+ }
1847
+ get $() {
1848
+ let t = St(), r = It();
1849
+ if (t.type === "normal") throw new Lr(r ? `Cannot access ${String(this.buffer)}. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation` : ".$ and .value are inaccessible during normal JS execution. Try `.read()`");
1850
+ return t.type === "codegen" ? this[j]() : t.type === "simulate" ? (t.buffers.has(this.buffer) || t.buffers.set(this.buffer, kn(this.buffer.dataType, this.buffer.initial)), t.buffers.get(this.buffer)) : rt(t, "bufferUsage.ts#TgpuFixedBufferImpl/$");
1851
+ }
1852
+ get value() {
1853
+ return this.$;
1854
+ }
1855
+ set $(t) {
1856
+ let r = St(), n = It();
1857
+ if (r.type === "normal") throw new Lr(n ? `Cannot access ${String(this.buffer)}. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation` : ".$ and .value are inaccessible during normal JS execution. Try `.write()`");
1858
+ if (r.type === "codegen") throw new Error("Unreachable bufferUsage.ts#TgpuFixedBufferImpl/$");
1859
+ if (r.type === "simulate") {
1860
+ r.buffers.set(this.buffer, t);
1861
+ return;
1862
+ }
1863
+ rt(r, "bufferUsage.ts#TgpuFixedBufferImpl/$");
1864
+ }
1865
+ set value(t) {
1866
+ this.$ = t;
1867
+ }
1868
+ }, Xr = class {
1869
+ constructor(t, r, n) {
1870
+ this.usage = t, this.dataType = r, this._membership = n, this[c] = { dataType: r }, F(this, n.key);
1871
+ }
1872
+ resourceType = "buffer-usage";
1873
+ [c];
1874
+ "~resolve"(t) {
1875
+ let r = t.names.makeUnique(g(this)), n = t.allocateLayoutEntry(this._membership.layout), a = ea[this.usage];
1876
+ return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var<${a}> ${r}: ${t.resolve(this.dataType)};`), r;
1877
+ }
1878
+ toString() {
1879
+ return `${this.usage}:${g(this) ?? "<unnamed>"}`;
1880
+ }
1881
+ [j]() {
1882
+ return new Proxy({ [c]: !0, "~resolve": (t) => t.resolve(this), toString: () => `.value:${g(this) ?? "<unnamed>"}`, [C]: this.dataType }, qe);
1883
+ }
1884
+ get $() {
1885
+ if (hr()) return this[j]();
1886
+ throw new Error("Direct access to buffer values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead");
1887
+ }
1888
+ get value() {
1889
+ return this.$;
1890
+ }
1891
+ }, Qr = /* @__PURE__ */ new WeakMap();
1892
+ function au(e) {
1893
+ if (!Mt(e)) throw new Error(`Cannot pass ${e} to asMutable, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);
1894
+ let t = Qr.get(e);
1895
+ return t || (t = new Er("mutable", e), Qr.set(e, t)), t;
1896
+ }
1897
+ var Kr = /* @__PURE__ */ new WeakMap();
1898
+ function su(e) {
1899
+ if (!Mt(e)) throw new Error(`Cannot pass ${e} to asReadonly, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);
1900
+ let t = Kr.get(e);
1901
+ return t || (t = new Er("readonly", e), Kr.set(e, t)), t;
1902
+ }
1903
+ var Hr = /* @__PURE__ */ new WeakMap();
1904
+ function iu(e) {
1905
+ if (!Hn(e)) throw new Error(`Cannot pass ${e} to asUniform, as it is not allowed to be used as a uniform. To allow it, call .$usage('uniform') when creating the buffer.`);
1906
+ let t = Hr.get(e);
1907
+ return t || (t = new Er("uniform", e), Hr.set(e, t)), t;
1908
+ }
1909
+ var ou = { uniform: iu, mutable: au, readonly: su };
1910
+ function wt(e, t, r) {
1911
+ return ie(t) ? new en(e, t, r) : new en(e, t, r, ["storage", "uniform"]);
1912
+ }
1913
+ function Qe(e) {
1914
+ return e.resourceType === "buffer";
1915
+ }
1916
+ var uu = /* @__PURE__ */ zn(), en = class {
1917
+ constructor(t, r, n, a) {
1918
+ this._group = t, this.dataType = r, this.initialOrBuffer = n, this._disallowedUsages = a, Kt(n) ? (this._ownBuffer = !1, this._buffer = n) : (this._ownBuffer = !0, this.initial = n);
1919
+ }
1920
+ [c] = !0;
1921
+ resourceType = "buffer";
1922
+ flags = GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC;
1923
+ _buffer = null;
1924
+ _ownBuffer;
1925
+ _destroyed = !1;
1926
+ _hostBuffer;
1927
+ initial;
1928
+ usableAsUniform = !1;
1929
+ usableAsStorage = !1;
1930
+ usableAsVertex = !1;
1931
+ usableAsIndex = !1;
1932
+ get buffer() {
1933
+ let t = this._group.device;
1934
+ if (this._destroyed) throw new Error("This buffer has been destroyed");
1935
+ if (!this._buffer && (this._buffer = t.createBuffer({ size: D(this.dataType), usage: this.flags, mappedAtCreation: !!this.initial, label: g(this) ?? "<unnamed>" }), this.initial)) {
1936
+ let r = new Se(this._buffer.getMappedRange());
1937
+ nt(r, this.dataType, this.initial), this._buffer.unmap();
1938
+ }
1939
+ return this._buffer;
1940
+ }
1941
+ get destroyed() {
1942
+ return this._destroyed;
1943
+ }
1944
+ $name(t) {
1945
+ return F(this, t), this._buffer && (this._buffer.label = t), this;
1946
+ }
1947
+ $usage(...t) {
1948
+ for (let r of t) {
1949
+ if (this._disallowedUsages?.includes(r)) throw new Error(`Buffer of type ${this.dataType.type} cannot be used as ${r}`);
1950
+ this.flags |= r === "uniform" ? GPUBufferUsage.UNIFORM : 0, this.flags |= r === "storage" ? GPUBufferUsage.STORAGE : 0, this.flags |= r === "vertex" ? GPUBufferUsage.VERTEX : 0, this.flags |= r === "index" ? GPUBufferUsage.INDEX : 0, this.usableAsUniform = this.usableAsUniform || r === "uniform", this.usableAsStorage = this.usableAsStorage || r === "storage", this.usableAsVertex = this.usableAsVertex || r === "vertex", this.usableAsIndex = this.usableAsIndex || r === "index";
1951
+ }
1952
+ return this;
1953
+ }
1954
+ $addFlags(t) {
1955
+ if (!this._ownBuffer) throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");
1956
+ return t & GPUBufferUsage.MAP_READ ? (this.flags = GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ, this) : t & GPUBufferUsage.MAP_WRITE ? (this.flags = GPUBufferUsage.COPY_SRC | GPUBufferUsage.MAP_WRITE, this) : (this.flags |= t, this);
1957
+ }
1958
+ compileWriter() {
1959
+ Jr(this.dataType);
1960
+ }
1961
+ _writeToTarget(t, r) {
1962
+ let n = Jr(this.dataType);
1963
+ if (n) try {
1964
+ n(new DataView(t), 0, r, uu === "little");
1965
+ return;
1966
+ } catch (a) {
1967
+ console.error(`Error when using compiled writer for buffer ${g(this) ?? "<unnamed>"} - this is likely a bug, please submit an issue at https://github.com/software-mansion/TypeGPU/issues
1968
+ Using fallback writer instead.`, a);
1969
+ }
1970
+ nt(new Se(t), this.dataType, r);
1971
+ }
1972
+ write(t) {
1973
+ let r = this.buffer, n = this._group.device;
1974
+ if (r.mapState === "mapped") {
1975
+ let s = r.getMappedRange();
1976
+ this._writeToTarget(s, t);
1977
+ return;
1978
+ }
1979
+ let a = D(this.dataType);
1980
+ this._hostBuffer || (this._hostBuffer = new ArrayBuffer(a)), this._group.flush(), this._writeToTarget(this._hostBuffer, t), n.queue.writeBuffer(r, 0, this._hostBuffer, 0, a);
1981
+ }
1982
+ writePartial(t) {
1983
+ let r = this.buffer, n = this._group.device, a = nu(this.dataType, t);
1984
+ if (r.mapState === "mapped") {
1985
+ let s = r.getMappedRange(), i = new Uint8Array(s);
1986
+ for (let l of a) i.set(l.data, l.data.byteOffset);
1987
+ } else for (let s of a) n.queue.writeBuffer(r, s.data.byteOffset, s.data, 0, s.data.byteLength);
1988
+ }
1989
+ copyFrom(t) {
1990
+ if (this.buffer.mapState === "mapped") throw new Error("Cannot copy to a mapped buffer.");
1991
+ let r = D(this.dataType);
1992
+ this._group.commandEncoder.copyBufferToBuffer(t.buffer, 0, this.buffer, 0, r);
1993
+ }
1994
+ async read() {
1995
+ this._group.flush();
1996
+ let t = this.buffer, r = this._group.device;
1997
+ if (t.mapState === "mapped") {
1998
+ let i = t.getMappedRange();
1999
+ return ce(new Ee(i), this.dataType);
2000
+ }
2001
+ if (t.usage & GPUBufferUsage.MAP_READ) {
2002
+ await t.mapAsync(GPUMapMode.READ);
2003
+ let i = t.getMappedRange(), l = ce(new Ee(i), this.dataType);
2004
+ return t.unmap(), l;
2005
+ }
2006
+ let n = (globalThis.__TYPEGPU_AUTONAME__ ?? ((i) => i))(r.createBuffer({ size: D(this.dataType), usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ }), "n"), a = r.createCommandEncoder();
2007
+ a.copyBufferToBuffer(t, 0, n, 0, D(this.dataType)), r.queue.submit([a.finish()]), await r.queue.onSubmittedWorkDone(), await n.mapAsync(GPUMapMode.READ, 0, D(this.dataType));
2008
+ let s = ce(new Ee(n.getMappedRange()), this.dataType);
2009
+ return n.unmap(), n.destroy(), s;
2010
+ }
2011
+ as(t) {
2012
+ return ou[t]?.(this);
2013
+ }
2014
+ destroy() {
2015
+ this._destroyed || (this._destroyed = !0, this._ownBuffer && this._buffer?.destroy());
2016
+ }
2017
+ toString() {
2018
+ return `buffer:${g(this) ?? "<unnamed>"}`;
2019
+ }
2020
+ };
2021
+ function lu(e) {
2022
+ return new hu(e);
2023
+ }
2024
+ function du(e) {
2025
+ return new fu(e);
2026
+ }
2027
+ function ta(e) {
2028
+ let t = e;
2029
+ return t?.resourceType === "sampler" && !!t[c];
2030
+ }
2031
+ function ra(e) {
2032
+ let t = e;
2033
+ return t?.resourceType === "sampler-comparison" && !!t[c];
2034
+ }
2035
+ var cu = class {
2036
+ constructor(t) {
2037
+ this._membership = t, this[C] = this, this[c] = {}, F(this, t.key);
2038
+ }
2039
+ [C];
2040
+ [c];
2041
+ resourceType = "sampler";
2042
+ "~resolve"(t) {
2043
+ let r = t.names.makeUnique(g(this)), n = t.allocateLayoutEntry(this._membership.layout);
2044
+ return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler;`), r;
2045
+ }
2046
+ toString() {
2047
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2048
+ }
2049
+ }, pu = class {
2050
+ constructor(t) {
2051
+ this._membership = t, this[C] = this, this[c] = {}, F(this, t.key);
2052
+ }
2053
+ [C];
2054
+ [c];
2055
+ resourceType = "sampler-comparison";
2056
+ "~resolve"(t) {
2057
+ let r = t.names.makeUnique(g(this)), n = t.allocateLayoutEntry(this._membership.layout);
2058
+ return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: sampler_comparison;`), r;
2059
+ }
2060
+ toString() {
2061
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2062
+ }
2063
+ }, hu = class {
2064
+ constructor(t) {
2065
+ this._props = t, this[C] = this, this[c] = { unwrap: (r) => (this._sampler || (this._sampler = r.device.createSampler({ ...this._props, label: g(this) ?? "<unnamed>" })), this._sampler) }, this._filtering = t.minFilter === "linear" || t.magFilter === "linear" || t.mipmapFilter === "linear";
2066
+ }
2067
+ [C];
2068
+ [c];
2069
+ resourceType = "sampler";
2070
+ _filtering;
2071
+ _sampler = null;
2072
+ $name(t) {
2073
+ return F(this, t), this;
2074
+ }
2075
+ "~resolve"(t) {
2076
+ let r = t.names.makeUnique(g(this)), { group: n, binding: a } = t.allocateFixedEntry({ sampler: this._filtering ? "filtering" : "non-filtering" }, this);
2077
+ return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler;`), r;
2078
+ }
2079
+ toString() {
2080
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2081
+ }
2082
+ }, fu = class {
2083
+ constructor(t) {
2084
+ this._props = t, this[C] = this, this[c] = { unwrap: (r) => (this._sampler || (this._sampler = r.device.createSampler({ ...this._props, label: g(this) ?? "<unnamed>" })), this._sampler) };
2085
+ }
2086
+ [C];
2087
+ [c];
2088
+ resourceType = "sampler-comparison";
2089
+ _sampler = null;
2090
+ $name(t) {
2091
+ return F(this, t), this;
2092
+ }
2093
+ "~resolve"(t) {
2094
+ let r = t.names.makeUnique(g(this)), { group: n, binding: a } = t.allocateFixedEntry({ sampler: "comparison" }, this);
2095
+ return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: sampler_comparison;`), r;
2096
+ }
2097
+ toString() {
2098
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2099
+ }
2100
+ }, mu = class {
2101
+ constructor(t) {
2102
+ this._membership = t, F(this, t.key);
2103
+ }
2104
+ [c] = !0;
2105
+ resourceType = "external-texture";
2106
+ "~resolve"(t) {
2107
+ let r = t.names.makeUnique(g(this)), n = t.allocateLayoutEntry(this._membership.layout);
2108
+ return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: texture_external;`), r;
2109
+ }
2110
+ toString() {
2111
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2112
+ }
2113
+ }, yu = { r8unorm: f, r8snorm: f, r8uint: m, r8sint: J, r16uint: m, r16sint: J, r16float: f, rg8unorm: f, rg8snorm: f, rg8uint: m, rg8sint: J, r32uint: m, r32sint: J, r32float: f, rg16uint: m, rg16sint: J, rg16float: f, rgba8unorm: f, "rgba8unorm-srgb": f, rgba8snorm: f, rgba8uint: m, rgba8sint: J, bgra8unorm: f, "bgra8unorm-srgb": f, rgb9e5ufloat: f, rgb10a2uint: m, rgb10a2unorm: f, rg11b10ufloat: f, rg32uint: m, rg32sint: J, rg32float: f, rgba16uint: m, rgba16sint: J, rgba16float: f, rgba32uint: m, rgba32sint: J, rgba32float: f, stencil8: f, depth16unorm: f, depth24plus: f, "depth24plus-stencil8": f, depth32float: f, "depth32float-stencil8": f, "bc1-rgba-unorm": f, "bc1-rgba-unorm-srgb": f, "bc2-rgba-unorm": f, "bc2-rgba-unorm-srgb": f, "bc3-rgba-unorm": f, "bc3-rgba-unorm-srgb": f, "bc4-r-unorm": f, "bc4-r-snorm": f, "bc5-rg-unorm": f, "bc5-rg-snorm": f, "bc6h-rgb-ufloat": f, "bc6h-rgb-float": f, "bc7-rgba-unorm": f, "bc7-rgba-unorm-srgb": f, "etc2-rgb8unorm": f, "etc2-rgb8unorm-srgb": f, "etc2-rgb8a1unorm": f, "etc2-rgb8a1unorm-srgb": f, "etc2-rgba8unorm": f, "etc2-rgba8unorm-srgb": f, "eac-r11unorm": f, "eac-r11snorm": f, "eac-rg11unorm": f, "eac-rg11snorm": f, "astc-4x4-unorm": f, "astc-4x4-unorm-srgb": f, "astc-5x4-unorm": f, "astc-5x4-unorm-srgb": f, "astc-5x5-unorm": f, "astc-5x5-unorm-srgb": f, "astc-6x5-unorm": f, "astc-6x5-unorm-srgb": f, "astc-6x6-unorm": f, "astc-6x6-unorm-srgb": f, "astc-8x5-unorm": f, "astc-8x5-unorm-srgb": f, "astc-8x6-unorm": f, "astc-8x6-unorm-srgb": f, "astc-8x8-unorm": f, "astc-8x8-unorm-srgb": f, "astc-10x5-unorm": f, "astc-10x5-unorm-srgb": f, "astc-10x6-unorm": f, "astc-10x6-unorm-srgb": f, "astc-10x8-unorm": f, "astc-10x8-unorm-srgb": f, "astc-10x10-unorm": f, "astc-10x10-unorm-srgb": f, "astc-12x10-unorm": f, "astc-12x10-unorm-srgb": f, "astc-12x12-unorm": f, "astc-12x12-unorm-srgb": f, r16snorm: f, r16unorm: f, rg16unorm: f, rg16snorm: f, rgba16unorm: f, rgba16snorm: f }, At = { rgba8unorm: O, rgba8snorm: O, rgba8uint: ue, rgba8sint: te, rgba16uint: ue, rgba16sint: te, rgba16float: O, r32uint: ue, r32sint: te, r32float: O, rg32uint: ue, rg32sint: te, rg32float: O, rgba32uint: ue, rgba32sint: te, rgba32float: O, bgra8unorm: O }, wu = { f32: "float", u32: "uint", i32: "sint" }, gu = { float: f, "unfilterable-float": f, uint: m, sint: J, depth: f };
2114
+ function bu(e, t) {
2115
+ return new vu(e, t);
2116
+ }
2117
+ function at(e) {
2118
+ return e?.resourceType === "texture" && !!e[c];
2119
+ }
2120
+ function na(e) {
2121
+ return e?.resourceType === "texture-storage-view" && !!e[c];
2122
+ }
2123
+ function aa(e) {
2124
+ return e?.resourceType === "texture-sampled-view" && !!e[c];
2125
+ }
2126
+ var sa = { mutable: "read_write", readonly: "read", writeonly: "write" }, vu = class {
2127
+ constructor(t, r) {
2128
+ this.props = t, this._branch = r, this[c] = { unwrap: () => {
2129
+ if (this._destroyed) throw new Error("This texture has been destroyed");
2130
+ return this._texture || (this._texture = this._branch.device.createTexture({ label: g(this) ?? "<unnamed>", format: this.props.format, size: this.props.size, usage: this._flags, dimension: this.props.dimension ?? "2d", viewFormats: this.props.viewFormats ?? [], mipLevelCount: this.props.mipLevelCount ?? 1, sampleCount: this.props.sampleCount ?? 1 })), this._texture;
2131
+ } };
2132
+ }
2133
+ [c];
2134
+ resourceType = "texture";
2135
+ usableAsSampled = !1;
2136
+ usableAsStorage = !1;
2137
+ usableAsRender = !1;
2138
+ _destroyed = !1;
2139
+ _flags = GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC;
2140
+ _texture = null;
2141
+ $name(t) {
2142
+ return F(this, t), this;
2143
+ }
2144
+ $usage(...t) {
2145
+ let r = t.includes("storage"), n = t.includes("sampled"), a = t.includes("render");
2146
+ return this._flags |= n ? GPUTextureUsage.TEXTURE_BINDING : 0, this._flags |= r ? GPUTextureUsage.STORAGE_BINDING : 0, this._flags |= a ? GPUTextureUsage.RENDER_ATTACHMENT : 0, this.usableAsStorage ||= r, this.usableAsSampled ||= n, this.usableAsRender ||= a, this;
2147
+ }
2148
+ createView(t, r) {
2149
+ if (t === "sampled") return this._asSampled(r);
2150
+ let n = r;
2151
+ switch (t) {
2152
+ case "mutable":
2153
+ return this._asMutable(n);
2154
+ case "readonly":
2155
+ return this._asReadonly(n);
2156
+ case "writeonly":
2157
+ return this._asWriteonly(n);
2158
+ }
2159
+ }
2160
+ _asStorage(t, r) {
2161
+ if (!this.usableAsStorage) throw new Error("Unusable as storage");
2162
+ let n = t?.format ?? this.props.format, a = At[n];
2163
+ return Pt(!!a, `Unsupported storage texture format: ${n}`), new _u(t ?? {}, r, this);
2164
+ }
2165
+ _asReadonly(t) {
2166
+ return this._asStorage(t, "readonly");
2167
+ }
2168
+ _asWriteonly(t) {
2169
+ return this._asStorage(t, "writeonly");
2170
+ }
2171
+ _asMutable(t) {
2172
+ return this._asStorage(t, "mutable");
2173
+ }
2174
+ _asSampled(t) {
2175
+ if (!this.usableAsSampled) throw new Error("Unusable as sampled");
2176
+ let r = t?.format ?? this.props.format;
2177
+ if (!At[r]) throw new Error(`Unsupported storage texture format: ${r}`);
2178
+ return new Tu(t, this);
2179
+ }
2180
+ destroy() {
2181
+ this._destroyed || (this._destroyed = !0, this._texture?.destroy());
2182
+ }
2183
+ }, qt = { "1d": "1d", "2d": "2d", "2d-array": "2d_array", cube: "cube", "cube-array": "cube_array", "3d": "3d" }, _u = class {
2184
+ constructor(t, r, n) {
2185
+ this.access = r, this._texture = n, this[C] = this, this[c] = { unwrap: () => (this._view || (this._view = this._texture[c].unwrap().createView({ label: `${g(this) ?? "<unnamed>"} - View`, format: this._format, dimension: this.dimension })), this._view) }, this[Y] = n, this.dimension = t?.dimension ?? n.props.dimension ?? "2d", this._format = t?.format ?? n.props.format, this.texelDataType = At[this._format];
2186
+ }
2187
+ [C];
2188
+ [c];
2189
+ [Y];
2190
+ resourceType = "texture-storage-view";
2191
+ texelDataType;
2192
+ dimension;
2193
+ _view;
2194
+ _format;
2195
+ $name(t) {
2196
+ return this._texture.$name(t), this;
2197
+ }
2198
+ "~resolve"(t) {
2199
+ let r = t.names.makeUnique(g(this)), { group: n, binding: a } = t.allocateFixedEntry({ storageTexture: this._format, access: this.access, viewDimension: this.dimension }, this), s = `texture_storage_${qt[this.dimension]}`;
2200
+ return t.addDeclaration(`@group(${n}) @binding(${a}) var ${r}: ${s}<${this._format}, ${sa[this.access]}>;`), r;
2201
+ }
2202
+ toString() {
2203
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2204
+ }
2205
+ }, xu = class {
2206
+ constructor(t, r, n, a) {
2207
+ this._format = t, this.dimension = r, this.access = n, this._membership = a, this[C] = this, this[c] = {}, this.texelDataType = At[this._format], F(this, a.key);
2208
+ }
2209
+ [C];
2210
+ [c];
2211
+ resourceType = "texture-storage-view";
2212
+ texelDataType;
2213
+ "~resolve"(t) {
2214
+ let r = t.names.makeUnique(g(this)), n = t.allocateLayoutEntry(this._membership.layout), a = `texture_storage_${qt[this.dimension]}`;
2215
+ return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${this._format}, ${sa[this.access]}>;`), r;
2216
+ }
2217
+ toString() {
2218
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2219
+ }
2220
+ }, Tu = class {
2221
+ constructor(t, r) {
2222
+ this._props = t, this._texture = r, this[C] = this, this[c] = { unwrap: () => (this._view || (this._view = this._texture[c].unwrap().createView({ label: `${g(this) ?? "<unnamed>"} - View`, ...this._props })), this._view) }, this[Y] = r, this.dimension = t?.dimension ?? r.props.dimension ?? "2d", this._format = t?.format ?? r.props.format, this.channelDataType = yu[this._format];
2223
+ }
2224
+ [C];
2225
+ [c];
2226
+ [Y];
2227
+ resourceType = "texture-sampled-view";
2228
+ channelDataType;
2229
+ dimension;
2230
+ _format;
2231
+ _view;
2232
+ $name(t) {
2233
+ return this._texture.$name(t), this;
2234
+ }
2235
+ "~resolve"(t) {
2236
+ let r = t.names.makeUnique(g(this)), n = (this._texture.props.sampleCount ?? 1) > 1, { group: a, binding: s } = t.allocateFixedEntry({ texture: wu[this.channelDataType.type], viewDimension: this.dimension, multisampled: n }, this), i = n ? "texture_multisampled_2d" : `texture_${qt[this.dimension]}`;
2237
+ return t.addDeclaration(`@group(${a}) @binding(${s}) var ${r}: ${i}<${t.resolve(this.channelDataType)}>;`), r;
2238
+ }
2239
+ toString() {
2240
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2241
+ }
2242
+ }, $u = class {
2243
+ constructor(t, r, n, a) {
2244
+ this.dimension = r, this._multisampled = n, this._membership = a, this[C] = this, this[c] = {}, F(this, a.key), this.channelDataType = gu[t];
2245
+ }
2246
+ [C];
2247
+ [c];
2248
+ resourceType = "texture-sampled-view";
2249
+ channelDataType;
2250
+ "~resolve"(t) {
2251
+ let r = t.names.makeUnique(g(this)), n = t.allocateLayoutEntry(this._membership.layout), a = this._multisampled ? "texture_multisampled_2d" : `texture_${qt[this.dimension]}`;
2252
+ return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var ${r}: ${a}<${t.resolve(this.channelDataType)}>;`), r;
2253
+ }
2254
+ toString() {
2255
+ return `${this.resourceType}:${g(this) ?? "<unnamed>"}`;
2256
+ }
2257
+ };
2258
+ function Eu(e) {
2259
+ return !!e?.usableAsSampled;
2260
+ }
2261
+ var Uu = class ia extends Error {
2262
+ constructor(t) {
2263
+ super(`Resource '${g(t) ?? "<unnamed>"}' cannot be bound as 'sampled'. Use .$usage('sampled') to allow it.`), Object.setPrototypeOf(this, ia.prototype);
2264
+ }
2265
+ };
2266
+ function oa(e) {
2267
+ return new Su(e);
2268
+ }
2269
+ function ua(e) {
2270
+ return !!e && e.resourceType === "bind-group-layout";
2271
+ }
2272
+ function tn(e) {
2273
+ return !!e && e.resourceType === "bind-group";
2274
+ }
2275
+ var Pu = class la extends Error {
2276
+ constructor(t, r) {
2277
+ super(`Bind group '${t ?? "<unnamed>"}' is missing a required binding '${r}'`), Object.setPrototypeOf(this, la.prototype);
2278
+ }
2279
+ }, rn = ["compute"], Ne = ["compute", "vertex", "fragment"], Su = class {
2280
+ constructor(e) {
2281
+ this.entries = e;
2282
+ let t = 0;
2283
+ for (let [r, n] of Object.entries(e)) {
2284
+ if (n === null) {
2285
+ t++;
2286
+ continue;
2287
+ }
2288
+ let a = { layout: this, key: r, idx: t };
2289
+ if ("uniform" in n && (this.bound[r] = new Xr("uniform", n.uniform, a)), "storage" in n) {
2290
+ let s = "type" in n.storage ? n.storage : n.storage(0);
2291
+ this.bound[r] = new Xr(n.access ?? "readonly", s, a);
2292
+ }
2293
+ "texture" in n && (this.bound[r] = new $u(n.texture, n.viewDimension ?? "2d", n.multisampled ?? !1, a)), "storageTexture" in n && (this.bound[r] = new xu(n.storageTexture, n.viewDimension ?? "2d", n.access ?? "writeonly", a)), "externalTexture" in n && (this.bound[r] = new mu(a)), "sampler" in n && (n.sampler === "comparison" ? this.bound[r] = new pu(a) : this.bound[r] = new cu(a)), "texture" in n || "storageTexture" in n || "externalTexture" in n || "sampler" in n ? this.value[r] = this.bound[r] : Object.defineProperty(this.value, r, { get: () => this.bound[r].value }), t++;
2294
+ }
2295
+ }
2296
+ [c] = !0;
2297
+ _index;
2298
+ resourceType = "bind-group-layout";
2299
+ bound = {};
2300
+ value = {};
2301
+ $ = this.value;
2302
+ [j]() {
2303
+ return this.$;
2304
+ }
2305
+ toString() {
2306
+ return `bindGroupLayout:${g(this) ?? "<unnamed>"}`;
2307
+ }
2308
+ get index() {
2309
+ return this._index;
2310
+ }
2311
+ $name(e) {
2312
+ return F(this, e), this;
2313
+ }
2314
+ $idx(e) {
2315
+ return this._index = e, this;
2316
+ }
2317
+ unwrap(e) {
2318
+ return e.device.createBindGroupLayout({ label: g(this) ?? "<unnamed>", entries: Object.values(this.entries).map((t, r) => {
2319
+ if (t === null) return null;
2320
+ let n = t.visibility, a = { binding: r, visibility: 0 };
2321
+ if ("uniform" in t) n = n ?? Ne, a.buffer = { type: "uniform" };
2322
+ else if ("storage" in t) n = n ?? (t.access === "mutable" ? rn : Ne), a.buffer = { type: t.access === "mutable" ? "storage" : "read-only-storage" };
2323
+ else if ("sampler" in t) n = n ?? Ne, a.sampler = { type: t.sampler };
2324
+ else if ("texture" in t) n = n ?? Ne, a.texture = { sampleType: t.texture, viewDimension: t.viewDimension ?? "2d", multisampled: t.multisampled ?? !1 };
2325
+ else if ("storageTexture" in t) {
2326
+ let s = t.access ?? "writeonly";
2327
+ n = n ?? (s === "readonly" ? Ne : rn), a.storageTexture = { format: t.storageTexture, access: { mutable: "read-write", readonly: "read-only", writeonly: "write-only" }[s], viewDimension: t.viewDimension ?? "2d" };
2328
+ } else "externalTexture" in t && (n = n ?? Ne, a.externalTexture = {});
2329
+ return n?.includes("compute") && (a.visibility |= GPUShaderStage.COMPUTE), n?.includes("vertex") && (a.visibility |= GPUShaderStage.VERTEX), n?.includes("fragment") && (a.visibility |= GPUShaderStage.FRAGMENT), a;
2330
+ }).filter((t) => t !== null) });
2331
+ }
2332
+ }, da = class {
2333
+ constructor(t, r) {
2334
+ this.layout = t, this.entries = r;
2335
+ for (let n of Object.keys(t.entries)) if (t.entries[n] !== null && !(n in r)) throw new Pu(g(t), n);
2336
+ }
2337
+ resourceType = "bind-group";
2338
+ unwrap(t) {
2339
+ return t.device.createBindGroup({ label: g(this.layout) ?? "<unnamed>", layout: t.unwrap(this.layout), entries: Object.entries(this.layout.entries).map(([r, n], a) => {
2340
+ if (n === null) return null;
2341
+ let s = this.entries[r];
2342
+ if (s === void 0) throw new Error(`'${r}' is a resource required to populate bind group layout '${g(this.layout) ?? "<unnamed>"}'.`);
2343
+ if ("uniform" in n) {
2344
+ let i;
2345
+ if (Qe(s)) {
2346
+ if (!Hn(s)) throw new Xs(s);
2347
+ i = { buffer: t.unwrap(s) };
2348
+ } else i = { buffer: s };
2349
+ return { binding: a, resource: i };
2350
+ }
2351
+ if ("storage" in n) {
2352
+ let i;
2353
+ if (Qe(s)) {
2354
+ if (!Mt(s)) throw new Zr(s);
2355
+ i = { buffer: t.unwrap(s) };
2356
+ } else i = { buffer: s };
2357
+ return { binding: a, resource: i };
2358
+ }
2359
+ if ("texture" in n) {
2360
+ let i;
2361
+ if (at(s)) {
2362
+ if (!Eu(s)) throw new Uu(s);
2363
+ i = t.unwrap(s.createView("sampled"));
2364
+ } else aa(s) ? i = t.unwrap(s) : i = s;
2365
+ return { binding: a, resource: i };
2366
+ }
2367
+ if ("storageTexture" in n) {
2368
+ let i;
2369
+ if (at(s)) {
2370
+ if (!Mt(s)) throw new Zr(s);
2371
+ n.access === "readonly" ? i = t.unwrap(s.createView("readonly")) : n.access === "mutable" ? i = t.unwrap(s.createView("mutable")) : i = t.unwrap(s.createView("writeonly"));
2372
+ } else na(s) ? i = t.unwrap(s) : i = s;
2373
+ return { binding: a, resource: i };
2374
+ }
2375
+ if ("sampler" in n) return ta(s) || ra(s) ? { binding: a, resource: t.unwrap(s) } : { binding: a, resource: s };
2376
+ if ("externalTexture" in n) return { binding: a, resource: s };
2377
+ throw new Error(`Malformed bind group entry: ${s} (${JSON.stringify(s)})`);
2378
+ }).filter((r) => r !== null) });
2379
+ }
2380
+ }, ca = "#CATCHALL#", Iu = class {
2381
+ _stack = [];
2382
+ _itemDepth = 0;
2383
+ get itemDepth() {
2384
+ return this._itemDepth;
2385
+ }
2386
+ get topItem() {
2387
+ let e = this._stack[this._stack.length - 1];
2388
+ if (!e || e.type !== "item") throw new Error("Internal error, expected item layer to be on top.");
2389
+ return e;
2390
+ }
2391
+ get topFunctionReturnType() {
2392
+ let e = this._stack.findLast((t) => t.type === "functionScope");
2393
+ if (!e) throw new Error("Internal error, expected function scope to be present.");
2394
+ return e.returnType;
2395
+ }
2396
+ pushItem() {
2397
+ this._itemDepth++, this._stack.push({ type: "item", usedSlots: /* @__PURE__ */ new Set() });
2398
+ }
2399
+ popItem() {
2400
+ this.pop("item");
2401
+ }
2402
+ pushSlotBindings(e) {
2403
+ this._stack.push({ type: "slotBinding", bindingMap: new WeakMap(e) });
2404
+ }
2405
+ popSlotBindings() {
2406
+ this.pop("slotBinding");
2407
+ }
2408
+ pushFunctionScope(e, t, r, n) {
2409
+ this._stack.push({ type: "functionScope", args: e, argAliases: t, returnType: r, externalMap: n });
2410
+ }
2411
+ popFunctionScope() {
2412
+ this.pop("functionScope");
2413
+ }
2414
+ pushBlockScope() {
2415
+ this._stack.push({ type: "blockScope", declarations: /* @__PURE__ */ new Map() });
2416
+ }
2417
+ popBlockScope() {
2418
+ this.pop("blockScope");
2419
+ }
2420
+ pop(e) {
2421
+ let t = this._stack[this._stack.length - 1];
2422
+ if (!t || e && t.type !== e) throw new Error(`Internal error, expected a ${e} layer to be on top.`);
2423
+ this._stack.pop(), e === "item" && this._itemDepth--;
2424
+ }
2425
+ readSlot(e) {
2426
+ for (let t = this._stack.length - 1; t >= 0; --t) {
2427
+ let r = this._stack[t];
2428
+ if (r?.type === "item") r.usedSlots.add(e);
2429
+ else if (r?.type === "slotBinding") {
2430
+ let n = r.bindingMap.get(e);
2431
+ if (n !== void 0) return n;
2432
+ } else if (!(r?.type === "functionScope" || r?.type === "blockScope")) throw new Error("Unknown layer type.");
2433
+ }
2434
+ return e.defaultValue;
2435
+ }
2436
+ getSnippetById(e) {
2437
+ for (let t = this._stack.length - 1; t >= 0; --t) {
2438
+ let r = this._stack[t];
2439
+ if (r?.type === "functionScope") {
2440
+ let n = r.args.find((s) => s.value === e);
2441
+ if (n !== void 0) return n;
2442
+ if (r.argAliases[e]) return r.argAliases[e];
2443
+ let a = r.externalMap[e];
2444
+ return a != null ? qs(a) : void 0;
2445
+ }
2446
+ if (r?.type === "blockScope") {
2447
+ let n = r.declarations.get(e);
2448
+ if (n !== void 0) return u(e, n);
2449
+ }
2450
+ }
2451
+ }
2452
+ defineBlockVariable(e, t) {
2453
+ if (t.type === "unknown") throw Error(`Tried to define variable '${e}' of unknown type`);
2454
+ for (let r = this._stack.length - 1; r >= 0; --r) {
2455
+ let n = this._stack[r];
2456
+ if (n?.type === "blockScope") return n.declarations.set(e, t), u(e, t);
2457
+ }
2458
+ throw new Error("No block scope found to define a variable in.");
2459
+ }
2460
+ }, vt = ["", " ", " ", " ", " ", " ", " ", " ", " "], Zt = vt.length - 1, ku = class {
2461
+ identLevel = 0;
2462
+ get pre() {
2463
+ return vt[this.identLevel] ?? vt[Zt].repeat(this.identLevel / Zt) + vt[this.identLevel % Zt];
2464
+ }
2465
+ indent() {
2466
+ let e = this.pre;
2467
+ return this.identLevel++, e;
2468
+ }
2469
+ dedent() {
2470
+ return this.identLevel--, this.pre;
2471
+ }
2472
+ withResetLevel(e) {
2473
+ let t = this.identLevel;
2474
+ this.identLevel = 0;
2475
+ try {
2476
+ return e();
2477
+ } finally {
2478
+ this.identLevel = t;
2479
+ }
2480
+ }
2481
+ }, pa = class {
2482
+ _memoizedResolves = /* @__PURE__ */ new WeakMap();
2483
+ _memoizedDerived = /* @__PURE__ */ new WeakMap();
2484
+ _indentController = new ku();
2485
+ _itemStateStack = new Iu();
2486
+ #e = [];
2487
+ _declarations = [];
2488
+ _varyingLocations;
2489
+ get varyingLocations() {
2490
+ return this._varyingLocations;
2491
+ }
2492
+ [c] = { itemStateStack: this._itemStateStack };
2493
+ bindGroupLayoutsToPlaceholderMap = /* @__PURE__ */ new Map();
2494
+ _nextFreeLayoutPlaceholderIdx = 0;
2495
+ fixedBindings = [];
2496
+ names;
2497
+ expectedType;
2498
+ constructor(t) {
2499
+ this.names = t.names;
2500
+ }
2501
+ get pre() {
2502
+ return this._indentController.pre;
2503
+ }
2504
+ get topFunctionReturnType() {
2505
+ return this._itemStateStack.topFunctionReturnType;
2506
+ }
2507
+ indent() {
2508
+ return this._indentController.indent();
2509
+ }
2510
+ dedent() {
2511
+ return this._indentController.dedent();
2512
+ }
2513
+ withResetIndentLevel(t) {
2514
+ return this._indentController.withResetLevel(t);
2515
+ }
2516
+ getById(t) {
2517
+ let r = this._itemStateStack.getSnippetById(t);
2518
+ return r === void 0 ? null : r;
2519
+ }
2520
+ defineVariable(t, r) {
2521
+ return this._itemStateStack.defineBlockVariable(t, r);
2522
+ }
2523
+ pushBlockScope() {
2524
+ this._itemStateStack.pushBlockScope();
2525
+ }
2526
+ popBlockScope() {
2527
+ this._itemStateStack.popBlockScope();
2528
+ }
2529
+ fnToWgsl(t) {
2530
+ this._itemStateStack.pushFunctionScope(t.args, t.argAliases, t.returnType, t.externalMap);
2531
+ try {
2532
+ return { head: Mu(this, t.args, t.returnType), body: Ba(this, t.body) };
2533
+ } finally {
2534
+ this._itemStateStack.popFunctionScope();
2535
+ }
2536
+ }
2537
+ addDeclaration(t) {
2538
+ this._declarations.push(t);
2539
+ }
2540
+ allocateLayoutEntry(t) {
2541
+ let r = this.bindGroupLayoutsToPlaceholderMap, n = r.get(t);
2542
+ return n || (n = `#BIND_GROUP_LAYOUT_${this._nextFreeLayoutPlaceholderIdx++}#`, r.set(t, n)), n;
2543
+ }
2544
+ allocateFixedEntry(t, r) {
2545
+ let n = this.fixedBindings.length;
2546
+ return this.fixedBindings.push({ layoutEntry: t, resource: r }), { group: ca, binding: n };
2547
+ }
2548
+ readSlot(t) {
2549
+ let r = this._itemStateStack.readSlot(t);
2550
+ if (r === void 0) throw new Cs(t);
2551
+ return r;
2552
+ }
2553
+ withSlots(t, r) {
2554
+ this._itemStateStack.pushSlotBindings(t);
2555
+ try {
2556
+ return r();
2557
+ } finally {
2558
+ this._itemStateStack.popSlotBindings();
2559
+ }
2560
+ }
2561
+ withVaryingLocations(t, r) {
2562
+ this._varyingLocations = t;
2563
+ try {
2564
+ return r();
2565
+ } finally {
2566
+ this._varyingLocations = void 0;
2567
+ }
2568
+ }
2569
+ unwrap(t) {
2570
+ if (Ar(t)) return this.withSlots(t[Me].pairs, () => this.unwrap(t[Me].inner));
2571
+ let r = t;
2572
+ for (; ; ) if (Or(r)) r = this.readSlot(r);
2573
+ else if (Gr(r)) r = this._getOrCompute(r);
2574
+ else break;
2575
+ return r;
2576
+ }
2577
+ _getOrCompute(t) {
2578
+ let r = this._memoizedDerived.get(t) ?? [];
2579
+ this._itemStateStack.pushItem();
2580
+ try {
2581
+ for (let s of r) if ([...s.slotToValueMap.entries()].every(([i, l]) => i.areEqual(this._itemStateStack.readSlot(i), l))) return s.result;
2582
+ this.pushMode(new Ns());
2583
+ let n;
2584
+ try {
2585
+ n = t["~compute"]();
2586
+ } finally {
2587
+ this.popMode("normal");
2588
+ }
2589
+ let a = /* @__PURE__ */ new Map();
2590
+ for (let s of this._itemStateStack.topItem.usedSlots) a.set(s, this._itemStateStack.readSlot(s));
2591
+ return r.push({ slotToValueMap: a, result: n }), this._memoizedDerived.set(t, r), n;
2592
+ } catch (n) {
2593
+ throw n instanceof ht ? n.appendToTrace(t) : new ht(n, [t]);
2594
+ } finally {
2595
+ this._itemStateStack.popItem();
2596
+ }
2597
+ }
2598
+ _getOrInstantiate(t) {
2599
+ let r = this._memoizedResolves.get(t) ?? [];
2600
+ this._itemStateStack.pushItem();
2601
+ try {
2602
+ for (let s of r) if ([...s.slotToValueMap.entries()].every(([i, l]) => i.areEqual(this._itemStateStack.readSlot(i), l))) return s.result;
2603
+ let n;
2604
+ if (Re(t)) n = Zn(this, t);
2605
+ else if (Gr(t) || Or(t)) n = this.resolve(this.unwrap(t));
2606
+ else if (Ls(t)) n = t["~resolve"](this);
2607
+ else throw new TypeError(`Unresolvable internal value: ${t} (as json: ${JSON.stringify(t)})`);
2608
+ let a = /* @__PURE__ */ new Map();
2609
+ for (let s of this._itemStateStack.topItem.usedSlots) a.set(s, this._itemStateStack.readSlot(s));
2610
+ return r.push({ slotToValueMap: a, result: n }), this._memoizedResolves.set(t, r), n;
2611
+ } catch (n) {
2612
+ throw n instanceof ht ? n.appendToTrace(t) : new ht(n, [t]);
2613
+ } finally {
2614
+ this._itemStateStack.popItem();
2615
+ }
2616
+ }
2617
+ resolve(t, r) {
2618
+ if (Ar(t)) return this.withSlots(t[Me].pairs, () => this.resolve(t[Me].inner, r));
2619
+ if (Ds(t)) {
2620
+ if (this._itemStateStack.itemDepth === 0) try {
2621
+ this.pushMode(new Ws());
2622
+ let n = Sn(this, () => this._getOrInstantiate(t));
2623
+ return `${[...this._declarations].join(`
2624
+
2625
+ `)}${n}`;
2626
+ } finally {
2627
+ this.popMode("codegen");
2628
+ }
2629
+ return this._getOrInstantiate(t);
2630
+ }
2631
+ if (typeof t == "number") {
2632
+ if (r?.type === "abstractInt" || r?.type === "u32" || r?.type === "i32") return String(t);
2633
+ let n = t.toExponential(), a = String(t);
2634
+ return n.length < a.length ? n : a;
2635
+ }
2636
+ if (typeof t != "object" && typeof t != "function") return String(t);
2637
+ if (r && lt(r)) {
2638
+ if (!Array.isArray(t)) throw new Vt(`Cannot coerce ${t} into value of type '${r}'`);
2639
+ if (r.elementCount !== t.length) throw new Vt(`Cannot create value of type '${r}' from an array of length: ${t.length}`);
2640
+ return `array<${this.resolve(r.elementType)}, ${r.elementCount}>(${t.map((n) => this.resolve(n, r.elementType))})`;
2641
+ }
2642
+ if (Array.isArray(t)) return `array(${t.map((n) => this.resolve(n))})`;
2643
+ if (r && be(r)) return `${this.resolve(r)}(${Object.entries(r.propTypes).map(([n, a]) => this.resolve(t[n], a))})`;
2644
+ throw new Vt(`Value ${t} (as json: ${JSON.stringify(t)}) is not resolvable${r ? ` to type ${r}` : ""}`);
2645
+ }
2646
+ pushMode(t) {
2647
+ this.#e.push(t);
2648
+ }
2649
+ popMode(t) {
2650
+ let r = this.#e.pop();
2651
+ t !== void 0 && Pt(r?.type === t, "Unexpected mode");
2652
+ }
2653
+ get mode() {
2654
+ return this.#e[this.#e.length - 1] ?? zs;
2655
+ }
2656
+ };
2657
+ function st(e, t, r) {
2658
+ let n = new pa(t), a = r ? n.withSlots(r(new Xn([])).bindings, () => n.resolve(e)) : n.resolve(e), s = n.bindGroupLayoutsToPlaceholderMap, i = [], l = new Set([...s.keys()].map((b) => b.index).filter((b) => b !== void 0)), o = Qo(l), y = n.fixedBindings.map((b, v) => [String(v), b.layoutEntry]), h = () => {
2659
+ let b = o.next().value, v = oa(Object.fromEntries(y));
2660
+ return i[b] = v, a = a.replaceAll(ca, String(b)), [b, new da(v, Object.fromEntries(n.fixedBindings.map((x, P) => [String(P), x.resource])))];
2661
+ }, w = y.length > 0 ? h() : void 0;
2662
+ for (let [b, v] of s.entries()) {
2663
+ let x = b.index ?? o.next().value;
2664
+ i[x] = b, a = a.replaceAll(v, String(x));
2665
+ }
2666
+ return { code: a, usedBindGroupLayouts: i, catchall: w };
2667
+ }
2668
+ function Mu(e, t, r) {
2669
+ let n = t.map((a) => `${a.value}: ${e.resolve(a.dataType)}`).join(", ");
2670
+ return r.type !== "void" ? `(${n}) -> ${lr(r)}${e.resolve(r)} ` : `(${n}) `;
2671
+ }
2672
+ function ha(e) {
2673
+ let { externals: t, template: r, names: n, config: a } = e, s = {};
2674
+ Xe(s, t ?? {});
2675
+ let i = { [c]: !0, "~resolve"(l) {
2676
+ return Dt(l, s, r ?? "");
2677
+ }, toString: () => "<root>" };
2678
+ return st(i, { names: n === "strict" ? new Yt() : new $r() }, a);
2679
+ }
2680
+ function Au(e) {
2681
+ return ha(e).code;
2682
+ }
2683
+ function Ou(e) {
2684
+ let t = tt() ?? new pa({ names: new Yt() }), r = [1, 1, 1], n = [1, 1, 1], a = [r[0] * n[0], r[1] * n[1], r[2] * n[2]], s = /* @__PURE__ */ new Map(), i = Array.from({ length: r[0] }, () => Array.from({ length: r[1] }, () => Array.from({ length: r[2] }, () => /* @__PURE__ */ new Map()))), l = Array.from({ length: a[0] }, () => Array.from({ length: a[1] }, () => Array.from({ length: a[2] }, () => /* @__PURE__ */ new Map()))), o = Array.from({ length: a[0] }, (y, h) => Array.from({ length: a[1] }, (w, b) => Array.from({ length: a[2] }, (v, x) => {
2685
+ let P = Math.floor(h / n[0]), $ = Math.floor(b / n[1]), k = Math.floor(x / n[2]);
2686
+ return new Fs(s, { private: l[h][b][x], workgroup: i[P][$][k] });
2687
+ })));
2688
+ t.pushMode(o[0][0][0]);
2689
+ try {
2690
+ return { value: Sn(t, e), buffers: s, privateVars: l, workgroupVars: i };
2691
+ } finally {
2692
+ t.popMode("simulate");
2693
+ }
2694
+ }
2695
+ function Gu(e, t, r, n) {
2696
+ return new Bu(e, t, r, n);
2697
+ }
2698
+ function Ur(e) {
2699
+ let t = e;
2700
+ return t?.resourceType === "query-set" && !!t[c];
2701
+ }
2702
+ var Bu = class {
2703
+ constructor(e, t, r, n) {
2704
+ this._group = e, this.type = t, this.count = r, this.rawQuerySet = n, this._ownQuerySet = !n, this._querySet = n || null;
2705
+ }
2706
+ resourceType = "query-set";
2707
+ _querySet = null;
2708
+ _ownQuerySet;
2709
+ _destroyed = !1;
2710
+ _available = !0;
2711
+ _readBuffer = null;
2712
+ _resolveBuffer = null;
2713
+ get querySet() {
2714
+ if (this._destroyed) throw new Error("This QuerySet has been destroyed.");
2715
+ return this.rawQuerySet ? this.rawQuerySet : this._querySet ? this._querySet : (this._querySet = this._group.device.createQuerySet({ type: this.type, count: this.count }), this._querySet);
2716
+ }
2717
+ get destroyed() {
2718
+ return this._destroyed;
2719
+ }
2720
+ get available() {
2721
+ return this._available;
2722
+ }
2723
+ get [c]() {
2724
+ let e = this;
2725
+ return { get readBuffer() {
2726
+ return e._readBuffer || (e._readBuffer = e._group.device.createBuffer({ size: e.count * BigUint64Array.BYTES_PER_ELEMENT, usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ })), e._readBuffer;
2727
+ }, get resolveBuffer() {
2728
+ return e._resolveBuffer || (e._resolveBuffer = e._group.device.createBuffer({ size: e.count * BigUint64Array.BYTES_PER_ELEMENT, usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC })), e._resolveBuffer;
2729
+ } };
2730
+ }
2731
+ $name(e) {
2732
+ return F(this, e), this._querySet && (this._querySet.label = e), this;
2733
+ }
2734
+ resolve() {
2735
+ if (this._destroyed) throw new Error("This QuerySet has been destroyed.");
2736
+ if (!this._available) throw new Error("This QuerySet is busy resolving or reading.");
2737
+ let e = this._group.device.createCommandEncoder();
2738
+ e.resolveQuerySet(this.querySet, 0, this.count, this[c].resolveBuffer, 0), this._group.device.queue.submit([e.finish()]);
2739
+ }
2740
+ async read() {
2741
+ if (this._group.flush(), !this._resolveBuffer) throw new Error("QuerySet must be resolved before reading.");
2742
+ this._available = !1;
2743
+ try {
2744
+ let e = this._group.device.createCommandEncoder();
2745
+ e.copyBufferToBuffer(this[c].resolveBuffer, 0, this[c].readBuffer, 0, this.count * BigUint64Array.BYTES_PER_ELEMENT), this._group.device.queue.submit([e.finish()]), await this._group.device.queue.onSubmittedWorkDone();
2746
+ let t = this[c].readBuffer;
2747
+ await t.mapAsync(GPUMapMode.READ);
2748
+ let r = new BigUint64Array(t.getMappedRange().slice());
2749
+ return t.unmap(), Array.from(r);
2750
+ } finally {
2751
+ this._available = !0;
2752
+ }
2753
+ }
2754
+ destroy() {
2755
+ this._destroyed || (this._destroyed = !0, this._querySet && this._ownQuerySet && this._querySet.destroy(), this._readBuffer?.destroy(), this._resolveBuffer?.destroy(), this._readBuffer = this._resolveBuffer = null);
2756
+ }
2757
+ }, nn = class {
2758
+ constructor(t) {
2759
+ this._make = t;
2760
+ }
2761
+ _map = /* @__PURE__ */ new WeakMap();
2762
+ getOrMake(t, ...r) {
2763
+ if (this._map.has(t)) return this._map.get(t);
2764
+ let n = this._make(t, ...r);
2765
+ return this._map.set(t, n), n;
2766
+ }
2767
+ };
2768
+ function fa(e, t, r) {
2769
+ if (!r.enabledFeatures.has("timestamp-query")) throw new Error('Performance callback requires the "timestamp-query" feature to be enabled on GPU device.');
2770
+ return e.timestampWrites ? { ...e, performanceCallback: t } : { ...e, performanceCallback: t, hasAutoQuerySet: !0, timestampWrites: { querySet: (globalThis.__TYPEGPU_AUTONAME__ ?? ((n) => n))(r.createQuerySet("timestamp", 2), "querySet"), beginningOfPassWriteIndex: 0, endOfPassWriteIndex: 1 } };
2771
+ }
2772
+ function ma(e, t, r) {
2773
+ if (!r.enabledFeatures.has("timestamp-query")) throw new Error('Timestamp writes require the "timestamp-query" feature to be enabled on GPU device.');
2774
+ e.hasAutoQuerySet && e.timestampWrites && e.timestampWrites.querySet.destroy();
2775
+ let n = { querySet: t.querySet };
2776
+ return t.beginningOfPassWriteIndex !== void 0 && (n.beginningOfPassWriteIndex = t.beginningOfPassWriteIndex), t.endOfPassWriteIndex !== void 0 && (n.endOfPassWriteIndex = t.endOfPassWriteIndex), { ...e, hasAutoQuerySet: !1, timestampWrites: n };
2777
+ }
2778
+ function ya(e, t) {
2779
+ if (!e.timestampWrites) return {};
2780
+ let { querySet: r, beginningOfPassWriteIndex: n, endOfPassWriteIndex: a } = e.timestampWrites, s = { querySet: Ur(r) ? t.unwrap(r) : r };
2781
+ return n !== void 0 && (s.beginningOfPassWriteIndex = n), a !== void 0 && (s.endOfPassWriteIndex = a), { timestampWrites: s };
2782
+ }
2783
+ function rr({ root: e, priors: t }) {
2784
+ let r = t.timestampWrites?.querySet, n = t.performanceCallback;
2785
+ if (!r) throw new Error("Cannot dispatch workgroups with performance callback without a query set.");
2786
+ if (!Ur(r)) throw new Error("Performance callback with raw GPUQuerySet is not supported. Use TgpuQuerySet instead.");
2787
+ e.commandEncoder.resolveQuerySet(e.unwrap(r), 0, r.count, r[c].resolveBuffer, 0), e.flush(), e.device.queue.onSubmittedWorkDone().then(async () => {
2788
+ if (!r.available) return;
2789
+ let a = await r.read(), s = a[t.timestampWrites?.beginningOfPassWriteIndex ?? 0], i = a[t.timestampWrites?.endOfPassWriteIndex ?? 1];
2790
+ if (s === void 0 || i === void 0) throw new Error("QuerySet did not return valid timestamps.");
2791
+ await n(s, i);
2792
+ });
2793
+ }
2794
+ function Fu(e, t, r) {
2795
+ return new Nu(new Lu(e, t, r), {});
2796
+ }
2797
+ function Cu(e) {
2798
+ let t = e;
2799
+ return t?.resourceType === "compute-pipeline" && !!t[c];
2800
+ }
2801
+ var Nu = class _t {
2802
+ constructor(t, r) {
2803
+ this._core = t, this._priors = r, this[c] = { get rawPipeline() {
2804
+ return t.unwrap().pipeline;
2805
+ }, get priors() {
2806
+ return r;
2807
+ } }, this[Y] = t;
2808
+ }
2809
+ [c];
2810
+ resourceType = "compute-pipeline";
2811
+ [Y];
2812
+ "~resolve"(t) {
2813
+ return t.resolve(this._core);
2814
+ }
2815
+ toString() {
2816
+ return `computePipeline:${g(this) ?? "<unnamed>"}`;
2817
+ }
2818
+ get rawPipeline() {
2819
+ return this._core.unwrap().pipeline;
2820
+ }
2821
+ with(t, r) {
2822
+ return new _t(this._core, { ...this._priors, bindGroupLayoutMap: new Map([...this._priors.bindGroupLayoutMap ?? [], [t, r]]) });
2823
+ }
2824
+ withPerformanceCallback(t) {
2825
+ let r = fa(this._priors, t, this._core.branch);
2826
+ return new _t(this._core, r);
2827
+ }
2828
+ withTimestampWrites(t) {
2829
+ let r = ma(this._priors, t, this._core.branch);
2830
+ return new _t(this._core, r);
2831
+ }
2832
+ dispatchWorkgroups(t, r, n) {
2833
+ let a = this._core.unwrap(), { branch: s } = this._core, i = { label: g(this._core) ?? "<unnamed>", ...ya(this._priors, s) }, l = s.commandEncoder.beginComputePass(i);
2834
+ l.setPipeline(a.pipeline);
2835
+ let o = new Set(a.usedBindGroupLayouts);
2836
+ if (a.usedBindGroupLayouts.forEach((y, h) => {
2837
+ if (a.catchall && h === a.catchall[0]) l.setBindGroup(h, s.unwrap(a.catchall[1])), o.delete(y);
2838
+ else {
2839
+ let w = this._priors.bindGroupLayoutMap?.get(y);
2840
+ w !== void 0 && (o.delete(y), l.setBindGroup(h, s.unwrap(w)));
2841
+ }
2842
+ }), o.size > 0) throw new fr(o);
2843
+ l.dispatchWorkgroups(t, r, n), l.end(), this._priors.performanceCallback && rr({ root: s, priors: this._priors });
2844
+ }
2845
+ $name(t) {
2846
+ return F(this._core, t), this;
2847
+ }
2848
+ }, Lu = class {
2849
+ constructor(e, t, r) {
2850
+ this.branch = e, this._slotBindings = t, this._entryFn = r;
2851
+ }
2852
+ [c] = !0;
2853
+ _memo;
2854
+ "~resolve"(e) {
2855
+ return e.withSlots(this._slotBindings, () => (e.resolve(this._entryFn), ""));
2856
+ }
2857
+ toString() {
2858
+ return "computePipelineCore";
2859
+ }
2860
+ unwrap() {
2861
+ if (this._memo === void 0) {
2862
+ let e = this.branch.device, t, r;
2863
+ if (De?.enabled) {
2864
+ let l = performance.mark("typegpu:resolution:start");
2865
+ t = st(this, { names: this.branch.nameRegistry }), r = performance.measure("typegpu:resolution", { start: l.name });
2866
+ } else t = st(this, { names: this.branch.nameRegistry });
2867
+ let { code: n, usedBindGroupLayouts: a, catchall: s } = t;
2868
+ s !== void 0 && a[s[0]]?.$name(`${g(this) ?? "<unnamed>"} - Automatic Bind Group & Layout`);
2869
+ let i = e.createShaderModule({ label: `${g(this) ?? "<unnamed>"} - Shader`, code: n });
2870
+ this._memo = { pipeline: e.createComputePipeline({ label: g(this) ?? "<unnamed>", layout: e.createPipelineLayout({ label: `${g(this) ?? "<unnamed>"} - Pipeline Layout`, bindGroupLayouts: a.map((l) => this.branch.unwrap(l)) }), compute: { module: i } }), usedBindGroupLayouts: a, catchall: s }, De?.enabled && (async () => {
2871
+ let l = performance.mark("typegpu:compile-start");
2872
+ await e.queue.onSubmittedWorkDone();
2873
+ let o = performance.measure("typegpu:compiled", { start: l.name });
2874
+ De?.record("resolution", { resolveDuration: r?.duration, compileDuration: o.duration, wgslSize: n.length });
2875
+ })();
2876
+ }
2877
+ return this._memo;
2878
+ }
2879
+ };
2880
+ function an(e, t = "vertex") {
2881
+ return new Du(e, t);
2882
+ }
2883
+ function wa(e) {
2884
+ return e?.resourceType === "vertex-layout";
2885
+ }
2886
+ var nr = Symbol("defaultAttribEntry");
2887
+ function xt(e, t, r, n, a) {
2888
+ if (dr(t) || wn(t)) {
2889
+ let s = Pe(t);
2890
+ return s !== void 0 && (n[a ?? nr] = s), xt(e, t.inner, $e(r, Oe(t)), n);
2891
+ }
2892
+ if (be(t)) {
2893
+ let s = r, i = t.propTypes;
2894
+ return Object.fromEntries(Object.entries(i).map(([l, o]) => {
2895
+ s = $e(s, re(o));
2896
+ let y = [l, xt(e, o, s, n, l)];
2897
+ return s += D(o), y;
2898
+ }));
2899
+ }
2900
+ if (ut(t)) {
2901
+ let s = r, i = t.propTypes;
2902
+ return Object.fromEntries(Object.entries(i).map(([l, o]) => {
2903
+ s = $e(s, Oe(o));
2904
+ let y = [l, xt(e, o, s, n, l)];
2905
+ return s += D(o), y;
2906
+ }));
2907
+ }
2908
+ if ("type" in t && typeof t.type == "string") {
2909
+ if (Js.includes(t.type)) return { _layout: e, format: t.type, offset: r };
2910
+ let s = Zs[t.type];
2911
+ if (s) return { _layout: e, format: s, offset: r };
2912
+ }
2913
+ throw new Error(`Unsupported data used in vertex layout: ${String(t)}`);
2914
+ }
2915
+ var Du = class {
2916
+ constructor(e, t) {
2917
+ this.schemaForCount = e, this.stepMode = t;
2918
+ let r = e(0);
2919
+ this.stride = $e(D(r.elementType), re(r)), this.attrib = xt(this, r.elementType, 0, this._customLocationMap);
2920
+ }
2921
+ [c] = !0;
2922
+ resourceType = "vertex-layout";
2923
+ stride;
2924
+ attrib;
2925
+ _customLocationMap = {};
2926
+ get vertexLayout() {
2927
+ if (this._customLocationMap[nr] !== void 0) {
2928
+ if (typeof this.attrib.format != "string" || typeof this.attrib.offset != "number") throw new Error("Single attribute vertex layouts must have a format and offset.");
2929
+ return { arrayStride: this.stride, stepMode: this.stepMode, attributes: [{ format: this.attrib.format, offset: this.attrib.offset, shaderLocation: this._customLocationMap[nr] }] };
2930
+ }
2931
+ if (!Object.keys(this.attrib).every((e) => this._customLocationMap[e] !== void 0)) throw new Error("All attributes must have custom locations in order to unwrap a vertex layout.");
2932
+ return { arrayStride: this.stride, stepMode: this.stepMode, attributes: [...Object.entries(this.attrib).map(([e, t]) => ({ format: t.format, offset: t.offset, shaderLocation: this._customLocationMap[e] }))] };
2933
+ }
2934
+ $name(e) {
2935
+ return F(this, e), this;
2936
+ }
2937
+ };
2938
+ function Wu(e) {
2939
+ return typeof e?.loadOp == "string";
2940
+ }
2941
+ function zu(e, t) {
2942
+ if (Re(e)) {
2943
+ if (!Wu(t)) throw new Error("Expected a single color attachment, not a record.");
2944
+ return [t];
2945
+ }
2946
+ let r = [];
2947
+ for (let n of Object.keys(e)) {
2948
+ let a = t[n];
2949
+ if (!a) throw new Error(`A color attachment by the name of '${n}' was not provided to the shader.`);
2950
+ r.push(a);
2951
+ }
2952
+ return r;
2953
+ }
2954
+ function Yu(e) {
2955
+ return typeof e?.format == "string";
2956
+ }
2957
+ function Ru(e, t) {
2958
+ if (Re(e)) {
2959
+ if (In(e)) return [];
2960
+ if (!Yu(t)) throw new Error("Expected a single color target configuration, not a record.");
2961
+ return [t];
2962
+ }
2963
+ let r = [];
2964
+ for (let n of Object.keys(e)) {
2965
+ let a = t[n];
2966
+ if (!a) throw new Error(`A color target by the name of '${n}' was not provided to the shader.`);
2967
+ r.push(a);
2968
+ }
2969
+ return r;
2970
+ }
2971
+ function qu(e) {
2972
+ return new Vu(new Ju(e), {});
2973
+ }
2974
+ function ju(e) {
2975
+ let t = e;
2976
+ return t?.resourceType === "render-pipeline" && !!t[c];
2977
+ }
2978
+ var Vu = class me {
2979
+ [c];
2980
+ resourceType = "render-pipeline";
2981
+ [Y];
2982
+ hasIndexBuffer = !1;
2983
+ constructor(t, r) {
2984
+ this[c] = { core: t, priors: r }, this[Y] = t;
2985
+ }
2986
+ "~resolve"(t) {
2987
+ return t.resolve(this[c].core);
2988
+ }
2989
+ toString() {
2990
+ return `renderPipeline:${g(this) ?? "<unnamed>"}`;
2991
+ }
2992
+ $name(t) {
2993
+ return F(this[c].core, t), this;
2994
+ }
2995
+ with(t, r) {
2996
+ let n = this[c];
2997
+ if (ua(t)) return new me(n.core, { ...n.priors, bindGroupLayoutMap: new Map([...n.priors.bindGroupLayoutMap ?? [], [t, r]]) });
2998
+ if (wa(t)) return new me(n.core, { ...n.priors, vertexLayoutMap: new Map([...n.priors.vertexLayoutMap ?? [], [t, r]]) });
2999
+ throw new Error("Unsupported value passed into .with()");
3000
+ }
3001
+ withPerformanceCallback(t) {
3002
+ let r = this[c], n = fa(r.priors, t, r.core.options.branch);
3003
+ return new me(r.core, n);
3004
+ }
3005
+ withTimestampWrites(t) {
3006
+ let r = this[c], n = ma(r.priors, t, r.core.options.branch);
3007
+ return new me(r.core, n);
3008
+ }
3009
+ withColorAttachment(t) {
3010
+ let r = this[c];
3011
+ return new me(r.core, { ...r.priors, colorAttachment: t });
3012
+ }
3013
+ withDepthStencilAttachment(t) {
3014
+ let r = this[c];
3015
+ return new me(r.core, { ...r.priors, depthStencilAttachment: t });
3016
+ }
3017
+ withIndexBuffer(t, r, n, a) {
3018
+ let s = this[c];
3019
+ if (Kt(t)) {
3020
+ if (typeof r != "string") throw new Error("If a GPUBuffer is passed, indexFormat must be provided.");
3021
+ return new me(s.core, { ...s.priors, indexBuffer: { buffer: t, indexFormat: r, offsetBytes: n, sizeBytes: a } });
3022
+ }
3023
+ let i = { u32: "uint32", u16: "uint16" }, l = t.dataType.elementType;
3024
+ return new me(s.core, { ...s.priors, indexBuffer: { buffer: t, indexFormat: i[l.type], offsetBytes: r !== void 0 ? r * Qt(l) : void 0, sizeBytes: a !== void 0 ? a * Qt(l) : void 0 } });
3025
+ }
3026
+ setupRenderPass() {
3027
+ let t = this[c], r = t.core.unwrap(), { branch: n, fragmentFn: a } = t.core.options, s = zu(a.shell.out, t.priors.colorAttachment ?? {}).map((h) => at(h.view) ? { ...h, view: n.unwrap(h.view).createView() } : h), i = { label: g(t.core) ?? "<unnamed>", colorAttachments: s, ...ya(t.priors, n) };
3028
+ if (t.priors.depthStencilAttachment !== void 0) {
3029
+ let h = t.priors.depthStencilAttachment;
3030
+ at(h.view) ? i.depthStencilAttachment = { ...h, view: n.unwrap(h.view).createView() } : i.depthStencilAttachment = h;
3031
+ }
3032
+ let l = n.commandEncoder.beginRenderPass(i);
3033
+ l.setPipeline(r.pipeline);
3034
+ let o = new Set(r.usedBindGroupLayouts);
3035
+ r.usedBindGroupLayouts.forEach((h, w) => {
3036
+ if (r.catchall && w === r.catchall[0]) l.setBindGroup(w, n.unwrap(r.catchall[1])), o.delete(h);
3037
+ else {
3038
+ let b = t.priors.bindGroupLayoutMap?.get(h);
3039
+ b !== void 0 && (o.delete(h), l.setBindGroup(w, n.unwrap(b)));
3040
+ }
3041
+ });
3042
+ let y = new Set(t.core.usedVertexLayouts);
3043
+ if (t.core.usedVertexLayouts.forEach((h, w) => {
3044
+ let b = t.priors.vertexLayoutMap?.get(h);
3045
+ b && (y.delete(h), l.setVertexBuffer(w, n.unwrap(b)));
3046
+ }), o.size > 0) throw new fr(o);
3047
+ if (y.size > 0) throw new Mn(y);
3048
+ return l;
3049
+ }
3050
+ draw(t, r, n, a) {
3051
+ let s = this[c], i = this.setupRenderPass(), { branch: l } = s.core.options;
3052
+ i.draw(t, r, n, a), i.end(), s.priors.performanceCallback ? rr({ root: l, priors: s.priors }) : l.flush();
3053
+ }
3054
+ drawIndexed(t, r, n, a, s) {
3055
+ let i = this[c];
3056
+ if (!i.priors.indexBuffer) throw new Error("No index buffer set for this render pipeline.");
3057
+ let { buffer: l, indexFormat: o, offsetBytes: y, sizeBytes: h } = i.priors.indexBuffer, w = this.setupRenderPass(), { branch: b } = i.core.options;
3058
+ Kt(l) ? w.setIndexBuffer(l, o, y, h) : w.setIndexBuffer(b.unwrap(l), o, y, h), w.drawIndexed(t, r, n, a, s), w.end(), i.priors.performanceCallback ? rr({ root: b, priors: i.priors }) : b.flush();
3059
+ }
3060
+ }, Ju = class {
3061
+ constructor(e) {
3062
+ this.options = e;
3063
+ let t = Ro(e.vertexFn.shell.in ?? {}, e.vertexAttribs);
3064
+ this._vertexBufferLayouts = t.bufferDefinitions, this.usedVertexLayouts = t.usedVertexLayouts, this._targets = Ru(e.fragmentFn.shell.out, e.targets);
3065
+ }
3066
+ [c] = !0;
3067
+ usedVertexLayouts;
3068
+ _memo;
3069
+ _vertexBufferLayouts;
3070
+ _targets;
3071
+ "~resolve"(e) {
3072
+ let { vertexFn: t, fragmentFn: r, slotBindings: n } = this.options, a = Zu(t.shell.out, r.shell.in, g(t) ?? "<unnamed>", g(r) ?? "<unnamed>");
3073
+ return e.withVaryingLocations(a, () => e.withSlots(n, () => (e.resolve(t), e.resolve(r), "")));
3074
+ }
3075
+ toString() {
3076
+ return "renderPipelineCore";
3077
+ }
3078
+ unwrap() {
3079
+ if (this._memo === void 0) {
3080
+ let { branch: e, primitiveState: t, depthStencilState: r, multisampleState: n } = this.options, a = e.device, s, i;
3081
+ if (De?.enabled) {
3082
+ let v = performance.mark("typegpu:resolution:start");
3083
+ s = st(this, { names: e.nameRegistry }), i = performance.measure("typegpu:resolution", { start: v.name });
3084
+ } else s = st(this, { names: e.nameRegistry });
3085
+ let { code: l, usedBindGroupLayouts: o, catchall: y } = s;
3086
+ y !== void 0 && o[y[0]]?.$name(`${g(this) ?? "<unnamed>"} - Automatic Bind Group & Layout`);
3087
+ let h = a.createShaderModule({ label: `${g(this) ?? "<unnamed>"} - Shader`, code: l }), w = { layout: a.createPipelineLayout({ label: `${g(this) ?? "<unnamed>"} - Pipeline Layout`, bindGroupLayouts: o.map((v) => e.unwrap(v)) }), vertex: { module: h, buffers: this._vertexBufferLayouts }, fragment: { module: h, targets: this._targets } }, b = g(this);
3088
+ b !== void 0 && (w.label = b), t && (ie(t.stripIndexFormat) ? w.primitive = { ...t, stripIndexFormat: { u32: "uint32", u16: "uint16" }[t.stripIndexFormat.type] } : w.primitive = t), r && (w.depthStencil = r), n && (w.multisample = n), this._memo = { pipeline: a.createRenderPipeline(w), usedBindGroupLayouts: o, catchall: y }, De?.enabled && (async () => {
3089
+ let v = performance.mark("typegpu:compile-start");
3090
+ await a.queue.onSubmittedWorkDone();
3091
+ let x = performance.measure("typegpu:compiled", { start: v.name });
3092
+ De?.record("resolution", { resolveDuration: i?.duration, compileDuration: x.duration, wgslSize: l.length });
3093
+ })();
3094
+ }
3095
+ return this._memo;
3096
+ }
3097
+ };
3098
+ function Zu(e, t, r, n) {
3099
+ let a = {}, s = /* @__PURE__ */ new Set();
3100
+ function i(o, y) {
3101
+ a[o] = y, s.add(y);
3102
+ }
3103
+ for (let [o, y] of Object.entries(e)) {
3104
+ let h = Pe(y);
3105
+ h !== void 0 && i(o, h);
3106
+ }
3107
+ for (let [o, y] of Object.entries(t ?? {})) {
3108
+ let h = Pe(y);
3109
+ h !== void 0 && (a[o] === void 0 ? i(o, h) : a[o] !== h && console.warn(`Mismatched location between vertexFn (${r}) output (${a[o]}) and fragmentFn (${n}) input (${h}) for the key "${o}", using the location set on vertex output.`));
3110
+ }
3111
+ let l = 0;
3112
+ for (let o of Object.keys(e ?? {})) if (!(Ft(e[o]) || a[o] !== void 0)) {
3113
+ for (; s.has(l); ) l++;
3114
+ i(o, l);
3115
+ }
3116
+ return a;
3117
+ }
3118
+ function Xu(e) {
3119
+ return e instanceof Tt;
3120
+ }
3121
+ var Tt = class {
3122
+ constructor(e, t) {
3123
+ this.resourceType = e, this.buffer = t, this[Y] = t, this.#e = this.buffer.as(this.resourceType);
3124
+ }
3125
+ [c] = !0;
3126
+ [Y];
3127
+ #e;
3128
+ $name(e) {
3129
+ return F(this[Y], e), this;
3130
+ }
3131
+ write(e) {
3132
+ this.buffer.write(e);
3133
+ }
3134
+ writePartial(e) {
3135
+ this.buffer.writePartial(e);
3136
+ }
3137
+ read() {
3138
+ return this.buffer.read();
3139
+ }
3140
+ [j](e) {
3141
+ return this.#e.$;
3142
+ }
3143
+ get $() {
3144
+ return this.#e.$;
3145
+ }
3146
+ get value() {
3147
+ return this.$;
3148
+ }
3149
+ "~resolve"(e) {
3150
+ return e.resolve(this.#e);
3151
+ }
3152
+ }, Qu = class ar {
3153
+ constructor(t, r) {
3154
+ this._getRoot = t, this._slotBindings = r;
3155
+ }
3156
+ with(t, r) {
3157
+ return new ar(this._getRoot, [...this._slotBindings, [Nt(t) ? t.slot : t, r]]);
3158
+ }
3159
+ withCompute(t) {
3160
+ return new Ku(this._getRoot(), this._slotBindings, t);
3161
+ }
3162
+ withVertex(t, r) {
3163
+ return new Hu({ branch: this._getRoot(), primitiveState: void 0, depthStencilState: void 0, slotBindings: this._slotBindings, vertexFn: t, vertexAttribs: r, multisampleState: void 0 });
3164
+ }
3165
+ pipe(t) {
3166
+ let r = t(new Xn([]));
3167
+ return new ar(this._getRoot, [...this._slotBindings, ...r.bindings]);
3168
+ }
3169
+ }, Ku = class {
3170
+ constructor(e, t, r) {
3171
+ this._root = e, this._slotBindings = t, this._entryFn = r;
3172
+ }
3173
+ createPipeline() {
3174
+ return Fu(this._root, this._slotBindings, this._entryFn);
3175
+ }
3176
+ }, Hu = class {
3177
+ constructor(e) {
3178
+ this._options = e;
3179
+ }
3180
+ withFragment(e, t, r) {
3181
+ return Pt(typeof e != "string", "Just type mismatch validation"), Pt(typeof t != "string", "Just type mismatch validation"), new el({ ...this._options, fragmentFn: e, targets: t });
3182
+ }
3183
+ }, el = class $t {
3184
+ constructor(t) {
3185
+ this._options = t;
3186
+ }
3187
+ withPrimitive(t) {
3188
+ return new $t({ ...this._options, primitiveState: t });
3189
+ }
3190
+ withDepthStencil(t) {
3191
+ return new $t({ ...this._options, depthStencilState: t });
3192
+ }
3193
+ withMultisample(t) {
3194
+ return new $t({ ...this._options, multisampleState: t });
3195
+ }
3196
+ createPipeline() {
3197
+ return qu(this._options);
3198
+ }
3199
+ }, ga = class extends Qu {
3200
+ constructor(t, r, n) {
3201
+ super(() => this, []), this.device = t, this.nameRegistry = r, this._ownDevice = n, this["~unstable"] = this;
3202
+ }
3203
+ "~unstable";
3204
+ _disposables = [];
3205
+ _unwrappedBindGroupLayouts = new nn((t) => t.unwrap(this));
3206
+ _unwrappedBindGroups = new nn((t) => t.unwrap(this));
3207
+ _commandEncoder = null;
3208
+ get commandEncoder() {
3209
+ return this._commandEncoder || (this._commandEncoder = this.device.createCommandEncoder()), this._commandEncoder;
3210
+ }
3211
+ get enabledFeatures() {
3212
+ return new Set(this.device.features);
3213
+ }
3214
+ createBuffer(t, r) {
3215
+ let n = wt(this, t, r);
3216
+ return this._disposables.push(n), n;
3217
+ }
3218
+ createUniform(t, r) {
3219
+ let n = wt(this, t, r).$usage("uniform");
3220
+ return this._disposables.push(n), new Tt("uniform", n);
3221
+ }
3222
+ createMutable(t, r) {
3223
+ let n = wt(this, t, r).$usage("storage");
3224
+ return this._disposables.push(n), new Tt("mutable", n);
3225
+ }
3226
+ createReadonly(t, r) {
3227
+ let n = wt(this, t, r).$usage("storage");
3228
+ return this._disposables.push(n), new Tt("readonly", n);
3229
+ }
3230
+ createQuerySet(t, r, n) {
3231
+ return Gu(this, t, r, n);
3232
+ }
3233
+ createBindGroup(t, r) {
3234
+ return new da(t, r);
3235
+ }
3236
+ destroy() {
3237
+ for (let t of this._disposables) t.destroy();
3238
+ this._ownDevice && this.device.destroy();
3239
+ }
3240
+ createTexture(t) {
3241
+ let r = bu(t, this);
3242
+ return this._disposables.push(r), r;
3243
+ }
3244
+ unwrap(t) {
3245
+ if (Cu(t)) return t[c].rawPipeline;
3246
+ if (ju(t)) return t[c].core.unwrap().pipeline;
3247
+ if (ua(t)) return this._unwrappedBindGroupLayouts.getOrMake(t);
3248
+ if (tn(t)) return this._unwrappedBindGroups.getOrMake(t);
3249
+ if (Qe(t)) return t.buffer;
3250
+ if (at(t)) return t[c].unwrap();
3251
+ if (na(t)) {
3252
+ if (t[c].unwrap) return t[c].unwrap();
3253
+ throw new Error("Cannot unwrap laid-out texture view.");
3254
+ }
3255
+ if (aa(t)) {
3256
+ if (t[c].unwrap) return t[c].unwrap();
3257
+ throw new Error("Cannot unwrap laid-out texture view.");
3258
+ }
3259
+ if (wa(t)) return t.vertexLayout;
3260
+ if (ta(t)) {
3261
+ if (t[c].unwrap) return t[c].unwrap(this);
3262
+ throw new Error("Cannot unwrap laid-out sampler.");
3263
+ }
3264
+ if (ra(t)) {
3265
+ if (t[c].unwrap) return t[c].unwrap(this);
3266
+ throw new Error("Cannot unwrap laid-out comparison sampler.");
3267
+ }
3268
+ if (Ur(t)) return t.querySet;
3269
+ throw new Error(`Unknown resource type: ${t}`);
3270
+ }
3271
+ beginRenderPass(t, r) {
3272
+ let n = this.commandEncoder.beginRenderPass(t), a = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), i, l = () => {
3273
+ if (!i) throw new Error("Cannot draw without a call to pass.setPipeline");
3274
+ let { core: o, priors: y } = i[c], h = o.unwrap();
3275
+ n.setPipeline(h.pipeline);
3276
+ let w = new Set(h.usedBindGroupLayouts);
3277
+ h.usedBindGroupLayouts.forEach((v, x) => {
3278
+ if (h.catchall && x === h.catchall[0]) n.setBindGroup(x, this.unwrap(h.catchall[1])), w.delete(v);
3279
+ else {
3280
+ let P = y.bindGroupLayoutMap?.get(v) ?? a.get(v);
3281
+ P !== void 0 && (w.delete(v), tn(P) ? n.setBindGroup(x, this.unwrap(P)) : n.setBindGroup(x, P));
3282
+ }
3283
+ });
3284
+ let b = /* @__PURE__ */ new Set();
3285
+ if (o.usedVertexLayouts.forEach((v, x) => {
3286
+ let P = y.vertexLayoutMap?.get(v), $ = P ? { buffer: P, offset: void 0, size: void 0 } : s.get(v);
3287
+ !$ || !$.buffer ? b.add(v) : Qe($.buffer) ? n.setVertexBuffer(x, this.unwrap($.buffer), $.offset, $.size) : n.setVertexBuffer(x, $.buffer, $.offset, $.size);
3288
+ }), w.size > 0) throw new fr(w);
3289
+ if (b.size > 0) throw new Mn(b);
3290
+ };
3291
+ r({ setViewport(...o) {
3292
+ n.setViewport(...o);
3293
+ }, setScissorRect(...o) {
3294
+ n.setScissorRect(...o);
3295
+ }, setBlendConstant(...o) {
3296
+ n.setBlendConstant(...o);
3297
+ }, setStencilReference(...o) {
3298
+ n.setStencilReference(...o);
3299
+ }, beginOcclusionQuery(...o) {
3300
+ n.beginOcclusionQuery(...o);
3301
+ }, endOcclusionQuery(...o) {
3302
+ n.endOcclusionQuery(...o);
3303
+ }, executeBundles(...o) {
3304
+ n.executeBundles(...o);
3305
+ }, setPipeline(o) {
3306
+ i = o;
3307
+ }, setIndexBuffer: (o, y, h, w) => {
3308
+ Qe(o) ? n.setIndexBuffer(this.unwrap(o), y, h, w) : n.setIndexBuffer(o, y, h, w);
3309
+ }, setVertexBuffer(o, y, h, w) {
3310
+ s.set(o, { buffer: y, offset: h, size: w });
3311
+ }, setBindGroup(o, y) {
3312
+ a.set(o, y);
3313
+ }, draw(o, y, h, w) {
3314
+ l(), n.draw(o, y, h, w);
3315
+ }, drawIndexed(...o) {
3316
+ l(), n.drawIndexed(...o);
3317
+ }, drawIndirect(...o) {
3318
+ l(), n.drawIndirect(...o);
3319
+ }, drawIndexedIndirect(...o) {
3320
+ l(), n.drawIndexedIndirect(...o);
3321
+ } }), n.end();
3322
+ }
3323
+ flush() {
3324
+ this._commandEncoder && (this.device.queue.submit([this._commandEncoder.finish()]), this._commandEncoder = null);
3325
+ }
3326
+ };
3327
+ async function tl(e) {
3328
+ let { adapter: t, device: r, unstable_names: n = "random" } = e ?? {};
3329
+ if (!navigator.gpu) throw new Error("WebGPU is not supported by this browser.");
3330
+ let a = await navigator.gpu.requestAdapter(t);
3331
+ if (!a) throw new Error("Could not find a compatible GPU");
3332
+ let s = [];
3333
+ for (let i of r?.requiredFeatures ?? []) {
3334
+ if (!a.features.has(i)) throw new Error(`Requested feature "${i}" is not supported by the adapter.`);
3335
+ s.push(i);
3336
+ }
3337
+ for (let i of r?.optionalFeatures ?? []) a.features.has(i) ? s.push(i) : console.warn(`Optional feature "${i}" is not supported by the adapter.`);
3338
+ return new ga(await a.requestDevice({ ...r, requiredFeatures: s }), n === "random" ? new $r() : new Yt(), !0);
3339
+ }
3340
+ function rl(e) {
3341
+ let { device: t, unstable_names: r = "random" } = e ?? {};
3342
+ return new ga(t, r === "random" ? new $r() : new Yt(), !1);
3343
+ }
3344
+ function sr(e) {
3345
+ return new nl(e);
3346
+ }
3347
+ var nl = class {
3348
+ constructor(e = void 0) {
3349
+ this.defaultValue = e;
3350
+ }
3351
+ [c] = !0;
3352
+ resourceType = "slot";
3353
+ $name(e) {
3354
+ return F(this, e), this;
3355
+ }
3356
+ areEqual(e, t) {
3357
+ return Object.is(e, t);
3358
+ }
3359
+ toString() {
3360
+ return `slot:${g(this) ?? "<unnamed>"}`;
3361
+ }
3362
+ [j](e) {
3363
+ return Tr(e, e.unwrap(this));
3364
+ }
3365
+ get value() {
3366
+ let e = tt();
3367
+ if (!e) throw new Error("Cannot access tgpu.slot's value outside of resolution.");
3368
+ return this[j](e);
3369
+ }
3370
+ get $() {
3371
+ return this.value;
3372
+ }
3373
+ };
3374
+ function al(e, t) {
3375
+ return new sl(e, t);
3376
+ }
3377
+ var sl = class {
3378
+ constructor(e, t = void 0) {
3379
+ this.schema = e, this.defaultValue = t, this.slot = sr(t), this[Y] = this.slot;
3380
+ }
3381
+ [c] = !0;
3382
+ resourceType = "accessor";
3383
+ slot;
3384
+ [Y];
3385
+ $name(e) {
3386
+ return this.slot.$name(e), this;
3387
+ }
3388
+ toString() {
3389
+ return `accessor:${g(this) ?? "<unnamed>"}`;
3390
+ }
3391
+ [j]() {
3392
+ return new Proxy({ [c]: !0, "~resolve": (e) => e.resolve(this), toString: () => `.value:${g(this) ?? "<unnamed>"}`, [C]: this.schema }, qe);
3393
+ }
3394
+ get value() {
3395
+ if (hr()) return this[j]();
3396
+ throw new Error("`tgpu.accessor` relies on GPU resources and cannot be accessed outside of a compute dispatch or draw call");
3397
+ }
3398
+ get $() {
3399
+ return this.value;
3400
+ }
3401
+ "~resolve"(e) {
3402
+ let t = e.unwrap(this.slot);
3403
+ return Ys(t) || Xu(t) ? e.resolve(t) : Co(t) ? `${e.resolve(t)}()` : e.resolve(t, this.schema);
3404
+ }
3405
+ };
3406
+ function il(e) {
3407
+ return ul(e);
3408
+ }
3409
+ function ol([e, t]) {
3410
+ return `${g(e) ?? "<unnamed>"}=${t}`;
3411
+ }
3412
+ function ul(e) {
3413
+ if (tt()) throw new Error("Cannot create tgpu.derived objects at the resolution stage.");
3414
+ return { [c]: !0, resourceType: "derived", "~compute": e, [j](t) {
3415
+ return Tr(t, t.unwrap(this));
3416
+ }, get value() {
3417
+ let t = tt();
3418
+ if (!t) throw new Error("Cannot access tgpu.derived's value outside of resolution.");
3419
+ return this[j](t);
3420
+ }, get $() {
3421
+ return this.value;
3422
+ }, with(t, r) {
3423
+ return ba(this, [[t, r]]);
3424
+ }, toString() {
3425
+ return "derived";
3426
+ } };
3427
+ }
3428
+ function ba(e, t) {
3429
+ return { [c]: !0, resourceType: "derived", "~compute"() {
3430
+ throw new Error("'~compute' should never be read on bound derived items.");
3431
+ }, [Me]: { inner: e, pairs: t }, [j](r) {
3432
+ return Tr(r, r.unwrap(this));
3433
+ }, get value() {
3434
+ let r = tt();
3435
+ if (!r) throw new Error("Cannot access tgpu.derived's value outside of resolution.");
3436
+ return this[j](r);
3437
+ }, get $() {
3438
+ return this.value;
3439
+ }, with(r, n) {
3440
+ return ba(e, [...t, [r, n]]);
3441
+ }, toString() {
3442
+ return `derived[${t.map(ol).join(", ")}]`;
3443
+ } };
3444
+ }
3445
+ function ll(e, t) {
3446
+ return new va("private", e, t);
3447
+ }
3448
+ function dl(e) {
3449
+ return new va("workgroup", e);
3450
+ }
3451
+ var va = class {
3452
+ [c] = {};
3453
+ #e;
3454
+ #t;
3455
+ #r;
3456
+ constructor(t, r, n) {
3457
+ this.#e = t, this.#t = r, this.#r = n;
3458
+ }
3459
+ "~resolve"(t) {
3460
+ let r = t.names.makeUnique(g(this));
3461
+ return this.#r ? t.addDeclaration(`var<${this.#e}> ${r}: ${t.resolve(this.#t)} = ${t.resolve(this.#r, this.#t)};`) : t.addDeclaration(`var<${this.#e}> ${r}: ${t.resolve(this.#t)};`), r;
3462
+ }
3463
+ $name(t) {
3464
+ return F(this, t), this;
3465
+ }
3466
+ toString() {
3467
+ return `var:${g(this) ?? "<unnamed>"}`;
3468
+ }
3469
+ [j]() {
3470
+ return new Proxy({ [c]: !0, "~resolve": (t) => t.resolve(this), toString: () => `.value:${g(this) ?? "<unnamed>"}`, [C]: this.#t }, qe);
3471
+ }
3472
+ get $() {
3473
+ let t = St(), r = It();
3474
+ if (t.type === "normal") throw new Br(r ? `Cannot access variable '${g(this) ?? "<unnamed>"}'. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation` : "TypeGPU variables are inaccessible during normal JS execution. If you wanted to simulate GPU behavior, try `tgpu.simulate()`");
3475
+ return t.type === "codegen" ? this[j]() : t.type === "simulate" ? (t.vars[this.#e].has(this) || t.vars[this.#e].set(this, this.#r), t.vars[this.#e].get(this)) : rt(t, "tgpuVariable.ts#TgpuVarImpl/$");
3476
+ }
3477
+ set $(t) {
3478
+ let r = St(), n = It();
3479
+ if (r.type === "normal") throw new Br(n ? `Cannot access ${String(this)}. TypeGPU functions that depends on GPU resources need to be part of a compute dispatch, draw call or simulation` : "TypeGPU variables are inaccessible during normal JS execution. If you wanted to simulate GPU behavior, try `tgpu.simulate()`");
3480
+ if (r.type === "codegen") throw new Error("Unreachable tgpuVariable.ts#TgpuVarImpl/$");
3481
+ if (r.type === "simulate") {
3482
+ r.vars[this.#e].set(this, t);
3483
+ return;
3484
+ }
3485
+ rt(r, "tgpuVariable.ts#TgpuVarImpl/$");
3486
+ }
3487
+ get value() {
3488
+ return this.$;
3489
+ }
3490
+ set value(t) {
3491
+ this.$ = t;
3492
+ }
3493
+ }, cl = { fn: qr, bindGroupLayout: oa, vertexLayout: an, slot: sr, init: tl, initFromDevice: rl, resolve: Au, resolveWithContext: ha, "~unstable": { fn: qr, fragmentFn: Do, vertexFn: zo, computeFn: Bo, vertexLayout: an, derived: il, slot: sr, accessor: al, privateVar: ll, workgroupVar: dl, const: go, declare: xo, sampler: lu, comparisonSampler: du, simulate: Ou } }, T = cl, pl = d(() => {
3494
+ throw new Error("`discard` relies on GPU resources and cannot be executed outside of a draw call");
3495
+ }, () => u("discard;", de), "discard"), hl = d((e) => typeof e == "number" ? Math.abs(e) : E.abs[e.kind](e), (e) => u(p`abs(${e})`, e.dataType), "abs"), fl = d((e) => typeof e == "number" ? Math.acos(e) : E.acos[e.kind](e), (e) => u(p`acos(${e})`, e.dataType), "acos"), ml = d((e) => typeof e == "number" ? Math.acosh(e) : E.acosh[e.kind](e), (e) => u(p`acosh(${e})`, e.dataType), "acosh"), yl = d((e) => typeof e == "number" ? Math.asin(e) : E.asin[e.kind](e), (e) => u(p`asin(${e})`, e.dataType), "asin"), wl = d((e) => typeof e == "number" ? Math.asinh(e) : E.asinh[e.kind](e), (e) => u(p`asinh(${e})`, e.dataType), "asinh"), gl = d((e) => typeof e == "number" ? Math.atan(e) : E.atan[e.kind](e), (e) => u(p`atan(${e})`, e.dataType), "atan"), bl = d((e) => typeof e == "number" ? Math.atanh(e) : E.atanh[e.kind](e), (e) => u(p`atanh(${e})`, e.dataType), "atanh"), vl = d((e, t) => typeof e == "number" && typeof t == "number" ? Math.atan2(e, t) : E.atan2[e.kind](e, t), (e, t) => u(p`atan2(${e}, ${t})`, e.dataType), "atan2", "unify"), _l = d((e) => typeof e == "number" ? Math.ceil(e) : E.ceil[e.kind](e), (e) => u(p`ceil(${e})`, e.dataType), "ceil"), xl = d((e, t, r) => typeof e == "number" ? Math.min(Math.max(t, e), r) : E.clamp[e.kind](e, t, r), (e, t, r) => u(p`clamp(${e}, ${t}, ${r})`, e.dataType), "clamp"), le = d((e) => typeof e == "number" ? Math.cos(e) : E.cos[e.kind](e), (e) => u(p`cos(${e})`, e.dataType), "cos"), Tl = d((e) => typeof e == "number" ? Math.cosh(e) : E.cosh[e.kind](e), (e) => u(p`cosh(${e})`, e.dataType), "cosh"), $l = d((e) => {
3496
+ throw new Error("CPU implementation for countLeadingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3497
+ }, (e) => u(p`countLeadingZeros(${e})`, e.dataType), "countLeadingZeros"), El = d((e) => {
3498
+ throw new Error("CPU implementation for countOneBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3499
+ }, (e) => u(p`countOneBits(${e})`, e.dataType), "countOneBits"), Ul = d((e) => {
3500
+ throw new Error("CPU implementation for countTrailingZeros not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3501
+ }, (e) => u(p`countTrailingZeros(${e})`, e.dataType), "countTrailingZeros"), Pl = d((e, t) => E.cross[e.kind](e, t), (e, t) => u(p`cross(${e}, ${t})`, e.dataType), "cross"), Sl = d((e) => {
3502
+ if (typeof e == "number") return e * 180 / Math.PI;
3503
+ throw new Error("CPU implementation for degrees on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3504
+ }, (e) => u(p`degrees(${e})`, e.dataType), "degrees"), Il = d((e) => {
3505
+ throw new Error("CPU implementation for determinant not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3506
+ }, (e) => u(p`determinant(${e})`, f), "determinant"), kl = d((e, t) => typeof e == "number" && typeof t == "number" ? Math.abs(e - t) : _a(M(e, t)), (e, t) => u(p`distance(${e}, ${t})`, e.dataType.type === "f16" || e.dataType.type.endsWith("h") ? We : f), "distance"), q = d((e, t) => E.dot[e.kind](e, t), (e, t) => u(p`dot(${e}, ${t})`, f), "dot"), Ml = d((e, t) => {
3507
+ throw new Error("CPU implementation for dot4U8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3508
+ }, (e, t) => u(p`dot4U8Packed(${e}, ${t})`, m), "dot4U8Packed", [m, m]), Al = d((e, t) => {
3509
+ throw new Error("CPU implementation for dot4I8Packed not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3510
+ }, (e, t) => u(p`dot4I8Packed(${e}, ${t})`, J), "dot4I8Packed", [J, J]), Ol = d((e) => typeof e == "number" ? Math.exp(e) : E.exp[e.kind](e), (e) => u(p`exp(${e})`, e.dataType), "exp"), Gl = d((e) => typeof e == "number" ? 2 ** e : E.exp2[e.kind](e), (e) => u(p`exp2(${e})`, e.dataType), "exp2"), Bl = d((e, t, r) => {
3511
+ throw new Error("CPU implementation for extractBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3512
+ }, (e, t, r) => u(p`extractBits(${e}, ${t}, ${r})`, e.dataType), "extractBits", (e, t, r) => [e.dataType, m, m]), Fl = d((e, t, r) => {
3513
+ throw new Error("CPU implementation for faceForward not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3514
+ }, (e, t, r) => u(p`faceForward(${e}, ${t}, ${r})`, e.dataType), "faceForward"), Cl = d((e) => {
3515
+ throw new Error("CPU implementation for firstLeadingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3516
+ }, (e) => u(p`firstLeadingBit(${e})`, e.dataType), "firstLeadingBit"), Nl = d((e) => {
3517
+ throw new Error("CPU implementation for firstTrailingBit not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3518
+ }, (e) => u(p`firstTrailingBit(${e})`, e.dataType), "firstTrailingBit"), Ge = d((e) => typeof e == "number" ? Math.floor(e) : E.floor[e.kind](e), (e) => u(p`floor(${e})`, e.dataType), "floor"), Ll = d((e, t, r) => {
3519
+ if (typeof e == "number") return e * t + r;
3520
+ throw new Error("CPU implementation for fma on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3521
+ }, (e, t, r) => u(p`fma(${e}, ${t}, ${r})`, e.dataType), "fma"), we = d((e) => typeof e == "number" ? e - Math.floor(e) : E.fract[e.kind](e), (e) => u(p`fract(${e})`, e.dataType), "fract"), Dl = { f32: Z({ fract: f, exp: J }), f16: Z({ fract: We, exp: J }), abstractFloat: Z({ fract: kt, exp: mr }), vec2f: Z({ fract: _, exp: K }), vec3f: Z({ fract: S, exp: Ue }), vec4f: Z({ fract: O, exp: te }), vec2h: Z({ fract: Ke, exp: K }), vec3h: Z({ fract: He, exp: Ue }), vec4h: Z({ fract: et, exp: te }) }, Wl = d((e) => {
3522
+ throw new Error("CPU implementation for frexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3523
+ }, (e) => {
3524
+ let t = Dl[e.dataType.type];
3525
+ if (!t) throw new Error(`Unsupported data type for frexp: ${e.dataType.type}. Supported types are f32, f16, abstractFloat, vec2f, vec3f, vec4f, vec2h, vec3h, vec4h.`);
3526
+ return u(p`frexp(${e})`, t);
3527
+ }, "frexp"), zl = d((e, t, r, n) => {
3528
+ throw new Error("CPU implementation for insertBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3529
+ }, (e, t, r, n) => u(p`insertBits(${e}, ${t}, ${r}, ${n})`, e.dataType), "insertBits"), Yl = d((e) => {
3530
+ if (typeof e == "number") return 1 / Math.sqrt(e);
3531
+ throw new Error("CPU implementation for inverseSqrt on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3532
+ }, (e) => u(p`inverseSqrt(${e})`, e.dataType), "inverseSqrt"), Rl = d((e, t) => {
3533
+ throw new Error("CPU implementation for ldexp not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3534
+ }, (e, t) => u(p`ldexp(${e}, ${t})`, e.dataType), "ldexp", (e, t) => {
3535
+ switch (e.dataType.type) {
3536
+ case "abstractFloat":
3537
+ return [kt, mr];
3538
+ case "f32":
3539
+ case "f16":
3540
+ return [e.dataType, J];
3541
+ case "vec2f":
3542
+ case "vec2h":
3543
+ return [e.dataType, K];
3544
+ case "vec3f":
3545
+ case "vec3h":
3546
+ return [e.dataType, Ue];
3547
+ case "vec4f":
3548
+ case "vec4h":
3549
+ return [e.dataType, te];
3550
+ default:
3551
+ throw new Error(`Unsupported data type for ldexp: ${e.dataType.type}. Supported types are abstractFloat, f32, f16, vec2f, vec2h, vec3f, vec3h, vec4f, vec4h.`);
3552
+ }
3553
+ }), _a = d((e) => typeof e == "number" ? Math.abs(e) : E.length[e.kind](e), (e) => u(p`length(${e})`, f), "length"), ql = d((e) => typeof e == "number" ? Math.log(e) : E.log[e.kind](e), (e) => u(p`log(${e})`, e.dataType), "log"), jl = d((e) => typeof e == "number" ? Math.log2(e) : E.log2[e.kind](e), (e) => u(p`log2(${e})`, e.dataType), "log2"), Vl = d((e, t) => typeof e == "number" ? Math.max(e, t) : E.max[e.kind](e, t), (e, t) => u(p`max(${e}, ${t})`, e.dataType), "max", "unify"), Jl = d((e, t) => typeof e == "number" ? Math.min(e, t) : E.min[e.kind](e, t), (e, t) => u(p`min(${e}, ${t})`, e.dataType), "min", "unify"), ye = d((e, t, r) => {
3554
+ if (typeof e == "number") {
3555
+ if (typeof r != "number" || typeof t != "number") throw new Error("When e1 and e2 are numbers, the blend factor must be a number.");
3556
+ return e * (1 - r) + t * r;
3557
+ }
3558
+ if (typeof e == "number" || typeof t == "number") throw new Error("e1 and e2 need to both be vectors of the same kind.");
3559
+ return E.mix[e.kind](e, t, r);
3560
+ }, (e, t, r) => u(p`mix(${e}, ${t}, ${r})`, e.dataType), "mix"), Zl = { f32: Z({ fract: f, whole: f }), f16: Z({ fract: We, whole: We }), abstractFloat: Z({ fract: kt, whole: kt }), vec2f: Z({ fract: _, whole: _ }), vec3f: Z({ fract: S, whole: S }), vec4f: Z({ fract: O, whole: O }), vec2h: Z({ fract: Ke, whole: Ke }), vec3h: Z({ fract: He, whole: He }), vec4h: Z({ fract: et, whole: et }) }, Xl = d((e) => {
3561
+ throw new Error("CPU implementation for modf not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3562
+ }, (e) => {
3563
+ let t = Zl[e.dataType.type];
3564
+ if (!t) throw new Error(`Unsupported data type for modf: ${e.dataType.type}. Supported types are f32, f16, abstractFloat, vec2f, vec3f, vec4f, vec2h, vec3h, vec4h.`);
3565
+ return u(p`modf(${e})`, t);
3566
+ }, "modf"), Ql = d((e) => E.normalize[e.kind](e), (e) => u(p`normalize(${e})`, e.dataType), "normalize"), Kl = d((e, t) => {
3567
+ if (typeof e == "number" && typeof t == "number") return e ** t;
3568
+ if (typeof e == "object" && typeof t == "object" && "kind" in e && "kind" in t) return E.pow[e.kind](e, t);
3569
+ throw new Error("Invalid arguments to pow()");
3570
+ }, (e, t) => u(p`pow(${e}, ${t})`, e.dataType), "pow"), Hl = d((e) => {
3571
+ throw new Error("CPU implementation for quantizeToF16 not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3572
+ }, (e) => u(p`quantizeToF16(${e})`, e.dataType), "quantizeToF16"), ed = d((e) => {
3573
+ if (typeof e == "number") return e * Math.PI / 180;
3574
+ throw new Error("CPU implementation for radians on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3575
+ }, (e) => u(p`radians(${e})`, e.dataType), "radians"), td = d((e, t) => M(e, A(2 * q(t, e), t)), (e, t) => u(p`reflect(${e}, ${t})`, e.dataType), "reflect"), rd = d((e, t, r) => {
3576
+ throw new Error("CPU implementation for refract not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3577
+ }, (e, t, r) => u(p`refract(${e}, ${t}, ${r})`, e.dataType), "refract", (e, t, r) => [e.dataType, t.dataType, e.dataType.type === "f16" || e.dataType.type.endsWith("h") ? We : f]), nd = d((e) => {
3578
+ throw new Error("CPU implementation for reverseBits not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3579
+ }, (e) => u(p`reverseBits(${e})`, e.dataType), "reverseBits"), ad = d((e) => {
3580
+ if (typeof e == "number") return Math.round(e);
3581
+ throw new Error("CPU implementation for round on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3582
+ }, (e) => u(p`round(${e})`, e.dataType), "round"), sd = d((e) => {
3583
+ if (typeof e == "number") return Math.max(0, Math.min(1, e));
3584
+ throw new Error("CPU implementation for saturate on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3585
+ }, (e) => u(p`saturate(${e})`, e.dataType), "saturate"), ir = d((e) => typeof e == "number" ? Math.sign(e) : E.sign[e.kind](e), (e) => u(p`sign(${e})`, e.dataType), "sign"), Be = d((e) => typeof e == "number" ? Math.sin(e) : E.sin[e.kind](e), (e) => u(p`sin(${e})`, e.dataType), "sin"), id = d((e) => {
3586
+ if (typeof e == "number") return Math.sinh(e);
3587
+ throw new Error("CPU implementation for sinh on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3588
+ }, (e) => u(p`sinh(${e})`, e.dataType), "sinh"), od = d((e, t, r) => typeof r == "number" ? si(e, t, r) : E.smoothstep[r.kind](e, t, r), (e, t, r) => u(p`smoothstep(${e}, ${t}, ${r})`, r.dataType), "smoothstep"), it = d((e) => typeof e == "number" ? Math.sqrt(e) : E.sqrt[e.kind](e), (e) => u(p`sqrt(${e})`, e.dataType), "sqrt"), ud = d((e, t) => {
3589
+ if (typeof e == "number") return e <= t ? 1 : 0;
3590
+ throw new Error("CPU implementation for step on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3591
+ }, (e, t) => u(p`step(${e}, ${t})`, e.dataType), "step"), ld = d((e) => {
3592
+ if (typeof e == "number") return Math.tan(e);
3593
+ throw new Error("CPU implementation for tan on vectors not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3594
+ }, (e) => u(p`tan(${e})`, e.dataType), "tan"), dd = d((e) => typeof e == "number" ? Math.tanh(e) : E.tanh[e.kind](e), (e) => u(p`tanh(${e})`, e.dataType), "tanh"), cd = d((e) => {
3595
+ throw new Error("CPU implementation for transpose not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3596
+ }, (e) => u(p`transpose(${e})`, e.dataType), "transpose"), pd = d((e) => {
3597
+ throw new Error("CPU implementation for trunc not implemented yet. Please submit an issue at https://github.com/software-mansion/TypeGPU/issues");
3598
+ }, (e) => u(p`trunc(${e})`, e.dataType), "trunc"), ct = A[c].jsImpl, hd = vr[c].jsImpl, fd = vr[c].gpuImpl, md = br[c].jsImpl, yd = br[c].gpuImpl, wd = yr[c].jsImpl, gd = yr[c].gpuImpl, bd = wr[c].jsImpl, vd = wr[c].gpuImpl, _d = gr[c].jsImpl, xd = gr[c].gpuImpl, Td = d((e, t) => ct(hd(t), e), (e, t) => u(p`(${fd(t)} * ${e})`, e.dataType), "translate4"), $d = d((e, t) => ct(md(t), e), (e, t) => u(p`(${yd(t)} * ${e})`, e.dataType), "scale4"), Ed = d((e, t) => ct(wd(t), e), (e, t) => u(p`(${gd(t)} * ${e})`, e.dataType), "rotateX4"), Ud = d((e, t) => ct(bd(t), e), (e, t) => u(p`(${vd(t)} * ${e})`, e.dataType), "rotateY4"), Pd = d((e, t) => ct(_d(t), e), (e, t) => u(p`(${xd(t)} * ${e})`, e.dataType), "rotateZ4");
3599
+ function je(e) {
3600
+ return e.dataType.type.includes("2") ? En : e.dataType.type.includes("3") ? Un : Pn;
3601
+ }
3602
+ var Sd = d((e, t) => Sr(pt(e, t)), (e, t) => u(p`all(${e} == ${t})`, Ae), "allEq"), pt = d((e, t) => E.eq[e.kind](e, t), (e, t) => u(p`(${e} == ${t})`, je(e)), "eq"), Id = d((e, t) => ge(pt(e, t)), (e, t) => u(p`(${e} != ${t})`, je(e)), "ne"), jt = d((e, t) => E.lt[e.kind](e, t), (e, t) => u(p`(${e} < ${t})`, je(e)), "lt"), kd = d((e, t) => Pr(jt(e, t), pt(e, t)), (e, t) => u(p`(${e} <= ${t})`, je(e)), "le"), Md = d((e, t) => xa(ge(jt(e, t)), ge(pt(e, t))), (e, t) => u(p`(${e} > ${t})`, je(e)), "gt"), Ad = d((e, t) => ge(jt(e, t)), (e, t) => u(p`(${e} >= ${t})`, je(e)), "ge"), ge = d((e) => E.neg[e.kind](e), (e) => u(p`!(${e})`, e.dataType), "not"), Pr = d((e, t) => E.or[e.kind](e, t), (e, t) => u(p`(${e} | ${t})`, e.dataType), "or"), xa = d((e, t) => ge(Pr(ge(e), ge(t))), (e, t) => u(p`(${e} & ${t})`, e.dataType), "and"), Sr = d((e) => E.all[e.kind](e), (e) => u(p`all(${e})`, Ae), "all"), Od = d((e) => !Sr(ge(e)), (e) => u(p`any(${e})`, Ae), "any"), Gd = d((e, t, r = 0.01) => typeof e == "number" && typeof t == "number" ? Math.abs(e - t) < r : Dr(e) && Dr(t) ? E.isCloseToZero[e.kind](M(e, t), r) : !1, (e, t, r = u(0.01, f)) => ft(e) && ft(t) ? u(p`(abs(f32(${e}) - f32(${t})) <= ${r})`, Ae) : !ft(e) && !ft(t) ? u(p`all(abs(${e} - ${t}) <= (${e} - ${e}) + ${r})`, Ae) : u("false", Ae), "isCloseTo"), Ie = d((e, t, r) => typeof r == "boolean" ? r ? t : e : E.select[e.kind](e, t, r), (e, t, r) => u(p`select(${e}, ${t}, ${r})`, e.dataType), "select"), Bd = d(() => console.warn("workgroupBarrier is a no-op outside of CODEGEN mode."), () => u("workgroupBarrier()", de), "workgroupBarrier"), Fd = d(() => console.warn("storageBarrier is a no-op outside of CODEGEN mode."), () => u("storageBarrier()", de), "storageBarrier"), Cd = d(() => console.warn("textureBarrier is a no-op outside of CODEGEN mode."), () => u("textureBarrier()", de), "textureBarrier"), Nd = d((e) => {
3603
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3604
+ }, (e) => {
3605
+ if (ie(e.dataType) && e.dataType.type === "atomic") return u(p`atomicLoad(&${e})`, e.dataType.inner);
3606
+ throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3607
+ }, "atomicLoad"), Ld = d((e, t) => {
3608
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3609
+ }, (e, t) => {
3610
+ if (!ie(e.dataType) || e.dataType.type !== "atomic") throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3611
+ return u(p`atomicStore(&${e}, ${t})`, de);
3612
+ }, "atomicStore"), Fe = (e, t) => e.dataType.type === "atomic" && e.dataType.inner.type === "i32" ? [e.dataType, J] : [e.dataType, m], Dd = d((e, t) => {
3613
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3614
+ }, (e, t) => {
3615
+ if (ie(e.dataType) && e.dataType.type === "atomic") return u(p`atomicAdd(&${e}, ${t})`, e.dataType.inner);
3616
+ throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3617
+ }, "atomicAdd", Fe), Wd = d((e, t) => {
3618
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3619
+ }, (e, t) => {
3620
+ if (ie(e.dataType) && e.dataType.type === "atomic") return u(p`atomicSub(&${e}, ${t})`, e.dataType.inner);
3621
+ throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3622
+ }, "atomicSub", Fe), zd = d((e, t) => {
3623
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3624
+ }, (e, t) => {
3625
+ if (ie(e.dataType) && e.dataType.type === "atomic") return u(p`atomicMax(&${e}, ${t})`, e.dataType.inner);
3626
+ throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3627
+ }, "atomicMax", Fe), Yd = d((e, t) => {
3628
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3629
+ }, (e, t) => {
3630
+ if (ie(e.dataType) && e.dataType.type === "atomic") return u(p`atomicMin(&${e}, ${t})`, e.dataType.inner);
3631
+ throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3632
+ }, "atomicMin", Fe), Rd = d((e, t) => {
3633
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3634
+ }, (e, t) => {
3635
+ if (ie(e.dataType) && e.dataType.type === "atomic") return u(p`atomicAnd(&${e}, ${t})`, e.dataType.inner);
3636
+ throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3637
+ }, "atomicAnd", Fe), qd = d((e, t) => {
3638
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3639
+ }, (e, t) => {
3640
+ if (ie(e.dataType) && e.dataType.type === "atomic") return u(p`atomicOr(&${e}, ${t})`, e.dataType.inner);
3641
+ throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3642
+ }, "atomicOr", Fe), jd = d((e, t) => {
3643
+ throw new Error("Atomic operations are not supported outside of CODEGEN mode.");
3644
+ }, (e, t) => {
3645
+ if (ie(e.dataType) && e.dataType.type === "atomic") return u(p`atomicXor(&${e}, ${t})`, e.dataType.inner);
3646
+ throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType, null, 2)}`);
3647
+ }, "atomicXor", Fe), Vd = d((e) => {
3648
+ throw new Error("Derivative builtins are not allowed on the cpu");
3649
+ }, (e) => u(p`dpdx(${e})`, e.dataType), "dpdx"), Jd = d((e) => {
3650
+ throw new Error("Derivative builtins are not allowed on the cpu");
3651
+ }, (e) => u(p`dpdxCoarse(${e})`, e.dataType), "dpdxCoarse"), Zd = d((e) => {
3652
+ throw new Error("Derivative builtins are not allowed on the cpu");
3653
+ }, (e) => u(p`dpdxFine(${e})`, e.dataType), "dpdxFine"), Xd = d((e) => {
3654
+ throw new Error("Derivative builtins are not allowed on the cpu");
3655
+ }, (e) => u(p`dpdy(${e})`, e.dataType), "dpdy"), Qd = d((e) => {
3656
+ throw new Error("Derivative builtins are not allowed on the cpu");
3657
+ }, (e) => u(p`dpdyCoarse(${e})`, e.dataType), "dpdyCoarse"), Kd = d((e) => {
3658
+ throw new Error("Derivative builtins are not allowed on the cpu");
3659
+ }, (e) => u(p`dpdyFine(${e})`, e.dataType), "dpdyFine"), Hd = d((e) => {
3660
+ throw new Error("Derivative builtins are not allowed on the cpu");
3661
+ }, (e) => u(p`fwidth(${e})`, e.dataType), "fwidth"), ec = d((e) => {
3662
+ throw new Error("Derivative builtins are not allowed on the cpu");
3663
+ }, (e) => u(p`fwidthCoarse(${e})`, e.dataType), "fwidthCoarse"), tc = d((e) => {
3664
+ throw new Error("Derivative builtins are not allowed on the cpu");
3665
+ }, (e) => u(p`fwidthFine(${e})`, e.dataType), "fwidthFine"), rc = d((e) => e.length, (e) => bn(e.dataType) && lt(e.dataType.inner) && e.dataType.inner.elementCount > 0 ? u(String(e.dataType.inner.elementCount), mr) : u(p`arrayLength(${e})`, m), "arrayLength", (e) => [Tn(e.dataType)]), nc = d((e) => {
3666
+ let t = new ArrayBuffer(4);
3667
+ new Se(t).writeUint32(e);
3668
+ let r = new Ee(t);
3669
+ return _(r.readFloat16(), r.readFloat16());
3670
+ }, (e) => u(p`unpack2x16float(${e})`, _), "unpack2x16float"), ac = d((e) => {
3671
+ let t = new ArrayBuffer(4), r = new Se(t);
3672
+ r.writeFloat16(e.x), r.writeFloat16(e.y);
3673
+ let n = new Ee(t);
3674
+ return m(n.readUint32());
3675
+ }, (e) => u(p`pack2x16float(${e})`, m), "pack2x16float"), sc = d((e) => {
3676
+ let t = new ArrayBuffer(4);
3677
+ new Se(t).writeUint32(e);
3678
+ let r = new Ee(t);
3679
+ return O(r.readUint8() / 255, r.readUint8() / 255, r.readUint8() / 255, r.readUint8() / 255);
3680
+ }, (e) => u(p`unpack4x8unorm(${e})`, O), "unpack4x8unorm"), ic = d((e) => {
3681
+ let t = new ArrayBuffer(4), r = new Se(t);
3682
+ r.writeUint8(e.x * 255), r.writeUint8(e.y * 255), r.writeUint8(e.z * 255), r.writeUint8(e.w * 255);
3683
+ let n = new Ee(t);
3684
+ return m(n.readUint32());
3685
+ }, (e) => u(p`pack4x8unorm(${e})`, m), "pack4x8unorm"), oc = d((e, t, r, n, a) => {
3686
+ throw new Error("Texture sampling relies on GPU resources and cannot be executed outside of a draw call");
3687
+ }, (...e) => u(p`textureSample(${e})`, O), "textureSample"), uc = d((e, t, r, n, a) => {
3688
+ throw new Error("Texture sampling relies on GPU resources and cannot be executed outside of a draw call");
3689
+ }, (...e) => u(p`textureSampleLevel(${e})`, O), "textureSampleLevel"), lc = { u32: ue, i32: te, f32: O }, dc = d((e, t, r) => {
3690
+ throw new Error("`textureLoad` relies on GPU resources and cannot be executed outside of a draw call");
3691
+ }, (...e) => {
3692
+ let t = e[0].dataType;
3693
+ return u(p`textureLoad(${e})`, "texelDataType" in t ? t.texelDataType : lc[t.channelDataType.type]);
3694
+ }, "textureLoad"), cc = d((e, t, r, n) => {
3695
+ throw new Error("`textureStore` relies on GPU resources and cannot be executed outside of a draw call");
3696
+ }, (...e) => u(p`textureStore(${e})`, de), "textureStore"), pc = d((e, t) => {
3697
+ throw new Error("`textureDimensions` relies on GPU resources and cannot be executed outside of a draw call");
3698
+ }, (...e) => {
3699
+ let t = e[0].dataType.dimension;
3700
+ return u(p`textureDimensions(${e})`, t === "1d" ? m : t === "3d" ? Ut : ne);
3701
+ }, "textureDimensions");
3702
+ const Ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3703
+ __proto__: null,
3704
+ abs: hl,
3705
+ acos: fl,
3706
+ acosh: ml,
3707
+ add: I,
3708
+ all: Sr,
3709
+ allEq: Sd,
3710
+ and: xa,
3711
+ any: Od,
3712
+ arrayLength: rc,
3713
+ asin: yl,
3714
+ asinh: wl,
3715
+ atan: gl,
3716
+ atan2: vl,
3717
+ atanh: bl,
3718
+ atomicAdd: Dd,
3719
+ atomicAnd: Rd,
3720
+ atomicLoad: Nd,
3721
+ atomicMax: zd,
3722
+ atomicMin: Yd,
3723
+ atomicOr: qd,
3724
+ atomicStore: Ld,
3725
+ atomicSub: Wd,
3726
+ atomicXor: jd,
3727
+ ceil: _l,
3728
+ clamp: xl,
3729
+ cos: le,
3730
+ cosh: Tl,
3731
+ countLeadingZeros: $l,
3732
+ countOneBits: El,
3733
+ countTrailingZeros: Ul,
3734
+ cross: Pl,
3735
+ degrees: Sl,
3736
+ determinant: Il,
3737
+ discard: pl,
3738
+ distance: kl,
3739
+ div: An,
3740
+ dot: q,
3741
+ dot4I8Packed: Al,
3742
+ dot4U8Packed: Ml,
3743
+ dpdx: Vd,
3744
+ dpdxCoarse: Jd,
3745
+ dpdxFine: Zd,
3746
+ dpdy: Xd,
3747
+ dpdyCoarse: Qd,
3748
+ dpdyFine: Kd,
3749
+ eq: pt,
3750
+ exp: Ol,
3751
+ exp2: Gl,
3752
+ extractBits: Bl,
3753
+ faceForward: Fl,
3754
+ firstLeadingBit: Cl,
3755
+ firstTrailingBit: Nl,
3756
+ floor: Ge,
3757
+ fma: Ll,
3758
+ fract: we,
3759
+ frexp: Wl,
3760
+ fwidth: Hd,
3761
+ fwidthCoarse: ec,
3762
+ fwidthFine: tc,
3763
+ ge: Ad,
3764
+ gt: Md,
3765
+ identity2: ii,
3766
+ identity3: oi,
3767
+ identity4: ui,
3768
+ insertBits: zl,
3769
+ inverseSqrt: Yl,
3770
+ isCloseTo: Gd,
3771
+ ldexp: Rl,
3772
+ le: kd,
3773
+ length: _a,
3774
+ log: ql,
3775
+ log2: jl,
3776
+ lt: jt,
3777
+ max: Vl,
3778
+ min: Jl,
3779
+ mix: ye,
3780
+ mod: li,
3781
+ modf: Xl,
3782
+ mul: A,
3783
+ ne: Id,
3784
+ neg: di,
3785
+ normalize: Ql,
3786
+ not: ge,
3787
+ or: Pr,
3788
+ pack2x16float: ac,
3789
+ pack4x8unorm: ic,
3790
+ pow: Kl,
3791
+ quantizeToF16: Hl,
3792
+ radians: ed,
3793
+ reflect: td,
3794
+ refract: rd,
3795
+ reverseBits: nd,
3796
+ rotateX4: Ed,
3797
+ rotateY4: Ud,
3798
+ rotateZ4: Pd,
3799
+ rotationX4: yr,
3800
+ rotationY4: wr,
3801
+ rotationZ4: gr,
3802
+ round: ad,
3803
+ saturate: sd,
3804
+ scale4: $d,
3805
+ scaling4: br,
3806
+ select: Ie,
3807
+ sign: ir,
3808
+ sin: Be,
3809
+ sinh: id,
3810
+ smoothstep: od,
3811
+ sqrt: it,
3812
+ step: ud,
3813
+ storageBarrier: Fd,
3814
+ sub: M,
3815
+ tan: ld,
3816
+ tanh: dd,
3817
+ textureBarrier: Cd,
3818
+ textureDimensions: pc,
3819
+ textureLoad: dc,
3820
+ textureSample: oc,
3821
+ textureSampleLevel: uc,
3822
+ textureStore: cc,
3823
+ translate4: Td,
3824
+ translation4: vr,
3825
+ transpose: cd,
3826
+ trunc: pd,
3827
+ unpack2x16float: nc,
3828
+ unpack4x8unorm: sc,
3829
+ workgroupBarrier: Bd
3830
+ }, Symbol.toStringTag, { value: "Module" })), hc = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([], f), "randomGeneratorShell"), fc = (() => {
3831
+ const e = (globalThis.__TYPEGPU_AUTONAME__ ?? ((t) => t))(T["~unstable"].privateVar(_), "seed");
3832
+ return {
3833
+ seed: (globalThis.__TYPEGPU_AUTONAME__ ?? ((t) => t))(T.fn([f])(((t) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(t.f = (r) => {
3834
+ e.value = _(r, 0);
3835
+ }, {
3836
+ v: 1,
3837
+ ast: { params: [{ type: "i", name: "value" }], body: [0, [[2, [7, "seed", "value"], "=", [6, [7, "d", "vec2f"], ["value", [5, "0"]]]]]], externalNames: ["seed", "d"] },
3838
+ get externals() {
3839
+ return { seed: e, d: W };
3840
+ }
3841
+ }) && t.f)({})), "seed"),
3842
+ seed2: (globalThis.__TYPEGPU_AUTONAME__ ?? ((t) => t))(T.fn([_])(((t) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(t.f = (r) => {
3843
+ e.value = r;
3844
+ }, {
3845
+ v: 1,
3846
+ ast: { params: [{ type: "i", name: "value" }], body: [0, [[2, [7, "seed", "value"], "=", "value"]]], externalNames: ["seed"] },
3847
+ get externals() {
3848
+ return { seed: e };
3849
+ }
3850
+ }) && t.f)({})), "seed2"),
3851
+ seed3: (globalThis.__TYPEGPU_AUTONAME__ ?? ((t) => t))(T.fn([S])(((t) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(t.f = (r) => {
3852
+ e.value = I(r.xy, _(r.z));
3853
+ }, {
3854
+ v: 1,
3855
+ ast: { params: [{ type: "i", name: "value" }], body: [0, [[2, [7, "seed", "value"], "=", [6, "add", [[7, "value", "xy"], [6, [7, "d", "vec2f"], [[7, "value", "z"]]]]]]]], externalNames: ["seed", "add", "d"] },
3856
+ get externals() {
3857
+ return { seed: e, add: I, d: W };
3858
+ }
3859
+ }) && t.f)({})), "seed3"),
3860
+ seed4: (globalThis.__TYPEGPU_AUTONAME__ ?? ((t) => t))(T.fn([O])(((t) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(t.f = (r) => {
3861
+ e.value = I(r.xy, r.zw);
3862
+ }, {
3863
+ v: 1,
3864
+ ast: { params: [{ type: "i", name: "value" }], body: [0, [[2, [7, "seed", "value"], "=", [6, "add", [[7, "value", "xy"], [7, "value", "zw"]]]]]], externalNames: ["seed", "add"] },
3865
+ get externals() {
3866
+ return { seed: e, add: I };
3867
+ }
3868
+ }) && t.f)({})), "seed4"),
3869
+ sample: hc(((t) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(t.f = ((r) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(r.f = () => {
3870
+ "kernel";
3871
+ const n = q(e.value, _(23.14077926, 232.61690225)), a = q(e.value, _(54.47856553, 345.84153136));
3872
+ return e.value.x = we(le(n) * 136.8168), e.value.y = we(le(a) * 534.7645), e.value.y;
3873
+ }, {
3874
+ v: 1,
3875
+ ast: { params: [], body: [0, [[13, "a", [6, "dot", [[7, "seed", "value"], [6, [7, "d", "vec2f"], [[5, "23.14077926"], [5, "232.61690225"]]]]]], [13, "b", [6, "dot", [[7, "seed", "value"], [6, [7, "d", "vec2f"], [[5, "54.47856553"], [5, "345.84153136"]]]]]], [2, [7, [7, "seed", "value"], "x"], "=", [6, "fract", [[1, [6, "cos", ["a"]], "*", [5, "136.8168"]]]]], [2, [7, [7, "seed", "value"], "y"], "=", [6, "fract", [[1, [6, "cos", ["b"]], "*", [5, "534.7645"]]]]], [10, [7, [7, "seed", "value"], "y"]]]], externalNames: ["dot", "seed", "d", "fract", "cos"] },
3876
+ get externals() {
3877
+ return { dot: q, seed: e, d: W, fract: we, cos: le };
3878
+ }
3879
+ }) && r.f)({}), {
3880
+ v: 1,
3881
+ ast: { params: [], body: [0, [[13, "a", [6, "dot", [[7, "seed", "value"], [6, [7, "d", "vec2f"], [[5, "23.14077926"], [5, "232.61690225"]]]]]], [13, "b", [6, "dot", [[7, "seed", "value"], [6, [7, "d", "vec2f"], [[5, "54.47856553"], [5, "345.84153136"]]]]]], [2, [7, [7, "seed", "value"], "x"], "=", [6, "fract", [[1, [6, "cos", ["a"]], "*", [5, "136.8168"]]]]], [2, [7, [7, "seed", "value"], "y"], "=", [6, "fract", [[1, [6, "cos", ["b"]], "*", [5, "534.7645"]]]]], [10, [7, [7, "seed", "value"], "y"]]]], externalNames: ["dot", "seed", "d", "fract", "cos"] },
3882
+ get externals() {
3883
+ return { dot: q, seed: e, d: W, fract: we, cos: le };
3884
+ }
3885
+ }) && t.f)({}))
3886
+ };
3887
+ })(), mc = fc, z = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.slot(
3888
+ mc
3889
+ ), "randomGeneratorSlot"), Ye = Math.PI * 2, yc = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([f])(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => {
3890
+ z.value.seed(t);
3891
+ }, {
3892
+ v: 1,
3893
+ ast: { params: [{ type: "i", name: "seed" }], body: [0, [[6, [7, [7, "randomGeneratorSlot", "value"], "seed"], ["seed"]]]], externalNames: ["randomGeneratorSlot"] },
3894
+ get externals() {
3895
+ return { randomGeneratorSlot: z };
3896
+ }
3897
+ }) && e.f)({})), "randSeed"), or = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([_])(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => {
3898
+ z.value.seed2(t);
3899
+ }, {
3900
+ v: 1,
3901
+ ast: { params: [{ type: "i", name: "seed" }], body: [0, [[6, [7, [7, "randomGeneratorSlot", "value"], "seed2"], ["seed"]]]], externalNames: ["randomGeneratorSlot"] },
3902
+ get externals() {
3903
+ return { randomGeneratorSlot: z };
3904
+ }
3905
+ }) && e.f)({})), "randSeed2"), ur = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([S])(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => {
3906
+ z.value.seed3(t);
3907
+ }, {
3908
+ v: 1,
3909
+ ast: { params: [{ type: "i", name: "seed" }], body: [0, [[6, [7, [7, "randomGeneratorSlot", "value"], "seed3"], ["seed"]]]], externalNames: ["randomGeneratorSlot"] },
3910
+ get externals() {
3911
+ return { randomGeneratorSlot: z };
3912
+ }
3913
+ }) && e.f)({})), "randSeed3"), wc = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([O])(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => {
3914
+ z.value.seed4(t);
3915
+ }, {
3916
+ v: 1,
3917
+ ast: { params: [{ type: "i", name: "seed" }], body: [0, [[6, [7, [7, "randomGeneratorSlot", "value"], "seed4"], ["seed"]]]], externalNames: ["randomGeneratorSlot"] },
3918
+ get externals() {
3919
+ return { randomGeneratorSlot: z };
3920
+ }
3921
+ }) && e.f)({})), "randSeed4"), gc = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([], f)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = () => z.value.sample(), {
3922
+ v: 1,
3923
+ ast: { params: [], body: [0, [[10, [6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []]]]], externalNames: ["randomGeneratorSlot"] },
3924
+ get externals() {
3925
+ return { randomGeneratorSlot: z };
3926
+ }
3927
+ }) && e.f)({})), "randFloat01"), bc = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([], S)(
3928
+ ((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = () => S(
3929
+ z.value.sample() * 2 - 1,
3930
+ z.value.sample() * 2 - 1,
3931
+ z.value.sample() * 2 - 1
3932
+ ), {
3933
+ v: 1,
3934
+ ast: { params: [], body: [0, [[10, [6, [7, "d", "vec3f"], [[1, [1, [6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []], "*", [5, "2"]], "-", [5, "1"]], [1, [1, [6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []], "*", [5, "2"]], "-", [5, "1"]], [1, [1, [6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []], "*", [5, "2"]], "-", [5, "1"]]]]]]], externalNames: ["d", "randomGeneratorSlot"] },
3935
+ get externals() {
3936
+ return { d: W, randomGeneratorSlot: z };
3937
+ }
3938
+ }) && e.f)({})
3939
+ ), "randInUnitCube"), vc = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([], _)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = () => {
3940
+ const t = it(z.value.sample()), r = z.value.sample() * Ye;
3941
+ return _(le(r) * t, Be(r) * t);
3942
+ }, {
3943
+ v: 1,
3944
+ ast: { params: [], body: [0, [[13, "radius", [6, "sqrt", [[6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []]]]], [13, "angle", [1, [6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []], "*", "TWO_PI"]], [10, [6, [7, "d", "vec2f"], [[1, [6, "cos", ["angle"]], "*", "radius"], [1, [6, "sin", ["angle"]], "*", "radius"]]]]]], externalNames: ["sqrt", "randomGeneratorSlot", "TWO_PI", "d", "cos", "sin"] },
3945
+ get externals() {
3946
+ return { sqrt: it, randomGeneratorSlot: z, TWO_PI: Ye, d: W, cos: le, sin: Be };
3947
+ }
3948
+ }) && e.f)({})), "randInUnitCircle"), sn = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([], _)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = () => {
3949
+ const t = z.value.sample() * Ye;
3950
+ return _(le(t), Be(t));
3951
+ }, {
3952
+ v: 1,
3953
+ ast: { params: [], body: [0, [[13, "angle", [1, [6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []], "*", "TWO_PI"]], [10, [6, [7, "d", "vec2f"], [[6, "cos", ["angle"]], [6, "sin", ["angle"]]]]]]], externalNames: ["randomGeneratorSlot", "TWO_PI", "d", "cos", "sin"] },
3954
+ get externals() {
3955
+ return { randomGeneratorSlot: z, TWO_PI: Ye, d: W, cos: le, sin: Be };
3956
+ }
3957
+ }) && e.f)({})), "randOnUnitCircle"), ot = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([], S)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = () => {
3958
+ const t = 2 * z.value.sample() - 1, r = it(1 - t * t), n = Ye * z.value.sample() - Math.PI, a = Be(n) * r, s = le(n) * r;
3959
+ return S(a, s, t);
3960
+ }, {
3961
+ v: 1,
3962
+ ast: { params: [], body: [0, [[13, "z", [1, [1, [5, "2"], "*", [6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []]], "-", [5, "1"]]], [13, "oneMinusZSq", [6, "sqrt", [[1, [5, "1"], "-", [1, "z", "*", "z"]]]]], [13, "theta", [1, [1, "TWO_PI", "*", [6, [7, [7, "randomGeneratorSlot", "value"], "sample"], []]], "-", [7, "Math", "PI"]]], [13, "x", [1, [6, "sin", ["theta"]], "*", "oneMinusZSq"]], [13, "y", [1, [6, "cos", ["theta"]], "*", "oneMinusZSq"]], [10, [6, [7, "d", "vec3f"], ["x", "y", "z"]]]]], externalNames: ["randomGeneratorSlot", "sqrt", "TWO_PI", "Math", "sin", "cos", "d"] },
3963
+ get externals() {
3964
+ return { randomGeneratorSlot: z, sqrt: it, TWO_PI: Ye, Math, sin: Be, cos: le, d: W };
3965
+ }
3966
+ }) && e.f)({})), "randOnUnitSphere"), _c = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([S], S)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => {
3967
+ const r = ot(), n = q(t, r);
3968
+ return A(ir(n), r);
3969
+ }, {
3970
+ v: 1,
3971
+ ast: { params: [{ type: "i", name: "normal" }], body: [0, [[13, "value", [6, "randOnUnitSphere", []]], [13, "alignment", [6, "dot", ["normal", "value"]]], [10, [6, "mul", [[6, "sign", ["alignment"]], "value"]]]]], externalNames: ["randOnUnitSphere", "dot", "mul", "sign"] },
3972
+ get externals() {
3973
+ return { randOnUnitSphere: ot, dot: q, mul: A, sign: ir };
3974
+ }
3975
+ }) && e.f)({})), "randOnUnitHemisphere"), Ta = ((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = ((t) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(t.f = (r) => {
3976
+ "kernel";
3977
+ return A(A(r, A(r, r)), I(A(r, M(A(r, 6), 15)), 10));
3978
+ }, {
3979
+ v: 1,
3980
+ ast: { params: [{ type: "i", name: "t" }], body: [0, [[10, [6, "mul", [[6, "mul", ["t", [6, "mul", ["t", "t"]]]], [6, "add", [[6, "mul", ["t", [6, "sub", [[6, "mul", ["t", [5, "6"]]], [5, "15"]]]]], [5, "10"]]]]]]]], externalNames: ["mul", "add", "sub"] },
3981
+ get externals() {
3982
+ return { mul: A, add: I, sub: M };
3983
+ }
3984
+ }) && t.f)({}), {
3985
+ v: 1,
3986
+ ast: { params: [{ type: "i", name: "t" }], body: [0, [[10, [6, "mul", [[6, "mul", ["t", [6, "mul", ["t", "t"]]]], [6, "add", [[6, "mul", ["t", [6, "sub", [[6, "mul", ["t", [5, "6"]]], [5, "15"]]]]], [5, "10"]]]]]]]], externalNames: ["mul", "add", "sub"] },
3987
+ get externals() {
3988
+ return { mul: A, add: I, sub: M };
3989
+ }
3990
+ }) && e.f)({}), Ot = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([_], _)(Ta), "quinticInterpolation2"), on = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([S], S)(Ta), "quinticInterpolation3"), $a = ((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = ((t) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(t.f = (r) => {
3991
+ "kernel";
3992
+ return A(A(A(30, r), r), I(A(r, M(r, 2)), 1));
3993
+ }, {
3994
+ v: 1,
3995
+ ast: { params: [{ type: "i", name: "t" }], body: [0, [[10, [6, "mul", [[6, "mul", [[6, "mul", [[5, "30"], "t"]], "t"]], [6, "add", [[6, "mul", ["t", [6, "sub", ["t", [5, "2"]]]]], [5, "1"]]]]]]]], externalNames: ["mul", "add", "sub"] },
3996
+ get externals() {
3997
+ return { mul: A, add: I, sub: M };
3998
+ }
3999
+ }) && t.f)({}), {
4000
+ v: 1,
4001
+ ast: { params: [{ type: "i", name: "t" }], body: [0, [[10, [6, "mul", [[6, "mul", [[6, "mul", [[5, "30"], "t"]], "t"]], [6, "add", [[6, "mul", ["t", [6, "sub", ["t", [5, "2"]]]]], [5, "1"]]]]]]]], externalNames: ["mul", "add", "sub"] },
4002
+ get externals() {
4003
+ return { mul: A, add: I, sub: M };
4004
+ }
4005
+ }) && e.f)({}), un = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([_], _)($a), "quinticDerivative2");
4006
+ (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([S], S)($a), "quinticDerivative3");
4007
+ const xc = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([K], _)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => (or(A(1e-3, _(t))), sn()), {
4008
+ v: 1,
4009
+ ast: { params: [{ type: "i", name: "pos" }], body: [0, [[6, "randSeed2", [[6, "mul", [[5, "1e-3"], [6, [7, "d", "vec2f"], ["pos"]]]]]], [10, [6, "randOnUnitCircle", []]]]], externalNames: ["randSeed2", "mul", "d", "randOnUnitCircle"] },
4010
+ get externals() {
4011
+ return { randSeed2: or, mul: A, d: W, randOnUnitCircle: sn };
4012
+ }
4013
+ }) && e.f)({})), "computeJunctionGradient"), pe = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.slot(xc), "getJunctionGradientSlot");
4014
+ (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([_], f)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => {
4015
+ const r = K(Ge(t)), n = we(t), a = Ot(n), s = pe.$(r), i = pe.$(I(r, K(1, 0))), l = pe.$(I(r, K(0, 1))), o = pe.$(I(r, K(1, 1))), y = q(s, M(n, _(0, 0))), h = q(i, M(n, _(1, 0))), w = q(l, M(n, _(0, 1))), b = q(o, M(n, _(1, 1)));
4016
+ return y + a.x * (h - y) + a.y * (w - y) + a.x * a.y * (y - h - w + b);
4017
+ }, {
4018
+ v: 1,
4019
+ ast: { params: [{ type: "i", name: "pos" }], body: [0, [[13, "i", [6, [7, "d", "vec2i"], [[6, "floor", ["pos"]]]]], [13, "f", [6, "fract", ["pos"]]], [13, "u", [6, "quinticInterpolation2", ["f"]]], [13, "ga", [6, [7, "getJunctionGradientSlot", "$"], ["i"]]], [13, "gb", [6, [7, "getJunctionGradientSlot", "$"], [[6, "add", ["i", [6, [7, "d", "vec2i"], [[5, "1"], [5, "0"]]]]]]]], [13, "gc", [6, [7, "getJunctionGradientSlot", "$"], [[6, "add", ["i", [6, [7, "d", "vec2i"], [[5, "0"], [5, "1"]]]]]]]], [13, "gd", [6, [7, "getJunctionGradientSlot", "$"], [[6, "add", ["i", [6, [7, "d", "vec2i"], [[5, "1"], [5, "1"]]]]]]]], [13, "va", [6, "dot", ["ga", [6, "sub", ["f", [6, [7, "d", "vec2f"], [[5, "0"], [5, "0"]]]]]]]], [13, "vb", [6, "dot", ["gb", [6, "sub", ["f", [6, [7, "d", "vec2f"], [[5, "1"], [5, "0"]]]]]]]], [13, "vc", [6, "dot", ["gc", [6, "sub", ["f", [6, [7, "d", "vec2f"], [[5, "0"], [5, "1"]]]]]]]], [13, "vd", [6, "dot", ["gd", [6, "sub", ["f", [6, [7, "d", "vec2f"], [[5, "1"], [5, "1"]]]]]]]], [13, "noise", [1, [1, [1, "va", "+", [1, [7, "u", "x"], "*", [1, "vb", "-", "va"]]], "+", [1, [7, "u", "y"], "*", [1, "vc", "-", "va"]]], "+", [1, [1, [7, "u", "x"], "*", [7, "u", "y"]], "*", [1, [1, [1, "va", "-", "vb"], "-", "vc"], "+", "vd"]]]], [10, "noise"]]], externalNames: ["d", "floor", "fract", "quinticInterpolation2", "getJunctionGradientSlot", "add", "dot", "sub"] },
4020
+ get externals() {
4021
+ return { d: W, floor: Ge, fract: we, quinticInterpolation2: Ot, getJunctionGradientSlot: pe, add: I, dot: q, sub: M };
4022
+ }
4023
+ }) && e.f)({})), "sample");
4024
+ (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([_], S)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => {
4025
+ const r = K(Ge(t)), n = we(t), a = Ot(n), s = un(n), i = pe.$(r), l = pe.$(I(r, K(1, 0))), o = pe.$(I(r, K(0, 1))), y = pe.$(I(r, K(1, 1))), h = q(i, M(n, _(0, 0))), w = q(l, M(n, _(1, 0))), b = q(o, M(n, _(0, 1))), v = q(y, M(n, _(1, 1))), x = h + a.x * (w - h) + a.y * (b - h) + a.x * a.y * (h - w - b + v), P = I(
4026
+ i,
4027
+ I(
4028
+ I(
4029
+ I(A(a.x, M(l, i)), A(a.y, M(o, i))),
4030
+ A(a.x, A(a.y, I(M(M(i, l), o), y)))
4031
+ ),
4032
+ A(s, M(I(A(a.yx, h - w - b + v), _(w, b)), h))
4033
+ )
4034
+ );
4035
+ return S(x, P);
4036
+ }, {
4037
+ v: 1,
4038
+ ast: { params: [{ type: "i", name: "pos" }], body: [0, [[13, "i", [6, [7, "d", "vec2i"], [[6, "floor", ["pos"]]]]], [13, "f", [6, "fract", ["pos"]]], [13, "u", [6, "quinticInterpolation2", ["f"]]], [13, "du", [6, "quinticDerivative2", ["f"]]], [13, "ga", [6, [7, "getJunctionGradientSlot", "$"], ["i"]]], [13, "gb", [6, [7, "getJunctionGradientSlot", "$"], [[6, "add", ["i", [6, [7, "d", "vec2i"], [[5, "1"], [5, "0"]]]]]]]], [13, "gc", [6, [7, "getJunctionGradientSlot", "$"], [[6, "add", ["i", [6, [7, "d", "vec2i"], [[5, "0"], [5, "1"]]]]]]]], [13, "gd", [6, [7, "getJunctionGradientSlot", "$"], [[6, "add", ["i", [6, [7, "d", "vec2i"], [[5, "1"], [5, "1"]]]]]]]], [13, "va", [6, "dot", ["ga", [6, "sub", ["f", [6, [7, "d", "vec2f"], [[5, "0"], [5, "0"]]]]]]]], [13, "vb", [6, "dot", ["gb", [6, "sub", ["f", [6, [7, "d", "vec2f"], [[5, "1"], [5, "0"]]]]]]]], [13, "vc", [6, "dot", ["gc", [6, "sub", ["f", [6, [7, "d", "vec2f"], [[5, "0"], [5, "1"]]]]]]]], [13, "vd", [6, "dot", ["gd", [6, "sub", ["f", [6, [7, "d", "vec2f"], [[5, "1"], [5, "1"]]]]]]]], [13, "noise", [1, [1, [1, "va", "+", [1, [7, "u", "x"], "*", [1, "vb", "-", "va"]]], "+", [1, [7, "u", "y"], "*", [1, "vc", "-", "va"]]], "+", [1, [1, [7, "u", "x"], "*", [7, "u", "y"]], "*", [1, [1, [1, "va", "-", "vb"], "-", "vc"], "+", "vd"]]]], [13, "grad", [6, "add", ["ga", [6, "add", [[6, "add", [[6, "add", [[6, "mul", [[7, "u", "x"], [6, "sub", ["gb", "ga"]]]], [6, "mul", [[7, "u", "y"], [6, "sub", ["gc", "ga"]]]]]], [6, "mul", [[7, "u", "x"], [6, "mul", [[7, "u", "y"], [6, "add", [[6, "sub", [[6, "sub", ["ga", "gb"]], "gc"]], "gd"]]]]]]]], [6, "mul", ["du", [6, "sub", [[6, "add", [[6, "mul", [[7, "u", "yx"], [1, [1, [1, "va", "-", "vb"], "-", "vc"], "+", "vd"]]], [6, [7, "d", "vec2f"], ["vb", "vc"]]]], "va"]]]]]]]]], [10, [6, [7, "d", "vec3f"], ["noise", "grad"]]]]], externalNames: ["d", "floor", "fract", "quinticInterpolation2", "quinticDerivative2", "getJunctionGradientSlot", "add", "dot", "sub", "mul"] },
4039
+ get externals() {
4040
+ return { d: W, floor: Ge, fract: we, quinticInterpolation2: Ot, quinticDerivative2: un, getJunctionGradientSlot: pe, add: I, dot: q, sub: M, mul: A };
4041
+ }
4042
+ }) && e.f)({})), "sampleWithGradient");
4043
+ Q(_);
4044
+ Q(_);
4045
+ const Tc = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([Ue], S)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => (ur(A(1e-3, S(t))), ot()), {
4046
+ v: 1,
4047
+ ast: { params: [{ type: "i", name: "pos" }], body: [0, [[6, "randSeed3", [[6, "mul", [[5, "1e-3"], [6, [7, "d", "vec3f"], ["pos"]]]]]], [10, [6, "randOnUnitSphere", []]]]], externalNames: ["randSeed3", "mul", "d", "randOnUnitSphere"] },
4048
+ get externals() {
4049
+ return { randSeed3: ur, mul: A, d: W, randOnUnitSphere: ot };
4050
+ }
4051
+ }) && e.f)({})), "computeJunctionGradient"), ln = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.slot(Tc), "getJunctionGradientSlot"), he = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([S, S], f)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r) => {
4052
+ const n = M(t, r), a = ln.value(Ue(r));
4053
+ return q(n, a);
4054
+ }, {
4055
+ v: 1,
4056
+ ast: { params: [{ type: "i", name: "pos" }, { type: "i", name: "junction" }], body: [0, [[13, "relative", [6, "sub", ["pos", "junction"]]], [13, "gridVector", [6, [7, "getJunctionGradientSlot", "value"], [[6, [7, "d", "vec3i"], ["junction"]]]]], [10, [6, "dot", ["relative", "gridVector"]]]]], externalNames: ["sub", "getJunctionGradientSlot", "d", "dot"] },
4057
+ get externals() {
4058
+ return { sub: M, getJunctionGradientSlot: ln, d: W, dot: q };
4059
+ }
4060
+ }) && e.f)({})), "dotProdGrid");
4061
+ (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn([S], f)(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t) => {
4062
+ const r = Ge(t), n = he(t, r), a = he(t, I(r, S(0, 0, 1))), s = he(t, I(r, S(0, 1, 0))), i = he(t, I(r, S(0, 1, 1))), l = he(t, I(r, S(1, 0, 0))), o = he(t, I(r, S(1, 0, 1))), y = he(t, I(r, S(1, 1, 0))), h = he(t, I(r, S(1, 1, 1))), w = M(t, r), b = on(w), v = ye(n, a, b.z), x = ye(s, i, b.z), P = ye(l, o, b.z), $ = ye(y, h, b.z), k = ye(v, x, b.y), L = ye(P, $, b.y);
4063
+ return ye(k, L, b.x);
4064
+ }, {
4065
+ v: 1,
4066
+ ast: { params: [{ type: "i", name: "pos" }], body: [0, [[13, "minJunction", [6, "floor", ["pos"]]], [13, "xyz", [6, "dotProdGrid", ["pos", "minJunction"]]], [13, "xyZ", [6, "dotProdGrid", ["pos", [6, "add", ["minJunction", [6, [7, "d", "vec3f"], [[5, "0"], [5, "0"], [5, "1"]]]]]]]], [13, "xYz", [6, "dotProdGrid", ["pos", [6, "add", ["minJunction", [6, [7, "d", "vec3f"], [[5, "0"], [5, "1"], [5, "0"]]]]]]]], [13, "xYZ", [6, "dotProdGrid", ["pos", [6, "add", ["minJunction", [6, [7, "d", "vec3f"], [[5, "0"], [5, "1"], [5, "1"]]]]]]]], [13, "Xyz", [6, "dotProdGrid", ["pos", [6, "add", ["minJunction", [6, [7, "d", "vec3f"], [[5, "1"], [5, "0"], [5, "0"]]]]]]]], [13, "XyZ", [6, "dotProdGrid", ["pos", [6, "add", ["minJunction", [6, [7, "d", "vec3f"], [[5, "1"], [5, "0"], [5, "1"]]]]]]]], [13, "XYz", [6, "dotProdGrid", ["pos", [6, "add", ["minJunction", [6, [7, "d", "vec3f"], [[5, "1"], [5, "1"], [5, "0"]]]]]]]], [13, "XYZ", [6, "dotProdGrid", ["pos", [6, "add", ["minJunction", [6, [7, "d", "vec3f"], [[5, "1"], [5, "1"], [5, "1"]]]]]]]], [13, "partial", [6, "sub", ["pos", "minJunction"]]], [13, "smoothPartial", [6, "quinticInterpolation3", ["partial"]]], [13, "xy", [6, "mix", ["xyz", "xyZ", [7, "smoothPartial", "z"]]]], [13, "xY", [6, "mix", ["xYz", "xYZ", [7, "smoothPartial", "z"]]]], [13, "Xy", [6, "mix", ["Xyz", "XyZ", [7, "smoothPartial", "z"]]]], [13, "XY", [6, "mix", ["XYz", "XYZ", [7, "smoothPartial", "z"]]]], [13, "x", [6, "mix", ["xy", "xY", [7, "smoothPartial", "y"]]]], [13, "X", [6, "mix", ["Xy", "XY", [7, "smoothPartial", "y"]]]], [10, [6, "mix", ["x", "X", [7, "smoothPartial", "x"]]]]]], externalNames: ["floor", "dotProdGrid", "add", "d", "sub", "quinticInterpolation3", "mix"] },
4067
+ get externals() {
4068
+ return { floor: Ge, dotProdGrid: he, add: I, d: W, sub: M, quinticInterpolation3: on, mix: ye };
4069
+ }
4070
+ }) && e.f)({})), "sample");
4071
+ Q(S);
4072
+ Q(S);
4073
+ const Xt = {
4074
+ seed: yc,
4075
+ seed2: or,
4076
+ seed3: ur,
4077
+ seed4: wc,
4078
+ sample: gc,
4079
+ inUnitCircle: vc,
4080
+ inUnitCube: bc,
4081
+ onHemisphere: _c,
4082
+ onUnitSphere: ot
4083
+ }, Ea = await navigator.gpu.requestAdapter();
4084
+ if (!Ea)
4085
+ throw new Error("No adapter");
4086
+ const Ua = await Ea.requestDevice();
4087
+ Ua.lost.then(() => {
4088
+ throw Error("Device lost");
4089
+ });
4090
+ let gt = 0, Gt;
4091
+ const G = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.bindGroupLayout({
4092
+ dimensions: { uniform: ne },
4093
+ colors: { storage: Q(m), access: "mutable" },
4094
+ newColors: { storage: Q(m), access: "mutable" },
4095
+ ids: { storage: Q(m), access: "mutable" },
4096
+ newIds: { storage: Q(m), access: "mutable" }
4097
+ }), "gridLayout"), xe = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.bindGroupLayout({
4098
+ neighborhood: { uniform: m },
4099
+ elements: {
4100
+ storage: Q(hi),
4101
+ access: "readonly"
4102
+ },
4103
+ rules: {
4104
+ storage: Q(pi),
4105
+ access: "readonly"
4106
+ },
4107
+ conditions: {
4108
+ storage: Q(ci),
4109
+ access: "readonly"
4110
+ }
4111
+ }), "automatonLayout"), ae = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4112
+ [m, m],
4113
+ m
4114
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r) => r % G.bound.dimensions.$.y * G.bound.dimensions.$.x + t % G.bound.dimensions.$.x, {
4115
+ v: 1,
4116
+ ast: { params: [{ type: "i", name: "x" }, { type: "i", name: "y" }], body: [0, [[10, [1, [1, [1, "y", "%", [7, [7, [7, [7, "gridLayout", "bound"], "dimensions"], "$"], "y"]], "*", [7, [7, [7, [7, "gridLayout", "bound"], "dimensions"], "$"], "x"]], "+", [1, "x", "%", [7, [7, [7, [7, "gridLayout", "bound"], "dimensions"], "$"], "x"]]]]]], externalNames: ["gridLayout"] },
4117
+ get externals() {
4118
+ return { gridLayout: G };
4119
+ }
4120
+ }) && e.f)({})), "pointToIndex"), fe = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4121
+ [m, m, m],
4122
+ m
4123
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r, n) => Ie(
4124
+ m(0),
4125
+ m(1),
4126
+ G.bound.ids.$[ae(r, n)] === t
4127
+ ), {
4128
+ v: 1,
4129
+ ast: { params: [{ type: "i", name: "checkId" }, { type: "i", name: "x" }, { type: "i", name: "y" }], body: [0, [[10, [6, [7, "std", "select"], [[6, [7, "d", "u32"], [[5, "0"]]], [6, [7, "d", "u32"], [[5, "1"]]], [1, [8, [7, [7, [7, "gridLayout", "bound"], "ids"], "$"], [6, "pointToIndex", ["x", "y"]]], "==", "checkId"]]]]]], externalNames: ["std", "d", "gridLayout", "pointToIndex"] },
4130
+ get externals() {
4131
+ return { std: Ce, d: W, gridLayout: G, pointToIndex: ae };
4132
+ }
4133
+ }) && e.f)({})), "testNeighbor"), oe = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4134
+ [m, m, m],
4135
+ m
4136
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r, n) => {
4137
+ const a = G.bound.ids.$[ae(r, n)];
4138
+ return Ie(
4139
+ m(0),
4140
+ m(1),
4141
+ // Note: in unsigned space if idMask is > 31 it's gonna loop back to 0,
4142
+ // so we cannot allow ids greater than 31 here. However no error is thrown,
4143
+ // so to keep gpu logic simple we do the check during the compile step.
4144
+ (t & m(1) << a) !== m(0)
4145
+ );
4146
+ }, {
4147
+ v: 1,
4148
+ ast: { params: [{ type: "i", name: "packedIds" }, { type: "i", name: "x" }, { type: "i", name: "y" }], body: [0, [[13, "idMask", [8, [7, [7, [7, "gridLayout", "bound"], "ids"], "$"], [6, "pointToIndex", ["x", "y"]]]], [10, [6, [7, "std", "select"], [[6, [7, "d", "u32"], [[5, "0"]]], [6, [7, "d", "u32"], [[5, "1"]]], [1, [1, "packedIds", "&", [1, [6, [7, "d", "u32"], [[5, "1"]]], "<<", "idMask"]], "!=", [6, [7, "d", "u32"], [[5, "0"]]]]]]]]], externalNames: ["gridLayout", "pointToIndex", "std", "d"] },
4149
+ get externals() {
4150
+ return { gridLayout: G, pointToIndex: ae, std: Ce, d: W };
4151
+ }
4152
+ }) && e.f)({})), "testIdInPack"), Bt = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4153
+ [m, m, m, m],
4154
+ m
4155
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r, n, a) => {
4156
+ const s = fe(n, t - 1, r - 1) + fe(n, t, r - 1) + fe(n, t + 1, r - 1) + fe(n, t - 1, r) + fe(n, t + 1, r) + fe(n, t - 1, r + 1) + fe(n, t, r + 1) + fe(n, t + 1, r + 1);
4157
+ return Ie(
4158
+ m(0),
4159
+ m(1),
4160
+ (a & m(1) << s) !== m(0)
4161
+ );
4162
+ }, {
4163
+ v: 1,
4164
+ ast: { params: [{ type: "i", name: "x" }, { type: "i", name: "y" }, { type: "i", name: "checkId" }, { type: "i", name: "packedCount" }], body: [0, [[13, "countMask", [1, [1, [1, [1, [1, [1, [1, [6, "testNeighbor", ["checkId", [1, "x", "-", [5, "1"]], [1, "y", "-", [5, "1"]]]], "+", [6, "testNeighbor", ["checkId", "x", [1, "y", "-", [5, "1"]]]]], "+", [6, "testNeighbor", ["checkId", [1, "x", "+", [5, "1"]], [1, "y", "-", [5, "1"]]]]], "+", [6, "testNeighbor", ["checkId", [1, "x", "-", [5, "1"]], "y"]]], "+", [6, "testNeighbor", ["checkId", [1, "x", "+", [5, "1"]], "y"]]], "+", [6, "testNeighbor", ["checkId", [1, "x", "-", [5, "1"]], [1, "y", "+", [5, "1"]]]]], "+", [6, "testNeighbor", ["checkId", "x", [1, "y", "+", [5, "1"]]]]], "+", [6, "testNeighbor", ["checkId", [1, "x", "+", [5, "1"]], [1, "y", "+", [5, "1"]]]]]], [10, [6, [7, "std", "select"], [[6, [7, "d", "u32"], [[5, "0"]]], [6, [7, "d", "u32"], [[5, "1"]]], [1, [1, "packedCount", "&", [1, [6, [7, "d", "u32"], [[5, "1"]]], "<<", "countMask"]], "!=", [6, [7, "d", "u32"], [[5, "0"]]]]]]]]], externalNames: ["testNeighbor", "std", "d"] },
4165
+ get externals() {
4166
+ return { testNeighbor: fe, std: Ce, d: W };
4167
+ }
4168
+ }) && e.f)({})), "checkIdCount"), dn = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4169
+ [m, m, m, m],
4170
+ m
4171
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r, n, a) => {
4172
+ const s = oe(n, t - 1, r - 1) + oe(n, t, r - 1) + oe(n, t + 1, r - 1) + oe(n, t - 1, r) + oe(n, t + 1, r) + oe(n, t - 1, r + 1) + oe(n, t, r + 1) + oe(n, t + 1, r + 1);
4173
+ return Ie(
4174
+ m(0),
4175
+ m(1),
4176
+ (a & m(1) << s) !== m(0)
4177
+ );
4178
+ }, {
4179
+ v: 1,
4180
+ ast: { params: [{ type: "i", name: "x" }, { type: "i", name: "y" }, { type: "i", name: "packedIds" }, { type: "i", name: "packedCount" }], body: [0, [[13, "countMask", [1, [1, [1, [1, [1, [1, [1, [6, "testIdInPack", ["packedIds", [1, "x", "-", [5, "1"]], [1, "y", "-", [5, "1"]]]], "+", [6, "testIdInPack", ["packedIds", "x", [1, "y", "-", [5, "1"]]]]], "+", [6, "testIdInPack", ["packedIds", [1, "x", "+", [5, "1"]], [1, "y", "-", [5, "1"]]]]], "+", [6, "testIdInPack", ["packedIds", [1, "x", "-", [5, "1"]], "y"]]], "+", [6, "testIdInPack", ["packedIds", [1, "x", "+", [5, "1"]], "y"]]], "+", [6, "testIdInPack", ["packedIds", [1, "x", "-", [5, "1"]], [1, "y", "+", [5, "1"]]]]], "+", [6, "testIdInPack", ["packedIds", "x", [1, "y", "+", [5, "1"]]]]], "+", [6, "testIdInPack", ["packedIds", [1, "x", "+", [5, "1"]], [1, "y", "+", [5, "1"]]]]]], [10, [6, [7, "std", "select"], [[6, [7, "d", "u32"], [[5, "0"]]], [6, [7, "d", "u32"], [[5, "1"]]], [1, [1, "packedCount", "&", [1, [6, [7, "d", "u32"], [[5, "1"]]], "<<", "countMask"]], "!=", [6, [7, "d", "u32"], [[5, "0"]]]]]]]]], externalNames: ["testIdInPack", "std", "d"] },
4181
+ get externals() {
4182
+ return { testIdInPack: oe, std: Ce, d: W };
4183
+ }
4184
+ }) && e.f)({})), "checkIdsCount"), cn = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4185
+ [m, m, ne, m],
4186
+ m
4187
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r, n, a) => {
4188
+ const s = ae(
4189
+ t + m(n.x),
4190
+ r + m(n.y)
4191
+ ), i = G.bound.ids.$[s];
4192
+ return Bt(t, r, i, a);
4193
+ }, {
4194
+ v: 1,
4195
+ ast: { params: [{ type: "i", name: "x" }, { type: "i", name: "y" }, { type: "i", name: "checkPoint" }, { type: "i", name: "packedCount" }], body: [0, [[13, "pointIndex", [6, "pointToIndex", [[1, "x", "+", [6, [7, "d", "u32"], [[7, "checkPoint", "x"]]]], [1, "y", "+", [6, [7, "d", "u32"], [[7, "checkPoint", "y"]]]]]]], [13, "checkId", [8, [7, [7, [7, "gridLayout", "bound"], "ids"], "$"], "pointIndex"]], [10, [6, "checkIdCount", ["x", "y", "checkId", "packedCount"]]]]], externalNames: ["pointToIndex", "d", "gridLayout", "checkIdCount"] },
4196
+ get externals() {
4197
+ return { pointToIndex: ae, d: W, gridLayout: G, checkIdCount: Bt };
4198
+ }
4199
+ }) && e.f)({})), "checkPointCount"), pn = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4200
+ [m, m, ne, m],
4201
+ m
4202
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r, n, a) => {
4203
+ const s = ae(
4204
+ t + n.x,
4205
+ r + n.y
4206
+ );
4207
+ return Ie(
4208
+ m(0),
4209
+ m(1),
4210
+ G.bound.ids.$[s] === a
4211
+ );
4212
+ }, {
4213
+ v: 1,
4214
+ ast: { params: [{ type: "i", name: "x" }, { type: "i", name: "y" }, { type: "i", name: "comparePoint" }, { type: "i", name: "withId" }], body: [0, [[13, "comparePointIndex", [6, "pointToIndex", [[1, "x", "+", [7, "comparePoint", "x"]], [1, "y", "+", [7, "comparePoint", "y"]]]]], [10, [6, [7, "std", "select"], [[6, [7, "d", "u32"], [[5, "0"]]], [6, [7, "d", "u32"], [[5, "1"]]], [1, [8, [7, [7, [7, "gridLayout", "bound"], "ids"], "$"], "comparePointIndex"], "==", "withId"]]]]]], externalNames: ["pointToIndex", "std", "d", "gridLayout"] },
4215
+ get externals() {
4216
+ return { pointToIndex: ae, std: Ce, d: W, gridLayout: G };
4217
+ }
4218
+ }) && e.f)({})), "comparePointWithId"), hn = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4219
+ [m, m, ne, m],
4220
+ m
4221
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r, n, a) => oe(a, t + n.x, r + n.y), {
4222
+ v: 1,
4223
+ ast: { params: [{ type: "i", name: "x" }, { type: "i", name: "y" }, { type: "i", name: "comparePoint" }, { type: "i", name: "packedIds" }], body: [0, [[10, [6, "testIdInPack", ["packedIds", [1, "x", "+", [7, "comparePoint", "x"]], [1, "y", "+", [7, "comparePoint", "y"]]]]]]], externalNames: ["testIdInPack"] },
4224
+ get externals() {
4225
+ return { testIdInPack: oe };
4226
+ }
4227
+ }) && e.f)({})), "comparePointWithKindId"), fn = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T.fn(
4228
+ [m, m, ne, ne],
4229
+ m
4230
+ )(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = (t, r, n, a) => {
4231
+ const s = ae(
4232
+ t + n.x,
4233
+ r + n.y
4234
+ ), i = ae(t + a.x, r + a.y);
4235
+ return Ie(
4236
+ m(0),
4237
+ m(1),
4238
+ G.bound.ids.$[s] === G.bound.ids.$[i]
4239
+ );
4240
+ }, {
4241
+ v: 1,
4242
+ ast: { params: [{ type: "i", name: "x" }, { type: "i", name: "y" }, { type: "i", name: "comparePoint" }, { type: "i", name: "withPoint" }], body: [0, [[13, "comparePointIndex", [6, "pointToIndex", [[1, "x", "+", [7, "comparePoint", "x"]], [1, "y", "+", [7, "comparePoint", "y"]]]]], [13, "withPointIndex", [6, "pointToIndex", [[1, "x", "+", [7, "withPoint", "x"]], [1, "y", "+", [7, "withPoint", "y"]]]]], [10, [6, [7, "std", "select"], [[6, [7, "d", "u32"], [[5, "0"]]], [6, [7, "d", "u32"], [[5, "1"]]], [1, [8, [7, [7, [7, "gridLayout", "bound"], "ids"], "$"], "comparePointIndex"], "==", [8, [7, [7, [7, "gridLayout", "bound"], "ids"], "$"], "withPointIndex"]]]]]]], externalNames: ["pointToIndex", "std", "d", "gridLayout"] },
4243
+ get externals() {
4244
+ return { pointToIndex: ae, std: Ce, d: W, gridLayout: G };
4245
+ }
4246
+ }) && e.f)({})), "comparePointWithPoint"), $c = (globalThis.__TYPEGPU_AUTONAME__ ?? ((e) => e))(T["~unstable"].computeFn({
4247
+ workgroupSize: Ht,
4248
+ in: { pos: mn.globalInvocationId }
4249
+ })(((e) => (globalThis.__TYPEGPU_META__ ??= /* @__PURE__ */ new WeakMap()).set(e.f = ({ pos: t }) => {
4250
+ const r = t.x, n = t.y, a = ae(r, n), s = G.bound.colors.$[a], i = G.bound.ids.$[a], l = xe.bound.elements.$[i], o = l.ruleStart, y = l.ruleEnd;
4251
+ for (let h = o; h < y; h++) {
4252
+ const w = xe.bound.rules.$[h], b = w.accept;
4253
+ let v = m(0);
4254
+ const x = w.conditionsStart, P = w.conditionsEnd, $ = P - x;
4255
+ for (let k = x; k < P; k++) {
4256
+ const L = xe.bound.conditions.$[k], ee = L.opcode;
4257
+ if (ee === _e.COUNT_ELEMENT) {
4258
+ const H = L.checkId, se = L.countOrWithId;
4259
+ v += Bt(r, n, H, se);
4260
+ } else if (ee === _e.COUNT_POINT) {
4261
+ const H = L.checkPointOrComparePoint, se = L.countOrWithId;
4262
+ v += cn(r, n, H, se);
4263
+ } else if (ee === _e.COUNT_KIND) {
4264
+ const H = L.checkId, se = L.countOrWithId;
4265
+ v += dn(r, n, H, se);
4266
+ } else if (ee === _e.IS_ELEMENT) {
4267
+ const H = L.checkPointOrComparePoint, se = L.countOrWithId;
4268
+ v += pn(r, n, H, se);
4269
+ } else if (ee === _e.IS_POINT) {
4270
+ const H = L.checkPointOrComparePoint, se = L.withPoint;
4271
+ v += fn(r, n, H, se);
4272
+ } else if (ee === _e.IS_KIND) {
4273
+ const H = L.checkPointOrComparePoint, se = L.countOrWithId;
4274
+ v += hn(r, n, H, se);
4275
+ } else if (ee === _e.CHANCE) {
4276
+ const H = L.chance;
4277
+ Xt.seed3(
4278
+ S(
4279
+ An(_(t.xy), _(G.bound.dimensions.$.xy)),
4280
+ Gt.$
4281
+ )
4282
+ ), v += Ie(m(0), m(1), Xt.sample() < H);
4283
+ }
4284
+ }
4285
+ if (b === Ve.ALL && v === $ || b === Ve.ANY && v >= m(1) || b === Ve.ONE && v === m(1) || b === Ve.NONE && v === m(0)) {
4286
+ let k = w.toId;
4287
+ if (w.toType === Wr.POINT) {
4288
+ const ee = ae(
4289
+ r + m(w.toNeighbor.x),
4290
+ n + m(w.toNeighbor.y)
4291
+ );
4292
+ k = G.bound.ids.$[ee];
4293
+ }
4294
+ G.bound.newIds.$[a] = k, G.bound.newColors.$[a] = xe.bound.elements.$[k].color;
4295
+ return;
4296
+ }
4297
+ }
4298
+ G.bound.newIds.$[a] = i, G.bound.newColors.$[a] = s;
4299
+ }, {
4300
+ v: 1,
4301
+ ast: { params: [{ type: "d", props: [{ name: "pos", alias: "pos" }] }], body: [0, [[13, "x", [7, "pos", "x"]], [13, "y", [7, "pos", "y"]], [13, "index", [6, "pointToIndex", ["x", "y"]]], [13, "color", [8, [7, [7, [7, "gridLayout", "bound"], "colors"], "$"], "index"]], [13, "id", [8, [7, [7, [7, "gridLayout", "bound"], "ids"], "$"], "index"]], [13, "element", [8, [7, [7, [7, "automatonLayout", "bound"], "elements"], "$"], "id"]], [13, "ruleStart", [7, "element", "ruleStart"]], [13, "ruleEnd", [7, "element", "ruleEnd"]], [14, [12, "i", "ruleStart"], [1, "i", "<", "ruleEnd"], [102, "++", "i"], [0, [[13, "rule", [8, [7, [7, [7, "automatonLayout", "bound"], "rules"], "$"], "i"]], [13, "accept", [7, "rule", "accept"]], [12, "passing", [6, [7, "d", "u32"], [[5, "0"]]]], [13, "conditionsStart", [7, "rule", "conditionsStart"]], [13, "conditionsEnd", [7, "rule", "conditionsEnd"]], [13, "conditionsCount", [1, "conditionsEnd", "-", "conditionsStart"]], [14, [12, "j", "conditionsStart"], [1, "j", "<", "conditionsEnd"], [102, "++", "j"], [0, [[13, "condition", [8, [7, [7, [7, "automatonLayout", "bound"], "conditions"], "$"], "j"]], [13, "opcode", [7, "condition", "opcode"]], [11, [1, "opcode", "==", [7, "Opcode", "COUNT_ELEMENT"]], [0, [[13, "checkId", [7, "condition", "checkId"]], [13, "count", [7, "condition", "countOrWithId"]], [2, "passing", "+=", [6, "checkIdCount", ["x", "y", "checkId", "count"]]]]], [11, [1, "opcode", "==", [7, "Opcode", "COUNT_POINT"]], [0, [[13, "checkPoint", [7, "condition", "checkPointOrComparePoint"]], [13, "count", [7, "condition", "countOrWithId"]], [2, "passing", "+=", [6, "checkPointCount", ["x", "y", "checkPoint", "count"]]]]], [11, [1, "opcode", "==", [7, "Opcode", "COUNT_KIND"]], [0, [[13, "packedIds", [7, "condition", "checkId"]], [13, "count", [7, "condition", "countOrWithId"]], [2, "passing", "+=", [6, "checkIdsCount", ["x", "y", "packedIds", "count"]]]]], [11, [1, "opcode", "==", [7, "Opcode", "IS_ELEMENT"]], [0, [[13, "comparePoint", [7, "condition", "checkPointOrComparePoint"]], [13, "withId", [7, "condition", "countOrWithId"]], [2, "passing", "+=", [6, "comparePointWithId", ["x", "y", "comparePoint", "withId"]]]]], [11, [1, "opcode", "==", [7, "Opcode", "IS_POINT"]], [0, [[13, "comparePoint", [7, "condition", "checkPointOrComparePoint"]], [13, "withPoint", [7, "condition", "withPoint"]], [2, "passing", "+=", [6, "comparePointWithPoint", ["x", "y", "comparePoint", "withPoint"]]]]], [11, [1, "opcode", "==", [7, "Opcode", "IS_KIND"]], [0, [[13, "comparePoint", [7, "condition", "checkPointOrComparePoint"]], [13, "packedIds", [7, "condition", "countOrWithId"]], [2, "passing", "+=", [6, "comparePointWithKindId", ["x", "y", "comparePoint", "packedIds"]]]]], [11, [1, "opcode", "==", [7, "Opcode", "CHANCE"]], [0, [[13, "chance", [7, "condition", "chance"]], [6, [7, "randf", "seed3"], [[6, [7, "d", "vec3f"], [[6, [7, "std", "div"], [[6, [7, "d", "vec2f"], [[7, "pos", "xy"]]], [6, [7, "d", "vec2f"], [[7, [7, [7, [7, "gridLayout", "bound"], "dimensions"], "$"], "xy"]]]]], [7, "seed", "$"]]]]], [2, "passing", "+=", [6, [7, "std", "select"], [[6, [7, "d", "u32"], [[5, "0"]]], [6, [7, "d", "u32"], [[5, "1"]]], [1, [6, [7, "randf", "sample"], []], "<", "chance"]]]]]]]]]]]]]]]], [11, [3, [3, [3, [3, [1, "accept", "==", [7, "Accept", "ALL"]], "&&", [1, "passing", "==", "conditionsCount"]], "||", [3, [1, "accept", "==", [7, "Accept", "ANY"]], "&&", [1, "passing", ">=", [6, [7, "d", "u32"], [[5, "1"]]]]]], "||", [3, [1, "accept", "==", [7, "Accept", "ONE"]], "&&", [1, "passing", "==", [6, [7, "d", "u32"], [[5, "1"]]]]]], "||", [3, [1, "accept", "==", [7, "Accept", "NONE"]], "&&", [1, "passing", "==", [6, [7, "d", "u32"], [[5, "0"]]]]]], [0, [[12, "resolvedId", [7, "rule", "toId"]], [13, "toType", [7, "rule", "toType"]], [11, [1, "toType", "==", [7, "To", "POINT"]], [0, [[13, "pointIndex", [6, "pointToIndex", [[1, "x", "+", [6, [7, "d", "u32"], [[7, [7, "rule", "toNeighbor"], "x"]]]], [1, "y", "+", [6, [7, "d", "u32"], [[7, [7, "rule", "toNeighbor"], "y"]]]]]]], [2, "resolvedId", "=", [8, [7, [7, [7, "gridLayout", "bound"], "ids"], "$"], "pointIndex"]]]]], [2, [8, [7, [7, [7, "gridLayout", "bound"], "newIds"], "$"], "index"], "=", "resolvedId"], [2, [8, [7, [7, [7, "gridLayout", "bound"], "newColors"], "$"], "index"], "=", [7, [8, [7, [7, [7, "automatonLayout", "bound"], "elements"], "$"], "resolvedId"], "color"]], [10]]]]]]], [2, [8, [7, [7, [7, "gridLayout", "bound"], "newIds"], "$"], "index"], "=", "id"], [2, [8, [7, [7, [7, "gridLayout", "bound"], "newColors"], "$"], "index"], "=", "color"]]], externalNames: ["pointToIndex", "gridLayout", "automatonLayout", "d", "Opcode", "checkIdCount", "checkPointCount", "checkIdsCount", "comparePointWithId", "comparePointWithPoint", "comparePointWithKindId", "randf", "std", "seed", "Accept", "To"] },
4302
+ get externals() {
4303
+ return { pointToIndex: ae, gridLayout: G, automatonLayout: xe, d: W, Opcode: _e, checkIdCount: Bt, checkPointCount: cn, checkIdsCount: dn, comparePointWithId: pn, comparePointWithPoint: fn, comparePointWithKindId: hn, randf: Xt, std: Ce, seed: Gt, Accept: Ve, To: Wr };
4304
+ }
4305
+ }) && e.f)({})), "mainCompute"), Kc = ({
4306
+ canvas: e,
4307
+ automaton: t
4308
+ }) => {
4309
+ const r = T.initFromDevice({ device: Ua }), n = (globalThis.__TYPEGPU_AUTONAME__ ?? ((B) => B))(r["~unstable"].withCompute($c).createPipeline(), "pipeline");
4310
+ gt = 0, Gt = (globalThis.__TYPEGPU_AUTONAME__ ?? ((B) => B))(r.createUniform(f), "seed");
4311
+ const { width: a, height: s } = e, i = e.getContext("2d"), l = Math.ceil(a / Ht[0]), o = Math.ceil(s / Ht[1]), y = (globalThis.__TYPEGPU_AUTONAME__ ?? ((B) => B))(r.createBuffer(ne, ne(a, s)).$usage("uniform"), "dimensions"), h = (globalThis.__TYPEGPU_AUTONAME__ ?? ((B) => B))(r.createBuffer(Q(m, a * s)).$usage("storage"), "colors0"), w = (globalThis.__TYPEGPU_AUTONAME__ ?? ((B) => B))(r.createBuffer(Q(m, a * s)).$usage("storage"), "colors1"), b = (globalThis.__TYPEGPU_AUTONAME__ ?? ((B) => B))(r.createBuffer(Q(m, a * s)).$usage("storage"), "ids0"), v = (globalThis.__TYPEGPU_AUTONAME__ ?? ((B) => B))(r.createBuffer(Q(m, a * s)).$usage("storage"), "ids1"), x = new Uint32Array(a * s), P = new Uint32Array(a * s);
4312
+ for (let B = 0; B < x.length; B++) {
4313
+ const Ir = Math.random() > 0.5;
4314
+ x[B] = Ir ? 4278190080 : 4294967295, P[B] = Ir ? 0 : 1;
4315
+ }
4316
+ h.write(Array.from(x)), b.write(Array.from(P));
4317
+ const $ = (globalThis.__TYPEGPU_AUTONAME__ ?? ((B) => B))(r.createBuffer(Q(m, a * s)).$addFlags(GPUBufferUsage.MAP_READ), "colorsStagingBuffer"), k = r.createBindGroup(G, {
4318
+ dimensions: y,
4319
+ colors: h,
4320
+ newColors: w,
4321
+ ids: b,
4322
+ newIds: v
4323
+ }), L = r.createBindGroup(G, {
4324
+ dimensions: y,
4325
+ colors: w,
4326
+ newColors: h,
4327
+ ids: v,
4328
+ newIds: b
4329
+ });
4330
+ let ee = r.createBindGroup(
4331
+ xe,
4332
+ Mr(r, t)
4333
+ );
4334
+ const H = i.createImageData(a, s), se = new Uint32Array(H.data.buffer);
4335
+ return { evolve: async () => {
4336
+ Gt.write(Math.random()), n.with(xe, ee).with(G, gt % 2 === 0 ? k : L).dispatchWorkgroups(l, o), $.copyFrom(gt % 2 === 0 ? h : w), r["~unstable"].flush();
4337
+ const B = $.buffer;
4338
+ await B.mapAsync(GPUMapMode.READ), se.set(new Uint32Array(B.getMappedRange())), i.putImageData(H, 0, 0), B.unmap(), gt++;
4339
+ }, setAutomaton: ({ automaton: B }) => {
4340
+ ee = r.createBindGroup(
4341
+ xe,
4342
+ Mr(r, B)
4343
+ );
4344
+ }, tgpuRoot: r };
4345
+ };
4346
+ export {
4347
+ Kc as setup
4348
+ };