servo/surfman

Use texture sharing instead of shared GL context

jdm opened this issue · 5 comments

jdm commented

This would avoid #82 and give us fast WebGL rendering on macOS (per servo/servo#11138 (comment)), as well as the benefits described by servo/rust-webvr#54 (comment).

The root of the problem is that Servo used shared OpenGL contexts to share WebGL textures
instead of using texture primitives that could be shared among different threads/processes
without requiring a shared GL context (e.g. SurfaceTextures on Andriod, IOSurface on Mac, etc)

We also need a SurfaceTexture on Android.

For Firefox Reality immersive mode we need a SurfaceTexture on Android.

I think this would be the approach for Servo immersive mode on Android:

  • Create a render target to a GL_EXTERNAL_TEXTURE_2D with its SurfaceTexture instead of a GL_TEXTURE_2D in Servo WebGLContext
  • WebRender should be updated to render using GL_EXTERNAL_TEXTURE_2D extension (for flat WebGL)
  • FxR can use the same SurfaceTexture for immersive mode. This works even if Servo is in another process so we don't need GL context sharing.

In order to share the SurfaceTexture, we need to share the java instance, it's not enough with the OpenGL texture id:

  • The global SurfaceTexture can be attached to different GL_textures depending on the GL context where its bound (e.g. it can use glTexId 2 in Webrender GL context, but 4 in FxR render context)
  • The textureId/texName for a SurfaceTexture can be changed by calling attachToGLContext so we can only share the java object reliably

It would be nice to combine the shared textures with this: #131