@luma.gl/engine 9.4.0 → 10.0.0-alpha.1
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/animation-loop/animation-loop.d.ts +12 -5
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +22 -7
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/animation-props.d.ts +3 -1
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +3 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/compute/computation.d.ts +12 -0
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +85 -22
- package/dist/compute/computation.js.map +1 -1
- package/dist/compute/kernel.d.ts +54 -0
- package/dist/compute/kernel.d.ts.map +1 -0
- package/dist/compute/kernel.js +103 -0
- package/dist/compute/kernel.js.map +1 -0
- package/dist/compute/render-kernel.d.ts +65 -0
- package/dist/compute/render-kernel.d.ts.map +1 -0
- package/dist/compute/render-kernel.js +129 -0
- package/dist/compute/render-kernel.js.map +1 -0
- package/dist/controls/orbit-controls.d.ts +9 -2
- package/dist/controls/orbit-controls.d.ts.map +1 -1
- package/dist/controls/orbit-controls.js +55 -8
- package/dist/controls/orbit-controls.js.map +1 -1
- package/dist/dist.dev.js +502 -134
- package/dist/dist.min.js +23 -23
- package/dist/index.cjs +504 -117
- 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/dist/model/model.d.ts +13 -2
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +137 -66
- package/dist/model/model.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +12 -12
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +17 -17
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/package.json +4 -4
- package/src/animation-loop/animation-loop.ts +36 -14
- package/src/animation-loop/animation-props.ts +4 -1
- package/src/animation-loop/make-animation-loop.ts +3 -1
- package/src/compute/computation.ts +83 -30
- package/src/compute/kernel.ts +146 -0
- package/src/compute/render-kernel.ts +192 -0
- package/src/controls/orbit-controls.ts +61 -9
- package/src/index.ts +12 -0
- package/src/model/model.ts +149 -87
- package/src/passes/shader-pass-renderer.ts +28 -25
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
Geometry: () => Geometry,
|
|
43
43
|
GroupNode: () => GroupNode,
|
|
44
44
|
IcoSphereGeometry: () => IcoSphereGeometry,
|
|
45
|
+
Kernel: () => Kernel,
|
|
45
46
|
KeyFrames: () => KeyFrames,
|
|
46
47
|
LegacyPickingManager: () => LegacyPickingManager,
|
|
47
48
|
Material: () => Material,
|
|
@@ -52,6 +53,7 @@ __export(index_exports, {
|
|
|
52
53
|
PickingManager: () => PickingManager,
|
|
53
54
|
PlaneGeometry: () => PlaneGeometry,
|
|
54
55
|
PointLightModel: () => PointLightModel,
|
|
56
|
+
RenderKernel: () => RenderKernel,
|
|
55
57
|
ScenegraphNode: () => ScenegraphNode,
|
|
56
58
|
ShaderInputs: () => ShaderInputs,
|
|
57
59
|
ShaderPassRenderer: () => ShaderPassRenderer,
|
|
@@ -1182,6 +1184,7 @@ var defaultAnimationFrameProvider = {
|
|
|
1182
1184
|
var AnimationLoop = class _AnimationLoop {
|
|
1183
1185
|
static defaultAnimationLoopProps = {
|
|
1184
1186
|
device: null,
|
|
1187
|
+
mobileQuality: void 0,
|
|
1185
1188
|
onAddHTML: () => "",
|
|
1186
1189
|
onInitialize: async () => null,
|
|
1187
1190
|
onRender: () => {
|
|
@@ -1251,8 +1254,11 @@ var AnimationLoop = class _AnimationLoop {
|
|
|
1251
1254
|
this.destroy();
|
|
1252
1255
|
}
|
|
1253
1256
|
reportError(error) {
|
|
1254
|
-
this.props.onError(error);
|
|
1255
1257
|
this._error = error;
|
|
1258
|
+
this.props.onError(error);
|
|
1259
|
+
if (this.props.onError === _AnimationLoop.defaultAnimationLoopProps.onError && typeof window !== "undefined" && typeof ErrorEvent !== "undefined") {
|
|
1260
|
+
window.dispatchEvent(new ErrorEvent("error", { error, message: error.message }));
|
|
1261
|
+
}
|
|
1256
1262
|
}
|
|
1257
1263
|
/** Flags this animation loop as needing redraw */
|
|
1258
1264
|
setNeedsRedraw(reason) {
|
|
@@ -1318,14 +1324,15 @@ var AnimationLoop = class _AnimationLoop {
|
|
|
1318
1324
|
/** Stops a render loop if already running, finalizing */
|
|
1319
1325
|
stop() {
|
|
1320
1326
|
if (this._running) {
|
|
1321
|
-
|
|
1322
|
-
this.props.onFinalize(this.animationProps);
|
|
1323
|
-
}
|
|
1327
|
+
const animationProps = this.animationProps;
|
|
1324
1328
|
this._cancelAnimationFrame();
|
|
1325
1329
|
this._nextFramePromise = null;
|
|
1326
1330
|
this._resolveNextFrame = null;
|
|
1327
1331
|
this._running = false;
|
|
1328
1332
|
this._lastFrameTime = 0;
|
|
1333
|
+
if (animationProps) {
|
|
1334
|
+
this.props.onFinalize(animationProps);
|
|
1335
|
+
}
|
|
1329
1336
|
}
|
|
1330
1337
|
return this;
|
|
1331
1338
|
}
|
|
@@ -1415,8 +1422,14 @@ var AnimationLoop = class _AnimationLoop {
|
|
|
1415
1422
|
if (!this._running) {
|
|
1416
1423
|
return;
|
|
1417
1424
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1425
|
+
try {
|
|
1426
|
+
this.redraw(time, animationFrame ?? null);
|
|
1427
|
+
this._requestAnimationFrame();
|
|
1428
|
+
} catch (error) {
|
|
1429
|
+
const renderError = error instanceof Error ? error : new Error(String(error));
|
|
1430
|
+
this.reportError(renderError);
|
|
1431
|
+
this.stop();
|
|
1432
|
+
}
|
|
1420
1433
|
}
|
|
1421
1434
|
// Called on each frame, can be overridden to call onRender multiple times
|
|
1422
1435
|
// to support e.g. stereoscopic rendering
|
|
@@ -1466,8 +1479,9 @@ var AnimationLoop = class _AnimationLoop {
|
|
|
1466
1479
|
tock: 0,
|
|
1467
1480
|
// Experimental
|
|
1468
1481
|
animationFrame: null,
|
|
1469
|
-
_mousePosition: null
|
|
1482
|
+
_mousePosition: null,
|
|
1470
1483
|
// Event props
|
|
1484
|
+
mobileQuality: this.props.mobileQuality
|
|
1471
1485
|
};
|
|
1472
1486
|
}
|
|
1473
1487
|
_getAnimationProps() {
|
|
@@ -1645,7 +1659,9 @@ function makeAnimationLoop(AnimationLoopTemplateCtor, props) {
|
|
|
1645
1659
|
} catch (error) {
|
|
1646
1660
|
console.error(error);
|
|
1647
1661
|
renderLoop = null;
|
|
1648
|
-
|
|
1662
|
+
const initializationError = error instanceof Error ? error : new Error(String(error));
|
|
1663
|
+
setError(animationProps.animationLoop.device, initializationError);
|
|
1664
|
+
animationProps.animationLoop.reportError(initializationError);
|
|
1649
1665
|
animationProps.animationLoop.stop();
|
|
1650
1666
|
return null;
|
|
1651
1667
|
}
|
|
@@ -1708,6 +1724,7 @@ var DEFAULT_PROPS = {
|
|
|
1708
1724
|
distance: 10,
|
|
1709
1725
|
yaw: 0,
|
|
1710
1726
|
pitch: 0.25,
|
|
1727
|
+
roll: 0,
|
|
1711
1728
|
minDistance: 1,
|
|
1712
1729
|
maxDistance: 100,
|
|
1713
1730
|
minPitch: -Math.PI / 2 + 0.01,
|
|
@@ -1715,6 +1732,7 @@ var DEFAULT_PROPS = {
|
|
|
1715
1732
|
rotateSpeed: 6e-3,
|
|
1716
1733
|
zoomSpeed: 1e-3,
|
|
1717
1734
|
enabled: true,
|
|
1735
|
+
enableRotate: false,
|
|
1718
1736
|
enableZoom: true,
|
|
1719
1737
|
enablePan: false,
|
|
1720
1738
|
panSpeed: 18e-4,
|
|
@@ -1726,11 +1744,13 @@ var OrbitControls = class {
|
|
|
1726
1744
|
props;
|
|
1727
1745
|
yaw;
|
|
1728
1746
|
pitch;
|
|
1747
|
+
roll;
|
|
1729
1748
|
distance;
|
|
1730
1749
|
dragging = false;
|
|
1731
1750
|
activePointers = /* @__PURE__ */ new Map();
|
|
1732
1751
|
lastPointer = [0, 0];
|
|
1733
1752
|
previousPinchDistance = null;
|
|
1753
|
+
previousPinchAngle = null;
|
|
1734
1754
|
previousTimeMilliseconds = null;
|
|
1735
1755
|
previousCursor;
|
|
1736
1756
|
previousTouchAction;
|
|
@@ -1740,6 +1760,7 @@ var OrbitControls = class {
|
|
|
1740
1760
|
this.props.target = [...this.props.target];
|
|
1741
1761
|
this.yaw = this.props.yaw;
|
|
1742
1762
|
this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
|
|
1763
|
+
this.roll = this.props.roll;
|
|
1743
1764
|
this.distance = clampNumber(this.props.distance, this.props.minDistance, this.props.maxDistance);
|
|
1744
1765
|
this.previousCursor = canvas.style.cursor;
|
|
1745
1766
|
this.previousTouchAction = canvas.style.touchAction;
|
|
@@ -1768,6 +1789,32 @@ var OrbitControls = class {
|
|
|
1768
1789
|
this.props.target[2] + horizontalDistance * Math.cos(this.yaw)
|
|
1769
1790
|
];
|
|
1770
1791
|
}
|
|
1792
|
+
/** Returns the camera up direction after applying pitch and optional two-finger roll. */
|
|
1793
|
+
getUpDirection() {
|
|
1794
|
+
return this.getCameraFrame().up;
|
|
1795
|
+
}
|
|
1796
|
+
getCameraFrame() {
|
|
1797
|
+
const sineYaw = Math.sin(this.yaw);
|
|
1798
|
+
const cosineYaw = Math.cos(this.yaw);
|
|
1799
|
+
const sinePitch = Math.sin(this.pitch);
|
|
1800
|
+
const cosinePitch = Math.cos(this.pitch);
|
|
1801
|
+
const sineRoll = Math.sin(this.roll);
|
|
1802
|
+
const cosineRoll = Math.cos(this.roll);
|
|
1803
|
+
const right = [cosineYaw, 0, -sineYaw];
|
|
1804
|
+
const up = [-sinePitch * sineYaw, cosinePitch, -sinePitch * cosineYaw];
|
|
1805
|
+
return {
|
|
1806
|
+
right: [
|
|
1807
|
+
right[0] * cosineRoll - up[0] * sineRoll,
|
|
1808
|
+
right[1] * cosineRoll - up[1] * sineRoll,
|
|
1809
|
+
right[2] * cosineRoll - up[2] * sineRoll
|
|
1810
|
+
],
|
|
1811
|
+
up: [
|
|
1812
|
+
up[0] * cosineRoll + right[0] * sineRoll,
|
|
1813
|
+
up[1] * cosineRoll + right[1] * sineRoll,
|
|
1814
|
+
up[2] * cosineRoll + right[2] * sineRoll
|
|
1815
|
+
]
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1771
1818
|
/** Enables or pauses automatic rotation without losing the current manual angle. */
|
|
1772
1819
|
setAutoRotate(autoRotate) {
|
|
1773
1820
|
this.props.autoRotate = autoRotate;
|
|
@@ -1787,14 +1834,18 @@ var OrbitControls = class {
|
|
|
1787
1834
|
if (props.pitch !== void 0 || props.minPitch !== void 0 || props.maxPitch !== void 0) {
|
|
1788
1835
|
this.pitch = clampNumber(props.pitch ?? this.pitch, this.props.minPitch, this.props.maxPitch);
|
|
1789
1836
|
}
|
|
1837
|
+
if (props.roll !== void 0) {
|
|
1838
|
+
this.roll = props.roll;
|
|
1839
|
+
}
|
|
1790
1840
|
if (props.distance !== void 0 || props.minDistance !== void 0 || props.maxDistance !== void 0) {
|
|
1791
1841
|
this.distance = clampNumber(props.distance ?? this.distance, this.props.minDistance, this.props.maxDistance);
|
|
1792
1842
|
}
|
|
1793
1843
|
}
|
|
1794
|
-
/** Restores the configured starting
|
|
1844
|
+
/** Restores the configured starting orbit, roll, and zoom. */
|
|
1795
1845
|
reset() {
|
|
1796
1846
|
this.yaw = this.props.yaw;
|
|
1797
1847
|
this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
|
|
1848
|
+
this.roll = this.props.roll;
|
|
1798
1849
|
this.distance = clampNumber(this.props.distance, this.props.minDistance, this.props.maxDistance);
|
|
1799
1850
|
}
|
|
1800
1851
|
destroy() {
|
|
@@ -1820,9 +1871,10 @@ var OrbitControls = class {
|
|
|
1820
1871
|
if (this.activePointers.size === 1) {
|
|
1821
1872
|
this.lastPointer = [event.clientX, event.clientY];
|
|
1822
1873
|
} else {
|
|
1823
|
-
const { center, distance } = this.getMultiPointerState();
|
|
1874
|
+
const { center, distance, angle } = this.getMultiPointerState();
|
|
1824
1875
|
this.lastPointer = center;
|
|
1825
1876
|
this.previousPinchDistance = distance;
|
|
1877
|
+
this.previousPinchAngle = distance > 0 ? angle : null;
|
|
1826
1878
|
}
|
|
1827
1879
|
this.canvas.setPointerCapture(event.pointerId);
|
|
1828
1880
|
this.canvas.style.cursor = "grabbing";
|
|
@@ -1833,15 +1885,19 @@ var OrbitControls = class {
|
|
|
1833
1885
|
}
|
|
1834
1886
|
this.activePointers.set(event.pointerId, [event.clientX, event.clientY]);
|
|
1835
1887
|
if (this.activePointers.size > 1) {
|
|
1836
|
-
const { center, distance } = this.getMultiPointerState();
|
|
1888
|
+
const { center, distance, angle } = this.getMultiPointerState();
|
|
1837
1889
|
if (this.props.enablePan) {
|
|
1838
1890
|
this.panTarget(center[0] - this.lastPointer[0], center[1] - this.lastPointer[1]);
|
|
1839
1891
|
}
|
|
1840
1892
|
if (this.props.enableZoom && this.previousPinchDistance && distance > 0) {
|
|
1841
1893
|
this.distance = clampNumber(this.distance * this.previousPinchDistance / distance, this.props.minDistance, this.props.maxDistance);
|
|
1842
1894
|
}
|
|
1895
|
+
if (this.props.enableRotate && this.previousPinchAngle !== null && distance > 0) {
|
|
1896
|
+
this.roll += normalizeAngleDelta(angle - this.previousPinchAngle);
|
|
1897
|
+
}
|
|
1843
1898
|
this.lastPointer = center;
|
|
1844
1899
|
this.previousPinchDistance = distance;
|
|
1900
|
+
this.previousPinchAngle = distance > 0 ? angle : null;
|
|
1845
1901
|
return;
|
|
1846
1902
|
}
|
|
1847
1903
|
const deltaX = event.clientX - this.lastPointer[0];
|
|
@@ -1863,6 +1919,7 @@ var OrbitControls = class {
|
|
|
1863
1919
|
}
|
|
1864
1920
|
this.activePointers.delete(event.pointerId);
|
|
1865
1921
|
this.previousPinchDistance = null;
|
|
1922
|
+
this.previousPinchAngle = null;
|
|
1866
1923
|
const remainingPointer = this.activePointers.entries().next().value;
|
|
1867
1924
|
if (remainingPointer) {
|
|
1868
1925
|
this.lastPointer = remainingPointer[1];
|
|
@@ -1879,6 +1936,7 @@ var OrbitControls = class {
|
|
|
1879
1936
|
}
|
|
1880
1937
|
this.activePointers.clear();
|
|
1881
1938
|
this.previousPinchDistance = null;
|
|
1939
|
+
this.previousPinchAngle = null;
|
|
1882
1940
|
this.canvas.style.cursor = "grab";
|
|
1883
1941
|
}
|
|
1884
1942
|
getMultiPointerState() {
|
|
@@ -1887,15 +1945,17 @@ var OrbitControls = class {
|
|
|
1887
1945
|
const deltaY = secondPointer[1] - firstPointer[1];
|
|
1888
1946
|
return {
|
|
1889
1947
|
center: [(firstPointer[0] + secondPointer[0]) / 2, (firstPointer[1] + secondPointer[1]) / 2],
|
|
1890
|
-
distance: Math.hypot(deltaX, deltaY)
|
|
1948
|
+
distance: Math.hypot(deltaX, deltaY),
|
|
1949
|
+
angle: Math.atan2(deltaY, deltaX)
|
|
1891
1950
|
};
|
|
1892
1951
|
}
|
|
1893
1952
|
panTarget(deltaX, deltaY) {
|
|
1894
1953
|
const panScale = this.distance * this.props.panSpeed;
|
|
1954
|
+
const { right, up } = this.getCameraFrame();
|
|
1895
1955
|
this.props.target = [
|
|
1896
|
-
this.props.target[0]
|
|
1897
|
-
this.props.target[1] + deltaY * panScale,
|
|
1898
|
-
this.props.target[2] +
|
|
1956
|
+
this.props.target[0] + (-right[0] * deltaX + up[0] * deltaY) * panScale,
|
|
1957
|
+
this.props.target[1] + (-right[1] * deltaX + up[1] * deltaY) * panScale,
|
|
1958
|
+
this.props.target[2] + (-right[2] * deltaX + up[2] * deltaY) * panScale
|
|
1899
1959
|
];
|
|
1900
1960
|
}
|
|
1901
1961
|
handleWheel = (event) => {
|
|
@@ -1912,6 +1972,9 @@ var OrbitControls = class {
|
|
|
1912
1972
|
function clampNumber(value, minimum, maximum) {
|
|
1913
1973
|
return Math.min(Math.max(value, minimum), maximum);
|
|
1914
1974
|
}
|
|
1975
|
+
function normalizeAngleDelta(angle) {
|
|
1976
|
+
return Math.atan2(Math.sin(angle), Math.cos(angle));
|
|
1977
|
+
}
|
|
1915
1978
|
|
|
1916
1979
|
// dist/model/model.js
|
|
1917
1980
|
var import_core13 = require("@luma.gl/core");
|
|
@@ -2866,6 +2929,29 @@ var DEPTH_STENCIL_ATTACHMENT_FORMATS = [
|
|
|
2866
2929
|
"depth32float-stencil8"
|
|
2867
2930
|
];
|
|
2868
2931
|
var Model = class _Model {
|
|
2932
|
+
/** Creates a model while allowing the backend to compile its render pipeline asynchronously. */
|
|
2933
|
+
static async createAsync(device, props) {
|
|
2934
|
+
const ownsCompilation = !import_core13.PipelineFactory.getAsyncCompilation(device);
|
|
2935
|
+
const asyncCompilation = ownsCompilation ? import_core13.PipelineFactory.beginAsyncCompilation(device) : import_core13.PipelineFactory.getAsyncCompilation(device);
|
|
2936
|
+
let model;
|
|
2937
|
+
try {
|
|
2938
|
+
model = new _Model(device, props);
|
|
2939
|
+
} finally {
|
|
2940
|
+
if (ownsCompilation)
|
|
2941
|
+
import_core13.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
2942
|
+
}
|
|
2943
|
+
try {
|
|
2944
|
+
if (ownsCompilation) {
|
|
2945
|
+
await Promise.all(asyncCompilation);
|
|
2946
|
+
} else {
|
|
2947
|
+
await model._pipelineInitialization;
|
|
2948
|
+
}
|
|
2949
|
+
return model;
|
|
2950
|
+
} catch (error) {
|
|
2951
|
+
model.destroy();
|
|
2952
|
+
throw error;
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2869
2955
|
static defaultProps = {
|
|
2870
2956
|
...import_core13.RenderPipeline.defaultProps,
|
|
2871
2957
|
source: void 0,
|
|
@@ -2932,7 +3018,7 @@ var Model = class _Model {
|
|
|
2932
3018
|
instanceCount = 0;
|
|
2933
3019
|
/** Vertex count */
|
|
2934
3020
|
vertexCount;
|
|
2935
|
-
/** Indexed draw count override. Undefined
|
|
3021
|
+
/** Indexed draw count override. Undefined uses vertexCount, then the full bound index buffer. */
|
|
2936
3022
|
indexCount;
|
|
2937
3023
|
/** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
|
|
2938
3024
|
firstVertex;
|
|
@@ -2973,9 +3059,11 @@ var Model = class _Model {
|
|
|
2973
3059
|
_needsRedraw = "initializing";
|
|
2974
3060
|
_drawBlockedReason = false;
|
|
2975
3061
|
_destroyed = false;
|
|
3062
|
+
_vertexCountSet = false;
|
|
2976
3063
|
/** "Time" of last draw. Monotonically increasing timestamp */
|
|
2977
3064
|
_lastDrawTimestamp = -1;
|
|
2978
3065
|
_bindingTable = [];
|
|
3066
|
+
_pipelineInitialization;
|
|
2979
3067
|
get [Symbol.toStringTag]() {
|
|
2980
3068
|
return "Model";
|
|
2981
3069
|
}
|
|
@@ -2985,11 +3073,13 @@ var Model = class _Model {
|
|
|
2985
3073
|
constructor(device, props) {
|
|
2986
3074
|
var _a;
|
|
2987
3075
|
const defaultShaderAssembler = _Model.defaultProps.shaderAssembler;
|
|
3076
|
+
const vertexCountSet = Object.hasOwn(props, "vertexCount");
|
|
2988
3077
|
this.props = {
|
|
2989
3078
|
..._Model.defaultProps,
|
|
2990
3079
|
...props,
|
|
2991
3080
|
shaderAssembler: props.shaderAssembler ?? (isShaderAssemblerForLanguage(defaultShaderAssembler, device.info.shadingLanguage) ? defaultShaderAssembler : import_shadertools3.ShaderAssembler.getDefaultShaderAssembler(device.info.shadingLanguage))
|
|
2992
3081
|
};
|
|
3082
|
+
this._vertexCountSet = vertexCountSet;
|
|
2993
3083
|
props = this.props;
|
|
2994
3084
|
this.id = props.id || uid("model");
|
|
2995
3085
|
this.device = device;
|
|
@@ -3062,46 +3152,52 @@ var Model = class _Model {
|
|
|
3062
3152
|
}
|
|
3063
3153
|
this.pipelineFactory = props.pipelineFactory || import_core13.PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
3064
3154
|
this.shaderFactory = props.shaderFactory || import_core13.ShaderFactory.getDefaultShaderFactory(this.device);
|
|
3065
|
-
|
|
3066
|
-
|
|
3155
|
+
const asyncCompilation = import_core13.PipelineFactory.getAsyncCompilation(this.device);
|
|
3156
|
+
if (asyncCompilation) {
|
|
3157
|
+
this._pipelineInitialization = this._initializePipelineAsync(props);
|
|
3158
|
+
asyncCompilation.push(this._pipelineInitialization);
|
|
3159
|
+
} else {
|
|
3160
|
+
this.pipeline = this._updatePipeline();
|
|
3161
|
+
this._initializePipelineResources(props);
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
async _initializePipelineAsync(props) {
|
|
3165
|
+
await this._updatePipelineAsync();
|
|
3166
|
+
this._initializePipelineResources(props);
|
|
3167
|
+
}
|
|
3168
|
+
_initializePipelineResources(props) {
|
|
3169
|
+
this.vertexArray = this.device.createVertexArray({
|
|
3067
3170
|
shaderLayout: this.pipeline.shaderLayout,
|
|
3068
3171
|
bufferLayout: this.pipeline.bufferLayout
|
|
3069
3172
|
});
|
|
3070
|
-
if (this._gpuGeometry)
|
|
3173
|
+
if (this._gpuGeometry)
|
|
3071
3174
|
this._setGeometryAttributes(this._gpuGeometry);
|
|
3072
|
-
|
|
3073
|
-
if ("isInstanced" in props) {
|
|
3175
|
+
if ("isInstanced" in props)
|
|
3074
3176
|
this.isInstanced = props.isInstanced;
|
|
3075
|
-
|
|
3076
|
-
if (props.instanceCount) {
|
|
3177
|
+
if (props.instanceCount)
|
|
3077
3178
|
this.setInstanceCount(props.instanceCount);
|
|
3078
|
-
|
|
3079
|
-
if (props.vertexCount) {
|
|
3179
|
+
if (props.vertexCount)
|
|
3080
3180
|
this.setVertexCount(props.vertexCount);
|
|
3081
|
-
|
|
3082
|
-
if (props.indexBuffer) {
|
|
3181
|
+
if (props.indexBuffer)
|
|
3083
3182
|
this.setIndexBuffer(props.indexBuffer);
|
|
3084
|
-
|
|
3085
|
-
if (props.attributes) {
|
|
3183
|
+
if (props.attributes)
|
|
3086
3184
|
this.setAttributes(props.attributes);
|
|
3087
|
-
|
|
3088
|
-
if (props.constantAttributes) {
|
|
3185
|
+
if (props.constantAttributes)
|
|
3089
3186
|
this.setConstantAttributes(props.constantAttributes);
|
|
3090
|
-
|
|
3091
|
-
if (props.bindings) {
|
|
3187
|
+
if (props.bindings)
|
|
3092
3188
|
this.setBindings(props.bindings);
|
|
3093
|
-
|
|
3094
|
-
if (props.transformFeedback) {
|
|
3189
|
+
if (props.transformFeedback)
|
|
3095
3190
|
this.transformFeedback = props.transformFeedback;
|
|
3096
|
-
}
|
|
3097
3191
|
}
|
|
3098
3192
|
destroy() {
|
|
3099
3193
|
var _a;
|
|
3100
3194
|
if (!this._destroyed) {
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
this.
|
|
3195
|
+
if (this.pipeline) {
|
|
3196
|
+
this.pipelineFactory.release(this.pipeline);
|
|
3197
|
+
this.shaderFactory.release(this.pipeline.vs);
|
|
3198
|
+
if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
|
|
3199
|
+
this.shaderFactory.release(this.pipeline.fs);
|
|
3200
|
+
}
|
|
3105
3201
|
}
|
|
3106
3202
|
this._uniformStore.destroy();
|
|
3107
3203
|
(_a = this._gpuGeometry) == null ? void 0 : _a.destroy();
|
|
@@ -3190,7 +3286,7 @@ var Model = class _Model {
|
|
|
3190
3286
|
const syncBindings = this._getBindings(shaderLayout);
|
|
3191
3287
|
const syncBindGroups = this._getBindGroups(shaderLayout, syncBindings);
|
|
3192
3288
|
const { indexBuffer } = this.vertexArray;
|
|
3193
|
-
const indexCount = indexBuffer ? this.indexCount ?? indexBuffer.byteLength / (indexBuffer.indexType === "uint32" ? 4 : 2) : void 0;
|
|
3289
|
+
const indexCount = indexBuffer ? this.indexCount ?? (this._vertexCountSet ? this.vertexCount : indexBuffer.byteLength / (indexBuffer.indexType === "uint32" ? 4 : 2)) : void 0;
|
|
3194
3290
|
renderPass.setPipeline(this.pipeline);
|
|
3195
3291
|
renderPass.setBindings(syncBindGroups, {
|
|
3196
3292
|
_bindGroupCacheKeys: this._getBindGroupCacheKeys()
|
|
@@ -3311,6 +3407,7 @@ var Model = class _Model {
|
|
|
3311
3407
|
*/
|
|
3312
3408
|
setVertexCount(vertexCount) {
|
|
3313
3409
|
this.vertexCount = vertexCount;
|
|
3410
|
+
this._vertexCountSet = true;
|
|
3314
3411
|
this.setNeedsRedraw("vertexCount");
|
|
3315
3412
|
}
|
|
3316
3413
|
/** Updates the indexed draw count override. */
|
|
@@ -3544,6 +3641,7 @@ var Model = class _Model {
|
|
|
3544
3641
|
}
|
|
3545
3642
|
}
|
|
3546
3643
|
this.vertexCount = gpuGeometry.vertexCount;
|
|
3644
|
+
this._vertexCountSet = true;
|
|
3547
3645
|
this.setIndexBuffer(gpuGeometry.indices || null);
|
|
3548
3646
|
this.setAttributes(gpuGeometry.attributes, { disableWarnings: true });
|
|
3549
3647
|
this.setAttributes(attributes, { disableWarnings: this.props.disableWarnings });
|
|
@@ -3557,33 +3655,57 @@ var Model = class _Model {
|
|
|
3557
3655
|
}
|
|
3558
3656
|
/** Update pipeline if needed */
|
|
3559
3657
|
_updatePipeline() {
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3658
|
+
const update = this._preparePipelineUpdate();
|
|
3659
|
+
if (update) {
|
|
3660
|
+
this.pipeline = this.pipelineFactory.createRenderPipeline(update.props);
|
|
3661
|
+
this._finishPipelineUpdate(update);
|
|
3662
|
+
}
|
|
3663
|
+
return this.pipeline;
|
|
3664
|
+
}
|
|
3665
|
+
/** Creates or replaces the render pipeline through the backend's asynchronous compilation path. */
|
|
3666
|
+
async _updatePipelineAsync() {
|
|
3667
|
+
const update = this._preparePipelineUpdate();
|
|
3668
|
+
if (update) {
|
|
3669
|
+
try {
|
|
3670
|
+
this.pipeline = await this.pipelineFactory.createRenderPipelineAsync(update.props);
|
|
3671
|
+
} catch (error) {
|
|
3672
|
+
this._releasePipelineShaders(update.vertexShader, update.fragmentShader);
|
|
3673
|
+
this._pipelineNeedsUpdate = "asynchronous pipeline creation failed";
|
|
3674
|
+
throw error;
|
|
3675
|
+
}
|
|
3676
|
+
this._finishPipelineUpdate(update);
|
|
3677
|
+
}
|
|
3678
|
+
return this.pipeline;
|
|
3679
|
+
}
|
|
3680
|
+
_preparePipelineUpdate() {
|
|
3681
|
+
var _a, _b;
|
|
3682
|
+
if (!this._pipelineNeedsUpdate)
|
|
3683
|
+
return null;
|
|
3684
|
+
const previousVertexShader = ((_a = this.pipeline) == null ? void 0 : _a.vs) ?? null;
|
|
3685
|
+
const previousFragmentShader = ((_b = this.pipeline) == null ? void 0 : _b.fs) ?? null;
|
|
3686
|
+
if (this.pipeline) {
|
|
3687
|
+
import_core13.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
3688
|
+
}
|
|
3689
|
+
this._pipelineNeedsUpdate = false;
|
|
3690
|
+
const vertexShader = this.shaderFactory.createShader({
|
|
3691
|
+
id: `${this.id}-vertex`,
|
|
3692
|
+
stage: "vertex",
|
|
3693
|
+
source: this.source || this.vs,
|
|
3694
|
+
debugShaders: this.props.debugShaders
|
|
3695
|
+
});
|
|
3696
|
+
let fragmentShader = null;
|
|
3697
|
+
if (this.source) {
|
|
3698
|
+
fragmentShader = vertexShader;
|
|
3699
|
+
} else if (this.fs) {
|
|
3700
|
+
fragmentShader = this.shaderFactory.createShader({
|
|
3701
|
+
id: `${this.id}-fragment`,
|
|
3702
|
+
stage: "fragment",
|
|
3703
|
+
source: this.fs,
|
|
3573
3704
|
debugShaders: this.props.debugShaders
|
|
3574
3705
|
});
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
} else if (this.fs) {
|
|
3579
|
-
fs4 = this.shaderFactory.createShader({
|
|
3580
|
-
id: `${this.id}-fragment`,
|
|
3581
|
-
stage: "fragment",
|
|
3582
|
-
source: this.source || this.fs,
|
|
3583
|
-
debugShaders: this.props.debugShaders
|
|
3584
|
-
});
|
|
3585
|
-
}
|
|
3586
|
-
this.pipeline = this.pipelineFactory.createRenderPipeline({
|
|
3706
|
+
}
|
|
3707
|
+
return {
|
|
3708
|
+
props: {
|
|
3587
3709
|
...this.props,
|
|
3588
3710
|
bindings: void 0,
|
|
3589
3711
|
bufferLayout: this.bufferLayout,
|
|
@@ -3592,17 +3714,25 @@ var Model = class _Model {
|
|
|
3592
3714
|
topology: this.topology,
|
|
3593
3715
|
parameters: this.parameters,
|
|
3594
3716
|
bindGroups: void 0,
|
|
3595
|
-
vs:
|
|
3596
|
-
fs:
|
|
3597
|
-
}
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3717
|
+
vs: vertexShader,
|
|
3718
|
+
fs: fragmentShader
|
|
3719
|
+
},
|
|
3720
|
+
vertexShader,
|
|
3721
|
+
fragmentShader,
|
|
3722
|
+
previousVertexShader,
|
|
3723
|
+
previousFragmentShader
|
|
3724
|
+
};
|
|
3725
|
+
}
|
|
3726
|
+
_finishPipelineUpdate(update) {
|
|
3727
|
+
this._attributeInfos = (0, import_core13.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout, this.bufferLayout);
|
|
3728
|
+
this._releasePipelineShaders(update.previousVertexShader, update.previousFragmentShader);
|
|
3729
|
+
}
|
|
3730
|
+
_releasePipelineShaders(vertexShader, fragmentShader) {
|
|
3731
|
+
if (vertexShader)
|
|
3732
|
+
this.shaderFactory.release(vertexShader);
|
|
3733
|
+
if (fragmentShader && fragmentShader !== vertexShader) {
|
|
3734
|
+
this.shaderFactory.release(fragmentShader);
|
|
3604
3735
|
}
|
|
3605
|
-
return this.pipeline;
|
|
3606
3736
|
}
|
|
3607
3737
|
/** Throttle draw call logging */
|
|
3608
3738
|
_lastLogTime = 0;
|
|
@@ -7790,6 +7920,34 @@ var import_types2 = require("@math.gl/types");
|
|
|
7790
7920
|
var LOG_DRAW_PRIORITY2 = 2;
|
|
7791
7921
|
var LOG_DRAW_TIMEOUT2 = 1e4;
|
|
7792
7922
|
var Computation = class _Computation {
|
|
7923
|
+
/**
|
|
7924
|
+
* Creates a computation while allowing the backend to compile its pipeline asynchronously.
|
|
7925
|
+
*
|
|
7926
|
+
* Use this factory when several independent computations can be prepared together. Calling the
|
|
7927
|
+
* constructor remains the synchronous compatibility path.
|
|
7928
|
+
*/
|
|
7929
|
+
static async createAsync(device, props) {
|
|
7930
|
+
const ownsCompilation = !import_core27.PipelineFactory.getAsyncCompilation(device);
|
|
7931
|
+
const asyncCompilation = ownsCompilation ? import_core27.PipelineFactory.beginAsyncCompilation(device) : import_core27.PipelineFactory.getAsyncCompilation(device);
|
|
7932
|
+
let computation;
|
|
7933
|
+
try {
|
|
7934
|
+
computation = new _Computation(device, props);
|
|
7935
|
+
} finally {
|
|
7936
|
+
if (ownsCompilation)
|
|
7937
|
+
import_core27.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
7938
|
+
}
|
|
7939
|
+
try {
|
|
7940
|
+
if (ownsCompilation) {
|
|
7941
|
+
await Promise.all(asyncCompilation);
|
|
7942
|
+
} else {
|
|
7943
|
+
await computation._pipelineInitialization;
|
|
7944
|
+
}
|
|
7945
|
+
return computation;
|
|
7946
|
+
} catch (error) {
|
|
7947
|
+
computation.destroy();
|
|
7948
|
+
throw error;
|
|
7949
|
+
}
|
|
7950
|
+
}
|
|
7793
7951
|
static defaultProps = {
|
|
7794
7952
|
...import_core27.ComputePipeline.defaultProps,
|
|
7795
7953
|
id: "unnamed",
|
|
@@ -7828,6 +7986,7 @@ var Computation = class _Computation {
|
|
|
7828
7986
|
_getModuleUniforms;
|
|
7829
7987
|
props;
|
|
7830
7988
|
_destroyed = false;
|
|
7989
|
+
_pipelineInitialization;
|
|
7831
7990
|
constructor(device, props) {
|
|
7832
7991
|
var _a, _b;
|
|
7833
7992
|
if (device.type !== "webgpu") {
|
|
@@ -7869,7 +8028,13 @@ var Computation = class _Computation {
|
|
|
7869
8028
|
this._getModuleUniforms = getUniforms2;
|
|
7870
8029
|
const inferredShaderLayout = assembledShaderLayout ?? ((_b = device.getShaderLayout) == null ? void 0 : _b.call(device, this.source, { scanVertexAttributes: false }));
|
|
7871
8030
|
this.props.shaderLayout = mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout || inferredShaderLayout || null, modules) || null;
|
|
7872
|
-
|
|
8031
|
+
const asyncCompilation = import_core27.PipelineFactory.getAsyncCompilation(this.device);
|
|
8032
|
+
if (asyncCompilation) {
|
|
8033
|
+
this._pipelineInitialization = this._updatePipelineAsync();
|
|
8034
|
+
asyncCompilation.push(this._pipelineInitialization);
|
|
8035
|
+
} else {
|
|
8036
|
+
this.pipeline = this._updatePipeline();
|
|
8037
|
+
}
|
|
7873
8038
|
if (props.bindings) {
|
|
7874
8039
|
this.setBindings(props.bindings);
|
|
7875
8040
|
}
|
|
@@ -7877,8 +8042,10 @@ var Computation = class _Computation {
|
|
|
7877
8042
|
destroy() {
|
|
7878
8043
|
if (this._destroyed)
|
|
7879
8044
|
return;
|
|
7880
|
-
|
|
7881
|
-
|
|
8045
|
+
if (this.pipeline)
|
|
8046
|
+
this.pipelineFactory.release(this.pipeline);
|
|
8047
|
+
if (this.shader)
|
|
8048
|
+
this.shaderFactory.release(this.shader);
|
|
7882
8049
|
this._uniformStore.destroy();
|
|
7883
8050
|
this._destroyed = true;
|
|
7884
8051
|
}
|
|
@@ -7973,29 +8140,49 @@ var Computation = class _Computation {
|
|
|
7973
8140
|
this._pipelineNeedsUpdate = this._pipelineNeedsUpdate || reason;
|
|
7974
8141
|
}
|
|
7975
8142
|
_updatePipeline() {
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
shader
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
this.shaderFactory.release(prevShader);
|
|
8143
|
+
const update = this._preparePipelineUpdate();
|
|
8144
|
+
if (update) {
|
|
8145
|
+
this.pipeline = this.pipelineFactory.createComputePipeline(update.props);
|
|
8146
|
+
this._finishPipelineUpdate(update.previousShader);
|
|
8147
|
+
}
|
|
8148
|
+
return this.pipeline;
|
|
8149
|
+
}
|
|
8150
|
+
/** Creates or replaces the pipeline through the backend's asynchronous compilation path. */
|
|
8151
|
+
async _updatePipelineAsync() {
|
|
8152
|
+
const update = this._preparePipelineUpdate();
|
|
8153
|
+
if (update) {
|
|
8154
|
+
try {
|
|
8155
|
+
this.pipeline = await this.pipelineFactory.createComputePipelineAsync(update.props);
|
|
8156
|
+
} catch (error) {
|
|
8157
|
+
this.shaderFactory.release(this.shader);
|
|
8158
|
+
this.shader = update.previousShader;
|
|
8159
|
+
this._pipelineNeedsUpdate = "asynchronous pipeline creation failed";
|
|
8160
|
+
throw error;
|
|
7995
8161
|
}
|
|
8162
|
+
this._finishPipelineUpdate(update.previousShader);
|
|
7996
8163
|
}
|
|
7997
8164
|
return this.pipeline;
|
|
7998
8165
|
}
|
|
8166
|
+
_preparePipelineUpdate() {
|
|
8167
|
+
if (!this._pipelineNeedsUpdate)
|
|
8168
|
+
return null;
|
|
8169
|
+
const previousShader = this.pipeline ? this.shader : null;
|
|
8170
|
+
if (this.pipeline) {
|
|
8171
|
+
import_core27.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
8172
|
+
}
|
|
8173
|
+
this._pipelineNeedsUpdate = false;
|
|
8174
|
+
this.shader = this.shaderFactory.createShader({
|
|
8175
|
+
id: `${this.id}-fragment`,
|
|
8176
|
+
stage: "compute",
|
|
8177
|
+
source: this.source,
|
|
8178
|
+
debugShaders: this.props.debugShaders
|
|
8179
|
+
});
|
|
8180
|
+
return { props: { ...this.props, shader: this.shader }, previousShader };
|
|
8181
|
+
}
|
|
8182
|
+
_finishPipelineUpdate(previousShader) {
|
|
8183
|
+
if (previousShader)
|
|
8184
|
+
this.shaderFactory.release(previousShader);
|
|
8185
|
+
}
|
|
7999
8186
|
/** Throttle draw call logging */
|
|
8000
8187
|
_lastLogTime = 0;
|
|
8001
8188
|
_logOpen = false;
|
|
@@ -8227,7 +8414,7 @@ var ShaderPassRenderer = class {
|
|
|
8227
8414
|
passRenderer.resize(size);
|
|
8228
8415
|
}
|
|
8229
8416
|
}
|
|
8230
|
-
/** Invalidates persistent
|
|
8417
|
+
/** Invalidates persistent composite-pass targets without destroying their allocations. */
|
|
8231
8418
|
resetHistory() {
|
|
8232
8419
|
for (const passRenderer of this.passRenderers) {
|
|
8233
8420
|
passRenderer.resetHistory();
|
|
@@ -8361,11 +8548,11 @@ var PassRenderer = class {
|
|
|
8361
8548
|
this.device = device;
|
|
8362
8549
|
this.shaderInputs = shaderInputs;
|
|
8363
8550
|
this.passDefinition = passDefinition;
|
|
8364
|
-
if (
|
|
8551
|
+
if (isCompositeShaderPass(passDefinition)) {
|
|
8365
8552
|
validateRenderTargetNames(passDefinition.name, passDefinition.renderTargets || {});
|
|
8366
8553
|
this.renderTargets = createManagedRenderTargets(device, passDefinition.renderTargets || {});
|
|
8367
8554
|
if (supportsComputeOptimization(device, passDefinition)) {
|
|
8368
|
-
this.computeRenderer = new
|
|
8555
|
+
this.computeRenderer = new CompositeShaderPassComputeRenderer(device, passDefinition.compute, this.renderTargets, shaderInputs);
|
|
8369
8556
|
}
|
|
8370
8557
|
const executableSteps = this.computeRenderer ? passDefinition.steps.filter((step) => !passDefinition.compute.replacedPasses.includes(step.shaderPass.name)) : passDefinition.steps;
|
|
8371
8558
|
this.subPassExecutions = executableSteps.flatMap((step) => this.createStepExecutions(passDefinition, step, flipY));
|
|
@@ -8496,10 +8683,10 @@ var PassRenderer = class {
|
|
|
8496
8683
|
}
|
|
8497
8684
|
return resolvedBindings;
|
|
8498
8685
|
}
|
|
8499
|
-
createStepExecutions(
|
|
8500
|
-
validateShaderPassDoesNotOwnRenderTargets(step.shaderPass, `${
|
|
8686
|
+
createStepExecutions(compositeShaderPass, step, flipY) {
|
|
8687
|
+
validateShaderPassDoesNotOwnRenderTargets(step.shaderPass, `${compositeShaderPass.name}/${step.shaderPass.name}`);
|
|
8501
8688
|
return this.createPassExecutions(step.shaderPass, {
|
|
8502
|
-
ownerName: `${
|
|
8689
|
+
ownerName: `${compositeShaderPass.name}/${step.shaderPass.name}`,
|
|
8503
8690
|
firstInputs: step.inputs,
|
|
8504
8691
|
lastOutput: step.output,
|
|
8505
8692
|
uniformOverrides: step.uniforms,
|
|
@@ -8543,7 +8730,7 @@ var PassRenderer = class {
|
|
|
8543
8730
|
return this.passDefinition.name;
|
|
8544
8731
|
}
|
|
8545
8732
|
};
|
|
8546
|
-
var
|
|
8733
|
+
var CompositeShaderPassComputeRenderer = class {
|
|
8547
8734
|
optimization;
|
|
8548
8735
|
renderTargets;
|
|
8549
8736
|
shaderInputs;
|
|
@@ -8668,13 +8855,13 @@ var SubPassRenderer = class {
|
|
|
8668
8855
|
}
|
|
8669
8856
|
};
|
|
8670
8857
|
function getExecutableShaderPasses(shaderPasses) {
|
|
8671
|
-
return shaderPasses.flatMap((shaderPass) =>
|
|
8858
|
+
return shaderPasses.flatMap((shaderPass) => isCompositeShaderPass(shaderPass) ? shaderPass.steps.map((step) => step.shaderPass) : [shaderPass]);
|
|
8672
8859
|
}
|
|
8673
|
-
function
|
|
8860
|
+
function isCompositeShaderPass(shaderPass) {
|
|
8674
8861
|
return "steps" in shaderPass;
|
|
8675
8862
|
}
|
|
8676
|
-
function supportsComputeOptimization(device,
|
|
8677
|
-
const optimization =
|
|
8863
|
+
function supportsComputeOptimization(device, compositeShaderPass) {
|
|
8864
|
+
const optimization = compositeShaderPass.compute;
|
|
8678
8865
|
if (!optimization || device.type !== "webgpu") {
|
|
8679
8866
|
return false;
|
|
8680
8867
|
}
|
|
@@ -8684,7 +8871,7 @@ function supportsComputeOptimization(device, pipeline) {
|
|
|
8684
8871
|
}
|
|
8685
8872
|
return outputNames.every((targetName) => {
|
|
8686
8873
|
var _a;
|
|
8687
|
-
const target = (_a =
|
|
8874
|
+
const target = (_a = compositeShaderPass.renderTargets) == null ? void 0 : _a[targetName];
|
|
8688
8875
|
if (!(target == null ? void 0 : target.storage)) {
|
|
8689
8876
|
return false;
|
|
8690
8877
|
}
|
|
@@ -8695,7 +8882,7 @@ function supportsComputeOptimization(device, pipeline) {
|
|
|
8695
8882
|
function validateShaderPassDoesNotOwnRenderTargets(shaderPass, ownerName) {
|
|
8696
8883
|
const renderTargets = shaderPass.renderTargets;
|
|
8697
8884
|
if (renderTargets && Object.keys(renderTargets).length > 0) {
|
|
8698
|
-
throw new Error(`${ownerName}: ShaderPass.renderTargets is not supported; use
|
|
8885
|
+
throw new Error(`${ownerName}: ShaderPass.renderTargets is not supported; use CompositeShaderPass.renderTargets instead`);
|
|
8699
8886
|
}
|
|
8700
8887
|
}
|
|
8701
8888
|
function validateRenderTargetNames(ownerName, renderTargets) {
|
|
@@ -8871,8 +9058,208 @@ function calculateTextureScale(sourceTexture, outputTexture) {
|
|
|
8871
9058
|
return [sourceAspect / outputAspect, 1];
|
|
8872
9059
|
}
|
|
8873
9060
|
|
|
8874
|
-
// dist/
|
|
9061
|
+
// dist/compute/kernel.js
|
|
8875
9062
|
var import_core29 = require("@luma.gl/core");
|
|
9063
|
+
var Kernel = class _Kernel {
|
|
9064
|
+
/** Creates a kernel while allowing the backend to compile its pipeline asynchronously. */
|
|
9065
|
+
static async createAsync(device, props) {
|
|
9066
|
+
const ownsCompilation = !import_core29.PipelineFactory.getAsyncCompilation(device);
|
|
9067
|
+
const asyncCompilation = ownsCompilation ? import_core29.PipelineFactory.beginAsyncCompilation(device) : import_core29.PipelineFactory.getAsyncCompilation(device);
|
|
9068
|
+
let kernel;
|
|
9069
|
+
try {
|
|
9070
|
+
kernel = new _Kernel(device, props);
|
|
9071
|
+
} finally {
|
|
9072
|
+
if (ownsCompilation)
|
|
9073
|
+
import_core29.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
9074
|
+
}
|
|
9075
|
+
try {
|
|
9076
|
+
if (ownsCompilation) {
|
|
9077
|
+
await Promise.all(asyncCompilation);
|
|
9078
|
+
} else {
|
|
9079
|
+
await kernel._pipelineInitialization;
|
|
9080
|
+
}
|
|
9081
|
+
return kernel;
|
|
9082
|
+
} catch (error) {
|
|
9083
|
+
kernel.destroy();
|
|
9084
|
+
throw error;
|
|
9085
|
+
}
|
|
9086
|
+
}
|
|
9087
|
+
device;
|
|
9088
|
+
id;
|
|
9089
|
+
source;
|
|
9090
|
+
pipelineFactory;
|
|
9091
|
+
shaderFactory;
|
|
9092
|
+
shader;
|
|
9093
|
+
pipeline;
|
|
9094
|
+
_pipelineInitialization;
|
|
9095
|
+
_destroyed = false;
|
|
9096
|
+
constructor(device, props) {
|
|
9097
|
+
if (device.type !== "webgpu") {
|
|
9098
|
+
throw new Error("Kernel is only supported in WebGPU");
|
|
9099
|
+
}
|
|
9100
|
+
const { source: source4, pipelineFactory, shaderFactory, debugShaders, ...pipelineProps } = props;
|
|
9101
|
+
this.device = device;
|
|
9102
|
+
this.id = props.id ?? "kernel";
|
|
9103
|
+
this.source = source4;
|
|
9104
|
+
this.pipelineFactory = pipelineFactory ?? import_core29.PipelineFactory.getDefaultPipelineFactory(device);
|
|
9105
|
+
this.shaderFactory = shaderFactory ?? import_core29.ShaderFactory.getDefaultShaderFactory(device);
|
|
9106
|
+
this.shader = this.shaderFactory.createShader({
|
|
9107
|
+
id: `${this.id}-compute`,
|
|
9108
|
+
stage: "compute",
|
|
9109
|
+
source: this.source,
|
|
9110
|
+
debugShaders
|
|
9111
|
+
});
|
|
9112
|
+
const computePipelineProps = { ...pipelineProps, shader: this.shader };
|
|
9113
|
+
const asyncCompilation = import_core29.PipelineFactory.getAsyncCompilation(device);
|
|
9114
|
+
if (asyncCompilation) {
|
|
9115
|
+
const pipelineInitialization = this.pipelineFactory.createComputePipelineAsync(computePipelineProps);
|
|
9116
|
+
this._pipelineInitialization = pipelineInitialization;
|
|
9117
|
+
asyncCompilation.push(pipelineInitialization.then((pipeline) => {
|
|
9118
|
+
this.pipeline = pipeline;
|
|
9119
|
+
return pipeline;
|
|
9120
|
+
}));
|
|
9121
|
+
} else {
|
|
9122
|
+
this.pipeline = this.pipelineFactory.createComputePipeline(computePipelineProps);
|
|
9123
|
+
}
|
|
9124
|
+
}
|
|
9125
|
+
/** Applies per-dispatch bindings and records a direct compute dispatch. */
|
|
9126
|
+
dispatch(computePass, options) {
|
|
9127
|
+
this._setPipeline(computePass, options.bindings);
|
|
9128
|
+
computePass.dispatch(options.x, options.y, options.z);
|
|
9129
|
+
}
|
|
9130
|
+
/** Applies per-dispatch bindings and records a GPU-driven indirect compute dispatch. */
|
|
9131
|
+
dispatchIndirect(computePass, options) {
|
|
9132
|
+
this._setPipeline(computePass, options.bindings);
|
|
9133
|
+
computePass.dispatchIndirect(options.indirectBuffer, options.indirectOffset ?? 0);
|
|
9134
|
+
}
|
|
9135
|
+
destroy() {
|
|
9136
|
+
if (this._destroyed)
|
|
9137
|
+
return;
|
|
9138
|
+
if (this.pipeline)
|
|
9139
|
+
this.pipelineFactory.release(this.pipeline);
|
|
9140
|
+
this.shaderFactory.release(this.shader);
|
|
9141
|
+
this._destroyed = true;
|
|
9142
|
+
}
|
|
9143
|
+
_setPipeline(computePass, bindings = {}) {
|
|
9144
|
+
computePass.setPipeline(this.pipeline);
|
|
9145
|
+
computePass.setBindings(bindings);
|
|
9146
|
+
}
|
|
9147
|
+
};
|
|
9148
|
+
|
|
9149
|
+
// dist/compute/render-kernel.js
|
|
9150
|
+
var import_core30 = require("@luma.gl/core");
|
|
9151
|
+
var RenderKernel = class _RenderKernel {
|
|
9152
|
+
/** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
|
|
9153
|
+
static async createAsync(device, props) {
|
|
9154
|
+
const ownsCompilation = !import_core30.PipelineFactory.getAsyncCompilation(device);
|
|
9155
|
+
const asyncCompilation = ownsCompilation ? import_core30.PipelineFactory.beginAsyncCompilation(device) : import_core30.PipelineFactory.getAsyncCompilation(device);
|
|
9156
|
+
let kernel;
|
|
9157
|
+
try {
|
|
9158
|
+
kernel = new _RenderKernel(device, props);
|
|
9159
|
+
} finally {
|
|
9160
|
+
if (ownsCompilation)
|
|
9161
|
+
import_core30.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
9162
|
+
}
|
|
9163
|
+
try {
|
|
9164
|
+
if (ownsCompilation) {
|
|
9165
|
+
await Promise.all(asyncCompilation);
|
|
9166
|
+
} else {
|
|
9167
|
+
await kernel._pipelineInitialization;
|
|
9168
|
+
}
|
|
9169
|
+
return kernel;
|
|
9170
|
+
} catch (error) {
|
|
9171
|
+
kernel.destroy();
|
|
9172
|
+
throw error;
|
|
9173
|
+
}
|
|
9174
|
+
}
|
|
9175
|
+
device;
|
|
9176
|
+
id;
|
|
9177
|
+
vertexSource;
|
|
9178
|
+
fragmentSource;
|
|
9179
|
+
pipelineFactory;
|
|
9180
|
+
shaderFactory;
|
|
9181
|
+
vertexShader;
|
|
9182
|
+
fragmentShader;
|
|
9183
|
+
pipeline;
|
|
9184
|
+
_pipelineInitialization;
|
|
9185
|
+
_destroyed = false;
|
|
9186
|
+
constructor(device, props) {
|
|
9187
|
+
if (device.type !== "webgpu") {
|
|
9188
|
+
throw new Error("RenderKernel is only supported in WebGPU");
|
|
9189
|
+
}
|
|
9190
|
+
const { vertexSource, fragmentSource, pipelineFactory, shaderFactory, debugShaders, ...pipelineProps } = props;
|
|
9191
|
+
this.device = device;
|
|
9192
|
+
this.id = props.id ?? "render-kernel";
|
|
9193
|
+
this.vertexSource = vertexSource;
|
|
9194
|
+
this.fragmentSource = fragmentSource;
|
|
9195
|
+
this.pipelineFactory = pipelineFactory ?? import_core30.PipelineFactory.getDefaultPipelineFactory(device);
|
|
9196
|
+
this.shaderFactory = shaderFactory ?? import_core30.ShaderFactory.getDefaultShaderFactory(device);
|
|
9197
|
+
this.vertexShader = this.shaderFactory.createShader({
|
|
9198
|
+
id: `${this.id}-vertex`,
|
|
9199
|
+
stage: "vertex",
|
|
9200
|
+
source: this.vertexSource,
|
|
9201
|
+
debugShaders
|
|
9202
|
+
});
|
|
9203
|
+
this.fragmentShader = this.fragmentSource ? this.shaderFactory.createShader({
|
|
9204
|
+
id: `${this.id}-fragment`,
|
|
9205
|
+
stage: "fragment",
|
|
9206
|
+
source: this.fragmentSource,
|
|
9207
|
+
debugShaders
|
|
9208
|
+
}) : null;
|
|
9209
|
+
const renderPipelineProps = {
|
|
9210
|
+
...pipelineProps,
|
|
9211
|
+
vs: this.vertexShader,
|
|
9212
|
+
fs: this.fragmentShader
|
|
9213
|
+
};
|
|
9214
|
+
const asyncCompilation = import_core30.PipelineFactory.getAsyncCompilation(device);
|
|
9215
|
+
if (asyncCompilation) {
|
|
9216
|
+
const pipelineInitialization = this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
|
|
9217
|
+
this._pipelineInitialization = pipelineInitialization;
|
|
9218
|
+
asyncCompilation.push(pipelineInitialization.then((pipeline) => {
|
|
9219
|
+
this.pipeline = pipeline;
|
|
9220
|
+
return pipeline;
|
|
9221
|
+
}));
|
|
9222
|
+
} else {
|
|
9223
|
+
this.pipeline = this.pipelineFactory.createRenderPipeline(renderPipelineProps);
|
|
9224
|
+
}
|
|
9225
|
+
}
|
|
9226
|
+
/** Applies per-draw bindings/vertex state and records a direct draw. */
|
|
9227
|
+
draw(renderPass, options) {
|
|
9228
|
+
const { bindings = {}, vertexArray, ...drawOptions } = options;
|
|
9229
|
+
this._setPipeline(renderPass, bindings, vertexArray);
|
|
9230
|
+
return renderPass.draw(drawOptions);
|
|
9231
|
+
}
|
|
9232
|
+
/** Applies per-draw state and records a non-indexed indirect draw. */
|
|
9233
|
+
drawIndirect(renderPass, options) {
|
|
9234
|
+
const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
|
|
9235
|
+
this._setPipeline(renderPass, bindings, vertexArray);
|
|
9236
|
+
renderPass.drawIndirect(indirectBuffer, indirectOffset);
|
|
9237
|
+
}
|
|
9238
|
+
/** Applies per-draw state and records an indexed indirect draw. */
|
|
9239
|
+
drawIndexedIndirect(renderPass, options) {
|
|
9240
|
+
const { bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0 } = options;
|
|
9241
|
+
this._setPipeline(renderPass, bindings, vertexArray);
|
|
9242
|
+
renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
|
|
9243
|
+
}
|
|
9244
|
+
destroy() {
|
|
9245
|
+
if (this._destroyed)
|
|
9246
|
+
return;
|
|
9247
|
+
if (this.pipeline)
|
|
9248
|
+
this.pipelineFactory.release(this.pipeline);
|
|
9249
|
+
this.shaderFactory.release(this.vertexShader);
|
|
9250
|
+
if (this.fragmentShader)
|
|
9251
|
+
this.shaderFactory.release(this.fragmentShader);
|
|
9252
|
+
this._destroyed = true;
|
|
9253
|
+
}
|
|
9254
|
+
_setPipeline(renderPass, bindings, vertexArray) {
|
|
9255
|
+
renderPass.setPipeline(this.pipeline);
|
|
9256
|
+
renderPass.setBindings(bindings);
|
|
9257
|
+
renderPass.setVertexArray(vertexArray);
|
|
9258
|
+
}
|
|
9259
|
+
};
|
|
9260
|
+
|
|
9261
|
+
// dist/modules/picking/picking-manager.js
|
|
9262
|
+
var import_core31 = require("@luma.gl/core");
|
|
8876
9263
|
|
|
8877
9264
|
// dist/modules/picking/picking-uniforms.js
|
|
8878
9265
|
var DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
|
|
@@ -9131,13 +9518,13 @@ var PickingManager = class _PickingManager {
|
|
|
9131
9518
|
format: "rgba8unorm",
|
|
9132
9519
|
width: 1,
|
|
9133
9520
|
height: 1,
|
|
9134
|
-
usage:
|
|
9521
|
+
usage: import_core31.Texture.RENDER_ATTACHMENT
|
|
9135
9522
|
});
|
|
9136
9523
|
const pickingTexture = this.device.createTexture({
|
|
9137
9524
|
format: "rg32sint",
|
|
9138
9525
|
width: 1,
|
|
9139
9526
|
height: 1,
|
|
9140
|
-
usage:
|
|
9527
|
+
usage: import_core31.Texture.RENDER_ATTACHMENT | import_core31.Texture.COPY_SRC
|
|
9141
9528
|
});
|
|
9142
9529
|
return this.device.createFramebuffer({
|
|
9143
9530
|
colorAttachments: [colorTexture, pickingTexture],
|
|
@@ -9149,7 +9536,7 @@ var PickingManager = class _PickingManager {
|
|
|
9149
9536
|
format: "rgba8unorm",
|
|
9150
9537
|
width: 1,
|
|
9151
9538
|
height: 1,
|
|
9152
|
-
usage:
|
|
9539
|
+
usage: import_core31.Texture.RENDER_ATTACHMENT | import_core31.Texture.COPY_SRC
|
|
9153
9540
|
});
|
|
9154
9541
|
return this.device.createFramebuffer({
|
|
9155
9542
|
colorAttachments: [pickingTexture],
|
|
@@ -9173,7 +9560,7 @@ var PickingManager = class _PickingManager {
|
|
|
9173
9560
|
const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
|
|
9174
9561
|
const readBuffer = this.device.createBuffer({
|
|
9175
9562
|
byteLength: layout.byteLength,
|
|
9176
|
-
usage:
|
|
9563
|
+
usage: import_core31.Buffer.COPY_DST | import_core31.Buffer.MAP_READ
|
|
9177
9564
|
});
|
|
9178
9565
|
try {
|
|
9179
9566
|
pickTexture.readBuffer({
|
|
@@ -9207,7 +9594,7 @@ var PickingManager = class _PickingManager {
|
|
|
9207
9594
|
const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
|
|
9208
9595
|
const readBuffer = this.device.createBuffer({
|
|
9209
9596
|
byteLength: layout.byteLength,
|
|
9210
|
-
usage:
|
|
9597
|
+
usage: import_core31.Buffer.COPY_DST | import_core31.Buffer.MAP_READ
|
|
9211
9598
|
});
|
|
9212
9599
|
try {
|
|
9213
9600
|
pickTexture.readBuffer({
|