[virglrenderer-devel] [PATCH] loader: disable virgl driver when no 3D for virtio

Lepton Wu lepton at chromium.org
Thu Apr 5 05:16:00 UTC 2018


If user are running mesa under old version of qemu or have turned off
GL at runtime, virtio gpu driver actually doesn't work. Adding a detection
here can make sure same disk image work with both cases.

Signed-off-by: Lepton Wu <lepton at chromium.org>
---
 src/loader/loader.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/loader/loader.c b/src/loader/loader.c
index 43275484cc..2a689c52d6 100644
--- a/src/loader/loader.c
+++ b/src/loader/loader.c
@@ -381,6 +381,27 @@ out:
    log_(driver ? _LOADER_DEBUG : _LOADER_WARNING,
          "pci id for fd %d: %04x:%04x, driver %s\n",
          fd, vendor_id, chip_id, driver);
+   if (!strcmp(driver, "virtio_gpu")) {
+      struct drm_virtgpu_getparam {
+         uint64_t param;
+         uint64_t value;
+      };
+      #define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */
+      struct drm_virtgpu_getparam args;
+      uint32_t gl = 0;
+      args.param = VIRTGPU_PARAM_3D_FEATURES;
+      args.value = (uint64_t)(uintptr_t)≷
+      #define DRM_VIRTGPU_GETPARAM    0x03
+      #define DRM_IOCTL_VIRTGPU_GETPARAM \
+         DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_GETPARAM,\
+                  struct drm_virtgpu_getparam)
+      int ret = drmIoctl(fd, DRM_IOCTL_VIRTGPU_GETPARAM, &args);
+      if (ret || !gl) {
+         /* Actually there is no virtio_2d driver, mesa will
+          * fallback to software driver */
+         return strdup("virtio_gpu_2d");
+      }
+   }
    return driver;
 }
 
-- 
2.17.0.484.g0c8726318c-goog



More information about the virglrenderer-devel mailing list