@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
@@ -16,7 +16,7 @@ import type {GPUCommandGraph, GraphBufferHandle} from '../gpu-core/gpu-command-g
16
16
 
17
17
  type Resource = {buffer: Buffer; resource: GraphBufferHandle};
18
18
 
19
- /** Snapshot active bodies and journal contact writes without changing shared failure semantics. */
19
+ /** Snapshot active bodies and journal contact writes and restore failed contact partitions or an entire failed shared step. */
20
20
  export function addEnsembleCheckpoint<GraphParameters>(
21
21
  graph: GPUCommandGraph<GraphParameters>,
22
22
  id: string,
@@ -27,7 +27,8 @@ export function addEnsembleCheckpoint<GraphParameters>(
27
27
  bodiesPerInstance: number,
28
28
  maximumPairs: number,
29
29
  allocate: (name: string, byteLength: number) => Buffer,
30
- vehicles?: {state: Resource; vehiclesPerInstance: number}
30
+ vehicles?: {state: Resource; vehiclesPerInstance: number},
31
+ pairsPerInstance?: number
31
32
  ) {
32
33
  const bodyCount = states[0].buffer.byteLength / 16;
33
34
  const instances = bodyCount / bodiesPerInstance;
@@ -40,8 +41,9 @@ export function addEnsembleCheckpoint<GraphParameters>(
40
41
  savedLinkOffset,
41
42
  savedHeadOffset,
42
43
  savedHeaderOffset,
43
- savedManifoldOffset
44
- } = getEnsembleContactLayout(bodyCount, instances, maximumPairs);
44
+ savedManifoldOffset,
45
+ failureOffset
46
+ } = getEnsembleContactLayout(bodyCount, instances, maximumPairs, Boolean(pairsPerInstance));
45
47
  const importAllocation = (name: string, byteLength: number): Resource => {
46
48
  const buffer = allocate(name, byteLength);
47
49
  return {
@@ -104,6 +106,16 @@ export function addEnsembleCheckpoint<GraphParameters>(
104
106
  compileAsync: async () => executable(await createBoundKernelAsync(graph.device, properties))
105
107
  });
106
108
  };
109
+ /** Shared failure is sticky; local overflow applies only to the attempted instance. */
110
+ const sharedFailure = 'statistics[1]!=0u||statistics[15]!=0u';
111
+ /** Fast exit before visiting journal entries when every instance accepted the step. */
112
+ const anyFailure = pairsPerInstance
113
+ ? `${sharedFailure}||targets[${failureOffset + instances}u]!=0u`
114
+ : sharedFailure;
115
+ /** Read the local failure word through the already allocated targets buffer. */
116
+ const localFailure = (instance: string) => `targets[${failureOffset}u+${instance}]!=0u`;
117
+ /** Bind local failure words only on recovery passes that need an additional binding. */
118
+ const localFailureInput = pairsPerInstance ? [{...targets, name: 'targets'}] : [];
107
119
  const bodyAddress = `let work=invocation.x;if(work>=ensemble[0]*${bodiesPerInstance}u){return;}
108
120
  let body=ensemble[${16 + instances * 8}u+work/${bodiesPerInstance}u]*${bodiesPerInstance}u+work%${bodiesPerInstance}u;`;
109
121
  /** Journal or restore contiguous vehicle rows for the scheduled instances. */
@@ -116,12 +128,14 @@ export function addEnsembleCheckpoint<GraphParameters>(
116
128
  {...vehicles.state, name: 'vehicle', writable: restore},
117
129
  {...vehicleSnapshot, name: 'snapshot', writable: !restore},
118
130
  {...ensemble, name: 'ensemble'},
119
- ...(restore ? [{...statistics, name: 'statistics'}] : [])
131
+ ...(restore ? [{...statistics, name: 'statistics'}, ...localFailureInput] : [])
120
132
  ],
121
133
  `@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
122
- ${restore ? 'if(statistics[1]==0u&&statistics[15]==0u){return;}' : ''}
134
+ ${restore ? `if(!(${anyFailure})){return;}` : ''}
123
135
  let work=invocation.x;if(work>=ensemble[0]*${count}u){return;}
124
- let row=(ensemble[${16 + instances * 8}u+work/${count}u]*${count}u+work%${count}u)*${VEHICLE_STRIDE / 4}u;
136
+ let instance=ensemble[${16 + instances * 8}u+work/${count}u];
137
+ ${restore && pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure('instance')})){return;}` : ''}
138
+ let row=(instance*${count}u+work%${count}u)*${VEHICLE_STRIDE / 4}u;
125
139
  for(var word=0u;word<${VEHICLE_STRIDE / 4}u;word++){
126
140
  ${restore ? 'vehicle[row+word]=snapshot[row+word];' : 'snapshot[row+word]=vehicle[row+word];'}
127
141
  }
@@ -176,10 +190,11 @@ export function addEnsembleCheckpoint<GraphParameters>(
176
190
  ],
177
191
  `
178
192
  @compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
179
- if(statistics[1]==0u&&statistics[15]==0u){return;}
193
+ if(!(${anyFailure})){return;}
180
194
  let count=targets[${bodyCount * 8 + 5}u];
181
195
  for(var work=invocation.x;work<count*104u;work+=64u){
182
196
  let pair=targets[${journalOffset}u+work/104u];let word=work%104u;
197
+ ${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`pair/${pairsPerInstance}u`)})){continue;}` : ''}
183
198
  manifolds[pair*104u+word]=targets[${savedManifoldOffset}u+pair*104u+word];
184
199
  }
185
200
  }`
@@ -193,20 +208,21 @@ export function addEnsembleCheckpoint<GraphParameters>(
193
208
  ],
194
209
  `
195
210
  @compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
196
- if(statistics[1]==0u&&statistics[15]==0u){return;}
211
+ if(!(${anyFailure})){return;}
197
212
  let count=targets[${bodyCount * 8 + 5}u];
198
213
  for(var index=invocation.x;index<count;index+=64u){let pair=targets[${journalOffset}u+index];
214
+ ${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`pair/${pairsPerInstance}u`)})){continue;}` : ''}
199
215
  targets[${bodyCount * 8 + 8}u+pair*2u]=targets[${savedKeyOffset}u+pair*2u];
200
216
  targets[${bodyCount * 8 + 9}u+pair*2u]=targets[${savedKeyOffset + 1}u+pair*2u];
201
217
  targets[${linkOffset}u+pair]=targets[${savedLinkOffset}u+pair];
202
218
  }
203
219
  for(var work=invocation.x;work<ensemble[0];work+=64u){let instance=ensemble[${16 + instances * 8}u+work];
220
+ ${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure('instance')})){continue;}` : ''}
204
221
  targets[${headOffset}u+instance]=targets[${savedHeadOffset}u+instance];
205
222
  targets[${headOffset + instances}u+instance]=targets[${savedHeadOffset + instances}u+instance];
206
223
  }
207
- storageBarrier();
208
224
  // Preserve the attempted step's journal list and counters so the next prepare can clear its marks.
209
- if(invocation.x<5u){targets[${bodyCount * 8}u+invocation.x]=targets[${savedHeaderOffset}u+invocation.x];}
225
+ if((${sharedFailure})&&invocation.x<5u){targets[${bodyCount * 8}u+invocation.x]=targets[${savedHeaderOffset}u+invocation.x];}
210
226
  }`
211
227
  );
212
228
  copyVehicleState(true);
@@ -217,11 +233,13 @@ export function addEnsembleCheckpoint<GraphParameters>(
217
233
  {...state, name: 'state', writable: true},
218
234
  {...snapshots[index], name: 'snapshot'},
219
235
  {...statistics, name: 'statistics'},
220
- {...ensemble, name: 'ensemble'}
236
+ {...ensemble, name: 'ensemble'},
237
+ ...localFailureInput
221
238
  ],
222
239
  `@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
223
- if(statistics[1]==0u&&statistics[15]==0u){return;}
240
+ if(!(${anyFailure})){return;}
224
241
  ${bodyAddress}
242
+ ${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`body/${bodiesPerInstance}u`)})){return;}` : ''}
225
243
  for(var word=0u;word<4u;word++){state[body*4u+word]=snapshot[body*4u+word];}
226
244
  }`,
227
245
  true
@@ -0,0 +1,252 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Buffer, type BindingDeclaration} from '@luma.gl/core';
6
+ import type {
7
+ GPUCommandGraph,
8
+ GPUCommandGraphComputeExecutable,
9
+ GraphBufferHandle
10
+ } from '../gpu-core/gpu-command-graph';
11
+ import {
12
+ createBoundKernel,
13
+ createBoundKernelAsync,
14
+ type BoundKernel
15
+ } from '../gpu-core/utils/bound-kernel';
16
+
17
+ /** Stable slot tiles also fit default WebGPU workgroup limits. */
18
+ const EVENT_WORKGROUP_SIZE = 64;
19
+
20
+ /** Storage binding shared by the three large-ring publication passes. */
21
+ const EVENT_WORK_LOCATION = 29;
22
+
23
+ /** Optional per-stage visibility for an imported simulation buffer. */
24
+ export type RigidBodyEventBinding = {
25
+ /** WGSL variable name. */
26
+ name: string;
27
+ /** Binding number in group zero. */
28
+ location: number;
29
+ /** Caller-owned simulation resource. */
30
+ resource: GraphBufferHandle;
31
+ /** Whether the underlying declaration is read-only storage. */
32
+ readOnly?: boolean;
33
+ };
34
+
35
+ /** Configure a publication ring and the resources each callback uses. */
36
+ type EventCompactionOptions = {
37
+ /** Prefix for the graph nodes and temporary storage. */
38
+ id: string;
39
+ /** Number of stable pair or trigger slots scanned in a step. */
40
+ rowCount: number;
41
+ /** Maximum number of retained events. */
42
+ capacity: number;
43
+ /** WGSL ring variable shared by the reservation helpers. */
44
+ ring: string;
45
+ /** WGSL declaring eventClassify, eventCount, eventPublish and eventCommit. */
46
+ source: string;
47
+ /** Resources used to determine transition flags. */
48
+ classify: readonly RigidBodyEventBinding[];
49
+ /** Resources read when deciding whether a step committed. */
50
+ commit: readonly RigidBodyEventBinding[];
51
+ /** Resources accessed to publish payloads and update history. */
52
+ publish: readonly RigidBodyEventBinding[];
53
+ };
54
+
55
+ /** Compact ordered transitions and publish a single coherent step into an existing ring. */
56
+ export function addRigidBodyEventCompaction<Parameters>(
57
+ graph: GPUCommandGraph<Parameters>,
58
+ options: EventCompactionOptions
59
+ ): void {
60
+ /** A single workgroup can classify and publish without external scratch. */
61
+ const workgroups = Math.max(1, Math.ceil(options.rowCount / EVENT_WORKGROUP_SIZE));
62
+ /** The shared WGSL preserves identical event sequence and overflow semantics in both paths. */
63
+ const source = options.source + getEventCompactionShader(options, workgroups);
64
+ /** Attach one explicit graph stage and resolve aliased scratch at encode time. */
65
+ function addStage(
66
+ entryPoint: string,
67
+ description: string,
68
+ bindings: readonly RigidBodyEventBinding[],
69
+ count: number
70
+ ): void {
71
+ /** A buffer may serve several callbacks in the fused entry point. */
72
+ const unique = [...new Map(bindings.map(binding => [binding.name, binding])).values()];
73
+ /** Bind resources without declaring unused storage at this entry point. */
74
+ const declarations = unique.map(
75
+ ({name, location, readOnly}): BindingDeclaration => ({
76
+ name,
77
+ location,
78
+ group: 0,
79
+ type: readOnly ? 'read-only-storage' : 'storage'
80
+ })
81
+ );
82
+ /** The same bindings serve sync and async pipeline compilation. */
83
+ const properties = {
84
+ id: `${options.id}-${entryPoint}`,
85
+ entryPoint,
86
+ source,
87
+ shaderLayout: {bindings: declarations}
88
+ };
89
+ /** Connect compiler-owned scratch and source views for this dispatch. */
90
+ const executable = (
91
+ computation: BoundKernel
92
+ ): GPUCommandGraphComputeExecutable<Parameters> => ({
93
+ encode: ({computePass, getBuffer}) => {
94
+ for (const binding of unique)
95
+ computation.bindings[binding.name] = getBuffer(binding.resource);
96
+ computation.kernel.dispatch(computePass, {bindings: computation.bindings, x: count});
97
+ },
98
+ destroy: () => computation.kernel.destroy()
99
+ });
100
+ graph.addComputePass({
101
+ id: properties.id,
102
+ description,
103
+ resources: unique.map(binding => ({
104
+ buffer: binding.resource,
105
+ usage: binding.readOnly ? 'storage-read' : 'storage-read-write'
106
+ })),
107
+ compile: () => executable(createBoundKernel(graph.device, properties)),
108
+ compileAsync: async () => executable(await createBoundKernelAsync(graph.device, properties))
109
+ });
110
+ }
111
+
112
+ if (workgroups === 1) {
113
+ addStage(
114
+ 'publishEventTile',
115
+ 'Publish ordered events in one workgroup.',
116
+ [...options.classify, ...options.commit, ...options.publish],
117
+ 1
118
+ );
119
+ return;
120
+ }
121
+
122
+ /** One flag/offset word per row, one total/offset per tile, and one reservation header. */
123
+ const scratch = graph.createTransientBuffer({
124
+ id: `${options.id}-compaction`,
125
+ usage: Buffer.STORAGE,
126
+ byteLength: (4 + options.rowCount + workgroups) * 4
127
+ });
128
+ /** Scratch is graph-owned and never enters snapshots or the public event ring layout. */
129
+ const work = {name: 'eventWork', location: EVENT_WORK_LOCATION, resource: scratch};
130
+ addStage(
131
+ 'classifyEventTiles',
132
+ 'Classify transitions and compact one tile per workgroup.',
133
+ [...options.classify, work],
134
+ workgroups
135
+ );
136
+ addStage(
137
+ 'reserveEventTiles',
138
+ 'Reserve ordered ring positions from tile counts.',
139
+ [...options.commit, work],
140
+ 1
141
+ );
142
+ addStage(
143
+ 'publishEventTiles',
144
+ 'Write retained event records and advance transition history.',
145
+ [...options.publish, work],
146
+ workgroups
147
+ );
148
+ }
149
+
150
+ /** Emit a stable workgroup scan and bounded ring reservation for the two event payloads. */
151
+ function getEventCompactionShader(
152
+ {ring, capacity, rowCount}: EventCompactionOptions,
153
+ workgroups: number
154
+ ): string {
155
+ return /* wgsl */ `
156
+ const EVENT_ROWS:u32=${rowCount}u;
157
+ const EVENT_CAPACITY:u32=${capacity}u;
158
+ const EVENT_TILE_SIZE:u32=${EVENT_WORKGROUP_SIZE}u;
159
+ var<workgroup> eventPrefix:array<u32,${EVENT_WORKGROUP_SIZE}>;
160
+
161
+ // Each row emits at most two records, in the order chosen by its publisher.
162
+ fn scanEvents(lane:u32,count:u32)->u32{
163
+ eventPrefix[lane]=count;
164
+ workgroupBarrier();
165
+ for(var stride=1u;stride<EVENT_TILE_SIZE;stride*=2u){
166
+ var prior=0u;
167
+ if(lane>=stride){prior=eventPrefix[lane-stride];}
168
+ workgroupBarrier();
169
+ eventPrefix[lane]+=prior;
170
+ workgroupBarrier();
171
+ }
172
+ return eventPrefix[lane]-count;
173
+ }
174
+
175
+ // Reserve from the old sequence but keep only the newest records that fit the ring.
176
+ // x = base sequence, y = accepted count, z = step (zero for an uncommitted tick).
177
+ fn reserveEvents(total:u32)->vec3u{
178
+ if(!eventCommit()){return vec3u(0);}
179
+ if(${ring}.step==0xffffffffu){${ring}.saturated=1u;return vec3u(0);}
180
+ let base=${ring}.sequence;
181
+ let accepted=min(total,0xffffffffu-base);
182
+ if(accepted<total){${ring}.saturated=1u;}
183
+ ${ring}.sequence=base+accepted;
184
+ ${ring}.step++;
185
+ return vec3u(base,accepted,${ring}.step);
186
+ }
187
+
188
+ fn retainedEventSequence(reservation:vec3u,offset:u32)->u32{
189
+ if(offset>=reservation.y||reservation.y-offset>EVENT_CAPACITY){return 0u;}
190
+ return reservation.x+offset+1u;
191
+ }
192
+
193
+ ${
194
+ workgroups === 1
195
+ ? /* wgsl */ `
196
+ var<workgroup> eventReservation:vec3u;
197
+ @compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn publishEventTile(
198
+ @builtin(local_invocation_index) lane:u32
199
+ ){
200
+ var flags=0u;
201
+ if(lane<EVENT_ROWS){flags=eventClassify(lane);}
202
+ let offset=scanEvents(lane,eventCount(flags));
203
+ if(lane==0u){eventReservation=reserveEvents(eventPrefix[EVENT_TILE_SIZE-1u]);}
204
+ workgroupBarrier();
205
+ if(lane<EVENT_ROWS&&eventReservation.z!=0u){eventPublish(lane,flags,offset,eventReservation);}
206
+ }
207
+ `
208
+ : /* wgsl */ `
209
+ @group(0) @binding(${EVENT_WORK_LOCATION}) var<storage,read_write> eventWork:array<u32>;
210
+ const EVENT_TILES:u32=${workgroups}u;
211
+
212
+ @compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn classifyEventTiles(
213
+ @builtin(global_invocation_id) invocation:vec3u,
214
+ @builtin(local_invocation_index) lane:u32,
215
+ @builtin(workgroup_id) tile:vec3u
216
+ ){
217
+ let row=invocation.x;
218
+ var flags=0u;
219
+ if(row<EVENT_ROWS){flags=eventClassify(row);}
220
+ let offset=scanEvents(lane,eventCount(flags));
221
+ // A 64-lane tile uses at most 128 records. Keep flags above the local offset.
222
+ if(row<EVENT_ROWS){eventWork[4u+row]=offset|(flags<<8u);}
223
+ if(lane==0u){eventWork[4u+EVENT_ROWS+tile.x]=eventPrefix[EVENT_TILE_SIZE-1u];}
224
+ }
225
+
226
+ @compute @workgroup_size(1) fn reserveEventTiles(){
227
+ var total=0u;
228
+ for(var tile=0u;tile<EVENT_TILES;tile++){
229
+ let index=4u+EVENT_ROWS+tile;
230
+ let count=eventWork[index];
231
+ eventWork[index]=total;
232
+ total+=count;
233
+ }
234
+ let reservation=reserveEvents(total);
235
+ eventWork[0]=reservation.x;eventWork[1]=reservation.y;eventWork[2]=reservation.z;
236
+ }
237
+
238
+ @compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn publishEventTiles(
239
+ @builtin(global_invocation_id) invocation:vec3u,
240
+ @builtin(workgroup_id) tile:vec3u
241
+ ){
242
+ let row=invocation.x;
243
+ let reservation=vec3u(eventWork[0],eventWork[1],eventWork[2]);
244
+ if(row>=EVENT_ROWS||reservation.z==0u){return;}
245
+ let word=eventWork[4u+row];
246
+ let offset=eventWork[4u+EVENT_ROWS+tile.x]+(word&255u);
247
+ eventPublish(row,word>>8u,offset,reservation);
248
+ }
249
+ `
250
+ }
251
+ `;
252
+ }
@@ -0,0 +1,76 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Buffer, type Device} from '@luma.gl/core';
6
+
7
+ /** The event stream position and step represented by a recovered overlap snapshot. */
8
+ export type GPURigidBodyEventSnapshot = {
9
+ /** Resume delta reads after this sequence. */
10
+ sequence: number;
11
+ /** Most recent step published by this ring. */
12
+ step: number;
13
+ /** Saturated counters require reconstructing the world to resume the stream. */
14
+ saturated: boolean;
15
+ };
16
+
17
+ /** A pair present in the contact publisher's current history. */
18
+ export type GPURigidBodyActiveContact = {
19
+ bodies: [number, number];
20
+ colliders: [number, number];
21
+ };
22
+
23
+ /** Contact stream recovery point and its complete active pair set. */
24
+ export type GPURigidBodyContactSnapshot = GPURigidBodyEventSnapshot & {
25
+ contacts: GPURigidBodyActiveContact[];
26
+ };
27
+
28
+ /** An active target with its current representative sensor/target collider pair. */
29
+ export type GPURigidBodyActiveTrigger = {
30
+ trigger: number;
31
+ body: number;
32
+ collider: number;
33
+ triggerCollider: number;
34
+ };
35
+
36
+ /** Trigger stream recovery point and its complete active overlap set. */
37
+ export type GPURigidBodyTriggerSnapshot = GPURigidBodyEventSnapshot & {
38
+ overlaps: GPURigidBodyActiveTrigger[];
39
+ };
40
+
41
+ /** Copy the ring header and published history in queue order as one coherent readback. */
42
+ export async function readRigidBodyEventSnapshot<Result extends GPURigidBodyEventSnapshot>(
43
+ device: Device,
44
+ ring: Buffer,
45
+ history: Buffer,
46
+ decode: (snapshot: GPURigidBodyEventSnapshot, rows: Uint32Array) => Result
47
+ ): Promise<Result> {
48
+ /** The snapshot omits retained event payloads and never reads poses or manifolds. */
49
+ const staging = device.createBuffer({
50
+ id: `${ring.id}-snapshot`,
51
+ byteLength: 16 + history.byteLength,
52
+ usage: Buffer.MAP_READ | Buffer.COPY_DST
53
+ });
54
+ try {
55
+ /** All prior submissions complete before both copies; later submissions cannot interleave. */
56
+ const encoder = device.createCommandEncoder();
57
+ encoder.copyBufferToBuffer({sourceBuffer: ring, destinationBuffer: staging, size: 16});
58
+ encoder.copyBufferToBuffer({
59
+ sourceBuffer: history,
60
+ destinationBuffer: staging,
61
+ destinationOffset: 16,
62
+ size: history.byteLength
63
+ });
64
+ device.submit(encoder.finish());
65
+ return await staging.mapAndReadAsync(buffer => {
66
+ /** The mapped bytes are consumed synchronously before the staging buffer is unmapped. */
67
+ const words = new Uint32Array(buffer);
68
+ return decode(
69
+ {sequence: words[0], step: words[1], saturated: words[2] !== 0},
70
+ words.subarray(4)
71
+ );
72
+ });
73
+ } finally {
74
+ staging.destroy();
75
+ }
76
+ }
@@ -53,10 +53,12 @@ export function decodeRigidBodyContactEvents(
53
53
  };
54
54
  }
55
55
 
56
+ /** Publish contact transitions from committed instances in the current step. */
56
57
  export function getRigidBodyEventShader(
57
58
  capacity: number,
58
59
  impulseThreshold: number,
59
- rollback = false
60
+ rollback = false,
61
+ pairsPerInstance?: number
60
62
  ): string {
61
63
  return /* wgsl */ `
62
64
  ${rollback ? '@group(0) @binding(14) var<storage,read> eventStatistics:array<u32>;' : ''}
@@ -64,31 +66,67 @@ struct ContactEvent { stamp:vec4u, identifiers:vec4u, point:vec4f, normal:vec4f
64
66
  struct EventRing { sequence:u32, step:u32, saturated:u32, reserved:u32, entries:array<ContactEvent,${capacity}> }
65
67
  @group(0) @binding(12) var<storage,read_write> contactHistory:array<vec4u>;
66
68
  @group(0) @binding(13) var<storage,read_write> contactEvents:EventRing;
67
- fn emitContact(first:u32,second:u32,phase:u32,point:vec3f,normal:vec3f,impulse:f32){
68
- if(contactEvents.sequence==0xffffffffu){contactEvents.saturated=1u;return;}
69
- let slot=contactEvents.sequence%${capacity}u;contactEvents.sequence++;
70
- contactEvents.entries[slot]=ContactEvent(vec4u(contactEvents.sequence,contactEvents.step,phase,0),vec4u(colliderBody(first),colliderBody(second),first,second),vec4f(point,impulse),vec4f(normal,0));
69
+ const CONTACT_END:u32=1u;
70
+ const CONTACT_BEGIN:u32=2u;
71
+ const CONTACT_IMPACT:u32=4u;
72
+ const CONTACT_PROCESS:u32=8u;
73
+
74
+ fn eventCommit()->bool{
75
+ return ${rollback ? 'eventStatistics[1]==0u&&eventStatistics[15]==0u' : 'true'};
76
+ }
77
+ fn contactImpulse(pair:u32)->vec2f{
78
+ var impulse=0.0;var strongest=0u;
79
+ for(var contact=0u;contact<manifolds[pair].count;contact++){
80
+ impulse+=max(0.0,manifolds[pair].contacts[contact].impulse.x);
81
+ if(manifolds[pair].contacts[contact].impulse.x>manifolds[pair].contacts[strongest].impulse.x){strongest=contact;}
82
+ }
83
+ return vec2f(impulse,f32(strongest));
84
+ }
85
+ fn eventClassify(pair:u32)->u32{
86
+ if(!eventCommit()){return 0u;}
87
+ ${
88
+ pairsPerInstance
89
+ ? `let instance=pair/${pairsPerInstance}u;
90
+ if(instance>=INSTANCE_COUNT||atomicLoad(&ensemble[16u+instance*8u+7u])!=0u){return 0u;}`
91
+ : ''
92
+ }
93
+ let first=getFirstCollider(pair);let second=getSecondCollider(pair);
94
+ if(!colliderScheduled(first)){return 0u;}
95
+ let previous=contactHistory[pair];let hasContact=manifolds[pair].count>0u;
96
+ let same=previous.x==first&&previous.y==second;
97
+ var flags=CONTACT_PROCESS;
98
+ if(previous.z!=0u&&(!hasContact||!same)){flags|=CONTACT_END;}
99
+ if(hasContact){
100
+ if(previous.z==0u||!same){flags|=CONTACT_BEGIN;}
101
+ else if(contactImpulse(pair).x>${impulseThreshold}){flags|=CONTACT_IMPACT;}
102
+ }
103
+ return flags;
104
+ }
105
+ fn eventCount(flags:u32)->u32{return countOneBits(flags&7u);}
106
+ fn emitContact(sequence:u32,step:u32,first:u32,second:u32,phase:u32,point:vec3f,normal:vec3f,impulse:f32){
107
+ let slot=(sequence-1u)%${capacity}u;
108
+ contactEvents.entries[slot]=ContactEvent(vec4u(sequence,step,phase,0),vec4u(colliderBody(first),colliderBody(second),first,second),vec4f(point,impulse),vec4f(normal,0));
71
109
  }
72
- @compute @workgroup_size(1) fn recordContacts(){
73
- ${rollback ? 'if(eventStatistics[1]!=0u||eventStatistics[15]!=0u){return;}' : ''}
74
- if(contactEvents.step==0xffffffffu){contactEvents.saturated=1u;return;}contactEvents.step++;
75
- for(var pair=0u;pair<PAIR_CAPACITY;pair++){
76
- let previous=contactHistory[pair];let hasContact=manifolds[pair].count>0u;
77
- let first=getFirstCollider(pair);let second=getSecondCollider(pair);
78
- if(!colliderScheduled(first)){continue;}
79
- let same=previous.x==first&&previous.y==second;
80
- if(previous.z!=0u&&(!hasContact||!same)){emitContact(previous.x,previous.y,2u,vec3f(0),vec3f(0),0);}
81
- if(hasContact){
82
- var impulse=0.0;var strongest=0u;
83
- for(var contact=0u;contact<manifolds[pair].count;contact++){
84
- impulse+=max(0.0,manifolds[pair].contacts[contact].impulse.x);
85
- if(manifolds[pair].contacts[contact].impulse.x>manifolds[pair].contacts[strongest].impulse.x){strongest=contact;}
86
- }
87
- let contact=manifolds[pair].contacts[strongest];
88
- if(previous.z==0u||!same){emitContact(first,second,0u,contact.point.xyz,contact.normal.xyz,impulse);}
89
- else if(impulse>${impulseThreshold}){emitContact(first,second,1u,contact.point.xyz,contact.normal.xyz,impulse);}
110
+ fn eventPublish(pair:u32,flags:u32,offset:u32,reservation:vec3u){
111
+ if((flags&CONTACT_PROCESS)==0u){return;}
112
+ let first=getFirstCollider(pair);let second=getSecondCollider(pair);
113
+ if((flags&CONTACT_END)!=0u){
114
+ let sequence=retainedEventSequence(reservation,offset);
115
+ if(sequence!=0u){
116
+ let previous=contactHistory[pair];
117
+ emitContact(sequence,reservation.z,previous.x,previous.y,2u,vec3f(0),vec3f(0),0);
90
118
  }
91
- contactHistory[pair]=vec4u(first,second,select(0u,1u,hasContact),0u);
92
119
  }
93
- }`;
120
+ if((flags&(CONTACT_BEGIN|CONTACT_IMPACT))!=0u){
121
+ let sequence=retainedEventSequence(reservation,offset+select(0u,1u,(flags&CONTACT_END)!=0u));
122
+ if(sequence!=0u){
123
+ let impulse=contactImpulse(pair);
124
+ let contact=manifolds[pair].contacts[u32(impulse.y)];
125
+ let phase=select(1u,0u,(flags&CONTACT_BEGIN)!=0u);
126
+ emitContact(sequence,reservation.z,first,second,phase,contact.point.xyz,contact.normal.xyz,impulse.x);
127
+ }
128
+ }
129
+ contactHistory[pair]=vec4u(first,second,select(0u,1u,manifolds[pair].count>0u),0u);
130
+ }
131
+ `;
94
132
  }
@@ -58,23 +58,21 @@ export function validateRigidBodyJoints(
58
58
  joint.first === joint.second ||
59
59
  [joint.first, joint.second].some(
60
60
  index => !Number.isInteger(index) || index < 0 || index >= bodies.length
61
- ) ||
62
- ![joint.first, joint.second].some(
63
- index =>
64
- (bodies[index].mode ?? ((bodies[index].mass ?? 1) === 0 ? 'static' : 'dynamic')) ===
65
- 'dynamic'
66
61
  )
67
62
  )
68
63
  throw new Error('Invalid joint bodies');
64
+ /** Ordered constraints can remain present while their bodies follow animation. */
65
+ const modes = [joint.first, joint.second].map(index => {
66
+ /** Resolve default static bodies from their mass when mode is omitted. */
67
+ const body = bodies[index];
68
+ return body.mode ?? ((body.mass ?? 1) === 0 ? 'static' : 'dynamic');
69
+ });
70
+ if (modes.every(mode => mode === 'static')) throw new Error('Invalid joint bodies');
69
71
  if (solver === 'parallel') {
70
72
  // Parallel contacts can alternate with a small serial sweep of anchored distance rows.
71
73
  // Dynamic-dynamic joints still require shared island ownership and remain ordered-only.
72
- const anchored = [joint.first, joint.second].some(
73
- index =>
74
- (bodies[index].mode ?? ((bodies[index].mass ?? 1) === 0 ? 'static' : 'dynamic')) ===
75
- 'static'
76
- );
77
- if (joint.type !== 'distance' || !anchored) throw new Error('Unsupported parallel joint');
74
+ if (joint.type !== 'distance' || !modes.includes('static') || !modes.includes('dynamic'))
75
+ throw new Error('Unsupported parallel joint');
78
76
  }
79
77
  if (joint.type === 'general') validateGeneralJoint(joint);
80
78
  for (const frame of [joint.firstFrame, joint.secondFrame]) {