diff --git a/include/vulkan/layer/vk_layer_settings.h b/include/vulkan/layer/vk_layer_settings.h index cb0f64a..5c3e9d1 100644 --- a/include/vulkan/layer/vk_layer_settings.h +++ b/include/vulkan/layer/vk_layer_settings.h @@ -47,7 +47,7 @@ typedef struct VkuFrameset { typedef void(VKAPI_PTR *VkuLayerSettingLogCallback)(const char *pSettingName, const char *pMessage); // Create a layer setting set. If 'pCallback' is set to NULL, the messages are outputed to stderr. -VkResult vkuCreateLayerSettingSet(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pCreateInfo, +VkResult vkuCreateLayerSettingSet(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pFirstCreateInfo, const VkAllocationCallbacks *pAllocator, VkuLayerSettingLogCallback pCallback, VkuLayerSettingSet *pLayerSettingSet); @@ -66,8 +66,11 @@ VkResult vkuGetLayerSettingValues(VkuLayerSettingSet layerSettingSet, const char // Find the VkLayerSettingsCreateInfoEXT in the VkInstanceCreateInfo pNext chain, return NULL if not present const VkLayerSettingsCreateInfoEXT *vkuFindLayerSettingsCreateInfo(const VkInstanceCreateInfo *pCreateInfo); +// Find the VkLayerSettingsCreateInfoEXT in the VkLayerSettingsCreateInfoEXT pNext chain, return NULL if not present +const VkLayerSettingsCreateInfoEXT *vkuNextLayerSettingsCreateInfo(const VkLayerSettingsCreateInfoEXT *pCreateInfo); + // Return the list of Unknown setting in VkLayerSettingsCreateInfoEXT -VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT *pCreateInfo, uint32_t settingsCount, const char **pSettings, +VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT *pFirstCreateInfo, uint32_t settingsCount, const char **pSettings, uint32_t *pUnknownSettingCount, const char **pUnknownSettings); #ifdef __cplusplus diff --git a/include/vulkan/layer/vk_layer_settings.hpp b/include/vulkan/layer/vk_layer_settings.hpp index feade48..cfaa363 100644 --- a/include/vulkan/layer/vk_layer_settings.hpp +++ b/include/vulkan/layer/vk_layer_settings.hpp @@ -57,6 +57,7 @@ typedef std::pair VkuCustomSTypeInfo; void vkuGetLayerSettingValues(VkuLayerSettingSet layerSettingSet, const char *pSettingName, std::vector &settingValues); -// Return the list of Unknown setting in VkLayerSettingsCreateInfoEXT -VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT *pCreateInfo, uint32_t settingsCount, const char **pSettings, +// Return the list of Unknown setting in all VkLayerSettingsCreateInfoEXT +VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT *pFirstCreateInfo, uint32_t settingsCount, const char **pSettings, std::vector &unknownSettings); + diff --git a/src/layer/layer_settings_manager.cpp b/src/layer/layer_settings_manager.cpp index 57b8f4a..85d7581 100644 --- a/src/layer/layer_settings_manager.cpp +++ b/src/layer/layer_settings_manager.cpp @@ -100,10 +100,10 @@ static void AddWorkaroundLayerNames(std::vector &layer_names) { namespace vl { -LayerSettings::LayerSettings(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pCreateInfo, +LayerSettings::LayerSettings(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pFirstCreateInfo, const VkAllocationCallbacks *pAllocator, VkuLayerSettingLogCallback pCallback) : layer_name(pLayerName) - , create_info(pCreateInfo) + , first_create_info(pFirstCreateInfo) , pCallback(pCallback) { (void)pAllocator; assert(pLayerName != nullptr); @@ -217,23 +217,29 @@ std::filesystem::path LayerSettings::FindSettingsFile() { } const VkLayerSettingEXT *LayerSettings::FindLayerSettingValue(const char *pSettingName) { - if (this->create_info == nullptr) { + if (this->first_create_info == nullptr) { return nullptr; } const std::string setting_name(pSettingName); - for (std::size_t i = 0, n = this->create_info->settingCount; i < n; ++i) { - const VkLayerSettingEXT *setting = &this->create_info->pSettings[i]; - if (setting->pLayerName != this->layer_name) { - continue; - } + const VkLayerSettingsCreateInfoEXT *current_create_info = this->first_create_info; + + while (current_create_info != nullptr) { + for (std::size_t i = 0, n = current_create_info->settingCount; i < n; ++i) { + const VkLayerSettingEXT *setting = ¤t_create_info->pSettings[i]; + if (setting->pLayerName != this->layer_name) { + continue; + } + + if (setting->pSettingName != setting_name) { + continue; + } - if (setting->pSettingName != setting_name) { - continue; + return setting; } - return setting; + current_create_info = vkuNextLayerSettingsCreateInfo(current_create_info); } return nullptr; diff --git a/src/layer/layer_settings_manager.hpp b/src/layer/layer_settings_manager.hpp index 5a03f9e..efa5935 100644 --- a/src/layer/layer_settings_manager.hpp +++ b/src/layer/layer_settings_manager.hpp @@ -18,7 +18,7 @@ namespace vl { class LayerSettings { public: - LayerSettings(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pCreateInfo, + LayerSettings(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pFirstCreateInfo, const VkAllocationCallbacks *pAllocator, VkuLayerSettingLogCallback pCallback); ~LayerSettings(); @@ -56,7 +56,8 @@ namespace vl { std::string prefix; std::string layer_name; - const VkLayerSettingsCreateInfoEXT *create_info{nullptr}; + + const VkLayerSettingsCreateInfoEXT *first_create_info{nullptr}; VkuLayerSettingLogCallback pCallback{nullptr}; }; }// namespace vl diff --git a/src/layer/vk_layer_settings.cpp b/src/layer/vk_layer_settings.cpp index bfb6a6e..4cee3a5 100644 --- a/src/layer/vk_layer_settings.cpp +++ b/src/layer/vk_layer_settings.cpp @@ -30,12 +30,12 @@ void test_helper_SetLayerSetting(VkuLayerSettingSet layerSettingSet, const char layer_setting_set->SetFileSetting(pSettingName, pValue); } -VkResult vkuCreateLayerSettingSet(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pCreateInfo, +VkResult vkuCreateLayerSettingSet(const char *pLayerName, const VkLayerSettingsCreateInfoEXT *pFirstCreateInfo, const VkAllocationCallbacks *pAllocator, VkuLayerSettingLogCallback pCallback, VkuLayerSettingSet *pLayerSettingSet) { (void)pAllocator; - vl::LayerSettings* layer_setting_set = new vl::LayerSettings(pLayerName, pCreateInfo, pAllocator, pCallback); + vl::LayerSettings *layer_setting_set = new vl::LayerSettings(pLayerName, pFirstCreateInfo, pAllocator, pCallback); *pLayerSettingSet = (VkuLayerSettingSet)layer_setting_set; return VK_SUCCESS; @@ -634,7 +634,21 @@ const VkLayerSettingsCreateInfoEXT *vkuFindLayerSettingsCreateInfo(const VkInsta return found; } -static bool vlHasSetting(uint32_t settingsCount, const char **pSettings, const char* searchedSettings) { +const VkLayerSettingsCreateInfoEXT *vkuNextLayerSettingsCreateInfo(const VkLayerSettingsCreateInfoEXT *pCreateInfo) { + const VkBaseOutStructure *current = reinterpret_cast(pCreateInfo->pNext); + const VkLayerSettingsCreateInfoEXT *found = nullptr; + while (current) { + if (VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT == current->sType) { + found = reinterpret_cast(current); + current = nullptr; + } else { + current = current->pNext; + } + } + return found; +} + +static bool vkuHasSetting(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; @@ -648,11 +662,13 @@ VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT* pCreateInfo, uint32_t* pUnknownSettingCount, const char** pUnknownSettings) { assert(pUnknownSettingCount != nullptr); + const VkLayerSettingsCreateInfoEXT *current_create_info = pCreateInfo; + uint32_t current_unknown_setting_count = 0; - if (pCreateInfo != nullptr) { - 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)) { + while (current_create_info != nullptr) { + for (uint32_t info_index = 0, info_count = current_create_info->settingCount; info_index < info_count; ++info_index) { + const char *current_setting_name = current_create_info->pSettings[info_index].pSettingName; + if (!vkuHasSetting(settingsCount, pSettings, current_setting_name)) { if (pUnknownSettings != nullptr && current_unknown_setting_count < *pUnknownSettingCount) { pUnknownSettings[current_unknown_setting_count] = current_setting_name; } @@ -660,6 +676,8 @@ VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT* pCreateInfo, ++current_unknown_setting_count; } } + + current_create_info = vkuNextLayerSettingsCreateInfo(current_create_info); } if (pUnknownSettings == nullptr) { @@ -672,16 +690,3 @@ VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT* pCreateInfo, return VK_SUCCESS; } -VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT* pCreateInfo, uint32_t settingsCount, const char** pSettings, - std::vector& unknownSettings) { - uint32_t unknown_setting_count = 0; - VkResult result = vkuGetUnknownSettings(pCreateInfo, settingsCount, pSettings, &unknown_setting_count, nullptr); - - if (unknown_setting_count > 0) { - unknownSettings.resize(unknown_setting_count); - - result = vkuGetUnknownSettings(pCreateInfo, settingsCount, pSettings, &unknown_setting_count, &unknownSettings[0]); - } - - return result; -} diff --git a/src/layer/vk_layer_settings_helper.cpp b/src/layer/vk_layer_settings_helper.cpp index 4bbc72a..d24fe08 100644 --- a/src/layer/vk_layer_settings_helper.cpp +++ b/src/layer/vk_layer_settings_helper.cpp @@ -193,3 +193,17 @@ void vkuGetLayerSettingValues(VkuLayerSettingSet layerSettingSet, const char *pS SetCustomStypeInfo(values, settingValues); } } + +VkResult vkuGetUnknownSettings(const VkLayerSettingsCreateInfoEXT *pFirstCreateInfo, uint32_t settingsCount, const char **pSettings, + std::vector &unknownSettings) { + uint32_t unknown_setting_count = 0; + VkResult result = vkuGetUnknownSettings(pFirstCreateInfo, settingsCount, pSettings, &unknown_setting_count, nullptr); + + if (unknown_setting_count > 0) { + unknownSettings.resize(unknown_setting_count); + + result = vkuGetUnknownSettings(pFirstCreateInfo, settingsCount, pSettings, &unknown_setting_count, &unknownSettings[0]); + } + + return result; +} diff --git a/tests/layer/test_setting_api.cpp b/tests/layer/test_setting_api.cpp index 5b16a05..63ebfe0 100644 --- a/tests/layer/test_setting_api.cpp +++ b/tests/layer/test_setting_api.cpp @@ -20,7 +20,7 @@ TEST(test_layer_setting_api, vkuHasLayerSetting_NotFound) { vkuDestroyLayerSettingSet(layerSettingSet, nullptr); } -TEST(test_layer_setting_api, vkuHasLayerSetting_Found) { +TEST(test_layer_setting_api, vkuHasLayerSetting_Found_SingleCreateInfo) { std::int32_t pValues = 76; VkLayerSettingEXT my_setting; @@ -44,6 +44,55 @@ TEST(test_layer_setting_api, vkuHasLayerSetting_Found) { vkuDestroyLayerSettingSet(layerSettingSet, nullptr); } +TEST(test_layer_setting_api, vkuHasLayerSetting_Found_MultipleCreateInfo) { + const std::int32_t valueA = 76; + const std::int32_t valueC1 = 77; + + const VkLayerSettingEXT settingsA[] = { + {"VK_LAYER_LUNARG_test", "my_settingA", VK_LAYER_SETTING_TYPE_INT32_EXT, 1, &valueA}, + {"VK_LAYER_LUNARG_test", "my_settingC", VK_LAYER_SETTING_TYPE_INT32_EXT, 1, &valueC1} + }; + + const VkLayerSettingsCreateInfoEXT layer_settings_create_infoA{ + VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT, + nullptr, + static_cast(std::size(settingsA)), settingsA}; + + const std::int32_t valueB = 82; + const std::int32_t valueC2 = 83; // Override valueC1 value! + + const VkLayerSettingEXT settingsB[] = { + {"VK_LAYER_LUNARG_test", "my_settingB", VK_LAYER_SETTING_TYPE_INT32_EXT, 1, &valueB}, + {"VK_LAYER_LUNARG_test", "my_settingC", VK_LAYER_SETTING_TYPE_INT32_EXT, 1, &valueC2} + }; + + const VkLayerSettingsCreateInfoEXT layer_settings_create_infoB{ + VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT, + &layer_settings_create_infoA, + static_cast(std::size(settingsB)), settingsB}; + + VkuLayerSettingSet layerSettingSet = VK_NULL_HANDLE; + vkuCreateLayerSettingSet("VK_LAYER_LUNARG_test", &layer_settings_create_infoB, nullptr, nullptr, &layerSettingSet); + + EXPECT_TRUE(vkuHasLayerSetting(layerSettingSet, "my_settingA")); + EXPECT_TRUE(vkuHasLayerSetting(layerSettingSet, "my_settingB")); + EXPECT_TRUE(vkuHasLayerSetting(layerSettingSet, "my_settingC")); + + std::int32_t resulatA = 0; + std::int32_t resulatB = 0; + std::int32_t resulatC = 0; + + uint32_t value_count = 1; + vkuGetLayerSettingValues(layerSettingSet, "my_settingA", VKU_LAYER_SETTING_TYPE_INT32, &value_count, &resulatA); + EXPECT_EQ(76, resulatA); + vkuGetLayerSettingValues(layerSettingSet, "my_settingB", VKU_LAYER_SETTING_TYPE_INT32, &value_count, &resulatB); + EXPECT_EQ(82, resulatB); + vkuGetLayerSettingValues(layerSettingSet, "my_settingC", VKU_LAYER_SETTING_TYPE_INT32, &value_count, &resulatC); + EXPECT_EQ(83, resulatC); + + vkuDestroyLayerSettingSet(layerSettingSet, nullptr); +} + TEST(test_layer_setting_api, vkuHasLayerSetting) { // The expected application code side: std::vector settings; diff --git a/tests/layer/test_setting_util.cpp b/tests/layer/test_setting_util.cpp index 1de5e9b..b48e570 100644 --- a/tests/layer/test_setting_util.cpp +++ b/tests/layer/test_setting_util.cpp @@ -578,7 +578,8 @@ TEST(test_layer_settings_util, to_framesets) { } } -TEST(test_layer_settings_util, vkuGetUnknownSettings) { + +TEST(test_layer_settings_util, vkuGetUnknownSettings_SingleCreateInfo) { std::vector settings; VkBool32 value_bool = VK_TRUE; @@ -681,3 +682,116 @@ TEST(test_layer_settings_util, vkuGetUnknownSettings) { EXPECT_STREQ("bool_value", unknown_settings[0]); EXPECT_STREQ("frameset_value", unknown_settings[1]); } + +TEST(test_layer_settings_util, vlGetUnknownSettings_MultipleCreateInfo) { + std::vector settingsA; + + 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; + settingsA.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; + settingsA.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; + settingsA.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; + settingsA.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; + settingsA.push_back(setting_uint64_value); + + VkLayerSettingsCreateInfoEXT create_infoA; + create_infoA.sType = VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT; + create_infoA.pNext = nullptr; + create_infoA.settingCount = static_cast(settingsA.size()); + create_infoA.pSettings = &settingsA[0]; + + std::vector settingsB; + + 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; + settingsB.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; + settingsB.push_back(setting_double_value); + + VkuFrameset 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(VkuFrameset) / sizeof(VkuFrameset::count); + settingsB.push_back(setting_frameset_value); + + VkLayerSettingsCreateInfoEXT create_infoB; + create_infoB.sType = VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT; + create_infoB.pNext = nullptr; + create_infoB.settingCount = static_cast(settingsB.size()); + create_infoB.pSettings = &settingsB[0]; + + // Chain the VkLayerSettingsCreateInfoEXT + create_infoA.pNext = &create_infoB; + + const char* setting_names[] = {"int32_value", "int64_value", "uint32_value", "uint64_value", "float_value", "double_value"}; + const std::uint32_t setting_name_count = static_cast(std::size(setting_names)); + + uint32_t unknown_settings_count = 0; + vkuGetUnknownSettings(&create_infoA, setting_name_count, setting_names, &unknown_settings_count, nullptr); + EXPECT_EQ(2, unknown_settings_count); + + std::vector unknown_settings(unknown_settings_count); + + unknown_settings_count = 1; + vkuGetUnknownSettings(&create_infoA, setting_name_count, setting_names, &unknown_settings_count, &unknown_settings[0]); + EXPECT_EQ(1, unknown_settings_count); + EXPECT_STREQ("bool_value", unknown_settings[0]); + + unknown_settings_count = 2; + vkuGetUnknownSettings(&create_infoA, setting_name_count, setting_names, &unknown_settings_count, &unknown_settings[0]); + + EXPECT_STREQ("bool_value", unknown_settings[0]); + EXPECT_STREQ("frameset_value", unknown_settings[1]); +}