1COPYRIGHT = """\ 2/* 3 * Copyright 2017 Intel Corporation 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sub license, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial portions 15 * of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25""" 26 27import copy 28import re 29 30def _bool_to_c_expr(b): 31 if b is True: 32 return 'true' 33 if b is False: 34 return 'false' 35 return b 36 37class Extension: 38 def __init__(self, name, ext_version, enable): 39 self.name = name 40 self.ext_version = int(ext_version) 41 self.enable = _bool_to_c_expr(enable) 42 43class ApiVersion: 44 def __init__(self, version, enable): 45 self.version = version 46 self.enable = _bool_to_c_expr(enable) 47 48API_PATCH_VERSION = 155 49 50# Supported API versions. Each one is the maximum patch version for the given 51# version. Version come in increasing order and each version is available if 52# it's provided "enable" condition is true and all previous versions are 53# available. 54API_VERSIONS = [ 55 ApiVersion('1.0', True), 56 ApiVersion('1.1', False), 57] 58 59MAX_API_VERSION = None # Computed later 60 61EXTENSIONS = [ 62 Extension('VK_KHR_display', 23, 'VK_USE_PLATFORM_DISPLAY_KHR'), 63 Extension('VK_KHR_external_memory', 1, True), 64 Extension('VK_KHR_external_memory_capabilities', 1, True), 65 Extension('VK_KHR_external_memory_fd', 1, True), 66 Extension('VK_KHR_get_physical_device_properties2', 1, True), 67 Extension('VK_KHR_get_surface_capabilities2', 1, 'V3DV_HAS_SURFACE'), 68 Extension('VK_KHR_maintenance1', 2, True), 69 Extension('VK_KHR_surface', 25, 'V3DV_HAS_SURFACE'), 70 Extension('VK_KHR_swapchain', 68, 'V3DV_HAS_SURFACE'), 71 Extension('VK_KHR_wayland_surface', 6, 'VK_USE_PLATFORM_WAYLAND_KHR'), 72 Extension('VK_KHR_xcb_surface', 6, 'VK_USE_PLATFORM_XCB_KHR'), 73 Extension('VK_KHR_xlib_surface', 6, 'VK_USE_PLATFORM_XLIB_KHR'), 74 Extension('VK_EXT_debug_report', 9, True), 75 Extension('VK_EXT_external_memory_dma_buf', 1, True), 76 Extension('VK_EXT_image_drm_format_modifier', 1, False), 77] 78 79# Sort the extension list the way we expect: KHR, then EXT, then vendors 80# alphabetically. For digits, read them as a whole number sort that. 81# eg.: VK_KHR_8bit_storage < VK_KHR_16bit_storage < VK_EXT_acquire_xlib_display 82def extension_order(ext): 83 order = [] 84 for substring in re.split('(KHR|EXT|[0-9]+)', ext.name): 85 if substring == 'KHR': 86 order.append(1) 87 if substring == 'EXT': 88 order.append(2) 89 elif substring.isdigit(): 90 order.append(int(substring)) 91 else: 92 order.append(substring) 93 return order 94for i in range(len(EXTENSIONS) - 1): 95 if extension_order(EXTENSIONS[i + 1]) < extension_order(EXTENSIONS[i]): 96 print(EXTENSIONS[i + 1].name + ' should come before ' + EXTENSIONS[i].name) 97 exit(1) 98 99class VkVersion: 100 def __init__(self, string): 101 split = string.split('.') 102 self.major = int(split[0]) 103 self.minor = int(split[1]) 104 if len(split) > 2: 105 assert len(split) == 3 106 self.patch = int(split[2]) 107 else: 108 self.patch = None 109 110 # Sanity check. The range bits are required by the definition of the 111 # VK_MAKE_VERSION macro 112 assert self.major < 1024 and self.minor < 1024 113 assert self.patch is None or self.patch < 4096 114 assert str(self) == string 115 116 def __str__(self): 117 ver_list = [str(self.major), str(self.minor)] 118 if self.patch is not None: 119 ver_list.append(str(self.patch)) 120 return '.'.join(ver_list) 121 122 def c_vk_version(self): 123 patch = self.patch if self.patch is not None else 0 124 ver_list = [str(self.major), str(self.minor), str(patch)] 125 return 'VK_MAKE_VERSION(' + ', '.join(ver_list) + ')' 126 127 def __int_ver(self): 128 # This is just an expansion of VK_VERSION 129 patch = self.patch if self.patch is not None else 0 130 return (self.major << 22) | (self.minor << 12) | patch 131 132 def __gt__(self, other): 133 # If only one of them has a patch version, "ignore" it by making 134 # other's patch version match self. 135 if (self.patch is None) != (other.patch is None): 136 other = copy.copy(other) 137 other.patch = self.patch 138 139 return self.__int_ver() > other.__int_ver() 140 141 142 143MAX_API_VERSION = VkVersion('0.0.0') 144for version in API_VERSIONS: 145 version.version = VkVersion(version.version) 146 version.version.patch = API_PATCH_VERSION 147 assert version.version > MAX_API_VERSION 148 MAX_API_VERSION = version.version 149