typegpu 0.5.4 → 0.5.6

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.
package/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { A as AnyWgslData, T as TgpuNamable, I as Infer, F as F32, a as F16, b as I32, U as U32, V as Vec2f, c as Vec3f, d as Vec4f, e as Vec2h, f as Vec3h, g as Vec4h, h as Vec2i, i as Vec3i, j as Vec4i, k as Vec2u, l as Vec3u, m as Vec4u, D as Decorated, n as AnyWgslStruct, $ as $repr, B as BaseData, L as Location, W as WgslStruct, o as Default, p as UnionToIntersection, q as WgslArray, O as OmitProps, P as Prettify, M as Mutable, r as WgslTypeLiteral, s as InferPartial, t as MemIdentity, u as InferGPU, v as AbstractInt, w as AbstractFloat, x as AnyVecInstance, y as AnyMatInstance } from './wgslTypes-Bh2dG5qv.js';
2
- import { A as AnyAttribute, a as AnyComputeBuiltin, D as Decorate, I as IsBuiltin, H as HasCustomLocation, b as AnyFragmentInputBuiltin, c as AnyFragmentOutputBuiltin, O as OmitBuiltins, d as Disarray, U as Unstruct, V as VertexFormat, T as TgpuVertexAttrib, K as KindToDefaultFormatMap, e as KindToAcceptedAttribMap, f as AnyData } from './attributes-CAsvE5Z9.js';
3
- import * as smol from 'tinyest';
1
+ import { A as AnyWgslData, T as TgpuNamable, I as Infer, $ as $internal, F as F32, a as F16, b as I32, U as U32, V as Vec2f, c as Vec3f, d as Vec4f, e as Vec2h, f as Vec3h, g as Vec4h, h as Vec2i, i as Vec3i, j as Vec4i, k as Vec2u, l as Vec3u, m as Vec4u, D as Decorated, n as AnyWgslStruct, o as $repr, B as BaseData, L as Location, W as WgslStruct, p as WgslArray, q as Disarray, r as AnyUnstruct, s as VertexFormat, t as TgpuVertexAttrib, K as KindToDefaultFormatMap, u as KindToAcceptedAttribMap, v as AnyData, O as OmitProps, P as Prettify, M as Mutable, w as WgslTypeLiteral, x as UnionToIntersection, y as InferPartial, z as MemIdentity, C as Default, E as InferGPU, G as AnyVecInstance, H as AnyMatInstance } from './dataTypes-6k4EJeol.js';
2
+ import { A as AnyAttribute, a as AnyComputeBuiltin, D as Decorate, I as IsBuiltin, H as HasCustomLocation, b as AnyFragmentInputBuiltin, c as AnyFragmentOutputBuiltin, O as OmitBuiltins } from './attributes-B90UjSYb.js';
3
+ import * as tinyest from 'tinyest';
4
4
  import { ArgNames, Block } from 'tinyest';
5
-
6
- declare const $internal: unique symbol;
5
+ import { T as TgpuTexture, R as Render, a as TgpuReadonlyTexture, b as TgpuWriteonlyTexture, c as TgpuMutableTexture, d as TgpuSampledTexture, e as TgpuSampler, f as TgpuComparisonSampler, S as StorageFlag, g as StorageTextureTexelFormat, h as StorageTextureDimension, C as ChannelFormatToSchema, V as ViewDimensionToDimension, i as TexelFormatToDataType, j as Sampled, k as TextureProps, l as ChannelTypeToLegalFormats, m as SampleTypeToStringChannelType, n as TgpuAnyTextureView, s as sampler, o as comparisonSampler } from './sampler-ByLNpSxj.js';
6
+ export { y as Storage, q as isComparisonSampler, r as isSampledTextureView, p as isSampler, t as isStorageTextureView, u as isTexture, v as isUsableAsRender, w as isUsableAsSampled, x as isUsableAsStorage } from './sampler-ByLNpSxj.js';
7
7
 
8
8
  interface TgpuConst<TDataType extends AnyWgslData = AnyWgslData> extends TgpuNamable {
9
9
  readonly value: Infer<TDataType>;
@@ -36,8 +36,8 @@ declare function declare(declaration: string): TgpuDeclare;
36
36
  * Information extracted from transpiling a JS function.
37
37
  */
38
38
  type TranspilationResult = {
39
- argNames: smol.ArgNames;
40
- body: smol.Block;
39
+ argNames: tinyest.ArgNames;
40
+ body: tinyest.Block;
41
41
  /**
42
42
  * All identifiers found in the function code that are not declared in the
43
43
  * function itself, or in the block that is accessing that identifier.
@@ -48,7 +48,8 @@ type InferArgs<T extends unknown[]> = {
48
48
  [Idx in keyof T]: Infer<T[Idx]>;
49
49
  };
50
50
  type InferReturn<T> = T extends undefined ? void : Infer<T>;
51
- type Implementation<Args extends unknown[] = unknown[], Return = unknown> = string | ((...args: Args) => Return);
51
+ type JsImplementation<Args extends unknown[] | Record<string, unknown> = unknown[] | Record<string, unknown>, Return = unknown> = (...args: Args extends unknown[] ? InferArgs<Args> : Args extends Record<string, never> ? [] : [InferIO<Args>]) => InferReturn<Return>;
52
+ type Implementation<Args extends unknown[] | Record<string, unknown> = unknown[] | Record<string, unknown>, Return = unknown> = string | JsImplementation<Args, Return>;
52
53
  type BaseIOData = F32 | F16 | I32 | U32 | Vec2f | Vec3f | Vec4f | Vec2h | Vec3h | Vec4h | Vec2i | Vec3i | Vec4i | Vec2u | Vec3u | Vec4u;
53
54
  type IOData = BaseIOData | Decorated<BaseIOData, AnyAttribute[]>;
54
55
  type IORecord<TElementType extends IOData = IOData> = Record<string, TElementType>;
@@ -66,9 +67,10 @@ type InferIO<T> = T extends {
66
67
  * Describes a compute entry function signature (its arguments, return type and workgroup size)
67
68
  */
68
69
  type TgpuComputeFnShellHeader<ComputeIn extends Record<string, AnyComputeBuiltin>> = {
69
- readonly argTypes: [AnyWgslStruct];
70
+ readonly argTypes: [AnyWgslStruct] | [];
70
71
  readonly returnType: undefined;
71
72
  readonly workgroupSize: [number, number, number];
73
+ readonly isEntry: true;
72
74
  };
73
75
  /**
74
76
  * Describes a compute entry function signature (its arguments, return type and workgroup size).
@@ -84,7 +86,7 @@ type TgpuComputeFnShell<ComputeIn extends Record<string, AnyComputeBuiltin>> = T
84
86
  * without `fn` keyword and function name
85
87
  * e.g. `"(x: f32) -> f32 { return x; }"`;
86
88
  */
87
- ((implementation: string) => TgpuComputeFn<ComputeIn>) & {
89
+ ((implementation: string) => TgpuComputeFn<ComputeIn>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuComputeFn<ComputeIn>) & {
88
90
  /**
89
91
  * @deprecated Invoke the shell as a function instead.
90
92
  */
@@ -109,17 +111,8 @@ declare function computeFn<ComputeIn extends Record<string, AnyComputeBuiltin>>(
109
111
  workgroupSize: number[];
110
112
  }): TgpuComputeFnShell<ComputeIn>;
111
113
 
112
- interface StorageFlag {
113
- usableAsStorage: true;
114
- }
115
- /**
116
- * @deprecated Use StorageFlag instead.
117
- */
118
- type Storage = StorageFlag;
119
- declare function isUsableAsStorage<T>(value: T): value is T & StorageFlag;
120
-
121
114
  /**
122
- * Used to transpile JS resources into SMoL on demand.
115
+ * Used to transpile JS resources into tinyest on demand.
123
116
  */
124
117
  interface JitTranspiler {
125
118
  transpileFn(rawJs: string): TranspilationResult;
@@ -206,9 +199,10 @@ type FragmentInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, AnyAttr
206
199
  * Describes a fragment entry function signature (its arguments, return type and targets)
207
200
  */
208
201
  type TgpuFragmentFnShellHeader<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = {
209
- readonly argTypes: [AnyWgslStruct];
202
+ readonly argTypes: [AnyWgslStruct] | [];
210
203
  readonly targets: FragmentOut;
211
204
  readonly returnType: FragmentOut;
205
+ readonly isEntry: true;
212
206
  };
213
207
  /**
214
208
  * Describes a fragment entry function signature (its arguments, return type and targets).
@@ -224,7 +218,7 @@ type TgpuFragmentFnShell<FragmentIn extends FragmentInConstrained, FragmentOut e
224
218
  * without `fn` keyword and function name
225
219
  * e.g. `"(x: f32) -> f32 { return x; }"`;
226
220
  */
227
- ((implementation: string) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) & {
221
+ ((implementation: string) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>) & {
228
222
  /**
229
223
  * @deprecated Invoke the shell as a function instead.
230
224
  */
@@ -254,16 +248,17 @@ declare function fragmentFn<FragmentIn extends FragmentInConstrained, FragmentOu
254
248
  * Describes a vertex entry function signature (its arguments, return type and attributes)
255
249
  */
256
250
  type TgpuVertexFnShellHeader<VertexIn extends IOLayout, VertexOut extends IOLayout> = {
257
- readonly argTypes: [AnyWgslStruct];
251
+ readonly argTypes: [AnyWgslStruct] | [];
258
252
  readonly returnType: VertexOut;
259
253
  readonly attributes: [VertexIn];
254
+ readonly isEntry: true;
260
255
  };
261
256
  /**
262
257
  * Describes a vertex entry function signature (its arguments, return type and attributes).
263
258
  * Allows creating tgpu vertex functions by calling this shell
264
259
  * and passing the implementation (as WGSL string or JS function) as the argument.
265
260
  */
266
- type TgpuVertexFnShell<VertexIn extends IOLayout, VertexOut extends IOLayout> = TgpuVertexFnShellHeader<VertexIn, VertexOut> & ((implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((implementation: string) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & {
261
+ type TgpuVertexFnShell<VertexIn extends IOLayout, VertexOut extends IOLayout> = TgpuVertexFnShellHeader<VertexIn, VertexOut> & ((implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((implementation: string) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & {
267
262
  /**
268
263
  * @deprecated Invoke the shell as a function instead.
269
264
  */
@@ -283,269 +278,6 @@ declare function vertexFn<VertexIn extends IORecord, VertexOut extends IORecord>
283
278
  out: VertexOut;
284
279
  }): TgpuVertexFnShell<VertexIn, VertexOut>;
285
280
 
286
- type TextureProps = {
287
- size: readonly number[];
288
- format: GPUTextureFormat;
289
- viewFormats?: GPUTextureFormat[] | undefined;
290
- dimension?: GPUTextureDimension | undefined;
291
- mipLevelCount?: number | undefined;
292
- sampleCount?: number | undefined;
293
- };
294
-
295
- declare const texelFormatToChannelType: {
296
- r8unorm: F32;
297
- r8snorm: F32;
298
- r8uint: U32;
299
- r8sint: I32;
300
- r16uint: U32;
301
- r16sint: I32;
302
- r16float: F32;
303
- rg8unorm: F32;
304
- rg8snorm: F32;
305
- rg8uint: U32;
306
- rg8sint: I32;
307
- r32uint: U32;
308
- r32sint: I32;
309
- r32float: F32;
310
- rg16uint: U32;
311
- rg16sint: I32;
312
- rg16float: F32;
313
- rgba8unorm: F32;
314
- 'rgba8unorm-srgb': F32;
315
- rgba8snorm: F32;
316
- rgba8uint: U32;
317
- rgba8sint: I32;
318
- bgra8unorm: F32;
319
- 'bgra8unorm-srgb': F32;
320
- rgb9e5ufloat: F32;
321
- rgb10a2uint: U32;
322
- rgb10a2unorm: F32;
323
- rg11b10ufloat: F32;
324
- rg32uint: U32;
325
- rg32sint: I32;
326
- rg32float: F32;
327
- rgba16uint: U32;
328
- rgba16sint: I32;
329
- rgba16float: F32;
330
- rgba32uint: U32;
331
- rgba32sint: I32;
332
- rgba32float: F32;
333
- stencil8: F32;
334
- depth16unorm: F32;
335
- depth24plus: F32;
336
- 'depth24plus-stencil8': F32;
337
- depth32float: F32;
338
- 'depth32float-stencil8': F32;
339
- 'bc1-rgba-unorm': F32;
340
- 'bc1-rgba-unorm-srgb': F32;
341
- 'bc2-rgba-unorm': F32;
342
- 'bc2-rgba-unorm-srgb': F32;
343
- 'bc3-rgba-unorm': F32;
344
- 'bc3-rgba-unorm-srgb': F32;
345
- 'bc4-r-unorm': F32;
346
- 'bc4-r-snorm': F32;
347
- 'bc5-rg-unorm': F32;
348
- 'bc5-rg-snorm': F32;
349
- 'bc6h-rgb-ufloat': F32;
350
- 'bc6h-rgb-float': F32;
351
- 'bc7-rgba-unorm': F32;
352
- 'bc7-rgba-unorm-srgb': F32;
353
- 'etc2-rgb8unorm': F32;
354
- 'etc2-rgb8unorm-srgb': F32;
355
- 'etc2-rgb8a1unorm': F32;
356
- 'etc2-rgb8a1unorm-srgb': F32;
357
- 'etc2-rgba8unorm': F32;
358
- 'etc2-rgba8unorm-srgb': F32;
359
- 'eac-r11unorm': F32;
360
- 'eac-r11snorm': F32;
361
- 'eac-rg11unorm': F32;
362
- 'eac-rg11snorm': F32;
363
- 'astc-4x4-unorm': F32;
364
- 'astc-4x4-unorm-srgb': F32;
365
- 'astc-5x4-unorm': F32;
366
- 'astc-5x4-unorm-srgb': F32;
367
- 'astc-5x5-unorm': F32;
368
- 'astc-5x5-unorm-srgb': F32;
369
- 'astc-6x5-unorm': F32;
370
- 'astc-6x5-unorm-srgb': F32;
371
- 'astc-6x6-unorm': F32;
372
- 'astc-6x6-unorm-srgb': F32;
373
- 'astc-8x5-unorm': F32;
374
- 'astc-8x5-unorm-srgb': F32;
375
- 'astc-8x6-unorm': F32;
376
- 'astc-8x6-unorm-srgb': F32;
377
- 'astc-8x8-unorm': F32;
378
- 'astc-8x8-unorm-srgb': F32;
379
- 'astc-10x5-unorm': F32;
380
- 'astc-10x5-unorm-srgb': F32;
381
- 'astc-10x6-unorm': F32;
382
- 'astc-10x6-unorm-srgb': F32;
383
- 'astc-10x8-unorm': F32;
384
- 'astc-10x8-unorm-srgb': F32;
385
- 'astc-10x10-unorm': F32;
386
- 'astc-10x10-unorm-srgb': F32;
387
- 'astc-12x10-unorm': F32;
388
- 'astc-12x10-unorm-srgb': F32;
389
- 'astc-12x12-unorm': F32;
390
- 'astc-12x12-unorm-srgb': F32;
391
- };
392
- type TexelFormatToChannelType = typeof texelFormatToChannelType;
393
- type TexelFormatToStringChannels = {
394
- [Key in keyof TexelFormatToChannelType]: TexelFormatToChannelType[Key]['type'];
395
- };
396
- type KeysWithValue<T extends Record<string, unknown>, TValue> = keyof {
397
- [Key in keyof T as T[Key] extends TValue ? Key : never]: Key;
398
- };
399
- type ChannelTypeToLegalFormats = {
400
- [Key in TexelFormatToChannelType[keyof TexelFormatToChannelType]['type']]: KeysWithValue<TexelFormatToStringChannels, Key>;
401
- };
402
- type SampleTypeToStringChannelType = {
403
- float: 'f32';
404
- 'unfilterable-float': 'f32';
405
- depth: 'f32';
406
- sint: 'i32';
407
- uint: 'u32';
408
- };
409
- type ViewDimensionToDimension = {
410
- '1d': '1d';
411
- '2d': '2d';
412
- '2d-array': '2d';
413
- '3d': '3d';
414
- cube: '2d';
415
- 'cube-array': '2d';
416
- };
417
- /**
418
- * https://www.w3.org/TR/WGSL/#storage-texel-formats
419
- */
420
- type StorageTextureTexelFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm';
421
- declare const texelFormatToDataType: {
422
- readonly rgba8unorm: Vec4f;
423
- readonly rgba8snorm: Vec4f;
424
- readonly rgba8uint: Vec4u;
425
- readonly rgba8sint: Vec4i;
426
- readonly rgba16uint: Vec4u;
427
- readonly rgba16sint: Vec4i;
428
- readonly rgba16float: Vec4f;
429
- readonly r32uint: Vec4u;
430
- readonly r32sint: Vec4i;
431
- readonly r32float: Vec4f;
432
- readonly rg32uint: Vec4u;
433
- readonly rg32sint: Vec4i;
434
- readonly rg32float: Vec4f;
435
- readonly rgba32uint: Vec4u;
436
- readonly rgba32sint: Vec4i;
437
- readonly rgba32float: Vec4f;
438
- readonly bgra8unorm: Vec4f;
439
- };
440
- declare const channelFormatToSchema: {
441
- float: F32;
442
- 'unfilterable-float': F32;
443
- uint: U32;
444
- sint: I32;
445
- depth: F32;
446
- };
447
- type ChannelFormatToSchema = typeof channelFormatToSchema;
448
- type TexelFormatToDataType = typeof texelFormatToDataType;
449
- type TexelFormatToDataTypeOrNever<T> = T extends keyof TexelFormatToDataType ? TexelFormatToDataType[T] : never;
450
- /**
451
- * Represents what formats a storage view can choose from based on its owner texture's props.
452
- */
453
- type StorageFormatOptions<TProps extends TextureProps> = Extract<TProps['format'] | Default<TProps['viewFormats'], []>[number], StorageTextureTexelFormat>;
454
- /**
455
- * Represents what formats a sampled view can choose from based on its owner texture's props.
456
- */
457
- type SampledFormatOptions<TProps extends TextureProps> = TProps['format'] | Default<TProps['viewFormats'], []>[number];
458
-
459
- interface Sampled {
460
- usableAsSampled: true;
461
- }
462
- interface Render {
463
- usableAsRender: true;
464
- }
465
- type LiteralToExtensionMap = {
466
- storage: StorageFlag;
467
- sampled: Sampled;
468
- render: Render;
469
- };
470
- type AllowedUsages<TProps extends TextureProps> = 'sampled' | 'render' | (TProps['format'] extends StorageTextureTexelFormat ? 'storage' : never);
471
- declare function isUsableAsSampled<T>(value: T): value is T & Sampled;
472
- declare function isUsableAsRender<T>(value: T): value is T & Render;
473
-
474
- type ResolveStorageDimension<TDimension extends GPUTextureViewDimension, TProps extends TextureProps> = StorageTextureDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension extends StorageTextureDimension ? TDimension : '2d';
475
- type ViewUsages$1<TProps extends TextureProps, TTexture extends TgpuTexture<TProps>> = boolean extends TTexture['usableAsSampled'] ? boolean extends TTexture['usableAsStorage'] ? never : 'readonly' | 'writeonly' | 'mutable' : boolean extends TTexture['usableAsStorage'] ? 'sampled' : 'readonly' | 'writeonly' | 'mutable' | 'sampled';
476
- type ChannelData = U32 | I32 | F32;
477
- type TexelData = Vec4u | Vec4i | Vec4f;
478
- /**
479
- * @param TProps all properties that distinguish this texture apart from other textures on the type level.
480
- */
481
- interface TgpuTexture<TProps extends TextureProps = TextureProps> extends TgpuNamable {
482
- readonly resourceType: 'texture';
483
- readonly props: TProps;
484
- readonly label: string | undefined;
485
- readonly usableAsStorage: boolean;
486
- readonly usableAsSampled: boolean;
487
- readonly usableAsRender: boolean;
488
- $usage<T extends AllowedUsages<TProps>[]>(...usages: T): this & UnionToIntersection<LiteralToExtensionMap[T[number]]>;
489
- createView<TUsage extends ViewUsages$1<TProps, this>, TDimension extends 'sampled' extends TUsage ? GPUTextureViewDimension : StorageTextureDimension, TFormat extends 'sampled' extends TUsage ? SampledFormatOptions<TProps> : StorageFormatOptions<TProps>>(access: TUsage, params?: TextureViewParams<TDimension, TFormat>): {
490
- mutable: TgpuMutableTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
491
- readonly: TgpuReadonlyTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
492
- writeonly: TgpuWriteonlyTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
493
- sampled: TgpuSampledTexture<GPUTextureViewDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension, TexelFormatToChannelType[SampledFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat]>;
494
- }[TUsage];
495
- destroy(): void;
496
- }
497
- type StorageTextureAccess = 'readonly' | 'writeonly' | 'mutable';
498
- /**
499
- * Based on @see GPUTextureViewDimension
500
- * https://www.w3.org/TR/WGSL/#texture-depth
501
- */
502
- type StorageTextureDimension = '1d' | '2d' | '2d-array' | '3d';
503
- type TextureViewParams<TDimension extends GPUTextureViewDimension | undefined, TFormat extends GPUTextureFormat | undefined> = {
504
- format?: TFormat;
505
- dimension?: TDimension;
506
- aspect?: GPUTextureAspect;
507
- baseMipLevel?: number;
508
- mipLevelCount?: number;
509
- baseArrayLayout?: number;
510
- arrayLayerCount?: number;
511
- };
512
- interface TgpuStorageTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> {
513
- readonly resourceType: 'texture-storage-view';
514
- readonly dimension: TDimension;
515
- readonly texelDataType: TData;
516
- readonly access: StorageTextureAccess;
517
- }
518
- /**
519
- * A texture accessed as "readonly" storage on the GPU.
520
- */
521
- interface TgpuReadonlyTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData> {
522
- readonly access: 'readonly';
523
- }
524
- /**
525
- * A texture accessed as "writeonly" storage on the GPU.
526
- */
527
- interface TgpuWriteonlyTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData> {
528
- readonly access: 'writeonly';
529
- }
530
- /**
531
- * A texture accessed as "mutable" (or read_write) storage on the GPU.
532
- */
533
- interface TgpuMutableTexture<TDimension extends StorageTextureDimension = StorageTextureDimension, TData extends TexelData = TexelData> extends TgpuStorageTexture<TDimension, TData> {
534
- readonly access: 'mutable';
535
- }
536
- /**
537
- * A texture accessed as sampled on the GPU.
538
- */
539
- interface TgpuSampledTexture<TDimension extends GPUTextureViewDimension = GPUTextureViewDimension, TData extends ChannelData = ChannelData> {
540
- readonly resourceType: 'texture-sampled-view';
541
- readonly dimension: TDimension;
542
- readonly channelDataType: TData;
543
- }
544
- declare function isTexture<T extends TgpuTexture>(value: unknown | T): value is T;
545
- declare function isStorageTextureView<T extends TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture>(value: unknown | T): value is T;
546
- declare function isSampledTextureView<T extends TgpuSampledTexture>(value: unknown | T): value is T;
547
- type TgpuAnyTextureView = TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture | TgpuSampledTexture;
548
-
549
281
  /**
550
282
  * The array can hold T, where T is a single/multi-component numeric, or a struct with members of type T.
551
283
  * Examples of valid array members:
@@ -554,7 +286,7 @@ type TgpuAnyTextureView = TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutab
554
286
  * - WgslStruct<{ a: Vec3f, b: unorm8x2 }>
555
287
  * - WgslStruct<{ nested: WgslStruct<{ a: Vec3f }> }>
556
288
  */
557
- type DataToContainedAttribs<T> = T extends AnyWgslStruct | Unstruct ? {
289
+ type DataToContainedAttribs<T> = T extends AnyWgslStruct | AnyUnstruct ? {
558
290
  [Key in keyof T['propTypes']]: DataToContainedAttribs<T['propTypes'][Key]>;
559
291
  } : T extends {
560
292
  type: VertexFormat;
@@ -688,100 +420,6 @@ interface DepthStencilAttachment {
688
420
  stencilReadOnly?: boolean;
689
421
  }
690
422
 
691
- interface SamplerProps {
692
- addressModeU?: GPUAddressMode;
693
- addressModeV?: GPUAddressMode;
694
- /**
695
- * Specifies the address modes for the texture width, height, and depth
696
- * coordinates, respectively.
697
- */
698
- addressModeW?: GPUAddressMode;
699
- /**
700
- * Specifies the sampling behavior when the sample footprint is smaller than or equal to one
701
- * texel.
702
- */
703
- magFilter?: GPUFilterMode;
704
- /**
705
- * Specifies the sampling behavior when the sample footprint is larger than one texel.
706
- */
707
- minFilter?: GPUFilterMode;
708
- /**
709
- * Specifies behavior for sampling between mipmap levels.
710
- */
711
- mipmapFilter?: GPUMipmapFilterMode;
712
- lodMinClamp?: number;
713
- /**
714
- * Specifies the minimum and maximum levels of detail, respectively, used internally when
715
- * sampling a texture.
716
- */
717
- lodMaxClamp?: number;
718
- /**
719
- * Specifies the maximum anisotropy value clamp used by the sampler. Anisotropic filtering is
720
- * enabled when {@link GPUSamplerDescriptor.maxAnisotropy} is > 1 and the implementation supports it.
721
- * Anisotropic filtering improves the image quality of textures sampled at oblique viewing
722
- * angles. Higher {@link GPUSamplerDescriptor.maxAnisotropy} values indicate the maximum ratio of
723
- * anisotropy supported when filtering.
724
- *
725
- * Most implementations support {@link GPUSamplerDescriptor.maxAnisotropy} values in range
726
- * between 1 and 16, inclusive. The used value of {@link GPUSamplerDescriptor.maxAnisotropy}
727
- * will be clamped to the maximum value that the platform supports.
728
- * The precise filtering behavior is implementation-dependent.
729
- */
730
- maxAnisotropy?: number;
731
- }
732
- interface ComparisonSamplerProps {
733
- compare: GPUCompareFunction;
734
- addressModeU?: GPUAddressMode;
735
- addressModeV?: GPUAddressMode;
736
- /**
737
- * Specifies the address modes for the texture width, height, and depth
738
- * coordinates, respectively.
739
- */
740
- addressModeW?: GPUAddressMode;
741
- /**
742
- * Specifies the sampling behavior when the sample footprint is smaller than or equal to one
743
- * texel.
744
- */
745
- magFilter?: GPUFilterMode;
746
- /**
747
- * Specifies the sampling behavior when the sample footprint is larger than one texel.
748
- */
749
- minFilter?: GPUFilterMode;
750
- /**
751
- * Specifies behavior for sampling between mipmap levels.
752
- */
753
- mipmapFilter?: GPUMipmapFilterMode;
754
- lodMinClamp?: number;
755
- /**
756
- * Specifies the minimum and maximum levels of detail, respectively, used internally when
757
- * sampling a texture.
758
- */
759
- lodMaxClamp?: number;
760
- /**
761
- * Specifies the maximum anisotropy value clamp used by the sampler. Anisotropic filtering is
762
- * enabled when {@link GPUSamplerDescriptor.maxAnisotropy} is > 1 and the implementation supports it.
763
- * Anisotropic filtering improves the image quality of textures sampled at oblique viewing
764
- * angles. Higher {@link GPUSamplerDescriptor.maxAnisotropy} values indicate the maximum ratio of
765
- * anisotropy supported when filtering.
766
- *
767
- * Most implementations support {@link GPUSamplerDescriptor.maxAnisotropy} values in range
768
- * between 1 and 16, inclusive. The used value of {@link GPUSamplerDescriptor.maxAnisotropy}
769
- * will be clamped to the maximum value that the platform supports.
770
- * The precise filtering behavior is implementation-dependent.
771
- */
772
- maxAnisotropy?: number;
773
- }
774
- interface TgpuSampler {
775
- readonly resourceType: 'sampler';
776
- }
777
- interface TgpuComparisonSampler {
778
- readonly resourceType: 'sampler-comparison';
779
- }
780
- declare function sampler(props: SamplerProps): TgpuSampler;
781
- declare function comparisonSampler(props: ComparisonSamplerProps): TgpuComparisonSampler;
782
- declare function isSampler(resource: unknown): resource is TgpuSampler;
783
- declare function isComparisonSampler(resource: unknown): resource is TgpuComparisonSampler;
784
-
785
423
  interface Unwrapper {
786
424
  readonly device: GPUDevice;
787
425
  unwrap(resource: TgpuComputePipeline): GPUComputePipeline;
@@ -1177,12 +815,6 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
1177
815
  * Used when generating WGSL code: `@group(${index}) @binding(...) ...;`
1178
816
  */
1179
817
  $idx(index?: number): this;
1180
- /**
1181
- * @deprecated Use the `root.createBindGroup` API instead, accessible through `await tgpu.init()`
1182
- */
1183
- populate(entries: {
1184
- [K in keyof OmitProps<Entries, null>]: LayoutEntryToInput<Entries[K]>;
1185
- }): TgpuBindGroup<Entries>;
1186
818
  /**
1187
819
  * Creates a raw WebGPU resource based on the typed descriptor.
1188
820
  * NOTE: This creates a new resource every time, better to use `root.unwrap(...)` instead.
@@ -1215,7 +847,7 @@ type GetStorageTextureRestriction<T extends TgpuLayoutStorageTexture> = Default<
1215
847
  dimension: Dimension;
1216
848
  } : never;
1217
849
  type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? (TgpuBuffer<UnwrapRuntimeConstructor<T['uniform']>> & UniformFlag) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer<UnwrapRuntimeConstructor<T['storage']>> & StorageFlag) | GPUBuffer : T extends TgpuLayoutSampler ? TgpuSampler | GPUSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler | GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | (Sampled & TgpuTexture<Prettify<TextureProps & GetTextureRestriction<T>>>) | TgpuSampledTexture<Default<T['viewDimension'], '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? GPUTextureView | (StorageFlag & TgpuTexture<Prettify<TextureProps & GetStorageTextureRestriction<T>>>) | StorageTextureUsageForEntry<T> : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
1218
- 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 ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
850
+ 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 ? TgpuSampledTexture<Default<T['viewDimension'], '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1219
851
  type InferLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? Infer<T['uniform']> : T extends TgpuLayoutStorage ? Infer<UnwrapRuntimeConstructor<T['storage']>> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1220
852
  type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
1221
853
  readonly resourceType: 'bind-group';
@@ -1286,20 +918,16 @@ declare function workgroupVar<TDataType extends AnyWgslData>(dataType: TDataType
1286
918
  type ResolvableObject = SelfResolvable | TgpuBufferUsage | TgpuConst | TgpuDeclare | TgpuFn | TgpuComputeFn | TgpuFragmentFn | TgpuComputePipeline | TgpuRenderPipeline | TgpuVertexFn | TgpuSampler | TgpuAccessor | TgpuExternalTexture | TgpuTexture | TgpuAnyTextureView | TgpuVar | AnyVecInstance | AnyMatInstance | AnyData | TgpuFn<any, any>;
1287
919
  type Wgsl = Eventual<string | number | boolean | ResolvableObject>;
1288
920
  declare const UnknownData: {
1289
- type: string;
921
+ type: "unknown";
1290
922
  };
1291
923
  type UnknownData = typeof UnknownData;
1292
- declare const Void: {
1293
- type: "void";
1294
- };
1295
- type Void = typeof Void;
1296
- type Resource = {
924
+ type Snippet = {
1297
925
  value: unknown;
1298
- dataType: AnyWgslData | UnknownData | AbstractInt | AbstractFloat | Void;
926
+ dataType: AnyData | UnknownData;
1299
927
  };
1300
928
  type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
1301
929
  interface FnToWgslOptions {
1302
- args: Resource[];
930
+ args: Snippet[];
1303
931
  returnType: AnyWgslData;
1304
932
  body: Block;
1305
933
  externalMap: Record<string, unknown>;
@@ -1315,14 +943,14 @@ interface ItemStateStack {
1315
943
  popItem(): void;
1316
944
  pushSlotBindings(pairs: SlotValuePair<unknown>[]): void;
1317
945
  popSlotBindings(): void;
1318
- pushFunctionScope(args: Resource[], returnType: AnyWgslData | undefined, externalMap: Record<string, unknown>): void;
946
+ pushFunctionScope(args: Snippet[], returnType: AnyWgslData | undefined, externalMap: Record<string, unknown>): void;
1319
947
  popFunctionScope(): void;
1320
948
  pushBlockScope(): void;
1321
949
  popBlockScope(): void;
1322
950
  pop(type?: 'functionScope' | 'blockScope' | 'slotBinding' | 'item'): void;
1323
951
  readSlot<T>(slot: TgpuSlot<T>): T | undefined;
1324
- getResourceById(id: string): Resource | undefined;
1325
- defineBlockVariable(id: string, type: AnyWgslData | UnknownData): Resource;
952
+ getSnippetById(id: string): Snippet | undefined;
953
+ defineBlockVariable(id: string, type: AnyWgslData | UnknownData): Snippet;
1326
954
  }
1327
955
  /**
1328
956
  * Passed into each resolvable item. All items in a tree share a resolution ctx,
@@ -1386,19 +1014,23 @@ type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
1386
1014
  type TgpuFnShellHeader<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = AnyWgslData | undefined> = {
1387
1015
  readonly argTypes: Args;
1388
1016
  readonly returnType: Return | undefined;
1017
+ readonly isEntry: false;
1389
1018
  };
1390
1019
  /**
1391
1020
  * Describes a function signature (its arguments and return type).
1392
1021
  * Allows creating tgpu functions by calling this shell
1393
1022
  * and passing the implementation (as WGSL string or JS function) as the argument.
1394
1023
  */
1395
- type TgpuFnShell<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnShellHeader<Args, Return> & ((implementation: (...args: Args extends AnyWgslData[] ? InferArgs<Args> : [InferIO<Args>]) => InferReturn<Return>) => TgpuFn<Args, Return>) & ((implementation: string) => TgpuFn<Args, Return>) & {
1024
+ type TgpuFnShell<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnShellHeader<Args, Return> & ((implementation: (...args: Args extends AnyWgslData[] ? InferArgs<Args> : [InferIO<Args>]) => InferReturn<Return>) => TgpuFn<Args, Return>) & ((implementation: string) => TgpuFn<Args, Return>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuFn<Args, Return>) & {
1396
1025
  /**
1397
1026
  * @deprecated Invoke the shell as a function instead.
1398
1027
  */
1399
1028
  does: ((implementation: (...args: Args extends AnyWgslData[] ? InferArgs<Args> : [InferIO<Args>]) => InferReturn<Return>) => TgpuFn<Args, Return>) & ((implementation: string) => TgpuFn<Args, Return>);
1400
1029
  };
1401
1030
  interface TgpuFnBase<Args extends AnyWgslData[] | Record<string, AnyWgslData>, Return extends AnyWgslData | undefined = undefined> extends TgpuNamable, Labelled {
1031
+ readonly [$internal]: {
1032
+ implementation: Implementation<Args, Return>;
1033
+ };
1402
1034
  readonly resourceType: 'function';
1403
1035
  readonly shell: TgpuFnShellHeader<Args, Return>;
1404
1036
  readonly '~providing'?: Providing | undefined;
@@ -1406,11 +1038,7 @@ interface TgpuFnBase<Args extends AnyWgslData[] | Record<string, AnyWgslData>, R
1406
1038
  with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TgpuFn<Args, Return>;
1407
1039
  with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): TgpuFn<Args, Return>;
1408
1040
  }
1409
- type TgpuFn<Args extends AnyWgslData[] | Record<string, AnyWgslData> = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnBase<Args, Return> & ((...args: Args extends AnyWgslData[] ? InferArgs<Args> : Args extends Record<string, never> ? [] : [InferIO<Args>]) => InferReturn<Return>) & {
1410
- readonly [$internal]: {
1411
- implementation: Implementation<Args extends AnyWgslData[] ? InferArgs<Args> : Args extends Record<string, never> ? [] : [InferIO<Args>], InferReturn<Return>>;
1412
- };
1413
- };
1041
+ type TgpuFn<Args extends AnyWgslData[] | Record<string, AnyWgslData> = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnBase<Args, Return> & ((...args: Args extends AnyWgslData[] ? InferArgs<Args> : Args extends Record<string, never> ? [] : [InferIO<Args>]) => InferReturn<Return>);
1414
1042
  declare function fn<Args extends AnyWgslData[] | Record<string, AnyWgslData> | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, undefined>;
1415
1043
  declare function fn<Args extends AnyWgslData[] | Record<string, AnyWgslData> | [], Return extends AnyWgslData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
1416
1044
  declare function isTgpuFn<Args extends AnyWgslData[], Return extends AnyWgslData | undefined = undefined>(value: unknown | TgpuFn<Args, Return>): value is TgpuFn<Args, Return>;
@@ -1595,4 +1223,4 @@ declare const tgpu: {
1595
1223
  };
1596
1224
  };
1597
1225
 
1598
- export { type BindLayoutEntry, type Eventual, type InitFromDeviceOptions, type InitOptions, type LayoutEntryToInput, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, RandomNameRegistry, type Render, ResolutionError, type Sampled, type Storage, type StorageFlag, StrictNameRegistry, type TextureProps, type TgpuAccessor, type TgpuAnyTextureView, type TgpuBindGroup, type TgpuBindGroupLayout, type TgpuBuffer, type TgpuBufferMutable, type TgpuBufferReadonly, type TgpuBufferUniform, type TgpuComputeFn, type TgpuComputeFnShell, type TgpuComputePipeline, type TgpuConst, type TgpuDeclare, type TgpuDerived, type TgpuFn, type TgpuFnShell, type TgpuFragmentFn, type TgpuFragmentFnShell, type TgpuLayoutComparisonSampler, type TgpuLayoutEntry, type TgpuLayoutExternalTexture, type TgpuLayoutSampler, type TgpuLayoutStorage, type TgpuLayoutStorageTexture, type TgpuLayoutTexture, type TgpuLayoutUniform, type TgpuMutableTexture, type TgpuReadonlyTexture, type TgpuRenderPipeline, type TgpuRoot, type TgpuSampledTexture, type TgpuSampler, type TgpuSlot, type TgpuTexture, type TgpuVar, type TgpuVertexFn, type TgpuVertexFnShell, type TgpuVertexLayout, type TgpuWriteonlyTexture, type Uniform, type UniformFlag, type VariableScope, type Vertex, type VertexFlag, type WithBinding, type WithCompute, type WithFragment, type WithVertex, tgpu as default, isBuffer, isComparisonSampler, isDerived, isSampledTextureView, isSampler, isSlot, isStorageTextureView, isTexture, isTgpuFn, isUsableAsRender, isUsableAsSampled, isUsableAsStorage, isUsableAsUniform, isUsableAsVertex, tgpu, asMutable as unstable_asMutable, asReadonly as unstable_asReadonly, asUniform as unstable_asUniform };
1226
+ export { type BindLayoutEntry, type Eventual, type InitFromDeviceOptions, type InitOptions, type LayoutEntryToInput, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, RandomNameRegistry, Render, ResolutionError, Sampled, StorageFlag, StrictNameRegistry, TextureProps, type TgpuAccessor, TgpuAnyTextureView, type TgpuBindGroup, type TgpuBindGroupLayout, type TgpuBuffer, type TgpuBufferMutable, type TgpuBufferReadonly, type TgpuBufferUniform, type TgpuComputeFn, type TgpuComputeFnShell, type TgpuComputePipeline, type TgpuConst, type TgpuDeclare, type TgpuDerived, type TgpuFn, type TgpuFnShell, type TgpuFragmentFn, type TgpuFragmentFnShell, type TgpuLayoutComparisonSampler, type TgpuLayoutEntry, type TgpuLayoutExternalTexture, type TgpuLayoutSampler, type TgpuLayoutStorage, type TgpuLayoutStorageTexture, type TgpuLayoutTexture, type TgpuLayoutUniform, TgpuMutableTexture, TgpuReadonlyTexture, type TgpuRenderPipeline, type TgpuRoot, TgpuSampledTexture, TgpuSampler, type TgpuSlot, TgpuTexture, type TgpuVar, type TgpuVertexFn, type TgpuVertexFnShell, type TgpuVertexLayout, TgpuWriteonlyTexture, type Uniform, type UniformFlag, type VariableScope, type Vertex, type VertexFlag, type WithBinding, type WithCompute, type WithFragment, type WithVertex, tgpu as default, isBuffer, isDerived, isSlot, isTgpuFn, isUsableAsUniform, isUsableAsVertex, tgpu, asMutable as unstable_asMutable, asReadonly as unstable_asReadonly, asUniform as unstable_asUniform };