I know this is kind of a goofy request as WebGPU itself is meant to run web "natively", but given that it is currently still in development on all browsers (according to the Chrome Platform Status) and gfx-backend-gl supports WebGL, would it be reasonable to have wgpu support a WebGL backend?
I imagine that this could be beneficial for those targeting WebGPU but want to run on browsers that only support WebGL.
Thanks for your time!
OpenGL backend is kinda rough for gfx-rs, but we are getting there. It's certainly a good feature (if not requirement) to have for wgpu-rs - ability to target GL/WebGL. If you want to help out, please talk to us on gitter/zulip. Basically, one can start adding the backend support today. It would be best, of course, to do this after GL backend is better aligned with the others (i.e. no longer using the Backbuffer::Framebuffer enum).
Is there any progress on this?
GL backend is progressing slowly but steadily, more info here: #450
GL support has landed in #907
We can now start playing with targeting WebGL from here
I鈥檓 trying to progress on this issue, but it seems very difficult to deal with the Surface being the Instance in the backend-gl.
Should I modify the backend-gl itself ?
I don't know if it would be possible to separate the Surface and Instance in the GL backend for WebGL target specifically... but be our guest and check it out. More eyes on it are direly needed.
Here is my problem :
wgpu-core::Instance struct needs a gfx_backend_gl::Instance,
wgpu-core::Surface struct needs a gfx_backend_gl::Backend::Surface,
Since hal::Instance trait is implemented by gfx_backend_gl::Backend::Surface when in wasm target, I used gfx_backend_gl::Backend::Surface instead of gfx_backend_gl::Instance in wgpu-core::Instance.
But wgpu-core::Surface also needs the same gfx_backend_gl::Backend::Surface that can鈥檛 be owned twice.
I miss some deep knowledge of wgpu-core architecture to go further.
@kvark any advice ?
How about this plan. We can change the gfx-backend-gl WASM backend to avoid that weird Instance implementation for a Surface. Instead, the Instance could be basically a dummy by itself until create_surface is called. I.e.:
struct Instance {
surface: Option<Arc<SurfaceInner>>,
}
So it would be created with None, and the only valid thing you'd be able to do with it is create_surface, at which point instance gets initialized properly with a WebGL context. Then you'd be able to use it as a normal instance. So the API would be aligned to the rest of gfx backends (including EGL part of GL backend), but with a few extra limitations:
create_surfaceenumerate_adapters before the instance is initialized would return an empty listDoes that sound approachable to you? Would you be able to jump on "#gfx:matrix.org" or "#wgpu:matrix.org" to discuss?
Seems clear to me !
If needed, I鈥檒l come on "#gfx:matrix.org" to discuss ;)
This is available now. Obviously has issues, but hello-triangle works.
Most helpful comment
GL support has landed in #907
We can now start playing with targeting WebGL from here