@luma.gl/graph 10.0.0-alpha.7 → 10.0.0-alpha.8
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/dist.dev.js +5096 -7269
- package/dist/dist.min.js +270 -83
- package/dist/experimental/index.cjs.map +2 -2
- package/dist/experimental/simulation/index.cjs.map +2 -2
- package/dist/gpu-core/compiled-gpu-graph.cjs +99 -14
- package/dist/gpu-core/compiled-gpu-graph.d.ts +26 -4
- package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
- package/dist/gpu-core/compiled-gpu-graph.js +101 -13
- package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
- package/dist/gpu-core/gpu-command-graph-compiler.cjs +35 -3
- package/dist/gpu-core/gpu-command-graph-compiler.js +40 -4
- package/dist/gpu-core/gpu-command-graph-compiler.js.map +1 -1
- package/dist/gpu-core/gpu-command-graph-types.d.ts +2 -0
- package/dist/gpu-core/gpu-command-graph-types.d.ts.map +1 -1
- package/dist/gpu-core/gpu-compaction-operation.cjs +56 -0
- package/dist/gpu-core/gpu-compaction-operation.d.ts +20 -0
- package/dist/gpu-core/gpu-compaction-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-compaction-operation.js +36 -0
- package/dist/gpu-core/gpu-compaction-operation.js.map +1 -0
- package/dist/gpu-core/gpu-compaction.cjs +35 -3
- package/dist/gpu-core/gpu-compaction.d.ts.map +1 -1
- package/dist/gpu-core/gpu-compaction.js +38 -3
- package/dist/gpu-core/gpu-compaction.js.map +1 -1
- package/dist/gpu-core/gpu-expression-operation.cjs +18 -2
- package/dist/gpu-core/gpu-expression-operation.d.ts +2 -2
- package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-operation.js +20 -1
- package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
- package/dist/gpu-core/gpu-expression-plan.cjs +140 -29
- package/dist/gpu-core/gpu-expression-plan.d.ts +26 -5
- package/dist/gpu-core/gpu-expression-plan.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-plan.js +168 -34
- package/dist/gpu-core/gpu-expression-plan.js.map +1 -1
- package/dist/gpu-core/gpu-graph-compiler.cjs +100 -11
- package/dist/gpu-core/gpu-graph-compiler.d.ts +7 -3
- package/dist/gpu-core/gpu-graph-compiler.d.ts.map +1 -1
- package/dist/gpu-core/gpu-graph-compiler.js +109 -9
- package/dist/gpu-core/gpu-graph-compiler.js.map +1 -1
- package/dist/gpu-core/gpu-graph-declarations.cjs +120 -0
- package/dist/gpu-core/gpu-graph-declarations.d.ts +4 -0
- package/dist/gpu-core/gpu-graph-declarations.d.ts.map +1 -0
- package/dist/gpu-core/gpu-graph-declarations.js +110 -0
- package/dist/gpu-core/gpu-graph-declarations.js.map +1 -0
- package/dist/gpu-core/gpu-graph-validation.cjs +33 -2
- package/dist/gpu-core/gpu-graph-validation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-graph-validation.js +32 -0
- package/dist/gpu-core/gpu-graph-validation.js.map +1 -1
- package/dist/gpu-core/gpu-graph-value.cjs +38 -3
- package/dist/gpu-core/gpu-graph-value.d.ts +50 -4
- package/dist/gpu-core/gpu-graph-value.d.ts.map +1 -1
- package/dist/gpu-core/gpu-graph-value.js +39 -1
- package/dist/gpu-core/gpu-graph-value.js.map +1 -1
- package/dist/gpu-core/gpu-graph.cjs +65 -0
- package/dist/gpu-core/gpu-graph.d.ts +15 -2
- package/dist/gpu-core/gpu-graph.d.ts.map +1 -1
- package/dist/gpu-core/gpu-graph.js +70 -0
- package/dist/gpu-core/gpu-graph.js.map +1 -1
- package/dist/gpu-core/gpu-operation-contract.cjs +5 -0
- package/dist/gpu-core/gpu-operation-contract.d.ts +10 -0
- package/dist/gpu-core/gpu-operation-contract.d.ts.map +1 -1
- package/dist/gpu-core/gpu-operation-contract.js +6 -1
- package/dist/gpu-core/gpu-operation-contract.js.map +1 -1
- package/dist/gpu-core/gpu-scan.cjs +11 -2
- package/dist/gpu-core/gpu-scan.d.ts.map +1 -1
- package/dist/gpu-core/gpu-scan.js +11 -2
- package/dist/gpu-core/gpu-scan.js.map +1 -1
- package/dist/gpu-core/gpu-texture-copy.cjs +53 -0
- package/dist/gpu-core/gpu-texture-copy.d.ts +7 -0
- package/dist/gpu-core/gpu-texture-copy.d.ts.map +1 -0
- package/dist/gpu-core/gpu-texture-copy.js +39 -0
- package/dist/gpu-core/gpu-texture-copy.js.map +1 -0
- package/dist/gpu-core/gpu-texture-plan.cjs +181 -0
- package/dist/gpu-core/gpu-texture-plan.d.ts +32 -0
- package/dist/gpu-core/gpu-texture-plan.d.ts.map +1 -0
- package/dist/gpu-core/gpu-texture-plan.js +215 -0
- package/dist/gpu-core/gpu-texture-plan.js.map +1 -0
- package/dist/gpu-core/gpu-transfer-lowering.cjs +109 -0
- package/dist/gpu-core/gpu-transfer-lowering.d.ts +9 -0
- package/dist/gpu-core/gpu-transfer-lowering.d.ts.map +1 -0
- package/dist/gpu-core/gpu-transfer-lowering.js +88 -0
- package/dist/gpu-core/gpu-transfer-lowering.js.map +1 -0
- package/dist/gpu-core/gpu-transfer-operation.cjs +100 -0
- package/dist/gpu-core/gpu-transfer-operation.d.ts +38 -0
- package/dist/gpu-core/gpu-transfer-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-transfer-operation.js +84 -0
- package/dist/gpu-core/gpu-transfer-operation.js.map +1 -0
- package/dist/gpu-core/index.cjs +13 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +11 -1
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +4 -1
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-dggs/benchmarks.cjs.map +2 -2
- package/dist/gpu-graph/index.cjs +8 -0
- package/dist/gpu-graph/index.cjs.map +3 -3
- package/dist/gpu-graph/index.d.ts +5 -0
- package/dist/gpu-graph/index.d.ts.map +1 -1
- package/dist/gpu-graph/index.js +2 -0
- package/dist/gpu-graph/index.js.map +1 -1
- package/dist/gpu-graph-algorithms/benchmarks.cjs.map +3 -3
- package/dist/gpu-graph-algorithms/index.cjs.map +2 -2
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +56 -17
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +42 -2
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs.map +2 -2
- package/dist/gpu-physics/rigid-body-joints.cjs +6 -1
- package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.js +9 -1
- package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
- package/dist/gpu-physics/rigid-body-parallel-shaders.cjs +4 -2
- package/dist/gpu-physics/rigid-body-parallel-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-parallel-shaders.js +4 -2
- package/dist/gpu-physics/rigid-body-parallel-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.cjs +1 -0
- package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.js +1 -0
- package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
- package/dist/gpu-pointcloud/index.cjs.map +1 -1
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +54 -7
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +11 -4
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts.map +1 -1
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js +56 -4
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph.cjs +16 -0
- package/dist/gpu-simple-graph/gpu-simple-graph.d.ts +11 -4
- package/dist/gpu-simple-graph/gpu-simple-graph.d.ts.map +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph.js +18 -0
- package/dist/gpu-simple-graph/gpu-simple-graph.js.map +1 -1
- package/dist/gpu-simple-graph/gpu-transfer-execution.cjs +82 -0
- package/dist/gpu-simple-graph/gpu-transfer-execution.d.ts +7 -0
- package/dist/gpu-simple-graph/gpu-transfer-execution.d.ts.map +1 -0
- package/dist/gpu-simple-graph/gpu-transfer-execution.js +64 -0
- package/dist/gpu-simple-graph/gpu-transfer-execution.js.map +1 -0
- package/dist/gpu-simple-graph/index.cjs +3 -0
- package/dist/gpu-simple-graph/index.cjs.map +3 -3
- package/dist/gpu-simple-graph/index.d.ts +3 -0
- package/dist/gpu-simple-graph/index.d.ts.map +1 -1
- package/dist/gpu-simple-graph/index.js +1 -0
- package/dist/gpu-simple-graph/index.js.map +1 -1
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/gpu-core/compiled-gpu-graph.ts +118 -15
- package/src/gpu-core/gpu-command-graph-compiler.ts +38 -6
- package/src/gpu-core/gpu-command-graph-types.ts +2 -0
- package/src/gpu-core/gpu-compaction-operation.ts +49 -0
- package/src/gpu-core/gpu-compaction.ts +47 -3
- package/src/gpu-core/gpu-expression-operation.ts +23 -2
- package/src/gpu-core/gpu-expression-plan.ts +247 -44
- package/src/gpu-core/gpu-graph-compiler.ts +130 -11
- package/src/gpu-core/gpu-graph-declarations.ts +137 -0
- package/src/gpu-core/gpu-graph-validation.ts +32 -0
- package/src/gpu-core/gpu-graph-value.ts +88 -4
- package/src/gpu-core/gpu-graph.ts +104 -2
- package/src/gpu-core/gpu-operation-contract.ts +18 -0
- package/src/gpu-core/gpu-scan.ts +15 -2
- package/src/gpu-core/gpu-texture-copy.ts +51 -0
- package/src/gpu-core/gpu-texture-plan.ts +248 -0
- package/src/gpu-core/gpu-transfer-lowering.ts +102 -0
- package/src/gpu-core/gpu-transfer-operation.ts +110 -0
- package/src/gpu-core/index.ts +22 -1
- package/src/gpu-graph/index.ts +15 -0
- package/src/gpu-physics/gpu-rigid-body-world.ts +44 -3
- package/src/gpu-physics/rigid-body-joints.ts +11 -2
- package/src/gpu-physics/rigid-body-parallel-shaders.ts +4 -2
- package/src/gpu-physics/rigid-body-shaders.ts +1 -0
- package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +90 -8
- package/src/gpu-simple-graph/gpu-simple-graph.ts +56 -3
- package/src/gpu-simple-graph/gpu-transfer-execution.ts +73 -0
- package/src/gpu-simple-graph/index.ts +9 -0
- package/src/index.ts +29 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {assert} from '@luma.gl/core';
|
|
6
|
+
import {getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
|
|
7
|
+
import {gpuGraph, type GPUGraphVectorFormat} from './gpu-graph-value';
|
|
8
|
+
import type {GPUOperation} from './gpu-operation';
|
|
9
|
+
import type {GPUOperationContract} from './gpu-operation-contract';
|
|
10
|
+
|
|
11
|
+
export type GPUUploadOperationProps = {
|
|
12
|
+
id?: string;
|
|
13
|
+
output: string;
|
|
14
|
+
format: GPUGraphVectorFormat;
|
|
15
|
+
/** Packed rows, snapshotted at construction. An array preserves explicit chunk boundaries. */
|
|
16
|
+
data:
|
|
17
|
+
| Float32Array
|
|
18
|
+
| Uint32Array
|
|
19
|
+
| Int32Array
|
|
20
|
+
| readonly (Float32Array | Uint32Array | Int32Array)[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Upload immutable host data into an operation-owned result on each execution. */
|
|
24
|
+
export class GPUUploadOperation implements GPUOperation {
|
|
25
|
+
readonly type = 'vector-upload';
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly output: string;
|
|
28
|
+
readonly format: GPUGraphVectorFormat;
|
|
29
|
+
private readonly chunks: readonly Uint8Array[];
|
|
30
|
+
readonly chunkLengths: readonly number[];
|
|
31
|
+
|
|
32
|
+
constructor(props: GPUUploadOperationProps) {
|
|
33
|
+
this.id = props.id ?? `${props.output}-upload`;
|
|
34
|
+
this.output = props.output;
|
|
35
|
+
this.format = props.format;
|
|
36
|
+
const info = getGPUVectorFormatInfo(props.format);
|
|
37
|
+
const chunks = Array.isArray(props.data) ? props.data : [props.data];
|
|
38
|
+
const ValueType =
|
|
39
|
+
info.signedDataType === 'float32'
|
|
40
|
+
? Float32Array
|
|
41
|
+
: info.signedDataType === 'uint32'
|
|
42
|
+
? Uint32Array
|
|
43
|
+
: Int32Array;
|
|
44
|
+
// Host component types and complete rows must agree with the declared memory format.
|
|
45
|
+
assert(
|
|
46
|
+
chunks.every(chunk => chunk instanceof ValueType && chunk.byteLength % info.byteLength === 0)
|
|
47
|
+
);
|
|
48
|
+
this.chunks = chunks.map(chunk =>
|
|
49
|
+
new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength).slice()
|
|
50
|
+
);
|
|
51
|
+
this.chunkLengths = Object.freeze(this.chunks.map(chunk => chunk.byteLength / info.byteLength));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Backend snapshot; callers cannot mutate the operation's stored data. @internal */
|
|
55
|
+
getData(): readonly Uint8Array[] {
|
|
56
|
+
return this.chunks.map(chunk => chunk.slice());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get contract(): GPUOperationContract {
|
|
60
|
+
const shape = {
|
|
61
|
+
length: this.chunkLengths.reduce((sum, length) => sum + length, 0),
|
|
62
|
+
chunkLengths: this.chunkLengths
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
outputs: {[this.output]: gpuGraph.vector(this.format, shape)},
|
|
66
|
+
values: [{value: this.output, access: 'write', shape}]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type GPUCopyOperationProps = {id?: string; input: string; output: string};
|
|
72
|
+
|
|
73
|
+
/** Copy every row into independent storage, preserving format and chunk boundaries. */
|
|
74
|
+
export class GPUCopyOperation implements GPUOperation {
|
|
75
|
+
readonly type = 'vector-copy';
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly input: string;
|
|
78
|
+
readonly output: string;
|
|
79
|
+
constructor(props: GPUCopyOperationProps) {
|
|
80
|
+
this.id = props.id ?? `${props.output}-copy`;
|
|
81
|
+
this.input = props.input;
|
|
82
|
+
this.output = props.output;
|
|
83
|
+
}
|
|
84
|
+
get contract(): GPUOperationContract {
|
|
85
|
+
return {
|
|
86
|
+
outputs: ({getValue}) => {
|
|
87
|
+
const input = getValue(this.input);
|
|
88
|
+
// Copy is a vector transfer, not a scalar assignment or conversion.
|
|
89
|
+
if (input.type === 'texture')
|
|
90
|
+
return {[this.output]: gpuGraph.texture({...input, extent: {like: this.input}})};
|
|
91
|
+
assert(input.type === 'vector');
|
|
92
|
+
return {
|
|
93
|
+
[this.output]: gpuGraph.vector(input.format, {
|
|
94
|
+
length: input.length,
|
|
95
|
+
chunkLengths: input.chunkLengths
|
|
96
|
+
})
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
values: [
|
|
100
|
+
{value: this.input, access: 'read', textureUsage: 'copy-source'},
|
|
101
|
+
{
|
|
102
|
+
value: this.output,
|
|
103
|
+
access: 'write',
|
|
104
|
+
shape: {like: this.input},
|
|
105
|
+
textureUsage: 'copy-destination'
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/gpu-core/index.ts
CHANGED
|
@@ -656,7 +656,7 @@ export type {GPUIndexPickInfo} from './gpu-index-picking-target';
|
|
|
656
656
|
|
|
657
657
|
export {GPUExpressionOperation} from './gpu-expression-operation';
|
|
658
658
|
export type {GPUExpressionOperationProps, GPUExpressionAST} from './gpu-expression-operation';
|
|
659
|
-
export {CompiledGPUGraph} from './compiled-gpu-graph';
|
|
659
|
+
export {CompiledGPUGraph, PreparedGPUGraphExecution} from './compiled-gpu-graph';
|
|
660
660
|
export type {
|
|
661
661
|
GPUGraphCompileOptions,
|
|
662
662
|
GPUGraphRunBindings,
|
|
@@ -669,3 +669,24 @@ export type {
|
|
|
669
669
|
GPUOperationValueUse,
|
|
670
670
|
GPUOperationVectorShape
|
|
671
671
|
} from './gpu-operation-contract';
|
|
672
|
+
|
|
673
|
+
export {gpuGraph} from './gpu-graph-value';
|
|
674
|
+
export type {
|
|
675
|
+
GPUGraphScalarDescriptor,
|
|
676
|
+
GPUGraphVectorDescriptor,
|
|
677
|
+
GPUGraphValueDescriptor,
|
|
678
|
+
GPUGraphValueRole
|
|
679
|
+
} from './gpu-graph-value';
|
|
680
|
+
export type {GPUGraphExecutionBindings} from './gpu-expression-plan';
|
|
681
|
+
export type {
|
|
682
|
+
GPUOperationOutputDeclarations,
|
|
683
|
+
GPUOperationContractContext
|
|
684
|
+
} from './gpu-operation-contract';
|
|
685
|
+
|
|
686
|
+
export {GPUUploadOperation, GPUCopyOperation} from './gpu-transfer-operation';
|
|
687
|
+
export type {GPUUploadOperationProps, GPUCopyOperationProps} from './gpu-transfer-operation';
|
|
688
|
+
export {GPUCompactionOperation} from './gpu-compaction-operation';
|
|
689
|
+
export type {GPUCompactionOperationProps} from './gpu-compaction-operation';
|
|
690
|
+
|
|
691
|
+
export type {GPUGraphTextureDescriptor, GPUGraphTextureExtent} from './gpu-graph-value';
|
|
692
|
+
export type {GPUGraphTextureBinding, GPUGraphOutput, GPUGraphOutputs} from './gpu-texture-plan';
|
package/src/gpu-graph/index.ts
CHANGED
|
@@ -59,3 +59,18 @@ export type {
|
|
|
59
59
|
GPUOperationVectorShape
|
|
60
60
|
} from '../gpu-core/gpu-operation-contract';
|
|
61
61
|
export type {GPUOperation} from '../gpu-core/gpu-operation';
|
|
62
|
+
|
|
63
|
+
export {gpuGraph} from '../gpu-core/gpu-graph-value';
|
|
64
|
+
export type {
|
|
65
|
+
GPUGraphScalarDescriptor,
|
|
66
|
+
GPUGraphVectorDescriptor,
|
|
67
|
+
GPUGraphValueDescriptor,
|
|
68
|
+
GPUGraphValueRole
|
|
69
|
+
} from '../gpu-core/gpu-graph-value';
|
|
70
|
+
export type {GPUGraphExecutionBindings} from '../gpu-core/gpu-expression-plan';
|
|
71
|
+
export type {
|
|
72
|
+
GPUOperationOutputDeclarations,
|
|
73
|
+
GPUOperationContractContext
|
|
74
|
+
} from '../gpu-core/gpu-operation-contract';
|
|
75
|
+
|
|
76
|
+
export {CompiledGPUGraph, PreparedGPUGraphExecution} from '../gpu-core/compiled-gpu-graph';
|
|
@@ -125,7 +125,7 @@ export type GPURigidBodyWorldProps = {
|
|
|
125
125
|
publicationBounds?: readonly GPURigidBodyBounds[];
|
|
126
126
|
/** Publish rigid body-node matrices without requiring authored visual bounds. */
|
|
127
127
|
publishPoses?: boolean;
|
|
128
|
-
/** Up to 64
|
|
128
|
+
/** Up to 64 joints. Parallel solving supports static-anchored distance joints only. */
|
|
129
129
|
joints?: readonly GPURigidBodyJoint[];
|
|
130
130
|
gravity?: Vector3;
|
|
131
131
|
timeStep?: number;
|
|
@@ -1095,6 +1095,23 @@ export class GPURigidBodyWorld {
|
|
|
1095
1095
|
parallelSleep: ['velocities', 'angularVelocities', 'bodies', 'sleepStates', 'parallelState']
|
|
1096
1096
|
};
|
|
1097
1097
|
parallelBindings['parallelSolve'] = parallelBindings['parallelPairs'];
|
|
1098
|
+
if (this.props.joints?.length) {
|
|
1099
|
+
const jointBindings = [
|
|
1100
|
+
'settings',
|
|
1101
|
+
'positions',
|
|
1102
|
+
'orientations',
|
|
1103
|
+
'velocities',
|
|
1104
|
+
'angularVelocities',
|
|
1105
|
+
'bodies',
|
|
1106
|
+
'sleepStates',
|
|
1107
|
+
'targets'
|
|
1108
|
+
];
|
|
1109
|
+
parallelBindings['parallelJointWarm'] = jointBindings;
|
|
1110
|
+
parallelBindings['parallelJointSolve'] = jointBindings;
|
|
1111
|
+
parallelBindings['parallelSolve'] = [
|
|
1112
|
+
...new Set([...parallelBindings['parallelSolve'], ...jointBindings])
|
|
1113
|
+
];
|
|
1114
|
+
}
|
|
1098
1115
|
this.simulationStatistics = allocate('simulation-statistics', 64);
|
|
1099
1116
|
const statisticsResource = graph.importBuffer(
|
|
1100
1117
|
{id: `${this.id}-statistics`, byteLength: 64, usage: Buffer.STORAGE},
|
|
@@ -1426,7 +1443,12 @@ export class GPURigidBodyWorld {
|
|
|
1426
1443
|
? [{buffer: dispatchBinding!.resource, usage: 'indirect' as const}]
|
|
1427
1444
|
: [];
|
|
1428
1445
|
if (entryPoint === 'parallelSolve') {
|
|
1429
|
-
const stages = [
|
|
1446
|
+
const stages = [
|
|
1447
|
+
'parallelWarm',
|
|
1448
|
+
'parallelPairs',
|
|
1449
|
+
'parallelGather',
|
|
1450
|
+
...(this.props.joints?.length ? ['parallelJointWarm', 'parallelJointSolve'] : [])
|
|
1451
|
+
];
|
|
1430
1452
|
const properties = stages.map(stage => ({
|
|
1431
1453
|
id: `${this.id}-${stage}`,
|
|
1432
1454
|
source,
|
|
@@ -1482,9 +1504,19 @@ export class GPURigidBodyWorld {
|
|
|
1482
1504
|
};
|
|
1483
1505
|
dispatchPairs(computations[0]);
|
|
1484
1506
|
dispatchBodies(computations[2]);
|
|
1507
|
+
if (computations[3])
|
|
1508
|
+
computations[3].kernel.dispatch(computePass, {
|
|
1509
|
+
bindings: computations[3].bindings,
|
|
1510
|
+
x: 1
|
|
1511
|
+
});
|
|
1485
1512
|
for (let iteration = 0; iteration < (this.props.iterations ?? 16); iteration++) {
|
|
1486
1513
|
dispatchPairs(computations[1]);
|
|
1487
1514
|
dispatchBodies(computations[2]);
|
|
1515
|
+
if (computations[4])
|
|
1516
|
+
computations[4].kernel.dispatch(computePass, {
|
|
1517
|
+
bindings: computations[4].bindings,
|
|
1518
|
+
x: 1
|
|
1519
|
+
});
|
|
1488
1520
|
}
|
|
1489
1521
|
},
|
|
1490
1522
|
destroy: () => {
|
|
@@ -1494,7 +1526,11 @@ export class GPURigidBodyWorld {
|
|
|
1494
1526
|
// Iterations share one semantic graph node; dispatch boundaries synchronize pair and body owners.
|
|
1495
1527
|
graph.addComputePass({
|
|
1496
1528
|
id: `${this.id}-solve`,
|
|
1497
|
-
workload: {
|
|
1529
|
+
workload: {
|
|
1530
|
+
commandCount:
|
|
1531
|
+
(this.props.joints?.length ? 3 : 2) +
|
|
1532
|
+
(this.props.joints?.length ? 3 : 2) * (this.props.iterations ?? 16)
|
|
1533
|
+
},
|
|
1498
1534
|
description: passDescriptions['solve'],
|
|
1499
1535
|
resources: [
|
|
1500
1536
|
...indirectResources,
|
|
@@ -2262,6 +2298,11 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2262
2298
|
(next.inertiaOrientation && !next.inertiaDiagonal)
|
|
2263
2299
|
)
|
|
2264
2300
|
throw new Error('Invalid motion properties');
|
|
2301
|
+
if (this.props.joints?.length) {
|
|
2302
|
+
const proposedBodies = [...this.props.bodies];
|
|
2303
|
+
proposedBodies[bodyIndex] = next;
|
|
2304
|
+
validateRigidBodyJoints(this.props.joints, proposedBodies, this.solver);
|
|
2305
|
+
}
|
|
2265
2306
|
const colliders = this.colliders.filter(collider => collider.body === bodyIndex);
|
|
2266
2307
|
for (const collider of colliders)
|
|
2267
2308
|
if (
|
|
@@ -51,8 +51,7 @@ export function validateRigidBodyJoints(
|
|
|
51
51
|
bodies: readonly GPURigidBody[],
|
|
52
52
|
solver: string
|
|
53
53
|
): void {
|
|
54
|
-
if (joints.length > 64
|
|
55
|
-
throw new Error('Unsupported joint configuration');
|
|
54
|
+
if (joints.length > 64) throw new Error('Unsupported joint configuration');
|
|
56
55
|
for (const joint of joints) {
|
|
57
56
|
if (
|
|
58
57
|
!['distance', 'fixed', 'hinge', 'slider', 'general'].includes(joint.type) ||
|
|
@@ -67,6 +66,16 @@ export function validateRigidBodyJoints(
|
|
|
67
66
|
)
|
|
68
67
|
)
|
|
69
68
|
throw new Error('Invalid joint bodies');
|
|
69
|
+
if (solver === 'parallel') {
|
|
70
|
+
// Parallel contacts can alternate with a small serial sweep of anchored distance rows.
|
|
71
|
+
// Dynamic-dynamic joints still require shared island ownership and remain ordered-only.
|
|
72
|
+
const anchored = [joint.first, joint.second].some(
|
|
73
|
+
index =>
|
|
74
|
+
(bodies[index].mode ?? ((bodies[index].mass ?? 1) === 0 ? 'static' : 'dynamic')) ===
|
|
75
|
+
'static'
|
|
76
|
+
);
|
|
77
|
+
if (joint.type !== 'distance' || !anchored) throw new Error('Unsupported parallel joint');
|
|
78
|
+
}
|
|
70
79
|
if (joint.type === 'general') validateGeneralJoint(joint);
|
|
71
80
|
for (const frame of [joint.firstFrame, joint.secondFrame]) {
|
|
72
81
|
if (
|
|
@@ -82,9 +82,11 @@ fn parallelSolvePair(index:u32)->u32 {
|
|
|
82
82
|
if(index>=atomicLoad(¶llelState.diagnostics[3])){return PAIR_CAPACITY;}
|
|
83
83
|
return parallelState.solvePairs[index];
|
|
84
84
|
}
|
|
85
|
+
// Parent IDs strictly decrease. A connected chain can require up to BODY_COUNT links
|
|
86
|
+
// before compression completes; a fixed 64-link cap rejects valid larger islands.
|
|
85
87
|
fn parallelRoot(body:u32)->u32 {
|
|
86
88
|
var current=body;
|
|
87
|
-
for(var iteration=0u;iteration<64u;iteration++){
|
|
89
|
+
for(var iteration=0u;iteration<max(64u,BODY_COUNT);iteration++){
|
|
88
90
|
let parent=atomicLoad(¶llelState.roots[current]);
|
|
89
91
|
if(parent==current){return current;}
|
|
90
92
|
let grandparent=atomicLoad(¶llelState.roots[parent]);
|
|
@@ -119,7 +121,7 @@ fn parallelRoot(body:u32)->u32 {
|
|
|
119
121
|
let pair=parallelPair(invocation.x);if(pair>=PAIR_CAPACITY||manifolds[pair].count==0u||!colliderScheduled(manifolds[pair].first)){return;}
|
|
120
122
|
let first=colliderBody(getFirstCollider(pair));let second=colliderBody(getSecondCollider(pair));
|
|
121
123
|
if(!dynamic(first)||!dynamic(second)){return;}
|
|
122
|
-
for(var iteration=0u;iteration<64u;iteration++){
|
|
124
|
+
for(var iteration=0u;iteration<max(64u,BODY_COUNT);iteration++){
|
|
123
125
|
let firstRoot=parallelRoot(first);let secondRoot=parallelRoot(second);
|
|
124
126
|
if(firstRoot==secondRoot){return;}
|
|
125
127
|
let larger=max(firstRoot,secondRoot);let smaller=min(firstRoot,secondRoot);
|
|
@@ -393,6 +393,7 @@ ${
|
|
|
393
393
|
${parallel ? getRigidBodyParallelShader(Boolean(ensembleBodiesPerInstance)) : ''}
|
|
394
394
|
${(parallel || hasJoints) && extended ? '@compute @workgroup_size(1) fn meshCollect(){collectMeshContacts();}' : ''}
|
|
395
395
|
${jointShader}
|
|
396
|
+
${parallel && hasJoints ? '@compute @workgroup_size(1) fn parallelJointWarm(){solveJoints(true);} @compute @workgroup_size(1) fn parallelJointSolve(){solveJoints(false);}' : ''}
|
|
396
397
|
fn root(body: u32) -> u32 {var current=body;for(var iteration=0u;iteration<BODY_COUNT;iteration++) {let parent=u32(sleepStates[current].z);if(parent==current) {break;}current=parent;}return current;}
|
|
397
398
|
@compute @workgroup_size(1) fn solve() {
|
|
398
399
|
${extended && !hasJoints ? 'collectMeshContacts();' : ''}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {Buffer, assert, type Device} from '@luma.gl/core';
|
|
5
|
+
import {Buffer, assert, type Device, type CommandEncoder} from '@luma.gl/core';
|
|
6
6
|
import {
|
|
7
7
|
GPUDataEvaluator,
|
|
8
8
|
GPUEvaluationScope,
|
|
@@ -27,14 +27,22 @@ import {
|
|
|
27
27
|
GPUExpressionProgram,
|
|
28
28
|
type GPUGraphCompileOptions,
|
|
29
29
|
type GPUGraphRunBindings,
|
|
30
|
+
type GPUGraphExecutionBindings,
|
|
30
31
|
type GPUGraphRunOptions
|
|
31
32
|
} from '../gpu-core/gpu-expression-plan';
|
|
32
33
|
|
|
34
|
+
import {GPUUploadOperation, GPUCopyOperation} from '../gpu-core/gpu-transfer-operation';
|
|
35
|
+
import {executeGPUTransfer} from './gpu-transfer-execution';
|
|
36
|
+
import {encodeTextureCopy} from '../gpu-core/gpu-texture-copy';
|
|
37
|
+
import type {GPUGraphOutputs} from '../gpu-core/gpu-texture-plan';
|
|
38
|
+
|
|
33
39
|
import {GPUExpressionCastOperation} from './gpu-expression-cast-operation';
|
|
34
40
|
import {GPUExpressionRowOperation} from './gpu-expression-row-operation';
|
|
35
41
|
|
|
36
42
|
/** Reusable expression program implemented through the unchanged evaluator API. */
|
|
37
|
-
export class CompiledGPUSimpleExpressionGraph
|
|
43
|
+
export class CompiledGPUSimpleExpressionGraph<
|
|
44
|
+
Outputs extends GPUGraphOutputs = Record<string, GPUVector>
|
|
45
|
+
> {
|
|
38
46
|
private readonly program: GPUExpressionProgram;
|
|
39
47
|
private running = false;
|
|
40
48
|
private destroyed = false;
|
|
@@ -46,16 +54,75 @@ export class CompiledGPUSimpleExpressionGraph {
|
|
|
46
54
|
) {
|
|
47
55
|
if (options.lowerings) throw new Error('Custom lowerings require GPUGraph');
|
|
48
56
|
this.program = new GPUExpressionProgram(source, options);
|
|
49
|
-
if (this.program.
|
|
50
|
-
throw new Error('SimpleGraph
|
|
57
|
+
if (this.program.textures.length && device.type !== 'webgpu')
|
|
58
|
+
throw new Error('SimpleGraph texture execution requires WebGPU');
|
|
59
|
+
if (this.program.vectors.some(value => value.role === 'state'))
|
|
60
|
+
throw new Error('SimpleGraph state execution is unsupported');
|
|
61
|
+
if (
|
|
62
|
+
this.program.operations.some(
|
|
63
|
+
operation =>
|
|
64
|
+
!(
|
|
65
|
+
operation instanceof GPUExpressionOperation ||
|
|
66
|
+
operation instanceof GPUUploadOperation ||
|
|
67
|
+
operation instanceof GPUCopyOperation
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
throw new Error(
|
|
72
|
+
'SimpleGraph declarative execution supports expression, upload and copy operations only'
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Prepare a straight-line texture-copy program without submitting work. */
|
|
77
|
+
prepare(
|
|
78
|
+
supplied: GPUGraphRunBindings | GPUGraphExecutionBindings,
|
|
79
|
+
options: GPUGraphRunOptions = {}
|
|
80
|
+
) {
|
|
81
|
+
assert(!this.destroyed && !this.running && this.device.type === 'webgpu');
|
|
82
|
+
if (
|
|
83
|
+
!this.program.textures.length ||
|
|
84
|
+
this.program.operations.some(
|
|
85
|
+
operation =>
|
|
86
|
+
!(operation instanceof GPUCopyOperation) ||
|
|
87
|
+
!this.program.textures.some(texture => texture.id === operation.input)
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
throw new Error('SimpleGraph prepare currently supports texture-copy programs only');
|
|
91
|
+
const resolved = this.program.resolveBindings(supplied, options);
|
|
92
|
+
const invocation = this.program.prepare(this.device, resolved.bindings, resolved.options);
|
|
93
|
+
let encoded = false;
|
|
94
|
+
let destroyed = false;
|
|
95
|
+
return {
|
|
96
|
+
outputs: invocation.getOutputs<Outputs>(),
|
|
97
|
+
encode: (encoder: CommandEncoder): void => {
|
|
98
|
+
assert(!this.destroyed && !destroyed && !encoded && encoder.device === this.device);
|
|
99
|
+
encoded = true;
|
|
100
|
+
for (const operation of this.program.operations) {
|
|
101
|
+
assert(operation instanceof GPUCopyOperation);
|
|
102
|
+
encodeTextureCopy(
|
|
103
|
+
encoder,
|
|
104
|
+
invocation.textures!.values.get(operation.input)!,
|
|
105
|
+
invocation.textures!.values.get(operation.output)!
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
destroy: (): void => {
|
|
110
|
+
if (destroyed) return;
|
|
111
|
+
destroyed = true;
|
|
112
|
+
invocation.finish();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
51
115
|
}
|
|
52
116
|
|
|
53
117
|
async run(
|
|
54
|
-
|
|
118
|
+
supplied: GPUGraphRunBindings | GPUGraphExecutionBindings,
|
|
55
119
|
options: GPUGraphRunOptions = {}
|
|
56
|
-
): Promise<
|
|
120
|
+
): Promise<Outputs> {
|
|
57
121
|
// Evaluators do not support concurrent evaluation on one execution scope.
|
|
58
122
|
assert(!this.running && !this.destroyed);
|
|
123
|
+
const resolvedBindings = this.program.resolveBindings(supplied, options);
|
|
124
|
+
const bindings = resolvedBindings.bindings;
|
|
125
|
+
options = resolvedBindings.options;
|
|
59
126
|
this.running = true;
|
|
60
127
|
const evaluators = new Set<GPUDataEvaluator>();
|
|
61
128
|
const scalarBuffers = new Set<Buffer>();
|
|
@@ -68,7 +135,22 @@ export class CompiledGPUSimpleExpressionGraph {
|
|
|
68
135
|
evaluators.add(evaluator);
|
|
69
136
|
return evaluator;
|
|
70
137
|
};
|
|
71
|
-
for (const
|
|
138
|
+
for (const operation of this.program.operations) {
|
|
139
|
+
if (operation instanceof GPUUploadOperation || operation instanceof GPUCopyOperation) {
|
|
140
|
+
if (
|
|
141
|
+
operation instanceof GPUCopyOperation &&
|
|
142
|
+
invocation.textures?.values.has(operation.input)
|
|
143
|
+
) {
|
|
144
|
+
assert(scope);
|
|
145
|
+
encodeTextureCopy(
|
|
146
|
+
scope.commandEncoder,
|
|
147
|
+
invocation.textures.values.get(operation.input)!,
|
|
148
|
+
invocation.textures.values.get(operation.output)!
|
|
149
|
+
);
|
|
150
|
+
} else executeGPUTransfer(this.device, operation, invocation.values, scope);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const plan = this.program.expressions.find(plan => plan.operation === operation)!;
|
|
72
154
|
const target = invocation.values.get(plan.operation.output) as GPUVector;
|
|
73
155
|
for (const [chunkIndex, chunk] of target.data.entries()) {
|
|
74
156
|
if (!chunk.length) continue;
|
|
@@ -276,7 +358,7 @@ export class CompiledGPUSimpleExpressionGraph {
|
|
|
276
358
|
}
|
|
277
359
|
}
|
|
278
360
|
scope?.submit();
|
|
279
|
-
return invocation.finish();
|
|
361
|
+
return invocation.finish<Outputs>();
|
|
280
362
|
} catch (error) {
|
|
281
363
|
scope?.cancel();
|
|
282
364
|
invocation?.destroy();
|
|
@@ -3,9 +3,20 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {GPUGraph} from '../gpu-core/gpu-graph';
|
|
6
|
+
import type {TextureFormat} from '@luma.gl/core';
|
|
7
|
+
import type {GPUGraphOutputs} from '../gpu-core/gpu-texture-plan';
|
|
8
|
+
import {GPUGraphTexture, type GPUGraphTextureDescriptor} from '../gpu-core/gpu-graph-value';
|
|
6
9
|
import {GPUExpressionOperation} from '../gpu-core/gpu-expression-operation';
|
|
7
10
|
import type {GPUGraphCompileOptions} from '../gpu-core/gpu-expression-plan';
|
|
8
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
GPUGraphScalarFormat,
|
|
13
|
+
GPUGraphVectorFormat,
|
|
14
|
+
GPUGraphScalarDescriptor,
|
|
15
|
+
GPUGraphVectorDescriptor,
|
|
16
|
+
GPUGraphValueDescriptor,
|
|
17
|
+
GPUGraphScalar,
|
|
18
|
+
GPUGraphVector
|
|
19
|
+
} from '../gpu-core/gpu-graph-value';
|
|
9
20
|
import {CompiledGPUSimpleExpressionGraph} from './compiled-gpu-expression-graph';
|
|
10
21
|
import {assert, type Device} from '@luma.gl/core';
|
|
11
22
|
import {GPUDataEvaluator, type GPUDataEvaluatorTargetBuffer} from './operation/gpu-data-evaluator';
|
|
@@ -96,6 +107,37 @@ export class GPUSimpleGraph {
|
|
|
96
107
|
});
|
|
97
108
|
}
|
|
98
109
|
|
|
110
|
+
addInput<T extends GPUGraphScalarFormat>(
|
|
111
|
+
id: string,
|
|
112
|
+
descriptor: GPUGraphScalarDescriptor<T>
|
|
113
|
+
): GPUGraphScalar<T>;
|
|
114
|
+
addInput<T extends GPUGraphVectorFormat>(
|
|
115
|
+
id: string,
|
|
116
|
+
descriptor: GPUGraphVectorDescriptor<T>
|
|
117
|
+
): GPUGraphVector<T>;
|
|
118
|
+
addInput<Format extends TextureFormat>(
|
|
119
|
+
id: string,
|
|
120
|
+
descriptor: GPUGraphTextureDescriptor<Format>
|
|
121
|
+
): GPUGraphTexture<Format>;
|
|
122
|
+
addInput(
|
|
123
|
+
id: string,
|
|
124
|
+
descriptor: GPUGraphValueDescriptor
|
|
125
|
+
): GPUGraphScalar | GPUGraphVector | GPUGraphTexture {
|
|
126
|
+
assert(!this.compiled);
|
|
127
|
+
if (descriptor.type === 'texture') return this.declarations.addInput(id, descriptor);
|
|
128
|
+
return descriptor.type === 'scalar'
|
|
129
|
+
? this.declarations.addInput(id, descriptor)
|
|
130
|
+
: this.declarations.addInput(id, descriptor);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
addState<T extends GPUGraphVectorFormat>(
|
|
134
|
+
id: string,
|
|
135
|
+
descriptor: GPUGraphVectorDescriptor<T>
|
|
136
|
+
): GPUGraphVector<T> {
|
|
137
|
+
assert(!this.compiled);
|
|
138
|
+
return this.declarations.addState(id, descriptor);
|
|
139
|
+
}
|
|
140
|
+
|
|
99
141
|
scalar<T extends GPUGraphScalarFormat>(id: string, format: T) {
|
|
100
142
|
assert(!this.compiled);
|
|
101
143
|
return this.declarations.scalar(id, format);
|
|
@@ -199,12 +241,15 @@ export class GPUSimpleGraph {
|
|
|
199
241
|
}
|
|
200
242
|
|
|
201
243
|
/** Captures selected roots and an inspectable dependency plan without executing work. */
|
|
202
|
-
compile
|
|
244
|
+
compile<Outputs extends GPUGraphOutputs = Record<string, GPUVector>>(
|
|
245
|
+
device: Device,
|
|
246
|
+
options?: GPUGraphCompileOptions
|
|
247
|
+
): CompiledGPUSimpleExpressionGraph<Outputs>;
|
|
203
248
|
compile(options?: GPUSimpleGraphCompileOptions): CompiledGPUSimpleGraph;
|
|
204
249
|
compile(
|
|
205
250
|
deviceOrOptions: Device | GPUSimpleGraphCompileOptions = {},
|
|
206
251
|
expressionOptions: GPUGraphCompileOptions = {}
|
|
207
|
-
): CompiledGPUSimpleGraph | CompiledGPUSimpleExpressionGraph {
|
|
252
|
+
): CompiledGPUSimpleGraph | CompiledGPUSimpleExpressionGraph<GPUGraphOutputs> {
|
|
208
253
|
if ('type' in deviceOrOptions) {
|
|
209
254
|
assert(!this.compiled && this.leafOperations.length === 0);
|
|
210
255
|
this.compiled = true;
|
|
@@ -216,6 +261,14 @@ export class GPUSimpleGraph {
|
|
|
216
261
|
}
|
|
217
262
|
// Legacy evaluator graphs bind their device in the constructor.
|
|
218
263
|
assert(this.device && this.declarations.operations.length === 0);
|
|
264
|
+
if (
|
|
265
|
+
[
|
|
266
|
+
...this.declarations.scalars,
|
|
267
|
+
...this.declarations.vectors,
|
|
268
|
+
...this.declarations.textures
|
|
269
|
+
].some(value => value.role)
|
|
270
|
+
)
|
|
271
|
+
throw new Error('Explicit input/state declarations require compile(device)');
|
|
219
272
|
const options = deviceOrOptions;
|
|
220
273
|
// A graph is compiled once, including when compilation fails.
|
|
221
274
|
assert(!this.compiled);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Buffer, type Device} from '@luma.gl/core';
|
|
6
|
+
import type {GPUVector} from '@luma.gl/graph/gpu-data';
|
|
7
|
+
import {GPUCopyOperation, GPUUploadOperation} from '../gpu-core/gpu-transfer-operation';
|
|
8
|
+
import type {GPUEvaluationScope} from './operation/gpu-evaluation-scope';
|
|
9
|
+
|
|
10
|
+
/** SimpleGraph transfer execution; evaluator APIs and caching are unchanged. @internal */
|
|
11
|
+
export function executeGPUTransfer(
|
|
12
|
+
device: Device,
|
|
13
|
+
operation: GPUUploadOperation | GPUCopyOperation,
|
|
14
|
+
values: ReadonlyMap<string, GPUVector | number>,
|
|
15
|
+
scope?: GPUEvaluationScope
|
|
16
|
+
): void {
|
|
17
|
+
const output = values.get(operation.output) as GPUVector;
|
|
18
|
+
if (operation instanceof GPUUploadOperation) {
|
|
19
|
+
const chunks = operation.getData();
|
|
20
|
+
for (const [index, chunk] of output.data.entries()) {
|
|
21
|
+
if (!chunk.length) continue;
|
|
22
|
+
if (scope) {
|
|
23
|
+
// Queue writes would overtake earlier encoded reads of a mutable declaration.
|
|
24
|
+
const staging = device.createBuffer({data: chunks[index], usage: Buffer.COPY_SRC});
|
|
25
|
+
scope.retain(() => staging.destroy());
|
|
26
|
+
const packed = chunk.byteStride === chunk.rowByteLength;
|
|
27
|
+
for (let row = 0; row < chunk.length; row += packed ? chunk.length : 1) {
|
|
28
|
+
scope.commandEncoder.copyBufferToBuffer({
|
|
29
|
+
sourceBuffer: staging,
|
|
30
|
+
sourceOffset: row * chunk.rowByteLength,
|
|
31
|
+
destinationBuffer: chunk.buffer instanceof Buffer ? chunk.buffer : chunk.buffer.buffer,
|
|
32
|
+
destinationOffset: chunk.byteOffset + row * chunk.byteStride,
|
|
33
|
+
size: chunk.rowByteLength * (packed ? chunk.length : 1)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (chunk.byteStride === chunk.rowByteLength)
|
|
39
|
+
chunk.buffer.write(chunks[index], chunk.byteOffset);
|
|
40
|
+
else
|
|
41
|
+
for (let row = 0; row < chunk.length; row++) {
|
|
42
|
+
chunk.buffer.write(
|
|
43
|
+
chunks[index].subarray(row * chunk.rowByteLength, (row + 1) * chunk.rowByteLength),
|
|
44
|
+
chunk.byteOffset + row * chunk.byteStride
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const input = values.get(operation.input) as GPUVector;
|
|
51
|
+
const encoder = scope?.commandEncoder ?? device.createCommandEncoder();
|
|
52
|
+
try {
|
|
53
|
+
for (const [index, source] of input.data.entries()) {
|
|
54
|
+
const destination = output.data[index];
|
|
55
|
+
const packed =
|
|
56
|
+
source.byteStride === source.rowByteLength &&
|
|
57
|
+
destination.byteStride === destination.rowByteLength;
|
|
58
|
+
for (let row = 0; row < source.length; row += packed ? source.length : 1) {
|
|
59
|
+
encoder.copyBufferToBuffer({
|
|
60
|
+
sourceBuffer: source.buffer instanceof Buffer ? source.buffer : source.buffer.buffer,
|
|
61
|
+
sourceOffset: source.byteOffset + row * source.byteStride,
|
|
62
|
+
destinationBuffer:
|
|
63
|
+
destination.buffer instanceof Buffer ? destination.buffer : destination.buffer.buffer,
|
|
64
|
+
destinationOffset: destination.byteOffset + row * destination.byteStride,
|
|
65
|
+
size: source.rowByteLength * (packed ? source.length : 1)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!scope) device.submit(encoder.finish());
|
|
70
|
+
} finally {
|
|
71
|
+
if (!scope) encoder.destroy();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -98,3 +98,12 @@ export {
|
|
|
98
98
|
} from './operation/gpu-evaluator-inspection';
|
|
99
99
|
|
|
100
100
|
export {CompiledGPUSimpleExpressionGraph} from './compiled-gpu-expression-graph';
|
|
101
|
+
|
|
102
|
+
export {gpuGraph} from '../gpu-core/gpu-graph-value';
|
|
103
|
+
export type {
|
|
104
|
+
GPUGraphScalarDescriptor,
|
|
105
|
+
GPUGraphVectorDescriptor,
|
|
106
|
+
GPUGraphValueDescriptor,
|
|
107
|
+
GPUGraphValueRole
|
|
108
|
+
} from '../gpu-core/gpu-graph-value';
|
|
109
|
+
export type {GPUGraphExecutionBindings} from '../gpu-core/gpu-expression-plan';
|