anv: Use tables for device extension wrangling
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 17 Jan 2018 00:15:13 +0000 (16:15 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 23 Jan 2018 08:15:40 +0000 (00:15 -0800)
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 9fd324ba3510319ba5081ce8b8de6571a30ef61f..2abf73dd95ed457f6251b91359d34161844d5a36 100644 (file)
@@ -433,6 +433,9 @@ anv_physical_device_init(struct anv_physical_device *device,
       goto fail;
    }
 
+   anv_physical_device_get_supported_extensions(device,
+                                                &device->supported_extensions);
+
    device->local_fd = fd;
    return VK_SUCCESS;
 
@@ -1205,6 +1208,27 @@ anv_device_init_trivial_batch(struct anv_device *device)
    anv_gem_munmap(map, device->trivial_batch_bo.size);
 }
 
+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 (int i = 0; i < ANV_DEVICE_EXTENSION_COUNT; i++) {
+      if (device->supported_extensions.extensions[i]) {
+         vk_outarray_append(&out, prop) {
+            *prop = anv_device_extensions[i];
+         }
+      }
+   }
+
+   return vk_outarray_status(&out);
+}
+
 VkResult anv_CreateDevice(
     VkPhysicalDevice                            physicalDevice,
     const VkDeviceCreateInfo*                   pCreateInfo,
@@ -1218,8 +1242,17 @@ VkResult anv_CreateDevice(
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
 
    for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
-      const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
-      if (!anv_physical_device_extension_supported(physical_device, ext_name))
+      int idx;
+      for (idx = 0; idx < ANV_DEVICE_EXTENSION_COUNT; idx++) {
+         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
+                    anv_device_extensions[idx].extensionName) == 0)
+            break;
+      }
+
+      if (idx >= ANV_DEVICE_EXTENSION_COUNT)
+         return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
+
+      if (!physical_device->supported_extensions.extensions[idx])
          return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
    }
 
index b86d76326a42f1eaf7165b9649b71857f6072641..33827ecd01565ea5ded16419b69d2f17b827a659 100644 (file)
@@ -98,6 +98,12 @@ struct anv_device_extension_table {
    };
 };
 
+struct anv_physical_device;
+
+void
+anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
+                                             struct anv_device_extension_table *extensions);
+
 #endif /* ANV_EXTENSIONS_H */
 """)
 
@@ -152,39 +158,15 @@ const VkExtensionProperties anv_device_extensions[ANV_DEVICE_EXTENSION_COUNT] =
 %endfor
 };
 
-bool
-anv_physical_device_extension_supported(struct anv_physical_device *device,
-                                        const char *name)
+void
+anv_physical_device_get_supported_extensions(const struct anv_physical_device *device,
+                                             struct anv_device_extension_table *extensions)
 {
+   *extensions = (struct anv_device_extension_table) {
 %for ext in device_extensions:
-    if (strcmp(name, "${ext.name}") == 0)
-        return ${ext.enable};
+      .${ext.name[3:]} = ${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);
+   };
 }
 """)
 
index e4ffdf2845bf71cd736250c631d4a4bcdbe2a291..a1f34aa22db5d724c482ce07b86391275bff3a8c 100644 (file)
@@ -770,6 +770,8 @@ struct anv_physical_device {
     bool                                        has_syncobj;
     bool                                        has_syncobj_wait;
 
+    struct anv_device_extension_table           supported_extensions;
+
     uint32_t                                    eu_total;
     uint32_t                                    subslice_total;