Bug 249125 - [GTK] WebGL not available with USE_ANGLE_WEBGL and sandbox enabled
Summary: [GTK] WebGL not available with USE_ANGLE_WEBGL and sandbox enabled
Status: RESOLVED DUPLICATE of bug 250073
Alias: None
Product: WebKit
Classification: Unclassified
Component: ANGLE (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 249145
  Show dependency treegraph
 
Reported: 2022-12-12 00:36 PST by Kdwk
Modified: 2023-01-16 05:16 PST (History)
7 users (show)

See Also:


Attachments
Screenshot showing the Aquarium WebGL test not working (54.31 KB, image/png)
2022-12-12 00:36 PST, Kdwk
no flags Details
The webkit://gpu page on Epiphany Technology Preview with WebKitGTK 2.39.2 (438.79 KB, image/png)
2022-12-12 00:37 PST, Kdwk
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kdwk 2022-12-12 00:36:22 PST
Created attachment 464003 [details]
Screenshot showing the Aquarium WebGL test not working

Starting from WebKitGTK 2.91.1 on Epiphany Technology Preview (GTK 4), websites can no longer use WebGL on any of my devices. For instance, the Aquarium WebGL test reports that my device does not appear to support WebGL. WebGL works on WebKitGTK 2.38.1 on Gnome Web stable (GTK 3).

Note: other users, like Alexander Mikhaylenko, reported that WebGL works on their device.

Note: not sure if related: when visiting sites like apple.com and reddit.com, the terminal outputs a few lines of `ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl`. Animations and position snapping on apple.com doesn't work (they did in stable). Scrolling on reddit.com is very sluggish (the problem is less pronounced in stable).
Comment 1 Kdwk 2022-12-12 00:37:45 PST
Created attachment 464004 [details]
The webkit://gpu page on Epiphany Technology Preview with WebKitGTK 2.39.2
Comment 2 Michael Catanzaro 2022-12-20 18:00:42 PST
So I can reproduce this. Both Ephy Tech Preview and my personal jhbuild WebKitGTK no longer support WebGL. And I have the same aforementioned EGL errors:

ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl
ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl
ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl
ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl
ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl
ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl
ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl
ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl

I will investigate soon, but I assume the problem is caused by USE_ANGLE_WEBGL.
Comment 3 Carlos Garcia Campos 2022-12-21 03:02:06 PST
Ok, we need to figure out why ANGLE fails to to initialize EGL, because GLContextEGL is not failing. First I would check the error generated by mFnPtrs->initializePtr in FunctionsEGL::initialize(). That can fail with EGL_BAD_DISPLAY or EGL_NOT_INITIALIZED. I would also check where we are creating the context, it could be either GraphicsContextGLGBM::platformInitializeContext() or GraphicsContextGLFallback::platformInitializeContext() although EGL is initialized with the default display and the same parameters in both cases.
Comment 4 Carlos Garcia Campos 2022-12-21 03:25:00 PST
Oh! I can repro with MiniBrowser by enabling the sandbox...
Comment 5 Michael Catanzaro 2022-12-22 07:39:40 PST
(In reply to Carlos Garcia Campos from comment #3)
> Ok, we need to figure out why ANGLE fails to to initialize EGL, because
> GLContextEGL is not failing. First I would check the error generated by
> mFnPtrs->initializePtr in FunctionsEGL::initialize(). That can fail with
> EGL_BAD_DISPLAY or EGL_NOT_INITIALIZED.

It's 0x3001 EGL_NOT_INITIALIZED, which is not super informative.

But I added this not very useful change:

diff --git a/Source/ThirdParty/ANGLE/src/libANGLE/renderer/gl/egl/FunctionsEGL.cpp b/Source/ThirdParty/ANGLE/src/libANGLE/renderer/gl/egl/FunctionsEGL.cpp
index d3061b57a2b7..c2fd90cd1991 100644
--- a/Source/ThirdParty/ANGLE/src/libANGLE/renderer/gl/egl/FunctionsEGL.cpp
+++ b/Source/ThirdParty/ANGLE/src/libANGLE/renderer/gl/egl/FunctionsEGL.cpp
@@ -174,7 +174,7 @@ FunctionsEGL::~FunctionsEGL()
 {
     SafeDelete(mFnPtrs);
 }
-
+#include <stdio.h>
 egl::Error FunctionsEGL::initialize(EGLNativeDisplayType nativeDisplay)
 {
 #define ANGLE_GET_PROC_OR_ERROR(MEMBER, NAME)                                           \
@@ -213,7 +213,8 @@ egl::Error FunctionsEGL::initialize(EGLNativeDisplayType nativeDisplay)
     mEGLDisplay = mFnPtrs->getDisplayPtr(nativeDisplay);
     if (mEGLDisplay != EGL_NO_DISPLAY)
     {
-        if (mFnPtrs->initializePtr(mEGLDisplay, &majorVersion, &minorVersion) != EGL_TRUE)
+auto ret = mFnPtrs->initializePtr(mEGLDisplay, &majorVersion, &minorVersion);
+        if (ret != EGL_TRUE)
         {
             return egl::Error(mFnPtrs->getErrorPtr(), "Failed to initialize system egl");
         }

That change sure looks like it should do nothing, but for whatever reason it changes the behavior of the calling function Display::initialize, which prints a detailed error only if I make that change:

ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: EGL >= 1.4 is required

So ANGLE thinks the EGL version is too old, but webkit://gpu reports EGL_VERSION is 1.5.

> I would also check where we are
> creating the context, it could be either
> GraphicsContextGLGBM::platformInitializeContext() or
> GraphicsContextGLFallback::platformInitializeContext() although EGL is
> initialized with the default display and the same parameters in both cases.

Mine is happening in GraphicsContextGLGBM::platformInitializeContext.
Comment 6 Carlos Garcia Campos 2022-12-22 07:42:56 PST
Michael, can you reproduce with the sandbox disabled?
Comment 7 Michael Catanzaro 2022-12-22 08:02:00 PST
Nope, I see lots of fish with the sandbox disabled.
Comment 8 Michael Catanzaro 2022-12-22 10:33:45 PST
Well I tried debugging this today, but didn't get very far. I can see that ANGLE is successfully dlopening libEGL.so.1, so I think it's really calling into mesa and that's where the failure occurs. But I can't easily step into mesa with host gdb because the web process doesn't run a gdbserver instance inside the sandbox. So that's pretty inconvenient.

That's as far as I'm going for now. I'll leave this on my to-do list for next year.
Comment 9 Michael Catanzaro 2022-12-22 10:36:09 PST
Oh, one more thing. It's not just hardware rendering that's failing. mesa's eglInitialize automatically falls back to software rendering, and presumably that fails to initialize too. (I'm looking at eglapi.c.)
Comment 10 Carlos Garcia Campos 2023-01-03 02:28:14 PST
I found the problem of eglInitialize. GraphicsContextGLGBM::platformInitializeContext() uses EGL_DEFAULT_DISPLAY and mesa (when built with x11 support) uses x11 as platform for the default display. So, we are always using EGL over xwayland in both GTK and WPE. With the sandbox enabled, we don't bind X11 when displaynis wayland and mesa fails to initialize egl because xcb_connect() fails. See logs:

libEGL debug: Native platform type: x11 (build-time configuration)
libEGL debug: EGL user error 0x3003 (EGL_BAD_ALLOC) in eglInitialize: xcb_connect failed

libEGL debug: EGL user error 0x3003 (EGL_BAD_ALLOC) in eglInitialize: xcb_connect failed

libEGL debug: EGL user error 0x3003 (EGL_BAD_ALLOC) in eglInitialize: xcb_connect failed

libEGL debug: EGL user error 0x3001 (EGL_NOT_INITIALIZED) in eglInitialize

ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289: Failed to initialize system egl

So, we should always pass the native display to EGL_GetPlatformDisplayEXT, to ensure mesa returns wayland platform from _eglNativePlatformDetectNativeDisplay() when called with a wl_display.
Comment 11 Carlos Garcia Campos 2023-01-03 03:44:04 PST
(In reply to Carlos Garcia Campos from comment #10)
> I found the problem of eglInitialize.
> GraphicsContextGLGBM::platformInitializeContext() uses EGL_DEFAULT_DISPLAY
> and mesa (when built with x11 support) uses x11 as platform for the default
> display. So, we are always using EGL over xwayland in both GTK and WPE. With
> the sandbox enabled, we don't bind X11 when displaynis wayland and mesa
> fails to initialize egl because xcb_connect() fails. See logs:
> 
> libEGL debug: Native platform type: x11 (build-time configuration)
> libEGL debug: EGL user error 0x3003 (EGL_BAD_ALLOC) in eglInitialize:
> xcb_connect failed
> 
> libEGL debug: EGL user error 0x3003 (EGL_BAD_ALLOC) in eglInitialize:
> xcb_connect failed
> 
> libEGL debug: EGL user error 0x3003 (EGL_BAD_ALLOC) in eglInitialize:
> xcb_connect failed
> 
> libEGL debug: EGL user error 0x3001 (EGL_NOT_INITIALIZED) in eglInitialize
> 
> ERR: Display.cpp:1021 (initialize): ANGLE Display::initialize error 12289:
> Failed to initialize system egl
> 
> So, we should always pass the native display to EGL_GetPlatformDisplayEXT,
> to ensure mesa returns wayland platform from
> _eglNativePlatformDetectNativeDisplay() when called with a wl_display.

No, that's not the right solution, because we are using EGL_PLATFORM_SURFACELESS_MESA as EGL_PLATFORM_ANGLE_NATIVE_PLATFORM_TYPE_ANGLE, so we want mesa to use the surfaceless display not the native one. In that case passing default display to eglGetPlatformDisplayEXT is the right thing. so, this is actually an ANGLE patch and needs to be fixed there.
Comment 12 Carlos Garcia Campos 2023-01-03 05:27:40 PST
An ANGLE bug I mean. Žan has a patch to fix it.
Comment 13 Carlos Garcia Campos 2023-01-16 05:16:53 PST

*** This bug has been marked as a duplicate of bug 250073 ***