From 5cf88188bd1720511d994f30e72cb6d0a5e048f6 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 24 Feb 2026 08:07:42 -0500 Subject: [PATCH] egl/device: fix the fix for explicit sw rejection in non-sw EGL_PLATFORM=device "explicit sw" means llvmpipe, which cannot be a real drm device. this requires also returning only a single device so as to avoid leaking non-sw drivers should fix LIBGL_ALWAYS_SOFTWARE=1 eglinfo Fixes: 8a339cdebcc ("egl: fix sw fallback rejection in non-sw EGL_PLATFORM=device") (cherry picked from commit c9b298660774291478323c5ef148362d9b136c3b) Part-of: --- .pick_status.json | 2 +- src/egl/drivers/dri2/platform_device.c | 18 ++++++++++-------- src/egl/main/egldevice.c | 11 ++++++++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 41029d1b5f2..f297190b015 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -134,7 +134,7 @@ "description": "egl/device: fix the fix for explicit sw rejection in non-sw EGL_PLATFORM=device", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "8a339cdebccdea0610bdd7a1ecc9a5ec63951940", "notes": null diff --git a/src/egl/drivers/dri2/platform_device.c b/src/egl/drivers/dri2/platform_device.c index e6ec4d5ee46..f94ab8b9535 100644 --- a/src/egl/drivers/dri2/platform_device.c +++ b/src/egl/drivers/dri2/platform_device.c @@ -260,12 +260,7 @@ static bool device_probe_device(_EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - bool request_software = - debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false); - if (request_software) - _eglLog(_EGL_WARNING, "Not allowed to force software rendering when " - "API explicitly selects a hardware device."); dri2_dpy->fd_render_gpu = device_get_fd(disp, disp->Device); if (dri2_dpy->fd_render_gpu < 0) return false; @@ -277,7 +272,7 @@ device_probe_device(_EGLDisplay *disp) goto err_name; /* this is software fallback */ - if (disp->Options.ForceSoftware && !request_software) { + if (disp->Options.ForceSoftware) { /* When doing software rendering, some times user still want to explicitly * choose the render node device since cross node import doesn't work between * vgem/virtio_gpu yet. It would be nice to have a new EXTENSION for this. @@ -327,15 +322,22 @@ dri2_initialize_device(_EGLDisplay *disp) { const char *err; struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + bool request_software = + debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false); /* Extension requires a PlatformDisplay - the EGLDevice. */ disp->Device = disp->PlatformDisplay; + if (request_software) + _eglLog(_EGL_WARNING, "Not allowed to force software rendering when " + "API explicitly selects a hardware device."); + err = "DRI2: failed to load driver"; - if (_eglDeviceSupports(disp->Device, _EGL_DEVICE_DRM)) { + /* device-drm platform cannot be explicit sw (because explicit sw is llvmpipe) */ + if (!request_software && _eglDeviceSupports(disp->Device, _EGL_DEVICE_DRM)) { if (!device_probe_device(disp)) goto cleanup; - } else if (_eglDeviceSupports(disp->Device, _EGL_DEVICE_SOFTWARE)) { + } else if (request_software || _eglDeviceSupports(disp->Device, _EGL_DEVICE_SOFTWARE)) { if (!device_probe_device_sw(disp)) goto cleanup; } else { diff --git a/src/egl/main/egldevice.c b/src/egl/main/egldevice.c index ba2f59f9e6e..ebebda46efe 100644 --- a/src/egl/main/egldevice.c +++ b/src/egl/main/egldevice.c @@ -30,6 +30,7 @@ #endif #include "util/compiler.h" #include "util/macros.h" +#include "util/u_debug.h" #include "eglcurrent.h" #include "egldevice.h" @@ -464,6 +465,8 @@ _eglQueryDevicesEXT(EGLint max_devices, _EGLDevice **devices, { _EGLDevice *dev, *devs, *swrast; int i = 0, num_devs; + bool request_software = + debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false); if ((devices && max_devices <= 0) || !num_devices) return _eglError(EGL_BAD_PARAMETER, "eglQueryDevicesEXT"); @@ -485,7 +488,13 @@ _eglQueryDevicesEXT(EGLint max_devices, _EGLDevice **devices, /* bail early if we only care about the count */ if (!devices) { - *num_devices = num_devs; + *num_devices = request_software ? !!swrast : num_devs; + goto out; + } + + if (request_software) { + *num_devices = !!swrast; + devices[0] = swrast; goto out; }