Skip to content

Commit

Permalink
vkconfig: Initial loader settings implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed May 16, 2024
1 parent 92f4467 commit 27ebab7
Show file tree
Hide file tree
Showing 18 changed files with 468 additions and 167 deletions.
8 changes: 5 additions & 3 deletions vkconfig/dialog_applications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ QTreeWidgetItem *ApplicationsDialog::CreateApplicationItem(const Application &ap

if (configurator.environment.GetUseApplicationList()) {
QCheckBox *check_box = new QCheckBox(application.app_name.c_str());
check_box->setChecked(application.override_layers);
check_box->setChecked(application.layers_mode != LAYERS_MODE_BY_APPLICATIONS);
ui->treeWidget->setItemWidget(item, 0, check_box);
connect(check_box, SIGNAL(stateChanged(int)), this, SLOT(OnStateChanged(int)));
} else {
Expand Down Expand Up @@ -233,7 +233,8 @@ void ApplicationsDialog::itemChanged(QTreeWidgetItem *item, int column) {
_last_selected_application_index = ui->treeWidget->indexOfTopLevelItem(item);
QCheckBox *check_box = dynamic_cast<QCheckBox *>(ui->treeWidget->itemWidget(item, column));
if (check_box != nullptr) {
Configurator::Get().environment.GetApplication(_last_selected_application_index).override_layers = check_box->isChecked();
Configurator::Get().environment.GetApplication(_last_selected_application_index).layers_mode =
check_box->isChecked() ? LAYERS_MODE_BY_CONFIGURATOR_RUNNING : LAYERS_MODE_BY_APPLICATIONS;
}
}

Expand All @@ -252,7 +253,8 @@ void ApplicationsDialog::OnStateChanged(int) {
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
QCheckBox *check_box = dynamic_cast<QCheckBox *>(ui->treeWidget->itemWidget(item, 0));
assert(check_box != nullptr);
environment.GetApplication(i).override_layers = check_box->isChecked();
environment.GetApplication(i).layers_mode =
check_box->isChecked() ? LAYERS_MODE_BY_CONFIGURATOR_RUNNING : LAYERS_MODE_BY_APPLICATIONS;
}
}

Expand Down
18 changes: 9 additions & 9 deletions vkconfig3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ else()
endif()

if(WIN32)
add_executable(vkconfig3 WIN32 ${FILES_ALL} ${CMAKE_CURRENT_SOURCE_DIR}/resourcefiles/vkconfig.rc)
target_compile_definitions(vkconfig3 PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_options(vkconfig3 PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/MP>)
target_link_libraries(vkconfig3 Cfgmgr32)
add_executable(vkconfig-gui WIN32 ${FILES_ALL} ${CMAKE_CURRENT_SOURCE_DIR}/resourcefiles/vkconfig.rc)
target_compile_definitions(vkconfig-gui PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_options(vkconfig-gui PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/MP>)
target_link_libraries(vkconfig-gui Cfgmgr32)
else()
add_executable(vkconfig3 ${FILES_ALL} ${FILES_UI})
add_executable(vkconfig-gui ${FILES_ALL} ${FILES_UI})
endif()

target_link_libraries(vkconfig3 Vulkan::Headers vkconfig_core Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network)
target_compile_definitions(vkconfig3 PRIVATE QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT)
set_target_properties(vkconfig3 PROPERTIES FOLDER "vkconfig")
target_link_libraries(vkconfig-gui Vulkan::Headers vkconfig_core Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network)
target_compile_definitions(vkconfig-gui PRIVATE QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT)
set_target_properties(vkconfig-gui PROPERTIES FOLDER "vkconfig")

install(TARGETS vkconfig3 DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS vkconfig-gui DESTINATION ${CMAKE_INSTALL_BINDIR})

if(WIN32)
get_target_property(QMAKE_EXE Qt5::qmake IMPORTED_LOCATION)
Expand Down
16 changes: 2 additions & 14 deletions vkconfig3/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void Configurator::UpdateDevices() {
pfnDestroyInstance(instance, NULL);
}

bool Configurator::SupportDifferentLayerVersions(Version *return_loader_version) const {
bool Configurator::SupportLoaderSettings(Version *return_loader_version) const {
// Check loader version
const Version version = GetVulkanLoaderVersion();
assert(version != Version::VERSION_NULL);
Expand All @@ -184,19 +184,7 @@ bool Configurator::SupportDifferentLayerVersions(Version *return_loader_version)
*return_loader_version = version;
}

return version >= Version("1.3.212");
}

bool Configurator::SupportApplicationList(Version *return_loader_version) const {
// Check loader version
const Version version = GetVulkanLoaderVersion();
assert(version != Version::VERSION_NULL);

if (return_loader_version) {
*return_loader_version = version;
}

return version >= Version("1.2.141");
return version >= Version("1.3.261");
}

void Configurator::ResetToDefault(bool hard) {
Expand Down
15 changes: 2 additions & 13 deletions vkconfig3/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "../vkconfig_core/configuration_manager.h"
#include "../vkconfig_core/platform.h"

static const std::vector<std::string> SUPPORTED_CONFIG_FILES = {"_2_2_3", "_2_2_2", "_2_2_1"};
static const std::vector<std::string> SUPPORTED_CONFIG_FILES = {"_2_2_3"};

class Configurator {
public:
Expand All @@ -38,22 +38,12 @@ class Configurator {

// The list of applications affected
public:
bool SupportDifferentLayerVersions(Version* return_loader_version = nullptr) const;

// If return_loader_version is not null, the function will return the loader version
// If quiet is false, message box will be generate
bool SupportApplicationList(Version* return_loader_version = nullptr) const;

bool HasActiveOverrideOnApplicationListOnly() const {
return SupportApplicationList() && environment.HasOverriddenApplications();
}
bool SupportLoaderSettings(Version* return_loader_version = nullptr) const;

void ActivateConfiguration(const std::string& configuration_name);

void ResetToDefault(bool hard);

std::string profile_file;

std::vector<std::string> GetDeviceNames() const;

private:
Expand All @@ -63,7 +53,6 @@ class Configurator {
Configurator(const Configurator&) = delete;
Configurator& operator=(const Configurator&) = delete;

void CopyResourceFiles();
void UpdateDevices();

public:
Expand Down
8 changes: 5 additions & 3 deletions vkconfig3/dialog_applications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ QTreeWidgetItem *ApplicationsDialog::CreateApplicationItem(const Application &ap

if (configurator.environment.GetUseApplicationList()) {
QCheckBox *check_box = new QCheckBox(application.app_name.c_str());
check_box->setChecked(application.override_layers);
check_box->setChecked(application.layers_mode != LAYERS_MODE_BY_APPLICATIONS);
ui->treeWidget->setItemWidget(item, 0, check_box);
connect(check_box, SIGNAL(clicked(bool)), this, SLOT(itemClicked(bool)));
} else {
Expand Down Expand Up @@ -233,7 +233,8 @@ void ApplicationsDialog::itemChanged(QTreeWidgetItem *item, int column) {
_last_selected_application_index = ui->treeWidget->indexOfTopLevelItem(item);
QCheckBox *check_box = dynamic_cast<QCheckBox *>(ui->treeWidget->itemWidget(item, column));
if (check_box != nullptr) {
Configurator::Get().environment.GetApplication(_last_selected_application_index).override_layers = check_box->isChecked();
Configurator::Get().environment.GetApplication(_last_selected_application_index).layers_mode =
check_box->isChecked() ? LAYERS_MODE_BY_CONFIGURATOR_RUNNING : LAYERS_MODE_BY_APPLICATIONS;
}
}

Expand All @@ -254,7 +255,8 @@ void ApplicationsDialog::itemClicked(bool clicked) {
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
QCheckBox *check_box = dynamic_cast<QCheckBox *>(ui->treeWidget->itemWidget(item, 0));
assert(check_box != nullptr);
environment.GetApplication(i).override_layers = check_box->isChecked();
environment.GetApplication(i).layers_mode =
check_box->isChecked() ? LAYERS_MODE_BY_CONFIGURATOR_RUNNING : LAYERS_MODE_BY_APPLICATIONS;
}
}

Expand Down
101 changes: 61 additions & 40 deletions vkconfig3/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->configurations_tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
SLOT(OnConfigurationTreeClicked(QTreeWidgetItem *, int)));

connect(ui->combo_box_mode, SIGNAL(currentIndexChanged(int)), this, SLOT(OnComboBoxModeChanged(int)));

connect(ui->settings_tree, SIGNAL(itemExpanded(QTreeWidgetItem *)), this, SLOT(editorExpanded(QTreeWidgetItem *)));
connect(ui->settings_tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
SLOT(OnSettingsTreeClicked(QTreeWidgetItem *, int)));
Expand Down Expand Up @@ -215,6 +213,9 @@ MainWindow::MainWindow(QWidget *parent)
ui->edit_env->setText(application.env.c_str());
ui->edit_log->setText(ReplaceBuiltInVariable(application.log_file.c_str()).c_str());

ui->execute_closer_application_label->setVisible(true);
ui->execute_closer_driver_label->setVisible(true);

// ui->check_box_persistent->setToolTip("Keep Vulkan Configurator running in system tray when closing the main window");
// ui->check_box_persistent->setVisible(QSystemTrayIcon::isSystemTrayAvailable());

Expand All @@ -227,6 +228,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->log_browser->document()->setMaximumBlockCount(2048);
// ui->configuration_tree->scrollToItem(ui->configuration_tree->topLevelItem(0), QAbstractItemView::PositionAtTop);

ui->check_box_per_application->setChecked(configurator.environment.GetPerApplicationConfig());

this->InitTray();
this->UpdateTray();
this->UpdateUI();
Expand Down Expand Up @@ -437,7 +440,9 @@ void MainWindow::AddLayerItem(const Parameter &parameter) {
// We simply hide these layers to avoid confusing the Vulkan developers
if (parameter.state == LAYER_STATE_EXCLUDED) return;

decorated_name += " (Missing)";
if (parameter.control != LAYER_STATE_APPLICATION_CONTROLLED && parameter.control != LAYER_CONTROL_UNORDERED) {
decorated_name += " (Missing)";
}
}

TreeWidgetItemParameter *item_state = new TreeWidgetItemParameter(parameter.key.c_str());
Expand Down Expand Up @@ -507,25 +512,16 @@ void MainWindow::UpdateUI() {
this->blockSignals(true);
ui->configurations_tree->blockSignals(true);

ui->combo_box_mode->blockSignals(true);
ui->combo_box_mode->setCurrentIndex(environment.GetMode());
ui->combo_box_mode->blockSignals(false);

// Add applications
ui->combo_box_applications->blockSignals(true);
ui->combo_box_applications->setEnabled(ui->check_box_per_application->isChecked());
const std::vector<Application> &applications = environment.GetApplications();
for (std::size_t i = 0, n = applications.size(); i < n; ++i) {
ui->combo_box_applications->addItem(applications[i].app_name.c_str());
ui->combo_box_applications->addItem(ReplaceBuiltInVariable(applications[i].executable_path.c_str()).c_str());
}
ui->combo_box_applications->setCurrentIndex(environment.GetActiveApplicationIndex());
ui->combo_box_applications->blockSignals(false);

const bool has_active_configuration = configurator.configurations.HasActiveConfiguration(configurator.layers.selected_layers);

const bool enable_layer_ui =
(ui->combo_box_mode->currentIndex() == LAYERS_MODE_BY_CONFIGURATOR_RUNNING) && has_selected_configuration;

// Mode states
this->UpdateTray();
// ui->tree_layers_paths->blockSignals(true);
Expand Down Expand Up @@ -575,7 +571,6 @@ void MainWindow::UpdateUI() {
*/

// Update configurations
ui->group_box_configurations->setEnabled(environment.GetMode() == LAYERS_MODE_BY_CONFIGURATOR_RUNNING);
ui->configurations_tree->setCurrentItem(nullptr);

for (int i = 0, n = ui->configurations_tree->topLevelItemCount(); i < n; ++i) {
Expand Down Expand Up @@ -608,7 +603,7 @@ void MainWindow::UpdateUI() {
// Load Layers paths
std::vector<std::string> layer_paths = configurator.layers.BuildPathList();

ui->tree_layers_paths->setEnabled(enable_layer_ui);
// ui->tree_layers_paths->setEnabled(enable_layer_ui);
ui->tree_layers_paths->clear();

for (std::size_t path_index = 0, count = layer_paths.size(); path_index < count; ++path_index) {
Expand All @@ -620,43 +615,45 @@ void MainWindow::UpdateUI() {
ui->tree_layers_paths->update();

// Load Layers items
ui->layers_tree->setEnabled(enable_layer_ui);
// ui->layers_tree->setEnabled(enable_layer_ui);
ui->layers_tree->clear();

if (has_selected_configuration) {
Configuration *configuration =
FindByKey(configurator.configurations.available_configurations, selected_contiguration_name.c_str());
if (configuration != nullptr) {
std::vector<Parameter> parameters = GatherParameters(configuration->parameters, configurator.layers.selected_layers);

/*
{
QListWidgetItem *item = new QListWidgetItem();
ui->layers_tree->addItem(item);
item->setText(TEXT_EXECUTE_CLOSER_APPLICATION);
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
//item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
item->setFlags(0);
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QFont font = item->font();
font.setItalic(true);
item->setFont(font);
// item->setDisabled(true);
}

*/
for (std::size_t i = 0, n = parameters.size(); i < n; ++i) {
AddLayerItem(parameters[i]);
}

/*
{
QListWidgetItem *item = new QListWidgetItem();
ui->layers_tree->addItem(item);
item->setText(TEXT_EXECUTE_CLOSER_DRIVER);
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
//item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
item->setFlags(0);
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QFont font = item->font();
font.setItalic(true);
item->setFont(font);
// item->setDisabled(true);
}

*/
resizeEvent(nullptr);

ui->layers_tree->update();
Expand Down Expand Up @@ -907,17 +904,44 @@ void MainWindow::on_check_box_apply_list_clicked() {
}
*/

void MainWindow::OnComboBoxModeChanged(int index) {
void MainWindow::on_combo_box_mode_currentIndexChanged(int index) {
Configurator &configurator = Configurator::Get();
configurator.environment.SetMode(static_cast<LayersMode>(ui->combo_box_mode->currentIndex()));
configurator.ActivateConfiguration(configurator.environment.GetSelectedConfiguration());
UpdateUI();

if (configurator.environment.GetPerApplicationConfig()) {
Application &application = configurator.environment.GetApplication(configurator.environment.GetActiveApplicationIndex());
application.layers_mode = static_cast<LayersMode>(index);
} else {
configurator.environment.SetMode(static_cast<LayersMode>(index));
configurator.ActivateConfiguration(configurator.environment.GetSelectedConfiguration());
}

const bool enabled_ui = index == LAYERS_MODE_BY_CONFIGURATOR_RUNNING;

ui->group_box_configurations->setEnabled(enabled_ui);
ui->group_box_settings->setEnabled(enabled_ui);
ui->group_box_layers->setEnabled(enabled_ui);
}

void MainWindow::on_check_box_per_application_clicked() {
ui->combo_box_applications->setEnabled(ui->check_box_per_application->isChecked());
void MainWindow::on_combo_box_applications_currentIndexChanged(int index) {
Configurator &configurator = Configurator::Get();
configurator.environment.SelectActiveApplication(index);

Configurator::Get().environment.SetPerApplicationConfig(ui->check_box_per_application->isChecked());
Application &application = configurator.environment.GetApplication(configurator.environment.GetActiveApplicationIndex());
ui->combo_box_applications->setToolTip(ReplaceBuiltInVariable(application.executable_path.c_str()).c_str());
ui->combo_box_mode->setCurrentIndex(application.layers_mode);
}

void MainWindow::on_check_box_per_application_toggled(bool checked) {
Configurator &configurator = Configurator::Get();
configurator.environment.SetPerApplicationConfig(checked);

ui->combo_box_applications->setEnabled(configurator.environment.GetPerApplicationConfig());
if (checked) {
Application &application = configurator.environment.GetApplication(configurator.environment.GetActiveApplicationIndex());
ui->combo_box_mode->setCurrentIndex(application.layers_mode);
} else {
ui->combo_box_mode->setCurrentIndex(configurator.environment.GetMode());
}
}

void MainWindow::on_check_box_clear_on_launch_clicked() {
Expand All @@ -943,14 +967,16 @@ void MainWindow::OnConfigurationItemClicked(bool checked) {
// Someone just got checked, they are now the current profile
// This pointer will only be valid if it's one of the elements with
// the radio button
ConfigurationListItem *item = GetCheckedItem();
if (item == nullptr) return;
ConfigurationListItem *configuration_item = GetCheckedItem();
if (configuration_item == nullptr) {
return;
}

// This appears redundant on Windows, but under linux it is needed
// to ensure the new item is "selected"
// ui->tree_configurations->setCurrentItem(item);

Configurator::Get().ActivateConfiguration(item->configuration_name);
Configurator::Get().ActivateConfiguration(configuration_item->configuration_name);

UpdateUI();
}
Expand Down Expand Up @@ -1181,7 +1207,7 @@ void MainWindow::resizeEvent(QResizeEvent *event) {
if (event != nullptr) event->accept();

const QFontMetrics fm = ui->layers_tree->fontMetrics();
const int combo_width = (fm.size(Qt::TextSingleLine, "Application-Controlled").width() * 1.6);
const int combo_width = (fm.size(Qt::TextSingleLine, "Auto").width() * 1.6);
const int width = ui->layers_tree->width() - combo_width;

// ui->tree_layers_list->setColumnWidth(0, width);
Expand Down Expand Up @@ -1726,16 +1752,11 @@ bool MainWindow::eventFilter(QObject *target, QEvent *event) {
if (right_click) {
QListWidgetItem *item = ui->layers_tree->itemAt(right_click->pos());

const std::string text = item->text().toStdString();
if (text == TEXT_EXECUTE_CLOSER_APPLICATION) {
return false;
}
if (text == TEXT_EXECUTE_CLOSER_DRIVER) {
const Layer *layer = GetLayer(ui->layers_tree, item);
if (layer == nullptr) {
return false;
}

const Layer *layer = GetLayer(ui->layers_tree, item);

QMenu menu(ui->layers_tree);
QFont subtitle_font = menu.font();
subtitle_font.setBold(true);
Expand Down
Loading

0 comments on commit 27ebab7

Please sign in to comment.