typegpu 0.0.0-alpha.2 → 0.0.0-alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. package/README.md +29 -0
  2. package/chunk-7HTWRNOH.cjs +12 -0
  3. package/chunk-7HTWRNOH.cjs.map +1 -0
  4. package/chunk-K2GYQABQ.js +12 -0
  5. package/chunk-K2GYQABQ.js.map +1 -0
  6. package/data/index.cjs +2 -0
  7. package/data/index.cjs.map +1 -0
  8. package/data/index.d.cts +38 -0
  9. package/data/index.d.ts +38 -0
  10. package/data/index.js +2 -0
  11. package/data/index.js.map +1 -0
  12. package/index.cjs +49 -0
  13. package/index.cjs.map +1 -0
  14. package/{dist/index.d.cts → index.d.cts} +129 -30
  15. package/{dist/index.d.ts → index.d.ts} +129 -30
  16. package/index.js +49 -0
  17. package/index.js.map +1 -0
  18. package/macro/index.cjs +8 -0
  19. package/{dist/macro → macro}/index.d.cts +1 -1
  20. package/{dist/macro → macro}/index.d.ts +1 -1
  21. package/{dist/macro → macro}/index.js +1 -1
  22. package/package.json +30 -37
  23. package/std140-Cv7GDE9w.d.ts +26 -0
  24. package/std140-DRitCcmc.d.cts +26 -0
  25. package/types-ENDwr_p9.d.cts +243 -0
  26. package/types-ENDwr_p9.d.ts +243 -0
  27. package/dist/chunk-3VCFA6WZ.cjs +0 -2
  28. package/dist/chunk-3VCFA6WZ.cjs.map +0 -1
  29. package/dist/chunk-G3U6RTMF.cjs +0 -2
  30. package/dist/chunk-G3U6RTMF.cjs.map +0 -1
  31. package/dist/chunk-GHP25GEO.js +0 -2
  32. package/dist/chunk-GHP25GEO.js.map +0 -1
  33. package/dist/chunk-XGSMOADT.js +0 -2
  34. package/dist/chunk-XGSMOADT.js.map +0 -1
  35. package/dist/data/index.cjs +0 -10
  36. package/dist/data/index.cjs.map +0 -1
  37. package/dist/data/index.d.cts +0 -84
  38. package/dist/data/index.d.ts +0 -84
  39. package/dist/data/index.js +0 -10
  40. package/dist/data/index.js.map +0 -1
  41. package/dist/index.cjs +0 -29
  42. package/dist/index.cjs.map +0 -1
  43. package/dist/index.js +0 -29
  44. package/dist/index.js.map +0 -1
  45. package/dist/macro/index.cjs +0 -8
  46. package/dist/struct-CpjQEnf9.d.cts +0 -9
  47. package/dist/struct-HAlb4aG-.d.ts +0 -9
  48. package/dist/types-gpN_64mT.d.cts +0 -148
  49. package/dist/types-gpN_64mT.d.ts +0 -148
  50. /package/{dist/macro → macro}/index.cjs.map +0 -0
  51. /package/{dist/macro → macro}/index.js.map +0 -0
@@ -0,0 +1,243 @@
1
+ import * as TB from 'typed-binary';
2
+ import { Parsed, ISchema } from 'typed-binary';
3
+
4
+ type Bool = WgslData<boolean>;
5
+ declare const bool: Bool;
6
+ type U32 = WgslData<number>;
7
+ declare const u32: U32;
8
+ type I32 = WgslData<number>;
9
+ declare const i32: I32;
10
+ type F32 = WgslData<number>;
11
+ declare const f32: F32;
12
+ type Vec2u = WgslData<[number, number]>;
13
+ declare const vec2u: Vec2u;
14
+ type Vec2i = WgslData<[number, number]>;
15
+ declare const vec2i: Vec2i;
16
+ type Vec2f = WgslData<[number, number]>;
17
+ declare const vec2f: Vec2f;
18
+ type Vec3u = WgslData<[number, number, number]>;
19
+ declare const vec3u: Vec3u;
20
+ type Vec3i = WgslData<[number, number, number]>;
21
+ declare const vec3i: Vec3i;
22
+ type Vec3f = WgslData<[number, number, number]>;
23
+ declare const vec3f: Vec3f;
24
+ type Vec4u = WgslData<[number, number, number, number]>;
25
+ declare const vec4u: Vec4u;
26
+ type Vec4i = WgslData<[number, number, number, number]>;
27
+ declare const vec4i: Vec4i;
28
+ type Vec4f = WgslData<[number, number, number, number]>;
29
+ declare const vec4f: Vec4f;
30
+ /**
31
+ * Array of column vectors
32
+ */
33
+ type Mat4f = WgslData<number[]>;
34
+ declare const mat4f: Mat4f;
35
+
36
+ /**
37
+ * Helpful when creating new Resolvable types. For internal use.
38
+ */
39
+ declare class WgslIdentifier implements WgslResolvable {
40
+ label?: string | undefined;
41
+ $name(label: string | undefined): this;
42
+ resolve(ctx: ResolutionCtx): string;
43
+ toString(): string;
44
+ }
45
+
46
+ type BuiltInPossibleTypes = U32 | F32 | Vec3u | Vec4f | WgslData<TB.Unwrap<U32>[]>;
47
+ declare const builtin: {
48
+ readonly vertexIndex: symbol;
49
+ readonly instanceIndex: symbol;
50
+ readonly position: symbol;
51
+ readonly clipDistances: symbol;
52
+ readonly frontFacing: symbol;
53
+ readonly fragDepth: symbol;
54
+ readonly sampleIndex: symbol;
55
+ readonly sampleMask: symbol;
56
+ readonly fragment: symbol;
57
+ readonly localInvocationId: symbol;
58
+ readonly localInvocationIndex: symbol;
59
+ readonly globalInvocationId: symbol;
60
+ readonly workgroupId: symbol;
61
+ readonly numWorkgroups: symbol;
62
+ };
63
+ interface Builtin {
64
+ name: string;
65
+ stage: 'vertex' | 'fragment' | 'compute';
66
+ direction: 'input' | 'output';
67
+ type: BuiltInPossibleTypes;
68
+ identifier: WgslIdentifier;
69
+ }
70
+ declare function getBuiltinInfo(s: symbol): Builtin;
71
+ declare function getUsedBuiltinsNamed(o: Record<symbol, string>): {
72
+ name: string;
73
+ builtin: Builtin;
74
+ }[];
75
+
76
+ declare const WgslSettableTrait: unique symbol;
77
+ interface WgslSettable {
78
+ readonly [WgslSettableTrait]: true;
79
+ }
80
+
81
+ type Getter = <T>(plum: WgslPlum<T>) => T;
82
+ type Unsubscribe = () => unknown;
83
+ type ExtractPlumValue<T> = T extends WgslPlum<infer TValue> ? TValue : never;
84
+ interface WgslPlum<TValue = unknown> {
85
+ readonly __brand: 'WgslPlum';
86
+ $name(label: string): this;
87
+ /**
88
+ * Computes the value of this plum. Circumvents the store
89
+ * memoization, so use with care.
90
+ */
91
+ compute(get: Getter): TValue;
92
+ }
93
+ declare const WgslExternalPlumTrait: unique symbol;
94
+ interface WgslExternalPlum {
95
+ readonly [WgslExternalPlumTrait]: true;
96
+ readonly version: number;
97
+ subscribe(listener: () => unknown): Unsubscribe;
98
+ }
99
+ /**
100
+ * Creates a computed plum. Its value depends on the plums read using `get`
101
+ * inside the `compute` function, so cannot be set imperatively.
102
+ *
103
+ * @param compute A pure function that describes this plum's value.
104
+ */
105
+ declare function plum<T extends Wgsl>(compute: (get: Getter) => T): WgslPlum<T> & WgslResolvable;
106
+ /**
107
+ * Creates a computed plum. Its value depends on the plums read using `get`
108
+ * inside the `compute` function, so cannot be set imperatively.
109
+ *
110
+ * @param compute A pure function that describes this plum's value.
111
+ */
112
+ declare function plum<T>(compute: (get: Getter) => T): WgslPlum<T>;
113
+ /**
114
+ * Creates a plum with an initial value of `initial`.
115
+ * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
116
+ *
117
+ * @param initial The initial value of this plum.
118
+ */
119
+ declare function plum<T extends Wgsl>(initial: T): WgslPlum<T> & WgslSettable & WgslResolvable;
120
+ /**
121
+ * Creates a plum with an initial value of `initial`.
122
+ * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
123
+ *
124
+ * @param initial The initial value of this plum.
125
+ */
126
+ declare function plum<T>(initial: T): WgslPlum<T> & WgslSettable;
127
+ declare function plumFromEvent<T>(subscribe: (listener: () => unknown) => Unsubscribe, getLatest: () => T): WgslPlum<T> & WgslExternalPlum;
128
+
129
+ type Wgsl = string | number | WgslResolvable | symbol | boolean;
130
+ /**
131
+ * Passed into each resolvable item. All sibling items share a resolution ctx,
132
+ * and a new resolution ctx is made when going down each level in the tree.
133
+ */
134
+ interface ResolutionCtx {
135
+ /**
136
+ * Slots that were used by items resolved by this context.
137
+ */
138
+ readonly usedSlots: Iterable<WgslSlot<unknown>>;
139
+ addDeclaration(item: WgslResolvable): void;
140
+ addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;
141
+ addRenderResource(resource: WgslRenderResource, identifier: WgslIdentifier): void;
142
+ addBuiltin(builtin: Builtin): void;
143
+ nameFor(token: WgslResolvable): string;
144
+ /**
145
+ * Unwraps all layers of slot indirection and returns the concrete value if available.
146
+ * @throws {MissingSlotValueError}
147
+ */
148
+ unwrap<T>(eventual: Eventual<T>): T;
149
+ resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
150
+ }
151
+ interface WgslResolvable {
152
+ readonly label?: string | undefined;
153
+ resolve(ctx: ResolutionCtx): string;
154
+ }
155
+ declare function isResolvable(value: unknown): value is WgslResolvable;
156
+ declare function isWgsl(value: unknown): value is Wgsl;
157
+ interface WgslSlot<T> {
158
+ readonly __brand: 'WgslSlot';
159
+ readonly defaultValue: T | undefined;
160
+ readonly label?: string | undefined;
161
+ $name(label: string): WgslSlot<T>;
162
+ /**
163
+ * Used to determine if code generated using either value `a` or `b` in place
164
+ * of the slot will be equivalent. Defaults to `Object.is`.
165
+ */
166
+ areEqual(a: T, b: T): boolean;
167
+ }
168
+ declare function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T>;
169
+ /**
170
+ * Represents a value that is available at resolution time.
171
+ */
172
+ type Eventual<T> = T | WgslSlot<T>;
173
+ type EventualGetter = <T>(value: Eventual<T>) => T;
174
+ type InlineResolve = (get: EventualGetter) => Wgsl;
175
+ interface WgslResolvableSlot<T extends Wgsl> extends WgslResolvable, WgslSlot<T> {
176
+ $name(label: string): WgslResolvableSlot<T>;
177
+ }
178
+ type SlotValuePair<T> = [WgslSlot<T>, T];
179
+ interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {
180
+ /**
181
+ * The data type this allocatable was constructed with.
182
+ * It informs the size and format of data in both JS and
183
+ * binary.
184
+ */
185
+ readonly dataType: TData;
186
+ vertexLayout: Omit<GPUVertexBufferLayout, 'attributes'> | null;
187
+ readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;
188
+ readonly flags: GPUBufferUsageFlags;
189
+ get label(): string | undefined;
190
+ }
191
+ interface WgslBindable<TData extends AnyWgslData = AnyWgslData, TUsage extends BufferUsage = BufferUsage> extends WgslResolvable {
192
+ readonly allocatable: WgslAllocatable<TData>;
193
+ readonly usage: TUsage;
194
+ }
195
+ type WgslSamplerType = 'sampler' | 'sampler_comparison';
196
+ type WgslTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
197
+ type WgslDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
198
+ type WgslStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
199
+ type WgslExternalTextureType = 'texture_external';
200
+ type WgslRenderResourceType = WgslSamplerType | WgslTypedTextureType | WgslDepthTextureType | WgslStorageTextureType | WgslExternalTextureType;
201
+ interface WgslRenderResource extends WgslResolvable {
202
+ readonly type: WgslRenderResourceType;
203
+ }
204
+ type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
205
+ type TextureUsage = 'sampled' | 'storage';
206
+ type StorageTextureAccess = 'read' | 'write' | 'read_write';
207
+ type StorageTextureParams = {
208
+ type: WgslStorageTextureType;
209
+ access: StorageTextureAccess;
210
+ descriptor?: GPUTextureViewDescriptor;
211
+ };
212
+ type SampledTextureParams = {
213
+ type: WgslTypedTextureType;
214
+ dataType: AnyWgslPrimitive;
215
+ descriptor?: GPUTextureViewDescriptor;
216
+ };
217
+ declare function isSamplerType(type: WgslRenderResourceType): type is WgslSamplerType;
218
+ declare function isTypedTextureType(type: WgslRenderResourceType): type is WgslTypedTextureType;
219
+ declare function isDepthTextureType(type: WgslRenderResourceType): type is WgslDepthTextureType;
220
+ declare function isStorageTextureType(type: WgslRenderResourceType): type is WgslStorageTextureType;
221
+ declare function isExternalTextureType(type: WgslRenderResourceType): type is WgslExternalTextureType;
222
+ interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {
223
+ readonly byteAlignment: number;
224
+ readonly size: number;
225
+ }
226
+ type AnyWgslData = WgslData<unknown>;
227
+ type AnyWgslPrimitive = U32 | I32 | F32;
228
+ type AnyWgslTexelFormat = Vec4u | Vec4i | Vec4f;
229
+ interface WgslPointer<TScope extends 'function', TInner extends AnyWgslData> {
230
+ readonly scope: TScope;
231
+ readonly pointsTo: TInner;
232
+ }
233
+ /**
234
+ * A virtual representation of a WGSL value.
235
+ */
236
+ type WgslValue<TDataType> = {
237
+ readonly __dataType: TDataType;
238
+ };
239
+ type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;
240
+ type WgslFnArgument = AnyWgslPointer | AnyWgslData;
241
+ declare function isPointer(value: AnyWgslPointer | AnyWgslData): value is AnyWgslPointer;
242
+
243
+ export { type I32 as $, type AnyWgslTexelFormat as A, type BufferUsage as B, type WgslDepthTextureType as C, type WgslStorageTextureType as D, type Eventual as E, type WgslExternalTextureType as F, isSamplerType as G, isTypedTextureType as H, type InlineResolve as I, isDepthTextureType as J, isStorageTextureType as K, isExternalTextureType as L, type WgslData as M, type WgslPointer as N, type AnyWgslPointer as O, isPointer as P, type BuiltInPossibleTypes as Q, type ResolutionCtx as R, type StorageTextureParams as S, type TextureUsage as T, type Unsubscribe as U, builtin as V, type WgslResolvable as W, type Builtin as X, getBuiltinInfo as Y, getUsedBuiltinsNamed as Z, type U32 as _, type WgslSlot as a, type Bool as a0, bool as a1, u32 as a2, i32 as a3, type F32 as a4, f32 as a5, type Vec2u as a6, vec2u as a7, type Vec2i as a8, vec2i as a9, type Vec2f as aa, vec2f as ab, type Vec3u as ac, vec3u as ad, type Vec3i as ae, vec3i as af, type Vec3f as ag, vec3f as ah, type Vec4u as ai, vec4u as aj, type Vec4i as ak, vec4i as al, type Vec4f as am, vec4f as an, type Mat4f as ao, mat4f as ap, type Wgsl as b, type WgslRenderResource as c, type SampledTextureParams as d, type AnyWgslPrimitive as e, type WgslRenderResourceType as f, type StorageTextureAccess as g, type WgslPlum as h, type ExtractPlumValue as i, type WgslSettable as j, type AnyWgslData as k, type WgslAllocatable as l, type WgslBindable as m, type WgslFnArgument as n, type WgslValue as o, WgslIdentifier as p, type WgslResolvableSlot as q, plum as r, plumFromEvent as s, isResolvable as t, isWgsl as u, isSlot as v, type EventualGetter as w, type SlotValuePair as x, type WgslSamplerType as y, type WgslTypedTextureType as z };
@@ -0,0 +1,243 @@
1
+ import * as TB from 'typed-binary';
2
+ import { Parsed, ISchema } from 'typed-binary';
3
+
4
+ type Bool = WgslData<boolean>;
5
+ declare const bool: Bool;
6
+ type U32 = WgslData<number>;
7
+ declare const u32: U32;
8
+ type I32 = WgslData<number>;
9
+ declare const i32: I32;
10
+ type F32 = WgslData<number>;
11
+ declare const f32: F32;
12
+ type Vec2u = WgslData<[number, number]>;
13
+ declare const vec2u: Vec2u;
14
+ type Vec2i = WgslData<[number, number]>;
15
+ declare const vec2i: Vec2i;
16
+ type Vec2f = WgslData<[number, number]>;
17
+ declare const vec2f: Vec2f;
18
+ type Vec3u = WgslData<[number, number, number]>;
19
+ declare const vec3u: Vec3u;
20
+ type Vec3i = WgslData<[number, number, number]>;
21
+ declare const vec3i: Vec3i;
22
+ type Vec3f = WgslData<[number, number, number]>;
23
+ declare const vec3f: Vec3f;
24
+ type Vec4u = WgslData<[number, number, number, number]>;
25
+ declare const vec4u: Vec4u;
26
+ type Vec4i = WgslData<[number, number, number, number]>;
27
+ declare const vec4i: Vec4i;
28
+ type Vec4f = WgslData<[number, number, number, number]>;
29
+ declare const vec4f: Vec4f;
30
+ /**
31
+ * Array of column vectors
32
+ */
33
+ type Mat4f = WgslData<number[]>;
34
+ declare const mat4f: Mat4f;
35
+
36
+ /**
37
+ * Helpful when creating new Resolvable types. For internal use.
38
+ */
39
+ declare class WgslIdentifier implements WgslResolvable {
40
+ label?: string | undefined;
41
+ $name(label: string | undefined): this;
42
+ resolve(ctx: ResolutionCtx): string;
43
+ toString(): string;
44
+ }
45
+
46
+ type BuiltInPossibleTypes = U32 | F32 | Vec3u | Vec4f | WgslData<TB.Unwrap<U32>[]>;
47
+ declare const builtin: {
48
+ readonly vertexIndex: symbol;
49
+ readonly instanceIndex: symbol;
50
+ readonly position: symbol;
51
+ readonly clipDistances: symbol;
52
+ readonly frontFacing: symbol;
53
+ readonly fragDepth: symbol;
54
+ readonly sampleIndex: symbol;
55
+ readonly sampleMask: symbol;
56
+ readonly fragment: symbol;
57
+ readonly localInvocationId: symbol;
58
+ readonly localInvocationIndex: symbol;
59
+ readonly globalInvocationId: symbol;
60
+ readonly workgroupId: symbol;
61
+ readonly numWorkgroups: symbol;
62
+ };
63
+ interface Builtin {
64
+ name: string;
65
+ stage: 'vertex' | 'fragment' | 'compute';
66
+ direction: 'input' | 'output';
67
+ type: BuiltInPossibleTypes;
68
+ identifier: WgslIdentifier;
69
+ }
70
+ declare function getBuiltinInfo(s: symbol): Builtin;
71
+ declare function getUsedBuiltinsNamed(o: Record<symbol, string>): {
72
+ name: string;
73
+ builtin: Builtin;
74
+ }[];
75
+
76
+ declare const WgslSettableTrait: unique symbol;
77
+ interface WgslSettable {
78
+ readonly [WgslSettableTrait]: true;
79
+ }
80
+
81
+ type Getter = <T>(plum: WgslPlum<T>) => T;
82
+ type Unsubscribe = () => unknown;
83
+ type ExtractPlumValue<T> = T extends WgslPlum<infer TValue> ? TValue : never;
84
+ interface WgslPlum<TValue = unknown> {
85
+ readonly __brand: 'WgslPlum';
86
+ $name(label: string): this;
87
+ /**
88
+ * Computes the value of this plum. Circumvents the store
89
+ * memoization, so use with care.
90
+ */
91
+ compute(get: Getter): TValue;
92
+ }
93
+ declare const WgslExternalPlumTrait: unique symbol;
94
+ interface WgslExternalPlum {
95
+ readonly [WgslExternalPlumTrait]: true;
96
+ readonly version: number;
97
+ subscribe(listener: () => unknown): Unsubscribe;
98
+ }
99
+ /**
100
+ * Creates a computed plum. Its value depends on the plums read using `get`
101
+ * inside the `compute` function, so cannot be set imperatively.
102
+ *
103
+ * @param compute A pure function that describes this plum's value.
104
+ */
105
+ declare function plum<T extends Wgsl>(compute: (get: Getter) => T): WgslPlum<T> & WgslResolvable;
106
+ /**
107
+ * Creates a computed plum. Its value depends on the plums read using `get`
108
+ * inside the `compute` function, so cannot be set imperatively.
109
+ *
110
+ * @param compute A pure function that describes this plum's value.
111
+ */
112
+ declare function plum<T>(compute: (get: Getter) => T): WgslPlum<T>;
113
+ /**
114
+ * Creates a plum with an initial value of `initial`.
115
+ * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
116
+ *
117
+ * @param initial The initial value of this plum.
118
+ */
119
+ declare function plum<T extends Wgsl>(initial: T): WgslPlum<T> & WgslSettable & WgslResolvable;
120
+ /**
121
+ * Creates a plum with an initial value of `initial`.
122
+ * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
123
+ *
124
+ * @param initial The initial value of this plum.
125
+ */
126
+ declare function plum<T>(initial: T): WgslPlum<T> & WgslSettable;
127
+ declare function plumFromEvent<T>(subscribe: (listener: () => unknown) => Unsubscribe, getLatest: () => T): WgslPlum<T> & WgslExternalPlum;
128
+
129
+ type Wgsl = string | number | WgslResolvable | symbol | boolean;
130
+ /**
131
+ * Passed into each resolvable item. All sibling items share a resolution ctx,
132
+ * and a new resolution ctx is made when going down each level in the tree.
133
+ */
134
+ interface ResolutionCtx {
135
+ /**
136
+ * Slots that were used by items resolved by this context.
137
+ */
138
+ readonly usedSlots: Iterable<WgslSlot<unknown>>;
139
+ addDeclaration(item: WgslResolvable): void;
140
+ addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;
141
+ addRenderResource(resource: WgslRenderResource, identifier: WgslIdentifier): void;
142
+ addBuiltin(builtin: Builtin): void;
143
+ nameFor(token: WgslResolvable): string;
144
+ /**
145
+ * Unwraps all layers of slot indirection and returns the concrete value if available.
146
+ * @throws {MissingSlotValueError}
147
+ */
148
+ unwrap<T>(eventual: Eventual<T>): T;
149
+ resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
150
+ }
151
+ interface WgslResolvable {
152
+ readonly label?: string | undefined;
153
+ resolve(ctx: ResolutionCtx): string;
154
+ }
155
+ declare function isResolvable(value: unknown): value is WgslResolvable;
156
+ declare function isWgsl(value: unknown): value is Wgsl;
157
+ interface WgslSlot<T> {
158
+ readonly __brand: 'WgslSlot';
159
+ readonly defaultValue: T | undefined;
160
+ readonly label?: string | undefined;
161
+ $name(label: string): WgslSlot<T>;
162
+ /**
163
+ * Used to determine if code generated using either value `a` or `b` in place
164
+ * of the slot will be equivalent. Defaults to `Object.is`.
165
+ */
166
+ areEqual(a: T, b: T): boolean;
167
+ }
168
+ declare function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T>;
169
+ /**
170
+ * Represents a value that is available at resolution time.
171
+ */
172
+ type Eventual<T> = T | WgslSlot<T>;
173
+ type EventualGetter = <T>(value: Eventual<T>) => T;
174
+ type InlineResolve = (get: EventualGetter) => Wgsl;
175
+ interface WgslResolvableSlot<T extends Wgsl> extends WgslResolvable, WgslSlot<T> {
176
+ $name(label: string): WgslResolvableSlot<T>;
177
+ }
178
+ type SlotValuePair<T> = [WgslSlot<T>, T];
179
+ interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {
180
+ /**
181
+ * The data type this allocatable was constructed with.
182
+ * It informs the size and format of data in both JS and
183
+ * binary.
184
+ */
185
+ readonly dataType: TData;
186
+ vertexLayout: Omit<GPUVertexBufferLayout, 'attributes'> | null;
187
+ readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;
188
+ readonly flags: GPUBufferUsageFlags;
189
+ get label(): string | undefined;
190
+ }
191
+ interface WgslBindable<TData extends AnyWgslData = AnyWgslData, TUsage extends BufferUsage = BufferUsage> extends WgslResolvable {
192
+ readonly allocatable: WgslAllocatable<TData>;
193
+ readonly usage: TUsage;
194
+ }
195
+ type WgslSamplerType = 'sampler' | 'sampler_comparison';
196
+ type WgslTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
197
+ type WgslDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
198
+ type WgslStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
199
+ type WgslExternalTextureType = 'texture_external';
200
+ type WgslRenderResourceType = WgslSamplerType | WgslTypedTextureType | WgslDepthTextureType | WgslStorageTextureType | WgslExternalTextureType;
201
+ interface WgslRenderResource extends WgslResolvable {
202
+ readonly type: WgslRenderResourceType;
203
+ }
204
+ type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
205
+ type TextureUsage = 'sampled' | 'storage';
206
+ type StorageTextureAccess = 'read' | 'write' | 'read_write';
207
+ type StorageTextureParams = {
208
+ type: WgslStorageTextureType;
209
+ access: StorageTextureAccess;
210
+ descriptor?: GPUTextureViewDescriptor;
211
+ };
212
+ type SampledTextureParams = {
213
+ type: WgslTypedTextureType;
214
+ dataType: AnyWgslPrimitive;
215
+ descriptor?: GPUTextureViewDescriptor;
216
+ };
217
+ declare function isSamplerType(type: WgslRenderResourceType): type is WgslSamplerType;
218
+ declare function isTypedTextureType(type: WgslRenderResourceType): type is WgslTypedTextureType;
219
+ declare function isDepthTextureType(type: WgslRenderResourceType): type is WgslDepthTextureType;
220
+ declare function isStorageTextureType(type: WgslRenderResourceType): type is WgslStorageTextureType;
221
+ declare function isExternalTextureType(type: WgslRenderResourceType): type is WgslExternalTextureType;
222
+ interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {
223
+ readonly byteAlignment: number;
224
+ readonly size: number;
225
+ }
226
+ type AnyWgslData = WgslData<unknown>;
227
+ type AnyWgslPrimitive = U32 | I32 | F32;
228
+ type AnyWgslTexelFormat = Vec4u | Vec4i | Vec4f;
229
+ interface WgslPointer<TScope extends 'function', TInner extends AnyWgslData> {
230
+ readonly scope: TScope;
231
+ readonly pointsTo: TInner;
232
+ }
233
+ /**
234
+ * A virtual representation of a WGSL value.
235
+ */
236
+ type WgslValue<TDataType> = {
237
+ readonly __dataType: TDataType;
238
+ };
239
+ type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;
240
+ type WgslFnArgument = AnyWgslPointer | AnyWgslData;
241
+ declare function isPointer(value: AnyWgslPointer | AnyWgslData): value is AnyWgslPointer;
242
+
243
+ export { type I32 as $, type AnyWgslTexelFormat as A, type BufferUsage as B, type WgslDepthTextureType as C, type WgslStorageTextureType as D, type Eventual as E, type WgslExternalTextureType as F, isSamplerType as G, isTypedTextureType as H, type InlineResolve as I, isDepthTextureType as J, isStorageTextureType as K, isExternalTextureType as L, type WgslData as M, type WgslPointer as N, type AnyWgslPointer as O, isPointer as P, type BuiltInPossibleTypes as Q, type ResolutionCtx as R, type StorageTextureParams as S, type TextureUsage as T, type Unsubscribe as U, builtin as V, type WgslResolvable as W, type Builtin as X, getBuiltinInfo as Y, getUsedBuiltinsNamed as Z, type U32 as _, type WgslSlot as a, type Bool as a0, bool as a1, u32 as a2, i32 as a3, type F32 as a4, f32 as a5, type Vec2u as a6, vec2u as a7, type Vec2i as a8, vec2i as a9, type Vec2f as aa, vec2f as ab, type Vec3u as ac, vec3u as ad, type Vec3i as ae, vec3i as af, type Vec3f as ag, vec3f as ah, type Vec4u as ai, vec4u as aj, type Vec4i as ak, vec4i as al, type Vec4f as am, vec4f as an, type Mat4f as ao, mat4f as ap, type Wgsl as b, type WgslRenderResource as c, type SampledTextureParams as d, type AnyWgslPrimitive as e, type WgslRenderResourceType as f, type StorageTextureAccess as g, type WgslPlum as h, type ExtractPlumValue as i, type WgslSettable as j, type AnyWgslData as k, type WgslAllocatable as l, type WgslBindable as m, type WgslFnArgument as n, type WgslValue as o, WgslIdentifier as p, type WgslResolvableSlot as q, plum as r, plumFromEvent as s, isResolvable as t, isWgsl as u, isSlot as v, type EventualGetter as w, type SlotValuePair as x, type WgslSamplerType as y, type WgslTypedTextureType as z };
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var y=Object.defineProperty,f=Object.defineProperties;var b=Object.getOwnPropertyDescriptors;var o=Object.getOwnPropertySymbols;var d=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable;var i=(t,e,l)=>e in t?y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[e]=l,T= exports.a =(t,e)=>{for(var l in e||(e={}))d.call(e,l)&&i(t,l,e[l]);if(o)for(var l of o(e))p.call(e,l)&&i(t,l,e[l]);return t},m= exports.b =(t,e)=>f(t,b(e));var x=(t,e)=>{var l={};for(var n in t)d.call(t,n)&&e.indexOf(n)<0&&(l[n]=t[n]);if(t!=null&&o)for(var n of o(t))e.indexOf(n)<0&&p.call(t,n)&&(l[n]=t[n]);return l};var a=(t,e,l)=>(i(t,typeof e!="symbol"?e+"":e,l),l);function g(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"resolve"in t}function v(t){return typeof t=="number"||typeof t=="string"||g(t)}function R(t){return t.__brand==="WgslSlot"}function S(t){return"pointsTo"in t}function P(t,...e){let l=t.flatMap((n,r)=>{let s=e[r];return s===void 0?[n]:Array.isArray(s)?[n,...s]:[n,s]});return new u(l)}var u=class{constructor(e){this.segments=e;a(this,"_label")}get label(){return this._label}$name(e){return this._label=e,this}resolve(e){let l="";for(let n of this.segments)if(typeof n=="function"){let r=n(s=>e.unwrap(s));l+=e.resolve(r)}else g(n)?l+=e.resolve(n):l+=String(n);return l}toString(){var e;return`code:${(e=this._label)!=null?e:"<unnamed>"}`}};var W=class{constructor(){a(this,"label")}$name(e){return this.label=e,this}resolve(e){return e.nameFor(this)}toString(){var e;return`id:${(e=this.label)!=null?e:"<unnamed>"}`}};exports.a = T; exports.b = m; exports.c = x; exports.d = a; exports.e = g; exports.f = v; exports.g = R; exports.h = S; exports.i = P; exports.j = W;
2
- //# sourceMappingURL=chunk-3VCFA6WZ.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts","../src/wgslCode.ts","../src/wgslIdentifier.ts"],"names":["isResolvable","value","isWgsl","isSlot","isPointer","code","strings","params","segments","string","idx","param","WgslCodeImpl","__publicField","label","ctx","s","result","eventual","_a","W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N,KAA+C,CAA/C,cACLP,EAAA,cAEA,MAAMC,EAA2B,CAC/B,YAAK,MAAQA,EACN,IACT,CAEA,QAAQC,EAA4B,CAClC,OAAOA,EAAI,QAAQ,IAAI,CACzB,CAEA,UAAmB,CAjBrB,IAAAI,EAkBI,MAAO,OAAMA,EAAA,KAAK,QAAL,KAAAA,EAAc,WAAW,EACxC,CACF","sourcesContent":["import type { ISchema, Parsed } from 'typed-binary';\nimport type { WgslIdentifier } from './wgslIdentifier';\nimport type { WgslPlum } from './wgslPlum';\n\nexport type Wgsl = string | boolean | number | WgslResolvable;\n\n/**\n * Passed into each resolvable item. All sibling items share a resolution ctx,\n * and a new resolution ctx is made when going down each level in the tree.\n */\nexport interface ResolutionCtx {\n /**\n * Slots that were used by items resolved by this context.\n */\n readonly usedSlots: Iterable<WgslSlot<unknown>>;\n\n addDeclaration(item: WgslResolvable): void;\n addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;\n nameFor(token: WgslResolvable): string;\n /**\n * Unwraps all layers of slot indirection and returns the concrete value if available.\n * @throws {MissingSlotValueError}\n */\n unwrap<T>(eventual: Eventual<T>): T;\n resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;\n}\n\nexport interface WgslResolvable {\n readonly label?: string | undefined;\n\n resolve(ctx: ResolutionCtx): string;\n}\n\nexport function isResolvable(value: unknown): value is WgslResolvable {\n return (\n !!value &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'resolve' in value\n );\n}\n\nexport function isWgsl(value: unknown): value is Wgsl {\n return (\n typeof value === 'number' ||\n typeof value === 'string' ||\n isResolvable(value)\n );\n}\n\nexport interface WgslSlot<T> {\n readonly __brand: 'WgslSlot';\n\n readonly defaultValue: T | undefined;\n\n readonly label?: string | undefined;\n\n $name(label: string): WgslSlot<T>;\n\n /**\n * Used to determine if code generated using either value `a` or `b` in place\n * of the slot will be equivalent. Defaults to `Object.is`.\n */\n areEqual(a: T, b: T): boolean;\n}\n\nexport function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T> {\n return (value as WgslSlot<T>).__brand === 'WgslSlot';\n}\n\n/**\n * Represents a value that is available at resolution time.\n */\nexport type Eventual<T> = T | WgslSlot<T>;\n\nexport type EventualGetter = <T>(value: Eventual<T>) => T;\n\nexport type InlineResolve = (get: EventualGetter) => Wgsl;\n\nexport interface WgslResolvableSlot<T extends Wgsl>\n extends WgslResolvable,\n WgslSlot<T> {\n $name(label: string): WgslResolvableSlot<T>;\n}\n\nexport type SlotValuePair<T> = [WgslSlot<T>, T];\n\nexport interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {\n /**\n * The data type this allocatable was constructed with.\n * It informs the size and format of data in both JS and\n * binary.\n */\n readonly dataType: TData;\n readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;\n readonly flags: GPUBufferUsageFlags;\n}\n\nexport interface WgslBindable<\n TData extends AnyWgslData = AnyWgslData,\n TUsage extends BufferUsage = BufferUsage,\n> extends WgslResolvable {\n readonly allocatable: WgslAllocatable<TData>;\n readonly usage: TUsage;\n}\n\nexport type BufferUsage = 'uniform' | 'readonly_storage' | 'mutable_storage';\n\nexport interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {\n readonly byteAlignment: number;\n readonly size: number;\n}\n\nexport type AnyWgslData = WgslData<unknown>;\n\nexport interface WgslPointer<\n TScope extends 'function',\n TInner extends AnyWgslData,\n> {\n readonly scope: TScope;\n readonly pointsTo: TInner;\n}\n\n/**\n * A virtual representation of a WGSL value.\n */\nexport type WgslValue<TDataType> = {\n readonly __dataType: TDataType;\n};\n\nexport type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;\n\nexport type WgslFnArgument = AnyWgslPointer | AnyWgslData;\n\nexport function isPointer(\n value: AnyWgslPointer | AnyWgslData,\n): value is AnyWgslPointer {\n return 'pointsTo' in value;\n}\n","import {\n type InlineResolve,\n type ResolutionCtx,\n type Wgsl,\n type WgslResolvable,\n isResolvable,\n} from './types';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslCode extends WgslResolvable {\n $name(label?: string | undefined): WgslCode;\n}\n\nexport function code(\n strings: TemplateStringsArray,\n ...params: (Wgsl | Wgsl[] | InlineResolve)[]\n): WgslCode {\n const segments: (Wgsl | InlineResolve)[] = strings.flatMap((string, idx) => {\n const param = params[idx];\n if (param === undefined) {\n return [string];\n }\n\n return Array.isArray(param) ? [string, ...param] : [string, param];\n });\n\n return new WgslCodeImpl(segments);\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslCodeImpl implements WgslCode {\n private _label: string | undefined;\n\n constructor(public readonly segments: (Wgsl | InlineResolve)[]) {}\n\n get label() {\n return this._label;\n }\n\n $name(label?: string | undefined) {\n this._label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx) {\n let code = '';\n\n for (const s of this.segments) {\n if (typeof s === 'function') {\n const result = s((eventual) => ctx.unwrap(eventual));\n code += ctx.resolve(result);\n } else if (isResolvable(s)) {\n code += ctx.resolve(s);\n } else {\n code += String(s);\n }\n }\n\n return code;\n }\n\n toString(): string {\n return `code:${this._label ?? '<unnamed>'}`;\n }\n}\n","import type { ResolutionCtx, WgslResolvable } from './types';\n\n/**\n * Helpful when creating new Resolvable types. For internal use.\n */\nexport class WgslIdentifier implements WgslResolvable {\n label?: string | undefined;\n\n $name(label: string | undefined) {\n this.label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.nameFor(this);\n }\n\n toString(): string {\n return `id:${this.label ?? '<unnamed>'}`;\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var o=class t extends Error{constructor(s){super(`Missing value for '${s}'`);this.slot=s;Object.setPrototypeOf(this,t.prototype)}},e= exports.b =class t extends Error{constructor(){super("Recursive types are not supported in WGSL"),Object.setPrototypeOf(this,t.prototype)}};exports.a = o; exports.b = e;
2
- //# sourceMappingURL=chunk-G3U6RTMF.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts"],"names":["MissingSlotValueError","_MissingSlotValueError","slot","RecursiveDataTypeError","_RecursiveDataTypeError"],"mappings":"AAKO,IAAMA,EAAN,MAAMC,UAA8B,KAAM,CAC/C,YAA4BC,EAAyB,CACnD,MAAM,sBAAsBA,CAAI,GAAG,EADT,UAAAA,EAI1B,OAAO,eAAe,KAAMD,EAAsB,SAAS,CAC7D,CACF,EAKaE,EAAN,MAAMC,UAA+B,KAAM,CAChD,aAAc,CACZ,MAAM,2CAA2C,EAGjD,OAAO,eAAe,KAAMA,EAAuB,SAAS,CAC9D,CACF","sourcesContent":["import type { WgslSlot } from './types';\n\n/**\n * @category Errors\n */\nexport class MissingSlotValueError extends Error {\n constructor(public readonly slot: WgslSlot<unknown>) {\n super(`Missing value for '${slot}'`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, MissingSlotValueError.prototype);\n }\n}\n\n/**\n * @category Errors\n */\nexport class RecursiveDataTypeError extends Error {\n constructor() {\n super('Recursive types are not supported in WGSL');\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, RecursiveDataTypeError.prototype);\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- var y=Object.defineProperty,f=Object.defineProperties;var b=Object.getOwnPropertyDescriptors;var o=Object.getOwnPropertySymbols;var d=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable;var i=(t,e,l)=>e in t?y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[e]=l,T=(t,e)=>{for(var l in e||(e={}))d.call(e,l)&&i(t,l,e[l]);if(o)for(var l of o(e))p.call(e,l)&&i(t,l,e[l]);return t},m=(t,e)=>f(t,b(e));var x=(t,e)=>{var l={};for(var n in t)d.call(t,n)&&e.indexOf(n)<0&&(l[n]=t[n]);if(t!=null&&o)for(var n of o(t))e.indexOf(n)<0&&p.call(t,n)&&(l[n]=t[n]);return l};var a=(t,e,l)=>(i(t,typeof e!="symbol"?e+"":e,l),l);function g(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"resolve"in t}function v(t){return typeof t=="number"||typeof t=="string"||g(t)}function R(t){return t.__brand==="WgslSlot"}function S(t){return"pointsTo"in t}function P(t,...e){let l=t.flatMap((n,r)=>{let s=e[r];return s===void 0?[n]:Array.isArray(s)?[n,...s]:[n,s]});return new u(l)}var u=class{constructor(e){this.segments=e;a(this,"_label")}get label(){return this._label}$name(e){return this._label=e,this}resolve(e){let l="";for(let n of this.segments)if(typeof n=="function"){let r=n(s=>e.unwrap(s));l+=e.resolve(r)}else g(n)?l+=e.resolve(n):l+=String(n);return l}toString(){var e;return`code:${(e=this._label)!=null?e:"<unnamed>"}`}};var W=class{constructor(){a(this,"label")}$name(e){return this.label=e,this}resolve(e){return e.nameFor(this)}toString(){var e;return`id:${(e=this.label)!=null?e:"<unnamed>"}`}};export{T as a,m as b,x as c,a as d,g as e,v as f,R as g,S as h,P as i,W as j};
2
- //# sourceMappingURL=chunk-GHP25GEO.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts","../src/wgslCode.ts","../src/wgslIdentifier.ts"],"sourcesContent":["import type { ISchema, Parsed } from 'typed-binary';\nimport type { WgslIdentifier } from './wgslIdentifier';\nimport type { WgslPlum } from './wgslPlum';\n\nexport type Wgsl = string | boolean | number | WgslResolvable;\n\n/**\n * Passed into each resolvable item. All sibling items share a resolution ctx,\n * and a new resolution ctx is made when going down each level in the tree.\n */\nexport interface ResolutionCtx {\n /**\n * Slots that were used by items resolved by this context.\n */\n readonly usedSlots: Iterable<WgslSlot<unknown>>;\n\n addDeclaration(item: WgslResolvable): void;\n addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;\n nameFor(token: WgslResolvable): string;\n /**\n * Unwraps all layers of slot indirection and returns the concrete value if available.\n * @throws {MissingSlotValueError}\n */\n unwrap<T>(eventual: Eventual<T>): T;\n resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;\n}\n\nexport interface WgslResolvable {\n readonly label?: string | undefined;\n\n resolve(ctx: ResolutionCtx): string;\n}\n\nexport function isResolvable(value: unknown): value is WgslResolvable {\n return (\n !!value &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'resolve' in value\n );\n}\n\nexport function isWgsl(value: unknown): value is Wgsl {\n return (\n typeof value === 'number' ||\n typeof value === 'string' ||\n isResolvable(value)\n );\n}\n\nexport interface WgslSlot<T> {\n readonly __brand: 'WgslSlot';\n\n readonly defaultValue: T | undefined;\n\n readonly label?: string | undefined;\n\n $name(label: string): WgslSlot<T>;\n\n /**\n * Used to determine if code generated using either value `a` or `b` in place\n * of the slot will be equivalent. Defaults to `Object.is`.\n */\n areEqual(a: T, b: T): boolean;\n}\n\nexport function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T> {\n return (value as WgslSlot<T>).__brand === 'WgslSlot';\n}\n\n/**\n * Represents a value that is available at resolution time.\n */\nexport type Eventual<T> = T | WgslSlot<T>;\n\nexport type EventualGetter = <T>(value: Eventual<T>) => T;\n\nexport type InlineResolve = (get: EventualGetter) => Wgsl;\n\nexport interface WgslResolvableSlot<T extends Wgsl>\n extends WgslResolvable,\n WgslSlot<T> {\n $name(label: string): WgslResolvableSlot<T>;\n}\n\nexport type SlotValuePair<T> = [WgslSlot<T>, T];\n\nexport interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {\n /**\n * The data type this allocatable was constructed with.\n * It informs the size and format of data in both JS and\n * binary.\n */\n readonly dataType: TData;\n readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;\n readonly flags: GPUBufferUsageFlags;\n}\n\nexport interface WgslBindable<\n TData extends AnyWgslData = AnyWgslData,\n TUsage extends BufferUsage = BufferUsage,\n> extends WgslResolvable {\n readonly allocatable: WgslAllocatable<TData>;\n readonly usage: TUsage;\n}\n\nexport type BufferUsage = 'uniform' | 'readonly_storage' | 'mutable_storage';\n\nexport interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {\n readonly byteAlignment: number;\n readonly size: number;\n}\n\nexport type AnyWgslData = WgslData<unknown>;\n\nexport interface WgslPointer<\n TScope extends 'function',\n TInner extends AnyWgslData,\n> {\n readonly scope: TScope;\n readonly pointsTo: TInner;\n}\n\n/**\n * A virtual representation of a WGSL value.\n */\nexport type WgslValue<TDataType> = {\n readonly __dataType: TDataType;\n};\n\nexport type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;\n\nexport type WgslFnArgument = AnyWgslPointer | AnyWgslData;\n\nexport function isPointer(\n value: AnyWgslPointer | AnyWgslData,\n): value is AnyWgslPointer {\n return 'pointsTo' in value;\n}\n","import {\n type InlineResolve,\n type ResolutionCtx,\n type Wgsl,\n type WgslResolvable,\n isResolvable,\n} from './types';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslCode extends WgslResolvable {\n $name(label?: string | undefined): WgslCode;\n}\n\nexport function code(\n strings: TemplateStringsArray,\n ...params: (Wgsl | Wgsl[] | InlineResolve)[]\n): WgslCode {\n const segments: (Wgsl | InlineResolve)[] = strings.flatMap((string, idx) => {\n const param = params[idx];\n if (param === undefined) {\n return [string];\n }\n\n return Array.isArray(param) ? [string, ...param] : [string, param];\n });\n\n return new WgslCodeImpl(segments);\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslCodeImpl implements WgslCode {\n private _label: string | undefined;\n\n constructor(public readonly segments: (Wgsl | InlineResolve)[]) {}\n\n get label() {\n return this._label;\n }\n\n $name(label?: string | undefined) {\n this._label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx) {\n let code = '';\n\n for (const s of this.segments) {\n if (typeof s === 'function') {\n const result = s((eventual) => ctx.unwrap(eventual));\n code += ctx.resolve(result);\n } else if (isResolvable(s)) {\n code += ctx.resolve(s);\n } else {\n code += String(s);\n }\n }\n\n return code;\n }\n\n toString(): string {\n return `code:${this._label ?? '<unnamed>'}`;\n }\n}\n","import type { ResolutionCtx, WgslResolvable } from './types';\n\n/**\n * Helpful when creating new Resolvable types. For internal use.\n */\nexport class WgslIdentifier implements WgslResolvable {\n label?: string | undefined;\n\n $name(label: string | undefined) {\n this.label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.nameFor(this);\n }\n\n toString(): string {\n return `id:${this.label ?? '<unnamed>'}`;\n }\n}\n"],"mappings":"moBAiCO,SAASA,EAAaC,EAAyC,CACpE,MACE,CAAC,CAACA,IACD,OAAOA,GAAU,UAAY,OAAOA,GAAU,aAC/C,YAAaA,CAEjB,CAEO,SAASC,EAAOD,EAA+B,CACpD,OACE,OAAOA,GAAU,UACjB,OAAOA,GAAU,UACjBD,EAAaC,CAAK,CAEtB,CAkBO,SAASE,EAAUF,EAAoD,CAC5E,OAAQA,EAAsB,UAAY,UAC5C,CAkEO,SAASG,EACdH,EACyB,CACzB,MAAO,aAAcA,CACvB,CCzHO,SAASI,EACdC,KACGC,EACO,CACV,IAAMC,EAAqCF,EAAQ,QAAQ,CAACG,EAAQC,IAAQ,CAC1E,IAAMC,EAAQJ,EAAOG,CAAG,EACxB,OAAIC,IAAU,OACL,CAACF,CAAM,EAGT,MAAM,QAAQE,CAAK,EAAI,CAACF,EAAQ,GAAGE,CAAK,EAAI,CAACF,EAAQE,CAAK,CACnE,CAAC,EAED,OAAO,IAAIC,EAAaJ,CAAQ,CAClC,CAMA,IAAMI,EAAN,KAAuC,CAGrC,YAA4BJ,EAAoC,CAApC,cAAAA,EAF5BK,EAAA,KAAQ,SAEyD,CAEjE,IAAI,OAAQ,CACV,OAAO,KAAK,MACd,CAEA,MAAMC,EAA4B,CAChC,YAAK,OAASA,EACP,IACT,CAEA,QAAQC,EAAoB,CAC1B,IAAIV,EAAO,GAEX,QAAWW,KAAK,KAAK,SACnB,GAAI,OAAOA,GAAM,WAAY,CAC3B,IAAMC,EAASD,EAAGE,GAAaH,EAAI,OAAOG,CAAQ,CAAC,EACnDb,GAAQU,EAAI,QAAQE,CAAM,CAC5B,MAAWE,EAAaH,CAAC,EACvBX,GAAQU,EAAI,QAAQC,CAAC,EAErBX,GAAQ,OAAOW,CAAC,EAIpB,OAAOX,CACT,CAEA,UAAmB,CAnErB,IAAAe,EAoEI,MAAO,SAAQA,EAAA,KAAK,SAAL,KAAAA,EAAe,WAAW,EAC3C,CACF,ECjEO,IAAMC,EAAN,KAA+C,CAA/C,cACLC,EAAA,cAEA,MAAMC,EAA2B,CAC/B,YAAK,MAAQA,EACN,IACT,CAEA,QAAQC,EAA4B,CAClC,OAAOA,EAAI,QAAQ,IAAI,CACzB,CAEA,UAAmB,CAjBrB,IAAAC,EAkBI,MAAO,OAAMA,EAAA,KAAK,QAAL,KAAAA,EAAc,WAAW,EACxC,CACF","names":["isResolvable","value","isWgsl","isSlot","isPointer","code","strings","params","segments","string","idx","param","WgslCodeImpl","__publicField","label","ctx","s","result","eventual","isResolvable","_a","WgslIdentifier","__publicField","label","ctx","_a"]}
@@ -1,2 +0,0 @@
1
- var o=class t extends Error{constructor(s){super(`Missing value for '${s}'`);this.slot=s;Object.setPrototypeOf(this,t.prototype)}},e=class t extends Error{constructor(){super("Recursive types are not supported in WGSL"),Object.setPrototypeOf(this,t.prototype)}};export{o as a,e as b};
2
- //# sourceMappingURL=chunk-XGSMOADT.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts"],"sourcesContent":["import type { WgslSlot } from './types';\n\n/**\n * @category Errors\n */\nexport class MissingSlotValueError extends Error {\n constructor(public readonly slot: WgslSlot<unknown>) {\n super(`Missing value for '${slot}'`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, MissingSlotValueError.prototype);\n }\n}\n\n/**\n * @category Errors\n */\nexport class RecursiveDataTypeError extends Error {\n constructor() {\n super('Recursive types are not supported in WGSL');\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, RecursiveDataTypeError.prototype);\n }\n}\n"],"mappings":"AAKO,IAAMA,EAAN,MAAMC,UAA8B,KAAM,CAC/C,YAA4BC,EAAyB,CACnD,MAAM,sBAAsBA,CAAI,GAAG,EADT,UAAAA,EAI1B,OAAO,eAAe,KAAMD,EAAsB,SAAS,CAC7D,CACF,EAKaE,EAAN,MAAMC,UAA+B,KAAM,CAChD,aAAc,CACZ,MAAM,2CAA2C,EAGjD,OAAO,eAAe,KAAMA,EAAuB,SAAS,CAC9D,CACF","names":["MissingSlotValueError","_MissingSlotValueError","slot","RecursiveDataTypeError","_RecursiveDataTypeError"]}
@@ -1,10 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _chunkG3U6RTMFcjs = require('../chunk-G3U6RTMF.cjs');var _chunk3VCFA6WZcjs = require('../chunk-3VCFA6WZ.cjs');var _typedbinary = require('typed-binary'); var t = _interopRequireWildcard(_typedbinary); var g = _interopRequireWildcard(_typedbinary);function x(n,o){let e="size"in n?n.size:n.currentByteOffset,r=o-1,i=e&r;"skipBytes"in n?n.skipBytes(o-i&r):n.add(o-i&r)}var p=x;var a=class extends _typedbinary.Schema{constructor({schema:e,byteAlignment:r,code:i}){super();_chunk3VCFA6WZcjs.d.call(void 0, this,"size");_chunk3VCFA6WZcjs.d.call(void 0, this,"byteAlignment");_chunk3VCFA6WZcjs.d.call(void 0, this,"_innerSchema");_chunk3VCFA6WZcjs.d.call(void 0, this,"_expressionCode");this._innerSchema=e,this.byteAlignment=r,this._expressionCode=i,this.size=this.measure(_typedbinary.MaxValue).size}resolveReferences(){throw new _chunkG3U6RTMFcjs.b}write(e,r){p(e,this.byteAlignment),this._innerSchema.write(e,r)}read(e){return p(e,this.byteAlignment),this._innerSchema.read(e)}measure(e,r=new _typedbinary.Measurer){return p(r,this.byteAlignment),this._innerSchema.measure(e,r),r}resolve(e){return e.resolve(this._expressionCode)}};var F=new a({schema:t.bool,byteAlignment:4,code:"bool"}),y= exports.u32 =new a({schema:t.u32,byteAlignment:4,code:"u32"}),q= exports.i32 =new a({schema:t.i32,byteAlignment:4,code:"i32"}),G= exports.f32 =new a({schema:t.f32,byteAlignment:4,code:"f32"}),H= exports.vec2u =new a({schema:t.tupleOf([t.u32,t.u32]),byteAlignment:8,code:"vec2u"}),J= exports.vec2i =new a({schema:t.tupleOf([t.i32,t.i32]),byteAlignment:8,code:"vec2i"}),K= exports.vec2f =new a({schema:t.tupleOf([t.f32,t.f32]),byteAlignment:8,code:"vec2f"}),L= exports.vec3u =new a({schema:t.tupleOf([t.u32,t.u32,t.u32]),byteAlignment:16,code:"vec3u"}),N= exports.vec3i =new a({schema:t.tupleOf([t.i32,t.i32,t.i32]),byteAlignment:16,code:"vec3i"}),Q= exports.vec3f =new a({schema:t.tupleOf([t.f32,t.f32,t.f32]),byteAlignment:16,code:"vec3f"}),X= exports.vec4u =new a({schema:t.tupleOf([t.u32,t.u32,t.u32,t.u32]),byteAlignment:16,code:"vec4u"}),Y= exports.vec4i =new a({schema:t.tupleOf([t.i32,t.i32,t.i32,t.i32]),byteAlignment:16,code:"vec4i"}),Z= exports.vec4f =new a({schema:t.tupleOf([t.f32,t.f32,t.f32,t.f32]),byteAlignment:16,code:"vec4f"}),ee= exports.mat4f =new a({schema:t.arrayOf(t.f32,16),byteAlignment:16,code:"mat4x4f"});var d=class extends _typedbinary.Schema{constructor(e,r){super();this._elementType=e;this.capacity=r;_chunk3VCFA6WZcjs.d.call(void 0, this,"_label");_chunk3VCFA6WZcjs.d.call(void 0, this,"byteAlignment");_chunk3VCFA6WZcjs.d.call(void 0, this,"size");this.byteAlignment=Math.max(4,this._elementType.byteAlignment),this.size=this.measure(_typedbinary.MaxValue).size}$name(e){return this._label=e,this}resolveReferences(){throw new _chunkG3U6RTMFcjs.b}write(e,r){if(r.length>this.capacity)throw new (0, _typedbinary.ValidationError)(`Tried to write too many values, ${r.length} > ${this.capacity}`);p(e,this.byteAlignment),y.write(e,r.length),p(e,this._elementType.byteAlignment);let i=e.currentByteOffset;for(let c of r)this._elementType.write(e,c);e.seekTo(i+this.capacity*this._elementType.size)}read(e){let r=[];p(e,this.byteAlignment);let i=y.read(e);p(e,this._elementType.byteAlignment);let c=e.currentByteOffset;for(let f=0;f<i;++f)r.push(this._elementType.read(e));return e.seekTo(c+this.capacity*this._elementType.size),r}measure(e,r=new _typedbinary.Measurer){return p(r,this.byteAlignment),y.measure(_typedbinary.MaxValue,r),p(r,this._elementType.byteAlignment),r.add(this._elementType.size*this.capacity),r}resolve(e){let r=new (0, _chunk3VCFA6WZcjs.j)().$name(this._label);return e.addDeclaration(_chunk3VCFA6WZcjs.i`
2
- struct ${r} {
3
- count: u32,
4
- values: array<${this._elementType}, ${this.capacity}>,
5
- }`),e.resolve(r)}},pe= exports.dynamicArrayOf =(n,o)=>new d(n,o);var he=n=>new h(n),h=class extends _typedbinary.Schema{constructor(e){super();this._properties=e;_chunk3VCFA6WZcjs.d.call(void 0, this,"_label");_chunk3VCFA6WZcjs.d.call(void 0, this,"_innerSchema");_chunk3VCFA6WZcjs.d.call(void 0, this,"byteAlignment");_chunk3VCFA6WZcjs.d.call(void 0, this,"size");this._innerSchema=_typedbinary.object.call(void 0, e),this.byteAlignment=Object.values(e).map(r=>r.byteAlignment).reduce((r,i)=>r>i?r:i),this.size=this.measure(_typedbinary.MaxValue).size}$name(e){return this._label=e,this}resolveReferences(){throw new _chunkG3U6RTMFcjs.b}write(e,r){this._innerSchema.write(e,r)}read(e){return this._innerSchema.read(e)}measure(e,r=new _typedbinary.Measurer){return this._innerSchema.measure(e,r),r}resolve(e){let r=new (0, _chunk3VCFA6WZcjs.j)().$name(this._label);return e.addDeclaration(_chunk3VCFA6WZcjs.i`
6
- struct ${r} {
7
- ${Object.entries(this._properties).map(([i,c])=>_chunk3VCFA6WZcjs.i`${i}: ${c},\n`)}
8
- }
9
- `),e.resolve(r)}};var xe=(n,o)=>new a({schema:g.arrayOf(n,o),byteAlignment:n.byteAlignment,code:_chunk3VCFA6WZcjs.i`array<${n}, ${o}>`});function O(n){return{scope:"function",pointsTo:n}}function R(n){return new T(n)}var T=class extends _typedbinary.Schema{constructor(e){super();this.innerData=e;_chunk3VCFA6WZcjs.d.call(void 0, this,"size");_chunk3VCFA6WZcjs.d.call(void 0, this,"byteAlignment");this.size=this.innerData.size,this.byteAlignment=this.innerData.byteAlignment}resolveReferences(){throw new _chunkG3U6RTMFcjs.b}write(e,r){this.innerData.write(e,r)}read(e){return this.innerData.read(e)}measure(e,r=new _typedbinary.Measurer){return this.innerData.measure(e,r)}resolve(e){return`atomic<${e.resolve(this.innerData)}>`}};exports.SimpleWgslData = a; exports.arrayOf = xe; exports.atomic = R; exports.bool = F; exports.dynamicArrayOf = pe; exports.f32 = G; exports.i32 = q; exports.mat4f = ee; exports.ptr = O; exports.struct = he; exports.u32 = y; exports.vec2f = K; exports.vec2i = J; exports.vec2u = H; exports.vec3f = Q; exports.vec3i = N; exports.vec3u = L; exports.vec4f = Z; exports.vec4i = Y; exports.vec4u = X;
10
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/data/std140.ts","../../src/data/alignIO.ts","../../src/data/numeric.ts","../../src/data/dynamicArray.ts","../../src/data/struct.ts","../../src/data/array.ts","../../src/data/pointer.ts","../../src/data/atomic.ts"],"names":["MaxValue","Measurer","Schema","alignIO","io","baseAlignment","currentPos","bitMask","offset","alignIO_default","SimpleWgslData","schema","byteAlignment","code","__publicField","RecursiveDataTypeError","output","value","input","measurer","ctx","TB","bool","u32","i32","f32","vec2u","vec2i","vec2f","vec3u","vec3i","vec3f","vec4u","vec4i","vec4f","mat4f","ValidationError","DynamicArrayDataType","_elementType","capacity","label","values","startOffset","array","len","i","_values","identifier","WgslIdentifier","dynamicArrayOf","elementType","object","struct","properties","WgslStructImpl","_properties","prop","a","b","key","field","arrayOf","size","ptr","pointsTo","atomic","data","AtomicImpl","innerData"],"mappings":"kGAIA,OAKE,YAAAA,EACA,YAAAC,EAEA,UAAAC,MAEK,eCRP,SAASC,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,GAC9C,CACF","sourcesContent":["/*\n * Typed-binary types that adhere to the `std140` layout rules.\n */\n\nimport {\n type AnySchema,\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { ResolutionCtx, Wgsl, WgslData } from '../types';\nimport alignIO from './alignIO';\n\nexport class SimpleWgslData<TSchema extends AnySchema>\n extends Schema<Unwrap<TSchema>>\n implements WgslData<Unwrap<TSchema>>\n{\n public readonly size: number;\n public readonly byteAlignment: number;\n\n private readonly _innerSchema: TSchema;\n private readonly _expressionCode: Wgsl;\n\n /**\n * byteAlignment has to be a power of 2\n */\n constructor({\n schema,\n byteAlignment,\n code,\n }: {\n schema: TSchema;\n byteAlignment: number;\n code: Wgsl;\n }) {\n super();\n\n this._innerSchema = schema;\n this.byteAlignment = byteAlignment;\n this._expressionCode = code;\n this.size = this.measure(MaxValue).size;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void {\n alignIO(output, this.byteAlignment);\n this._innerSchema.write(output, value);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TSchema> {\n alignIO(input, this.byteAlignment);\n return this._innerSchema.read(input) as ParseUnwrapped<TSchema>;\n }\n\n measure(\n value: ParseUnwrapped<TSchema> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment);\n\n this._innerSchema.measure(value, measurer);\n\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this._expressionCode);\n }\n}\n","import type { IMeasurer, ISerialInput, ISerialOutput } from 'typed-binary';\n\n/**\n * @param io the IO to align\n * @param baseAlignment must be power of 2\n */\nfunction alignIO(\n io: ISerialInput | ISerialOutput | IMeasurer,\n baseAlignment: number,\n) {\n const currentPos = 'size' in io ? io.size : io.currentByteOffset;\n\n const bitMask = baseAlignment - 1;\n const offset = currentPos & bitMask;\n\n if ('skipBytes' in io) {\n io.skipBytes((baseAlignment - offset) & bitMask);\n } else {\n io.add((baseAlignment - offset) & bitMask);\n }\n}\n\nexport default alignIO;\n","import * as TB from 'typed-binary';\nimport type { WgslData } from '../types';\nimport { SimpleWgslData } from './std140';\n\nexport type Bool = WgslData<boolean>;\nexport const bool: Bool = new SimpleWgslData({\n schema: TB.bool,\n byteAlignment: 4,\n code: 'bool',\n});\nexport type U32 = WgslData<number>;\nexport const u32: U32 = new SimpleWgslData({\n schema: TB.u32,\n byteAlignment: 4,\n code: 'u32',\n});\nexport type I32 = WgslData<number>;\nexport const i32: I32 = new SimpleWgslData({\n schema: TB.i32,\n byteAlignment: 4,\n code: 'i32',\n});\nexport type F32 = WgslData<number>;\nexport const f32: F32 = new SimpleWgslData({\n schema: TB.f32,\n byteAlignment: 4,\n code: 'f32',\n});\n\nexport type Vec2u = WgslData<[number, number]>;\nexport const vec2u: Vec2u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32]),\n byteAlignment: 8,\n code: 'vec2u',\n});\n\nexport type Vec2i = WgslData<[number, number]>;\nexport const vec2i: Vec2i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32]),\n byteAlignment: 8,\n code: 'vec2i',\n});\nexport type Vec2f = WgslData<[number, number]>;\nexport const vec2f: Vec2f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32]),\n byteAlignment: 8,\n code: 'vec2f',\n});\nexport type Vec3u = WgslData<[number, number, number]>;\nexport const vec3u: Vec3u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32, TB.u32]),\n byteAlignment: 16,\n code: 'vec3u',\n});\nexport type Vec3i = WgslData<[number, number, number]>;\nexport const vec3i: Vec3i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32, TB.i32]),\n byteAlignment: 16,\n code: 'vec3i',\n});\nexport type Vec3f = WgslData<[number, number, number]>;\nexport const vec3f: Vec3f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32, TB.f32]),\n byteAlignment: 16,\n code: 'vec3f',\n});\nexport type Vec4u = WgslData<[number, number, number, number]>;\nexport const vec4u: Vec4u = new SimpleWgslData({\n schema: TB.tupleOf([TB.u32, TB.u32, TB.u32, TB.u32]),\n byteAlignment: 16,\n code: 'vec4u',\n});\nexport type Vec4i = WgslData<[number, number, number, number]>;\nexport const vec4i: Vec4i = new SimpleWgslData({\n schema: TB.tupleOf([TB.i32, TB.i32, TB.i32, TB.i32]),\n byteAlignment: 16,\n code: 'vec4i',\n});\nexport type Vec4f = WgslData<[number, number, number, number]>;\nexport const vec4f: Vec4f = new SimpleWgslData({\n schema: TB.tupleOf([TB.f32, TB.f32, TB.f32, TB.f32]),\n byteAlignment: 16,\n code: 'vec4f',\n});\n\n/**\n * Array of column vectors\n */\nexport type Mat4f = WgslData<number[]>;\nexport const mat4f: Mat4f = new SimpleWgslData({\n schema: TB.arrayOf(TB.f32, 16),\n byteAlignment: 16,\n code: 'mat4x4f',\n});\n","import {\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n ValidationError,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { AnyWgslData, ResolutionCtx, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { WgslIdentifier } from '../wgslIdentifier';\nimport alignIO from './alignIO';\nimport { u32 } from './numeric';\n\nclass DynamicArrayDataType<TElement extends WgslData<unknown>>\n extends Schema<Unwrap<TElement>[]>\n implements WgslData<Unwrap<TElement>[]>\n{\n private _label: string | undefined;\n\n public readonly byteAlignment: number;\n public readonly size: number;\n\n constructor(\n private readonly _elementType: TElement,\n public readonly capacity: number,\n ) {\n super();\n\n this.byteAlignment = Math.max(\n 4 /* u32 base alignment */,\n this._elementType.byteAlignment,\n );\n\n this.size = this.measure(MaxValue).size;\n }\n\n $name(label: string) {\n this._label = label;\n return this;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, values: ParseUnwrapped<TElement>[]): void {\n if (values.length > this.capacity) {\n throw new ValidationError(\n `Tried to write too many values, ${values.length} > ${this.capacity}`,\n );\n }\n\n alignIO(output, this.byteAlignment); // aligning to the start\n u32.write(output, values.length);\n alignIO(output, this._elementType.byteAlignment); // aligning to the start of the array\n const startOffset = output.currentByteOffset;\n for (const value of values) {\n this._elementType.write(output, value);\n }\n output.seekTo(startOffset + this.capacity * this._elementType.size);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TElement>[] {\n const array: ParseUnwrapped<TElement>[] = [];\n\n alignIO(input, this.byteAlignment); // aligning to the start\n const len = u32.read(input);\n alignIO(input, this._elementType.byteAlignment); // aligning to the start of the array\n const startOffset = input.currentByteOffset;\n for (let i = 0; i < len; ++i) {\n array.push(this._elementType.read(input) as ParseUnwrapped<TElement>);\n }\n input.seekTo(startOffset + this.capacity * this._elementType.size);\n\n return array;\n }\n\n measure(\n _values: ParseUnwrapped<TElement>[] | typeof MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n alignIO(measurer, this.byteAlignment); // aligning to the start\n\n // Length encoding\n u32.measure(MaxValue, measurer);\n\n // Aligning to the start of the array\n alignIO(measurer, this._elementType.byteAlignment);\n\n // Values encoding\n measurer.add(this._elementType.size * this.capacity);\n\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n const identifier = new WgslIdentifier().$name(this._label);\n\n ctx.addDeclaration(code`\n struct ${identifier} {\n count: u32,\n values: array<${this._elementType}, ${this.capacity}>,\n }`);\n\n return ctx.resolve(identifier);\n }\n}\n\nexport const dynamicArrayOf = <TSchema extends AnyWgslData>(\n elementType: TSchema,\n capacity: number,\n) => new DynamicArrayDataType(elementType, capacity);\n\nexport default DynamicArrayDataType;\n","import {\n type IMeasurer,\n type ISchema,\n type ISerialInput,\n type ISerialOutput,\n MaxValue,\n Measurer,\n type Parsed,\n Schema,\n type UnwrapRecord,\n object,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { AnyWgslData, ResolutionCtx, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { WgslIdentifier } from '../wgslIdentifier';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslStruct<TProps extends Record<string, AnyWgslData>>\n extends ISchema<UnwrapRecord<TProps>>,\n WgslData<UnwrapRecord<TProps>> {\n $name(label: string): this;\n}\n\nexport const struct = <TProps extends Record<string, AnyWgslData>>(\n properties: TProps,\n): WgslStruct<TProps> => new WgslStructImpl(properties);\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslStructImpl<TProps extends Record<string, AnyWgslData>>\n extends Schema<UnwrapRecord<TProps>>\n implements WgslData<UnwrapRecord<TProps>>\n{\n private _label: string | undefined;\n private _innerSchema: ISchema<UnwrapRecord<TProps>>;\n\n public readonly byteAlignment: number;\n public readonly size: number;\n\n constructor(private readonly _properties: TProps) {\n super();\n\n this._innerSchema = object(_properties);\n\n this.byteAlignment = Object.values(_properties)\n .map((prop) => prop.byteAlignment)\n .reduce((a, b) => (a > b ? a : b));\n\n this.size = this.measure(MaxValue).size;\n }\n\n $name(label: string) {\n this._label = label;\n return this;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: Parsed<UnwrapRecord<TProps>>): void {\n this._innerSchema.write(output, value);\n }\n\n read(input: ISerialInput): Parsed<UnwrapRecord<TProps>> {\n return this._innerSchema.read(input);\n }\n\n measure(\n value: MaxValue | Parsed<UnwrapRecord<TProps>>,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n this._innerSchema.measure(value, measurer);\n return measurer;\n }\n\n resolve(ctx: ResolutionCtx): string {\n const identifier = new WgslIdentifier().$name(this._label);\n\n ctx.addDeclaration(code`\n struct ${identifier} {\n ${Object.entries(this._properties).map(([key, field]) => code`${key}: ${field},\\n`)}\n }\n `);\n\n return ctx.resolve(identifier);\n }\n}\n","import * as TB from 'typed-binary';\nimport type { AnyWgslData, WgslData } from '../types';\nimport { code } from '../wgslCode';\nimport { SimpleWgslData } from './std140';\n\ntype WgslArray<TElement extends AnyWgslData> = WgslData<TB.Unwrap<TElement>[]>;\n\nexport const arrayOf = <TElement extends AnyWgslData>(\n elementType: TElement,\n size: number,\n): WgslArray<TElement> =>\n new SimpleWgslData({\n schema: TB.arrayOf(elementType, size),\n byteAlignment: elementType.byteAlignment,\n code: code`array<${elementType}, ${size}>`,\n });\n","import type { AnyWgslData, WgslPointer } from '../types';\n\nexport function ptr<TDataType extends AnyWgslData>(\n pointsTo: TDataType,\n): WgslPointer<'function', TDataType> {\n return {\n scope: 'function',\n pointsTo,\n };\n}\n","import {\n type IMeasurer,\n type ISerialInput,\n type ISerialOutput,\n type MaxValue,\n Measurer,\n type ParseUnwrapped,\n Schema,\n type Unwrap,\n} from 'typed-binary';\nimport { RecursiveDataTypeError } from '../errors';\nimport type { ResolutionCtx, WgslData } from '../types';\nimport type { I32, U32 } from './numeric';\n\nexport function atomic<TSchema extends U32 | I32>(\n data: TSchema,\n): Atomic<TSchema> {\n return new AtomicImpl(data);\n}\n\nexport interface Atomic<TSchema extends U32 | I32>\n extends WgslData<Unwrap<TSchema>> {}\n\nclass AtomicImpl<TSchema extends U32 | I32>\n extends Schema<Unwrap<TSchema>>\n implements Atomic<TSchema>\n{\n public readonly size: number;\n public readonly byteAlignment: number;\n\n constructor(private readonly innerData: TSchema) {\n super();\n this.size = this.innerData.size;\n this.byteAlignment = this.innerData.byteAlignment;\n }\n\n resolveReferences(): void {\n throw new RecursiveDataTypeError();\n }\n\n write(output: ISerialOutput, value: ParseUnwrapped<TSchema>): void {\n this.innerData.write(output, value);\n }\n\n read(input: ISerialInput): ParseUnwrapped<TSchema> {\n return this.innerData.read(input) as ParseUnwrapped<TSchema>;\n }\n\n measure(\n value: ParseUnwrapped<TSchema> | MaxValue,\n measurer: IMeasurer = new Measurer(),\n ): IMeasurer {\n return this.innerData.measure(value, measurer);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return `atomic<${ctx.resolve(this.innerData)}>`;\n }\n}\n"]}