typegpu 0.3.0-alpha.6 → 0.3.0-alpha.7

Sign up to get free protection for your applications and to get access to all the features.
package/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { T as TgpuNamable, I as Infer, D as Default, F as F32, U as U32, a as I32, V as Vec4f, b as Vec4u, c as Vec4i, d as UnionToIntersection, A as AnyData, E as Exotic, O as OmitProps, P as Prettify, M as Mutable, W as WgslTypeLiteral, B as BaseWgslData, e as AnyWgslData } from './utilityTypes-D53GCmPw.cjs';
1
+ import { U as Unwrapper, A as AnyData, I as Infer, E as Exotic, T as TgpuBuffer$1, a as TgpuLayoutEntry, b as TgpuBindGroupLayout, O as OmitProps, L as LayoutEntryToInput, c as TgpuBindGroup, d as TgpuResolvable, e as AnyWgslData, f as TgpuBufferMutable$1, g as TgpuBufferReadonly$1, h as TgpuBufferUniform$1, i as bindGroupLayout } from './wgslTypes-BsqIvRBG.cjs';
2
+ export { H as BindLayoutEntry, S as Storage, x as TgpuAnyTextureView, F as TgpuLayoutExternalTexture, z as TgpuLayoutSampler, C as TgpuLayoutStorage, D as TgpuLayoutStorageTexture, B as TgpuLayoutTexture, G as TgpuLayoutUniform, v as TgpuMutableTexture, t as TgpuReadonlyTexture, w as TgpuSampledTexture, y as TgpuSampler, s as TgpuTexture, u as TgpuWriteonlyTexture, r as Uniform, V as Vertex, j as isBuffer, n as isComparisonSampler, o as isSampledTextureView, m as isSampler, p as isStorageTextureView, q as isUsableAsStorage, k as isUsableAsUniform, l as isUsableAsVertex } from './wgslTypes-BsqIvRBG.cjs';
2
3
  import * as smol from 'tinyest';
3
- import { Block } from 'tinyest';
4
4
 
5
5
  /**
6
6
  * Information extracted from transpiling a JS function.
@@ -22,367 +22,6 @@ interface JitTranspiler {
22
22
  transpileFn(rawJs: string): TranspilationResult;
23
23
  }
24
24
 
25
- interface TgpuSlot<T> extends TgpuNamable {
26
- readonly resourceType: 'slot';
27
- readonly defaultValue: T | undefined;
28
- readonly label?: string | undefined;
29
- /**
30
- * Used to determine if code generated using either value `a` or `b` in place
31
- * of the slot will be equivalent. Defaults to `Object.is`.
32
- */
33
- areEqual(a: T, b: T): boolean;
34
- readonly value: Infer<T>;
35
- }
36
- interface TgpuDerived<T> {
37
- readonly resourceType: 'derived';
38
- readonly value: Infer<T>;
39
- with<TValue>(slot: TgpuSlot<TValue>, value: Eventual<TValue>): TgpuDerived<T>;
40
- /**
41
- * @internal
42
- */
43
- '~compute'(): T;
44
- }
45
- /**
46
- * Represents a value that is available at resolution time.
47
- */
48
- type Eventual<T> = T | TgpuSlot<T> | TgpuDerived<T>;
49
- type SlotValuePair<T> = [TgpuSlot<T>, T];
50
-
51
- interface NameRegistry {
52
- /**
53
- * Creates a valid WGSL identifier, each guaranteed to be unique
54
- * in the lifetime of a single resolution process.
55
- * @param primer Used in the generation process, makes the identifier more recognizable.
56
- */
57
- makeUnique(primer?: string): string;
58
- }
59
-
60
- interface NotAllowed<TMsg> {
61
- reason: TMsg;
62
- }
63
- type ExtensionGuard<TFlag, TMsg, TAllowed> = boolean extends TFlag ? NotAllowed<TMsg> | TAllowed : TAllowed;
64
- interface Storage {
65
- usableAsStorage: true;
66
- }
67
- declare const Storage: Storage;
68
- declare function isUsableAsStorage<T>(value: T): value is T & Storage;
69
-
70
- interface TgpuComputePipeline extends TgpuNamable {
71
- readonly resourceType: 'compute-pipeline';
72
- readonly label: string | undefined;
73
- with(bindGroupLayout: TgpuBindGroupLayout, bindGroup: TgpuBindGroup): TgpuComputePipeline;
74
- dispatchWorkgroups(x: number, y?: number | undefined, z?: number | undefined): void;
75
- }
76
-
77
- type TextureProps = {
78
- size: readonly number[];
79
- format: GPUTextureFormat;
80
- viewFormats?: GPUTextureFormat[] | undefined;
81
- dimension?: GPUTextureDimension | undefined;
82
- mipLevelCount?: number | undefined;
83
- sampleCount?: number | undefined;
84
- };
85
-
86
- declare const texelFormatToChannelType: {
87
- r8unorm: F32;
88
- r8snorm: F32;
89
- r8uint: U32;
90
- r8sint: I32;
91
- r16uint: U32;
92
- r16sint: I32;
93
- r16float: F32;
94
- rg8unorm: F32;
95
- rg8snorm: F32;
96
- rg8uint: U32;
97
- rg8sint: I32;
98
- r32uint: U32;
99
- r32sint: I32;
100
- r32float: F32;
101
- rg16uint: U32;
102
- rg16sint: I32;
103
- rg16float: F32;
104
- rgba8unorm: F32;
105
- 'rgba8unorm-srgb': F32;
106
- rgba8snorm: F32;
107
- rgba8uint: U32;
108
- rgba8sint: I32;
109
- bgra8unorm: F32;
110
- 'bgra8unorm-srgb': F32;
111
- rgb9e5ufloat: F32;
112
- rgb10a2uint: U32;
113
- rgb10a2unorm: F32;
114
- rg11b10ufloat: F32;
115
- rg32uint: U32;
116
- rg32sint: I32;
117
- rg32float: F32;
118
- rgba16uint: U32;
119
- rgba16sint: I32;
120
- rgba16float: F32;
121
- rgba32uint: U32;
122
- rgba32sint: I32;
123
- rgba32float: F32;
124
- stencil8: F32;
125
- depth16unorm: F32;
126
- depth24plus: F32;
127
- 'depth24plus-stencil8': F32;
128
- depth32float: F32;
129
- 'depth32float-stencil8': F32;
130
- 'bc1-rgba-unorm': F32;
131
- 'bc1-rgba-unorm-srgb': F32;
132
- 'bc2-rgba-unorm': F32;
133
- 'bc2-rgba-unorm-srgb': F32;
134
- 'bc3-rgba-unorm': F32;
135
- 'bc3-rgba-unorm-srgb': F32;
136
- 'bc4-r-unorm': F32;
137
- 'bc4-r-snorm': F32;
138
- 'bc5-rg-unorm': F32;
139
- 'bc5-rg-snorm': F32;
140
- 'bc6h-rgb-ufloat': F32;
141
- 'bc6h-rgb-float': F32;
142
- 'bc7-rgba-unorm': F32;
143
- 'bc7-rgba-unorm-srgb': F32;
144
- 'etc2-rgb8unorm': F32;
145
- 'etc2-rgb8unorm-srgb': F32;
146
- 'etc2-rgb8a1unorm': F32;
147
- 'etc2-rgb8a1unorm-srgb': F32;
148
- 'etc2-rgba8unorm': F32;
149
- 'etc2-rgba8unorm-srgb': F32;
150
- 'eac-r11unorm': F32;
151
- 'eac-r11snorm': F32;
152
- 'eac-rg11unorm': F32;
153
- 'eac-rg11snorm': F32;
154
- 'astc-4x4-unorm': F32;
155
- 'astc-4x4-unorm-srgb': F32;
156
- 'astc-5x4-unorm': F32;
157
- 'astc-5x4-unorm-srgb': F32;
158
- 'astc-5x5-unorm': F32;
159
- 'astc-5x5-unorm-srgb': F32;
160
- 'astc-6x5-unorm': F32;
161
- 'astc-6x5-unorm-srgb': F32;
162
- 'astc-6x6-unorm': F32;
163
- 'astc-6x6-unorm-srgb': F32;
164
- 'astc-8x5-unorm': F32;
165
- 'astc-8x5-unorm-srgb': F32;
166
- 'astc-8x6-unorm': F32;
167
- 'astc-8x6-unorm-srgb': F32;
168
- 'astc-8x8-unorm': F32;
169
- 'astc-8x8-unorm-srgb': F32;
170
- 'astc-10x5-unorm': F32;
171
- 'astc-10x5-unorm-srgb': F32;
172
- 'astc-10x6-unorm': F32;
173
- 'astc-10x6-unorm-srgb': F32;
174
- 'astc-10x8-unorm': F32;
175
- 'astc-10x8-unorm-srgb': F32;
176
- 'astc-10x10-unorm': F32;
177
- 'astc-10x10-unorm-srgb': F32;
178
- 'astc-12x10-unorm': F32;
179
- 'astc-12x10-unorm-srgb': F32;
180
- 'astc-12x12-unorm': F32;
181
- 'astc-12x12-unorm-srgb': F32;
182
- };
183
- type TexelFormatToChannelType = typeof texelFormatToChannelType;
184
- type TexelFormatToStringChannels = {
185
- [Key in keyof TexelFormatToChannelType]: TexelFormatToChannelType[Key]['type'];
186
- };
187
- type KeysWithValue<T extends Record<string, unknown>, TValue> = keyof {
188
- [Key in keyof T as T[Key] extends TValue ? Key : never]: Key;
189
- };
190
- type ChannelTypeToLegalFormats = {
191
- [Key in TexelFormatToChannelType[keyof TexelFormatToChannelType]['type']]: KeysWithValue<TexelFormatToStringChannels, Key>;
192
- };
193
- type SampleTypeToStringChannelType = {
194
- float: 'f32';
195
- 'unfilterable-float': 'f32';
196
- depth: 'f32';
197
- sint: 'i32';
198
- uint: 'u32';
199
- };
200
- type ViewDimensionToDimension = {
201
- '1d': '1d';
202
- '2d': '2d';
203
- '2d-array': '2d';
204
- '3d': '3d';
205
- cube: '2d';
206
- 'cube-array': '2d';
207
- };
208
- /**
209
- * https://www.w3.org/TR/WGSL/#storage-texel-formats
210
- */
211
- type StorageTextureTexelFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm';
212
- declare const texelFormatToDataType: {
213
- readonly rgba8unorm: Vec4f;
214
- readonly rgba8snorm: Vec4f;
215
- readonly rgba8uint: Vec4u;
216
- readonly rgba8sint: Vec4i;
217
- readonly rgba16uint: Vec4u;
218
- readonly rgba16sint: Vec4i;
219
- readonly rgba16float: Vec4f;
220
- readonly r32uint: Vec4u;
221
- readonly r32sint: Vec4i;
222
- readonly r32float: Vec4f;
223
- readonly rg32uint: Vec4u;
224
- readonly rg32sint: Vec4i;
225
- readonly rg32float: Vec4f;
226
- readonly rgba32uint: Vec4u;
227
- readonly rgba32sint: Vec4i;
228
- readonly rgba32float: Vec4f;
229
- readonly bgra8unorm: Vec4f;
230
- };
231
- declare const channelFormatToSchema: {
232
- float: F32;
233
- 'unfilterable-float': F32;
234
- uint: U32;
235
- sint: I32;
236
- depth: F32;
237
- };
238
- type ChannelFormatToSchema = typeof channelFormatToSchema;
239
- type TexelFormatToDataType = typeof texelFormatToDataType;
240
- type TexelFormatToDataTypeOrNever<T> = T extends keyof TexelFormatToDataType ? TexelFormatToDataType[T] : never;
241
- /**
242
- * Represents what formats a storage view can choose from based on its owner texture's props.
243
- */
244
- type StorageFormatOptions<TProps extends TextureProps> = Extract<TProps['format'] | Default<TProps['viewFormats'], []>[number], StorageTextureTexelFormat>;
245
- /**
246
- * Represents what formats a sampled view can choose from based on its owner texture's props.
247
- */
248
- type SampledFormatOptions<TProps extends TextureProps> = TProps['format'] | Default<TProps['viewFormats'], []>[number];
249
-
250
- interface Sampled {
251
- usableAsSampled: true;
252
- }
253
- interface Render {
254
- usableAsRender: true;
255
- }
256
- type LiteralToExtensionMap = {
257
- storage: Storage;
258
- sampled: Sampled;
259
- render: Render;
260
- };
261
- type AllowedUsages<TProps extends TextureProps> = 'sampled' | 'render' | (TProps['format'] extends StorageTextureTexelFormat ? 'storage' : never);
262
- declare function isUsableAsSampled<T>(value: T): value is T & Sampled;
263
- declare function isUsableAsRender<T>(value: T): value is T & Render;
264
-
265
- type ChannelData = U32 | I32 | F32;
266
- type TexelData = Vec4u | Vec4i | Vec4f;
267
- /**
268
- * @param TProps all properties that distinguish this texture apart from other textures on the type level.
269
- */
270
- interface TgpuTexture<TProps extends TextureProps = TextureProps> extends TgpuNamable {
271
- readonly resourceType: 'texture';
272
- readonly props: TProps;
273
- readonly label: string | undefined;
274
- readonly usableAsStorage: boolean;
275
- readonly usableAsSampled: boolean;
276
- readonly usableAsRender: boolean;
277
- $usage<T extends AllowedUsages<TProps>[]>(...usages: T): this & UnionToIntersection<LiteralToExtensionMap[T[number]]>;
278
- asReadonly<TDimension extends StorageTextureDimension, TFormat extends StorageFormatOptions<TProps>>(params?: TextureViewParams<TDimension, TFormat>): ExtensionGuard<this['usableAsStorage'], "missing .$usage('storage')", TgpuReadonlyTexture<StorageTextureDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>>;
279
- asWriteonly<TDimension extends StorageTextureDimension, TFormat extends StorageFormatOptions<TProps>>(params?: TextureViewParams<TDimension, TFormat>): ExtensionGuard<this['usableAsStorage'], "missing .$usage('storage')", TgpuWriteonlyTexture<StorageTextureDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>>;
280
- asMutable<TDimension extends StorageTextureDimension, TFormat extends StorageFormatOptions<TProps>>(params?: TextureViewParams<TDimension, TFormat>): ExtensionGuard<this['usableAsStorage'], "missing .$usage('storage')", TgpuMutableTexture<StorageTextureDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>>;
281
- asSampled<TDimension extends GPUTextureViewDimension, TFormat extends SampledFormatOptions<TProps>>(params?: TextureViewParams<TDimension, TFormat>): ExtensionGuard<this['usableAsSampled'], "missing .$usage('sampled')", TgpuSampledTexture<GPUTextureViewDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension, TexelFormatToChannelType[SampledFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat]>>;
282
- destroy(): void;
283
- }
284
- type StorageTextureAccess = 'readonly' | 'writeonly' | 'mutable';
285
- /**
286
- * Based on @see GPUTextureViewDimension
287
- * https://www.w3.org/TR/WGSL/#texture-depth
288
- */
289
- type StorageTextureDimension = '1d' | '2d' | '2d-array' | '3d';
290
- type TextureViewParams<TDimension extends GPUTextureViewDimension | undefined, TFormat extends GPUTextureFormat | undefined> = {
291
- format?: TFormat;
292
- dimension?: TDimension;
293
- aspect?: GPUTextureAspect;
294
- baseMipLevel?: number;
295
- mipLevelCount?: number;
296
- baseArrayLayout?: number;
297
- arrayLayerCount?: number;
298
- };
299
- interface TgpuStorageTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> {
300
- readonly resourceType: 'texture-storage-view';
301
- readonly dimension: TDimension;
302
- readonly texelDataType: TData;
303
- readonly access: StorageTextureAccess;
304
- }
305
- /**
306
- * A texture accessed as "readonly" storage on the GPU.
307
- */
308
- interface TgpuReadonlyTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData>, TgpuResolvable {
309
- readonly access: 'readonly';
310
- }
311
- /**
312
- * A texture accessed as "writeonly" storage on the GPU.
313
- */
314
- interface TgpuWriteonlyTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData>, TgpuResolvable {
315
- readonly access: 'writeonly';
316
- }
317
- /**
318
- * A texture accessed as "mutable" (or read_write) storage on the GPU.
319
- */
320
- interface TgpuMutableTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData>, TgpuResolvable {
321
- readonly access: 'mutable';
322
- }
323
- /**
324
- * A texture accessed as sampled on the GPU.
325
- */
326
- interface TgpuSampledTexture<TDimension extends GPUTextureViewDimension = GPUTextureViewDimension, TData extends ChannelData = ChannelData> extends TgpuResolvable {
327
- readonly resourceType: 'texture-sampled-view';
328
- readonly dimension: TDimension;
329
- readonly channelDataType: TData;
330
- }
331
- declare function isTexture<T extends TgpuTexture>(value: unknown | T): value is T;
332
- declare function isStorageTextureView<T extends TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture>(value: unknown | T): value is T;
333
- declare function isSampledTextureView<T extends TgpuSampledTexture>(value: unknown | T): value is T;
334
- type TgpuAnyTextureView = TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture | TgpuSampledTexture;
335
-
336
- interface Unwrapper {
337
- readonly device: GPUDevice;
338
- unwrap(resource: TgpuComputePipeline): GPUComputePipeline;
339
- unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
340
- unwrap(resource: TgpuBindGroup): GPUBindGroup;
341
- unwrap(resource: TgpuBuffer$1<AnyData>): GPUBuffer;
342
- unwrap(resource: TgpuTexture): GPUTexture;
343
- unwrap(resource: TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture | TgpuSampledTexture): GPUTextureView;
344
- }
345
-
346
- type CreateTextureOptions<TSize, TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormat extends GPUTextureFormat, TDimension extends GPUTextureDimension> = {
347
- /**
348
- * The width, height, and depth or layer count of the texture.
349
- */
350
- size: TSize;
351
- /**
352
- * The format of the texture.
353
- */
354
- format: TFormat;
355
- /**
356
- * The number of mip levels the texture will contain.
357
- * @default 1
358
- */
359
- mipLevelCount?: TMipLevelCount | undefined;
360
- /**
361
- * The sample count of the texture. A sampleCount > 1 indicates a multisampled texture.
362
- * @default 1
363
- */
364
- sampleCount?: TSampleCount | undefined;
365
- /**
366
- * Specifies extra formats (in addition to the texture's actual format) that can be used
367
- * when creating views of this texture.
368
- * @default []
369
- */
370
- viewFormats?: TViewFormat[] | undefined;
371
- /**
372
- * Whether the texture is one-dimensional, an array of two-dimensional layers, or three-dimensional.
373
- * @default '2d'
374
- */
375
- dimension?: TDimension | undefined;
376
- };
377
- type CreateTextureResult<TSize extends readonly number[], TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormat extends GPUTextureFormat, TDimension extends GPUTextureDimension> = Prettify<{
378
- size: Mutable<TSize>;
379
- format: TFormat;
380
- } & OmitProps<{
381
- dimension: GPUTextureDimension extends TDimension ? undefined : TDimension extends '2d' ? undefined : TDimension;
382
- mipLevelCount: number extends TMipLevelCount ? undefined : TMipLevelCount extends 1 ? undefined : TMipLevelCount;
383
- sampleCount: number extends TSampleCount ? undefined : TSampleCount extends 1 ? undefined : TSampleCount;
384
- viewFormats: GPUTextureFormat extends TViewFormat ? undefined : TViewFormat[] extends never[] ? undefined : TViewFormat[];
385
- }, undefined>>;
386
25
  interface TgpuRoot extends Unwrapper {
387
26
  /**
388
27
  * The GPU device associated with this root.
@@ -398,254 +37,68 @@ interface TgpuRoot extends Unwrapper {
398
37
  * @param gpuBuffer A vanilla WebGPU buffer.
399
38
  */
400
39
  createBuffer<TData extends AnyData>(typeSchema: TData, gpuBuffer: GPUBuffer): TgpuBuffer$1<Exotic<TData>>;
401
- 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, TViewFormat extends GPUTextureFormat, TDimension extends GPUTextureDimension>(props: CreateTextureOptions<TSize, TFormat, TMipLevelCount, TSampleCount, TViewFormat, TDimension>): TgpuTexture<CreateTextureResult<TSize, TFormat, TMipLevelCount, TSampleCount, TViewFormat, TDimension>>;
402
40
  createBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>>(layout: TgpuBindGroupLayout<Entries>, entries: {
403
41
  [K in keyof OmitProps<Entries, null>]: LayoutEntryToInput<Entries[K]>;
404
42
  }): TgpuBindGroup<Entries>;
405
43
  destroy(): void;
406
44
  }
407
45
 
408
- interface Uniform {
409
- usableAsUniform: true;
410
- }
411
- declare const Uniform: Uniform;
412
- interface Vertex {
413
- usableAsVertex: true;
414
- }
415
- declare const Vertex: Vertex;
416
- type LiteralToUsageType<T extends 'uniform' | 'storage' | 'vertex'> = T extends 'uniform' ? Uniform : T extends 'storage' ? Storage : T extends 'vertex' ? Vertex : never;
417
- interface TgpuBuffer$1<TData extends AnyData> extends TgpuNamable {
418
- readonly resourceType: 'buffer';
419
- readonly dataType: TData;
420
- readonly initial?: Infer<TData> | undefined;
421
- readonly label: string | undefined;
422
- readonly buffer: GPUBuffer;
423
- readonly destroyed: boolean;
424
- $usage<T extends RestrictVertexUsages<TData>>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
425
- $addFlags(flags: GPUBufferUsageFlags): this;
426
- write(data: Infer<TData>): void;
427
- copyFrom(srcBuffer: TgpuBuffer$1<TData>): void;
428
- read(): Promise<Infer<TData>>;
429
- destroy(): void;
430
- }
431
- declare function isBuffer<T extends TgpuBuffer$1<AnyData>>(value: T | unknown): value is T;
432
- declare function isUsableAsUniform<T extends TgpuBuffer$1<AnyData>>(buffer: T): buffer is T & Uniform;
433
- declare function isUsableAsVertex<T extends TgpuBuffer$1<AnyData>>(buffer: T): buffer is T & Vertex;
434
- type RestrictVertexUsages<TData extends AnyData> = TData extends {
435
- readonly type: WgslTypeLiteral;
436
- } ? ('uniform' | 'storage' | 'vertex')[] : 'vertex'[];
437
-
438
- interface TgpuBufferUsage<TData extends BaseWgslData, TUsage extends BindableBufferUsage = BindableBufferUsage> extends TgpuResolvable {
439
- readonly resourceType: 'buffer-usage';
440
- readonly usage: TUsage;
441
- readonly '~repr': Infer<TData>;
442
- value: Infer<TData>;
443
- }
444
- interface TgpuBufferUniform$1<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'uniform'> {
445
- readonly value: Infer<TData>;
446
- }
447
- interface TgpuBufferReadonly$1<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'readonly'> {
448
- readonly value: Infer<TData>;
449
- }
450
- interface TgpuBufferMutable$1<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'mutable'> {
451
- }
452
-
453
- interface TgpuSampler extends TgpuResolvable {
454
- readonly resourceType: 'sampler';
455
- }
456
- interface TgpuComparisonSampler {
457
- readonly resourceType: 'sampler-comparison';
458
- }
459
- declare function isSampler(resource: unknown): resource is TgpuSampler;
460
- declare function isComparisonSampler(resource: unknown): resource is TgpuComparisonSampler;
461
-
462
- type TgpuLayoutEntryBase = {
463
- /**
464
- * Limits this resource's visibility to specific shader stages.
465
- *
466
- * By default, each resource is visible to all shader stage types, but
467
- * depending on the underlying implementation, this may have performance implications.
468
- *
469
- * @default ['compute'] for mutable resources
470
- * @default ['compute','vertex','fragment'] for everything else
471
- */
472
- visibility?: TgpuShaderStage[];
473
- };
474
- type TgpuLayoutUniform = TgpuLayoutEntryBase & {
475
- uniform: AnyWgslData;
476
- };
477
- type TgpuLayoutStorage = TgpuLayoutEntryBase & {
478
- storage: AnyWgslData | ((arrayLength: number) => AnyWgslData);
479
- /** @default 'readonly' */
480
- access?: 'mutable' | 'readonly';
481
- };
482
- type TgpuLayoutSampler = TgpuLayoutEntryBase & {
483
- sampler: GPUSamplerBindingType;
484
- };
485
- type TgpuLayoutTexture<TSampleType extends GPUTextureSampleType = GPUTextureSampleType> = TgpuLayoutEntryBase & {
486
- /**
487
- * - 'float' - f32
488
- * - 'unfilterable-float' - f32, cannot be used with filtering samplers
489
- * - 'depth' - f32
490
- * - 'sint' - i32
491
- * - 'uint' - u32
492
- */
493
- texture: TSampleType;
46
+ interface TgpuResolveOptions {
494
47
  /**
495
- * @default '2d'
48
+ * Map of external names to their resolvable values.
496
49
  */
497
- viewDimension?: GPUTextureViewDimension;
50
+ externals: Record<string, TgpuResolvable | AnyWgslData | boolean | number>;
498
51
  /**
499
- * @default false
52
+ * The code template to use for the resolution. All external names will be replaced with their resolved values.
53
+ * @default ''
500
54
  */
501
- multisampled?: boolean;
502
- };
503
- type TgpuLayoutStorageTexture<TFormat extends StorageTextureTexelFormat = StorageTextureTexelFormat> = TgpuLayoutEntryBase & {
504
- storageTexture: TFormat;
505
- /** @default 'writeonly' */
506
- access?: 'readonly' | 'writeonly' | 'mutable';
507
- /** @default '2d' */
508
- viewDimension?: StorageTextureDimension;
509
- };
510
- type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
511
- externalTexture: Record<string, never>;
512
- };
513
- type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
514
- type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends (_: number) => BaseWgslData ? ReturnType<T> : T;
515
- type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
516
- interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
517
- readonly resourceType: 'bind-group-layout';
518
- readonly label: string | undefined;
519
- readonly entries: Entries;
520
- readonly bound: {
521
- [K in keyof Entries]: BindLayoutEntry<Entries[K]>;
522
- };
55
+ template?: string | undefined;
523
56
  /**
524
- * An explicit numeric index assigned to this bind group layout. If undefined, a unique
525
- * index is assigned automatically during resolution. This can be changed with the
526
- * `.$idx()` method.
527
- */
528
- readonly index: number | undefined;
529
- /**
530
- * @deprecated Use the `root.createBindGroup` API instead, accessible through `await tgpu.init()`
57
+ * The naming strategy used for generating identifiers for resolved externals and their dependencies.
58
+ * @default 'random'
531
59
  */
532
- populate(entries: {
533
- [K in keyof OmitProps<Entries, null>]: LayoutEntryToInput<Entries[K]>;
534
- }): TgpuBindGroup<Entries>;
60
+ names?: 'strict' | 'random' | undefined;
535
61
  /**
536
- * Creates a raw WebGPU resource based on the typed descriptor.
537
- * NOTE: This creates a new resource every time, better to use `root.unwrap(...)` instead.
538
- * @param unwrapper Used to unwrap any resources that this resource depends on.
62
+ * Optional JIT transpiler for resolving TGSL functions.
63
+ * @experimental
539
64
  */
540
- unwrap(unwrapper: Unwrapper): GPUBindGroupLayout;
541
- }
542
- type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
543
- access?: infer Access;
544
- } ? 'mutable' | 'readonly' extends Access ? TgpuBufferReadonly$1<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable$1<UnwrapRuntimeConstructor<T['storage']>> : 'readonly' extends Access ? TgpuBufferReadonly$1<UnwrapRuntimeConstructor<T['storage']>> : 'mutable' extends Access ? TgpuBufferMutable$1<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly$1<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable$1<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly$1<UnwrapRuntimeConstructor<T['storage']>>;
545
- type GetUsageForStorageTexture<T extends TgpuLayoutStorageTexture, TAccess extends 'readonly' | 'writeonly' | 'mutable'> = {
546
- mutable: TgpuMutableTexture<Default<GetDimension<T['viewDimension']>, '2d'>, TexelFormatToDataType[T['storageTexture']]>;
547
- readonly: TgpuReadonlyTexture<Default<GetDimension<T['viewDimension']>, '2d'>, TexelFormatToDataType[T['storageTexture']]>;
548
- writeonly: TgpuWriteonlyTexture<Default<GetDimension<T['viewDimension']>, '2d'>, TexelFormatToDataType[T['storageTexture']]>;
549
- }[TAccess];
550
- type StorageTextureUsageForEntry<T extends TgpuLayoutStorageTexture> = T extends unknown ? GetUsageForStorageTexture<T, Default<T['access'], 'writeonly'>> : never;
551
- type GetDimension<T extends GPUTextureViewDimension | undefined> = T extends keyof ViewDimensionToDimension ? ViewDimensionToDimension[T] : undefined;
552
- type GetTextureRestriction<T extends TgpuLayoutTexture> = Default<GetDimension<T['viewDimension']>, '2d'> extends infer Dimension ? Dimension extends '2d' ? {
553
- format: ChannelTypeToLegalFormats[SampleTypeToStringChannelType[T['texture']]];
554
- dimension?: Dimension;
555
- } : {
556
- format: ChannelTypeToLegalFormats[SampleTypeToStringChannelType[T['texture']]];
557
- dimension: Dimension;
558
- } : never;
559
- type GetStorageTextureRestriction<T extends TgpuLayoutStorageTexture> = Default<GetDimension<T['viewDimension']>, '2d'> extends infer Dimension ? Dimension extends '2d' ? {
560
- format: T['storageTexture'];
561
- dimension?: Dimension;
562
- } : {
563
- format: T['storageTexture'];
564
- dimension: Dimension;
565
- } : never;
566
- type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? (TgpuBuffer$1<UnwrapRuntimeConstructor<T['uniform']>> & Uniform) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer$1<UnwrapRuntimeConstructor<T['storage']>> & Storage) | GPUBuffer : T extends TgpuLayoutSampler ? GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | (TgpuTexture<Prettify<TextureProps & GetTextureRestriction<T>>> & Sampled) : T extends TgpuLayoutStorageTexture ? GPUTextureView | (TgpuTexture<Prettify<TextureProps & GetStorageTextureRestriction<T>>> & Storage) : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
567
- type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform$1<UnwrapRuntimeConstructor<T['uniform']>> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
568
- type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
569
- readonly resourceType: 'bind-group';
570
- readonly layout: TgpuBindGroupLayout<Entries>;
571
- unwrap(unwrapper: Unwrapper): GPUBindGroup;
572
- };
573
- type ExoticEntry<T> = T extends Record<string | number | symbol, unknown> ? {
574
- [Key in keyof T]: T[Key] extends BaseWgslData ? Exotic<T[Key]> : T[Key] extends (...args: infer TArgs) => infer TReturn ? (...args: TArgs) => Exotic<TReturn> : T[Key];
575
- } : T;
576
- type ExoticEntries<T extends Record<string, TgpuLayoutEntry | null>> = {
577
- [BindingKey in keyof T]: ExoticEntry<T[BindingKey]>;
578
- };
579
- declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<ExoticEntries<Entries>>>;
580
-
581
- type Wgsl = Eventual<string | number | boolean | TgpuResolvable | AnyWgslData>;
582
- declare const UnknownData: unique symbol;
583
- type UnknownData = typeof UnknownData;
584
- type Resource = {
585
- value: unknown;
586
- dataType: AnyWgslData | UnknownData;
587
- };
588
- type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
589
- interface FnToWgslOptions {
590
- args: Resource[];
591
- returnType: AnyWgslData;
592
- body: Block;
593
- externalMap: Record<string, unknown>;
65
+ unstable_jitTranspiler?: JitTranspiler | undefined;
594
66
  }
595
67
  /**
596
- * Passed into each resolvable item. All items in a tree share a resolution ctx,
597
- * but there can be layers added and removed from the item stack when going down
598
- * and up the tree.
68
+ * Resolves a template with external values. Each external will get resolved to a code string and replaced in the template.
69
+ * Any dependencies of the externals will also be resolved and included in the output.
70
+ * @param options - The options for the resolution.
71
+ *
72
+ * @returns The resolved code.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const Gradient = d.struct({
77
+ * from: d.vec3f,
78
+ * to: d.vec3f,
79
+ * });
80
+ *
81
+ * const resolved = tgpu.resolve({
82
+ * template: `
83
+ * fn getGradientAngle(gradient: Gradient) -> f32 {
84
+ * return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
85
+ * }
86
+ * `,
87
+ * externals: {
88
+ * Gradient,
89
+ * },
90
+ * });
91
+ *
92
+ * console.log(resolved);
93
+ * // struct Gradient_0 {
94
+ * // from: vec3f,
95
+ * // to: vec3f,
96
+ * // }
97
+ * // fn getGradientAngle(gradient: Gradient_0) -> f32 {
98
+ * // return atan(gradient.to.y - gradient.from.y, gradient.to.x - gradient.from.x);
99
+ * // }
100
+ * ```
599
101
  */
600
- interface ResolutionCtx {
601
- readonly names: NameRegistry;
602
- addDeclaration(declaration: string): void;
603
- /**
604
- * Reserves a bind group number, and returns a placeholder that will be replaced
605
- * with a concrete number at the end of the resolution process.
606
- */
607
- allocateLayoutEntry(layout: TgpuBindGroupLayout): string;
608
- /**
609
- * Reserves a spot in the catch-all bind group, without the indirection of a bind-group.
610
- * This means the resource is 'fixed', and cannot be swapped between code execution.
611
- */
612
- allocateFixedEntry(layoutEntry: TgpuLayoutEntry, resource: object): {
613
- group: string;
614
- binding: number;
615
- };
616
- withSlots<T>(pairs: SlotValuePair<unknown>[], callback: () => T): T;
617
- /**
618
- * Unwraps all layers of slot/derived indirection and returns the concrete value if available.
619
- * @throws {MissingSlotValueError}
620
- */
621
- unwrap<T>(eventual: Eventual<T>): T;
622
- resolve(item: Wgsl): string;
623
- resolveValue<T extends BaseWgslData>(value: Infer<T>, schema: T): string;
624
- transpileFn(fn: string): {
625
- argNames: string[];
626
- body: Block;
627
- externalNames: string[];
628
- };
629
- fnToWgsl(options: FnToWgslOptions): {
630
- head: Wgsl;
631
- body: Wgsl;
632
- };
633
- }
634
- interface TgpuResolvable {
635
- readonly label?: string | undefined;
636
- resolve(ctx: ResolutionCtx): string;
637
- }
638
- type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
639
-
640
- interface TgpuResolveOptions {
641
- input: string | TgpuResolvable | AnyWgslData | (string | TgpuResolvable | AnyWgslData)[];
642
- extraDependencies?: Record<string, TgpuResolvable | AnyWgslData | string | number> | undefined;
643
- /**
644
- * @default 'random'
645
- */
646
- names?: 'strict' | 'random' | undefined;
647
- jitTranspiler?: JitTranspiler | undefined;
648
- }
649
102
  declare function resolve(options: TgpuResolveOptions): string;
650
103
 
651
104
  /**
@@ -706,9 +159,9 @@ declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
706
159
  */
707
160
  declare class ResolutionError extends Error {
708
161
  readonly cause: unknown;
709
- readonly trace: (TgpuResolvable | TgpuSlot<unknown> | TgpuDerived<unknown> | AnyWgslData)[];
710
- constructor(cause: unknown, trace: (TgpuResolvable | TgpuSlot<unknown> | TgpuDerived<unknown> | AnyWgslData)[]);
711
- appendToTrace(ancestor: TgpuResolvable | TgpuDerived<unknown> | AnyWgslData): ResolutionError;
162
+ readonly trace: unknown[];
163
+ constructor(cause: unknown, trace: unknown[]);
164
+ appendToTrace(ancestor: unknown): ResolutionError;
712
165
  }
713
166
  /**
714
167
  * @category Errors
@@ -739,4 +192,4 @@ declare const tgpu: {
739
192
  resolve: typeof resolve;
740
193
  };
741
194
 
742
- export { type BindLayoutEntry, type InitFromDeviceOptions, type InitOptions, type LayoutEntryToInput, NotUniformError, type Render, ResolutionError, type Sampled, Storage, type TextureProps, type TgpuAnyTextureView, type TgpuBindGroup, type TgpuBindGroupLayout, type TgpuBuffer, type TgpuBufferMutable, type TgpuBufferReadonly, type TgpuBufferUniform, type TgpuLayoutEntry, type TgpuLayoutExternalTexture, type TgpuLayoutSampler, type TgpuLayoutStorage, type TgpuLayoutStorageTexture, type TgpuLayoutTexture, type TgpuLayoutUniform, type TgpuMutableTexture, type TgpuReadonlyTexture, type TgpuRoot, type TgpuSampledTexture, type TgpuSampler, type TgpuTexture, type TgpuWriteonlyTexture, Uniform, Vertex, tgpu as default, isBuffer, isComparisonSampler, isSampledTextureView, isSampler, isStorageTextureView, isTexture, isUsableAsRender, isUsableAsSampled, isUsableAsStorage, isUsableAsUniform, isUsableAsVertex, tgpu };
195
+ export { type InitFromDeviceOptions, type InitOptions, LayoutEntryToInput, NotUniformError, ResolutionError, TgpuBindGroup, TgpuBindGroupLayout, type TgpuBuffer, type TgpuBufferMutable, type TgpuBufferReadonly, type TgpuBufferUniform, TgpuLayoutEntry, type TgpuRoot, tgpu as default, tgpu };