@luma.gl/shadertools 9.2.6 → 9.3.0-alpha.10

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.
Files changed (174) hide show
  1. package/dist/dist.dev.js +4798 -6439
  2. package/dist/dist.min.js +2047 -311
  3. package/dist/index.cjs +3033 -507
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +12 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
  10. package/dist/lib/preprocessor/preprocessor.js +35 -8
  11. package/dist/lib/preprocessor/preprocessor.js.map +1 -1
  12. package/dist/lib/shader-assembler.d.ts +10 -0
  13. package/dist/lib/shader-assembler.d.ts.map +1 -1
  14. package/dist/lib/shader-assembler.js +20 -3
  15. package/dist/lib/shader-assembler.js.map +1 -1
  16. package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
  17. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  18. package/dist/lib/shader-assembly/assemble-shaders.js +214 -11
  19. package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
  20. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
  21. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
  22. package/dist/lib/shader-assembly/wgsl-binding-debug.js +140 -0
  23. package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
  24. package/dist/lib/shader-generator/glsl/generate-glsl.js +7 -4
  25. package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
  26. package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
  27. package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
  28. package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
  29. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +91 -0
  30. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
  31. package/dist/lib/shader-module/shader-module-uniform-layout.js +209 -0
  32. package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
  33. package/dist/lib/shader-module/shader-module.d.ts +12 -6
  34. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  35. package/dist/lib/shader-module/shader-module.js.map +1 -1
  36. package/dist/lib/utils/assert.d.ts.map +1 -1
  37. package/dist/lib/utils/assert.js +3 -1
  38. package/dist/lib/utils/assert.js.map +1 -1
  39. package/dist/lib/utils/uniform-types.d.ts +11 -7
  40. package/dist/lib/utils/uniform-types.d.ts.map +1 -1
  41. package/dist/modules/engine/picking/picking.d.ts +5 -2
  42. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  43. package/dist/modules/engine/picking/picking.js +5 -2
  44. package/dist/modules/engine/picking/picking.js.map +1 -1
  45. package/dist/modules/engine/project/project.d.ts +1 -1
  46. package/dist/modules/engine/project/project.js +1 -1
  47. package/dist/modules/engine/skin/skin.d.ts +30 -0
  48. package/dist/modules/engine/skin/skin.d.ts.map +1 -0
  49. package/dist/modules/engine/skin/skin.js +86 -0
  50. package/dist/modules/engine/skin/skin.js.map +1 -0
  51. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
  52. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  53. package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
  54. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
  55. package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
  56. package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
  57. package/dist/modules/lighting/ibl/ibl.js +33 -0
  58. package/dist/modules/lighting/ibl/ibl.js.map +1 -0
  59. package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
  60. package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
  61. package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
  62. package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
  63. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
  64. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
  65. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
  66. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
  67. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
  68. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
  69. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
  70. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
  71. package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
  72. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
  73. package/dist/modules/lighting/lights/lighting-glsl.js +44 -38
  74. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
  75. package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
  76. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
  77. package/dist/modules/lighting/lights/lighting-wgsl.js +46 -18
  78. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
  79. package/dist/modules/lighting/lights/lighting.d.ts +104 -62
  80. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  81. package/dist/modules/lighting/lights/lighting.js +107 -68
  82. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  83. package/dist/modules/lighting/no-material/dirlight.d.ts +8 -3
  84. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  85. package/dist/modules/lighting/no-material/dirlight.js +4 -2
  86. package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
  87. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
  88. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
  89. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +581 -28
  90. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
  91. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
  92. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  93. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +850 -107
  94. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  95. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +172 -41
  96. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  97. package/dist/modules/lighting/pbr-material/pbr-material.js +109 -1
  98. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
  99. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
  100. package/dist/modules/lighting/pbr-material/pbr-projection.js +14 -2
  101. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
  102. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +40 -0
  103. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
  104. package/dist/modules/lighting/pbr-material/pbr-scene.js +67 -0
  105. package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
  106. package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
  107. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  108. package/dist/modules/lighting/phong-material/phong-material.js +4 -0
  109. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
  110. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
  111. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  112. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +17 -6
  113. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
  114. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
  115. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
  116. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
  117. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
  118. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
  119. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
  120. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +42 -11
  121. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
  122. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
  123. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
  124. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
  125. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
  126. package/dist/modules/math/fp64/fp64.d.ts +1 -0
  127. package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
  128. package/dist/modules/math/fp64/fp64.js +8 -2
  129. package/dist/modules/math/fp64/fp64.js.map +1 -1
  130. package/dist/modules/math/random/random.d.ts +1 -1
  131. package/dist/modules/math/random/random.d.ts.map +1 -1
  132. package/dist/modules/math/random/random.js +2 -3
  133. package/dist/modules/math/random/random.js.map +1 -1
  134. package/package.json +4 -5
  135. package/src/index.ts +37 -6
  136. package/src/lib/preprocessor/preprocessor.ts +44 -8
  137. package/src/lib/shader-assembler.ts +25 -3
  138. package/src/lib/shader-assembly/assemble-shaders.ts +384 -12
  139. package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
  140. package/src/lib/shader-generator/glsl/generate-glsl.ts +11 -5
  141. package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
  142. package/src/lib/shader-module/shader-module-uniform-layout.ts +346 -0
  143. package/src/lib/shader-module/shader-module.ts +17 -7
  144. package/src/lib/utils/assert.ts +3 -1
  145. package/src/lib/utils/uniform-types.ts +24 -9
  146. package/src/modules/engine/picking/picking.ts +5 -2
  147. package/src/modules/engine/project/project.ts +1 -1
  148. package/src/modules/engine/skin/skin.ts +114 -0
  149. package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
  150. package/src/modules/lighting/ibl/ibl.ts +44 -0
  151. package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
  152. package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
  153. package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
  154. package/src/modules/lighting/lights/lighting-glsl.ts +44 -38
  155. package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
  156. package/src/modules/lighting/lights/lighting.ts +198 -99
  157. package/src/modules/lighting/no-material/dirlight.ts +4 -2
  158. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +581 -28
  159. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +850 -107
  160. package/src/modules/lighting/pbr-material/pbr-material.ts +185 -5
  161. package/src/modules/lighting/pbr-material/pbr-projection.ts +15 -2
  162. package/src/modules/lighting/pbr-material/pbr-scene.ts +91 -0
  163. package/src/modules/lighting/phong-material/phong-material.ts +5 -0
  164. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +17 -6
  165. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
  166. package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +42 -11
  167. package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
  168. package/src/modules/math/fp64/fp64.ts +9 -3
  169. package/src/modules/math/random/random.ts +2 -3
  170. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts +0 -8
  171. package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +0 -1
  172. package/dist/lib/wgsl/get-shader-layout-wgsl.js +0 -95
  173. package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +0 -1
  174. package/src/lib/wgsl/get-shader-layout-wgsl.ts +0 -105
@@ -4,8 +4,9 @@
4
4
 
5
5
  export const fp64arithmeticShader = /* glsl */ `\
6
6
 
7
- uniform fp64arithmeticUniforms {
7
+ layout(std140) uniform fp64arithmeticUniforms {
8
8
  uniform float ONE;
9
+ uniform float SPLIT;
9
10
  } fp64;
10
11
 
11
12
  /*
@@ -15,6 +16,12 @@ The purpose of this workaround is to prevent shader compilers from
15
16
  optimizing away necessary arithmetic operations by swapping their sequences
16
17
  or transform the equation to some 'equivalent' form.
17
18
 
19
+ These helpers implement Dekker/Veltkamp-style error tracking. If the compiler
20
+ folds constants or reassociates the arithmetic, the high/low split can stop
21
+ tracking the rounding error correctly. That failure mode tends to look fine in
22
+ simple coordinate setup, but then breaks down inside iterative arithmetic such
23
+ as fp64 Mandelbrot loops.
24
+
18
25
  The method is to multiply an artifical variable, ONE, which will be known to
19
26
  the compiler to be 1 only at runtime. The whole expression is then represented
20
27
  as a polynomial with respective to ONE. In the coefficients of all terms, only one a
@@ -23,17 +30,23 @@ and one b should appear
23
30
  err = (a + b) * ONE^6 - a * ONE^5 - (a + b) * ONE^4 + a * ONE^3 - b - (a + b) * ONE^2 + a * ONE
24
31
  */
25
32
 
26
- // Divide float number to high and low floats to extend fraction bits
27
- vec2 split(float a) {
28
- const float SPLIT = 4097.0;
29
- float t = a * SPLIT;
33
+ float prevent_fp64_optimization(float value) {
30
34
  #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
31
- float a_hi = t * fp64.ONE - (t - a);
32
- float a_lo = a * fp64.ONE - a_hi;
35
+ return value + fp64.ONE * 0.0;
33
36
  #else
34
- float a_hi = t - (t - a);
35
- float a_lo = a - a_hi;
37
+ return value;
36
38
  #endif
39
+ }
40
+
41
+ // Divide float number to high and low floats to extend fraction bits
42
+ vec2 split(float a) {
43
+ // Keep SPLIT as a runtime uniform so the compiler cannot fold the Dekker
44
+ // split into a constant expression and reassociate the recovery steps.
45
+ float split = prevent_fp64_optimization(fp64.SPLIT);
46
+ float t = prevent_fp64_optimization(a * split);
47
+ float temp = t - a;
48
+ float a_hi = t - temp;
49
+ float a_lo = a - a_hi;
37
50
  return vec2(a_hi, a_lo);
38
51
  }
39
52
 
@@ -97,8 +110,26 @@ vec2 twoProd(float a, float b) {
97
110
  float prod = a * b;
98
111
  vec2 a_fp64 = split(a);
99
112
  vec2 b_fp64 = split(b);
100
- float err = ((a_fp64.x * b_fp64.x - prod) + a_fp64.x * b_fp64.y +
101
- a_fp64.y * b_fp64.x) + a_fp64.y * b_fp64.y;
113
+ // twoProd is especially sensitive because mul_fp64 and div_fp64 both depend
114
+ // on the split terms and cross terms staying in the original evaluation
115
+ // order. If the compiler folds or reassociates them, the low part tends to
116
+ // collapse to zero or NaN on some drivers.
117
+ float highProduct = prevent_fp64_optimization(a_fp64.x * b_fp64.x);
118
+ float crossProduct1 = prevent_fp64_optimization(a_fp64.x * b_fp64.y);
119
+ float crossProduct2 = prevent_fp64_optimization(a_fp64.y * b_fp64.x);
120
+ float lowProduct = prevent_fp64_optimization(a_fp64.y * b_fp64.y);
121
+ #if defined(LUMA_FP64_CODE_ELIMINATION_WORKAROUND)
122
+ float err1 = (highProduct - prod) * fp64.ONE;
123
+ float err2 = crossProduct1 * fp64.ONE * fp64.ONE;
124
+ float err3 = crossProduct2 * fp64.ONE * fp64.ONE * fp64.ONE;
125
+ float err4 = lowProduct * fp64.ONE * fp64.ONE * fp64.ONE * fp64.ONE;
126
+ #else
127
+ float err1 = highProduct - prod;
128
+ float err2 = crossProduct1;
129
+ float err3 = crossProduct2;
130
+ float err4 = lowProduct;
131
+ #endif
132
+ float err = ((err1 + err2) + err3) + err4;
102
133
  return vec2(prod, err);
103
134
  }
104
135
 
@@ -0,0 +1,212 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export const fp64arithmeticWGSL = /* wgsl */ `\
6
+ struct Fp64ArithmeticUniforms {
7
+ ONE: f32,
8
+ SPLIT: f32,
9
+ };
10
+
11
+ @group(0) @binding(auto) var<uniform> fp64arithmetic : Fp64ArithmeticUniforms;
12
+
13
+ fn fp64_nan(seed: f32) -> f32 {
14
+ let nanBits = 0x7fc00000u | select(0u, 1u, seed < 0.0);
15
+ return bitcast<f32>(nanBits);
16
+ }
17
+
18
+ fn fp64_runtime_zero() -> f32 {
19
+ return fp64arithmetic.ONE * 0.0;
20
+ }
21
+
22
+ fn prevent_fp64_optimization(value: f32) -> f32 {
23
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
24
+ return value + fp64_runtime_zero();
25
+ #else
26
+ return value;
27
+ #endif
28
+ }
29
+
30
+ fn split(a: f32) -> vec2f {
31
+ let splitValue = prevent_fp64_optimization(fp64arithmetic.SPLIT + fp64_runtime_zero());
32
+ let t = prevent_fp64_optimization(a * splitValue);
33
+ let temp = prevent_fp64_optimization(t - a);
34
+ let aHi = prevent_fp64_optimization(t - temp);
35
+ let aLo = prevent_fp64_optimization(a - aHi);
36
+ return vec2f(aHi, aLo);
37
+ }
38
+
39
+ fn split2(a: vec2f) -> vec2f {
40
+ var b = split(a.x);
41
+ b.y = b.y + a.y;
42
+ return b;
43
+ }
44
+
45
+ fn quickTwoSum(a: f32, b: f32) -> vec2f {
46
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
47
+ let sum = prevent_fp64_optimization((a + b) * fp64arithmetic.ONE);
48
+ let err = prevent_fp64_optimization(b - (sum - a) * fp64arithmetic.ONE);
49
+ #else
50
+ let sum = prevent_fp64_optimization(a + b);
51
+ let err = prevent_fp64_optimization(b - (sum - a));
52
+ #endif
53
+ return vec2f(sum, err);
54
+ }
55
+
56
+ fn twoSum(a: f32, b: f32) -> vec2f {
57
+ let s = prevent_fp64_optimization(a + b);
58
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
59
+ let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
60
+ let err =
61
+ prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
62
+ fp64arithmetic.ONE *
63
+ fp64arithmetic.ONE *
64
+ fp64arithmetic.ONE) +
65
+ prevent_fp64_optimization(b - v);
66
+ #else
67
+ let v = prevent_fp64_optimization(s - a);
68
+ let err = prevent_fp64_optimization(a - (s - v)) + prevent_fp64_optimization(b - v);
69
+ #endif
70
+ return vec2f(s, err);
71
+ }
72
+
73
+ fn twoSub(a: f32, b: f32) -> vec2f {
74
+ let s = prevent_fp64_optimization(a - b);
75
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
76
+ let v = prevent_fp64_optimization((s * fp64arithmetic.ONE - a) * fp64arithmetic.ONE);
77
+ let err =
78
+ prevent_fp64_optimization((a - (s - v) * fp64arithmetic.ONE) *
79
+ fp64arithmetic.ONE *
80
+ fp64arithmetic.ONE *
81
+ fp64arithmetic.ONE) -
82
+ prevent_fp64_optimization(b + v);
83
+ #else
84
+ let v = prevent_fp64_optimization(s - a);
85
+ let err = prevent_fp64_optimization(a - (s - v)) - prevent_fp64_optimization(b + v);
86
+ #endif
87
+ return vec2f(s, err);
88
+ }
89
+
90
+ fn twoSqr(a: f32) -> vec2f {
91
+ let prod = prevent_fp64_optimization(a * a);
92
+ let aFp64 = split(a);
93
+ let highProduct = prevent_fp64_optimization(aFp64.x * aFp64.x);
94
+ let crossProduct = prevent_fp64_optimization(2.0 * aFp64.x * aFp64.y);
95
+ let lowProduct = prevent_fp64_optimization(aFp64.y * aFp64.y);
96
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
97
+ let err =
98
+ (prevent_fp64_optimization(highProduct - prod) * fp64arithmetic.ONE +
99
+ crossProduct * fp64arithmetic.ONE * fp64arithmetic.ONE) +
100
+ lowProduct * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
101
+ #else
102
+ let err = ((prevent_fp64_optimization(highProduct - prod) + crossProduct) + lowProduct);
103
+ #endif
104
+ return vec2f(prod, err);
105
+ }
106
+
107
+ fn twoProd(a: f32, b: f32) -> vec2f {
108
+ let prod = prevent_fp64_optimization(a * b);
109
+ let aFp64 = split(a);
110
+ let bFp64 = split(b);
111
+ let highProduct = prevent_fp64_optimization(aFp64.x * bFp64.x);
112
+ let crossProduct1 = prevent_fp64_optimization(aFp64.x * bFp64.y);
113
+ let crossProduct2 = prevent_fp64_optimization(aFp64.y * bFp64.x);
114
+ let lowProduct = prevent_fp64_optimization(aFp64.y * bFp64.y);
115
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
116
+ let err1 = (highProduct - prod) * fp64arithmetic.ONE;
117
+ let err2 = crossProduct1 * fp64arithmetic.ONE * fp64arithmetic.ONE;
118
+ let err3 = crossProduct2 * fp64arithmetic.ONE * fp64arithmetic.ONE * fp64arithmetic.ONE;
119
+ let err4 =
120
+ lowProduct *
121
+ fp64arithmetic.ONE *
122
+ fp64arithmetic.ONE *
123
+ fp64arithmetic.ONE *
124
+ fp64arithmetic.ONE;
125
+ #else
126
+ let err1 = highProduct - prod;
127
+ let err2 = crossProduct1;
128
+ let err3 = crossProduct2;
129
+ let err4 = lowProduct;
130
+ #endif
131
+ let err12InputA = prevent_fp64_optimization(err1);
132
+ let err12InputB = prevent_fp64_optimization(err2);
133
+ let err12 = prevent_fp64_optimization(err12InputA + err12InputB);
134
+ let err123InputA = prevent_fp64_optimization(err12);
135
+ let err123InputB = prevent_fp64_optimization(err3);
136
+ let err123 = prevent_fp64_optimization(err123InputA + err123InputB);
137
+ let err1234InputA = prevent_fp64_optimization(err123);
138
+ let err1234InputB = prevent_fp64_optimization(err4);
139
+ let err = prevent_fp64_optimization(err1234InputA + err1234InputB);
140
+ return vec2f(prod, err);
141
+ }
142
+
143
+ fn sum_fp64(a: vec2f, b: vec2f) -> vec2f {
144
+ var s = twoSum(a.x, b.x);
145
+ let t = twoSum(a.y, b.y);
146
+ s.y = prevent_fp64_optimization(s.y + t.x);
147
+ s = quickTwoSum(s.x, s.y);
148
+ s.y = prevent_fp64_optimization(s.y + t.y);
149
+ s = quickTwoSum(s.x, s.y);
150
+ return s;
151
+ }
152
+
153
+ fn sub_fp64(a: vec2f, b: vec2f) -> vec2f {
154
+ var s = twoSub(a.x, b.x);
155
+ let t = twoSub(a.y, b.y);
156
+ s.y = prevent_fp64_optimization(s.y + t.x);
157
+ s = quickTwoSum(s.x, s.y);
158
+ s.y = prevent_fp64_optimization(s.y + t.y);
159
+ s = quickTwoSum(s.x, s.y);
160
+ return s;
161
+ }
162
+
163
+ fn mul_fp64(a: vec2f, b: vec2f) -> vec2f {
164
+ var prod = twoProd(a.x, b.x);
165
+ let crossProduct1 = prevent_fp64_optimization(a.x * b.y);
166
+ prod.y = prevent_fp64_optimization(prod.y + crossProduct1);
167
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
168
+ prod = split2(prod);
169
+ #endif
170
+ prod = quickTwoSum(prod.x, prod.y);
171
+ let crossProduct2 = prevent_fp64_optimization(a.y * b.x);
172
+ prod.y = prevent_fp64_optimization(prod.y + crossProduct2);
173
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
174
+ prod = split2(prod);
175
+ #endif
176
+ prod = quickTwoSum(prod.x, prod.y);
177
+ return prod;
178
+ }
179
+
180
+ fn div_fp64(a: vec2f, b: vec2f) -> vec2f {
181
+ let xn = prevent_fp64_optimization(1.0 / b.x);
182
+ let yn = mul_fp64(a, vec2f(xn, fp64_runtime_zero()));
183
+ let diff = prevent_fp64_optimization(sub_fp64(a, mul_fp64(b, yn)).x);
184
+ let prod = twoProd(xn, diff);
185
+ return sum_fp64(yn, prod);
186
+ }
187
+
188
+ fn sqrt_fp64(a: vec2f) -> vec2f {
189
+ if (a.x == 0.0 && a.y == 0.0) {
190
+ return vec2f(0.0, 0.0);
191
+ }
192
+ if (a.x < 0.0) {
193
+ let nanValue = fp64_nan(a.x);
194
+ return vec2f(nanValue, nanValue);
195
+ }
196
+
197
+ let x = prevent_fp64_optimization(1.0 / sqrt(a.x));
198
+ let yn = prevent_fp64_optimization(a.x * x);
199
+ #ifdef LUMA_FP64_CODE_ELIMINATION_WORKAROUND
200
+ let ynSqr = twoSqr(yn) * fp64arithmetic.ONE;
201
+ #else
202
+ let ynSqr = twoSqr(yn);
203
+ #endif
204
+ let diff = prevent_fp64_optimization(sub_fp64(a, ynSqr).x);
205
+ let prod = twoProd(prevent_fp64_optimization(x * 0.5), diff);
206
+ #ifdef LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND
207
+ return sum_fp64(split(yn), prod);
208
+ #else
209
+ return sum_fp64(vec2f(yn, 0.0), prod);
210
+ #endif
211
+ }
212
+ `;
@@ -6,10 +6,11 @@ import {ShaderModule} from '../../../lib/shader-module/shader-module';
6
6
 
7
7
  import {fp64ify, fp64LowPart, fp64ifyMatrix4} from '../../../modules/math/fp64/fp64-utils';
8
8
  import {fp64arithmeticShader} from './fp64-arithmetic-glsl';
9
+ import {fp64arithmeticWGSL} from './fp64-arithmetic-wgsl';
9
10
  import {fp64functionShader} from './fp64-functions-glsl';
10
11
 
11
12
  type FP64Props = {};
12
- type FP64Uniforms = {ONE: number};
13
+ type FP64Uniforms = {ONE: number; SPLIT: number};
13
14
  type FP64Bindings = {};
14
15
 
15
16
  type FP64Utilities = {
@@ -20,7 +21,10 @@ type FP64Utilities = {
20
21
 
21
22
  const defaultUniforms: FP64Uniforms = {
22
23
  // Used in LUMA_FP64_CODE_ELIMINATION_WORKAROUND
23
- ONE: 1.0
24
+ ONE: 1.0,
25
+ // Runtime split factor for Dekker splitting. Keeping this as a uniform helps
26
+ // prevent aggressive constant folding in shader compilers.
27
+ SPLIT: 4097.0
24
28
  };
25
29
 
26
30
  /**
@@ -28,9 +32,11 @@ const defaultUniforms: FP64Uniforms = {
28
32
  */
29
33
  export const fp64arithmetic: ShaderModule<FP64Props, FP64Uniforms, FP64Bindings> & FP64Utilities = {
30
34
  name: 'fp64arithmetic',
35
+ source: fp64arithmeticWGSL,
36
+ fs: fp64arithmeticShader,
31
37
  vs: fp64arithmeticShader,
32
38
  defaultUniforms,
33
- uniformTypes: {ONE: 'f32'},
39
+ uniformTypes: {ONE: 'f32', SPLIT: 'f32'},
34
40
 
35
41
  // Additional Functions
36
42
  fp64ify,
@@ -5,9 +5,8 @@
5
5
  import {ShaderModule} from '../../../lib/shader-module/shader-module';
6
6
 
7
7
  const source = /* wgsl */ `\
8
- fn random(scale: vec3f, seed: float) -> f32 {
9
- /* use the fragment position for a different seed per-pixel */
10
- return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
8
+ fn random(scale: vec3f, seed: f32) -> f32 {
9
+ return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
11
10
  }
12
11
  `;
13
12
 
@@ -1,8 +0,0 @@
1
- import { ShaderLayout } from '@luma.gl/core';
2
- /**
3
- * Parse a ShaderLayout from WGSL shader source code.
4
- * @param source WGSL source code (can contain both @vertex and @fragment entry points)
5
- * @returns
6
- */
7
- export declare function getShaderLayoutFromWGSL(source: string): ShaderLayout;
8
- //# sourceMappingURL=get-shader-layout-wgsl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-shader-layout-wgsl.d.ts","sourceRoot":"","sources":["../../../src/lib/wgsl/get-shader-layout-wgsl.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,YAAY,EAAM,MAAM,eAAe,CAAC;AAGrE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAoEpE"}
@@ -1,95 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { log } from '@luma.gl/core';
5
- import { WgslReflect } from 'wgsl_reflect';
6
- /**
7
- * Parse a ShaderLayout from WGSL shader source code.
8
- * @param source WGSL source code (can contain both @vertex and @fragment entry points)
9
- * @returns
10
- */
11
- export function getShaderLayoutFromWGSL(source) {
12
- const shaderLayout = { attributes: [], bindings: [] };
13
- let parsedWGSL;
14
- try {
15
- parsedWGSL = parseWGSL(source);
16
- }
17
- catch (error) {
18
- log.error(error.message)();
19
- return shaderLayout;
20
- }
21
- for (const uniform of parsedWGSL.uniforms) {
22
- const members = [];
23
- // @ts-expect-error
24
- for (const attribute of uniform.type?.members || []) {
25
- members.push({
26
- name: attribute.name,
27
- type: getType(attribute.type)
28
- });
29
- }
30
- shaderLayout.bindings.push({
31
- type: 'uniform',
32
- name: uniform.name,
33
- group: uniform.group,
34
- location: uniform.binding,
35
- // @ts-expect-error TODO - unused for now but needs fixing
36
- members
37
- });
38
- }
39
- for (const texture of parsedWGSL.textures) {
40
- shaderLayout.bindings.push({
41
- type: 'texture',
42
- name: texture.name,
43
- group: texture.group,
44
- location: texture.binding
45
- });
46
- }
47
- for (const sampler of parsedWGSL.samplers) {
48
- shaderLayout.bindings.push({
49
- type: 'sampler',
50
- name: sampler.name,
51
- group: sampler.group,
52
- location: sampler.binding
53
- });
54
- }
55
- const vertex = parsedWGSL.entry.vertex[0]; // "main"
56
- // Vertex shader inputs
57
- const attributeCount = vertex?.inputs.length || 0; // inputs to "main"
58
- for (let i = 0; i < attributeCount; i++) {
59
- const wgslAttribute = vertex.inputs[i];
60
- // locationType can be "builtin"
61
- if (wgslAttribute.locationType === 'location') {
62
- const type = getType(wgslAttribute.type);
63
- shaderLayout.attributes.push({
64
- name: wgslAttribute.name,
65
- location: Number(wgslAttribute.location),
66
- type
67
- });
68
- }
69
- }
70
- return shaderLayout;
71
- }
72
- /** Get a valid shader attribute type string from a wgsl-reflect type */
73
- function getType(type) {
74
- // @ts-expect-error WgslReflect type checks needed
75
- return type?.format ? `${type.name}<${type.format.name}>` : type.name;
76
- }
77
- function parseWGSL(source) {
78
- try {
79
- return new WgslReflect(source);
80
- }
81
- catch (error) {
82
- if (error instanceof Error) {
83
- throw error;
84
- }
85
- let message = 'WGSL parse error';
86
- if (typeof error === 'object' && error?.message) {
87
- message += `: ${error.message} `;
88
- }
89
- if (typeof error === 'object' && error?.token) {
90
- message += error.token.line || '';
91
- }
92
- throw new Error(message, { cause: error });
93
- }
94
- }
95
- //# sourceMappingURL=get-shader-layout-w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;AAED,wEAAwE;AACxE,SAAS,OAAO,CAAC,IAAqB;IACpC,kDAAkD;IAClD,OAAO,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AACxE,CAAC;AAED,SAAS,SAAS,CAAC,MAAc;IAC/B,IAAI,CAAC;QACH,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,KAAK,CAAC;QACd,CAAC;QACD,IAAI,OAAO,GAAG,kBAAkB,CAAC;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,EAAE,OAAO,EAAE,CAAC;YAChD,OAAO,IAAI,KAAK,KAAK,CAAC,OAAO,GAAG,CAAC;QACnC,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,EAAE,KAAK,EAAE,CAAC;YAC9C,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QACpC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
@@ -1,105 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {AttributeShaderType, ShaderLayout, log} from '@luma.gl/core';
6
- import {TypeInfo, WgslReflect} from 'wgsl_reflect';
7
-
8
- /**
9
- * Parse a ShaderLayout from WGSL shader source code.
10
- * @param source WGSL source code (can contain both @vertex and @fragment entry points)
11
- * @returns
12
- */
13
- export function getShaderLayoutFromWGSL(source: string): ShaderLayout {
14
- const shaderLayout: ShaderLayout = {attributes: [], bindings: []};
15
-
16
- let parsedWGSL: WgslReflect;
17
- try {
18
- parsedWGSL = parseWGSL(source);
19
- } catch (error: any) {
20
- log.error(error.message)();
21
- return shaderLayout;
22
- }
23
-
24
- for (const uniform of parsedWGSL.uniforms) {
25
- const members = [];
26
- // @ts-expect-error
27
- for (const attribute of uniform.type?.members || []) {
28
- members.push({
29
- name: attribute.name,
30
- type: getType(attribute.type)
31
- });
32
- }
33
-
34
- shaderLayout.bindings.push({
35
- type: 'uniform',
36
- name: uniform.name,
37
- group: uniform.group,
38
- location: uniform.binding,
39
- // @ts-expect-error TODO - unused for now but needs fixing
40
- members
41
- });
42
- }
43
-
44
- for (const texture of parsedWGSL.textures) {
45
- shaderLayout.bindings.push({
46
- type: 'texture',
47
- name: texture.name,
48
- group: texture.group,
49
- location: texture.binding
50
- });
51
- }
52
-
53
- for (const sampler of parsedWGSL.samplers) {
54
- shaderLayout.bindings.push({
55
- type: 'sampler',
56
- name: sampler.name,
57
- group: sampler.group,
58
- location: sampler.binding
59
- });
60
- }
61
-
62
- const vertex = parsedWGSL.entry.vertex[0]; // "main"
63
-
64
- // Vertex shader inputs
65
- const attributeCount = vertex?.inputs.length || 0; // inputs to "main"
66
- for (let i = 0; i < attributeCount; i++) {
67
- const wgslAttribute = vertex.inputs[i];
68
-
69
- // locationType can be "builtin"
70
- if (wgslAttribute.locationType === 'location') {
71
- const type = getType(wgslAttribute.type);
72
-
73
- shaderLayout.attributes.push({
74
- name: wgslAttribute.name,
75
- location: Number(wgslAttribute.location),
76
- type
77
- });
78
- }
79
- }
80
- return shaderLayout;
81
- }
82
-
83
- /** Get a valid shader attribute type string from a wgsl-reflect type */
84
- function getType(type: TypeInfo | null): AttributeShaderType {
85
- // @ts-expect-error WgslReflect type checks needed
86
- return type?.format ? `${type.name}<${type.format.name}>` : type.name;
87
- }
88
-
89
- function parseWGSL(source: string): WgslReflect {
90
- try {
91
- return new WgslReflect(source);
92
- } catch (error: any) {
93
- if (error instanceof Error) {
94
- throw error;
95
- }
96
- let message = 'WGSL parse error';
97
- if (typeof error === 'object' && error?.message) {
98
- message += `: ${error.message} `;
99
- }
100
- if (typeof error === 'object' && error?.token) {
101
- message += error.token.line || '';
102
- }
103
- throw new Error(message, {cause: error});
104
- }
105
- }