I’m using es6 imports from @babylonjs. I’ve been working on WebGL for a while and everything’s awesome. I tried to switch to webGPU (chrome with the origin trial turned on and confirmed) and I got the below error.
I figured it was something I was using so I started a new project that just creates and initAsyncs the engine and get the same error. Any idea what’s going on?
Here’s the code:
import { Engine } from '@babylonjs/core/Engines/engine';
import { WebGPUEngine } from '@babylonjs/core/Engines/webgpuEngine';
// some unrelated class stuff...
private async initEngine(gameCanvas) {
const webGPUSupported = await WebGPUEngine.IsSupportedAsync;
console.log({webGPUSupported}); // This shows as true
if (webGPUSupported) {
this.engine = new WebGPUEngine(gameCanvas, {
adaptToDeviceRatio: true,
antialiasing: true,
});
await (this.engine as WebGPUEngine).initAsync();
} else {
this.engine = new Engine(gameCanvas, true, {}, true);
}
}
import { WebGPUEngine } from '@babylonjs/core/Engines/webgpuEngine';
// Changed to
import { WebGPUEngine } from '@babylonjs/core';
Importing the entire core library makes the error go away and is good enough for now, but not a good long-term solution. I’ve been using tree-shaking and specific imports with webGL to keep my application size down. Doing this about triples the size!
Does anyone know which imports are missing for this? Maybe there’s a side effect I need to import like how the gltf loader has to be imported?
I found these, but importing doesn’t help. Think these might be legacy ones, not webgpu?
Yes, probably because you are using these features
We will probably need to make the engine extensions more of a plugin system than an import system. I noted this, we’ll find a solution. Hopefully soon.
Haha, fun indeed. Good luck and thank you all for your help!
For anyone else hitting this issue before @RaananW works their magic, here’s the solution:
If you’re using imports from @babylonjs/core for webgpu, you’ll need to manually import the uniformBuffer extension as well. It’s needed for the engine to function.
import { WebGPUEngine } from '@babylonjs/core/Engines/webgpuEngine';
import "@babylonjs/core/Engines/WebGPU/Extensions/engine.uniformBuffer";
Also be ready to include other Extensions as you add more features. These are all in Engines/WebGPU/Extensions. @mise, above, is using a few more than just the uniformBuffer and I will be as well once I get this back in to my main codebase.