@luma.gl/graph 10.0.0-beta.2 → 10.0.0-beta.4

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 (317) hide show
  1. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.cjs +22 -9
  2. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts +11 -2
  3. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts.map +1 -1
  4. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js +27 -10
  5. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js.map +1 -1
  6. package/dist/arrow/gpu/arrow-gpu-analytics-readback.cjs +24 -13
  7. package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts +9 -1
  8. package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts.map +1 -1
  9. package/dist/arrow/gpu/arrow-gpu-analytics-readback.js +41 -14
  10. package/dist/arrow/gpu/arrow-gpu-analytics-readback.js.map +1 -1
  11. package/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +82 -23
  12. package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +16 -1
  13. package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -1
  14. package/dist/arrow/gpu/arrow-gpu-table-conversion.js +98 -24
  15. package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -1
  16. package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +7 -0
  17. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts +2 -0
  18. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
  19. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +14 -0
  20. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
  21. package/dist/arrow/index.cjs +2 -0
  22. package/dist/arrow/index.cjs.map +3 -3
  23. package/dist/arrow/index.d.ts +1 -1
  24. package/dist/arrow/index.d.ts.map +1 -1
  25. package/dist/arrow/index.js +1 -1
  26. package/dist/arrow/index.js.map +1 -1
  27. package/dist/arrow/vectors/arrow-temporal-gpu-vector.cjs +1 -2
  28. package/dist/arrow/vectors/arrow-temporal-gpu-vector.js +2 -2
  29. package/dist/arrow/vectors/arrow-temporal-gpu-vector.js.map +1 -1
  30. package/dist/dist.dev.js +62 -27
  31. package/dist/dist.min.js +48 -47
  32. package/dist/gpu-core/gpu-bvh-bounds.cjs +63 -0
  33. package/dist/gpu-core/gpu-bvh-bounds.d.ts +32 -0
  34. package/dist/gpu-core/gpu-bvh-bounds.d.ts.map +1 -0
  35. package/dist/gpu-core/gpu-bvh-bounds.js +56 -0
  36. package/dist/gpu-core/gpu-bvh-bounds.js.map +1 -0
  37. package/dist/gpu-core/gpu-command-graph-budget-controller.cjs +10 -2
  38. package/dist/gpu-core/gpu-command-graph-budget-controller.d.ts +4 -0
  39. package/dist/gpu-core/gpu-command-graph-budget-controller.d.ts.map +1 -1
  40. package/dist/gpu-core/gpu-command-graph-budget-controller.js +10 -2
  41. package/dist/gpu-core/gpu-command-graph-budget-controller.js.map +1 -1
  42. package/dist/gpu-core/gpu-command-graph-submission-pacer.cjs +92 -0
  43. package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts +41 -0
  44. package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts.map +1 -0
  45. package/dist/gpu-core/gpu-command-graph-submission-pacer.js +85 -0
  46. package/dist/gpu-core/gpu-command-graph-submission-pacer.js.map +1 -0
  47. package/dist/gpu-core/gpu-group-aggregation.cjs +45 -21
  48. package/dist/gpu-core/gpu-group-aggregation.d.ts +4 -0
  49. package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
  50. package/dist/gpu-core/gpu-group-aggregation.js +58 -24
  51. package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
  52. package/dist/gpu-core/index.cjs +6 -0
  53. package/dist/gpu-core/index.cjs.map +3 -3
  54. package/dist/gpu-core/index.d.ts +4 -0
  55. package/dist/gpu-core/index.d.ts.map +1 -1
  56. package/dist/gpu-core/index.js +2 -0
  57. package/dist/gpu-core/index.js.map +1 -1
  58. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.cjs +6 -6
  59. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts +1 -1
  60. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts.map +1 -1
  61. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js +6 -6
  62. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js.map +1 -1
  63. package/dist/gpu-dataframe/gpu-data-frame-query.cjs +55 -14
  64. package/dist/gpu-dataframe/gpu-data-frame-query.d.ts +13 -2
  65. package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
  66. package/dist/gpu-dataframe/gpu-data-frame-query.js +58 -17
  67. package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
  68. package/dist/gpu-dataframe/gpu-data-frame.cjs +1 -3
  69. package/dist/gpu-dataframe/gpu-data-frame.d.ts +10 -0
  70. package/dist/gpu-dataframe/gpu-data-frame.d.ts.map +1 -1
  71. package/dist/gpu-dataframe/gpu-data-frame.js +1 -3
  72. package/dist/gpu-dataframe/gpu-data-frame.js.map +1 -1
  73. package/dist/gpu-dataframe/gpu-expression-shader.cjs +94 -44
  74. package/dist/gpu-dataframe/gpu-expression-shader.d.ts +8 -5
  75. package/dist/gpu-dataframe/gpu-expression-shader.d.ts.map +1 -1
  76. package/dist/gpu-dataframe/gpu-expression-shader.js +110 -47
  77. package/dist/gpu-dataframe/gpu-expression-shader.js.map +1 -1
  78. package/dist/gpu-dataframe/gpu-expression.cjs +14 -8
  79. package/dist/gpu-dataframe/gpu-expression.d.ts +12 -1
  80. package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
  81. package/dist/gpu-dataframe/gpu-expression.js +11 -6
  82. package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
  83. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +8 -4
  84. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts +2 -1
  85. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
  86. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +10 -4
  87. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js.map +1 -1
  88. package/dist/gpu-dataframe/gpu-global-aggregation-query.cjs +2 -2
  89. package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts +5 -1
  90. package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts.map +1 -1
  91. package/dist/gpu-dataframe/gpu-global-aggregation-query.js +6 -2
  92. package/dist/gpu-dataframe/gpu-global-aggregation-query.js.map +1 -1
  93. package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +156 -124
  94. package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +12 -2
  95. package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
  96. package/dist/gpu-dataframe/gpu-global-sort-compiler.js +160 -128
  97. package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
  98. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +366 -53
  99. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts +26 -4
  100. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
  101. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +378 -47
  102. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
  103. package/dist/gpu-dataframe/gpu-group-by-query.cjs +20 -9
  104. package/dist/gpu-dataframe/gpu-group-by-query.d.ts +15 -2
  105. package/dist/gpu-dataframe/gpu-group-by-query.d.ts.map +1 -1
  106. package/dist/gpu-dataframe/gpu-group-by-query.js +22 -8
  107. package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
  108. package/dist/gpu-dataframe/gpu-join-compiler.cjs +61 -8
  109. package/dist/gpu-dataframe/gpu-join-compiler.d.ts +10 -2
  110. package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
  111. package/dist/gpu-dataframe/gpu-join-compiler.js +60 -7
  112. package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
  113. package/dist/gpu-dataframe/gpu-query-compiler.cjs +61 -11
  114. package/dist/gpu-dataframe/gpu-query-compiler.d.ts +5 -1
  115. package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
  116. package/dist/gpu-dataframe/gpu-query-compiler.js +61 -10
  117. package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
  118. package/dist/gpu-dataframe/index.cjs +4 -2
  119. package/dist/gpu-dataframe/index.cjs.map +3 -3
  120. package/dist/gpu-dataframe/index.d.ts +1 -1
  121. package/dist/gpu-dataframe/index.d.ts.map +1 -1
  122. package/dist/gpu-dataframe/index.js +1 -1
  123. package/dist/gpu-dataframe/index.js.map +1 -1
  124. package/dist/gpu-graph/index.cjs.map +1 -1
  125. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +2 -2
  126. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.cjs +182 -62
  127. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.d.ts +29 -2
  128. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.d.ts.map +1 -1
  129. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.js +200 -64
  130. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.js.map +1 -1
  131. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.cjs +135 -9
  132. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.d.ts +55 -8
  133. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.d.ts.map +1 -1
  134. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.js +145 -14
  135. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.js.map +1 -1
  136. package/dist/gpu-graph-algorithms/index.cjs.map +3 -3
  137. package/dist/gpu-physics/articulation-tree-shader.cjs +177 -0
  138. package/dist/gpu-physics/articulation-tree-shader.d.ts +3 -0
  139. package/dist/gpu-physics/articulation-tree-shader.d.ts.map +1 -0
  140. package/dist/gpu-physics/articulation-tree-shader.js +159 -0
  141. package/dist/gpu-physics/articulation-tree-shader.js.map +1 -0
  142. package/dist/gpu-physics/gpu-articulation-tree.cjs +203 -0
  143. package/dist/gpu-physics/gpu-articulation-tree.d.ts +81 -0
  144. package/dist/gpu-physics/gpu-articulation-tree.d.ts.map +1 -0
  145. package/dist/gpu-physics/gpu-articulation-tree.js +205 -0
  146. package/dist/gpu-physics/gpu-articulation-tree.js.map +1 -0
  147. package/dist/gpu-physics/gpu-physics-batch.cjs +11 -10
  148. package/dist/gpu-physics/gpu-physics-batch.d.ts +1 -0
  149. package/dist/gpu-physics/gpu-physics-batch.d.ts.map +1 -1
  150. package/dist/gpu-physics/gpu-physics-batch.js +14 -10
  151. package/dist/gpu-physics/gpu-physics-batch.js.map +1 -1
  152. package/dist/gpu-physics/gpu-physics-ensemble.cjs +9 -4
  153. package/dist/gpu-physics/gpu-physics-ensemble.d.ts +10 -1
  154. package/dist/gpu-physics/gpu-physics-ensemble.d.ts.map +1 -1
  155. package/dist/gpu-physics/gpu-physics-ensemble.js +11 -4
  156. package/dist/gpu-physics/gpu-physics-ensemble.js.map +1 -1
  157. package/dist/gpu-physics/gpu-rigid-body-world.cjs +323 -68
  158. package/dist/gpu-physics/gpu-rigid-body-world.d.ts +59 -2
  159. package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
  160. package/dist/gpu-physics/gpu-rigid-body-world.js +400 -75
  161. package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
  162. package/dist/gpu-physics/index.cjs +3 -0
  163. package/dist/gpu-physics/index.cjs.map +3 -3
  164. package/dist/gpu-physics/index.d.ts +3 -1
  165. package/dist/gpu-physics/index.d.ts.map +1 -1
  166. package/dist/gpu-physics/index.js +1 -0
  167. package/dist/gpu-physics/index.js.map +1 -1
  168. package/dist/gpu-physics/rigid-body-cache-shaders.cjs +10 -6
  169. package/dist/gpu-physics/rigid-body-cache-shaders.d.ts +2 -1
  170. package/dist/gpu-physics/rigid-body-cache-shaders.d.ts.map +1 -1
  171. package/dist/gpu-physics/rigid-body-cache-shaders.js +15 -6
  172. package/dist/gpu-physics/rigid-body-cache-shaders.js.map +1 -1
  173. package/dist/gpu-physics/rigid-body-capacity.cjs +15 -2
  174. package/dist/gpu-physics/rigid-body-capacity.d.ts +3 -1
  175. package/dist/gpu-physics/rigid-body-capacity.d.ts.map +1 -1
  176. package/dist/gpu-physics/rigid-body-capacity.js +21 -2
  177. package/dist/gpu-physics/rigid-body-capacity.js.map +1 -1
  178. package/dist/gpu-physics/rigid-body-cast-index.cjs +192 -0
  179. package/dist/gpu-physics/rigid-body-cast-index.d.ts +44 -0
  180. package/dist/gpu-physics/rigid-body-cast-index.d.ts.map +1 -0
  181. package/dist/gpu-physics/rigid-body-cast-index.js +194 -0
  182. package/dist/gpu-physics/rigid-body-cast-index.js.map +1 -0
  183. package/dist/gpu-physics/rigid-body-ensemble-layout.cjs +4 -2
  184. package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts +2 -1
  185. package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts.map +1 -1
  186. package/dist/gpu-physics/rigid-body-ensemble-layout.js +5 -2
  187. package/dist/gpu-physics/rigid-body-ensemble-layout.js.map +1 -1
  188. package/dist/gpu-physics/rigid-body-ensemble-reset.cjs +11 -9
  189. package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts +1 -1
  190. package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts.map +1 -1
  191. package/dist/gpu-physics/rigid-body-ensemble-reset.js +13 -9
  192. package/dist/gpu-physics/rigid-body-ensemble-reset.js.map +1 -1
  193. package/dist/gpu-physics/rigid-body-ensemble-shaders.cjs +14 -7
  194. package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts +5 -0
  195. package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts.map +1 -1
  196. package/dist/gpu-physics/rigid-body-ensemble-shaders.js +17 -7
  197. package/dist/gpu-physics/rigid-body-ensemble-shaders.js.map +1 -1
  198. package/dist/gpu-physics/rigid-body-ensemble-transaction.cjs +21 -11
  199. package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts +2 -2
  200. package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts.map +1 -1
  201. package/dist/gpu-physics/rigid-body-ensemble-transaction.js +28 -12
  202. package/dist/gpu-physics/rigid-body-ensemble-transaction.js.map +1 -1
  203. package/dist/gpu-physics/rigid-body-event-compaction.cjs +184 -0
  204. package/dist/gpu-physics/rigid-body-event-compaction.d.ts +35 -0
  205. package/dist/gpu-physics/rigid-body-event-compaction.d.ts.map +1 -0
  206. package/dist/gpu-physics/rigid-body-event-compaction.js +168 -0
  207. package/dist/gpu-physics/rigid-body-event-compaction.js.map +1 -0
  208. package/dist/gpu-physics/rigid-body-event-snapshot.cjs +51 -0
  209. package/dist/gpu-physics/rigid-body-event-snapshot.d.ts +33 -0
  210. package/dist/gpu-physics/rigid-body-event-snapshot.d.ts.map +1 -0
  211. package/dist/gpu-physics/rigid-body-event-snapshot.js +34 -0
  212. package/dist/gpu-physics/rigid-body-event-snapshot.js.map +1 -0
  213. package/dist/gpu-physics/rigid-body-events.cjs +57 -25
  214. package/dist/gpu-physics/rigid-body-events.d.ts +2 -1
  215. package/dist/gpu-physics/rigid-body-events.d.ts.map +1 -1
  216. package/dist/gpu-physics/rigid-body-events.js +60 -25
  217. package/dist/gpu-physics/rigid-body-events.js.map +1 -1
  218. package/dist/gpu-physics/rigid-body-joints.cjs +8 -3
  219. package/dist/gpu-physics/rigid-body-joints.d.ts +2 -0
  220. package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
  221. package/dist/gpu-physics/rigid-body-joints.js +10 -6
  222. package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
  223. package/dist/gpu-physics/rigid-body-queries.cjs +159 -16
  224. package/dist/gpu-physics/rigid-body-queries.d.ts +24 -1
  225. package/dist/gpu-physics/rigid-body-queries.d.ts.map +1 -1
  226. package/dist/gpu-physics/rigid-body-queries.js +166 -14
  227. package/dist/gpu-physics/rigid-body-queries.js.map +1 -1
  228. package/dist/gpu-physics/rigid-body-shaders.cjs +3 -3
  229. package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
  230. package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
  231. package/dist/gpu-physics/rigid-body-shaders.js +3 -3
  232. package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
  233. package/dist/gpu-physics/rigid-body-triggers.cjs +53 -15
  234. package/dist/gpu-physics/rigid-body-triggers.d.ts +1 -0
  235. package/dist/gpu-physics/rigid-body-triggers.d.ts.map +1 -1
  236. package/dist/gpu-physics/rigid-body-triggers.js +55 -15
  237. package/dist/gpu-physics/rigid-body-triggers.js.map +1 -1
  238. package/dist/gpu-physics/sphere-world-shaders.cjs +48 -20
  239. package/dist/gpu-physics/sphere-world-shaders.d.ts.map +1 -1
  240. package/dist/gpu-physics/sphere-world-shaders.js +51 -21
  241. package/dist/gpu-physics/sphere-world-shaders.js.map +1 -1
  242. package/dist/gpu-project/benchmarks.cjs.map +2 -2
  243. package/dist/gpu-project/crs.cjs.map +2 -2
  244. package/dist/gpu-project/graph.cjs.map +2 -2
  245. package/dist/gpu-project/index.cjs.map +2 -2
  246. package/dist/gpu-project/projection-program.cjs +2 -9
  247. package/dist/gpu-project/projection-program.d.ts.map +1 -1
  248. package/dist/gpu-project/projection-program.js +1 -8
  249. package/dist/gpu-project/projection-program.js.map +1 -1
  250. package/dist/gpu-simple-graph/index.cjs.map +2 -2
  251. package/dist/gpu-sql/gpu-sql.cjs +345 -81
  252. package/dist/gpu-sql/gpu-sql.d.ts +42 -2
  253. package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
  254. package/dist/gpu-sql/gpu-sql.js +393 -90
  255. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  256. package/dist/gpu-sql/index.cjs.map +3 -3
  257. package/dist/gpu-sql/index.d.ts +1 -1
  258. package/dist/gpu-sql/index.d.ts.map +1 -1
  259. package/dist/index.cjs.map +1 -1
  260. package/dist/utils/float32.cjs +35 -0
  261. package/dist/utils/float32.d.ts +3 -0
  262. package/dist/utils/float32.d.ts.map +1 -0
  263. package/dist/utils/float32.js +16 -0
  264. package/dist/utils/float32.js.map +1 -0
  265. package/package.json +8 -8
  266. package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +77 -25
  267. package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +52 -16
  268. package/src/arrow/gpu/arrow-gpu-table-conversion.ts +130 -31
  269. package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +19 -0
  270. package/src/arrow/index.ts +1 -0
  271. package/src/arrow/vectors/arrow-temporal-gpu-vector.ts +2 -2
  272. package/src/gpu-core/gpu-bvh-bounds.ts +84 -0
  273. package/src/gpu-core/gpu-command-graph-budget-controller.ts +22 -2
  274. package/src/gpu-core/gpu-command-graph-submission-pacer.ts +102 -0
  275. package/src/gpu-core/gpu-group-aggregation.ts +68 -30
  276. package/src/gpu-core/index.ts +5 -0
  277. package/src/gpu-dataframe/gpu-analytics-compiler-utils.ts +7 -10
  278. package/src/gpu-dataframe/gpu-data-frame-query.ts +106 -25
  279. package/src/gpu-dataframe/gpu-data-frame.ts +35 -2
  280. package/src/gpu-dataframe/gpu-expression-shader.ts +172 -58
  281. package/src/gpu-dataframe/gpu-expression.ts +62 -9
  282. package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +15 -4
  283. package/src/gpu-dataframe/gpu-global-aggregation-query.ts +12 -3
  284. package/src/gpu-dataframe/gpu-global-sort-compiler.ts +231 -156
  285. package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +645 -61
  286. package/src/gpu-dataframe/gpu-group-by-query.ts +51 -14
  287. package/src/gpu-dataframe/gpu-join-compiler.ts +87 -6
  288. package/src/gpu-dataframe/gpu-query-compiler.ts +100 -18
  289. package/src/gpu-dataframe/index.ts +1 -1
  290. package/src/gpu-graph-algorithms/README.md +4 -2
  291. package/src/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.ts +248 -66
  292. package/src/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.ts +218 -20
  293. package/src/gpu-physics/articulation-tree-shader.ts +169 -0
  294. package/src/gpu-physics/gpu-articulation-tree.ts +279 -0
  295. package/src/gpu-physics/gpu-physics-batch.ts +19 -13
  296. package/src/gpu-physics/gpu-physics-ensemble.ts +20 -4
  297. package/src/gpu-physics/gpu-rigid-body-world.ts +510 -93
  298. package/src/gpu-physics/index.ts +16 -0
  299. package/src/gpu-physics/rigid-body-cache-shaders.ts +18 -6
  300. package/src/gpu-physics/rigid-body-capacity.ts +25 -4
  301. package/src/gpu-physics/rigid-body-cast-index.ts +277 -0
  302. package/src/gpu-physics/rigid-body-ensemble-layout.ts +6 -2
  303. package/src/gpu-physics/rigid-body-ensemble-reset.ts +21 -9
  304. package/src/gpu-physics/rigid-body-ensemble-shaders.ts +18 -7
  305. package/src/gpu-physics/rigid-body-ensemble-transaction.ts +31 -13
  306. package/src/gpu-physics/rigid-body-event-compaction.ts +252 -0
  307. package/src/gpu-physics/rigid-body-event-snapshot.ts +76 -0
  308. package/src/gpu-physics/rigid-body-events.ts +63 -25
  309. package/src/gpu-physics/rigid-body-joints.ts +11 -11
  310. package/src/gpu-physics/rigid-body-queries.ts +202 -14
  311. package/src/gpu-physics/rigid-body-shaders.ts +4 -3
  312. package/src/gpu-physics/rigid-body-triggers.ts +64 -20
  313. package/src/gpu-physics/sphere-world-shaders.ts +53 -21
  314. package/src/gpu-project/projection-program.ts +1 -9
  315. package/src/gpu-sql/gpu-sql.ts +629 -124
  316. package/src/gpu-sql/index.ts +1 -1
  317. package/src/utils/float32.ts +16 -0
@@ -3,14 +3,26 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
  // SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuGraph.
5
5
 
6
- import type {Buffer} from '@luma.gl/core';
6
+ import {Buffer, type Device} from '@luma.gl/core';
7
7
  import {DynamicBuffer} from '@luma.gl/core/dynamic';
8
8
  import type {GPUData, GPUVector} from '@luma.gl/graph/gpu-data';
9
- import type {GPUCommandGraph} from '../gpu-core/gpu-command-graph';
10
- import {addGPUGraphAlgorithmsSingleSourceShortestPathToGraphWithDispatchLimit} from './gpu-graph-single-source-shortest-path-internals';
9
+ import {GPUCommandGraph, type CompiledGPUCommandGraph} from '../gpu-core/gpu-command-graph';
10
+ import {
11
+ type GPUGraphAlgorithmsShortestPathPersistentState,
12
+ SHORTEST_PATH_CONTROL_BYTE_LENGTH,
13
+ SHORTEST_PATH_CONTROL_CONVERGED,
14
+ SHORTEST_PATH_CONTROL_DISPATCH_X,
15
+ SHORTEST_PATH_CONTROL_ITERATIONS,
16
+ addGPUGraphAlgorithmsShortestPathInitializationToGraph,
17
+ addGPUGraphAlgorithmsShortestPathRoundsToGraph,
18
+ addGPUGraphAlgorithmsSingleSourceShortestPathToGraphWithDispatchLimit
19
+ } from './gpu-graph-single-source-shortest-path-internals';
11
20
  import type {GPUGraphAlgorithmsAdjacency, GPUGraphAlgorithmsTopology} from './gpu-graph-topology';
12
21
 
13
- const MAXIMUM_SHORTEST_PATH_ITERATIONS = 1024;
22
+ /** Most relaxation rounds that one command graph encodes. */
23
+ const MAXIMUM_ENCODED_ITERATIONS = 1024;
24
+ const MAXIMUM_UINT32 = 0xffffffff;
25
+ const DEFAULT_ITERATIONS_PER_SUBMIT = 128;
14
26
  const SCALAR_BYTE_LENGTH = 4;
15
27
 
16
28
  /** Forward, reverse, or combined orientation for weighted shortest-path exploration. */
@@ -22,13 +34,14 @@ export type GPUGraphAlgorithmsSingleSourceShortestPathProps = {
22
34
  id?: string;
23
35
  /** Existing GPU-resident compressed adjacency and its explicit overflow status. */
24
36
  topology: GPUGraphAlgorithmsTopology;
25
- /** Stable source vertex identifier; zero is also accepted for an empty graph. */
26
- sourceVertex: number;
27
37
  /** One caller-owned floating-point distance for every graph vertex. */
28
38
  distances: GPUVector<'float32'>;
29
39
  /** One caller-owned unsigned predecessor identifier for every graph vertex. */
30
40
  predecessors: GPUVector<'uint32'>;
31
- /** Maximum compiled relaxation rounds, between zero and 1,024 inclusive. */
41
+ /**
42
+ * Maximum relaxation rounds, a uint32. Defaults to `vertexCount - 1`, which is enough for every
43
+ * simple path. `addToGraph()` encodes at most 1,024 of them; `run()` continues to this budget.
44
+ */
32
45
  maxIterations?: number;
33
46
  /** Forward, reverse, or combined edge orientation. Defaults to outgoing. */
34
47
  direction?: GPUGraphAlgorithmsSingleSourceShortestPathDirection;
@@ -36,6 +49,33 @@ export type GPUGraphAlgorithmsSingleSourceShortestPathProps = {
36
49
  converged?: GPUVector<'uint32'>;
37
50
  /** Optional caller-owned scalar receiving invalid, valid-endpoint source-edge weights. */
38
51
  invalidWeightCount?: GPUVector<'uint32'>;
52
+ /**
53
+ * Stable source vertex identifier; zero is also accepted for an empty graph. Give exactly one
54
+ * of `sourceVertex` and `seeds`.
55
+ */
56
+ sourceVertex?: number;
57
+ /**
58
+ * Caller-owned source vertex identifiers in one packed chunk, read when the GPU work runs.
59
+ * Await {@link GPUGraphAlgorithmsSingleSourceShortestPath.run} before writing new identifiers.
60
+ * Every seed starts at distance zero. Identifiers outside the graph are ignored.
61
+ */
62
+ seeds?: GPUVector<'uint32'>;
63
+ };
64
+
65
+ /** Options for {@link GPUGraphAlgorithmsSingleSourceShortestPath.run}. */
66
+ export type GPUGraphAlgorithmsSingleSourceShortestPathRunOptions = {
67
+ /** Relaxation rounds encoded per submission, between 1 and 1,024. Default 128. */
68
+ iterationsPerSubmit?: number;
69
+ };
70
+
71
+ /** Status of one {@link GPUGraphAlgorithmsSingleSourceShortestPath.run}. */
72
+ export type GPUGraphAlgorithmsSingleSourceShortestPathRunResult = {
73
+ /** Whether every distance is final. */
74
+ converged: boolean;
75
+ /** Relaxation rounds that ran, including the last round, which found no shorter distance. */
76
+ iterations: number;
77
+ /** Command buffers submitted, each followed by one status readback. */
78
+ submissions: number;
39
79
  };
40
80
 
41
81
  /**
@@ -51,13 +91,15 @@ export class GPUGraphAlgorithmsSingleSourceShortestPath {
51
91
  readonly id: string;
52
92
  /** Existing caller-owned graph topology. */
53
93
  readonly topology: GPUGraphAlgorithmsTopology;
54
- /** Stable source vertex identifier. */
55
- readonly sourceVertex: number;
94
+ /** Stable source vertex identifier, when the source is not read from `seeds`. */
95
+ readonly sourceVertex?: number;
96
+ /** Caller-owned source vertex identifiers. Await {@link run} before writing to the buffer. */
97
+ readonly seeds?: GPUVector<'uint32'>;
56
98
  /** Caller-owned, vertex-aligned weighted distance column. */
57
99
  readonly distances: GPUVector<'float32'>;
58
100
  /** Caller-owned, vertex-aligned deterministic predecessor column. */
59
101
  readonly predecessors: GPUVector<'uint32'>;
60
- /** Maximum compiled Bellman-Ford relaxation rounds. */
102
+ /** Maximum Bellman-Ford relaxation rounds. */
61
103
  readonly maxIterations: number;
62
104
  /** Selected graph edge orientation. */
63
105
  readonly direction: GPUGraphAlgorithmsSingleSourceShortestPathDirection;
@@ -66,28 +108,38 @@ export class GPUGraphAlgorithmsSingleSourceShortestPath {
66
108
  /** Optional caller-owned invalid-source-edge-weight count scalar. */
67
109
  readonly invalidWeightCount?: GPUVector<'uint32'>;
68
110
 
111
+ private _runner?: ShortestPathRunner;
112
+ /** Whether a run owns the runner and its outputs. */
113
+ private _running = false;
114
+
69
115
  /** Validates caller-owned metadata without allocating, submitting, or reading GPU work. */
70
116
  constructor(props: GPUGraphAlgorithmsSingleSourceShortestPathProps) {
71
117
  this.id = props.id ?? 'gpu-graph-single-source-shortest-path';
72
118
  this.topology = props.topology;
73
119
  this.sourceVertex = props.sourceVertex;
120
+ this.seeds = props.seeds;
74
121
  this.distances = props.distances;
75
122
  this.predecessors = props.predecessors;
76
- this.maxIterations =
77
- props.maxIterations ??
78
- Math.min(Math.max(this.topology.graph.vertexCount - 1, 0), MAXIMUM_SHORTEST_PATH_ITERATIONS);
123
+ this.maxIterations = props.maxIterations ?? Math.max(this.topology.graph.vertexCount - 1, 0);
79
124
  this.direction = props.direction ?? 'outgoing';
80
125
  this.converged = props.converged;
81
126
  this.invalidWeightCount = props.invalidWeightCount;
82
127
 
128
+ if ((this.sourceVertex === undefined) === (this.seeds === undefined)) {
129
+ throw new Error(`${this.id} requires exactly one of sourceVertex and seeds`);
130
+ }
83
131
  const maximumSourceVertex = Math.max(this.topology.graph.vertexCount - 1, 0);
84
132
  if (
85
- !Number.isSafeInteger(this.sourceVertex) ||
86
- this.sourceVertex < 0 ||
87
- this.sourceVertex > maximumSourceVertex
133
+ this.sourceVertex !== undefined &&
134
+ (!Number.isSafeInteger(this.sourceVertex) ||
135
+ this.sourceVertex < 0 ||
136
+ this.sourceVertex > maximumSourceVertex)
88
137
  ) {
89
138
  throw new Error(`${this.id} sourceVertex must identify an existing graph vertex`);
90
139
  }
140
+ if (this.seeds) {
141
+ validateSeedVector(this.seeds, `${this.id} seeds`);
142
+ }
91
143
  if (!['outgoing', 'incoming', 'both'].includes(this.direction)) {
92
144
  throw new Error(`${this.id} direction must be outgoing, incoming, or both`);
93
145
  }
@@ -99,9 +151,9 @@ export class GPUGraphAlgorithmsSingleSourceShortestPath {
99
151
  if (
100
152
  !Number.isSafeInteger(this.maxIterations) ||
101
153
  this.maxIterations < 0 ||
102
- this.maxIterations > MAXIMUM_SHORTEST_PATH_ITERATIONS
154
+ this.maxIterations > MAXIMUM_UINT32
103
155
  ) {
104
- throw new Error(`${this.id} maxIterations must be a safe integer between zero and 1024`);
156
+ throw new Error(`${this.id} maxIterations must be an integer between zero and 2^32 - 1`);
105
157
  }
106
158
 
107
159
  validateShortestPathVector(
@@ -130,16 +182,159 @@ export class GPUGraphAlgorithmsSingleSourceShortestPath {
130
182
  validateDistinctShortestPathOutputs(this);
131
183
  }
132
184
 
133
- /** Adds bounded weighted-path passes without submitting commands or reading GPU results. */
185
+ /**
186
+ * Adds initialization and up to 1,024 relaxation rounds without submitting or reading back.
187
+ *
188
+ * Every round is GPU-gated: once the search converges or exhausts `maxIterations`, later rounds
189
+ * dispatch zero workgroups. Use {@link run} when the search can need more than 1,024 rounds.
190
+ */
134
191
  addToGraph<Parameters>(commandGraph: GPUCommandGraph<Parameters>): void {
135
192
  addGPUGraphAlgorithmsSingleSourceShortestPathToGraphWithDispatchLimit(
136
193
  this,
137
194
  commandGraph,
138
- commandGraph.device.limits.maxComputeWorkgroupsPerDimension
195
+ commandGraph.device.limits.maxComputeWorkgroupsPerDimension,
196
+ Math.min(this.maxIterations, MAXIMUM_ENCODED_ITERATIONS)
197
+ );
198
+ }
199
+
200
+ /**
201
+ * Runs the search to convergence or to `maxIterations`, in batches of GPU-gated rounds.
202
+ *
203
+ * Each submission encodes `iterationsPerSubmit` rounds and reads back one 32-byte status.
204
+ * Runs with the same batch size reuse the compiled command graphs. Build the topology first.
205
+ * An overlapping call rejects. Await the current run before writing to {@link seeds} or calling
206
+ * {@link destroy}.
207
+ */
208
+ async run(
209
+ options: GPUGraphAlgorithmsSingleSourceShortestPathRunOptions = {}
210
+ ): Promise<GPUGraphAlgorithmsSingleSourceShortestPathRunResult> {
211
+ if (this._running) {
212
+ throw new Error(`${this.id} is already running. Await run() before starting another run.`);
213
+ }
214
+ const iterationsPerSubmit = options.iterationsPerSubmit ?? DEFAULT_ITERATIONS_PER_SUBMIT;
215
+ if (
216
+ !Number.isSafeInteger(iterationsPerSubmit) ||
217
+ iterationsPerSubmit < 1 ||
218
+ iterationsPerSubmit > MAXIMUM_ENCODED_ITERATIONS
219
+ ) {
220
+ throw new Error(`${this.id} iterationsPerSubmit must be an integer between 1 and 1024`);
221
+ }
222
+ this._running = true;
223
+ try {
224
+ if (this._runner?.iterationsPerSubmit !== iterationsPerSubmit) {
225
+ this._runner?.destroy();
226
+ this._runner = undefined;
227
+ this._runner = createShortestPathRunner(this, iterationsPerSubmit);
228
+ }
229
+ const runner = this._runner;
230
+ const {device} = runner;
231
+
232
+ let submissions = 0;
233
+ let status: Uint32Array;
234
+ let encoder = device.createCommandEncoder({id: `${this.id}-run`});
235
+ runner.initialization.encode(encoder, {parameters: undefined});
236
+ for (;;) {
237
+ runner.rounds.encode(encoder, {parameters: undefined});
238
+ device.submit(encoder.finish());
239
+ submissions++;
240
+ status = await readControl(runner.control);
241
+ if (status[SHORTEST_PATH_CONTROL_DISPATCH_X] === 0) {
242
+ break;
243
+ }
244
+ encoder = device.createCommandEncoder({id: `${this.id}-run`});
245
+ }
246
+ return {
247
+ converged: status[SHORTEST_PATH_CONTROL_CONVERGED] === 1,
248
+ iterations: status[SHORTEST_PATH_CONTROL_ITERATIONS],
249
+ submissions
250
+ };
251
+ } finally {
252
+ this._running = false;
253
+ }
254
+ }
255
+
256
+ /** Releases the command graphs and status buffers. Await {@link run} before calling this method. */
257
+ destroy(): void {
258
+ this._runner?.destroy();
259
+ this._runner = undefined;
260
+ }
261
+ }
262
+
263
+ type ShortestPathRunner = {
264
+ device: Device;
265
+ iterationsPerSubmit: number;
266
+ control: Buffer;
267
+ initialization: CompiledGPUCommandGraph;
268
+ rounds: CompiledGPUCommandGraph;
269
+ destroy: () => void;
270
+ };
271
+
272
+ /** Compiles the reusable initialization and round-batch command graphs for {@link run}. */
273
+ function createShortestPathRunner(
274
+ search: GPUGraphAlgorithmsSingleSourceShortestPath,
275
+ iterationsPerSubmit: number
276
+ ): ShortestPathRunner {
277
+ const device = getPhysicalBuffer(search.distances.data[0]).device;
278
+ const maxComputeWorkgroupsPerDimension = device.limits.maxComputeWorkgroupsPerDimension;
279
+ const control = device.createBuffer({
280
+ id: `${search.id}-control`,
281
+ byteLength: SHORTEST_PATH_CONTROL_BYTE_LENGTH,
282
+ usage: Buffer.STORAGE | Buffer.INDIRECT | Buffer.COPY_SRC
283
+ });
284
+ const persistent: GPUGraphAlgorithmsShortestPathPersistentState = {control};
285
+ const compiled: CompiledGPUCommandGraph[] = [];
286
+ const destroy = () => {
287
+ for (const graph of compiled) graph.destroy();
288
+ control.destroy();
289
+ };
290
+ try {
291
+ const initializationGraph = new GPUCommandGraph(device, {id: `${search.id}-initialization`});
292
+ addGPUGraphAlgorithmsShortestPathInitializationToGraph(
293
+ search,
294
+ initializationGraph,
295
+ maxComputeWorkgroupsPerDimension,
296
+ persistent
139
297
  );
298
+ const initialization = initializationGraph.compile();
299
+ compiled.push(initialization);
300
+ const roundsGraph = new GPUCommandGraph(device, {id: `${search.id}-rounds`});
301
+ addGPUGraphAlgorithmsShortestPathRoundsToGraph(
302
+ search,
303
+ roundsGraph,
304
+ maxComputeWorkgroupsPerDimension,
305
+ iterationsPerSubmit,
306
+ persistent
307
+ );
308
+ const rounds = roundsGraph.compile();
309
+ compiled.push(rounds);
310
+ return {
311
+ device,
312
+ iterationsPerSubmit,
313
+ control,
314
+ initialization,
315
+ rounds,
316
+ destroy
317
+ };
318
+ } catch (error) {
319
+ destroy();
320
+ throw error;
140
321
  }
141
322
  }
142
323
 
324
+ /** Reads the dispatch command, round count, and convergence status in one transfer. */
325
+ async function readControl(control: Buffer): Promise<Uint32Array> {
326
+ const bytes = await control.readAsync(0, SHORTEST_PATH_CONTROL_BYTE_LENGTH);
327
+ return new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
328
+ }
329
+
330
+ /** Requires one packed uint32 chunk with at least one seed. */
331
+ function validateSeedVector(seeds: GPUVector<'uint32'>, name: string): void {
332
+ if (seeds.length < 1 || seeds.length > MAXIMUM_UINT32) {
333
+ throw new Error(`${name} must contain at least one uint32 vertex identifier`);
334
+ }
335
+ validateShortestPathVector(seeds, 'uint32', seeds.length, name);
336
+ }
337
+
143
338
  /** Requires exactly one packed, properly aligned caller-owned scalar output chunk. */
144
339
  function validateShortestPathVector<Format extends 'uint32' | 'float32'>(
145
340
  vector: GPUVector<Format>,
@@ -197,6 +392,9 @@ function validateDistinctShortestPathOutputs(
197
392
  }
198
393
  }
199
394
 
395
+ if (search.seeds) {
396
+ physicalAllocations.add(getPhysicalBuffer(search.seeds.data[0]));
397
+ }
200
398
  const outputs = [
201
399
  {name: 'distances', vector: search.distances},
202
400
  {name: 'predecessors', vector: search.predecessors},
@@ -0,0 +1,169 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** Fixed-base joint-space forward dynamics. One invocation owns a whole small tree. */
6
+ export function getArticulationTreeShader(
7
+ count: number,
8
+ contact = false,
9
+ publishMatrices = false
10
+ ): string {
11
+ return /* wgsl */ `
12
+ const N = ${count}u;
13
+ struct Link {
14
+ parentAnchor:vec4f, childAnchor:vec4f, axisMass:vec4f, inertia:vec4f, rest:vec4f
15
+ }
16
+ struct Pose { position:vec4f, rotation:vec4f, velocity:vec4f, spin:vec4f }
17
+ struct Settings { base:vec4f, gravityStep:vec4f, boxCenterRadius:vec4f, boxExtentsLink:vec4f }
18
+ @group(0) @binding(0) var<storage,read> links:array<Link>;
19
+ @group(0) @binding(1) var<storage,read> drives:array<vec4f>;
20
+ @group(0) @binding(2) var<storage,read_write> coordinates:array<vec4f>;
21
+ @group(0) @binding(3) var<storage,read_write> poses:array<Pose>;
22
+ @group(0) @binding(4) var<storage,read_write> counters:array<u32>;
23
+ @group(0) @binding(5) var<uniform> settings:Settings;
24
+
25
+ ${publishMatrices ? '@group(0) @binding(6) var<storage,read_write> matrices:array<mat4x4f>;' : ''}
26
+ var<private> angle:array<f32,N>;
27
+ var<private> speed:array<f32,N>;
28
+ var<private> solved:array<Pose,N>;
29
+ var<private> axis:array<vec3f,N>;
30
+ var<private> pivot:array<vec3f,N>;
31
+ var<private> acceleration:array<vec3f,N>;
32
+ var<private> angularAcceleration:array<vec3f,N>;
33
+ fn rotate(q:vec4f,v:vec3f)->vec3f{return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}
34
+ fn product(a:vec4f,b:vec4f)->vec4f{return vec4f(a.w*b.xyz+b.w*a.xyz+cross(a.xyz,b.xyz),a.w*b.w-dot(a.xyz,b.xyz));}
35
+ fn inertia(i:u32,v:vec3f)->vec3f{
36
+ let q=solved[i].rotation;
37
+ return rotate(q,links[i].inertia.xyz*rotate(vec4f(-q.xyz,q.w),v));
38
+ }
39
+ // Propagate pose, twist and bias acceleration (joint accelerations held at zero).
40
+ fn kinematics(){
41
+ for(var i=0u;i<N;i++){
42
+ let link=links[i];let parent=i32(link.parentAnchor.w);
43
+ var previous=Pose(vec4f(settings.base.xyz,0),vec4f(0,0,0,1),vec4f(0),vec4f(0));
44
+ var linearBias=vec3f(0);var angularBias=vec3f(0);
45
+ if(parent>=0){previous=solved[parent];linearBias=acceleration[parent];angularBias=angularAcceleration[parent];}
46
+ let offset=rotate(previous.rotation,link.parentAnchor.xyz);
47
+ pivot[i]=previous.position.xyz+offset;
48
+ axis[i]=rotate(previous.rotation,link.axisMass.xyz);
49
+ let halfAngle=0.5*angle[i];
50
+ let rotation=normalize(product(product(previous.rotation,vec4f(link.axisMass.xyz*sin(halfAngle),cos(halfAngle))),link.rest));
51
+ let radius=rotate(rotation,-link.childAnchor.xyz);
52
+ let parentSpin=previous.spin.xyz;
53
+ let spin=parentSpin+axis[i]*speed[i];
54
+ let velocity=previous.velocity.xyz+cross(parentSpin,offset)+cross(spin,radius);
55
+ let pivotBias=linearBias+cross(angularBias,offset)+cross(parentSpin,cross(parentSpin,offset));
56
+ angularAcceleration[i]=angularBias+cross(parentSpin,axis[i]*speed[i]);
57
+ acceleration[i]=pivotBias+cross(angularAcceleration[i],radius)+cross(spin,cross(spin,radius));
58
+ solved[i]=Pose(vec4f(pivot[i]+radius,1),rotation,vec4f(velocity,0),vec4f(spin,0));
59
+ }
60
+ }
61
+ fn finite(v:vec4f)->bool{return all(abs(v)<=vec4f(3.4028234e38));}
62
+ @compute @workgroup_size(1) fn main(){
63
+ if(counters[1]!=0u){return;}
64
+ let dt=settings.gravityStep.w;
65
+ var mass:array<array<f32,N>,N>;var inverse:array<array<f32,N>,N>;
66
+ var force:array<f32,N>;var impulse:array<f32,N>;
67
+ for(var i=0u;i<N;i++){
68
+ angle[i]=coordinates[i].x;speed[i]=coordinates[i].y;inverse[i][i]=1;
69
+ // A fixed link contributes its mass to ancestors and has no generalized motion.
70
+ if(dot(links[i].axisMass.xyz,links[i].axisMass.xyz)==0){mass[i][i]=1;}
71
+ }
72
+ kinematics();
73
+ for(var body=0u;body<N;body++){
74
+ let center=solved[body].position.xyz;let spin=solved[body].spin.xyz;
75
+ let load=links[body].axisMass.w*(settings.gravityStep.xyz-acceleration[body]);
76
+ let moment= -inertia(body,angularAcceleration[body])-cross(spin,inertia(body,spin));
77
+ for(var row=i32(body);row>=0;row=i32(links[row].parentAnchor.w)){
78
+ let linear=cross(axis[row],center-pivot[row]);
79
+ force[row]+=dot(linear,load)+dot(axis[row],moment);
80
+ let angularMass=inertia(body,axis[row]);
81
+ for(var column=i32(body);column>=0;column=i32(links[column].parentAnchor.w)){
82
+ mass[row][column]+=links[body].axisMass.w*dot(linear,cross(axis[column],center-pivot[column]))+dot(angularMass,axis[column]);
83
+ }
84
+ }
85
+ }
86
+ // Positive definite joint inertia admits elimination without pivoting.
87
+ for(var k=0u;k<N;k++){
88
+ let diagonal=mass[k][k];if(!(diagonal>0)){counters[1]=1u;return;}
89
+ for(var j=0u;j<N;j++){mass[k][j]/=diagonal;inverse[k][j]/=diagonal;}
90
+ for(var i=0u;i<N;i++){if(i!=k){
91
+ let factor=mass[i][k];
92
+ for(var j=0u;j<N;j++){mass[i][j]-=factor*mass[k][j];inverse[i][j]-=factor*inverse[k][j];}
93
+ }}
94
+ }
95
+ for(var i=0u;i<N;i++){for(var j=0u;j<N;j++){speed[i]+=dt*inverse[i][j]*force[j];}}
96
+ ${
97
+ contact
98
+ ? `// Closest point on a finite AABB. Inside, use the nearest exit face.
99
+ let body=u32(settings.boxExtentsLink.w);
100
+ let center=solved[body].position.xyz;
101
+ let local=center-settings.boxCenterRadius.xyz;
102
+ let extent=settings.boxExtentsLink.xyz;
103
+ let outside=local-clamp(local,-extent,extent);
104
+ let distance=length(outside);
105
+ var normal=vec3f(0);
106
+ var gap=distance-settings.boxCenterRadius.w;
107
+ if(distance>0.0){normal=outside/distance;}else{
108
+ let depth=extent-abs(local);var face=0u;
109
+ if(depth.y<depth.x){face=1u;}if(depth.z<depth[face]){face=2u;}
110
+ normal[face]=select(-1.0,1.0,local[face]>=0.0);
111
+ gap= -depth[face]-settings.boxCenterRadius.w;
112
+ }
113
+ var jacobian:array<f32,N>;var response:array<f32,N>;
114
+ for(var joint=i32(body);joint>=0;joint=i32(links[joint].parentAnchor.w)){
115
+ jacobian[joint]=dot(normal,cross(axis[joint],center-pivot[joint]));
116
+ }
117
+ var inverseContactMass=0.0;
118
+ for(var row=0u;row<N;row++){
119
+ for(var column=0u;column<N;column++){response[row]+=inverse[row][column]*jacobian[column];}
120
+ inverseContactMass+=jacobian[row]*response[row];
121
+ }
122
+ // Speculate across the remaining gap; correct existing overlap gradually.
123
+ let separationSpeed=select(-gap/dt,min(2.0,0.2*max(0.0,-gap-0.0001)/dt),gap<0.0);
124
+ var normalImpulse=0.0;`
125
+ : ''
126
+ }
127
+ // Implicit spring/damper impulses in coupled joint space. Project each update
128
+ // onto its torque budget and propagate the resulting velocity change to all axes.
129
+ for(var sweep=0u;sweep<64u;sweep++){
130
+ var change=0.0;
131
+ for(var i=0u;i<N;i++){
132
+ let drive=drives[i];let resistance=dt*(drive.z+dt*drive.y);
133
+ let residual=dt*drive.y*(drive.x-angle[i])-resistance*speed[i]-impulse[i];
134
+ let next=clamp(impulse[i]+residual/(1.0+resistance*inverse[i][i]),-dt*drive.w,dt*drive.w);
135
+ let delta=next-impulse[i];impulse[i]=next;change=max(change,abs(delta));
136
+ for(var j=0u;j<N;j++){speed[j]+=inverse[j][i]*delta;}
137
+ }
138
+ ${
139
+ contact
140
+ ? `if(inverseContactMass>1e-9){
141
+ var normalSpeed=0.0;
142
+ for(var j=0u;j<N;j++){normalSpeed+=jacobian[j]*speed[j];}
143
+ let next=max(0.0,normalImpulse+(separationSpeed-normalSpeed)/inverseContactMass);
144
+ let delta=next-normalImpulse;normalImpulse=next;change=max(change,abs(delta));
145
+ for(var j=0u;j<N;j++){speed[j]+=response[j]*delta;}
146
+ }`
147
+ : ''
148
+ }
149
+ if(change<1e-7){break;}
150
+ }
151
+ for(var i=0u;i<N;i++){angle[i]+=dt*speed[i];}
152
+ kinematics();
153
+ for(var i=0u;i<N;i++){let pose=solved[i];
154
+ if(!finite(vec4f(angle[i],speed[i],impulse[i]/dt,0))||!finite(pose.position)||!finite(pose.rotation)||!finite(pose.velocity)||!finite(pose.spin)){counters[1]=1u;return;}
155
+ }
156
+ for(var i=0u;i<N;i++){coordinates[i]=vec4f(angle[i],speed[i],impulse[i]/dt,0);poses[i]=solved[i];}
157
+ ${contact ? 'counters[2]=bitcast<u32>(normalImpulse/dt);' : ''}
158
+ ${
159
+ publishMatrices
160
+ ? `for(var i=0u;i<N;i++){
161
+ let pose=solved[i];let q=pose.rotation;
162
+ matrices[i]=mat4x4f(vec4f(rotate(q,vec3f(1,0,0)),0),vec4f(rotate(q,vec3f(0,1,0)),0),vec4f(rotate(q,vec3f(0,0,1)),0),pose.position);
163
+ }`
164
+ : ''
165
+ }
166
+ counters[0]++;
167
+ }
168
+ `;
169
+ }