Skip to content

Commit

Permalink
vkconfig: Use layer settings library
Browse files Browse the repository at this point in the history
Change-Id: I1cc62183a72404f623bbf0991b53e4648191c54d
  • Loading branch information
christophe-lunarg committed Aug 31, 2023
1 parent a9de9e8 commit d567134
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 824 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions layersvt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()

Expand Down
9 changes: 4 additions & 5 deletions vkconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<CXX_COMPILER_ID:MSVC>:/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})

Expand Down
5 changes: 3 additions & 2 deletions vkconfig_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<CXX_COMPILER_ID:MSVC>:/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()
2 changes: 2 additions & 0 deletions vkconfig_core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
237 changes: 151 additions & 86 deletions vkconfig_core/test/test_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "../environment.h"
#include "../layer.h"
#include "../layer_manager.h"
#include "../../vku/vk_layer_settings.h"
#include <vulkan/layer/vk_layer_settings.hpp>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -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<std::string> flags_required_only = vku::GetLayerSettingStrings(LAYER, "flags_required_only");
EXPECT_EQ(true, vku::IsLayerSetting(LAYER, "flags_with_optional"));
std::vector<std::string> 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<std::pair<std::string, int>> 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<std::pair<std::string, int>> 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<std::pair<std::string, int>> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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<std::string> 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
}

Expand All @@ -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));

Expand Down
33 changes: 0 additions & 33 deletions vku/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit d567134

Please sign in to comment.