Skip to content

Commit

Permalink
vkconfig3: Fix layer control env var handling
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Nov 11, 2024
1 parent 5f88fed commit 9200963
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
56 changes: 20 additions & 36 deletions vkconfig_core/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,63 +86,48 @@ bool Layer::IsValid() const {
LayerControl Layer::GetActualControl() const {
if (this->type == LAYER_TYPE_IMPLICIT) {
if (!this->disable_env.empty()) {
if (this->disable_value.empty()) {
if (qEnvironmentVariableIsSet(this->disable_env.c_str())) {
return LAYER_CONTROL_OFF;
}
} else {
if (qgetenv(this->disable_env.c_str()).toStdString() == this->disable_value) {
return LAYER_CONTROL_OFF;
}
if (qEnvironmentVariableIsSet(this->disable_env.c_str())) {
return LAYER_CONTROL_OFF;
}
}

if (!this->enable_env.empty()) {
if (this->enable_value.empty()) {
if (qEnvironmentVariableIsSet(this->enable_env.c_str())) {
return LAYER_CONTROL_ON;
}
if (qgetenv(this->enable_env.c_str()).toStdString() == this->enable_value) {
return LAYER_CONTROL_ON;
} else {
if (qgetenv(this->enable_env.c_str()).toStdString() == this->enable_value) {
return LAYER_CONTROL_ON;
}
return LAYER_CONTROL_OFF; // Implicit layer which has an enable env must have it set to be enabled
}
}
}

return this->type == LAYER_TYPE_IMPLICIT ? LAYER_CONTROL_ON : LAYER_CONTROL_OFF;
return LAYER_CONTROL_ON; // Implicit layer
} else {
return LAYER_CONTROL_OFF; // Explicit layer
}
}

std::string Layer::GetActualControlTooltip() const {
if (this->type == LAYER_TYPE_IMPLICIT) {
if (!this->disable_env.empty()) {
const std::string& value = qgetenv(this->disable_env.c_str()).toStdString();
if (this->disable_value.empty()) {
if (qEnvironmentVariableIsSet(this->disable_env.c_str())) {
return format("'%s' is set", this->disable_env.c_str());
}
} else if (value == this->disable_value) {
if (qgetenv(this->disable_env.c_str()).toStdString() == this->disable_value) {
return format("'%s' is set to '%s'", this->disable_env.c_str(), value.c_str());
}
if (qEnvironmentVariableIsSet(this->disable_env.c_str())) {
return format("'%s' is set", this->disable_env.c_str());
}
}

if (!this->enable_env.empty()) {
const std::string& value = qgetenv(this->enable_env.c_str()).toStdString();
if (this->enable_value.empty()) {
if (qEnvironmentVariableIsSet(this->enable_env.c_str())) {
return format("'%s' is set", this->enable_env.c_str());
}
} else if (value == this->enable_value) {
if (qgetenv(this->enable_env.c_str()).toStdString() == this->enable_value) {
return format("'%s' is set to '%s'", this->enable_env.c_str(), value.c_str());
}
if (value == this->enable_value) {
return format("'%s' is set to '%s'.", this->enable_env.c_str(), value.c_str());
} else {
return format("Set '%s' to '%s' to enable '%s' by default.", this->enable_env.c_str(), this->enable_value.c_str(),
this->key.c_str());
}
}
}

return ::GetDescription(LAYER_CONTROL_AUTO);
return format("Set '%s' to disable '%s' by default.", this->disable_env.c_str(), this->key.c_str());
} else {
return ::GetDescription(LAYER_CONTROL_AUTO);
}
}

std::string Layer::FindPresetLabel(const SettingDataSet& settings) const {
Expand Down Expand Up @@ -338,7 +323,6 @@ bool Layer::Load(const Path& full_path_to_file, LayerType type, bool request_val
const QJsonObject& json_env_object = json_layer_object.value("disable_environment").toObject();
const QStringList keys = json_env_object.keys();
this->disable_env = keys[0].toStdString();
this->disable_value = ReadStringValue(json_env_object, this->disable_env.c_str());
}
if (json_layer_object.value("enable_environment") != QJsonValue::Undefined) {
const QJsonObject& json_env_object = json_layer_object.value("enable_environment").toObject();
Expand Down
1 change: 0 additions & 1 deletion vkconfig_core/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class Layer {
QJsonDocument profile;
std::string disable_env;
std::string enable_env;
std::string disable_value;
std::string enable_value;
bool is_32bits = false;
bool enabled = true;
Expand Down
26 changes: 24 additions & 2 deletions vkconfig_core/layer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,38 @@ std::string LayerManager::Log() const {

for (std::size_t path_index = 0, path_count = paths_group.size(); path_index < path_count; ++path_index) {
log += format(" - %s (%s)\n", paths_group[path_index].path.AbsolutePath().c_str(),
paths_group[path_index].enabled ? "enabled" : "disabled");
paths_group[path_index].enabled ? "Enabled" : "Disabled");

const std::vector<const Layer *> layers = this->GatherLayers(paths_group[path_index]);

for (std::size_t i = 0, n = layers.size(); i < n; ++i) {
log += format(" * %s - %s", layers[i]->key.c_str(), layers[i]->api_version.str().c_str());
if (layers[i]->type == LAYER_TYPE_IMPLICIT) {
log += format(" * %s - %s (Auto: %s)", layers[i]->key.c_str(), layers[i]->api_version.str().c_str(),
GetLabel(layers[i]->GetActualControl()));
} else {
log += format(" * %s - %s", layers[i]->key.c_str(), layers[i]->api_version.str().c_str());
}

if (layers[i]->status != STATUS_STABLE) {
log += format(" (%s)", GetToken(layers[i]->status));
}
log += "\n";

if (layers[i]->type == LAYER_TYPE_IMPLICIT) {
if (!layers[i]->disable_env.empty()) {
const std::string &value = qEnvironmentVariableIsSet(layers[i]->disable_env.c_str()) ? "set" : "not set";
log += format(" '%s' is %s\n", layers[i]->disable_env.c_str(), value.c_str());
}
if (!layers[i]->enable_env.empty()) {
if (qEnvironmentVariableIsSet(layers[i]->enable_env.c_str())) {
const std::string &value = qgetenv(layers[i]->enable_env.c_str()).toStdString();
log += format(" '%s' is set to '%s'\n", layers[i]->enable_env.c_str(), value.c_str());
} else {
log += format(" '%s' is not set to '%s'\n", layers[i]->enable_env.c_str(),
layers[i]->enable_value.c_str());
}
}
}
}
}
}
Expand Down

0 comments on commit 9200963

Please sign in to comment.