render/egl: fix software rendering check

Commit b4ce0d8b39 ("render/egl: accept negative DRM FD to select
software rendering") added an EXT_device_drm check to figure out
whether the user selected a device with a DRM FD or without one.
However, for KMS-only devices, Mesa will never advertise the
selected KMS node:
3f1d40d230/src/egl/main/egldevice.c (L109)

Instead, pass down a parameter to indicate whether a DRM FD was
passed in.

Fixes: b4ce0d8b39 ("render/egl: accept negative DRM FD to select software rendering")
This commit is contained in:
Simon Ser 2025-06-29 10:57:56 +02:00
parent 8c7041c4e8
commit 48bd1831fe

View file

@ -260,7 +260,8 @@ static struct wlr_egl *egl_create(void) {
return egl;
}
static bool egl_init_display(struct wlr_egl *egl, EGLDisplay display) {
static bool egl_init_display(struct wlr_egl *egl, EGLDisplay display,
bool allow_software) {
egl->display = display;
EGLint major, minor;
@ -326,9 +327,8 @@ static bool egl_init_display(struct wlr_egl *egl, EGLDisplay display) {
// The only way a non-DRM device is selected is when the user
// explicitly picks software rendering
if (check_egl_ext(device_exts_str, "EGL_MESA_device_software") &&
egl->exts.EXT_device_drm) {
if (env_parse_bool("WLR_RENDERER_ALLOW_SOFTWARE")) {
if (check_egl_ext(device_exts_str, "EGL_MESA_device_software")) {
if (allow_software || env_parse_bool("WLR_RENDERER_ALLOW_SOFTWARE")) {
wlr_log(WLR_INFO, "Using software rendering");
} else {
wlr_log(WLR_ERROR, "Software rendering detected, please use "
@ -382,7 +382,7 @@ static bool egl_init_display(struct wlr_egl *egl, EGLDisplay display) {
}
static bool egl_init(struct wlr_egl *egl, EGLenum platform,
void *remote_display) {
void *remote_display, bool allow_software) {
EGLint display_attribs[3] = {0};
size_t display_attribs_len = 0;
@ -401,7 +401,7 @@ static bool egl_init(struct wlr_egl *egl, EGLenum platform,
return false;
}
if (!egl_init_display(egl, display)) {
if (!egl_init_display(egl, display, allow_software)) {
if (egl->exts.KHR_display_reference) {
eglTerminate(display);
}
@ -556,6 +556,8 @@ static int open_render_node(int drm_fd) {
}
struct wlr_egl *wlr_egl_create_with_drm_fd(int drm_fd) {
bool allow_software = drm_fd < 0;
struct wlr_egl *egl = egl_create();
if (egl == NULL) {
wlr_log(WLR_ERROR, "Failed to create EGL context");
@ -569,7 +571,7 @@ struct wlr_egl *wlr_egl_create_with_drm_fd(int drm_fd) {
*/
EGLDeviceEXT egl_device = get_egl_device_from_drm_fd(egl, drm_fd);
if (egl_device != EGL_NO_DEVICE_EXT) {
if (egl_init(egl, EGL_PLATFORM_DEVICE_EXT, egl_device)) {
if (egl_init(egl, EGL_PLATFORM_DEVICE_EXT, egl_device, allow_software)) {
wlr_log(WLR_DEBUG, "Using EGL_PLATFORM_DEVICE_EXT");
return egl;
}
@ -594,7 +596,7 @@ struct wlr_egl *wlr_egl_create_with_drm_fd(int drm_fd) {
goto error;
}
if (egl_init(egl, EGL_PLATFORM_GBM_KHR, egl->gbm_device)) {
if (egl_init(egl, EGL_PLATFORM_GBM_KHR, egl->gbm_device, allow_software)) {
wlr_log(WLR_DEBUG, "Using EGL_PLATFORM_GBM_KHR");
return egl;
}
@ -633,7 +635,7 @@ struct wlr_egl *wlr_egl_create_with_context(EGLDisplay display,
return NULL;
}
if (!egl_init_display(egl, display)) {
if (!egl_init_display(egl, display, true)) {
free(egl);
return NULL;
}