driconfig: add a new engine name/version parameter
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Sun, 8 Sep 2019 09:59:32 +0000 (12:59 +0300)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Sun, 15 Sep 2019 12:37:02 +0000 (15:37 +0300)
Vulkan applications can register with the following structure :

typedef struct VkApplicationInfo {
    VkStructureType    sType;
    const void*        pNext;
    const char*        pApplicationName;
    uint32_t           applicationVersion;
    const char*        pEngineName;
    uint32_t           engineVersion;
    uint32_t           apiVersion;
} VkApplicationInfo;

This enables the Vulkan implementations to apply workarounds based off
matching this description.

Here we add a new parameter for matching the driconfig options with
the following :

    <device driver="anv">
        <application engine_name_match="MyOwnEngine.*" engine_versions="10:12,40:42">
            <option name="blaaah" value="true" />
        </application>
    </device>

v2: switch engine name match to use regexps

v3: Verify that the regexec returns REG_NOMATCH for match failure (Eric)

v4: Add missing bit that went to the following commit (Eric)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Cc: 19.2 <mesa-stable@lists.freedesktop.org>
14 files changed:
src/amd/vulkan/radv_device.c
src/gallium/auxiliary/pipe-loader/pipe_loader.c
src/gallium/targets/d3dadapter9/drm.c
src/intel/vulkan/anv_device.c
src/loader/loader.c
src/mesa/drivers/dri/common/dri_util.c
src/mesa/drivers/dri/i915/intel_context.c
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/intel_screen.c
src/mesa/drivers/dri/r200/r200_context.c
src/mesa/drivers/dri/radeon/radeon_context.c
src/util/00-mesa-defaults.conf
src/util/xmlconfig.c
src/util/xmlconfig.h

index 57f492088bd57b92c62010cb3f93c1c35d19e3ab..7a6af56379787e75ee9c2bfbd98692290124b9ae 100644 (file)
@@ -567,7 +567,9 @@ static void  radv_init_dri_options(struct radv_instance *instance)
        driParseOptionInfo(&instance->available_dri_options, radv_dri_options_xml);
        driParseConfigFiles(&instance->dri_options,
                            &instance->available_dri_options,
-                           0, "radv", NULL);
+                           0, "radv", NULL,
+                           instance->engineName,
+                           instance->engineVersion);
 }
 
 VkResult radv_CreateInstance(
index 54af4d531ca5a48f6789ebc6e6c64b3f34e1d66d..e0fb249b6f096b02cab242483d834e01d532edef 100644 (file)
@@ -99,7 +99,7 @@ pipe_loader_load_options(struct pipe_loader_device *dev)
 
    driParseOptionInfo(&dev->option_info, xml_options);
    driParseConfigFiles(&dev->option_cache, &dev->option_info, 0,
-                       dev->driver_name, NULL);
+                       dev->driver_name, NULL, NULL, 0);
 }
 
 char *
index 657c619ac42b7741bbb68db251aacdd2a426a4aa..819aa59468cd2b86223e63b557792fd29a7dd186 100644 (file)
@@ -250,7 +250,8 @@ drm_create_adapter( int fd,
     ctx->base.throttling = ctx->base.throttling_value > 0;
 
     driParseOptionInfo(&defaultInitOptions, __driConfigOptionsNine);
-    driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "nine", NULL);
+    driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
+                        "nine", NULL, NULL, 0);
     if (driCheckOption(&userInitOptions, "throttle_value", DRI_INT)) {
         throttling_value_user = driQueryOptioni(&userInitOptions, "throttle_value");
         if (throttling_value_user == -1)
index 77361f8f6315a40760af7d3186f84029dfc4d5e4..b458c15abed5baf1c401f67899dbc6a85749e11d 100644 (file)
@@ -780,7 +780,9 @@ VkResult anv_CreateInstance(
 
    driParseOptionInfo(&instance->available_dri_options, anv_dri_options_xml);
    driParseConfigFiles(&instance->dri_options, &instance->available_dri_options,
-                       0, "anv", NULL);
+                       0, "anv", NULL,
+                       instance->app_info.engine_name,
+                       instance->app_info.engine_version);
 
    *pInstance = anv_instance_to_handle(instance);
 
index 7f29d19cfdf4d3df23fb6f6df23ec7aa8a075b6c..6894c65114fe53d57a5604105f21062e69bc257e 100644 (file)
@@ -185,7 +185,7 @@ static char *loader_get_dri_config_driver(int fd)
 
    driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
    driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
-                       "loader", kernel_driver);
+                       "loader", kernel_driver, NULL, 0);
    if (driCheckOption(&userInitOptions, "dri_driver", DRI_STRING)) {
       char *opt = driQueryOptionstr(&userInitOptions, "dri_driver");
       /* not an empty string */
@@ -206,7 +206,8 @@ static char *loader_get_dri_config_device_id(void)
    char *prime = NULL;
 
    driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
-   driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "loader", NULL);
+   driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
+                       "loader", NULL, NULL, 0);
    if (driCheckOption(&userInitOptions, "device_id", DRI_STRING))
       prime = strdup(driQueryOptionstr(&userInitOptions, "device_id"));
    driDestroyOptionCache(&userInitOptions);
index a384cadd55752f1d9dd5b1a808f4a8181fea8e00..45f614bf720eb2520f3bcf2396141ecc5cc17244 100644 (file)
@@ -148,7 +148,8 @@ driCreateNewScreen2(int scrn, int fd,
 
     /* Option parsing before ->InitScreen(), as some options apply there. */
     driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions);
-    driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, "dri2", NULL);
+    driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum,
+                        "dri2", NULL, NULL, 0);
 
     *driver_configs = psp->driver->InitScreen(psp);
     if (*driver_configs == NULL) {
index aa3175816cfe5a1ebcb325ba25af5c78e22850bb..14b56f614d9b6352cab5a3feae56986ba7ebdda3 100644 (file)
@@ -446,7 +446,7 @@ intelInitContext(struct intel_context *intel,
          0, sizeof(ctx->TextureFormatSupported));
 
    driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
-                       sPriv->myNum, "i915", NULL);
+                       sPriv->myNum, "i915", NULL, NULL, 0);
    intel->maxBatchSize = 4096;
 
    /* Estimate the size of the mappable aperture into the GTT.  There's an
index 6cec836da5c99ca687e263c97e7c2f5d0f7a566d..ac84864f521dbac5a99966f8513e4ad53ab46c87 100644 (file)
@@ -844,7 +844,7 @@ brw_process_driconf_options(struct brw_context *brw)
    driOptionCache *options = &brw->optionCache;
    driParseConfigFiles(options, &brw->screen->optionCache,
                        brw->driContext->driScreenPriv->myNum,
-                       "i965", NULL);
+                       "i965", NULL, NULL, 0);
 
    if (INTEL_DEBUG & DEBUG_NO_HIZ) {
        brw->has_hiz = false;
index b7d3a408c1f41b0182c8079e48256c9711eb7c68..81df6b34e653fae75614af18e364127c5c5692db 100644 (file)
@@ -2524,7 +2524,7 @@ __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen)
 
    driParseOptionInfo(&options, brw_config_options.xml);
    driParseConfigFiles(&screen->optionCache, &options, dri_screen->myNum,
-                       "i965", NULL);
+                       "i965", NULL, NULL, 0);
    driDestroyOptionCache(&options);
 
    screen->driScrnPriv = dri_screen;
index 4f210bf652266473dac777c4f42c02c4b256fab8..742862d2675b75b9dc2371a22be3868236ba1ffe 100644 (file)
@@ -216,13 +216,13 @@ GLboolean r200CreateContext( gl_api api,
     * the default textures.
     */
    driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache,
-                       screen->driScreen->myNum, "r200", NULL);
+                       screen->driScreen->myNum, "r200", NULL, NULL, 0);
    rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache,
                                                        "def_max_anisotropy");
 
    if (driQueryOptionb( &rmesa->radeon.optionCache, "hyperz"))
       rmesa->using_hyperz = GL_TRUE;
+
    /* Init default driver functions then plug in our R200-specific functions
     * (the texture functions are especially important)
     */
index 57c7079b2f2aac317d0232646fbfe46d07e78bdf..9db0ea6db3ea34d06d48357cc2de58a33da21bf2 100644 (file)
@@ -177,13 +177,13 @@ r100CreateContext( gl_api api,
 
    /* init exp fog table data */
    radeonInitStaticFogData();
-   
+
    /* Parse configuration files.
     * Do this here so that initialMaxAnisotropy is set before we create
     * the default textures.
     */
    driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache,
-                       screen->driScreen->myNum, "radeon", NULL);
+                       screen->driScreen->myNum, "radeon", NULL, NULL, 0);
    rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache,
                                                  "def_max_anisotropy");
 
index a927dcc5b4c788ec9c9334f2e4ab9ce8c84d3a3c..3deb8aee1a54316f72c049022d3d070103c4ff93 100644 (file)
@@ -30,11 +30,20 @@ TODO: document the other workarounds.
 
 <!DOCTYPE driconf [
    <!ELEMENT driconf      (device+)>
-   <!ELEMENT device       (application+)>
+   <!ELEMENT device       (application | engine)+>
    <!ATTLIST device       driver CDATA #IMPLIED>
    <!ELEMENT application  (option+)>
    <!ATTLIST application  name CDATA #REQUIRED
                           executable CDATA #REQUIRED>
+   <!ELEMENT engine       (option+)>
+
+   <!-- engine_name_match: A regexp matching the engine name -->
+   <!-- engine_version: A list of version in range format
+             (version 1 to 4 and version 7 to 8 : "1:4,7:8") -->
+
+   <!ATTLIST engine       engine_name_match CDATA #REQUIRED
+                          engine_versions CDATA #REQUIRED>
+
    <!ELEMENT option       EMPTY>
    <!ATTLIST option       name CDATA #REQUIRED
                           value CDATA #REQUIRED>
index d1b10c6605009a2cc22cad144cf1b41c59815e97..4b77ea7624f6b96345f8eec9785f60faf76fa885 100644 (file)
@@ -42,6 +42,7 @@
 #include <errno.h>
 #include <dirent.h>
 #include <fnmatch.h>
+#include <regex.h>
 #include "xmlconfig.h"
 #include "u_process.h"
 
@@ -699,6 +700,8 @@ struct OptConfData {
     int screenNum;
     const char *driverName, *execName;
     const char *kernelDriverName;
+    const char *engineName;
+    uint32_t engineVersion;
     uint32_t ignoringDevice;
     uint32_t ignoringApp;
     uint32_t inDriConf;
@@ -709,12 +712,13 @@ struct OptConfData {
 
 /** \brief Elements in configuration files. */
 enum OptConfElem {
-    OC_APPLICATION = 0, OC_DEVICE, OC_DRICONF, OC_OPTION, OC_COUNT
+    OC_APPLICATION = 0, OC_DEVICE, OC_DRICONF, OC_ENGINE, OC_OPTION, OC_COUNT
 };
 static const XML_Char *OptConfElems[] = {
     [OC_APPLICATION]  = "application",
     [OC_DEVICE] = "device",
     [OC_DRICONF] = "driconf",
+    [OC_ENGINE]  = "engine",
     [OC_OPTION] = "option",
 };
 
@@ -743,6 +747,20 @@ parseDeviceAttr(struct OptConfData *data, const XML_Char **attr)
     }
 }
 
+static bool
+valueInRanges(const driOptionInfo *info, uint32_t value)
+{
+    uint32_t i;
+
+    for (i = 0; i < info->nRanges; i++) {
+       if (info->ranges[i].start._int <= value &&
+           info->ranges[i].end._int >= value)
+           return true;
+    }
+
+    return false;
+}
+
 /** \brief Parse attributes of an application element. */
 static void
 parseAppAttr(struct OptConfData *data, const XML_Char **attr)
@@ -758,6 +776,40 @@ parseAppAttr(struct OptConfData *data, const XML_Char **attr)
         data->ignoringApp = data->inApp;
 }
 
+/** \brief Parse attributes of an application element. */
+static void
+parseEngineAttr(struct OptConfData *data, const XML_Char **attr)
+{
+    uint32_t i;
+    const XML_Char *engine_name_match = NULL, *engine_versions = NULL;
+    driOptionInfo version_ranges = {
+       .type = DRI_INT,
+    };
+    for (i = 0; attr[i]; i += 2) {
+        if (!strcmp (attr[i], "name")) /* not needed here */;
+        else if (!strcmp (attr[i], "engine_name_match")) engine_name_match = attr[i+1];
+        else if (!strcmp (attr[i], "engine_versions")) engine_versions = attr[i+1];
+        else XML_WARNING("unknown application attribute: %s.", attr[i]);
+    }
+    if (engine_name_match) {
+       regex_t re;
+
+       if (regcomp (&re, engine_name_match, REG_EXTENDED|REG_NOSUB) != 0) {
+          if (regexec (&re, data->engineName, 0, NULL, 0) == REG_NOMATCH)
+             data->ignoringApp = data->inApp;
+          regfree (&re);
+       } else
+          XML_WARNING ("Invalid engine_name_match=\"%s\".", engine_name_match);
+    }
+    if (engine_versions) {
+       if (parseRanges (&version_ranges, engine_versions) &&
+           !valueInRanges (&version_ranges, data->engineVersion))
+          data->ignoringApp = data->inApp;
+    }
+
+    free(version_ranges.ranges);
+}
+
 /** \brief Parse attributes of an option element. */
 static void
 parseOptConfAttr(struct OptConfData *data, const XML_Char **attr)
@@ -815,11 +867,20 @@ optConfStartElem(void *userData, const XML_Char *name,
         if (!data->inDevice)
             XML_WARNING1 ("<application> should be inside <device>.");
         if (data->inApp)
-            XML_WARNING1 ("nested <application> elements.");
+            XML_WARNING1 ("nested <application> or <engine> elements.");
         data->inApp++;
         if (!data->ignoringDevice && !data->ignoringApp)
             parseAppAttr (data, attr);
         break;
+      case OC_ENGINE:
+        if (!data->inDevice)
+            XML_WARNING1 ("<engine> should be inside <device>.");
+        if (data->inApp)
+            XML_WARNING1 ("nested <application> or <engine> elements.");
+        data->inApp++;
+        if (!data->ignoringDevice && !data->ignoringApp)
+            parseEngineAttr (data, attr);
+        break;
       case OC_OPTION:
         if (!data->inApp)
             XML_WARNING1 ("<option> should be inside <application>.");
@@ -849,6 +910,7 @@ optConfEndElem(void *userData, const XML_Char *name)
             data->ignoringDevice = 0;
         break;
       case OC_APPLICATION:
+      case OC_ENGINE:
         if (data->inApp-- == data->ignoringApp)
             data->ignoringApp = 0;
         break;
@@ -996,7 +1058,8 @@ parseConfigDir(struct OptConfData *data, const char *dirname)
 void
 driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
                     int screenNum, const char *driverName,
-                    const char *kernelDriverName)
+                    const char *kernelDriverName,
+                    const char *engineName, uint32_t engineVersion)
 {
     char *home;
     struct OptConfData userData;
@@ -1007,6 +1070,8 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
     userData.screenNum = screenNum;
     userData.driverName = driverName;
     userData.kernelDriverName = kernelDriverName;
+    userData.engineName = engineName ? engineName : "";
+    userData.engineVersion = engineVersion;
     userData.execName = util_get_process_name();
 
     parseConfigDir(&userData, DATADIR "/drirc.d");
index cc8c6ef098f4dfeadb219a4f6afc4cdac7e54304..6cc3e8b59d785d32ee3270d8a93f57be56946b60 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "util/mesa-sha1.h"
 #include "util/ralloc.h"
+#include <stdint.h>
 #include <string.h>
 
 #define STRING_CONF_MAXLEN 25
@@ -102,11 +103,12 @@ void driParseOptionInfo (driOptionCache *info,
                         const char *configOptions);
 /** \brief Initialize option cache from info and parse configuration files
  *
- * To be called in <driver>CreateContext. screenNum, driverName and
- * kernelDriverName select device sections. */
+ * To be called in <driver>CreateContext. screenNum, driverName,
+ * kernelDriverName and engineName select device sections. */
 void driParseConfigFiles (driOptionCache *cache, const driOptionCache *info,
                          int screenNum, const char *driverName,
-                         const char *kernelDriverName);
+                         const char *kernelDriverName,
+                         const char *engineName, uint32_t engineVersion);
 /** \brief Destroy option info
  *
  * To be called in <driver>DestroyScreen */