3 * Copyright 2017 Intel Corporation
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
28 import xml
.etree
.cElementTree
as et
30 from mako
.template
import Template
32 from anv_extensions
import *
36 def _init_exts_from_xml(xml
):
37 """ Walk the Vulkan XML and fill out extra extension information. """
42 for ext
in EXTENSIONS
:
43 ext_name_map
[ext
.name
] = ext
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'])
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
:
55 ext
= ext_name_map
[ext_name
]
56 ext
.type = ext_elem
.attrib
['type']
58 _TEMPLATE_H
= Template(COPYRIGHT
+ """
60 #ifndef ANV_EXTENSIONS_H
61 #define ANV_EXTENSIONS_H
65 #include "perf/gen_perf.h"
67 #define ANV_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
69 extern const VkExtensionProperties anv_instance_extensions[];
71 struct anv_instance_extension_table {
73 bool extensions[ANV_INSTANCE_EXTENSION_COUNT];
75 %for ext in instance_extensions:
82 extern const struct anv_instance_extension_table anv_instance_extensions_supported;
85 #define ANV_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
87 extern const VkExtensionProperties anv_device_extensions[];
89 struct anv_device_extension_table {
91 bool extensions[ANV_DEVICE_EXTENSION_COUNT];
93 %for ext in device_extensions:
100 struct anv_physical_device;
103 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
104 struct anv_device_extension_table *extensions);
106 #endif /* ANV_EXTENSIONS_H */
109 _TEMPLATE_C
= Template(COPYRIGHT
+ """
110 #include "anv_private.h"
114 /* Convert the VK_USE_PLATFORM_* defines to booleans */
115 %for platform_define in platform_defines:
116 #ifdef ${platform_define}
117 # undef ${platform_define}
118 # define ${platform_define} true
120 # define ${platform_define} false
124 /* And ANDROID too */
127 # define ANDROID true
129 # define ANDROID false
130 # define ANDROID_API_LEVEL 0
133 #define ANV_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\
134 VK_USE_PLATFORM_XCB_KHR || \\
135 VK_USE_PLATFORM_XLIB_KHR || \\
136 VK_USE_PLATFORM_DISPLAY_KHR)
138 static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
140 VkResult anv_EnumerateInstanceVersion(
141 uint32_t* pApiVersion)
143 *pApiVersion = MAX_API_VERSION;
147 const VkExtensionProperties anv_instance_extensions[ANV_INSTANCE_EXTENSION_COUNT] = {
148 %for ext in instance_extensions:
149 {"${ext.name}", ${ext.ext_version}},
153 const struct anv_instance_extension_table anv_instance_extensions_supported = {
154 %for ext in instance_extensions:
155 .${ext.name[3:]} = ${get_extension_condition(ext.name, ext.enable)},
160 anv_physical_device_api_version(struct anv_physical_device *device)
162 uint32_t version = 0;
164 uint32_t override = vk_get_version_override();
166 return MIN2(override, MAX_API_VERSION);
168 %for version in API_VERSIONS:
169 if (!(${version.enable}))
171 version = ${version.version.c_vk_version()};
177 const VkExtensionProperties anv_device_extensions[ANV_DEVICE_EXTENSION_COUNT] = {
178 %for ext in device_extensions:
179 {"${ext.name}", ${ext.ext_version}},
184 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
185 struct anv_device_extension_table *extensions)
187 *extensions = (struct anv_device_extension_table) {
188 %for ext in device_extensions:
189 .${ext.name[3:]} = ${get_extension_condition(ext.name, ext.enable)},
195 if __name__
== '__main__':
196 parser
= argparse
.ArgumentParser()
197 parser
.add_argument('--out-c', help='Output C file.')
198 parser
.add_argument('--out-h', help='Output H file.')
199 parser
.add_argument('--xml',
200 help='Vulkan API XML file.',
204 args
= parser
.parse_args()
206 for filename
in args
.xml_files
:
207 _init_exts_from_xml(filename
)
209 for ext
in EXTENSIONS
:
210 assert ext
.type == 'instance' or ext
.type == 'device'
213 'API_VERSIONS': API_VERSIONS
,
214 'MAX_API_VERSION': MAX_API_VERSION
,
215 'instance_extensions': [e
for e
in EXTENSIONS
if e
.type == 'instance'],
216 'device_extensions': [e
for e
in EXTENSIONS
if e
.type == 'device'],
217 'platform_defines': platform_defines
,
218 'get_extension_condition': get_extension_condition
,
222 with
open(args
.out_h
, 'w') as f
:
223 f
.write(_TEMPLATE_H
.render(**template_env
))
226 with
open(args
.out_c
, 'w') as f
:
227 f
.write(_TEMPLATE_C
.render(**template_env
))