@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.
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.cjs +22 -9
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts +11 -2
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js +27 -10
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.cjs +24 -13
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts +9 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js +41 -14
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +24 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +10 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js +29 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -1
- package/dist/arrow/index.cjs +2 -0
- package/dist/arrow/index.cjs.map +3 -3
- package/dist/arrow/index.d.ts +1 -1
- package/dist/arrow/index.d.ts.map +1 -1
- package/dist/arrow/index.js +1 -1
- package/dist/arrow/index.js.map +1 -1
- package/dist/gpu-core/gpu-bvh-bounds.cjs +63 -0
- package/dist/gpu-core/gpu-bvh-bounds.d.ts +32 -0
- package/dist/gpu-core/gpu-bvh-bounds.d.ts.map +1 -0
- package/dist/gpu-core/gpu-bvh-bounds.js +56 -0
- package/dist/gpu-core/gpu-bvh-bounds.js.map +1 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.cjs +92 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts +41 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts.map +1 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.js +85 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.js.map +1 -0
- package/dist/gpu-core/index.cjs +6 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +4 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +2 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.cjs +6 -6
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js +6 -6
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.cjs +55 -14
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts +13 -2
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.js +58 -17
- package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame.cjs +1 -3
- package/dist/gpu-dataframe/gpu-data-frame.d.ts +10 -0
- package/dist/gpu-dataframe/gpu-data-frame.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame.js +1 -3
- package/dist/gpu-dataframe/gpu-data-frame.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.cjs +94 -44
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts +8 -5
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.js +110 -47
- package/dist/gpu-dataframe/gpu-expression-shader.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.cjs +14 -8
- package/dist/gpu-dataframe/gpu-expression.d.ts +12 -1
- package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.js +11 -6
- package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +2 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +4 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.cjs +2 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts +5 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js +6 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +113 -88
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +6 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js +111 -85
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +286 -48
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts +17 -2
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +290 -39
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.cjs +8 -6
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts +7 -1
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.js +9 -5
- package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.cjs +8 -6
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.js +9 -7
- package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.cjs +37 -11
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts +3 -1
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.js +36 -10
- package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
- package/dist/gpu-dataframe/index.cjs +4 -2
- package/dist/gpu-dataframe/index.cjs.map +3 -3
- package/dist/gpu-dataframe/index.d.ts +1 -1
- package/dist/gpu-dataframe/index.d.ts.map +1 -1
- package/dist/gpu-dataframe/index.js +1 -1
- package/dist/gpu-dataframe/index.js.map +1 -1
- package/dist/gpu-physics/gpu-physics-batch.cjs +11 -10
- package/dist/gpu-physics/gpu-physics-batch.d.ts +1 -0
- package/dist/gpu-physics/gpu-physics-batch.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-batch.js +14 -10
- package/dist/gpu-physics/gpu-physics-batch.js.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.cjs +9 -4
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts +10 -1
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.js +11 -4
- package/dist/gpu-physics/gpu-physics-ensemble.js.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +261 -68
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +47 -2
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +324 -75
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs.map +3 -3
- package/dist/gpu-physics/index.d.ts +2 -1
- package/dist/gpu-physics/index.d.ts.map +1 -1
- package/dist/gpu-physics/index.js.map +1 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.cjs +10 -6
- package/dist/gpu-physics/rigid-body-cache-shaders.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.js +15 -6
- package/dist/gpu-physics/rigid-body-cache-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-capacity.cjs +15 -2
- package/dist/gpu-physics/rigid-body-capacity.d.ts +3 -1
- package/dist/gpu-physics/rigid-body-capacity.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-capacity.js +21 -2
- package/dist/gpu-physics/rigid-body-capacity.js.map +1 -1
- package/dist/gpu-physics/rigid-body-cast-index.cjs +192 -0
- package/dist/gpu-physics/rigid-body-cast-index.d.ts +44 -0
- package/dist/gpu-physics/rigid-body-cast-index.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-cast-index.js +194 -0
- package/dist/gpu-physics/rigid-body-cast-index.js.map +1 -0
- package/dist/gpu-physics/rigid-body-ensemble-layout.cjs +4 -2
- package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-layout.js +5 -2
- package/dist/gpu-physics/rigid-body-ensemble-layout.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.cjs +11 -9
- package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.js +13 -9
- package/dist/gpu-physics/rigid-body-ensemble-reset.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-shaders.cjs +14 -7
- package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts +5 -0
- package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-shaders.js +17 -7
- package/dist/gpu-physics/rigid-body-ensemble-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.cjs +21 -11
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts +2 -2
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js +28 -12
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js.map +1 -1
- package/dist/gpu-physics/rigid-body-event-compaction.cjs +184 -0
- package/dist/gpu-physics/rigid-body-event-compaction.d.ts +35 -0
- package/dist/gpu-physics/rigid-body-event-compaction.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-event-compaction.js +168 -0
- package/dist/gpu-physics/rigid-body-event-compaction.js.map +1 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.cjs +51 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.d.ts +33 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.js +34 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.js.map +1 -0
- package/dist/gpu-physics/rigid-body-events.cjs +57 -25
- package/dist/gpu-physics/rigid-body-events.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-events.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-events.js +60 -25
- package/dist/gpu-physics/rigid-body-events.js.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.cjs +8 -3
- package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.js +10 -6
- package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
- package/dist/gpu-physics/rigid-body-queries.cjs +159 -16
- package/dist/gpu-physics/rigid-body-queries.d.ts +24 -1
- package/dist/gpu-physics/rigid-body-queries.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-queries.js +166 -14
- package/dist/gpu-physics/rigid-body-queries.js.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.cjs +3 -3
- package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.js +3 -3
- package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.cjs +53 -15
- package/dist/gpu-physics/rigid-body-triggers.d.ts +1 -0
- package/dist/gpu-physics/rigid-body-triggers.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.js +55 -15
- package/dist/gpu-physics/rigid-body-triggers.js.map +1 -1
- package/dist/gpu-physics/sphere-world-shaders.cjs +48 -20
- package/dist/gpu-physics/sphere-world-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/sphere-world-shaders.js +51 -21
- package/dist/gpu-physics/sphere-world-shaders.js.map +1 -1
- package/dist/gpu-project/benchmarks.cjs.map +2 -2
- package/dist/gpu-project/crs.cjs.map +2 -2
- package/dist/gpu-project/index.cjs.map +2 -2
- package/dist/gpu-project/projection-program.cjs +2 -9
- package/dist/gpu-project/projection-program.d.ts.map +1 -1
- package/dist/gpu-project/projection-program.js +1 -8
- package/dist/gpu-project/projection-program.js.map +1 -1
- package/dist/gpu-sql/gpu-sql.cjs +203 -59
- package/dist/gpu-sql/gpu-sql.d.ts +36 -1
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +225 -62
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +3 -3
- package/dist/gpu-sql/index.d.ts +1 -1
- package/dist/gpu-sql/index.d.ts.map +1 -1
- package/dist/utils/float32.cjs +35 -0
- package/dist/utils/float32.d.ts +3 -0
- package/dist/utils/float32.d.ts.map +1 -0
- package/dist/utils/float32.js +16 -0
- package/dist/utils/float32.js.map +1 -0
- package/package.json +4 -4
- package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +77 -25
- package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +52 -16
- package/src/arrow/gpu/arrow-gpu-table-conversion.ts +46 -1
- package/src/arrow/index.ts +1 -0
- package/src/gpu-core/gpu-bvh-bounds.ts +84 -0
- package/src/gpu-core/gpu-command-graph-submission-pacer.ts +102 -0
- package/src/gpu-core/index.ts +5 -0
- package/src/gpu-dataframe/gpu-analytics-compiler-utils.ts +7 -10
- package/src/gpu-dataframe/gpu-data-frame-query.ts +106 -25
- package/src/gpu-dataframe/gpu-data-frame.ts +35 -2
- package/src/gpu-dataframe/gpu-expression-shader.ts +172 -58
- package/src/gpu-dataframe/gpu-expression.ts +62 -9
- package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +6 -2
- package/src/gpu-dataframe/gpu-global-aggregation-query.ts +12 -3
- package/src/gpu-dataframe/gpu-global-sort-compiler.ts +151 -93
- package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +469 -52
- package/src/gpu-dataframe/gpu-group-by-query.ts +24 -10
- package/src/gpu-dataframe/gpu-join-compiler.ts +12 -6
- package/src/gpu-dataframe/gpu-query-compiler.ts +60 -18
- package/src/gpu-dataframe/index.ts +1 -1
- package/src/gpu-physics/gpu-physics-batch.ts +19 -13
- package/src/gpu-physics/gpu-physics-ensemble.ts +20 -4
- package/src/gpu-physics/gpu-rigid-body-world.ts +421 -93
- package/src/gpu-physics/index.ts +9 -0
- package/src/gpu-physics/rigid-body-cache-shaders.ts +18 -6
- package/src/gpu-physics/rigid-body-capacity.ts +25 -4
- package/src/gpu-physics/rigid-body-cast-index.ts +277 -0
- package/src/gpu-physics/rigid-body-ensemble-layout.ts +6 -2
- package/src/gpu-physics/rigid-body-ensemble-reset.ts +21 -9
- package/src/gpu-physics/rigid-body-ensemble-shaders.ts +18 -7
- package/src/gpu-physics/rigid-body-ensemble-transaction.ts +31 -13
- package/src/gpu-physics/rigid-body-event-compaction.ts +252 -0
- package/src/gpu-physics/rigid-body-event-snapshot.ts +76 -0
- package/src/gpu-physics/rigid-body-events.ts +63 -25
- package/src/gpu-physics/rigid-body-joints.ts +9 -11
- package/src/gpu-physics/rigid-body-queries.ts +202 -14
- package/src/gpu-physics/rigid-body-shaders.ts +4 -3
- package/src/gpu-physics/rigid-body-triggers.ts +64 -20
- package/src/gpu-physics/sphere-world-shaders.ts +53 -21
- package/src/gpu-project/projection-program.ts +1 -9
- package/src/gpu-sql/gpu-sql.ts +405 -91
- package/src/gpu-sql/index.ts +1 -1
- 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 {
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
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.
|
|
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.
|
|
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
|
|
@@ -2387,18 +2479,29 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2387
2479
|
readContactEvents() {
|
|
2388
2480
|
if (!this.contactEvents || this.destroyed)
|
|
2389
2481
|
return Promise.reject(new Error('Contact events are not enabled'));
|
|
2390
|
-
|
|
2391
|
-
|
|
2482
|
+
/** Queue the copy now, then decode only after any preceding recovery sets the cursor. */
|
|
2483
|
+
const afterSnapshot = this.contactSnapshotRead;
|
|
2484
|
+
if (this.eventRead && (!afterSnapshot || this.eventRead.afterSnapshot === afterSnapshot))
|
|
2485
|
+
return this.eventRead.result;
|
|
2486
|
+
/** Register the read before recovery can clear its own busy flag. */
|
|
2487
|
+
const pending = {
|
|
2488
|
+
afterSnapshot,
|
|
2489
|
+
result: this.contactEvents
|
|
2392
2490
|
.readAsync()
|
|
2491
|
+
.finally(() => afterSnapshot)
|
|
2393
2492
|
.then(bytes => {
|
|
2493
|
+
/** The newest stream cursor is available once the preceding snapshot resolves. */
|
|
2394
2494
|
const batch = decodeRigidBodyContactEvents(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), this.eventCursor);
|
|
2395
2495
|
this.eventCursor = batch.sequence;
|
|
2396
2496
|
return batch;
|
|
2397
2497
|
})
|
|
2398
2498
|
.finally(() => {
|
|
2399
|
-
this.eventRead
|
|
2400
|
-
|
|
2401
|
-
|
|
2499
|
+
if (this.eventRead === pending)
|
|
2500
|
+
this.eventRead = null;
|
|
2501
|
+
})
|
|
2502
|
+
};
|
|
2503
|
+
this.eventRead = pending;
|
|
2504
|
+
return pending.result;
|
|
2402
2505
|
}
|
|
2403
2506
|
/** Nearest exact sphere/OBB hit. Origins inside a shape return distance zero and a zero normal. */
|
|
2404
2507
|
raycast(query) {
|
|
@@ -2408,6 +2511,74 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2408
2511
|
overlapSphere(query) {
|
|
2409
2512
|
return this.runQuery(query);
|
|
2410
2513
|
}
|
|
2514
|
+
/**
|
|
2515
|
+
* Query the closest hit for each ray or sphere cast with one submission and readback.
|
|
2516
|
+
* Results follow input order. This snapshots already submitted poses, using one shared collider selection.
|
|
2517
|
+
*/
|
|
2518
|
+
async castBatch(commands, options = {}) {
|
|
2519
|
+
if (!this.device ||
|
|
2520
|
+
!this.batchCast ||
|
|
2521
|
+
!this.querySelection ||
|
|
2522
|
+
!this.batchCastCommands ||
|
|
2523
|
+
!this.batchCastResults ||
|
|
2524
|
+
this.destroyed ||
|
|
2525
|
+
this.queryPending)
|
|
2526
|
+
throw new Error('Batched collision casts are disabled or busy');
|
|
2527
|
+
if (commands.length > this.props.queryBatchCapacity)
|
|
2528
|
+
throw new Error('Collision cast batch exceeds capacity');
|
|
2529
|
+
if (!commands.length)
|
|
2530
|
+
return [];
|
|
2531
|
+
if (options.strategy === 'indexed' && !this.props.queryBatchIndex)
|
|
2532
|
+
throw new Error('Batched collision cast index is disabled');
|
|
2533
|
+
/** The scan remains available for short or dense workloads and reference comparisons. */
|
|
2534
|
+
const order = options.strategy === 'scan' ? null : this.batchCastOrder;
|
|
2535
|
+
/** Deduplicate the shared selection before publishing any GPU input. */
|
|
2536
|
+
const selection = options.colliderIndices
|
|
2537
|
+
? Uint32Array.from(new Set(this.validateQueryColliders(options.colliderIndices)))
|
|
2538
|
+
: (order?.indices ?? Uint32Array.from({ length: this.colliderCount }, (_, index) => index));
|
|
2539
|
+
/** The indexed prefix can be empty when a filter selects only extended geometry. */
|
|
2540
|
+
let indexedCount = order?.indexedCount ?? 0;
|
|
2541
|
+
if (order && options.colliderIndices) {
|
|
2542
|
+
selection.sort((first, second) => order.ranks[first] - order.ranks[second]);
|
|
2543
|
+
/** All selected primitives precede the extended collider fallback. */
|
|
2544
|
+
const firstExtended = selection.findIndex(index => order.ranks[index] >= order.indexedCount);
|
|
2545
|
+
indexedCount = firstExtended < 0 ? selection.length : firstExtended;
|
|
2546
|
+
}
|
|
2547
|
+
/** Validate and encode all commands before changing staging data. */
|
|
2548
|
+
const data = packRigidBodyBatchCasts(commands, this.count, selection.length, indexedCount);
|
|
2549
|
+
this.queryPending = true;
|
|
2550
|
+
try {
|
|
2551
|
+
this.batchCastCommands.write(data);
|
|
2552
|
+
if (selection.length)
|
|
2553
|
+
this.querySelection.write(selection);
|
|
2554
|
+
/** Submit after any preceding pose changes in device queue order. */
|
|
2555
|
+
const encoder = this.device.createCommandEncoder();
|
|
2556
|
+
if (this.batchCastIndex && indexedCount) {
|
|
2557
|
+
this.batchCastIndex.encode(encoder, { parameters: commands.length });
|
|
2558
|
+
}
|
|
2559
|
+
else {
|
|
2560
|
+
/** One workgroup handles one command and reduces its collider results locally. */
|
|
2561
|
+
const pass = encoder.beginComputePass();
|
|
2562
|
+
this.batchCast.kernel.dispatch(pass, {
|
|
2563
|
+
bindings: this.batchCast.bindings,
|
|
2564
|
+
x: commands.length
|
|
2565
|
+
});
|
|
2566
|
+
pass.end();
|
|
2567
|
+
}
|
|
2568
|
+
this.device.submit(encoder.finish());
|
|
2569
|
+
return decodeRigidBodyBatchCasts(await this.batchCastResults.readAsync(0, commands.length * RIGID_BODY_BATCH_RESULT_BYTES));
|
|
2570
|
+
}
|
|
2571
|
+
finally {
|
|
2572
|
+
this.queryPending = false;
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
/** Reject invalid indices before scalar or batch query buffers are written. */
|
|
2576
|
+
validateQueryColliders(indices) {
|
|
2577
|
+
for (const index of indices)
|
|
2578
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.colliderCount)
|
|
2579
|
+
throw new Error('Invalid query collider');
|
|
2580
|
+
return indices;
|
|
2581
|
+
}
|
|
2411
2582
|
async runQuery(query) {
|
|
2412
2583
|
if (!this.device ||
|
|
2413
2584
|
!this.queryComputation ||
|
|
@@ -2444,9 +2615,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2444
2615
|
throw new Error('Invalid collision query');
|
|
2445
2616
|
const selected = query.colliderIndices ?? Array.from({ length: this.colliderCount }, (_, index) => index);
|
|
2446
2617
|
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');
|
|
2618
|
+
for (const index of this.validateQueryColliders(selected)) {
|
|
2450
2619
|
const collider = this.colliders[index];
|
|
2451
2620
|
if (collider.body === query.excludeBody)
|
|
2452
2621
|
continue;
|
|
@@ -2476,16 +2645,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2476
2645
|
const bytes = await this.queryOutput.readAsync(0, 16 + maximumHits * 48);
|
|
2477
2646
|
const words = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
2478
2647
|
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
|
-
});
|
|
2648
|
+
const hits = Array.from({ length: words[0] }, (_, index) => decodeRigidBodyQueryHit(words, floats, 4 + index * 12));
|
|
2489
2649
|
return {
|
|
2490
2650
|
hits,
|
|
2491
2651
|
totalHits: words[1],
|
|
@@ -2536,19 +2696,107 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2536
2696
|
readTriggerEvents() {
|
|
2537
2697
|
if (!this.triggerEvents || this.destroyed)
|
|
2538
2698
|
throw new Error('Triggers are disabled');
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
this.triggerRead
|
|
2542
|
-
.
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2699
|
+
/** Queue the copy in caller order, including when recovery is still mapping. */
|
|
2700
|
+
const afterSnapshot = this.triggerSnapshotRead;
|
|
2701
|
+
if (this.triggerRead && (!afterSnapshot || this.triggerRead.afterSnapshot === afterSnapshot))
|
|
2702
|
+
return this.triggerRead.result;
|
|
2703
|
+
/** Track the read immediately so checkpoint operations see a busy world. */
|
|
2704
|
+
const pending = {
|
|
2705
|
+
afterSnapshot,
|
|
2706
|
+
result: this.triggerEvents
|
|
2707
|
+
.readAsync()
|
|
2708
|
+
.finally(() => afterSnapshot)
|
|
2709
|
+
.then(bytes => {
|
|
2710
|
+
/** The snapshot has established the sequence used to decode this delta. */
|
|
2711
|
+
const batch = decodeRigidBodyTriggerEvents(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), this.triggerCursor);
|
|
2712
|
+
this.triggerCursor = batch.sequence;
|
|
2713
|
+
return batch;
|
|
2714
|
+
})
|
|
2715
|
+
.finally(() => {
|
|
2716
|
+
if (this.triggerRead === pending)
|
|
2717
|
+
this.triggerRead = null;
|
|
2718
|
+
})
|
|
2719
|
+
};
|
|
2720
|
+
this.triggerRead = pending;
|
|
2721
|
+
return pending.result;
|
|
2722
|
+
}
|
|
2723
|
+
/** Recover the active contact set and advance the incremental cursor to the snapshot. */
|
|
2724
|
+
resyncContactEvents() {
|
|
2725
|
+
if (!this.device || !this.contactEvents || !this.contactHistory || this.destroyed)
|
|
2726
|
+
return Promise.reject(new Error('Contact events are not enabled'));
|
|
2727
|
+
if (this.contactSnapshotRead)
|
|
2728
|
+
return this.contactSnapshotRead;
|
|
2729
|
+
/** An earlier incremental read may still be advancing its cursor. */
|
|
2730
|
+
const priorRead = this.eventRead?.result.catch(() => undefined);
|
|
2731
|
+
/** Capture immediately, even when a previous delta read is still mapping. */
|
|
2732
|
+
const snapshot = readRigidBodyEventSnapshot(this.device, this.contactEvents, this.contactHistory, (header, rows) => {
|
|
2733
|
+
/** The retained history contains active pairs, independent of event retention. */
|
|
2734
|
+
const contacts = [];
|
|
2735
|
+
for (let offset = 0; offset < rows.length; offset += 4) {
|
|
2736
|
+
if (rows[offset + 2] === 0)
|
|
2737
|
+
continue;
|
|
2738
|
+
/** A contact history row stores the two original collider IDs. */
|
|
2739
|
+
const first = rows[offset];
|
|
2740
|
+
/** Compound collider IDs map back to their owning bodies. */
|
|
2741
|
+
const second = rows[offset + 1];
|
|
2742
|
+
contacts.push({
|
|
2743
|
+
colliders: [first, second],
|
|
2744
|
+
bodies: [this.colliders[first].body, this.colliders[second].body]
|
|
2745
|
+
});
|
|
2746
|
+
}
|
|
2747
|
+
return { ...header, contacts };
|
|
2748
|
+
});
|
|
2749
|
+
this.contactSnapshotRead = snapshot
|
|
2750
|
+
.finally(() => priorRead)
|
|
2751
|
+
.then(result => {
|
|
2752
|
+
this.eventCursor = result.sequence;
|
|
2753
|
+
return result;
|
|
2754
|
+
})
|
|
2755
|
+
.finally(() => {
|
|
2756
|
+
this.contactSnapshotRead = null;
|
|
2757
|
+
});
|
|
2758
|
+
return this.contactSnapshotRead;
|
|
2759
|
+
}
|
|
2760
|
+
/** Recover the active trigger overlap set and advance the incremental trigger cursor. */
|
|
2761
|
+
resyncTriggerEvents() {
|
|
2762
|
+
if (!this.device || !this.triggerEvents || !this.triggerHistory || this.destroyed)
|
|
2763
|
+
return Promise.reject(new Error('Triggers are disabled'));
|
|
2764
|
+
if (this.triggerSnapshotRead)
|
|
2765
|
+
return this.triggerSnapshotRead;
|
|
2766
|
+
/** Preserve authored trigger and target-body identities alongside the sampled pairs. */
|
|
2767
|
+
const { buffer, groups } = this.triggerHistory;
|
|
2768
|
+
/** Wait for prior cursor updates before replacing them with the new recovery point. */
|
|
2769
|
+
const priorRead = this.triggerRead?.result.catch(() => undefined);
|
|
2770
|
+
/** Read only the history bit and representative collider pair for each group. */
|
|
2771
|
+
const snapshot = readRigidBodyEventSnapshot(this.device, this.triggerEvents, buffer, (header, rows) => {
|
|
2772
|
+
/** Swept crossings with no final overlap are absent from this state. */
|
|
2773
|
+
const overlaps = [];
|
|
2774
|
+
for (let offset = 0; offset < rows.length; offset += 4) {
|
|
2775
|
+
if ((rows[offset] & 1) === 0)
|
|
2776
|
+
continue;
|
|
2777
|
+
overlaps.push({
|
|
2778
|
+
trigger: groups[offset],
|
|
2779
|
+
body: groups[offset + 1],
|
|
2780
|
+
triggerCollider: rows[offset + 1],
|
|
2781
|
+
collider: rows[offset + 2]
|
|
2782
|
+
});
|
|
2783
|
+
}
|
|
2784
|
+
return { ...header, overlaps };
|
|
2785
|
+
});
|
|
2786
|
+
this.triggerSnapshotRead = snapshot
|
|
2787
|
+
.finally(() => priorRead)
|
|
2788
|
+
.then(result => {
|
|
2789
|
+
this.triggerCursor = result.sequence;
|
|
2790
|
+
return result;
|
|
2547
2791
|
})
|
|
2548
2792
|
.finally(() => {
|
|
2549
|
-
this.
|
|
2793
|
+
this.triggerSnapshotRead = null;
|
|
2550
2794
|
});
|
|
2551
|
-
return this.
|
|
2795
|
+
return this.triggerSnapshotRead;
|
|
2796
|
+
}
|
|
2797
|
+
/** Reset, capture and origin operations require stable event cursors. */
|
|
2798
|
+
get eventReadsPending() {
|
|
2799
|
+
return Boolean(this.eventRead || this.triggerRead || this.contactSnapshotRead || this.triggerSnapshotRead);
|
|
2552
2800
|
}
|
|
2553
2801
|
getSnapshotBuffers(includeRollbackScratch = true) {
|
|
2554
2802
|
return this.ownedBuffers.filter(buffer => includeRollbackScratch || !buffer.id.startsWith(`${this.id}-checkpoint-`));
|
|
@@ -2584,7 +2832,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2584
2832
|
throw error;
|
|
2585
2833
|
}
|
|
2586
2834
|
const copy = (restore) => {
|
|
2587
|
-
if (released || this.destroyed || this.queryPending || this.
|
|
2835
|
+
if (released || this.destroyed || this.queryPending || this.eventReadsPending)
|
|
2588
2836
|
throw new Error('Checkpoint requires an idle live world');
|
|
2589
2837
|
const encoder = device.createCommandEncoder();
|
|
2590
2838
|
for (const [index, buffer] of checkpointBuffers.entries())
|
|
@@ -2642,7 +2890,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2642
2890
|
}
|
|
2643
2891
|
/** Stop graph submissions and controls first; includes diagnostics, caches and event history. */
|
|
2644
2892
|
async captureState(options = {}) {
|
|
2645
|
-
if (!this.device || this.destroyed || this.queryPending || this.
|
|
2893
|
+
if (!this.device || this.destroyed || this.queryPending || this.eventReadsPending)
|
|
2646
2894
|
throw new Error('Capture requires an idle attached world');
|
|
2647
2895
|
return {
|
|
2648
2896
|
version: 1,
|
|
@@ -2667,8 +2915,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2667
2915
|
if (!this.device ||
|
|
2668
2916
|
this.destroyed ||
|
|
2669
2917
|
this.queryPending ||
|
|
2670
|
-
this.
|
|
2671
|
-
this.triggerRead ||
|
|
2918
|
+
this.eventReadsPending ||
|
|
2672
2919
|
capture.version !== 1 ||
|
|
2673
2920
|
Boolean(capture.terrainAtlasLeases) !== Boolean(this.terrainAtlas) ||
|
|
2674
2921
|
!Number.isInteger(terrainRevision) ||
|
|
@@ -2833,6 +3080,8 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2833
3080
|
this.terrainWake?.kernel.destroy();
|
|
2834
3081
|
this.queryComputation?.kernel.destroy();
|
|
2835
3082
|
this.queryReduction?.kernel.destroy();
|
|
3083
|
+
this.batchCastIndex?.destroy();
|
|
3084
|
+
this.batchCast?.kernel.destroy();
|
|
2836
3085
|
for (const buffer of this.ownedBuffers)
|
|
2837
3086
|
buffer.destroy();
|
|
2838
3087
|
this.ownedBuffers.length = 0;
|