Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/vulkan/util/vk_extensions.py
7136 views
1
import argparse
2
import copy
3
import re
4
import xml.etree.ElementTree as et
5
6
def _bool_to_c_expr(b):
7
if b is True:
8
return 'true'
9
if b is False:
10
return 'false'
11
return b
12
13
class Extension:
14
def __init__(self, name, ext_version, enable):
15
self.name = name
16
self.ext_version = int(ext_version)
17
self.enable = _bool_to_c_expr(enable)
18
19
def c_android_condition(self):
20
# if it's an EXT or vendor extension, it's allowed
21
if not self.name.startswith(ANDROID_EXTENSION_WHITELIST_PREFIXES):
22
return 'true'
23
24
allowed_version = ALLOWED_ANDROID_VERSION.get(self.name, None)
25
if allowed_version is None:
26
return 'false'
27
28
return 'ANDROID_API_LEVEL >= %d' % (allowed_version)
29
30
class ApiVersion:
31
def __init__(self, version, enable):
32
self.version = version
33
self.enable = _bool_to_c_expr(enable)
34
35
class VkVersion:
36
def __init__(self, string):
37
split = string.split('.')
38
self.major = int(split[0])
39
self.minor = int(split[1])
40
if len(split) > 2:
41
assert len(split) == 3
42
self.patch = int(split[2])
43
else:
44
self.patch = None
45
46
# Sanity check. The range bits are required by the definition of the
47
# VK_MAKE_VERSION macro
48
assert self.major < 1024 and self.minor < 1024
49
assert self.patch is None or self.patch < 4096
50
assert(str(self) == string)
51
52
def __str__(self):
53
ver_list = [str(self.major), str(self.minor)]
54
if self.patch is not None:
55
ver_list.append(str(self.patch))
56
return '.'.join(ver_list)
57
58
def c_vk_version(self):
59
patch = self.patch if self.patch is not None else 0
60
ver_list = [str(self.major), str(self.minor), str(patch)]
61
return 'VK_MAKE_VERSION(' + ', '.join(ver_list) + ')'
62
63
def __int_ver(self):
64
# This is just an expansion of VK_VERSION
65
patch = self.patch if self.patch is not None else 0
66
return (self.major << 22) | (self.minor << 12) | patch
67
68
def __gt__(self, other):
69
# If only one of them has a patch version, "ignore" it by making
70
# other's patch version match self.
71
if (self.patch is None) != (other.patch is None):
72
other = copy.copy(other)
73
other.patch = self.patch
74
75
return self.__int_ver() > other.__int_ver()
76
77
# Sort the extension list the way we expect: KHR, then EXT, then vendors
78
# alphabetically. For digits, read them as a whole number sort that.
79
# eg.: VK_KHR_8bit_storage < VK_KHR_16bit_storage < VK_EXT_acquire_xlib_display
80
def extension_order(ext):
81
order = []
82
for substring in re.split('(KHR|EXT|[0-9]+)', ext.name):
83
if substring == 'KHR':
84
order.append(1)
85
if substring == 'EXT':
86
order.append(2)
87
elif substring.isdigit():
88
order.append(int(substring))
89
else:
90
order.append(substring)
91
return order
92
93
def get_all_exts_from_xml(xml):
94
""" Get a list of all Vulkan extensions. """
95
96
xml = et.parse(xml)
97
98
extensions = []
99
for ext_elem in xml.findall('.extensions/extension'):
100
supported = ext_elem.attrib['supported'] == 'vulkan'
101
name = ext_elem.attrib['name']
102
if not supported and name != 'VK_ANDROID_native_buffer':
103
continue
104
version = None
105
for enum_elem in ext_elem.findall('.require/enum'):
106
if enum_elem.attrib['name'].endswith('_SPEC_VERSION'):
107
assert version is None
108
version = int(enum_elem.attrib['value'])
109
ext = Extension(name, version, True)
110
extensions.append(Extension(name, version, True))
111
112
return sorted(extensions, key=extension_order)
113
114
def init_exts_from_xml(xml, extensions, platform_defines):
115
""" Walk the Vulkan XML and fill out extra extension information. """
116
117
xml = et.parse(xml)
118
119
ext_name_map = {}
120
for ext in extensions:
121
ext_name_map[ext.name] = ext
122
123
# KHR_display is missing from the list.
124
platform_defines.append('VK_USE_PLATFORM_DISPLAY_KHR')
125
for platform in xml.findall('./platforms/platform'):
126
platform_defines.append(platform.attrib['protect'])
127
128
for ext_elem in xml.findall('.extensions/extension'):
129
ext_name = ext_elem.attrib['name']
130
if ext_name not in ext_name_map:
131
continue
132
133
ext = ext_name_map[ext_name]
134
ext.type = ext_elem.attrib['type']
135
136
# Mapping between extension name and the android version in which the extension
137
# was whitelisted in Android CTS.
138
ALLOWED_ANDROID_VERSION = {
139
# Allowed Instance KHR Extensions
140
"VK_KHR_surface": 26,
141
"VK_KHR_display": 26,
142
"VK_KHR_android_surface": 26,
143
"VK_KHR_mir_surface": 26,
144
"VK_KHR_wayland_surface": 26,
145
"VK_KHR_win32_surface": 26,
146
"VK_KHR_xcb_surface": 26,
147
"VK_KHR_xlib_surface": 26,
148
"VK_KHR_get_physical_device_properties2": 26,
149
"VK_KHR_get_surface_capabilities2": 26,
150
"VK_KHR_external_memory_capabilities": 28,
151
"VK_KHR_external_semaphore_capabilities": 28,
152
"VK_KHR_external_fence_capabilities": 28,
153
"VK_KHR_device_group_creation": 28,
154
"VK_KHR_get_display_properties2": 29,
155
"VK_KHR_surface_protected_capabilities": 29,
156
157
# Allowed Device KHR Extensions
158
"VK_KHR_swapchain": 26,
159
"VK_KHR_display_swapchain": 26,
160
"VK_KHR_sampler_mirror_clamp_to_edge": 26,
161
"VK_KHR_shader_draw_parameters": 26,
162
"VK_KHR_shader_float_controls": 29,
163
"VK_KHR_shader_float16_int8": 29,
164
"VK_KHR_maintenance1": 26,
165
"VK_KHR_push_descriptor": 26,
166
"VK_KHR_descriptor_update_template": 26,
167
"VK_KHR_incremental_present": 26,
168
"VK_KHR_shared_presentable_image": 26,
169
"VK_KHR_storage_buffer_storage_class": 28,
170
"VK_KHR_8bit_storage": 29,
171
"VK_KHR_16bit_storage": 28,
172
"VK_KHR_get_memory_requirements2": 28,
173
"VK_KHR_external_memory": 28,
174
"VK_KHR_external_memory_fd": 28,
175
"VK_KHR_external_memory_win32": 28,
176
"VK_KHR_external_semaphore": 28,
177
"VK_KHR_external_semaphore_fd": 28,
178
"VK_KHR_external_semaphore_win32": 28,
179
"VK_KHR_external_fence": 28,
180
"VK_KHR_external_fence_fd": 28,
181
"VK_KHR_external_fence_win32": 28,
182
"VK_KHR_win32_keyed_mutex": 28,
183
"VK_KHR_dedicated_allocation": 28,
184
"VK_KHR_variable_pointers": 28,
185
"VK_KHR_relaxed_block_layout": 28,
186
"VK_KHR_bind_memory2": 28,
187
"VK_KHR_maintenance2": 28,
188
"VK_KHR_image_format_list": 28,
189
"VK_KHR_sampler_ycbcr_conversion": 28,
190
"VK_KHR_device_group": 28,
191
"VK_KHR_multiview": 28,
192
"VK_KHR_maintenance3": 28,
193
"VK_KHR_draw_indirect_count": 28,
194
"VK_KHR_create_renderpass2": 28,
195
"VK_KHR_depth_stencil_resolve": 29,
196
"VK_KHR_driver_properties": 28,
197
"VK_KHR_swapchain_mutable_format": 29,
198
"VK_KHR_shader_atomic_int64": 29,
199
"VK_KHR_vulkan_memory_model": 29,
200
"VK_KHR_performance_query": 30,
201
202
"VK_GOOGLE_display_timing": 26,
203
"VK_ANDROID_native_buffer": 26,
204
"VK_ANDROID_external_memory_android_hardware_buffer": 28,
205
}
206
207
# Extensions with these prefixes are checked in Android CTS, and thus must be
208
# whitelisted per the preceding dict.
209
ANDROID_EXTENSION_WHITELIST_PREFIXES = (
210
"VK_KHX",
211
"VK_KHR",
212
"VK_GOOGLE",
213
"VK_ANDROID"
214
)
215
216