anv/extensions: Generate a header file with extension tables
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 16 Jan 2018 22:23:29 +0000 (14:23 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 23 Jan 2018 08:15:40 +0000 (00:15 -0800)
This allows us better introspection into extensions.

Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
src/intel/Makefile.sources
src/intel/Makefile.vulkan.am
src/intel/vulkan/anv_extensions_gen.py
src/intel/vulkan/anv_private.h
src/intel/vulkan/meson.build

index 7f8379c66a197372f45e88f0a70c679129be6bff..9595bf4258242e15259d9c96723ee09f81e7038e 100644 (file)
@@ -249,7 +249,8 @@ VULKAN_GEM_STUB_FILES := \
 VULKAN_GENERATED_FILES := \
        vulkan/anv_entrypoints.c \
        vulkan/anv_entrypoints.h \
-       vulkan/anv_extensions.c
+       vulkan/anv_extensions.c \
+       vulkan/anv_extensions.h
 
 VULKAN_GENX_FILES := \
        vulkan/genX_blorp_exec.c \
index 3e385ffd03318d05beb84d368ff1ae6039554622..7823b608804690dbd6216c60c4875b2f83605102 100644 (file)
@@ -44,7 +44,17 @@ vulkan/anv_extensions.c: vulkan/anv_extensions_gen.py \
        $(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_extensions_gen.py \
                --xml $(vulkan_api_xml) \
                --xml $(vk_android_native_buffer_xml) \
-               --out $@
+               --out-c $@
+
+vulkan/anv_extensions.h: vulkan/anv_extensions_gen.py \
+                        vulkan/anv_extensions.py \
+                        $(vulkan_api_xml) \
+                        $(vk_android_native_buffer_xml)
+       $(MKDIR_GEN)
+       $(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_extensions_gen.py \
+               --xml $(vulkan_api_xml) \
+               --xml $(vk_android_native_buffer_xml) \
+               --out-h $@
 
 BUILT_SOURCES += $(VULKAN_GENERATED_FILES)
 CLEANFILES += \
index a1e868855bde7721c9238b4bb5e0adad6393caa1..dadf20a687e8b1d6e090d50dd83b1a05afc437fb 100644 (file)
@@ -58,7 +58,48 @@ def _init_exts_from_xml(xml):
         ext = ext_name_map[ext_name]
         ext.type = ext_elem.attrib['type']
 
-_TEMPLATE = Template(COPYRIGHT + """
+_TEMPLATE_H = Template(COPYRIGHT + """
+
+#ifndef ANV_EXTENSIONS_H
+#define ANV_EXTENSIONS_H
+
+#include "stdbool.h"
+
+#define ANV_INSTANCE_EXTENSION_COUNT ${len(instance_extensions)}
+
+extern const VkExtensionProperties anv_instance_extensions[];
+
+struct anv_instance_extension_table {
+   union {
+      bool extensions[ANV_INSTANCE_EXTENSION_COUNT];
+      struct {
+%for ext in instance_extensions:
+         bool ${ext.name[3:]};
+%endfor
+      };
+   };
+};
+
+
+#define ANV_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
+
+extern const VkExtensionProperties anv_device_extensions[];
+
+struct anv_device_extension_table {
+   union {
+      bool extensions[ANV_DEVICE_EXTENSION_COUNT];
+      struct {
+%for ext in device_extensions:
+        bool ${ext.name[3:]};
+%endfor
+      };
+   };
+};
+
+#endif /* ANV_EXTENSIONS_H */
+""")
+
+_TEMPLATE_C = Template(COPYRIGHT + """
 #include "anv_private.h"
 
 #include "vk_util.h"
@@ -85,6 +126,12 @@ _TEMPLATE = Template(COPYRIGHT + """
                          VK_USE_PLATFORM_XCB_KHR || \\
                          VK_USE_PLATFORM_XLIB_KHR)
 
+const VkExtensionProperties anv_instance_extensions[ANV_INSTANCE_EXTENSION_COUNT] = {
+%for ext in instance_extensions:
+   {"${ext.name}", ${ext.ext_version}},
+%endfor
+};
+
 bool
 anv_instance_extension_supported(const char *name)
 {
@@ -122,6 +169,12 @@ anv_physical_device_api_version(struct anv_physical_device *dev)
     return ${MAX_API_VERSION.c_vk_version()};
 }
 
+const VkExtensionProperties anv_device_extensions[ANV_DEVICE_EXTENSION_COUNT] = {
+%for ext in device_extensions:
+   {"${ext.name}", ${ext.ext_version}},
+%endfor
+};
+
 bool
 anv_physical_device_extension_supported(struct anv_physical_device *device,
                                         const char *name)
@@ -160,7 +213,8 @@ VkResult anv_EnumerateDeviceExtensionProperties(
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser()
-    parser.add_argument('--out', help='Output C file.', required=True)
+    parser.add_argument('--out-c', help='Output C file.')
+    parser.add_argument('--out-h', help='Output H file.')
     parser.add_argument('--xml',
                         help='Vulkan API XML file.',
                         required=True,
@@ -180,5 +234,10 @@ if __name__ == '__main__':
         'device_extensions': [e for e in EXTENSIONS if e.type == 'device'],
     }
 
-    with open(args.out, 'w') as f:
-        f.write(_TEMPLATE.render(**template_env))
+    if args.out_h:
+        with open(args.out_h, 'w') as f:
+            f.write(_TEMPLATE_H.render(**template_env))
+
+    if args.out_c:
+        with open(args.out_c, 'w') as f:
+            f.write(_TEMPLATE_C.render(**template_env))
index ed711e9434b9804fa2e9b7c9bb7c452eef12c9c1..d3953f10420d99bf855425604095ab9d2441243e 100644 (file)
@@ -72,6 +72,7 @@ struct gen_l3_config;
 #include <vulkan/vk_android_native_buffer.h>
 
 #include "anv_entrypoints.h"
+#include "anv_extensions.h"
 #include "isl/isl.h"
 
 #include "common/gen_debug.h"
index cbbd5677dcc4f82ae2bfb38fda6bd907e9194c74..69ec26e19b6895fca540196d9434861553eae43d 100644 (file)
@@ -37,7 +37,18 @@ anv_extensions_c = custom_target(
   output : 'anv_extensions.c',
   command : [
     prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@',
-    '--out', '@OUTPUT@',
+    '--out-c', '@OUTPUT@',
+  ],
+)
+
+anv_extensions_h = custom_target(
+  'anv_extensions.h',
+  input : ['anv_extensions_gen.py', vk_api_xml, vk_android_native_buffer_xml,
+           'anv_extensions.py'],
+  output : 'anv_extensions.h',
+  command : [
+    prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@',
+    '--out-h', '@OUTPUT@',
   ],
 )
 
@@ -162,7 +173,7 @@ endif
 
 libanv_common = static_library(
   'anv_common',
-  [libanv_files, anv_entrypoints, anv_extensions_c],
+  [libanv_files, anv_entrypoints, anv_extensions_c, anv_extensions_h],
   include_directories : [
     inc_common, inc_intel, inc_compiler, inc_drm_uapi, inc_vulkan_util,
     inc_vulkan_wsi,
@@ -173,7 +184,7 @@ libanv_common = static_library(
 
 libvulkan_intel = shared_library(
   'vulkan_intel',
-  [files('anv_gem.c'), block_entrypoints],
+  [files('anv_gem.c'), block_entrypoints, anv_extensions_h],
   include_directories : [
     inc_common, inc_intel, inc_compiler, inc_drm_uapi, inc_vulkan_util,
     inc_vulkan_wsi,
@@ -194,7 +205,7 @@ libvulkan_intel = shared_library(
 if with_tests
   libvulkan_intel_test = static_library(
     'vulkan_intel_test',
-    [files('anv_gem_stubs.c'), block_entrypoints],
+    [files('anv_gem_stubs.c'), block_entrypoints, anv_extensions_h],
     include_directories : [
       inc_common, inc_intel, inc_compiler, inc_drm_uapi, inc_vulkan_util,
       inc_vulkan_wsi,