RESOLVED FIXED300085
[GTK][WPE] OpenGL assets created by WebGL are not released when destroying the WebGLRenderingContext
https://bugs.webkit.org/show_bug.cgi?id=300085
Summary [GTK][WPE] OpenGL assets created by WebGL are not released when destroying th...
Miguel Gomez
Reported 2025-10-03 02:28:33 PDT
Time ago WebGLRenderingContext kept track of the OpenGL assets created through WebGL and would destroy them when the context was destroyed. Then https://commits.webkit.org/266910@main removed this feature, and WebGLRenderingContext now just forgets about the OpenGL resources instead of specifically destroying them. This is done under the assumption that when destroying the underlying GLContext, those resources are automatically released. While this assumption is true in many cases it's not for the GTK and WPE ports because we're using sharing GLContexts in order to share textures from the WebGL GLContext to the compositor GLContext. This means that the resources allocated by those sharing contexts are not automatically released until all of the sharing contexts are destroyed. And our main sharing GLContext is a singleton, so the resources are not destroyed until the process exits. This means that while navigating using the same process, we're accumulating more and more GL resources as long as we're visiting WebGL pages. This happens also when using the GBM integration with ANGLE. Despite we don't need to use sharing contexts in that case, cause we share textures through dmabuf, we're using them anyway because GraphicsContextGLTextureMapperGBM uses the same initialization as GraphicsContextGLTextureMapperANGLE, which uses the sharing context.
Attachments
Miguel Gomez
Comment 1 2025-10-03 02:37:36 PDT
I think we can fix this without having to keep track of the OpenGL assets ourselves by leveraging ANGLE, cause it already keeps track of the assets created in its contexts and destroys them when the context is destroyed. At the ANGLE level we have the same problem with the sharing contexts than at the OpenGL level. If the ANGLE context is sharing with another ANGLE context, the last destroyed context will be the one destroying the remaining assets. And we're using another ANGLE sharing context that's a singleton, so we would have the same problem than with OpenGL. But we don't need the ANGLE sharing context to be a singleton. We can make each WebGLRenderingContext to have their own ANGLE context and ANGLE sharing context and destroy both so the resources are released. Making the ANGLE sharing context not a singleton means that if we have several WebGLRenderingContext instances at the same time, each of them will have an ANGLE sharing context wrapping the same OpenGL sharing context (our main sharing context), but this doesn't seem to be a problem because ANGLE sharing context seems to be only keeping track of the resources, and it never makes the underlying context current.
Miguel Gomez
Comment 2 2025-10-03 03:56:11 PDT
EWS
Comment 3 2025-10-06 00:21:00 PDT
Committed 301043@main (1d16639f9d57): <https://commits.webkit.org/301043@main> Reviewed commits have been landed. Closing PR #51738 and removing active labels.
Ian Grunert
Comment 4 2025-10-10 13:39:04 PDT
This change caused a regression on Windows; I've opened a PR to fix it by restoring the old behavior on Windows. https://bugs.webkit.org/show_bug.cgi?id=300457
Note You need to log in before you can comment on or make changes to this bug.