• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1COPYRIGHT = """\
2/*
3 * Copyright 2017 Intel Corporation
4 *
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:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
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.
24 */
25"""
26
27import xml.etree.ElementTree as et
28
29from mako.template import Template
30
31from vk_extensions import *
32
33_TEMPLATE_H = Template(COPYRIGHT + """
34
35#ifndef ${driver.upper()}_EXTENSIONS_H
36#define ${driver.upper()}_EXTENSIONS_H
37
38%for include in includes:
39#include "${include}"
40%endfor
41
42#define ${driver.upper()}_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
43
44extern const VkExtensionProperties ${driver}_instance_extensions[];
45
46struct ${driver}_instance_extension_table {
47   union {
48      bool extensions[${driver.upper()}_INSTANCE_EXTENSION_COUNT];
49      struct {
50%for ext in instance_extensions:
51         bool ${ext.name[3:]};
52%endfor
53      };
54   };
55};
56
57extern const struct ${driver}_instance_extension_table ${driver}_instance_extensions_supported;
58
59
60#define ${driver.upper()}_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
61
62extern const VkExtensionProperties ${driver}_device_extensions[];
63
64struct ${driver}_device_extension_table {
65   union {
66      bool extensions[${driver.upper()}_DEVICE_EXTENSION_COUNT];
67      struct {
68%for ext in device_extensions:
69        bool ${ext.name[3:]};
70%endfor
71      };
72   };
73};
74
75struct ${driver}_physical_device;
76
77void
78${driver}_physical_device_get_supported_extensions(const struct ${driver}_physical_device *device,
79                                             struct ${driver}_device_extension_table *extensions);
80
81#endif /* ${driver.upper()}_EXTENSIONS_H */
82""")
83
84_TEMPLATE_C = Template(COPYRIGHT + """
85#include "${driver}_private.h"
86
87#include "vk_util.h"
88
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
94#else
95#   define ${platform_define} false
96#endif
97%endfor
98
99/* And ANDROID too */
100#ifdef ANDROID
101#   undef ANDROID
102#   define ANDROID true
103#else
104#   define ANDROID false
105#   define ANDROID_API_LEVEL 0
106#endif
107
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)
112
113static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()};
114
115VkResult ${driver}_EnumerateInstanceVersion(
116    uint32_t*                                   pApiVersion)
117{
118    *pApiVersion = MAX_API_VERSION;
119    return VK_SUCCESS;
120}
121
122const VkExtensionProperties ${driver}_instance_extensions[${driver.upper()}_INSTANCE_EXTENSION_COUNT] = {
123%for ext in instance_extensions:
124   {"${ext.name}", ${ext.ext_version}},
125%endfor
126};
127
128const 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)},
131%endfor
132};
133
134uint32_t
135${driver}_physical_device_api_version(struct ${driver}_physical_device *device)
136{
137    uint32_t version = 0;
138
139    uint32_t override = vk_get_version_override();
140    if (override)
141        return MIN2(override, MAX_API_VERSION);
142
143%for version in API_VERSIONS:
144    if (!(${version.enable}))
145        return version;
146    version = ${version.version.c_vk_version()};
147
148%endfor
149    return version;
150}
151
152const VkExtensionProperties ${driver}_device_extensions[${driver.upper()}_DEVICE_EXTENSION_COUNT] = {
153%for ext in device_extensions:
154   {"${ext.name}", ${ext.ext_version}},
155%endfor
156};
157
158void
159${driver}_physical_device_get_supported_extensions(const struct ${driver}_physical_device *device,
160                                                   struct ${driver}_device_extension_table *extensions)
161{
162   *extensions = (struct ${driver}_device_extension_table) {
163%for ext in device_extensions:
164      .${ext.name[3:]} = ${get_extension_condition(ext.name, ext.enable)},
165%endfor
166   };
167}
168""")
169
170def 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)
174
175    for ext in extensions:
176        assert ext.type == 'instance' or ext.type == 'device'
177
178    template_env = {
179        'driver': driver,
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,
187    }
188
189    if out_h:
190        with open(out_h, 'w') as f:
191            f.write(_TEMPLATE_H.render(**template_env))
192
193    if out_c:
194        with open(out_c, 'w') as f:
195            f.write(_TEMPLATE_C.render(**template_env))
196