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

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 (240) 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 +1233 -442
  37. package/dist/dist.min.js +126 -108
  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 +47 -0
  41. package/dist/gpu-core/compiled-gpu-graph.d.ts +5 -0
  42. package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
  43. package/dist/gpu-core/compiled-gpu-graph.js +54 -1
  44. package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
  45. package/dist/gpu-core/gpu-command-graph.cjs +28 -7
  46. package/dist/gpu-core/gpu-command-graph.d.ts +13 -4
  47. package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
  48. package/dist/gpu-core/gpu-command-graph.js +33 -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 +5 -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 +7 -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-shader-pass-kernel.cjs +267 -0
  82. package/dist/gpu-core/gpu-shader-pass-kernel.d.ts +29 -0
  83. package/dist/gpu-core/gpu-shader-pass-kernel.d.ts.map +1 -0
  84. package/dist/gpu-core/gpu-shader-pass-kernel.js +260 -0
  85. package/dist/gpu-core/gpu-shader-pass-kernel.js.map +1 -0
  86. package/dist/gpu-core/gpu-shader-pass-operation.cjs +85 -0
  87. package/dist/gpu-core/gpu-shader-pass-operation.d.ts +32 -0
  88. package/dist/gpu-core/gpu-shader-pass-operation.d.ts.map +1 -0
  89. package/dist/gpu-core/gpu-shader-pass-operation.js +74 -0
  90. package/dist/gpu-core/gpu-shader-pass-operation.js.map +1 -0
  91. package/dist/gpu-core/gpu-texture-plan.d.ts +3 -2
  92. package/dist/gpu-core/gpu-texture-plan.d.ts.map +1 -1
  93. package/dist/gpu-core/gpu-texture-plan.js.map +1 -1
  94. package/dist/gpu-core/index.cjs +9 -0
  95. package/dist/gpu-core/index.cjs.map +3 -3
  96. package/dist/gpu-core/index.d.ts +6 -0
  97. package/dist/gpu-core/index.d.ts.map +1 -1
  98. package/dist/gpu-core/index.js +3 -0
  99. package/dist/gpu-core/index.js.map +1 -1
  100. package/dist/gpu-data/cpu-data.cjs +60 -0
  101. package/dist/gpu-data/cpu-data.d.ts +28 -0
  102. package/dist/gpu-data/cpu-data.d.ts.map +1 -0
  103. package/dist/gpu-data/cpu-data.js +41 -0
  104. package/dist/gpu-data/cpu-data.js.map +1 -0
  105. package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +93 -0
  106. package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts +9 -0
  107. package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -0
  108. package/dist/gpu-data/cpu-gpu-vector-transfer.js +82 -0
  109. package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -0
  110. package/dist/gpu-data/cpu-vector.cjs +42 -0
  111. package/dist/gpu-data/cpu-vector.d.ts +17 -0
  112. package/dist/gpu-data/cpu-vector.d.ts.map +1 -0
  113. package/dist/gpu-data/cpu-vector.js +21 -0
  114. package/dist/gpu-data/cpu-vector.js.map +1 -0
  115. package/dist/gpu-data/index.cjs +13 -2
  116. package/dist/gpu-data/index.cjs.map +3 -3
  117. package/dist/gpu-data/index.d.ts +3 -0
  118. package/dist/gpu-data/index.d.ts.map +1 -1
  119. package/dist/gpu-data/index.js +3 -0
  120. package/dist/gpu-data/index.js.map +1 -1
  121. package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
  122. package/dist/gpu-graph/index.cjs +3 -0
  123. package/dist/gpu-graph/index.cjs.map +3 -3
  124. package/dist/gpu-graph/index.d.ts +2 -0
  125. package/dist/gpu-graph/index.d.ts.map +1 -1
  126. package/dist/gpu-graph/index.js +1 -0
  127. package/dist/gpu-graph/index.js.map +1 -1
  128. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
  129. package/dist/gpu-physics/index.cjs.map +1 -1
  130. package/dist/gpu-project/coordinate-projection-graph.cjs +59 -0
  131. package/dist/gpu-project/coordinate-projection-graph.d.ts +23 -0
  132. package/dist/gpu-project/coordinate-projection-graph.d.ts.map +1 -0
  133. package/dist/gpu-project/coordinate-projection-graph.js +40 -0
  134. package/dist/gpu-project/coordinate-projection-graph.js.map +1 -0
  135. package/dist/gpu-project/cpu-geoarrow.cjs +112 -0
  136. package/dist/gpu-project/cpu-geoarrow.d.ts +10 -0
  137. package/dist/gpu-project/cpu-geoarrow.d.ts.map +1 -0
  138. package/dist/gpu-project/cpu-geoarrow.js +103 -0
  139. package/dist/gpu-project/cpu-geoarrow.js.map +1 -0
  140. package/dist/gpu-project/cpu-geometry-pipelines.cjs +134 -0
  141. package/dist/gpu-project/cpu-geometry-pipelines.d.ts +18 -0
  142. package/dist/gpu-project/cpu-geometry-pipelines.d.ts.map +1 -0
  143. package/dist/gpu-project/cpu-geometry-pipelines.js +114 -0
  144. package/dist/gpu-project/cpu-geometry-pipelines.js.map +1 -0
  145. package/dist/gpu-project/cpu-projection-operation.cjs +54 -0
  146. package/dist/gpu-project/cpu-projection-operation.d.ts +14 -0
  147. package/dist/gpu-project/cpu-projection-operation.d.ts.map +1 -0
  148. package/dist/gpu-project/cpu-projection-operation.js +37 -0
  149. package/dist/gpu-project/cpu-projection-operation.js.map +1 -0
  150. package/dist/gpu-project/geoarrow.cjs +36 -0
  151. package/dist/gpu-project/geoarrow.cjs.map +6 -0
  152. package/dist/gpu-project/geoarrow.d.ts +3 -0
  153. package/dist/gpu-project/geoarrow.d.ts.map +1 -0
  154. package/dist/gpu-project/geoarrow.js +7 -0
  155. package/dist/gpu-project/geoarrow.js.map +1 -0
  156. package/dist/gpu-project/graph.cjs +27 -0
  157. package/dist/gpu-project/graph.cjs.map +6 -0
  158. package/dist/gpu-project/graph.d.ts +2 -0
  159. package/dist/gpu-project/graph.d.ts.map +1 -0
  160. package/dist/gpu-project/graph.js +6 -0
  161. package/dist/gpu-project/graph.js.map +1 -0
  162. package/dist/gpu-project/index.cjs +3 -0
  163. package/dist/gpu-project/index.cjs.map +3 -3
  164. package/dist/gpu-project/index.d.ts +1 -0
  165. package/dist/gpu-project/index.d.ts.map +1 -1
  166. package/dist/gpu-project/index.js +1 -0
  167. package/dist/gpu-project/index.js.map +1 -1
  168. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +75 -5
  169. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +5 -1
  170. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts.map +1 -1
  171. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js +86 -6
  172. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
  173. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.cjs +9 -0
  174. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.d.ts +2 -0
  175. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.d.ts.map +1 -1
  176. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.js +10 -0
  177. package/dist/gpu-simple-graph/gpu-simple-graph-lowering.js.map +1 -1
  178. package/dist/gpu-simple-graph/gpu-simple-graph.cjs +126 -10
  179. package/dist/gpu-simple-graph/gpu-simple-graph.d.ts +36 -11
  180. package/dist/gpu-simple-graph/gpu-simple-graph.d.ts.map +1 -1
  181. package/dist/gpu-simple-graph/gpu-simple-graph.js +137 -12
  182. package/dist/gpu-simple-graph/gpu-simple-graph.js.map +1 -1
  183. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  184. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.cjs +23 -0
  185. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.d.ts +6 -0
  186. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.d.ts.map +1 -1
  187. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js +25 -0
  188. package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js.map +1 -1
  189. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.cjs +7 -0
  190. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.d.ts +2 -0
  191. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.d.ts.map +1 -1
  192. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.js +7 -0
  193. package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.js.map +1 -1
  194. package/dist/gpu-simple-graph/operations/webgl/index.cjs.map +1 -1
  195. package/dist/gpu-simple-graph/operations/webgpu/index.cjs.map +1 -1
  196. package/dist/index.cjs +6 -0
  197. package/dist/index.cjs.map +3 -3
  198. package/dist/index.d.ts +4 -0
  199. package/dist/index.d.ts.map +1 -1
  200. package/dist/index.js +2 -0
  201. package/dist/index.js.map +1 -1
  202. package/package.json +17 -6
  203. package/src/arrow/cpu/arrow-coordinate-projection.ts +18 -0
  204. package/src/arrow/cpu/arrow-cpu-pipelines.ts +9 -0
  205. package/src/arrow/cpu/arrow-cpu-vector-adapters.ts +153 -0
  206. package/src/arrow/geoarrow/arrow-geoarrow-adapter.ts +23 -493
  207. package/src/arrow/geoarrow/arrow-geoarrow-conversion.ts +5 -3
  208. package/src/arrow/geoarrow/arrow-polygon-tessellation.ts +1 -1
  209. package/src/arrow/index.ts +11 -0
  210. package/src/gpu-core/compiled-gpu-graph.ts +73 -1
  211. package/src/gpu-core/gpu-command-graph.ts +37 -7
  212. package/src/gpu-core/gpu-cpu-execution.ts +345 -0
  213. package/src/gpu-core/gpu-cpu-operation.ts +65 -0
  214. package/src/gpu-core/gpu-expression-operation.ts +1 -1
  215. package/src/gpu-core/gpu-expression-plan.ts +11 -3
  216. package/src/gpu-core/gpu-graph.ts +3 -3
  217. package/src/gpu-core/gpu-operation.ts +9 -7
  218. package/src/gpu-core/gpu-render-operation.ts +42 -0
  219. package/src/gpu-core/gpu-shader-pass-kernel.ts +307 -0
  220. package/src/gpu-core/gpu-shader-pass-operation.ts +103 -0
  221. package/src/gpu-core/gpu-texture-plan.ts +3 -2
  222. package/src/gpu-core/index.ts +12 -0
  223. package/src/gpu-data/cpu-data.ts +62 -0
  224. package/src/gpu-data/cpu-gpu-vector-transfer.ts +107 -0
  225. package/src/gpu-data/cpu-vector.ts +31 -0
  226. package/src/gpu-data/index.ts +5 -0
  227. package/src/gpu-graph/index.ts +8 -0
  228. package/src/gpu-project/coordinate-projection-graph.ts +59 -0
  229. package/src/gpu-project/cpu-geoarrow.ts +135 -0
  230. package/src/gpu-project/cpu-geometry-pipelines.ts +159 -0
  231. package/src/gpu-project/cpu-projection-operation.ts +49 -0
  232. package/src/gpu-project/geoarrow.ts +11 -0
  233. package/src/gpu-project/graph.ts +10 -0
  234. package/src/gpu-project/index.ts +2 -0
  235. package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +97 -6
  236. package/src/gpu-simple-graph/gpu-simple-graph-lowering.ts +11 -0
  237. package/src/gpu-simple-graph/gpu-simple-graph.ts +163 -19
  238. package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +22 -0
  239. package/src/gpu-simple-graph/operation/gpu-vector-evaluator.ts +7 -0
  240. package/src/index.ts +10 -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,22 @@ import {
23
23
  type GPUGraphRunOptions
24
24
  } from './gpu-expression-plan';
25
25
  import {GPUExpressionKernel} from './gpu-expression-kernel';
26
+ import {GPUShaderPassOperation} from './gpu-shader-pass-operation';
27
+ import {GPUShaderPassKernel} from './gpu-shader-pass-kernel';
28
+ import {GPUCPUOperation} from './gpu-cpu-operation';
29
+ import {GPUCPUExecution} from './gpu-cpu-execution';
26
30
 
27
31
  /** Reusable WebGPU program. Returned output vectors belong to the caller. */
28
32
  export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, GPUVector>> {
29
33
  private readonly program: GPUExpressionProgram;
34
+ private readonly stageLowerings: readonly GPUOperationLowering[];
30
35
  private readonly compiler: GPUGraphCompiler;
31
36
  private readonly kernels = new Map<GPUExpressionOperation, GPUExpressionKernel>();
37
+ private readonly shaderPasses = new Map<GPUShaderPassOperation, GPUShaderPassKernel>();
32
38
  private destroyed = false;
39
+ private runningCPU = false;
40
+ private cpuExecution?: GPUCPUExecution;
41
+ private readonly outputLocations: Readonly<Record<string, 'cpu' | 'gpu'>>;
33
42
 
34
43
  constructor(
35
44
  readonly device: Device,
@@ -39,17 +48,42 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
39
48
  ) {
40
49
  if (device.type !== 'webgpu') throw new Error('GPUGraph execution requires WebGPU');
41
50
  this.program = new GPUExpressionProgram(source, options);
51
+ this.outputLocations = options.outputLocations ?? {};
52
+ this.stageLowerings = lowerings ?? options.lowerings ?? [];
42
53
  this.compiler = new GPUGraphCompiler(device, [
43
54
  ...(lowerings ?? options.lowerings ?? []),
55
+ {
56
+ type: 'shader-pass',
57
+ lower: (operation: GPUShaderPassOperation, context) =>
58
+ this.shaderPasses.get(operation)!.lower(context)
59
+ },
44
60
  {
45
61
  type: 'expression',
46
62
  lower: (operation: GPUExpressionOperation, context) =>
47
63
  this.kernels.get(operation)!.lower(context)
48
64
  }
49
65
  ]);
66
+ if (
67
+ this.program.operations.some(operation => operation instanceof GPUCPUOperation) ||
68
+ Object.values(this.outputLocations).includes('cpu')
69
+ ) {
70
+ this.cpuExecution = new GPUCPUExecution(
71
+ device,
72
+ this.program,
73
+ (source, outputs) =>
74
+ new CompiledGPUGraph(device, source, {outputs}, lowerings ?? options.lowerings)
75
+ );
76
+ return;
77
+ }
50
78
  try {
51
79
  for (const plan of this.program.expressions)
52
80
  this.kernels.set(plan.operation, new GPUExpressionKernel(device, this.program, plan));
81
+ for (const operation of this.program.operations)
82
+ if (operation instanceof GPUShaderPassOperation)
83
+ this.shaderPasses.set(
84
+ operation,
85
+ new GPUShaderPassKernel(device, operation, this.program)
86
+ );
53
87
  } catch (error) {
54
88
  this.destroy();
55
89
  throw error;
@@ -60,6 +94,32 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
60
94
  supplied: GPUGraphRunBindings | GPUGraphExecutionBindings,
61
95
  options: GPUGraphRunOptions = {}
62
96
  ): Promise<Outputs> {
97
+ assert(!this.destroyed && !this.runningCPU);
98
+ const suppliedInputs = 'inputs' in supplied ? supplied.inputs : supplied;
99
+ const useCPU =
100
+ this.program.operations.some(operation => operation instanceof GPUCPUOperation) ||
101
+ Object.values(this.outputLocations).includes('cpu') ||
102
+ Object.values(suppliedInputs ?? {}).some(value => value instanceof CPUVector);
103
+ if (!this.cpuExecution && useCPU)
104
+ this.cpuExecution = new GPUCPUExecution(
105
+ this.device,
106
+ this.program,
107
+ (source, outputs) =>
108
+ new CompiledGPUGraph(this.device, source, {outputs}, this.stageLowerings)
109
+ );
110
+ if (useCPU && this.cpuExecution) {
111
+ const resolved = this.program.resolveBindings(supplied, options);
112
+ // Dynamic CPU outputs are owned by the invocation, not caller-provided targets.
113
+ assert(
114
+ !resolved.options.outputTargets || Object.keys(resolved.options.outputTargets).length === 0
115
+ );
116
+ this.runningCPU = true;
117
+ try {
118
+ return (await this.cpuExecution.run(resolved.bindings, this.outputLocations)) as Outputs;
119
+ } finally {
120
+ this.runningCPU = false;
121
+ }
122
+ }
63
123
  const execution = this.prepare(supplied, options);
64
124
  let encoder: CommandEncoder | undefined;
65
125
  try {
@@ -83,12 +143,19 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
83
143
  ): PreparedGPUGraphExecution<Outputs> {
84
144
  // A destroyed compiled program cannot encode further work.
85
145
  assert(!this.destroyed);
146
+ if (
147
+ this.program.operations.some(operation => operation instanceof GPUCPUOperation) ||
148
+ Object.values(this.outputLocations).includes('cpu')
149
+ )
150
+ throw new Error('CPU operations require asynchronous run(), not prepare()');
86
151
  const resolvedBindings = this.program.resolveBindings(supplied, options);
87
152
  const bindings = resolvedBindings.bindings;
88
153
  options = resolvedBindings.options;
89
154
  const invocation = this.program.prepare(this.device, bindings, options, true);
90
155
  let executable: CompiledGPUCommandGraph | undefined;
91
156
  try {
157
+ for (const kernel of this.shaderPasses.values())
158
+ kernel.validateTextures(invocation.textures!.values);
92
159
  const resolved = new GPUGraph();
93
160
  for (const scalar of this.program.scalars) resolved.scalar(scalar.id, scalar.format);
94
161
  const vectors: Record<string, GPUVector> = Object.create(null);
@@ -179,6 +246,11 @@ export class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, G
179
246
  }
180
247
 
181
248
  destroy(): void {
249
+ // CPU callbacks may still be awaiting input readback or producing output arrays.
250
+ assert(!this.runningCPU);
251
+ this.cpuExecution?.destroy();
252
+ for (const kernel of this.shaderPasses.values()) kernel.destroy();
253
+ this.shaderPasses.clear();
182
254
  for (const kernel of this.kernels.values()) kernel.destroy();
183
255
  this.kernels.clear();
184
256
  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';
@@ -741,6 +738,16 @@ export class GPUCommandGraph<Parameters = void> {
741
738
  return this.addBuffer(new GraphBufferHandle(this, descriptor, true));
742
739
  }
743
740
 
741
+ /** Choose a compiler-owned resource name without treating diagnostic labels as unique. @internal */
742
+ getUniqueResourceId(label: string): string {
743
+ let id = label;
744
+ let suffix = 1;
745
+ while (this.buffers.has(id) || this.textures.has(id) || this.externalTextures.has(id)) {
746
+ id = `${label}-${suffix++}`;
747
+ }
748
+ return id;
749
+ }
750
+
744
751
  /**
745
752
  * Creates one typed range over a graph buffer.
746
753
  *
@@ -1025,6 +1032,10 @@ export class GPUCommandGraph<Parameters = void> {
1025
1032
  }
1026
1033
 
1027
1034
  private addNode(node: GPUCommandGraphNode<Parameters>): void {
1035
+ // SimpleGraph only exposes render passes on WebGL. Compute requires WebGPU.
1036
+ if (this.device.type !== 'webgpu' && node.type !== 'render') {
1037
+ throw new Error('WebGL graphs support render passes only');
1038
+ }
1028
1039
  this.assertMutable();
1029
1040
  if (!node.id) {
1030
1041
  throw new Error('GPUCommandGraph node id is required');
@@ -1115,6 +1126,15 @@ export class GPUCommandGraph<Parameters = void> {
1115
1126
  this.assertTexture(texture);
1116
1127
  validateTextureUseAgainstDescriptor(texture, resource.usage);
1117
1128
  validateTextureViewForUsage(resource.texture, resource.usage);
1129
+ // WebGL sampler bindings use the underlying texture, not a selected view range.
1130
+ if (
1131
+ this.device.type === 'webgl' &&
1132
+ resource.usage === 'sampled' &&
1133
+ resource.texture instanceof GraphTextureView &&
1134
+ !isDefaultGraphTextureView(resource.texture)
1135
+ ) {
1136
+ throw new Error('WebGL sampled textures require a full-resource view');
1137
+ }
1118
1138
  } else {
1119
1139
  this.assertExternalTexture(resource.externalTexture);
1120
1140
  if (resource.usage !== 'sampled') {
@@ -2524,3 +2544,13 @@ function isDefaultGraphTextureView(view: GraphTextureView): boolean {
2524
2544
  view.arrayLayerCount === (texture.dimension === '3d' ? 1 : texture.depth)
2525
2545
  );
2526
2546
  }
2547
+
2548
+ /** WebGPU command graph. SimpleGraph reuses its resource planner for portable render passes. */
2549
+ export class GPUCommandGraph<Parameters = void> extends GPUCommandGraphBuilder<Parameters> {
2550
+ constructor(device: Device, props: {id?: string; autotuner?: GPUCommandGraphAutotuner} = {}) {
2551
+ if (device.type !== 'webgpu') {
2552
+ throw new Error('GPUCommandGraph requires a WebGPU device');
2553
+ }
2554
+ super(device, props);
2555
+ }
2556
+ }
@@ -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';