<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>300085</bug_id>
          
          <creation_ts>2025-10-03 02:28:33 -0700</creation_ts>
          <short_desc>[GTK][WPE] OpenGL assets created by WebGL are not released when destroying the WebGLRenderingContext</short_desc>
          <delta_ts>2025-10-13 01:53:03 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WPE WebKit</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=300614</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Miguel Gomez">magomez</reporter>
          <assigned_to name="Miguel Gomez">magomez</assigned_to>
          <cc>bugs-noreply</cc>
    
    <cc>ian.grunert</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2148076</commentid>
    <comment_count>0</comment_count>
    <who name="Miguel Gomez">magomez</who>
    <bug_when>2025-10-03 02:28:33 -0700</bug_when>
    <thetext>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&apos;s not for the GTK and WPE ports because we&apos;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&apos;re accumulating more and more GL resources as long as we&apos;re visiting WebGL pages.

This happens also when using the GBM integration with ANGLE. Despite we don&apos;t need to use sharing contexts in that case, cause we share textures through dmabuf, we&apos;re using them anyway because GraphicsContextGLTextureMapperGBM uses the same initialization as GraphicsContextGLTextureMapperANGLE, which uses the sharing context.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2148079</commentid>
    <comment_count>1</comment_count>
    <who name="Miguel Gomez">magomez</who>
    <bug_when>2025-10-03 02:37:36 -0700</bug_when>
    <thetext>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&apos;re using another ANGLE sharing context that&apos;s a singleton, so we would have the same problem than with OpenGL. But we don&apos;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&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2148091</commentid>
    <comment_count>2</comment_count>
    <who name="Miguel Gomez">magomez</who>
    <bug_when>2025-10-03 03:56:11 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/51738</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2148641</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-10-06 00:21:00 -0700</bug_when>
    <thetext>Committed 301043@main (1d16639f9d57): &lt;https://commits.webkit.org/301043@main&gt;

Reviewed commits have been landed. Closing PR #51738 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2150056</commentid>
    <comment_count>4</comment_count>
    <who name="Ian Grunert">ian.grunert</who>
    <bug_when>2025-10-10 13:39:04 -0700</bug_when>
    <thetext>This change caused a regression on Windows; I&apos;ve opened a PR to fix it by restoring the old behavior on Windows.

https://bugs.webkit.org/show_bug.cgi?id=300457</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>