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