Hello,
In my code, I am trying to do the following:
if (supportsWebGPU) {
engine = new WebGPUEngine(canvas);
await engine.initAsync();
}
else {
engine = new Engine(canvas);
}
const scene = new Scene(engine);
MeshBuilder.CreateSphere("sphere", { diameter: 1 }, engine);
Whenever a users’ browser supports WebGPU, I want it to use the WebGPUEngine instead of the regular Engine. With this comes my first question: How do I detect if a users’ browser supports WebGPU?
My second quesiton is; is there a difference in the way the Engine and WebGPUEngine classes are handled? Or can you simply switch them out with the same code, like in the snippet above? (Stability aside)
Checking whether WebGPU is supported should be possible via BABYLON.WebGPUEngine.IsSupportedAsync (a static property), according to the API docs.
Since this is a pretty basic thing to worry about when it comes to using the feature, maybe this should be covered in the WebGPU section of the docs? They seem a bit WIP and unfinished, so maybe that’s why it’s not mentioned anywhere (or it’s there and I just didn’t find the info).
I really like this solution, the less lines the merrier, but the method seems to return a ThinEngine, which can not be converted to Engine or WebGPUEngine. Any clue on how to convert ThinEngine to a regular one?
ThinEngine is a more general (abstract) class than Engine or WebGPUEngine. I don’t think it’s possible to reverse the abstraction since you’d have to add the missing functionality back in, at which point you might as well create a WebGPUEngine to begin with…
Don’t take my word as gospel, I’m going purely by the info provided in the docs. It sounds like the engine returned might even have all the required functionality (if it’s supported), but you mentioned that you want a different return type. Have you tried using the ThinEngine for WebGPU features to see if it it works similarly when WebGPU is supported?
Ah, it does seem to be working, I just messed something else up elsewhere. I guess its just a typing issue, it will be solved in the next release according to sebavan tho, thanks for the help!