typegpu 0.3.0-alpha.7 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1814 +0,0 @@
1
- import { Block } from 'tinyest';
2
-
3
- /**
4
- * Extracts the inferred representation of a resource.
5
- * @example
6
- * type A = Infer<F32> // => number
7
- * type B = Infer<TgpuArray<F32>> // => number[]
8
- */
9
- type Infer<T> = T extends {
10
- readonly '~repr': infer TRepr;
11
- } ? TRepr : T;
12
- type InferRecord<T extends Record<string | number | symbol, unknown>> = {
13
- [Key in keyof T]: Infer<T[Key]>;
14
- };
15
-
16
- /**
17
- * A schema that represents a boolean value. (equivalent to `bool` in WGSL)
18
- */
19
- declare const bool: Bool;
20
- /**
21
- * Unsigned 32-bit integer schema representing a single WGSL u32 value.
22
- */
23
- type NativeU32 = U32 & {
24
- '~exotic': U32;
25
- } & ((v: number | boolean) => number);
26
- /**
27
- * A schema that represents an unsigned 32-bit integer value. (equivalent to `u32` in WGSL)
28
- *
29
- * Can also be called to cast a value to an u32 in accordance with WGSL casting rules.
30
- *
31
- * @example
32
- * const value = u32(3.14); // 3
33
- * @example
34
- * const value = u32(-1); // 4294967295
35
- * @example
36
- * const value = u32(-3.1); // 0
37
- */
38
- declare const u32: NativeU32;
39
- /**
40
- * Signed 32-bit integer schema representing a single WGSL i32 value.
41
- */
42
- type NativeI32 = I32 & {
43
- '~exotic': I32;
44
- } & ((v: number | boolean) => number);
45
- /**
46
- * A schema that represents a signed 32-bit integer value. (equivalent to `i32` in WGSL)
47
- *
48
- * Can also be called to cast a value to an i32 in accordance with WGSL casting rules.
49
- *
50
- * @example
51
- * const value = i32(3.14); // 3
52
- * @example
53
- * const value = i32(-3.9); // -3
54
- * @example
55
- * const value = i32(10000000000) // 1410065408
56
- */
57
- declare const i32: NativeI32;
58
- /**
59
- * 32-bit float schema representing a single WGSL f32 value.
60
- */
61
- type NativeF32 = F32 & {
62
- '~exotic': F32;
63
- } & ((v: number | boolean) => number);
64
- /**
65
- * A schema that represents a 32-bit float value. (equivalent to `f32` in WGSL)
66
- *
67
- * Can also be called to cast a value to an f32.
68
- *
69
- * @example
70
- * const value = f32(true); // 1
71
- */
72
- declare const f32: NativeF32;
73
- /**
74
- * 16-bit float schema representing a single WGSL f16 value.
75
- */
76
- type NativeF16 = F16 & {
77
- '~exotic': F16;
78
- } & ((v: number | boolean) => number);
79
- /**
80
- * A schema that represents a 16-bit float value. (equivalent to `f16` in WGSL)
81
- *
82
- * Can also be called to cast a value to an f16.
83
- *
84
- * @example
85
- * const value = f16(true); // 1
86
- * @example
87
- * const value = f16(21877.5); // 21872
88
- */
89
- declare const f16: NativeF16;
90
-
91
- /**
92
- * Can be assigned a name. Not to be confused with
93
- * being able to HAVE a name.
94
- */
95
- interface TgpuNamable {
96
- $name(label?: string | undefined): this;
97
- }
98
-
99
- type Default<T, TDefault> = unknown extends T ? TDefault : T extends undefined ? TDefault : T;
100
- type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
101
- type Prettify<T> = {
102
- [K in keyof T]: T[K];
103
- } & {};
104
- /**
105
- * Removes properties from record type that extend `Prop`
106
- */
107
- type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, {
108
- [Key in keyof T]: T[Key] extends Prop ? never : Key;
109
- }[keyof T]>;
110
-
111
- /**
112
- * Strips schema types down to their most basic forms. (native -> exotic)
113
- * This is used by schema constructors to be able to ingest native schemas (created by TypeGPU), and
114
- * spit out a type that matches non-native schemas as well.
115
- */
116
- type Exotic<T> = T extends {
117
- readonly '~exotic': infer TExotic;
118
- } ? TExotic : T;
119
- type ExoticRecord<T> = T extends Record<string | number | symbol, unknown> ? {
120
- [Key in keyof T]: Exotic<T[Key]>;
121
- } : T;
122
-
123
- /**
124
- * Type of the `d.vec2f` object/function: vector data type schema/constructor
125
- */
126
- type NativeVec2f = Vec2f & {
127
- '~exotic': Vec2f;
128
- } & ((x: number, y: number) => v2f) & ((xy: number) => v2f) & (() => v2f);
129
- /**
130
- *
131
- * Schema representing vec2f - a vector with 2 elements of type f32.
132
- * Also a constructor function for this vector value.
133
- *
134
- * @example
135
- * const vector = d.vec2f(); // (0.0, 0.0)
136
- * const vector = d.vec2f(1); // (1.0, 1.0)
137
- * const vector = d.vec2f(0.5, 0.1); // (0.5, 0.1)
138
- *
139
- * @example
140
- * const buffer = root.createBuffer(d.vec2f, d.vec2f(0, 1)); // buffer holding a d.vec2f value, with an initial value of vec2f(0, 1);
141
- */
142
- declare const vec2f: NativeVec2f;
143
- /**
144
- * Type of the `d.vec2h` object/function: vector data type schema/constructor
145
- */
146
- type NativeVec2h = Vec2h & {
147
- '~exotic': Vec2h;
148
- } & ((x: number, y: number) => v2h) & ((xy: number) => v2h) & (() => v2h);
149
- /**
150
- *
151
- * Schema representing vec2h - a vector with 2 elements of type f16.
152
- * Also a constructor function for this vector value.
153
- *
154
- * @example
155
- * const vector = d.vec2h(); // (0.0, 0.0)
156
- * const vector = d.vec2h(1); // (1.0, 1.0)
157
- * const vector = d.vec2h(0.5, 0.1); // (0.5, 0.1)
158
- *
159
- * @example
160
- * const buffer = root.createBuffer(d.vec2h, d.vec2h(0, 1)); // buffer holding a d.vec2h value, with an initial value of vec2h(0, 1);
161
- */
162
- declare const vec2h: NativeVec2h;
163
- /**
164
- * Type of the `d.vec2i` object/function: vector data type schema/constructor
165
- */
166
- type NativeVec2i = Vec2i & {
167
- '~exotic': Vec2i;
168
- } & ((x: number, y: number) => v2i) & ((xy: number) => v2i) & (() => v2i);
169
- /**
170
- *
171
- * Schema representing vec2i - a vector with 2 elements of type i32.
172
- * Also a constructor function for this vector value.
173
- *
174
- * @example
175
- * const vector = d.vec2i(); // (0, 0)
176
- * const vector = d.vec2i(1); // (1, 1)
177
- * const vector = d.vec2i(-1, 1); // (-1, 1)
178
- *
179
- * @example
180
- * const buffer = root.createBuffer(d.vec2i, d.vec2i(0, 1)); // buffer holding a d.vec2i value, with an initial value of vec2i(0, 1);
181
- */
182
- declare const vec2i: NativeVec2i;
183
- /**
184
- * Type of the `d.vec2u` object/function: vector data type schema/constructor
185
- */
186
- type NativeVec2u = Vec2u & {
187
- '~exotic': Vec2u;
188
- } & ((x: number, y: number) => v2u) & ((xy: number) => v2u) & (() => v2u);
189
- /**
190
- *
191
- * Schema representing vec2u - a vector with 2 elements of type u32.
192
- * Also a constructor function for this vector value.
193
- *
194
- * @example
195
- * const vector = d.vec2u(); // (0, 0)
196
- * const vector = d.vec2u(1); // (1, 1)
197
- * const vector = d.vec2u(1, 2); // (1, 2)
198
- *
199
- * @example
200
- * const buffer = root.createBuffer(d.vec2u, d.vec2u(0, 1)); // buffer holding a d.vec2u value, with an initial value of vec2u(0, 1);
201
- */
202
- declare const vec2u: NativeVec2u;
203
- /**
204
- * Type of the `d.vec3f` object/function: vector data type schema/constructor
205
- */
206
- type NativeVec3f = Vec3f & {
207
- '~exotic': Vec3f;
208
- } & ((x: number, y: number, z: number) => v3f) & ((xyz: number) => v3f) & (() => v3f);
209
- /**
210
- *
211
- * Schema representing vec3f - a vector with 3 elements of type f32.
212
- * Also a constructor function for this vector value.
213
- *
214
- * @example
215
- * const vector = d.vec3f(); // (0.0, 0.0, 0.0)
216
- * const vector = d.vec3f(1); // (1.0, 1.0, 1.0)
217
- * const vector = d.vec3f(1, 2, 3.5); // (1.0, 2.0, 3.5)
218
- *
219
- * @example
220
- * 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);
221
- */
222
- declare const vec3f: NativeVec3f;
223
- /**
224
- * Type of the `d.vec3h` object/function: vector data type schema/constructor
225
- */
226
- type NativeVec3h = Vec3h & {
227
- '~exotic': Vec3h;
228
- } & ((x: number, y: number, z: number) => v3h) & ((xyz: number) => v3h) & (() => v3h);
229
- /**
230
- *
231
- * Schema representing vec3h - a vector with 3 elements of type f16.
232
- * Also a constructor function for this vector value.
233
- *
234
- * @example
235
- * const vector = d.vec3h(); // (0.0, 0.0, 0.0)
236
- * const vector = d.vec3h(1); // (1.0, 1.0, 1.0)
237
- * const vector = d.vec3h(1, 2, 3.5); // (1.0, 2.0, 3.5)
238
- *
239
- * @example
240
- * 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);
241
- */
242
- declare const vec3h: NativeVec3h;
243
- /**
244
- * Type of the `d.vec3i` object/function: vector data type schema/constructor
245
- */
246
- type NativeVec3i = Vec3i & {
247
- '~exotic': Vec3i;
248
- } & ((x: number, y: number, z: number) => v3i) & ((xyz: number) => v3i) & (() => v3i);
249
- /**
250
- *
251
- * Schema representing vec3i - a vector with 3 elements of type i32.
252
- * Also a constructor function for this vector value.
253
- *
254
- * @example
255
- * const vector = d.vec3i(); // (0, 0, 0)
256
- * const vector = d.vec3i(1); // (1, 1, 1)
257
- * const vector = d.vec3i(1, 2, -3); // (1, 2, -3)
258
- *
259
- * @example
260
- * 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);
261
- */
262
- declare const vec3i: NativeVec3i;
263
- /**
264
- * Type of the `d.vec3u` object/function: vector data type schema/constructor
265
- */
266
- type NativeVec3u = Vec3u & {
267
- '~exotic': Vec3u;
268
- } & ((x: number, y: number, z: number) => v3u) & ((xyz: number) => v3u) & (() => v3u);
269
- /**
270
- *
271
- * Schema representing vec3u - a vector with 3 elements of type u32.
272
- * Also a constructor function for this vector value.
273
- *
274
- * @example
275
- * const vector = d.vec3u(); // (0, 0, 0)
276
- * const vector = d.vec3u(1); // (1, 1, 1)
277
- * const vector = d.vec3u(1, 2, 3); // (1, 2, 3)
278
- *
279
- * @example
280
- * 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);
281
- */
282
- declare const vec3u: NativeVec3u;
283
- /**
284
- * Type of the `d.vec4f` object/function: vector data type schema/constructor
285
- */
286
- type NativeVec4f = Vec4f & {
287
- '~exotic': Vec4f;
288
- } & ((x: number, y: number, z: number, w: number) => v4f) & ((xyzw: number) => v4f) & (() => v4f);
289
- /**
290
- *
291
- * Schema representing vec4f - a vector with 4 elements of type f32.
292
- * Also a constructor function for this vector value.
293
- *
294
- * @example
295
- * const vector = d.vec4f(); // (0.0, 0.0, 0.0, 0.0)
296
- * const vector = d.vec4f(1); // (1.0, 1.0, 1.0, 1.0)
297
- * const vector = d.vec4f(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
298
- *
299
- * @example
300
- * 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);
301
- */
302
- declare const vec4f: NativeVec4f;
303
- /**
304
- * Type of the `d.vec4h` object/function: vector data type schema/constructor
305
- */
306
- type NativeVec4h = Vec4h & {
307
- '~exotic': Vec4h;
308
- } & ((x: number, y: number, z: number, w: number) => v4h) & ((xyzw: number) => v4h) & (() => v4h);
309
- /**
310
- *
311
- * Schema representing vec4h - a vector with 4 elements of type f16.
312
- * Also a constructor function for this vector value.
313
- *
314
- * @example
315
- * const vector = d.vec4h(); // (0.0, 0.0, 0.0, 0.0)
316
- * const vector = d.vec4h(1); // (1.0, 1.0, 1.0, 1.0)
317
- * const vector = d.vec4h(1, 2, 3, 4.5); // (1.0, 2.0, 3.0, 4.5)
318
- *
319
- * @example
320
- * 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);
321
- */
322
- declare const vec4h: NativeVec4h;
323
- /**
324
- * Type of the `d.vec4i` object/function: vector data type schema/constructor
325
- */
326
- type NativeVec4i = Vec4i & {
327
- '~exotic': Vec4i;
328
- } & ((x: number, y: number, z: number, w: number) => v4i) & ((xyzw: number) => v4i) & (() => v4i);
329
- /**
330
- *
331
- * Schema representing vec4i - a vector with 4 elements of type i32.
332
- * Also a constructor function for this vector value.
333
- *
334
- * @example
335
- * const vector = d.vec4i(); // (0, 0, 0, 0)
336
- * const vector = d.vec4i(1); // (1, 1, 1, 1)
337
- * const vector = d.vec4i(1, 2, 3, -4); // (1, 2, 3, -4)
338
- *
339
- * @example
340
- * 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);
341
- */
342
- declare const vec4i: NativeVec4i;
343
- /**
344
- * Type of the `d.vec4u` object/function: vector data type schema/constructor
345
- */
346
- type NativeVec4u = Vec4u & {
347
- '~exotic': Vec4u;
348
- } & ((x: number, y: number, z: number, w: number) => v4u) & ((xyzw: number) => v4u) & (() => v4u);
349
- /**
350
- *
351
- * Schema representing vec4u - a vector with 4 elements of type u32.
352
- * Also a constructor function for this vector value.
353
- *
354
- * @example
355
- * const vector = d.vec4u(); // (0, 0, 0, 0)
356
- * const vector = d.vec4u(1); // (1, 1, 1, 1)
357
- * const vector = d.vec4u(1, 2, 3, 4); // (1, 2, 3, 4)
358
- *
359
- * @example
360
- * 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);
361
- */
362
- declare const vec4u: NativeVec4u;
363
-
364
- 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"];
365
- type VertexFormat = (typeof vertexFormats)[number];
366
-
367
- type FormatToWGSLType<T extends VertexFormat> = (typeof formatToWGSLType)[T];
368
- interface TgpuVertexFormatData<T extends VertexFormat> {
369
- readonly '~repr': Infer<FormatToWGSLType<T>>;
370
- readonly type: T;
371
- }
372
- declare const formatToWGSLType: {
373
- readonly uint8: NativeU32;
374
- readonly uint8x2: NativeVec2u;
375
- readonly uint8x4: NativeVec4u;
376
- readonly sint8: NativeI32;
377
- readonly sint8x2: NativeVec2i;
378
- readonly sint8x4: NativeVec4i;
379
- readonly unorm8: NativeF32;
380
- readonly unorm8x2: NativeVec2f;
381
- readonly unorm8x4: NativeVec4f;
382
- readonly snorm8: NativeF32;
383
- readonly snorm8x2: NativeVec2f;
384
- readonly snorm8x4: NativeVec4f;
385
- readonly uint16: NativeU32;
386
- readonly uint16x2: NativeVec2u;
387
- readonly uint16x4: NativeVec4u;
388
- readonly sint16: NativeI32;
389
- readonly sint16x2: NativeVec2i;
390
- readonly sint16x4: NativeVec4i;
391
- readonly unorm16: NativeF32;
392
- readonly unorm16x2: NativeVec2f;
393
- readonly unorm16x4: NativeVec4f;
394
- readonly snorm16: NativeF32;
395
- readonly snorm16x2: NativeVec2f;
396
- readonly snorm16x4: NativeVec4f;
397
- readonly float16: NativeF32;
398
- readonly float16x2: NativeVec2f;
399
- readonly float16x4: NativeVec4f;
400
- readonly float32: NativeF32;
401
- readonly float32x2: NativeVec2f;
402
- readonly float32x3: NativeVec3f;
403
- readonly float32x4: NativeVec4f;
404
- readonly uint32: NativeU32;
405
- readonly uint32x2: NativeVec2u;
406
- readonly uint32x3: NativeVec3u;
407
- readonly uint32x4: NativeVec4u;
408
- readonly sint32: NativeI32;
409
- readonly sint32x2: NativeVec2i;
410
- readonly sint32x3: NativeVec3i;
411
- readonly sint32x4: NativeVec4i;
412
- readonly 'unorm10-10-10-2': NativeVec4f;
413
- readonly 'unorm8x4-bgra': NativeVec4f;
414
- };
415
- declare const packedFormats: string[];
416
- type uint8 = TgpuVertexFormatData<'uint8'>;
417
- declare const uint8: uint8;
418
- type uint8x2 = TgpuVertexFormatData<'uint8x2'>;
419
- declare const uint8x2: uint8x2;
420
- type uint8x4 = TgpuVertexFormatData<'uint8x4'>;
421
- declare const uint8x4: uint8x4;
422
- type sint8 = TgpuVertexFormatData<'sint8'>;
423
- declare const sint8: sint8;
424
- type sint8x2 = TgpuVertexFormatData<'sint8x2'>;
425
- declare const sint8x2: sint8x2;
426
- type sint8x4 = TgpuVertexFormatData<'sint8x4'>;
427
- declare const sint8x4: sint8x4;
428
- type unorm8 = TgpuVertexFormatData<'unorm8'>;
429
- declare const unorm8: unorm8;
430
- type unorm8x2 = TgpuVertexFormatData<'unorm8x2'>;
431
- declare const unorm8x2: unorm8x2;
432
- type unorm8x4 = TgpuVertexFormatData<'unorm8x4'>;
433
- declare const unorm8x4: unorm8x4;
434
- type snorm8 = TgpuVertexFormatData<'snorm8'>;
435
- declare const snorm8: snorm8;
436
- type snorm8x2 = TgpuVertexFormatData<'snorm8x2'>;
437
- declare const snorm8x2: snorm8x2;
438
- type snorm8x4 = TgpuVertexFormatData<'snorm8x4'>;
439
- declare const snorm8x4: snorm8x4;
440
- type uint16 = TgpuVertexFormatData<'uint16'>;
441
- declare const uint16: uint16;
442
- type uint16x2 = TgpuVertexFormatData<'uint16x2'>;
443
- declare const uint16x2: uint16x2;
444
- type uint16x4 = TgpuVertexFormatData<'uint16x4'>;
445
- declare const uint16x4: uint16x4;
446
- type sint16 = TgpuVertexFormatData<'sint16'>;
447
- declare const sint16: sint16;
448
- type sint16x2 = TgpuVertexFormatData<'sint16x2'>;
449
- declare const sint16x2: sint16x2;
450
- type sint16x4 = TgpuVertexFormatData<'sint16x4'>;
451
- declare const sint16x4: sint16x4;
452
- type unorm16 = TgpuVertexFormatData<'unorm16'>;
453
- declare const unorm16: unorm16;
454
- type unorm16x2 = TgpuVertexFormatData<'unorm16x2'>;
455
- declare const unorm16x2: unorm16x2;
456
- type unorm16x4 = TgpuVertexFormatData<'unorm16x4'>;
457
- declare const unorm16x4: unorm16x4;
458
- type snorm16 = TgpuVertexFormatData<'snorm16'>;
459
- declare const snorm16: snorm16;
460
- type snorm16x2 = TgpuVertexFormatData<'snorm16x2'>;
461
- declare const snorm16x2: snorm16x2;
462
- type snorm16x4 = TgpuVertexFormatData<'snorm16x4'>;
463
- declare const snorm16x4: snorm16x4;
464
- type float16 = TgpuVertexFormatData<'float16'>;
465
- declare const float16: float16;
466
- type float16x2 = TgpuVertexFormatData<'float16x2'>;
467
- declare const float16x2: float16x2;
468
- type float16x4 = TgpuVertexFormatData<'float16x4'>;
469
- declare const float16x4: float16x4;
470
- type float32 = TgpuVertexFormatData<'float32'>;
471
- declare const float32: float32;
472
- type float32x2 = TgpuVertexFormatData<'float32x2'>;
473
- declare const float32x2: float32x2;
474
- type float32x3 = TgpuVertexFormatData<'float32x3'>;
475
- declare const float32x3: float32x3;
476
- type float32x4 = TgpuVertexFormatData<'float32x4'>;
477
- declare const float32x4: float32x4;
478
- type uint32 = TgpuVertexFormatData<'uint32'>;
479
- declare const uint32: uint32;
480
- type uint32x2 = TgpuVertexFormatData<'uint32x2'>;
481
- declare const uint32x2: uint32x2;
482
- type uint32x3 = TgpuVertexFormatData<'uint32x3'>;
483
- declare const uint32x3: uint32x3;
484
- type uint32x4 = TgpuVertexFormatData<'uint32x4'>;
485
- declare const uint32x4: uint32x4;
486
- type sint32 = TgpuVertexFormatData<'sint32'>;
487
- declare const sint32: sint32;
488
- type sint32x2 = TgpuVertexFormatData<'sint32x2'>;
489
- declare const sint32x2: sint32x2;
490
- type sint32x3 = TgpuVertexFormatData<'sint32x3'>;
491
- declare const sint32x3: sint32x3;
492
- type sint32x4 = TgpuVertexFormatData<'sint32x4'>;
493
- declare const sint32x4: sint32x4;
494
- type unorm10_10_10_2 = TgpuVertexFormatData<'unorm10-10-10-2'>;
495
- declare const unorm10_10_10_2: unorm10_10_10_2;
496
- type unorm8x4_bgra = TgpuVertexFormatData<'unorm8x4-bgra'>;
497
- declare const unorm8x4_bgra: unorm8x4_bgra;
498
- type PackedData = 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;
499
-
500
- /**
501
- * Array schema constructed via `d.disarrayOf` function.
502
- *
503
- * Useful for defining vertex buffers.
504
- * Elements in the schema are not aligned in respect to their `byteAlignment`,
505
- * unless they are explicitly decorated with the custom align attribute
506
- * via `d.align` function.
507
- */
508
- interface Disarray<TElement extends BaseWgslData = BaseWgslData> {
509
- readonly type: 'disarray';
510
- readonly elementCount: number;
511
- readonly elementType: TElement;
512
- readonly '~repr': Infer<TElement>[];
513
- }
514
- /**
515
- * Struct schema constructed via `d.unstruct` function.
516
- *
517
- * Useful for defining vertex buffers, as the standard layout restrictions do not apply.
518
- * Members are not aligned in respect to their `byteAlignment`,
519
- * unless they are explicitly decorated with the custom align attribute
520
- * via `d.align` function.
521
- */
522
- interface Unstruct<TProps extends Record<string, BaseWgslData> = Record<string, BaseWgslData>> {
523
- readonly type: 'unstruct';
524
- readonly propTypes: TProps;
525
- readonly '~repr': InferRecord<TProps>;
526
- }
527
- interface LooseDecorated<TInner extends BaseWgslData = BaseWgslData, TAttribs extends unknown[] = unknown[]> {
528
- readonly type: 'loose-decorated';
529
- readonly inner: TInner;
530
- readonly attribs: TAttribs;
531
- readonly '~repr': Infer<TInner>;
532
- }
533
- declare const looseTypeLiterals: readonly ["unstruct", "disarray", "loose-decorated", "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"];
534
- type LooseTypeLiteral = (typeof looseTypeLiterals)[number];
535
- type AnyLooseData = Disarray | Unstruct | LooseDecorated | PackedData;
536
- declare function isLooseData(data: unknown): data is AnyLooseData;
537
- /**
538
- * Checks whether the passed in value is a disarray schema,
539
- * as opposed to, e.g., a regular array schema.
540
- *
541
- * Array schemas can be used to describe uniform and storage buffers,
542
- * whereas disarray schemas cannot. Disarrays are useful for
543
- * defining vertex buffers instead.
544
- *
545
- * @example
546
- * isDisarray(d.arrayOf(d.u32, 4)) // false
547
- * isDisarray(d.disarrayOf(d.u32, 4)) // true
548
- * isDisarray(d.vec3f) // false
549
- */
550
- declare function isDisarray<T extends Disarray>(schema: T | unknown): schema is T;
551
- /**
552
- * Checks whether passed in value is a unstruct schema,
553
- * as opposed to, e.g., a struct schema.
554
- *
555
- * Struct schemas can be used to describe uniform and storage buffers,
556
- * whereas unstruct schemas cannot. Unstructs are useful for
557
- * defining vertex buffers instead.
558
- *
559
- * @example
560
- * isUnstruct(d.struct({ a: d.u32 })) // false
561
- * isUnstruct(d.unstruct({ a: d.u32 })) // true
562
- * isUnstruct(d.vec3f) // false
563
- */
564
- declare function isUnstruct<T extends Unstruct>(schema: T | unknown): schema is T;
565
- declare function isLooseDecorated<T extends LooseDecorated>(value: T | unknown): value is T;
566
- declare function isData(value: unknown): value is AnyData;
567
- type AnyData = AnyWgslData | AnyLooseData;
568
-
569
- interface Storage {
570
- usableAsStorage: true;
571
- }
572
- declare const Storage: Storage;
573
- declare function isUsableAsStorage<T>(value: T): value is T & Storage;
574
-
575
- interface NameRegistry {
576
- /**
577
- * Creates a valid WGSL identifier, each guaranteed to be unique
578
- * in the lifetime of a single resolution process.
579
- * @param primer Used in the generation process, makes the identifier more recognizable.
580
- */
581
- makeUnique(primer?: string): string;
582
- }
583
-
584
- interface TgpuComputePipeline extends TgpuNamable {
585
- readonly resourceType: 'compute-pipeline';
586
- readonly label: string | undefined;
587
- with(bindGroupLayout: TgpuBindGroupLayout, bindGroup: TgpuBindGroup): TgpuComputePipeline;
588
- dispatchWorkgroups(x: number, y?: number | undefined, z?: number | undefined): void;
589
- }
590
-
591
- type TextureProps = {
592
- size: readonly number[];
593
- format: GPUTextureFormat;
594
- viewFormats?: GPUTextureFormat[] | undefined;
595
- dimension?: GPUTextureDimension | undefined;
596
- mipLevelCount?: number | undefined;
597
- sampleCount?: number | undefined;
598
- };
599
-
600
- declare const texelFormatToChannelType: {
601
- r8unorm: F32;
602
- r8snorm: F32;
603
- r8uint: U32;
604
- r8sint: I32;
605
- r16uint: U32;
606
- r16sint: I32;
607
- r16float: F32;
608
- rg8unorm: F32;
609
- rg8snorm: F32;
610
- rg8uint: U32;
611
- rg8sint: I32;
612
- r32uint: U32;
613
- r32sint: I32;
614
- r32float: F32;
615
- rg16uint: U32;
616
- rg16sint: I32;
617
- rg16float: F32;
618
- rgba8unorm: F32;
619
- 'rgba8unorm-srgb': F32;
620
- rgba8snorm: F32;
621
- rgba8uint: U32;
622
- rgba8sint: I32;
623
- bgra8unorm: F32;
624
- 'bgra8unorm-srgb': F32;
625
- rgb9e5ufloat: F32;
626
- rgb10a2uint: U32;
627
- rgb10a2unorm: F32;
628
- rg11b10ufloat: F32;
629
- rg32uint: U32;
630
- rg32sint: I32;
631
- rg32float: F32;
632
- rgba16uint: U32;
633
- rgba16sint: I32;
634
- rgba16float: F32;
635
- rgba32uint: U32;
636
- rgba32sint: I32;
637
- rgba32float: F32;
638
- stencil8: F32;
639
- depth16unorm: F32;
640
- depth24plus: F32;
641
- 'depth24plus-stencil8': F32;
642
- depth32float: F32;
643
- 'depth32float-stencil8': F32;
644
- 'bc1-rgba-unorm': F32;
645
- 'bc1-rgba-unorm-srgb': F32;
646
- 'bc2-rgba-unorm': F32;
647
- 'bc2-rgba-unorm-srgb': F32;
648
- 'bc3-rgba-unorm': F32;
649
- 'bc3-rgba-unorm-srgb': F32;
650
- 'bc4-r-unorm': F32;
651
- 'bc4-r-snorm': F32;
652
- 'bc5-rg-unorm': F32;
653
- 'bc5-rg-snorm': F32;
654
- 'bc6h-rgb-ufloat': F32;
655
- 'bc6h-rgb-float': F32;
656
- 'bc7-rgba-unorm': F32;
657
- 'bc7-rgba-unorm-srgb': F32;
658
- 'etc2-rgb8unorm': F32;
659
- 'etc2-rgb8unorm-srgb': F32;
660
- 'etc2-rgb8a1unorm': F32;
661
- 'etc2-rgb8a1unorm-srgb': F32;
662
- 'etc2-rgba8unorm': F32;
663
- 'etc2-rgba8unorm-srgb': F32;
664
- 'eac-r11unorm': F32;
665
- 'eac-r11snorm': F32;
666
- 'eac-rg11unorm': F32;
667
- 'eac-rg11snorm': F32;
668
- 'astc-4x4-unorm': F32;
669
- 'astc-4x4-unorm-srgb': F32;
670
- 'astc-5x4-unorm': F32;
671
- 'astc-5x4-unorm-srgb': F32;
672
- 'astc-5x5-unorm': F32;
673
- 'astc-5x5-unorm-srgb': F32;
674
- 'astc-6x5-unorm': F32;
675
- 'astc-6x5-unorm-srgb': F32;
676
- 'astc-6x6-unorm': F32;
677
- 'astc-6x6-unorm-srgb': F32;
678
- 'astc-8x5-unorm': F32;
679
- 'astc-8x5-unorm-srgb': F32;
680
- 'astc-8x6-unorm': F32;
681
- 'astc-8x6-unorm-srgb': F32;
682
- 'astc-8x8-unorm': F32;
683
- 'astc-8x8-unorm-srgb': F32;
684
- 'astc-10x5-unorm': F32;
685
- 'astc-10x5-unorm-srgb': F32;
686
- 'astc-10x6-unorm': F32;
687
- 'astc-10x6-unorm-srgb': F32;
688
- 'astc-10x8-unorm': F32;
689
- 'astc-10x8-unorm-srgb': F32;
690
- 'astc-10x10-unorm': F32;
691
- 'astc-10x10-unorm-srgb': F32;
692
- 'astc-12x10-unorm': F32;
693
- 'astc-12x10-unorm-srgb': F32;
694
- 'astc-12x12-unorm': F32;
695
- 'astc-12x12-unorm-srgb': F32;
696
- };
697
- type TexelFormatToChannelType = typeof texelFormatToChannelType;
698
- type TexelFormatToStringChannels = {
699
- [Key in keyof TexelFormatToChannelType]: TexelFormatToChannelType[Key]['type'];
700
- };
701
- type KeysWithValue<T extends Record<string, unknown>, TValue> = keyof {
702
- [Key in keyof T as T[Key] extends TValue ? Key : never]: Key;
703
- };
704
- type ChannelTypeToLegalFormats = {
705
- [Key in TexelFormatToChannelType[keyof TexelFormatToChannelType]['type']]: KeysWithValue<TexelFormatToStringChannels, Key>;
706
- };
707
- type SampleTypeToStringChannelType = {
708
- float: 'f32';
709
- 'unfilterable-float': 'f32';
710
- depth: 'f32';
711
- sint: 'i32';
712
- uint: 'u32';
713
- };
714
- type ViewDimensionToDimension = {
715
- '1d': '1d';
716
- '2d': '2d';
717
- '2d-array': '2d';
718
- '3d': '3d';
719
- cube: '2d';
720
- 'cube-array': '2d';
721
- };
722
- /**
723
- * https://www.w3.org/TR/WGSL/#storage-texel-formats
724
- */
725
- type StorageTextureTexelFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm';
726
- declare const texelFormatToDataType: {
727
- readonly rgba8unorm: Vec4f;
728
- readonly rgba8snorm: Vec4f;
729
- readonly rgba8uint: Vec4u;
730
- readonly rgba8sint: Vec4i;
731
- readonly rgba16uint: Vec4u;
732
- readonly rgba16sint: Vec4i;
733
- readonly rgba16float: Vec4f;
734
- readonly r32uint: Vec4u;
735
- readonly r32sint: Vec4i;
736
- readonly r32float: Vec4f;
737
- readonly rg32uint: Vec4u;
738
- readonly rg32sint: Vec4i;
739
- readonly rg32float: Vec4f;
740
- readonly rgba32uint: Vec4u;
741
- readonly rgba32sint: Vec4i;
742
- readonly rgba32float: Vec4f;
743
- readonly bgra8unorm: Vec4f;
744
- };
745
- declare const channelFormatToSchema: {
746
- float: F32;
747
- 'unfilterable-float': F32;
748
- uint: U32;
749
- sint: I32;
750
- depth: F32;
751
- };
752
- type ChannelFormatToSchema = typeof channelFormatToSchema;
753
- type TexelFormatToDataType = typeof texelFormatToDataType;
754
- type TexelFormatToDataTypeOrNever<T> = T extends keyof TexelFormatToDataType ? TexelFormatToDataType[T] : never;
755
- /**
756
- * Represents what formats a storage view can choose from based on its owner texture's props.
757
- */
758
- type StorageFormatOptions<TProps extends TextureProps> = Extract<TProps['format'] | Default<TProps['viewFormats'], []>[number], StorageTextureTexelFormat>;
759
- /**
760
- * Represents what formats a sampled view can choose from based on its owner texture's props.
761
- */
762
- type SampledFormatOptions<TProps extends TextureProps> = TProps['format'] | Default<TProps['viewFormats'], []>[number];
763
-
764
- interface Sampled {
765
- usableAsSampled: true;
766
- }
767
- interface Render {
768
- usableAsRender: true;
769
- }
770
- type LiteralToExtensionMap = {
771
- storage: Storage;
772
- sampled: Sampled;
773
- render: Render;
774
- };
775
- type AllowedUsages<TProps extends TextureProps> = 'sampled' | 'render' | (TProps['format'] extends StorageTextureTexelFormat ? 'storage' : never);
776
-
777
- type ResolveStorageDimension<TDimension extends GPUTextureViewDimension, TProps extends TextureProps> = StorageTextureDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension extends StorageTextureDimension ? TDimension : '2d';
778
- type ViewUsages<TProps extends TextureProps, TTexture extends TgpuTexture<TProps>> = boolean extends TTexture['usableAsSampled'] ? boolean extends TTexture['usableAsStorage'] ? never : 'readonly' | 'writeonly' | 'mutable' : boolean extends TTexture['usableAsStorage'] ? 'sampled' : 'readonly' | 'writeonly' | 'mutable' | 'sampled';
779
- type ChannelData = U32 | I32 | F32;
780
- type TexelData = Vec4u | Vec4i | Vec4f;
781
- /**
782
- * @param TProps all properties that distinguish this texture apart from other textures on the type level.
783
- */
784
- interface TgpuTexture<TProps extends TextureProps = TextureProps> extends TgpuNamable {
785
- readonly resourceType: 'texture';
786
- readonly props: TProps;
787
- readonly label: string | undefined;
788
- readonly usableAsStorage: boolean;
789
- readonly usableAsSampled: boolean;
790
- readonly usableAsRender: boolean;
791
- $usage<T extends AllowedUsages<TProps>[]>(...usages: T): this & UnionToIntersection<LiteralToExtensionMap[T[number]]>;
792
- createView<TUsage extends ViewUsages<TProps, this>, TDimension extends 'sampled' extends TUsage ? GPUTextureViewDimension : StorageTextureDimension, TFormat extends 'sampled' extends TUsage ? SampledFormatOptions<TProps> : StorageFormatOptions<TProps>>(access: TUsage, params?: TextureViewParams<TDimension, TFormat>): {
793
- mutable: TgpuMutableTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
794
- readonly: TgpuReadonlyTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
795
- writeonly: TgpuWriteonlyTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
796
- sampled: TgpuSampledTexture<GPUTextureViewDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension, TexelFormatToChannelType[SampledFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat]>;
797
- }[TUsage];
798
- destroy(): void;
799
- }
800
- type StorageTextureAccess = 'readonly' | 'writeonly' | 'mutable';
801
- /**
802
- * Based on @see GPUTextureViewDimension
803
- * https://www.w3.org/TR/WGSL/#texture-depth
804
- */
805
- type StorageTextureDimension = '1d' | '2d' | '2d-array' | '3d';
806
- type TextureViewParams<TDimension extends GPUTextureViewDimension | undefined, TFormat extends GPUTextureFormat | undefined> = {
807
- format?: TFormat;
808
- dimension?: TDimension;
809
- aspect?: GPUTextureAspect;
810
- baseMipLevel?: number;
811
- mipLevelCount?: number;
812
- baseArrayLayout?: number;
813
- arrayLayerCount?: number;
814
- };
815
- interface TgpuStorageTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> {
816
- readonly resourceType: 'texture-storage-view';
817
- readonly dimension: TDimension;
818
- readonly texelDataType: TData;
819
- readonly access: StorageTextureAccess;
820
- }
821
- /**
822
- * A texture accessed as "readonly" storage on the GPU.
823
- */
824
- interface TgpuReadonlyTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData>, TgpuResolvable {
825
- readonly access: 'readonly';
826
- }
827
- /**
828
- * A texture accessed as "writeonly" storage on the GPU.
829
- */
830
- interface TgpuWriteonlyTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData>, TgpuResolvable {
831
- readonly access: 'writeonly';
832
- }
833
- /**
834
- * A texture accessed as "mutable" (or read_write) storage on the GPU.
835
- */
836
- interface TgpuMutableTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData>, TgpuResolvable {
837
- readonly access: 'mutable';
838
- }
839
- /**
840
- * A texture accessed as sampled on the GPU.
841
- */
842
- interface TgpuSampledTexture<TDimension extends GPUTextureViewDimension = GPUTextureViewDimension, TData extends ChannelData = ChannelData> extends TgpuResolvable {
843
- readonly resourceType: 'texture-sampled-view';
844
- readonly dimension: TDimension;
845
- readonly channelDataType: TData;
846
- }
847
- declare function isStorageTextureView<T extends TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture>(value: unknown | T): value is T;
848
- declare function isSampledTextureView<T extends TgpuSampledTexture>(value: unknown | T): value is T;
849
- type TgpuAnyTextureView = TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture | TgpuSampledTexture;
850
-
851
- interface Unwrapper {
852
- readonly device: GPUDevice;
853
- unwrap(resource: TgpuComputePipeline): GPUComputePipeline;
854
- unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
855
- unwrap(resource: TgpuBindGroup): GPUBindGroup;
856
- unwrap(resource: TgpuBuffer<AnyData>): GPUBuffer;
857
- unwrap(resource: TgpuTexture): GPUTexture;
858
- unwrap(resource: TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture | TgpuSampledTexture): GPUTextureView;
859
- }
860
-
861
- interface Uniform {
862
- usableAsUniform: true;
863
- }
864
- declare const Uniform: Uniform;
865
- interface Vertex {
866
- usableAsVertex: true;
867
- }
868
- declare const Vertex: Vertex;
869
- type LiteralToUsageType<T extends 'uniform' | 'storage' | 'vertex'> = T extends 'uniform' ? Uniform : T extends 'storage' ? Storage : T extends 'vertex' ? Vertex : never;
870
- interface TgpuBuffer<TData extends AnyData> extends TgpuNamable {
871
- readonly resourceType: 'buffer';
872
- readonly dataType: TData;
873
- readonly initial?: Infer<TData> | undefined;
874
- readonly label: string | undefined;
875
- readonly buffer: GPUBuffer;
876
- readonly destroyed: boolean;
877
- $usage<T extends RestrictVertexUsages<TData>>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
878
- $addFlags(flags: GPUBufferUsageFlags): this;
879
- write(data: Infer<TData>): void;
880
- copyFrom(srcBuffer: TgpuBuffer<TData>): void;
881
- read(): Promise<Infer<TData>>;
882
- destroy(): void;
883
- }
884
- declare function isBuffer<T extends TgpuBuffer<AnyData>>(value: T | unknown): value is T;
885
- declare function isUsableAsUniform<T extends TgpuBuffer<AnyData>>(buffer: T): buffer is T & Uniform;
886
- declare function isUsableAsVertex<T extends TgpuBuffer<AnyData>>(buffer: T): buffer is T & Vertex;
887
- type RestrictVertexUsages<TData extends AnyData> = TData extends {
888
- readonly type: WgslTypeLiteral;
889
- } ? ('uniform' | 'storage' | 'vertex')[] : 'vertex'[];
890
-
891
- interface TgpuSampler extends TgpuResolvable {
892
- readonly resourceType: 'sampler';
893
- }
894
- interface TgpuComparisonSampler {
895
- readonly resourceType: 'sampler-comparison';
896
- }
897
- declare function isSampler(resource: unknown): resource is TgpuSampler;
898
- declare function isComparisonSampler(resource: unknown): resource is TgpuComparisonSampler;
899
-
900
- type TgpuLayoutEntryBase = {
901
- /**
902
- * Limits this resource's visibility to specific shader stages.
903
- *
904
- * By default, each resource is visible to all shader stage types, but
905
- * depending on the underlying implementation, this may have performance implications.
906
- *
907
- * @default ['compute'] for mutable resources
908
- * @default ['compute','vertex','fragment'] for everything else
909
- */
910
- visibility?: TgpuShaderStage[];
911
- };
912
- type TgpuLayoutUniform = TgpuLayoutEntryBase & {
913
- uniform: AnyWgslData;
914
- };
915
- type TgpuLayoutStorage = TgpuLayoutEntryBase & {
916
- storage: AnyWgslData | ((arrayLength: number) => AnyWgslData);
917
- /** @default 'readonly' */
918
- access?: 'mutable' | 'readonly';
919
- };
920
- type TgpuLayoutSampler = TgpuLayoutEntryBase & {
921
- sampler: GPUSamplerBindingType;
922
- };
923
- type TgpuLayoutTexture<TSampleType extends GPUTextureSampleType = GPUTextureSampleType> = TgpuLayoutEntryBase & {
924
- /**
925
- * - 'float' - f32
926
- * - 'unfilterable-float' - f32, cannot be used with filtering samplers
927
- * - 'depth' - f32
928
- * - 'sint' - i32
929
- * - 'uint' - u32
930
- */
931
- texture: TSampleType;
932
- /**
933
- * @default '2d'
934
- */
935
- viewDimension?: GPUTextureViewDimension;
936
- /**
937
- * @default false
938
- */
939
- multisampled?: boolean;
940
- };
941
- type TgpuLayoutStorageTexture<TFormat extends StorageTextureTexelFormat = StorageTextureTexelFormat> = TgpuLayoutEntryBase & {
942
- storageTexture: TFormat;
943
- /** @default 'writeonly' */
944
- access?: 'readonly' | 'writeonly' | 'mutable';
945
- /** @default '2d' */
946
- viewDimension?: StorageTextureDimension;
947
- };
948
- type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
949
- externalTexture: Record<string, never>;
950
- };
951
- type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
952
- type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends (_: number) => BaseWgslData ? ReturnType<T> : T;
953
- type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
954
- interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
955
- readonly resourceType: 'bind-group-layout';
956
- readonly label: string | undefined;
957
- readonly entries: Entries;
958
- readonly bound: {
959
- [K in keyof Entries]: BindLayoutEntry<Entries[K]>;
960
- };
961
- /**
962
- * An explicit numeric index assigned to this bind group layout. If undefined, a unique
963
- * index is assigned automatically during resolution. This can be changed with the
964
- * `.$idx()` method.
965
- */
966
- readonly index: number | undefined;
967
- /**
968
- * Associates this bind group layout with an explicit numeric index. When a call to this
969
- * method is omitted, a unique numeric index is assigned to it automatically.
970
- *
971
- * Used when generating WGSL code: `@group(${index}) @binding(...) ...;`
972
- */
973
- $idx(index?: number): this;
974
- /**
975
- * @deprecated Use the `root.createBindGroup` API instead, accessible through `await tgpu.init()`
976
- */
977
- populate(entries: {
978
- [K in keyof OmitProps<Entries, null>]: LayoutEntryToInput<Entries[K]>;
979
- }): TgpuBindGroup<Entries>;
980
- /**
981
- * Creates a raw WebGPU resource based on the typed descriptor.
982
- * NOTE: This creates a new resource every time, better to use `root.unwrap(...)` instead.
983
- * @param unwrapper Used to unwrap any resources that this resource depends on.
984
- */
985
- unwrap(unwrapper: Unwrapper): GPUBindGroupLayout;
986
- }
987
- type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
988
- access?: infer Access;
989
- } ? 'mutable' | 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> : 'mutable' extends Access ? TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>>;
990
- type GetUsageForStorageTexture<T extends TgpuLayoutStorageTexture, TAccess extends 'readonly' | 'writeonly' | 'mutable'> = {
991
- mutable: TgpuMutableTexture<Default<GetDimension<T['viewDimension']>, '2d'>, TexelFormatToDataType[T['storageTexture']]>;
992
- readonly: TgpuReadonlyTexture<Default<GetDimension<T['viewDimension']>, '2d'>, TexelFormatToDataType[T['storageTexture']]>;
993
- writeonly: TgpuWriteonlyTexture<Default<GetDimension<T['viewDimension']>, '2d'>, TexelFormatToDataType[T['storageTexture']]>;
994
- }[TAccess];
995
- type StorageTextureUsageForEntry<T extends TgpuLayoutStorageTexture> = T extends unknown ? GetUsageForStorageTexture<T, Default<T['access'], 'writeonly'>> : never;
996
- type GetDimension<T extends GPUTextureViewDimension | undefined> = T extends keyof ViewDimensionToDimension ? ViewDimensionToDimension[T] : undefined;
997
- type GetTextureRestriction<T extends TgpuLayoutTexture> = Default<GetDimension<T['viewDimension']>, '2d'> extends infer Dimension ? Dimension extends '2d' ? {
998
- format: ChannelTypeToLegalFormats[SampleTypeToStringChannelType[T['texture']]];
999
- dimension?: Dimension;
1000
- } : {
1001
- format: ChannelTypeToLegalFormats[SampleTypeToStringChannelType[T['texture']]];
1002
- dimension: Dimension;
1003
- } : never;
1004
- type GetStorageTextureRestriction<T extends TgpuLayoutStorageTexture> = Default<GetDimension<T['viewDimension']>, '2d'> extends infer Dimension ? Dimension extends '2d' ? {
1005
- format: T['storageTexture'];
1006
- dimension?: Dimension;
1007
- } : {
1008
- format: T['storageTexture'];
1009
- dimension: Dimension;
1010
- } : never;
1011
- type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? (TgpuBuffer<UnwrapRuntimeConstructor<T['uniform']>> & Uniform) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer<UnwrapRuntimeConstructor<T['storage']>> & Storage) | GPUBuffer : T extends TgpuLayoutSampler ? GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | (Sampled & TgpuTexture<Prettify<TextureProps & GetTextureRestriction<T>>>) : T extends TgpuLayoutStorageTexture ? GPUTextureView | (Storage & TgpuTexture<Prettify<TextureProps & GetStorageTextureRestriction<T>>>) : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
1012
- type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<UnwrapRuntimeConstructor<T['uniform']>> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1013
- type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
1014
- readonly resourceType: 'bind-group';
1015
- readonly layout: TgpuBindGroupLayout<Entries>;
1016
- unwrap(unwrapper: Unwrapper): GPUBindGroup;
1017
- };
1018
- type ExoticEntry<T> = T extends Record<string | number | symbol, unknown> ? {
1019
- [Key in keyof T]: T[Key] extends BaseWgslData ? Exotic<T[Key]> : T[Key] extends (...args: infer TArgs) => infer TReturn ? (...args: TArgs) => Exotic<TReturn> : T[Key];
1020
- } : T;
1021
- type ExoticEntries<T extends Record<string, TgpuLayoutEntry | null>> = {
1022
- [BindingKey in keyof T]: ExoticEntry<T[BindingKey]>;
1023
- };
1024
- declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<ExoticEntries<Entries>>>;
1025
-
1026
- interface TgpuBufferUsage<TData extends BaseWgslData, TUsage extends BindableBufferUsage = BindableBufferUsage> extends TgpuResolvable {
1027
- readonly resourceType: 'buffer-usage';
1028
- readonly usage: TUsage;
1029
- readonly '~repr': Infer<TData>;
1030
- value: Infer<TData>;
1031
- }
1032
- interface TgpuBufferUniform<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'uniform'> {
1033
- readonly value: Infer<TData>;
1034
- }
1035
- interface TgpuBufferReadonly<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'readonly'> {
1036
- readonly value: Infer<TData>;
1037
- }
1038
- interface TgpuBufferMutable<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'mutable'> {
1039
- }
1040
-
1041
- interface TgpuSlot<T> extends TgpuNamable {
1042
- readonly resourceType: 'slot';
1043
- readonly defaultValue: T | undefined;
1044
- readonly label?: string | undefined;
1045
- /**
1046
- * Used to determine if code generated using either value `a` or `b` in place
1047
- * of the slot will be equivalent. Defaults to `Object.is`.
1048
- */
1049
- areEqual(a: T, b: T): boolean;
1050
- readonly value: Infer<T>;
1051
- }
1052
- interface TgpuDerived<T> {
1053
- readonly resourceType: 'derived';
1054
- readonly value: Infer<T>;
1055
- with<TValue>(slot: TgpuSlot<TValue>, value: Eventual<TValue>): TgpuDerived<T>;
1056
- /**
1057
- * @internal
1058
- */
1059
- '~compute'(): T;
1060
- }
1061
- /**
1062
- * Represents a value that is available at resolution time.
1063
- */
1064
- type Eventual<T> = T | TgpuSlot<T> | TgpuDerived<T>;
1065
- type SlotValuePair<T> = [TgpuSlot<T>, T];
1066
-
1067
- type Wgsl = Eventual<string | number | boolean | TgpuResolvable | AnyWgslData>;
1068
- declare const UnknownData: unique symbol;
1069
- type UnknownData = typeof UnknownData;
1070
- type Resource = {
1071
- value: unknown;
1072
- dataType: AnyWgslData | UnknownData;
1073
- };
1074
- type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
1075
- interface FnToWgslOptions {
1076
- args: Resource[];
1077
- returnType: AnyWgslData;
1078
- body: Block;
1079
- externalMap: Record<string, unknown>;
1080
- }
1081
- /**
1082
- * Passed into each resolvable item. All items in a tree share a resolution ctx,
1083
- * but there can be layers added and removed from the item stack when going down
1084
- * and up the tree.
1085
- */
1086
- interface ResolutionCtx {
1087
- readonly names: NameRegistry;
1088
- addDeclaration(declaration: string): void;
1089
- /**
1090
- * Reserves a bind group number, and returns a placeholder that will be replaced
1091
- * with a concrete number at the end of the resolution process.
1092
- */
1093
- allocateLayoutEntry(layout: TgpuBindGroupLayout): string;
1094
- /**
1095
- * Reserves a spot in the catch-all bind group, without the indirection of a bind-group.
1096
- * This means the resource is 'fixed', and cannot be swapped between code execution.
1097
- */
1098
- allocateFixedEntry(layoutEntry: TgpuLayoutEntry, resource: object): {
1099
- group: string;
1100
- binding: number;
1101
- };
1102
- withSlots<T>(pairs: SlotValuePair<unknown>[], callback: () => T): T;
1103
- /**
1104
- * Unwraps all layers of slot/derived indirection and returns the concrete value if available.
1105
- * @throws {MissingSlotValueError}
1106
- */
1107
- unwrap<T>(eventual: Eventual<T>): T;
1108
- resolve(item: Wgsl): string;
1109
- resolveValue<T extends BaseWgslData>(value: Infer<T>, schema: T): string;
1110
- transpileFn(fn: string): {
1111
- argNames: string[];
1112
- body: Block;
1113
- externalNames: string[];
1114
- };
1115
- fnToWgsl(options: FnToWgslOptions): {
1116
- head: Wgsl;
1117
- body: Wgsl;
1118
- };
1119
- }
1120
- interface TgpuResolvable {
1121
- readonly label?: string | undefined;
1122
- resolve(ctx: ResolutionCtx): string;
1123
- toString(): string;
1124
- }
1125
- type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
1126
-
1127
- interface NumberArrayView {
1128
- readonly length: number;
1129
- [n: number]: number;
1130
- }
1131
- interface BaseWgslData {
1132
- type: string;
1133
- /** Type-token, not available at runtime */
1134
- readonly '~repr': unknown;
1135
- }
1136
- interface Swizzle2<T2, T3, T4> {
1137
- readonly xx: T2;
1138
- readonly xy: T2;
1139
- readonly yx: T2;
1140
- readonly yy: T2;
1141
- readonly xxx: T3;
1142
- readonly xxy: T3;
1143
- readonly xyx: T3;
1144
- readonly xyy: T3;
1145
- readonly yxx: T3;
1146
- readonly yxy: T3;
1147
- readonly yyx: T3;
1148
- readonly yyy: T3;
1149
- readonly xxxx: T4;
1150
- readonly xxxy: T4;
1151
- readonly xxyx: T4;
1152
- readonly xxyy: T4;
1153
- readonly xyxx: T4;
1154
- readonly xyxy: T4;
1155
- readonly xyyx: T4;
1156
- readonly xyyy: T4;
1157
- readonly yxxx: T4;
1158
- readonly yxxy: T4;
1159
- readonly yxyx: T4;
1160
- readonly yxyy: T4;
1161
- readonly yyxx: T4;
1162
- readonly yyxy: T4;
1163
- readonly yyyx: T4;
1164
- readonly yyyy: T4;
1165
- }
1166
- interface Swizzle3<T2, T3, T4> extends Swizzle2<T2, T3, T4> {
1167
- readonly xz: T2;
1168
- readonly yz: T2;
1169
- readonly zx: T2;
1170
- readonly zy: T2;
1171
- readonly zz: T2;
1172
- readonly xxz: T3;
1173
- readonly xyz: T3;
1174
- readonly xzx: T3;
1175
- readonly xzy: T3;
1176
- readonly xzz: T3;
1177
- readonly yxz: T3;
1178
- readonly yyz: T3;
1179
- readonly yzx: T3;
1180
- readonly yzy: T3;
1181
- readonly yzz: T3;
1182
- readonly zxx: T3;
1183
- readonly zxy: T3;
1184
- readonly zxz: T3;
1185
- readonly zyx: T3;
1186
- readonly zyy: T3;
1187
- readonly zyz: T3;
1188
- readonly zzx: T3;
1189
- readonly zzy: T3;
1190
- readonly zzz: T3;
1191
- readonly xxxz: T4;
1192
- readonly xxyz: T4;
1193
- readonly xxzx: T4;
1194
- readonly xxzy: T4;
1195
- readonly xxzz: T4;
1196
- readonly xyxz: T4;
1197
- readonly xyyz: T4;
1198
- readonly xyzx: T4;
1199
- readonly xyzy: T4;
1200
- readonly xyzz: T4;
1201
- readonly xzxx: T4;
1202
- readonly xzxy: T4;
1203
- readonly xzxz: T4;
1204
- readonly xzyx: T4;
1205
- readonly xzyy: T4;
1206
- readonly xzyz: T4;
1207
- readonly xzzx: T4;
1208
- readonly xzzy: T4;
1209
- readonly xzzz: T4;
1210
- readonly yxxz: T4;
1211
- readonly yxyz: T4;
1212
- readonly yxzx: T4;
1213
- readonly yxzy: T4;
1214
- readonly yxzz: T4;
1215
- readonly yyxz: T4;
1216
- readonly yyyz: T4;
1217
- readonly yyzx: T4;
1218
- readonly yyzy: T4;
1219
- readonly yyzz: T4;
1220
- readonly yzxx: T4;
1221
- readonly yzxy: T4;
1222
- readonly yzxz: T4;
1223
- readonly yzyx: T4;
1224
- readonly yzyy: T4;
1225
- readonly yzyz: T4;
1226
- readonly yzzx: T4;
1227
- readonly yzzy: T4;
1228
- readonly yzzz: T4;
1229
- readonly zxxx: T4;
1230
- readonly zxxy: T4;
1231
- readonly zxxz: T4;
1232
- readonly zxyx: T4;
1233
- readonly zxyy: T4;
1234
- readonly zxyz: T4;
1235
- readonly zxzx: T4;
1236
- readonly zxzy: T4;
1237
- readonly zxzz: T4;
1238
- readonly zyxx: T4;
1239
- readonly zyxy: T4;
1240
- readonly zyxz: T4;
1241
- readonly zyyx: T4;
1242
- readonly zyyy: T4;
1243
- readonly zyyz: T4;
1244
- readonly zyzx: T4;
1245
- readonly zyzy: T4;
1246
- readonly zyzz: T4;
1247
- readonly zzxx: T4;
1248
- readonly zzxy: T4;
1249
- readonly zzxz: T4;
1250
- readonly zzyx: T4;
1251
- readonly zzyy: T4;
1252
- readonly zzyz: T4;
1253
- readonly zzzx: T4;
1254
- readonly zzzy: T4;
1255
- readonly zzzz: T4;
1256
- }
1257
- interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3, T4> {
1258
- readonly yw: T2;
1259
- readonly zw: T2;
1260
- readonly wx: T2;
1261
- readonly wy: T2;
1262
- readonly wz: T2;
1263
- readonly ww: T2;
1264
- readonly xxw: T3;
1265
- readonly xyw: T3;
1266
- readonly xzw: T3;
1267
- readonly xwx: T3;
1268
- readonly xwy: T3;
1269
- readonly xwz: T3;
1270
- readonly xww: T3;
1271
- readonly yxw: T3;
1272
- readonly yyw: T3;
1273
- readonly yzw: T3;
1274
- readonly ywx: T3;
1275
- readonly ywy: T3;
1276
- readonly ywz: T3;
1277
- readonly yww: T3;
1278
- readonly zxw: T3;
1279
- readonly zyw: T3;
1280
- readonly zzw: T3;
1281
- readonly zwx: T3;
1282
- readonly zwy: T3;
1283
- readonly zwz: T3;
1284
- readonly zww: T3;
1285
- readonly wxx: T3;
1286
- readonly wxz: T3;
1287
- readonly wxy: T3;
1288
- readonly wyy: T3;
1289
- readonly wyz: T3;
1290
- readonly wzz: T3;
1291
- readonly wwx: T3;
1292
- readonly wwy: T3;
1293
- readonly wwz: T3;
1294
- readonly www: T3;
1295
- readonly xxxw: T4;
1296
- readonly xxyw: T4;
1297
- readonly xxzw: T4;
1298
- readonly xxwx: T4;
1299
- readonly xxwy: T4;
1300
- readonly xxwz: T4;
1301
- readonly xxww: T4;
1302
- readonly xyxw: T4;
1303
- readonly xyyw: T4;
1304
- readonly xyzw: T4;
1305
- readonly xywx: T4;
1306
- readonly xywy: T4;
1307
- readonly xywz: T4;
1308
- readonly xyww: T4;
1309
- readonly xzxw: T4;
1310
- readonly xzyw: T4;
1311
- readonly xzzw: T4;
1312
- readonly xzwx: T4;
1313
- readonly xzwy: T4;
1314
- readonly xzwz: T4;
1315
- readonly xzww: T4;
1316
- readonly xwxx: T4;
1317
- readonly xwxy: T4;
1318
- readonly xwxz: T4;
1319
- readonly xwyy: T4;
1320
- readonly xwyz: T4;
1321
- readonly xwzz: T4;
1322
- readonly xwwx: T4;
1323
- readonly xwwy: T4;
1324
- readonly xwwz: T4;
1325
- readonly xwww: T4;
1326
- readonly yxxw: T4;
1327
- readonly yxyw: T4;
1328
- readonly yxzw: T4;
1329
- readonly yxwx: T4;
1330
- readonly yxwy: T4;
1331
- readonly yxwz: T4;
1332
- readonly yxww: T4;
1333
- readonly yyxw: T4;
1334
- readonly yyyw: T4;
1335
- readonly yyzw: T4;
1336
- readonly yywx: T4;
1337
- readonly yywy: T4;
1338
- readonly yywz: T4;
1339
- readonly yyww: T4;
1340
- readonly yzxw: T4;
1341
- readonly yzyw: T4;
1342
- readonly yzzw: T4;
1343
- readonly yzwx: T4;
1344
- readonly yzwy: T4;
1345
- readonly yzwz: T4;
1346
- readonly yzww: T4;
1347
- readonly ywxx: T4;
1348
- readonly ywxy: T4;
1349
- readonly ywxz: T4;
1350
- readonly ywxw: T4;
1351
- readonly ywyy: T4;
1352
- readonly ywyz: T4;
1353
- readonly ywzz: T4;
1354
- readonly ywwx: T4;
1355
- readonly ywwy: T4;
1356
- readonly ywwz: T4;
1357
- readonly ywww: T4;
1358
- readonly zxxw: T4;
1359
- readonly zxyw: T4;
1360
- readonly zxzw: T4;
1361
- readonly zxwx: T4;
1362
- readonly zxwy: T4;
1363
- readonly zxwz: T4;
1364
- readonly zxww: T4;
1365
- readonly zyxw: T4;
1366
- readonly zyyw: T4;
1367
- readonly zyzw: T4;
1368
- readonly zywx: T4;
1369
- readonly zywy: T4;
1370
- readonly zywz: T4;
1371
- readonly zyww: T4;
1372
- readonly zzxw: T4;
1373
- readonly zzyw: T4;
1374
- readonly zzzw: T4;
1375
- readonly zzwx: T4;
1376
- readonly zzwy: T4;
1377
- readonly zzwz: T4;
1378
- readonly zzww: T4;
1379
- readonly zwxx: T4;
1380
- readonly zwxy: T4;
1381
- readonly zwxz: T4;
1382
- readonly zwxw: T4;
1383
- readonly zwyy: T4;
1384
- readonly zwyz: T4;
1385
- readonly zwzz: T4;
1386
- readonly zwwx: T4;
1387
- readonly zwwy: T4;
1388
- readonly zwwz: T4;
1389
- readonly zwww: T4;
1390
- readonly wxxx: T4;
1391
- readonly wxxy: T4;
1392
- readonly wxxz: T4;
1393
- readonly wxxw: T4;
1394
- readonly wxyx: T4;
1395
- readonly wxyy: T4;
1396
- readonly wxyz: T4;
1397
- readonly wxyw: T4;
1398
- readonly wxzx: T4;
1399
- readonly wxzy: T4;
1400
- readonly wxzz: T4;
1401
- readonly wxzw: T4;
1402
- readonly wxwx: T4;
1403
- readonly wxwy: T4;
1404
- readonly wxwz: T4;
1405
- readonly wxww: T4;
1406
- readonly wyxx: T4;
1407
- readonly wyxy: T4;
1408
- readonly wyxz: T4;
1409
- readonly wyxw: T4;
1410
- readonly wyyy: T4;
1411
- readonly wyyz: T4;
1412
- readonly wyzw: T4;
1413
- readonly wywx: T4;
1414
- readonly wywy: T4;
1415
- readonly wywz: T4;
1416
- readonly wyww: T4;
1417
- readonly wzxx: T4;
1418
- readonly wzxy: T4;
1419
- readonly wzxz: T4;
1420
- readonly wzxw: T4;
1421
- readonly wzyy: T4;
1422
- readonly wzyz: T4;
1423
- readonly wzzy: T4;
1424
- readonly wzzw: T4;
1425
- readonly wzwx: T4;
1426
- readonly wzwy: T4;
1427
- readonly wzwz: T4;
1428
- readonly wzww: T4;
1429
- readonly wwxx: T4;
1430
- readonly wwxy: T4;
1431
- readonly wwxz: T4;
1432
- readonly wwxw: T4;
1433
- readonly wwyy: T4;
1434
- readonly wwyz: T4;
1435
- readonly wwzz: T4;
1436
- readonly wwwx: T4;
1437
- readonly wwwy: T4;
1438
- readonly wwwz: T4;
1439
- readonly wwww: T4;
1440
- }
1441
- /**
1442
- * Interface representing its WGSL vector type counterpart: vec2f or vec2<f32>.
1443
- * A vector with 2 elements of type f32
1444
- */
1445
- interface v2f extends NumberArrayView, Swizzle2<v2f, v3f, v4f>, TgpuResolvable {
1446
- /** use to distinguish between vectors of the same size on the type level */
1447
- readonly kind: 'vec2f';
1448
- x: number;
1449
- y: number;
1450
- }
1451
- /**
1452
- * Interface representing its WGSL vector type counterpart: vec2h or vec2<f16>.
1453
- * A vector with 2 elements of type f16
1454
- */
1455
- interface v2h extends NumberArrayView, Swizzle2<v2h, v3h, v4h>, TgpuResolvable {
1456
- /** use to distinguish between vectors of the same size on the type level */
1457
- readonly kind: 'vec2h';
1458
- x: number;
1459
- y: number;
1460
- }
1461
- /**
1462
- * Interface representing its WGSL vector type counterpart: vec2i or vec2<i32>.
1463
- * A vector with 2 elements of type i32
1464
- */
1465
- interface v2i extends NumberArrayView, Swizzle2<v2i, v3i, v4i>, TgpuResolvable {
1466
- /** use to distinguish between vectors of the same size on the type level */
1467
- readonly kind: 'vec2i';
1468
- x: number;
1469
- y: number;
1470
- }
1471
- /**
1472
- * Interface representing its WGSL vector type counterpart: vec2u or vec2<u32>.
1473
- * A vector with 2 elements of type u32
1474
- */
1475
- interface v2u extends NumberArrayView, Swizzle2<v2u, v3u, v4u>, TgpuResolvable {
1476
- /** use to distinguish between vectors of the same size on the type level */
1477
- readonly kind: 'vec2u';
1478
- x: number;
1479
- y: number;
1480
- }
1481
- /**
1482
- * Interface representing its WGSL vector type counterpart: vec3f or vec3<f32>.
1483
- * A vector with 3 elements of type f32
1484
- */
1485
- interface v3f extends NumberArrayView, Swizzle3<v2f, v3f, v4f>, TgpuResolvable {
1486
- /** use to distinguish between vectors of the same size on the type level */
1487
- readonly kind: 'vec3f';
1488
- x: number;
1489
- y: number;
1490
- z: number;
1491
- }
1492
- /**
1493
- * Interface representing its WGSL vector type counterpart: vec3h or vec3<f16>.
1494
- * A vector with 3 elements of type f16
1495
- */
1496
- interface v3h extends NumberArrayView, Swizzle3<v2h, v3h, v4h>, TgpuResolvable {
1497
- /** use to distinguish between vectors of the same size on the type level */
1498
- readonly kind: 'vec3h';
1499
- x: number;
1500
- y: number;
1501
- z: number;
1502
- }
1503
- /**
1504
- * Interface representing its WGSL vector type counterpart: vec3i or vec3<i32>.
1505
- * A vector with 3 elements of type i32
1506
- */
1507
- interface v3i extends NumberArrayView, Swizzle3<v2i, v3i, v4i>, TgpuResolvable {
1508
- /** use to distinguish between vectors of the same size on the type level */
1509
- readonly kind: 'vec3i';
1510
- x: number;
1511
- y: number;
1512
- z: number;
1513
- }
1514
- /**
1515
- * Interface representing its WGSL vector type counterpart: vec3u or vec3<u32>.
1516
- * A vector with 3 elements of type u32
1517
- */
1518
- interface v3u extends NumberArrayView, Swizzle3<v2u, v3u, v4u>, TgpuResolvable {
1519
- /** use to distinguish between vectors of the same size on the type level */
1520
- readonly kind: 'vec3u';
1521
- x: number;
1522
- y: number;
1523
- z: number;
1524
- }
1525
- /**
1526
- * Interface representing its WGSL vector type counterpart: vec4f or vec4<f32>.
1527
- * A vector with 4 elements of type f32
1528
- */
1529
- interface v4f extends NumberArrayView, Swizzle4<v2f, v3f, v4f>, TgpuResolvable {
1530
- /** use to distinguish between vectors of the same size on the type level */
1531
- readonly kind: 'vec4f';
1532
- x: number;
1533
- y: number;
1534
- z: number;
1535
- w: number;
1536
- }
1537
- /**
1538
- * Interface representing its WGSL vector type counterpart: vec4h or vec4<f16>.
1539
- * A vector with 4 elements of type f16
1540
- */
1541
- interface v4h extends NumberArrayView, Swizzle4<v2h, v3h, v4h>, TgpuResolvable {
1542
- /** use to distinguish between vectors of the same size on the type level */
1543
- readonly kind: 'vec4h';
1544
- x: number;
1545
- y: number;
1546
- z: number;
1547
- w: number;
1548
- }
1549
- /**
1550
- * Interface representing its WGSL vector type counterpart: vec4i or vec4<i32>.
1551
- * A vector with 4 elements of type i32
1552
- */
1553
- interface v4i extends NumberArrayView, Swizzle4<v2i, v3i, v4i>, TgpuResolvable {
1554
- /** use to distinguish between vectors of the same size on the type level */
1555
- readonly kind: 'vec4i';
1556
- x: number;
1557
- y: number;
1558
- z: number;
1559
- w: number;
1560
- }
1561
- /**
1562
- * Interface representing its WGSL vector type counterpart: vec4u or vec4<u32>.
1563
- * A vector with 4 elements of type u32
1564
- */
1565
- interface v4u extends NumberArrayView, Swizzle4<v2u, v3u, v4u>, TgpuResolvable {
1566
- /** use to distinguish between vectors of the same size on the type level */
1567
- readonly kind: 'vec4u';
1568
- x: number;
1569
- y: number;
1570
- z: number;
1571
- w: number;
1572
- }
1573
- interface matBase<TColumn> extends NumberArrayView {
1574
- readonly columns: readonly TColumn[];
1575
- }
1576
- /**
1577
- * Interface representing its WGSL matrix type counterpart: mat2x2
1578
- * A matrix with 2 rows and 2 columns, with elements of type `TColumn`
1579
- */
1580
- interface mat2x2<TColumn> extends matBase<TColumn> {
1581
- readonly length: 4;
1582
- [n: number]: number;
1583
- }
1584
- /**
1585
- * Interface representing its WGSL matrix type counterpart: mat2x2f or mat2x2<f32>
1586
- * A matrix with 2 rows and 2 columns, with elements of type d.f32
1587
- */
1588
- interface m2x2f extends mat2x2<v2f> {
1589
- readonly kind: 'mat2x2f';
1590
- }
1591
- /**
1592
- * Interface representing its WGSL matrix type counterpart: mat3x3
1593
- * A matrix with 3 rows and 3 columns, with elements of type `TColumn`
1594
- */
1595
- interface mat3x3<TColumn> extends matBase<TColumn> {
1596
- readonly length: 12;
1597
- [n: number]: number;
1598
- }
1599
- /**
1600
- * Interface representing its WGSL matrix type counterpart: mat3x3f or mat3x3<f32>
1601
- * A matrix with 3 rows and 3 columns, with elements of type d.f32
1602
- */
1603
- interface m3x3f extends mat3x3<v3f> {
1604
- readonly kind: 'mat3x3f';
1605
- }
1606
- /**
1607
- * Interface representing its WGSL matrix type counterpart: mat4x4
1608
- * A matrix with 4 rows and 4 columns, with elements of type `TColumn`
1609
- */
1610
- interface mat4x4<TColumn> extends matBase<TColumn> {
1611
- readonly length: 16;
1612
- [n: number]: number;
1613
- }
1614
- /**
1615
- * Interface representing its WGSL matrix type counterpart: mat4x4f or mat4x4<f32>
1616
- * A matrix with 4 rows and 4 columns, with elements of type d.f32
1617
- */
1618
- interface m4x4f extends mat4x4<v4f> {
1619
- readonly kind: 'mat4x4f';
1620
- }
1621
- /**
1622
- * Boolean schema representing a single WGSL bool value.
1623
- * Cannot be used inside buffers as it is not host-shareable.
1624
- */
1625
- interface Bool {
1626
- readonly type: 'bool';
1627
- readonly '~repr': boolean;
1628
- }
1629
- interface F32 {
1630
- readonly type: 'f32';
1631
- /** Type-token, not available at runtime */
1632
- readonly '~repr': number;
1633
- }
1634
- interface F16 {
1635
- readonly type: 'f16';
1636
- /** Type-token, not available at runtime */
1637
- readonly '~repr': number;
1638
- }
1639
- interface I32 {
1640
- readonly type: 'i32';
1641
- /** Type-token, not available at runtime */
1642
- readonly '~repr': number;
1643
- }
1644
- interface U32 {
1645
- readonly type: 'u32';
1646
- /** Type-token, not available at runtime */
1647
- readonly '~repr': number;
1648
- }
1649
- interface Vec2f {
1650
- readonly type: 'vec2f';
1651
- /** Type-token, not available at runtime */
1652
- readonly '~repr': v2f;
1653
- }
1654
- interface Vec2h {
1655
- readonly type: 'vec2h';
1656
- /** Type-token, not available at runtime */
1657
- readonly '~repr': v2h;
1658
- }
1659
- interface Vec2i {
1660
- readonly type: 'vec2i';
1661
- /** Type-token, not available at runtime */
1662
- readonly '~repr': v2i;
1663
- }
1664
- interface Vec2u {
1665
- readonly type: 'vec2u';
1666
- /** Type-token, not available at runtime */
1667
- readonly '~repr': v2u;
1668
- }
1669
- interface Vec3f {
1670
- readonly type: 'vec3f';
1671
- /** Type-token, not available at runtime */
1672
- readonly '~repr': v3f;
1673
- }
1674
- interface Vec3h {
1675
- readonly type: 'vec3h';
1676
- /** Type-token, not available at runtime */
1677
- readonly '~repr': v3h;
1678
- }
1679
- interface Vec3i {
1680
- readonly type: 'vec3i';
1681
- /** Type-token, not available at runtime */
1682
- readonly '~repr': v3i;
1683
- }
1684
- interface Vec3u {
1685
- readonly type: 'vec3u';
1686
- /** Type-token, not available at runtime */
1687
- readonly '~repr': v3u;
1688
- }
1689
- interface Vec4f {
1690
- readonly type: 'vec4f';
1691
- /** Type-token, not available at runtime */
1692
- readonly '~repr': v4f;
1693
- }
1694
- interface Vec4h {
1695
- readonly type: 'vec4h';
1696
- /** Type-token, not available at runtime */
1697
- readonly '~repr': v4h;
1698
- }
1699
- interface Vec4i {
1700
- readonly type: 'vec4i';
1701
- /** Type-token, not available at runtime */
1702
- readonly '~repr': v4i;
1703
- }
1704
- interface Vec4u {
1705
- readonly type: 'vec4u';
1706
- /** Type-token, not available at runtime */
1707
- readonly '~repr': v4u;
1708
- }
1709
- interface Mat2x2f {
1710
- readonly type: 'mat2x2f';
1711
- /** Type-token, not available at runtime */
1712
- readonly '~repr': m2x2f;
1713
- }
1714
- interface Mat3x3f {
1715
- readonly type: 'mat3x3f';
1716
- /** Type-token, not available at runtime */
1717
- readonly '~repr': m3x3f;
1718
- }
1719
- interface Mat4x4f {
1720
- readonly type: 'mat4x4f';
1721
- /** Type-token, not available at runtime */
1722
- readonly '~repr': m4x4f;
1723
- }
1724
- interface WgslStruct<TProps extends Record<string, BaseWgslData> = Record<string, BaseWgslData>> {
1725
- readonly type: 'struct';
1726
- readonly label?: string | undefined;
1727
- readonly propTypes: TProps;
1728
- /** Type-token, not available at runtime */
1729
- readonly '~repr': InferRecord<TProps>;
1730
- }
1731
- interface WgslArray<TElement = BaseWgslData> {
1732
- readonly type: 'array';
1733
- readonly elementCount: number;
1734
- readonly elementType: TElement;
1735
- /** Type-token, not available at runtime */
1736
- readonly '~repr': Infer<TElement>[];
1737
- }
1738
- /**
1739
- * Schema representing the `atomic<...>` WGSL data type.
1740
- */
1741
- interface Atomic<TInner extends U32 | I32 = U32 | I32> {
1742
- readonly type: 'atomic';
1743
- readonly inner: TInner;
1744
- /** Type-token, not available at runtime */
1745
- readonly '~repr': Infer<TInner>;
1746
- }
1747
- interface Align<T extends number> {
1748
- readonly type: '@align';
1749
- readonly value: T;
1750
- }
1751
- interface Size<T extends number> {
1752
- readonly type: '@size';
1753
- readonly value: T;
1754
- }
1755
- interface Location<T extends number> {
1756
- readonly type: '@location';
1757
- readonly value: T;
1758
- }
1759
- interface Builtin<T extends string> {
1760
- readonly type: '@builtin';
1761
- readonly value: T;
1762
- }
1763
- interface Decorated<TInner extends BaseWgslData = BaseWgslData, TAttribs extends unknown[] = unknown[]> {
1764
- readonly type: 'decorated';
1765
- readonly inner: TInner;
1766
- readonly attribs: TAttribs;
1767
- /** Type-token, not available at runtime */
1768
- readonly '~repr': Infer<TInner>;
1769
- }
1770
- declare const wgslTypeLiterals: readonly ["bool", "f32", "f16", "i32", "u32", "vec2f", "vec2h", "vec2i", "vec2u", "vec3f", "vec3h", "vec3i", "vec3u", "vec4f", "vec4h", "vec4i", "vec4u", "mat2x2f", "mat3x3f", "mat4x4f", "struct", "array", "atomic", "decorated"];
1771
- type WgslTypeLiteral = (typeof wgslTypeLiterals)[number];
1772
- type AnyWgslData = Bool | F32 | F16 | I32 | U32 | Vec2f | Vec2h | Vec2i | Vec2u | Vec3f | Vec3h | Vec3i | Vec3u | Vec4f | Vec4h | Vec4i | Vec4u | Mat2x2f | Mat3x3f | Mat4x4f | WgslStruct | WgslArray | Atomic | Decorated;
1773
- declare function isWgslData(value: unknown): value is AnyWgslData;
1774
- /**
1775
- * Checks whether passed in value is an array schema,
1776
- * as opposed to, e.g., a disarray schema.
1777
- *
1778
- * Array schemas can be used to describe uniform and storage buffers,
1779
- * whereas disarray schemas cannot.
1780
- *
1781
- * @example
1782
- * isWgslArray(d.arrayOf(d.u32, 4)) // true
1783
- * isWgslArray(d.disarray(d.u32, 4)) // false
1784
- * isWgslArray(d.vec3f) // false
1785
- */
1786
- declare function isWgslArray<T extends WgslArray>(schema: T | unknown): schema is T;
1787
- /**
1788
- * Checks whether passed in value is a struct schema,
1789
- * as opposed to, e.g., an unstruct schema.
1790
- *
1791
- * Struct schemas can be used to describe uniform and storage buffers,
1792
- * whereas unstruct schemas cannot.
1793
- *
1794
- * @example
1795
- * isWgslStruct(d.struct({ a: d.u32 })) // true
1796
- * isWgslStruct(d.unstruct({ a: d.u32 })) // false
1797
- * isWgslStruct(d.vec3f) // false
1798
- */
1799
- declare function isWgslStruct<T extends WgslStruct>(schema: T | unknown): schema is T;
1800
- /**
1801
- * Checks whether the passed in value is an atomic schema.
1802
- *
1803
- * @example
1804
- * isAtomic(d.atomic(d.u32)) // true
1805
- * isAtomic(d.u32) // false
1806
- */
1807
- declare function isAtomic<T extends Atomic<U32 | I32>>(schema: T | unknown): schema is T;
1808
- declare function isAlignAttrib<T extends Align<number>>(value: unknown | T): value is T;
1809
- declare function isSizeAttrib<T extends Size<number>>(value: unknown | T): value is T;
1810
- declare function isLocationAttrib<T extends Location<number>>(value: unknown | T): value is T;
1811
- declare function isBuiltinAttrib<T extends Builtin<string>>(value: unknown | T): value is T;
1812
- declare function isDecorated<T extends Decorated>(value: unknown | T): value is T;
1813
-
1814
- export { type v2f as $, type AnyData as A, type TgpuLayoutTexture as B, type TgpuLayoutStorage as C, type TgpuLayoutStorageTexture as D, type Exotic as E, type TgpuLayoutExternalTexture as F, type TgpuLayoutUniform as G, type BindLayoutEntry as H, type Infer as I, type BaseWgslData as J, type TgpuNamable as K, type LayoutEntryToInput as L, type ExoticRecord as M, type WgslArray as N, type OmitProps as O, type Prettify as P, type Disarray as Q, type Unstruct as R, Storage as S, type TgpuBuffer as T, type Unwrapper as U, Vertex as V, type WgslStruct as W, type m2x2f as X, type m3x3f as Y, type m4x4f as Z, type Mat2x2f as _, type TgpuLayoutEntry as a, isDisarray as a$, type Mat3x3f as a0, type v3f as a1, type Mat4x4f as a2, type v4f as a3, type U32 as a4, type I32 as a5, type Atomic as a6, type Align as a7, type Size as a8, type Location as a9, type Vec2h as aA, type Vec2i as aB, type Vec2u as aC, type Vec3f as aD, type Vec3h as aE, type Vec3i as aF, type Vec4h as aG, type Vec4i as aH, type Vec4u as aI, type v2i as aJ, type v2u as aK, type v3i as aL, type v3u as aM, type v4i as aN, type v4u as aO, vec2f as aP, vec2h as aQ, vec2i as aR, vec2u as aS, vec3f as aT, vec3h as aU, vec3i as aV, vec3u as aW, vec4f as aX, vec4h as aY, vec4i as aZ, vec4u as a_, type Builtin as aa, type Decorated as ab, type LooseDecorated as ac, type AnyLooseData as ad, type WgslTypeLiteral as ae, type LooseTypeLiteral as af, type Vec4f as ag, type F32 as ah, type Vec3u as ai, bool as aj, f32 as ak, f16 as al, i32 as am, u32 as an, isWgslData as ao, isWgslArray as ap, isWgslStruct as aq, isAtomic as ar, isDecorated as as, isAlignAttrib as at, isBuiltinAttrib as au, isLocationAttrib as av, isSizeAttrib as aw, type Bool as ax, type F16 as ay, type Vec2f as az, type TgpuBindGroupLayout as b, isUnstruct as b0, isLooseDecorated as b1, isData as b2, isLooseData as b3, type FormatToWGSLType as b4, type TgpuVertexFormatData as b5, packedFormats as b6, uint8 as b7, uint8x2 as b8, uint8x4 as b9, float32x3 as bA, float32x4 as bB, uint32 as bC, uint32x2 as bD, uint32x3 as bE, uint32x4 as bF, sint32 as bG, sint32x2 as bH, sint32x3 as bI, sint32x4 as bJ, unorm10_10_10_2 as bK, unorm8x4_bgra as bL, type PackedData as bM, sint8 as ba, sint8x2 as bb, sint8x4 as bc, unorm8 as bd, unorm8x2 as be, unorm8x4 as bf, snorm8 as bg, snorm8x2 as bh, snorm8x4 as bi, uint16 as bj, uint16x2 as bk, uint16x4 as bl, sint16 as bm, sint16x2 as bn, sint16x4 as bo, unorm16 as bp, unorm16x2 as bq, unorm16x4 as br, snorm16 as bs, snorm16x2 as bt, snorm16x4 as bu, float16 as bv, float16x2 as bw, float16x4 as bx, float32 as by, float32x2 as bz, type TgpuBindGroup as c, type TgpuResolvable as d, type AnyWgslData as e, type TgpuBufferMutable as f, type TgpuBufferReadonly as g, type TgpuBufferUniform as h, bindGroupLayout as i, isBuffer as j, isUsableAsUniform as k, isUsableAsVertex as l, isSampler as m, isComparisonSampler as n, isSampledTextureView as o, isStorageTextureView as p, isUsableAsStorage as q, Uniform as r, type TgpuTexture as s, type TgpuReadonlyTexture as t, type TgpuWriteonlyTexture as u, type TgpuMutableTexture as v, type TgpuSampledTexture as w, type TgpuAnyTextureView as x, type TgpuSampler as y, type TgpuLayoutSampler as z };