@luma.gl/shadertools 9.3.0-alpha.4 → 9.3.0-alpha.8
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/dist/dist.dev.js +4657 -523
- package/dist/dist.min.js +1952 -301
- package/dist/index.cjs +2804 -406
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
- package/dist/lib/preprocessor/preprocessor.js +35 -8
- package/dist/lib/preprocessor/preprocessor.js.map +1 -1
- package/dist/lib/shader-assembler.d.ts +10 -0
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +20 -3
- package/dist/lib/shader-assembler.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +211 -11
- package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js +140 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js +3 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
- package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
- package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
- package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +22 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js +112 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
- package/dist/lib/shader-module/shader-module.d.ts +12 -6
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js.map +1 -1
- package/dist/lib/utils/uniform-types.d.ts +11 -7
- package/dist/lib/utils/uniform-types.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.d.ts +3 -0
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +3 -0
- package/dist/modules/engine/picking/picking.js.map +1 -1
- package/dist/modules/engine/skin/skin.d.ts +30 -0
- package/dist/modules/engine/skin/skin.d.ts.map +1 -0
- package/dist/modules/engine/skin/skin.js +86 -0
- package/dist/modules/engine/skin/skin.js.map +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
- package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
- package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
- package/dist/modules/lighting/ibl/ibl.js +33 -0
- package/dist/modules/lighting/ibl/ibl.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
- package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
- package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
- package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.js +43 -37
- package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.js +46 -18
- package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +104 -62
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +107 -68
- package/dist/modules/lighting/lights/lighting.js.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.d.ts +7 -2
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +3 -1
- package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +524 -28
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +784 -101
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +110 -45
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +85 -9
- package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js +13 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +4 -0
- package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +15 -4
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +41 -10
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
- package/dist/modules/math/fp64/fp64.d.ts +1 -0
- package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64.js +8 -2
- package/dist/modules/math/fp64/fp64.js.map +1 -1
- package/dist/modules/math/random/random.d.ts +1 -1
- package/dist/modules/math/random/random.d.ts.map +1 -1
- package/dist/modules/math/random/random.js +2 -3
- package/dist/modules/math/random/random.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +20 -2
- package/src/lib/preprocessor/preprocessor.ts +44 -8
- package/src/lib/shader-assembler.ts +25 -3
- package/src/lib/shader-assembly/assemble-shaders.ts +377 -12
- package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
- package/src/lib/shader-generator/glsl/generate-glsl.ts +7 -1
- package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
- package/src/lib/shader-module/shader-module-uniform-layout.ts +194 -0
- package/src/lib/shader-module/shader-module.ts +17 -7
- package/src/lib/utils/uniform-types.ts +24 -9
- package/src/modules/engine/picking/picking.ts +3 -0
- package/src/modules/engine/skin/skin.ts +114 -0
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
- package/src/modules/lighting/ibl/ibl.ts +44 -0
- package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
- package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
- package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
- package/src/modules/lighting/lights/lighting-glsl.ts +43 -37
- package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
- package/src/modules/lighting/lights/lighting.ts +198 -99
- package/src/modules/lighting/no-material/dirlight.ts +3 -1
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +524 -28
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +784 -101
- package/src/modules/lighting/pbr-material/pbr-material.ts +111 -18
- package/src/modules/lighting/pbr-material/pbr-projection.ts +14 -1
- package/src/modules/lighting/phong-material/phong-material.ts +5 -0
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +15 -4
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
- package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +41 -10
- package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
- package/src/modules/math/fp64/fp64.ts +9 -3
- package/src/modules/math/random/random.ts +2 -3
|
@@ -5,6 +5,7 @@ export const fp64arithmeticShader = /* glsl */ `\
|
|
|
5
5
|
|
|
6
6
|
uniform fp64arithmeticUniforms {
|
|
7
7
|
uniform float ONE;
|
|
8
|
+
uniform float SPLIT;
|
|
8
9
|
} fp64;
|
|
9
10
|
|
|
10
11
|
/*
|
|
@@ -14,6 +15,12 @@ The purpose of this workaround is to prevent shader compilers from
|
|
|
14
15
|
optimizing away necessary arithmetic operations by swapping their sequences
|
|
15
16
|
or transform the equation to some 'equivalent' form.
|
|
16
17
|
|
|
18
|
+
These helpers implement Dekker/Veltkamp-style error tracking. If the compiler
|
|
19
|
+
folds constants or reassociates the arithmetic, the high/low split can stop
|
|
20
|
+
tracking the rounding error correctly. That failure mode tends to look fine in
|
|
21
|
+
simple coordinate setup, but then breaks down inside iterative arithmetic such
|
|
22
|
+
as fp64 Mandelbrot loops.
|
|
23
|
+
|
|
17
24
|
The method is to multiply an artifical variable, ONE, which will be known to
|
|
18
25
|
the compiler to be 1 only at runtime. The whole expression is then represented
|
|
19
26
|
as a polynomial with respective to ONE. In the coefficients of all terms, only one a
|
|
@@ -22,17 +29,23 @@ and one b should appear
|
|
|
22
29
|
err = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE
|
|
23
30
|
*/
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
vec2 split(float a) {
|
|
27
|
-
const float SPLIT = 4097.0;
|
|
28
|
-
float t = a * SPLIT;
|
|
32
|
+
float prevent_fp64_optimization(float value) {
|
|
29
33
|
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
30
|
-
|
|
31
|
-
float a_lo = a * fp64.ONE - a_hi;
|
|
34
|
+
return value + fp64.ONE * 0.0;
|
|
32
35
|
#else
|
|
33
|
-
|
|
34
|
-
float a_lo = a - a_hi;
|
|
36
|
+
return value;
|
|
35
37
|
#endif
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Divide float number to high and low floats to extend fraction bits
|
|
41
|
+
vec2 split(float a) {
|
|
42
|
+
// Keep SPLIT as a runtime uniform so the compiler cannot fold the Dekker
|
|
43
|
+
// split into a constant expression and reassociate the recovery steps.
|
|
44
|
+
float split = prevent_fp64_optimization(fp64.SPLIT);
|
|
45
|
+
float t = prevent_fp64_optimization(a * split);
|
|
46
|
+
float temp = t - a;
|
|
47
|
+
float a_hi = t - temp;
|
|
48
|
+
float a_lo = a - a_hi;
|
|
36
49
|
return vec2(a_hi, a_lo);
|
|
37
50
|
}
|
|
38
51
|
|
|
@@ -96,8 +109,26 @@ vec2 twoProd(float a, float b) {
|
|
|
96
109
|
float prod = a * b;
|
|
97
110
|
vec2 a_fp64 = split(a);
|
|
98
111
|
vec2 b_fp64 = split(b);
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
// twoProd is especially sensitive because mul_fp64 and div_fp64 both depend
|
|
113
|
+
// on the split terms and cross terms staying in the original evaluation
|
|
114
|
+
// order. If the compiler folds or reassociates them, the low part tends to
|
|
115
|
+
// collapse to zero or NaN on some drivers.
|
|
116
|
+
float highProduct = prevent_fp64_optimization(a_fp64.x * b_fp64.x);
|
|
117
|
+
float crossProduct1 = prevent_fp64_optimization(a_fp64.x * b_fp64.y);
|
|
118
|
+
float crossProduct2 = prevent_fp64_optimization(a_fp64.y * b_fp64.x);
|
|
119
|
+
float lowProduct = prevent_fp64_optimization(a_fp64.y * b_fp64.y);
|
|
120
|
+
#if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
|
|
121
|
+
float err1 = (highProduct - prod) * fp64.ONE;
|
|
122
|
+
float err2 = crossProduct1 * fp64.ONE * fp64.ONE;
|
|
123
|
+
float err3 = crossProduct2 * fp64.ONE * fp64.ONE * fp64.ONE;
|
|
124
|
+
float err4 = lowProduct * fp64.ONE * fp64.ONE * fp64.ONE * fp64.ONE;
|
|
125
|
+
#else
|
|
126
|
+
float err1 = highProduct - prod;
|
|
127
|
+
float err2 = crossProduct1;
|
|
128
|
+
float err3 = crossProduct2;
|
|
129
|
+
float err4 = lowProduct;
|
|
130
|
+
#endif
|
|
131
|
+
float err = ((err1 + err2) + err3) + err4;
|
|
101
132
|
return vec2(prod, err);
|
|
102
133
|
}
|
|
103
134
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp64-arithmetic-glsl.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"fp64-arithmetic-glsl.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwM9C,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const fp64arithmeticWGSL = "struct Fp64ArithmeticUniforms {\n ONE: f32,\n SPLIT: f32,\n};\n\n@group(0) @binding(auto) var<uniform> fp64arithmetic : Fp64ArithmeticUniforms;\n\nfn fp64_nan(seed: f32) -> f32 {\n let nanBits = 0x7fc00000u | select(0u, 1u, seed < 0.0);\n return bitcast<f32>(nanBits);\n}\n\nfn fp64_runtime_zero() -> f32 {\n return fp64arithmetic.ONE * 0.0;\n}\n\nfn prevent_fp64_optimization(value: f32) -> f32 {\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n return value + fp64_runtime_zero();\n#else\n return value;\n#endif\n}\n\nfn split(a: f32) -> vec2f {\n let splitValue = prevent_fp64_optimization(fp64arithmetic.SPLIT + fp64_runtime_zero());\n let t = prevent_fp64_optimization(a * splitValue);\n let temp = prevent_fp64_optimization(t - a);\n let aHi = prevent_fp64_optimization(t - temp);\n let aLo = prevent_fp64_optimization(a - aHi);\n return vec2f(aHi, aLo);\n}\n\nfn split2(a: vec2f) -> vec2f {\n var b = split(a.x);\n b.y = b.y + a.y;\n return b;\n}\n\nfn quickTwoSum(a: f32, b: f32) -> vec2f {\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let sum = prevent_fp64_optimization((a + b) * fp64arithmetic.ONE);\n let err = prevent_fp64_optimization(b - (sum - a) * fp64arithmetic.ONE);\n#else\n let sum = prevent_fp64_optimization(a + b);\n let err = prevent_fp64_optimization(b - (sum - a));\n#endif\n return vec2f(sum, err);\n}\n\nfn twoSum(a: f32, b: f32) -> vec2f {\n let s = prevent_fp64_optimization(a + b);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);\n let err =\n prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE) +\n prevent_fp64_optimization(b - v);\n#else\n let v = prevent_fp64_optimization(s - a);\n let err = prevent_fp64_optimization(a - (s - v)) + prevent_fp64_optimization(b - v);\n#endif\n return vec2f(s, err);\n}\n\nfn twoSub(a: f32, b: f32) -> vec2f {\n let s = prevent_fp64_optimization(a - b);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);\n let err =\n prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE) -\n prevent_fp64_optimization(b + v);\n#else\n let v = prevent_fp64_optimization(s - a);\n let err = prevent_fp64_optimization(a - (s - v)) - prevent_fp64_optimization(b + v);\n#endif\n return vec2f(s, err);\n}\n\nfn twoSqr(a: f32) -> vec2f {\n let prod = prevent_fp64_optimization(a * a);\n let aFp64 = split(a);\n let highProduct = prevent_fp64_optimization(aFp64.x * aFp64.x);\n let crossProduct = prevent_fp64_optimization(2.0 * aFp64.x * aFp64.y);\n let lowProduct = prevent_fp64_optimization(aFp64.y * aFp64.y);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let err =\n (prevent_fp64_optimization(highProduct - prod) * fp64arithmetic.ONE +\n crossProduct * fp64arithmetic.ONE * fp64arithmetic.ONE) +\n lowProduct * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;\n#else\n let err = ((prevent_fp64_optimization(highProduct - prod) + crossProduct) + lowProduct);\n#endif\n return vec2f(prod, err);\n}\n\nfn twoProd(a: f32, b: f32) -> vec2f {\n let prod = prevent_fp64_optimization(a * b);\n let aFp64 = split(a);\n let bFp64 = split(b);\n let highProduct = prevent_fp64_optimization(aFp64.x * bFp64.x);\n let crossProduct1 = prevent_fp64_optimization(aFp64.x * bFp64.y);\n let crossProduct2 = prevent_fp64_optimization(aFp64.y * bFp64.x);\n let lowProduct = prevent_fp64_optimization(aFp64.y * bFp64.y);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let err1 = (highProduct - prod) * fp64arithmetic.ONE;\n let err2 = crossProduct1 * fp64arithmetic.ONE * fp64arithmetic.ONE;\n let err3 = crossProduct2 * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;\n let err4 =\n lowProduct *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE *\n fp64arithmetic.ONE;\n#else\n let err1 = highProduct - prod;\n let err2 = crossProduct1;\n let err3 = crossProduct2;\n let err4 = lowProduct;\n#endif\n let err12InputA = prevent_fp64_optimization(err1);\n let err12InputB = prevent_fp64_optimization(err2);\n let err12 = prevent_fp64_optimization(err12InputA + err12InputB);\n let err123InputA = prevent_fp64_optimization(err12);\n let err123InputB = prevent_fp64_optimization(err3);\n let err123 = prevent_fp64_optimization(err123InputA + err123InputB);\n let err1234InputA = prevent_fp64_optimization(err123);\n let err1234InputB = prevent_fp64_optimization(err4);\n let err = prevent_fp64_optimization(err1234InputA + err1234InputB);\n return vec2f(prod, err);\n}\n\nfn sum_fp64(a: vec2f, b: vec2f) -> vec2f {\n var s = twoSum(a.x, b.x);\n let t = twoSum(a.y, b.y);\n s.y = prevent_fp64_optimization(s.y + t.x);\n s = quickTwoSum(s.x, s.y);\n s.y = prevent_fp64_optimization(s.y + t.y);\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nfn sub_fp64(a: vec2f, b: vec2f) -> vec2f {\n var s = twoSub(a.x, b.x);\n let t = twoSub(a.y, b.y);\n s.y = prevent_fp64_optimization(s.y + t.x);\n s = quickTwoSum(s.x, s.y);\n s.y = prevent_fp64_optimization(s.y + t.y);\n s = quickTwoSum(s.x, s.y);\n return s;\n}\n\nfn mul_fp64(a: vec2f, b: vec2f) -> vec2f {\n var prod = twoProd(a.x, b.x);\n let crossProduct1 = prevent_fp64_optimization(a.x * b.y);\n prod.y = prevent_fp64_optimization(prod.y + crossProduct1);\n#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n let crossProduct2 = prevent_fp64_optimization(a.y * b.x);\n prod.y = prevent_fp64_optimization(prod.y + crossProduct2);\n#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND\n prod = split2(prod);\n#endif\n prod = quickTwoSum(prod.x, prod.y);\n return prod;\n}\n\nfn div_fp64(a: vec2f, b: vec2f) -> vec2f {\n let xn = prevent_fp64_optimization(1.0 / b.x);\n let yn = mul_fp64(a, vec2f(xn, fp64_runtime_zero()));\n let diff = prevent_fp64_optimization(sub_fp64(a, mul_fp64(b, yn)).x);\n let prod = twoProd(xn, diff);\n return sum_fp64(yn, prod);\n}\n\nfn sqrt_fp64(a: vec2f) -> vec2f {\n if (a.x == 0.0 && a.y == 0.0) {\n return vec2f(0.0, 0.0);\n }\n if (a.x < 0.0) {\n let nanValue = fp64_nan(a.x);\n return vec2f(nanValue, nanValue);\n }\n\n let x = prevent_fp64_optimization(1.0 / sqrt(a.x));\n let yn = prevent_fp64_optimization(a.x * x);\n#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND\n let ynSqr = twoSqr(yn) * fp64arithmetic.ONE;\n#else\n let ynSqr = twoSqr(yn);\n#endif\n let diff = prevent_fp64_optimization(sub_fp64(a, ynSqr).x);\n let prod = twoProd(prevent_fp64_optimization(x * 0.5), diff);\n#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND\n return sum_fp64(split(yn), prod);\n#else\n return sum_fp64(vec2f(yn, 0.0), prod);\n#endif\n}\n";
|
|
2
|
+
//# sourceMappingURL=fp64-arithmetic-wgsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fp64-arithmetic-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,yyNA+M9B,CAAC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export const fp64arithmeticWGSL = /* wgsl */ `\
|
|
5
|
+
struct Fp64ArithmeticUniforms {
|
|
6
|
+
ONE: f32,
|
|
7
|
+
SPLIT: f32,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
@group(0) @binding(auto) var<uniform> fp64arithmetic : Fp64ArithmeticUniforms;
|
|
11
|
+
|
|
12
|
+
fn fp64_nan(seed: f32) -> f32 {
|
|
13
|
+
let nanBits = 0x7fc00000u | select(0u, 1u, seed < 0.0);
|
|
14
|
+
return bitcast<f32>(nanBits);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fn fp64_runtime_zero() -> f32 {
|
|
18
|
+
return fp64arithmetic.ONE * 0.0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fn prevent_fp64_optimization(value: f32) -> f32 {
|
|
22
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
23
|
+
return value + fp64_runtime_zero();
|
|
24
|
+
#else
|
|
25
|
+
return value;
|
|
26
|
+
#endif
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fn split(a: f32) -> vec2f {
|
|
30
|
+
let splitValue = prevent_fp64_optimization(fp64arithmetic.SPLIT + fp64_runtime_zero());
|
|
31
|
+
let t = prevent_fp64_optimization(a * splitValue);
|
|
32
|
+
let temp = prevent_fp64_optimization(t - a);
|
|
33
|
+
let aHi = prevent_fp64_optimization(t - temp);
|
|
34
|
+
let aLo = prevent_fp64_optimization(a - aHi);
|
|
35
|
+
return vec2f(aHi, aLo);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fn split2(a: vec2f) -> vec2f {
|
|
39
|
+
var b = split(a.x);
|
|
40
|
+
b.y = b.y + a.y;
|
|
41
|
+
return b;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn quickTwoSum(a: f32, b: f32) -> vec2f {
|
|
45
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
46
|
+
let sum = prevent_fp64_optimization((a + b) * fp64arithmetic.ONE);
|
|
47
|
+
let err = prevent_fp64_optimization(b - (sum - a) * fp64arithmetic.ONE);
|
|
48
|
+
#else
|
|
49
|
+
let sum = prevent_fp64_optimization(a + b);
|
|
50
|
+
let err = prevent_fp64_optimization(b - (sum - a));
|
|
51
|
+
#endif
|
|
52
|
+
return vec2f(sum, err);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fn twoSum(a: f32, b: f32) -> vec2f {
|
|
56
|
+
let s = prevent_fp64_optimization(a + b);
|
|
57
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
58
|
+
let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
|
|
59
|
+
let err =
|
|
60
|
+
prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
|
|
61
|
+
fp64arithmetic.ONE *
|
|
62
|
+
fp64arithmetic.ONE *
|
|
63
|
+
fp64arithmetic.ONE) +
|
|
64
|
+
prevent_fp64_optimization(b - v);
|
|
65
|
+
#else
|
|
66
|
+
let v = prevent_fp64_optimization(s - a);
|
|
67
|
+
let err = prevent_fp64_optimization(a - (s - v)) + prevent_fp64_optimization(b - v);
|
|
68
|
+
#endif
|
|
69
|
+
return vec2f(s, err);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fn twoSub(a: f32, b: f32) -> vec2f {
|
|
73
|
+
let s = prevent_fp64_optimization(a - b);
|
|
74
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
75
|
+
let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
|
|
76
|
+
let err =
|
|
77
|
+
prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
|
|
78
|
+
fp64arithmetic.ONE *
|
|
79
|
+
fp64arithmetic.ONE *
|
|
80
|
+
fp64arithmetic.ONE) -
|
|
81
|
+
prevent_fp64_optimization(b + v);
|
|
82
|
+
#else
|
|
83
|
+
let v = prevent_fp64_optimization(s - a);
|
|
84
|
+
let err = prevent_fp64_optimization(a - (s - v)) - prevent_fp64_optimization(b + v);
|
|
85
|
+
#endif
|
|
86
|
+
return vec2f(s, err);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fn twoSqr(a: f32) -> vec2f {
|
|
90
|
+
let prod = prevent_fp64_optimization(a * a);
|
|
91
|
+
let aFp64 = split(a);
|
|
92
|
+
let highProduct = prevent_fp64_optimization(aFp64.x * aFp64.x);
|
|
93
|
+
let crossProduct = prevent_fp64_optimization(2.0 * aFp64.x * aFp64.y);
|
|
94
|
+
let lowProduct = prevent_fp64_optimization(aFp64.y * aFp64.y);
|
|
95
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
96
|
+
let err =
|
|
97
|
+
(prevent_fp64_optimization(highProduct - prod) * fp64arithmetic.ONE +
|
|
98
|
+
crossProduct * fp64arithmetic.ONE * fp64arithmetic.ONE) +
|
|
99
|
+
lowProduct * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
|
|
100
|
+
#else
|
|
101
|
+
let err = ((prevent_fp64_optimization(highProduct - prod) + crossProduct) + lowProduct);
|
|
102
|
+
#endif
|
|
103
|
+
return vec2f(prod, err);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn twoProd(a: f32, b: f32) -> vec2f {
|
|
107
|
+
let prod = prevent_fp64_optimization(a * b);
|
|
108
|
+
let aFp64 = split(a);
|
|
109
|
+
let bFp64 = split(b);
|
|
110
|
+
let highProduct = prevent_fp64_optimization(aFp64.x * bFp64.x);
|
|
111
|
+
let crossProduct1 = prevent_fp64_optimization(aFp64.x * bFp64.y);
|
|
112
|
+
let crossProduct2 = prevent_fp64_optimization(aFp64.y * bFp64.x);
|
|
113
|
+
let lowProduct = prevent_fp64_optimization(aFp64.y * bFp64.y);
|
|
114
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
115
|
+
let err1 = (highProduct - prod) * fp64arithmetic.ONE;
|
|
116
|
+
let err2 = crossProduct1 * fp64arithmetic.ONE * fp64arithmetic.ONE;
|
|
117
|
+
let err3 = crossProduct2 * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
|
|
118
|
+
let err4 =
|
|
119
|
+
lowProduct *
|
|
120
|
+
fp64arithmetic.ONE *
|
|
121
|
+
fp64arithmetic.ONE *
|
|
122
|
+
fp64arithmetic.ONE *
|
|
123
|
+
fp64arithmetic.ONE;
|
|
124
|
+
#else
|
|
125
|
+
let err1 = highProduct - prod;
|
|
126
|
+
let err2 = crossProduct1;
|
|
127
|
+
let err3 = crossProduct2;
|
|
128
|
+
let err4 = lowProduct;
|
|
129
|
+
#endif
|
|
130
|
+
let err12InputA = prevent_fp64_optimization(err1);
|
|
131
|
+
let err12InputB = prevent_fp64_optimization(err2);
|
|
132
|
+
let err12 = prevent_fp64_optimization(err12InputA + err12InputB);
|
|
133
|
+
let err123InputA = prevent_fp64_optimization(err12);
|
|
134
|
+
let err123InputB = prevent_fp64_optimization(err3);
|
|
135
|
+
let err123 = prevent_fp64_optimization(err123InputA + err123InputB);
|
|
136
|
+
let err1234InputA = prevent_fp64_optimization(err123);
|
|
137
|
+
let err1234InputB = prevent_fp64_optimization(err4);
|
|
138
|
+
let err = prevent_fp64_optimization(err1234InputA + err1234InputB);
|
|
139
|
+
return vec2f(prod, err);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
fn sum_fp64(a: vec2f, b: vec2f) -> vec2f {
|
|
143
|
+
var s = twoSum(a.x, b.x);
|
|
144
|
+
let t = twoSum(a.y, b.y);
|
|
145
|
+
s.y = prevent_fp64_optimization(s.y + t.x);
|
|
146
|
+
s = quickTwoSum(s.x, s.y);
|
|
147
|
+
s.y = prevent_fp64_optimization(s.y + t.y);
|
|
148
|
+
s = quickTwoSum(s.x, s.y);
|
|
149
|
+
return s;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
fn sub_fp64(a: vec2f, b: vec2f) -> vec2f {
|
|
153
|
+
var s = twoSub(a.x, b.x);
|
|
154
|
+
let t = twoSub(a.y, b.y);
|
|
155
|
+
s.y = prevent_fp64_optimization(s.y + t.x);
|
|
156
|
+
s = quickTwoSum(s.x, s.y);
|
|
157
|
+
s.y = prevent_fp64_optimization(s.y + t.y);
|
|
158
|
+
s = quickTwoSum(s.x, s.y);
|
|
159
|
+
return s;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fn mul_fp64(a: vec2f, b: vec2f) -> vec2f {
|
|
163
|
+
var prod = twoProd(a.x, b.x);
|
|
164
|
+
let crossProduct1 = prevent_fp64_optimization(a.x * b.y);
|
|
165
|
+
prod.y = prevent_fp64_optimization(prod.y + crossProduct1);
|
|
166
|
+
#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
|
|
167
|
+
prod = split2(prod);
|
|
168
|
+
#endif
|
|
169
|
+
prod = quickTwoSum(prod.x, prod.y);
|
|
170
|
+
let crossProduct2 = prevent_fp64_optimization(a.y * b.x);
|
|
171
|
+
prod.y = prevent_fp64_optimization(prod.y + crossProduct2);
|
|
172
|
+
#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
|
|
173
|
+
prod = split2(prod);
|
|
174
|
+
#endif
|
|
175
|
+
prod = quickTwoSum(prod.x, prod.y);
|
|
176
|
+
return prod;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
fn div_fp64(a: vec2f, b: vec2f) -> vec2f {
|
|
180
|
+
let xn = prevent_fp64_optimization(1.0 / b.x);
|
|
181
|
+
let yn = mul_fp64(a, vec2f(xn, fp64_runtime_zero()));
|
|
182
|
+
let diff = prevent_fp64_optimization(sub_fp64(a, mul_fp64(b, yn)).x);
|
|
183
|
+
let prod = twoProd(xn, diff);
|
|
184
|
+
return sum_fp64(yn, prod);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
fn sqrt_fp64(a: vec2f) -> vec2f {
|
|
188
|
+
if (a.x == 0.0 && a.y == 0.0) {
|
|
189
|
+
return vec2f(0.0, 0.0);
|
|
190
|
+
}
|
|
191
|
+
if (a.x < 0.0) {
|
|
192
|
+
let nanValue = fp64_nan(a.x);
|
|
193
|
+
return vec2f(nanValue, nanValue);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let x = prevent_fp64_optimization(1.0 / sqrt(a.x));
|
|
197
|
+
let yn = prevent_fp64_optimization(a.x * x);
|
|
198
|
+
#ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
199
|
+
let ynSqr = twoSqr(yn) * fp64arithmetic.ONE;
|
|
200
|
+
#else
|
|
201
|
+
let ynSqr = twoSqr(yn);
|
|
202
|
+
#endif
|
|
203
|
+
let diff = prevent_fp64_optimization(sub_fp64(a, ynSqr).x);
|
|
204
|
+
let prod = twoProd(prevent_fp64_optimization(x * 0.5), diff);
|
|
205
|
+
#ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
|
|
206
|
+
return sum_fp64(split(yn), prod);
|
|
207
|
+
#else
|
|
208
|
+
return sum_fp64(vec2f(yn, 0.0), prod);
|
|
209
|
+
#endif
|
|
210
|
+
}
|
|
211
|
+
`;
|
|
212
|
+
//# sourceMappingURL=fp64-arithmetic-wgsl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fp64-arithmetic-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64-arithmetic-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+M5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp64.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;
|
|
1
|
+
{"version":3,"file":"fp64.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAK3F,KAAK,SAAS,GAAG,EAAE,CAAC;AACpB,KAAK,YAAY,GAAG;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC;AACjD,KAAK,YAAY,GAAG,EAAE,CAAC;AAEvB,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,WAAW,CAAC;IAChC,cAAc,EAAE,OAAO,cAAc,CAAC;CACvC,CAAC;AAUF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,SAAS,EAAE,YAAY,EAAE,YAAY,CAAC,GAAG,aAYlF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,aASrC,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,CAAC"}
|
|
@@ -3,19 +3,25 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { fp64ify, fp64LowPart, fp64ifyMatrix4 } from "../../../modules/math/fp64/fp64-utils.js";
|
|
5
5
|
import { fp64arithmeticShader } from "./fp64-arithmetic-glsl.js";
|
|
6
|
+
import { fp64arithmeticWGSL } from "./fp64-arithmetic-wgsl.js";
|
|
6
7
|
import { fp64functionShader } from "./fp64-functions-glsl.js";
|
|
7
8
|
const defaultUniforms = {
|
|
8
9
|
// Used in LUMA_FP64_CODE_ELIMINATION_WORKAROUND
|
|
9
|
-
ONE: 1.0
|
|
10
|
+
ONE: 1.0,
|
|
11
|
+
// Runtime split factor for Dekker splitting. Keeping this as a uniform helps
|
|
12
|
+
// prevent aggressive constant folding in shader compilers.
|
|
13
|
+
SPLIT: 4097.0
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
12
16
|
* 64bit arithmetic: add, sub, mul, div (small subset of fp64 module)
|
|
13
17
|
*/
|
|
14
18
|
export const fp64arithmetic = {
|
|
15
19
|
name: 'fp64arithmetic',
|
|
20
|
+
source: fp64arithmeticWGSL,
|
|
21
|
+
fs: fp64arithmeticShader,
|
|
16
22
|
vs: fp64arithmeticShader,
|
|
17
23
|
defaultUniforms,
|
|
18
|
-
uniformTypes: { ONE: 'f32' },
|
|
24
|
+
uniformTypes: { ONE: 'f32', SPLIT: 'f32' },
|
|
19
25
|
// Additional Functions
|
|
20
26
|
fp64ify,
|
|
21
27
|
fp64LowPart,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fp64.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAC3F,OAAO,EAAC,oBAAoB,EAAC,kCAA+B;AAC5D,OAAO,EAAC,kBAAkB,EAAC,iCAA8B;AAYzD,MAAM,eAAe,GAAiB;IACpC,gDAAgD;IAChD,GAAG,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"fp64.js","sourceRoot":"","sources":["../../../../src/modules/math/fp64/fp64.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,iDAA8C;AAC3F,OAAO,EAAC,oBAAoB,EAAC,kCAA+B;AAC5D,OAAO,EAAC,kBAAkB,EAAC,kCAA+B;AAC1D,OAAO,EAAC,kBAAkB,EAAC,iCAA8B;AAYzD,MAAM,eAAe,GAAiB;IACpC,gDAAgD;IAChD,GAAG,EAAE,GAAG;IACR,6EAA6E;IAC7E,2DAA2D;IAC3D,KAAK,EAAE,MAAM;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAwE;IACjG,IAAI,EAAE,gBAAgB;IACtB,MAAM,EAAE,kBAAkB;IAC1B,EAAE,EAAE,oBAAoB;IACxB,EAAE,EAAE,oBAAoB;IACxB,eAAe;IACf,YAAY,EAAE,EAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC;IAExC,uBAAuB;IACvB,OAAO;IACP,WAAW;IACX,cAAc;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAqC;IACpD,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,kBAAkB;IACtB,YAAY,EAAE,CAAC,cAAc,CAAC;IAE9B,uBAAuB;IACvB,OAAO;IACP,WAAW;IACX,cAAc;CACf,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Quick random generator for fragment shaders */
|
|
2
2
|
export declare const random: {
|
|
3
3
|
readonly name: "random";
|
|
4
|
-
readonly source: "fn random(scale: vec3f, seed:
|
|
4
|
+
readonly source: "fn random(scale: vec3f, seed: f32) -> f32 {\n return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);\n}\n";
|
|
5
5
|
readonly fs: "float random(vec3 scale, float seed) {\n /* use the fragment position for a different seed per-pixel */\n return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);\n}\n";
|
|
6
6
|
};
|
|
7
7
|
//# sourceMappingURL=random.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAmBA,kDAAkD;AAClD,eAAO,MAAM,MAAM;;;;CAIsB,CAAC"}
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
const source = /* wgsl */ `\
|
|
5
|
-
fn random(scale: vec3f, seed:
|
|
6
|
-
|
|
7
|
-
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
5
|
+
fn random(scale: vec3f, seed: f32) -> f32 {
|
|
6
|
+
return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
|
|
8
7
|
}
|
|
9
8
|
`;
|
|
10
9
|
const fs = /* glsl */ `\
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,MAAM,MAAM,GAAG,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../src/modules/math/random/random.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,MAAM,MAAM,GAAG,UAAU,CAAC;;;;CAIzB,CAAC;AAEF,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;CAKrB,CAAC;AAEF,kDAAkD;AAClD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,MAAM;IACN,EAAE;CACqC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.3.0-alpha.
|
|
3
|
+
"version": "9.3.0-alpha.8",
|
|
4
4
|
"description": "Shader module system for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@luma.gl/core": "9.
|
|
49
|
+
"@luma.gl/core": "9.3.0-alpha.6"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@math.gl/core": "^4.1.0",
|
|
53
53
|
"@math.gl/types": "^4.1.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "371f0979c1cd01563badc36118f314365a66e1a1"
|
|
56
56
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,17 +9,28 @@
|
|
|
9
9
|
* Install https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
|
|
10
10
|
*/
|
|
11
11
|
export type {PlatformInfo} from './lib/shader-assembly/platform-info';
|
|
12
|
+
export type {ShaderBindingDebugRow} from './lib/shader-assembly/wgsl-binding-debug';
|
|
12
13
|
|
|
13
14
|
// ShaderModules
|
|
14
15
|
|
|
15
16
|
export type {ShaderModule} from './lib/shader-module/shader-module';
|
|
16
17
|
export type {ShaderPass} from './lib/shader-module/shader-pass';
|
|
17
|
-
export type {UniformTypes} from './lib/utils/uniform-types';
|
|
18
|
+
export type {ShaderModuleUniformValue, UniformTypes} from './lib/utils/uniform-types';
|
|
18
19
|
|
|
19
20
|
export {initializeShaderModule, initializeShaderModules} from './lib/shader-module/shader-module';
|
|
20
21
|
export {getShaderModuleUniforms} from './lib/shader-module/shader-module';
|
|
21
22
|
export {getShaderModuleDependencies} from './lib/shader-module/shader-module-dependencies';
|
|
22
23
|
export {checkShaderModuleDeprecations} from './lib/shader-module/shader-module';
|
|
24
|
+
export type {
|
|
25
|
+
ShaderModuleUniformLayoutStage,
|
|
26
|
+
ShaderModuleUniformLayoutValidationResult
|
|
27
|
+
} from './lib/shader-module/shader-module-uniform-layout';
|
|
28
|
+
export {
|
|
29
|
+
getShaderModuleUniformBlockFields,
|
|
30
|
+
getShaderModuleUniformBlockName,
|
|
31
|
+
getShaderModuleUniformLayoutValidationResult,
|
|
32
|
+
validateShaderModuleUniformLayout
|
|
33
|
+
} from './lib/shader-module/shader-module-uniform-layout';
|
|
23
34
|
|
|
24
35
|
export {getShaderModuleSource} from './lib/shader-assembly/assemble-shaders';
|
|
25
36
|
|
|
@@ -70,18 +81,25 @@ export {fp64, fp64arithmetic} from './modules/math/fp64/fp64';
|
|
|
70
81
|
// export {projection} from './modules/engine/project/project';
|
|
71
82
|
export type {PickingProps, PickingUniforms} from './modules/engine/picking/picking';
|
|
72
83
|
export {picking} from './modules/engine/picking/picking';
|
|
84
|
+
export {skin} from './modules/engine/skin/skin';
|
|
73
85
|
|
|
74
86
|
// lighting
|
|
75
87
|
export {
|
|
76
88
|
type Light,
|
|
77
89
|
type AmbientLight,
|
|
78
90
|
type PointLight,
|
|
79
|
-
type
|
|
91
|
+
type SpotLight,
|
|
92
|
+
type DirectionalLight,
|
|
93
|
+
type LightingLightUniform
|
|
80
94
|
} from './modules/lighting/lights/lighting';
|
|
81
95
|
|
|
82
96
|
export type {LightingProps, LightingUniforms} from './modules/lighting/lights/lighting';
|
|
83
97
|
export {lighting} from './modules/lighting/lights/lighting';
|
|
98
|
+
export type {IBLBindings} from './modules/lighting/ibl/ibl';
|
|
99
|
+
export {ibl} from './modules/lighting/ibl/ibl';
|
|
84
100
|
export {dirlight} from './modules/lighting/no-material/dirlight';
|
|
101
|
+
export type {LambertMaterialProps} from './modules/lighting/lambert-material/lambert-material';
|
|
102
|
+
export {lambertMaterial} from './modules/lighting/lambert-material/lambert-material';
|
|
85
103
|
export type {GouraudMaterialProps} from './modules/lighting/gouraud-material/gouraud-material';
|
|
86
104
|
export {gouraudMaterial} from './modules/lighting/gouraud-material/gouraud-material';
|
|
87
105
|
export type {PhongMaterialProps} from './modules/lighting/phong-material/phong-material';
|
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const DEFINE_NAME_PATTERN = '([a-zA-Z_][a-zA-Z0-9_]*)';
|
|
6
|
+
const IFDEF_REGEXP = new RegExp(`^\\s*\\#\\s*ifdef\\s*${DEFINE_NAME_PATTERN}\\s*$`);
|
|
7
|
+
const IFNDEF_REGEXP = new RegExp(`^\\s*\\#\\s*ifndef\\s*${DEFINE_NAME_PATTERN}\\s*(?:\\/\\/.*)?$`);
|
|
8
|
+
const ELSE_REGEXP = /^\s*\#\s*else\s*(?:\/\/.*)?$/;
|
|
6
9
|
const ENDIF_REGEXP = /^\s*\#\s*endif\s*$/;
|
|
10
|
+
const IFDEF_WITH_COMMENT_REGEXP = new RegExp(
|
|
11
|
+
`^\\s*\\#\\s*ifdef\\s*${DEFINE_NAME_PATTERN}\\s*(?:\\/\\/.*)?$`
|
|
12
|
+
);
|
|
13
|
+
const ENDIF_WITH_COMMENT_REGEXP = /^\s*\#\s*endif\s*(?:\/\/.*)?$/;
|
|
7
14
|
|
|
8
15
|
export type PreprocessorOptions = {
|
|
9
16
|
defines?: Record<string, boolean>;
|
|
@@ -13,19 +20,48 @@ export function preprocess(source: string, options?: PreprocessorOptions): strin
|
|
|
13
20
|
const lines = source.split('\n');
|
|
14
21
|
const output: string[] = [];
|
|
15
22
|
|
|
23
|
+
const conditionalStack: Array<{
|
|
24
|
+
parentActive: boolean;
|
|
25
|
+
branchTaken: boolean;
|
|
26
|
+
active: boolean;
|
|
27
|
+
}> = [];
|
|
16
28
|
let conditional = true;
|
|
17
|
-
|
|
29
|
+
|
|
18
30
|
for (const line of lines) {
|
|
19
|
-
const matchIf = line.match(IFDEF_REGEXP);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
const matchIf = line.match(IFDEF_WITH_COMMENT_REGEXP) || line.match(IFDEF_REGEXP);
|
|
32
|
+
const matchIfNot = line.match(IFNDEF_REGEXP);
|
|
33
|
+
const matchElse = line.match(ELSE_REGEXP);
|
|
34
|
+
const matchEnd = line.match(ENDIF_WITH_COMMENT_REGEXP) || line.match(ENDIF_REGEXP);
|
|
35
|
+
|
|
36
|
+
if (matchIf || matchIfNot) {
|
|
37
|
+
const defineName = (matchIf || matchIfNot)?.[1];
|
|
38
|
+
const defineValue: boolean = Boolean(options?.defines?.[defineName!]);
|
|
39
|
+
const branchTaken: boolean = matchIf ? defineValue : !defineValue;
|
|
40
|
+
const active: boolean = conditional && branchTaken;
|
|
41
|
+
conditionalStack.push({parentActive: conditional, branchTaken, active});
|
|
42
|
+
conditional = active;
|
|
43
|
+
} else if (matchElse) {
|
|
44
|
+
const currentConditional = conditionalStack[conditionalStack.length - 1];
|
|
45
|
+
if (!currentConditional) {
|
|
46
|
+
throw new Error('Encountered #else without matching #ifdef or #ifndef');
|
|
47
|
+
}
|
|
48
|
+
currentConditional.active =
|
|
49
|
+
currentConditional.parentActive && !currentConditional.branchTaken;
|
|
50
|
+
currentConditional.branchTaken = true;
|
|
51
|
+
conditional = currentConditional.active;
|
|
24
52
|
} else if (matchEnd) {
|
|
25
|
-
|
|
53
|
+
conditionalStack.pop();
|
|
54
|
+
conditional = conditionalStack.length
|
|
55
|
+
? conditionalStack[conditionalStack.length - 1].active
|
|
56
|
+
: true;
|
|
26
57
|
} else if (conditional) {
|
|
27
58
|
output.push(line);
|
|
28
59
|
}
|
|
29
60
|
}
|
|
61
|
+
|
|
62
|
+
if (conditionalStack.length > 0) {
|
|
63
|
+
throw new Error('Unterminated conditional block in shader source');
|
|
64
|
+
}
|
|
65
|
+
|
|
30
66
|
return output.join('\n');
|
|
31
67
|
}
|
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
assembleWGSLShader,
|
|
11
11
|
assembleGLSLShaderPair
|
|
12
12
|
} from './shader-assembly/assemble-shaders';
|
|
13
|
+
import {
|
|
14
|
+
getShaderBindingDebugRowsFromWGSL,
|
|
15
|
+
type ShaderBindingDebugRow
|
|
16
|
+
} from './shader-assembly/wgsl-binding-debug';
|
|
13
17
|
import {preprocess} from './preprocessor/preprocessor';
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -23,6 +27,8 @@ export class ShaderAssembler {
|
|
|
23
27
|
private readonly _hookFunctions: any[] = [];
|
|
24
28
|
/** Shader modules */
|
|
25
29
|
private _defaultModules: ShaderModule[] = [];
|
|
30
|
+
/** Stable per-run WGSL auto-binding assignments keyed by group/module/binding. */
|
|
31
|
+
private readonly _wgslBindingRegistry = new Map<string, number>();
|
|
26
32
|
|
|
27
33
|
/**
|
|
28
34
|
* A default shader assembler instance - the natural place to register default modules and hooks
|
|
@@ -77,20 +83,36 @@ export class ShaderAssembler {
|
|
|
77
83
|
source: string;
|
|
78
84
|
getUniforms: GetUniformsFunc;
|
|
79
85
|
modules: ShaderModule[];
|
|
86
|
+
bindingAssignments: {moduleName: string; name: string; group: number; location: number}[];
|
|
87
|
+
bindingTable: ShaderBindingDebugRow[];
|
|
80
88
|
} {
|
|
81
89
|
const modules = this._getModuleList(props.modules); // Combine with default modules
|
|
82
90
|
const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions
|
|
83
|
-
const {source, getUniforms} = assembleWGSLShader({
|
|
91
|
+
const {source, getUniforms, bindingAssignments} = assembleWGSLShader({
|
|
84
92
|
...props,
|
|
85
93
|
// @ts-expect-error
|
|
86
94
|
source: props.source,
|
|
95
|
+
_bindingRegistry: this._wgslBindingRegistry,
|
|
87
96
|
modules,
|
|
88
97
|
hookFunctions
|
|
89
98
|
});
|
|
99
|
+
const defines = {
|
|
100
|
+
...modules.reduce<Record<string, boolean>>((accumulator, module) => {
|
|
101
|
+
Object.assign(accumulator, module.defines);
|
|
102
|
+
return accumulator;
|
|
103
|
+
}, {}),
|
|
104
|
+
...props.defines
|
|
105
|
+
};
|
|
90
106
|
// WGSL does not have built-in preprocessing support (just compile time constants)
|
|
91
107
|
const preprocessedSource =
|
|
92
|
-
props.platformInfo.shaderLanguage === 'wgsl' ? preprocess(source) : source;
|
|
93
|
-
return {
|
|
108
|
+
props.platformInfo.shaderLanguage === 'wgsl' ? preprocess(source, {defines}) : source;
|
|
109
|
+
return {
|
|
110
|
+
source: preprocessedSource,
|
|
111
|
+
getUniforms,
|
|
112
|
+
modules,
|
|
113
|
+
bindingAssignments,
|
|
114
|
+
bindingTable: getShaderBindingDebugRowsFromWGSL(preprocessedSource, bindingAssignments)
|
|
115
|
+
};
|
|
94
116
|
}
|
|
95
117
|
|
|
96
118
|
/**
|