Skip to content

Commit 287c064

Browse files
Add vkGetPhysicalDeviceSurfaceSupportKHR test when ICD doesn't support the surface extension
1 parent d4bb743 commit 287c064

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

tests/framework/icd/test_icd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfacePresentModes2EXT(V
934934
uint32_t* pPresentModeCount,
935935
VkPresentModeKHR* pPresentModes) {
936936
if (pSurfaceInfo->surface != VK_NULL_HANDLE) {
937-
if (!is_valid_surface(surface)) {
937+
if (!is_valid_surface(pSurfaceInfo->surface)) {
938938
assert(false && "Surface not found during GetPhysicalDeviceSurfacePresentModesKHR query!");
939939
return VK_ERROR_UNKNOWN;
940940
}

tests/loader_wsi_tests.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ TEST(WsiTests, Win32GetPhysicalDeviceSurfaceSupportKHR) {
203203
for (uint32_t pd = 0; pd < max_device_count; ++pd) {
204204
VkBool32 supported = VK_FALSE;
205205
ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported));
206+
ASSERT_EQ(VK_TRUE, supported);
206207
}
207208

208209
env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
@@ -386,6 +387,7 @@ TEST(WsiTests, XcbGetPhysicalDeviceSurfaceSupportKHR) {
386387
for (uint32_t pd = 0; pd < max_device_count; ++pd) {
387388
VkBool32 supported = VK_FALSE;
388389
ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported));
390+
ASSERT_EQ(VK_TRUE, supported);
389391
}
390392

391393
env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
@@ -569,6 +571,7 @@ TEST(WsiTests, XlibGetPhysicalDeviceSurfaceSupportKHR) {
569571
for (uint32_t pd = 0; pd < max_device_count; ++pd) {
570572
VkBool32 supported = VK_FALSE;
571573
ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported));
574+
ASSERT_EQ(VK_TRUE, supported);
572575
}
573576

574577
env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
@@ -752,6 +755,7 @@ TEST(WsiTests, WaylandGetPhysicalDeviceSurfaceSupportKHR) {
752755
for (uint32_t pd = 0; pd < max_device_count; ++pd) {
753756
VkBool32 supported = VK_FALSE;
754757
ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported));
758+
ASSERT_EQ(VK_TRUE, supported);
755759
}
756760

757761
env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
@@ -1036,3 +1040,113 @@ TEST(WsiTests, EXTSurfaceMaintenance1) {
10361040
}
10371041
}
10381042
}
1043+
#if defined(VK_USE_PLATFORM_WAYLAND_KHR) && defined(VK_USE_PLATFORM_XCB_KHR)
1044+
TEST(WsiTests, MultiPlatformGetPhysicalDeviceSurfaceSupportKHR) {
1045+
FrameworkEnvironment env{};
1046+
1047+
const char* xcb_device_name = "XCB";
1048+
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2))
1049+
.setup_WSI("VK_USE_PLATFORM_XCB_KHR")
1050+
.add_physical_device(PhysicalDevice{}
1051+
.set_deviceName(xcb_device_name)
1052+
.add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true})
1053+
.finish());
1054+
const char* wayland_device_name = "WAYLAND";
1055+
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2))
1056+
.setup_WSI("VK_USE_PLATFORM_WAYLAND_KHR")
1057+
.add_physical_device(PhysicalDevice{}
1058+
.set_deviceName(wayland_device_name)
1059+
.add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true})
1060+
.finish());
1061+
1062+
{
1063+
// Create instance with only XCB support
1064+
InstWrapper inst{env.vulkan_functions};
1065+
inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME});
1066+
inst.CheckCreate();
1067+
1068+
auto phys_devs = inst.GetPhysDevs();
1069+
// Physical devices are enumerated in reverse order to the ICD order
1070+
VkPhysicalDevice xcb_physical_device = phys_devs[1];
1071+
VkPhysicalDevice wayland_physical_device = phys_devs[0];
1072+
VkPhysicalDeviceProperties props0{};
1073+
inst->vkGetPhysicalDeviceProperties(wayland_physical_device, &props0);
1074+
ASSERT_TRUE(string_eq(props0.deviceName, wayland_device_name));
1075+
1076+
VkPhysicalDeviceProperties props1{};
1077+
inst->vkGetPhysicalDeviceProperties(xcb_physical_device, &props1);
1078+
ASSERT_TRUE(string_eq(props1.deviceName, xcb_device_name));
1079+
1080+
VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
1081+
1082+
VkSurfaceKHR surface0{VK_NULL_HANDLE};
1083+
ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(inst, &xcb_createInfo, nullptr, &surface0));
1084+
ASSERT_TRUE(surface0 != VK_NULL_HANDLE);
1085+
WrappedHandle<VkSurfaceKHR, VkInstance, PFN_vkDestroySurfaceKHR> wrapped_surface{surface0, inst.inst,
1086+
env.vulkan_functions.vkDestroySurfaceKHR};
1087+
1088+
VkWaylandSurfaceCreateInfoKHR wayland_createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
1089+
1090+
VkSurfaceKHR surface1{VK_NULL_HANDLE};
1091+
ASSERT_EQ(VK_ERROR_EXTENSION_NOT_PRESENT,
1092+
env.vulkan_functions.vkCreateWaylandSurfaceKHR(inst, &wayland_createInfo, nullptr, &surface1));
1093+
1094+
// Use the successful surface
1095+
1096+
VkBool32 supported0 = VK_FALSE;
1097+
ASSERT_EQ(VK_SUCCESS,
1098+
env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(xcb_physical_device, 0, surface0, &supported0));
1099+
ASSERT_EQ(VK_TRUE, supported0);
1100+
1101+
VkBool32 supported1 = VK_FALSE;
1102+
ASSERT_EQ(VK_SUCCESS,
1103+
env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(wayland_physical_device, 0, surface0, &supported1));
1104+
ASSERT_EQ(VK_FALSE, supported1);
1105+
}
1106+
1107+
{
1108+
// Create instance with only WAYLAND support
1109+
1110+
InstWrapper inst{env.vulkan_functions};
1111+
inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
1112+
inst.CheckCreate();
1113+
1114+
auto phys_devs = inst.GetPhysDevs();
1115+
// Physical devices are enumerated in reverse order to the ICD order
1116+
VkPhysicalDevice xcb_physical_device = phys_devs[1];
1117+
VkPhysicalDevice wayland_physical_device = phys_devs[0];
1118+
VkPhysicalDeviceProperties props0{};
1119+
inst->vkGetPhysicalDeviceProperties(wayland_physical_device, &props0);
1120+
ASSERT_TRUE(string_eq(props0.deviceName, wayland_device_name));
1121+
1122+
VkPhysicalDeviceProperties props1{};
1123+
inst->vkGetPhysicalDeviceProperties(xcb_physical_device, &props1);
1124+
ASSERT_TRUE(string_eq(props1.deviceName, xcb_device_name));
1125+
1126+
VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
1127+
1128+
VkSurfaceKHR surface0{VK_NULL_HANDLE};
1129+
ASSERT_EQ(VK_ERROR_EXTENSION_NOT_PRESENT,
1130+
env.vulkan_functions.vkCreateXcbSurfaceKHR(inst, &xcb_createInfo, nullptr, &surface0));
1131+
1132+
VkWaylandSurfaceCreateInfoKHR wayland_createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
1133+
1134+
VkSurfaceKHR surface1{VK_NULL_HANDLE};
1135+
ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(inst, &wayland_createInfo, nullptr, &surface1));
1136+
ASSERT_TRUE(surface1 != VK_NULL_HANDLE);
1137+
WrappedHandle<VkSurfaceKHR, VkInstance, PFN_vkDestroySurfaceKHR> wrapped_surface{surface1, inst.inst,
1138+
env.vulkan_functions.vkDestroySurfaceKHR};
1139+
// Use the successful surface
1140+
1141+
VkBool32 supported0 = VK_FALSE;
1142+
ASSERT_EQ(VK_SUCCESS,
1143+
env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(xcb_physical_device, 0, surface1, &supported0));
1144+
ASSERT_EQ(VK_FALSE, supported0);
1145+
1146+
VkBool32 supported1 = VK_FALSE;
1147+
ASSERT_EQ(VK_SUCCESS,
1148+
env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(wayland_physical_device, 0, surface1, &supported1));
1149+
ASSERT_EQ(VK_TRUE, supported1);
1150+
}
1151+
}
1152+
#endif // defined(VK_USE_PLATFORM_WAYLAND_KHR) && defined(VK_USE_PLATFORM_XCB_KHR)

0 commit comments

Comments
 (0)