Skip to content

Commit

Permalink
vkconfig3: Enable layer version selection
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Jul 16, 2024
1 parent 4085704 commit ef51ab8
Show file tree
Hide file tree
Showing 24 changed files with 317 additions and 265 deletions.
2 changes: 1 addition & 1 deletion vkconfig_cmd/main_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static int RunLayersOverride(const CommandLine& command_line) {

Configuration configuration;
const bool load_result =
configuration.Load(configurator.layers.selected_layers, command_line.layers_configuration_path.c_str());
configuration.Load(command_line.layers_configuration_path.c_str(), configurator.layers.selected_layers);
if (!load_result) {
printf("\nFailed to load the layers configuration file...\n");
return -1;
Expand Down
99 changes: 65 additions & 34 deletions vkconfig_core/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,30 @@ Configuration Configuration::CreateDisabled(const std::vector<Layer>& available_
return result;
}

bool Configuration::Load3_0(const std::vector<Layer>& available_layers, const QJsonObject& json_root_object) {
bool Configuration::Load(const Path& full_path, const std::vector<Layer>& available_layers) {
assert(!full_path.Empty());

this->parameters.clear();

QFile file(full_path.AbsolutePath().c_str());
const bool result = file.open(QIODevice::ReadOnly | QIODevice::Text);
assert(result);
std::string json_text = file.readAll().toStdString();
file.close();

QJsonParseError parse_error;
QJsonDocument json_doc = QJsonDocument::fromJson(json_text.c_str(), &parse_error);

if (parse_error.error != QJsonParseError::NoError) {
return false;
}

Version version(json_doc.object().value("file_format_version").toString().toStdString());
if (version < (Version(3, 0, 0))) {
return false; // Unsupported version
}

const QJsonObject& json_root_object = json_doc.object();
const QJsonValue& json_configuration_value = json_root_object.value("configuration");
if (json_configuration_value == QJsonValue::Undefined) {
return false; // Not a configuration file
Expand Down Expand Up @@ -114,15 +137,33 @@ bool Configuration::Load3_0(const std::vector<Layer>& available_layers, const QJ
parameter.key = ReadStringValue(json_layer_object, "name").c_str();
parameter.overridden_rank = ReadIntValue(json_layer_object, "rank");
parameter.control = GetLayerControl(ReadStringValue(json_layer_object, "control").c_str());
const std::string& version = ReadStringValue(json_layer_object, "version");
parameter.api_version = version == "latest" ? Version::VERSION_NULL : Version(version.c_str());

const QJsonValue& json_platform_value = json_layer_object.value("platforms");
if (json_platform_value != QJsonValue::Undefined) {
parameter.platform_flags = GetPlatformFlags(ReadStringArray(json_layer_object, "platforms"));
}

const Layer* layer = FindByKey(available_layers, parameter.key.c_str());
const Layer* layer = nullptr;
for (std::size_t i = 0, n = available_layers.size(); i < n; ++i) {
const Layer& current_layer = available_layers[i];
if (current_layer.key != parameter.key) {
continue;
}

if (parameter.api_version == Version::VERSION_NULL) {
if (layer == nullptr) {
layer = &current_layer;
} else if (layer->api_version < current_layer.api_version) {
layer = &current_layer;
}
} else if (parameter.api_version == current_layer.api_version) {
layer = &current_layer;
}
}

if (layer != nullptr) {
parameter.api_version = layer->api_version;
CollectDefaultSettingData(layer->settings, parameter.settings);
}

Expand All @@ -134,10 +175,14 @@ bool Configuration::Load3_0(const std::vector<Layer>& available_layers, const QJ
const SettingType setting_type = GetSettingType(ReadStringValue(json_setting_object, "type").c_str());

SettingData* setting_data = FindSetting(parameter.settings, setting_key.c_str());
if (setting_data == nullptr) continue;
if (setting_data == nullptr) {
continue;
}

// Configuration type and layer type are differents, use layer default value
if (setting_data->type != setting_type) continue;
if (setting_data->type != setting_type) {
continue;
}

const bool result = setting_data->Load(json_setting_object);
assert(result);
Expand All @@ -149,33 +194,7 @@ bool Configuration::Load3_0(const std::vector<Layer>& available_layers, const QJ
return true;
}

bool Configuration::Load(const std::vector<Layer>& available_layers, const Path& full_path) {
assert(!full_path.Empty());

this->parameters.clear();

QFile file(full_path.AbsolutePath().c_str());
const bool result = file.open(QIODevice::ReadOnly | QIODevice::Text);
assert(result);
std::string json_text = file.readAll().toStdString();
file.close();

QJsonParseError parse_error;
QJsonDocument json_doc = QJsonDocument::fromJson(json_text.c_str(), &parse_error);

if (parse_error.error != QJsonParseError::NoError) {
return false;
}

Version version(json_doc.object().value("file_format_version").toString().toStdString());
if (version < (Version(3, 0, 0))) {
return false; // Unsupported version
}

return Load3_0(available_layers, json_doc.object());
}

bool Configuration::Save(const std::vector<Layer>& available_layers, const Path& full_path, bool exporter) const {
bool Configuration::Save(const Path& full_path, bool exporter) const {
assert(!full_path.Empty());

QJsonObject root;
Expand All @@ -202,6 +221,8 @@ bool Configuration::Save(const std::vector<Layer>& available_layers, const Path&
json_layer.insert("name", parameter.key.c_str());
json_layer.insert("rank", parameter.overridden_rank);
json_layer.insert("control", GetToken(parameter.control));
json_layer.insert("version",
parameter.api_version == Version::VERSION_NULL ? "latest" : parameter.api_version.str().c_str());
SaveStringArray(json_layer, "platforms", GetPlatformTokens(parameter.platform_flags));

QJsonArray json_settings;
Expand Down Expand Up @@ -265,14 +286,24 @@ bool Configuration::Save(const std::vector<Layer>& available_layers, const Path&
}
}

Parameter* Configuration::Find(std::string parameter_key) {
for (std::size_t i = 0, n = this->parameters.size(); i < n; ++i) {
if (this->parameters[i].key == parameter_key) {
return &this->parameters[i];
}
}

return nullptr;
}

void Configuration::Reset(const std::vector<Layer>& available_layers) {
// Case 1: reset using built-in configuration files
const std::vector<Path>& builtin_configuration_files = CollectFilePaths(":/configurations/");
for (int i = 0, n = builtin_configuration_files.size(); i < n; ++i) {
const std::string& basename = builtin_configuration_files[i].Basename();

if (this->key == basename) {
const bool result = this->Load(available_layers, builtin_configuration_files[i]);
const bool result = this->Load(builtin_configuration_files[i], available_layers);
assert(result);

OrderParameter(this->parameters, available_layers);
Expand All @@ -286,7 +317,7 @@ void Configuration::Reset(const std::vector<Layer>& available_layers) {
std::FILE* file = std::fopen(full_path.AbsolutePath().c_str(), "r");
if (file) {
std::fclose(file);
const bool result = this->Load(available_layers, full_path);
const bool result = this->Load(full_path, available_layers);
assert(result);

OrderParameter(this->parameters, available_layers);
Expand Down
8 changes: 3 additions & 5 deletions vkconfig_core/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class Configuration {

static Configuration CreateDisabled(const std::vector<Layer>& available_layers);

bool Load(const std::vector<Layer>& available_layers, const Path& full_path);
bool Save(const std::vector<Layer>& available_layers, const Path& full_path, bool exporter = false) const;
bool Load(const Path& full_path, const std::vector<Layer>& available_layers);
bool Save(const Path& full_path, bool exporter = false) const;
bool HasOverride() const;
Parameter* Find(std::string parameter_key);

void Reset(const std::vector<Layer>& available_layers);

Expand All @@ -53,9 +54,6 @@ class Configuration {
std::vector<Path> user_defined_paths;

bool IsBuiltIn() const;

private:
bool Load3_0(const std::vector<Layer>& available_layers, const QJsonObject& json_root_object);
};

std::string MakeConfigurationName(const std::vector<Configuration>& configurations, const std::string& configuration_name);
21 changes: 12 additions & 9 deletions vkconfig_core/configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void ConfigurationManager::LoadDefaultConfigurations(const std::vector<Layer> &a

for (int i = 0, n = configuration_files.size(); i < n; ++i) {
Configuration configuration;
const bool result = configuration.Load(available_layers, configuration_files[i]);
const bool result = configuration.Load(configuration_files[i], available_layers);
assert(result);

if (!IsPlatformSupported(configuration.platform_flags)) {
Expand Down Expand Up @@ -90,7 +90,7 @@ void ConfigurationManager::LoadConfigurationsPath(const std::vector<Layer> &avai
const std::vector<Path> &configuration_files = CollectFilePaths(Get(Path::CONFIGS));
for (int i = 0, n = configuration_files.size(); i < n; ++i) {
Configuration configuration;
const bool result = configuration.Load(available_layers, configuration_files[i]);
const bool result = configuration.Load(configuration_files[i], available_layers);
if (!result) {
continue;
}
Expand All @@ -108,12 +108,15 @@ void ConfigurationManager::LoadConfigurationsPath(const std::vector<Layer> &avai
}
}

static Path MakeConfigurationPath(const std::string &key) { return (Get(Path::CONFIGS) + "/" + key + ".json").AbsolutePath(); }
static Path MakeConfigurationPath(const std::string &key) {
const Path &path = Get(Path::CONFIGS) + "/" + key + ".json";
return path.AbsolutePath();
}

void ConfigurationManager::SaveAllConfigurations(const std::vector<Layer> &available_layers) {
void ConfigurationManager::SaveAllConfigurations() {
for (std::size_t i = 0, n = available_configurations.size(); i < n; ++i) {
const Path &path(MakeConfigurationPath(available_configurations[i].key));
available_configurations[i].Save(available_layers, path);
available_configurations[i].Save(path);
}
}

Expand All @@ -125,11 +128,11 @@ Configuration &ConfigurationManager::CreateConfiguration(const std::vector<Layer
new_configuration.key = MakeConfigurationName(available_configurations, configuration_name);

const Path &path(MakeConfigurationPath(new_configuration.key));
new_configuration.Save(available_layers, path);
new_configuration.Save(path);

// Reload from file to workaround the lack of SettingSet copy support
Configuration configuration;
const bool result = configuration.Load(available_layers, path);
const bool result = configuration.Load(path, available_layers);
assert(result);

this->available_configurations.push_back(configuration);
Expand Down Expand Up @@ -221,7 +224,7 @@ std::string ConfigurationManager::ImportConfiguration(const std::vector<Layer> &
assert(!full_import_path.Empty());

Configuration configuration;
if (!configuration.Load(available_layers, full_import_path)) {
if (!configuration.Load(full_import_path, available_layers)) {
QMessageBox msg;
msg.setIcon(QMessageBox::Critical);
msg.setWindowTitle("Import of Layers Configuration error");
Expand All @@ -246,7 +249,7 @@ void ConfigurationManager::ExportConfiguration(const std::vector<Layer> &availab
Configuration *configuration = FindByKey(available_configurations, configuration_name.c_str());
assert(configuration);

if (!configuration->Save(available_layers, full_export_path, true)) {
if (!configuration->Save(full_export_path, true)) {
QMessageBox msg;
msg.setIcon(QMessageBox::Critical);
msg.setWindowTitle("Export of Layers Configuration error");
Expand Down
2 changes: 1 addition & 1 deletion vkconfig_core/configuration_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ConfigurationManager {

void LoadAllConfigurations(const std::vector<Layer>& available_layers);

void SaveAllConfigurations(const std::vector<Layer>& available_layers);
void SaveAllConfigurations();

Configuration& CreateConfiguration(const std::vector<Layer>& available_layers, const std::string& configuration_name,
bool duplicate = false);
Expand Down
3 changes: 2 additions & 1 deletion vkconfig_core/configurations/3.0.0/API dump.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"rank": 0,
"settings": [
],
"control": "on"
"control": "on",
"version": "latest"
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion vkconfig_core/configurations/3.0.0/Crash Diagnostic.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
"value": true
}
],
"state": "OVERRIDDEN"
"control": "on",
"version": "latest"
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion vkconfig_core/configurations/3.0.0/Frame Capture.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"value": "${VK_LOCAL}/gfxrecon_capture.gfxr"
}
],
"control": "on"
"control": "on",
"version": "latest"
}
]
}
Expand Down
53 changes: 4 additions & 49 deletions vkconfig_core/configurations/3.0.0/Portability.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,13 @@
],
"description": "Check the Vulkan application is portable to Apple platforms",
"layers": [
{
"name": "VK_LAYER_LUNARG_api_dump",
"rank": -1,
"settings": [
],
"control": "off"
},
{
"name": "VK_LAYER_LUNARG_gfxreconstruct",
"rank": -1,
"settings": [
],
"control": "off",
"platforms": [
"WINDOWS",
"LINUX"
]
},
{
"name": "VK_LAYER_LUNARG_monitor",
"rank": -1,
"settings": [
],
"control": "off",
"platforms": [
"WINDOWS",
"LINUX"
]
},
{
"name": "VK_LAYER_LUNARG_screenshot",
"rank": -1,
"settings": [
],
"control": "off",
"platforms": [
"WINDOWS",
"LINUX"
]
},
{
"name": "VK_LAYER_KHRONOS_synchronization2",
"rank": -1,
"settings": [
],
"control": "off"
},
{
"name": "VK_LAYER_KHRONOS_validation",
"rank": 4,
"settings": [
],
"control": "on"
"control": "on",
"version": "latest"
},
{
"name": "VK_LAYER_KHRONOS_profiles",
Expand All @@ -79,7 +33,8 @@
"value": "VP_LUNARG_desktop_baseline_2023"
}
],
"control": "on"
"control": "on",
"version": "latest"
}
]
}
Expand Down
6 changes: 4 additions & 2 deletions vkconfig_core/configurations/3.0.0/Synchronization.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
"value": false
}
],
"control": "on"
"control": "on",
"version": "latest"
},
{
"name": "VK_LAYER_KHRONOS_synchronization2",
Expand All @@ -102,7 +103,8 @@
"value": false
}
],
"control": "on"
"control": "on",
"version": "latest"
}
]
}
Expand Down
Loading

0 comments on commit ef51ab8

Please sign in to comment.