diff --git a/vkconfig_core/configuration.cpp b/vkconfig_core/configuration.cpp index 7fb0acfb20..acd2998afa 100644 --- a/vkconfig_core/configuration.cpp +++ b/vkconfig_core/configuration.cpp @@ -79,10 +79,10 @@ static void AddApplicationEnabledParameters(std::vector& parameters) } } -Configuration Configuration::Create(const LayerManager& layers, const std::string& key) { +Configuration Configuration::Create(const LayerManager& layers, const std::string& configuration_key) { Configuration result; - result.key = key; + result.key = configuration_key; result.GatherParameters(layers); AddApplicationEnabledParameters(result.parameters); @@ -409,7 +409,7 @@ void Configuration::SwitchLayerVersion(const LayerManager& layers, const std::st const Layer* new_layer = layers.Find(layer_key, version); - parameter->api_version = version; + parameter->api_version = new_layer->api_version == version ? version : Version::LATEST; CollectDefaultSettingData(new_layer->settings, parameter->settings); } @@ -455,7 +455,9 @@ void Configuration::Reorder(const std::vector& layer_names) { for (std::size_t i = 0, n = layer_names.size(); i < n; ++i) { Parameter* parameter = this->Find(layer_names[i]); - assert(parameter != nullptr); + if (parameter == nullptr) { + continue; + } ordered_parameters.push_back(*parameter); } diff --git a/vkconfig_core/configuration.h b/vkconfig_core/configuration.h index b0c0dc97ec..ff876a18c0 100644 --- a/vkconfig_core/configuration.h +++ b/vkconfig_core/configuration.h @@ -34,7 +34,7 @@ class LayerManager; class Configuration { public: static Configuration CreateDisabled(const LayerManager& layers); - static Configuration Create(const LayerManager& layers, const std::string& layer_key); + static Configuration Create(const LayerManager& layers, const std::string& configuration_key); bool Load(const Path& full_path, const LayerManager& layers); bool Save(const Path& full_path, bool exporter = false) const; diff --git a/vkconfig_core/configuration_manager.cpp b/vkconfig_core/configuration_manager.cpp index d7365e096b..74507f29be 100644 --- a/vkconfig_core/configuration_manager.cpp +++ b/vkconfig_core/configuration_manager.cpp @@ -255,27 +255,40 @@ bool ConfigurationManager::HasActiveConfiguration() const { return false; } -Configuration &ConfigurationManager::CreateConfiguration(const LayerManager &layers, const std::string &configuration_name, - bool duplicate) { - Configuration *duplicate_configuration = this->FindConfiguration(configuration_name); +Configuration &ConfigurationManager::CreateConfiguration(const LayerManager &layers, const std::string &configuration_name) { + std::string configuration_key = MakeConfigurationName(available_configurations, configuration_name); - Configuration new_configuration = duplicate_configuration != nullptr && duplicate ? *duplicate_configuration : Configuration(); - new_configuration.key = MakeConfigurationName(available_configurations, configuration_name); + Configuration new_configuration = Configuration::Create(layers, configuration_key); - const Path &path(MakeConfigurationPath(new_configuration.key)); - new_configuration.Save(path); + this->available_configurations.push_back(new_configuration); + this->SortConfigurations(); + + this->GetActiveConfigurationInfo()->name = new_configuration.key; + + return *this->FindConfiguration(new_configuration.key); +} + +Configuration &ConfigurationManager::DuplicateConfiguration(const LayerManager &layers, const std::string &configuration_name) { + Configuration *source_configuration = this->FindConfiguration(configuration_name); + assert(source_configuration != nullptr); + + Configuration duplicated_configuration = *source_configuration; + duplicated_configuration.key = MakeConfigurationName(available_configurations, configuration_name); + + const Path &path = MakeConfigurationPath(duplicated_configuration.key); + duplicated_configuration.Save(path); // Reload from file to workaround the lack of SettingSet copy support - Configuration configuration; - const bool result = configuration.Load(path, layers); + Configuration reloaded_configuration; + const bool result = reloaded_configuration.Load(path, layers); assert(result); - this->available_configurations.push_back(configuration); - this->SortConfigurations(); + this->available_configurations.push_back(reloaded_configuration); + this->SortConfigurations(); // invalidated all pointers to configuration object - this->GetActiveConfigurationInfo()->name = configuration.key; + this->GetActiveConfigurationInfo()->name = reloaded_configuration.key; - return *this->FindConfiguration(configuration.key); + return *this->FindConfiguration(reloaded_configuration.key); } bool ConfigurationManager::HasFile(const Configuration &configuration) const { diff --git a/vkconfig_core/configuration_manager.h b/vkconfig_core/configuration_manager.h index b154315aa6..4cf63ab51c 100644 --- a/vkconfig_core/configuration_manager.h +++ b/vkconfig_core/configuration_manager.h @@ -48,7 +48,8 @@ class ConfigurationManager : public Serialize { const std::map& GetConfigurationInfos() const; bool HasActiveConfiguration() const; - Configuration& CreateConfiguration(const LayerManager& layers, const std::string& configuration_name, bool duplicate = false); + Configuration& CreateConfiguration(const LayerManager& layers, const std::string& configuration_name); + Configuration& DuplicateConfiguration(const LayerManager& layers, const std::string& configuration_name); void RemoveConfiguration(const std::string& configuration_name); int GetConfigurationIndex(const std::string& configuration_name) const; diff --git a/vkconfig_core/test/test_configuration.cpp b/vkconfig_core/test/test_configuration.cpp index 8c457dd198..4a36cc9c06 100644 --- a/vkconfig_core/test/test_configuration.cpp +++ b/vkconfig_core/test/test_configuration.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2020-2021 Valve Corporation - * Copyright (c) 2020-2021 LunarG, Inc. + * Copyright (c) 2020-2024 Valve Corporation + * Copyright (c) 2020-2024 LunarG, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ */ #include "../configuration.h" +#include "../layer_manager.h" #include "../util.h" #include @@ -195,3 +196,189 @@ TEST(test_configuration, make_duplicate_tagged_name_mix) { EXPECT_STREQ("Tag Configuration (tag) Bla", new_name.c_str()); EXPECT_TRUE(!new_name.empty()); } + +TEST(test_configuration, create) { + LayerManager layer_manager; + layer_manager.LoadLayersFromPath(":/layers"); + + Configuration configuration = Configuration::Create(layer_manager, "New Configuration"); + + bool has_app_api = false; + bool has_app_env = false; + + for (std::size_t i = 0, n = configuration.parameters.size(); i < n; ++i) { + if (configuration.parameters[i].control == LAYER_CONTROL_APPLICATIONS_API) { + has_app_api = true; + continue; + } + + if (configuration.parameters[i].control == LAYER_CONTROL_APPLICATIONS_ENV) { + has_app_env = true; + continue; + } + + EXPECT_EQ(configuration.parameters[i].control, LAYER_CONTROL_AUTO); + } + + EXPECT_EQ(has_app_api, true); + EXPECT_EQ(has_app_env, true); +} + +TEST(test_configuration, create_disabled) { + LayerManager layer_manager; + layer_manager.LoadLayersFromPath(":/layers"); + + Configuration configuration = Configuration::CreateDisabled(layer_manager); + + bool has_app_api = false; + bool has_app_env = false; + + for (std::size_t i = 0, n = configuration.parameters.size(); i < n; ++i) { + if (configuration.parameters[i].control == LAYER_CONTROL_APPLICATIONS_API) { + has_app_api = true; + continue; + } + + if (configuration.parameters[i].control == LAYER_CONTROL_APPLICATIONS_ENV) { + has_app_env = true; + continue; + } + + EXPECT_EQ(configuration.parameters[i].control, LAYER_CONTROL_OFF); + } + + EXPECT_EQ(has_app_api, true); + EXPECT_EQ(has_app_env, true); +} + +TEST(test_configuration, SwitchLayerVersion) { + LayerManager layer_manager; + layer_manager.LoadLayersFromPath(":/layers"); + + Configuration configuration = Configuration::Create(layer_manager, "New Configuration"); + for (std::size_t i = 0, n = configuration.parameters.size(); i < n; ++i) { + EXPECT_EQ(configuration.parameters[i].api_version, Version::LATEST); + } + Parameter* parameter_latest = configuration.Find("VK_LAYER_LUNARG_version"); + EXPECT_EQ(parameter_latest->api_version, Version::LATEST); + + configuration.SwitchLayerVersion(layer_manager, "VK_LAYER_LUNARG_version", Version(1, 3, 204)); + Parameter* parameter_204 = configuration.Find("VK_LAYER_LUNARG_version"); + EXPECT_EQ(parameter_204->api_version, Version(1, 3, 204)); + + configuration.SwitchLayerVersion(layer_manager, "VK_LAYER_LUNARG_version", Version::LATEST); + Parameter* parameter_restore = configuration.Find("VK_LAYER_LUNARG_version"); + EXPECT_EQ(parameter_restore->api_version, Version::LATEST); + + configuration.SwitchLayerVersion(layer_manager, "VK_LAYER_LUNARG_version", Version(1, 3, 205)); + Parameter* parameter_version_not_found = configuration.Find("VK_LAYER_LUNARG_version"); + EXPECT_EQ(parameter_version_not_found->api_version, Version::LATEST); +} + +TEST(test_configuration, Reorder_full) { + LayerManager layer_manager; + layer_manager.LoadLayersFromPath(":/layers"); + + Configuration configuration = Configuration::Create(layer_manager, "New Configuration"); + + std::vector layer_names; + layer_names.push_back("VK_LAYER_LUNARG_test_04"); + layer_names.push_back("VK_LAYER_LUNARG_test_01"); + layer_names.push_back("VK_LAYER_LUNARG_test_02"); + layer_names.push_back("Vulkan Layers from the Application Vulkan API"); + layer_names.push_back("Vulkan Layers from Application Environment Variables"); + layer_names.push_back("VK_LAYER_LUNARG_version"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_2_1"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_2_0"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_1_0"); + layer_names.push_back("VK_LAYER_LUNARG_test_00"); + layer_names.push_back("VK_LAYER_LUNARG_test_05"); + layer_names.push_back("VK_LAYER_LUNARG_test_06"); + layer_names.push_back("VK_LAYER_LUNARG_test_03"); + + configuration.Reorder(layer_names); + + EXPECT_STREQ(configuration.parameters[0].key.c_str(), "VK_LAYER_LUNARG_test_04"); + EXPECT_STREQ(configuration.parameters[1].key.c_str(), "VK_LAYER_LUNARG_test_01"); + EXPECT_STREQ(configuration.parameters[2].key.c_str(), "VK_LAYER_LUNARG_test_02"); + EXPECT_STREQ(configuration.parameters[3].key.c_str(), "Vulkan Layers from the Application Vulkan API"); + EXPECT_STREQ(configuration.parameters[4].key.c_str(), "Vulkan Layers from Application Environment Variables"); + EXPECT_STREQ(configuration.parameters[5].key.c_str(), "VK_LAYER_LUNARG_version"); + EXPECT_STREQ(configuration.parameters[6].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_1"); + EXPECT_STREQ(configuration.parameters[7].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_0"); + EXPECT_STREQ(configuration.parameters[8].key.c_str(), "VK_LAYER_LUNARG_reference_1_1_0"); + EXPECT_STREQ(configuration.parameters[9].key.c_str(), "VK_LAYER_LUNARG_test_00"); + EXPECT_STREQ(configuration.parameters[10].key.c_str(), "VK_LAYER_LUNARG_test_05"); + EXPECT_STREQ(configuration.parameters[11].key.c_str(), "VK_LAYER_LUNARG_test_06"); + EXPECT_STREQ(configuration.parameters[12].key.c_str(), "VK_LAYER_LUNARG_test_03"); +} + +TEST(test_configuration, Reorder_partial) { + LayerManager layer_manager; + layer_manager.LoadLayersFromPath(":/layers"); + + Configuration configuration = Configuration::Create(layer_manager, "New Configuration"); + + std::vector layer_names; + layer_names.push_back("VK_LAYER_LUNARG_test_04"); + layer_names.push_back("Vulkan Layers from the Application Vulkan API"); + layer_names.push_back("VK_LAYER_LUNARG_version"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_2_1"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_2_0"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_1_0"); + layer_names.push_back("VK_LAYER_LUNARG_test_06"); + layer_names.push_back("VK_LAYER_LUNARG_test_03"); + + configuration.Reorder(layer_names); + + EXPECT_STREQ(configuration.parameters[0].key.c_str(), "VK_LAYER_LUNARG_test_04"); + EXPECT_STREQ(configuration.parameters[1].key.c_str(), "Vulkan Layers from the Application Vulkan API"); + EXPECT_STREQ(configuration.parameters[2].key.c_str(), "VK_LAYER_LUNARG_version"); + EXPECT_STREQ(configuration.parameters[3].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_1"); + EXPECT_STREQ(configuration.parameters[4].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_0"); + EXPECT_STREQ(configuration.parameters[5].key.c_str(), "VK_LAYER_LUNARG_reference_1_1_0"); + EXPECT_STREQ(configuration.parameters[6].key.c_str(), "VK_LAYER_LUNARG_test_06"); + EXPECT_STREQ(configuration.parameters[7].key.c_str(), "VK_LAYER_LUNARG_test_03"); +} + +TEST(test_configuration, Reorder_missing) { + LayerManager layer_manager; + layer_manager.LoadLayersFromPath(":/layers"); + + Configuration configuration = Configuration::Create(layer_manager, "New Configuration"); + + std::vector layer_names; + layer_names.push_back("VK_LAYER_LUNARG_test_04"); + layer_names.push_back("Vulkan Layers from the Application Vulkan API"); + layer_names.push_back("VK_LAYER_LUNARG_missing_0"); + layer_names.push_back("VK_LAYER_LUNARG_version"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_2_1"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_2_0"); + layer_names.push_back("VK_LAYER_LUNARG_reference_1_1_0"); + layer_names.push_back("VK_LAYER_LUNARG_test_06"); + layer_names.push_back("VK_LAYER_LUNARG_test_03"); + layer_names.push_back("VK_LAYER_LUNARG_missing_1"); + + configuration.Reorder(layer_names); + + EXPECT_STREQ(configuration.parameters[0].key.c_str(), "VK_LAYER_LUNARG_test_04"); + EXPECT_STREQ(configuration.parameters[1].key.c_str(), "Vulkan Layers from the Application Vulkan API"); + EXPECT_STREQ(configuration.parameters[2].key.c_str(), "VK_LAYER_LUNARG_version"); + EXPECT_STREQ(configuration.parameters[3].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_1"); + EXPECT_STREQ(configuration.parameters[4].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_0"); + EXPECT_STREQ(configuration.parameters[5].key.c_str(), "VK_LAYER_LUNARG_reference_1_1_0"); + EXPECT_STREQ(configuration.parameters[6].key.c_str(), "VK_LAYER_LUNARG_test_06"); + EXPECT_STREQ(configuration.parameters[7].key.c_str(), "VK_LAYER_LUNARG_test_03"); +} + +TEST(test_configuration, Reorder_empty) { + LayerManager layer_manager; + layer_manager.LoadLayersFromPath(":/layers"); + + Configuration configuration = Configuration::Create(layer_manager, "New Configuration"); + + std::vector layer_names; + configuration.Reorder(layer_names); + + EXPECT_TRUE(configuration.parameters.empty()); +} diff --git a/vkconfig_gui/tab_configurations.cpp b/vkconfig_gui/tab_configurations.cpp index d3d2e1be74..e3253a39a8 100644 --- a/vkconfig_gui/tab_configurations.cpp +++ b/vkconfig_gui/tab_configurations.cpp @@ -587,6 +587,9 @@ void TabConfigurations::OnContextMenuNewClicked(ConfigurationListItem *item) { configurator.Override(OVERRIDE_AREA_ALL); this->UpdateUI_Configurations(UPDATE_REBUILD_UI); + this->UpdateUI_LoaderMessages(); + this->UpdateUI_Layers(UPDATE_REBUILD_UI); + this->UpdateUI_Settings(UPDATE_REBUILD_UI); } void TabConfigurations::OnContextMenuImportClicked(ConfigurationListItem *item) { @@ -629,7 +632,7 @@ void TabConfigurations::OnContextMenuDuplicateClicked(ConfigurationListItem *ite Configurator &configurator = Configurator::Get(); const Configuration &duplicated_configuration = - configurator.configurations.CreateConfiguration(configurator.layers, item->configuration_name, true); + configurator.configurations.DuplicateConfiguration(configurator.layers, item->configuration_name); item->configuration_name = duplicated_configuration.key;