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 *
34 def _init_exts_from_xml(xml
):
35 """ Walk the Vulkan XML and fill out extra extension information. """
40 for ext
in EXTENSIONS
:
41 ext_name_map
[ext
.name
] = ext
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
:
48 ext
= ext_name_map
[ext_name
]
49 if ext_name
== 'VK_ANDROID_native_buffer':
50 # VK_ANDROID_native_buffer is missing the type specifier. Just
51 # hard-code it to be a device extension for now.
54 ext
.type = ext_elem
.attrib
['type']
56 _TEMPLATE_H
= Template(COPYRIGHT
+ """
58 #ifndef ANV_EXTENSIONS_H
59 #define ANV_EXTENSIONS_H
63 #define ANV_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
65 extern const VkExtensionProperties anv_instance_extensions[];
67 struct anv_instance_extension_table {
69 bool extensions[ANV_INSTANCE_EXTENSION_COUNT];
71 %for ext in instance_extensions:
78 extern const struct anv_instance_extension_table anv_instance_extensions_supported;
81 #define ANV_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
83 extern const VkExtensionProperties anv_device_extensions[];
85 struct anv_device_extension_table {
87 bool extensions[ANV_DEVICE_EXTENSION_COUNT];
89 %for ext in device_extensions:
96 struct anv_physical_device;
99 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
100 struct anv_device_extension_table *extensions);
102 #endif /* ANV_EXTENSIONS_H */
105 _TEMPLATE_C
= Template(COPYRIGHT
+ """
106 #include "anv_private.h"
110 /* Convert the VK_USE_PLATFORM_* defines to booleans */
111 %for platform in ['ANDROID', 'WAYLAND', 'XCB', 'XLIB']:
112 #ifdef VK_USE_PLATFORM_${platform}_KHR
113 # undef VK_USE_PLATFORM_${platform}_KHR
114 # define VK_USE_PLATFORM_${platform}_KHR true
116 # define VK_USE_PLATFORM_${platform}_KHR false
120 /* And ANDROID too */
123 # define ANDROID true
125 # define ANDROID false
128 #define ANV_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\
129 VK_USE_PLATFORM_XCB_KHR || \\
130 VK_USE_PLATFORM_XLIB_KHR)
132 static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
134 VkResult anv_EnumerateInstanceVersion(
135 uint32_t* pApiVersion)
137 *pApiVersion = MAX_API_VERSION;
141 const VkExtensionProperties anv_instance_extensions[ANV_INSTANCE_EXTENSION_COUNT] = {
142 %for ext in instance_extensions:
143 {"${ext.name}", ${ext.ext_version}},
147 const struct anv_instance_extension_table anv_instance_extensions_supported = {
148 %for ext in instance_extensions:
149 .${ext.name[3:]} = ${ext.enable},
154 anv_physical_device_api_version(struct anv_physical_device *device)
156 uint32_t version = 0;
158 uint32_t override = vk_get_version_override();
160 return MIN2(override, MAX_API_VERSION);
162 %for version in API_VERSIONS:
163 if (!(${version.enable}))
165 version = ${version.max_patch_version.c_vk_version()};
171 const VkExtensionProperties anv_device_extensions[ANV_DEVICE_EXTENSION_COUNT] = {
172 %for ext in device_extensions:
173 {"${ext.name}", ${ext.ext_version}},
178 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
179 struct anv_device_extension_table *extensions)
181 *extensions = (struct anv_device_extension_table) {
182 %for ext in device_extensions:
183 .${ext.name[3:]} = ${ext.enable},
189 if __name__
== '__main__':
190 parser
= argparse
.ArgumentParser()
191 parser
.add_argument('--out-c', help='Output C file.')
192 parser
.add_argument('--out-h', help='Output H file.')
193 parser
.add_argument('--xml',
194 help='Vulkan API XML file.',
198 args
= parser
.parse_args()
200 for filename
in args
.xml_files
:
201 _init_exts_from_xml(filename
)
203 for ext
in EXTENSIONS
:
204 assert ext
.type == 'instance' or ext
.type == 'device'
207 'API_VERSIONS': API_VERSIONS
,
208 'MAX_API_VERSION': MAX_API_VERSION
,
209 'instance_extensions': [e
for e
in EXTENSIONS
if e
.type == 'instance'],
210 'device_extensions': [e
for e
in EXTENSIONS
if e
.type == 'device'],
214 with
open(args
.out_h
, 'w') as f
:
215 f
.write(_TEMPLATE_H
.render(**template_env
))
218 with
open(args
.out_c
, 'w') as f
:
219 f
.write(_TEMPLATE_C
.render(**template_env
))