driconfig: Add support for device specific config

Add support for driconf overrides on a per-device level, for cases
where we don't want to override behavior for all devices supported
by a particular driver.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12135>
This commit is contained in:
Rob Clark
2021-07-28 18:17:42 -07:00
parent b080aa9466
commit 6edf0d8e90
22 changed files with 37 additions and 22 deletions

View File

@@ -874,7 +874,7 @@ radv_init_dri_options(struct radv_instance *instance)
{ {
driParseOptionInfo(&instance->available_dri_options, radv_dri_options, driParseOptionInfo(&instance->available_dri_options, radv_dri_options,
ARRAY_SIZE(radv_dri_options)); ARRAY_SIZE(radv_dri_options));
driParseConfigFiles(&instance->dri_options, &instance->available_dri_options, 0, "radv", NULL, driParseConfigFiles(&instance->dri_options, &instance->available_dri_options, 0, "radv", NULL, NULL,
instance->vk.app_info.app_name, instance->vk.app_info.app_version, instance->vk.app_info.app_name, instance->vk.app_info.app_version,
instance->vk.app_info.engine_name, instance->vk.app_info.engine_version); instance->vk.app_info.engine_name, instance->vk.app_info.engine_version);

View File

@@ -133,7 +133,7 @@ pipe_loader_config_options(struct pipe_loader_device *dev)
{ {
if (!dev->option_cache.info) { if (!dev->option_cache.info) {
driParseConfigFiles(&dev->option_cache, &dev->option_info, 0, driParseConfigFiles(&dev->option_cache, &dev->option_info, 0,
dev->driver_name, NULL, NULL, 0, NULL, 0); dev->driver_name, NULL, NULL, NULL, 0, NULL, 0);
} }
} }

View File

@@ -766,7 +766,7 @@ crocus_screen_create(int fd, const struct pipe_screen_config *config)
screen->no_hw = true; screen->no_hw = true;
driParseConfigFiles(config->options, config->options_info, 0, "crocus", driParseConfigFiles(config->options, config->options_info, 0, "crocus",
NULL, NULL, 0, NULL, 0); NULL, NULL, NULL, 0, NULL, 0);
bool bo_reuse = false; bool bo_reuse = false;
int bo_reuse_mode = driQueryOptioni(config->options, "bo_reuse"); int bo_reuse_mode = driQueryOptioni(config->options, "bo_reuse");

View File

@@ -812,7 +812,7 @@ iris_screen_create(int fd, const struct pipe_screen_config *config)
return NULL; return NULL;
driParseConfigFiles(config->options, config->options_info, 0, "iris", driParseConfigFiles(config->options, config->options_info, 0, "iris",
NULL, NULL, 0, NULL, 0); NULL, NULL, NULL, 0, NULL, 0);
bool bo_reuse = false; bool bo_reuse = false;
int bo_reuse_mode = driQueryOptioni(config->options, "bo_reuse"); int bo_reuse_mode = driQueryOptioni(config->options, "bo_reuse");

View File

@@ -1400,7 +1400,7 @@ struct pipe_screen *radeonsi_screen_create(int fd, const struct pipe_screen_conf
struct radeon_winsys *rw = NULL; struct radeon_winsys *rw = NULL;
driParseConfigFiles(config->options, config->options_info, 0, "radeonsi", driParseConfigFiles(config->options, config->options_info, 0, "radeonsi",
NULL, NULL, 0, NULL, 0); NULL, NULL, NULL, 0, NULL, 0);
switch (version->version_major) { switch (version->version_major) {
case 2: case 2:

View File

@@ -794,7 +794,7 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config,
goto fail; goto fail;
driParseConfigFiles(config->options, config->options_info, 0, "v3d", driParseConfigFiles(config->options, config->options_info, 0, "v3d",
NULL, NULL, 0, NULL, 0); NULL, NULL, NULL, 0, NULL, 0);
/* We have to driCheckOption for the simulator mode to not assertion /* We have to driCheckOption for the simulator mode to not assertion
* fail on not having our XML config. * fail on not having our XML config.

View File

@@ -943,7 +943,7 @@ virgl_create_screen(struct virgl_winsys *vws, const struct pipe_screen_config *c
if (config && config->options) { if (config && config->options) {
driParseConfigFiles(config->options, config->options_info, 0, "virtio_gpu", driParseConfigFiles(config->options, config->options_info, 0, "virtio_gpu",
NULL, NULL, 0, NULL, 0); NULL, NULL, NULL, 0, NULL, 0);
screen->tweak_gles_emulate_bgra = screen->tweak_gles_emulate_bgra =
driQueryOptionb(config->options, VIRGL_GLES_EMULATE_BGRA); driQueryOptionb(config->options, VIRGL_GLES_EMULATE_BGRA);

View File

@@ -1904,7 +1904,7 @@ zink_internal_create_screen(const struct pipe_screen_config *config)
#if WITH_XMLCONFIG #if WITH_XMLCONFIG
if (config) { if (config) {
driParseConfigFiles(config->options, config->options_info, 0, "zink", driParseConfigFiles(config->options, config->options_info, 0, "zink",
NULL, NULL, 0, NULL, 0); NULL, NULL, NULL, 0, NULL, 0);
screen->driconf.dual_color_blend_by_location = driQueryOptionb(config->options, "dual_color_blend_by_location"); screen->driconf.dual_color_blend_by_location = driQueryOptionb(config->options, "dual_color_blend_by_location");
//screen->driconf.inline_uniforms = driQueryOptionb(config->options, "radeonsi_inline_uniforms"); //screen->driconf.inline_uniforms = driQueryOptionb(config->options, "radeonsi_inline_uniforms");
} }

View File

@@ -257,7 +257,7 @@ drm_create_adapter( int fd,
driParseOptionInfo(&defaultInitOptions, __driConfigOptionsNine, driParseOptionInfo(&defaultInitOptions, __driConfigOptionsNine,
ARRAY_SIZE(__driConfigOptionsNine)); ARRAY_SIZE(__driConfigOptionsNine));
driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
"nine", NULL, NULL, 0, NULL, 0); "nine", NULL, NULL, NULL, 0, NULL, 0);
if (driCheckOption(&userInitOptions, "throttle_value", DRI_INT)) { if (driCheckOption(&userInitOptions, "throttle_value", DRI_INT)) {
throttling_value_user = driQueryOptioni(&userInitOptions, "throttle_value"); throttling_value_user = driQueryOptioni(&userInitOptions, "throttle_value");
if (throttling_value_user == -1) if (throttling_value_user == -1)

View File

@@ -1036,7 +1036,7 @@ anv_init_dri_options(struct anv_instance *instance)
driParseOptionInfo(&instance->available_dri_options, anv_dri_options, driParseOptionInfo(&instance->available_dri_options, anv_dri_options,
ARRAY_SIZE(anv_dri_options)); ARRAY_SIZE(anv_dri_options));
driParseConfigFiles(&instance->dri_options, driParseConfigFiles(&instance->dri_options,
&instance->available_dri_options, 0, "anv", NULL, &instance->available_dri_options, 0, "anv", NULL, NULL,
instance->vk.app_info.app_name, instance->vk.app_info.app_name,
instance->vk.app_info.app_version, instance->vk.app_info.app_version,
instance->vk.app_info.engine_name, instance->vk.app_info.engine_name,

View File

@@ -195,7 +195,7 @@ static char *loader_get_dri_config_driver(int fd)
driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader, driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader,
ARRAY_SIZE(__driConfigOptionsLoader)); ARRAY_SIZE(__driConfigOptionsLoader));
driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
"loader", kernel_driver, NULL, 0, NULL, 0); "loader", kernel_driver, NULL, NULL, 0, NULL, 0);
if (driCheckOption(&userInitOptions, "dri_driver", DRI_STRING)) { if (driCheckOption(&userInitOptions, "dri_driver", DRI_STRING)) {
char *opt = driQueryOptionstr(&userInitOptions, "dri_driver"); char *opt = driQueryOptionstr(&userInitOptions, "dri_driver");
/* not an empty string */ /* not an empty string */
@@ -218,7 +218,7 @@ static char *loader_get_dri_config_device_id(void)
driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader, driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader,
ARRAY_SIZE(__driConfigOptionsLoader)); ARRAY_SIZE(__driConfigOptionsLoader));
driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
"loader", NULL, NULL, 0, NULL, 0); "loader", NULL, NULL, NULL, 0, NULL, 0);
if (driCheckOption(&userInitOptions, "device_id", DRI_STRING)) if (driCheckOption(&userInitOptions, "device_id", DRI_STRING))
prime = strdup(driQueryOptionstr(&userInitOptions, "device_id")); prime = strdup(driQueryOptionstr(&userInitOptions, "device_id"));
driDestroyOptionCache(&userInitOptions); driDestroyOptionCache(&userInitOptions);

View File

@@ -155,7 +155,7 @@ driCreateNewScreen2(int scrn, int fd,
driParseOptionInfo(&psp->optionInfo, driParseOptionInfo(&psp->optionInfo,
__dri2ConfigOptions, ARRAY_SIZE(__dri2ConfigOptions)); __dri2ConfigOptions, ARRAY_SIZE(__dri2ConfigOptions));
driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum,
"dri2", NULL, NULL, 0, NULL, 0); "dri2", NULL, NULL, NULL, 0, NULL, 0);
*driver_configs = psp->driver->InitScreen(psp); *driver_configs = psp->driver->InitScreen(psp);
if (*driver_configs == NULL) { if (*driver_configs == NULL) {

View File

@@ -447,7 +447,7 @@ intelInitContext(struct intel_context *intel,
0, sizeof(ctx->TextureFormatSupported)); 0, sizeof(ctx->TextureFormatSupported));
driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache, driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
sPriv->myNum, "i915", NULL, NULL, 0, NULL, 0); sPriv->myNum, "i915", NULL, NULL, NULL, 0, NULL, 0);
intel->maxBatchSize = 4096; intel->maxBatchSize = 4096;
/* Estimate the size of the mappable aperture into the GTT. There's an /* Estimate the size of the mappable aperture into the GTT. There's an

View File

@@ -2543,7 +2543,7 @@ __DRIconfig **brw_init_screen(__DRIscreen *dri_screen)
driParseOptionInfo(&options, brw_driconf, ARRAY_SIZE(brw_driconf)); driParseOptionInfo(&options, brw_driconf, ARRAY_SIZE(brw_driconf));
driParseConfigFiles(&screen->optionCache, &options, dri_screen->myNum, driParseConfigFiles(&screen->optionCache, &options, dri_screen->myNum,
"i965", NULL, NULL, 0, NULL, 0); "i965", NULL, NULL, NULL, 0, NULL, 0);
driDestroyOptionCache(&options); driDestroyOptionCache(&options);
screen->driScrnPriv = dri_screen; screen->driScrnPriv = dri_screen;

View File

@@ -217,7 +217,7 @@ GLboolean r200CreateContext( gl_api api,
* the default textures. * the default textures.
*/ */
driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache, driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache,
screen->driScreen->myNum, "r200", NULL, NULL, 0, NULL, 0); screen->driScreen->myNum, "r200", NULL, NULL, NULL, 0, NULL, 0);
rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache, rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache,
"def_max_anisotropy"); "def_max_anisotropy");

View File

@@ -183,7 +183,7 @@ r100CreateContext( gl_api api,
* the default textures. * the default textures.
*/ */
driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache, driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache,
screen->driScreen->myNum, "radeon", NULL, NULL, 0, NULL, 0); screen->driScreen->myNum, "radeon", NULL, NULL, NULL, 0, NULL, 0);
rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache, rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache,
"def_max_anisotropy"); "def_max_anisotropy");

View File

@@ -31,7 +31,8 @@ TODO: document the other workarounds.
<!DOCTYPE driconf [ <!DOCTYPE driconf [
<!ELEMENT driconf (device+)> <!ELEMENT driconf (device+)>
<!ELEMENT device (application | engine)+> <!ELEMENT device (application | engine)+>
<!ATTLIST device driver CDATA #IMPLIED> <!ATTLIST device driver CDATA #IMPLIED
device CDATA #IMPLIED>
<!ELEMENT application (option+)> <!ELEMENT application (option+)>
<!ATTLIST application name CDATA #REQUIRED <!ATTLIST application name CDATA #REQUIRED
executable CDATA #IMPLIED executable CDATA #IMPLIED

View File

@@ -68,6 +68,7 @@ class Device(object):
def __init__(self, xml): def __init__(self, xml):
self.cname = cname('device') self.cname = cname('device')
self.driver = xml.attrib.get('driver', None) self.driver = xml.attrib.get('driver', None)
self.device = xml.attrib.get('device', None)
self.applications = [] self.applications = []
self.engines = [] self.engines = []
@@ -133,6 +134,7 @@ struct driconf_engine {
struct driconf_device { struct driconf_device {
const char *driver; const char *driver;
const char *device;
unsigned num_engines; unsigned num_engines;
const struct driconf_engine *engines; const struct driconf_engine *engines;
unsigned num_applications; unsigned num_applications;
@@ -196,6 +198,9 @@ static const struct driconf_application ${device.cname}_applications[] = {
static const struct driconf_device ${device.cname} = { static const struct driconf_device ${device.cname} = {
% if device.driver: % if device.driver:
.driver = "${device.driver}", .driver = "${device.driver}",
% endif
% if device.device:
.device = "${device.device}",
% endif % endif
.num_engines = ${len(device.engines)}, .num_engines = ${len(device.engines)},
% if len(device.engines) > 0: % if len(device.engines) > 0:

View File

@@ -143,7 +143,7 @@ TEST_F(xmlconfig_test, copy_cache)
* user's homedir/environment that would override us. * user's homedir/environment that would override us.
*/ */
driParseConfigFiles(&cache, &options, driParseConfigFiles(&cache, &options,
0, "driver", "drm", 0, "driver", "drm", NULL,
NULL, 0, NULL, 0,
NULL, 0); NULL, 0);
@@ -184,7 +184,7 @@ xmlconfig_test::drirc_init(const char *driver, const char *drm,
* based on the setting of $HOME by meson.build. * based on the setting of $HOME by meson.build.
*/ */
driParseConfigFiles(&cache, &options, driParseConfigFiles(&cache, &options,
0, driver, drm, 0, driver, drm, NULL,
app, appver, app, appver,
engine, enginever); engine, enginever);

View File

@@ -595,6 +595,7 @@ struct OptConfData {
int screenNum; int screenNum;
const char *driverName, *execName; const char *driverName, *execName;
const char *kernelDriverName; const char *kernelDriverName;
const char *deviceName;
const char *engineName; const char *engineName;
const char *applicationName; const char *applicationName;
uint32_t engineVersion; uint32_t engineVersion;
@@ -648,11 +649,12 @@ static void
parseDeviceAttr(struct OptConfData *data, const char **attr) parseDeviceAttr(struct OptConfData *data, const char **attr)
{ {
uint32_t i; uint32_t i;
const char *driver = NULL, *screen = NULL, *kernel = NULL; const char *driver = NULL, *screen = NULL, *kernel = NULL, *device = NULL;
for (i = 0; attr[i]; i += 2) { for (i = 0; attr[i]; i += 2) {
if (!strcmp(attr[i], "driver")) driver = attr[i+1]; if (!strcmp(attr[i], "driver")) driver = attr[i+1];
else if (!strcmp(attr[i], "screen")) screen = attr[i+1]; else if (!strcmp(attr[i], "screen")) screen = attr[i+1];
else if (!strcmp(attr[i], "kernel_driver")) kernel = attr[i+1]; else if (!strcmp(attr[i], "kernel_driver")) kernel = attr[i+1];
else if (!strcmp(attr[i], "device")) device = attr[i+1];
else XML_WARNING("unknown device attribute: %s.", attr[i]); else XML_WARNING("unknown device attribute: %s.", attr[i]);
} }
if (driver && strcmp(driver, data->driverName)) if (driver && strcmp(driver, data->driverName))
@@ -660,6 +662,9 @@ parseDeviceAttr(struct OptConfData *data, const char **attr)
else if (kernel && (!data->kernelDriverName || else if (kernel && (!data->kernelDriverName ||
strcmp(kernel, data->kernelDriverName))) strcmp(kernel, data->kernelDriverName)))
data->ignoringDevice = data->inDevice; data->ignoringDevice = data->inDevice;
else if (device && (!data->deviceName ||
strcmp(device, data->deviceName)))
data->ignoringDevice = data->inDevice;
else if (screen) { else if (screen) {
driOptionValue screenNum; driOptionValue screenNum;
if (!parseValue(&screenNum, DRI_INT, screen)) if (!parseValue(&screenNum, DRI_INT, screen))
@@ -1059,6 +1064,7 @@ parseStaticConfig(struct OptConfData *data)
const struct driconf_device *d = driconf[i]; const struct driconf_device *d = driconf[i];
const char *devattr[] = { const char *devattr[] = {
"driver", d->driver, "driver", d->driver,
"device", d->device,
NULL NULL
}; };
@@ -1149,6 +1155,7 @@ void
driParseConfigFiles(driOptionCache *cache, const driOptionCache *info, driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
int screenNum, const char *driverName, int screenNum, const char *driverName,
const char *kernelDriverName, const char *kernelDriverName,
const char *deviceName,
const char *applicationName, uint32_t applicationVersion, const char *applicationName, uint32_t applicationVersion,
const char *engineName, uint32_t engineVersion) const char *engineName, uint32_t engineVersion)
{ {
@@ -1159,6 +1166,7 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
userData.screenNum = screenNum; userData.screenNum = screenNum;
userData.driverName = driverName; userData.driverName = driverName;
userData.kernelDriverName = kernelDriverName; userData.kernelDriverName = kernelDriverName;
userData.deviceName = deviceName;
userData.applicationName = applicationName ? applicationName : ""; userData.applicationName = applicationName ? applicationName : "";
userData.applicationVersion = applicationVersion; userData.applicationVersion = applicationVersion;
userData.engineName = engineName ? engineName : ""; userData.engineName = engineName ? engineName : "";

View File

@@ -139,6 +139,7 @@ void driParseOptionInfo(driOptionCache *info,
void driParseConfigFiles(driOptionCache *cache, const driOptionCache *info, void driParseConfigFiles(driOptionCache *cache, const driOptionCache *info,
int screenNum, const char *driverName, int screenNum, const char *driverName,
const char *kernelDriverName, const char *kernelDriverName,
const char *deviceName,
const char *applicationName, uint32_t applicationVersion, const char *applicationName, uint32_t applicationVersion,
const char *engineName, uint32_t engineVersion); const char *engineName, uint32_t engineVersion);
/** \brief Destroy option info /** \brief Destroy option info

View File

@@ -726,7 +726,7 @@ vn_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
driParseOptionInfo(&instance->available_dri_options, vn_dri_options, driParseOptionInfo(&instance->available_dri_options, vn_dri_options,
ARRAY_SIZE(vn_dri_options)); ARRAY_SIZE(vn_dri_options));
driParseConfigFiles(&instance->dri_options, driParseConfigFiles(&instance->dri_options,
&instance->available_dri_options, 0, "venus", NULL, &instance->available_dri_options, 0, "venus", NULL, NULL,
instance->base.base.app_info.app_name, instance->base.base.app_info.app_name,
instance->base.base.app_info.app_version, instance->base.base.app_info.app_version,
instance->base.base.app_info.engine_name, instance->base.base.app_info.engine_name,