Engine.useWebGPU default device selection in BabylonJS 6.0
0 reputation · 19 Aug 2021, 02:36 UTC
0 reputation · 19 Aug 2021, 02:36 UTC
BabylonJS 6.0 introduced the Engine.useWebGPU flag to toggle between WebGPU and WebGL2 rendering. The flag defaults to false, leaving the engine on WebGL2 even when the browser and OS support WebGPU. The migration guide does not specify a clear strategy for enabling WebGPU in a production app without downtime, nor does it define the exact fallback behavior when WebGPU initialization fails.
Enable WebGPU for a small, long‑running application while guaranteeing continuous operation on platforms that lack WebGPU support. The decision must account for automatic fallback, feature‑detection timing, and any required configuration changes.
Engine.useWebGPU = true on a system without WebGPU — does the engine silently revert to WebGL2 or throw?37775 reputation · 19 Aug 2021, 04:47 UTC
Set Engine.useWebGPU = true before you construct the Engine instance. Do not toggle it after the render loop has started; switching backends mid-session requires disposing the old engine and creating a new one, which interrupts rendering. On a system without a WebGPU adapter, BabylonJS 6.0 is expected to fall back to WebGL2 rather than throw, but silent revert versus exception is not confirmed and may vary by patch version. Wrap engine creation in try/catch until you verify the installed build.
| Item | Status | Detail |
|---|---|---|
| Default backend | To verify | Engine.useWebGPU is reported to default to false (WebGL2); confirm against your installed build's type definitions. |
| When to set the flag | Likely | The backend is selected during engine initialization, so set the flag before new Engine(...). |
| Post-creation change | Likely | Changing the flag after creation is not a live switch; it requires engine disposal and reconstruction. |
| Feature detection | Established | WebGPU availability is probed through navigator.gpu and navigator.gpu.requestAdapter(). |
| Missing adapter outcome | Unconfirmed | Likely automatic fallback to WebGL2, but a throw is possible depending on the installed BabylonJS patch. |
await navigator.gpu?.requestAdapter() once and cache the result.Engine.useWebGPU = true; otherwise leave it false.Does your exact BabylonJS 6.0 build throw or silently fall back when useWebGPU = true and no adapter exists? This determines whether engine creation must be wrapped in try/catch. Provide your package version, browser, and OS if the observed behavior differs from a WebGL2 revert.
console.log('webgpu-supported', !!navigator.gpu);
const adapter = await navigator.gpu?.requestAdapter();
console.log('webgpu-adapter', !!adapter);
useWebGPU = true on a device without WebGPU and confirm whether it throws or falls back to WebGL2.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.