Skip to content

Commit

Permalink
vkconfig3: Fix layer ordering and layer path enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Nov 4, 2024
1 parent 296d0ba commit 0053e43
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 94 deletions.
40 changes: 20 additions & 20 deletions vkconfig_core/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void AddApplicationEnabledParameters(std::vector<Parameter>& parameters)
applications_enabled_layers_api.key = ::GetLabel(LAYER_BUILTIN_API);
applications_enabled_layers_api.builtin = LAYER_BUILTIN_API;
applications_enabled_layers_api.control = LAYER_CONTROL_DISCARD; // Until the Vulkan Loader is fixed
applications_enabled_layers_api.overridden_rank = 998;
applications_enabled_layers_api.overridden_rank = Parameter::NO_RANK;
parameters.push_back(applications_enabled_layers_api);
}

Expand All @@ -76,7 +76,7 @@ static void AddApplicationEnabledParameters(std::vector<Parameter>& parameters)
applications_enabled_layers_env.key = ::GetLabel(LAYER_BUILTIN_ENV);
applications_enabled_layers_env.builtin = LAYER_BUILTIN_ENV;
applications_enabled_layers_env.control = LAYER_CONTROL_DISCARD; // Until the Vulkan Loader is fixed
applications_enabled_layers_env.overridden_rank = 999;
applications_enabled_layers_env.overridden_rank = Parameter::NO_RANK;
parameters.push_back(applications_enabled_layers_env);
}
}
Expand All @@ -87,8 +87,6 @@ Configuration Configuration::Create(const LayerManager& layers, const std::strin
result.key = configuration_key;
result.GatherParameters(layers);

AddApplicationEnabledParameters(result.parameters);

return result;
}

Expand All @@ -101,8 +99,6 @@ Configuration Configuration::CreateDisabled(const LayerManager& layers) {
result.parameters[i].control = LAYER_CONTROL_OFF;
}

AddApplicationEnabledParameters(result.parameters);

return result;
}

Expand Down Expand Up @@ -249,8 +245,6 @@ bool Configuration::Load(const Path& full_path, const LayerManager& layers) {

this->GatherParameters(layers);

AddApplicationEnabledParameters(this->parameters);

return true;
}

Expand Down Expand Up @@ -379,7 +373,7 @@ void Configuration::Reset(const LayerManager& layers) {
const bool result = this->Load(builtin_configuration_files[i], layers);
assert(result);

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

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

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

OrderParameter(this->parameters, layers);
// OrderParameter(this->parameters, layers);
}
}

Expand All @@ -421,27 +415,31 @@ bool Configuration::HasMissingLayer(const LayerManager& layers, std::vector<std:
continue;
}

if (it->control == LAYER_CONTROL_OFF) {
continue; // If excluded are missing, it doesn't matter
if (it->control != LAYER_CONTROL_ON) {
continue; // If not on, let's say it doesn't matter so it's not notified to the users
}

if (layers.Find(it->key, it->api_version) == nullptr) {
missing_layers.push_back(it->key);
continue;
}
/*
if (layers.Find(it->key, it->api_version) == nullptr) {
missing_layers.push_back(it->key);
continue;
}
*/

if (layers.FindFromManifest(it->manifest) == nullptr) {
missing_layers.push_back(it->key);
continue;
}
*/
}

return !missing_layers.empty();
}

void Configuration::SwitchLayerVersion(const LayerManager& layers, const std::string& layer_key, const Path& manifest_path) {
assert(!manifest_path.Empty());
if (manifest_path.Empty()) {
this->SwitchLayerLatest(layers, layer_key);
return;
}

Parameter* parameter = this->Find(layer_key);
assert(parameter != nullptr);
Expand Down Expand Up @@ -497,7 +495,9 @@ void Configuration::GatherParameters(const LayerManager& layers) {
gathered_parameters.push_back(parameter);
}

// OrderParameter(gathered_parameters, layers);
::AddApplicationEnabledParameters(gathered_parameters);

::OrderParameter(gathered_parameters, layers);

this->parameters = gathered_parameters;
}
Expand Down
4 changes: 3 additions & 1 deletion vkconfig_core/configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ void ConfigurationManager::LoadConfigurationsPath(const LayerManager &layers) {
continue;
}

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

available_configurations.push_back(configuration);
}
Expand Down
26 changes: 20 additions & 6 deletions vkconfig_core/layer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ bool LayerManager::Save(QJsonObject &json_root_object) const {

QJsonObject json_paths_object;
for (int paths_type_index = LAYERS_PATHS_FIRST; paths_type_index <= LAYERS_PATHS_LAST; ++paths_type_index) {
for (std::size_t i = 0, n = this->paths[paths_type_index].size(); i < n; ++i) {
json_paths_object.insert(this->paths[paths_type_index][i].path.RelativePath().c_str(),
this->paths[paths_type_index][i].enabled);
const std::vector<LayersPathInfo> &path_infos = this->paths[paths_type_index];

for (std::size_t i = 0, n = path_infos.size(); i < n; ++i) {
json_paths_object.insert(path_infos[i].path.RelativePath().c_str(), path_infos[i].enabled);
}
}

Expand Down Expand Up @@ -341,17 +342,25 @@ const Layer *LayerManager::FindLastModified(const std::string &layer_name, const
return result;
}

const Layer *LayerManager::FindFromManifest(const Path &manifest_path) const {
const Layer *LayerManager::FindFromManifest(const Path &manifest_path, bool find_disabled_layers) const {
for (std::size_t i = 0, n = this->selected_layers.size(); i < n; ++i) {
if (!find_disabled_layers && this->selected_layers[i].enabled == false) {
continue;
}

if (this->selected_layers[i].manifest_path == manifest_path) {
return &this->selected_layers[i];
}
}
return nullptr;
}

Layer *LayerManager::FindFromManifest(const Path &manifest_path) {
Layer *LayerManager::FindFromManifest(const Path &manifest_path, bool find_disabled_layers) {
for (std::size_t i = 0, n = this->selected_layers.size(); i < n; ++i) {
if (!find_disabled_layers && this->selected_layers[i].enabled == false) {
continue;
}

if (this->selected_layers[i].manifest_path == manifest_path) {
return &this->selected_layers[i];
}
Expand All @@ -369,6 +378,7 @@ void LayerManager::LoadAllInstalledLayers() {
const std::vector<LayersPathInfo> &paths_group = this->paths[group_index];
for (std::size_t i = 0, n = paths_group.size(); i < n; ++i) {
this->LoadLayersFromPath(paths_group[i].path, paths_group[i].type);
this->UpdatePathEnabled(paths_group[i]);
}
}
}
Expand Down Expand Up @@ -457,7 +467,7 @@ void LayerManager::UpdatePathEnabled(const LayersPathInfo &path_info) {
const std::vector<Path> &layers_paths = CollectFilePaths(path_info.path);

for (std::size_t i = 0, n = layers_paths.size(); i < n; ++i) {
Layer *layer = this->FindFromManifest(layers_paths[i]);
Layer *layer = this->FindFromManifest(layers_paths[i], true);
if (layer == nullptr) {
continue;
}
Expand All @@ -470,6 +480,10 @@ std::vector<std::string> LayerManager::BuildLayerNameList() const {
std::vector<std::string> result;

for (std::size_t i = 0, n = this->selected_layers.size(); i < n; ++i) {
if (this->selected_layers[i].enabled == false) {
continue;
}

if (std::find(result.begin(), result.end(), this->selected_layers[i].key) != result.end()) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/layer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class LayerManager : public Serialize {
std::vector<Version> GatherVersions(const std::string& layer_name) const;
const Layer* Find(const std::string& layer_name, const Version& version = Version::LATEST) const;
const Layer* FindLastModified(const std::string& layer_name, const Version& version) const;
const Layer* FindFromManifest(const Path& manifest_path) const;
Layer* FindFromManifest(const Path& manifest_path);
const Layer* FindFromManifest(const Path& manifest_path, bool find_disabled_layers = false) const;
Layer* FindFromManifest(const Path& manifest_path, bool find_disabled_layers = false);

void LoadAllInstalledLayers();
void LoadLayersFromPath(const Path& layers_path, LayerType type = LAYER_TYPE_EXPLICIT);
Expand Down
56 changes: 25 additions & 31 deletions vkconfig_core/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,19 @@ ParameterRank GetParameterOrdering(const LayerManager& layers, const Parameter&
assert(!parameter.key.empty());

const Layer* layer = layers.Find(parameter.key, parameter.api_version);
if (layer == nullptr) {
return PARAMETER_RANK_MISSING;
} else if (parameter.control == LAYER_CONTROL_OFF) {
return PARAMETER_RANK_EXCLUDED;
} else if (parameter.control == LAYER_CONTROL_AUTO && layer->type == LAYER_TYPE_IMPLICIT) {
return PARAMETER_RANK_IMPLICIT_AVAILABLE;
} else if (parameter.control == LAYER_CONTROL_ON && layer->type == LAYER_TYPE_IMPLICIT) {
return PARAMETER_RANK_IMPLICIT_OVERRIDDEN;
} else if (parameter.control == LAYER_CONTROL_ON && layer->type != LAYER_TYPE_IMPLICIT) {
return PARAMETER_RANK_EXPLICIT_OVERRIDDEN;
} else if (parameter.control == LAYER_CONTROL_AUTO && layer->type != LAYER_TYPE_IMPLICIT) {
return PARAMETER_RANK_EXPLICIT_AVAILABLE;
if (parameter.builtin == LAYER_BUILTIN_ENV) {
return PARAMETER_RANK_APPPLICATION_ENV;
} else if (parameter.builtin == LAYER_BUILTIN_API) {
return PARAMETER_RANK_APPPLICATION_API;
} else if (layer == nullptr) {
return PARAMETER_RANK_MISSING_LAYER;
} else if (layer->type == LAYER_TYPE_IMPLICIT) {
return PARAMETER_RANK_IMPLICIT_LAYER;
} else if (layer->type == LAYER_TYPE_EXPLICIT) {
return PARAMETER_RANK_EXPLICIT_LAYER;
} else {
assert(0); // Unknown ordering
return PARAMETER_RANK_MISSING;
return PARAMETER_RANK_MISSING_LAYER;
}
}

Expand All @@ -85,31 +83,23 @@ void OrderParameter(std::vector<Parameter>& parameters, const LayerManager& laye
const ParameterRank rankA = GetParameterOrdering(layers, a);
const ParameterRank rankB = GetParameterOrdering(layers, b);

const bool both_ranked = a.overridden_rank != Parameter::NO_RANK && b.overridden_rank != Parameter::NO_RANK;
const bool both_overridden = a.overridden_rank != Parameter::NO_RANK && b.overridden_rank != Parameter::NO_RANK;

if (rankA == rankB && a.control == LAYER_CONTROL_ON)
if (a.overridden_rank != Parameter::NO_RANK && b.overridden_rank != Parameter::NO_RANK)
return a.overridden_rank < b.overridden_rank;
else if (a.key == VK_LAYER_KHRONOS_PROFILES_NAME)
return false;
else if (b.key == VK_LAYER_KHRONOS_PROFILES_NAME)
return true;
else if (a.key == VK_LAYER_KHRONOS_VALIDATION_NAME && b.key == VK_LAYER_KHRONOS_PROFILES_NAME)
if (both_overridden)
return a.overridden_rank < b.overridden_rank;
else if (rankA == rankB)
if (a.key == VK_LAYER_KHRONOS_VALIDATION_NAME && b.key == VK_LAYER_KHRONOS_PROFILES_NAME)
return true;
else if (a.key == VK_LAYER_KHRONOS_PROFILES_NAME && b.key == VK_LAYER_KHRONOS_VALIDATION_NAME)
return false;
else if (a.key == VK_LAYER_KHRONOS_VALIDATION_NAME)
return true;
else if (b.key == VK_LAYER_KHRONOS_VALIDATION_NAME)
return false;
else
return a.key < b.key;
else if (both_ranked && rankA == PARAMETER_RANK_IMPLICIT_OVERRIDDEN && rankB == PARAMETER_RANK_EXPLICIT_OVERRIDDEN)
return a.overridden_rank < b.overridden_rank;
else if (both_ranked && rankA == PARAMETER_RANK_EXPLICIT_OVERRIDDEN && rankB == PARAMETER_RANK_IMPLICIT_OVERRIDDEN)
return a.overridden_rank < b.overridden_rank;
else if (rankA == rankB && a.control != LAYER_CONTROL_ON)
return a.key < b.key;
else if (rankA != rankB)
return rankA < rankB;
else
return a.key < b.key;
return rankA < rankB;
}

const LayerManager& layers;
Expand All @@ -127,6 +117,10 @@ void OrderParameter(std::vector<Parameter>& parameters, const LayerManager& laye

bool HasMissingLayer(const std::vector<Parameter>& parameters, const LayerManager& layers, std::string& missing_layer) {
for (auto it = parameters.begin(), end = parameters.end(); it != end; ++it) {
if (it->builtin != LAYER_BUILTIN_NONE) {
continue; // If application API or ENV layers
}

if (it->control == LAYER_CONTROL_OFF) {
continue; // If excluded are missing, it doesn't matter
}
Expand Down
11 changes: 5 additions & 6 deletions vkconfig_core/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
#include <vector>

enum ParameterRank {
PARAMETER_RANK_MISSING = 0,
PARAMETER_RANK_EXCLUDED,
PARAMETER_RANK_IMPLICIT_AVAILABLE,
PARAMETER_RANK_IMPLICIT_OVERRIDDEN,
PARAMETER_RANK_EXPLICIT_OVERRIDDEN,
PARAMETER_RANK_EXPLICIT_AVAILABLE
PARAMETER_RANK_MISSING_LAYER = 0,
PARAMETER_RANK_IMPLICIT_LAYER,
PARAMETER_RANK_EXPLICIT_LAYER,
PARAMETER_RANK_APPPLICATION_ENV,
PARAMETER_RANK_APPPLICATION_API,
};

struct Parameter {
Expand Down
1 change: 0 additions & 1 deletion vkconfig_core/test/Configuration 3.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"layers": [
{
"name": "VK_LAYER_LUNARG_reference_1_2_1",
"rank": 8,
"version": "latest",
"settings": [
{
Expand Down
6 changes: 3 additions & 3 deletions vkconfig_core/test/test_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ TEST(test_parameter, apply_settings) {
TEST(test_parameter, ordering_no_layers) {
LayerManager layer_manager;

EXPECT_EQ(PARAMETER_RANK_MISSING, GetParameterOrdering(layer_manager, Parameter("Layer", LAYER_CONTROL_AUTO)));
EXPECT_EQ(PARAMETER_RANK_MISSING, GetParameterOrdering(layer_manager, Parameter("Layer", LAYER_CONTROL_ON)));
EXPECT_EQ(PARAMETER_RANK_MISSING, GetParameterOrdering(layer_manager, Parameter("Layer", LAYER_CONTROL_OFF)));
EXPECT_EQ(PARAMETER_RANK_MISSING_LAYER, GetParameterOrdering(layer_manager, Parameter("Layer", LAYER_CONTROL_AUTO)));
EXPECT_EQ(PARAMETER_RANK_MISSING_LAYER, GetParameterOrdering(layer_manager, Parameter("Layer", LAYER_CONTROL_ON)));
EXPECT_EQ(PARAMETER_RANK_MISSING_LAYER, GetParameterOrdering(layer_manager, Parameter("Layer", LAYER_CONTROL_OFF)));
}
/*
TEST(test_parameter, ordering_found_custom_layers) {
Expand Down
18 changes: 13 additions & 5 deletions vkconfig_gui/settings_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@ void SettingsTreeManager::CreateGUI() {
Parameter *parameter = configuration != nullptr ? configuration->GetActiveParameter() : nullptr;
const bool no_selected_layer = configuration != nullptr ? configuration->selected_layer_name.empty() : false;

if (parameter != nullptr) {
if (parameter->manifest.Empty()) {
configuration->SwitchLayerLatest(configurator.layers, configuration->GetActiveParameter()->key);
} else {
configuration->SwitchLayerVersion(configurator.layers, configuration->GetActiveParameter()->key, parameter->manifest);
}
}

// Group box things
const Layer *layer = parameter != nullptr ? configurator.layers.Find(parameter->key, parameter->api_version) : nullptr;
const Layer *layer = parameter != nullptr ? configurator.layers.FindFromManifest(parameter->manifest) : nullptr;

if (no_selected_layer) {
this->ui->configurations_group_box_settings->setTitle("Select a layer to display settings");
Expand All @@ -93,10 +101,10 @@ void SettingsTreeManager::CreateGUI() {
this->ui->configurations_presets->setVisible(!layer->presets.empty());
}

const std::vector<Path> &layer_version = configurator.layers.GatherManifests(parameter->key);
this->layer_version->setVisible(layer_version.size() > 1);
if (layer_version.size() > 1) {
this->layer_version->Init(*parameter, layer_version);
const std::vector<Path> &layer_versions = configurator.layers.GatherManifests(parameter->key);
this->layer_version->setVisible(!layer_versions.empty());
if (!layer_versions.empty()) {
this->layer_version->Init(*parameter, layer_versions);
}

// preset combobox
Expand Down
6 changes: 3 additions & 3 deletions vkconfig_gui/tab_configurations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ void TabConfigurations::UpdateUI_Configurations(UpdateUIMode ui_update_mode) {
const bool has_missing_layer = configuration.HasMissingLayer(configurator.layers, missing_layers);

// Hide built-in configuration when the layer is missing. The Vulkan user may have not installed the necessary layer
if (configuration.IsBuiltIn() && has_missing_layer) {
continue;
}
// if (configuration.IsBuiltIn() && has_missing_layer) {
// continue;
//}

ListItem *item = new ListItem(configuration.key.c_str());
item->setFlags(item->flags() | Qt::ItemIsEditable);
Expand Down
Loading

0 comments on commit 0053e43

Please sign in to comment.