Skip to content

Commit

Permalink
vkconfig3: Fix SetExpanded and add support for different settings per…
Browse files Browse the repository at this point in the history
… layer
  • Loading branch information
christophe-lunarg committed Nov 21, 2024
1 parent 91f2561 commit 0dae5b3
Show file tree
Hide file tree
Showing 42 changed files with 271 additions and 139 deletions.
10 changes: 1 addition & 9 deletions vkconfig_core/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ bool Configuration::Load(const Path& full_path, const LayerManager& layers) {
parameter.platform_flags = GetPlatformFlags(ReadStringArray(json_layer_object, "platforms"));
}

const QJsonValue& json_expanded_value = json_layer_object.value("expanded_states");
if (json_expanded_value != QJsonValue::Undefined) {
parameter.setting_tree_state = json_layer_object.value("expanded_states").toVariant().toByteArray();
}

if (layer != nullptr) {
CollectDefaultSettingData(layer->settings, parameter.settings);
}
Expand Down Expand Up @@ -262,9 +257,6 @@ bool Configuration::Save(const Path& full_path, bool exporter) const {
json_layer.insert("manifest", parameter.manifest.RelativePath().c_str());
}
SaveStringArray(json_layer, "platforms", GetPlatformTokens(parameter.platform_flags));
if (!exporter && !parameter.setting_tree_state.isEmpty()) {
json_layer.insert("expanded_states", parameter.setting_tree_state.data());
}

QJsonArray json_settings;
for (std::size_t j = 0, m = parameter.settings.size(); j < m; ++j) {
Expand Down Expand Up @@ -483,7 +475,7 @@ void Configuration::GatherParameters(const LayerManager& layers) {
parameter.control = this->default_control;
parameter.api_version = Version::LATEST;
parameter.manifest = layer->manifest_path;
CollectDefaultSettingData(layer->settings, parameter.settings);
::CollectDefaultSettingData(layer->settings, parameter.settings);

gathered_parameters.push_back(parameter);
}
Expand Down
19 changes: 18 additions & 1 deletion vkconfig_core/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,29 @@ void Layer::AddSettingsSet(SettingMetaSet& settings, const SettingMeta* parent,
const QJsonObject& json_setting = json_array[i].toObject();

const std::string key = ReadStringValue(json_setting, "key");
if (this->key == "VK_LAYER_KHRONOS_validation" && key == "enables") {
continue;
}
if (this->key == "VK_LAYER_KHRONOS_validation" && key == "disables") {
continue;
}

const std::string desc = ReadStringValue(json_setting, "description");
const SettingType type = GetSettingType(ReadStringValue(json_setting, "type").c_str());
SettingView view = SETTING_VIEW_STANDARD;
if (json_setting.value("view") != QJsonValue::Undefined) {
view = GetSettingView(ReadStringValue(json_setting, "view").c_str());
}
if (view == SETTING_VIEW_HIDDEN) {
continue;
}

SettingMeta* setting_meta = Instantiate(settings, key, type);
setting_meta->platform_flags = parent == nullptr ? this->platforms : parent->platform_flags;
setting_meta->status = parent == nullptr ? this->status : parent->status;
if (parent != nullptr) setting_meta->view = parent->view;
if (parent != nullptr) {
setting_meta->view = parent->view;
}

LoadMetaHeader(*setting_meta, json_setting);
if (json_setting.value("env") != QJsonValue::Undefined) {
Expand Down
31 changes: 31 additions & 0 deletions vkconfig_core/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "setting_filesystem.h"
#include "setting_flags.h"
#include "parameter.h"
#include "type_platform.h"
#include "version.h"
Expand Down Expand Up @@ -61,6 +62,36 @@ bool Parameter::ApplyPresetSettings(const LayerPreset& preset) {
return true;
}

bool Parameter::GetExpanded(const std::string& setting_key, const std::string& flag) const {
const SettingData* setting_data = ::FindSetting(this->settings, setting_key.c_str());

if (setting_data == nullptr) {
return false;
}

if (!flag.empty() && setting_data->type == SETTING_FLAGS) {
const SettingDataFlags* data = static_cast<const SettingDataFlags*>(setting_data);
return data->expanded_flags.find(flag)->second;
} else {
return setting_data->expanded;
}
}

void Parameter::SetExpanded(const std::string& setting_key, const std::string& flag, bool expanded) {
SettingData* setting_data = ::FindSetting(this->settings, setting_key.c_str());

if (setting_data == nullptr) {
return;
}

if (!flag.empty() && setting_data->type == SETTING_FLAGS) {
SettingDataFlags* data = static_cast<SettingDataFlags*>(setting_data);
data->expanded_flags.find(flag)->second = expanded;
} else {
setting_data->expanded = expanded;
}
}

ParameterRank GetParameterOrdering(const LayerManager& layers, const Parameter& parameter) {
assert(!parameter.key.empty());

Expand Down
3 changes: 2 additions & 1 deletion vkconfig_core/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct Parameter {
Parameter(const std::string& key, const LayerControl control) : key(key), control(control) {}

bool ApplyPresetSettings(const LayerPreset& preset);
bool GetExpanded(const std::string& setting_key, const std::string& flag = "") const;
void SetExpanded(const std::string& setting_key, const std::string& flag, bool expanded);

std::string key;
LayerType type = LAYER_TYPE_EXPLICIT;
Expand All @@ -55,7 +57,6 @@ struct Parameter {
int overridden_rank = NO_RANK;
Version api_version = Version::LATEST;
Path manifest;
QByteArray setting_tree_state; // Recall editor tree state
bool override_settings = true;
};

Expand Down
28 changes: 21 additions & 7 deletions vkconfig_core/setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,15 @@ bool SettingMeta::Equal(const SettingMeta& other) const {
return false;
else {
for (std::size_t i = 0, n = this->children.size(); i < n; ++i) {
if (this->children[i] != other.children[i]) return false;
if (this->children[i] != other.children[i]) {
return false;
}
}

for (std::size_t i = 0, n = this->dependence.size(); i < n; ++i) {
if (this->dependence[i] != other.dependence[i]) return false;
if (this->dependence[i] != other.dependence[i]) {
return false;
}
}
}
return true;
Expand Down Expand Up @@ -180,17 +184,23 @@ bool IsSupported(const SettingEnumValue* value) {

SettingMeta* FindSetting(SettingMetaSet& settings, const char* key) {
for (std::size_t i = 0, n = settings.size(); i < n; ++i) {
if (settings[i]->key == key) return settings[i];
if (settings[i]->key == key) {
return settings[i];
}

SettingMeta* child = FindSetting(settings[i]->children, key);
if (child != nullptr) return child;
if (child != nullptr) {
return child;
}

if (IsEnum(settings[i]->type) || IsFlags(settings[i]->type)) {
SettingMetaEnum& setting_meta_enum = static_cast<SettingMetaEnum&>(*settings[i]);

for (std::size_t j = 0, o = setting_meta_enum.enum_values.size(); j < o; ++j) {
SettingMeta* setting_meta = FindSetting(setting_meta_enum.enum_values[j].settings, key);
if (setting_meta != nullptr) return setting_meta;
if (setting_meta != nullptr) {
return setting_meta;
}
}
}
}
Expand All @@ -203,14 +213,18 @@ const SettingMeta* FindSetting(const SettingMetaSet& settings, const char* key)
if (settings[i]->key == key) return settings[i];

const SettingMeta* child = FindSetting(settings[i]->children, key);
if (child != nullptr) return child;
if (child != nullptr) {
return child;
}

if (IsEnum(settings[i]->type) || IsFlags(settings[i]->type)) {
const SettingMetaEnum& setting_meta_enum = static_cast<const SettingMetaEnum&>(*settings[i]);

for (std::size_t j = 0, o = setting_meta_enum.enum_values.size(); j < o; ++j) {
const SettingMeta* setting_meta = FindSetting(setting_meta_enum.enum_values[j].settings, key);
if (setting_meta != nullptr) return setting_meta;
if (setting_meta != nullptr) {
return setting_meta;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions vkconfig_core/setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct SettingData {

const std::string key;
const SettingType type;
bool expanded = true;

protected:
SettingData(const std::string& key, const SettingType& type);
Expand Down
8 changes: 6 additions & 2 deletions vkconfig_core/setting_bool.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020-2021 Valve Corporation
* Copyright (c) 2020-2021 LunarG, Inc.
* 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.
Expand Down Expand Up @@ -69,11 +69,15 @@ void SettingDataBool::Copy(const SettingData* data) {

bool SettingDataBool::Load(const QJsonObject& json_setting) {
this->value = ReadBoolValue(json_setting, "value");
if (json_setting.value("expanded") != QJsonValue::Undefined) {
this->expanded = ReadBoolValue(json_setting, "expanded");
}
return true;
}

bool SettingDataBool::Save(QJsonObject& json_setting) const {
json_setting.insert("value", this->value);
json_setting.insert("expanded", this->expanded);
return true;
}

Expand Down
17 changes: 12 additions & 5 deletions vkconfig_core/setting_filesystem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020-2021 Valve Corporation
* Copyright (c) 2020-2021 LunarG, Inc.
* 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.
Expand Down Expand Up @@ -82,11 +82,17 @@ void SettingDataFilesystem::Copy(const SettingData* data) {

bool SettingDataFilesystem::Load(const QJsonObject& json_setting) {
this->value = ReadStringValue(json_setting, "value");

if (json_setting.value("expanded") != QJsonValue::Undefined) {
this->expanded = ReadBoolValue(json_setting, "expanded");
}

return true;
}

bool SettingDataFilesystem::Save(QJsonObject& json_setting) const {
json_setting.insert("value", this->value.RelativePath().c_str());
json_setting.insert("expanded", this->expanded);
return true;
}

Expand Down Expand Up @@ -143,12 +149,13 @@ void SettingDataFileLoad::Copy(const SettingData* data) {
}

bool SettingDataFileLoad::Load(const QJsonObject& json_setting) {
this->value = Path(ReadStringValue(json_setting, "value"));
const bool result = this->SettingDataFilesystem::Load(json_setting);

if (this->meta->format == "PROFILE") {
this->profile_names = CollectProfileNamesFromFile(this->value);
}
return true;

return result;
}

void SettingDataFileLoad::Reset() { this->value = this->meta->default_value; }
Expand Down Expand Up @@ -208,7 +215,7 @@ void SettingDataFolderLoad::Copy(const SettingData* data) {
}

bool SettingDataFolderLoad::Load(const QJsonObject& json_setting) {
SettingDataFilesystem::Load(json_setting);
this->SettingDataFilesystem::Load(json_setting);

if (this->meta->format == "PROFILE") {
this->profile_names = CollectProfileNamesFromDir(this->value);
Expand Down
19 changes: 17 additions & 2 deletions vkconfig_core/setting_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ SettingData* SettingMetaEnum::Instantiate() {
}

bool SettingMetaEnum::Load(const QJsonObject& json_setting) {
SettingMetaEnumeration::Load(json_setting);
this->SettingMetaEnumeration::Load(json_setting);

this->default_value = ReadStringValue(json_setting, "default");
return true;
Expand Down Expand Up @@ -123,7 +123,7 @@ SettingData* SettingMetaFlags::Instantiate() {
}

bool SettingMetaFlags::Load(const QJsonObject& json_setting) {
SettingMetaEnumeration::Load(json_setting);
this->SettingMetaEnumeration::Load(json_setting);

this->default_value = ReadStringArray(json_setting, "default");
return true;
Expand Down Expand Up @@ -166,6 +166,10 @@ bool SettingMetaFlags::Equal(const SettingMeta& other) const {

SettingDataFlags::SettingDataFlags(const SettingMetaFlags* meta) : SettingData(meta->key, meta->type), meta(meta) {
assert(meta != nullptr);

for (std::size_t i = 0, n = meta->enum_values.size(); i < n; ++i) {
this->expanded_flags.insert(std::make_pair(meta->enum_values[i].key, true));
}
}

void SettingDataFlags::Reset() {
Expand All @@ -182,6 +186,16 @@ void SettingDataFlags::Copy(const SettingData* data) {

bool SettingDataFlags::Load(const QJsonObject& json_setting) {
this->value = ReadStringArray(json_setting, "value");
if (json_setting.value("expanded") != QJsonValue::Undefined) {
this->expanded = ReadBoolValue(json_setting, "expanded");
}
if (json_setting.value("expanded_flags") != QJsonValue::Undefined) {
const QJsonObject& json_object = json_setting.value("expanded_flags").toObject();
for (auto it = this->expanded_flags.begin(); it != this->expanded_flags.end(); ++it) {
it->second = json_object.value(it->first.c_str()).toBool();
}
}

return true;
}

Expand All @@ -193,6 +207,7 @@ bool SettingDataFlags::Save(QJsonObject& json_setting) const {
}

json_setting.insert("value", json_array);
json_setting.insert("expanded", this->expanded);

return true;
}
Expand Down
3 changes: 3 additions & 0 deletions vkconfig_core/setting_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "setting_string.h"

#include <map>

struct SettingEnumValue : public Header {
std::string key;
SettingMetaSet settings;
Expand Down Expand Up @@ -98,6 +100,7 @@ struct SettingDataFlags : public SettingData {
void Reset() override;

std::vector<std::string> value;
std::map<std::string, bool> expanded_flags;

protected:
bool Equal(const SettingData& other) const override;
Expand Down
8 changes: 6 additions & 2 deletions vkconfig_core/setting_float.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020-2021 Valve Corporation
* Copyright (c) 2020-2021 LunarG, Inc.
* 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.
Expand Down Expand Up @@ -100,11 +100,15 @@ void SettingDataFloat::Copy(const SettingData* data) {

bool SettingDataFloat::Load(const QJsonObject& json_setting) {
this->value = ReadFloatValue(json_setting, "value");
if (json_setting.value("expanded") != QJsonValue::Undefined) {
this->expanded = ReadBoolValue(json_setting, "expanded");
}
return true;
}

bool SettingDataFloat::Save(QJsonObject& json_setting) const {
json_setting.insert("value", this->value);
json_setting.insert("expanded", this->expanded);
return true;
}

Expand Down
5 changes: 0 additions & 5 deletions vkconfig_core/setting_frames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ SettingMetaFrames::SettingMetaFrames(Layer& layer, const std::string& key) : Set

SettingDataFrames::SettingDataFrames(const SettingMetaFrames* meta) : SettingDataString(meta), meta(meta) {}

bool SettingDataFrames::Load(const QJsonObject& json_setting) {
this->value = ReadStringValue(json_setting, "value");
return true;
}

bool SettingDataFrames::IsValid() const { return IsFrames(this->value) || this->value.empty(); }

SettingInputError SettingDataFrames::ProcessInput(const std::string& input_value) {
Expand Down
2 changes: 0 additions & 2 deletions vkconfig_core/setting_frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ struct SettingMetaFrames : public SettingMetaString {
struct SettingDataFrames : public SettingDataString {
SettingDataFrames(const SettingMetaFrames* meta);

bool Load(const QJsonObject& json_setting) override;

bool IsValid() const override;

SettingInputError ProcessInput(const std::string& value);
Expand Down
Loading

0 comments on commit 0dae5b3

Please sign in to comment.