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