flypig.co.uk

List items

Items from the current list are shown below.

Blog

31 Mar 2024 : Day 202 #
Recently I've been looking at the EGL mesa display. Yesterday I finished restoring patch 0038, which is designed to fix this part of the rendering pipeline. Today I want to try to understand a little better what's being executed and when, in the hope that this will clarify whether what's happening is happening correctly or not.

In fact, I know there's something not working because rendering is still failing, but my hope is to narrow down what is and isn't working. After all, to badly misquote an expert on the matter, when you have eliminated the impossible, whatever remains, however improbable, must be the source of the bug.

The interesting methods, by which I mean the methods I'm interested in, which are those I've been making changes to over the last couple of days, are the following:
 
  1. GetAppDisplay()
  2. CreateEmulatorBufferSurface()
  3. WaylandGLSurface::WaylandGLSurface()
  4. GLLibraryEGL::Create()
  5. GLLibraryEGL::DefaultDisplay()
  6. GLLibraryEGL::CreateDisplay()
  7. GetAndInitDisplay()

To understand how these are getting called, I've placed breakpoints on all of them:
(gdb) b GetAppDisplay
Breakpoint 1 at 0x7ff1105918: file ${PROJECT}/gecko-dev/gfx/gl/
    GLContextProviderEGL.cpp, line 161.
(gdb) b CreateEmulatorBufferSurface
Breakpoint 2 at 0x7ff111d054: file ${PROJECT}/gecko-dev/gfx/gl/
    GLContextProviderEGL.cpp, line 980.
(gdb) b WaylandGLSurface::WaylandGLSurface
Breakpoint 3 at 0x7ff111d17c: file ${PROJECT}/gecko-dev/gfx/gl/
    GLContextProviderEGL.cpp, line 952.
(gdb) b GLLibraryEGL::Create
Breakpoint 4 at 0x7ff1118c50: file ${PROJECT}/gecko-dev/gfx/gl/
    GLLibraryEGL.cpp, line 343.
(gdb) b GLLibraryEGL::DefaultDisplay
Breakpoint 5 at 0x7ff111ce84: file ${PROJECT}/gecko-dev/gfx/gl/
    GLLibraryEGL.cpp, line 736.
(gdb) b GLLibraryEGL::CreateDisplay
Breakpoint 6 at 0x7ff111c8b8: file ${PROJECT}/gecko-dev/gfx/gl/
    GLLibraryEGL.cpp, line 747.
(gdb) b GetAndInitDisplay
Breakpoint 7 at 0x7ff111c82c: file ${PROJECT}/gecko-dev/gfx/gl/
    GLLibraryEGL.cpp, line 149.
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /usr/bin/harbour-webview 
[...]
You can probably tell that today is going to be another day of lengthy backtraces. It's true I'm afraid and I can only apologise in advance. As always, these backtraces make for very dull reading, but are important for my records. You won't lose anything by skipping them.

So executing the code with the debugger I can quickly find out which of these methods are called, in what order, and which are never called at all.
Thread 36 "Compositor" hit Breakpoint 1, mozilla::gl::GetAppDisplay ()
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:161
161     ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp: No such file or 
    directory.
(gdb) c
Continuing.

Thread 36 "Compositor" hit Breakpoint 1, mozilla::gl::GetAppDisplay ()
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:161
161     in ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp
(gdb) c
Continuing.

Thread 36 "Compositor" hit Breakpoint 4, mozilla::gl::GLLibraryEGL::
    Create (out_failureId=out_failureId@entry=0x7f1f7cb1c8, aDisplay=0x1)
    at ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp:343
343     ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp: No such file or directory.
(gdb) c
Continuing.

Thread 36 "Compositor" hit Breakpoint 5, mozilla::gl::GLLibraryEGL::
    DefaultDisplay (this=0x7edc003200, 
    out_failureId=out_failureId@entry=0x7f1f7cb1c8, 
    aDisplay=aDisplay@entry=0x1) at ${PROJECT}/gecko-dev/gfx/gl/
    GLLibraryEGL.cpp:736
736     in ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp
(gdb) c
Continuing.

Thread 36 "Compositor" hit Breakpoint 6, mozilla::gl::GLLibraryEGL::
    CreateDisplay (this=this@entry=0x7edc003200, 
    forceAccel=forceAccel@entry=false, 
    out_failureId=out_failureId@entry=0x7f1f7cb1c8, aDisplay=aDisplay@entry=0x1)
    at ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp:747
747     in ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp
(gdb) c
Continuing.

Thread 36 "Compositor" hit Breakpoint 7, mozilla::gl::
    GetAndInitDisplay (egl=..., displayType=displayType@entry=0x0, 
    display=display@entry=0x1)
    at ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp:149
149     in ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp
(gdb) c
Continuing.
[New Thread 0x7f1f4fa7e0 (LWP 2850)]
=============== Preparing offscreen rendering context ===============
This looks pretty healthy to be honest. After this point, none of the methods are called, so everything is happening during initialisation, which I was hoping would be the case. So far so good.

That flow is useful, but it's not the entire picture. I also want to know the call stacks for these method calls. Some of them are obvious because there's only one path for them to be called via. But others, including the calls to GetAppDisplay(), are less clear. This method in particular is called in many different places in the code. It'd be useful to know which paths are causing it to be triggered.

The easiest way to find this out is to get a copy of the backtrace when the breakpoint has been hit. I didn't do this first time round, but a second run through allows me to collect this info too.

Here's the (slightly abridged) backtrace for the first hit of GetAppDisplay()
Thread 38 "Compositor" hit Breakpoint 1, mozilla::gl::GetAppDisplay ()
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:161
161     ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp: No such file or 
    directory.
(gdb) bt
#0  mozilla::gl::GetAppDisplay () at ${PROJECT}/gecko-dev/gfx/gl/
    GLContextProviderEGL.cpp:161
#1  0x0000007ff112e684 in mozilla::gl::GLContextProviderEGL::CreateHeadless (
    desc=..., out_failureId=out_failureId@entry=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:1434
#2  0x0000007ff112efd4 in mozilla::gl::GLContextProviderEGL::CreateOffscreen (
    size=..., minCaps=..., 
    flags=flags@entry=mozilla::gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE, 
    out_failureId=out_failureId@entry=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:1476
#3  0x0000007ff1197b04 in mozilla::layers::CompositorOGL::CreateContext (
    this=this@entry=0x7edc002f10)
    at ${PROJECT}/gecko-dev/gfx/layers/opengl/CompositorOGL.cpp:254
#4  0x0000007ff11ad0f4 in mozilla::layers::CompositorOGL::Initialize (
    this=0x7edc002f10, out_failureReason=0x7f1f96f520)
    at ${PROJECT}/gecko-dev/gfx/layers/opengl/CompositorOGL.cpp:391
#5  0x0000007ff12c2d90 in mozilla::layers::CompositorBridgeParent::
    NewCompositor (this=this@entry=0x7fc4b7b7d0, aBackendHints=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1493
#6  0x0000007ff12cde0c in mozilla::layers::CompositorBridgeParent::
    InitializeLayerManager (this=this@entry=0x7fc4b7b7d0, aBackendHints=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1436
#7  0x0000007ff12cdf3c in mozilla::layers::CompositorBridgeParent::
    AllocPLayerTransactionParent (this=this@entry=0x7fc4b7b7d0, 
    aBackendHints=..., aId=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1546
#8  0x0000007ff36649c8 in mozilla::embedlite::EmbedLiteCompositorBridgeParent::
    AllocPLayerTransactionParent (this=0x7fc4b7b7d0, aBackendHints=..., 
    aId=...)
    at ${PROJECT}/gecko-dev/mobile/sailfishos/embedthread/
    EmbedLiteCompositorBridgeParent.cpp:80
#9  0x0000007ff0c5c3ac in mozilla::layers::PCompositorBridgeParent::
    OnMessageReceived (this=0x7fc4b7b7d0, msg__=...) at 
    PCompositorBridgeParent.cpp:1285
#10 0x0000007ff0ca08c0 in mozilla::layers::PCompositorManagerParent::
    OnMessageReceived (this=<optimized out>, msg__=...)
    at ${PROJECT}/obj-build-mer-qt-xr/dist/include/mozilla/ipc/ProtocolUtils.h:
    675
[...]
#24 0x0000007ff6a0289c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/
    clone.S:78
(gdb) 
The above backtrace shows that the call to GetAppDisplay() is being triggered from GLContextProviderEGL::CreateHeadless(). There it's being called directly. But interestingly, later in the same CreateHeadless() it gets called again, this time indirectly via DefaultEglDisplay() and then DefaultEglLibrary (despite the similar names those are very different methods; I find I need to focus hard on this stuff to properly distinguish). Here's the (again, slightly abridged) backtrace for this second call to GetAppDisplay().
Thread 38 &quot;Compositor&quot; hit Breakpoint 1, mozilla::gl::GetAppDisplay ()
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:161
161     in ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp
(gdb) bt
#0  mozilla::gl::GetAppDisplay () at ${PROJECT}/gecko-dev/gfx/gl/
    GLContextProviderEGL.cpp:161
#1  0x0000007ff1118e40 in mozilla::gl::DefaultEglLibrary (
    out_failureId=out_failureId@entry=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:1519
#2  0x0000007ff112e694 in mozilla::gl::DefaultEglDisplay (aDisplay=0x1, 
    out_failureId=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextEGL.h:29
#3  mozilla::gl::GLContextProviderEGL::CreateHeadless (desc=..., 
    out_failureId=out_failureId@entry=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:1434
#4  0x0000007ff112efd4 in mozilla::gl::GLContextProviderEGL::CreateOffscreen (
    size=..., minCaps=..., 
    flags=flags@entry=mozilla::gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE, 
    out_failureId=out_failureId@entry=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:1476
#5  0x0000007ff1197b04 in mozilla::layers::CompositorOGL::CreateContext (
    this=this@entry=0x7edc002f10)
    at ${PROJECT}/gecko-dev/gfx/layers/opengl/CompositorOGL.cpp:254
#6  0x0000007ff11ad0f4 in mozilla::layers::CompositorOGL::Initialize (
    this=0x7edc002f10, out_failureReason=0x7f1f96f520)
    at ${PROJECT}/gecko-dev/gfx/layers/opengl/CompositorOGL.cpp:391
#7  0x0000007ff12c2d90 in mozilla::layers::CompositorBridgeParent::
    NewCompositor (this=this@entry=0x7fc4b7b7d0, aBackendHints=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1493
#8  0x0000007ff12cde0c in mozilla::layers::CompositorBridgeParent::
    InitializeLayerManager (this=this@entry=0x7fc4b7b7d0, aBackendHints=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1436
#9  0x0000007ff12cdf3c in mozilla::layers::CompositorBridgeParent::
    AllocPLayerTransactionParent (this=this@entry=0x7fc4b7b7d0, 
    aBackendHints=..., aId=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1546
#10 0x0000007ff36649c8 in mozilla::embedlite::EmbedLiteCompositorBridgeParent::
    AllocPLayerTransactionParent (this=0x7fc4b7b7d0, aBackendHints=..., 
    aId=...)
    at ${PROJECT}/gecko-dev/mobile/sailfishos/embedthread/
    EmbedLiteCompositorBridgeParent.cpp:80
#11 0x0000007ff0c5c3ac in mozilla::layers::PCompositorBridgeParent::
    OnMessageReceived (this=0x7fc4b7b7d0, msg__=...) at 
    PCompositorBridgeParent.cpp:1285
[...]
#26 0x0000007ff6a0289c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/
    clone.S:78
(gdb) 
From here I think it starts getting less interesting (I'm pretending it ever was!), but for completeness, here's the backtrace for GLLibraryEGL::Create():
Thread 38 &quot;Compositor&quot; hit Breakpoint 4, mozilla::gl::GLLibraryEGL::
    Create (out_failureId=out_failureId@entry=0x7f1f96f1c8, aDisplay=0x1)
    at ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp:343
343     ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp: No such file or directory.
(gdb) bt
#0  mozilla::gl::GLLibraryEGL::Create (
    out_failureId=out_failureId@entry=0x7f1f96f1c8, aDisplay=0x1)
    at ${PROJECT}/gecko-dev/gfx/gl/GLLibraryEGL.cpp:343
#1  0x0000007ff1118e50 in mozilla::gl::DefaultEglLibrary (
    out_failureId=out_failureId@entry=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:1519
#2  0x0000007ff112e694 in mozilla::gl::DefaultEglDisplay (aDisplay=0x1, 
    out_failureId=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextEGL.h:29
#3  mozilla::gl::GLContextProviderEGL::CreateHeadless (desc=..., 
    out_failureId=out_failureId@entry=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:1434
#4  0x0000007ff112efd4 in mozilla::gl::GLContextProviderEGL::CreateOffscreen (
    size=..., minCaps=..., 
    flags=flags@entry=mozilla::gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE, 
    out_failureId=out_failureId@entry=0x7f1f96f1c8)
    at ${PROJECT}/gecko-dev/gfx/gl/GLContextProviderEGL.cpp:1476
#5  0x0000007ff1197b04 in mozilla::layers::CompositorOGL::CreateContext (
    this=this@entry=0x7edc002f10)
    at ${PROJECT}/gecko-dev/gfx/layers/opengl/CompositorOGL.cpp:254
#6  0x0000007ff11ad0f4 in mozilla::layers::CompositorOGL::Initialize (
    this=0x7edc002f10, out_failureReason=0x7f1f96f520)
    at ${PROJECT}/gecko-dev/gfx/layers/opengl/CompositorOGL.cpp:391
#7  0x0000007ff12c2d90 in mozilla::layers::CompositorBridgeParent::
    NewCompositor (this=this@entry=0x7fc4b7b7d0, aBackendHints=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1493
#8  0x0000007ff12cde0c in mozilla::layers::CompositorBridgeParent::
    InitializeLayerManager (this=this@entry=0x7fc4b7b7d0, aBackendHints=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1436
#9  0x0000007ff12cdf3c in mozilla::layers::CompositorBridgeParent::
    AllocPLayerTransactionParent (this=this@entry=0x7fc4b7b7d0, 
    aBackendHints=..., aId=...)
    at ${PROJECT}/gecko-dev/gfx/layers/ipc/CompositorBridgeParent.cpp:1546
#10 0x0000007ff36649c8 in mozilla::embedlite::EmbedLiteCompositorBridgeParent::
    AllocPLayerTransactionParent (this=0x7fc4b7b7d0, aBackendHints=..., 
    aId=...)
    at ${PROJECT}/gecko-dev/mobile/sailfishos/embedthread/
    EmbedLiteCompositorBridgeParent.cpp:80
#11 0x0000007ff0c5c3ac in mozilla::layers::PCompositorBridgeParent::
    OnMessageReceived (this=0x7fc4b7b7d0, msg__=...) at 
    PCompositorBridgeParent.cpp:1285
[...]
#26 0x0000007ff6a0289c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/
    clone.S:78
(gdb) 
I won't give the backtraces for the others because their location is already pretty fixed in the code. But on checking all of the values passed in to these and the other methods it's clear that the value for mDisplay is consistently set to 1 in all cases:
(gdb) p aDisplay
$1 = (EGLDisplay) 0x1
(gdb) 
That should be a good thing, but this doesn't mean everything is fixed and there's a nagging feeling in the back of my mind. I'll go through the flow and backtraces properly tomorrow, but that's it for today.

If you'd like to read any of my other gecko diary entries, they're all available on my Gecko-dev Diary page.

Comments

Uncover Disqus comments