anv: Use tables for instance extension wrangling
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 16 Jan 2018 23:49:28 +0000 (15:49 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 23 Jan 2018 08:15:40 +0000 (00:15 -0800)
This lets us move a bunch of stuff out of codegen and back into
anv_device.c which is a bit nicer.

Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_extensions_gen.py
src/intel/vulkan/anv_private.h

index 777abd87578ab474c24a941444b7d74ec46f7d26..7835b8780b9e8390d84fb544835ea6e36e22de03 100644 (file)
@@ -476,6 +476,24 @@ static const VkAllocationCallbacks default_alloc = {
    .pfnFree = default_free_func,
 };
 
+VkResult anv_EnumerateInstanceExtensionProperties(
+    const char*                                 pLayerName,
+    uint32_t*                                   pPropertyCount,
+    VkExtensionProperties*                      pProperties)
+{
+   VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
+
+   for (int i = 0; i < ANV_INSTANCE_EXTENSION_COUNT; i++) {
+      if (anv_instance_extensions_supported.extensions[i]) {
+         vk_outarray_append(&out, prop) {
+            *prop = anv_instance_extensions[i];
+         }
+      }
+   }
+
+   return vk_outarray_status(&out);
+}
+
 VkResult anv_CreateInstance(
     const VkInstanceCreateInfo*                 pCreateInfo,
     const VkAllocationCallbacks*                pAllocator,
@@ -522,8 +540,17 @@ VkResult anv_CreateInstance(
    }
 
    for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
-      const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
-      if (!anv_instance_extension_supported(ext_name))
+      int idx;
+      for (idx = 0; idx < ANV_INSTANCE_EXTENSION_COUNT; idx++) {
+         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
+                    anv_instance_extensions[idx].extensionName) == 0)
+            break;
+      }
+
+      if (idx >= ANV_INSTANCE_EXTENSION_COUNT)
+         return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
+
+      if (!anv_instance_extensions_supported.extensions[idx])
          return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
    }
 
index dadf20a687e8b1d6e090d50dd83b1a05afc437fb..b86d76326a42f1eaf7165b9649b71857f6072641 100644 (file)
@@ -80,6 +80,8 @@ struct anv_instance_extension_table {
    };
 };
 
+extern const struct anv_instance_extension_table anv_instance_extensions_supported;
+
 
 #define ANV_DEVICE_EXTENSION_COUNT ${len(device_extensions)}
 
@@ -132,36 +134,11 @@ const VkExtensionProperties anv_instance_extensions[ANV_INSTANCE_EXTENSION_COUNT
 %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);
-
+const struct anv_instance_extension_table anv_instance_extensions_supported = {
 %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
 anv_physical_device_api_version(struct anv_physical_device *dev)
index d3953f10420d99bf855425604095ab9d2441243e..55417faceaae8ea849679ace787d39cb5b27e9b4 100644 (file)
@@ -803,7 +803,6 @@ struct anv_instance {
 VkResult anv_init_wsi(struct anv_physical_device *physical_device);
 void anv_finish_wsi(struct anv_physical_device *physical_device);
 
-bool anv_instance_extension_supported(const char *name);
 uint32_t anv_physical_device_api_version(struct anv_physical_device *dev);
 bool anv_physical_device_extension_supported(struct anv_physical_device *dev,
                                              const char *name);