@luma.gl/graph 10.0.0-alpha.10 → 10.0.0-alpha.12
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/cpu/arrow-coordinate-projection.cjs +30 -0
- package/dist/arrow/cpu/arrow-coordinate-projection.d.ts +5 -0
- package/dist/arrow/cpu/arrow-coordinate-projection.d.ts.map +1 -0
- package/dist/arrow/cpu/arrow-coordinate-projection.js +9 -0
- package/dist/arrow/cpu/arrow-coordinate-projection.js.map +1 -0
- package/dist/arrow/cpu/arrow-cpu-pipelines.cjs +31 -0
- package/dist/arrow/cpu/arrow-cpu-pipelines.d.ts +2 -0
- package/dist/arrow/cpu/arrow-cpu-pipelines.d.ts.map +1 -0
- package/dist/arrow/cpu/arrow-cpu-pipelines.js +5 -0
- package/dist/arrow/cpu/arrow-cpu-pipelines.js.map +1 -0
- package/dist/arrow/cpu/arrow-cpu-vector-adapters.cjs +99 -0
- package/dist/arrow/cpu/arrow-cpu-vector-adapters.d.ts +9 -0
- package/dist/arrow/cpu/arrow-cpu-vector-adapters.d.ts.map +1 -0
- package/dist/arrow/cpu/arrow-cpu-vector-adapters.js +100 -0
- package/dist/arrow/cpu/arrow-cpu-vector-adapters.js.map +1 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.cjs +10 -371
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts +9 -28
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts.map +1 -1
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js +5 -381
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js.map +1 -1
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.cjs +11 -11
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.d.ts +2 -0
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.d.ts.map +1 -1
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js +3 -3
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js.map +1 -1
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.cjs +2 -2
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.js +1 -1
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.js.map +1 -1
- package/dist/arrow/index.cjs +17 -2
- package/dist/arrow/index.cjs.map +3 -3
- package/dist/arrow/index.d.ts +3 -0
- package/dist/arrow/index.d.ts.map +1 -1
- package/dist/arrow/index.js +3 -0
- package/dist/arrow/index.js.map +1 -1
- package/dist/arrow/internal.cjs.map +2 -2
- package/dist/dist.dev.js +1233 -442
- package/dist/dist.min.js +126 -108
- package/dist/experimental/index.cjs.map +1 -1
- package/dist/experimental/simulation/index.cjs.map +1 -1
- package/dist/gpu-core/compiled-gpu-graph.cjs +47 -0
- package/dist/gpu-core/compiled-gpu-graph.d.ts +5 -0
- package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
- package/dist/gpu-core/compiled-gpu-graph.js +54 -1
- package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
- package/dist/gpu-core/gpu-command-graph.cjs +28 -7
- package/dist/gpu-core/gpu-command-graph.d.ts +13 -4
- package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
- package/dist/gpu-core/gpu-command-graph.js +33 -7
- package/dist/gpu-core/gpu-command-graph.js.map +1 -1
- package/dist/gpu-core/gpu-cpu-execution.cjs +279 -0
- package/dist/gpu-core/gpu-cpu-execution.d.ts +22 -0
- package/dist/gpu-core/gpu-cpu-execution.d.ts.map +1 -0
- package/dist/gpu-core/gpu-cpu-execution.js +294 -0
- package/dist/gpu-core/gpu-cpu-execution.js.map +1 -0
- package/dist/gpu-core/gpu-cpu-operation.cjs +54 -0
- package/dist/gpu-core/gpu-cpu-operation.d.ts +40 -0
- package/dist/gpu-core/gpu-cpu-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-cpu-operation.js +35 -0
- package/dist/gpu-core/gpu-cpu-operation.js.map +1 -0
- package/dist/gpu-core/gpu-expression-operation.cjs +2 -2
- package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
- package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-operation.js +1 -1
- package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
- package/dist/gpu-core/gpu-expression-plan.cjs +5 -1
- package/dist/gpu-core/gpu-expression-plan.d.ts +3 -2
- package/dist/gpu-core/gpu-expression-plan.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-plan.js +7 -1
- package/dist/gpu-core/gpu-expression-plan.js.map +1 -1
- package/dist/gpu-core/gpu-graph.d.ts +2 -2
- package/dist/gpu-core/gpu-graph.d.ts.map +1 -1
- package/dist/gpu-core/gpu-graph.js.map +1 -1
- package/dist/gpu-core/gpu-operation.d.ts +4 -4
- package/dist/gpu-core/gpu-operation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-operation.js.map +1 -1
- package/dist/gpu-core/gpu-render-operation.cjs +39 -0
- package/dist/gpu-core/gpu-render-operation.d.ts +21 -0
- package/dist/gpu-core/gpu-render-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-render-operation.js +22 -0
- package/dist/gpu-core/gpu-render-operation.js.map +1 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.cjs +267 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.d.ts +29 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.d.ts.map +1 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.js +260 -0
- package/dist/gpu-core/gpu-shader-pass-kernel.js.map +1 -0
- package/dist/gpu-core/gpu-shader-pass-operation.cjs +85 -0
- package/dist/gpu-core/gpu-shader-pass-operation.d.ts +32 -0
- package/dist/gpu-core/gpu-shader-pass-operation.d.ts.map +1 -0
- package/dist/gpu-core/gpu-shader-pass-operation.js +74 -0
- package/dist/gpu-core/gpu-shader-pass-operation.js.map +1 -0
- package/dist/gpu-core/gpu-texture-plan.d.ts +3 -2
- package/dist/gpu-core/gpu-texture-plan.d.ts.map +1 -1
- package/dist/gpu-core/gpu-texture-plan.js.map +1 -1
- package/dist/gpu-core/index.cjs +9 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +6 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +3 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-data/cpu-data.cjs +60 -0
- package/dist/gpu-data/cpu-data.d.ts +28 -0
- package/dist/gpu-data/cpu-data.d.ts.map +1 -0
- package/dist/gpu-data/cpu-data.js +41 -0
- package/dist/gpu-data/cpu-data.js.map +1 -0
- package/dist/gpu-data/cpu-gpu-vector-transfer.cjs +93 -0
- package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts +9 -0
- package/dist/gpu-data/cpu-gpu-vector-transfer.d.ts.map +1 -0
- package/dist/gpu-data/cpu-gpu-vector-transfer.js +82 -0
- package/dist/gpu-data/cpu-gpu-vector-transfer.js.map +1 -0
- package/dist/gpu-data/cpu-vector.cjs +42 -0
- package/dist/gpu-data/cpu-vector.d.ts +17 -0
- package/dist/gpu-data/cpu-vector.d.ts.map +1 -0
- package/dist/gpu-data/cpu-vector.js +21 -0
- package/dist/gpu-data/cpu-vector.js.map +1 -0
- package/dist/gpu-data/index.cjs +13 -2
- package/dist/gpu-data/index.cjs.map +3 -3
- package/dist/gpu-data/index.d.ts +3 -0
- package/dist/gpu-data/index.d.ts.map +1 -1
- package/dist/gpu-data/index.js +3 -0
- package/dist/gpu-data/index.js.map +1 -1
- package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
- package/dist/gpu-graph/index.cjs +3 -0
- package/dist/gpu-graph/index.cjs.map +3 -3
- package/dist/gpu-graph/index.d.ts +2 -0
- package/dist/gpu-graph/index.d.ts.map +1 -1
- package/dist/gpu-graph/index.js +1 -0
- package/dist/gpu-graph/index.js.map +1 -1
- package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
- package/dist/gpu-physics/index.cjs.map +1 -1
- package/dist/gpu-project/coordinate-projection-graph.cjs +59 -0
- package/dist/gpu-project/coordinate-projection-graph.d.ts +23 -0
- package/dist/gpu-project/coordinate-projection-graph.d.ts.map +1 -0
- package/dist/gpu-project/coordinate-projection-graph.js +40 -0
- package/dist/gpu-project/coordinate-projection-graph.js.map +1 -0
- package/dist/gpu-project/cpu-geoarrow.cjs +112 -0
- package/dist/gpu-project/cpu-geoarrow.d.ts +10 -0
- package/dist/gpu-project/cpu-geoarrow.d.ts.map +1 -0
- package/dist/gpu-project/cpu-geoarrow.js +103 -0
- package/dist/gpu-project/cpu-geoarrow.js.map +1 -0
- package/dist/gpu-project/cpu-geometry-pipelines.cjs +134 -0
- package/dist/gpu-project/cpu-geometry-pipelines.d.ts +18 -0
- package/dist/gpu-project/cpu-geometry-pipelines.d.ts.map +1 -0
- package/dist/gpu-project/cpu-geometry-pipelines.js +114 -0
- package/dist/gpu-project/cpu-geometry-pipelines.js.map +1 -0
- package/dist/gpu-project/cpu-projection-operation.cjs +54 -0
- package/dist/gpu-project/cpu-projection-operation.d.ts +14 -0
- package/dist/gpu-project/cpu-projection-operation.d.ts.map +1 -0
- package/dist/gpu-project/cpu-projection-operation.js +37 -0
- package/dist/gpu-project/cpu-projection-operation.js.map +1 -0
- package/dist/gpu-project/geoarrow.cjs +36 -0
- package/dist/gpu-project/geoarrow.cjs.map +6 -0
- package/dist/gpu-project/geoarrow.d.ts +3 -0
- package/dist/gpu-project/geoarrow.d.ts.map +1 -0
- package/dist/gpu-project/geoarrow.js +7 -0
- package/dist/gpu-project/geoarrow.js.map +1 -0
- package/dist/gpu-project/graph.cjs +27 -0
- package/dist/gpu-project/graph.cjs.map +6 -0
- package/dist/gpu-project/graph.d.ts +2 -0
- package/dist/gpu-project/graph.d.ts.map +1 -0
- package/dist/gpu-project/graph.js +6 -0
- package/dist/gpu-project/graph.js.map +1 -0
- package/dist/gpu-project/index.cjs +3 -0
- package/dist/gpu-project/index.cjs.map +3 -3
- package/dist/gpu-project/index.d.ts +1 -0
- package/dist/gpu-project/index.d.ts.map +1 -1
- package/dist/gpu-project/index.js +1 -0
- package/dist/gpu-project/index.js.map +1 -1
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +75 -5
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +5 -1
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts.map +1 -1
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js +86 -6
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph-lowering.cjs +9 -0
- package/dist/gpu-simple-graph/gpu-simple-graph-lowering.d.ts +2 -0
- package/dist/gpu-simple-graph/gpu-simple-graph-lowering.d.ts.map +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph-lowering.js +10 -0
- package/dist/gpu-simple-graph/gpu-simple-graph-lowering.js.map +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph.cjs +126 -10
- package/dist/gpu-simple-graph/gpu-simple-graph.d.ts +36 -11
- package/dist/gpu-simple-graph/gpu-simple-graph.d.ts.map +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph.js +137 -12
- package/dist/gpu-simple-graph/gpu-simple-graph.js.map +1 -1
- package/dist/gpu-simple-graph/index.cjs.map +3 -3
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.cjs +23 -0
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.d.ts +6 -0
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js +25 -0
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.js.map +1 -1
- package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.cjs +7 -0
- package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.d.ts +2 -0
- package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.js +7 -0
- package/dist/gpu-simple-graph/operation/gpu-vector-evaluator.js.map +1 -1
- package/dist/gpu-simple-graph/operations/webgl/index.cjs.map +1 -1
- package/dist/gpu-simple-graph/operations/webgpu/index.cjs.map +1 -1
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +17 -6
- package/src/arrow/cpu/arrow-coordinate-projection.ts +18 -0
- package/src/arrow/cpu/arrow-cpu-pipelines.ts +9 -0
- package/src/arrow/cpu/arrow-cpu-vector-adapters.ts +153 -0
- package/src/arrow/geoarrow/arrow-geoarrow-adapter.ts +23 -493
- package/src/arrow/geoarrow/arrow-geoarrow-conversion.ts +5 -3
- package/src/arrow/geoarrow/arrow-polygon-tessellation.ts +1 -1
- package/src/arrow/index.ts +11 -0
- package/src/gpu-core/compiled-gpu-graph.ts +73 -1
- package/src/gpu-core/gpu-command-graph.ts +37 -7
- package/src/gpu-core/gpu-cpu-execution.ts +345 -0
- package/src/gpu-core/gpu-cpu-operation.ts +65 -0
- package/src/gpu-core/gpu-expression-operation.ts +1 -1
- package/src/gpu-core/gpu-expression-plan.ts +11 -3
- package/src/gpu-core/gpu-graph.ts +3 -3
- package/src/gpu-core/gpu-operation.ts +9 -7
- package/src/gpu-core/gpu-render-operation.ts +42 -0
- package/src/gpu-core/gpu-shader-pass-kernel.ts +307 -0
- package/src/gpu-core/gpu-shader-pass-operation.ts +103 -0
- package/src/gpu-core/gpu-texture-plan.ts +3 -2
- package/src/gpu-core/index.ts +12 -0
- package/src/gpu-data/cpu-data.ts +62 -0
- package/src/gpu-data/cpu-gpu-vector-transfer.ts +107 -0
- package/src/gpu-data/cpu-vector.ts +31 -0
- package/src/gpu-data/index.ts +5 -0
- package/src/gpu-graph/index.ts +8 -0
- package/src/gpu-project/coordinate-projection-graph.ts +59 -0
- package/src/gpu-project/cpu-geoarrow.ts +135 -0
- package/src/gpu-project/cpu-geometry-pipelines.ts +159 -0
- package/src/gpu-project/cpu-projection-operation.ts +49 -0
- package/src/gpu-project/geoarrow.ts +11 -0
- package/src/gpu-project/graph.ts +10 -0
- package/src/gpu-project/index.ts +2 -0
- package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +97 -6
- package/src/gpu-simple-graph/gpu-simple-graph-lowering.ts +11 -0
- package/src/gpu-simple-graph/gpu-simple-graph.ts +163 -19
- package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +22 -0
- package/src/gpu-simple-graph/operation/gpu-vector-evaluator.ts +7 -0
- package/src/index.ts +10 -0
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Buffer, Texture, TextureView, type Device} from '@luma.gl/core';
|
|
6
|
-
import {GPUData, GPUVector, getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
|
|
6
|
+
import {CPUVector, GPUData, GPUVector, getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
|
|
7
7
|
import type {GPUGraph} from './gpu-graph';
|
|
8
8
|
import {GPUCopyOperation} from './gpu-transfer-operation';
|
|
9
|
+
import {GPUShaderPassOperation} from './gpu-shader-pass-operation';
|
|
9
10
|
import {validateTextureCopy} from './gpu-texture-copy';
|
|
10
11
|
import {
|
|
11
12
|
GPUTextureInvocation,
|
|
@@ -37,7 +38,7 @@ import {
|
|
|
37
38
|
} from './gpu-operation-contract';
|
|
38
39
|
|
|
39
40
|
export type GPUGraphRunBindings = Readonly<
|
|
40
|
-
Record<string, GPUVector | number | GPUGraphTextureBinding>
|
|
41
|
+
Record<string, GPUVector | CPUVector | number | GPUGraphTextureBinding>
|
|
41
42
|
>;
|
|
42
43
|
export type GPUGraphExecutionBindings = {
|
|
43
44
|
inputs?: GPUGraphRunBindings;
|
|
@@ -46,6 +47,7 @@ export type GPUGraphExecutionBindings = {
|
|
|
46
47
|
};
|
|
47
48
|
export type GPUGraphCompileOptions = {
|
|
48
49
|
outputs?: readonly string[];
|
|
50
|
+
outputLocations?: Readonly<Record<string, 'cpu' | 'gpu'>>;
|
|
49
51
|
lowerings?: readonly GPUOperationLowering[];
|
|
50
52
|
};
|
|
51
53
|
export type GPUGraphRunOptions = {outputTargets?: Readonly<Record<string, GPUGraphOutput>>};
|
|
@@ -88,6 +90,11 @@ export class GPUExpressionProgram {
|
|
|
88
90
|
operation.operations.forEach(flatten);
|
|
89
91
|
else {
|
|
90
92
|
if (operation instanceof GPUCompositeOperation) {
|
|
93
|
+
const containsShaderPass = (child: GPUGraphOperation): boolean =>
|
|
94
|
+
child instanceof GPUShaderPassOperation ||
|
|
95
|
+
(child instanceof GPUCompositeOperation && child.operations.some(containsShaderPass));
|
|
96
|
+
if (operation.operations.some(containsShaderPass))
|
|
97
|
+
throw new Error('Shader-pass operations inside control flow are not supported');
|
|
91
98
|
const containsExpression = (child: GPUGraphOperation): boolean =>
|
|
92
99
|
child instanceof GPUExpressionOperation ||
|
|
93
100
|
(child instanceof GPUCompositeOperation && child.operations.some(containsExpression));
|
|
@@ -259,6 +266,7 @@ export class GPUExpressionProgram {
|
|
|
259
266
|
value !== undefined &&
|
|
260
267
|
typeof value === 'object' &&
|
|
261
268
|
!(value instanceof GPUVector) &&
|
|
269
|
+
!(value instanceof CPUVector) &&
|
|
262
270
|
!(value instanceof Texture) &&
|
|
263
271
|
!(value instanceof TextureView)
|
|
264
272
|
);
|
|
@@ -272,7 +280,7 @@ export class GPUExpressionProgram {
|
|
|
272
280
|
if (!['inputs', 'state', 'outputTargets'].includes(name))
|
|
273
281
|
throw new Error(`Unknown execution option ${name}`);
|
|
274
282
|
const execution = supplied as GPUGraphExecutionBindings;
|
|
275
|
-
const bindings: Record<string, GPUVector | number | GPUGraphTextureBinding> =
|
|
283
|
+
const bindings: Record<string, GPUVector | CPUVector | number | GPUGraphTextureBinding> =
|
|
276
284
|
Object.create(null);
|
|
277
285
|
for (const [role, group] of [
|
|
278
286
|
['input', execution.inputs],
|
|
@@ -222,9 +222,9 @@ export class GPUGraph {
|
|
|
222
222
|
throw new Error(`${this.id} accepts GPU operations only`);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
export function composite(
|
|
226
|
-
operations: readonly
|
|
225
|
+
export function composite<Operation extends GPUGraphOperation>(
|
|
226
|
+
operations: readonly Operation[],
|
|
227
227
|
props: {id?: string} = {}
|
|
228
|
-
): GPUCompositeOperation {
|
|
228
|
+
): GPUCompositeOperation<Operation> {
|
|
229
229
|
return new GPUCompositeOperation({id: props.id, operations});
|
|
230
230
|
}
|
|
@@ -49,30 +49,32 @@ export type GPUGraphOperation =
|
|
|
49
49
|
export type GPUOperationLike = GPUGraphOperation | readonly GPUOperationLike[];
|
|
50
50
|
|
|
51
51
|
/** Semantic hierarchy. Grouping never implies synchronization or a command-graph child graph. */
|
|
52
|
-
export class GPUCompositeOperation
|
|
52
|
+
export class GPUCompositeOperation<Operation extends GPUGraphOperation = GPUGraphOperation>
|
|
53
|
+
implements GPUOperation
|
|
54
|
+
{
|
|
53
55
|
readonly id: string;
|
|
54
56
|
readonly type: string = 'composite';
|
|
55
|
-
readonly operations: readonly
|
|
57
|
+
readonly operations: readonly Operation[];
|
|
56
58
|
readonly metadata?: GPUOperationMetadata;
|
|
57
59
|
|
|
58
60
|
constructor(
|
|
59
61
|
props:
|
|
60
|
-
| readonly
|
|
62
|
+
| readonly Operation[]
|
|
61
63
|
| {
|
|
62
64
|
id?: string;
|
|
63
|
-
operations: readonly
|
|
65
|
+
operations: readonly Operation[];
|
|
64
66
|
metadata?: GPUOperationMetadata;
|
|
65
67
|
}
|
|
66
68
|
) {
|
|
67
69
|
const normalized: {
|
|
68
70
|
id?: string;
|
|
69
|
-
operations: readonly
|
|
71
|
+
operations: readonly Operation[];
|
|
70
72
|
metadata?: GPUOperationMetadata;
|
|
71
73
|
} = Array.isArray(props)
|
|
72
|
-
? {operations: props as readonly
|
|
74
|
+
? {operations: props as readonly Operation[]}
|
|
73
75
|
: (props as {
|
|
74
76
|
id?: string;
|
|
75
|
-
operations: readonly
|
|
77
|
+
operations: readonly Operation[];
|
|
76
78
|
metadata?: GPUOperationMetadata;
|
|
77
79
|
});
|
|
78
80
|
this.id = normalized.id ?? 'gpu-composite-operation';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {GPUCommandGraph} from './gpu-command-graph';
|
|
6
|
+
import type {GPURenderCommandNode} from './gpu-command-node';
|
|
7
|
+
|
|
8
|
+
/** Resource declarations shared by SimpleGraph and full WebGPU graphs. */
|
|
9
|
+
export type GPURenderOperationResources<Parameters = unknown> = Pick<
|
|
10
|
+
GPUCommandGraph<Parameters>,
|
|
11
|
+
'device' | 'importBuffer' | 'importTexture' | 'createTransientTexture' | 'createTextureView'
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A reusable render primitive. Each compilation creates fresh logical resources and executables.
|
|
16
|
+
* Declare every buffer and texture access so the containing graph can schedule its passes.
|
|
17
|
+
* Omit the parameter type for passes that do not inspect application parameters.
|
|
18
|
+
*/
|
|
19
|
+
export class GPURenderOperation<Parameters = unknown> {
|
|
20
|
+
readonly type = 'render-operation';
|
|
21
|
+
readonly id: string;
|
|
22
|
+
private readonly createNodes: (
|
|
23
|
+
graph: GPURenderOperationResources<Parameters>
|
|
24
|
+
) => readonly GPURenderCommandNode<Parameters>[];
|
|
25
|
+
|
|
26
|
+
constructor(props: {
|
|
27
|
+
id: string;
|
|
28
|
+
createNodes: (
|
|
29
|
+
graph: GPURenderOperationResources<Parameters>
|
|
30
|
+
) => readonly GPURenderCommandNode<Parameters>[];
|
|
31
|
+
}) {
|
|
32
|
+
this.id = props.id;
|
|
33
|
+
this.createNodes = props.createNodes;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Contributes individual passes to the containing graph; never compiles or submits it. */
|
|
37
|
+
getCommandNodes(
|
|
38
|
+
graph: GPURenderOperationResources<Parameters>
|
|
39
|
+
): readonly GPURenderCommandNode<Parameters>[] {
|
|
40
|
+
return this.createNodes(graph);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
assert,
|
|
7
|
+
Buffer,
|
|
8
|
+
type Binding,
|
|
9
|
+
type CommandEncoder,
|
|
10
|
+
type Device,
|
|
11
|
+
type RenderPass,
|
|
12
|
+
type Sampler,
|
|
13
|
+
type VertexArray
|
|
14
|
+
} from '@luma.gl/core';
|
|
15
|
+
import {GPUVector} from '@luma.gl/graph/gpu-data';
|
|
16
|
+
import {RenderKernel} from '../execution/compute/render-kernel';
|
|
17
|
+
import type {GPUShaderPassOperation} from './gpu-shader-pass-operation';
|
|
18
|
+
import type {GPUExpressionProgram} from './gpu-expression-plan';
|
|
19
|
+
import type {GPUOperationLoweringContext} from './gpu-graph-lowering';
|
|
20
|
+
import {getGPUScalarWGSLType} from './gpu-scalar';
|
|
21
|
+
import {getTextureBindingInfo, type GPUGraphTextureBinding} from './gpu-texture-plan';
|
|
22
|
+
|
|
23
|
+
const VERTEX_SOURCE = `
|
|
24
|
+
struct GraphShaderPassVertex {
|
|
25
|
+
@builtin(position) position: vec4<f32>,
|
|
26
|
+
@location(0) textureCoordinates: vec2<f32>
|
|
27
|
+
};
|
|
28
|
+
@vertex fn vertexMain(@builtin(vertex_index) index: u32) -> GraphShaderPassVertex {
|
|
29
|
+
let position = vec2<f32>(f32((index << 1u) & 2u), f32(index & 2u));
|
|
30
|
+
var result: GraphShaderPassVertex;
|
|
31
|
+
result.position = vec4<f32>(position * 2.0 - 1.0, 0.0, 1.0);
|
|
32
|
+
result.textureCoordinates = vec2<f32>(position.x, 1.0 - position.y);
|
|
33
|
+
return result;
|
|
34
|
+
}`;
|
|
35
|
+
|
|
36
|
+
/** One immutable pipeline; resources and uniforms are supplied independently for each draw. @internal */
|
|
37
|
+
export class GPUShaderPassKernel {
|
|
38
|
+
private kernel!: RenderKernel;
|
|
39
|
+
private vertexArray!: VertexArray;
|
|
40
|
+
private readonly samplers: Record<string, Sampler> = Object.create(null);
|
|
41
|
+
private readonly parameterFormats: readonly ('float32' | 'uint32' | 'sint32')[];
|
|
42
|
+
private readonly parameterByteLength: number;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
readonly device: Device,
|
|
46
|
+
readonly operation: GPUShaderPassOperation,
|
|
47
|
+
program: Pick<GPUExpressionProgram, 'textures' | 'scalars'>
|
|
48
|
+
) {
|
|
49
|
+
assert(device.type === 'webgpu');
|
|
50
|
+
this.parameterFormats = Object.values(operation.parameters).map(name => {
|
|
51
|
+
const scalar = program.scalars.find(value => value.id === name);
|
|
52
|
+
assert(scalar);
|
|
53
|
+
return scalar.format;
|
|
54
|
+
});
|
|
55
|
+
this.parameterByteLength = Math.ceil(this.parameterFormats.length / 4) * 16;
|
|
56
|
+
// This first shader-pass contract samples filterable float color and writes float color.
|
|
57
|
+
for (const name of Object.values(operation.inputs)) {
|
|
58
|
+
const input = program.textures.find(texture => texture.id === name)!;
|
|
59
|
+
const info = device.getTextureFormatInfo(input.format);
|
|
60
|
+
assert(
|
|
61
|
+
!info.integer &&
|
|
62
|
+
info.attachment !== 'depth' &&
|
|
63
|
+
info.attachment !== 'depth-stencil' &&
|
|
64
|
+
device.getTextureFormatCapabilities(input.format).filter
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const outputInfo = device.getTextureFormatInfo(operation.outputDescriptor.format);
|
|
68
|
+
assert(
|
|
69
|
+
!outputInfo.integer &&
|
|
70
|
+
device.getTextureFormatCapabilities(operation.outputDescriptor.format).render
|
|
71
|
+
);
|
|
72
|
+
const shaderBindings: import('@luma.gl/core').ShaderLayout['bindings'] = [
|
|
73
|
+
...Object.keys(operation.inputs).map((name, location) => ({
|
|
74
|
+
name,
|
|
75
|
+
location,
|
|
76
|
+
group: 0,
|
|
77
|
+
type: 'texture' as const,
|
|
78
|
+
viewDimension: '2d' as const,
|
|
79
|
+
sampleType: 'float' as const
|
|
80
|
+
})),
|
|
81
|
+
...Object.keys(operation.samplers).map((name, index) => ({
|
|
82
|
+
name,
|
|
83
|
+
location: Object.keys(operation.inputs).length + index,
|
|
84
|
+
group: 0,
|
|
85
|
+
type: 'sampler' as const
|
|
86
|
+
}))
|
|
87
|
+
];
|
|
88
|
+
let binding = 0;
|
|
89
|
+
const declarations = [
|
|
90
|
+
...Object.keys(operation.inputs).map(
|
|
91
|
+
name => `@group(0) @binding(${binding++}) var ${name}: texture_2d<f32>;`
|
|
92
|
+
),
|
|
93
|
+
...Object.keys(operation.samplers).map(
|
|
94
|
+
name => `@group(0) @binding(${binding++}) var ${name}: sampler;`
|
|
95
|
+
)
|
|
96
|
+
];
|
|
97
|
+
if (this.parameterFormats.length) {
|
|
98
|
+
shaderBindings.push({name: 'parameters', location: binding, group: 0, type: 'uniform'});
|
|
99
|
+
declarations.push(
|
|
100
|
+
`struct GraphShaderPassParameters {${Object.keys(operation.parameters)
|
|
101
|
+
.map((name, index) => `${name}: ${getGPUScalarWGSLType(this.parameterFormats[index])}`)
|
|
102
|
+
.join(
|
|
103
|
+
','
|
|
104
|
+
)}};\n@group(0) @binding(${binding}) var<uniform> parameters: GraphShaderPassParameters;`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
this.kernel = new RenderKernel(device, {
|
|
109
|
+
id: operation.id,
|
|
110
|
+
vertexSource: VERTEX_SOURCE,
|
|
111
|
+
fragmentSource: `${declarations.join('\n')}\n${operation.fragmentSource}\n
|
|
112
|
+
@fragment fn fragmentMain(@location(0) textureCoordinates: vec2<f32>) -> @location(0) vec4<f32> {
|
|
113
|
+
return shade(textureCoordinates);
|
|
114
|
+
}`,
|
|
115
|
+
vertexEntryPoint: 'vertexMain',
|
|
116
|
+
fragmentEntryPoint: 'fragmentMain',
|
|
117
|
+
topology: 'triangle-list',
|
|
118
|
+
shaderLayout: {attributes: [], bindings: shaderBindings},
|
|
119
|
+
colorAttachmentFormats: [operation.outputDescriptor.format],
|
|
120
|
+
parameters: {depthWriteEnabled: false}
|
|
121
|
+
});
|
|
122
|
+
this.vertexArray = device.createVertexArray({
|
|
123
|
+
shaderLayout: this.kernel.pipeline.shaderLayout,
|
|
124
|
+
bufferLayout: []
|
|
125
|
+
});
|
|
126
|
+
for (const [name, props] of Object.entries(operation.samplers))
|
|
127
|
+
this.samplers[name] = device.createSampler(props);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
this.destroy();
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Validate selected view geometry before either executor records commands. */
|
|
135
|
+
validateTextures(textures: ReadonlyMap<string, GPUGraphTextureBinding>): void {
|
|
136
|
+
for (const name of [...Object.values(this.operation.inputs), this.operation.output]) {
|
|
137
|
+
const binding = textures.get(name);
|
|
138
|
+
assert(binding);
|
|
139
|
+
const info = getTextureBindingInfo(binding);
|
|
140
|
+
assert(
|
|
141
|
+
info.texture.device === this.device &&
|
|
142
|
+
info.dimension === '2d' &&
|
|
143
|
+
info.depth === 1 &&
|
|
144
|
+
info.samples === 1
|
|
145
|
+
);
|
|
146
|
+
if (name === this.operation.output) assert(info.mipLevels === 1);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Full graph lowers to ordinary resource-tracked copy and render nodes. */
|
|
151
|
+
lower<Parameters>(context: GPUOperationLoweringContext<Parameters>): void {
|
|
152
|
+
const operation = this.operation;
|
|
153
|
+
const inputs = Object.fromEntries(
|
|
154
|
+
Object.entries(operation.inputs).map(([name, value]) => [
|
|
155
|
+
name,
|
|
156
|
+
context.resolveTextureView(value)
|
|
157
|
+
])
|
|
158
|
+
);
|
|
159
|
+
const output = context.resolveTextureView(operation.output);
|
|
160
|
+
const parameters = this.parameterFormats.length
|
|
161
|
+
? context.graph.createTransientBuffer({
|
|
162
|
+
id: context.graph.getUniqueResourceId(`${operation.id}-parameters`),
|
|
163
|
+
byteLength: this.parameterByteLength,
|
|
164
|
+
usage: Buffer.UNIFORM | Buffer.COPY_DST
|
|
165
|
+
})
|
|
166
|
+
: undefined;
|
|
167
|
+
if (parameters) {
|
|
168
|
+
const sources = Object.values(operation.parameters).map(
|
|
169
|
+
name => context.resolveScalar(name).view
|
|
170
|
+
);
|
|
171
|
+
context.graph.addCopyPass({
|
|
172
|
+
id: `${operation.id}-parameters`,
|
|
173
|
+
resources: [
|
|
174
|
+
...sources.map(buffer => ({buffer, usage: 'copy-source' as const})),
|
|
175
|
+
{buffer: parameters, usage: 'copy-destination'}
|
|
176
|
+
],
|
|
177
|
+
compile: () => ({
|
|
178
|
+
encode: ({commandEncoder, getBuffer}) => {
|
|
179
|
+
sources.forEach((source, index) =>
|
|
180
|
+
commandEncoder.copyBufferToBuffer({
|
|
181
|
+
sourceBuffer: getBuffer(source),
|
|
182
|
+
sourceOffset: source.byteOffset,
|
|
183
|
+
destinationBuffer: getBuffer(parameters),
|
|
184
|
+
destinationOffset: index * 4,
|
|
185
|
+
size: 4
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
context.graph.addRenderPass({
|
|
193
|
+
id: operation.id,
|
|
194
|
+
resources: [
|
|
195
|
+
...Object.values(inputs).map(texture => ({texture, usage: 'sampled' as const})),
|
|
196
|
+
...(parameters ? [{buffer: parameters, usage: 'uniform' as const}] : [])
|
|
197
|
+
],
|
|
198
|
+
attachments: {colorAttachments: [output]},
|
|
199
|
+
compile: () => ({
|
|
200
|
+
getRenderPassProps: () => ({clearColor: [0, 0, 0, 0], clearDepth: false}),
|
|
201
|
+
encode: ({renderPass, getTextureView, getBuffer}) =>
|
|
202
|
+
this.draw(
|
|
203
|
+
renderPass,
|
|
204
|
+
Object.fromEntries(
|
|
205
|
+
Object.entries(inputs).map(([name, view]) => [name, getTextureView(view)])
|
|
206
|
+
),
|
|
207
|
+
parameters ? getBuffer(parameters) : undefined
|
|
208
|
+
)
|
|
209
|
+
})
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** SimpleGraph owns only per-invocation framebuffer/uniform wrappers, never bound textures. */
|
|
214
|
+
prepare(
|
|
215
|
+
textures: ReadonlyMap<string, GPUGraphTextureBinding>,
|
|
216
|
+
values: ReadonlyMap<string, GPUVector | number>
|
|
217
|
+
) {
|
|
218
|
+
this.validateTextures(textures);
|
|
219
|
+
const inputs = Object.fromEntries(
|
|
220
|
+
Object.entries(this.operation.inputs).map(([name, value]) => [name, textures.get(value)!])
|
|
221
|
+
);
|
|
222
|
+
const output = textures.get(this.operation.output)!;
|
|
223
|
+
const info = getTextureBindingInfo(output);
|
|
224
|
+
const data = new Uint8Array(this.parameterByteLength);
|
|
225
|
+
const view = new DataView(data.buffer);
|
|
226
|
+
const parameterValues = Object.values(this.operation.parameters).map((name, index) => {
|
|
227
|
+
const value = values.get(name);
|
|
228
|
+
assert(value !== undefined);
|
|
229
|
+
if (typeof value === 'number') {
|
|
230
|
+
switch (this.parameterFormats[index]) {
|
|
231
|
+
case 'float32':
|
|
232
|
+
view.setFloat32(index * 4, value, true);
|
|
233
|
+
break;
|
|
234
|
+
case 'sint32':
|
|
235
|
+
view.setInt32(index * 4, value, true);
|
|
236
|
+
break;
|
|
237
|
+
case 'uint32':
|
|
238
|
+
view.setUint32(index * 4, value, true);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
} else assert(value.length === 1 && value.data.length === 1);
|
|
242
|
+
return value;
|
|
243
|
+
});
|
|
244
|
+
const parameters = data.byteLength
|
|
245
|
+
? this.device.createBuffer({data, usage: Buffer.UNIFORM | Buffer.COPY_DST})
|
|
246
|
+
: undefined;
|
|
247
|
+
let framebuffer;
|
|
248
|
+
try {
|
|
249
|
+
framebuffer = this.device.createFramebuffer({
|
|
250
|
+
width: info.width,
|
|
251
|
+
height: info.height,
|
|
252
|
+
colorAttachments: [output]
|
|
253
|
+
});
|
|
254
|
+
} catch (error) {
|
|
255
|
+
parameters?.destroy();
|
|
256
|
+
throw error;
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
encode: (commandEncoder: CommandEncoder) => {
|
|
260
|
+
this.validateTextures(textures);
|
|
261
|
+
if (parameters)
|
|
262
|
+
parameterValues.forEach((value, index) => {
|
|
263
|
+
if (!(value instanceof GPUVector)) return;
|
|
264
|
+
const chunk = value.data[0];
|
|
265
|
+
const buffer = chunk.buffer instanceof Buffer ? chunk.buffer : chunk.buffer.buffer;
|
|
266
|
+
commandEncoder.copyBufferToBuffer({
|
|
267
|
+
sourceBuffer: buffer,
|
|
268
|
+
sourceOffset: chunk.byteOffset,
|
|
269
|
+
destinationBuffer: parameters,
|
|
270
|
+
destinationOffset: index * 4,
|
|
271
|
+
size: 4
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
const pass = commandEncoder.beginRenderPass({
|
|
275
|
+
framebuffer,
|
|
276
|
+
clearColor: [0, 0, 0, 0],
|
|
277
|
+
clearDepth: false
|
|
278
|
+
});
|
|
279
|
+
try {
|
|
280
|
+
this.draw(pass, inputs, parameters);
|
|
281
|
+
} finally {
|
|
282
|
+
pass.end();
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
destroy: () => {
|
|
286
|
+
framebuffer.destroy();
|
|
287
|
+
parameters?.destroy();
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
destroy(): void {
|
|
293
|
+
for (const sampler of Object.values(this.samplers)) sampler.destroy();
|
|
294
|
+
this.vertexArray?.destroy();
|
|
295
|
+
this.kernel?.destroy();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private draw(
|
|
299
|
+
renderPass: RenderPass,
|
|
300
|
+
inputs: Record<string, GPUGraphTextureBinding>,
|
|
301
|
+
parameters?: Buffer
|
|
302
|
+
): void {
|
|
303
|
+
const bindings: Record<string, Binding> = {...inputs, ...this.samplers};
|
|
304
|
+
if (parameters) bindings['parameters'] = parameters;
|
|
305
|
+
this.kernel.draw(renderPass, {vertexArray: this.vertexArray, vertexCount: 3, bindings});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {assert, type SamplerProps, type TextureFormatColor} from '@luma.gl/core';
|
|
6
|
+
import {gpuGraph, type GPUGraphTextureDescriptor} from './gpu-graph-value';
|
|
7
|
+
import type {GPUOperation} from './gpu-operation';
|
|
8
|
+
import type {GPUOperationContract} from './gpu-operation-contract';
|
|
9
|
+
|
|
10
|
+
export type GPUShaderPassOperationProps = {
|
|
11
|
+
id?: string;
|
|
12
|
+
/** WGSL defining fn shade(textureCoordinates: vec2<f32>) -> vec4<f32>. */
|
|
13
|
+
fragmentSource: string;
|
|
14
|
+
/** Shader texture binding names mapped to logical graph texture names. */
|
|
15
|
+
inputs: Readonly<Record<string, string>>;
|
|
16
|
+
/** Explicit, immutable color sampler descriptions, keyed by shader binding name. */
|
|
17
|
+
samplers?: Readonly<Record<string, SamplerProps>>;
|
|
18
|
+
/** Fields of the generated parameters uniform, mapped to graph scalar names. */
|
|
19
|
+
parameters?: Readonly<Record<string, string>>;
|
|
20
|
+
output: string;
|
|
21
|
+
/** Single-sampled 2D color result with an explicit fixed or inherited extent. */
|
|
22
|
+
outputDescriptor: GPUGraphTextureDescriptor<TextureFormatColor>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** One fullscreen WGSL draw, shared by GPUGraph and WebGPU SimpleGraph. */
|
|
26
|
+
export class GPUShaderPassOperation implements GPUOperation {
|
|
27
|
+
readonly type = 'shader-pass';
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly fragmentSource: string;
|
|
30
|
+
readonly inputs: Readonly<Record<string, string>>;
|
|
31
|
+
readonly samplers: Readonly<Record<string, Readonly<SamplerProps>>>;
|
|
32
|
+
readonly parameters: Readonly<Record<string, string>>;
|
|
33
|
+
readonly output: string;
|
|
34
|
+
readonly outputDescriptor: GPUGraphTextureDescriptor<TextureFormatColor>;
|
|
35
|
+
|
|
36
|
+
constructor(props: GPUShaderPassOperationProps) {
|
|
37
|
+
this.id = props.id ?? `${props.output}-shader-pass`;
|
|
38
|
+
this.fragmentSource = props.fragmentSource;
|
|
39
|
+
this.inputs = Object.freeze({...props.inputs});
|
|
40
|
+
this.parameters = Object.freeze({...props.parameters});
|
|
41
|
+
this.samplers = Object.freeze(
|
|
42
|
+
Object.fromEntries(
|
|
43
|
+
Object.entries(props.samplers ?? {}).map(([name, sampler]) => [
|
|
44
|
+
name,
|
|
45
|
+
Object.freeze({...sampler})
|
|
46
|
+
])
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
this.output = props.output;
|
|
50
|
+
const descriptor = props.outputDescriptor;
|
|
51
|
+
// This operation writes one complete 2D color attachment, without mip generation or MSAA.
|
|
52
|
+
assert(
|
|
53
|
+
descriptor.extent &&
|
|
54
|
+
(descriptor.dimension ?? '2d') === '2d' &&
|
|
55
|
+
(descriptor.mipLevels ?? 1) === 1 &&
|
|
56
|
+
(descriptor.samples ?? 1) === 1
|
|
57
|
+
);
|
|
58
|
+
this.outputDescriptor = gpuGraph.texture({
|
|
59
|
+
...descriptor,
|
|
60
|
+
dimension: '2d',
|
|
61
|
+
mipLevels: 1,
|
|
62
|
+
samples: 1
|
|
63
|
+
});
|
|
64
|
+
const bindings = [...Object.keys(this.inputs), ...Object.keys(this.samplers)];
|
|
65
|
+
// Binding names are WGSL identifiers; reserve the generated uniform and entry-point names.
|
|
66
|
+
assert(new Set(bindings).size === bindings.length);
|
|
67
|
+
for (const name of [...bindings, ...Object.keys(this.parameters)])
|
|
68
|
+
assert(
|
|
69
|
+
/^[A-Za-z][A-Za-z0-9_]*$/.test(name) &&
|
|
70
|
+
!['parameters', 'shade', 'vertexMain', 'fragmentMain'].includes(name) &&
|
|
71
|
+
!name.startsWith('GraphShaderPass')
|
|
72
|
+
);
|
|
73
|
+
for (const sampler of Object.values(this.samplers))
|
|
74
|
+
assert((sampler.type ?? 'color-sampler') === 'color-sampler');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get contract(): GPUOperationContract {
|
|
78
|
+
return {
|
|
79
|
+
values: [
|
|
80
|
+
...Object.values(this.inputs).map(value => ({
|
|
81
|
+
value,
|
|
82
|
+
access: 'read' as const,
|
|
83
|
+
textureUsage: 'sampled' as const
|
|
84
|
+
})),
|
|
85
|
+
...Object.values(this.parameters).map(value => ({value, access: 'read' as const})),
|
|
86
|
+
{value: this.output, access: 'write', textureUsage: 'render-attachment'}
|
|
87
|
+
],
|
|
88
|
+
outputs: ({getValue}) => {
|
|
89
|
+
for (const name of Object.values(this.inputs)) {
|
|
90
|
+
const input = getValue(name);
|
|
91
|
+
// Texture views may select one layer of an array, but the logical input is 2D.
|
|
92
|
+
assert(
|
|
93
|
+
input.type === 'texture' &&
|
|
94
|
+
(input.dimension ?? '2d') === '2d' &&
|
|
95
|
+
(input.samples ?? 1) === 1
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
for (const name of Object.values(this.parameters)) assert(getValue(name).type === 'scalar');
|
|
99
|
+
return {[this.output]: this.outputDescriptor};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import type {CPUVector} from '../gpu-data/cpu-vector';
|
|
5
6
|
import {assert, Texture, TextureView, type Device, type TextureViewProps} from '@luma.gl/core';
|
|
6
7
|
import type {GPUVector} from '@luma.gl/graph/gpu-data';
|
|
7
8
|
import type {GPUGraphTexture, GPUGraphTextureDescriptor} from './gpu-graph-value';
|
|
@@ -10,7 +11,7 @@ import {getGPUOperationValueName} from './gpu-operation-contract';
|
|
|
10
11
|
import type {GraphTextureUsage, GraphTextureViewProps} from './gpu-command-graph';
|
|
11
12
|
|
|
12
13
|
export type GPUGraphTextureBinding = Texture | TextureView;
|
|
13
|
-
export type GPUGraphOutput = GPUVector | GPUGraphTextureBinding;
|
|
14
|
+
export type GPUGraphOutput = CPUVector | GPUVector | GPUGraphTextureBinding;
|
|
14
15
|
export type GPUGraphOutputs = Record<string, GPUGraphOutput>;
|
|
15
16
|
|
|
16
17
|
/** Selected view geometry, without creating another view. @internal */
|
|
@@ -109,7 +110,7 @@ export class GPUTextureInvocation {
|
|
|
109
110
|
device: Device,
|
|
110
111
|
declarations: readonly GPUGraphTexture[],
|
|
111
112
|
contracts: readonly GPUOperationContract[],
|
|
112
|
-
bindings: Readonly<Record<string, GPUVector | number | GPUGraphTextureBinding>>,
|
|
113
|
+
bindings: Readonly<Record<string, GPUVector | CPUVector | number | GPUGraphTextureBinding>>,
|
|
113
114
|
targets: Readonly<Record<string, GPUGraphOutput>>
|
|
114
115
|
) {
|
|
115
116
|
const usages = new Map<string, number>();
|
package/src/gpu-core/index.ts
CHANGED
|
@@ -653,6 +653,8 @@ export type {
|
|
|
653
653
|
export type {GPUResourcePreview} from './gpu-resource-preview';
|
|
654
654
|
|
|
655
655
|
export type {GPUIndexPickInfo} from './gpu-index-picking-target';
|
|
656
|
+
export {GPURenderOperation} from './gpu-render-operation';
|
|
657
|
+
export type {GPURenderOperationResources} from './gpu-render-operation';
|
|
656
658
|
|
|
657
659
|
export {GPUExpressionOperation} from './gpu-expression-operation';
|
|
658
660
|
export type {GPUExpressionOperationProps, GPUExpressionAST} from './gpu-expression-operation';
|
|
@@ -684,9 +686,19 @@ export type {
|
|
|
684
686
|
} from './gpu-operation-contract';
|
|
685
687
|
|
|
686
688
|
export {GPUUploadOperation, GPUCopyOperation} from './gpu-transfer-operation';
|
|
689
|
+
export {GPUShaderPassOperation} from './gpu-shader-pass-operation';
|
|
690
|
+
export type {GPUShaderPassOperationProps} from './gpu-shader-pass-operation';
|
|
687
691
|
export type {GPUUploadOperationProps, GPUCopyOperationProps} from './gpu-transfer-operation';
|
|
688
692
|
export {GPUCompactionOperation} from './gpu-compaction-operation';
|
|
689
693
|
export type {GPUCompactionOperationProps} from './gpu-compaction-operation';
|
|
690
694
|
|
|
691
695
|
export type {GPUGraphTextureDescriptor, GPUGraphTextureExtent} from './gpu-graph-value';
|
|
692
696
|
export type {GPUGraphTextureBinding, GPUGraphOutput, GPUGraphOutputs} from './gpu-texture-plan';
|
|
697
|
+
|
|
698
|
+
export {GPUCPUOperation} from './gpu-cpu-operation';
|
|
699
|
+
export type {
|
|
700
|
+
GPUCPUOperationProps,
|
|
701
|
+
GPUCPUArray,
|
|
702
|
+
GPUCPUVector,
|
|
703
|
+
GPUCPUResult
|
|
704
|
+
} from './gpu-cpu-operation';
|
|
@@ -0,0 +1,62 @@
|
|
|
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, type GPUVectorFormat} from './gpu-vector-format';
|
|
7
|
+
|
|
8
|
+
export type CPUDataProps<T extends GPUVectorFormat = GPUVectorFormat> = {
|
|
9
|
+
buffer: ArrayBuffer | ArrayBufferView;
|
|
10
|
+
format: T;
|
|
11
|
+
length: number;
|
|
12
|
+
valueLength?: number;
|
|
13
|
+
/** Byte offset relative to the supplied buffer or view. */
|
|
14
|
+
byteOffset?: number;
|
|
15
|
+
byteStride?: number;
|
|
16
|
+
rowByteLength?: number;
|
|
17
|
+
valueOffsets?: Int32Array;
|
|
18
|
+
nullBitmap?: Uint8Array;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Borrowed CPU storage for fixed rows or one level of list elements. No allocation or copying. */
|
|
22
|
+
export class CPUData<T extends GPUVectorFormat = GPUVectorFormat> {
|
|
23
|
+
readonly buffer: ArrayBufferLike;
|
|
24
|
+
readonly format: T;
|
|
25
|
+
readonly length: number;
|
|
26
|
+
readonly valueLength: number;
|
|
27
|
+
/** Absolute offset into buffer. */
|
|
28
|
+
readonly byteOffset: number;
|
|
29
|
+
readonly byteStride: number;
|
|
30
|
+
readonly rowByteLength: number;
|
|
31
|
+
readonly valueOffsets?: Int32Array;
|
|
32
|
+
readonly nullBitmap?: Uint8Array;
|
|
33
|
+
|
|
34
|
+
constructor(props: CPUDataProps<T>) {
|
|
35
|
+
const info = getGPUVectorFormatInfo(props.format);
|
|
36
|
+
const view = ArrayBuffer.isView(props.buffer) ? props.buffer : undefined;
|
|
37
|
+
this.buffer = view ? view.buffer : (props.buffer as ArrayBuffer);
|
|
38
|
+
this.format = props.format;
|
|
39
|
+
this.length = props.length;
|
|
40
|
+
this.valueLength = props.valueLength ?? props.length * (info.listSize ?? 1);
|
|
41
|
+
const offset = props.byteOffset ?? 0;
|
|
42
|
+
this.byteOffset = (view?.byteOffset ?? 0) + offset;
|
|
43
|
+
this.rowByteLength = props.rowByteLength ?? info.byteLength;
|
|
44
|
+
this.byteStride = props.byteStride ?? this.rowByteLength;
|
|
45
|
+
this.valueOffsets = props.valueOffsets;
|
|
46
|
+
this.nullBitmap = props.nullBitmap;
|
|
47
|
+
const variable = info.vertexList || info.valueList;
|
|
48
|
+
const count = variable ? this.valueLength : this.length;
|
|
49
|
+
// Layouts must describe complete rows within the supplied view, including empty ranges.
|
|
50
|
+
assert(
|
|
51
|
+
[this.length, this.valueLength, offset, this.rowByteLength, this.byteStride].every(
|
|
52
|
+
value => Number.isSafeInteger(value) && value >= 0
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
assert(this.rowByteLength >= info.byteLength && this.byteStride >= this.rowByteLength);
|
|
56
|
+
assert(variable || this.valueLength === this.length * (info.listSize ?? 1));
|
|
57
|
+
assert(
|
|
58
|
+
offset + (count ? (count - 1) * this.byteStride + this.rowByteLength : 0) <=
|
|
59
|
+
props.buffer.byteLength
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|