[Mesa-dev] [PATCH 13/16] st/dri: implement v2 of DRI_ConfigOptions

Nicolai Hähnle nhaehnle at gmail.com
Fri Jun 30 12:45:54 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/gallium/auxiliary/pipe-loader/pipe_loader.c    | 13 ++++++++++++
 src/gallium/auxiliary/pipe-loader/pipe_loader.h    | 16 +++++++++++++++
 .../auxiliary/pipe-loader/pipe_loader_drm.c        | 23 ++++++++++++++++++++++
 src/gallium/state_trackers/dri/dri_screen.c        |  5 +++--
 4 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
index cb37f30..39d33d8 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c
@@ -27,20 +27,22 @@
 
 #include "pipe_loader_priv.h"
 
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
 #include "util/u_dl.h"
 #include "util/xmlconfig.h"
 #include "util/xmlpool.h"
 
+#include <string.h>
+
 #ifdef _MSC_VER
 #include <stdlib.h>
 #define PATH_MAX _MAX_PATH
 #endif
 
 #define MODULE_PREFIX "pipe_"
 
 static int (*backends[])(struct pipe_loader_device **, int) = {
 #ifdef HAVE_LIBDRM
    &pipe_loader_drm_probe,
@@ -100,20 +102,31 @@ pipe_loader_load_options(struct pipe_loader_device *dev)
       pipe_loader_configuration(dev, DRM_CONF_XML_OPTIONS);
 
    if (xml_options_conf)
       xml_options = xml_options_conf->val.val_pointer;
 
    driParseOptionInfo(&dev->option_info, xml_options);
    driParseConfigFiles(&dev->option_cache, &dev->option_info, 0,
                        dev->driver_name);
 }
 
+char *
+pipe_loader_get_driinfo_xml(const char *driver_name)
+{
+   char *xml = pipe_loader_drm_get_driinfo_xml(driver_name);
+
+   if (!xml)
+      xml = strdup(gallium_driinfo_xml);
+
+   return xml;
+}
+
 struct pipe_screen *
 pipe_loader_create_screen(struct pipe_loader_device *dev,
                           struct pipe_screen_config *config)
 {
    pipe_loader_load_options(dev);
    config->options = &dev->option_cache;
 
    return dev->ops->create_screen(dev, config);
 }
 
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.h b/src/gallium/auxiliary/pipe-loader/pipe_loader.h
index a4502ae..b6e81cf 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader.h
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.h
@@ -107,20 +107,28 @@ pipe_loader_configuration(struct pipe_loader_device *dev,
  * Ensure that dev->option_cache is initialized appropriately for the driver.
  *
  * This function can be called multiple times.
  *
  * \param dev Device for which options should be loaded.
  */
 void
 pipe_loader_load_options(struct pipe_loader_device *dev);
 
 /**
+ * Get the driinfo XML string used by the given driver.
+ *
+ * The returned string is heap-allocated.
+ */
+char *
+pipe_loader_get_driinfo_xml(const char *driver_name);
+
+/**
  * Release resources allocated for a list of devices.
  *
  * Should be called when the specified devices are no longer in use to
  * release any resources allocated by pipe_loader_probe.
  *
  * \param devs Devices to release.
  * \param ndev Number of devices to release.
  */
 void
 pipe_loader_release(struct pipe_loader_device **devs, int ndev);
@@ -190,17 +198,25 @@ pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev);
 /**
  * Initialize a DRM device in an already opened fd.
  *
  * This function is platform-specific.
  *
  * \sa pipe_loader_probe
  */
 bool
 pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd);
 
+/**
+ * Get the driinfo XML used for the DRM driver of the given name, if any.
+ *
+ * The returned string is heap-allocated.
+ */
+char *
+pipe_loader_drm_get_driinfo_xml(const char *driver_name);
+
 extern const char gallium_driinfo_xml[];
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* PIPE_LOADER_H */
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
index 92b2421..5c8c750 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
@@ -25,20 +25,21 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *    Kristian Høgsberg <krh at bitplanet.net>
  *    Benjamin Franzke <benjaminfranzke at googlemail.com>
  *
  **************************************************************************/
 
 #include <fcntl.h>
 #include <stdio.h>
+#include <string.h>
 #include <xf86drm.h>
 #include <unistd.h>
 
 #include "loader.h"
 #include "target-helpers/drm_helper_public.h"
 #include "state_tracker/drm_driver.h"
 #include "pipe_loader_priv.h"
 
 #include "util/u_memory.h"
 #include "util/u_dl.h"
@@ -292,15 +293,37 @@ pipe_loader_drm_configuration(struct pipe_loader_device *dev,
 
 static struct pipe_screen *
 pipe_loader_drm_create_screen(struct pipe_loader_device *dev,
                               const struct pipe_screen_config *config)
 {
    struct pipe_loader_drm_device *ddev = pipe_loader_drm_device(dev);
 
    return ddev->dd->create_screen(ddev->fd, config);
 }
 
+char *
+pipe_loader_drm_get_driinfo_xml(const char *driver_name)
+{
+   char *xml = NULL;
+   struct util_dl_library *lib = NULL;
+   const struct drm_driver_descriptor *dd =
+      get_driver_descriptor(driver_name, &lib);
+   if (!dd)
+      goto out;
+
+   const struct drm_conf_ret *conf = dd->configuration(DRM_CONF_XML_OPTIONS);
+   if (!conf)
+      goto out;
+
+   xml = strdup((const char *)conf->val.val_pointer);
+
+out:
+   if (lib)
+      util_dl_close(lib);
+   return xml;
+}
+
 static const struct pipe_loader_ops pipe_loader_drm_ops = {
    .create_screen = pipe_loader_drm_create_screen,
    .configuration = pipe_loader_drm_configuration,
    .release = pipe_loader_drm_release
 };
diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c
index c130091..de6feb9 100644
--- a/src/gallium/state_trackers/dri/dri_screen.c
+++ b/src/gallium/state_trackers/dri/dri_screen.c
@@ -42,22 +42,23 @@
 #include "state_tracker/drm_driver.h"
 
 #include "util/u_debug.h"
 #include "util/u_format_s3tc.h"
 
 #define MSAA_VISUAL_MAX_SAMPLES 32
 
 #undef false
 
 const __DRIconfigOptionsExtension gallium_config_options = {
-   .base = { __DRI_CONFIG_OPTIONS, 1 },
-   .xml = gallium_driinfo_xml
+   .base = { __DRI_CONFIG_OPTIONS, 2 },
+   .xml = gallium_driinfo_xml,
+   .getXml = pipe_loader_get_driinfo_xml
 };
 
 #define false 0
 
 static void
 dri_fill_st_options(struct dri_screen *screen)
 {
    struct st_config_options *options = &screen->options;
    const struct driOptionCache *optionCache = &screen->dev->option_cache;
 
-- 
2.9.3



More information about the mesa-dev mailing list