test: Update Device Layers Match test

Move the old EnumerateDeviceLayers.LayersMatch to the new framework,
implementing the necessary components in the TestLayer code path.
This commit is contained in:
Charles Giessen 2021-08-16 16:41:42 -06:00 committed by Charles Giessen
parent 413673b249
commit b926e41607
4 changed files with 52 additions and 83 deletions

View File

@ -123,6 +123,8 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateInstance(const VkInstanceCreateInfo*
return VK_ERROR_INITIALIZATION_FAILED;
}
layer.next_vkGetInstanceProcAddr = fpGetInstanceProcAddr;
// Advance the link info for the next element of the chain
chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
@ -156,6 +158,9 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDevice(VkPhysicalDevice physicalDevi
if (fpCreateDevice == NULL) {
return VK_ERROR_INITIALIZATION_FAILED;
}
layer.next_vkGetDeviceProcAddr = fpGetDeviceProcAddr;
// Advance the link info for the next element on the chain
chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
@ -189,23 +194,24 @@ VKAPI_ATTR void VKAPI_CALL test_vkDestroyDevice(VkDevice device, const VkAllocat
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_device_func(VkDevice device, const char* pName) {
if (string_eq(pName, "vkDestroyDevice")) return TO_VOID_PFN(test_vkDestroyDevice);
return nullptr;
return layer.next_vkGetDeviceProcAddr(device, pName);
}
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_instance_func(VkInstance instance, const char* pName) {
if (pName == nullptr) return nullptr;
if (instance == NULL) {
if (string_eq(pName, "vkGetInstanceProcAddr")) return TO_VOID_PFN(get_instance_func);
if (string_eq(pName, "vkEnumerateInstanceLayerProperties")) return TO_VOID_PFN(test_vkEnumerateInstanceLayerProperties);
if (string_eq(pName, "vkEnumerateInstanceExtensionProperties"))
return TO_VOID_PFN(test_vkEnumerateInstanceExtensionProperties);
if (string_eq(pName, "vkEnumerateInstanceVersion")) return TO_VOID_PFN(test_vkEnumerateInstanceVersion);
if (string_eq(pName, "vkGetInstanceProcAddr")) return TO_VOID_PFN(get_instance_func);
if (string_eq(pName, "vkEnumerateInstanceLayerProperties")) return TO_VOID_PFN(test_vkEnumerateInstanceLayerProperties);
if (string_eq(pName, "vkEnumerateInstanceExtensionProperties")) return TO_VOID_PFN(test_vkEnumerateInstanceExtensionProperties);
if (string_eq(pName, "vkEnumerateInstanceVersion")) return TO_VOID_PFN(test_vkEnumerateInstanceVersion);
if (string_eq(pName, "vkEnumerateDeviceLayerProperties")) return TO_VOID_PFN(test_vkEnumerateDeviceLayerProperties);
if (string_eq(pName, "vkEnumerateDeviceExtensionProperties")) return TO_VOID_PFN(test_vkEnumerateDeviceExtensionProperties);
}
if (string_eq(pName, "vkEnumerateDeviceLayerProperties")) return TO_VOID_PFN(test_vkEnumerateDeviceLayerProperties);
if (string_eq(pName, "vkEnumerateDeviceExtensionProperties")) return TO_VOID_PFN(test_vkEnumerateDeviceExtensionProperties);
if (string_eq(pName, "vkCreateInstance")) return TO_VOID_PFN(test_vkCreateInstance);
if (string_eq(pName, "vkDestroyInstance")) return TO_VOID_PFN(test_vkDestroyInstance);
if (string_eq(pName, "vkCreateDevice")) return TO_VOID_PFN(test_vkCreateDevice);
if (string_eq(pName, "vkGetDeviceProcAddr")) return TO_VOID_PFN(get_device_func);
return nullptr;
return layer.next_vkGetInstanceProcAddr(instance, pName);
}
// Exported functions

View File

@ -58,7 +58,6 @@ vkEnumerateDeviceExtensionProperties
// export vkGetDeviceProcAddr
// TEST_LAYER_EXPORT_NO_NAME_GDPA
/*
Interface Version 1
*/
@ -106,6 +105,9 @@ struct TestLayer {
bool intercept_vkEnumerateInstanceExtensionProperties = false;
bool intercept_vkEnumerateInstanceLayerProperties = false;
PFN_vkGetInstanceProcAddr next_vkGetInstanceProcAddr = VK_NULL_HANDLE;
PFN_vkGetDeviceProcAddr next_vkGetDeviceProcAddr = VK_NULL_HANDLE;
VkInstance instance_handle;
VkLayerInstanceDispatchTable instance_dispatch_table;

View File

@ -292,6 +292,36 @@ TEST_F(CreateDevice, LayersNotPresent) {
ASSERT_EQ(VK_SUCCESS, inst->vkCreateDevice(phys_dev, dev_create_info.get(), nullptr, &device));
}
TEST_F(EnumerateDeviceLayerProperties, LayersMatch) {
auto& driver = env->get_test_icd();
driver.physical_devices.emplace_back("physical_device_0");
const char* layer_name = "TestLayer";
ManifestLayer::LayerDescription description{};
description.name = layer_name;
description.lib_path = TEST_LAYER_PATH_EXPORT_VERSION_2;
ManifestLayer layer;
layer.layers.push_back(description);
env->AddExplicitLayer(layer, "test_layer.json");
InstWrapper inst{env->vulkan_functions};
InstanceCreateInfo inst_create_info;
inst_create_info.add_layer(layer_name);
ASSERT_EQ(CreateInst(inst, inst_create_info), VK_SUCCESS);
VkPhysicalDevice phys_dev;
ASSERT_EQ(CreatePhysDev(inst, phys_dev), VK_SUCCESS);
uint32_t layer_count = 0;
ASSERT_EQ(env->vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &layer_count, nullptr), VK_SUCCESS);
ASSERT_EQ(layer_count, 1);
VkLayerProperties layer_props;
ASSERT_EQ(env->vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &layer_count, &layer_props), VK_SUCCESS);
ASSERT_EQ(layer_count, 1);
ASSERT_TRUE(string_eq(layer_props.layerName, layer_name));
}
TEST_F(EnumerateInstanceExtensionProperties, OnePass) {
Extension first_ext{"VK_EXT_validation_features"}; // known instance extensions
Extension second_ext{"VK_EXT_headless_surface"};

View File

@ -294,8 +294,8 @@ void test_create_device(VkPhysicalDevice physical) {
// Used by run_loader_tests.sh to test for layer insertion.
TEST(CreateInstance, LayerPresent) {
char const *const names1[] = {"VK_LAYER_LUNARG_test"}; // Temporary required due to MSVC bug.
char const *const names2[] = {"VK_LAYER_LUNARG_meta"}; // Temporary required due to MSVC bug.
char const *const names1[] = {"VK_LAYER_LUNARG_test"}; // Temporary required due to MSVC bug.
char const *const names2[] = {"VK_LAYER_LUNARG_meta"}; // Temporary required due to MSVC bug.
char const *const names3[] = {"VK_LAYER_LUNARG_meta_rev"}; // Temporary required due to MSVC bug.
auto const info1 = VK::InstanceCreateInfo().enabledLayerCount(1).ppEnabledLayerNames(names1);
VkInstance instance = VK_NULL_HANDLE;
@ -319,75 +319,6 @@ TEST(CreateInstance, LayerPresent) {
}
}
// Test to make sure that layers enabled in the instance show up in the list of device layers.
TEST(EnumerateDeviceLayers, LayersMatch) {
char const *const names1[] = {"VK_LAYER_LUNARG_meta"};
char const *const names2[2] = {"VK_LAYER_LUNARG_test", "VK_LAYER_LUNARG_wrap_objects"};
auto const info1 = VK::InstanceCreateInfo().enabledLayerCount(1).ppEnabledLayerNames(names1);
VkInstance instance = VK_NULL_HANDLE;
VkResult result = vkCreateInstance(info1, VK_NULL_HANDLE, &instance);
ASSERT_EQ(result, VK_SUCCESS);
uint32_t physicalCount = 0;
result = vkEnumeratePhysicalDevices(instance, &physicalCount, nullptr);
ASSERT_EQ(result, VK_SUCCESS);
ASSERT_GT(physicalCount, 0u);
std::unique_ptr<VkPhysicalDevice[]> physical(new VkPhysicalDevice[physicalCount]);
result = vkEnumeratePhysicalDevices(instance, &physicalCount, physical.get());
ASSERT_EQ(result, VK_SUCCESS);
ASSERT_GT(physicalCount, 0u);
uint32_t count = 24;
VkLayerProperties layer_props[24];
vkEnumerateDeviceLayerProperties(physical[0], &count, layer_props);
ASSERT_GE(count, 1u);
bool found = false;
for (uint32_t iii = 0; iii < count; iii++) {
if (!strcmp(layer_props[iii].layerName, names1[0])) {
found = true;
break;
}
}
if (!found) {
ASSERT_EQ(count, 0);
}
vkDestroyInstance(instance, nullptr);
auto const info2 = VK::InstanceCreateInfo().enabledLayerCount(2).ppEnabledLayerNames(names2);
instance = VK_NULL_HANDLE;
result = vkCreateInstance(info2, VK_NULL_HANDLE, &instance);
ASSERT_EQ(result, VK_SUCCESS);
physicalCount = 0;
result = vkEnumeratePhysicalDevices(instance, &physicalCount, nullptr);
ASSERT_EQ(result, VK_SUCCESS);
ASSERT_GT(physicalCount, 0u);
std::unique_ptr<VkPhysicalDevice[]> physical2(new VkPhysicalDevice[physicalCount]);
result = vkEnumeratePhysicalDevices(instance, &physicalCount, physical2.get());
ASSERT_EQ(result, VK_SUCCESS);
ASSERT_GT(physicalCount, 0u);
count = 24;
vkEnumerateDeviceLayerProperties(physical2[0], &count, layer_props);
ASSERT_GE(count, 2u);
for (uint32_t jjj = 0; jjj < 2; jjj++) {
found = false;
for (uint32_t iii = 0; iii < count; iii++) {
if (!strcmp(layer_props[iii].layerName, names2[jjj])) {
found = true;
break;
}
}
if (!found) {
ASSERT_EQ(count, 0);
}
}
vkDestroyInstance(instance, nullptr);
}
TEST_F(EnumerateInstanceLayerProperties, PropertyCountLessThanAvailable) {
uint32_t count = 0u;
VkResult result = vkEnumerateInstanceLayerProperties(&count, nullptr);