Revert "Don't load layer libraries in vkCreateDevice"
authorCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Wed, 12 Oct 2022 21:45:58 +0000 (15:45 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Wed, 12 Oct 2022 22:22:24 +0000 (16:22 -0600)
This reverts commit cd9b4afed4e556ac88a75371eb7283fed94ca3c6.

loader/loader.c

index ae819cef56bb903484e2cb29c46433254decbd8e..ed33af356c5624116af73dc589b89a20d5329e66 100644 (file)
@@ -1191,8 +1191,12 @@ void loader_destroy_logical_device(const struct loader_instance *inst, struct lo
     if (pAllocator) {
         dev->alloc_callbacks = *pAllocator;
     }
-    loader_destroy_layer_list(inst, dev, &dev->expanded_activated_layer_list);
-    loader_destroy_layer_list(inst, dev, &dev->app_activated_layer_list);
+    if (NULL != dev->expanded_activated_layer_list.list) {
+        loader_deactivate_layers(inst, dev, &dev->expanded_activated_layer_list);
+    }
+    if (NULL != dev->app_activated_layer_list.list) {
+        loader_destroy_layer_list(inst, dev, &dev->app_activated_layer_list);
+    }
     loader_device_heap_free(dev, dev);
 }
 
@@ -3981,7 +3985,8 @@ struct loader_instance *loader_get_instance(const VkInstance instance) {
     return ptr_instance;
 }
 
-static loader_platform_dl_handle loader_open_layer_file(const struct loader_instance *inst, struct loader_layer_properties *prop) {
+static loader_platform_dl_handle loader_open_layer_file(const struct loader_instance *inst, const char *chain_type,
+                                                        struct loader_layer_properties *prop) {
     if ((prop->lib_handle = loader_platform_open_library(prop->lib_name)) == NULL) {
         loader_handle_load_library_error(inst, prop->lib_name, &prop->lib_status);
     } else {
@@ -4374,7 +4379,7 @@ VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, c
                 continue;
             }
 
-            lib_handle = loader_open_layer_file(inst, layer_prop);
+            lib_handle = loader_open_layer_file(inst, "instance", layer_prop);
             if (!lib_handle) {
                 continue;
             }
@@ -4688,15 +4693,23 @@ VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCre
         chain_info.pNext = loader_create_info.pNext;
         loader_create_info.pNext = &chain_info;
 
+        bool done = false;
+
         // Create instance chain of enabled layers
         for (int32_t i = dev->expanded_activated_layer_list.count - 1; i >= 0; i--) {
             struct loader_layer_properties *layer_prop = &dev->expanded_activated_layer_list.list[i];
-            loader_platform_dl_handle lib_handle = layer_prop->lib_handle;
+            loader_platform_dl_handle lib_handle;
+
             // Skip it if a Layer with the same name has been already successfully activated
             if (loader_names_array_has_layer_property(&layer_prop->info, num_activated_layers, activated_layers)) {
                 continue;
             }
 
+            lib_handle = loader_open_layer_file(inst, "device", layer_prop);
+            if (!lib_handle || done) {
+                continue;
+            }
+
             // The Get*ProcAddr pointers will already be filled in if they were received from either the json file or the
             // version negotiation
             if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == NULL) {
@@ -4718,6 +4731,7 @@ VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCre
                 if (layerNextGDPA != NULL) {
                     *layerNextGDPA = nextGDPA;
                 }
+                done = true;
                 continue;
             }