Skip to content

Commit

Permalink
vkconfig3: Add manual ordering of layers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Dec 17, 2024
1 parent aed74ad commit 3017a8a
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 31 deletions.
2 changes: 1 addition & 1 deletion vkconfig_core/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Layer {
std::string description;
std::string introduction;
std::string url;
int platforms;
int platforms = PLATFORM_DESKTOP_BIT;
Path manifest_path;
LayerType type = LAYER_TYPE_EXPLICIT;
QJsonDocument profile;
Expand Down
21 changes: 12 additions & 9 deletions vkconfig_core/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ ParameterRank GetParameterOrdering(const LayerManager& layers, const Parameter&
return PARAMETER_RANK_UNORDERED_LAYER;
} else if (layer == nullptr) {
return PARAMETER_RANK_MISSING_LAYER;
} else if (IsValidationLayer(layer->key)) {
} else if (parameter.type == LAYER_TYPE_IMPLICIT) {
return PARAMETER_RANK_IMPLICIT_LAYER;
} else if (IsValidationLayer(parameter.key)) {
return PARAMETER_RANK_VALIDATION_LAYER;
} else if (IsProfilesLayer(layer->key)) {
} else if (IsProfilesLayer(parameter.key)) {
return PARAMETER_RANK_PROFILES_LAYER;
} else if (IsExtensionLayer(layer->key)) {
} else if (IsExtensionLayer(parameter.key)) {
return PARAMETER_RANK_EXTENSION_LAYER;
} else if (layer->type == LAYER_TYPE_IMPLICIT) {
return PARAMETER_RANK_IMPLICIT_LAYER;
} else if (layer->type == LAYER_TYPE_EXPLICIT) {
} else if (parameter.type == LAYER_TYPE_EXPLICIT) {
return PARAMETER_RANK_EXPLICIT_LAYER;
} else {
assert(0); // Unknown ordering
Expand All @@ -128,10 +128,10 @@ void OrderParameter(std::vector<Parameter>& parameters, const LayerManager& laye

if (both_overridden)
return a.overridden_rank < b.overridden_rank;
else if (rankA == rankB)
return a.key < b.key;
else
else if (rankA != rankB)
return rankA < rankB;
else
return a.key < b.key;
}

const LayerManager& layers;
Expand All @@ -140,10 +140,13 @@ void OrderParameter(std::vector<Parameter>& parameters, const LayerManager& laye
std::sort(parameters.begin(), parameters.end(), ParameterCompare(layers));

for (std::size_t i = 0, n = parameters.size(); i < n; ++i) {
parameters[i].overridden_rank = static_cast<int>(i);
/*
if (parameters[i].control == LAYER_CONTROL_ON)
parameters[i].overridden_rank = static_cast<int>(i);
else
parameters[i].overridden_rank = Parameter::NO_RANK;
*/
}
}

Expand Down
2 changes: 1 addition & 1 deletion vkconfig_core/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum ParameterRank {
};

struct Parameter {
static const int NO_RANK = -1;
enum { NO_RANK = -1 };

Parameter() : control(LAYER_CONTROL_AUTO) {}

Expand Down
35 changes: 17 additions & 18 deletions vkconfig_core/test/test_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,24 +333,23 @@ TEST(test_configuration, gather_parameters_missing) {
configuration.GatherParameters(layer_manager);

// Missing layer are reordred first
EXPECT_STREQ(configuration.parameters[0].key.c_str(), "VK_LAYER_LUNARG_reference_1_1_0");
EXPECT_STREQ(configuration.parameters[1].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_0");
EXPECT_STREQ(configuration.parameters[2].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_1");

EXPECT_STREQ(configuration.parameters[3].key.c_str(), "VK_LAYER_LUNARG_test_00");
EXPECT_STREQ(configuration.parameters[4].key.c_str(), "VK_LAYER_LUNARG_test_01");
EXPECT_STREQ(configuration.parameters[5].key.c_str(), "VK_LAYER_LUNARG_test_02");
EXPECT_STREQ(configuration.parameters[6].key.c_str(), "VK_LAYER_LUNARG_test_03");
EXPECT_STREQ(configuration.parameters[7].key.c_str(), "VK_LAYER_LUNARG_test_04");
EXPECT_STREQ(configuration.parameters[8].key.c_str(), "VK_LAYER_LUNARG_test_05");
EXPECT_STREQ(configuration.parameters[9].key.c_str(), "VK_LAYER_LUNARG_test_06");
EXPECT_STREQ(configuration.parameters[10].key.c_str(), "VK_LAYER_LUNARG_test_07");
EXPECT_STREQ(configuration.parameters[11].key.c_str(), "VK_LAYER_LUNARG_test_08");

EXPECT_STREQ(configuration.parameters[12].key.c_str(), "VK_LAYER_LUNARG_version");

// Unordered are never missing so end up last
EXPECT_STREQ(configuration.parameters[13].key.c_str(), ::GetLabel(LAYER_BUILTIN_UNORDERED));
EXPECT_STREQ(configuration.parameters[0].key.c_str(), ::GetLabel(LAYER_BUILTIN_UNORDERED));

EXPECT_STREQ(configuration.parameters[1].key.c_str(), "VK_LAYER_LUNARG_reference_1_1_0");
EXPECT_STREQ(configuration.parameters[2].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_0");
EXPECT_STREQ(configuration.parameters[3].key.c_str(), "VK_LAYER_LUNARG_reference_1_2_1");

EXPECT_STREQ(configuration.parameters[4].key.c_str(), "VK_LAYER_LUNARG_test_00");
EXPECT_STREQ(configuration.parameters[5].key.c_str(), "VK_LAYER_LUNARG_test_01");
EXPECT_STREQ(configuration.parameters[6].key.c_str(), "VK_LAYER_LUNARG_test_02");
EXPECT_STREQ(configuration.parameters[7].key.c_str(), "VK_LAYER_LUNARG_test_03");
EXPECT_STREQ(configuration.parameters[8].key.c_str(), "VK_LAYER_LUNARG_test_04");
EXPECT_STREQ(configuration.parameters[9].key.c_str(), "VK_LAYER_LUNARG_test_05");
EXPECT_STREQ(configuration.parameters[10].key.c_str(), "VK_LAYER_LUNARG_test_06");
EXPECT_STREQ(configuration.parameters[11].key.c_str(), "VK_LAYER_LUNARG_test_07");
EXPECT_STREQ(configuration.parameters[12].key.c_str(), "VK_LAYER_LUNARG_test_08");

EXPECT_STREQ(configuration.parameters[13].key.c_str(), "VK_LAYER_LUNARG_version");

std::string missing_layer;
EXPECT_TRUE(HasMissingLayer(configuration.parameters, layer_manager, missing_layer));
Expand Down
155 changes: 153 additions & 2 deletions vkconfig_core/test/test_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ TEST(test_parameter, ordering_found_parameter_rank) {

layers.selected_layers[0].type = LAYER_TYPE_IMPLICIT;

Parameter parameter_implicit("VK_LAYER_KHRONOS_implicit", LAYER_CONTROL_OFF);
parameter_implicit.type = LAYER_TYPE_IMPLICIT;

EXPECT_EQ(PARAMETER_RANK_VALIDATION_LAYER,
GetParameterOrdering(layers, Parameter("VK_LAYER_KHRONOS_validation", LAYER_CONTROL_AUTO)));
EXPECT_EQ(PARAMETER_RANK_PROFILES_LAYER,
Expand All @@ -94,8 +97,7 @@ TEST(test_parameter, ordering_found_parameter_rank) {
GetParameterOrdering(layers, Parameter("VK_LAYER_KHRONOS_memory_decompression", LAYER_CONTROL_OFF)));
EXPECT_EQ(PARAMETER_RANK_EXPLICIT_LAYER,
GetParameterOrdering(layers, Parameter("VK_LAYER_KHRONOS_explicit", LAYER_CONTROL_ON)));
EXPECT_EQ(PARAMETER_RANK_IMPLICIT_LAYER,
GetParameterOrdering(layers, Parameter("VK_LAYER_KHRONOS_implicit", LAYER_CONTROL_OFF)));
EXPECT_EQ(PARAMETER_RANK_IMPLICIT_LAYER, GetParameterOrdering(layers, parameter_implicit));
EXPECT_EQ(PARAMETER_RANK_MISSING_LAYER, GetParameterOrdering(layers, Parameter("VK_LAYER_KHRONOS_missing", LAYER_CONTROL_OFF)));
}

Expand Down Expand Up @@ -126,3 +128,152 @@ TEST(test_parameter, no_missing_layer) {
EXPECT_EQ(::HasMissingLayer(parameters, layers, missing_layer), false);
EXPECT_TRUE(missing_layer.empty());
}

TEST(test_parameter, order_parameter_automatic) {
LayerManager layers;
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_implicit", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_explicit", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_validation", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_profiles", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(
Layer("VK_LAYER_KHRONOS_timeline_semaphore", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(
Layer("VK_LAYER_KHRONOS_synchronization2", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(
Layer("VK_LAYER_KHRONOS_shader_object", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(
Layer("VK_LAYER_KHRONOS_memory_decompression", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers[0].type = LAYER_TYPE_IMPLICIT;

Parameter unordered_layers(::GetToken(LAYER_BUILTIN_UNORDERED), LAYER_CONTROL_AUTO);
unordered_layers.builtin = LAYER_BUILTIN_UNORDERED;

std::vector<Parameter> parameters;
parameters.push_back(Parameter("VK_LAYER_KHRONOS_implicit", LAYER_CONTROL_AUTO));
parameters.push_back(unordered_layers);
parameters.push_back(Parameter("VK_LAYER_KHRONOS_validation", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_profiles", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_timeline_semaphore", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_synchronization2", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_shader_object", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_memory_decompression", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_explicit", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_missing", LAYER_CONTROL_AUTO));

parameters[0].type = LAYER_TYPE_IMPLICIT;

::OrderParameter(parameters, layers);

EXPECT_STREQ(parameters[0].key.c_str(), "VK_LAYER_KHRONOS_missing");
EXPECT_STREQ(parameters[1].key.c_str(), "VK_LAYER_KHRONOS_implicit");
EXPECT_EQ(parameters[2].builtin, LAYER_BUILTIN_UNORDERED);
EXPECT_STREQ(parameters[3].key.c_str(), "VK_LAYER_KHRONOS_explicit");
EXPECT_STREQ(parameters[4].key.c_str(), "VK_LAYER_KHRONOS_validation");
EXPECT_STREQ(parameters[5].key.c_str(), "VK_LAYER_KHRONOS_profiles");
EXPECT_STREQ(parameters[6].key.c_str(), "VK_LAYER_KHRONOS_memory_decompression");
EXPECT_STREQ(parameters[7].key.c_str(), "VK_LAYER_KHRONOS_shader_object");
EXPECT_STREQ(parameters[8].key.c_str(), "VK_LAYER_KHRONOS_synchronization2");
EXPECT_STREQ(parameters[9].key.c_str(), "VK_LAYER_KHRONOS_timeline_semaphore");

::OrderParameter(parameters, layers);

EXPECT_STREQ(parameters[0].key.c_str(), "VK_LAYER_KHRONOS_missing");
EXPECT_STREQ(parameters[1].key.c_str(), "VK_LAYER_KHRONOS_implicit");
EXPECT_EQ(parameters[2].builtin, LAYER_BUILTIN_UNORDERED);
EXPECT_STREQ(parameters[3].key.c_str(), "VK_LAYER_KHRONOS_explicit");
EXPECT_STREQ(parameters[4].key.c_str(), "VK_LAYER_KHRONOS_validation");
EXPECT_STREQ(parameters[5].key.c_str(), "VK_LAYER_KHRONOS_profiles");
EXPECT_STREQ(parameters[6].key.c_str(), "VK_LAYER_KHRONOS_memory_decompression");
EXPECT_STREQ(parameters[7].key.c_str(), "VK_LAYER_KHRONOS_shader_object");
EXPECT_STREQ(parameters[8].key.c_str(), "VK_LAYER_KHRONOS_synchronization2");
EXPECT_STREQ(parameters[9].key.c_str(), "VK_LAYER_KHRONOS_timeline_semaphore");
}

TEST(test_parameter, order_parameter_manual_partial) {
LayerManager layers;
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_implicit", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_explicit", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_validation", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_profiles", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(
Layer("VK_LAYER_KHRONOS_timeline_semaphore", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(
Layer("VK_LAYER_KHRONOS_synchronization2", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(
Layer("VK_LAYER_KHRONOS_shader_object", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.push_back(
Layer("VK_LAYER_KHRONOS_memory_decompression", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers[0].type = LAYER_TYPE_IMPLICIT;

std::vector<Parameter> parameters;
parameters.push_back(Parameter("VK_LAYER_KHRONOS_implicit", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter(::GetToken(LAYER_BUILTIN_UNORDERED), LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_missing", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_validation", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_profiles", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_timeline_semaphore", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_synchronization2", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_shader_object", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_memory_decompression", LAYER_CONTROL_AUTO));
parameters.push_back(Parameter("VK_LAYER_KHRONOS_explicit", LAYER_CONTROL_AUTO));

parameters[0].type = LAYER_TYPE_IMPLICIT;
parameters[1].builtin = LAYER_BUILTIN_UNORDERED;

for (std::size_t i = 0, n = parameters.size(); i < n; ++i) {
if (i == 7 || i == 0) {
continue;
}

parameters[i].overridden_rank = static_cast<int>(i);
}

::OrderParameter(parameters, layers);

EXPECT_STREQ(parameters[0].key.c_str(), "VK_LAYER_KHRONOS_missing");
EXPECT_STREQ(parameters[1].key.c_str(), "VK_LAYER_KHRONOS_implicit");
EXPECT_EQ(parameters[2].builtin, LAYER_BUILTIN_UNORDERED);
EXPECT_STREQ(parameters[3].key.c_str(), "VK_LAYER_KHRONOS_validation");
EXPECT_STREQ(parameters[4].key.c_str(), "VK_LAYER_KHRONOS_profiles");
EXPECT_STREQ(parameters[5].key.c_str(), "VK_LAYER_KHRONOS_shader_object");
EXPECT_STREQ(parameters[6].key.c_str(), "VK_LAYER_KHRONOS_timeline_semaphore");
EXPECT_STREQ(parameters[7].key.c_str(), "VK_LAYER_KHRONOS_synchronization2");
EXPECT_STREQ(parameters[8].key.c_str(), "VK_LAYER_KHRONOS_memory_decompression");
EXPECT_STREQ(parameters[9].key.c_str(), "VK_LAYER_KHRONOS_explicit");

// Check ordering again result in the same list
::OrderParameter(parameters, layers);

EXPECT_STREQ(parameters[0].key.c_str(), "VK_LAYER_KHRONOS_missing");
EXPECT_STREQ(parameters[1].key.c_str(), "VK_LAYER_KHRONOS_implicit");
EXPECT_EQ(parameters[2].builtin, LAYER_BUILTIN_UNORDERED);
EXPECT_STREQ(parameters[3].key.c_str(), "VK_LAYER_KHRONOS_validation");
EXPECT_STREQ(parameters[4].key.c_str(), "VK_LAYER_KHRONOS_profiles");
EXPECT_STREQ(parameters[5].key.c_str(), "VK_LAYER_KHRONOS_shader_object");
EXPECT_STREQ(parameters[6].key.c_str(), "VK_LAYER_KHRONOS_timeline_semaphore");
EXPECT_STREQ(parameters[7].key.c_str(), "VK_LAYER_KHRONOS_synchronization2");
EXPECT_STREQ(parameters[8].key.c_str(), "VK_LAYER_KHRONOS_memory_decompression");
EXPECT_STREQ(parameters[9].key.c_str(), "VK_LAYER_KHRONOS_explicit");

// Insert a new layer in the parameter list
layers.selected_layers.push_back(Layer("VK_LAYER_KHRONOS_implicit2", Version(1, 0, 0), Version(1, 2, 148), "1", "layer.json"));
layers.selected_layers.back().type = LAYER_TYPE_IMPLICIT;

Parameter parameter_implicit2("VK_LAYER_KHRONOS_implicit2", LAYER_CONTROL_AUTO);
parameter_implicit2.type = LAYER_TYPE_IMPLICIT;
parameters.push_back(parameter_implicit2);

::OrderParameter(parameters, layers);

EXPECT_STREQ(parameters[0].key.c_str(), "VK_LAYER_KHRONOS_missing");
EXPECT_STREQ(parameters[1].key.c_str(), "VK_LAYER_KHRONOS_implicit");
EXPECT_STREQ(parameters[2].key.c_str(), "VK_LAYER_KHRONOS_implicit2");
EXPECT_EQ(parameters[3].builtin, LAYER_BUILTIN_UNORDERED);
EXPECT_STREQ(parameters[4].key.c_str(), "VK_LAYER_KHRONOS_validation");
EXPECT_STREQ(parameters[5].key.c_str(), "VK_LAYER_KHRONOS_profiles");
EXPECT_STREQ(parameters[6].key.c_str(), "VK_LAYER_KHRONOS_shader_object");
EXPECT_STREQ(parameters[7].key.c_str(), "VK_LAYER_KHRONOS_timeline_semaphore");
EXPECT_STREQ(parameters[8].key.c_str(), "VK_LAYER_KHRONOS_synchronization2");
EXPECT_STREQ(parameters[9].key.c_str(), "VK_LAYER_KHRONOS_memory_decompression");
EXPECT_STREQ(parameters[10].key.c_str(), "VK_LAYER_KHRONOS_explicit");
}

0 comments on commit 3017a8a

Please sign in to comment.