@luma.gl/graph 10.0.0-alpha.11 → 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/dist.dev.js +658 -292
- package/dist/dist.min.js +110 -92
- 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 +15 -0
- package/dist/gpu-core/compiled-gpu-graph.d.ts +1 -0
- package/dist/gpu-core/compiled-gpu-graph.d.ts.map +1 -1
- package/dist/gpu-core/compiled-gpu-graph.js +15 -0
- package/dist/gpu-core/compiled-gpu-graph.js.map +1 -1
- package/dist/gpu-core/gpu-command-graph.cjs +9 -0
- package/dist/gpu-core/gpu-command-graph.d.ts +2 -0
- package/dist/gpu-core/gpu-command-graph.d.ts.map +1 -1
- package/dist/gpu-core/gpu-command-graph.js +9 -0
- package/dist/gpu-core/gpu-command-graph.js.map +1 -1
- package/dist/gpu-core/gpu-expression-plan.cjs +4 -0
- package/dist/gpu-core/gpu-expression-plan.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-plan.js +5 -0
- package/dist/gpu-core/gpu-expression-plan.js.map +1 -1
- 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/index.cjs +3 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +2 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +1 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-dggs/benchmarks.cjs.map +1 -1
- package/dist/gpu-graph/index.cjs.map +3 -3
- package/dist/gpu-graph-algorithms/benchmarks.cjs.map +1 -1
- package/dist/gpu-physics/index.cjs.map +1 -1
- package/dist/gpu-project/graph.cjs.map +3 -3
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.cjs +53 -5
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.d.ts +3 -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 +58 -5
- package/dist/gpu-simple-graph/compiled-gpu-expression-graph.js.map +1 -1
- package/dist/gpu-simple-graph/index.cjs.map +3 -3
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/gpu-core/compiled-gpu-graph.ts +18 -0
- package/src/gpu-core/gpu-command-graph.ts +10 -0
- package/src/gpu-core/gpu-expression-plan.ts +6 -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/index.ts +2 -0
- package/src/gpu-simple-graph/compiled-gpu-expression-graph.ts +59 -5
- package/src/index.ts +2 -0
package/dist/dist.dev.js
CHANGED
|
@@ -72,6 +72,7 @@ var __exports__ = (() => {
|
|
|
72
72
|
GPUGraphTexture: () => GPUGraphTexture,
|
|
73
73
|
GPUGraphTextureView: () => GPUGraphTextureView,
|
|
74
74
|
GPUGraphVector: () => GPUGraphVector,
|
|
75
|
+
GPUShaderPassOperation: () => GPUShaderPassOperation,
|
|
75
76
|
GPUUploadOperation: () => GPUUploadOperation,
|
|
76
77
|
GraphBufferHandle: () => GraphBufferHandle,
|
|
77
78
|
GraphDataView: () => GraphDataView,
|
|
@@ -1193,7 +1194,19 @@ var __exports__ = (() => {
|
|
|
1193
1194
|
}
|
|
1194
1195
|
|
|
1195
1196
|
// ../core/src/shadertypes/data-types/decode-data-types.ts
|
|
1197
|
+
var dataTypeInfoCache = /* @__PURE__ */ new Map();
|
|
1196
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) {
|
|
1197
1210
|
const normalized = type.includes("norm");
|
|
1198
1211
|
const integer = !normalized && !type.startsWith("float");
|
|
1199
1212
|
const signed = type.startsWith("s");
|
|
@@ -1534,40 +1547,33 @@ var __exports__ = (() => {
|
|
|
1534
1547
|
return this.isCompressed(format) && !format.endsWith("-webgl") ? WEBGPU_CREATE_FILTER2 : 0;
|
|
1535
1548
|
}
|
|
1536
1549
|
/** Computes the memory layout for a texture, in particular including row byte alignment */
|
|
1537
|
-
computeMemoryLayout(opts) {
|
|
1538
|
-
return computeTextureMemoryLayout(opts);
|
|
1550
|
+
computeMemoryLayout(opts, result) {
|
|
1551
|
+
return computeTextureMemoryLayout(opts, result);
|
|
1539
1552
|
}
|
|
1540
1553
|
};
|
|
1541
1554
|
var textureFormatDecoder = new TextureFormatDecoder();
|
|
1542
|
-
function computeTextureMemoryLayout({
|
|
1543
|
-
format,
|
|
1544
|
-
width,
|
|
1545
|
-
height,
|
|
1546
|
-
depth,
|
|
1547
|
-
byteAlignment
|
|
1548
|
-
}) {
|
|
1555
|
+
function computeTextureMemoryLayout({ format, width, height, depth, byteAlignment }, result = {}) {
|
|
1549
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) {
|
|
1550
1569
|
const {
|
|
1551
1570
|
bytesPerPixel,
|
|
1552
1571
|
bytesPerBlock = bytesPerPixel,
|
|
1553
1572
|
blockWidth = 1,
|
|
1554
|
-
blockHeight = 1,
|
|
1555
1573
|
compressed = false
|
|
1556
1574
|
} = formatInfo;
|
|
1557
1575
|
const blockColumns = compressed ? Math.ceil(width / blockWidth) : width;
|
|
1558
|
-
|
|
1559
|
-
const unpaddedBytesPerRow = blockColumns * bytesPerBlock;
|
|
1560
|
-
const bytesPerRow = Math.ceil(unpaddedBytesPerRow / byteAlignment) * byteAlignment;
|
|
1561
|
-
const rowsPerImage = blockRows;
|
|
1562
|
-
const byteLength = bytesPerRow * rowsPerImage * depth;
|
|
1563
|
-
return {
|
|
1564
|
-
bytesPerPixel,
|
|
1565
|
-
bytesPerRow,
|
|
1566
|
-
rowsPerImage,
|
|
1567
|
-
depthOrArrayLayers: depth,
|
|
1568
|
-
bytesPerImage: bytesPerRow * rowsPerImage,
|
|
1569
|
-
byteLength
|
|
1570
|
-
};
|
|
1576
|
+
return Math.ceil(blockColumns * bytesPerBlock / byteAlignment) * byteAlignment;
|
|
1571
1577
|
}
|
|
1572
1578
|
function getTextureFormatCapabilities(format) {
|
|
1573
1579
|
const info = getTextureFormatDefinition(format);
|
|
@@ -1589,7 +1595,18 @@ var __exports__ = (() => {
|
|
|
1589
1595
|
formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
|
|
1590
1596
|
return formatCapabilities;
|
|
1591
1597
|
}
|
|
1598
|
+
var textureFormatInfoCache = /* @__PURE__ */ new Map();
|
|
1592
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) {
|
|
1593
1610
|
let formatInfo = getTextureFormatInfoUsingTable(format);
|
|
1594
1611
|
if (textureFormatDecoder.isCompressed(format)) {
|
|
1595
1612
|
formatInfo.channels = "rgb";
|
|
@@ -1758,6 +1775,8 @@ var __exports__ = (() => {
|
|
|
1758
1775
|
};
|
|
1759
1776
|
|
|
1760
1777
|
// ../core/src/api/adapter/resources/texture.ts
|
|
1778
|
+
var textureLayoutScratchPool = [];
|
|
1779
|
+
var emptyTextureReadOptions = Object.freeze({});
|
|
1761
1780
|
var BASE_DIMENSIONS = {
|
|
1762
1781
|
"1d": "1d",
|
|
1763
1782
|
"2d": "2d",
|
|
@@ -1876,17 +1895,24 @@ var __exports__ = (() => {
|
|
|
1876
1895
|
* Calculates the memory layout of the texture, required when reading and writing data.
|
|
1877
1896
|
* @return the backend-aligned linear layout, in particular bytesPerRow which includes any required padding for buffer copy/read paths
|
|
1878
1897
|
*/
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
const
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
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
|
+
}
|
|
1890
1916
|
}
|
|
1891
1917
|
/**
|
|
1892
1918
|
* Read the contents of a texture into a GPU Buffer.
|
|
@@ -1995,59 +2021,57 @@ var __exports__ = (() => {
|
|
|
1995
2021
|
});
|
|
1996
2022
|
}
|
|
1997
2023
|
}
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
const
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
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;
|
|
2005
2035
|
}
|
|
2006
|
-
_normalizeCopyExternalImageOptions(options_) {
|
|
2007
|
-
const
|
|
2008
|
-
const mipLevel = optionsWithoutUndefined.mipLevel ?? 0;
|
|
2009
|
-
const mipLevelSize = this._getMipLevelSize(mipLevel);
|
|
2036
|
+
_normalizeCopyExternalImageOptions(options_, result = {}) {
|
|
2037
|
+
const { width, height } = options_;
|
|
2010
2038
|
const size = this.device.getExternalImageSize(options_.image);
|
|
2011
|
-
const options =
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
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);
|
|
2020
2050
|
return options;
|
|
2021
2051
|
}
|
|
2022
|
-
_normalizeCopyElementImageOptions(options_) {
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
options.width = Math.min(options.width,
|
|
2032
|
-
options.height = Math.min(options.height,
|
|
2033
|
-
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);
|
|
2034
2064
|
return options;
|
|
2035
2065
|
}
|
|
2036
|
-
_normalizeTextureReadOptions(options_) {
|
|
2037
|
-
const
|
|
2038
|
-
const
|
|
2039
|
-
const
|
|
2040
|
-
const
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
options.width = Math.min(options.width, mipLevelSize.width - options.x);
|
|
2046
|
-
options.height = Math.min(options.height, mipLevelSize.height - options.y);
|
|
2047
|
-
options.depthOrArrayLayers = Math.min(
|
|
2048
|
-
options.depthOrArrayLayers,
|
|
2049
|
-
mipLevelSize.depthOrArrayLayers - options.z
|
|
2050
|
-
);
|
|
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);
|
|
2051
2075
|
return options;
|
|
2052
2076
|
}
|
|
2053
2077
|
/**
|
|
@@ -2102,31 +2126,15 @@ var __exports__ = (() => {
|
|
|
2102
2126
|
throw new Error(`${this} color readback does not support format ${this.format}`);
|
|
2103
2127
|
}
|
|
2104
2128
|
}
|
|
2105
|
-
_normalizeTextureWriteOptions(options_) {
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2108
|
-
const
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
options.width = Math.min(options.width, mipLevelSize.width - options.x);
|
|
2115
|
-
options.height = Math.min(options.height, mipLevelSize.height - options.y);
|
|
2116
|
-
options.depthOrArrayLayers = Math.min(
|
|
2117
|
-
options.depthOrArrayLayers,
|
|
2118
|
-
mipLevelSize.depthOrArrayLayers - options.z
|
|
2119
|
-
);
|
|
2120
|
-
const layout = textureFormatDecoder.computeMemoryLayout({
|
|
2121
|
-
format: this.format,
|
|
2122
|
-
width: options.width,
|
|
2123
|
-
height: options.height,
|
|
2124
|
-
depth: options.depthOrArrayLayers,
|
|
2125
|
-
byteAlignment: this.byteAlignment
|
|
2126
|
-
});
|
|
2127
|
-
const minimumBytesPerRow = layout.bytesPerPixel * options.width;
|
|
2128
|
-
options.bytesPerRow = optionsWithoutUndefined.bytesPerRow ?? layout.bytesPerRow;
|
|
2129
|
-
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;
|
|
2130
2138
|
if (options.bytesPerRow < minimumBytesPerRow) {
|
|
2131
2139
|
throw new Error(
|
|
2132
2140
|
`bytesPerRow (${options.bytesPerRow}) must be at least ${minimumBytesPerRow} for ${this.format}`
|
|
@@ -2137,7 +2145,7 @@ var __exports__ = (() => {
|
|
|
2137
2145
|
`rowsPerImage (${options.rowsPerImage}) must be at least ${options.height} for ${this.format}`
|
|
2138
2146
|
);
|
|
2139
2147
|
}
|
|
2140
|
-
const bytesPerPixel =
|
|
2148
|
+
const { bytesPerPixel } = formatInfo;
|
|
2141
2149
|
if (bytesPerPixel && options.bytesPerRow % bytesPerPixel !== 0) {
|
|
2142
2150
|
throw new Error(
|
|
2143
2151
|
`bytesPerRow (${options.bytesPerRow}) must be a multiple of bytesPerPixel (${bytesPerPixel}) for ${this.format}`
|
|
@@ -2165,10 +2173,12 @@ var __exports__ = (() => {
|
|
|
2165
2173
|
}
|
|
2166
2174
|
return allocatedByteLength * this.samples;
|
|
2167
2175
|
}
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
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;
|
|
2172
2182
|
}
|
|
2173
2183
|
static defaultProps = {
|
|
2174
2184
|
...Resource.defaultProps,
|
|
@@ -2245,19 +2255,6 @@ var __exports__ = (() => {
|
|
|
2245
2255
|
mipLevel: 0,
|
|
2246
2256
|
aspect: "all"
|
|
2247
2257
|
};
|
|
2248
|
-
static defaultTextureWriteOptions = {
|
|
2249
|
-
byteOffset: 0,
|
|
2250
|
-
bytesPerRow: void 0,
|
|
2251
|
-
rowsPerImage: void 0,
|
|
2252
|
-
x: 0,
|
|
2253
|
-
y: 0,
|
|
2254
|
-
z: 0,
|
|
2255
|
-
width: void 0,
|
|
2256
|
-
height: void 0,
|
|
2257
|
-
depthOrArrayLayers: 1,
|
|
2258
|
-
mipLevel: 0,
|
|
2259
|
-
aspect: "all"
|
|
2260
|
-
};
|
|
2261
2258
|
};
|
|
2262
2259
|
|
|
2263
2260
|
// ../core/src/dynamic/dynamic-buffer/dynamic-buffer.ts
|
|
@@ -5253,6 +5250,15 @@ var __exports__ = (() => {
|
|
|
5253
5250
|
validateGraphBufferDescriptor(descriptor, this.device);
|
|
5254
5251
|
return this.addBuffer(new GraphBufferHandle(this, descriptor, true));
|
|
5255
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
|
+
}
|
|
5256
5262
|
/**
|
|
5257
5263
|
* Creates one typed range over a graph buffer.
|
|
5258
5264
|
*
|
|
@@ -6674,7 +6680,7 @@ var __exports__ = (() => {
|
|
|
6674
6680
|
};
|
|
6675
6681
|
|
|
6676
6682
|
// src/gpu-core/compiled-gpu-graph.ts
|
|
6677
|
-
var
|
|
6683
|
+
var import_core25 = __toESM(require_core(), 1);
|
|
6678
6684
|
|
|
6679
6685
|
// src/gpu-core/gpu-texture-plan.ts
|
|
6680
6686
|
var import_core10 = __toESM(require_core(), 1);
|
|
@@ -8667,6 +8673,16 @@ ${countBinding}
|
|
|
8667
8673
|
const arena = getGPUValueArena(graph);
|
|
8668
8674
|
return new GPUScalar(arena, arena.allocate(id, format));
|
|
8669
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
|
+
}
|
|
8670
8686
|
function getGPUScalarWGSLLoad(scalar, arenaExpression = "gpuValues") {
|
|
8671
8687
|
const word = `${arenaExpression}[${scalar.wordOffset}u]`;
|
|
8672
8688
|
switch (scalar.format) {
|
|
@@ -10931,7 +10947,76 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
10931
10947
|
}
|
|
10932
10948
|
|
|
10933
10949
|
// src/gpu-core/gpu-expression-plan.ts
|
|
10950
|
+
var import_core20 = __toESM(require_core(), 1);
|
|
10951
|
+
|
|
10952
|
+
// src/gpu-core/gpu-shader-pass-operation.ts
|
|
10934
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
|
+
};
|
|
10935
11020
|
|
|
10936
11021
|
// ../../node_modules/@math.gl/core/dist/expressions/vendor/jsep/runtime.js
|
|
10937
11022
|
var Hooks = class {
|
|
@@ -12142,6 +12227,9 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12142
12227
|
operation.operations.forEach(flatten);
|
|
12143
12228
|
else {
|
|
12144
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");
|
|
12145
12233
|
const containsExpression = (child) => child instanceof GPUExpressionOperation || child instanceof GPUCompositeOperation && child.operations.some(containsExpression);
|
|
12146
12234
|
if (operation.operations.some(containsExpression))
|
|
12147
12235
|
throw new Error("Expression operations inside control flow are not supported");
|
|
@@ -12273,7 +12361,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12273
12361
|
const declarations = [...this.scalars, ...this.vectors, ...this.textures];
|
|
12274
12362
|
const explicit = declarations.some((value) => value.role === "input" || value.role === "state");
|
|
12275
12363
|
const grouped = explicit || Object.values(supplied).some(
|
|
12276
|
-
(value) => value !== void 0 && typeof value === "object" && !(value instanceof GPUVector) && !(value instanceof CPUVector) && !(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)
|
|
12277
12365
|
);
|
|
12278
12366
|
if (!grouped) {
|
|
12279
12367
|
for (const name of Object.keys(supplied))
|
|
@@ -12548,7 +12636,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12548
12636
|
const outputs = /* @__PURE__ */ Object.create(null);
|
|
12549
12637
|
for (const name of this.program.outputs) {
|
|
12550
12638
|
const value = this.textures?.values.get(name) ?? this.values.get(name);
|
|
12551
|
-
if (!(value instanceof GPUVector || value instanceof
|
|
12639
|
+
if (!(value instanceof GPUVector || value instanceof import_core20.Texture || value instanceof import_core20.TextureView))
|
|
12552
12640
|
throw new Error(`Output ${name} has no materialized resource`);
|
|
12553
12641
|
outputs[name] = value;
|
|
12554
12642
|
}
|
|
@@ -12576,7 +12664,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12576
12664
|
new GPUData({
|
|
12577
12665
|
buffer: device.createBuffer({
|
|
12578
12666
|
byteLength: Math.max(1, length) * getGPUExpressionRowInfo(format).components * 4,
|
|
12579
|
-
usage:
|
|
12667
|
+
usage: import_core20.Buffer.STORAGE | import_core20.Buffer.VERTEX | import_core20.Buffer.COPY_SRC | import_core20.Buffer.COPY_DST
|
|
12580
12668
|
}),
|
|
12581
12669
|
format,
|
|
12582
12670
|
length,
|
|
@@ -12603,7 +12691,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12603
12691
|
}
|
|
12604
12692
|
}
|
|
12605
12693
|
function validateWritableTarget(name, target, values) {
|
|
12606
|
-
const getBuffer = (chunk) => chunk.buffer instanceof
|
|
12694
|
+
const getBuffer = (chunk) => chunk.buffer instanceof import_core20.Buffer ? chunk.buffer : chunk.buffer.buffer;
|
|
12607
12695
|
const ranges = /* @__PURE__ */ new Map();
|
|
12608
12696
|
for (const chunk of target.data) {
|
|
12609
12697
|
if (chunk.length === 0) continue;
|
|
@@ -12627,7 +12715,7 @@ ${cooperative ? `var<workgroup> scratch: array<f32, ${workgroupSize}>;` : ""}
|
|
|
12627
12715
|
}
|
|
12628
12716
|
|
|
12629
12717
|
// src/gpu-core/gpu-expression-kernel.ts
|
|
12630
|
-
var
|
|
12718
|
+
var import_core21 = __toESM(require_core(), 1);
|
|
12631
12719
|
|
|
12632
12720
|
// src/gpu-core/gpu-expression-cast.ts
|
|
12633
12721
|
var GPU_EXPRESSION_SHADER_TYPES = { float32: "f32", sint32: "i32", uint32: "u32" };
|
|
@@ -12850,7 +12938,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12850
12938
|
getViewElementOffset(output),
|
|
12851
12939
|
...inputs.map(getViewElementOffset)
|
|
12852
12940
|
]);
|
|
12853
|
-
const metadataBuffer = device.createBuffer({ data, usage:
|
|
12941
|
+
const metadataBuffer = device.createBuffer({ data, usage: import_core21.Buffer.UNIFORM });
|
|
12854
12942
|
return {
|
|
12855
12943
|
encode: ({ computePass, getBuffer }) => {
|
|
12856
12944
|
const bindings = { metadata: metadataBuffer };
|
|
@@ -12882,6 +12970,404 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12882
12970
|
}
|
|
12883
12971
|
};
|
|
12884
12972
|
|
|
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;
|
|
12984
|
+
try {
|
|
12985
|
+
kernel = new _RenderKernel(device, props);
|
|
12986
|
+
} finally {
|
|
12987
|
+
if (ownsCompilation) import_core22.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
12988
|
+
}
|
|
12989
|
+
try {
|
|
12990
|
+
if (ownsCompilation) {
|
|
12991
|
+
await Promise.all(asyncCompilation);
|
|
12992
|
+
} else {
|
|
12993
|
+
await kernel._pipelineInitialization;
|
|
12994
|
+
}
|
|
12995
|
+
return kernel;
|
|
12996
|
+
} catch (error) {
|
|
12997
|
+
kernel.destroy();
|
|
12998
|
+
throw error;
|
|
12999
|
+
}
|
|
13000
|
+
}
|
|
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
|
+
|
|
12885
13371
|
// src/gpu-core/gpu-cpu-operation.ts
|
|
12886
13372
|
var GPUCPUOperation = class {
|
|
12887
13373
|
type = "cpu";
|
|
@@ -12917,17 +13403,17 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12917
13403
|
};
|
|
12918
13404
|
|
|
12919
13405
|
// src/gpu-core/gpu-cpu-execution.ts
|
|
12920
|
-
var
|
|
13406
|
+
var import_core24 = __toESM(require_core(), 1);
|
|
12921
13407
|
var GPUCPUExecution = class {
|
|
12922
13408
|
constructor(device, program, compileStage) {
|
|
12923
13409
|
this.device = device;
|
|
12924
13410
|
this.program = program;
|
|
12925
13411
|
this.compileStage = compileStage;
|
|
12926
|
-
(0,
|
|
13412
|
+
(0, import_core24.assert)(!program.textures.length && !program.vectors.some((value) => value.role === "state"));
|
|
12927
13413
|
const declarations = [...program.scalars, ...program.vectors];
|
|
12928
13414
|
const addInput = (graph, name) => {
|
|
12929
13415
|
const declaration = declarations.find((value) => value.id === name);
|
|
12930
|
-
(0,
|
|
13416
|
+
(0, import_core24.assert)(declaration);
|
|
12931
13417
|
const vector = program.vectors.find((value) => value.id === name);
|
|
12932
13418
|
if (vector)
|
|
12933
13419
|
graph.addInput(
|
|
@@ -12949,7 +13435,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12949
13435
|
this.stages.push(operation);
|
|
12950
13436
|
continue;
|
|
12951
13437
|
}
|
|
12952
|
-
(0,
|
|
13438
|
+
(0, import_core24.assert)("contract" in operation && operation.contract);
|
|
12953
13439
|
const inputs = operation.contract.values.filter((use) => use.access !== "write").map((use) => typeof use.value === "string" ? use.value : use.value.id);
|
|
12954
13440
|
const outputs = operation.contract.values.filter((use) => use.access !== "read").map((use) => typeof use.value === "string" ? use.value : use.value.id);
|
|
12955
13441
|
const graph = new GPUGraph();
|
|
@@ -12983,13 +13469,13 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
12983
13469
|
stages = [];
|
|
12984
13470
|
async run(bindings, locations = {}) {
|
|
12985
13471
|
for (const [name, location] of Object.entries(locations))
|
|
12986
|
-
(0,
|
|
13472
|
+
(0, import_core24.assert)(this.program.outputs.includes(name) && (location === "cpu" || location === "gpu"));
|
|
12987
13473
|
const cpu = /* @__PURE__ */ new Map();
|
|
12988
13474
|
for (const declaration of [...this.program.vectors, ...this.program.scalars].filter(
|
|
12989
13475
|
(value) => value.role === "input"
|
|
12990
13476
|
)) {
|
|
12991
13477
|
const value = bindings[declaration.id];
|
|
12992
|
-
(0,
|
|
13478
|
+
(0, import_core24.assert)(value !== void 0);
|
|
12993
13479
|
if (!(value instanceof CPUVector)) {
|
|
12994
13480
|
const graph = new GPUGraph();
|
|
12995
13481
|
const vector = this.program.vectors.find((vector2) => vector2.id === declaration.id);
|
|
@@ -13011,11 +13497,11 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13011
13497
|
new GPUExpressionProgram(graph, { outputs: [] }).prepare(this.device, { [declaration.id]: value }).finish();
|
|
13012
13498
|
}
|
|
13013
13499
|
if (value instanceof CPUVector) {
|
|
13014
|
-
(0,
|
|
13015
|
-
(0,
|
|
13500
|
+
(0, import_core24.assert)(value.data.every((chunk) => !chunk.nullBitmap && !chunk.valueOffsets));
|
|
13501
|
+
(0, import_core24.assert)(value.format === declaration.format);
|
|
13016
13502
|
const vector = this.program.vectors.find((vector2) => vector2.id === declaration.id);
|
|
13017
|
-
(0,
|
|
13018
|
-
(0,
|
|
13503
|
+
(0, import_core24.assert)(vector && (vector.length === void 0 || vector.length === value.length));
|
|
13504
|
+
(0, import_core24.assert)(
|
|
13019
13505
|
!vector.chunkLengths || vector.chunkLengths.length === value.data.length && vector.chunkLengths.every((length, index) => length === value.data[index].length)
|
|
13020
13506
|
);
|
|
13021
13507
|
cpu.set(declaration.id, value);
|
|
@@ -13027,7 +13513,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13027
13513
|
let value = cpu.get(name);
|
|
13028
13514
|
if (!value) {
|
|
13029
13515
|
const gpu = values[name];
|
|
13030
|
-
(0,
|
|
13516
|
+
(0, import_core24.assert)(gpu instanceof GPUVector);
|
|
13031
13517
|
const read = await readCPUVector(gpu);
|
|
13032
13518
|
value = makeCPUVector(
|
|
13033
13519
|
read.format,
|
|
@@ -13070,11 +13556,11 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13070
13556
|
inputs[localName] = typeof cpuValue !== "number" && this.program.scalars.some((scalar) => scalar.id === name) ? cpuValue.pack()[0] : cpuValue;
|
|
13071
13557
|
}
|
|
13072
13558
|
const outputs2 = await stage.execute({ inputs });
|
|
13073
|
-
(0,
|
|
13559
|
+
(0, import_core24.assert)(Object.keys(outputs2).length === Object.keys(stage.outputs).length);
|
|
13074
13560
|
for (const name of Object.keys(stage.outputs)) {
|
|
13075
13561
|
const descriptor = this.program.vectors.find((vector) => vector.id === name);
|
|
13076
13562
|
const result = outputs2[name];
|
|
13077
|
-
(0,
|
|
13563
|
+
(0, import_core24.assert)(result);
|
|
13078
13564
|
const arrays = "chunks" in result ? result.chunks.map((chunk) => chunk.values) : [result];
|
|
13079
13565
|
const upload = new GPUUploadOperation({
|
|
13080
13566
|
output: name,
|
|
@@ -13082,8 +13568,8 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13082
13568
|
data: arrays
|
|
13083
13569
|
});
|
|
13084
13570
|
const length = upload.chunkLengths.reduce((total, count) => total + count, 0);
|
|
13085
|
-
(0,
|
|
13086
|
-
(0,
|
|
13571
|
+
(0, import_core24.assert)(descriptor.length === void 0 || descriptor.length === length);
|
|
13572
|
+
(0, import_core24.assert)(
|
|
13087
13573
|
!descriptor.chunkLengths || descriptor.chunkLengths.length === arrays.length && descriptor.chunkLengths.every(
|
|
13088
13574
|
(count, index) => count === upload.chunkLengths[index]
|
|
13089
13575
|
)
|
|
@@ -13125,7 +13611,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13125
13611
|
}
|
|
13126
13612
|
};
|
|
13127
13613
|
async function readCPUVector(vector) {
|
|
13128
|
-
(0,
|
|
13614
|
+
(0, import_core24.assert)(vector.format);
|
|
13129
13615
|
const info = getGPUVectorFormatInfo(vector.format);
|
|
13130
13616
|
const ValueType = info.signedDataType === "float32" ? Float32Array : info.signedDataType === "uint32" ? Uint32Array : Int32Array;
|
|
13131
13617
|
const chunks = [];
|
|
@@ -13169,7 +13655,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13169
13655
|
}
|
|
13170
13656
|
function getCPUView(vector) {
|
|
13171
13657
|
const format = vector.format;
|
|
13172
|
-
(0,
|
|
13658
|
+
(0, import_core24.assert)(/^(float32|sint32|uint32)(x[234])?$/.test(format));
|
|
13173
13659
|
const info = getGPUVectorFormatInfo(format);
|
|
13174
13660
|
const ValueType = info.signedDataType === "float32" ? Float32Array : info.signedDataType === "uint32" ? Uint32Array : Int32Array;
|
|
13175
13661
|
const chunks = vector.data.map((chunk) => {
|
|
@@ -13208,6 +13694,10 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13208
13694
|
this.stageLowerings = lowerings ?? options.lowerings ?? [];
|
|
13209
13695
|
this.compiler = new GPUGraphCompiler(device, [
|
|
13210
13696
|
...lowerings ?? options.lowerings ?? [],
|
|
13697
|
+
{
|
|
13698
|
+
type: "shader-pass",
|
|
13699
|
+
lower: (operation, context) => this.shaderPasses.get(operation).lower(context)
|
|
13700
|
+
},
|
|
13211
13701
|
{
|
|
13212
13702
|
type: "expression",
|
|
13213
13703
|
lower: (operation, context) => this.kernels.get(operation).lower(context)
|
|
@@ -13224,6 +13714,12 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13224
13714
|
try {
|
|
13225
13715
|
for (const plan of this.program.expressions)
|
|
13226
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
|
+
);
|
|
13227
13723
|
} catch (error) {
|
|
13228
13724
|
this.destroy();
|
|
13229
13725
|
throw error;
|
|
@@ -13234,12 +13730,13 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13234
13730
|
stageLowerings;
|
|
13235
13731
|
compiler;
|
|
13236
13732
|
kernels = /* @__PURE__ */ new Map();
|
|
13733
|
+
shaderPasses = /* @__PURE__ */ new Map();
|
|
13237
13734
|
destroyed = false;
|
|
13238
13735
|
runningCPU = false;
|
|
13239
13736
|
cpuExecution;
|
|
13240
13737
|
outputLocations;
|
|
13241
13738
|
async run(supplied, options = {}) {
|
|
13242
|
-
(0,
|
|
13739
|
+
(0, import_core25.assert)(!this.destroyed && !this.runningCPU);
|
|
13243
13740
|
const suppliedInputs = "inputs" in supplied ? supplied.inputs : supplied;
|
|
13244
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);
|
|
13245
13742
|
if (!this.cpuExecution && useCPU)
|
|
@@ -13250,7 +13747,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13250
13747
|
);
|
|
13251
13748
|
if (useCPU && this.cpuExecution) {
|
|
13252
13749
|
const resolved = this.program.resolveBindings(supplied, options);
|
|
13253
|
-
(0,
|
|
13750
|
+
(0, import_core25.assert)(
|
|
13254
13751
|
!resolved.options.outputTargets || Object.keys(resolved.options.outputTargets).length === 0
|
|
13255
13752
|
);
|
|
13256
13753
|
this.runningCPU = true;
|
|
@@ -13277,7 +13774,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13277
13774
|
}
|
|
13278
13775
|
/** Bind one invocation without encoding or submitting commands. */
|
|
13279
13776
|
prepare(supplied, options = {}) {
|
|
13280
|
-
(0,
|
|
13777
|
+
(0, import_core25.assert)(!this.destroyed);
|
|
13281
13778
|
if (this.program.operations.some((operation) => operation instanceof GPUCPUOperation) || Object.values(this.outputLocations).includes("cpu"))
|
|
13282
13779
|
throw new Error("CPU operations require asynchronous run(), not prepare()");
|
|
13283
13780
|
const resolvedBindings = this.program.resolveBindings(supplied, options);
|
|
@@ -13286,6 +13783,8 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13286
13783
|
const invocation = this.program.prepare(this.device, bindings, options, true);
|
|
13287
13784
|
let executable;
|
|
13288
13785
|
try {
|
|
13786
|
+
for (const kernel of this.shaderPasses.values())
|
|
13787
|
+
kernel.validateTextures(invocation.textures.values);
|
|
13289
13788
|
const resolved = new GPUGraph();
|
|
13290
13789
|
for (const scalar of this.program.scalars) resolved.scalar(scalar.id, scalar.format);
|
|
13291
13790
|
const vectors = /* @__PURE__ */ Object.create(null);
|
|
@@ -13363,7 +13862,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13363
13862
|
}
|
|
13364
13863
|
executable = compilation.graph.compile();
|
|
13365
13864
|
return new PreparedGPUGraphExecution(this.device, invocation, executable, () => {
|
|
13366
|
-
(0,
|
|
13865
|
+
(0, import_core25.assert)(!this.destroyed);
|
|
13367
13866
|
});
|
|
13368
13867
|
} catch (error) {
|
|
13369
13868
|
executable?.destroy();
|
|
@@ -13372,8 +13871,10 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13372
13871
|
}
|
|
13373
13872
|
}
|
|
13374
13873
|
destroy() {
|
|
13375
|
-
(0,
|
|
13874
|
+
(0, import_core25.assert)(!this.runningCPU);
|
|
13376
13875
|
this.cpuExecution?.destroy();
|
|
13876
|
+
for (const kernel of this.shaderPasses.values()) kernel.destroy();
|
|
13877
|
+
this.shaderPasses.clear();
|
|
13377
13878
|
for (const kernel of this.kernels.values()) kernel.destroy();
|
|
13378
13879
|
this.kernels.clear();
|
|
13379
13880
|
this.destroyed = true;
|
|
@@ -13397,7 +13898,7 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
13397
13898
|
destroyed = false;
|
|
13398
13899
|
/** Append commands once to a caller-owned encoder; never finish or submit it. */
|
|
13399
13900
|
encode(commandEncoder) {
|
|
13400
|
-
(0,
|
|
13901
|
+
(0, import_core25.assert)(!this.destroyed && !this.encoded && commandEncoder.device === this.device);
|
|
13401
13902
|
this.checkProgram();
|
|
13402
13903
|
this.encoded = true;
|
|
13403
13904
|
this.executable.encode(commandEncoder, { parameters: void 0 });
|
|
@@ -14279,143 +14780,8 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
14279
14780
|
};
|
|
14280
14781
|
}
|
|
14281
14782
|
|
|
14282
|
-
// src/execution/compute/render-kernel.ts
|
|
14283
|
-
var import_core23 = __toESM(require_core(), 1);
|
|
14284
|
-
var RenderKernel = class _RenderKernel {
|
|
14285
|
-
/** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
|
|
14286
|
-
static async createAsync(device, props) {
|
|
14287
|
-
const ownsCompilation = !import_core23.PipelineFactory.getAsyncCompilation(device);
|
|
14288
|
-
const asyncCompilation = ownsCompilation ? import_core23.PipelineFactory.beginAsyncCompilation(device) : import_core23.PipelineFactory.getAsyncCompilation(device);
|
|
14289
|
-
let kernel;
|
|
14290
|
-
try {
|
|
14291
|
-
kernel = new _RenderKernel(device, props);
|
|
14292
|
-
} finally {
|
|
14293
|
-
if (ownsCompilation) import_core23.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
14294
|
-
}
|
|
14295
|
-
try {
|
|
14296
|
-
if (ownsCompilation) {
|
|
14297
|
-
await Promise.all(asyncCompilation);
|
|
14298
|
-
} else {
|
|
14299
|
-
await kernel._pipelineInitialization;
|
|
14300
|
-
}
|
|
14301
|
-
return kernel;
|
|
14302
|
-
} catch (error) {
|
|
14303
|
-
kernel.destroy();
|
|
14304
|
-
throw error;
|
|
14305
|
-
}
|
|
14306
|
-
}
|
|
14307
|
-
device;
|
|
14308
|
-
id;
|
|
14309
|
-
vertexSource;
|
|
14310
|
-
fragmentSource;
|
|
14311
|
-
pipelineFactory;
|
|
14312
|
-
shaderFactory;
|
|
14313
|
-
vertexShader;
|
|
14314
|
-
fragmentShader;
|
|
14315
|
-
pipeline;
|
|
14316
|
-
_pipelineInitialization;
|
|
14317
|
-
_destroyed = false;
|
|
14318
|
-
drawDefaults;
|
|
14319
|
-
constructor(device, props) {
|
|
14320
|
-
if (device.type !== "webgpu" && device.type !== "webgl") {
|
|
14321
|
-
throw new Error("RenderKernel requires WebGL or WebGPU");
|
|
14322
|
-
}
|
|
14323
|
-
if (device.type === "webgl" && !props.fragmentSource) {
|
|
14324
|
-
throw new Error("WebGL RenderKernel requires a fragment shader");
|
|
14325
|
-
}
|
|
14326
|
-
const {
|
|
14327
|
-
vertexSource,
|
|
14328
|
-
fragmentSource,
|
|
14329
|
-
pipelineFactory,
|
|
14330
|
-
shaderFactory,
|
|
14331
|
-
debugShaders,
|
|
14332
|
-
...pipelineProps
|
|
14333
|
-
} = props;
|
|
14334
|
-
this.device = device;
|
|
14335
|
-
this.drawDefaults = {
|
|
14336
|
-
parameters: props.parameters ?? {},
|
|
14337
|
-
topology: props.topology ?? "triangle-list"
|
|
14338
|
-
};
|
|
14339
|
-
this.id = props.id ?? "render-kernel";
|
|
14340
|
-
this.vertexSource = vertexSource;
|
|
14341
|
-
this.fragmentSource = fragmentSource;
|
|
14342
|
-
this.pipelineFactory = pipelineFactory ?? import_core23.PipelineFactory.getDefaultPipelineFactory(device);
|
|
14343
|
-
this.shaderFactory = shaderFactory ?? import_core23.ShaderFactory.getDefaultShaderFactory(device);
|
|
14344
|
-
this.vertexShader = this.shaderFactory.createShader({
|
|
14345
|
-
id: `${this.id}-vertex`,
|
|
14346
|
-
stage: "vertex",
|
|
14347
|
-
source: this.vertexSource,
|
|
14348
|
-
debugShaders
|
|
14349
|
-
});
|
|
14350
|
-
this.fragmentShader = this.fragmentSource ? this.shaderFactory.createShader({
|
|
14351
|
-
id: `${this.id}-fragment`,
|
|
14352
|
-
stage: "fragment",
|
|
14353
|
-
source: this.fragmentSource,
|
|
14354
|
-
debugShaders
|
|
14355
|
-
}) : null;
|
|
14356
|
-
const renderPipelineProps = {
|
|
14357
|
-
...pipelineProps,
|
|
14358
|
-
vs: this.vertexShader,
|
|
14359
|
-
fs: this.fragmentShader
|
|
14360
|
-
};
|
|
14361
|
-
const asyncCompilation = import_core23.PipelineFactory.getAsyncCompilation(device);
|
|
14362
|
-
if (asyncCompilation) {
|
|
14363
|
-
const pipelineInitialization = this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
|
|
14364
|
-
this._pipelineInitialization = pipelineInitialization;
|
|
14365
|
-
asyncCompilation.push(
|
|
14366
|
-
pipelineInitialization.then((pipeline) => {
|
|
14367
|
-
this.pipeline = pipeline;
|
|
14368
|
-
return pipeline;
|
|
14369
|
-
})
|
|
14370
|
-
);
|
|
14371
|
-
} else {
|
|
14372
|
-
this.pipeline = this.pipelineFactory.createRenderPipeline(renderPipelineProps);
|
|
14373
|
-
}
|
|
14374
|
-
}
|
|
14375
|
-
/** Applies per-draw bindings/vertex state and records a direct draw. */
|
|
14376
|
-
draw(renderPass, options) {
|
|
14377
|
-
const { bindings = {}, vertexArray, ...drawOptions } = options;
|
|
14378
|
-
this._setPipeline(renderPass, bindings, vertexArray);
|
|
14379
|
-
return renderPass.draw(
|
|
14380
|
-
this.device.type === "webgl" ? {
|
|
14381
|
-
...this.drawDefaults,
|
|
14382
|
-
...drawOptions,
|
|
14383
|
-
isInstanced: drawOptions.isInstanced ?? drawOptions.instanceCount !== void 0
|
|
14384
|
-
} : drawOptions
|
|
14385
|
-
);
|
|
14386
|
-
}
|
|
14387
|
-
/** Applies per-draw state and records a non-indexed indirect draw. */
|
|
14388
|
-
drawIndirect(renderPass, options) {
|
|
14389
|
-
if (this.device.type !== "webgpu")
|
|
14390
|
-
throw new Error("Indirect drawing is only supported in WebGPU");
|
|
14391
|
-
const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
|
|
14392
|
-
this._setPipeline(renderPass, bindings, vertexArray);
|
|
14393
|
-
renderPass.drawIndirect(indirectBuffer, indirectOffset);
|
|
14394
|
-
}
|
|
14395
|
-
/** Applies per-draw state and records an indexed indirect draw. */
|
|
14396
|
-
drawIndexedIndirect(renderPass, options) {
|
|
14397
|
-
if (this.device.type !== "webgpu")
|
|
14398
|
-
throw new Error("Indirect drawing is only supported in WebGPU");
|
|
14399
|
-
const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
|
|
14400
|
-
this._setPipeline(renderPass, bindings, vertexArray);
|
|
14401
|
-
renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
|
|
14402
|
-
}
|
|
14403
|
-
destroy() {
|
|
14404
|
-
if (this._destroyed) return;
|
|
14405
|
-
if (this.pipeline) this.pipelineFactory.release(this.pipeline);
|
|
14406
|
-
this.shaderFactory.release(this.vertexShader);
|
|
14407
|
-
if (this.fragmentShader) this.shaderFactory.release(this.fragmentShader);
|
|
14408
|
-
this._destroyed = true;
|
|
14409
|
-
}
|
|
14410
|
-
_setPipeline(renderPass, bindings, vertexArray) {
|
|
14411
|
-
renderPass.setPipeline(this.pipeline);
|
|
14412
|
-
renderPass.setBindings(bindings);
|
|
14413
|
-
renderPass.setVertexArray(vertexArray);
|
|
14414
|
-
}
|
|
14415
|
-
};
|
|
14416
|
-
|
|
14417
14783
|
// src/gpu-core/gpu-compaction-operation.ts
|
|
14418
|
-
var
|
|
14784
|
+
var import_core26 = __toESM(require_core(), 1);
|
|
14419
14785
|
var GPUCompactionOperation = class {
|
|
14420
14786
|
type = "compaction";
|
|
14421
14787
|
id;
|
|
@@ -14430,9 +14796,9 @@ fn main(@builtin(workgroup_id) workgroup: vec3u, @builtin(num_workgroups) dimens
|
|
|
14430
14796
|
outputs: ({ getValue }) => {
|
|
14431
14797
|
for (const name of [input, flags]) {
|
|
14432
14798
|
const value = getValue(name);
|
|
14433
|
-
(0,
|
|
14799
|
+
(0, import_core26.assert)(value.type === "vector" && value.format === "uint32");
|
|
14434
14800
|
}
|
|
14435
|
-
(0,
|
|
14801
|
+
(0, import_core26.assert)(output !== count);
|
|
14436
14802
|
return { [output]: gpuGraph.vector("uint32"), [count]: gpuGraph.scalar("uint32") };
|
|
14437
14803
|
},
|
|
14438
14804
|
values: [
|