UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

60 lines (57 loc) 2.6 kB
import { aE as stopEngine, aF as disposeGpuResourceRetirements, T as ThrowLiteError, o as TU, aG as _refreshScRT, aH as resizeEngine, aI as startEngine } from './index-DMbDahsc.esm.js'; async function runDeviceLostRecovery(engine, state, registrations) { const handlers = /* @__PURE__ */ new Map(); for (const registration of registrations) { handlers.set(registration._kind, registration); } const wasRunning = engine._renderFn !== null; stopEngine(engine); disposeGpuResourceRetirements(engine); const adapter = await runRecoveryStep("requesting a replacement adapter", () => navigator.gpu.requestAdapter({ powerPreference: "high-performance" })); if (!adapter) { ThrowLiteError(43); } const missingFeatures = state._requiredFeatures.filter((feature) => !adapter.features.has(feature)); if (missingFeatures.length) { ThrowLiteError(44, missingFeatures.join(", ")); } engine._device = await runRecoveryStep( "requesting a replacement device", () => adapter.requestDevice({ requiredFeatures: state._requiredFeatures, requiredLimits: { ...engine._options?.requiredLimits, ...engine._storageRequiredLimits } }) ); await runRecoveryStep("rebuilding engine storage buffers", () => engine._rebuildStorageBuffers?.()); await runRecoveryStep("reconfiguring rendering surfaces", () => { for (const surface of engine.surfaces) { const usage = surface._swapchainCopySrc ? TU.RENDER_ATTACHMENT | TU.COPY_SRC : TU.RENDER_ATTACHMENT; surface._context.configure({ device: engine._device, format: surface._configureFormat, alphaMode: surface._alphaMode, usage, viewFormats: [surface.format] }); _refreshScRT(surface); } }); await runRecoveryStep("resizing rendering surfaces", () => resizeEngine(engine)); const orderedHandlers = Array.from(handlers.values()).sort((a, b) => (a._recoverOrder ?? 0) - (b._recoverOrder ?? 0)); for (const handler of orderedHandlers) { await runRecoveryStep(`running "${handler._kind}" recovery`, () => handler._recover(engine)); } if (wasRunning) { await runRecoveryStep("restarting rendering", () => startEngine(engine)); } } async function runRecoveryStep(description, action) { try { return await action(); } catch (error) { const message = error instanceof Error ? error.message : String(error); throw new Error(`Device-lost recovery failed while ${description}: ${message}`, { cause: error }); } } export { runDeviceLostRecovery }; //# sourceMappingURL=device-lost-recovery-run-DrSWIIkF.esm.js.map