@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
@@ -3,9 +3,10 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {type GPUCommandNode, createGPUComputeCommandNode} from './gpu-command-node';
6
- import type {Binding} from '@luma.gl/core';
6
+ import type {Binding, ComputeShaderLayout} from '@luma.gl/core';
7
7
  import {Kernel} from '../execution/compute/kernel';
8
8
  import {GPUCommandGraph, type GraphDataView} from './gpu-command-graph';
9
+ import {getBoundedWorkgroupLayout, type GPUBoundedDispatchLayout} from './gpu-dispatch-utils';
9
10
  import {
10
11
  getViewBinding,
11
12
  getViewElementOffset,
@@ -66,16 +67,35 @@ export class GPUSegmentedScan {
66
67
  throw new Error(`${this.id} views must belong to target graph`);
67
68
  }
68
69
  const segmentCount = this.segmentOffsets.length - 1;
69
- if (segmentCount === 0) return nodes;
70
- const source = makeShaderSource(this);
70
+ if (segmentCount === 0 || this.input.length === 0) return nodes;
71
+ const dispatch = getBoundedWorkgroupLayout(
72
+ this.id,
73
+ segmentCount,
74
+ graph.device.limits.maxComputeWorkgroupsPerDimension
75
+ );
76
+ const workgroupCount = dispatch.x * dispatch.y * dispatch.z;
77
+ const source = makeShaderSource(this, dispatch, segmentCount);
78
+ const shaderLayout: ComputeShaderLayout = {
79
+ bindings: [
80
+ {name: 'inputValues', type: 'read-only-storage', group: 0, location: 0},
81
+ {name: 'segmentOffsets', type: 'read-only-storage', group: 0, location: 1},
82
+ {name: 'outputValues', type: 'storage', group: 0, location: 2}
83
+ ]
84
+ };
71
85
  nodes.push(
72
86
  createGPUComputeCommandNode<Parameters>({
73
87
  id: this.id,
88
+ kernel: {
89
+ entryPoint: 'main',
90
+ workgroupSize: [WORKGROUP_SIZE, 1, 1],
91
+ bindings: shaderLayout.bindings,
92
+ source
93
+ },
74
94
  workload: {
75
95
  operation: 'GPUSegmentedScan',
76
96
  commandCount: 1,
77
- maximumWorkgroupCount: segmentCount,
78
- maximumInvocationCount: segmentCount * WORKGROUP_SIZE,
97
+ maximumWorkgroupCount: workgroupCount,
98
+ maximumInvocationCount: workgroupCount * WORKGROUP_SIZE,
79
99
  readByteLength: this.input.length * 4 + this.segmentOffsets.length * 4,
80
100
  writeByteLength: this.output.length * 4
81
101
  },
@@ -88,13 +108,7 @@ export class GPUSegmentedScan {
88
108
  const kernel = new Kernel(device, {
89
109
  id: this.id,
90
110
  source,
91
- shaderLayout: {
92
- bindings: [
93
- {name: 'inputValues', type: 'read-only-storage', group: 0, location: 0},
94
- {name: 'segmentOffsets', type: 'read-only-storage', group: 0, location: 1},
95
- {name: 'outputValues', type: 'storage', group: 0, location: 2}
96
- ]
97
- }
111
+ shaderLayout
98
112
  });
99
113
  return {
100
114
  encode: ({computePass, getBuffer}) => {
@@ -104,7 +118,7 @@ export class GPUSegmentedScan {
104
118
  outputValues: getViewBinding(this.output, getBuffer)
105
119
  };
106
120
 
107
- kernel.dispatch(computePass, {bindings, x: segmentCount, y: 1, z: 1});
121
+ kernel.dispatch(computePass, {bindings, ...dispatch});
108
122
  },
109
123
  destroy: () => kernel.destroy()
110
124
  };
@@ -116,8 +130,59 @@ export class GPUSegmentedScan {
116
130
  }
117
131
  }
118
132
 
119
- function makeShaderSource(scan: GPUSegmentedScan): string {
120
- return `const INPUT_OFFSET:u32=${getViewElementOffset(scan.input)}u; const SEGMENT_OFFSET:u32=${getViewElementOffset(scan.segmentOffsets)}u; const OUTPUT_OFFSET:u32=${getViewElementOffset(scan.output)}u; const INCLUSIVE:bool=${scan.mode === 'inclusive'};
121
- @group(0) @binding(0) var<storage,read> inputValues:array<u32>; @group(0) @binding(1) var<storage,read> segmentOffsets:array<u32>; @group(0) @binding(2) var<storage,read_write> outputValues:array<u32>;
122
- @compute @workgroup_size(${WORKGROUP_SIZE}) fn main(@builtin(workgroup_id) wg:vec3u,@builtin(local_invocation_index) lane:u32){let segment=wg.x;let begin=segmentOffsets[SEGMENT_OFFSET+segment];let end=segmentOffsets[SEGMENT_OFFSET+segment+1u];if(lane!=0u){return;}var sum=0u;var i=begin;loop{if(i>=end){break;}let value=inputValues[INPUT_OFFSET+i];outputValues[OUTPUT_OFFSET+i]=select(sum,sum+value,INCLUSIVE);sum+=value;i+=1u;}}`;
133
+ function makeShaderSource(
134
+ scan: GPUSegmentedScan,
135
+ dispatch: GPUBoundedDispatchLayout,
136
+ segmentCount: number
137
+ ): string {
138
+ return `const INPUT_OFFSET: u32 = ${getViewElementOffset(scan.input)}u;
139
+ const SEGMENT_OFFSET: u32 = ${getViewElementOffset(scan.segmentOffsets)}u;
140
+ const OUTPUT_OFFSET: u32 = ${getViewElementOffset(scan.output)}u;
141
+ const INPUT_LENGTH: u32 = ${scan.input.length}u;
142
+ @group(0) @binding(0) var<storage, read> inputValues: array<u32>;
143
+ @group(0) @binding(1) var<storage, read> segmentOffsets: array<u32>;
144
+ @group(0) @binding(2) var<storage, read_write> outputValues: array<u32>;
145
+ var<workgroup> prefixes: array<u32, ${WORKGROUP_SIZE}>;
146
+ var<workgroup> segmentBounds: array<u32, 2>;
147
+
148
+
149
+ @compute @workgroup_size(${WORKGROUP_SIZE})
150
+ fn main(
151
+ @builtin(workgroup_id) workgroup: vec3u,
152
+ @builtin(local_invocation_index) lane: u32
153
+ ) {
154
+ let segment = (workgroup.z * ${dispatch.y}u + workgroup.y) * ${dispatch.x}u + workgroup.x;
155
+ if (segment >= ${segmentCount}u) { return; }
156
+ if (lane == 0u) {
157
+ segmentBounds[0] = min(segmentOffsets[SEGMENT_OFFSET + segment], INPUT_LENGTH);
158
+ segmentBounds[1] = min(segmentOffsets[SEGMENT_OFFSET + segment + 1u], INPUT_LENGTH);
159
+ }
160
+ let begin = workgroupUniformLoad(&segmentBounds[0]);
161
+ let end = workgroupUniformLoad(&segmentBounds[1]);
162
+ var carry = 0u;
163
+ for (var tile = begin; tile < end;) {
164
+ let tileLength = min(end - tile, ${WORKGROUP_SIZE}u);
165
+ var value = 0u;
166
+ if (lane < tileLength) {
167
+ value = inputValues[INPUT_OFFSET + tile + lane];
168
+ }
169
+ prefixes[lane] = value;
170
+ workgroupBarrier();
171
+
172
+ for (var stride = 1u; stride < ${WORKGROUP_SIZE}u; stride *= 2u) {
173
+ var previous = 0u;
174
+ if (lane >= stride) { previous = prefixes[lane - stride]; }
175
+ workgroupBarrier();
176
+ prefixes[lane] += previous;
177
+ workgroupBarrier();
178
+ }
179
+
180
+ if (lane < tileLength) {
181
+ outputValues[OUTPUT_OFFSET + tile + lane] = carry + prefixes[lane]${scan.mode === 'exclusive' ? ' - value' : ''};
182
+ }
183
+ carry += prefixes[${WORKGROUP_SIZE - 1}u];
184
+ workgroupBarrier();
185
+ tile += tileLength;
186
+ }
187
+ }`;
123
188
  }
@@ -46,6 +46,8 @@ export type {
46
46
  GPUCommandGraphNodeTiming,
47
47
  GPUCommandGraphNodeType,
48
48
  GPUCommandGraphNodePreflight,
49
+ GPUCommandGraphCompileOptions,
50
+ GPUCommandGraphKernelMetadata,
49
51
  GPUCommandGraphResourceSummary,
50
52
  GPUCommandGraphNodePublication,
51
53
  GPUCommandGraphNodeWorkloadEstimate,
@@ -140,6 +142,8 @@ export {GPUByteRangeGather} from './gpu-byte-range-gather';
140
142
  export type {GPUByteRangeGatherProps} from './gpu-byte-range-gather';
141
143
  export {GPUGather} from './gpu-gather';
142
144
  export type {GPUGatherFormat, GPUGatherProps} from './gpu-gather';
145
+ export {GPUScatter} from './gpu-scatter';
146
+ export type {GPUScatterFormat, GPUScatterProps} from './gpu-scatter';
143
147
  export {
144
148
  GPULZByteDecompressor,
145
149
  GPU_LZ_BYTE_DESCRIPTOR_WORDS,
@@ -177,6 +181,15 @@ export type {
177
181
  GPUWorkgroupReductionBenchmarkReport,
178
182
  GPUWorkgroupReductionBenchmarkStrategy
179
183
  } from './gpu-workgroup-reduction-benchmark';
184
+ export {GPUSegmentedScan} from './gpu-segmented-scan';
185
+ export type {GPUSegmentedScanMode, GPUSegmentedScanProps} from './gpu-segmented-scan';
186
+
187
+ export {GPUSegmentedReduction} from './gpu-segmented-reduction';
188
+ export type {
189
+ GPUSegmentedReductionOperation,
190
+ GPUSegmentedReductionProps
191
+ } from './gpu-segmented-reduction';
192
+
180
193
  export {GPUSegmentedSort} from './gpu-segmented-sort';
181
194
  export type {GPUSegmentedSortProps, GPUSortSegment} from './gpu-segmented-sort';
182
195
  export {GPUCompaction} from './gpu-compaction';
@@ -392,6 +405,8 @@ export type {
392
405
  GPUHistogramProps
393
406
  } from './gpu-histogram';
394
407
 
408
+ export {GPU_GRID_COORDINATE_WGSL} from './gpu-grid-coordinate';
409
+
395
410
  export {GPUGridBinning} from './gpu-grid-binning';
396
411
  export type {
397
412
  GPUGridBinningBounds,
@@ -637,6 +652,12 @@ export {GPUGraphDotProduct, GPUGraphVectorMADD} from './gpu-semantic-vector-oper
637
652
  export {GPUGraphCSRMatrix, GPUGraphSpMV} from './gpu-semantic-spmv';
638
653
  export {createGPUConjugateGradientGraph} from './gpu-conjugate-gradient-program';
639
654
 
655
+ export {GPUAdaptiveSpMV} from './gpu-adaptive-spmv';
656
+ export type {GPUAdaptiveSpMVProps} from './gpu-adaptive-spmv';
657
+ export type {GPUSpMVRowStatistics, GPUSpMVStrategyId} from './gpu-spmv-strategy';
658
+ export {GPUJacobiPCG} from './gpu-pcg';
659
+ export type {GPUJacobiPCGProps, GPUJacobiPCGResult} from './gpu-pcg';
660
+
640
661
  export {GPUCOOToCSR} from './gpu-coo-to-csr';
641
662
  export type {GPUCOOToCSRProps} from './gpu-coo-to-csr';
642
663
  export {GPURunLengthEncode, GPUUnique} from './gpu-run-length-encode';
@@ -0,0 +1,158 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {assert} from '@luma.gl/core';
6
+ import {fromHalfFloat} from '@luma.gl/shaders';
7
+ import {CPUData} from './cpu-data';
8
+ import {CPUVector} from './cpu-vector';
9
+ import {getGPUVectorFormatInfo, type GPUVectorFormat} from './gpu-vector-format';
10
+
11
+ export type ColorOutputFormat = 'unorm8x4' | 'float16x4' | 'float32x4';
12
+ export type ColorConversionOptions = {
13
+ /** Default RGBA8; preserve keeps source precision while expanding RGB to RGBA. */
14
+ format?: ColorOutputFormat | 'preserve';
15
+ /** Consumer capabilities; never silently select a lossy fallback. */
16
+ acceptedFormats?: readonly ColorOutputFormat[];
17
+ fallbackFormat?: ColorOutputFormat;
18
+ };
19
+
20
+ /** Resolve color storage independently from the device and conversion backend. */
21
+ export function resolveColorOutputFormat(
22
+ sourceFormat: GPUVectorFormat,
23
+ options: ColorConversionOptions = {}
24
+ ): ColorOutputFormat {
25
+ const info = getGPUVectorFormatInfo(sourceFormat);
26
+ // Only fixed-width byte/IEEE RGB or RGBA rows have color semantics here.
27
+ assert(
28
+ !info.vertexList &&
29
+ !info.valueList &&
30
+ !info.fixedSizeList &&
31
+ (info.components === 3 || info.components === 4) &&
32
+ ['uint8', 'float16', 'float32'].includes(info.signedDataType)
33
+ );
34
+ const preserved =
35
+ info.signedDataType === 'float32'
36
+ ? 'float32x4'
37
+ : info.signedDataType === 'float16'
38
+ ? 'float16x4'
39
+ : 'unorm8x4';
40
+ let format = options.format === 'preserve' ? preserved : (options.format ?? 'unorm8x4');
41
+ if (options.acceptedFormats && !options.acceptedFormats.includes(format)) {
42
+ if (
43
+ options.format === 'preserve' &&
44
+ options.fallbackFormat &&
45
+ options.acceptedFormats.includes(options.fallbackFormat)
46
+ )
47
+ format = options.fallbackFormat;
48
+ else throw new Error('Requested color format is not accepted by the consumer');
49
+ }
50
+ return format;
51
+ }
52
+
53
+ /** CPU storage interpretation, independent of output format negotiation. */
54
+ type CPUColorConversionOptions = ColorConversionOptions & {
55
+ /** Interpret packed Float16 RGB stored using the uint16x3-webgl alias. */
56
+ inputFormat?: 'float16x3';
57
+ };
58
+
59
+ /** Convert CPU color chunks without uploading or combining chunks. Input storage is borrowed. */
60
+ export function convertCPUColors(
61
+ source: CPUVector,
62
+ options?: CPUColorConversionOptions & {format?: 'unorm8x4'}
63
+ ): CPUVector<'unorm8x4'>;
64
+ export function convertCPUColors<T extends ColorOutputFormat>(
65
+ source: CPUVector,
66
+ options: CPUColorConversionOptions & {format: T}
67
+ ): CPUVector<T>;
68
+ export function convertCPUColors(
69
+ source: CPUVector,
70
+ options: CPUColorConversionOptions
71
+ ): CPUVector<ColorOutputFormat>;
72
+ export function convertCPUColors(
73
+ source: CPUVector,
74
+ options: CPUColorConversionOptions = {}
75
+ ): CPUVector<ColorOutputFormat> {
76
+ const format = resolveColorOutputFormat(
77
+ options.inputFormat ? 'float16x4' : source.format,
78
+ options
79
+ );
80
+ if (options.format === 'preserve' && source.format === format)
81
+ return new CPUVector({
82
+ name: source.name,
83
+ format,
84
+ data: source.data as readonly CPUData<ColorOutputFormat>[]
85
+ });
86
+ return new CPUVector({
87
+ name: source.name,
88
+ format,
89
+ data: source.data.map(chunk => convertCPUColorData(chunk, format, options.inputFormat))
90
+ });
91
+ }
92
+
93
+ /** @internal Shared CPU backend implementation, including offsets, strides and validity. */
94
+ export function convertCPUColorData(
95
+ source: CPUData,
96
+ format: ColorOutputFormat,
97
+ inputFormat?: string
98
+ ): CPUData<ColorOutputFormat> {
99
+ const info = getGPUVectorFormatInfo(source.format);
100
+ const type = inputFormat?.startsWith('float16') ? 'float16' : info.signedDataType;
101
+ const components = inputFormat?.endsWith('x3') ? 3 : info.components;
102
+ // Color rows contain only byte channels or IEEE floats and three or four components.
103
+ assert((components === 3 || components === 4) && ['uint8', 'float16', 'float32'].includes(type));
104
+ const bytes = type === 'uint8' ? 1 : type === 'float16' ? 2 : 4;
105
+ const input = new DataView(source.buffer, source.byteOffset);
106
+ const output =
107
+ format === 'unorm8x4'
108
+ ? new Uint8Array(source.length * 4)
109
+ : format === 'float16x4'
110
+ ? new Uint16Array(source.length * 4)
111
+ : new Float32Array(source.length * 4);
112
+ const scratch = new DataView(new ArrayBuffer(4));
113
+ for (let rowIndex = 0; rowIndex < source.length; rowIndex++) {
114
+ for (let componentIndex = 0; componentIndex < 4; componentIndex++) {
115
+ const offset = rowIndex * source.byteStride + componentIndex * bytes;
116
+ const value =
117
+ componentIndex >= components
118
+ ? 1
119
+ : type === 'uint8'
120
+ ? input.getUint8(offset) / 255
121
+ : type === 'float16'
122
+ ? fromHalfFloat(input.getUint16(offset, true))
123
+ : input.getFloat32(offset, true);
124
+ output[rowIndex * 4 + componentIndex] =
125
+ format === 'unorm8x4'
126
+ ? Math.round(Math.min(Math.max(value, 0), 1) * 255)
127
+ : format === 'float16x4'
128
+ ? encodeHalfFloat(value, scratch)
129
+ : value;
130
+ }
131
+ }
132
+ return new CPUData({
133
+ buffer: output,
134
+ format,
135
+ length: source.length,
136
+ nullBitmap: source.nullBitmap && new Uint8Array(source.nullBitmap)
137
+ });
138
+ }
139
+
140
+ /** IEEE binary16 round-to-nearest-even, matching pack2x16float (no display-range clamp). */
141
+ function encodeHalfFloat(value: number, scratch: DataView): number {
142
+ scratch.setFloat32(0, value, true);
143
+ const bits = scratch.getUint32(0, true);
144
+ const sign = (bits >>> 16) & 0x8000;
145
+ const exponent = (bits >>> 23) & 255;
146
+ const mantissa = bits & 0x7fffff;
147
+ if (exponent === 255) return sign | 0x7c00 | (mantissa ? 0x200 : 0);
148
+ if (exponent > 142) return sign | 0x7c00;
149
+ if (exponent < 102) return sign;
150
+ const shift = exponent < 113 ? 126 - exponent : 13;
151
+ const significand = exponent < 113 ? mantissa | 0x800000 : mantissa;
152
+ const divisor = 2 ** shift;
153
+ const quotient = Math.floor(significand / divisor);
154
+ const remainder = significand % divisor;
155
+ const rounded =
156
+ quotient + (remainder > divisor / 2 || (remainder === divisor / 2 && quotient % 2) ? 1 : 0);
157
+ return sign | ((exponent < 113 ? 0 : (exponent - 112) * 1024) + rounded);
158
+ }
@@ -0,0 +1,79 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {getLeafLayoutInfo, makeShaderBlockLayout} from '@luma.gl/shaders/types';
6
+ import {getGPUVectorFormatInfo} from './gpu-vector-format';
7
+
8
+ /** Scalar formats with matching 32-bit WGSL component representations. */
9
+ export type GPUVectorWGSLScalarFormat = 'float32' | 'sint32' | 'uint32';
10
+
11
+ /** Packed 32-bit numeric formats with a corresponding WGSL value type. */
12
+ export type GPUVectorWGSLFormat =
13
+ | GPUVectorWGSLScalarFormat
14
+ | `${GPUVectorWGSLScalarFormat}x${2 | 3 | 4}`;
15
+
16
+ /** Packed row metadata and the layout of the corresponding native WGSL storage value. */
17
+ export type GPUVectorWGSLLayout = {
18
+ /** The packed GPUVector format. */
19
+ format: GPUVectorWGSLFormat;
20
+ /** Number of scalar components in a row. */
21
+ components: 1 | 2 | 3 | 4;
22
+ /** GPUVector format of an individual component. */
23
+ componentType: GPUVectorWGSLScalarFormat;
24
+ /** WGSL type of an individual component. */
25
+ scalarType: 'f32' | 'i32' | 'u32';
26
+ /** WGSL scalar or vector type for one row. */
27
+ shaderType: 'f32' | 'i32' | 'u32' | `vec${2 | 3 | 4}<${'f32' | 'i32' | 'u32'}>`;
28
+ /** Number of bytes occupied by the components of one row. */
29
+ byteLength: number;
30
+ /** Distance in bytes between rows in a tightly packed GPUVector. */
31
+ packedByteStride: number;
32
+ /** Required byte alignment of the value in a native WGSL storage buffer. */
33
+ storageAlignment: number;
34
+ /** Distance in bytes between elements in a native WGSL storage array of this value type. */
35
+ nativeArrayByteStride: number;
36
+ };
37
+
38
+ /**
39
+ * Describes packed GPUVector rows and the corresponding native WGSL storage array.
40
+ *
41
+ * @param format - Packed 32-bit scalar or vector format.
42
+ * @returns Layout metadata in bytes. The helper does not allocate or modify storage.
43
+ * @throws If the format has no supported 32-bit WGSL representation.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const layout = getGPUVectorWGSLLayout('float32x3');
48
+ * layout.packedByteStride; // 12
49
+ * layout.nativeArrayByteStride; // 16
50
+ * ```
51
+ */
52
+ export function getGPUVectorWGSLLayout(format: GPUVectorWGSLFormat): GPUVectorWGSLLayout {
53
+ const {components, signedDataType, primitiveType, byteLength, elementFormat, normalized} =
54
+ getGPUVectorFormatInfo(format);
55
+ if (
56
+ normalized ||
57
+ elementFormat !== format ||
58
+ (signedDataType !== 'float32' && signedDataType !== 'sint32' && signedDataType !== 'uint32') ||
59
+ primitiveType === 'f16'
60
+ ) {
61
+ throw new Error('Expected a packed 32-bit numeric vector format');
62
+ }
63
+ const scalarType = primitiveType;
64
+ const shaderType = components === 1 ? scalarType : (`vec${components}<${scalarType}>` as const);
65
+ const layout = 'wgsl-storage';
66
+ const {alignment} = getLeafLayoutInfo(shaderType, layout);
67
+ const arrayLayout = makeShaderBlockLayout({values: [shaderType, 2]}, {layout});
68
+ return {
69
+ format,
70
+ components,
71
+ componentType: signedDataType,
72
+ scalarType,
73
+ shaderType,
74
+ byteLength,
75
+ packedByteStride: byteLength,
76
+ storageAlignment: alignment * Uint32Array.BYTES_PER_ELEMENT,
77
+ nativeArrayByteStride: arrayLayout.byteLength / 2
78
+ };
79
+ }
@@ -73,3 +73,13 @@ export {CPUData, type CPUDataProps} from './cpu-data';
73
73
  export {CPUVector, type CPUVectorProps} from './cpu-vector';
74
74
 
75
75
  export {makeGPUVectorFromCPUVector, makeCPUVectorFromGPUVector} from './cpu-gpu-vector-transfer';
76
+
77
+ export {
78
+ getGPUVectorWGSLLayout,
79
+ type GPUVectorWGSLFormat,
80
+ type GPUVectorWGSLLayout,
81
+ type GPUVectorWGSLScalarFormat
82
+ } from './gpu-vector-wgsl-layout';
83
+
84
+ export {convertCPUColors, resolveColorOutputFormat} from './color-conversion';
85
+ export type {ColorOutputFormat, ColorConversionOptions} from './color-conversion';
@@ -6,7 +6,12 @@
6
6
  import type {GPUTypeMap} from '@luma.gl/graph/gpu-tables';
7
7
  import type {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
8
8
  import type {GPUDataFrame} from './gpu-data-frame';
9
- import {getGPUExpressionColumnNames, GPUExpression, type GPUExpressionNode} from './gpu-expression';
9
+ import {
10
+ getGPUExpressionColumnNames,
11
+ GPUExpression,
12
+ isBooleanExpressionNode,
13
+ type GPUExpressionNode
14
+ } from './gpu-expression';
10
15
  import {
11
16
  GPUDataFrameAggregationQuery,
12
17
  type GPUDataFrameGlobalAggregationDefinitions,
@@ -434,28 +439,3 @@ function isNumericExpressionNode(node: GPUExpressionNode): boolean {
434
439
  return false;
435
440
  }
436
441
  }
437
-
438
- function isBooleanExpressionNode(node: GPUExpressionNode): boolean {
439
- switch (node.kind) {
440
- case 'column':
441
- return false;
442
- case 'literal':
443
- case 'parameter':
444
- return typeof node.value === 'boolean';
445
- case 'unary':
446
- return node.operator === 'not' || node.operator === 'is-valid' || node.operator === 'is-null';
447
- case 'binary':
448
- return (
449
- node.operator === 'equal' ||
450
- node.operator === 'not-equal' ||
451
- node.operator === 'greater-than' ||
452
- node.operator === 'greater-than-or-equal' ||
453
- node.operator === 'less-than' ||
454
- node.operator === 'less-than-or-equal' ||
455
- node.operator === 'and' ||
456
- node.operator === 'or'
457
- );
458
- default:
459
- return false;
460
- }
461
- }
@@ -3,6 +3,14 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
  // SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuDF.
5
5
 
6
+ import {
7
+ getGPUVectorWGSLLayout,
8
+ type GPUVectorWGSLFormat as GPUExpressionNumericFormat
9
+ } from '@luma.gl/graph/gpu-data';
10
+
11
+ /** Numeric values, including fixed-width vectors. */
12
+ export type GPUExpressionNumericValue = number | readonly number[] | null;
13
+
6
14
  /** Portable scalar values accepted by GPU-resident dataframe expressions. */
7
15
  export type GPUExpressionValue = number | boolean | null;
8
16
 
@@ -26,6 +34,12 @@ export type GPUExpressionBinaryOperator =
26
34
 
27
35
  /** Immutable, renderer-independent dataframe expression syntax. */
28
36
  export type GPUExpressionNode =
37
+ | Readonly<{
38
+ kind: 'vector';
39
+ format: GPUExpressionNumericFormat;
40
+ components: readonly GPUExpressionNode[];
41
+ }>
42
+ | Readonly<{kind: 'cast'; format: GPUExpressionNumericFormat; operand: GPUExpressionNode}>
29
43
  | Readonly<{kind: 'column'; name: string}>
30
44
  | Readonly<{kind: 'literal'; value: GPUExpressionValue}>
31
45
  | Readonly<{kind: 'parameter'; name: string; value: GPUExpressionValue}>
@@ -236,6 +250,18 @@ export function getGPUExpressionColumnNames(expression: GPUExpression<any, strin
236
250
  /** Clones every closed node so caller-owned child objects cannot alter an immutable query plan. */
237
251
  function cloneFrozenGPUExpressionNode(node: GPUExpressionNode): GPUExpressionNode {
238
252
  switch (node.kind) {
253
+ case 'vector':
254
+ return Object.freeze({
255
+ kind: 'vector',
256
+ format: node.format,
257
+ components: Object.freeze(node.components.map(cloneFrozenGPUExpressionNode))
258
+ });
259
+ case 'cast':
260
+ return Object.freeze({
261
+ kind: 'cast',
262
+ format: node.format,
263
+ operand: cloneFrozenGPUExpressionNode(node.operand)
264
+ });
239
265
  case 'column':
240
266
  return Object.freeze({kind: 'column', name: node.name});
241
267
  case 'literal':
@@ -262,6 +288,13 @@ function cloneFrozenGPUExpressionNode(node: GPUExpressionNode): GPUExpressionNod
262
288
 
263
289
  function collectGPUExpressionColumnNames(node: GPUExpressionNode, columnNames: Set<string>): void {
264
290
  switch (node.kind) {
291
+ case 'vector':
292
+ for (const component of node.components)
293
+ collectGPUExpressionColumnNames(component, columnNames);
294
+ break;
295
+ case 'cast':
296
+ collectGPUExpressionColumnNames(node.operand, columnNames);
297
+ break;
265
298
  case 'column':
266
299
  columnNames.add(node.name);
267
300
  break;
@@ -307,3 +340,105 @@ function assertValidExpressionValue(
307
340
  throw new Error(`GPUDataFrame ${kind} values must be finite numbers, booleans, or null`);
308
341
  }
309
342
  }
343
+
344
+ /**
345
+ * Constructs a fixed-width numeric vector. A null component makes the whole row null.
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * const position = vector('float32x3', [column('x'), column('y'), column('z')]);
350
+ * ```
351
+ */
352
+ export function vector<Columns extends string>(
353
+ format: GPUExpressionNumericFormat,
354
+ components: readonly GPUExpression<number | null, Columns>[]
355
+ ): GPUExpression<readonly number[] | null, Columns> {
356
+ const width = getGPUVectorWGSLLayout(format).components;
357
+ if (![2, 3, 4].includes(width) || components.length !== width)
358
+ throw new Error('Vector width must match its format');
359
+ return new GPUExpression({
360
+ kind: 'vector',
361
+ format,
362
+ components: components.map(component => component.node)
363
+ });
364
+ }
365
+
366
+ /**
367
+ * Converts a numeric expression to the requested format while preserving its width.
368
+ *
369
+ * @example
370
+ * ```ts
371
+ * const position = vector('sint32x2', [column('x'), column('y')]);
372
+ * const floatPosition = cast(position, 'float32x2');
373
+ * ```
374
+ */
375
+ export function cast<Value extends GPUExpressionNumericValue, Columns extends string>(
376
+ expression: GPUExpression<Value, Columns>,
377
+ format: GPUExpressionNumericFormat
378
+ ): GPUExpression<Value, Columns> {
379
+ return new GPUExpression(makeGPUCastNode(expression.node, format));
380
+ }
381
+
382
+ export function makeGPUCastNode<Format extends GPUExpressionNumericFormat>(
383
+ operand: GPUExpressionNode,
384
+ format: Format
385
+ ): {kind: 'cast'; format: Format; operand: GPUExpressionNode} {
386
+ const width = getGPUVectorWGSLLayout(format).components;
387
+ const operandWidth = getKnownExpressionWidth(operand);
388
+ if (operandWidth !== undefined && operandWidth !== width) {
389
+ throw new Error('Numeric casts must preserve width');
390
+ }
391
+ return {kind: 'cast', format, operand};
392
+ }
393
+
394
+ function getKnownExpressionWidth(node: GPUExpressionNode): number | undefined {
395
+ switch (node.kind) {
396
+ case 'vector':
397
+ case 'cast':
398
+ return getGPUVectorWGSLLayout(node.format).components;
399
+ case 'literal':
400
+ case 'parameter':
401
+ return node.value === null ? undefined : 1;
402
+ case 'unary':
403
+ return node.operator === 'negate' ? getKnownExpressionWidth(node.operand) : 1;
404
+ case 'binary': {
405
+ if (isBooleanExpressionNode(node)) {
406
+ return 1;
407
+ }
408
+ const leftWidth = getKnownExpressionWidth(node.left);
409
+ const rightWidth = getKnownExpressionWidth(node.right);
410
+ if (leftWidth !== undefined && rightWidth !== undefined && leftWidth !== rightWidth) {
411
+ throw new Error('Numeric arithmetic requires matching widths');
412
+ }
413
+ return leftWidth ?? rightWidth;
414
+ }
415
+ case 'column':
416
+ return undefined;
417
+ }
418
+ }
419
+
420
+ /** Checks whether the expression produces a boolean result. */
421
+ export function isBooleanExpressionNode(node: GPUExpressionNode): boolean {
422
+ switch (node.kind) {
423
+ case 'column':
424
+ return false;
425
+ case 'literal':
426
+ case 'parameter':
427
+ return typeof node.value === 'boolean';
428
+ case 'unary':
429
+ return node.operator === 'not' || node.operator === 'is-valid' || node.operator === 'is-null';
430
+ case 'binary':
431
+ return (
432
+ node.operator === 'equal' ||
433
+ node.operator === 'not-equal' ||
434
+ node.operator === 'greater-than' ||
435
+ node.operator === 'greater-than-or-equal' ||
436
+ node.operator === 'less-than' ||
437
+ node.operator === 'less-than-or-equal' ||
438
+ node.operator === 'and' ||
439
+ node.operator === 'or'
440
+ );
441
+ default:
442
+ return false;
443
+ }
444
+ }
@@ -63,3 +63,14 @@ export {CompiledGPUDataFrameHistogram} from './gpu-histogram-compiler';
63
63
  export {CompiledGPUDataFrameSort} from './gpu-sort-compiler';
64
64
  export {CompiledGPUDataFrameGlobalSort} from './gpu-global-sort-compiler';
65
65
  export {CompiledGPUDataFrameJoin, CompiledGPUDataFrameLookup} from './gpu-join-compiler';
66
+
67
+ export {vector, cast} from './gpu-expression';
68
+ export type {GPUExpressionNumericValue} from './gpu-expression';
69
+ export type {
70
+ GPUVectorWGSLFormat as GPUExpressionNumericFormat,
71
+ GPUVectorWGSLScalarFormat as GPUExpressionScalarFormat
72
+ } from '@luma.gl/graph/gpu-data';
73
+ export {
74
+ makeGPUExpressionFromPortableAST,
75
+ makeGPUPredicateFromPortableAST
76
+ } from './portable-expression';