Skip to content

Commit

Permalink
vkconfig3: Implement layer version switching
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Sep 6, 2024
1 parent 15358e0 commit 9e41caf
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 97 deletions.
2 changes: 1 addition & 1 deletion vkconfig_cmd/main_doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int run_doc_settings(const CommandLine& command_line) {

ConfigurationManager configuration_manager;
Configuration config = configuration_manager.CreateConfiguration(layers, "Config");
config.parameters = GatherParameters(config.parameters, layers);
config.GatherParameters(layers);
config.parameters[0].control = LAYER_CONTROL_ON;
ExportSettingsDoc(layers.selected_layers, config, command_line.doc_out_dir + "/vk_layer_settings.txt");

Expand Down
104 changes: 93 additions & 11 deletions vkconfig_core/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Configuration Configuration::Create(const LayerManager& layers, const std::strin
Configuration result;

result.key = key;
result.parameters = GatherParameters(result.parameters, layers);
result.GatherParameters(layers);

AddApplicationEnabledParameters(result.parameters);

Expand All @@ -93,7 +93,7 @@ Configuration Configuration::Create(const LayerManager& layers, const std::strin
Configuration Configuration::CreateDisabled(const LayerManager& layers) {
Configuration result;
result.key = "_DisablingConfiguration";
result.parameters = GatherParameters(result.parameters, layers);
result.GatherParameters(layers);

for (std::size_t i = 0, n = result.parameters.size(); i < n; ++i) {
result.parameters[i].control = LAYER_CONTROL_OFF;
Expand Down Expand Up @@ -239,7 +239,7 @@ bool Configuration::Load(const Path& full_path, const LayerManager& layers) {
this->parameters.push_back(parameter);
}

this->parameters = GatherParameters(this->parameters, layers);
this->GatherParameters(layers);

AddApplicationEnabledParameters(this->parameters);

Expand Down Expand Up @@ -337,9 +337,9 @@ bool Configuration::Save(const Path& full_path, bool exporter) const {
}
}

Parameter* Configuration::Find(std::string parameter_key) {
Parameter* Configuration::Find(const std::string& layer_key) {
for (std::size_t i = 0, n = this->parameters.size(); i < n; ++i) {
if (this->parameters[i].key == parameter_key) {
if (this->parameters[i].key == layer_key) {
return &this->parameters[i];
}
}
Expand All @@ -357,7 +357,7 @@ void Configuration::Reset(const LayerManager& layers) {
const bool result = this->Load(builtin_configuration_files[i], layers);
assert(result);

OrderParameter(this->parameters, layers.selected_layers);
OrderParameter(this->parameters, layers);
return;
}
}
Expand All @@ -371,7 +371,7 @@ void Configuration::Reset(const LayerManager& layers) {
const bool result = this->Load(full_path, layers);
assert(result);

OrderParameter(this->parameters, layers.selected_layers);
OrderParameter(this->parameters, layers);
return;
}

Expand All @@ -385,7 +385,7 @@ void Configuration::Reset(const LayerManager& layers) {
}
}

OrderParameter(this->parameters, layers.selected_layers);
OrderParameter(this->parameters, layers);
}
}

Expand All @@ -403,6 +403,82 @@ bool Configuration::HasOverride() const {
return false;
}

void Configuration::SwitchLayerVersion(const LayerManager& layers, const std::string& layer_key, const Version& version) {
Parameter* parameter = this->Find(layer_key);
assert(parameter != nullptr);

const Layer* new_layer = layers.Find(layer_key, version);

parameter->api_version = version;
CollectDefaultSettingData(new_layer->settings, parameter->settings);
}

void Configuration::GatherParameters(const LayerManager& layers) {
const std::vector<Parameter>& previous_parameters = this->parameters;

std::vector<Parameter> gathered_parameters;

// Loop through the layers. They are expected to be in order
for (std::size_t i = 0, n = parameters.size(); i < n; ++i) {
const Parameter& parameter = parameters[i];
assert(!parameter.key.empty());

gathered_parameters.push_back(parameter);
}

const std::vector<std::string>& list = layers.BuildLayerNameList();

for (std::size_t i = 0, n = list.size(); i < n; ++i) {
const Layer* layer = layers.Find(list[i], Version::LATEST);

// The layer is already in the layer tree
if (this->Find(layer->key.c_str())) {
continue;
}

Parameter parameter;
parameter.key = layer->key;
parameter.control = LAYER_CONTROL_AUTO;
parameter.api_version = Version::LATEST;
CollectDefaultSettingData(layer->settings, parameter.settings);

gathered_parameters.push_back(parameter);
}

// OrderParameter(gathered_parameters, layers);

this->parameters = gathered_parameters;
}

void Configuration::Reorder(const std::vector<std::string>& layer_names) {
std::vector<Parameter> ordered_parameters;

for (std::size_t i = 0, n = layer_names.size(); i < n; ++i) {
Parameter* parameter = this->Find(layer_names[i]);
assert(parameter != nullptr);
ordered_parameters.push_back(*parameter);
}

if (!this->view_advanced_layers) {
for (std::size_t i = 0, n = this->parameters.size(); i < n; ++i) {
Parameter& parameter = this->parameters[i];

bool found = false;
for (std::size_t j = 0, o = ordered_parameters.size(); j < o; ++j) {
if (ordered_parameters[j].key == parameter.key) {
found = true;
}
}

if (!found) {
ordered_parameters.push_back(parameter);
}
}
}

this->parameters = ordered_parameters;
}

bool Configuration::IsBuiltIn() const {
const std::vector<Path>& builtin_configuration_files = CollectFilePaths(":/configurations/");
for (std::size_t i = 0, n = builtin_configuration_files.size(); i < n; ++i) {
Expand All @@ -420,13 +496,19 @@ 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;
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;
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;
if (!IsNumber(number)) {
return NOT_FOUND;
}

return std::stoi(number);
}
Expand Down
11 changes: 7 additions & 4 deletions vkconfig_core/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ class LayerManager;
class Configuration {
public:
static Configuration CreateDisabled(const LayerManager& layers);
static Configuration Create(const LayerManager& layers, const std::string& key);
static Configuration Create(const LayerManager& layers, const std::string& layer_key);

bool Load(const Path& full_path, const LayerManager& layers);
bool Save(const Path& full_path, bool exporter = false) const;
bool HasOverride() const;
Parameter* Find(std::string parameter_key);

void Reset(const LayerManager& layers);

bool HasOverride() const;
Parameter* Find(const std::string& layer_key);
std::size_t Size() const { return this->parameters.size(); };

void SwitchLayerVersion(const LayerManager& layers, const std::string& layer_key, const Version& version);
void GatherParameters(const LayerManager& layers);
void Reorder(const std::vector<std::string>& layer_names);

std::string key = "New Configuration"; // User readable display of the configuration name (may contain spaces)
int version = 1;
int platform_flags = PLATFORM_DESKTOP_BIT;
Expand Down
32 changes: 23 additions & 9 deletions vkconfig_core/configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ bool ConfigurationManager::Load(const QJsonObject &json_root_object) {
this->active_application = json_configurations_object.value("active_application").toString().toStdString();

if (json_configurations_object.value("infos") != QJsonValue::Undefined) {
this->configuration_infos.clear();

const QJsonObject &json_infos_object = json_configurations_object.value("infos").toObject();
const QStringList &json_infos_keys = json_infos_object.keys();
for (int i = 0, n = json_infos_keys.length(); i < n; ++i) {
Expand Down Expand Up @@ -145,7 +147,7 @@ void ConfigurationManager::LoadDefaultConfigurations(const LayerManager &layers)
}
#endif

OrderParameter(configuration.parameters, layers.selected_layers);
OrderParameter(configuration.parameters, layers);

Configuration *found_configuration = this->FindConfiguration(configuration.key);
if (found_configuration == nullptr) {
Expand Down Expand Up @@ -184,13 +186,13 @@ void ConfigurationManager::LoadConfigurationsPath(const LayerManager &layers) {
continue;
}

if (FindByKey(available_configurations, configuration.key.c_str()) != nullptr) {
if (this->FindConfiguration(configuration.key) != nullptr) {
continue;
}

std::string missing_layer;
if (!HasMissingLayer(configuration.parameters, layers.selected_layers, missing_layer)) {
OrderParameter(configuration.parameters, layers.selected_layers);
if (!HasMissingLayer(configuration.parameters, layers, missing_layer)) {
OrderParameter(configuration.parameters, layers);
}

available_configurations.push_back(configuration);
Expand Down Expand Up @@ -255,7 +257,7 @@ bool ConfigurationManager::HasActiveConfiguration() const {

Configuration &ConfigurationManager::CreateConfiguration(const LayerManager &layers, const std::string &configuration_name,
bool duplicate) {
Configuration *duplicate_configuration = FindByKey(available_configurations, configuration_name.c_str());
Configuration *duplicate_configuration = this->FindConfiguration(configuration_name);

Configuration new_configuration = duplicate_configuration != nullptr && duplicate ? *duplicate_configuration : Configuration();
new_configuration.key = MakeConfigurationName(available_configurations, configuration_name);
Expand All @@ -273,7 +275,7 @@ Configuration &ConfigurationManager::CreateConfiguration(const LayerManager &lay

this->GetActiveConfigurationInfo()->name = configuration.key;

return *FindByKey(this->available_configurations, configuration.key.c_str());
return *this->FindConfiguration(configuration.key);
}

bool ConfigurationManager::HasFile(const Configuration &configuration) const {
Expand Down Expand Up @@ -344,7 +346,13 @@ Configuration *ConfigurationManager::FindConfiguration(const std::string &config
return nullptr;
}

return FindByKey(this->available_configurations, configuration_name.c_str());
for (std::size_t i = 0, n = this->available_configurations.size(); i < n; ++i) {
if (this->available_configurations[i].key == configuration_name) {
return &this->available_configurations[i];
}
}

return nullptr;
}

const Configuration *ConfigurationManager::FindConfiguration(const std::string &configuration_name) const {
Expand All @@ -356,7 +364,13 @@ const Configuration *ConfigurationManager::FindConfiguration(const std::string &
return nullptr;
}

return FindByKey(this->available_configurations, configuration_name.c_str());
for (std::size_t i = 0, n = this->available_configurations.size(); i < n; ++i) {
if (this->available_configurations[i].key == configuration_name) {
return &this->available_configurations[i];
}
}

return nullptr;
}

void ConfigurationManager::ImportConfiguration(const LayerManager &layers, const Path &full_import_path) {
Expand Down Expand Up @@ -385,7 +399,7 @@ void ConfigurationManager::ExportConfiguration(const LayerManager &layers, const
assert(!configuration_name.empty());
assert(!full_export_path.Empty());

Configuration *configuration = FindByKey(available_configurations, configuration_name.c_str());
Configuration *configuration = this->FindConfiguration(configuration_name);
assert(configuration);

if (!configuration->Save(full_export_path, true)) {
Expand Down
2 changes: 1 addition & 1 deletion vkconfig_core/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void Configurator::BuildLoaderSettings(const ConfigurationInfo& info, const std:
if (parameter.control == LAYER_CONTROL_APPLICATIONS_API || parameter.control == LAYER_CONTROL_APPLICATIONS_ENV) {
loader_layer_settings.control = parameter.control;
} else {
const Layer* layer = FindByKey(this->layers.selected_layers, parameter.key.c_str());
const Layer* layer = this->layers.Find(parameter.key, parameter.api_version);
if (layer == nullptr) {
continue;
}
Expand Down
Loading

0 comments on commit 9e41caf

Please sign in to comment.