[Mesa-dev] [PATCH] egl/surfaceless: Use KMS swrast fallback
Eric Engestrom
eric.engestrom at imgtec.com
Mon Oct 2 10:54:10 UTC 2017
On Friday, 2017-09-29 23:57:32 +0000, gurchetansingh at chromium.org wrote:
> From: Gurchetan Singh <gurchetansingh at chromium.org>
>
> The kms_swrast extension is an actively developed software fallback,
> and platform_surfaceless can use it if there are no available
> hardware drivers.
> ---
> src/egl/drivers/dri2/platform_surfaceless.c | 77 ++++++++++++++++++-----------
> 1 file changed, 48 insertions(+), 29 deletions(-)
>
> diff --git a/src/egl/drivers/dri2/platform_surfaceless.c b/src/egl/drivers/dri2/platform_surfaceless.c
> index 3c00ff44ab..518b74fcde 100644
> --- a/src/egl/drivers/dri2/platform_surfaceless.c
> +++ b/src/egl/drivers/dri2/platform_surfaceless.c
> @@ -267,6 +267,47 @@ static const __DRIextension *image_loader_extensions[] = {
> NULL,
> };
>
> +static int
> +surfaceless_probe_device(_EGLDisplay *dpy, int swrast)
both the `swrast` param and the return value are ints used as bools.
please change those to proper `bool`
> +{
> + struct dri2_egl_display *dri2_dpy = dpy->DriverData;
> + const int limit = 64;
> + const int base = 128;
> + int fd;
> + int i;
> +
> + for (i = 0; i < limit; ++i) {
> + char *card_path;
> + if (asprintf(&card_path, DRM_RENDER_DEV_NAME, DRM_DIR_NAME, base + i) < 0)
> + continue;
> +
> + fd = loader_open_device(card_path);
> + free(card_path);
> + if (fd < 0)
> + continue;
> +
> + if (swrast)
> + dri2_dpy->driver_name = strdup("kms_swrast");
> + else
> + dri2_dpy->driver_name = loader_get_driver_for_fd(fd);
> + if (!dri2_dpy->driver_name) {
> + close(fd);
> + continue;
> + }
> +
> + dri2_dpy->fd = fd;
> + if (dri2_load_driver_dri3(dpy))
> + return 0;
> +
> + close(fd);
> + dri2_dpy->fd = -1;
> + free(dri2_dpy->driver_name);
> + dri2_dpy->driver_name = NULL;
> + }
> +
> + return -1;
> +}
> +
> EGLBoolean
> dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp)
> {
> @@ -282,36 +323,14 @@ dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp)
>
> dri2_dpy->fd = -1;
> disp->DriverData = (void *) dri2_dpy;
> -
> - const int limit = 64;
> - const int base = 128;
> - for (int i = 0; i < limit; ++i) {
> - char *card_path;
> - if (asprintf(&card_path, DRM_RENDER_DEV_NAME, DRM_DIR_NAME, base + i) < 0)
> - continue;
> -
> - dri2_dpy->fd = loader_open_device(card_path);
> -
> - free(card_path);
> - if (dri2_dpy->fd < 0)
> - continue;
> -
> - dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd);
> - if (dri2_dpy->driver_name) {
> - if (dri2_load_driver_dri3(disp)) {
> - driver_loaded = 1;
> - break;
> - }
> - free(dri2_dpy->driver_name);
> - dri2_dpy->driver_name = NULL;
> + if (surfaceless_probe_device(disp, 0) < 0) {
> + _eglLog(_EGL_DEBUG, "No hardware driver found, falling back to"
> + "kms_swrast");
To keep in line with other platforms, please check LIBGL_ALWAYS_SOFTWARE
as well.
Look at dri2_initialize_x11() for example, or dri2_initialize_wayland()
after my patch:
https://lists.freedesktop.org/archives/mesa-dev/2017-October/171295.html
> + /* Retry with kms_swrast driver. */
> + if (surfaceless_probe_device(disp, 1) < 0) {
> + err = "DRI2: failed to load driver";
> + goto cleanup;
> }
> - close(dri2_dpy->fd);
> - dri2_dpy->fd = -1;
> - }
> -
> - if (!driver_loaded) {
> - err = "DRI2: failed to load driver";
> - goto cleanup;
> }
>
> dri2_dpy->loader_extensions = image_loader_extensions;
> --
> 2.12.2
>
More information about the mesa-dev
mailing list