@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
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {Buffer, type Device} from '@luma.gl/core';
|
|
5
|
+
import {Buffer, Texture, TextureView, type Device} from '@luma.gl/core';
|
|
6
6
|
import {GPUData, GPUVector, getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
|
|
7
7
|
import type {GPUGraph} from './gpu-graph';
|
|
8
|
+
import {GPUCopyOperation} from './gpu-transfer-operation';
|
|
9
|
+
import {validateTextureCopy} from './gpu-texture-copy';
|
|
10
|
+
import {
|
|
11
|
+
GPUTextureInvocation,
|
|
12
|
+
type GPUGraphTextureBinding,
|
|
13
|
+
type GPUGraphOutput,
|
|
14
|
+
type GPUGraphOutputs
|
|
15
|
+
} from './gpu-texture-plan';
|
|
16
|
+
import type {GPUGraphTexture} from './gpu-graph-value';
|
|
17
|
+
import {resolveGPUGraphDeclarations} from './gpu-graph-declarations';
|
|
8
18
|
import {GPUGraphVector, type GPUGraphScalar, type GPUGraphVectorFormat} from './gpu-graph-value';
|
|
9
19
|
import {GPUCompositeOperation, isGPUOperation, type GPUGraphOperation} from './gpu-operation';
|
|
10
20
|
import {GPULoopOperation} from './gpu-control-flow-operation';
|
|
@@ -26,12 +36,19 @@ import {
|
|
|
26
36
|
type GPUOperationContract
|
|
27
37
|
} from './gpu-operation-contract';
|
|
28
38
|
|
|
29
|
-
export type GPUGraphRunBindings = Readonly<
|
|
39
|
+
export type GPUGraphRunBindings = Readonly<
|
|
40
|
+
Record<string, GPUVector | number | GPUGraphTextureBinding>
|
|
41
|
+
>;
|
|
42
|
+
export type GPUGraphExecutionBindings = {
|
|
43
|
+
inputs?: GPUGraphRunBindings;
|
|
44
|
+
state?: Readonly<Record<string, GPUVector>>;
|
|
45
|
+
outputTargets?: Readonly<Record<string, GPUGraphOutput>>;
|
|
46
|
+
};
|
|
30
47
|
export type GPUGraphCompileOptions = {
|
|
31
48
|
outputs?: readonly string[];
|
|
32
49
|
lowerings?: readonly GPUOperationLowering[];
|
|
33
50
|
};
|
|
34
|
-
export type GPUGraphRunOptions = {outputTargets?: Readonly<Record<string,
|
|
51
|
+
export type GPUGraphRunOptions = {outputTargets?: Readonly<Record<string, GPUGraphOutput>>};
|
|
35
52
|
|
|
36
53
|
/** @internal */
|
|
37
54
|
export type GPUExpressionPlan = {
|
|
@@ -43,18 +60,28 @@ export type GPUExpressionPlan = {
|
|
|
43
60
|
gpuScalarInputs: readonly string[];
|
|
44
61
|
};
|
|
45
62
|
|
|
63
|
+
/** CPU-known dimensions for an unallocated operation result. @internal */
|
|
64
|
+
export type GPUExpressionVectorShape = {
|
|
65
|
+
length: number;
|
|
66
|
+
chunkLengths: readonly number[];
|
|
67
|
+
};
|
|
68
|
+
|
|
46
69
|
/** Snapshot of declarations and checked expressions; contains no bound resources. @internal */
|
|
47
70
|
export class GPUExpressionProgram {
|
|
48
71
|
private readonly contracts = new Map<GPUGraphOperation, GPUOperationContract>();
|
|
72
|
+
private readonly resultNames: ReadonlySet<string>;
|
|
49
73
|
readonly expressions: readonly GPUExpressionPlan[];
|
|
50
74
|
readonly operations: readonly GPUGraphOperation[];
|
|
51
75
|
readonly outputs: readonly string[];
|
|
52
76
|
readonly scalars: readonly GPUGraphScalar[];
|
|
53
77
|
readonly vectors: readonly GPUGraphVector[];
|
|
78
|
+
readonly textures: readonly GPUGraphTexture[];
|
|
54
79
|
|
|
55
80
|
constructor(program: GPUGraph, options: GPUGraphCompileOptions = {}) {
|
|
81
|
+
program = resolveGPUGraphDeclarations(program);
|
|
56
82
|
this.scalars = program.scalars;
|
|
57
83
|
this.vectors = program.vectors;
|
|
84
|
+
this.textures = program.textures;
|
|
58
85
|
const operations: GPUGraphOperation[] = [];
|
|
59
86
|
const flatten = (operation: GPUGraphOperation): void => {
|
|
60
87
|
if (operation instanceof GPUCompositeOperation && operation.type === 'composite')
|
|
@@ -73,7 +100,7 @@ export class GPUExpressionProgram {
|
|
|
73
100
|
program.operations.forEach(flatten);
|
|
74
101
|
this.operations = operations;
|
|
75
102
|
const declarations = new Map(
|
|
76
|
-
[...this.scalars, ...this.vectors].map(value => [value.id, value])
|
|
103
|
+
[...this.scalars, ...this.vectors, ...this.textures].map(value => [value.id, value])
|
|
77
104
|
);
|
|
78
105
|
const expressions = operations.filter(
|
|
79
106
|
(operation): operation is GPUExpressionOperation =>
|
|
@@ -110,7 +137,11 @@ export class GPUExpressionProgram {
|
|
|
110
137
|
}
|
|
111
138
|
// Non-expression values may be initialized by execution bindings, even if overwritten later.
|
|
112
139
|
// Expression outputs remain single-assignment values with compile-time producer ordering.
|
|
113
|
-
const available = new Set(
|
|
140
|
+
const available = new Set(
|
|
141
|
+
[...declarations.keys()].filter(
|
|
142
|
+
name => !producers.has(name) && declarations.get(name)?.role !== 'value'
|
|
143
|
+
)
|
|
144
|
+
);
|
|
114
145
|
const expressionPlans: GPUExpressionPlan[] = [];
|
|
115
146
|
for (const operation of operations) {
|
|
116
147
|
const contract = this.contracts.get(operation);
|
|
@@ -153,7 +184,12 @@ export class GPUExpressionProgram {
|
|
|
153
184
|
throw new Error(`Vector expression cannot write scalar ${operation.output}`);
|
|
154
185
|
if (
|
|
155
186
|
this.vectors.some(vector => vector.id === operation.output) &&
|
|
156
|
-
!references.some(name => this.vectors.some(vector => vector.id === name))
|
|
187
|
+
!references.some(name => this.vectors.some(vector => vector.id === name)) &&
|
|
188
|
+
!(
|
|
189
|
+
output instanceof GPUGraphVector &&
|
|
190
|
+
output.role === 'value' &&
|
|
191
|
+
output.length !== undefined
|
|
192
|
+
)
|
|
157
193
|
)
|
|
158
194
|
throw new Error(
|
|
159
195
|
`Vector expression ${operation.output} requires a vector input to determine its shape`
|
|
@@ -173,7 +209,32 @@ export class GPUExpressionProgram {
|
|
|
173
209
|
}
|
|
174
210
|
}
|
|
175
211
|
this.expressions = expressionPlans;
|
|
176
|
-
|
|
212
|
+
const producedValues = [...declarations.values()].filter(value => value.role === 'value');
|
|
213
|
+
this.resultNames = new Set(
|
|
214
|
+
[...this.contracts.values()]
|
|
215
|
+
.flatMap(contract =>
|
|
216
|
+
contract.values
|
|
217
|
+
.filter(use => use.access !== 'read')
|
|
218
|
+
.map(use => getGPUOperationValueName(use.value))
|
|
219
|
+
)
|
|
220
|
+
.filter(
|
|
221
|
+
name =>
|
|
222
|
+
declarations.get(name)?.role !== 'input' && declarations.get(name)?.role !== 'state'
|
|
223
|
+
)
|
|
224
|
+
);
|
|
225
|
+
const consumed = new Set(
|
|
226
|
+
[...this.contracts.values()].flatMap(contract =>
|
|
227
|
+
contract.values
|
|
228
|
+
.filter(use => use.access !== 'write')
|
|
229
|
+
.map(use => getGPUOperationValueName(use.value))
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
this.outputs = [
|
|
233
|
+
...(options.outputs ??
|
|
234
|
+
(producedValues.length
|
|
235
|
+
? [...this.resultNames].filter(name => !consumed.has(name))
|
|
236
|
+
: expressions.map(operation => operation.output)))
|
|
237
|
+
];
|
|
177
238
|
for (const name of this.outputs) {
|
|
178
239
|
if (!declarations.has(name)) throw new Error(`Undeclared output ${name}`);
|
|
179
240
|
if (
|
|
@@ -185,15 +246,118 @@ export class GPUExpressionProgram {
|
|
|
185
246
|
}
|
|
186
247
|
}
|
|
187
248
|
|
|
249
|
+
resolveBindings(
|
|
250
|
+
supplied: GPUGraphRunBindings | GPUGraphExecutionBindings,
|
|
251
|
+
options: GPUGraphRunOptions = {}
|
|
252
|
+
): {bindings: GPUGraphRunBindings; options: GPUGraphRunOptions} {
|
|
253
|
+
const declarations = [...this.scalars, ...this.vectors, ...this.textures];
|
|
254
|
+
const explicit = declarations.some(value => value.role === 'input' || value.role === 'state');
|
|
255
|
+
const grouped =
|
|
256
|
+
explicit ||
|
|
257
|
+
Object.values(supplied).some(
|
|
258
|
+
value =>
|
|
259
|
+
value !== undefined &&
|
|
260
|
+
typeof value === 'object' &&
|
|
261
|
+
!(value instanceof GPUVector) &&
|
|
262
|
+
!(value instanceof Texture) &&
|
|
263
|
+
!(value instanceof TextureView)
|
|
264
|
+
);
|
|
265
|
+
if (!grouped) {
|
|
266
|
+
for (const name of Object.keys(supplied))
|
|
267
|
+
if (declarations.find(value => value.id === name)?.role === 'value')
|
|
268
|
+
throw new Error(`Use outputTargets for graph result ${name}`);
|
|
269
|
+
return {bindings: supplied as GPUGraphRunBindings, options};
|
|
270
|
+
}
|
|
271
|
+
for (const name of Object.keys(supplied))
|
|
272
|
+
if (!['inputs', 'state', 'outputTargets'].includes(name))
|
|
273
|
+
throw new Error(`Unknown execution option ${name}`);
|
|
274
|
+
const execution = supplied as GPUGraphExecutionBindings;
|
|
275
|
+
const bindings: Record<string, GPUVector | number | GPUGraphTextureBinding> =
|
|
276
|
+
Object.create(null);
|
|
277
|
+
for (const [role, group] of [
|
|
278
|
+
['input', execution.inputs],
|
|
279
|
+
['state', execution.state]
|
|
280
|
+
] as const) {
|
|
281
|
+
for (const [name, value] of Object.entries(group ?? {})) {
|
|
282
|
+
const declaration = declarations.find(value => value.id === name);
|
|
283
|
+
const bindingRole = declaration?.role ?? (this.resultNames.has(name) ? 'value' : 'input');
|
|
284
|
+
if (!declaration || bindingRole !== role)
|
|
285
|
+
throw new Error(`Invalid ${role} binding ${name}`);
|
|
286
|
+
bindings[name] = value;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (const declaration of declarations)
|
|
290
|
+
if (
|
|
291
|
+
(declaration.role === 'input' || declaration.role === 'state') &&
|
|
292
|
+
bindings[declaration.id] === undefined
|
|
293
|
+
)
|
|
294
|
+
throw new Error(`Missing ${declaration.role} binding ${declaration.id}`);
|
|
295
|
+
if (options.outputTargets && execution.outputTargets)
|
|
296
|
+
throw new Error('Duplicate output targets');
|
|
297
|
+
const outputTargets = execution.outputTargets ?? options.outputTargets;
|
|
298
|
+
for (const name of Object.keys(outputTargets ?? {}))
|
|
299
|
+
if (!this.resultNames.has(name) || !this.outputs.includes(name))
|
|
300
|
+
throw new Error(`Invalid graph output target ${name}`);
|
|
301
|
+
return {bindings, options: {outputTargets}};
|
|
302
|
+
}
|
|
303
|
+
|
|
188
304
|
prepare(
|
|
189
305
|
device: Device,
|
|
190
306
|
bindings: GPUGraphRunBindings,
|
|
191
|
-
options: GPUGraphRunOptions = {}
|
|
307
|
+
options: GPUGraphRunOptions = {},
|
|
308
|
+
deferIntermediateStorage = false
|
|
192
309
|
): GPUExpressionInvocation {
|
|
310
|
+
const textures = new GPUTextureInvocation(
|
|
311
|
+
device,
|
|
312
|
+
this.textures,
|
|
313
|
+
[...this.contracts.values()],
|
|
314
|
+
bindings,
|
|
315
|
+
options.outputTargets ?? {}
|
|
316
|
+
);
|
|
193
317
|
const values = new Map<string, GPUVector | number>();
|
|
194
318
|
const owned = new Set<GPUVector>();
|
|
319
|
+
const transientVectors = new Map<string, GPUExpressionVectorShape>();
|
|
320
|
+
// Keep legacy declarations and control-flow allocation behavior unchanged.
|
|
321
|
+
const deferStorage =
|
|
322
|
+
deferIntermediateStorage &&
|
|
323
|
+
!this.operations.some(operation => operation instanceof GPUCompositeOperation);
|
|
324
|
+
const getShape = (name: string): GPUExpressionVectorShape | undefined => {
|
|
325
|
+
const value = values.get(name);
|
|
326
|
+
return value instanceof GPUVector
|
|
327
|
+
? {length: value.length, chunkLengths: value.data.map(chunk => chunk.length)}
|
|
328
|
+
: transientVectors.get(name);
|
|
329
|
+
};
|
|
330
|
+
const allocateOutput = (
|
|
331
|
+
name: string,
|
|
332
|
+
chunkLengths: readonly number[],
|
|
333
|
+
format: GPUGraphVectorFormat
|
|
334
|
+
): void => {
|
|
335
|
+
if (
|
|
336
|
+
deferStorage &&
|
|
337
|
+
!this.outputs.includes(name) &&
|
|
338
|
+
this.vectors.some(vector => vector.id === name && vector.role === 'value')
|
|
339
|
+
) {
|
|
340
|
+
transientVectors.set(name, {
|
|
341
|
+
length: chunkLengths.reduce((sum, count) => sum + count, 0),
|
|
342
|
+
chunkLengths
|
|
343
|
+
});
|
|
344
|
+
} else {
|
|
345
|
+
const output = allocateVector(device, name, chunkLengths, format);
|
|
346
|
+
owned.add(output);
|
|
347
|
+
values.set(name, output);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
195
350
|
const produced = new Set(this.expressions.map(plan => plan.operation.output));
|
|
196
|
-
const targets = new Map(
|
|
351
|
+
const targets = new Map<string, GPUVector>();
|
|
352
|
+
for (const [name, target] of Object.entries(options.outputTargets ?? {})) {
|
|
353
|
+
if (this.textures.some(texture => texture.id === name)) continue;
|
|
354
|
+
// Numeric targets retain their existing GPUVector contract.
|
|
355
|
+
if (!(target instanceof GPUVector)) {
|
|
356
|
+
textures.destroy();
|
|
357
|
+
throw new Error(`Expected GPUVector ${name}`);
|
|
358
|
+
}
|
|
359
|
+
targets.set(name, target);
|
|
360
|
+
}
|
|
197
361
|
const writableVectors = new Set(
|
|
198
362
|
[...this.contracts.values()].flatMap(contract =>
|
|
199
363
|
contract.values
|
|
@@ -209,6 +373,7 @@ export class GPUExpressionProgram {
|
|
|
209
373
|
const readVectors = new Set<string>();
|
|
210
374
|
try {
|
|
211
375
|
for (const [name, binding] of Object.entries(bindings)) {
|
|
376
|
+
if (this.textures.some(texture => texture.id === name)) continue;
|
|
212
377
|
if (produced.has(name)) throw new Error(`Use outputTargets for expression output ${name}`);
|
|
213
378
|
const scalar = this.scalars.find(value => value.id === name);
|
|
214
379
|
const vector = this.vectors.find(value => value.id === name);
|
|
@@ -226,9 +391,14 @@ export class GPUExpressionProgram {
|
|
|
226
391
|
if (!(binding instanceof GPUVector)) throw new Error(`Expected GPUVector ${name}`);
|
|
227
392
|
validateVector(device, binding, vector.format, vector.length, vector.chunkLengths);
|
|
228
393
|
} else throw new Error(`Undeclared binding ${name}`);
|
|
229
|
-
values.set(name, binding);
|
|
394
|
+
values.set(name, binding as GPUVector | number);
|
|
230
395
|
}
|
|
231
396
|
for (const operation of this.operations) {
|
|
397
|
+
if (operation instanceof GPUCopyOperation && textures.values.has(operation.input))
|
|
398
|
+
validateTextureCopy(
|
|
399
|
+
textures.values.get(operation.input)!,
|
|
400
|
+
textures.values.get(operation.output)!
|
|
401
|
+
);
|
|
232
402
|
for (const use of this.contracts.get(operation)?.values ?? []) {
|
|
233
403
|
const name = getGPUOperationValueName(use.value);
|
|
234
404
|
if (use.access !== 'write' && values.get(name) instanceof GPUVector)
|
|
@@ -238,7 +408,13 @@ export class GPUExpressionProgram {
|
|
|
238
408
|
const contract = this.contracts.get(operation);
|
|
239
409
|
for (const use of contract?.values ?? []) {
|
|
240
410
|
const name = getGPUOperationValueName(use.value);
|
|
241
|
-
if (
|
|
411
|
+
if (
|
|
412
|
+
use.access !== 'write' &&
|
|
413
|
+
!values.has(name) &&
|
|
414
|
+
!textures.values.has(name) &&
|
|
415
|
+
!transientVectors.has(name) &&
|
|
416
|
+
!availableScalars.has(name)
|
|
417
|
+
)
|
|
242
418
|
throw new Error(
|
|
243
419
|
`Missing ${use.access === 'read-write' ? 'read-write' : 'execution'} binding ${name}`
|
|
244
420
|
);
|
|
@@ -261,18 +437,15 @@ export class GPUExpressionProgram {
|
|
|
261
437
|
targets.get(declaration.id) ?? (existing instanceof GPUVector ? existing : undefined);
|
|
262
438
|
const shape = use.shape;
|
|
263
439
|
const template =
|
|
264
|
-
shape && 'like' in shape
|
|
265
|
-
|
|
266
|
-
: undefined;
|
|
267
|
-
if (shape && 'like' in shape && !(template instanceof GPUVector))
|
|
440
|
+
shape && 'like' in shape ? getShape(getGPUOperationValueName(shape.like)) : undefined;
|
|
441
|
+
if (shape && 'like' in shape && !template)
|
|
268
442
|
throw new Error(`Missing shape input ${getGPUOperationValueName(shape.like)}`);
|
|
269
|
-
const chunks =
|
|
270
|
-
template
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
:
|
|
275
|
-
(declaration.length === undefined ? undefined : [declaration.length]));
|
|
443
|
+
const chunks = template
|
|
444
|
+
? template.chunkLengths
|
|
445
|
+
: shape && 'length' in shape
|
|
446
|
+
? (shape.chunkLengths ?? declaration.chunkLengths ?? [shape.length])
|
|
447
|
+
: (declaration.chunkLengths ??
|
|
448
|
+
(declaration.length === undefined ? undefined : [declaration.length]));
|
|
276
449
|
if (use.access === 'read-write' && !(existing instanceof GPUVector))
|
|
277
450
|
throw new Error(`Missing read-write binding ${declaration.id}`);
|
|
278
451
|
if (use.access === 'read-write' && target !== existing)
|
|
@@ -299,34 +472,36 @@ export class GPUExpressionProgram {
|
|
|
299
472
|
validateWritableTarget(declaration.id, target, values);
|
|
300
473
|
values.set(declaration.id, target);
|
|
301
474
|
} else {
|
|
302
|
-
|
|
303
|
-
owned.add(output);
|
|
304
|
-
values.set(declaration.id, output);
|
|
475
|
+
allocateOutput(declaration.id, chunks!, declaration.format);
|
|
305
476
|
}
|
|
306
477
|
}
|
|
307
478
|
continue;
|
|
308
479
|
}
|
|
309
480
|
const plan = this.expressions.find(expression => expression.operation === operation)!;
|
|
310
|
-
const vectorInputs:
|
|
481
|
+
const vectorInputs: GPUExpressionVectorShape[] = [];
|
|
311
482
|
for (const name of plan.references) {
|
|
312
483
|
const value = values.get(name);
|
|
313
|
-
if (
|
|
484
|
+
if (
|
|
485
|
+
value === undefined &&
|
|
486
|
+
!transientVectors.has(name) &&
|
|
487
|
+
!plan.gpuScalarInputs.includes(name)
|
|
488
|
+
)
|
|
314
489
|
throw new Error(`Missing execution binding ${name}`);
|
|
315
|
-
|
|
316
|
-
|
|
490
|
+
const shape = getShape(name);
|
|
491
|
+
if (shape && this.vectors.some(vector => vector.id === name)) vectorInputs.push(shape);
|
|
317
492
|
}
|
|
318
493
|
const declaration = this.vectors.find(value => value.id === plan.operation.output);
|
|
319
494
|
const template = vectorInputs[0];
|
|
320
495
|
const chunkLengths = declaration
|
|
321
|
-
? (template?.
|
|
496
|
+
? (template?.chunkLengths ??
|
|
322
497
|
declaration.chunkLengths ??
|
|
323
498
|
(declaration.length === undefined ? undefined : [declaration.length]))
|
|
324
499
|
: [1];
|
|
325
500
|
if (!chunkLengths) throw new Error(`Cannot infer length of ${plan.operation.output}`);
|
|
326
501
|
for (const vector of vectorInputs) {
|
|
327
502
|
if (
|
|
328
|
-
vector.
|
|
329
|
-
vector.
|
|
503
|
+
vector.chunkLengths.length !== chunkLengths.length ||
|
|
504
|
+
vector.chunkLengths.some((length, index) => length !== chunkLengths[index])
|
|
330
505
|
)
|
|
331
506
|
throw new Error(
|
|
332
507
|
`Expression ${plan.operation.id} requires matching vector chunk boundaries`
|
|
@@ -347,13 +522,18 @@ export class GPUExpressionProgram {
|
|
|
347
522
|
validateWritableTarget(plan.operation.output, target, values);
|
|
348
523
|
values.set(plan.operation.output, target);
|
|
349
524
|
} else {
|
|
350
|
-
|
|
351
|
-
owned.add(output);
|
|
352
|
-
values.set(plan.operation.output, output);
|
|
525
|
+
allocateOutput(plan.operation.output, chunkLengths, plan.format);
|
|
353
526
|
}
|
|
354
527
|
}
|
|
355
528
|
for (const name of Object.keys(options.outputTargets ?? {})) {
|
|
356
|
-
|
|
529
|
+
const scalarOutput =
|
|
530
|
+
this.outputs.includes(name) && this.scalars.some(scalar => scalar.id === name);
|
|
531
|
+
if (
|
|
532
|
+
!produced.has(name) &&
|
|
533
|
+
!writableVectors.has(name) &&
|
|
534
|
+
!scalarOutput &&
|
|
535
|
+
!this.textures.some(texture => texture.id === name && texture.role === 'value')
|
|
536
|
+
)
|
|
357
537
|
throw new Error(`Unknown graph output target ${name}`);
|
|
358
538
|
}
|
|
359
539
|
for (const name of this.outputs) {
|
|
@@ -361,6 +541,19 @@ export class GPUExpressionProgram {
|
|
|
361
541
|
!(values.get(name) instanceof GPUVector) &&
|
|
362
542
|
this.scalars.some(scalar => scalar.id === name)
|
|
363
543
|
) {
|
|
544
|
+
const target = targets.get(name);
|
|
545
|
+
if (target) {
|
|
546
|
+
validateVector(
|
|
547
|
+
device,
|
|
548
|
+
target,
|
|
549
|
+
this.scalars.find(scalar => scalar.id === name)!.format,
|
|
550
|
+
1,
|
|
551
|
+
[1]
|
|
552
|
+
);
|
|
553
|
+
validateWritableTarget(name, target, values);
|
|
554
|
+
values.set(name, target);
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
364
557
|
const output = allocateVector(
|
|
365
558
|
device,
|
|
366
559
|
name,
|
|
@@ -371,8 +564,9 @@ export class GPUExpressionProgram {
|
|
|
371
564
|
values.set(name, output);
|
|
372
565
|
}
|
|
373
566
|
}
|
|
374
|
-
return new GPUExpressionInvocation(this, values, owned);
|
|
567
|
+
return new GPUExpressionInvocation(this, values, owned, transientVectors, textures);
|
|
375
568
|
} catch (error) {
|
|
569
|
+
textures.destroy();
|
|
376
570
|
for (const vector of owned) vector.destroy();
|
|
377
571
|
throw error;
|
|
378
572
|
}
|
|
@@ -418,21 +612,30 @@ export class GPUExpressionInvocation {
|
|
|
418
612
|
constructor(
|
|
419
613
|
readonly program: GPUExpressionProgram,
|
|
420
614
|
readonly values: Map<string, GPUVector | number>,
|
|
421
|
-
private readonly owned: Set<GPUVector
|
|
615
|
+
private readonly owned: Set<GPUVector>,
|
|
616
|
+
readonly transientVectors: ReadonlyMap<string, GPUExpressionVectorShape> = new Map(),
|
|
617
|
+
readonly textures?: GPUTextureInvocation
|
|
422
618
|
) {}
|
|
423
|
-
|
|
424
|
-
const outputs:
|
|
619
|
+
getOutputs<Outputs extends GPUGraphOutputs = Record<string, GPUVector>>(): Outputs {
|
|
620
|
+
const outputs: GPUGraphOutputs = Object.create(null);
|
|
425
621
|
for (const name of this.program.outputs) {
|
|
426
|
-
const value = this.values.get(name);
|
|
427
|
-
if (!(value instanceof GPUVector))
|
|
428
|
-
throw new Error(`Output ${name} has no materialized
|
|
622
|
+
const value = this.textures?.values.get(name) ?? this.values.get(name);
|
|
623
|
+
if (!(value instanceof GPUVector || value instanceof Texture || value instanceof TextureView))
|
|
624
|
+
throw new Error(`Output ${name} has no materialized resource`);
|
|
429
625
|
outputs[name] = value;
|
|
430
626
|
}
|
|
431
|
-
|
|
627
|
+
return outputs as Outputs;
|
|
628
|
+
}
|
|
629
|
+
finish<Outputs extends GPUGraphOutputs = Record<string, GPUVector>>(): Outputs {
|
|
630
|
+
const outputs = this.getOutputs<Outputs>();
|
|
631
|
+
for (const value of Object.values(outputs))
|
|
632
|
+
if (value instanceof GPUVector) this.owned.delete(value);
|
|
633
|
+
this.textures?.finish(this.program.outputs);
|
|
432
634
|
this.destroy();
|
|
433
635
|
return outputs;
|
|
434
636
|
}
|
|
435
637
|
destroy(): void {
|
|
638
|
+
this.textures?.destroy();
|
|
436
639
|
for (const vector of this.owned) vector.destroy();
|
|
437
640
|
this.owned.clear();
|
|
438
641
|
}
|