@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
@@ -26,6 +26,8 @@ import {type GPUEvaluationScope} from './operation/gpu-evaluation-scope';
26
26
  import type {GPUVector, GPUVectorFormat} from '@luma.gl/graph/gpu-data';
27
27
 
28
28
  import {
29
+ GPURenderOperation,
30
+ type GPUCommandGraphEncodeOptions,
29
31
  GPUCompositeOperation,
30
32
  GPUGraphScalarLiteral,
31
33
  GPUGraphScalarOperation,
@@ -48,6 +50,7 @@ import {
48
50
  } from './gpu-simple-graph-transfer';
49
51
  import {GPUSimpleGraphValue, GPUSimpleGraphValueOperation} from './gpu-simple-graph-value';
50
52
  import {SimpleGraphLowering, type SimpleOperation} from './gpu-simple-graph-lowering';
53
+ import {GPUCommandGraphBuilder, type CompiledGPUCommandGraph} from '../gpu-core/gpu-command-graph';
51
54
 
52
55
  /** Inspection record for one evaluator in dependency order. */
53
56
  export type GPUSimpleGraphNode = {
@@ -72,7 +75,10 @@ export type GPUSimpleGraphCompileOptions = {
72
75
  };
73
76
 
74
77
  /** Run options; scopes defer submission until the caller submits or cancels. */
75
- export type GPUSimpleGraphRunOptions = {scope?: GPUEvaluationScope};
78
+ export type GPUSimpleGraphRunOptions<Parameters = void> = {
79
+ scope?: GPUEvaluationScope;
80
+ } & Pick<GPUCommandGraphEncodeOptions<Parameters>, 'buffers' | 'textures'> &
81
+ ([Parameters] extends [void] ? {parameters?: Parameters} : {parameters: Parameters});
76
82
 
77
83
  /**
78
84
  * Prototype graph-shaped interface to the existing lazy GPGPU evaluator.
@@ -80,7 +86,7 @@ export type GPUSimpleGraphRunOptions = {scope?: GPUEvaluationScope};
80
86
  * Operations, backend selection, fusion, caching, and storage ownership remain with
81
87
  * the evaluators. Explicit evaluator inputs are borrowed; semantic lowering owns its adapters.
82
88
  */
83
- export class GPUSimpleGraph {
89
+ export class GPUSimpleGraph<Parameters = void> {
84
90
  private readonly declarations = new GPUGraph();
85
91
  readonly device?: Device;
86
92
  readonly id: string;
@@ -88,12 +94,14 @@ export class GPUSimpleGraph {
88
94
  private readonly evaluatorIds = new Set<string>();
89
95
  private readonly programOperations: GPUGraphOperation[] = [];
90
96
  private compiled = false;
97
+ private readonly renderOperations: GPURenderOperation<Parameters>[] = [];
91
98
 
92
99
  /** Execution capabilities; evaluators retain control of backend submission. */
93
100
  readonly capabilities: Readonly<{
94
101
  callerControlledSubmission: boolean;
95
- dynamicBindings: boolean;
96
- transientAllocation: false;
102
+ dynamicBindings: true;
103
+ /** Evaluator render mode uses graph-managed transient resources. */
104
+ transientAllocation: boolean;
97
105
  }>;
98
106
 
99
107
  constructor(deviceOrProps?: Device | {id?: string}, props: {id?: string} = {}) {
@@ -102,8 +110,8 @@ export class GPUSimpleGraph {
102
110
  this.id = (device ? props.id : deviceOrProps?.id) ?? 'simple-graph';
103
111
  this.capabilities = Object.freeze({
104
112
  callerControlledSubmission: device?.type === 'webgpu',
105
- dynamicBindings: !device,
106
- transientAllocation: false
113
+ dynamicBindings: true,
114
+ transientAllocation: Boolean(device)
107
115
  });
108
116
  }
109
117
 
@@ -156,14 +164,24 @@ export class GPUSimpleGraph {
156
164
  }
157
165
 
158
166
  /** Accepts evaluator operations, semantic composites, and recursively nested arrays. */
159
- add(operation: GPUOperationLike): this {
167
+ add<Operation extends GPUOperationLike>(
168
+ operation: Operation &
169
+ (true extends HasIncompatibleRenderParameters<NoInfer<Operation>, Parameters>
170
+ ? never
171
+ : unknown)
172
+ ): this {
173
+ return this.addOperations(operation);
174
+ }
175
+
176
+ private addOperations(operation: GPUOperationLike): this {
160
177
  // Compilation freezes the builder, as it does for GPUCommandGraph.
161
178
  assert(!this.compiled);
162
179
  if (!this.device || operation instanceof GPUExpressionOperation) {
163
180
  this.declarations.add(operation);
164
181
  return this;
165
182
  }
166
- const pending: SimpleOperation[] = [];
183
+ const pending: (SimpleOperation | GPURenderOperation<Parameters>)[] = [];
184
+ let hasRenderOperation = this.renderOperations.length > 0;
167
185
  const pendingEvaluatorIds = new Set<string>();
168
186
  const operations: GPUGraphOperation[] = [];
169
187
  const visit = (value: GPUOperationLike): void => {
@@ -173,7 +191,12 @@ export class GPUSimpleGraph {
173
191
  // Control-flow composites cannot be executed as unconditional groups.
174
192
  assert(value.type === 'composite');
175
193
  for (const child of value.operations) visit(child);
194
+ } else if (value instanceof GPURenderOperation) {
195
+ hasRenderOperation = true;
196
+ pending.push(value);
176
197
  } else {
198
+ // Evaluator work precedes render work; never silently reorder the authored graph.
199
+ assert(!hasRenderOperation);
177
200
  // Only the initial portable semantic subset and explicit evaluator adapters are supported.
178
201
  assert(
179
202
  value instanceof GPUSimpleGraphValueOperation ||
@@ -210,7 +233,10 @@ export class GPUSimpleGraph {
210
233
  };
211
234
  visit(operation);
212
235
  collect(operation);
213
- this.leafOperations.push(...pending);
236
+ for (const value of pending) {
237
+ if (value instanceof GPURenderOperation) this.renderOperations.push(value);
238
+ else this.leafOperations.push(value);
239
+ }
214
240
  for (const identifier of pendingEvaluatorIds) this.evaluatorIds.add(identifier);
215
241
  this.programOperations.push(...operations);
216
242
  return this;
@@ -221,7 +247,7 @@ export class GPUSimpleGraph {
221
247
  identifier: string,
222
248
  value: Value
223
249
  ): Value {
224
- this.add(new GPUSimpleGraphValueOperation({id: identifier, value}));
250
+ this.addOperations(new GPUSimpleGraphValueOperation({id: identifier, value}));
225
251
  return value;
226
252
  }
227
253
 
@@ -230,10 +256,15 @@ export class GPUSimpleGraph {
230
256
  identifier: string,
231
257
  evaluator: Evaluator
232
258
  ): Evaluator {
233
- this.add(new GPUSimpleGraphOperation({id: identifier, evaluator}));
259
+ this.addOperations(new GPUSimpleGraphOperation({id: identifier, evaluator}));
234
260
  return evaluator;
235
261
  }
236
262
 
263
+ /** Appends shared render passes after the evaluator phase. Use the same operation in GPUGraph. */
264
+ addRenderOperation(operation: GPURenderOperation<Parameters>): this {
265
+ return this.addOperations(operation);
266
+ }
267
+
237
268
  get operationTree(): readonly GPUOperationTree[] {
238
269
  return Object.freeze(
239
270
  [...this.programOperations, ...this.declarations.operations].map(getGPUOperationTree)
@@ -245,13 +276,16 @@ export class GPUSimpleGraph {
245
276
  device: Device,
246
277
  options?: GPUGraphCompileOptions
247
278
  ): CompiledGPUSimpleExpressionGraph<Outputs>;
248
- compile(options?: GPUSimpleGraphCompileOptions): CompiledGPUSimpleGraph;
279
+ compile(options?: GPUSimpleGraphCompileOptions): CompiledGPUSimpleGraph<Parameters>;
249
280
  compile(
250
281
  deviceOrOptions: Device | GPUSimpleGraphCompileOptions = {},
251
282
  expressionOptions: GPUGraphCompileOptions = {}
252
- ): CompiledGPUSimpleGraph | CompiledGPUSimpleExpressionGraph<GPUGraphOutputs> {
283
+ ): CompiledGPUSimpleGraph<Parameters> | CompiledGPUSimpleExpressionGraph<GPUGraphOutputs> {
253
284
  if ('type' in deviceOrOptions) {
254
- assert(!this.compiled && this.leafOperations.length === 0);
285
+ // Reusable expression compilation cannot silently discard evaluator/render recipes.
286
+ assert(
287
+ !this.compiled && this.leafOperations.length === 0 && this.renderOperations.length === 0
288
+ );
255
289
  this.compiled = true;
256
290
  return new CompiledGPUSimpleExpressionGraph(
257
291
  deviceOrOptions,
@@ -259,7 +293,7 @@ export class GPUSimpleGraph {
259
293
  expressionOptions
260
294
  );
261
295
  }
262
- // Legacy evaluator graphs bind their device in the constructor.
296
+ // Evaluator recipes bind their device in the constructor.
263
297
  assert(this.device && this.declarations.operations.length === 0);
264
298
  if (
265
299
  [
@@ -274,6 +308,7 @@ export class GPUSimpleGraph {
274
308
  assert(!this.compiled);
275
309
  this.compiled = true;
276
310
  const lowering = new SimpleGraphLowering(options.bindings ?? {});
311
+ let renderGraph: CompiledGPUCommandGraph<Parameters> | undefined;
277
312
  try {
278
313
  for (const operation of this.leafOperations) lowering.lower(operation);
279
314
  const evaluators = lowering.outputs;
@@ -354,15 +389,25 @@ export class GPUSimpleGraph {
354
389
  });
355
390
  }
356
391
  }
392
+ if (this.renderOperations.length) {
393
+ const renderBuilder = new GPUCommandGraphBuilder<Parameters>(this.device, {
394
+ id: `${this.id}-render`
395
+ });
396
+ for (const operation of this.renderOperations) renderBuilder.add(operation);
397
+ renderGraph = renderBuilder.compile();
398
+ }
357
399
  return new CompiledGPUSimpleGraph(
358
400
  this.device,
359
401
  nodes,
360
402
  roots,
361
403
  this.operationTree,
362
404
  lowering.owned,
363
- Object.fromEntries(roots.map(({id, evaluator}) => [id, getIdentifier(evaluator)]))
405
+ Object.fromEntries(roots.map(({id, evaluator}) => [id, getIdentifier(evaluator)])),
406
+ renderGraph,
407
+ lowering.inputs
364
408
  );
365
409
  } catch (error) {
410
+ renderGraph?.destroy();
366
411
  lowering.destroy();
367
412
  throw error;
368
413
  }
@@ -370,7 +415,7 @@ export class GPUSimpleGraph {
370
415
  }
371
416
 
372
417
  /** Snapshot of named evaluator outputs and their reachable dependency plan. */
373
- export class CompiledGPUSimpleGraph {
418
+ export class CompiledGPUSimpleGraph<Parameters = void> {
374
419
  readonly nodes: readonly GPUSimpleGraphNode[];
375
420
  readonly outputs: Readonly<Record<string, GPUSimpleGraphEvaluator>>;
376
421
  /** Maps every selected output ID, including aliases, to its dependency inspection node. */
@@ -388,7 +433,10 @@ export class CompiledGPUSimpleGraph {
388
433
  roots: readonly GPUSimpleGraphOperation[],
389
434
  operationTree: readonly GPUOperationTree[],
390
435
  private readonly ownedEvaluators: ReadonlySet<GPUSimpleGraphEvaluator> = new Set(),
391
- outputNodes: Readonly<Record<string, string>> = {}
436
+ outputNodes: Readonly<Record<string, string>> = {},
437
+ /** Shared render executor, including buffer/texture inspection and ownership. */
438
+ readonly renderGraph?: CompiledGPUCommandGraph<Parameters>,
439
+ private readonly inputs: ReadonlyMap<string, GPUSimpleGraphEvaluator> = new Map()
392
440
  ) {
393
441
  this.device = device;
394
442
  this.nodes = Object.freeze(
@@ -404,17 +452,99 @@ export class CompiledGPUSimpleGraph {
404
452
  );
405
453
  }
406
454
 
455
+ /** Invalidates changed named inputs and their reachable consumers, preserving other channels. */
456
+ invalidate(inputIds: readonly string[]): void {
457
+ assert(!this.running && !this.destroyed && !this.pendingScope);
458
+ const changed = new Set<GPUSimpleGraphEvaluator>();
459
+ for (const identifier of inputIds) {
460
+ const input = this.inputs.get(identifier);
461
+ // Only graph-owned, named leaf inputs can be invalidated through this API.
462
+ assert(input && this.ownedEvaluators.has(input));
463
+ changed.add(input);
464
+ if (input instanceof GPUVectorEvaluator) {
465
+ for (const chunk of input.gpuDataEvaluators) changed.add(chunk);
466
+ }
467
+ }
468
+ const affected = new Map<GPUSimpleGraphEvaluator, boolean>();
469
+ const visit = (evaluator: GPUSimpleGraphEvaluator): boolean => {
470
+ const existing = affected.get(evaluator);
471
+ if (existing !== undefined) return existing;
472
+ // Visit every dependency, even if an earlier dependency is already dirty.
473
+ const dependencies = getDependencies(evaluator).map(visit);
474
+ const dirty = changed.has(evaluator) || dependencies.some(Boolean);
475
+ affected.set(evaluator, dirty);
476
+ return dirty;
477
+ };
478
+ for (const input of changed) visit(input);
479
+ for (const {evaluator} of this.executionPlan) visit(evaluator);
480
+ // Validate the whole change before clearing anything; borrowed evaluator caches stay untouched.
481
+ for (const [evaluator, dirty] of affected) {
482
+ if (dirty) assert(this.ownedEvaluators.has(evaluator));
483
+ }
484
+ for (const [evaluator, dirty] of affected) {
485
+ if (dirty) evaluator.invalidate();
486
+ }
487
+ }
488
+
407
489
  /** Releases semantic evaluator results, preserving borrowed inputs and wrappers. */
408
490
  destroy(): void {
409
491
  // Results must no longer be in use; borrowed evaluators and input buffers remain caller-owned.
410
492
  assert(!this.running && !this.pendingScope);
411
493
  if (this.destroyed) return;
494
+ this.renderGraph?.destroy();
412
495
  for (const evaluator of this.ownedEvaluators) evaluator.destroy();
413
496
  this.destroyed = true;
414
497
  }
415
498
 
499
+ /** Executes supported synchronous evaluators and render passes on WebGL, without readback. */
500
+ runSync(this: CompiledGPUSimpleGraph<void>): Record<string, GPUVector>;
501
+ runSync(options: GPUSimpleGraphRunOptions<Parameters>): Record<string, GPUVector>;
502
+ runSync(options?: GPUSimpleGraphRunOptions<Parameters>): Record<string, GPUVector> {
503
+ assert(this.device.type === 'webgl' && !options?.scope);
504
+ assert(!this.running && !this.destroyed && !this.pendingScope);
505
+ this.running = true;
506
+ try {
507
+ const results: Record<string, GPUVector> = {};
508
+ const evaluated = new Set<GPUSimpleGraphEvaluator>();
509
+ const evaluate = (evaluator: GPUSimpleGraphEvaluator): void => {
510
+ if (evaluated.has(evaluator)) return;
511
+ for (const dependency of getDependencies(evaluator)) evaluate(dependency);
512
+ evaluator.evaluateSync(this.device);
513
+ evaluated.add(evaluator);
514
+ };
515
+ for (const {id, evaluator} of this.executionPlan) {
516
+ evaluate(evaluator);
517
+ results[id] = evaluator.gpuVector;
518
+ }
519
+ this.encodeRenderPasses(options);
520
+ return results;
521
+ } finally {
522
+ this.running = false;
523
+ }
524
+ }
525
+
526
+ private encodeRenderPasses(options?: GPUSimpleGraphRunOptions<Parameters>): void {
527
+ const scope = options?.scope;
528
+ if (!this.renderGraph) return;
529
+ const commandEncoder = scope?.commandEncoder ?? this.device.createCommandEncoder();
530
+ try {
531
+ this.renderGraph.encode(commandEncoder, {
532
+ buffers: options?.buffers,
533
+ textures: options?.textures,
534
+ // The public overload requires parameters unless Parameters is void.
535
+ parameters: options?.parameters as Parameters
536
+ });
537
+ if (!scope) this.device.submit(commandEncoder.finish());
538
+ } finally {
539
+ if (!scope) commandEncoder.destroy();
540
+ }
541
+ }
542
+
416
543
  /** Materializes selected outputs without CPU readback. Semantic results live until destroy(). */
417
- async run({scope}: GPUSimpleGraphRunOptions = {}): Promise<Record<string, GPUVector>> {
544
+ run(this: CompiledGPUSimpleGraph<void>): Promise<Record<string, GPUVector>>;
545
+ run(options: GPUSimpleGraphRunOptions<Parameters>): Promise<Record<string, GPUVector>>;
546
+ async run(options?: GPUSimpleGraphRunOptions<Parameters>): Promise<Record<string, GPUVector>> {
547
+ const scope = options?.scope;
418
548
  // The underlying evaluators do not support concurrent evaluation of shared outputs.
419
549
  assert(!this.running && !this.destroyed && !this.pendingScope);
420
550
  if (scope) {
@@ -444,6 +574,7 @@ export class CompiledGPUSimpleGraph {
444
574
  else await evaluateDependencies(evaluator);
445
575
  results.push([id, evaluator.gpuVector]);
446
576
  }
577
+ this.encodeRenderPasses(options);
447
578
  return Object.fromEntries(results);
448
579
  } catch (error) {
449
580
  scope?.cancel();
@@ -459,3 +590,16 @@ function getDependencies(evaluator: GPUSimpleGraphEvaluator): readonly GPUSimple
459
590
  if (evaluator.source instanceof GPUDataEvaluator) return [evaluator.source];
460
591
  return evaluator.source?.dependencies ?? [];
461
592
  }
593
+
594
+ /** Preserve render parameter requirements without expanding the recursive GPUOperationLike type. */
595
+ type HasIncompatibleRenderParameters<Operation, Parameters> = GPUOperationLike extends Operation
596
+ ? false
597
+ : Operation extends GPURenderOperation<infer RequiredParameters>
598
+ ? [Parameters] extends [RequiredParameters]
599
+ ? false
600
+ : true
601
+ : Operation extends GPUCompositeOperation<infer Child>
602
+ ? HasIncompatibleRenderParameters<Child, Parameters>
603
+ : Operation extends readonly (infer Child)[]
604
+ ? HasIncompatibleRenderParameters<Child, Parameters>
605
+ : false;
@@ -721,6 +721,28 @@ export class GPUDataEvaluator {
721
721
  return this._id ?? this.source?.toString() ?? this.constructor.name;
722
722
  }
723
723
 
724
+ /**
725
+ * Clears cached results after an input changes, without changing its fixed layout.
726
+ * Does not propagate to consumers. Caller-owned input/target buffers remain borrowed.
727
+ * Call only when no evaluation or readback is in flight.
728
+ */
729
+ invalidate(): void {
730
+ this.assertScopeAccess();
731
+ if (this._destroyed) throw new Error('Cannot invalidate a destroyed evaluator');
732
+ if (this.source || this._bufferOwnership === 'borrowed') this._value = undefined;
733
+ // A buffer-backed leaf keeps its source buffer. Only its readback cache is stale.
734
+ if (!this.source && this._bufferOwnership === 'borrowed') return;
735
+ if (this._gpuVector) {
736
+ const buffer = getBufferFromGPUVector(this._gpuVector);
737
+ if (this._bufferOwnership === 'owned') bufferPool.recycle(buffer);
738
+ else if (!(this.source instanceof GPUDataEvaluator)) {
739
+ // Preserve the explicit borrowed destination and its layout on the next evaluation.
740
+ this._targetBuffer = {buffer, byteOffset: this.offset, byteStride: this.stride};
741
+ }
742
+ this._gpuVector = undefined;
743
+ }
744
+ }
745
+
724
746
  /** Releases cached GPU storage owned by this evaluator and prevents future evaluation. */
725
747
  destroy(): void {
726
748
  this.assertScopeAccess();
@@ -243,6 +243,13 @@ export class GPUVectorEvaluator {
243
243
  return this._gpuVector;
244
244
  }
245
245
 
246
+ /** Clears only the collected vector view. Invalidate changed children separately. */
247
+ invalidate(): void {
248
+ this.assertScopeAccess();
249
+ if (this._destroyed) throw new Error('Cannot invalidate a destroyed evaluator');
250
+ this._gpuVector = undefined;
251
+ }
252
+
246
253
  /** Releases cached GPU resources owned through child `GPUDataEvaluator` instances. */
247
254
  destroy(): void {
248
255
  this.assertScopeAccess();
package/src/index.ts CHANGED
@@ -206,3 +206,11 @@ export type {
206
206
  GPUGraphOutput,
207
207
  GPUGraphOutputs
208
208
  } from './gpu-core/gpu-texture-plan';
209
+
210
+ export {GPUCPUOperation} from './gpu-core/gpu-cpu-operation';
211
+ export type {
212
+ GPUCPUOperationProps,
213
+ GPUCPUArray,
214
+ GPUCPUVector,
215
+ GPUCPUResult
216
+ } from './gpu-core/gpu-cpu-operation';