anv+tu+radv: delete unusable dev_icd.json
[mesa.git] / src / intel / vulkan / anv_extensions_gen.py
1 COPYRIGHT = """\
2 /*
3 * Copyright 2017 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 """
26
27 import argparse
28 import xml.etree.cElementTree as et
29
30 from mako.template import Template
31
32 from anv_extensions import *
33
34 platform_defines = []
35
36 def _init_exts_from_xml(xml):
37 """ Walk the Vulkan XML and fill out extra extension information. """
38
39 xml = et.parse(xml)
40
41 ext_name_map = {}
42 for ext in EXTENSIONS:
43 ext_name_map[ext.name] = ext
44
45 # KHR_display is missing from the list.
46 platform_defines.append('VK_USE_PLATFORM_DISPLAY_KHR')
47 for platform in xml.findall('./platforms/platform'):
48 platform_defines.append(platform.attrib['protect'])
49
50 for ext_elem in xml.findall('.extensions/extension'):
51 ext_name = ext_elem.attrib['name']
52 if ext_name not in ext_name_map:
53 continue
54
55 ext = ext_name_map[ext_name]
56 ext.type = ext_elem.attrib['type']
57
58 _TEMPLATE_H = Template(COPYRIGHT + """
59
60 #ifndef ANV_EXTENSIONS_H
61 #define ANV_EXTENSIONS_H
62
63 #include "stdbool.h"
64
65 #define ANV_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
66
67 extern const VkExtensionProperties anv_instance_extensions[];
68
69 struct anv_instance_extension_table {
70 union {
71 bool extensions[ANV_INSTANCE_EXTENSION_COUNT];
72 struct {
73 %for ext in instance_extensions:
74 bool ${ext.name[3:]};
75 %endfor
76 };
77 };
78 };
79
80 extern const struct anv_instance_extension_table anv_instance_extensions_supported;
81
82
83 #define ANV_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
84
85 extern const VkExtensionProperties anv_device_extensions[];
86
87 struct anv_device_extension_table {
88 union {
89 bool extensions[ANV_DEVICE_EXTENSION_COUNT];
90 struct {
91 %for ext in device_extensions:
92 bool ${ext.name[3:]};
93 %endfor
94 };
95 };
96 };
97
98 struct anv_physical_device;
99
100 void
101 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
102 struct anv_device_extension_table *extensions);
103
104 #endif /* ANV_EXTENSIONS_H */
105 """)
106
107 _TEMPLATE_C = Template(COPYRIGHT + """
108 #include "anv_private.h"
109
110 #include "vk_util.h"
111
112 /* Convert the VK_USE_PLATFORM_* defines to booleans */
113 %for platform_define in platform_defines:
114 #ifdef ${platform_define}
115 # undef ${platform_define}
116 # define ${platform_define} true
117 #else
118 # define ${platform_define} false
119 #endif
120 %endfor
121
122 /* And ANDROID too */
123 #ifdef ANDROID
124 # undef ANDROID
125 # define ANDROID true
126 #else
127 # define ANDROID false
128 #endif
129
130 #define ANV_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\
131 VK_USE_PLATFORM_XCB_KHR || \\
132 VK_USE_PLATFORM_XLIB_KHR || \\
133 VK_USE_PLATFORM_DISPLAY_KHR)
134
135 static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
136
137 VkResult anv_EnumerateInstanceVersion(
138 uint32_t* pApiVersion)
139 {
140 *pApiVersion = MAX_API_VERSION;
141 return VK_SUCCESS;
142 }
143
144 const VkExtensionProperties anv_instance_extensions[ANV_INSTANCE_EXTENSION_COUNT] = {
145 %for ext in instance_extensions:
146 {"${ext.name}", ${ext.ext_version}},
147 %endfor
148 };
149
150 const struct anv_instance_extension_table anv_instance_extensions_supported = {
151 %for ext in instance_extensions:
152 .${ext.name[3:]} = ${ext.enable},
153 %endfor
154 };
155
156 uint32_t
157 anv_physical_device_api_version(struct anv_physical_device *device)
158 {
159 uint32_t version = 0;
160
161 uint32_t override = vk_get_version_override();
162 if (override)
163 return MIN2(override, MAX_API_VERSION);
164
165 %for version in API_VERSIONS:
166 if (!(${version.enable}))
167 return version;
168 version = ${version.version.c_vk_version()};
169
170 %endfor
171 return version;
172 }
173
174 const VkExtensionProperties anv_device_extensions[ANV_DEVICE_EXTENSION_COUNT] = {
175 %for ext in device_extensions:
176 {"${ext.name}", ${ext.ext_version}},
177 %endfor
178 };
179
180 void
181 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
182 struct anv_device_extension_table *extensions)
183 {
184 *extensions = (struct anv_device_extension_table) {
185 %for ext in device_extensions:
186 .${ext.name[3:]} = ${ext.enable},
187 %endfor
188 };
189 }
190 """)
191
192 if __name__ == '__main__':
193 parser = argparse.ArgumentParser()
194 parser.add_argument('--out-c', help='Output C file.')
195 parser.add_argument('--out-h', help='Output H file.')
196 parser.add_argument('--xml',
197 help='Vulkan API XML file.',
198 required=True,
199 action='append',
200 dest='xml_files')
201 args = parser.parse_args()
202
203 for filename in args.xml_files:
204 _init_exts_from_xml(filename)
205
206 for ext in EXTENSIONS:
207 assert ext.type == 'instance' or ext.type == 'device'
208
209 template_env = {
210 'API_VERSIONS': API_VERSIONS,
211 'MAX_API_VERSION': MAX_API_VERSION,
212 'instance_extensions': [e for e in EXTENSIONS if e.type == 'instance'],
213 'device_extensions': [e for e in EXTENSIONS if e.type == 'device'],
214 'platform_defines': platform_defines,
215 }
216
217 if args.out_h:
218 with open(args.out_h, 'w') as f:
219 f.write(_TEMPLATE_H.render(**template_env))
220
221 if args.out_c:
222 with open(args.out_c, 'w') as f:
223 f.write(_TEMPLATE_C.render(**template_env))