typegpu 0.2.0-alpha.0 → 0.3.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,880 +0,0 @@
1
- import { Unwrap, Parsed, ISchema } from 'typed-binary';
2
-
3
- type Return = {
4
- return: Expression | null;
5
- };
6
- type If = {
7
- /** condition */
8
- if: Expression;
9
- do: Statement;
10
- else?: Statement | undefined;
11
- };
12
- type Block = {
13
- block: Statement[];
14
- };
15
- type Let = {
16
- /** variable's identifier */
17
- let: string;
18
- eq?: Expression | undefined;
19
- };
20
- type Const = {
21
- /** variable's identifier */
22
- const: string;
23
- eq?: Expression | undefined;
24
- };
25
- type Statement = Return | If | Block | Let | Const | Expression;
26
- type BinaryOperator = '==' | '!=' | '<' | '<=' | '>' | '>=' | '<<' | '>>' | '+' | '-' | '*' | '/' | '%' | '|' | '^' | '&';
27
- type BinaryExpression = {
28
- x2: [Expression, BinaryOperator, Expression];
29
- };
30
- type AssignmentOperator = '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '<<=' | '>>=' | '|=' | '^=' | '&=' | '**=' | '||=' | '&&=';
31
- type AssignmentExpression = {
32
- x2: [Expression, AssignmentOperator, Expression];
33
- };
34
- type LogicalOperator = '&&' | '||';
35
- type LogicalExpression = {
36
- x2: [Expression, LogicalOperator, Expression];
37
- };
38
- type MemberAccess = {
39
- '.': [Expression, string];
40
- };
41
- type IndexAccess = {
42
- '[]': [Expression, Expression];
43
- };
44
- type Call = {
45
- /** function identifier */
46
- call: Expression;
47
- /** expressions passed as function arguments */
48
- args: Expression[];
49
- };
50
- /** A numeric literal */
51
- type Num = {
52
- num: string;
53
- };
54
- type Literal = Num | boolean;
55
- /** Identifiers are just strings, since string literals are rare in WGSL, and identifiers are everywhere. */
56
- type Expression = string | BinaryExpression | AssignmentExpression | LogicalExpression | MemberAccess | IndexAccess | Call | Literal;
57
-
58
- /**
59
- * Can be assigned a name. Not to be confused with
60
- * being able to HAVE a name.
61
- */
62
- interface TgpuNamable {
63
- $name(label?: string | undefined): this;
64
- }
65
-
66
- type Getter = <T>(plum: TgpuPlum<T>) => T;
67
- type Unsubscribe = () => unknown;
68
- type ExtractPlumValue<T> = T extends TgpuPlum<infer TValue> ? TValue : never;
69
- interface TgpuPlum<TValue = unknown> extends TgpuNamable {
70
- readonly __brand: 'TgpuPlum';
71
- /**
72
- * Computes the value of this plum. Circumvents the store
73
- * memoization, so use with care.
74
- */
75
- compute(get: Getter): TValue;
76
- }
77
-
78
- /**
79
- * Boolean schema representing a single WGSL bool value.
80
- * Cannot be used inside buffers as it is not host-shareable.
81
- */
82
- type Bool = TgpuData<boolean>;
83
- /**
84
- * A schema that represents a boolean value. (equivalent to `bool` in WGSL)
85
- */
86
- declare const bool: Bool;
87
- /**
88
- * Unsigned 32-bit integer schema representing a single WGSL u32 value.
89
- */
90
- type U32 = TgpuData<number> & {
91
- kind: 'u32';
92
- } & ((v: number | boolean) => number);
93
- /**
94
- * A schema that represents an unsigned 32-bit integer value. (equivalent to `u32` in WGSL)
95
- *
96
- * Can also be called to cast a value to an u32 in accordance with WGSL casting rules.
97
- *
98
- * @example
99
- * const value = u32(3.14); // 3
100
- * @example
101
- * const value = u32(-1); // 4294967295
102
- * @example
103
- * const value = u32(-3.1); // 0
104
- */
105
- declare const u32: U32;
106
- /**
107
- * Signed 32-bit integer schema representing a single WGSL i32 value.
108
- */
109
- type I32 = TgpuData<number> & {
110
- kind: 'i32';
111
- } & ((v: number | boolean) => number);
112
- /**
113
- * A schema that represents a signed 32-bit integer value. (equivalent to `i32` in WGSL)
114
- *
115
- * Can also be called to cast a value to an i32 in accordance with WGSL casting rules.
116
- *
117
- * @example
118
- * const value = i32(3.14); // 3
119
- * @example
120
- * const value = i32(-3.9); // -3
121
- * @example
122
- * const value = i32(10000000000) // 1410065408
123
- */
124
- declare const i32: I32;
125
- /**
126
- * 32-bit float schema representing a single WGSL f32 value.
127
- */
128
- type F32 = TgpuData<number> & {
129
- kind: 'f32';
130
- } & ((v: number | boolean) => number);
131
- /**
132
- * A schema that represents a 32-bit float value. (equivalent to `f32` in WGSL)
133
- *
134
- * Can also be called to cast a value to an f32.
135
- *
136
- * @example
137
- * const value = f32(true); // 1
138
- */
139
- declare const f32: F32;
140
-
141
- interface Swizzle2<T2, T3, T4> {
142
- readonly xx: T2;
143
- readonly xy: T2;
144
- readonly yx: T2;
145
- readonly yy: T2;
146
- readonly xxx: T3;
147
- readonly xxy: T3;
148
- readonly xyx: T3;
149
- readonly xyy: T3;
150
- readonly yxx: T3;
151
- readonly yxy: T3;
152
- readonly yyx: T3;
153
- readonly yyy: T3;
154
- readonly xxxx: T4;
155
- readonly xxxy: T4;
156
- readonly xxyx: T4;
157
- readonly xxyy: T4;
158
- readonly xyxx: T4;
159
- readonly xyxy: T4;
160
- readonly xyyx: T4;
161
- readonly xyyy: T4;
162
- readonly yxxx: T4;
163
- readonly yxxy: T4;
164
- readonly yxyx: T4;
165
- readonly yxyy: T4;
166
- readonly yyxx: T4;
167
- readonly yyxy: T4;
168
- readonly yyyx: T4;
169
- readonly yyyy: T4;
170
- }
171
- interface Swizzle3<T2, T3, T4> extends Swizzle2<T2, T3, T4> {
172
- readonly xz: T2;
173
- readonly yz: T2;
174
- readonly zx: T2;
175
- readonly zy: T2;
176
- readonly zz: T2;
177
- readonly xxz: T3;
178
- readonly xyz: T3;
179
- readonly xzx: T3;
180
- readonly xzy: T3;
181
- readonly xzz: T3;
182
- readonly yxz: T3;
183
- readonly yyz: T3;
184
- readonly yzx: T3;
185
- readonly yzy: T3;
186
- readonly yzz: T3;
187
- readonly zxx: T3;
188
- readonly zxy: T3;
189
- readonly zxz: T3;
190
- readonly zyx: T3;
191
- readonly zyy: T3;
192
- readonly zyz: T3;
193
- readonly zzx: T3;
194
- readonly zzy: T3;
195
- readonly zzz: T3;
196
- readonly xxxz: T4;
197
- readonly xxyz: T4;
198
- readonly xxzx: T4;
199
- readonly xxzy: T4;
200
- readonly xxzz: T4;
201
- readonly xyxz: T4;
202
- readonly xyyz: T4;
203
- readonly xyzx: T4;
204
- readonly xyzy: T4;
205
- readonly xyzz: T4;
206
- readonly xzxx: T4;
207
- readonly xzxy: T4;
208
- readonly xzxz: T4;
209
- readonly xzyx: T4;
210
- readonly xzyy: T4;
211
- readonly xzyz: T4;
212
- readonly xzzx: T4;
213
- readonly xzzy: T4;
214
- readonly xzzz: T4;
215
- readonly yxxz: T4;
216
- readonly yxyz: T4;
217
- readonly yxzx: T4;
218
- readonly yxzy: T4;
219
- readonly yxzz: T4;
220
- readonly yyxz: T4;
221
- readonly yyyz: T4;
222
- readonly yyzx: T4;
223
- readonly yyzy: T4;
224
- readonly yyzz: T4;
225
- readonly yzxx: T4;
226
- readonly yzxy: T4;
227
- readonly yzxz: T4;
228
- readonly yzyx: T4;
229
- readonly yzyy: T4;
230
- readonly yzyz: T4;
231
- readonly yzzx: T4;
232
- readonly yzzy: T4;
233
- readonly yzzz: T4;
234
- readonly zxxx: T4;
235
- readonly zxxy: T4;
236
- readonly zxxz: T4;
237
- readonly zxyx: T4;
238
- readonly zxyy: T4;
239
- readonly zxyz: T4;
240
- readonly zxzx: T4;
241
- readonly zxzy: T4;
242
- readonly zxzz: T4;
243
- readonly zyxx: T4;
244
- readonly zyxy: T4;
245
- readonly zyxz: T4;
246
- readonly zyyx: T4;
247
- readonly zyyy: T4;
248
- readonly zyyz: T4;
249
- readonly zyzx: T4;
250
- readonly zyzy: T4;
251
- readonly zyzz: T4;
252
- readonly zzxx: T4;
253
- readonly zzxy: T4;
254
- readonly zzxz: T4;
255
- readonly zzyx: T4;
256
- readonly zzyy: T4;
257
- readonly zzyz: T4;
258
- readonly zzzx: T4;
259
- readonly zzzy: T4;
260
- readonly zzzz: T4;
261
- }
262
- interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3, T4> {
263
- readonly yw: T2;
264
- readonly zw: T2;
265
- readonly wx: T2;
266
- readonly wy: T2;
267
- readonly wz: T2;
268
- readonly ww: T2;
269
- readonly xxw: T3;
270
- readonly xyw: T3;
271
- readonly xzw: T3;
272
- readonly xwx: T3;
273
- readonly xwy: T3;
274
- readonly xwz: T3;
275
- readonly xww: T3;
276
- readonly yxw: T3;
277
- readonly yyw: T3;
278
- readonly yzw: T3;
279
- readonly ywx: T3;
280
- readonly ywy: T3;
281
- readonly ywz: T3;
282
- readonly yww: T3;
283
- readonly zxw: T3;
284
- readonly zyw: T3;
285
- readonly zzw: T3;
286
- readonly zwx: T3;
287
- readonly zwy: T3;
288
- readonly zwz: T3;
289
- readonly zww: T3;
290
- readonly wxx: T3;
291
- readonly wxz: T3;
292
- readonly wxy: T3;
293
- readonly wyy: T3;
294
- readonly wyz: T3;
295
- readonly wzz: T3;
296
- readonly wwx: T3;
297
- readonly wwy: T3;
298
- readonly wwz: T3;
299
- readonly www: T3;
300
- readonly xxxw: T4;
301
- readonly xxyw: T4;
302
- readonly xxzw: T4;
303
- readonly xxwx: T4;
304
- readonly xxwy: T4;
305
- readonly xxwz: T4;
306
- readonly xxww: T4;
307
- readonly xyxw: T4;
308
- readonly xyyw: T4;
309
- readonly xyzw: T4;
310
- readonly xywx: T4;
311
- readonly xywy: T4;
312
- readonly xywz: T4;
313
- readonly xyww: T4;
314
- readonly xzxw: T4;
315
- readonly xzyw: T4;
316
- readonly xzzw: T4;
317
- readonly xzwx: T4;
318
- readonly xzwy: T4;
319
- readonly xzwz: T4;
320
- readonly xzww: T4;
321
- readonly xwxx: T4;
322
- readonly xwxy: T4;
323
- readonly xwxz: T4;
324
- readonly xwyy: T4;
325
- readonly xwyz: T4;
326
- readonly xwzz: T4;
327
- readonly xwwx: T4;
328
- readonly xwwy: T4;
329
- readonly xwwz: T4;
330
- readonly xwww: T4;
331
- readonly yxxw: T4;
332
- readonly yxyw: T4;
333
- readonly yxzw: T4;
334
- readonly yxwx: T4;
335
- readonly yxwy: T4;
336
- readonly yxwz: T4;
337
- readonly yxww: T4;
338
- readonly yyxw: T4;
339
- readonly yyyw: T4;
340
- readonly yyzw: T4;
341
- readonly yywx: T4;
342
- readonly yywy: T4;
343
- readonly yywz: T4;
344
- readonly yyww: T4;
345
- readonly yzxw: T4;
346
- readonly yzyw: T4;
347
- readonly yzzw: T4;
348
- readonly yzwx: T4;
349
- readonly yzwy: T4;
350
- readonly yzwz: T4;
351
- readonly yzww: T4;
352
- readonly ywxx: T4;
353
- readonly ywxy: T4;
354
- readonly ywxz: T4;
355
- readonly ywxw: T4;
356
- readonly ywyy: T4;
357
- readonly ywyz: T4;
358
- readonly ywzz: T4;
359
- readonly ywwx: T4;
360
- readonly ywwy: T4;
361
- readonly ywwz: T4;
362
- readonly ywww: T4;
363
- readonly zxxw: T4;
364
- readonly zxyw: T4;
365
- readonly zxzw: T4;
366
- readonly zxwx: T4;
367
- readonly zxwy: T4;
368
- readonly zxwz: T4;
369
- readonly zxww: T4;
370
- readonly zyxw: T4;
371
- readonly zyyw: T4;
372
- readonly zyzw: T4;
373
- readonly zywx: T4;
374
- readonly zywy: T4;
375
- readonly zywz: T4;
376
- readonly zyww: T4;
377
- readonly zzxw: T4;
378
- readonly zzyw: T4;
379
- readonly zzzw: T4;
380
- readonly zzwx: T4;
381
- readonly zzwy: T4;
382
- readonly zzwz: T4;
383
- readonly zzww: T4;
384
- readonly zwxx: T4;
385
- readonly zwxy: T4;
386
- readonly zwxz: T4;
387
- readonly zwxw: T4;
388
- readonly zwyy: T4;
389
- readonly zwyz: T4;
390
- readonly zwzz: T4;
391
- readonly zwwx: T4;
392
- readonly zwwy: T4;
393
- readonly zwwz: T4;
394
- readonly zwww: T4;
395
- readonly wxxx: T4;
396
- readonly wxxy: T4;
397
- readonly wxxz: T4;
398
- readonly wxxw: T4;
399
- readonly wxyx: T4;
400
- readonly wxyy: T4;
401
- readonly wxyz: T4;
402
- readonly wxyw: T4;
403
- readonly wxzx: T4;
404
- readonly wxzy: T4;
405
- readonly wxzz: T4;
406
- readonly wxzw: T4;
407
- readonly wxwx: T4;
408
- readonly wxwy: T4;
409
- readonly wxwz: T4;
410
- readonly wxww: T4;
411
- readonly wyxx: T4;
412
- readonly wyxy: T4;
413
- readonly wyxz: T4;
414
- readonly wyxw: T4;
415
- readonly wyyy: T4;
416
- readonly wyyz: T4;
417
- readonly wyzw: T4;
418
- readonly wywx: T4;
419
- readonly wywy: T4;
420
- readonly wywz: T4;
421
- readonly wyww: T4;
422
- readonly wzxx: T4;
423
- readonly wzxy: T4;
424
- readonly wzxz: T4;
425
- readonly wzxw: T4;
426
- readonly wzyy: T4;
427
- readonly wzyz: T4;
428
- readonly wzzy: T4;
429
- readonly wzzw: T4;
430
- readonly wzwx: T4;
431
- readonly wzwy: T4;
432
- readonly wzwz: T4;
433
- readonly wzww: T4;
434
- readonly wwxx: T4;
435
- readonly wwxy: T4;
436
- readonly wwxz: T4;
437
- readonly wwxw: T4;
438
- readonly wwyy: T4;
439
- readonly wwyz: T4;
440
- readonly wwzz: T4;
441
- readonly wwwx: T4;
442
- readonly wwwy: T4;
443
- readonly wwwz: T4;
444
- readonly wwww: T4;
445
- }
446
- interface vec2 extends NumberArrayView {
447
- x: number;
448
- y: number;
449
- [Symbol.iterator](): Iterator<number>;
450
- }
451
- interface vec3 extends NumberArrayView {
452
- x: number;
453
- y: number;
454
- z: number;
455
- [Symbol.iterator](): Iterator<number>;
456
- }
457
- interface vec4 extends NumberArrayView {
458
- x: number;
459
- y: number;
460
- z: number;
461
- w: number;
462
- [Symbol.iterator](): Iterator<number>;
463
- }
464
- /**
465
- * Type encompassing all available kinds of vector.
466
- */
467
- type VecKind = 'vec2f' | 'vec2i' | 'vec2u' | 'vec3f' | 'vec3i' | 'vec3u' | 'vec4f' | 'vec4i' | 'vec4u';
468
- /**
469
- * Common interface for all vector types, no matter their size and inner type.
470
- */
471
- interface vecBase {
472
- kind: VecKind;
473
- [Symbol.iterator](): Iterator<number>;
474
- }
475
- /**
476
- * Type of the `d.vec2f` object/function: vector data type schema/constructor
477
- */
478
- type Vec2f = TgpuData<vec2f> & {
479
- kind: 'vec2f';
480
- } & ((x: number, y: number) => vec2f) & ((xy: number) => vec2f) & (() => vec2f);
481
- /**
482
- * Interface representing its WGSL vector type counterpart: vec2f or vec2<f32>.
483
- * A vector with 2 elements of type d.f32
484
- */
485
- interface vec2f extends vec2, Swizzle2<vec2f, vec3f, vec4f> {
486
- /** use to distinguish between vectors of the same size on the type level */
487
- kind: 'vec2f';
488
- }
489
- /**
490
- *
491
- * Schema representing vec2f - a vector with 2 elements of type f32.
492
- * Also a constructor function for this vector value.
493
- *
494
- * @example
495
- * const vector = d.vec2f(); // (0.0, 0.0)
496
- * const vector = d.vec2f(1); // (1.0, 1.0)
497
- * const vector = d.vec2f(0.5, 0.1); // (0.5, 0.1)
498
- *
499
- * @example
500
- * const buffer = root.createBuffer(d.vec2f, d.vec2f(0, 1)); // buffer holding a d.vec2f value, with an initial value of vec2f(0, 1);
501
- */
502
- declare const vec2f: Vec2f;
503
- /**
504
- * Type of the `d.vec2i` object/function: vector data type schema/constructor
505
- */
506
- type Vec2i = TgpuData<vec2i> & {
507
- kind: 'vec2i';
508
- } & ((x: number, y: number) => vec2i) & ((xy: number) => vec2i) & (() => vec2i);
509
- /**
510
- * Interface representing its WGSL vector type counterpart: vec2i or vec2<i32>.
511
- * A vector with 2 elements of type d.i32
512
- */
513
- interface vec2i extends vec2, Swizzle2<vec2i, vec3i, vec4i> {
514
- /** use to distinguish between vectors of the same size on the type level */
515
- kind: 'vec2i';
516
- }
517
- /**
518
- *
519
- * Schema representing vec2i - a vector with 2 elements of type i32.
520
- * Also a constructor function for this vector value.
521
- *
522
- * @example
523
- * const vector = d.vec2i(); // (0, 0)
524
- * const vector = d.vec2i(1); // (1, 1)
525
- * const vector = d.vec2i(-1, 1); // (-1, 1)
526
- *
527
- * @example
528
- * const buffer = root.createBuffer(d.vec2i, d.vec2i(0, 1)); // buffer holding a d.vec2i value, with an initial value of vec2i(0, 1);
529
- */
530
- declare const vec2i: Vec2i;
531
- /**
532
- * Type of the `d.vec2u` object/function: vector data type schema/constructor
533
- */
534
- type Vec2u = TgpuData<vec2u> & {
535
- kind: 'vec2u';
536
- } & ((x: number, y: number) => vec2u) & ((xy: number) => vec2u) & (() => vec2u);
537
- /**
538
- * Interface representing its WGSL vector type counterpart: vec2u or vec2<u32>.
539
- * A vector with 2 elements of type d.u32
540
- */
541
- interface vec2u extends vec2, Swizzle2<vec2u, vec3u, vec4u> {
542
- /** use to distinguish between vectors of the same size on the type level */
543
- kind: 'vec2u';
544
- }
545
- /**
546
- *
547
- * Schema representing vec2u - a vector with 2 elements of type u32.
548
- * Also a constructor function for this vector value.
549
- *
550
- * @example
551
- * const vector = d.vec2u(); // (0, 0)
552
- * const vector = d.vec2u(1); // (1, 1)
553
- * const vector = d.vec2u(1, 2); // (1, 2)
554
- *
555
- * @example
556
- * const buffer = root.createBuffer(d.vec2u, d.vec2u(0, 1)); // buffer holding a d.vec2u value, with an initial value of vec2u(0, 1);
557
- */
558
- declare const vec2u: Vec2u;
559
- /**
560
- * Type of the `d.vec3f` object/function: vector data type schema/constructor
561
- */
562
- type Vec3f = TgpuData<vec3f> & {
563
- kind: 'vec3f';
564
- } & ((x: number, y: number, z: number) => vec3f) & ((xyz: number) => vec3f) & (() => vec3f);
565
- /**
566
- * Interface representing its WGSL vector type counterpart: vec3f or vec3<f32>.
567
- * A vector with 3 elements of type d.f32
568
- */
569
- interface vec3f extends vec3, Swizzle3<vec2f, vec3f, vec4f> {
570
- /** use to distinguish between vectors of the same size on the type level */
571
- kind: 'vec3f';
572
- }
573
- /**
574
- *
575
- * Schema representing vec3f - a vector with 3 elements of type f32.
576
- * Also a constructor function for this vector value.
577
- *
578
- * @example
579
- * const vector = d.vec3f(); // (0.0, 0.0, 0.0)
580
- * const vector = d.vec3f(1); // (1.0, 1.0, 1.0)
581
- * const vector = d.vec3f(1, 2, 3.5); // (1.0, 2.0, 3.5)
582
- *
583
- * @example
584
- * const buffer = root.createBuffer(d.vec3f, d.vec3f(0, 1, 2)); // buffer holding a d.vec3f value, with an initial value of vec3f(0, 1, 2);
585
- */
586
- declare const vec3f: Vec3f;
587
- /**
588
- * Type of the `d.vec3i` object/function: vector data type schema/constructor
589
- */
590
- type Vec3i = TgpuData<vec3i> & {
591
- kind: 'vec3i';
592
- } & ((x: number, y: number, z: number) => vec3i) & ((xyz: number) => vec3i) & (() => vec3i);
593
- /**
594
- * Interface representing its WGSL vector type counterpart: vec3i or vec3<i32>.
595
- * A vector with 3 elements of type d.i32
596
- */
597
- interface vec3i extends vec3, Swizzle3<vec2i, vec3i, vec4i> {
598
- /** use to distinguish between vectors of the same size on the type level */
599
- kind: 'vec3i';
600
- }
601
- /**
602
- *
603
- * Schema representing vec3i - a vector with 3 elements of type i32.
604
- * Also a constructor function for this vector value.
605
- *
606
- * @example
607
- * const vector = d.vec3i(); // (0, 0, 0)
608
- * const vector = d.vec3i(1); // (1, 1, 1)
609
- * const vector = d.vec3i(1, 2, -3); // (1, 2, -3)
610
- *
611
- * @example
612
- * const buffer = root.createBuffer(d.vec3i, d.vec3i(0, 1, 2)); // buffer holding a d.vec3i value, with an initial value of vec3i(0, 1, 2);
613
- */
614
- declare const vec3i: Vec3i;
615
- /**
616
- * Type of the `d.vec3u` object/function: vector data type schema/constructor
617
- */
618
- type Vec3u = TgpuData<vec3u> & {
619
- kind: 'vec3u';
620
- } & ((x: number, y: number, z: number) => vec3u) & ((xyz: number) => vec3u) & (() => vec3u);
621
- /**
622
- * Interface representing its WGSL vector type counterpart: vec3u or vec3<u32>.
623
- * A vector with 3 elements of type d.u32
624
- */
625
- interface vec3u extends vec3, Swizzle3<vec2u, vec3u, vec4u> {
626
- /** use to distinguish between vectors of the same size on the type level */
627
- kind: 'vec3u';
628
- }
629
- /**
630
- *
631
- * Schema representing vec3u - a vector with 3 elements of type u32.
632
- * Also a constructor function for this vector value.
633
- *
634
- * @example
635
- * const vector = d.vec3u(); // (0, 0, 0)
636
- * const vector = d.vec3u(1); // (1, 1, 1)
637
- * const vector = d.vec3u(1, 2, 3); // (1, 2, 3)
638
- *
639
- * @example
640
- * const buffer = root.createBuffer(d.vec3u, d.vec3u(0, 1, 2)); // buffer holding a d.vec3u value, with an initial value of vec3u(0, 1, 2);
641
- */
642
- declare const vec3u: Vec3u;
643
- /**
644
- * Type of the `d.vec4f` object/function: vector data type schema/constructor
645
- */
646
- type Vec4f = TgpuData<vec4f> & {
647
- kind: 'vec4f';
648
- } & ((x: number, y: number, z: number, w: number) => vec4f) & ((xyzw: number) => vec4f) & (() => vec4f);
649
- /**
650
- * Interface representing its WGSL vector type counterpart: vec4f or vec4<f32>.
651
- * A vector with 4 elements of type d.f32
652
- */
653
- interface vec4f extends vec4, Swizzle4<vec2f, vec3f, vec4f> {
654
- /** use to distinguish between vectors of the same size on the type level */
655
- kind: 'vec4f';
656
- }
657
- /**
658
- *
659
- * Schema representing vec4f - a vector with 4 elements of type f32.
660
- * Also a constructor function for this vector value.
661
- *
662
- * @example
663
- * const vector = d.vec4f(); // (0.0, 0.0, 0.0, 0.0)
664
- * const vector = d.vec4f(1); // (1.0, 1.0, 1.0, 1.0)
665
- * const vector = d.vec4f(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
666
- *
667
- * @example
668
- * const buffer = root.createBuffer(d.vec4f, d.vec4f(0, 1, 2, 3)); // buffer holding a d.vec4f value, with an initial value of vec4f(0, 1, 2, 3);
669
- */
670
- declare const vec4f: Vec4f;
671
- /**
672
- * Type of the `d.vec4i` object/function: vector data type schema/constructor
673
- */
674
- type Vec4i = TgpuData<vec4i> & {
675
- kind: 'vec4i';
676
- } & ((x: number, y: number, z: number, w: number) => vec4i) & ((xyzw: number) => vec4i) & (() => vec4i);
677
- /**
678
- * Interface representing its WGSL vector type counterpart: vec4i or vec4<i32>.
679
- * A vector with 4 elements of type d.i32
680
- */
681
- interface vec4i extends vec4, Swizzle4<vec2i, vec3i, vec4i> {
682
- /** use to distinguish between vectors of the same size on the type level */
683
- kind: 'vec4i';
684
- }
685
- /**
686
- *
687
- * Schema representing vec4i - a vector with 4 elements of type i32.
688
- * Also a constructor function for this vector value.
689
- *
690
- * @example
691
- * const vector = d.vec4i(); // (0, 0, 0, 0)
692
- * const vector = d.vec4i(1); // (1, 1, 1, 1)
693
- * const vector = d.vec4i(1, 2, 3, -4); // (1, 2, 3, -4)
694
- *
695
- * @example
696
- * const buffer = root.createBuffer(d.vec4i, d.vec4i(0, 1, 2, 3)); // buffer holding a d.vec4i value, with an initial value of vec4i(0, 1, 2, 3);
697
- */
698
- declare const vec4i: Vec4i;
699
- /**
700
- * Type of the `d.vec4u` object/function: vector data type schema/constructor
701
- */
702
- type Vec4u = TgpuData<vec4u> & {
703
- kind: 'vec4u';
704
- } & ((x: number, y: number, z: number, w: number) => vec4u) & ((xyzw: number) => vec4u) & (() => vec4u);
705
- /**
706
- * Interface representing its WGSL vector type counterpart: vec4u or vec4<u32>.
707
- * A vector with 4 elements of type d.u32
708
- */
709
- interface vec4u extends vec4, Swizzle4<vec2u, vec3u, vec4u> {
710
- /** use to distinguish between vectors of the same size on the type level */
711
- kind: 'vec4u';
712
- }
713
- /**
714
- *
715
- * Schema representing vec4u - a vector with 4 elements of type u32.
716
- * Also a constructor function for this vector value.
717
- *
718
- * @example
719
- * const vector = d.vec4u(); // (0, 0, 0, 0)
720
- * const vector = d.vec4u(1); // (1, 1, 1, 1)
721
- * const vector = d.vec4u(1, 2, 3, 4); // (1, 2, 3, 4)
722
- *
723
- * @example
724
- * const buffer = root.createBuffer(d.vec4u, d.vec4u(0, 1, 2, 3)); // buffer holding a d.vec4u value, with an initial value of vec4u(0, 1, 2, 3);
725
- */
726
- declare const vec4u: Vec4u;
727
-
728
- interface TgpuBufferUniform<TData extends AnyTgpuData> extends TgpuBindable<TData, 'uniform'> {
729
- readonly resourceType: 'buffer-usage';
730
- readonly value: Unwrap<TData>;
731
- }
732
- interface TgpuBufferReadonly<TData extends AnyTgpuData> extends TgpuBindable<TData, 'readonly'> {
733
- readonly resourceType: 'buffer-usage';
734
- readonly value: Unwrap<TData>;
735
- }
736
- interface TgpuBufferMutable<TData extends AnyTgpuData> extends TgpuBindable<TData, 'mutable'> {
737
- readonly resourceType: 'buffer-usage';
738
- value: Unwrap<TData>;
739
- }
740
- interface TgpuBufferUsage<TData extends AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuBindable<TData, TUsage> {
741
- readonly resourceType: 'buffer-usage';
742
- value: Unwrap<TData>;
743
- }
744
-
745
- interface Uniform {
746
- usableAsUniform: true;
747
- }
748
- declare const Uniform: Uniform;
749
- interface Storage {
750
- usableAsStorage: true;
751
- }
752
- declare const Storage: Storage;
753
- interface Vertex {
754
- usableAsVertex: true;
755
- }
756
- declare const Vertex: Vertex;
757
- type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
758
- type LiteralToUsageType<T extends 'uniform' | 'storage' | 'vertex'> = T extends 'uniform' ? Uniform : T extends 'storage' ? Storage : T extends 'vertex' ? Vertex : never;
759
- interface TgpuBuffer<TData extends AnyTgpuData> extends TgpuNamable {
760
- readonly resourceType: 'buffer';
761
- readonly dataType: TData;
762
- readonly initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined;
763
- readonly label: string | undefined;
764
- readonly buffer: GPUBuffer;
765
- readonly device: GPUDevice;
766
- readonly destroyed: boolean;
767
- $usage<T extends ('uniform' | 'storage' | 'vertex')[]>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
768
- $addFlags(flags: GPUBufferUsageFlags): this;
769
- $device(device: GPUDevice): this;
770
- write(data: Parsed<TData> | TgpuBuffer<TData>): void;
771
- read(): Promise<Parsed<TData>>;
772
- destroy(): void;
773
- }
774
- declare function isUsableAsUniform<T extends TgpuBuffer<AnyTgpuData>>(buffer: T): buffer is T & Uniform;
775
- declare function isUsableAsStorage<T extends TgpuBuffer<AnyTgpuData>>(buffer: T): buffer is T & Storage;
776
- declare function isUsableAsVertex<T extends TgpuBuffer<AnyTgpuData>>(buffer: T): buffer is T & Vertex;
777
-
778
- interface TgpuFnShellBase<Args extends AnyTgpuData[], Return extends AnyTgpuData | undefined> {
779
- readonly argTypes: Args;
780
- readonly returnType: Return | undefined;
781
- }
782
-
783
- type Wgsl = string | number | TgpuResolvable | symbol | boolean;
784
- type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
785
- interface NumberArrayView {
786
- readonly length: number;
787
- [n: number]: number;
788
- }
789
- /**
790
- * Removes properties from record type that extend `Prop`
791
- */
792
- type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, {
793
- [Key in keyof T]: T[Key] extends Prop ? never : Key;
794
- }[keyof T]>;
795
- /**
796
- * Passed into each resolvable item. All sibling items share a resolution ctx,
797
- * and a new resolution ctx is made when going down each level in the tree.
798
- */
799
- interface ResolutionCtx {
800
- addDeclaration(item: TgpuResolvable): void;
801
- addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;
802
- addRenderResource(resource: TgpuRenderResource, identifier: TgpuIdentifier): void;
803
- addBuiltin(builtin: symbol): void;
804
- nameFor(token: TgpuResolvable): string;
805
- /**
806
- * Unwraps all layers of slot indirection and returns the concrete value if available.
807
- * @throws {MissingSlotValueError}
808
- */
809
- unwrap<T>(eventual: Eventual<T>): T;
810
- resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
811
- transpileFn(fn: string): {
812
- argNames: string[];
813
- body: Block;
814
- externalNames: string[];
815
- };
816
- fnToWgsl(shell: TgpuFnShellBase<any, AnyTgpuData | undefined>, argNames: string[], body: Block, externalMap: Record<string, unknown>): {
817
- head: Wgsl;
818
- body: Wgsl;
819
- };
820
- }
821
- interface TgpuResolvable {
822
- readonly label?: string | undefined;
823
- resolve(ctx: ResolutionCtx): string;
824
- }
825
- interface TgpuIdentifier extends TgpuNamable, TgpuResolvable {
826
- }
827
- /**
828
- * Represents a value that is available at resolution time.
829
- */
830
- type Eventual<T> = T | TgpuSlot<T>;
831
- type SlotValuePair<T> = [TgpuSlot<T>, T];
832
- interface TgpuBindable<TData extends AnyTgpuData = AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuResolvable {
833
- readonly allocatable: TgpuBuffer<TData>;
834
- readonly usage: TUsage;
835
- }
836
- type TgpuSamplerType = 'sampler' | 'sampler_comparison';
837
- type TgpuTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
838
- type TgpuDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
839
- type TgpuStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
840
- type TgpuExternalTextureType = 'texture_external';
841
- type TgpuRenderResourceType = TgpuSamplerType | TgpuTypedTextureType | TgpuDepthTextureType | TgpuStorageTextureType | TgpuExternalTextureType;
842
- interface TgpuRenderResource extends TgpuResolvable {
843
- readonly type: TgpuRenderResourceType;
844
- }
845
- type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
846
- type ValueOf<T> = T extends TgpuSlot<infer I> ? ValueOf<I> : T extends TgpuBufferUsage<infer D> ? ValueOf<D> : T extends TgpuData<unknown> ? Unwrap<T> : T;
847
- interface TgpuData<TInner> extends ISchema<TInner>, TgpuResolvable {
848
- readonly isLoose: false;
849
- readonly byteAlignment: number;
850
- readonly size: number;
851
- }
852
- interface TgpuLooseData<TInner> extends ISchema<TInner> {
853
- readonly isLoose: true;
854
- readonly byteAlignment: number;
855
- readonly size: number;
856
- }
857
- type AnyTgpuData = TgpuData<unknown>;
858
- type AnyTgpuLooseData = TgpuLooseData<unknown>;
859
- interface TgpuPointer<TScope extends 'function', TInner extends AnyTgpuData> {
860
- readonly scope: TScope;
861
- readonly pointsTo: TInner;
862
- }
863
- interface BoundTgpuCode extends TgpuResolvable {
864
- with<T>(slot: TgpuSlot<T>, value: Eventual<T>): BoundTgpuCode;
865
- }
866
- interface TgpuCode extends BoundTgpuCode, TgpuNamable {
867
- }
868
- interface TgpuSlot<T> extends TgpuNamable {
869
- readonly __brand: 'TgpuSlot';
870
- readonly defaultValue: T | undefined;
871
- readonly label?: string | undefined;
872
- /**
873
- * Used to determine if code generated using either value `a` or `b` in place
874
- * of the slot will be equivalent. Defaults to `Object.is`.
875
- */
876
- areEqual(a: T, b: T): boolean;
877
- value: ValueOf<T>;
878
- }
879
-
880
- export { vec2u as $, type AnyTgpuData as A, type BoundTgpuCode as B, vec4f as C, type Vec2u as D, type ExtractPlumValue as E, type F32 as F, type Vec2i as G, type Vec2f as H, type I32 as I, type Vec3f as J, type Vec3u as K, type Vec3i as L, type TgpuPointer as M, type NumberArrayView as N, type OmitProps as O, type Bool as P, bool as Q, type ResolutionCtx as R, Storage as S, type TgpuRenderResource as T, Uniform as U, type Vec4u as V, u32 as W, i32 as X, f32 as Y, type VecKind as Z, vec2i as _, type TgpuNamable as a, vec4i as a0, vec4u as a1, type TgpuBuffer as b, type TgpuBufferUsage as c, type TgpuBufferUniform as d, type TgpuShaderStage as e, type TgpuBufferReadonly as f, type TgpuBufferMutable as g, type U32 as h, type Vec4i as i, type Vec4f as j, type TgpuPlum as k, type Unsubscribe as l, type TgpuCode as m, type Block as n, vec3f as o, vec3i as p, vec3u as q, type TgpuData as r, isUsableAsStorage as s, isUsableAsUniform as t, isUsableAsVertex as u, type vecBase as v, Vertex as w, type AnyTgpuLooseData as x, type TgpuLooseData as y, vec2f as z };