Bug 199060 - [GTK] Add ANGLE backend to GTK port
Summary: [GTK] Add ANGLE backend to GTK port
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: ChangSeok Oh
URL:
Keywords: InRadar
Depends on: 201748 204446
Blocks: webglangle 202508
  Show dependency treegraph
 
Reported: 2019-06-19 23:26 PDT by ChangSeok Oh
Modified: 2019-11-27 00:25 PST (History)
25 users (show)

See Also:


Attachments
Patch (52.95 KB, patch)
2019-09-18 22:43 PDT, ChangSeok Oh
no flags Details | Formatted Diff | Diff
Patch (53.69 KB, patch)
2019-09-19 01:45 PDT, ChangSeok Oh
no flags Details | Formatted Diff | Diff
Patch (56.24 KB, patch)
2019-09-19 03:08 PDT, ChangSeok Oh
no flags Details | Formatted Diff | Diff
Patch (58.62 KB, patch)
2019-11-09 21:10 PST, ChangSeok Oh
no flags Details | Formatted Diff | Diff
Patch (58.83 KB, patch)
2019-11-10 00:32 PST, ChangSeok Oh
no flags Details | Formatted Diff | Diff
Patch (56.34 KB, patch)
2019-11-11 19:03 PST, ChangSeok Oh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ChangSeok Oh 2019-06-19 23:26:18 PDT
WebKit is switching WebGL backend to ANGLE from its raw opengl calls in 198948. GTK port would also adopt ANGLE as one of opengl backend.
Comment 1 Kenneth Russell 2019-06-21 16:55:28 PDT
Exciting that the GTK port will use ANGLE too!
Comment 2 ChangSeok Oh 2019-09-12 19:22:58 PDT
I made a patch that renders webgl layers with ANGLE on top of GLX texture mapper and would start send it to upstream. The outline is here: https://github.com/shivamidow/webkit/tree/angle-webgl
Sharing webgl textures beween GLX and ANGLE egl contexts seems not feasible so I chose a readpixel-writetexture approach for now. (i.e., webgl scene -- (read pixels) --> texture for texture mapper)

Rather than trying to land the patch once, I will divide the work into multiple steps as follows.
1. Remove GraphicsContext3D dependencies from texture mapper and coordinate graphics code. It will be used by WebGL code only.
2. Land ANGLE support for WebGL
3. Make other rendering backends (e.g., opengl es) adopt ANGLE webgl.
4. Replace the readpixel part with texture sharing.
5. Bug fix and other improvement
Comment 3 ChangSeok Oh 2019-09-18 22:43:24 PDT
Created attachment 379104 [details]
Patch
Comment 4 EWS Watchlist 2019-09-18 22:44:08 PDT
Note that there are important steps to take when updating ANGLE. See http://trac.webkit.org/wiki/UpdatingANGLE
Comment 5 ChangSeok Oh 2019-09-18 22:45:26 PDT
(In reply to ChangSeok Oh from comment #3)
> Created attachment 379104 [details]
> Patch

This is a build test for EWS, not a final patch.
Comment 6 ChangSeok Oh 2019-09-19 01:45:24 PDT
Created attachment 379114 [details]
Patch

No review required yet. EWS test purpose.
Comment 7 ChangSeok Oh 2019-09-19 03:08:07 PDT
Created attachment 379115 [details]
Patch
Comment 8 ChangSeok Oh 2019-09-19 03:13:40 PDT
The Win-cairo bot keeps complaining as follow but it looks not related to this change.

> patching file Source/ThirdParty/ANGLE/PlatformGTK.cmake
> patch: **** Can't create file C:\Users\ContainerAdministrator\AppData\Local\Temp/ppz13552 : File exists
> patching file Source/ThirdParty/ANGLE/include/CMakeLists.txt
Comment 9 Alex Christensen 2019-09-26 12:00:33 PDT
This seems ok.  Zan, do you have an opinion?
Comment 10 Zan Dobersek 2019-09-29 12:35:09 PDT
This approach of download-reupload is the only one we can take up now, but we'll have to modify ANGLE possibly a lot in order to get everything in place to work without this bypass but instead use textures between ANGLE and non-ANGLE GL paths.

So this is a good first approach. I'll review it tomorrow.
Comment 11 Zan Dobersek 2019-11-04 07:37:48 PST
Comment on attachment 379115 [details]
Patch

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

> Source/WebCore/platform/graphics/angle/GLContextANGLE.h:33
> +class GLContextANGLE final : public GLContext {

I think this class can be avoided altogether. Instead of it, I would recommend packing all this logic into a new Nicosia::GC3DANGLELayer class. This would give us an easier time integrating with ANGLE, without having to work through the GLContext interface.

> Source/WebCore/platform/graphics/texmap/GraphicsContext3DTextureMapper.cpp:266
> +#if !USE(ANGLE)

I don't think this guard is needed -- this is already non-USE(ANGLE) code.

> Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp:86
> -#if USE(OPENGL_ES)
> +#if USE(ANGLE)
> +        std::unique_ptr<Extensions3DANGLE> glExtensions = makeUnique<Extensions3DANGLE>(nullptr, GLContext::current()->version() >= 320);
> +#elif USE(OPENGL_ES)

This change is fine on its own, but this check should be done without any usage of the Extensions3D* classes. This can be fixed after the fact.
Comment 12 ChangSeok Oh 2019-11-09 21:10:21 PST
Created attachment 383236 [details]
Patch
Comment 13 ChangSeok Oh 2019-11-09 21:22:51 PST
Comment on attachment 379115 [details]
Patch

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

>> Source/WebCore/platform/graphics/angle/GLContextANGLE.h:33
>> +class GLContextANGLE final : public GLContext {
> 
> I think this class can be avoided altogether. Instead of it, I would recommend packing all this logic into a new Nicosia::GC3DANGLELayer class. This would give us an easier time integrating with ANGLE, without having to work through the GLContext interface.

I am not sure if you meant just peeling off this class into NicosiaGC3DANLGELayer. So, I just pack GLContextANGLE into NicosiaGC3DANLGELayer::ANGLEContext for now.

>> Source/WebCore/platform/graphics/texmap/GraphicsContext3DTextureMapper.cpp:266
>> +#if !USE(ANGLE)
> 
> I don't think this guard is needed -- this is already non-USE(ANGLE) code.

You're right. Removed.

>> Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreWayland.cpp:86
>> +#elif USE(OPENGL_ES)
> 
> This change is fine on its own, but this check should be done without any usage of the Extensions3D* classes. This can be fixed after the fact.

If it is ok, I want to address this in the following changes since I already made a fix there. https://github.com/shivamidow/webkit/commit/c9981306834c745ed391608be30357794162883d
Comment 14 ChangSeok Oh 2019-11-10 00:32:29 PST
Created attachment 383240 [details]
Patch
Comment 15 EWS Watchlist 2019-11-10 00:33:28 PST
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See http://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Comment 16 Carlos Garcia Campos 2019-11-11 01:41:35 PST
Comment on attachment 383240 [details]
Patch

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

> Source/WebCore/platform/graphics/angle/GraphicsContext3DANGLE.cpp:203
> +#if USE(COORDINATED_GRAPHICS)

USE(COORDINATED_GRAPHICS) is always true for GTK port, so we can avoid it here

> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp:88
> +    EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);

Why the default display? Can't you use the platformDisplay.eglDisplay() instead?

> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp:149
> +    EGLSurface surface = EGL_CreatePbufferSurface(display, config, pbufferAttributes);

Isn't it possible to use a surfaceless context? or do we really need a surface here?

> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h:54
> +    class ANGLEContext : public WebCore::GLContext {

It's weird to have this here, why not adding an angle directory in Source/WebCore/platform/graphics and add the new context there following EGL and GLX contexts? Shouldn't this inherit from EGLContext instead?

> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h:63
> +        enum EGLSurfaceType { PbufferSurface, WindowSurface, PixmapSurface, Surfaceless };

Only PbufferSurface is supported, no?

> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h:70
> +        bool canRenderToDefaultFramebuffer() override { return m_type == WindowSurface; };

Is this really possible?

> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DLayer.h:46
> +    GC3DLayer(WebCore::GraphicsContext3D&);

explicit

> Source/WebCore/platform/graphics/texmap/BitmapTextureGL.cpp:172
> +void BitmapTextureGL::setPendingContents(RefPtr<Image> image)

RefPtr<Image>&&
Comment 17 ChangSeok Oh 2019-11-11 19:03:30 PST
Created attachment 383330 [details]
Patch
Comment 18 ChangSeok Oh 2019-11-11 19:04:03 PST
Comment on attachment 383240 [details]
Patch

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

>> Source/WebCore/platform/graphics/angle/GraphicsContext3DANGLE.cpp:203
>> +#if USE(COORDINATED_GRAPHICS)
> 
> USE(COORDINATED_GRAPHICS) is always true for GTK port, so we can avoid it here

Removed.

>> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp:88
>> +    EGLDisplay display = EGL_GetDisplay(EGL_DEFAULT_DISPLAY);
> 
> Why the default display? Can't you use the platformDisplay.eglDisplay() instead?

Because platformDisplay.eglDisplay() is not compatible to ANGLE. platformDisplay.eglDisplay returns EGLDisplay from Mesa so a crash happens in EGL_Initialize if we use it below. It looks same but Mesa and ANGLE implement different data structures for EGL/GL primitive data types. Basically, what we want to do is to isolate ANGLE use from Mesa GL calls. That is why we keep ANGLE gl headers in a different path to Mesa headers, and use internal ANGLE egl/gl calls instead of prototypes. Otherwise, many conflicts occurs in both compile time and runtime.

>> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.cpp:149
>> +    EGLSurface surface = EGL_CreatePbufferSurface(display, config, pbufferAttributes);
> 
> Isn't it possible to use a surfaceless context? or do we really need a surface here?

Creating pbuffer here is a little bit experimental. Yeah, I just confirmed surfaceless works here.

>> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h:54
>> +    class ANGLEContext : public WebCore::GLContext {
> 
> It's weird to have this here, why not adding an angle directory in Source/WebCore/platform/graphics and add the new context there following EGL and GLX contexts? Shouldn't this inherit from EGLContext instead?

Main reason is to separate ANGLE calls from the rest of world calling gl calls (mesa and others). I thought GLContext::makeContextCurrent() should be called in ANGLEContext::makeContextCurrent but it seems not. We can remove the GLContext inheritance then.

>> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h:63
>> +        enum EGLSurfaceType { PbufferSurface, WindowSurface, PixmapSurface, Surfaceless };
> 
> Only PbufferSurface is supported, no?

Surfaceless only. We can simply remove EGLSurfaceType if ANGLEContext does not inherit GLContext.

>> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DANGLELayer.h:70
>> +        bool canRenderToDefaultFramebuffer() override { return m_type == WindowSurface; };
> 
> Is this really possible?

No. Removed.

>> Source/WebCore/platform/graphics/nicosia/texmap/NicosiaGC3DLayer.h:46
>> +    GC3DLayer(WebCore::GraphicsContext3D&);
> 
> explicit

Fixed.

>> Source/WebCore/platform/graphics/texmap/BitmapTextureGL.cpp:172
>> +void BitmapTextureGL::setPendingContents(RefPtr<Image> image)
> 
> RefPtr<Image>&&

Ditto.
Comment 19 Zan Dobersek 2019-11-20 04:26:18 PST
Comment on attachment 383330 [details]
Patch

Looks OK. Thanks for addressing the feedback.
Comment 20 ChangSeok Oh 2019-11-20 10:05:45 PST
Anyone cq+, please?
Comment 21 WebKit Commit Bot 2019-11-20 14:16:54 PST
The commit-queue encountered the following flaky tests while processing attachment 383330 [details]:

imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/form-double-submit-3.html bug 203609 (author: cdumez@apple.com)
The commit-queue is continuing to process your patch.
Comment 22 WebKit Commit Bot 2019-11-20 14:16:56 PST
The commit-queue encountered the following flaky tests while processing attachment 383330 [details]:

The commit-queue is continuing to process your patch.
Comment 23 WebKit Commit Bot 2019-11-20 15:59:20 PST
Comment on attachment 383330 [details]
Patch

Clearing flags on attachment: 383330

Committed r252717: <https://trac.webkit.org/changeset/252717>
Comment 24 WebKit Commit Bot 2019-11-20 15:59:22 PST
All reviewed patches have been landed.  Closing bug.
Comment 25 Radar WebKit Bug Importer 2019-11-20 16:00:29 PST
<rdar://problem/57376341>