typegpu 0.5.8 → 0.6.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/chunk-APTRHY5Y.js +41 -0
- package/chunk-APTRHY5Y.js.map +1 -0
- package/chunk-RC26P3MP.cjs +2 -0
- package/chunk-RC26P3MP.cjs.map +1 -0
- package/chunk-RK6TMFVW.js +2 -0
- package/chunk-RK6TMFVW.js.map +1 -0
- package/chunk-S62QJDM6.js +2 -0
- package/chunk-S62QJDM6.js.map +1 -0
- package/chunk-TG4A6AM3.cjs +2 -0
- package/chunk-TG4A6AM3.cjs.map +1 -0
- package/chunk-UMHCZDPA.cjs +41 -0
- package/chunk-UMHCZDPA.cjs.map +1 -0
- package/data/index.cjs +1 -1
- package/data/index.cjs.map +1 -1
- package/data/index.d.cts +30 -77
- package/data/index.d.ts +30 -77
- package/data/index.js +1 -1
- package/index.cjs +21 -20
- package/index.cjs.map +1 -1
- package/index.d.cts +65 -12
- package/index.d.ts +65 -12
- package/index.js +21 -20
- package/index.js.map +1 -1
- package/matrix-BN6ObiMv.d.cts +122 -0
- package/matrix-S8W4dk8I.d.ts +122 -0
- package/package.json +1 -1
- package/std/index.cjs +1 -1
- package/std/index.cjs.map +1 -1
- package/std/index.d.cts +69 -2
- package/std/index.d.ts +69 -2
- package/std/index.js +1 -1
- package/std/index.js.map +1 -1
- package/{tgpuComputeFn-S61HxwW-.d.ts → tgpuComputeFn-DOUjhQua.d.cts} +402 -127
- package/{tgpuComputeFn-S61HxwW-.d.cts → tgpuComputeFn-DOUjhQua.d.ts} +402 -127
- package/chunk-7ACLI4JY.cjs +0 -2
- package/chunk-7ACLI4JY.cjs.map +0 -1
- package/chunk-L7HIBZAX.js +0 -4
- package/chunk-L7HIBZAX.js.map +0 -1
- package/chunk-SFECI7OX.js +0 -2
- package/chunk-SFECI7OX.js.map +0 -1
- package/chunk-SLWTVY6K.js +0 -2
- package/chunk-SLWTVY6K.js.map +0 -1
- package/chunk-TF6YPHJS.cjs +0 -2
- package/chunk-TF6YPHJS.cjs.map +0 -1
- package/chunk-V4CSEIB2.cjs +0 -4
- package/chunk-V4CSEIB2.cjs.map +0 -1
- /package/{LICENSE.md → LICENSE} +0 -0
@@ -1,6 +1,30 @@
|
|
1
|
-
import * as tinyest from 'tinyest';
|
2
1
|
import { FuncParameter, Block } from 'tinyest';
|
3
2
|
|
3
|
+
interface MetaData {
|
4
|
+
name?: string | undefined;
|
5
|
+
ast?: {
|
6
|
+
v: number;
|
7
|
+
params: FuncParameter[];
|
8
|
+
body: Block;
|
9
|
+
externalNames: string[];
|
10
|
+
} | undefined;
|
11
|
+
externals?: Record<string, unknown> | undefined;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Don't use or you WILL get fired from your job.
|
15
|
+
*
|
16
|
+
* The information that this type describes is additional
|
17
|
+
* properties that we add onto `globalThis`, used by tools
|
18
|
+
* like `unplugin-typegpu` or our test suite.
|
19
|
+
*
|
20
|
+
* @internal
|
21
|
+
*/
|
22
|
+
type INTERNAL_GlobalExt = typeof globalThis & {
|
23
|
+
__TYPEGPU_META__: WeakMap<object, MetaData>;
|
24
|
+
__TYPEGPU_AUTONAME__: <T>(exp: T, label: string) => T;
|
25
|
+
__TYPEGPU_MEASURE_PERF__?: boolean | undefined;
|
26
|
+
__TYPEGPU_PERF_RECORDS__?: Map<string, unknown[]> | undefined;
|
27
|
+
};
|
4
28
|
/**
|
5
29
|
* Can be assigned a name. Not to be confused with
|
6
30
|
* being able to HAVE a name.
|
@@ -11,7 +35,30 @@ interface TgpuNamable {
|
|
11
35
|
$name(label: string): this;
|
12
36
|
}
|
13
37
|
|
38
|
+
declare const $internal: unique symbol;
|
39
|
+
/**
|
40
|
+
* Marks an object with slot-value bindings
|
41
|
+
*/
|
42
|
+
declare const $providing: unique symbol;
|
43
|
+
/**
|
44
|
+
* Type token for the inferred (CPU & GPU) representation of a resource
|
45
|
+
*/
|
14
46
|
declare const $repr: unique symbol;
|
47
|
+
/**
|
48
|
+
* Type token for the inferred (GPU-side) representation of a resource
|
49
|
+
* If present, it shadows the value of `$repr` for GPU-side inference.
|
50
|
+
*/
|
51
|
+
declare const $gpuRepr: unique symbol;
|
52
|
+
/**
|
53
|
+
* Type token for the inferred partial representation of a resource.
|
54
|
+
* If present, it shadows the value of `$repr` for use in partial IO.
|
55
|
+
*/
|
56
|
+
declare const $reprPartial: unique symbol;
|
57
|
+
/**
|
58
|
+
* Type token holding schemas that are identical in memory layout.
|
59
|
+
*/
|
60
|
+
declare const $memIdent: unique symbol;
|
61
|
+
|
15
62
|
/**
|
16
63
|
* Extracts the inferred representation of a resource.
|
17
64
|
* For inferring types as seen by the GPU, see {@link InferGPU}
|
@@ -34,7 +81,7 @@ type Infer<T> = T extends {
|
|
34
81
|
* type C = InferPartial<WgslArray<F32>> // => { idx: number; value: number | undefined }[] | undefined
|
35
82
|
*/
|
36
83
|
type InferPartial<T> = T extends {
|
37
|
-
readonly
|
84
|
+
readonly [$reprPartial]: infer TRepr;
|
38
85
|
} ? TRepr : T extends {
|
39
86
|
readonly [$repr]: infer TRepr;
|
40
87
|
} ? TRepr | undefined : T;
|
@@ -47,7 +94,7 @@ type InferPartial<T> = T extends {
|
|
47
94
|
* type C = InferGPU<Atomic<U32>> // => atomicU32
|
48
95
|
*/
|
49
96
|
type InferGPU<T> = T extends {
|
50
|
-
readonly
|
97
|
+
readonly [$gpuRepr]: infer TRepr;
|
51
98
|
} ? TRepr : Infer<T>;
|
52
99
|
type InferRecord<T extends Record<string | number | symbol, unknown>> = {
|
53
100
|
[Key in keyof T]: Infer<T[Key]>;
|
@@ -59,14 +106,12 @@ type InferGPURecord<T extends Record<string | number | symbol, unknown>> = {
|
|
59
106
|
[Key in keyof T]: InferGPU<T[Key]>;
|
60
107
|
};
|
61
108
|
type MemIdentity<T> = T extends {
|
62
|
-
readonly
|
109
|
+
readonly [$memIdent]: infer TMemIdent;
|
63
110
|
} ? TMemIdent : T;
|
64
111
|
type MemIdentityRecord<T extends Record<string | number | symbol, unknown>> = {
|
65
112
|
[Key in keyof T]: MemIdentity<T[Key]>;
|
66
113
|
};
|
67
114
|
|
68
|
-
declare const $internal: unique symbol;
|
69
|
-
|
70
115
|
type Default<T, TDefault> = unknown extends T ? TDefault : T extends undefined ? TDefault : T;
|
71
116
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
72
117
|
type Prettify<T> = {
|
@@ -78,6 +123,11 @@ type Prettify<T> = {
|
|
78
123
|
type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, {
|
79
124
|
[Key in keyof T]: T[Key] extends Prop ? never : Key;
|
80
125
|
}[keyof T]>;
|
126
|
+
type NullableToOptional<T> = {
|
127
|
+
[K in keyof T as T[K] extends null ? K : never]?: T[K];
|
128
|
+
} & {
|
129
|
+
[K in keyof T as T[K] extends null ? never : K]: T[K];
|
130
|
+
};
|
81
131
|
/**
|
82
132
|
* The opposite of Readonly<T>
|
83
133
|
*/
|
@@ -687,6 +737,7 @@ interface Bool {
|
|
687
737
|
readonly [$internal]: true;
|
688
738
|
readonly type: 'bool';
|
689
739
|
readonly [$repr]: boolean;
|
740
|
+
(v?: number | boolean): boolean;
|
690
741
|
}
|
691
742
|
/**
|
692
743
|
* 32-bit float schema representing a single WGSL f32 value.
|
@@ -695,7 +746,7 @@ interface F32 {
|
|
695
746
|
readonly [$internal]: true;
|
696
747
|
readonly type: 'f32';
|
697
748
|
readonly [$repr]: number;
|
698
|
-
(v
|
749
|
+
(v?: number | boolean): number;
|
699
750
|
}
|
700
751
|
/**
|
701
752
|
* 16-bit float schema representing a single WGSL f16 value.
|
@@ -704,7 +755,7 @@ interface F16 {
|
|
704
755
|
readonly [$internal]: true;
|
705
756
|
readonly type: 'f16';
|
706
757
|
readonly [$repr]: number;
|
707
|
-
(v
|
758
|
+
(v?: number | boolean): number;
|
708
759
|
}
|
709
760
|
/**
|
710
761
|
* Signed 32-bit integer schema representing a single WGSL i32 value.
|
@@ -713,8 +764,8 @@ interface I32 {
|
|
713
764
|
readonly [$internal]: true;
|
714
765
|
readonly type: 'i32';
|
715
766
|
readonly [$repr]: number;
|
716
|
-
readonly
|
717
|
-
(v
|
767
|
+
readonly [$memIdent]: I32 | Atomic<I32> | DecoratedLocation<I32>;
|
768
|
+
(v?: number | boolean): number;
|
718
769
|
}
|
719
770
|
/**
|
720
771
|
* Unsigned 32-bit integer schema representing a single WGSL u32 value.
|
@@ -723,8 +774,16 @@ interface U32 {
|
|
723
774
|
readonly [$internal]: true;
|
724
775
|
readonly type: 'u32';
|
725
776
|
readonly [$repr]: number;
|
726
|
-
readonly
|
727
|
-
(v
|
777
|
+
readonly [$memIdent]: U32 | Atomic<U32> | DecoratedLocation<U32>;
|
778
|
+
(v?: number | boolean): number;
|
779
|
+
}
|
780
|
+
/**
|
781
|
+
* Unsigned 16-bit integer schema used exclusively for index buffer schemas.
|
782
|
+
*/
|
783
|
+
interface U16 {
|
784
|
+
readonly [$internal]: true;
|
785
|
+
readonly type: 'u16';
|
786
|
+
readonly [$repr]: number;
|
728
787
|
}
|
729
788
|
/**
|
730
789
|
* Type of the `d.vec2f` object/function: vector data type schema/constructor
|
@@ -959,6 +1018,7 @@ interface Mat2x2f {
|
|
959
1018
|
(...elements: [number, number, number, number]): m2x2f;
|
960
1019
|
(...columns: [v2f, v2f]): m2x2f;
|
961
1020
|
(): m2x2f;
|
1021
|
+
identity(): m2x2f;
|
962
1022
|
}
|
963
1023
|
/**
|
964
1024
|
* Type of the `d.mat3x3f` object/function: matrix data type schema/constructor
|
@@ -970,6 +1030,7 @@ interface Mat3x3f {
|
|
970
1030
|
(...elements: [number, number, number, number, number, number, number, number, number]): m3x3f;
|
971
1031
|
(...columns: [v3f, v3f, v3f]): m3x3f;
|
972
1032
|
(): m3x3f;
|
1033
|
+
identity(): m3x3f;
|
973
1034
|
}
|
974
1035
|
/**
|
975
1036
|
* Type of the `d.mat4x4f` object/function: matrix data type schema/constructor
|
@@ -981,6 +1042,12 @@ interface Mat4x4f {
|
|
981
1042
|
(...elements: [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]): m4x4f;
|
982
1043
|
(...columns: [v4f, v4f, v4f, v4f]): m4x4f;
|
983
1044
|
(): m4x4f;
|
1045
|
+
identity(): m4x4f;
|
1046
|
+
translation(vec: v3f): m4x4f;
|
1047
|
+
scaling(vec: v3f): m4x4f;
|
1048
|
+
rotationX(angle: number): m4x4f;
|
1049
|
+
rotationY(angle: number): m4x4f;
|
1050
|
+
rotationZ(angle: number): m4x4f;
|
984
1051
|
}
|
985
1052
|
/**
|
986
1053
|
* Array schema constructed via `d.arrayOf` function.
|
@@ -995,12 +1062,12 @@ interface WgslArray<TElement extends BaseData = BaseData> {
|
|
995
1062
|
readonly elementCount: number;
|
996
1063
|
readonly elementType: TElement;
|
997
1064
|
readonly [$repr]: Infer<TElement>[];
|
998
|
-
readonly
|
999
|
-
readonly
|
1065
|
+
readonly [$gpuRepr]: InferGPU<TElement>[];
|
1066
|
+
readonly [$reprPartial]: {
|
1000
1067
|
idx: number;
|
1001
1068
|
value: InferPartial<TElement>;
|
1002
1069
|
}[] | undefined;
|
1003
|
-
readonly
|
1070
|
+
readonly [$memIdent]: WgslArray<MemIdentity<TElement>>;
|
1004
1071
|
}
|
1005
1072
|
/**
|
1006
1073
|
* Struct schema constructed via `d.struct` function.
|
@@ -1015,12 +1082,9 @@ interface WgslStruct<TProps extends Record<string, BaseData> = Record<string, Ba
|
|
1015
1082
|
readonly type: 'struct';
|
1016
1083
|
readonly propTypes: TProps;
|
1017
1084
|
readonly [$repr]: Prettify<InferRecord<TProps>>;
|
1018
|
-
|
1019
|
-
readonly
|
1020
|
-
|
1021
|
-
readonly '~memIdent': WgslStruct<Prettify<MemIdentityRecord<TProps>>>;
|
1022
|
-
/** Type-token, not available at runtime */
|
1023
|
-
readonly '~reprPartial': Prettify<Partial<InferPartialRecord<TProps>>> | undefined;
|
1085
|
+
readonly [$gpuRepr]: Prettify<InferGPURecord<TProps>>;
|
1086
|
+
readonly [$memIdent]: WgslStruct<Prettify<MemIdentityRecord<TProps>>>;
|
1087
|
+
readonly [$reprPartial]: Prettify<Partial<InferPartialRecord<TProps>>> | undefined;
|
1024
1088
|
}
|
1025
1089
|
type AnyWgslStruct = WgslStruct<any>;
|
1026
1090
|
type AddressSpace = 'uniform' | 'storage' | 'workgroup' | 'private' | 'function' | 'handle';
|
@@ -1042,8 +1106,8 @@ interface Atomic<TInner extends U32 | I32 = U32 | I32> {
|
|
1042
1106
|
readonly type: 'atomic';
|
1043
1107
|
readonly inner: TInner;
|
1044
1108
|
readonly [$repr]: Infer<TInner>;
|
1045
|
-
readonly
|
1046
|
-
readonly
|
1109
|
+
readonly [$gpuRepr]: TInner extends U32 ? atomicU32 : atomicI32;
|
1110
|
+
readonly [$memIdent]: MemIdentity<TInner>;
|
1047
1111
|
}
|
1048
1112
|
interface atomicU32 {
|
1049
1113
|
readonly [$internal]: true;
|
@@ -1087,17 +1151,17 @@ interface Decorated<TInner extends BaseData = BaseData, TAttribs extends unknown
|
|
1087
1151
|
readonly inner: TInner;
|
1088
1152
|
readonly attribs: TAttribs;
|
1089
1153
|
readonly [$repr]: Infer<TInner>;
|
1090
|
-
readonly
|
1091
|
-
readonly
|
1092
|
-
readonly
|
1154
|
+
readonly [$gpuRepr]: InferGPU<TInner>;
|
1155
|
+
readonly [$reprPartial]: InferPartial<TInner>;
|
1156
|
+
readonly [$memIdent]: TAttribs extends Location[] ? MemIdentity<TInner> | Decorated<MemIdentity<TInner>, TAttribs> : Decorated<MemIdentity<TInner>, TAttribs>;
|
1093
1157
|
}
|
1094
|
-
declare const wgslTypeLiterals: readonly ["bool", "f32", "f16", "i32", "u32", "vec2f", "vec2h", "vec2i", "vec2u", "vec2<bool>", "vec3f", "vec3h", "vec3i", "vec3u", "vec3<bool>", "vec4f", "vec4h", "vec4i", "vec4u", "vec4<bool>", "mat2x2f", "mat3x3f", "mat4x4f", "struct", "array", "ptr", "atomic", "decorated", "abstractInt", "abstractFloat", "void"];
|
1158
|
+
declare const wgslTypeLiterals: readonly ["bool", "f32", "f16", "i32", "u32", "u16", "vec2f", "vec2h", "vec2i", "vec2u", "vec2<bool>", "vec3f", "vec3h", "vec3i", "vec3u", "vec3<bool>", "vec4f", "vec4h", "vec4i", "vec4u", "vec4<bool>", "mat2x2f", "mat3x3f", "mat4x4f", "struct", "array", "ptr", "atomic", "decorated", "abstractInt", "abstractFloat", "void"];
|
1095
1159
|
type WgslTypeLiteral = (typeof wgslTypeLiterals)[number];
|
1096
1160
|
type PerspectiveOrLinearInterpolatableBaseType = F32 | F16 | Vec2f | Vec2h | Vec3f | Vec3h | Vec4f | Vec4h;
|
1097
1161
|
type PerspectiveOrLinearInterpolatableData = PerspectiveOrLinearInterpolatableBaseType | Decorated<PerspectiveOrLinearInterpolatableBaseType>;
|
1098
1162
|
type FlatInterpolatableAdditionalBaseType = I32 | U32 | Vec2i | Vec2u | Vec3i | Vec3u | Vec4i | Vec4u;
|
1099
1163
|
type FlatInterpolatableData = PerspectiveOrLinearInterpolatableData | FlatInterpolatableAdditionalBaseType | Decorated<FlatInterpolatableAdditionalBaseType>;
|
1100
|
-
type AnyWgslData = Bool | F32 | F16 | I32 | U32 | Vec2f | Vec2h | Vec2i | Vec2u | Vec2b | Vec3f | Vec3h | Vec3i | Vec3u | Vec3b | Vec4f | Vec4h | Vec4i | Vec4u | Vec4b | Mat2x2f | Mat3x3f | Mat4x4f | AnyWgslStruct | WgslArray | Ptr | Atomic | Decorated | AbstractInt | AbstractFloat | Void;
|
1164
|
+
type AnyWgslData = Bool | F32 | F16 | I32 | U32 | U16 | Vec2f | Vec2h | Vec2i | Vec2u | Vec2b | Vec3f | Vec3h | Vec3i | Vec3u | Vec3b | Vec4f | Vec4h | Vec4i | Vec4u | Vec4b | Mat2x2f | Mat3x3f | Mat4x4f | AnyWgslStruct | WgslArray | Ptr | Atomic<U32> | Atomic<I32> | Decorated | AbstractInt | AbstractFloat | Void;
|
1101
1165
|
declare function isWgslData(value: unknown): value is AnyWgslData;
|
1102
1166
|
/**
|
1103
1167
|
* Checks whether passed in value is an array schema,
|
@@ -1150,6 +1214,7 @@ declare function isDecorated<T extends Decorated>(value: unknown | T): value is
|
|
1150
1214
|
|
1151
1215
|
interface TgpuConst<TDataType extends AnyWgslData = AnyWgslData> extends TgpuNamable {
|
1152
1216
|
readonly value: InferGPU<TDataType>;
|
1217
|
+
readonly $: InferGPU<TDataType>;
|
1153
1218
|
readonly [$internal]: {
|
1154
1219
|
readonly dataType: TDataType;
|
1155
1220
|
};
|
@@ -1181,7 +1246,7 @@ type BuiltinPosition = Decorated<Vec4f, [Builtin<'position'>]>;
|
|
1181
1246
|
type BuiltinClipDistances = Decorated<WgslArray<U32>, [
|
1182
1247
|
Builtin<'clip_distances'>
|
1183
1248
|
]>;
|
1184
|
-
type BuiltinFrontFacing = Decorated<
|
1249
|
+
type BuiltinFrontFacing = Decorated<Bool, [Builtin<'front_facing'>]>;
|
1185
1250
|
type BuiltinFragDepth = Decorated<F32, [Builtin<'frag_depth'>]>;
|
1186
1251
|
type BuiltinSampleIndex = Decorated<U32, [Builtin<'sample_index'>]>;
|
1187
1252
|
type BuiltinSampleMask = Decorated<U32, [Builtin<'sample_mask'>]>;
|
@@ -1238,11 +1303,20 @@ interface StorageFlag {
|
|
1238
1303
|
type Storage = StorageFlag;
|
1239
1304
|
declare function isUsableAsStorage<T>(value: T): value is T & StorageFlag;
|
1240
1305
|
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1306
|
+
interface TgpuQuerySet<T extends GPUQueryType> extends TgpuNamable {
|
1307
|
+
readonly resourceType: 'query-set';
|
1308
|
+
readonly type: T;
|
1309
|
+
readonly count: number;
|
1310
|
+
readonly querySet: GPUQuerySet;
|
1311
|
+
readonly destroyed: boolean;
|
1312
|
+
readonly available: boolean;
|
1313
|
+
readonly [$internal]: {
|
1314
|
+
readonly readBuffer: GPUBuffer;
|
1315
|
+
readonly resolveBuffer: GPUBuffer;
|
1316
|
+
};
|
1317
|
+
resolve(): void;
|
1318
|
+
read(): Promise<bigint[]>;
|
1319
|
+
destroy(): void;
|
1246
1320
|
}
|
1247
1321
|
|
1248
1322
|
interface NameRegistry {
|
@@ -1272,7 +1346,7 @@ declare class StrictNameRegistry implements NameRegistry {
|
|
1272
1346
|
type TgpuFnShellHeader<Args extends AnyData[], Return extends AnyData> = {
|
1273
1347
|
readonly [$internal]: true;
|
1274
1348
|
readonly argTypes: Args;
|
1275
|
-
readonly returnType: Return
|
1349
|
+
readonly returnType: Return;
|
1276
1350
|
readonly isEntry: false;
|
1277
1351
|
};
|
1278
1352
|
/**
|
@@ -1280,33 +1354,29 @@ type TgpuFnShellHeader<Args extends AnyData[], Return extends AnyData> = {
|
|
1280
1354
|
* Allows creating tgpu functions by calling this shell
|
1281
1355
|
* and passing the implementation (as WGSL string or JS function) as the argument.
|
1282
1356
|
*/
|
1283
|
-
type TgpuFnShell<Args extends AnyData[], Return extends AnyData> = TgpuFnShellHeader<Args, Return> & (
|
1284
|
-
|
1285
|
-
* @deprecated Invoke the shell as a function instead.
|
1286
|
-
*/
|
1287
|
-
does: ((implementation: (...args: InferArgs<Args>) => InferReturn<Return>) => TgpuFn<Args, Return>) & ((implementation: string) => TgpuFn<Args, Return>);
|
1288
|
-
};
|
1289
|
-
interface TgpuFnBase<Args extends AnyData[], Return extends AnyData> extends TgpuNamable {
|
1357
|
+
type TgpuFnShell<Args extends AnyData[], Return extends AnyData> = TgpuFnShellHeader<Args, Return> & (<T extends (...args: InferArgs<Args>) => Infer<Return>>(implementation: T) => TgpuFn<Prettify<InheritArgNames<(...args: Args) => Return, T>>['result']>) & ((implementation: string) => TgpuFn<(...args: Args) => Return>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuFn<(...args: Args) => Return>);
|
1358
|
+
interface TgpuFnBase<ImplSchema extends AnyFn> extends TgpuNamable {
|
1290
1359
|
readonly [$internal]: {
|
1291
|
-
implementation: Implementation<
|
1360
|
+
implementation: Implementation<ImplSchema>;
|
1292
1361
|
argTypes: FnArgsConversionHint;
|
1293
1362
|
};
|
1294
1363
|
readonly resourceType: 'function';
|
1295
|
-
readonly shell: TgpuFnShellHeader<
|
1296
|
-
readonly
|
1364
|
+
readonly shell: TgpuFnShellHeader<Parameters<ImplSchema>, Extract<ReturnType<ImplSchema>, AnyData>>;
|
1365
|
+
readonly [$providing]?: Providing | undefined;
|
1297
1366
|
$uses(dependencyMap: Record<string, unknown>): this;
|
1298
|
-
with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TgpuFn<
|
1299
|
-
with<T extends AnyData>(accessor: TgpuAccessor<T>, value: TgpuFn<
|
1367
|
+
with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TgpuFn<ImplSchema>;
|
1368
|
+
with<T extends AnyData>(accessor: TgpuAccessor<T>, value: TgpuFn<() => T> | TgpuBufferUsage<T> | Infer<T>): TgpuFn<ImplSchema>;
|
1300
1369
|
}
|
1301
|
-
type TgpuFn<
|
1370
|
+
type TgpuFn<ImplSchema extends AnyFn = (...args: any[]) => any> = TgpuFnBase<ImplSchema> & InferImplSchema<ImplSchema>;
|
1302
1371
|
declare function fn<Args extends AnyData[] | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, Void>;
|
1303
1372
|
declare function fn<Args extends AnyData[] | [], Return extends AnyData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
|
1304
|
-
declare function isTgpuFn<Args extends AnyData[], Return extends AnyData>(value: unknown | TgpuFn<Args
|
1373
|
+
declare function isTgpuFn<Args extends AnyData[] | [], Return extends AnyData>(value: unknown | TgpuFn<(...args: Args) => Return>): value is TgpuFn<(...args: Args) => Return>;
|
1305
1374
|
|
1306
1375
|
interface TgpuSlot<T> extends TgpuNamable {
|
1376
|
+
readonly [$internal]: true;
|
1307
1377
|
readonly resourceType: 'slot';
|
1308
1378
|
readonly [$repr]: Infer<T>;
|
1309
|
-
readonly
|
1379
|
+
readonly [$gpuRepr]: InferGPU<T>;
|
1310
1380
|
readonly defaultValue: T | undefined;
|
1311
1381
|
/**
|
1312
1382
|
* Used to determine if code generated using either value `a` or `b` in place
|
@@ -1314,13 +1384,15 @@ interface TgpuSlot<T> extends TgpuNamable {
|
|
1314
1384
|
*/
|
1315
1385
|
areEqual(a: T, b: T): boolean;
|
1316
1386
|
readonly value: InferGPU<T>;
|
1387
|
+
readonly $: InferGPU<T>;
|
1317
1388
|
}
|
1318
1389
|
interface TgpuDerived<T> {
|
1319
1390
|
readonly resourceType: 'derived';
|
1320
1391
|
readonly value: InferGPU<T>;
|
1321
|
-
|
1322
|
-
|
1323
|
-
readonly
|
1392
|
+
readonly $: InferGPU<T>;
|
1393
|
+
readonly [$repr]: Infer<T>;
|
1394
|
+
readonly [$gpuRepr]: InferGPU<T>;
|
1395
|
+
readonly [$providing]?: Providing | undefined;
|
1324
1396
|
with<TValue>(slot: TgpuSlot<TValue>, value: Eventual<TValue>): TgpuDerived<T>;
|
1325
1397
|
/**
|
1326
1398
|
* @internal
|
@@ -1328,13 +1400,15 @@ interface TgpuDerived<T> {
|
|
1328
1400
|
'~compute'(): T;
|
1329
1401
|
}
|
1330
1402
|
interface TgpuAccessor<T extends AnyData = AnyData> extends TgpuNamable {
|
1403
|
+
readonly [$internal]: true;
|
1331
1404
|
readonly resourceType: 'accessor';
|
1332
1405
|
readonly [$repr]: Infer<T>;
|
1333
|
-
readonly
|
1406
|
+
readonly [$gpuRepr]: InferGPU<T>;
|
1334
1407
|
readonly schema: T;
|
1335
|
-
readonly defaultValue: TgpuFn<
|
1336
|
-
readonly slot: TgpuSlot<TgpuFn<
|
1408
|
+
readonly defaultValue: TgpuFn<() => T> | TgpuBufferUsage<T> | Infer<T> | undefined;
|
1409
|
+
readonly slot: TgpuSlot<TgpuFn<() => T> | TgpuBufferUsage<T> | Infer<T>>;
|
1337
1410
|
readonly value: InferGPU<T>;
|
1411
|
+
readonly $: InferGPU<T>;
|
1338
1412
|
}
|
1339
1413
|
/**
|
1340
1414
|
* Represents a value that is available at resolution time.
|
@@ -1348,15 +1422,37 @@ type Providing = {
|
|
1348
1422
|
declare function isSlot<T>(value: unknown | TgpuSlot<T>): value is TgpuSlot<T>;
|
1349
1423
|
declare function isDerived<T extends TgpuDerived<unknown>>(value: T | unknown): value is T;
|
1350
1424
|
|
1425
|
+
interface Timeable {
|
1426
|
+
withPerformanceCallback(callback: (start: bigint, end: bigint) => void | Promise<void>): this;
|
1427
|
+
withTimestampWrites(options: {
|
1428
|
+
querySet: TgpuQuerySet<'timestamp'> | GPUQuerySet;
|
1429
|
+
beginningOfPassWriteIndex?: number;
|
1430
|
+
endOfPassWriteIndex?: number;
|
1431
|
+
}): this;
|
1432
|
+
}
|
1433
|
+
type TimestampWritesPriors = {
|
1434
|
+
readonly timestampWrites?: {
|
1435
|
+
querySet: TgpuQuerySet<'timestamp'> | GPUQuerySet;
|
1436
|
+
beginningOfPassWriteIndex?: number;
|
1437
|
+
endOfPassWriteIndex?: number;
|
1438
|
+
};
|
1439
|
+
readonly performanceCallback?: (start: bigint, end: bigint) => void | Promise<void>;
|
1440
|
+
readonly hasAutoQuerySet?: boolean;
|
1441
|
+
};
|
1442
|
+
|
1351
1443
|
interface ComputePipelineInternals {
|
1352
1444
|
readonly rawPipeline: GPUComputePipeline;
|
1445
|
+
readonly priors: TgpuComputePipelinePriors & TimestampWritesPriors;
|
1353
1446
|
}
|
1354
|
-
interface TgpuComputePipeline extends TgpuNamable {
|
1447
|
+
interface TgpuComputePipeline extends TgpuNamable, SelfResolvable, Timeable {
|
1355
1448
|
readonly [$internal]: ComputePipelineInternals;
|
1356
1449
|
readonly resourceType: 'compute-pipeline';
|
1357
1450
|
with(bindGroupLayout: TgpuBindGroupLayout, bindGroup: TgpuBindGroup): TgpuComputePipeline;
|
1358
1451
|
dispatchWorkgroups(x: number, y?: number | undefined, z?: number | undefined): void;
|
1359
1452
|
}
|
1453
|
+
type TgpuComputePipelinePriors = {
|
1454
|
+
readonly bindGroupLayoutMap?: Map<TgpuBindGroupLayout, TgpuBindGroup>;
|
1455
|
+
} & TimestampWritesPriors;
|
1360
1456
|
|
1361
1457
|
declare const vertexFormats: readonly ["uint8", "uint8x2", "uint8x4", "sint8", "sint8x2", "sint8x4", "unorm8", "unorm8x2", "unorm8x4", "snorm8", "snorm8x2", "snorm8x4", "uint16", "uint16x2", "uint16x4", "sint16", "sint16x2", "sint16x4", "unorm16", "unorm16x2", "unorm16x4", "snorm16", "snorm16x2", "snorm16x4", "float16", "float16x2", "float16x4", "float32", "float32x2", "float32x3", "float32x4", "uint32", "uint32x2", "uint32x3", "uint32x4", "sint32", "sint32x2", "sint32x3", "sint32x4", "unorm10-10-10-2", "unorm8x4-bgra"];
|
1362
1458
|
type VertexFormat = (typeof vertexFormats)[number];
|
@@ -1439,8 +1535,8 @@ type FragmentOutConstrained = IOLayout<Vec4f | Decorated<Vec4f, (Location | Inte
|
|
1439
1535
|
* Describes a fragment entry function signature (its arguments, return type and targets)
|
1440
1536
|
*/
|
1441
1537
|
type TgpuFragmentFnShellHeader<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = {
|
1442
|
-
readonly
|
1443
|
-
readonly
|
1538
|
+
readonly in: FragmentIn | undefined;
|
1539
|
+
readonly out: FragmentOut;
|
1444
1540
|
readonly returnType: IOLayoutToSchema<FragmentOut>;
|
1445
1541
|
readonly isEntry: true;
|
1446
1542
|
};
|
@@ -1468,6 +1564,7 @@ type TgpuFragmentFnShell<FragmentIn extends FragmentInConstrained, FragmentOut e
|
|
1468
1564
|
*/ ((implementation: string) => TgpuFragmentFn<OmitBuiltins<FragmentIn>, OmitBuiltins<FragmentOut>>);
|
1469
1565
|
};
|
1470
1566
|
interface TgpuFragmentFn<Varying extends FragmentInConstrained = FragmentInConstrained, Output extends FragmentOutConstrained = FragmentOutConstrained> extends TgpuNamable {
|
1567
|
+
readonly [$internal]: true;
|
1471
1568
|
readonly shell: TgpuFragmentFnShellHeader<Varying, Output>;
|
1472
1569
|
readonly outputType: IOLayoutToSchema<Output>;
|
1473
1570
|
$uses(dependencyMap: Record<string, unknown>): this;
|
@@ -1480,15 +1577,15 @@ declare function fragmentFn<FragmentIn extends FragmentInConstrained, FragmentOu
|
|
1480
1577
|
out: FragmentOut;
|
1481
1578
|
}): TgpuFragmentFnShell<FragmentIn, FragmentOut>;
|
1482
1579
|
|
1483
|
-
type VertexInConstrained = IORecord<BaseIOData | AnyVertexInputBuiltin>;
|
1580
|
+
type VertexInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, Location[]> | AnyVertexInputBuiltin>;
|
1484
1581
|
type VertexOutConstrained = IORecord<BaseIOData | Decorated<BaseIOData, (Location | Interpolate)[]> | AnyVertexOutputBuiltin>;
|
1485
1582
|
/**
|
1486
1583
|
* Describes a vertex entry function signature (its arguments, return type and attributes)
|
1487
1584
|
*/
|
1488
1585
|
type TgpuVertexFnShellHeader<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained> = {
|
1586
|
+
readonly in: VertexIn | undefined;
|
1587
|
+
readonly out: VertexOut;
|
1489
1588
|
readonly argTypes: [IOLayoutToSchema<VertexIn>] | [];
|
1490
|
-
readonly returnType: IOLayoutToSchema<VertexOut> | undefined;
|
1491
|
-
readonly attributes: [VertexIn];
|
1492
1589
|
readonly isEntry: true;
|
1493
1590
|
};
|
1494
1591
|
/**
|
@@ -1502,10 +1599,9 @@ type TgpuVertexFnShell<VertexIn extends VertexInConstrained, VertexOut extends V
|
|
1502
1599
|
*/
|
1503
1600
|
does: ((implementation: (input: InferIO<VertexIn>) => InferIO<VertexOut>) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>) & ((implementation: string) => TgpuVertexFn<OmitBuiltins<VertexIn>, OmitBuiltins<VertexOut>>);
|
1504
1601
|
};
|
1505
|
-
interface TgpuVertexFn<VertexIn extends VertexInConstrained =
|
1602
|
+
interface TgpuVertexFn<VertexIn extends VertexInConstrained = VertexInConstrained, VertexOut extends VertexOutConstrained = VertexOutConstrained> extends TgpuNamable {
|
1603
|
+
readonly [$internal]: true;
|
1506
1604
|
readonly shell: TgpuVertexFnShellHeader<VertexIn, VertexOut>;
|
1507
|
-
readonly outputType: IOLayoutToSchema<VertexOut>;
|
1508
|
-
readonly inputType: IOLayoutToSchema<VertexIn>;
|
1509
1605
|
$uses(dependencyMap: Record<string, unknown>): this;
|
1510
1606
|
}
|
1511
1607
|
declare function vertexFn<VertexOut extends VertexOutConstrained>(options: {
|
@@ -1621,6 +1717,12 @@ declare const texelFormatToChannelType: {
|
|
1621
1717
|
'astc-12x10-unorm-srgb': F32;
|
1622
1718
|
'astc-12x12-unorm': F32;
|
1623
1719
|
'astc-12x12-unorm-srgb': F32;
|
1720
|
+
r16snorm: F32;
|
1721
|
+
r16unorm: F32;
|
1722
|
+
rg16unorm: F32;
|
1723
|
+
rg16snorm: F32;
|
1724
|
+
rgba16unorm: F32;
|
1725
|
+
rgba16snorm: F32;
|
1624
1726
|
};
|
1625
1727
|
type TexelFormatToChannelType = typeof texelFormatToChannelType;
|
1626
1728
|
type TexelFormatToStringChannels = {
|
@@ -1813,6 +1915,7 @@ type LayoutToAllowedAttribs<T> = T extends {
|
|
1813
1915
|
} : never;
|
1814
1916
|
|
1815
1917
|
interface TgpuVertexLayout<TData extends WgslArray | Disarray = WgslArray | Disarray> extends TgpuNamable {
|
1918
|
+
readonly [$internal]: true;
|
1816
1919
|
readonly resourceType: 'vertex-layout';
|
1817
1920
|
readonly stride: number;
|
1818
1921
|
readonly stepMode: 'vertex' | 'instance';
|
@@ -1824,15 +1927,22 @@ declare function vertexLayout<TData extends WgslArray | Disarray>(schemaForCount
|
|
1824
1927
|
|
1825
1928
|
interface RenderPipelineInternals {
|
1826
1929
|
readonly core: RenderPipelineCore;
|
1827
|
-
readonly priors: TgpuRenderPipelinePriors;
|
1930
|
+
readonly priors: TgpuRenderPipelinePriors & TimestampWritesPriors;
|
1931
|
+
}
|
1932
|
+
interface HasIndexBuffer {
|
1933
|
+
readonly hasIndexBuffer: true;
|
1934
|
+
drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void;
|
1828
1935
|
}
|
1829
|
-
interface TgpuRenderPipeline<Output extends IOLayout = IOLayout> extends TgpuNamable {
|
1936
|
+
interface TgpuRenderPipeline<Output extends IOLayout = IOLayout> extends TgpuNamable, SelfResolvable, Timeable {
|
1830
1937
|
readonly [$internal]: RenderPipelineInternals;
|
1831
1938
|
readonly resourceType: 'render-pipeline';
|
1832
|
-
|
1833
|
-
with<
|
1834
|
-
|
1835
|
-
|
1939
|
+
readonly hasIndexBuffer: boolean;
|
1940
|
+
with<TData extends WgslArray | Disarray>(vertexLayout: TgpuVertexLayout<TData>, buffer: TgpuBuffer<TData> & VertexFlag): this;
|
1941
|
+
with<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries>): this;
|
1942
|
+
withColorAttachment(attachment: FragmentOutToColorAttachment<Output>): this;
|
1943
|
+
withDepthStencilAttachment(attachment: DepthStencilAttachment): this;
|
1944
|
+
withIndexBuffer(buffer: TgpuBuffer<AnyWgslData> & IndexFlag, offsetElements?: number, sizeElements?: number): this & HasIndexBuffer;
|
1945
|
+
withIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offsetBytes?: number, sizeBytes?: number): this & HasIndexBuffer;
|
1836
1946
|
draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
|
1837
1947
|
}
|
1838
1948
|
type FragmentOutToTargets<T extends IOLayout> = T extends IOData ? GPUColorTargetState : T extends Record<string, unknown> ? {
|
@@ -1942,7 +2052,9 @@ type RenderPipelineCoreOptions = {
|
|
1942
2052
|
vertexAttribs: AnyVertexAttribs;
|
1943
2053
|
vertexFn: TgpuVertexFn;
|
1944
2054
|
fragmentFn: TgpuFragmentFn;
|
1945
|
-
primitiveState: GPUPrimitiveState |
|
2055
|
+
primitiveState: GPUPrimitiveState | Omit<GPUPrimitiveState, 'stripIndexFormat'> & {
|
2056
|
+
stripIndexFormat?: U32 | U16;
|
2057
|
+
} | undefined;
|
1946
2058
|
depthStencilState: GPUDepthStencilState | undefined;
|
1947
2059
|
targets: AnyFragmentTargets;
|
1948
2060
|
multisampleState: GPUMultisampleState | undefined;
|
@@ -1952,19 +2064,27 @@ type TgpuRenderPipelinePriors = {
|
|
1952
2064
|
readonly bindGroupLayoutMap?: Map<TgpuBindGroupLayout, TgpuBindGroup> | undefined;
|
1953
2065
|
readonly colorAttachment?: AnyFragmentColorAttachment | undefined;
|
1954
2066
|
readonly depthStencilAttachment?: DepthStencilAttachment | undefined;
|
1955
|
-
|
2067
|
+
readonly indexBuffer?: {
|
2068
|
+
buffer: TgpuBuffer<AnyWgslData> & IndexFlag | GPUBuffer;
|
2069
|
+
indexFormat: GPUIndexFormat;
|
2070
|
+
offsetBytes?: number | undefined;
|
2071
|
+
sizeBytes?: number | undefined;
|
2072
|
+
} | undefined;
|
2073
|
+
} & TimestampWritesPriors;
|
1956
2074
|
type Memo = {
|
1957
2075
|
pipeline: GPURenderPipeline;
|
1958
|
-
|
1959
|
-
catchall: [number, TgpuBindGroup] |
|
2076
|
+
usedBindGroupLayouts: TgpuBindGroupLayout[];
|
2077
|
+
catchall: [number, TgpuBindGroup] | undefined;
|
1960
2078
|
};
|
1961
|
-
declare class RenderPipelineCore {
|
2079
|
+
declare class RenderPipelineCore implements SelfResolvable {
|
1962
2080
|
readonly options: RenderPipelineCoreOptions;
|
1963
2081
|
readonly usedVertexLayouts: TgpuVertexLayout[];
|
1964
2082
|
private _memo;
|
1965
2083
|
private readonly _vertexBufferLayouts;
|
1966
2084
|
private readonly _targets;
|
1967
2085
|
constructor(options: RenderPipelineCoreOptions);
|
2086
|
+
'~resolve'(ctx: ResolutionCtx): string;
|
2087
|
+
toString(): string;
|
1968
2088
|
unwrap(): Memo;
|
1969
2089
|
}
|
1970
2090
|
|
@@ -2062,8 +2182,12 @@ interface TgpuComparisonSampler {
|
|
2062
2182
|
readonly [$internal]: SamplerInternals;
|
2063
2183
|
readonly resourceType: 'sampler-comparison';
|
2064
2184
|
}
|
2065
|
-
|
2066
|
-
|
2185
|
+
interface TgpuFixedSampler extends TgpuSampler, TgpuNamable {
|
2186
|
+
}
|
2187
|
+
interface TgpuFixedComparisonSampler extends TgpuComparisonSampler, TgpuNamable {
|
2188
|
+
}
|
2189
|
+
declare function sampler(props: SamplerProps): TgpuFixedSampler;
|
2190
|
+
declare function comparisonSampler(props: ComparisonSamplerProps): TgpuFixedComparisonSampler;
|
2067
2191
|
declare function isSampler(resource: unknown): resource is TgpuSampler;
|
2068
2192
|
declare function isComparisonSampler(resource: unknown): resource is TgpuComparisonSampler;
|
2069
2193
|
|
@@ -2079,12 +2203,40 @@ interface Unwrapper {
|
|
2079
2203
|
unwrap(resource: TgpuVertexLayout): GPUVertexBufferLayout;
|
2080
2204
|
unwrap(resource: TgpuSampler): GPUSampler;
|
2081
2205
|
unwrap(resource: TgpuComparisonSampler): GPUSampler;
|
2206
|
+
unwrap(resource: TgpuQuerySet<GPUQueryType>): GPUQuerySet;
|
2082
2207
|
}
|
2083
2208
|
|
2209
|
+
interface TgpuBufferShorthandBase<TData extends BaseData> extends TgpuNamable {
|
2210
|
+
readonly [$internal]: true;
|
2211
|
+
write(data: Infer<TData>): void;
|
2212
|
+
writePartial(data: InferPartial<TData>): void;
|
2213
|
+
read(): Promise<Infer<TData>>;
|
2214
|
+
}
|
2215
|
+
interface TgpuMutable<TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
|
2216
|
+
readonly resourceType: 'mutable';
|
2217
|
+
readonly buffer: TgpuBuffer<TData> & StorageFlag;
|
2218
|
+
value: InferGPU<TData>;
|
2219
|
+
$: InferGPU<TData>;
|
2220
|
+
}
|
2221
|
+
interface TgpuReadonly<TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
|
2222
|
+
readonly resourceType: 'readonly';
|
2223
|
+
readonly buffer: TgpuBuffer<TData> & StorageFlag;
|
2224
|
+
readonly value: InferGPU<TData>;
|
2225
|
+
readonly $: InferGPU<TData>;
|
2226
|
+
}
|
2227
|
+
interface TgpuUniform<TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
|
2228
|
+
readonly resourceType: 'uniform';
|
2229
|
+
readonly buffer: TgpuBuffer<TData> & UniformFlag;
|
2230
|
+
readonly value: InferGPU<TData>;
|
2231
|
+
readonly $: InferGPU<TData>;
|
2232
|
+
}
|
2233
|
+
type TgpuBufferShorthand<TData extends BaseData> = TgpuMutable<TData> | TgpuReadonly<TData> | TgpuUniform<TData>;
|
2234
|
+
declare function isBufferShorthand<TData extends BaseData>(value: unknown | TgpuBufferShorthand<TData>): value is TgpuBufferShorthand<TData>;
|
2235
|
+
|
2084
2236
|
interface WithCompute {
|
2085
2237
|
createPipeline(): TgpuComputePipeline;
|
2086
2238
|
}
|
2087
|
-
type ValidateFragmentIn<VertexOut extends
|
2239
|
+
type ValidateFragmentIn<VertexOut extends VertexOutConstrained, FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = UndecorateRecord<FragmentIn> extends Partial<UndecorateRecord<VertexOut>> ? UndecorateRecord<VertexOut> extends UndecorateRecord<FragmentIn> ? [
|
2088
2240
|
entryFn: TgpuFragmentFn<FragmentIn, FragmentOut>,
|
2089
2241
|
targets: FragmentOutToTargets<FragmentOut>
|
2090
2242
|
] : [
|
@@ -2100,20 +2252,29 @@ type ValidateFragmentIn<VertexOut extends IORecord, FragmentIn extends FragmentI
|
|
2100
2252
|
[Key in keyof FragmentIn & keyof VertexOut as FragmentIn[Key] extends VertexOut[Key] ? never : Key]: [got: VertexOut[Key], expecting: FragmentIn[Key]];
|
2101
2253
|
}
|
2102
2254
|
];
|
2103
|
-
interface WithVertex<VertexOut extends
|
2255
|
+
interface WithVertex<VertexOut extends VertexOutConstrained = VertexOutConstrained> {
|
2104
2256
|
withFragment<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained>(...args: ValidateFragmentIn<VertexOut, FragmentIn, FragmentOut>): WithFragment<FragmentOut>;
|
2105
2257
|
}
|
2106
2258
|
interface WithFragment<Output extends FragmentOutConstrained = FragmentOutConstrained> {
|
2107
|
-
withPrimitive(primitiveState: GPUPrimitiveState |
|
2259
|
+
withPrimitive(primitiveState: GPUPrimitiveState | Omit<GPUPrimitiveState, 'stripIndexFormat'> & {
|
2260
|
+
stripIndexFormat?: U32 | U16;
|
2261
|
+
} | undefined): WithFragment<Output>;
|
2108
2262
|
withDepthStencil(depthStencilState: GPUDepthStencilState | undefined): WithFragment<Output>;
|
2109
2263
|
withMultisample(multisampleState: GPUMultisampleState | undefined): WithFragment<Output>;
|
2110
2264
|
createPipeline(): TgpuRenderPipeline<Output>;
|
2111
2265
|
}
|
2266
|
+
interface Configurable {
|
2267
|
+
readonly bindings: [slot: TgpuSlot<unknown>, value: unknown][];
|
2268
|
+
with<T>(slot: TgpuSlot<T>, value: Eventual<T>): Configurable;
|
2269
|
+
with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<() => T> | TgpuBufferUsage<T> | TgpuBufferShorthand<T> | Infer<T>): Configurable;
|
2270
|
+
pipe(transform: (cfg: Configurable) => Configurable): Configurable;
|
2271
|
+
}
|
2112
2272
|
interface WithBinding {
|
2113
|
-
with<T>(slot: TgpuSlot<T>, value: Eventual<T>): WithBinding;
|
2114
|
-
with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<[], T> | TgpuBufferUsage<T> | Infer<T>): WithBinding;
|
2115
2273
|
withCompute<ComputeIn extends IORecord<AnyComputeBuiltin>>(entryFn: TgpuComputeFn<ComputeIn>): WithCompute;
|
2116
2274
|
withVertex<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(entryFn: TgpuVertexFn<VertexIn, VertexOut>, attribs: LayoutToAllowedAttribs<OmitBuiltins<VertexIn>>): WithVertex<VertexOut>;
|
2275
|
+
with<T>(slot: TgpuSlot<T>, value: Eventual<T>): WithBinding;
|
2276
|
+
with<T extends AnyWgslData>(accessor: TgpuAccessor<T>, value: TgpuFn<() => T> | TgpuBufferUsage<T> | TgpuBufferShorthand<T> | Infer<T>): WithBinding;
|
2277
|
+
pipe(transform: (cfg: Configurable) => Configurable): WithBinding;
|
2117
2278
|
}
|
2118
2279
|
type CreateTextureOptions<TSize, TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormat extends GPUTextureFormat, TDimension extends GPUTextureDimension> = {
|
2119
2280
|
/**
|
@@ -2252,6 +2413,14 @@ interface RenderPass {
|
|
2252
2413
|
*/
|
2253
2414
|
drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): undefined;
|
2254
2415
|
}
|
2416
|
+
type ValidateSchema<TData extends AnyData> = HasNestedType<[
|
2417
|
+
TData
|
2418
|
+
], 'bool'> extends true ? 'Error: Bool is not host-shareable, use U32 or I32 instead' : HasNestedType<[TData], 'u16'> extends true ? TData extends {
|
2419
|
+
type: 'array';
|
2420
|
+
elementType: {
|
2421
|
+
type: 'u16';
|
2422
|
+
};
|
2423
|
+
} ? TData : 'Error: U16 is only usable inside arrays for index buffers' : TData;
|
2255
2424
|
interface TgpuRoot extends Unwrapper {
|
2256
2425
|
/**
|
2257
2426
|
* The GPU device associated with this root.
|
@@ -2266,7 +2435,7 @@ interface TgpuRoot extends Unwrapper {
|
|
2266
2435
|
* @param typeSchema The type of data that this buffer will hold.
|
2267
2436
|
* @param initial The initial value of the buffer. (optional)
|
2268
2437
|
*/
|
2269
|
-
createBuffer<TData extends AnyData>(typeSchema: TData
|
2438
|
+
createBuffer<TData extends AnyData>(typeSchema: ValidateSchema<TData>, initial?: Infer<TData> | undefined): TgpuBuffer<TData>;
|
2270
2439
|
/**
|
2271
2440
|
* Allocates memory on the GPU, allows passing data between host and shader.
|
2272
2441
|
*
|
@@ -2276,7 +2445,72 @@ interface TgpuRoot extends Unwrapper {
|
|
2276
2445
|
* @param typeSchema The type of data that this buffer will hold.
|
2277
2446
|
* @param gpuBuffer A vanilla WebGPU buffer.
|
2278
2447
|
*/
|
2279
|
-
createBuffer<TData extends AnyData>(typeSchema: TData
|
2448
|
+
createBuffer<TData extends AnyData>(typeSchema: ValidateSchema<TData>, gpuBuffer: GPUBuffer): TgpuBuffer<TData>;
|
2449
|
+
/**
|
2450
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
2451
|
+
* Read-only on the GPU, optimized for small data. For a general-purpose buffer,
|
2452
|
+
* use {@link TgpuRoot.createBuffer}.
|
2453
|
+
*
|
2454
|
+
* @param typeSchema The type of data that this buffer will hold.
|
2455
|
+
* @param initial The initial value of the buffer. (optional)
|
2456
|
+
*/
|
2457
|
+
createUniform<TData extends AnyWgslData>(typeSchema: TData, initial?: Infer<TData>): TgpuUniform<TData>;
|
2458
|
+
/**
|
2459
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
2460
|
+
* Read-only on the GPU, optimized for small data. For a general-purpose buffer,
|
2461
|
+
* use {@link TgpuRoot.createBuffer}.
|
2462
|
+
*
|
2463
|
+
* @param typeSchema The type of data that this buffer will hold.
|
2464
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
2465
|
+
*/
|
2466
|
+
createUniform<TData extends AnyWgslData>(typeSchema: TData, gpuBuffer: GPUBuffer): TgpuUniform<TData>;
|
2467
|
+
/**
|
2468
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
2469
|
+
* Can be mutated in-place on the GPU. For a general-purpose buffer,
|
2470
|
+
* use {@link TgpuRoot.createBuffer}.
|
2471
|
+
*
|
2472
|
+
* @param typeSchema The type of data that this buffer will hold.
|
2473
|
+
* @param initial The initial value of the buffer. (optional)
|
2474
|
+
*/
|
2475
|
+
createMutable<TData extends AnyWgslData>(typeSchema: TData, initial?: Infer<TData>): TgpuMutable<TData>;
|
2476
|
+
/**
|
2477
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
2478
|
+
* Can be mutated in-place on the GPU. For a general-purpose buffer,
|
2479
|
+
* use {@link TgpuRoot.createBuffer}.
|
2480
|
+
*
|
2481
|
+
* @param typeSchema The type of data that this buffer will hold.
|
2482
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
2483
|
+
*/
|
2484
|
+
createMutable<TData extends AnyWgslData>(typeSchema: TData, gpuBuffer: GPUBuffer): TgpuMutable<TData>;
|
2485
|
+
/**
|
2486
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
2487
|
+
* Read-only on the GPU, optimized for large data. For a general-purpose buffer,
|
2488
|
+
* use {@link TgpuRoot.createBuffer}.
|
2489
|
+
*
|
2490
|
+
* @param typeSchema The type of data that this buffer will hold.
|
2491
|
+
* @param initial The initial value of the buffer. (optional)
|
2492
|
+
*/
|
2493
|
+
createReadonly<TData extends AnyWgslData>(typeSchema: TData, initial?: Infer<TData>): TgpuReadonly<TData>;
|
2494
|
+
/**
|
2495
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
2496
|
+
* Read-only on the GPU, optimized for large data. For a general-purpose buffer,
|
2497
|
+
* use {@link TgpuRoot.createBuffer}.
|
2498
|
+
*
|
2499
|
+
* @param typeSchema The type of data that this buffer will hold.
|
2500
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
2501
|
+
*/
|
2502
|
+
createReadonly<TData extends AnyWgslData>(typeSchema: TData, gpuBuffer: GPUBuffer): TgpuReadonly<TData>;
|
2503
|
+
/**
|
2504
|
+
* Creates a query set for collecting timestamps or occlusion queries.
|
2505
|
+
*
|
2506
|
+
* @remarks
|
2507
|
+
* Typed wrapper around a GPUQuerySet.
|
2508
|
+
*
|
2509
|
+
* @param type The type of queries to collect ('occlusion' or 'timestamp').
|
2510
|
+
* @param count The number of queries in the set.
|
2511
|
+
* @param rawQuerySet An optional pre-existing GPUQuerySet to use instead of creating a new one.
|
2512
|
+
*/
|
2513
|
+
createQuerySet<T extends GPUQueryType>(type: T, count: number, rawQuerySet?: GPUQuerySet | undefined): TgpuQuerySet<T>;
|
2280
2514
|
/**
|
2281
2515
|
* Creates a group of resources that can be bound to a shader based on a specified layout.
|
2282
2516
|
*
|
@@ -2301,9 +2535,12 @@ interface TgpuRoot extends Unwrapper {
|
|
2301
2535
|
* @param entries A record with values being the resources populating the bind group
|
2302
2536
|
* and keys being their associated names, matching the layout keys.
|
2303
2537
|
*/
|
2304
|
-
createBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>>(layout: TgpuBindGroupLayout<Entries>, entries:
|
2305
|
-
|
2306
|
-
|
2538
|
+
createBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>>(layout: TgpuBindGroupLayout<Entries>, entries: ExtractBindGroupInputFromLayout<Entries>): TgpuBindGroup<Entries>;
|
2539
|
+
/**
|
2540
|
+
* Retrieves a read-only list of all enabled features of the GPU device.
|
2541
|
+
* @returns A set of strings representing the enabled features.
|
2542
|
+
*/
|
2543
|
+
get enabledFeatures(): ReadonlySet<GPUFeatureName>;
|
2307
2544
|
/**
|
2308
2545
|
* Destroys all underlying resources (i.e. buffers...) created through this root object.
|
2309
2546
|
* If the object is created via `tgpu.init` instead of `tgpu.initFromDevice`,
|
@@ -2313,16 +2550,12 @@ interface TgpuRoot extends Unwrapper {
|
|
2313
2550
|
'~unstable': Omit<ExperimentalTgpuRoot, keyof TgpuRoot>;
|
2314
2551
|
}
|
2315
2552
|
interface ExperimentalTgpuRoot extends TgpuRoot, WithBinding {
|
2316
|
-
readonly jitTranspiler?: JitTranspiler | undefined;
|
2317
2553
|
readonly nameRegistry: NameRegistry;
|
2318
2554
|
/**
|
2319
2555
|
* The current command encoder. This property will
|
2320
2556
|
* hold the same value until `flush()` is called.
|
2321
2557
|
*/
|
2322
2558
|
readonly commandEncoder: GPUCommandEncoder;
|
2323
|
-
createUniform<TData extends AnyWgslData>(typeSchema: TData, initialOrBuffer?: Infer<TData> | GPUBuffer): TgpuBufferUniform<TData> & TgpuFixedBufferUsage<TData>;
|
2324
|
-
createMutable<TData extends AnyWgslData>(typeSchema: TData, initialOrBuffer?: Infer<TData> | GPUBuffer): TgpuBufferMutable<TData> & TgpuFixedBufferUsage<TData>;
|
2325
|
-
createReadonly<TData extends AnyWgslData>(typeSchema: TData, initialOrBuffer?: Infer<TData> | GPUBuffer): TgpuBufferReadonly<TData> & TgpuFixedBufferUsage<TData>;
|
2326
2559
|
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>>;
|
2327
2560
|
beginRenderPass(descriptor: GPURenderPassDescriptor, callback: (pass: RenderPass) => void): void;
|
2328
2561
|
/**
|
@@ -2342,18 +2575,28 @@ type Uniform = UniformFlag;
|
|
2342
2575
|
interface VertexFlag {
|
2343
2576
|
usableAsVertex: true;
|
2344
2577
|
}
|
2578
|
+
interface IndexFlag {
|
2579
|
+
usableAsIndex: true;
|
2580
|
+
}
|
2345
2581
|
/**
|
2346
2582
|
* @deprecated Use VertexFlag instead.
|
2347
2583
|
*/
|
2348
2584
|
type Vertex = VertexFlag;
|
2349
|
-
type LiteralToUsageType<T extends 'uniform' | 'storage' | 'vertex'> = T extends 'uniform' ? UniformFlag : T extends 'storage' ? StorageFlag : T extends 'vertex' ? VertexFlag : never;
|
2585
|
+
type LiteralToUsageType<T extends 'uniform' | 'storage' | 'vertex' | 'index'> = T extends 'uniform' ? UniformFlag : T extends 'storage' ? StorageFlag : T extends 'vertex' ? VertexFlag : T extends 'index' ? IndexFlag : never;
|
2350
2586
|
type ViewUsages<TBuffer extends TgpuBuffer<BaseData>> = (boolean extends TBuffer['usableAsUniform'] ? never : 'uniform') | (boolean extends TBuffer['usableAsStorage'] ? never : 'readonly' | 'mutable');
|
2351
2587
|
type UsageTypeToBufferUsage<TData extends BaseData> = {
|
2352
2588
|
uniform: TgpuBufferUniform<TData> & TgpuFixedBufferUsage<TData>;
|
2353
2589
|
mutable: TgpuBufferMutable<TData> & TgpuFixedBufferUsage<TData>;
|
2354
2590
|
readonly: TgpuBufferReadonly<TData> & TgpuFixedBufferUsage<TData>;
|
2355
2591
|
};
|
2592
|
+
type IsIndexCompatible<TData extends BaseData> = UnwrapDecorated<TData> extends {
|
2593
|
+
readonly type: 'array';
|
2594
|
+
readonly elementType: infer TElement;
|
2595
|
+
} ? TElement extends BaseData ? UnwrapDecorated<TElement> extends {
|
2596
|
+
readonly type: 'u32' | 'u16';
|
2597
|
+
} ? true : false : false : false;
|
2356
2598
|
interface TgpuBuffer<TData extends BaseData> extends TgpuNamable {
|
2599
|
+
readonly [$internal]: true;
|
2357
2600
|
readonly resourceType: 'buffer';
|
2358
2601
|
readonly dataType: TData;
|
2359
2602
|
readonly initial?: Infer<TData> | undefined;
|
@@ -2362,7 +2605,8 @@ interface TgpuBuffer<TData extends BaseData> extends TgpuNamable {
|
|
2362
2605
|
usableAsUniform: boolean;
|
2363
2606
|
usableAsStorage: boolean;
|
2364
2607
|
usableAsVertex: boolean;
|
2365
|
-
|
2608
|
+
usableAsIndex: boolean;
|
2609
|
+
$usage<T extends RestrictUsages<TData>>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
|
2366
2610
|
$addFlags(flags: GPUBufferUsageFlags): this;
|
2367
2611
|
as<T extends ViewUsages<this>>(usage: T): UsageTypeToBufferUsage<TData>[T];
|
2368
2612
|
compileWriter(): void;
|
@@ -2374,9 +2618,16 @@ interface TgpuBuffer<TData extends BaseData> extends TgpuNamable {
|
|
2374
2618
|
}
|
2375
2619
|
declare function isBuffer<T extends TgpuBuffer<AnyData>>(value: T | unknown): value is T;
|
2376
2620
|
declare function isUsableAsVertex<T extends TgpuBuffer<AnyData>>(buffer: T): buffer is T & VertexFlag;
|
2377
|
-
type
|
2621
|
+
type IsArrayOfU32<TData extends BaseData> = UnwrapDecorated<TData> extends {
|
2622
|
+
readonly type: 'array';
|
2623
|
+
readonly elementType: infer TElement;
|
2624
|
+
} ? TElement extends BaseData ? UnwrapDecorated<TElement> extends {
|
2625
|
+
readonly type: 'u32';
|
2626
|
+
} ? true : false : false : false;
|
2627
|
+
type IsWgslLiteral<TData extends BaseData> = TData extends {
|
2378
2628
|
readonly type: WgslTypeLiteral;
|
2379
|
-
} ?
|
2629
|
+
} ? true : false;
|
2630
|
+
type RestrictUsages<TData extends BaseData> = string extends TData['type'] ? ('uniform' | 'storage' | 'vertex' | 'index')[] : IsIndexCompatible<TData> extends true ? IsArrayOfU32<TData> extends true ? ('uniform' | 'storage' | 'vertex' | 'index')[] : ['index'] : IsWgslLiteral<TData> extends true ? ('uniform' | 'storage' | 'vertex')[] : ['vertex'];
|
2380
2631
|
|
2381
2632
|
type TgpuLayoutEntryBase = {
|
2382
2633
|
/**
|
@@ -2436,6 +2687,7 @@ type TgpuLayoutEntry = TgpuLayoutUniform | TgpuLayoutStorage | TgpuLayoutSampler
|
|
2436
2687
|
type UnwrapRuntimeConstructorInner<T extends BaseData | ((_: number) => BaseData)> = T extends (_: number) => BaseData ? ReturnType<T> : T;
|
2437
2688
|
type UnwrapRuntimeConstructor<T extends AnyData | ((_: number) => AnyData)> = T extends unknown ? UnwrapRuntimeConstructorInner<T> : never;
|
2438
2689
|
interface TgpuBindGroupLayout<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> extends TgpuNamable {
|
2690
|
+
readonly [$internal]: true;
|
2439
2691
|
readonly resourceType: 'bind-group-layout';
|
2440
2692
|
readonly entries: Entries;
|
2441
2693
|
readonly bound: {
|
@@ -2491,12 +2743,12 @@ type GetStorageTextureRestriction<T extends TgpuLayoutStorageTexture> = Default<
|
|
2491
2743
|
format: T['storageTexture'];
|
2492
2744
|
dimension: Dimension;
|
2493
2745
|
} : never;
|
2494
|
-
type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? (TgpuBuffer<UnwrapRuntimeConstructor<T['uniform']
|
2746
|
+
type LayoutEntryToInput<T extends TgpuLayoutEntry | null> = TgpuLayoutEntry | null extends T ? TgpuBuffer<AnyWgslData> | GPUBuffer | TgpuSampler | GPUSampler | TgpuComparisonSampler | GPUSampler | TgpuTexture | TgpuSampledTexture | TgpuMutableTexture | TgpuReadonlyTexture | TgpuWriteonlyTexture | GPUTextureView | GPUExternalTexture : T extends TgpuLayoutUniform ? (TgpuBuffer<MemIdentity<UnwrapRuntimeConstructor<T['uniform']>>> & UniformFlag) | GPUBuffer : T extends TgpuLayoutStorage ? (TgpuBuffer<MemIdentity<UnwrapRuntimeConstructor<T['storage']>>> & StorageFlag) | GPUBuffer : T extends TgpuLayoutSampler ? TgpuSampler | GPUSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler | GPUSampler : T extends TgpuLayoutTexture ? GPUTextureView | (Sampled & TgpuTexture<Prettify<TextureProps & GetTextureRestriction<T>>>) | TgpuSampledTexture<Default<T['viewDimension'], '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? GPUTextureView | (StorageFlag & TgpuTexture<Prettify<TextureProps & GetStorageTextureRestriction<T>>>) | StorageTextureUsageForEntry<T> : T extends TgpuLayoutExternalTexture ? GPUExternalTexture : never;
|
2495
2747
|
type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? TgpuBufferUniform<T['uniform']> : T extends TgpuLayoutStorage ? StorageUsageForEntry<T> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<T['viewDimension'], '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
|
2496
2748
|
type InferLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform ? Infer<T['uniform']> : T extends TgpuLayoutStorage ? Infer<UnwrapRuntimeConstructor<T['storage']>> : T extends TgpuLayoutSampler ? TgpuSampler : T extends TgpuLayoutComparisonSampler ? TgpuComparisonSampler : T extends TgpuLayoutTexture ? TgpuSampledTexture<Default<T['viewDimension'], '2d'>, ChannelFormatToSchema[T['texture']]> : T extends TgpuLayoutStorageTexture ? StorageTextureUsageForEntry<T> : never;
|
2497
|
-
type ExtractBindGroupInputFromLayout<T extends Record<string, TgpuLayoutEntry | null>> = {
|
2749
|
+
type ExtractBindGroupInputFromLayout<T extends Record<string, TgpuLayoutEntry | null>> = NullableToOptional<{
|
2498
2750
|
[K in keyof T]: LayoutEntryToInput<T[K]>;
|
2499
|
-
}
|
2751
|
+
}>;
|
2500
2752
|
type TgpuBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>> = {
|
2501
2753
|
readonly resourceType: 'bind-group';
|
2502
2754
|
readonly layout: TgpuBindGroupLayout<Entries>;
|
@@ -2509,19 +2761,21 @@ interface TgpuBufferUsage<TData extends BaseData = BaseData, TUsage extends Bind
|
|
2509
2761
|
readonly usage: TUsage;
|
2510
2762
|
readonly [$repr]: Infer<TData>;
|
2511
2763
|
value: InferGPU<TData>;
|
2764
|
+
$: InferGPU<TData>;
|
2512
2765
|
readonly [$internal]: {
|
2513
2766
|
readonly dataType: TData;
|
2514
2767
|
};
|
2515
2768
|
}
|
2516
2769
|
interface TgpuBufferUniform<TData extends BaseData> extends TgpuBufferUsage<TData, 'uniform'> {
|
2517
2770
|
readonly value: InferGPU<TData>;
|
2771
|
+
readonly $: InferGPU<TData>;
|
2518
2772
|
}
|
2519
2773
|
interface TgpuBufferReadonly<TData extends BaseData> extends TgpuBufferUsage<TData, 'readonly'> {
|
2520
2774
|
readonly value: InferGPU<TData>;
|
2775
|
+
readonly $: InferGPU<TData>;
|
2521
2776
|
}
|
2522
2777
|
interface TgpuFixedBufferUsage<TData extends BaseData> extends TgpuNamable {
|
2523
2778
|
readonly buffer: TgpuBuffer<TData>;
|
2524
|
-
write(data: Infer<TData>): void;
|
2525
2779
|
}
|
2526
2780
|
interface TgpuBufferMutable<TData extends BaseData> extends TgpuBufferUsage<TData, 'mutable'> {
|
2527
2781
|
}
|
@@ -2565,7 +2819,7 @@ declare function privateVar<TDataType extends AnyData>(dataType: TDataType, init
|
|
2565
2819
|
*/
|
2566
2820
|
declare function workgroupVar<TDataType extends AnyData>(dataType: TDataType): TgpuVar<'workgroup', TDataType>;
|
2567
2821
|
|
2568
|
-
type ResolvableObject = SelfResolvable | TgpuBufferUsage | TgpuConst | TgpuDeclare | TgpuFn | TgpuComputeFn | TgpuFragmentFn | TgpuComputePipeline | TgpuRenderPipeline | TgpuVertexFn | TgpuSampler | TgpuAccessor | TgpuExternalTexture | TgpuTexture | TgpuAnyTextureView | TgpuVar | AnyVecInstance | AnyMatInstance | AnyData | TgpuFn
|
2822
|
+
type ResolvableObject = SelfResolvable | TgpuBufferUsage | TgpuConst | TgpuDeclare | TgpuFn | TgpuComputeFn | TgpuFragmentFn | TgpuComputePipeline | TgpuRenderPipeline | TgpuVertexFn | TgpuSampler | TgpuAccessor | TgpuExternalTexture | TgpuTexture | TgpuAnyTextureView | TgpuVar | AnyVecInstance | AnyMatInstance | AnyData | TgpuFn;
|
2569
2823
|
type Wgsl = Eventual<string | number | boolean | ResolvableObject>;
|
2570
2824
|
type TgpuShaderStage = 'compute' | 'vertex' | 'fragment';
|
2571
2825
|
interface FnToWgslOptions {
|
@@ -2624,15 +2878,12 @@ interface ResolutionCtx {
|
|
2624
2878
|
unwrap<T>(eventual: Eventual<T>): T;
|
2625
2879
|
resolve(item: unknown): string;
|
2626
2880
|
resolveValue<T extends BaseData>(value: Infer<T> | InferGPU<T>, schema: T): string;
|
2627
|
-
transpileFn(fn: string): {
|
2628
|
-
params: FuncParameter[];
|
2629
|
-
body: Block;
|
2630
|
-
externalNames: string[];
|
2631
|
-
};
|
2632
2881
|
fnToWgsl(options: FnToWgslOptions): {
|
2633
2882
|
head: Wgsl;
|
2634
2883
|
body: Wgsl;
|
2635
2884
|
};
|
2885
|
+
withVaryingLocations<T>(locations: Record<string, number>, callback: () => T): T;
|
2886
|
+
get varyingLocations(): Record<string, number> | undefined;
|
2636
2887
|
[$internal]: {
|
2637
2888
|
itemStateStack: ItemStateStack;
|
2638
2889
|
};
|
@@ -2804,7 +3055,7 @@ interface Disarray<TElement extends BaseData = BaseData> {
|
|
2804
3055
|
readonly elementCount: number;
|
2805
3056
|
readonly elementType: TElement;
|
2806
3057
|
readonly [$repr]: Infer<TElement>[];
|
2807
|
-
readonly
|
3058
|
+
readonly [$reprPartial]: {
|
2808
3059
|
idx: number;
|
2809
3060
|
value: InferPartial<TElement>;
|
2810
3061
|
}[] | undefined;
|
@@ -2823,9 +3074,9 @@ interface Unstruct<TProps extends Record<string, BaseData> = Record<string, Base
|
|
2823
3074
|
readonly type: 'unstruct';
|
2824
3075
|
readonly propTypes: TProps;
|
2825
3076
|
readonly [$repr]: Prettify<InferRecord<TProps>>;
|
2826
|
-
readonly
|
2827
|
-
readonly
|
2828
|
-
readonly
|
3077
|
+
readonly [$gpuRepr]: Prettify<InferGPURecord<TProps>>;
|
3078
|
+
readonly [$memIdent]: Unstruct<Prettify<MemIdentityRecord<TProps>>>;
|
3079
|
+
readonly [$reprPartial]: Prettify<Partial<InferPartialRecord<TProps>>> | undefined;
|
2829
3080
|
}
|
2830
3081
|
type AnyUnstruct = Unstruct<any>;
|
2831
3082
|
interface LooseDecorated<TInner extends BaseData = BaseData, TAttribs extends unknown[] = unknown[]> {
|
@@ -2878,6 +3129,25 @@ interface Snippet {
|
|
2878
3129
|
readonly value: unknown;
|
2879
3130
|
readonly dataType: AnyData | UnknownData;
|
2880
3131
|
}
|
3132
|
+
type UnwrapDecorated<TData extends BaseData> = TData extends {
|
3133
|
+
readonly type: 'decorated';
|
3134
|
+
readonly inner: infer TInner;
|
3135
|
+
} ? TInner extends BaseData ? UnwrapDecorated<TInner> : TData : TData;
|
3136
|
+
type HasNestedType<TData extends [BaseData], TType extends string> = UnwrapDecorated<TData[0]> extends {
|
3137
|
+
readonly type: TType;
|
3138
|
+
} ? true : UnwrapDecorated<TData[0]> extends {
|
3139
|
+
readonly type: 'array';
|
3140
|
+
readonly elementType: infer TElement;
|
3141
|
+
} ? TElement extends BaseData ? UnwrapDecorated<TElement> extends {
|
3142
|
+
readonly type: TType;
|
3143
|
+
} ? true : HasNestedType<[TElement], TType> : false : UnwrapDecorated<TData[0]> extends {
|
3144
|
+
readonly type: 'struct';
|
3145
|
+
readonly propTypes: infer TProps;
|
3146
|
+
} ? TProps extends Record<string, BaseData> ? true extends {
|
3147
|
+
[K in keyof TProps]: UnwrapDecorated<TProps[K]> extends {
|
3148
|
+
readonly type: TType;
|
3149
|
+
} ? true : HasNestedType<[TProps[K]], TType>;
|
3150
|
+
}[keyof TProps] ? true : false : false : false;
|
2881
3151
|
|
2882
3152
|
declare const builtinNames: readonly ["vertex_index", "instance_index", "position", "clip_distances", "front_facing", "frag_depth", "sample_index", "sample_mask", "fragment", "local_invocation_id", "local_invocation_index", "global_invocation_id", "workgroup_id", "num_workgroups", "subgroup_invocation_id", "subgroup_size"];
|
2883
3153
|
type BuiltinName = (typeof builtinNames)[number];
|
@@ -2888,6 +3158,9 @@ type ExtractAttributes<T> = T extends {
|
|
2888
3158
|
type Undecorate<T> = T extends {
|
2889
3159
|
readonly inner: infer TInner;
|
2890
3160
|
} ? TInner : T;
|
3161
|
+
type UndecorateRecord<T extends Record<string, unknown>> = {
|
3162
|
+
[Key in keyof T]: Undecorate<T[Key]>;
|
3163
|
+
};
|
2891
3164
|
/**
|
2892
3165
|
* Decorates a data-type `TData` with an attribute `TAttrib`.
|
2893
3166
|
*
|
@@ -2983,25 +3256,26 @@ declare function interpolate<TInterpolation extends PerspectiveOrLinearInterpola
|
|
2983
3256
|
declare function interpolate<TInterpolation extends FlatInterpolationType, TData extends FlatInterpolatableData>(interpolationType: TInterpolation, data: TData): Decorate<TData, Interpolate<TInterpolation>>;
|
2984
3257
|
declare function isBuiltin<T extends Decorated<AnyWgslData, AnyAttribute[]> | LooseDecorated<AnyLooseData, AnyAttribute[]>>(value: T | unknown): value is T;
|
2985
3258
|
|
2986
|
-
|
2987
|
-
* Information extracted from transpiling a JS function.
|
2988
|
-
*/
|
2989
|
-
type TranspilationResult = {
|
2990
|
-
params: tinyest.FuncParameter[];
|
2991
|
-
body: tinyest.Block;
|
2992
|
-
/**
|
2993
|
-
* All identifiers found in the function code that are not declared in the
|
2994
|
-
* function itself, or in the block that is accessing that identifier.
|
2995
|
-
*/
|
2996
|
-
externalNames: string[];
|
2997
|
-
};
|
3259
|
+
type AnyFn = (...args: never[]) => unknown;
|
2998
3260
|
type InferArgs<T extends unknown[]> = {
|
2999
3261
|
[Idx in keyof T]: Infer<T[Idx]>;
|
3000
3262
|
};
|
3001
|
-
type
|
3002
|
-
|
3003
|
-
|
3004
|
-
|
3263
|
+
type InheritTupleValues<T, From> = {
|
3264
|
+
[K in keyof T]: K extends keyof From ? From[K] : never;
|
3265
|
+
};
|
3266
|
+
/**
|
3267
|
+
* Returns a type that has arg and return types of `T`, but argument
|
3268
|
+
* names of `From`
|
3269
|
+
*
|
3270
|
+
* Wrapped in an object type with `result` prop just so that it's easier
|
3271
|
+
* to remove InheritArgNames<...> from Intellisense with Prettify<T>['result']
|
3272
|
+
*/
|
3273
|
+
type InheritArgNames<T extends AnyFn, From extends AnyFn> = {
|
3274
|
+
result: (...args: Parameters<((...args: InheritTupleValues<Parameters<From>, Parameters<T>>) => ReturnType<T>) & T>) => ReturnType<T>;
|
3275
|
+
};
|
3276
|
+
type InferImplSchema<ImplSchema extends AnyFn> = (...args: InferArgs<Parameters<ImplSchema>>) => Infer<ReturnType<ImplSchema>>;
|
3277
|
+
type Implementation<ImplSchema extends AnyFn = AnyFn> = string | InferImplSchema<ImplSchema>;
|
3278
|
+
type BaseIOData = Bool | F32 | F16 | I32 | U32 | Vec2f | Vec3f | Vec4f | Vec2h | Vec3h | Vec4h | Vec2i | Vec3i | Vec4i | Vec2u | Vec3u | Vec4u;
|
3005
3279
|
type IOData = BaseIOData | Decorated<BaseIOData, AnyAttribute[]> | BuiltinClipDistances;
|
3006
3280
|
type IORecord<TElementType extends IOData = IOData> = Record<string, TElementType>;
|
3007
3281
|
/**
|
@@ -3049,6 +3323,7 @@ type TgpuComputeFnShell<ComputeIn extends IORecord<AnyComputeBuiltin>> = TgpuCom
|
|
3049
3323
|
*/ ((implementation: string) => TgpuComputeFn<ComputeIn>);
|
3050
3324
|
};
|
3051
3325
|
interface TgpuComputeFn<ComputeIn extends IORecord<AnyComputeBuiltin> = any> extends TgpuNamable {
|
3326
|
+
readonly [$internal]: true;
|
3052
3327
|
readonly shell: TgpuComputeFnShellHeader<ComputeIn>;
|
3053
3328
|
$uses(dependencyMap: Record<string, unknown>): this;
|
3054
3329
|
}
|
@@ -3060,4 +3335,4 @@ declare function computeFn<ComputeIn extends IORecord<AnyComputeBuiltin>>(option
|
|
3060
3335
|
workgroupSize: number[];
|
3061
3336
|
}): TgpuComputeFnShell<ComputeIn>;
|
3062
3337
|
|
3063
|
-
export { type
|
3338
|
+
export { type Storage as $, type AnyWgslData as A, isSlot as B, isComparisonSampler as C, type Disarray as D, isSampler as E, isSampledTextureView as F, isStorageTextureView as G, isTexture as H, type Infer as I, isUsableAsRender as J, isUsableAsSampled as K, isUsableAsStorage as L, asMutable as M, asReadonly as N, asUniform as O, isUsableAsUniform as P, isBufferShorthand as Q, RandomNameRegistry as R, StrictNameRegistry as S, type TgpuBindGroupLayout as T, isTgpuFn as U, type Configurable as V, type Wgsl as W, type WithBinding as X, type WithCompute as Y, type WithFragment as Z, type WithVertex as _, type TgpuBindGroup as a, type Vec3h as a$, type StorageFlag as a0, type TgpuRenderPipeline as a1, type TgpuComputePipeline as a2, type IndexFlag as a3, type Uniform as a4, type UniformFlag as a5, type Vertex as a6, type VertexFlag as a7, type TgpuBufferMutable as a8, type TgpuBufferReadonly as a9, type TgpuLayoutStorageTexture as aA, type TgpuLayoutTexture as aB, type TgpuLayoutUniform as aC, type TgpuFnShell as aD, type TgpuVertexFn as aE, type TgpuVertexFnShell as aF, type TgpuFragmentFn as aG, type TgpuFragmentFnShell as aH, type TgpuComputeFn as aI, type TgpuComputeFnShell as aJ, type TgpuDeclare as aK, type INTERNAL_GlobalExt as aL, type Bool as aM, type F16 as aN, type F32 as aO, type I32 as aP, type U16 as aQ, type U32 as aR, type WgslStruct as aS, type Ptr as aT, type Vec2b as aU, type Vec2f as aV, type Vec2h as aW, type Vec2i as aX, type Vec2u as aY, type Vec3b as aZ, type Vec3f as a_, type TgpuBufferUniform as aa, type TgpuMutable as ab, type TgpuReadonly as ac, type TgpuUniform as ad, type Eventual as ae, type TgpuAnyTextureView as af, type TgpuMutableTexture as ag, type TgpuReadonlyTexture as ah, type TgpuSampledTexture as ai, type TgpuTexture as aj, type TgpuWriteonlyTexture as ak, type TextureProps as al, type Render as am, type Sampled as an, type TgpuConst as ao, type TgpuVar as ap, type VariableScope as aq, type TgpuSampler as ar, type BindLayoutEntry as as, type ExtractBindGroupInputFromLayout as at, type LayoutEntryToInput as au, type TgpuLayoutComparisonSampler as av, type TgpuLayoutEntry as aw, type TgpuLayoutExternalTexture as ax, type TgpuLayoutSampler as ay, type TgpuLayoutStorage as az, type TgpuRoot as b, builtin as b$, type Vec3i as b0, type Vec3u as b1, type Vec4b as b2, type Vec4f as b3, type Vec4h as b4, type Vec4i as b5, type Vec4u as b6, type BaseData as b7, type Unstruct as b8, type Atomic as b9, type v2b as bA, type v2f as bB, type v2i as bC, type v2u as bD, type v3b as bE, type v3f as bF, type v3i as bG, type v3u as bH, type v4b as bI, type v4f as bJ, type v4i as bK, type v4u as bL, type AnyLooseData as bM, type LooseDecorated as bN, align as bO, type AnyAttribute as bP, type HasCustomLocation as bQ, interpolate as bR, type IsBuiltin as bS, isBuiltin as bT, location as bU, size as bV, isData as bW, isDisarray as bX, isLooseData as bY, isLooseDecorated as bZ, isUnstruct as b_, isAlignAttrib as ba, isAtomic as bb, isBuiltinAttrib as bc, isDecorated as bd, isInterpolateAttrib as be, isLocationAttrib as bf, isPtr as bg, isSizeAttrib as bh, isWgslArray as bi, isWgslData as bj, isWgslStruct as bk, Void as bl, type Align as bm, type AnyVecInstance as bn, type AnyWgslStruct as bo, type Builtin as bp, type Decorated as bq, type Interpolate as br, type Location as bs, type m2x2f as bt, type m3x3f as bu, type m4x4f as bv, type Mat2x2f as bw, type Mat3x3f as bx, type Mat4x4f as by, type Size as bz, type TgpuFn as c, type AnyNumericVecInstance as c$, type AnyBuiltin as c0, type BuiltinClipDistances as c1, type BuiltinFragDepth as c2, type BuiltinFrontFacing as c3, type BuiltinGlobalInvocationId as c4, type BuiltinInstanceIndex as c5, type BuiltinLocalInvocationId as c6, type BuiltinLocalInvocationIndex as c7, type BuiltinNumWorkgroups as c8, type BuiltinPosition as c9, sint16x2 as cA, sint16x4 as cB, unorm16 as cC, unorm16x2 as cD, unorm16x4 as cE, snorm16 as cF, snorm16x2 as cG, snorm16x4 as cH, float16 as cI, float16x2 as cJ, float16x4 as cK, float32 as cL, float32x2 as cM, float32x3 as cN, float32x4 as cO, uint32 as cP, uint32x2 as cQ, uint32x3 as cR, uint32x4 as cS, sint32 as cT, sint32x2 as cU, sint32x3 as cV, sint32x4 as cW, unorm10_10_10_2 as cX, unorm8x4_bgra as cY, type PackedData as cZ, type TgpuDualFn as c_, type BuiltinSampleIndex as ca, type BuiltinSampleMask as cb, type BuiltinVertexIndex as cc, type BuiltinWorkgroupId as cd, type InferGPU as ce, type InferPartial as cf, type FormatToWGSLType as cg, type TgpuVertexFormatData as ch, formatToWGSLType as ci, packedFormats as cj, uint8 as ck, uint8x2 as cl, uint8x4 as cm, sint8 as cn, sint8x2 as co, sint8x4 as cp, unorm8 as cq, unorm8x2 as cr, unorm8x4 as cs, snorm8 as ct, snorm8x2 as cu, snorm8x4 as cv, uint16 as cw, uint16x2 as cx, uint16x4 as cy, sint16 as cz, type TgpuBufferUsage as d, type AnyMatInstance as d0, type vBaseForMat as d1, type mBaseForVec as d2, type AnyFloatVecInstance as d3, type v3h as d4, type v2h as d5, type v4h as d6, type AnyVec2Instance as d7, type AnyVec3Instance as d8, type AnyBooleanVecInstance as d9, type atomicI32 as da, type atomicU32 as db, type TgpuStorageTexture as dc, type TexelData as dd, type ChannelData as de, type TgpuAccessor as e, type TgpuDerived as f, type TgpuSlot as g, type TgpuVertexLayout as h, type WgslArray as i, type TgpuBuffer as j, type AnyData as k, fn as l, bindGroupLayout as m, fragmentFn as n, vertexFn as o, computeFn as p, privateVar as q, constant as r, declare as s, sampler as t, comparisonSampler as u, vertexLayout as v, workgroupVar as w, isBuffer as x, isUsableAsVertex as y, isDerived as z };
|