Early access to the new WebGPU backend

Question, if a browser does not support WebGPU, does Unity fallback to WebGL? Curious as the instructions at the start of this thread states to put WebGPU above WebGL in the web player build settings.

I’ll guess it’s like how in Android if u put Vulcan and then OpenGL it will fall back to the next in the list if it fails to initialize. The “danger” with adding WebGPU to project right now (in my opinion) is that your game might work great in WebGL already, but WebGPU support isn’t quite there yet or has bugs because it’s early days… although the browser technically supports it. So then your game loads up with WebGPU because it’s technically supported… but has issues compared to WebGL. So for production purposes / actual releases aside from testing things right now, might want to avoid it. Then again, if your game requires compute shaders, it won’t work in WebGL anyway, so no reason to also have WebGL unless you also create a fallback and check SystemInfo.supportsComputeShaders (which I hope is implemented in this case… where WebGPU will always be true and WebGL will be false… but wondering now, what if system actually doesn’t support compute shaders but browser does support WebGPU).

1 Like

@jonkuze The Graphics API list in the Web Player Settings says what graphics APIs will be included in the build. It will start at the top of the list, check for support of that, and if not supported check the next in the list.

So you can include both WebGPU and WebGL in a build. Add WebGPU, move it to the top of the list, leaving WebGL2 second in the list. Now if a browser doesn’t support WebGPU (first in the list), it will fall back to WebGL2. You can check this by testing the build in both Chrome (supporting WebGPU) and Firefox (currently doesn’t have WebGPU enabled).

This will include both WebGPU and WebGL compiled shaders in the build, so the build will be somewhat bigger.

As @adamgolden said, if you include things that can only be done in WebGPU like Compute shaders, you should check for support using the SystemInfo and have an alternative solution for cases that do not support that feature.

3 Likes

@brendanduncan_u3d @adamgolden thanks soo much for the responses! I’m honestly not too concerned with having backwards compatibility with WebGL as long WebGPU yields the performance boosts i’m hoping for.

Currently, I’m limited to 20 animated skinned meshes in a scene. If I go anywhere above that performance drops drastically. Even with the current 20, i’m seeing big fluctuation between 40 - 60 FPS during gameplay on WebGL on a laptop that can probably run some AAA games at high graphic settings.

Eventually all browsers will catchup in the coming year or two… so I’m not too concerned with backwards compability. I was just curious if fallback to WebGL was even possible, not that I really need it. I really want the best performance possible for my web game, and I’m totally OK with going to go through the WebGPU development growing pains with you all lol. I’m in no absolute rush!

1 Like

By the way, I hope it’s OK to share here. I’m apart of a really cool Discord server that has about 1,200 members all focused of Web Game Development here Discord. Most of the devs use various Javascript-based engines but the server also welcomes Unity and other native engines that export to WebGL / WebGPU. Feel free to join up and share what your working on. = )

3 Likes

Hi everyone, recently I’m uploading to the Facebook Instant platform my game using WebGPU. On Android devices, the game works normally, but on iPhone, it shows errors as shown below. Can anyone help me

Hi! What’s the status of Chrome Canary for mobile in this matter? Have you tried anything so far? We are trying to run some tests but I also got the black screen after loading (webGPU api only). We are using 2023.3.0b1

Cheers

Chrome for Android will ship with WebGPU support sometime this month, allegedly.
Chrome Canary for Android currently has WebGPU support, but you need to enable it from chrome://flags.
Apple mobile requires WebKit to ship with WebGPU support, which is still quite a bit aways (but being actively worked on by Apple).

1 Like

Does your build have both WebGPU and WebGL enabled? On Android and iPhone, it should fall back to WebGL, given they don’t support WebGPU currently.

1 Like

Yes, i did. But on Android, it shows errors as shown below. What does it mean? Does it mean that it did not fall back to WebGL?
9584014--1357429--upload_2024-1-16_14-41-30.png

@duytin095 Indeed it did fail to fall back to WebGL. I haven’t checked Android in a bit, but it would seem Android is currently in a bad state for WebGPU, likely pending the upcoming update that will have it enabled. We check for the existence of the navigator.gpu browser object to know if the browser supports WebGPU. From that message, it would seem Android Chrome is saying the navigator.gpu object is defined, but they have it error on creation. Unfortunately if the browser is lying about it’s support of WebGPU, it might be a little too late in the initialization to fall back to WebGL at that point. I’ll take a look at the current state of Android.

1 Like

WebGPU for Android has officially arrived! Note that it only supports devices running Android 12 and newer:

5 Likes

Besides rendering changes are there any WebGPU abilities that could help with math or physics calculations?

I added webGLEnableWebGPU: 1 to the projectSettings.asset after forcing it to be text instead of binary which took a few restarts for some reason and throwing out the original file. I also added universal rendering pipeline. But in the player settings–>other after unchecking autoGraphics there is only webgl2 not a WebGPU option. This is using unity 2023.0b3 on a mac.

No, just graphics. You’ll eventually be able to use VFX Graph, and it will help with skinned animation since it can use compute shaders for that, but it won’t help with CPU intensive calculations like physics.

I’m not sure why you’re not seeing WebGPU after setting webGLEnableWebGPU, and I’m not sure why your system thought it was a binary file, but it seems like it could be related.

Your clue helped. I looked at the file again and it had been overwritten. This time the parameter was there and set to 0, so I changed to 1 and it worked.

1 Like

Hey everyone, has anyone had any issues hosting a Unity URP WebGPU example on anything other than localhost (over HTTP)? I know non-HTTPS is not recommended, but I’m just using this for testing rather than setting up a cert at this time. I’ve enabled “Allow downloads over HTTP: Always Allowed”.

Under the latest Edge (Windows 11) and Google Chrome Unstable (Ubuntu 22.04 LTS) (with the --enable-unsafe-webgpu flags, etc), it seems the GPU device doesn’t initialize properly:

9600185--1360847--ksnip_20240123-154102.png

Unless the URL is localhost or 127.0.0.1. If I even just use my device’s internal 192.168 internal IP address, I get this NullGfxDevice issue, and of course none of the shaders support the null GPU, so the example never fully loads. I’m just using the URP 3D template with Render Graph disabled (compatibility). I tried adding CORS headers, etc, but no luck yet.

@davedc2 I think WebGPU needs HTTPS by the browser. localhost always exempts those requirements.

There have been a number of reports of the WebGPU builds having an error saying the Adapter is null, and not falling back to WebGL when that happens. I have a fix for that which I’ll get into the main Unity branch and will go out in an update whenever that happens.

Ah figures, thanks! I’ll give that a try

Edit: This fixed it, thank you very much :):):slight_smile:

I did disable the WebGL 2 fallback, so no worries there.

1 Like