From b5f6889648488d735e920a630917ffa17ff3691f Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 17 Sep 2015 11:19:16 -0700 Subject: [PATCH] vk/device: Don't allow device or instance creation with invalid extensions --- src/vulkan/anv_device.c | 55 ++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index cf93cd1a6eb..a1c12e0dd17 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -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, -- 2.30.2