I think we need to get to the bottom of this problem, as it keeps
getting more annoying, e.g. now with AIGLX it's not always easy to tell
whether direct rendering is being used, and when it's not, bugs may take
down the server instead of just the app, not to mention the inferior
performance.

>From what I've gathered, the problem seems to be due to the DRI drivers
no longer being linked against libGL (again for AIGLX) and occurs with
apps that aren't linked to libGL directly but dlopen it, and do so
without RTLD_GLOBAL. This seems to be mostly the case with SDL, but I
don't think we can just discard it as a bug there, as even changing SDL
to dlopen libGL with RTLD_GLOBAL now won't help with games that ship
their own versions of SDL, etc.

The attached patch attempts to fix this in libGL by always dlopening
libGL itself with RTLD_GLOBAL before trying to dlopen the driver, and
dlclosing the handle obtained from dlopening libGL again before
returning. It works here, e.g. tremulous and slune now get direct
rendering without LD_PRELOAD=libGL.so.1 again.

Any feedback appreciated.


-- 
Earthling Michel Dänzer           |          http://tungstengraphics.com
Libre software enthusiast         |          Debian, X and DRI developer

Index: ./src/glx/x11/dri_glx.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/glx/x11/dri_glx.c,v
retrieving revision 1.9
diff -p -u -r1.9 dri_glx.c
--- ./src/glx/x11/dri_glx.c	12 Jul 2006 19:40:59 -0000	1.9
+++ ./src/glx/x11/dri_glx.c	22 Jul 2006 16:05:22 -0000
@@ -183,6 +183,7 @@ static const char createNewScreenName[] 
  */
 static __DRIdriver *OpenDriver(const char *driverName)
 {
+   void *glhandle = NULL;
    char *libPaths = NULL;
    char libDir[1000];
    int i;
@@ -196,6 +197,9 @@ static __DRIdriver *OpenDriver(const cha
       }
    }
 
+   /* Attempt to make sure libGL symbols will be visible to the driver */
+   glhandle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL);
+
    if (geteuid() == getuid()) {
       /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
       libPaths = getenv("LIBGL_DRIVERS_PATH");
@@ -229,12 +233,13 @@ static __DRIdriver *OpenDriver(const cha
          /* allocate __DRIdriver struct */
          driver = (__DRIdriver *) Xmalloc(sizeof(__DRIdriver));
          if (!driver)
-            return NULL; /* out of memory! */
+            break; /* out of memory! */
          /* init the struct */
          driver->name = __glXstrdup(driverName);
          if (!driver->name) {
             Xfree(driver);
-            return NULL; /* out of memory! */
+            driver = NULL;
+            break; /* out of memory! */
          }
 
          driver->createNewScreenFunc = (PFNCREATENEWSCREENFUNC)
@@ -248,6 +253,7 @@ static __DRIdriver *OpenDriver(const cha
 			  "Your driver may be too old for this libGL.\n",
 			  createNewScreenName, driverName);
             Xfree(driver);
+            driver = NULL;
             dlclose(handle);
             continue;
          }
@@ -255,15 +261,20 @@ static __DRIdriver *OpenDriver(const cha
          /* put at head of linked list */
          driver->next = Drivers;
          Drivers = driver;
-         return driver;
+         break;
       }
       else {
 	 ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
       }
    }
 
-   ErrorMessageF("unable to find driver: %s_dri.so\n", driverName);
-   return NULL;
+   if (!driver)
+      ErrorMessageF("unable to load driver: %s_dri.so\n", driverName);
+
+   if (glhandle)
+      dlclose(glhandle);
+
+   return driver;
 }
 
 
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to