Mesa (master): dri: Implement a DRI vtable extension to replace the global driDriverAPI.

Eric Anholt anholt at kemper.freedesktop.org
Thu Oct 24 21:48:09 UTC 2013


Module: Mesa
Branch: master
Commit: 4e54751624db7cb07cb4d36c3e683d9ed0a30016
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4e54751624db7cb07cb4d36c3e683d9ed0a30016

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Sep 26 10:51:29 2013 -0700

dri: Implement a DRI vtable extension to replace the global driDriverAPI.

As we move to megadrivers, we are unable to build multiple drivers with
the same public global symbol per driver (Think an X Server with an intel
and a nouveau driver, and the X Server implementing indirect for both --
we have to actually talk to the right driver).  By slipping the
driDriverAPI vtable into the driver's extension list, we can replace the
usage of the global symbol with usage of the loader-dlsym()ed driver
information.

v2: Pull in the hunk to avoid crashing on null driver_extensions.  Thanks,
    Emil!

Reviewed-by: Matt Turner <mattst88 at gmail.com> (v1)
Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
Reviewed-by: Emil Velikov <emil.l.velikov at gmail.com>

---

 include/GL/internal/dri_interface.h    |   17 +++++++++++++++++
 src/mesa/drivers/dri/common/dri_util.c |   13 +++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index a7afa22..48993b9 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1270,4 +1270,21 @@ typedef struct __DRIconfigOptionsExtensionRec {
    const char *xml;
 } __DRIconfigOptionsExtension;
 
+/**
+ * This extension provides a driver vtable to a set of common driver helper
+ * functions (driCoreExtension, driDRI2Extension) within the driver
+ * implementation, as opposed to having to pass them through a global
+ * variable.
+ *
+ * It is not intended to be public API to the actual loader, and the vtable
+ * layout may change at any time.
+ */
+#define __DRI_DRIVER_VTABLE "DRI_DriverVtable"
+#define __DRI_DRIVER_VTABLE_VERSION 1
+
+typedef struct __DRIDriverVtableExtensionRec {
+    __DRIextension base;
+    const struct __DriverAPIRec *vtable;
+} __DRIDriverVtableExtension;
+
 #endif
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index 8a413da..2a85703 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -101,8 +101,21 @@ dri2CreateNewScreen2(int scrn, int fd,
     if (!psp)
 	return NULL;
 
+    /* By default, use the global driDriverAPI symbol (non-megadrivers). */
     psp->driver = &driDriverAPI;
 
+    /* If the driver exposes its vtable through its extensions list
+     * (megadrivers), use that instead.
+     */
+    if (driver_extensions) {
+       for (int i = 0; driver_extensions[i]; i++) {
+          if (strcmp(driver_extensions[i]->name, __DRI_DRIVER_VTABLE) == 0) {
+             psp->driver =
+                ((__DRIDriverVtableExtension *)driver_extensions[i])->vtable;
+          }
+       }
+    }
+
     setupLoaderExtensions(psp, extensions);
 
 #ifndef __NOT_HAVE_DRM_H




More information about the mesa-commit mailing list