Subject: eglCreateImageKHR for nested Mir

From: Alexandros Frantzis <[email-masked]>
Date: Fri, 6 Sep 2013 21:24:16 +0300

Hi all,

I have been working on eglCreateImageKHR for the Mir EGL platform in
Mesa, using gbm_bo as the "native pixmap" type (EGL_NATIVE_PIXMAP_KHR).
This is needed by nested Mir, but could also be useful in general.

The current state of the (still very hacky) WIP can be found at:

lp:~afrantzis/mir/spike-nested-gbm-egl-image-hack/

and

http://paste.ubuntu.com/6071345/

(it is the diff against https://github.com/RAOF/mesa/ branch
egl-platform-mir)

I have run into the following problem: when a client connects to the
nested mir server, it fails almost immediately because of what seems to
be a problem referencing a buffer that was created earlier. In
particular, we create gbm_bos (using GEM objects internally) for the
buffers backing the surface of the client, but, sometimes, when trying
to reference these GEM objects, e.g. when trying to create an EGLImage
for them we can't find them anymore!

An interesting observation is that if the client submits the first 3
buffers slowly (which trigger the gbm_bo creation and EGLImage
initialization and rendering on the server), the problem doesn't occur,
which indicates that there is some kind of synchronization problem.

For anyone interested, things to try with the code above:

!!! Make sure you run against the modified Mesa
(e.g. set your LD_LIBRARY_PATH)

First run the host server:
$ sudo LD_LIBRARY_PATH=... bin/mir_demo_server_basic -f /tmp/mir_host

Run the nested server:
$ sudo LD_LIBRARY_PATH=... bin/mir_demo_server_basic --nested-mode /tmp/mir_host --enable-input off

Run a normal client and watch the nested server crash:
$ sudo LD_LIBRARY_PATH=...  bin/mir_demo_client_egltriangle

Run an (initially) slow client and watch it work (I have modified this
example to start slow and speed up):
$ sudo LD_LIBRARY_PATH=...  bin/mir_demo_client_scroll

To aid the investigation I created a client that stresses multi-threaded
gbm_bo and EGLImage creation and rendering, trying to approximate nested
mir behavior, but I can't get it to fail! :
$ sudo LD_LIBRARY_PATH=...  bin/mir_demo_client_egl_image -m /tmp/mir_host

Thoughts welcome :)

Note that I have only tried this on an Intel GPU. It would be interesting
to see if the behavior is different with Radeon or Nouveau.

Thanks,
Alexandros

---

From: Alexandros Frantzis <[email-masked]>
Date: Mon, 9 Sep 2013 15:05:39 +0300

> to see if the behavior is different with Radeon or Nouveau.

Further investigation uncovered that this happens only when using PRIME
fds in Mesa. Using GEM names works correctly.

I have updated the branch lp:~afrantzis/mir/spike-nested-gbm-egl-image-hack/
to send both a PRIME fd and a GEM name for each buffer for testing
purposes.

The diff (against https://github.com/RAOF/mesa/) at:

http://paste.ubuntu.com/6083139/

allows selecting which handle to use (set USE_PRIME in platform_mir.c to
0 to use GEM names).

Thanks,
Alexandros