@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
@@ -26,7 +26,10 @@ import { addRigidBodyPosePublication } from "./rigid-body-publication.js";
26
26
  import { getRigidBodyShader } from "./rigid-body-shaders.js";
27
27
  import { getVehicleShader, VEHICLE_STRIDE, VEHICLE_TERRAIN_ROW_SIZE } from "./rigid-body-vehicle.js";
28
28
  import { decodeRigidBodyContactEvents, getRigidBodyEventShader } from "./rigid-body-events.js";
29
- import { RIGID_BODY_QUERY_SHADER } from "./rigid-body-queries.js";
29
+ import { addRigidBodyEventCompaction } from "./rigid-body-event-compaction.js";
30
+ import { readRigidBodyEventSnapshot } from "./rigid-body-event-snapshot.js";
31
+ import { RIGID_BODY_QUERY_SHADER, getRigidBodyBatchCastShader, RIGID_BODY_CAST_COMMAND_BYTES, RIGID_BODY_BATCH_RESULT_BYTES, packRigidBodyBatchCasts, decodeRigidBodyBatchCasts, decodeRigidBodyQueryHit } from "./rigid-body-queries.js";
32
+ import { canIndexRigidBodyCastCollider, createRigidBodyCastIndex, estimateRigidBodyCastIndexBytes, getRigidBodyCastOrder } from "./rigid-body-cast-index.js";
30
33
  export class GPURigidBodyWorld {
31
34
  worldOrigin = [0, 0, 0];
32
35
  id;
@@ -48,6 +51,14 @@ export class GPURigidBodyWorld {
48
51
  sleepStates = null;
49
52
  /** World-owned GPU event ring; present only when eventCapacity is positive. */
50
53
  contactEvents = null;
54
+ /** Trigger history and authored group IDs remain stable until world destruction. */
55
+ triggerHistory = null;
56
+ /** Contact activity is recorded in pair-slot order after accepted steps. */
57
+ contactHistory = null;
58
+ /** A recovery read shares the incremental trigger cursor. */
59
+ triggerSnapshotRead = null;
60
+ /** A recovery read shares the incremental contact cursor. */
61
+ contactSnapshotRead = null;
51
62
  triggerEvents = null;
52
63
  triggerCursor = 0;
53
64
  triggerRead = null;
@@ -55,6 +66,18 @@ export class GPURigidBodyWorld {
55
66
  eventRead = null;
56
67
  queryComputation = null;
57
68
  queryReduction = null;
69
+ /** Batched nearest-hit computation using the current world pose buffers. */
70
+ batchCast = null;
71
+ /** Compiled query graph that refits the world BVH and then casts. */
72
+ batchCastIndex = null;
73
+ /** Initial spatial order and stable collider ID mapping for indexed batches. */
74
+ batchCastOrder = null;
75
+ /** Query graph reservation before attachment, when the physical plan is unavailable. */
76
+ batchCastIndexEstimate;
77
+ /** Reusable storage for a bounded list of ray and sweep commands. */
78
+ batchCastCommands = null;
79
+ /** Reusable GPU output with one compact result per batch command. */
80
+ batchCastResults = null;
58
81
  /** Chassis definitions in GPU storage order. */
59
82
  vehicles;
60
83
  /** Whether any chassis has more than one terrain candidate. */
@@ -102,6 +125,14 @@ export class GPURigidBodyWorld {
102
125
  gpuCheckpoints = new Set();
103
126
  broadPhaseCounters = null;
104
127
  constructor(props) {
128
+ /** Zero leaves the optional command and result buffers unallocated. */
129
+ const queryBatchCapacity = props.queryBatchCapacity ?? 0;
130
+ if (!Number.isSafeInteger(queryBatchCapacity) ||
131
+ queryBatchCapacity < 0 ||
132
+ queryBatchCapacity > 65535 ||
133
+ (queryBatchCapacity > 0 && !props.enableQueries) ||
134
+ (props.queryBatchIndex && queryBatchCapacity === 0))
135
+ throw new Error('Invalid collision cast batch capacity');
105
136
  for (const damping of [props.linearDamping ?? 0, props.angularDamping ?? 0]) {
106
137
  if (!Number.isFinite(damping) || damping < 0)
107
138
  throw new Error('Invalid damping');
@@ -267,6 +298,16 @@ export class GPURigidBodyWorld {
267
298
  (this.broadPhase === 'hierarchical-grid' &&
268
299
  (this.maximumPairs & (this.maximumPairs - 1)) !== 0))
269
300
  throw new Error('Invalid rigid-body pair capacity');
301
+ /** Size each recoverable cache range independently of the shared candidate budget. */
302
+ const instancePairCapacity = props.ensemblePairsPerInstance;
303
+ if (instancePairCapacity !== undefined &&
304
+ (!props.ensembleBodiesPerInstance ||
305
+ props.failurePolicy !== 'rollback' ||
306
+ !Number.isSafeInteger(instancePairCapacity) ||
307
+ instancePairCapacity < 1 ||
308
+ instancePairCapacity * (this.count / props.ensembleBodiesPerInstance) > this.maximumPairs ||
309
+ (instancePairCapacity & (instancePairCapacity - 1)) !== 0))
310
+ throw new Error('Invalid ensemble instance contact capacity');
270
311
  if (props.continuous) {
271
312
  if (props.failurePolicy !== 'rollback' ||
272
313
  !Number.isInteger(props.continuous.maximumImpacts ?? 4) ||
@@ -307,6 +348,10 @@ export class GPURigidBodyWorld {
307
348
  const definitions = structuredClone({ colliders, props });
308
349
  this.props = definitions.props;
309
350
  this.colliders = definitions.colliders;
351
+ this.batchCastIndexEstimate =
352
+ this.props.queryBatchIndex && this.colliderCount
353
+ ? estimateRigidBodyCastIndexBytes(this.colliders.filter(canIndexRigidBodyCastCollider).length)
354
+ : 0;
310
355
  this.ensembleTerrainSlots = new Set(this.props.ensembleTerrainSlots);
311
356
  if (this.ensembleTerrainSlots.size &&
312
357
  (!this.props.ensembleBodiesPerInstance ||
@@ -398,7 +443,9 @@ export class GPURigidBodyWorld {
398
443
  sparse,
399
444
  extended,
400
445
  parallel,
401
- ...getRigidBodyStorageLayout(this.count, this.colliderStorageCount, this.maximumPairs, geometryWords, sparse, extended, parallel, this.props.eventCapacity ?? 0, this.props.enableQueries ?? false, this.props.failurePolicy === 'rollback', Boolean(this.props.continuous), this.props.joints?.length ?? 0, this.props.ensembleBodiesPerInstance ? this.count / this.props.ensembleBodiesPerInstance : 0)
446
+ ...getRigidBodyStorageLayout(this.count, this.colliderStorageCount, this.maximumPairs, geometryWords, sparse, extended, parallel, this.props.eventCapacity ?? 0, this.props.enableQueries ?? false, this.props.failurePolicy === 'rollback', Boolean(this.props.continuous), this.props.joints?.length ?? 0, this.props.ensembleBodiesPerInstance
447
+ ? this.count / this.props.ensembleBodiesPerInstance
448
+ : 0, Boolean(this.props.ensemblePairsPerInstance), this.props.queryBatchCapacity)
402
449
  };
403
450
  if (this.vehicles.length) {
404
451
  const byteLength = this.getVehicleByteLength();
@@ -463,7 +510,7 @@ export class GPURigidBodyWorld {
463
510
  if (!this.device || !this.ensembleBuffer || this.destroyed)
464
511
  throw new Error('World has no ensemble scheduler');
465
512
  this.ensembleResetOrigin ??= this.origin;
466
- this.ensembleReset ??= makeEnsembleReset(this.device, this.id, this.ownedBuffers, this.count, this.props.ensembleBodiesPerInstance, this.props.collisionPartitionSize, this.maximumPairs, this.vehiclesPerInstance, this.ensembleTerrainSlots);
513
+ this.ensembleReset ??= makeEnsembleReset(this.device, this.id, this.ownedBuffers, this.count, this.props.ensembleBodiesPerInstance, this.props.collisionPartitionSize, this.maximumPairs, this.vehiclesPerInstance, this.ensembleTerrainSlots, this.props.ensemblePairsPerInstance);
467
514
  return this.ensembleReset.byteLength;
468
515
  }
469
516
  resetEnsembleInstance(instance) {
@@ -505,7 +552,7 @@ export class GPURigidBodyWorld {
505
552
  metadata.write(new Float32Array((collider.position ?? [0, 0, 0]).map((value, axis) => value - center[axis])), this.count * 48 + index * 96 + 16);
506
553
  }
507
554
  this.ensembleReset.reset(instance, this.origin.map((value, axis) => value - this.ensembleResetOrigin[axis]));
508
- this.ensembleBuffer.write(new Uint32Array([0, 0, 0, 0, 1, 1]), (16 + instance * 8 + 1) * 4);
555
+ this.ensembleBuffer.write(new Uint32Array([0, 0, 0, 0, 1, 1, 0]), (16 + instance * 8 + 1) * 4);
509
556
  if (this.encodePosePublication) {
510
557
  const encoder = this.device.createCommandEncoder();
511
558
  this.encodePosePublication(encoder);
@@ -564,7 +611,7 @@ export class GPURigidBodyWorld {
564
611
  instance >= this.count / this.props.ensembleBodiesPerInstance)
565
612
  throw new Error('Invalid ensemble instance');
566
613
  }
567
- /** Allocation preflight without GPU allocation. Graph scratch and driver overhead are separate. */
614
+ /** World buffer sizes and private query scratch. Simulation graph scratch and driver overhead are separate. */
568
615
  getCapacityInfo() {
569
616
  const buffers = this.allocationPlan
570
617
  ? this.allocationPlan.map(buffer => ({ ...buffer }))
@@ -575,6 +622,7 @@ export class GPURigidBodyWorld {
575
622
  maximumPairs: this.maximumPairs,
576
623
  pairWorkgroups: Math.ceil(this.maximumPairs / 64),
577
624
  buffers,
625
+ queryIndexScratchBytes: this.batchCastIndex?.stats.physicalTransientResourceBytes ?? this.batchCastIndexEstimate,
578
626
  ownedBufferBytes: buffers.reduce((total, buffer) => total + buffer.byteLength, 0)
579
627
  };
580
628
  }
@@ -597,6 +645,8 @@ export class GPURigidBodyWorld {
597
645
  if (buffer.byteLength > Math.min(graph.device.limits.maxBufferSize, bindingLimit))
598
646
  throw new Error(`Rigid-body ${buffer.name} storage exceeds device limits`);
599
647
  }
648
+ if ((this.props.queryBatchCapacity ?? 0) > graph.device.limits.maxComputeWorkgroupsPerDimension)
649
+ throw new Error('Collision cast batch exceeds device dispatch limits');
600
650
  this.allocationPlan = allocationPlan;
601
651
  this.device = graph.device;
602
652
  const allocate = (name, data, uniform = false) => {
@@ -721,7 +771,7 @@ export class GPURigidBodyWorld {
721
771
  this.angularVelocities = allocate('angular-velocities', angular);
722
772
  this.sleepStates = allocate('sleep', this.count * 16);
723
773
  this.targets = allocate('targets', this.props.ensembleBodiesPerInstance
724
- ? getEnsembleContactLayout(this.count, this.count / this.props.ensembleBodiesPerInstance, this.maximumPairs).byteLength
774
+ ? getEnsembleContactLayout(this.count, this.count / this.props.ensembleBodiesPerInstance, this.maximumPairs, Boolean(this.props.ensemblePairsPerInstance)).byteLength
725
775
  : Math.ceil((this.count * 32 + (sparse ? 32 + this.maximumPairs * 8 : 16)) / 16) * 16 +
726
776
  (this.props.joints?.length ?? 0) * RIGID_BODY_JOINT_STATE_BYTES);
727
777
  for (const [index, joint] of (this.props.joints ?? []).entries()) {
@@ -837,7 +887,7 @@ export class GPURigidBodyWorld {
837
887
  usage: Buffer.STORAGE
838
888
  }, objectAttributes), { format: 'uint32', length: this.colliderStorageCount })
839
889
  : undefined;
840
- const source = getRigidBodyShader(this.count, this.props.iterations ?? 16, this.colliderStorageCount, extended, sparseLayout, parallel, this.props.maximumMeshTraversalTestsPerPair ?? 65536, getRigidBodyJointShader(this.props.joints ?? [], this.props.bodies), Boolean(this.props.joints?.length), this.props.linearDamping ?? 0, this.props.angularDamping ?? 0, this.props.joints?.length ?? 0, this.props.compactContacts ?? true, this.props.collisionPartitionSize, this.props.ensembleBodiesPerInstance, this.props.parallelContactSolver === 'block', this.colliders.some(collider => collider.shape.type === 'height-field'));
890
+ const source = getRigidBodyShader(this.count, this.props.iterations ?? 16, this.colliderStorageCount, extended, sparseLayout, parallel, this.props.maximumMeshTraversalTestsPerPair ?? 65536, getRigidBodyJointShader(this.props.joints ?? [], this.props.bodies), Boolean(this.props.joints?.length), this.props.linearDamping ?? 0, this.props.angularDamping ?? 0, this.props.joints?.length ?? 0, this.props.compactContacts ?? true, this.props.collisionPartitionSize, this.props.ensembleBodiesPerInstance, this.props.parallelContactSolver === 'block', this.colliders.some(collider => collider.shape.type === 'height-field'), this.props.ensemblePairsPerInstance);
841
891
  const parallelBindings = {
842
892
  parallelReset: ['parallelState'],
843
893
  parallelResetCounters: ['parallelState'],
@@ -924,6 +974,8 @@ export class GPURigidBodyWorld {
924
974
  }, allocate, Boolean(this.props.joints?.length), extended)
925
975
  : undefined;
926
976
  this.triggerEvents = triggers?.events ?? null;
977
+ if (triggers && triggerLayout)
978
+ this.triggerHistory = { buffer: triggers.history, groups: triggerLayout.groups };
927
979
  const passDescriptions = {
928
980
  integrate: 'Apply gravity and advance body velocities and predicted poses for this timestep.',
929
981
  prepare: 'Reset broad-phase counters before generating potential collider pairs.',
@@ -1091,7 +1143,7 @@ export class GPURigidBodyWorld {
1091
1143
  ? addEnsembleCheckpoint(graph, this.id, checkpointStates, { buffer: this.simulationStatistics, resource: statisticsResource }, bindings.find(binding => binding.name === 'ensemble'), bindings.find(binding => binding.name === 'manifolds'), this.props.ensembleBodiesPerInstance, this.maximumPairs, allocate, vehicleResource && {
1092
1144
  state: vehicleResource,
1093
1145
  vehiclesPerInstance: this.vehiclesPerInstance
1094
- })
1146
+ }, this.props.ensemblePairsPerInstance)
1095
1147
  : addRigidBodyCheckpoint(graph, this.id, [
1096
1148
  ...checkpointStates,
1097
1149
  bindings.find(binding => binding.name === 'manifolds'),
@@ -1502,7 +1554,12 @@ export class GPURigidBodyWorld {
1502
1554
  });
1503
1555
  restoreCheckpoint?.restore();
1504
1556
  if (this.ensembleBuffer)
1505
- addEnsembleStatus(graph, this.id, this.count / this.props.ensembleBodiesPerInstance, this.props.ensembleBodiesPerInstance, diagnosticBinding('bodies'), diagnosticBinding('sleepStates'), diagnosticBinding('ensemble'), { buffer: this.simulationStatistics, resource: statisticsResource });
1557
+ addEnsembleStatus(graph, this.id, this.count / this.props.ensembleBodiesPerInstance, this.props.ensembleBodiesPerInstance, diagnosticBinding('bodies'), diagnosticBinding('sleepStates'), diagnosticBinding('ensemble'), { buffer: this.simulationStatistics, resource: statisticsResource }, this.props.ensemblePairsPerInstance
1558
+ ? {
1559
+ ...diagnosticBinding('targets'),
1560
+ wordOffset: getEnsembleContactLayout(this.count, this.count / this.props.ensembleBodiesPerInstance, this.maximumPairs, true).failureOffset
1561
+ }
1562
+ : undefined);
1506
1563
  triggers?.publish();
1507
1564
  if (this.props.publicationBounds || this.props.publishPoses) {
1508
1565
  const publication = addRigidBodyPosePublication(graph, this.id, this.props.bodies, this.props.publicationBounds ??
@@ -1516,6 +1573,7 @@ export class GPURigidBodyWorld {
1516
1573
  }
1517
1574
  if (this.props.eventCapacity) {
1518
1575
  const contactHistory = allocate('contact-history', this.maximumPairs * 16);
1576
+ this.contactHistory = contactHistory;
1519
1577
  this.contactEvents = allocate('contact-events', 16 + this.props.eventCapacity * 64);
1520
1578
  const eventBindings = [
1521
1579
  ...bindings.filter(binding => ['bodies', 'manifolds', 'ensemble'].includes(binding.name)),
@@ -1541,40 +1599,23 @@ export class GPURigidBodyWorld {
1541
1599
  }, binding.buffer)
1542
1600
  }))
1543
1601
  ];
1544
- const properties = {
1602
+ /** The classify and scatter passes use the same committed manifold and history buffers. */
1603
+ const contactResources = eventBindings.map(({ name, resource, location }) => ({
1604
+ name,
1605
+ resource,
1606
+ location,
1607
+ readOnly: name === 'bodies' || name === 'eventStatistics'
1608
+ }));
1609
+ addRigidBodyEventCompaction(graph, {
1545
1610
  id: `${this.id}-contact-events`,
1611
+ rowCount: this.maximumPairs,
1612
+ capacity: this.props.eventCapacity,
1613
+ ring: 'contactEvents',
1546
1614
  source: source +
1547
- getRigidBodyEventShader(this.props.eventCapacity, this.props.impactImpulseThreshold ?? 1, this.props.failurePolicy === 'rollback'),
1548
- entryPoint: 'recordContacts',
1549
- shaderLayout: {
1550
- bindings: eventBindings.map(({ name, location }) => ({
1551
- name,
1552
- location,
1553
- group: 0,
1554
- type: ['bodies', 'eventStatistics'].includes(name)
1555
- ? 'read-only-storage'
1556
- : 'storage'
1557
- }))
1558
- }
1559
- };
1560
- const executable = (computation) => ({
1561
- encode: ({ computePass, getBuffer }) => {
1562
- Object.assign(computation.bindings, Object.fromEntries(eventBindings.map(binding => [binding.name, getBuffer(binding.resource)])));
1563
- computation.kernel.dispatch(computePass, { bindings: computation.bindings, x: 1 });
1564
- },
1565
- destroy: () => computation.kernel.destroy()
1566
- });
1567
- graph.addComputePass({
1568
- id: properties.id,
1569
- description: 'Compare contact history and publish contact begin, persist, and end events.',
1570
- resources: eventBindings.map(binding => ({
1571
- buffer: binding.resource,
1572
- usage: ['bodies', 'eventStatistics'].includes(binding.name)
1573
- ? 'storage-read'
1574
- : 'storage-read-write'
1575
- })),
1576
- compile: () => executable(createBoundKernel(graph.device, properties)),
1577
- compileAsync: async () => executable(await createBoundKernelAsync(graph.device, properties))
1615
+ getRigidBodyEventShader(this.props.eventCapacity, this.props.impactImpulseThreshold ?? 1, this.props.failurePolicy === 'rollback', this.props.ensemblePairsPerInstance),
1616
+ classify: contactResources.filter(binding => !['bodies', 'contactEvents'].includes(binding.name)),
1617
+ commit: contactResources.filter(binding => ['eventStatistics', 'contactEvents'].includes(binding.name)),
1618
+ publish: contactResources.filter(binding => !['eventStatistics', 'ensemble'].includes(binding.name))
1578
1619
  });
1579
1620
  }
1580
1621
  if (this.props.enableQueries) {
@@ -1615,6 +1656,46 @@ export class GPURigidBodyWorld {
1615
1656
  queryOutput: this.queryOutput
1616
1657
  }
1617
1658
  });
1659
+ if (this.props.queryBatchCapacity) {
1660
+ /** Fixed staging capacity keeps query dispatch independent of simulation allocations. */
1661
+ const capacity = this.props.queryBatchCapacity;
1662
+ this.batchCastCommands = allocate('query-batch-commands', capacity * RIGID_BODY_CAST_COMMAND_BYTES);
1663
+ this.batchCastResults = allocate('query-batch-results', capacity * RIGID_BODY_BATCH_RESULT_BYTES);
1664
+ /** Share external bindings between the scan and the indexed query graph. */
1665
+ const batchBindings = {
1666
+ positions: this.positions,
1667
+ orientations: this.orientations,
1668
+ bodies,
1669
+ querySelection: this.querySelection,
1670
+ batchCommands: this.batchCastCommands,
1671
+ batchResults: this.batchCastResults
1672
+ };
1673
+ /** Batch commands and results use storage bindings, shared by both strategies. */
1674
+ const batchLayout = [
1675
+ ...queryProperties.shaderLayout.bindings.filter(binding => ['positions', 'orientations', 'bodies', 'querySelection'].includes(binding.name)),
1676
+ { name: 'batchCommands', group: 0, location: 30, type: 'read-only-storage' },
1677
+ { name: 'batchResults', group: 0, location: 31, type: 'storage' }
1678
+ ];
1679
+ this.batchCast = createBoundKernel(graph.device, {
1680
+ id: `${this.id}-batched-casts`,
1681
+ entryPoint: 'castBatch',
1682
+ source: queryProperties.source + getRigidBodyBatchCastShader(),
1683
+ shaderLayout: { bindings: batchLayout },
1684
+ bindings: batchBindings
1685
+ });
1686
+ if (this.props.queryBatchIndex && this.colliderCount) {
1687
+ this.batchCastOrder = getRigidBodyCastOrder(this.colliders, this.props.bodies);
1688
+ if (this.batchCastOrder.indexedCount) {
1689
+ this.batchCastIndex = createRigidBodyCastIndex(graph.device, {
1690
+ id: `${this.id}-cast-index`,
1691
+ source: queryProperties.source,
1692
+ layout: batchLayout,
1693
+ buffers: batchBindings,
1694
+ indexedCount: this.batchCastOrder.indexedCount
1695
+ });
1696
+ }
1697
+ }
1698
+ }
1618
1699
  }
1619
1700
  this.controlSettings = allocate('control-settings', 64, true);
1620
1701
  const controlProperties = {
@@ -1753,7 +1834,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
1753
1834
  }
1754
1835
  /** Rebase between submissions, preserving velocities, contact impulses and sleeping state. */
1755
1836
  shiftOrigin(shift) {
1756
- if (!this.device || this.destroyed || this.queryPending || this.eventRead || this.triggerRead)
1837
+ if (!this.device || this.destroyed || this.queryPending || this.eventReadsPending)
1757
1838
  throw new Error('Origin shifting requires an idle attached world');
1758
1839
  // Exact float32 shifts keep the CPU origin and GPU subtraction consistent.
1759
1840
  if (shift.length !== 3 ||
@@ -1917,6 +1998,17 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
1917
1998
  metadata.write(data);
1918
1999
  this.props.publicationBounds = structuredClone(bounds);
1919
2000
  }
2001
+ /** Read the authored collider frame relative to its body's node origin, excluding COM offset. */
2002
+ getColliderTransform(colliderIndex) {
2003
+ /** This frame is metadata, so reading it does not synchronize the device. */
2004
+ const collider = this.colliders[colliderIndex];
2005
+ if (!Number.isInteger(colliderIndex) || !collider || this.destroyed)
2006
+ throw new Error('Invalid collider');
2007
+ return {
2008
+ position: [...(collider.position ?? [0, 0, 0])],
2009
+ orientation: normalizeRigidBodyRotation(collider.orientation)
2010
+ };
2011
+ }
1920
2012
  /** Applied scale relative to the initially cooked analytic shape. */
1921
2013
  getColliderShapeScale(colliderIndex) {
1922
2014
  this.getColliderShape(colliderIndex);
@@ -1991,7 +2083,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
1991
2083
  if (!edits.length)
1992
2084
  return;
1993
2085
  const metadata = this.ownedBuffers.find(buffer => buffer.id === `${this.id}-bodies`);
1994
- if (!metadata || this.destroyed || this.queryPending || this.eventRead || this.triggerRead)
2086
+ if (!metadata || this.destroyed || this.queryPending || this.eventReadsPending)
1995
2087
  throw new Error('Terrain streaming requires an idle attached world');
1996
2088
  const seen = new Set();
1997
2089
  const packedFields = this.terrainAtlas
@@ -2319,6 +2411,82 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2319
2411
  throw new Error('Invalid joint');
2320
2412
  return structuredClone(joint);
2321
2413
  }
2414
+ /** Command a named angular force drive. Angles are radians and maximum torque is N·m. */
2415
+ setAngularActuator(id, axis, command) {
2416
+ const index = this.findAngularActuator(id, axis);
2417
+ const joint = this.props.joints[index];
2418
+ if (joint.type !== 'general' || !joint.drive)
2419
+ throw new Error('Expected angular drive');
2420
+ if (command.stiffness === undefined &&
2421
+ command.damping === undefined &&
2422
+ command.maximumTorque === undefined) {
2423
+ this.setAngularDriveTargets(new Map([[index, command.angle]]));
2424
+ return;
2425
+ }
2426
+ this.setJointParameters(index, {
2427
+ ...joint,
2428
+ drive: {
2429
+ ...joint.drive,
2430
+ positionTarget: command.angle,
2431
+ stiffness: command.stiffness ?? joint.drive.stiffness,
2432
+ damping: command.damping ?? joint.drive.damping,
2433
+ maximumForce: command.maximumTorque ?? joint.drive.maximumForce
2434
+ }
2435
+ });
2436
+ }
2437
+ /** Read the signed mean motor torque from the most recently submitted step. */
2438
+ async readAngularActuatorTorque(id, axis) {
2439
+ const index = this.findAngularActuator(id, axis);
2440
+ if (!this.targets || this.destroyed)
2441
+ throw new Error('Inactive world');
2442
+ const bytes = await this.targets.readAsync(this.getJointStateOffset() + index * RIGID_BODY_JOINT_STATE_BYTES, 4);
2443
+ return new DataView(bytes.buffer, bytes.byteOffset, 4).getFloat32(0, true) / this.timeStep;
2444
+ }
2445
+ findAngularActuator(id, axis) {
2446
+ const indices = (this.props.joints ?? []).flatMap((joint, index) => joint.id === id &&
2447
+ joint.type === 'general' &&
2448
+ joint.angular &&
2449
+ joint.drive &&
2450
+ joint.drive.mode !== 'acceleration' &&
2451
+ joint.axes[0] === axis
2452
+ ? [index]
2453
+ : []);
2454
+ if (indices.length !== 1)
2455
+ throw new Error('Missing or ambiguous angular force drive');
2456
+ return indices[0];
2457
+ }
2458
+ /** Retarget authored angular drive rows between steps while preserving the other joints' settings. */
2459
+ setAngularDriveTargets(targets) {
2460
+ /** Validate the entire batch before publishing writes to the GPU. */
2461
+ const joints = [...(this.props.joints ?? [])];
2462
+ if (!this.targets || !this.sleepStates || this.destroyed)
2463
+ throw new Error('Inactive world');
2464
+ for (const [index, angle] of targets) {
2465
+ const joint = joints[index];
2466
+ if (joint?.type !== 'general' ||
2467
+ !joint.angular ||
2468
+ !joint.drive ||
2469
+ !Number.isFinite(Math.fround(angle))) {
2470
+ throw new Error('Invalid angular drive target');
2471
+ }
2472
+ if (Math.fround(joint.drive.positionTarget ?? 0) === Math.fround(angle))
2473
+ continue;
2474
+ joints[index] = { ...joint, drive: { ...joint.drive, positionTarget: angle } };
2475
+ }
2476
+ const drivenBodies = new Set();
2477
+ for (const [index, angle] of targets) {
2478
+ if (joints[index] === this.props.joints?.[index])
2479
+ continue;
2480
+ drivenBodies.add(joints[index].first);
2481
+ drivenBodies.add(joints[index].second);
2482
+ // Word 40 is general.drive.x in packRigidBodyJointState.
2483
+ this.targets.write(new Float32Array([angle]), this.getJointStateOffset() + index * RIGID_BODY_JOINT_STATE_BYTES + 40 * 4);
2484
+ }
2485
+ this.props.joints = joints;
2486
+ // Wake the endpoints while preserving warm starts for contacts already at rest.
2487
+ for (const body of drivenBodies)
2488
+ this.sleepStates.write(new Float32Array(2), body * 16);
2489
+ }
2322
2490
  /** Update an existing constraint's response without recompiling or changing attachment topology. */
2323
2491
  setJointParameters(index, parameters) {
2324
2492
  this.setJointParameterEdits([{ index, parameters }]);
@@ -2387,18 +2555,29 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2387
2555
  readContactEvents() {
2388
2556
  if (!this.contactEvents || this.destroyed)
2389
2557
  return Promise.reject(new Error('Contact events are not enabled'));
2390
- if (!this.eventRead)
2391
- this.eventRead = this.contactEvents
2558
+ /** Queue the copy now, then decode only after any preceding recovery sets the cursor. */
2559
+ const afterSnapshot = this.contactSnapshotRead;
2560
+ if (this.eventRead && (!afterSnapshot || this.eventRead.afterSnapshot === afterSnapshot))
2561
+ return this.eventRead.result;
2562
+ /** Register the read before recovery can clear its own busy flag. */
2563
+ const pending = {
2564
+ afterSnapshot,
2565
+ result: this.contactEvents
2392
2566
  .readAsync()
2567
+ .finally(() => afterSnapshot)
2393
2568
  .then(bytes => {
2569
+ /** The newest stream cursor is available once the preceding snapshot resolves. */
2394
2570
  const batch = decodeRigidBodyContactEvents(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), this.eventCursor);
2395
2571
  this.eventCursor = batch.sequence;
2396
2572
  return batch;
2397
2573
  })
2398
2574
  .finally(() => {
2399
- this.eventRead = null;
2400
- });
2401
- return this.eventRead;
2575
+ if (this.eventRead === pending)
2576
+ this.eventRead = null;
2577
+ })
2578
+ };
2579
+ this.eventRead = pending;
2580
+ return pending.result;
2402
2581
  }
2403
2582
  /** Nearest exact sphere/OBB hit. Origins inside a shape return distance zero and a zero normal. */
2404
2583
  raycast(query) {
@@ -2408,6 +2587,74 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2408
2587
  overlapSphere(query) {
2409
2588
  return this.runQuery(query);
2410
2589
  }
2590
+ /**
2591
+ * Query the closest hit for each ray or sphere cast with one submission and readback.
2592
+ * Results follow input order. This snapshots already submitted poses, using one shared collider selection.
2593
+ */
2594
+ async castBatch(commands, options = {}) {
2595
+ if (!this.device ||
2596
+ !this.batchCast ||
2597
+ !this.querySelection ||
2598
+ !this.batchCastCommands ||
2599
+ !this.batchCastResults ||
2600
+ this.destroyed ||
2601
+ this.queryPending)
2602
+ throw new Error('Batched collision casts are disabled or busy');
2603
+ if (commands.length > this.props.queryBatchCapacity)
2604
+ throw new Error('Collision cast batch exceeds capacity');
2605
+ if (!commands.length)
2606
+ return [];
2607
+ if (options.strategy === 'indexed' && !this.props.queryBatchIndex)
2608
+ throw new Error('Batched collision cast index is disabled');
2609
+ /** The scan remains available for short or dense workloads and reference comparisons. */
2610
+ const order = options.strategy === 'scan' ? null : this.batchCastOrder;
2611
+ /** Deduplicate the shared selection before publishing any GPU input. */
2612
+ const selection = options.colliderIndices
2613
+ ? Uint32Array.from(new Set(this.validateQueryColliders(options.colliderIndices)))
2614
+ : (order?.indices ?? Uint32Array.from({ length: this.colliderCount }, (_, index) => index));
2615
+ /** The indexed prefix can be empty when a filter selects only extended geometry. */
2616
+ let indexedCount = order?.indexedCount ?? 0;
2617
+ if (order && options.colliderIndices) {
2618
+ selection.sort((first, second) => order.ranks[first] - order.ranks[second]);
2619
+ /** All selected primitives precede the extended collider fallback. */
2620
+ const firstExtended = selection.findIndex(index => order.ranks[index] >= order.indexedCount);
2621
+ indexedCount = firstExtended < 0 ? selection.length : firstExtended;
2622
+ }
2623
+ /** Validate and encode all commands before changing staging data. */
2624
+ const data = packRigidBodyBatchCasts(commands, this.count, selection.length, indexedCount);
2625
+ this.queryPending = true;
2626
+ try {
2627
+ this.batchCastCommands.write(data);
2628
+ if (selection.length)
2629
+ this.querySelection.write(selection);
2630
+ /** Submit after any preceding pose changes in device queue order. */
2631
+ const encoder = this.device.createCommandEncoder();
2632
+ if (this.batchCastIndex && indexedCount) {
2633
+ this.batchCastIndex.encode(encoder, { parameters: commands.length });
2634
+ }
2635
+ else {
2636
+ /** One workgroup handles one command and reduces its collider results locally. */
2637
+ const pass = encoder.beginComputePass();
2638
+ this.batchCast.kernel.dispatch(pass, {
2639
+ bindings: this.batchCast.bindings,
2640
+ x: commands.length
2641
+ });
2642
+ pass.end();
2643
+ }
2644
+ this.device.submit(encoder.finish());
2645
+ return decodeRigidBodyBatchCasts(await this.batchCastResults.readAsync(0, commands.length * RIGID_BODY_BATCH_RESULT_BYTES));
2646
+ }
2647
+ finally {
2648
+ this.queryPending = false;
2649
+ }
2650
+ }
2651
+ /** Reject invalid indices before scalar or batch query buffers are written. */
2652
+ validateQueryColliders(indices) {
2653
+ for (const index of indices)
2654
+ if (!Number.isInteger(index) || index < 0 || index >= this.colliderCount)
2655
+ throw new Error('Invalid query collider');
2656
+ return indices;
2657
+ }
2411
2658
  async runQuery(query) {
2412
2659
  if (!this.device ||
2413
2660
  !this.queryComputation ||
@@ -2444,9 +2691,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2444
2691
  throw new Error('Invalid collision query');
2445
2692
  const selected = query.colliderIndices ?? Array.from({ length: this.colliderCount }, (_, index) => index);
2446
2693
  const selection = new Uint32Array(this.colliderStorageCount);
2447
- for (const index of selected) {
2448
- if (!Number.isInteger(index) || index < 0 || index >= this.colliderCount)
2449
- throw new Error('Invalid query collider');
2694
+ for (const index of this.validateQueryColliders(selected)) {
2450
2695
  const collider = this.colliders[index];
2451
2696
  if (collider.body === query.excludeBody)
2452
2697
  continue;
@@ -2476,16 +2721,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2476
2721
  const bytes = await this.queryOutput.readAsync(0, 16 + maximumHits * 48);
2477
2722
  const words = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
2478
2723
  const floats = new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
2479
- const hits = Array.from({ length: words[0] }, (_, index) => {
2480
- const offset = 4 + index * 12;
2481
- return {
2482
- body: words[offset],
2483
- collider: words[offset + 1],
2484
- point: [floats[offset + 4], floats[offset + 5], floats[offset + 6]],
2485
- distance: floats[offset + 7],
2486
- normal: [floats[offset + 8], floats[offset + 9], floats[offset + 10]]
2487
- };
2488
- });
2724
+ const hits = Array.from({ length: words[0] }, (_, index) => decodeRigidBodyQueryHit(words, floats, 4 + index * 12));
2489
2725
  return {
2490
2726
  hits,
2491
2727
  totalHits: words[1],
@@ -2536,19 +2772,107 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2536
2772
  readTriggerEvents() {
2537
2773
  if (!this.triggerEvents || this.destroyed)
2538
2774
  throw new Error('Triggers are disabled');
2539
- if (this.triggerRead)
2540
- return this.triggerRead;
2541
- this.triggerRead = this.triggerEvents
2542
- .readAsync()
2543
- .then(bytes => {
2544
- const batch = decodeRigidBodyTriggerEvents(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), this.triggerCursor);
2545
- this.triggerCursor = batch.sequence;
2546
- return batch;
2775
+ /** Queue the copy in caller order, including when recovery is still mapping. */
2776
+ const afterSnapshot = this.triggerSnapshotRead;
2777
+ if (this.triggerRead && (!afterSnapshot || this.triggerRead.afterSnapshot === afterSnapshot))
2778
+ return this.triggerRead.result;
2779
+ /** Track the read immediately so checkpoint operations see a busy world. */
2780
+ const pending = {
2781
+ afterSnapshot,
2782
+ result: this.triggerEvents
2783
+ .readAsync()
2784
+ .finally(() => afterSnapshot)
2785
+ .then(bytes => {
2786
+ /** The snapshot has established the sequence used to decode this delta. */
2787
+ const batch = decodeRigidBodyTriggerEvents(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), this.triggerCursor);
2788
+ this.triggerCursor = batch.sequence;
2789
+ return batch;
2790
+ })
2791
+ .finally(() => {
2792
+ if (this.triggerRead === pending)
2793
+ this.triggerRead = null;
2794
+ })
2795
+ };
2796
+ this.triggerRead = pending;
2797
+ return pending.result;
2798
+ }
2799
+ /** Recover the active contact set and advance the incremental cursor to the snapshot. */
2800
+ resyncContactEvents() {
2801
+ if (!this.device || !this.contactEvents || !this.contactHistory || this.destroyed)
2802
+ return Promise.reject(new Error('Contact events are not enabled'));
2803
+ if (this.contactSnapshotRead)
2804
+ return this.contactSnapshotRead;
2805
+ /** An earlier incremental read may still be advancing its cursor. */
2806
+ const priorRead = this.eventRead?.result.catch(() => undefined);
2807
+ /** Capture immediately, even when a previous delta read is still mapping. */
2808
+ const snapshot = readRigidBodyEventSnapshot(this.device, this.contactEvents, this.contactHistory, (header, rows) => {
2809
+ /** The retained history contains active pairs, independent of event retention. */
2810
+ const contacts = [];
2811
+ for (let offset = 0; offset < rows.length; offset += 4) {
2812
+ if (rows[offset + 2] === 0)
2813
+ continue;
2814
+ /** A contact history row stores the two original collider IDs. */
2815
+ const first = rows[offset];
2816
+ /** Compound collider IDs map back to their owning bodies. */
2817
+ const second = rows[offset + 1];
2818
+ contacts.push({
2819
+ colliders: [first, second],
2820
+ bodies: [this.colliders[first].body, this.colliders[second].body]
2821
+ });
2822
+ }
2823
+ return { ...header, contacts };
2824
+ });
2825
+ this.contactSnapshotRead = snapshot
2826
+ .finally(() => priorRead)
2827
+ .then(result => {
2828
+ this.eventCursor = result.sequence;
2829
+ return result;
2547
2830
  })
2548
2831
  .finally(() => {
2549
- this.triggerRead = null;
2832
+ this.contactSnapshotRead = null;
2550
2833
  });
2551
- return this.triggerRead;
2834
+ return this.contactSnapshotRead;
2835
+ }
2836
+ /** Recover the active trigger overlap set and advance the incremental trigger cursor. */
2837
+ resyncTriggerEvents() {
2838
+ if (!this.device || !this.triggerEvents || !this.triggerHistory || this.destroyed)
2839
+ return Promise.reject(new Error('Triggers are disabled'));
2840
+ if (this.triggerSnapshotRead)
2841
+ return this.triggerSnapshotRead;
2842
+ /** Preserve authored trigger and target-body identities alongside the sampled pairs. */
2843
+ const { buffer, groups } = this.triggerHistory;
2844
+ /** Wait for prior cursor updates before replacing them with the new recovery point. */
2845
+ const priorRead = this.triggerRead?.result.catch(() => undefined);
2846
+ /** Read only the history bit and representative collider pair for each group. */
2847
+ const snapshot = readRigidBodyEventSnapshot(this.device, this.triggerEvents, buffer, (header, rows) => {
2848
+ /** Swept crossings with no final overlap are absent from this state. */
2849
+ const overlaps = [];
2850
+ for (let offset = 0; offset < rows.length; offset += 4) {
2851
+ if ((rows[offset] & 1) === 0)
2852
+ continue;
2853
+ overlaps.push({
2854
+ trigger: groups[offset],
2855
+ body: groups[offset + 1],
2856
+ triggerCollider: rows[offset + 1],
2857
+ collider: rows[offset + 2]
2858
+ });
2859
+ }
2860
+ return { ...header, overlaps };
2861
+ });
2862
+ this.triggerSnapshotRead = snapshot
2863
+ .finally(() => priorRead)
2864
+ .then(result => {
2865
+ this.triggerCursor = result.sequence;
2866
+ return result;
2867
+ })
2868
+ .finally(() => {
2869
+ this.triggerSnapshotRead = null;
2870
+ });
2871
+ return this.triggerSnapshotRead;
2872
+ }
2873
+ /** Reset, capture and origin operations require stable event cursors. */
2874
+ get eventReadsPending() {
2875
+ return Boolean(this.eventRead || this.triggerRead || this.contactSnapshotRead || this.triggerSnapshotRead);
2552
2876
  }
2553
2877
  getSnapshotBuffers(includeRollbackScratch = true) {
2554
2878
  return this.ownedBuffers.filter(buffer => includeRollbackScratch || !buffer.id.startsWith(`${this.id}-checkpoint-`));
@@ -2584,7 +2908,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2584
2908
  throw error;
2585
2909
  }
2586
2910
  const copy = (restore) => {
2587
- if (released || this.destroyed || this.queryPending || this.eventRead || this.triggerRead)
2911
+ if (released || this.destroyed || this.queryPending || this.eventReadsPending)
2588
2912
  throw new Error('Checkpoint requires an idle live world');
2589
2913
  const encoder = device.createCommandEncoder();
2590
2914
  for (const [index, buffer] of checkpointBuffers.entries())
@@ -2642,7 +2966,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2642
2966
  }
2643
2967
  /** Stop graph submissions and controls first; includes diagnostics, caches and event history. */
2644
2968
  async captureState(options = {}) {
2645
- if (!this.device || this.destroyed || this.queryPending || this.eventRead || this.triggerRead)
2969
+ if (!this.device || this.destroyed || this.queryPending || this.eventReadsPending)
2646
2970
  throw new Error('Capture requires an idle attached world');
2647
2971
  return {
2648
2972
  version: 1,
@@ -2667,8 +2991,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2667
2991
  if (!this.device ||
2668
2992
  this.destroyed ||
2669
2993
  this.queryPending ||
2670
- this.eventRead ||
2671
- this.triggerRead ||
2994
+ this.eventReadsPending ||
2672
2995
  capture.version !== 1 ||
2673
2996
  Boolean(capture.terrainAtlasLeases) !== Boolean(this.terrainAtlas) ||
2674
2997
  !Number.isInteger(terrainRevision) ||
@@ -2833,6 +3156,8 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
2833
3156
  this.terrainWake?.kernel.destroy();
2834
3157
  this.queryComputation?.kernel.destroy();
2835
3158
  this.queryReduction?.kernel.destroy();
3159
+ this.batchCastIndex?.destroy();
3160
+ this.batchCast?.kernel.destroy();
2836
3161
  for (const buffer of this.ownedBuffers)
2837
3162
  buffer.destroy();
2838
3163
  this.ownedBuffers.length = 0;