vulkan: Rework extension disabling on Android

Instead of building it into the auto-generated condition we use for the
per-driver ${driver}_physical_device_get_supported_extensions()
function, generate a table and handle it inside the various common
extension enumeration and verification routines.  This reduces our
reliance on code-gen for extension enables.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tested-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8792>
This commit is contained in:
Jason Ekstrand 2021-01-30 11:13:33 -06:00 committed by Marge Bot
parent 0260b4a7e7
commit cf54fc768e
5 changed files with 60 additions and 20 deletions

View file

@ -65,6 +65,11 @@ vk_device_init(struct vk_device *device,
if (!physical_device->supported_extensions.extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
#ifdef ANDROID
if (!vk_android_allowed_device_extensions.extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
#endif
device->enabled_extensions.extensions[idx] = true;
}

View file

@ -16,6 +16,17 @@ class Extension:
self.ext_version = int(ext_version)
self.enable = _bool_to_c_expr(enable)
def c_android_condition(self):
# if it's an EXT or vendor extension, it's allowed
if not self.name.startswith(ANDROID_EXTENSION_WHITELIST_PREFIXES):
return 'true'
allowed_version = ALLOWED_ANDROID_VERSION.get(self.name, None)
if allowed_version is None:
return 'false'
return 'ANDROID_API_LEVEL >= %d' % (allowed_version)
class ApiVersion:
def __init__(self, version, enable):
self.version = version
@ -124,7 +135,7 @@ def init_exts_from_xml(xml, extensions, platform_defines):
# Mapping between extension name and the android version in which the extension
# was whitelisted in Android CTS.
allowed_android_version = {
ALLOWED_ANDROID_VERSION = {
# Allowed Instance KHR Extensions
"VK_KHR_surface": 26,
"VK_KHR_display": 26,
@ -195,19 +206,9 @@ allowed_android_version = {
# Extensions with these prefixes are checked in Android CTS, and thus must be
# whitelisted per the preceding dict.
android_extension_whitelist_prefixes = (
ANDROID_EXTENSION_WHITELIST_PREFIXES = (
"VK_KHX",
"VK_KHR",
"VK_GOOGLE",
"VK_ANDROID"
)
def get_extension_condition(ext_name, condition):
""" If |ext_name| is an extension that Android CTS cares about, prepend
a condition to ensure that the extension is only enabled for Android
versions in which the extension is whitelisted in CTS. """
if not ext_name.startswith(android_extension_whitelist_prefixes):
return condition
allowed_version = allowed_android_version.get(ext_name, 9999)
return "(!ANDROID || ANDROID_API_LEVEL >= %d) && (%s)" % (allowed_version,
condition)

View file

@ -78,7 +78,12 @@ struct vk_device_extension_table {
struct ${driver}_physical_device;
%if driver != 'vk':
%if driver == 'vk':
#ifdef ANDROID
extern const struct vk_instance_extension_table vk_android_allowed_instance_extensions;
extern const struct vk_device_extension_table vk_android_allowed_device_extensions;
#endif
%else:
extern const struct vk_instance_extension_table ${driver}_instance_extensions_supported;
void
@ -110,6 +115,20 @@ const VkExtensionProperties ${driver}_device_extensions[${driver.upper()}_DEVICE
{"${ext.name}", ${ext.ext_version}},
%endfor
};
#ifdef ANDROID
const struct vk_instance_extension_table vk_android_allowed_instance_extensions = {
%for ext in instance_extensions:
.${ext.name[3:]} = ${ext.c_android_condition()},
%endfor
};
extern const struct vk_device_extension_table vk_android_allowed_device_extensions = {
%for ext in device_extensions:
.${ext.name[3:]} = ${ext.c_android_condition()},
%endfor
};
#endif
%endif
%if driver != 'vk':
@ -150,7 +169,7 @@ VkResult ${driver}_EnumerateInstanceVersion(
const struct vk_instance_extension_table ${driver}_instance_extensions_supported = {
%for ext in instance_extensions:
.${ext.name[3:]} = ${get_extension_condition(ext.name, ext.enable)},
.${ext.name[3:]} = ${ext.enable},
%endfor
};
@ -178,7 +197,7 @@ ${driver}_physical_device_get_supported_extensions(const struct ${driver}_physic
{
*extensions = (struct vk_device_extension_table) {
%for ext in device_extensions:
.${ext.name[3:]} = ${get_extension_condition(ext.name, ext.enable)},
.${ext.name[3:]} = ${ext.enable},
%endfor
};
}
@ -201,7 +220,6 @@ def gen_extensions(driver, xml_files, api_versions, max_api_version,
'instance_extensions': [e for e in extensions if e.type == 'instance'],
'device_extensions': [e for e in extensions if e.type == 'device'],
'platform_defines': platform_defines,
'get_extension_condition': get_extension_condition,
'includes': includes,
}

View file

@ -72,6 +72,11 @@ vk_instance_init(struct vk_instance *instance,
if (!supported_extensions->extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
#ifdef ANDROID
if (!vk_android_allowed_instance_extensions.extensions[idx])
return VK_ERROR_EXTENSION_NOT_PRESENT;
#endif
instance->enabled_extensions.extensions[idx] = true;
}
@ -110,6 +115,11 @@ vk_enumerate_instance_extension_properties(
if (!supported_extensions->extensions[i])
continue;
#ifdef ANDROID
if (!vk_android_allowed_instance_extensions.extensions[i])
continue;
#endif
vk_outarray_append(&out, prop) {
*prop = vk_instance_extensions[i];
}

View file

@ -78,10 +78,16 @@ vk_common_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
for (int i = 0; i < VK_DEVICE_EXTENSION_COUNT; i++) {
if (pdevice->supported_extensions.extensions[i]) {
vk_outarray_append(&out, prop) {
*prop = vk_device_extensions[i];
}
if (!pdevice->supported_extensions.extensions[i])
continue;
#ifdef ANDROID
if (!vk_android_allowed_device_extensions.extensions[i])
continue;
#endif
vk_outarray_append(&out, prop) {
*prop = vk_device_extensions[i];
}
}