Update more logging info for the Loader
authorMark Young <marky@lunarg.com>
Tue, 17 Aug 2021 02:01:25 +0000 (20:01 -0600)
committerMark Young <marky@lunarg.com>
Fri, 10 Sep 2021 19:57:32 +0000 (13:57 -0600)
Output more information to the "info" debug target when the loader loads
so we can determine more info about:
 - Where loader was loaded from (Windows)
 - What Git Branch was used to build it
 - What Git tags were most recent when it was built.
Also, add more detailed logging of implicit layers:
 - Log manifest file location
 - Layer library location
 - Type of layer (implicit/explicit)
 - Disable enum if layer is implicit

CMakeLists.txt
loader/CMakeLists.txt
loader/loader.c
loader/loader_common.h
loader/loader_windows.c

index c79a1c0697ceddee8aa079aa97340146fa65b90f..a8d04181bfe7bd4dda780404fa64ea998cfa9287 100644 (file)
@@ -89,6 +89,31 @@ if(APPLE)
     set(CMAKE_MACOSX_RPATH 1)
 endif()
 
+find_package (Git)
+if (GIT_FOUND)
+    execute_process(
+        COMMAND ${GIT_EXECUTABLE} describe --tags --always
+        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+        OUTPUT_VARIABLE GIT_TAG_INFO)
+    string(REGEX REPLACE "\n$" "" GIT_TAG_INFO "${GIT_TAG_INFO}")
+
+    file(READ ".git/HEAD" GIT_HEAD_REF_INFO)
+    if (GIT_HEAD_REF_INFO)
+        string(REGEX MATCH "ref: refs/heads/(.*)" _ ${GIT_HEAD_REF_INFO})
+        if (CMAKE_MATCH_1)
+            set(GIT_BRANCH_NAME ${CMAKE_MATCH_1})
+        else()
+            set(GIT_BRANCH_NAME ${GIT_HEAD_REF_INFO})
+        endif()
+        string(REGEX REPLACE "\n$" "" GIT_BRANCH_NAME "${GIT_BRANCH_NAME}")
+    else()
+        set(GIT_BRANCH_NAME "--unknown--")
+    endif()
+else()
+    set(GIT_BRANCH_NAME "--unknown--")
+    set(GIT_TAG_INFO "--unknown--")
+endif()
+
 if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
     # Windows: if install locations not set by user, set install prefix to "<build_dir>\install".
     set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
index 58260b608ed6832861cd16f6d4b6485a213f4fc4..20361b3a899d3fb56339829185f93f869e016f07 100644 (file)
@@ -70,8 +70,10 @@ else()
 endif()
 
 # DEBUG enables runtime loader ICD verification
-set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
+set(CMAKE_C_FLAGS_DEBUG
+        "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -DGIT_BRANCH_NAME=${GIT_BRANCH_NAME} -DGIT_TAG_INFO=${GIT_TAG_INFO}")
+set(CMAKE_CXX_FLAGS_DEBUG
+        "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -DGIT_BRANCH_NAME=${GIT_BRANCH_NAME} -DGIT_TAG_INFO=${GIT_TAG_INFO}")
 
 if(WIN32)
     if(MSVC)
index d8f8c2336ea4d57e4e92eb4d009abf9028a286a5..e3302003e4f91d38a86e5ce08df314f2311ca780 100644 (file)
 
 struct loader_struct loader = {0};
 
+struct activated_layer_info {
+    char *name;
+    char *manifest;
+    char *library;
+    bool is_implicit;
+    char *disable_env;
+} ;
+
 // thread safety lock for accessing global data structures such as "loader"
 // all entrypoints on the instance chain need to be locked except GPA
 // additionally CreateDevice and DestroyDevice needs to be locked
@@ -772,9 +780,10 @@ static bool loader_init_layer_list(const struct loader_instance *inst, struct lo
 }
 
 // Search the given array of layer names for an entry matching the given VkLayerProperties
-bool loader_names_array_has_layer_property(const VkLayerProperties *vk_layer_prop, uint32_t layer_names_count, char **layer_names) {
-    for (uint32_t i = 0; i < layer_names_count; i++) {
-        if (strcmp(vk_layer_prop->layerName, layer_names[i]) == 0) {
+bool loader_names_array_has_layer_property(const VkLayerProperties *vk_layer_prop, uint32_t layer_info_count,
+                                           struct activated_layer_info *layer_info) {
+    for (uint32_t i = 0; i < layer_info_count; i++) {
+        if (strcmp(vk_layer_prop->layerName, layer_info[i].name) == 0) {
             return true;
         }
     }
@@ -1487,6 +1496,17 @@ void loader_initialize(void) {
 #if defined(_WIN32)
     windows_initialization();
 #endif
+
+    loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "Vulkan Loader Version %d.%d.%d", VK_API_VERSION_MAJOR(VK_HEADER_VERSION_COMPLETE),
+               VK_API_VERSION_MINOR(VK_HEADER_VERSION_COMPLETE), VK_API_VERSION_PATCH(VK_HEADER_VERSION_COMPLETE));
+
+#if defined(GIT_BRANCH_NAME) && defined(GIT_TAG_INFO)
+#define LOADER_GIT_STRINGIFY(x) #x
+#define LOADER_GIT_TOSTRING(x) LOADER_GIT_STRINGIFY(x)
+    const char git_branch_name[] = LOADER_GIT_TOSTRING(GIT_BRANCH_NAME);
+    const char git_tag_info[] = LOADER_GIT_TOSTRING(GIT_TAG_INFO);
+    loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "[Git - Tag: %s, Branch/Commit: %s]", git_tag_info, git_branch_name);
+#endif
 }
 
 void loader_release() {
@@ -2068,6 +2088,7 @@ static VkResult loader_read_layer_json(const struct loader_instance *inst, struc
         strcpy(library_path_str, &temp[1]);
         cJSON_Free(inst, temp);
 
+        strncpy(props->manifest_file_name, filename, MAX_STRING_SIZE);
         char *fullpath = props->lib_name;
         char *rel_base;
         if (NULL != library_path_str) {
@@ -4715,8 +4736,8 @@ VKAPI_ATTR void VKAPI_CALL loader_layer_destroy_device(VkDevice device, const Vk
 // cache those VkInstance objects for future use.
 VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
                                       struct loader_instance *inst, VkInstance *created_instance) {
-    uint32_t activated_layers = 0;
-    char **activated_layer_names = NULL;
+    uint32_t num_activated_layers = 0;
+    struct activated_layer_info* activated_layers = NULL;
     VkLayerInstanceCreateInfo chain_info;
     VkLayerInstanceLink *layer_instance_link_info = NULL;
     VkInstanceCreateInfo loader_create_info;
@@ -4744,10 +4765,10 @@ VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, c
             return VK_ERROR_OUT_OF_HOST_MEMORY;
         }
 
-        activated_layer_names = loader_stack_alloc(sizeof(char *) * inst->expanded_activated_layer_list.count);
-        if (!activated_layer_names) {
+        activated_layers = loader_stack_alloc(sizeof(struct activated_layer_info) * inst->expanded_activated_layer_list.count);
+        if (!activated_layers) {
             loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
-                       "loader_create_instance_chain: Failed to alloc activated layer names array");
+                       "loader_create_instance_chain: Failed to alloc activated layer storage array");
             return VK_ERROR_OUT_OF_HOST_MEMORY;
         }
 
@@ -4757,7 +4778,7 @@ VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, c
             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, activated_layers, activated_layer_names)) {
+            if (loader_names_array_has_layer_property(&layer_prop->info, num_activated_layers, activated_layers)) {
                 continue;
             }
 
@@ -4829,9 +4850,9 @@ VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, c
                 }
             }
 
-            layer_instance_link_info[activated_layers].pNext = chain_info.u.pLayerInfo;
-            layer_instance_link_info[activated_layers].pfnNextGetInstanceProcAddr = next_gipa;
-            layer_instance_link_info[activated_layers].pfnNextGetPhysicalDeviceProcAddr = next_gpdpa;
+            layer_instance_link_info[num_activated_layers].pNext = chain_info.u.pLayerInfo;
+            layer_instance_link_info[num_activated_layers].pfnNextGetInstanceProcAddr = next_gipa;
+            layer_instance_link_info[num_activated_layers].pfnNextGetPhysicalDeviceProcAddr = next_gpdpa;
             next_gipa = cur_gipa;
             if (layer_prop->interface_version > 1 && cur_gpdpa != NULL) {
                 layer_prop->functions.get_physical_device_proc_addr = cur_gpdpa;
@@ -4844,14 +4865,20 @@ VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, c
                 layer_prop->functions.get_device_proc_addr = cur_gdpa;
             }
 
-            chain_info.u.pLayerInfo = &layer_instance_link_info[activated_layers];
+            chain_info.u.pLayerInfo = &layer_instance_link_info[num_activated_layers];
 
-            activated_layer_names[activated_layers] = layer_prop->info.layerName;
+            activated_layers[num_activated_layers].name = layer_prop->info.layerName;
+            activated_layers[num_activated_layers].manifest = layer_prop->manifest_file_name;
+            activated_layers[num_activated_layers].library = layer_prop->lib_name;
+            activated_layers[num_activated_layers].is_implicit = !(layer_prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER);
+            if (activated_layers[num_activated_layers].is_implicit) {
+                activated_layers[num_activated_layers].disable_env = layer_prop->disable_env_var.name;
+            }
 
             loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Insert instance layer %s (%s)",
                        layer_prop->info.layerName, layer_prop->lib_name);
 
-            activated_layers++;
+            num_activated_layers++;
         }
     }
 
@@ -4903,8 +4930,17 @@ VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, c
             loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "     ||");
             loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "   <Loader>");
             loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "     ||");
-            for (uint32_t cur_layer = 0; cur_layer < activated_layers; ++cur_layer) {
-                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "   %s", activated_layer_names[activated_layers - cur_layer - 1]);
+            for (uint32_t cur_layer = 0; cur_layer < num_activated_layers; ++cur_layer) {
+                uint32_t index = num_activated_layers - cur_layer - 1;
+                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "   %s", activated_layers[index].name);
+                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "           Type: %s",
+                           activated_layers[index].is_implicit ? "Implicit" : "Explicit");
+                if (activated_layers[index].is_implicit) {
+                    loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "               Disable Env Var:  %s",
+                               activated_layers[index].disable_env);
+                }
+                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "           Manifset: %s", activated_layers[index].manifest);
+                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "           Library:  %s", activated_layers[index].library);
                 loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "     ||");
             }
             loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "   <Implementations>\n");
@@ -4934,8 +4970,8 @@ VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCre
                                     const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst,
                                     struct loader_device *dev, PFN_vkGetInstanceProcAddr callingLayer,
                                     PFN_vkGetDeviceProcAddr *layerNextGDPA) {
-    uint32_t activated_layers = 0;
-    char **activated_layer_names = NULL;
+    uint32_t num_activated_layers = 0;
+    struct activated_layer_info* activated_layers = NULL;
     VkLayerDeviceLink *layer_device_link_info;
     VkLayerDeviceCreateInfo chain_info;
     VkDeviceCreateInfo loader_create_info;
@@ -4995,10 +5031,10 @@ VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCre
             return VK_ERROR_OUT_OF_HOST_MEMORY;
         }
 
-        activated_layer_names = loader_stack_alloc(sizeof(char *) * inst->expanded_activated_layer_list.count);
-        if (!activated_layer_names) {
+        activated_layers = loader_stack_alloc(sizeof(struct activated_layer_info) * inst->expanded_activated_layer_list.count);
+        if (!activated_layers) {
             loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
-                       "loader_create_instance_chain: Failed to alloc activated layer names array");
+                       "loader_create_device_chain: Failed to alloc activated layer storage array");
             return VK_ERROR_OUT_OF_HOST_MEMORY;
         }
 
@@ -5016,7 +5052,7 @@ VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCre
             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, activated_layers, activated_layer_names)) {
+            if (loader_names_array_has_layer_property(&layer_prop->info, num_activated_layers, activated_layers)) {
                 continue;
             }
 
@@ -5063,19 +5099,25 @@ VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCre
                 }
             }
 
-            layer_device_link_info[activated_layers].pNext = chain_info.u.pLayerInfo;
-            layer_device_link_info[activated_layers].pfnNextGetInstanceProcAddr = nextGIPA;
-            layer_device_link_info[activated_layers].pfnNextGetDeviceProcAddr = nextGDPA;
-            chain_info.u.pLayerInfo = &layer_device_link_info[activated_layers];
+            layer_device_link_info[num_activated_layers].pNext = chain_info.u.pLayerInfo;
+            layer_device_link_info[num_activated_layers].pfnNextGetInstanceProcAddr = nextGIPA;
+            layer_device_link_info[num_activated_layers].pfnNextGetDeviceProcAddr = nextGDPA;
+            chain_info.u.pLayerInfo = &layer_device_link_info[num_activated_layers];
             nextGIPA = fpGIPA;
             nextGDPA = fpGDPA;
 
-            activated_layer_names[activated_layers] = layer_prop->info.layerName;
+            activated_layers[num_activated_layers].name = layer_prop->info.layerName;
+            activated_layers[num_activated_layers].manifest = layer_prop->manifest_file_name;
+            activated_layers[num_activated_layers].library = layer_prop->lib_name;
+            activated_layers[num_activated_layers].is_implicit = !(layer_prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER);
+            if (activated_layers[num_activated_layers].is_implicit) {
+                activated_layers[num_activated_layers].disable_env = layer_prop->disable_env_var.name;
+            }
 
             loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Inserted device layer %s (%s)",
                        layer_prop->info.layerName, layer_prop->lib_name);
 
-            activated_layers++;
+            num_activated_layers++;
         }
     }
 
@@ -5097,8 +5139,17 @@ VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCre
             loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "     ||");
             loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "   <Loader>");
             loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "     ||");
-            for (uint32_t cur_layer = 0; cur_layer < activated_layers; ++cur_layer) {
-                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "   %s", activated_layer_names[activated_layers - cur_layer - 1]);
+            for (uint32_t cur_layer = 0; cur_layer < num_activated_layers; ++cur_layer) {
+                uint32_t index = num_activated_layers - cur_layer - 1;
+                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "   %s", activated_layers[index].name);
+                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "           Type: %s",
+                           activated_layers[index].is_implicit ? "Implicit" : "Explicit");
+                if (activated_layers[index].is_implicit) {
+                    loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "               Disable Env Var:  %s",
+                               activated_layers[index].disable_env);
+                }
+                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "           Manifset: %s", activated_layers[index].manifest);
+                loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "           Library:  %s", activated_layers[index].library);
                 loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "     ||");
             }
             loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "   <Device>\n");
index 5b9e25c3b40b6b8043de1d25f52e928c1f52ef62..783d63276317408b3696ec4718409d935ded5ba3 100644 (file)
@@ -108,6 +108,7 @@ struct loader_layer_properties {
     VkLayerProperties info;
     enum layer_type_flags type_flags;
     uint32_t interface_version;  // PFN_vkNegotiateLoaderLayerInterfaceVersion
+    char manifest_file_name[MAX_STRING_SIZE];
     char lib_name[MAX_STRING_SIZE];
     loader_platform_dl_handle lib_handle;
     struct loader_layer_functions functions;
index 374f61e2c78deda705b01c4030dc614a97bc2726..62f67f3237bb0087d28bfc357a2453cc182e4198 100644 (file)
@@ -59,6 +59,16 @@ typedef HRESULT(APIENTRY *PFN_CreateDXGIFactory1)(REFIID riid, void **ppFactory)
 static PFN_CreateDXGIFactory1 fpCreateDXGIFactory1;
 
 void windows_initialization(void) {
+    char dll_location[MAX_PATH];
+    HMODULE module_handle = NULL;
+
+    // Get a module handle to a static function inside of this source
+    if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+                          (LPCSTR)&loader_debug_init, &module_handle) != 0 &&
+        GetModuleFileName(module_handle, dll_location, sizeof(dll_location)) != 0) {
+        loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "Using Vulkan Loader %s", dll_location);
+    }
+
     // This is needed to ensure that newer APIs are available right away
     // and not after the first call that has been statically linked
     LoadLibrary("gdi32.dll");