glre 0.47.0 → 0.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1017 -29
- package/dist/addons.d.ts +60 -55
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +84 -79
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +65 -58
- package/dist/node.cjs +42 -42
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +63 -58
- package/dist/node.js +15 -15
- package/dist/node.js.map +1 -1
- package/dist/react.d.ts +84 -79
- package/dist/solid.d.ts +84 -79
- package/package.json +1 -1
- package/src/helpers.ts +2 -2
- package/src/index.ts +9 -4
- package/src/node/create.ts +10 -9
- package/src/node/scope.ts +3 -15
- package/src/node/types.ts +20 -45
- package/src/node/utils/const.ts +27 -10
- package/src/node/utils/index.ts +15 -8
- package/src/node/utils/infer.ts +26 -20
- package/src/node/utils/parse.ts +5 -5
- package/src/types.ts +6 -4
- package/src/webgl/compute.ts +4 -4
- package/src/webgl/graphic.ts +6 -6
- package/src/webgpu/compute.ts +5 -5
- package/src/webgpu/graphic.ts +15 -27
- package/src/webgpu/index.ts +36 -17
- package/src/webgpu/utils.ts +23 -27
package/dist/react.d.ts
CHANGED
|
@@ -29,8 +29,54 @@ declare const TYPE_MAPPING: {
|
|
|
29
29
|
readonly struct: "struct";
|
|
30
30
|
};
|
|
31
31
|
declare const CONSTANTS: (keyof typeof TYPE_MAPPING)[];
|
|
32
|
+
declare const SWIZZLE_BASE_MAP: {
|
|
33
|
+
readonly float: "float";
|
|
34
|
+
readonly vec2: "float";
|
|
35
|
+
readonly vec3: "float";
|
|
36
|
+
readonly vec4: "float";
|
|
37
|
+
readonly int: "int";
|
|
38
|
+
readonly ivec2: "int";
|
|
39
|
+
readonly ivec3: "int";
|
|
40
|
+
readonly ivec4: "int";
|
|
41
|
+
readonly uint: "uint";
|
|
42
|
+
readonly uvec2: "uint";
|
|
43
|
+
readonly uvec3: "uint";
|
|
44
|
+
readonly uvec4: "uint";
|
|
45
|
+
readonly bool: "bool";
|
|
46
|
+
readonly bvec2: "bool";
|
|
47
|
+
readonly bvec3: "bool";
|
|
48
|
+
readonly bvec4: "bool";
|
|
49
|
+
};
|
|
50
|
+
declare const SWIZZLE_RESULT_MAP: {
|
|
51
|
+
float: {
|
|
52
|
+
readonly 1: "float";
|
|
53
|
+
readonly 2: "vec2";
|
|
54
|
+
readonly 3: "vec3";
|
|
55
|
+
readonly 4: "vec4";
|
|
56
|
+
readonly 9: "mat3";
|
|
57
|
+
readonly 16: "mat4";
|
|
58
|
+
};
|
|
59
|
+
int: {
|
|
60
|
+
readonly 1: "int";
|
|
61
|
+
readonly 2: "ivec2";
|
|
62
|
+
readonly 3: "ivec3";
|
|
63
|
+
readonly 4: "ivec4";
|
|
64
|
+
};
|
|
65
|
+
uint: {
|
|
66
|
+
readonly 1: "uint";
|
|
67
|
+
readonly 2: "uvec2";
|
|
68
|
+
readonly 3: "uvec3";
|
|
69
|
+
readonly 4: "uvec4";
|
|
70
|
+
};
|
|
71
|
+
bool: {
|
|
72
|
+
readonly 1: "bool";
|
|
73
|
+
readonly 2: "bvec2";
|
|
74
|
+
readonly 3: "bvec3";
|
|
75
|
+
readonly 4: "bvec4";
|
|
76
|
+
};
|
|
77
|
+
};
|
|
32
78
|
declare const OPERATORS: {
|
|
33
|
-
readonly not: "";
|
|
79
|
+
readonly not: "!";
|
|
34
80
|
readonly add: "+";
|
|
35
81
|
readonly sub: "-";
|
|
36
82
|
readonly mul: "*";
|
|
@@ -69,28 +115,6 @@ declare const OPERATOR_TYPE_RULES: readonly [readonly ["float", "vec2", "vec2"],
|
|
|
69
115
|
*/
|
|
70
116
|
declare const FUNCTIONS: readonly [...("texture" | "all" | "any" | "determinant" | "distance" | "dot" | "length" | "lengthSq" | "luminance" | "cross" | "cubeTexture" | "texelFetch" | "textureLod")[], "abs", "acos", "acosh", "asin", "asinh", "atan", "atanh", "ceil", "cos", "cosh", "dFdx", "dFdy", "degrees", "exp", "exp2", "floor", "fract", "fwidth", "inverse", "inverseSqrt", "log", "log2", "negate", "normalize", "oneMinus", "radians", "reciprocal", "round", "sign", "sin", "sinh", "sqrt", "tan", "tanh", "trunc", "saturate", "atan2", "clamp", "max", "min", "mix", "pow", "reflect", "refract", "smoothstep", "step"];
|
|
71
117
|
|
|
72
|
-
/**
|
|
73
|
-
* binding
|
|
74
|
-
*/
|
|
75
|
-
declare const createBinding: () => {
|
|
76
|
-
uniform: reev.Nested<{
|
|
77
|
-
group: number;
|
|
78
|
-
binding: number;
|
|
79
|
-
}, []>;
|
|
80
|
-
texture: reev.Nested<{
|
|
81
|
-
group: number;
|
|
82
|
-
binding: number;
|
|
83
|
-
}, []>;
|
|
84
|
-
storage: reev.Nested<{
|
|
85
|
-
group: number;
|
|
86
|
-
binding: number;
|
|
87
|
-
}, []>;
|
|
88
|
-
attrib: reev.Nested<{
|
|
89
|
-
location: number;
|
|
90
|
-
}, []>;
|
|
91
|
-
};
|
|
92
|
-
type Binding = ReturnType<typeof createBinding>;
|
|
93
|
-
|
|
94
118
|
type Constants = (typeof CONSTANTS)[number] | 'void';
|
|
95
119
|
type Conversions = (typeof CONVERSIONS)[number];
|
|
96
120
|
type Functions = (typeof FUNCTIONS)[number];
|
|
@@ -100,7 +124,7 @@ type Operators = (typeof OPERATOR_KEYS)[number];
|
|
|
100
124
|
*/
|
|
101
125
|
interface FnLayout {
|
|
102
126
|
name: string;
|
|
103
|
-
type
|
|
127
|
+
type?: C | 'auto';
|
|
104
128
|
inputs?: Array<{
|
|
105
129
|
name: string;
|
|
106
130
|
type: C | 'auto';
|
|
@@ -123,7 +147,6 @@ interface NodeProps {
|
|
|
123
147
|
}
|
|
124
148
|
interface NodeContext {
|
|
125
149
|
gl?: Partial<GL>;
|
|
126
|
-
binding?: Binding;
|
|
127
150
|
label?: 'vert' | 'frag' | 'compute';
|
|
128
151
|
isWebGL?: boolean;
|
|
129
152
|
units?: any;
|
|
@@ -140,6 +163,15 @@ interface NodeContext {
|
|
|
140
163
|
structStructFields: Map<string, StructFields>;
|
|
141
164
|
};
|
|
142
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* swizzle
|
|
168
|
+
*/
|
|
169
|
+
type _SwizzleLength<A extends string> = A extends `${infer _}${infer A}` ? A extends '' ? 1 : A extends `${infer _}${infer B}` ? B extends '' ? 2 : B extends `${infer _}${infer C}` ? C extends '' ? 3 : 4 : never : never : never;
|
|
170
|
+
type _SwizzleBaseMap = typeof SWIZZLE_BASE_MAP;
|
|
171
|
+
type _SwizzleResultMap = typeof SWIZZLE_RESULT_MAP;
|
|
172
|
+
type _SwizzleBase<T extends C> = T extends keyof _SwizzleBaseMap ? _SwizzleBaseMap[T] : never;
|
|
173
|
+
type _SwizzleResult<T extends C, L extends 1 | 2 | 3 | 4> = _SwizzleResultMap[_SwizzleBase<T>][L];
|
|
174
|
+
type InferSwizzleType<T extends C, S extends string> = _SwizzleLength<S> extends infer L extends 1 | 2 | 3 | 4 ? _SwizzleResult<_SwizzleBase<T>, L> : never;
|
|
143
175
|
/**
|
|
144
176
|
* infer
|
|
145
177
|
*/
|
|
@@ -150,57 +182,6 @@ type ExtractPairs<T> = T extends readonly [infer L, infer R, string] ? [L, R] |
|
|
|
150
182
|
type OperatorTypeRules = ExtractPairs<_OperatorTypeRulesMap[number]>;
|
|
151
183
|
type IsInRules<L extends C, R extends C> = [L, R] extends OperatorTypeRules ? 1 : 0;
|
|
152
184
|
type ValidateOperator<L extends C, R extends C> = L extends R ? 1 : IsInRules<L, R>;
|
|
153
|
-
/**
|
|
154
|
-
* swizzle
|
|
155
|
-
*/
|
|
156
|
-
type _SwizzleLength<A extends string> = A extends `${infer _}${infer A}` ? A extends '' ? 1 : A extends `${infer _}${infer B}` ? B extends '' ? 2 : B extends `${infer _}${infer C}` ? C extends '' ? 3 : 4 : never : never : never;
|
|
157
|
-
type _SwizzleBaseMap = {
|
|
158
|
-
float: 'float';
|
|
159
|
-
vec2: 'float';
|
|
160
|
-
vec3: 'float';
|
|
161
|
-
vec4: 'float';
|
|
162
|
-
int: 'int';
|
|
163
|
-
ivec2: 'int';
|
|
164
|
-
ivec3: 'int';
|
|
165
|
-
ivec4: 'int';
|
|
166
|
-
uint: 'uint';
|
|
167
|
-
uvec2: 'uint';
|
|
168
|
-
uvec3: 'uint';
|
|
169
|
-
uvec4: 'uint';
|
|
170
|
-
bool: 'bool';
|
|
171
|
-
bvec2: 'bool';
|
|
172
|
-
bvec3: 'bool';
|
|
173
|
-
bvec4: 'bool';
|
|
174
|
-
};
|
|
175
|
-
type _SwizzleResultMap = {
|
|
176
|
-
float: {
|
|
177
|
-
1: 'float';
|
|
178
|
-
2: 'vec2';
|
|
179
|
-
3: 'vec3';
|
|
180
|
-
4: 'vec4';
|
|
181
|
-
};
|
|
182
|
-
int: {
|
|
183
|
-
1: 'int';
|
|
184
|
-
2: 'ivec2';
|
|
185
|
-
3: 'ivec3';
|
|
186
|
-
4: 'ivec4';
|
|
187
|
-
};
|
|
188
|
-
uint: {
|
|
189
|
-
1: 'uint';
|
|
190
|
-
2: 'uvec2';
|
|
191
|
-
3: 'uvec3';
|
|
192
|
-
4: 'uvec4';
|
|
193
|
-
};
|
|
194
|
-
bool: {
|
|
195
|
-
1: 'bool';
|
|
196
|
-
2: 'bvec2';
|
|
197
|
-
3: 'bvec3';
|
|
198
|
-
4: 'bvec4';
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
type _SwizzleBase<T extends C> = T extends keyof _SwizzleBaseMap ? _SwizzleBaseMap[T] : never;
|
|
202
|
-
type _SwizzleResult<T extends C, L extends 1 | 2 | 3 | 4> = _SwizzleResultMap[_SwizzleBase<T>][L];
|
|
203
|
-
type InferSwizzleType<T extends C, S extends string> = _SwizzleLength<S> extends infer L extends 1 | 2 | 3 | 4 ? _SwizzleResult<_SwizzleBase<T>, L> : never;
|
|
204
185
|
/**
|
|
205
186
|
* Swizzles
|
|
206
187
|
*/
|
|
@@ -408,6 +389,28 @@ interface _X<T extends C> {
|
|
|
408
389
|
step<U extends C>(edge: number | X<U>): X<InferOperator<T, U>>;
|
|
409
390
|
}
|
|
410
391
|
|
|
392
|
+
/**
|
|
393
|
+
* binding
|
|
394
|
+
*/
|
|
395
|
+
declare const createBinding: () => {
|
|
396
|
+
uniform: reev.Nested<{
|
|
397
|
+
group: number;
|
|
398
|
+
binding: number;
|
|
399
|
+
}, []>;
|
|
400
|
+
texture: reev.Nested<{
|
|
401
|
+
group: number;
|
|
402
|
+
binding: number;
|
|
403
|
+
}, []>;
|
|
404
|
+
storage: reev.Nested<{
|
|
405
|
+
group: number;
|
|
406
|
+
binding: number;
|
|
407
|
+
}, []>;
|
|
408
|
+
attrib: reev.Nested<{
|
|
409
|
+
location: number;
|
|
410
|
+
}, []>;
|
|
411
|
+
};
|
|
412
|
+
type Binding = ReturnType<typeof createBinding>;
|
|
413
|
+
|
|
411
414
|
type GL = EventState<{
|
|
412
415
|
/**
|
|
413
416
|
* initial value
|
|
@@ -445,7 +448,9 @@ type GL = EventState<{
|
|
|
445
448
|
gpu: GPUCanvasContext;
|
|
446
449
|
device: GPUDevice;
|
|
447
450
|
format: GPUTextureFormat;
|
|
448
|
-
|
|
451
|
+
passEncoder: GPURenderPassEncoder;
|
|
452
|
+
commandEncoder: GPUCommandEncoder;
|
|
453
|
+
depthTexture?: GPUTexture;
|
|
449
454
|
binding: Binding;
|
|
450
455
|
/**
|
|
451
456
|
* core state
|
|
@@ -499,10 +504,10 @@ type Storage = number[] | Float32Array;
|
|
|
499
504
|
* for webgpu
|
|
500
505
|
*/
|
|
501
506
|
interface UniformData {
|
|
502
|
-
array: Float32Array;
|
|
503
|
-
buffer: GPUBuffer;
|
|
504
507
|
binding: number;
|
|
505
508
|
group: number;
|
|
509
|
+
array: Float32Array;
|
|
510
|
+
buffer: GPUBuffer;
|
|
506
511
|
}
|
|
507
512
|
interface TextureData {
|
|
508
513
|
binding: number;
|
package/dist/solid.d.ts
CHANGED
|
@@ -29,8 +29,54 @@ declare const TYPE_MAPPING: {
|
|
|
29
29
|
readonly struct: "struct";
|
|
30
30
|
};
|
|
31
31
|
declare const CONSTANTS: (keyof typeof TYPE_MAPPING)[];
|
|
32
|
+
declare const SWIZZLE_BASE_MAP: {
|
|
33
|
+
readonly float: "float";
|
|
34
|
+
readonly vec2: "float";
|
|
35
|
+
readonly vec3: "float";
|
|
36
|
+
readonly vec4: "float";
|
|
37
|
+
readonly int: "int";
|
|
38
|
+
readonly ivec2: "int";
|
|
39
|
+
readonly ivec3: "int";
|
|
40
|
+
readonly ivec4: "int";
|
|
41
|
+
readonly uint: "uint";
|
|
42
|
+
readonly uvec2: "uint";
|
|
43
|
+
readonly uvec3: "uint";
|
|
44
|
+
readonly uvec4: "uint";
|
|
45
|
+
readonly bool: "bool";
|
|
46
|
+
readonly bvec2: "bool";
|
|
47
|
+
readonly bvec3: "bool";
|
|
48
|
+
readonly bvec4: "bool";
|
|
49
|
+
};
|
|
50
|
+
declare const SWIZZLE_RESULT_MAP: {
|
|
51
|
+
float: {
|
|
52
|
+
readonly 1: "float";
|
|
53
|
+
readonly 2: "vec2";
|
|
54
|
+
readonly 3: "vec3";
|
|
55
|
+
readonly 4: "vec4";
|
|
56
|
+
readonly 9: "mat3";
|
|
57
|
+
readonly 16: "mat4";
|
|
58
|
+
};
|
|
59
|
+
int: {
|
|
60
|
+
readonly 1: "int";
|
|
61
|
+
readonly 2: "ivec2";
|
|
62
|
+
readonly 3: "ivec3";
|
|
63
|
+
readonly 4: "ivec4";
|
|
64
|
+
};
|
|
65
|
+
uint: {
|
|
66
|
+
readonly 1: "uint";
|
|
67
|
+
readonly 2: "uvec2";
|
|
68
|
+
readonly 3: "uvec3";
|
|
69
|
+
readonly 4: "uvec4";
|
|
70
|
+
};
|
|
71
|
+
bool: {
|
|
72
|
+
readonly 1: "bool";
|
|
73
|
+
readonly 2: "bvec2";
|
|
74
|
+
readonly 3: "bvec3";
|
|
75
|
+
readonly 4: "bvec4";
|
|
76
|
+
};
|
|
77
|
+
};
|
|
32
78
|
declare const OPERATORS: {
|
|
33
|
-
readonly not: "";
|
|
79
|
+
readonly not: "!";
|
|
34
80
|
readonly add: "+";
|
|
35
81
|
readonly sub: "-";
|
|
36
82
|
readonly mul: "*";
|
|
@@ -69,28 +115,6 @@ declare const OPERATOR_TYPE_RULES: readonly [readonly ["float", "vec2", "vec2"],
|
|
|
69
115
|
*/
|
|
70
116
|
declare const FUNCTIONS: readonly [...("texture" | "all" | "any" | "determinant" | "distance" | "dot" | "length" | "lengthSq" | "luminance" | "cross" | "cubeTexture" | "texelFetch" | "textureLod")[], "abs", "acos", "acosh", "asin", "asinh", "atan", "atanh", "ceil", "cos", "cosh", "dFdx", "dFdy", "degrees", "exp", "exp2", "floor", "fract", "fwidth", "inverse", "inverseSqrt", "log", "log2", "negate", "normalize", "oneMinus", "radians", "reciprocal", "round", "sign", "sin", "sinh", "sqrt", "tan", "tanh", "trunc", "saturate", "atan2", "clamp", "max", "min", "mix", "pow", "reflect", "refract", "smoothstep", "step"];
|
|
71
117
|
|
|
72
|
-
/**
|
|
73
|
-
* binding
|
|
74
|
-
*/
|
|
75
|
-
declare const createBinding: () => {
|
|
76
|
-
uniform: reev.Nested<{
|
|
77
|
-
group: number;
|
|
78
|
-
binding: number;
|
|
79
|
-
}, []>;
|
|
80
|
-
texture: reev.Nested<{
|
|
81
|
-
group: number;
|
|
82
|
-
binding: number;
|
|
83
|
-
}, []>;
|
|
84
|
-
storage: reev.Nested<{
|
|
85
|
-
group: number;
|
|
86
|
-
binding: number;
|
|
87
|
-
}, []>;
|
|
88
|
-
attrib: reev.Nested<{
|
|
89
|
-
location: number;
|
|
90
|
-
}, []>;
|
|
91
|
-
};
|
|
92
|
-
type Binding = ReturnType<typeof createBinding>;
|
|
93
|
-
|
|
94
118
|
type Constants = (typeof CONSTANTS)[number] | 'void';
|
|
95
119
|
type Conversions = (typeof CONVERSIONS)[number];
|
|
96
120
|
type Functions = (typeof FUNCTIONS)[number];
|
|
@@ -100,7 +124,7 @@ type Operators = (typeof OPERATOR_KEYS)[number];
|
|
|
100
124
|
*/
|
|
101
125
|
interface FnLayout {
|
|
102
126
|
name: string;
|
|
103
|
-
type
|
|
127
|
+
type?: C | 'auto';
|
|
104
128
|
inputs?: Array<{
|
|
105
129
|
name: string;
|
|
106
130
|
type: C | 'auto';
|
|
@@ -123,7 +147,6 @@ interface NodeProps {
|
|
|
123
147
|
}
|
|
124
148
|
interface NodeContext {
|
|
125
149
|
gl?: Partial<GL>;
|
|
126
|
-
binding?: Binding;
|
|
127
150
|
label?: 'vert' | 'frag' | 'compute';
|
|
128
151
|
isWebGL?: boolean;
|
|
129
152
|
units?: any;
|
|
@@ -140,6 +163,15 @@ interface NodeContext {
|
|
|
140
163
|
structStructFields: Map<string, StructFields>;
|
|
141
164
|
};
|
|
142
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* swizzle
|
|
168
|
+
*/
|
|
169
|
+
type _SwizzleLength<A extends string> = A extends `${infer _}${infer A}` ? A extends '' ? 1 : A extends `${infer _}${infer B}` ? B extends '' ? 2 : B extends `${infer _}${infer C}` ? C extends '' ? 3 : 4 : never : never : never;
|
|
170
|
+
type _SwizzleBaseMap = typeof SWIZZLE_BASE_MAP;
|
|
171
|
+
type _SwizzleResultMap = typeof SWIZZLE_RESULT_MAP;
|
|
172
|
+
type _SwizzleBase<T extends C> = T extends keyof _SwizzleBaseMap ? _SwizzleBaseMap[T] : never;
|
|
173
|
+
type _SwizzleResult<T extends C, L extends 1 | 2 | 3 | 4> = _SwizzleResultMap[_SwizzleBase<T>][L];
|
|
174
|
+
type InferSwizzleType<T extends C, S extends string> = _SwizzleLength<S> extends infer L extends 1 | 2 | 3 | 4 ? _SwizzleResult<_SwizzleBase<T>, L> : never;
|
|
143
175
|
/**
|
|
144
176
|
* infer
|
|
145
177
|
*/
|
|
@@ -150,57 +182,6 @@ type ExtractPairs<T> = T extends readonly [infer L, infer R, string] ? [L, R] |
|
|
|
150
182
|
type OperatorTypeRules = ExtractPairs<_OperatorTypeRulesMap[number]>;
|
|
151
183
|
type IsInRules<L extends C, R extends C> = [L, R] extends OperatorTypeRules ? 1 : 0;
|
|
152
184
|
type ValidateOperator<L extends C, R extends C> = L extends R ? 1 : IsInRules<L, R>;
|
|
153
|
-
/**
|
|
154
|
-
* swizzle
|
|
155
|
-
*/
|
|
156
|
-
type _SwizzleLength<A extends string> = A extends `${infer _}${infer A}` ? A extends '' ? 1 : A extends `${infer _}${infer B}` ? B extends '' ? 2 : B extends `${infer _}${infer C}` ? C extends '' ? 3 : 4 : never : never : never;
|
|
157
|
-
type _SwizzleBaseMap = {
|
|
158
|
-
float: 'float';
|
|
159
|
-
vec2: 'float';
|
|
160
|
-
vec3: 'float';
|
|
161
|
-
vec4: 'float';
|
|
162
|
-
int: 'int';
|
|
163
|
-
ivec2: 'int';
|
|
164
|
-
ivec3: 'int';
|
|
165
|
-
ivec4: 'int';
|
|
166
|
-
uint: 'uint';
|
|
167
|
-
uvec2: 'uint';
|
|
168
|
-
uvec3: 'uint';
|
|
169
|
-
uvec4: 'uint';
|
|
170
|
-
bool: 'bool';
|
|
171
|
-
bvec2: 'bool';
|
|
172
|
-
bvec3: 'bool';
|
|
173
|
-
bvec4: 'bool';
|
|
174
|
-
};
|
|
175
|
-
type _SwizzleResultMap = {
|
|
176
|
-
float: {
|
|
177
|
-
1: 'float';
|
|
178
|
-
2: 'vec2';
|
|
179
|
-
3: 'vec3';
|
|
180
|
-
4: 'vec4';
|
|
181
|
-
};
|
|
182
|
-
int: {
|
|
183
|
-
1: 'int';
|
|
184
|
-
2: 'ivec2';
|
|
185
|
-
3: 'ivec3';
|
|
186
|
-
4: 'ivec4';
|
|
187
|
-
};
|
|
188
|
-
uint: {
|
|
189
|
-
1: 'uint';
|
|
190
|
-
2: 'uvec2';
|
|
191
|
-
3: 'uvec3';
|
|
192
|
-
4: 'uvec4';
|
|
193
|
-
};
|
|
194
|
-
bool: {
|
|
195
|
-
1: 'bool';
|
|
196
|
-
2: 'bvec2';
|
|
197
|
-
3: 'bvec3';
|
|
198
|
-
4: 'bvec4';
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
type _SwizzleBase<T extends C> = T extends keyof _SwizzleBaseMap ? _SwizzleBaseMap[T] : never;
|
|
202
|
-
type _SwizzleResult<T extends C, L extends 1 | 2 | 3 | 4> = _SwizzleResultMap[_SwizzleBase<T>][L];
|
|
203
|
-
type InferSwizzleType<T extends C, S extends string> = _SwizzleLength<S> extends infer L extends 1 | 2 | 3 | 4 ? _SwizzleResult<_SwizzleBase<T>, L> : never;
|
|
204
185
|
/**
|
|
205
186
|
* Swizzles
|
|
206
187
|
*/
|
|
@@ -408,6 +389,28 @@ interface _X<T extends C> {
|
|
|
408
389
|
step<U extends C>(edge: number | X<U>): X<InferOperator<T, U>>;
|
|
409
390
|
}
|
|
410
391
|
|
|
392
|
+
/**
|
|
393
|
+
* binding
|
|
394
|
+
*/
|
|
395
|
+
declare const createBinding: () => {
|
|
396
|
+
uniform: reev.Nested<{
|
|
397
|
+
group: number;
|
|
398
|
+
binding: number;
|
|
399
|
+
}, []>;
|
|
400
|
+
texture: reev.Nested<{
|
|
401
|
+
group: number;
|
|
402
|
+
binding: number;
|
|
403
|
+
}, []>;
|
|
404
|
+
storage: reev.Nested<{
|
|
405
|
+
group: number;
|
|
406
|
+
binding: number;
|
|
407
|
+
}, []>;
|
|
408
|
+
attrib: reev.Nested<{
|
|
409
|
+
location: number;
|
|
410
|
+
}, []>;
|
|
411
|
+
};
|
|
412
|
+
type Binding = ReturnType<typeof createBinding>;
|
|
413
|
+
|
|
411
414
|
type GL = EventState<{
|
|
412
415
|
/**
|
|
413
416
|
* initial value
|
|
@@ -445,7 +448,9 @@ type GL = EventState<{
|
|
|
445
448
|
gpu: GPUCanvasContext;
|
|
446
449
|
device: GPUDevice;
|
|
447
450
|
format: GPUTextureFormat;
|
|
448
|
-
|
|
451
|
+
passEncoder: GPURenderPassEncoder;
|
|
452
|
+
commandEncoder: GPUCommandEncoder;
|
|
453
|
+
depthTexture?: GPUTexture;
|
|
449
454
|
binding: Binding;
|
|
450
455
|
/**
|
|
451
456
|
* core state
|
|
@@ -499,10 +504,10 @@ type Storage = number[] | Float32Array;
|
|
|
499
504
|
* for webgpu
|
|
500
505
|
*/
|
|
501
506
|
interface UniformData {
|
|
502
|
-
array: Float32Array;
|
|
503
|
-
buffer: GPUBuffer;
|
|
504
507
|
binding: number;
|
|
505
508
|
group: number;
|
|
509
|
+
array: Float32Array;
|
|
510
|
+
buffer: GPUBuffer;
|
|
506
511
|
}
|
|
507
512
|
interface TextureData {
|
|
508
513
|
binding: number;
|
package/package.json
CHANGED
package/src/helpers.ts
CHANGED
|
@@ -64,9 +64,9 @@ const calcStride = (arrayLength: number, count = 3) => {
|
|
|
64
64
|
return -1
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export const getStride = (arrayLength: number, count = 1, error = console.warn) => {
|
|
67
|
+
export const getStride = (arrayLength: number, count = 1, error = console.warn, id = '') => {
|
|
68
68
|
const ret = calcStride(arrayLength, count)
|
|
69
|
-
if (!isValidStride(ret)) error(`glre attribute error: Invalid attribute length ${arrayLength}
|
|
69
|
+
if (!isValidStride(ret)) error(`glre attribute error: Invalid attribute length ${arrayLength}, ${id ? `${id} ` : ' '}must divide by vertex count (${count}) with valid stride (1,2,3,4,9,16)`)
|
|
70
70
|
return ret
|
|
71
71
|
}
|
|
72
72
|
|
package/src/index.ts
CHANGED
|
@@ -54,18 +54,23 @@ export const createGL = (...args: Partial<GL>[]) => {
|
|
|
54
54
|
gl('mount', async (el: HTMLCanvasElement) => {
|
|
55
55
|
gl.el = findElement(gl) || el || args.map(findElement).find(Boolean)
|
|
56
56
|
const isAppend = !gl.el // Check first: canvas may unmount during WebGPU async processing
|
|
57
|
-
if (isAppend && !gl.isNative)
|
|
58
|
-
|
|
57
|
+
if (isAppend && !gl.isNative) {
|
|
58
|
+
gl.el = document.createElement('canvas')
|
|
59
|
+
Object.assign(gl.el.style, { top: 0, left: 0, position: 'fixed' })
|
|
60
|
+
}
|
|
61
|
+
for (let i = 0; i < args.length; i++) {
|
|
62
|
+
const arg = args[i]
|
|
59
63
|
gl.fs = arg.fs || arg.frag || arg.fragment || undefined
|
|
60
64
|
gl.cs = arg.cs || arg.comp || arg.compute || undefined
|
|
61
65
|
gl.vs = arg.vs || arg.vert || arg.vertex || undefined
|
|
62
|
-
gl.triangleCount = arg.triangleCount ||
|
|
66
|
+
gl.triangleCount = arg.triangleCount || 2
|
|
63
67
|
gl.instanceCount = arg.instanceCount || 1
|
|
64
68
|
gl.particleCount = arg.particleCount || 1024
|
|
69
|
+
gl.count = arg.count || gl.triangleCount * 3 || 6
|
|
65
70
|
gl(arg)
|
|
66
71
|
if (is.bol(arg.isWebGL)) gl.isWebGL = arg.isWebGL || !isWebGPUSupported()
|
|
67
72
|
if (gl.isWebGL) webgl(gl)
|
|
68
|
-
else await webgpu(gl)
|
|
73
|
+
else await webgpu(gl, i === args.length - 1)
|
|
69
74
|
if (arg.mount) arg.mount() // events added in mount phase need explicit call to execute
|
|
70
75
|
}
|
|
71
76
|
if (!gl.el || gl.isError) return // stop if error or canvas was unmounted during async
|
package/src/node/create.ts
CHANGED
|
@@ -8,9 +8,9 @@ const toPrimitive = (x: Y, hint: string) => {
|
|
|
8
8
|
if (hint === 'string') return code(x as any, null)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const create = <T extends C>(type: NodeTypes, props?: NodeProps | null, ...
|
|
11
|
+
export const create = <T extends C>(type: NodeTypes, props?: NodeProps | null, ...children: Y[]) => {
|
|
12
12
|
if (!props) props = {}
|
|
13
|
-
if (
|
|
13
|
+
if (children.length) props.children = children
|
|
14
14
|
const listeners = new Set<(value: any) => void>()
|
|
15
15
|
const get = (_: unknown, key: string | Symbol) => {
|
|
16
16
|
if (key === 'type') return type
|
|
@@ -30,20 +30,21 @@ export const create = <T extends C>(type: NodeTypes, props?: NodeProps | null, .
|
|
|
30
30
|
if (key === 'variable') return (id = getId()) => variable(id)
|
|
31
31
|
if (key === 'builtin') return (id = getId()) => builtin(id)
|
|
32
32
|
if (key === 'vertexStage') return (id = getId()) => vertexStage(x, id)
|
|
33
|
-
if (key === 'element') return (
|
|
34
|
-
if (key === 'member') return (
|
|
33
|
+
if (key === 'element') return (y: Y) => (type === 'storage' ? gather(x, y) : element(x, y))
|
|
34
|
+
if (key === 'member') return (y: Y) => member(x, y)
|
|
35
35
|
if (key === 'assign') return assign.bind(null, x, x.type === 'gather')
|
|
36
36
|
if (key === 'select') return select.bind(null, x)
|
|
37
37
|
if (isOperator(key)) {
|
|
38
|
-
|
|
38
|
+
if (key.endsWith('Assign')) return (...y: Y[]) => addToScope(operator(key, x, ...y))
|
|
39
|
+
return (...y: Y[]) => operator(key, x, ...y)
|
|
39
40
|
}
|
|
40
|
-
if (isFunction(key)) return (...
|
|
41
|
+
if (isFunction(key)) return (...y: Y[]) => function_(key, x, ...y)
|
|
41
42
|
if (isConversion(key)) return () => conversion(getConstant(key), x)
|
|
42
43
|
if (is.str(key)) return isArrayAccess(key) ? element(x, key) : member(x, key)
|
|
43
44
|
}
|
|
44
|
-
const set = (_: unknown, key: string,
|
|
45
|
-
if (key === 'value') listeners.forEach((fun) => fun(
|
|
46
|
-
if (is.str(key)) member(x, key).assign(
|
|
45
|
+
const set = (_: unknown, key: string, y: Y) => {
|
|
46
|
+
if (key === 'value') listeners.forEach((fun) => fun(y))
|
|
47
|
+
if (is.str(key)) member(x, key).assign(y)
|
|
47
48
|
return true
|
|
48
49
|
}
|
|
49
50
|
const x = new Proxy({}, { get, set }) as unknown as X<T>
|
package/src/node/scope.ts
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { conversion, create } from './create'
|
|
2
|
-
import type {
|
|
3
|
-
FnLayout,
|
|
4
|
-
FnType,
|
|
5
|
-
Constants as C,
|
|
6
|
-
Int,
|
|
7
|
-
NodeProps,
|
|
8
|
-
Struct,
|
|
9
|
-
StructFactory,
|
|
10
|
-
StructFields,
|
|
11
|
-
X,
|
|
12
|
-
Y,
|
|
13
|
-
} from './types'
|
|
14
2
|
import { getId } from './utils'
|
|
3
|
+
import type { FnLayout, FnType, Constants as C, Int, NodeProps, Struct, StructFactory, StructFields, X, Y } from './types'
|
|
15
4
|
|
|
16
5
|
let scope: X | null = null
|
|
17
6
|
let define: X | null = null
|
|
18
7
|
|
|
19
8
|
export const addToScope = <T extends C>(x: X<T>) => {
|
|
20
|
-
if (!scope) return
|
|
9
|
+
if (!scope) return x
|
|
21
10
|
if (!scope.props.children) scope.props.children = []
|
|
22
11
|
scope.props.children.push(x)
|
|
23
12
|
if (x.type !== 'return' || !define) return x
|
|
@@ -133,8 +122,7 @@ export function Fn<T extends X | Struct | void, Args extends any[]>(fun: (args:
|
|
|
133
122
|
else
|
|
134
123
|
paramDefs.push({
|
|
135
124
|
id: input.name,
|
|
136
|
-
inferFrom:
|
|
137
|
-
input.type === 'auto' ? [args[i]] : [conversion(input.type, args[i])],
|
|
125
|
+
inferFrom: input.type === 'auto' ? [args[i]] : [conversion(input.type, args[i])],
|
|
138
126
|
})
|
|
139
127
|
}
|
|
140
128
|
for (const props of paramDefs) paramVars.push(create('variable', props))
|
package/src/node/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { CONSTANTS, CONVERSIONS, FUNCTIONS, OPERATOR_KEYS, OPERATOR_TYPE_RULES } from './utils/const'
|
|
1
|
+
import { CONSTANTS, CONVERSIONS, FUNCTIONS, OPERATOR_KEYS, OPERATOR_TYPE_RULES, SWIZZLE_BASE_MAP, SWIZZLE_RESULT_MAP } from './utils/const'
|
|
2
2
|
import type { GL } from '../types'
|
|
3
|
-
import type { Binding } from '../webgpu/utils'
|
|
4
3
|
|
|
5
4
|
export type Constants = (typeof CONSTANTS)[number] | 'void'
|
|
6
5
|
export type Conversions = (typeof CONVERSIONS)[number]
|
|
@@ -12,7 +11,7 @@ export type Operators = (typeof OPERATOR_KEYS)[number]
|
|
|
12
11
|
*/
|
|
13
12
|
export interface FnLayout {
|
|
14
13
|
name: string
|
|
15
|
-
type
|
|
14
|
+
type?: C | 'auto'
|
|
16
15
|
inputs?: Array<{
|
|
17
16
|
name: string
|
|
18
17
|
type: C | 'auto'
|
|
@@ -81,7 +80,6 @@ export interface NodeProps {
|
|
|
81
80
|
|
|
82
81
|
export interface NodeContext {
|
|
83
82
|
gl?: Partial<GL>
|
|
84
|
-
binding?: Binding
|
|
85
83
|
label?: 'vert' | 'frag' | 'compute'
|
|
86
84
|
isWebGL?: boolean
|
|
87
85
|
units?: any // @TODO FIX
|
|
@@ -99,6 +97,24 @@ export interface NodeContext {
|
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
|
|
100
|
+
/**
|
|
101
|
+
* swizzle
|
|
102
|
+
*/
|
|
103
|
+
// Optimized string length using direct pattern matching
|
|
104
|
+
// prettier-ignore
|
|
105
|
+
type _SwizzleLength<A extends string> =
|
|
106
|
+
A extends `${infer _}${infer A}` ? A extends '' ? 1 :
|
|
107
|
+
A extends `${infer _}${infer B}` ? B extends '' ? 2 :
|
|
108
|
+
B extends `${infer _}${infer C}` ? C extends '' ? 3 :
|
|
109
|
+
4 : never : never : never
|
|
110
|
+
|
|
111
|
+
// Unified logic with infer.ts inferSwizzleType
|
|
112
|
+
type _SwizzleBaseMap = typeof SWIZZLE_BASE_MAP
|
|
113
|
+
type _SwizzleResultMap = typeof SWIZZLE_RESULT_MAP
|
|
114
|
+
type _SwizzleBase<T extends C> = T extends keyof _SwizzleBaseMap ? _SwizzleBaseMap[T] : never
|
|
115
|
+
type _SwizzleResult<T extends C, L extends 1 | 2 | 3 | 4> = _SwizzleResultMap[_SwizzleBase<T>][L]
|
|
116
|
+
type InferSwizzleType<T extends C, S extends string> = _SwizzleLength<S> extends infer L extends 1 | 2 | 3 | 4 ? _SwizzleResult<_SwizzleBase<T>, L> : never
|
|
117
|
+
|
|
102
118
|
/**
|
|
103
119
|
* infer
|
|
104
120
|
*/
|
|
@@ -132,47 +148,6 @@ type OperatorTypeRules = ExtractPairs<_OperatorTypeRulesMap[number]>
|
|
|
132
148
|
type IsInRules<L extends C, R extends C> = [L, R] extends OperatorTypeRules ? 1 : 0
|
|
133
149
|
type ValidateOperator<L extends C, R extends C> = L extends R ? 1 : IsInRules<L, R>
|
|
134
150
|
|
|
135
|
-
/**
|
|
136
|
-
* swizzle
|
|
137
|
-
*/
|
|
138
|
-
// Optimized string length using direct pattern matching
|
|
139
|
-
// prettier-ignore
|
|
140
|
-
type _SwizzleLength<A extends string> =
|
|
141
|
-
A extends `${infer _}${infer A}` ? A extends '' ? 1 :
|
|
142
|
-
A extends `${infer _}${infer B}` ? B extends '' ? 2 :
|
|
143
|
-
B extends `${infer _}${infer C}` ? C extends '' ? 3 :
|
|
144
|
-
4 : never : never : never
|
|
145
|
-
|
|
146
|
-
type _SwizzleBaseMap = {
|
|
147
|
-
float: 'float'
|
|
148
|
-
vec2: 'float'
|
|
149
|
-
vec3: 'float'
|
|
150
|
-
vec4: 'float'
|
|
151
|
-
int: 'int'
|
|
152
|
-
ivec2: 'int'
|
|
153
|
-
ivec3: 'int'
|
|
154
|
-
ivec4: 'int'
|
|
155
|
-
uint: 'uint'
|
|
156
|
-
uvec2: 'uint'
|
|
157
|
-
uvec3: 'uint'
|
|
158
|
-
uvec4: 'uint'
|
|
159
|
-
bool: 'bool'
|
|
160
|
-
bvec2: 'bool'
|
|
161
|
-
bvec3: 'bool'
|
|
162
|
-
bvec4: 'bool'
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
type _SwizzleResultMap = {
|
|
166
|
-
float: { 1: 'float'; 2: 'vec2'; 3: 'vec3'; 4: 'vec4' }
|
|
167
|
-
int: { 1: 'int'; 2: 'ivec2'; 3: 'ivec3'; 4: 'ivec4' }
|
|
168
|
-
uint: { 1: 'uint'; 2: 'uvec2'; 3: 'uvec3'; 4: 'uvec4' }
|
|
169
|
-
bool: { 1: 'bool'; 2: 'bvec2'; 3: 'bvec3'; 4: 'bvec4' }
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
type _SwizzleBase<T extends C> = T extends keyof _SwizzleBaseMap ? _SwizzleBaseMap[T] : never
|
|
173
|
-
type _SwizzleResult<T extends C, L extends 1 | 2 | 3 | 4> = _SwizzleResultMap[_SwizzleBase<T>][L]
|
|
174
|
-
type InferSwizzleType<T extends C, S extends string> = _SwizzleLength<S> extends infer L extends 1 | 2 | 3 | 4 ? _SwizzleResult<_SwizzleBase<T>, L> : never
|
|
175
|
-
|
|
176
151
|
/**
|
|
177
152
|
* Swizzles
|
|
178
153
|
*/
|