e340761a67893bfd9b91f5bcb582e4a60d565ffd
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.
27 import xml
.etree
.cElementTree
as et
29 from mako
.template
import Template
31 from vk_extensions
import *
33 _TEMPLATE_H
= Template(COPYRIGHT
+ """
35 #ifndef ${driver.upper()}_EXTENSIONS_H
36 #define ${driver.upper()}_EXTENSIONS_H
38 %for include in includes:
42 #define ${driver.upper()}_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
44 extern const VkExtensionProperties ${driver}_instance_extensions[];
46 struct ${driver}_instance_extension_table {
48 bool extensions[${driver.upper()}_INSTANCE_EXTENSION_COUNT];
50 %for ext in instance_extensions:
57 extern const struct ${driver}_instance_extension_table ${driver}_instance_extensions_supported;
60 #define ${driver.upper()}_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
62 extern const VkExtensionProperties ${driver}_device_extensions[];
64 struct ${driver}_device_extension_table {
66 bool extensions[${driver.upper()}_DEVICE_EXTENSION_COUNT];
68 %for ext in device_extensions:
75 struct ${driver}_physical_device;
78 ${driver}_physical_device_get_supported_extensions(const struct ${driver}_physical_device *device,
79 struct ${driver}_device_extension_table *extensions);
81 #endif /* ${driver.upper()}_EXTENSIONS_H */
84 _TEMPLATE_C
= Template(COPYRIGHT
+ """
85 #include "${driver}_private.h"
89 /* Convert the VK_USE_PLATFORM_* defines to booleans */
90 %for platform_define in platform_defines:
91 #ifdef ${platform_define}
92 # undef ${platform_define}
93 # define ${platform_define} true
95 # define ${platform_define} false
102 # define ANDROID true
104 # define ANDROID false
105 # define ANDROID_API_LEVEL 0
108 #define ${driver.upper()}_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\
109 VK_USE_PLATFORM_XCB_KHR || \\
110 VK_USE_PLATFORM_XLIB_KHR || \\
111 VK_USE_PLATFORM_DISPLAY_KHR)
113 static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
115 VkResult ${driver}_EnumerateInstanceVersion(
116 uint32_t* pApiVersion)
118 *pApiVersion = MAX_API_VERSION;
122 const VkExtensionProperties ${driver}_instance_extensions[${driver.upper()}_INSTANCE_EXTENSION_COUNT] = {
123 %for ext in instance_extensions:
124 {"${ext.name}", ${ext.ext_version}},
128 const struct ${driver}_instance_extension_table ${driver}_instance_extensions_supported = {
129 %for ext in instance_extensions:
130 .${ext.name[3:]} = ${get_extension_condition(ext.name, ext.enable)},
135 ${driver}_physical_device_api_version(struct ${driver}_physical_device *device)
137 uint32_t version = 0;
139 uint32_t override = vk_get_version_override();
141 return MIN2(override, MAX_API_VERSION);
143 %for version in API_VERSIONS:
144 if (!(${version.enable}))
146 version = ${version.version.c_vk_version()};
152 const VkExtensionProperties ${driver}_device_extensions[${driver.upper()}_DEVICE_EXTENSION_COUNT] = {
153 %for ext in device_extensions:
154 {"${ext.name}", ${ext.ext_version}},
159 ${driver}_physical_device_get_supported_extensions(const struct ${driver}_physical_device *device,
160 struct ${driver}_device_extension_table *extensions)
162 *extensions = (struct ${driver}_device_extension_table) {
163 %for ext in device_extensions:
164 .${ext.name[3:]} = ${get_extension_condition(ext.name, ext.enable)},
170 def gen_extensions(driver
, xml_files
, api_versions
, max_api_version
, extensions
, out_c
, out_h
, includes
= []):
171 platform_defines
= []
172 for filename
in xml_files
:
173 init_exts_from_xml(filename
, extensions
, platform_defines
)
175 for ext
in extensions
:
176 assert ext
.type == 'instance' or ext
.type == 'device'
180 'API_VERSIONS': api_versions
,
181 'MAX_API_VERSION': max_api_version
,
182 'instance_extensions': [e
for e
in extensions
if e
.type == 'instance'],
183 'device_extensions': [e
for e
in extensions
if e
.type == 'device'],
184 'platform_defines': platform_defines
,
185 'get_extension_condition': get_extension_condition
,
186 'includes': includes
,
190 with
open(out_h
, 'w') as f
:
191 f
.write(_TEMPLATE_H
.render(**template_env
))
194 with
open(out_c
, 'w') as f
:
195 f
.write(_TEMPLATE_C
.render(**template_env
))