Should we add wgpu support to webrender?

Wu Yu Wei published on
4 min, 638 words

I've been thinking about adding wgpu support whenever I need to mess around with rendering context and compositor of Servo. The core component of these parts is webrender and it uses OpenGL for graphics. While it works most of the time, it has many workarounds on different platforms. On Windows, it needs ANGLE to guarantee the GL version. On macOS, it stucks on version 4.1 forever since Metal has been the latest official support. It is also worrying that OpenGL hasn't been updated ever since because Khronos decideds to move on to Vulkan. Whenever I look into webrender, I also fear it will become the part that might be unable to maintain in one day. There are some solutions in my mind that we could take depending on the situations and the resources we could use.

Build on top of ANGLE

The easiest and minimum effort we could take is, of course, extending the support of ANGLE. Servo already uses it on Windows and has a fork called mozangle. It shouldn't be a problem to extend the support to other platforms. This should resolve the worry if macOS doesn't want to support CGL(legacy openGL) anymore.

However, there are some disadvantages that will restrict Servo's development. First is the binary size. Building the shared libraries of ANGLE are around 20MB of DLLs on Windows. If we extend to all platforms, Servo will increase this amount of size. And Servo already needs to include GStreamer and SpiderMonkey already. Another issue is moudlarity, keep using OpenGL means anyone who wish to adopt Servo need to use this graphic library. If you browse through Rust's GUI ecosystem, you can see many frameworks are migrating to wgpu. Some even don't have OpenGL support anymore. It will be a growing problem for people who wish to integrate Servo and many other crates.

Implement Compositor trait

If we are able to spare some resources to look into, I think the experiment we could do is implementing the Compositor trait. This is the trait for webrender managing surfaces and framebuffers. It can be None which is what Servo does, and it will let external usage to decide how to bind the buffers and surfaces. For Firefox, it does implement this trait instead.

The only issue I found is webrender still use OpenGL APIs internally. I'm not sure if wgpu has any interoperability to OpenGL. Perhaps it needs to lock into OpenGL backends as well. But this will circle back to the need of ANGLE or similar tools again.

Add wgpu version of Renderer

The one true solution in my opion is adding a wgpu version of Renderer to webrender if we have enough resource. While it sounds crazy because webrender is a huge project which is over 200k LOC, the GL usage is limited to Device and Renderer. Although they are still pretty large, I believe with someone who understand WebGPU, it can build the minimum support in reasonable amount of time. The only worrying is probably shader support. However, there're only a few shader in Servo. I also believe we are able to translate them.

If we can get the wgpu support, I believe it can bring lots of benefits to Servo ecosystem. For maintainers, it's already fewer workarounds need to worry about. This also means we can obtain better WebGPU support, because the current one needs to copy the buffer to openGL which is not ideal in terms of performance. And for the cummunity, it will be easier for people to integrate into other projects.