egl/sl: use kms_swrast with vgem instead of a random GPU
authorEmil Velikov <emil.velikov@collabora.com>
Tue, 19 Feb 2019 14:08:08 +0000 (14:08 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Thu, 28 Feb 2019 12:05:03 +0000 (12:05 +0000)
VGEM and kms_swrast were introduced to work with one another.

All we do is CPU rendering to dumb buffers. There is no reason to carve
out GPU memory, increasing the memory pressure on a device that could
make a better use of it.

Note:
 - The original code did not work out of the box, since the dumb buffer
ioctls are not exposed to render nodes.
 - This requires libdrm commit 3df8a7f0 ("xf86drm: fallback to MODALIAS
for OF less platform devices")
 - The non-kms, swrast is unaffected by this change.

v2:
 - elaborate what and how is/isn't working (Eric)
 - simplify driver_name handling (Eric)

v3:
 - move node_type outside of the loop (Eric)
 - kill no longer needed DRM_RENDER_DEV_NAME define

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
src/egl/drivers/dri2/platform_surfaceless.c

index ccdc370d0598eb7d0534f1c77387898d91c13d9e..4fe364ab22e7b24e1db2bbeab36ac1c8b91833c6 100644 (file)
@@ -254,8 +254,6 @@ static const __DRIswrastLoaderExtension swrast_loader_extension = {
    .getImage        = NULL,
 };
 
-#define DRM_RENDER_DEV_NAME  "%s/renderD%d"
-
 static const __DRIextension *image_loader_extensions[] = {
    &image_loader_extension.base,
    &image_lookup_extension.base,
@@ -275,6 +273,7 @@ static bool
 surfaceless_probe_device(_EGLDisplay *disp, bool swrast)
 {
 #define MAX_DRM_DEVICES 64
+   const unsigned node_type = swrast ? DRM_NODE_PRIMARY : DRM_NODE_RENDER;
    struct dri2_egl_display *dri2_dpy = disp->DriverData;
    drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
    int i, num_devices;
@@ -286,10 +285,10 @@ surfaceless_probe_device(_EGLDisplay *disp, bool swrast)
    for (i = 0; i < num_devices; ++i) {
       device = devices[i];
 
-      if (!(device->available_nodes & (1 << DRM_NODE_RENDER)))
+      if (!(device->available_nodes & (1 << node_type)))
          continue;
 
-      dri2_dpy->fd = loader_open_device(device->nodes[DRM_NODE_RENDER]);
+      dri2_dpy->fd = loader_open_device(device->nodes[node_type]);
       if (dri2_dpy->fd < 0)
          continue;
 
@@ -300,10 +299,16 @@ surfaceless_probe_device(_EGLDisplay *disp, bool swrast)
          continue;
       }
 
-      if (swrast)
-         dri2_dpy->driver_name = strdup("kms_swrast");
-      else
-         dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd);
+      char *driver_name = loader_get_driver_for_fd(dri2_dpy->fd);
+      if (swrast) {
+         /* Use kms swrast only with vgem */
+         if (strcmp(driver_name, "vgem") == 0)
+            dri2_dpy->driver_name = strdup("kms_swrast");
+         free(driver_name);
+      } else {
+         /* Use the given hardware driver */
+         dri2_dpy->driver_name = driver_name;
+      }
 
       if (dri2_dpy->driver_name && dri2_load_driver_dri3(disp))
          break;