Skip to content

Commit 3cb6251

Browse files
vkconfig: Improve layers tab
Change-Id: Ie81261c89228ad4ba89b71da3207b255eefd9e72
1 parent 796d193 commit 3cb6251

8 files changed

Lines changed: 116 additions & 129 deletions

File tree

vkconfig_core/layer.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@
4949
#include <string>
5050
#include <algorithm>
5151

52-
bool operator<(const LayersPathInfo& a, const LayersPathInfo& b) { return a.path.RelativePath() < b.path.RelativePath(); }
53-
54-
bool Found(const std::vector<LayersPathInfo>& data, const Path& path) {
52+
bool Found(const std::vector<Path>& data, const Path& path) {
5553
for (std::size_t i = 0, n = data.size(); i < n; ++i) {
56-
if (data[i].path == path) {
54+
if (data[i] == path) {
5755
return true;
5856
}
5957
}
@@ -407,6 +405,14 @@ LayerLoadStatus Layer::Load(const Path& full_path_to_file, LayerType type, bool
407405
return this->IsValid() ? LAYER_LOAD_ADDED : LAYER_LOAD_INVALID; // Not all JSON file are layer JSON valid
408406
}
409407

408+
bool operator<(const Layer& layer_a, const Layer& layer_b) {
409+
if (layer_a.key == layer_b.key) {
410+
return layer_a.api_version < layer_b.api_version;
411+
} else {
412+
return layer_a.key < layer_b.key;
413+
}
414+
}
415+
410416
void CollectDefaultSettingData(const SettingMetaSet& meta_set, SettingDataSet& data_set) {
411417
for (std::size_t i = 0, n = meta_set.size(); i < n; ++i) {
412418
SettingMeta* setting_meta = meta_set[i];

vkconfig_core/layer.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,13 @@
3737
#include <string>
3838

3939
struct LayerStatus {
40+
LayerType type = LAYER_TYPE_EXPLICIT;
4041
std::string last_modified;
4142
bool validated = false;
42-
bool disabled = false;
43-
};
44-
45-
struct LayersPathInfo {
46-
Path path;
47-
LayerType type = LAYER_TYPE_EXPLICIT;
4843
bool enabled = true;
4944
};
5045

51-
bool operator<(const LayersPathInfo& a, const LayersPathInfo& b);
52-
53-
bool Found(const std::vector<LayersPathInfo>& data, const Path& path);
46+
bool Found(const std::vector<Path>& data, const Path& path);
5447

5548
enum LayerLoadStatus {
5649
LAYER_LOAD_ADDED = 0,
@@ -129,4 +122,6 @@ class Layer {
129122
std::vector<std::shared_ptr<SettingMeta> > memory; // Settings are deleted when all layers instances are deleted.
130123
};
131124

125+
bool operator<(const Layer& layer_a, const Layer& layer_b);
126+
132127
void CollectDefaultSettingData(const SettingMetaSet& meta_set, SettingDataSet& data_set);

vkconfig_core/layer_manager.cpp

Lines changed: 63 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,34 @@
2525

2626
#include <QJsonArray>
2727

28-
std::vector<LayersPathInfo> GetEnvVariablePaths(const char *variable_name, LayerType type) {
29-
std::vector<LayersPathInfo> result;
28+
static std::vector<Path> GetEnvVariablePaths(const char *variable_name, LayerType type) {
29+
std::vector<Path> result;
3030

3131
const char *SEPARATOR = GetToken(PARSE_ENV_VAR);
3232

3333
const std::vector<std::string> &paths = UniqueStrings(Split(qgetenv(variable_name).toStdString(), SEPARATOR));
3434
result.resize(paths.size());
3535
for (std::size_t i = 0, n = paths.size(); i < n; ++i) {
36-
result[i].path = paths[i];
37-
result[i].enabled = true;
38-
result[i].type = type;
36+
result[i] = paths[i];
3937
}
4038

4139
return result;
4240
}
4341

44-
std::vector<LayersPathInfo> GetImplicitLayerPaths() {
45-
std::vector<LayersPathInfo> result;
42+
static std::vector<Path> GetImplicitLayerPaths() {
43+
std::vector<Path> result;
4644

4745
#if VKC_ENV == VKC_ENV_WIN32
48-
const std::vector<LayersPathInfo> &admin_registry_paths =
46+
const std::vector<Path> &admin_registry_paths =
4947
LoadRegistrySoftwareLayers("HKEY_LOCAL_MACHINE\\Software\\Khronos\\Vulkan\\ImplicitLayers", LAYER_TYPE_IMPLICIT);
5048
result.insert(result.begin(), admin_registry_paths.begin(), admin_registry_paths.end());
5149

52-
const std::vector<LayersPathInfo> &user_registry_paths =
50+
const std::vector<Path> &user_registry_paths =
5351
LoadRegistrySoftwareLayers("HKEY_CURRENT_USER\\Software\\Khronos\\Vulkan\\ImplicitLayers", LAYER_TYPE_IMPLICIT);
5452
result.insert(result.begin(), user_registry_paths.begin(), user_registry_paths.end());
5553

5654
// Search for drivers specific layers
57-
const std::vector<LayersPathInfo> &drivers_registry_paths =
55+
const std::vector<Path> &drivers_registry_paths =
5856
LoadRegistrySystemLayers("HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Class\\...\\VulkanImplicitLayers");
5957
result.insert(result.begin(), drivers_registry_paths.begin(), drivers_registry_paths.end());
6058
#else
@@ -101,20 +99,20 @@ std::vector<LayersPathInfo> GetImplicitLayerPaths() {
10199
return result;
102100
}
103101

104-
std::vector<LayersPathInfo> GetExplicitLayerPaths() {
105-
std::vector<LayersPathInfo> result;
102+
std::vector<Path> GetExplicitLayerPaths() {
103+
std::vector<Path> result;
106104

107105
#if VKC_ENV == VKC_ENV_WIN32
108-
const std::vector<LayersPathInfo> &admin_registry_paths =
106+
const std::vector<Path> &admin_registry_paths =
109107
LoadRegistrySoftwareLayers("HKEY_LOCAL_MACHINE\\Software\\Khronos\\Vulkan\\ExplicitLayers", LAYER_TYPE_EXPLICIT);
110108
result.insert(result.begin(), admin_registry_paths.begin(), admin_registry_paths.end());
111109

112-
const std::vector<LayersPathInfo> &user_registry_paths =
110+
const std::vector<Path> &user_registry_paths =
113111
LoadRegistrySoftwareLayers("HKEY_CURRENT_USER\\Software\\Khronos\\Vulkan\\ExplicitLayers", LAYER_TYPE_EXPLICIT);
114112
result.insert(result.begin(), user_registry_paths.begin(), user_registry_paths.end());
115113

116114
// Search for drivers specific layers
117-
const std::vector<LayersPathInfo> &drivers_registry_paths =
115+
const std::vector<Path> &drivers_registry_paths =
118116
LoadRegistrySystemLayers("HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Class\\...\\VulkanExplicitLayers");
119117
result.insert(result.begin(), drivers_registry_paths.begin(), drivers_registry_paths.end());
120118
#else
@@ -161,27 +159,18 @@ std::vector<LayersPathInfo> GetExplicitLayerPaths() {
161159
return result;
162160
}
163161

164-
static LayersPathInfo *FindPathInfo(std::array<std::vector<LayersPathInfo>, LAYERS_PATHS_COUNT> &paths, const std::string &path) {
165-
for (int paths_type_index = LAYERS_PATHS_FIRST; paths_type_index <= LAYERS_PATHS_LAST; ++paths_type_index) {
166-
for (std::size_t i = 0, n = paths[paths_type_index].size(); i < n; ++i) {
167-
if (paths[paths_type_index][i].path == path) {
168-
return &paths[paths_type_index][i];
169-
}
170-
}
171-
}
172-
173-
return nullptr;
174-
}
175-
176-
LayerManager::LayerManager() { this->InitSystemPaths(); }
162+
LayerManager::LayerManager() {}
177163

178164
bool LayerManager::Load(const QJsonObject &json_root_object, ConfiguratorMode configurator_mode) {
165+
this->available_layers.clear();
166+
this->layers_found.clear();
167+
179168
// LAYERS_PATHS_GUI
180169
if (json_root_object.value("layers") != QJsonValue::Undefined) {
181170
const QJsonObject &json_layers_object = json_root_object.value("layers").toObject();
182171

183-
if (json_layers_object.value("last_layers_path") != QJsonValue::Undefined) {
184-
this->last_layers_path = json_layers_object.value("last_layers_path").toString().toStdString();
172+
if (json_layers_object.value("last_layers_dir") != QJsonValue::Undefined) {
173+
this->last_layers_dir = json_layers_object.value("last_layers_dir").toString().toStdString();
185174
}
186175

187176
if (json_layers_object.value("validate_manifests") != QJsonValue::Undefined) {
@@ -196,27 +185,20 @@ bool LayerManager::Load(const QJsonObject &json_root_object, ConfiguratorMode co
196185
const QJsonObject &json_status_object = json_layers_found_object.value(json_layers_found_keys[i]).toObject();
197186

198187
LayerStatus layer_status;
188+
if (json_status_object.value("type") != QJsonValue::Undefined) {
189+
layer_status.type = ::GetLayerType(json_status_object.value("type").toString().toStdString().c_str());
190+
}
199191
layer_status.last_modified = json_status_object.value("last_modified").toString().toStdString();
200192
layer_status.validated = json_status_object.value("validated").toBool();
201-
layer_status.disabled = json_status_object.value("disabled").toBool();
193+
if (json_status_object.value("enabled") != QJsonValue::Undefined) {
194+
layer_status.enabled = json_status_object.value("enabled").toBool();
195+
}
202196

203197
const Path &manifest_path = json_layers_found_keys[i].toStdString();
204198

205199
this->layers_found.insert(std::make_pair(manifest_path, layer_status));
206200
}
207201
}
208-
209-
if (json_layers_object.value("paths") != QJsonValue::Undefined) {
210-
const QJsonObject &json_paths_object = json_layers_object.value("paths").toObject();
211-
const QStringList &json_paths_keys = json_paths_object.keys();
212-
213-
for (int i = 0, n = json_paths_keys.length(); i < n; ++i) {
214-
LayersPathInfo info;
215-
info.path = json_paths_keys[i].toStdString();
216-
info.enabled = json_paths_object.value(json_paths_keys[i].toStdString().c_str()).toBool();
217-
this->AppendPath(info);
218-
}
219-
}
220202
}
221203

222204
this->LoadAllInstalledLayers(configurator_mode);
@@ -229,25 +211,16 @@ bool LayerManager::Save(QJsonObject &json_root_object) const {
229211
for (auto it = this->layers_found.begin(); it != this->layers_found.end(); ++it) {
230212
QJsonObject json_layer_status_object;
231213
json_layer_status_object.insert("last_modified", it->second.last_modified.c_str());
214+
json_layer_status_object.insert("type", ::GetToken(it->second.type));
232215
json_layer_status_object.insert("validated", it->second.validated);
233-
json_layer_status_object.insert("disabled", it->second.disabled);
216+
json_layer_status_object.insert("enabled", it->second.enabled);
234217
json_layers_status_object.insert(it->first.AbsolutePath().c_str(), json_layer_status_object);
235218
}
236219

237-
QJsonObject json_paths_object;
238-
for (int paths_type_index = LAYERS_PATHS_FIRST; paths_type_index <= LAYERS_PATHS_LAST; ++paths_type_index) {
239-
const std::vector<LayersPathInfo> &path_infos = this->paths[paths_type_index];
240-
241-
for (std::size_t i = 0, n = path_infos.size(); i < n; ++i) {
242-
json_paths_object.insert(path_infos[i].path.RelativePath().c_str(), path_infos[i].enabled);
243-
}
244-
}
245-
246220
QJsonObject json_layers_object;
247221
json_layers_object.insert("validate_manifests", this->validate_manifests);
248-
json_layers_object.insert("last_layers_path", this->last_layers_path.RelativePath().c_str());
222+
json_layers_object.insert("last_layers_dir", this->last_layers_dir.RelativePath().c_str());
249223
json_layers_object.insert("found", json_layers_status_object);
250-
json_layers_object.insert("paths", json_paths_object);
251224

252225
json_root_object.insert("layers", json_layers_object);
253226

@@ -308,7 +281,7 @@ std::string LayerManager::Log() const {
308281

309282
return log;
310283
}
311-
284+
/*
312285
void LayerManager::InitSystemPaths() {
313286
this->available_layers.clear();
314287
this->layers_found.clear();
@@ -342,7 +315,7 @@ void LayerManager::InitSystemPaths() {
342315
this->paths[LAYERS_PATHS_SDK].push_back(info);
343316
}
344317
}
345-
318+
*/
346319
void LayerManager::Clear() { this->available_layers.clear(); }
347320

348321
bool LayerManager::Empty() const { return this->available_layers.empty(); }
@@ -471,24 +444,41 @@ Layer *LayerManager::FindFromManifest(const Path &manifest_path, bool find_disab
471444

472445
// Find all installed layers on the system.
473446
void LayerManager::LoadAllInstalledLayers(ConfiguratorMode configurator_mode) {
474-
this->available_layers.clear();
447+
std::array<std::vector<Path>, LAYERS_PATHS_COUNT> paths;
475448

476-
for (std::size_t group_index = 0, group_count = this->paths.size(); group_index < group_count; ++group_index) {
449+
// Search new layers
450+
paths[LAYERS_PATHS_IMPLICIT_SYSTEM] = GetImplicitLayerPaths();
451+
452+
// LAYERS_PATHS_IMPLICIT_ENV_SET: VK_IMPLICIT_LAYER_PATH env variables
453+
paths[LAYERS_PATHS_IMPLICIT_ENV_SET] = GetEnvVariablePaths("VK_IMPLICIT_LAYER_PATH", LAYER_TYPE_IMPLICIT);
454+
455+
// LAYERS_PATHS_IMPLICIT_ENV_ADD: VK_ADD_IMPLICIT_LAYER_PATH env variables
456+
paths[LAYERS_PATHS_IMPLICIT_ENV_ADD] = GetEnvVariablePaths("VK_ADD_IMPLICIT_LAYER_PATH", LAYER_TYPE_IMPLICIT);
457+
458+
// LAYERS_PATHS_EXPLICIT_SYSTEM
459+
paths[LAYERS_PATHS_EXPLICIT_SYSTEM] = GetExplicitLayerPaths();
460+
461+
// LAYERS_PATHS_EXPLICIT_ENV_SET: VK_LAYER_PATH env variables
462+
paths[LAYERS_PATHS_EXPLICIT_ENV_SET] = GetEnvVariablePaths("VK_LAYER_PATH", LAYER_TYPE_EXPLICIT);
463+
464+
// LAYERS_PATHS_EXPLICIT_ENV_ADD: VK_ADD_LAYER_PATH env variables
465+
paths[LAYERS_PATHS_EXPLICIT_ENV_ADD] = GetEnvVariablePaths("VK_ADD_LAYER_PATH", LAYER_TYPE_EXPLICIT);
466+
467+
// LAYERS_PATHS_SDK
468+
paths[LAYERS_PATHS_SDK].clear();
469+
paths[LAYERS_PATHS_SDK].push_back(Path(Path::SDK_EXPLICIT_LAYERS));
470+
471+
for (std::size_t group_index = 0, group_count = paths.size(); group_index < group_count; ++group_index) {
477472
const LayersPaths layers_path = static_cast<LayersPaths>(group_index);
478473

479-
const std::vector<LayersPathInfo> &paths_group = this->paths[group_index];
474+
const std::vector<Path> &paths_group = paths[group_index];
480475
for (std::size_t i = 0, n = paths_group.size(); i < n; ++i) {
481-
this->LoadLayersFromPath(paths_group[i].path, paths_group[i].type, configurator_mode);
482-
this->UpdatePathEnabled(paths_group[i], layers_path);
483-
}
484-
}
485-
}
486-
487-
void LayerManager::LoadLayersFromPath(const Path &layers_path, LayerType type, ConfiguratorMode configurator_mode) {
488-
const std::vector<Path> &layers_paths = CollectFilePaths(layers_path);
476+
const std::vector<Path> &layers_paths = CollectFilePaths(paths_group[i]);
489477

490-
for (std::size_t i = 0, n = layers_paths.size(); i < n; ++i) {
491-
this->LoadLayer(layers_paths[i], type, configurator_mode);
478+
for (std::size_t j = 0, o = layers_paths.size(); j < o; ++j) {
479+
this->LoadLayer(layers_paths[j], ::GetLayerType(layers_path), configurator_mode);
480+
}
481+
}
492482
}
493483
}
494484

@@ -600,21 +590,6 @@ void LayerManager::UpdatePathEnabled(const LayersPathInfo &path_info, LayersPath
600590
this->UpdateLayersEnabled(path_info);
601591
}
602592

603-
void LayerManager::UpdateLayersEnabled(const LayersPathInfo &path_info) {
604-
const bool are_enabled = this->AreLayersEnabled(path_info);
605-
606-
const std::vector<Path> &layers_paths = ::CollectFilePaths(path_info.path);
607-
608-
for (std::size_t i = 0, n = layers_paths.size(); i < n; ++i) {
609-
Layer *layer = this->FindFromManifest(layers_paths[i], true);
610-
if (layer == nullptr) {
611-
continue;
612-
}
613-
614-
layer->enabled = are_enabled;
615-
}
616-
}
617-
618593
std::vector<Path> LayerManager::CollectManifestPaths() const {
619594
std::vector<Path> results;
620595

@@ -645,8 +620,8 @@ std::vector<std::string> LayerManager::GatherLayerNames() const {
645620

646621
return result;
647622
}
648-
649-
std::vector<const Layer *> LayerManager::GatherLayers(const LayersPathInfo &path_info) const {
623+
/*
624+
std::vector<const Layer *> LayerManager::GatherLayers(const Path& path) const {
650625
std::vector<const Layer *> result;
651626
652627
for (std::size_t i = 0, n = this->available_layers.size(); i < n; ++i) {
@@ -661,3 +636,4 @@ std::vector<const Layer *> LayerManager::GatherLayers(const LayersPathInfo &path
661636
662637
return result;
663638
}
639+
*/

vkconfig_core/layer_manager.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,24 @@ class LayerManager : public Serialize {
4949
Layer* FindFromManifest(const Path& manifest_path, bool find_disabled_layers = false);
5050

5151
void LoadAllInstalledLayers(ConfiguratorMode configurator_mode);
52-
void LoadLayersFromPath(const Path& layers_path, LayerType type, ConfiguratorMode configurator_mode);
5352
LayerLoadStatus LoadLayer(const Path& layer_path, LayerType type, ConfiguratorMode configurator_mode);
5453

55-
bool AreLayersEnabled(const LayersPathInfo& path_info) const;
56-
void AppendPath(const LayersPathInfo& path_info);
57-
void RemovePath(const LayersPathInfo& path_info);
58-
void UpdatePathEnabled(const LayersPathInfo& path_info, LayersPaths layers_paths);
54+
/*
55+
bool AreLayersEnabled(const LayersPathInfo& path_info) const;
56+
void AppendPath(const LayersPathInfo& path_info);
57+
void RemovePath(const LayersPathInfo& path_info);
58+
void UpdatePathEnabled(const LayersPathInfo& path_info, LayersPaths layers_paths);
59+
*/
5960
std::vector<Path> CollectManifestPaths() const;
6061

6162
std::vector<std::string> GatherLayerNames() const;
62-
std::vector<const Layer*> GatherLayers(const LayersPathInfo& path_info) const;
63+
// std::vector<const Layer*> GatherLayers(const Path& path) const;
6364

6465
std::vector<Layer> available_layers;
65-
std::array<std::vector<LayersPathInfo>, LAYERS_PATHS_COUNT> paths;
66-
Path last_layers_path = Path(Path::HOME);
66+
// std::array<std::vector<LayersPathInfo>, LAYERS_PATHS_COUNT> paths;
67+
Path last_layers_dir = Path(Path::HOME);
6768
bool validate_manifests = false;
6869

6970
private:
70-
void InitSystemPaths();
71-
void UpdateLayersEnabled(const LayersPathInfo& path_info);
72-
7371
std::map<Path, LayerStatus> layers_found;
7472
};

0 commit comments

Comments
 (0)