loader: Use drirc device_id parameter in complement to DRI_PRIME
authorAxel Davy <axel.davy@ens.fr>
Sun, 8 Jun 2014 23:47:48 +0000 (19:47 -0400)
committerDave Airlie <airlied@gmail.com>
Tue, 1 Jul 2014 03:07:40 +0000 (13:07 +1000)
DRI_PRIME is not very handy, because you have to launch the executable
with it set, which is not always easy to do.
By using drirc, the user specifies the target executable
and the device to use. After that the program will be launched everytime
on the target device.

For example if .drirc contains:

<driconf>
    <device driver="loader">
        <application name="Glmark2" executable="glmark2">
            <option name="device_id" value="pci-0000_01_00_0" />
        </application>
    </device>
</driconf>

Then glmark2 will use if possible the render-node of
ID_PATH_TAG pci-0000_01_00_0.

v2: Fix compilation issue
v3: Add "-lm" and rebase.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/Makefile.am
src/loader/Makefile.am
src/loader/loader.c
src/mesa/drivers/dri/common/xmlpool/t_options.h

index 9d1580f90412189e905a1837f03e2c21b4233875..d4a7090dca5ddbcb38ffb72996b6b025ab309821 100644 (file)
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 # IN THE SOFTWARE.
 
-SUBDIRS = gtest loader mapi
+SUBDIRS = gtest mapi
 
 if NEED_OPENGL_COMMON
 SUBDIRS += glsl mesa
 endif
 
+SUBDIRS += loader
+
 if HAVE_DRI_GLX
 SUBDIRS += glx
 endif
index bddf7ac35ed7db741f9058be1fc1a96411117e9f..ae8a84492fd09da9d6a75587780b53a13f89dd45 100644 (file)
@@ -29,6 +29,25 @@ libloader_la_CPPFLAGS = \
        $(VISIBILITY_CFLAGS) \
        $(LIBUDEV_CFLAGS)
 
+libloader_la_SOURCES = $(LOADER_C_FILES)
+libloader_la_LIBADD =
+
+if NEED_OPENGL_COMMON
+libloader_la_CPPFLAGS += \
+       -I$(top_srcdir)/src/mesa/drivers/dri/common/ \
+       -I$(top_builddir)/src/mesa/drivers/dri/common/ \
+       -I$(top_srcdir)/src/mesa/ \
+       -I$(top_srcdir)/src/mapi/ \
+       -DUSE_DRICONF
+
+libloader_la_SOURCES += \
+       $(top_srcdir)/src/mesa/drivers/dri/common/xmlconfig.c
+
+libloader_la_LIBADD += \
+       -lm \
+       $(EXPAT_LIBS)
+endif
+
 if !HAVE_LIBDRM
 libloader_la_CPPFLAGS += \
        -D__NOT_HAVE_DRM_H
@@ -36,8 +55,6 @@ else
 libloader_la_CPPFLAGS += \
        $(LIBDRM_CFLAGS)
 
-libloader_la_LIBADD = \
+libloader_la_LIBADD += \
        $(LIBDRM_LIBS)
 endif
-
-libloader_la_SOURCES = $(LOADER_C_FILES)
index 19d99d52ef2349b2e6b36503f61d51438d6825b3..47e1f58746ce6c4ded590783524919026ce3bb16 100644 (file)
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
+#ifdef USE_DRICONF
+#include "xmlconfig.h"
+#include "xmlpool.h"
+#endif
 #endif
 #ifdef HAVE_SYSFS
 #include <sys/stat.h>
@@ -323,9 +327,22 @@ drm_open_device(const char *device_name)
    return fd;
 }
 
+#ifdef USE_DRICONF
+const char __driConfigOptionsLoader[] =
+DRI_CONF_BEGIN
+    DRI_CONF_SECTION_INITIALIZATION
+        DRI_CONF_DEVICE_ID_PATH_TAG()
+    DRI_CONF_SECTION_END
+DRI_CONF_END;
+#endif
+
 int loader_get_user_preferred_fd(int default_fd, int *different_device)
 {
    struct udev *udev;
+#ifdef USE_DRICONF
+   driOptionCache defaultInitOptions;
+   driOptionCache userInitOptions;
+#endif
    const char *dri_prime = getenv("DRI_PRIME");
    char *prime = NULL;
    int is_different_device = 0, fd = default_fd;
@@ -337,6 +354,16 @@ int loader_get_user_preferred_fd(int default_fd, int *different_device)
 
    if (dri_prime)
       prime = strdup(dri_prime);
+#ifdef USE_DRICONF
+   else {
+      driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
+      driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "loader");
+      if (driCheckOption(&userInitOptions, "device_id", DRI_STRING))
+         prime = strdup(driQueryOptionstr(&userInitOptions, "device_id"));
+      driDestroyOptionCache(&userInitOptions);
+      driDestroyOptionInfo(&defaultInitOptions);
+   }
+#endif
 
    if (prime == NULL) {
       *different_device = 0;
index 3bf804a171cfc167ae63f5d7b8a429bdb7efb972..fc9e10461c55c43a9a64268327d5917c4211695e 100644 (file)
@@ -321,3 +321,17 @@ DRI_CONF_SECTION_BEGIN \
 DRI_CONF_OPT_BEGIN_B(always_have_depth_buffer, def) \
         DRI_CONF_DESC(en,gettext("Create all visuals with a depth buffer")) \
 DRI_CONF_OPT_END
+
+
+
+/**
+ * \brief Initialization configuration options
+ */
+#define DRI_CONF_SECTION_INITIALIZATION \
+DRI_CONF_SECTION_BEGIN \
+        DRI_CONF_DESC(en,gettext("Initialization"))
+
+#define DRI_CONF_DEVICE_ID_PATH_TAG(def) \
+DRI_CONF_OPT_BEGIN(device_id, string, def) \
+        DRI_CONF_DESC(en,gettext("Define the graphic device to use if possible")) \
+DRI_CONF_OPT_END