@luma.gl/graph 10.0.0-alpha.11 → 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 (60) hide show
  1. package/dist/dist.dev.js +658 -292
  2. package/dist/dist.min.js +110 -92
  3. package/dist/experimental/index.cjs.map +1 -1
  4. package/dist/experimental/simulation/index.cjs.map +1 -1
  5. package/dist/gpu-core/compiled-gpu-graph.cjs +15 -0
  6. package/dist/gpu-core/compiled-gpu-graph.d.ts +1 -0
  7. package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
  8. package/dist/gpu-core/compiled-gpu-graph.js +15 -0
  9. package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
  10. package/dist/gpu-core/gpu-command-graph.cjs +9 -0
  11. package/dist/gpu-core/gpu-command-graph.d.ts +2 -0
  12. package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
  13. package/dist/gpu-core/gpu-command-graph.js +9 -0
  14. package/dist/gpu-core/gpu-command-graph.js.map +1 -1
  15. package/dist/gpu-core/gpu-expression-plan.cjs +4 -0
  16. package/dist/gpu-core/gpu-expression-plan.d.ts.map +1 -1
  17. package/dist/gpu-core/gpu-expression-plan.js +5 -0
  18. package/dist/gpu-core/gpu-expression-plan.js.map +1 -1
  19. package/dist/gpu-core/gpu-shader-pass-kernel.cjs +267 -0
  20. package/dist/gpu-core/gpu-shader-pass-kernel.d.ts +29 -0
  21. package/dist/gpu-core/gpu-shader-pass-kernel.d.ts.map +1 -0
  22. package/dist/gpu-core/gpu-shader-pass-kernel.js +260 -0
  23. package/dist/gpu-core/gpu-shader-pass-kernel.js.map +1 -0
  24. package/dist/gpu-core/gpu-shader-pass-operation.cjs +85 -0
  25. package/dist/gpu-core/gpu-shader-pass-operation.d.ts +32 -0
  26. package/dist/gpu-core/gpu-shader-pass-operation.d.ts.map +1 -0
  27. package/dist/gpu-core/gpu-shader-pass-operation.js +74 -0
  28. package/dist/gpu-core/gpu-shader-pass-operation.js.map +1 -0
  29. package/dist/gpu-core/index.cjs +3 -0
  30. package/dist/gpu-core/index.cjs.map +3 -3
  31. package/dist/gpu-core/index.d.ts +2 -0
  32. package/dist/gpu-core/index.d.ts.map +1 -1
  33. package/dist/gpu-core/index.js +1 -0
  34. package/dist/gpu-core/index.js.map +1 -1
  35. package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
  36. package/dist/gpu-graph/index.cjs.map +3 -3
  37. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
  38. package/dist/gpu-physics/index.cjs.map +1 -1
  39. package/dist/gpu-project/graph.cjs.map +3 -3
  40. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +53 -5
  41. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +3 -1
  42. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts.map +1 -1
  43. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js +58 -5
  44. package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
  45. package/dist/gpu-simple-graph/index.cjs.map +3 -3
  46. package/dist/index.cjs +3 -0
  47. package/dist/index.cjs.map +3 -3
  48. package/dist/index.d.ts +2 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -0
  51. package/dist/index.js.map +1 -1
  52. package/package.json +7 -7
  53. package/src/gpu-core/compiled-gpu-graph.ts +18 -0
  54. package/src/gpu-core/gpu-command-graph.ts +10 -0
  55. package/src/gpu-core/gpu-expression-plan.ts +6 -0
  56. package/src/gpu-core/gpu-shader-pass-kernel.ts +307 -0
  57. package/src/gpu-core/gpu-shader-pass-operation.ts +103 -0
  58. package/src/gpu-core/index.ts +2 -0
  59. package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +59 -5
  60. package/src/index.ts +2 -0
@@ -38,6 +38,8 @@ import type {GPUGraphOutputs} from '../gpu-core/gpu-texture-plan';
38
38
 
39
39
  import {GPUExpressionCastOperation} from './gpu-expression-cast-operation';
40
40
  import {GPUExpressionRowOperation} from './gpu-expression-row-operation';
41
+ import {GPUShaderPassOperation} from '../gpu-core/gpu-shader-pass-operation';
42
+ import {GPUShaderPassKernel} from '../gpu-core/gpu-shader-pass-kernel';
41
43
 
42
44
  import {GPUCPUOperation} from '../gpu-core/gpu-cpu-operation';
43
45
  import {GPUCPUExecution} from '../gpu-core/gpu-cpu-execution';
@@ -47,6 +49,7 @@ export class CompiledGPUSimpleExpressionGraph<
47
49
  Outputs extends GPUGraphOutputs = Record<string, GPUVector>
48
50
  > {
49
51
  private readonly program: GPUExpressionProgram;
52
+ private readonly shaderPasses = new Map<GPUShaderPassOperation, GPUShaderPassKernel>();
50
53
  private cpuExecution?: GPUCPUExecution;
51
54
  private readonly outputLocations: Readonly<Record<string, 'cpu' | 'gpu'>>;
52
55
  private running = false;
@@ -71,12 +74,13 @@ export class CompiledGPUSimpleExpressionGraph<
71
74
  operation instanceof GPUCPUOperation ||
72
75
  operation instanceof GPUExpressionOperation ||
73
76
  operation instanceof GPUUploadOperation ||
77
+ operation instanceof GPUShaderPassOperation ||
74
78
  operation instanceof GPUCopyOperation
75
79
  )
76
80
  )
77
81
  )
78
82
  throw new Error(
79
- 'SimpleGraph declarative execution supports expression, CPU, upload and copy operations only'
83
+ 'SimpleGraph declarative execution supports expression, CPU, upload, copy and shader-pass operations only'
80
84
  );
81
85
  if (
82
86
  this.program.operations.some(operation => operation instanceof GPUCPUOperation) ||
@@ -87,9 +91,20 @@ export class CompiledGPUSimpleExpressionGraph<
87
91
  this.program,
88
92
  (source, outputs) => new CompiledGPUSimpleExpressionGraph(device, source, {outputs})
89
93
  );
94
+ try {
95
+ for (const operation of this.program.operations)
96
+ if (operation instanceof GPUShaderPassOperation)
97
+ this.shaderPasses.set(
98
+ operation,
99
+ new GPUShaderPassKernel(device, operation, this.program)
100
+ );
101
+ } catch (error) {
102
+ this.destroy();
103
+ throw error;
104
+ }
90
105
  }
91
106
 
92
- /** Prepare a straight-line texture-copy program without submitting work. */
107
+ /** Prepare straight-line texture copies and shader passes without submitting work. */
93
108
  prepare(
94
109
  supplied: GPUGraphRunBindings | GPUGraphExecutionBindings,
95
110
  options: GPUGraphRunOptions = {}
@@ -99,13 +114,23 @@ export class CompiledGPUSimpleExpressionGraph<
99
114
  !this.program.textures.length ||
100
115
  this.program.operations.some(
101
116
  operation =>
102
- !(operation instanceof GPUCopyOperation) ||
103
- !this.program.textures.some(texture => texture.id === operation.input)
117
+ !(operation instanceof GPUShaderPassOperation) &&
118
+ (!(operation instanceof GPUCopyOperation) ||
119
+ !this.program.textures.some(texture => texture.id === operation.input))
104
120
  )
105
121
  )
106
- throw new Error('SimpleGraph prepare currently supports texture-copy programs only');
122
+ throw new Error(
123
+ 'SimpleGraph prepare currently supports texture-copy and shader-pass programs only'
124
+ );
107
125
  const resolved = this.program.resolveBindings(supplied, options);
108
126
  const invocation = this.program.prepare(this.device, resolved.bindings, resolved.options);
127
+ let shaderPasses;
128
+ try {
129
+ shaderPasses = this.prepareShaderPasses(invocation);
130
+ } catch (error) {
131
+ invocation.destroy();
132
+ throw error;
133
+ }
109
134
  let encoded = false;
110
135
  let destroyed = false;
111
136
  return {
@@ -114,6 +139,10 @@ export class CompiledGPUSimpleExpressionGraph<
114
139
  assert(!this.destroyed && !destroyed && !encoded && encoder.device === this.device);
115
140
  encoded = true;
116
141
  for (const operation of this.program.operations) {
142
+ if (operation instanceof GPUShaderPassOperation) {
143
+ shaderPasses.get(operation)!.encode(encoder);
144
+ continue;
145
+ }
117
146
  assert(operation instanceof GPUCopyOperation);
118
147
  encodeTextureCopy(
119
148
  encoder,
@@ -125,6 +154,7 @@ export class CompiledGPUSimpleExpressionGraph<
125
154
  destroy: (): void => {
126
155
  if (destroyed) return;
127
156
  destroyed = true;
157
+ for (const pass of shaderPasses.values()) pass.destroy();
128
158
  invocation.finish();
129
159
  }
130
160
  };
@@ -164,14 +194,23 @@ export class CompiledGPUSimpleExpressionGraph<
164
194
  const scalarBuffers = new Set<Buffer>();
165
195
  let scope: GPUEvaluationScope | undefined;
166
196
  let invocation: ReturnType<GPUExpressionProgram['prepare']> | undefined;
197
+ let shaderPasses:
198
+ | ReturnType<CompiledGPUSimpleExpressionGraph['prepareShaderPasses']>
199
+ | undefined;
167
200
  try {
168
201
  invocation = this.program.prepare(this.device, bindings, options);
202
+ shaderPasses = this.prepareShaderPasses(invocation);
169
203
  if (this.device.type === 'webgpu') scope = new GPUEvaluationScope(this.device);
170
204
  const retain = (evaluator: GPUDataEvaluator): GPUDataEvaluator => {
171
205
  evaluators.add(evaluator);
172
206
  return evaluator;
173
207
  };
174
208
  for (const operation of this.program.operations) {
209
+ if (operation instanceof GPUShaderPassOperation) {
210
+ assert(scope);
211
+ shaderPasses.get(operation)!.encode(scope.commandEncoder);
212
+ continue;
213
+ }
175
214
  if (operation instanceof GPUUploadOperation || operation instanceof GPUCopyOperation) {
176
215
  if (
177
216
  operation instanceof GPUCopyOperation &&
@@ -400,6 +439,7 @@ export class CompiledGPUSimpleExpressionGraph<
400
439
  invocation?.destroy();
401
440
  throw error;
402
441
  } finally {
442
+ for (const pass of shaderPasses?.values() ?? []) pass.destroy();
403
443
  for (const evaluator of evaluators) evaluator.destroy();
404
444
  for (const buffer of scalarBuffers) buffer.destroy();
405
445
  this.running = false;
@@ -410,8 +450,22 @@ export class CompiledGPUSimpleExpressionGraph<
410
450
  // A running program owns evaluator resources until execution finishes.
411
451
  assert(!this.running);
412
452
  this.cpuExecution?.destroy();
453
+ for (const kernel of this.shaderPasses.values()) kernel.destroy();
454
+ this.shaderPasses.clear();
413
455
  this.destroyed = true;
414
456
  }
457
+
458
+ private prepareShaderPasses(invocation: ReturnType<GPUExpressionProgram['prepare']>) {
459
+ const passes = new Map<GPUShaderPassOperation, ReturnType<GPUShaderPassKernel['prepare']>>();
460
+ try {
461
+ for (const [operation, kernel] of this.shaderPasses)
462
+ passes.set(operation, kernel.prepare(invocation.textures!.values, invocation.values));
463
+ return passes;
464
+ } catch (error) {
465
+ for (const pass of passes.values()) pass.destroy();
466
+ throw error;
467
+ }
468
+ }
415
469
  }
416
470
 
417
471
  /** Keep graph scalar arithmetic on the GPU with the same float32 boundaries as vectors. */
package/src/index.ts CHANGED
@@ -193,6 +193,8 @@ export type {
193
193
  } from './gpu-core/gpu-operation-contract';
194
194
 
195
195
  export {GPUUploadOperation, GPUCopyOperation} from './gpu-core/gpu-transfer-operation';
196
+ export {GPUShaderPassOperation} from './gpu-core/gpu-shader-pass-operation';
197
+ export type {GPUShaderPassOperationProps} from './gpu-core/gpu-shader-pass-operation';
196
198
  export type {
197
199
  GPUUploadOperationProps,
198
200
  GPUCopyOperationProps