Fix some issues when EnumerateAdapterPhysicalDevices is available
authorPiers Daniell <pdaniell@nvidia.com>
Wed, 7 Oct 2020 16:39:39 +0000 (10:39 -0600)
committerLenny Komow <lenny@lunarg.com>
Wed, 7 Oct 2020 20:41:11 +0000 (14:41 -0600)
1) Fix a memory leak with sorted_array[].physical_devices when EnumerateAdapterPhysicalDevices  returns an error. This fixes a failure with the "dEQP-VK.api.device_init.create_instance_device_intentional_alloc_fail" Vulkan CTS test.

2) Fix an issue with vkEnumeratePhysicalDeviceGroups() when fpCreateDXGIFactory1() fails, which will happen with Windows versions before version 10.

loader/loader.c

index 509f2f420655f5b99b2691f8e6d4fdacad851bd9..1eb7cbfa121784fa29c3e6708676e45b1b9dfa46 100644 (file)
@@ -7154,11 +7154,15 @@ VkResult ReadSortedPhysicalDevices(struct loader_instance *inst, struct LoaderSo
                 }
 
                 if (vkres != VK_SUCCESS) {
-                    loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Failed to convert DXGI adapter into Vulkan physical device");
-                    continue;
-                } else if (vkres == VK_ERROR_OUT_OF_HOST_MEMORY) {
-                    res = VK_ERROR_OUT_OF_HOST_MEMORY;
-                    goto out;
+                    loader_instance_heap_free(inst, sorted_array[*sorted_count].physical_devices);
+                    sorted_array[*sorted_count].physical_devices = NULL;
+                    if (vkres == VK_ERROR_OUT_OF_HOST_MEMORY) {
+                        res = VK_ERROR_OUT_OF_HOST_MEMORY;
+                        goto out;
+                    } else {
+                        loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Failed to convert DXGI adapter into Vulkan physical device");
+                        continue;
+                    }
                 }
                 inst->total_gpu_count += (sorted_array[*sorted_count].device_count = count);
                 sorted_array[*sorted_count].icd_index = icd_idx;
@@ -7981,7 +7985,7 @@ VkResult setupLoaderTermPhysDevGroups(struct loader_instance *inst) {
 
         // Check if this group can be sorted
 #if defined(VK_USE_PLATFORM_WIN32_KHR)
-        bool icd_sorted = icd_term->scanned_icd->EnumerateAdapterPhysicalDevices != NULL;
+        bool icd_sorted = sorted_count && (icd_term->scanned_icd->EnumerateAdapterPhysicalDevices != NULL);
 #else
         bool icd_sorted = false;
 #endif