@luma.gl/graph 10.0.0-alpha.13 → 10.0.0-alpha.15

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 (236) hide show
  1. package/dist/arrow/arrow-colors.cjs +99 -18
  2. package/dist/arrow/arrow-colors.d.ts +27 -10
  3. package/dist/arrow/arrow-colors.d.ts.map +1 -1
  4. package/dist/arrow/arrow-colors.js +107 -24
  5. package/dist/arrow/arrow-colors.js.map +1 -1
  6. package/dist/arrow/gpu/arrow-column-gpu-vector.cjs +27 -8
  7. package/dist/arrow/gpu/arrow-column-gpu-vector.d.ts +11 -1
  8. package/dist/arrow/gpu/arrow-column-gpu-vector.d.ts.map +1 -1
  9. package/dist/arrow/gpu/arrow-column-gpu-vector.js +33 -8
  10. package/dist/arrow/gpu/arrow-column-gpu-vector.js.map +1 -1
  11. package/dist/arrow/gpu/arrow-gpu-vector-adapters.cjs +2 -0
  12. package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts +1 -0
  13. package/dist/arrow/gpu/arrow-gpu-vector-adapters.d.ts.map +1 -1
  14. package/dist/arrow/gpu/arrow-gpu-vector-adapters.js +1 -1
  15. package/dist/arrow/gpu/arrow-gpu-vector-adapters.js.map +1 -1
  16. package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +32 -3
  17. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts +6 -1
  18. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
  19. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +37 -3
  20. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
  21. package/dist/arrow/index.cjs +2 -0
  22. package/dist/arrow/index.cjs.map +3 -3
  23. package/dist/arrow/index.d.ts +1 -1
  24. package/dist/arrow/index.d.ts.map +1 -1
  25. package/dist/arrow/index.js +1 -1
  26. package/dist/arrow/index.js.map +1 -1
  27. package/dist/dist.dev.js +98 -43
  28. package/dist/dist.min.js +63 -63
  29. package/dist/experimental/index.cjs.map +1 -1
  30. package/dist/experimental/simulation/index.cjs.map +1 -1
  31. package/dist/geospatial/gpu-point-spatial-query.cjs +2 -15
  32. package/dist/geospatial/gpu-point-spatial-query.d.ts.map +1 -1
  33. package/dist/geospatial/gpu-point-spatial-query.js +2 -15
  34. package/dist/geospatial/gpu-point-spatial-query.js.map +1 -1
  35. package/dist/geospatial/index.cjs.map +2 -2
  36. package/dist/gpu-a5/index.cjs.map +1 -1
  37. package/dist/gpu-core/gpu-command-graph-compiler.cjs +11 -2
  38. package/dist/gpu-core/gpu-command-graph-compiler.d.ts +2 -1
  39. package/dist/gpu-core/gpu-command-graph-compiler.d.ts.map +1 -1
  40. package/dist/gpu-core/gpu-command-graph-compiler.js +13 -2
  41. package/dist/gpu-core/gpu-command-graph-compiler.js.map +1 -1
  42. package/dist/gpu-core/gpu-command-graph-types.d.ts +16 -1
  43. package/dist/gpu-core/gpu-command-graph-types.d.ts.map +1 -1
  44. package/dist/gpu-core/gpu-command-graph-types.js.map +1 -1
  45. package/dist/gpu-core/gpu-command-graph.cjs +6 -4
  46. package/dist/gpu-core/gpu-command-graph.d.ts +4 -4
  47. package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
  48. package/dist/gpu-core/gpu-command-graph.js +6 -4
  49. package/dist/gpu-core/gpu-command-graph.js.map +1 -1
  50. package/dist/gpu-core/gpu-dispatch-utils.cjs +7 -3
  51. package/dist/gpu-core/gpu-dispatch-utils.d.ts +2 -0
  52. package/dist/gpu-core/gpu-dispatch-utils.d.ts.map +1 -1
  53. package/dist/gpu-core/gpu-dispatch-utils.js +4 -1
  54. package/dist/gpu-core/gpu-dispatch-utils.js.map +1 -1
  55. package/dist/gpu-core/gpu-expression-operation.cjs +1 -1
  56. package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
  57. package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
  58. package/dist/gpu-core/gpu-expression-operation.js +1 -1
  59. package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
  60. package/dist/gpu-core/gpu-grid-aggregation.cjs +2 -5
  61. package/dist/gpu-core/gpu-grid-aggregation.d.ts.map +1 -1
  62. package/dist/gpu-core/gpu-grid-aggregation.js +2 -5
  63. package/dist/gpu-core/gpu-grid-aggregation.js.map +1 -1
  64. package/dist/gpu-core/gpu-grid-binning.cjs +2 -5
  65. package/dist/gpu-core/gpu-grid-binning.d.ts.map +1 -1
  66. package/dist/gpu-core/gpu-grid-binning.js +2 -5
  67. package/dist/gpu-core/gpu-grid-binning.js.map +1 -1
  68. package/dist/gpu-core/gpu-grid-coordinate.cjs +41 -0
  69. package/dist/gpu-core/gpu-grid-coordinate.d.ts +7 -0
  70. package/dist/gpu-core/gpu-grid-coordinate.d.ts.map +1 -0
  71. package/dist/gpu-core/gpu-grid-coordinate.js +24 -0
  72. package/dist/gpu-core/gpu-grid-coordinate.js.map +1 -0
  73. package/dist/gpu-core/gpu-grid-index-internals.cjs +2 -15
  74. package/dist/gpu-core/gpu-grid-index-internals.d.ts.map +1 -1
  75. package/dist/gpu-core/gpu-grid-index-internals.js +2 -15
  76. package/dist/gpu-core/gpu-grid-index-internals.js.map +1 -1
  77. package/dist/gpu-core/gpu-grid-index-query.cjs +2 -16
  78. package/dist/gpu-core/gpu-grid-index-query.d.ts.map +1 -1
  79. package/dist/gpu-core/gpu-grid-index-query.js +2 -16
  80. package/dist/gpu-core/gpu-grid-index-query.js.map +1 -1
  81. package/dist/gpu-core/gpu-scan.cjs +46 -32
  82. package/dist/gpu-core/gpu-scan.d.ts.map +1 -1
  83. package/dist/gpu-core/gpu-scan.js +56 -44
  84. package/dist/gpu-core/gpu-scan.js.map +1 -1
  85. package/dist/gpu-core/gpu-segmented-reduction.cjs +12 -9
  86. package/dist/gpu-core/gpu-segmented-reduction.d.ts +1 -1
  87. package/dist/gpu-core/gpu-segmented-reduction.d.ts.map +1 -1
  88. package/dist/gpu-core/gpu-segmented-reduction.js +12 -9
  89. package/dist/gpu-core/gpu-segmented-reduction.js.map +1 -1
  90. package/dist/gpu-core/gpu-segmented-scan.cjs +73 -16
  91. package/dist/gpu-core/gpu-segmented-scan.d.ts.map +1 -1
  92. package/dist/gpu-core/gpu-segmented-scan.js +73 -16
  93. package/dist/gpu-core/gpu-segmented-scan.js.map +1 -1
  94. package/dist/gpu-core/index.cjs +18 -0
  95. package/dist/gpu-core/index.cjs.map +3 -3
  96. package/dist/gpu-core/index.d.ts +13 -1
  97. package/dist/gpu-core/index.d.ts.map +1 -1
  98. package/dist/gpu-core/index.js +6 -0
  99. package/dist/gpu-core/index.js.map +1 -1
  100. package/dist/gpu-data/color-conversion.cjs +105 -0
  101. package/dist/gpu-data/color-conversion.d.ts +30 -0
  102. package/dist/gpu-data/color-conversion.d.ts.map +1 -0
  103. package/dist/gpu-data/color-conversion.js +109 -0
  104. package/dist/gpu-data/color-conversion.js.map +1 -0
  105. package/dist/gpu-data/gpu-vector-wgsl-layout.cjs +50 -0
  106. package/dist/gpu-data/gpu-vector-wgsl-layout.d.ts +41 -0
  107. package/dist/gpu-data/gpu-vector-wgsl-layout.d.ts.map +1 -0
  108. package/dist/gpu-data/gpu-vector-wgsl-layout.js +45 -0
  109. package/dist/gpu-data/gpu-vector-wgsl-layout.js.map +1 -0
  110. package/dist/gpu-data/index.cjs +10 -2
  111. package/dist/gpu-data/index.cjs.map +3 -3
  112. package/dist/gpu-data/index.d.ts +3 -0
  113. package/dist/gpu-data/index.d.ts.map +1 -1
  114. package/dist/gpu-data/index.js +2 -0
  115. package/dist/gpu-data/index.js.map +1 -1
  116. package/dist/gpu-dataframe/gpu-data-frame-query.cjs +1 -16
  117. package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
  118. package/dist/gpu-dataframe/gpu-data-frame-query.js +1 -23
  119. package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
  120. package/dist/gpu-dataframe/gpu-expression.cjs +91 -2
  121. package/dist/gpu-dataframe/gpu-expression.d.ts +37 -0
  122. package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
  123. package/dist/gpu-dataframe/gpu-expression.js +106 -0
  124. package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
  125. package/dist/gpu-dataframe/index.cjs +12 -2
  126. package/dist/gpu-dataframe/index.cjs.map +3 -3
  127. package/dist/gpu-dataframe/index.d.ts +4 -0
  128. package/dist/gpu-dataframe/index.d.ts.map +1 -1
  129. package/dist/gpu-dataframe/index.js +2 -0
  130. package/dist/gpu-dataframe/index.js.map +1 -1
  131. package/dist/gpu-dataframe/portable-expression.cjs +103 -0
  132. package/dist/gpu-dataframe/portable-expression.d.ts +19 -0
  133. package/dist/gpu-dataframe/portable-expression.d.ts.map +1 -0
  134. package/dist/gpu-dataframe/portable-expression.js +98 -0
  135. package/dist/gpu-dataframe/portable-expression.js.map +1 -0
  136. package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
  137. package/dist/gpu-dggs/index.cjs.map +1 -1
  138. package/dist/gpu-geometry/index.cjs.map +1 -1
  139. package/dist/gpu-graph/index.cjs.map +1 -1
  140. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +2 -2
  141. package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.cjs +2 -15
  142. package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.d.ts.map +1 -1
  143. package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.js +2 -15
  144. package/dist/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.js.map +1 -1
  145. package/dist/gpu-graph-algorithms/index.cjs.map +2 -2
  146. package/dist/gpu-h3/index.cjs.map +1 -1
  147. package/dist/gpu-physics/gpu-rigid-body-world.cjs +3 -1
  148. package/dist/gpu-physics/gpu-rigid-body-world.d.ts +4 -0
  149. package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
  150. package/dist/gpu-physics/gpu-rigid-body-world.js +3 -1
  151. package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
  152. package/dist/gpu-physics/index.cjs.map +1 -1
  153. package/dist/gpu-physics/rigid-body-parallel-shaders.cjs +24 -9
  154. package/dist/gpu-physics/rigid-body-parallel-shaders.d.ts +1 -1
  155. package/dist/gpu-physics/rigid-body-parallel-shaders.d.ts.map +1 -1
  156. package/dist/gpu-physics/rigid-body-parallel-shaders.js +28 -9
  157. package/dist/gpu-physics/rigid-body-parallel-shaders.js.map +1 -1
  158. package/dist/gpu-physics/rigid-body-shaders.cjs +2 -2
  159. package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
  160. package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
  161. package/dist/gpu-physics/rigid-body-shaders.js +2 -2
  162. package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
  163. package/dist/gpu-pointcloud/index.cjs.map +1 -1
  164. package/dist/gpu-project/graph.cjs.map +3 -3
  165. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  166. package/dist/gpu-simple-graph/index.d.ts +1 -1
  167. package/dist/gpu-simple-graph/index.d.ts.map +1 -1
  168. package/dist/gpu-simple-graph/index.js.map +1 -1
  169. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.cjs +2 -0
  170. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js +3 -0
  171. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js.map +1 -1
  172. package/dist/gpu-simple-graph/operations/convert-colors.cjs +6 -6
  173. package/dist/gpu-simple-graph/operations/convert-colors.d.ts +5 -1
  174. package/dist/gpu-simple-graph/operations/convert-colors.d.ts.map +1 -1
  175. package/dist/gpu-simple-graph/operations/convert-colors.js +12 -7
  176. package/dist/gpu-simple-graph/operations/convert-colors.js.map +1 -1
  177. package/dist/gpu-simple-graph/operations/cpu/convert-colors.cjs +16 -33
  178. package/dist/gpu-simple-graph/operations/cpu/convert-colors.d.ts.map +1 -1
  179. package/dist/gpu-simple-graph/operations/cpu/convert-colors.js +22 -35
  180. package/dist/gpu-simple-graph/operations/cpu/convert-colors.js.map +1 -1
  181. package/dist/gpu-simple-graph/operations/cpu/index.cjs.map +3 -3
  182. package/dist/gpu-simple-graph/operations/webgl/index.cjs.map +3 -3
  183. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.cjs +31 -13
  184. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.d.ts.map +1 -1
  185. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js +42 -13
  186. package/dist/gpu-simple-graph/operations/webgpu/convert-colors.js.map +1 -1
  187. package/dist/gpu-simple-graph/operations/webgpu/index.cjs.map +1 -1
  188. package/dist/gpu-sql/gpu-sql.cjs +98 -5
  189. package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
  190. package/dist/gpu-sql/gpu-sql.js +100 -5
  191. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  192. package/dist/gpu-sql/index.cjs.map +2 -2
  193. package/dist/gpu-timeseries/index.cjs.map +1 -1
  194. package/dist/index.cjs.map +1 -1
  195. package/dist/index.d.ts +1 -1
  196. package/dist/index.d.ts.map +1 -1
  197. package/dist/index.js.map +1 -1
  198. package/package.json +8 -7
  199. package/src/arrow/arrow-colors.ts +194 -33
  200. package/src/arrow/gpu/arrow-column-gpu-vector.ts +67 -14
  201. package/src/arrow/gpu/arrow-gpu-vector-adapters.ts +3 -1
  202. package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +46 -4
  203. package/src/arrow/index.ts +2 -0
  204. package/src/geospatial/gpu-point-spatial-query.ts +2 -15
  205. package/src/gpu-core/gpu-command-graph-compiler.ts +25 -2
  206. package/src/gpu-core/gpu-command-graph-types.ts +20 -0
  207. package/src/gpu-core/gpu-command-graph.ts +11 -4
  208. package/src/gpu-core/gpu-dispatch-utils.ts +13 -1
  209. package/src/gpu-core/gpu-expression-operation.ts +1 -1
  210. package/src/gpu-core/gpu-grid-aggregation.ts +2 -5
  211. package/src/gpu-core/gpu-grid-binning.ts +2 -5
  212. package/src/gpu-core/gpu-grid-coordinate.ts +24 -0
  213. package/src/gpu-core/gpu-grid-index-internals.ts +2 -15
  214. package/src/gpu-core/gpu-grid-index-query.ts +2 -16
  215. package/src/gpu-core/gpu-scan.ts +59 -45
  216. package/src/gpu-core/gpu-segmented-reduction.ts +20 -10
  217. package/src/gpu-core/gpu-segmented-scan.ts +82 -17
  218. package/src/gpu-core/index.ts +21 -0
  219. package/src/gpu-data/color-conversion.ts +158 -0
  220. package/src/gpu-data/gpu-vector-wgsl-layout.ts +79 -0
  221. package/src/gpu-data/index.ts +10 -0
  222. package/src/gpu-dataframe/gpu-data-frame-query.ts +6 -26
  223. package/src/gpu-dataframe/gpu-expression.ts +135 -0
  224. package/src/gpu-dataframe/index.ts +11 -0
  225. package/src/gpu-dataframe/portable-expression.ts +117 -0
  226. package/src/gpu-graph-algorithms/gpu-graph-spatial-force-layout-internals.ts +2 -15
  227. package/src/gpu-physics/gpu-rigid-body-world.ts +8 -1
  228. package/src/gpu-physics/rigid-body-parallel-shaders.ts +32 -9
  229. package/src/gpu-physics/rigid-body-shaders.ts +3 -2
  230. package/src/gpu-simple-graph/index.ts +1 -0
  231. package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +2 -0
  232. package/src/gpu-simple-graph/operations/convert-colors.ts +22 -7
  233. package/src/gpu-simple-graph/operations/cpu/convert-colors.ts +31 -48
  234. package/src/gpu-simple-graph/operations/webgpu/convert-colors.ts +47 -13
  235. package/src/gpu-sql/gpu-sql.ts +106 -6
  236. package/src/index.ts +2 -0
@@ -0,0 +1,117 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuDF.
5
+
6
+ import {validateExpressionAST, type Expression} from '@math.gl/expressions';
7
+ import {
8
+ GPUExpression,
9
+ isBooleanExpressionNode,
10
+ makeGPUCastNode,
11
+ type GPUExpressionNode,
12
+ type GPUExpressionBinaryOperator,
13
+ type GPUExpressionNumericValue
14
+ } from './gpu-expression';
15
+
16
+ /**
17
+ * Converts the supported subset of math.gl's portable AST into a DataFrame expression.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import {parseSQLExpression} from '@math.gl/expressions/sql';
22
+ *
23
+ * const position = makeGPUExpressionFromPortableAST(
24
+ * parseSQLExpression('ARRAY[x,y,z]::REAL[3]')
25
+ * );
26
+ * const query = frame.withColumn('position', position, {format: 'float32x3'});
27
+ * ```
28
+ */
29
+ export function makeGPUExpressionFromPortableAST(
30
+ expression: Expression
31
+ ): GPUExpression<GPUExpressionNumericValue | boolean> {
32
+ return new GPUExpression(convertPortableExpression(expression));
33
+ }
34
+
35
+ /** Converts a portable AST and requires a boolean result for use as a DataFrame predicate. */
36
+ export function makeGPUPredicateFromPortableAST(expression: Expression): GPUExpression<boolean> {
37
+ const node = convertPortableExpression(expression);
38
+ if (!isBooleanExpressionNode(node)) {
39
+ throw new Error('Expected a boolean portable GPU dataframe expression');
40
+ }
41
+ return new GPUExpression(node);
42
+ }
43
+
44
+ function convertPortableExpression(expression: Expression): GPUExpressionNode {
45
+ validateExpressionAST(expression);
46
+ return convert(expression);
47
+ }
48
+
49
+ const binaryOperators: Readonly<Record<string, GPUExpressionBinaryOperator>> = {
50
+ '+': 'add',
51
+ '-': 'subtract',
52
+ '*': 'multiply',
53
+ '/': 'divide',
54
+ '==': 'equal',
55
+ '===': 'equal',
56
+ '!=': 'not-equal',
57
+ '!==': 'not-equal',
58
+ '>': 'greater-than',
59
+ '>=': 'greater-than-or-equal',
60
+ '<': 'less-than',
61
+ '<=': 'less-than-or-equal',
62
+ '&&': 'and',
63
+ '||': 'or'
64
+ };
65
+
66
+ /** Lowers one validated portable node and rejects unsupported operations. */
67
+ function convert(expression: Expression): GPUExpressionNode {
68
+ // math.gl's public parser type includes nonportable nodes; validation above narrows at runtime.
69
+ const node = expression as any;
70
+ switch (node.type) {
71
+ case 'Identifier':
72
+ return {kind: 'column', name: node.name};
73
+ case 'Literal':
74
+ if (
75
+ node.value === null ||
76
+ typeof node.value === 'boolean' ||
77
+ (typeof node.value === 'number' && Number.isFinite(node.value))
78
+ )
79
+ return {kind: 'literal', value: node.value};
80
+ break;
81
+ case 'UnaryExpression':
82
+ if (node.operator === '-' || node.operator === '!')
83
+ return {
84
+ kind: 'unary',
85
+ operator: node.operator === '-' ? 'negate' : 'not',
86
+ operand: convert(node.argument)
87
+ };
88
+ break;
89
+ case 'BinaryExpression':
90
+ case 'LogicalExpression': {
91
+ const operator = binaryOperators[node.operator];
92
+ if (operator)
93
+ return {kind: 'binary', operator, left: convert(node.left), right: convert(node.right)};
94
+ break;
95
+ }
96
+ case 'CallExpression': {
97
+ const name = node.callee.name;
98
+ if (name === 'array_float32' && [2, 3, 4].includes(node.arguments.length)) {
99
+ return {
100
+ kind: 'vector',
101
+ format: `float32x${node.arguments.length}` as 'float32x2' | 'float32x3' | 'float32x4',
102
+ components: node.arguments.map(convert)
103
+ };
104
+ }
105
+ if (name === 'cast' && node.arguments.length === 2 && node.arguments[1].type === 'Literal') {
106
+ const target = node.arguments[1].value;
107
+ if (target === 'float32' || target === 'int32')
108
+ return makeGPUCastNode(
109
+ convert(node.arguments[0]),
110
+ target === 'int32' ? 'sint32' : 'float32'
111
+ );
112
+ }
113
+ break;
114
+ }
115
+ }
116
+ throw new Error('Unsupported portable GPU dataframe expression');
117
+ }
@@ -3,6 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
  // SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuGraph.
5
5
 
6
+ import {GPU_GRID_COORDINATE_WGSL} from '../gpu-core/gpu-grid-coordinate';
6
7
  import {addGPUCommandNodes} from '@luma.gl/graph/gpu-core';
7
8
  import {type Binding} from '@luma.gl/core';
8
9
  import {Kernel} from '../execution/compute/kernel';
@@ -423,21 +424,7 @@ const CELL_CENTERS_OFFSET: u32 = ${getViewElementOffset(state.cellCenters)}u;
423
424
  const VALIDITY_OFFSET: u32 = ${getViewElementOffset(state.validity)}u;
424
425
  ${getBindingDeclarations(bindings)}
425
426
 
426
- fn getCoordinate(value: f32, minimum: f32, maximum: f32, size: u32) -> u32 {
427
- if (maximum == minimum || value == minimum) { return 0u; }
428
- if (value == maximum) { return size - 1u; }
429
- if (minimum < 0.0 && maximum > 0.0) {
430
- let scale = max(abs(minimum), abs(maximum));
431
- let scaledValue = value / scale;
432
- let scaledMinimum = minimum / scale;
433
- let scaledMaximum = maximum / scale;
434
- return min(
435
- u32((scaledValue - scaledMinimum) / (scaledMaximum - scaledMinimum) * f32(size)),
436
- size - 1u
437
- );
438
- }
439
- return min(u32((value - minimum) / (maximum - minimum) * f32(size)), size - 1u);
440
- }
427
+ ${GPU_GRID_COORDINATE_WGSL}
441
428
 
442
429
  fn readPosition(vertex: u32) -> vec2<f32> {
443
430
  let positionOffset = POSITIONS_OFFSET + vertex * 2u;
@@ -139,6 +139,10 @@ export type GPURigidBodyWorldProps = {
139
139
  maximumRecoverySpeed?: number;
140
140
  /** Additional under-relaxation for the parallel solver, in (0, 1]. Default 1. */
141
141
  parallelRelaxation?: number;
142
+ /** Contact scheduling within a parallel manifold. Block uses two local sweeps before gathering.
143
+ * Default scalar preserves the original per-contact relaxation path.
144
+ */
145
+ parallelContactSolver?: 'scalar' | 'block';
142
146
  /** Small worlds retain the all-pairs numerical oracle; larger worlds use sparse discovery. */
143
147
  /** Independent equal collider blocks; currently excludes joints, CCD and authored triggers. */
144
148
  collisionPartitionSize?: number;
@@ -271,6 +275,8 @@ export class GPURigidBodyWorld {
271
275
  this.solver = props.solver ?? 'ordered';
272
276
  if (!['ordered', 'parallel'].includes(this.solver))
273
277
  throw new Error('Invalid rigid-body solver');
278
+ if (!['scalar', 'block'].includes(props.parallelContactSolver ?? 'scalar'))
279
+ throw new Error('Invalid parallel contact solver');
274
280
  validateRigidBodyJoints(props.joints ?? [], props.bodies, this.solver);
275
281
  const colliderCount = props.bodies.reduce(
276
282
  (sum, body) => sum + (body.colliders?.length ?? 1),
@@ -1043,7 +1049,8 @@ export class GPURigidBodyWorld {
1043
1049
  this.props.joints?.length ?? 0,
1044
1050
  this.props.compactContacts ?? true,
1045
1051
  this.props.collisionPartitionSize,
1046
- this.props.ensembleBodiesPerInstance
1052
+ this.props.ensembleBodiesPerInstance,
1053
+ this.props.parallelContactSolver === 'block'
1047
1054
  );
1048
1055
  const parallelBindings: Record<string, readonly string[]> = {
1049
1056
  parallelReset: ['parallelState'],
@@ -3,7 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  /** Sparse contact adjacency and block-Jacobi impulses; each dispatch has exclusive output owners. */
6
- export function getRigidBodyParallelShader(ensemble: boolean): string {
6
+ export function getRigidBodyParallelShader(ensemble: boolean, blockContacts = false): string {
7
7
  return /* wgsl */ `
8
8
  struct ParallelState {
9
9
  diagnostics:array<atomic<u32>,4>,
@@ -173,32 +173,55 @@ fn writePairDeltas(pair:u32,first:u32,second:u32,impulse:vec3f,firstTorque:vec3f
173
173
  let relaxation=settings.stability.w/f32(max(1u,max(atomicLoad(&parallelState.degrees[first]),atomicLoad(&parallelState.degrees[second]))));
174
174
  var firstLinear=velocities[first].xyz;var secondLinear=velocities[second].xyz;
175
175
  var firstAngular=angularVelocities[first].xyz;var secondAngular=angularVelocities[second].xyz;
176
+ ${
177
+ blockContacts
178
+ ? `
179
+ // Solve the contact patch locally, then relax the whole block once. No extra dispatches.
180
+ var contacts:array<Contact,4>;
181
+ for(var slot=0u;slot<manifolds[pair].count;slot++){contacts[slot]=manifolds[pair].contacts[slot];}
182
+ for(var sweep=0u;sweep<2u;sweep++){
183
+ `
184
+ : ''
185
+ }
176
186
  for(var slot=0u;slot<manifolds[pair].count;slot++){
177
- var contact=manifolds[pair].contacts[slot];let point=contact.point.xyz;let normal=contact.normal.xyz;
187
+ var contact=${blockContacts ? 'contacts[slot]' : 'manifolds[pair].contacts[slot]'};let point=contact.point.xyz;let normal=contact.normal.xyz;
178
188
  let firstLever=point-positions[first].xyz;let secondLever=point-positions[second].xyz;
179
189
  let relative=secondLinear+cross(secondAngular,secondLever)-firstLinear-cross(firstAngular,firstLever);
180
190
  let normalMass=effectiveMass(first,second,point,normal);if(normalMass<=0.0){continue;}
181
191
  let bias=min(settings.stability.z,settings.stability.y*max(0.0,contact.point.w-settings.solver.x)/settings.gravity.w);
182
192
  let desiredImpulse=max(0.0,contact.impulse.x+(max(bias,contact.normal.w)-dot(relative,normal))/normalMass);
183
- let change=(desiredImpulse-contact.impulse.x)*relaxation;contact.impulse.x+=change;
193
+ let change=(desiredImpulse-contact.impulse.x)*${blockContacts ? '1.0' : 'relaxation'};contact.impulse.x+=change;
184
194
  var impulse=normal*change;
185
195
  if(dynamic(first)){firstLinear-=impulse*velocities[first].w;firstAngular-=inverseInertia(first,cross(firstLever,impulse));}
186
196
  if(dynamic(second)){secondLinear+=impulse*velocities[second].w;secondAngular+=inverseInertia(second,cross(secondLever,impulse));}
187
197
  let after=secondLinear+cross(secondAngular,secondLever)-firstLinear-cross(firstAngular,firstLever);
188
198
  let tangent=solveFriction(firstCollider,secondCollider,contact,after);
189
- var relaxedTangent=contact.tangent.xyz+(tangent-contact.tangent.xyz)*relaxation;
199
+ var relaxedTangent=contact.tangent.xyz+(tangent-contact.tangent.xyz)*${blockContacts ? '1.0' : 'relaxation'};
190
200
  // A falling normal impulse must shrink the cone even when under-relaxing.
191
201
  let staticLimit=frictionCoefficient(firstCollider,secondCollider,false)*contact.impulse.x;
192
202
  if(length(relaxedTangent)>staticLimit){relaxedTangent*=staticLimit/max(1e-30,length(relaxedTangent));}
193
203
  impulse=relaxedTangent-contact.tangent.xyz;contact.tangent=vec4f(relaxedTangent,0);
194
204
  if(dynamic(first)){firstLinear-=impulse*velocities[first].w;firstAngular-=inverseInertia(first,cross(firstLever,impulse));}
195
205
  if(dynamic(second)){secondLinear+=impulse*velocities[second].w;secondAngular+=inverseInertia(second,cross(secondLever,impulse));}
196
- manifolds[pair].contacts[slot]=contact;
206
+ ${blockContacts ? 'contacts[slot]' : 'manifolds[pair].contacts[slot]'}=contact;
207
+ }
208
+ ${
209
+ blockContacts
210
+ ? `
211
+ }
212
+ // Interpolation of feasible impulses preserves the friction cone, including unloading.
213
+ for(var slot=0u;slot<manifolds[pair].count;slot++){
214
+ let previous=manifolds[pair].contacts[slot];
215
+ manifolds[pair].contacts[slot].impulse.x=mix(previous.impulse.x,contacts[slot].impulse.x,relaxation);
216
+ manifolds[pair].contacts[slot].tangent=mix(previous.tangent,contacts[slot].tangent,relaxation);
217
+ }
218
+ `
219
+ : ''
197
220
  }
198
- parallelState.deltas[pair*4u]=vec4f(firstLinear-velocities[first].xyz,0);
199
- parallelState.deltas[pair*4u+1u]=vec4f(firstAngular-angularVelocities[first].xyz,0);
200
- parallelState.deltas[pair*4u+2u]=vec4f(secondLinear-velocities[second].xyz,0);
201
- parallelState.deltas[pair*4u+3u]=vec4f(secondAngular-angularVelocities[second].xyz,0);
221
+ parallelState.deltas[pair*4u]=vec4f((firstLinear-velocities[first].xyz)*${blockContacts ? 'relaxation' : '1.0'},0);
222
+ parallelState.deltas[pair*4u+1u]=vec4f((firstAngular-angularVelocities[first].xyz)*${blockContacts ? 'relaxation' : '1.0'},0);
223
+ parallelState.deltas[pair*4u+2u]=vec4f((secondLinear-velocities[second].xyz)*${blockContacts ? 'relaxation' : '1.0'},0);
224
+ parallelState.deltas[pair*4u+3u]=vec4f((secondAngular-angularVelocities[second].xyz)*${blockContacts ? 'relaxation' : '1.0'},0);
202
225
  }
203
226
  @compute @workgroup_size(64) fn parallelGather(@builtin(global_invocation_id) invocation:vec3u){
204
227
  var body=invocation.x;
@@ -29,7 +29,8 @@ export function getRigidBodyShader(
29
29
  jointCount = 0,
30
30
  compactContacts = true,
31
31
  collisionPartitionSize?: number,
32
- ensembleBodiesPerInstance?: number
32
+ ensembleBodiesPerInstance?: number,
33
+ blockContacts = false
33
34
  ): string {
34
35
  return /* wgsl */ `
35
36
  const COMPACT_CONTACTS:bool=${compactContacts};
@@ -390,7 +391,7 @@ ${
390
391
  }
391
392
  manifolds[pair].count=contactCount;
392
393
  }
393
- ${parallel ? getRigidBodyParallelShader(Boolean(ensembleBodiesPerInstance)) : ''}
394
+ ${parallel ? getRigidBodyParallelShader(Boolean(ensembleBodiesPerInstance), blockContacts) : ''}
394
395
  ${(parallel || hasJoints) && extended ? '@compute @workgroup_size(1) fn meshCollect(){collectMeshContacts();}' : ''}
395
396
  ${jointShader}
396
397
  ${parallel && hasJoints ? '@compute @workgroup_size(1) fn parallelJointWarm(){solveJoints(true);} @compute @workgroup_size(1) fn parallelJointSolve(){solveJoints(false);}' : ''}
@@ -63,6 +63,7 @@ export {extent} from './operations/extent';
63
63
  export {convertColorData} from './operations/convert-colors';
64
64
  export type {
65
65
  ColorInputFormat,
66
+ ColorOutputFormat,
66
67
  ConvertColorsInputs,
67
68
  ConvertColorsProps
68
69
  } from './operations/convert-colors';
@@ -929,6 +929,8 @@ function getVertexFormat(
929
929
  if (size < 1 || size > 4) {
930
930
  throw new Error(`Cannot synthesize a GPUVector vertex format with ${size} components`);
931
931
  }
932
+ // Binary16 RGB has no vertex format; retain byte-identical packed storage for compute readers.
933
+ if (type === 'float16' && size === 3 && !normalized) return 'uint16x3-webgl';
932
934
  let baseFormat: string = type;
933
935
  if (normalized) {
934
936
  switch (type) {
@@ -8,6 +8,7 @@ import {
8
8
  type GPUDataEvaluatorInput
9
9
  } from '../operation/gpu-data-evaluator';
10
10
  import {Operation} from '../operation/operation';
11
+ import type {ColorOutputFormat} from '../../gpu-data/color-conversion';
11
12
 
12
13
  export type ColorInputFormat =
13
14
  | 'uint8x3'
@@ -17,13 +18,17 @@ export type ColorInputFormat =
17
18
  | 'float32x3'
18
19
  | 'float32x4';
19
20
 
21
+ export type {ColorOutputFormat} from '../../gpu-data/color-conversion';
22
+
20
23
  export type ConvertColorsProps = {
24
+ format?: ColorOutputFormat;
21
25
  inputFormat?: ColorInputFormat;
22
26
  };
23
27
 
24
28
  export type ConvertColorsInputs = {
25
29
  source: GPUDataEvaluator;
26
30
  inputFormat: ColorInputFormat;
31
+ outputFormat: ColorOutputFormat;
27
32
  };
28
33
 
29
34
  class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
@@ -31,15 +36,24 @@ class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
31
36
 
32
37
  output: GPUDataEvaluator;
33
38
 
34
- constructor(source: GPUDataEvaluator, inputFormat: ColorInputFormat) {
35
- super({source, inputFormat});
39
+ constructor(
40
+ source: GPUDataEvaluator,
41
+ inputFormat: ColorInputFormat,
42
+ outputFormat: ColorOutputFormat
43
+ ) {
44
+ super({source, inputFormat, outputFormat});
36
45
 
37
46
  this.output = new GPUDataEvaluator({
38
47
  id: `convertColors(${source})`,
39
- type: 'uint8',
48
+ type:
49
+ outputFormat === 'unorm8x4'
50
+ ? 'uint8'
51
+ : outputFormat === 'float16x4'
52
+ ? 'float16'
53
+ : 'float32',
40
54
  size: 4,
41
- normalized: true,
42
- format: 'unorm8x4',
55
+ normalized: outputFormat === 'unorm8x4',
56
+ format: outputFormat,
43
57
  length: source.length,
44
58
  source: this
45
59
  });
@@ -50,14 +64,15 @@ class ConvertColorsOperation extends Operation<ConvertColorsInputs> {
50
64
  }
51
65
  }
52
66
 
53
- /** Converts one fixed-width GPU data range to normalized Uint8 RGBA values. */
67
+ /** Converts one fixed-width color range to RGBA8, binary16 or binary32 RGBA storage. */
54
68
  export function convertColorData(
55
69
  source: GPUDataEvaluatorInput,
56
70
  props: ConvertColorsProps = {}
57
71
  ): GPUDataEvaluator {
58
72
  const sourceEvaluator = getGPUDataEvaluator(source);
59
73
  const inputFormat = props.inputFormat ?? getColorInputFormat(sourceEvaluator);
60
- return new ConvertColorsOperation(sourceEvaluator, inputFormat).output;
74
+ return new ConvertColorsOperation(sourceEvaluator, inputFormat, props.format ?? 'unorm8x4')
75
+ .output;
61
76
  }
62
77
 
63
78
  function getColorInputFormat(source: GPUDataEvaluator): ColorInputFormat {
@@ -2,55 +2,38 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import {fromHalfFloat} from '@luma.gl/shaders';
6
- import type {TypedArray} from '@math.gl/core';
5
+ import {CPUData} from '../../../gpu-data/cpu-data';
6
+ import {convertCPUColorData} from '../../../gpu-data/color-conversion';
7
7
  import type {OperationHandler} from '../../operation/operation';
8
8
  import type {ConvertColorsInputs} from '../convert-colors';
9
9
 
10
- export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
11
- inputs,
12
- output,
13
- target
14
- }) => {
15
- const {source, inputFormat} = inputs;
16
- const sourceValue = await source.ensureCPUValue();
17
- const result = new output.ValueType(output.length * output.size);
18
- const inputSize = inputFormat.endsWith('x3') ? 3 : 4;
19
-
20
- for (let rowIndex = 0; rowIndex < output.length; rowIndex++) {
21
- const inputOffset =
22
- source.offset / source.ValueType.BYTES_PER_ELEMENT +
23
- rowIndex * (source.stride / source.ValueType.BYTES_PER_ELEMENT);
24
- const outputOffset = rowIndex * 4;
25
-
26
- result[outputOffset] = convertColorChannel(sourceValue, inputOffset, inputFormat);
27
- result[outputOffset + 1] = convertColorChannel(sourceValue, inputOffset + 1, inputFormat);
28
- result[outputOffset + 2] = convertColorChannel(sourceValue, inputOffset + 2, inputFormat);
29
- result[outputOffset + 3] =
30
- inputSize === 4 ? convertColorChannel(sourceValue, inputOffset + 3, inputFormat) : 255;
31
- }
32
-
33
- target.write(result);
34
- return {success: true, value: result};
10
+ export const convertColors: OperationHandler<ConvertColorsInputs> = async ({inputs, target}) => {
11
+ const {source, inputFormat, outputFormat} = inputs;
12
+ const values = await source.ensureCPUValue();
13
+ const format =
14
+ source.format ??
15
+ (inputFormat === 'uint8x3'
16
+ ? 'uint8x3-webgl'
17
+ : inputFormat === 'float16x3'
18
+ ? 'uint16x3-webgl'
19
+ : inputFormat);
20
+ const converted = convertCPUColorData(
21
+ new CPUData({
22
+ buffer: values,
23
+ format,
24
+ length: source.length,
25
+ byteOffset: source.offset,
26
+ byteStride: source.stride
27
+ }),
28
+ outputFormat,
29
+ inputFormat
30
+ );
31
+ const bytes = new Uint8Array(
32
+ converted.buffer,
33
+ converted.byteOffset,
34
+ converted.length * converted.byteStride
35
+ );
36
+ target.write(bytes);
37
+ // Let the evaluator decode the target in its own Float16Array/Uint16Array representation.
38
+ return {success: true};
35
39
  };
36
-
37
- function convertColorChannel(values: TypedArray, index: number, inputFormat: string): number {
38
- if (inputFormat.startsWith('uint8')) {
39
- return values[index];
40
- }
41
-
42
- const value = inputFormat.startsWith('float16') ? getFloat16Value(values, index) : values[index];
43
- return Math.round(Math.min(Math.max(value, 0), 1) * 255);
44
- }
45
-
46
- function getFloat16Value(values: TypedArray, index: number): number {
47
- const Float16ArrayConstructor = getNativeFloat16ArrayConstructor();
48
- if (Float16ArrayConstructor && values.constructor === Float16ArrayConstructor) {
49
- return values[index];
50
- }
51
- return fromHalfFloat(values[index]);
52
- }
53
-
54
- function getNativeFloat16ArrayConstructor(): unknown {
55
- return (globalThis as typeof globalThis & {Float16Array?: unknown}).Float16Array;
56
- }
@@ -13,11 +13,19 @@ const COMPUTATION_RUNS = 'Computation Runs';
13
13
  export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
14
14
  inputs,
15
15
  output,
16
- target
16
+ target,
17
+ scope
17
18
  }) => {
18
19
  const {source, inputFormat} = inputs;
20
+ if (output.length === 0) return {success: true};
19
21
  const kernel = new Kernel(target.device, {
20
- source: getConvertColorsWGSL(inputFormat, source.offset, source.stride, output.length),
22
+ source: getConvertColorsWGSL(
23
+ inputFormat,
24
+ source.offset,
25
+ source.stride,
26
+ output.length,
27
+ inputs.outputFormat
28
+ ),
21
29
  shaderLayout: {
22
30
  bindings: [
23
31
  {name: 'source', type: 'storage' as const, group: 0, location: 0},
@@ -31,23 +39,38 @@ export const convertColors: OperationHandler<ConvertColorsInputs> = async ({
31
39
  result: target
32
40
  };
33
41
 
34
- const computePass = target.device.beginComputePass({});
35
- target.device.statsManager.getStats(GPGPU_OPERATION_STATS).get(COMPUTATION_RUNS).incrementCount();
36
- kernel.dispatch(computePass, {
37
- bindings: kernelBindings,
38
- x: Math.ceil(output.length / WORKGROUP_SIZE)
39
- });
40
- computePass.end();
41
- target.device.submit();
42
- kernel.destroy();
42
+ if (scope) scope.retain(() => kernel.destroy());
43
+ try {
44
+ const computePass = scope
45
+ ? scope.commandEncoder.beginComputePass({})
46
+ : target.device.beginComputePass({});
47
+ try {
48
+ target.device.statsManager
49
+ .getStats(GPGPU_OPERATION_STATS)
50
+ .get(COMPUTATION_RUNS)
51
+ .incrementCount();
52
+ kernel.dispatch(computePass, {
53
+ bindings: kernelBindings,
54
+ x: Math.ceil(output.length / WORKGROUP_SIZE)
55
+ });
56
+ } finally {
57
+ computePass.end();
58
+ }
59
+ if (!scope) target.device.submit();
60
+ } finally {
61
+ if (!scope) kernel.destroy();
62
+ }
63
+
43
64
  return {success: true};
44
65
  };
66
+ convertColors.supportsEvaluationScope = true;
45
67
 
46
68
  function getConvertColorsWGSL(
47
69
  inputFormat: ConvertColorsInputs['inputFormat'],
48
70
  byteOffset: number,
49
71
  byteStride: number,
50
- length: number
72
+ length: number,
73
+ outputFormat: ConvertColorsInputs['outputFormat']
51
74
  ): string {
52
75
  return /* wgsl */ `\
53
76
  @group(0) @binding(0) var<storage, read> source: array<u32>;
@@ -90,7 +113,18 @@ ${getReadColorWGSL(inputFormat)}
90
113
  return;
91
114
  }
92
115
 
93
- result[rowIndex] = pack4x8unorm(readColor(rowIndex));
116
+ let color = readColor(rowIndex);
117
+ ${
118
+ outputFormat === 'unorm8x4'
119
+ ? ' result[rowIndex] = pack4x8unorm(color);'
120
+ : outputFormat === 'float16x4'
121
+ ? ` result[rowIndex * 2u] = pack2x16float(color.xy);
122
+ result[rowIndex * 2u + 1u] = pack2x16float(color.zw);`
123
+ : ` result[rowIndex * 4u] = bitcast<u32>(color.x);
124
+ result[rowIndex * 4u + 1u] = bitcast<u32>(color.y);
125
+ result[rowIndex * 4u + 2u] = bitcast<u32>(color.z);
126
+ result[rowIndex * 4u + 3u] = bitcast<u32>(color.w);`
127
+ }
94
128
  }
95
129
  `;
96
130
  }