vk/device: Don't allow device or instance creation with invalid extensions
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 17 Sep 2015 18:19:16 +0000 (11:19 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 18 Sep 2015 00:44:20 +0000 (17:44 -0700)
src/vulkan/anv_device.c

index cf93cd1a6ebcdf242a14c774e78a60f7db753cd7..a1c12e0dd173fe68b61929c3eb42de6f7feb6aa2 100644 (file)
@@ -110,6 +110,21 @@ static const VkAllocCallbacks default_alloc_callbacks = {
    .pfnFree = default_free
 };
 
+static const VkExtensionProperties global_extensions[] = {
+   {
+      .extName = "VK_WSI_swapchain",
+      .specVersion = 12
+   },
+};
+
+static const VkExtensionProperties device_extensions[] = {
+   {
+      .extName = "VK_WSI_device_swapchain",
+      .specVersion = 12
+   },
+};
+
+
 VkResult anv_CreateInstance(
     const VkInstanceCreateInfo*                 pCreateInfo,
     VkInstance*                                 pInstance)
@@ -120,6 +135,19 @@ VkResult anv_CreateInstance(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
 
+   for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
+      bool found = false;
+      for (uint32_t j = 0; j < ARRAY_SIZE(global_extensions); j++) {
+         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
+                    global_extensions[j].extName) == 0) {
+            found = true;
+            break;
+         }
+      }
+      if (!found)
+         return vk_error(VK_ERROR_INVALID_EXTENSION);
+   }
+
    if (pCreateInfo->pAllocCb) {
       alloc_callbacks = pCreateInfo->pAllocCb;
       user_data = pCreateInfo->pAllocCb->pUserData;
@@ -546,6 +574,19 @@ VkResult anv_CreateDevice(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO);
 
+   for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
+      bool found = false;
+      for (uint32_t j = 0; j < ARRAY_SIZE(device_extensions); j++) {
+         if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
+                    device_extensions[j].extName) == 0) {
+            found = true;
+            break;
+         }
+      }
+      if (!found)
+         return vk_error(VK_ERROR_INVALID_EXTENSION);
+   }
+
    anv_set_dispatch_gen(physical_device->info->gen);
 
    device = anv_instance_alloc(instance, sizeof(*device), 8,
@@ -636,13 +677,6 @@ VkResult anv_DestroyDevice(
    return VK_SUCCESS;
 }
 
-static const VkExtensionProperties global_extensions[] = {
-   {
-      .extName = "VK_WSI_swapchain",
-      .specVersion = 12
-   },
-};
-
 VkResult anv_GetGlobalExtensionProperties(
     const char*                                 pLayerName,
     uint32_t*                                   pCount,
@@ -661,13 +695,6 @@ VkResult anv_GetGlobalExtensionProperties(
    return VK_SUCCESS;
 }
 
-static const VkExtensionProperties device_extensions[] = {
-   {
-      .extName = "VK_WSI_device_swapchain",
-      .specVersion = 12
-   },
-};
-
 VkResult anv_GetPhysicalDeviceExtensionProperties(
     VkPhysicalDevice                            physicalDevice,
     const char*                                 pLayerName,