17ec681f3SmrgCOPYRIGHT = """\ 27ec681f3Smrg/* 37ec681f3Smrg * Copyright 2017 Intel Corporation 47ec681f3Smrg * 57ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 67ec681f3Smrg * copy of this software and associated documentation files (the 77ec681f3Smrg * "Software"), to deal in the Software without restriction, including 87ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish, 97ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to 107ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to 117ec681f3Smrg * the following conditions: 127ec681f3Smrg * 137ec681f3Smrg * The above copyright notice and this permission notice (including the 147ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions 157ec681f3Smrg * of the Software. 167ec681f3Smrg * 177ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 187ec681f3Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 197ec681f3Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 207ec681f3Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 217ec681f3Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 227ec681f3Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 237ec681f3Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 247ec681f3Smrg */ 257ec681f3Smrg""" 267ec681f3Smrg 277ec681f3Smrgimport xml.etree.ElementTree as et 287ec681f3Smrg 297ec681f3Smrgfrom mako.template import Template 307ec681f3Smrg 317ec681f3Smrg# Mesa-local imports must be declared in meson variable 327ec681f3Smrg# '{file_without_suffix}_depend_files'. 337ec681f3Smrgfrom vk_extensions import * 347ec681f3Smrg 357ec681f3Smrg_TEMPLATE_H = Template(COPYRIGHT + """ 367ec681f3Smrg 377ec681f3Smrg#ifndef ${driver.upper()}_EXTENSIONS_H 387ec681f3Smrg#define ${driver.upper()}_EXTENSIONS_H 397ec681f3Smrg 407ec681f3Smrg#include <stdbool.h> 417ec681f3Smrg 427ec681f3Smrg%for include in includes: 437ec681f3Smrg#include "${include}" 447ec681f3Smrg%endfor 457ec681f3Smrg 467ec681f3Smrg%if driver == 'vk': 477ec681f3Smrg#define VK_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)} 487ec681f3Smrg 497ec681f3Smrgextern const VkExtensionProperties vk_instance_extensions[]; 507ec681f3Smrg 517ec681f3Smrgstruct vk_instance_extension_table { 527ec681f3Smrg union { 537ec681f3Smrg bool extensions[VK_INSTANCE_EXTENSION_COUNT]; 547ec681f3Smrg struct { 557ec681f3Smrg%for ext in instance_extensions: 567ec681f3Smrg bool ${ext.name[3:]}; 577ec681f3Smrg%endfor 587ec681f3Smrg }; 597ec681f3Smrg }; 607ec681f3Smrg}; 617ec681f3Smrg 627ec681f3Smrg 637ec681f3Smrg#define VK_DEVICE_EXTENSION_COUNT ${len(device_extensions)} 647ec681f3Smrg 657ec681f3Smrgextern const VkExtensionProperties vk_device_extensions[]; 667ec681f3Smrg 677ec681f3Smrgstruct vk_device_extension_table { 687ec681f3Smrg union { 697ec681f3Smrg bool extensions[VK_DEVICE_EXTENSION_COUNT]; 707ec681f3Smrg struct { 717ec681f3Smrg%for ext in device_extensions: 727ec681f3Smrg bool ${ext.name[3:]}; 737ec681f3Smrg%endfor 747ec681f3Smrg }; 757ec681f3Smrg }; 767ec681f3Smrg}; 777ec681f3Smrg%else: 787ec681f3Smrg#include "vk_extensions.h" 797ec681f3Smrg%endif 807ec681f3Smrg 817ec681f3Smrgstruct ${driver}_physical_device; 827ec681f3Smrg 837ec681f3Smrg%if driver == 'vk': 847ec681f3Smrg#ifdef ANDROID 857ec681f3Smrgextern const struct vk_instance_extension_table vk_android_allowed_instance_extensions; 867ec681f3Smrgextern const struct vk_device_extension_table vk_android_allowed_device_extensions; 877ec681f3Smrg#endif 887ec681f3Smrg%else: 897ec681f3Smrgextern const struct vk_instance_extension_table ${driver}_instance_extensions_supported; 907ec681f3Smrg 917ec681f3Smrgvoid 927ec681f3Smrg${driver}_physical_device_get_supported_extensions(const struct ${driver}_physical_device *device, 937ec681f3Smrg struct vk_device_extension_table *extensions); 947ec681f3Smrg%endif 957ec681f3Smrg 967ec681f3Smrg#endif /* ${driver.upper()}_EXTENSIONS_H */ 977ec681f3Smrg""") 987ec681f3Smrg 997ec681f3Smrg_TEMPLATE_C = Template(COPYRIGHT + """ 1007ec681f3Smrg%if driver == 'vk': 1017ec681f3Smrg#include "vk_object.h" 1027ec681f3Smrg%else: 1037ec681f3Smrg#include "${driver}_private.h" 1047ec681f3Smrg%endif 1057ec681f3Smrg 1067ec681f3Smrg#include "${driver}_extensions.h" 1077ec681f3Smrg 1087ec681f3Smrg%if driver == 'vk': 1097ec681f3Smrgconst VkExtensionProperties ${driver}_instance_extensions[${driver.upper()}_INSTANCE_EXTENSION_COUNT] = { 1107ec681f3Smrg%for ext in instance_extensions: 1117ec681f3Smrg {"${ext.name}", ${ext.ext_version}}, 1127ec681f3Smrg%endfor 1137ec681f3Smrg}; 1147ec681f3Smrg 1157ec681f3Smrgconst VkExtensionProperties ${driver}_device_extensions[${driver.upper()}_DEVICE_EXTENSION_COUNT] = { 1167ec681f3Smrg%for ext in device_extensions: 1177ec681f3Smrg {"${ext.name}", ${ext.ext_version}}, 1187ec681f3Smrg%endfor 1197ec681f3Smrg}; 1207ec681f3Smrg 1217ec681f3Smrg#ifdef ANDROID 1227ec681f3Smrgconst struct vk_instance_extension_table vk_android_allowed_instance_extensions = { 1237ec681f3Smrg%for ext in instance_extensions: 1247ec681f3Smrg .${ext.name[3:]} = ${ext.c_android_condition()}, 1257ec681f3Smrg%endfor 1267ec681f3Smrg}; 1277ec681f3Smrg 1287ec681f3Smrgextern const struct vk_device_extension_table vk_android_allowed_device_extensions = { 1297ec681f3Smrg%for ext in device_extensions: 1307ec681f3Smrg .${ext.name[3:]} = ${ext.c_android_condition()}, 1317ec681f3Smrg%endfor 1327ec681f3Smrg}; 1337ec681f3Smrg#endif 1347ec681f3Smrg%endif 1357ec681f3Smrg 1367ec681f3Smrg%if driver != 'vk': 1377ec681f3Smrg#include "vk_util.h" 1387ec681f3Smrg 1397ec681f3Smrg/* Convert the VK_USE_PLATFORM_* defines to booleans */ 1407ec681f3Smrg%for platform_define in platform_defines: 1417ec681f3Smrg#ifdef ${platform_define} 1427ec681f3Smrg# undef ${platform_define} 1437ec681f3Smrg# define ${platform_define} true 1447ec681f3Smrg#else 1457ec681f3Smrg# define ${platform_define} false 1467ec681f3Smrg#endif 1477ec681f3Smrg%endfor 1487ec681f3Smrg 1497ec681f3Smrg/* And ANDROID too */ 1507ec681f3Smrg#ifdef ANDROID 1517ec681f3Smrg# undef ANDROID 1527ec681f3Smrg# define ANDROID true 1537ec681f3Smrg#else 1547ec681f3Smrg# define ANDROID false 1557ec681f3Smrg# define ANDROID_API_LEVEL 0 1567ec681f3Smrg#endif 1577ec681f3Smrg 1587ec681f3Smrg#define ${driver.upper()}_HAS_SURFACE (VK_USE_PLATFORM_WIN32_KHR || \\ 1597ec681f3Smrg VK_USE_PLATFORM_WAYLAND_KHR || \\ 1607ec681f3Smrg VK_USE_PLATFORM_XCB_KHR || \\ 1617ec681f3Smrg VK_USE_PLATFORM_XLIB_KHR || \\ 1627ec681f3Smrg VK_USE_PLATFORM_DISPLAY_KHR) 1637ec681f3Smrg 1647ec681f3Smrgstatic const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()}; 1657ec681f3Smrg 1667ec681f3SmrgVKAPI_ATTR VkResult VKAPI_CALL ${driver}_EnumerateInstanceVersion( 1677ec681f3Smrg uint32_t* pApiVersion) 1687ec681f3Smrg{ 1697ec681f3Smrg *pApiVersion = MAX_API_VERSION; 1707ec681f3Smrg return VK_SUCCESS; 1717ec681f3Smrg} 1727ec681f3Smrg 1737ec681f3Smrgconst struct vk_instance_extension_table ${driver}_instance_extensions_supported = { 1747ec681f3Smrg%for ext in instance_extensions: 1757ec681f3Smrg .${ext.name[3:]} = ${ext.enable}, 1767ec681f3Smrg%endfor 1777ec681f3Smrg}; 1787ec681f3Smrg 1797ec681f3Smrguint32_t 1807ec681f3Smrg${driver}_physical_device_api_version(struct ${driver}_physical_device *device) 1817ec681f3Smrg{ 1827ec681f3Smrg uint32_t version = 0; 1837ec681f3Smrg 1847ec681f3Smrg uint32_t override = vk_get_version_override(); 1857ec681f3Smrg if (override) 1867ec681f3Smrg return MIN2(override, MAX_API_VERSION); 1877ec681f3Smrg 1887ec681f3Smrg%for version in API_VERSIONS: 1897ec681f3Smrg if (!(${version.enable})) 1907ec681f3Smrg return version; 1917ec681f3Smrg version = ${version.version.c_vk_version()}; 1927ec681f3Smrg 1937ec681f3Smrg%endfor 1947ec681f3Smrg return version; 1957ec681f3Smrg} 1967ec681f3Smrg 1977ec681f3Smrgvoid 1987ec681f3Smrg${driver}_physical_device_get_supported_extensions(const struct ${driver}_physical_device *device, 1997ec681f3Smrg struct vk_device_extension_table *extensions) 2007ec681f3Smrg{ 2017ec681f3Smrg *extensions = (struct vk_device_extension_table) { 2027ec681f3Smrg%for ext in device_extensions: 2037ec681f3Smrg .${ext.name[3:]} = ${ext.enable}, 2047ec681f3Smrg%endfor 2057ec681f3Smrg }; 2067ec681f3Smrg} 2077ec681f3Smrg%endif 2087ec681f3Smrg""") 2097ec681f3Smrg 2107ec681f3Smrgdef gen_extensions(driver, xml_files, api_versions, max_api_version, 2117ec681f3Smrg extensions, out_c, out_h, includes = []): 2127ec681f3Smrg platform_defines = [] 2137ec681f3Smrg for filename in xml_files: 2147ec681f3Smrg init_exts_from_xml(filename, extensions, platform_defines) 2157ec681f3Smrg 2167ec681f3Smrg for ext in extensions: 2177ec681f3Smrg assert ext.type == 'instance' or ext.type == 'device' 2187ec681f3Smrg 2197ec681f3Smrg template_env = { 2207ec681f3Smrg 'driver': driver, 2217ec681f3Smrg 'API_VERSIONS': api_versions, 2227ec681f3Smrg 'MAX_API_VERSION': max_api_version, 2237ec681f3Smrg 'instance_extensions': [e for e in extensions if e.type == 'instance'], 2247ec681f3Smrg 'device_extensions': [e for e in extensions if e.type == 'device'], 2257ec681f3Smrg 'platform_defines': platform_defines, 2267ec681f3Smrg 'includes': includes, 2277ec681f3Smrg } 2287ec681f3Smrg 2297ec681f3Smrg if out_h: 2307ec681f3Smrg with open(out_h, 'w') as f: 2317ec681f3Smrg f.write(_TEMPLATE_H.render(**template_env)) 2327ec681f3Smrg 2337ec681f3Smrg if out_c: 2347ec681f3Smrg with open(out_c, 'w') as f: 2357ec681f3Smrg f.write(_TEMPLATE_C.render(**template_env)) 2367ec681f3Smrg 2377ec681f3Smrg 2387ec681f3Smrgif __name__ == '__main__': 2397ec681f3Smrg parser = argparse.ArgumentParser() 2407ec681f3Smrg parser.add_argument('--out-c', help='Output C file.') 2417ec681f3Smrg parser.add_argument('--out-h', help='Output H file.') 2427ec681f3Smrg parser.add_argument('--xml', 2437ec681f3Smrg help='Vulkan API XML file.', 2447ec681f3Smrg required=True, 2457ec681f3Smrg action='append', 2467ec681f3Smrg dest='xml_files') 2477ec681f3Smrg args = parser.parse_args() 2487ec681f3Smrg 2497ec681f3Smrg extensions = [] 2507ec681f3Smrg for filename in args.xml_files: 2517ec681f3Smrg extensions += get_all_exts_from_xml(filename) 2527ec681f3Smrg 2537ec681f3Smrg gen_extensions('vk', args.xml_files, None, None, 2547ec681f3Smrg extensions, args.out_c, args.out_h, []) 255