From ab86d4bb937d6ee4916d2e6aa94fa0cf5ad12054 Mon Sep 17 00:00:00 2001 From: Christophe Date: Wed, 13 Sep 2023 16:30:36 +0200 Subject: [PATCH] layer: Add features to list unknown settings --- include/vulkan/layer/vk_layer_settings.h | 5 ++ src/layer/vk_layer_settings.cpp | 38 ++++++++ tests/layer/test_setting_util.cpp | 106 +++++++++++++++++++++++ 3 files changed, 149 insertions(+) diff --git a/include/vulkan/layer/vk_layer_settings.h b/include/vulkan/layer/vk_layer_settings.h index 9cc1642..a3efb10 100644 --- a/include/vulkan/layer/vk_layer_settings.h +++ b/include/vulkan/layer/vk_layer_settings.h @@ -60,8 +60,13 @@ VkBool32 vlHasLayerSetting(VlLayerSettingSet layerSettingSet, const char *pSetti VkResult vlGetLayerSettingValues(VlLayerSettingSet layerSettingSet, const char *pSettingName, VlLayerSettingType type, uint32_t *pValueCount, void *pValues); +// Find the VkLayerSettingsCreateInfoEXT in the VkInstanceCreateInfo pNext chain, return NULL if not present const VkLayerSettingsCreateInfoEXT *vlFindLayerSettingsCreateInfo(const VkInstanceCreateInfo *pCreateInfo); +// Return the list of Unknown setting in VkLayerSettingsCreateInfoEXT +VkResult vlGetUnknownSettings(const VkLayerSettingsCreateInfoEXT *pCreateInfo, uint32_t settingsCount, const char **pSettings, + uint32_t *pUnknownSettingCount, const char **pUnknownSettings); + #ifdef __cplusplus } #endif diff --git a/src/layer/vk_layer_settings.cpp b/src/layer/vk_layer_settings.cpp index b5576b6..ce2ff02 100644 --- a/src/layer/vk_layer_settings.cpp +++ b/src/layer/vk_layer_settings.cpp @@ -627,3 +627,41 @@ const VkLayerSettingsCreateInfoEXT *vlFindLayerSettingsCreateInfo(const VkInstan } return found; } + +static bool vlHasSetting(uint32_t settingsCount, const char **pSettings, const char* searchedSettings) { + for (uint32_t setting_index = 0; setting_index < settingsCount; ++setting_index) { + if (std::strcmp(pSettings[setting_index], searchedSettings) == 0) { + return true; + } + } + + return false; +} + +VkResult vlGetUnknownSettings(const VkLayerSettingsCreateInfoEXT* pCreateInfo, uint32_t settingsCount, const char** pSettings, + uint32_t* pUnknownSettingCount, const char** pUnknownSettings) { + assert(pUnknownSettingCount != nullptr); + + uint32_t current_unknown_setting_count = 0; + for (uint32_t info_index = 0, info_count = pCreateInfo->settingCount; info_index < info_count; ++info_index) { + const char* current_setting_name = pCreateInfo->pSettings[info_index].pSettingName; + if (!vlHasSetting(settingsCount, pSettings, current_setting_name)) { + if (pUnknownSettings != nullptr && current_unknown_setting_count < *pUnknownSettingCount) { + pUnknownSettings[current_unknown_setting_count] = current_setting_name; + } + + ++current_unknown_setting_count; + } + } + + if (pUnknownSettings == nullptr) { + *pUnknownSettingCount = current_unknown_setting_count; + return VK_SUCCESS; + } else if (current_unknown_setting_count > *pUnknownSettingCount) { + return VK_INCOMPLETE; + } else { + return VK_SUCCESS; + } + + return VK_SUCCESS; +} diff --git a/tests/layer/test_setting_util.cpp b/tests/layer/test_setting_util.cpp index d18991a..2c07182 100644 --- a/tests/layer/test_setting_util.cpp +++ b/tests/layer/test_setting_util.cpp @@ -569,3 +569,109 @@ TEST(test_layer_settings_util, to_framesets) { EXPECT_EQ(1, framesets[3].step); } } + +TEST(test_layer_settings_util, vlGetUnknownSettings) { + std::vector settings; + + VkBool32 value_bool = VK_TRUE; + VkLayerSettingEXT setting_bool_value{}; + setting_bool_value.pLayerName = "VK_LAYER_LUNARG_test"; + setting_bool_value.pSettingName = "bool_value"; + setting_bool_value.type = VK_LAYER_SETTING_TYPE_BOOL32_EXT; + setting_bool_value.pValues = &value_bool; + setting_bool_value.count = 1; + settings.push_back(setting_bool_value); + + std::int32_t value_int32 = 76; + VkLayerSettingEXT setting_int32_value{}; + setting_int32_value.pLayerName = "VK_LAYER_LUNARG_test"; + setting_int32_value.pSettingName = "int32_value"; + setting_int32_value.type = VK_LAYER_SETTING_TYPE_INT32_EXT; + setting_int32_value.pValues = &value_int32; + setting_int32_value.count = 1; + settings.push_back(setting_int32_value); + + std::int64_t value_int64 = static_cast(1) << static_cast(40); + VkLayerSettingEXT setting_int64_value{}; + setting_int64_value.pLayerName = "VK_LAYER_LUNARG_test"; + setting_int64_value.pSettingName = "int64_value"; + setting_int64_value.type = VK_LAYER_SETTING_TYPE_INT64_EXT; + setting_int64_value.pValues = &value_int64; + setting_int64_value.count = 1; + settings.push_back(setting_int64_value); + + std::uint32_t value_uint32 = 76u; + VkLayerSettingEXT setting_uint32_value{}; + setting_uint32_value.pLayerName = "VK_LAYER_LUNARG_test"; + setting_uint32_value.pSettingName = "uint32_value"; + setting_uint32_value.type = VK_LAYER_SETTING_TYPE_UINT32_EXT; + setting_uint32_value.pValues = &value_uint32; + setting_uint32_value.count = 1; + settings.push_back(setting_uint32_value); + + std::uint64_t value_uint64 = static_cast(1) << static_cast(40); + VkLayerSettingEXT setting_uint64_value{}; + setting_uint64_value.pLayerName = "VK_LAYER_LUNARG_test"; + setting_uint64_value.pSettingName = "uint64_value"; + setting_uint64_value.type = VK_LAYER_SETTING_TYPE_UINT64_EXT; + setting_uint64_value.pValues = &value_uint64; + setting_uint64_value.count = 1; + settings.push_back(setting_uint64_value); + + float value_float = 76.1f; + VkLayerSettingEXT setting_float_value{}; + setting_float_value.pLayerName = "VK_LAYER_LUNARG_test"; + setting_float_value.pSettingName = "float_value"; + setting_float_value.type = VK_LAYER_SETTING_TYPE_FLOAT32_EXT; + setting_float_value.pValues = &value_float; + setting_float_value.count = 1; + settings.push_back(setting_float_value); + + double value_double = 76.1; + VkLayerSettingEXT setting_double_value{}; + setting_double_value.pLayerName = "VK_LAYER_LUNARG_test"; + setting_double_value.pSettingName = "double_value"; + setting_double_value.type = VK_LAYER_SETTING_TYPE_FLOAT64_EXT; + setting_double_value.pValues = &value_double; + setting_double_value.count = 1; + settings.push_back(setting_double_value); + + VlFrameset value_frameset{76, 100, 10}; + VkLayerSettingEXT setting_frameset_value{}; + setting_frameset_value.pLayerName = "VK_LAYER_LUNARG_test"; + setting_frameset_value.pSettingName = "frameset_value"; + setting_frameset_value.type = VK_LAYER_SETTING_TYPE_UINT32_EXT; + setting_frameset_value.pValues = &value_frameset; + setting_frameset_value.count = sizeof(VlFrameset) / sizeof(VlFrameset::count); + settings.push_back(setting_frameset_value); + + VkLayerSettingsCreateInfoEXT layer_settings_create_info; + layer_settings_create_info.sType = VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT; + layer_settings_create_info.pNext = nullptr; + layer_settings_create_info.settingCount = static_cast(settings.size()); + layer_settings_create_info.pSettings = &settings[0]; + + const char* setting_names[] = { + "int32_value", "int64_value", "uint32_value", "uint64_value", "float_value", "double_value" + }; + + uint32_t unknownSettingsCount = 0; + vlGetUnknownSettings(&layer_settings_create_info, static_cast(std::size(setting_names)), setting_names, + &unknownSettingsCount, nullptr); + EXPECT_EQ(2, unknownSettingsCount); + + std::vector unknownSettings(unknownSettingsCount); + + unknownSettingsCount = 1; + vlGetUnknownSettings(&layer_settings_create_info, static_cast(std::size(setting_names)), setting_names, + &unknownSettingsCount, &unknownSettings[0]); + EXPECT_EQ(1, unknownSettingsCount); + EXPECT_STREQ("bool_value", unknownSettings[0]); + + unknownSettingsCount = 2; + vlGetUnknownSettings(&layer_settings_create_info, static_cast(std::size(setting_names)), setting_names, + &unknownSettingsCount, &unknownSettings[0]); + + EXPECT_STREQ("bool_value", unknownSettings[0]); + EXPECT_STREQ("frameset_value", unknownSettings[1]); +}