typegpu 0.3.4 → 0.4.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.
@@ -1,322 +1,10 @@
1
1
  /**
2
- * Type encompassing all available kinds of vector.
2
+ * Can be assigned a name. Not to be confused with
3
+ * being able to HAVE a name.
3
4
  */
4
- type VecKind = 'vec2f' | 'vec2i' | 'vec2u' | 'vec2h' | 'vec3f' | 'vec3i' | 'vec3u' | 'vec3h' | 'vec4f' | 'vec4i' | 'vec4u' | 'vec4h';
5
- /**
6
- * Type of the `d.vec2f` object/function: vector data type schema/constructor
7
- */
8
- type NativeVec2f = Vec2f & {
9
- '~exotic': Vec2f;
10
- } & ((x: number, y: number) => v2f) & ((xy: number) => v2f) & (() => v2f);
11
- /**
12
- *
13
- * Schema representing vec2f - a vector with 2 elements of type f32.
14
- * Also a constructor function for this vector value.
15
- *
16
- * @example
17
- * const vector = d.vec2f(); // (0.0, 0.0)
18
- * const vector = d.vec2f(1); // (1.0, 1.0)
19
- * const vector = d.vec2f(0.5, 0.1); // (0.5, 0.1)
20
- *
21
- * @example
22
- * const buffer = root.createBuffer(d.vec2f, d.vec2f(0, 1)); // buffer holding a d.vec2f value, with an initial value of vec2f(0, 1);
23
- */
24
- declare const vec2f: NativeVec2f;
25
- /**
26
- * Type of the `d.vec2h` object/function: vector data type schema/constructor
27
- */
28
- type NativeVec2h = Vec2h & {
29
- '~exotic': Vec2h;
30
- } & ((x: number, y: number) => v2h) & ((xy: number) => v2h) & (() => v2h);
31
- /**
32
- *
33
- * Schema representing vec2h - a vector with 2 elements of type f16.
34
- * Also a constructor function for this vector value.
35
- *
36
- * @example
37
- * const vector = d.vec2h(); // (0.0, 0.0)
38
- * const vector = d.vec2h(1); // (1.0, 1.0)
39
- * const vector = d.vec2h(0.5, 0.1); // (0.5, 0.1)
40
- *
41
- * @example
42
- * const buffer = root.createBuffer(d.vec2h, d.vec2h(0, 1)); // buffer holding a d.vec2h value, with an initial value of vec2h(0, 1);
43
- */
44
- declare const vec2h: NativeVec2h;
45
- /**
46
- * Type of the `d.vec2i` object/function: vector data type schema/constructor
47
- */
48
- type NativeVec2i = Vec2i & {
49
- '~exotic': Vec2i;
50
- } & ((x: number, y: number) => v2i) & ((xy: number) => v2i) & (() => v2i);
51
- /**
52
- *
53
- * Schema representing vec2i - a vector with 2 elements of type i32.
54
- * Also a constructor function for this vector value.
55
- *
56
- * @example
57
- * const vector = d.vec2i(); // (0, 0)
58
- * const vector = d.vec2i(1); // (1, 1)
59
- * const vector = d.vec2i(-1, 1); // (-1, 1)
60
- *
61
- * @example
62
- * const buffer = root.createBuffer(d.vec2i, d.vec2i(0, 1)); // buffer holding a d.vec2i value, with an initial value of vec2i(0, 1);
63
- */
64
- declare const vec2i: NativeVec2i;
65
- /**
66
- * Type of the `d.vec2u` object/function: vector data type schema/constructor
67
- */
68
- type NativeVec2u = Vec2u & {
69
- '~exotic': Vec2u;
70
- } & ((x: number, y: number) => v2u) & ((xy: number) => v2u) & (() => v2u);
71
- /**
72
- *
73
- * Schema representing vec2u - a vector with 2 elements of type u32.
74
- * Also a constructor function for this vector value.
75
- *
76
- * @example
77
- * const vector = d.vec2u(); // (0, 0)
78
- * const vector = d.vec2u(1); // (1, 1)
79
- * const vector = d.vec2u(1, 2); // (1, 2)
80
- *
81
- * @example
82
- * const buffer = root.createBuffer(d.vec2u, d.vec2u(0, 1)); // buffer holding a d.vec2u value, with an initial value of vec2u(0, 1);
83
- */
84
- declare const vec2u: NativeVec2u;
85
- /**
86
- * Type of the `d.vec3f` object/function: vector data type schema/constructor
87
- */
88
- type NativeVec3f = Vec3f & {
89
- '~exotic': Vec3f;
90
- } & ((x: number, y: number, z: number) => v3f) & ((xyz: number) => v3f) & (() => v3f);
91
- /**
92
- *
93
- * Schema representing vec3f - a vector with 3 elements of type f32.
94
- * Also a constructor function for this vector value.
95
- *
96
- * @example
97
- * const vector = d.vec3f(); // (0.0, 0.0, 0.0)
98
- * const vector = d.vec3f(1); // (1.0, 1.0, 1.0)
99
- * const vector = d.vec3f(1, 2, 3.5); // (1.0, 2.0, 3.5)
100
- *
101
- * @example
102
- * 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);
103
- */
104
- declare const vec3f: NativeVec3f;
105
- /**
106
- * Type of the `d.vec3h` object/function: vector data type schema/constructor
107
- */
108
- type NativeVec3h = Vec3h & {
109
- '~exotic': Vec3h;
110
- } & ((x: number, y: number, z: number) => v3h) & ((xyz: number) => v3h) & (() => v3h);
111
- /**
112
- *
113
- * Schema representing vec3h - a vector with 3 elements of type f16.
114
- * Also a constructor function for this vector value.
115
- *
116
- * @example
117
- * const vector = d.vec3h(); // (0.0, 0.0, 0.0)
118
- * const vector = d.vec3h(1); // (1.0, 1.0, 1.0)
119
- * const vector = d.vec3h(1, 2, 3.5); // (1.0, 2.0, 3.5)
120
- *
121
- * @example
122
- * const buffer = root.createBuffer(d.vec3h, d.vec3h(0, 1, 2)); // buffer holding a d.vec3h value, with an initial value of vec3h(0, 1, 2);
123
- */
124
- declare const vec3h: NativeVec3h;
125
- /**
126
- * Type of the `d.vec3i` object/function: vector data type schema/constructor
127
- */
128
- type NativeVec3i = Vec3i & {
129
- '~exotic': Vec3i;
130
- } & ((x: number, y: number, z: number) => v3i) & ((xyz: number) => v3i) & (() => v3i);
131
- /**
132
- *
133
- * Schema representing vec3i - a vector with 3 elements of type i32.
134
- * Also a constructor function for this vector value.
135
- *
136
- * @example
137
- * const vector = d.vec3i(); // (0, 0, 0)
138
- * const vector = d.vec3i(1); // (1, 1, 1)
139
- * const vector = d.vec3i(1, 2, -3); // (1, 2, -3)
140
- *
141
- * @example
142
- * 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);
143
- */
144
- declare const vec3i: NativeVec3i;
145
- /**
146
- * Type of the `d.vec3u` object/function: vector data type schema/constructor
147
- */
148
- type NativeVec3u = Vec3u & {
149
- '~exotic': Vec3u;
150
- } & ((x: number, y: number, z: number) => v3u) & ((xyz: number) => v3u) & (() => v3u);
151
- /**
152
- *
153
- * Schema representing vec3u - a vector with 3 elements of type u32.
154
- * Also a constructor function for this vector value.
155
- *
156
- * @example
157
- * const vector = d.vec3u(); // (0, 0, 0)
158
- * const vector = d.vec3u(1); // (1, 1, 1)
159
- * const vector = d.vec3u(1, 2, 3); // (1, 2, 3)
160
- *
161
- * @example
162
- * 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);
163
- */
164
- declare const vec3u: NativeVec3u;
165
- /**
166
- * Type of the `d.vec4f` object/function: vector data type schema/constructor
167
- */
168
- type NativeVec4f = Vec4f & {
169
- '~exotic': Vec4f;
170
- } & ((x: number, y: number, z: number, w: number) => v4f) & ((xyzw: number) => v4f) & (() => v4f);
171
- /**
172
- *
173
- * Schema representing vec4f - a vector with 4 elements of type f32.
174
- * Also a constructor function for this vector value.
175
- *
176
- * @example
177
- * const vector = d.vec4f(); // (0.0, 0.0, 0.0, 0.0)
178
- * const vector = d.vec4f(1); // (1.0, 1.0, 1.0, 1.0)
179
- * const vector = d.vec4f(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
180
- *
181
- * @example
182
- * 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);
183
- */
184
- declare const vec4f: NativeVec4f;
185
- /**
186
- * Type of the `d.vec4h` object/function: vector data type schema/constructor
187
- */
188
- type NativeVec4h = Vec4h & {
189
- '~exotic': Vec4h;
190
- } & ((x: number, y: number, z: number, w: number) => v4h) & ((xyzw: number) => v4h) & (() => v4h);
191
- /**
192
- *
193
- * Schema representing vec4h - a vector with 4 elements of type f16.
194
- * Also a constructor function for this vector value.
195
- *
196
- * @example
197
- * const vector = d.vec4h(); // (0.0, 0.0, 0.0, 0.0)
198
- * const vector = d.vec4h(1); // (1.0, 1.0, 1.0, 1.0)
199
- * const vector = d.vec4h(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
200
- *
201
- * @example
202
- * const buffer = root.createBuffer(d.vec4h, d.vec4h(0, 1, 2, 3)); // buffer holding a d.vec4h value, with an initial value of vec4h(0, 1, 2, 3);
203
- */
204
- declare const vec4h: NativeVec4h;
205
- /**
206
- * Type of the `d.vec4i` object/function: vector data type schema/constructor
207
- */
208
- type NativeVec4i = Vec4i & {
209
- '~exotic': Vec4i;
210
- } & ((x: number, y: number, z: number, w: number) => v4i) & ((xyzw: number) => v4i) & (() => v4i);
211
- /**
212
- *
213
- * Schema representing vec4i - a vector with 4 elements of type i32.
214
- * Also a constructor function for this vector value.
215
- *
216
- * @example
217
- * const vector = d.vec4i(); // (0, 0, 0, 0)
218
- * const vector = d.vec4i(1); // (1, 1, 1, 1)
219
- * const vector = d.vec4i(1, 2, 3, -4); // (1, 2, 3, -4)
220
- *
221
- * @example
222
- * 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);
223
- */
224
- declare const vec4i: NativeVec4i;
225
- /**
226
- * Type of the `d.vec4u` object/function: vector data type schema/constructor
227
- */
228
- type NativeVec4u = Vec4u & {
229
- '~exotic': Vec4u;
230
- } & ((x: number, y: number, z: number, w: number) => v4u) & ((xyzw: number) => v4u) & (() => v4u);
231
- /**
232
- *
233
- * Schema representing vec4u - a vector with 4 elements of type u32.
234
- * Also a constructor function for this vector value.
235
- *
236
- * @example
237
- * const vector = d.vec4u(); // (0, 0, 0, 0)
238
- * const vector = d.vec4u(1); // (1, 1, 1, 1)
239
- * const vector = d.vec4u(1, 2, 3, 4); // (1, 2, 3, 4)
240
- *
241
- * @example
242
- * 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);
243
- */
244
- declare const vec4u: NativeVec4u;
245
-
246
- /**
247
- * A schema that represents a boolean value. (equivalent to `bool` in WGSL)
248
- */
249
- declare const bool: Bool;
250
- /**
251
- * Unsigned 32-bit integer schema representing a single WGSL u32 value.
252
- */
253
- type NativeU32 = U32 & {
254
- '~exotic': U32;
255
- } & ((v: number | boolean) => number);
256
- /**
257
- * A schema that represents an unsigned 32-bit integer value. (equivalent to `u32` in WGSL)
258
- *
259
- * Can also be called to cast a value to an u32 in accordance with WGSL casting rules.
260
- *
261
- * @example
262
- * const value = u32(3.14); // 3
263
- * @example
264
- * const value = u32(-1); // 4294967295
265
- * @example
266
- * const value = u32(-3.1); // 0
267
- */
268
- declare const u32: NativeU32;
269
- /**
270
- * Signed 32-bit integer schema representing a single WGSL i32 value.
271
- */
272
- type NativeI32 = I32 & {
273
- '~exotic': I32;
274
- } & ((v: number | boolean) => number);
275
- /**
276
- * A schema that represents a signed 32-bit integer value. (equivalent to `i32` in WGSL)
277
- *
278
- * Can also be called to cast a value to an i32 in accordance with WGSL casting rules.
279
- *
280
- * @example
281
- * const value = i32(3.14); // 3
282
- * @example
283
- * const value = i32(-3.9); // -3
284
- * @example
285
- * const value = i32(10000000000) // 1410065408
286
- */
287
- declare const i32: NativeI32;
288
- /**
289
- * 32-bit float schema representing a single WGSL f32 value.
290
- */
291
- type NativeF32 = F32 & {
292
- '~exotic': F32;
293
- } & ((v: number | boolean) => number);
294
- /**
295
- * A schema that represents a 32-bit float value. (equivalent to `f32` in WGSL)
296
- *
297
- * Can also be called to cast a value to an f32.
298
- *
299
- * @example
300
- * const value = f32(true); // 1
301
- */
302
- declare const f32: NativeF32;
303
- /**
304
- * 16-bit float schema representing a single WGSL f16 value.
305
- */
306
- type NativeF16 = F16 & {
307
- '~exotic': F16;
308
- } & ((v: number | boolean) => number);
309
- /**
310
- * A schema that represents a 16-bit float value. (equivalent to `f16` in WGSL)
311
- *
312
- * Can also be called to cast a value to an f16.
313
- *
314
- * @example
315
- * const value = f16(true); // 1
316
- * @example
317
- * const value = f16(21877.5); // 21872
318
- */
319
- declare const f16: NativeF16;
5
+ interface TgpuNamable {
6
+ $name(label?: string | undefined): this;
7
+ }
320
8
 
321
9
  declare const vertexFormats: readonly ["uint8", "uint8x2", "uint8x4", "sint8", "sint8x2", "sint8x4", "unorm8", "unorm8x2", "unorm8x4", "snorm8", "snorm8x2", "snorm8x4", "uint16", "uint16x2", "uint16x4", "sint16", "sint16x2", "sint16x4", "unorm16", "unorm16x2", "unorm16x4", "snorm16", "snorm16x2", "snorm16x4", "float16", "float16x2", "float16x4", "float32", "float32x2", "float32x3", "float32x4", "uint32", "uint32x2", "uint32x3", "uint32x4", "sint32", "sint32x2", "sint32x3", "sint32x4", "unorm10-10-10-2", "unorm8x4-bgra"];
322
10
  type VertexFormat = (typeof vertexFormats)[number];
@@ -391,47 +79,47 @@ interface TgpuVertexFormatData<T extends VertexFormat> {
391
79
  readonly type: T;
392
80
  }
393
81
  declare const formatToWGSLType: {
394
- readonly uint8: NativeU32;
395
- readonly uint8x2: NativeVec2u;
396
- readonly uint8x4: NativeVec4u;
397
- readonly sint8: NativeI32;
398
- readonly sint8x2: NativeVec2i;
399
- readonly sint8x4: NativeVec4i;
400
- readonly unorm8: NativeF32;
401
- readonly unorm8x2: NativeVec2f;
402
- readonly unorm8x4: NativeVec4f;
403
- readonly snorm8: NativeF32;
404
- readonly snorm8x2: NativeVec2f;
405
- readonly snorm8x4: NativeVec4f;
406
- readonly uint16: NativeU32;
407
- readonly uint16x2: NativeVec2u;
408
- readonly uint16x4: NativeVec4u;
409
- readonly sint16: NativeI32;
410
- readonly sint16x2: NativeVec2i;
411
- readonly sint16x4: NativeVec4i;
412
- readonly unorm16: NativeF32;
413
- readonly unorm16x2: NativeVec2f;
414
- readonly unorm16x4: NativeVec4f;
415
- readonly snorm16: NativeF32;
416
- readonly snorm16x2: NativeVec2f;
417
- readonly snorm16x4: NativeVec4f;
418
- readonly float16: NativeF32;
419
- readonly float16x2: NativeVec2f;
420
- readonly float16x4: NativeVec4f;
421
- readonly float32: NativeF32;
422
- readonly float32x2: NativeVec2f;
423
- readonly float32x3: NativeVec3f;
424
- readonly float32x4: NativeVec4f;
425
- readonly uint32: NativeU32;
426
- readonly uint32x2: NativeVec2u;
427
- readonly uint32x3: NativeVec3u;
428
- readonly uint32x4: NativeVec4u;
429
- readonly sint32: NativeI32;
430
- readonly sint32x2: NativeVec2i;
431
- readonly sint32x3: NativeVec3i;
432
- readonly sint32x4: NativeVec4i;
433
- readonly 'unorm10-10-10-2': NativeVec4f;
434
- readonly 'unorm8x4-bgra': NativeVec4f;
82
+ readonly uint8: U32;
83
+ readonly uint8x2: Vec2u;
84
+ readonly uint8x4: Vec4u;
85
+ readonly sint8: I32;
86
+ readonly sint8x2: Vec2i;
87
+ readonly sint8x4: Vec4i;
88
+ readonly unorm8: F32;
89
+ readonly unorm8x2: Vec2f;
90
+ readonly unorm8x4: Vec4f;
91
+ readonly snorm8: F32;
92
+ readonly snorm8x2: Vec2f;
93
+ readonly snorm8x4: Vec4f;
94
+ readonly uint16: U32;
95
+ readonly uint16x2: Vec2u;
96
+ readonly uint16x4: Vec4u;
97
+ readonly sint16: I32;
98
+ readonly sint16x2: Vec2i;
99
+ readonly sint16x4: Vec4i;
100
+ readonly unorm16: F32;
101
+ readonly unorm16x2: Vec2f;
102
+ readonly unorm16x4: Vec4f;
103
+ readonly snorm16: F32;
104
+ readonly snorm16x2: Vec2f;
105
+ readonly snorm16x4: Vec4f;
106
+ readonly float16: F32;
107
+ readonly float16x2: Vec2f;
108
+ readonly float16x4: Vec4f;
109
+ readonly float32: F32;
110
+ readonly float32x2: Vec2f;
111
+ readonly float32x3: Vec3f;
112
+ readonly float32x4: Vec4f;
113
+ readonly uint32: U32;
114
+ readonly uint32x2: Vec2u;
115
+ readonly uint32x3: Vec3u;
116
+ readonly uint32x4: Vec4u;
117
+ readonly sint32: I32;
118
+ readonly sint32x2: Vec2i;
119
+ readonly sint32x3: Vec3i;
120
+ readonly sint32x4: Vec4i;
121
+ readonly 'unorm10-10-10-2': Vec4f;
122
+ readonly 'unorm8x4-bgra': Vec4f;
435
123
  };
436
124
  declare const packedFormats: string[];
437
125
  type uint8 = TgpuVertexFormatData<'uint8'>;
@@ -526,11 +214,15 @@ type PackedData = uint8 | uint8x2 | uint8x4 | sint8 | sint8x2 | sint8x4 | unorm8
526
214
  * unless they are explicitly decorated with the custom align attribute
527
215
  * via `d.align` function.
528
216
  */
529
- interface Disarray<TElement extends BaseWgslData = BaseWgslData> {
217
+ interface Disarray<TElement extends BaseData = BaseData> {
530
218
  readonly type: 'disarray';
531
219
  readonly elementCount: number;
532
220
  readonly elementType: TElement;
533
221
  readonly '~repr': Infer<TElement>[];
222
+ readonly '~reprPartial': {
223
+ idx: number;
224
+ value: InferPartial<TElement>;
225
+ }[];
534
226
  }
535
227
  /**
536
228
  * Struct schema constructed via `d.unstruct` function.
@@ -540,12 +232,14 @@ interface Disarray<TElement extends BaseWgslData = BaseWgslData> {
540
232
  * unless they are explicitly decorated with the custom align attribute
541
233
  * via `d.align` function.
542
234
  */
543
- interface Unstruct<TProps extends Record<string, BaseWgslData> = Record<string, BaseWgslData>> {
235
+ interface Unstruct<TProps extends Record<string, BaseData> = Record<string, BaseData>> extends TgpuNamable {
236
+ readonly label?: string | undefined;
544
237
  readonly type: 'unstruct';
545
238
  readonly propTypes: TProps;
546
239
  readonly '~repr': InferRecord<TProps>;
240
+ readonly '~reprPartial': Partial<InferPartialRecord<TProps>>;
547
241
  }
548
- interface LooseDecorated<TInner extends BaseWgslData = BaseWgslData, TAttribs extends unknown[] = unknown[]> {
242
+ interface LooseDecorated<TInner extends BaseData = BaseData, TAttribs extends unknown[] = unknown[]> {
549
243
  readonly type: 'loose-decorated';
550
244
  readonly inner: TInner;
551
245
  readonly attribs: TAttribs;
@@ -591,14 +285,22 @@ type AnyData = AnyWgslData | AnyLooseData;
591
285
  * Extracts the inferred representation of a resource.
592
286
  * @example
593
287
  * type A = Infer<F32> // => number
594
- * type B = Infer<TgpuArray<F32>> // => number[]
288
+ * type B = Infer<WgslArray<F32>> // => number[]
595
289
  */
596
290
  type Infer<T> = T extends {
597
291
  readonly '~repr': infer TRepr;
598
292
  } ? TRepr : T;
293
+ type InferPartial<T> = T extends {
294
+ readonly '~reprPartial': infer TRepr;
295
+ } ? TRepr : T extends {
296
+ readonly '~repr': infer TRepr;
297
+ } ? TRepr | undefined : T extends Record<string | number | symbol, unknown> ? InferPartialRecord<T> : T;
599
298
  type InferRecord<T extends Record<string | number | symbol, unknown>> = {
600
299
  [Key in keyof T]: Infer<T[Key]>;
601
300
  };
301
+ type InferPartialRecord<T extends Record<string | number | symbol, unknown>> = {
302
+ [Key in keyof T]: InferPartial<T[Key]>;
303
+ };
602
304
  type MemIdentity<T> = T extends {
603
305
  readonly '~memIdent': infer TMemIdent extends AnyData;
604
306
  } ? TMemIdent : T;
@@ -606,12 +308,63 @@ type MemIdentityRecord<T extends Record<string | number | symbol, unknown>> = {
606
308
  [Key in keyof T]: MemIdentity<T[Key]>;
607
309
  };
608
310
 
609
- type DecoratedLocation<T extends BaseWgslData> = Decorated<T, Location<number>[]>;
311
+ type Default<T, TDefault> = unknown extends T ? TDefault : T extends undefined ? TDefault : T;
312
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
313
+ type Prettify<T> = {
314
+ [K in keyof T]: T[K];
315
+ } & {};
316
+ /**
317
+ * Removes properties from record type that extend `Prop`
318
+ */
319
+ type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, {
320
+ [Key in keyof T]: T[Key] extends Prop ? never : Key;
321
+ }[keyof T]>;
322
+ /**
323
+ * The opposite of Readonly<T>
324
+ */
325
+ type Mutable<T> = {
326
+ -readonly [P in keyof T]: T[P];
327
+ };
328
+
329
+ /**
330
+ * Struct schema constructed via `d.struct` function.
331
+ *
332
+ * Responsible for handling reading and writing struct values
333
+ * between binary and JS representation. Takes into account
334
+ * the `byteAlignment` requirement of its members.
335
+ */
336
+ interface WgslStruct<TProps extends Record<string, BaseData> = Record<string, BaseData>> extends TgpuNamable {
337
+ (props: InferRecord<TProps>): InferRecord<TProps>;
338
+ readonly type: 'struct';
339
+ readonly label?: string | undefined;
340
+ readonly propTypes: TProps;
341
+ /** Type-token, not available at runtime */
342
+ readonly '~repr': InferRecord<TProps>;
343
+ /** Type-token, not available at runtime */
344
+ readonly '~memIdent': WgslStruct<MemIdentityRecord<TProps>>;
345
+ /** Type-token, not available at runtime */
346
+ readonly '~reprPartial': Partial<InferPartialRecord<TProps>>;
347
+ }
348
+ type AnyWgslStruct = WgslStruct<any>;
349
+ /**
350
+ * Creates a struct schema that can be used to construct GPU buffers.
351
+ * Ensures proper alignment and padding of properties (as opposed to a `d.unstruct` schema).
352
+ * The order of members matches the passed in properties object.
353
+ *
354
+ * @example
355
+ * const CircleStruct = d.struct({ radius: d.f32, pos: d.vec3f });
356
+ *
357
+ * @param props Record with `string` keys and `TgpuData` values,
358
+ * each entry describing one struct member.
359
+ */
360
+ declare function struct<TProps extends Record<string, AnyWgslData>>(props: TProps): WgslStruct<Prettify<TProps>>;
361
+
362
+ type DecoratedLocation<T extends BaseData> = Decorated<T, Location<number>[]>;
610
363
  interface NumberArrayView {
611
364
  readonly length: number;
612
365
  [n: number]: number;
613
366
  }
614
- interface BaseWgslData {
367
+ interface BaseData {
615
368
  type: string;
616
369
  /** Type-token, not available at runtime */
617
370
  readonly '~repr': unknown;
@@ -1114,122 +867,229 @@ interface Bool {
1114
867
  readonly type: 'bool';
1115
868
  readonly '~repr': boolean;
1116
869
  }
870
+ /**
871
+ * 32-bit float schema representing a single WGSL f32 value.
872
+ */
1117
873
  interface F32 {
1118
874
  readonly type: 'f32';
1119
875
  /** Type-token, not available at runtime */
1120
876
  readonly '~repr': number;
877
+ (v: number | boolean): number;
1121
878
  }
879
+ /**
880
+ * 16-bit float schema representing a single WGSL f16 value.
881
+ */
1122
882
  interface F16 {
1123
883
  readonly type: 'f16';
1124
884
  /** Type-token, not available at runtime */
1125
885
  readonly '~repr': number;
886
+ (v: number | boolean): number;
1126
887
  }
888
+ /**
889
+ * Signed 32-bit integer schema representing a single WGSL i32 value.
890
+ */
1127
891
  interface I32 {
1128
892
  readonly type: 'i32';
1129
893
  /** Type-token, not available at runtime */
1130
894
  readonly '~repr': number;
1131
895
  readonly '~memIdent': I32 | Atomic<I32> | DecoratedLocation<I32>;
896
+ (v: number | boolean): number;
1132
897
  }
898
+ /**
899
+ * Unsigned 32-bit integer schema representing a single WGSL u32 value.
900
+ */
1133
901
  interface U32 {
1134
902
  readonly type: 'u32';
1135
903
  /** Type-token, not available at runtime */
1136
904
  readonly '~repr': number;
1137
905
  readonly '~memIdent': U32 | Atomic<U32> | DecoratedLocation<U32>;
906
+ (v: number | boolean): number;
1138
907
  }
908
+ /**
909
+ * Type of the `d.vec2f` object/function: vector data type schema/constructor
910
+ */
1139
911
  interface Vec2f {
1140
912
  readonly type: 'vec2f';
1141
913
  /** Type-token, not available at runtime */
1142
914
  readonly '~repr': v2f;
915
+ (x: number, y: number): v2f;
916
+ (xy: number): v2f;
917
+ (): v2f;
1143
918
  }
919
+ /**
920
+ * Type of the `d.vec2h` object/function: vector data type schema/constructor
921
+ */
1144
922
  interface Vec2h {
1145
923
  readonly type: 'vec2h';
1146
924
  /** Type-token, not available at runtime */
1147
925
  readonly '~repr': v2h;
926
+ (x: number, y: number): v2h;
927
+ (xy: number): v2h;
928
+ (): v2h;
1148
929
  }
930
+ /**
931
+ * Type of the `d.vec2i` object/function: vector data type schema/constructor
932
+ */
1149
933
  interface Vec2i {
1150
934
  readonly type: 'vec2i';
1151
935
  /** Type-token, not available at runtime */
1152
936
  readonly '~repr': v2i;
937
+ (x: number, y: number): v2i;
938
+ (xy: number): v2i;
939
+ (): v2i;
1153
940
  }
941
+ /**
942
+ * Type of the `d.vec2u` object/function: vector data type schema/constructor
943
+ */
1154
944
  interface Vec2u {
1155
945
  readonly type: 'vec2u';
1156
946
  /** Type-token, not available at runtime */
1157
947
  readonly '~repr': v2u;
948
+ (x: number, y: number): v2u;
949
+ (xy: number): v2u;
950
+ (): v2u;
1158
951
  }
952
+ /**
953
+ * Type of the `d.vec3f` object/function: vector data type schema/constructor
954
+ */
1159
955
  interface Vec3f {
1160
956
  readonly type: 'vec3f';
1161
957
  /** Type-token, not available at runtime */
1162
958
  readonly '~repr': v3f;
959
+ (x: number, y: number, z: number): v3f;
960
+ (xyz: number): v3f;
961
+ (): v3f;
1163
962
  }
963
+ /**
964
+ * Type of the `d.vec3h` object/function: vector data type schema/constructor
965
+ */
1164
966
  interface Vec3h {
1165
967
  readonly type: 'vec3h';
1166
968
  /** Type-token, not available at runtime */
1167
969
  readonly '~repr': v3h;
970
+ (x: number, y: number, z: number): v3h;
971
+ (xyz: number): v3h;
972
+ (): v3h;
1168
973
  }
974
+ /**
975
+ * Type of the `d.vec3i` object/function: vector data type schema/constructor
976
+ */
1169
977
  interface Vec3i {
1170
978
  readonly type: 'vec3i';
1171
979
  /** Type-token, not available at runtime */
1172
980
  readonly '~repr': v3i;
981
+ (x: number, y: number, z: number): v3i;
982
+ (xyz: number): v3i;
983
+ (): v3i;
1173
984
  }
985
+ /**
986
+ * Type of the `d.vec3u` object/function: vector data type schema/constructor
987
+ */
1174
988
  interface Vec3u {
1175
989
  readonly type: 'vec3u';
1176
990
  /** Type-token, not available at runtime */
1177
991
  readonly '~repr': v3u;
992
+ (x: number, y: number, z: number): v3u;
993
+ (xyz: number): v3u;
994
+ (): v3u;
1178
995
  }
996
+ /**
997
+ * Type of the `d.vec4f` object/function: vector data type schema/constructor
998
+ */
1179
999
  interface Vec4f {
1180
1000
  readonly type: 'vec4f';
1181
1001
  /** Type-token, not available at runtime */
1182
1002
  readonly '~repr': v4f;
1003
+ (x: number, y: number, z: number, w: number): v4f;
1004
+ (xyzw: number): v4f;
1005
+ (): v4f;
1183
1006
  }
1007
+ /**
1008
+ * Type of the `d.vec4h` object/function: vector data type schema/constructor
1009
+ */
1184
1010
  interface Vec4h {
1185
1011
  readonly type: 'vec4h';
1186
1012
  /** Type-token, not available at runtime */
1187
1013
  readonly '~repr': v4h;
1014
+ (x: number, y: number, z: number, w: number): v4h;
1015
+ (xyzw: number): v4h;
1016
+ (): v4h;
1188
1017
  }
1018
+ /**
1019
+ * Type of the `d.vec4i` object/function: vector data type schema/constructor
1020
+ */
1189
1021
  interface Vec4i {
1190
1022
  readonly type: 'vec4i';
1191
1023
  /** Type-token, not available at runtime */
1192
1024
  readonly '~repr': v4i;
1025
+ (x: number, y: number, z: number, w: number): v4i;
1026
+ (xyzw: number): v4i;
1027
+ (): v4i;
1193
1028
  }
1029
+ /**
1030
+ * Type of the `d.vec4u` object/function: vector data type schema/constructor
1031
+ */
1194
1032
  interface Vec4u {
1195
1033
  readonly type: 'vec4u';
1196
1034
  /** Type-token, not available at runtime */
1197
1035
  readonly '~repr': v4u;
1036
+ (x: number, y: number, z: number, w: number): v4u;
1037
+ (xyzw: number): v4u;
1038
+ (): v4u;
1198
1039
  }
1040
+ /**
1041
+ * Type of the `d.mat2x2f` object/function: matrix data type schema/constructor
1042
+ */
1199
1043
  interface Mat2x2f {
1200
1044
  readonly type: 'mat2x2f';
1201
1045
  /** Type-token, not available at runtime */
1202
1046
  readonly '~repr': m2x2f;
1047
+ (...elements: number[]): m2x2f;
1048
+ (...columns: v2f[]): m2x2f;
1049
+ (): m2x2f;
1203
1050
  }
1051
+ /**
1052
+ * Type of the `d.mat3x3f` object/function: matrix data type schema/constructor
1053
+ */
1204
1054
  interface Mat3x3f {
1205
1055
  readonly type: 'mat3x3f';
1206
1056
  /** Type-token, not available at runtime */
1207
1057
  readonly '~repr': m3x3f;
1058
+ (...elements: number[]): m3x3f;
1059
+ (...columns: v3f[]): m3x3f;
1060
+ (): m3x3f;
1208
1061
  }
1062
+ /**
1063
+ * Type of the `d.mat4x4f` object/function: matrix data type schema/constructor
1064
+ */
1209
1065
  interface Mat4x4f {
1210
1066
  readonly type: 'mat4x4f';
1211
1067
  /** Type-token, not available at runtime */
1212
1068
  readonly '~repr': m4x4f;
1069
+ (...elements: number[]): m4x4f;
1070
+ (...columns: v4f[]): m4x4f;
1071
+ (): m4x4f;
1213
1072
  }
1214
- interface WgslStruct<TProps extends Record<string, BaseWgslData> = Record<string, BaseWgslData>> {
1215
- (props: InferRecord<TProps>): InferRecord<TProps>;
1216
- readonly type: 'struct';
1217
- readonly label?: string | undefined;
1218
- readonly propTypes: TProps;
1219
- /** Type-token, not available at runtime */
1220
- readonly '~repr': InferRecord<TProps>;
1221
- readonly '~memIdent': WgslStruct<MemIdentityRecord<TProps>>;
1222
- }
1223
- type AnyWgslStruct = WgslStruct<any>;
1224
- interface WgslArray<TElement = BaseWgslData> {
1073
+ /**
1074
+ * Array schema constructed via `d.arrayOf` function.
1075
+ *
1076
+ * Responsible for handling reading and writing array values
1077
+ * between binary and JS representation. Takes into account
1078
+ * the `byteAlignment` requirement of its elementType.
1079
+ */
1080
+ interface WgslArray<TElement extends BaseData = BaseData> {
1225
1081
  readonly type: 'array';
1226
1082
  readonly elementCount: number;
1227
1083
  readonly elementType: TElement;
1228
1084
  /** Type-token, not available at runtime */
1229
1085
  readonly '~repr': Infer<TElement>[];
1086
+ readonly '~reprPartial': {
1087
+ idx: number;
1088
+ value: InferPartial<TElement>;
1089
+ }[];
1230
1090
  readonly '~memIdent': WgslArray<MemIdentity<TElement>>;
1231
1091
  }
1232
- interface PtrFn<TInner = BaseWgslData> {
1092
+ interface PtrFn<TInner = BaseData> {
1233
1093
  readonly type: 'ptrFn';
1234
1094
  readonly inner: TInner;
1235
1095
  /** Type-token, not available at runtime */
@@ -1268,7 +1128,7 @@ interface Builtin<T extends string> {
1268
1128
  readonly type: '@builtin';
1269
1129
  readonly value: T;
1270
1130
  }
1271
- interface Decorated<TInner extends BaseWgslData = BaseWgslData, TAttribs extends unknown[] = unknown[]> {
1131
+ interface Decorated<TInner extends BaseData = BaseData, TAttribs extends unknown[] = unknown[]> {
1272
1132
  readonly type: 'decorated';
1273
1133
  readonly inner: TInner;
1274
1134
  readonly attribs: TAttribs;
@@ -1331,4 +1191,4 @@ declare function isInterpolateAttrib<T extends Interpolate<InterpolationType>>(v
1331
1191
  declare function isBuiltinAttrib<T extends Builtin<string>>(value: unknown | T): value is T;
1332
1192
  declare function isDecorated<T extends Decorated>(value: unknown | T): value is T;
1333
1193
 
1334
- export { type Mat3x3f as $, type AnyWgslData as A, type BaseWgslData as B, type PerspectiveOrLinearInterpolatableData as C, type Decorated as D, type FlatInterpolationType as E, type F32 as F, type FlatInterpolatableData as G, type LooseDecorated as H, type Infer as I, type AnyLooseData as J, type KindToAcceptedAttribMap as K, type Location as L, type MemIdentity as M, type LooseTypeLiteral as N, type WgslStruct as O, type PerspectiveOrLinearInterpolationType as P, type PtrFn as Q, type m2x2f as R, type Size as S, type TgpuVertexAttrib as T, type U32 as U, type Vec2f as V, type WgslArray as W, type m3x3f as X, type m4x4f as Y, type Mat2x2f as Z, type v2f as _, type F16 as a, sint16x2 as a$, type v3f as a0, type Mat4x4f as a1, type v4f as a2, type Atomic as a3, bool as a4, f32 as a5, f16 as a6, i32 as a7, u32 as a8, isWgslData as a9, vec4h as aA, vec4i as aB, vec4u as aC, isDisarray as aD, isUnstruct as aE, isLooseDecorated as aF, isData as aG, isLooseData as aH, type FormatToWGSLType as aI, type TgpuVertexFormatData as aJ, packedFormats as aK, uint8 as aL, uint8x2 as aM, uint8x4 as aN, sint8 as aO, sint8x2 as aP, sint8x4 as aQ, unorm8 as aR, unorm8x2 as aS, unorm8x4 as aT, snorm8 as aU, snorm8x2 as aV, snorm8x4 as aW, uint16 as aX, uint16x2 as aY, uint16x4 as aZ, sint16 as a_, isWgslArray as aa, isWgslStruct as ab, isPtrFn as ac, isAtomic as ad, isDecorated as ae, isAlignAttrib as af, isBuiltinAttrib as ag, isLocationAttrib as ah, isInterpolateAttrib as ai, isSizeAttrib as aj, type Bool as ak, type v2i as al, type v2u as am, type v3i as an, type v3u as ao, type v4i as ap, type v4u as aq, vec2f as ar, vec2h as as, vec2i as at, vec2u as au, vec3f as av, vec3h as aw, vec3i as ax, vec3u as ay, vec4f as az, type I32 as b, sint16x4 as b0, unorm16 as b1, unorm16x2 as b2, unorm16x4 as b3, snorm16 as b4, snorm16x2 as b5, snorm16x4 as b6, float16 as b7, float16x2 as b8, float16x4 as b9, float32 as ba, float32x2 as bb, float32x3 as bc, float32x4 as bd, uint32 as be, uint32x2 as bf, uint32x3 as bg, uint32x4 as bh, sint32 as bi, sint32x2 as bj, sint32x3 as bk, sint32x4 as bl, unorm10_10_10_2 as bm, unorm8x4_bgra as bn, type PackedData as bo, type VecKind as bp, type Vec3f as c, type Vec4f as d, type Vec2h as e, type Vec3h as f, type Vec4h as g, type Vec2i as h, type Vec3i as i, type Vec4i as j, type Vec2u as k, type Vec3u as l, type Vec4u as m, type AnyWgslStruct as n, type AnyData as o, type Disarray as p, type Unstruct as q, type VertexFormat as r, type KindToDefaultFormatMap as s, type WgslTypeLiteral as t, type AnyVecInstance as u, type AnyMatInstance as v, type Builtin as w, type Align as x, type Interpolate as y, type InterpolationType as z };
1194
+ export { isWgslStruct as $, type AnyWgslData as A, type BaseData as B, type AnyVecInstance as C, type Decorated as D, type AnyMatInstance as E, type F32 as F, type Bool as G, type PtrFn as H, type Infer as I, type Mat2x2f as J, type KindToAcceptedAttribMap as K, type Location as L, type Mutable as M, type Mat3x3f as N, type OmitProps as O, type Prettify as P, type Mat4x4f as Q, type m2x2f as R, type m3x3f as S, type TgpuNamable as T, type U32 as U, type Vec2f as V, type WgslArray as W, type m4x4f as X, type Atomic as Y, isWgslData as Z, isWgslArray as _, type F16 as a, float32x4 as a$, isPtrFn as a0, isAtomic as a1, isDecorated as a2, isAlignAttrib as a3, isBuiltinAttrib as a4, isLocationAttrib as a5, isInterpolateAttrib as a6, isSizeAttrib as a7, type Size as a8, type Align as a9, sint8 as aA, sint8x2 as aB, sint8x4 as aC, unorm8 as aD, unorm8x2 as aE, unorm8x4 as aF, snorm8 as aG, snorm8x2 as aH, snorm8x4 as aI, uint16 as aJ, uint16x2 as aK, uint16x4 as aL, sint16 as aM, sint16x2 as aN, sint16x4 as aO, unorm16 as aP, unorm16x2 as aQ, unorm16x4 as aR, snorm16 as aS, snorm16x2 as aT, snorm16x4 as aU, float16 as aV, float16x2 as aW, float16x4 as aX, float32 as aY, float32x2 as aZ, float32x3 as a_, type Builtin as aa, type Interpolate as ab, type v2f as ac, type v2i as ad, type v2u as ae, type v3f as af, type v3i as ag, type v3u as ah, type v4f as ai, type v4i as aj, type v4u as ak, struct as al, type LooseDecorated as am, type AnyLooseData as an, isDisarray as ao, isUnstruct as ap, isLooseDecorated as aq, isData as ar, isLooseData as as, type FormatToWGSLType as at, type TgpuVertexFormatData as au, formatToWGSLType as av, packedFormats as aw, uint8 as ax, uint8x2 as ay, uint8x4 as az, type I32 as b, uint32 as b0, uint32x2 as b1, uint32x3 as b2, uint32x4 as b3, sint32 as b4, sint32x2 as b5, sint32x3 as b6, sint32x4 as b7, unorm10_10_10_2 as b8, unorm8x4_bgra as b9, type PackedData as ba, type InterpolationType as bb, type PerspectiveOrLinearInterpolationType as bc, type PerspectiveOrLinearInterpolatableData as bd, type FlatInterpolationType as be, type FlatInterpolatableData as bf, type LooseTypeLiteral as bg, type v2h as bh, type v3h as bi, type v4h as bj, type Vec3f as c, type Vec4f as d, type Vec2h as e, type Vec3h as f, type Vec4h as g, type Vec2i as h, type Vec3i as i, type Vec4i as j, type Vec2u as k, type Vec3u as l, type Vec4u as m, type AnyWgslStruct as n, type Default as o, type UnionToIntersection as p, type Disarray as q, type Unstruct as r, type VertexFormat as s, type TgpuVertexAttrib as t, type KindToDefaultFormatMap as u, type AnyData as v, type WgslStruct as w, type InferPartial as x, type MemIdentity as y, type WgslTypeLiteral as z };