typegpu 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/data/index.d.cts CHANGED
@@ -1,13 +1,94 @@
1
- import { AnySchema, Schema, Unwrap, ISerialOutput, ParseUnwrapped, ISerialInput, MaxValue, IMeasurer, ISchema, UnwrapRecord } from 'typed-binary';
1
+ import { Unwrap, AnySchema, Schema, ISerialOutput, ParseUnwrapped, ISerialInput, MaxValue, IMeasurer, ISchema, UnwrapRecord } from 'typed-binary';
2
2
  export { Parsed, Unwrap } from 'typed-binary';
3
- import { e as TgpuData, R as ResolutionCtx, A as AnyTgpuData, h as TgpuNamable, j as vec2f, b as vec3f, k as vec4f, l as TgpuPointer, m as AnyTgpuLooseData, n as TgpuLooseData } from '../tgpuBuffer-BVk2wCHR.cjs';
4
- export { t as Vec2f, u as Vec2i, w as Vec2u, x as Vec3f, y as Vec3i, z as Vec3u, B as Vec4f, C as Vec4i, D as Vec4u, o as VecKind, p as vec2i, q as vec2u, c as vec3i, d as vec3u, r as vec4i, s as vec4u, v as vecBase } from '../tgpuBuffer-BVk2wCHR.cjs';
3
+ import { A as AnyTgpuData, x as AnyTgpuLooseData, r as TgpuData, y as TgpuLooseData, R as ResolutionCtx, a as TgpuNamable, z as vec2f, o as vec3f, C as vec4f, N as NumberArrayView, D as Vec2u, V as Vec4u, G as Vec2i, i as Vec4i, H as Vec2f, j as Vec4f, F as F32, J as Vec3f, h as U32, K as Vec3u, I as I32, L as Vec3i, M as TgpuPointer } from '../types-CGmVkuAt.cjs';
4
+ export { P as Bool, Z as VecKind, Q as bool, Y as f32, X as i32, W as u32, _ as vec2i, $ as vec2u, p as vec3i, q as vec3u, a0 as vec4i, a1 as vec4u, v as vecBase } from '../types-CGmVkuAt.cjs';
5
+
6
+ interface TgpuBaseArray<TElement extends AnyTgpuData | AnyTgpuLooseData = AnyTgpuData | AnyTgpuLooseData> {
7
+ readonly elementType: TElement;
8
+ readonly elementCount: number;
9
+ readonly stride: number;
10
+ }
11
+ /**
12
+ * Array schema constructed via `d.arrayOf` function.
13
+ *
14
+ * Responsible for handling reading and writing array values
15
+ * between binary and JS representation. Takes into account
16
+ * the `byteAlignment` requirement of its elementType.
17
+ */
18
+ interface TgpuArray<TElement extends AnyTgpuData> extends TgpuBaseArray<TElement>, TgpuData<Unwrap<TElement>[]> {
19
+ }
20
+ /**
21
+ * Creates an array schema that can be used to construct gpu buffers.
22
+ * Describes arrays with fixed-size length, storing elements of the same type.
23
+ *
24
+ * @example
25
+ * const LENGTH = 3;
26
+ * const array = d.arrayOf(d.u32, LENGTH);
27
+ *
28
+ * @param elementType The type of elements in the array.
29
+ * @param count The number of elements in the array.
30
+ */
31
+ declare const arrayOf: <TElement extends AnyTgpuData>(elementType: TElement, count: number) => TgpuArray<TElement>;
32
+ /**
33
+ * Array schema constructed via `d.looseArrayOf` function.
34
+ *
35
+ * Useful for defining vertex buffers.
36
+ * Elements in the schema are not aligned in respect to their `byteAlignment`,
37
+ * unless they are explicitly decorated with the custom align attribute
38
+ * via `d.align` function.
39
+ */
40
+ interface TgpuLooseArray<TElement extends AnyTgpuData | AnyTgpuLooseData> extends TgpuBaseArray<TElement>, TgpuLooseData<Unwrap<TElement>[]> {
41
+ }
42
+ /**
43
+ * Creates an array schema that can be used to construct vertex buffers.
44
+ * Describes arrays with fixed-size length, storing elements of the same type.
45
+ *
46
+ * Elements in the schema are not aligned in respect to their `byteAlignment`,
47
+ * unless they are explicitly decorated with the custom align attribute
48
+ * via `d.align` function.
49
+ *
50
+ * @example
51
+ * const looseArray = d.looseArrayOf(d.vec3f, 3); // packed array of vec3f
52
+ *
53
+ * @example
54
+ * const looseArray = d.looseArrayOf(d.align(16, d.vec3f), 3);
55
+ *
56
+ * @param elementType The type of elements in the array.
57
+ * @param count The number of elements in the array.
58
+ */
59
+ declare const looseArrayOf: <TElement extends AnyTgpuData | AnyTgpuLooseData>(elementType: TElement, count: number) => TgpuLooseArray<TElement>;
60
+ /**
61
+ * Checks whether passed in value is an array schema,
62
+ * as opposed to, e.g., a looseArray schema.
63
+ *
64
+ * Array schemas can be used to describe uniform and storage buffers,
65
+ * whereas looseArray schemas cannot.
66
+ *
67
+ * @example
68
+ * isArraySchema(d.arrayOf(d.u32, 4)) // true
69
+ * isArraySchema(d.looseArrayOf(d.u32, 4)) // false
70
+ * isArraySchema(d.vec3f) // false
71
+ */
72
+ declare function isArraySchema<T extends TgpuArray<AnyTgpuData>>(schema: T | unknown): schema is T;
73
+ /**
74
+ * Checks whether the passed in value is a looseArray schema,
75
+ * as opposed to, e.g., a regular array schema.
76
+ *
77
+ * Array schemas can be used to describe uniform and storage buffers,
78
+ * whereas looseArray schemas cannot. Loose arrays are useful for
79
+ * defining vertex buffers instead.
80
+ *
81
+ * @example
82
+ * isLooseArraySchema(d.arrayOf(d.u32, 4)) // false
83
+ * isLooseArraySchema(d.looseArrayOf(d.u32, 4)) // true
84
+ * isLooseArraySchema(d.vec3f) // false
85
+ */
86
+ declare function isLooseArraySchema<T extends TgpuLooseArray<AnyTgpuData>>(schema: T | unknown): schema is T;
5
87
 
6
88
  declare class SimpleTgpuData<TSchema extends AnySchema> extends Schema<Unwrap<TSchema>> implements TgpuData<Unwrap<TSchema>> {
7
89
  readonly size: number;
8
90
  readonly byteAlignment: number;
9
91
  readonly expressionCode: string;
10
- readonly isCustomAligned = false;
11
92
  private readonly _innerSchema;
12
93
  readonly isLoose: false;
13
94
  readonly label?: string | undefined;
@@ -23,88 +104,440 @@ declare class SimpleTgpuData<TSchema extends AnySchema> extends Schema<Unwrap<TS
23
104
  write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void;
24
105
  read(input: ISerialInput): ParseUnwrapped<TSchema>;
25
106
  measure(value: ParseUnwrapped<TSchema> | MaxValue, measurer?: IMeasurer): IMeasurer;
26
- getUnderlyingTypeString(): string;
27
- getUnderlyingType(): SimpleTgpuData<AnySchema>;
28
107
  resolve(ctx: ResolutionCtx): string;
29
108
  }
30
109
 
31
- type Bool = TgpuData<boolean>;
32
- declare const bool: Bool;
33
- type U32 = TgpuData<number> & ((v: number | boolean) => number);
34
- declare const u32: U32;
35
- type I32 = TgpuData<number> & ((v: number | boolean) => number);
36
- declare const i32: I32;
37
- type F32 = TgpuData<number> & ((v: number | boolean) => number);
38
- declare const f32: F32;
39
-
40
- interface TgpuStruct<TProps extends Record<string, AnyTgpuData>> extends ISchema<UnwrapRecord<TProps>>, TgpuData<UnwrapRecord<TProps>>, TgpuNamable {
110
+ interface TgpuBaseStruct<TProps extends Record<string, unknown>> extends ISchema<UnwrapRecord<TProps>> {
111
+ readonly properties: TProps;
41
112
  }
113
+ /**
114
+ * Struct schema constructed via `d.struct` function.
115
+ *
116
+ * Responsible for handling reading and writing struct values
117
+ * between binary and JS representation. Takes into account
118
+ * the `byteAlignment` requirement of its members.
119
+ */
120
+ interface TgpuStruct<TProps extends Record<string, AnyTgpuData>> extends TgpuBaseStruct<TProps>, TgpuData<UnwrapRecord<TProps>>, TgpuNamable {
121
+ }
122
+ /**
123
+ * Creates a struct schema that can be used to construct GPU buffers.
124
+ * Ensures proper alignment and padding of properties (as opposed to a `d.looseStruct` schema).
125
+ * The order of members matches the passed in properties object.
126
+ *
127
+ * @example
128
+ * const CircleStruct = d.struct({ radius: d.f32, pos: d.vec3f });
129
+ *
130
+ * @param properties Record with `string` keys and `TgpuData` values,
131
+ * each entry describing one struct member.
132
+ */
42
133
  declare const struct: <TProps extends Record<string, AnyTgpuData>>(properties: TProps) => TgpuStruct<TProps>;
43
- declare function isStructSchema<T extends TgpuStruct<Record<string, AnyTgpuData>>>(schema: T | unknown): schema is T;
44
-
45
- interface TgpuArray<TElement extends AnyTgpuData> extends TgpuData<Unwrap<TElement>[]> {
46
- readonly elementType: TElement;
47
- readonly elementCount: number;
134
+ /**
135
+ * Struct schema constructed via `d.looseStruct` function.
136
+ *
137
+ * Useful for defining vertex buffers, as the standard layout restrictions do not apply.
138
+ * Members are not aligned in respect to their `byteAlignment`,
139
+ * unless they are explicitly decorated with the custom align attribute
140
+ * via `d.align` function.
141
+ */
142
+ interface TgpuLooseStruct<TProps extends Record<string, AnyTgpuData | AnyTgpuLooseData>> extends TgpuBaseStruct<TProps>, TgpuLooseData<UnwrapRecord<TProps>> {
48
143
  }
49
- declare const arrayOf: <TElement extends AnyTgpuData>(elementType: TElement, count: number) => TgpuArray<TElement>;
50
- declare function isArraySchema<T extends TgpuArray<AnyTgpuData>>(schema: T | unknown): schema is T;
144
+ /**
145
+ * Creates a loose struct schema that can be used to construct vertex buffers.
146
+ * Describes structs with members of both loose and non-loose types.
147
+ *
148
+ * The order of members matches the passed in properties object.
149
+ * Members are not aligned in respect to their `byteAlignment`,
150
+ * unless they are explicitly decorated with the custom align attribute
151
+ * via `d.align` function.
152
+ *
153
+ * @example
154
+ * const CircleStruct = d.looseStruct({ radius: d.f32, pos: d.vec3f }); // packed struct with no padding
155
+ *
156
+ * @example
157
+ * const CircleStruct = d.looseStruct({ radius: d.f32, pos: d.align(16, d.vec3f) });
158
+ *
159
+ * @param properties Record with `string` keys and `TgpuData` or `TgpuLooseData` values,
160
+ * each entry describing one struct member.
161
+ */
162
+ declare const looseStruct: <TProps extends Record<string, AnyTgpuData | AnyTgpuLooseData>>(properties: TProps) => TgpuLooseStruct<TProps>;
163
+ /**
164
+ * Checks whether passed in value is a struct schema,
165
+ * as opposed to, e.g., a looseStruct schema.
166
+ *
167
+ * Struct schemas can be used to describe uniform and storage buffers,
168
+ * whereas looseStruct schemas cannot.
169
+ *
170
+ * @example
171
+ * isStructSchema(d.struct({ a: d.u32 })) // true
172
+ * isStructSchema(d.looseStruct({ a: d.u32 })) // false
173
+ * isStructSchema(d.vec3f) // false
174
+ */
175
+ declare function isStructSchema<T extends TgpuStruct<Record<string, AnyTgpuData>>>(schema: T | unknown): schema is T;
176
+ /**
177
+ * Checks whether passed in value is a looseStruct schema,
178
+ * as opposed to, e.g., a struct schema.
179
+ *
180
+ * Struct schemas can be used to describe uniform and storage buffers,
181
+ * whereas looseStruct schemas cannot. Loose structs are useful for
182
+ * defining vertex buffers instead.
183
+ *
184
+ * @example
185
+ * isLooseStructSchema(d.struct({ a: d.u32 })) // false
186
+ * isLooseStructSchema(d.looseStruct({ a: d.u32 })) // true
187
+ * isLooseStructSchema(d.vec3f) // false
188
+ */
189
+ declare function isLooseStructSchema<T extends TgpuLooseStruct<Record<string, AnyTgpuData | AnyTgpuLooseData>>>(schema: T | unknown): schema is T;
51
190
 
52
- interface matBase<TColumn> {
53
- columns(): Iterable<TColumn>;
191
+ interface matBase<TColumn> extends NumberArrayView {
192
+ readonly columns: readonly TColumn[];
54
193
  elements(): Iterable<number>;
55
194
  }
195
+ /**
196
+ * Interface representing its WGSL matrix type counterpart: mat2x2
197
+ * A matrix with 2 rows and 2 columns, with elements of type `TColumn`
198
+ */
56
199
  interface mat2x2<TColumn> extends matBase<TColumn> {
57
- [0]: TColumn;
58
- [1]: TColumn;
59
- [idx: number]: TColumn | undefined;
200
+ readonly length: 4;
201
+ [n: number]: number;
60
202
  }
203
+ /**
204
+ * Type of the `d.mat2x2f` object/function: matrix data type schema/constructor
205
+ */
61
206
  type Mat2x2f = TgpuData<mat2x2f> & ((...elements: number[]) => mat2x2f) & ((...columns: vec2f[]) => mat2x2f) & (() => mat2x2f);
207
+ /**
208
+ * Interface representing its WGSL matrix type counterpart: mat2x2f or mat2x2<f32>
209
+ * A matrix with 2 rows and 2 columns, with elements of type d.f32
210
+ */
62
211
  interface mat2x2f extends mat2x2<vec2f> {
63
212
  }
213
+ /**
214
+ *
215
+ * Schema representing mat2x2f - a matrix with 2 rows and 2 columns, with elements of type f32.
216
+ * Also a constructor function for this matrix type.
217
+ *
218
+ * @example
219
+ * const zero2x2 = mat2x2f(); // filled with zeros
220
+ *
221
+ * @example
222
+ * const mat = mat2x2f(0, 1, 2, 3);
223
+ * mat[0] // vec2f(0, 1)
224
+ * mat[1] // vec2f(2, 3)
225
+ *
226
+ * @example
227
+ * const mat = mat2x2f(
228
+ * vec2f(0, 1), // column 0
229
+ * vec2f(1, 2), // column 1
230
+ * );
231
+ *
232
+ * @example
233
+ * 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))
234
+ */
64
235
  declare const mat2x2f: Mat2x2f;
236
+ /**
237
+ * Interface representing its WGSL matrix type counterpart: mat3x3
238
+ * A matrix with 3 rows and 3 columns, with elements of type `TColumn`
239
+ */
65
240
  interface mat3x3<TColumn> extends matBase<TColumn> {
66
- [0]: TColumn;
67
- [1]: TColumn;
68
- [2]: TColumn;
69
- [idx: number]: TColumn | undefined;
241
+ readonly length: 12;
242
+ [n: number]: number;
70
243
  }
244
+ /**
245
+ * Type of the `d.mat3x3f` object/function: matrix data type schema/constructor
246
+ */
71
247
  type Mat3x3f = TgpuData<mat3x3f> & ((...elements: number[]) => mat3x3f) & ((...columns: vec3f[]) => mat3x3f) & (() => mat3x3f);
248
+ /**
249
+ * Interface representing its WGSL matrix type counterpart: mat3x3f or mat3x3<f32>
250
+ * A matrix with 3 rows and 3 columns, with elements of type d.f32
251
+ */
72
252
  interface mat3x3f extends mat3x3<vec3f> {
73
253
  }
254
+ /**
255
+ *
256
+ * Schema representing mat3x3f - a matrix with 3 rows and 3 columns, with elements of type f32.
257
+ * Also a constructor function for this matrix type.
258
+ *
259
+ * @example
260
+ * const zero3x3 = mat3x3f(); // filled with zeros
261
+ *
262
+ * @example
263
+ * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8);
264
+ * mat[0] // vec3f(0, 1, 2)
265
+ * mat[1] // vec3f(3, 4, 5)
266
+ * mat[2] // vec3f(6, 7, 8)
267
+ *
268
+ * @example
269
+ * const mat = mat3x3f(
270
+ * vec3f(0, 1, 2), // column 0
271
+ * vec3f(2, 3, 4), // column 1
272
+ * vec3f(5, 6, 7), // column 2
273
+ * );
274
+ *
275
+ * @example
276
+ * const buffer = root.createBuffer(d.mat3x3f, d.mat3x3f()); // buffer holding a d.mat3x3f value, with an initial value of mat3x3f filled with zeros
277
+ */
74
278
  declare const mat3x3f: Mat3x3f;
279
+ /**
280
+ * Interface representing its WGSL matrix type counterpart: mat4x4
281
+ * A matrix with 4 rows and 4 columns, with elements of type `TColumn`
282
+ */
75
283
  interface mat4x4<TColumn> extends matBase<TColumn> {
76
- [0]: TColumn;
77
- [1]: TColumn;
78
- [2]: TColumn;
79
- [3]: TColumn;
80
- [idx: number]: TColumn | undefined;
284
+ readonly length: 16;
285
+ [n: number]: number;
81
286
  }
287
+ /**
288
+ * Type of the `d.mat4x4f` object/function: matrix data type schema/constructor
289
+ */
82
290
  type Mat4x4f = TgpuData<mat4x4f> & ((...elements: number[]) => mat4x4f) & ((...columns: vec4f[]) => mat4x4f) & (() => mat4x4f);
291
+ /**
292
+ * Interface representing its WGSL matrix type counterpart: mat4x4f or mat4x4<f32>
293
+ * A matrix with 4 rows and 4 columns, with elements of type d.f32
294
+ */
83
295
  interface mat4x4f extends mat4x4<vec4f> {
84
296
  }
297
+ /**
298
+ *
299
+ * Schema representing mat4x4f - a matrix with 4 rows and 4 columns, with elements of type f32.
300
+ * Also a constructor function for this matrix type.
301
+ *
302
+ * @example
303
+ * const zero4x4 = mat4x4f(); // filled with zeros
304
+ *
305
+ * @example
306
+ * const mat = mat3x3f(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
307
+ * mat[0] // vec4f(0, 1, 2, 3)
308
+ * mat[1] // vec4f(4, 5, 6, 7)
309
+ * mat[2] // vec4f(8, 9, 10, 11)
310
+ * mat[3] // vec4f(12, 13, 14, 15)
311
+ *
312
+ * @example
313
+ * const mat = mat3x3f(
314
+ * vec4f(0, 1, 2, 3), // column 0
315
+ * vec4f(4, 5, 6, 7), // column 1
316
+ * vec4f(8, 9, 10, 11), // column 2
317
+ * vec4f(12, 13, 14, 15), // column 3
318
+ * );
319
+ *
320
+ * @example
321
+ * const buffer = root.createBuffer(d.mat4x4f, d.mat4x4f()); // buffer holding a d.mat4x4f value, with an initial value of mat4x4f filled with zeros
322
+ */
85
323
  declare const mat4x4f: Mat4x4f;
86
324
 
325
+ declare const vertexFormats: readonly ["uint8x2", "uint8x4", "sint8x2", "sint8x4", "unorm8x2", "unorm8x4", "snorm8x2", "snorm8x4", "uint16x2", "uint16x4", "sint16x2", "sint16x4", "unorm16x2", "unorm16x4", "snorm16x2", "snorm16x4", "float16x2", "float16x4", "float32", "float32x2", "float32x3", "float32x4", "uint32", "uint32x2", "uint32x3", "uint32x4", "sint32", "sint32x2", "sint32x3", "sint32x4", "unorm10_10_10_2"];
326
+ type VertexFormat = (typeof vertexFormats)[number];
327
+
328
+ type FormatToWGSLType<T extends VertexFormat> = (typeof formatToWGSLType)[T];
329
+ interface TgpuVertexFormatData<T extends VertexFormat> extends TgpuLooseData<FormatToWGSLType<T>> {
330
+ readonly kind: T;
331
+ }
332
+ declare const formatToWGSLType: {
333
+ readonly uint8x2: Vec2u;
334
+ readonly uint8x4: Vec4u;
335
+ readonly sint8x2: Vec2i;
336
+ readonly sint8x4: Vec4i;
337
+ readonly unorm8x2: Vec2f;
338
+ readonly unorm8x4: Vec4f;
339
+ readonly snorm8x2: Vec2f;
340
+ readonly snorm8x4: Vec4f;
341
+ readonly uint16x2: Vec2u;
342
+ readonly uint16x4: Vec4u;
343
+ readonly sint16x2: Vec2i;
344
+ readonly sint16x4: Vec4i;
345
+ readonly unorm16x2: Vec2f;
346
+ readonly unorm16x4: Vec4f;
347
+ readonly snorm16x2: Vec2f;
348
+ readonly snorm16x4: Vec4f;
349
+ readonly float16x2: Vec2f;
350
+ readonly float16x4: Vec4f;
351
+ readonly float32: F32;
352
+ readonly float32x2: Vec2f;
353
+ readonly float32x3: Vec3f;
354
+ readonly float32x4: Vec4f;
355
+ readonly uint32: U32;
356
+ readonly uint32x2: Vec2u;
357
+ readonly uint32x3: Vec3u;
358
+ readonly uint32x4: Vec4u;
359
+ readonly sint32: I32;
360
+ readonly sint32x2: Vec2i;
361
+ readonly sint32x3: Vec3i;
362
+ readonly sint32x4: Vec4i;
363
+ readonly unorm10_10_10_2: Vec4f;
364
+ };
365
+ type uint8x2 = TgpuVertexFormatData<'uint8x2'>;
366
+ declare const uint8x2: uint8x2;
367
+ type uint8x4 = TgpuVertexFormatData<'uint8x4'>;
368
+ declare const uint8x4: uint8x4;
369
+ type sint8x2 = TgpuVertexFormatData<'sint8x2'>;
370
+ declare const sint8x2: sint8x2;
371
+ type sint8x4 = TgpuVertexFormatData<'sint8x4'>;
372
+ declare const sint8x4: sint8x4;
373
+ type unorm8x2 = TgpuVertexFormatData<'unorm8x2'>;
374
+ declare const unorm8x2: unorm8x2;
375
+ type unorm8x4 = TgpuVertexFormatData<'unorm8x4'>;
376
+ declare const unorm8x4: unorm8x4;
377
+ type snorm8x2 = TgpuVertexFormatData<'snorm8x2'>;
378
+ declare const snorm8x2: snorm8x2;
379
+ type snorm8x4 = TgpuVertexFormatData<'snorm8x4'>;
380
+ declare const snorm8x4: snorm8x4;
381
+ type uint16x2 = TgpuVertexFormatData<'uint16x2'>;
382
+ declare const uint16x2: uint16x2;
383
+ type uint16x4 = TgpuVertexFormatData<'uint16x4'>;
384
+ declare const uint16x4: uint16x4;
385
+ type sint16x2 = TgpuVertexFormatData<'sint16x2'>;
386
+ declare const sint16x2: sint16x2;
387
+ type sint16x4 = TgpuVertexFormatData<'sint16x4'>;
388
+ declare const sint16x4: sint16x4;
389
+ type unorm16x2 = TgpuVertexFormatData<'unorm16x2'>;
390
+ declare const unorm16x2: unorm16x2;
391
+ type unorm16x4 = TgpuVertexFormatData<'unorm16x4'>;
392
+ declare const unorm16x4: unorm16x4;
393
+ type snorm16x2 = TgpuVertexFormatData<'snorm16x2'>;
394
+ declare const snorm16x2: snorm16x2;
395
+ type snorm16x4 = TgpuVertexFormatData<'snorm16x4'>;
396
+ declare const snorm16x4: snorm16x4;
397
+ type float16x2 = TgpuVertexFormatData<'float16x2'>;
398
+ declare const float16x2: float16x2;
399
+ type float16x4 = TgpuVertexFormatData<'float16x4'>;
400
+ declare const float16x4: float16x4;
401
+ type float32 = TgpuVertexFormatData<'float32'>;
402
+ declare const float32: float32;
403
+ type float32x2 = TgpuVertexFormatData<'float32x2'>;
404
+ declare const float32x2: float32x2;
405
+ type float32x3 = TgpuVertexFormatData<'float32x3'>;
406
+ declare const float32x3: float32x3;
407
+ type float32x4 = TgpuVertexFormatData<'float32x4'>;
408
+ declare const float32x4: float32x4;
409
+ type uint32 = TgpuVertexFormatData<'uint32'>;
410
+ declare const uint32: uint32;
411
+ type uint32x2 = TgpuVertexFormatData<'uint32x2'>;
412
+ declare const uint32x2: uint32x2;
413
+ type uint32x3 = TgpuVertexFormatData<'uint32x3'>;
414
+ declare const uint32x3: uint32x3;
415
+ type uint32x4 = TgpuVertexFormatData<'uint32x4'>;
416
+ declare const uint32x4: uint32x4;
417
+ type sint32 = TgpuVertexFormatData<'sint32'>;
418
+ declare const sint32: sint32;
419
+ type sint32x2 = TgpuVertexFormatData<'sint32x2'>;
420
+ declare const sint32x2: sint32x2;
421
+ type sint32x3 = TgpuVertexFormatData<'sint32x3'>;
422
+ declare const sint32x3: sint32x3;
423
+ type sint32x4 = TgpuVertexFormatData<'sint32x4'>;
424
+ declare const sint32x4: sint32x4;
425
+ type unorm10_10_10_2 = TgpuVertexFormatData<'unorm10_10_10_2'>;
426
+ declare const unorm10_10_10_2: unorm10_10_10_2;
427
+
87
428
  declare function ptr<TDataType extends AnyTgpuData>(pointsTo: TDataType): TgpuPointer<'function', TDataType>;
88
429
 
430
+ /**
431
+ * Marks a concrete integer scalar type schema (u32 or i32) as a WGSL atomic.
432
+ *
433
+ * @example
434
+ * const atomicU32 = d.atomic(d.u32);
435
+ * const atomicI32 = d.atomic(d.i32);
436
+ *
437
+ * @param data Underlying type schema.
438
+ */
89
439
  declare function atomic<TSchema extends U32 | I32>(data: TSchema): Atomic<TSchema>;
440
+ /**
441
+ * Atomic schema constructed via `d.atomic` function.
442
+ */
90
443
  interface Atomic<TSchema extends U32 | I32> extends TgpuData<Unwrap<TSchema>> {
91
444
  }
445
+ /**
446
+ * Checks whether the passed in value is a d.atomic schema.
447
+ *
448
+ * @example
449
+ * isAtomicSchema(d.atomic(d.u32)) // true
450
+ * isAtomicSchema(d.u32) // false
451
+ */
92
452
  declare function isAtomicSchema<T extends Atomic<U32 | I32>>(schema: T | unknown): schema is T;
93
453
 
94
- declare function align<TAlign extends number, TData extends AnyTgpuData>(byteAlignment: TAlign, data: TData): TgpuAligned<TAlign, TData>;
95
- declare function align<TAlign extends number, TData extends AnyTgpuLooseData>(byteAlignment: TAlign, data: TData): TgpuLooseAligned<TAlign, TData>;
96
- interface TgpuAligned<TAlign extends number, TData extends AnyTgpuData> extends TgpuData<Unwrap<TData>> {
97
- readonly byteAlignment: TAlign;
454
+ interface Align<T extends number> {
455
+ type: 'align';
456
+ alignment: T;
98
457
  }
99
- interface TgpuLooseAligned<TAlign extends number, TData extends AnyTgpuLooseData> extends TgpuLooseData<Unwrap<TData>> {
100
- readonly byteAlignment: TAlign;
458
+ interface Size<T extends number> {
459
+ type: 'size';
460
+ size: T;
101
461
  }
102
- declare function isAlignedSchema<T extends TgpuAligned<number, AnyTgpuData>>(value: T | unknown): value is T;
103
-
104
- declare function size<TSize extends number, TData extends AnyTgpuData>(size: TSize, data: TData): TgpuSized<TSize, TData>;
105
- interface TgpuSized<TSize extends number, TData extends AnyTgpuData> extends TgpuData<Unwrap<TData>> {
106
- readonly size: TSize;
462
+ interface Location<T extends number> {
463
+ type: 'location';
464
+ location: T;
465
+ }
466
+ type AnyAttribute = Align<number> | Size<number> | Location<number>;
467
+ interface BaseDecorated<TInner extends AnyTgpuData | AnyTgpuLooseData = AnyTgpuData | AnyTgpuLooseData, TAttribs extends AnyAttribute[] = AnyAttribute[]> {
468
+ readonly inner: TInner;
469
+ readonly attributes: TAttribs;
470
+ readonly alignAttrib: number | undefined;
471
+ readonly sizeAttrib: number | undefined;
472
+ readonly locationAttrib: number | undefined;
473
+ }
474
+ interface Decorated<TInner extends AnyTgpuData, TAttribs extends AnyAttribute[]> extends BaseDecorated<TInner, TAttribs>, TgpuData<Unwrap<TInner>> {
475
+ }
476
+ interface LooseDecorated<TInner extends AnyTgpuLooseData, TAttribs extends AnyAttribute[]> extends BaseDecorated<TInner, TAttribs>, TgpuLooseData<Unwrap<TInner>> {
107
477
  }
108
- declare function isSizedSchema<T extends TgpuSized<number, TgpuData<unknown>>>(value: T | unknown): value is T;
478
+ type ExtractAttributes<T> = T extends BaseDecorated<AnyTgpuData, infer Attribs> ? Attribs : [];
479
+ type UnwrapDecorated<T> = T extends BaseDecorated<infer Inner> ? Inner : T;
480
+ /**
481
+ * Decorates a data-type `TData` with an attribute `TAttrib`.
482
+ *
483
+ * - if `TData` is loose
484
+ * - if `TData` is already `LooseDecorated`
485
+ * - Prepend `TAttrib` to the existing attribute tuple.
486
+ * - else
487
+ * - Wrap `TData` with `LooseDecorated` and a single attribute `[TAttrib]`
488
+ * - else
489
+ * - if `TData` is already `Decorated`
490
+ * - Prepend `TAttrib` to the existing attribute tuple.
491
+ * - else
492
+ * - Wrap `TData` with `Decorated` and a single attribute `[TAttrib]`
493
+ */
494
+ type Decorate<TData extends AnyTgpuData | AnyTgpuLooseData, TAttrib extends AnyAttribute> = TData extends AnyTgpuData ? Decorated<UnwrapDecorated<TData>, [TAttrib, ...ExtractAttributes<TData>]> : TData extends AnyTgpuLooseData ? LooseDecorated<UnwrapDecorated<TData>, [
495
+ TAttrib,
496
+ ...ExtractAttributes<TData>
497
+ ]> : never;
498
+ /**
499
+ * Gives the wrapped data-type a custom byte alignment. Useful in order to
500
+ * fulfill uniform alignment requirements.
501
+ *
502
+ * @example
503
+ * const Data = d.struct({
504
+ * a: u32, // takes up 4 bytes
505
+ * // 12 bytes of padding, because `b` is custom aligned to multiples of 16 bytes
506
+ * b: d.align(16, u32),
507
+ * });
508
+ *
509
+ * @param alignment The multiple of bytes this data should align itself to.
510
+ * @param data The data-type to align.
511
+ */
512
+ declare function align<TAlign extends number, TData extends AnyTgpuData | AnyTgpuLooseData>(alignment: TAlign, data: TData): Decorate<TData, Align<TAlign>>;
513
+ /**
514
+ * Adds padding bytes after the wrapped data-type, until the whole value takes up `size` bytes.
515
+ *
516
+ * @example
517
+ * const Data = d.struct({
518
+ * a: d.size(16, u32), // takes up 16 bytes, instead of 4
519
+ * b: u32, // starts at byte 16, because `a` has a custom size
520
+ * });
521
+ *
522
+ * @param size The amount of bytes that should be reserved for this data-type.
523
+ * @param data The data-type to wrap.
524
+ */
525
+ declare function size<TSize extends number, TData extends AnyTgpuData | AnyTgpuLooseData>(size: TSize, data: TData): Decorate<TData, Size<TSize>>;
526
+ /**
527
+ * Assigns an explicit numeric location to a struct member or a parameter that has this type.
528
+ *
529
+ * @example
530
+ * const Data = d.ioStruct({
531
+ * a: d.u32, // has implicit location 0
532
+ * b: d.location(5, d.u32),
533
+ * c: d.u32, // has implicit location 6
534
+ * });
535
+ *
536
+ * @param location The explicit numeric location.
537
+ * @param data The data-type to wrap.
538
+ */
539
+ declare function location<TLocation extends number, TData extends AnyTgpuData | AnyTgpuLooseData>(location: TLocation, data: TData): Decorate<TData, Location<TLocation>>;
540
+ declare function isDecorated<T extends Decorated<AnyTgpuData, AnyAttribute[]>>(value: T | unknown): value is T;
541
+ declare function isLooseDecorated<T extends LooseDecorated<AnyTgpuLooseData, AnyAttribute[]>>(value: T | unknown): value is T;
109
542
 
110
- export { type Atomic, type Bool, type F32, type I32, type Mat2x2f, type Mat3x3f, type Mat4x4f, SimpleTgpuData, type TgpuAligned, type TgpuArray, type TgpuSized, type TgpuStruct, type U32, align, arrayOf, atomic, bool, f32, i32, isAlignedSchema, isArraySchema, isAtomicSchema, isSizedSchema, isStructSchema, type mat2x2, mat2x2f, type mat3x3, mat3x3f, type mat4x4, mat4x4f, ptr, size, struct, u32, vec2f, vec3f, vec4f };
543
+ export { type Align, type AnyAttribute, type Atomic, type BaseDecorated, type Decorated, F32, type FormatToWGSLType, I32, type Location, type LooseDecorated, type Mat2x2f, type Mat3x3f, type Mat4x4f, SimpleTgpuData, type Size, type TgpuArray, type TgpuBaseArray, type TgpuBaseStruct, type TgpuLooseArray, type TgpuLooseStruct, type TgpuStruct, type TgpuVertexFormatData, U32, Vec2f, Vec2i, Vec2u, Vec3f, Vec3i, Vec3u, Vec4f, Vec4i, Vec4u, align, arrayOf, atomic, float16x2, float16x4, float32, float32x2, float32x3, float32x4, isArraySchema, isAtomicSchema, isDecorated, isLooseArraySchema, isLooseDecorated, isLooseStructSchema, isStructSchema, location, looseArrayOf, looseStruct, mat2x2f, mat3x3f, mat4x4f, ptr, sint16x2, sint16x4, sint32, sint32x2, sint32x3, sint32x4, sint8x2, sint8x4, size, snorm16x2, snorm16x4, snorm8x2, snorm8x4, struct, uint16x2, uint16x4, uint32, uint32x2, uint32x3, uint32x4, uint8x2, uint8x4, unorm10_10_10_2, unorm16x2, unorm16x4, unorm8x2, unorm8x4, vec2f, vec3f, vec4f };