Skip to content

Commit

Permalink
layer: Add multiple VkLayerSettingsCreateInfo support
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Sep 20, 2023
1 parent 276fc1b commit acedefc
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 39 deletions.
7 changes: 5 additions & 2 deletions include/vulkan/layer/vk_layer_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions include/vulkan/layer/vk_layer_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef std::pair<uint32_t, uint32_t> VkuCustomSTypeInfo;
void vkuGetLayerSettingValues(VkuLayerSettingSet layerSettingSet, const char *pSettingName,
std::vector<VkuCustomSTypeInfo> &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<const char *> &unknownSettings);

28 changes: 17 additions & 11 deletions src/layer/layer_settings_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ static void AddWorkaroundLayerNames(std::vector<std::string> &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);
Expand Down Expand Up @@ -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 = &current_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;
Expand Down
5 changes: 3 additions & 2 deletions src/layer/layer_settings_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down
45 changes: 25 additions & 20 deletions src/layer/vk_layer_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<const VkBaseOutStructure *>(pCreateInfo->pNext);
const VkLayerSettingsCreateInfoEXT *found = nullptr;
while (current) {
if (VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT == current->sType) {
found = reinterpret_cast<const VkLayerSettingsCreateInfoEXT *>(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;
Expand All @@ -648,18 +662,22 @@ 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;
}

++current_unknown_setting_count;
}
}

current_create_info = vkuNextLayerSettingsCreateInfo(current_create_info);
}

if (pUnknownSettings == nullptr) {
Expand All @@ -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<const char*>& 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;
}
14 changes: 14 additions & 0 deletions src/layer/vk_layer_settings_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *> &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;
}
51 changes: 50 additions & 1 deletion tests/layer/test_setting_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<uint32_t>(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<uint32_t>(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<VkLayerSettingEXT> settings;
Expand Down
116 changes: 115 additions & 1 deletion tests/layer/test_setting_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkLayerSettingEXT> settings;

VkBool32 value_bool = VK_TRUE;
Expand Down Expand Up @@ -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<VkLayerSettingEXT> 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<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;
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<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;
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<uint32_t>(settingsA.size());
create_infoA.pSettings = &settingsA[0];

std::vector<VkLayerSettingEXT> 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<uint32_t>(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::uint32_t>(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<const char*> 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]);
}

0 comments on commit acedefc

Please sign in to comment.