Skip to content

Commit

Permalink
vkconfig3: Various clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Sep 10, 2024
1 parent 9e41caf commit 974d731
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 207 deletions.
21 changes: 21 additions & 0 deletions vkconfig_core/application_manager.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 "application_manager.h"
26 changes: 26 additions & 0 deletions vkconfig_core/application_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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

class ApplicationManager {
public:
private:
};
12 changes: 6 additions & 6 deletions vkconfig_core/configuration_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ void ConfigurationManager::LoadDefaultConfigurations(const LayerManager &layers)
continue;
}

#ifdef _M_ARM64
if (configuration.key == "Frame Capture") {
continue;
} else if (configuration.key == "Crash Diagnostic") {
continue;
if (VKC_PLATFORM == PLATFORM_WINDOWS_ARM) {
if (configuration.key == "Frame Capture") {
continue;
} else if (configuration.key == "Crash Diagnostic") {
continue;
}
}
#endif

OrderParameter(configuration.parameters, layers);

Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ bool Configurator::Override(OverrideArea override_area) {
bool result_layers_settings = this->WriteLayersSettings(override_area, layers_settings_path);

// On Windows only, we need to write these values to the registry
#if VKC_PLATFORM == VKC_PLATFORM_WINDOWS
#if VKC_ENV == VKC_ENV_WIN32
AppendRegistryEntriesForLayers(loader_settings_path.AbsolutePath().c_str(), layers_settings_path.AbsolutePath().c_str());
#endif

Expand All @@ -441,7 +441,7 @@ bool Configurator::Surrender(OverrideArea override_area) {
result_layers_settings = layers_settings_path.Remove();
}

#if VKC_PLATFORM == VKC_PLATFORM_WINDOWS
#if VKC_ENV == VKC_ENV_WIN32
RemoveRegistryEntriesForLayers(loader_settings_path.AbsolutePath().c_str(), layers_settings_path.AbsolutePath().c_str());
#endif

Expand Down
14 changes: 8 additions & 6 deletions vkconfig_core/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@

static const char* GetApplicationSuffix() {
static const char* TABLE[] = {
".exe", // PLATFORM_WINDOWS
".exe", // PLATFORM_WINDOWS_X86
".exe", // PLATFORM_WINDOWS_ARM
"", // PLATFORM_LINUX
".app", // PLATFORM_MACOS
"N/A" // PLATFORM_ANDROID
"N/A", // PLATFORM_ANDROID
"N/A" // PLATFORM_IOS
};
static_assert(std::size(TABLE) == PLATFORM_COUNT, "The tranlation table size doesn't match the enum number of elements");

Expand Down Expand Up @@ -356,7 +358,7 @@ bool ExactExecutableFromAppBundle(Path& app_path) {
}

DefaultPath Environment::GetDefaultExecutablePath(const std::string& executable_name) const {
static const char* DEFAULT_PATH = VKC_PLATFORM == VKC_PLATFORM_MACOS ? "/../.." : "";
static const char* DEFAULT_PATH = VKC_PLATFORM == PLATFORM_MACOS ? "/../.." : "";

DefaultPath default_path{"." + executable_name, "."};

Expand All @@ -372,14 +374,14 @@ DefaultPath Environment::GetDefaultExecutablePath(const std::string& executable_
}

// Search the default applications from package installation (Linux)
if (VKC_PLATFORM == VKC_PLATFORM_LINUX) {
if (VKC_PLATFORM == PLATFORM_LINUX) {
const Path search_path(std::string("/usr/bin") + DEFAULT_PATH + executable_name);
if (search_path.Exists()) {
default_path.executable_path = Path(search_path.AbsolutePath(), true);
default_path.working_folder = Path(search_path.AbsoluteDir(), true);
return default_path;
}
} else if (VKC_PLATFORM == VKC_PLATFORM_MACOS) {
} else if (VKC_PLATFORM == PLATFORM_MACOS) {
Path search_path(std::string("/Applications") + executable_name);
if (search_path.Exists() && ExactExecutableFromAppBundle(search_path)) {
default_path.executable_path = Path(search_path.AbsolutePath(), true);
Expand All @@ -389,7 +391,7 @@ DefaultPath Environment::GetDefaultExecutablePath(const std::string& executable_
}

// Using relative path to vkconfig in case SDK is not "installed"
if (VKC_PLATFORM == VKC_PLATFORM_MACOS) {
if (VKC_PLATFORM == PLATFORM_MACOS) {
Path search_path(std::string("..") + DEFAULT_PATH + executable_name);
if (search_path.Exists() && ExactExecutableFromAppBundle(search_path)) {
default_path.executable_path = Path(search_path.AbsolutePath(), true);
Expand Down
9 changes: 7 additions & 2 deletions vkconfig_core/help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@

void ShowDoc(DocType doc_type) {
static const char* PLATFORM_STRING[] = {
"windows", // PLATFORM_WINDOWS
"windows", // PLATFORM_WINDOWS_X86
"windows", // PLATFORM_WINDOWS_ARM
"linux", // PLATFORM_LINUX
"mac" // PLATFORM_MACOS
"mac", // PLATFORM_MACOS
"android", // PLATFORM_ANDROID
"ios" // PLATFORM_ANDROID
};
static_assert(std::size(PLATFORM_STRING) == PLATFORM_COUNT,
"The tranlation table size doesn't match the enum number of elements");

const char* platform = PLATFORM_STRING[VKC_PLATFORM];

Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/layer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LayerType GetLayerType(LayersPaths Layers_paths_type) {
std::vector<LayersPathInfo> GetImplicitLayerPaths() {
std::vector<LayersPathInfo> result;

#if VKC_PLATFORM == VKC_PLATFORM_WINDOWS
#if VKC_ENV == VKC_ENV_WIN32
static const char *REGISTRY_PATHS[] = {
"HKEY_LOCAL_MACHINE\\Software\\Khronos\\Vulkan\\ImplicitLayers",
"HKEY_CURRENT_USER\\Software\\Khronos\\Vulkan\\ImplicitLayers",
Expand Down Expand Up @@ -74,7 +74,7 @@ std::vector<LayersPathInfo> GetImplicitLayerPaths() {
std::vector<LayersPathInfo> GetExplicitLayerPaths() {
std::vector<LayersPathInfo> result;

#if VKC_PLATFORM == VKC_PLATFORM_WINDOWS
#if VKC_ENV == VKC_ENV_WIN32
static const char *REGISTRY_PATHS[] = {
"HKEY_LOCAL_MACHINE\\Software\\Khronos\\Vulkan\\ExplicitLayers",
"HKEY_CURRENT_USER\\Software\\Khronos\\Vulkan\\ExplicitLayers",
Expand Down
16 changes: 11 additions & 5 deletions vkconfig_core/layer_preset.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 @@ -38,13 +38,19 @@ const LayerPreset* GetPreset(const std::vector<LayerPreset>& presets, const char
}

bool HasPreset(const SettingDataSet& layer_settings, const SettingDataSetConst& preset_settings) {
if (preset_settings.empty()) return false;
if (preset_settings.empty()) {
return false;
}

for (std::size_t preset_index = 0, preset_count = preset_settings.size(); preset_index < preset_count; ++preset_index) {
const SettingData* layer_setting = FindSetting(layer_settings, preset_settings[preset_index]->key.c_str());
if (layer_setting == nullptr) return false;
if (layer_setting == nullptr) {
return false;
}

if (*preset_settings[preset_index] != *layer_setting) return false;
if (*preset_settings[preset_index] != *layer_setting) {
return false;
}
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/layer_preset.h
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
66 changes: 0 additions & 66 deletions vkconfig_core/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,6 @@ ParameterRank GetParameterOrdering(const LayerManager& layers, const Parameter&
}
}

Version ComputeMinApiVersion(const Version api_version, const std::vector<Parameter>& parameters, const LayerManager& layers) {
if (parameters.empty()) {
return Version::NONE;
}

Version min_version = api_version;

for (std::size_t i = 0, n = parameters.size(); i < n; ++i) {
const Layer* layer = layers.Find(parameters[i].key, parameters[i].api_version);
if (layer == nullptr) {
continue;
}

const ParameterRank state = GetParameterOrdering(layers, parameters[i]);

if (state == PARAMETER_RANK_EXCLUDED) {
continue;
}
if (state == PARAMETER_RANK_MISSING) {
continue;
}

min_version = min_version < layer->api_version ? min_version : layer->api_version;
}

return min_version;
}

void OrderParameter(std::vector<Parameter>& parameters, const LayerManager& layers) {
struct ParameterCompare {
ParameterCompare(const LayerManager& layers) : layers(layers) {}
Expand Down Expand Up @@ -144,20 +116,6 @@ void OrderParameter(std::vector<Parameter>& parameters, const LayerManager& laye
}
}

void FilterParameters(std::vector<Parameter>& parameters, const LayerControl control) {
std::vector<Parameter> filtered_parameters;

for (std::size_t i = 0, n = parameters.size(); i < n; ++i) {
if (parameters[i].control == control) {
continue;
}

filtered_parameters.push_back(parameters[i]);
}

parameters = filtered_parameters;
}

bool HasMissingLayer(const std::vector<Parameter>& parameters, const LayerManager& layers, std::string& missing_layer) {
for (auto it = parameters.begin(), end = parameters.end(); it != end; ++it) {
if (it->control == LAYER_CONTROL_OFF) {
Expand Down Expand Up @@ -194,27 +152,3 @@ std::size_t CountOverriddenLayers(const std::vector<Parameter>& parameters) {

return count;
}

std::size_t CountExcludedLayers(const std::vector<Parameter>& parameters, const LayerManager& layers) {
std::size_t count = 0;

for (std::size_t i = 0, n = parameters.size(); i < n; ++i) {
const Parameter& parameter = parameters[i];
if (!IsPlatformSupported(parameter.platform_flags)) {
continue;
}

if (parameter.control != LAYER_CONTROL_OFF) {
continue;
}

const Layer* layer = layers.Find(parameter.key, parameter.api_version);
if (layer == nullptr) {
continue; // Do not display missing excluded layers
}

++count;
}

return count;
}
3 changes: 0 additions & 3 deletions vkconfig_core/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ struct Parameter {
};

ParameterRank GetParameterOrdering(const LayerManager& layers, const Parameter& parameter);
Version ComputeMinApiVersion(const Version api_version, const std::vector<Parameter>& parameters, const LayerManager& layers);
void OrderParameter(std::vector<Parameter>& parameters, const LayerManager& layers);
void FilterParameters(std::vector<Parameter>& parameters, const LayerControl control);

bool HasMissingLayer(const std::vector<Parameter>& parameters, const LayerManager& layers, std::string& missing_layer);

std::size_t CountOverriddenLayers(const std::vector<Parameter>& parameters);
std::size_t CountExcludedLayers(const std::vector<Parameter>& parameters, const LayerManager& layers);
14 changes: 9 additions & 5 deletions vkconfig_core/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,20 @@ static const Path GetLoaderSettingsPath() {

static const Path GetSDKPath() {
const char* TABLE[] = {
"", // PLATFORM_WINDOWS
"", // PLATFORM_WINDOWS_X86
"", // PLATFORM_WINDOWS_ARM
"/usr", // PLATFORM_LINUX
"/usr/local/share/vulkan", // PLATFORM_MACOS
"" // PLATFORM_ANDROID
"", // PLATFORM_ANDROID
"" // PLATFORM_IOS
};
static_assert(std::size(TABLE) == PLATFORM_COUNT, "The tranlation table size doesn't match the enum number of elements");

std::string result = qgetenv("VULKAN_SDK").toStdString();
if (result.empty()) {
result = TABLE[VKC_PLATFORM];
} else { // VULKAN_SDK may be set on macOS
if (VKC_PLATFORM == VKC_PLATFORM_MACOS) {
if (VKC_PLATFORM == PLATFORM_MACOS) {
result += "/share/vulkan";
}
}
Expand Down Expand Up @@ -377,10 +379,12 @@ static const Path GetExplicitLayersPath() {

static const Path GetVulkanContentPath() {
static const std::string TABLE[] = {
"/Config", // PLATFORM_WINDOWS
"/Config", // PLATFORM_WINDOWS_86
"/Config", // PLATFORM_WINDOWS_ARM
"/share/vulkan/config", // PLATFORM_LINUX
"/config", // PLATFORM_MACOS
"N/A" // PLATFORM_ANDROID
"N/A", // PLATFORM_ANDROID
"N/A" // PLATFORM_IOS
};
static_assert(std::size(TABLE) == PLATFORM_COUNT);

Expand Down
4 changes: 2 additions & 2 deletions vkconfig_core/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <QTextStream>

#if VKC_PLATFORM == VKC_PLATFORM_WINDOWS
#if VKC_ENV == VKC_ENV_WIN32
#include <windows.h>
#include <winreg.h>
#include <Cfgmgr32.h>
Expand Down Expand Up @@ -200,4 +200,4 @@ std::vector<LayersPathInfo> LoadRegistryLayers(const QString &path) {
return layers_paths;
}

#endif // VKC_PLATFORM == VKC_PLATFORM_WINDOWS
#endif // VKC_ENV == VKC_ENV_WIN32
4 changes: 2 additions & 2 deletions vkconfig_core/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "type_platform.h"
#include "layer.h"

#if VKC_PLATFORM == VKC_PLATFORM_WINDOWS
#if VKC_ENV == VKC_ENV_WIN32

#include <QString>

Expand All @@ -35,4 +35,4 @@ void RemoveRegistryEntriesForLayers(QString override_file, QString settings_file

std::vector<LayersPathInfo> LoadRegistryLayers(const QString &path);

#endif // VKC_PLATFORM == VKC_PLATFORM_WINDOWS
#endif // VKC_ENV == VKC_ENV_WIN32
Loading

0 comments on commit 974d731

Please sign in to comment.