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