Skip to content

Commit

Permalink
vkconfig3: Clean up Per and all enabled executables scope
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Nov 18, 2024
1 parent c4e2dda commit 58d837e
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 300 deletions.
148 changes: 71 additions & 77 deletions vkconfig_core/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ void Configurator::BuildLoaderSettings(const std::string& configuration_key, con
bool Configurator::WriteLoaderSettings(OverrideArea override_area, const Path& loader_settings_path) {
assert(!loader_settings_path.Empty());

if (!this->HasActiveConfiguration()) {
return false;
}

if (override_area & OVERRIDE_AREA_LOADER_SETTINGS_BIT) {
std::vector<LoaderSettings> loader_settings_array;

Expand All @@ -222,13 +218,17 @@ bool Configurator::WriteLoaderSettings(OverrideArea override_area, const Path& l
break;
case EXECUTABLE_ALL:
case EXECUTABLE_PER: {
const std::vector<Executable>& collection = this->executables.GetExecutables();
for (std::size_t i = 0, n = collection.size(); i < n; ++i) {
const std::vector<Executable>& executables = this->executables.GetExecutables();
for (std::size_t i = 0, n = executables.size(); i < n; ++i) {
if (!executables[i].enabled) {
continue;
}

if (this->executable_scope == EXECUTABLE_PER) {
configuration = collection[i].GetActiveOptions()->configuration;
configuration = executables[i].configuration;
}

this->BuildLoaderSettings(configuration, collection[i].path.AbsolutePath(), loader_settings_array);
this->BuildLoaderSettings(configuration, executables[i].path.AbsolutePath(), loader_settings_array);
}
break;
}
Expand All @@ -237,10 +237,10 @@ bool Configurator::WriteLoaderSettings(OverrideArea override_area, const Path& l
break;
}

if (!loader_settings_array.empty()) {
if (this->executable_scope != EXECUTABLE_NONE) {
QJsonObject root;
root.insert("file_format_version", "1.0.0");
if (loader_settings_array.size() > 1) {
if (::EnabledExecutables(this->executable_scope)) {
QJsonArray json_settings_array;
for (std::size_t i = 0, n = loader_settings_array.size(); i < n; ++i) {
json_settings_array.append(CreateJsonSettingObject(loader_settings_array[i]));
Expand All @@ -267,10 +267,6 @@ bool Configurator::WriteLoaderSettings(OverrideArea override_area, const Path& l

// Create and write vk_layer_settings.txt file
bool Configurator::WriteLayersSettings(OverrideArea override_area, const Path& layers_settings_path) {
if (!this->HasActiveConfiguration()) {
return false;
}

if (override_area & OVERRIDE_AREA_LAYERS_SETTINGS_BIT) {
std::vector<LayersSettings> layers_settings_array;

Expand All @@ -289,14 +285,18 @@ bool Configurator::WriteLayersSettings(OverrideArea override_area, const Path& l
std::string configuration_name = this->selected_global_configuration;

for (std::size_t i = 0, n = executables.size(); i < n; ++i) {
if (!executables[i].enabled) {
continue;
}

if (this->executable_scope == EXECUTABLE_PER) {
configuration_name = executables[i].GetActiveOptions()->configuration;
configuration_name = executables[i].configuration;
}

LayersSettings settings;
settings.executable_path = executables[i].path;
settings.configuration_name = configuration_name;
settings.settings_path = executables[i].GetActiveOptions()->working_folder;
settings.settings_path = executables[i].GetActiveOptions()->working_folder + "/vk_layer_settings.txt";
layers_settings_array.push_back(settings);
}
break;
Expand Down Expand Up @@ -463,10 +463,23 @@ bool Configurator::Surrender(OverrideArea override_area) {
result_loader_settings = loader_settings_path.Remove();
}

// TODO, Remove per application layer_settings file
bool result_layers_settings = true;
if (override_area & OVERRIDE_AREA_LAYERS_SETTINGS_BIT) {
result_layers_settings = layers_settings_path.Remove();
bool global_removed = layers_settings_path.Remove();
if (this->executable_scope == EXECUTABLE_ALL) {
result_layers_settings = global_removed;
}

const std::vector<Executable>& executables = this->executables.GetExecutables();
for (std::size_t i = 0, n = executables.size(); i < n; ++i) {
Path path(executables[i].GetActiveOptions()->working_folder + "/vk_layer_settings.txt");
if (path.Exists()) {
bool local_removed = path.Remove();
if (::EnabledExecutables(this->executable_scope)) {
result_layers_settings = result_layers_settings && local_removed;
}
}
}
}

#if VKC_ENV == VKC_ENV_WIN32
Expand Down Expand Up @@ -500,71 +513,26 @@ void Configurator::Reset(bool hard) {
void Configurator::SetActiveConfigurationName(const std::string& configuration_name) {
if (this->executable_scope == EXECUTABLE_PER) {
Executable* executable = this->executables.GetActiveExecutable();
executable->GetActiveOptions()->configuration = configuration_name;
executable->configuration = configuration_name;
} else {
this->selected_global_configuration = configuration_name;
}
}

std::string Configurator::GetActionConfigurationName() const {
if (this->executable_scope == EXECUTABLE_PER) {
const Executable* executable = this->executables.GetActiveExecutable();
return executable->GetActiveOptions()->configuration;
} else {
return this->selected_global_configuration;
}
}

Configuration* Configurator::GetActiveConfiguration() {
if (this->executable_scope == EXECUTABLE_PER) {
const Executable* executable = this->executables.GetActiveExecutable();
return this->configurations.FindConfiguration(executable->GetActiveOptions()->configuration);
if (!executable->enabled) {
return nullptr;
}
return this->configurations.FindConfiguration(executable->configuration);
} else {
return this->configurations.FindConfiguration(this->selected_global_configuration);
}
}

const Configuration* Configurator::GetActiveConfiguration() const {
if (this->executable_scope == EXECUTABLE_PER) {
const Executable* executable = this->executables.GetActiveExecutable();
return this->configurations.FindConfiguration(executable->GetActiveOptions()->configuration);
} else {
return this->configurations.FindConfiguration(this->selected_global_configuration);
}
}

bool Configurator::HasActiveConfiguration() const {
switch (this->executable_scope) {
default:
case EXECUTABLE_NONE:
return false;
case EXECUTABLE_ANY:
return this->configurations.FindConfiguration(this->selected_global_configuration) != nullptr;
case EXECUTABLE_ALL: {
const Configuration* configuration = this->configurations.FindConfiguration(this->selected_global_configuration);
const std::vector<Executable>& data = this->executables.GetExecutables();
for (std::size_t i = 0, n = data.size(); i < n; ++i) {
if (data[i].enabled) {
return true;
}
}
return false;
} break;
case EXECUTABLE_PER: {
const std::vector<Executable>& data = this->executables.GetExecutables();
for (std::size_t i = 0, n = data.size(); i < n; ++i) {
if (data[i].enabled) {
const ExecutableOptions* options = data[i].GetActiveOptions();
if (options != nullptr) {
return this->configurations.FindConfiguration(options->configuration) != nullptr;
} else {
return false;
}
}
}
return false;
}
}
return const_cast<Configurator*>(this)->GetActiveConfiguration();
}

Parameter* Configurator::GetActiveParameter() {
Expand All @@ -576,14 +544,7 @@ Parameter* Configurator::GetActiveParameter() {
}
}

const Parameter* Configurator::GetActiveParameter() const {
const Configuration* configuration = this->GetActiveConfiguration();
if (configuration != nullptr) {
return configuration->GetActiveParameter();
} else {
return nullptr;
}
}
const Parameter* Configurator::GetActiveParameter() const { return const_cast<Configurator*>(this)->GetActiveParameter(); }

bool Configurator::HasActiveParameter() const { return this->GetActiveParameter() != nullptr; }

Expand Down Expand Up @@ -872,6 +833,39 @@ bool Configurator::HasActiveSettings() const {
}
}

bool Configurator::HasEnabledUI(EnabledUI enabled_ui) {
switch (enabled_ui) {
default:
assert(false);
return false;
case ENABLE_UI_CONFIG: {
return this->GetExecutableScope() != EXECUTABLE_NONE;
}
case ENABLE_UI_LOADER:
case ENABLE_UI_LAYERS: {
if (!this->HasEnabledUI(ENABLE_UI_CONFIG)) {
return false;
}
if (::EnabledExecutables(this->GetExecutableScope())) {
const Executable* executable = this->executables.GetActiveExecutable();
if (executable == nullptr) {
return false;
}
if (!executable->enabled) {
return false;
}
}
return this->GetActiveConfiguration() != nullptr;
}
case ENABLE_UI_SETTINGS: {
if (!this->HasEnabledUI(ENABLE_UI_LAYERS)) {
return false;
}
return this->HasActiveSettings();
}
}
}

std::string Configurator::GenerateVulkanStatus() const {
std::string log;

Expand Down
10 changes: 8 additions & 2 deletions vkconfig_core/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
#include "type_executable_mode.h"
#include "serialization.h"

enum EnabledUI {
ENABLE_UI_CONFIG = 0,
ENABLE_UI_LAYERS,
ENABLE_UI_LOADER,
ENABLE_UI_SETTINGS,
};

class Configurator : public Serialize {
public:
enum Mode { CMD, GUI };
Expand Down Expand Up @@ -76,11 +83,9 @@ class Configurator : public Serialize {
void Reset(bool hard);

void SetActiveConfigurationName(const std::string& configuration_name);
std::string GetActionConfigurationName() const;

Configuration* GetActiveConfiguration();
const Configuration* GetActiveConfiguration() const;
bool HasActiveConfiguration() const;

Parameter* GetActiveParameter();
const Parameter* GetActiveParameter() const;
Expand All @@ -105,6 +110,7 @@ class Configurator : public Serialize {
void SetHomeSDK(const Path& path);

bool HasActiveSettings() const;
bool HasEnabledUI(EnabledUI enabled_ui);

std::string GenerateVulkanStatus() const;

Expand Down
2 changes: 1 addition & 1 deletion vkconfig_core/executable.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct DefaultPath {

struct ExecutableOptions {
std::string label = "Default Options";
std::string configuration = "Validation";
Path working_folder;
std::vector<std::string> args;
std::vector<std::string> envs;
Expand All @@ -51,6 +50,7 @@ struct Executable {
enum { INVALID_OPTIONS = -1 };

Path path;
std::string configuration = "Validation";
bool enabled = true;

int GetActiveOptionsIndex() const;
Expand Down
32 changes: 30 additions & 2 deletions vkconfig_core/executable_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ bool ExecutableManager::Load(const QJsonObject& json_root_object) {
const QJsonObject& json_application_object = json_list_object.value(json_list_keys[i]).toObject();
executable.path = json_list_keys[i].toStdString();
executable.enabled = json_application_object.value("enabled").toBool();
if (json_application_object.value("configuration") != QJsonValue::Undefined) {
executable.configuration = json_application_object.value("configuration").toString().toStdString();
}

const QJsonArray& json_options_array = json_application_object.value("options").toArray();
for (int j = 0, o = json_options_array.size(); j < o; ++j) {
Expand All @@ -93,7 +96,6 @@ bool ExecutableManager::Load(const QJsonObject& json_root_object) {
ExecutableOptions executable_options;

executable_options.label = json_options_object.value("label").toString().toStdString();
executable_options.configuration = json_options_object.value("configuration").toString().toStdString();
executable_options.working_folder = json_options_object.value("working_folder").toString().toStdString();

const QJsonArray& json_command_lines_array = json_options_object.value("arguments").toArray();
Expand Down Expand Up @@ -135,6 +137,7 @@ bool ExecutableManager::Save(QJsonObject& json_root_object) const {

QJsonObject json_executable_object;
json_executable_object.insert("enabled", executable.enabled);
json_executable_object.insert("configuration", executable.configuration.c_str());
json_executable_object.insert("active_option", executable.GetActiveOptionsName().c_str());

QJsonArray json_options_array;
Expand All @@ -155,7 +158,6 @@ bool ExecutableManager::Save(QJsonObject& json_root_object) const {

QJsonObject json_option_object;
json_option_object.insert("label", options.label.c_str());
json_option_object.insert("configuration", options.configuration.c_str());
json_option_object.insert("working_folder", options.working_folder.RelativePath().c_str());
json_option_object.insert("arguments", json_arg_array);
json_option_object.insert("environment_variables", json_env_array);
Expand Down Expand Up @@ -305,3 +307,29 @@ std::vector<Executable> ExecutableManager::RemoveMissingExecutables(const std::v

return valid_applications;
}

bool ExecutableManager::HasIncompatiblePerExecutables(const Executable& executable,
std::vector<Executable>& imcompatible_executables) const {
for (std::size_t i = 0, n = this->data.size(); i < n; ++i) {
if (executable.path == this->data[i].path) {
continue;
}

if (executable.GetActiveOptions()->working_folder == this->data[i].GetActiveOptions()->working_folder) {
imcompatible_executables.push_back(this->data[i]);
}
}

return !imcompatible_executables.empty();
}

bool ExecutableManager::HasIncompatiblePerExecutables(std::vector<Executable>& imcompatible_executables) const {
for (std::size_t i = 0, n = this->data.size(); i < n; ++i) {
bool incompatible = this->HasIncompatiblePerExecutables(this->data[i], imcompatible_executables);
if (incompatible) {
imcompatible_executables.push_back(this->data[i]);
}
}

return !imcompatible_executables.empty();
}
3 changes: 3 additions & 0 deletions vkconfig_core/executable_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ExecutableManager : public Serialize {
// Search for all the applications in the list, an remove the application which executable can't be found
std::vector<Executable> RemoveMissingExecutables(const std::vector<Executable>& executables) const;

bool HasIncompatiblePerExecutables(const Executable& executable, std::vector<Executable>& imcompatible_executables) const;
bool HasIncompatiblePerExecutables(std::vector<Executable>& imcompatible_executables) const;

bool launcher_clear_on_launch = true;
Path last_path_executable = ::Get(Path::HOME);

Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ Path::Path(const std::string& path, bool recover_vars) {
this->data = result;
}

bool Path::IsFile() const { return QFileInfo(this->data.c_str()).isFile(); }
bool Path::IsFile() const { return QFileInfo(this->AbsolutePath().c_str()).isFile(); }

bool Path::IsDir() const { return QFileInfo(this->data.c_str()).isDir(); }
bool Path::IsDir() const { return QFileInfo(this->AbsolutePath().c_str()).isDir(); }

bool Path::IsBuiltIn() const { return this->data.find(":") == 0; }

Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/test/test_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
TEST(test_ui, GetMainWindowTitle) {
std::string title = GetMainWindowTitle(false, false);

EXPECT_STREQ(("Vulkan Configurator " + Version::VKCONFIG.str() + "-Alpha").c_str(), title.c_str());
EXPECT_STREQ(("Vulkan Configurator " + Version::VKCONFIG.str() + " (BETA)").c_str(), title.c_str());
}

TEST(test_ui, GetMainWindowTitle_active) {
std::string title = GetMainWindowTitle(true, false);

EXPECT_STREQ(("Vulkan Configurator " + Version::VKCONFIG.str() + "-Alpha <ACTIVE>").c_str(), title.c_str());
EXPECT_STREQ(("Vulkan Configurator " + Version::VKCONFIG.str() + " (BETA) <ACTIVE>").c_str(), title.c_str());
}
Loading

0 comments on commit 58d837e

Please sign in to comment.