Path: blob/21.2-virgl/src/vulkan/util/vk_extensions.py
7136 views
import argparse1import copy2import re3import xml.etree.ElementTree as et45def _bool_to_c_expr(b):6if b is True:7return 'true'8if b is False:9return 'false'10return b1112class Extension:13def __init__(self, name, ext_version, enable):14self.name = name15self.ext_version = int(ext_version)16self.enable = _bool_to_c_expr(enable)1718def c_android_condition(self):19# if it's an EXT or vendor extension, it's allowed20if not self.name.startswith(ANDROID_EXTENSION_WHITELIST_PREFIXES):21return 'true'2223allowed_version = ALLOWED_ANDROID_VERSION.get(self.name, None)24if allowed_version is None:25return 'false'2627return 'ANDROID_API_LEVEL >= %d' % (allowed_version)2829class ApiVersion:30def __init__(self, version, enable):31self.version = version32self.enable = _bool_to_c_expr(enable)3334class VkVersion:35def __init__(self, string):36split = string.split('.')37self.major = int(split[0])38self.minor = int(split[1])39if len(split) > 2:40assert len(split) == 341self.patch = int(split[2])42else:43self.patch = None4445# Sanity check. The range bits are required by the definition of the46# VK_MAKE_VERSION macro47assert self.major < 1024 and self.minor < 102448assert self.patch is None or self.patch < 409649assert(str(self) == string)5051def __str__(self):52ver_list = [str(self.major), str(self.minor)]53if self.patch is not None:54ver_list.append(str(self.patch))55return '.'.join(ver_list)5657def c_vk_version(self):58patch = self.patch if self.patch is not None else 059ver_list = [str(self.major), str(self.minor), str(patch)]60return 'VK_MAKE_VERSION(' + ', '.join(ver_list) + ')'6162def __int_ver(self):63# This is just an expansion of VK_VERSION64patch = self.patch if self.patch is not None else 065return (self.major << 22) | (self.minor << 12) | patch6667def __gt__(self, other):68# If only one of them has a patch version, "ignore" it by making69# other's patch version match self.70if (self.patch is None) != (other.patch is None):71other = copy.copy(other)72other.patch = self.patch7374return self.__int_ver() > other.__int_ver()7576# Sort the extension list the way we expect: KHR, then EXT, then vendors77# alphabetically. For digits, read them as a whole number sort that.78# eg.: VK_KHR_8bit_storage < VK_KHR_16bit_storage < VK_EXT_acquire_xlib_display79def extension_order(ext):80order = []81for substring in re.split('(KHR|EXT|[0-9]+)', ext.name):82if substring == 'KHR':83order.append(1)84if substring == 'EXT':85order.append(2)86elif substring.isdigit():87order.append(int(substring))88else:89order.append(substring)90return order9192def get_all_exts_from_xml(xml):93""" Get a list of all Vulkan extensions. """9495xml = et.parse(xml)9697extensions = []98for ext_elem in xml.findall('.extensions/extension'):99supported = ext_elem.attrib['supported'] == 'vulkan'100name = ext_elem.attrib['name']101if not supported and name != 'VK_ANDROID_native_buffer':102continue103version = None104for enum_elem in ext_elem.findall('.require/enum'):105if enum_elem.attrib['name'].endswith('_SPEC_VERSION'):106assert version is None107version = int(enum_elem.attrib['value'])108ext = Extension(name, version, True)109extensions.append(Extension(name, version, True))110111return sorted(extensions, key=extension_order)112113def init_exts_from_xml(xml, extensions, platform_defines):114""" Walk the Vulkan XML and fill out extra extension information. """115116xml = et.parse(xml)117118ext_name_map = {}119for ext in extensions:120ext_name_map[ext.name] = ext121122# KHR_display is missing from the list.123platform_defines.append('VK_USE_PLATFORM_DISPLAY_KHR')124for platform in xml.findall('./platforms/platform'):125platform_defines.append(platform.attrib['protect'])126127for ext_elem in xml.findall('.extensions/extension'):128ext_name = ext_elem.attrib['name']129if ext_name not in ext_name_map:130continue131132ext = ext_name_map[ext_name]133ext.type = ext_elem.attrib['type']134135# Mapping between extension name and the android version in which the extension136# was whitelisted in Android CTS.137ALLOWED_ANDROID_VERSION = {138# Allowed Instance KHR Extensions139"VK_KHR_surface": 26,140"VK_KHR_display": 26,141"VK_KHR_android_surface": 26,142"VK_KHR_mir_surface": 26,143"VK_KHR_wayland_surface": 26,144"VK_KHR_win32_surface": 26,145"VK_KHR_xcb_surface": 26,146"VK_KHR_xlib_surface": 26,147"VK_KHR_get_physical_device_properties2": 26,148"VK_KHR_get_surface_capabilities2": 26,149"VK_KHR_external_memory_capabilities": 28,150"VK_KHR_external_semaphore_capabilities": 28,151"VK_KHR_external_fence_capabilities": 28,152"VK_KHR_device_group_creation": 28,153"VK_KHR_get_display_properties2": 29,154"VK_KHR_surface_protected_capabilities": 29,155156# Allowed Device KHR Extensions157"VK_KHR_swapchain": 26,158"VK_KHR_display_swapchain": 26,159"VK_KHR_sampler_mirror_clamp_to_edge": 26,160"VK_KHR_shader_draw_parameters": 26,161"VK_KHR_shader_float_controls": 29,162"VK_KHR_shader_float16_int8": 29,163"VK_KHR_maintenance1": 26,164"VK_KHR_push_descriptor": 26,165"VK_KHR_descriptor_update_template": 26,166"VK_KHR_incremental_present": 26,167"VK_KHR_shared_presentable_image": 26,168"VK_KHR_storage_buffer_storage_class": 28,169"VK_KHR_8bit_storage": 29,170"VK_KHR_16bit_storage": 28,171"VK_KHR_get_memory_requirements2": 28,172"VK_KHR_external_memory": 28,173"VK_KHR_external_memory_fd": 28,174"VK_KHR_external_memory_win32": 28,175"VK_KHR_external_semaphore": 28,176"VK_KHR_external_semaphore_fd": 28,177"VK_KHR_external_semaphore_win32": 28,178"VK_KHR_external_fence": 28,179"VK_KHR_external_fence_fd": 28,180"VK_KHR_external_fence_win32": 28,181"VK_KHR_win32_keyed_mutex": 28,182"VK_KHR_dedicated_allocation": 28,183"VK_KHR_variable_pointers": 28,184"VK_KHR_relaxed_block_layout": 28,185"VK_KHR_bind_memory2": 28,186"VK_KHR_maintenance2": 28,187"VK_KHR_image_format_list": 28,188"VK_KHR_sampler_ycbcr_conversion": 28,189"VK_KHR_device_group": 28,190"VK_KHR_multiview": 28,191"VK_KHR_maintenance3": 28,192"VK_KHR_draw_indirect_count": 28,193"VK_KHR_create_renderpass2": 28,194"VK_KHR_depth_stencil_resolve": 29,195"VK_KHR_driver_properties": 28,196"VK_KHR_swapchain_mutable_format": 29,197"VK_KHR_shader_atomic_int64": 29,198"VK_KHR_vulkan_memory_model": 29,199"VK_KHR_performance_query": 30,200201"VK_GOOGLE_display_timing": 26,202"VK_ANDROID_native_buffer": 26,203"VK_ANDROID_external_memory_android_hardware_buffer": 28,204}205206# Extensions with these prefixes are checked in Android CTS, and thus must be207# whitelisted per the preceding dict.208ANDROID_EXTENSION_WHITELIST_PREFIXES = (209"VK_KHX",210"VK_KHR",211"VK_GOOGLE",212"VK_ANDROID"213)214215216