| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 1 | #!/usr/bin/python3 -i |
| 2 | # |
| Shannon McPherson | ff80a93 | 2019-03-06 12:11:20 -0700 | [diff] [blame] | 3 | # Copyright (c) 2015-2017, 2019 The Khronos Group Inc. |
| 4 | # Copyright (c) 2015-2017, 2019 Valve Corporation |
| 5 | # Copyright (c) 2015-2017, 2019 LunarG, Inc. |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # |
| 19 | # Author: Mark Lobodzinski <mark@lunarg.com> |
| 20 | |
| 21 | import os,re,sys,string |
| 22 | import xml.etree.ElementTree as etree |
| Mike Schuchardt | 09a1c75 | 2019-06-20 12:04:38 -0700 | [diff] [blame] | 23 | from collections import namedtuple, OrderedDict |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 24 | |
| 25 | # Copyright text prefixing all headers (list of strings). |
| 26 | prefixStrings = [ |
| 27 | '/*', |
| Shannon McPherson | ff80a93 | 2019-03-06 12:11:20 -0700 | [diff] [blame] | 28 | '** Copyright (c) 2015-2017, 2019 The Khronos Group Inc.', |
| 29 | '** Copyright (c) 2015-2017, 2019 Valve Corporation', |
| 30 | '** Copyright (c) 2015-2017, 2019 LunarG, Inc.', |
| 31 | '** Copyright (c) 2015-2017, 2019 Google Inc.', |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 32 | '**', |
| 33 | '** Licensed under the Apache License, Version 2.0 (the "License");', |
| 34 | '** you may not use this file except in compliance with the License.', |
| 35 | '** You may obtain a copy of the License at', |
| 36 | '**', |
| 37 | '** http://www.apache.org/licenses/LICENSE-2.0', |
| 38 | '**', |
| 39 | '** Unless required by applicable law or agreed to in writing, software', |
| 40 | '** distributed under the License is distributed on an "AS IS" BASIS,', |
| 41 | '** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.', |
| 42 | '** See the License for the specific language governing permissions and', |
| 43 | '** limitations under the License.', |
| 44 | '*/', |
| 45 | '' |
| 46 | ] |
| 47 | |
| 48 | |
| 49 | platform_dict = { |
| 50 | 'android' : 'VK_USE_PLATFORM_ANDROID_KHR', |
| Shannon McPherson | ceacc24 | 2018-10-08 13:46:55 -0600 | [diff] [blame] | 51 | 'fuchsia' : 'VK_USE_PLATFORM_FUCHSIA', |
| Mike Schuchardt | 21638df | 2019-03-16 10:52:02 -0700 | [diff] [blame] | 52 | 'ggp': 'VK_USE_PLATFORM_GGP', |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 53 | 'ios' : 'VK_USE_PLATFORM_IOS_MVK', |
| 54 | 'macos' : 'VK_USE_PLATFORM_MACOS_MVK', |
| Shannon McPherson | ff80a93 | 2019-03-06 12:11:20 -0700 | [diff] [blame] | 55 | 'metal' : 'VK_USE_PLATFORM_METAL_EXT', |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 56 | 'vi' : 'VK_USE_PLATFORM_VI_NN', |
| 57 | 'wayland' : 'VK_USE_PLATFORM_WAYLAND_KHR', |
| 58 | 'win32' : 'VK_USE_PLATFORM_WIN32_KHR', |
| 59 | 'xcb' : 'VK_USE_PLATFORM_XCB_KHR', |
| 60 | 'xlib' : 'VK_USE_PLATFORM_XLIB_KHR', |
| Mike Schuchardt | 72b7930 | 2018-02-07 14:47:01 -0700 | [diff] [blame] | 61 | 'xlib_xrandr' : 'VK_USE_PLATFORM_XLIB_XRANDR_EXT', |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | # |
| 65 | # Return appropriate feature protect string from 'platform' tag on feature |
| 66 | def GetFeatureProtect(interface): |
| 67 | """Get platform protection string""" |
| 68 | platform = interface.get('platform') |
| 69 | protect = None |
| 70 | if platform is not None: |
| 71 | protect = platform_dict[platform] |
| 72 | return protect |
| John Zulauf | 2c2ccd4 | 2019-04-05 13:13:13 -0600 | [diff] [blame] | 73 | |
| Mike Schuchardt | 09a1c75 | 2019-06-20 12:04:38 -0700 | [diff] [blame] | 74 | # Return a dict containing the dispatchable/non-dispatchable type of every handle |
| 75 | def GetHandleTypes(tree): |
| Mike Schuchardt | f869026 | 2019-07-11 10:08:33 -0700 | [diff] [blame] | 76 | # Extend OrderedDict with common handle operations |
| 77 | class HandleDict(OrderedDict): |
| 78 | def IsDispatchable(self, handle_type): |
| 79 | return self.get(handle_type) == 'VK_DEFINE_HANDLE' |
| 80 | def IsNonDispatchable(self, handle_type): |
| 81 | return self.get(handle_type) == 'VK_DEFINE_NON_DISPATCHABLE_HANDLE' |
| 82 | |
| 83 | handles = HandleDict() |
| Mike Schuchardt | 09a1c75 | 2019-06-20 12:04:38 -0700 | [diff] [blame] | 84 | for elem in tree.findall("types/type/[@category='handle']"): |
| 85 | if not elem.get('alias'): |
| 86 | name = elem.get('name') |
| 87 | handles[name] = elem.find('type').text |
| 88 | return handles |
| 89 | |
| 90 | # Return a dict containing the category attribute of every type |
| 91 | def GetTypeCategories(tree): |
| 92 | type_categories = OrderedDict() |
| 93 | for elem in tree.findall("types/type"): |
| 94 | if not elem.get('alias'): |
| 95 | # name is either an attribute or the text of a child <name> tag |
| 96 | name = elem.get('name') or (elem.find("name") and elem.find('name').text) |
| 97 | type_categories[name] = elem.get('category') |
| 98 | return type_categories |
| John Zulauf | 2c2ccd4 | 2019-04-05 13:13:13 -0600 | [diff] [blame] | 99 | |
| 100 | # Treats outdents a multiline string by the leading whitespace on the first line |
| 101 | # Optionally indenting by the given prefix |
| 102 | def Outdent(string_in, indent=''): |
| 103 | string_out = re.sub('^ *', '', string_in) # kill stray leading spaces |
| 104 | if string_out[0] != '\n': |
| 105 | return string_in # needs new line to find the first line's indent level |
| 106 | |
| 107 | first_indent = string_out[1:] |
| 108 | fake_indent = '\n' + ' ' * (len(first_indent) - len(first_indent.lstrip())) |
| 109 | indent = '\n' + indent |
| 110 | |
| 111 | string_out = string_out.rstrip() + '\n' # remove trailing whitespace except for a newline |
| 112 | outdent = re.sub(fake_indent, indent, string_out) |
| 113 | return outdent[1:] |
| 114 | |
| Mike Schuchardt | e51c74b | 2019-07-10 17:01:21 -0700 | [diff] [blame] | 115 | |
| 116 | # helper to define paths relative to the repo root |
| 117 | def repo_relative(path): |
| 118 | return os.path.abspath(os.path.join(os.path.dirname(__file__), '..', path)) |
| 119 | |