Skip to content

Commit

Permalink
layer: Add CPP version of GetUnknownSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Sep 14, 2023
1 parent dbeeb93 commit df882d0
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 20 deletions.
4 changes: 4 additions & 0 deletions include/vulkan/layer/vk_layer_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ typedef std::pair<uint32_t, uint32_t> VlCustomSTypeInfo;
void vlGetLayerSettingValues(VlLayerSettingSet layerSettingSet,
const char *pSettingName,
std::vector<VlCustomSTypeInfo> &settingValues);

// Return the list of Unknown setting in VkLayerSettingsCreateInfoEXT
VkResult vlGetUnknownSettings(const VkLayerSettingsCreateInfoEXT *pCreateInfo, uint32_t settingsCount, const char **pSettings,
std::vector<const char *>& unknownSettings);
14 changes: 14 additions & 0 deletions src/layer/vk_layer_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,17 @@ VkResult vlGetUnknownSettings(const VkLayerSettingsCreateInfoEXT* pCreateInfo, u

return VK_SUCCESS;
}

VkResult vlGetUnknownSettings(const VkLayerSettingsCreateInfoEXT* pCreateInfo, uint32_t settingsCount, const char** pSettings,
std::vector<const char*>& unknownSettings) {
uint32_t unknown_setting_count = 0;
VkResult result = vlGetUnknownSettings(pCreateInfo, settingsCount, pSettings, &unknown_setting_count, nullptr);

if (unknown_setting_count > 0) {
unknownSettings.resize(unknown_setting_count);

result = vlGetUnknownSettings(pCreateInfo, settingsCount, pSettings, &unknown_setting_count, &unknownSettings[0]);
}

return result;
}
92 changes: 92 additions & 0 deletions tests/layer/test_setting_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,95 @@ TEST(test_layer_setting_cpp, vlGetLayerSettingValues_VlCustomSTypeInfo) {

vlDestroyLayerSettingSet(layerSettingSet, nullptr);
}

TEST(test_layer_setting_cpp, vlGetUnknownSettings) {
std::vector<VkLayerSettingEXT> 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<int64_t>(1) << static_cast<int64_t>(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<uint64_t>(1) << static_cast<uint64_t>(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<uint32_t>(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"};
const std::uint32_t setting_name_count = static_cast<std::uint32_t>(std::size(setting_names));

std::vector<const char*> unknown_settings;
vlGetUnknownSettings(&layer_settings_create_info, setting_name_count, setting_names, unknown_settings);
EXPECT_EQ(2, unknown_settings.size());

EXPECT_STREQ("bool_value", unknown_settings[0]);
EXPECT_STREQ("frameset_value", unknown_settings[1]);
}
38 changes: 18 additions & 20 deletions tests/layer/test_setting_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,33 +645,31 @@ TEST(test_layer_settings_util, vlGetUnknownSettings) {
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<uint32_t>(settings.size());
layer_settings_create_info.pSettings = &settings[0];
VkLayerSettingsCreateInfoEXT create_info;
create_info.sType = VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT;
create_info.pNext = nullptr;
create_info.settingCount = static_cast<uint32_t>(settings.size());
create_info.pSettings = &settings[0];

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::uint32_t>(std::size(setting_names));

uint32_t unknownSettingsCount = 0;
vlGetUnknownSettings(&layer_settings_create_info, static_cast<std::uint32_t>(std::size(setting_names)), setting_names,
&unknownSettingsCount, nullptr);
EXPECT_EQ(2, unknownSettingsCount);
uint32_t unknown_settings_count = 0;
vlGetUnknownSettings(&create_info, setting_name_count, setting_names, &unknown_settings_count, nullptr);
EXPECT_EQ(2, unknown_settings_count);

std::vector<const char*> unknownSettings(unknownSettingsCount);
std::vector<const char*> unknown_settings(unknown_settings_count);

unknownSettingsCount = 1;
vlGetUnknownSettings(&layer_settings_create_info, static_cast<std::uint32_t>(std::size(setting_names)), setting_names,
&unknownSettingsCount, &unknownSettings[0]);
EXPECT_EQ(1, unknownSettingsCount);
EXPECT_STREQ("bool_value", unknownSettings[0]);
unknown_settings_count = 1;
vlGetUnknownSettings(&create_info, setting_name_count, setting_names, &unknown_settings_count, &unknown_settings[0]);
EXPECT_EQ(1, unknown_settings_count);
EXPECT_STREQ("bool_value", unknown_settings[0]);

unknownSettingsCount = 2;
vlGetUnknownSettings(&layer_settings_create_info, static_cast<std::uint32_t>(std::size(setting_names)), setting_names,
&unknownSettingsCount, &unknownSettings[0]);
unknown_settings_count = 2;
vlGetUnknownSettings(&create_info, setting_name_count, setting_names, &unknown_settings_count, &unknown_settings[0]);

EXPECT_STREQ("bool_value", unknownSettings[0]);
EXPECT_STREQ("frameset_value", unknownSettings[1]);
EXPECT_STREQ("bool_value", unknown_settings[0]);
EXPECT_STREQ("frameset_value", unknown_settings[1]);
}

0 comments on commit df882d0

Please sign in to comment.