Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGL2 backend #1617

Closed
kvark opened this issue Jul 8, 2021 · 15 comments
Closed

WebGL2 backend #1617

kvark opened this issue Jul 8, 2021 · 15 comments
Labels
area: api Issues related to API surface help required We need community help to make this happen.

Comments

@kvark
Copy link
Member

kvark commented Jul 8, 2021

Is your feature request related to a problem? Please describe.
The new GLES3 backend landed in #1510
Now we need to enable the Web target for WebGL2.

Describe the solution you'd like
On "wasm32-unknown-unknown" target the GLES backend should target WebGL2, just like the old "gfx-backend-gl" did.

Describe alternatives you've considered
Having a separate feature for this, may still be a good idea in order to help the cargo-vendor volume.

Additional context
Required for Bevy

@kvark kvark added help required We need community help to make this happen. area: api Issues related to API surface labels Jul 8, 2021
@zicklag
Copy link
Contributor

zicklag commented Jul 16, 2021

I'm going to start working on this as I have the time. So far I got it compiling, but haven't tested it yet.

@zicklag
Copy link
Contributor

zicklag commented Jul 16, 2021

Got the hello-triangle example working on web. So far it's the only example running, and I may have to figure out how to calculate certain hardware limits that I am just guessing at so far, but it's a good sign. 😄

image

And now with naga we don't have to bundle the WASM build of spirv_cross! So nice. :)

@kvark
Copy link
Member Author

kvark commented Jul 16, 2021

It would be very useful to get in touch with you on more immediate channels than Github. Please consider joining Matrix or Discord!

@Gordon-F
Copy link
Contributor

@zicklag Hi! A couple of notes, that, maybe, helps you a little bit with your journey :)

  1. Bring WebGL related fixes, that are presented in gfx-backend-gl, but not present in wgpu-hal:
  1. 2 debugging tools (idk, maybe these are the only 2 existing useful debugging tools for webgl 😢)
  • SpectorJS
  • webgl-lint. I recommend disabling throwOnError first. And you can safely ignore all errors like glAnyFunction(None) because wasmbindgen send None as undefined, but webgl-lint required null.

@zicklag
Copy link
Contributor

zicklag commented Jul 17, 2021

Got some help on Matrix ( thanks guys! ), and with gfx-rs/naga#1100 the shader problem I was stuck on was fixed.

After that I got to a blank screen for the cube example ( no more panic! ):

image

It's got an invalid operation I've got to investigate, but we got past the shader problems!

@Gordon-F
Copy link
Contributor

@zicklag This was fixed in gfx-rs/gfx#3682.

From WebGL docs:

Only one target can be bound to a given WebGLBuffer. An attempt to bind the buffer to another target will throw an INVALID_OPERATION error and the current buffer binding will remain the same.

I guess, you can use gfx-backend-gl solution as is in wgpu-hal. https://github.com/gfx-rs/gfx/blob/master/src/backend/gl/src/queue.rs#L621-L665

@zicklag
Copy link
Contributor

zicklag commented Jul 17, 2021

@Gordon-F Ah, cool, thanks. I had already started copying that code from the gfx backend. So far grabbing the gfx-backend-gl code every time something goes wrong is working pretty well. 😁


And...We've got a cube!

image

Apparently my browser is using mesa for the WebGL implementation and runs into the same fastclear bug ( #1627 ), but I think something else is wrong, too, because the color is still wrong with fastclear disabled. I'm going to look into that a little more.

Also, a quick test of the shadow example yields:

image

@cwfitzgerald
Copy link
Member

The fact the error is talking about the vertex stage is erroneous. As it stands now, the shadow example cannot run on WebGL at all as it uses SSBOs and WebGL doesn't support SSBOs.

That being said, it doesn't actually need to use SSBOs, it could totally use a uniform buffer for what it is doing.

@zicklag
Copy link
Contributor

zicklag commented Jul 17, 2021

That being said, it doesn't actually need to use SSBOs, it could totally use a uniform buffer for what it is doing.

Would it be good to switch it to a uniform for web and desktop, or do we want it using SSBOs for the sake of demonstrating GPU features?

@kvark
Copy link
Member Author

kvark commented Jul 17, 2021 via email

@zicklag zicklag mentioned this issue Jul 17, 2021
7 tasks
@zicklag
Copy link
Contributor

zicklag commented Jul 28, 2021

If you compile WGPU for web, how do we want to indicate that you want support for WebGPU or WebGL or both?

Right now if you compile for web, it just assumes WebGPU and there's no way to disable it ( if I've interpreted that correctly ). Since it's just passthrough to the browser is that probably fine, or do we want a webgpu feature flag so that you could choose just to target WebGL?

Also, if we pass in the WebGL flag do we want it to keep the WebGPU backend, too. So that, unless otherwise specified by the user's Backends selection, it will try to use WebGPU and fall back to WebGL?


On a related topic, does anybody else get a problem trying to compile WGPU master for WASM? I'm getting tons of errors like the web-sys features are not properly activating somehow and all of the GPU types are missing.

cargo build --target wasm32-unknown-unknown --example shadow
error[E0432]: unresolved import `web_sys::GpuTextureFormat`
   --> wgpu/src/backend/web.rs:461:9
    |
461 |     use web_sys::GpuTextureFormat as tf;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `GpuTextureFormat` in the root

Edit: Building the docs with the following command also only shows so many types enabled. I wonder if it's like winit's selected features are the only ones being applied. Maybe this has something to do the Cargo resolver version 2.

 cargo doc -p web-sys --no-deps --target wasm32-unknown-unknown --open

image


Edit2: Now I'm even more confused. CI seems to be running just fine, but I can't get this command to complete locally without tons of errors:

cargo +1.53.0 clippy --target wasm32-unknown-unknown -p wgpu -- -D warnings

@grovesNL
Copy link
Collaborator

@zicklag

Since it's just passthrough to the browser is that probably fine, or do we want a webgpu feature flag so that you could choose just to target WebGL?

IMO it should be the other way around, so people would opt-in to using WebGL as fallback somehow and we always assume WebGPU is available by default. We had a feature for opting into WebGL previously but not sure if it's still there after the gfx-hal -> wgpu-hal migration.

On a related topic, does anybody else get a problem trying to compile WGPU master for WASM? I'm getting tons of errors like the web-sys features are not properly activating somehow and all of the GPU types are missing.

You need to use RUSTFLAGS=--cfg=web_sys_unstable_apis, see https://github.com/gfx-rs/wgpu/wiki/Running-on-the-Web-with-WebGPU-and-WebGL#compiling-for-wasm

@zicklag
Copy link
Contributor

zicklag commented Jul 28, 2021

You need to use RUSTFLAGS=--cfg=web_sys_unstable_apis

Ah, that works!

IMO it should be the other way around,

The only issue I have with that is actually that building the WebGPU wrapper requires that web_sys_unstable_apis flag. For now, because WebGPU isn't even available in normal browsers yet, it seems like having a default feature that requires an unstable flag when targeting web isn't ideal. That would require everybody who wants to build for WebGL to add the extra rustc flag, even though they aren't practically using it.

@andrewvarga
Copy link

Hi all! I asked this on the Wgpu Users channel but maybe it's better to track on github:
https://matrix.to/#/!XFRnMvAfptAHthwBCx:matrix.org/$xqMiU6EZP9Vk4K1Rl7VDxmXiXeeAvqdcIYeau80gNSY?via=matrix.org&via=mozilla.org&via=kyju.org

In short, I'm just curious if the WebGL2 backend is considered stable enough for production at this point, and if it is maybe I'm doing something wrong?
Something as simple as using a uniform buffer to set the color of a triangle seems not to work when target is WebGL2, and the official examples have problems on my end.

@zicklag
Copy link
Contributor

zicklag commented Aug 30, 2022

Replied in a new discussion: #3003 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: api Issues related to API surface help required We need community help to make this happen.
Projects
None yet
Development

No branches or pull requests

6 participants