Electron + BabylonJS + WebGPU not working yet

I know this problem could well be on the part of Electron, but I got this one working – Rotating Cube - WebGPU Samples, so I started by posting it here. Hopefully I can get some insight.

In case it is helpful, I created a repo with a simple Electron + webgpu setup:

if compilation fails you might need to edit index.d.ts with: export const api: any;

pinging @Evgeni_Popov

Seems like WebGPU is available, but the wasm for twgsl was not loaded correctly. But I am sure he will have a better answer :slight_smile:

I don’t know Electron unfortunately…

We have pushed this fix lately:

Are you sure the cache of the browser has been reset and the latest versions of twgsl.js/twgsl.wasm have been loaded? I think it could be the explanation.

3 Likes

oh, wow, that was a really good call and a timely fix :slight_smile:

1 Like

@Evgeni_Popov https://github.com/jeremy-coleman/OceanDemo . Not done with what I’m experimenting with so its pretty messy, but it works. just npm i npm run start. It’s using nightly build of electron, so v16 atm . I was pinning to v14 before, which is the first version of electron that added webgpu, but i found that webgpu/wgsl changes somewhat frequently for arbitrary pedantic bullshit like the name of a variable with no functionality changes , so it’d often work in electron then not in the browser any more , which is enraging. I also swapped out webpack for vite.

in addition to the obvious caching issues I also had CORS issues with loading ‘https://preview.babylonjs.com/...js’ files on the fly. So I decided to host the glslang.js etc on my own server.

@Evgeni_Popov I’m assuming this is a temporary way of including these scripts? Let me know if you want me to create an issue.

@mise do you know if its possible / how to enable spirv shaders in electron? Also, any thoughts on how to make it permanent , because google is gonna take it out / already has. I really really dont want to deal with wgsl shit for the next 2+ years. The glslang wasm compiler isn’t really going to be effective if it compiles glsl to an ever-changing wgsl spec. Also naga is another option now.

Side note: Ofc, I dont think this is ideal for electron, but probably best for the web.

I don’t know anything about what you’re mentioning :slight_smile:

The spec of WebGPU/WGSL is not final yet, so it’s expected to have some changes, but there normally should be less and less as we are gearing to v1 release.

@mise We should not have CORS issues when including these files: are you able to setup a repro? The Playground are linking to those files and it does work as expected.

In Babylon we are currently using glslang + Tint wrapped in a WASM module to convert from glsl to spir-v (glslang) and spir-v to wgsl (Tint). We are evaluating the possibility to use Naga in a WASM module instead of glslang+Tint, mostly to have a lighter dependency (currently, glslang+Tint ASM = around 2Mbytes).

We are also adding support for native WGSL in ShaderMaterial so that you are able to use features specific to WGSL (like external textures).

4 Likes

You are a scholar and a gentleman

1 Like

@mise @Evgeni_Popov

here is a working fix that doesnt have any csp requirements.

import { app } from 'electron';
app.commandLine.appendSwitch('enable-features', "SharedArrayBuffer")
app.commandLine.appendSwitch('enable-unsafe-webgpu')

you can also launch electron or chrome using the flag:

--enable-features=SharedArrayBuffer
1 Like

yes, it’s connected to the SharedArrayBuffer and COEP/CORP stuff. But I’m also running on the web, so can’t rely on electron features.