typegpu 0.3.4 → 0.4.0

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,5 +1,5 @@
1
- import { A as AnyWgslData, I as Infer, D as Decorated, 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, n as AnyWgslStruct, o as AnyData, B as BaseWgslData, L as Location, W as WgslArray, p as Disarray, K as KindToAcceptedAttribMap, q as Unstruct, r as VertexFormat, T as TgpuVertexAttrib, s as KindToDefaultFormatMap, M as MemIdentity, t as WgslTypeLiteral, u as AnyVecInstance, v as AnyMatInstance } from './wgslTypes-DHAmU620.js';
2
- import { T as TgpuNamable, E as Exotic, A as AnyAttribute, a as AnyComputeBuiltin, D as Default, U as UnionToIntersection, b as Decorate, c as TgpuStruct, I as IsBuiltin, H as HasCustomLocation, O as OmitBuiltins, d as OmitProps, P as Prettify, M as Mutable, e as Infer$1, f as ExoticArray } from './index-FeXoGB17.js';
1
+ import { A as AnyWgslData, T as TgpuNamable, I as Infer, D as Decorated, 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, n as AnyWgslStruct, o as Default, p as UnionToIntersection, W as WgslArray, q as Disarray, K as KindToAcceptedAttribMap, r as Unstruct, s as VertexFormat, t as TgpuVertexAttrib, u as KindToDefaultFormatMap, v as AnyData, B as BaseData, L as Location, w as WgslStruct, O as OmitProps, P as Prettify, M as Mutable, x as InferPartial, y as MemIdentity, z as WgslTypeLiteral, C as AnyVecInstance, E as AnyMatInstance } from './wgslTypes-BNsjCP--.js';
2
+ import { A as AnyAttribute, a as AnyComputeBuiltin, D as Decorate, I as IsBuiltin, H as HasCustomLocation, O as OmitBuiltins, B as BuiltinSampleMask, b as BuiltinFragDepth } from './attributes-BQuRnaZ4.js';
3
3
  import * as smol from 'tinyest';
4
4
  import { Block } from 'tinyest';
5
5
 
@@ -10,7 +10,7 @@ interface TgpuConst<TDataType extends AnyWgslData = AnyWgslData> extends TgpuNam
10
10
  /**
11
11
  * Creates a module constant with specified value.
12
12
  */
13
- declare function constant<TDataType extends AnyWgslData>(dataType: Exotic<TDataType>, value: Infer<Exotic<TDataType>>): TgpuConst<Exotic<TDataType>>;
13
+ declare function constant<TDataType extends AnyWgslData>(dataType: TDataType, value: Infer<TDataType>): TgpuConst<TDataType>;
14
14
 
15
15
  /**
16
16
  * Extra declaration that shall be included in final WGSL code,
@@ -56,11 +56,6 @@ type InferIO<T> = T extends {
56
56
  } ? Infer<T> : T extends Record<string, unknown> ? {
57
57
  [K in keyof T]: Infer<T[K]>;
58
58
  } : T;
59
- type ExoticIO<T> = T extends {
60
- type: string;
61
- } ? Exotic<T> : T extends Record<string, unknown> ? {
62
- [K in keyof T]: Exotic<T[K]>;
63
- } : T;
64
59
 
65
60
  /**
66
61
  * Describes a compute entry function signature (its arguments and return type)
@@ -369,7 +364,7 @@ declare function isUsableAsSampled<T>(value: T): value is T & Sampled;
369
364
  declare function isUsableAsRender<T>(value: T): value is T & Render;
370
365
 
371
366
  type ResolveStorageDimension<TDimension extends GPUTextureViewDimension, TProps extends TextureProps> = StorageTextureDimension extends TDimension ? Default<TProps['dimension'], '2d'> : TDimension extends StorageTextureDimension ? TDimension : '2d';
372
- type ViewUsages<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';
367
+ 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';
373
368
  type ChannelData = U32 | I32 | F32;
374
369
  type TexelData = Vec4u | Vec4i | Vec4f;
375
370
  /**
@@ -383,7 +378,7 @@ interface TgpuTexture<TProps extends TextureProps = TextureProps> extends TgpuNa
383
378
  readonly usableAsSampled: boolean;
384
379
  readonly usableAsRender: boolean;
385
380
  $usage<T extends AllowedUsages<TProps>[]>(...usages: T): this & UnionToIntersection<LiteralToExtensionMap[T[number]]>;
386
- createView<TUsage extends ViewUsages<TProps, this>, TDimension extends 'sampled' extends TUsage ? GPUTextureViewDimension : StorageTextureDimension, TFormat extends 'sampled' extends TUsage ? SampledFormatOptions<TProps> : StorageFormatOptions<TProps>>(access: TUsage, params?: TextureViewParams<TDimension, TFormat>): {
381
+ 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>): {
387
382
  mutable: TgpuMutableTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
388
383
  readonly: TgpuReadonlyTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
389
384
  writeonly: TgpuWriteonlyTexture<ResolveStorageDimension<TDimension, TProps>, TexelFormatToDataTypeOrNever<StorageFormatOptions<TProps> extends TFormat ? TProps['format'] : TFormat>>;
@@ -443,26 +438,64 @@ declare function isStorageTextureView<T extends TgpuReadonlyTexture | TgpuWriteo
443
438
  declare function isSampledTextureView<T extends TgpuSampledTexture>(value: unknown | T): value is T;
444
439
  type TgpuAnyTextureView = TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture | TgpuSampledTexture;
445
440
 
441
+ /**
442
+ * The array can hold T, where T is a single/multi-component numeric, or a struct with members of type T.
443
+ * Examples of valid array members:
444
+ * - Vec3f,
445
+ * - unorm8x2
446
+ * - WgslStruct<{ a: Vec3f, b: unorm8x2 }>
447
+ * - WgslStruct<{ nested: WgslStruct<{ a: Vec3f }> }>
448
+ */
449
+ type DataToContainedAttribs<T> = T extends AnyWgslStruct | Unstruct ? {
450
+ [Key in keyof T['propTypes']]: DataToContainedAttribs<T['propTypes'][Key]>;
451
+ } : T extends {
452
+ type: VertexFormat;
453
+ } ? TgpuVertexAttrib<T['type']> : T extends {
454
+ type: keyof KindToDefaultFormatMap;
455
+ } ? TgpuVertexAttrib<KindToDefaultFormatMap[T['type']]> : never;
456
+ /**
457
+ * Interprets an array as a set of vertex attributes.
458
+ */
459
+ type ArrayToContainedAttribs<T extends WgslArray | Disarray> = DataToContainedAttribs<T['elementType']>;
460
+ type LayoutToAllowedAttribs<T> = T extends {
461
+ type: keyof KindToAcceptedAttribMap;
462
+ } ? KindToAcceptedAttribMap[T['type']] : T extends Record<string, unknown> ? {
463
+ [Key in keyof T]: LayoutToAllowedAttribs<T[Key]>;
464
+ } : never;
465
+
466
+ interface TgpuVertexLayout<TData extends WgslArray | Disarray = WgslArray | Disarray> extends TgpuNamable, Labelled {
467
+ readonly resourceType: 'vertex-layout';
468
+ readonly stride: number;
469
+ readonly stepMode: 'vertex' | 'instance';
470
+ readonly attrib: ArrayToContainedAttribs<TData>;
471
+ readonly vertexLayout: GPUVertexBufferLayout;
472
+ schemaForCount(n: number): TData;
473
+ }
474
+ declare function vertexLayout<TData extends WgslArray | Disarray>(schemaForCount: (count: number) => TData, stepMode?: 'vertex' | 'instance'): TgpuVertexLayout<TData>;
475
+
446
476
  interface Unwrapper {
447
477
  readonly device: GPUDevice;
448
478
  unwrap(resource: TgpuComputePipeline): GPUComputePipeline;
449
479
  unwrap(resource: TgpuBindGroupLayout): GPUBindGroupLayout;
450
480
  unwrap(resource: TgpuBindGroup): GPUBindGroup;
451
- unwrap(resource: TgpuBuffer$1<AnyData>): GPUBuffer;
481
+ unwrap(resource: TgpuBuffer<AnyData>): GPUBuffer;
452
482
  unwrap(resource: TgpuTexture): GPUTexture;
453
483
  unwrap(resource: TgpuReadonlyTexture | TgpuWriteonlyTexture | TgpuMutableTexture | TgpuSampledTexture): GPUTextureView;
484
+ unwrap(resource: TgpuVertexLayout): GPUVertexBufferLayout;
454
485
  }
455
486
 
456
487
  type WithLocations<T extends IORecord> = {
457
488
  [Key in keyof T]: IsBuiltin<T[Key]> extends true ? T[Key] : HasCustomLocation<T[Key]> extends true ? T[Key] : Decorate<T[Key], Location<number>>;
458
489
  };
459
- type IOLayoutToSchema<T extends IOLayout> = T extends BaseWgslData ? Decorate<T, Location<0>> : T extends IORecord ? TgpuStruct<WithLocations<T>> : never;
490
+ type IOLayoutToSchema<T extends IOLayout> = T extends BaseData ? Decorate<T, Location<0>> : T extends IORecord ? WgslStruct<WithLocations<T>> : never;
460
491
 
492
+ type FragmentOutConstrained = Vec4f | Decorated<Vec4f, [Location<number>]> | BuiltinSampleMask | BuiltinFragDepth | IORecord<Vec4f | Decorated<Vec4f, [Location<number>]> | BuiltinSampleMask | BuiltinFragDepth>;
461
493
  /**
462
494
  * Describes a fragment entry function signature (its arguments and return type)
463
495
  */
464
- interface TgpuFragmentFnShell<FragmentIn extends IOLayout, FragmentOut extends IOLayout<Vec4f>> {
465
- readonly argTypes: [FragmentIn];
496
+ interface TgpuFragmentFnShell<FragmentIn extends IOLayout, FragmentOut extends FragmentOutConstrained> {
497
+ readonly argTypes: [AnyWgslStruct];
498
+ readonly targets: FragmentOut;
466
499
  readonly returnType: FragmentOut;
467
500
  /**
468
501
  * Creates a type-safe implementation of this signature
@@ -476,7 +509,7 @@ interface TgpuFragmentFnShell<FragmentIn extends IOLayout, FragmentOut extends I
476
509
  */
477
510
  does(implementation: string): TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>;
478
511
  }
479
- interface TgpuFragmentFn<Varying extends IOLayout = IOLayout, Output extends IOLayout<Vec4f> = IOLayout<Vec4f>> extends TgpuNamable {
512
+ interface TgpuFragmentFn<Varying extends IOLayout = IOLayout, Output extends FragmentOutConstrained = FragmentOutConstrained> extends TgpuNamable {
480
513
  readonly shell: TgpuFragmentFnShell<Varying, Output>;
481
514
  readonly outputType: IOLayoutToSchema<Output>;
482
515
  $uses(dependencyMap: Record<string, unknown>): this;
@@ -493,7 +526,7 @@ interface TgpuFragmentFn<Varying extends IOLayout = IOLayout, Output extends IOL
493
526
  * A `vec4f`, signaling this function outputs a color for one target, or a struct/array containing
494
527
  * colors for multiple targets.
495
528
  */
496
- declare function fragmentFn<FragmentIn extends IORecord, FragmentOut extends IOLayout<Vec4f>>(inputType: FragmentIn, outputType: FragmentOut): TgpuFragmentFnShell<ExoticIO<FragmentIn>, ExoticIO<FragmentOut>>;
529
+ declare function fragmentFn<FragmentIn extends IORecord, FragmentOut extends FragmentOutConstrained>(inputType: FragmentIn, outputType: FragmentOut): TgpuFragmentFnShell<FragmentIn, FragmentOut>;
497
530
 
498
531
  /**
499
532
  * Describes a vertex entry function signature (its arguments and return type)
@@ -531,46 +564,12 @@ interface TgpuVertexFn<VertexIn extends IOLayout = IOLayout, VertexOut extends I
531
564
  * A struct type containing the final position of the vertex, and any information
532
565
  * passed onto the fragment shader stage.
533
566
  */
534
- declare function vertexFn<VertexIn extends IORecord, VertexOut extends IORecord>(inputType: VertexIn, outputType: VertexOut): TgpuVertexFnShell<ExoticIO<VertexIn>, ExoticIO<VertexOut>>;
535
-
536
- /**
537
- * The array can hold T, where T is a single/multi-component numeric, or a struct with members of type T.
538
- * Examples of valid array members:
539
- * - Vec3f,
540
- * - unorm8x2
541
- * - TgpuStruct<{ a: Vec3f, b: unorm8x2 }>
542
- * - TgpuStruct<{ nested: TgpuStruct<{ a: Vec3f }> }>
543
- */
544
- type DataToContainedAttribs<T> = T extends AnyWgslStruct | Unstruct ? {
545
- [Key in keyof T['propTypes']]: DataToContainedAttribs<T['propTypes'][Key]>;
546
- } : T extends {
547
- type: VertexFormat;
548
- } ? TgpuVertexAttrib<T['type']> : T extends {
549
- type: keyof KindToDefaultFormatMap;
550
- } ? TgpuVertexAttrib<KindToDefaultFormatMap[T['type']]> : never;
551
- /**
552
- * Interprets an array as a set of vertex attributes.
553
- */
554
- type ArrayToContainedAttribs<T extends WgslArray | Disarray> = DataToContainedAttribs<T['elementType']>;
555
- type LayoutToAllowedAttribs<T> = T extends {
556
- type: keyof KindToAcceptedAttribMap;
557
- } ? KindToAcceptedAttribMap[T['type']] : T extends Record<string, unknown> ? {
558
- [Key in keyof T]: LayoutToAllowedAttribs<T[Key]>;
559
- } : never;
560
-
561
- interface TgpuVertexLayout<TData extends WgslArray | Disarray = WgslArray | Disarray> extends TgpuNamable, Labelled {
562
- readonly resourceType: 'vertex-layout';
563
- readonly stride: number;
564
- readonly stepMode: 'vertex' | 'instance';
565
- readonly attrib: ArrayToContainedAttribs<TData>;
566
- schemaForCount(n: number): TData;
567
- }
568
- declare function vertexLayout<TData extends WgslArray | Disarray>(schemaForCount: (count: number) => TData, stepMode?: 'vertex' | 'instance'): TgpuVertexLayout<ExoticIO<TData>>;
567
+ declare function vertexFn<VertexIn extends IORecord, VertexOut extends IORecord>(inputType: VertexIn, outputType: VertexOut): TgpuVertexFnShell<VertexIn, VertexOut>;
569
568
 
570
569
  interface TgpuRenderPipeline<Output extends IOLayout = IOLayout> extends TgpuNamable {
571
570
  readonly resourceType: 'render-pipeline';
572
571
  readonly label: string | undefined;
573
- with<TData extends WgslArray | Disarray>(vertexLayout: TgpuVertexLayout<TData>, buffer: TgpuBuffer$1<TData> & Vertex): TgpuRenderPipeline<IOLayout>;
572
+ with<TData extends WgslArray | Disarray>(vertexLayout: TgpuVertexLayout<TData>, buffer: TgpuBuffer<TData> & Vertex): TgpuRenderPipeline<IOLayout>;
574
573
  with<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries>): TgpuRenderPipeline<IOLayout>;
575
574
  withColorAttachment(attachment: FragmentOutToColorAttachment<Output>): TgpuRenderPipeline<IOLayout>;
576
575
  withDepthStencilAttachment(attachment: DepthStencilAttachment): TgpuRenderPipeline<IOLayout>;
@@ -677,7 +676,7 @@ interface DepthStencilAttachment {
677
676
  interface WithCompute {
678
677
  createPipeline(): TgpuComputePipeline;
679
678
  }
680
- type ValidateFragmentIn<VertexOut extends IORecord, FragmentIn extends IORecord, FragmentOut extends IOLayout<Vec4f>> = FragmentIn extends Partial<VertexOut> ? VertexOut extends FragmentIn ? [
679
+ type ValidateFragmentIn<VertexOut extends IORecord, FragmentIn extends IORecord, FragmentOut extends FragmentOutConstrained> = FragmentIn extends Partial<VertexOut> ? VertexOut extends FragmentIn ? [
681
680
  entryFn: TgpuFragmentFn<FragmentIn, FragmentOut>,
682
681
  targets: FragmentOutToTargets<FragmentOut>
683
682
  ] : [
@@ -694,9 +693,9 @@ type ValidateFragmentIn<VertexOut extends IORecord, FragmentIn extends IORecord,
694
693
  }
695
694
  ];
696
695
  interface WithVertex<VertexOut extends IORecord = IORecord> {
697
- withFragment<FragmentIn extends IORecord, FragmentOut extends IOLayout<Vec4f>>(...args: ValidateFragmentIn<VertexOut, FragmentIn, FragmentOut>): WithFragment<FragmentOut>;
696
+ withFragment<FragmentIn extends IORecord, FragmentOut extends FragmentOutConstrained>(...args: ValidateFragmentIn<VertexOut, FragmentIn, FragmentOut>): WithFragment<FragmentOut>;
698
697
  }
699
- interface WithFragment<Output extends IOLayout<Vec4f> = IOLayout<Vec4f>> {
698
+ interface WithFragment<Output extends FragmentOutConstrained = FragmentOutConstrained> {
700
699
  withPrimitive(primitiveState: GPUPrimitiveState | undefined): WithFragment<Output>;
701
700
  withDepthStencil(depthStencilState: GPUDepthStencilState | undefined): WithFragment<Output>;
702
701
  createPipeline(): TgpuRenderPipeline<Output>;
@@ -761,7 +760,7 @@ interface TgpuRoot extends Unwrapper {
761
760
  * @param typeSchema The type of data that this buffer will hold.
762
761
  * @param initial The initial value of the buffer. (optional)
763
762
  */
764
- createBuffer<TData extends AnyData>(typeSchema: TData, initial?: Infer<Exotic<TData>> | undefined): TgpuBuffer$1<Exotic<TData>>;
763
+ createBuffer<TData extends AnyData>(typeSchema: TData, initial?: Infer<TData> | undefined): TgpuBuffer<TData>;
765
764
  /**
766
765
  * Allocates memory on the GPU, allows passing data between host and shader.
767
766
  *
@@ -771,7 +770,7 @@ interface TgpuRoot extends Unwrapper {
771
770
  * @param typeSchema The type of data that this buffer will hold.
772
771
  * @param gpuBuffer A vanilla WebGPU buffer.
773
772
  */
774
- createBuffer<TData extends AnyData>(typeSchema: TData, gpuBuffer: GPUBuffer): TgpuBuffer$1<Exotic<TData>>;
773
+ createBuffer<TData extends AnyData>(typeSchema: TData, gpuBuffer: GPUBuffer): TgpuBuffer<TData>;
775
774
  /**
776
775
  * Creates a group of resources that can be bound to a shader based on a specified layout.
777
776
  *
@@ -815,6 +814,9 @@ interface ExperimentalTgpuRoot extends TgpuRoot, WithBinding {
815
814
  * hold the same value until `flush()` is called.
816
815
  */
817
816
  readonly commandEncoder: GPUCommandEncoder;
817
+ createUniform<TData extends AnyWgslData>(typeSchema: TData, initialOrBuffer?: Infer<TData> | GPUBuffer): TgpuBufferUniform<TData> & TgpuFixedBufferUsage<TData>;
818
+ createMutable<TData extends AnyWgslData>(typeSchema: TData, initialOrBuffer?: Infer<TData> | GPUBuffer): TgpuBufferMutable<TData> & TgpuFixedBufferUsage<TData>;
819
+ createReadonly<TData extends AnyWgslData>(typeSchema: TData, initialOrBuffer?: Infer<TData> | GPUBuffer): TgpuBufferReadonly<TData> & TgpuFixedBufferUsage<TData>;
818
820
  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>>;
819
821
  /**
820
822
  * Causes all commands enqueued by pipelines to be
@@ -826,30 +828,38 @@ interface ExperimentalTgpuRoot extends TgpuRoot, WithBinding {
826
828
  interface Uniform {
827
829
  usableAsUniform: true;
828
830
  }
829
- declare const Uniform: Uniform;
830
831
  interface Vertex {
831
832
  usableAsVertex: true;
832
833
  }
833
- declare const Vertex: Vertex;
834
834
  type LiteralToUsageType<T extends 'uniform' | 'storage' | 'vertex'> = T extends 'uniform' ? Uniform : T extends 'storage' ? Storage : T extends 'vertex' ? Vertex : never;
835
- interface TgpuBuffer$1<TData extends AnyData> extends TgpuNamable {
835
+ type ViewUsages<TBuffer extends TgpuBuffer<BaseData>> = (boolean extends TBuffer['usableAsUniform'] ? never : 'uniform') | (boolean extends TBuffer['usableAsStorage'] ? never : 'readonly' | 'mutable');
836
+ type UsageTypeToBufferUsage<TData extends BaseData> = {
837
+ uniform: TgpuBufferUniform<TData> & TgpuFixedBufferUsage<TData>;
838
+ mutable: TgpuBufferMutable<TData> & TgpuFixedBufferUsage<TData>;
839
+ readonly: TgpuBufferReadonly<TData> & TgpuFixedBufferUsage<TData>;
840
+ };
841
+ interface TgpuBuffer<TData extends BaseData> extends TgpuNamable {
836
842
  readonly resourceType: 'buffer';
837
843
  readonly dataType: TData;
838
844
  readonly initial?: Infer<TData> | undefined;
839
845
  readonly label: string | undefined;
840
846
  readonly buffer: GPUBuffer;
841
847
  readonly destroyed: boolean;
848
+ usableAsUniform: boolean;
849
+ usableAsStorage: boolean;
850
+ usableAsVertex: boolean;
842
851
  $usage<T extends RestrictVertexUsages<TData>>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
843
852
  $addFlags(flags: GPUBufferUsageFlags): this;
853
+ as<T extends ViewUsages<this>>(usage: T): UsageTypeToBufferUsage<TData>[T];
844
854
  write(data: Infer<TData>): void;
845
- copyFrom(srcBuffer: TgpuBuffer$1<MemIdentity<TData>>): void;
855
+ writePartial(data: InferPartial<TData>): void;
856
+ copyFrom(srcBuffer: TgpuBuffer<MemIdentity<TData>>): void;
846
857
  read(): Promise<Infer<TData>>;
847
858
  destroy(): void;
848
859
  }
849
- declare function isBuffer<T extends TgpuBuffer$1<AnyData>>(value: T | unknown): value is T;
850
- declare function isUsableAsUniform<T extends TgpuBuffer$1<AnyData>>(buffer: T): buffer is T & Uniform;
851
- declare function isUsableAsVertex<T extends TgpuBuffer$1<AnyData>>(buffer: T): buffer is T & Vertex;
852
- type RestrictVertexUsages<TData extends AnyData> = TData extends {
860
+ declare function isBuffer<T extends TgpuBuffer<AnyData>>(value: T | unknown): value is T;
861
+ declare function isUsableAsVertex<T extends TgpuBuffer<AnyData>>(buffer: T): buffer is T & Vertex;
862
+ type RestrictVertexUsages<TData extends BaseData> = TData extends {
853
863
  readonly type: WgslTypeLiteral;
854
864
  } ? ('uniform' | 'storage' | 'vertex')[] : 'vertex'[];
855
865
 
@@ -1002,7 +1012,7 @@ type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
1002
1012
  externalTexture: Record<string, never>;
1003
1013
  };
1004
1014
  type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutComparisonSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
1005
- type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends (_: number) => BaseWgslData ? ReturnType<T> : T;
1015
+ type UnwrapRuntimeConstructorInner<T extends BaseData | ((_: number) => BaseData)> = T extends (_: number) => BaseData ? ReturnType<T> : T;
1006
1016
  type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
1007
1017
  interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
1008
1018
  readonly resourceType: 'bind-group-layout';
@@ -1039,7 +1049,7 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
1039
1049
  }
1040
1050
  type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
1041
1051
  access?: infer Access;
1042
- } ? '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']>>;
1052
+ } ? 'mutable' | 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : 'readonly' extends Access ? TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> : 'mutable' extends Access ? TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>> | TgpuBufferMutable<UnwrapRuntimeConstructor<T['storage']>> : TgpuBufferReadonly<UnwrapRuntimeConstructor<T['storage']>>;
1043
1053
  type GetUsageForStorageTexture<T extends TgpuLayoutStorageTexture, TAccess extends 'readonly' | 'writeonly' | 'mutable'> = {
1044
1054
  mutable: TgpuMutableTexture<Default<GetDimension<T['viewDimension']>, '2d'>, TexelFormatToDataType[T['storageTexture']]>;
1045
1055
  readonly: TgpuReadonlyTexture<Default<GetDimension<T['viewDimension']>, '2d'>, TexelFormatToDataType[T['storageTexture']]>;
@@ -1061,38 +1071,46 @@ type GetStorageTextureRestriction<T extends TgpuLayoutStorageTexture> = Default<
1061
1071
  format: T['storageTexture'];
1062
1072
  dimension: Dimension;
1063
1073
  } : never;
1064
- 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 ? TgpuSampler | GPUSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler | GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | (Sampled & TgpuTexture<Prettify<TextureProps & GetTextureRestriction<T>>>) : T extends TgpuLayoutStorageTexture ? GPUTextureView | (Storage & TgpuTexture<Prettify<TextureProps & GetStorageTextureRestriction<T>>>) : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
1065
- 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 TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<GetDimension<T['viewDimension']>, '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
1074
+ type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? (TgpuBuffer<UnwrapRuntimeConstructor<T['uniform']>> & Uniform) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer<UnwrapRuntimeConstructor<T['storage']>> & Storage) | GPUBuffer : T extends TgpuLayoutSampler ? TgpuSampler | GPUSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler | GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | (Sampled & TgpuTexture<Prettify<TextureProps & GetTextureRestriction<T>>>) : T extends TgpuLayoutStorageTexture ? GPUTextureView | (Storage & TgpuTexture<Prettify<TextureProps & GetStorageTextureRestriction<T>>>) : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
1075
+ type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<UnwrapRuntimeConstructor<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;
1066
1076
  type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
1067
1077
  readonly resourceType: 'bind-group';
1068
1078
  readonly layout: TgpuBindGroupLayout<Entries>;
1069
1079
  unwrap(unwrapper: Unwrapper): GPUBindGroup;
1070
1080
  };
1071
- type ExoticEntry<T> = T extends Record<string | number | symbol, unknown> ? {
1072
- [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];
1073
- } : T;
1074
- type ExoticEntries<T extends Record<string, TgpuLayoutEntry | null>> = {
1075
- [BindingKey in keyof T]: ExoticEntry<T[BindingKey]>;
1076
- };
1077
- declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<ExoticEntries<Entries>>>;
1081
+ declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<Entries>>;
1078
1082
 
1079
- interface TgpuBufferUsage<TData extends BaseWgslData = BaseWgslData, TUsage extends BindableBufferUsage = BindableBufferUsage> {
1083
+ interface TgpuBufferUsage<TData extends BaseData = BaseData, TUsage extends BindableBufferUsage = BindableBufferUsage> {
1080
1084
  readonly resourceType: 'buffer-usage';
1081
1085
  readonly usage: TUsage;
1082
1086
  readonly '~repr': Infer<TData>;
1083
1087
  value: Infer<TData>;
1084
1088
  }
1085
- interface TgpuBufferUniform$1<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'uniform'> {
1089
+ interface TgpuBufferUniform<TData extends BaseData> extends TgpuBufferUsage<TData, 'uniform'> {
1086
1090
  readonly value: Infer<TData>;
1087
1091
  }
1088
- interface TgpuBufferReadonly$1<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'readonly'> {
1092
+ interface TgpuBufferReadonly<TData extends BaseData> extends TgpuBufferUsage<TData, 'readonly'> {
1089
1093
  readonly value: Infer<TData>;
1090
1094
  }
1091
- interface TgpuBufferMutable$1<TData extends BaseWgslData> extends TgpuBufferUsage<TData, 'mutable'> {
1095
+ interface TgpuFixedBufferUsage<TData extends BaseData> extends TgpuNamable {
1096
+ readonly buffer: TgpuBuffer<TData>;
1097
+ write(data: Infer<TData>): void;
1098
+ }
1099
+ interface TgpuBufferMutable<TData extends BaseData> extends TgpuBufferUsage<TData, 'mutable'> {
1092
1100
  }
1093
- declare function asMutable<TData extends AnyWgslData>(buffer: TgpuBuffer$1<TData> & Storage): TgpuBufferMutable$1<TData>;
1094
- declare function asReadonly<TData extends AnyWgslData>(buffer: TgpuBuffer$1<TData> & Storage): TgpuBufferReadonly$1<TData>;
1095
- declare function asUniform<TData extends AnyWgslData>(buffer: TgpuBuffer$1<TData> & Uniform): TgpuBufferUniform$1<TData>;
1101
+ declare function isUsableAsUniform<T extends TgpuBuffer<AnyData>>(buffer: T): buffer is T & Uniform;
1102
+ /**
1103
+ * @deprecated Use buffer.as('mutable') instead.
1104
+ */
1105
+ declare function asMutable<TData extends AnyWgslData>(buffer: TgpuBuffer<TData> & Storage): TgpuBufferMutable<TData> & TgpuFixedBufferUsage<TData>;
1106
+ /**
1107
+ * @deprecated Use buffer.as('readonly') instead.
1108
+ */
1109
+ declare function asReadonly<TData extends AnyWgslData>(buffer: TgpuBuffer<TData> & Storage): TgpuBufferReadonly<TData> & TgpuFixedBufferUsage<TData>;
1110
+ /**
1111
+ * @deprecated Use buffer.as('uniform') instead.
1112
+ */
1113
+ declare function asUniform<TData extends AnyWgslData>(buffer: TgpuBuffer<TData> & Uniform): TgpuBufferUniform<TData> & TgpuFixedBufferUsage<TData>;
1096
1114
 
1097
1115
  interface TgpuExternalTexture {
1098
1116
  readonly resourceType: 'external-texture';
@@ -1109,7 +1127,7 @@ interface TgpuVar<TScope extends VariableScope = VariableScope, TDataType extend
1109
1127
  * @param dataType The schema of the held data's type
1110
1128
  * @param initialValue If not provided, the variable will be initialized to the dataType's "zero-value".
1111
1129
  */
1112
- declare function privateVar<TDataType extends AnyWgslData>(dataType: Exotic<TDataType>, initialValue?: Infer<Exotic<TDataType>>): TgpuVar<'private', Exotic<TDataType>>;
1130
+ declare function privateVar<TDataType extends AnyWgslData>(dataType: TDataType, initialValue?: Infer<TDataType>): TgpuVar<'private', TDataType>;
1113
1131
  /**
1114
1132
  * Defines a variable scoped to the whole workgroup, shared between entry functions
1115
1133
  * of the same invocation.
@@ -1118,7 +1136,7 @@ declare function privateVar<TDataType extends AnyWgslData>(dataType: Exotic<TDat
1118
1136
  */
1119
1137
  declare function workgroupVar<TDataType extends AnyWgslData>(dataType: TDataType): TgpuVar<'workgroup', TDataType>;
1120
1138
 
1121
- type ResolvableObject = SelfResolvable | TgpuBufferUsage | TgpuConst | TgpuDeclare | TgpuFn | TgpuComputeFn | TgpuFragmentFn | TgpuComputePipeline | TgpuRenderPipeline | TgpuVertexFn | TgpuSampler | TgpuAccessor | TgpuExternalTexture | TgpuTexture | TgpuAnyTextureView | TgpuVar | AnyVecInstance | AnyMatInstance | AnyWgslData | TgpuFn<any, any>;
1139
+ type ResolvableObject = SelfResolvable | TgpuBufferUsage | TgpuConst | TgpuDeclare | TgpuFn | TgpuComputeFn | TgpuFragmentFn | TgpuComputePipeline | TgpuRenderPipeline | TgpuVertexFn | TgpuSampler | TgpuAccessor | TgpuExternalTexture | TgpuTexture | TgpuAnyTextureView | TgpuVar | AnyVecInstance | AnyMatInstance | AnyData | TgpuFn<any, any>;
1122
1140
  type Wgsl = Eventual<string | number | boolean | ResolvableObject>;
1123
1141
  declare const UnknownData: unique symbol;
1124
1142
  type UnknownData = typeof UnknownData;
@@ -1161,7 +1179,7 @@ interface ResolutionCtx {
1161
1179
  */
1162
1180
  unwrap<T>(eventual: Eventual<T>): T;
1163
1181
  resolve(item: unknown): string;
1164
- resolveValue<T extends BaseWgslData>(value: Infer<T>, schema: T): string;
1182
+ resolveValue<T extends BaseData>(value: Infer<T>, schema: T): string;
1165
1183
  transpileFn(fn: string): {
1166
1184
  argNames: string[];
1167
1185
  body: Block;
@@ -1210,11 +1228,11 @@ interface TgpuFnBase<Args extends AnyWgslData[], Return extends AnyWgslData | un
1210
1228
  readonly '~providing'?: Providing | undefined;
1211
1229
  $uses(dependencyMap: Record<string, unknown>): this;
1212
1230
  with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TgpuFn<Args, Return>;
1213
- with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer$1<T>): TgpuFn<Args, Return>;
1231
+ with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): TgpuFn<Args, Return>;
1214
1232
  }
1215
1233
  type TgpuFn<Args extends AnyWgslData[] = AnyWgslData[], Return extends AnyWgslData | undefined = AnyWgslData | undefined> = TgpuFnBase<Args, Return> & ((...args: InferArgs<Args>) => InferReturn<Return>);
1216
- declare function fn<Args extends AnyWgslData[] | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<ExoticArray<Args>, undefined>;
1217
- declare function fn<Args extends AnyWgslData[] | [], Return extends AnyWgslData>(argTypes: Args, returnType: Return): TgpuFnShell<ExoticArray<Args>, Exotic<Return>>;
1234
+ declare function fn<Args extends AnyWgslData[] | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, undefined>;
1235
+ declare function fn<Args extends AnyWgslData[] | [], Return extends AnyWgslData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
1218
1236
  declare function isTgpuFn<Args extends AnyWgslData[], Return extends AnyWgslData | undefined = undefined>(value: unknown | TgpuFn<Args, Return>): value is TgpuFn<Args, Return>;
1219
1237
 
1220
1238
  interface TgpuResolveOptions {
@@ -1324,7 +1342,7 @@ declare function init(options?: InitOptions): Promise<TgpuRoot>;
1324
1342
  */
1325
1343
  declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
1326
1344
 
1327
- declare function accessor<T extends AnyWgslData>(schema: T, defaultValue?: TgpuFn<[], Exotic<T>> | TgpuBufferUsage<Exotic<T>> | Infer<Exotic<T>>): TgpuAccessor<Exotic<T>>;
1345
+ declare function accessor<T extends AnyWgslData>(schema: T, defaultValue?: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): TgpuAccessor<T>;
1328
1346
 
1329
1347
  declare function derived<T>(compute: () => T): TgpuDerived<T>;
1330
1348
 
@@ -1354,7 +1372,7 @@ declare class MissingSlotValueError extends Error {
1354
1372
  * @category Errors
1355
1373
  */
1356
1374
  declare class NotUniformError extends Error {
1357
- constructor(value: TgpuBuffer$1<AnyData>);
1375
+ constructor(value: TgpuBuffer<AnyData>);
1358
1376
  }
1359
1377
  declare class MissingLinksError extends Error {
1360
1378
  constructor(fnLabel: string | undefined, externalNames: string[]);
@@ -1366,11 +1384,6 @@ declare class MissingVertexBuffersError extends Error {
1366
1384
  constructor(layouts: Iterable<TgpuVertexLayout<WgslArray | Disarray>>);
1367
1385
  }
1368
1386
 
1369
- type TgpuBuffer<TData extends AnyData> = TgpuBuffer$1<Exotic<TData>>;
1370
- type TgpuBufferMutable<TData extends AnyData> = TgpuBufferMutable$1<Exotic<TData>>;
1371
- type TgpuBufferReadonly<TData extends AnyData> = TgpuBufferReadonly$1<Exotic<TData>>;
1372
- type TgpuBufferUniform<TData extends AnyData> = TgpuBufferUniform$1<Exotic<TData>>;
1373
-
1374
1387
  /**
1375
1388
  * @module typegpu
1376
1389
  */
@@ -1398,4 +1411,4 @@ declare const tgpu: {
1398
1411
  };
1399
1412
  };
1400
1413
 
1401
- export { type BindLayoutEntry, type Eventual, type InitFromDeviceOptions, type InitOptions, type LayoutEntryToInput, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, RandomNameRegistry, type Render, ResolutionError, type Sampled, Storage, 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, Uniform, type VariableScope, Vertex, 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 };
1414
+ export { type BindLayoutEntry, type Eventual, type InitFromDeviceOptions, type InitOptions, type LayoutEntryToInput, MissingBindGroupsError, MissingLinksError, MissingSlotValueError, MissingVertexBuffersError, NotUniformError, RandomNameRegistry, type Render, ResolutionError, type Sampled, Storage, 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 VariableScope, type Vertex, 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 };