typegpu 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/builtin-DdtWpk2t.js +818 -0
  3. package/builtin-DdtWpk2t.js.map +1 -0
  4. package/chunk-BYypO7fO.js +18 -0
  5. package/common/index.d.ts +8 -23
  6. package/common/index.d.ts.map +1 -0
  7. package/common/index.js +7 -5
  8. package/common/index.js.map +1 -1
  9. package/data/index.d.ts +7 -401
  10. package/data/index.d.ts.map +1 -0
  11. package/data/index.js +164 -1
  12. package/data/index.js.map +1 -1
  13. package/deepEqual-DQxK4vdp.js +413 -0
  14. package/deepEqual-DQxK4vdp.js.map +1 -0
  15. package/extensions-DIVuAfBM.js +2032 -0
  16. package/extensions-DIVuAfBM.js.map +1 -0
  17. package/fullScreenTriangle-CfFyQd_0.js +543 -0
  18. package/fullScreenTriangle-CfFyQd_0.js.map +1 -0
  19. package/index.d.ts +124 -310
  20. package/index.d.ts.map +1 -0
  21. package/index.js +6282 -153
  22. package/index.js.map +1 -1
  23. package/indexNamedExports-oL6tyaJ9.d.ts +5697 -0
  24. package/indexNamedExports-oL6tyaJ9.d.ts.map +1 -0
  25. package/operators-d-PMVTo7.js +4158 -0
  26. package/operators-d-PMVTo7.js.map +1 -0
  27. package/package.json +3 -2
  28. package/std/index.d.ts +7 -621
  29. package/std/index.d.ts.map +1 -0
  30. package/std/index.js +165 -1
  31. package/std/index.js.map +1 -1
  32. package/texture-BagDrrks.js +205 -0
  33. package/texture-BagDrrks.js.map +1 -0
  34. package/chunk-5ABKYSJD.js +0 -2
  35. package/chunk-5ABKYSJD.js.map +0 -1
  36. package/chunk-D5UYO3OX.js +0 -3
  37. package/chunk-D5UYO3OX.js.map +0 -1
  38. package/chunk-EHLRP4V2.js +0 -2
  39. package/chunk-EHLRP4V2.js.map +0 -1
  40. package/chunk-LMPPDGRD.js +0 -2
  41. package/chunk-LMPPDGRD.js.map +0 -1
  42. package/chunk-MBB2XFH6.js +0 -2
  43. package/chunk-MBB2XFH6.js.map +0 -1
  44. package/chunk-SHSILTWI.js +0 -10
  45. package/chunk-SHSILTWI.js.map +0 -1
  46. package/comptime-DKpw1IVu.d.ts +0 -28
  47. package/matrix-C4IFKU1R.d.ts +0 -123
  48. package/tgpuConstant-BOn7U_lv.d.ts +0 -4031
@@ -1,4031 +0,0 @@
1
- import { FuncParameter, Block, Expression, Statement } from 'tinyest';
2
-
3
- interface MetaData {
4
- v?: number;
5
- name?: string | undefined;
6
- ast?: {
7
- params: FuncParameter[];
8
- body: Block;
9
- externalNames: string[];
10
- } | undefined;
11
- externals?: Record<string, unknown> | (() => Record<string, unknown>) | undefined;
12
- }
13
- /**
14
- * Don't use or you WILL get fired from your job.
15
- *
16
- * The information that this type describes is additional
17
- * properties that we add onto `globalThis`, used by tools
18
- * like `unplugin-typegpu` or our test suite.
19
- *
20
- * @internal
21
- */
22
- type INTERNAL_GlobalExt = typeof globalThis & {
23
- __TYPEGPU_META__: WeakMap<object, MetaData>;
24
- __TYPEGPU_AUTONAME__: <T>(exp: T, label: string) => T;
25
- __TYPEGPU_MEASURE_PERF__?: boolean | undefined;
26
- __TYPEGPU_PERF_RECORDS__?: Map<string, unknown[]> | undefined;
27
- };
28
- /**
29
- * Can be assigned a name. Not to be confused with
30
- * being able to HAVE a name.
31
- * The `$name` function should use `setName` to rename the object itself,
32
- * or rename the object `$getNameForward` symbol points to instead if applicable.
33
- */
34
- interface TgpuNamable {
35
- $name(label: string): this;
36
- }
37
-
38
- type ViewDimensionToDimension = {
39
- '1d': '1d';
40
- '2d': '2d';
41
- '2d-array': '2d';
42
- '3d': '3d';
43
- cube: '2d';
44
- 'cube-array': '2d';
45
- };
46
- type StorageTextureFormats = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16unorm' | 'rgba16snorm' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'rg8unorm' | 'rg8snorm' | 'rg8uint' | 'rg8sint' | 'rg16unorm' | 'rg16snorm' | 'rg16uint' | 'rg16sint' | 'rg16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm' | 'r8unorm' | 'r8snorm' | 'r8uint' | 'r8sint' | 'r16unorm' | 'r16snorm' | 'r16uint' | 'r16sint' | 'r16float' | 'rgb10a2unorm' | 'rgb10a2uint' | 'rg11b10ufloat';
47
- type ParseChannelType<T extends GPUTextureFormat> = T extends `${string}uint${string}` ? 'u32' : T extends `${string}sint${string}` ? 'i32' : 'f32';
48
- type ChannelTypeToSampleType<T extends 'f32' | 'i32' | 'u32'> = {
49
- f32: F32;
50
- i32: I32;
51
- u32: U32;
52
- }[T];
53
- type ChannelTypeToVectorType<T extends 'f32' | 'i32' | 'u32'> = {
54
- f32: Vec4f;
55
- i32: Vec4i;
56
- u32: Vec4u;
57
- }[T];
58
- type TextureFormats = {
59
- [K in GPUTextureFormat]: {
60
- channelType: ChannelTypeToSampleType<ParseChannelType<K>>;
61
- vectorType: ChannelTypeToVectorType<ParseChannelType<K>>;
62
- };
63
- };
64
-
65
- declare const $internal: unique symbol;
66
- /**
67
- * The getter to the value of this resource, accessible on the GPU
68
- */
69
- declare const $gpuValueOf: unique symbol;
70
- declare const $getNameForward: unique symbol;
71
- /**
72
- * Marks an object with slot-value bindings
73
- */
74
- declare const $providing: unique symbol;
75
- declare const $resolve: unique symbol;
76
- /**
77
- * Type token for the inferred (CPU & GPU) representation of a resource
78
- */
79
- declare const $repr: unique symbol;
80
- /**
81
- * Type token for the inferred (GPU-side) representation of a resource
82
- * If present, it shadows the value of `$repr` for GPU-side inference.
83
- */
84
- declare const $gpuRepr: unique symbol;
85
- /**
86
- * Type token for the inferred partial representation of a resource.
87
- * If present, it shadows the value of `$repr` for use in partial IO.
88
- */
89
- declare const $reprPartial: unique symbol;
90
- /**
91
- * Type token holding schemas that are identical in memory layout.
92
- */
93
- declare const $memIdent: unique symbol;
94
- /**
95
- * Type token, signaling that a schema can be used in a storage buffer.
96
- */
97
- declare const $validStorageSchema: unique symbol;
98
- /**
99
- * Type token, signaling that a schema can be used in a uniform buffer.
100
- */
101
- declare const $validUniformSchema: unique symbol;
102
- /**
103
- * Type token, signaling that a schema can be used in a vertex buffer.
104
- */
105
- declare const $validVertexSchema: unique symbol;
106
- /**
107
- * Type token, containing a reason for why the schema is invalid (if it is).
108
- */
109
- declare const $invalidSchemaReason: unique symbol;
110
-
111
- type Default<T, TDefault> = unknown extends T ? TDefault : T extends undefined ? TDefault : T;
112
- type SwapNever<T, Replacement> = [T] extends [never] ? Replacement : T;
113
- type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
114
- type Prettify<T> = {
115
- [K in keyof T]: T[K];
116
- } & {};
117
- /**
118
- * Utility type that merges a partial type with defaults, where defaults are used
119
- * for properties not present in the partial type.
120
- */
121
- type WithDefaults<TPartial, TDefaults> = Omit<TDefaults, keyof TPartial> & TPartial;
122
- /**
123
- * Removes properties from record type that extend `Prop`
124
- */
125
- type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, {
126
- [Key in keyof T]: T[Key] extends Prop ? never : Key;
127
- }[keyof T]>;
128
- type NullableToOptional<T> = {
129
- [K in keyof T as T[K] extends null ? K : never]?: T[K];
130
- } & {
131
- [K in keyof T as T[K] extends null ? never : K]: T[K];
132
- };
133
- /**
134
- * The opposite of Readonly<T>
135
- */
136
- type Mutable<T> = {
137
- -readonly [P in keyof T]: T[P];
138
- };
139
- /**
140
- * Any typed array
141
- */
142
- type TypedArray = Uint8Array | Uint16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
143
-
144
- type StorageTextureDimension = '1d' | '2d' | '2d-array' | '3d';
145
- type WgslTextureProps = {
146
- dimension: GPUTextureViewDimension;
147
- sampleType: TextureSampleTypes;
148
- multisampled: boolean;
149
- };
150
- type WgslStorageTextureProps = {
151
- dimension: StorageTextureDimension;
152
- format: StorageTextureFormats;
153
- access: GPUStorageTextureAccess;
154
- };
155
- type ResolvedTextureProps<TProps extends Partial<WgslTextureProps>> = WithDefaults<TProps, WgslTextureProps>;
156
- type ResolvedStorageTextureProps<TProps extends Partial<WgslStorageTextureProps>> = WithDefaults<TProps, WgslStorageTextureProps>;
157
- type SampledTextureLiteral = `texture_${'1d' | '2d' | '2d_array' | '3d' | 'cube' | 'cube_array' | 'multisampled_2d' | 'depth_multisampled_2d' | 'depth_2d' | 'depth_2d_array' | 'depth_cube' | 'depth_cube_array'}`;
158
- type StorageTextureLiteral = `texture_storage_${'1d' | '2d' | '2d_array' | '3d'}`;
159
- interface WgslTexture<TProps extends Partial<WgslTextureProps> = WgslTextureProps> extends BaseData {
160
- readonly [$repr]: unknown;
161
- readonly type: SampledTextureLiteral;
162
- readonly sampleType: ResolvedTextureProps<TProps>['sampleType'];
163
- readonly dimension: ResolvedTextureProps<TProps>['dimension'];
164
- readonly multisampled: ResolvedTextureProps<TProps>['multisampled'];
165
- readonly bindingSampleType: [GPUTextureSampleType, ...GPUTextureSampleType[]];
166
- }
167
- interface WgslStorageTexture<TProps extends Partial<WgslStorageTextureProps> = WgslStorageTextureProps> extends BaseData {
168
- readonly [$repr]: unknown;
169
- readonly type: StorageTextureLiteral;
170
- readonly format: ResolvedStorageTextureProps<TProps>['format'];
171
- readonly dimension: ResolvedStorageTextureProps<TProps>['dimension'];
172
- readonly access: ResolvedStorageTextureProps<TProps>['access'];
173
- }
174
- interface WgslExternalTexture extends BaseData {
175
- readonly [$repr]: textureExternal;
176
- readonly type: 'texture_external';
177
- readonly dimension: '2d';
178
- }
179
- interface WgslTexture1d<TSample extends TextureSampleTypes = TextureSampleTypes> extends WgslTexture<{
180
- dimension: '1d';
181
- sampleType: TSample;
182
- multisampled: false;
183
- }> {
184
- readonly type: 'texture_1d';
185
- readonly [$repr]: texture1d<TSample>;
186
- }
187
- interface WgslTexture2d<TSample extends TextureSampleTypes = TextureSampleTypes> extends WgslTexture<{
188
- dimension: '2d';
189
- sampleType: TSample;
190
- multisampled: false;
191
- }> {
192
- readonly type: 'texture_2d';
193
- readonly [$repr]: texture2d<TSample>;
194
- }
195
- interface WgslTextureMultisampled2d<TSample extends TextureSampleTypes = TextureSampleTypes> extends WgslTexture<{
196
- dimension: '2d';
197
- sampleType: TSample;
198
- multisampled: true;
199
- }> {
200
- readonly type: 'texture_multisampled_2d';
201
- readonly [$repr]: textureMultisampled2d<TSample>;
202
- }
203
- interface WgslTexture2dArray<TSample extends TextureSampleTypes = TextureSampleTypes> extends WgslTexture<{
204
- dimension: '2d-array';
205
- sampleType: TSample;
206
- multisampled: false;
207
- }> {
208
- readonly type: 'texture_2d_array';
209
- readonly [$repr]: texture2dArray<TSample>;
210
- }
211
- interface WgslTextureCube<TSample extends TextureSampleTypes = TextureSampleTypes> extends WgslTexture<{
212
- dimension: 'cube';
213
- sampleType: TSample;
214
- multisampled: false;
215
- }> {
216
- readonly type: 'texture_cube';
217
- readonly [$repr]: textureCube<TSample>;
218
- }
219
- interface WgslTextureCubeArray<TSample extends TextureSampleTypes = TextureSampleTypes> extends WgslTexture<{
220
- dimension: 'cube-array';
221
- sampleType: TSample;
222
- multisampled: false;
223
- }> {
224
- readonly type: 'texture_cube_array';
225
- readonly [$repr]: textureCubeArray<TSample>;
226
- }
227
- interface WgslTexture3d<TSample extends TextureSampleTypes = TextureSampleTypes> extends WgslTexture<{
228
- dimension: '3d';
229
- sampleType: TSample;
230
- multisampled: false;
231
- }> {
232
- readonly type: 'texture_3d';
233
- readonly [$repr]: texture3d<TSample>;
234
- }
235
- interface WgslTextureDepth2d extends WgslTexture<{
236
- dimension: '2d';
237
- sampleType: F32;
238
- multisampled: false;
239
- }> {
240
- readonly type: 'texture_depth_2d';
241
- readonly [$repr]: textureDepth2d;
242
- }
243
- interface WgslTextureDepthMultisampled2d extends WgslTexture<{
244
- dimension: '2d';
245
- sampleType: F32;
246
- multisampled: true;
247
- }> {
248
- readonly type: 'texture_depth_multisampled_2d';
249
- readonly [$repr]: textureDepthMultisampled2d;
250
- }
251
- interface WgslTextureDepth2dArray extends WgslTexture<{
252
- dimension: '2d-array';
253
- sampleType: F32;
254
- multisampled: false;
255
- }> {
256
- readonly type: 'texture_depth_2d_array';
257
- readonly [$repr]: textureDepth2dArray;
258
- }
259
- interface WgslTextureDepthCube extends WgslTexture<{
260
- dimension: 'cube';
261
- sampleType: F32;
262
- multisampled: false;
263
- }> {
264
- readonly type: 'texture_depth_cube';
265
- readonly [$repr]: textureDepthCube;
266
- }
267
- interface WgslTextureDepthCubeArray extends WgslTexture<{
268
- dimension: 'cube-array';
269
- sampleType: F32;
270
- multisampled: false;
271
- }> {
272
- readonly type: 'texture_depth_cube_array';
273
- readonly [$repr]: textureDepthCubeArray;
274
- }
275
- interface WgslStorageTexture1d<TFormat extends StorageTextureFormats = StorageTextureFormats, TAccess extends GPUStorageTextureAccess = GPUStorageTextureAccess> extends WgslStorageTexture<{
276
- dimension: '1d';
277
- format: TFormat;
278
- access: TAccess;
279
- }> {
280
- readonly type: 'texture_storage_1d';
281
- readonly [$repr]: textureStorage1d<TFormat, TAccess>;
282
- }
283
- interface WgslStorageTexture2d<TFormat extends StorageTextureFormats = StorageTextureFormats, TAccess extends GPUStorageTextureAccess = GPUStorageTextureAccess> extends WgslStorageTexture<{
284
- dimension: '2d';
285
- format: TFormat;
286
- access: TAccess;
287
- }> {
288
- readonly type: 'texture_storage_2d';
289
- readonly [$repr]: textureStorage2d<TFormat, TAccess>;
290
- }
291
- interface WgslStorageTexture2dArray<TFormat extends StorageTextureFormats = StorageTextureFormats, TAccess extends GPUStorageTextureAccess = GPUStorageTextureAccess> extends WgslStorageTexture<{
292
- dimension: '2d-array';
293
- format: TFormat;
294
- access: TAccess;
295
- }> {
296
- readonly type: 'texture_storage_2d_array';
297
- readonly [$repr]: textureStorage2dArray<TFormat, TAccess>;
298
- }
299
- interface WgslStorageTexture3d<TFormat extends StorageTextureFormats = StorageTextureFormats, TAccess extends GPUStorageTextureAccess = GPUStorageTextureAccess> extends WgslStorageTexture<{
300
- dimension: '3d';
301
- format: TFormat;
302
- access: TAccess;
303
- }> {
304
- readonly type: 'texture_storage_3d';
305
- readonly [$repr]: textureStorage3d<TFormat, TAccess>;
306
- }
307
- type SampledTextureSchemaMap<T extends WgslTextureProps> = {
308
- multisampled: {
309
- '1d': never;
310
- '2d': WgslTextureMultisampled2d<T['sampleType']>;
311
- '2d-array': never;
312
- '3d': never;
313
- cube: never;
314
- 'cube-array': never;
315
- };
316
- sampled: {
317
- '1d': WgslTexture1d<T['sampleType']>;
318
- '2d': WgslTexture2d<T['sampleType']>;
319
- '2d-array': WgslTexture2dArray<T['sampleType']>;
320
- '3d': WgslTexture3d<T['sampleType']>;
321
- cube: WgslTextureCube<T['sampleType']>;
322
- 'cube-array': WgslTextureCubeArray<T['sampleType']>;
323
- };
324
- };
325
- type StorageTextureSchemaMap<T extends WgslStorageTextureProps> = {
326
- '1d': WgslStorageTexture1d<T['format'], T['access']>;
327
- '2d': WgslStorageTexture2d<T['format'], T['access']>;
328
- '2d-array': WgslStorageTexture2dArray<T['format'], T['access']>;
329
- '3d': WgslStorageTexture3d<T['format'], T['access']>;
330
- };
331
- type TextureSchemaForDescriptor<T extends WgslTextureProps | WgslStorageTextureProps> = T extends WgslTextureProps ? T['multisampled'] extends true ? SampledTextureSchemaMap<T>['multisampled'][T['dimension']] : SampledTextureSchemaMap<T>['sampled'][T['dimension']] : T extends WgslStorageTextureProps ? StorageTextureSchemaMap<T>[T['dimension']] : never;
332
- interface texture1d<T extends TextureSampleTypes = TextureSampleTypes> {
333
- readonly kind: `texture_1d<${T['type']}>`;
334
- [$internal]: T;
335
- }
336
- declare function texture1d<T extends TextureSampleTypes>(sampleType: T): WgslTexture1d<T>;
337
- declare function texture1d(): WgslTexture1d<F32>;
338
- interface texture2d<T extends TextureSampleTypes = TextureSampleTypes> {
339
- readonly kind: `texture_2d<${T['type']}>`;
340
- [$internal]: T;
341
- }
342
- declare function texture2d<T extends TextureSampleTypes>(sampleType: T): WgslTexture2d<T>;
343
- declare function texture2d(): WgslTexture2d<F32>;
344
- interface textureMultisampled2d<T extends TextureSampleTypes = TextureSampleTypes> {
345
- readonly kind: `texture_multisampled_2d<${T['type']}>`;
346
- [$internal]: T;
347
- }
348
- declare function textureMultisampled2d<T extends TextureSampleTypes>(sampleType: T): WgslTextureMultisampled2d<T>;
349
- declare function textureMultisampled2d(): WgslTextureMultisampled2d<F32>;
350
- interface texture2dArray<T extends TextureSampleTypes = TextureSampleTypes> {
351
- readonly kind: `texture_2d_array<${T['type']}>`;
352
- [$internal]: T;
353
- }
354
- declare function texture2dArray<T extends TextureSampleTypes>(sampleType: T): WgslTexture2dArray<T>;
355
- declare function texture2dArray(): WgslTexture2dArray<F32>;
356
- interface textureCube<T extends TextureSampleTypes = TextureSampleTypes> {
357
- readonly kind: `texture_cube<${T['type']}>`;
358
- [$internal]: T;
359
- }
360
- declare function textureCube<T extends TextureSampleTypes>(sampleType: T): WgslTextureCube<T>;
361
- declare function textureCube(): WgslTextureCube<F32>;
362
- interface textureCubeArray<T extends TextureSampleTypes = TextureSampleTypes> {
363
- readonly kind: `texture_cube_array<${T['type']}>`;
364
- [$internal]: T;
365
- }
366
- declare function textureCubeArray<T extends TextureSampleTypes>(sampleType: T): WgslTextureCubeArray<T>;
367
- declare function textureCubeArray(): WgslTextureCubeArray<F32>;
368
- interface texture3d<T extends TextureSampleTypes = TextureSampleTypes> {
369
- readonly kind: `texture_3d<${T['type']}>`;
370
- [$internal]: T;
371
- }
372
- declare function texture3d<T extends TextureSampleTypes>(sampleType: T): WgslTexture3d<T>;
373
- declare function texture3d(): WgslTexture3d<F32>;
374
- interface textureStorage1d<TFormat extends StorageTextureFormats = StorageTextureFormats, TAccess extends GPUStorageTextureAccess = GPUStorageTextureAccess> {
375
- readonly kind: `texture_storage_1d<${TFormat}, ${TAccess}>`;
376
- [$internal]: [TFormat, TAccess];
377
- }
378
- declare function textureStorage1d<TFormat extends StorageTextureFormats, TAccess extends GPUStorageTextureAccess>(format: TFormat, access: TAccess): WgslStorageTexture1d<TFormat, TAccess>;
379
- declare function textureStorage1d<TFormat extends StorageTextureFormats>(format: TFormat): WgslStorageTexture1d<TFormat, 'write-only'>;
380
- interface textureStorage2d<TFormat extends StorageTextureFormats = StorageTextureFormats, TAccess extends GPUStorageTextureAccess = GPUStorageTextureAccess> {
381
- readonly kind: `texture_storage_2d<${TFormat}, ${TAccess}>`;
382
- [$internal]: [TFormat, TAccess];
383
- }
384
- declare function textureStorage2d<TFormat extends StorageTextureFormats, TAccess extends GPUStorageTextureAccess>(format: TFormat, access: TAccess): WgslStorageTexture2d<TFormat, TAccess>;
385
- declare function textureStorage2d<TFormat extends StorageTextureFormats>(format: TFormat): WgslStorageTexture2d<TFormat, 'write-only'>;
386
- interface textureStorage2dArray<TFormat extends StorageTextureFormats = StorageTextureFormats, TAccess extends GPUStorageTextureAccess = GPUStorageTextureAccess> {
387
- readonly kind: `texture_storage_2d_array<${TFormat}, ${TAccess}>`;
388
- [$internal]: [TFormat, TAccess];
389
- }
390
- declare function textureStorage2dArray<TFormat extends StorageTextureFormats, TAccess extends GPUStorageTextureAccess>(format: TFormat, access: TAccess): WgslStorageTexture2dArray<TFormat, TAccess>;
391
- declare function textureStorage2dArray<TFormat extends StorageTextureFormats>(format: TFormat): WgslStorageTexture2dArray<TFormat, 'write-only'>;
392
- interface textureStorage3d<TFormat extends StorageTextureFormats = StorageTextureFormats, TAccess extends GPUStorageTextureAccess = GPUStorageTextureAccess> {
393
- readonly kind: `texture_storage_3d<${TFormat}, ${TAccess}>`;
394
- [$internal]: [TFormat, TAccess];
395
- }
396
- declare function textureStorage3d<TFormat extends StorageTextureFormats, TAccess extends GPUStorageTextureAccess>(format: TFormat, access: TAccess): WgslStorageTexture3d<TFormat, TAccess>;
397
- declare function textureStorage3d<TFormat extends StorageTextureFormats>(format: TFormat): WgslStorageTexture3d<TFormat, 'write-only'>;
398
- interface textureDepth2d {
399
- readonly kind: 'texture_depth_2d';
400
- [$internal]: F32;
401
- }
402
- declare function textureDepth2d(): WgslTextureDepth2d;
403
- interface textureDepthMultisampled2d {
404
- readonly kind: 'texture_depth_multisampled_2d';
405
- [$internal]: F32;
406
- }
407
- declare function textureDepthMultisampled2d(): WgslTextureDepthMultisampled2d;
408
- interface textureDepth2dArray {
409
- readonly kind: 'texture_depth_2d_array';
410
- [$internal]: F32;
411
- }
412
- declare function textureDepth2dArray(): WgslTextureDepth2dArray;
413
- interface textureDepthCube {
414
- readonly kind: 'texture_depth_cube';
415
- [$internal]: F32;
416
- }
417
- declare function textureDepthCube(): WgslTextureDepthCube;
418
- interface textureDepthCubeArray {
419
- readonly kind: 'texture_depth_cube_array';
420
- [$internal]: F32;
421
- }
422
- declare function textureDepthCubeArray(): WgslTextureDepthCubeArray;
423
- interface textureExternal {
424
- readonly kind: 'texture_external';
425
- [$internal]: true;
426
- }
427
- declare function textureExternal(): WgslExternalTexture;
428
-
429
- 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"];
430
- type VertexFormat = (typeof vertexFormats)[number];
431
- declare const kindToDefaultFormatMap: {
432
- readonly f32: "float32";
433
- readonly vec2f: "float32x2";
434
- readonly vec3f: "float32x3";
435
- readonly vec4f: "float32x4";
436
- readonly f16: "float16";
437
- readonly vec2h: "float16x2";
438
- readonly vec4h: "float16x4";
439
- readonly u32: "uint32";
440
- readonly vec2u: "uint32x2";
441
- readonly vec3u: "uint32x3";
442
- readonly vec4u: "uint32x4";
443
- readonly i32: "sint32";
444
- readonly vec2i: "sint32x2";
445
- readonly vec3i: "sint32x3";
446
- readonly vec4i: "sint32x4";
447
- };
448
- type KindToDefaultFormatMap = typeof kindToDefaultFormatMap;
449
- interface TgpuVertexAttrib<TFormat extends VertexFormat = VertexFormat> {
450
- readonly format: TFormat;
451
- readonly offset: number;
452
- }
453
- type AnyVertexAttribs = Record<string, TgpuVertexAttrib> | TgpuVertexAttrib;
454
- /**
455
- * All vertex attribute formats that can be interpreted as
456
- * an single or multi component u32 in a shader.
457
- * https://www.w3.org/TR/webgpu/#vertex-formats
458
- */
459
- type U32CompatibleFormats = TgpuVertexAttrib<'uint8'> | TgpuVertexAttrib<'uint8x2'> | TgpuVertexAttrib<'uint8x4'> | TgpuVertexAttrib<'uint16'> | TgpuVertexAttrib<'uint16x2'> | TgpuVertexAttrib<'uint16x4'> | TgpuVertexAttrib<'uint32'> | TgpuVertexAttrib<'uint32x2'> | TgpuVertexAttrib<'uint32x3'> | TgpuVertexAttrib<'uint32x4'>;
460
- /**
461
- * All vertex attribute formats that can be interpreted as
462
- * an single or multi component i32 in a shader.
463
- * https://www.w3.org/TR/webgpu/#vertex-formats
464
- */
465
- type I32CompatibleFormats = TgpuVertexAttrib<'sint8'> | TgpuVertexAttrib<'sint8x2'> | TgpuVertexAttrib<'sint8x4'> | TgpuVertexAttrib<'sint16'> | TgpuVertexAttrib<'sint16x2'> | TgpuVertexAttrib<'sint16x4'> | TgpuVertexAttrib<'sint32'> | TgpuVertexAttrib<'sint32x2'> | TgpuVertexAttrib<'sint32x3'> | TgpuVertexAttrib<'sint32x4'>;
466
- /**
467
- * All vertex attribute formats that can be interpreted as
468
- * an single or multi component f32 in a shader.
469
- * https://www.w3.org/TR/webgpu/#vertex-formats
470
- */
471
- type F32CompatibleFormats = TgpuVertexAttrib<'unorm8'> | TgpuVertexAttrib<'unorm8x2'> | TgpuVertexAttrib<'unorm8x4'> | TgpuVertexAttrib<'snorm8'> | TgpuVertexAttrib<'snorm8x2'> | TgpuVertexAttrib<'snorm8x4'> | TgpuVertexAttrib<'unorm16'> | TgpuVertexAttrib<'unorm16x2'> | TgpuVertexAttrib<'unorm16x4'> | TgpuVertexAttrib<'snorm16'> | TgpuVertexAttrib<'snorm16x2'> | TgpuVertexAttrib<'snorm16x4'> | TgpuVertexAttrib<'float16'> | TgpuVertexAttrib<'float16x2'> | TgpuVertexAttrib<'float16x4'> | TgpuVertexAttrib<'float32'> | TgpuVertexAttrib<'float32x2'> | TgpuVertexAttrib<'float32x3'> | TgpuVertexAttrib<'float32x4'> | TgpuVertexAttrib<'unorm10-10-10-2'> | TgpuVertexAttrib<'unorm8x4-bgra'>;
472
- /**
473
- * All vertex attribute formats that can be interpreted as
474
- * a single or multi component f16 in a shader. (same as f32 on the shader side)
475
- * https://www.w3.org/TR/webgpu/#vertex-formats
476
- */
477
- type F16CompatibleFormats = F32CompatibleFormats;
478
- type KindToAcceptedAttribMap = {
479
- u32: U32CompatibleFormats;
480
- vec2u: U32CompatibleFormats;
481
- vec3u: U32CompatibleFormats;
482
- vec4u: U32CompatibleFormats;
483
- i32: I32CompatibleFormats;
484
- vec2i: I32CompatibleFormats;
485
- vec3i: I32CompatibleFormats;
486
- vec4i: I32CompatibleFormats;
487
- f16: F16CompatibleFormats;
488
- vec2h: F16CompatibleFormats;
489
- vec3h: F16CompatibleFormats;
490
- vec4h: F16CompatibleFormats;
491
- f32: F32CompatibleFormats;
492
- vec2f: F32CompatibleFormats;
493
- vec3f: F32CompatibleFormats;
494
- vec4f: F32CompatibleFormats;
495
- };
496
-
497
- type FormatToWGSLType<T extends VertexFormat> = (typeof formatToWGSLType)[T];
498
- interface TgpuVertexFormatData<T extends VertexFormat> extends BaseData {
499
- readonly type: T;
500
- readonly [$repr]: Infer<FormatToWGSLType<T>>;
501
- readonly [$validVertexSchema]: true;
502
- readonly [$invalidSchemaReason]: 'Vertex formats are not host-shareable, use concrete types instead';
503
- }
504
- declare const formatToWGSLType: {
505
- readonly uint8: U32;
506
- readonly uint8x2: Vec2u;
507
- readonly uint8x4: Vec4u;
508
- readonly sint8: I32;
509
- readonly sint8x2: Vec2i;
510
- readonly sint8x4: Vec4i;
511
- readonly unorm8: F32;
512
- readonly unorm8x2: Vec2f;
513
- readonly unorm8x4: Vec4f;
514
- readonly snorm8: F32;
515
- readonly snorm8x2: Vec2f;
516
- readonly snorm8x4: Vec4f;
517
- readonly uint16: U32;
518
- readonly uint16x2: Vec2u;
519
- readonly uint16x4: Vec4u;
520
- readonly sint16: I32;
521
- readonly sint16x2: Vec2i;
522
- readonly sint16x4: Vec4i;
523
- readonly unorm16: F32;
524
- readonly unorm16x2: Vec2f;
525
- readonly unorm16x4: Vec4f;
526
- readonly snorm16: F32;
527
- readonly snorm16x2: Vec2f;
528
- readonly snorm16x4: Vec4f;
529
- readonly float16: F32;
530
- readonly float16x2: Vec2f;
531
- readonly float16x4: Vec4f;
532
- readonly float32: F32;
533
- readonly float32x2: Vec2f;
534
- readonly float32x3: Vec3f;
535
- readonly float32x4: Vec4f;
536
- readonly uint32: U32;
537
- readonly uint32x2: Vec2u;
538
- readonly uint32x3: Vec3u;
539
- readonly uint32x4: Vec4u;
540
- readonly sint32: I32;
541
- readonly sint32x2: Vec2i;
542
- readonly sint32x3: Vec3i;
543
- readonly sint32x4: Vec4i;
544
- readonly 'unorm10-10-10-2': Vec4f;
545
- readonly 'unorm8x4-bgra': Vec4f;
546
- };
547
- declare const packedFormats: Set<string>;
548
- type uint8 = TgpuVertexFormatData<'uint8'>;
549
- declare const uint8: uint8;
550
- type uint8x2 = TgpuVertexFormatData<'uint8x2'>;
551
- declare const uint8x2: uint8x2;
552
- type uint8x4 = TgpuVertexFormatData<'uint8x4'>;
553
- declare const uint8x4: uint8x4;
554
- type sint8 = TgpuVertexFormatData<'sint8'>;
555
- declare const sint8: sint8;
556
- type sint8x2 = TgpuVertexFormatData<'sint8x2'>;
557
- declare const sint8x2: sint8x2;
558
- type sint8x4 = TgpuVertexFormatData<'sint8x4'>;
559
- declare const sint8x4: sint8x4;
560
- type unorm8 = TgpuVertexFormatData<'unorm8'>;
561
- declare const unorm8: unorm8;
562
- type unorm8x2 = TgpuVertexFormatData<'unorm8x2'>;
563
- declare const unorm8x2: unorm8x2;
564
- type unorm8x4 = TgpuVertexFormatData<'unorm8x4'>;
565
- declare const unorm8x4: unorm8x4;
566
- type snorm8 = TgpuVertexFormatData<'snorm8'>;
567
- declare const snorm8: snorm8;
568
- type snorm8x2 = TgpuVertexFormatData<'snorm8x2'>;
569
- declare const snorm8x2: snorm8x2;
570
- type snorm8x4 = TgpuVertexFormatData<'snorm8x4'>;
571
- declare const snorm8x4: snorm8x4;
572
- type uint16 = TgpuVertexFormatData<'uint16'>;
573
- declare const uint16: uint16;
574
- type uint16x2 = TgpuVertexFormatData<'uint16x2'>;
575
- declare const uint16x2: uint16x2;
576
- type uint16x4 = TgpuVertexFormatData<'uint16x4'>;
577
- declare const uint16x4: uint16x4;
578
- type sint16 = TgpuVertexFormatData<'sint16'>;
579
- declare const sint16: sint16;
580
- type sint16x2 = TgpuVertexFormatData<'sint16x2'>;
581
- declare const sint16x2: sint16x2;
582
- type sint16x4 = TgpuVertexFormatData<'sint16x4'>;
583
- declare const sint16x4: sint16x4;
584
- type unorm16 = TgpuVertexFormatData<'unorm16'>;
585
- declare const unorm16: unorm16;
586
- type unorm16x2 = TgpuVertexFormatData<'unorm16x2'>;
587
- declare const unorm16x2: unorm16x2;
588
- type unorm16x4 = TgpuVertexFormatData<'unorm16x4'>;
589
- declare const unorm16x4: unorm16x4;
590
- type snorm16 = TgpuVertexFormatData<'snorm16'>;
591
- declare const snorm16: snorm16;
592
- type snorm16x2 = TgpuVertexFormatData<'snorm16x2'>;
593
- declare const snorm16x2: snorm16x2;
594
- type snorm16x4 = TgpuVertexFormatData<'snorm16x4'>;
595
- declare const snorm16x4: snorm16x4;
596
- type float16 = TgpuVertexFormatData<'float16'>;
597
- declare const float16: float16;
598
- type float16x2 = TgpuVertexFormatData<'float16x2'>;
599
- declare const float16x2: float16x2;
600
- type float16x4 = TgpuVertexFormatData<'float16x4'>;
601
- declare const float16x4: float16x4;
602
- type float32 = TgpuVertexFormatData<'float32'>;
603
- declare const float32: float32;
604
- type float32x2 = TgpuVertexFormatData<'float32x2'>;
605
- declare const float32x2: float32x2;
606
- type float32x3 = TgpuVertexFormatData<'float32x3'>;
607
- declare const float32x3: float32x3;
608
- type float32x4 = TgpuVertexFormatData<'float32x4'>;
609
- declare const float32x4: float32x4;
610
- type uint32 = TgpuVertexFormatData<'uint32'>;
611
- declare const uint32: uint32;
612
- type uint32x2 = TgpuVertexFormatData<'uint32x2'>;
613
- declare const uint32x2: uint32x2;
614
- type uint32x3 = TgpuVertexFormatData<'uint32x3'>;
615
- declare const uint32x3: uint32x3;
616
- type uint32x4 = TgpuVertexFormatData<'uint32x4'>;
617
- declare const uint32x4: uint32x4;
618
- type sint32 = TgpuVertexFormatData<'sint32'>;
619
- declare const sint32: sint32;
620
- type sint32x2 = TgpuVertexFormatData<'sint32x2'>;
621
- declare const sint32x2: sint32x2;
622
- type sint32x3 = TgpuVertexFormatData<'sint32x3'>;
623
- declare const sint32x3: sint32x3;
624
- type sint32x4 = TgpuVertexFormatData<'sint32x4'>;
625
- declare const sint32x4: sint32x4;
626
- type unorm10_10_10_2 = TgpuVertexFormatData<'unorm10-10-10-2'>;
627
- declare const unorm10_10_10_2: unorm10_10_10_2;
628
- type unorm8x4_bgra = TgpuVertexFormatData<'unorm8x4-bgra'>;
629
- declare const unorm8x4_bgra: unorm8x4_bgra;
630
- 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;
631
- declare function isPackedData(value: unknown): value is PackedData;
632
-
633
- interface WgslSamplerProps {
634
- addressModeU?: GPUAddressMode;
635
- addressModeV?: GPUAddressMode;
636
- /**
637
- * Specifies the address modes for the texture width, height, and depth
638
- * coordinates, respectively.
639
- */
640
- addressModeW?: GPUAddressMode;
641
- /**
642
- * Specifies the sampling behavior when the sample footprint is smaller than or equal to one
643
- * texel.
644
- */
645
- magFilter?: GPUFilterMode;
646
- /**
647
- * Specifies the sampling behavior when the sample footprint is larger than one texel.
648
- */
649
- minFilter?: GPUFilterMode;
650
- /**
651
- * Specifies behavior for sampling between mipmap levels.
652
- */
653
- mipmapFilter?: GPUMipmapFilterMode;
654
- lodMinClamp?: number;
655
- /**
656
- * Specifies the minimum and maximum levels of detail, respectively, used internally when
657
- * sampling a texture.
658
- */
659
- lodMaxClamp?: number;
660
- /**
661
- * Specifies the maximum anisotropy value clamp used by the sampler. Anisotropic filtering is
662
- * enabled when {@link GPUSamplerDescriptor.maxAnisotropy} is > 1 and the implementation supports it.
663
- * Anisotropic filtering improves the image quality of textures sampled at oblique viewing
664
- * angles. Higher {@link GPUSamplerDescriptor.maxAnisotropy} values indicate the maximum ratio of
665
- * anisotropy supported when filtering.
666
- *
667
- * Most implementations support {@link GPUSamplerDescriptor.maxAnisotropy} values in range
668
- * between 1 and 16, inclusive. The used value of {@link GPUSamplerDescriptor.maxAnisotropy}
669
- * will be clamped to the maximum value that the platform supports.
670
- * The precise filtering behavior is implementation-dependent.
671
- */
672
- maxAnisotropy?: number;
673
- }
674
- interface WgslComparisonSamplerProps {
675
- compare: GPUCompareFunction;
676
- addressModeU?: GPUAddressMode;
677
- addressModeV?: GPUAddressMode;
678
- /**
679
- * Specifies the address modes for the texture width, height, and depth
680
- * coordinates, respectively.
681
- */
682
- addressModeW?: GPUAddressMode;
683
- /**
684
- * Specifies the sampling behavior when the sample footprint is smaller than or equal to one
685
- * texel.
686
- */
687
- magFilter?: GPUFilterMode;
688
- /**
689
- * Specifies the sampling behavior when the sample footprint is larger than one texel.
690
- */
691
- minFilter?: GPUFilterMode;
692
- /**
693
- * Specifies behavior for sampling between mipmap levels.
694
- */
695
- mipmapFilter?: GPUMipmapFilterMode;
696
- lodMinClamp?: number;
697
- /**
698
- * Specifies the minimum and maximum levels of detail, respectively, used internally when
699
- * sampling a texture.
700
- */
701
- lodMaxClamp?: number;
702
- /**
703
- * Specifies the maximum anisotropy value clamp used by the sampler. Anisotropic filtering is
704
- * enabled when {@link GPUSamplerDescriptor.maxAnisotropy} is > 1 and the implementation supports it.
705
- * Anisotropic filtering improves the image quality of textures sampled at oblique viewing
706
- * angles. Higher {@link GPUSamplerDescriptor.maxAnisotropy} values indicate the maximum ratio of
707
- * anisotropy supported when filtering.
708
- *
709
- * Most implementations support {@link GPUSamplerDescriptor.maxAnisotropy} values in range
710
- * between 1 and 16, inclusive. The used value of {@link GPUSamplerDescriptor.maxAnisotropy}
711
- * will be clamped to the maximum value that the platform supports.
712
- * The precise filtering behavior is implementation-dependent.
713
- */
714
- maxAnisotropy?: number;
715
- }
716
- interface sampler {
717
- [$internal]: true;
718
- type: 'sampler';
719
- }
720
- declare function sampler(): WgslSampler;
721
- interface comparisonSampler {
722
- [$internal]: true;
723
- type: 'sampler_comparison';
724
- }
725
- declare function comparisonSampler(): WgslComparisonSampler;
726
- interface WgslSampler extends BaseData {
727
- readonly [$repr]: sampler;
728
- readonly type: 'sampler';
729
- }
730
- interface WgslComparisonSampler extends BaseData {
731
- readonly [$repr]: comparisonSampler;
732
- readonly type: 'sampler_comparison';
733
- }
734
-
735
- /**
736
- * Array schema constructed via `d.disarrayOf` function.
737
- *
738
- * Useful for defining vertex buffers.
739
- * Elements in the schema are not aligned in respect to their `byteAlignment`,
740
- * unless they are explicitly decorated with the custom align attribute
741
- * via `d.align` function.
742
- */
743
- interface Disarray<TElement extends BaseData = BaseData> extends BaseData {
744
- <T extends TElement>(elements: Infer<T>[]): Infer<T>[];
745
- (): Infer<TElement>[];
746
- readonly type: 'disarray';
747
- readonly elementCount: number;
748
- readonly elementType: TElement;
749
- readonly [$repr]: Infer<TElement>[];
750
- readonly [$reprPartial]: {
751
- idx: number;
752
- value: InferPartial<TElement>;
753
- }[] | undefined;
754
- readonly [$validVertexSchema]: IsValidVertexSchema<TElement>;
755
- readonly [$invalidSchemaReason]: 'Disarrays are not host-shareable, use arrays instead';
756
- }
757
- /**
758
- * Struct schema constructed via `d.unstruct` function.
759
- *
760
- * Useful for defining vertex buffers, as the standard layout restrictions do not apply.
761
- * Members are not aligned in respect to their `byteAlignment`,
762
- * unless they are explicitly decorated with the custom align attribute
763
- * via `d.align` function.
764
- */
765
- interface Unstruct<TProps extends Record<string, BaseData> = any> extends BaseData, TgpuNamable {
766
- (props: Prettify<InferRecord<TProps>>): Prettify<InferRecord<TProps>>;
767
- (): Prettify<InferRecord<TProps>>;
768
- readonly type: 'unstruct';
769
- readonly propTypes: TProps;
770
- readonly [$repr]: Prettify<InferRecord<TProps>>;
771
- readonly [$gpuRepr]: Prettify<InferGPURecord<TProps>>;
772
- readonly [$memIdent]: Unstruct<Prettify<MemIdentityRecord<TProps>>>;
773
- readonly [$reprPartial]: Prettify<Partial<InferPartialRecord<TProps>>> | undefined;
774
- readonly [$validVertexSchema]: {
775
- [K in keyof TProps]: IsValidVertexSchema<TProps[K]>;
776
- }[keyof TProps] extends true ? true : false;
777
- readonly [$invalidSchemaReason]: 'Unstructs are not host-shareable, use structs instead';
778
- }
779
- interface LooseDecorated<TInner extends BaseData = BaseData, TAttribs extends unknown[] = unknown[]> extends BaseData {
780
- readonly type: 'loose-decorated';
781
- readonly inner: TInner;
782
- readonly attribs: TAttribs;
783
- readonly [$repr]: Infer<TInner>;
784
- readonly [$invalidSchemaReason]: 'Loosely decorated schemas are not host-shareable';
785
- readonly [$validVertexSchema]: IsValidVertexSchema<TInner>;
786
- }
787
- /**
788
- * Type utility to extract the inner type from decorated types.
789
- */
790
- type Undecorate<T> = T extends {
791
- readonly type: 'decorated' | 'loose-decorated';
792
- readonly inner: infer TInner;
793
- } ? TInner : T;
794
- /**
795
- * Type utility to undecorate all values in a record.
796
- */
797
- type UndecorateRecord<T extends Record<string, unknown>> = {
798
- [Key in keyof T]: Undecorate<T[Key]>;
799
- };
800
- 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"];
801
- type LooseTypeLiteral = (typeof looseTypeLiterals)[number];
802
- type AnyLooseData = Disarray | Unstruct | LooseDecorated | PackedData;
803
- declare function isLooseData(data: unknown): data is AnyLooseData;
804
- /**
805
- * Checks whether the passed in value is a disarray schema,
806
- * as opposed to, e.g., a regular array schema.
807
- *
808
- * Array schemas can be used to describe uniform and storage buffers,
809
- * whereas disarray schemas cannot. Disarrays are useful for
810
- * defining vertex buffers instead.
811
- *
812
- * @example
813
- * isDisarray(d.arrayOf(d.u32, 4)) // false
814
- * isDisarray(d.disarrayOf(d.u32, 4)) // true
815
- * isDisarray(d.vec3f) // false
816
- */
817
- declare function isDisarray<T extends Disarray>(schema: T | unknown): schema is T;
818
- /**
819
- * Checks whether passed in value is a unstruct schema,
820
- * as opposed to, e.g., a struct schema.
821
- *
822
- * Struct schemas can be used to describe uniform and storage buffers,
823
- * whereas unstruct schemas cannot. Unstructs are useful for
824
- * defining vertex buffers instead.
825
- *
826
- * @example
827
- * isUnstruct(d.struct({ a: d.u32 })) // false
828
- * isUnstruct(d.unstruct({ a: d.u32 })) // true
829
- * isUnstruct(d.vec3f) // false
830
- */
831
- declare function isUnstruct<T extends Unstruct>(schema: T | unknown): schema is T;
832
- declare function isLooseDecorated<T extends LooseDecorated>(value: T | unknown): value is T;
833
- declare function isData(value: unknown): value is AnyData;
834
- type AnyData = AnyWgslData | AnyLooseData;
835
- interface UnknownData {
836
- readonly type: 'unknown';
837
- }
838
- declare const UnknownData: UnknownData;
839
-
840
- type Origin = 'uniform' | 'readonly' | 'mutable' | 'workgroup' | 'private' | 'function' | 'this-function' | 'handle' | 'argument' | 'runtime' | 'constant' | 'constant-tgpu-const-ref' | 'runtime-tgpu-const-ref';
841
- interface Snippet {
842
- readonly value: unknown;
843
- /**
844
- * The type that `value` is assignable to (not necessary exactly inferred as).
845
- * E.g. `1.1` is assignable to `f32`, but `1.1` itself is an abstract float
846
- */
847
- readonly dataType: AnyData | UnknownData;
848
- readonly origin: Origin;
849
- }
850
- interface ResolvedSnippet {
851
- readonly value: string;
852
- /**
853
- * The type that `value` is assignable to (not necessary exactly inferred as).
854
- * E.g. `1.1` is assignable to `f32`, but `1.1` itself is an abstract float
855
- */
856
- readonly dataType: AnyData;
857
- readonly origin: Origin;
858
- }
859
- type MapValueToSnippet<T> = {
860
- [K in keyof T]: Snippet;
861
- };
862
-
863
- interface StorageFlag {
864
- usableAsStorage: true;
865
- }
866
- /**
867
- * @deprecated Use StorageFlag instead.
868
- */
869
- type Storage = StorageFlag;
870
- declare function isUsableAsStorage<T>(value: T): value is T & StorageFlag;
871
-
872
- type BuiltinVertexIndex = Decorated<U32, [Builtin<'vertex_index'>]>;
873
- type BuiltinInstanceIndex = Decorated<U32, [Builtin<'instance_index'>]>;
874
- type BuiltinPosition = Decorated<Vec4f, [Builtin<'position'>]>;
875
- type BuiltinClipDistances = Decorated<WgslArray<U32>, [
876
- Builtin<'clip_distances'>
877
- ]>;
878
- type BuiltinFrontFacing = Decorated<Bool, [Builtin<'front_facing'>]>;
879
- type BuiltinFragDepth = Decorated<F32, [Builtin<'frag_depth'>]>;
880
- type BuiltinSampleIndex = Decorated<U32, [Builtin<'sample_index'>]>;
881
- type BuiltinSampleMask = Decorated<U32, [Builtin<'sample_mask'>]>;
882
- type BuiltinLocalInvocationId = Decorated<Vec3u, [
883
- Builtin<'local_invocation_id'>
884
- ]>;
885
- type BuiltinLocalInvocationIndex = Decorated<U32, [
886
- Builtin<'local_invocation_index'>
887
- ]>;
888
- type BuiltinGlobalInvocationId = Decorated<Vec3u, [
889
- Builtin<'global_invocation_id'>
890
- ]>;
891
- type BuiltinWorkgroupId = Decorated<Vec3u, [Builtin<'workgroup_id'>]>;
892
- type BuiltinNumWorkgroups = Decorated<Vec3u, [
893
- Builtin<'num_workgroups'>
894
- ]>;
895
- type BuiltinSubgroupInvocationId = Decorated<U32, [
896
- Builtin<'subgroup_invocation_id'>
897
- ]>;
898
- type BuiltinSubgroupSize = Decorated<U32, [Builtin<'subgroup_size'>]>;
899
- declare const builtin: {
900
- readonly vertexIndex: BuiltinVertexIndex;
901
- readonly instanceIndex: BuiltinInstanceIndex;
902
- readonly position: BuiltinPosition;
903
- readonly clipDistances: BuiltinClipDistances;
904
- readonly frontFacing: BuiltinFrontFacing;
905
- readonly fragDepth: BuiltinFragDepth;
906
- readonly sampleIndex: BuiltinSampleIndex;
907
- readonly sampleMask: BuiltinSampleMask;
908
- readonly localInvocationId: BuiltinLocalInvocationId;
909
- readonly localInvocationIndex: BuiltinLocalInvocationIndex;
910
- readonly globalInvocationId: BuiltinGlobalInvocationId;
911
- readonly workgroupId: BuiltinWorkgroupId;
912
- readonly numWorkgroups: BuiltinNumWorkgroups;
913
- readonly subgroupInvocationId: BuiltinSubgroupInvocationId;
914
- readonly subgroupSize: BuiltinSubgroupSize;
915
- };
916
- type AnyBuiltin = (typeof builtin)[keyof typeof builtin];
917
- type AnyComputeBuiltin = BuiltinLocalInvocationId | BuiltinLocalInvocationIndex | BuiltinGlobalInvocationId | BuiltinWorkgroupId | BuiltinNumWorkgroups | BuiltinSubgroupInvocationId | BuiltinSubgroupSize;
918
- type AnyVertexInputBuiltin = BuiltinVertexIndex | BuiltinInstanceIndex;
919
- type AnyVertexOutputBuiltin = BuiltinClipDistances | BuiltinPosition;
920
- type AnyFragmentInputBuiltin = BuiltinPosition | BuiltinFrontFacing | BuiltinSampleIndex | BuiltinSampleMask | BuiltinSubgroupInvocationId | BuiltinSubgroupSize;
921
- type AnyFragmentOutputBuiltin = BuiltinFragDepth | BuiltinSampleMask;
922
- type OmitBuiltins<S> = S extends AnyBuiltin ? never : S extends BaseData ? S : {
923
- [Key in keyof S as S[Key] extends AnyBuiltin ? never : Key]: S[Key];
924
- };
925
-
926
- interface TgpuQuerySet<T extends GPUQueryType> extends TgpuNamable {
927
- readonly resourceType: 'query-set';
928
- readonly type: T;
929
- readonly count: number;
930
- readonly querySet: GPUQuerySet;
931
- readonly destroyed: boolean;
932
- readonly available: boolean;
933
- readonly [$internal]: {
934
- readonly readBuffer: GPUBuffer;
935
- readonly resolveBuffer: GPUBuffer;
936
- };
937
- resolve(): void;
938
- read(): Promise<bigint[]>;
939
- destroy(): void;
940
- }
941
-
942
- interface TgpuBufferUsage<TData extends BaseData = BaseData, TUsage extends BindableBufferUsage = BindableBufferUsage> {
943
- readonly resourceType: 'buffer-usage';
944
- readonly usage: TUsage;
945
- readonly [$repr]: Infer<TData>;
946
- readonly [$gpuValueOf]: InferGPU<TData>;
947
- value: InferGPU<TData>;
948
- $: InferGPU<TData>;
949
- readonly [$internal]: {
950
- readonly dataType: TData;
951
- };
952
- }
953
- interface TgpuBufferUniform<TData extends BaseData> extends TgpuBufferUsage<TData, 'uniform'> {
954
- readonly value: InferGPU<TData>;
955
- readonly $: InferGPU<TData>;
956
- }
957
- interface TgpuBufferReadonly<TData extends BaseData> extends TgpuBufferUsage<TData, 'readonly'> {
958
- readonly value: InferGPU<TData>;
959
- readonly $: InferGPU<TData>;
960
- }
961
- interface TgpuFixedBufferUsage<TData extends BaseData> extends TgpuNamable {
962
- readonly buffer: TgpuBuffer<TData>;
963
- }
964
- interface TgpuBufferMutable<TData extends BaseData> extends TgpuBufferUsage<TData, 'mutable'> {
965
- }
966
- declare function isUsableAsUniform<T extends TgpuBuffer<AnyData>>(buffer: T): buffer is T & UniformFlag;
967
-
968
- /**
969
- * Extra declaration that shall be included in final WGSL code,
970
- * when resolving objects that use it.
971
- */
972
- interface TgpuDeclare {
973
- $uses(dependencyMap: Record<string, unknown>): this;
974
- }
975
- /**
976
- * Allows defining extra declarations that shall be included in the final WGSL code,
977
- * when resolving objects that use them.
978
- *
979
- * Using this API is generally discouraged, as it shouldn't be necessary in any common scenario.
980
- * It was developed to ensure full compatibility of TypeGPU programs with current and future versions of WGSL.
981
- */
982
- declare function declare(declaration: string): TgpuDeclare;
983
-
984
- declare const builtinNames: readonly ["vertex_index", "instance_index", "position", "clip_distances", "front_facing", "frag_depth", "sample_index", "sample_mask", "fragment", "local_invocation_id", "local_invocation_index", "global_invocation_id", "workgroup_id", "num_workgroups", "subgroup_invocation_id", "subgroup_size"];
985
- type BuiltinName = (typeof builtinNames)[number];
986
- type AnyAttribute<AllowedBuiltins extends Builtin<BuiltinName> = Builtin<BuiltinName>> = Align<number> | Size<number> | Location<number> | Interpolate<InterpolationType> | Invariant | AllowedBuiltins;
987
- type ExtractAttributes<T> = T extends {
988
- readonly attribs: unknown[];
989
- } ? T['attribs'] : [];
990
- /**
991
- * Decorates a data-type `TData` with an attribute `TAttrib`.
992
- *
993
- * - if `TData` is loose
994
- * - if `TData` is already `LooseDecorated`
995
- * - Prepend `TAttrib` to the existing attribute tuple.
996
- * - else
997
- * - Wrap `TData` with `LooseDecorated` and a single attribute `[TAttrib]`
998
- * - else
999
- * - if `TData` is already `Decorated`
1000
- * - Prepend `TAttrib` to the existing attribute tuple.
1001
- * - else
1002
- * - Wrap `TData` with `Decorated` and a single attribute `[TAttrib]`
1003
- */
1004
- type Decorate<TData extends BaseData, TAttrib extends AnyAttribute> = TData['type'] extends WgslTypeLiteral ? Decorated<Undecorate<TData>, [TAttrib, ...ExtractAttributes<TData>]> : TData['type'] extends LooseTypeLiteral ? LooseDecorated<Undecorate<TData>, [TAttrib, ...ExtractAttributes<TData>]> : never;
1005
- type IsBuiltin<T> = ExtractAttributes<T>[number] extends [] ? false : ExtractAttributes<T>[number] extends Builtin<BuiltinName> ? true : false;
1006
- type HasCustomLocation<T> = ExtractAttributes<T>[number] extends [] ? false : ExtractAttributes<T>[number] extends Location ? true : false;
1007
- /**
1008
- * Gives the wrapped data-type a custom byte alignment. Useful in order to
1009
- * fulfill uniform alignment requirements.
1010
- *
1011
- * @example
1012
- * const Data = d.struct({
1013
- * a: u32, // takes up 4 bytes
1014
- * // 12 bytes of padding, because `b` is custom aligned to multiples of 16 bytes
1015
- * b: d.align(16, u32),
1016
- * });
1017
- *
1018
- * @param alignment The multiple of bytes this data should align itself to.
1019
- * @param data The data-type to align.
1020
- */
1021
- declare function align<TAlign extends number, TData extends AnyData>(alignment: TAlign, data: TData): Decorate<TData, Align<TAlign>>;
1022
- /**
1023
- * Adds padding bytes after the wrapped data-type, until the whole value takes up `size` bytes.
1024
- *
1025
- * @example
1026
- * const Data = d.struct({
1027
- * a: d.size(16, u32), // takes up 16 bytes, instead of 4
1028
- * b: u32, // starts at byte 16, because `a` has a custom size
1029
- * });
1030
- *
1031
- * @param size The amount of bytes that should be reserved for this data-type.
1032
- * @param data The data-type to wrap.
1033
- */
1034
- declare function size<TSize extends number, TData extends AnyData>(size: TSize, data: TData): Decorate<TData, Size<TSize>>;
1035
- /**
1036
- * Assigns an explicit numeric location to a struct member or a parameter that has this type.
1037
- *
1038
- * @example
1039
- * const VertexOutput = {
1040
- * a: d.u32, // has implicit location 0
1041
- * b: d.location(5, d.u32),
1042
- * c: d.u32, // has implicit location 6
1043
- * };
1044
- *
1045
- * @param location The explicit numeric location.
1046
- * @param data The data-type to wrap.
1047
- */
1048
- declare function location<TLocation extends number, TData extends AnyData>(location: TLocation, data: TData): Decorate<TData, Location<TLocation>>;
1049
- /**
1050
- * Specifies how user-defined vertex shader output (fragment shader input)
1051
- * must be interpolated.
1052
- *
1053
- * Tip: Integer outputs cannot be interpolated.
1054
- *
1055
- * @example
1056
- * const VertexOutput = {
1057
- * a: d.f32, // has implicit 'perspective, center' interpolation
1058
- * b: d.interpolate('linear, sample', d.f32),
1059
- * };
1060
- *
1061
- * @param interpolationType How data should be interpolated.
1062
- * @param data The data-type to wrap.
1063
- */
1064
- declare function interpolate<TInterpolation extends PerspectiveOrLinearInterpolationType, TData extends PerspectiveOrLinearInterpolatableData>(interpolationType: TInterpolation, data: TData): Decorate<TData, Interpolate<TInterpolation>>;
1065
- /**
1066
- * Specifies how user-defined vertex shader output (fragment shader input)
1067
- * must be interpolated.
1068
- *
1069
- * Tip: Default sampling method of `flat` is `first`. Unless you specifically
1070
- * need deterministic behavior provided by `'flat, first'`, prefer explicit
1071
- * `'flat, either'` as it could be slightly faster in hardware.
1072
- *
1073
- * @example
1074
- * const VertexOutput = {
1075
- * a: d.f32, // has implicit 'perspective, center' interpolation
1076
- * b: d.interpolate('flat, either', d.u32), // integer outputs cannot interpolate
1077
- * };
1078
- *
1079
- * @param interpolationType How data should be interpolated.
1080
- * @param data The data-type to wrap.
1081
- */
1082
- declare function interpolate<TInterpolation extends FlatInterpolationType, TData extends FlatInterpolatableData>(interpolationType: TInterpolation, data: TData): Decorate<TData, Interpolate<TInterpolation>>;
1083
- /**
1084
- * Marks a position built-in output value as invariant in vertex shaders.
1085
- * If the data and control flow match for two position outputs in different
1086
- * entry points, then the result values are guaranteed to be the same.
1087
- *
1088
- * Must only be applied to the position built-in value.
1089
- *
1090
- * @example
1091
- * const VertexOutput = {
1092
- * pos: d.invariant(d.builtin.position),
1093
- * };
1094
- *
1095
- * @param data The position built-in data-type to mark as invariant.
1096
- */
1097
- declare function invariant(data: Decorated<Vec4f, [Builtin<'position'>]>): Decorated<Vec4f, [Builtin<'position'>, Invariant]>;
1098
- declare function isBuiltin<T extends Decorated<AnyWgslData, AnyAttribute[]> | LooseDecorated<AnyLooseData, AnyAttribute[]>>(value: T | unknown): value is T;
1099
-
1100
- type AnyFn$1 = (...args: never[]) => unknown;
1101
- type InferArgs<T extends unknown[]> = {
1102
- [Idx in keyof T]: Infer<T[Idx]>;
1103
- };
1104
- type InheritTupleValues<T, From> = {
1105
- [K in keyof T]: K extends keyof From ? From[K] : never;
1106
- };
1107
- /**
1108
- * Returns a type that has arg and return types of `T`, but argument
1109
- * names of `From`
1110
- *
1111
- * Wrapped in an object type with `result` prop just so that it's easier
1112
- * to remove InheritArgNames<...> from Intellisense with Prettify<T>['result']
1113
- */
1114
- type InheritArgNames<T extends AnyFn$1, From extends AnyFn$1> = {
1115
- result: (...args: Parameters<((...args: InheritTupleValues<Parameters<From>, Parameters<T>>) => ReturnType<T>) & T>) => ReturnType<T>;
1116
- };
1117
- type InferImplSchema<ImplSchema extends AnyFn$1> = (...args: InferArgs<Parameters<ImplSchema>>) => Infer<ReturnType<ImplSchema>>;
1118
- type Implementation<ImplSchema extends AnyFn$1 = AnyFn$1> = string | InferImplSchema<ImplSchema>;
1119
- type BaseIOData = Bool | F32 | F16 | I32 | U32 | Vec2f | Vec3f | Vec4f | Vec2h | Vec3h | Vec4h | Vec2i | Vec3i | Vec4i | Vec2u | Vec3u | Vec4u;
1120
- type IOData = BaseIOData | Decorated<BaseIOData, AnyAttribute[]> | BuiltinClipDistances;
1121
- type IORecord<TElementType extends IOData = IOData> = Record<string, TElementType>;
1122
- /**
1123
- * Used for I/O definitions of entry functions.
1124
- */
1125
- type IOLayout<TElementType extends IOData = IOData> = TElementType | IORecord<TElementType> | Void;
1126
- type InferIO<T> = T extends {
1127
- type: string;
1128
- } ? Infer<T> : T extends Record<string, unknown> ? {
1129
- [K in keyof T]: Infer<T[K]>;
1130
- } : T;
1131
-
1132
- type WithLocations<T extends IORecord> = {
1133
- [Key in keyof T]: IsBuiltin<T[Key]> extends true ? T[Key] : HasCustomLocation<T[Key]> extends true ? T[Key] : Decorate<T[Key], Location>;
1134
- };
1135
- type IOLayoutToSchema<T extends IOLayout> = T extends BaseData ? Decorate<T, Location<0>> : T extends IORecord ? WgslStruct<WithLocations<T>> : T extends {
1136
- type: 'void';
1137
- } ? void : never;
1138
-
1139
- /**
1140
- * Describes a compute entry function signature (its arguments, return type and workgroup size)
1141
- */
1142
- type TgpuComputeFnShellHeader<ComputeIn extends IORecord<AnyComputeBuiltin>> = {
1143
- readonly argTypes: [IOLayoutToSchema<ComputeIn>] | [];
1144
- readonly returnType: Void;
1145
- readonly workgroupSize: [number, number, number];
1146
- readonly isEntry: true;
1147
- };
1148
- /**
1149
- * Describes a compute entry function signature (its arguments, return type and workgroup size).
1150
- * Allows creating tgpu compute functions by calling this shell
1151
- * and passing the implementation (as WGSL string or JS function) as the argument.
1152
- */
1153
- type TgpuComputeFnShell<ComputeIn extends IORecord<AnyComputeBuiltin>> = TgpuComputeFnShellHeader<ComputeIn>
1154
- /**
1155
- * Creates a type-safe implementation of this signature
1156
- */
1157
- & ((implementation: (input: InferIO<ComputeIn>) => undefined) => TgpuComputeFn<ComputeIn>) & /**
1158
- * @param implementation
1159
- * Raw WGSL function implementation with header and body
1160
- * without `fn` keyword and function name
1161
- * e.g. `"(x: f32) -> f32 { return x; }"`;
1162
- */ ((implementation: string) => TgpuComputeFn<ComputeIn>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuComputeFn<ComputeIn>);
1163
- interface TgpuComputeFn<ComputeIn extends IORecord<AnyComputeBuiltin> = any> extends TgpuNamable {
1164
- readonly [$internal]: true;
1165
- readonly shell: TgpuComputeFnShellHeader<ComputeIn>;
1166
- $uses(dependencyMap: Record<string, unknown>): this;
1167
- }
1168
- declare function computeFn(options: {
1169
- workgroupSize: number[];
1170
- }): TgpuComputeFnShell<{}>;
1171
- declare function computeFn<ComputeIn extends IORecord<AnyComputeBuiltin>>(options: {
1172
- in: ComputeIn;
1173
- workgroupSize: number[];
1174
- }): TgpuComputeFnShell<ComputeIn>;
1175
-
1176
- type DualFn<TImpl extends (...args: never[]) => unknown = (...args: never[]) => unknown> = TImpl & {
1177
- readonly [$internal]: {
1178
- jsImpl: TImpl;
1179
- gpuImpl: (...args: MapValueToSnippet<Parameters<TImpl>>) => Snippet;
1180
- argConversionHint: FnArgsConversionHint;
1181
- strictSignature?: {
1182
- argTypes: AnyData[];
1183
- returnType: AnyData;
1184
- } | undefined;
1185
- };
1186
- };
1187
-
1188
- interface TgpuSlot<T> extends TgpuNamable {
1189
- readonly [$internal]: true;
1190
- readonly resourceType: 'slot';
1191
- readonly defaultValue: T | undefined;
1192
- /**
1193
- * Used to determine if code generated using either value `a` or `b` in place
1194
- * of the slot will be equivalent. Defaults to `Object.is`.
1195
- */
1196
- areEqual(a: T, b: T): boolean;
1197
- readonly [$gpuValueOf]: GPUValueOf<T>;
1198
- readonly value: GPUValueOf<T>;
1199
- readonly $: GPUValueOf<T>;
1200
- }
1201
- interface TgpuDerived<T> {
1202
- readonly [$internal]: true;
1203
- readonly resourceType: 'derived';
1204
- readonly [$gpuValueOf]: GPUValueOf<T>;
1205
- readonly value: GPUValueOf<T>;
1206
- readonly $: GPUValueOf<T>;
1207
- readonly [$providing]?: Providing | undefined;
1208
- with<TValue>(slot: TgpuSlot<TValue>, value: Eventual<TValue>): TgpuDerived<T>;
1209
- /**
1210
- * @internal
1211
- */
1212
- '~compute'(): T;
1213
- }
1214
- interface TgpuAccessor<T extends AnyData = AnyData> extends TgpuNamable {
1215
- readonly [$internal]: true;
1216
- readonly resourceType: 'accessor';
1217
- readonly schema: T;
1218
- readonly defaultValue: TgpuFn<() => T> | TgpuBufferUsage<T> | TgpuBufferShorthand<T> | Infer<T> | undefined;
1219
- readonly slot: TgpuSlot<TgpuFn<() => T> | TgpuBufferUsage<T> | TgpuBufferShorthand<T> | Infer<T>>;
1220
- readonly [$gpuValueOf]: InferGPU<T>;
1221
- readonly value: InferGPU<T>;
1222
- readonly $: InferGPU<T>;
1223
- }
1224
- /**
1225
- * Represents a value that is available at resolution time.
1226
- */
1227
- type Eventual<T> = T | TgpuSlot<T> | TgpuDerived<T>;
1228
- type SlotValuePair<T = unknown> = [TgpuSlot<T>, T];
1229
- type Providing = {
1230
- inner: unknown;
1231
- pairs: SlotValuePair[];
1232
- };
1233
- declare function isSlot<T>(value: unknown | TgpuSlot<T>): value is TgpuSlot<T>;
1234
- declare function isDerived<T extends TgpuDerived<unknown>>(value: T | unknown): value is T;
1235
-
1236
- /**
1237
- * Describes a function signature (its arguments and return type)
1238
- */
1239
- type TgpuFnShellHeader<Args extends AnyData[], Return extends AnyData> = {
1240
- readonly [$internal]: true;
1241
- readonly argTypes: Args;
1242
- readonly returnType: Return;
1243
- readonly isEntry: false;
1244
- };
1245
- /**
1246
- * Describes a function signature (its arguments and return type).
1247
- * Allows creating tgpu functions by calling this shell
1248
- * and passing the implementation (as WGSL string or JS function) as the argument.
1249
- */
1250
- type TgpuFnShell<Args extends AnyData[], Return extends AnyData> = TgpuFnShellHeader<Args, Return> & (<T extends (...args: InferArgs<Args>) => Infer<Return>>(implementation: T) => TgpuFn<Prettify<InheritArgNames<(...args: Args) => Return, T>>['result']>) & ((implementation: string) => TgpuFn<(...args: Args) => Return>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuFn<(...args: Args) => Return>);
1251
- interface TgpuFnBase<ImplSchema extends AnyFn$1> extends TgpuNamable {
1252
- readonly resourceType: 'function';
1253
- readonly shell: TgpuFnShellHeader<Parameters<ImplSchema>, Extract<ReturnType<ImplSchema>, AnyData>>;
1254
- readonly [$providing]?: Providing | undefined;
1255
- $uses(dependencyMap: Record<string, unknown>): this;
1256
- with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TgpuFn<ImplSchema>;
1257
- with<T extends AnyData>(accessor: TgpuAccessor<T>, value: TgpuFn<() => T> | TgpuBufferUsage<T> | Infer<T>): TgpuFn<ImplSchema>;
1258
- }
1259
- type TgpuFn<ImplSchema extends AnyFn$1 = (...args: any[]) => any> = TgpuFnBase<ImplSchema> & InferImplSchema<ImplSchema> & {
1260
- readonly [$internal]: DualFn<InferImplSchema<ImplSchema>>[typeof $internal] & {
1261
- implementation: Implementation<ImplSchema>;
1262
- };
1263
- };
1264
- declare function fn<Args extends AnyData[] | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, Void>;
1265
- declare function fn<Args extends AnyData[] | [], Return extends AnyData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
1266
- declare function isTgpuFn<Args extends AnyData[] | [], Return extends AnyData>(value: unknown | TgpuFn<(...args: Args) => Return>): value is TgpuFn<(...args: Args) => Return>;
1267
-
1268
- type FragmentInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, (Location | Interpolate)[]> | AnyFragmentInputBuiltin>;
1269
- type FragmentColorValue = Vec4f | Vec4i | Vec4u;
1270
- type FragmentOutConstrained = IOLayout<FragmentColorValue | Decorated<FragmentColorValue, (Location | Interpolate)[]> | AnyFragmentOutputBuiltin>;
1271
- /**
1272
- * Describes a fragment entry function signature (its arguments, return type and targets)
1273
- */
1274
- type TgpuFragmentFnShellHeader<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = {
1275
- readonly in: FragmentIn | undefined;
1276
- readonly out: FragmentOut;
1277
- readonly returnType: IOLayoutToSchema<FragmentOut>;
1278
- readonly isEntry: true;
1279
- };
1280
- /**
1281
- * Describes a fragment entry function signature (its arguments, return type and targets).
1282
- * Allows creating tgpu fragment functions by calling this shell
1283
- * and passing the implementation (as WGSL string or JS function) as the argument.
1284
- */
1285
- type TgpuFragmentFnShell<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = TgpuFragmentFnShellHeader<FragmentIn, FragmentOut> /**
1286
- * Creates a type-safe implementation of this signature
1287
- */ & ((implementation: (input: InferIO<FragmentIn>, out: FragmentOut extends IORecord ? WgslStruct<FragmentOut> : FragmentOut) => InferIO<FragmentOut>) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, FragmentOut>) & /**
1288
- * @param implementation
1289
- * Raw WGSL function implementation with header and body
1290
- * without `fn` keyword and function name
1291
- * e.g. `"(x: f32) -> f32 { return x; }"`;
1292
- */ ((implementation: string) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, FragmentOut>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, FragmentOut>);
1293
- interface TgpuFragmentFn<Varying extends FragmentInConstrained = FragmentInConstrained, Output extends FragmentOutConstrained = FragmentOutConstrained> extends TgpuNamable {
1294
- readonly [$internal]: true;
1295
- readonly shell: TgpuFragmentFnShellHeader<Varying, Output>;
1296
- readonly outputType: IOLayoutToSchema<Output>;
1297
- $uses(dependencyMap: Record<string, unknown>): this;
1298
- }
1299
- declare function fragmentFn<FragmentOut extends FragmentOutConstrained>(options: {
1300
- out: FragmentOut;
1301
- }): TgpuFragmentFnShell<{}, FragmentOut>;
1302
- declare function fragmentFn<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained>(options: {
1303
- in: FragmentIn;
1304
- out: FragmentOut;
1305
- }): TgpuFragmentFnShell<FragmentIn, FragmentOut>;
1306
-
1307
- type VertexInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, Location[]> | AnyVertexInputBuiltin>;
1308
- type VertexOutConstrained = IORecord<BaseIOData | Decorated<BaseIOData, (Location | Interpolate)[]> | AnyVertexOutputBuiltin>;
1309
- /**
1310
- * Describes a vertex entry function signature (its arguments, return type and attributes)
1311
- */
1312
- type TgpuVertexFnShellHeader<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained> = {
1313
- readonly in: VertexIn | undefined;
1314
- readonly out: VertexOut;
1315
- readonly argTypes: [IOLayoutToSchema<VertexIn>] | [];
1316
- readonly isEntry: true;
1317
- };
1318
- /**
1319
- * Describes a vertex entry function signature (its arguments, return type and attributes).
1320
- * Allows creating tgpu vertex functions by calling this shell
1321
- * and passing the implementation (as WGSL string or JS function) as the argument.
1322
- */
1323
- type TgpuVertexFnShell<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained> = TgpuVertexFnShellHeader<VertexIn, VertexOut> & ((implementation: (input: InferIO<VertexIn>, out: WgslStruct<VertexOut>) => InferIO<VertexOut>) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((implementation: string) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>);
1324
- interface TgpuVertexFn<VertexIn extends VertexInConstrained = VertexInConstrained, VertexOut extends VertexOutConstrained = VertexOutConstrained> extends TgpuNamable {
1325
- readonly [$internal]: true;
1326
- readonly shell: TgpuVertexFnShellHeader<VertexIn, VertexOut>;
1327
- $uses(dependencyMap: Record<string, unknown>): this;
1328
- }
1329
- declare function vertexFn<VertexOut extends VertexOutConstrained>(options: {
1330
- out: VertexOut;
1331
- }): TgpuVertexFnShell<{}, VertexOut>;
1332
- declare function vertexFn<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(options: {
1333
- in: VertexIn;
1334
- out: VertexOut;
1335
- }): TgpuVertexFnShell<VertexIn, VertexOut>;
1336
-
1337
- interface Timeable {
1338
- withPerformanceCallback(callback: (start: bigint, end: bigint) => void | Promise<void>): this;
1339
- withTimestampWrites(options: {
1340
- querySet: TgpuQuerySet<'timestamp'> | GPUQuerySet;
1341
- beginningOfPassWriteIndex?: number;
1342
- endOfPassWriteIndex?: number;
1343
- }): this;
1344
- }
1345
- type TimestampWritesPriors = {
1346
- readonly timestampWrites?: {
1347
- querySet: TgpuQuerySet<'timestamp'> | GPUQuerySet;
1348
- beginningOfPassWriteIndex?: number;
1349
- endOfPassWriteIndex?: number;
1350
- };
1351
- readonly performanceCallback?: (start: bigint, end: bigint) => void | Promise<void>;
1352
- readonly hasAutoQuerySet?: boolean;
1353
- };
1354
-
1355
- interface ComputePipelineInternals {
1356
- readonly rawPipeline: GPUComputePipeline;
1357
- readonly priors: TgpuComputePipelinePriors & TimestampWritesPriors;
1358
- readonly branch: ExperimentalTgpuRoot;
1359
- }
1360
- interface TgpuComputePipeline extends TgpuNamable, SelfResolvable, Timeable {
1361
- readonly [$internal]: ComputePipelineInternals;
1362
- readonly resourceType: 'compute-pipeline';
1363
- /**
1364
- * @deprecated This overload is outdated.
1365
- * Call `pipeline.with(bindGroup)` instead.
1366
- */
1367
- with<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries>): this;
1368
- with(bindGroup: TgpuBindGroup): this;
1369
- dispatchWorkgroups(x: number, y?: number | undefined, z?: number | undefined): void;
1370
- }
1371
- type TgpuComputePipelinePriors = {
1372
- readonly bindGroupLayoutMap?: Map<TgpuBindGroupLayout, TgpuBindGroup>;
1373
- } & TimestampWritesPriors;
1374
-
1375
- type TextureProps = {
1376
- size: readonly number[];
1377
- format: GPUTextureFormat;
1378
- viewFormats?: GPUTextureFormat[] | undefined;
1379
- dimension?: GPUTextureDimension | undefined;
1380
- mipLevelCount?: number | undefined;
1381
- sampleCount?: number | undefined;
1382
- };
1383
-
1384
- interface SampledFlag {
1385
- usableAsSampled: true;
1386
- }
1387
- interface RenderFlag {
1388
- usableAsRender: true;
1389
- }
1390
- type LiteralToExtensionMap = {
1391
- storage: StorageFlag;
1392
- sampled: SampledFlag;
1393
- render: RenderFlag;
1394
- };
1395
- type AllowedUsages<TProps extends TextureProps> = 'sampled' | 'render' | (TProps['format'] extends StorageTextureFormats ? 'storage' : never);
1396
- declare function isUsableAsSampled<T>(value: T): value is T & SampledFlag;
1397
- declare function isUsableAsRender<T>(value: T): value is T & RenderFlag;
1398
-
1399
- /**
1400
- * The array can hold T, where T is a single/multi-component numeric, or a struct with members of type T.
1401
- * Examples of valid array members:
1402
- * - Vec3f,
1403
- * - unorm8x2
1404
- * - WgslStruct<{ a: Vec3f, b: unorm8x2 }>
1405
- * - WgslStruct<{ nested: WgslStruct<{ a: Vec3f }> }>
1406
- */
1407
- type DataToContainedAttribs<T> = T extends WgslStruct | Unstruct ? {
1408
- [Key in keyof T['propTypes']]: DataToContainedAttribs<T['propTypes'][Key]>;
1409
- } : T extends {
1410
- type: VertexFormat;
1411
- } ? TgpuVertexAttrib<T['type']> : T extends {
1412
- type: keyof KindToDefaultFormatMap;
1413
- } ? TgpuVertexAttrib<KindToDefaultFormatMap[T['type']]> : T extends Decorated<infer TInner> ? DataToContainedAttribs<TInner> : T extends LooseDecorated<infer TInner> ? DataToContainedAttribs<TInner> : never;
1414
- /**
1415
- * Interprets an array as a set of vertex attributes.
1416
- */
1417
- type ArrayToContainedAttribs<T extends WgslArray | Disarray> = DataToContainedAttribs<T['elementType']>;
1418
- type LayoutToAllowedAttribs<T> = T extends {
1419
- type: keyof KindToAcceptedAttribMap;
1420
- } ? KindToAcceptedAttribMap[T['type']] : T extends Record<string, unknown> ? {
1421
- [Key in keyof T]: LayoutToAllowedAttribs<T[Key]>;
1422
- } : never;
1423
-
1424
- interface TgpuVertexLayout<TData extends WgslArray | Disarray = WgslArray | Disarray> extends TgpuNamable {
1425
- readonly [$internal]: true;
1426
- readonly resourceType: 'vertex-layout';
1427
- readonly stride: number;
1428
- readonly stepMode: 'vertex' | 'instance';
1429
- readonly attrib: ArrayToContainedAttribs<TData>;
1430
- readonly vertexLayout: GPUVertexBufferLayout;
1431
- schemaForCount(n: number): TData;
1432
- }
1433
- declare function vertexLayout<TData extends WgslArray | Disarray>(schemaForCount: (count: number) => TData, stepMode?: 'vertex' | 'instance'): TgpuVertexLayout<TData>;
1434
-
1435
- interface RenderPipelineInternals {
1436
- readonly core: RenderPipelineCore;
1437
- readonly priors: TgpuRenderPipelinePriors & TimestampWritesPriors;
1438
- readonly branch: ExperimentalTgpuRoot;
1439
- }
1440
- interface HasIndexBuffer {
1441
- readonly hasIndexBuffer: true;
1442
- drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void;
1443
- }
1444
- interface TgpuRenderPipeline<Output extends IOLayout = IOLayout> extends TgpuNamable, SelfResolvable, Timeable {
1445
- readonly [$internal]: RenderPipelineInternals;
1446
- readonly resourceType: 'render-pipeline';
1447
- readonly hasIndexBuffer: boolean;
1448
- with<TData extends WgslArray | Disarray>(vertexLayout: TgpuVertexLayout<TData>, buffer: TgpuBuffer<TData> & VertexFlag): this;
1449
- /**
1450
- * @deprecated This overload is outdated.
1451
- * Call `pipeline.with(bindGroup)` instead.
1452
- */
1453
- with<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries>): this;
1454
- with(bindGroup: TgpuBindGroup): this;
1455
- withColorAttachment(attachment: FragmentOutToColorAttachment<Output>): this;
1456
- withDepthStencilAttachment(attachment: DepthStencilAttachment): this;
1457
- withStencilReference(reference: GPUStencilValue): this;
1458
- withIndexBuffer(buffer: TgpuBuffer<AnyWgslData> & IndexFlag, offsetElements?: number, sizeElements?: number): this & HasIndexBuffer;
1459
- withIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offsetBytes?: number, sizeBytes?: number): this & HasIndexBuffer;
1460
- draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
1461
- }
1462
- type FragmentOutToTargets<T extends IOLayout> = T extends IOData ? T extends Decorated ? Record<string, never> : GPUColorTargetState : T extends Record<string, unknown> ? {
1463
- [Key in keyof T as T[Key] extends Decorated ? never : Key]: GPUColorTargetState;
1464
- } : T extends {
1465
- type: 'void';
1466
- } ? Record<string, never> : never;
1467
- type FragmentOutToColorAttachment<T extends IOLayout> = T extends IOData ? T extends Decorated ? Record<string, never> : ColorAttachment : T extends Record<string, unknown> ? {
1468
- [Key in keyof T as T[Key] extends Decorated ? never : Key]: ColorAttachment;
1469
- } : T extends {
1470
- type: 'void';
1471
- } ? Record<string, never> : never;
1472
- type AnyFragmentTargets = GPUColorTargetState | Record<string, GPUColorTargetState>;
1473
- interface ColorTextureConstraint {
1474
- readonly [$internal]: TextureInternals;
1475
- readonly resourceType: 'texture';
1476
- readonly props: {
1477
- format: GPUTextureFormat;
1478
- };
1479
- }
1480
- interface ColorAttachment {
1481
- /**
1482
- * A {@link GPUTextureView} describing the texture subresource that will be output to for this
1483
- * color attachment.
1484
- */
1485
- view: (ColorTextureConstraint & RenderFlag) | GPUTextureView | TgpuTextureView<WgslTexture> | TgpuTextureRenderView;
1486
- /**
1487
- * Indicates the depth slice index of {@link GPUTextureViewDimension#"3d"} {@link GPURenderPassColorAttachment#view}
1488
- * that will be output to for this color attachment.
1489
- */
1490
- depthSlice?: GPUIntegerCoordinate;
1491
- /**
1492
- * A {@link GPUTextureView} describing the texture subresource that will receive the resolved
1493
- * output for this color attachment if {@link GPURenderPassColorAttachment#view} is
1494
- * multisampled.
1495
- */
1496
- resolveTarget?: GPUTextureView;
1497
- /**
1498
- * Indicates the value to clear {@link GPURenderPassColorAttachment#view} to prior to executing the
1499
- * render pass. If not map/exist|provided, defaults to `{r: 0, g: 0, b: 0, a: 0}`. Ignored
1500
- * if {@link GPURenderPassColorAttachment#loadOp} is not {@link GPULoadOp#"clear"}.
1501
- * The components of {@link GPURenderPassColorAttachment#clearValue} are all double values.
1502
- * They are converted to a texel value of texture format matching the render attachment.
1503
- * If conversion fails, a validation error is generated.
1504
- */
1505
- clearValue?: GPUColor;
1506
- /**
1507
- * Indicates the load operation to perform on {@link GPURenderPassColorAttachment#view} prior to
1508
- * executing the render pass.
1509
- * Note: It is recommended to prefer clearing; see {@link GPULoadOp#"clear"} for details.
1510
- */
1511
- loadOp: GPULoadOp;
1512
- /**
1513
- * The store operation to perform on {@link GPURenderPassColorAttachment#view}
1514
- * after executing the render pass.
1515
- */
1516
- storeOp: GPUStoreOp;
1517
- }
1518
- type DepthStencilFormat = 'stencil8' | 'depth16unorm' | 'depth24plus' | 'depth24plus-stencil8' | 'depth32float' | 'depth32float-stencil8';
1519
- interface DepthStencilTextureConstraint {
1520
- readonly [$internal]: TextureInternals;
1521
- readonly resourceType: 'texture';
1522
- readonly props: {
1523
- format: DepthStencilFormat;
1524
- };
1525
- }
1526
- interface DepthStencilAttachment {
1527
- /**
1528
- * A {@link GPUTextureView} | ({@link TgpuTexture} & {@link RenderFlag}) describing the texture subresource that will be output to
1529
- * and read from for this depth/stencil attachment.
1530
- */
1531
- view: (DepthStencilTextureConstraint & RenderFlag) | TgpuTextureView<WgslTextureDepth2d | WgslTextureDepthMultisampled2d> | TgpuTextureRenderView | GPUTextureView;
1532
- /**
1533
- * Indicates the value to clear {@link GPURenderPassDepthStencilAttachment#view}'s depth component
1534
- * to prior to executing the render pass. Ignored if {@link GPURenderPassDepthStencilAttachment#depthLoadOp}
1535
- * is not {@link GPULoadOp#"clear"}. Must be between 0.0 and 1.0, inclusive (unless unrestricted depth is enabled).
1536
- */
1537
- depthClearValue?: number;
1538
- /**
1539
- * Indicates the load operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s
1540
- * depth component prior to executing the render pass.
1541
- * Note: It is recommended to prefer clearing; see {@link GPULoadOp#"clear"} for details.
1542
- */
1543
- depthLoadOp?: GPULoadOp;
1544
- /**
1545
- * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s
1546
- * depth component after executing the render pass.
1547
- */
1548
- depthStoreOp?: GPUStoreOp;
1549
- /**
1550
- * Indicates that the depth component of {@link GPURenderPassDepthStencilAttachment#view}
1551
- * is read only.
1552
- */
1553
- depthReadOnly?: boolean;
1554
- /**
1555
- * Indicates the value to clear {@link GPURenderPassDepthStencilAttachment#view}'s stencil component
1556
- * to prior to executing the render pass. Ignored if {@link GPURenderPassDepthStencilAttachment#stencilLoadOp}
1557
- * is not {@link GPULoadOp#"clear"}.
1558
- * The value will be converted to the type of the stencil aspect of `view` by taking the same
1559
- * number of LSBs as the number of bits in the stencil aspect of one texel block|texel of `view`.
1560
- */
1561
- stencilClearValue?: GPUStencilValue;
1562
- /**
1563
- * Indicates the load operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s
1564
- * stencil component prior to executing the render pass.
1565
- * Note: It is recommended to prefer clearing; see {@link GPULoadOp#"clear"} for details.
1566
- */
1567
- stencilLoadOp?: GPULoadOp;
1568
- /**
1569
- * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s
1570
- * stencil component after executing the render pass.
1571
- */
1572
- stencilStoreOp?: GPUStoreOp;
1573
- /**
1574
- * Indicates that the stencil component of {@link GPURenderPassDepthStencilAttachment#view}
1575
- * is read only.
1576
- */
1577
- stencilReadOnly?: boolean;
1578
- }
1579
- type AnyFragmentColorAttachment = ColorAttachment | Record<string, ColorAttachment>;
1580
- type RenderPipelineCoreOptions = {
1581
- branch: ExperimentalTgpuRoot;
1582
- slotBindings: [TgpuSlot<unknown>, unknown][];
1583
- vertexAttribs: AnyVertexAttribs;
1584
- vertexFn: TgpuVertexFn;
1585
- fragmentFn: TgpuFragmentFn | null;
1586
- primitiveState: GPUPrimitiveState | Omit<GPUPrimitiveState, 'stripIndexFormat'> & {
1587
- stripIndexFormat?: U32 | U16;
1588
- } | undefined;
1589
- depthStencilState: GPUDepthStencilState | undefined;
1590
- targets: AnyFragmentTargets | null;
1591
- multisampleState: GPUMultisampleState | undefined;
1592
- };
1593
- type TgpuRenderPipelinePriors = {
1594
- readonly vertexLayoutMap?: Map<TgpuVertexLayout, TgpuBuffer<AnyWgslData> & VertexFlag> | undefined;
1595
- readonly bindGroupLayoutMap?: Map<TgpuBindGroupLayout, TgpuBindGroup> | undefined;
1596
- readonly colorAttachment?: AnyFragmentColorAttachment | undefined;
1597
- readonly depthStencilAttachment?: DepthStencilAttachment | undefined;
1598
- readonly stencilReference?: GPUStencilValue | undefined;
1599
- readonly indexBuffer?: {
1600
- buffer: TgpuBuffer<AnyWgslData> & IndexFlag | GPUBuffer;
1601
- indexFormat: GPUIndexFormat;
1602
- offsetBytes?: number | undefined;
1603
- sizeBytes?: number | undefined;
1604
- } | undefined;
1605
- } & TimestampWritesPriors;
1606
- type Memo = {
1607
- pipeline: GPURenderPipeline;
1608
- usedBindGroupLayouts: TgpuBindGroupLayout[];
1609
- catchall: [number, TgpuBindGroup] | undefined;
1610
- logResources: LogResources | undefined;
1611
- };
1612
- declare class RenderPipelineCore implements SelfResolvable {
1613
- readonly options: RenderPipelineCoreOptions;
1614
- readonly [$internal] = true;
1615
- readonly usedVertexLayouts: TgpuVertexLayout[];
1616
- private _memo;
1617
- private readonly _vertexBufferLayouts;
1618
- private readonly _targets;
1619
- constructor(options: RenderPipelineCoreOptions);
1620
- [$resolve](ctx: ResolutionCtx): ResolvedSnippet;
1621
- toString(): string;
1622
- unwrap(): Memo;
1623
- }
1624
-
1625
- interface Unwrapper {
1626
- readonly device: GPUDevice;
1627
- unwrap(resource: TgpuComputePipeline): GPUComputePipeline;
1628
- unwrap(resource: TgpuRenderPipeline): GPURenderPipeline;
1629
- unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
1630
- unwrap(resource: TgpuBindGroup): GPUBindGroup;
1631
- unwrap(resource: TgpuBuffer<AnyData>): GPUBuffer;
1632
- unwrap(resource: TgpuTextureView): GPUTextureView;
1633
- unwrap(resource: TgpuVertexLayout): GPUVertexBufferLayout;
1634
- unwrap(resource: TgpuSampler): GPUSampler;
1635
- unwrap(resource: TgpuComparisonSampler): GPUSampler;
1636
- unwrap(resource: TgpuQuerySet<GPUQueryType>): GPUQuerySet;
1637
- unwrap(resource: TgpuTexture<any>): GPUTexture;
1638
- }
1639
-
1640
- interface SamplerInternals {
1641
- readonly unwrap?: (() => GPUSampler) | undefined;
1642
- }
1643
- interface TgpuSampler {
1644
- readonly [$internal]: SamplerInternals;
1645
- readonly resourceType: 'sampler';
1646
- readonly schema: WgslSampler;
1647
- readonly [$gpuValueOf]: Infer<WgslSampler>;
1648
- value: Infer<WgslSampler>;
1649
- $: Infer<WgslSampler>;
1650
- }
1651
- interface TgpuComparisonSampler {
1652
- readonly [$internal]: SamplerInternals;
1653
- readonly resourceType: 'sampler-comparison';
1654
- readonly schema: WgslComparisonSampler;
1655
- readonly [$gpuValueOf]: Infer<WgslComparisonSampler>;
1656
- value: Infer<WgslComparisonSampler>;
1657
- $: Infer<WgslComparisonSampler>;
1658
- }
1659
- interface TgpuFixedSampler extends TgpuSampler, TgpuNamable {
1660
- }
1661
- interface TgpuFixedComparisonSampler extends TgpuComparisonSampler, TgpuNamable {
1662
- }
1663
- declare function isSampler(resource: unknown): resource is TgpuSampler;
1664
- declare function isComparisonSampler(resource: unknown): resource is TgpuComparisonSampler;
1665
-
1666
- interface TgpuExternalTexture {
1667
- readonly resourceType: 'external-texture';
1668
- }
1669
-
1670
- type VariableScope = 'private' | 'workgroup';
1671
- interface TgpuVar<TScope extends VariableScope = VariableScope, TDataType extends AnyData = AnyData> extends TgpuNamable {
1672
- readonly [$gpuValueOf]: InferGPU<TDataType>;
1673
- value: InferGPU<TDataType>;
1674
- $: InferGPU<TDataType>;
1675
- readonly [$internal]: {
1676
- /** Makes it differentiable on the type level. Does not exist at runtime. */
1677
- dataType?: TDataType;
1678
- /** Makes it differentiable on the type level. Does not exist at runtime. */
1679
- scope?: TScope;
1680
- };
1681
- }
1682
- /**
1683
- * Defines a variable scoped to each entry function (private).
1684
- *
1685
- * @param dataType The schema of the held data's type
1686
- * @param initialValue If not provided, the variable will be initialized to the dataType's "zero-value".
1687
- */
1688
- declare function privateVar<TDataType extends AnyData>(dataType: TDataType, initialValue?: InferGPU<TDataType>): TgpuVar<'private', TDataType>;
1689
- /**
1690
- * Defines a variable scoped to the whole workgroup, shared between entry functions
1691
- * of the same invocation.
1692
- *
1693
- * @param dataType The schema of the held data's type
1694
- */
1695
- declare function workgroupVar<TDataType extends AnyData>(dataType: TDataType): TgpuVar<'workgroup', TDataType>;
1696
- declare function isVariable<T extends TgpuVar>(value: T | unknown): value is T;
1697
-
1698
- declare const wgslExtensions: readonly ["f16", "clip_distances", "dual_source_blending", "subgroups", "primitive_index"];
1699
- type WgslExtension = (typeof wgslExtensions)[number];
1700
-
1701
- type ResolvableObject = SelfResolvable | TgpuBufferUsage | TgpuConst | TgpuDeclare | TgpuFn | TgpuComputeFn | TgpuFragmentFn | TgpuComputePipeline | TgpuRenderPipeline | TgpuVertexFn | TgpuSampler | TgpuAccessor | TgpuExternalTexture | TgpuTexture | TgpuTextureView | TgpuVar | AnyVecInstance | AnyMatInstance | AnyData | ((...args: never[]) => unknown);
1702
- type Wgsl = Eventual<string | number | boolean | ResolvableObject>;
1703
- type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
1704
- interface FnToWgslOptions {
1705
- functionType: 'normal' | TgpuShaderStage;
1706
- argTypes: AnyData[];
1707
- /**
1708
- * The return type of the function. If undefined, the type should be inferred
1709
- * from the implementation (relevant for shellless functions).
1710
- */
1711
- returnType: AnyData | undefined;
1712
- body: Block;
1713
- params: FuncParameter[];
1714
- externalMap: Record<string, unknown>;
1715
- }
1716
- type ItemLayer = {
1717
- type: 'item';
1718
- usedSlots: Set<TgpuSlot<unknown>>;
1719
- };
1720
- type FunctionScopeLayer = {
1721
- type: 'functionScope';
1722
- functionType: 'normal' | 'compute' | 'vertex' | 'fragment';
1723
- args: Snippet[];
1724
- argAliases: Record<string, Snippet>;
1725
- externalMap: Record<string, unknown>;
1726
- /**
1727
- * The return type of the function. If undefined, the type should be inferred
1728
- * from the implementation (relevant for shellless functions).
1729
- */
1730
- returnType: AnyData | undefined;
1731
- /**
1732
- * All types used in `return` statements.
1733
- */
1734
- reportedReturnTypes: Set<AnyData>;
1735
- };
1736
- interface ItemStateStack {
1737
- readonly itemDepth: number;
1738
- readonly topItem: ItemLayer;
1739
- readonly topFunctionScope: FunctionScopeLayer | undefined;
1740
- pushItem(): void;
1741
- popItem(): void;
1742
- pushSlotBindings(pairs: SlotValuePair<unknown>[]): void;
1743
- popSlotBindings(): void;
1744
- pushFunctionScope(functionType: 'normal' | TgpuShaderStage, args: Snippet[], argAliases: Record<string, Snippet>,
1745
- /**
1746
- * The return type of the function. If undefined, the type should be inferred
1747
- * from the implementation (relevant for shellless functions).
1748
- */
1749
- returnType: AnyData | undefined, externalMap: Record<string, unknown>): FunctionScopeLayer;
1750
- popFunctionScope(): void;
1751
- pushBlockScope(): void;
1752
- popBlockScope(): void;
1753
- pop(type?: 'functionScope' | 'blockScope' | 'slotBinding' | 'item'): void;
1754
- readSlot<T>(slot: TgpuSlot<T>): T | undefined;
1755
- getSnippetById(id: string): Snippet | undefined;
1756
- defineBlockVariable(id: string, snippet: Snippet): void;
1757
- }
1758
- /**
1759
- * # What are execution modes/states? 🤷‍♂️
1760
- * They're used to control how each TypeGPU resource reacts
1761
- * to actions upon them.
1762
- *
1763
- * ## Normal mode
1764
- * This is the default mode, where resources are acted upon
1765
- * by code either:
1766
- * - Not wrapped inside any of our execution-altering APIs
1767
- * like tgpu.resolve or tgpu.simulate.
1768
- * - Inside tgpu.derived definitions, where we're taking a break
1769
- * from codegen/simulation to create resources on-demand.
1770
- *
1771
- * ```ts
1772
- * const count = tgpu.privateVar(d.f32);
1773
- * count.$ += 1; // Illegal in top-level
1774
- *
1775
- * const root = await tgpu.init();
1776
- * const countMutable = root.createMutable(d.f32);
1777
- * countMutable.$ = [1, 2, 3]; // Illegal in top-level
1778
- * countMutable.write([1, 2, 3]); // OK!
1779
- * ```
1780
- *
1781
- * ## Codegen mode
1782
- * Brought upon by `tgpu.resolve()` (or higher-level APIs using it like our pipelines).
1783
- * Resources are expected to generate WGSL code that represents them, instead of
1784
- * fulfilling their task in JS.
1785
- *
1786
- * ```ts
1787
- * const foo = tgpu.fn([], d.f32)(() => 123);
1788
- * // The following is running in `codegen` mode
1789
- * console.log(foo()); // Prints `foo_0()`
1790
- * ```
1791
- *
1792
- * ## Simulate mode
1793
- * Callbacks passed to `tgpu.simulate()` are executed in this mode. Each 'simulation'
1794
- * is isolated, and does not share state with other simulations (even nested ones).
1795
- * Variables and buffers can be accessed and mutated directly, and their state
1796
- * is returned at the end of the simulation.
1797
- *
1798
- * ```ts
1799
- * const var = tgpu.privateVar(d.f32, 0);
1800
- *
1801
- * const result = tgpu.simulate(() => {
1802
- * // This is running in `simulate` mode
1803
- * var.$ += 1; // Direct access is legal
1804
- * return var.$; // Returns 1
1805
- * });
1806
- *
1807
- * console.log(result.value); // Prints 1
1808
- * ```
1809
- */
1810
- type ExecMode = 'normal' | 'codegen' | 'simulate';
1811
- declare class NormalState {
1812
- readonly type: "normal";
1813
- }
1814
- declare class CodegenState {
1815
- readonly type: "codegen";
1816
- }
1817
- declare class SimulationState {
1818
- readonly buffers: Map<TgpuBuffer<AnyData>, unknown>;
1819
- readonly vars: {
1820
- private: Map<TgpuVar, unknown>;
1821
- workgroup: Map<TgpuVar, unknown>;
1822
- };
1823
- readonly type: "simulate";
1824
- constructor(buffers: Map<TgpuBuffer<AnyData>, unknown>, vars: {
1825
- private: Map<TgpuVar, unknown>;
1826
- workgroup: Map<TgpuVar, unknown>;
1827
- });
1828
- }
1829
- type ExecState = NormalState | CodegenState | SimulationState;
1830
- /**
1831
- * Passed into each resolvable item. All items in a tree share a resolution ctx,
1832
- * but there can be layers added and removed from the item stack when going down
1833
- * and up the tree.
1834
- */
1835
- interface ResolutionCtx {
1836
- [$internal]: {
1837
- itemStateStack: ItemStateStack;
1838
- };
1839
- readonly mode: ExecState;
1840
- readonly enableExtensions: WgslExtension[] | undefined;
1841
- addDeclaration(declaration: string): void;
1842
- withResetIndentLevel<T>(callback: () => T): T;
1843
- /**
1844
- * Reserves a bind group number, and returns a placeholder that will be replaced
1845
- * with a concrete number at the end of the resolution process.
1846
- */
1847
- allocateLayoutEntry(layout: TgpuBindGroupLayout): string;
1848
- /**
1849
- * Reserves a spot in the catch-all bind group, without the indirection of a bind-group.
1850
- * This means the resource is 'fixed', and cannot be swapped between code execution.
1851
- */
1852
- allocateFixedEntry(layoutEntry: TgpuLayoutEntry, resource: object): {
1853
- group: string;
1854
- binding: number;
1855
- };
1856
- withSlots<T>(pairs: SlotValuePair<unknown>[], callback: () => T): T;
1857
- pushMode(state: ExecState): void;
1858
- popMode(expected?: ExecMode | undefined): void;
1859
- /**
1860
- * Unwraps all layers of slot/derived indirection and returns the concrete value if available.
1861
- * @throws {MissingSlotValueError}
1862
- */
1863
- unwrap<T>(eventual: Eventual<T>): T;
1864
- /**
1865
- * Returns the snippet representing `item`.
1866
- *
1867
- * @param item The value to resolve
1868
- * @param schema Additional information about the item's data type
1869
- * @param exact Should the inferred value of the resulting code be typed exactly as `schema` (true),
1870
- * or is being assignable to `schema` enough (false). Default is false.
1871
- */
1872
- resolve(item: unknown, schema?: AnyData | UnknownData | undefined, exact?: boolean | undefined): ResolvedSnippet;
1873
- fnToWgsl(options: FnToWgslOptions): {
1874
- head: Wgsl;
1875
- body: Wgsl;
1876
- returnType: AnyData;
1877
- };
1878
- withVaryingLocations<T>(locations: Record<string, number>, callback: () => T): T;
1879
- get varyingLocations(): Record<string, number> | undefined;
1880
- getUniqueName(resource: object): string;
1881
- makeNameValid(name: string): string;
1882
- }
1883
- /**
1884
- * Houses a method on the symbol '$resolve` that returns a
1885
- * code string representing it, as opposed to offloading the
1886
- * resolution to another mechanism.
1887
- */
1888
- interface SelfResolvable {
1889
- [$internal]: unknown;
1890
- [$resolve](ctx: ResolutionCtx): ResolvedSnippet;
1891
- toString(): string;
1892
- }
1893
- type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
1894
- type ConversionStrategy = 'keep' | 'unify';
1895
- /**
1896
- * Optional hints for converting function argument types during resolution.
1897
- * In case of tgpu functions, this is just the array of argument schemas.
1898
- * In case of raw dualImpls (e.g. in std), this is either a function that converts the snippets appropriately,
1899
- * or a string defining a conversion strategy.
1900
- * The strategy 'keep' is the default.
1901
- */
1902
- type FnArgsConversionHint = AnyData[] | ((...args: Snippet[]) => AnyWgslData[]) | ConversionStrategy;
1903
-
1904
- interface TgpuBufferShorthandBase<TData extends BaseData> extends TgpuNamable {
1905
- readonly [$internal]: true;
1906
- write(data: Infer<TData>): void;
1907
- writePartial(data: InferPartial<TData>): void;
1908
- read(): Promise<Infer<TData>>;
1909
- readonly [$gpuValueOf]: InferGPU<TData>;
1910
- }
1911
- interface TgpuMutable<TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
1912
- readonly resourceType: 'mutable';
1913
- readonly buffer: TgpuBuffer<TData> & StorageFlag;
1914
- value: InferGPU<TData>;
1915
- $: InferGPU<TData>;
1916
- }
1917
- interface TgpuReadonly<TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
1918
- readonly resourceType: 'readonly';
1919
- readonly buffer: TgpuBuffer<TData> & StorageFlag;
1920
- readonly value: InferGPU<TData>;
1921
- readonly $: InferGPU<TData>;
1922
- }
1923
- interface TgpuUniform<TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
1924
- readonly resourceType: 'uniform';
1925
- readonly buffer: TgpuBuffer<TData> & UniformFlag;
1926
- readonly value: InferGPU<TData>;
1927
- readonly $: InferGPU<TData>;
1928
- }
1929
- type TgpuBufferShorthand<TData extends BaseData> = TgpuMutable<TData> | TgpuReadonly<TData> | TgpuUniform<TData>;
1930
- declare function isBufferShorthand<TData extends BaseData>(value: unknown | TgpuBufferShorthand<TData>): value is TgpuBufferShorthand<TData>;
1931
-
1932
- /**
1933
- * Shell-less functions are possible because we can infer the signature based solely on the context
1934
- * around the function.
1935
- *
1936
- * ## Arguments
1937
- * The snippets of the function's arguments are used to infer the types of the function's arguments.
1938
- * We only care that the arguments are of a concrete type (we concretize them if they're not). We
1939
- * cache these signatures based on the argument types, so that we can reuse them across calls.
1940
- *
1941
- * ## Return type
1942
- * In shelled functions, the return type is known when generating the body, but in the case of shell-less functions,
1943
- * we gather candidates for return types when visiting return statement nodes, and try to unify them into one type
1944
- * before generating the signature.
1945
- *
1946
- * TODO: This behavior can be refined by considering the "expected type" of the function call expression.
1947
- */
1948
- interface ShelllessImpl extends SelfResolvable {
1949
- readonly resourceType: 'shellless-impl';
1950
- readonly argTypes: AnyData[];
1951
- readonly [$getNameForward]: unknown;
1952
- }
1953
-
1954
- type AnyFn = (...args: never[]) => unknown;
1955
- declare class ShelllessRepository {
1956
- cache: Map<AnyFn, ShelllessImpl[]>;
1957
- get(fn: AnyFn, argSnippets: Snippet[] | undefined): ShelllessImpl | undefined;
1958
- }
1959
-
1960
- type GenerationCtx = ResolutionCtx & {
1961
- readonly pre: string;
1962
- /**
1963
- * Used by `typedExpression` to signal downstream
1964
- * expression resolution what type is expected of them.
1965
- *
1966
- * It is used exclusively for inferring the types of structs and arrays.
1967
- * It is modified exclusively by `typedExpression` function.
1968
- */
1969
- expectedType: AnyData | undefined;
1970
- readonly topFunctionScope: FunctionScopeLayer | undefined;
1971
- readonly topFunctionReturnType: AnyData | undefined;
1972
- indent(): string;
1973
- dedent(): string;
1974
- pushBlockScope(): void;
1975
- popBlockScope(): void;
1976
- generateLog(op: string, args: Snippet[]): Snippet;
1977
- getById(id: string): Snippet | null;
1978
- defineVariable(id: string, snippet: Snippet): void;
1979
- /**
1980
- * Types that are used in `return` statements are
1981
- * reported using this function, and used to infer
1982
- * the return type of the owning function.
1983
- */
1984
- reportReturnType(dataType: AnyData): void;
1985
- readonly shelllessRepo: ShelllessRepository;
1986
- };
1987
-
1988
- /**
1989
- * Options for configuring GPU log generation.
1990
- */
1991
- interface LogGeneratorOptions {
1992
- /**
1993
- * The maximum number of logs that appear during a single draw/dispatch call.
1994
- * If this number is exceeded, a warning containing the total number of calls is logged and further logs are dropped.
1995
- * @default 64
1996
- */
1997
- logCountLimit?: number;
1998
- /**
1999
- * The total number of bytes reserved for each log call.
2000
- * If this number is exceeded, an exception is thrown during resolution.
2001
- * @default 252
2002
- */
2003
- logSizeLimit?: number;
2004
- /**
2005
- * The prefix attached to each log call.
2006
- * @default ' GPU '
2007
- */
2008
- messagePrefix?: string;
2009
- }
2010
- type SerializedLogCallData = WgslStruct<{
2011
- id: U32;
2012
- serializedData: WgslArray<U32>;
2013
- }>;
2014
- interface LogMeta {
2015
- op: SupportedLogOps;
2016
- argTypes: (string | AnyWgslData)[];
2017
- }
2018
- /**
2019
- * The resources required for logging within the TGSL console.
2020
- *
2021
- * @property indexBuffer - A buffer used for indexing log entries. Needs to be cleared after each dispatch/draw.
2022
- * @property dataBuffer - A buffer containing an array of serialized log call data.
2023
- * @property options - The configuration options for the LogGenerator.
2024
- * @property logIdToMeta - A mapping from log identifiers to an object containing the corresponding log op and argument types.
2025
- */
2026
- interface LogResources {
2027
- indexBuffer: TgpuMutable<Atomic<U32>>;
2028
- dataBuffer: TgpuMutable<WgslArray<SerializedLogCallData>>;
2029
- options: Required<LogGeneratorOptions>;
2030
- logIdToMeta: Map<number, LogMeta>;
2031
- }
2032
- declare const supportedLogOps: readonly ["log", "debug", "info", "warn", "error", "clear"];
2033
- type SupportedLogOps = (typeof supportedLogOps)[number];
2034
-
2035
- interface ShaderGenerator {
2036
- initGenerator(ctx: GenerationCtx): void;
2037
- block(body: Block): string;
2038
- identifier(id: string): Snippet;
2039
- typedExpression(expression: Expression, expectedType: AnyData): Snippet;
2040
- expression(expression: Expression): Snippet;
2041
- statement(statement: Statement): string;
2042
- functionDefinition(body: Block): string;
2043
- }
2044
-
2045
- interface TgpuGuardedComputePipeline<TArgs extends number[] = number[]> {
2046
- /**
2047
- * Returns a pipeline wrapper with the specified bind group bound.
2048
- * Analogous to `TgpuComputePipeline.with(bindGroup)`.
2049
- */
2050
- with(bindGroup: TgpuBindGroup): TgpuGuardedComputePipeline<TArgs>;
2051
- /**
2052
- * Dispatches the pipeline.
2053
- * Unlike `TgpuComputePipeline.dispatchWorkgroups()`, this method takes in the
2054
- * number of threads to run in each dimension.
2055
- *
2056
- * Under the hood, the number of expected threads is sent as a uniform, and
2057
- * "guarded" by a bounds check.
2058
- */
2059
- dispatchThreads(...args: TArgs): void;
2060
- /**
2061
- * The underlying pipeline used during `dispatchThreads`.
2062
- */
2063
- pipeline: TgpuComputePipeline;
2064
- /**
2065
- * The buffer used to automatically pass the thread count to the underlying pipeline during `dispatchThreads`.
2066
- * For pipelines with a dimension count lower than 3, the remaining coordinates are expected to be 1.
2067
- */
2068
- sizeUniform: TgpuUniform<Vec3u>;
2069
- }
2070
- interface WithCompute {
2071
- createPipeline(): TgpuComputePipeline;
2072
- }
2073
- type IsEmptyRecord<T> = T extends Record<string, never> ? true : false;
2074
- type OptionalArgs<T> = IsEmptyRecord<T> extends true ? [] | [T] : [T];
2075
- type ValidateFragmentIn<VertexOut extends VertexOutConstrained, FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = UndecorateRecord<FragmentIn> extends Partial<UndecorateRecord<VertexOut>> ? UndecorateRecord<VertexOut> extends UndecorateRecord<FragmentIn> ? OptionalArgs<FragmentOutToTargets<FragmentOut>> extends infer Args ? Args extends [infer T] ? [entryFn: TgpuFragmentFn<FragmentIn, FragmentOut>, targets: T] : Args extends [] | [infer T] ? [entryFn: TgpuFragmentFn<FragmentIn, FragmentOut>] | [entryFn: TgpuFragmentFn<FragmentIn, FragmentOut>, targets: T] : never : never : [
2076
- entryFn: 'n/a',
2077
- targets: 'n/a',
2078
- MissingFromVertexOutput: {
2079
- [Key in Exclude<keyof FragmentIn, keyof VertexOut>]: FragmentIn[Key];
2080
- }
2081
- ] : [
2082
- entryFn: 'n/a',
2083
- targets: 'n/a',
2084
- MismatchedVertexOutput: {
2085
- [Key in keyof FragmentIn & keyof VertexOut as FragmentIn[Key] extends VertexOut[Key] ? never : Key]: [got: VertexOut[Key], expecting: FragmentIn[Key]];
2086
- }
2087
- ];
2088
- interface WithVertex<VertexOut extends VertexOutConstrained = VertexOutConstrained> {
2089
- withFragment<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained>(...args: ValidateFragmentIn<VertexOut, FragmentIn, FragmentOut>): WithFragment<FragmentOut>;
2090
- withPrimitive(primitiveState: GPUPrimitiveState | Omit<GPUPrimitiveState, 'stripIndexFormat'> & {
2091
- stripIndexFormat?: U32 | U16;
2092
- } | undefined): WithFragment<Void>;
2093
- withDepthStencil(depthStencilState: GPUDepthStencilState | undefined): WithFragment<Void>;
2094
- withMultisample(multisampleState: GPUMultisampleState | undefined): WithFragment<Void>;
2095
- createPipeline(): TgpuRenderPipeline<Void>;
2096
- }
2097
- interface WithFragment<Output extends FragmentOutConstrained = FragmentOutConstrained> {
2098
- withPrimitive(primitiveState: GPUPrimitiveState | Omit<GPUPrimitiveState, 'stripIndexFormat'> & {
2099
- stripIndexFormat?: U32 | U16;
2100
- } | undefined): WithFragment<Output>;
2101
- withDepthStencil(depthStencilState: GPUDepthStencilState | undefined): WithFragment<Output>;
2102
- withMultisample(multisampleState: GPUMultisampleState | undefined): WithFragment<Output>;
2103
- createPipeline(): TgpuRenderPipeline<Output>;
2104
- }
2105
- interface Configurable {
2106
- readonly bindings: [slot: TgpuSlot<unknown>, value: unknown][];
2107
- with<T>(slot: TgpuSlot<T>, value: Eventual<T>): Configurable;
2108
- with<T extends WgslTexture | WgslStorageTexture>(accessor: TgpuAccessor<T>, value: TgpuTextureView<T> | Infer<T>): Configurable;
2109
- with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<() => T> | TgpuBufferUsage<T> | TgpuBufferShorthand<T> | Infer<T>): Configurable;
2110
- pipe(transform: (cfg: Configurable) => Configurable): Configurable;
2111
- }
2112
- interface WithBinding {
2113
- withCompute<ComputeIn extends IORecord<AnyComputeBuiltin>>(entryFn: TgpuComputeFn<ComputeIn>): WithCompute;
2114
- /**
2115
- * Creates a compute pipeline that executes the given callback in an exact number of threads.
2116
- * This is different from `withCompute(...).createPipeline()` in that it does a bounds check on the
2117
- * thread id, where as regular pipelines do not and work in units of workgroups.
2118
- *
2119
- * @param callback A function converted to WGSL and executed on the GPU.
2120
- * It can accept up to 3 parameters (x, y, z) which correspond to the global invocation ID
2121
- * of the executing thread.
2122
- *
2123
- * @example
2124
- * If no parameters are provided, the callback will be executed once, in a single thread.
2125
- *
2126
- * ```ts
2127
- * const fooPipeline = root
2128
- * .createGuardedComputePipeline(() => {
2129
- * 'use gpu';
2130
- * console.log('Hello, GPU!');
2131
- * });
2132
- *
2133
- * fooPipeline.dispatchThreads();
2134
- * // [GPU] Hello, GPU!
2135
- * ```
2136
- *
2137
- * @example
2138
- * One parameter means n-threads will be executed in parallel.
2139
- *
2140
- * ```ts
2141
- * const fooPipeline = root
2142
- * .createGuardedComputePipeline((x) => {
2143
- * 'use gpu';
2144
- * if (x % 16 === 0) {
2145
- * // Logging every 16th thread
2146
- * console.log('I am the', x, 'thread');
2147
- * }
2148
- * });
2149
- *
2150
- * // executing 512 threads
2151
- * fooPipeline.dispatchThreads(512);
2152
- * // [GPU] I am the 256 thread
2153
- * // [GPU] I am the 272 thread
2154
- * // ... (30 hidden logs)
2155
- * // [GPU] I am the 16 thread
2156
- * // [GPU] I am the 240 thread
2157
- * ```
2158
- */
2159
- createGuardedComputePipeline<TArgs extends number[]>(callback: (...args: TArgs) => void): TgpuGuardedComputePipeline<TArgs>;
2160
- withVertex<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(entryFn: TgpuVertexFn<VertexIn, VertexOut>, ...args: OptionalArgs<LayoutToAllowedAttribs<OmitBuiltins<VertexIn>>>): WithVertex<VertexOut>;
2161
- with<T>(slot: TgpuSlot<T>, value: Eventual<T>): WithBinding;
2162
- with<T extends WgslTexture | WgslStorageTexture>(accessor: TgpuAccessor<T>, value: TgpuTextureView<T> | Infer<T>): WithBinding;
2163
- with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<() => T> | TgpuBufferUsage<T> | TgpuBufferShorthand<T> | Infer<T>): WithBinding;
2164
- pipe(transform: (cfg: Configurable) => Configurable): WithBinding;
2165
- }
2166
- type SrgbVariants = {
2167
- rgba8unorm: 'rgba8unorm-srgb';
2168
- bgra8unorm: 'bgra8unorm-srgb';
2169
- 'bc1-rgba-unorm': 'bc1-rgba-unorm-srgb';
2170
- 'bc2-rgba-unorm': 'bc2-rgba-unorm-srgb';
2171
- 'bc3-rgba-unorm': 'bc3-rgba-unorm-srgb';
2172
- 'bc7-rgba-unorm': 'bc7-rgba-unorm-srgb';
2173
- 'etc2-rgb8unorm': 'etc2-rgb8unorm-srgb';
2174
- 'etc2-rgb8a1unorm': 'etc2-rgb8a1unorm-srgb';
2175
- 'etc2-rgba8unorm': 'etc2-rgba8unorm-srgb';
2176
- 'astc-4x4-unorm': 'astc-4x4-unorm-srgb';
2177
- 'astc-5x4-unorm': 'astc-5x4-unorm-srgb';
2178
- 'astc-5x5-unorm': 'astc-5x5-unorm-srgb';
2179
- 'astc-6x5-unorm': 'astc-6x5-unorm-srgb';
2180
- 'astc-6x6-unorm': 'astc-6x6-unorm-srgb';
2181
- 'astc-8x5-unorm': 'astc-8x5-unorm-srgb';
2182
- 'astc-8x6-unorm': 'astc-8x6-unorm-srgb';
2183
- 'astc-8x8-unorm': 'astc-8x8-unorm-srgb';
2184
- 'astc-10x5-unorm': 'astc-10x5-unorm-srgb';
2185
- 'astc-10x6-unorm': 'astc-10x6-unorm-srgb';
2186
- 'astc-10x8-unorm': 'astc-10x8-unorm-srgb';
2187
- 'astc-10x10-unorm': 'astc-10x10-unorm-srgb';
2188
- 'astc-12x10-unorm': 'astc-12x10-unorm-srgb';
2189
- 'astc-12x12-unorm': 'astc-12x12-unorm-srgb';
2190
- };
2191
- type SrgbVariantOrSelf<T extends GPUTextureFormat> = T extends keyof SrgbVariants ? (SrgbVariants[T] | T)[] | undefined : T extends `${infer Base}-srgb` ? Base extends keyof SrgbVariants ? (T | SrgbVariants[Base])[] | undefined : T[] | undefined : T[] | undefined;
2192
- type CreateTextureOptions<TSize, TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormats extends GPUTextureFormat[], TDimension extends GPUTextureDimension> = {
2193
- /**
2194
- * The width, height, and depth or layer count of the texture.
2195
- */
2196
- size: TSize;
2197
- /**
2198
- * The format of the texture.
2199
- */
2200
- format: TFormat;
2201
- /**
2202
- * The number of mip levels the texture will contain.
2203
- * @default 1
2204
- */
2205
- mipLevelCount?: TMipLevelCount | undefined;
2206
- /**
2207
- * The sample count of the texture. A sampleCount > 1 indicates a multisampled texture.
2208
- * @default 1
2209
- */
2210
- sampleCount?: TSampleCount | undefined;
2211
- /**
2212
- * Specifies extra formats (in addition to the texture's actual format) that can be used
2213
- * when creating views of this texture.
2214
- * @default []
2215
- */
2216
- viewFormats?: TViewFormats extends SrgbVariantOrSelf<NoInfer<TFormat>> ? TViewFormats : SrgbVariantOrSelf<NoInfer<TFormat>>;
2217
- /**
2218
- * Whether the texture is one-dimensional, an array of two-dimensional layers, or three-dimensional.
2219
- * @default '2d'
2220
- */
2221
- dimension?: TDimension | undefined;
2222
- };
2223
- type CreateTextureResult<TSize extends readonly number[], TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormats extends GPUTextureFormat[], TDimension extends GPUTextureDimension> = Prettify<{
2224
- size: Mutable<TSize>;
2225
- format: TFormat;
2226
- } & OmitProps<{
2227
- dimension: GPUTextureDimension extends TDimension ? undefined : TDimension extends '2d' ? undefined : TDimension;
2228
- mipLevelCount: number extends TMipLevelCount ? undefined : TMipLevelCount extends 1 ? undefined : TMipLevelCount;
2229
- sampleCount: number extends TSampleCount ? undefined : TSampleCount extends 1 ? undefined : TSampleCount;
2230
- viewFormats: GPUTextureFormat[] extends TViewFormats ? undefined : TViewFormats extends never[] ? undefined : TViewFormats extends SrgbVariantOrSelf<TFormat> ? TViewFormats : never;
2231
- }, undefined>>;
2232
- interface RenderPass {
2233
- /**
2234
- * Sets the viewport used during the rasterization stage to linearly map from
2235
- * NDC (i.e., normalized device coordinates) to viewport coordinates.
2236
- * @param x - Minimum X value of the viewport in pixels.
2237
- * @param y - Minimum Y value of the viewport in pixels.
2238
- * @param width - Width of the viewport in pixels.
2239
- * @param height - Height of the viewport in pixels.
2240
- * @param minDepth - Minimum depth value of the viewport.
2241
- * @param maxDepth - Maximum depth value of the viewport.
2242
- */
2243
- setViewport(x: number, y: number, width: number, height: number, minDepth: number, maxDepth: number): void;
2244
- /**
2245
- * Sets the scissor rectangle used during the rasterization stage.
2246
- * After transformation into viewport coordinates any fragments which fall outside the scissor
2247
- * rectangle will be discarded.
2248
- * @param x - Minimum X value of the scissor rectangle in pixels.
2249
- * @param y - Minimum Y value of the scissor rectangle in pixels.
2250
- * @param width - Width of the scissor rectangle in pixels.
2251
- * @param height - Height of the scissor rectangle in pixels.
2252
- */
2253
- setScissorRect(x: number, y: number, width: number, height: number): void;
2254
- /**
2255
- * Sets the constant blend color and alpha values used with {@link GPUBlendFactor#constant}
2256
- * and {@link GPUBlendFactor#"one-minus-constant"} {@link GPUBlendFactor}s.
2257
- * @param color - The color to use when blending.
2258
- */
2259
- setBlendConstant(color: GPUColor): void;
2260
- /**
2261
- * Sets the {@link RenderState#[[stencilReference]]} value used during stencil tests with
2262
- * the {@link GPUStencilOperation#"replace"} {@link GPUStencilOperation}.
2263
- * @param reference - The new stencil reference value.
2264
- */
2265
- setStencilReference(reference: GPUStencilValue): undefined;
2266
- /**
2267
- * @param queryIndex - The index of the query in the query set.
2268
- */
2269
- beginOcclusionQuery(queryIndex: GPUSize32): undefined;
2270
- endOcclusionQuery(): undefined;
2271
- /**
2272
- * Executes the commands previously recorded into the given {@link GPURenderBundle}s as part of
2273
- * this render pass.
2274
- * When a {@link GPURenderBundle} is executed, it does not inherit the render pass's pipeline, bind
2275
- * groups, or vertex and index buffers. After a {@link GPURenderBundle} has executed, the render
2276
- * pass's pipeline, bind group, and vertex/index buffer state is cleared
2277
- * (to the initial, empty values).
2278
- * Note: The state is cleared, not restored to the previous state.
2279
- * This occurs even if zero {@link GPURenderBundle|GPURenderBundles} are executed.
2280
- * @param bundles - List of render bundles to execute.
2281
- */
2282
- executeBundles(bundles: Iterable<GPURenderBundle>): undefined;
2283
- setPipeline(pipeline: TgpuRenderPipeline): void;
2284
- /**
2285
- * Sets the current index buffer.
2286
- * @param buffer - Buffer containing index data to use for subsequent drawing commands.
2287
- * @param indexFormat - Format of the index data contained in `buffer`.
2288
- * @param offset - Offset in bytes into `buffer` where the index data begins. Defaults to `0`.
2289
- * @param size - Size in bytes of the index data in `buffer`.
2290
- * Defaults to the size of the buffer minus the offset.
2291
- */
2292
- setIndexBuffer<TData extends WgslArray | Disarray>(buffer: TgpuBuffer<TData> | GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): void;
2293
- setVertexBuffer<TData extends WgslArray | Disarray>(vertexLayout: TgpuVertexLayout<TData>, buffer: (TgpuBuffer<TData> & VertexFlag) | GPUBuffer, offset?: GPUSize64, size?: GPUSize64): void;
2294
- setBindGroup<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries> | GPUBindGroup): void;
2295
- /**
2296
- * Draws primitives.
2297
- * @param vertexCount - The number of vertices to draw.
2298
- * @param instanceCount - The number of instances to draw.
2299
- * @param firstVertex - Offset into the vertex buffers, in vertices, to begin drawing from.
2300
- * @param firstInstance - First instance to draw.
2301
- */
2302
- draw(vertexCount: number, instanceCount?: number | undefined, firstVertex?: number | undefined, firstInstance?: number | undefined): void;
2303
- /**
2304
- * Draws indexed primitives.
2305
- * @param indexCount - The number of indices to draw.
2306
- * @param instanceCount - The number of instances to draw.
2307
- * @param firstIndex - Offset into the index buffer, in indices, begin drawing from.
2308
- * @param baseVertex - Added to each index value before indexing into the vertex buffers.
2309
- * @param firstInstance - First instance to draw.
2310
- */
2311
- drawIndexed(indexCount: number, instanceCount?: number | undefined, firstIndex?: number | undefined, baseVertex?: number | undefined, firstInstance?: number | undefined): void;
2312
- /**
2313
- * Draws primitives using parameters read from a {@link GPUBuffer}.
2314
- * Packed block of **four 32-bit unsigned integer values (16 bytes total)**, given in the same
2315
- * order as the arguments for {@link GPURenderEncoderBase#draw}. For example:
2316
- * @param indirectBuffer - Buffer containing the indirect draw parameters.
2317
- * @param indirectOffset - Offset in bytes into `indirectBuffer` where the drawing data begins.
2318
- */
2319
- drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): undefined;
2320
- /**
2321
- * Draws indexed primitives using parameters read from a {@link GPUBuffer}.
2322
- * Tightly packed block of **five 32-bit unsigned integer values (20 bytes total)**, given in
2323
- * the same order as the arguments for {@link GPURenderEncoderBase#drawIndexed}. For example:
2324
- * @param indirectBuffer - Buffer containing the indirect drawIndexed parameters.
2325
- * @param indirectOffset - Offset in bytes into `indirectBuffer` where the drawing data begins.
2326
- */
2327
- drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): undefined;
2328
- }
2329
- type ValidateBufferSchema<TData extends AnyData> = IsValidBufferSchema<TData> extends false ? ExtractInvalidSchemaError<TData, '(Error) '> : TData;
2330
- type ValidateStorageSchema<TData extends AnyData> = IsValidStorageSchema<TData> extends false ? ExtractInvalidSchemaError<TData, '(Error) '> : TData;
2331
- type ValidateUniformSchema<TData extends AnyData> = IsValidUniformSchema<TData> extends false ? ExtractInvalidSchemaError<TData, '(Error) '> : TData;
2332
- interface TgpuRoot extends Unwrapper {
2333
- [$internal]: {
2334
- logOptions: LogGeneratorOptions;
2335
- };
2336
- /**
2337
- * The GPU device associated with this root.
2338
- */
2339
- readonly device: GPUDevice;
2340
- /**
2341
- * Allocates memory on the GPU, allows passing data between host and shader.
2342
- *
2343
- * @remarks
2344
- * Typed wrapper around a GPUBuffer.
2345
- *
2346
- * @param typeSchema The type of data that this buffer will hold.
2347
- * @param initial The initial value of the buffer. (optional)
2348
- */
2349
- createBuffer<TData extends AnyData>(typeSchema: ValidateBufferSchema<TData>, initial?: Infer<NoInfer<TData>> | undefined): TgpuBuffer<TData>;
2350
- /**
2351
- * Allocates memory on the GPU, allows passing data between host and shader.
2352
- *
2353
- * @remarks
2354
- * Typed wrapper around a GPUBuffer.
2355
- *
2356
- * @param typeSchema The type of data that this buffer will hold.
2357
- * @param gpuBuffer A vanilla WebGPU buffer.
2358
- */
2359
- createBuffer<TData extends AnyData>(typeSchema: ValidateBufferSchema<TData>, gpuBuffer: GPUBuffer): TgpuBuffer<TData>;
2360
- /**
2361
- * Allocates memory on the GPU, allows passing data between host and shader.
2362
- * Read-only on the GPU, optimized for small data. For a general-purpose buffer,
2363
- * use {@link TgpuRoot.createBuffer}.
2364
- *
2365
- * @param typeSchema The type of data that this buffer will hold.
2366
- * @param initial The initial value of the buffer. (optional)
2367
- */
2368
- createUniform<TData extends AnyWgslData>(typeSchema: ValidateUniformSchema<TData>, initial?: Infer<NoInfer<TData>>): TgpuUniform<TData>;
2369
- /**
2370
- * Allocates memory on the GPU, allows passing data between host and shader.
2371
- * Read-only on the GPU, optimized for small data. For a general-purpose buffer,
2372
- * use {@link TgpuRoot.createBuffer}.
2373
- *
2374
- * @param typeSchema The type of data that this buffer will hold.
2375
- * @param gpuBuffer A vanilla WebGPU buffer.
2376
- */
2377
- createUniform<TData extends AnyWgslData>(typeSchema: ValidateUniformSchema<TData>, gpuBuffer: GPUBuffer): TgpuUniform<TData>;
2378
- /**
2379
- * Allocates memory on the GPU, allows passing data between host and shader.
2380
- * Can be mutated in-place on the GPU. For a general-purpose buffer,
2381
- * use {@link TgpuRoot.createBuffer}.
2382
- *
2383
- * @param typeSchema The type of data that this buffer will hold.
2384
- * @param initial The initial value of the buffer. (optional)
2385
- */
2386
- createMutable<TData extends AnyWgslData>(typeSchema: ValidateStorageSchema<TData>, initial?: Infer<NoInfer<TData>>): TgpuMutable<TData>;
2387
- /**
2388
- * Allocates memory on the GPU, allows passing data between host and shader.
2389
- * Can be mutated in-place on the GPU. For a general-purpose buffer,
2390
- * use {@link TgpuRoot.createBuffer}.
2391
- *
2392
- * @param typeSchema The type of data that this buffer will hold.
2393
- * @param gpuBuffer A vanilla WebGPU buffer.
2394
- */
2395
- createMutable<TData extends AnyWgslData>(typeSchema: ValidateStorageSchema<TData>, gpuBuffer: GPUBuffer): TgpuMutable<TData>;
2396
- /**
2397
- * Allocates memory on the GPU, allows passing data between host and shader.
2398
- * Read-only on the GPU, optimized for large data. For a general-purpose buffer,
2399
- * use {@link TgpuRoot.createBuffer}.
2400
- *
2401
- * @param typeSchema The type of data that this buffer will hold.
2402
- * @param initial The initial value of the buffer. (optional)
2403
- */
2404
- createReadonly<TData extends AnyWgslData>(typeSchema: ValidateStorageSchema<TData>, initial?: Infer<NoInfer<TData>>): TgpuReadonly<TData>;
2405
- /**
2406
- * Allocates memory on the GPU, allows passing data between host and shader.
2407
- * Read-only on the GPU, optimized for large data. For a general-purpose buffer,
2408
- * use {@link TgpuRoot.createBuffer}.
2409
- *
2410
- * @param typeSchema The type of data that this buffer will hold.
2411
- * @param gpuBuffer A vanilla WebGPU buffer.
2412
- */
2413
- createReadonly<TData extends AnyWgslData>(typeSchema: ValidateStorageSchema<TData>, gpuBuffer: GPUBuffer): TgpuReadonly<TData>;
2414
- /**
2415
- * Creates a query set for collecting timestamps or occlusion queries.
2416
- *
2417
- * @remarks
2418
- * Typed wrapper around a GPUQuerySet.
2419
- *
2420
- * @param type The type of queries to collect ('occlusion' or 'timestamp').
2421
- * @param count The number of queries in the set.
2422
- * @param rawQuerySet An optional pre-existing GPUQuerySet to use instead of creating a new one.
2423
- */
2424
- createQuerySet<T extends GPUQueryType>(type: T, count: number, rawQuerySet?: GPUQuerySet | undefined): TgpuQuerySet<T>;
2425
- /**
2426
- * Creates a group of resources that can be bound to a shader based on a specified layout.
2427
- *
2428
- * @remarks
2429
- * Typed wrapper around a GPUBindGroup.
2430
- *
2431
- * @example
2432
- * const fooLayout = tgpu.bindGroupLayout({
2433
- * foo: { uniform: d.vec3f },
2434
- * bar: { texture: 'float' },
2435
- * });
2436
- *
2437
- * const fooBuffer = ...;
2438
- * const barTexture = ...;
2439
- *
2440
- * const fooBindGroup = root.createBindGroup(fooLayout, {
2441
- * foo: fooBuffer,
2442
- * bar: barTexture,
2443
- * });
2444
- *
2445
- * @param layout Layout describing the bind group to be created.
2446
- * @param entries A record with values being the resources populating the bind group
2447
- * and keys being their associated names, matching the layout keys.
2448
- */
2449
- createBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>>(layout: TgpuBindGroupLayout<Entries>, entries: ExtractBindGroupInputFromLayout<Entries>): TgpuBindGroup<Entries>;
2450
- /**
2451
- * Retrieves a read-only list of all enabled features of the GPU device.
2452
- * @returns A set of strings representing the enabled features.
2453
- */
2454
- get enabledFeatures(): ReadonlySet<GPUFeatureName>;
2455
- /**
2456
- * Destroys all underlying resources (i.e. buffers...) created through this root object.
2457
- * If the object is created via `tgpu.init` instead of `tgpu.initFromDevice`,
2458
- * then the inner GPU device is destroyed as well.
2459
- */
2460
- destroy(): void;
2461
- '~unstable': Omit<ExperimentalTgpuRoot, keyof TgpuRoot>;
2462
- }
2463
- interface ExperimentalTgpuRoot extends TgpuRoot, WithBinding {
2464
- readonly nameRegistrySetting: 'strict' | 'random';
2465
- readonly shaderGenerator?: ShaderGenerator | undefined;
2466
- createTexture<TWidth extends number, THeight extends number, TDepth extends number, TSize extends readonly [TWidth] | readonly [TWidth, THeight] | readonly [TWidth, THeight, TDepth], TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormats extends GPUTextureFormat[], TDimension extends GPUTextureDimension>(props: CreateTextureOptions<TSize, TFormat, TMipLevelCount, TSampleCount, TViewFormats, TDimension>): TgpuTexture<CreateTextureResult<TSize, TFormat, TMipLevelCount, TSampleCount, TViewFormats, TDimension>>;
2467
- beginRenderPass(descriptor: GPURenderPassDescriptor, callback: (pass: RenderPass) => void): void;
2468
- createSampler(props: WgslSamplerProps): TgpuFixedSampler;
2469
- createComparisonSampler(props: WgslComparisonSamplerProps): TgpuFixedComparisonSampler;
2470
- /**
2471
- * @deprecated Used to cause all commands enqueued by pipelines to be
2472
- * submitted to the GPU, but now commands are immediately dispatched,
2473
- * which makes this method unnecessary.
2474
- */
2475
- flush(): void;
2476
- }
2477
-
2478
- interface UniformFlag {
2479
- usableAsUniform: true;
2480
- }
2481
- /**
2482
- * @deprecated Use UniformFlag instead.
2483
- */
2484
- type Uniform = UniformFlag;
2485
- interface VertexFlag {
2486
- usableAsVertex: true;
2487
- }
2488
- interface IndexFlag {
2489
- usableAsIndex: true;
2490
- }
2491
- /**
2492
- * @deprecated Use VertexFlag instead.
2493
- */
2494
- type Vertex = VertexFlag;
2495
- type LiteralToUsageType<T extends 'uniform' | 'storage' | 'vertex' | 'index'> = T extends 'uniform' ? UniformFlag : T extends 'storage' ? StorageFlag : T extends 'vertex' ? VertexFlag : T extends 'index' ? IndexFlag : never;
2496
- type ViewUsages<TBuffer extends TgpuBuffer<BaseData>> = (boolean extends TBuffer['usableAsUniform'] ? never : 'uniform') | (boolean extends TBuffer['usableAsStorage'] ? never : 'readonly' | 'mutable');
2497
- type UsageTypeToBufferUsage<TData extends BaseData> = {
2498
- uniform: TgpuBufferUniform<TData> & TgpuFixedBufferUsage<TData>;
2499
- mutable: TgpuBufferMutable<TData> & TgpuFixedBufferUsage<TData>;
2500
- readonly: TgpuBufferReadonly<TData> & TgpuFixedBufferUsage<TData>;
2501
- };
2502
- /**
2503
- * Done as an object to later Prettify it
2504
- */
2505
- type InnerValidUsagesFor<T> = {
2506
- usage: (IsValidStorageSchema<T> extends true ? 'storage' : never) | (IsValidUniformSchema<T> extends true ? 'uniform' : never) | (IsValidVertexSchema<T> extends true ? 'vertex' : never) | (IsValidIndexSchema<T> extends true ? 'index' : never);
2507
- };
2508
- type ValidUsagesFor<T> = InnerValidUsagesFor<T>['usage'];
2509
- interface TgpuBuffer<TData extends BaseData> extends TgpuNamable {
2510
- readonly [$internal]: true;
2511
- readonly resourceType: 'buffer';
2512
- readonly dataType: TData;
2513
- readonly initial?: Infer<TData> | undefined;
2514
- readonly buffer: GPUBuffer;
2515
- readonly destroyed: boolean;
2516
- usableAsUniform: boolean;
2517
- usableAsStorage: boolean;
2518
- usableAsVertex: boolean;
2519
- usableAsIndex: boolean;
2520
- $usage<T extends [
2521
- Prettify<InnerValidUsagesFor<TData>>['usage'],
2522
- ...Prettify<InnerValidUsagesFor<TData>>['usage'][]
2523
- ]>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
2524
- $addFlags(flags: GPUBufferUsageFlags): this;
2525
- as<T extends ViewUsages<this>>(usage: T): UsageTypeToBufferUsage<TData>[T];
2526
- compileWriter(): void;
2527
- write(data: Infer<TData>): void;
2528
- writePartial(data: InferPartial<TData>): void;
2529
- clear(): void;
2530
- copyFrom(srcBuffer: TgpuBuffer<MemIdentity<TData>>): void;
2531
- read(): Promise<Infer<TData>>;
2532
- destroy(): void;
2533
- }
2534
- declare function isBuffer<T extends TgpuBuffer<AnyData>>(value: T | unknown): value is T;
2535
- declare function isUsableAsVertex<T extends TgpuBuffer<AnyData>>(buffer: T): buffer is T & VertexFlag;
2536
-
2537
- type TgpuLayoutEntryBase = {
2538
- /**
2539
- * Limits this resource's visibility to specific shader stages.
2540
- *
2541
- * By default, each resource is visible to all shader stage types, but
2542
- * depending on the underlying implementation, this may have performance implications.
2543
- *
2544
- * @default ['compute','fragment'] for mutable resources
2545
- * @default ['compute','vertex','fragment'] for everything else
2546
- */
2547
- visibility?: TgpuShaderStage[];
2548
- };
2549
- type TgpuLayoutUniform = TgpuLayoutEntryBase & {
2550
- uniform: AnyWgslData;
2551
- };
2552
- type TgpuLayoutStorage = TgpuLayoutEntryBase & {
2553
- storage: AnyWgslData | ((arrayLength: number) => AnyWgslData);
2554
- /** @default 'readonly' */
2555
- access?: 'mutable' | 'readonly';
2556
- };
2557
- type TgpuLayoutSampler = TgpuLayoutEntryBase & {
2558
- sampler: 'filtering' | 'non-filtering';
2559
- };
2560
- type TgpuLayoutComparisonSampler = TgpuLayoutEntryBase & {
2561
- sampler: 'comparison';
2562
- };
2563
- type TgpuLayoutTexture<TSchema extends WgslTexture = WgslTexture> = TgpuLayoutEntryBase & {
2564
- texture: TSchema;
2565
- sampleType?: GPUTextureSampleType;
2566
- };
2567
- type TgpuLayoutStorageTexture<TSchema extends WgslStorageTexture = WgslStorageTexture> = TgpuLayoutEntryBase & {
2568
- storageTexture: TSchema;
2569
- };
2570
- type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
2571
- externalTexture: WgslExternalTexture;
2572
- };
2573
- type TgpuLegacyLayoutTexture<TSampleType extends GPUTextureSampleType = GPUTextureSampleType> = TgpuLayoutEntryBase & {
2574
- /**
2575
- * - 'float' - f32
2576
- * - 'unfilterable-float' - f32, cannot be used with filtering samplers
2577
- * - 'depth' - f32
2578
- * - 'sint' - i32
2579
- * - 'uint' - u32
2580
- */
2581
- texture: TSampleType;
2582
- /**
2583
- * @default '2d'
2584
- */
2585
- viewDimension?: GPUTextureViewDimension;
2586
- /**
2587
- * @default false
2588
- */
2589
- multisampled?: boolean;
2590
- };
2591
- type TgpuLegacyLayoutStorageTexture<TFormat extends StorageTextureFormats = StorageTextureFormats> = TgpuLayoutEntryBase & {
2592
- storageTexture: TFormat;
2593
- /** @default 'writeonly' */
2594
- access?: 'readonly' | 'writeonly' | 'mutable';
2595
- /** @default '2d' */
2596
- viewDimension?: StorageTextureDimension;
2597
- };
2598
- type TgpuLegacyLayoutExternalTexture = TgpuLayoutEntryBase & {
2599
- externalTexture: Record<string, never>;
2600
- };
2601
- type TgpuLegacyLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutComparisonSampler | TgpuLegacyLayoutTexture | TgpuLegacyLayoutStorageTexture | TgpuLegacyLayoutExternalTexture;
2602
- type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutComparisonSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
2603
- type SampleTypeToPrimitive = {
2604
- float: F32;
2605
- 'unfilterable-float': F32;
2606
- depth: F32;
2607
- sint: I32;
2608
- uint: U32;
2609
- };
2610
- type LeagcyAccessToAccess = {
2611
- writeonly: 'write-only';
2612
- readonly: 'read-only';
2613
- mutable: 'read-write';
2614
- };
2615
- type MapLegacyTextureToUpToDate<T extends Record<string, TgpuLegacyLayoutEntry | TgpuLayoutEntry | null>> = {
2616
- [K in keyof T]: T[K] extends TgpuLayoutEntry | null ? T[K] : T[K] extends TgpuLegacyLayoutTexture<infer SampleType> ? TgpuLayoutTexture<TextureSchemaForDescriptor<{
2617
- dimension: Default<T[K]['viewDimension'], '2d'>;
2618
- sampleType: SampleTypeToPrimitive[SampleType];
2619
- multisampled: Default<T[K]['multisampled'], false>;
2620
- }>> : T[K] extends TgpuLegacyLayoutStorageTexture<infer Format> ? TgpuLayoutStorageTexture<TextureSchemaForDescriptor<{
2621
- access: LeagcyAccessToAccess[Default<T[K]['access'], 'writeonly'>];
2622
- format: Format;
2623
- dimension: Default<T[K]['viewDimension'], '2d'>;
2624
- }>> : T[K] extends TgpuLegacyLayoutExternalTexture ? TgpuLayoutExternalTexture : never;
2625
- };
2626
- type UnwrapRuntimeConstructorInner<T extends BaseData | ((_: number) => BaseData)> = T extends (_: number) => BaseData ? ReturnType<T> : T;
2627
- type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
2628
- interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
2629
- readonly [$internal]: true;
2630
- readonly resourceType: 'bind-group-layout';
2631
- readonly entries: Entries;
2632
- readonly bound: {
2633
- [K in keyof Entries]: BindLayoutEntry<Entries[K]>;
2634
- };
2635
- readonly [$gpuValueOf]: {
2636
- [K in keyof Entries]: InferLayoutEntry<Entries[K]>;
2637
- };
2638
- readonly value: {
2639
- [K in keyof Entries]: InferLayoutEntry<Entries[K]>;
2640
- };
2641
- readonly $: {
2642
- [K in keyof Entries]: InferLayoutEntry<Entries[K]>;
2643
- };
2644
- /**
2645
- * An explicit numeric index assigned to this bind group layout. If undefined, a unique
2646
- * index is assigned automatically during resolution. This can be changed with the
2647
- * `.$idx()` method.
2648
- */
2649
- readonly index: number | undefined;
2650
- /**
2651
- * Associates this bind group layout with an explicit numeric index. When a call to this
2652
- * method is omitted, a unique numeric index is assigned to it automatically.
2653
- *
2654
- * Used when generating WGSL code: `@group(${index}) @binding(...) ...;`
2655
- */
2656
- $idx(index?: number): this;
2657
- /**
2658
- * Creates a raw WebGPU resource based on the typed descriptor.
2659
- * NOTE: This creates a new resource every time, better to use `root.unwrap(...)` instead.
2660
- * @param unwrapper Used to unwrap any resources that this resource depends on.
2661
- */
2662
- unwrap(unwrapper: Unwrapper): GPUBindGroupLayout;
2663
- }
2664
- type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
2665
- access?: infer Access;
2666
- } ? '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']>>;
2667
- type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = TgpuLayoutEntry | null extends T ? TgpuBuffer<AnyWgslData> | GPUBuffer | TgpuSampler | GPUSampler | TgpuComparisonSampler | GPUSampler | TgpuTexture | GPUTextureView | GPUExternalTexture : T extends TgpuLayoutUniform ? (TgpuBuffer<MemIdentity<UnwrapRuntimeConstructor<T['uniform']>>> & UniformFlag) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer<MemIdentity<UnwrapRuntimeConstructor<T['storage']>>> & StorageFlag) | GPUBuffer : T extends TgpuLayoutSampler ? TgpuSampler | GPUSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler | GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | GPUTexture | (SampledFlag & TgpuTexture<Prettify<PropsForSchema<T['texture']>>>) | TgpuTextureView<WgslTexture> : T extends TgpuLayoutStorageTexture ? GPUTextureView | GPUTexture | (StorageFlag & TgpuTexture<Prettify<PropsForSchema<T['storageTexture']>>>) | TgpuTextureView<WgslStorageTexture> : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
2668
- type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<T['uniform']> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture<infer TSchema> ? TgpuTextureView<TSchema> : T extends TgpuLayoutStorageTexture<infer TSchema> ? TgpuTextureView<TSchema> : T extends TgpuLayoutExternalTexture ? TgpuExternalTexture : never;
2669
- type InferLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? Infer<T['uniform']> : T extends TgpuLayoutStorage ? Infer<UnwrapRuntimeConstructor<T['storage']>> : T extends TgpuLayoutSampler ? Infer<WgslSampler> : T extends TgpuLayoutComparisonSampler ? Infer<WgslComparisonSampler> : T extends TgpuLayoutTexture<infer TSchema> ? Infer<TSchema> : T extends TgpuLayoutStorageTexture<infer TSchema> ? Infer<TSchema> : T extends TgpuLayoutExternalTexture ? Infer<T['externalTexture']> : never;
2670
- type ExtractBindGroupInputFromLayout<T extends Record<string, TgpuLayoutEntry | null>> = NullableToOptional<{
2671
- [K in keyof T]: LayoutEntryToInput<T[K]>;
2672
- }>;
2673
- type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
2674
- readonly resourceType: 'bind-group';
2675
- readonly layout: TgpuBindGroupLayout<Entries>;
2676
- unwrap(unwrapper: Unwrapper): GPUBindGroup;
2677
- };
2678
- declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<Entries>>;
2679
- /**
2680
- * @deprecated Layouts containing the legacy texture api entries are deprecated and will be removed in future versions. Please use the up-to-date texture api entries instead.
2681
- */
2682
- declare function bindGroupLayout<Entries extends Record<string, TgpuLegacyLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<MapLegacyTextureToUpToDate<Entries>>>;
2683
-
2684
- type TextureInternals = {
2685
- unwrap(): GPUTexture;
2686
- };
2687
- type TextureViewInternals = {
2688
- readonly unwrap: (() => GPUTextureView) | undefined;
2689
- };
2690
- type ExternalImageSource = HTMLCanvasElement | HTMLImageElement | HTMLVideoElement | ImageBitmap | ImageData | OffscreenCanvas | VideoFrame;
2691
- type TgpuTextureViewDescriptor = {
2692
- /**
2693
- * Which {@link GPUTextureAspect | aspect(s)} of the texture are accessible to the texture view.
2694
- */
2695
- aspect?: GPUTextureAspect;
2696
- /**
2697
- * The first (most detailed) mipmap level accessible to the texture view.
2698
- */
2699
- baseMipLevel?: GPUIntegerCoordinate;
2700
- /**
2701
- * How many mipmap levels, starting with {@link GPUTextureViewDescriptor#baseMipLevel}, are accessible to
2702
- * the texture view.
2703
- */
2704
- mipLevelCount?: GPUIntegerCoordinate;
2705
- /**
2706
- * The index of the first array layer accessible to the texture view.
2707
- */
2708
- baseArrayLayer?: GPUIntegerCoordinate;
2709
- /**
2710
- * How many array layers, starting with {@link GPUTextureViewDescriptor#baseArrayLayer}, are accessible
2711
- * to the texture view.
2712
- */
2713
- arrayLayerCount?: GPUIntegerCoordinate;
2714
- /**
2715
- * The format of the texture view. Must be either the {@link GPUTextureDescriptor#format} of the
2716
- * texture or one of the {@link GPUTextureDescriptor#viewFormats} specified during its creation.
2717
- */
2718
- format?: GPUTextureFormat;
2719
- };
2720
- type DefaultViewSchema<T extends Partial<TextureProps>> = TextureSchemaForDescriptor<{
2721
- dimension: Default<T['dimension'], '2d'>;
2722
- sampleType: T['format'] extends keyof TextureFormats ? TextureFormats[T['format']]['channelType'] : TextureFormats[keyof TextureFormats]['channelType'];
2723
- multisampled: Default<T['sampleCount'], 1> extends 1 ? false : true;
2724
- }>;
2725
- type BaseDimension<T extends string> = T extends keyof ViewDimensionToDimension ? ViewDimensionToDimension[T] : never;
2726
- type OptionalDimension<T extends string> = T extends '2d' | '2d-array' | 'cube' | 'cube-array' ? {
2727
- dimension?: BaseDimension<T>;
2728
- } : {
2729
- dimension: BaseDimension<T>;
2730
- };
2731
- type MultisampledProps<T extends WgslTexture> = T['multisampled'] extends true ? OptionalDimension<T['dimension']> & {
2732
- sampleCount: 4;
2733
- } : OptionalDimension<T['dimension']> & {
2734
- sampleCount?: 1;
2735
- };
2736
- type PropsForSchema<T extends WgslTexture | WgslStorageTexture> = T extends WgslTexture ? {
2737
- size: readonly number[];
2738
- format: GPUTextureFormat;
2739
- } & MultisampledProps<T> : T extends WgslStorageTexture ? {
2740
- size: readonly number[];
2741
- format: T['format'];
2742
- } & OptionalDimension<T['dimension']> : never;
2743
- type CopyCompatibleTexture<T extends TextureProps> = TgpuTexture<{
2744
- size: T['size'];
2745
- format: T['format'];
2746
- sampleCount?: T['sampleCount'];
2747
- }>;
2748
- interface TgpuTexture<TProps extends TextureProps = any> extends TgpuNamable {
2749
- readonly [$internal]: TextureInternals;
2750
- readonly resourceType: 'texture';
2751
- readonly props: TProps;
2752
- readonly destroyed: boolean;
2753
- readonly usableAsStorage: boolean;
2754
- readonly usableAsSampled: boolean;
2755
- readonly usableAsRender: boolean;
2756
- $usage<T extends AllowedUsages<TProps>[]>(...usages: T): this & UnionToIntersection<LiteralToExtensionMap[T[number]]>;
2757
- createView(...args: this['usableAsSampled'] extends true ? [] : [ValidateTextureViewSchema<this, WgslTexture>]): TgpuTextureView<DefaultViewSchema<TProps>>;
2758
- createView(schema: 'render', viewDescriptor?: TgpuTextureViewDescriptor): TgpuTextureRenderView;
2759
- createView<T extends WgslTexture>(schema: ValidateTextureViewSchema<this, T>, viewDescriptor?: TgpuTextureViewDescriptor & {
2760
- sampleType?: T['sampleType'] extends F32 ? 'float' | 'unfilterable-float' : never;
2761
- }): TgpuTextureView<T>;
2762
- createView<T extends WgslStorageTexture>(schema: ValidateTextureViewSchema<this, T>, viewDescriptor?: TgpuTextureViewDescriptor): TgpuTextureView<T>;
2763
- clear(mipLevel?: number | 'all'): void;
2764
- generateMipmaps(baseMipLevel?: number, mipLevels?: number): void;
2765
- write(source: ExternalImageSource | ExternalImageSource[]): void;
2766
- write(source: ArrayBuffer | TypedArray | DataView, mipLevel?: number): void;
2767
- copyFrom<T extends CopyCompatibleTexture<TProps>>(source: T): void;
2768
- destroy(): void;
2769
- }
2770
- interface TgpuTextureView<TSchema extends WgslStorageTexture | WgslTexture = WgslStorageTexture | WgslTexture> {
2771
- readonly [$internal]: TextureViewInternals;
2772
- readonly resourceType: 'texture-view';
2773
- readonly schema: TSchema;
2774
- readonly [$gpuValueOf]: Infer<TSchema>;
2775
- value: Infer<TSchema>;
2776
- $: Infer<TSchema>;
2777
- }
2778
- interface TgpuTextureRenderView {
2779
- readonly [$internal]: TextureViewInternals;
2780
- readonly resourceType: 'texture-view';
2781
- readonly descriptor: TgpuTextureViewDescriptor;
2782
- }
2783
- declare function isTexture<T extends TgpuTexture>(value: unknown | T): value is T;
2784
-
2785
- /**
2786
- * Extracts the inferred representation of a resource.
2787
- * For inferring types as seen by the GPU, see {@link InferGPU}
2788
- *
2789
- * @example
2790
- * type A = Infer<F32> // => number
2791
- * type B = Infer<WgslArray<F32>> // => number[]
2792
- * type C = Infer<Atomic<U32>> // => number
2793
- */
2794
- type Infer<T> = T extends {
2795
- readonly [$repr]: infer TRepr;
2796
- } ? TRepr : T;
2797
- /**
2798
- * Extracts a sparse/partial inferred representation of a resource.
2799
- * Used by the `buffer.writePartial` API.
2800
- *
2801
- * @example
2802
- * type A = InferPartial<F32> // => number | undefined
2803
- * type B = InferPartial<WgslStruct<{ a: F32 }>> // => { a?: number | undefined }
2804
- * type C = InferPartial<WgslArray<F32>> // => { idx: number; value: number | undefined }[] | undefined
2805
- */
2806
- type InferPartial<T> = T extends {
2807
- readonly [$reprPartial]: infer TRepr;
2808
- } ? TRepr : T extends {
2809
- readonly [$repr]: infer TRepr;
2810
- } ? TRepr | undefined : T;
2811
- /**
2812
- * Extracts the inferred representation of a resource (as seen by the GPU).
2813
- *
2814
- * @example
2815
- * type A = InferGPU<F32> // => number
2816
- * type B = InferGPU<WgslArray<F32>> // => number[]
2817
- * type C = InferGPU<Atomic<U32>> // => atomicU32
2818
- */
2819
- type InferGPU<T> = T extends {
2820
- readonly [$gpuRepr]: infer TRepr;
2821
- } ? TRepr : Infer<T>;
2822
- type InferRecord<T extends Record<string | number | symbol, unknown>> = {
2823
- [Key in keyof T]: Infer<T[Key]>;
2824
- };
2825
- type InferPartialRecord<T extends Record<string | number | symbol, unknown>> = {
2826
- [Key in keyof T]?: InferPartial<T[Key]>;
2827
- };
2828
- type InferGPURecord<T extends Record<string | number | symbol, unknown>> = {
2829
- [Key in keyof T]: InferGPU<T[Key]>;
2830
- };
2831
- type GPUValueOf<T> = T extends {
2832
- readonly [$gpuValueOf]: infer TValue;
2833
- } ? TValue : T;
2834
- type MemIdentity<T> = T extends {
2835
- readonly [$memIdent]: infer TMemIdent;
2836
- } ? TMemIdent : T;
2837
- type MemIdentityRecord<T extends Record<string | number | symbol, unknown>> = {
2838
- [Key in keyof T]: MemIdentity<T[Key]>;
2839
- };
2840
- type IsValidStorageSchema<T> = (T extends {
2841
- readonly [$validStorageSchema]: true;
2842
- } ? true : false) extends false ? false : true;
2843
- type IsValidUniformSchema<T> = (T extends {
2844
- readonly [$validUniformSchema]: true;
2845
- } ? true : false) extends false ? false : true;
2846
- type IsValidVertexSchema<T> = (T extends {
2847
- readonly [$validVertexSchema]: true;
2848
- } ? true : false) extends false ? false : true;
2849
- /**
2850
- * Accepts only arrays (or disarrays) of u32 or u16.
2851
- */
2852
- type IsValidIndexSchema<T> = Undecorate<T> extends WgslArray | Disarray ? (Undecorate<Undecorate<T>['elementType']>) extends U32 | U16 ? true : false : false;
2853
- /**
2854
- * Checks if a schema can be used in a buffer at all
2855
- */
2856
- type IsValidBufferSchema<T> = (IsValidStorageSchema<T> | IsValidUniformSchema<T> | IsValidVertexSchema<T> | IsValidIndexSchema<T>) extends false ? false : true;
2857
- /**
2858
- * Validates if a texture can be used as sampled texture
2859
- */
2860
- type IsValidSampledTextureUsage<TTexture extends TgpuTexture> = TTexture['usableAsSampled'] extends true ? true : {
2861
- readonly invalidSampled: "Texture not usable as sampled, call $usage('sampled') first";
2862
- };
2863
- /**
2864
- * Validates if a texture can be used as storage texture
2865
- */
2866
- type IsValidStorageTextureUsage<TTexture extends TgpuTexture> = TTexture['usableAsStorage'] extends true ? true : {
2867
- readonly invalidStorage: "Texture not usable as storage, call $usage('storage') first";
2868
- };
2869
- /**
2870
- * Validates if a texture view dimension is compatible with the texture dimension
2871
- */
2872
- type IsValidSubdimension<TTexture extends TgpuTexture, TSchema extends WgslTexture | WgslStorageTexture> = ViewDimensionToDimension[TSchema['dimension']] extends infer TVDim ? TVDim extends Default<TTexture['props']['dimension'], '2d'> ? true : {
2873
- readonly invalidViewDim: `Texture dimension '${Default<TTexture['props']['dimension'], '2d'>}' incompatible with view dimension '${TSchema['dimension']}'`;
2874
- } : never;
2875
- type IsValidStorageFormat<TTexture extends TgpuTexture, TSchema extends WgslStorageTexture> = TSchema['format'] extends TTexture['props']['format'] ? true : TTexture['props']['viewFormats'] extends readonly unknown[] ? TSchema['format'] extends TTexture['props']['viewFormats'][number] ? true : FormatError<TSchema, TTexture> : FormatError<TSchema, TTexture>;
2876
- type FormatError<TSchema extends WgslStorageTexture, TTexture extends TgpuTexture> = {
2877
- readonly invalidFormat: `Storage texture format '${TSchema['format']}' incompatible with texture format '${TTexture['props']['format']}'`;
2878
- };
2879
- type IsExactly<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
2880
- type SelfOrErrors<TSelf, T> = IsExactly<T, true> extends true ? TSelf : `(Error) ${T[Extract<keyof T, `invalid${string}`>] & string}`;
2881
- type ValidStorageUsage<TTexture extends TgpuTexture, TSchema extends WgslStorageTexture> = IsValidStorageTextureUsage<TTexture> & IsValidSubdimension<TTexture, TSchema> & IsValidStorageFormat<TTexture, TSchema>;
2882
- type ValidSampledUsage<TTexture extends TgpuTexture, TSchema extends WgslTexture> = IsValidSampledTextureUsage<TTexture> & IsValidSubdimension<TTexture, TSchema>;
2883
- /**
2884
- * Validates texture view schema against texture usage
2885
- */
2886
- type ValidateTextureViewSchema<TTexture extends TgpuTexture, TSchema extends WgslTexture | WgslStorageTexture> = TSchema extends WgslStorageTexture ? SelfOrErrors<TSchema, ValidStorageUsage<TTexture, TSchema>> : TSchema extends WgslTexture ? SelfOrErrors<TSchema, ValidSampledUsage<TTexture, TSchema>> : never;
2887
- type ExtractInvalidSchemaError<T, TPrefix extends string = ''> = [
2888
- T
2889
- ] extends [{
2890
- readonly [$invalidSchemaReason]: string;
2891
- }] ? `${TPrefix}${T[typeof $invalidSchemaReason]}` : never;
2892
-
2893
- type RefFn = <T>(value: T) => ref<T>;
2894
- /**
2895
- * A reference to a value `T`. Can be passed to other functions to give them
2896
- * mutable access to the underlying value.
2897
- *
2898
- * Conceptually, it represents a WGSL pointer.
2899
- */
2900
- interface ref<T> {
2901
- readonly [$internal]: unknown;
2902
- readonly type: 'ref';
2903
- /**
2904
- * Derefences the reference, and gives access to the underlying value.
2905
- *
2906
- * @example ```ts
2907
- * const boid = Boid({ pos: d.vec3f(3, 2, 1) });
2908
- * const posRef = d.ref(boid.pos);
2909
- *
2910
- * // Actually updates `boid.pos`
2911
- * posRef.$ = d.vec3f(1, 2, 3);
2912
- * console.log(boid.pos); // Output: vec3f(1, 2, 3)
2913
- * ```
2914
- */
2915
- $: T;
2916
- }
2917
- declare const ref: DualFn<RefFn>;
2918
-
2919
- type DecoratedLocation<T extends BaseData> = Decorated<T, Location[]>;
2920
- interface BaseData {
2921
- readonly [$internal]: true | Record<string, any>;
2922
- readonly type: string;
2923
- readonly [$repr]: unknown;
2924
- }
2925
- interface NumberArrayView {
2926
- readonly length: number;
2927
- [n: number]: number;
2928
- [Symbol.iterator]: () => Iterator<number>;
2929
- }
2930
- /**
2931
- * Vector infix notation.
2932
- *
2933
- * @privateRemarks
2934
- * These functions are not defined on vectors,
2935
- * but are instead assigned to `VecBase` after both `data` and `std` are initialized.
2936
- */
2937
- interface vecInfixNotation<T extends AnyNumericVecInstance> {
2938
- add(other: number): T;
2939
- add(other: T): T;
2940
- sub(other: number): T;
2941
- sub(other: T): T;
2942
- mul(other: number): T;
2943
- mul(other: T): T;
2944
- mul(other: mBaseForVec<T>): T;
2945
- div(other: number): T;
2946
- div(other: T): T;
2947
- }
2948
- /**
2949
- * Matrix infix notation.
2950
- *
2951
- * @privateRemarks
2952
- * These functions are not defined on matrices,
2953
- * but are instead assigned to `MatBase` after both `data` and `std` are initialized.
2954
- */
2955
- interface matInfixNotation<T extends AnyMatInstance> {
2956
- add(other: T): T;
2957
- sub(other: T): T;
2958
- mul(other: number): T;
2959
- mul(other: vBaseForMat<T>): vBaseForMat<T>;
2960
- mul(other: T): T;
2961
- }
2962
- /**
2963
- * Represents a 64-bit integer.
2964
- */
2965
- interface AbstractInt extends BaseData {
2966
- readonly type: 'abstractInt';
2967
- readonly [$repr]: number;
2968
- readonly [$invalidSchemaReason]: 'Abstract numerics are not host-shareable';
2969
- }
2970
- /**
2971
- * Represents a 64-bit IEEE 754 floating point number.
2972
- */
2973
- interface AbstractFloat extends BaseData {
2974
- readonly type: 'abstractFloat';
2975
- readonly [$repr]: number;
2976
- readonly [$invalidSchemaReason]: 'Abstract numerics are not host-shareable';
2977
- }
2978
- interface Void extends BaseData {
2979
- readonly type: 'void';
2980
- readonly [$repr]: void;
2981
- readonly [$invalidSchemaReason]: 'Void is not host-shareable';
2982
- }
2983
- declare const Void: Void;
2984
- interface Swizzle2<T2, T3, T4> {
2985
- readonly xx: T2;
2986
- readonly xy: T2;
2987
- readonly yx: T2;
2988
- readonly yy: T2;
2989
- readonly xxx: T3;
2990
- readonly xxy: T3;
2991
- readonly xyx: T3;
2992
- readonly xyy: T3;
2993
- readonly yxx: T3;
2994
- readonly yxy: T3;
2995
- readonly yyx: T3;
2996
- readonly yyy: T3;
2997
- readonly xxxx: T4;
2998
- readonly xxxy: T4;
2999
- readonly xxyx: T4;
3000
- readonly xxyy: T4;
3001
- readonly xyxx: T4;
3002
- readonly xyxy: T4;
3003
- readonly xyyx: T4;
3004
- readonly xyyy: T4;
3005
- readonly yxxx: T4;
3006
- readonly yxxy: T4;
3007
- readonly yxyx: T4;
3008
- readonly yxyy: T4;
3009
- readonly yyxx: T4;
3010
- readonly yyxy: T4;
3011
- readonly yyyx: T4;
3012
- readonly yyyy: T4;
3013
- }
3014
- interface Swizzle3<T2, T3, T4> extends Swizzle2<T2, T3, T4> {
3015
- readonly xz: T2;
3016
- readonly yz: T2;
3017
- readonly zx: T2;
3018
- readonly zy: T2;
3019
- readonly zz: T2;
3020
- readonly xxz: T3;
3021
- readonly xyz: T3;
3022
- readonly xzx: T3;
3023
- readonly xzy: T3;
3024
- readonly xzz: T3;
3025
- readonly yxz: T3;
3026
- readonly yyz: T3;
3027
- readonly yzx: T3;
3028
- readonly yzy: T3;
3029
- readonly yzz: T3;
3030
- readonly zxx: T3;
3031
- readonly zxy: T3;
3032
- readonly zxz: T3;
3033
- readonly zyx: T3;
3034
- readonly zyy: T3;
3035
- readonly zyz: T3;
3036
- readonly zzx: T3;
3037
- readonly zzy: T3;
3038
- readonly zzz: T3;
3039
- readonly xxxz: T4;
3040
- readonly xxyz: T4;
3041
- readonly xxzx: T4;
3042
- readonly xxzy: T4;
3043
- readonly xxzz: T4;
3044
- readonly xyxz: T4;
3045
- readonly xyyz: T4;
3046
- readonly xyzx: T4;
3047
- readonly xyzy: T4;
3048
- readonly xyzz: T4;
3049
- readonly xzxx: T4;
3050
- readonly xzxy: T4;
3051
- readonly xzxz: T4;
3052
- readonly xzyx: T4;
3053
- readonly xzyy: T4;
3054
- readonly xzyz: T4;
3055
- readonly xzzx: T4;
3056
- readonly xzzy: T4;
3057
- readonly xzzz: T4;
3058
- readonly yxxz: T4;
3059
- readonly yxyz: T4;
3060
- readonly yxzx: T4;
3061
- readonly yxzy: T4;
3062
- readonly yxzz: T4;
3063
- readonly yyxz: T4;
3064
- readonly yyyz: T4;
3065
- readonly yyzx: T4;
3066
- readonly yyzy: T4;
3067
- readonly yyzz: T4;
3068
- readonly yzxx: T4;
3069
- readonly yzxy: T4;
3070
- readonly yzxz: T4;
3071
- readonly yzyx: T4;
3072
- readonly yzyy: T4;
3073
- readonly yzyz: T4;
3074
- readonly yzzx: T4;
3075
- readonly yzzy: T4;
3076
- readonly yzzz: T4;
3077
- readonly zxxx: T4;
3078
- readonly zxxy: T4;
3079
- readonly zxxz: T4;
3080
- readonly zxyx: T4;
3081
- readonly zxyy: T4;
3082
- readonly zxyz: T4;
3083
- readonly zxzx: T4;
3084
- readonly zxzy: T4;
3085
- readonly zxzz: T4;
3086
- readonly zyxx: T4;
3087
- readonly zyxy: T4;
3088
- readonly zyxz: T4;
3089
- readonly zyyx: T4;
3090
- readonly zyyy: T4;
3091
- readonly zyyz: T4;
3092
- readonly zyzx: T4;
3093
- readonly zyzy: T4;
3094
- readonly zyzz: T4;
3095
- readonly zzxx: T4;
3096
- readonly zzxy: T4;
3097
- readonly zzxz: T4;
3098
- readonly zzyx: T4;
3099
- readonly zzyy: T4;
3100
- readonly zzyz: T4;
3101
- readonly zzzx: T4;
3102
- readonly zzzy: T4;
3103
- readonly zzzz: T4;
3104
- }
3105
- interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3, T4> {
3106
- readonly yw: T2;
3107
- readonly zw: T2;
3108
- readonly wx: T2;
3109
- readonly wy: T2;
3110
- readonly wz: T2;
3111
- readonly ww: T2;
3112
- readonly xxw: T3;
3113
- readonly xyw: T3;
3114
- readonly xzw: T3;
3115
- readonly xwx: T3;
3116
- readonly xwy: T3;
3117
- readonly xwz: T3;
3118
- readonly xww: T3;
3119
- readonly yxw: T3;
3120
- readonly yyw: T3;
3121
- readonly yzw: T3;
3122
- readonly ywx: T3;
3123
- readonly ywy: T3;
3124
- readonly ywz: T3;
3125
- readonly yww: T3;
3126
- readonly zxw: T3;
3127
- readonly zyw: T3;
3128
- readonly zzw: T3;
3129
- readonly zwx: T3;
3130
- readonly zwy: T3;
3131
- readonly zwz: T3;
3132
- readonly zww: T3;
3133
- readonly wxx: T3;
3134
- readonly wxz: T3;
3135
- readonly wxy: T3;
3136
- readonly wyy: T3;
3137
- readonly wyz: T3;
3138
- readonly wzz: T3;
3139
- readonly wwx: T3;
3140
- readonly wwy: T3;
3141
- readonly wwz: T3;
3142
- readonly www: T3;
3143
- readonly xxxw: T4;
3144
- readonly xxyw: T4;
3145
- readonly xxzw: T4;
3146
- readonly xxwx: T4;
3147
- readonly xxwy: T4;
3148
- readonly xxwz: T4;
3149
- readonly xxww: T4;
3150
- readonly xyxw: T4;
3151
- readonly xyyw: T4;
3152
- readonly xyzw: T4;
3153
- readonly xywx: T4;
3154
- readonly xywy: T4;
3155
- readonly xywz: T4;
3156
- readonly xyww: T4;
3157
- readonly xzxw: T4;
3158
- readonly xzyw: T4;
3159
- readonly xzzw: T4;
3160
- readonly xzwx: T4;
3161
- readonly xzwy: T4;
3162
- readonly xzwz: T4;
3163
- readonly xzww: T4;
3164
- readonly xwxx: T4;
3165
- readonly xwxy: T4;
3166
- readonly xwxz: T4;
3167
- readonly xwyy: T4;
3168
- readonly xwyz: T4;
3169
- readonly xwzz: T4;
3170
- readonly xwwx: T4;
3171
- readonly xwwy: T4;
3172
- readonly xwwz: T4;
3173
- readonly xwww: T4;
3174
- readonly yxxw: T4;
3175
- readonly yxyw: T4;
3176
- readonly yxzw: T4;
3177
- readonly yxwx: T4;
3178
- readonly yxwy: T4;
3179
- readonly yxwz: T4;
3180
- readonly yxww: T4;
3181
- readonly yyxw: T4;
3182
- readonly yyyw: T4;
3183
- readonly yyzw: T4;
3184
- readonly yywx: T4;
3185
- readonly yywy: T4;
3186
- readonly yywz: T4;
3187
- readonly yyww: T4;
3188
- readonly yzxw: T4;
3189
- readonly yzyw: T4;
3190
- readonly yzzw: T4;
3191
- readonly yzwx: T4;
3192
- readonly yzwy: T4;
3193
- readonly yzwz: T4;
3194
- readonly yzww: T4;
3195
- readonly ywxx: T4;
3196
- readonly ywxy: T4;
3197
- readonly ywxz: T4;
3198
- readonly ywxw: T4;
3199
- readonly ywyy: T4;
3200
- readonly ywyz: T4;
3201
- readonly ywzz: T4;
3202
- readonly ywwx: T4;
3203
- readonly ywwy: T4;
3204
- readonly ywwz: T4;
3205
- readonly ywww: T4;
3206
- readonly zxxw: T4;
3207
- readonly zxyw: T4;
3208
- readonly zxzw: T4;
3209
- readonly zxwx: T4;
3210
- readonly zxwy: T4;
3211
- readonly zxwz: T4;
3212
- readonly zxww: T4;
3213
- readonly zyxw: T4;
3214
- readonly zyyw: T4;
3215
- readonly zyzw: T4;
3216
- readonly zywx: T4;
3217
- readonly zywy: T4;
3218
- readonly zywz: T4;
3219
- readonly zyww: T4;
3220
- readonly zzxw: T4;
3221
- readonly zzyw: T4;
3222
- readonly zzzw: T4;
3223
- readonly zzwx: T4;
3224
- readonly zzwy: T4;
3225
- readonly zzwz: T4;
3226
- readonly zzww: T4;
3227
- readonly zwxx: T4;
3228
- readonly zwxy: T4;
3229
- readonly zwxz: T4;
3230
- readonly zwxw: T4;
3231
- readonly zwyy: T4;
3232
- readonly zwyz: T4;
3233
- readonly zwzz: T4;
3234
- readonly zwwx: T4;
3235
- readonly zwwy: T4;
3236
- readonly zwwz: T4;
3237
- readonly zwww: T4;
3238
- readonly wxxx: T4;
3239
- readonly wxxy: T4;
3240
- readonly wxxz: T4;
3241
- readonly wxxw: T4;
3242
- readonly wxyx: T4;
3243
- readonly wxyy: T4;
3244
- readonly wxyz: T4;
3245
- readonly wxyw: T4;
3246
- readonly wxzx: T4;
3247
- readonly wxzy: T4;
3248
- readonly wxzz: T4;
3249
- readonly wxzw: T4;
3250
- readonly wxwx: T4;
3251
- readonly wxwy: T4;
3252
- readonly wxwz: T4;
3253
- readonly wxww: T4;
3254
- readonly wyxx: T4;
3255
- readonly wyxy: T4;
3256
- readonly wyxz: T4;
3257
- readonly wyxw: T4;
3258
- readonly wyyy: T4;
3259
- readonly wyyz: T4;
3260
- readonly wyzw: T4;
3261
- readonly wywx: T4;
3262
- readonly wywy: T4;
3263
- readonly wywz: T4;
3264
- readonly wyww: T4;
3265
- readonly wzxx: T4;
3266
- readonly wzxy: T4;
3267
- readonly wzxz: T4;
3268
- readonly wzxw: T4;
3269
- readonly wzyy: T4;
3270
- readonly wzyz: T4;
3271
- readonly wzzy: T4;
3272
- readonly wzzw: T4;
3273
- readonly wzwx: T4;
3274
- readonly wzwy: T4;
3275
- readonly wzwz: T4;
3276
- readonly wzww: T4;
3277
- readonly wwxx: T4;
3278
- readonly wwxy: T4;
3279
- readonly wwxz: T4;
3280
- readonly wwxw: T4;
3281
- readonly wwyy: T4;
3282
- readonly wwyz: T4;
3283
- readonly wwzz: T4;
3284
- readonly wwwx: T4;
3285
- readonly wwwy: T4;
3286
- readonly wwwz: T4;
3287
- readonly wwww: T4;
3288
- }
3289
- type Tuple2<S> = [S, S];
3290
- type Tuple3<S> = [S, S, S];
3291
- type Tuple4<S> = [S, S, S, S];
3292
- /**
3293
- * Interface representing its WGSL vector type counterpart: vec2f or vec2<f32>.
3294
- * A vector with 2 elements of type f32
3295
- */
3296
- interface v2f extends Tuple2<number>, Swizzle2<v2f, v3f, v4f>, vecInfixNotation<v2f> {
3297
- readonly [$internal]: true;
3298
- /** use to distinguish between vectors of the same size on the type level */
3299
- readonly kind: 'vec2f';
3300
- x: number;
3301
- y: number;
3302
- }
3303
- /**
3304
- * Interface representing its WGSL vector type counterpart: vec2h or vec2<f16>.
3305
- * A vector with 2 elements of type f16
3306
- */
3307
- interface v2h extends Tuple2<number>, Swizzle2<v2h, v3h, v4h>, vecInfixNotation<v2h> {
3308
- readonly [$internal]: true;
3309
- /** use to distinguish between vectors of the same size on the type level */
3310
- readonly kind: 'vec2h';
3311
- x: number;
3312
- y: number;
3313
- }
3314
- /**
3315
- * Interface representing its WGSL vector type counterpart: vec2i or vec2<i32>.
3316
- * A vector with 2 elements of type i32
3317
- */
3318
- interface v2i extends Tuple2<number>, Swizzle2<v2i, v3i, v4i>, vecInfixNotation<v2i> {
3319
- readonly [$internal]: true;
3320
- /** use to distinguish between vectors of the same size on the type level */
3321
- readonly kind: 'vec2i';
3322
- x: number;
3323
- y: number;
3324
- }
3325
- /**
3326
- * Interface representing its WGSL vector type counterpart: vec2u or vec2<u32>.
3327
- * A vector with 2 elements of type u32
3328
- */
3329
- interface v2u extends Tuple2<number>, Swizzle2<v2u, v3u, v4u>, vecInfixNotation<v2u> {
3330
- readonly [$internal]: true;
3331
- /** use to distinguish between vectors of the same size on the type level */
3332
- readonly kind: 'vec2u';
3333
- x: number;
3334
- y: number;
3335
- }
3336
- /**
3337
- * Interface representing its WGSL vector type counterpart: `vec2<bool>`.
3338
- * A vector with 2 elements of type `bool`
3339
- */
3340
- interface v2b extends Tuple2<boolean>, Swizzle2<v2b, v3b, v4b> {
3341
- readonly [$internal]: true;
3342
- /** use to distinguish between vectors of the same size on the type level */
3343
- readonly kind: 'vec2<bool>';
3344
- x: boolean;
3345
- y: boolean;
3346
- }
3347
- /**
3348
- * Interface representing its WGSL vector type counterpart: vec3f or vec3<f32>.
3349
- * A vector with 3 elements of type f32
3350
- */
3351
- interface v3f extends Tuple3<number>, Swizzle3<v2f, v3f, v4f>, vecInfixNotation<v3f> {
3352
- readonly [$internal]: true;
3353
- /** use to distinguish between vectors of the same size on the type level */
3354
- readonly kind: 'vec3f';
3355
- x: number;
3356
- y: number;
3357
- z: number;
3358
- }
3359
- /**
3360
- * Interface representing its WGSL vector type counterpart: vec3h or vec3<f16>.
3361
- * A vector with 3 elements of type f16
3362
- */
3363
- interface v3h extends Tuple3<number>, Swizzle3<v2h, v3h, v4h>, vecInfixNotation<v3h> {
3364
- readonly [$internal]: true;
3365
- /** use to distinguish between vectors of the same size on the type level */
3366
- readonly kind: 'vec3h';
3367
- x: number;
3368
- y: number;
3369
- z: number;
3370
- }
3371
- /**
3372
- * Interface representing its WGSL vector type counterpart: vec3i or vec3<i32>.
3373
- * A vector with 3 elements of type i32
3374
- */
3375
- interface v3i extends Tuple3<number>, Swizzle3<v2i, v3i, v4i>, vecInfixNotation<v3i> {
3376
- readonly [$internal]: true;
3377
- /** use to distinguish between vectors of the same size on the type level */
3378
- readonly kind: 'vec3i';
3379
- x: number;
3380
- y: number;
3381
- z: number;
3382
- }
3383
- /**
3384
- * Interface representing its WGSL vector type counterpart: vec3u or vec3<u32>.
3385
- * A vector with 3 elements of type u32
3386
- */
3387
- interface v3u extends Tuple3<number>, Swizzle3<v2u, v3u, v4u>, vecInfixNotation<v3u> {
3388
- readonly [$internal]: true;
3389
- /** use to distinguish between vectors of the same size on the type level */
3390
- readonly kind: 'vec3u';
3391
- x: number;
3392
- y: number;
3393
- z: number;
3394
- }
3395
- /**
3396
- * Interface representing its WGSL vector type counterpart: `vec3<bool>`.
3397
- * A vector with 3 elements of type `bool`
3398
- */
3399
- interface v3b extends Tuple3<boolean>, Swizzle3<v2b, v3b, v4b> {
3400
- readonly [$internal]: true;
3401
- /** use to distinguish between vectors of the same size on the type level */
3402
- readonly kind: 'vec3<bool>';
3403
- x: boolean;
3404
- y: boolean;
3405
- z: boolean;
3406
- }
3407
- /**
3408
- * Interface representing its WGSL vector type counterpart: vec4f or vec4<f32>.
3409
- * A vector with 4 elements of type f32
3410
- */
3411
- interface v4f extends Tuple4<number>, Swizzle4<v2f, v3f, v4f>, vecInfixNotation<v4f> {
3412
- readonly [$internal]: true;
3413
- /** use to distinguish between vectors of the same size on the type level */
3414
- readonly kind: 'vec4f';
3415
- x: number;
3416
- y: number;
3417
- z: number;
3418
- w: number;
3419
- }
3420
- /**
3421
- * Interface representing its WGSL vector type counterpart: vec4h or vec4<f16>.
3422
- * A vector with 4 elements of type f16
3423
- */
3424
- interface v4h extends Tuple4<number>, Swizzle4<v2h, v3h, v4h>, vecInfixNotation<v4h> {
3425
- readonly [$internal]: true;
3426
- /** use to distinguish between vectors of the same size on the type level */
3427
- readonly kind: 'vec4h';
3428
- x: number;
3429
- y: number;
3430
- z: number;
3431
- w: number;
3432
- }
3433
- /**
3434
- * Interface representing its WGSL vector type counterpart: vec4i or vec4<i32>.
3435
- * A vector with 4 elements of type i32
3436
- */
3437
- interface v4i extends Tuple4<number>, Swizzle4<v2i, v3i, v4i>, vecInfixNotation<v4i> {
3438
- readonly [$internal]: true;
3439
- /** use to distinguish between vectors of the same size on the type level */
3440
- readonly kind: 'vec4i';
3441
- x: number;
3442
- y: number;
3443
- z: number;
3444
- w: number;
3445
- }
3446
- /**
3447
- * Interface representing its WGSL vector type counterpart: vec4u or vec4<u32>.
3448
- * A vector with 4 elements of type u32
3449
- */
3450
- interface v4u extends Tuple4<number>, Swizzle4<v2u, v3u, v4u>, vecInfixNotation<v4u> {
3451
- readonly [$internal]: true;
3452
- /** use to distinguish between vectors of the same size on the type level */
3453
- readonly kind: 'vec4u';
3454
- x: number;
3455
- y: number;
3456
- z: number;
3457
- w: number;
3458
- }
3459
- /**
3460
- * Interface representing its WGSL vector type counterpart: `vec4<bool>`.
3461
- * A vector with 4 elements of type `bool`
3462
- */
3463
- interface v4b extends Tuple4<boolean>, Swizzle4<v2b, v3b, v4b> {
3464
- readonly [$internal]: true;
3465
- /** use to distinguish between vectors of the same size on the type level */
3466
- readonly kind: 'vec4<bool>';
3467
- x: boolean;
3468
- y: boolean;
3469
- z: boolean;
3470
- w: boolean;
3471
- }
3472
- type AnyFloat32VecInstance = v2f | v3f | v4f;
3473
- type AnyFloatVecInstance = v2f | v2h | v3f | v3h | v4f | v4h;
3474
- type AnyIntegerVecInstance = v2i | v2u | v3i | v3u | v4i | v4u;
3475
- type AnyBooleanVecInstance = v2b | v3b | v4b;
3476
- type AnySignedVecInstance = v2i | v2f | v2h | v3i | v3f | v3h | v4i | v4f | v4h;
3477
- type AnyNumericVec2Instance = v2f | v2h | v2i | v2u;
3478
- type AnyNumericVec3Instance = v3f | v3h | v3i | v3u;
3479
- type AnyNumericVec4Instance = v4f | v4h | v4i | v4u;
3480
- type AnyNumericVecInstance = AnyNumericVec2Instance | AnyNumericVec3Instance | AnyNumericVec4Instance;
3481
- type AnyVec2Instance = v2f | v2h | v2i | v2u | v2b;
3482
- type AnyVec3Instance = v3f | v3h | v3i | v3u | v3b;
3483
- type AnyVec4Instance = v4f | v4h | v4i | v4u | v4b;
3484
- type AnyVecInstance = AnyVec2Instance | AnyVec3Instance | AnyVec4Instance;
3485
- /**
3486
- * Interface representing its WGSL matrix type counterpart: mat2x2
3487
- * A matrix with 2 rows and 2 columns, with elements of type `TColumn`
3488
- */
3489
- interface mat2x2<TColumn> extends NumberArrayView {
3490
- readonly [$internal]: true;
3491
- readonly length: 4;
3492
- readonly kind: string;
3493
- readonly columns: readonly [TColumn, TColumn];
3494
- [n: number]: number;
3495
- }
3496
- /**
3497
- * Interface representing its WGSL matrix type counterpart: mat2x2f or mat2x2<f32>
3498
- * A matrix with 2 rows and 2 columns, with elements of type d.f32
3499
- */
3500
- interface m2x2f extends mat2x2<v2f>, matInfixNotation<m2x2f> {
3501
- readonly kind: 'mat2x2f';
3502
- }
3503
- /**
3504
- * Interface representing its WGSL matrix type counterpart: mat3x3
3505
- * A matrix with 3 rows and 3 columns, with elements of type `TColumn`
3506
- */
3507
- interface mat3x3<TColumn> extends NumberArrayView {
3508
- readonly [$internal]: true;
3509
- readonly length: 12;
3510
- readonly kind: string;
3511
- readonly columns: readonly [TColumn, TColumn, TColumn];
3512
- [n: number]: number;
3513
- }
3514
- /**
3515
- * Interface representing its WGSL matrix type counterpart: mat3x3f or mat3x3<f32>
3516
- * A matrix with 3 rows and 3 columns, with elements of type d.f32
3517
- */
3518
- interface m3x3f extends mat3x3<v3f>, matInfixNotation<m3x3f> {
3519
- readonly kind: 'mat3x3f';
3520
- }
3521
- /**
3522
- * Interface representing its WGSL matrix type counterpart: mat4x4
3523
- * A matrix with 4 rows and 4 columns, with elements of type `TColumn`
3524
- */
3525
- interface mat4x4<TColumn> extends NumberArrayView {
3526
- readonly [$internal]: true;
3527
- readonly length: 16;
3528
- readonly kind: string;
3529
- readonly columns: readonly [
3530
- TColumn,
3531
- TColumn,
3532
- TColumn,
3533
- TColumn
3534
- ];
3535
- [n: number]: number;
3536
- }
3537
- /**
3538
- * Interface representing its WGSL matrix type counterpart: mat4x4f or mat4x4<f32>
3539
- * A matrix with 4 rows and 4 columns, with elements of type d.f32
3540
- */
3541
- interface m4x4f extends mat4x4<v4f>, matInfixNotation<m4x4f> {
3542
- readonly kind: 'mat4x4f';
3543
- }
3544
- type AnyMatInstance = m2x2f | m3x3f | m4x4f;
3545
- type vBaseForMat<T extends AnyMatInstance> = T extends m2x2f ? v2f : T extends m3x3f ? v3f : v4f;
3546
- type mBaseForVec<T extends AnyVecInstance> = T extends v2f ? m2x2f : T extends v3f ? m3x3f : T extends v4f ? m4x4f : never;
3547
- /**
3548
- * Boolean schema representing a single WGSL bool value.
3549
- * Cannot be used inside buffers as it is not host-shareable.
3550
- */
3551
- interface Bool extends DualFn<(v?: number | boolean) => boolean> {
3552
- readonly type: 'bool';
3553
- readonly [$repr]: boolean;
3554
- readonly [$invalidSchemaReason]: 'Bool is not host-shareable, use U32 or I32 instead';
3555
- }
3556
- /**
3557
- * 32-bit float schema representing a single WGSL f32 value.
3558
- */
3559
- interface F32 extends DualFn<(v?: number | boolean) => number> {
3560
- readonly type: 'f32';
3561
- readonly [$repr]: number;
3562
- readonly [$validStorageSchema]: true;
3563
- readonly [$validUniformSchema]: true;
3564
- readonly [$validVertexSchema]: true;
3565
- }
3566
- /**
3567
- * 16-bit float schema representing a single WGSL f16 value.
3568
- */
3569
- interface F16 extends DualFn<(v?: number | boolean) => number> {
3570
- readonly type: 'f16';
3571
- readonly [$repr]: number;
3572
- readonly [$validStorageSchema]: true;
3573
- readonly [$validUniformSchema]: true;
3574
- readonly [$validVertexSchema]: true;
3575
- }
3576
- /**
3577
- * Signed 32-bit integer schema representing a single WGSL i32 value.
3578
- */
3579
- interface I32 extends DualFn<(v?: number | boolean) => number> {
3580
- readonly type: 'i32';
3581
- readonly [$repr]: number;
3582
- readonly [$memIdent]: I32 | Atomic<I32> | DecoratedLocation<I32>;
3583
- readonly [$validStorageSchema]: true;
3584
- readonly [$validUniformSchema]: true;
3585
- readonly [$validVertexSchema]: true;
3586
- }
3587
- /**
3588
- * Unsigned 32-bit integer schema representing a single WGSL u32 value.
3589
- */
3590
- interface U32 extends DualFn<(v?: number | boolean) => number> {
3591
- readonly type: 'u32';
3592
- readonly [$repr]: number;
3593
- readonly [$memIdent]: U32 | Atomic<U32> | DecoratedLocation<U32>;
3594
- readonly [$validStorageSchema]: true;
3595
- readonly [$validUniformSchema]: true;
3596
- readonly [$validVertexSchema]: true;
3597
- }
3598
- /**
3599
- * Unsigned 16-bit integer schema used exclusively for index buffer schemas.
3600
- */
3601
- interface U16 extends BaseData {
3602
- readonly type: 'u16';
3603
- readonly [$repr]: number;
3604
- readonly [$invalidSchemaReason]: 'U16 is only usable inside arrays for index buffers, use U32 or I32 instead';
3605
- }
3606
- /**
3607
- * Type of the `d.vec2f` object/function: vector data type schema/constructor
3608
- */
3609
- interface Vec2f extends DualFn<((x: number, y: number) => v2f) & ((xy: number) => v2f) & (() => v2f) & ((v: AnyNumericVec2Instance) => v2f)> {
3610
- readonly type: 'vec2f';
3611
- readonly primitive: F32;
3612
- readonly [$repr]: v2f;
3613
- readonly [$validStorageSchema]: true;
3614
- readonly [$validUniformSchema]: true;
3615
- readonly [$validVertexSchema]: true;
3616
- }
3617
- /**
3618
- * Type of the `d.vec2h` object/function: vector data type schema/constructor
3619
- */
3620
- interface Vec2h extends DualFn<((x: number, y: number) => v2h) & ((xy: number) => v2h) & (() => v2h) & ((v: AnyNumericVec2Instance) => v2h)> {
3621
- readonly type: 'vec2h';
3622
- readonly primitive: F16;
3623
- readonly [$repr]: v2h;
3624
- readonly [$validStorageSchema]: true;
3625
- readonly [$validUniformSchema]: true;
3626
- readonly [$validVertexSchema]: true;
3627
- }
3628
- /**
3629
- * Type of the `d.vec2i` object/function: vector data type schema/constructor
3630
- */
3631
- interface Vec2i extends DualFn<((x: number, y: number) => v2i) & ((xy: number) => v2i) & (() => v2i) & ((v: AnyNumericVec2Instance) => v2i)> {
3632
- readonly type: 'vec2i';
3633
- readonly primitive: I32;
3634
- readonly [$repr]: v2i;
3635
- readonly [$validStorageSchema]: true;
3636
- readonly [$validUniformSchema]: true;
3637
- readonly [$validVertexSchema]: true;
3638
- }
3639
- /**
3640
- * Type of the `d.vec2u` object/function: vector data type schema/constructor
3641
- */
3642
- interface Vec2u extends DualFn<((x: number, y: number) => v2u) & ((xy: number) => v2u) & (() => v2u) & ((v: AnyNumericVec2Instance) => v2u)> {
3643
- readonly type: 'vec2u';
3644
- readonly primitive: U32;
3645
- readonly [$repr]: v2u;
3646
- readonly [$validStorageSchema]: true;
3647
- readonly [$validUniformSchema]: true;
3648
- readonly [$validVertexSchema]: true;
3649
- }
3650
- /**
3651
- * Type of the `d.vec2b` object/function: vector data type schema/constructor
3652
- * Cannot be used inside buffers as it is not host-shareable.
3653
- */
3654
- interface Vec2b extends DualFn<((x: boolean, y: boolean) => v2b) & ((xy: boolean) => v2b) & (() => v2b) & ((v: v2b) => v2b)> {
3655
- readonly type: 'vec2<bool>';
3656
- readonly primitive: Bool;
3657
- readonly [$repr]: v2b;
3658
- readonly [$invalidSchemaReason]: 'Boolean vectors is not host-shareable, use numeric vectors instead';
3659
- }
3660
- /**
3661
- * Type of the `d.vec3f` object/function: vector data type schema/constructor
3662
- */
3663
- interface Vec3f extends DualFn<((x: number, y: number, z: number) => v3f) & ((xyz: number) => v3f) & (() => v3f) & ((v: AnyNumericVec3Instance) => v3f) & ((v0: AnyNumericVec2Instance, z: number) => v3f) & ((x: number, v0: AnyNumericVec2Instance) => v3f)> {
3664
- readonly type: 'vec3f';
3665
- readonly primitive: F32;
3666
- readonly [$repr]: v3f;
3667
- readonly [$validStorageSchema]: true;
3668
- readonly [$validUniformSchema]: true;
3669
- readonly [$validVertexSchema]: true;
3670
- }
3671
- /**
3672
- * Type of the `d.vec3h` object/function: vector data type schema/constructor
3673
- */
3674
- interface Vec3h extends DualFn<((x: number, y: number, z: number) => v3h) & ((xyz: number) => v3h) & (() => v3h) & ((v: AnyNumericVec3Instance) => v3h) & ((v0: AnyNumericVec2Instance, z: number) => v3h) & ((x: number, v0: AnyNumericVec2Instance) => v3h)> {
3675
- readonly type: 'vec3h';
3676
- readonly primitive: F16;
3677
- readonly [$repr]: v3h;
3678
- readonly [$validStorageSchema]: true;
3679
- readonly [$validUniformSchema]: true;
3680
- readonly [$validVertexSchema]: true;
3681
- }
3682
- /**
3683
- * Type of the `d.vec3i` object/function: vector data type schema/constructor
3684
- */
3685
- interface Vec3i extends DualFn<((x: number, y: number, z: number) => v3i) & ((xyz: number) => v3i) & (() => v3i) & ((v: AnyNumericVec3Instance) => v3i) & ((v0: AnyNumericVec2Instance, z: number) => v3i) & ((x: number, v0: AnyNumericVec2Instance) => v3i)> {
3686
- readonly type: 'vec3i';
3687
- readonly primitive: I32;
3688
- readonly [$repr]: v3i;
3689
- readonly [$validStorageSchema]: true;
3690
- readonly [$validUniformSchema]: true;
3691
- readonly [$validVertexSchema]: true;
3692
- }
3693
- /**
3694
- * Type of the `d.vec3u` object/function: vector data type schema/constructor
3695
- */
3696
- interface Vec3u extends DualFn<((x: number, y: number, z: number) => v3u) & ((xyz: number) => v3u) & (() => v3u) & ((v: AnyNumericVec3Instance) => v3u) & ((v0: AnyNumericVec2Instance, z: number) => v3u) & ((x: number, v0: AnyNumericVec2Instance) => v3u)> {
3697
- readonly type: 'vec3u';
3698
- readonly primitive: U32;
3699
- readonly [$repr]: v3u;
3700
- readonly [$validStorageSchema]: true;
3701
- readonly [$validUniformSchema]: true;
3702
- readonly [$validVertexSchema]: true;
3703
- }
3704
- /**
3705
- * Type of the `d.vec3b` object/function: vector data type schema/constructor
3706
- * Cannot be used inside buffers as it is not host-shareable.
3707
- */
3708
- interface Vec3b extends DualFn<((x: boolean, y: boolean, z: boolean) => v3b) & ((xyz: boolean) => v3b) & (() => v3b) & ((v: v3b) => v3b) & ((v0: v2b, z: boolean) => v3b) & ((x: boolean, v0: v2b) => v3b)> {
3709
- readonly type: 'vec3<bool>';
3710
- readonly primitive: Bool;
3711
- readonly [$repr]: v3b;
3712
- readonly [$invalidSchemaReason]: 'Boolean vectors is not host-shareable, use numeric vectors instead';
3713
- }
3714
- /**
3715
- * Type of the `d.vec4f` object/function: vector data type schema/constructor
3716
- */
3717
- interface Vec4f extends DualFn<((x: number, y: number, z: number, w: number) => v4f) & ((xyzw: number) => v4f) & (() => v4f) & ((v: AnyNumericVec4Instance) => v4f) & ((v0: AnyNumericVec3Instance, w: number) => v4f) & ((x: number, v0: AnyNumericVec3Instance) => v4f) & ((v0: AnyNumericVec2Instance, v1: AnyNumericVec2Instance) => v4f) & ((v0: AnyNumericVec2Instance, z: number, w: number) => v4f) & ((x: number, v0: AnyNumericVec2Instance, z: number) => v4f) & ((x: number, y: number, v0: AnyNumericVec2Instance) => v4f)> {
3718
- readonly type: 'vec4f';
3719
- readonly primitive: F32;
3720
- readonly [$repr]: v4f;
3721
- readonly [$validStorageSchema]: true;
3722
- readonly [$validUniformSchema]: true;
3723
- readonly [$validVertexSchema]: true;
3724
- }
3725
- /**
3726
- * Type of the `d.vec4h` object/function: vector data type schema/constructor
3727
- */
3728
- interface Vec4h extends DualFn<((x: number, y: number, z: number, w: number) => v4h) & ((xyzw: number) => v4h) & (() => v4h) & ((v: AnyNumericVec4Instance) => v4h) & ((v0: AnyNumericVec3Instance, w: number) => v4h) & ((x: number, v0: AnyNumericVec3Instance) => v4h) & ((v0: AnyNumericVec2Instance, v1: AnyNumericVec2Instance) => v4h) & ((v0: AnyNumericVec2Instance, z: number, w: number) => v4h) & ((x: number, v0: AnyNumericVec2Instance, z: number) => v4h) & ((x: number, y: number, v0: AnyNumericVec2Instance) => v4h)> {
3729
- readonly type: 'vec4h';
3730
- readonly primitive: F16;
3731
- readonly [$repr]: v4h;
3732
- readonly [$validStorageSchema]: true;
3733
- readonly [$validUniformSchema]: true;
3734
- readonly [$validVertexSchema]: true;
3735
- }
3736
- /**
3737
- * Type of the `d.vec4i` object/function: vector data type schema/constructor
3738
- */
3739
- interface Vec4i extends DualFn<((x: number, y: number, z: number, w: number) => v4i) & ((xyzw: number) => v4i) & (() => v4i) & ((v: AnyNumericVec4Instance) => v4i) & ((v0: AnyNumericVec3Instance, w: number) => v4i) & ((x: number, v0: AnyNumericVec3Instance) => v4i) & ((v0: AnyNumericVec2Instance, v1: AnyNumericVec2Instance) => v4i) & ((v0: AnyNumericVec2Instance, z: number, w: number) => v4i) & ((x: number, v0: AnyNumericVec2Instance, z: number) => v4i) & ((x: number, y: number, v0: AnyNumericVec2Instance) => v4i)> {
3740
- readonly type: 'vec4i';
3741
- readonly primitive: I32;
3742
- readonly [$repr]: v4i;
3743
- readonly [$validStorageSchema]: true;
3744
- readonly [$validUniformSchema]: true;
3745
- readonly [$validVertexSchema]: true;
3746
- }
3747
- /**
3748
- * Type of the `d.vec4u` object/function: vector data type schema/constructor
3749
- */
3750
- interface Vec4u extends DualFn<((x: number, y: number, z: number, w: number) => v4u) & ((xyzw: number) => v4u) & (() => v4u) & ((v: AnyNumericVec4Instance) => v4u) & ((v0: AnyNumericVec3Instance, w: number) => v4u) & ((x: number, v0: AnyNumericVec3Instance) => v4u) & ((v0: AnyNumericVec2Instance, v1: AnyNumericVec2Instance) => v4u) & ((v0: AnyNumericVec2Instance, z: number, w: number) => v4u) & ((x: number, v0: AnyNumericVec2Instance, z: number) => v4u) & ((x: number, y: number, v0: AnyNumericVec2Instance) => v4u)> {
3751
- readonly type: 'vec4u';
3752
- readonly primitive: U32;
3753
- readonly [$repr]: v4u;
3754
- readonly [$validStorageSchema]: true;
3755
- readonly [$validUniformSchema]: true;
3756
- readonly [$validVertexSchema]: true;
3757
- }
3758
- /**
3759
- * Type of the `d.vec4b` object/function: vector data type schema/constructor
3760
- * Cannot be used inside buffers as it is not host-shareable.
3761
- */
3762
- interface Vec4b extends DualFn<((x: boolean, y: boolean, z: boolean, w: boolean) => v4b) & ((xyzw: boolean) => v4b) & (() => v4b) & ((v: v4b) => v4b) & ((v0: v3b, w: boolean) => v4b) & ((x: boolean, v0: v3b) => v4b) & ((v0: v2b, v1: v2b) => v4b) & ((v0: v2b, z: boolean, w: boolean) => v4b) & ((x: boolean, v0: v2b, z: boolean) => v4b) & ((x: boolean, y: boolean, v0: v2b) => v4b)> {
3763
- readonly type: 'vec4<bool>';
3764
- readonly primitive: Bool;
3765
- readonly [$repr]: v4b;
3766
- readonly [$invalidSchemaReason]: 'Boolean vectors is not host-shareable, use numeric vectors instead';
3767
- }
3768
- /**
3769
- * Type of the `d.mat2x2f` object/function: matrix data type schema/constructor
3770
- */
3771
- interface Mat2x2f extends BaseData {
3772
- readonly type: 'mat2x2f';
3773
- readonly [$repr]: m2x2f;
3774
- readonly [$validStorageSchema]: true;
3775
- readonly [$validUniformSchema]: true;
3776
- (...elements: [number, number, number, number]): m2x2f;
3777
- (...columns: [v2f, v2f]): m2x2f;
3778
- (): m2x2f;
3779
- identity(): m2x2f;
3780
- }
3781
- /**
3782
- * Type of the `d.mat3x3f` object/function: matrix data type schema/constructor
3783
- */
3784
- interface Mat3x3f extends BaseData {
3785
- readonly type: 'mat3x3f';
3786
- readonly [$repr]: m3x3f;
3787
- readonly [$validStorageSchema]: true;
3788
- readonly [$validUniformSchema]: true;
3789
- (...elements: [number, number, number, number, number, number, number, number, number]): m3x3f;
3790
- (...columns: [v3f, v3f, v3f]): m3x3f;
3791
- (): m3x3f;
3792
- identity(): m3x3f;
3793
- }
3794
- /**
3795
- * Type of the `d.mat4x4f` object/function: matrix data type schema/constructor
3796
- */
3797
- interface Mat4x4f extends BaseData {
3798
- readonly type: 'mat4x4f';
3799
- readonly [$repr]: m4x4f;
3800
- readonly [$validStorageSchema]: true;
3801
- readonly [$validUniformSchema]: true;
3802
- (...elements: [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]): m4x4f;
3803
- (...columns: [v4f, v4f, v4f, v4f]): m4x4f;
3804
- (): m4x4f;
3805
- identity(): m4x4f;
3806
- translation(vec: v3f): m4x4f;
3807
- scaling(vec: v3f): m4x4f;
3808
- rotationX(angle: number): m4x4f;
3809
- rotationY(angle: number): m4x4f;
3810
- rotationZ(angle: number): m4x4f;
3811
- }
3812
- /**
3813
- * Array schema constructed via `d.arrayOf` function.
3814
- *
3815
- * Responsible for handling reading and writing array values
3816
- * between binary and JS representation. Takes into account
3817
- * the `byteAlignment` requirement of its elementType.
3818
- */
3819
- interface WgslArray<TElement extends BaseData = BaseData> extends BaseData {
3820
- <T extends TElement>(elements: Infer<T>[]): Infer<T>[];
3821
- (): Infer<TElement>[];
3822
- readonly type: 'array';
3823
- readonly elementCount: number;
3824
- readonly elementType: TElement;
3825
- readonly [$repr]: Infer<TElement>[];
3826
- readonly [$gpuRepr]: InferGPU<TElement>[];
3827
- readonly [$reprPartial]: {
3828
- idx: number;
3829
- value: InferPartial<TElement>;
3830
- }[] | undefined;
3831
- readonly [$memIdent]: WgslArray<MemIdentity<TElement>>;
3832
- readonly [$validStorageSchema]: IsValidStorageSchema<TElement>;
3833
- readonly [$validUniformSchema]: IsValidUniformSchema<TElement>;
3834
- readonly [$validVertexSchema]: IsValidVertexSchema<TElement>;
3835
- readonly [$invalidSchemaReason]: `in array element — ${ExtractInvalidSchemaError<TElement>}`;
3836
- }
3837
- /**
3838
- * Struct schema constructed via `d.struct` function.
3839
- *
3840
- * Responsible for handling reading and writing struct values
3841
- * between binary and JS representation. Takes into account
3842
- * the `byteAlignment` requirement of its members.
3843
- */
3844
- interface WgslStruct<TProps extends Record<string, BaseData> = any> extends BaseData, TgpuNamable {
3845
- readonly [$internal]: {
3846
- isAbstruct: boolean;
3847
- };
3848
- readonly type: 'struct';
3849
- readonly propTypes: TProps;
3850
- (props: Prettify<InferRecord<TProps>>): Prettify<InferRecord<TProps>>;
3851
- (): Prettify<InferRecord<TProps>>;
3852
- readonly [$repr]: Prettify<InferRecord<TProps>>;
3853
- readonly [$gpuRepr]: Prettify<InferGPURecord<TProps>>;
3854
- readonly [$memIdent]: WgslStruct<Prettify<MemIdentityRecord<TProps>>>;
3855
- readonly [$reprPartial]: Prettify<Partial<InferPartialRecord<TProps>>> | undefined;
3856
- readonly [$invalidSchemaReason]: SwapNever<{
3857
- [K in keyof TProps]: ExtractInvalidSchemaError<TProps[K], `in struct property '${K & string}' — `>;
3858
- }[keyof TProps], undefined>;
3859
- readonly [$validStorageSchema]: {
3860
- [K in keyof TProps]: IsValidStorageSchema<TProps[K]>;
3861
- }[keyof TProps] extends true ? true : false;
3862
- readonly [$validUniformSchema]: {
3863
- [K in keyof TProps]: IsValidUniformSchema<TProps[K]>;
3864
- }[keyof TProps] extends true ? true : false;
3865
- readonly [$validVertexSchema]: {
3866
- [K in keyof TProps]: IsValidVertexSchema<TProps[K]>;
3867
- }[keyof TProps] extends true ? true : false;
3868
- }
3869
- /** @deprecated Just use `WgslStruct` without any type parameters */
3870
- type AnyWgslStruct = WgslStruct;
3871
- type AddressSpace = 'uniform' | 'storage' | 'workgroup' | 'private' | 'function' | 'handle';
3872
- type Access = 'read' | 'write' | 'read-write';
3873
- interface Ptr<TAddr extends AddressSpace = AddressSpace, TInner extends StorableData = StorableData, TAccess extends Access = Access> extends BaseData {
3874
- readonly type: 'ptr';
3875
- readonly inner: TInner;
3876
- readonly addressSpace: TAddr;
3877
- readonly access: TAccess;
3878
- readonly implicit: boolean;
3879
- readonly [$repr]: ref<Infer<TInner>>;
3880
- readonly [$invalidSchemaReason]: 'Pointers are not host-shareable';
3881
- }
3882
- /**
3883
- * Schema representing the `atomic<...>` WGSL data type.
3884
- */
3885
- interface Atomic<TInner extends U32 | I32 = U32 | I32> extends BaseData {
3886
- readonly type: 'atomic';
3887
- readonly inner: TInner;
3888
- readonly [$repr]: Infer<TInner>;
3889
- readonly [$gpuRepr]: TInner extends U32 ? atomicU32 : atomicI32;
3890
- readonly [$memIdent]: MemIdentity<TInner>;
3891
- readonly [$validStorageSchema]: true;
3892
- readonly [$validUniformSchema]: true;
3893
- readonly [$validVertexSchema]: true;
3894
- }
3895
- interface atomicU32 {
3896
- readonly [$internal]: true;
3897
- readonly type: 'atomicU32';
3898
- }
3899
- interface atomicI32 {
3900
- readonly [$internal]: true;
3901
- readonly type: 'atomicI32';
3902
- }
3903
- interface Align<T extends number> {
3904
- readonly [$internal]: true;
3905
- readonly type: '@align';
3906
- readonly params: [T];
3907
- }
3908
- interface Size<T extends number> {
3909
- readonly [$internal]: true;
3910
- readonly type: '@size';
3911
- readonly params: [T];
3912
- }
3913
- interface Location<T extends number = number> {
3914
- readonly [$internal]: true;
3915
- readonly type: '@location';
3916
- readonly params: [T];
3917
- }
3918
- type PerspectiveOrLinearInterpolationType = `${'perspective' | 'linear'}${'' | ', center' | ', centroid' | ', sample'}`;
3919
- type FlatInterpolationType = `flat${'' | ', first' | ', either'}`;
3920
- type InterpolationType = PerspectiveOrLinearInterpolationType | FlatInterpolationType;
3921
- interface Interpolate<T extends InterpolationType = InterpolationType> {
3922
- readonly [$internal]: true;
3923
- readonly type: '@interpolate';
3924
- readonly params: [T];
3925
- }
3926
- interface Builtin<T extends string> {
3927
- readonly [$internal]: true;
3928
- readonly type: '@builtin';
3929
- readonly params: [T];
3930
- }
3931
- interface Invariant {
3932
- readonly [$internal]: true;
3933
- readonly type: '@invariant';
3934
- readonly params: [];
3935
- }
3936
- interface Decorated<TInner extends BaseData = BaseData, TAttribs extends unknown[] = unknown[]> extends BaseData {
3937
- readonly type: 'decorated';
3938
- readonly inner: TInner;
3939
- readonly attribs: TAttribs;
3940
- readonly [$repr]: Infer<TInner>;
3941
- readonly [$gpuRepr]: InferGPU<TInner>;
3942
- readonly [$reprPartial]: InferPartial<TInner>;
3943
- readonly [$memIdent]: TAttribs extends Location[] ? MemIdentity<TInner> | Decorated<MemIdentity<TInner>, TAttribs> : Decorated<MemIdentity<TInner>, TAttribs>;
3944
- readonly [$validStorageSchema]: IsValidStorageSchema<TInner>;
3945
- readonly [$validUniformSchema]: IsValidUniformSchema<TInner>;
3946
- readonly [$validVertexSchema]: IsValidVertexSchema<TInner>;
3947
- readonly [$invalidSchemaReason]: ExtractInvalidSchemaError<TInner>;
3948
- }
3949
- declare const wgslTypeLiterals: readonly ["bool", "f32", "f16", "i32", "u32", "u16", "vec2f", "vec2h", "vec2i", "vec2u", "vec2<bool>", "vec3f", "vec3h", "vec3i", "vec3u", "vec3<bool>", "vec4f", "vec4h", "vec4i", "vec4u", "vec4<bool>", "mat2x2f", "mat3x3f", "mat4x4f", "struct", "array", "ptr", "atomic", "decorated", "abstractInt", "abstractFloat", "void", "texture_1d", "texture_storage_1d", "texture_2d", "texture_storage_2d", "texture_multisampled_2d", "texture_depth_2d", "texture_depth_multisampled_2d", "texture_2d_array", "texture_storage_2d_array", "texture_depth_2d_array", "texture_cube", "texture_depth_cube", "texture_cube_array", "texture_depth_cube_array", "texture_3d", "texture_storage_3d", "texture_external", "sampler", "sampler_comparison"];
3950
- type WgslTypeLiteral = (typeof wgslTypeLiterals)[number];
3951
- type PerspectiveOrLinearInterpolatableBaseType = F32 | F16 | Vec2f | Vec2h | Vec3f | Vec3h | Vec4f | Vec4h;
3952
- type PerspectiveOrLinearInterpolatableData = PerspectiveOrLinearInterpolatableBaseType | Decorated<PerspectiveOrLinearInterpolatableBaseType>;
3953
- type FlatInterpolatableAdditionalBaseType = I32 | U32 | Vec2i | Vec2u | Vec3i | Vec3u | Vec4i | Vec4u;
3954
- type FlatInterpolatableData = PerspectiveOrLinearInterpolatableData | FlatInterpolatableAdditionalBaseType | Decorated<FlatInterpolatableAdditionalBaseType>;
3955
- type TextureSampleTypes = F32 | I32 | U32;
3956
- type ScalarData = Bool | F32 | F16 | I32 | U32 | AbstractInt | AbstractFloat;
3957
- type VecData = Vec2f | Vec2h | Vec2i | Vec2u | Vec2b | Vec3f | Vec3h | Vec3i | Vec3u | Vec3b | Vec4f | Vec4h | Vec4i | Vec4u | Vec4b;
3958
- type MatData = Mat2x2f | Mat3x3f | Mat4x4f;
3959
- type StorableData = ScalarData | VecData | MatData | Atomic<I32> | Atomic<U32> | WgslArray | WgslStruct;
3960
- type AnyWgslData = Bool | F32 | F16 | I32 | U32 | U16 | Vec2f | Vec2h | Vec2i | Vec2u | Vec2b | Vec3f | Vec3h | Vec3i | Vec3u | Vec3b | Vec4f | Vec4h | Vec4i | Vec4u | Vec4b | Mat2x2f | Mat3x3f | Mat4x4f | WgslStruct | WgslArray | Ptr | Atomic<U32> | Atomic<I32> | Decorated | AbstractInt | AbstractFloat | Void | WgslTexture | WgslStorageTexture | WgslExternalTexture | WgslSampler | WgslComparisonSampler;
3961
- declare function isWgslData(value: unknown): value is AnyWgslData;
3962
- /**
3963
- * Checks whether passed in value is an array schema,
3964
- * as opposed to, e.g., a disarray schema.
3965
- *
3966
- * Array schemas can be used to describe uniform and storage buffers,
3967
- * whereas disarray schemas cannot.
3968
- *
3969
- * @example
3970
- * isWgslArray(d.arrayOf(d.u32, 4)) // true
3971
- * isWgslArray(d.disarray(d.u32, 4)) // false
3972
- * isWgslArray(d.vec3f) // false
3973
- */
3974
- declare function isWgslArray<T extends WgslArray>(schema: T | unknown): schema is T;
3975
- /**
3976
- * Checks whether passed in value is a struct schema,
3977
- * as opposed to, e.g., an unstruct schema.
3978
- *
3979
- * Struct schemas can be used to describe uniform and storage buffers,
3980
- * whereas unstruct schemas cannot.
3981
- *
3982
- * @example
3983
- * isWgslStruct(d.struct({ a: d.u32 })) // true
3984
- * isWgslStruct(d.unstruct({ a: d.u32 })) // false
3985
- * isWgslStruct(d.vec3f) // false
3986
- */
3987
- declare function isWgslStruct<T extends WgslStruct>(schema: T | unknown): schema is T;
3988
- /**
3989
- * Checks whether passed in value is a pointer schema.
3990
- *
3991
- * @example
3992
- * isPtr(d.ptrFn(d.f32)) // true
3993
- * isPtr(d.ptrPrivate(d.f32)) // true
3994
- * isPtr(d.f32) // false
3995
- */
3996
- declare function isPtr<T extends Ptr>(schema: T | unknown): schema is T;
3997
- /**
3998
- * Checks whether the passed in value is an atomic schema.
3999
- *
4000
- * @example
4001
- * isAtomic(d.atomic(d.u32)) // true
4002
- * isAtomic(d.u32) // false
4003
- */
4004
- declare function isAtomic<T extends Atomic<U32 | I32>>(schema: T | unknown): schema is T;
4005
- declare function isAlignAttrib<T extends Align<number>>(value: unknown | T): value is T;
4006
- declare function isSizeAttrib<T extends Size<number>>(value: unknown | T): value is T;
4007
- declare function isLocationAttrib<T extends Location<number>>(value: unknown | T): value is T;
4008
- declare function isInterpolateAttrib<T extends Interpolate<InterpolationType>>(value: unknown | T): value is T;
4009
- declare function isBuiltinAttrib<T extends Builtin<string>>(value: unknown | T): value is T;
4010
- declare function isDecorated<T extends Decorated>(value: unknown | T): value is T;
4011
-
4012
- type DeepReadonly<T> = T extends {
4013
- [$internal]: unknown;
4014
- } ? T : T extends unknown[] ? ReadonlyArray<DeepReadonly<T[number]>> : T extends Record<string, unknown> ? {
4015
- readonly [K in keyof T]: DeepReadonly<T[K]>;
4016
- } : T;
4017
- interface TgpuConst<TDataType extends AnyWgslData = AnyWgslData> extends TgpuNamable {
4018
- readonly [$gpuValueOf]: DeepReadonly<InferGPU<TDataType>>;
4019
- readonly value: DeepReadonly<InferGPU<TDataType>>;
4020
- readonly $: DeepReadonly<InferGPU<TDataType>>;
4021
- readonly [$internal]: {
4022
- /** Makes it differentiable on the type level. Does not exist at runtime. */
4023
- dataType?: TDataType;
4024
- };
4025
- }
4026
- /**
4027
- * Creates a module constant with specified value.
4028
- */
4029
- declare function constant<TDataType extends AnyWgslData>(dataType: TDataType, value: InferGPU<TDataType>): TgpuConst<TDataType>;
4030
-
4031
- export { $internal as $, type AnyData as A, computeFn as B, type Configurable as C, type Disarray as D, declare as E, isBuffer as F, isUsableAsVertex as G, isDerived as H, type InferGPU as I, isSlot as J, isComparisonSampler as K, type LogResources as L, isSampler as M, isTexture as N, type Origin as O, isUsableAsRender as P, isUsableAsSampled as Q, type ResolvedSnippet as R, ShelllessRepository as S, type TgpuSlot as T, isUsableAsStorage as U, isUsableAsUniform as V, type WgslExtension as W, isBufferShorthand as X, isTgpuFn as Y, isVariable as Z, type TgpuGuardedComputePipeline as _, type TgpuDerived as a, type StorableData as a$, type ValidateBufferSchema as a0, type ValidateStorageSchema as a1, type ValidateUniformSchema as a2, type WithBinding as a3, type WithCompute as a4, type WithFragment as a5, type WithVertex as a6, type Storage as a7, type StorageFlag as a8, type TgpuRenderPipeline as a9, type BindLayoutEntry as aA, type ExtractBindGroupInputFromLayout as aB, type LayoutEntryToInput as aC, type TgpuLayoutComparisonSampler as aD, type TgpuLayoutEntry as aE, type TgpuLayoutExternalTexture as aF, type TgpuLayoutSampler as aG, type TgpuLayoutStorage as aH, type TgpuLayoutTexture as aI, type TgpuLayoutUniform as aJ, type TgpuFnShell as aK, type TgpuVertexFn as aL, type TgpuVertexFnShell as aM, type TgpuFragmentFn as aN, type TgpuFragmentFnShell as aO, type TgpuComputeFn as aP, type TgpuComputeFnShell as aQ, type TgpuDeclare as aR, type INTERNAL_GlobalExt as aS, type Vec2f as aT, type Bool as aU, type F16 as aV, type F32 as aW, type I32 as aX, type U16 as aY, type U32 as aZ, type WgslStruct as a_, type TgpuComputePipeline as aa, type IndexFlag as ab, type Uniform as ac, type UniformFlag as ad, type ValidUsagesFor as ae, type Vertex as af, type VertexFlag as ag, type TgpuBufferMutable as ah, type TgpuBufferReadonly as ai, type TgpuBufferUniform as aj, type TgpuMutable as ak, type TgpuReadonly as al, type TgpuUniform as am, type Eventual as an, type TgpuTexture as ao, type TgpuTextureView as ap, type TextureProps as aq, type RenderFlag as ar, type SampledFlag as as, type TgpuConst as at, type VariableScope as au, type TgpuComparisonSampler as av, type TgpuFixedComparisonSampler as aw, type TgpuFixedSampler as ax, type TgpuSampler as ay, type TgpuQuerySet as az, type TgpuBindGroupLayout as b, textureCubeArray as b$, type Ptr as b0, type Vec2b as b1, type Vec2h as b2, type Vec2i as b3, type Vec2u as b4, type Vec3b as b5, type Vec3f as b6, type Vec3h as b7, type Vec3i as b8, type Vec3u as b9, type Location as bA, type m2x2f as bB, type m3x3f as bC, type m4x4f as bD, type Mat2x2f as bE, type Mat3x3f as bF, type Mat4x4f as bG, type Size as bH, type v2b as bI, type v2f as bJ, type v2i as bK, type v2u as bL, type v3b as bM, type v3f as bN, type v3i as bO, type v3u as bP, type v4b as bQ, type v4f as bR, type v4i as bS, type v4u as bT, type AnyLooseData as bU, type LooseDecorated as bV, texture1d as bW, texture2d as bX, texture2dArray as bY, texture3d as bZ, textureCube as b_, type Vec4b as ba, type Vec4f as bb, type Vec4h as bc, type Vec4i as bd, type Vec4u as be, type BaseData as bf, type Unstruct as bg, type Atomic as bh, isAlignAttrib as bi, isAtomic as bj, isBuiltinAttrib as bk, isDecorated as bl, isInterpolateAttrib as bm, isLocationAttrib as bn, isPtr as bo, isSizeAttrib as bp, isWgslArray as bq, isWgslData as br, isWgslStruct as bs, Void as bt, type Align as bu, type AnyVecInstance as bv, type AnyWgslStruct as bw, type Builtin as bx, type Decorated as by, type Interpolate as bz, type TgpuBindGroup as c, type BuiltinVertexIndex as c$, textureDepth2d as c0, textureDepth2dArray as c1, textureDepthCube as c2, textureDepthCubeArray as c3, textureDepthMultisampled2d as c4, textureExternal as c5, textureMultisampled2d as c6, textureStorage1d as c7, textureStorage2d as c8, textureStorage2dArray as c9, align as cA, type AnyAttribute as cB, type HasCustomLocation as cC, interpolate as cD, invariant as cE, type IsBuiltin as cF, isBuiltin as cG, location as cH, size as cI, isData as cJ, isDisarray as cK, isLooseData as cL, isLooseDecorated as cM, isUnstruct as cN, builtin as cO, type AnyBuiltin as cP, type BuiltinClipDistances as cQ, type BuiltinFragDepth as cR, type BuiltinFrontFacing as cS, type BuiltinGlobalInvocationId as cT, type BuiltinInstanceIndex as cU, type BuiltinLocalInvocationId as cV, type BuiltinLocalInvocationIndex as cW, type BuiltinNumWorkgroups as cX, type BuiltinPosition as cY, type BuiltinSampleIndex as cZ, type BuiltinSampleMask as c_, textureStorage3d as ca, type WgslExternalTexture as cb, type WgslStorageTexture as cc, type WgslStorageTexture1d as cd, type WgslStorageTexture2d as ce, type WgslStorageTexture2dArray as cf, type WgslStorageTexture3d as cg, type WgslStorageTextureProps as ch, type WgslTexture as ci, type WgslTexture1d as cj, type WgslTexture2d as ck, type WgslTexture2dArray as cl, type WgslTexture3d as cm, type WgslTextureCube as cn, type WgslTextureCubeArray as co, type WgslTextureDepth2d as cp, type WgslTextureDepth2dArray as cq, type WgslTextureDepthCube as cr, type WgslTextureDepthCubeArray as cs, type WgslTextureDepthMultisampled2d as ct, type WgslTextureMultisampled2d as cu, comparisonSampler as cv, sampler as cw, type WgslComparisonSampler as cx, type WgslSampler as cy, ref as cz, type ShaderGenerator as d, type mBaseForVec as d$, type BuiltinWorkgroupId as d0, type InferPartial as d1, type FormatToWGSLType as d2, type TgpuVertexFormatData as d3, formatToWGSLType as d4, packedFormats as d5, uint8 as d6, uint8x2 as d7, uint8x4 as d8, sint8 as d9, float32x3 as dA, float32x4 as dB, uint32 as dC, uint32x2 as dD, uint32x3 as dE, uint32x4 as dF, sint32 as dG, sint32x2 as dH, sint32x3 as dI, sint32x4 as dJ, unorm10_10_10_2 as dK, unorm8x4_bgra as dL, type PackedData as dM, isPackedData as dN, type DualFn as dO, type AnyNumericVecInstance as dP, type AnyFloatVecInstance as dQ, type AnyIntegerVecInstance as dR, type v3h as dS, type AnyMatInstance as dT, type AbstractFloat as dU, type AbstractInt as dV, type v2h as dW, type v4h as dX, type AnyFloat32VecInstance as dY, type AnySignedVecInstance as dZ, type vBaseForMat as d_, sint8x2 as da, sint8x4 as db, unorm8 as dc, unorm8x2 as dd, unorm8x4 as de, snorm8 as df, snorm8x2 as dg, snorm8x4 as dh, uint16 as di, uint16x2 as dj, uint16x4 as dk, sint16 as dl, sint16x2 as dm, sint16x4 as dn, unorm16 as dp, unorm16x2 as dq, unorm16x4 as dr, snorm16 as ds, snorm16x2 as dt, snorm16x4 as du, float16 as dv, float16x2 as dw, float16x4 as dx, float32 as dy, float32x2 as dz, type Wgsl as e, type AnyVec2Instance as e0, type AnyVec3Instance as e1, type AnyBooleanVecInstance as e2, type atomicI32 as e3, type atomicU32 as e4, type StorageTextureFormats as e5, type TextureFormats as e6, $repr as e7, type TgpuNamable as e8, $getNameForward as e9, type ResolvableObject as f, type TgpuBuffer as g, type TgpuVar as h, type LogGeneratorOptions as i, type TgpuRoot as j, type AnyWgslData as k, type TgpuFn as l, type TgpuBufferUsage as m, type TgpuBufferShorthand as n, type Infer as o, type TgpuAccessor as p, type TgpuVertexLayout as q, type WgslArray as r, fn as s, bindGroupLayout as t, privateVar as u, vertexLayout as v, workgroupVar as w, constant as x, fragmentFn as y, vertexFn as z };