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

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 (258) 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 +24 -1
  12. package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +10 -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 +29 -1
  15. package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -1
  16. package/dist/arrow/index.cjs +2 -0
  17. package/dist/arrow/index.cjs.map +3 -3
  18. package/dist/arrow/index.d.ts +1 -1
  19. package/dist/arrow/index.d.ts.map +1 -1
  20. package/dist/arrow/index.js +1 -1
  21. package/dist/arrow/index.js.map +1 -1
  22. package/dist/gpu-core/gpu-bvh-bounds.cjs +63 -0
  23. package/dist/gpu-core/gpu-bvh-bounds.d.ts +32 -0
  24. package/dist/gpu-core/gpu-bvh-bounds.d.ts.map +1 -0
  25. package/dist/gpu-core/gpu-bvh-bounds.js +56 -0
  26. package/dist/gpu-core/gpu-bvh-bounds.js.map +1 -0
  27. package/dist/gpu-core/gpu-command-graph-submission-pacer.cjs +92 -0
  28. package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts +41 -0
  29. package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts.map +1 -0
  30. package/dist/gpu-core/gpu-command-graph-submission-pacer.js +85 -0
  31. package/dist/gpu-core/gpu-command-graph-submission-pacer.js.map +1 -0
  32. package/dist/gpu-core/index.cjs +6 -0
  33. package/dist/gpu-core/index.cjs.map +3 -3
  34. package/dist/gpu-core/index.d.ts +4 -0
  35. package/dist/gpu-core/index.d.ts.map +1 -1
  36. package/dist/gpu-core/index.js +2 -0
  37. package/dist/gpu-core/index.js.map +1 -1
  38. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.cjs +6 -6
  39. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts +1 -1
  40. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts.map +1 -1
  41. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js +6 -6
  42. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js.map +1 -1
  43. package/dist/gpu-dataframe/gpu-data-frame-query.cjs +55 -14
  44. package/dist/gpu-dataframe/gpu-data-frame-query.d.ts +13 -2
  45. package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
  46. package/dist/gpu-dataframe/gpu-data-frame-query.js +58 -17
  47. package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
  48. package/dist/gpu-dataframe/gpu-data-frame.cjs +1 -3
  49. package/dist/gpu-dataframe/gpu-data-frame.d.ts +10 -0
  50. package/dist/gpu-dataframe/gpu-data-frame.d.ts.map +1 -1
  51. package/dist/gpu-dataframe/gpu-data-frame.js +1 -3
  52. package/dist/gpu-dataframe/gpu-data-frame.js.map +1 -1
  53. package/dist/gpu-dataframe/gpu-expression-shader.cjs +94 -44
  54. package/dist/gpu-dataframe/gpu-expression-shader.d.ts +8 -5
  55. package/dist/gpu-dataframe/gpu-expression-shader.d.ts.map +1 -1
  56. package/dist/gpu-dataframe/gpu-expression-shader.js +110 -47
  57. package/dist/gpu-dataframe/gpu-expression-shader.js.map +1 -1
  58. package/dist/gpu-dataframe/gpu-expression.cjs +14 -8
  59. package/dist/gpu-dataframe/gpu-expression.d.ts +12 -1
  60. package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
  61. package/dist/gpu-dataframe/gpu-expression.js +11 -6
  62. package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
  63. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +2 -2
  64. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
  65. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +4 -2
  66. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js.map +1 -1
  67. package/dist/gpu-dataframe/gpu-global-aggregation-query.cjs +2 -2
  68. package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts +5 -1
  69. package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts.map +1 -1
  70. package/dist/gpu-dataframe/gpu-global-aggregation-query.js +6 -2
  71. package/dist/gpu-dataframe/gpu-global-aggregation-query.js.map +1 -1
  72. package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +113 -88
  73. package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +6 -1
  74. package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
  75. package/dist/gpu-dataframe/gpu-global-sort-compiler.js +111 -85
  76. package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
  77. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +286 -48
  78. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts +17 -2
  79. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
  80. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +290 -39
  81. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
  82. package/dist/gpu-dataframe/gpu-group-by-query.cjs +8 -6
  83. package/dist/gpu-dataframe/gpu-group-by-query.d.ts +7 -1
  84. package/dist/gpu-dataframe/gpu-group-by-query.d.ts.map +1 -1
  85. package/dist/gpu-dataframe/gpu-group-by-query.js +9 -5
  86. package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
  87. package/dist/gpu-dataframe/gpu-join-compiler.cjs +8 -6
  88. package/dist/gpu-dataframe/gpu-join-compiler.d.ts +1 -1
  89. package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
  90. package/dist/gpu-dataframe/gpu-join-compiler.js +9 -7
  91. package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
  92. package/dist/gpu-dataframe/gpu-query-compiler.cjs +37 -11
  93. package/dist/gpu-dataframe/gpu-query-compiler.d.ts +3 -1
  94. package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
  95. package/dist/gpu-dataframe/gpu-query-compiler.js +36 -10
  96. package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
  97. package/dist/gpu-dataframe/index.cjs +4 -2
  98. package/dist/gpu-dataframe/index.cjs.map +3 -3
  99. package/dist/gpu-dataframe/index.d.ts +1 -1
  100. package/dist/gpu-dataframe/index.d.ts.map +1 -1
  101. package/dist/gpu-dataframe/index.js +1 -1
  102. package/dist/gpu-dataframe/index.js.map +1 -1
  103. package/dist/gpu-physics/gpu-physics-batch.cjs +11 -10
  104. package/dist/gpu-physics/gpu-physics-batch.d.ts +1 -0
  105. package/dist/gpu-physics/gpu-physics-batch.d.ts.map +1 -1
  106. package/dist/gpu-physics/gpu-physics-batch.js +14 -10
  107. package/dist/gpu-physics/gpu-physics-batch.js.map +1 -1
  108. package/dist/gpu-physics/gpu-physics-ensemble.cjs +9 -4
  109. package/dist/gpu-physics/gpu-physics-ensemble.d.ts +10 -1
  110. package/dist/gpu-physics/gpu-physics-ensemble.d.ts.map +1 -1
  111. package/dist/gpu-physics/gpu-physics-ensemble.js +11 -4
  112. package/dist/gpu-physics/gpu-physics-ensemble.js.map +1 -1
  113. package/dist/gpu-physics/gpu-rigid-body-world.cjs +261 -68
  114. package/dist/gpu-physics/gpu-rigid-body-world.d.ts +47 -2
  115. package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
  116. package/dist/gpu-physics/gpu-rigid-body-world.js +324 -75
  117. package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
  118. package/dist/gpu-physics/index.cjs.map +3 -3
  119. package/dist/gpu-physics/index.d.ts +2 -1
  120. package/dist/gpu-physics/index.d.ts.map +1 -1
  121. package/dist/gpu-physics/index.js.map +1 -1
  122. package/dist/gpu-physics/rigid-body-cache-shaders.cjs +10 -6
  123. package/dist/gpu-physics/rigid-body-cache-shaders.d.ts +2 -1
  124. package/dist/gpu-physics/rigid-body-cache-shaders.d.ts.map +1 -1
  125. package/dist/gpu-physics/rigid-body-cache-shaders.js +15 -6
  126. package/dist/gpu-physics/rigid-body-cache-shaders.js.map +1 -1
  127. package/dist/gpu-physics/rigid-body-capacity.cjs +15 -2
  128. package/dist/gpu-physics/rigid-body-capacity.d.ts +3 -1
  129. package/dist/gpu-physics/rigid-body-capacity.d.ts.map +1 -1
  130. package/dist/gpu-physics/rigid-body-capacity.js +21 -2
  131. package/dist/gpu-physics/rigid-body-capacity.js.map +1 -1
  132. package/dist/gpu-physics/rigid-body-cast-index.cjs +192 -0
  133. package/dist/gpu-physics/rigid-body-cast-index.d.ts +44 -0
  134. package/dist/gpu-physics/rigid-body-cast-index.d.ts.map +1 -0
  135. package/dist/gpu-physics/rigid-body-cast-index.js +194 -0
  136. package/dist/gpu-physics/rigid-body-cast-index.js.map +1 -0
  137. package/dist/gpu-physics/rigid-body-ensemble-layout.cjs +4 -2
  138. package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts +2 -1
  139. package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts.map +1 -1
  140. package/dist/gpu-physics/rigid-body-ensemble-layout.js +5 -2
  141. package/dist/gpu-physics/rigid-body-ensemble-layout.js.map +1 -1
  142. package/dist/gpu-physics/rigid-body-ensemble-reset.cjs +11 -9
  143. package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts +1 -1
  144. package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts.map +1 -1
  145. package/dist/gpu-physics/rigid-body-ensemble-reset.js +13 -9
  146. package/dist/gpu-physics/rigid-body-ensemble-reset.js.map +1 -1
  147. package/dist/gpu-physics/rigid-body-ensemble-shaders.cjs +14 -7
  148. package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts +5 -0
  149. package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts.map +1 -1
  150. package/dist/gpu-physics/rigid-body-ensemble-shaders.js +17 -7
  151. package/dist/gpu-physics/rigid-body-ensemble-shaders.js.map +1 -1
  152. package/dist/gpu-physics/rigid-body-ensemble-transaction.cjs +21 -11
  153. package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts +2 -2
  154. package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts.map +1 -1
  155. package/dist/gpu-physics/rigid-body-ensemble-transaction.js +28 -12
  156. package/dist/gpu-physics/rigid-body-ensemble-transaction.js.map +1 -1
  157. package/dist/gpu-physics/rigid-body-event-compaction.cjs +184 -0
  158. package/dist/gpu-physics/rigid-body-event-compaction.d.ts +35 -0
  159. package/dist/gpu-physics/rigid-body-event-compaction.d.ts.map +1 -0
  160. package/dist/gpu-physics/rigid-body-event-compaction.js +168 -0
  161. package/dist/gpu-physics/rigid-body-event-compaction.js.map +1 -0
  162. package/dist/gpu-physics/rigid-body-event-snapshot.cjs +51 -0
  163. package/dist/gpu-physics/rigid-body-event-snapshot.d.ts +33 -0
  164. package/dist/gpu-physics/rigid-body-event-snapshot.d.ts.map +1 -0
  165. package/dist/gpu-physics/rigid-body-event-snapshot.js +34 -0
  166. package/dist/gpu-physics/rigid-body-event-snapshot.js.map +1 -0
  167. package/dist/gpu-physics/rigid-body-events.cjs +57 -25
  168. package/dist/gpu-physics/rigid-body-events.d.ts +2 -1
  169. package/dist/gpu-physics/rigid-body-events.d.ts.map +1 -1
  170. package/dist/gpu-physics/rigid-body-events.js +60 -25
  171. package/dist/gpu-physics/rigid-body-events.js.map +1 -1
  172. package/dist/gpu-physics/rigid-body-joints.cjs +8 -3
  173. package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
  174. package/dist/gpu-physics/rigid-body-joints.js +10 -6
  175. package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
  176. package/dist/gpu-physics/rigid-body-queries.cjs +159 -16
  177. package/dist/gpu-physics/rigid-body-queries.d.ts +24 -1
  178. package/dist/gpu-physics/rigid-body-queries.d.ts.map +1 -1
  179. package/dist/gpu-physics/rigid-body-queries.js +166 -14
  180. package/dist/gpu-physics/rigid-body-queries.js.map +1 -1
  181. package/dist/gpu-physics/rigid-body-shaders.cjs +3 -3
  182. package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
  183. package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
  184. package/dist/gpu-physics/rigid-body-shaders.js +3 -3
  185. package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
  186. package/dist/gpu-physics/rigid-body-triggers.cjs +53 -15
  187. package/dist/gpu-physics/rigid-body-triggers.d.ts +1 -0
  188. package/dist/gpu-physics/rigid-body-triggers.d.ts.map +1 -1
  189. package/dist/gpu-physics/rigid-body-triggers.js +55 -15
  190. package/dist/gpu-physics/rigid-body-triggers.js.map +1 -1
  191. package/dist/gpu-physics/sphere-world-shaders.cjs +48 -20
  192. package/dist/gpu-physics/sphere-world-shaders.d.ts.map +1 -1
  193. package/dist/gpu-physics/sphere-world-shaders.js +51 -21
  194. package/dist/gpu-physics/sphere-world-shaders.js.map +1 -1
  195. package/dist/gpu-project/benchmarks.cjs.map +2 -2
  196. package/dist/gpu-project/crs.cjs.map +2 -2
  197. package/dist/gpu-project/index.cjs.map +2 -2
  198. package/dist/gpu-project/projection-program.cjs +2 -9
  199. package/dist/gpu-project/projection-program.d.ts.map +1 -1
  200. package/dist/gpu-project/projection-program.js +1 -8
  201. package/dist/gpu-project/projection-program.js.map +1 -1
  202. package/dist/gpu-sql/gpu-sql.cjs +203 -59
  203. package/dist/gpu-sql/gpu-sql.d.ts +36 -1
  204. package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
  205. package/dist/gpu-sql/gpu-sql.js +225 -62
  206. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  207. package/dist/gpu-sql/index.cjs.map +3 -3
  208. package/dist/gpu-sql/index.d.ts +1 -1
  209. package/dist/gpu-sql/index.d.ts.map +1 -1
  210. package/dist/utils/float32.cjs +35 -0
  211. package/dist/utils/float32.d.ts +3 -0
  212. package/dist/utils/float32.d.ts.map +1 -0
  213. package/dist/utils/float32.js +16 -0
  214. package/dist/utils/float32.js.map +1 -0
  215. package/package.json +4 -4
  216. package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +77 -25
  217. package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +52 -16
  218. package/src/arrow/gpu/arrow-gpu-table-conversion.ts +46 -1
  219. package/src/arrow/index.ts +1 -0
  220. package/src/gpu-core/gpu-bvh-bounds.ts +84 -0
  221. package/src/gpu-core/gpu-command-graph-submission-pacer.ts +102 -0
  222. package/src/gpu-core/index.ts +5 -0
  223. package/src/gpu-dataframe/gpu-analytics-compiler-utils.ts +7 -10
  224. package/src/gpu-dataframe/gpu-data-frame-query.ts +106 -25
  225. package/src/gpu-dataframe/gpu-data-frame.ts +35 -2
  226. package/src/gpu-dataframe/gpu-expression-shader.ts +172 -58
  227. package/src/gpu-dataframe/gpu-expression.ts +62 -9
  228. package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +6 -2
  229. package/src/gpu-dataframe/gpu-global-aggregation-query.ts +12 -3
  230. package/src/gpu-dataframe/gpu-global-sort-compiler.ts +151 -93
  231. package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +469 -52
  232. package/src/gpu-dataframe/gpu-group-by-query.ts +24 -10
  233. package/src/gpu-dataframe/gpu-join-compiler.ts +12 -6
  234. package/src/gpu-dataframe/gpu-query-compiler.ts +60 -18
  235. package/src/gpu-dataframe/index.ts +1 -1
  236. package/src/gpu-physics/gpu-physics-batch.ts +19 -13
  237. package/src/gpu-physics/gpu-physics-ensemble.ts +20 -4
  238. package/src/gpu-physics/gpu-rigid-body-world.ts +421 -93
  239. package/src/gpu-physics/index.ts +9 -0
  240. package/src/gpu-physics/rigid-body-cache-shaders.ts +18 -6
  241. package/src/gpu-physics/rigid-body-capacity.ts +25 -4
  242. package/src/gpu-physics/rigid-body-cast-index.ts +277 -0
  243. package/src/gpu-physics/rigid-body-ensemble-layout.ts +6 -2
  244. package/src/gpu-physics/rigid-body-ensemble-reset.ts +21 -9
  245. package/src/gpu-physics/rigid-body-ensemble-shaders.ts +18 -7
  246. package/src/gpu-physics/rigid-body-ensemble-transaction.ts +31 -13
  247. package/src/gpu-physics/rigid-body-event-compaction.ts +252 -0
  248. package/src/gpu-physics/rigid-body-event-snapshot.ts +76 -0
  249. package/src/gpu-physics/rigid-body-events.ts +63 -25
  250. package/src/gpu-physics/rigid-body-joints.ts +9 -11
  251. package/src/gpu-physics/rigid-body-queries.ts +202 -14
  252. package/src/gpu-physics/rigid-body-shaders.ts +4 -3
  253. package/src/gpu-physics/rigid-body-triggers.ts +64 -20
  254. package/src/gpu-physics/sphere-world-shaders.ts +53 -21
  255. package/src/gpu-project/projection-program.ts +1 -9
  256. package/src/gpu-sql/gpu-sql.ts +405 -91
  257. package/src/gpu-sql/index.ts +1 -1
  258. package/src/utils/float32.ts +16 -0
@@ -94,6 +94,8 @@ export type {
94
94
  GPURigidBodySphereCastQuery,
95
95
  GPURigidBodyOverlapQuery,
96
96
  GPURigidBodyQueryFilter,
97
+ GPURigidBodyBatchCast,
98
+ GPURigidBodyBatchCastOptions,
97
99
  GPURigidBodyQueryHit,
98
100
  GPURigidBodyQueryResult
99
101
  } from './rigid-body-queries';
@@ -105,6 +107,13 @@ export type {
105
107
  GPURigidBodyTriggerEvent,
106
108
  GPURigidBodyTriggerBatch
107
109
  } from './rigid-body-triggers';
110
+ export type {
111
+ GPURigidBodyActiveContact,
112
+ GPURigidBodyActiveTrigger,
113
+ GPURigidBodyContactSnapshot,
114
+ GPURigidBodyEventSnapshot,
115
+ GPURigidBodyTriggerSnapshot
116
+ } from './rigid-body-event-snapshot';
108
117
  export {decodeRigidBodyTriggerEvents} from './rigid-body-triggers';
109
118
 
110
119
  export type {GPURigidBodyJoint, GPURigidBodyJointFrame} from './rigid-body-joints';
@@ -8,10 +8,15 @@ export type RigidBodySparseShaderLayout = {
8
8
  diagnosticOffset: number;
9
9
  };
10
10
 
11
+ /** Build sparse cache ownership and optional partition-local overflow reporting. */
11
12
  export function getRigidBodyCacheShader(
12
13
  layout: RigidBodySparseShaderLayout,
13
- ensemble = false
14
+ ensemble = false,
15
+ pairsPerInstance?: number
14
16
  ): string {
17
+ // Disjoint ranges ensure a sibling cannot claim an address that a failed instance must restore.
18
+ /** Use the selected capacity as a power-of-two mask within the owning cache range. */
19
+ const capacity = pairsPerInstance ? `${pairsPerInstance}u` : 'PAIR_CAPACITY';
15
20
  let source = /* wgsl */ `
16
21
  const EMPTY_PAIR:u32=0u;
17
22
  const DELETED_PAIR:u32=0xffffffffu;
@@ -24,11 +29,12 @@ fn claimManifold(first:u32,second:u32)->u32{
24
29
  let key=((first<<16u)|second)+1u;
25
30
  var mixed=(key^(key>>16u))*2246822519u;
26
31
  mixed=(mixed^(mixed>>13u))*3266489917u;
27
- let origin=(mixed^(mixed>>16u))&(PAIR_CAPACITY-1u);
32
+ ${pairsPerInstance ? `let instanceIndex=first/INSTANCE_COLLIDERS;let base=instanceIndex*${capacity};` : 'let base=0u;'}
33
+ let origin=(mixed^(mixed>>16u))&(${capacity}-1u);
28
34
  for(var attempt=0u;attempt<8u;attempt++){
29
35
  var reusable=DELETED_PAIR;var observed=DELETED_PAIR;
30
- for(var probe=0u;probe<min(PAIR_CAPACITY,128u);probe++){
31
- let slot=(origin+probe)&(PAIR_CAPACITY-1u);let stored=atomicLoad(&targets.keys[slot].key);
36
+ for(var probe=0u;probe<min(${capacity},128u);probe++){
37
+ let slot=base+((origin+probe)&(${capacity}-1u));let stored=atomicLoad(&targets.keys[slot].key);
32
38
  if(stored==key){targets.keys[slot].epoch=targets.frame;manifolds[slot].first=first;manifolds[slot].second=second;return slot;}
33
39
  if(stored==DELETED_PAIR&&reusable==DELETED_PAIR){reusable=slot;observed=DELETED_PAIR;}
34
40
  if(stored==EMPTY_PAIR){if(reusable==DELETED_PAIR){reusable=slot;observed=EMPTY_PAIR;}break;}
@@ -40,7 +46,12 @@ fn claimManifold(first:u32,second:u32)->u32{
40
46
  manifolds[reusable].first=first;manifolds[reusable].second=second;return reusable;
41
47
  }
42
48
  }
43
- atomicAdd(&targets.cacheDropped,1u);return DELETED_PAIR;
49
+ ${
50
+ pairsPerInstance
51
+ ? 'atomicStore(&targets.instanceFailures[instanceIndex],1u);atomicStore(&targets.instanceFailures[INSTANCE_COUNT],1u);'
52
+ : 'atomicAdd(&targets.cacheDropped,1u);'
53
+ }
54
+ return DELETED_PAIR;
44
55
  }
45
56
  var<workgroup> cacheEpoch:u32;
46
57
  @compute @workgroup_size(64) fn prepare(@builtin(local_invocation_index) invocation:u32){
@@ -86,11 +97,12 @@ fn journalManifold(pair:u32,key:u32){
86
97
  let count=atomicLoad(&targets.reserved0);
87
98
  for(var index=invocation;index<count;index+=64u){targets.journalMarks[targets.journalSlots[index]]=0u;}
88
99
  storageBarrier();
89
- if(invocation==0u){targets.frame++;atomicStore(&targets.reserved0,0u);atomicStore(&targets.reserved1,0u);atomicStore(&targets.reserved2,0u);atomicStore(&targets.cacheDropped,0u);}
100
+ if(invocation==0u){targets.frame++;atomicStore(&targets.reserved0,0u);atomicStore(&targets.reserved1,0u);atomicStore(&targets.reserved2,0u);atomicStore(&targets.cacheDropped,0u);${pairsPerInstance ? 'atomicStore(&targets.instanceFailures[INSTANCE_COUNT],0u);' : ''}}
90
101
  }
91
102
  @compute @workgroup_size(64) fn prepare(@builtin(global_invocation_id) invocation:vec3u){
92
103
  let work=invocation.x;if(work>=atomicLoad(&ensemble[0])){return;}
93
104
  let instance=atomicLoad(&ensemble[INSTANCE_QUEUE+work]);
105
+ ${pairsPerInstance ? 'atomicStore(&targets.instanceFailures[instance],0u);' : ''}
94
106
  targets.instanceFrames[instance]++;let epoch=targets.instanceFrames[instance];
95
107
  var previous=0u;var link=atomicLoad(&targets.instanceHeads[instance]);
96
108
  loop{
@@ -1,15 +1,19 @@
1
- import {getEnsembleContactLayout} from './rigid-body-ensemble-layout';
2
- import {RIGID_BODY_JOINT_STATE_BYTES} from './rigid-body-joints';
3
1
  // luma.gl
4
2
  // SPDX-License-Identifier: MIT
5
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
6
4
 
5
+ import {RIGID_BODY_CAST_COMMAND_BYTES, RIGID_BODY_BATCH_RESULT_BYTES} from './rigid-body-queries';
6
+ import {getEnsembleContactLayout} from './rigid-body-ensemble-layout';
7
+ import {RIGID_BODY_JOINT_STATE_BYTES} from './rigid-body-joints';
8
+
7
9
  export type GPURigidBodyCapacityInfo = {
8
10
  bodyCount: number;
9
11
  colliderCount: number;
10
12
  maximumPairs: number;
11
13
  /** World-owned buffers only; excludes graph scratch, pipelines and driver allocation overhead. */
12
14
  ownedBufferBytes: number;
15
+ /** Private cast index scratch. Upper bound before attachment, physical allocation afterward. */
16
+ queryIndexScratchBytes: number;
13
17
  buffers: {name: string; byteLength: number; uniform: boolean}[];
14
18
  pairWorkgroups: number;
15
19
  };
@@ -28,7 +32,9 @@ export function getRigidBodyStorageLayout(
28
32
  rollback = false,
29
33
  continuous = false,
30
34
  jointCount = 0,
31
- ensembleInstances = 0
35
+ ensembleInstances = 0,
36
+ independentRecovery = false,
37
+ queryBatchCapacity = 0
32
38
  ) {
33
39
  const geometryOffset = Math.ceil((bodyCount * 12 + colliderCount * 26) / 4) * 4;
34
40
  const pairOffset = Math.ceil((geometryOffset + geometryWords) / 64) * 64;
@@ -49,7 +55,8 @@ export function getRigidBodyStorageLayout(
49
55
  {
50
56
  name: 'targets',
51
57
  byteLength: ensembleInstances
52
- ? getEnsembleContactLayout(bodyCount, ensembleInstances, maximumPairs).byteLength
58
+ ? getEnsembleContactLayout(bodyCount, ensembleInstances, maximumPairs, independentRecovery)
59
+ .byteLength
53
60
  : Math.ceil((bodyCount * 32 + (sparse ? 32 + maximumPairs * 8 : 16)) / 16) * 16 +
54
61
  jointCount * RIGID_BODY_JOINT_STATE_BYTES,
55
62
  uniform: false
@@ -76,6 +83,20 @@ export function getRigidBodyStorageLayout(
76
83
  {name: 'query-output', byteLength: 16 + Math.max(1, colliderCount) * 48, uniform: false}
77
84
  ]
78
85
  : []),
86
+ ...(queryBatchCapacity
87
+ ? [
88
+ {
89
+ name: 'query-batch-commands',
90
+ byteLength: queryBatchCapacity * RIGID_BODY_CAST_COMMAND_BYTES,
91
+ uniform: false
92
+ },
93
+ {
94
+ name: 'query-batch-results',
95
+ byteLength: queryBatchCapacity * RIGID_BODY_BATCH_RESULT_BYTES,
96
+ uniform: false
97
+ }
98
+ ]
99
+ : []),
79
100
  ...(extended ? [{name: 'mesh-tasks', byteLength: 16 + 65536 * 48, uniform: false}] : []),
80
101
  ...(parallel
81
102
  ? [
@@ -0,0 +1,277 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Buffer, type BindingDeclaration, type Device} from '@luma.gl/core';
6
+ import {GPUBVH} from '../gpu-core/gpu-bvh';
7
+ import {
8
+ GPUCommandGraph,
9
+ type CompiledGPUCommandGraph,
10
+ type GraphBufferHandle
11
+ } from '../gpu-core/gpu-command-graph';
12
+ import {Kernel} from '../execution/compute/kernel';
13
+ import {getRigidBodyBatchCastShader} from './rigid-body-queries';
14
+ import {
15
+ normalizeRigidBodyRotation,
16
+ rotateRigidBodyVector,
17
+ type GPURigidBody,
18
+ type GPURigidBodyCollider
19
+ } from './rigid-body-properties';
20
+
21
+ /** Authored locality and stable query identities for a refittable index. */
22
+ export type RigidBodyCastOrder = {
23
+ /** Collider IDs, with indexed primitives first. */
24
+ indices: Uint32Array;
25
+ /** Inverse permutation for sorting small explicit selections. */
26
+ ranks: Uint32Array;
27
+ /** Sphere and box count in the indexed prefix. */
28
+ indexedCount: number;
29
+ };
30
+
31
+ /** Index colliders whose exact intersection does not use a traversal budget. */
32
+ export function canIndexRigidBodyCastCollider(collider: GPURigidBodyCollider): boolean {
33
+ return collider.shape.type === 'sphere' || collider.shape.type === 'box';
34
+ }
35
+
36
+ /** Size the implicit complete binary tree, including padded leaves. */
37
+ function getCastIndexShape(indexedCount: number) {
38
+ /** Zero primitives require no private query graph. */
39
+ const leafCapacity = indexedCount ? 2 ** Math.ceil(Math.log2(indexedCount)) : 0;
40
+ return {leafCapacity, nodeCount: Math.max(0, leafCapacity * 2 - 1)};
41
+ }
42
+
43
+ /** Bound scratch before compilation and transient buffer aliasing. */
44
+ export function estimateRigidBodyCastIndexBytes(indexedCount: number): number {
45
+ if (!indexedCount) return 0;
46
+ /** Source and node bounds have two float32x3 rows. Node children add two words. */
47
+ const {leafCapacity, nodeCount} = getCastIndexShape(indexedCount);
48
+ return indexedCount * 24 + nodeCount * 32 + leafCapacity * 4 + 8;
49
+ }
50
+
51
+ /** Sort primitive leaves by position once. GPU refits preserve this order as bodies move. */
52
+ export function getRigidBodyCastOrder(
53
+ colliders: readonly (GPURigidBodyCollider & {body: number})[],
54
+ bodies: readonly GPURigidBody[]
55
+ ): RigidBodyCastOrder {
56
+ /** Separate the primitives whose exact intersection has no traversal budget. */
57
+ const primitives: {index: number; center: number[]; key: number}[] = [];
58
+ /** Retain direct traversal for extended shapes to preserve their completion status. */
59
+ const extended: number[] = [];
60
+ /** Authored center range for quantization. */
61
+ const lower = [Infinity, Infinity, Infinity];
62
+ /** Authored center range for quantization. */
63
+ const upper = [-Infinity, -Infinity, -Infinity];
64
+ for (const [index, collider] of colliders.entries()) {
65
+ if (!canIndexRigidBodyCastCollider(collider)) {
66
+ extended.push(index);
67
+ continue;
68
+ }
69
+ /** Map compound offsets out of the authored body frame before ordering the leaves. */
70
+ const body = bodies[collider.body];
71
+ /** Collider translation relative to the authored body origin in world axes. */
72
+ const offset = collider.position
73
+ ? rotateRigidBodyVector(normalizeRigidBodyRotation(body.orientation), collider.position)
74
+ : [0, 0, 0];
75
+ /** Include each collider center even when one body owns several separated primitives. */
76
+ const center = body.position.map((value, coordinate) => value + offset[coordinate]);
77
+ for (let coordinate = 0; coordinate < 3; coordinate++) {
78
+ lower[coordinate] = Math.min(lower[coordinate], center[coordinate]);
79
+ upper[coordinate] = Math.max(upper[coordinate], center[coordinate]);
80
+ }
81
+ primitives.push({index, center, key: 0});
82
+ }
83
+ for (const primitive of primitives) {
84
+ for (let coordinate = 0; coordinate < 3; coordinate++) {
85
+ /** Ten bits per axis keep the Morton key inside a uint32. */
86
+ const span = upper[coordinate] - lower[coordinate];
87
+ /** Clamp the endpoint and handle a flat axis without dividing by zero. */
88
+ const quantized =
89
+ span > 0
90
+ ? Math.floor(((primitive.center[coordinate] - lower[coordinate]) / span) * 1023)
91
+ : 0;
92
+ for (let bit = 0; bit < 10; bit++) {
93
+ primitive.key |= ((quantized >> bit) & 1) << (3 * bit + coordinate);
94
+ }
95
+ }
96
+ }
97
+ primitives.sort((first, second) => first.key - second.key);
98
+ /** Restore caller-facing collider identities after traversal. */
99
+ const indices = Uint32Array.from([...primitives.map(primitive => primitive.index), ...extended]);
100
+ /** Use the same topology when an application passes a subset in a different order. */
101
+ const ranks = new Uint32Array(indices.length);
102
+ for (const [rank, index] of indices.entries()) ranks[index] = rank;
103
+ return {indices, ranks, indexedCount: primitives.length};
104
+ }
105
+
106
+ /** Gather conservative world-space bounds for the selected primitive prefix. */
107
+ function getGatherCastBoundsShader(indexedCount: number): string {
108
+ return /* wgsl */ `
109
+ @group(0) @binding(24) var<storage,read_write> sourceMinima:array<f32>;
110
+ @group(0) @binding(25) var<storage,read_write> sourceMaxima:array<f32>;
111
+ @group(0) @binding(30) var<storage,read> batchCommands:array<Query>;
112
+
113
+ @compute @workgroup_size(64) fn gatherCastBounds(@builtin(global_invocation_id) invocation:vec3u){
114
+ let row=invocation.x;
115
+ if(row>=${indexedCount}u){return;}
116
+ let largest=0x1.fffffep127f;
117
+ var lower=vec3f(largest);
118
+ var upper=vec3f(-largest);
119
+ if(row<batchCommands[0].settings.y){
120
+ let collider=querySelection[row];
121
+ let center=colliderPosition(collider);
122
+ let shape=bodies.colliders[collider].shape;
123
+ var extent=vec3f(shape.x);
124
+ if(shape.w==1.0){extent=shapeWorldExtent(collider);}
125
+ // Cover float32 pose and slab arithmetic, including the narrow phase's
126
+ // near-tangent sphere sweep tolerance.
127
+ let padding=max(vec3f(1e-7),(abs(center)+extent)*2e-6);
128
+ lower=center-extent-padding;
129
+ upper=center+extent+padding;
130
+ if(!all(abs(lower)<=vec3f(largest))||!all(abs(upper)<=vec3f(largest))){
131
+ lower=vec3f(-largest);
132
+ upper=vec3f(largest);
133
+ }
134
+ }
135
+ for(var coordinate=0u;coordinate<3u;coordinate++){
136
+ sourceMinima[row*3u+coordinate]=lower[coordinate];
137
+ sourceMaxima[row*3u+coordinate]=upper[coordinate];
138
+ }
139
+ }
140
+ `;
141
+ }
142
+
143
+ /** Index construction and traversal inputs borrowed from the rigid-body world. */
144
+ type RigidBodyCastIndexProps = {
145
+ /** Prefix for graph resources and passes. */
146
+ id: string;
147
+ /** WGSL containing shared geometry and cast declarations. */
148
+ source: string;
149
+ /** Binding declarations for the shared batch cast shader. */
150
+ layout: readonly BindingDeclaration[];
151
+ /** Borrowed world buffers and batch staging. */
152
+ buffers: {
153
+ positions: Buffer;
154
+ orientations: Buffer;
155
+ bodies: Buffer;
156
+ querySelection: Buffer;
157
+ batchCommands: Buffer;
158
+ batchResults: Buffer;
159
+ };
160
+ /** Maximum number of indexed leaves. */
161
+ indexedCount: number;
162
+ };
163
+
164
+ /** Compile one private query graph. Holds no ownership of world state or query staging. */
165
+ export function createRigidBodyCastIndex(
166
+ device: Device,
167
+ {id, source, layout, buffers, indexedCount}: RigidBodyCastIndexProps
168
+ ): CompiledGPUCommandGraph<number> {
169
+ /** Keep refits separate from the application simulation graph. */
170
+ const graph = new GPUCommandGraph<number>(device, {id});
171
+ /** Import each world buffer once so graph dependencies track the same handles. */
172
+ const resources = Object.fromEntries(
173
+ Object.entries(buffers).map(([name, buffer]) => [
174
+ name,
175
+ graph.importBuffer({id: name, byteLength: buffer.byteLength, usage: buffer.usage}, buffer)
176
+ ])
177
+ );
178
+ /** Every internal and leaf row uses the same packed bounds format. */
179
+ const {leafCapacity, nodeCount} = getCastIndexShape(indexedCount);
180
+ /** Allocate a packed scratch view owned by the query graph. */
181
+ function createView<Format extends 'float32x3' | 'uint32x2' | 'uint32'>(
182
+ name: string,
183
+ format: Format,
184
+ length: number
185
+ ) {
186
+ /** Three floats for bounds or one or two words for topology. */
187
+ const rowBytes = format === 'float32x3' ? 12 : format === 'uint32x2' ? 8 : 4;
188
+ return graph.createDataView(
189
+ graph.createTransientBuffer({id: name, byteLength: length * rowBytes, usage: Buffer.STORAGE}),
190
+ {format, length}
191
+ );
192
+ }
193
+
194
+ /** Shared BVH primitive publishes stable implicit leaves and refits from the current poses. */
195
+ const hierarchy = new GPUBVH({
196
+ id,
197
+ leafCapacity,
198
+ minima: createView('source-minima', 'float32x3', indexedCount),
199
+ maxima: createView('source-maxima', 'float32x3', indexedCount),
200
+ nodeMinima: createView('node-minima', 'float32x3', nodeCount),
201
+ nodeMaxima: createView('node-maxima', 'float32x3', nodeCount),
202
+ nodeChildren: createView('children', 'uint32x2', nodeCount),
203
+ leafIds: createView('leaf-ids', 'uint32', leafCapacity),
204
+ count: createView('count', 'uint32', 1),
205
+ overflow: createView('overflow', 'uint32', 1)
206
+ });
207
+
208
+ /** Add one compute node with explicit hazards for the external world and tree scratch. */
209
+ function addPass(
210
+ entryPoint: string,
211
+ shaderSource: string,
212
+ bindings: Record<string, GraphBufferHandle>,
213
+ writes: readonly string[],
214
+ workgroups?: number
215
+ ): void {
216
+ /** The shader shares declarations with the unindexed pipeline. */
217
+ const bindingLayout = [
218
+ ...layout,
219
+ {name: 'sourceMinima', group: 0, location: 24, type: 'storage' as const},
220
+ {name: 'sourceMaxima', group: 0, location: 25, type: 'storage' as const},
221
+ {name: 'nodeMinima', group: 0, location: 26, type: 'read-only-storage' as const},
222
+ {name: 'nodeMaxima', group: 0, location: 27, type: 'read-only-storage' as const}
223
+ ].filter(binding => binding.name in bindings);
224
+ graph.addComputePass({
225
+ id: `${id}-${entryPoint}`,
226
+ resources: Object.entries(bindings).map(([name, buffer]) => ({
227
+ buffer,
228
+ usage: writes.includes(name) ? 'storage-read-write' : 'storage-read'
229
+ })),
230
+ compile: () => {
231
+ /** Compile once and resolve graph-owned temporary buffers at encode time. */
232
+ const kernel = new Kernel(device, {
233
+ id: `${id}-${entryPoint}`,
234
+ source: shaderSource,
235
+ entryPoint,
236
+ shaderLayout: {bindings: bindingLayout}
237
+ });
238
+ return {
239
+ encode: ({computePass, getBuffer, parameters}) =>
240
+ kernel.dispatch(computePass, {
241
+ bindings: Object.fromEntries(
242
+ Object.entries(bindings).map(([name, handle]) => [name, getBuffer(handle)])
243
+ ),
244
+ x: workgroups ?? parameters
245
+ }),
246
+ destroy: () => kernel.destroy()
247
+ };
248
+ }
249
+ });
250
+ }
251
+
252
+ /** The shared geometry source defines the command struct and collider pose helpers. */
253
+ const {batchResults, ...inputs} = resources;
254
+ addPass(
255
+ 'gatherCastBounds',
256
+ source + getGatherCastBoundsShader(indexedCount),
257
+ {
258
+ ...inputs,
259
+ sourceMinima: hierarchy.minima.buffer,
260
+ sourceMaxima: hierarchy.maxima.buffer
261
+ },
262
+ ['sourceMinima', 'sourceMaxima'],
263
+ Math.ceil(indexedCount / 64)
264
+ );
265
+ graph.add(hierarchy);
266
+ addPass(
267
+ 'castBatch',
268
+ source + getRigidBodyBatchCastShader(leafCapacity),
269
+ {
270
+ ...resources,
271
+ nodeMinima: hierarchy.nodeMinima.buffer,
272
+ nodeMaxima: hierarchy.nodeMaxima.buffer
273
+ },
274
+ ['batchResults']
275
+ );
276
+ return graph.compile();
277
+ }
@@ -6,7 +6,8 @@
6
6
  export function getEnsembleContactLayout(
7
7
  bodyCount: number,
8
8
  instances: number,
9
- maximumPairs: number
9
+ maximumPairs: number,
10
+ independentRecovery = false
10
11
  ) {
11
12
  const keyOffset = bodyCount * 8 + 8;
12
13
  const headOffset = keyOffset + maximumPairs * 2;
@@ -20,6 +21,8 @@ export function getEnsembleContactLayout(
20
21
  const savedFrameOffset = savedHeadOffset + instances;
21
22
  const savedHeaderOffset = savedFrameOffset + instances;
22
23
  const savedManifoldOffset = Math.ceil((savedHeaderOffset + 8) / 4) * 4;
24
+ /** Local fault words and one aggregate flag follow the journal payloads. */
25
+ const failureOffset = savedManifoldOffset + maximumPairs * 104;
23
26
  return {
24
27
  keyOffset,
25
28
  headOffset,
@@ -33,6 +36,7 @@ export function getEnsembleContactLayout(
33
36
  savedFrameOffset,
34
37
  savedHeaderOffset,
35
38
  savedManifoldOffset,
36
- byteLength: (savedManifoldOffset + maximumPairs * 104) * 4
39
+ failureOffset,
40
+ byteLength: (failureOffset + (independentRecovery ? Math.ceil((instances + 1) / 4) * 4 : 0)) * 4
37
41
  };
38
42
  }
@@ -16,7 +16,8 @@ export function makeEnsembleReset(
16
16
  collidersPerInstance: number,
17
17
  maximumPairs: number,
18
18
  vehiclesPerInstance: number,
19
- terrainSlots: ReadonlySet<number>
19
+ terrainSlots: ReadonlySet<number>,
20
+ pairsPerInstance?: number
20
21
  ) {
21
22
  const find = (name: string) => buffers.find(buffer => buffer.id === `${id}-${name}`)!;
22
23
  // A streamed collider row contains a private atlas address, revision and placement.
@@ -104,15 +105,21 @@ ${vehicle ? '@group(0) @binding(7) var<storage,read_write> vehicle:array<u32>;'
104
105
  }`
105
106
  : ''
106
107
  }
107
- if(index>=${maximumPairs}u){return;}
108
- let key=targets[${bodyCount * 8 + 8}u+index*2u];
108
+ if(index>=${pairsPerInstance ?? maximumPairs}u){return;}
109
+ ${
110
+ pairsPerInstance
111
+ ? `let pair=(selection.x/${bodiesPerInstance}u)*${pairsPerInstance}u+index;`
112
+ : `let pair=index;
113
+ let key=targets[${bodyCount * 8 + 8}u+pair*2u];
109
114
  if(key==0u||key==0xffffffffu){return;}
110
- let address=index*104u;let collider=manifolds[address+97u];
111
- if(collider<selection.y||collider>=selection.y+${collidersPerInstance}u){return;}
115
+ let collider=manifolds[pair*104u+97u];
116
+ if(collider<selection.y||collider>=selection.y+${collidersPerInstance}u){return;}`
117
+ }
118
+ let address=pair*104u;
112
119
  for(var word=0u;word<104u;word++){manifolds[address+word]=0u;}
113
- targets[${bodyCount * 8 + 8}u+index*2u]=0xffffffffu;
114
- targets[${bodyCount * 8 + 9}u+index*2u]=0u;
115
- ${history ? 'for(var word=0u;word<4u;word++){history[index*4u+word]=0u;}' : ''}
120
+ targets[${bodyCount * 8 + 8}u+pair*2u]=${pairsPerInstance ? '0u' : '0xffffffffu'};
121
+ targets[${bodyCount * 8 + 9}u+pair*2u]=0u;
122
+ ${history ? 'for(var word=0u;word<4u;word++){history[pair*4u+word]=0u;}' : ''}
116
123
  }`,
117
124
  shaderLayout: {
118
125
  bindings: [
@@ -162,7 +169,12 @@ ${vehicle ? '@group(0) @binding(7) var<storage,read_write> vehicle:array<u32>;'
162
169
  });
163
170
  const pass = encoder.beginComputePass();
164
171
  const groups = Math.ceil(
165
- Math.max(maximumPairs, collidersPerInstance, bodiesPerInstance, vehiclesPerInstance) / 64
172
+ Math.max(
173
+ pairsPerInstance ?? maximumPairs,
174
+ collidersPerInstance,
175
+ bodiesPerInstance,
176
+ vehiclesPerInstance
177
+ ) / 64
166
178
  );
167
179
  computation!.kernel.dispatch(pass, {
168
180
  bindings: computation!.bindings,
@@ -16,6 +16,7 @@ import type {
16
16
  GPUCommandGraphComputeExecutable
17
17
  } from '../gpu-core/gpu-command-graph';
18
18
 
19
+ /** Schedule only enabled, awake instances that have no latched local failure. */
19
20
  export function getEnsembleShader(
20
21
  bodyCount: number,
21
22
  bodiesPerInstance?: number,
@@ -54,7 +55,7 @@ fn scheduledCollider(index:u32)->u32{return atomicLoad(&ensemble[INSTANCE_QUEUE+
54
55
  let instance=invocation.x;if(instance>=INSTANCE_COUNT){return;}let offset=16u+instance*8u;
55
56
  // Controls must remain pending across disabled steps after the shared wake flag is consumed.
56
57
  if(atomicLoad(&ensemble[1])!=0u){atomicStore(&ensemble[offset+6u],1u);}
57
- if(atomicLoad(&ensemble[offset])==0u){return;}
58
+ if(atomicLoad(&ensemble[offset])==0u||atomicLoad(&ensemble[offset+7u])!=0u){return;}
58
59
  if(atomicLoad(&ensemble[offset+5u])!=0u||atomicLoad(&ensemble[offset+6u])!=0u||atomicLoad(&ensemble[1])!=0u){
59
60
  atomicStore(&ensemble[offset+1u],1u);atomicStore(&ensemble[offset+6u],0u);
60
61
  }
@@ -94,21 +95,26 @@ export function addEnsembleStatus<Parameters>(
94
95
  bodies: {buffer: Buffer; resource: GraphBufferHandle},
95
96
  sleepStates: {buffer: Buffer; resource: GraphBufferHandle},
96
97
  ensemble: {buffer: Buffer; resource: GraphBufferHandle},
97
- statistics: {buffer: Buffer; resource: GraphBufferHandle}
98
+ statistics: {buffer: Buffer; resource: GraphBufferHandle},
99
+ failureSource?: {buffer: Buffer; resource: GraphBufferHandle; wordOffset: number}
98
100
  ) {
99
101
  const properties = {
100
102
  id: `${id}-ensemble-status`,
101
103
  source: `
102
104
  @group(0) @binding(0) var<storage,read_write> ensemble:array<u32>;
103
105
  @group(0) @binding(1) var<storage,read> statistics:array<u32>;
106
+ ${failureSource ? '@group(0) @binding(4) var<storage,read> targets:array<u32>;' : ''}
104
107
  struct Body {inertia:vec4f,inertiaOrientation:vec4f,motion:vec4f}
105
108
  @group(0) @binding(2) var<storage,read> bodies:array<Body>;
106
109
  @group(0) @binding(3) var<storage,read> sleepStates:array<vec4f>;
107
110
  @compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
108
111
  let instance=invocation.x;if(instance>=${instances}u){return;}
109
- let offset=16u+instance*8u;let failed=statistics[1]!=0u||statistics[15]!=0u;
110
- ensemble[offset+4u]=select(0u,1u,failed);
112
+ let offset=16u+instance*8u;let sharedFault=statistics[1]!=0u||statistics[15]!=0u;
113
+ ensemble[offset+4u]=select(0u,1u,sharedFault);
111
114
  if(ensemble[offset+1u]==0u){return;}
115
+ ${failureSource ? `let localFailure=targets[${failureSource.wordOffset}u+instance];` : 'let localFailure=0u;'}
116
+ if(localFailure!=0u&&!sharedFault){ensemble[offset+7u]=localFailure;}
117
+ let failed=sharedFault||localFailure!=0u;
112
118
  var awake=failed;
113
119
  for(var local=0u;local<${bodiesPerInstance}u;local++){
114
120
  let body=instance*${bodiesPerInstance}u+local;let motion=bodies[body].motion.x;
@@ -123,14 +129,18 @@ struct Body {inertia:vec4f,inertiaOrientation:vec4f,motion:vec4f}
123
129
  {name: 'ensemble', group: 0, location: 0, type: 'storage' as const},
124
130
  {name: 'statistics', group: 0, location: 1, type: 'read-only-storage' as const},
125
131
  {name: 'bodies', group: 0, location: 2, type: 'read-only-storage' as const},
126
- {name: 'sleepStates', group: 0, location: 3, type: 'read-only-storage' as const}
132
+ {name: 'sleepStates', group: 0, location: 3, type: 'read-only-storage' as const},
133
+ ...(failureSource
134
+ ? [{name: 'targets', group: 0, location: 4, type: 'read-only-storage' as const}]
135
+ : [])
127
136
  ]
128
137
  },
129
138
  bindings: {
130
139
  ensemble: ensemble.buffer,
131
140
  statistics: statistics.buffer,
132
141
  bodies: bodies.buffer,
133
- sleepStates: sleepStates.buffer
142
+ sleepStates: sleepStates.buffer,
143
+ ...(failureSource ? {targets: failureSource.buffer} : {})
134
144
  }
135
145
  };
136
146
  const executable = (computation: BoundKernel): GPUCommandGraphComputeExecutable<Parameters> => ({
@@ -149,7 +159,8 @@ struct Body {inertia:vec4f,inertiaOrientation:vec4f,motion:vec4f}
149
159
  {buffer: ensemble.resource, usage: 'storage-read-write'},
150
160
  {buffer: statistics.resource, usage: 'storage-read'},
151
161
  {buffer: bodies.resource, usage: 'storage-read'},
152
- {buffer: sleepStates.resource, usage: 'storage-read'}
162
+ {buffer: sleepStates.resource, usage: 'storage-read'},
163
+ ...(failureSource ? [{buffer: failureSource.resource, usage: 'storage-read' as const}] : [])
153
164
  ],
154
165
  compile: ({device}) => executable(createBoundKernel(device, properties)),
155
166
  compileAsync: async ({device}) => executable(await createBoundKernelAsync(device, properties))