Bug 227585 - For large WebGL contexts, WebGL is spending a lot of time in allocating new Metal textures for default frame buffer backing store
Summary: For large WebGL contexts, WebGL is spending a lot of time in allocating new M...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on: 227582
Blocks:
  Show dependency treegraph
 
Reported: 2021-07-01 08:14 PDT by Kimmo Kinnunen
Modified: 2021-07-01 08:18 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kimmo Kinnunen 2021-07-01 08:14:59 PDT
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
Comment 1 Radar WebKit Bug Importer 2021-07-01 08:15:26 PDT
<rdar://problem/80024974>
Comment 2 Kimmo Kinnunen 2021-07-01 08:15:44 PDT
Reproducible at least on MacBookPro19,1 Intel/AMD.
Metal selects Intel always.
Comment 3 Kimmo Kinnunen 2021-07-01 08:18:37 PDT
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 ....)