diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ae4b867fe..4c344b37e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,8 +120,6 @@ if(BUILD_VIA) add_subdirectory(via) endif() -add_subdirectory(vku) - if(BUILD_APIDUMP OR BUILD_MONITOR OR BUILD_SCREENSHOT) add_subdirectory(layersvt) endif() diff --git a/layersvt/CMakeLists.txt b/layersvt/CMakeLists.txt index 45d5a1dc29..d2c1605e85 100644 --- a/layersvt/CMakeLists.txt +++ b/layersvt/CMakeLists.txt @@ -157,17 +157,17 @@ if(BUILD_APIDUMP) run_vulkantools_video_xml_generate(api_dump_generator.py api_dump_video_html.h) run_vulkantools_video_xml_generate(api_dump_generator.py api_dump_video_json.h) - add_vk_layer(api_dump api_dump.cpp vk_layer_table.cpp ../vku/vk_layer_settings.cpp ../vku/vk_layer_settings.h) + add_vk_layer(api_dump api_dump.cpp vk_layer_table.cpp) add_dependencies(VkLayer_api_dump generate_api_cpp generate_api_text_h generate_api_html_h generate_api_json_h generate_api_video_text_h generate_api_video_html_h generate_api_video_json_h) endif () if (NOT APPLE) if(BUILD_MONITOR) - add_vk_layer(monitor monitor.cpp vk_layer_table.cpp ../vku/vk_layer_settings.cpp ../vku/vk_layer_settings.h) + add_vk_layer(monitor monitor.cpp vk_layer_table.cpp) endif () if(BUILD_SCREENSHOT) - add_vk_layer(screenshot screenshot.cpp screenshot_parsing.h screenshot_parsing.cpp vk_layer_table.cpp ../vku/vk_layer_settings.cpp ../vku/vk_layer_settings.h) + add_vk_layer(screenshot screenshot.cpp screenshot_parsing.h screenshot_parsing.cpp vk_layer_table.cpp) endif () endif () diff --git a/vkconfig/CMakeLists.txt b/vkconfig/CMakeLists.txt index 9bde6350ce..591d8e5679 100644 --- a/vkconfig/CMakeLists.txt +++ b/vkconfig/CMakeLists.txt @@ -22,24 +22,23 @@ else() set(FILES_ALL ${FILES_UI} ${FILES_SOURCE} ${FILES_HEADER} ${FILES_DOCS} resources.qrc) - add_definitions(-DQT_NO_DEBUG_OUTPUT) - add_definitions(-DQT_NO_WARNING_OUTPUT) - if(NOT APPLE) if (NOT DEFINED CMAKE_INSTALL_BINDIR) include(GNUInstallDirs) endif() if(WIN32) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_executable(vkconfig WIN32 ${FILES_ALL} ${CMAKE_CURRENT_SOURCE_DIR}/resourcefiles/vkconfig.rc) + target_compile_definitions(vkconfig PRIVATE _CRT_SECURE_NO_WARNINGS) + target_compile_options(vkconfig PRIVATE $<$:/MP>) target_link_libraries(vkconfig Cfgmgr32) else() add_executable(vkconfig ${FILES_ALL} ${FILES_UI}) endif() target_link_libraries(vkconfig Vulkan::Headers vkconfig_core Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network) - target_compile_definitions(vkconfig PRIVATE ${VKCONFIG_DEFINITIONS}) + target_compile_definitions(vkconfig PRIVATE QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT) + set_target_properties(vkconfig PROPERTIES FOLDER "vkconfig") install(TARGETS vkconfig DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/vkconfig_core/CMakeLists.txt b/vkconfig_core/CMakeLists.txt index 9a5d5cf65b..d82338fe67 100644 --- a/vkconfig_core/CMakeLists.txt +++ b/vkconfig_core/CMakeLists.txt @@ -47,15 +47,16 @@ if(Qt5_FOUND) set(FILES_ALL ${FILES_SOURCE} ${FILES_HEADER} ${FILES_RESOURCES}) add_library(vkconfig_core STATIC ${FILES_ALL}) + target_compile_options(vkconfig_core PRIVATE $<$:/MP>) target_compile_definitions(vkconfig_core PRIVATE QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT) + set_target_properties(vkconfig_core PROPERTIES FOLDER "vkconfig") if(WIN32) target_compile_definitions(vkconfig_core PRIVATE _CRT_SECURE_NO_WARNINGS) target_link_libraries(vkconfig_core Cfgmgr32) endif() - target_link_libraries(vkconfig_core Vulkan::Headers Vulkan::LayerSettings vku valijson Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network) - target_compile_definitions(vkconfig_core PRIVATE ${VKCONFIG_DEFINITIONS}) + target_link_libraries(vkconfig_core Vulkan::Headers valijson Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Network) add_subdirectory(test) endif() diff --git a/vkconfig_core/test/CMakeLists.txt b/vkconfig_core/test/CMakeLists.txt index fbfe028be6..ca9a7c0000 100644 --- a/vkconfig_core/test/CMakeLists.txt +++ b/vkconfig_core/test/CMakeLists.txt @@ -13,7 +13,9 @@ function(vkConfigTest NAME) source_group("Test Files" FILES ${FILES_JSON} ${FILES_TEXT}) add_executable(${TEST_NAME} ${TEST_FILE} ${FILES_JSON} ${FILES_TEXT} resources.qrc) + set_target_properties(${TEST_NAME} PROPERTIES FOLDER "vkconfig/tests") target_link_libraries(${TEST_NAME} vkconfig_core + Vulkan::LayerSettings GTest::gtest GTest::gtest_main Qt5::Core diff --git a/vkconfig_core/test/test_override.cpp b/vkconfig_core/test/test_override.cpp index 404c94cf28..4eaa6c719c 100644 --- a/vkconfig_core/test/test_override.cpp +++ b/vkconfig_core/test/test_override.cpp @@ -22,7 +22,7 @@ #include "../environment.h" #include "../layer.h" #include "../layer_manager.h" -#include "../../vku/vk_layer_settings.h" +#include #include @@ -115,87 +115,141 @@ TEST(test_override, vk_layer_settings_txt) { EXPECT_EQ(true, OverrideConfiguration(env, layer_manager.available_layers, configuration)); - EXPECT_EQ(false, vku::IsLayerSetting(LAYER, "not_found")); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "toogle")); - EXPECT_EQ(true, vku::GetLayerSettingBool(LAYER, "toogle")); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "enum_required_only")); - EXPECT_STREQ("value2", vku::GetLayerSettingString(LAYER, "enum_required_only").c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "enum_with_optional")); - EXPECT_STREQ("value1", vku::GetLayerSettingString(LAYER, "enum_with_optional").c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "flags_required_only")); - std::vector flags_required_only = vku::GetLayerSettingStrings(LAYER, "flags_required_only"); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "flags_with_optional")); - std::vector flags_with_optional = vku::GetLayerSettingStrings(LAYER, "flags_with_optional"); - - EXPECT_STREQ("flag0", flags_required_only[0].c_str()); - EXPECT_STREQ("flag2", flags_required_only[1].c_str()); - EXPECT_STREQ("flag0", flags_with_optional[0].c_str()); - EXPECT_STREQ("flag2", flags_with_optional[1].c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "string_required_only")); - EXPECT_STREQ("My string", vku::GetLayerSettingString(LAYER, "string_required_only").c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "string_with_optional")); - EXPECT_STREQ("My string", vku::GetLayerSettingString(LAYER, "string_with_optional").c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "bool_required_only")); - EXPECT_EQ(true, vku::GetLayerSettingBool(LAYER, "bool_required_only")); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "bool_with_optional")); - EXPECT_EQ(true, vku::GetLayerSettingBool(LAYER, "bool_with_optional")); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "load_file_required_only")); - EXPECT_STREQ("./my_test.txt", vku::GetLayerSettingString(LAYER, "load_file_required_only").c_str()); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "load_file_with_optional")); - EXPECT_STREQ("./my_test.txt", vku::GetLayerSettingString(LAYER, "load_file_with_optional").c_str()); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "save_file_required_only")); - EXPECT_STREQ("./my_test.txt", vku::GetLayerSettingString(LAYER, "save_file_required_only").c_str()); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "save_file_with_optional")); - EXPECT_STREQ("./my_test.txt", vku::GetLayerSettingString(LAYER, "save_file_with_optional").c_str()); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "save_folder_required_only")); - EXPECT_STREQ("./my_test", vku::GetLayerSettingString(LAYER, "save_folder_required_only").c_str()); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "save_folder_with_optional")); - EXPECT_STREQ("./my_test", vku::GetLayerSettingString(LAYER, "save_folder_with_optional").c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "int_required_only")); - EXPECT_EQ(76, vku::GetLayerSettingInt(LAYER, "int_required_only")); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "int_with_optional")); - EXPECT_EQ(82, vku::GetLayerSettingInt(LAYER, "int_with_optional")); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "float_required_only")); - EXPECT_EQ(76.500000, vku::GetLayerSettingFloat(LAYER, "float_required_only")); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "float_with_optional")); - EXPECT_EQ(76.500000, vku::GetLayerSettingFloat(LAYER, "float_with_optional")); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "frames_required_only")); - EXPECT_STREQ("76-82,75", vku::GetLayerSettingFrames(LAYER, "frames_required_only").c_str()); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "frames_with_optional")); - EXPECT_STREQ("79-82,75", vku::GetLayerSettingFrames(LAYER, "frames_with_optional").c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "list_required_only")); - std::vector> list_required_only = vku::GetLayerSettingList(LAYER, "list_required_only"); - - EXPECT_EQ(76, list_required_only[0].second); - EXPECT_EQ(82, list_required_only[1].second); - EXPECT_STREQ("stringB", list_required_only[2].first.c_str()); - EXPECT_STREQ("stringD", list_required_only[3].first.c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "list_with_optional")); - std::vector> list_with_optional = vku::GetLayerSettingList(LAYER, "list_with_optional"); - - EXPECT_EQ(76, list_with_optional[0].second); - EXPECT_STREQ("stringA", list_with_optional[1].first.c_str()); - - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "list_empty")); - std::vector> list_empty = vku::GetLayerSettingList(LAYER, "list_empty"); - EXPECT_EQ(true, list_empty.empty()); + VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE; + vlCreateLayerSettingSet(LAYER, nullptr, nullptr, nullptr, &layerSettingSet); + + EXPECT_EQ(false, vlHasLayerSetting(layerSettingSet, "not_found")); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "toogle")); + bool setting_toogle = false; + vlGetLayerSettingValue(layerSettingSet, "toogle", setting_toogle); + EXPECT_EQ(true, setting_toogle); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "enum_required_only")); + std::string setting_enum_required_only; + vlGetLayerSettingValue(layerSettingSet, "enum_required_only", setting_enum_required_only); + EXPECT_STREQ("value2", setting_enum_required_only.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "enum_with_optional")); + std::string setting_enum_with_optional; + vlGetLayerSettingValue(layerSettingSet, "enum_required_only", setting_enum_with_optional); + EXPECT_STREQ("value1", setting_enum_with_optional.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "flags_required_only")); + std::vector setting_flags_required_only; + vlGetLayerSettingValues(layerSettingSet, "flags_required_only", setting_flags_required_only); + EXPECT_STREQ("flag0", setting_flags_required_only[0].c_str()); + EXPECT_STREQ("flag2", setting_flags_required_only[1].c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "flags_with_optional")); + std::vector setting_flags_with_optional; + vlGetLayerSettingValues(layerSettingSet, "flags_with_optional", setting_flags_with_optional); + EXPECT_STREQ("flag0", setting_flags_with_optional[0].c_str()); + EXPECT_STREQ("flag2", setting_flags_with_optional[1].c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "string_required_only")); + std::string setting_string_required_only; + vlGetLayerSettingValue(layerSettingSet, "string_required_only", setting_string_required_only); + EXPECT_STREQ("My string", setting_string_required_only.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "string_with_optional")); + std::string setting_string_with_optional; + vlGetLayerSettingValue(layerSettingSet, "string_required_only", setting_string_with_optional); + EXPECT_STREQ("My string", setting_string_with_optional.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "bool_required_only")); + bool setting_bool_required_only = false; + vlGetLayerSettingValue(layerSettingSet, "bool_required_only", setting_bool_required_only); + EXPECT_EQ(true, setting_bool_required_only); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "bool_with_optional")); + bool setting_bool_with_optional = false; + vlGetLayerSettingValue(layerSettingSet, "bool_with_optional", setting_bool_with_optional); + EXPECT_EQ(true, setting_bool_with_optional); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "load_file_required_only")); + std::string setting_load_file_required_only; + vlGetLayerSettingValue(layerSettingSet, "load_file_required_only", setting_load_file_required_only); + EXPECT_STREQ("./my_test.txt", setting_load_file_required_only.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "load_file_with_optional")); + std::string setting_load_file_with_optional; + vlGetLayerSettingValue(layerSettingSet, "load_file_with_optional", setting_load_file_with_optional); + EXPECT_STREQ("./my_test.txt", setting_load_file_with_optional.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "save_file_required_only")); + std::string setting_save_file_required_only; + vlGetLayerSettingValue(layerSettingSet, "load_file_with_optional", setting_save_file_required_only); + EXPECT_STREQ("./my_test.txt", setting_save_file_required_only.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "save_file_with_optional")); + std::string setting_save_file_with_optional; + vlGetLayerSettingValue(layerSettingSet, "load_file_with_optional", setting_save_file_with_optional); + EXPECT_STREQ("./my_test.txt", setting_save_file_with_optional.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "save_folder_required_only")); + std::string setting_save_folder_required_only; + vlGetLayerSettingValue(layerSettingSet, "load_file_with_optional", setting_save_folder_required_only); + EXPECT_STREQ("./my_test", setting_save_folder_required_only.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "save_folder_with_optional")); + std::string setting_save_folder_with_optional; + vlGetLayerSettingValue(layerSettingSet, "save_folder_with_optional", setting_save_folder_with_optional); + EXPECT_STREQ("./my_test", setting_save_folder_with_optional.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "int_required_only")); + int setting_int_required_only = 0; + vlGetLayerSettingValue(layerSettingSet, "int_required_only", setting_int_required_only); + EXPECT_EQ(76, setting_int_required_only); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "int_with_optional")); + int setting_int_with_optional = 0; + vlGetLayerSettingValue(layerSettingSet, "int_with_optional", setting_int_with_optional); + EXPECT_EQ(82, setting_int_with_optional); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "float_required_only")); + float setting_float_required_only = 0.0f; + vlGetLayerSettingValue(layerSettingSet, "float_required_only", setting_float_required_only); + EXPECT_EQ(76.500000, setting_float_required_only); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "float_with_optional")); + float setting_float_with_optional = 0.0f; + vlGetLayerSettingValue(layerSettingSet, "float_required_only", setting_float_with_optional); + EXPECT_EQ(76.500000, setting_float_with_optional); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "frames_required_only")); + std::string setting_frames_required_only; + vlGetLayerSettingValue(layerSettingSet, "float_required_only", setting_frames_required_only); + EXPECT_STREQ("76-82,75", setting_frames_required_only.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "frames_with_optional")); + std::string setting_frames_with_optional; + vlGetLayerSettingValue(layerSettingSet, "float_required_only", setting_frames_with_optional); + EXPECT_STREQ("79-82,75", setting_frames_with_optional.c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "list_required_only")); + std::vector setting_list_required_only; + vlGetLayerSettingValues(layerSettingSet, "list_required_only", setting_list_required_only); + EXPECT_STREQ("76", setting_list_required_only[0].c_str()); + EXPECT_STREQ("82", setting_list_required_only[1].c_str()); + EXPECT_STREQ("stringB", setting_list_required_only[2].c_str()); + EXPECT_STREQ("stringD", setting_list_required_only[3].c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "list_with_optional")); + std::vector setting_list_with_optional; + vlGetLayerSettingValues(layerSettingSet, "list_with_optional", setting_list_with_optional); + EXPECT_STREQ("76", setting_list_with_optional[0].c_str()); + EXPECT_STREQ("stringA", setting_list_with_optional[1].c_str()); + + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "list_empty")); + std::vector setting_list_empty; + vlGetLayerSettingValues(layerSettingSet, "list_empty", setting_list_empty); + EXPECT_EQ(true, setting_list_empty.empty()); EXPECT_EQ(true, SurrenderConfiguration(env)); + vlDestroyLayerSettingSet(layerSettingSet, nullptr); + env.Reset(Environment::SYSTEM); // Don't change the system settings on exit } @@ -218,21 +272,32 @@ TEST(test_override, env_var) { EXPECT_EQ(true, OverrideConfiguration(env, layer_manager.available_layers, configuration)); - EXPECT_EQ(false, vku::IsLayerSetting(LAYER, "env_o")); + VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE; + vlCreateLayerSettingSet(LAYER, nullptr, nullptr, nullptr, &layerSettingSet); + + EXPECT_EQ(false, vlHasLayerSetting(layerSettingSet, "env_o")); qputenv("VK_LUNARG_REFERENCE_1_2_1_ENV_A", "pouet"); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "env_a")); - EXPECT_STREQ("pouet", vku::GetLayerSettingString(LAYER, "env_a").c_str()); + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "env_a")); + std::string setting_env_a; + vlGetLayerSettingValue(layerSettingSet, "env_a", setting_env_a); + EXPECT_STREQ("pouet", setting_env_a.c_str()); // Check support of environment variable without vendor namespace qputenv("VK_REFERENCE_1_2_1_ENV_B", "pouet"); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "env_b")); - EXPECT_STREQ("pouet", vku::GetLayerSettingString(LAYER, "env_b").c_str()); + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "env_b")); + std::string setting_env_b; + vlGetLayerSettingValue(layerSettingSet, "env_b", setting_env_b); + EXPECT_STREQ("pouet", setting_env_b.c_str()); // Check support of environment variable without full namespace qputenv("VK_ENV_C", "pouet"); - EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "env_c")); - EXPECT_STREQ("pouet", vku::GetLayerSettingString(LAYER, "env_c").c_str()); + EXPECT_EQ(true, vlHasLayerSetting(layerSettingSet, "env_c")); + std::string setting_env_c; + vlGetLayerSettingValue(layerSettingSet, "env_c", setting_env_c); + EXPECT_STREQ("pouet", setting_env_c.c_str()); + + vlDestroyLayerSettingSet(layerSettingSet, nullptr); EXPECT_EQ(true, SurrenderConfiguration(env)); diff --git a/vku/CMakeLists.txt b/vku/CMakeLists.txt deleted file mode 100644 index 5693e6f4dd..0000000000 --- a/vku/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (c) 2021-2021 Valve Corporation -# Copyright (c) 2021-2021 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. -# - -file(GLOB FILES_SOURCE ./*.cpp) -file(GLOB FILES_HEADER ./*.h) - -add_library(vku STATIC ${FILES_SOURCE} ${FILES_HEADER}) - -target_link_libraries(vku PRIVATE Vulkan::Headers) - -if(WIN32) - target_compile_definitions(vku PUBLIC _CRT_SECURE_NO_WARNINGS) -else() - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -endif() - -set_target_properties(vku PROPERTIES LINKER_LANGUAGE CXX) -include_directories(${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/generated) diff --git a/vku/vk_layer_settings.cpp b/vku/vk_layer_settings.cpp deleted file mode 100644 index 6dca9b84ca..0000000000 --- a/vku/vk_layer_settings.cpp +++ /dev/null @@ -1,630 +0,0 @@ -/* - * Copyright (c) 2015-2021 The Khronos Group Inc. - * Copyright (c) 2015-2021 Valve Corporation - * Copyright (c) 2015-2021 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 - * - Mark Lobodzinski - * - Jon Ashburn - * - Courtney Goeltzenleuchter - * - Tobin Ehlis - */ - -#include "vk_layer_settings.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(_WIN32) -#include -#include -#define GetCurrentDir _getcwd -#else -#include -#define GetCurrentDir getcwd -#endif - -namespace vku { - -static std::string format(const char *message, ...) { - std::size_t const STRING_BUFFER(4096); - - assert(message != nullptr); - assert(strlen(message) >= 0 && strlen(message) < STRING_BUFFER); - - char buffer[STRING_BUFFER]; - va_list list; - - va_start(list, message); - vsprintf(buffer, message, list); - va_end(list); - - return buffer; -} - -static bool IsFrames(const std::string &s) { - static const std::regex FRAME_REGEX("^([0-9]+([-][0-9]+){0,2})(,([0-9]+([-][0-9]+){0,2}))*$"); - - return std::regex_search(s, FRAME_REGEX); -} - -static bool IsNumber(const std::string &s) { - static const std::regex FRAME_REGEX("^-?[0-9]*$"); - - return std::regex_search(s, FRAME_REGEX); -} - -static bool IsFloat(const std::string &s) { - static const std::regex FRAME_REGEX("^-?[0-9]*([.][0-9]*)?$"); - - return std::regex_search(s, FRAME_REGEX); -} - -enum Source { - SOURCE_VKCONFIG, - SOURCE_ENV_VAR, - SOURCE_LOCAL, -}; - -struct SettingsFileInfo { - SettingsFileInfo() : file_found(false), source(SOURCE_LOCAL) {} - - bool file_found; - std::string location; - Source source; -}; - -class LayerSettings { - public: - LayerSettings(); - ~LayerSettings(){}; - - void SetCallback(LAYER_SETTING_LOG_CALLBACK callback) { this->callback_ = callback; } - void Log(const std::string &setting_key, const std::string &message); - - bool Is(const std::string &setting_key); - const char *Get(const std::string &setting_key); - void Set(const std::string &setting_key, const std::string &setting_value); - - std::string vk_layer_disables_env_var; - SettingsFileInfo settings_info; - - private: - bool file_is_parsed_; - std::map value_map_; - - std::string last_log_setting; - std::string last_log_message; - - std::string FindSettings(); - void ParseFile(const char *filename); - LAYER_SETTING_LOG_CALLBACK callback_; -}; - -static LayerSettings vk_layer_settings; - -static bool IsEnvironment(const char *variable) { -#if _WIN32 - return GetEnvironmentVariable(variable, NULL, 0) != 0; -#elif defined(__ANDROID__) - std::string command = "getprop " + std::string(variable); - FILE *pPipe = popen(command.c_str(), "r"); - if (pPipe != nullptr) { - pclose(pPipe); - - return true; - } else { - return false; - } -#else - return std::getenv(variable) != NULL; -#endif -} - -static std::string GetEnvironment(const char *variable) { -#if _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 - const char *output = std::getenv(variable); - return output == NULL ? "" : output; -#endif -} - -static std::string string_tolower(const std::string &s) { - std::string result = s; - for (auto &c : result) { - c = std::tolower(c); - } - return result; -} - -static std::string string_toupper(const std::string &s) { - std::string result = s; - for (auto &c : result) { - c = std::toupper(c); - } - return result; -} - -static std::string TrimPrefix(const std::string &layer_key) { - assert(layer_key.find("VK_LAYER_") == 0); - std::size_t prefix = std::strlen("VK_LAYER_"); - return layer_key.substr(prefix, layer_key.size() - prefix); -} - -static std::string GetSettingKey(const char *layer_key, const char *setting_key) { - std::stringstream result; - result << string_tolower(TrimPrefix(layer_key)) << "." << setting_key; - return result.str(); -} - -static inline std::string TrimVendor(const std::string &layer_key) { - static const char *separator = "_"; - - const std::string &namespace_key = TrimPrefix(layer_key); - - const auto trimmed_beg = namespace_key.find_first_of(separator); - if (trimmed_beg == std::string::npos) return namespace_key; - - assert(namespace_key.find_last_not_of(separator) != std::string::npos && - trimmed_beg <= namespace_key.find_last_not_of(separator)); - - return namespace_key.substr(trimmed_beg + 1, namespace_key.size()); -} - -enum TrimMode { - TRIM_NONE, - TRIM_VENDOR, - TRIM_NAMESPACE, - - TRIM_FIRST = TRIM_NONE, - TRIM_LAST = TRIM_NAMESPACE, -}; - -static std::string GetEnvVarKey(const char *layer_key, const char *setting_key, TrimMode trim_mode) { - std::stringstream result; - -#if defined(__ANDROID__) - switch (trim_mode) { - default: - case TRIM_NONE: { - result << "debug.vulkan." << GetSettingKey(layer_key, setting_key); - break; - } - case TRIM_VENDOR: { - result << "debug.vulkan." << GetSettingKey(TrimVendor(layer_key).c_str(), setting_key); - break; - } - case TRIM_NAMESPACE: { - result << "debug.vulkan." << setting_key; - break; - } - } -#else - switch (trim_mode) { - default: - case TRIM_NONE: { - result << "VK_" << string_toupper(TrimPrefix(layer_key)) << "_" << string_toupper(setting_key); - break; - } - case TRIM_VENDOR: { - result << "VK_" << string_toupper(TrimVendor(layer_key)) << "_" << string_toupper(setting_key); - break; - } - case TRIM_NAMESPACE: { - result << "VK_" << string_toupper(setting_key); - break; - } - } - -#endif - return result.str(); -} - -void InitLayerSettingsLogCallback(LAYER_SETTING_LOG_CALLBACK callback) { - vk_layer_settings.SetCallback(callback); - return; -} - -bool IsLayerSetting(const char *layer_key, const char *setting_key) { - assert(layer_key); - assert(!std::string(layer_key).empty()); - assert(setting_key); - assert(!std::string(setting_key).empty()); - - for (int i = TRIM_FIRST, n = TRIM_LAST; i <= n; ++i) { - if (IsEnvironment(GetEnvVarKey(layer_key, setting_key, static_cast(i)).c_str())) return true; - } - - return vk_layer_settings.Is(GetSettingKey(layer_key, setting_key).c_str()); -} - -static std::string GetLayerSettingData(const char *layer_key, const char *setting_key) { - // First search in the environment variables - for (int i = TRIM_FIRST, n = TRIM_LAST; i <= n; ++i) { - std::string setting = GetEnvironment(GetEnvVarKey(layer_key, setting_key, static_cast(i)).c_str()); - if (!setting.empty()) return setting; - } - - // Second search in vk_layer_settings.txt - return vk_layer_settings.Get(GetSettingKey(layer_key, setting_key).c_str()); -} - -bool GetLayerSettingBool(const char *layer_key, const char *setting_key) { - assert(IsLayerSetting(layer_key, setting_key)); - - bool result = false; // default value - - std::string setting = string_tolower(GetLayerSettingData(layer_key, setting_key)); - if (setting.empty()) { - vk_layer_settings.Log(setting_key, - "The setting is used but the value is empty which is invalid for a boolean setting type."); - } else if (IsNumber(setting)) { - result = std::atoi(setting.c_str()) != 0; - } else if (setting == "true" || setting == "false") { - result = setting == "true"; - } else { - std::string message = format("The data provided (%s) is not a boolean value.", setting.c_str()); - vk_layer_settings.Log(setting_key, message); - } - - return result; -} - -int GetLayerSettingInt(const char *layer_key, const char *setting_key) { - assert(IsLayerSetting(layer_key, setting_key)); - - int result = 0; // default value - - std::string setting = GetLayerSettingData(layer_key, setting_key); - if (setting.empty()) { - std::string message = "The setting is used but the value is empty which is invalid for a integer setting type."; - vk_layer_settings.Log(setting_key, message); - } else if (!IsNumber(setting)) { - std::string message = format("The data provided (%s) is not an integer value.", setting.c_str()); - vk_layer_settings.Log(setting_key, message); - } else { - result = std::atoi(setting.c_str()); - } - - return result; -} - -double GetLayerSettingFloat(const char *layer_key, const char *setting_key) { - assert(IsLayerSetting(layer_key, setting_key)); - - double result = 0.0; // default value - - std::string setting = GetLayerSettingData(layer_key, setting_key); - if (setting.empty()) { - std::string message = "The setting is used but the value is empty which is invalid for a floating-point setting type."; - vk_layer_settings.Log(setting_key, message); - } else if (!IsFloat(setting)) { - std::string message = format("The data provided (%s) is not a floating-point value.", setting.c_str()); - vk_layer_settings.Log(setting_key, message); - } else { - result = std::atof(setting.c_str()); - } - - return result; -} - -std::string GetLayerSettingString(const char *layer_key, const char *setting_key) { - assert(IsLayerSetting(layer_key, setting_key)); - - std::string setting = GetLayerSettingData(layer_key, setting_key); - if (setting.empty()) { - std::string message = "The setting is used but the value is empty which is invalid for a string setting type."; - vk_layer_settings.Log(setting_key, message); - } - - return setting; -} - -std::string GetLayerSettingFrames(const char *layer_key, const char *setting_key) { - assert(IsLayerSetting(layer_key, setting_key)); - - std::string setting = GetLayerSettingData(layer_key, setting_key); - if (!setting.empty() && !IsFrames(setting)) { - std::string message = format("The data provided (%s) is not a frames value.", setting.c_str()); - vk_layer_settings.Log(setting_key, message); - } - - return setting; -} - -static inline std::vector Split(const std::string &value, const std::string &delimiter) { - std::vector result; - - std::string parse = value; - - std::size_t start = 0; - std::size_t end = parse.find(delimiter); - while (end != std::string::npos) { - result.push_back(parse.substr(start, end - start)); - start = end + delimiter.length(); - end = parse.find(delimiter, start); - } - - const std::string last = parse.substr(start, end); - if (!last.empty()) { - result.push_back(last); - } - - return result; -} - -Strings GetLayerSettingStrings(const char *layer_key, const char *setting_key) { - assert(IsLayerSetting(layer_key, setting_key)); - - std::string setting = GetLayerSettingData(layer_key, setting_key); - if (setting.find_first_of(",") != std::string::npos) { - return Split(setting, ","); - } else { -#ifdef _WIN32 - const char *delimiter = ";"; -#else - const char *delimiter = ":"; -#endif - return Split(setting, delimiter); - } -} - -List GetLayerSettingList(const char *layer_key, const char *setting_key) { - assert(IsLayerSetting(layer_key, setting_key)); - - std::vector inputs = GetLayerSettingStrings(layer_key, setting_key); - - List result; - for (std::size_t i = 0, n = inputs.size(); i < n; ++i) { - std::pair value; - if (IsNumber(inputs[i])) { - value.second = atoi(inputs[i].c_str()); - } else { - value.first = inputs[i]; - } - result.push_back(value); - } - return result; -} - -// 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. -LayerSettings::LayerSettings() : file_is_parsed_(false), callback_(nullptr) {} - -void LayerSettings::Log(const std::string &setting_key, const std::string &message) { - this->last_log_setting = setting_key; - this->last_log_message = message; - - if (this->callback_ == nullptr) { - fprintf(stderr, "LAYER SETTING (%s) error: %s\n", this->last_log_setting.c_str(), this->last_log_message.c_str()); - } else { - this->callback_(this->last_log_setting.c_str(), this->last_log_message.c_str()); - } -} - -bool LayerSettings::Is(const std::string &setting_key) { - std::map::const_iterator it; - if (!file_is_parsed_) { - std::string settings_file = FindSettings(); - ParseFile(settings_file.c_str()); - } - - return value_map_.find(setting_key) != value_map_.end(); -} - -const char *LayerSettings::Get(const std::string &setting_key) { - std::map::const_iterator it; - if (!file_is_parsed_) { - std::string settings_file = FindSettings(); - ParseFile(settings_file.c_str()); - } - - if ((it = value_map_.find(setting_key)) == value_map_.end()) { - return ""; - } else { - return it->second.c_str(); - } -} - -void LayerSettings::Set(const std::string &setting_key, const std::string &value) { - if (!file_is_parsed_) { - std::string settings_file = FindSettings(); - ParseFile(settings_file.c_str()); - } - - value_map_[setting_key] = value; -} - -#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 LayerSettings::FindSettings() { - struct stat info; - -#if defined(WIN32) - // Look for VkConfig-specific settings location specified in the windows registry - HKEY key; - - const std::array hives = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER}; - 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 = SOURCE_VKCONFIG; - 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 = SOURCE_VKCONFIG; - 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 = SOURCE_ENV_VAR; - settings_info.location = env_path; - return env_path; - } - - // Default -- use the current working directory for the settings file location - settings_info.source = SOURCE_LOCAL; - 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"; -} - -static inline std::string TrimWhitespace(const std::string &s) { - const char *whitespace = " \t\f\v\n\r"; - - const auto trimmed_beg = s.find_first_not_of(whitespace); - if (trimmed_beg == std::string::npos) return ""; - - const auto trimmed_end = s.find_last_not_of(whitespace); - assert(trimmed_end != std::string::npos && trimmed_beg <= trimmed_end); - - return s.substr(trimmed_beg, trimmed_end - trimmed_beg + 1); -} - -void LayerSettings::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 setting_key = TrimWhitespace(line.substr(0, value_pos)); - const std::string setting_value = TrimWhitespace(line.substr(value_pos + 1)); - value_map_[setting_key] = setting_value; - } - } - } -} - -} // namespace vku diff --git a/vku/vk_layer_settings.h b/vku/vk_layer_settings.h deleted file mode 100644 index aa2890d24f..0000000000 --- a/vku/vk_layer_settings.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2015-2021 The Khronos Group Inc. - * Copyright (c) 2015-2021 Valve Corporation - * Copyright (c) 2015-2021 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 - */ - -#pragma once - -#include -#include - -#include -#include - -namespace vku { - -typedef std::vector Strings; -typedef std::vector> List; -typedef void *(*LAYER_SETTING_LOG_CALLBACK)(const char *setting_key, const char *message); - -// Initialize the callback function to get error messages. By default the error messages are outputed to stderr. Use nullptr to -// return to the default behavior. -void InitLayerSettingsLogCallback(LAYER_SETTING_LOG_CALLBACK callback); - -// Check whether a setting was set either from vk_layer_settings.txt or an environment variable -bool IsLayerSetting(const char *layer_key, const char *setting_key); - -// Query setting data for BOOL setting type in the layer manifest -bool GetLayerSettingBool(const char *layer_key, const char *setting_key); - -// Query setting data for INT setting type in the layer manifest -int GetLayerSettingInt(const char *layer_key, const char *setting_key); - -// Query setting data for FLOAT setting type in the layer manifest -double GetLayerSettingFloat(const char *layer_key, const char *setting_key); - -// Query setting data for FRAMES setting type in the layer manifest -std::string GetLayerSettingFrames(const char *layer_key, const char *setting_key); - -// Query setting data for STRING, ENUM, LOAD_FILE, SAVE_FILE and SAVE_FOLDER setting types in the layer manifest -std::string GetLayerSettingString(const char *layer_key, const char *setting_key); - -// Query setting data for FLAGS setting type in the layer manifest -Strings GetLayerSettingStrings(const char *layer_key, const char *setting_key); - -// Query setting data for LIST setting type in the layer manifest -List GetLayerSettingList(const char *layer_key, const char *setting_key); -} // namespace vku