@luma.gl/graph 10.0.0-alpha.7 → 10.0.0-alpha.8

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 (177) hide show
  1. package/dist/dist.dev.js +5096 -7269
  2. package/dist/dist.min.js +270 -83
  3. package/dist/experimental/index.cjs.map +2 -2
  4. package/dist/experimental/simulation/index.cjs.map +2 -2
  5. package/dist/gpu-core/compiled-gpu-graph.cjs +99 -14
  6. package/dist/gpu-core/compiled-gpu-graph.d.ts +26 -4
  7. package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
  8. package/dist/gpu-core/compiled-gpu-graph.js +101 -13
  9. package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
  10. package/dist/gpu-core/gpu-command-graph-compiler.cjs +35 -3
  11. package/dist/gpu-core/gpu-command-graph-compiler.js +40 -4
  12. package/dist/gpu-core/gpu-command-graph-compiler.js.map +1 -1
  13. package/dist/gpu-core/gpu-command-graph-types.d.ts +2 -0
  14. package/dist/gpu-core/gpu-command-graph-types.d.ts.map +1 -1
  15. package/dist/gpu-core/gpu-compaction-operation.cjs +56 -0
  16. package/dist/gpu-core/gpu-compaction-operation.d.ts +20 -0
  17. package/dist/gpu-core/gpu-compaction-operation.d.ts.map +1 -0
  18. package/dist/gpu-core/gpu-compaction-operation.js +36 -0
  19. package/dist/gpu-core/gpu-compaction-operation.js.map +1 -0
  20. package/dist/gpu-core/gpu-compaction.cjs +35 -3
  21. package/dist/gpu-core/gpu-compaction.d.ts.map +1 -1
  22. package/dist/gpu-core/gpu-compaction.js +38 -3
  23. package/dist/gpu-core/gpu-compaction.js.map +1 -1
  24. package/dist/gpu-core/gpu-expression-operation.cjs +18 -2
  25. package/dist/gpu-core/gpu-expression-operation.d.ts +2 -2
  26. package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
  27. package/dist/gpu-core/gpu-expression-operation.js +20 -1
  28. package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
  29. package/dist/gpu-core/gpu-expression-plan.cjs +140 -29
  30. package/dist/gpu-core/gpu-expression-plan.d.ts +26 -5
  31. package/dist/gpu-core/gpu-expression-plan.d.ts.map +1 -1
  32. package/dist/gpu-core/gpu-expression-plan.js +168 -34
  33. package/dist/gpu-core/gpu-expression-plan.js.map +1 -1
  34. package/dist/gpu-core/gpu-graph-compiler.cjs +100 -11
  35. package/dist/gpu-core/gpu-graph-compiler.d.ts +7 -3
  36. package/dist/gpu-core/gpu-graph-compiler.d.ts.map +1 -1
  37. package/dist/gpu-core/gpu-graph-compiler.js +109 -9
  38. package/dist/gpu-core/gpu-graph-compiler.js.map +1 -1
  39. package/dist/gpu-core/gpu-graph-declarations.cjs +120 -0
  40. package/dist/gpu-core/gpu-graph-declarations.d.ts +4 -0
  41. package/dist/gpu-core/gpu-graph-declarations.d.ts.map +1 -0
  42. package/dist/gpu-core/gpu-graph-declarations.js +110 -0
  43. package/dist/gpu-core/gpu-graph-declarations.js.map +1 -0
  44. package/dist/gpu-core/gpu-graph-validation.cjs +33 -2
  45. package/dist/gpu-core/gpu-graph-validation.d.ts.map +1 -1
  46. package/dist/gpu-core/gpu-graph-validation.js +32 -0
  47. package/dist/gpu-core/gpu-graph-validation.js.map +1 -1
  48. package/dist/gpu-core/gpu-graph-value.cjs +38 -3
  49. package/dist/gpu-core/gpu-graph-value.d.ts +50 -4
  50. package/dist/gpu-core/gpu-graph-value.d.ts.map +1 -1
  51. package/dist/gpu-core/gpu-graph-value.js +39 -1
  52. package/dist/gpu-core/gpu-graph-value.js.map +1 -1
  53. package/dist/gpu-core/gpu-graph.cjs +65 -0
  54. package/dist/gpu-core/gpu-graph.d.ts +15 -2
  55. package/dist/gpu-core/gpu-graph.d.ts.map +1 -1
  56. package/dist/gpu-core/gpu-graph.js +70 -0
  57. package/dist/gpu-core/gpu-graph.js.map +1 -1
  58. package/dist/gpu-core/gpu-operation-contract.cjs +5 -0
  59. package/dist/gpu-core/gpu-operation-contract.d.ts +10 -0
  60. package/dist/gpu-core/gpu-operation-contract.d.ts.map +1 -1
  61. package/dist/gpu-core/gpu-operation-contract.js +6 -1
  62. package/dist/gpu-core/gpu-operation-contract.js.map +1 -1
  63. package/dist/gpu-core/gpu-scan.cjs +11 -2
  64. package/dist/gpu-core/gpu-scan.d.ts.map +1 -1
  65. package/dist/gpu-core/gpu-scan.js +11 -2
  66. package/dist/gpu-core/gpu-scan.js.map +1 -1
  67. package/dist/gpu-core/gpu-texture-copy.cjs +53 -0
  68. package/dist/gpu-core/gpu-texture-copy.d.ts +7 -0
  69. package/dist/gpu-core/gpu-texture-copy.d.ts.map +1 -0
  70. package/dist/gpu-core/gpu-texture-copy.js +39 -0
  71. package/dist/gpu-core/gpu-texture-copy.js.map +1 -0
  72. package/dist/gpu-core/gpu-texture-plan.cjs +181 -0
  73. package/dist/gpu-core/gpu-texture-plan.d.ts +32 -0
  74. package/dist/gpu-core/gpu-texture-plan.d.ts.map +1 -0
  75. package/dist/gpu-core/gpu-texture-plan.js +215 -0
  76. package/dist/gpu-core/gpu-texture-plan.js.map +1 -0
  77. package/dist/gpu-core/gpu-transfer-lowering.cjs +109 -0
  78. package/dist/gpu-core/gpu-transfer-lowering.d.ts +9 -0
  79. package/dist/gpu-core/gpu-transfer-lowering.d.ts.map +1 -0
  80. package/dist/gpu-core/gpu-transfer-lowering.js +88 -0
  81. package/dist/gpu-core/gpu-transfer-lowering.js.map +1 -0
  82. package/dist/gpu-core/gpu-transfer-operation.cjs +100 -0
  83. package/dist/gpu-core/gpu-transfer-operation.d.ts +38 -0
  84. package/dist/gpu-core/gpu-transfer-operation.d.ts.map +1 -0
  85. package/dist/gpu-core/gpu-transfer-operation.js +84 -0
  86. package/dist/gpu-core/gpu-transfer-operation.js.map +1 -0
  87. package/dist/gpu-core/index.cjs +13 -0
  88. package/dist/gpu-core/index.cjs.map +3 -3
  89. package/dist/gpu-core/index.d.ts +11 -1
  90. package/dist/gpu-core/index.d.ts.map +1 -1
  91. package/dist/gpu-core/index.js +4 -1
  92. package/dist/gpu-core/index.js.map +1 -1
  93. package/dist/gpu-dggs/benchmarks.cjs.map +2 -2
  94. package/dist/gpu-graph/index.cjs +8 -0
  95. package/dist/gpu-graph/index.cjs.map +3 -3
  96. package/dist/gpu-graph/index.d.ts +5 -0
  97. package/dist/gpu-graph/index.d.ts.map +1 -1
  98. package/dist/gpu-graph/index.js +2 -0
  99. package/dist/gpu-graph/index.js.map +1 -1
  100. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +3 -3
  101. package/dist/gpu-graph-algorithms/index.cjs.map +2 -2
  102. package/dist/gpu-physics/gpu-rigid-body-world.cjs +56 -17
  103. package/dist/gpu-physics/gpu-rigid-body-world.d.ts +1 -1
  104. package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
  105. package/dist/gpu-physics/gpu-rigid-body-world.js +42 -2
  106. package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
  107. package/dist/gpu-physics/index.cjs.map +2 -2
  108. package/dist/gpu-physics/rigid-body-joints.cjs +6 -1
  109. package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
  110. package/dist/gpu-physics/rigid-body-joints.js +9 -1
  111. package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
  112. package/dist/gpu-physics/rigid-body-parallel-shaders.cjs +4 -2
  113. package/dist/gpu-physics/rigid-body-parallel-shaders.d.ts.map +1 -1
  114. package/dist/gpu-physics/rigid-body-parallel-shaders.js +4 -2
  115. package/dist/gpu-physics/rigid-body-parallel-shaders.js.map +1 -1
  116. package/dist/gpu-physics/rigid-body-shaders.cjs +1 -0
  117. package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
  118. package/dist/gpu-physics/rigid-body-shaders.js +1 -0
  119. package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
  120. package/dist/gpu-pointcloud/index.cjs.map +1 -1
  121. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +54 -7
  122. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +11 -4
  123. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts.map +1 -1
  124. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js +56 -4
  125. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
  126. package/dist/gpu-simple-graph/gpu-simple-graph.cjs +16 -0
  127. package/dist/gpu-simple-graph/gpu-simple-graph.d.ts +11 -4
  128. package/dist/gpu-simple-graph/gpu-simple-graph.d.ts.map +1 -1
  129. package/dist/gpu-simple-graph/gpu-simple-graph.js +18 -0
  130. package/dist/gpu-simple-graph/gpu-simple-graph.js.map +1 -1
  131. package/dist/gpu-simple-graph/gpu-transfer-execution.cjs +82 -0
  132. package/dist/gpu-simple-graph/gpu-transfer-execution.d.ts +7 -0
  133. package/dist/gpu-simple-graph/gpu-transfer-execution.d.ts.map +1 -0
  134. package/dist/gpu-simple-graph/gpu-transfer-execution.js +64 -0
  135. package/dist/gpu-simple-graph/gpu-transfer-execution.js.map +1 -0
  136. package/dist/gpu-simple-graph/index.cjs +3 -0
  137. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  138. package/dist/gpu-simple-graph/index.d.ts +3 -0
  139. package/dist/gpu-simple-graph/index.d.ts.map +1 -1
  140. package/dist/gpu-simple-graph/index.js +1 -0
  141. package/dist/gpu-simple-graph/index.js.map +1 -1
  142. package/dist/index.cjs +13 -0
  143. package/dist/index.cjs.map +3 -3
  144. package/dist/index.d.ts +11 -1
  145. package/dist/index.d.ts.map +1 -1
  146. package/dist/index.js +4 -1
  147. package/dist/index.js.map +1 -1
  148. package/package.json +6 -7
  149. package/src/gpu-core/compiled-gpu-graph.ts +118 -15
  150. package/src/gpu-core/gpu-command-graph-compiler.ts +38 -6
  151. package/src/gpu-core/gpu-command-graph-types.ts +2 -0
  152. package/src/gpu-core/gpu-compaction-operation.ts +49 -0
  153. package/src/gpu-core/gpu-compaction.ts +47 -3
  154. package/src/gpu-core/gpu-expression-operation.ts +23 -2
  155. package/src/gpu-core/gpu-expression-plan.ts +247 -44
  156. package/src/gpu-core/gpu-graph-compiler.ts +130 -11
  157. package/src/gpu-core/gpu-graph-declarations.ts +137 -0
  158. package/src/gpu-core/gpu-graph-validation.ts +32 -0
  159. package/src/gpu-core/gpu-graph-value.ts +88 -4
  160. package/src/gpu-core/gpu-graph.ts +104 -2
  161. package/src/gpu-core/gpu-operation-contract.ts +18 -0
  162. package/src/gpu-core/gpu-scan.ts +15 -2
  163. package/src/gpu-core/gpu-texture-copy.ts +51 -0
  164. package/src/gpu-core/gpu-texture-plan.ts +248 -0
  165. package/src/gpu-core/gpu-transfer-lowering.ts +102 -0
  166. package/src/gpu-core/gpu-transfer-operation.ts +110 -0
  167. package/src/gpu-core/index.ts +22 -1
  168. package/src/gpu-graph/index.ts +15 -0
  169. package/src/gpu-physics/gpu-rigid-body-world.ts +44 -3
  170. package/src/gpu-physics/rigid-body-joints.ts +11 -2
  171. package/src/gpu-physics/rigid-body-parallel-shaders.ts +4 -2
  172. package/src/gpu-physics/rigid-body-shaders.ts +1 -0
  173. package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +90 -8
  174. package/src/gpu-simple-graph/gpu-simple-graph.ts +56 -3
  175. package/src/gpu-simple-graph/gpu-transfer-execution.ts +73 -0
  176. package/src/gpu-simple-graph/index.ts +9 -0
  177. package/src/index.ts +29 -1
@@ -17,11 +17,13 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var compiled_gpu_graph_exports = {};
19
19
  __export(compiled_gpu_graph_exports, {
20
- CompiledGPUGraph: () => CompiledGPUGraph
20
+ CompiledGPUGraph: () => CompiledGPUGraph,
21
+ PreparedGPUGraphExecution: () => PreparedGPUGraphExecution
21
22
  });
22
23
  module.exports = __toCommonJS(compiled_gpu_graph_exports);
23
24
  var import_core = require("@luma.gl/core");
24
25
  var import_gpu_data = require("@luma.gl/graph/gpu-data");
26
+ var import_gpu_texture_plan = require("./gpu-texture-plan.cjs");
25
27
  var import_gpu_graph = require("./gpu-graph.cjs");
26
28
  var import_gpu_graph_compiler = require("./gpu-graph-compiler.cjs");
27
29
  var import_gpu_expression_plan = require("./gpu-expression-plan.cjs");
@@ -36,8 +38,6 @@ class CompiledGPUGraph {
36
38
  this.device = device;
37
39
  if (device.type !== "webgpu")
38
40
  throw new Error("GPUGraph execution requires WebGPU");
39
- if (source.textures.length)
40
- throw new Error("Reusable expression programs do not yet support texture declarations");
41
41
  this.program = new import_gpu_expression_plan.GPUExpressionProgram(source, options);
42
42
  this.compiler = new import_gpu_graph_compiler.GPUGraphCompiler(device, [
43
43
  ...lowerings ?? options.lowerings ?? [],
@@ -54,11 +54,30 @@ class CompiledGPUGraph {
54
54
  throw error;
55
55
  }
56
56
  }
57
- async run(bindings, options = {}) {
57
+ async run(supplied, options = {}) {
58
+ const execution = this.prepare(supplied, options);
59
+ let encoder;
60
+ try {
61
+ encoder = this.device.createCommandEncoder();
62
+ execution.encode(encoder);
63
+ this.device.submit(encoder.finish());
64
+ return execution.outputs;
65
+ } catch (error) {
66
+ execution.discard();
67
+ throw error;
68
+ } finally {
69
+ execution.destroy();
70
+ encoder == null ? void 0 : encoder.destroy();
71
+ }
72
+ }
73
+ /** Bind one invocation without encoding or submitting commands. */
74
+ prepare(supplied, options = {}) {
58
75
  (0, import_core.assert)(!this.destroyed);
59
- const invocation = this.program.prepare(this.device, bindings, options);
76
+ const resolvedBindings = this.program.resolveBindings(supplied, options);
77
+ const bindings = resolvedBindings.bindings;
78
+ options = resolvedBindings.options;
79
+ const invocation = this.program.prepare(this.device, bindings, options, true);
60
80
  let executable;
61
- const encoder = this.device.createCommandEncoder();
62
81
  try {
63
82
  const resolved = new import_gpu_graph.GPUGraph();
64
83
  for (const scalar of this.program.scalars)
@@ -77,6 +96,16 @@ class CompiledGPUGraph {
77
96
  }
78
97
  for (const vector of this.program.vectors) {
79
98
  const binding = vectors[vector.id];
99
+ const transient = invocation.transientVectors.get(vector.id);
100
+ if (transient) {
101
+ resolved.addDeclaration(vector.id, {
102
+ type: "vector",
103
+ format: vector.format,
104
+ length: transient.length,
105
+ chunkLengths: transient.chunkLengths
106
+ }, "value");
107
+ continue;
108
+ }
80
109
  if (!binding && vector.length === void 0)
81
110
  throw new Error(`Missing length or execution binding for ${vector.id}`);
82
111
  resolved.vector(vector.id, vector.format, (binding == null ? void 0 : binding.length) ?? vector.length, {
@@ -84,8 +113,25 @@ class CompiledGPUGraph {
84
113
  chunkLengths: (binding == null ? void 0 : binding.data.map((chunk) => chunk.length)) ?? vector.chunkLengths
85
114
  });
86
115
  }
116
+ const textures = /* @__PURE__ */ Object.create(null);
117
+ for (const texture of this.program.textures) {
118
+ const binding = invocation.textures.values.get(texture.id);
119
+ const info = (0, import_gpu_texture_plan.getTextureBindingInfo)(binding);
120
+ resolved.texture(texture.id, {
121
+ format: info.format,
122
+ dimension: info.dimension,
123
+ width: info.width,
124
+ height: info.height,
125
+ depth: info.depth,
126
+ mipLevels: info.mipLevels,
127
+ samples: info.samples,
128
+ usage: info.texture.props.usage,
129
+ external: true
130
+ });
131
+ textures[texture.id] = binding;
132
+ }
87
133
  resolved.add(this.program.operations);
88
- const compilation = this.compiler.compile(resolved, { vectors, scalars });
134
+ const compilation = this.compiler.compile(resolved, { vectors, scalars, textures });
89
135
  for (const scalar of this.program.scalars) {
90
136
  const target = invocation.values.get(scalar.id);
91
137
  if (!(target instanceof import_gpu_data.GPUVector))
@@ -110,15 +156,13 @@ class CompiledGPUGraph {
110
156
  });
111
157
  }
112
158
  executable = compilation.graph.compile();
113
- executable.encode(encoder, { parameters: void 0 });
114
- this.device.submit(encoder.finish());
115
- return invocation.finish();
159
+ return new PreparedGPUGraphExecution(this.device, invocation, executable, () => {
160
+ (0, import_core.assert)(!this.destroyed);
161
+ });
116
162
  } catch (error) {
163
+ executable == null ? void 0 : executable.destroy();
117
164
  invocation.destroy();
118
165
  throw error;
119
- } finally {
120
- executable == null ? void 0 : executable.destroy();
121
- encoder.destroy();
122
166
  }
123
167
  }
124
168
  destroy() {
@@ -128,7 +172,48 @@ class CompiledGPUGraph {
128
172
  this.destroyed = true;
129
173
  }
130
174
  }
175
+ class PreparedGPUGraphExecution {
176
+ device;
177
+ invocation;
178
+ executable;
179
+ checkProgram;
180
+ outputs;
181
+ encoded = false;
182
+ destroyed = false;
183
+ /** @internal Use CompiledGPUGraph.prepare(). */
184
+ constructor(device, invocation, executable, checkProgram) {
185
+ this.device = device;
186
+ this.invocation = invocation;
187
+ this.executable = executable;
188
+ this.checkProgram = checkProgram;
189
+ this.outputs = invocation.getOutputs();
190
+ }
191
+ /** Append commands once to a caller-owned encoder; never finish or submit it. */
192
+ encode(commandEncoder) {
193
+ (0, import_core.assert)(!this.destroyed && !this.encoded && commandEncoder.device === this.device);
194
+ this.checkProgram();
195
+ this.encoded = true;
196
+ this.executable.encode(commandEncoder, { parameters: void 0 });
197
+ }
198
+ /** Release scratch after submission, or after abandoning an unsubmitted encoder. */
199
+ destroy() {
200
+ if (this.destroyed)
201
+ return;
202
+ this.destroyed = true;
203
+ this.executable.destroy();
204
+ this.invocation.finish();
205
+ }
206
+ /** @internal run() has no caller to receive allocated outputs when it fails. */
207
+ discard() {
208
+ if (this.destroyed)
209
+ return;
210
+ this.destroyed = true;
211
+ this.executable.destroy();
212
+ this.invocation.destroy();
213
+ }
214
+ }
131
215
  // Annotate the CommonJS export names for ESM import in node:
132
216
  0 && (module.exports = {
133
- CompiledGPUGraph
217
+ CompiledGPUGraph,
218
+ PreparedGPUGraphExecution
134
219
  });
@@ -1,17 +1,39 @@
1
- import { type Device } from '@luma.gl/core';
1
+ import { type CommandEncoder, type Device } from '@luma.gl/core';
2
2
  import { GPUVector } from '@luma.gl/graph/gpu-data';
3
+ import { type GPUGraphOutputs } from "./gpu-texture-plan.js";
3
4
  import { GPUGraph } from "./gpu-graph.js";
5
+ import type { CompiledGPUCommandGraph } from "./gpu-command-graph.js";
4
6
  import type { GPUOperationLowering } from "./gpu-graph-lowering.js";
5
- import { type GPUGraphCompileOptions, type GPUGraphRunBindings, type GPUGraphRunOptions } from "./gpu-expression-plan.js";
7
+ import { type GPUExpressionInvocation, type GPUGraphCompileOptions, type GPUGraphRunBindings, type GPUGraphExecutionBindings, type GPUGraphRunOptions } from "./gpu-expression-plan.js";
6
8
  /** Reusable WebGPU program. Returned output vectors belong to the caller. */
7
- export declare class CompiledGPUGraph {
9
+ export declare class CompiledGPUGraph<Outputs extends GPUGraphOutputs = Record<string, GPUVector>> {
8
10
  readonly device: Device;
9
11
  private readonly program;
10
12
  private readonly compiler;
11
13
  private readonly kernels;
12
14
  private destroyed;
13
15
  constructor(device: Device, source: GPUGraph, options?: GPUGraphCompileOptions, lowerings?: readonly GPUOperationLowering[]);
14
- run(bindings: GPUGraphRunBindings, options?: GPUGraphRunOptions): Promise<Record<string, GPUVector>>;
16
+ run(supplied: GPUGraphRunBindings | GPUGraphExecutionBindings, options?: GPUGraphRunOptions): Promise<Outputs>;
17
+ /** Bind one invocation without encoding or submitting commands. */
18
+ prepare(supplied: GPUGraphRunBindings | GPUGraphExecutionBindings, options?: GPUGraphRunOptions): PreparedGPUGraphExecution<Outputs>;
15
19
  destroy(): void;
16
20
  }
21
+ /** One bound invocation. Outputs remain caller-owned after destruction. */
22
+ export declare class PreparedGPUGraphExecution<Outputs extends GPUGraphOutputs = Record<string, GPUVector>> {
23
+ private readonly device;
24
+ private readonly invocation;
25
+ private readonly executable;
26
+ private readonly checkProgram;
27
+ readonly outputs: Outputs;
28
+ private encoded;
29
+ private destroyed;
30
+ /** @internal Use CompiledGPUGraph.prepare(). */
31
+ constructor(device: Device, invocation: GPUExpressionInvocation, executable: CompiledGPUCommandGraph, checkProgram: () => void);
32
+ /** Append commands once to a caller-owned encoder; never finish or submit it. */
33
+ encode(commandEncoder: CommandEncoder): void;
34
+ /** Release scratch after submission, or after abandoning an unsubmitted encoder. */
35
+ destroy(): void;
36
+ /** @internal run() has no caller to receive allocated outputs when it fails. */
37
+ discard(): void;
38
+ }
17
39
  //# sourceMappingURL=compiled-gpu-graph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiled-gpu-graph.d.ts","sourceRoot":"","sources":["../../src/gpu-core/compiled-gpu-graph.ts"],"names":[],"mappings":"AAIA,OAAO,EAAS,KAAK,MAAM,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAC,QAAQ,EAAC,uBAAoB;AAGrC,OAAO,KAAK,EAAC,oBAAoB,EAAC,gCAA6B;AAE/D,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,iCAA8B;AAG/B,6EAA6E;AAC7E,qBAAa,gBAAgB;IAOzB,QAAQ,CAAC,MAAM,EAAE,MAAM;IANzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0D;IAClF,OAAO,CAAC,SAAS,CAAS;gBAGf,MAAM,EAAE,MAAM,EACvB,MAAM,EAAE,QAAQ,EAChB,OAAO,GAAE,sBAA2B,EACpC,SAAS,CAAC,EAAE,SAAS,oBAAoB,EAAE;IAuBvC,GAAG,CACP,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAkErC,OAAO,IAAI,IAAI;CAKhB"}
1
+ {"version":3,"file":"compiled-gpu-graph.d.ts","sourceRoot":"","sources":["../../src/gpu-core/compiled-gpu-graph.ts"],"names":[],"mappings":"AAIA,OAAO,EAAS,KAAK,cAAc,EAAE,KAAK,MAAM,EAAC,MAAM,eAAe,CAAC;AACvE,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAGL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AO,CAAC,QAAQ,CAAC,YAAY;IAT/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAS;IAE1B,gDAAgD;gBAE7B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,uBAAuB,EACnC,UAAU,EAAE,uBAAuB,EACnC,YAAY,EAAE,MAAM,IAAI;IAK3C,iFAAiF;IACjF,MAAM,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI;IAS5C,oFAAoF;IACpF,OAAO,IAAI,IAAI;IAOf,gFAAgF;IAChF,OAAO,IAAI,IAAI;CAMhB"}
@@ -3,6 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
  import { assert } from '@luma.gl/core';
5
5
  import { GPUVector } from '@luma.gl/graph/gpu-data';
6
+ import { getTextureBindingInfo } from "./gpu-texture-plan.js";
6
7
  import { GPUGraph } from "./gpu-graph.js";
7
8
  import { GPUGraphCompiler } from "./gpu-graph-compiler.js";
8
9
  import { GPUExpressionProgram } from "./gpu-expression-plan.js";
@@ -18,8 +19,6 @@ export class CompiledGPUGraph {
18
19
  this.device = device;
19
20
  if (device.type !== 'webgpu')
20
21
  throw new Error('GPUGraph execution requires WebGPU');
21
- if (source.textures.length)
22
- throw new Error('Reusable expression programs do not yet support texture declarations');
23
22
  this.program = new GPUExpressionProgram(source, options);
24
23
  this.compiler = new GPUGraphCompiler(device, [
25
24
  ...(lowerings ?? options.lowerings ?? []),
@@ -37,12 +36,33 @@ export class CompiledGPUGraph {
37
36
  throw error;
38
37
  }
39
38
  }
40
- async run(bindings, options = {}) {
39
+ async run(supplied, options = {}) {
40
+ const execution = this.prepare(supplied, options);
41
+ let encoder;
42
+ try {
43
+ encoder = this.device.createCommandEncoder();
44
+ execution.encode(encoder);
45
+ this.device.submit(encoder.finish());
46
+ return execution.outputs;
47
+ }
48
+ catch (error) {
49
+ execution.discard();
50
+ throw error;
51
+ }
52
+ finally {
53
+ execution.destroy();
54
+ encoder?.destroy();
55
+ }
56
+ }
57
+ /** Bind one invocation without encoding or submitting commands. */
58
+ prepare(supplied, options = {}) {
41
59
  // A destroyed compiled program cannot encode further work.
42
60
  assert(!this.destroyed);
43
- const invocation = this.program.prepare(this.device, bindings, options);
61
+ const resolvedBindings = this.program.resolveBindings(supplied, options);
62
+ const bindings = resolvedBindings.bindings;
63
+ options = resolvedBindings.options;
64
+ const invocation = this.program.prepare(this.device, bindings, options, true);
44
65
  let executable;
45
- const encoder = this.device.createCommandEncoder();
46
66
  try {
47
67
  const resolved = new GPUGraph();
48
68
  for (const scalar of this.program.scalars)
@@ -61,6 +81,16 @@ export class CompiledGPUGraph {
61
81
  }
62
82
  for (const vector of this.program.vectors) {
63
83
  const binding = vectors[vector.id];
84
+ const transient = invocation.transientVectors.get(vector.id);
85
+ if (transient) {
86
+ resolved.addDeclaration(vector.id, {
87
+ type: 'vector',
88
+ format: vector.format,
89
+ length: transient.length,
90
+ chunkLengths: transient.chunkLengths
91
+ }, 'value');
92
+ continue;
93
+ }
64
94
  if (!binding && vector.length === undefined)
65
95
  throw new Error(`Missing length or execution binding for ${vector.id}`);
66
96
  resolved.vector(vector.id, vector.format, binding?.length ?? vector.length, {
@@ -68,8 +98,25 @@ export class CompiledGPUGraph {
68
98
  chunkLengths: binding?.data.map(chunk => chunk.length) ?? vector.chunkLengths
69
99
  });
70
100
  }
101
+ const textures = Object.create(null);
102
+ for (const texture of this.program.textures) {
103
+ const binding = invocation.textures.values.get(texture.id);
104
+ const info = getTextureBindingInfo(binding);
105
+ resolved.texture(texture.id, {
106
+ format: info.format,
107
+ dimension: info.dimension,
108
+ width: info.width,
109
+ height: info.height,
110
+ depth: info.depth,
111
+ mipLevels: info.mipLevels,
112
+ samples: info.samples,
113
+ usage: info.texture.props.usage,
114
+ external: true
115
+ });
116
+ textures[texture.id] = binding;
117
+ }
71
118
  resolved.add(this.program.operations);
72
- const compilation = this.compiler.compile(resolved, { vectors, scalars });
119
+ const compilation = this.compiler.compile(resolved, { vectors, scalars, textures });
73
120
  for (const scalar of this.program.scalars) {
74
121
  const target = invocation.values.get(scalar.id);
75
122
  if (!(target instanceof GPUVector))
@@ -95,18 +142,16 @@ export class CompiledGPUGraph {
95
142
  });
96
143
  }
97
144
  executable = compilation.graph.compile();
98
- executable.encode(encoder, { parameters: undefined });
99
- this.device.submit(encoder.finish());
100
- return invocation.finish();
145
+ return new PreparedGPUGraphExecution(this.device, invocation, executable, () => {
146
+ // Keep the compiled program alive until encoding and submission have completed.
147
+ assert(!this.destroyed);
148
+ });
101
149
  }
102
150
  catch (error) {
151
+ executable?.destroy();
103
152
  invocation.destroy();
104
153
  throw error;
105
154
  }
106
- finally {
107
- executable?.destroy();
108
- encoder.destroy();
109
- }
110
155
  }
111
156
  destroy() {
112
157
  for (const kernel of this.kernels.values())
@@ -115,4 +160,47 @@ export class CompiledGPUGraph {
115
160
  this.destroyed = true;
116
161
  }
117
162
  }
163
+ /** One bound invocation. Outputs remain caller-owned after destruction. */
164
+ export class PreparedGPUGraphExecution {
165
+ device;
166
+ invocation;
167
+ executable;
168
+ checkProgram;
169
+ outputs;
170
+ encoded = false;
171
+ destroyed = false;
172
+ /** @internal Use CompiledGPUGraph.prepare(). */
173
+ constructor(device, invocation, executable, checkProgram) {
174
+ this.device = device;
175
+ this.invocation = invocation;
176
+ this.executable = executable;
177
+ this.checkProgram = checkProgram;
178
+ this.outputs = invocation.getOutputs();
179
+ }
180
+ /** Append commands once to a caller-owned encoder; never finish or submit it. */
181
+ encode(commandEncoder) {
182
+ // An execution is single-use, and its encoder must belong to the same device.
183
+ assert(!this.destroyed && !this.encoded && commandEncoder.device === this.device);
184
+ this.checkProgram();
185
+ // A partial encoding cannot be retried. Discard the caller's encoder on failure.
186
+ this.encoded = true;
187
+ this.executable.encode(commandEncoder, { parameters: undefined });
188
+ }
189
+ /** Release scratch after submission, or after abandoning an unsubmitted encoder. */
190
+ destroy() {
191
+ if (this.destroyed)
192
+ return;
193
+ this.destroyed = true;
194
+ this.executable.destroy();
195
+ this.invocation.finish();
196
+ }
197
+ /** @internal run() has no caller to receive allocated outputs when it fails. */
198
+ discard() {
199
+ if (this.destroyed)
200
+ return;
201
+ this.destroyed = true;
202
+ this.executable.destroy();
203
+ this.invocation.destroy();
204
+ }
205
+ }
118
206
  //# sourceMappingURL=compiled-gpu-graph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiled-gpu-graph.js","sourceRoot":"","sources":["../../src/gpu-core/compiled-gpu-graph.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAAC,MAAM,EAAc,MAAM,eAAe,CAAC;AAClD,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAC,QAAQ,EAAC,uBAAoB;AAErC,OAAO,EAAC,gBAAgB,EAAC,gCAA6B;AAGtD,OAAO,EACL,oBAAoB,EAIrB,iCAA8B;AAC/B,OAAO,EAAC,mBAAmB,EAAC,mCAAgC;AAE5D,6EAA6E;AAC7E,MAAM,OAAO,gBAAgB;IAOhB;IANM,OAAO,CAAuB;IAC9B,QAAQ,CAAmB;IAC3B,OAAO,GAAG,IAAI,GAAG,EAA+C,CAAC;IAC1E,SAAS,GAAG,KAAK,CAAC;IAE1B,YACW,MAAc,EACvB,MAAgB,EAChB,UAAkC,EAAE,EACpC,SAA2C;QAHlC,WAAM,GAAN,MAAM,CAAQ;QAKvB,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACpF,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM;YACxB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC1F,IAAI,CAAC,OAAO,GAAG,IAAI,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACzD,IAAI,CAAC,QAAQ,GAAG,IAAI,g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IAAI,cAAc,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC;QAClF,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,iFAAiF;QACjF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,EAAC,UAAU,EAAE,SAAS,EAAC,CAAC,CAAC;IAClE,CAAC;IAED,oFAAoF;IACpF,OAAO;QACL,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;IAC3B,CAAC;IAED,gFAAgF;IAChF,OAAO;QACL,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;CACF"}
@@ -447,21 +447,53 @@ function intervalsOverlap(leftStart, leftCount, rightStart, rightCount) {
447
447
  }
448
448
  function getBufferTransientAllocationPlan(nodes, buffers) {
449
449
  const lifetimes = getResourceLifetimes(nodes, (resource) => isGraphBufferUse(resource) ? getBufferHandle(resource.buffer) : null);
450
+ const scopes = /* @__PURE__ */ new Map();
451
+ nodes.forEach((node, nodeIndex) => {
452
+ var _a;
453
+ if (!((_a = node.retainedBuffers) == null ? void 0 : _a.length))
454
+ return;
455
+ const scope = scopes.get(node.retainedBuffers);
456
+ if (scope)
457
+ scope.lastUse = nodeIndex;
458
+ else
459
+ scopes.set(node.retainedBuffers, { firstUse: nodeIndex, lastUse: nodeIndex });
460
+ });
461
+ for (const [buffers2, scope] of scopes) {
462
+ for (const buffer of buffers2) {
463
+ if (!buffer.transient)
464
+ continue;
465
+ const lifetime = lifetimes.get(buffer);
466
+ lifetimes.set(buffer, {
467
+ firstUse: Math.min((lifetime == null ? void 0 : lifetime.firstUse) ?? scope.firstUse, scope.firstUse),
468
+ lastUse: Math.max((lifetime == null ? void 0 : lifetime.lastUse) ?? scope.lastUse, scope.lastUse)
469
+ });
470
+ }
471
+ }
450
472
  const allocations = [];
451
473
  const transientBuffers = Array.from(buffers).filter((buffer) => buffer.transient).map((buffer) => ({ buffer, lifetime: lifetimes.get(buffer) })).sort((left, right) => {
452
474
  var _a, _b;
453
475
  return (((_a = left.lifetime) == null ? void 0 : _a.firstUse) ?? Number.MAX_SAFE_INTEGER) - (((_b = right.lifetime) == null ? void 0 : _b.firstUse) ?? Number.MAX_SAFE_INTEGER);
454
476
  });
455
477
  const active = new import_gpu_planning_heap.GPUPlanningHeap((left, right) => left.allocation.lastUse - right.allocation.lastUse || left.index - right.index);
456
- const available = new import_gpu_planning_heap.GPUPlanningHeap((left, right) => left.allocation.byteLength - right.allocation.byteLength || left.index - right.index);
478
+ const available = /* @__PURE__ */ new Map();
479
+ const getAvailable = (usage) => {
480
+ const key = usage & (import_core.Buffer.MAP_READ | import_core.Buffer.MAP_WRITE);
481
+ let pool = available.get(key);
482
+ if (!pool) {
483
+ pool = new import_gpu_planning_heap.GPUPlanningHeap((left, right) => left.allocation.byteLength - right.allocation.byteLength || left.index - right.index);
484
+ available.set(key, pool);
485
+ }
486
+ return pool;
487
+ };
457
488
  for (const { buffer, lifetime } of transientBuffers) {
458
489
  if (!lifetime) {
459
490
  continue;
460
491
  }
461
492
  while (active.peek() && active.peek().allocation.lastUse < lifetime.firstUse) {
462
- available.push(active.pop());
493
+ const completed = active.pop();
494
+ getAvailable(completed.allocation.usage).push(completed);
463
495
  }
464
- let candidate = available.pop();
496
+ let candidate = getAvailable(buffer.usage).pop();
465
497
  if (!candidate) {
466
498
  candidate = {
467
499
  allocation: { byteLength: 0, usage: 0, lastUse: -1, handles: [] },
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
  import { GPUPlanningHeap } from "./gpu-planning-heap.js";
5
- import { PipelineFactory, textureFormatDecoder } from '@luma.gl/core';
5
+ import { Buffer, PipelineFactory, textureFormatDecoder } from '@luma.gl/core';
6
6
  /**
7
7
  * Compiles scheduling, transient allocations, and executable node resources.
8
8
  *
@@ -526,6 +526,31 @@ function intervalsOverlap(leftStart, leftCount, rightStart, rightCount) {
526
526
  */
527
527
  function getBufferTransientAllocationPlan(nodes, buffers) {
528
528
  const lifetimes = getResourceLifetimes(nodes, resource => isGraphBufferUse(resource) ? getBufferHandle(resource.buffer) : null);
529
+ // Each operation shares one retained-buffer list across all its command nodes. Find the
530
+ // scope once, rather than visiting every chunk on every node in a chunked operation.
531
+ const scopes = new Map();
532
+ nodes.forEach((node, nodeIndex) => {
533
+ if (!node.retainedBuffers?.length)
534
+ return;
535
+ const scope = scopes.get(node.retainedBuffers);
536
+ if (scope)
537
+ scope.lastUse = nodeIndex;
538
+ else
539
+ scopes.set(node.retainedBuffers, { firstUse: nodeIndex, lastUse: nodeIndex });
540
+ });
541
+ // Logical operation inputs/results overlap even for multi-pass lowerings. Private command
542
+ // scratch continues to use its precise command-level lifetime.
543
+ for (const [buffers, scope] of scopes) {
544
+ for (const buffer of buffers) {
545
+ if (!buffer.transient)
546
+ continue;
547
+ const lifetime = lifetimes.get(buffer);
548
+ lifetimes.set(buffer, {
549
+ firstUse: Math.min(lifetime?.firstUse ?? scope.firstUse, scope.firstUse),
550
+ lastUse: Math.max(lifetime?.lastUse ?? scope.lastUse, scope.lastUse)
551
+ });
552
+ }
553
+ }
529
554
  const allocations = [];
530
555
  const transientBuffers = Array.from(buffers)
531
556
  .filter(buffer => buffer.transient)
@@ -533,15 +558,26 @@ function getBufferTransientAllocationPlan(nodes, buffers) {
533
558
  .sort((left, right) => (left.lifetime?.firstUse ?? Number.MAX_SAFE_INTEGER) -
534
559
  (right.lifetime?.firstUse ?? Number.MAX_SAFE_INTEGER));
535
560
  const active = new GPUPlanningHeap((left, right) => left.allocation.lastUse - right.allocation.lastUse || left.index - right.index);
536
- const available = new GPUPlanningHeap((left, right) => left.allocation.byteLength - right.allocation.byteLength || left.index - right.index);
561
+ // Mappable staging buffers cannot combine their usages with storage/vertex buffers.
562
+ const available = new Map();
563
+ const getAvailable = (usage) => {
564
+ const key = usage & (Buffer.MAP_READ | Buffer.MAP_WRITE);
565
+ let pool = available.get(key);
566
+ if (!pool) {
567
+ pool = new GPUPlanningHeap((left, right) => left.allocation.byteLength - right.allocation.byteLength || left.index - right.index);
568
+ available.set(key, pool);
569
+ }
570
+ return pool;
571
+ };
537
572
  for (const { buffer, lifetime } of transientBuffers) {
538
573
  if (!lifetime) {
539
574
  continue;
540
575
  }
541
576
  while (active.peek() && active.peek().allocation.lastUse < lifetime.firstUse) {
542
- available.push(active.pop());
577
+ const completed = active.pop();
578
+ getAvailable(completed.allocation.usage).push(completed);
543
579
  }
544
- let candidate = available.pop();
580
+ let candidate = getAvailable(buffer.usage).pop();
545
581
  if (!candidate) {
546
582
  candidate = {
547
583
  allocation: { byteLength: 0, usage: 0, lastUse: -1, handles: [] },