New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 741854 link

Starred by 4 users

Issue metadata

Status: WontFix
Owner:
OOO until 2019-01-24
Closed: Aug 3
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug

Blocking:
issue 713854



Sign in to add a comment

WebGL Stencil Buffer Leak

Project Member Reported by ericrk@chromium.org, Jul 12 2017

Issue description

Using WebGL apps on affected MacOS devices leads to leaking all stencil buffers.

Repro Steps:
1) Obtain an affected machine. Currently, the following machines have been confirmed to show the issue:
   MacBook Pro (Retina, 13-inch, Early 2015) (GPU ID 0x162b)
   MacBook Air (13-inch, Early 2015) (GPU ID 0x1626)
   MacBook Pro (Retina, 15-inch, Mid 2014) (GPU ID 0x0d26)
   MacBook Pro (Retina, 15-inch, Mid 2015) (GPU ID 0x0d26)
   Mac mini (Late 2014) (GPU ID 0x0a2e)
Although any machine with the above GPU IDs should repro.

2) Open Chrome and make not of the GPU process PID (via task manager).

3) Close all open Chrome windows (but not the app) and run the following command:
   vmmap -v {GPU Process ID} | grep IOKit | grep PURGE=N

The command should list a small number of entries (around 25). This is the baseline set of memory entries which we expect to remain constant with all windows closed, assuming no leak.

4) Open a Chrome incognito window and navigate to maps.google.com. I don't know why, but non-incognito windows aren't triggering the leak for me. It may be that my system is being opted in to a maps experiment or has cookies which are impacting how MapsGL renders.

5) Re-close all open Chrome windows (but not the app) and run the command from (3). This time, you should see 2-3 additional rows. On my system they are fairly large - the first bracketed number in each line (after the memory addresses) is around 20MB.

6) Repeat steps (4/5), each time, you should see between 40-60MB of memory leaked.


Notes:
Playing around with maps *can* cause this leak to grow more. Logging in and using the timeline view appears to trigger larger leaks (I saw ~1GB in a few minutes), but it's unclear to me exactly which actions are responsible.

Additionally, a custom WebGL app which just allocates, uses, and frees stencil buffers should cause the leak to become very obvious. Note that the stencil buffers must be used (bound and cleared is enough) or the leak won't occur.
 

Comment 1 by kbr@chromium.org, Jul 13 2017

Cc: cwallez@chromium.org geoffl...@chromium.org jmad...@chromium.org
Components: -Internals>GPU Blink>WebGL Internals>GPU>Internals
Status: Started (was: Assigned)
It looks like putting WebGL contexts into their own "real" OpenGL share group on the service side, by modifying GpuCommandBufferStub::Initialize (src/gpu/ipc/service/gpu_command_buffer_stub.cc) and creating a new gl::GLShareGroup if the share_command_buffer_stub is null, works around this bug.

I'm a little surprised this worked that easily -- doing this for all contexts broke Chrome's rendering, and it must be working because erikchen@ changed WebGL to prefer to use IOSurfaces for its back buffer, and these can be shared both across share groups and across processes.

CC'ing ANGLE folks as FYI. By the time MANGLE ships on macOS, hopefully 10.13 will have been out for a while so this sort of workaround won't be needed there.

Comment 2 by kbr@chromium.org, Jul 13 2017

Cc: ccameron@chromium.org
erikchen / ccameron: how viable is a workaround of this form, where if the avoid_stencil_buffers driver bug workaround is active, we require the CHROMIUM_image path to be taken in DrawingBuffer::CreateColorBuffer? I don't remember whether there are situations where other content on the page would somehow cause the WebGL DrawingBuffer to fall back to the texture-backed path.

Just perusing through the code a bit, the only times CHROMIUM_image are disabled are via:

1) Developer flag/command line flag.
2) host()->IsOffscreenCanvas(). The latter appears to still be an experimental technology.

As such, I think that forcing CHROMIUM_image for the workaround [which is to say, disabling WebGL if CHROMIUM_image isn't available] seems acceptable.

Comment 4 by kbr@chromium.org, Jul 14 2017

Talked with ccameron@ and piman@ at length about this.

It's not quite as simple as this in the general case. It's necessary not just to display WebGL's back buffer in the compositor, but also to support tex[Sub]Image2D from DOM sources. Some of these like canvases already prefer to use IOSurfaces as their backing stores, but not all.

It may be possible to add a new MailboxManager implementation that is specialized for passing IOSurfaces between contexts, and which calls CGLTexImageIOSurface2D in the receiving context when it's not in the same share group as the sending context. (It would use the GLImage APIs, but would only be used on Mac.) When passing regular textures, it would need to blit both into and out of an IOSurface in order to get a TEXTURE_2D texture on the other side.

macOS' OpenGL implementation has constraints like global flush ordering that would probably make this tractable. On other OSs, the cross-context sharing mechanisms have restrictions that make it hard to implement mailboxes' semantics. So any workaround like this would be heavily Mac-specific.

piman@ suggested to investigate whether Maps is allocating stencil buffers itself or whether the WebGL back buffer is leaking, which could inform a different workaround. Investigating that now.

Comment 5 by kbr@chromium.org, Jul 17 2017

Per logging, Maps is allocating its own depth/stencil renderbuffer (of type GL_DEPTH_STENCIL_OES) and attaching it to the GL_DEPTH_STENCIL_ATTACHMENT attachment point. Therefore, it would not work -- at least not easily -- to try to lazily allocate the stencil buffer.

The only feasible workaround at this point is to track the total amount of memory allocated for depth/stencil renderbuffers, computing an approximation of the amount of memory that has leaked at any point in time, and restarting the GPU process when all WebGL contexts have been released and the leak is more than a certain amount.

This week I'll be working with the Montreal team and unable to move this bug forward. If someone would like to take it and implement the above workaround please feel free.

Comment 6 by kbr@chromium.org, Jul 27 2017

Labels: -Pri-1 Pri-2
Status: Assigned (was: Started)
The only possible workaround for this is fairly drastic and I think that the stencil buffer leak associated with Google Maps is probably not the top issue affecting users. Consequently I'm downgrading this to P2.

Status: WontFix (was: Assigned)
This bug was fixed in Apple's graphics driver for 10.13. It's not worth the engineering effort to try to work around the bug in earlier OS releases.

Sign in to add a comment