vk/device: Move device enumeration to vkEnumeratePhysicalDevices()
authorChad Versace <chad.versace@intel.com>
Thu, 9 Jul 2015 22:38:58 +0000 (15:38 -0700)
committerChad Versace <chad.versace@intel.com>
Thu, 9 Jul 2015 22:41:17 +0000 (15:41 -0700)
Don't enumerate devices in vkCreateInstance(). That's where global,
device-independent initialization should happen. Move device enumeration
to the more logical location, vkEnumeratePhysicalDevices().

src/vulkan/device.c

index ca8fd843f524aae69f91c9dcc7d31866f2204e51..bbe4ff1c87e788e476a2db10602c4f80df451d47 100644 (file)
@@ -121,7 +121,6 @@ VkResult anv_CreateInstance(
    struct anv_instance *instance;
    const VkAllocCallbacks *alloc_callbacks = &default_alloc_callbacks;
    void *user_data = NULL;
-   VkResult result;
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
 
@@ -138,15 +137,8 @@ VkResult anv_CreateInstance(
    instance->pfnAlloc = alloc_callbacks->pfnAlloc;
    instance->pfnFree = alloc_callbacks->pfnFree;
    instance->apiVersion = pCreateInfo->pAppInfo->apiVersion;
-
    instance->physicalDeviceCount = 0;
-   result = fill_physical_device(&instance->physicalDevice,
-                                 instance, "/dev/dri/renderD128");
-
-   if (result != VK_SUCCESS)
-      return result;
 
-   instance->physicalDeviceCount++;
    *pInstance = (VkInstance) instance;
 
    return VK_SUCCESS;
@@ -168,6 +160,16 @@ VkResult anv_EnumeratePhysicalDevices(
     VkPhysicalDevice*                           pPhysicalDevices)
 {
    struct anv_instance *instance = (struct anv_instance *) _instance;
+   VkResult result;
+
+   if (instance->physicalDeviceCount == 0) {
+      result = fill_physical_device(&instance->physicalDevice,
+                                    instance, "/dev/dri/renderD128");
+      if (result != VK_SUCCESS)
+         return result;
+
+      instance->physicalDeviceCount++;
+   }
 
    if (*pPhysicalDeviceCount >= 1)
       pPhysicalDevices[0] = (VkPhysicalDevice) &instance->physicalDevice;