anv,radv: Drop XML workarounds for VK_ANDROID_native_buffer
[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 def _init_exts_from_xml(xml):
35 """ Walk the Vulkan XML and fill out extra extension information. """
36
37 xml = et.parse(xml)
38
39 ext_name_map = {}
40 for ext in EXTENSIONS:
41 ext_name_map[ext.name] = ext
42
43 for ext_elem in xml.findall('.extensions/extension'):
44 ext_name = ext_elem.attrib['name']
45 if ext_name not in ext_name_map:
46 continue
47
48 ext = ext_name_map[ext_name]
49 ext.type = ext_elem.attrib['type']
50
51 _TEMPLATE_H = Template(COPYRIGHT + """
52
53 #ifndef ANV_EXTENSIONS_H
54 #define ANV_EXTENSIONS_H
55
56 #include "stdbool.h"
57
58 #define ANV_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
59
60 extern const VkExtensionProperties anv_instance_extensions[];
61
62 struct anv_instance_extension_table {
63 union {
64 bool extensions[ANV_INSTANCE_EXTENSION_COUNT];
65 struct {
66 %for ext in instance_extensions:
67 bool ${ext.name[3:]};
68 %endfor
69 };
70 };
71 };
72
73 extern const struct anv_instance_extension_table anv_instance_extensions_supported;
74
75
76 #define ANV_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
77
78 extern const VkExtensionProperties anv_device_extensions[];
79
80 struct anv_device_extension_table {
81 union {
82 bool extensions[ANV_DEVICE_EXTENSION_COUNT];
83 struct {
84 %for ext in device_extensions:
85 bool ${ext.name[3:]};
86 %endfor
87 };
88 };
89 };
90
91 struct anv_physical_device;
92
93 void
94 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
95 struct anv_device_extension_table *extensions);
96
97 #endif /* ANV_EXTENSIONS_H */
98 """)
99
100 _TEMPLATE_C = Template(COPYRIGHT + """
101 #include "anv_private.h"
102
103 #include "vk_util.h"
104
105 /* Convert the VK_USE_PLATFORM_* defines to booleans */
106 %for platform in ['ANDROID', 'WAYLAND', 'XCB', 'XLIB']:
107 #ifdef VK_USE_PLATFORM_${platform}_KHR
108 # undef VK_USE_PLATFORM_${platform}_KHR
109 # define VK_USE_PLATFORM_${platform}_KHR true
110 #else
111 # define VK_USE_PLATFORM_${platform}_KHR false
112 #endif
113 %endfor
114
115 /* And ANDROID too */
116 #ifdef ANDROID
117 # undef ANDROID
118 # define ANDROID true
119 #else
120 # define ANDROID false
121 #endif
122
123 #define ANV_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\
124 VK_USE_PLATFORM_XCB_KHR || \\
125 VK_USE_PLATFORM_XLIB_KHR)
126
127 static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
128
129 VkResult anv_EnumerateInstanceVersion(
130 uint32_t* pApiVersion)
131 {
132 *pApiVersion = MAX_API_VERSION;
133 return VK_SUCCESS;
134 }
135
136 const VkExtensionProperties anv_instance_extensions[ANV_INSTANCE_EXTENSION_COUNT] = {
137 %for ext in instance_extensions:
138 {"${ext.name}", ${ext.ext_version}},
139 %endfor
140 };
141
142 const struct anv_instance_extension_table anv_instance_extensions_supported = {
143 %for ext in instance_extensions:
144 .${ext.name[3:]} = ${ext.enable},
145 %endfor
146 };
147
148 uint32_t
149 anv_physical_device_api_version(struct anv_physical_device *device)
150 {
151 uint32_t version = 0;
152
153 uint32_t override = vk_get_version_override();
154 if (override)
155 return MIN2(override, MAX_API_VERSION);
156
157 %for version in API_VERSIONS:
158 if (!(${version.enable}))
159 return version;
160 version = ${version.max_patch_version.c_vk_version()};
161
162 %endfor
163 return version;
164 }
165
166 const VkExtensionProperties anv_device_extensions[ANV_DEVICE_EXTENSION_COUNT] = {
167 %for ext in device_extensions:
168 {"${ext.name}", ${ext.ext_version}},
169 %endfor
170 };
171
172 void
173 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
174 struct anv_device_extension_table *extensions)
175 {
176 *extensions = (struct anv_device_extension_table) {
177 %for ext in device_extensions:
178 .${ext.name[3:]} = ${ext.enable},
179 %endfor
180 };
181 }
182 """)
183
184 if __name__ == '__main__':
185 parser = argparse.ArgumentParser()
186 parser.add_argument('--out-c', help='Output C file.')
187 parser.add_argument('--out-h', help='Output H file.')
188 parser.add_argument('--xml',
189 help='Vulkan API XML file.',
190 required=True,
191 action='append',
192 dest='xml_files')
193 args = parser.parse_args()
194
195 for filename in args.xml_files:
196 _init_exts_from_xml(filename)
197
198 for ext in EXTENSIONS:
199 assert ext.type == 'instance' or ext.type == 'device'
200
201 template_env = {
202 'API_VERSIONS': API_VERSIONS,
203 'MAX_API_VERSION': MAX_API_VERSION,
204 'instance_extensions': [e for e in EXTENSIONS if e.type == 'instance'],
205 'device_extensions': [e for e in EXTENSIONS if e.type == 'device'],
206 }
207
208 if args.out_h:
209 with open(args.out_h, 'w') as f:
210 f.write(_TEMPLATE_H.render(**template_env))
211
212 if args.out_c:
213 with open(args.out_c, 'w') as f:
214 f.write(_TEMPLATE_C.render(**template_env))