so far the WebGPU support for browsers running on Linux is only experimental. But I wanted to try it out to see its effect on the performance of a rather complex scene. I tried to start the engine with the following code, as described in the documentation:
var renderCanvas = document.getElementById(“renderCanvas”);
var engine = new BABYLON.WebGPUEngine(renderCanvas);
await engine.initAsync();
But I receive this error message:
Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
According to the message, you need to make the function, where you use await expression, to be an async function.
The simplest way to do it is to add async before function.
Example: the basic PG made async - Babylon.js Playground
The error message you’re seeing, “Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules,” indicates that the “await” keyword needs to be used within an dg customer service async function or a module’s top-level body. To fix this, wrap your code in an async function like so:
async function startEngine() {
var renderCanvas = document.getElementById("renderCanvas");
var engine = new BABYLON.WebGPUEngine(renderCanvas);
await engine.initAsync();
}
startEngine();
By doing this, “await” will be properly used within an async function, resolving the error.