Repository navigation
Expand file tree
/
Copy pathextract_vulkan_extensions_sifter.py
More file actions
executable file
·165 lines (140 loc) · 5.81 KB
/
Copy pathextract_vulkan_extensions_sifter.py
File metadata and controls
executable file
·165 lines (140 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python3
import argparse
from collections import namedtuple
import xml.etree.ElementTree as ET
import json
import sys
def is_banned_ext(ext):
if 'Scissor' in ext:
return False
if 'DisplacementMicromap' in ext:
return True
if 'CudaKernelLaunch' in ext:
return True
banned_vendors = [ 'ANDROID', 'AMDX', 'Sci', 'Portability', 'VulkanSC', 'QNX' ]
for vendor in banned_vendors:
if vendor in ext:
return True
return False
def main():
parser = argparse.ArgumentParser(description = 'Script for extracting what needs to be sifted through w.r.t. PDF2.')
parser.add_argument('--xml', help = 'Path to Vulkan registry XML.')
args = parser.parse_args()
if not args.xml:
sys.stderr.write('Need XML.\n')
sys.exit(1)
tree = ET.parse(args.xml)
root = tree.getroot()
struct_types = {}
enum_types = {}
bitmask_requirements = {}
type_aliases = {}
feature_structs = {}
for t in root.find('types').iter('type'):
if 'alias' in t.attrib:
type_aliases[t.attrib['name']] = t.attrib['alias']
pNextLUT = []
for t in root.find('types').iter('type'):
if 'category' not in t.attrib:
continue
category = t.attrib['category']
if category == 'struct':
name = t.attrib['name']
if is_banned_ext(name):
continue
member_types = []
extended_types = set()
extends = set()
if 'structextends' in t.attrib:
extends = t.attrib['structextends'].split(',')
extends = set([type_aliases.get(x, x) for x in extends])
if ('VkPhysicalDeviceFeatures2' in extends) or ('VkPhysicalDeviceFeatures2KHR' in extends):
stype = t.find('member').attrib['values']
if name not in type_aliases:
pNextLUT.append((stype, name))
feature_structs[name] = stype
print('#pragma once')
print('// Autogenerated from extract_vulkan_extensions_sifter.py')
print('#include <string>')
print('static const struct {')
print('\tVkStructureType sType;')
print('\tsize_t size;')
print('} pNextLUT[] = {')
for entry in pNextLUT:
print('\t{', entry[0] + ',', f'sizeof({entry[1]})', '},')
print('};\n')
print('struct ExtensionRequirements {')
print('\tvoid *primary_feature;')
print('\tvoid *secondary_feature;')
print('\tconst char * const *extension_dependencies;')
print('\tuint32_t num_extension_dependencies;')
print('\tuint32_t minimum_api_version;')
print('};\n')
member_names = []
print('struct ExistingFeatureStructs {')
for feat in feature_structs:
print(f'\t{feat} m{feat[16:]} =', '{', feature_structs[feat], '};')
member_names.append(feat[16:])
info_impl = []
for ext in root.find('extensions').iter('extension'):
if ('vulkan' in ext.attrib['supported'].split(',')) and (ext.attrib['type'] == 'device'):
ext_name = ext.attrib['name']
deps = ext.attrib['depends'] if 'depends' in ext.attrib else None
if is_banned_ext(ext_name):
continue
core_dep = 'VK_VERSION_1_0'
ext_deps = []
# Crude parsing. Don't want to implement basic grammar here, so just do
# the minimal hackery needed to parse the xml.
# Just consider everything "and".
if deps:
or_deps = deps.split(',')
for or_dep in or_deps:
deps = or_dep.split('+')
for dep in deps:
while dep[0] == '(':
dep = dep[1:]
while dep[-1] == ')':
dep = dep[:-1]
if 'VK_VERSION' in dep:
if dep > core_dep:
core_dep = dep
else:
ext_deps.append(dep)
features = []
for reqs in ext.iter('require'):
for t in reqs.iter('type'):
type_name = t.attrib['name']
type_name = type_aliases.get(type_name, type_name)
if (type_name in feature_structs) and (type_name not in features):
features.append(type_name)
info_impl.append(f'if (ext == "{ext_name}")' + ' {')
info_impl.append('\tdep = {};')
info_impl.append(f'\tdep.minimum_api_version = {core_dep};')
if len(ext_deps) != 0:
info_impl.append('\tstatic const char * const exts[] = { ' + ', '.join([f'"{e}"' for e in ext_deps]) + ' };')
info_impl.append('\tdep.num_extension_dependencies = uint32_t(sizeof(exts) / sizeof(exts[0]));')
info_impl.append('\tdep.extension_dependencies = exts;')
if len(features) >= 1:
info_impl.append(f'\tdep.primary_feature = &m{features[0][16:]};')
if len(features) >= 2:
info_impl.append(f'\tdep.secondary_feature = &m{features[1][16:]};')
info_impl.append('\treturn true;')
info_impl.append('}')
info_impl.append('')
assert len(features) <= 2, 'Number of feature structs per extension is expected to be max 2.'
print('\tvoid reset_pnext() {')
for member_name in member_names:
print(f'\t\tm{member_name}.pNext = nullptr;')
print('\t}\n')
print('\tbool get_extension_requirements(const std::string &ext, ExtensionRequirements &dep) {')
for l in info_impl:
if len(l):
print('\t\t' + l)
else:
print('')
print('\t\treturn false;')
print('\t}')
print('};\n')
if __name__ == '__main__':
main()