From 6f7f75a0001ae3d154042b19c01cb7d88c704358 Mon Sep 17 00:00:00 2001 From: Christophe Date: Thu, 17 Aug 2023 15:12:56 +0200 Subject: [PATCH] tests: Use VK_EXT_layer_settings for testing --- CMakeLists.txt | 2 - .../VkLayer_khronos_memory_decompression.def | 1 + layers/VkLayer_khronos_shader_object.def | 1 + layers/VkLayer_khronos_synchronization2.def | 9 +- layers/VkLayer_khronos_timeline_semaphore.def | 9 +- ...ibVkLayer_khronos_memory_decompression.map | 1 + layers/libVkLayer_khronos_shader_object.map | 1 + .../libVkLayer_khronos_synchronization2.map | 1 + .../libVkLayer_khronos_timeline_semaphore.map | 1 + scripts/known_good.json | 2 +- tests/CMakeLists.txt | 1 + tests/decompression_tests.cpp | 12 +- tests/extension_layer_tests.cpp | 2 +- tests/extension_layer_tests.h | 1 + tests/shader_object_tests.cpp | 16 +- tests/synchronization2_tests.cpp | 14 +- tests/vkrenderframework.h | 4 +- tests/vktestframework.cpp | 9 + tests/vktestframework.h | 2 + utils/CMakeLists.txt | 1 - utils/vk_layer_config.cpp | 425 ------------------ utils/vk_layer_config.h | 107 ----- 22 files changed, 64 insertions(+), 558 deletions(-) delete mode 100644 utils/vk_layer_config.cpp delete mode 100644 utils/vk_layer_config.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fee7326..b1d55657 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,8 +68,6 @@ endif() find_package(VulkanUtilityLibraries CONFIG REQUIRED QUIET) -target_compile_definitions(Vulkan::LayerSettings INTERFACE VK_ENABLE_BETA_EXTENSIONS) # Enable beta Vulkan extensions - option(BUILD_WERROR "Treat compiler warnings as errors") if (BUILD_WERROR) add_compile_options("$,/WX,-Werror>") diff --git a/layers/VkLayer_khronos_memory_decompression.def b/layers/VkLayer_khronos_memory_decompression.def index 86ad6a08..990ab63d 100755 --- a/layers/VkLayer_khronos_memory_decompression.def +++ b/layers/VkLayer_khronos_memory_decompression.def @@ -25,3 +25,4 @@ vkGetInstanceProcAddr vkGetDeviceProcAddr vkEnumerateInstanceExtensionProperties vkNegotiateLoaderLayerInterfaceVersion +vkEnumerateInstanceLayerSettingsEXT diff --git a/layers/VkLayer_khronos_shader_object.def b/layers/VkLayer_khronos_shader_object.def index d876c80e..ae4e2616 100644 --- a/layers/VkLayer_khronos_shader_object.def +++ b/layers/VkLayer_khronos_shader_object.def @@ -21,3 +21,4 @@ LIBRARY VkLayer_khronos_shader_object EXPORTS vkGetInstanceProcAddr vkGetDeviceProcAddr +vkEnumerateInstanceLayerSettingsEXT diff --git a/layers/VkLayer_khronos_synchronization2.def b/layers/VkLayer_khronos_synchronization2.def index 5359f0a8..ed56492a 100644 --- a/layers/VkLayer_khronos_synchronization2.def +++ b/layers/VkLayer_khronos_synchronization2.def @@ -1,10 +1,10 @@ ;;;; Begin Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; -; Copyright (c) 2015-2021 The Khronos Group Inc. -; Copyright (c) 2015-2021 Valve Corporation -; Copyright (c) 2015-2021 LunarG, Inc. -; Copyright (c) 2020 Intel Corporation +; Copyright (c) 2015-2021, 2023 The Khronos Group Inc. +; Copyright (c) 2015-2021, 2023 Valve Corporation +; Copyright (c) 2015-2021, 2023 LunarG, Inc. +; Copyright (c) 2020 Intel Corporation ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. @@ -27,3 +27,4 @@ EXPORTS vkGetInstanceProcAddr vkGetDeviceProcAddr vkNegotiateLoaderLayerInterfaceVersion +vkEnumerateInstanceLayerSettingsEXT diff --git a/layers/VkLayer_khronos_timeline_semaphore.def b/layers/VkLayer_khronos_timeline_semaphore.def index fa861e82..81f2665c 100644 --- a/layers/VkLayer_khronos_timeline_semaphore.def +++ b/layers/VkLayer_khronos_timeline_semaphore.def @@ -1,10 +1,10 @@ ;;;; Begin Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; -; Copyright (c) 2015-2019, 2021 The Khronos Group Inc. -; Copyright (c) 2015-2019, 2021 Valve Corporation -; Copyright (c) 2015-2019, 2021 LunarG, Inc. -; Copyright (c) 2020 Intel Corporation +; Copyright (c) 2015-2019, 2021, 2023 The Khronos Group Inc. +; Copyright (c) 2015-2019, 2021, 2023 Valve Corporation +; Copyright (c) 2015-2019, 2021, 2023 LunarG, Inc. +; Copyright (c) 2020 Intel Corporation ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. @@ -27,3 +27,4 @@ EXPORTS vkGetInstanceProcAddr vkGetDeviceProcAddr vkEnumerateInstanceExtensionProperties +vkEnumerateInstanceLayerSettingsEXT diff --git a/layers/libVkLayer_khronos_memory_decompression.map b/layers/libVkLayer_khronos_memory_decompression.map index 6ad46e6a..092ef325 100755 --- a/layers/libVkLayer_khronos_memory_decompression.map +++ b/layers/libVkLayer_khronos_memory_decompression.map @@ -6,6 +6,7 @@ vkEnumerateInstanceLayerProperties; vkEnumerateDeviceExtensionProperties; vkEnumerateDeviceLayerProperties; + vkEnumerateInstanceLayerSettingsEXT; local: *; }; diff --git a/layers/libVkLayer_khronos_shader_object.map b/layers/libVkLayer_khronos_shader_object.map index 6ad46e6a..092ef325 100644 --- a/layers/libVkLayer_khronos_shader_object.map +++ b/layers/libVkLayer_khronos_shader_object.map @@ -6,6 +6,7 @@ vkEnumerateInstanceLayerProperties; vkEnumerateDeviceExtensionProperties; vkEnumerateDeviceLayerProperties; + vkEnumerateInstanceLayerSettingsEXT; local: *; }; diff --git a/layers/libVkLayer_khronos_synchronization2.map b/layers/libVkLayer_khronos_synchronization2.map index 6ad46e6a..092ef325 100644 --- a/layers/libVkLayer_khronos_synchronization2.map +++ b/layers/libVkLayer_khronos_synchronization2.map @@ -6,6 +6,7 @@ vkEnumerateInstanceLayerProperties; vkEnumerateDeviceExtensionProperties; vkEnumerateDeviceLayerProperties; + vkEnumerateInstanceLayerSettingsEXT; local: *; }; diff --git a/layers/libVkLayer_khronos_timeline_semaphore.map b/layers/libVkLayer_khronos_timeline_semaphore.map index 6ad46e6a..092ef325 100644 --- a/layers/libVkLayer_khronos_timeline_semaphore.map +++ b/layers/libVkLayer_khronos_timeline_semaphore.map @@ -6,6 +6,7 @@ vkEnumerateInstanceLayerProperties; vkEnumerateDeviceExtensionProperties; vkEnumerateDeviceLayerProperties; + vkEnumerateInstanceLayerSettingsEXT; local: *; }; diff --git a/scripts/known_good.json b/scripts/known_good.json index 525cb47b..7f23c7d7 100755 --- a/scripts/known_good.json +++ b/scripts/known_good.json @@ -14,7 +14,7 @@ "sub_dir": "Vulkan-Utility-Libraries", "build_dir": "Vulkan-Utility-Libraries/build", "install_dir": "Vulkan-Utility-Libraries/build/install", - "commit": "c0525368d724896349b40d8aa7b779f32bbbed0c", + "commit": "6999ef9b82191d4824cd105aba1f5f2433b4ccb6", "deps": [ { "var_name": "VULKAN_HEADERS_INSTALL_DIR", diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1fb883f3..868e7272 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -92,6 +92,7 @@ find_package(glslang REQUIRED CONFIG QUIET) target_link_libraries(vk_extension_layer_tests PRIVATE VkExtLayer_utils + Vulkan::LayerSettings Vulkan::Headers GTest::gtest GTest::gtest_main diff --git a/tests/decompression_tests.cpp b/tests/decompression_tests.cpp index fd66da6e..53a7a395 100644 --- a/tests/decompression_tests.cpp +++ b/tests/decompression_tests.cpp @@ -24,12 +24,20 @@ #include "decompression_data.h" void DecompressionTest::SetUp() { - SetEnvironment("VK_MEMORY_DECOMPRESSION_FORCE_ENABLE", "1"); + VkBool32 force_enable = VK_TRUE; + + VkLayerSettingEXT settings[] = { + {"VK_LAYER_KHRONOS_memory_decompression", "force_enable", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &force_enable}}; + + VkLayerSettingsCreateInfoEXT layer_settings_create_info{ + VK_STRUCTURE_TYPE_LAYER_SETTINGS_EXT, nullptr, + static_cast(std::size(settings)), &settings[0]}; + VkExtensionLayerTest::SetUp(); SetTargetApiVersion(VK_API_VERSION_1_2); VkExtensionLayerTest::AddSurfaceInstanceExtension(); instance_layers_.push_back("VK_LAYER_KHRONOS_memory_decompression"); - ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor, &layer_settings_create_info)); VkExtensionLayerTest::AddSwapchainDeviceExtension(); } diff --git a/tests/extension_layer_tests.cpp b/tests/extension_layer_tests.cpp index b6d2209f..5b9666da 100755 --- a/tests/extension_layer_tests.cpp +++ b/tests/extension_layer_tests.cpp @@ -675,7 +675,7 @@ int main(int argc, char **argv) { #endif // Set VK_LAYER_PATH so that the loader can find the layers - SetEnvironment("VK_LAYER_PATH", LAYER_BUILD_LOCATION); + VkTestFramework::setEnvironmentSetting("VK_LAYER_PATH", LAYER_BUILD_LOCATION); ::testing::InitGoogleTest(&argc, argv); VkTestFramework::InitArgs(&argc, argv); diff --git a/tests/extension_layer_tests.h b/tests/extension_layer_tests.h index 8e95f684..e5b0099b 100755 --- a/tests/extension_layer_tests.h +++ b/tests/extension_layer_tests.h @@ -28,6 +28,7 @@ #define VKLAYERTEST_H #include +#include #if defined(ANDROID) #include diff --git a/tests/shader_object_tests.cpp b/tests/shader_object_tests.cpp index 7c284412..407b195f 100644 --- a/tests/shader_object_tests.cpp +++ b/tests/shader_object_tests.cpp @@ -20,17 +20,23 @@ #include "extension_layer_tests.h" #include "shader_object_tests.h" -#include "vk_layer_config.h" void ShaderObjectTest::SetUp() { - SetEnvironment("VK_SHADER_OBJECT_FORCE_ENABLE", "1"); - const std::string layer_path = std::string(SHADER_OBJECT_BINARY_PATH); - SetEnvironment("VK_LAYER_PATH", layer_path.c_str()); + VkBool32 force_enable = VK_TRUE; + + VkLayerSettingEXT settings[] = { + {"VK_LAYER_KHRONOS_shader_object", "force_enable", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &force_enable} + }; + + VkLayerSettingsCreateInfoEXT layer_settings_create_info{ + VK_STRUCTURE_TYPE_LAYER_SETTINGS_EXT, nullptr, + static_cast(std::size(settings)), &settings[0]}; + VkExtensionLayerTest::SetUp(); SetTargetApiVersion(VK_API_VERSION_1_1); VkExtensionLayerTest::AddSurfaceInstanceExtension(); instance_layers_.push_back("VK_LAYER_KHRONOS_shader_object"); - ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor, &layer_settings_create_info)); VkExtensionLayerTest::AddSwapchainDeviceExtension(); } diff --git a/tests/synchronization2_tests.cpp b/tests/synchronization2_tests.cpp index 48cf16fa..3b5d9292 100644 --- a/tests/synchronization2_tests.cpp +++ b/tests/synchronization2_tests.cpp @@ -28,15 +28,23 @@ #include "extension_layer_tests.h" #include "synchronization2_tests.h" -#include "vk_layer_config.h" void Sync2Test::SetUp() { - SetEnvironment("VK_SYNCHRONIZATION2_FORCE_ENABLE", "1"); + VkBool32 force_enable = VK_TRUE; + + VkLayerSettingEXT settings[] = { + {"VK_LAYER_KHRONOS_synchronization2", "force_enable", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &force_enable} + }; + + VkLayerSettingsCreateInfoEXT layer_settings_create_info{ + VK_STRUCTURE_TYPE_LAYER_SETTINGS_EXT, nullptr, + static_cast(std::size(settings)), &settings[0]}; + VkExtensionLayerTest::SetUp(); SetTargetApiVersion(VK_API_VERSION_1_2); VkExtensionLayerTest::AddSurfaceInstanceExtension(); instance_layers_.push_back("VK_LAYER_KHRONOS_synchronization2"); - ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor, &layer_settings_create_info)); VkExtensionLayerTest::AddSwapchainDeviceExtension(); } diff --git a/tests/vkrenderframework.h b/tests/vkrenderframework.h index f27766c9..c04d05c9 100644 --- a/tests/vkrenderframework.h +++ b/tests/vkrenderframework.h @@ -44,8 +44,6 @@ class VkImageObj; #include #include -#include "vk_layer_config.h" - using vk_testing::MakeVkHandles; template @@ -129,7 +127,7 @@ class ErrorMonitor { // Helpers // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags - void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = kErrorBit); + void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT); void VerifyFound(); void VerifyNotFound(); diff --git a/tests/vktestframework.cpp b/tests/vktestframework.cpp index a9a65f6d..d61ffcef 100644 --- a/tests/vktestframework.cpp +++ b/tests/vktestframework.cpp @@ -114,6 +114,15 @@ VkTestFramework::VkTestFramework() : m_compile_options(0), m_num_shader_strings( VkTestFramework::~VkTestFramework() {} +// TODO: When the layer path issue is resolved with CI (set outside of the tests) remove this function +void VkTestFramework::setEnvironmentSetting(std::string setting, const char *val) { +#ifdef _WIN32 + _putenv_s(setting.c_str(), val); +#else + setenv(setting.c_str(), val, 1); +#endif +} + // Define all the static elements bool VkTestFramework::m_canonicalize_spv = false; bool VkTestFramework::m_strip_spv = false; diff --git a/tests/vktestframework.h b/tests/vktestframework.h index 5027dd22..d121690c 100644 --- a/tests/vktestframework.h +++ b/tests/vktestframework.h @@ -71,6 +71,8 @@ class VkTestFramework : public ::testing::Test { char **ReadFileData(const char *fileName); void FreeFileData(char **data); + static void setEnvironmentSetting(std::string setting, const char *val); + protected: VkTestFramework(); virtual ~VkTestFramework() = 0; diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 4589926c..8acfa5cd 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -20,7 +20,6 @@ add_library(VkExtLayer_utils STATIC) target_sources(VkExtLayer_utils PRIVATE allocator.cpp vk_format_utils.cpp - vk_layer_config.cpp generated/vk_safe_struct.cpp generated/lvt_function_pointers.cpp ) diff --git a/utils/vk_layer_config.cpp b/utils/vk_layer_config.cpp deleted file mode 100644 index fbcde344..00000000 --- a/utils/vk_layer_config.cpp +++ /dev/null @@ -1,425 +0,0 @@ -/************************************************************************** - * - * Copyright 2014-2020, 2022-2023 Valve Software - * Copyright 2015-2020, 2022-2023 Google Inc. - * Copyright 2019-2020, 2022-2023 LunarG, Inc. - * All Rights Reserved. - * - * 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. - * - * Author: Jon Ashburn - * Author: Courtney Goeltzenleuchter - * Author: Tobin Ehlis - * Author: Mark Lobodzinski - **************************************************************************/ -#include "vk_layer_config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "vk_string_utils.h" - -#if defined(_WIN32) -#include -#include -#define GetCurrentDir _getcwd -#else -#include -#define GetCurrentDir getcwd -#endif - -class ConfigFile { - public: - ConfigFile(); - ~ConfigFile(){}; - - const char *GetOption(const std::string &option); - void SetOption(const std::string &option, const std::string &value); - std::string vk_layer_disables_env_var; - SettingsFileInfo settings_info{}; - - private: - bool file_is_parsed_; - std::map value_map_; - - std::string FindSettings(); - void ParseFile(const char *filename); -}; - -static ConfigFile layer_config; - -// On at least some platforms, environment functions are not reentrant. -// It is possible to run test cases concurrently in multiple threads, -// so guard the calls to these functions. -static std::mutex layer_env_mutex; - -std::string GetEnvironment(const char *variable) { - const std::lock_guard guard(layer_env_mutex); -#if !defined(__ANDROID__) && !defined(_WIN32) - const char *output = getenv(variable); - return output == NULL ? "" : output; -#elif defined(_WIN32) - int size = GetEnvironmentVariable(variable, NULL, 0); - if (size == 0) { - return ""; - } - char *buffer = new char[size]; - GetEnvironmentVariable(variable, buffer, size); - std::string output = buffer; - delete[] buffer; - return output; -#elif defined(__ANDROID__) - std::string command = "getprop " + std::string(variable); - FILE *pPipe = popen(command.c_str(), "r"); - if (pPipe != nullptr) { - char value[256]; - fgets(value, 256, pPipe); - pclose(pPipe); - - // Make sure its not an empty line - if (strcspn(value, "\r\n") == 0) { - return ""; - } else { - return std::string(value); - } - } else { - return ""; - } -#else - return ""; -#endif -} - -bool SetEnvironment(const char *name, const char *value) { - const std::lock_guard guard(layer_env_mutex); -#if !defined(__ANDROID__) && !defined(_WIN32) - // don't overwrite if the variable is already set. - return (setenv(name, value, 0) == 0) ? true : false; -#elif defined(_WIN32) - int size = GetEnvironmentVariable(name, NULL, 0); - // only overwrite if the variable isn't already set. - if (size == 0) { - return static_cast(SetEnvironmentVariable(name, value)); - } - return true; -#elif defined(__ANDROID__) - // TODO: unclear if this is possible on android - return false; -#else - return false; -#endif -} - -const char *GetLayerOption(const char *option) { return layer_config.GetOption(option); } - -const SettingsFileInfo *GetLayerSettingsFileInfo() { return &layer_config.settings_info; } - -// If option is NULL or stdout, return stdout, otherwise try to open option -// as a filename. If successful, return file handle, otherwise stdout -FILE *GetLayerLogOutput(const char *option, const char *layer_name) { - FILE *log_output = NULL; - if (!option || !strcmp("stdout", option)) { - log_output = stdout; - } else { - log_output = fopen(option, "w"); - if (log_output == NULL) { - if (option) { - std::cout << std::endl - << layer_name << " ERROR: Bad output filename specified: " << option << ". Writing to STDOUT instead" - << std::endl - << std::endl; - } - log_output = stdout; - } - } - return log_output; -} - -// Map option strings to flag enum values -VkFlags GetLayerOptionFlags(std::string option, std::unordered_map const &enum_data, - uint32_t option_default) { - VkDebugReportFlagsEXT flags = option_default; - std::string option_list = layer_config.GetOption(option.c_str()); - - while (option_list.length() != 0) { - // Find length of option string - std::size_t option_length = option_list.find(","); - if (option_length == option_list.npos) { - option_length = option_list.size(); - } - - // Get first option item in list - const std::string option_item = option_list.substr(0, option_length); - - auto enum_value = enum_data.find(option_item); - if (enum_value != enum_data.end()) { - flags |= enum_value->second; - } - - // Remove first option from option_list - option_list.erase(0, option_length); - // Remove possible comma separator - std::size_t char_position = option_list.find(","); - if (char_position == 0) { - option_list.erase(char_position, 1); - } - // Remove possible space - char_position = option_list.find(" "); - if (char_position == 0) { - option_list.erase(char_position, 1); - } - } - return flags; -} - -void SetLayerOption(const char *option, const char *value) { layer_config.SetOption(option, value); } - -// Constructor for ConfigFile. Initialize layers to log error messages to stdout by default. If a vk_layer_settings file is present, -// its settings will override the defaults. -ConfigFile::ConfigFile() : file_is_parsed_(false) { -} - -const char *ConfigFile::GetOption(const std::string &option) { - std::map::const_iterator it; - if (!file_is_parsed_) { - std::string settings_file = FindSettings(); - ParseFile(settings_file.c_str()); - } - - if ((it = value_map_.find(option)) == value_map_.end()) { - return ""; - } else { - return it->second.c_str(); - } -} - -void ConfigFile::SetOption(const std::string &option, const std::string &val) { - if (!file_is_parsed_) { - std::string settings_file = FindSettings(); - ParseFile(settings_file.c_str()); - } - - value_map_[option] = val; -} - -#if defined(WIN32) -// Check for admin rights -static inline bool IsHighIntegrity() { - HANDLE process_token; - if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_QUERY_SOURCE, &process_token)) { - // Maximum possible size of SID_AND_ATTRIBUTES is maximum size of a SID + size of attributes DWORD. - uint8_t mandatory_label_buffer[SECURITY_MAX_SID_SIZE + sizeof(DWORD)]; - DWORD buffer_size; - if (GetTokenInformation(process_token, TokenIntegrityLevel, mandatory_label_buffer, sizeof(mandatory_label_buffer), - &buffer_size) != 0) { - const TOKEN_MANDATORY_LABEL *mandatory_label = (const TOKEN_MANDATORY_LABEL *)mandatory_label_buffer; - const DWORD sub_authority_count = *GetSidSubAuthorityCount(mandatory_label->Label.Sid); - const DWORD integrity_level = *GetSidSubAuthority(mandatory_label->Label.Sid, sub_authority_count - 1); - - CloseHandle(process_token); - return integrity_level > SECURITY_MANDATORY_MEDIUM_RID; - } - - CloseHandle(process_token); - } - - return false; -} -#endif - -std::string ConfigFile::FindSettings() { - struct stat info; - -#if defined(WIN32) - // Look for VkConfig-specific settings location specified in the windows registry - HKEY key; - - const std::array hives = {DEFAULT_VK_REGISTRY_HIVE, SECONDARY_VK_REGISTRY_HIVE}; - const size_t hives_to_check_count = IsHighIntegrity() ? 1 : hives.size(); // Admin checks only the default hive - - for (size_t hive_index = 0; hive_index < hives_to_check_count; ++hive_index) { - LSTATUS err = RegOpenKeyEx(hives[hive_index], "Software\\Khronos\\Vulkan\\Settings", 0, KEY_READ, &key); - if (err == ERROR_SUCCESS) { - char name[2048]; - DWORD i = 0, name_size, type, value, value_size; - while (ERROR_SUCCESS == RegEnumValue(key, i++, name, &(name_size = sizeof(name)), nullptr, &type, - reinterpret_cast(&value), &(value_size = sizeof(value)))) { - // Check if the registry entry is a dword with a value of zero - if (type != REG_DWORD || value != 0) { - continue; - } - - // Check if this actually points to a file - if ((stat(name, &info) != 0) || !(info.st_mode & S_IFREG)) { - continue; - } - - // Use this file - RegCloseKey(key); - settings_info.source = kVkConfig; - settings_info.location = name; - return name; - } - - RegCloseKey(key); - } - } - -#else - // Look for VkConfig-specific settings location specified in a specific spot in the linux settings store - std::string search_path = GetEnvironment("XDG_DATA_HOME"); - if (search_path == "") { - search_path = GetEnvironment("HOME"); - if (search_path != "") { - search_path += "/.local/share"; - } - } - // Use the vk_layer_settings.txt file from here, if it is present - if (search_path != "") { - std::string home_file = search_path + "/vulkan/settings.d/vk_layer_settings.txt"; - if (stat(home_file.c_str(), &info) == 0) { - if (info.st_mode & S_IFREG) { - settings_info.source = kVkConfig; - settings_info.location = home_file; - return home_file; - } - } - } - -#endif - // Look for an enviornment variable override for the settings file location - std::string env_path = GetEnvironment("VK_LAYER_SETTINGS_PATH"); - - // If the path exists use it, else use vk_layer_settings - if (stat(env_path.c_str(), &info) == 0) { - // If this is a directory, append settings file name - if (info.st_mode & S_IFDIR) { - env_path.append("/vk_layer_settings.txt"); - } - settings_info.source = kEnvVar; - settings_info.location = env_path; - return env_path; - } - - // Default -- use the current working directory for the settings file location - settings_info.source = kLocal; - char buff[512]; - auto buf_ptr = GetCurrentDir(buff, 512); - if (buf_ptr) { - settings_info.location = buf_ptr; - settings_info.location.append("\\vk_layer_settings.txt"); - } - return "vk_layer_settings.txt"; -} - -void ConfigFile::ParseFile(const char *filename) { - file_is_parsed_ = true; - - // Extract option = value pairs from a file - std::ifstream file(filename); - if (file.good()) { - settings_info.file_found = true; - for (std::string line; std::getline(file, line);) { - // discard comments, which start with '#' - const auto comments_pos = line.find_first_of('#'); - if (comments_pos != std::string::npos) line.erase(comments_pos); - - const auto value_pos = line.find_first_of('='); - if (value_pos != std::string::npos) { - const std::string option = string_trim(line.substr(0, value_pos)); - const std::string value = string_trim(line.substr(value_pos + 1)); - value_map_[option] = value; - } - } - } -} - -void PrintMessageFlags(VkFlags vk_flags, char *msg_flags) { - bool separator = false; - - msg_flags[0] = 0; - if (vk_flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) { - strcat(msg_flags, "DEBUG"); - separator = true; - } - if (vk_flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "INFO"); - separator = true; - } - if (vk_flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "WARN"); - separator = true; - } - if (vk_flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "PERF"); - separator = true; - } - if (vk_flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "ERROR"); - } -} - -void PrintMessageSeverity(VkFlags vk_flags, char *msg_flags) { - bool separator = false; - - msg_flags[0] = 0; - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) { - strcat(msg_flags, "VERBOSE"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "INFO"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "WARN"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "ERROR"); - } -} - -void PrintMessageType(VkFlags vk_flags, char *msg_flags) { - bool separator = false; - - msg_flags[0] = 0; - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT) { - strcat(msg_flags, "GEN"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "SPEC"); - separator = true; - } - if (vk_flags & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) { - if (separator) strcat(msg_flags, ","); - strcat(msg_flags, "PERF"); - } -} diff --git a/utils/vk_layer_config.h b/utils/vk_layer_config.h deleted file mode 100644 index 4fc99c81..00000000 --- a/utils/vk_layer_config.h +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright (c) 2015-2020,2023 The Khronos Group Inc. - * Copyright (c) 2015-2020,2023 Valve Corporation - * Copyright (c) 2015-2020,2023 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. - * - * Author: Jon Ashburn - * Author: Mark Lobodzinski - **************************************************************************/ -#pragma once - -#include -#include -#include - -#include "vulkan/vk_layer.h" -#include "vulkan/vulkan.h" - -#if defined(WIN32) -#define DEFAULT_VK_REGISTRY_HIVE HKEY_LOCAL_MACHINE -#define DEFAULT_VK_REGISTRY_HIVE_STR "HKEY_LOCAL_MACHINE" -#define SECONDARY_VK_REGISTRY_HIVE HKEY_CURRENT_USER -#define SECONDARY_VK_REGISTRY_HIVE_STR "HKEY_CURRENT_USER" -#endif - -typedef enum { - kVkConfig, - kEnvVar, - kLocal, -} SettingsFileSource; - -typedef struct SettingsFileInfo { - bool file_found = false; - std::string location{}; - SettingsFileSource source = kLocal; -} SettingsFileInfo; - -typedef enum { - kInformationBit = 0x00000001, - kWarningBit = 0x00000002, - kPerformanceWarningBit = 0x00000004, - kErrorBit = 0x00000008, - kDebugBit = 0x00000010, -} LogMessageTypeBits; -typedef VkFlags LogMessageTypeFlags; - -// Definitions for Debug Actions -typedef enum VkLayerDbgActionBits { - VK_DBG_LAYER_ACTION_IGNORE = 0x00000000, - VK_DBG_LAYER_ACTION_CALLBACK = 0x00000001, - VK_DBG_LAYER_ACTION_LOG_MSG = 0x00000002, - VK_DBG_LAYER_ACTION_BREAK = 0x00000004, - VK_DBG_LAYER_ACTION_DEBUG_OUTPUT = 0x00000008, - VK_DBG_LAYER_ACTION_DEFAULT = 0x40000000, -} VkLayerDbgActionBits; -typedef VkFlags VkLayerDbgActionFlags; - -const std::unordered_map debug_actions_option_definitions = { - {std::string("VK_DBG_LAYER_ACTION_IGNORE"), VK_DBG_LAYER_ACTION_IGNORE}, - {std::string("VK_DBG_LAYER_ACTION_CALLBACK"), VK_DBG_LAYER_ACTION_CALLBACK}, - {std::string("VK_DBG_LAYER_ACTION_LOG_MSG"), VK_DBG_LAYER_ACTION_LOG_MSG}, - {std::string("VK_DBG_LAYER_ACTION_BREAK"), VK_DBG_LAYER_ACTION_BREAK}, -#if defined(WIN32) - {std::string("VK_DBG_LAYER_ACTION_DEBUG_OUTPUT"), VK_DBG_LAYER_ACTION_DEBUG_OUTPUT}, -#endif - {std::string("VK_DBG_LAYER_ACTION_DEFAULT"), VK_DBG_LAYER_ACTION_DEFAULT}}; - -const std::unordered_map report_flags_option_definitions = { - {std::string("warn"), VK_DEBUG_REPORT_WARNING_BIT_EXT}, - {std::string("info"), VK_DEBUG_REPORT_INFORMATION_BIT_EXT}, - {std::string("perf"), VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT}, - {std::string("error"), VK_DEBUG_REPORT_ERROR_BIT_EXT}, - {std::string("debug"), VK_DEBUG_REPORT_DEBUG_BIT_EXT}}; - -const std::unordered_map log_msg_type_option_definitions = {{std::string("warn"), kWarningBit}, - {std::string("info"), kInformationBit}, - {std::string("perf"), kPerformanceWarningBit}, - {std::string("error"), kErrorBit}, - {std::string("debug"), kDebugBit}}; - -const char *GetLayerOption(const char *option); -void SetLayerOption(const char *option, const char *val); - -// Get an environment variable, returns "" if the variable is unset. -std::string GetEnvironment(const char *name); - -// Set an environment variable, if it is not already set -bool SetEnvironment(const char *name, const char *value); - -const SettingsFileInfo *GetLayerSettingsFileInfo(); - -FILE *GetLayerLogOutput(const char *option, const char *layer_name); -VkFlags GetLayerOptionFlags(std::string option, std::unordered_map const &enum_data, uint32_t option_default); - -void PrintMessageFlags(VkFlags vk_flags, char *msg_flags); -void PrintMessageSeverity(VkFlags vk_flags, char *msg_flags); -void PrintMessageType(VkFlags vk_flags, char *msg_flags);