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
178164bool 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+ /*
312285void 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+ */
346319void LayerManager::Clear () { this ->available_layers .clear (); }
347320
348321bool 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.
473446void 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-
618593std::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+ */
0 commit comments