Skip to content

Commit

Permalink
Log when Filter Env-Vars act when settings file is active
Browse files Browse the repository at this point in the history
The logging to indicate that VK_LOADER_LAYERS_ENABLE and VK_LOADER_LAYERS_DISABLE
turned on/off layers was not occuring when the settings file was active. This
is due to layer enablement being done in `enable_correct_layers_from_settings()`,
a newer function. which lacked the log functions.
This commit rectifies the lack of logging in the new function.
  • Loading branch information
charles-lunarg committed Nov 21, 2024
1 parent 73ea419 commit 63dcb0a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions loader/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ VkResult enable_correct_layers_from_settings(const struct loader_instance* inst,
bool enable_layer = false;
struct loader_layer_properties* props = &instance_layers->list[i];

// Skip the sentinel unordered layer location
if (props->settings_control_value == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
continue;
}

// Do not enable the layer if the settings have it set as off
if (props->settings_control_value == LOADER_SETTINGS_LAYER_CONTROL_OFF) {
continue;
Expand All @@ -780,13 +785,20 @@ VkResult enable_correct_layers_from_settings(const struct loader_instance* inst,
if ((filters->disable_filter.disable_all || filters->disable_filter.disable_all_implicit ||
check_name_matches_filter_environment_var(props->info.layerName, &filters->disable_filter.additional_filters)) &&
!check_name_matches_filter_environment_var(props->info.layerName, &filters->allow_filter)) {
// Report a message that we've forced off a layer if it would have been enabled normally.
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
"Layer \"%s\" forced disabled because name matches filter of env var \'%s\'.", props->info.layerName,
VK_LAYERS_DISABLE_ENV_VAR);

continue;
}
}
// Check the enable filter
if (!enable_layer && check_name_matches_filter_environment_var(props->info.layerName, &filters->enable_filter)) {
enable_layer = true;
props->enabled_by_what = ENABLED_BY_WHAT_VK_LOADER_LAYERS_ENABLE;
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
"Layer \"%s\" forced enabled due to env var \'%s\'.", props->info.layerName, VK_LAYERS_ENABLE_ENV_VAR);
}

// First look for the old-fashion layers forced on with VK_INSTANCE_LAYERS
Expand Down
24 changes: 24 additions & 0 deletions tests/loader_settings_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2910,7 +2910,10 @@ TEST(SettingsFile, EnvVarsWorkTogether) {
EXPECT_TRUE(string_eq(layers.at(1).layerName, regular_explicit_layer));
EXPECT_TRUE(string_eq(layers.at(2).layerName, regular_explicit_layer_settings_file_set_on));
EXPECT_TRUE(string_eq(layers.at(3).layerName, env_var_implicit_layer));
EXPECT_TRUE(env.platform_shim->find_in_log(
"env var 'VK_INSTANCE_LAYERS' defined and adding layers: VK_LAYER_regular_explicit_layer"));
}
env.platform_shim->clear_logs();
{ // VK_LOADER_LAYERS_ENABLE
EnvVarWrapper env_var_enable{"VK_LOADER_LAYERS_ENABLE", regular_explicit_layer};
InstWrapper inst{env.vulkan_functions};
Expand All @@ -2920,14 +2923,22 @@ TEST(SettingsFile, EnvVarsWorkTogether) {
EXPECT_TRUE(string_eq(layers.at(1).layerName, regular_explicit_layer));
EXPECT_TRUE(string_eq(layers.at(2).layerName, regular_explicit_layer_settings_file_set_on));
EXPECT_TRUE(string_eq(layers.at(3).layerName, env_var_implicit_layer));
EXPECT_TRUE(env.platform_shim->find_in_log(
"Layer \"VK_LAYER_regular_explicit_layer\" forced enabled due to env var 'VK_LOADER_LAYERS_ENABLE'"));
}
env.platform_shim->clear_logs();
{ // VK_LOADER_LAYERS_DISABLE
EnvVarWrapper env_var_disable{"VK_LOADER_LAYERS_DISABLE", "~all~"}; // ignored by settings file
InstWrapper inst{env.vulkan_functions};
inst.CheckCreate();
auto layers = inst.GetActiveLayers(inst.GetPhysDev(), 1);
EXPECT_TRUE(string_eq(layers.at(0).layerName, regular_explicit_layer_settings_file_set_on));
EXPECT_TRUE(
env.platform_shim->find_in_log("Layer \"VK_LAYER_env_var_implicit_layer\" forced disabled because name matches filter "
"of env var 'VK_LOADER_LAYERS_DISABLE'"));
}
env.platform_shim->clear_logs();

{ // VK_LOADER_LAYERS_ALLOW
EnvVarWrapper env_var_allow{"VK_LOADER_LAYERS_ALLOW", regular_implicit_layer};
// Allow only makes sense when the disable env-var is also set
Expand All @@ -2939,7 +2950,13 @@ TEST(SettingsFile, EnvVarsWorkTogether) {
// The regular_implicit_layer is set to "auto" so is affected by environment variables
EXPECT_TRUE(string_eq(layers.at(0).layerName, regular_implicit_layer));
EXPECT_TRUE(string_eq(layers.at(1).layerName, regular_explicit_layer_settings_file_set_on));

EXPECT_TRUE(
env.platform_shim->find_in_log("Layer \"VK_LAYER_env_var_implicit_layer\" forced disabled because name matches filter "
"of env var 'VK_LOADER_LAYERS_DISABLE'"));
}
env.platform_shim->clear_logs();

{ // VK_LAYER_PATH
// VK_LAYER_PATH is set by add_explicit_layer()
InstWrapper inst{env.vulkan_functions};
Expand All @@ -2950,7 +2967,9 @@ TEST(SettingsFile, EnvVarsWorkTogether) {
EXPECT_TRUE(string_eq(layers.at(1).layerName, regular_explicit_layer_settings_file_set_on));
EXPECT_TRUE(string_eq(layers.at(2).layerName, env_var_implicit_layer));
EXPECT_TRUE(string_eq(layers.at(3).layerName, env_var_explicit_layer));
EXPECT_TRUE(env.platform_shim->find_in_log("Insert instance layer \"VK_LAYER_env_var_explicit_layer\""));
}
env.platform_shim->clear_logs();
{ // VK_IMPLICIT_LAYER_PATH
// VK_IMPLICIT_LAYER_PATH is set by add_implicit_layer()
InstWrapper inst{env.vulkan_functions};
Expand All @@ -2959,7 +2978,9 @@ TEST(SettingsFile, EnvVarsWorkTogether) {
EXPECT_TRUE(string_eq(layers.at(0).layerName, regular_implicit_layer));
EXPECT_TRUE(string_eq(layers.at(1).layerName, regular_explicit_layer_settings_file_set_on));
EXPECT_TRUE(string_eq(layers.at(2).layerName, env_var_implicit_layer));
EXPECT_TRUE(env.platform_shim->find_in_log("Insert instance layer \"VK_LAYER_env_var_implicit_layer\""));
}
env.platform_shim->clear_logs();
{ // VK_ADD_LAYER_PATH
// VK_ADD_LAYER_PATH is set by add_explicit_layer(), but we need to disable VK_LAYER_PATH
// since VK_LAYER_PATH overrides VK_ADD_LAYER_PATH
Expand All @@ -2973,7 +2994,9 @@ TEST(SettingsFile, EnvVarsWorkTogether) {
EXPECT_TRUE(string_eq(layers.at(1).layerName, regular_explicit_layer_settings_file_set_on));
EXPECT_TRUE(string_eq(layers.at(2).layerName, env_var_implicit_layer));
EXPECT_TRUE(string_eq(layers.at(3).layerName, add_env_var_explicit_layer));
EXPECT_TRUE(env.platform_shim->find_in_log("Insert instance layer \"VK_LAYER_add_env_var_explicit_layer\""));
}
env.platform_shim->clear_logs();
{ // VK_ADD_IMPLICIT_LAYER_PATH
// VK_ADD_IMPLICIT_LAYER_PATH is set by add_explicit_layer(), but we need to disable VK_LAYER_PATH
// since VK_IMPLICIT_LAYER_PATH overrides VK_ADD_IMPLICIT_LAYER_PATH
Expand All @@ -2985,5 +3008,6 @@ TEST(SettingsFile, EnvVarsWorkTogether) {
EXPECT_TRUE(string_eq(layers.at(0).layerName, regular_implicit_layer));
EXPECT_TRUE(string_eq(layers.at(1).layerName, regular_explicit_layer_settings_file_set_on));
EXPECT_TRUE(string_eq(layers.at(2).layerName, add_env_var_implicit_layer));
EXPECT_TRUE(env.platform_shim->find_in_log("Insert instance layer \"VK_LAYER_add_env_var_implicit_layer\""));
}
}

0 comments on commit 63dcb0a

Please sign in to comment.