Skip to content

Commit

Permalink
vkconfig3: Implement initilization sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Jul 11, 2024
1 parent 2597995 commit f111b0f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 57 deletions.
8 changes: 5 additions & 3 deletions vkconfig_core/configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ void ConfigurationManager::LoadDefaultConfigurations(const std::vector<Layer> &a
if (found_configuration == nullptr) {
auto iter = this->removed_built_in_configuration.find(configuration.key);
// If the removed built-in configuration is a version older than the current built-in configuration, we are it back.
if (iter->second < configuration.version) {
if (iter == this->removed_built_in_configuration.end()) {
this->available_configurations.push_back(configuration);
} else if (iter->second < configuration.version) {
this->available_configurations.push_back(configuration);
}
} else if (found_configuration->version < configuration.version) {
Expand All @@ -71,8 +73,6 @@ void ConfigurationManager::LoadDefaultConfigurations(const std::vector<Layer> &a
this->available_configurations.push_back(configuration);
}
}

this->SortConfigurations();
}

void ConfigurationManager::SortConfigurations() {
Expand Down Expand Up @@ -259,6 +259,8 @@ void ConfigurationManager::ExportConfiguration(const std::vector<Layer> &availab
void ConfigurationManager::Reset(const std::vector<Layer> &available_layers) {
// Now we need to kind of restart everything
this->LoadDefaultConfigurations(available_layers);

this->SortConfigurations();
}

bool ConfigurationManager::CheckApiVersions(const std::vector<Layer> &available_layers, Configuration *selected_configuration,
Expand Down
3 changes: 3 additions & 0 deletions vkconfig_core/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void Configurator::BuildLoaderSettings(const ConfigurationInfo& info, const std:
return;
case LAYERS_CONTROLLED_BY_CONFIGURATOR: {
configuration = this->configurations.FindConfiguration(info.GetName());
if (configuration == nullptr) {
return;
}
} break;
case LAYERS_DISABLED_BY_CONFIGURATOR: {
configuration = &disbled_configuration;
Expand Down
22 changes: 7 additions & 15 deletions vkconfig_core/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,15 @@ static const char* GetLayoutStateToken(LayoutState state) {
}

Environment::Environment(Mode mode)
: mode(mode),
active_tab(TAB_DIAGNOSTIC),
has_crashed(false),
use_system_tray(false),
use_per_application_configuration(false),
loader_message_types_flags(::GetLogFlags(qgetenv("VK_LOADER_DEBUG").toStdString())),
hide_message_boxes_flags(0) {
: mode(mode), loader_message_types_flags(::GetLogFlags(qgetenv("VK_LOADER_DEBUG").toStdString())) {
if (mode == MODE_AUTO_LOAD_SAVE) {
const bool result = Load();
assert(result);
}

if (this->applications.empty()) {
this->applications = CreateDefaultApplications();
}
}

Environment::~Environment() {
Expand Down Expand Up @@ -508,15 +506,9 @@ DefaultPath Environment::GetDefaultExecutablePath(const std::string& executable_
DefaultPath default_path{"." + executable_name, "."};

// Using VULKAN_SDK environement variable
const Path env = ::Get(Path::SDK);
const Path env = ::Get(Path::SDK_BIN);
if (!env.Empty()) {
static const char* TABLE[] = {
"/Bin", // ENVIRONMENT_WIN32
"/bin", // ENVIRONMENT_UNIX
};
static_assert(std::size(TABLE) == ENVIRONMENT_COUNT);

const Path search_path(env + TABLE[VKC_ENV] + DEFAULT_PATH + executable_name.c_str());
const Path search_path(env + DEFAULT_PATH + executable_name.c_str());
if (search_path.Exists()) {
default_path.executable_path = Path(search_path.AbsolutePath(), true);
default_path.working_folder = Path(search_path.AbsoluteDir(), true);
Expand Down
10 changes: 5 additions & 5 deletions vkconfig_core/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class Environment {
// Search for all the applications in the list, an remove the application which executable can't be found
std::vector<Application> RemoveMissingApplications(const std::vector<Application>& applications) const;

bool has_crashed;
int hide_message_boxes_flags;
bool has_crashed = false;
int hide_message_boxes_flags = 0;

Path path_export;
Path path_import;
Expand All @@ -122,9 +122,9 @@ class Environment {

const Mode mode;

TabType active_tab;
bool use_system_tray;
bool use_per_application_configuration;
TabType active_tab = TAB_DIAGNOSTIC;
bool use_system_tray = false;
bool use_per_application_configuration = false;
LogFlags loader_message_types_flags;
Path home_sdk_path;

Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/layer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ LayerManager::LayerManager(const std::vector<Path> &user_defined_paths) {
this->paths[LAYERS_PATHS_GUI].insert(this->paths[LAYERS_PATHS_GUI].begin(), user_defined_paths.begin(),
user_defined_paths.end());

this->paths[LAYERS_PATHS_SDK].push_back(::Get(Path::SDK));
this->paths[LAYERS_PATHS_SDK].push_back(::Get(Path::SDK_BIN));

this->LoadAllInstalledLayers();
}
Expand All @@ -150,7 +150,7 @@ const Layer *LayerManager::Find(const std::string &layer_name) const {
void LayerManager::LoadAllInstalledLayers() {
this->selected_layers.clear();

for (std::size_t group_index = 0, group_count = LAYERS_PATHS_COUNT; group_index < group_count; ++group_index) {
for (std::size_t group_index = 0, group_count = this->paths.size(); group_index < group_count; ++group_index) {
const LayerType layer_type = ::GetLayerType(static_cast<LayersPaths>(group_index));

const std::vector<Path> &paths_group = this->paths[group_index];
Expand Down
14 changes: 13 additions & 1 deletion vkconfig_core/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static const Path GetLoaderSettingsPath() {
}

static const Path GetSDKPath() {
static const char* TABLE[] = {
const char* TABLE[] = {
"", // PLATFORM_WINDOWS
"/usr", // PLATFORM_LINUX
"/usr/local/share/vulkan", // PLATFORM_MACOS
Expand All @@ -339,6 +339,16 @@ static const Path GetSDKPath() {
return result;
}

static const Path GetSDKBinPath() {
const char* TABLE[] = {
"/Bin", // ENVIRONMENT_WIN32
"/bin", // ENVIRONMENT_UNIX
};
static_assert(std::size(TABLE) == ENVIRONMENT_COUNT);

return GetSDKPath() + TABLE[VKC_ENV];
}

static const Path GetExplicitLayersPath() {
static const std::string TABLE[] = {
"/Bin", // ENVIRONMENT_WIN32
Expand Down Expand Up @@ -380,6 +390,8 @@ Path Get(Path::Builtin path) {
return ::GetLoaderSettingsPath();
case Path::SDK:
return ::GetSDKPath();
case Path::SDK_BIN:
return ::GetSDKBinPath();
case Path::EXPLICIT_LAYERS:
return ::GetExplicitLayersPath();
case Path::CONTENT:
Expand Down
1 change: 1 addition & 0 deletions vkconfig_core/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Path {
LAYERS_SETTINGS,
LOADER_SETTINGS,
SDK,
SDK_BIN,
EXPLICIT_LAYERS,
CONTENT,
};
Expand Down
52 changes: 24 additions & 28 deletions vkconfig_gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,19 @@ MainWindow::MainWindow(QWidget *parent)
Configurator &configurator = Configurator::Get();
Environment &environment = configurator.environment;

// Restore window geometry from last launch
// restoreGeometry(environment.Get(VKCONFIG3_LAYOUT_MAIN_GEOMETRY));
// restoreState(environment.Get(VKCONFIG3_LAYOUT_MAIN_WINDOW_STATE));
// ui->splitter_main->restoreState(environment.Get(VKCONFIG3_LAYOUT_MAIN_SPLITTER1));
// ui->splitter_configurations->restoreState(environment.Get(VKCONFIG3_LAYOUT_MAIN_SPLITTER2));
// ui->splitter_settings->restoreState(environment.Get(VKCONFIG3_LAYOUT_MAIN_SPLITTER3));
ui->combo_box_mode->setCurrentIndex(environment.GetActiveConfigurationInfo().GetMode());

// Update configuration application area

if (!environment.GetApplications().empty()) {
if (environment.GetApplications().empty()) {
environment.SetPerApplicationConfig(false);

ui->check_box_per_application->setEnabled(false);
ui->check_box_per_application->setVisible(false);
ui->combo_box_applications->setVisible(false);
} else {
ui->check_box_per_application->setEnabled(true);

ui->combo_box_applications->blockSignals(true);
ui->combo_box_applications->clear();
for (std::size_t i = 0, n = environment.GetApplications().size(); i < n; ++i) {
Expand All @@ -299,10 +302,11 @@ MainWindow::MainWindow(QWidget *parent)
ui->combo_box_applications->addItem(application.executable_path.RelativePath().c_str());
}
ui->combo_box_applications->blockSignals(false);

this->on_check_box_per_application_toggled(environment.GetPerApplicationConfig());
this->on_combo_box_applications_currentIndexChanged(environment.GetActiveApplicationIndex());
ui->combo_box_applications->setCurrentIndex(environment.GetActiveApplicationIndex());
}
this->on_check_box_per_application_toggled(environment.GetPerApplicationConfig());
this->on_combo_box_applications_currentIndexChanged(environment.GetActiveApplicationIndex());
ui->combo_box_applications->setCurrentIndex(environment.GetActiveApplicationIndex());

// ui->edit_executable->setText(application.executable_path.c_str());
/*
Expand All @@ -326,6 +330,13 @@ MainWindow::MainWindow(QWidget *parent)
ui->log_browser->document()->setMaximumBlockCount(2048);
// ui->configuration_tree->scrollToItem(ui->configuration_tree->topLevelItem(0), QAbstractItemView::PositionAtTop);

// Restore window geometry from last launch
// restoreGeometry(environment.Get(VKCONFIG3_LAYOUT_MAIN_GEOMETRY));
// restoreState(environment.Get(VKCONFIG3_LAYOUT_MAIN_WINDOW_STATE));
// ui->splitter_main->restoreState(environment.Get(VKCONFIG3_LAYOUT_MAIN_SPLITTER1));
// ui->splitter_configurations->restoreState(environment.Get(VKCONFIG3_LAYOUT_MAIN_SPLITTER2));
// ui->splitter_settings->restoreState(environment.Get(VKCONFIG3_LAYOUT_MAIN_SPLITTER3));

this->InitTray();
this->UpdateTray();
this->UpdateUI();
Expand Down Expand Up @@ -378,14 +389,9 @@ void MainWindow::UpdateTray() {
if (QSystemTrayIcon::isSystemTrayAvailable()) {
// QApplication::setQuitOnLastWindowClosed(!ui->check_box_persistent->isChecked());

Configurator &configurator = Configurator::Get();

const Environment &environment = configurator.environment;

const bool use_override = environment.global_configuration.GetMode() != LAYERS_CONTROLLED_BY_APPLICATIONS;
const bool active = configurator.HasActiveConfiguration() && use_override;
const Environment &environment = Configurator::Get().environment;

switch (environment.global_configuration.GetMode()) {
switch (environment.GetActiveConfigurationInfo().GetMode()) {
default:
case LAYERS_CONTROLLED_BY_APPLICATIONS:
this->_tray_layers_controlled_by_applications->setChecked(true);
Expand All @@ -404,7 +410,7 @@ void MainWindow::UpdateTray() {
break;
}

if (active) {
if (environment.global_configuration.GetMode() != LAYERS_CONTROLLED_BY_APPLICATIONS) {
const QIcon icon(":/resourcefiles/vkconfig-on.png");

this->setWindowIcon(icon);
Expand Down Expand Up @@ -512,16 +518,6 @@ static std::string GetMainWindowTitle(bool active) {
return title;
}

void MainWindow::InitUI() {
const Environment &environment = Configurator::Get().environment;

if (environment.GetPerApplicationConfig()) {
ui->combo_box_mode->setCurrentIndex(environment.GetActiveApplication().configuration.GetMode());
} else {
ui->combo_box_mode->setCurrentIndex(environment.global_configuration.GetMode());
}
}

void MainWindow::AddLayerPathItem(const std::string &layer_path) {
TreeWidgetItemParameter *item_state = new TreeWidgetItemParameter(layer_path.c_str());

Expand Down
1 change: 0 additions & 1 deletion vkconfig_gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ class MainWindow : public QMainWindow {
MainWindow(QWidget *parent = nullptr);
~MainWindow();

void InitUI();
void UpdateUI();

private:
Expand Down
4 changes: 2 additions & 2 deletions vkconfig_gui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Layers Configuration Mode:</string>
<string>Layers Configuration Mode: </string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -701,7 +701,7 @@
<item row="0" column="0">
<widget class="QCheckBox" name="check_box_per_application">
<property name="text">
<string>Per-Application Configuration:</string>
<string>Per-Application Configuration: </string>
</property>
</widget>
</item>
Expand Down

0 comments on commit f111b0f

Please sign in to comment.