typegpu 0.0.0-alpha.4 → 0.0.0-alpha.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,207 @@
1
+ import { ISchema, Parsed } from 'typed-binary';
2
+
3
+ interface Swizzle2<T2> {
4
+ readonly xx: T2;
5
+ readonly xy: T2;
6
+ readonly yx: T2;
7
+ readonly yy: T2;
8
+ }
9
+ interface Swizzle3<T2, T3> extends Swizzle2<T2> {
10
+ }
11
+ interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3> {
12
+ }
13
+ interface vec2 {
14
+ x: number;
15
+ y: number;
16
+ length: 2;
17
+ at(idx: 0 | 1): number;
18
+ }
19
+ interface vec3 {
20
+ x: number;
21
+ y: number;
22
+ z: number;
23
+ length: 3;
24
+ at(idx: 0 | 1 | 2): number;
25
+ }
26
+ interface vec4 {
27
+ x: number;
28
+ y: number;
29
+ z: number;
30
+ w: number;
31
+ length: 4;
32
+ at(idx: 0 | 1 | 2 | 3): number;
33
+ }
34
+ type VecKind = 'vec2f' | 'vec2i' | 'vec2u' | 'vec3f' | 'vec3i' | 'vec3u' | 'vec4f' | 'vec4i' | 'vec4u';
35
+ interface vecBase {
36
+ kind: VecKind;
37
+ length: number;
38
+ at(idx: number): number;
39
+ }
40
+ type Vec2f = TgpuData<vec2f> & ((x: number, y: number) => vec2f) & ((xy: number) => vec2f) & (() => vec2f);
41
+ interface vec2f extends vec2, Swizzle2<vec2f> {
42
+ /** use to distinguish between vectors of the same size on the type level */
43
+ kind: 'vec2f';
44
+ }
45
+ declare const vec2f: Vec2f;
46
+ type Vec2i = TgpuData<vec2i> & ((x: number, y: number) => vec2i) & ((xy: number) => vec2i) & (() => vec2i);
47
+ interface vec2i extends vec2, Swizzle2<vec2i> {
48
+ /** use to distinguish between vectors of the same size on the type level */
49
+ kind: 'vec2i';
50
+ }
51
+ declare const vec2i: Vec2i;
52
+ type Vec2u = TgpuData<vec2u> & ((x: number, y: number) => vec2u) & ((xy: number) => vec2u) & (() => vec2u);
53
+ interface vec2u extends vec2, Swizzle2<vec2u> {
54
+ /** use to distinguish between vectors of the same size on the type level */
55
+ kind: 'vec2u';
56
+ }
57
+ declare const vec2u: Vec2u;
58
+ type Vec3f = TgpuData<vec3f> & ((x: number, y: number, z: number) => vec3f) & ((xyz: number) => vec3f) & (() => vec3f);
59
+ interface vec3f extends vec3, Swizzle3<vec2f, vec3f> {
60
+ /** use to distinguish between vectors of the same size on the type level */
61
+ kind: 'vec3f';
62
+ }
63
+ declare const vec3f: Vec3f;
64
+ type Vec3i = TgpuData<vec3i> & ((x: number, y: number, z: number) => vec3i) & ((xyz: number) => vec3i) & (() => vec3i);
65
+ interface vec3i extends vec3, Swizzle3<vec2i, vec3i> {
66
+ /** use to distinguish between vectors of the same size on the type level */
67
+ kind: 'vec3i';
68
+ }
69
+ declare const vec3i: Vec3i;
70
+ type Vec3u = TgpuData<vec3u> & ((x: number, y: number, z: number) => vec3u) & ((xyz: number) => vec3u) & (() => vec3u);
71
+ interface vec3u extends vec3, Swizzle3<vec2u, vec3u> {
72
+ /** use to distinguish between vectors of the same size on the type level */
73
+ kind: 'vec3u';
74
+ }
75
+ declare const vec3u: Vec3u;
76
+ type Vec4f = TgpuData<vec4f> & ((x: number, y: number, z: number, w: number) => vec4f) & ((xyzw: number) => vec4f) & (() => vec4f);
77
+ interface vec4f extends vec4, Swizzle4<vec2f, vec3f, vec4f> {
78
+ /** use to distinguish between vectors of the same size on the type level */
79
+ kind: 'vec4f';
80
+ }
81
+ declare const vec4f: Vec4f;
82
+ type Vec4i = TgpuData<vec4i> & ((x: number, y: number, z: number, w: number) => vec4i) & ((xyzw: number) => vec4i) & (() => vec4i);
83
+ interface vec4i extends vec4, Swizzle4<vec2i, vec3i, vec4i> {
84
+ /** use to distinguish between vectors of the same size on the type level */
85
+ kind: 'vec4i';
86
+ }
87
+ declare const vec4i: Vec4i;
88
+ type Vec4u = TgpuData<vec4u> & ((x: number, y: number, z: number, w: number) => vec4u) & ((xyzw: number) => vec4u) & (() => vec4u);
89
+ interface vec4u extends vec4, Swizzle4<vec2u, vec3u, vec4u> {
90
+ /** use to distinguish between vectors of the same size on the type level */
91
+ kind: 'vec4u';
92
+ }
93
+ declare const vec4u: Vec4u;
94
+
95
+ /**
96
+ * Helpful when creating new Resolvable types. For internal use.
97
+ */
98
+ declare class TgpuIdentifier implements TgpuResolvable, TgpuNamable {
99
+ label?: string | undefined;
100
+ $name(label: string | undefined): this;
101
+ resolve(ctx: ResolutionCtx): string;
102
+ toString(): string;
103
+ }
104
+
105
+ interface Builtin {
106
+ symbol: symbol;
107
+ name: string;
108
+ stage: 'vertex' | 'fragment' | 'compute';
109
+ direction: 'input' | 'output';
110
+ identifier: TgpuIdentifier;
111
+ }
112
+
113
+ type Getter = <T>(plum: TgpuPlum<T>) => T;
114
+ interface TgpuPlum<TValue = unknown> extends TgpuNamable {
115
+ readonly __brand: 'TgpuPlum';
116
+ /**
117
+ * Computes the value of this plum. Circumvents the store
118
+ * memoization, so use with care.
119
+ */
120
+ compute(get: Getter): TValue;
121
+ }
122
+
123
+ type Wgsl = string | number | TgpuResolvable | symbol | boolean;
124
+ /**
125
+ * Passed into each resolvable item. All sibling items share a resolution ctx,
126
+ * and a new resolution ctx is made when going down each level in the tree.
127
+ */
128
+ interface ResolutionCtx {
129
+ /**
130
+ * Slots that were used by items resolved by this context.
131
+ */
132
+ readonly usedSlots: Iterable<TgpuSlot<unknown>>;
133
+ addDeclaration(item: TgpuResolvable): void;
134
+ addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;
135
+ addRenderResource(resource: TgpuRenderResource, identifier: TgpuIdentifier): void;
136
+ addBuiltin(builtin: Builtin): void;
137
+ nameFor(token: TgpuResolvable): string;
138
+ /**
139
+ * Unwraps all layers of slot indirection and returns the concrete value if available.
140
+ * @throws {MissingSlotValueError}
141
+ */
142
+ unwrap<T>(eventual: Eventual<T>): T;
143
+ resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
144
+ }
145
+ interface TgpuResolvable {
146
+ readonly label?: string | undefined;
147
+ resolve(ctx: ResolutionCtx): string;
148
+ }
149
+ /**
150
+ * Can be assigned a name. Not to be confused with
151
+ * being able to HAVE a name.
152
+ */
153
+ interface TgpuNamable {
154
+ $name(label?: string | undefined): this;
155
+ }
156
+ interface TgpuSlot<T> extends TgpuNamable {
157
+ readonly __brand: 'TgpuSlot';
158
+ readonly defaultValue: T | undefined;
159
+ readonly label?: string | undefined;
160
+ /**
161
+ * Used to determine if code generated using either value `a` or `b` in place
162
+ * of the slot will be equivalent. Defaults to `Object.is`.
163
+ */
164
+ areEqual(a: T, b: T): boolean;
165
+ }
166
+ /**
167
+ * Represents a value that is available at resolution time.
168
+ */
169
+ type Eventual<T> = T | TgpuSlot<T>;
170
+ type SlotValuePair<T> = [TgpuSlot<T>, T];
171
+ interface TgpuAllocatable<TData extends AnyTgpuData = AnyTgpuData> {
172
+ /**
173
+ * The data type this allocatable was constructed with.
174
+ * It informs the size and format of data in both JS and
175
+ * binary.
176
+ */
177
+ readonly dataType: TData;
178
+ vertexLayout: Omit<GPUVertexBufferLayout, 'attributes'> | null;
179
+ readonly initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined;
180
+ readonly flags: GPUBufferUsageFlags;
181
+ }
182
+ interface TgpuBindable<TData extends AnyTgpuData = AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuResolvable {
183
+ readonly allocatable: TgpuAllocatable<TData>;
184
+ readonly usage: TUsage;
185
+ }
186
+ type TgpuSamplerType = 'sampler' | 'sampler_comparison';
187
+ type TgpuTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
188
+ type TgpuDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
189
+ type TgpuStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
190
+ type TgpuExternalTextureType = 'texture_external';
191
+ type TgpuRenderResourceType = TgpuSamplerType | TgpuTypedTextureType | TgpuDepthTextureType | TgpuStorageTextureType | TgpuExternalTextureType;
192
+ interface TgpuRenderResource extends TgpuResolvable {
193
+ readonly type: TgpuRenderResourceType;
194
+ }
195
+ type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
196
+ interface TgpuData<TInner> extends ISchema<TInner>, TgpuResolvable {
197
+ readonly byteAlignment: number;
198
+ readonly size: number;
199
+ }
200
+ type AnyTgpuData = TgpuData<unknown>;
201
+ type TexelFormat = Vec4u | Vec4i | Vec4f;
202
+ interface TgpuPointer<TScope extends 'function', TInner extends AnyTgpuData> {
203
+ readonly scope: TScope;
204
+ readonly pointsTo: TInner;
205
+ }
206
+
207
+ export { type AnyTgpuData as A, type BufferUsage as B, type Eventual as E, type ResolutionCtx as R, type TgpuBindable as T, type VecKind as V, type Wgsl as W, type TgpuAllocatable as a, type TgpuNamable as b, type TgpuPlum as c, vec3f as d, vec3i as e, vec3u as f, type TgpuData as g, type TexelFormat as h, type TgpuPointer as i, vec2f as j, vec2i as k, vec2u as l, vec4f as m, vec4i as n, vec4u as o, type Vec2f as p, type Vec2i as q, type Vec2u as r, type Vec3f as s, type Vec3i as t, type Vec3u as u, type vecBase as v, type Vec4f as w, type Vec4i as x, type Vec4u as y };
@@ -0,0 +1,207 @@
1
+ import { ISchema, Parsed } from 'typed-binary';
2
+
3
+ interface Swizzle2<T2> {
4
+ readonly xx: T2;
5
+ readonly xy: T2;
6
+ readonly yx: T2;
7
+ readonly yy: T2;
8
+ }
9
+ interface Swizzle3<T2, T3> extends Swizzle2<T2> {
10
+ }
11
+ interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3> {
12
+ }
13
+ interface vec2 {
14
+ x: number;
15
+ y: number;
16
+ length: 2;
17
+ at(idx: 0 | 1): number;
18
+ }
19
+ interface vec3 {
20
+ x: number;
21
+ y: number;
22
+ z: number;
23
+ length: 3;
24
+ at(idx: 0 | 1 | 2): number;
25
+ }
26
+ interface vec4 {
27
+ x: number;
28
+ y: number;
29
+ z: number;
30
+ w: number;
31
+ length: 4;
32
+ at(idx: 0 | 1 | 2 | 3): number;
33
+ }
34
+ type VecKind = 'vec2f' | 'vec2i' | 'vec2u' | 'vec3f' | 'vec3i' | 'vec3u' | 'vec4f' | 'vec4i' | 'vec4u';
35
+ interface vecBase {
36
+ kind: VecKind;
37
+ length: number;
38
+ at(idx: number): number;
39
+ }
40
+ type Vec2f = TgpuData<vec2f> & ((x: number, y: number) => vec2f) & ((xy: number) => vec2f) & (() => vec2f);
41
+ interface vec2f extends vec2, Swizzle2<vec2f> {
42
+ /** use to distinguish between vectors of the same size on the type level */
43
+ kind: 'vec2f';
44
+ }
45
+ declare const vec2f: Vec2f;
46
+ type Vec2i = TgpuData<vec2i> & ((x: number, y: number) => vec2i) & ((xy: number) => vec2i) & (() => vec2i);
47
+ interface vec2i extends vec2, Swizzle2<vec2i> {
48
+ /** use to distinguish between vectors of the same size on the type level */
49
+ kind: 'vec2i';
50
+ }
51
+ declare const vec2i: Vec2i;
52
+ type Vec2u = TgpuData<vec2u> & ((x: number, y: number) => vec2u) & ((xy: number) => vec2u) & (() => vec2u);
53
+ interface vec2u extends vec2, Swizzle2<vec2u> {
54
+ /** use to distinguish between vectors of the same size on the type level */
55
+ kind: 'vec2u';
56
+ }
57
+ declare const vec2u: Vec2u;
58
+ type Vec3f = TgpuData<vec3f> & ((x: number, y: number, z: number) => vec3f) & ((xyz: number) => vec3f) & (() => vec3f);
59
+ interface vec3f extends vec3, Swizzle3<vec2f, vec3f> {
60
+ /** use to distinguish between vectors of the same size on the type level */
61
+ kind: 'vec3f';
62
+ }
63
+ declare const vec3f: Vec3f;
64
+ type Vec3i = TgpuData<vec3i> & ((x: number, y: number, z: number) => vec3i) & ((xyz: number) => vec3i) & (() => vec3i);
65
+ interface vec3i extends vec3, Swizzle3<vec2i, vec3i> {
66
+ /** use to distinguish between vectors of the same size on the type level */
67
+ kind: 'vec3i';
68
+ }
69
+ declare const vec3i: Vec3i;
70
+ type Vec3u = TgpuData<vec3u> & ((x: number, y: number, z: number) => vec3u) & ((xyz: number) => vec3u) & (() => vec3u);
71
+ interface vec3u extends vec3, Swizzle3<vec2u, vec3u> {
72
+ /** use to distinguish between vectors of the same size on the type level */
73
+ kind: 'vec3u';
74
+ }
75
+ declare const vec3u: Vec3u;
76
+ type Vec4f = TgpuData<vec4f> & ((x: number, y: number, z: number, w: number) => vec4f) & ((xyzw: number) => vec4f) & (() => vec4f);
77
+ interface vec4f extends vec4, Swizzle4<vec2f, vec3f, vec4f> {
78
+ /** use to distinguish between vectors of the same size on the type level */
79
+ kind: 'vec4f';
80
+ }
81
+ declare const vec4f: Vec4f;
82
+ type Vec4i = TgpuData<vec4i> & ((x: number, y: number, z: number, w: number) => vec4i) & ((xyzw: number) => vec4i) & (() => vec4i);
83
+ interface vec4i extends vec4, Swizzle4<vec2i, vec3i, vec4i> {
84
+ /** use to distinguish between vectors of the same size on the type level */
85
+ kind: 'vec4i';
86
+ }
87
+ declare const vec4i: Vec4i;
88
+ type Vec4u = TgpuData<vec4u> & ((x: number, y: number, z: number, w: number) => vec4u) & ((xyzw: number) => vec4u) & (() => vec4u);
89
+ interface vec4u extends vec4, Swizzle4<vec2u, vec3u, vec4u> {
90
+ /** use to distinguish between vectors of the same size on the type level */
91
+ kind: 'vec4u';
92
+ }
93
+ declare const vec4u: Vec4u;
94
+
95
+ /**
96
+ * Helpful when creating new Resolvable types. For internal use.
97
+ */
98
+ declare class TgpuIdentifier implements TgpuResolvable, TgpuNamable {
99
+ label?: string | undefined;
100
+ $name(label: string | undefined): this;
101
+ resolve(ctx: ResolutionCtx): string;
102
+ toString(): string;
103
+ }
104
+
105
+ interface Builtin {
106
+ symbol: symbol;
107
+ name: string;
108
+ stage: 'vertex' | 'fragment' | 'compute';
109
+ direction: 'input' | 'output';
110
+ identifier: TgpuIdentifier;
111
+ }
112
+
113
+ type Getter = <T>(plum: TgpuPlum<T>) => T;
114
+ interface TgpuPlum<TValue = unknown> extends TgpuNamable {
115
+ readonly __brand: 'TgpuPlum';
116
+ /**
117
+ * Computes the value of this plum. Circumvents the store
118
+ * memoization, so use with care.
119
+ */
120
+ compute(get: Getter): TValue;
121
+ }
122
+
123
+ type Wgsl = string | number | TgpuResolvable | symbol | boolean;
124
+ /**
125
+ * Passed into each resolvable item. All sibling items share a resolution ctx,
126
+ * and a new resolution ctx is made when going down each level in the tree.
127
+ */
128
+ interface ResolutionCtx {
129
+ /**
130
+ * Slots that were used by items resolved by this context.
131
+ */
132
+ readonly usedSlots: Iterable<TgpuSlot<unknown>>;
133
+ addDeclaration(item: TgpuResolvable): void;
134
+ addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;
135
+ addRenderResource(resource: TgpuRenderResource, identifier: TgpuIdentifier): void;
136
+ addBuiltin(builtin: Builtin): void;
137
+ nameFor(token: TgpuResolvable): string;
138
+ /**
139
+ * Unwraps all layers of slot indirection and returns the concrete value if available.
140
+ * @throws {MissingSlotValueError}
141
+ */
142
+ unwrap<T>(eventual: Eventual<T>): T;
143
+ resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
144
+ }
145
+ interface TgpuResolvable {
146
+ readonly label?: string | undefined;
147
+ resolve(ctx: ResolutionCtx): string;
148
+ }
149
+ /**
150
+ * Can be assigned a name. Not to be confused with
151
+ * being able to HAVE a name.
152
+ */
153
+ interface TgpuNamable {
154
+ $name(label?: string | undefined): this;
155
+ }
156
+ interface TgpuSlot<T> extends TgpuNamable {
157
+ readonly __brand: 'TgpuSlot';
158
+ readonly defaultValue: T | undefined;
159
+ readonly label?: string | undefined;
160
+ /**
161
+ * Used to determine if code generated using either value `a` or `b` in place
162
+ * of the slot will be equivalent. Defaults to `Object.is`.
163
+ */
164
+ areEqual(a: T, b: T): boolean;
165
+ }
166
+ /**
167
+ * Represents a value that is available at resolution time.
168
+ */
169
+ type Eventual<T> = T | TgpuSlot<T>;
170
+ type SlotValuePair<T> = [TgpuSlot<T>, T];
171
+ interface TgpuAllocatable<TData extends AnyTgpuData = AnyTgpuData> {
172
+ /**
173
+ * The data type this allocatable was constructed with.
174
+ * It informs the size and format of data in both JS and
175
+ * binary.
176
+ */
177
+ readonly dataType: TData;
178
+ vertexLayout: Omit<GPUVertexBufferLayout, 'attributes'> | null;
179
+ readonly initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined;
180
+ readonly flags: GPUBufferUsageFlags;
181
+ }
182
+ interface TgpuBindable<TData extends AnyTgpuData = AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuResolvable {
183
+ readonly allocatable: TgpuAllocatable<TData>;
184
+ readonly usage: TUsage;
185
+ }
186
+ type TgpuSamplerType = 'sampler' | 'sampler_comparison';
187
+ type TgpuTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
188
+ type TgpuDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
189
+ type TgpuStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
190
+ type TgpuExternalTextureType = 'texture_external';
191
+ type TgpuRenderResourceType = TgpuSamplerType | TgpuTypedTextureType | TgpuDepthTextureType | TgpuStorageTextureType | TgpuExternalTextureType;
192
+ interface TgpuRenderResource extends TgpuResolvable {
193
+ readonly type: TgpuRenderResourceType;
194
+ }
195
+ type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
196
+ interface TgpuData<TInner> extends ISchema<TInner>, TgpuResolvable {
197
+ readonly byteAlignment: number;
198
+ readonly size: number;
199
+ }
200
+ type AnyTgpuData = TgpuData<unknown>;
201
+ type TexelFormat = Vec4u | Vec4i | Vec4f;
202
+ interface TgpuPointer<TScope extends 'function', TInner extends AnyTgpuData> {
203
+ readonly scope: TScope;
204
+ readonly pointsTo: TInner;
205
+ }
206
+
207
+ export { type AnyTgpuData as A, type BufferUsage as B, type Eventual as E, type ResolutionCtx as R, type TgpuBindable as T, type VecKind as V, type Wgsl as W, type TgpuAllocatable as a, type TgpuNamable as b, type TgpuPlum as c, vec3f as d, vec3i as e, vec3u as f, type TgpuData as g, type TexelFormat as h, type TgpuPointer as i, vec2f as j, vec2i as k, vec2u as l, vec4f as m, vec4i as n, vec4u as o, type Vec2f as p, type Vec2i as q, type Vec2u as r, type Vec3f as s, type Vec3i as t, type Vec3u as u, type vecBase as v, type Vec4f as w, type Vec4i as x, type Vec4u as y };
@@ -1,12 +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 E=Object.defineProperty,M=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var x=(t,n,e)=>n in t?E(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,ee= exports.a =(t,n)=>{for(var e in n||(n={}))D.call(n,e)&&x(t,e,n[e]);if(f)for(var e of f(n))B.call(n,e)&&x(t,e,n[e]);return t},te= exports.b =(t,n)=>M(t,k(n));var re=(t,n)=>{var e={};for(var r in t)D.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&f)for(var r of f(t))n.indexOf(r)<0&&B.call(t,r)&&(e[r]=t[r]);return e};var s=(t,n,e)=>(x(t,typeof n!="symbol"?n+"":n,e),e);var _typedbinary = require('typed-binary'); var a = _interopRequireWildcard(_typedbinary); var P = _interopRequireWildcard(_typedbinary); var $ = _interopRequireWildcard(_typedbinary);var R=class t extends Error{constructor(e,r){let i=r.map(p=>`- ${p}`);i.length>20&&(i=[...i.slice(0,11),"...",...i.slice(-10)]);super(`Resolution of the following tree failed:
2
- ${i.join(`
3
- `)}`);this.cause=e;this.trace=r;Object.setPrototypeOf(this,t.prototype)}appendToTrace(e){let r=[e,...this.trace];return new t(this.cause,r)}},A= exports.f =class t extends Error{constructor(e){super(`Missing value for '${e}'`);this.slot=e;Object.setPrototypeOf(this,t.prototype)}},d= exports.g =class t extends Error{constructor(){super("Recursive types are not supported in WGSL"),Object.setPrototypeOf(this,t.prototype)}};function C(t,n){let e="size"in t?t.size:t.currentByteOffset,r=n-1,i=e&r;"skipBytes"in t?t.skipBytes(n-i&r):t.add(n-i&r)}var m=C;var o=class extends _typedbinary.Schema{constructor({schema:e,byteAlignment:r,code:i}){super();s(this,"size");s(this,"byteAlignment");s(this,"expressionCode");s(this,"_innerSchema");this._innerSchema=e,this.byteAlignment=r,this.expressionCode=i,this.size=this.measure(_typedbinary.MaxValue).size}resolveReferences(){throw new d}write(e,r){m(e,this.byteAlignment),this._innerSchema.write(e,r)}read(e){return m(e,this.byteAlignment),this._innerSchema.read(e)}measure(e,r=new _typedbinary.Measurer){return m(r,this.byteAlignment),this._innerSchema.measure(e,r),r}getUnderlyingTypeString(){if(typeof this.expressionCode=="string")return this.expressionCode;if("elementSchema"in this._innerSchema)return this._innerSchema.elementSchema.getUnderlyingTypeString();throw new Error("Unexpected type used as vertex buffer element")}getUnderlyingType(){return"elementSchema"in this._innerSchema?this._innerSchema.elementSchema.getUnderlyingType():this}resolve(e){return e.resolve(this.expressionCode)}};var ce=new o({schema:a.bool,byteAlignment:4,code:"bool"}),c= exports.s =new o({schema:a.u32,byteAlignment:4,code:"u32"}),de= exports.t =new o({schema:a.i32,byteAlignment:4,code:"i32"}),T= exports.u =new o({schema:a.f32,byteAlignment:4,code:"f32"}),ye= exports.v =new o({schema:a.tupleOf([a.u32,a.u32]),byteAlignment:8,code:"vec2u"}),ge= exports.w =new o({schema:a.tupleOf([a.i32,a.i32]),byteAlignment:8,code:"vec2i"}),fe= exports.x =new o({schema:a.tupleOf([a.f32,a.f32]),byteAlignment:8,code:"vec2f"}),g= exports.y =new o({schema:a.tupleOf([a.u32,a.u32,a.u32]),byteAlignment:16,code:"vec3u"}),xe= exports.z =new o({schema:a.tupleOf([a.i32,a.i32,a.i32]),byteAlignment:16,code:"vec3i"}),Te= exports.A =new o({schema:a.tupleOf([a.f32,a.f32,a.f32]),byteAlignment:16,code:"vec3f"}),be= exports.B =new o({schema:a.tupleOf([a.u32,a.u32,a.u32,a.u32]),byteAlignment:16,code:"vec4u"}),he= exports.C =new o({schema:a.tupleOf([a.i32,a.i32,a.i32,a.i32]),byteAlignment:16,code:"vec4i"}),b= exports.D =new o({schema:a.tupleOf([a.f32,a.f32,a.f32,a.f32]),byteAlignment:16,code:"vec4f"}),We= exports.E =new o({schema:a.arrayOf(a.f32,16),byteAlignment:16,code:"mat4x4f"});function h(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"resolve"in t}function Se(t){return typeof t=="number"||typeof t=="boolean"||typeof t=="string"||h(t)}function ve(t){return t.__brand==="WgslSlot"}function we(t){return t==="sampler"||t==="sampler_comparison"}function Ie(t){return["texture_1d","texture_2d","texture_2d_array","texture_3d","texture_cube","texture_cube_array","texture_multisampled_2d"].includes(t)}function De(t){return["texture_depth_2d","texture_depth_2d_array","texture_depth_cube","texture_depth_cube_array","texture_depth_multisampled_2d"].includes(t)}function Be(t){return["texture_storage_1d","texture_storage_2d","texture_storage_2d_array","texture_storage_3d"].includes(t)}function Re(t){return t==="texture_external"}function Ae(t){return"pointsTo"in t}var l=class{constructor(){s(this,"label")}$name(n){return this.label=n,this}resolve(n){return n.nameFor(this)}toString(){var n;return`id:${(n=this.label)!=null?n:"<unnamed>"}`}};var u={vertexIndex:Symbol("builtin_vertexIndex"),instanceIndex:Symbol("builtin_instanceIndex"),position:Symbol("builtin_position"),clipDistances:Symbol("builtin_clipDistances"),frontFacing:Symbol("builtin_frontFacing"),fragDepth:Symbol("builtin_fragDepth"),sampleIndex:Symbol("builtin_sampleIndex"),sampleMask:Symbol("builtin_sampleMask"),fragment:Symbol("builtin_fragment"),localInvocationId:Symbol("builtin_localInvocationId"),localInvocationIndex:Symbol("builtin_localInvocationIndex"),globalInvocationId:Symbol("builtin_globalInvocationId"),workgroupId:Symbol("builtin_workgroupId"),numWorkgroups:Symbol("builtin_numWorkgroups")},U={[u.vertexIndex]:{name:"vertex_index",stage:"vertex",direction:"input",type:c,identifier:new l().$name("vertex_index")},[u.instanceIndex]:{name:"instance_index",stage:"vertex",direction:"input",type:c,identifier:new l().$name("instance_index")},[u.position]:{name:"position",stage:"vertex",direction:"output",type:b,identifier:new l().$name("position")},[u.clipDistances]:{name:"clip_distances",stage:"vertex",direction:"output",type:new o({schema:P.arrayOf(c,8),byteAlignment:16,code:"array<u32, 8>"}),identifier:new l().$name("clip_distances")},[u.frontFacing]:{name:"front_facing",stage:"fragment",direction:"input",type:T,identifier:new l().$name("front_facing")},[u.fragDepth]:{name:"frag_depth",stage:"fragment",direction:"output",type:T,identifier:new l().$name("frag_depth")},[u.sampleIndex]:{name:"sample_index",stage:"fragment",direction:"input",type:c,identifier:new l().$name("sample_index")},[u.sampleMask]:{name:"sample_mask",stage:"fragment",direction:"input",type:c,identifier:new l().$name("sample_mask")},[u.fragment]:{name:"fragment",stage:"fragment",direction:"input",type:b,identifier:new l().$name("fragment")},[u.localInvocationId]:{name:"local_invocation_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("local_invocation_id")},[u.localInvocationIndex]:{name:"local_invocation_index",stage:"compute",direction:"input",type:c,identifier:new l().$name("local_invocation_index")},[u.globalInvocationId]:{name:"global_invocation_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("global_invocation_id")},[u.workgroupId]:{name:"workgroup_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("workgroup_id")},[u.numWorkgroups]:{name:"num_workgroups",stage:"compute",direction:"input",type:g,identifier:new l().$name("num_workgroups")}};function V(t){let n=U[t];if(!n)throw new Error("Symbol is not a member of builtin");return n}function Ee(t){return Object.getOwnPropertySymbols(t).map(e=>{let r=U[e];if(!r)throw new Error("Symbol is not a member of builtin");let i=t[e];if(!i)throw new Error("Name is not provided");return{name:i,builtin:r}})}function y(t,...n){let e=t.flatMap((r,i)=>{let p=n[i];return p===void 0?[r]:Array.isArray(p)?[r,...p]:[r,p]});return new W(e)}var W=class{constructor(n){this.segments=n;s(this,"_label")}get label(){return this._label}$name(n){return this._label=n,this}resolve(n){let e="";for(let r of this.segments)if(typeof r=="function"){let i=r(p=>n.unwrap(p));e+=n.resolve(i)}else if(h(r))e+=n.resolve(r);else if(typeof r=="symbol"){let i=V(r);n.addBuiltin(i),e+=n.resolve(i.identifier)}else e+=String(r);return e}with(n,e){return new _(this,[n,e])}toString(){var n;return`code:${(n=this._label)!=null?n:"<unnamed>"}`}},_=class t{constructor(n,e){this._innerFn=n;this._slotValuePair=e}get label(){return this._innerFn.label}with(n,e){return new t(this,[n,e])}resolve(n){return n.resolve(this._innerFn,[this._slotValuePair])}toString(){var r,i;let[n,e]=this._slotValuePair;return`code:${(r=this.label)!=null?r:"<unnamed>"}[${(i=n.label)!=null?i:"<unnamed>"}=${e}]`}};var S=class extends _typedbinary.Schema{constructor(e,r){super();this._elementType=e;this.capacity=r;s(this,"_label");s(this,"byteAlignment");s(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 d}write(e,r){if(r.length>this.capacity)throw new (0, _typedbinary.ValidationError)(`Tried to write too many values, ${r.length} > ${this.capacity}`);m(e,this.byteAlignment),c.write(e,r.length),m(e,this._elementType.byteAlignment);let i=e.currentByteOffset;for(let p of r)this._elementType.write(e,p);e.seekTo(i+this.capacity*this._elementType.size)}read(e){let r=[];m(e,this.byteAlignment);let i=c.read(e);m(e,this._elementType.byteAlignment);let p=e.currentByteOffset;for(let I=0;I<i;++I)r.push(this._elementType.read(e));return e.seekTo(p+this.capacity*this._elementType.size),r}measure(e,r=new _typedbinary.Measurer){return m(r,this.byteAlignment),c.measure(_typedbinary.MaxValue,r),m(r,this._elementType.byteAlignment),r.add(this._elementType.size*this.capacity),r}resolve(e){let r=new l().$name(this._label);return e.addDeclaration(y`
4
- struct ${r} {
5
- count: u32,
6
- values: array<${this._elementType}, ${this.capacity}>,
7
- }`),e.resolve(r)}},Je= exports.G =(t,n)=>new S(t,n);var rt=t=>new v(t),v=class extends _typedbinary.Schema{constructor(e){super();this._properties=e;s(this,"_label");s(this,"_innerSchema");s(this,"byteAlignment");s(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 d}write(e,r){this._innerSchema.write(e,r)}read(e){return this._innerSchema.read(e)}measure(e,r=new _typedbinary.Measurer){return m(r,this.byteAlignment),this._innerSchema.measure(e,r),r}resolve(e){let r=new l().$name(this._label);return e.addDeclaration(y`
8
- struct ${r} {
9
- ${Object.entries(this._properties).map(([i,p])=>y`${i}: ${p},\n`)}
10
- }
11
- `),e.resolve(r)}};var ot=(t,n)=>new o({schema:$.arrayOf(t,n),byteAlignment:t.byteAlignment,code:y`array<${t}, ${n}>`});function Q(t){return{scope:"function",pointsTo:t}}function Z(t){return new w(t)}var w=class extends _typedbinary.Schema{constructor(e){super();this.innerData=e;s(this,"size");s(this,"byteAlignment");this.size=this.innerData.size,this.byteAlignment=this.innerData.byteAlignment}resolveReferences(){throw new d}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.a = ee; exports.b = te; exports.c = re; exports.d = s; exports.e = R; exports.f = A; exports.g = d; exports.h = h; exports.i = Se; exports.j = ve; exports.k = we; exports.l = Ie; exports.m = De; exports.n = Be; exports.o = Re; exports.p = Ae; exports.q = o; exports.r = ce; exports.s = c; exports.t = de; exports.u = T; exports.v = ye; exports.w = ge; exports.x = fe; exports.y = g; exports.z = xe; exports.A = Te; exports.B = be; exports.C = he; exports.D = b; exports.E = We; exports.F = l; exports.G = Je; exports.H = rt; exports.I = ot; exports.J = Q; exports.K = Z; exports.L = u; exports.M = V; exports.N = Ee; exports.O = y;
12
- //# sourceMappingURL=chunk-7HTWRNOH.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/data/std140.ts","../src/errors.ts","../src/data/alignIO.ts","../src/data/numeric.ts","../src/data/dynamicArray.ts","../src/types.ts","../src/wgslBuiltin.ts","../src/wgslIdentifier.ts","../src/wgslCode.ts","../src/data/struct.ts","../src/data/array.ts","../src/data/pointer.ts","../src/data/atomic.ts"],"names":["MaxValue","Measurer","Schema","ResolutionError","_ResolutionError","cause","trace","entries","ancestor","newTrace","MissingSlotValueError","_MissingSlotValueError","slot","RecursiveDataTypeError","_RecursiveDataTypeError","alignIO","io","baseAlignment","currentPos","bitMask","offset","alignIO_default","SimpleWgslData","schema","byteAlignment","code","__publicField","output","value","input","measurer","ctx","TB","bool","u32","i32","f32","vec2u","vec2i","vec2f","vec3u","vec3i","vec3f","vec4u","vec4i","vec4f","mat4f","ValidationError","isResolvable","isWgsl","isSlot","isSamplerType","type","isTypedTextureType","isDepthTextureType","isStorageTextureType","isExternalTextureType","isPointer","WgslIdentifier","label","_a","builtin","builtinSymbolToObj","getBuiltinInfo","s","getUsedBuiltinsNamed","o","name","strings","params","segments","string","idx","param","WgslCodeImpl","result","eventual","BoundWgslCodeImpl","_BoundWgslCodeImpl","_innerFn","_slotValuePair","_b","DynamicArrayDataType","_elementType","capacity","values","startOffset","array","len","i","_values","identifier","dynamicArrayOf","elementType","object","struct","properties","WgslStructImpl","_properties","prop","a","b","key","field","arrayOf","size","ptr","pointsTo","atomic","data","AtomicImpl","innerData"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,eAAAA,EAH7BrF,EAAA,KAAgB,QAChBA,EAAA,KAAgB,iBAId,KAAK,KAAO,KAAK,UAAU,KAC3B,KAAK,cAAgB,KAAK,UAAU,aACtC,CAEA,mBAA0B,CACxB,MAAM,IAAIb,CACZ,CAEA,MAAMc,EAAuBC,EAAsC,CACjE,KAAK,UAAU,MAAMD,EAAQC,CAAK,CACpC,CAEA,KAAKC,EAA8C,CACjD,OAAO,KAAK,UAAU,KAAKA,CAAK,CAClC,CAEA,QACED,EACAE,EAAsB,IAAI7B,EACf,CACX,OAAO,KAAK,UAAU,QAAQ2B,EAAOE,CAAQ,CAC/C,CAEA,QAAQC,EAA4B,CAClC,MAAO,UAAUA,EAAI,QAAQ,KAAK,SAAS,CAAC,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 public readonly expressionCode: Wgsl;\n\n private readonly _innerSchema: TSchema;\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 getUnderlyingTypeString(): string {\n if (typeof this.expressionCode === 'string') {\n return this.expressionCode;\n }\n if ('elementSchema' in this._innerSchema) {\n const underlyingType = this._innerSchema\n .elementSchema as SimpleWgslData<AnySchema>;\n return underlyingType.getUnderlyingTypeString();\n }\n throw new Error('Unexpected type used as vertex buffer element');\n }\n\n getUnderlyingType(): SimpleWgslData<AnySchema> {\n if ('elementSchema' in this._innerSchema) {\n const underlyingType = this._innerSchema\n .elementSchema as SimpleWgslData<AnySchema>;\n return underlyingType.getUnderlyingType();\n }\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this.expressionCode);\n }\n}\n","import type { WgslResolvable, WgslSlot } from './types';\n\n/**\n * An error that happens during resolution of WGSL code.\n * Contains a trace of all ancestor resolvables in\n * which this error originated.\n *\n * @category Errors\n */\nexport class ResolutionError extends Error {\n constructor(\n public readonly cause: unknown,\n public readonly trace: WgslResolvable[],\n ) {\n let entries = trace.map((ancestor) => `- ${ancestor}`);\n\n // Showing only the root and leaf nodes.\n if (entries.length > 20) {\n entries = [...entries.slice(0, 11), '...', ...entries.slice(-10)];\n }\n\n super(`Resolution of the following tree failed: \\n${entries.join('\\n')}`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, ResolutionError.prototype);\n }\n\n appendToTrace(ancestor: WgslResolvable): ResolutionError {\n const newTrace = [ancestor, ...this.trace];\n\n return new ResolutionError(this.cause, newTrace);\n }\n}\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","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 type { ISchema, Parsed } from 'typed-binary';\nimport type { F32, I32, U32, Vec4f, Vec4i, Vec4u } from './data';\nimport type { Builtin } from './wgslBuiltin';\nimport type { WgslIdentifier } from './wgslIdentifier';\nimport type { WgslPlum } from './wgslPlum';\n\nexport type Wgsl = string | number | WgslResolvable | symbol | boolean;\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 addRenderResource(\n resource: WgslRenderResource,\n identifier: WgslIdentifier,\n ): void;\n addBuiltin(builtin: Builtin): 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 === 'boolean' ||\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 vertexLayout: Omit<GPUVertexBufferLayout, 'attributes'> | null;\n readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;\n readonly flags: GPUBufferUsageFlags;\n get label(): string | undefined;\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 WgslSamplerType = 'sampler' | 'sampler_comparison';\nexport type WgslTypedTextureType =\n | 'texture_1d'\n | 'texture_2d'\n | 'texture_2d_array'\n | 'texture_3d'\n | 'texture_cube'\n | 'texture_cube_array'\n | 'texture_multisampled_2d';\nexport type WgslDepthTextureType =\n | 'texture_depth_2d'\n | 'texture_depth_2d_array'\n | 'texture_depth_cube'\n | 'texture_depth_cube_array'\n | 'texture_depth_multisampled_2d';\nexport type WgslStorageTextureType =\n | 'texture_storage_1d'\n | 'texture_storage_2d'\n | 'texture_storage_2d_array'\n | 'texture_storage_3d';\nexport type WgslExternalTextureType = 'texture_external';\n\nexport type WgslRenderResourceType =\n | WgslSamplerType\n | WgslTypedTextureType\n | WgslDepthTextureType\n | WgslStorageTextureType\n | WgslExternalTextureType;\n\nexport interface WgslRenderResource extends WgslResolvable {\n readonly type: WgslRenderResourceType;\n}\n\nexport type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';\nexport type TextureUsage = 'sampled' | 'storage';\nexport type StorageTextureAccess = 'read' | 'write' | 'read_write';\n\nexport type StorageTextureParams = {\n type: WgslStorageTextureType;\n access: StorageTextureAccess;\n descriptor?: GPUTextureViewDescriptor;\n};\nexport type SampledTextureParams = {\n type: WgslTypedTextureType;\n dataType: AnyWgslPrimitive;\n descriptor?: GPUTextureViewDescriptor;\n};\n\nexport function isSamplerType(\n type: WgslRenderResourceType,\n): type is WgslSamplerType {\n return type === 'sampler' || type === 'sampler_comparison';\n}\n\nexport function isTypedTextureType(\n type: WgslRenderResourceType,\n): type is WgslTypedTextureType {\n return [\n 'texture_1d',\n 'texture_2d',\n 'texture_2d_array',\n 'texture_3d',\n 'texture_cube',\n 'texture_cube_array',\n 'texture_multisampled_2d',\n ].includes(type);\n}\n\nexport function isDepthTextureType(\n type: WgslRenderResourceType,\n): type is WgslDepthTextureType {\n return [\n 'texture_depth_2d',\n 'texture_depth_2d_array',\n 'texture_depth_cube',\n 'texture_depth_cube_array',\n 'texture_depth_multisampled_2d',\n ].includes(type);\n}\n\nexport function isStorageTextureType(\n type: WgslRenderResourceType,\n): type is WgslStorageTextureType {\n return [\n 'texture_storage_1d',\n 'texture_storage_2d',\n 'texture_storage_2d_array',\n 'texture_storage_3d',\n ].includes(type);\n}\n\nexport function isExternalTextureType(\n type: WgslRenderResourceType,\n): type is WgslExternalTextureType {\n return type === 'texture_external';\n}\n\nexport interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {\n readonly byteAlignment: number;\n readonly size: number;\n}\n\nexport type AnyWgslData = WgslData<unknown>;\nexport type AnyWgslPrimitive = U32 | I32 | F32;\nexport type AnyWgslTexelFormat = Vec4u | Vec4i | Vec4f;\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 * as TB from 'typed-binary';\nimport type { F32, U32, Vec3u, Vec4f } from './data';\nimport { SimpleWgslData, f32, u32, vec3u, vec4f } from './data';\nimport type { WgslData } from './types';\nimport { WgslIdentifier } from './wgslIdentifier';\n\nexport type BuiltInPossibleTypes =\n | U32\n | F32\n | Vec3u\n | Vec4f\n | WgslData<TB.Unwrap<U32>[]>;\n\nexport const builtin = {\n vertexIndex: Symbol('builtin_vertexIndex'),\n instanceIndex: Symbol('builtin_instanceIndex'),\n position: Symbol('builtin_position'),\n clipDistances: Symbol('builtin_clipDistances'),\n frontFacing: Symbol('builtin_frontFacing'),\n fragDepth: Symbol('builtin_fragDepth'),\n sampleIndex: Symbol('builtin_sampleIndex'),\n sampleMask: Symbol('builtin_sampleMask'),\n fragment: Symbol('builtin_fragment'),\n localInvocationId: Symbol('builtin_localInvocationId'),\n localInvocationIndex: Symbol('builtin_localInvocationIndex'),\n globalInvocationId: Symbol('builtin_globalInvocationId'),\n workgroupId: Symbol('builtin_workgroupId'),\n numWorkgroups: Symbol('builtin_numWorkgroups'),\n} as const;\n\nexport interface Builtin {\n name: string;\n stage: 'vertex' | 'fragment' | 'compute';\n direction: 'input' | 'output';\n type: BuiltInPossibleTypes;\n identifier: WgslIdentifier;\n}\n\nconst builtinSymbolToObj: Record<symbol, Builtin> = {\n [builtin.vertexIndex]: {\n name: 'vertex_index',\n stage: 'vertex',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('vertex_index'),\n },\n [builtin.instanceIndex]: {\n name: 'instance_index',\n stage: 'vertex',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('instance_index'),\n },\n [builtin.position]: {\n name: 'position',\n stage: 'vertex',\n direction: 'output',\n type: vec4f,\n identifier: new WgslIdentifier().$name('position'),\n },\n [builtin.clipDistances]: {\n name: 'clip_distances',\n stage: 'vertex',\n direction: 'output',\n type: new SimpleWgslData({\n schema: TB.arrayOf(u32, 8),\n byteAlignment: 16,\n code: 'array<u32, 8>',\n }),\n identifier: new WgslIdentifier().$name('clip_distances'),\n },\n [builtin.frontFacing]: {\n name: 'front_facing',\n stage: 'fragment',\n direction: 'input',\n type: f32,\n identifier: new WgslIdentifier().$name('front_facing'),\n },\n [builtin.fragDepth]: {\n name: 'frag_depth',\n stage: 'fragment',\n direction: 'output',\n type: f32,\n identifier: new WgslIdentifier().$name('frag_depth'),\n },\n [builtin.sampleIndex]: {\n name: 'sample_index',\n stage: 'fragment',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('sample_index'),\n },\n [builtin.sampleMask]: {\n name: 'sample_mask',\n stage: 'fragment',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('sample_mask'),\n },\n [builtin.fragment]: {\n name: 'fragment',\n stage: 'fragment',\n direction: 'input',\n type: vec4f,\n identifier: new WgslIdentifier().$name('fragment'),\n },\n [builtin.localInvocationId]: {\n name: 'local_invocation_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('local_invocation_id'),\n },\n [builtin.localInvocationIndex]: {\n name: 'local_invocation_index',\n stage: 'compute',\n direction: 'input',\n type: u32,\n identifier: new WgslIdentifier().$name('local_invocation_index'),\n },\n [builtin.globalInvocationId]: {\n name: 'global_invocation_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('global_invocation_id'),\n },\n [builtin.workgroupId]: {\n name: 'workgroup_id',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('workgroup_id'),\n },\n [builtin.numWorkgroups]: {\n name: 'num_workgroups',\n stage: 'compute',\n direction: 'input',\n type: vec3u,\n identifier: new WgslIdentifier().$name('num_workgroups'),\n },\n};\n\nexport function getBuiltinInfo(s: symbol): Builtin {\n const builtin = builtinSymbolToObj[s];\n if (!builtin) {\n throw new Error('Symbol is not a member of builtin');\n }\n return builtin;\n}\n\nexport function getUsedBuiltinsNamed(\n o: Record<symbol, string>,\n): { name: string; builtin: Builtin }[] {\n const res = Object.getOwnPropertySymbols(o).map((s) => {\n const builtin = builtinSymbolToObj[s];\n if (!builtin) {\n throw new Error('Symbol is not a member of builtin');\n }\n const name = o[s];\n if (!name) {\n throw new Error('Name is not provided');\n }\n return { name: name, builtin: builtin };\n });\n return res;\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","import {\n type Eventual,\n type InlineResolve,\n type ResolutionCtx,\n type SlotValuePair,\n type Wgsl,\n type WgslResolvable,\n type WgslSlot,\n isResolvable,\n} from './types';\nimport { getBuiltinInfo } from './wgslBuiltin';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslCode extends WgslResolvable {\n $name(label?: string | undefined): WgslCode;\n\n with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;\n}\n\nexport type BoundWgslCode = Omit<WgslCode, '$name'>;\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 if (typeof s === 'symbol') {\n const builtin = getBuiltinInfo(s);\n ctx.addBuiltin(builtin);\n code += ctx.resolve(builtin.identifier);\n } else {\n code += String(s);\n }\n }\n\n return code;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n toString(): string {\n return `code:${this._label ?? '<unnamed>'}`;\n }\n}\n\nclass BoundWgslCodeImpl<T> implements BoundWgslCode {\n constructor(\n private readonly _innerFn: BoundWgslCode,\n private readonly _slotValuePair: SlotValuePair<T>,\n ) {}\n\n get label() {\n return this._innerFn.label;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this._innerFn, [this._slotValuePair]);\n }\n\n toString(): string {\n const [slot, value] = this._slotValuePair;\n return `code:${this.label ?? '<unnamed>'}[${slot.label ?? '<unnamed>'}=${value}]`;\n }\n}\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';\nimport alignIO from './alignIO';\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 alignIO(measurer, this.byteAlignment);\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\nexport type WgslArray<TElement extends AnyWgslData> = WgslData<\n TB.Unwrap<TElement>[]\n>;\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"]}
package/chunk-K2GYQABQ.js DELETED
@@ -1,12 +0,0 @@
1
- var E=Object.defineProperty,M=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var x=(t,n,e)=>n in t?E(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,ee=(t,n)=>{for(var e in n||(n={}))D.call(n,e)&&x(t,e,n[e]);if(f)for(var e of f(n))B.call(n,e)&&x(t,e,n[e]);return t},te=(t,n)=>M(t,k(n));var re=(t,n)=>{var e={};for(var r in t)D.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&f)for(var r of f(t))n.indexOf(r)<0&&B.call(t,r)&&(e[r]=t[r]);return e};var s=(t,n,e)=>(x(t,typeof n!="symbol"?n+"":n,e),e);import{MaxValue as z,Measurer as F,Schema as j}from"typed-binary";var R=class t extends Error{constructor(e,r){let i=r.map(p=>`- ${p}`);i.length>20&&(i=[...i.slice(0,11),"...",...i.slice(-10)]);super(`Resolution of the following tree failed:
2
- ${i.join(`
3
- `)}`);this.cause=e;this.trace=r;Object.setPrototypeOf(this,t.prototype)}appendToTrace(e){let r=[e,...this.trace];return new t(this.cause,r)}},A=class t extends Error{constructor(e){super(`Missing value for '${e}'`);this.slot=e;Object.setPrototypeOf(this,t.prototype)}},d=class t extends Error{constructor(){super("Recursive types are not supported in WGSL"),Object.setPrototypeOf(this,t.prototype)}};function C(t,n){let e="size"in t?t.size:t.currentByteOffset,r=n-1,i=e&r;"skipBytes"in t?t.skipBytes(n-i&r):t.add(n-i&r)}var m=C;var o=class extends j{constructor({schema:e,byteAlignment:r,code:i}){super();s(this,"size");s(this,"byteAlignment");s(this,"expressionCode");s(this,"_innerSchema");this._innerSchema=e,this.byteAlignment=r,this.expressionCode=i,this.size=this.measure(z).size}resolveReferences(){throw new d}write(e,r){m(e,this.byteAlignment),this._innerSchema.write(e,r)}read(e){return m(e,this.byteAlignment),this._innerSchema.read(e)}measure(e,r=new F){return m(r,this.byteAlignment),this._innerSchema.measure(e,r),r}getUnderlyingTypeString(){if(typeof this.expressionCode=="string")return this.expressionCode;if("elementSchema"in this._innerSchema)return this._innerSchema.elementSchema.getUnderlyingTypeString();throw new Error("Unexpected type used as vertex buffer element")}getUnderlyingType(){return"elementSchema"in this._innerSchema?this._innerSchema.elementSchema.getUnderlyingType():this}resolve(e){return e.resolve(this.expressionCode)}};import*as a from"typed-binary";var ce=new o({schema:a.bool,byteAlignment:4,code:"bool"}),c=new o({schema:a.u32,byteAlignment:4,code:"u32"}),de=new o({schema:a.i32,byteAlignment:4,code:"i32"}),T=new o({schema:a.f32,byteAlignment:4,code:"f32"}),ye=new o({schema:a.tupleOf([a.u32,a.u32]),byteAlignment:8,code:"vec2u"}),ge=new o({schema:a.tupleOf([a.i32,a.i32]),byteAlignment:8,code:"vec2i"}),fe=new o({schema:a.tupleOf([a.f32,a.f32]),byteAlignment:8,code:"vec2f"}),g=new o({schema:a.tupleOf([a.u32,a.u32,a.u32]),byteAlignment:16,code:"vec3u"}),xe=new o({schema:a.tupleOf([a.i32,a.i32,a.i32]),byteAlignment:16,code:"vec3i"}),Te=new o({schema:a.tupleOf([a.f32,a.f32,a.f32]),byteAlignment:16,code:"vec3f"}),be=new o({schema:a.tupleOf([a.u32,a.u32,a.u32,a.u32]),byteAlignment:16,code:"vec4u"}),he=new o({schema:a.tupleOf([a.i32,a.i32,a.i32,a.i32]),byteAlignment:16,code:"vec4i"}),b=new o({schema:a.tupleOf([a.f32,a.f32,a.f32,a.f32]),byteAlignment:16,code:"vec4f"}),We=new o({schema:a.arrayOf(a.f32,16),byteAlignment:16,code:"mat4x4f"});import{MaxValue as O,Measurer as G,Schema as L,ValidationError as N}from"typed-binary";function h(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"resolve"in t}function Se(t){return typeof t=="number"||typeof t=="boolean"||typeof t=="string"||h(t)}function ve(t){return t.__brand==="WgslSlot"}function we(t){return t==="sampler"||t==="sampler_comparison"}function Ie(t){return["texture_1d","texture_2d","texture_2d_array","texture_3d","texture_cube","texture_cube_array","texture_multisampled_2d"].includes(t)}function De(t){return["texture_depth_2d","texture_depth_2d_array","texture_depth_cube","texture_depth_cube_array","texture_depth_multisampled_2d"].includes(t)}function Be(t){return["texture_storage_1d","texture_storage_2d","texture_storage_2d_array","texture_storage_3d"].includes(t)}function Re(t){return t==="texture_external"}function Ae(t){return"pointsTo"in t}import*as P from"typed-binary";var l=class{constructor(){s(this,"label")}$name(n){return this.label=n,this}resolve(n){return n.nameFor(this)}toString(){var n;return`id:${(n=this.label)!=null?n:"<unnamed>"}`}};var u={vertexIndex:Symbol("builtin_vertexIndex"),instanceIndex:Symbol("builtin_instanceIndex"),position:Symbol("builtin_position"),clipDistances:Symbol("builtin_clipDistances"),frontFacing:Symbol("builtin_frontFacing"),fragDepth:Symbol("builtin_fragDepth"),sampleIndex:Symbol("builtin_sampleIndex"),sampleMask:Symbol("builtin_sampleMask"),fragment:Symbol("builtin_fragment"),localInvocationId:Symbol("builtin_localInvocationId"),localInvocationIndex:Symbol("builtin_localInvocationIndex"),globalInvocationId:Symbol("builtin_globalInvocationId"),workgroupId:Symbol("builtin_workgroupId"),numWorkgroups:Symbol("builtin_numWorkgroups")},U={[u.vertexIndex]:{name:"vertex_index",stage:"vertex",direction:"input",type:c,identifier:new l().$name("vertex_index")},[u.instanceIndex]:{name:"instance_index",stage:"vertex",direction:"input",type:c,identifier:new l().$name("instance_index")},[u.position]:{name:"position",stage:"vertex",direction:"output",type:b,identifier:new l().$name("position")},[u.clipDistances]:{name:"clip_distances",stage:"vertex",direction:"output",type:new o({schema:P.arrayOf(c,8),byteAlignment:16,code:"array<u32, 8>"}),identifier:new l().$name("clip_distances")},[u.frontFacing]:{name:"front_facing",stage:"fragment",direction:"input",type:T,identifier:new l().$name("front_facing")},[u.fragDepth]:{name:"frag_depth",stage:"fragment",direction:"output",type:T,identifier:new l().$name("frag_depth")},[u.sampleIndex]:{name:"sample_index",stage:"fragment",direction:"input",type:c,identifier:new l().$name("sample_index")},[u.sampleMask]:{name:"sample_mask",stage:"fragment",direction:"input",type:c,identifier:new l().$name("sample_mask")},[u.fragment]:{name:"fragment",stage:"fragment",direction:"input",type:b,identifier:new l().$name("fragment")},[u.localInvocationId]:{name:"local_invocation_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("local_invocation_id")},[u.localInvocationIndex]:{name:"local_invocation_index",stage:"compute",direction:"input",type:c,identifier:new l().$name("local_invocation_index")},[u.globalInvocationId]:{name:"global_invocation_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("global_invocation_id")},[u.workgroupId]:{name:"workgroup_id",stage:"compute",direction:"input",type:g,identifier:new l().$name("workgroup_id")},[u.numWorkgroups]:{name:"num_workgroups",stage:"compute",direction:"input",type:g,identifier:new l().$name("num_workgroups")}};function V(t){let n=U[t];if(!n)throw new Error("Symbol is not a member of builtin");return n}function Ee(t){return Object.getOwnPropertySymbols(t).map(e=>{let r=U[e];if(!r)throw new Error("Symbol is not a member of builtin");let i=t[e];if(!i)throw new Error("Name is not provided");return{name:i,builtin:r}})}function y(t,...n){let e=t.flatMap((r,i)=>{let p=n[i];return p===void 0?[r]:Array.isArray(p)?[r,...p]:[r,p]});return new W(e)}var W=class{constructor(n){this.segments=n;s(this,"_label")}get label(){return this._label}$name(n){return this._label=n,this}resolve(n){let e="";for(let r of this.segments)if(typeof r=="function"){let i=r(p=>n.unwrap(p));e+=n.resolve(i)}else if(h(r))e+=n.resolve(r);else if(typeof r=="symbol"){let i=V(r);n.addBuiltin(i),e+=n.resolve(i.identifier)}else e+=String(r);return e}with(n,e){return new _(this,[n,e])}toString(){var n;return`code:${(n=this._label)!=null?n:"<unnamed>"}`}},_=class t{constructor(n,e){this._innerFn=n;this._slotValuePair=e}get label(){return this._innerFn.label}with(n,e){return new t(this,[n,e])}resolve(n){return n.resolve(this._innerFn,[this._slotValuePair])}toString(){var r,i;let[n,e]=this._slotValuePair;return`code:${(r=this.label)!=null?r:"<unnamed>"}[${(i=n.label)!=null?i:"<unnamed>"}=${e}]`}};var S=class extends L{constructor(e,r){super();this._elementType=e;this.capacity=r;s(this,"_label");s(this,"byteAlignment");s(this,"size");this.byteAlignment=Math.max(4,this._elementType.byteAlignment),this.size=this.measure(O).size}$name(e){return this._label=e,this}resolveReferences(){throw new d}write(e,r){if(r.length>this.capacity)throw new N(`Tried to write too many values, ${r.length} > ${this.capacity}`);m(e,this.byteAlignment),c.write(e,r.length),m(e,this._elementType.byteAlignment);let i=e.currentByteOffset;for(let p of r)this._elementType.write(e,p);e.seekTo(i+this.capacity*this._elementType.size)}read(e){let r=[];m(e,this.byteAlignment);let i=c.read(e);m(e,this._elementType.byteAlignment);let p=e.currentByteOffset;for(let I=0;I<i;++I)r.push(this._elementType.read(e));return e.seekTo(p+this.capacity*this._elementType.size),r}measure(e,r=new G){return m(r,this.byteAlignment),c.measure(O,r),m(r,this._elementType.byteAlignment),r.add(this._elementType.size*this.capacity),r}resolve(e){let r=new l().$name(this._label);return e.addDeclaration(y`
4
- struct ${r} {
5
- count: u32,
6
- values: array<${this._elementType}, ${this.capacity}>,
7
- }`),e.resolve(r)}},Je=(t,n)=>new S(t,n);import{MaxValue as q,Measurer as H,Schema as J,object as K}from"typed-binary";var rt=t=>new v(t),v=class extends J{constructor(e){super();this._properties=e;s(this,"_label");s(this,"_innerSchema");s(this,"byteAlignment");s(this,"size");this._innerSchema=K(e),this.byteAlignment=Object.values(e).map(r=>r.byteAlignment).reduce((r,i)=>r>i?r:i),this.size=this.measure(q).size}$name(e){return this._label=e,this}resolveReferences(){throw new d}write(e,r){this._innerSchema.write(e,r)}read(e){return this._innerSchema.read(e)}measure(e,r=new H){return m(r,this.byteAlignment),this._innerSchema.measure(e,r),r}resolve(e){let r=new l().$name(this._label);return e.addDeclaration(y`
8
- struct ${r} {
9
- ${Object.entries(this._properties).map(([i,p])=>y`${i}: ${p},\n`)}
10
- }
11
- `),e.resolve(r)}};import*as $ from"typed-binary";var ot=(t,n)=>new o({schema:$.arrayOf(t,n),byteAlignment:t.byteAlignment,code:y`array<${t}, ${n}>`});function Q(t){return{scope:"function",pointsTo:t}}import{Measurer as X,Schema as Y}from"typed-binary";function Z(t){return new w(t)}var w=class extends Y{constructor(e){super();this.innerData=e;s(this,"size");s(this,"byteAlignment");this.size=this.innerData.size,this.byteAlignment=this.innerData.byteAlignment}resolveReferences(){throw new d}write(e,r){this.innerData.write(e,r)}read(e){return this.innerData.read(e)}measure(e,r=new X){return this.innerData.measure(e,r)}resolve(e){return`atomic<${e.resolve(this.innerData)}>`}};export{ee as a,te as b,re as c,s as d,R as e,A as f,d as g,h,Se as i,ve as j,we as k,Ie as l,De as m,Be as n,Re as o,Ae as p,o as q,ce as r,c as s,de as t,T as u,ye as v,ge as w,fe as x,g as y,xe as z,Te as A,be as B,he as C,b as D,We as E,l as F,Je as G,rt as H,ot as I,Q as J,Z as K,u as L,V as M,Ee as N,y as O};
12
- //# sourceMappingURL=chunk-K2GYQABQ.js.map