@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
package/dist/dist.dev.js
CHANGED
|
@@ -56,6 +56,7 @@ var __exports__ = (() => {
|
|
|
56
56
|
CompiledGPUGraph: () => CompiledGPUGraph,
|
|
57
57
|
DynamicBuffer: () => DynamicBuffer,
|
|
58
58
|
DynamicTexture: () => DynamicTexture,
|
|
59
|
+
GPUCPUOperation: () => GPUCPUOperation,
|
|
59
60
|
GPUCommandGraph: () => GPUCommandGraph,
|
|
60
61
|
GPUCommandGraphAutotuner: () => GPUCommandGraphAutotuner,
|
|
61
62
|
GPUCommandGraphEncoding: () => GPUCommandGraphEncoding,
|
|
@@ -71,6 +72,7 @@ var __exports__ = (() => {
|
|
|
71
72
|
GPUGraphTexture: () => GPUGraphTexture,
|
|
72
73
|
GPUGraphTextureView: () => GPUGraphTextureView,
|
|
73
74
|
GPUGraphVector: () => GPUGraphVector,
|
|
75
|
+
GPUShaderPassOperation: () => GPUShaderPassOperation,
|
|
74
76
|
GPUUploadOperation: () => GPUUploadOperation,
|
|
75
77
|
GraphBufferHandle: () => GraphBufferHandle,
|
|
76
78
|
GraphDataView: () => GraphDataView,
|
|
@@ -150,7 +152,7 @@ var __exports__ = (() => {
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
// src/gpu-core/gpu-command-graph.ts
|
|
153
|
-
var
|
|
155
|
+
var import_core9 = __toESM(require_core(), 1);
|
|
154
156
|
|
|
155
157
|
// ../../node_modules/probe.gl/dist/env/lib/globals.js
|
|
156
158
|
var window_ = globalThis;
|
|
@@ -1192,7 +1194,19 @@ var __exports__ = (() => {
|
|
|
1192
1194
|
}
|
|
1193
1195
|
|
|
1194
1196
|
// ../core/src/shadertypes/data-types/decode-data-types.ts
|
|
1197
|
+
var dataTypeInfoCache = /* @__PURE__ */ new Map();
|
|
1195
1198
|
function getDataTypeInfo(type) {
|
|
1199
|
+
const cached = dataTypeInfoCache.get(type);
|
|
1200
|
+
if (cached) {
|
|
1201
|
+
return cached;
|
|
1202
|
+
}
|
|
1203
|
+
const decoded = Object.freeze(decodeDataTypeInfo(type));
|
|
1204
|
+
if (Object.hasOwn(NORMALIZED_TYPE_MAP, type)) {
|
|
1205
|
+
dataTypeInfoCache.set(type, decoded);
|
|
1206
|
+
}
|
|
1207
|
+
return decoded;
|
|
1208
|
+
}
|
|
1209
|
+
function decodeDataTypeInfo(type) {
|
|
1196
1210
|
const normalized = type.includes("norm");
|
|
1197
1211
|
const integer = !normalized && !type.startsWith("float");
|
|
1198
1212
|
const signed = type.startsWith("s");
|
|
@@ -1533,40 +1547,33 @@ var __exports__ = (() => {
|
|
|
1533
1547
|
return this.isCompressed(format) && !format.endsWith("-webgl") ? WEBGPU_CREATE_FILTER2 : 0;
|
|
1534
1548
|
}
|
|
1535
1549
|
/** Computes the memory layout for a texture, in particular including row byte alignment */
|
|
1536
|
-
computeMemoryLayout(opts) {
|
|
1537
|
-
return computeTextureMemoryLayout(opts);
|
|
1550
|
+
computeMemoryLayout(opts, result) {
|
|
1551
|
+
return computeTextureMemoryLayout(opts, result);
|
|
1538
1552
|
}
|
|
1539
1553
|
};
|
|
1540
1554
|
var textureFormatDecoder = new TextureFormatDecoder();
|
|
1541
|
-
function computeTextureMemoryLayout({
|
|
1542
|
-
format,
|
|
1543
|
-
width,
|
|
1544
|
-
height,
|
|
1545
|
-
depth,
|
|
1546
|
-
byteAlignment
|
|
1547
|
-
}) {
|
|
1555
|
+
function computeTextureMemoryLayout({ format, width, height, depth, byteAlignment }, result = {}) {
|
|
1548
1556
|
const formatInfo = textureFormatDecoder.getInfo(format);
|
|
1557
|
+
const { bytesPerPixel, blockHeight = 1, compressed = false } = formatInfo;
|
|
1558
|
+
const bytesPerRow = getTextureBytesPerRow(formatInfo, width, byteAlignment);
|
|
1559
|
+
const rowsPerImage = compressed ? Math.ceil(height / blockHeight) : height;
|
|
1560
|
+
result.bytesPerPixel = bytesPerPixel;
|
|
1561
|
+
result.bytesPerRow = bytesPerRow;
|
|
1562
|
+
result.rowsPerImage = rowsPerImage;
|
|
1563
|
+
result.depthOrArrayLayers = depth;
|
|
1564
|
+
result.bytesPerImage = bytesPerRow * rowsPerImage;
|
|
1565
|
+
result.byteLength = result.bytesPerImage * depth;
|
|
1566
|
+
return result;
|
|
1567
|
+
}
|
|
1568
|
+
function getTextureBytesPerRow(formatInfo, width, byteAlignment) {
|
|
1549
1569
|
const {
|
|
1550
1570
|
bytesPerPixel,
|
|
1551
1571
|
bytesPerBlock = bytesPerPixel,
|
|
1552
1572
|
blockWidth = 1,
|
|
1553
|
-
blockHeight = 1,
|
|
1554
1573
|
compressed = false
|
|
1555
1574
|
} = formatInfo;
|
|
1556
1575
|
const blockColumns = compressed ? Math.ceil(width / blockWidth) : width;
|
|
1557
|
-
|
|
1558
|
-
const unpaddedBytesPerRow = blockColumns * bytesPerBlock;
|
|
1559
|
-
const bytesPerRow = Math.ceil(unpaddedBytesPerRow / byteAlignment) * byteAlignment;
|
|
1560
|
-
const rowsPerImage = blockRows;
|
|
1561
|
-
const byteLength = bytesPerRow * rowsPerImage * depth;
|
|
1562
|
-
return {
|
|
1563
|
-
bytesPerPixel,
|
|
1564
|
-
bytesPerRow,
|
|
1565
|
-
rowsPerImage,
|
|
1566
|
-
depthOrArrayLayers: depth,
|
|
1567
|
-
bytesPerImage: bytesPerRow * rowsPerImage,
|
|
1568
|
-
byteLength
|
|
1569
|
-
};
|
|
1576
|
+
return Math.ceil(blockColumns * bytesPerBlock / byteAlignment) * byteAlignment;
|
|
1570
1577
|
}
|
|
1571
1578
|
function getTextureFormatCapabilities(format) {
|
|
1572
1579
|
const info = getTextureFormatDefinition(format);
|
|
@@ -1588,7 +1595,18 @@ var __exports__ = (() => {
|
|
|
1588
1595
|
formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
|
|
1589
1596
|
return formatCapabilities;
|
|
1590
1597
|
}
|
|
1598
|
+
var textureFormatInfoCache = /* @__PURE__ */ new Map();
|
|
1591
1599
|
function getTextureFormatInfo(format) {
|
|
1600
|
+
let formatInfo = textureFormatInfoCache.get(format);
|
|
1601
|
+
if (!formatInfo) {
|
|
1602
|
+
const decoded = decodeTextureFormatInfo(format);
|
|
1603
|
+
decoded.bitsPerChannel = Object.freeze([...decoded.bitsPerChannel]);
|
|
1604
|
+
formatInfo = Object.freeze(decoded);
|
|
1605
|
+
textureFormatInfoCache.set(format, formatInfo);
|
|
1606
|
+
}
|
|
1607
|
+
return formatInfo;
|
|
1608
|
+
}
|
|
1609
|
+
function decodeTextureFormatInfo(format) {
|
|
1592
1610
|
let formatInfo = getTextureFormatInfoUsingTable(format);
|
|
1593
1611
|
if (textureFormatDecoder.isCompressed(format)) {
|
|
1594
1612
|
formatInfo.channels = "rgb";
|
|
@@ -1757,6 +1775,8 @@ var __exports__ = (() => {
|
|
|
1757
1775
|
};
|
|
1758
1776
|
|
|
1759
1777
|
// ../core/src/api/adapter/resources/texture.ts
|
|
1778
|
+
var textureLayoutScratchPool = [];
|
|
1779
|
+
var emptyTextureReadOptions = Object.freeze({});
|
|
1760
1780
|
var BASE_DIMENSIONS = {
|
|
1761
1781
|
"1d": "1d",
|
|
1762
1782
|
"2d": "2d",
|
|
@@ -1875,17 +1895,24 @@ var __exports__ = (() => {
|
|
|
1875
1895
|
* Calculates the memory layout of the texture, required when reading and writing data.
|
|
1876
1896
|
* @return the backend-aligned linear layout, in particular bytesPerRow which includes any required padding for buffer copy/read paths
|
|
1877
1897
|
*/
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
const
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1898
|
+
/** The optional result is caller-owned; internal scratch never escapes this call. */
|
|
1899
|
+
computeMemoryLayout(options_ = emptyTextureReadOptions, result) {
|
|
1900
|
+
const scratch = textureLayoutScratchPool.pop() || {
|
|
1901
|
+
readOptions: {},
|
|
1902
|
+
layoutOptions: {}
|
|
1903
|
+
};
|
|
1904
|
+
try {
|
|
1905
|
+
const options = this._normalizeTextureReadOptions(options_, scratch.readOptions);
|
|
1906
|
+
const layoutOptions = scratch.layoutOptions;
|
|
1907
|
+
layoutOptions.format = this.format;
|
|
1908
|
+
layoutOptions.width = options.width;
|
|
1909
|
+
layoutOptions.height = options.height;
|
|
1910
|
+
layoutOptions.depth = options.depthOrArrayLayers;
|
|
1911
|
+
layoutOptions.byteAlignment = this.byteAlignment;
|
|
1912
|
+
return textureFormatDecoder.computeMemoryLayout(layoutOptions, result);
|
|
1913
|
+
} finally {
|
|
1914
|
+
textureLayoutScratchPool.push(scratch);
|
|
1915
|
+
}
|
|
1889
1916
|
}
|
|
1890
1917
|
/**
|
|
1891
1918
|
* Read the contents of a texture into a GPU Buffer.
|
|
@@ -1994,59 +2021,57 @@ var __exports__ = (() => {
|
|
|
1994
2021
|
});
|
|
1995
2022
|
}
|
|
1996
2023
|
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
const
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2024
|
+
/** The optional result is caller-owned scratch storage; every result field is overwritten. */
|
|
2025
|
+
_normalizeCopyImageDataOptions(options_, result = {}) {
|
|
2026
|
+
const { data, depth, depthOrArrayLayers } = options_;
|
|
2027
|
+
this._normalizeTextureWriteOptions(options_, result);
|
|
2028
|
+
if (depthOrArrayLayers === void 0 && depth !== void 0) {
|
|
2029
|
+
const mipDepth = this.dimension === "3d" ? Math.max(1, this.depth >> result.mipLevel) : this.depth;
|
|
2030
|
+
result.depthOrArrayLayers = Math.min(depth, mipDepth - result.z);
|
|
2031
|
+
}
|
|
2032
|
+
result.data = data;
|
|
2033
|
+
result.depth = result.depthOrArrayLayers;
|
|
2034
|
+
return result;
|
|
2004
2035
|
}
|
|
2005
|
-
_normalizeCopyExternalImageOptions(options_) {
|
|
2006
|
-
const
|
|
2007
|
-
const mipLevel = optionsWithoutUndefined.mipLevel ?? 0;
|
|
2008
|
-
const mipLevelSize = this._getMipLevelSize(mipLevel);
|
|
2036
|
+
_normalizeCopyExternalImageOptions(options_, result = {}) {
|
|
2037
|
+
const { width, height } = options_;
|
|
2009
2038
|
const size = this.device.getExternalImageSize(options_.image);
|
|
2010
|
-
const options =
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
options.
|
|
2039
|
+
const options = _Texture._normalizeOptions(
|
|
2040
|
+
options_,
|
|
2041
|
+
_Texture.defaultCopyExternalImageOptions,
|
|
2042
|
+
result
|
|
2043
|
+
);
|
|
2044
|
+
const mipWidth = Math.max(1, this.width >> options.mipLevel);
|
|
2045
|
+
const mipHeight = this.baseDimension === "1d" ? 1 : Math.max(1, this.height >> options.mipLevel);
|
|
2046
|
+
const mipDepth = this.dimension === "3d" ? Math.max(1, this.depth >> options.mipLevel) : this.depth;
|
|
2047
|
+
options.width = Math.min(width ?? size.width, mipWidth - options.x);
|
|
2048
|
+
options.height = Math.min(height ?? size.height, mipHeight - options.y);
|
|
2049
|
+
options.depth = Math.min(options.depth, mipDepth - options.z);
|
|
2019
2050
|
return options;
|
|
2020
2051
|
}
|
|
2021
|
-
_normalizeCopyElementImageOptions(options_) {
|
|
2022
|
-
const
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
options.width = Math.min(options.width,
|
|
2031
|
-
options.height = Math.min(options.height,
|
|
2032
|
-
options.depth = Math.min(options.depth,
|
|
2052
|
+
_normalizeCopyElementImageOptions(options_, result = {}) {
|
|
2053
|
+
const options = _Texture._normalizeOptions(
|
|
2054
|
+
options_,
|
|
2055
|
+
_Texture.defaultCopyElementImageOptions,
|
|
2056
|
+
result
|
|
2057
|
+
);
|
|
2058
|
+
const mipWidth = Math.max(1, this.width >> options.mipLevel);
|
|
2059
|
+
const mipHeight = this.baseDimension === "1d" ? 1 : Math.max(1, this.height >> options.mipLevel);
|
|
2060
|
+
const mipDepth = this.dimension === "3d" ? Math.max(1, this.depth >> options.mipLevel) : this.depth;
|
|
2061
|
+
options.width = Math.min(options.width ?? mipWidth, mipWidth - options.x);
|
|
2062
|
+
options.height = Math.min(options.height ?? mipHeight, mipHeight - options.y);
|
|
2063
|
+
options.depth = Math.min(options.depth, mipDepth - options.z);
|
|
2033
2064
|
return options;
|
|
2034
2065
|
}
|
|
2035
|
-
_normalizeTextureReadOptions(options_) {
|
|
2036
|
-
const
|
|
2037
|
-
const
|
|
2038
|
-
const
|
|
2039
|
-
const
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
options.width = Math.min(options.width, mipLevelSize.width - options.x);
|
|
2045
|
-
options.height = Math.min(options.height, mipLevelSize.height - options.y);
|
|
2046
|
-
options.depthOrArrayLayers = Math.min(
|
|
2047
|
-
options.depthOrArrayLayers,
|
|
2048
|
-
mipLevelSize.depthOrArrayLayers - options.z
|
|
2049
|
-
);
|
|
2066
|
+
_normalizeTextureReadOptions(options_, result = {}) {
|
|
2067
|
+
const { depthOrArrayLayers } = options_;
|
|
2068
|
+
const options = _Texture._normalizeOptions(options_, _Texture.defaultTextureReadOptions, result);
|
|
2069
|
+
const mipWidth = Math.max(1, this.width >> options.mipLevel);
|
|
2070
|
+
const mipHeight = this.baseDimension === "1d" ? 1 : Math.max(1, this.height >> options.mipLevel);
|
|
2071
|
+
const mipDepth = this.dimension === "3d" ? Math.max(1, this.depth >> options.mipLevel) : this.depth;
|
|
2072
|
+
options.width = Math.min(options.width ?? mipWidth, mipWidth - options.x);
|
|
2073
|
+
options.height = Math.min(options.height ?? mipHeight, mipHeight - options.y);
|
|
2074
|
+
options.depthOrArrayLayers = Math.min(depthOrArrayLayers ?? mipDepth, mipDepth - options.z);
|
|
2050
2075
|
return options;
|
|
2051
2076
|
}
|
|
2052
2077
|
/**
|
|
@@ -2101,31 +2126,15 @@ var __exports__ = (() => {
|
|
|
2101
2126
|
throw new Error(`${this} color readback does not support format ${this.format}`);
|
|
2102
2127
|
}
|
|
2103
2128
|
}
|
|
2104
|
-
_normalizeTextureWriteOptions(options_) {
|
|
2105
|
-
const
|
|
2106
|
-
|
|
2107
|
-
const
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
options.width = Math.min(options.width, mipLevelSize.width - options.x);
|
|
2114
|
-
options.height = Math.min(options.height, mipLevelSize.height - options.y);
|
|
2115
|
-
options.depthOrArrayLayers = Math.min(
|
|
2116
|
-
options.depthOrArrayLayers,
|
|
2117
|
-
mipLevelSize.depthOrArrayLayers - options.z
|
|
2118
|
-
);
|
|
2119
|
-
const layout = textureFormatDecoder.computeMemoryLayout({
|
|
2120
|
-
format: this.format,
|
|
2121
|
-
width: options.width,
|
|
2122
|
-
height: options.height,
|
|
2123
|
-
depth: options.depthOrArrayLayers,
|
|
2124
|
-
byteAlignment: this.byteAlignment
|
|
2125
|
-
});
|
|
2126
|
-
const minimumBytesPerRow = layout.bytesPerPixel * options.width;
|
|
2127
|
-
options.bytesPerRow = optionsWithoutUndefined.bytesPerRow ?? layout.bytesPerRow;
|
|
2128
|
-
options.rowsPerImage = optionsWithoutUndefined.rowsPerImage ?? options.height;
|
|
2129
|
+
_normalizeTextureWriteOptions(options_, result = {}) {
|
|
2130
|
+
const { byteOffset = 0, bytesPerRow, rowsPerImage } = options_;
|
|
2131
|
+
this._normalizeTextureReadOptions(options_, result);
|
|
2132
|
+
const options = result;
|
|
2133
|
+
options.byteOffset = byteOffset;
|
|
2134
|
+
const formatInfo = this.device.getTextureFormatInfo(this.format);
|
|
2135
|
+
const minimumBytesPerRow = formatInfo.bytesPerPixel * options.width;
|
|
2136
|
+
options.bytesPerRow = bytesPerRow ?? getTextureBytesPerRow(formatInfo, options.width, this.byteAlignment);
|
|
2137
|
+
options.rowsPerImage = rowsPerImage ?? options.height;
|
|
2129
2138
|
if (options.bytesPerRow < minimumBytesPerRow) {
|
|
2130
2139
|
throw new Error(
|
|
2131
2140
|
`bytesPerRow (${options.bytesPerRow}) must be at least ${minimumBytesPerRow} for ${this.format}`
|
|
@@ -2136,7 +2145,7 @@ var __exports__ = (() => {
|
|
|
2136
2145
|
`rowsPerImage (${options.rowsPerImage}) must be at least ${options.height} for ${this.format}`
|
|
2137
2146
|
);
|
|
2138
2147
|
}
|
|
2139
|
-
const bytesPerPixel =
|
|
2148
|
+
const { bytesPerPixel } = formatInfo;
|
|
2140
2149
|
if (bytesPerPixel && options.bytesPerRow % bytesPerPixel !== 0) {
|
|
2141
2150
|
throw new Error(
|
|
2142
2151
|
`bytesPerRow (${options.bytesPerRow}) must be a multiple of bytesPerPixel (${bytesPerPixel}) for ${this.format}`
|
|
@@ -2164,10 +2173,12 @@ var __exports__ = (() => {
|
|
|
2164
2173
|
}
|
|
2165
2174
|
return allocatedByteLength * this.samples;
|
|
2166
2175
|
}
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2176
|
+
/** Fill every declared field, resetting stale scratch values without allocating entries or spreads. */
|
|
2177
|
+
static _normalizeOptions(options, defaults, result) {
|
|
2178
|
+
for (const key in defaults) {
|
|
2179
|
+
result[key] = options[key] === void 0 ? defaults[key] : options[key];
|
|
2180
|
+
}
|
|
2181
|
+
return result;
|
|
2171
2182
|
}
|
|
2172
2183
|
static defaultProps = {
|
|
2173
2184
|
...Resource.defaultProps,
|
|
@@ -2244,19 +2255,6 @@ var __exports__ = (() => {
|
|
|
2244
2255
|
mipLevel: 0,
|
|
2245
2256
|
aspect: "all"
|
|
2246
2257
|
};
|
|
2247
|
-
static defaultTextureWriteOptions = {
|
|
2248
|
-
byteOffset: 0,
|
|
2249
|
-
bytesPerRow: void 0,
|
|
2250
|
-
rowsPerImage: void 0,
|
|
2251
|
-
x: 0,
|
|
2252
|
-
y: 0,
|
|
2253
|
-
z: 0,
|
|
2254
|
-
width: void 0,
|
|
2255
|
-
height: void 0,
|
|
2256
|
-
depthOrArrayLayers: 1,
|
|
2257
|
-
mipLevel: 0,
|
|
2258
|
-
aspect: "all"
|
|
2259
|
-
};
|
|
2260
2258
|
};
|
|
2261
2259
|
|
|
2262
2260
|
// ../core/src/dynamic/dynamic-buffer/dynamic-buffer.ts
|
|
@@ -3934,7 +3932,66 @@ var __exports__ = (() => {
|
|
|
3934
3932
|
}
|
|
3935
3933
|
|
|
3936
3934
|
// src/gpu-data/index.ts
|
|
3935
|
+
var import_core7 = __toESM(require_core(), 1);
|
|
3936
|
+
|
|
3937
|
+
// src/gpu-data/cpu-data.ts
|
|
3937
3938
|
var import_core5 = __toESM(require_core(), 1);
|
|
3939
|
+
var CPUData = class {
|
|
3940
|
+
buffer;
|
|
3941
|
+
format;
|
|
3942
|
+
length;
|
|
3943
|
+
valueLength;
|
|
3944
|
+
/** Absolute offset into buffer. */
|
|
3945
|
+
byteOffset;
|
|
3946
|
+
byteStride;
|
|
3947
|
+
rowByteLength;
|
|
3948
|
+
valueOffsets;
|
|
3949
|
+
nullBitmap;
|
|
3950
|
+
constructor(props) {
|
|
3951
|
+
const info = getGPUVectorFormatInfo(props.format);
|
|
3952
|
+
const view = ArrayBuffer.isView(props.buffer) ? props.buffer : void 0;
|
|
3953
|
+
this.buffer = view ? view.buffer : props.buffer;
|
|
3954
|
+
this.format = props.format;
|
|
3955
|
+
this.length = props.length;
|
|
3956
|
+
this.valueLength = props.valueLength ?? props.length * (info.listSize ?? 1);
|
|
3957
|
+
const offset = props.byteOffset ?? 0;
|
|
3958
|
+
this.byteOffset = (view?.byteOffset ?? 0) + offset;
|
|
3959
|
+
this.rowByteLength = props.rowByteLength ?? info.byteLength;
|
|
3960
|
+
this.byteStride = props.byteStride ?? this.rowByteLength;
|
|
3961
|
+
this.valueOffsets = props.valueOffsets;
|
|
3962
|
+
this.nullBitmap = props.nullBitmap;
|
|
3963
|
+
const variable = info.vertexList || info.valueList;
|
|
3964
|
+
const count = variable ? this.valueLength : this.length;
|
|
3965
|
+
(0, import_core5.assert)(
|
|
3966
|
+
[this.length, this.valueLength, offset, this.rowByteLength, this.byteStride].every(
|
|
3967
|
+
(value) => Number.isSafeInteger(value) && value >= 0
|
|
3968
|
+
)
|
|
3969
|
+
);
|
|
3970
|
+
(0, import_core5.assert)(this.rowByteLength >= info.byteLength && this.byteStride >= this.rowByteLength);
|
|
3971
|
+
(0, import_core5.assert)(variable || this.valueLength === this.length * (info.listSize ?? 1));
|
|
3972
|
+
(0, import_core5.assert)(
|
|
3973
|
+
offset + (count ? (count - 1) * this.byteStride + this.rowByteLength : 0) <= props.buffer.byteLength
|
|
3974
|
+
);
|
|
3975
|
+
}
|
|
3976
|
+
};
|
|
3977
|
+
|
|
3978
|
+
// src/gpu-data/cpu-vector.ts
|
|
3979
|
+
var import_core6 = __toESM(require_core(), 1);
|
|
3980
|
+
var CPUVector = class {
|
|
3981
|
+
name;
|
|
3982
|
+
format;
|
|
3983
|
+
data;
|
|
3984
|
+
length;
|
|
3985
|
+
valueLength;
|
|
3986
|
+
constructor(props) {
|
|
3987
|
+
(0, import_core6.assert)(props.data.every((chunk) => chunk.format === props.format));
|
|
3988
|
+
this.name = props.name ?? "";
|
|
3989
|
+
this.format = props.format;
|
|
3990
|
+
this.data = Object.freeze([...props.data]);
|
|
3991
|
+
this.length = this.data.reduce((total, chunk) => total + chunk.length, 0);
|
|
3992
|
+
this.valueLength = this.data.reduce((total, chunk) => total + chunk.valueLength, 0);
|
|
3993
|
+
}
|
|
3994
|
+
};
|
|
3938
3995
|
|
|
3939
3996
|
// src/gpu-core/gpu-planning-heap.ts
|
|
3940
3997
|
var GPUPlanningHeap = class {
|
|
@@ -3977,7 +4034,7 @@ var __exports__ = (() => {
|
|
|
3977
4034
|
};
|
|
3978
4035
|
|
|
3979
4036
|
// src/gpu-core/gpu-command-graph-compiler.ts
|
|
3980
|
-
var
|
|
4037
|
+
var import_core8 = __toESM(require_core(), 1);
|
|
3981
4038
|
function compileGPUCommandGraph(props) {
|
|
3982
4039
|
const nodeOrder = getNodeOrder(props.nodes);
|
|
3983
4040
|
const bufferPlan = getBufferTransientAllocationPlan(nodeOrder, props.buffers.values());
|
|
@@ -4056,12 +4113,12 @@ var __exports__ = (() => {
|
|
|
4056
4113
|
transientTextures.set(handle, allocation.texture);
|
|
4057
4114
|
}
|
|
4058
4115
|
}
|
|
4059
|
-
const asyncPipelineCompilation =
|
|
4116
|
+
const asyncPipelineCompilation = import_core8.PipelineFactory.beginAsyncCompilation(props.device);
|
|
4060
4117
|
const nodeCompilationPromises = nodeOrder.map(async (node) => ({
|
|
4061
4118
|
node,
|
|
4062
4119
|
executable: node.compileAsync ? await node.compileAsync({ device: props.device }) : node.compile({ device: props.device })
|
|
4063
4120
|
}));
|
|
4064
|
-
|
|
4121
|
+
import_core8.PipelineFactory.endAsyncCompilation(props.device, asyncPipelineCompilation);
|
|
4065
4122
|
const [results, pipelineResults] = await Promise.all([
|
|
4066
4123
|
Promise.allSettled(nodeCompilationPromises),
|
|
4067
4124
|
Promise.allSettled(asyncPipelineCompilation)
|
|
@@ -4496,7 +4553,7 @@ var __exports__ = (() => {
|
|
|
4496
4553
|
);
|
|
4497
4554
|
const available = /* @__PURE__ */ new Map();
|
|
4498
4555
|
const getAvailable = (usage) => {
|
|
4499
|
-
const key = usage & (
|
|
4556
|
+
const key = usage & (import_core8.Buffer.MAP_READ | import_core8.Buffer.MAP_WRITE);
|
|
4500
4557
|
let pool = available.get(key);
|
|
4501
4558
|
if (!pool) {
|
|
4502
4559
|
pool = new GPUPlanningHeap(
|
|
@@ -4602,7 +4659,7 @@ var __exports__ = (() => {
|
|
|
4602
4659
|
for (let mipLevel = 0; mipLevel < texture.mipLevels; mipLevel++) {
|
|
4603
4660
|
byteLength = addSafeByteLengths(
|
|
4604
4661
|
byteLength,
|
|
4605
|
-
|
|
4662
|
+
import_core8.textureFormatDecoder.computeMemoryLayout({
|
|
4606
4663
|
format: texture.format,
|
|
4607
4664
|
width: Math.max(1, texture.width >> mipLevel),
|
|
4608
4665
|
height: texture.dimension === "1d" ? 1 : Math.max(1, texture.height >> mipLevel),
|
|
@@ -5127,8 +5184,8 @@ var __exports__ = (() => {
|
|
|
5127
5184
|
};
|
|
5128
5185
|
}
|
|
5129
5186
|
};
|
|
5130
|
-
var
|
|
5131
|
-
/**
|
|
5187
|
+
var GPUCommandGraphBuilder = class {
|
|
5188
|
+
/** Device that owns compilation and transient resources. */
|
|
5132
5189
|
device;
|
|
5133
5190
|
/** Identifier used as a prefix for graph-owned GPU resources. */
|
|
5134
5191
|
id;
|
|
@@ -5145,14 +5202,10 @@ var __exports__ = (() => {
|
|
|
5145
5202
|
/**
|
|
5146
5203
|
* Creates a mutable graph definition.
|
|
5147
5204
|
*
|
|
5148
|
-
* @param device
|
|
5205
|
+
* @param device Device used to compile and execute the graph.
|
|
5149
5206
|
* @param props Optional graph identity and generic adaptive-kernel selector.
|
|
5150
|
-
* @throws If `device` is not a WebGPU device.
|
|
5151
5207
|
*/
|
|
5152
5208
|
constructor(device, props = {}) {
|
|
5153
|
-
if (device.type !== "webgpu") {
|
|
5154
|
-
throw new Error("GPUCommandGraph requires a WebGPU device");
|
|
5155
|
-
}
|
|
5156
5209
|
assertDeviceAvailable(device, "construction");
|
|
5157
5210
|
this.device = device;
|
|
5158
5211
|
this.id = props.id ?? "gpu-command-graph";
|
|
@@ -5197,6 +5250,15 @@ var __exports__ = (() => {
|
|
|
5197
5250
|
validateGraphBufferDescriptor(descriptor, this.device);
|
|
5198
5251
|
return this.addBuffer(new GraphBufferHandle(this, descriptor, true));
|
|
5199
5252
|
}
|
|
5253
|
+
/** Choose a compiler-owned resource name without treating diagnostic labels as unique. @internal */
|
|
5254
|
+
getUniqueResourceId(label) {
|
|
5255
|
+
let id = label;
|
|
5256
|
+
let suffix = 1;
|
|
5257
|
+
while (this.buffers.has(id) || this.textures.has(id) || this.externalTextures.has(id)) {
|
|
5258
|
+
id = `${label}-${suffix++}`;
|
|
5259
|
+
}
|
|
5260
|
+
return id;
|
|
5261
|
+
}
|
|
5200
5262
|
/**
|
|
5201
5263
|
* Creates one typed range over a graph buffer.
|
|
5202
5264
|
*
|
|
@@ -5435,6 +5497,9 @@ var __exports__ = (() => {
|
|
|
5435
5497
|
);
|
|
5436
5498
|
}
|
|
5437
5499
|
addNode(node) {
|
|
5500
|
+
if (this.device.type !== "webgpu" && node.type !== "render") {
|
|
5501
|
+
throw new Error("WebGL graphs support render passes only");
|
|
5502
|
+
}
|
|
5438
5503
|
this.assertMutable();
|
|
5439
5504
|
if (!node.id) {
|
|
5440
5505
|
throw new Error("GPUCommandGraph node id is required");
|
|
@@ -5520,6 +5585,9 @@ var __exports__ = (() => {
|
|
|
5520
5585
|
this.assertTexture(texture);
|
|
5521
5586
|
validateTextureUseAgainstDescriptor(texture, resource.usage);
|
|
5522
5587
|
validateTextureViewForUsage(resource.texture, resource.usage);
|
|
5588
|
+
if (this.device.type === "webgl" && resource.usage === "sampled" && resource.texture instanceof GraphTextureView && !isDefaultGraphTextureView(resource.texture)) {
|
|
5589
|
+
throw new Error("WebGL sampled textures require a full-resource view");
|
|
5590
|
+
}
|
|
5523
5591
|
} else {
|
|
5524
5592
|
this.assertExternalTexture(resource.externalTexture);
|
|
5525
5593
|
if (resource.usage !== "sampled") {
|
|
@@ -6071,7 +6139,7 @@ var __exports__ = (() => {
|
|
|
6071
6139
|
if ("frameScoped" in handle && handle.frameScoped)
|
|
6072
6140
|
throw new Error("Frame textures expire after presentation.");
|
|
6073
6141
|
const resource = "buffer" in use ? getBuffer(use.buffer) : getTexture(use.texture);
|
|
6074
|
-
const aliases = resource instanceof
|
|
6142
|
+
const aliases = resource instanceof import_core9.Buffer ? this.transientBuffers : this.transientTextures;
|
|
6075
6143
|
if (handle.transient && [...aliases].some(
|
|
6076
6144
|
([candidate, allocation]) => candidate !== handle && allocation === resource
|
|
6077
6145
|
))
|
|
@@ -6567,47 +6635,55 @@ var __exports__ = (() => {
|
|
|
6567
6635
|
case "storage-read":
|
|
6568
6636
|
case "storage-write":
|
|
6569
6637
|
case "storage-read-write":
|
|
6570
|
-
return
|
|
6638
|
+
return import_core9.Buffer.STORAGE;
|
|
6571
6639
|
case "uniform":
|
|
6572
|
-
return
|
|
6640
|
+
return import_core9.Buffer.UNIFORM;
|
|
6573
6641
|
case "copy-source":
|
|
6574
|
-
return
|
|
6642
|
+
return import_core9.Buffer.COPY_SRC;
|
|
6575
6643
|
case "copy-destination":
|
|
6576
|
-
return
|
|
6644
|
+
return import_core9.Buffer.COPY_DST;
|
|
6577
6645
|
case "indirect":
|
|
6578
|
-
return
|
|
6646
|
+
return import_core9.Buffer.INDIRECT;
|
|
6579
6647
|
case "vertex":
|
|
6580
|
-
return
|
|
6648
|
+
return import_core9.Buffer.VERTEX;
|
|
6581
6649
|
case "index":
|
|
6582
|
-
return
|
|
6650
|
+
return import_core9.Buffer.INDEX;
|
|
6583
6651
|
}
|
|
6584
6652
|
}
|
|
6585
6653
|
function getRequiredTextureUsage(usage) {
|
|
6586
6654
|
switch (usage) {
|
|
6587
6655
|
case "sampled":
|
|
6588
|
-
return
|
|
6656
|
+
return import_core9.Texture.SAMPLE;
|
|
6589
6657
|
case "storage-read":
|
|
6590
6658
|
case "storage-write":
|
|
6591
6659
|
case "storage-read-write":
|
|
6592
|
-
return
|
|
6660
|
+
return import_core9.Texture.STORAGE;
|
|
6593
6661
|
case "render-attachment":
|
|
6594
|
-
return
|
|
6662
|
+
return import_core9.Texture.RENDER;
|
|
6595
6663
|
case "copy-source":
|
|
6596
|
-
return
|
|
6664
|
+
return import_core9.Texture.COPY_SRC;
|
|
6597
6665
|
case "copy-destination":
|
|
6598
|
-
return
|
|
6666
|
+
return import_core9.Texture.COPY_DST;
|
|
6599
6667
|
}
|
|
6600
6668
|
}
|
|
6601
6669
|
function isDefaultGraphTextureView(view) {
|
|
6602
6670
|
const texture = view.texture;
|
|
6603
6671
|
return view.dimension === texture.dimension && view.aspect === "all" && view.baseMipLevel === 0 && view.mipLevelCount === texture.mipLevels && view.baseArrayLayer === 0 && view.arrayLayerCount === (texture.dimension === "3d" ? 1 : texture.depth);
|
|
6604
6672
|
}
|
|
6673
|
+
var GPUCommandGraph = class extends GPUCommandGraphBuilder {
|
|
6674
|
+
constructor(device, props = {}) {
|
|
6675
|
+
if (device.type !== "webgpu") {
|
|
6676
|
+
throw new Error("GPUCommandGraph requires a WebGPU device");
|
|
6677
|
+
}
|
|
6678
|
+
super(device, props);
|
|
6679
|
+
}
|
|
6680
|
+
};
|
|
6605
6681
|
|
|
6606
6682
|
// src/gpu-core/compiled-gpu-graph.ts
|
|
6607
|
-
var
|
|
6683
|
+
var import_core25 = __toESM(require_core(), 1);
|
|
6608
6684
|
|
|
6609
6685
|
// src/gpu-core/gpu-texture-plan.ts
|
|
6610
|
-
var
|
|
6686
|
+
var import_core10 = __toESM(require_core(), 1);
|
|
6611
6687
|
|
|
6612
6688
|
// src/gpu-core/gpu-graph-value.ts
|
|
6613
6689
|
var gpuGraph = {
|
|
@@ -6754,19 +6830,19 @@ var __exports__ = (() => {
|
|
|
6754
6830
|
|
|
6755
6831
|
// src/gpu-core/gpu-texture-plan.ts
|
|
6756
6832
|
function getTextureBindingInfo(binding) {
|
|
6757
|
-
const texture = binding instanceof
|
|
6758
|
-
const props = binding instanceof
|
|
6833
|
+
const texture = binding instanceof import_core10.TextureView ? binding.texture : binding;
|
|
6834
|
+
const props = binding instanceof import_core10.TextureView ? binding.props : {};
|
|
6759
6835
|
const baseMipLevel = props.baseMipLevel ?? 0;
|
|
6760
6836
|
const baseArrayLayer = props.baseArrayLayer ?? 0;
|
|
6761
6837
|
const dimension = props.dimension ?? texture.dimension;
|
|
6762
6838
|
const mipLevels = props.mipLevelCount ?? texture.mipLevels - baseMipLevel;
|
|
6763
6839
|
const depth = dimension === "3d" ? Math.max(1, texture.depth >> baseMipLevel) : props.arrayLayerCount ?? (dimension === "cube" ? 6 : dimension === "2d" ? 1 : texture.depth - baseArrayLayer);
|
|
6764
|
-
(0,
|
|
6765
|
-
(0,
|
|
6766
|
-
(0,
|
|
6840
|
+
(0, import_core10.assert)((props.format ?? texture.format) === texture.format && (props.aspect ?? "all") === "all");
|
|
6841
|
+
(0, import_core10.assert)(!binding.destroyed && !texture.destroyed);
|
|
6842
|
+
(0, import_core10.assert)(
|
|
6767
6843
|
Number.isInteger(baseMipLevel) && baseMipLevel >= 0 && Number.isInteger(mipLevels) && mipLevels > 0 && baseMipLevel + mipLevels <= texture.mipLevels
|
|
6768
6844
|
);
|
|
6769
|
-
(0,
|
|
6845
|
+
(0, import_core10.assert)(
|
|
6770
6846
|
Number.isInteger(baseArrayLayer) && baseArrayLayer >= 0 && Number.isInteger(depth) && depth > 0 && (dimension === "3d" ? baseArrayLayer === 0 : baseArrayLayer + depth <= texture.depth)
|
|
6771
6847
|
);
|
|
6772
6848
|
return {
|
|
@@ -6789,7 +6865,7 @@ var __exports__ = (() => {
|
|
|
6789
6865
|
const dimension = props.dimension ?? info.dimension;
|
|
6790
6866
|
const mipLevelCount = props.mipLevelCount ?? info.mipLevels - baseMipLevel;
|
|
6791
6867
|
const arrayLayerCount = props.arrayLayerCount ?? (dimension === "cube" ? 6 : dimension === "2d" || dimension === "3d" ? 1 : info.depth - baseArrayLayer);
|
|
6792
|
-
(0,
|
|
6868
|
+
(0, import_core10.assert)(
|
|
6793
6869
|
baseMipLevel >= 0 && baseMipLevel + mipLevelCount <= info.mipLevels && baseArrayLayer >= 0 && baseArrayLayer + arrayLayerCount <= info.depth
|
|
6794
6870
|
);
|
|
6795
6871
|
return {
|
|
@@ -6802,13 +6878,13 @@ var __exports__ = (() => {
|
|
|
6802
6878
|
};
|
|
6803
6879
|
}
|
|
6804
6880
|
var TEXTURE_USAGE = {
|
|
6805
|
-
sampled:
|
|
6806
|
-
"storage-read":
|
|
6807
|
-
"storage-write":
|
|
6808
|
-
"storage-read-write":
|
|
6809
|
-
"render-attachment":
|
|
6810
|
-
"copy-source":
|
|
6811
|
-
"copy-destination":
|
|
6881
|
+
sampled: import_core10.Texture.SAMPLE,
|
|
6882
|
+
"storage-read": import_core10.Texture.STORAGE,
|
|
6883
|
+
"storage-write": import_core10.Texture.STORAGE,
|
|
6884
|
+
"storage-read-write": import_core10.Texture.STORAGE,
|
|
6885
|
+
"render-attachment": import_core10.Texture.RENDER,
|
|
6886
|
+
"copy-source": import_core10.Texture.COPY_SRC,
|
|
6887
|
+
"copy-destination": import_core10.Texture.COPY_DST
|
|
6812
6888
|
};
|
|
6813
6889
|
var GPUTextureInvocation = class {
|
|
6814
6890
|
values = /* @__PURE__ */ new Map();
|
|
@@ -6820,9 +6896,9 @@ var __exports__ = (() => {
|
|
|
6820
6896
|
for (const use of contract.values) {
|
|
6821
6897
|
const name = getGPUOperationValueName(use.value);
|
|
6822
6898
|
if (!declarations.some((value) => value.id === name)) continue;
|
|
6823
|
-
(0,
|
|
6899
|
+
(0, import_core10.assert)(use.textureUsage);
|
|
6824
6900
|
const usage = use.textureUsage;
|
|
6825
|
-
(0,
|
|
6901
|
+
(0, import_core10.assert)(
|
|
6826
6902
|
use.access === "read" && ["sampled", "storage-read", "copy-source"].includes(usage) || use.access === "write" && ["storage-write", "render-attachment", "copy-destination"].includes(usage) || use.access === "read-write" && ["storage-read-write", "render-attachment"].includes(usage)
|
|
6827
6903
|
);
|
|
6828
6904
|
usages.set(name, (usages.get(name) ?? 0) | TEXTURE_USAGE[usage]);
|
|
@@ -6846,7 +6922,7 @@ var __exports__ = (() => {
|
|
|
6846
6922
|
if (extent && "like" in extent && !template) continue;
|
|
6847
6923
|
const source = template ? getTextureBindingInfo(template) : void 0;
|
|
6848
6924
|
const scale = extent && "like" in extent ? extent.scale ?? [1, 1] : [1, 1];
|
|
6849
|
-
(0,
|
|
6925
|
+
(0, import_core10.assert)(scale.every((value) => Number.isFinite(value) && value > 0));
|
|
6850
6926
|
const width = source ? Math.max(1, Math.round(source.width * scale[0])) : extent && "width" in extent ? extent.width : void 0;
|
|
6851
6927
|
const height = source ? Math.max(1, Math.round(source.height * scale[1])) : extent && "height" in extent ? extent.height : void 0;
|
|
6852
6928
|
const dimension = descriptor.dimension ?? source?.dimension ?? "2d";
|
|
@@ -6854,13 +6930,13 @@ var __exports__ = (() => {
|
|
|
6854
6930
|
const mipLevels = descriptor.mipLevels ?? source?.mipLevels ?? 1;
|
|
6855
6931
|
const samples = descriptor.samples ?? source?.samples ?? 1;
|
|
6856
6932
|
const usage = (usages.get(declaration.id) ?? 0) | declaration.usage;
|
|
6857
|
-
(0,
|
|
6933
|
+
(0, import_core10.assert)(samples === 1 || !(usage & (import_core10.Texture.COPY_SRC | import_core10.Texture.COPY_DST)));
|
|
6858
6934
|
let binding = targets[declaration.id] ?? bindings[declaration.id];
|
|
6859
6935
|
if (binding === void 0) {
|
|
6860
|
-
(0,
|
|
6936
|
+
(0, import_core10.assert)(
|
|
6861
6937
|
declaration.role !== "input" && !declaration.external && width !== void 0 && height !== void 0 && usage !== 0
|
|
6862
6938
|
);
|
|
6863
|
-
(0,
|
|
6939
|
+
(0, import_core10.assert)(
|
|
6864
6940
|
Number.isSafeInteger(width) && width > 0 && Number.isSafeInteger(height) && height > 0
|
|
6865
6941
|
);
|
|
6866
6942
|
const texture = device.createTexture({
|
|
@@ -6872,27 +6948,27 @@ var __exports__ = (() => {
|
|
|
6872
6948
|
depth: depth ?? 1,
|
|
6873
6949
|
mipLevels,
|
|
6874
6950
|
samples,
|
|
6875
|
-
usage: usage | (samples === 1 ?
|
|
6951
|
+
usage: usage | (samples === 1 ? import_core10.Texture.COPY_SRC : 0) | import_core10.Texture.SAMPLE
|
|
6876
6952
|
});
|
|
6877
6953
|
this.owned.add(texture);
|
|
6878
6954
|
binding = texture;
|
|
6879
6955
|
}
|
|
6880
|
-
(0,
|
|
6956
|
+
(0, import_core10.assert)(binding instanceof import_core10.Texture || binding instanceof import_core10.TextureView);
|
|
6881
6957
|
const info = getTextureBindingInfo(binding);
|
|
6882
|
-
(0,
|
|
6883
|
-
(0,
|
|
6958
|
+
(0, import_core10.assert)(info.samples === 1 || !(usage & (import_core10.Texture.COPY_SRC | import_core10.Texture.COPY_DST)));
|
|
6959
|
+
(0, import_core10.assert)(
|
|
6884
6960
|
info.texture.device === device && info.format === descriptor.format && info.dimension === dimension && (width === void 0 || info.width === width) && (height === void 0 || info.height === height) && (depth === void 0 || info.depth === depth) && (descriptor.mipLevels === void 0 && declaration.role === "input" || info.mipLevels === mipLevels) && (descriptor.samples === void 0 && declaration.role === "input" || info.samples === samples) && (info.texture.props.usage & usage) === usage
|
|
6885
6961
|
);
|
|
6886
6962
|
this.values.set(declaration.id, binding);
|
|
6887
6963
|
pending.delete(declaration);
|
|
6888
6964
|
progress = true;
|
|
6889
6965
|
}
|
|
6890
|
-
(0,
|
|
6966
|
+
(0, import_core10.assert)(progress);
|
|
6891
6967
|
}
|
|
6892
6968
|
for (const name of writable) {
|
|
6893
6969
|
const texture = getTextureBindingInfo(this.values.get(name)).texture;
|
|
6894
6970
|
for (const [otherName, value] of this.values)
|
|
6895
|
-
(0,
|
|
6971
|
+
(0, import_core10.assert)(name === otherName || getTextureBindingInfo(value).texture !== texture);
|
|
6896
6972
|
}
|
|
6897
6973
|
} catch (error) {
|
|
6898
6974
|
this.destroy();
|
|
@@ -6902,7 +6978,7 @@ var __exports__ = (() => {
|
|
|
6902
6978
|
finish(outputs) {
|
|
6903
6979
|
for (const name of outputs) {
|
|
6904
6980
|
const value = this.values.get(name);
|
|
6905
|
-
if (value instanceof
|
|
6981
|
+
if (value instanceof import_core10.Texture) this.owned.delete(value);
|
|
6906
6982
|
}
|
|
6907
6983
|
this.destroy();
|
|
6908
6984
|
}
|
|
@@ -6913,7 +6989,7 @@ var __exports__ = (() => {
|
|
|
6913
6989
|
};
|
|
6914
6990
|
|
|
6915
6991
|
// src/gpu-core/gpu-texture-copy.ts
|
|
6916
|
-
var
|
|
6992
|
+
var import_core11 = __toESM(require_core(), 1);
|
|
6917
6993
|
function encodeTextureCopy(encoder, input, output) {
|
|
6918
6994
|
const source = getTextureBindingInfo(input);
|
|
6919
6995
|
const destination = getTextureBindingInfo(output);
|
|
@@ -6935,13 +7011,13 @@ var __exports__ = (() => {
|
|
|
6935
7011
|
function validateTextureCopy(input, output) {
|
|
6936
7012
|
const source = getTextureBindingInfo(input);
|
|
6937
7013
|
const destination = getTextureBindingInfo(output);
|
|
6938
|
-
(0,
|
|
7014
|
+
(0, import_core11.assert)(
|
|
6939
7015
|
source.texture !== destination.texture && source.samples === 1 && destination.samples === 1 && source.format === destination.format && source.width === destination.width && source.height === destination.height && source.depth === destination.depth && source.mipLevels === destination.mipLevels && source.dimension === destination.dimension
|
|
6940
7016
|
);
|
|
6941
7017
|
}
|
|
6942
7018
|
|
|
6943
7019
|
// src/gpu-core/gpu-transfer-lowering.ts
|
|
6944
|
-
var
|
|
7020
|
+
var import_core12 = __toESM(require_core(), 1);
|
|
6945
7021
|
function lowerGPUUpload(operation, context) {
|
|
6946
7022
|
const output = context.resolveVector(operation.output);
|
|
6947
7023
|
const chunks = operation.getData();
|
|
@@ -6952,7 +7028,7 @@ var __exports__ = (() => {
|
|
|
6952
7028
|
id: `${operation.id}-${index}`,
|
|
6953
7029
|
resources: [{ buffer: destination, usage: "copy-destination" }],
|
|
6954
7030
|
compile: ({ device }) => {
|
|
6955
|
-
const staging = device.createBuffer({ data, usage:
|
|
7031
|
+
const staging = device.createBuffer({ data, usage: import_core12.Buffer.COPY_SRC });
|
|
6956
7032
|
return {
|
|
6957
7033
|
encode: ({ commandEncoder, getBuffer }) => {
|
|
6958
7034
|
const packed = destination.byteStride === destination.rowByteLength;
|
|
@@ -6975,10 +7051,10 @@ var __exports__ = (() => {
|
|
|
6975
7051
|
function lowerGPUCopy(operation, context) {
|
|
6976
7052
|
const input = context.resolveVector(operation.input);
|
|
6977
7053
|
const output = context.resolveVector(operation.output);
|
|
6978
|
-
(0,
|
|
7054
|
+
(0, import_core12.assert)(input.format === output.format && input.data.length === output.data.length);
|
|
6979
7055
|
for (const [index, source] of input.data.entries()) {
|
|
6980
7056
|
const destination = output.data[index];
|
|
6981
|
-
(0,
|
|
7057
|
+
(0, import_core12.assert)(source.length === destination.length);
|
|
6982
7058
|
if (!source.length) continue;
|
|
6983
7059
|
context.graph.addCopyPass({
|
|
6984
7060
|
id: `${operation.id}-${index}`,
|
|
@@ -7019,7 +7095,7 @@ var __exports__ = (() => {
|
|
|
7019
7095
|
}
|
|
7020
7096
|
|
|
7021
7097
|
// src/gpu-core/gpu-transfer-operation.ts
|
|
7022
|
-
var
|
|
7098
|
+
var import_core13 = __toESM(require_core(), 1);
|
|
7023
7099
|
var GPUUploadOperation = class {
|
|
7024
7100
|
type = "vector-upload";
|
|
7025
7101
|
id;
|
|
@@ -7034,7 +7110,7 @@ var __exports__ = (() => {
|
|
|
7034
7110
|
const info = getGPUVectorFormatInfo(props.format);
|
|
7035
7111
|
const chunks = Array.isArray(props.data) ? props.data : [props.data];
|
|
7036
7112
|
const ValueType = info.signedDataType === "float32" ? Float32Array : info.signedDataType === "uint32" ? Uint32Array : Int32Array;
|
|
7037
|
-
(0,
|
|
7113
|
+
(0, import_core13.assert)(
|
|
7038
7114
|
chunks.every((chunk) => chunk instanceof ValueType && chunk.byteLength % info.byteLength === 0)
|
|
7039
7115
|
);
|
|
7040
7116
|
this.chunks = chunks.map(
|
|
@@ -7073,7 +7149,7 @@ var __exports__ = (() => {
|
|
|
7073
7149
|
const input = getValue(this.input);
|
|
7074
7150
|
if (input.type === "texture")
|
|
7075
7151
|
return { [this.output]: gpuGraph.texture({ ...input, extent: { like: this.input } }) };
|
|
7076
|
-
(0,
|
|
7152
|
+
(0, import_core13.assert)(input.type === "vector");
|
|
7077
7153
|
return {
|
|
7078
7154
|
[this.output]: gpuGraph.vector(input.format, {
|
|
7079
7155
|
length: input.length,
|
|
@@ -7118,17 +7194,17 @@ var __exports__ = (() => {
|
|
|
7118
7194
|
}
|
|
7119
7195
|
|
|
7120
7196
|
// src/execution/compute/kernel.ts
|
|
7121
|
-
var
|
|
7197
|
+
var import_core14 = __toESM(require_core(), 1);
|
|
7122
7198
|
var Kernel = class _Kernel {
|
|
7123
7199
|
/** Creates a kernel while allowing the backend to compile its pipeline asynchronously. */
|
|
7124
7200
|
static async createAsync(device, props) {
|
|
7125
|
-
const ownsCompilation = !
|
|
7126
|
-
const asyncCompilation = ownsCompilation ?
|
|
7201
|
+
const ownsCompilation = !import_core14.PipelineFactory.getAsyncCompilation(device);
|
|
7202
|
+
const asyncCompilation = ownsCompilation ? import_core14.PipelineFactory.beginAsyncCompilation(device) : import_core14.PipelineFactory.getAsyncCompilation(device);
|
|
7127
7203
|
let kernel;
|
|
7128
7204
|
try {
|
|
7129
7205
|
kernel = new _Kernel(device, props);
|
|
7130
7206
|
} finally {
|
|
7131
|
-
if (ownsCompilation)
|
|
7207
|
+
if (ownsCompilation) import_core14.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
7132
7208
|
}
|
|
7133
7209
|
try {
|
|
7134
7210
|
if (ownsCompilation) {
|
|
@@ -7159,8 +7235,8 @@ var __exports__ = (() => {
|
|
|
7159
7235
|
this.device = device;
|
|
7160
7236
|
this.id = props.id ?? "kernel";
|
|
7161
7237
|
this.source = source;
|
|
7162
|
-
this.pipelineFactory = pipelineFactory ??
|
|
7163
|
-
this.shaderFactory = shaderFactory ??
|
|
7238
|
+
this.pipelineFactory = pipelineFactory ?? import_core14.PipelineFactory.getDefaultPipelineFactory(device);
|
|
7239
|
+
this.shaderFactory = shaderFactory ?? import_core14.ShaderFactory.getDefaultShaderFactory(device);
|
|
7164
7240
|
this.shader = this.shaderFactory.createShader({
|
|
7165
7241
|
id: `${this.id}-compute`,
|
|
7166
7242
|
stage: "compute",
|
|
@@ -7168,7 +7244,7 @@ var __exports__ = (() => {
|
|
|
7168
7244
|
debugShaders
|
|
7169
7245
|
});
|
|
7170
7246
|
const computePipelineProps = { ...pipelineProps, shader: this.shader };
|
|
7171
|
-
const asyncCompilation =
|
|
7247
|
+
const asyncCompilation = import_core14.PipelineFactory.getAsyncCompilation(device);
|
|
7172
7248
|
if (asyncCompilation) {
|
|
7173
7249
|
const pipelineInitialization = this.pipelineFactory.createComputePipelineAsync(computePipelineProps);
|
|
7174
7250
|
this._pipelineInitialization = pipelineInitialization;
|
|
@@ -7241,7 +7317,7 @@ var __exports__ = (() => {
|
|
|
7241
7317
|
}
|
|
7242
7318
|
|
|
7243
7319
|
// src/gpu-core/graph-data-view-utils.ts
|
|
7244
|
-
var
|
|
7320
|
+
var import_core15 = __toESM(require_core(), 1);
|
|
7245
7321
|
var UINT32_BYTE_LENGTH2 = Uint32Array.BYTES_PER_ELEMENT;
|
|
7246
7322
|
var STORAGE_BINDING_ALIGNMENT = 256;
|
|
7247
7323
|
function validatePackedView(view, formats, name) {
|
|
@@ -7279,11 +7355,11 @@ var __exports__ = (() => {
|
|
|
7279
7355
|
}
|
|
7280
7356
|
return view.byteOffset % STORAGE_BINDING_ALIGNMENT / UINT32_BYTE_LENGTH2;
|
|
7281
7357
|
}
|
|
7282
|
-
function createTransientView(graph, id, format, length, usage =
|
|
7358
|
+
function createTransientView(graph, id, format, length, usage = import_core15.Buffer.STORAGE) {
|
|
7283
7359
|
if (!Number.isSafeInteger(length) || length < 0) {
|
|
7284
7360
|
throw new Error("Transient GraphDataView length must be a non-negative safe integer");
|
|
7285
7361
|
}
|
|
7286
|
-
if ((usage &
|
|
7362
|
+
if ((usage & import_core15.Buffer.STORAGE) === 0) {
|
|
7287
7363
|
throw new Error("Transient GraphDataView usage must include Buffer.STORAGE");
|
|
7288
7364
|
}
|
|
7289
7365
|
if (isVertexListGPUVectorFormat(format) || isValueListGPUVectorFormat(format)) {
|
|
@@ -8417,7 +8493,7 @@ ${countBinding}
|
|
|
8417
8493
|
}
|
|
8418
8494
|
|
|
8419
8495
|
// src/gpu-core/gpu-graph-compiler.ts
|
|
8420
|
-
var
|
|
8496
|
+
var import_core18 = __toESM(require_core(), 1);
|
|
8421
8497
|
|
|
8422
8498
|
// src/gpu-core/gpu-command-graph-lowering-scope.ts
|
|
8423
8499
|
var GPUCommandLoweringGraph = class extends GPUCommandGraph {
|
|
@@ -8480,10 +8556,10 @@ ${countBinding}
|
|
|
8480
8556
|
};
|
|
8481
8557
|
|
|
8482
8558
|
// src/gpu-core/gpu-scalar-dispatch-gate.ts
|
|
8483
|
-
var
|
|
8559
|
+
var import_core17 = __toESM(require_core(), 1);
|
|
8484
8560
|
|
|
8485
8561
|
// src/gpu-core/gpu-value-arena.ts
|
|
8486
|
-
var
|
|
8562
|
+
var import_core16 = __toESM(require_core(), 1);
|
|
8487
8563
|
var DEFAULT_GPU_VALUE_ARENA_BYTE_LENGTH = 16 * 1024;
|
|
8488
8564
|
var GRAPH_VALUE_ARENAS = /* @__PURE__ */ new WeakMap();
|
|
8489
8565
|
function getGPUValueArena(graph) {
|
|
@@ -8513,7 +8589,7 @@ ${countBinding}
|
|
|
8513
8589
|
this.buffer = graph.createTransientBuffer({
|
|
8514
8590
|
id: `${this.id}-buffer`,
|
|
8515
8591
|
byteLength: capacityByteLength,
|
|
8516
|
-
usage:
|
|
8592
|
+
usage: import_core16.Buffer.STORAGE | import_core16.Buffer.COPY_SRC | import_core16.Buffer.COPY_DST
|
|
8517
8593
|
});
|
|
8518
8594
|
}
|
|
8519
8595
|
allocate(id, format) {
|
|
@@ -8597,6 +8673,16 @@ ${countBinding}
|
|
|
8597
8673
|
const arena = getGPUValueArena(graph);
|
|
8598
8674
|
return new GPUScalar(arena, arena.allocate(id, format));
|
|
8599
8675
|
}
|
|
8676
|
+
function getGPUScalarWGSLType(format) {
|
|
8677
|
+
switch (format) {
|
|
8678
|
+
case "float32":
|
|
8679
|
+
return "f32";
|
|
8680
|
+
case "uint32":
|
|
8681
|
+
return "u32";
|
|
8682
|
+
case "sint32":
|
|
8683
|
+
return "i32";
|
|
8684
|
+
}
|
|
8685
|
+
}
|
|
8600
8686
|
function getGPUScalarWGSLLoad(scalar, arenaExpression = "gpuValues") {
|
|
8601
8687
|
const word = `${arenaExpression}[${scalar.wordOffset}u]`;
|
|
8602
8688
|
switch (scalar.format) {
|
|
@@ -8638,7 +8724,7 @@ ${countBinding}
|
|
|
8638
8724
|
this.dispatchBuffer = graph.createTransientBuffer({
|
|
8639
8725
|
id: `${this.id}-dispatch`,
|
|
8640
8726
|
byteLength: 12,
|
|
8641
|
-
usage:
|
|
8727
|
+
usage: import_core17.Buffer.STORAGE | import_core17.Buffer.INDIRECT | import_core17.Buffer.COPY_SRC
|
|
8642
8728
|
});
|
|
8643
8729
|
}
|
|
8644
8730
|
getUpdateCommandNodes(graph, id = `${this.id}-update`) {
|
|
@@ -10343,10 +10429,10 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
10343
10429
|
if (operation instanceof GPUCompositeOperation)
|
|
10344
10430
|
operation.operations.forEach(collectTransferUsages);
|
|
10345
10431
|
else if (operation instanceof GPUUploadOperation)
|
|
10346
|
-
addTransferUsage(operation.output,
|
|
10432
|
+
addTransferUsage(operation.output, import_core18.Buffer.COPY_DST);
|
|
10347
10433
|
else if (operation instanceof GPUCopyOperation) {
|
|
10348
|
-
addTransferUsage(operation.input,
|
|
10349
|
-
addTransferUsage(operation.output,
|
|
10434
|
+
addTransferUsage(operation.input, import_core18.Buffer.COPY_SRC);
|
|
10435
|
+
addTransferUsage(operation.output, import_core18.Buffer.COPY_DST);
|
|
10350
10436
|
}
|
|
10351
10437
|
};
|
|
10352
10438
|
program.operations.forEach(collectTransferUsages);
|
|
@@ -10370,7 +10456,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
10370
10456
|
resources: [{ buffer: view, usage: "copy-destination" }],
|
|
10371
10457
|
compile: ({ device }) => {
|
|
10372
10458
|
const data = scalar.format === "float32" ? new Float32Array([value]) : scalar.format === "uint32" ? new Uint32Array([value]) : new Int32Array([value]);
|
|
10373
|
-
const buffer = device.createBuffer({ data, usage:
|
|
10459
|
+
const buffer = device.createBuffer({ data, usage: import_core18.Buffer.COPY_SRC });
|
|
10374
10460
|
return {
|
|
10375
10461
|
encode: ({ commandEncoder, getBuffer }) => commandEncoder.copyBufferToBuffer({
|
|
10376
10462
|
sourceBuffer: buffer,
|
|
@@ -10416,7 +10502,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
10416
10502
|
chunkLengths.length === 1 ? vector.id : `${vector.id}-chunk-${index}`,
|
|
10417
10503
|
vector.format,
|
|
10418
10504
|
length,
|
|
10419
|
-
vector.role === "value" ?
|
|
10505
|
+
vector.role === "value" ? import_core18.Buffer.STORAGE | import_core18.Buffer.VERTEX | import_core18.Buffer.COPY_SRC | import_core18.Buffer.COPY_DST : import_core18.Buffer.STORAGE | (transferUsages.get(vector.id) ?? 0)
|
|
10420
10506
|
)
|
|
10421
10507
|
);
|
|
10422
10508
|
const formatInfo = getGPUVectorFormatInfo(vector.format);
|
|
@@ -10437,12 +10523,12 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
10437
10523
|
const textures = /* @__PURE__ */ new Map();
|
|
10438
10524
|
const textureViews = /* @__PURE__ */ new Map();
|
|
10439
10525
|
for (const texture of program.textures) {
|
|
10440
|
-
(0,
|
|
10526
|
+
(0, import_core18.assert)(texture.width !== void 0 && texture.height !== void 0);
|
|
10441
10527
|
let binding = bindings.textures?.[texture.id];
|
|
10442
10528
|
let descriptor = { ...texture, width: texture.width, height: texture.height };
|
|
10443
|
-
if (binding instanceof
|
|
10529
|
+
if (binding instanceof import_core18.TextureView) {
|
|
10444
10530
|
const info = getTextureBindingInfo(binding);
|
|
10445
|
-
(0,
|
|
10531
|
+
(0, import_core18.assert)(
|
|
10446
10532
|
info.format === texture.format && info.width === texture.width && info.height === texture.height
|
|
10447
10533
|
);
|
|
10448
10534
|
textureViews.set(texture.id, binding);
|
|
@@ -10861,7 +10947,76 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
10861
10947
|
}
|
|
10862
10948
|
|
|
10863
10949
|
// src/gpu-core/gpu-expression-plan.ts
|
|
10864
|
-
var
|
|
10950
|
+
var import_core20 = __toESM(require_core(), 1);
|
|
10951
|
+
|
|
10952
|
+
// src/gpu-core/gpu-shader-pass-operation.ts
|
|
10953
|
+
var import_core19 = __toESM(require_core(), 1);
|
|
10954
|
+
var GPUShaderPassOperation = class {
|
|
10955
|
+
type = "shader-pass";
|
|
10956
|
+
id;
|
|
10957
|
+
fragmentSource;
|
|
10958
|
+
inputs;
|
|
10959
|
+
samplers;
|
|
10960
|
+
parameters;
|
|
10961
|
+
output;
|
|
10962
|
+
outputDescriptor;
|
|
10963
|
+
constructor(props) {
|
|
10964
|
+
this.id = props.id ?? `${props.output}-shader-pass`;
|
|
10965
|
+
this.fragmentSource = props.fragmentSource;
|
|
10966
|
+
this.inputs = Object.freeze({ ...props.inputs });
|
|
10967
|
+
this.parameters = Object.freeze({ ...props.parameters });
|
|
10968
|
+
this.samplers = Object.freeze(
|
|
10969
|
+
Object.fromEntries(
|
|
10970
|
+
Object.entries(props.samplers ?? {}).map(([name, sampler]) => [
|
|
10971
|
+
name,
|
|
10972
|
+
Object.freeze({ ...sampler })
|
|
10973
|
+
])
|
|
10974
|
+
)
|
|
10975
|
+
);
|
|
10976
|
+
this.output = props.output;
|
|
10977
|
+
const descriptor = props.outputDescriptor;
|
|
10978
|
+
(0, import_core19.assert)(
|
|
10979
|
+
descriptor.extent && (descriptor.dimension ?? "2d") === "2d" && (descriptor.mipLevels ?? 1) === 1 && (descriptor.samples ?? 1) === 1
|
|
10980
|
+
);
|
|
10981
|
+
this.outputDescriptor = gpuGraph.texture({
|
|
10982
|
+
...descriptor,
|
|
10983
|
+
dimension: "2d",
|
|
10984
|
+
mipLevels: 1,
|
|
10985
|
+
samples: 1
|
|
10986
|
+
});
|
|
10987
|
+
const bindings = [...Object.keys(this.inputs), ...Object.keys(this.samplers)];
|
|
10988
|
+
(0, import_core19.assert)(new Set(bindings).size === bindings.length);
|
|
10989
|
+
for (const name of [...bindings, ...Object.keys(this.parameters)])
|
|
10990
|
+
(0, import_core19.assert)(
|
|
10991
|
+
/^[A-Za-z][A-Za-z0-9_]*$/.test(name) && !["parameters", "shade", "vertexMain", "fragmentMain"].includes(name) && !name.startsWith("GraphShaderPass")
|
|
10992
|
+
);
|
|
10993
|
+
for (const sampler of Object.values(this.samplers))
|
|
10994
|
+
(0, import_core19.assert)((sampler.type ?? "color-sampler") === "color-sampler");
|
|
10995
|
+
}
|
|
10996
|
+
get contract() {
|
|
10997
|
+
return {
|
|
10998
|
+
values: [
|
|
10999
|
+
...Object.values(this.inputs).map((value) => ({
|
|
11000
|
+
value,
|
|
11001
|
+
access: "read",
|
|
11002
|
+
textureUsage: "sampled"
|
|
11003
|
+
})),
|
|
11004
|
+
...Object.values(this.parameters).map((value) => ({ value, access: "read" })),
|
|
11005
|
+
{ value: this.output, access: "write", textureUsage: "render-attachment" }
|
|
11006
|
+
],
|
|
11007
|
+
outputs: ({ getValue }) => {
|
|
11008
|
+
for (const name of Object.values(this.inputs)) {
|
|
11009
|
+
const input = getValue(name);
|
|
11010
|
+
(0, import_core19.assert)(
|
|
11011
|
+
input.type === "texture" && (input.dimension ?? "2d") === "2d" && (input.samples ?? 1) === 1
|
|
11012
|
+
);
|
|
11013
|
+
}
|
|
11014
|
+
for (const name of Object.values(this.parameters)) (0, import_core19.assert)(getValue(name).type === "scalar");
|
|
11015
|
+
return { [this.output]: this.outputDescriptor };
|
|
11016
|
+
}
|
|
11017
|
+
};
|
|
11018
|
+
}
|
|
11019
|
+
};
|
|
10865
11020
|
|
|
10866
11021
|
// ../../node_modules/@math.gl/core/dist/expressions/vendor/jsep/runtime.js
|
|
10867
11022
|
var Hooks = class {
|
|
@@ -12072,6 +12227,9 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12072
12227
|
operation.operations.forEach(flatten);
|
|
12073
12228
|
else {
|
|
12074
12229
|
if (operation instanceof GPUCompositeOperation) {
|
|
12230
|
+
const containsShaderPass = (child) => child instanceof GPUShaderPassOperation || child instanceof GPUCompositeOperation && child.operations.some(containsShaderPass);
|
|
12231
|
+
if (operation.operations.some(containsShaderPass))
|
|
12232
|
+
throw new Error("Shader-pass operations inside control flow are not supported");
|
|
12075
12233
|
const containsExpression = (child) => child instanceof GPUExpressionOperation || child instanceof GPUCompositeOperation && child.operations.some(containsExpression);
|
|
12076
12234
|
if (operation.operations.some(containsExpression))
|
|
12077
12235
|
throw new Error("Expression operations inside control flow are not supported");
|
|
@@ -12203,7 +12361,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12203
12361
|
const declarations = [...this.scalars, ...this.vectors, ...this.textures];
|
|
12204
12362
|
const explicit = declarations.some((value) => value.role === "input" || value.role === "state");
|
|
12205
12363
|
const grouped = explicit || Object.values(supplied).some(
|
|
12206
|
-
(value) => value !== void 0 && typeof value === "object" && !(value instanceof GPUVector) && !(value instanceof
|
|
12364
|
+
(value) => value !== void 0 && typeof value === "object" && !(value instanceof GPUVector) && !(value instanceof CPUVector) && !(value instanceof import_core20.Texture) && !(value instanceof import_core20.TextureView)
|
|
12207
12365
|
);
|
|
12208
12366
|
if (!grouped) {
|
|
12209
12367
|
for (const name of Object.keys(supplied))
|
|
@@ -12478,7 +12636,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12478
12636
|
const outputs = /* @__PURE__ */ Object.create(null);
|
|
12479
12637
|
for (const name of this.program.outputs) {
|
|
12480
12638
|
const value = this.textures?.values.get(name) ?? this.values.get(name);
|
|
12481
|
-
if (!(value instanceof GPUVector || value instanceof
|
|
12639
|
+
if (!(value instanceof GPUVector || value instanceof import_core20.Texture || value instanceof import_core20.TextureView))
|
|
12482
12640
|
throw new Error(`Output ${name} has no materialized resource`);
|
|
12483
12641
|
outputs[name] = value;
|
|
12484
12642
|
}
|
|
@@ -12506,7 +12664,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12506
12664
|
new GPUData({
|
|
12507
12665
|
buffer: device.createBuffer({
|
|
12508
12666
|
byteLength: Math.max(1, length) * getGPUExpressionRowInfo(format).components * 4,
|
|
12509
|
-
usage:
|
|
12667
|
+
usage: import_core20.Buffer.STORAGE | import_core20.Buffer.VERTEX | import_core20.Buffer.COPY_SRC | import_core20.Buffer.COPY_DST
|
|
12510
12668
|
}),
|
|
12511
12669
|
format,
|
|
12512
12670
|
length,
|
|
@@ -12533,7 +12691,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12533
12691
|
}
|
|
12534
12692
|
}
|
|
12535
12693
|
function validateWritableTarget(name, target, values) {
|
|
12536
|
-
const getBuffer = (chunk) => chunk.buffer instanceof
|
|
12694
|
+
const getBuffer = (chunk) => chunk.buffer instanceof import_core20.Buffer ? chunk.buffer : chunk.buffer.buffer;
|
|
12537
12695
|
const ranges = /* @__PURE__ */ new Map();
|
|
12538
12696
|
for (const chunk of target.data) {
|
|
12539
12697
|
if (chunk.length === 0) continue;
|
|
@@ -12557,7 +12715,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12557
12715
|
}
|
|
12558
12716
|
|
|
12559
12717
|
// src/gpu-core/gpu-expression-kernel.ts
|
|
12560
|
-
var
|
|
12718
|
+
var import_core21 = __toESM(require_core(), 1);
|
|
12561
12719
|
|
|
12562
12720
|
// src/gpu-core/gpu-expression-cast.ts
|
|
12563
12721
|
var GPU_EXPRESSION_SHADER_TYPES = { float32: "f32", sint32: "i32", uint32: "u32" };
|
|
@@ -12780,7 +12938,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12780
12938
|
getViewElementOffset(output),
|
|
12781
12939
|
...inputs.map(getViewElementOffset)
|
|
12782
12940
|
]);
|
|
12783
|
-
const metadataBuffer = device.createBuffer({ data, usage:
|
|
12941
|
+
const metadataBuffer = device.createBuffer({ data, usage: import_core21.Buffer.UNIFORM });
|
|
12784
12942
|
return {
|
|
12785
12943
|
encode: ({ computePass, getBuffer }) => {
|
|
12786
12944
|
const bindings = { metadata: metadataBuffer };
|
|
@@ -12812,97 +12970,861 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12812
12970
|
}
|
|
12813
12971
|
};
|
|
12814
12972
|
|
|
12815
|
-
// src/gpu-core/
|
|
12816
|
-
var
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
}
|
|
12827
|
-
]);
|
|
12973
|
+
// src/gpu-core/gpu-shader-pass-kernel.ts
|
|
12974
|
+
var import_core23 = __toESM(require_core(), 1);
|
|
12975
|
+
|
|
12976
|
+
// src/execution/compute/render-kernel.ts
|
|
12977
|
+
var import_core22 = __toESM(require_core(), 1);
|
|
12978
|
+
var RenderKernel = class _RenderKernel {
|
|
12979
|
+
/** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
|
|
12980
|
+
static async createAsync(device, props) {
|
|
12981
|
+
const ownsCompilation = !import_core22.PipelineFactory.getAsyncCompilation(device);
|
|
12982
|
+
const asyncCompilation = ownsCompilation ? import_core22.PipelineFactory.beginAsyncCompilation(device) : import_core22.PipelineFactory.getAsyncCompilation(device);
|
|
12983
|
+
let kernel;
|
|
12828
12984
|
try {
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
|
|
12832
|
-
this.destroy();
|
|
12833
|
-
throw error;
|
|
12985
|
+
kernel = new _RenderKernel(device, props);
|
|
12986
|
+
} finally {
|
|
12987
|
+
if (ownsCompilation) import_core22.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
12834
12988
|
}
|
|
12835
|
-
}
|
|
12836
|
-
device;
|
|
12837
|
-
program;
|
|
12838
|
-
compiler;
|
|
12839
|
-
kernels = /* @__PURE__ */ new Map();
|
|
12840
|
-
destroyed = false;
|
|
12841
|
-
async run(supplied, options = {}) {
|
|
12842
|
-
const execution = this.prepare(supplied, options);
|
|
12843
|
-
let encoder;
|
|
12844
12989
|
try {
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
|
|
12990
|
+
if (ownsCompilation) {
|
|
12991
|
+
await Promise.all(asyncCompilation);
|
|
12992
|
+
} else {
|
|
12993
|
+
await kernel._pipelineInitialization;
|
|
12994
|
+
}
|
|
12995
|
+
return kernel;
|
|
12849
12996
|
} catch (error) {
|
|
12850
|
-
|
|
12997
|
+
kernel.destroy();
|
|
12851
12998
|
throw error;
|
|
12852
|
-
} finally {
|
|
12853
|
-
execution.destroy();
|
|
12854
|
-
encoder?.destroy();
|
|
12855
12999
|
}
|
|
12856
13000
|
}
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
12884
|
-
|
|
12885
|
-
|
|
12886
|
-
|
|
12887
|
-
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12905
|
-
|
|
13001
|
+
device;
|
|
13002
|
+
id;
|
|
13003
|
+
vertexSource;
|
|
13004
|
+
fragmentSource;
|
|
13005
|
+
pipelineFactory;
|
|
13006
|
+
shaderFactory;
|
|
13007
|
+
vertexShader;
|
|
13008
|
+
fragmentShader;
|
|
13009
|
+
pipeline;
|
|
13010
|
+
_pipelineInitialization;
|
|
13011
|
+
_destroyed = false;
|
|
13012
|
+
drawDefaults;
|
|
13013
|
+
constructor(device, props) {
|
|
13014
|
+
if (device.type !== "webgpu" && device.type !== "webgl") {
|
|
13015
|
+
throw new Error("RenderKernel requires WebGL or WebGPU");
|
|
13016
|
+
}
|
|
13017
|
+
if (device.type === "webgl" && !props.fragmentSource) {
|
|
13018
|
+
throw new Error("WebGL RenderKernel requires a fragment shader");
|
|
13019
|
+
}
|
|
13020
|
+
const {
|
|
13021
|
+
vertexSource,
|
|
13022
|
+
fragmentSource,
|
|
13023
|
+
pipelineFactory,
|
|
13024
|
+
shaderFactory,
|
|
13025
|
+
debugShaders,
|
|
13026
|
+
...pipelineProps
|
|
13027
|
+
} = props;
|
|
13028
|
+
this.device = device;
|
|
13029
|
+
this.drawDefaults = {
|
|
13030
|
+
parameters: props.parameters ?? {},
|
|
13031
|
+
topology: props.topology ?? "triangle-list"
|
|
13032
|
+
};
|
|
13033
|
+
this.id = props.id ?? "render-kernel";
|
|
13034
|
+
this.vertexSource = vertexSource;
|
|
13035
|
+
this.fragmentSource = fragmentSource;
|
|
13036
|
+
this.pipelineFactory = pipelineFactory ?? import_core22.PipelineFactory.getDefaultPipelineFactory(device);
|
|
13037
|
+
this.shaderFactory = shaderFactory ?? import_core22.ShaderFactory.getDefaultShaderFactory(device);
|
|
13038
|
+
this.vertexShader = this.shaderFactory.createShader({
|
|
13039
|
+
id: `${this.id}-vertex`,
|
|
13040
|
+
stage: "vertex",
|
|
13041
|
+
source: this.vertexSource,
|
|
13042
|
+
debugShaders
|
|
13043
|
+
});
|
|
13044
|
+
this.fragmentShader = this.fragmentSource ? this.shaderFactory.createShader({
|
|
13045
|
+
id: `${this.id}-fragment`,
|
|
13046
|
+
stage: "fragment",
|
|
13047
|
+
source: this.fragmentSource,
|
|
13048
|
+
debugShaders
|
|
13049
|
+
}) : null;
|
|
13050
|
+
const renderPipelineProps = {
|
|
13051
|
+
...pipelineProps,
|
|
13052
|
+
vs: this.vertexShader,
|
|
13053
|
+
fs: this.fragmentShader
|
|
13054
|
+
};
|
|
13055
|
+
const asyncCompilation = import_core22.PipelineFactory.getAsyncCompilation(device);
|
|
13056
|
+
if (asyncCompilation) {
|
|
13057
|
+
const pipelineInitialization = this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
|
|
13058
|
+
this._pipelineInitialization = pipelineInitialization;
|
|
13059
|
+
asyncCompilation.push(
|
|
13060
|
+
pipelineInitialization.then((pipeline) => {
|
|
13061
|
+
this.pipeline = pipeline;
|
|
13062
|
+
return pipeline;
|
|
13063
|
+
})
|
|
13064
|
+
);
|
|
13065
|
+
} else {
|
|
13066
|
+
this.pipeline = this.pipelineFactory.createRenderPipeline(renderPipelineProps);
|
|
13067
|
+
}
|
|
13068
|
+
}
|
|
13069
|
+
/** Applies per-draw bindings/vertex state and records a direct draw. */
|
|
13070
|
+
draw(renderPass, options) {
|
|
13071
|
+
const { bindings = {}, vertexArray, ...drawOptions } = options;
|
|
13072
|
+
this._setPipeline(renderPass, bindings, vertexArray);
|
|
13073
|
+
return renderPass.draw(
|
|
13074
|
+
this.device.type === "webgl" ? {
|
|
13075
|
+
...this.drawDefaults,
|
|
13076
|
+
...drawOptions,
|
|
13077
|
+
isInstanced: drawOptions.isInstanced ?? drawOptions.instanceCount !== void 0
|
|
13078
|
+
} : drawOptions
|
|
13079
|
+
);
|
|
13080
|
+
}
|
|
13081
|
+
/** Applies per-draw state and records a non-indexed indirect draw. */
|
|
13082
|
+
drawIndirect(renderPass, options) {
|
|
13083
|
+
if (this.device.type !== "webgpu")
|
|
13084
|
+
throw new Error("Indirect drawing is only supported in WebGPU");
|
|
13085
|
+
const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
|
|
13086
|
+
this._setPipeline(renderPass, bindings, vertexArray);
|
|
13087
|
+
renderPass.drawIndirect(indirectBuffer, indirectOffset);
|
|
13088
|
+
}
|
|
13089
|
+
/** Applies per-draw state and records an indexed indirect draw. */
|
|
13090
|
+
drawIndexedIndirect(renderPass, options) {
|
|
13091
|
+
if (this.device.type !== "webgpu")
|
|
13092
|
+
throw new Error("Indirect drawing is only supported in WebGPU");
|
|
13093
|
+
const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
|
|
13094
|
+
this._setPipeline(renderPass, bindings, vertexArray);
|
|
13095
|
+
renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
|
|
13096
|
+
}
|
|
13097
|
+
destroy() {
|
|
13098
|
+
if (this._destroyed) return;
|
|
13099
|
+
if (this.pipeline) this.pipelineFactory.release(this.pipeline);
|
|
13100
|
+
this.shaderFactory.release(this.vertexShader);
|
|
13101
|
+
if (this.fragmentShader) this.shaderFactory.release(this.fragmentShader);
|
|
13102
|
+
this._destroyed = true;
|
|
13103
|
+
}
|
|
13104
|
+
_setPipeline(renderPass, bindings, vertexArray) {
|
|
13105
|
+
renderPass.setPipeline(this.pipeline);
|
|
13106
|
+
renderPass.setBindings(bindings);
|
|
13107
|
+
renderPass.setVertexArray(vertexArray);
|
|
13108
|
+
}
|
|
13109
|
+
};
|
|
13110
|
+
|
|
13111
|
+
// src/gpu-core/gpu-shader-pass-kernel.ts
|
|
13112
|
+
var VERTEX_SOURCE = `
|
|
13113
|
+
struct GraphShaderPassVertex {
|
|
13114
|
+
@builtin(position) position: vec4<f32>,
|
|
13115
|
+
@location(0) textureCoordinates: vec2<f32>
|
|
13116
|
+
};
|
|
13117
|
+
@vertex fn vertexMain(@builtin(vertex_index) index: u32) -> GraphShaderPassVertex {
|
|
13118
|
+
let position = vec2<f32>(f32((index << 1u) & 2u), f32(index & 2u));
|
|
13119
|
+
var result: GraphShaderPassVertex;
|
|
13120
|
+
result.position = vec4<f32>(position * 2.0 - 1.0, 0.0, 1.0);
|
|
13121
|
+
result.textureCoordinates = vec2<f32>(position.x, 1.0 - position.y);
|
|
13122
|
+
return result;
|
|
13123
|
+
}`;
|
|
13124
|
+
var GPUShaderPassKernel = class {
|
|
13125
|
+
constructor(device, operation, program) {
|
|
13126
|
+
this.device = device;
|
|
13127
|
+
this.operation = operation;
|
|
13128
|
+
(0, import_core23.assert)(device.type === "webgpu");
|
|
13129
|
+
this.parameterFormats = Object.values(operation.parameters).map((name) => {
|
|
13130
|
+
const scalar = program.scalars.find((value) => value.id === name);
|
|
13131
|
+
(0, import_core23.assert)(scalar);
|
|
13132
|
+
return scalar.format;
|
|
13133
|
+
});
|
|
13134
|
+
this.parameterByteLength = Math.ceil(this.parameterFormats.length / 4) * 16;
|
|
13135
|
+
for (const name of Object.values(operation.inputs)) {
|
|
13136
|
+
const input = program.textures.find((texture) => texture.id === name);
|
|
13137
|
+
const info = device.getTextureFormatInfo(input.format);
|
|
13138
|
+
(0, import_core23.assert)(
|
|
13139
|
+
!info.integer && info.attachment !== "depth" && info.attachment !== "depth-stencil" && device.getTextureFormatCapabilities(input.format).filter
|
|
13140
|
+
);
|
|
13141
|
+
}
|
|
13142
|
+
const outputInfo = device.getTextureFormatInfo(operation.outputDescriptor.format);
|
|
13143
|
+
(0, import_core23.assert)(
|
|
13144
|
+
!outputInfo.integer && device.getTextureFormatCapabilities(operation.outputDescriptor.format).render
|
|
13145
|
+
);
|
|
13146
|
+
const shaderBindings = [
|
|
13147
|
+
...Object.keys(operation.inputs).map((name, location) => ({
|
|
13148
|
+
name,
|
|
13149
|
+
location,
|
|
13150
|
+
group: 0,
|
|
13151
|
+
type: "texture",
|
|
13152
|
+
viewDimension: "2d",
|
|
13153
|
+
sampleType: "float"
|
|
13154
|
+
})),
|
|
13155
|
+
...Object.keys(operation.samplers).map((name, index) => ({
|
|
13156
|
+
name,
|
|
13157
|
+
location: Object.keys(operation.inputs).length + index,
|
|
13158
|
+
group: 0,
|
|
13159
|
+
type: "sampler"
|
|
13160
|
+
}))
|
|
13161
|
+
];
|
|
13162
|
+
let binding = 0;
|
|
13163
|
+
const declarations = [
|
|
13164
|
+
...Object.keys(operation.inputs).map(
|
|
13165
|
+
(name) => `@group(0) @binding(${binding++}) var ${name}: texture_2d<f32>;`
|
|
13166
|
+
),
|
|
13167
|
+
...Object.keys(operation.samplers).map(
|
|
13168
|
+
(name) => `@group(0) @binding(${binding++}) var ${name}: sampler;`
|
|
13169
|
+
)
|
|
13170
|
+
];
|
|
13171
|
+
if (this.parameterFormats.length) {
|
|
13172
|
+
shaderBindings.push({ name: "parameters", location: binding, group: 0, type: "uniform" });
|
|
13173
|
+
declarations.push(
|
|
13174
|
+
`struct GraphShaderPassParameters {${Object.keys(operation.parameters).map((name, index) => `${name}: ${getGPUScalarWGSLType(this.parameterFormats[index])}`).join(
|
|
13175
|
+
","
|
|
13176
|
+
)}};
|
|
13177
|
+
@group(0) @binding(${binding}) var<uniform> parameters: GraphShaderPassParameters;`
|
|
13178
|
+
);
|
|
13179
|
+
}
|
|
13180
|
+
try {
|
|
13181
|
+
this.kernel = new RenderKernel(device, {
|
|
13182
|
+
id: operation.id,
|
|
13183
|
+
vertexSource: VERTEX_SOURCE,
|
|
13184
|
+
fragmentSource: `${declarations.join("\n")}
|
|
13185
|
+
${operation.fragmentSource}
|
|
13186
|
+
|
|
13187
|
+
@fragment fn fragmentMain(@location(0) textureCoordinates: vec2<f32>) -> @location(0) vec4<f32> {
|
|
13188
|
+
return shade(textureCoordinates);
|
|
13189
|
+
}`,
|
|
13190
|
+
vertexEntryPoint: "vertexMain",
|
|
13191
|
+
fragmentEntryPoint: "fragmentMain",
|
|
13192
|
+
topology: "triangle-list",
|
|
13193
|
+
shaderLayout: { attributes: [], bindings: shaderBindings },
|
|
13194
|
+
colorAttachmentFormats: [operation.outputDescriptor.format],
|
|
13195
|
+
parameters: { depthWriteEnabled: false }
|
|
13196
|
+
});
|
|
13197
|
+
this.vertexArray = device.createVertexArray({
|
|
13198
|
+
shaderLayout: this.kernel.pipeline.shaderLayout,
|
|
13199
|
+
bufferLayout: []
|
|
13200
|
+
});
|
|
13201
|
+
for (const [name, props] of Object.entries(operation.samplers))
|
|
13202
|
+
this.samplers[name] = device.createSampler(props);
|
|
13203
|
+
} catch (error) {
|
|
13204
|
+
this.destroy();
|
|
13205
|
+
throw error;
|
|
13206
|
+
}
|
|
13207
|
+
}
|
|
13208
|
+
device;
|
|
13209
|
+
operation;
|
|
13210
|
+
kernel;
|
|
13211
|
+
vertexArray;
|
|
13212
|
+
samplers = /* @__PURE__ */ Object.create(null);
|
|
13213
|
+
parameterFormats;
|
|
13214
|
+
parameterByteLength;
|
|
13215
|
+
/** Validate selected view geometry before either executor records commands. */
|
|
13216
|
+
validateTextures(textures) {
|
|
13217
|
+
for (const name of [...Object.values(this.operation.inputs), this.operation.output]) {
|
|
13218
|
+
const binding = textures.get(name);
|
|
13219
|
+
(0, import_core23.assert)(binding);
|
|
13220
|
+
const info = getTextureBindingInfo(binding);
|
|
13221
|
+
(0, import_core23.assert)(
|
|
13222
|
+
info.texture.device === this.device && info.dimension === "2d" && info.depth === 1 && info.samples === 1
|
|
13223
|
+
);
|
|
13224
|
+
if (name === this.operation.output) (0, import_core23.assert)(info.mipLevels === 1);
|
|
13225
|
+
}
|
|
13226
|
+
}
|
|
13227
|
+
/** Full graph lowers to ordinary resource-tracked copy and render nodes. */
|
|
13228
|
+
lower(context) {
|
|
13229
|
+
const operation = this.operation;
|
|
13230
|
+
const inputs = Object.fromEntries(
|
|
13231
|
+
Object.entries(operation.inputs).map(([name, value]) => [
|
|
13232
|
+
name,
|
|
13233
|
+
context.resolveTextureView(value)
|
|
13234
|
+
])
|
|
13235
|
+
);
|
|
13236
|
+
const output = context.resolveTextureView(operation.output);
|
|
13237
|
+
const parameters = this.parameterFormats.length ? context.graph.createTransientBuffer({
|
|
13238
|
+
id: context.graph.getUniqueResourceId(`${operation.id}-parameters`),
|
|
13239
|
+
byteLength: this.parameterByteLength,
|
|
13240
|
+
usage: import_core23.Buffer.UNIFORM | import_core23.Buffer.COPY_DST
|
|
13241
|
+
}) : void 0;
|
|
13242
|
+
if (parameters) {
|
|
13243
|
+
const sources = Object.values(operation.parameters).map(
|
|
13244
|
+
(name) => context.resolveScalar(name).view
|
|
13245
|
+
);
|
|
13246
|
+
context.graph.addCopyPass({
|
|
13247
|
+
id: `${operation.id}-parameters`,
|
|
13248
|
+
resources: [
|
|
13249
|
+
...sources.map((buffer) => ({ buffer, usage: "copy-source" })),
|
|
13250
|
+
{ buffer: parameters, usage: "copy-destination" }
|
|
13251
|
+
],
|
|
13252
|
+
compile: () => ({
|
|
13253
|
+
encode: ({ commandEncoder, getBuffer }) => {
|
|
13254
|
+
sources.forEach(
|
|
13255
|
+
(source, index) => commandEncoder.copyBufferToBuffer({
|
|
13256
|
+
sourceBuffer: getBuffer(source),
|
|
13257
|
+
sourceOffset: source.byteOffset,
|
|
13258
|
+
destinationBuffer: getBuffer(parameters),
|
|
13259
|
+
destinationOffset: index * 4,
|
|
13260
|
+
size: 4
|
|
13261
|
+
})
|
|
13262
|
+
);
|
|
13263
|
+
}
|
|
13264
|
+
})
|
|
13265
|
+
});
|
|
13266
|
+
}
|
|
13267
|
+
context.graph.addRenderPass({
|
|
13268
|
+
id: operation.id,
|
|
13269
|
+
resources: [
|
|
13270
|
+
...Object.values(inputs).map((texture) => ({ texture, usage: "sampled" })),
|
|
13271
|
+
...parameters ? [{ buffer: parameters, usage: "uniform" }] : []
|
|
13272
|
+
],
|
|
13273
|
+
attachments: { colorAttachments: [output] },
|
|
13274
|
+
compile: () => ({
|
|
13275
|
+
getRenderPassProps: () => ({ clearColor: [0, 0, 0, 0], clearDepth: false }),
|
|
13276
|
+
encode: ({ renderPass, getTextureView, getBuffer }) => this.draw(
|
|
13277
|
+
renderPass,
|
|
13278
|
+
Object.fromEntries(
|
|
13279
|
+
Object.entries(inputs).map(([name, view]) => [name, getTextureView(view)])
|
|
13280
|
+
),
|
|
13281
|
+
parameters ? getBuffer(parameters) : void 0
|
|
13282
|
+
)
|
|
13283
|
+
})
|
|
13284
|
+
});
|
|
13285
|
+
}
|
|
13286
|
+
/** SimpleGraph owns only per-invocation framebuffer/uniform wrappers, never bound textures. */
|
|
13287
|
+
prepare(textures, values) {
|
|
13288
|
+
this.validateTextures(textures);
|
|
13289
|
+
const inputs = Object.fromEntries(
|
|
13290
|
+
Object.entries(this.operation.inputs).map(([name, value]) => [name, textures.get(value)])
|
|
13291
|
+
);
|
|
13292
|
+
const output = textures.get(this.operation.output);
|
|
13293
|
+
const info = getTextureBindingInfo(output);
|
|
13294
|
+
const data = new Uint8Array(this.parameterByteLength);
|
|
13295
|
+
const view = new DataView(data.buffer);
|
|
13296
|
+
const parameterValues = Object.values(this.operation.parameters).map((name, index) => {
|
|
13297
|
+
const value = values.get(name);
|
|
13298
|
+
(0, import_core23.assert)(value !== void 0);
|
|
13299
|
+
if (typeof value === "number") {
|
|
13300
|
+
switch (this.parameterFormats[index]) {
|
|
13301
|
+
case "float32":
|
|
13302
|
+
view.setFloat32(index * 4, value, true);
|
|
13303
|
+
break;
|
|
13304
|
+
case "sint32":
|
|
13305
|
+
view.setInt32(index * 4, value, true);
|
|
13306
|
+
break;
|
|
13307
|
+
case "uint32":
|
|
13308
|
+
view.setUint32(index * 4, value, true);
|
|
13309
|
+
break;
|
|
13310
|
+
}
|
|
13311
|
+
} else (0, import_core23.assert)(value.length === 1 && value.data.length === 1);
|
|
13312
|
+
return value;
|
|
13313
|
+
});
|
|
13314
|
+
const parameters = data.byteLength ? this.device.createBuffer({ data, usage: import_core23.Buffer.UNIFORM | import_core23.Buffer.COPY_DST }) : void 0;
|
|
13315
|
+
let framebuffer;
|
|
13316
|
+
try {
|
|
13317
|
+
framebuffer = this.device.createFramebuffer({
|
|
13318
|
+
width: info.width,
|
|
13319
|
+
height: info.height,
|
|
13320
|
+
colorAttachments: [output]
|
|
13321
|
+
});
|
|
13322
|
+
} catch (error) {
|
|
13323
|
+
parameters?.destroy();
|
|
13324
|
+
throw error;
|
|
13325
|
+
}
|
|
13326
|
+
return {
|
|
13327
|
+
encode: (commandEncoder) => {
|
|
13328
|
+
this.validateTextures(textures);
|
|
13329
|
+
if (parameters)
|
|
13330
|
+
parameterValues.forEach((value, index) => {
|
|
13331
|
+
if (!(value instanceof GPUVector)) return;
|
|
13332
|
+
const chunk = value.data[0];
|
|
13333
|
+
const buffer = chunk.buffer instanceof import_core23.Buffer ? chunk.buffer : chunk.buffer.buffer;
|
|
13334
|
+
commandEncoder.copyBufferToBuffer({
|
|
13335
|
+
sourceBuffer: buffer,
|
|
13336
|
+
sourceOffset: chunk.byteOffset,
|
|
13337
|
+
destinationBuffer: parameters,
|
|
13338
|
+
destinationOffset: index * 4,
|
|
13339
|
+
size: 4
|
|
13340
|
+
});
|
|
13341
|
+
});
|
|
13342
|
+
const pass = commandEncoder.beginRenderPass({
|
|
13343
|
+
framebuffer,
|
|
13344
|
+
clearColor: [0, 0, 0, 0],
|
|
13345
|
+
clearDepth: false
|
|
13346
|
+
});
|
|
13347
|
+
try {
|
|
13348
|
+
this.draw(pass, inputs, parameters);
|
|
13349
|
+
} finally {
|
|
13350
|
+
pass.end();
|
|
13351
|
+
}
|
|
13352
|
+
},
|
|
13353
|
+
destroy: () => {
|
|
13354
|
+
framebuffer.destroy();
|
|
13355
|
+
parameters?.destroy();
|
|
13356
|
+
}
|
|
13357
|
+
};
|
|
13358
|
+
}
|
|
13359
|
+
destroy() {
|
|
13360
|
+
for (const sampler of Object.values(this.samplers)) sampler.destroy();
|
|
13361
|
+
this.vertexArray?.destroy();
|
|
13362
|
+
this.kernel?.destroy();
|
|
13363
|
+
}
|
|
13364
|
+
draw(renderPass, inputs, parameters) {
|
|
13365
|
+
const bindings = { ...inputs, ...this.samplers };
|
|
13366
|
+
if (parameters) bindings["parameters"] = parameters;
|
|
13367
|
+
this.kernel.draw(renderPass, { vertexArray: this.vertexArray, vertexCount: 3, bindings });
|
|
13368
|
+
}
|
|
13369
|
+
};
|
|
13370
|
+
|
|
13371
|
+
// src/gpu-core/gpu-cpu-operation.ts
|
|
13372
|
+
var GPUCPUOperation = class {
|
|
13373
|
+
type = "cpu";
|
|
13374
|
+
id;
|
|
13375
|
+
inputs;
|
|
13376
|
+
outputs;
|
|
13377
|
+
execute;
|
|
13378
|
+
constructor(props) {
|
|
13379
|
+
this.id = props.id;
|
|
13380
|
+
this.inputs = Object.freeze({ ...props.inputs });
|
|
13381
|
+
this.outputs = Object.freeze(
|
|
13382
|
+
Object.fromEntries(
|
|
13383
|
+
Object.entries(props.outputs).map(([name, descriptor]) => [
|
|
13384
|
+
name,
|
|
13385
|
+
Object.freeze({
|
|
13386
|
+
...descriptor,
|
|
13387
|
+
...descriptor.chunkLengths ? { chunkLengths: Object.freeze([...descriptor.chunkLengths]) } : {}
|
|
13388
|
+
})
|
|
13389
|
+
])
|
|
13390
|
+
)
|
|
13391
|
+
);
|
|
13392
|
+
this.execute = props.execute;
|
|
13393
|
+
}
|
|
13394
|
+
get contract() {
|
|
13395
|
+
return {
|
|
13396
|
+
outputs: this.outputs,
|
|
13397
|
+
values: [
|
|
13398
|
+
...Object.values(this.inputs).map((value) => ({ value, access: "read" })),
|
|
13399
|
+
...Object.keys(this.outputs).map((value) => ({ value, access: "write" }))
|
|
13400
|
+
]
|
|
13401
|
+
};
|
|
13402
|
+
}
|
|
13403
|
+
};
|
|
13404
|
+
|
|
13405
|
+
// src/gpu-core/gpu-cpu-execution.ts
|
|
13406
|
+
var import_core24 = __toESM(require_core(), 1);
|
|
13407
|
+
var GPUCPUExecution = class {
|
|
13408
|
+
constructor(device, program, compileStage) {
|
|
13409
|
+
this.device = device;
|
|
13410
|
+
this.program = program;
|
|
13411
|
+
this.compileStage = compileStage;
|
|
13412
|
+
(0, import_core24.assert)(!program.textures.length && !program.vectors.some((value) => value.role === "state"));
|
|
13413
|
+
const declarations = [...program.scalars, ...program.vectors];
|
|
13414
|
+
const addInput = (graph, name) => {
|
|
13415
|
+
const declaration = declarations.find((value) => value.id === name);
|
|
13416
|
+
(0, import_core24.assert)(declaration);
|
|
13417
|
+
const vector = program.vectors.find((value) => value.id === name);
|
|
13418
|
+
if (vector)
|
|
13419
|
+
graph.addInput(
|
|
13420
|
+
name,
|
|
13421
|
+
gpuGraph.vector(vector.format, {
|
|
13422
|
+
length: vector.length,
|
|
13423
|
+
chunkLengths: vector.chunkLengths
|
|
13424
|
+
})
|
|
13425
|
+
);
|
|
13426
|
+
else
|
|
13427
|
+
graph.addInput(
|
|
13428
|
+
name,
|
|
13429
|
+
gpuGraph.scalar(program.scalars.find((value) => value.id === name).format)
|
|
13430
|
+
);
|
|
13431
|
+
};
|
|
13432
|
+
try {
|
|
13433
|
+
for (const operation of program.operations) {
|
|
13434
|
+
if (operation instanceof GPUCPUOperation) {
|
|
13435
|
+
this.stages.push(operation);
|
|
13436
|
+
continue;
|
|
13437
|
+
}
|
|
13438
|
+
(0, import_core24.assert)("contract" in operation && operation.contract);
|
|
13439
|
+
const inputs = operation.contract.values.filter((use) => use.access !== "write").map((use) => typeof use.value === "string" ? use.value : use.value.id);
|
|
13440
|
+
const outputs = operation.contract.values.filter((use) => use.access !== "read").map((use) => typeof use.value === "string" ? use.value : use.value.id);
|
|
13441
|
+
const graph = new GPUGraph();
|
|
13442
|
+
for (const name of new Set(inputs)) addInput(graph, name);
|
|
13443
|
+
for (const name of new Set(outputs)) {
|
|
13444
|
+
const vector = program.vectors.find((value) => value.id === name);
|
|
13445
|
+
if (vector)
|
|
13446
|
+
graph.addDeclaration(
|
|
13447
|
+
name,
|
|
13448
|
+
gpuGraph.vector(vector.format, {
|
|
13449
|
+
length: vector.length,
|
|
13450
|
+
chunkLengths: vector.chunkLengths
|
|
13451
|
+
}),
|
|
13452
|
+
"value"
|
|
13453
|
+
);
|
|
13454
|
+
}
|
|
13455
|
+
graph.add(operation);
|
|
13456
|
+
this.stages.push({
|
|
13457
|
+
graph: compileStage(graph, outputs),
|
|
13458
|
+
inputs
|
|
13459
|
+
});
|
|
13460
|
+
}
|
|
13461
|
+
} catch (error) {
|
|
13462
|
+
this.destroy();
|
|
13463
|
+
throw error;
|
|
13464
|
+
}
|
|
13465
|
+
}
|
|
13466
|
+
device;
|
|
13467
|
+
program;
|
|
13468
|
+
compileStage;
|
|
13469
|
+
stages = [];
|
|
13470
|
+
async run(bindings, locations = {}) {
|
|
13471
|
+
for (const [name, location] of Object.entries(locations))
|
|
13472
|
+
(0, import_core24.assert)(this.program.outputs.includes(name) && (location === "cpu" || location === "gpu"));
|
|
13473
|
+
const cpu = /* @__PURE__ */ new Map();
|
|
13474
|
+
for (const declaration of [...this.program.vectors, ...this.program.scalars].filter(
|
|
13475
|
+
(value) => value.role === "input"
|
|
13476
|
+
)) {
|
|
13477
|
+
const value = bindings[declaration.id];
|
|
13478
|
+
(0, import_core24.assert)(value !== void 0);
|
|
13479
|
+
if (!(value instanceof CPUVector)) {
|
|
13480
|
+
const graph = new GPUGraph();
|
|
13481
|
+
const vector = this.program.vectors.find((vector2) => vector2.id === declaration.id);
|
|
13482
|
+
if (vector)
|
|
13483
|
+
graph.addInput(
|
|
13484
|
+
declaration.id,
|
|
13485
|
+
gpuGraph.vector(vector.format, {
|
|
13486
|
+
length: vector.length,
|
|
13487
|
+
chunkLengths: vector.chunkLengths
|
|
13488
|
+
})
|
|
13489
|
+
);
|
|
13490
|
+
else
|
|
13491
|
+
graph.addInput(
|
|
13492
|
+
declaration.id,
|
|
13493
|
+
gpuGraph.scalar(
|
|
13494
|
+
this.program.scalars.find((scalar) => scalar.id === declaration.id).format
|
|
13495
|
+
)
|
|
13496
|
+
);
|
|
13497
|
+
new GPUExpressionProgram(graph, { outputs: [] }).prepare(this.device, { [declaration.id]: value }).finish();
|
|
13498
|
+
}
|
|
13499
|
+
if (value instanceof CPUVector) {
|
|
13500
|
+
(0, import_core24.assert)(value.data.every((chunk) => !chunk.nullBitmap && !chunk.valueOffsets));
|
|
13501
|
+
(0, import_core24.assert)(value.format === declaration.format);
|
|
13502
|
+
const vector = this.program.vectors.find((vector2) => vector2.id === declaration.id);
|
|
13503
|
+
(0, import_core24.assert)(vector && (vector.length === void 0 || vector.length === value.length));
|
|
13504
|
+
(0, import_core24.assert)(
|
|
13505
|
+
!vector.chunkLengths || vector.chunkLengths.length === value.data.length && vector.chunkLengths.every((length, index) => length === value.data[index].length)
|
|
13506
|
+
);
|
|
13507
|
+
cpu.set(declaration.id, value);
|
|
13508
|
+
}
|
|
13509
|
+
}
|
|
13510
|
+
const values = { ...bindings };
|
|
13511
|
+
const owned = /* @__PURE__ */ new Set();
|
|
13512
|
+
const ensureCPU = async (name) => {
|
|
13513
|
+
let value = cpu.get(name);
|
|
13514
|
+
if (!value) {
|
|
13515
|
+
const gpu = values[name];
|
|
13516
|
+
(0, import_core24.assert)(gpu instanceof GPUVector);
|
|
13517
|
+
const read = await readCPUVector(gpu);
|
|
13518
|
+
value = makeCPUVector(
|
|
13519
|
+
read.format,
|
|
13520
|
+
read.chunks.map((chunk) => chunk.values)
|
|
13521
|
+
);
|
|
13522
|
+
cpu.set(name, value);
|
|
13523
|
+
}
|
|
13524
|
+
return getCPUView(value);
|
|
13525
|
+
};
|
|
13526
|
+
const ensureGPU = async (name) => {
|
|
13527
|
+
const existing = values[name];
|
|
13528
|
+
if (existing instanceof GPUVector) return existing;
|
|
13529
|
+
const view = await ensureCPU(name);
|
|
13530
|
+
const graph = new GPUGraph();
|
|
13531
|
+
graph.add(
|
|
13532
|
+
new GPUUploadOperation({
|
|
13533
|
+
output: name,
|
|
13534
|
+
format: view.format,
|
|
13535
|
+
data: view.chunks.map((chunk) => chunk.values)
|
|
13536
|
+
})
|
|
13537
|
+
);
|
|
13538
|
+
const compiled = this.compileStage(graph);
|
|
13539
|
+
try {
|
|
13540
|
+
const result = (await compiled.run({}))[name];
|
|
13541
|
+
owned.add(result);
|
|
13542
|
+
values[name] = result;
|
|
13543
|
+
return result;
|
|
13544
|
+
} finally {
|
|
13545
|
+
compiled.destroy();
|
|
13546
|
+
}
|
|
13547
|
+
};
|
|
13548
|
+
try {
|
|
13549
|
+
for (const stage of this.stages) {
|
|
13550
|
+
let results;
|
|
13551
|
+
if (stage instanceof GPUCPUOperation) {
|
|
13552
|
+
const inputs = /* @__PURE__ */ Object.create(null);
|
|
13553
|
+
for (const [localName, name] of Object.entries(stage.inputs)) {
|
|
13554
|
+
const value = values[name];
|
|
13555
|
+
const cpuValue = typeof value === "number" ? value : await ensureCPU(name);
|
|
13556
|
+
inputs[localName] = typeof cpuValue !== "number" && this.program.scalars.some((scalar) => scalar.id === name) ? cpuValue.pack()[0] : cpuValue;
|
|
13557
|
+
}
|
|
13558
|
+
const outputs2 = await stage.execute({ inputs });
|
|
13559
|
+
(0, import_core24.assert)(Object.keys(outputs2).length === Object.keys(stage.outputs).length);
|
|
13560
|
+
for (const name of Object.keys(stage.outputs)) {
|
|
13561
|
+
const descriptor = this.program.vectors.find((vector) => vector.id === name);
|
|
13562
|
+
const result = outputs2[name];
|
|
13563
|
+
(0, import_core24.assert)(result);
|
|
13564
|
+
const arrays = "chunks" in result ? result.chunks.map((chunk) => chunk.values) : [result];
|
|
13565
|
+
const upload = new GPUUploadOperation({
|
|
13566
|
+
output: name,
|
|
13567
|
+
format: descriptor.format,
|
|
13568
|
+
data: arrays
|
|
13569
|
+
});
|
|
13570
|
+
const length = upload.chunkLengths.reduce((total, count) => total + count, 0);
|
|
13571
|
+
(0, import_core24.assert)(descriptor.length === void 0 || descriptor.length === length);
|
|
13572
|
+
(0, import_core24.assert)(
|
|
13573
|
+
!descriptor.chunkLengths || descriptor.chunkLengths.length === arrays.length && descriptor.chunkLengths.every(
|
|
13574
|
+
(count, index) => count === upload.chunkLengths[index]
|
|
13575
|
+
)
|
|
13576
|
+
);
|
|
13577
|
+
cpu.set(name, makeCPUVector(descriptor.format, arrays));
|
|
13578
|
+
delete values[name];
|
|
13579
|
+
}
|
|
13580
|
+
continue;
|
|
13581
|
+
} else {
|
|
13582
|
+
const inputs = /* @__PURE__ */ Object.create(null);
|
|
13583
|
+
for (const name of stage.inputs) {
|
|
13584
|
+
const value = values[name];
|
|
13585
|
+
inputs[name] = this.program.scalars.some((scalar) => scalar.id === name) ? typeof value === "number" ? value : (await ensureCPU(name)).pack()[0] : await ensureGPU(name);
|
|
13586
|
+
}
|
|
13587
|
+
results = await stage.graph.run({ inputs });
|
|
13588
|
+
}
|
|
13589
|
+
for (const [name, value] of Object.entries(results)) {
|
|
13590
|
+
cpu.delete(name);
|
|
13591
|
+
values[name] = value;
|
|
13592
|
+
owned.add(value);
|
|
13593
|
+
}
|
|
13594
|
+
}
|
|
13595
|
+
const outputs = /* @__PURE__ */ Object.create(null);
|
|
13596
|
+
for (const name of this.program.outputs) {
|
|
13597
|
+
if (locations[name] === "cpu") {
|
|
13598
|
+
await ensureCPU(name);
|
|
13599
|
+
outputs[name] = cpu.get(name);
|
|
13600
|
+
} else outputs[name] = await ensureGPU(name);
|
|
13601
|
+
}
|
|
13602
|
+
for (const value of Object.values(outputs))
|
|
13603
|
+
if (value instanceof GPUVector) owned.delete(value);
|
|
13604
|
+
return outputs;
|
|
13605
|
+
} finally {
|
|
13606
|
+
for (const value of owned) value.destroy();
|
|
13607
|
+
}
|
|
13608
|
+
}
|
|
13609
|
+
destroy() {
|
|
13610
|
+
for (const stage of this.stages) if (!(stage instanceof GPUCPUOperation)) stage.graph.destroy();
|
|
13611
|
+
}
|
|
13612
|
+
};
|
|
13613
|
+
async function readCPUVector(vector) {
|
|
13614
|
+
(0, import_core24.assert)(vector.format);
|
|
13615
|
+
const info = getGPUVectorFormatInfo(vector.format);
|
|
13616
|
+
const ValueType = info.signedDataType === "float32" ? Float32Array : info.signedDataType === "uint32" ? Uint32Array : Int32Array;
|
|
13617
|
+
const chunks = [];
|
|
13618
|
+
for (const chunk of vector.data) {
|
|
13619
|
+
const values = new ValueType(chunk.length * info.byteLength / 4);
|
|
13620
|
+
if (chunk.length) {
|
|
13621
|
+
const bytes = await chunk.buffer.readAsync(
|
|
13622
|
+
chunk.byteOffset,
|
|
13623
|
+
(chunk.length - 1) * chunk.byteStride + info.byteLength
|
|
13624
|
+
);
|
|
13625
|
+
const packed = new Uint8Array(values.buffer);
|
|
13626
|
+
for (let row = 0; row < chunk.length; row++)
|
|
13627
|
+
packed.set(
|
|
13628
|
+
bytes.subarray(row * chunk.byteStride, row * chunk.byteStride + info.byteLength),
|
|
13629
|
+
row * info.byteLength
|
|
13630
|
+
);
|
|
13631
|
+
}
|
|
13632
|
+
chunks.push({ values, length: chunk.length });
|
|
13633
|
+
}
|
|
13634
|
+
return {
|
|
13635
|
+
format: vector.format,
|
|
13636
|
+
length: vector.length,
|
|
13637
|
+
chunks,
|
|
13638
|
+
pack() {
|
|
13639
|
+
const packed = new ValueType(chunks.reduce((total, chunk) => total + chunk.values.length, 0));
|
|
13640
|
+
let offset = 0;
|
|
13641
|
+
for (const chunk of chunks) {
|
|
13642
|
+
packed.set(chunk.values, offset);
|
|
13643
|
+
offset += chunk.values.length;
|
|
13644
|
+
}
|
|
13645
|
+
return packed;
|
|
13646
|
+
}
|
|
13647
|
+
};
|
|
13648
|
+
}
|
|
13649
|
+
function makeCPUVector(format, arrays) {
|
|
13650
|
+
const width = getGPUVectorFormatInfo(format).byteLength;
|
|
13651
|
+
return new CPUVector({
|
|
13652
|
+
format,
|
|
13653
|
+
data: arrays.map((buffer) => new CPUData({ buffer, format, length: buffer.byteLength / width }))
|
|
13654
|
+
});
|
|
13655
|
+
}
|
|
13656
|
+
function getCPUView(vector) {
|
|
13657
|
+
const format = vector.format;
|
|
13658
|
+
(0, import_core24.assert)(/^(float32|sint32|uint32)(x[234])?$/.test(format));
|
|
13659
|
+
const info = getGPUVectorFormatInfo(format);
|
|
13660
|
+
const ValueType = info.signedDataType === "float32" ? Float32Array : info.signedDataType === "uint32" ? Uint32Array : Int32Array;
|
|
13661
|
+
const chunks = vector.data.map((chunk) => {
|
|
13662
|
+
const values = new ValueType(chunk.length * info.components);
|
|
13663
|
+
const bytes = new Uint8Array(values.buffer);
|
|
13664
|
+
for (let row = 0; row < chunk.length; row++)
|
|
13665
|
+
bytes.set(
|
|
13666
|
+
new Uint8Array(chunk.buffer, chunk.byteOffset + row * chunk.byteStride, info.byteLength),
|
|
13667
|
+
row * info.byteLength
|
|
13668
|
+
);
|
|
13669
|
+
return { values, length: chunk.length };
|
|
13670
|
+
});
|
|
13671
|
+
return {
|
|
13672
|
+
format,
|
|
13673
|
+
length: vector.length,
|
|
13674
|
+
chunks,
|
|
13675
|
+
pack() {
|
|
13676
|
+
const values = new ValueType(vector.length * info.components);
|
|
13677
|
+
let offset = 0;
|
|
13678
|
+
for (const chunk of chunks) {
|
|
13679
|
+
values.set(chunk.values, offset);
|
|
13680
|
+
offset += chunk.values.length;
|
|
13681
|
+
}
|
|
13682
|
+
return values;
|
|
13683
|
+
}
|
|
13684
|
+
};
|
|
13685
|
+
}
|
|
13686
|
+
|
|
13687
|
+
// src/gpu-core/compiled-gpu-graph.ts
|
|
13688
|
+
var CompiledGPUGraph = class _CompiledGPUGraph {
|
|
13689
|
+
constructor(device, source, options = {}, lowerings) {
|
|
13690
|
+
this.device = device;
|
|
13691
|
+
if (device.type !== "webgpu") throw new Error("GPUGraph execution requires WebGPU");
|
|
13692
|
+
this.program = new GPUExpressionProgram(source, options);
|
|
13693
|
+
this.outputLocations = options.outputLocations ?? {};
|
|
13694
|
+
this.stageLowerings = lowerings ?? options.lowerings ?? [];
|
|
13695
|
+
this.compiler = new GPUGraphCompiler(device, [
|
|
13696
|
+
...lowerings ?? options.lowerings ?? [],
|
|
13697
|
+
{
|
|
13698
|
+
type: "shader-pass",
|
|
13699
|
+
lower: (operation, context) => this.shaderPasses.get(operation).lower(context)
|
|
13700
|
+
},
|
|
13701
|
+
{
|
|
13702
|
+
type: "expression",
|
|
13703
|
+
lower: (operation, context) => this.kernels.get(operation).lower(context)
|
|
13704
|
+
}
|
|
13705
|
+
]);
|
|
13706
|
+
if (this.program.operations.some((operation) => operation instanceof GPUCPUOperation) || Object.values(this.outputLocations).includes("cpu")) {
|
|
13707
|
+
this.cpuExecution = new GPUCPUExecution(
|
|
13708
|
+
device,
|
|
13709
|
+
this.program,
|
|
13710
|
+
(source2, outputs) => new _CompiledGPUGraph(device, source2, { outputs }, lowerings ?? options.lowerings)
|
|
13711
|
+
);
|
|
13712
|
+
return;
|
|
13713
|
+
}
|
|
13714
|
+
try {
|
|
13715
|
+
for (const plan of this.program.expressions)
|
|
13716
|
+
this.kernels.set(plan.operation, new GPUExpressionKernel(device, this.program, plan));
|
|
13717
|
+
for (const operation of this.program.operations)
|
|
13718
|
+
if (operation instanceof GPUShaderPassOperation)
|
|
13719
|
+
this.shaderPasses.set(
|
|
13720
|
+
operation,
|
|
13721
|
+
new GPUShaderPassKernel(device, operation, this.program)
|
|
13722
|
+
);
|
|
13723
|
+
} catch (error) {
|
|
13724
|
+
this.destroy();
|
|
13725
|
+
throw error;
|
|
13726
|
+
}
|
|
13727
|
+
}
|
|
13728
|
+
device;
|
|
13729
|
+
program;
|
|
13730
|
+
stageLowerings;
|
|
13731
|
+
compiler;
|
|
13732
|
+
kernels = /* @__PURE__ */ new Map();
|
|
13733
|
+
shaderPasses = /* @__PURE__ */ new Map();
|
|
13734
|
+
destroyed = false;
|
|
13735
|
+
runningCPU = false;
|
|
13736
|
+
cpuExecution;
|
|
13737
|
+
outputLocations;
|
|
13738
|
+
async run(supplied, options = {}) {
|
|
13739
|
+
(0, import_core25.assert)(!this.destroyed && !this.runningCPU);
|
|
13740
|
+
const suppliedInputs = "inputs" in supplied ? supplied.inputs : supplied;
|
|
13741
|
+
const useCPU = this.program.operations.some((operation) => operation instanceof GPUCPUOperation) || Object.values(this.outputLocations).includes("cpu") || Object.values(suppliedInputs ?? {}).some((value) => value instanceof CPUVector);
|
|
13742
|
+
if (!this.cpuExecution && useCPU)
|
|
13743
|
+
this.cpuExecution = new GPUCPUExecution(
|
|
13744
|
+
this.device,
|
|
13745
|
+
this.program,
|
|
13746
|
+
(source, outputs) => new _CompiledGPUGraph(this.device, source, { outputs }, this.stageLowerings)
|
|
13747
|
+
);
|
|
13748
|
+
if (useCPU && this.cpuExecution) {
|
|
13749
|
+
const resolved = this.program.resolveBindings(supplied, options);
|
|
13750
|
+
(0, import_core25.assert)(
|
|
13751
|
+
!resolved.options.outputTargets || Object.keys(resolved.options.outputTargets).length === 0
|
|
13752
|
+
);
|
|
13753
|
+
this.runningCPU = true;
|
|
13754
|
+
try {
|
|
13755
|
+
return await this.cpuExecution.run(resolved.bindings, this.outputLocations);
|
|
13756
|
+
} finally {
|
|
13757
|
+
this.runningCPU = false;
|
|
13758
|
+
}
|
|
13759
|
+
}
|
|
13760
|
+
const execution = this.prepare(supplied, options);
|
|
13761
|
+
let encoder;
|
|
13762
|
+
try {
|
|
13763
|
+
encoder = this.device.createCommandEncoder();
|
|
13764
|
+
execution.encode(encoder);
|
|
13765
|
+
this.device.submit(encoder.finish());
|
|
13766
|
+
return execution.outputs;
|
|
13767
|
+
} catch (error) {
|
|
13768
|
+
execution.discard();
|
|
13769
|
+
throw error;
|
|
13770
|
+
} finally {
|
|
13771
|
+
execution.destroy();
|
|
13772
|
+
encoder?.destroy();
|
|
13773
|
+
}
|
|
13774
|
+
}
|
|
13775
|
+
/** Bind one invocation without encoding or submitting commands. */
|
|
13776
|
+
prepare(supplied, options = {}) {
|
|
13777
|
+
(0, import_core25.assert)(!this.destroyed);
|
|
13778
|
+
if (this.program.operations.some((operation) => operation instanceof GPUCPUOperation) || Object.values(this.outputLocations).includes("cpu"))
|
|
13779
|
+
throw new Error("CPU operations require asynchronous run(), not prepare()");
|
|
13780
|
+
const resolvedBindings = this.program.resolveBindings(supplied, options);
|
|
13781
|
+
const bindings = resolvedBindings.bindings;
|
|
13782
|
+
options = resolvedBindings.options;
|
|
13783
|
+
const invocation = this.program.prepare(this.device, bindings, options, true);
|
|
13784
|
+
let executable;
|
|
13785
|
+
try {
|
|
13786
|
+
for (const kernel of this.shaderPasses.values())
|
|
13787
|
+
kernel.validateTextures(invocation.textures.values);
|
|
13788
|
+
const resolved = new GPUGraph();
|
|
13789
|
+
for (const scalar of this.program.scalars) resolved.scalar(scalar.id, scalar.format);
|
|
13790
|
+
const vectors = /* @__PURE__ */ Object.create(null);
|
|
13791
|
+
const scalars = /* @__PURE__ */ Object.create(null);
|
|
13792
|
+
for (const [name, value] of invocation.values) {
|
|
13793
|
+
if (typeof value === "number") scalars[name] = value;
|
|
13794
|
+
else if (this.program.vectors.some((vector) => vector.id === name)) vectors[name] = value;
|
|
13795
|
+
}
|
|
13796
|
+
for (const [name, value] of Object.entries(bindings)) {
|
|
13797
|
+
if (typeof value === "number") scalars[name] = value;
|
|
13798
|
+
}
|
|
13799
|
+
for (const vector of this.program.vectors) {
|
|
13800
|
+
const binding = vectors[vector.id];
|
|
13801
|
+
const transient = invocation.transientVectors.get(vector.id);
|
|
13802
|
+
if (transient) {
|
|
13803
|
+
resolved.addDeclaration(
|
|
13804
|
+
vector.id,
|
|
13805
|
+
{
|
|
13806
|
+
type: "vector",
|
|
13807
|
+
format: vector.format,
|
|
13808
|
+
length: transient.length,
|
|
13809
|
+
chunkLengths: transient.chunkLengths
|
|
13810
|
+
},
|
|
13811
|
+
"value"
|
|
13812
|
+
);
|
|
13813
|
+
continue;
|
|
13814
|
+
}
|
|
13815
|
+
if (!binding && vector.length === void 0)
|
|
13816
|
+
throw new Error(`Missing length or execution binding for ${vector.id}`);
|
|
13817
|
+
resolved.vector(vector.id, vector.format, binding?.length ?? vector.length, {
|
|
13818
|
+
external: Boolean(binding),
|
|
13819
|
+
chunkLengths: binding?.data.map((chunk) => chunk.length) ?? vector.chunkLengths
|
|
13820
|
+
});
|
|
13821
|
+
}
|
|
13822
|
+
const textures = /* @__PURE__ */ Object.create(null);
|
|
13823
|
+
for (const texture of this.program.textures) {
|
|
13824
|
+
const binding = invocation.textures.values.get(texture.id);
|
|
13825
|
+
const info = getTextureBindingInfo(binding);
|
|
13826
|
+
resolved.texture(texture.id, {
|
|
13827
|
+
format: info.format,
|
|
12906
13828
|
dimension: info.dimension,
|
|
12907
13829
|
width: info.width,
|
|
12908
13830
|
height: info.height,
|
|
@@ -12940,7 +13862,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12940
13862
|
}
|
|
12941
13863
|
executable = compilation.graph.compile();
|
|
12942
13864
|
return new PreparedGPUGraphExecution(this.device, invocation, executable, () => {
|
|
12943
|
-
(0,
|
|
13865
|
+
(0, import_core25.assert)(!this.destroyed);
|
|
12944
13866
|
});
|
|
12945
13867
|
} catch (error) {
|
|
12946
13868
|
executable?.destroy();
|
|
@@ -12949,6 +13871,10 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12949
13871
|
}
|
|
12950
13872
|
}
|
|
12951
13873
|
destroy() {
|
|
13874
|
+
(0, import_core25.assert)(!this.runningCPU);
|
|
13875
|
+
this.cpuExecution?.destroy();
|
|
13876
|
+
for (const kernel of this.shaderPasses.values()) kernel.destroy();
|
|
13877
|
+
this.shaderPasses.clear();
|
|
12952
13878
|
for (const kernel of this.kernels.values()) kernel.destroy();
|
|
12953
13879
|
this.kernels.clear();
|
|
12954
13880
|
this.destroyed = true;
|
|
@@ -12972,7 +13898,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12972
13898
|
destroyed = false;
|
|
12973
13899
|
/** Append commands once to a caller-owned encoder; never finish or submit it. */
|
|
12974
13900
|
encode(commandEncoder) {
|
|
12975
|
-
(0,
|
|
13901
|
+
(0, import_core25.assert)(!this.destroyed && !this.encoded && commandEncoder.device === this.device);
|
|
12976
13902
|
this.checkProgram();
|
|
12977
13903
|
this.encoded = true;
|
|
12978
13904
|
this.executable.encode(commandEncoder, { parameters: void 0 });
|
|
@@ -13854,143 +14780,8 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13854
14780
|
};
|
|
13855
14781
|
}
|
|
13856
14782
|
|
|
13857
|
-
// src/execution/compute/render-kernel.ts
|
|
13858
|
-
var import_core21 = __toESM(require_core(), 1);
|
|
13859
|
-
var RenderKernel = class _RenderKernel {
|
|
13860
|
-
/** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
|
|
13861
|
-
static async createAsync(device, props) {
|
|
13862
|
-
const ownsCompilation = !import_core21.PipelineFactory.getAsyncCompilation(device);
|
|
13863
|
-
const asyncCompilation = ownsCompilation ? import_core21.PipelineFactory.beginAsyncCompilation(device) : import_core21.PipelineFactory.getAsyncCompilation(device);
|
|
13864
|
-
let kernel;
|
|
13865
|
-
try {
|
|
13866
|
-
kernel = new _RenderKernel(device, props);
|
|
13867
|
-
} finally {
|
|
13868
|
-
if (ownsCompilation) import_core21.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
13869
|
-
}
|
|
13870
|
-
try {
|
|
13871
|
-
if (ownsCompilation) {
|
|
13872
|
-
await Promise.all(asyncCompilation);
|
|
13873
|
-
} else {
|
|
13874
|
-
await kernel._pipelineInitialization;
|
|
13875
|
-
}
|
|
13876
|
-
return kernel;
|
|
13877
|
-
} catch (error) {
|
|
13878
|
-
kernel.destroy();
|
|
13879
|
-
throw error;
|
|
13880
|
-
}
|
|
13881
|
-
}
|
|
13882
|
-
device;
|
|
13883
|
-
id;
|
|
13884
|
-
vertexSource;
|
|
13885
|
-
fragmentSource;
|
|
13886
|
-
pipelineFactory;
|
|
13887
|
-
shaderFactory;
|
|
13888
|
-
vertexShader;
|
|
13889
|
-
fragmentShader;
|
|
13890
|
-
pipeline;
|
|
13891
|
-
_pipelineInitialization;
|
|
13892
|
-
_destroyed = false;
|
|
13893
|
-
drawDefaults;
|
|
13894
|
-
constructor(device, props) {
|
|
13895
|
-
if (device.type !== "webgpu" && device.type !== "webgl") {
|
|
13896
|
-
throw new Error("RenderKernel requires WebGL or WebGPU");
|
|
13897
|
-
}
|
|
13898
|
-
if (device.type === "webgl" && !props.fragmentSource) {
|
|
13899
|
-
throw new Error("WebGL RenderKernel requires a fragment shader");
|
|
13900
|
-
}
|
|
13901
|
-
const {
|
|
13902
|
-
vertexSource,
|
|
13903
|
-
fragmentSource,
|
|
13904
|
-
pipelineFactory,
|
|
13905
|
-
shaderFactory,
|
|
13906
|
-
debugShaders,
|
|
13907
|
-
...pipelineProps
|
|
13908
|
-
} = props;
|
|
13909
|
-
this.device = device;
|
|
13910
|
-
this.drawDefaults = {
|
|
13911
|
-
parameters: props.parameters ?? {},
|
|
13912
|
-
topology: props.topology ?? "triangle-list"
|
|
13913
|
-
};
|
|
13914
|
-
this.id = props.id ?? "render-kernel";
|
|
13915
|
-
this.vertexSource = vertexSource;
|
|
13916
|
-
this.fragmentSource = fragmentSource;
|
|
13917
|
-
this.pipelineFactory = pipelineFactory ?? import_core21.PipelineFactory.getDefaultPipelineFactory(device);
|
|
13918
|
-
this.shaderFactory = shaderFactory ?? import_core21.ShaderFactory.getDefaultShaderFactory(device);
|
|
13919
|
-
this.vertexShader = this.shaderFactory.createShader({
|
|
13920
|
-
id: `${this.id}-vertex`,
|
|
13921
|
-
stage: "vertex",
|
|
13922
|
-
source: this.vertexSource,
|
|
13923
|
-
debugShaders
|
|
13924
|
-
});
|
|
13925
|
-
this.fragmentShader = this.fragmentSource ? this.shaderFactory.createShader({
|
|
13926
|
-
id: `${this.id}-fragment`,
|
|
13927
|
-
stage: "fragment",
|
|
13928
|
-
source: this.fragmentSource,
|
|
13929
|
-
debugShaders
|
|
13930
|
-
}) : null;
|
|
13931
|
-
const renderPipelineProps = {
|
|
13932
|
-
...pipelineProps,
|
|
13933
|
-
vs: this.vertexShader,
|
|
13934
|
-
fs: this.fragmentShader
|
|
13935
|
-
};
|
|
13936
|
-
const asyncCompilation = import_core21.PipelineFactory.getAsyncCompilation(device);
|
|
13937
|
-
if (asyncCompilation) {
|
|
13938
|
-
const pipelineInitialization = this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
|
|
13939
|
-
this._pipelineInitialization = pipelineInitialization;
|
|
13940
|
-
asyncCompilation.push(
|
|
13941
|
-
pipelineInitialization.then((pipeline) => {
|
|
13942
|
-
this.pipeline = pipeline;
|
|
13943
|
-
return pipeline;
|
|
13944
|
-
})
|
|
13945
|
-
);
|
|
13946
|
-
} else {
|
|
13947
|
-
this.pipeline = this.pipelineFactory.createRenderPipeline(renderPipelineProps);
|
|
13948
|
-
}
|
|
13949
|
-
}
|
|
13950
|
-
/** Applies per-draw bindings/vertex state and records a direct draw. */
|
|
13951
|
-
draw(renderPass, options) {
|
|
13952
|
-
const { bindings = {}, vertexArray, ...drawOptions } = options;
|
|
13953
|
-
this._setPipeline(renderPass, bindings, vertexArray);
|
|
13954
|
-
return renderPass.draw(
|
|
13955
|
-
this.device.type === "webgl" ? {
|
|
13956
|
-
...this.drawDefaults,
|
|
13957
|
-
...drawOptions,
|
|
13958
|
-
isInstanced: drawOptions.isInstanced ?? drawOptions.instanceCount !== void 0
|
|
13959
|
-
} : drawOptions
|
|
13960
|
-
);
|
|
13961
|
-
}
|
|
13962
|
-
/** Applies per-draw state and records a non-indexed indirect draw. */
|
|
13963
|
-
drawIndirect(renderPass, options) {
|
|
13964
|
-
if (this.device.type !== "webgpu")
|
|
13965
|
-
throw new Error("Indirect drawing is only supported in WebGPU");
|
|
13966
|
-
const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
|
|
13967
|
-
this._setPipeline(renderPass, bindings, vertexArray);
|
|
13968
|
-
renderPass.drawIndirect(indirectBuffer, indirectOffset);
|
|
13969
|
-
}
|
|
13970
|
-
/** Applies per-draw state and records an indexed indirect draw. */
|
|
13971
|
-
drawIndexedIndirect(renderPass, options) {
|
|
13972
|
-
if (this.device.type !== "webgpu")
|
|
13973
|
-
throw new Error("Indirect drawing is only supported in WebGPU");
|
|
13974
|
-
const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
|
|
13975
|
-
this._setPipeline(renderPass, bindings, vertexArray);
|
|
13976
|
-
renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
|
|
13977
|
-
}
|
|
13978
|
-
destroy() {
|
|
13979
|
-
if (this._destroyed) return;
|
|
13980
|
-
if (this.pipeline) this.pipelineFactory.release(this.pipeline);
|
|
13981
|
-
this.shaderFactory.release(this.vertexShader);
|
|
13982
|
-
if (this.fragmentShader) this.shaderFactory.release(this.fragmentShader);
|
|
13983
|
-
this._destroyed = true;
|
|
13984
|
-
}
|
|
13985
|
-
_setPipeline(renderPass, bindings, vertexArray) {
|
|
13986
|
-
renderPass.setPipeline(this.pipeline);
|
|
13987
|
-
renderPass.setBindings(bindings);
|
|
13988
|
-
renderPass.setVertexArray(vertexArray);
|
|
13989
|
-
}
|
|
13990
|
-
};
|
|
13991
|
-
|
|
13992
14783
|
// src/gpu-core/gpu-compaction-operation.ts
|
|
13993
|
-
var
|
|
14784
|
+
var import_core26 = __toESM(require_core(), 1);
|
|
13994
14785
|
var GPUCompactionOperation = class {
|
|
13995
14786
|
type = "compaction";
|
|
13996
14787
|
id;
|
|
@@ -14005,9 +14796,9 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
14005
14796
|
outputs: ({ getValue }) => {
|
|
14006
14797
|
for (const name of [input, flags]) {
|
|
14007
14798
|
const value = getValue(name);
|
|
14008
|
-
(0,
|
|
14799
|
+
(0, import_core26.assert)(value.type === "vector" && value.format === "uint32");
|
|
14009
14800
|
}
|
|
14010
|
-
(0,
|
|
14801
|
+
(0, import_core26.assert)(output !== count);
|
|
14011
14802
|
return { [output]: gpuGraph.vector("uint32"), [count]: gpuGraph.scalar("uint32") };
|
|
14012
14803
|
},
|
|
14013
14804
|
values: [
|