Skip to content

Commit 6110fe1

Browse files
Only log after determining global stderr_log filters
This change prevents the loader from logging anything before determining if the loader settings file has stderr_log filters that should take precedence. Without the change, info about the loader version, branch, and the settings file itself could be printed depending on the value of VK_LOADER_DEBUG.
1 parent 30aa753 commit 6110fe1

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

loader/loader.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,8 @@ void loader_initialize(void) {
19751975

19761976
// initialize logging
19771977
loader_init_global_debug_level();
1978+
update_global_loader_settings();
1979+
19781980
#if defined(_WIN32)
19791981
windows_initialization();
19801982
#endif
@@ -1998,6 +2000,9 @@ void loader_initialize(void) {
19982000
#if defined(LOADER_USE_UNSAFE_FILE_SEARCH)
19992001
loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "Vulkan Loader: unsafe searching is enabled");
20002002
#endif
2003+
2004+
log_global_settings();
2005+
20012006
#if defined(_WIN32)
20022007
return TRUE;
20032008
#endif

loader/settings.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ void log_settings(const struct loader_instance* inst, loader_settings* settings)
305305
loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---------------------------------");
306306
}
307307

308+
void log_global_settings() {
309+
loader_platform_thread_lock_mutex(&global_loader_settings_lock);
310+
if (global_loader_settings.settings_active) {
311+
log_settings(NULL, &global_loader_settings);
312+
} else {
313+
loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0,
314+
"No valid vk_loader_settings.json file found, no loader settings will be active");
315+
}
316+
loader_platform_thread_unlock_mutex(&global_loader_settings_lock);
317+
}
318+
308319
// Loads the vk_loader_settings.json file
309320
// Returns VK_SUCCESS if it was found & was successfully parsed. Otherwise, it returns VK_ERROR_INITIALIZATION_FAILED if it
310321
// wasn't found or failed to parse, and returns VK_ERROR_OUT_OF_HOST_MEMORY if it was unable to allocate enough memory.
@@ -316,16 +327,12 @@ VkResult get_loader_settings(const struct loader_instance* inst, loader_settings
316327
#if defined(WIN32)
317328
res = windows_get_loader_settings_file_path(inst, &settings_file_path);
318329
if (res != VK_SUCCESS) {
319-
loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
320-
"No valid vk_loader_settings.json file found, no loader settings will be active");
321330
goto out;
322331
}
323332

324333
#elif COMMON_UNIX_PLATFORMS
325334
res = get_unix_settings_path(inst, &settings_file_path);
326335
if (res != VK_SUCCESS) {
327-
loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
328-
"No valid vk_loader_settings.json file found, no loader settings will be active");
329336
goto out;
330337
}
331338
#else
@@ -489,12 +496,16 @@ TEST_FUNCTION_EXPORT VkResult update_global_loader_settings(void) {
489496
loader_settings settings = {0};
490497
VkResult res = get_loader_settings(NULL, &settings);
491498
loader_platform_thread_lock_mutex(&global_loader_settings_lock);
492-
493-
free_loader_settings(NULL, &global_loader_settings);
494-
if (res == VK_SUCCESS) {
495-
if (!check_if_settings_are_equal(&settings, &global_loader_settings)) {
496-
log_settings(NULL, &settings);
497-
}
499+
if (res != VK_SUCCESS) {
500+
// If we failed to get the global loader settings file, unset the current loader settings
501+
free_loader_settings(NULL, &global_loader_settings);
502+
memset(&global_loader_settings, 0, sizeof(loader_settings));
503+
} else if (check_if_settings_are_equal(&settings, &global_loader_settings)) {
504+
// If we successfully got the new global loader settings, but is identical to old settings, return after cleaning up
505+
free_loader_settings(NULL, &settings);
506+
} else {
507+
// Replace the current global loader settings with the new ones, setting the debug level if there are any debug filters set
508+
free_loader_settings(NULL, &global_loader_settings);
498509

499510
memcpy(&global_loader_settings, &settings, sizeof(loader_settings));
500511
if (global_loader_settings.settings_active && global_loader_settings.debug_level > 0) {

loader/settings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ void free_loader_settings(const struct loader_instance* inst, loader_settings* l
8282

8383
// Log the settings to the console
8484
void log_settings(const struct loader_instance* inst, loader_settings* settings);
85+
void log_global_settings();
8586

86-
// Every global function needs to call this at startup to insure that
87+
// Every global function needs to call this at startup to insure that its up to date
8788
TEST_FUNCTION_EXPORT VkResult update_global_loader_settings(void);
8889

8990
// Needs to be called during startup -

loader/trampoline.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
544544
if (settings_file_res == VK_ERROR_OUT_OF_HOST_MEMORY) {
545545
res = settings_file_res;
546546
goto out;
547+
} else if (settings_file_res != VK_SUCCESS) {
548+
loader_log(ptr_instance, VULKAN_LOADER_INFO_BIT, 0,
549+
"No valid vk_loader_settings.json file found, no loader settings will be active");
547550
}
548551
if (ptr_instance->settings.settings_active) {
549552
log_settings(ptr_instance, &ptr_instance->settings);

0 commit comments

Comments
 (0)