aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorLionel Landwerlin <[email protected]>2019-09-08 12:59:32 +0300
committerLionel Landwerlin <[email protected]>2019-09-15 15:37:02 +0300
commit04dc6074cf7f651b720868e0ba24362b585d1b31 (patch)
treea4d6f4ec7a4ce32b397fbca1a0e6510539da14dc /src/util
parent6d5f11ab345b05759c22acbcd2f79928311689e3 (diff)
driconfig: add a new engine name/version parameter
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 <[email protected]> Reviewed-by: Eric Engestrom <[email protected]> Reviewed-by: Bas Nieuwenhuizen <[email protected]> Cc: 19.2 <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/00-mesa-defaults.conf11
-rw-r--r--src/util/xmlconfig.c71
-rw-r--r--src/util/xmlconfig.h8
3 files changed, 83 insertions, 7 deletions
diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf
index a927dcc5b4c..3deb8aee1a5 100644
--- a/src/util/00-mesa-defaults.conf
+++ b/src/util/00-mesa-defaults.conf
@@ -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>
diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c
index d1b10c66050..4b77ea7624f 100644
--- a/src/util/xmlconfig.c
+++ b/src/util/xmlconfig.c
@@ -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");
diff --git a/src/util/xmlconfig.h b/src/util/xmlconfig.h
index cc8c6ef098f..6cc3e8b59d7 100644
--- a/src/util/xmlconfig.h
+++ b/src/util/xmlconfig.h
@@ -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 */