@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
package/dist/dist.dev.js CHANGED
@@ -56,6 +56,7 @@ var __exports__ = (() => {
56
56
  CompiledGPUGraph: () => CompiledGPUGraph,
57
57
  DynamicBuffer: () => DynamicBuffer,
58
58
  DynamicTexture: () => DynamicTexture,
59
+ GPUCPUOperation: () => GPUCPUOperation,
59
60
  GPUCommandGraph: () => GPUCommandGraph,
60
61
  GPUCommandGraphAutotuner: () => GPUCommandGraphAutotuner,
61
62
  GPUCommandGraphEncoding: () => GPUCommandGraphEncoding,
@@ -150,7 +151,7 @@ var __exports__ = (() => {
150
151
  }
151
152
 
152
153
  // src/gpu-core/gpu-command-graph.ts
153
- var import_core7 = __toESM(require_core(), 1);
154
+ var import_core9 = __toESM(require_core(), 1);
154
155
 
155
156
  // ../../node_modules/probe.gl/dist/env/lib/globals.js
156
157
  var window_ = globalThis;
@@ -3934,7 +3935,66 @@ var __exports__ = (() => {
3934
3935
  }
3935
3936
 
3936
3937
  // src/gpu-data/index.ts
3938
+ var import_core7 = __toESM(require_core(), 1);
3939
+
3940
+ // src/gpu-data/cpu-data.ts
3937
3941
  var import_core5 = __toESM(require_core(), 1);
3942
+ var CPUData = class {
3943
+ buffer;
3944
+ format;
3945
+ length;
3946
+ valueLength;
3947
+ /** Absolute offset into buffer. */
3948
+ byteOffset;
3949
+ byteStride;
3950
+ rowByteLength;
3951
+ valueOffsets;
3952
+ nullBitmap;
3953
+ constructor(props) {
3954
+ const info = getGPUVectorFormatInfo(props.format);
3955
+ const view = ArrayBuffer.isView(props.buffer) ? props.buffer : void 0;
3956
+ this.buffer = view ? view.buffer : props.buffer;
3957
+ this.format = props.format;
3958
+ this.length = props.length;
3959
+ this.valueLength = props.valueLength ?? props.length * (info.listSize ?? 1);
3960
+ const offset = props.byteOffset ?? 0;
3961
+ this.byteOffset = (view?.byteOffset ?? 0) + offset;
3962
+ this.rowByteLength = props.rowByteLength ?? info.byteLength;
3963
+ this.byteStride = props.byteStride ?? this.rowByteLength;
3964
+ this.valueOffsets = props.valueOffsets;
3965
+ this.nullBitmap = props.nullBitmap;
3966
+ const variable = info.vertexList || info.valueList;
3967
+ const count = variable ? this.valueLength : this.length;
3968
+ (0, import_core5.assert)(
3969
+ [this.length, this.valueLength, offset, this.rowByteLength, this.byteStride].every(
3970
+ (value) => Number.isSafeInteger(value) && value >= 0
3971
+ )
3972
+ );
3973
+ (0, import_core5.assert)(this.rowByteLength >= info.byteLength && this.byteStride >= this.rowByteLength);
3974
+ (0, import_core5.assert)(variable || this.valueLength === this.length * (info.listSize ?? 1));
3975
+ (0, import_core5.assert)(
3976
+ offset + (count ? (count - 1) * this.byteStride + this.rowByteLength : 0) <= props.buffer.byteLength
3977
+ );
3978
+ }
3979
+ };
3980
+
3981
+ // src/gpu-data/cpu-vector.ts
3982
+ var import_core6 = __toESM(require_core(), 1);
3983
+ var CPUVector = class {
3984
+ name;
3985
+ format;
3986
+ data;
3987
+ length;
3988
+ valueLength;
3989
+ constructor(props) {
3990
+ (0, import_core6.assert)(props.data.every((chunk) => chunk.format === props.format));
3991
+ this.name = props.name ?? "";
3992
+ this.format = props.format;
3993
+ this.data = Object.freeze([...props.data]);
3994
+ this.length = this.data.reduce((total, chunk) => total + chunk.length, 0);
3995
+ this.valueLength = this.data.reduce((total, chunk) => total + chunk.valueLength, 0);
3996
+ }
3997
+ };
3938
3998
 
3939
3999
  // src/gpu-core/gpu-planning-heap.ts
3940
4000
  var GPUPlanningHeap = class {
@@ -3977,7 +4037,7 @@ var __exports__ = (() => {
3977
4037
  };
3978
4038
 
3979
4039
  // src/gpu-core/gpu-command-graph-compiler.ts
3980
- var import_core6 = __toESM(require_core(), 1);
4040
+ var import_core8 = __toESM(require_core(), 1);
3981
4041
  function compileGPUCommandGraph(props) {
3982
4042
  const nodeOrder = getNodeOrder(props.nodes);
3983
4043
  const bufferPlan = getBufferTransientAllocationPlan(nodeOrder, props.buffers.values());
@@ -4056,12 +4116,12 @@ var __exports__ = (() => {
4056
4116
  transientTextures.set(handle, allocation.texture);
4057
4117
  }
4058
4118
  }
4059
- const asyncPipelineCompilation = import_core6.PipelineFactory.beginAsyncCompilation(props.device);
4119
+ const asyncPipelineCompilation = import_core8.PipelineFactory.beginAsyncCompilation(props.device);
4060
4120
  const nodeCompilationPromises = nodeOrder.map(async (node) => ({
4061
4121
  node,
4062
4122
  executable: node.compileAsync ? await node.compileAsync({ device: props.device }) : node.compile({ device: props.device })
4063
4123
  }));
4064
- import_core6.PipelineFactory.endAsyncCompilation(props.device, asyncPipelineCompilation);
4124
+ import_core8.PipelineFactory.endAsyncCompilation(props.device, asyncPipelineCompilation);
4065
4125
  const [results, pipelineResults] = await Promise.all([
4066
4126
  Promise.allSettled(nodeCompilationPromises),
4067
4127
  Promise.allSettled(asyncPipelineCompilation)
@@ -4496,7 +4556,7 @@ var __exports__ = (() => {
4496
4556
  );
4497
4557
  const available = /* @__PURE__ */ new Map();
4498
4558
  const getAvailable = (usage) => {
4499
- const key = usage & (import_core6.Buffer.MAP_READ | import_core6.Buffer.MAP_WRITE);
4559
+ const key = usage & (import_core8.Buffer.MAP_READ | import_core8.Buffer.MAP_WRITE);
4500
4560
  let pool = available.get(key);
4501
4561
  if (!pool) {
4502
4562
  pool = new GPUPlanningHeap(
@@ -4602,7 +4662,7 @@ var __exports__ = (() => {
4602
4662
  for (let mipLevel = 0; mipLevel < texture.mipLevels; mipLevel++) {
4603
4663
  byteLength = addSafeByteLengths(
4604
4664
  byteLength,
4605
- import_core6.textureFormatDecoder.computeMemoryLayout({
4665
+ import_core8.textureFormatDecoder.computeMemoryLayout({
4606
4666
  format: texture.format,
4607
4667
  width: Math.max(1, texture.width >> mipLevel),
4608
4668
  height: texture.dimension === "1d" ? 1 : Math.max(1, texture.height >> mipLevel),
@@ -5127,8 +5187,8 @@ var __exports__ = (() => {
5127
5187
  };
5128
5188
  }
5129
5189
  };
5130
- var GPUCommandGraph = class {
5131
- /** WebGPU device that owns compilation and transient resources. */
5190
+ var GPUCommandGraphBuilder = class {
5191
+ /** Device that owns compilation and transient resources. */
5132
5192
  device;
5133
5193
  /** Identifier used as a prefix for graph-owned GPU resources. */
5134
5194
  id;
@@ -5145,14 +5205,10 @@ var __exports__ = (() => {
5145
5205
  /**
5146
5206
  * Creates a mutable graph definition.
5147
5207
  *
5148
- * @param device WebGPU device used to compile and execute the graph.
5208
+ * @param device Device used to compile and execute the graph.
5149
5209
  * @param props Optional graph identity and generic adaptive-kernel selector.
5150
- * @throws If `device` is not a WebGPU device.
5151
5210
  */
5152
5211
  constructor(device, props = {}) {
5153
- if (device.type !== "webgpu") {
5154
- throw new Error("GPUCommandGraph requires a WebGPU device");
5155
- }
5156
5212
  assertDeviceAvailable(device, "construction");
5157
5213
  this.device = device;
5158
5214
  this.id = props.id ?? "gpu-command-graph";
@@ -5435,6 +5491,9 @@ var __exports__ = (() => {
5435
5491
  );
5436
5492
  }
5437
5493
  addNode(node) {
5494
+ if (this.device.type !== "webgpu" && node.type !== "render") {
5495
+ throw new Error("WebGL graphs support render passes only");
5496
+ }
5438
5497
  this.assertMutable();
5439
5498
  if (!node.id) {
5440
5499
  throw new Error("GPUCommandGraph node id is required");
@@ -5520,6 +5579,9 @@ var __exports__ = (() => {
5520
5579
  this.assertTexture(texture);
5521
5580
  validateTextureUseAgainstDescriptor(texture, resource.usage);
5522
5581
  validateTextureViewForUsage(resource.texture, resource.usage);
5582
+ if (this.device.type === "webgl" && resource.usage === "sampled" && resource.texture instanceof GraphTextureView && !isDefaultGraphTextureView(resource.texture)) {
5583
+ throw new Error("WebGL sampled textures require a full-resource view");
5584
+ }
5523
5585
  } else {
5524
5586
  this.assertExternalTexture(resource.externalTexture);
5525
5587
  if (resource.usage !== "sampled") {
@@ -6071,7 +6133,7 @@ var __exports__ = (() => {
6071
6133
  if ("frameScoped" in handle && handle.frameScoped)
6072
6134
  throw new Error("Frame textures expire after presentation.");
6073
6135
  const resource = "buffer" in use ? getBuffer(use.buffer) : getTexture(use.texture);
6074
- const aliases = resource instanceof import_core7.Buffer ? this.transientBuffers : this.transientTextures;
6136
+ const aliases = resource instanceof import_core9.Buffer ? this.transientBuffers : this.transientTextures;
6075
6137
  if (handle.transient && [...aliases].some(
6076
6138
  ([candidate, allocation]) => candidate !== handle && allocation === resource
6077
6139
  ))
@@ -6567,47 +6629,55 @@ var __exports__ = (() => {
6567
6629
  case "storage-read":
6568
6630
  case "storage-write":
6569
6631
  case "storage-read-write":
6570
- return import_core7.Buffer.STORAGE;
6632
+ return import_core9.Buffer.STORAGE;
6571
6633
  case "uniform":
6572
- return import_core7.Buffer.UNIFORM;
6634
+ return import_core9.Buffer.UNIFORM;
6573
6635
  case "copy-source":
6574
- return import_core7.Buffer.COPY_SRC;
6636
+ return import_core9.Buffer.COPY_SRC;
6575
6637
  case "copy-destination":
6576
- return import_core7.Buffer.COPY_DST;
6638
+ return import_core9.Buffer.COPY_DST;
6577
6639
  case "indirect":
6578
- return import_core7.Buffer.INDIRECT;
6640
+ return import_core9.Buffer.INDIRECT;
6579
6641
  case "vertex":
6580
- return import_core7.Buffer.VERTEX;
6642
+ return import_core9.Buffer.VERTEX;
6581
6643
  case "index":
6582
- return import_core7.Buffer.INDEX;
6644
+ return import_core9.Buffer.INDEX;
6583
6645
  }
6584
6646
  }
6585
6647
  function getRequiredTextureUsage(usage) {
6586
6648
  switch (usage) {
6587
6649
  case "sampled":
6588
- return import_core7.Texture.SAMPLE;
6650
+ return import_core9.Texture.SAMPLE;
6589
6651
  case "storage-read":
6590
6652
  case "storage-write":
6591
6653
  case "storage-read-write":
6592
- return import_core7.Texture.STORAGE;
6654
+ return import_core9.Texture.STORAGE;
6593
6655
  case "render-attachment":
6594
- return import_core7.Texture.RENDER;
6656
+ return import_core9.Texture.RENDER;
6595
6657
  case "copy-source":
6596
- return import_core7.Texture.COPY_SRC;
6658
+ return import_core9.Texture.COPY_SRC;
6597
6659
  case "copy-destination":
6598
- return import_core7.Texture.COPY_DST;
6660
+ return import_core9.Texture.COPY_DST;
6599
6661
  }
6600
6662
  }
6601
6663
  function isDefaultGraphTextureView(view) {
6602
6664
  const texture = view.texture;
6603
6665
  return view.dimension === texture.dimension && view.aspect === "all" && view.baseMipLevel === 0 && view.mipLevelCount === texture.mipLevels && view.baseArrayLayer === 0 && view.arrayLayerCount === (texture.dimension === "3d" ? 1 : texture.depth);
6604
6666
  }
6667
+ var GPUCommandGraph = class extends GPUCommandGraphBuilder {
6668
+ constructor(device, props = {}) {
6669
+ if (device.type !== "webgpu") {
6670
+ throw new Error("GPUCommandGraph requires a WebGPU device");
6671
+ }
6672
+ super(device, props);
6673
+ }
6674
+ };
6605
6675
 
6606
6676
  // src/gpu-core/compiled-gpu-graph.ts
6607
- var import_core20 = __toESM(require_core(), 1);
6677
+ var import_core22 = __toESM(require_core(), 1);
6608
6678
 
6609
6679
  // src/gpu-core/gpu-texture-plan.ts
6610
- var import_core8 = __toESM(require_core(), 1);
6680
+ var import_core10 = __toESM(require_core(), 1);
6611
6681
 
6612
6682
  // src/gpu-core/gpu-graph-value.ts
6613
6683
  var gpuGraph = {
@@ -6754,19 +6824,19 @@ var __exports__ = (() => {
6754
6824
 
6755
6825
  // src/gpu-core/gpu-texture-plan.ts
6756
6826
  function getTextureBindingInfo(binding) {
6757
- const texture = binding instanceof import_core8.TextureView ? binding.texture : binding;
6758
- const props = binding instanceof import_core8.TextureView ? binding.props : {};
6827
+ const texture = binding instanceof import_core10.TextureView ? binding.texture : binding;
6828
+ const props = binding instanceof import_core10.TextureView ? binding.props : {};
6759
6829
  const baseMipLevel = props.baseMipLevel ?? 0;
6760
6830
  const baseArrayLayer = props.baseArrayLayer ?? 0;
6761
6831
  const dimension = props.dimension ?? texture.dimension;
6762
6832
  const mipLevels = props.mipLevelCount ?? texture.mipLevels - baseMipLevel;
6763
6833
  const depth = dimension === "3d" ? Math.max(1, texture.depth >> baseMipLevel) : props.arrayLayerCount ?? (dimension === "cube" ? 6 : dimension === "2d" ? 1 : texture.depth - baseArrayLayer);
6764
- (0, import_core8.assert)((props.format ?? texture.format) === texture.format && (props.aspect ?? "all") === "all");
6765
- (0, import_core8.assert)(!binding.destroyed && !texture.destroyed);
6766
- (0, import_core8.assert)(
6834
+ (0, import_core10.assert)((props.format ?? texture.format) === texture.format && (props.aspect ?? "all") === "all");
6835
+ (0, import_core10.assert)(!binding.destroyed && !texture.destroyed);
6836
+ (0, import_core10.assert)(
6767
6837
  Number.isInteger(baseMipLevel) && baseMipLevel >= 0 && Number.isInteger(mipLevels) && mipLevels > 0 && baseMipLevel + mipLevels <= texture.mipLevels
6768
6838
  );
6769
- (0, import_core8.assert)(
6839
+ (0, import_core10.assert)(
6770
6840
  Number.isInteger(baseArrayLayer) && baseArrayLayer >= 0 && Number.isInteger(depth) && depth > 0 && (dimension === "3d" ? baseArrayLayer === 0 : baseArrayLayer + depth <= texture.depth)
6771
6841
  );
6772
6842
  return {
@@ -6789,7 +6859,7 @@ var __exports__ = (() => {
6789
6859
  const dimension = props.dimension ?? info.dimension;
6790
6860
  const mipLevelCount = props.mipLevelCount ?? info.mipLevels - baseMipLevel;
6791
6861
  const arrayLayerCount = props.arrayLayerCount ?? (dimension === "cube" ? 6 : dimension === "2d" || dimension === "3d" ? 1 : info.depth - baseArrayLayer);
6792
- (0, import_core8.assert)(
6862
+ (0, import_core10.assert)(
6793
6863
  baseMipLevel >= 0 && baseMipLevel + mipLevelCount <= info.mipLevels && baseArrayLayer >= 0 && baseArrayLayer + arrayLayerCount <= info.depth
6794
6864
  );
6795
6865
  return {
@@ -6802,13 +6872,13 @@ var __exports__ = (() => {
6802
6872
  };
6803
6873
  }
6804
6874
  var TEXTURE_USAGE = {
6805
- sampled: import_core8.Texture.SAMPLE,
6806
- "storage-read": import_core8.Texture.STORAGE,
6807
- "storage-write": import_core8.Texture.STORAGE,
6808
- "storage-read-write": import_core8.Texture.STORAGE,
6809
- "render-attachment": import_core8.Texture.RENDER,
6810
- "copy-source": import_core8.Texture.COPY_SRC,
6811
- "copy-destination": import_core8.Texture.COPY_DST
6875
+ sampled: import_core10.Texture.SAMPLE,
6876
+ "storage-read": import_core10.Texture.STORAGE,
6877
+ "storage-write": import_core10.Texture.STORAGE,
6878
+ "storage-read-write": import_core10.Texture.STORAGE,
6879
+ "render-attachment": import_core10.Texture.RENDER,
6880
+ "copy-source": import_core10.Texture.COPY_SRC,
6881
+ "copy-destination": import_core10.Texture.COPY_DST
6812
6882
  };
6813
6883
  var GPUTextureInvocation = class {
6814
6884
  values = /* @__PURE__ */ new Map();
@@ -6820,9 +6890,9 @@ var __exports__ = (() => {
6820
6890
  for (const use of contract.values) {
6821
6891
  const name = getGPUOperationValueName(use.value);
6822
6892
  if (!declarations.some((value) => value.id === name)) continue;
6823
- (0, import_core8.assert)(use.textureUsage);
6893
+ (0, import_core10.assert)(use.textureUsage);
6824
6894
  const usage = use.textureUsage;
6825
- (0, import_core8.assert)(
6895
+ (0, import_core10.assert)(
6826
6896
  use.access === "read" && ["sampled", "storage-read", "copy-source"].includes(usage) || use.access === "write" && ["storage-write", "render-attachment", "copy-destination"].includes(usage) || use.access === "read-write" && ["storage-read-write", "render-attachment"].includes(usage)
6827
6897
  );
6828
6898
  usages.set(name, (usages.get(name) ?? 0) | TEXTURE_USAGE[usage]);
@@ -6846,7 +6916,7 @@ var __exports__ = (() => {
6846
6916
  if (extent && "like" in extent && !template) continue;
6847
6917
  const source = template ? getTextureBindingInfo(template) : void 0;
6848
6918
  const scale = extent && "like" in extent ? extent.scale ?? [1, 1] : [1, 1];
6849
- (0, import_core8.assert)(scale.every((value) => Number.isFinite(value) && value > 0));
6919
+ (0, import_core10.assert)(scale.every((value) => Number.isFinite(value) && value > 0));
6850
6920
  const width = source ? Math.max(1, Math.round(source.width * scale[0])) : extent && "width" in extent ? extent.width : void 0;
6851
6921
  const height = source ? Math.max(1, Math.round(source.height * scale[1])) : extent && "height" in extent ? extent.height : void 0;
6852
6922
  const dimension = descriptor.dimension ?? source?.dimension ?? "2d";
@@ -6854,13 +6924,13 @@ var __exports__ = (() => {
6854
6924
  const mipLevels = descriptor.mipLevels ?? source?.mipLevels ?? 1;
6855
6925
  const samples = descriptor.samples ?? source?.samples ?? 1;
6856
6926
  const usage = (usages.get(declaration.id) ?? 0) | declaration.usage;
6857
- (0, import_core8.assert)(samples === 1 || !(usage & (import_core8.Texture.COPY_SRC | import_core8.Texture.COPY_DST)));
6927
+ (0, import_core10.assert)(samples === 1 || !(usage & (import_core10.Texture.COPY_SRC | import_core10.Texture.COPY_DST)));
6858
6928
  let binding = targets[declaration.id] ?? bindings[declaration.id];
6859
6929
  if (binding === void 0) {
6860
- (0, import_core8.assert)(
6930
+ (0, import_core10.assert)(
6861
6931
  declaration.role !== "input" && !declaration.external && width !== void 0 && height !== void 0 && usage !== 0
6862
6932
  );
6863
- (0, import_core8.assert)(
6933
+ (0, import_core10.assert)(
6864
6934
  Number.isSafeInteger(width) && width > 0 && Number.isSafeInteger(height) && height > 0
6865
6935
  );
6866
6936
  const texture = device.createTexture({
@@ -6872,27 +6942,27 @@ var __exports__ = (() => {
6872
6942
  depth: depth ?? 1,
6873
6943
  mipLevels,
6874
6944
  samples,
6875
- usage: usage | (samples === 1 ? import_core8.Texture.COPY_SRC : 0) | import_core8.Texture.SAMPLE
6945
+ usage: usage | (samples === 1 ? import_core10.Texture.COPY_SRC : 0) | import_core10.Texture.SAMPLE
6876
6946
  });
6877
6947
  this.owned.add(texture);
6878
6948
  binding = texture;
6879
6949
  }
6880
- (0, import_core8.assert)(binding instanceof import_core8.Texture || binding instanceof import_core8.TextureView);
6950
+ (0, import_core10.assert)(binding instanceof import_core10.Texture || binding instanceof import_core10.TextureView);
6881
6951
  const info = getTextureBindingInfo(binding);
6882
- (0, import_core8.assert)(info.samples === 1 || !(usage & (import_core8.Texture.COPY_SRC | import_core8.Texture.COPY_DST)));
6883
- (0, import_core8.assert)(
6952
+ (0, import_core10.assert)(info.samples === 1 || !(usage & (import_core10.Texture.COPY_SRC | import_core10.Texture.COPY_DST)));
6953
+ (0, import_core10.assert)(
6884
6954
  info.texture.device === device && info.format === descriptor.format && info.dimension === dimension && (width === void 0 || info.width === width) && (height === void 0 || info.height === height) && (depth === void 0 || info.depth === depth) && (descriptor.mipLevels === void 0 && declaration.role === "input" || info.mipLevels === mipLevels) && (descriptor.samples === void 0 && declaration.role === "input" || info.samples === samples) && (info.texture.props.usage & usage) === usage
6885
6955
  );
6886
6956
  this.values.set(declaration.id, binding);
6887
6957
  pending.delete(declaration);
6888
6958
  progress = true;
6889
6959
  }
6890
- (0, import_core8.assert)(progress);
6960
+ (0, import_core10.assert)(progress);
6891
6961
  }
6892
6962
  for (const name of writable) {
6893
6963
  const texture = getTextureBindingInfo(this.values.get(name)).texture;
6894
6964
  for (const [otherName, value] of this.values)
6895
- (0, import_core8.assert)(name === otherName || getTextureBindingInfo(value).texture !== texture);
6965
+ (0, import_core10.assert)(name === otherName || getTextureBindingInfo(value).texture !== texture);
6896
6966
  }
6897
6967
  } catch (error) {
6898
6968
  this.destroy();
@@ -6902,7 +6972,7 @@ var __exports__ = (() => {
6902
6972
  finish(outputs) {
6903
6973
  for (const name of outputs) {
6904
6974
  const value = this.values.get(name);
6905
- if (value instanceof import_core8.Texture) this.owned.delete(value);
6975
+ if (value instanceof import_core10.Texture) this.owned.delete(value);
6906
6976
  }
6907
6977
  this.destroy();
6908
6978
  }
@@ -6913,7 +6983,7 @@ var __exports__ = (() => {
6913
6983
  };
6914
6984
 
6915
6985
  // src/gpu-core/gpu-texture-copy.ts
6916
- var import_core9 = __toESM(require_core(), 1);
6986
+ var import_core11 = __toESM(require_core(), 1);
6917
6987
  function encodeTextureCopy(encoder, input, output) {
6918
6988
  const source = getTextureBindingInfo(input);
6919
6989
  const destination = getTextureBindingInfo(output);
@@ -6935,13 +7005,13 @@ var __exports__ = (() => {
6935
7005
  function validateTextureCopy(input, output) {
6936
7006
  const source = getTextureBindingInfo(input);
6937
7007
  const destination = getTextureBindingInfo(output);
6938
- (0, import_core9.assert)(
7008
+ (0, import_core11.assert)(
6939
7009
  source.texture !== destination.texture && source.samples === 1 && destination.samples === 1 && source.format === destination.format && source.width === destination.width && source.height === destination.height && source.depth === destination.depth && source.mipLevels === destination.mipLevels && source.dimension === destination.dimension
6940
7010
  );
6941
7011
  }
6942
7012
 
6943
7013
  // src/gpu-core/gpu-transfer-lowering.ts
6944
- var import_core10 = __toESM(require_core(), 1);
7014
+ var import_core12 = __toESM(require_core(), 1);
6945
7015
  function lowerGPUUpload(operation, context) {
6946
7016
  const output = context.resolveVector(operation.output);
6947
7017
  const chunks = operation.getData();
@@ -6952,7 +7022,7 @@ var __exports__ = (() => {
6952
7022
  id: `${operation.id}-${index}`,
6953
7023
  resources: [{ buffer: destination, usage: "copy-destination" }],
6954
7024
  compile: ({ device }) => {
6955
- const staging = device.createBuffer({ data, usage: import_core10.Buffer.COPY_SRC });
7025
+ const staging = device.createBuffer({ data, usage: import_core12.Buffer.COPY_SRC });
6956
7026
  return {
6957
7027
  encode: ({ commandEncoder, getBuffer }) => {
6958
7028
  const packed = destination.byteStride === destination.rowByteLength;
@@ -6975,10 +7045,10 @@ var __exports__ = (() => {
6975
7045
  function lowerGPUCopy(operation, context) {
6976
7046
  const input = context.resolveVector(operation.input);
6977
7047
  const output = context.resolveVector(operation.output);
6978
- (0, import_core10.assert)(input.format === output.format && input.data.length === output.data.length);
7048
+ (0, import_core12.assert)(input.format === output.format && input.data.length === output.data.length);
6979
7049
  for (const [index, source] of input.data.entries()) {
6980
7050
  const destination = output.data[index];
6981
- (0, import_core10.assert)(source.length === destination.length);
7051
+ (0, import_core12.assert)(source.length === destination.length);
6982
7052
  if (!source.length) continue;
6983
7053
  context.graph.addCopyPass({
6984
7054
  id: `${operation.id}-${index}`,
@@ -7019,7 +7089,7 @@ var __exports__ = (() => {
7019
7089
  }
7020
7090
 
7021
7091
  // src/gpu-core/gpu-transfer-operation.ts
7022
- var import_core11 = __toESM(require_core(), 1);
7092
+ var import_core13 = __toESM(require_core(), 1);
7023
7093
  var GPUUploadOperation = class {
7024
7094
  type = "vector-upload";
7025
7095
  id;
@@ -7034,7 +7104,7 @@ var __exports__ = (() => {
7034
7104
  const info = getGPUVectorFormatInfo(props.format);
7035
7105
  const chunks = Array.isArray(props.data) ? props.data : [props.data];
7036
7106
  const ValueType = info.signedDataType === "float32" ? Float32Array : info.signedDataType === "uint32" ? Uint32Array : Int32Array;
7037
- (0, import_core11.assert)(
7107
+ (0, import_core13.assert)(
7038
7108
  chunks.every((chunk) => chunk instanceof ValueType && chunk.byteLength % info.byteLength === 0)
7039
7109
  );
7040
7110
  this.chunks = chunks.map(
@@ -7073,7 +7143,7 @@ var __exports__ = (() => {
7073
7143
  const input = getValue(this.input);
7074
7144
  if (input.type === "texture")
7075
7145
  return { [this.output]: gpuGraph.texture({ ...input, extent: { like: this.input } }) };
7076
- (0, import_core11.assert)(input.type === "vector");
7146
+ (0, import_core13.assert)(input.type === "vector");
7077
7147
  return {
7078
7148
  [this.output]: gpuGraph.vector(input.format, {
7079
7149
  length: input.length,
@@ -7118,17 +7188,17 @@ var __exports__ = (() => {
7118
7188
  }
7119
7189
 
7120
7190
  // src/execution/compute/kernel.ts
7121
- var import_core12 = __toESM(require_core(), 1);
7191
+ var import_core14 = __toESM(require_core(), 1);
7122
7192
  var Kernel = class _Kernel {
7123
7193
  /** Creates a kernel while allowing the backend to compile its pipeline asynchronously. */
7124
7194
  static async createAsync(device, props) {
7125
- const ownsCompilation = !import_core12.PipelineFactory.getAsyncCompilation(device);
7126
- const asyncCompilation = ownsCompilation ? import_core12.PipelineFactory.beginAsyncCompilation(device) : import_core12.PipelineFactory.getAsyncCompilation(device);
7195
+ const ownsCompilation = !import_core14.PipelineFactory.getAsyncCompilation(device);
7196
+ const asyncCompilation = ownsCompilation ? import_core14.PipelineFactory.beginAsyncCompilation(device) : import_core14.PipelineFactory.getAsyncCompilation(device);
7127
7197
  let kernel;
7128
7198
  try {
7129
7199
  kernel = new _Kernel(device, props);
7130
7200
  } finally {
7131
- if (ownsCompilation) import_core12.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
7201
+ if (ownsCompilation) import_core14.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
7132
7202
  }
7133
7203
  try {
7134
7204
  if (ownsCompilation) {
@@ -7159,8 +7229,8 @@ var __exports__ = (() => {
7159
7229
  this.device = device;
7160
7230
  this.id = props.id ?? "kernel";
7161
7231
  this.source = source;
7162
- this.pipelineFactory = pipelineFactory ?? import_core12.PipelineFactory.getDefaultPipelineFactory(device);
7163
- this.shaderFactory = shaderFactory ?? import_core12.ShaderFactory.getDefaultShaderFactory(device);
7232
+ this.pipelineFactory = pipelineFactory ?? import_core14.PipelineFactory.getDefaultPipelineFactory(device);
7233
+ this.shaderFactory = shaderFactory ?? import_core14.ShaderFactory.getDefaultShaderFactory(device);
7164
7234
  this.shader = this.shaderFactory.createShader({
7165
7235
  id: `${this.id}-compute`,
7166
7236
  stage: "compute",
@@ -7168,7 +7238,7 @@ var __exports__ = (() => {
7168
7238
  debugShaders
7169
7239
  });
7170
7240
  const computePipelineProps = { ...pipelineProps, shader: this.shader };
7171
- const asyncCompilation = import_core12.PipelineFactory.getAsyncCompilation(device);
7241
+ const asyncCompilation = import_core14.PipelineFactory.getAsyncCompilation(device);
7172
7242
  if (asyncCompilation) {
7173
7243
  const pipelineInitialization = this.pipelineFactory.createComputePipelineAsync(computePipelineProps);
7174
7244
  this._pipelineInitialization = pipelineInitialization;
@@ -7241,7 +7311,7 @@ var __exports__ = (() => {
7241
7311
  }
7242
7312
 
7243
7313
  // src/gpu-core/graph-data-view-utils.ts
7244
- var import_core13 = __toESM(require_core(), 1);
7314
+ var import_core15 = __toESM(require_core(), 1);
7245
7315
  var UINT32_BYTE_LENGTH2 = Uint32Array.BYTES_PER_ELEMENT;
7246
7316
  var STORAGE_BINDING_ALIGNMENT = 256;
7247
7317
  function validatePackedView(view, formats, name) {
@@ -7279,11 +7349,11 @@ var __exports__ = (() => {
7279
7349
  }
7280
7350
  return view.byteOffset % STORAGE_BINDING_ALIGNMENT / UINT32_BYTE_LENGTH2;
7281
7351
  }
7282
- function createTransientView(graph, id, format, length, usage = import_core13.Buffer.STORAGE) {
7352
+ function createTransientView(graph, id, format, length, usage = import_core15.Buffer.STORAGE) {
7283
7353
  if (!Number.isSafeInteger(length) || length < 0) {
7284
7354
  throw new Error("Transient GraphDataView length must be a non-negative safe integer");
7285
7355
  }
7286
- if ((usage & import_core13.Buffer.STORAGE) === 0) {
7356
+ if ((usage & import_core15.Buffer.STORAGE) === 0) {
7287
7357
  throw new Error("Transient GraphDataView usage must include Buffer.STORAGE");
7288
7358
  }
7289
7359
  if (isVertexListGPUVectorFormat(format) || isValueListGPUVectorFormat(format)) {
@@ -8417,7 +8487,7 @@ ${countBinding}
8417
8487
  }
8418
8488
 
8419
8489
  // src/gpu-core/gpu-graph-compiler.ts
8420
- var import_core16 = __toESM(require_core(), 1);
8490
+ var import_core18 = __toESM(require_core(), 1);
8421
8491
 
8422
8492
  // src/gpu-core/gpu-command-graph-lowering-scope.ts
8423
8493
  var GPUCommandLoweringGraph = class extends GPUCommandGraph {
@@ -8480,10 +8550,10 @@ ${countBinding}
8480
8550
  };
8481
8551
 
8482
8552
  // src/gpu-core/gpu-scalar-dispatch-gate.ts
8483
- var import_core15 = __toESM(require_core(), 1);
8553
+ var import_core17 = __toESM(require_core(), 1);
8484
8554
 
8485
8555
  // src/gpu-core/gpu-value-arena.ts
8486
- var import_core14 = __toESM(require_core(), 1);
8556
+ var import_core16 = __toESM(require_core(), 1);
8487
8557
  var DEFAULT_GPU_VALUE_ARENA_BYTE_LENGTH = 16 * 1024;
8488
8558
  var GRAPH_VALUE_ARENAS = /* @__PURE__ */ new WeakMap();
8489
8559
  function getGPUValueArena(graph) {
@@ -8513,7 +8583,7 @@ ${countBinding}
8513
8583
  this.buffer = graph.createTransientBuffer({
8514
8584
  id: `${this.id}-buffer`,
8515
8585
  byteLength: capacityByteLength,
8516
- usage: import_core14.Buffer.STORAGE | import_core14.Buffer.COPY_SRC | import_core14.Buffer.COPY_DST
8586
+ usage: import_core16.Buffer.STORAGE | import_core16.Buffer.COPY_SRC | import_core16.Buffer.COPY_DST
8517
8587
  });
8518
8588
  }
8519
8589
  allocate(id, format) {
@@ -8638,7 +8708,7 @@ ${countBinding}
8638
8708
  this.dispatchBuffer = graph.createTransientBuffer({
8639
8709
  id: `${this.id}-dispatch`,
8640
8710
  byteLength: 12,
8641
- usage: import_core15.Buffer.STORAGE | import_core15.Buffer.INDIRECT | import_core15.Buffer.COPY_SRC
8711
+ usage: import_core17.Buffer.STORAGE | import_core17.Buffer.INDIRECT | import_core17.Buffer.COPY_SRC
8642
8712
  });
8643
8713
  }
8644
8714
  getUpdateCommandNodes(graph, id = `${this.id}-update`) {
@@ -10343,10 +10413,10 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
10343
10413
  if (operation instanceof GPUCompositeOperation)
10344
10414
  operation.operations.forEach(collectTransferUsages);
10345
10415
  else if (operation instanceof GPUUploadOperation)
10346
- addTransferUsage(operation.output, import_core16.Buffer.COPY_DST);
10416
+ addTransferUsage(operation.output, import_core18.Buffer.COPY_DST);
10347
10417
  else if (operation instanceof GPUCopyOperation) {
10348
- addTransferUsage(operation.input, import_core16.Buffer.COPY_SRC);
10349
- addTransferUsage(operation.output, import_core16.Buffer.COPY_DST);
10418
+ addTransferUsage(operation.input, import_core18.Buffer.COPY_SRC);
10419
+ addTransferUsage(operation.output, import_core18.Buffer.COPY_DST);
10350
10420
  }
10351
10421
  };
10352
10422
  program.operations.forEach(collectTransferUsages);
@@ -10370,7 +10440,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
10370
10440
  resources: [{ buffer: view, usage: "copy-destination" }],
10371
10441
  compile: ({ device }) => {
10372
10442
  const data = scalar.format === "float32" ? new Float32Array([value]) : scalar.format === "uint32" ? new Uint32Array([value]) : new Int32Array([value]);
10373
- const buffer = device.createBuffer({ data, usage: import_core16.Buffer.COPY_SRC });
10443
+ const buffer = device.createBuffer({ data, usage: import_core18.Buffer.COPY_SRC });
10374
10444
  return {
10375
10445
  encode: ({ commandEncoder, getBuffer }) => commandEncoder.copyBufferToBuffer({
10376
10446
  sourceBuffer: buffer,
@@ -10416,7 +10486,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
10416
10486
  chunkLengths.length === 1 ? vector.id : `${vector.id}-chunk-${index}`,
10417
10487
  vector.format,
10418
10488
  length,
10419
- vector.role === "value" ? import_core16.Buffer.STORAGE | import_core16.Buffer.VERTEX | import_core16.Buffer.COPY_SRC | import_core16.Buffer.COPY_DST : import_core16.Buffer.STORAGE | (transferUsages.get(vector.id) ?? 0)
10489
+ vector.role === "value" ? import_core18.Buffer.STORAGE | import_core18.Buffer.VERTEX | import_core18.Buffer.COPY_SRC | import_core18.Buffer.COPY_DST : import_core18.Buffer.STORAGE | (transferUsages.get(vector.id) ?? 0)
10420
10490
  )
10421
10491
  );
10422
10492
  const formatInfo = getGPUVectorFormatInfo(vector.format);
@@ -10437,12 +10507,12 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
10437
10507
  const textures = /* @__PURE__ */ new Map();
10438
10508
  const textureViews = /* @__PURE__ */ new Map();
10439
10509
  for (const texture of program.textures) {
10440
- (0, import_core16.assert)(texture.width !== void 0 && texture.height !== void 0);
10510
+ (0, import_core18.assert)(texture.width !== void 0 && texture.height !== void 0);
10441
10511
  let binding = bindings.textures?.[texture.id];
10442
10512
  let descriptor = { ...texture, width: texture.width, height: texture.height };
10443
- if (binding instanceof import_core16.TextureView) {
10513
+ if (binding instanceof import_core18.TextureView) {
10444
10514
  const info = getTextureBindingInfo(binding);
10445
- (0, import_core16.assert)(
10515
+ (0, import_core18.assert)(
10446
10516
  info.format === texture.format && info.width === texture.width && info.height === texture.height
10447
10517
  );
10448
10518
  textureViews.set(texture.id, binding);
@@ -10861,7 +10931,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
10861
10931
  }
10862
10932
 
10863
10933
  // src/gpu-core/gpu-expression-plan.ts
10864
- var import_core18 = __toESM(require_core(), 1);
10934
+ var import_core19 = __toESM(require_core(), 1);
10865
10935
 
10866
10936
  // ../../node_modules/@math.gl/core/dist/expressions/vendor/jsep/runtime.js
10867
10937
  var Hooks = class {
@@ -12203,7 +12273,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
12203
12273
  const declarations = [...this.scalars, ...this.vectors, ...this.textures];
12204
12274
  const explicit = declarations.some((value) => value.role === "input" || value.role === "state");
12205
12275
  const grouped = explicit || Object.values(supplied).some(
12206
- (value) => value !== void 0 && typeof value === "object" && !(value instanceof GPUVector) && !(value instanceof import_core18.Texture) && !(value instanceof import_core18.TextureView)
12276
+ (value) => value !== void 0 && typeof value === "object" && !(value instanceof GPUVector) && !(value instanceof CPUVector) && !(value instanceof import_core19.Texture) && !(value instanceof import_core19.TextureView)
12207
12277
  );
12208
12278
  if (!grouped) {
12209
12279
  for (const name of Object.keys(supplied))
@@ -12478,7 +12548,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
12478
12548
  const outputs = /* @__PURE__ */ Object.create(null);
12479
12549
  for (const name of this.program.outputs) {
12480
12550
  const value = this.textures?.values.get(name) ?? this.values.get(name);
12481
- if (!(value instanceof GPUVector || value instanceof import_core18.Texture || value instanceof import_core18.TextureView))
12551
+ if (!(value instanceof GPUVector || value instanceof import_core19.Texture || value instanceof import_core19.TextureView))
12482
12552
  throw new Error(`Output ${name} has no materialized resource`);
12483
12553
  outputs[name] = value;
12484
12554
  }
@@ -12506,7 +12576,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
12506
12576
  new GPUData({
12507
12577
  buffer: device.createBuffer({
12508
12578
  byteLength: Math.max(1, length) * getGPUExpressionRowInfo(format).components * 4,
12509
- usage: import_core18.Buffer.STORAGE | import_core18.Buffer.VERTEX | import_core18.Buffer.COPY_SRC | import_core18.Buffer.COPY_DST
12579
+ usage: import_core19.Buffer.STORAGE | import_core19.Buffer.VERTEX | import_core19.Buffer.COPY_SRC | import_core19.Buffer.COPY_DST
12510
12580
  }),
12511
12581
  format,
12512
12582
  length,
@@ -12533,7 +12603,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
12533
12603
  }
12534
12604
  }
12535
12605
  function validateWritableTarget(name, target, values) {
12536
- const getBuffer = (chunk) => chunk.buffer instanceof import_core18.Buffer ? chunk.buffer : chunk.buffer.buffer;
12606
+ const getBuffer = (chunk) => chunk.buffer instanceof import_core19.Buffer ? chunk.buffer : chunk.buffer.buffer;
12537
12607
  const ranges = /* @__PURE__ */ new Map();
12538
12608
  for (const chunk of target.data) {
12539
12609
  if (chunk.length === 0) continue;
@@ -12557,7 +12627,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
12557
12627
  }
12558
12628
 
12559
12629
  // src/gpu-core/gpu-expression-kernel.ts
12560
- var import_core19 = __toESM(require_core(), 1);
12630
+ var import_core20 = __toESM(require_core(), 1);
12561
12631
 
12562
12632
  // src/gpu-core/gpu-expression-cast.ts
12563
12633
  var GPU_EXPRESSION_SHADER_TYPES = { float32: "f32", sint32: "i32", uint32: "u32" };
@@ -12780,7 +12850,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
12780
12850
  getViewElementOffset(output),
12781
12851
  ...inputs.map(getViewElementOffset)
12782
12852
  ]);
12783
- const metadataBuffer = device.createBuffer({ data, usage: import_core19.Buffer.UNIFORM });
12853
+ const metadataBuffer = device.createBuffer({ data, usage: import_core20.Buffer.UNIFORM });
12784
12854
  return {
12785
12855
  encode: ({ computePass, getBuffer }) => {
12786
12856
  const bindings = { metadata: metadataBuffer };
@@ -12812,12 +12882,330 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
12812
12882
  }
12813
12883
  };
12814
12884
 
12885
+ // src/gpu-core/gpu-cpu-operation.ts
12886
+ var GPUCPUOperation = class {
12887
+ type = "cpu";
12888
+ id;
12889
+ inputs;
12890
+ outputs;
12891
+ execute;
12892
+ constructor(props) {
12893
+ this.id = props.id;
12894
+ this.inputs = Object.freeze({ ...props.inputs });
12895
+ this.outputs = Object.freeze(
12896
+ Object.fromEntries(
12897
+ Object.entries(props.outputs).map(([name, descriptor]) => [
12898
+ name,
12899
+ Object.freeze({
12900
+ ...descriptor,
12901
+ ...descriptor.chunkLengths ? { chunkLengths: Object.freeze([...descriptor.chunkLengths]) } : {}
12902
+ })
12903
+ ])
12904
+ )
12905
+ );
12906
+ this.execute = props.execute;
12907
+ }
12908
+ get contract() {
12909
+ return {
12910
+ outputs: this.outputs,
12911
+ values: [
12912
+ ...Object.values(this.inputs).map((value) => ({ value, access: "read" })),
12913
+ ...Object.keys(this.outputs).map((value) => ({ value, access: "write" }))
12914
+ ]
12915
+ };
12916
+ }
12917
+ };
12918
+
12919
+ // src/gpu-core/gpu-cpu-execution.ts
12920
+ var import_core21 = __toESM(require_core(), 1);
12921
+ var GPUCPUExecution = class {
12922
+ constructor(device, program, compileStage) {
12923
+ this.device = device;
12924
+ this.program = program;
12925
+ this.compileStage = compileStage;
12926
+ (0, import_core21.assert)(!program.textures.length && !program.vectors.some((value) => value.role === "state"));
12927
+ const declarations = [...program.scalars, ...program.vectors];
12928
+ const addInput = (graph, name) => {
12929
+ const declaration = declarations.find((value) => value.id === name);
12930
+ (0, import_core21.assert)(declaration);
12931
+ const vector = program.vectors.find((value) => value.id === name);
12932
+ if (vector)
12933
+ graph.addInput(
12934
+ name,
12935
+ gpuGraph.vector(vector.format, {
12936
+ length: vector.length,
12937
+ chunkLengths: vector.chunkLengths
12938
+ })
12939
+ );
12940
+ else
12941
+ graph.addInput(
12942
+ name,
12943
+ gpuGraph.scalar(program.scalars.find((value) => value.id === name).format)
12944
+ );
12945
+ };
12946
+ try {
12947
+ for (const operation of program.operations) {
12948
+ if (operation instanceof GPUCPUOperation) {
12949
+ this.stages.push(operation);
12950
+ continue;
12951
+ }
12952
+ (0, import_core21.assert)("contract" in operation && operation.contract);
12953
+ const inputs = operation.contract.values.filter((use) => use.access !== "write").map((use) => typeof use.value === "string" ? use.value : use.value.id);
12954
+ const outputs = operation.contract.values.filter((use) => use.access !== "read").map((use) => typeof use.value === "string" ? use.value : use.value.id);
12955
+ const graph = new GPUGraph();
12956
+ for (const name of new Set(inputs)) addInput(graph, name);
12957
+ for (const name of new Set(outputs)) {
12958
+ const vector = program.vectors.find((value) => value.id === name);
12959
+ if (vector)
12960
+ graph.addDeclaration(
12961
+ name,
12962
+ gpuGraph.vector(vector.format, {
12963
+ length: vector.length,
12964
+ chunkLengths: vector.chunkLengths
12965
+ }),
12966
+ "value"
12967
+ );
12968
+ }
12969
+ graph.add(operation);
12970
+ this.stages.push({
12971
+ graph: compileStage(graph, outputs),
12972
+ inputs
12973
+ });
12974
+ }
12975
+ } catch (error) {
12976
+ this.destroy();
12977
+ throw error;
12978
+ }
12979
+ }
12980
+ device;
12981
+ program;
12982
+ compileStage;
12983
+ stages = [];
12984
+ async run(bindings, locations = {}) {
12985
+ for (const [name, location] of Object.entries(locations))
12986
+ (0, import_core21.assert)(this.program.outputs.includes(name) && (location === "cpu" || location === "gpu"));
12987
+ const cpu = /* @__PURE__ */ new Map();
12988
+ for (const declaration of [...this.program.vectors, ...this.program.scalars].filter(
12989
+ (value) => value.role === "input"
12990
+ )) {
12991
+ const value = bindings[declaration.id];
12992
+ (0, import_core21.assert)(value !== void 0);
12993
+ if (!(value instanceof CPUVector)) {
12994
+ const graph = new GPUGraph();
12995
+ const vector = this.program.vectors.find((vector2) => vector2.id === declaration.id);
12996
+ if (vector)
12997
+ graph.addInput(
12998
+ declaration.id,
12999
+ gpuGraph.vector(vector.format, {
13000
+ length: vector.length,
13001
+ chunkLengths: vector.chunkLengths
13002
+ })
13003
+ );
13004
+ else
13005
+ graph.addInput(
13006
+ declaration.id,
13007
+ gpuGraph.scalar(
13008
+ this.program.scalars.find((scalar) => scalar.id === declaration.id).format
13009
+ )
13010
+ );
13011
+ new GPUExpressionProgram(graph, { outputs: [] }).prepare(this.device, { [declaration.id]: value }).finish();
13012
+ }
13013
+ if (value instanceof CPUVector) {
13014
+ (0, import_core21.assert)(value.data.every((chunk) => !chunk.nullBitmap && !chunk.valueOffsets));
13015
+ (0, import_core21.assert)(value.format === declaration.format);
13016
+ const vector = this.program.vectors.find((vector2) => vector2.id === declaration.id);
13017
+ (0, import_core21.assert)(vector && (vector.length === void 0 || vector.length === value.length));
13018
+ (0, import_core21.assert)(
13019
+ !vector.chunkLengths || vector.chunkLengths.length === value.data.length && vector.chunkLengths.every((length, index) => length === value.data[index].length)
13020
+ );
13021
+ cpu.set(declaration.id, value);
13022
+ }
13023
+ }
13024
+ const values = { ...bindings };
13025
+ const owned = /* @__PURE__ */ new Set();
13026
+ const ensureCPU = async (name) => {
13027
+ let value = cpu.get(name);
13028
+ if (!value) {
13029
+ const gpu = values[name];
13030
+ (0, import_core21.assert)(gpu instanceof GPUVector);
13031
+ const read = await readCPUVector(gpu);
13032
+ value = makeCPUVector(
13033
+ read.format,
13034
+ read.chunks.map((chunk) => chunk.values)
13035
+ );
13036
+ cpu.set(name, value);
13037
+ }
13038
+ return getCPUView(value);
13039
+ };
13040
+ const ensureGPU = async (name) => {
13041
+ const existing = values[name];
13042
+ if (existing instanceof GPUVector) return existing;
13043
+ const view = await ensureCPU(name);
13044
+ const graph = new GPUGraph();
13045
+ graph.add(
13046
+ new GPUUploadOperation({
13047
+ output: name,
13048
+ format: view.format,
13049
+ data: view.chunks.map((chunk) => chunk.values)
13050
+ })
13051
+ );
13052
+ const compiled = this.compileStage(graph);
13053
+ try {
13054
+ const result = (await compiled.run({}))[name];
13055
+ owned.add(result);
13056
+ values[name] = result;
13057
+ return result;
13058
+ } finally {
13059
+ compiled.destroy();
13060
+ }
13061
+ };
13062
+ try {
13063
+ for (const stage of this.stages) {
13064
+ let results;
13065
+ if (stage instanceof GPUCPUOperation) {
13066
+ const inputs = /* @__PURE__ */ Object.create(null);
13067
+ for (const [localName, name] of Object.entries(stage.inputs)) {
13068
+ const value = values[name];
13069
+ const cpuValue = typeof value === "number" ? value : await ensureCPU(name);
13070
+ inputs[localName] = typeof cpuValue !== "number" && this.program.scalars.some((scalar) => scalar.id === name) ? cpuValue.pack()[0] : cpuValue;
13071
+ }
13072
+ const outputs2 = await stage.execute({ inputs });
13073
+ (0, import_core21.assert)(Object.keys(outputs2).length === Object.keys(stage.outputs).length);
13074
+ for (const name of Object.keys(stage.outputs)) {
13075
+ const descriptor = this.program.vectors.find((vector) => vector.id === name);
13076
+ const result = outputs2[name];
13077
+ (0, import_core21.assert)(result);
13078
+ const arrays = "chunks" in result ? result.chunks.map((chunk) => chunk.values) : [result];
13079
+ const upload = new GPUUploadOperation({
13080
+ output: name,
13081
+ format: descriptor.format,
13082
+ data: arrays
13083
+ });
13084
+ const length = upload.chunkLengths.reduce((total, count) => total + count, 0);
13085
+ (0, import_core21.assert)(descriptor.length === void 0 || descriptor.length === length);
13086
+ (0, import_core21.assert)(
13087
+ !descriptor.chunkLengths || descriptor.chunkLengths.length === arrays.length && descriptor.chunkLengths.every(
13088
+ (count, index) => count === upload.chunkLengths[index]
13089
+ )
13090
+ );
13091
+ cpu.set(name, makeCPUVector(descriptor.format, arrays));
13092
+ delete values[name];
13093
+ }
13094
+ continue;
13095
+ } else {
13096
+ const inputs = /* @__PURE__ */ Object.create(null);
13097
+ for (const name of stage.inputs) {
13098
+ const value = values[name];
13099
+ inputs[name] = this.program.scalars.some((scalar) => scalar.id === name) ? typeof value === "number" ? value : (await ensureCPU(name)).pack()[0] : await ensureGPU(name);
13100
+ }
13101
+ results = await stage.graph.run({ inputs });
13102
+ }
13103
+ for (const [name, value] of Object.entries(results)) {
13104
+ cpu.delete(name);
13105
+ values[name] = value;
13106
+ owned.add(value);
13107
+ }
13108
+ }
13109
+ const outputs = /* @__PURE__ */ Object.create(null);
13110
+ for (const name of this.program.outputs) {
13111
+ if (locations[name] === "cpu") {
13112
+ await ensureCPU(name);
13113
+ outputs[name] = cpu.get(name);
13114
+ } else outputs[name] = await ensureGPU(name);
13115
+ }
13116
+ for (const value of Object.values(outputs))
13117
+ if (value instanceof GPUVector) owned.delete(value);
13118
+ return outputs;
13119
+ } finally {
13120
+ for (const value of owned) value.destroy();
13121
+ }
13122
+ }
13123
+ destroy() {
13124
+ for (const stage of this.stages) if (!(stage instanceof GPUCPUOperation)) stage.graph.destroy();
13125
+ }
13126
+ };
13127
+ async function readCPUVector(vector) {
13128
+ (0, import_core21.assert)(vector.format);
13129
+ const info = getGPUVectorFormatInfo(vector.format);
13130
+ const ValueType = info.signedDataType === "float32" ? Float32Array : info.signedDataType === "uint32" ? Uint32Array : Int32Array;
13131
+ const chunks = [];
13132
+ for (const chunk of vector.data) {
13133
+ const values = new ValueType(chunk.length * info.byteLength / 4);
13134
+ if (chunk.length) {
13135
+ const bytes = await chunk.buffer.readAsync(
13136
+ chunk.byteOffset,
13137
+ (chunk.length - 1) * chunk.byteStride + info.byteLength
13138
+ );
13139
+ const packed = new Uint8Array(values.buffer);
13140
+ for (let row = 0; row < chunk.length; row++)
13141
+ packed.set(
13142
+ bytes.subarray(row * chunk.byteStride, row * chunk.byteStride + info.byteLength),
13143
+ row * info.byteLength
13144
+ );
13145
+ }
13146
+ chunks.push({ values, length: chunk.length });
13147
+ }
13148
+ return {
13149
+ format: vector.format,
13150
+ length: vector.length,
13151
+ chunks,
13152
+ pack() {
13153
+ const packed = new ValueType(chunks.reduce((total, chunk) => total + chunk.values.length, 0));
13154
+ let offset = 0;
13155
+ for (const chunk of chunks) {
13156
+ packed.set(chunk.values, offset);
13157
+ offset += chunk.values.length;
13158
+ }
13159
+ return packed;
13160
+ }
13161
+ };
13162
+ }
13163
+ function makeCPUVector(format, arrays) {
13164
+ const width = getGPUVectorFormatInfo(format).byteLength;
13165
+ return new CPUVector({
13166
+ format,
13167
+ data: arrays.map((buffer) => new CPUData({ buffer, format, length: buffer.byteLength / width }))
13168
+ });
13169
+ }
13170
+ function getCPUView(vector) {
13171
+ const format = vector.format;
13172
+ (0, import_core21.assert)(/^(float32|sint32|uint32)(x[234])?$/.test(format));
13173
+ const info = getGPUVectorFormatInfo(format);
13174
+ const ValueType = info.signedDataType === "float32" ? Float32Array : info.signedDataType === "uint32" ? Uint32Array : Int32Array;
13175
+ const chunks = vector.data.map((chunk) => {
13176
+ const values = new ValueType(chunk.length * info.components);
13177
+ const bytes = new Uint8Array(values.buffer);
13178
+ for (let row = 0; row < chunk.length; row++)
13179
+ bytes.set(
13180
+ new Uint8Array(chunk.buffer, chunk.byteOffset + row * chunk.byteStride, info.byteLength),
13181
+ row * info.byteLength
13182
+ );
13183
+ return { values, length: chunk.length };
13184
+ });
13185
+ return {
13186
+ format,
13187
+ length: vector.length,
13188
+ chunks,
13189
+ pack() {
13190
+ const values = new ValueType(vector.length * info.components);
13191
+ let offset = 0;
13192
+ for (const chunk of chunks) {
13193
+ values.set(chunk.values, offset);
13194
+ offset += chunk.values.length;
13195
+ }
13196
+ return values;
13197
+ }
13198
+ };
13199
+ }
13200
+
12815
13201
  // src/gpu-core/compiled-gpu-graph.ts
12816
- var CompiledGPUGraph = class {
13202
+ var CompiledGPUGraph = class _CompiledGPUGraph {
12817
13203
  constructor(device, source, options = {}, lowerings) {
12818
13204
  this.device = device;
12819
13205
  if (device.type !== "webgpu") throw new Error("GPUGraph execution requires WebGPU");
12820
13206
  this.program = new GPUExpressionProgram(source, options);
13207
+ this.outputLocations = options.outputLocations ?? {};
13208
+ this.stageLowerings = lowerings ?? options.lowerings ?? [];
12821
13209
  this.compiler = new GPUGraphCompiler(device, [
12822
13210
  ...lowerings ?? options.lowerings ?? [],
12823
13211
  {
@@ -12825,6 +13213,14 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
12825
13213
  lower: (operation, context) => this.kernels.get(operation).lower(context)
12826
13214
  }
12827
13215
  ]);
13216
+ if (this.program.operations.some((operation) => operation instanceof GPUCPUOperation) || Object.values(this.outputLocations).includes("cpu")) {
13217
+ this.cpuExecution = new GPUCPUExecution(
13218
+ device,
13219
+ this.program,
13220
+ (source2, outputs) => new _CompiledGPUGraph(device, source2, { outputs }, lowerings ?? options.lowerings)
13221
+ );
13222
+ return;
13223
+ }
12828
13224
  try {
12829
13225
  for (const plan of this.program.expressions)
12830
13226
  this.kernels.set(plan.operation, new GPUExpressionKernel(device, this.program, plan));
@@ -12835,10 +13231,35 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
12835
13231
  }
12836
13232
  device;
12837
13233
  program;
13234
+ stageLowerings;
12838
13235
  compiler;
12839
13236
  kernels = /* @__PURE__ */ new Map();
12840
13237
  destroyed = false;
13238
+ runningCPU = false;
13239
+ cpuExecution;
13240
+ outputLocations;
12841
13241
  async run(supplied, options = {}) {
13242
+ (0, import_core22.assert)(!this.destroyed && !this.runningCPU);
13243
+ const suppliedInputs = "inputs" in supplied ? supplied.inputs : supplied;
13244
+ const useCPU = this.program.operations.some((operation) => operation instanceof GPUCPUOperation) || Object.values(this.outputLocations).includes("cpu") || Object.values(suppliedInputs ?? {}).some((value) => value instanceof CPUVector);
13245
+ if (!this.cpuExecution && useCPU)
13246
+ this.cpuExecution = new GPUCPUExecution(
13247
+ this.device,
13248
+ this.program,
13249
+ (source, outputs) => new _CompiledGPUGraph(this.device, source, { outputs }, this.stageLowerings)
13250
+ );
13251
+ if (useCPU && this.cpuExecution) {
13252
+ const resolved = this.program.resolveBindings(supplied, options);
13253
+ (0, import_core22.assert)(
13254
+ !resolved.options.outputTargets || Object.keys(resolved.options.outputTargets).length === 0
13255
+ );
13256
+ this.runningCPU = true;
13257
+ try {
13258
+ return await this.cpuExecution.run(resolved.bindings, this.outputLocations);
13259
+ } finally {
13260
+ this.runningCPU = false;
13261
+ }
13262
+ }
12842
13263
  const execution = this.prepare(supplied, options);
12843
13264
  let encoder;
12844
13265
  try {
@@ -12856,7 +13277,9 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
12856
13277
  }
12857
13278
  /** Bind one invocation without encoding or submitting commands. */
12858
13279
  prepare(supplied, options = {}) {
12859
- (0, import_core20.assert)(!this.destroyed);
13280
+ (0, import_core22.assert)(!this.destroyed);
13281
+ if (this.program.operations.some((operation) => operation instanceof GPUCPUOperation) || Object.values(this.outputLocations).includes("cpu"))
13282
+ throw new Error("CPU operations require asynchronous run(), not prepare()");
12860
13283
  const resolvedBindings = this.program.resolveBindings(supplied, options);
12861
13284
  const bindings = resolvedBindings.bindings;
12862
13285
  options = resolvedBindings.options;
@@ -12940,7 +13363,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
12940
13363
  }
12941
13364
  executable = compilation.graph.compile();
12942
13365
  return new PreparedGPUGraphExecution(this.device, invocation, executable, () => {
12943
- (0, import_core20.assert)(!this.destroyed);
13366
+ (0, import_core22.assert)(!this.destroyed);
12944
13367
  });
12945
13368
  } catch (error) {
12946
13369
  executable?.destroy();
@@ -12949,6 +13372,8 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
12949
13372
  }
12950
13373
  }
12951
13374
  destroy() {
13375
+ (0, import_core22.assert)(!this.runningCPU);
13376
+ this.cpuExecution?.destroy();
12952
13377
  for (const kernel of this.kernels.values()) kernel.destroy();
12953
13378
  this.kernels.clear();
12954
13379
  this.destroyed = true;
@@ -12972,7 +13397,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
12972
13397
  destroyed = false;
12973
13398
  /** Append commands once to a caller-owned encoder; never finish or submit it. */
12974
13399
  encode(commandEncoder) {
12975
- (0, import_core20.assert)(!this.destroyed && !this.encoded && commandEncoder.device === this.device);
13400
+ (0, import_core22.assert)(!this.destroyed && !this.encoded && commandEncoder.device === this.device);
12976
13401
  this.checkProgram();
12977
13402
  this.encoded = true;
12978
13403
  this.executable.encode(commandEncoder, { parameters: void 0 });
@@ -13855,17 +14280,17 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
13855
14280
  }
13856
14281
 
13857
14282
  // src/execution/compute/render-kernel.ts
13858
- var import_core21 = __toESM(require_core(), 1);
14283
+ var import_core23 = __toESM(require_core(), 1);
13859
14284
  var RenderKernel = class _RenderKernel {
13860
14285
  /** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
13861
14286
  static async createAsync(device, props) {
13862
- const ownsCompilation = !import_core21.PipelineFactory.getAsyncCompilation(device);
13863
- const asyncCompilation = ownsCompilation ? import_core21.PipelineFactory.beginAsyncCompilation(device) : import_core21.PipelineFactory.getAsyncCompilation(device);
14287
+ const ownsCompilation = !import_core23.PipelineFactory.getAsyncCompilation(device);
14288
+ const asyncCompilation = ownsCompilation ? import_core23.PipelineFactory.beginAsyncCompilation(device) : import_core23.PipelineFactory.getAsyncCompilation(device);
13864
14289
  let kernel;
13865
14290
  try {
13866
14291
  kernel = new _RenderKernel(device, props);
13867
14292
  } finally {
13868
- if (ownsCompilation) import_core21.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
14293
+ if (ownsCompilation) import_core23.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
13869
14294
  }
13870
14295
  try {
13871
14296
  if (ownsCompilation) {
@@ -13914,8 +14339,8 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
13914
14339
  this.id = props.id ?? "render-kernel";
13915
14340
  this.vertexSource = vertexSource;
13916
14341
  this.fragmentSource = fragmentSource;
13917
- this.pipelineFactory = pipelineFactory ?? import_core21.PipelineFactory.getDefaultPipelineFactory(device);
13918
- this.shaderFactory = shaderFactory ?? import_core21.ShaderFactory.getDefaultShaderFactory(device);
14342
+ this.pipelineFactory = pipelineFactory ?? import_core23.PipelineFactory.getDefaultPipelineFactory(device);
14343
+ this.shaderFactory = shaderFactory ?? import_core23.ShaderFactory.getDefaultShaderFactory(device);
13919
14344
  this.vertexShader = this.shaderFactory.createShader({
13920
14345
  id: `${this.id}-vertex`,
13921
14346
  stage: "vertex",
@@ -13933,7 +14358,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
13933
14358
  vs: this.vertexShader,
13934
14359
  fs: this.fragmentShader
13935
14360
  };
13936
- const asyncCompilation = import_core21.PipelineFactory.getAsyncCompilation(device);
14361
+ const asyncCompilation = import_core23.PipelineFactory.getAsyncCompilation(device);
13937
14362
  if (asyncCompilation) {
13938
14363
  const pipelineInitialization = this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
13939
14364
  this._pipelineInitialization = pipelineInitialization;
@@ -13990,7 +14415,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
13990
14415
  };
13991
14416
 
13992
14417
  // src/gpu-core/gpu-compaction-operation.ts
13993
- var import_core22 = __toESM(require_core(), 1);
14418
+ var import_core24 = __toESM(require_core(), 1);
13994
14419
  var GPUCompactionOperation = class {
13995
14420
  type = "compaction";
13996
14421
  id;
@@ -14005,9 +14430,9 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
14005
14430
  outputs: ({ getValue }) => {
14006
14431
  for (const name of [input, flags]) {
14007
14432
  const value = getValue(name);
14008
- (0, import_core22.assert)(value.type === "vector" && value.format === "uint32");
14433
+ (0, import_core24.assert)(value.type === "vector" && value.format === "uint32");
14009
14434
  }
14010
- (0, import_core22.assert)(output !== count);
14435
+ (0, import_core24.assert)(output !== count);
14011
14436
  return { [output]: gpuGraph.vector("uint32"), [count]: gpuGraph.scalar("uint32") };
14012
14437
  },
14013
14438
  values: [