Bug 231011 - ScopedEGLDefaultDisplay should be removed
Summary: ScopedEGLDefaultDisplay should be removed
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kimmo Kinnunen
URL:
Keywords: InRadar
: 230951 (view as bug list)
Depends on:
Blocks: 231012
  Show dependency treegraph
 
Reported: 2021-09-30 01:33 PDT by Kimmo Kinnunen
Modified: 2021-10-07 10:43 PDT (History)
11 users (show)

See Also:


Attachments
Patch (61.00 KB, patch)
2021-09-30 01:50 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
Patch (61.13 KB, patch)
2021-09-30 10:03 PDT, Kimmo Kinnunen
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (61.55 KB, patch)
2021-09-30 10:26 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
Patch for landing (61.83 KB, patch)
2021-10-01 05:17 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
Patch for landing (61.67 KB, patch)
2021-10-01 07:00 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
Patch for landing (65.63 KB, patch)
2021-10-05 01:50 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
Patch for landing (61.83 KB, patch)
2021-10-06 04:27 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
Patch for landing (61.85 KB, patch)
2021-10-06 23:37 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kimmo Kinnunen 2021-09-30 01:33:58 PDT
ScopedEGLDefaultDisplay should be removed

It makes the use of EGLDisplays harder, especially in scenarios where there might be multiple EGLDisplays
Comment 1 Kimmo Kinnunen 2021-09-30 01:50:57 PDT
Created attachment 439708 [details]
Patch
Comment 2 Kimmo Kinnunen 2021-09-30 10:03:55 PDT
Created attachment 439749 [details]
Patch
Comment 3 Kimmo Kinnunen 2021-09-30 10:26:56 PDT
Created attachment 439755 [details]
Patch
Comment 4 Kenneth Russell 2021-09-30 13:31:30 PDT
Comment on attachment 439755 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439755&action=review

Looks good overall, and a good step toward better supporting multiple EGLDisplays. A couple of small naming suggestions, but feel free to take/ignore as you see fit. r+

> Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp:107
> +            EGL_Terminate(display);

If TerminateAndReleaseThreadResources is passed, this code calls EGL_Terminate before falling through to the EGL_ReleaseThread call below. Is that the correct order in which to call these fairly low-level APIs? It looks like it probably is - just asking for a double-check. I hope this is tested in UIWebView (?) tests on the ios-wk2 bot and not just in the wild.

> Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:64
>      return !!EGL_Initialize;

How does this turn into a function pointer that can be tested in this way? Via some of the weak-linked dylib magic that was added recently?

Worth adding a comment?

> Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h:121
> +    enum class ReleaseResourcesBehavior {

Reading this code afresh, the term "ReleaseResources" in this enum and in the method call is a little confusing - it sounds like OpenGL resources like textures or buffers are being released, where in fact thread-related resources like the current context or access to the EGL API are being released.

I wonder whether a different name could be chosen like:
  ReleaseThreadResourcesBehavior
  ReleasePerThreadResourcesBehavior
  ReleaseEGLResourcesBehavior
(and releasePerThreadResources(), releaseEGLResources(), or similar.)

> Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h:584
> +    static void platformReleaseResources();

If releaseResources is renamed, let's rename this to match.
Comment 5 Kimmo Kinnunen 2021-10-01 05:16:03 PDT
Thanks for the thoughts!

(In reply to Kenneth Russell from comment #4)
> If TerminateAndReleaseThreadResources is passed, this code calls
> EGL_Terminate before falling through to the EGL_ReleaseThread call below. Is
> that the correct order in which to call these fairly low-level APIs? It
> looks like it probably is - just asking for a double-check.

Yeah. First destroy the display, then free driver internal structures, like potential TLS slots.

> I hope this is
> tested in UIWebView (?) tests on the ios-wk2 bot and not just in the wild.

Yeah, I actually wrote a test for it year ago, WebGLNoCrashOnOnOtherThreadAccess, though it starts to be a bit outdated since EAGL isn't used on iOS anymore.

> 
> > Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:64
> >      return !!EGL_Initialize;
> 
> How does this turn into a function pointer that can be tested in this way?
> Via some of the weak-linked dylib magic that was added recently?
> Worth adding a comment?

Correct. Added.

> 
> > Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h:121
> > +    enum class ReleaseResourcesBehavior {
> 
> Reading this code afresh, the term "ReleaseResources" in this enum and in
> the method call is a little confusing - it sounds like OpenGL resources like
> textures or buffers are being released, where in fact thread-related
> resources like the current context or access to the EGL API are being
> released.
> 
> I wonder whether a different name could be chosen like:
>   ReleaseThreadResourcesBehavior

Used this.
Comment 6 Kimmo Kinnunen 2021-10-01 05:17:12 PDT
Created attachment 439840 [details]
Patch for landing
Comment 7 Kimmo Kinnunen 2021-10-01 06:52:57 PDT
*** Bug 230951 has been marked as a duplicate of this bug. ***
Comment 8 Kimmo Kinnunen 2021-10-01 07:00:44 PDT
Created attachment 439854 [details]
Patch for landing
Comment 9 Kenneth Russell 2021-10-04 16:19:37 PDT
Still looks good. Did this land? Note that if you fix up the "Reviewed by" lines in the Changelog, you don't need to set the r+ flag yourself.
Comment 10 Kimmo Kinnunen 2021-10-05 00:39:06 PDT
Comment on attachment 439854 [details]
Patch for landing

User error: first I waited on the mac-debug-wk1 which never showed up, then I set the plus on wrong field..
Comment 11 EWS 2021-10-05 00:40:18 PDT
Tools/Scripts/svn-apply failed to apply attachment 439854 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 12 Kimmo Kinnunen 2021-10-05 01:50:45 PDT
Created attachment 440182 [details]
Patch for landing
Comment 13 EWS 2021-10-05 12:15:11 PDT
Tools/Scripts/svn-apply failed to apply attachment 440182 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 14 Kimmo Kinnunen 2021-10-06 04:27:45 PDT
Created attachment 440352 [details]
Patch for landing
Comment 15 EWS 2021-10-06 04:29:43 PDT
ChangeLog entry in Source/WebKit/ChangeLog contains OOPS!.
Comment 16 Kimmo Kinnunen 2021-10-06 23:37:17 PDT
Created attachment 440473 [details]
Patch for landing
Comment 17 EWS 2021-10-07 01:08:50 PDT
Committed r283703 (242629@main): <https://commits.webkit.org/242629@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 440473 [details].
Comment 18 Radar WebKit Bug Importer 2021-10-07 01:09:21 PDT
<rdar://problem/83970802>
Comment 19 Michael Catanzaro 2021-10-07 10:43:14 PDT
Hi, the non-ANGLE implementation of GraphicsContextGLOpenGL::releaseThreadResources is broken, it's missing its return value:

bool GraphicsContextGLOpenGL::releaseThreadResources(ReleaseThreadResourceBehavior)
{
}

The ANGLE implementation carefully chooses between true or false, but I don't understand how or why. It's called from only two places, WebCoreThread.mm and ScopedWebGLRenderingResourcesRequest.cpp, and neither caller checks the return value, so it's somewhat academic, I suppose. I'm going to have it always return false, but you might consider converting this to return void.