# Electron + BabylonJS + WebGPU not working yet

**URL:** <https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544>\
**Category:** Questions\
**Tags:** webgpu\
**Created:** [September 3, 2021, 11:05am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544 "2021-09-03T11:05:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mise](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mise/32/37506_2.png) [@mise](https://forum.babylonjs.com/u/mise)\
**Post date:** [September 3, 2021, 11:05am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/1 "2021-09-03T11:05:49Z")

</div>

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/2/c27986ebe8528e8e29a1eb6b34ff2febaebd97c9.png)

I know this problem could well be on the part of Electron, but I got this one working – [Rotating Cube - WebGPU Samples](https://austin-eng.com/webgpu-samples/samples/rotatingCube), 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:

> **[GitHub - Mise22/electron-babylonjs-webgpu](https://github.com/Mise22/electron-babylonjs-webgpu)**
>
> Contribute to Mise22/electron-babylonjs-webgpu development by creating an account on GitHub.

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

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [September 3, 2021, 11:19am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/2 "2021-09-03T11:19:50Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 3, 2021, 11:47am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/3 "2021-09-03T11:47:59Z")

</div>

I don’t know Electron unfortunately…

We have pushed this fix lately:

> <https://github.com/BabylonJS/Babylon.js/pull/10982>
>
> Simplifies the twgsl export to make it more es build friendly

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.

---

<div class="post-metadata">

**Author:** ![mise](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mise/32/37506_2.png) [@mise](https://forum.babylonjs.com/u/mise)\
**Post date:** [September 3, 2021, 11:57am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/4 "2021-09-03T11:57:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeremy-coleman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeremy-coleman/32/15493_2.png) [@jeremy-coleman](https://forum.babylonjs.com/u/jeremy-coleman)\
**Post date:** [September 4, 2021, 2:33am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/5 "2021-09-04T02:33:21Z")

</div>

@Evgeni_Popov [https://github.com/jeremy-coleman/OceanDemo](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.

---

<div class="post-metadata">

**Author:** ![mise](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mise/32/37506_2.png) [@mise](https://forum.babylonjs.com/u/mise)\
**Post date:** [September 4, 2021, 8:19am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/6 "2021-09-04T08:19:14Z")

</div>

in addition to the obvious caching issues I also had CORS issues with loading ‘[https://preview.babylonjs.com/...js](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.

---

<div class="post-metadata">

**Author:** ![jeremy-coleman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeremy-coleman/32/15493_2.png) [@jeremy-coleman](https://forum.babylonjs.com/u/jeremy-coleman)\
**Post date:** [September 5, 2021, 3:44am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/7 "2021-09-05T03:44:25Z")

</div>

@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.

> **[noclip.website/rust at master · magcius/noclip.website](https://github.com/magcius/noclip.website/tree/master/rust)**
>
> master/rust

> **[GitHub - pjoe/wasm-shaders: Created with CodeSandbox](https://github.com/pjoe/wasm-shaders)**
>
> Created with CodeSandbox. Contribute to pjoe/wasm-shaders development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![mise](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mise/32/37506_2.png) [@mise](https://forum.babylonjs.com/u/mise)\
**Post date:** [September 6, 2021, 8:14am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/8 "2021-09-06T08:14:27Z")

</div>

I don’t know anything about what you’re mentioning 🙂

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 6, 2021, 2:09pm UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/9 "2021-09-06T14:09:48Z")

</div>

> [@jeremy-coleman](#):
>
> but i found that webgpu/wgsl changes somewhat frequently

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.

> [@jeremy-coleman](#):
>
> 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.

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).

---

<div class="post-metadata">

**Author:** ![jeremy-coleman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeremy-coleman/32/15493_2.png) [@jeremy-coleman](https://forum.babylonjs.com/u/jeremy-coleman)\
**Post date:** [September 7, 2021, 4:17am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/10 "2021-09-07T04:17:43Z")

</div>

You are a scholar and a gentleman

---

<div class="post-metadata">

**Author:** ![jeremy-coleman](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jeremy-coleman/32/15493_2.png) [@jeremy-coleman](https://forum.babylonjs.com/u/jeremy-coleman)\
**Post date:** [September 13, 2021, 2:23am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/11 "2021-09-13T02:23:25Z")

</div>

@mise @Evgeni_Popov

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

```auto
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:

```bash
--enable-features=SharedArrayBuffer

```

---

<div class="post-metadata">

**Author:** ![mise](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mise/32/37506_2.png) [@mise](https://forum.babylonjs.com/u/mise)\
**Post date:** [September 13, 2021, 6:16am UTC](https://forum.babylonjs.com/t/electron-babylonjs-webgpu-not-working-yet/23544/12 "2021-09-13T06:16:33Z")

</div>

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.
