typegpu 0.3.0-alpha.4 → 0.3.0-alpha.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.cts CHANGED
@@ -1,4 +1,4 @@
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, B as BaseWgslData, e as AnyWgslData } from './utilityTypes-NWbtoFu5.cjs';
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';
2
2
  import * as smol from 'tinyest';
3
3
  import { Block } from 'tinyest';
4
4
 
@@ -22,6 +22,32 @@ 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
+
25
51
  interface NameRegistry {
26
52
  /**
27
53
  * Creates a valid WGSL identifier, each guaranteed to be unique
@@ -34,7 +60,7 @@ interface NameRegistry {
34
60
  interface NotAllowed<TMsg> {
35
61
  reason: TMsg;
36
62
  }
37
- type ExtensionGuard<TFlag, TMsg, TAllowed> = boolean extends TFlag ? NotAllowed<TMsg> : TAllowed;
63
+ type ExtensionGuard<TFlag, TMsg, TAllowed> = boolean extends TFlag ? NotAllowed<TMsg> | TAllowed : TAllowed;
38
64
  interface Storage {
39
65
  usableAsStorage: true;
40
66
  }
@@ -155,6 +181,30 @@ declare const texelFormatToChannelType: {
155
181
  'astc-12x12-unorm-srgb': F32;
156
182
  };
157
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
+ };
158
208
  /**
159
209
  * https://www.w3.org/TR/WGSL/#storage-texel-formats
160
210
  */
@@ -178,6 +228,14 @@ declare const texelFormatToDataType: {
178
228
  readonly rgba32float: Vec4f;
179
229
  readonly bgra8unorm: Vec4f;
180
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;
181
239
  type TexelFormatToDataType = typeof texelFormatToDataType;
182
240
  type TexelFormatToDataTypeOrNever<T> = T extends keyof TexelFormatToDataType ? TexelFormatToDataType[T] : never;
183
241
  /**
@@ -362,18 +420,20 @@ interface TgpuBuffer$1<TData extends AnyData> extends TgpuNamable {
362
420
  readonly initial?: Infer<TData> | undefined;
363
421
  readonly label: string | undefined;
364
422
  readonly buffer: GPUBuffer;
365
- readonly device: GPUDevice;
366
423
  readonly destroyed: boolean;
367
- $usage<T extends ('uniform' | 'storage' | 'vertex')[]>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
424
+ $usage<T extends RestrictVertexUsages<TData>>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
368
425
  $addFlags(flags: GPUBufferUsageFlags): this;
369
- $device(device: GPUDevice): this;
370
- write(data: Infer<TData> | TgpuBuffer$1<TData>): void;
426
+ write(data: Infer<TData>): void;
427
+ copyFrom(srcBuffer: TgpuBuffer$1<TData>): void;
371
428
  read(): Promise<Infer<TData>>;
372
429
  destroy(): void;
373
430
  }
374
431
  declare function isBuffer<T extends TgpuBuffer$1<AnyData>>(value: T | unknown): value is T;
375
432
  declare function isUsableAsUniform<T extends TgpuBuffer$1<AnyData>>(buffer: T): buffer is T & Uniform;
376
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'[];
377
437
 
378
438
  interface TgpuBufferUsage<TData extends BaseWgslData, TUsage extends BindableBufferUsage = BindableBufferUsage> extends TgpuResolvable {
379
439
  readonly resourceType: 'buffer-usage';
@@ -451,7 +511,7 @@ type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
451
511
  externalTexture: Record<string, never>;
452
512
  };
453
513
  type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
454
- type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends BaseWgslData ? T : T extends (_: number) => infer Return ? Return : never;
514
+ type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends (_: number) => BaseWgslData ? ReturnType<T> : T;
455
515
  type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
456
516
  interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
457
517
  readonly resourceType: 'bind-group-layout';
@@ -466,6 +526,9 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
466
526
  * `.$idx()` method.
467
527
  */
468
528
  readonly index: number | undefined;
529
+ /**
530
+ * @deprecated Use the `root.createBindGroup` API instead, accessible through `await tgpu.init()`
531
+ */
469
532
  populate(entries: {
470
533
  [K in keyof OmitProps<Entries, null>]: LayoutEntryToInput<Entries[K]>;
471
534
  }): TgpuBindGroup<Entries>;
@@ -479,10 +542,29 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
479
542
  type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
480
543
  access?: infer Access;
481
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']>>;
482
- 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
483
- GPUTextureView | TgpuTexture : T extends TgpuLayoutStorageTexture ? // TODO: Allow storage usages here
484
- GPUTextureView | TgpuTexture : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
485
- type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform$1<UnwrapRuntimeConstructor<T['uniform']>> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : never;
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;
486
568
  type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
487
569
  readonly resourceType: 'bind-group';
488
570
  readonly layout: TgpuBindGroupLayout<Entries>;
@@ -496,7 +578,7 @@ type ExoticEntries<T extends Record<string, TgpuLayoutEntry | null>> = {
496
578
  };
497
579
  declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<ExoticEntries<Entries>>>;
498
580
 
499
- type Wgsl = string | number | boolean | TgpuResolvable | AnyWgslData;
581
+ type Wgsl = Eventual<string | number | boolean | TgpuResolvable | AnyWgslData>;
500
582
  declare const UnknownData: unique symbol;
501
583
  type UnknownData = typeof UnknownData;
502
584
  type Resource = {
@@ -531,12 +613,14 @@ interface ResolutionCtx {
531
613
  group: string;
532
614
  binding: number;
533
615
  };
616
+ withSlots<T>(pairs: SlotValuePair<unknown>[], callback: () => T): T;
534
617
  /**
535
- * Unwraps all layers of slot indirection and returns the concrete value if available.
618
+ * Unwraps all layers of slot/derived indirection and returns the concrete value if available.
536
619
  * @throws {MissingSlotValueError}
537
620
  */
538
621
  unwrap<T>(eventual: Eventual<T>): T;
539
- resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
622
+ resolve(item: Wgsl): string;
623
+ resolveValue<T extends BaseWgslData>(value: Infer<T>, schema: T): string;
540
624
  transpileFn(fn: string): {
541
625
  argNames: string[];
542
626
  body: Block;
@@ -551,23 +635,7 @@ interface TgpuResolvable {
551
635
  readonly label?: string | undefined;
552
636
  resolve(ctx: ResolutionCtx): string;
553
637
  }
554
- /**
555
- * Represents a value that is available at resolution time.
556
- */
557
- type Eventual<T> = T | TgpuSlot<T>;
558
- type SlotValuePair<T> = [TgpuSlot<T>, T];
559
638
  type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
560
- interface TgpuSlot<T> extends TgpuNamable {
561
- readonly __brand: 'TgpuSlot';
562
- readonly defaultValue: T | undefined;
563
- readonly label?: string | undefined;
564
- /**
565
- * Used to determine if code generated using either value `a` or `b` in place
566
- * of the slot will be equivalent. Defaults to `Object.is`.
567
- */
568
- areEqual(a: T, b: T): boolean;
569
- readonly value: Infer<T>;
570
- }
571
639
 
572
640
  interface TgpuResolveOptions {
573
641
  input: string | TgpuResolvable | AnyWgslData | (string | TgpuResolvable | AnyWgslData)[];
@@ -638,9 +706,9 @@ declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
638
706
  */
639
707
  declare class ResolutionError extends Error {
640
708
  readonly cause: unknown;
641
- readonly trace: (TgpuResolvable | AnyWgslData)[];
642
- constructor(cause: unknown, trace: (TgpuResolvable | AnyWgslData)[]);
643
- appendToTrace(ancestor: TgpuResolvable | AnyWgslData): ResolutionError;
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;
644
712
  }
645
713
  /**
646
714
  * @category Errors
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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, B as BaseWgslData, e as AnyWgslData } from './utilityTypes-NWbtoFu5.js';
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.js';
2
2
  import * as smol from 'tinyest';
3
3
  import { Block } from 'tinyest';
4
4
 
@@ -22,6 +22,32 @@ 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
+
25
51
  interface NameRegistry {
26
52
  /**
27
53
  * Creates a valid WGSL identifier, each guaranteed to be unique
@@ -34,7 +60,7 @@ interface NameRegistry {
34
60
  interface NotAllowed<TMsg> {
35
61
  reason: TMsg;
36
62
  }
37
- type ExtensionGuard<TFlag, TMsg, TAllowed> = boolean extends TFlag ? NotAllowed<TMsg> : TAllowed;
63
+ type ExtensionGuard<TFlag, TMsg, TAllowed> = boolean extends TFlag ? NotAllowed<TMsg> | TAllowed : TAllowed;
38
64
  interface Storage {
39
65
  usableAsStorage: true;
40
66
  }
@@ -155,6 +181,30 @@ declare const texelFormatToChannelType: {
155
181
  'astc-12x12-unorm-srgb': F32;
156
182
  };
157
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
+ };
158
208
  /**
159
209
  * https://www.w3.org/TR/WGSL/#storage-texel-formats
160
210
  */
@@ -178,6 +228,14 @@ declare const texelFormatToDataType: {
178
228
  readonly rgba32float: Vec4f;
179
229
  readonly bgra8unorm: Vec4f;
180
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;
181
239
  type TexelFormatToDataType = typeof texelFormatToDataType;
182
240
  type TexelFormatToDataTypeOrNever<T> = T extends keyof TexelFormatToDataType ? TexelFormatToDataType[T] : never;
183
241
  /**
@@ -362,18 +420,20 @@ interface TgpuBuffer$1<TData extends AnyData> extends TgpuNamable {
362
420
  readonly initial?: Infer<TData> | undefined;
363
421
  readonly label: string | undefined;
364
422
  readonly buffer: GPUBuffer;
365
- readonly device: GPUDevice;
366
423
  readonly destroyed: boolean;
367
- $usage<T extends ('uniform' | 'storage' | 'vertex')[]>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
424
+ $usage<T extends RestrictVertexUsages<TData>>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
368
425
  $addFlags(flags: GPUBufferUsageFlags): this;
369
- $device(device: GPUDevice): this;
370
- write(data: Infer<TData> | TgpuBuffer$1<TData>): void;
426
+ write(data: Infer<TData>): void;
427
+ copyFrom(srcBuffer: TgpuBuffer$1<TData>): void;
371
428
  read(): Promise<Infer<TData>>;
372
429
  destroy(): void;
373
430
  }
374
431
  declare function isBuffer<T extends TgpuBuffer$1<AnyData>>(value: T | unknown): value is T;
375
432
  declare function isUsableAsUniform<T extends TgpuBuffer$1<AnyData>>(buffer: T): buffer is T & Uniform;
376
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'[];
377
437
 
378
438
  interface TgpuBufferUsage<TData extends BaseWgslData, TUsage extends BindableBufferUsage = BindableBufferUsage> extends TgpuResolvable {
379
439
  readonly resourceType: 'buffer-usage';
@@ -451,7 +511,7 @@ type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
451
511
  externalTexture: Record<string, never>;
452
512
  };
453
513
  type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
454
- type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends BaseWgslData ? T : T extends (_: number) => infer Return ? Return : never;
514
+ type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends (_: number) => BaseWgslData ? ReturnType<T> : T;
455
515
  type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
456
516
  interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
457
517
  readonly resourceType: 'bind-group-layout';
@@ -466,6 +526,9 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
466
526
  * `.$idx()` method.
467
527
  */
468
528
  readonly index: number | undefined;
529
+ /**
530
+ * @deprecated Use the `root.createBindGroup` API instead, accessible through `await tgpu.init()`
531
+ */
469
532
  populate(entries: {
470
533
  [K in keyof OmitProps<Entries, null>]: LayoutEntryToInput<Entries[K]>;
471
534
  }): TgpuBindGroup<Entries>;
@@ -479,10 +542,29 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
479
542
  type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
480
543
  access?: infer Access;
481
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']>>;
482
- 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
483
- GPUTextureView | TgpuTexture : T extends TgpuLayoutStorageTexture ? // TODO: Allow storage usages here
484
- GPUTextureView | TgpuTexture : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
485
- type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform$1<UnwrapRuntimeConstructor<T['uniform']>> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : never;
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;
486
568
  type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
487
569
  readonly resourceType: 'bind-group';
488
570
  readonly layout: TgpuBindGroupLayout<Entries>;
@@ -496,7 +578,7 @@ type ExoticEntries<T extends Record<string, TgpuLayoutEntry | null>> = {
496
578
  };
497
579
  declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<ExoticEntries<Entries>>>;
498
580
 
499
- type Wgsl = string | number | boolean | TgpuResolvable | AnyWgslData;
581
+ type Wgsl = Eventual<string | number | boolean | TgpuResolvable | AnyWgslData>;
500
582
  declare const UnknownData: unique symbol;
501
583
  type UnknownData = typeof UnknownData;
502
584
  type Resource = {
@@ -531,12 +613,14 @@ interface ResolutionCtx {
531
613
  group: string;
532
614
  binding: number;
533
615
  };
616
+ withSlots<T>(pairs: SlotValuePair<unknown>[], callback: () => T): T;
534
617
  /**
535
- * Unwraps all layers of slot indirection and returns the concrete value if available.
618
+ * Unwraps all layers of slot/derived indirection and returns the concrete value if available.
536
619
  * @throws {MissingSlotValueError}
537
620
  */
538
621
  unwrap<T>(eventual: Eventual<T>): T;
539
- resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
622
+ resolve(item: Wgsl): string;
623
+ resolveValue<T extends BaseWgslData>(value: Infer<T>, schema: T): string;
540
624
  transpileFn(fn: string): {
541
625
  argNames: string[];
542
626
  body: Block;
@@ -551,23 +635,7 @@ interface TgpuResolvable {
551
635
  readonly label?: string | undefined;
552
636
  resolve(ctx: ResolutionCtx): string;
553
637
  }
554
- /**
555
- * Represents a value that is available at resolution time.
556
- */
557
- type Eventual<T> = T | TgpuSlot<T>;
558
- type SlotValuePair<T> = [TgpuSlot<T>, T];
559
638
  type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
560
- interface TgpuSlot<T> extends TgpuNamable {
561
- readonly __brand: 'TgpuSlot';
562
- readonly defaultValue: T | undefined;
563
- readonly label?: string | undefined;
564
- /**
565
- * Used to determine if code generated using either value `a` or `b` in place
566
- * of the slot will be equivalent. Defaults to `Object.is`.
567
- */
568
- areEqual(a: T, b: T): boolean;
569
- readonly value: Infer<T>;
570
- }
571
639
 
572
640
  interface TgpuResolveOptions {
573
641
  input: string | TgpuResolvable | AnyWgslData | (string | TgpuResolvable | AnyWgslData)[];
@@ -638,9 +706,9 @@ declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
638
706
  */
639
707
  declare class ResolutionError extends Error {
640
708
  readonly cause: unknown;
641
- readonly trace: (TgpuResolvable | AnyWgslData)[];
642
- constructor(cause: unknown, trace: (TgpuResolvable | AnyWgslData)[]);
643
- appendToTrace(ancestor: TgpuResolvable | AnyWgslData): ResolutionError;
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;
644
712
  }
645
713
  /**
646
714
  * @category Errors