Created attachment 80361 [details]
Potential fix for Gallium EGL Wayland protocol
wayland_drm_display_init_screen (via wayland_roundtrip) blocks indefinitely in wl_display_dispatch_queue. The man page explains this behavior:
[A user created queue is dispatched with wl_display_dispatch_queue(). If there are no events to dispatch this function will block. If this is called by the main thread, this will attempt to read data from the display fd and queue any events on the appropriate queues. If calling from any other thread, the function will block until the main thread queues an event on the queue being dispatched.]
The calling thread is not identified by libwayland-client as the "main thread". The protocol used in Wayland test programs is to call wl_display_dispatch_pending() prior to this point, which sets the calling thread as the "main thread". See attached patch and test case.
While this fixes the test case (and all EGL calls for a single-threaded application), this problem may also affect other calls, e.g. eglSwapBuffers(), which is specified to be callable from different threads. The same wl_display_dispatch_queue() call could be introduced into this path (rebinding the "main thread" with each call), but the overhead of doing so has not been measured.
It may be preferable to do this in wayland_roundtrip() or to consider a change in Wayland itself.
Created attachment 80362 [details]
Trivial test case for Gallium EGL Wayland backend
The EGL state tracker was dropped from Mesa long ago. Closing.