| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
|  | 2 | # | 
|  | 3 | # Copyright 2019 The Android Open Source Project | 
|  | 4 | # | 
|  | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 6 | # you may not use this file except in compliance with the License. | 
|  | 7 | # You may obtain a copy of the License at | 
|  | 8 | # | 
|  | 9 | #      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 10 | # | 
|  | 11 | # Unless required by applicable law or agreed to in writing, software | 
|  | 12 | # distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 14 | # See the License for the specific language governing permissions and | 
|  | 15 | # limitations under the License. | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 16 |  | 
|  | 17 | """Provide the utilities for framework generation. | 
|  | 18 | """ | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 19 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 20 | import os | 
|  | 21 | import subprocess | 
|  | 22 | import xml.etree.ElementTree as element_tree | 
| Adithya Srinivasan | 8dce9d7 | 2019-07-11 14:26:04 -0700 | [diff] [blame] | 23 |  | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 24 | # Extensions unsupported on Android. | 
| Yiwei Zhang | 9592422 | 2020-06-15 09:39:03 -0700 | [diff] [blame] | 25 | _BLOCKED_EXTENSIONS = [ | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 26 | 'VK_EXT_acquire_xlib_display', | 
|  | 27 | 'VK_EXT_direct_mode_display', | 
| Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 28 | 'VK_EXT_directfb_surface', | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 29 | 'VK_EXT_display_control', | 
| Yiwei Zhang | dc792f5 | 2019-10-10 16:29:42 -0700 | [diff] [blame] | 30 | 'VK_EXT_display_surface_counter', | 
|  | 31 | 'VK_EXT_full_screen_exclusive', | 
|  | 32 | 'VK_EXT_headless_surface', | 
|  | 33 | 'VK_EXT_metal_surface', | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 34 | 'VK_FUCHSIA_imagepipe_surface', | 
| Yiwei Zhang | dc792f5 | 2019-10-10 16:29:42 -0700 | [diff] [blame] | 35 | 'VK_GGP_stream_descriptor_surface', | 
|  | 36 | 'VK_KHR_display', | 
|  | 37 | 'VK_KHR_display_swapchain', | 
|  | 38 | 'VK_KHR_external_fence_win32', | 
|  | 39 | 'VK_KHR_external_memory_win32', | 
|  | 40 | 'VK_KHR_external_semaphore_win32', | 
|  | 41 | 'VK_KHR_mir_surface', | 
|  | 42 | 'VK_KHR_wayland_surface', | 
|  | 43 | 'VK_KHR_win32_keyed_mutex', | 
|  | 44 | 'VK_KHR_win32_surface', | 
|  | 45 | 'VK_KHR_xcb_surface', | 
|  | 46 | 'VK_KHR_xlib_surface', | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 47 | 'VK_MVK_ios_surface', | 
|  | 48 | 'VK_MVK_macos_surface', | 
|  | 49 | 'VK_NN_vi_surface', | 
| Yiwei Zhang | dc792f5 | 2019-10-10 16:29:42 -0700 | [diff] [blame] | 50 | 'VK_NV_cooperative_matrix', | 
|  | 51 | 'VK_NV_coverage_reduction_mode', | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 52 | 'VK_NV_external_memory_win32', | 
|  | 53 | 'VK_NV_win32_keyed_mutex', | 
| Yiwei Zhang | dc792f5 | 2019-10-10 16:29:42 -0700 | [diff] [blame] | 54 | 'VK_NVX_image_view_handle', | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 55 | ] | 
|  | 56 |  | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 57 | # Extensions having functions exported by the loader. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 58 | _EXPORTED_EXTENSIONS = [ | 
| Yiwei Zhang | dc792f5 | 2019-10-10 16:29:42 -0700 | [diff] [blame] | 59 | 'VK_ANDROID_external_memory_android_hardware_buffer', | 
|  | 60 | 'VK_KHR_android_surface', | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 61 | 'VK_KHR_surface', | 
|  | 62 | 'VK_KHR_swapchain', | 
| Yiwei Zhang | dc792f5 | 2019-10-10 16:29:42 -0700 | [diff] [blame] | 63 | ] | 
|  | 64 |  | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 65 | # Functions optional on Android even if extension is advertised. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 66 | _OPTIONAL_COMMANDS = [ | 
| Yiwei Zhang | dc792f5 | 2019-10-10 16:29:42 -0700 | [diff] [blame] | 67 | 'vkGetSwapchainGrallocUsageANDROID', | 
|  | 68 | 'vkGetSwapchainGrallocUsage2ANDROID', | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 69 | ] | 
|  | 70 |  | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 71 | # Dict for mapping dispatch table to a type. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 72 | _DISPATCH_TYPE_DICT = { | 
|  | 73 | 'VkInstance ': 'Instance', | 
|  | 74 | 'VkPhysicalDevice ': 'Instance', | 
|  | 75 | 'VkDevice ': 'Device', | 
|  | 76 | 'VkQueue ': 'Device', | 
|  | 77 | 'VkCommandBuffer ': 'Device' | 
|  | 78 | } | 
| Adithya Srinivasan | 8dce9d7 | 2019-07-11 14:26:04 -0700 | [diff] [blame] | 79 |  | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 80 | # Dict for mapping a function to its alias. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 81 | alias_dict = {} | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 82 |  | 
|  | 83 | # List of all the Vulkan functions. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 84 | command_list = [] | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 85 |  | 
|  | 86 | # Dict for mapping a function to an extension. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 87 | extension_dict = {} | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 88 |  | 
|  | 89 | # Dict for mapping a function to all its parameters. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 90 | param_dict = {} | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 91 |  | 
|  | 92 | # Dict for mapping a function to its return type. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 93 | return_type_dict = {} | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 94 |  | 
| Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 95 | # List of the sorted Vulkan version codes. e.g. '1_0', '1_1'. | 
|  | 96 | version_code_list = [] | 
|  | 97 |  | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 98 | # Dict for mapping a function to the core Vulkan API version. | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 99 | version_dict = {} | 
| Adithya Srinivasan | 0136414 | 2019-07-02 15:52:49 -0700 | [diff] [blame] | 100 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 101 |  | 
|  | 102 | def indent(num): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 103 | """Returns the requested indents. | 
|  | 104 |  | 
|  | 105 | Args: | 
|  | 106 | num: Number of the 4-space indents. | 
|  | 107 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 108 | return '    ' * num | 
|  | 109 |  | 
|  | 110 |  | 
|  | 111 | def copyright_and_warning(year): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 112 | """Returns the standard copyright and warning codes. | 
|  | 113 |  | 
|  | 114 | Args: | 
|  | 115 | year: An integer year for the copyright. | 
|  | 116 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 117 | return """\ | 
|  | 118 | /* | 
|  | 119 | * Copyright """ + str(year) + """ The Android Open Source Project | 
|  | 120 | * | 
|  | 121 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 122 | * you may not use this file except in compliance with the License. | 
|  | 123 | * You may obtain a copy of the License at | 
|  | 124 | * | 
|  | 125 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 126 | * | 
|  | 127 | * Unless required by applicable law or agreed to in writing, software | 
|  | 128 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 129 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 130 | * See the License for the specific language governing permissions and | 
|  | 131 | * limitations under the License. | 
|  | 132 | */ | 
|  | 133 |  | 
|  | 134 | // WARNING: This file is generated. See ../README.md for instructions. | 
|  | 135 |  | 
|  | 136 | """ | 
|  | 137 |  | 
|  | 138 |  | 
|  | 139 | def run_clang_format(args): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 140 | """Run clang format on the file. | 
|  | 141 |  | 
|  | 142 | Args: | 
|  | 143 | args: The file to be formatted. | 
|  | 144 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 145 | clang_call = ['clang-format', '--style', 'file', '-i', args] | 
|  | 146 | subprocess.check_call(clang_call) | 
|  | 147 |  | 
|  | 148 |  | 
| Yiwei Zhang | 5365a7b | 2019-10-11 17:26:44 -0700 | [diff] [blame] | 149 | def is_extension_internal(ext): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 150 | """Returns true if an extension is internal to the loader and drivers. | 
|  | 151 |  | 
|  | 152 | The loader should not enumerate this extension. | 
|  | 153 |  | 
|  | 154 | Args: | 
| Yiwei Zhang | 5365a7b | 2019-10-11 17:26:44 -0700 | [diff] [blame] | 155 | ext: Vulkan extension name. | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 156 | """ | 
| Yiwei Zhang | 5365a7b | 2019-10-11 17:26:44 -0700 | [diff] [blame] | 157 | return ext == 'VK_ANDROID_native_buffer' | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 158 |  | 
|  | 159 |  | 
|  | 160 | def base_name(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 161 | """Returns a function name without the 'vk' prefix. | 
|  | 162 |  | 
|  | 163 | Args: | 
|  | 164 | cmd: Vulkan function name. | 
|  | 165 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 166 | return cmd[2:] | 
|  | 167 |  | 
|  | 168 |  | 
| Yiwei Zhang | 5365a7b | 2019-10-11 17:26:44 -0700 | [diff] [blame] | 169 | def base_ext_name(ext): | 
|  | 170 | """Returns an extension name without the 'VK_' prefix. | 
|  | 171 |  | 
|  | 172 | Args: | 
|  | 173 | ext: Vulkan extension name. | 
|  | 174 | """ | 
|  | 175 | return ext[3:] | 
|  | 176 |  | 
|  | 177 |  | 
| Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 178 | def version_code(version): | 
|  | 179 | """Returns the version code from a version string. | 
|  | 180 |  | 
|  | 181 | Args: | 
|  | 182 | version: Vulkan version string. | 
|  | 183 | """ | 
|  | 184 | return version[11:] | 
|  | 185 |  | 
|  | 186 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 187 | def is_function_supported(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 188 | """Returns true if a function is core or from a supportable extension. | 
|  | 189 |  | 
|  | 190 | Args: | 
|  | 191 | cmd: Vulkan function name. | 
|  | 192 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 193 | if cmd not in extension_dict: | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 194 | return True | 
|  | 195 | else: | 
| Yiwei Zhang | 9592422 | 2020-06-15 09:39:03 -0700 | [diff] [blame] | 196 | if extension_dict[cmd] not in _BLOCKED_EXTENSIONS: | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 197 | return True | 
|  | 198 | return False | 
|  | 199 |  | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 200 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 201 | def get_dispatch_table_type(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 202 | """Returns the dispatch table type for a function. | 
|  | 203 |  | 
|  | 204 | Args: | 
|  | 205 | cmd: Vulkan function name. | 
|  | 206 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 207 | if cmd not in param_dict: | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 208 | return None | 
|  | 209 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 210 | if param_dict[cmd]: | 
|  | 211 | return _DISPATCH_TYPE_DICT.get(param_dict[cmd][0][0], 'Global') | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 212 | return 'Global' | 
|  | 213 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 214 |  | 
|  | 215 | def is_globally_dispatched(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 216 | """Returns true if the function is global, which is not dispatched. | 
|  | 217 |  | 
|  | 218 | Only global functions and functions handled in the loader top without calling | 
|  | 219 | into lower layers are not dispatched. | 
|  | 220 |  | 
|  | 221 | Args: | 
|  | 222 | cmd: Vulkan function name. | 
|  | 223 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 224 | return is_function_supported(cmd) and get_dispatch_table_type(cmd) == 'Global' | 
|  | 225 |  | 
|  | 226 |  | 
|  | 227 | def is_instance_dispatched(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 228 | """Returns true for functions that can have instance-specific dispatch. | 
|  | 229 |  | 
|  | 230 | Args: | 
|  | 231 | cmd: Vulkan function name. | 
|  | 232 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 233 | return (is_function_supported(cmd) and | 
|  | 234 | get_dispatch_table_type(cmd) == 'Instance') | 
|  | 235 |  | 
|  | 236 |  | 
|  | 237 | def is_device_dispatched(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 238 | """Returns true for functions that can have device-specific dispatch. | 
|  | 239 |  | 
|  | 240 | Args: | 
|  | 241 | cmd: Vulkan function name. | 
|  | 242 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 243 | return is_function_supported(cmd) and get_dispatch_table_type(cmd) == 'Device' | 
|  | 244 |  | 
|  | 245 |  | 
| Yiwei Zhang | 5365a7b | 2019-10-11 17:26:44 -0700 | [diff] [blame] | 246 | def is_extension_exported(ext): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 247 | """Returns true if an extension has functions exported by the loader. | 
|  | 248 |  | 
|  | 249 | E.g. applications can directly link to an extension function. | 
|  | 250 |  | 
|  | 251 | Args: | 
| Yiwei Zhang | 5365a7b | 2019-10-11 17:26:44 -0700 | [diff] [blame] | 252 | ext: Vulkan extension name. | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 253 | """ | 
| Yiwei Zhang | 5365a7b | 2019-10-11 17:26:44 -0700 | [diff] [blame] | 254 | return ext in _EXPORTED_EXTENSIONS | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 255 |  | 
|  | 256 |  | 
|  | 257 | def is_function_exported(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 258 | """Returns true if a function is exported from the Android Vulkan library. | 
|  | 259 |  | 
|  | 260 | Functions in the core API and in loader extensions are exported. | 
|  | 261 |  | 
|  | 262 | Args: | 
|  | 263 | cmd: Vulkan function name. | 
|  | 264 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 265 | if is_function_supported(cmd): | 
|  | 266 | if cmd in extension_dict: | 
|  | 267 | return is_extension_exported(extension_dict[cmd]) | 
|  | 268 | return True | 
|  | 269 | return False | 
|  | 270 |  | 
|  | 271 |  | 
|  | 272 | def is_instance_dispatch_table_entry(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 273 | """Returns true if a function is exported and instance-dispatched. | 
|  | 274 |  | 
|  | 275 | Args: | 
|  | 276 | cmd: Vulkan function name. | 
|  | 277 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 278 | if cmd == 'vkEnumerateDeviceLayerProperties': | 
|  | 279 | # deprecated, unused internally - @dbd33bc | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 280 | return False | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 281 | return is_function_exported(cmd) and is_instance_dispatched(cmd) | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 282 |  | 
|  | 283 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 284 | def is_device_dispatch_table_entry(cmd): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 285 | """Returns true if a function is exported and device-dispatched. | 
|  | 286 |  | 
|  | 287 | Args: | 
|  | 288 | cmd: Vulkan function name. | 
|  | 289 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 290 | return is_function_exported(cmd) and is_device_dispatched(cmd) | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 291 |  | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 292 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 293 | def init_proc(name, f): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 294 | """Emits code to invoke INIT_PROC or INIT_PROC_EXT. | 
|  | 295 |  | 
|  | 296 | Args: | 
|  | 297 | name: Vulkan function name. | 
|  | 298 | f: Output file handle. | 
|  | 299 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 300 | f.write(indent(1)) | 
|  | 301 | if name in extension_dict: | 
| Yiwei Zhang | aeaa867 | 2019-10-16 18:59:41 -0700 | [diff] [blame] | 302 | f.write('INIT_PROC_EXT(' + base_ext_name(extension_dict[name]) + ', ') | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 303 | else: | 
|  | 304 | f.write('INIT_PROC(') | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 305 |  | 
| Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 306 | if name in _OPTIONAL_COMMANDS: | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 307 | f.write('false, ') | 
| Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 308 | elif version_dict[name] == 'VK_VERSION_1_0': | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 309 | f.write('true, ') | 
| Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 310 | else: | 
|  | 311 | f.write('false, ') | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 312 |  | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 313 | if is_instance_dispatched(name): | 
|  | 314 | f.write('instance, ') | 
|  | 315 | else: | 
|  | 316 | f.write('dev, ') | 
|  | 317 |  | 
|  | 318 | f.write(base_name(name) + ');\n') | 
|  | 319 |  | 
|  | 320 |  | 
|  | 321 | def parse_vulkan_registry(): | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 322 | """Parses Vulkan registry into the below global variables. | 
|  | 323 |  | 
|  | 324 | alias_dict | 
|  | 325 | command_list | 
|  | 326 | extension_dict | 
|  | 327 | param_dict | 
|  | 328 | return_type_dict | 
| Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 329 | version_code_list | 
| Yiwei Zhang | 6ca5d0c | 2019-10-11 17:15:02 -0700 | [diff] [blame] | 330 | version_dict | 
|  | 331 | """ | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 332 | registry = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', | 
|  | 333 | 'external', 'vulkan-headers', 'registry', 'vk.xml') | 
|  | 334 | tree = element_tree.parse(registry) | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 335 | root = tree.getroot() | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 336 | for commands in root.iter('commands'): | 
|  | 337 | for command in commands: | 
|  | 338 | if command.tag == 'command': | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 339 | parameter_list = [] | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 340 | protoset = False | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 341 | cmd_name = '' | 
|  | 342 | cmd_type = '' | 
|  | 343 | if command.get('alias') is not None: | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 344 | alias = command.get('alias') | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 345 | cmd_name = command.get('name') | 
|  | 346 | alias_dict[cmd_name] = alias | 
|  | 347 | command_list.append(cmd_name) | 
|  | 348 | param_dict[cmd_name] = param_dict[alias].copy() | 
|  | 349 | return_type_dict[cmd_name] = return_type_dict[alias] | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 350 | for params in command: | 
| Yiwei Zhang | 4bc489b | 2019-09-23 15:17:22 -0700 | [diff] [blame] | 351 | if params.tag == 'param': | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 352 | param_type = '' | 
|  | 353 | if params.text is not None and params.text.strip(): | 
|  | 354 | param_type = params.text.strip() + ' ' | 
|  | 355 | type_val = params.find('type') | 
|  | 356 | param_type = param_type + type_val.text | 
|  | 357 | if type_val.tail is not None: | 
|  | 358 | param_type += type_val.tail.strip() + ' ' | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 359 | pname = params.find('name') | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 360 | param_name = pname.text | 
|  | 361 | if pname.tail is not None and pname.tail.strip(): | 
|  | 362 | parameter_list.append( | 
|  | 363 | (param_type, param_name, pname.tail.strip())) | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 364 | else: | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 365 | parameter_list.append((param_type, param_name)) | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 366 | if params.tag == 'proto': | 
|  | 367 | for c in params: | 
|  | 368 | if c.tag == 'type': | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 369 | cmd_type = c.text | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 370 | if c.tag == 'name': | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 371 | cmd_name = c.text | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 372 | protoset = True | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 373 | command_list.append(cmd_name) | 
|  | 374 | return_type_dict[cmd_name] = cmd_type | 
|  | 375 | if protoset: | 
|  | 376 | param_dict[cmd_name] = parameter_list.copy() | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 377 |  | 
|  | 378 | for exts in root.iter('extensions'): | 
|  | 379 | for extension in exts: | 
| Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 380 | apiversion = 'VK_VERSION_1_0' | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 381 | if extension.tag == 'extension': | 
|  | 382 | extname = extension.get('name') | 
|  | 383 | for req in extension: | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 384 | if req.get('feature') is not None: | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 385 | apiversion = req.get('feature') | 
|  | 386 | for commands in req: | 
|  | 387 | if commands.tag == 'command': | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 388 | cmd_name = commands.get('name') | 
|  | 389 | if cmd_name not in extension_dict: | 
|  | 390 | extension_dict[cmd_name] = extname | 
| Yiwei Zhang | 6be097b | 2020-10-19 20:22:05 -0700 | [diff] [blame] | 391 | version_dict[cmd_name] = apiversion | 
| Adithya Srinivasan | 751a7dc | 2019-07-02 17:17:25 -0700 | [diff] [blame] | 392 |  | 
|  | 393 | for feature in root.iter('feature'): | 
|  | 394 | apiversion = feature.get('name') | 
|  | 395 | for req in feature: | 
|  | 396 | for command in req: | 
|  | 397 | if command.tag == 'command': | 
| Yiwei Zhang | 1ca59c1 | 2019-10-10 12:54:42 -0700 | [diff] [blame] | 398 | cmd_name = command.get('name') | 
|  | 399 | if cmd_name in command_list: | 
|  | 400 | version_dict[cmd_name] = apiversion | 
| Yiwei Zhang | 7cc36a5 | 2019-10-11 19:02:09 -0700 | [diff] [blame] | 401 |  | 
|  | 402 | version_code_set = set() | 
|  | 403 | for version in version_dict.values(): | 
|  | 404 | version_code_set.add(version_code(version)) | 
|  | 405 | for code in sorted(version_code_set): | 
|  | 406 | version_code_list.append(code) |