radv: Put supported extensions in a struct.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sat, 10 Feb 2018 20:43:55 +0000 (21:43 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Thu, 22 Feb 2018 23:39:02 +0000 (00:39 +0100)
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/meson.build
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_extensions.py
src/amd/vulkan/radv_private.h

index 0a7b7c0bf3c8a55ca4e92d3ece399f7251e7879a..98051560a5204cf20d061eb8ae3c8f6951a3e555 100644 (file)
@@ -32,9 +32,10 @@ radv_entrypoints = custom_target(
 radv_extensions_c = custom_target(
   'radv_extensions.c',
   input : ['radv_extensions.py', vk_api_xml, vk_android_native_buffer_xml],
-  output : ['radv_extensions.c'],
+  output : ['radv_extensions.c', 'radv_extensions.h'],
   command : [
-    prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@', '--out', '@OUTPUT@',
+    prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@', '--out-c', '@OUTPUT0@',
+    '--out-h', '@OUTPUT1@'
   ],
 )
 
index 98cfd9b58a91237dcf374c10a32ed2f317e33538..9ee8ae2beb08a23daaa5ce923a5b45edf92b5e0e 100644 (file)
@@ -303,6 +303,7 @@ radv_physical_device_init(struct radv_physical_device *device,
                                  device->rad_info.family == CHIP_RAVEN;
 
        radv_physical_device_init_mem_types(device);
+       radv_fill_device_extension_table(device, &device->supported_extensions);
 
        result = radv_init_wsi(device);
        if (result != VK_SUCCESS) {
@@ -2242,6 +2243,65 @@ VkResult radv_DeviceWaitIdle(
        return VK_SUCCESS;
 }
 
+bool
+radv_instance_extension_supported(const char *name)
+{
+       for (unsigned i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; ++i) {
+               if (strcmp(name, radv_instance_extensions[i].extensionName) == 0)
+                       return radv_supported_instance_extensions.extensions[i];
+       }
+       return false;
+}
+
+VkResult radv_EnumerateInstanceExtensionProperties(
+    const char*                                 pLayerName,
+    uint32_t*                                   pPropertyCount,
+    VkExtensionProperties*                      pProperties)
+{
+       VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
+
+       for (int i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; i++) {
+               if (radv_supported_instance_extensions.extensions[i]) {
+                       vk_outarray_append(&out, prop) {
+                               *prop = radv_instance_extensions[i];
+                       }
+               }
+       }
+
+       return vk_outarray_status(&out);
+}
+
+bool
+radv_physical_device_extension_supported(struct radv_physical_device *device,
+                                        const char *name)
+{
+       for (unsigned i = 0; i < RADV_DEVICE_EXTENSION_COUNT; ++i) {
+               if (strcmp(name, radv_device_extensions[i].extensionName) == 0)
+                       return device->supported_extensions.extensions[i];
+       }
+       return false;
+}
+
+VkResult radv_EnumerateDeviceExtensionProperties(
+    VkPhysicalDevice                            physicalDevice,
+    const char*                                 pLayerName,
+    uint32_t*                                   pPropertyCount,
+    VkExtensionProperties*                      pProperties)
+{
+       RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
+       VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
+
+       for (int i = 0; i < RADV_DEVICE_EXTENSION_COUNT; i++) {
+               if (device->supported_extensions.extensions[i]) {
+                       vk_outarray_append(&out, prop) {
+                               *prop = radv_device_extensions[i];
+                       }
+               }
+       }
+
+       return vk_outarray_status(&out);
+}
+
 PFN_vkVoidFunction radv_GetInstanceProcAddr(
        VkInstance                                  instance,
        const char*                                 pName)
index d761895d3a09a41a19302e8a50e17fab8a4a3113..ac6ec8744e0ec741b1b8fdf3aac28b4723a9dad2 100644 (file)
@@ -162,7 +162,50 @@ 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 RADV_EXTENSIONS_H
+#define RADV_EXTENSIONS_H
+
+enum {
+   RADV_INSTANCE_EXTENSION_COUNT = ${len(instance_extensions)},
+   RADV_DEVICE_EXTENSION_COUNT = ${len(device_extensions)},
+};
+
+struct radv_instance_extension_table {
+   union {
+      bool extensions[RADV_INSTANCE_EXTENSION_COUNT];
+      struct {
+%for ext in instance_extensions:
+        bool ${ext.name[3:]};
+%endfor
+      };
+   };
+};
+
+struct radv_device_extension_table {
+   union {
+      bool extensions[RADV_DEVICE_EXTENSION_COUNT];
+      struct {
+%for ext in device_extensions:
+        bool ${ext.name[3:]};
+%endfor
+      };
+   };
+};
+
+const VkExtensionProperties radv_instance_extensions[RADV_INSTANCE_EXTENSION_COUNT];
+const VkExtensionProperties radv_device_extensions[RADV_DEVICE_EXTENSION_COUNT];
+const struct radv_instance_extension_table radv_supported_instance_extensions;
+
+
+struct radv_physical_device;
+
+void radv_fill_device_extension_table(const struct radv_physical_device *device,
+                                      struct radv_device_extension_table* table);
+#endif
+""")
+
+_TEMPLATE_C = Template(COPYRIGHT + """
 #include "radv_private.h"
 
 #include "vk_util.h"
@@ -189,82 +232,43 @@ _TEMPLATE = Template(COPYRIGHT + """
                          VK_USE_PLATFORM_XCB_KHR || \\
                          VK_USE_PLATFORM_XLIB_KHR)
 
-bool
-radv_instance_extension_supported(const char *name)
-{
+const VkExtensionProperties radv_instance_extensions[RADV_INSTANCE_EXTENSION_COUNT] = {
 %for ext in instance_extensions:
-    if (strcmp(name, "${ext.name}") == 0)
-        return ${ext.enable};
+   {"${ext.name}", ${ext.ext_version}},
 %endfor
-    return false;
-}
+};
 
-VkResult radv_EnumerateInstanceExtensionProperties(
-    const char*                                 pLayerName,
-    uint32_t*                                   pPropertyCount,
-    VkExtensionProperties*                      pProperties)
-{
-    VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
+const VkExtensionProperties radv_device_extensions[RADV_DEVICE_EXTENSION_COUNT] = {
+%for ext in device_extensions:
+   {"${ext.name}", ${ext.ext_version}},
+%endfor
+};
 
+const struct radv_instance_extension_table radv_supported_instance_extensions = {
 %for ext in instance_extensions:
-    if (${ext.enable}) {
-        vk_outarray_append(&out, prop) {
-            *prop = (VkExtensionProperties) {
-                .extensionName = "${ext.name}",
-                .specVersion = ${ext.ext_version},
-            };
-        }
-    }
+   .${ext.name[3:]} = ${ext.enable},
 %endfor
+};
 
-    return vk_outarray_status(&out);
-}
-
-uint32_t
-radv_physical_device_api_version(struct radv_physical_device *dev)
-{
-    return ${MAX_API_VERSION.c_vk_version()};
-}
-
-bool
-radv_physical_device_extension_supported(struct radv_physical_device *device,
-                                        const char *name)
+void radv_fill_device_extension_table(const struct radv_physical_device *device,
+                                      struct radv_device_extension_table* table)
 {
 %for ext in device_extensions:
-    if (strcmp(name, "${ext.name}") == 0)
-        return ${ext.enable};
+   table->${ext.name[3:]} = ${ext.enable};
 %endfor
-    return false;
 }
 
-VkResult radv_EnumerateDeviceExtensionProperties(
-    VkPhysicalDevice                            physicalDevice,
-    const char*                                 pLayerName,
-    uint32_t*                                   pPropertyCount,
-    VkExtensionProperties*                      pProperties)
+uint32_t
+radv_physical_device_api_version(struct radv_physical_device *dev)
 {
-    RADV_FROM_HANDLE(radv_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);
+    return ${MAX_API_VERSION.c_vk_version()};
 }
 """)
 
 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.', required=True)
+    parser.add_argument('--out-h', help='Output H file.', required=True)
     parser.add_argument('--xml',
                         help='Vulkan API XML file.',
                         required=True,
@@ -284,5 +288,7 @@ 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))
+    with open(args.out_c, 'w') as f:
+        f.write(_TEMPLATE_C.render(**template_env))
+    with open(args.out_h, 'w') as f:
+        f.write(_TEMPLATE_H.render(**template_env))
index be9e8f4396455628f62282f35b67d099e0209dd0..335c8417e77134567c1c7b1f8372bd489036f6e7 100644 (file)
@@ -57,6 +57,7 @@
 #include "ac_gpu_info.h"
 #include "ac_surface.h"
 #include "radv_descriptor_set.h"
+#include "radv_extensions.h"
 
 #include <llvm-c/TargetMachine.h>
 
@@ -285,6 +286,8 @@ struct radv_physical_device {
 
        VkPhysicalDeviceMemoryProperties memory_properties;
        enum radv_mem_type mem_type_indices[RADV_MEM_TYPE_COUNT];
+
+       struct radv_device_extension_table supported_extensions;
 };
 
 struct radv_instance {