summaryrefslogtreecommitdiffstats
path: root/src/intel/vulkan/anv_extensions.py
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-07-13 22:50:30 -0700
committerJason Ekstrand <[email protected]>2017-08-01 11:12:41 -0700
commitd62063ce316a86e3e091a392b42261138524a1a0 (patch)
treec570506616c45afaa909c489c62fe66f5620f16f /src/intel/vulkan/anv_extensions.py
parentddc86c1d0e56e2f16bf37cd378656f459fd15622 (diff)
anv: Autogenerate extension query and lookup
As time goes on, extension advertising is going to get more complex. Today, we either implement an extension or we don't. However, in the future, whether or not we advertise an extension will depend on kernel or hardware features. This commit introduces a python codegen framework that generates the anv_EnumerateFooExtensionProperties functions as well as a pair of anv_foo_extension_supported functions for querying for the support of a given extension string. Each extension has an "enable" predicate that is any valid C expression. For device extensions, the physical device is available as "device" so the expression could be something such as "device->has_kernel_feature". For instance extensions, the only option is VK_USE_PLATFORM defines. This mechanism also means that we have a single one-line-per-entry table for all extension declarations instead of the two tables we had in anv_device.c and the one we had in anv_entrypoints_gen.py. The Python code is smart and uses the XML to determine whether an extension is an instance extension or device extension. Reviewed-by: Emil Velikov <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]>
Diffstat (limited to 'src/intel/vulkan/anv_extensions.py')
-rw-r--r--src/intel/vulkan/anv_extensions.py118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py
index f325fe84da8..005a514eca8 100644
--- a/src/intel/vulkan/anv_extensions.py
+++ b/src/intel/vulkan/anv_extensions.py
@@ -63,3 +63,121 @@ EXTENSIONS = [
Extension('VK_KHR_xlib_surface', 6, 'VK_USE_PLATFORM_XLIB_KHR'),
Extension('VK_KHX_multiview', 1, True),
]
+
+def init_exts_from_xml(xml):
+ """ Walk the Vulkan XML and fill out extra extension information. """
+
+ xml = et.parse(xml)
+
+ ext_name_map = {}
+ for ext in EXTENSIONS:
+ ext_name_map[ext.name] = ext
+
+ for ext_elem in xml.findall('.extensions/extension'):
+ ext_name = ext_elem.attrib['name']
+ if ext_name not in ext_name_map:
+ continue
+ ext = ext_name_map[ext_name]
+
+ ext.type = ext_elem.attrib['type']
+
+ for ext in EXTENSIONS:
+ assert ext.type == 'instance' or ext.type == 'device'
+
+TEMPLATE = Template(COPYRIGHT + """
+#include "anv_private.h"
+
+#include "vk_util.h"
+
+/* Convert the VK_USE_PLATFORM_* defines to booleans */
+%for platform in ['ANDROID', 'WAYLAND', 'XCB', 'XLIB']:
+#ifdef VK_USE_PLATFORM_${platform}_KHR
+# undef VK_USE_PLATFORM_${platform}_KHR
+# define VK_USE_PLATFORM_${platform}_KHR true
+#else
+# define VK_USE_PLATFORM_${platform}_KHR false
+#endif
+%endfor
+
+bool
+anv_instance_extension_supported(const char *name)
+{
+%for ext in instance_extensions:
+ if (strcmp(name, "${ext.name}") == 0)
+ return ${ext.enable};
+%endfor
+ return false;
+}
+
+VkResult anv_EnumerateInstanceExtensionProperties(
+ const char* pLayerName,
+ uint32_t* pPropertyCount,
+ VkExtensionProperties* pProperties)
+{
+ VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
+
+%for ext in instance_extensions:
+ if (${ext.enable}) {
+ vk_outarray_append(&out, prop) {
+ *prop = (VkExtensionProperties) {
+ .extensionName = "${ext.name}",
+ .specVersion = ${ext.ext_version},
+ };
+ }
+ }
+%endfor
+
+ return vk_outarray_status(&out);
+}
+
+bool
+anv_physical_device_extension_supported(struct anv_physical_device *device,
+ const char *name)
+{
+%for ext in device_extensions:
+ if (strcmp(name, "${ext.name}") == 0)
+ return ${ext.enable};
+%endfor
+ return false;
+}
+
+VkResult anv_EnumerateDeviceExtensionProperties(
+ VkPhysicalDevice physicalDevice,
+ const char* pLayerName,
+ uint32_t* pPropertyCount,
+ VkExtensionProperties* pProperties)
+{
+ ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+ VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
+ (void)device;
+
+%for ext in device_extensions:
+ if (${ext.enable}) {
+ vk_outarray_append(&out, prop) {
+ *prop = (VkExtensionProperties) {
+ .extensionName = "${ext.name}",
+ .specVersion = ${ext.ext_version},
+ };
+ }
+ }
+%endfor
+
+ return vk_outarray_status(&out);
+}
+""")
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--out', help='Output C file.', required=True)
+ parser.add_argument('--xml', help='Vulkan API XML file.', required=True)
+ args = parser.parse_args()
+
+ init_exts_from_xml(args.xml)
+
+ template_env = {
+ 'instance_extensions': [e for e in EXTENSIONS if e.type == 'instance'],
+ 'device_extensions': [e for e in EXTENSIONS if e.type == 'device'],
+ }
+
+ with open(args.out, 'w') as f:
+ f.write(TEMPLATE.render(**template_env))