servo / surfman

Accelerated offscreen graphics for WebGL
Apache License 2.0
172 stars 84 forks source link

Browser support #294

Closed KnorpelSenf closed 4 months ago

KnorpelSenf commented 4 months ago

I am interested in browser support for surfman. The README section about future work states

Support for running in a browser with WebAssembly.

I mainly have a number of questions about this. I have very limited experience with graphics libraries and virtually no experience with surfman, so bear with me if some questions have trivial answers or if the questions don't make sense :)

  1. It seems to me like browser support is still wanted, but nobody is working on it. Would you accept contributions?
  2. There's wgpu which provides a graphics API and that runs in the browser. My naïve understanding is that surfman can “just” wrap wgpu and thereby have browser support. How far off am I? What else is needed?
  3. The background of this issue is that I would like to use webrender to perform rendering in a browser. I imagine that if I can have surfman work in a browser, WR will work there, too. I also don't know a lot about webrender—is there a flaw in this assumption?

So in summary, in a few weeks time, I would like to attempt the following. Please stop me and tell me why that's a bad idea:

sagudev commented 4 months ago

I tired adding wgpu backend to surfman, but didn't get very far (I didn't have much time). I think that adding wgpu to surfamn shouldn't be that hard, but adding wgpu support would be a big project for itself. It was already attempted before, but with gfx-rs.

Somehow relevant is https://github.com/servo/servo/issues/21320, if we could somehow implement GLES on top of wgpu we get WR, surfman, webgl, ... everything we want. ANGLE already has wgpu (actually uses dawn, but I think wgpu and dawn can both be abstracted with wgpu-native ...) backend: https://github.com/google/angle/tree/main/src/libANGLE/renderer/wgpu

KnorpelSenf commented 4 months ago

I tired adding wgpu backend to surfman, but didn't get very far (I didn't have much time).

Is this code still public?

I think that adding wgpu to surfamn shouldn't be that hard, but adding wgpu support would be a big project for itself.

What do you mean, it is not that hard but at the same time it is a big project for itself?

Somehow relevant is servo/servo#21320, if we could somehow implement GLES on top of wgpu we get WR, surfman, webgl, ... everything we want. ANGLE already has wgpu (actually uses dawn, but I think wgpu and dawn can both be abstracted with wgpu-native ...) backend: google/angle@main/src/libANGLE/renderer/wgpu

Does that mean that all of these libraries would have to be compiled to WebAssembly? Is that feasible?

sagudev commented 4 months ago

Is this code still public?

I think it's lost, I do not have it on my machine nor my fork, but it was nothing so no real loss.

What do you mean, it is not that hard but at the same time it is a big project for itself?

Hard IMO.

I imagine that if I can have surfman work in a browser, WR will work there, too. I also don't know a lot about webrender—is there a flaw in this assumption?

I think that would not work like like that. Surfman only manages surfaces. WebRender does not depend on surfman to access GPU, it uses gleam to access OpenGL I think. Here is fork that has done gfx-rs work: https://github.com/szeged/webrender and they were paid by mozilla IIRC.

Does that mean that all of these libraries would have to be compiled to WebAssembly?

Not necessarily, you just need to link "gl-wgpu" with it. Something similar was done for vulkan: https://github.com/gfx-rs/portability.

KnorpelSenf commented 4 months ago

I think that would not work like like that. Surfman only manages surfaces. WebRender does not depend on surfman to access GPU, it uses gleam to access OpenGL I think.

Oh alright. I guess then the scope of this is very different from what I assumed (which is not surprising). Thanks for explaining! <3