typegpu 0.3.0-alpha.5 → 0.3.0-alpha.6
Sign up to get free protection for your applications and to get access to all the features.
- package/chunk-3A2SULTE.cjs +4 -0
- package/chunk-3A2SULTE.cjs.map +1 -0
- package/chunk-U7YXBTRR.js +4 -0
- package/chunk-U7YXBTRR.js.map +1 -0
- package/data/index.cjs +1 -1
- package/data/index.d.cts +2 -2
- package/data/index.d.ts +2 -2
- package/data/index.js +1 -1
- package/index.cjs +9 -11
- package/index.cjs.map +1 -1
- package/index.d.cts +92 -29
- package/index.d.ts +92 -29
- package/index.js +9 -11
- package/index.js.map +1 -1
- package/package.json +9 -3
- package/{utilityTypes-CRzYf73j.d.cts → utilityTypes-D53GCmPw.d.cts} +1 -1
- package/{utilityTypes-CRzYf73j.d.ts → utilityTypes-D53GCmPw.d.ts} +1 -1
- package/chunk-CXTZVSMH.cjs +0 -2
- package/chunk-CXTZVSMH.cjs.map +0 -1
- package/chunk-R4KCT3GE.js +0 -2
- package/chunk-R4KCT3GE.js.map +0 -1
package/index.d.cts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { T as TgpuNamable, D as Default, F as F32, U as U32,
|
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
|
/**
|
@@ -453,7 +511,7 @@ type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
|
|
453
511
|
externalTexture: Record<string, never>;
|
454
512
|
};
|
455
513
|
type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
|
456
|
-
type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends
|
514
|
+
type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends (_: number) => BaseWgslData ? ReturnType<T> : T;
|
457
515
|
type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
|
458
516
|
interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
|
459
517
|
readonly resourceType: 'bind-group-layout';
|
@@ -484,10 +542,29 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
|
|
484
542
|
type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
|
485
543
|
access?: infer Access;
|
486
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']>>;
|
487
|
-
type
|
488
|
-
|
489
|
-
|
490
|
-
|
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;
|
491
568
|
type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
|
492
569
|
readonly resourceType: 'bind-group';
|
493
570
|
readonly layout: TgpuBindGroupLayout<Entries>;
|
@@ -501,7 +578,7 @@ type ExoticEntries<T extends Record<string, TgpuLayoutEntry | null>> = {
|
|
501
578
|
};
|
502
579
|
declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<ExoticEntries<Entries>>>;
|
503
580
|
|
504
|
-
type Wgsl = string | number | boolean | TgpuResolvable | AnyWgslData
|
581
|
+
type Wgsl = Eventual<string | number | boolean | TgpuResolvable | AnyWgslData>;
|
505
582
|
declare const UnknownData: unique symbol;
|
506
583
|
type UnknownData = typeof UnknownData;
|
507
584
|
type Resource = {
|
@@ -536,12 +613,14 @@ interface ResolutionCtx {
|
|
536
613
|
group: string;
|
537
614
|
binding: number;
|
538
615
|
};
|
616
|
+
withSlots<T>(pairs: SlotValuePair<unknown>[], callback: () => T): T;
|
539
617
|
/**
|
540
|
-
* 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.
|
541
619
|
* @throws {MissingSlotValueError}
|
542
620
|
*/
|
543
621
|
unwrap<T>(eventual: Eventual<T>): T;
|
544
|
-
resolve(item: Wgsl
|
622
|
+
resolve(item: Wgsl): string;
|
623
|
+
resolveValue<T extends BaseWgslData>(value: Infer<T>, schema: T): string;
|
545
624
|
transpileFn(fn: string): {
|
546
625
|
argNames: string[];
|
547
626
|
body: Block;
|
@@ -556,23 +635,7 @@ interface TgpuResolvable {
|
|
556
635
|
readonly label?: string | undefined;
|
557
636
|
resolve(ctx: ResolutionCtx): string;
|
558
637
|
}
|
559
|
-
/**
|
560
|
-
* Represents a value that is available at resolution time.
|
561
|
-
*/
|
562
|
-
type Eventual<T> = T | TgpuSlot<T>;
|
563
|
-
type SlotValuePair<T> = [TgpuSlot<T>, T];
|
564
638
|
type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
|
565
|
-
interface TgpuSlot<T> extends TgpuNamable {
|
566
|
-
readonly __brand: 'TgpuSlot';
|
567
|
-
readonly defaultValue: T | undefined;
|
568
|
-
readonly label?: string | undefined;
|
569
|
-
/**
|
570
|
-
* Used to determine if code generated using either value `a` or `b` in place
|
571
|
-
* of the slot will be equivalent. Defaults to `Object.is`.
|
572
|
-
*/
|
573
|
-
areEqual(a: T, b: T): boolean;
|
574
|
-
readonly value: Infer<T>;
|
575
|
-
}
|
576
639
|
|
577
640
|
interface TgpuResolveOptions {
|
578
641
|
input: string | TgpuResolvable | AnyWgslData | (string | TgpuResolvable | AnyWgslData)[];
|
@@ -643,9 +706,9 @@ declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
|
|
643
706
|
*/
|
644
707
|
declare class ResolutionError extends Error {
|
645
708
|
readonly cause: unknown;
|
646
|
-
readonly trace: (TgpuResolvable | AnyWgslData)[];
|
647
|
-
constructor(cause: unknown, trace: (TgpuResolvable | AnyWgslData)[]);
|
648
|
-
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;
|
649
712
|
}
|
650
713
|
/**
|
651
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,
|
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
|
/**
|
@@ -453,7 +511,7 @@ type TgpuLayoutExternalTexture = TgpuLayoutEntryBase & {
|
|
453
511
|
externalTexture: Record<string, never>;
|
454
512
|
};
|
455
513
|
type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler | TgpuLayoutTexture | TgpuLayoutStorageTexture | TgpuLayoutExternalTexture;
|
456
|
-
type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends
|
514
|
+
type UnwrapRuntimeConstructorInner<T extends BaseWgslData | ((_: number) => BaseWgslData)> = T extends (_: number) => BaseWgslData ? ReturnType<T> : T;
|
457
515
|
type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
|
458
516
|
interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
|
459
517
|
readonly resourceType: 'bind-group-layout';
|
@@ -484,10 +542,29 @@ interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | n
|
|
484
542
|
type StorageUsageForEntry<T extends TgpuLayoutStorage> = T extends {
|
485
543
|
access?: infer Access;
|
486
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']>>;
|
487
|
-
type
|
488
|
-
|
489
|
-
|
490
|
-
|
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;
|
491
568
|
type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
|
492
569
|
readonly resourceType: 'bind-group';
|
493
570
|
readonly layout: TgpuBindGroupLayout<Entries>;
|
@@ -501,7 +578,7 @@ type ExoticEntries<T extends Record<string, TgpuLayoutEntry | null>> = {
|
|
501
578
|
};
|
502
579
|
declare function bindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null>>(entries: Entries): TgpuBindGroupLayout<Prettify<ExoticEntries<Entries>>>;
|
503
580
|
|
504
|
-
type Wgsl = string | number | boolean | TgpuResolvable | AnyWgslData
|
581
|
+
type Wgsl = Eventual<string | number | boolean | TgpuResolvable | AnyWgslData>;
|
505
582
|
declare const UnknownData: unique symbol;
|
506
583
|
type UnknownData = typeof UnknownData;
|
507
584
|
type Resource = {
|
@@ -536,12 +613,14 @@ interface ResolutionCtx {
|
|
536
613
|
group: string;
|
537
614
|
binding: number;
|
538
615
|
};
|
616
|
+
withSlots<T>(pairs: SlotValuePair<unknown>[], callback: () => T): T;
|
539
617
|
/**
|
540
|
-
* 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.
|
541
619
|
* @throws {MissingSlotValueError}
|
542
620
|
*/
|
543
621
|
unwrap<T>(eventual: Eventual<T>): T;
|
544
|
-
resolve(item: Wgsl
|
622
|
+
resolve(item: Wgsl): string;
|
623
|
+
resolveValue<T extends BaseWgslData>(value: Infer<T>, schema: T): string;
|
545
624
|
transpileFn(fn: string): {
|
546
625
|
argNames: string[];
|
547
626
|
body: Block;
|
@@ -556,23 +635,7 @@ interface TgpuResolvable {
|
|
556
635
|
readonly label?: string | undefined;
|
557
636
|
resolve(ctx: ResolutionCtx): string;
|
558
637
|
}
|
559
|
-
/**
|
560
|
-
* Represents a value that is available at resolution time.
|
561
|
-
*/
|
562
|
-
type Eventual<T> = T | TgpuSlot<T>;
|
563
|
-
type SlotValuePair<T> = [TgpuSlot<T>, T];
|
564
638
|
type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
|
565
|
-
interface TgpuSlot<T> extends TgpuNamable {
|
566
|
-
readonly __brand: 'TgpuSlot';
|
567
|
-
readonly defaultValue: T | undefined;
|
568
|
-
readonly label?: string | undefined;
|
569
|
-
/**
|
570
|
-
* Used to determine if code generated using either value `a` or `b` in place
|
571
|
-
* of the slot will be equivalent. Defaults to `Object.is`.
|
572
|
-
*/
|
573
|
-
areEqual(a: T, b: T): boolean;
|
574
|
-
readonly value: Infer<T>;
|
575
|
-
}
|
576
639
|
|
577
640
|
interface TgpuResolveOptions {
|
578
641
|
input: string | TgpuResolvable | AnyWgslData | (string | TgpuResolvable | AnyWgslData)[];
|
@@ -643,9 +706,9 @@ declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;
|
|
643
706
|
*/
|
644
707
|
declare class ResolutionError extends Error {
|
645
708
|
readonly cause: unknown;
|
646
|
-
readonly trace: (TgpuResolvable | AnyWgslData)[];
|
647
|
-
constructor(cause: unknown, trace: (TgpuResolvable | AnyWgslData)[]);
|
648
|
-
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;
|
649
712
|
}
|
650
713
|
/**
|
651
714
|
* @category Errors
|