Skip to content

Commit

Permalink
vkconfig3: Layer tabs UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Oct 9, 2024
1 parent 685b603 commit a851086
Show file tree
Hide file tree
Showing 18 changed files with 380 additions and 109 deletions.
2 changes: 1 addition & 1 deletion vkconfig_core/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Layer {
std::string enable_env;
bool disable_value;
bool enable_value;
bool visible = true;
bool enabled = true;

std::vector<SettingMeta*> settings;
std::vector<LayerPreset> presets;
Expand Down
64 changes: 35 additions & 29 deletions vkconfig_core/layer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@

#include <QJsonArray>

LayerType GetLayerType(LayersPaths Layers_paths_type) {
if (Layers_paths_type == LAYERS_PATHS_IMPLICIT) {
return LAYER_TYPE_IMPLICIT;
} else {
return LAYER_TYPE_EXPLICIT;
}
}

std::vector<LayersPathInfo> GetImplicitLayerPaths() {
std::vector<LayersPathInfo> result;

Expand Down Expand Up @@ -128,6 +120,14 @@ bool LayerManager::Load(const QJsonObject &json_root_object) {
if (json_root_object.value("layers") != QJsonValue::Undefined) {
const QJsonObject &json_layers_object = json_root_object.value("layers").toObject();

if (json_layers_object.value("last_layers_path") != QJsonValue::Undefined) {
this->last_layers_path = json_layers_object.value("last_layers_path").toString().toStdString();
}

if (json_layers_object.value("paths_view") != QJsonValue::Undefined) {
this->paths_view = static_cast<LayersPathViewType>(json_layers_object.value("paths_view").toInt());
}

if (json_layers_object.value("validated") != QJsonValue::Undefined) {
const QJsonObject &json_layers_validated_object = json_layers_object.value("validated").toObject();
const QStringList &json_layers_validated_keys = json_layers_validated_object.keys();
Expand Down Expand Up @@ -175,6 +175,8 @@ bool LayerManager::Save(QJsonObject &json_root_object) const {
}

QJsonObject json_layers_object;
json_layers_object.insert("last_layers_path", this->last_layers_path.RelativePath().c_str());
json_layers_object.insert("paths_view", this->paths_view);
json_layers_object.insert("validated", json_layers_paths_object);
json_layers_object.insert("paths", json_paths_object);

Expand Down Expand Up @@ -239,7 +241,7 @@ std::vector<Version> LayerManager::GatherVersions(const std::string &layer_name)
std::vector<Version> result;

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

Expand Down Expand Up @@ -274,7 +276,7 @@ const Layer *LayerManager::Find(const std::string &layer_name, const Version &la
return this->Find(layer_name, latest);
} else {
for (std::size_t i = 0, n = this->selected_layers.size(); i < n; ++i) {
if (this->selected_layers[i].visible == false) {
if (this->selected_layers[i].enabled == false) {
continue;
}
if (this->selected_layers[i].key != layer_name) {
Expand Down Expand Up @@ -330,26 +332,30 @@ void LayerManager::LoadLayersFromPath(const Path &layers_path, LayerType type) {
const std::vector<Path> &layers_paths = CollectFilePaths(layers_path);

for (std::size_t i = 0, n = layers_paths.size(); i < n; ++i) {
const std::string &last_modified = layers_paths[i].LastModified();

Layer *already_loaded_layer = this->FindFromManifest(layers_paths[i]);
if (already_loaded_layer != nullptr) {
// Already loaded
auto it = this->layers_validated.find(layers_paths[i]);
if (it != layers_validated.end()) {
if (last_modified == it->second) {
continue; // Already loaded and up to date
}
}
this->LoadLayer(layers_paths[i], type);
}
}

void LayerManager::LoadLayer(const Path &layer_path, LayerType type) {
const std::string &last_modified = layer_path.LastModified();

// Reload
already_loaded_layer->Load(layers_paths[i], this->layers_validated, type);
} else {
Layer layer;
if (layer.Load(layers_paths[i], this->layers_validated, type)) {
this->selected_layers.push_back(layer);
Layer *already_loaded_layer = this->FindFromManifest(layer_path);
if (already_loaded_layer != nullptr) {
// Already loaded
auto it = this->layers_validated.find(layer_path);
if (it != layers_validated.end()) {
if (last_modified == it->second) {
return;
}
}

// Modified to reload
already_loaded_layer->Load(layer_path, this->layers_validated, type);
} else {
Layer layer;
if (layer.Load(layer_path, this->layers_validated, type)) {
this->selected_layers.push_back(layer);
}
}
}

Expand All @@ -373,7 +379,7 @@ void LayerManager::RemovePath(const LayersPathInfo &path_info) {
continue;
}

layer->visible = false;
layer->enabled = false;
}

for (int paths_type_index = LAYERS_PATHS_FIRST; paths_type_index <= LAYERS_PATHS_LAST; ++paths_type_index) {
Expand Down Expand Up @@ -407,7 +413,7 @@ void LayerManager::UpdatePathEnabled(const LayersPathInfo &path_info) {
continue;
}

layer->visible = path_info.enabled;
layer->enabled = path_info.enabled;
}
}

Expand Down
21 changes: 5 additions & 16 deletions vkconfig_core/layer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,13 @@
#include "layer.h"
#include "path.h"
#include "serialization.h"
#include "type_layer_path_view.h"
#include "type_layers_paths.h"

#include <string>
#include <vector>
#include <memory>

enum LayersPaths {
LAYERS_PATHS_IMPLICIT = 0,
LAYERS_PATHS_EXPLICIT,
LAYERS_PATHS_ENV_SET, // From $VK_LAYER_PATH
LAYERS_PATHS_ENV_ADD, // from $VK_ADD_LAYER_PATH
LAYERS_PATHS_GUI,
LAYERS_PATHS_SDK,

LAYERS_PATHS_FIRST = LAYERS_PATHS_IMPLICIT,
LAYERS_PATHS_LAST = LAYERS_PATHS_SDK,
};

enum { LAYERS_PATHS_COUNT = LAYERS_PATHS_LAST - LAYERS_PATHS_FIRST + 1 };

LayerType GetLayerType(LayersPaths Layers_paths_type);

class LayerManager : public Serialize {
public:
bool Load(const QJsonObject& json_root_object) override;
Expand All @@ -61,6 +47,7 @@ class LayerManager : public Serialize {

void LoadAllInstalledLayers();
void LoadLayersFromPath(const Path& layers_path, LayerType type = LAYER_TYPE_EXPLICIT);
void LoadLayer(const Path& layer_path, LayerType type = LAYER_TYPE_EXPLICIT);

void AppendPath(const LayersPathInfo& path_info);
void RemovePath(const LayersPathInfo& path_info);
Expand All @@ -70,6 +57,8 @@ class LayerManager : public Serialize {

std::vector<Layer> selected_layers;
std::array<std::vector<LayersPathInfo>, LAYERS_PATHS_COUNT> paths;
Path last_layers_path = Get(Path::HOME);
LayersPathViewType paths_view = LAYERS_PATH_ONLY_USER_DEFINED;

private:
void InitSystemPaths();
Expand Down
8 changes: 4 additions & 4 deletions vkconfig_core/test/test_layer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST(test_layer_manager, GatherVersions) {
EXPECT_TRUE(layer193 != nullptr);

Layer* layer_edit = layer_manager.FindFromManifest(layer193->manifest_path);
layer_edit->visible = false;
layer_edit->enabled = false;

const std::vector<Version>& versions_found_b = layer_manager.GatherVersions("VK_LAYER_LUNARG_version");
EXPECT_FALSE(versions_found_b.empty());
Expand Down Expand Up @@ -272,21 +272,21 @@ TEST(test_layer_manager, custom_path_update_layers) {
EXPECT_EQ(layer_manager.paths[LAYERS_PATHS_GUI].size(), 1);
EXPECT_EQ(layer_manager.paths[LAYERS_PATHS_GUI][0].enabled, true);
for (std::size_t i = 0, n = layer_manager.selected_layers.size(); i < n; ++i) {
EXPECT_TRUE(layer_manager.selected_layers[i].visible);
EXPECT_TRUE(layer_manager.selected_layers[i].enabled);
}

info.enabled = false;
layer_manager.UpdatePathEnabled(info);
EXPECT_EQ(layer_manager.paths[LAYERS_PATHS_GUI][0].enabled, false);
for (std::size_t i = 0, n = layer_manager.selected_layers.size(); i < n; ++i) {
EXPECT_FALSE(layer_manager.selected_layers[i].visible);
EXPECT_FALSE(layer_manager.selected_layers[i].enabled);
}

info.enabled = true;
layer_manager.UpdatePathEnabled(info);
EXPECT_EQ(layer_manager.paths[LAYERS_PATHS_GUI][0].enabled, true);
for (std::size_t i = 0, n = layer_manager.selected_layers.size(); i < n; ++i) {
EXPECT_TRUE(layer_manager.selected_layers[i].visible);
EXPECT_TRUE(layer_manager.selected_layers[i].enabled);
}

EXPECT_EQ(layer_manager.paths[LAYERS_PATHS_GUI].size(), 1);
Expand Down
17 changes: 15 additions & 2 deletions vkconfig_core/type_layer_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,21 @@ const char* GetToken(LayerControl control) {
"Auto", // LAYER_CONTROL_AUTO
"Off", // LAYER_CONTROL_OFF
"On", // LAYER_CONTROL_ON
"application_enabled_layers", // LAYER_CONTROL_APPLICATIONS
"unordered_layer_location" // LAYER_CONTROL_UNORDERED
"application_enabled_layers", // LAYER_CONTROL_APPLICATIONS_API
"unordered_layer_location" // LAYER_CONTROL_APPLICATIONS_ENV
};
static_assert(std::size(TOKENS) == LAYER_CONTROL_COUNT);

return TOKENS[control];
}

const char* GetDescription(LayerControl control) {
static const char* TOKENS[] = {
"Auto, let Vulkan applications or environment variables to enable or disable the layer", // LAYER_CONTROL_AUTO
"Force Off the layer, preventing its execution", // LAYER_CONTROL_OFF
"Force On the layer, insuring its execution", // LAYER_CONTROL_ON
"Located and Enabled Layers using the Vulkan API by the Vulkan Application", // LAYER_CONTROL_APPLICATIONS_API
"Located and Enabled Layers using Environment Variables by the Vulkan Application" // LAYER_CONTROL_APPLICATIONS_ENV
};
static_assert(std::size(TOKENS) == LAYER_CONTROL_COUNT);

Expand Down
2 changes: 2 additions & 0 deletions vkconfig_core/type_layer_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ enum { LAYER_CONTROL_COUNT = LAYER_CONTROL_LAST - LAYER_CONTROL_FIRST + 1 };

const char* GetToken(LayerControl control);

const char* GetDescription(LayerControl control);

LayerControl GetLayerControl(const char* token);
21 changes: 21 additions & 0 deletions vkconfig_core/type_layer_path_view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2020-2024 Valve Corporation
* Copyright (c) 2020-2024 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors:
* - Christophe Riccio <[email protected]>
*/

#include "type_layer_path_view.h"
31 changes: 31 additions & 0 deletions vkconfig_core/type_layer_path_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2020-2024 Valve Corporation
* Copyright (c) 2020-2024 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors:
* - Christophe Riccio <[email protected]>
*/

#pragma once

enum LayersPathViewType {
LAYERS_PATH_ONLY_USER_DEFINED = 0,
LAYERS_PATH_ONLY_ACTIVE_SDK,
LAYERS_PATH_ALL,

LAYERS_PATH_FIRST = LAYERS_PATH_ONLY_USER_DEFINED,
LAYERS_PATH_LAST = LAYERS_PATH_ALL,
};
enum { LAYERS_PATH_COUNT = LAYERS_PATH_LAST - LAYERS_PATH_FIRST + 1 };
45 changes: 45 additions & 0 deletions vkconfig_core/type_layers_paths.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2020-2024 Valve Corporation
* Copyright (c) 2020-2024 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors:
* - Christophe Riccio <[email protected]>
*/

#include "type_layers_paths.h"

#include <array>

LayerType GetLayerType(LayersPaths Layers_paths_type) {
if (Layers_paths_type == LAYERS_PATHS_IMPLICIT) {
return LAYER_TYPE_IMPLICIT;
} else {
return LAYER_TYPE_EXPLICIT;
}
}

const char* GetLabel(LayersPaths Layers_paths_type) {
static const char* TABLE[] = {
"Implicit Layers", // LAYERS_PATHS_IMPLICIT
"Explicit Layers", // LAYERS_PATHS_EXPLICIT
"$VK_LAYER_PATH Layers", // LAYERS_PATHS_ENV_SET
"$VK_ADD_LAYER_PATH Layers", // LAYERS_PATHS_ENV_ADD
"Vulkan Configurator Layers", // LAYERS_PATHS_GUI
"Vulkan SDK Layers", // LAYERS_PATHS_SDK
};
static_assert(std::size(TABLE) == LAYERS_PATHS_COUNT, "The tranlation table size doesn't match the enum number of elements");

return TABLE[Layers_paths_type];
}
41 changes: 41 additions & 0 deletions vkconfig_core/type_layers_paths.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2020-2024 Valve Corporation
* Copyright (c) 2020-2024 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Authors:
* - Christophe Riccio <[email protected]>
*/

#pragma once

#include "type_layer_type.h"

enum LayersPaths {
LAYERS_PATHS_IMPLICIT = 0,
LAYERS_PATHS_EXPLICIT,
LAYERS_PATHS_ENV_SET, // From $VK_LAYER_PATH
LAYERS_PATHS_ENV_ADD, // from $VK_ADD_LAYER_PATH
LAYERS_PATHS_GUI,
LAYERS_PATHS_SDK,

LAYERS_PATHS_FIRST = LAYERS_PATHS_IMPLICIT,
LAYERS_PATHS_LAST = LAYERS_PATHS_SDK,
};

enum { LAYERS_PATHS_COUNT = LAYERS_PATHS_LAST - LAYERS_PATHS_FIRST + 1 };

LayerType GetLayerType(LayersPaths Layers_paths_type);

const char* GetLabel(LayersPaths Layers_paths_type);
Loading

0 comments on commit a851086

Please sign in to comment.