Skip to content

Commit

Permalink
vkconfig3: Various clean up
Browse files Browse the repository at this point in the history
Change-Id: I1159ebf5919932fec023c02ccc6140a728cd87cc
  • Loading branch information
christophe-lunarg committed Sep 9, 2024
1 parent 9e41caf commit 9dc6d3b
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 195 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
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
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
6 changes: 2 additions & 4 deletions vkconfig_core/test/test_command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
#include "../util.h"
#include "../type_platform.h"

#if VKC_PLATFORM == VKC_PLATFORM_LINUX
#if VKC_ENV == VKC_ENV_UNIX
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#elif VKC_PLATFORM == VKC_PLATFORM_MACOS
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wwrite-strings"
#endif
Expand Down Expand Up @@ -203,8 +202,7 @@ TEST(test_command_line, usage_mode_layers_override_invalid_args) {
EXPECT_TRUE(command_line.layers_configuration_path.empty());
}

#if VKC_PLATFORM == VKC_PLATFORM_LINUX
#if VKC_ENV == VKC_ENV_UNIX
#pragma GCC diagnostic pop
#elif VKC_PLATFORM == VKC_PLATFORM_MACOS
#pragma clang diagnostic pop
#endif
4 changes: 2 additions & 2 deletions vkconfig_core/test/test_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST(test_path, native_path) {
for (std::size_t i = 0, n = std::size(table); i < n; ++i) {
const std::string test_case = table[i];

if (VKC_PLATFORM == VKC_PLATFORM_WINDOWS) {
if (VKC_ENV == VKC_ENV_WIN32) {
EXPECT_STREQ("\\vkconfig\\test\\path\\format", Path(test_case).RelativePath().c_str());
} else {
EXPECT_STREQ("/vkconfig/test/path/format", Path(test_case).RelativePath().c_str());
Expand All @@ -51,7 +51,7 @@ TEST(test_path, native_path_with_file) {
for (std::size_t i = 0, n = std::size(table); i < n; ++i) {
const std::string test_case = table[i];

if (VKC_PLATFORM == VKC_PLATFORM_WINDOWS) {
if (VKC_ENV == VKC_ENV_WIN32) {
EXPECT_STREQ("\\vkconfig\\test\\path\\format\\file.txt", Path(test_case).RelativePath().c_str());
} else {
EXPECT_STREQ("/vkconfig/test/path/format/file.txt", Path(test_case).RelativePath().c_str());
Expand Down
Loading

0 comments on commit 9dc6d3b

Please sign in to comment.