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 ext
.type = ext_elem
.attrib
['type']
51 _TEMPLATE_H
= Template(COPYRIGHT
+ """
53 #ifndef ANV_EXTENSIONS_H
54 #define ANV_EXTENSIONS_H
58 #define ANV_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
60 extern const VkExtensionProperties anv_instance_extensions[];
62 struct anv_instance_extension_table {
64 bool extensions[ANV_INSTANCE_EXTENSION_COUNT];
66 %for ext in instance_extensions:
73 extern const struct anv_instance_extension_table anv_instance_extensions_supported;
76 #define ANV_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
78 extern const VkExtensionProperties anv_device_extensions[];
80 struct anv_device_extension_table {
82 bool extensions[ANV_DEVICE_EXTENSION_COUNT];
84 %for ext in device_extensions:
91 struct anv_physical_device;
94 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
95 struct anv_device_extension_table *extensions);
97 #endif /* ANV_EXTENSIONS_H */
100 _TEMPLATE_C
= Template(COPYRIGHT
+ """
101 #include "anv_private.h"
105 /* Convert the VK_USE_PLATFORM_* defines to booleans */
106 %for platform in ['ANDROID_KHR', 'WAYLAND_KHR', 'XCB_KHR', 'XLIB_KHR', 'DISPLAY_KHR', 'XLIB_XRANDR_EXT']:
107 #ifdef VK_USE_PLATFORM_${platform}
108 # undef VK_USE_PLATFORM_${platform}
109 # define VK_USE_PLATFORM_${platform} true
111 # define VK_USE_PLATFORM_${platform} false
115 /* And ANDROID too */
118 # define ANDROID true
120 # define ANDROID false
123 #define ANV_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\
124 VK_USE_PLATFORM_XCB_KHR || \\
125 VK_USE_PLATFORM_XLIB_KHR || \\
126 VK_USE_PLATFORM_DISPLAY_KHR)
128 static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
130 VkResult anv_EnumerateInstanceVersion(
131 uint32_t* pApiVersion)
133 *pApiVersion = MAX_API_VERSION;
137 const VkExtensionProperties anv_instance_extensions[ANV_INSTANCE_EXTENSION_COUNT] = {
138 %for ext in instance_extensions:
139 {"${ext.name}", ${ext.ext_version}},
143 const struct anv_instance_extension_table anv_instance_extensions_supported = {
144 %for ext in instance_extensions:
145 .${ext.name[3:]} = ${ext.enable},
150 anv_physical_device_api_version(struct anv_physical_device *device)
152 uint32_t version = 0;
154 uint32_t override = vk_get_version_override();
156 return MIN2(override, MAX_API_VERSION);
158 %for version in API_VERSIONS:
159 if (!(${version.enable}))
161 version = ${version.version.c_vk_version()};
167 const VkExtensionProperties anv_device_extensions[ANV_DEVICE_EXTENSION_COUNT] = {
168 %for ext in device_extensions:
169 {"${ext.name}", ${ext.ext_version}},
174 anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
175 struct anv_device_extension_table *extensions)
177 *extensions = (struct anv_device_extension_table) {
178 %for ext in device_extensions:
179 .${ext.name[3:]} = ${ext.enable},
185 if __name__
== '__main__':
186 parser
= argparse
.ArgumentParser()
187 parser
.add_argument('--out-c', help='Output C file.')
188 parser
.add_argument('--out-h', help='Output H file.')
189 parser
.add_argument('--xml',
190 help='Vulkan API XML file.',
194 args
= parser
.parse_args()
196 for filename
in args
.xml_files
:
197 _init_exts_from_xml(filename
)
199 for ext
in EXTENSIONS
:
200 assert ext
.type == 'instance' or ext
.type == 'device'
203 'API_VERSIONS': API_VERSIONS
,
204 'MAX_API_VERSION': MAX_API_VERSION
,
205 'instance_extensions': [e
for e
in EXTENSIONS
if e
.type == 'instance'],
206 'device_extensions': [e
for e
in EXTENSIONS
if e
.type == 'device'],
210 with
open(args
.out_h
, 'w') as f
:
211 f
.write(_TEMPLATE_H
.render(**template_env
))
214 with
open(args
.out_c
, 'w') as f
:
215 f
.write(_TEMPLATE_C
.render(**template_env
))