typegpu 0.5.3 → 0.5.4
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/README.md +1 -1
- package/attributes-BdU8hyQq.d.cts +435 -0
- package/attributes-CAsvE5Z9.d.ts +435 -0
- package/{chunk-RMXVIINO.js → chunk-5PJ3H5OR.js} +2 -2
- package/chunk-5PJ3H5OR.js.map +1 -0
- package/chunk-7UUBX6MC.cjs +4 -0
- package/chunk-7UUBX6MC.cjs.map +1 -0
- package/chunk-AKBL6GDL.js +4 -0
- package/chunk-AKBL6GDL.js.map +1 -0
- package/{chunk-FM3TKZFZ.cjs → chunk-URJCMUTT.cjs} +2 -2
- package/chunk-URJCMUTT.cjs.map +1 -0
- package/data/index.cjs +1 -1
- package/data/index.cjs.map +1 -1
- package/data/index.d.cts +51 -4
- package/data/index.d.ts +51 -4
- package/data/index.js +1 -1
- package/index.cjs +16 -16
- package/index.cjs.map +1 -1
- package/index.d.cts +92 -53
- package/index.d.ts +92 -53
- package/index.js +16 -16
- package/index.js.map +1 -1
- package/package.json +2 -2
- package/std/index.cjs +1 -1
- package/std/index.cjs.map +1 -1
- package/std/index.d.cts +141 -33
- package/std/index.d.ts +141 -33
- package/std/index.js +1 -1
- package/std/index.js.map +1 -1
- package/{wgslTypes-VtSRoe90.d.cts → wgslTypes-Bh2dG5qv.d.cts} +213 -405
- package/{wgslTypes-VtSRoe90.d.ts → wgslTypes-Bh2dG5qv.d.ts} +213 -405
- package/attributes-B4JpvOTz.d.ts +0 -159
- package/attributes-DSOqT8yA.d.cts +0 -159
- package/chunk-DVZNNZFQ.js +0 -2
- package/chunk-DVZNNZFQ.js.map +0 -1
- package/chunk-FM3TKZFZ.cjs.map +0 -1
- package/chunk-M4VUFFPZ.cjs +0 -4
- package/chunk-M4VUFFPZ.cjs.map +0 -1
- package/chunk-RMXVIINO.js.map +0 -1
- package/chunk-UHU5Z2IS.js +0 -4
- package/chunk-UHU5Z2IS.js.map +0 -1
- package/chunk-UPPJES6W.cjs +0 -2
- package/chunk-UPPJES6W.cjs.map +0 -1
package/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
**TypeGPU** is a TypeScript library that enhances the WebGPU API, allowing resource management in a type-safe, declarative way.
|
11
11
|
|
12
12
|
<div align="center">
|
13
|
-
<video autoplay muted loop src="https://github.com/user-attachments/assets/5bca716d-477d-44a1-a839-5df0c8d9044c"></video>
|
13
|
+
<video autoplay muted loop playsinline src="https://github.com/user-attachments/assets/5bca716d-477d-44a1-a839-5df0c8d9044c"></video>
|
14
14
|
</div>
|
15
15
|
|
16
16
|
## Documentation
|
@@ -0,0 +1,435 @@
|
|
1
|
+
import { D as Decorated, l as Vec3u, aa as Builtin, U as U32, d as Vec4f, q as WgslArray, F as F32, B as BaseData, $ as $repr, I as Infer, k as Vec2u, m as Vec4u, b as I32, h as Vec2i, j as Vec4i, V as Vec2f, c as Vec3f, i as Vec3i, A as AnyWgslData, s as InferPartial, T as TgpuNamable, P as Prettify, al as InferRecord, am as InferPartialRecord, a9 as Align, a8 as Size, L as Location, ab as Interpolate, an as InterpolationType, r as WgslTypeLiteral, ao as PerspectiveOrLinearInterpolationType, ap as PerspectiveOrLinearInterpolatableData, aq as FlatInterpolationType, ar as FlatInterpolatableData } from './wgslTypes-Bh2dG5qv.cjs';
|
2
|
+
|
3
|
+
type BuiltinVertexIndex = Decorated<U32, [Builtin<'vertex_index'>]>;
|
4
|
+
type BuiltinInstanceIndex = Decorated<U32, [Builtin<'instance_index'>]>;
|
5
|
+
type BuiltinPosition = Decorated<Vec4f, [Builtin<'position'>]>;
|
6
|
+
type BuiltinClipDistances = Decorated<WgslArray<U32>, [
|
7
|
+
Builtin<'clip_distances'>
|
8
|
+
]>;
|
9
|
+
type BuiltinFrontFacing = Decorated<F32, [Builtin<'front_facing'>]>;
|
10
|
+
type BuiltinFragDepth = Decorated<F32, [Builtin<'frag_depth'>]>;
|
11
|
+
type BuiltinSampleIndex = Decorated<U32, [Builtin<'sample_index'>]>;
|
12
|
+
type BuiltinSampleMask = Decorated<U32, [Builtin<'sample_mask'>]>;
|
13
|
+
type BuiltinLocalInvocationId = Decorated<Vec3u, [
|
14
|
+
Builtin<'local_invocation_id'>
|
15
|
+
]>;
|
16
|
+
type BuiltinLocalInvocationIndex = Decorated<U32, [
|
17
|
+
Builtin<'local_invocation_index'>
|
18
|
+
]>;
|
19
|
+
type BuiltinGlobalInvocationId = Decorated<Vec3u, [
|
20
|
+
Builtin<'global_invocation_id'>
|
21
|
+
]>;
|
22
|
+
type BuiltinWorkgroupId = Decorated<Vec3u, [Builtin<'workgroup_id'>]>;
|
23
|
+
type BuiltinNumWorkgroups = Decorated<Vec3u, [
|
24
|
+
Builtin<'num_workgroups'>
|
25
|
+
]>;
|
26
|
+
type BuiltinSubgroupInvocationId = Decorated<U32, [
|
27
|
+
Builtin<'subgroup_invocation_id'>
|
28
|
+
]>;
|
29
|
+
type BuiltinSubgroupSize = Decorated<U32, [Builtin<'subgroup_size'>]>;
|
30
|
+
declare const builtin: {
|
31
|
+
readonly vertexIndex: BuiltinVertexIndex;
|
32
|
+
readonly instanceIndex: BuiltinInstanceIndex;
|
33
|
+
readonly position: BuiltinPosition;
|
34
|
+
readonly clipDistances: BuiltinClipDistances;
|
35
|
+
readonly frontFacing: BuiltinFrontFacing;
|
36
|
+
readonly fragDepth: BuiltinFragDepth;
|
37
|
+
readonly sampleIndex: BuiltinSampleIndex;
|
38
|
+
readonly sampleMask: BuiltinSampleMask;
|
39
|
+
readonly localInvocationId: BuiltinLocalInvocationId;
|
40
|
+
readonly localInvocationIndex: BuiltinLocalInvocationIndex;
|
41
|
+
readonly globalInvocationId: BuiltinGlobalInvocationId;
|
42
|
+
readonly workgroupId: BuiltinWorkgroupId;
|
43
|
+
readonly numWorkgroups: BuiltinNumWorkgroups;
|
44
|
+
readonly subgroupInvocationId: BuiltinSubgroupInvocationId;
|
45
|
+
readonly subgroupSize: BuiltinSubgroupSize;
|
46
|
+
};
|
47
|
+
type AnyBuiltin = (typeof builtin)[keyof typeof builtin];
|
48
|
+
type AnyComputeBuiltin = BuiltinLocalInvocationId | BuiltinLocalInvocationIndex | BuiltinGlobalInvocationId | BuiltinWorkgroupId | BuiltinNumWorkgroups | BuiltinSubgroupInvocationId | BuiltinSubgroupSize;
|
49
|
+
type AnyFragmentInputBuiltin = BuiltinPosition | BuiltinFrontFacing | BuiltinSampleIndex | BuiltinSampleMask | BuiltinSubgroupInvocationId | BuiltinSubgroupSize;
|
50
|
+
type AnyFragmentOutputBuiltin = BuiltinFragDepth | BuiltinSampleMask;
|
51
|
+
type OmitBuiltins<S> = S extends AnyBuiltin ? never : S extends BaseData ? S : {
|
52
|
+
[Key in keyof S as S[Key] extends AnyBuiltin ? never : Key]: S[Key];
|
53
|
+
};
|
54
|
+
|
55
|
+
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"];
|
56
|
+
type VertexFormat = (typeof vertexFormats)[number];
|
57
|
+
declare const kindToDefaultFormatMap: {
|
58
|
+
readonly f32: "float32";
|
59
|
+
readonly vec2f: "float32x2";
|
60
|
+
readonly vec3f: "float32x3";
|
61
|
+
readonly vec4f: "float32x4";
|
62
|
+
readonly f16: "float16";
|
63
|
+
readonly vec2h: "float16x2";
|
64
|
+
readonly vec4h: "float16x4";
|
65
|
+
readonly u32: "uint32";
|
66
|
+
readonly vec2u: "uint32x2";
|
67
|
+
readonly vec3u: "uint32x3";
|
68
|
+
readonly vec4u: "uint32x4";
|
69
|
+
readonly i32: "sint32";
|
70
|
+
readonly vec2i: "sint32x2";
|
71
|
+
readonly vec3i: "sint32x3";
|
72
|
+
readonly vec4i: "sint32x4";
|
73
|
+
};
|
74
|
+
type KindToDefaultFormatMap = typeof kindToDefaultFormatMap;
|
75
|
+
interface TgpuVertexAttrib<TFormat extends VertexFormat = VertexFormat> {
|
76
|
+
readonly format: TFormat;
|
77
|
+
readonly offset: number;
|
78
|
+
}
|
79
|
+
/**
|
80
|
+
* All vertex attribute formats that can be interpreted as
|
81
|
+
* an single or multi component u32 in a shader.
|
82
|
+
* https://www.w3.org/TR/webgpu/#vertex-formats
|
83
|
+
*/
|
84
|
+
type U32CompatibleFormats = TgpuVertexAttrib<'uint8'> | TgpuVertexAttrib<'uint8x2'> | TgpuVertexAttrib<'uint8x4'> | TgpuVertexAttrib<'uint16'> | TgpuVertexAttrib<'uint16x2'> | TgpuVertexAttrib<'uint16x4'> | TgpuVertexAttrib<'uint32'> | TgpuVertexAttrib<'uint32x2'> | TgpuVertexAttrib<'uint32x3'> | TgpuVertexAttrib<'uint32x4'>;
|
85
|
+
/**
|
86
|
+
* All vertex attribute formats that can be interpreted as
|
87
|
+
* an single or multi component i32 in a shader.
|
88
|
+
* https://www.w3.org/TR/webgpu/#vertex-formats
|
89
|
+
*/
|
90
|
+
type I32CompatibleFormats = TgpuVertexAttrib<'sint8'> | TgpuVertexAttrib<'sint8x2'> | TgpuVertexAttrib<'sint8x4'> | TgpuVertexAttrib<'sint16'> | TgpuVertexAttrib<'sint16x2'> | TgpuVertexAttrib<'sint16x4'> | TgpuVertexAttrib<'sint32'> | TgpuVertexAttrib<'sint32x2'> | TgpuVertexAttrib<'sint32x3'> | TgpuVertexAttrib<'sint32x4'>;
|
91
|
+
/**
|
92
|
+
* All vertex attribute formats that can be interpreted as
|
93
|
+
* an single or multi component f32 in a shader.
|
94
|
+
* https://www.w3.org/TR/webgpu/#vertex-formats
|
95
|
+
*/
|
96
|
+
type F32CompatibleFormats = TgpuVertexAttrib<'unorm8'> | TgpuVertexAttrib<'unorm8x2'> | TgpuVertexAttrib<'unorm8x4'> | TgpuVertexAttrib<'snorm8'> | TgpuVertexAttrib<'snorm8x2'> | TgpuVertexAttrib<'snorm8x4'> | TgpuVertexAttrib<'unorm16'> | TgpuVertexAttrib<'unorm16x2'> | TgpuVertexAttrib<'unorm16x4'> | TgpuVertexAttrib<'snorm16'> | TgpuVertexAttrib<'snorm16x2'> | TgpuVertexAttrib<'snorm16x4'> | TgpuVertexAttrib<'float16'> | TgpuVertexAttrib<'float16x2'> | TgpuVertexAttrib<'float16x4'> | TgpuVertexAttrib<'float32'> | TgpuVertexAttrib<'float32x2'> | TgpuVertexAttrib<'float32x3'> | TgpuVertexAttrib<'float32x4'> | TgpuVertexAttrib<'unorm10-10-10-2'> | TgpuVertexAttrib<'unorm8x4-bgra'>;
|
97
|
+
/**
|
98
|
+
* All vertex attribute formats that can be interpreted as
|
99
|
+
* a single or multi component f16 in a shader. (same as f32 on the shader side)
|
100
|
+
* https://www.w3.org/TR/webgpu/#vertex-formats
|
101
|
+
*/
|
102
|
+
type F16CompatibleFormats = F32CompatibleFormats;
|
103
|
+
type KindToAcceptedAttribMap = {
|
104
|
+
u32: U32CompatibleFormats;
|
105
|
+
vec2u: U32CompatibleFormats;
|
106
|
+
vec3u: U32CompatibleFormats;
|
107
|
+
vec4u: U32CompatibleFormats;
|
108
|
+
i32: I32CompatibleFormats;
|
109
|
+
vec2i: I32CompatibleFormats;
|
110
|
+
vec3i: I32CompatibleFormats;
|
111
|
+
vec4i: I32CompatibleFormats;
|
112
|
+
f16: F16CompatibleFormats;
|
113
|
+
vec2h: F16CompatibleFormats;
|
114
|
+
vec3h: F16CompatibleFormats;
|
115
|
+
vec4h: F16CompatibleFormats;
|
116
|
+
f32: F32CompatibleFormats;
|
117
|
+
vec2f: F32CompatibleFormats;
|
118
|
+
vec3f: F32CompatibleFormats;
|
119
|
+
vec4f: F32CompatibleFormats;
|
120
|
+
};
|
121
|
+
|
122
|
+
type FormatToWGSLType<T extends VertexFormat> = (typeof formatToWGSLType)[T];
|
123
|
+
interface TgpuVertexFormatData<T extends VertexFormat> {
|
124
|
+
readonly type: T;
|
125
|
+
/** Type-token, not available at runtime */
|
126
|
+
readonly [$repr]: Infer<FormatToWGSLType<T>>;
|
127
|
+
}
|
128
|
+
declare const formatToWGSLType: {
|
129
|
+
readonly uint8: U32;
|
130
|
+
readonly uint8x2: Vec2u;
|
131
|
+
readonly uint8x4: Vec4u;
|
132
|
+
readonly sint8: I32;
|
133
|
+
readonly sint8x2: Vec2i;
|
134
|
+
readonly sint8x4: Vec4i;
|
135
|
+
readonly unorm8: F32;
|
136
|
+
readonly unorm8x2: Vec2f;
|
137
|
+
readonly unorm8x4: Vec4f;
|
138
|
+
readonly snorm8: F32;
|
139
|
+
readonly snorm8x2: Vec2f;
|
140
|
+
readonly snorm8x4: Vec4f;
|
141
|
+
readonly uint16: U32;
|
142
|
+
readonly uint16x2: Vec2u;
|
143
|
+
readonly uint16x4: Vec4u;
|
144
|
+
readonly sint16: I32;
|
145
|
+
readonly sint16x2: Vec2i;
|
146
|
+
readonly sint16x4: Vec4i;
|
147
|
+
readonly unorm16: F32;
|
148
|
+
readonly unorm16x2: Vec2f;
|
149
|
+
readonly unorm16x4: Vec4f;
|
150
|
+
readonly snorm16: F32;
|
151
|
+
readonly snorm16x2: Vec2f;
|
152
|
+
readonly snorm16x4: Vec4f;
|
153
|
+
readonly float16: F32;
|
154
|
+
readonly float16x2: Vec2f;
|
155
|
+
readonly float16x4: Vec4f;
|
156
|
+
readonly float32: F32;
|
157
|
+
readonly float32x2: Vec2f;
|
158
|
+
readonly float32x3: Vec3f;
|
159
|
+
readonly float32x4: Vec4f;
|
160
|
+
readonly uint32: U32;
|
161
|
+
readonly uint32x2: Vec2u;
|
162
|
+
readonly uint32x3: Vec3u;
|
163
|
+
readonly uint32x4: Vec4u;
|
164
|
+
readonly sint32: I32;
|
165
|
+
readonly sint32x2: Vec2i;
|
166
|
+
readonly sint32x3: Vec3i;
|
167
|
+
readonly sint32x4: Vec4i;
|
168
|
+
readonly 'unorm10-10-10-2': Vec4f;
|
169
|
+
readonly 'unorm8x4-bgra': Vec4f;
|
170
|
+
};
|
171
|
+
declare const packedFormats: string[];
|
172
|
+
type uint8 = TgpuVertexFormatData<'uint8'>;
|
173
|
+
declare const uint8: uint8;
|
174
|
+
type uint8x2 = TgpuVertexFormatData<'uint8x2'>;
|
175
|
+
declare const uint8x2: uint8x2;
|
176
|
+
type uint8x4 = TgpuVertexFormatData<'uint8x4'>;
|
177
|
+
declare const uint8x4: uint8x4;
|
178
|
+
type sint8 = TgpuVertexFormatData<'sint8'>;
|
179
|
+
declare const sint8: sint8;
|
180
|
+
type sint8x2 = TgpuVertexFormatData<'sint8x2'>;
|
181
|
+
declare const sint8x2: sint8x2;
|
182
|
+
type sint8x4 = TgpuVertexFormatData<'sint8x4'>;
|
183
|
+
declare const sint8x4: sint8x4;
|
184
|
+
type unorm8 = TgpuVertexFormatData<'unorm8'>;
|
185
|
+
declare const unorm8: unorm8;
|
186
|
+
type unorm8x2 = TgpuVertexFormatData<'unorm8x2'>;
|
187
|
+
declare const unorm8x2: unorm8x2;
|
188
|
+
type unorm8x4 = TgpuVertexFormatData<'unorm8x4'>;
|
189
|
+
declare const unorm8x4: unorm8x4;
|
190
|
+
type snorm8 = TgpuVertexFormatData<'snorm8'>;
|
191
|
+
declare const snorm8: snorm8;
|
192
|
+
type snorm8x2 = TgpuVertexFormatData<'snorm8x2'>;
|
193
|
+
declare const snorm8x2: snorm8x2;
|
194
|
+
type snorm8x4 = TgpuVertexFormatData<'snorm8x4'>;
|
195
|
+
declare const snorm8x4: snorm8x4;
|
196
|
+
type uint16 = TgpuVertexFormatData<'uint16'>;
|
197
|
+
declare const uint16: uint16;
|
198
|
+
type uint16x2 = TgpuVertexFormatData<'uint16x2'>;
|
199
|
+
declare const uint16x2: uint16x2;
|
200
|
+
type uint16x4 = TgpuVertexFormatData<'uint16x4'>;
|
201
|
+
declare const uint16x4: uint16x4;
|
202
|
+
type sint16 = TgpuVertexFormatData<'sint16'>;
|
203
|
+
declare const sint16: sint16;
|
204
|
+
type sint16x2 = TgpuVertexFormatData<'sint16x2'>;
|
205
|
+
declare const sint16x2: sint16x2;
|
206
|
+
type sint16x4 = TgpuVertexFormatData<'sint16x4'>;
|
207
|
+
declare const sint16x4: sint16x4;
|
208
|
+
type unorm16 = TgpuVertexFormatData<'unorm16'>;
|
209
|
+
declare const unorm16: unorm16;
|
210
|
+
type unorm16x2 = TgpuVertexFormatData<'unorm16x2'>;
|
211
|
+
declare const unorm16x2: unorm16x2;
|
212
|
+
type unorm16x4 = TgpuVertexFormatData<'unorm16x4'>;
|
213
|
+
declare const unorm16x4: unorm16x4;
|
214
|
+
type snorm16 = TgpuVertexFormatData<'snorm16'>;
|
215
|
+
declare const snorm16: snorm16;
|
216
|
+
type snorm16x2 = TgpuVertexFormatData<'snorm16x2'>;
|
217
|
+
declare const snorm16x2: snorm16x2;
|
218
|
+
type snorm16x4 = TgpuVertexFormatData<'snorm16x4'>;
|
219
|
+
declare const snorm16x4: snorm16x4;
|
220
|
+
type float16 = TgpuVertexFormatData<'float16'>;
|
221
|
+
declare const float16: float16;
|
222
|
+
type float16x2 = TgpuVertexFormatData<'float16x2'>;
|
223
|
+
declare const float16x2: float16x2;
|
224
|
+
type float16x4 = TgpuVertexFormatData<'float16x4'>;
|
225
|
+
declare const float16x4: float16x4;
|
226
|
+
type float32 = TgpuVertexFormatData<'float32'>;
|
227
|
+
declare const float32: float32;
|
228
|
+
type float32x2 = TgpuVertexFormatData<'float32x2'>;
|
229
|
+
declare const float32x2: float32x2;
|
230
|
+
type float32x3 = TgpuVertexFormatData<'float32x3'>;
|
231
|
+
declare const float32x3: float32x3;
|
232
|
+
type float32x4 = TgpuVertexFormatData<'float32x4'>;
|
233
|
+
declare const float32x4: float32x4;
|
234
|
+
type uint32 = TgpuVertexFormatData<'uint32'>;
|
235
|
+
declare const uint32: uint32;
|
236
|
+
type uint32x2 = TgpuVertexFormatData<'uint32x2'>;
|
237
|
+
declare const uint32x2: uint32x2;
|
238
|
+
type uint32x3 = TgpuVertexFormatData<'uint32x3'>;
|
239
|
+
declare const uint32x3: uint32x3;
|
240
|
+
type uint32x4 = TgpuVertexFormatData<'uint32x4'>;
|
241
|
+
declare const uint32x4: uint32x4;
|
242
|
+
type sint32 = TgpuVertexFormatData<'sint32'>;
|
243
|
+
declare const sint32: sint32;
|
244
|
+
type sint32x2 = TgpuVertexFormatData<'sint32x2'>;
|
245
|
+
declare const sint32x2: sint32x2;
|
246
|
+
type sint32x3 = TgpuVertexFormatData<'sint32x3'>;
|
247
|
+
declare const sint32x3: sint32x3;
|
248
|
+
type sint32x4 = TgpuVertexFormatData<'sint32x4'>;
|
249
|
+
declare const sint32x4: sint32x4;
|
250
|
+
type unorm10_10_10_2 = TgpuVertexFormatData<'unorm10-10-10-2'>;
|
251
|
+
declare const unorm10_10_10_2: unorm10_10_10_2;
|
252
|
+
type unorm8x4_bgra = TgpuVertexFormatData<'unorm8x4-bgra'>;
|
253
|
+
declare const unorm8x4_bgra: unorm8x4_bgra;
|
254
|
+
type PackedData = 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;
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Array schema constructed via `d.disarrayOf` function.
|
258
|
+
*
|
259
|
+
* Useful for defining vertex buffers.
|
260
|
+
* Elements in the schema are not aligned in respect to their `byteAlignment`,
|
261
|
+
* unless they are explicitly decorated with the custom align attribute
|
262
|
+
* via `d.align` function.
|
263
|
+
*/
|
264
|
+
interface Disarray<TElement extends BaseData = BaseData> {
|
265
|
+
readonly type: 'disarray';
|
266
|
+
readonly elementCount: number;
|
267
|
+
readonly elementType: TElement;
|
268
|
+
readonly [$repr]: Infer<TElement>[];
|
269
|
+
readonly '~reprPartial': {
|
270
|
+
idx: number;
|
271
|
+
value: InferPartial<TElement>;
|
272
|
+
}[];
|
273
|
+
}
|
274
|
+
/**
|
275
|
+
* Struct schema constructed via `d.unstruct` function.
|
276
|
+
*
|
277
|
+
* Useful for defining vertex buffers, as the standard layout restrictions do not apply.
|
278
|
+
* Members are not aligned in respect to their `byteAlignment`,
|
279
|
+
* unless they are explicitly decorated with the custom align attribute
|
280
|
+
* via `d.align` function.
|
281
|
+
*/
|
282
|
+
interface Unstruct<TProps extends Record<string, BaseData> = Record<string, BaseData>> extends TgpuNamable {
|
283
|
+
readonly label?: string | undefined;
|
284
|
+
readonly type: 'unstruct';
|
285
|
+
readonly propTypes: TProps;
|
286
|
+
readonly [$repr]: Prettify<InferRecord<TProps>>;
|
287
|
+
readonly '~reprPartial': Prettify<Partial<InferPartialRecord<TProps>>>;
|
288
|
+
}
|
289
|
+
interface LooseDecorated<TInner extends BaseData = BaseData, TAttribs extends unknown[] = unknown[]> {
|
290
|
+
readonly type: 'loose-decorated';
|
291
|
+
readonly inner: TInner;
|
292
|
+
readonly attribs: TAttribs;
|
293
|
+
readonly [$repr]: Infer<TInner>;
|
294
|
+
}
|
295
|
+
declare const looseTypeLiterals: readonly ["unstruct", "disarray", "loose-decorated", "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"];
|
296
|
+
type LooseTypeLiteral = (typeof looseTypeLiterals)[number];
|
297
|
+
type AnyLooseData = Disarray | Unstruct | LooseDecorated | PackedData;
|
298
|
+
declare function isLooseData(data: unknown): data is AnyLooseData;
|
299
|
+
/**
|
300
|
+
* Checks whether the passed in value is a disarray schema,
|
301
|
+
* as opposed to, e.g., a regular array schema.
|
302
|
+
*
|
303
|
+
* Array schemas can be used to describe uniform and storage buffers,
|
304
|
+
* whereas disarray schemas cannot. Disarrays are useful for
|
305
|
+
* defining vertex buffers instead.
|
306
|
+
*
|
307
|
+
* @example
|
308
|
+
* isDisarray(d.arrayOf(d.u32, 4)) // false
|
309
|
+
* isDisarray(d.disarrayOf(d.u32, 4)) // true
|
310
|
+
* isDisarray(d.vec3f) // false
|
311
|
+
*/
|
312
|
+
declare function isDisarray<T extends Disarray>(schema: T | unknown): schema is T;
|
313
|
+
/**
|
314
|
+
* Checks whether passed in value is a unstruct schema,
|
315
|
+
* as opposed to, e.g., a struct schema.
|
316
|
+
*
|
317
|
+
* Struct schemas can be used to describe uniform and storage buffers,
|
318
|
+
* whereas unstruct schemas cannot. Unstructs are useful for
|
319
|
+
* defining vertex buffers instead.
|
320
|
+
*
|
321
|
+
* @example
|
322
|
+
* isUnstruct(d.struct({ a: d.u32 })) // false
|
323
|
+
* isUnstruct(d.unstruct({ a: d.u32 })) // true
|
324
|
+
* isUnstruct(d.vec3f) // false
|
325
|
+
*/
|
326
|
+
declare function isUnstruct<T extends Unstruct>(schema: T | unknown): schema is T;
|
327
|
+
declare function isLooseDecorated<T extends LooseDecorated>(value: T | unknown): value is T;
|
328
|
+
declare function isData(value: unknown): value is AnyData;
|
329
|
+
type AnyData = AnyWgslData | AnyLooseData;
|
330
|
+
|
331
|
+
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"];
|
332
|
+
type BuiltinName = (typeof builtinNames)[number];
|
333
|
+
type AnyAttribute<AllowedBuiltins extends Builtin<BuiltinName> = Builtin<BuiltinName>> = Align<number> | Size<number> | Location<number> | Interpolate<InterpolationType> | AllowedBuiltins;
|
334
|
+
type ExtractAttributes<T> = T extends {
|
335
|
+
readonly attribs: unknown[];
|
336
|
+
} ? T['attribs'] : [];
|
337
|
+
type Undecorate<T> = T extends {
|
338
|
+
readonly inner: infer TInner;
|
339
|
+
} ? TInner : T;
|
340
|
+
/**
|
341
|
+
* Decorates a data-type `TData` with an attribute `TAttrib`.
|
342
|
+
*
|
343
|
+
* - if `TData` is loose
|
344
|
+
* - if `TData` is already `LooseDecorated`
|
345
|
+
* - Prepend `TAttrib` to the existing attribute tuple.
|
346
|
+
* - else
|
347
|
+
* - Wrap `TData` with `LooseDecorated` and a single attribute `[TAttrib]`
|
348
|
+
* - else
|
349
|
+
* - if `TData` is already `Decorated`
|
350
|
+
* - Prepend `TAttrib` to the existing attribute tuple.
|
351
|
+
* - else
|
352
|
+
* - Wrap `TData` with `Decorated` and a single attribute `[TAttrib]`
|
353
|
+
*/
|
354
|
+
type Decorate<TData extends BaseData, TAttrib extends AnyAttribute> = TData['type'] extends WgslTypeLiteral ? Decorated<Undecorate<TData>, [TAttrib, ...ExtractAttributes<TData>]> : TData['type'] extends LooseTypeLiteral ? LooseDecorated<Undecorate<TData>, [TAttrib, ...ExtractAttributes<TData>]> : never;
|
355
|
+
type IsBuiltin<T> = ExtractAttributes<T>[number] extends [] ? false : ExtractAttributes<T>[number] extends Builtin<BuiltinName> ? true : false;
|
356
|
+
type HasCustomLocation<T> = ExtractAttributes<T>[number] extends [] ? false : ExtractAttributes<T>[number] extends Location<number> ? true : false;
|
357
|
+
/**
|
358
|
+
* Gives the wrapped data-type a custom byte alignment. Useful in order to
|
359
|
+
* fulfill uniform alignment requirements.
|
360
|
+
*
|
361
|
+
* @example
|
362
|
+
* const Data = d.struct({
|
363
|
+
* a: u32, // takes up 4 bytes
|
364
|
+
* // 12 bytes of padding, because `b` is custom aligned to multiples of 16 bytes
|
365
|
+
* b: d.align(16, u32),
|
366
|
+
* });
|
367
|
+
*
|
368
|
+
* @param alignment The multiple of bytes this data should align itself to.
|
369
|
+
* @param data The data-type to align.
|
370
|
+
*/
|
371
|
+
declare function align<TAlign extends number, TData extends AnyData>(alignment: TAlign, data: TData): Decorate<TData, Align<TAlign>>;
|
372
|
+
/**
|
373
|
+
* Adds padding bytes after the wrapped data-type, until the whole value takes up `size` bytes.
|
374
|
+
*
|
375
|
+
* @example
|
376
|
+
* const Data = d.struct({
|
377
|
+
* a: d.size(16, u32), // takes up 16 bytes, instead of 4
|
378
|
+
* b: u32, // starts at byte 16, because `a` has a custom size
|
379
|
+
* });
|
380
|
+
*
|
381
|
+
* @param size The amount of bytes that should be reserved for this data-type.
|
382
|
+
* @param data The data-type to wrap.
|
383
|
+
*/
|
384
|
+
declare function size<TSize extends number, TData extends AnyData>(size: TSize, data: TData): Decorate<TData, Size<TSize>>;
|
385
|
+
/**
|
386
|
+
* Assigns an explicit numeric location to a struct member or a parameter that has this type.
|
387
|
+
*
|
388
|
+
* @example
|
389
|
+
* const VertexOutput = {
|
390
|
+
* a: d.u32, // has implicit location 0
|
391
|
+
* b: d.location(5, d.u32),
|
392
|
+
* c: d.u32, // has implicit location 6
|
393
|
+
* };
|
394
|
+
*
|
395
|
+
* @param location The explicit numeric location.
|
396
|
+
* @param data The data-type to wrap.
|
397
|
+
*/
|
398
|
+
declare function location<TLocation extends number, TData extends AnyData>(location: TLocation, data: TData): Decorate<TData, Location<TLocation>>;
|
399
|
+
/**
|
400
|
+
* Specifies how user-defined vertex shader output (fragment shader input)
|
401
|
+
* must be interpolated.
|
402
|
+
*
|
403
|
+
* Tip: Integer outputs cannot be interpolated.
|
404
|
+
*
|
405
|
+
* @example
|
406
|
+
* const VertexOutput = {
|
407
|
+
* a: d.f32, // has implicit 'perspective, center' interpolation
|
408
|
+
* b: d.interpolate('linear, sample', d.f32),
|
409
|
+
* };
|
410
|
+
*
|
411
|
+
* @param interpolationType How data should be interpolated.
|
412
|
+
* @param data The data-type to wrap.
|
413
|
+
*/
|
414
|
+
declare function interpolate<TInterpolation extends PerspectiveOrLinearInterpolationType, TData extends PerspectiveOrLinearInterpolatableData>(interpolationType: TInterpolation, data: TData): Decorate<TData, Interpolate<TInterpolation>>;
|
415
|
+
/**
|
416
|
+
* Specifies how user-defined vertex shader output (fragment shader input)
|
417
|
+
* must be interpolated.
|
418
|
+
*
|
419
|
+
* Tip: Default sampling method of `flat` is `first`. Unless you specifically
|
420
|
+
* need deterministic behavior provided by `'flat, first'`, prefer explicit
|
421
|
+
* `'flat, either'` as it could be slightly faster in hardware.
|
422
|
+
*
|
423
|
+
* @example
|
424
|
+
* const VertexOutput = {
|
425
|
+
* a: d.f32, // has implicit 'perspective, center' interpolation
|
426
|
+
* b: d.interpolate('flat, either', d.u32), // integer outputs cannot interpolate
|
427
|
+
* };
|
428
|
+
*
|
429
|
+
* @param interpolationType How data should be interpolated.
|
430
|
+
* @param data The data-type to wrap.
|
431
|
+
*/
|
432
|
+
declare function interpolate<TInterpolation extends FlatInterpolationType, TData extends FlatInterpolatableData>(interpolationType: TInterpolation, data: TData): Decorate<TData, Interpolate<TInterpolation>>;
|
433
|
+
declare function isBuiltin<T extends Decorated<AnyWgslData, AnyAttribute[]> | LooseDecorated<AnyLooseData, AnyAttribute[]>>(value: T | unknown): value is T;
|
434
|
+
|
435
|
+
export { unorm8x2 as $, type AnyAttribute as A, type BuiltinVertexIndex as B, type BuiltinLocalInvocationIndex as C, type Decorate as D, type BuiltinGlobalInvocationId as E, type BuiltinWorkgroupId as F, type BuiltinNumWorkgroups as G, type HasCustomLocation as H, type IsBuiltin as I, type AnyBuiltin as J, type KindToDefaultFormatMap as K, type LooseDecorated as L, type FormatToWGSLType as M, type TgpuVertexFormatData as N, type OmitBuiltins as O, formatToWGSLType as P, packedFormats as Q, uint8 as R, uint8x2 as S, type TgpuVertexAttrib as T, type Unstruct as U, type VertexFormat as V, uint8x4 as W, sint8 as X, sint8x2 as Y, sint8x4 as Z, unorm8 as _, type AnyComputeBuiltin as a, unorm8x4 as a0, snorm8 as a1, snorm8x2 as a2, snorm8x4 as a3, uint16 as a4, uint16x2 as a5, uint16x4 as a6, sint16 as a7, sint16x2 as a8, sint16x4 as a9, unorm16 as aa, unorm16x2 as ab, unorm16x4 as ac, snorm16 as ad, snorm16x2 as ae, snorm16x4 as af, float16 as ag, float16x2 as ah, float16x4 as ai, float32 as aj, float32x2 as ak, float32x3 as al, float32x4 as am, uint32 as an, uint32x2 as ao, uint32x3 as ap, uint32x4 as aq, sint32 as ar, sint32x2 as as, sint32x3 as at, sint32x4 as au, unorm10_10_10_2 as av, unorm8x4_bgra as aw, type PackedData as ax, type AnyFragmentInputBuiltin as b, type AnyFragmentOutputBuiltin as c, type Disarray as d, type KindToAcceptedAttribMap as e, type AnyData as f, type AnyLooseData as g, align as h, interpolate as i, isBuiltin as j, isDisarray as k, location as l, isUnstruct as m, isLooseDecorated as n, isData as o, isLooseData as p, builtin as q, type BuiltinInstanceIndex as r, size as s, type BuiltinPosition as t, type BuiltinClipDistances as u, type BuiltinFrontFacing as v, type BuiltinFragDepth as w, type BuiltinSampleIndex as x, type BuiltinSampleMask as y, type BuiltinLocalInvocationId as z };
|