Skip to content

Commit

Permalink
vkconfig3: Implement application launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Sep 19, 2024
1 parent 921e99c commit 24a2ab6
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 331 deletions.
26 changes: 0 additions & 26 deletions vkconfig_core/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,32 +494,6 @@ bool Configuration::IsBuiltIn() const {

static const size_t NOT_FOUND = static_cast<size_t>(-1);

static std::size_t ExtractDuplicateNumber(const std::string& configuration_name) {
const std::size_t name_open = configuration_name.find_last_of("(");
if (name_open == NOT_FOUND) {
return NOT_FOUND;
}

const std::size_t name_close = configuration_name.find_last_of(")");
if (name_close == NOT_FOUND) {
return NOT_FOUND;
}

const std::string number = configuration_name.substr(name_open + 1, name_close - (name_open + 1));
if (!IsNumber(number)) {
return NOT_FOUND;
}

return std::stoi(number);
}

static std::string ExtractDuplicateBaseName(const std::string& configuration_name) {
assert(ExtractDuplicateNumber(configuration_name) != NOT_FOUND);
const std::size_t found = configuration_name.find_last_of("(");
assert(found != NOT_FOUND);
return configuration_name.substr(0, found - 1);
}

std::string MakeConfigurationName(const std::vector<Configuration>& configurations, const std::string& configuration_name) {
const std::string key = configuration_name;
const std::string base_name = ExtractDuplicateNumber(key) != NOT_FOUND ? ExtractDuplicateBaseName(key) : key;
Expand Down
2 changes: 1 addition & 1 deletion vkconfig_core/configurations/3.0.0/Frame Capture.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{
"key": "capture_file",
"type": "SAVE_FILE",
"value": "${VK_LOCAL}/gfxrecon_capture.gfxr"
"value": "${VK_HOME}/gfxrecon_capture.gfxr"
}
],
"control": "on",
Expand Down
50 changes: 45 additions & 5 deletions vkconfig_core/executable_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "executable_manager.h"
#include "version.h"
#include "type_platform.h"
#include "util.h"

#include <QJsonArray>
#include <QTextStream>
Expand Down Expand Up @@ -57,6 +58,29 @@ bool ExecutableManager::Empty() const { return this->data.empty(); }

std::size_t ExecutableManager::Size() const { return this->data.size(); }

static const size_t NOT_FOUND = static_cast<size_t>(-1);

std::string ExecutableManager::MakeOptionsName(const std::string& name) const {
const std::string key = name;
const std::string base_name = ExtractDuplicateNumber(key) != NOT_FOUND ? ExtractDuplicateBaseName(key) : key;

const Executable* executable = GetActiveExecutable();

std::size_t max_duplicate = 0;
for (std::size_t i = 0, n = executable->options.size(); i < n; ++i) {
const std::string& search_name = executable->options[i].label;

if (search_name.compare(0, base_name.length(), base_name) != 0) {
continue;
}

const std::size_t found_number = ExtractDuplicateNumber(search_name);
max_duplicate = std::max<std::size_t>(max_duplicate, found_number != NOT_FOUND ? found_number : 1);
}

return base_name + (max_duplicate > 0 ? format(" (%d)", max_duplicate + 1).c_str() : "");
}

bool ExecutableManager::Load(const QJsonObject& json_root_object) {
// applications json object
const QJsonObject& json_executables_object = json_root_object.value("executables").toObject();
Expand Down Expand Up @@ -88,6 +112,9 @@ bool ExecutableManager::Load(const QJsonObject& json_root_object) {
ExecutableOptions executable_options;

executable_options.label = json_options_object.value("label").toString().toStdString();
executable_options.layers_mode =
GetLayersMode(json_options_object.value("layers_mode").toString().toStdString().c_str());
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 @@ -165,9 +192,14 @@ bool ExecutableManager::Save(QJsonObject& json_root_object) const {
return true;
}

void ExecutableManager::SelectActiveExecutable(std::size_t executable_index) {
assert(executable_index < this->data.size());
this->active_executable = this->data[executable_index].path;
void ExecutableManager::SetActiveExecutable(int executable_index) {
assert(executable_index < static_cast<int>(this->data.size()));

if (executable_index < 0) {
this->active_executable.Clear();
} else {
this->active_executable = this->data[executable_index].path;
}
}

int ExecutableManager::GetActiveExecutableIndex() const {
Expand All @@ -177,7 +209,6 @@ int ExecutableManager::GetActiveExecutableIndex() const {
}
}

assert(0);
return -1; // Not found, but the list is present, so return the first item.
}

Expand Down Expand Up @@ -222,6 +253,13 @@ bool ExecutableManager::RemoveExecutable(std::size_t executable_index) {
}

std::swap(this->data, new_executables);

if (this->data.empty()) {
this->active_executable.Clear();
} else {
this->active_executable = this->data[0].path;
}

return true;
}

Expand Down Expand Up @@ -376,12 +414,14 @@ Executable ExecutableManager::CreateDefaultExecutable(const DefaultExecutable& d
ExecutableOptions options;
options.label = "Default";
options.working_folder = default_paths.working_folder;
options.args.push_back(default_executable.arguments);

// On all operating systems, but Windows we keep running into problems with this ending up
// somewhere the user isn't allowed to create and write files. For consistncy sake, the log
// initially will be set to the users home folder across all OS's. This is highly visible
// in the application launcher and should not present a usability issue. The developer can
// easily change this later to anywhere they like.
options.log_file = std::string("${VK_LOCAL}") + default_executable.key + ".txt";
options.log_file = std::string("${VK_HOME}") + default_executable.key + ".txt";

Executable executable;
executable.path = Path(default_paths.executable_path.AbsolutePath(), true);
Expand Down
6 changes: 4 additions & 2 deletions vkconfig_core/executable_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct DefaultPath {
};

struct ExecutableOptions {
std::string label = "Default";
std::string label = "Default Options";
LayersMode layers_mode = LAYERS_CONTROLLED_BY_APPLICATIONS;
std::string configuration = "Validation";
Path working_folder;
Expand Down Expand Up @@ -68,7 +68,9 @@ class ExecutableManager : public Serialize {
bool Empty() const;
std::size_t Size() const;

void SelectActiveExecutable(std::size_t executable_index);
std::string MakeOptionsName(const std::string& name) const;

void SetActiveExecutable(int executable_index);
int GetActiveExecutableIndex() const;
bool AppendExecutable(const Executable& executable);
bool AppendExecutable(const Path& executable_path);
Expand Down
8 changes: 4 additions & 4 deletions vkconfig_core/test/test_executable_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ TEST(test_executable_manager, reset_default_applications_sdk_found) {
// Make sure the variable are not replaced
EXPECT_TRUE(executables[0].path.RelativePath().find("${VULKAN_SDK}") != std::string::npos);
EXPECT_TRUE(executables[0].options[0].working_folder.RelativePath().find("${VULKAN_SDK}") != std::string::npos);
EXPECT_TRUE(executables[0].options[0].log_file.RelativePath().find("${VK_LOCAL}") != std::string::npos);
EXPECT_TRUE(executables[0].options[0].log_file.RelativePath().find("${VK_HOME}") != std::string::npos);
EXPECT_TRUE(executables[1].path.RelativePath().find("${VULKAN_SDK}") != std::string::npos);
EXPECT_TRUE(executables[1].options[0].working_folder.RelativePath().find("${VULKAN_SDK}") != std::string::npos);
EXPECT_TRUE(executables[1].options[0].log_file.RelativePath().find("${VK_LOCAL}") != std::string::npos);
EXPECT_TRUE(executables[1].options[0].log_file.RelativePath().find("${VK_HOME}") != std::string::npos);
}
}

Expand All @@ -58,10 +58,10 @@ TEST(test_executable_manager, reset_default_applications_no_sdk) {
// Make sure the variable are not replaced
EXPECT_TRUE(executables[0].path.RelativePath().find("vkcube") != std::string::npos);
EXPECT_TRUE(executables[0].options[0].working_folder.RelativePath().find(".") != std::string::npos);
EXPECT_TRUE(executables[0].options[0].log_file.RelativePath().find("${VK_LOCAL}") != std::string::npos);
EXPECT_TRUE(executables[0].options[0].log_file.RelativePath().find("${VK_HOME}") != std::string::npos);
EXPECT_TRUE(executables[1].path.RelativePath().find("vkcubepp") != std::string::npos);
EXPECT_TRUE(executables[1].options[0].working_folder.RelativePath().find(".") != std::string::npos);
EXPECT_TRUE(executables[1].options[0].log_file.RelativePath().find("${VK_LOCAL}") != std::string::npos);
EXPECT_TRUE(executables[1].options[0].log_file.RelativePath().find("${VK_HOME}") != std::string::npos);
}

TEST(test_executable_manager, remove_missing_applications) {
Expand Down
28 changes: 28 additions & 0 deletions vkconfig_core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,31 @@ std::string GetLayerSettingPrefix(const std::string& key) {
result.remove("VK_LAYER_");
return ToLowerCase(result.toStdString()) + ".";
}

static const size_t NOT_FOUND = static_cast<size_t>(-1);

std::size_t ExtractDuplicateNumber(const std::string& name) {
const std::size_t name_open = name.find_last_of("(");
if (name_open == NOT_FOUND) {
return NOT_FOUND;
}

const std::size_t name_close = name.find_last_of(")");
if (name_close == NOT_FOUND) {
return NOT_FOUND;
}

const std::string number = name.substr(name_open + 1, name_close - (name_open + 1));
if (!IsNumber(number)) {
return NOT_FOUND;
}

return std::stoi(number);
}

std::string ExtractDuplicateBaseName(const std::string& name) {
assert(ExtractDuplicateNumber(name) != NOT_FOUND);
const std::size_t found = name.find_last_of("(");
assert(found != NOT_FOUND);
return name.substr(0, found - 1);
}
4 changes: 4 additions & 0 deletions vkconfig_core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,7 @@ std::vector<T> GetVector(const T& value) {
result.push_back(value);
return result;
}

std::size_t ExtractDuplicateNumber(const std::string& name);

std::string ExtractDuplicateBaseName(const std::string& name);
Loading

0 comments on commit 24a2ab6

Please sign in to comment.