@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
|
@@ -24,11 +24,11 @@ var import_bound_kernel = require("../gpu-core/utils/bound-kernel.cjs");
|
|
|
24
24
|
var import_core = require("@luma.gl/core");
|
|
25
25
|
var import_rigid_body_vehicle = require("./rigid-body-vehicle.cjs");
|
|
26
26
|
var import_rigid_body_ensemble_layout = require("./rigid-body-ensemble-layout.cjs");
|
|
27
|
-
function addEnsembleCheckpoint(graph, id, states, statistics, ensemble, manifolds, bodiesPerInstance, maximumPairs, allocate, vehicles) {
|
|
27
|
+
function addEnsembleCheckpoint(graph, id, states, statistics, ensemble, manifolds, bodiesPerInstance, maximumPairs, allocate, vehicles, pairsPerInstance) {
|
|
28
28
|
const bodyCount = states[0].buffer.byteLength / 16;
|
|
29
29
|
const instances = bodyCount / bodiesPerInstance;
|
|
30
30
|
const targets = states[5];
|
|
31
|
-
const { headOffset, linkOffset, journalOffset, savedKeyOffset, savedLinkOffset, savedHeadOffset, savedHeaderOffset, savedManifoldOffset } = (0, import_rigid_body_ensemble_layout.getEnsembleContactLayout)(bodyCount, instances, maximumPairs);
|
|
31
|
+
const { headOffset, linkOffset, journalOffset, savedKeyOffset, savedLinkOffset, savedHeadOffset, savedHeaderOffset, savedManifoldOffset, failureOffset } = (0, import_rigid_body_ensemble_layout.getEnsembleContactLayout)(bodyCount, instances, maximumPairs, Boolean(pairsPerInstance));
|
|
32
32
|
const importAllocation = (name, byteLength) => {
|
|
33
33
|
const buffer = allocate(name, byteLength);
|
|
34
34
|
return {
|
|
@@ -82,6 +82,10 @@ ${source}`,
|
|
|
82
82
|
compileAsync: async () => executable(await (0, import_bound_kernel.createBoundKernelAsync)(graph.device, properties))
|
|
83
83
|
});
|
|
84
84
|
};
|
|
85
|
+
const sharedFailure = "statistics[1]!=0u||statistics[15]!=0u";
|
|
86
|
+
const anyFailure = pairsPerInstance ? `${sharedFailure}||targets[${failureOffset + instances}u]!=0u` : sharedFailure;
|
|
87
|
+
const localFailure = (instance) => `targets[${failureOffset}u+${instance}]!=0u`;
|
|
88
|
+
const localFailureInput = pairsPerInstance ? [{ ...targets, name: "targets" }] : [];
|
|
85
89
|
const bodyAddress = `let work=invocation.x;if(work>=ensemble[0]*${bodiesPerInstance}u){return;}
|
|
86
90
|
let body=ensemble[${16 + instances * 8}u+work/${bodiesPerInstance}u]*${bodiesPerInstance}u+work%${bodiesPerInstance}u;`;
|
|
87
91
|
const copyVehicleState = (restore2) => {
|
|
@@ -92,11 +96,13 @@ ${source}`,
|
|
|
92
96
|
{ ...vehicles.state, name: "vehicle", writable: restore2 },
|
|
93
97
|
{ ...vehicleSnapshot, name: "snapshot", writable: !restore2 },
|
|
94
98
|
{ ...ensemble, name: "ensemble" },
|
|
95
|
-
...restore2 ? [{ ...statistics, name: "statistics" }] : []
|
|
99
|
+
...restore2 ? [{ ...statistics, name: "statistics" }, ...localFailureInput] : []
|
|
96
100
|
], `@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
|
|
97
|
-
${restore2 ?
|
|
101
|
+
${restore2 ? `if(!(${anyFailure})){return;}` : ""}
|
|
98
102
|
let work=invocation.x;if(work>=ensemble[0]*${count}u){return;}
|
|
99
|
-
let
|
|
103
|
+
let instance=ensemble[${16 + instances * 8}u+work/${count}u];
|
|
104
|
+
${restore2 && pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure("instance")})){return;}` : ""}
|
|
105
|
+
let row=(instance*${count}u+work%${count}u)*${import_rigid_body_vehicle.VEHICLE_STRIDE / 4}u;
|
|
100
106
|
for(var word=0u;word<${import_rigid_body_vehicle.VEHICLE_STRIDE / 4}u;word++){
|
|
101
107
|
${restore2 ? "vehicle[row+word]=snapshot[row+word];" : "snapshot[row+word]=vehicle[row+word];"}
|
|
102
108
|
}
|
|
@@ -134,10 +140,11 @@ ${source}`,
|
|
|
134
140
|
{ ...statistics, name: "statistics" }
|
|
135
141
|
], `
|
|
136
142
|
@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
|
|
137
|
-
if(
|
|
143
|
+
if(!(${anyFailure})){return;}
|
|
138
144
|
let count=targets[${bodyCount * 8 + 5}u];
|
|
139
145
|
for(var work=invocation.x;work<count*104u;work+=64u){
|
|
140
146
|
let pair=targets[${journalOffset}u+work/104u];let word=work%104u;
|
|
147
|
+
${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`pair/${pairsPerInstance}u`)})){continue;}` : ""}
|
|
141
148
|
manifolds[pair*104u+word]=targets[${savedManifoldOffset}u+pair*104u+word];
|
|
142
149
|
}
|
|
143
150
|
}`);
|
|
@@ -147,30 +154,33 @@ ${source}`,
|
|
|
147
154
|
{ ...statistics, name: "statistics" }
|
|
148
155
|
], `
|
|
149
156
|
@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
|
|
150
|
-
if(
|
|
157
|
+
if(!(${anyFailure})){return;}
|
|
151
158
|
let count=targets[${bodyCount * 8 + 5}u];
|
|
152
159
|
for(var index=invocation.x;index<count;index+=64u){let pair=targets[${journalOffset}u+index];
|
|
160
|
+
${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`pair/${pairsPerInstance}u`)})){continue;}` : ""}
|
|
153
161
|
targets[${bodyCount * 8 + 8}u+pair*2u]=targets[${savedKeyOffset}u+pair*2u];
|
|
154
162
|
targets[${bodyCount * 8 + 9}u+pair*2u]=targets[${savedKeyOffset + 1}u+pair*2u];
|
|
155
163
|
targets[${linkOffset}u+pair]=targets[${savedLinkOffset}u+pair];
|
|
156
164
|
}
|
|
157
165
|
for(var work=invocation.x;work<ensemble[0];work+=64u){let instance=ensemble[${16 + instances * 8}u+work];
|
|
166
|
+
${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure("instance")})){continue;}` : ""}
|
|
158
167
|
targets[${headOffset}u+instance]=targets[${savedHeadOffset}u+instance];
|
|
159
168
|
targets[${headOffset + instances}u+instance]=targets[${savedHeadOffset + instances}u+instance];
|
|
160
169
|
}
|
|
161
|
-
storageBarrier();
|
|
162
170
|
// Preserve the attempted step's journal list and counters so the next prepare can clear its marks.
|
|
163
|
-
if(invocation.x<5u){targets[${bodyCount * 8}u+invocation.x]=targets[${savedHeaderOffset}u+invocation.x];}
|
|
171
|
+
if((${sharedFailure})&&invocation.x<5u){targets[${bodyCount * 8}u+invocation.x]=targets[${savedHeaderOffset}u+invocation.x];}
|
|
164
172
|
}`);
|
|
165
173
|
copyVehicleState(true);
|
|
166
174
|
states.slice(0, 5).forEach((state, index) => addCompute(`rollback-${index}`, [
|
|
167
175
|
{ ...state, name: "state", writable: true },
|
|
168
176
|
{ ...snapshots[index], name: "snapshot" },
|
|
169
177
|
{ ...statistics, name: "statistics" },
|
|
170
|
-
{ ...ensemble, name: "ensemble" }
|
|
178
|
+
{ ...ensemble, name: "ensemble" },
|
|
179
|
+
...localFailureInput
|
|
171
180
|
], `@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
|
|
172
|
-
if(
|
|
181
|
+
if(!(${anyFailure})){return;}
|
|
173
182
|
${bodyAddress}
|
|
183
|
+
${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`body/${bodiesPerInstance}u`)})){return;}` : ""}
|
|
174
184
|
for(var word=0u;word<4u;word++){state[body*4u+word]=snapshot[body*4u+word];}
|
|
175
185
|
}`, true));
|
|
176
186
|
};
|
|
@@ -4,11 +4,11 @@ type Resource = {
|
|
|
4
4
|
buffer: Buffer;
|
|
5
5
|
resource: GraphBufferHandle;
|
|
6
6
|
};
|
|
7
|
-
/** Snapshot active bodies and journal contact writes
|
|
7
|
+
/** Snapshot active bodies and journal contact writes and restore failed contact partitions or an entire failed shared step. */
|
|
8
8
|
export declare function addEnsembleCheckpoint<GraphParameters>(graph: GPUCommandGraph<GraphParameters>, id: string, states: Resource[], statistics: Resource, ensemble: Resource, manifolds: Resource, bodiesPerInstance: number, maximumPairs: number, allocate: (name: string, byteLength: number) => Buffer, vehicles?: {
|
|
9
9
|
state: Resource;
|
|
10
10
|
vehiclesPerInstance: number;
|
|
11
|
-
}): {
|
|
11
|
+
}, pairsPerInstance?: number): {
|
|
12
12
|
save: () => void;
|
|
13
13
|
restore: () => void;
|
|
14
14
|
validate: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rigid-body-ensemble-transaction.d.ts","sourceRoot":"","sources":["../../src/gpu-physics/rigid-body-ensemble-transaction.ts"],"names":[],"mappings":"AAUA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAIrC,OAAO,KAAK,EAAC,eAAe,EAAE,iBAAiB,EAAC,yCAAsC;AAEtF,KAAK,QAAQ,GAAG;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,iBAAiB,CAAA;CAAC,CAAC;AAE9D
|
|
1
|
+
{"version":3,"file":"rigid-body-ensemble-transaction.d.ts","sourceRoot":"","sources":["../../src/gpu-physics/rigid-body-ensemble-transaction.ts"],"names":[],"mappings":"AAUA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAIrC,OAAO,KAAK,EAAC,eAAe,EAAE,iBAAiB,EAAC,yCAAsC;AAEtF,KAAK,QAAQ,GAAG;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,iBAAiB,CAAA;CAAC,CAAC;AAE9D,+HAA+H;AAC/H,wBAAgB,qBAAqB,CAAC,eAAe,EACnD,KAAK,EAAE,eAAe,CAAC,eAAe,CAAC,EACvC,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,QAAQ,EAAE,EAClB,UAAU,EAAE,QAAQ,EACpB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,QAAQ,EACnB,iBAAiB,EAAE,MAAM,EACzB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,EACtD,QAAQ,CAAC,EAAE;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAC,EACzD,gBAAgB,CAAC,EAAE,MAAM;;;;;;gBAdF,MAAM;kBAAY,iBAAiB;;EA8P3D"}
|
|
@@ -5,12 +5,12 @@ import { createBoundKernel, createBoundKernelAsync } from "../gpu-core/utils/bou
|
|
|
5
5
|
import { Buffer } from '@luma.gl/core';
|
|
6
6
|
import { VEHICLE_STRIDE } from "./rigid-body-vehicle.js";
|
|
7
7
|
import { getEnsembleContactLayout } from "./rigid-body-ensemble-layout.js";
|
|
8
|
-
/** Snapshot active bodies and journal contact writes
|
|
9
|
-
export function addEnsembleCheckpoint(graph, id, states, statistics, ensemble, manifolds, bodiesPerInstance, maximumPairs, allocate, vehicles) {
|
|
8
|
+
/** Snapshot active bodies and journal contact writes and restore failed contact partitions or an entire failed shared step. */
|
|
9
|
+
export function addEnsembleCheckpoint(graph, id, states, statistics, ensemble, manifolds, bodiesPerInstance, maximumPairs, allocate, vehicles, pairsPerInstance) {
|
|
10
10
|
const bodyCount = states[0].buffer.byteLength / 16;
|
|
11
11
|
const instances = bodyCount / bodiesPerInstance;
|
|
12
12
|
const targets = states[5];
|
|
13
|
-
const { headOffset, linkOffset, journalOffset, savedKeyOffset, savedLinkOffset, savedHeadOffset, savedHeaderOffset, savedManifoldOffset } = getEnsembleContactLayout(bodyCount, instances, maximumPairs);
|
|
13
|
+
const { headOffset, linkOffset, journalOffset, savedKeyOffset, savedLinkOffset, savedHeadOffset, savedHeaderOffset, savedManifoldOffset, failureOffset } = getEnsembleContactLayout(bodyCount, instances, maximumPairs, Boolean(pairsPerInstance));
|
|
14
14
|
const importAllocation = (name, byteLength) => {
|
|
15
15
|
const buffer = allocate(name, byteLength);
|
|
16
16
|
return {
|
|
@@ -66,6 +66,16 @@ export function addEnsembleCheckpoint(graph, id, states, statistics, ensemble, m
|
|
|
66
66
|
compileAsync: async () => executable(await createBoundKernelAsync(graph.device, properties))
|
|
67
67
|
});
|
|
68
68
|
};
|
|
69
|
+
/** Shared failure is sticky; local overflow applies only to the attempted instance. */
|
|
70
|
+
const sharedFailure = 'statistics[1]!=0u||statistics[15]!=0u';
|
|
71
|
+
/** Fast exit before visiting journal entries when every instance accepted the step. */
|
|
72
|
+
const anyFailure = pairsPerInstance
|
|
73
|
+
? `${sharedFailure}||targets[${failureOffset + instances}u]!=0u`
|
|
74
|
+
: sharedFailure;
|
|
75
|
+
/** Read the local failure word through the already allocated targets buffer. */
|
|
76
|
+
const localFailure = (instance) => `targets[${failureOffset}u+${instance}]!=0u`;
|
|
77
|
+
/** Bind local failure words only on recovery passes that need an additional binding. */
|
|
78
|
+
const localFailureInput = pairsPerInstance ? [{ ...targets, name: 'targets' }] : [];
|
|
69
79
|
const bodyAddress = `let work=invocation.x;if(work>=ensemble[0]*${bodiesPerInstance}u){return;}
|
|
70
80
|
let body=ensemble[${16 + instances * 8}u+work/${bodiesPerInstance}u]*${bodiesPerInstance}u+work%${bodiesPerInstance}u;`;
|
|
71
81
|
/** Journal or restore contiguous vehicle rows for the scheduled instances. */
|
|
@@ -77,11 +87,13 @@ export function addEnsembleCheckpoint(graph, id, states, statistics, ensemble, m
|
|
|
77
87
|
{ ...vehicles.state, name: 'vehicle', writable: restore },
|
|
78
88
|
{ ...vehicleSnapshot, name: 'snapshot', writable: !restore },
|
|
79
89
|
{ ...ensemble, name: 'ensemble' },
|
|
80
|
-
...(restore ? [{ ...statistics, name: 'statistics' }] : [])
|
|
90
|
+
...(restore ? [{ ...statistics, name: 'statistics' }, ...localFailureInput] : [])
|
|
81
91
|
], `@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
|
|
82
|
-
${restore ?
|
|
92
|
+
${restore ? `if(!(${anyFailure})){return;}` : ''}
|
|
83
93
|
let work=invocation.x;if(work>=ensemble[0]*${count}u){return;}
|
|
84
|
-
let
|
|
94
|
+
let instance=ensemble[${16 + instances * 8}u+work/${count}u];
|
|
95
|
+
${restore && pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure('instance')})){return;}` : ''}
|
|
96
|
+
let row=(instance*${count}u+work%${count}u)*${VEHICLE_STRIDE / 4}u;
|
|
85
97
|
for(var word=0u;word<${VEHICLE_STRIDE / 4}u;word++){
|
|
86
98
|
${restore ? 'vehicle[row+word]=snapshot[row+word];' : 'snapshot[row+word]=vehicle[row+word];'}
|
|
87
99
|
}
|
|
@@ -120,10 +132,11 @@ export function addEnsembleCheckpoint(graph, id, states, statistics, ensemble, m
|
|
|
120
132
|
{ ...statistics, name: 'statistics' }
|
|
121
133
|
], `
|
|
122
134
|
@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
|
|
123
|
-
if(
|
|
135
|
+
if(!(${anyFailure})){return;}
|
|
124
136
|
let count=targets[${bodyCount * 8 + 5}u];
|
|
125
137
|
for(var work=invocation.x;work<count*104u;work+=64u){
|
|
126
138
|
let pair=targets[${journalOffset}u+work/104u];let word=work%104u;
|
|
139
|
+
${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`pair/${pairsPerInstance}u`)})){continue;}` : ''}
|
|
127
140
|
manifolds[pair*104u+word]=targets[${savedManifoldOffset}u+pair*104u+word];
|
|
128
141
|
}
|
|
129
142
|
}`);
|
|
@@ -133,30 +146,33 @@ export function addEnsembleCheckpoint(graph, id, states, statistics, ensemble, m
|
|
|
133
146
|
{ ...statistics, name: 'statistics' }
|
|
134
147
|
], `
|
|
135
148
|
@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
|
|
136
|
-
if(
|
|
149
|
+
if(!(${anyFailure})){return;}
|
|
137
150
|
let count=targets[${bodyCount * 8 + 5}u];
|
|
138
151
|
for(var index=invocation.x;index<count;index+=64u){let pair=targets[${journalOffset}u+index];
|
|
152
|
+
${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`pair/${pairsPerInstance}u`)})){continue;}` : ''}
|
|
139
153
|
targets[${bodyCount * 8 + 8}u+pair*2u]=targets[${savedKeyOffset}u+pair*2u];
|
|
140
154
|
targets[${bodyCount * 8 + 9}u+pair*2u]=targets[${savedKeyOffset + 1}u+pair*2u];
|
|
141
155
|
targets[${linkOffset}u+pair]=targets[${savedLinkOffset}u+pair];
|
|
142
156
|
}
|
|
143
157
|
for(var work=invocation.x;work<ensemble[0];work+=64u){let instance=ensemble[${16 + instances * 8}u+work];
|
|
158
|
+
${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure('instance')})){continue;}` : ''}
|
|
144
159
|
targets[${headOffset}u+instance]=targets[${savedHeadOffset}u+instance];
|
|
145
160
|
targets[${headOffset + instances}u+instance]=targets[${savedHeadOffset + instances}u+instance];
|
|
146
161
|
}
|
|
147
|
-
storageBarrier();
|
|
148
162
|
// Preserve the attempted step's journal list and counters so the next prepare can clear its marks.
|
|
149
|
-
if(invocation.x<5u){targets[${bodyCount * 8}u+invocation.x]=targets[${savedHeaderOffset}u+invocation.x];}
|
|
163
|
+
if((${sharedFailure})&&invocation.x<5u){targets[${bodyCount * 8}u+invocation.x]=targets[${savedHeaderOffset}u+invocation.x];}
|
|
150
164
|
}`);
|
|
151
165
|
copyVehicleState(true);
|
|
152
166
|
states.slice(0, 5).forEach((state, index) => addCompute(`rollback-${index}`, [
|
|
153
167
|
{ ...state, name: 'state', writable: true },
|
|
154
168
|
{ ...snapshots[index], name: 'snapshot' },
|
|
155
169
|
{ ...statistics, name: 'statistics' },
|
|
156
|
-
{ ...ensemble, name: 'ensemble' }
|
|
170
|
+
{ ...ensemble, name: 'ensemble' },
|
|
171
|
+
...localFailureInput
|
|
157
172
|
], `@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) invocation:vec3u){
|
|
158
|
-
if(
|
|
173
|
+
if(!(${anyFailure})){return;}
|
|
159
174
|
${bodyAddress}
|
|
175
|
+
${pairsPerInstance ? `if(!(${sharedFailure})&&!(${localFailure(`body/${bodiesPerInstance}u`)})){return;}` : ''}
|
|
160
176
|
for(var word=0u;word<4u;word++){state[body*4u+word]=snapshot[body*4u+word];}
|
|
161
177
|
}`, true));
|
|
162
178
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rigid-body-ensemble-transaction.js","sourceRoot":"","sources":["../../src/gpu-physics/rigid-body-ensemble-transaction.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,EACvB,0CAAuC;AAExC,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAErC,OAAO,EAAC,cAAc,EAAC,gCAA6B;AACpD,OAAO,EAAC,wBAAwB,EAAC,wCAAqC;AAKtE
|
|
1
|
+
{"version":3,"file":"rigid-body-ensemble-transaction.js","sourceRoot":"","sources":["../../src/gpu-physics/rigid-body-ensemble-transaction.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,EACvB,0CAAuC;AAExC,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAErC,OAAO,EAAC,cAAc,EAAC,gCAA6B;AACpD,OAAO,EAAC,wBAAwB,EAAC,wCAAqC;AAKtE,+HAA+H;AAC/H,MAAM,UAAU,qBAAqB,CACnC,KAAuC,EACvC,EAAU,EACV,MAAkB,EAClB,UAAoB,EACpB,QAAkB,EAClB,SAAmB,EACnB,iBAAyB,EACzB,YAAoB,EAC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AAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAC;QAC7D,EAAC,GAAG,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAC;KAChC,EACD;;;GAGH,WAAW;;;;EAIZ,EACI,IAAI,CACL,CAAC;IACJ,OAAO,EAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAC,GAAG,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAC,EAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var rigid_body_event_compaction_exports = {};
|
|
19
|
+
__export(rigid_body_event_compaction_exports, {
|
|
20
|
+
addRigidBodyEventCompaction: () => addRigidBodyEventCompaction
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(rigid_body_event_compaction_exports);
|
|
23
|
+
var import_core = require("@luma.gl/core");
|
|
24
|
+
var import_bound_kernel = require("../gpu-core/utils/bound-kernel.cjs");
|
|
25
|
+
const EVENT_WORKGROUP_SIZE = 64;
|
|
26
|
+
const EVENT_WORK_LOCATION = 29;
|
|
27
|
+
function addRigidBodyEventCompaction(graph, options) {
|
|
28
|
+
const workgroups = Math.max(1, Math.ceil(options.rowCount / EVENT_WORKGROUP_SIZE));
|
|
29
|
+
const source = options.source + getEventCompactionShader(options, workgroups);
|
|
30
|
+
function addStage(entryPoint, description, bindings, count) {
|
|
31
|
+
const unique = [...new Map(bindings.map((binding) => [binding.name, binding])).values()];
|
|
32
|
+
const declarations = unique.map(({ name, location, readOnly }) => ({
|
|
33
|
+
name,
|
|
34
|
+
location,
|
|
35
|
+
group: 0,
|
|
36
|
+
type: readOnly ? "read-only-storage" : "storage"
|
|
37
|
+
}));
|
|
38
|
+
const properties = {
|
|
39
|
+
id: `${options.id}-${entryPoint}`,
|
|
40
|
+
entryPoint,
|
|
41
|
+
source,
|
|
42
|
+
shaderLayout: { bindings: declarations }
|
|
43
|
+
};
|
|
44
|
+
const executable = (computation) => ({
|
|
45
|
+
encode: ({ computePass, getBuffer }) => {
|
|
46
|
+
for (const binding of unique)
|
|
47
|
+
computation.bindings[binding.name] = getBuffer(binding.resource);
|
|
48
|
+
computation.kernel.dispatch(computePass, { bindings: computation.bindings, x: count });
|
|
49
|
+
},
|
|
50
|
+
destroy: () => computation.kernel.destroy()
|
|
51
|
+
});
|
|
52
|
+
graph.addComputePass({
|
|
53
|
+
id: properties.id,
|
|
54
|
+
description,
|
|
55
|
+
resources: unique.map((binding) => ({
|
|
56
|
+
buffer: binding.resource,
|
|
57
|
+
usage: binding.readOnly ? "storage-read" : "storage-read-write"
|
|
58
|
+
})),
|
|
59
|
+
compile: () => executable((0, import_bound_kernel.createBoundKernel)(graph.device, properties)),
|
|
60
|
+
compileAsync: async () => executable(await (0, import_bound_kernel.createBoundKernelAsync)(graph.device, properties))
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (workgroups === 1) {
|
|
64
|
+
addStage("publishEventTile", "Publish ordered events in one workgroup.", [...options.classify, ...options.commit, ...options.publish], 1);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const scratch = graph.createTransientBuffer({
|
|
68
|
+
id: `${options.id}-compaction`,
|
|
69
|
+
usage: import_core.Buffer.STORAGE,
|
|
70
|
+
byteLength: (4 + options.rowCount + workgroups) * 4
|
|
71
|
+
});
|
|
72
|
+
const work = { name: "eventWork", location: EVENT_WORK_LOCATION, resource: scratch };
|
|
73
|
+
addStage("classifyEventTiles", "Classify transitions and compact one tile per workgroup.", [...options.classify, work], workgroups);
|
|
74
|
+
addStage("reserveEventTiles", "Reserve ordered ring positions from tile counts.", [...options.commit, work], 1);
|
|
75
|
+
addStage("publishEventTiles", "Write retained event records and advance transition history.", [...options.publish, work], workgroups);
|
|
76
|
+
}
|
|
77
|
+
function getEventCompactionShader({ ring, capacity, rowCount }, workgroups) {
|
|
78
|
+
return (
|
|
79
|
+
/* wgsl */
|
|
80
|
+
`
|
|
81
|
+
const EVENT_ROWS:u32=${rowCount}u;
|
|
82
|
+
const EVENT_CAPACITY:u32=${capacity}u;
|
|
83
|
+
const EVENT_TILE_SIZE:u32=${EVENT_WORKGROUP_SIZE}u;
|
|
84
|
+
var<workgroup> eventPrefix:array<u32,${EVENT_WORKGROUP_SIZE}>;
|
|
85
|
+
|
|
86
|
+
// Each row emits at most two records, in the order chosen by its publisher.
|
|
87
|
+
fn scanEvents(lane:u32,count:u32)->u32{
|
|
88
|
+
eventPrefix[lane]=count;
|
|
89
|
+
workgroupBarrier();
|
|
90
|
+
for(var stride=1u;stride<EVENT_TILE_SIZE;stride*=2u){
|
|
91
|
+
var prior=0u;
|
|
92
|
+
if(lane>=stride){prior=eventPrefix[lane-stride];}
|
|
93
|
+
workgroupBarrier();
|
|
94
|
+
eventPrefix[lane]+=prior;
|
|
95
|
+
workgroupBarrier();
|
|
96
|
+
}
|
|
97
|
+
return eventPrefix[lane]-count;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Reserve from the old sequence but keep only the newest records that fit the ring.
|
|
101
|
+
// x = base sequence, y = accepted count, z = step (zero for an uncommitted tick).
|
|
102
|
+
fn reserveEvents(total:u32)->vec3u{
|
|
103
|
+
if(!eventCommit()){return vec3u(0);}
|
|
104
|
+
if(${ring}.step==0xffffffffu){${ring}.saturated=1u;return vec3u(0);}
|
|
105
|
+
let base=${ring}.sequence;
|
|
106
|
+
let accepted=min(total,0xffffffffu-base);
|
|
107
|
+
if(accepted<total){${ring}.saturated=1u;}
|
|
108
|
+
${ring}.sequence=base+accepted;
|
|
109
|
+
${ring}.step++;
|
|
110
|
+
return vec3u(base,accepted,${ring}.step);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn retainedEventSequence(reservation:vec3u,offset:u32)->u32{
|
|
114
|
+
if(offset>=reservation.y||reservation.y-offset>EVENT_CAPACITY){return 0u;}
|
|
115
|
+
return reservation.x+offset+1u;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
${workgroups === 1 ? (
|
|
119
|
+
/* wgsl */
|
|
120
|
+
`
|
|
121
|
+
var<workgroup> eventReservation:vec3u;
|
|
122
|
+
@compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn publishEventTile(
|
|
123
|
+
@builtin(local_invocation_index) lane:u32
|
|
124
|
+
){
|
|
125
|
+
var flags=0u;
|
|
126
|
+
if(lane<EVENT_ROWS){flags=eventClassify(lane);}
|
|
127
|
+
let offset=scanEvents(lane,eventCount(flags));
|
|
128
|
+
if(lane==0u){eventReservation=reserveEvents(eventPrefix[EVENT_TILE_SIZE-1u]);}
|
|
129
|
+
workgroupBarrier();
|
|
130
|
+
if(lane<EVENT_ROWS&&eventReservation.z!=0u){eventPublish(lane,flags,offset,eventReservation);}
|
|
131
|
+
}
|
|
132
|
+
`
|
|
133
|
+
) : (
|
|
134
|
+
/* wgsl */
|
|
135
|
+
`
|
|
136
|
+
@group(0) @binding(${EVENT_WORK_LOCATION}) var<storage,read_write> eventWork:array<u32>;
|
|
137
|
+
const EVENT_TILES:u32=${workgroups}u;
|
|
138
|
+
|
|
139
|
+
@compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn classifyEventTiles(
|
|
140
|
+
@builtin(global_invocation_id) invocation:vec3u,
|
|
141
|
+
@builtin(local_invocation_index) lane:u32,
|
|
142
|
+
@builtin(workgroup_id) tile:vec3u
|
|
143
|
+
){
|
|
144
|
+
let row=invocation.x;
|
|
145
|
+
var flags=0u;
|
|
146
|
+
if(row<EVENT_ROWS){flags=eventClassify(row);}
|
|
147
|
+
let offset=scanEvents(lane,eventCount(flags));
|
|
148
|
+
// A 64-lane tile uses at most 128 records. Keep flags above the local offset.
|
|
149
|
+
if(row<EVENT_ROWS){eventWork[4u+row]=offset|(flags<<8u);}
|
|
150
|
+
if(lane==0u){eventWork[4u+EVENT_ROWS+tile.x]=eventPrefix[EVENT_TILE_SIZE-1u];}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@compute @workgroup_size(1) fn reserveEventTiles(){
|
|
154
|
+
var total=0u;
|
|
155
|
+
for(var tile=0u;tile<EVENT_TILES;tile++){
|
|
156
|
+
let index=4u+EVENT_ROWS+tile;
|
|
157
|
+
let count=eventWork[index];
|
|
158
|
+
eventWork[index]=total;
|
|
159
|
+
total+=count;
|
|
160
|
+
}
|
|
161
|
+
let reservation=reserveEvents(total);
|
|
162
|
+
eventWork[0]=reservation.x;eventWork[1]=reservation.y;eventWork[2]=reservation.z;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn publishEventTiles(
|
|
166
|
+
@builtin(global_invocation_id) invocation:vec3u,
|
|
167
|
+
@builtin(workgroup_id) tile:vec3u
|
|
168
|
+
){
|
|
169
|
+
let row=invocation.x;
|
|
170
|
+
let reservation=vec3u(eventWork[0],eventWork[1],eventWork[2]);
|
|
171
|
+
if(row>=EVENT_ROWS||reservation.z==0u){return;}
|
|
172
|
+
let word=eventWork[4u+row];
|
|
173
|
+
let offset=eventWork[4u+EVENT_ROWS+tile.x]+(word&255u);
|
|
174
|
+
eventPublish(row,word>>8u,offset,reservation);
|
|
175
|
+
}
|
|
176
|
+
`
|
|
177
|
+
)}
|
|
178
|
+
`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
182
|
+
0 && (module.exports = {
|
|
183
|
+
addRigidBodyEventCompaction
|
|
184
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GPUCommandGraph, GraphBufferHandle } from "../gpu-core/gpu-command-graph.js";
|
|
2
|
+
/** Optional per-stage visibility for an imported simulation buffer. */
|
|
3
|
+
export type RigidBodyEventBinding = {
|
|
4
|
+
/** WGSL variable name. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Binding number in group zero. */
|
|
7
|
+
location: number;
|
|
8
|
+
/** Caller-owned simulation resource. */
|
|
9
|
+
resource: GraphBufferHandle;
|
|
10
|
+
/** Whether the underlying declaration is read-only storage. */
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** Configure a publication ring and the resources each callback uses. */
|
|
14
|
+
type EventCompactionOptions = {
|
|
15
|
+
/** Prefix for the graph nodes and temporary storage. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Number of stable pair or trigger slots scanned in a step. */
|
|
18
|
+
rowCount: number;
|
|
19
|
+
/** Maximum number of retained events. */
|
|
20
|
+
capacity: number;
|
|
21
|
+
/** WGSL ring variable shared by the reservation helpers. */
|
|
22
|
+
ring: string;
|
|
23
|
+
/** WGSL declaring eventClassify, eventCount, eventPublish and eventCommit. */
|
|
24
|
+
source: string;
|
|
25
|
+
/** Resources used to determine transition flags. */
|
|
26
|
+
classify: readonly RigidBodyEventBinding[];
|
|
27
|
+
/** Resources read when deciding whether a step committed. */
|
|
28
|
+
commit: readonly RigidBodyEventBinding[];
|
|
29
|
+
/** Resources accessed to publish payloads and update history. */
|
|
30
|
+
publish: readonly RigidBodyEventBinding[];
|
|
31
|
+
};
|
|
32
|
+
/** Compact ordered transitions and publish a single coherent step into an existing ring. */
|
|
33
|
+
export declare function addRigidBodyEventCompaction<Parameters>(graph: GPUCommandGraph<Parameters>, options: EventCompactionOptions): void;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=rigid-body-event-compaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rigid-body-event-compaction.d.ts","sourceRoot":"","sources":["../../src/gpu-physics/rigid-body-event-compaction.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EAEf,iBAAiB,EAClB,yCAAsC;AAavC,uEAAuE;AACvE,MAAM,MAAM,qBAAqB,GAAG;IAClC,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,yEAAyE;AACzE,KAAK,sBAAsB,GAAG;IAC5B,wDAAwD;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,QAAQ,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC3C,6DAA6D;IAC7D,MAAM,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACzC,iEAAiE;IACjE,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC3C,CAAC;AAEF,4FAA4F;AAC5F,wBAAgB,2BAA2B,CAAC,UAAU,EACpD,KAAK,EAAE,eAAe,CAAC,UAAU,CAAC,EAClC,OAAO,EAAE,sBAAsB,GAC9B,IAAI,CAyFN"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { Buffer } from '@luma.gl/core';
|
|
5
|
+
import { createBoundKernel, createBoundKernelAsync } from "../gpu-core/utils/bound-kernel.js";
|
|
6
|
+
/** Stable slot tiles also fit default WebGPU workgroup limits. */
|
|
7
|
+
const EVENT_WORKGROUP_SIZE = 64;
|
|
8
|
+
/** Storage binding shared by the three large-ring publication passes. */
|
|
9
|
+
const EVENT_WORK_LOCATION = 29;
|
|
10
|
+
/** Compact ordered transitions and publish a single coherent step into an existing ring. */
|
|
11
|
+
export function addRigidBodyEventCompaction(graph, options) {
|
|
12
|
+
/** A single workgroup can classify and publish without external scratch. */
|
|
13
|
+
const workgroups = Math.max(1, Math.ceil(options.rowCount / EVENT_WORKGROUP_SIZE));
|
|
14
|
+
/** The shared WGSL preserves identical event sequence and overflow semantics in both paths. */
|
|
15
|
+
const source = options.source + getEventCompactionShader(options, workgroups);
|
|
16
|
+
/** Attach one explicit graph stage and resolve aliased scratch at encode time. */
|
|
17
|
+
function addStage(entryPoint, description, bindings, count) {
|
|
18
|
+
/** A buffer may serve several callbacks in the fused entry point. */
|
|
19
|
+
const unique = [...new Map(bindings.map(binding => [binding.name, binding])).values()];
|
|
20
|
+
/** Bind resources without declaring unused storage at this entry point. */
|
|
21
|
+
const declarations = unique.map(({ name, location, readOnly }) => ({
|
|
22
|
+
name,
|
|
23
|
+
location,
|
|
24
|
+
group: 0,
|
|
25
|
+
type: readOnly ? 'read-only-storage' : 'storage'
|
|
26
|
+
}));
|
|
27
|
+
/** The same bindings serve sync and async pipeline compilation. */
|
|
28
|
+
const properties = {
|
|
29
|
+
id: `${options.id}-${entryPoint}`,
|
|
30
|
+
entryPoint,
|
|
31
|
+
source,
|
|
32
|
+
shaderLayout: { bindings: declarations }
|
|
33
|
+
};
|
|
34
|
+
/** Connect compiler-owned scratch and source views for this dispatch. */
|
|
35
|
+
const executable = (computation) => ({
|
|
36
|
+
encode: ({ computePass, getBuffer }) => {
|
|
37
|
+
for (const binding of unique)
|
|
38
|
+
computation.bindings[binding.name] = getBuffer(binding.resource);
|
|
39
|
+
computation.kernel.dispatch(computePass, { bindings: computation.bindings, x: count });
|
|
40
|
+
},
|
|
41
|
+
destroy: () => computation.kernel.destroy()
|
|
42
|
+
});
|
|
43
|
+
graph.addComputePass({
|
|
44
|
+
id: properties.id,
|
|
45
|
+
description,
|
|
46
|
+
resources: unique.map(binding => ({
|
|
47
|
+
buffer: binding.resource,
|
|
48
|
+
usage: binding.readOnly ? 'storage-read' : 'storage-read-write'
|
|
49
|
+
})),
|
|
50
|
+
compile: () => executable(createBoundKernel(graph.device, properties)),
|
|
51
|
+
compileAsync: async () => executable(await createBoundKernelAsync(graph.device, properties))
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (workgroups === 1) {
|
|
55
|
+
addStage('publishEventTile', 'Publish ordered events in one workgroup.', [...options.classify, ...options.commit, ...options.publish], 1);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
/** One flag/offset word per row, one total/offset per tile, and one reservation header. */
|
|
59
|
+
const scratch = graph.createTransientBuffer({
|
|
60
|
+
id: `${options.id}-compaction`,
|
|
61
|
+
usage: Buffer.STORAGE,
|
|
62
|
+
byteLength: (4 + options.rowCount + workgroups) * 4
|
|
63
|
+
});
|
|
64
|
+
/** Scratch is graph-owned and never enters snapshots or the public event ring layout. */
|
|
65
|
+
const work = { name: 'eventWork', location: EVENT_WORK_LOCATION, resource: scratch };
|
|
66
|
+
addStage('classifyEventTiles', 'Classify transitions and compact one tile per workgroup.', [...options.classify, work], workgroups);
|
|
67
|
+
addStage('reserveEventTiles', 'Reserve ordered ring positions from tile counts.', [...options.commit, work], 1);
|
|
68
|
+
addStage('publishEventTiles', 'Write retained event records and advance transition history.', [...options.publish, work], workgroups);
|
|
69
|
+
}
|
|
70
|
+
/** Emit a stable workgroup scan and bounded ring reservation for the two event payloads. */
|
|
71
|
+
function getEventCompactionShader({ ring, capacity, rowCount }, workgroups) {
|
|
72
|
+
return /* wgsl */ `
|
|
73
|
+
const EVENT_ROWS:u32=${rowCount}u;
|
|
74
|
+
const EVENT_CAPACITY:u32=${capacity}u;
|
|
75
|
+
const EVENT_TILE_SIZE:u32=${EVENT_WORKGROUP_SIZE}u;
|
|
76
|
+
var<workgroup> eventPrefix:array<u32,${EVENT_WORKGROUP_SIZE}>;
|
|
77
|
+
|
|
78
|
+
// Each row emits at most two records, in the order chosen by its publisher.
|
|
79
|
+
fn scanEvents(lane:u32,count:u32)->u32{
|
|
80
|
+
eventPrefix[lane]=count;
|
|
81
|
+
workgroupBarrier();
|
|
82
|
+
for(var stride=1u;stride<EVENT_TILE_SIZE;stride*=2u){
|
|
83
|
+
var prior=0u;
|
|
84
|
+
if(lane>=stride){prior=eventPrefix[lane-stride];}
|
|
85
|
+
workgroupBarrier();
|
|
86
|
+
eventPrefix[lane]+=prior;
|
|
87
|
+
workgroupBarrier();
|
|
88
|
+
}
|
|
89
|
+
return eventPrefix[lane]-count;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Reserve from the old sequence but keep only the newest records that fit the ring.
|
|
93
|
+
// x = base sequence, y = accepted count, z = step (zero for an uncommitted tick).
|
|
94
|
+
fn reserveEvents(total:u32)->vec3u{
|
|
95
|
+
if(!eventCommit()){return vec3u(0);}
|
|
96
|
+
if(${ring}.step==0xffffffffu){${ring}.saturated=1u;return vec3u(0);}
|
|
97
|
+
let base=${ring}.sequence;
|
|
98
|
+
let accepted=min(total,0xffffffffu-base);
|
|
99
|
+
if(accepted<total){${ring}.saturated=1u;}
|
|
100
|
+
${ring}.sequence=base+accepted;
|
|
101
|
+
${ring}.step++;
|
|
102
|
+
return vec3u(base,accepted,${ring}.step);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fn retainedEventSequence(reservation:vec3u,offset:u32)->u32{
|
|
106
|
+
if(offset>=reservation.y||reservation.y-offset>EVENT_CAPACITY){return 0u;}
|
|
107
|
+
return reservation.x+offset+1u;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
${workgroups === 1
|
|
111
|
+
? /* wgsl */ `
|
|
112
|
+
var<workgroup> eventReservation:vec3u;
|
|
113
|
+
@compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn publishEventTile(
|
|
114
|
+
@builtin(local_invocation_index) lane:u32
|
|
115
|
+
){
|
|
116
|
+
var flags=0u;
|
|
117
|
+
if(lane<EVENT_ROWS){flags=eventClassify(lane);}
|
|
118
|
+
let offset=scanEvents(lane,eventCount(flags));
|
|
119
|
+
if(lane==0u){eventReservation=reserveEvents(eventPrefix[EVENT_TILE_SIZE-1u]);}
|
|
120
|
+
workgroupBarrier();
|
|
121
|
+
if(lane<EVENT_ROWS&&eventReservation.z!=0u){eventPublish(lane,flags,offset,eventReservation);}
|
|
122
|
+
}
|
|
123
|
+
`
|
|
124
|
+
: /* wgsl */ `
|
|
125
|
+
@group(0) @binding(${EVENT_WORK_LOCATION}) var<storage,read_write> eventWork:array<u32>;
|
|
126
|
+
const EVENT_TILES:u32=${workgroups}u;
|
|
127
|
+
|
|
128
|
+
@compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn classifyEventTiles(
|
|
129
|
+
@builtin(global_invocation_id) invocation:vec3u,
|
|
130
|
+
@builtin(local_invocation_index) lane:u32,
|
|
131
|
+
@builtin(workgroup_id) tile:vec3u
|
|
132
|
+
){
|
|
133
|
+
let row=invocation.x;
|
|
134
|
+
var flags=0u;
|
|
135
|
+
if(row<EVENT_ROWS){flags=eventClassify(row);}
|
|
136
|
+
let offset=scanEvents(lane,eventCount(flags));
|
|
137
|
+
// A 64-lane tile uses at most 128 records. Keep flags above the local offset.
|
|
138
|
+
if(row<EVENT_ROWS){eventWork[4u+row]=offset|(flags<<8u);}
|
|
139
|
+
if(lane==0u){eventWork[4u+EVENT_ROWS+tile.x]=eventPrefix[EVENT_TILE_SIZE-1u];}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@compute @workgroup_size(1) fn reserveEventTiles(){
|
|
143
|
+
var total=0u;
|
|
144
|
+
for(var tile=0u;tile<EVENT_TILES;tile++){
|
|
145
|
+
let index=4u+EVENT_ROWS+tile;
|
|
146
|
+
let count=eventWork[index];
|
|
147
|
+
eventWork[index]=total;
|
|
148
|
+
total+=count;
|
|
149
|
+
}
|
|
150
|
+
let reservation=reserveEvents(total);
|
|
151
|
+
eventWork[0]=reservation.x;eventWork[1]=reservation.y;eventWork[2]=reservation.z;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@compute @workgroup_size(${EVENT_WORKGROUP_SIZE}) fn publishEventTiles(
|
|
155
|
+
@builtin(global_invocation_id) invocation:vec3u,
|
|
156
|
+
@builtin(workgroup_id) tile:vec3u
|
|
157
|
+
){
|
|
158
|
+
let row=invocation.x;
|
|
159
|
+
let reservation=vec3u(eventWork[0],eventWork[1],eventWork[2]);
|
|
160
|
+
if(row>=EVENT_ROWS||reservation.z==0u){return;}
|
|
161
|
+
let word=eventWork[4u+row];
|
|
162
|
+
let offset=eventWork[4u+EVENT_ROWS+tile.x]+(word&255u);
|
|
163
|
+
eventPublish(row,word>>8u,offset,reservation);
|
|
164
|
+
}
|
|
165
|
+
`}
|
|
166
|
+
`;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=rigid-body-event-compaction.js.map
|