egl/gbm: Walk device list to initialize DRM platform

We cannot always use /dev/dri/card0.
As a matter of fact, on systems with SimpleDRM enabled /dev/dri/card0
will be created by it and removed once a GPU driver has loaded.

In any case we shouldn't hard-code the device number and instead walk
the device list to find the first suitable device.

This issue is trivially reproducible with `eglinfo -B -p gbm` on
Ubuntu 24.04 or Fedora 40

Fixes: 32f4cf3808 ("egl/gbm: Fix EGL_DEFAULT_DISPLAY")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30325>
This commit is contained in:
Alessandro Astone
2024-07-23 16:19:51 +02:00
committed by Marge Bot
parent 4ef0cbaf05
commit 7949471716

View File

@@ -42,6 +42,7 @@
#include "egl_dri2.h"
#include "egldevice.h"
#include "eglglobals.h"
#include "loader.h"
static struct gbm_bo *
@@ -586,10 +587,26 @@ dri2_initialize_drm(_EGLDisplay *disp)
dri2_dpy->fd_display_gpu =
loader_open_device(drm->nodes[DRM_NODE_PRIMARY]);
} else {
char buf[64];
int n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, 0);
if (n != -1 && n < sizeof(buf))
dri2_dpy->fd_display_gpu = loader_open_device(buf);
_EGLDevice *dev_list = _eglGlobal.DeviceList;
drmDevicePtr drm;
while (dev_list) {
if (!_eglDeviceSupports(dev_list, _EGL_DEVICE_DRM))
goto next;
drm = _eglDeviceDrm(dev_list);
if (!(drm->available_nodes & (1 << DRM_NODE_PRIMARY)))
goto next;
dri2_dpy->fd_display_gpu =
loader_open_device(drm->nodes[DRM_NODE_PRIMARY]);
if (dri2_dpy->fd_display_gpu < 0)
goto next;
break;
next:
dev_list = _eglDeviceNext(dev_list);
}
}
gbm = gbm_create_device(dri2_dpy->fd_display_gpu);