<?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>227585</bug_id>
          
          <creation_ts>2021-07-01 08:14:59 -0700</creation_ts>
          <short_desc>For large WebGL contexts, WebGL is spending a lot of time in allocating new Metal textures for default frame buffer backing store</short_desc>
          <delta_ts>2021-07-01 08:18:37 -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>WebGL</component>
          <version>WebKit Local Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>227582</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kimmo Kinnunen">kkinnunen</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dino</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>kpiddington</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1774115</commentid>
    <comment_count>0</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2021-07-01 08:14:59 -0700</bug_when>
    <thetext>For large WebGL contexts, WebGL is spending a lot of time in allocating new Metal textures for default frame buffer backing store

Conditions:
1. Somewhat large WebGL context (e.g. fullscreen MacBookPro19,1 3072x1920)
2. Somewhat non-trivial amount of WebGL drawing (e.g. converting 4K video to texture via texImage2D and drawing it)

Causes a scenario where somehow WindowServer does not let the WebGL display buffers go, e.g. the IOSurface IsInUse property remains false when WebGL tries to obtain a new drawing buffer.

This causes WebGL to allocate a new drawing buffer.


Allocating the IOSurface seems to be fast, but then creating a Metal texture out of it seems to be slow.

Sampling reveals a lot of samples in [MTL...Device newTextureWithDescriptor:iosurface:plane:]


Reproable for example in 4k 360 YouTube: 
 - https://www.youtube.com/watch?v=HKNI658SKJ4
 - Let it load and observe sharp rendering
 - Stop the video
 - Rotate the video around with WASD keys
 - Vary the window size: small sized windows are smooth, large sized windows start to skip frames</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1774116</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-07-01 08:15:26 -0700</bug_when>
    <thetext>&lt;rdar://problem/80024974&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1774118</commentid>
    <comment_count>2</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2021-07-01 08:15:44 -0700</bug_when>
    <thetext>Reproducible at least on MacBookPro19,1 Intel/AMD.
Metal selects Intel always.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1774120</commentid>
    <comment_count>3</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2021-07-01 08:18:37 -0700</bug_when>
    <thetext>Sample Count, Samples %, Normalized CPU %, Symbol
1367, 8.7%, 1.8%, WebCore::Document::prepareCanvasesForDisplayIfNeeded() (in WebCore)
1234, 7.8%, 1.6%,     WebCore::GraphicsContextGLOpenGL::prepareForDisplay() (in WebCore)
1100, 7.0%, 1.4%,         WebCore::GraphicsContextGLOpenGL::allocateAndBindDisplayBufferBacking() (in WebCore)
1100, 7.0%, 1.4%,             EGL_BindTexImage (in libANGLE-shared.dylib)
1100, 7.0%, 1.4%,                 egl::Surface::bindTexImage(gl::Context*, gl::Texture*, int) (in libANGLE-shared.dylib)
1063, 6.7%, 1.4%,                     rx::IOSurfaceSurfaceMtl::bindTexImage(gl::Context const*, gl::Texture*, int) (in libANGLE-shared.dylib)
1054, 6.7%, 1.4%,                         rx::IOSurfaceSurfaceMtl::ensureColorTextureCreated(gl::Context const*) (in libANGLE-shared.dylib)
1004, 6.4%, 1.3%,                             -[MTL..AccelDevice newTextureWithDescriptor:iosurface:plane:] (in ....)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>