typegpu 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,749 @@
1
+ import { D as Decorated, U as U32, r as Builtin, d as Vec4f, W as WgslArray, F as F32, l as Vec3u, B as BaseWgslData, s as Bool, b as I32, a as F16, n as WgslStruct, A as AnyWgslData, I as Infer$1, N as NativeVec2u, t as NativeVec4u, u as NativeVec2i, v as NativeVec4i, w as NativeVec2f, x as NativeVec4f, y as NativeVec3f, z as NativeVec3u, C as NativeVec3i, E as InferRecord, G as m2x2f, H as m3x3f, J as m4x4f, M as Mat2x2f, K as v2f, O as Mat3x3f, P as v3f, Q as Mat4x4f, R as v4f, S as Atomic, T as Align, X as Size, L as Location, Y as Interpolate, Z as InterpolationType, _ as PerspectiveOrLinearInterpolationType, $ as PerspectiveOrLinearInterpolatableData, a0 as FlatInterpolationType, a1 as FlatInterpolatableData, o as WgslTypeLiteral } from './vector-BSez01sn.cjs';
2
+
3
+ /**
4
+ * Can be assigned a name. Not to be confused with
5
+ * being able to HAVE a name.
6
+ */
7
+ interface TgpuNamable {
8
+ $name(label?: string | undefined): this;
9
+ }
10
+
11
+ /**
12
+ * Strips schema types down to their most basic forms. (native -> exotic)
13
+ * This is used by schema constructors to be able to ingest native schemas (created by TypeGPU), and
14
+ * spit out a type that matches non-native schemas as well.
15
+ */
16
+ type Exotic<T> = T extends {
17
+ readonly '~exotic': infer TExotic;
18
+ } ? TExotic : T;
19
+ type ExoticArray<T> = T extends unknown[] | [] ? {
20
+ [Key in keyof T]: Exotic<T[Key]>;
21
+ } : T;
22
+ type ExoticRecord<T> = T extends Record<string | number | symbol, unknown> ? {
23
+ [Key in keyof T]: Exotic<T[Key]>;
24
+ } : T;
25
+
26
+ type BuiltinVertexIndex = Decorated<U32, [Builtin<'vertex_index'>]>;
27
+ type BuiltinInstanceIndex = Decorated<U32, [Builtin<'instance_index'>]>;
28
+ type BuiltinPosition = Decorated<Vec4f, [Builtin<'position'>]>;
29
+ type BuiltinClipDistances = Decorated<WgslArray<U32>, [
30
+ Builtin<'clip_distances'>
31
+ ]>;
32
+ type BuiltinFrontFacing = Decorated<F32, [Builtin<'front_facing'>]>;
33
+ type BuiltinFragDepth = Decorated<F32, [Builtin<'frag_depth'>]>;
34
+ type BuiltinSampleIndex = Decorated<U32, [Builtin<'sample_index'>]>;
35
+ type BuiltinSampleMask = Decorated<U32, [Builtin<'sample_mask'>]>;
36
+ type BuiltinFragment = Decorated<Vec4f, [Builtin<'fragment'>]>;
37
+ type BuiltinLocalInvocationId = Decorated<Vec3u, [
38
+ Builtin<'local_invocation_id'>
39
+ ]>;
40
+ type BuiltinLocalInvocationIndex = Decorated<U32, [
41
+ Builtin<'local_invocation_index'>
42
+ ]>;
43
+ type BuiltinGlobalInvocationId = Decorated<Vec3u, [
44
+ Builtin<'global_invocation_id'>
45
+ ]>;
46
+ type BuiltinWorkgroupId = Decorated<Vec3u, [Builtin<'workgroup_id'>]>;
47
+ type BuiltinNumWorkgroups = Decorated<Vec3u, [
48
+ Builtin<'num_workgroups'>
49
+ ]>;
50
+ declare const builtin: {
51
+ readonly vertexIndex: BuiltinVertexIndex;
52
+ readonly instanceIndex: BuiltinInstanceIndex;
53
+ readonly position: BuiltinPosition;
54
+ readonly clipDistances: BuiltinClipDistances;
55
+ readonly frontFacing: BuiltinFrontFacing;
56
+ readonly fragDepth: BuiltinFragDepth;
57
+ readonly sampleIndex: BuiltinSampleIndex;
58
+ readonly sampleMask: BuiltinSampleMask;
59
+ readonly localInvocationId: BuiltinLocalInvocationId;
60
+ readonly localInvocationIndex: BuiltinLocalInvocationIndex;
61
+ readonly globalInvocationId: BuiltinGlobalInvocationId;
62
+ readonly workgroupId: BuiltinWorkgroupId;
63
+ readonly numWorkgroups: BuiltinNumWorkgroups;
64
+ };
65
+ type AnyBuiltin = (typeof builtin)[keyof typeof builtin];
66
+ type OmitBuiltins<S> = S extends AnyBuiltin ? never : S extends BaseWgslData ? S : {
67
+ [Key in keyof S as S[Key] extends AnyBuiltin ? never : Key]: S[Key];
68
+ };
69
+
70
+ /**
71
+ * A schema that represents a boolean value. (equivalent to `bool` in WGSL)
72
+ */
73
+ declare const bool: Bool;
74
+ /**
75
+ * Unsigned 32-bit integer schema representing a single WGSL u32 value.
76
+ */
77
+ type NativeU32 = U32 & {
78
+ '~exotic': U32;
79
+ } & ((v: number | boolean) => number);
80
+ /**
81
+ * A schema that represents an unsigned 32-bit integer value. (equivalent to `u32` in WGSL)
82
+ *
83
+ * Can also be called to cast a value to an u32 in accordance with WGSL casting rules.
84
+ *
85
+ * @example
86
+ * const value = u32(3.14); // 3
87
+ * @example
88
+ * const value = u32(-1); // 4294967295
89
+ * @example
90
+ * const value = u32(-3.1); // 0
91
+ */
92
+ declare const u32: NativeU32;
93
+ /**
94
+ * Signed 32-bit integer schema representing a single WGSL i32 value.
95
+ */
96
+ type NativeI32 = I32 & {
97
+ '~exotic': I32;
98
+ } & ((v: number | boolean) => number);
99
+ /**
100
+ * A schema that represents a signed 32-bit integer value. (equivalent to `i32` in WGSL)
101
+ *
102
+ * Can also be called to cast a value to an i32 in accordance with WGSL casting rules.
103
+ *
104
+ * @example
105
+ * const value = i32(3.14); // 3
106
+ * @example
107
+ * const value = i32(-3.9); // -3
108
+ * @example
109
+ * const value = i32(10000000000) // 1410065408
110
+ */
111
+ declare const i32: NativeI32;
112
+ /**
113
+ * 32-bit float schema representing a single WGSL f32 value.
114
+ */
115
+ type NativeF32 = F32 & {
116
+ '~exotic': F32;
117
+ } & ((v: number | boolean) => number);
118
+ /**
119
+ * A schema that represents a 32-bit float value. (equivalent to `f32` in WGSL)
120
+ *
121
+ * Can also be called to cast a value to an f32.
122
+ *
123
+ * @example
124
+ * const value = f32(true); // 1
125
+ */
126
+ declare const f32: NativeF32;
127
+ /**
128
+ * 16-bit float schema representing a single WGSL f16 value.
129
+ */
130
+ type NativeF16 = F16 & {
131
+ '~exotic': F16;
132
+ } & ((v: number | boolean) => number);
133
+ /**
134
+ * A schema that represents a 16-bit float value. (equivalent to `f16` in WGSL)
135
+ *
136
+ * Can also be called to cast a value to an f16.
137
+ *
138
+ * @example
139
+ * const value = f16(true); // 1
140
+ * @example
141
+ * const value = f16(21877.5); // 21872
142
+ */
143
+ declare const f16: NativeF16;
144
+
145
+ type Default<T, TDefault> = unknown extends T ? TDefault : T extends undefined ? TDefault : T;
146
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
147
+ type Prettify<T> = {
148
+ [K in keyof T]: T[K];
149
+ } & {};
150
+ /**
151
+ * Removes properties from record type that extend `Prop`
152
+ */
153
+ type OmitProps<T extends Record<string, unknown>, Prop> = Pick<T, {
154
+ [Key in keyof T]: T[Key] extends Prop ? never : Key;
155
+ }[keyof T]>;
156
+ /**
157
+ * The opposite of Readonly<T>
158
+ */
159
+ type Mutable<T> = {
160
+ -readonly [P in keyof T]: T[P];
161
+ };
162
+
163
+ /**
164
+ * Struct schema constructed via `d.struct` function.
165
+ *
166
+ * Responsible for handling reading and writing struct values
167
+ * between binary and JS representation. Takes into account
168
+ * the `byteAlignment` requirement of its members.
169
+ */
170
+ interface TgpuStruct<TProps extends Record<string, BaseWgslData>> extends WgslStruct<TProps>, TgpuNamable {
171
+ readonly '~exotic': WgslStruct<ExoticRecord<TProps>>;
172
+ }
173
+ /**
174
+ * Creates a struct schema that can be used to construct GPU buffers.
175
+ * Ensures proper alignment and padding of properties (as opposed to a `d.unstruct` schema).
176
+ * The order of members matches the passed in properties object.
177
+ *
178
+ * @example
179
+ * const CircleStruct = d.struct({ radius: d.f32, pos: d.vec3f });
180
+ *
181
+ * @param props Record with `string` keys and `TgpuData` values,
182
+ * each entry describing one struct member.
183
+ */
184
+ declare const struct: <TProps extends Record<string, AnyWgslData>>(props: TProps) => TgpuStruct<Prettify<ExoticRecord<TProps>>>;
185
+
186
+ /**
187
+ * Array schema constructed via `d.arrayOf` function.
188
+ *
189
+ * Responsible for handling reading and writing array values
190
+ * between binary and JS representation. Takes into account
191
+ * the `byteAlignment` requirement of its elementType.
192
+ */
193
+ interface TgpuArray<TElement extends AnyWgslData> extends WgslArray<TElement> {
194
+ readonly '~exotic': WgslArray<Exotic<TElement>>;
195
+ }
196
+ /**
197
+ * Creates an array schema that can be used to construct gpu buffers.
198
+ * Describes arrays with fixed-size length, storing elements of the same type.
199
+ *
200
+ * @example
201
+ * const LENGTH = 3;
202
+ * const array = d.arrayOf(d.u32, LENGTH);
203
+ *
204
+ * @param elementType The type of elements in the array.
205
+ * @param elementCount The number of elements in the array.
206
+ */
207
+ declare const arrayOf: <TElement extends AnyWgslData>(elementType: TElement, elementCount: number) => TgpuArray<Exotic<TElement>>;
208
+
209
+ 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"];
210
+ type VertexFormat = (typeof vertexFormats)[number];
211
+ declare const kindToDefaultFormatMap: {
212
+ readonly f32: "float32";
213
+ readonly vec2f: "float32x2";
214
+ readonly vec3f: "float32x3";
215
+ readonly vec4f: "float32x4";
216
+ readonly f16: "float16";
217
+ readonly vec2h: "float16x2";
218
+ readonly vec4h: "float16x4";
219
+ readonly u32: "uint32";
220
+ readonly vec2u: "uint32x2";
221
+ readonly vec3u: "uint32x3";
222
+ readonly vec4u: "uint32x4";
223
+ readonly i32: "sint32";
224
+ readonly vec2i: "sint32x2";
225
+ readonly vec3i: "sint32x3";
226
+ readonly vec4i: "sint32x4";
227
+ };
228
+ type KindToDefaultFormatMap = typeof kindToDefaultFormatMap;
229
+ interface TgpuVertexAttrib<TFormat extends VertexFormat = VertexFormat> {
230
+ readonly format: TFormat;
231
+ readonly offset: number;
232
+ }
233
+ /**
234
+ * All vertex attribute formats that can be interpreted as
235
+ * an single or multi component u32 in a shader.
236
+ * https://www.w3.org/TR/webgpu/#vertex-formats
237
+ */
238
+ type U32CompatibleFormats = TgpuVertexAttrib<'uint8'> | TgpuVertexAttrib<'uint8x2'> | TgpuVertexAttrib<'uint8x4'> | TgpuVertexAttrib<'uint16'> | TgpuVertexAttrib<'uint16x2'> | TgpuVertexAttrib<'uint16x4'> | TgpuVertexAttrib<'uint32'> | TgpuVertexAttrib<'uint32x2'> | TgpuVertexAttrib<'uint32x3'> | TgpuVertexAttrib<'uint32x4'>;
239
+ /**
240
+ * All vertex attribute formats that can be interpreted as
241
+ * an single or multi component i32 in a shader.
242
+ * https://www.w3.org/TR/webgpu/#vertex-formats
243
+ */
244
+ type I32CompatibleFormats = TgpuVertexAttrib<'sint8'> | TgpuVertexAttrib<'sint8x2'> | TgpuVertexAttrib<'sint8x4'> | TgpuVertexAttrib<'sint16'> | TgpuVertexAttrib<'sint16x2'> | TgpuVertexAttrib<'sint16x4'> | TgpuVertexAttrib<'sint32'> | TgpuVertexAttrib<'sint32x2'> | TgpuVertexAttrib<'sint32x3'> | TgpuVertexAttrib<'sint32x4'>;
245
+ /**
246
+ * All vertex attribute formats that can be interpreted as
247
+ * an single or multi component f32 in a shader.
248
+ * https://www.w3.org/TR/webgpu/#vertex-formats
249
+ */
250
+ 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'>;
251
+ /**
252
+ * All vertex attribute formats that can be interpreted as
253
+ * a single or multi component f16 in a shader. (same as f32 on the shader side)
254
+ * https://www.w3.org/TR/webgpu/#vertex-formats
255
+ */
256
+ type F16CompatibleFormats = F32CompatibleFormats;
257
+ type KindToAcceptedAttribMap = {
258
+ u32: U32CompatibleFormats;
259
+ vec2u: U32CompatibleFormats;
260
+ vec3u: U32CompatibleFormats;
261
+ vec4u: U32CompatibleFormats;
262
+ i32: I32CompatibleFormats;
263
+ vec2i: I32CompatibleFormats;
264
+ vec3i: I32CompatibleFormats;
265
+ vec4i: I32CompatibleFormats;
266
+ f16: F16CompatibleFormats;
267
+ vec2h: F16CompatibleFormats;
268
+ vec3h: F16CompatibleFormats;
269
+ vec4h: F16CompatibleFormats;
270
+ f32: F32CompatibleFormats;
271
+ vec2f: F32CompatibleFormats;
272
+ vec3f: F32CompatibleFormats;
273
+ vec4f: F32CompatibleFormats;
274
+ };
275
+
276
+ type FormatToWGSLType<T extends VertexFormat> = (typeof formatToWGSLType)[T];
277
+ interface TgpuVertexFormatData<T extends VertexFormat> {
278
+ readonly '~repr': Infer$1<FormatToWGSLType<T>>;
279
+ readonly type: T;
280
+ }
281
+ declare const formatToWGSLType: {
282
+ readonly uint8: NativeU32;
283
+ readonly uint8x2: NativeVec2u;
284
+ readonly uint8x4: NativeVec4u;
285
+ readonly sint8: NativeI32;
286
+ readonly sint8x2: NativeVec2i;
287
+ readonly sint8x4: NativeVec4i;
288
+ readonly unorm8: NativeF32;
289
+ readonly unorm8x2: NativeVec2f;
290
+ readonly unorm8x4: NativeVec4f;
291
+ readonly snorm8: NativeF32;
292
+ readonly snorm8x2: NativeVec2f;
293
+ readonly snorm8x4: NativeVec4f;
294
+ readonly uint16: NativeU32;
295
+ readonly uint16x2: NativeVec2u;
296
+ readonly uint16x4: NativeVec4u;
297
+ readonly sint16: NativeI32;
298
+ readonly sint16x2: NativeVec2i;
299
+ readonly sint16x4: NativeVec4i;
300
+ readonly unorm16: NativeF32;
301
+ readonly unorm16x2: NativeVec2f;
302
+ readonly unorm16x4: NativeVec4f;
303
+ readonly snorm16: NativeF32;
304
+ readonly snorm16x2: NativeVec2f;
305
+ readonly snorm16x4: NativeVec4f;
306
+ readonly float16: NativeF32;
307
+ readonly float16x2: NativeVec2f;
308
+ readonly float16x4: NativeVec4f;
309
+ readonly float32: NativeF32;
310
+ readonly float32x2: NativeVec2f;
311
+ readonly float32x3: NativeVec3f;
312
+ readonly float32x4: NativeVec4f;
313
+ readonly uint32: NativeU32;
314
+ readonly uint32x2: NativeVec2u;
315
+ readonly uint32x3: NativeVec3u;
316
+ readonly uint32x4: NativeVec4u;
317
+ readonly sint32: NativeI32;
318
+ readonly sint32x2: NativeVec2i;
319
+ readonly sint32x3: NativeVec3i;
320
+ readonly sint32x4: NativeVec4i;
321
+ readonly 'unorm10-10-10-2': NativeVec4f;
322
+ readonly 'unorm8x4-bgra': NativeVec4f;
323
+ };
324
+ declare const packedFormats: string[];
325
+ type uint8 = TgpuVertexFormatData<'uint8'>;
326
+ declare const uint8: uint8;
327
+ type uint8x2 = TgpuVertexFormatData<'uint8x2'>;
328
+ declare const uint8x2: uint8x2;
329
+ type uint8x4 = TgpuVertexFormatData<'uint8x4'>;
330
+ declare const uint8x4: uint8x4;
331
+ type sint8 = TgpuVertexFormatData<'sint8'>;
332
+ declare const sint8: sint8;
333
+ type sint8x2 = TgpuVertexFormatData<'sint8x2'>;
334
+ declare const sint8x2: sint8x2;
335
+ type sint8x4 = TgpuVertexFormatData<'sint8x4'>;
336
+ declare const sint8x4: sint8x4;
337
+ type unorm8 = TgpuVertexFormatData<'unorm8'>;
338
+ declare const unorm8: unorm8;
339
+ type unorm8x2 = TgpuVertexFormatData<'unorm8x2'>;
340
+ declare const unorm8x2: unorm8x2;
341
+ type unorm8x4 = TgpuVertexFormatData<'unorm8x4'>;
342
+ declare const unorm8x4: unorm8x4;
343
+ type snorm8 = TgpuVertexFormatData<'snorm8'>;
344
+ declare const snorm8: snorm8;
345
+ type snorm8x2 = TgpuVertexFormatData<'snorm8x2'>;
346
+ declare const snorm8x2: snorm8x2;
347
+ type snorm8x4 = TgpuVertexFormatData<'snorm8x4'>;
348
+ declare const snorm8x4: snorm8x4;
349
+ type uint16 = TgpuVertexFormatData<'uint16'>;
350
+ declare const uint16: uint16;
351
+ type uint16x2 = TgpuVertexFormatData<'uint16x2'>;
352
+ declare const uint16x2: uint16x2;
353
+ type uint16x4 = TgpuVertexFormatData<'uint16x4'>;
354
+ declare const uint16x4: uint16x4;
355
+ type sint16 = TgpuVertexFormatData<'sint16'>;
356
+ declare const sint16: sint16;
357
+ type sint16x2 = TgpuVertexFormatData<'sint16x2'>;
358
+ declare const sint16x2: sint16x2;
359
+ type sint16x4 = TgpuVertexFormatData<'sint16x4'>;
360
+ declare const sint16x4: sint16x4;
361
+ type unorm16 = TgpuVertexFormatData<'unorm16'>;
362
+ declare const unorm16: unorm16;
363
+ type unorm16x2 = TgpuVertexFormatData<'unorm16x2'>;
364
+ declare const unorm16x2: unorm16x2;
365
+ type unorm16x4 = TgpuVertexFormatData<'unorm16x4'>;
366
+ declare const unorm16x4: unorm16x4;
367
+ type snorm16 = TgpuVertexFormatData<'snorm16'>;
368
+ declare const snorm16: snorm16;
369
+ type snorm16x2 = TgpuVertexFormatData<'snorm16x2'>;
370
+ declare const snorm16x2: snorm16x2;
371
+ type snorm16x4 = TgpuVertexFormatData<'snorm16x4'>;
372
+ declare const snorm16x4: snorm16x4;
373
+ type float16 = TgpuVertexFormatData<'float16'>;
374
+ declare const float16: float16;
375
+ type float16x2 = TgpuVertexFormatData<'float16x2'>;
376
+ declare const float16x2: float16x2;
377
+ type float16x4 = TgpuVertexFormatData<'float16x4'>;
378
+ declare const float16x4: float16x4;
379
+ type float32 = TgpuVertexFormatData<'float32'>;
380
+ declare const float32: float32;
381
+ type float32x2 = TgpuVertexFormatData<'float32x2'>;
382
+ declare const float32x2: float32x2;
383
+ type float32x3 = TgpuVertexFormatData<'float32x3'>;
384
+ declare const float32x3: float32x3;
385
+ type float32x4 = TgpuVertexFormatData<'float32x4'>;
386
+ declare const float32x4: float32x4;
387
+ type uint32 = TgpuVertexFormatData<'uint32'>;
388
+ declare const uint32: uint32;
389
+ type uint32x2 = TgpuVertexFormatData<'uint32x2'>;
390
+ declare const uint32x2: uint32x2;
391
+ type uint32x3 = TgpuVertexFormatData<'uint32x3'>;
392
+ declare const uint32x3: uint32x3;
393
+ type uint32x4 = TgpuVertexFormatData<'uint32x4'>;
394
+ declare const uint32x4: uint32x4;
395
+ type sint32 = TgpuVertexFormatData<'sint32'>;
396
+ declare const sint32: sint32;
397
+ type sint32x2 = TgpuVertexFormatData<'sint32x2'>;
398
+ declare const sint32x2: sint32x2;
399
+ type sint32x3 = TgpuVertexFormatData<'sint32x3'>;
400
+ declare const sint32x3: sint32x3;
401
+ type sint32x4 = TgpuVertexFormatData<'sint32x4'>;
402
+ declare const sint32x4: sint32x4;
403
+ type unorm10_10_10_2 = TgpuVertexFormatData<'unorm10-10-10-2'>;
404
+ declare const unorm10_10_10_2: unorm10_10_10_2;
405
+ type unorm8x4_bgra = TgpuVertexFormatData<'unorm8x4-bgra'>;
406
+ declare const unorm8x4_bgra: unorm8x4_bgra;
407
+ 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;
408
+
409
+ /**
410
+ * Array schema constructed via `d.disarrayOf` function.
411
+ *
412
+ * Useful for defining vertex buffers.
413
+ * Elements in the schema are not aligned in respect to their `byteAlignment`,
414
+ * unless they are explicitly decorated with the custom align attribute
415
+ * via `d.align` function.
416
+ */
417
+ interface Disarray<TElement extends BaseWgslData = BaseWgslData> {
418
+ readonly type: 'disarray';
419
+ readonly elementCount: number;
420
+ readonly elementType: TElement;
421
+ readonly '~repr': Infer$1<TElement>[];
422
+ }
423
+ /**
424
+ * Struct schema constructed via `d.unstruct` function.
425
+ *
426
+ * Useful for defining vertex buffers, as the standard layout restrictions do not apply.
427
+ * Members are not aligned in respect to their `byteAlignment`,
428
+ * unless they are explicitly decorated with the custom align attribute
429
+ * via `d.align` function.
430
+ */
431
+ interface Unstruct<TProps extends Record<string, BaseWgslData> = Record<string, BaseWgslData>> {
432
+ readonly type: 'unstruct';
433
+ readonly propTypes: TProps;
434
+ readonly '~repr': InferRecord<TProps>;
435
+ }
436
+ interface LooseDecorated<TInner extends BaseWgslData = BaseWgslData, TAttribs extends unknown[] = unknown[]> {
437
+ readonly type: 'loose-decorated';
438
+ readonly inner: TInner;
439
+ readonly attribs: TAttribs;
440
+ readonly '~repr': Infer$1<TInner>;
441
+ }
442
+ 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"];
443
+ type LooseTypeLiteral = (typeof looseTypeLiterals)[number];
444
+ type AnyLooseData = Disarray | Unstruct | LooseDecorated | PackedData;
445
+ declare function isLooseData(data: unknown): data is AnyLooseData;
446
+ /**
447
+ * Checks whether the passed in value is a disarray schema,
448
+ * as opposed to, e.g., a regular array schema.
449
+ *
450
+ * Array schemas can be used to describe uniform and storage buffers,
451
+ * whereas disarray schemas cannot. Disarrays are useful for
452
+ * defining vertex buffers instead.
453
+ *
454
+ * @example
455
+ * isDisarray(d.arrayOf(d.u32, 4)) // false
456
+ * isDisarray(d.disarrayOf(d.u32, 4)) // true
457
+ * isDisarray(d.vec3f) // false
458
+ */
459
+ declare function isDisarray<T extends Disarray>(schema: T | unknown): schema is T;
460
+ /**
461
+ * Checks whether passed in value is a unstruct schema,
462
+ * as opposed to, e.g., a struct schema.
463
+ *
464
+ * Struct schemas can be used to describe uniform and storage buffers,
465
+ * whereas unstruct schemas cannot. Unstructs are useful for
466
+ * defining vertex buffers instead.
467
+ *
468
+ * @example
469
+ * isUnstruct(d.struct({ a: d.u32 })) // false
470
+ * isUnstruct(d.unstruct({ a: d.u32 })) // true
471
+ * isUnstruct(d.vec3f) // false
472
+ */
473
+ declare function isUnstruct<T extends Unstruct>(schema: T | unknown): schema is T;
474
+ declare function isLooseDecorated<T extends LooseDecorated>(value: T | unknown): value is T;
475
+ declare function isData(value: unknown): value is AnyData;
476
+ type AnyData = AnyWgslData | AnyLooseData;
477
+
478
+ /**
479
+ * Creates an array schema that can be used to construct vertex buffers.
480
+ * Describes arrays with fixed-size length, storing elements of the same type.
481
+ *
482
+ * Elements in the schema are not aligned in respect to their `byteAlignment`,
483
+ * unless they are explicitly decorated with the custom align attribute
484
+ * via `d.align` function.
485
+ *
486
+ * @example
487
+ * const disarray = d.disarrayOf(d.vec3f, 3); // packed array of vec3f
488
+ *
489
+ * @example
490
+ * const disarray = d.disarrayOf(d.align(16, d.vec3f), 3);
491
+ *
492
+ * @param elementType The type of elements in the array.
493
+ * @param count The number of elements in the array.
494
+ */
495
+ declare const disarrayOf: <TElement extends AnyData>(elementType: TElement, count: number) => Disarray<Exotic<TElement>>;
496
+
497
+ /**
498
+ * Creates a loose struct schema that can be used to construct vertex buffers.
499
+ * Describes structs with members of both loose and non-loose types.
500
+ *
501
+ * The order of members matches the passed in properties object.
502
+ * Members are not aligned in respect to their `byteAlignment`,
503
+ * unless they are explicitly decorated with the custom align attribute
504
+ * via `d.align` function.
505
+ *
506
+ * @example
507
+ * const CircleStruct = d.unstruct({ radius: d.f32, pos: d.vec3f }); // packed struct with no padding
508
+ *
509
+ * @example
510
+ * const CircleStruct = d.unstruct({ radius: d.f32, pos: d.align(16, d.vec3f) });
511
+ *
512
+ * @param properties Record with `string` keys and `TgpuData` or `TgpuLooseData` values,
513
+ * each entry describing one struct member.
514
+ */
515
+ declare const unstruct: <TProps extends Record<string, BaseWgslData>>(properties: TProps) => Unstruct<ExoticRecord<TProps>>;
516
+
517
+ /**
518
+ * Type of the `d.mat2x2f` object/function: matrix data type schema/constructor
519
+ */
520
+ type NativeMat2x2f = Mat2x2f & {
521
+ '~exotic': Mat2x2f;
522
+ } & ((...elements: number[]) => m2x2f) & ((...columns: v2f[]) => m2x2f) & (() => m2x2f);
523
+ /**
524
+ *
525
+ * Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.
526
+ * Also a constructor function for this matrix type.
527
+ *
528
+ * @example
529
+ * const zero2x2 = mat2x2f(); // filled with zeros
530
+ *
531
+ * @example
532
+ * const mat = mat2x2f(0, 1, 2, 3);
533
+ * mat[0] // vec2f(0, 1)
534
+ * mat[1] // vec2f(2, 3)
535
+ *
536
+ * @example
537
+ * const mat = mat2x2f(
538
+ * vec2f(0, 1), // column 0
539
+ * vec2f(1, 2), // column 1
540
+ * );
541
+ *
542
+ * @example
543
+ * const buffer = root.createBuffer(d.mat2x2f, d.mat2x2f(0, 1, 2, 3)); // buffer holding a d.mat2x2f value, with an initial value of ((0, 1), (2, 3))
544
+ */
545
+ declare const mat2x2f: NativeMat2x2f;
546
+ /**
547
+ * Type of the `d.mat3x3f` object/function: matrix data type schema/constructor
548
+ */
549
+ type NativeMat3x3f = Mat3x3f & {
550
+ '~exotic': Mat3x3f;
551
+ } & ((...elements: number[]) => m3x3f) & ((...columns: v3f[]) => m3x3f) & (() => m3x3f);
552
+ /**
553
+ *
554
+ * Schema representing mat3x3f - a matrix with 3 rows and 3 columns, with elements of type f32.
555
+ * Also a constructor function for this matrix type.
556
+ *
557
+ * @example
558
+ * const zero3x3 = mat3x3f(); // filled with zeros
559
+ *
560
+ * @example
561
+ * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8);
562
+ * mat[0] // vec3f(0, 1, 2)
563
+ * mat[1] // vec3f(3, 4, 5)
564
+ * mat[2] // vec3f(6, 7, 8)
565
+ *
566
+ * @example
567
+ * const mat = mat3x3f(
568
+ * vec3f(0, 1, 2), // column 0
569
+ * vec3f(2, 3, 4), // column 1
570
+ * vec3f(5, 6, 7), // column 2
571
+ * );
572
+ *
573
+ * @example
574
+ * const buffer = root.createBuffer(d.mat3x3f, d.mat3x3f()); // buffer holding a d.mat3x3f value, with an initial value of mat3x3f filled with zeros
575
+ */
576
+ declare const mat3x3f: NativeMat3x3f;
577
+ /**
578
+ * Type of the `d.mat4x4f` object/function: matrix data type schema/constructor
579
+ */
580
+ type NativeMat4x4f = Mat4x4f & {
581
+ '~exotic': Mat4x4f;
582
+ } & ((...elements: number[]) => m4x4f) & ((...columns: v4f[]) => m4x4f) & (() => m4x4f);
583
+ /**
584
+ *
585
+ * Schema representing mat4x4f - a matrix with 4 rows and 4 columns, with elements of type f32.
586
+ * Also a constructor function for this matrix type.
587
+ *
588
+ * @example
589
+ * const zero4x4 = mat4x4f(); // filled with zeros
590
+ *
591
+ * @example
592
+ * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
593
+ * mat[0] // vec4f(0, 1, 2, 3)
594
+ * mat[1] // vec4f(4, 5, 6, 7)
595
+ * mat[2] // vec4f(8, 9, 10, 11)
596
+ * mat[3] // vec4f(12, 13, 14, 15)
597
+ *
598
+ * @example
599
+ * const mat = mat3x3f(
600
+ * vec4f(0, 1, 2, 3), // column 0
601
+ * vec4f(4, 5, 6, 7), // column 1
602
+ * vec4f(8, 9, 10, 11), // column 2
603
+ * vec4f(12, 13, 14, 15), // column 3
604
+ * );
605
+ *
606
+ * @example
607
+ * const buffer = root.createBuffer(d.mat4x4f, d.mat4x4f()); // buffer holding a d.mat4x4f value, with an initial value of mat4x4f filled with zeros
608
+ */
609
+ declare const mat4x4f: NativeMat4x4f;
610
+ declare function matToArray(mat: m2x2f | m3x3f | m4x4f): number[];
611
+
612
+ /**
613
+ * Marks a concrete integer scalar type schema (u32 or i32) as a WGSL atomic.
614
+ *
615
+ * @example
616
+ * const atomicU32 = d.atomic(d.u32);
617
+ * const atomicI32 = d.atomic(d.i32);
618
+ *
619
+ * @param data Underlying type schema.
620
+ */
621
+ declare function atomic<TSchema extends U32 | I32>(data: TSchema): Atomic<Exotic<TSchema>>;
622
+
623
+ 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"];
624
+ type BuiltinName = (typeof builtinNames)[number];
625
+ type AnyAttribute = Align<number> | Size<number> | Location<number> | Builtin<BuiltinName> | Interpolate<InterpolationType>;
626
+ type ExtractAttributes<T> = T extends {
627
+ readonly attribs: unknown[];
628
+ } ? T['attribs'] : [];
629
+ type Undecorate<T> = T extends {
630
+ readonly inner: infer TInner;
631
+ } ? TInner : T;
632
+ /**
633
+ * Decorates a data-type `TData` with an attribute `TAttrib`.
634
+ *
635
+ * - if `TData` is loose
636
+ * - if `TData` is already `LooseDecorated`
637
+ * - Prepend `TAttrib` to the existing attribute tuple.
638
+ * - else
639
+ * - Wrap `TData` with `LooseDecorated` and a single attribute `[TAttrib]`
640
+ * - else
641
+ * - if `TData` is already `Decorated`
642
+ * - Prepend `TAttrib` to the existing attribute tuple.
643
+ * - else
644
+ * - Wrap `TData` with `Decorated` and a single attribute `[TAttrib]`
645
+ */
646
+ type Decorate<TData extends BaseWgslData, TAttrib extends AnyAttribute> = TData['type'] extends WgslTypeLiteral ? Decorated<Undecorate<TData>, [TAttrib, ...ExtractAttributes<TData>]> : TData['type'] extends LooseTypeLiteral ? LooseDecorated<Undecorate<TData>, [TAttrib, ...ExtractAttributes<TData>]> : never;
647
+ type IsBuiltin<T> = ExtractAttributes<T>[number] extends [] ? false : ExtractAttributes<T>[number] extends Builtin<BuiltinName> ? true : false;
648
+ type HasCustomLocation<T> = ExtractAttributes<T>[number] extends [] ? false : ExtractAttributes<T>[number] extends Location<number> ? true : false;
649
+ /**
650
+ * Gives the wrapped data-type a custom byte alignment. Useful in order to
651
+ * fulfill uniform alignment requirements.
652
+ *
653
+ * @example
654
+ * const Data = d.struct({
655
+ * a: u32, // takes up 4 bytes
656
+ * // 12 bytes of padding, because `b` is custom aligned to multiples of 16 bytes
657
+ * b: d.align(16, u32),
658
+ * });
659
+ *
660
+ * @param alignment The multiple of bytes this data should align itself to.
661
+ * @param data The data-type to align.
662
+ */
663
+ declare function align<TAlign extends number, TData extends AnyData>(alignment: TAlign, data: TData): Decorate<Exotic<TData>, Align<TAlign>>;
664
+ /**
665
+ * Adds padding bytes after the wrapped data-type, until the whole value takes up `size` bytes.
666
+ *
667
+ * @example
668
+ * const Data = d.struct({
669
+ * a: d.size(16, u32), // takes up 16 bytes, instead of 4
670
+ * b: u32, // starts at byte 16, because `a` has a custom size
671
+ * });
672
+ *
673
+ * @param size The amount of bytes that should be reserved for this data-type.
674
+ * @param data The data-type to wrap.
675
+ */
676
+ declare function size<TSize extends number, TData extends AnyData>(size: TSize, data: TData): Decorate<Exotic<TData>, Size<TSize>>;
677
+ /**
678
+ * Assigns an explicit numeric location to a struct member or a parameter that has this type.
679
+ *
680
+ * @example
681
+ * const VertexOutput = {
682
+ * a: d.u32, // has implicit location 0
683
+ * b: d.location(5, d.u32),
684
+ * c: d.u32, // has implicit location 6
685
+ * };
686
+ *
687
+ * @param location The explicit numeric location.
688
+ * @param data The data-type to wrap.
689
+ */
690
+ declare function location<TLocation extends number, TData extends AnyData>(location: TLocation, data: TData): Decorate<Exotic<TData>, Location<TLocation>>;
691
+ /**
692
+ * Specifies how user-defined vertex shader output (fragment shader input)
693
+ * must be interpolated.
694
+ *
695
+ * Tip: Integer outputs cannot be interpolated.
696
+ *
697
+ * @example
698
+ * const VertexOutput = {
699
+ * a: d.f32, // has implicit 'perspective, center' interpolation
700
+ * b: d.interpolate('linear, sample', d.f32),
701
+ * };
702
+ *
703
+ * @param interpolationType How data should be interpolated.
704
+ * @param data The data-type to wrap.
705
+ */
706
+ declare function interpolate<TInterpolation extends PerspectiveOrLinearInterpolationType, TData extends PerspectiveOrLinearInterpolatableData>(interpolationType: TInterpolation, data: TData): Decorate<Exotic<TData>, Interpolate<TInterpolation>>;
707
+ /**
708
+ * Specifies how user-defined vertex shader output (fragment shader input)
709
+ * must be interpolated.
710
+ *
711
+ * Tip: Default sampling method of `flat` is `first`. Unless you specifically
712
+ * need deterministic behavior provided by `'flat, first'`, prefer explicit
713
+ * `'flat, either'` as it could be slightly faster in hardware.
714
+ *
715
+ * @example
716
+ * const VertexOutput = {
717
+ * a: d.f32, // has implicit 'perspective, center' interpolation
718
+ * b: d.interpolate('flat, either', d.u32), // integer outputs cannot interpolate
719
+ * };
720
+ *
721
+ * @param interpolationType How data should be interpolated.
722
+ * @param data The data-type to wrap.
723
+ */
724
+ declare function interpolate<TInterpolation extends FlatInterpolationType, TData extends FlatInterpolatableData>(interpolationType: TInterpolation, data: TData): Decorate<Exotic<TData>, Interpolate<TInterpolation>>;
725
+ declare function isBuiltin<T extends Decorated<AnyWgslData, AnyAttribute[]> | LooseDecorated<AnyLooseData, AnyAttribute[]>>(value: T | unknown): value is T;
726
+
727
+ /**
728
+ * Returns the size (in bytes) of data represented by the `schema`.
729
+ */
730
+ declare function PUBLIC_sizeOf(schema: AnyData): number;
731
+
732
+ /**
733
+ * Returns the alignment (in bytes) of data represented by the `schema`.
734
+ */
735
+ declare function PUBLIC_alignmentOf(schema: AnyData): number;
736
+
737
+ /**
738
+ * @module typegpu/data
739
+ */
740
+
741
+ /**
742
+ * Extracts the inferred representation of a resource.
743
+ * @example
744
+ * type A = Infer<F32> // => number
745
+ * type B = Infer<TgpuArray<F32>> // => number[]
746
+ */
747
+ type Infer<T> = Infer$1<Exotic<T>>;
748
+
749
+ export { type BuiltinVertexIndex as $, type AnyBuiltin as A, atomic as B, align as C, type Default as D, type Exotic as E, size as F, location as G, type HasCustomLocation as H, type IsBuiltin as I, interpolate as J, type KindToAcceptedAttribMap as K, type LooseDecorated as L, type Mutable as M, isBuiltin as N, type OmitBuiltins as O, type Prettify as P, isDisarray as Q, isUnstruct as R, isLooseDecorated as S, type TgpuNamable as T, type UnionToIntersection as U, type VertexFormat as V, isData as W, isLooseData as X, PUBLIC_sizeOf as Y, PUBLIC_alignmentOf as Z, builtin as _, type AnyAttribute as a, type BuiltinInstanceIndex as a0, type BuiltinPosition as a1, type BuiltinClipDistances as a2, type BuiltinFrontFacing as a3, type BuiltinFragDepth as a4, type BuiltinSampleIndex as a5, type BuiltinSampleMask as a6, type BuiltinFragment as a7, type BuiltinLocalInvocationId as a8, type BuiltinLocalInvocationIndex as a9, unorm16x4 as aA, snorm16 as aB, snorm16x2 as aC, snorm16x4 as aD, float16 as aE, float16x2 as aF, float16x4 as aG, float32 as aH, float32x2 as aI, float32x3 as aJ, float32x4 as aK, uint32 as aL, uint32x2 as aM, uint32x3 as aN, uint32x4 as aO, sint32 as aP, sint32x2 as aQ, sint32x3 as aR, sint32x4 as aS, unorm10_10_10_2 as aT, unorm8x4_bgra as aU, type PackedData as aV, type BuiltinGlobalInvocationId as aa, type BuiltinWorkgroupId as ab, type BuiltinNumWorkgroups as ac, type FormatToWGSLType as ad, type TgpuVertexFormatData as ae, packedFormats as af, uint8 as ag, uint8x2 as ah, uint8x4 as ai, sint8 as aj, sint8x2 as ak, sint8x4 as al, unorm8 as am, unorm8x2 as an, unorm8x4 as ao, snorm8 as ap, snorm8x2 as aq, snorm8x4 as ar, uint16 as as, uint16x2 as at, uint16x4 as au, sint16 as av, sint16x2 as aw, sint16x4 as ax, unorm16 as ay, unorm16x2 as az, type AnyData as b, type Decorate as c, type TgpuStruct as d, type Disarray as e, type Unstruct as f, type TgpuVertexAttrib as g, type KindToDefaultFormatMap as h, type OmitProps as i, type Infer as j, type ExoticArray as k, bool as l, f32 as m, f16 as n, i32 as o, type TgpuArray as p, arrayOf as q, type AnyLooseData as r, struct as s, disarrayOf as t, u32 as u, unstruct as v, mat2x2f as w, mat3x3f as x, mat4x4f as y, matToArray as z };