1import copy 2import re 3import xml.etree.ElementTree as et 4 5def get_api_list(s): 6 apis = [] 7 for a in s.split(','): 8 if a == 'disabled': 9 continue 10 assert a in ('vulkan', 'vulkansc') 11 apis.append(a) 12 return apis 13 14class Extension: 15 def __init__(self, name, number, ext_version): 16 self.name = name 17 self.type = None 18 self.number = number 19 self.platform = None 20 self.provisional = False 21 self.ext_version = int(ext_version) 22 self.supported = [] 23 24 def from_xml(ext_elem): 25 name = ext_elem.attrib['name'] 26 number = int(ext_elem.attrib['number']) 27 supported = get_api_list(ext_elem.attrib['supported']) 28 if name == 'VK_ANDROID_native_buffer': 29 assert not supported 30 supported = ['vulkan'] 31 32 if not supported: 33 return Extension(name, number, 0) 34 35 version = None 36 for enum_elem in ext_elem.findall('.require/enum'): 37 if enum_elem.attrib['name'].endswith('_SPEC_VERSION'): 38 # Skip alias SPEC_VERSIONs 39 if 'value' in enum_elem.attrib: 40 assert version is None 41 version = int(enum_elem.attrib['value']) 42 43 assert version is not None 44 ext = Extension(name, number, version) 45 ext.type = ext_elem.attrib['type'] 46 ext.platform = ext_elem.attrib.get('platform', None) 47 ext.provisional = ext_elem.attrib.get('provisional', False) 48 ext.supported = supported 49 50 return ext 51 52 def c_android_condition(self): 53 # if it's an EXT or vendor extension, it's allowed 54 if not self.name.startswith(ANDROID_EXTENSION_WHITELIST_PREFIXES): 55 return 'true' 56 57 allowed_version = ALLOWED_ANDROID_VERSION.get(self.name, None) 58 if allowed_version is None: 59 return 'false' 60 61 return 'ANDROID_API_LEVEL >= %d' % (allowed_version) 62 63class ApiVersion: 64 def __init__(self, version): 65 self.version = version 66 67class VkVersion: 68 def __init__(self, string): 69 split = string.split('.') 70 self.major = int(split[0]) 71 self.minor = int(split[1]) 72 if len(split) > 2: 73 assert len(split) == 3 74 self.patch = int(split[2]) 75 else: 76 self.patch = None 77 78 # Sanity check. The range bits are required by the definition of the 79 # VK_MAKE_VERSION macro 80 assert self.major < 1024 and self.minor < 1024 81 assert self.patch is None or self.patch < 4096 82 assert str(self) == string 83 84 def __str__(self): 85 ver_list = [str(self.major), str(self.minor)] 86 if self.patch is not None: 87 ver_list.append(str(self.patch)) 88 return '.'.join(ver_list) 89 90 def c_vk_version(self): 91 ver_list = [str(self.major), str(self.minor), str(self.patch or 0)] 92 return 'VK_MAKE_VERSION(' + ', '.join(ver_list) + ')' 93 94 def __int_ver(self): 95 # This is just an expansion of VK_VERSION 96 return (self.major << 22) | (self.minor << 12) | (self.patch or 0) 97 98 def __gt__(self, other): 99 # If only one of them has a patch version, "ignore" it by making 100 # other's patch version match self. 101 if (self.patch is None) != (other.patch is None): 102 other = copy.copy(other) 103 other.patch = self.patch 104 105 return self.__int_ver() > other.__int_ver() 106 107# Sort the extension list the way we expect: KHR, then EXT, then vendors 108# alphabetically. For digits, read them as a whole number sort that. 109# eg.: VK_KHR_8bit_storage < VK_KHR_16bit_storage < VK_EXT_acquire_xlib_display 110def extension_order(ext): 111 order = [] 112 for substring in re.split('(KHR|EXT|[0-9]+)', ext.name): 113 if substring == 'KHR': 114 order.append(1) 115 if substring == 'EXT': 116 order.append(2) 117 elif substring.isdigit(): 118 order.append(int(substring)) 119 else: 120 order.append(substring) 121 return order 122 123def get_all_exts_from_xml(xml, api='vulkan'): 124 """ Get a list of all Vulkan extensions. """ 125 126 xml = et.parse(xml) 127 128 extensions = [] 129 for ext_elem in xml.findall('.extensions/extension'): 130 ext = Extension.from_xml(ext_elem) 131 if api in ext.supported: 132 extensions.append(ext) 133 134 return sorted(extensions, key=extension_order) 135 136def init_exts_from_xml(xml, extensions, platform_defines): 137 """ Walk the Vulkan XML and fill out extra extension information. """ 138 139 xml = et.parse(xml) 140 141 ext_name_map = {} 142 for ext in extensions: 143 ext_name_map[ext.name] = ext 144 145 # KHR_display is missing from the list. 146 platform_defines.append('VK_USE_PLATFORM_DISPLAY_KHR') 147 for platform in xml.findall('./platforms/platform'): 148 platform_defines.append(platform.attrib['protect']) 149 150 for ext_elem in xml.findall('.extensions/extension'): 151 ext_name = ext_elem.attrib['name'] 152 if ext_name not in ext_name_map: 153 continue 154 155 ext = ext_name_map[ext_name] 156 ext.type = ext_elem.attrib['type'] 157 158class Requirements: 159 def __init__(self, core_version=None): 160 self.core_version = core_version 161 self.extensions = [] 162 self.guard = None 163 164 def add_extension(self, ext): 165 for e in self.extensions: 166 if e == ext: 167 return; 168 assert e.name != ext.name 169 170 self.extensions.append(ext) 171 172def filter_api(elem, api): 173 if 'api' not in elem.attrib: 174 return True 175 176 return api in elem.attrib['api'].split(',') 177 178def get_all_required(xml, thing, api, beta): 179 things = {} 180 for feature in xml.findall('./feature'): 181 if not filter_api(feature, api): 182 continue 183 184 version = VkVersion(feature.attrib['number']) 185 for t in feature.findall('./require/' + thing): 186 name = t.attrib['name'] 187 assert name not in things 188 things[name] = Requirements(core_version=version) 189 190 for extension in xml.findall('.extensions/extension'): 191 ext = Extension.from_xml(extension) 192 if api not in ext.supported: 193 continue 194 195 if beta != 'true' and ext.provisional: 196 continue 197 198 for require in extension.findall('./require'): 199 if not filter_api(require, api): 200 continue 201 202 for t in require.findall('./' + thing): 203 name = t.attrib['name'] 204 r = things.setdefault(name, Requirements()) 205 r.add_extension(ext) 206 207 platform_defines = {} 208 for platform in xml.findall('./platforms/platform'): 209 name = platform.attrib['name'] 210 define = platform.attrib['protect'] 211 platform_defines[name] = define 212 213 for req in things.values(): 214 if req.core_version is not None: 215 continue 216 217 for ext in req.extensions: 218 if ext.platform in platform_defines: 219 req.guard = platform_defines[ext.platform] 220 break 221 222 return things 223 224# Mapping between extension name and the android version in which the extension 225# was whitelisted in Android CTS's dEQP-VK.info.device_extensions and 226# dEQP-VK.api.info.android.no_unknown_extensions, excluding those blocked by 227# android.graphics.cts.VulkanFeaturesTest#testVulkanBlockedExtensions. 228ALLOWED_ANDROID_VERSION = { 229 # checkInstanceExtensions on oreo-cts-release 230 "VK_KHR_surface": 26, 231 "VK_KHR_display": 26, 232 "VK_KHR_android_surface": 26, 233 "VK_KHR_mir_surface": 26, 234 "VK_KHR_wayland_surface": 26, 235 "VK_KHR_win32_surface": 26, 236 "VK_KHR_xcb_surface": 26, 237 "VK_KHR_xlib_surface": 26, 238 "VK_KHR_get_physical_device_properties2": 26, 239 "VK_KHR_get_surface_capabilities2": 26, 240 "VK_KHR_external_memory_capabilities": 26, 241 "VK_KHR_external_semaphore_capabilities": 26, 242 "VK_KHR_external_fence_capabilities": 26, 243 # on pie-cts-release 244 "VK_KHR_device_group_creation": 28, 245 "VK_KHR_get_display_properties2": 28, 246 # on android10-tests-release 247 "VK_KHR_surface_protected_capabilities": 29, 248 # on android13-tests-release 249 "VK_KHR_portability_enumeration": 33, 250 251 # checkDeviceExtensions on oreo-cts-release 252 "VK_KHR_swapchain": 26, 253 "VK_KHR_display_swapchain": 26, 254 "VK_KHR_sampler_mirror_clamp_to_edge": 26, 255 "VK_KHR_shader_draw_parameters": 26, 256 "VK_KHR_maintenance1": 26, 257 "VK_KHR_push_descriptor": 26, 258 "VK_KHR_descriptor_update_template": 26, 259 "VK_KHR_incremental_present": 26, 260 "VK_KHR_shared_presentable_image": 26, 261 "VK_KHR_storage_buffer_storage_class": 26, 262 "VK_KHR_16bit_storage": 26, 263 "VK_KHR_get_memory_requirements2": 26, 264 "VK_KHR_external_memory": 26, 265 "VK_KHR_external_memory_fd": 26, 266 "VK_KHR_external_memory_win32": 26, 267 "VK_KHR_external_semaphore": 26, 268 "VK_KHR_external_semaphore_fd": 26, 269 "VK_KHR_external_semaphore_win32": 26, 270 "VK_KHR_external_fence": 26, 271 "VK_KHR_external_fence_fd": 26, 272 "VK_KHR_external_fence_win32": 26, 273 "VK_KHR_win32_keyed_mutex": 26, 274 "VK_KHR_dedicated_allocation": 26, 275 "VK_KHR_variable_pointers": 26, 276 "VK_KHR_relaxed_block_layout": 26, 277 "VK_KHR_bind_memory2": 26, 278 "VK_KHR_maintenance2": 26, 279 "VK_KHR_image_format_list": 26, 280 "VK_KHR_sampler_ycbcr_conversion": 26, 281 # on oreo-mr1-cts-release 282 "VK_KHR_draw_indirect_count": 27, 283 # on pie-cts-release 284 "VK_KHR_device_group": 28, 285 "VK_KHR_multiview": 28, 286 "VK_KHR_maintenance3": 28, 287 "VK_KHR_create_renderpass2": 28, 288 "VK_KHR_driver_properties": 28, 289 # on android10-tests-release 290 "VK_KHR_shader_float_controls": 29, 291 "VK_KHR_shader_float16_int8": 29, 292 "VK_KHR_8bit_storage": 29, 293 "VK_KHR_depth_stencil_resolve": 29, 294 "VK_KHR_swapchain_mutable_format": 29, 295 "VK_KHR_shader_atomic_int64": 29, 296 "VK_KHR_vulkan_memory_model": 29, 297 "VK_KHR_swapchain_mutable_format": 29, 298 "VK_KHR_uniform_buffer_standard_layout": 29, 299 # on android11-tests-release 300 "VK_KHR_imageless_framebuffer": 30, 301 "VK_KHR_shader_subgroup_extended_types": 30, 302 "VK_KHR_buffer_device_address": 30, 303 "VK_KHR_separate_depth_stencil_layouts": 30, 304 "VK_KHR_timeline_semaphore": 30, 305 "VK_KHR_spirv_1_4": 30, 306 "VK_KHR_pipeline_executable_properties": 30, 307 "VK_KHR_shader_clock": 30, 308 # blocked by testVulkanBlockedExtensions 309 # "VK_KHR_performance_query": 30, 310 "VK_KHR_shader_non_semantic_info": 30, 311 "VK_KHR_copy_commands2": 30, 312 # on android12-tests-release 313 "VK_KHR_shader_terminate_invocation": 31, 314 "VK_KHR_ray_tracing_pipeline": 31, 315 "VK_KHR_ray_query": 31, 316 "VK_KHR_acceleration_structure": 31, 317 "VK_KHR_pipeline_library": 31, 318 "VK_KHR_deferred_host_operations": 31, 319 "VK_KHR_fragment_shading_rate": 31, 320 "VK_KHR_zero_initialize_workgroup_memory": 31, 321 "VK_KHR_workgroup_memory_explicit_layout": 31, 322 "VK_KHR_synchronization2": 31, 323 "VK_KHR_shader_integer_dot_product": 31, 324 # on android13-tests-release 325 "VK_KHR_dynamic_rendering": 33, 326 "VK_KHR_format_feature_flags2": 33, 327 "VK_KHR_global_priority": 33, 328 "VK_KHR_maintenance4": 33, 329 "VK_KHR_portability_subset": 33, 330 "VK_KHR_present_id": 33, 331 "VK_KHR_present_wait": 33, 332 "VK_KHR_shader_subgroup_uniform_control_flow": 33, 333 334 # testNoUnknownExtensions on oreo-cts-release 335 "VK_GOOGLE_display_timing": 26, 336 # on pie-cts-release 337 "VK_ANDROID_external_memory_android_hardware_buffer": 28, 338 # on android11-tests-release 339 "VK_GOOGLE_decorate_string": 30, 340 "VK_GOOGLE_hlsl_functionality1": 30, 341 # on android13-tests-release 342 "VK_GOOGLE_surfaceless_query": 33, 343 344 # this HAL extension is always allowed and will be filtered out by the 345 # loader 346 "VK_ANDROID_native_buffer": 26, 347} 348 349# Extensions with these prefixes are checked in Android CTS, and thus must be 350# whitelisted per the preceding dict. 351ANDROID_EXTENSION_WHITELIST_PREFIXES = ( 352 "VK_KHX", 353 "VK_KHR", 354 "VK_GOOGLE", 355 "VK_ANDROID" 356) 357