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
33 def __init__(self
, name
, ext_version
, enable
):
35 self
.ext_version
= int(ext_version
)
39 self
.enable
= 'false';
44 Extension('VK_KHR_dedicated_allocation', 1, True),
45 Extension('VK_KHR_descriptor_update_template', 1, True),
46 Extension('VK_KHR_external_memory', 1, True),
47 Extension('VK_KHR_external_memory_capabilities', 1, True),
48 Extension('VK_KHR_external_memory_fd', 1, True),
49 Extension('VK_KHR_get_memory_requirements2', 1, True),
50 Extension('VK_KHR_get_physical_device_properties2', 1, True),
51 Extension('VK_KHR_get_surface_capabilities2', 1, True),
52 Extension('VK_KHR_incremental_present', 1, True),
53 Extension('VK_KHR_maintenance1', 1, True),
54 Extension('VK_KHR_push_descriptor', 1, True),
55 Extension('VK_KHR_sampler_mirror_clamp_to_edge', 1, True),
56 Extension('VK_KHR_shader_draw_parameters', 1, True),
57 Extension('VK_KHR_storage_buffer_storage_class', 1, True),
58 Extension('VK_KHR_surface', 25, True),
59 Extension('VK_KHR_swapchain', 68, True),
60 Extension('VK_KHR_variable_pointers', 1, True),
61 Extension('VK_KHR_wayland_surface', 6, 'VK_USE_PLATFORM_WAYLAND_KHR'),
62 Extension('VK_KHR_xcb_surface', 6, 'VK_USE_PLATFORM_XCB_KHR'),
63 Extension('VK_KHR_xlib_surface', 6, 'VK_USE_PLATFORM_XLIB_KHR'),
64 Extension('VK_KHX_multiview', 1, True),
67 def _init_exts_from_xml(xml
):
68 """ Walk the Vulkan XML and fill out extra extension information. """
73 for ext
in EXTENSIONS
:
74 ext_name_map
[ext
.name
] = ext
76 for ext_elem
in xml
.findall('.extensions/extension'):
77 ext_name
= ext_elem
.attrib
['name']
78 if ext_name
not in ext_name_map
:
80 ext
= ext_name_map
[ext_name
]
82 ext
.type = ext_elem
.attrib
['type']
84 for ext
in EXTENSIONS
:
85 assert ext
.type == 'instance' or ext
.type == 'device'
87 _TEMPLATE
= Template(COPYRIGHT
+ """
88 #include "anv_private.h"
92 /* Convert the VK_USE_PLATFORM_* defines to booleans */
93 %for platform in ['ANDROID', 'WAYLAND', 'XCB', 'XLIB']:
94 #ifdef VK_USE_PLATFORM_${platform}_KHR
95 # undef VK_USE_PLATFORM_${platform}_KHR
96 # define VK_USE_PLATFORM_${platform}_KHR true
98 # define VK_USE_PLATFORM_${platform}_KHR false
103 anv_instance_extension_supported(const char *name)
105 %for ext in instance_extensions:
106 if (strcmp(name, "${ext.name}") == 0)
107 return ${ext.enable};
112 VkResult anv_EnumerateInstanceExtensionProperties(
113 const char* pLayerName,
114 uint32_t* pPropertyCount,
115 VkExtensionProperties* pProperties)
117 VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
119 %for ext in instance_extensions:
121 vk_outarray_append(&out, prop) {
122 *prop = (VkExtensionProperties) {
123 .extensionName = "${ext.name}",
124 .specVersion = ${ext.ext_version},
130 return vk_outarray_status(&out);
134 anv_physical_device_extension_supported(struct anv_physical_device *device,
137 %for ext in device_extensions:
138 if (strcmp(name, "${ext.name}") == 0)
139 return ${ext.enable};
144 VkResult anv_EnumerateDeviceExtensionProperties(
145 VkPhysicalDevice physicalDevice,
146 const char* pLayerName,
147 uint32_t* pPropertyCount,
148 VkExtensionProperties* pProperties)
150 ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
151 VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
154 %for ext in device_extensions:
156 vk_outarray_append(&out, prop) {
157 *prop = (VkExtensionProperties) {
158 .extensionName = "${ext.name}",
159 .specVersion = ${ext.ext_version},
165 return vk_outarray_status(&out);
169 if __name__
== '__main__':
170 parser
= argparse
.ArgumentParser()
171 parser
.add_argument('--out', help='Output C file.', required
=True)
172 parser
.add_argument('--xml', help='Vulkan API XML file.', required
=True)
173 args
= parser
.parse_args()
175 _init_exts_from_xml(args
.xml
)
178 'instance_extensions': [e
for e
in EXTENSIONS
if e
.type == 'instance'],
179 'device_extensions': [e
for e
in EXTENSIONS
if e
.type == 'device'],
182 with
open(args
.out
, 'w') as f
:
183 f
.write(_TEMPLATE
.render(**template_env
))