@luma.gl/graph 10.0.0-alpha.10 → 10.0.0-alpha.11

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 (228) hide show
  1. package/dist/arrow/cpu/arrow-coordinate-projection.cjs +30 -0
  2. package/dist/arrow/cpu/arrow-coordinate-projection.d.ts +5 -0
  3. package/dist/arrow/cpu/arrow-coordinate-projection.d.ts.map +1 -0
  4. package/dist/arrow/cpu/arrow-coordinate-projection.js +9 -0
  5. package/dist/arrow/cpu/arrow-coordinate-projection.js.map +1 -0
  6. package/dist/arrow/cpu/arrow-cpu-pipelines.cjs +31 -0
  7. package/dist/arrow/cpu/arrow-cpu-pipelines.d.ts +2 -0
  8. package/dist/arrow/cpu/arrow-cpu-pipelines.d.ts.map +1 -0
  9. package/dist/arrow/cpu/arrow-cpu-pipelines.js +5 -0
  10. package/dist/arrow/cpu/arrow-cpu-pipelines.js.map +1 -0
  11. package/dist/arrow/cpu/arrow-cpu-vector-adapters.cjs +99 -0
  12. package/dist/arrow/cpu/arrow-cpu-vector-adapters.d.ts +9 -0
  13. package/dist/arrow/cpu/arrow-cpu-vector-adapters.d.ts.map +1 -0
  14. package/dist/arrow/cpu/arrow-cpu-vector-adapters.js +100 -0
  15. package/dist/arrow/cpu/arrow-cpu-vector-adapters.js.map +1 -0
  16. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.cjs +10 -371
  17. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts +9 -28
  18. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts.map +1 -1
  19. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js +5 -381
  20. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js.map +1 -1
  21. package/dist/arrow/geoarrow/arrow-geoarrow-conversion.cjs +11 -11
  22. package/dist/arrow/geoarrow/arrow-geoarrow-conversion.d.ts +2 -0
  23. package/dist/arrow/geoarrow/arrow-geoarrow-conversion.d.ts.map +1 -1
  24. package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js +3 -3
  25. package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js.map +1 -1
  26. package/dist/arrow/geoarrow/arrow-polygon-tessellation.cjs +2 -2
  27. package/dist/arrow/geoarrow/arrow-polygon-tessellation.js +1 -1
  28. package/dist/arrow/geoarrow/arrow-polygon-tessellation.js.map +1 -1
  29. package/dist/arrow/index.cjs +17 -2
  30. package/dist/arrow/index.cjs.map +3 -3
  31. package/dist/arrow/index.d.ts +3 -0
  32. package/dist/arrow/index.d.ts.map +1 -1
  33. package/dist/arrow/index.js +3 -0
  34. package/dist/arrow/index.js.map +1 -1
  35. package/dist/arrow/internal.cjs.map +2 -2
  36. package/dist/dist.dev.js +533 -108
  37. package/dist/dist.min.js +70 -70
  38. package/dist/experimental/index.cjs.map +1 -1
  39. package/dist/experimental/simulation/index.cjs.map +1 -1
  40. package/dist/gpu-core/compiled-gpu-graph.cjs +32 -0
  41. package/dist/gpu-core/compiled-gpu-graph.d.ts +4 -0
  42. package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
  43. package/dist/gpu-core/compiled-gpu-graph.js +39 -1
  44. package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
  45. package/dist/gpu-core/gpu-command-graph.cjs +19 -7
  46. package/dist/gpu-core/gpu-command-graph.d.ts +11 -4
  47. package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
  48. package/dist/gpu-core/gpu-command-graph.js +24 -7
  49. package/dist/gpu-core/gpu-command-graph.js.map +1 -1
  50. package/dist/gpu-core/gpu-cpu-execution.cjs +279 -0
  51. package/dist/gpu-core/gpu-cpu-execution.d.ts +22 -0
  52. package/dist/gpu-core/gpu-cpu-execution.d.ts.map +1 -0
  53. package/dist/gpu-core/gpu-cpu-execution.js +294 -0
  54. package/dist/gpu-core/gpu-cpu-execution.js.map +1 -0
  55. package/dist/gpu-core/gpu-cpu-operation.cjs +54 -0
  56. package/dist/gpu-core/gpu-cpu-operation.d.ts +40 -0
  57. package/dist/gpu-core/gpu-cpu-operation.d.ts.map +1 -0
  58. package/dist/gpu-core/gpu-cpu-operation.js +35 -0
  59. package/dist/gpu-core/gpu-cpu-operation.js.map +1 -0
  60. package/dist/gpu-core/gpu-expression-operation.cjs +2 -2
  61. package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
  62. package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
  63. package/dist/gpu-core/gpu-expression-operation.js +1 -1
  64. package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
  65. package/dist/gpu-core/gpu-expression-plan.cjs +1 -1
  66. package/dist/gpu-core/gpu-expression-plan.d.ts +3 -2
  67. package/dist/gpu-core/gpu-expression-plan.d.ts.map +1 -1
  68. package/dist/gpu-core/gpu-expression-plan.js +2 -1
  69. package/dist/gpu-core/gpu-expression-plan.js.map +1 -1
  70. package/dist/gpu-core/gpu-graph.d.ts +2 -2
  71. package/dist/gpu-core/gpu-graph.d.ts.map +1 -1
  72. package/dist/gpu-core/gpu-graph.js.map +1 -1
  73. package/dist/gpu-core/gpu-operation.d.ts +4 -4
  74. package/dist/gpu-core/gpu-operation.d.ts.map +1 -1
  75. package/dist/gpu-core/gpu-operation.js.map +1 -1
  76. package/dist/gpu-core/gpu-render-operation.cjs +39 -0
  77. package/dist/gpu-core/gpu-render-operation.d.ts +21 -0
  78. package/dist/gpu-core/gpu-render-operation.d.ts.map +1 -0
  79. package/dist/gpu-core/gpu-render-operation.js +22 -0
  80. package/dist/gpu-core/gpu-render-operation.js.map +1 -0
  81. package/dist/gpu-core/gpu-texture-plan.d.ts +3 -2
  82. package/dist/gpu-core/gpu-texture-plan.d.ts.map +1 -1
  83. package/dist/gpu-core/gpu-texture-plan.js.map +1 -1
  84. package/dist/gpu-core/index.cjs +6 -0
  85. package/dist/gpu-core/index.cjs.map +3 -3
  86. package/dist/gpu-core/index.d.ts +4 -0
  87. package/dist/gpu-core/index.d.ts.map +1 -1
  88. package/dist/gpu-core/index.js +2 -0
  89. package/dist/gpu-core/index.js.map +1 -1
  90. package/dist/gpu-data/cpu-data.cjs +60 -0
  91. package/dist/gpu-data/cpu-data.d.ts +28 -0
  92. package/dist/gpu-data/cpu-data.d.ts.map +1 -0
  93. package/dist/gpu-data/cpu-data.js +41 -0
  94. package/dist/gpu-data/cpu-data.js.map +1 -0
  95. package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +93 -0
  96. package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts +9 -0
  97. package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -0
  98. package/dist/gpu-data/cpu-gpu-vector-transfer.js +82 -0
  99. package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -0
  100. package/dist/gpu-data/cpu-vector.cjs +42 -0
  101. package/dist/gpu-data/cpu-vector.d.ts +17 -0
  102. package/dist/gpu-data/cpu-vector.d.ts.map +1 -0
  103. package/dist/gpu-data/cpu-vector.js +21 -0
  104. package/dist/gpu-data/cpu-vector.js.map +1 -0
  105. package/dist/gpu-data/index.cjs +13 -2
  106. package/dist/gpu-data/index.cjs.map +3 -3
  107. package/dist/gpu-data/index.d.ts +3 -0
  108. package/dist/gpu-data/index.d.ts.map +1 -1
  109. package/dist/gpu-data/index.js +3 -0
  110. package/dist/gpu-data/index.js.map +1 -1
  111. package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
  112. package/dist/gpu-graph/index.cjs +3 -0
  113. package/dist/gpu-graph/index.cjs.map +3 -3
  114. package/dist/gpu-graph/index.d.ts +2 -0
  115. package/dist/gpu-graph/index.d.ts.map +1 -1
  116. package/dist/gpu-graph/index.js +1 -0
  117. package/dist/gpu-graph/index.js.map +1 -1
  118. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
  119. package/dist/gpu-physics/index.cjs.map +1 -1
  120. package/dist/gpu-project/coordinate-projection-graph.cjs +59 -0
  121. package/dist/gpu-project/coordinate-projection-graph.d.ts +23 -0
  122. package/dist/gpu-project/coordinate-projection-graph.d.ts.map +1 -0
  123. package/dist/gpu-project/coordinate-projection-graph.js +40 -0
  124. package/dist/gpu-project/coordinate-projection-graph.js.map +1 -0
  125. package/dist/gpu-project/cpu-geoarrow.cjs +112 -0
  126. package/dist/gpu-project/cpu-geoarrow.d.ts +10 -0
  127. package/dist/gpu-project/cpu-geoarrow.d.ts.map +1 -0
  128. package/dist/gpu-project/cpu-geoarrow.js +103 -0
  129. package/dist/gpu-project/cpu-geoarrow.js.map +1 -0
  130. package/dist/gpu-project/cpu-geometry-pipelines.cjs +134 -0
  131. package/dist/gpu-project/cpu-geometry-pipelines.d.ts +18 -0
  132. package/dist/gpu-project/cpu-geometry-pipelines.d.ts.map +1 -0
  133. package/dist/gpu-project/cpu-geometry-pipelines.js +114 -0
  134. package/dist/gpu-project/cpu-geometry-pipelines.js.map +1 -0
  135. package/dist/gpu-project/cpu-projection-operation.cjs +54 -0
  136. package/dist/gpu-project/cpu-projection-operation.d.ts +14 -0
  137. package/dist/gpu-project/cpu-projection-operation.d.ts.map +1 -0
  138. package/dist/gpu-project/cpu-projection-operation.js +37 -0
  139. package/dist/gpu-project/cpu-projection-operation.js.map +1 -0
  140. package/dist/gpu-project/geoarrow.cjs +36 -0
  141. package/dist/gpu-project/geoarrow.cjs.map +6 -0
  142. package/dist/gpu-project/geoarrow.d.ts +3 -0
  143. package/dist/gpu-project/geoarrow.d.ts.map +1 -0
  144. package/dist/gpu-project/geoarrow.js +7 -0
  145. package/dist/gpu-project/geoarrow.js.map +1 -0
  146. package/dist/gpu-project/graph.cjs +27 -0
  147. package/dist/gpu-project/graph.cjs.map +6 -0
  148. package/dist/gpu-project/graph.d.ts +2 -0
  149. package/dist/gpu-project/graph.d.ts.map +1 -0
  150. package/dist/gpu-project/graph.js +6 -0
  151. package/dist/gpu-project/graph.js.map +1 -0
  152. package/dist/gpu-project/index.cjs +3 -0
  153. package/dist/gpu-project/index.cjs.map +3 -3
  154. package/dist/gpu-project/index.d.ts +1 -0
  155. package/dist/gpu-project/index.d.ts.map +1 -1
  156. package/dist/gpu-project/index.js +1 -0
  157. package/dist/gpu-project/index.js.map +1 -1
  158. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +24 -2
  159. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +2 -0
  160. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts.map +1 -1
  161. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js +29 -2
  162. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
  163. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.cjs +9 -0
  164. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.d.ts +2 -0
  165. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.d.ts.map +1 -1
  166. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.js +10 -0
  167. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.js.map +1 -1
  168. package/dist/gpu-simple-graph/gpu-simple-graph.cjs +126 -10
  169. package/dist/gpu-simple-graph/gpu-simple-graph.d.ts +36 -11
  170. package/dist/gpu-simple-graph/gpu-simple-graph.d.ts.map +1 -1
  171. package/dist/gpu-simple-graph/gpu-simple-graph.js +137 -12
  172. package/dist/gpu-simple-graph/gpu-simple-graph.js.map +1 -1
  173. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  174. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.cjs +23 -0
  175. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.d.ts +6 -0
  176. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.d.ts.map +1 -1
  177. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js +25 -0
  178. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js.map +1 -1
  179. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.cjs +7 -0
  180. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.d.ts +2 -0
  181. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.d.ts.map +1 -1
  182. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.js +7 -0
  183. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.js.map +1 -1
  184. package/dist/gpu-simple-graph/operations/webgl/index.cjs.map +1 -1
  185. package/dist/gpu-simple-graph/operations/webgpu/index.cjs.map +1 -1
  186. package/dist/index.cjs +3 -0
  187. package/dist/index.cjs.map +3 -3
  188. package/dist/index.d.ts +2 -0
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +1 -0
  191. package/dist/index.js.map +1 -1
  192. package/package.json +17 -6
  193. package/src/arrow/cpu/arrow-coordinate-projection.ts +18 -0
  194. package/src/arrow/cpu/arrow-cpu-pipelines.ts +9 -0
  195. package/src/arrow/cpu/arrow-cpu-vector-adapters.ts +153 -0
  196. package/src/arrow/geoarrow/arrow-geoarrow-adapter.ts +23 -493
  197. package/src/arrow/geoarrow/arrow-geoarrow-conversion.ts +5 -3
  198. package/src/arrow/geoarrow/arrow-polygon-tessellation.ts +1 -1
  199. package/src/arrow/index.ts +11 -0
  200. package/src/gpu-core/compiled-gpu-graph.ts +55 -1
  201. package/src/gpu-core/gpu-command-graph.ts +27 -7
  202. package/src/gpu-core/gpu-cpu-execution.ts +345 -0
  203. package/src/gpu-core/gpu-cpu-operation.ts +65 -0
  204. package/src/gpu-core/gpu-expression-operation.ts +1 -1
  205. package/src/gpu-core/gpu-expression-plan.ts +5 -3
  206. package/src/gpu-core/gpu-graph.ts +3 -3
  207. package/src/gpu-core/gpu-operation.ts +9 -7
  208. package/src/gpu-core/gpu-render-operation.ts +42 -0
  209. package/src/gpu-core/gpu-texture-plan.ts +3 -2
  210. package/src/gpu-core/index.ts +10 -0
  211. package/src/gpu-data/cpu-data.ts +62 -0
  212. package/src/gpu-data/cpu-gpu-vector-transfer.ts +107 -0
  213. package/src/gpu-data/cpu-vector.ts +31 -0
  214. package/src/gpu-data/index.ts +5 -0
  215. package/src/gpu-graph/index.ts +8 -0
  216. package/src/gpu-project/coordinate-projection-graph.ts +59 -0
  217. package/src/gpu-project/cpu-geoarrow.ts +135 -0
  218. package/src/gpu-project/cpu-geometry-pipelines.ts +159 -0
  219. package/src/gpu-project/cpu-projection-operation.ts +49 -0
  220. package/src/gpu-project/geoarrow.ts +11 -0
  221. package/src/gpu-project/graph.ts +10 -0
  222. package/src/gpu-project/index.ts +2 -0
  223. package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +39 -2
  224. package/src/gpu-simple-graph/gpu-simple-graph-lowering.ts +11 -0
  225. package/src/gpu-simple-graph/gpu-simple-graph.ts +163 -19
  226. package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +22 -0
  227. package/src/gpu-simple-graph/operation/gpu-vector-evaluator.ts +7 -0
  228. package/src/index.ts +8 -0
@@ -3,7 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {assert, type CommandEncoder, type Device} from '@luma.gl/core';
6
- import {GPUVector} from '@luma.gl/graph/gpu-data';
6
+ import {CPUVector, GPUVector} from '@luma.gl/graph/gpu-data';
7
7
  import {
8
8
  getTextureBindingInfo,
9
9
  type GPUGraphTextureBinding,
@@ -23,13 +23,19 @@ import {
23
23
  type GPUGraphRunOptions
24
24
  } from './gpu-expression-plan';
25
25
  import {GPUExpressionKernel} from './gpu-expression-kernel';
26
+ import {GPUCPUOperation} from './gpu-cpu-operation';
27
+ import {GPUCPUExecution} from './gpu-cpu-execution';
26
28
 
27
29
  /** Reusable WebGPU program. Returned output vectors belong to the caller. */
28
30
  export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, GPUVector>> {
29
31
  private readonly program: GPUExpressionProgram;
32
+ private readonly stageLowerings: readonly GPUOperationLowering[];
30
33
  private readonly compiler: GPUGraphCompiler;
31
34
  private readonly kernels = new Map<GPUExpressionOperation, GPUExpressionKernel>();
32
35
  private destroyed = false;
36
+ private runningCPU = false;
37
+ private cpuExecution?: GPUCPUExecution;
38
+ private readonly outputLocations: Readonly<Record<string, 'cpu' | 'gpu'>>;
33
39
 
34
40
  constructor(
35
41
  readonly device: Device,
@@ -39,6 +45,8 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
39
45
  ) {
40
46
  if (device.type !== 'webgpu') throw new Error('GPUGraph execution requires WebGPU');
41
47
  this.program = new GPUExpressionProgram(source, options);
48
+ this.outputLocations = options.outputLocations ?? {};
49
+ this.stageLowerings = lowerings ?? options.lowerings ?? [];
42
50
  this.compiler = new GPUGraphCompiler(device, [
43
51
  ...(lowerings ?? options.lowerings ?? []),
44
52
  {
@@ -47,6 +55,18 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
47
55
  this.kernels.get(operation)!.lower(context)
48
56
  }
49
57
  ]);
58
+ if (
59
+ this.program.operations.some(operation => operation instanceof GPUCPUOperation) ||
60
+ Object.values(this.outputLocations).includes('cpu')
61
+ ) {
62
+ this.cpuExecution = new GPUCPUExecution(
63
+ device,
64
+ this.program,
65
+ (source, outputs) =>
66
+ new CompiledGPUGraph(device, source, {outputs}, lowerings ?? options.lowerings)
67
+ );
68
+ return;
69
+ }
50
70
  try {
51
71
  for (const plan of this.program.expressions)
52
72
  this.kernels.set(plan.operation, new GPUExpressionKernel(device, this.program, plan));
@@ -60,6 +80,32 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
60
80
  supplied: GPUGraphRunBindings | GPUGraphExecutionBindings,
61
81
  options: GPUGraphRunOptions = {}
62
82
  ): Promise<Outputs> {
83
+ assert(!this.destroyed && !this.runningCPU);
84
+ const suppliedInputs = 'inputs' in supplied ? supplied.inputs : supplied;
85
+ const useCPU =
86
+ this.program.operations.some(operation => operation instanceof GPUCPUOperation) ||
87
+ Object.values(this.outputLocations).includes('cpu') ||
88
+ Object.values(suppliedInputs ?? {}).some(value => value instanceof CPUVector);
89
+ if (!this.cpuExecution && useCPU)
90
+ this.cpuExecution = new GPUCPUExecution(
91
+ this.device,
92
+ this.program,
93
+ (source, outputs) =>
94
+ new CompiledGPUGraph(this.device, source, {outputs}, this.stageLowerings)
95
+ );
96
+ if (useCPU && this.cpuExecution) {
97
+ const resolved = this.program.resolveBindings(supplied, options);
98
+ // Dynamic CPU outputs are owned by the invocation, not caller-provided targets.
99
+ assert(
100
+ !resolved.options.outputTargets || Object.keys(resolved.options.outputTargets).length === 0
101
+ );
102
+ this.runningCPU = true;
103
+ try {
104
+ return (await this.cpuExecution.run(resolved.bindings, this.outputLocations)) as Outputs;
105
+ } finally {
106
+ this.runningCPU = false;
107
+ }
108
+ }
63
109
  const execution = this.prepare(supplied, options);
64
110
  let encoder: CommandEncoder | undefined;
65
111
  try {
@@ -83,6 +129,11 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
83
129
  ): PreparedGPUGraphExecution<Outputs> {
84
130
  // A destroyed compiled program cannot encode further work.
85
131
  assert(!this.destroyed);
132
+ if (
133
+ this.program.operations.some(operation => operation instanceof GPUCPUOperation) ||
134
+ Object.values(this.outputLocations).includes('cpu')
135
+ )
136
+ throw new Error('CPU operations require asynchronous run(), not prepare()');
86
137
  const resolvedBindings = this.program.resolveBindings(supplied, options);
87
138
  const bindings = resolvedBindings.bindings;
88
139
  options = resolvedBindings.options;
@@ -179,6 +230,9 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
179
230
  }
180
231
 
181
232
  destroy(): void {
233
+ // CPU callbacks may still be awaiting input readback or producing output arrays.
234
+ assert(!this.runningCPU);
235
+ this.cpuExecution?.destroy();
182
236
  for (const kernel of this.kernels.values()) kernel.destroy();
183
237
  this.kernels.clear();
184
238
  this.destroyed = true;
@@ -663,8 +663,9 @@ export class GPUCommandGraphEncoding {
663
663
  * The graph compiles resource hazards, transient lifetimes, and node resources,
664
664
  * but encoding and submission remain controlled by the application.
665
665
  */
666
- export class GPUCommandGraph<Parameters = void> {
667
- /** WebGPU device that owns compilation and transient resources. */
666
+ /** @internal Shared resource planner and executor builder used by SimpleGraph render passes. */
667
+ export class GPUCommandGraphBuilder<Parameters = void> {
668
+ /** Device that owns compilation and transient resources. */
668
669
  readonly device: Device;
669
670
  /** Identifier used as a prefix for graph-owned GPU resources. */
670
671
  readonly id: string;
@@ -683,14 +684,10 @@ export class GPUCommandGraph<Parameters = void> {
683
684
  /**
684
685
  * Creates a mutable graph definition.
685
686
  *
686
- * @param device WebGPU device used to compile and execute the graph.
687
+ * @param device Device used to compile and execute the graph.
687
688
  * @param props Optional graph identity and generic adaptive-kernel selector.
688
- * @throws If `device` is not a WebGPU device.
689
689
  */
690
690
  constructor(device: Device, props: {id?: string; autotuner?: GPUCommandGraphAutotuner} = {}) {
691
- if (device.type !== 'webgpu') {
692
- throw new Error('GPUCommandGraph requires a WebGPU device');
693
- }
694
691
  assertDeviceAvailable(device, 'construction');
695
692
  this.device = device;
696
693
  this.id = props.id ?? 'gpu-command-graph';
@@ -1025,6 +1022,10 @@ export class GPUCommandGraph<Parameters = void> {
1025
1022
  }
1026
1023
 
1027
1024
  private addNode(node: GPUCommandGraphNode<Parameters>): void {
1025
+ // SimpleGraph only exposes render passes on WebGL. Compute requires WebGPU.
1026
+ if (this.device.type !== 'webgpu' && node.type !== 'render') {
1027
+ throw new Error('WebGL graphs support render passes only');
1028
+ }
1028
1029
  this.assertMutable();
1029
1030
  if (!node.id) {
1030
1031
  throw new Error('GPUCommandGraph node id is required');
@@ -1115,6 +1116,15 @@ export class GPUCommandGraph<Parameters = void> {
1115
1116
  this.assertTexture(texture);
1116
1117
  validateTextureUseAgainstDescriptor(texture, resource.usage);
1117
1118
  validateTextureViewForUsage(resource.texture, resource.usage);
1119
+ // WebGL sampler bindings use the underlying texture, not a selected view range.
1120
+ if (
1121
+ this.device.type === 'webgl' &&
1122
+ resource.usage === 'sampled' &&
1123
+ resource.texture instanceof GraphTextureView &&
1124
+ !isDefaultGraphTextureView(resource.texture)
1125
+ ) {
1126
+ throw new Error('WebGL sampled textures require a full-resource view');
1127
+ }
1118
1128
  } else {
1119
1129
  this.assertExternalTexture(resource.externalTexture);
1120
1130
  if (resource.usage !== 'sampled') {
@@ -2524,3 +2534,13 @@ function isDefaultGraphTextureView(view: GraphTextureView): boolean {
2524
2534
  view.arrayLayerCount === (texture.dimension === '3d' ? 1 : texture.depth)
2525
2535
  );
2526
2536
  }
2537
+
2538
+ /** WebGPU command graph. SimpleGraph reuses its resource planner for portable render passes. */
2539
+ export class GPUCommandGraph<Parameters = void> extends GPUCommandGraphBuilder<Parameters> {
2540
+ constructor(device: Device, props: {id?: string; autotuner?: GPUCommandGraphAutotuner} = {}) {
2541
+ if (device.type !== 'webgpu') {
2542
+ throw new Error('GPUCommandGraph requires a WebGPU device');
2543
+ }
2544
+ super(device, props);
2545
+ }
2546
+ }
@@ -0,0 +1,345 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {assert, type Device} from '@luma.gl/core';
6
+ import {CPUData, CPUVector, GPUVector, getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
7
+ import {GPUGraph} from './gpu-graph';
8
+ import {gpuGraph} from './gpu-graph-value';
9
+ import {GPUCPUOperation, type GPUCPUVector, type GPUCPUArray} from './gpu-cpu-operation';
10
+ import {GPUExpressionProgram, type GPUGraphRunBindings} from './gpu-expression-plan';
11
+ import {GPUUploadOperation} from './gpu-transfer-operation';
12
+ import type {GPUGraphExecutionBindings} from './gpu-expression-plan';
13
+
14
+ /** Backend-specific GPU stage; CPU scheduling is shared by both graph executors. */
15
+ export type GPUCPUStage = {
16
+ run(bindings: GPUGraphExecutionBindings): Promise<Record<string, GPUVector>>;
17
+ destroy(): void;
18
+ };
19
+ export type GPUCPUStageCompiler = (source: GPUGraph, outputs?: readonly string[]) => GPUCPUStage;
20
+
21
+ /** Submission boundaries around CPU callbacks; each GPU stage resolves its shapes independently. */
22
+ export class GPUCPUExecution {
23
+ private readonly stages: (
24
+ | GPUCPUOperation
25
+ | {
26
+ graph: GPUCPUStage;
27
+ inputs: readonly string[];
28
+ }
29
+ )[] = [];
30
+
31
+ constructor(
32
+ readonly device: Device,
33
+ readonly program: GPUExpressionProgram,
34
+ private readonly compileStage: GPUCPUStageCompiler
35
+ ) {
36
+ // Initial support is for pure numeric, operation-owned results.
37
+ assert(!program.textures.length && !program.vectors.some(value => value.role === 'state'));
38
+ const declarations = [...program.scalars, ...program.vectors];
39
+ const addInput = (graph: GPUGraph, name: string) => {
40
+ const declaration = declarations.find(value => value.id === name)!;
41
+ assert(declaration);
42
+ const vector = program.vectors.find(value => value.id === name);
43
+ if (vector)
44
+ graph.addInput(
45
+ name,
46
+ gpuGraph.vector(vector.format, {
47
+ length: vector.length,
48
+ chunkLengths: vector.chunkLengths
49
+ })
50
+ );
51
+ else
52
+ graph.addInput(
53
+ name,
54
+ gpuGraph.scalar(program.scalars.find(value => value.id === name)!.format)
55
+ );
56
+ };
57
+ try {
58
+ for (const operation of program.operations) {
59
+ if (operation instanceof GPUCPUOperation) {
60
+ this.stages.push(operation);
61
+ continue;
62
+ }
63
+ assert('contract' in operation && operation.contract);
64
+ const inputs = operation.contract.values
65
+ .filter(use => use.access !== 'write')
66
+ .map(use => (typeof use.value === 'string' ? use.value : use.value.id));
67
+ const outputs = operation.contract.values
68
+ .filter(use => use.access !== 'read')
69
+ .map(use => (typeof use.value === 'string' ? use.value : use.value.id));
70
+ const graph = new GPUGraph();
71
+ for (const name of new Set(inputs)) addInput(graph, name);
72
+ for (const name of new Set(outputs)) {
73
+ const vector = program.vectors.find(value => value.id === name);
74
+ if (vector)
75
+ graph.addDeclaration(
76
+ name,
77
+ gpuGraph.vector(vector.format, {
78
+ length: vector.length,
79
+ chunkLengths: vector.chunkLengths
80
+ }),
81
+ 'value'
82
+ );
83
+ }
84
+ graph.add(operation);
85
+ this.stages.push({
86
+ graph: compileStage(graph, outputs),
87
+ inputs
88
+ });
89
+ }
90
+ } catch (error) {
91
+ this.destroy();
92
+ throw error;
93
+ }
94
+ }
95
+
96
+ async run(
97
+ bindings: GPUGraphRunBindings,
98
+ locations: Readonly<Record<string, 'cpu' | 'gpu'>> = {}
99
+ ): Promise<Record<string, GPUVector | CPUVector>> {
100
+ for (const [name, location] of Object.entries(locations))
101
+ assert(this.program.outputs.includes(name) && (location === 'cpu' || location === 'gpu'));
102
+ const cpu = new Map<string, CPUVector>();
103
+ for (const declaration of [...this.program.vectors, ...this.program.scalars].filter(
104
+ value => value.role === 'input'
105
+ )) {
106
+ const value = bindings[declaration.id];
107
+ assert(value !== undefined);
108
+ if (!(value instanceof CPUVector)) {
109
+ const graph = new GPUGraph();
110
+ const vector = this.program.vectors.find(vector => vector.id === declaration.id);
111
+ if (vector)
112
+ graph.addInput(
113
+ declaration.id,
114
+ gpuGraph.vector(vector.format, {
115
+ length: vector.length,
116
+ chunkLengths: vector.chunkLengths
117
+ })
118
+ );
119
+ else
120
+ graph.addInput(
121
+ declaration.id,
122
+ gpuGraph.scalar(
123
+ this.program.scalars.find(scalar => scalar.id === declaration.id)!.format
124
+ )
125
+ );
126
+ new GPUExpressionProgram(graph, {outputs: []})
127
+ .prepare(this.device, {[declaration.id]: value})
128
+ .finish();
129
+ }
130
+ if (value instanceof CPUVector) {
131
+ // List and validity metadata cannot be represented by portable callback rows yet.
132
+ assert(value.data.every(chunk => !chunk.nullBitmap && !chunk.valueOffsets));
133
+ assert(value.format === declaration.format);
134
+ const vector = this.program.vectors.find(vector => vector.id === declaration.id);
135
+ assert(vector && (vector.length === undefined || vector.length === value.length));
136
+ assert(
137
+ !vector.chunkLengths ||
138
+ (vector.chunkLengths.length === value.data.length &&
139
+ vector.chunkLengths.every((length, index) => length === value.data[index].length))
140
+ );
141
+ cpu.set(declaration.id, value);
142
+ }
143
+ }
144
+ const values: Record<string, GPUGraphRunBindings[string]> = {...bindings};
145
+ const owned = new Set<GPUVector>();
146
+ const ensureCPU = async (name: string): Promise<GPUCPUVector> => {
147
+ let value = cpu.get(name);
148
+ if (!value) {
149
+ const gpu = values[name];
150
+ assert(gpu instanceof GPUVector);
151
+ const read = await readCPUVector(gpu);
152
+ value = makeCPUVector(
153
+ read.format,
154
+ read.chunks.map(chunk => chunk.values)
155
+ );
156
+ cpu.set(name, value);
157
+ }
158
+ return getCPUView(value);
159
+ };
160
+ const ensureGPU = async (name: string): Promise<GPUVector> => {
161
+ const existing = values[name];
162
+ if (existing instanceof GPUVector) return existing;
163
+ const view = await ensureCPU(name);
164
+ const graph = new GPUGraph();
165
+ graph.add(
166
+ new GPUUploadOperation({
167
+ output: name,
168
+ format: view.format,
169
+ data: view.chunks.map(chunk => chunk.values)
170
+ })
171
+ );
172
+ const compiled = this.compileStage(graph);
173
+ try {
174
+ const result = (await compiled.run({}))[name];
175
+ owned.add(result);
176
+ values[name] = result;
177
+ return result;
178
+ } finally {
179
+ compiled.destroy();
180
+ }
181
+ };
182
+ try {
183
+ for (const stage of this.stages) {
184
+ let results: Record<string, GPUVector>;
185
+ if (stage instanceof GPUCPUOperation) {
186
+ const inputs: Record<string, GPUCPUVector | number> = Object.create(null);
187
+ for (const [localName, name] of Object.entries(stage.inputs)) {
188
+ const value = values[name];
189
+ const cpuValue = typeof value === 'number' ? value : await ensureCPU(name);
190
+ inputs[localName] =
191
+ typeof cpuValue !== 'number' &&
192
+ this.program.scalars.some(scalar => scalar.id === name)
193
+ ? cpuValue.pack()[0]
194
+ : cpuValue;
195
+ }
196
+ const outputs = await stage.execute({inputs});
197
+ assert(Object.keys(outputs).length === Object.keys(stage.outputs).length);
198
+ for (const name of Object.keys(stage.outputs)) {
199
+ // The resolved declaration includes constraints supplied through graph.vector().
200
+ const descriptor = this.program.vectors.find(vector => vector.id === name)!;
201
+ const result = outputs[name];
202
+ assert(result);
203
+ const arrays = 'chunks' in result ? result.chunks.map(chunk => chunk.values) : [result];
204
+ const upload = new GPUUploadOperation({
205
+ output: name,
206
+ format: descriptor.format,
207
+ data: arrays
208
+ });
209
+ const length = upload.chunkLengths.reduce((total, count) => total + count, 0);
210
+ // Returned rows must satisfy any declared fixed shape.
211
+ assert(descriptor.length === undefined || descriptor.length === length);
212
+ assert(
213
+ !descriptor.chunkLengths ||
214
+ (descriptor.chunkLengths.length === arrays.length &&
215
+ descriptor.chunkLengths.every(
216
+ (count, index) => count === upload.chunkLengths[index]
217
+ ))
218
+ );
219
+ cpu.set(name, makeCPUVector(descriptor.format, arrays));
220
+ delete values[name];
221
+ }
222
+ continue;
223
+ } else {
224
+ const inputs: Record<string, GPUGraphRunBindings[string]> = Object.create(null);
225
+ for (const name of stage.inputs) {
226
+ const value = values[name];
227
+ // Stage scalar inputs are host numbers, including results produced by an earlier GPU stage.
228
+ inputs[name] = this.program.scalars.some(scalar => scalar.id === name)
229
+ ? typeof value === 'number'
230
+ ? value
231
+ : (await ensureCPU(name)).pack()[0]
232
+ : await ensureGPU(name);
233
+ }
234
+ results = await stage.graph.run({inputs});
235
+ }
236
+ for (const [name, value] of Object.entries(results)) {
237
+ cpu.delete(name);
238
+ values[name] = value;
239
+ owned.add(value);
240
+ }
241
+ }
242
+ const outputs: Record<string, GPUVector | CPUVector> = Object.create(null);
243
+ for (const name of this.program.outputs) {
244
+ if (locations[name] === 'cpu') {
245
+ await ensureCPU(name);
246
+ outputs[name] = cpu.get(name)!;
247
+ } else outputs[name] = await ensureGPU(name);
248
+ }
249
+ for (const value of Object.values(outputs))
250
+ if (value instanceof GPUVector) owned.delete(value);
251
+ return outputs;
252
+ } finally {
253
+ for (const value of owned) value.destroy();
254
+ }
255
+ }
256
+
257
+ destroy(): void {
258
+ for (const stage of this.stages) if (!(stage instanceof GPUCPUOperation)) stage.graph.destroy();
259
+ }
260
+ }
261
+
262
+ async function readCPUVector(vector: GPUVector): Promise<GPUCPUVector> {
263
+ assert(vector.format);
264
+ const info = getGPUVectorFormatInfo(vector.format);
265
+ const ValueType =
266
+ info.signedDataType === 'float32'
267
+ ? Float32Array
268
+ : info.signedDataType === 'uint32'
269
+ ? Uint32Array
270
+ : Int32Array;
271
+ const chunks: {values: GPUCPUArray; length: number}[] = [];
272
+ for (const chunk of vector.data) {
273
+ const values = new ValueType((chunk.length * info.byteLength) / 4);
274
+ if (chunk.length) {
275
+ const bytes = await chunk.buffer.readAsync(
276
+ chunk.byteOffset,
277
+ (chunk.length - 1) * chunk.byteStride + info.byteLength
278
+ );
279
+ const packed = new Uint8Array(values.buffer);
280
+ for (let row = 0; row < chunk.length; row++)
281
+ packed.set(
282
+ bytes.subarray(row * chunk.byteStride, row * chunk.byteStride + info.byteLength),
283
+ row * info.byteLength
284
+ );
285
+ }
286
+ chunks.push({values, length: chunk.length});
287
+ }
288
+ return {
289
+ format: vector.format as GPUCPUVector['format'],
290
+ length: vector.length,
291
+ chunks,
292
+ pack() {
293
+ const packed = new ValueType(chunks.reduce((total, chunk) => total + chunk.values.length, 0));
294
+ let offset = 0;
295
+ for (const chunk of chunks) {
296
+ packed.set(chunk.values, offset);
297
+ offset += chunk.values.length;
298
+ }
299
+ return packed;
300
+ }
301
+ };
302
+ }
303
+
304
+ function makeCPUVector(format: GPUCPUVector['format'], arrays: readonly GPUCPUArray[]): CPUVector {
305
+ const width = getGPUVectorFormatInfo(format).byteLength;
306
+ return new CPUVector({
307
+ format,
308
+ data: arrays.map(buffer => new CPUData({buffer, format, length: buffer.byteLength / width}))
309
+ });
310
+ }
311
+ function getCPUView(vector: CPUVector): GPUCPUVector {
312
+ const format = vector.format as GPUCPUVector['format'];
313
+ assert(/^(float32|sint32|uint32)(x[234])?$/.test(format));
314
+ const info = getGPUVectorFormatInfo(format);
315
+ const ValueType =
316
+ info.signedDataType === 'float32'
317
+ ? Float32Array
318
+ : info.signedDataType === 'uint32'
319
+ ? Uint32Array
320
+ : Int32Array;
321
+ const chunks = vector.data.map(chunk => {
322
+ const values = new ValueType(chunk.length * info.components);
323
+ const bytes = new Uint8Array(values.buffer);
324
+ for (let row = 0; row < chunk.length; row++)
325
+ bytes.set(
326
+ new Uint8Array(chunk.buffer, chunk.byteOffset + row * chunk.byteStride, info.byteLength),
327
+ row * info.byteLength
328
+ );
329
+ return {values, length: chunk.length};
330
+ });
331
+ return {
332
+ format,
333
+ length: vector.length,
334
+ chunks,
335
+ pack() {
336
+ const values = new ValueType(vector.length * info.components);
337
+ let offset = 0;
338
+ for (const chunk of chunks) {
339
+ values.set(chunk.values, offset);
340
+ offset += chunk.values.length;
341
+ }
342
+ return values;
343
+ }
344
+ };
345
+ }
@@ -0,0 +1,65 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {GPUOperation} from './gpu-operation';
6
+ import type {GPUOperationContract} from './gpu-operation-contract';
7
+ import type {GPUGraphVectorDescriptor, GPUGraphVectorFormat} from './gpu-graph-value';
8
+
9
+ /** Packed numeric rows supported by portable graph operations. */
10
+ export type GPUCPUArray = Float32Array | Int32Array | Uint32Array;
11
+ export type GPUCPUVector = {
12
+ readonly format: GPUGraphVectorFormat;
13
+ readonly length: number;
14
+ readonly chunks: readonly {readonly values: GPUCPUArray; readonly length: number}[];
15
+ /** Explicitly combine the source chunks into a new packed array. */
16
+ pack(): GPUCPUArray;
17
+ };
18
+ export type GPUCPUResult = GPUCPUArray | {chunks: readonly {values: GPUCPUArray}[]};
19
+ export type GPUCPUOperationProps = {
20
+ id: string;
21
+ inputs: Readonly<Record<string, string>>;
22
+ outputs: Readonly<Record<string, GPUGraphVectorDescriptor>>;
23
+ /** Input arrays are borrowed read-only snapshots. Do not mutate returned arrays until run settles. */
24
+ execute(context: {
25
+ inputs: Readonly<Record<string, GPUCPUVector | number>>;
26
+ }): Record<string, GPUCPUResult> | Promise<Record<string, GPUCPUResult>>;
27
+ };
28
+
29
+ /** Shared CPU operation intent. Executed by reusable, unscoped GPUGraph and GPUSimpleGraph. */
30
+ export class GPUCPUOperation implements GPUOperation {
31
+ readonly type = 'cpu';
32
+ readonly id: string;
33
+ readonly inputs: GPUCPUOperationProps['inputs'];
34
+ readonly outputs: GPUCPUOperationProps['outputs'];
35
+ readonly execute: GPUCPUOperationProps['execute'];
36
+
37
+ constructor(props: GPUCPUOperationProps) {
38
+ this.id = props.id;
39
+ this.inputs = Object.freeze({...props.inputs});
40
+ this.outputs = Object.freeze(
41
+ Object.fromEntries(
42
+ Object.entries(props.outputs).map(([name, descriptor]) => [
43
+ name,
44
+ Object.freeze({
45
+ ...descriptor,
46
+ ...(descriptor.chunkLengths
47
+ ? {chunkLengths: Object.freeze([...descriptor.chunkLengths])}
48
+ : {})
49
+ })
50
+ ])
51
+ )
52
+ );
53
+ this.execute = props.execute;
54
+ }
55
+
56
+ get contract(): GPUOperationContract {
57
+ return {
58
+ outputs: this.outputs,
59
+ values: [
60
+ ...Object.values(this.inputs).map(value => ({value, access: 'read' as const})),
61
+ ...Object.keys(this.outputs).map(value => ({value, access: 'write' as const}))
62
+ ]
63
+ };
64
+ }
65
+ }
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import {parse, type Expression} from '@math.gl/core';
5
+ import {parse, type Expression} from '@math.gl/core/expressions';
6
6
  import {getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
7
7
  import {gpuGraph, type GPUGraphVectorFormat} from './gpu-graph-value';
8
8
  import type {GPUOperationContract} from './gpu-operation-contract';
@@ -3,7 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Buffer, Texture, TextureView, type Device} from '@luma.gl/core';
6
- import {GPUData, GPUVector, getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
6
+ import {CPUVector, GPUData, GPUVector, getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
7
7
  import type {GPUGraph} from './gpu-graph';
8
8
  import {GPUCopyOperation} from './gpu-transfer-operation';
9
9
  import {validateTextureCopy} from './gpu-texture-copy';
@@ -37,7 +37,7 @@ import {
37
37
  } from './gpu-operation-contract';
38
38
 
39
39
  export type GPUGraphRunBindings = Readonly<
40
- Record<string, GPUVector | number | GPUGraphTextureBinding>
40
+ Record<string, GPUVector | CPUVector | number | GPUGraphTextureBinding>
41
41
  >;
42
42
  export type GPUGraphExecutionBindings = {
43
43
  inputs?: GPUGraphRunBindings;
@@ -46,6 +46,7 @@ export type GPUGraphExecutionBindings = {
46
46
  };
47
47
  export type GPUGraphCompileOptions = {
48
48
  outputs?: readonly string[];
49
+ outputLocations?: Readonly<Record<string, 'cpu' | 'gpu'>>;
49
50
  lowerings?: readonly GPUOperationLowering[];
50
51
  };
51
52
  export type GPUGraphRunOptions = {outputTargets?: Readonly<Record<string, GPUGraphOutput>>};
@@ -259,6 +260,7 @@ export class GPUExpressionProgram {
259
260
  value !== undefined &&
260
261
  typeof value === 'object' &&
261
262
  !(value instanceof GPUVector) &&
263
+ !(value instanceof CPUVector) &&
262
264
  !(value instanceof Texture) &&
263
265
  !(value instanceof TextureView)
264
266
  );
@@ -272,7 +274,7 @@ export class GPUExpressionProgram {
272
274
  if (!['inputs', 'state', 'outputTargets'].includes(name))
273
275
  throw new Error(`Unknown execution option ${name}`);
274
276
  const execution = supplied as GPUGraphExecutionBindings;
275
- const bindings: Record<string, GPUVector | number | GPUGraphTextureBinding> =
277
+ const bindings: Record<string, GPUVector | CPUVector | number | GPUGraphTextureBinding> =
276
278
  Object.create(null);
277
279
  for (const [role, group] of [
278
280
  ['input', execution.inputs],
@@ -222,9 +222,9 @@ export class GPUGraph {
222
222
  throw new Error(`${this.id} accepts GPU operations only`);
223
223
  }
224
224
  }
225
- export function composite(
226
- operations: readonly GPUGraphOperation[],
225
+ export function composite<Operation extends GPUGraphOperation>(
226
+ operations: readonly Operation[],
227
227
  props: {id?: string} = {}
228
- ): GPUCompositeOperation {
228
+ ): GPUCompositeOperation<Operation> {
229
229
  return new GPUCompositeOperation({id: props.id, operations});
230
230
  }