15db71995Sopenharmony_ci/* 25db71995Sopenharmony_ci * Copyright (c) 2021-2022 The Khronos Group Inc. 35db71995Sopenharmony_ci * Copyright (c) 2021-2022 Valve Corporation 45db71995Sopenharmony_ci * Copyright (c) 2021-2022 LunarG, Inc. 55db71995Sopenharmony_ci * 65db71995Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 75db71995Sopenharmony_ci * of this software and/or associated documentation files (the "Materials"), to 85db71995Sopenharmony_ci * deal in the Materials without restriction, including without limitation the 95db71995Sopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 105db71995Sopenharmony_ci * sell copies of the Materials, and to permit persons to whom the Materials are 115db71995Sopenharmony_ci * furnished to do so, subject to the following conditions: 125db71995Sopenharmony_ci * 135db71995Sopenharmony_ci * The above copyright notice(s) and this permission notice shall be included in 145db71995Sopenharmony_ci * all copies or substantial portions of the Materials. 155db71995Sopenharmony_ci * 165db71995Sopenharmony_ci * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 175db71995Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 185db71995Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 195db71995Sopenharmony_ci * 205db71995Sopenharmony_ci * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 215db71995Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 225db71995Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE 235db71995Sopenharmony_ci * USE OR OTHER DEALINGS IN THE MATERIALS. 245db71995Sopenharmony_ci * 255db71995Sopenharmony_ci * Author: Charles Giessen <charles@lunarg.com> 265db71995Sopenharmony_ci */ 275db71995Sopenharmony_ci 285db71995Sopenharmony_ci#include "test_environment.h" 295db71995Sopenharmony_ci 305db71995Sopenharmony_ciclass WsiTests : public ::testing::Test {}; 315db71995Sopenharmony_ci 325db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_WIN32_KHR) 335db71995Sopenharmony_ci 345db71995Sopenharmony_ci// When ICD doesn't support the extension, create instance should fail 355db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceWin32NoICDSupport) { 365db71995Sopenharmony_ci FrameworkEnvironment env{}; 375db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 385db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 395db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 405db71995Sopenharmony_ci 415db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 425db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 435db71995Sopenharmony_ci inst.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 445db71995Sopenharmony_ci 455db71995Sopenharmony_ci InstWrapper inst2{env.vulkan_functions}; 465db71995Sopenharmony_ci inst2.CheckCreate(); 475db71995Sopenharmony_ci 485db71995Sopenharmony_ci ASSERT_EQ(nullptr, env.vulkan_functions.vkGetInstanceProcAddr(inst2.inst, "vkCreateWin32SurfaceKHR")); 495db71995Sopenharmony_ci} 505db71995Sopenharmony_ci 515db71995Sopenharmony_ci// When ICD doesn't support the surface creation, the loader should handle it 525db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceWin32NoICDCreateSupport) { 535db71995Sopenharmony_ci FrameworkEnvironment env{}; 545db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 555db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 565db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 575db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 585db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 595db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 605db71995Sopenharmony_ci 615db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 625db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 635db71995Sopenharmony_ci inst.CheckCreate(); 645db71995Sopenharmony_ci 655db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 665db71995Sopenharmony_ci VkWin32SurfaceCreateInfoKHR surf_create_info{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR}; 675db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWin32SurfaceKHR(inst, &surf_create_info, nullptr, &surface)); 685db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 695db71995Sopenharmony_ci 705db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr); 715db71995Sopenharmony_ci} 725db71995Sopenharmony_ci 735db71995Sopenharmony_ci// When ICD does support the surface creation, the loader should delegat handle it to the ICD 745db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceWin32ICDSupport) { 755db71995Sopenharmony_ci FrameworkEnvironment env{}; 765db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 775db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 785db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 795db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 805db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 815db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 825db71995Sopenharmony_ci 835db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 845db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 855db71995Sopenharmony_ci inst.CheckCreate(); 865db71995Sopenharmony_ci 875db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 885db71995Sopenharmony_ci VkWin32SurfaceCreateInfoKHR surf_create_info{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR}; 895db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWin32SurfaceKHR(inst, &surf_create_info, nullptr, &surface)); 905db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 915db71995Sopenharmony_ci 925db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr); 935db71995Sopenharmony_ci} 945db71995Sopenharmony_ci 955db71995Sopenharmony_ci// Some drivers supporting vkCreateWin32SurfaceKHR, and at least one that doesn't 965db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceWin32MixedICDSupport) { 975db71995Sopenharmony_ci FrameworkEnvironment env{}; 985db71995Sopenharmony_ci for (uint32_t icd = 0; icd < 3; ++icd) { 995db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 1005db71995Sopenharmony_ci Extension second_ext{VK_KHR_WIN32_SURFACE_EXTENSION_NAME}; 1015db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 1025db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 1035db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 1045db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext}); 1055db71995Sopenharmony_ci if (icd < 2) { 1065db71995Sopenharmony_ci // Only enable ICD for first two 1075db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 1085db71995Sopenharmony_ci } 1095db71995Sopenharmony_ci } 1105db71995Sopenharmony_ci 1115db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 1125db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 1135db71995Sopenharmony_ci instance.CheckCreate(); 1145db71995Sopenharmony_ci 1155db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 1165db71995Sopenharmony_ci VkWin32SurfaceCreateInfoKHR surf_create_info{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR}; 1175db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWin32SurfaceKHR(instance.inst, &surf_create_info, nullptr, &surface)); 1185db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 1195db71995Sopenharmony_ci 1205db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr); 1215db71995Sopenharmony_ci} 1225db71995Sopenharmony_ci 1235db71995Sopenharmony_ciTEST(WsiTests, GetPhysicalDeviceWin32PresentNoICDSupport) { 1245db71995Sopenharmony_ci FrameworkEnvironment env{}; 1255db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 1265db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 1275db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 1285db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 1295db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 1305db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back("physical_device_0"); 1315db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 1325db71995Sopenharmony_ci 1335db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 1345db71995Sopenharmony_ci inst.create_info.add_extensions( 1355db71995Sopenharmony_ci {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 1365db71995Sopenharmony_ci inst.CheckCreate(); 1375db71995Sopenharmony_ci 1385db71995Sopenharmony_ci uint32_t driver_count = 1; 1395db71995Sopenharmony_ci VkPhysicalDevice physical_device; 1405db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device)); 1415db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 1425db71995Sopenharmony_ci 1435db71995Sopenharmony_ci DebugUtilsWrapper log{inst}; 1445db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 1455db71995Sopenharmony_ci auto res = env.vulkan_functions.vkGetPhysicalDeviceWin32PresentationSupportKHR(physical_device, 0); 1465db71995Sopenharmony_ci ASSERT_EQ(res, VK_FALSE); 1475db71995Sopenharmony_ci ASSERT_TRUE(log.find("ICD for selected physical device does not export vkGetPhysicalDeviceWin32PresentationSupportKHR!")); 1485db71995Sopenharmony_ci} 1495db71995Sopenharmony_ci 1505db71995Sopenharmony_ciTEST(WsiTests, GetPhysicalDeviceWin32PresentICDSupport) { 1515db71995Sopenharmony_ci FrameworkEnvironment env{}; 1525db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 1535db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 1545db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 1555db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 1565db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 1575db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back("physical_device_0"); 1585db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 1595db71995Sopenharmony_ci 1605db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 1615db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 1625db71995Sopenharmony_ci inst.CheckCreate(); 1635db71995Sopenharmony_ci 1645db71995Sopenharmony_ci uint32_t driver_count = 1; 1655db71995Sopenharmony_ci VkPhysicalDevice physical_device; 1665db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device)); 1675db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 1685db71995Sopenharmony_ci 1695db71995Sopenharmony_ci ASSERT_EQ(VK_TRUE, env.vulkan_functions.vkGetPhysicalDeviceWin32PresentationSupportKHR(physical_device, 0)); 1705db71995Sopenharmony_ci} 1715db71995Sopenharmony_ci 1725db71995Sopenharmony_ciTEST(WsiTests, Win32GetPhysicalDeviceSurfaceSupportKHR) { 1735db71995Sopenharmony_ci FrameworkEnvironment env{}; 1745db71995Sopenharmony_ci const uint32_t max_device_count = 4; 1755db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_device_count; ++icd) { 1765db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 1775db71995Sopenharmony_ci Extension second_ext{VK_KHR_WIN32_SURFACE_EXTENSION_NAME}; 1785db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 1795db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 1805db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 1815db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 1825db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext}); 1835db71995Sopenharmony_ci std::string dev_name = "phys_dev_" + std::to_string(icd); 1845db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back(dev_name.c_str()); 1855db71995Sopenharmony_ci cur_icd.physical_devices.back().add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true}); 1865db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 1875db71995Sopenharmony_ci } 1885db71995Sopenharmony_ci 1895db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 1905db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME}); 1915db71995Sopenharmony_ci instance.CheckCreate(); 1925db71995Sopenharmony_ci 1935db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 1945db71995Sopenharmony_ci VkWin32SurfaceCreateInfoKHR surf_create_info{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR}; 1955db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWin32SurfaceKHR(instance.inst, &surf_create_info, nullptr, &surface)); 1965db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 1975db71995Sopenharmony_ci 1985db71995Sopenharmony_ci uint32_t device_count = max_device_count; 1995db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_device_count> phys_devs; 2005db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumeratePhysicalDevices(instance.inst, &device_count, phys_devs.data())); 2015db71995Sopenharmony_ci ASSERT_EQ(device_count, max_device_count); 2025db71995Sopenharmony_ci 2035db71995Sopenharmony_ci for (uint32_t pd = 0; pd < max_device_count; ++pd) { 2045db71995Sopenharmony_ci VkBool32 supported = VK_FALSE; 2055db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported)); 2065db71995Sopenharmony_ci } 2075db71995Sopenharmony_ci 2085db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr); 2095db71995Sopenharmony_ci} 2105db71995Sopenharmony_ci#endif 2115db71995Sopenharmony_ci 2125db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_XCB_KHR) 2135db71995Sopenharmony_ci// When ICD doesn't support the extension, create instance should fail 2145db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceXCBNoICDSupport) { 2155db71995Sopenharmony_ci FrameworkEnvironment env{}; 2165db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 2175db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 2185db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 2195db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 2205db71995Sopenharmony_ci 2215db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 2225db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 2235db71995Sopenharmony_ci inst.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 2245db71995Sopenharmony_ci 2255db71995Sopenharmony_ci InstWrapper inst2{env.vulkan_functions}; 2265db71995Sopenharmony_ci inst2.CheckCreate(); 2275db71995Sopenharmony_ci 2285db71995Sopenharmony_ci ASSERT_EQ(nullptr, env.vulkan_functions.vkGetInstanceProcAddr(inst2.inst, "vkCreateXcbSurfaceKHR")); 2295db71995Sopenharmony_ci} 2305db71995Sopenharmony_ci 2315db71995Sopenharmony_ci// When ICD doesn't support the surface creation, the loader should handle it 2325db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceXCBNoICDCreateSupport) { 2335db71995Sopenharmony_ci FrameworkEnvironment env{}; 2345db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 2355db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 2365db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 2375db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 2385db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 2395db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 2405db71995Sopenharmony_ci 2415db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 2425db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 2435db71995Sopenharmony_ci inst.CheckCreate(); 2445db71995Sopenharmony_ci 2455db71995Sopenharmony_ci VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR}; 2465db71995Sopenharmony_ci 2475db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 2485db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(inst, &xcb_createInfo, nullptr, &surface)); 2495db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 2505db71995Sopenharmony_ci 2515db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr); 2525db71995Sopenharmony_ci} 2535db71995Sopenharmony_ci 2545db71995Sopenharmony_ci// When ICD does support the surface creation, the loader should delegat handle it to the ICD 2555db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceXCBICDSupport) { 2565db71995Sopenharmony_ci FrameworkEnvironment env{}; 2575db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 2585db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 2595db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 2605db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 2615db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 2625db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 2635db71995Sopenharmony_ci 2645db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 2655db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 2665db71995Sopenharmony_ci inst.CheckCreate(); 2675db71995Sopenharmony_ci 2685db71995Sopenharmony_ci VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR}; 2695db71995Sopenharmony_ci 2705db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 2715db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(inst, &xcb_createInfo, nullptr, &surface)); 2725db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 2735db71995Sopenharmony_ci 2745db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr); 2755db71995Sopenharmony_ci} 2765db71995Sopenharmony_ci 2775db71995Sopenharmony_ci// Some drivers supporting vkCreateXcbSurfaceKHR, and at least one that doesn't 2785db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceXCBMixedICDSupport) { 2795db71995Sopenharmony_ci FrameworkEnvironment env{}; 2805db71995Sopenharmony_ci for (uint32_t icd = 0; icd < 3; ++icd) { 2815db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 2825db71995Sopenharmony_ci Extension second_ext{VK_KHR_XCB_SURFACE_EXTENSION_NAME}; 2835db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 2845db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 2855db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 2865db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext}); 2875db71995Sopenharmony_ci if (icd < 2) { 2885db71995Sopenharmony_ci // Only enable ICD for first two 2895db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 2905db71995Sopenharmony_ci } 2915db71995Sopenharmony_ci } 2925db71995Sopenharmony_ci 2935db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 2945db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 2955db71995Sopenharmony_ci instance.CheckCreate(); 2965db71995Sopenharmony_ci 2975db71995Sopenharmony_ci VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR}; 2985db71995Sopenharmony_ci 2995db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 3005db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(instance.inst, &xcb_createInfo, nullptr, &surface)); 3015db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 3025db71995Sopenharmony_ci 3035db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr); 3045db71995Sopenharmony_ci} 3055db71995Sopenharmony_ci 3065db71995Sopenharmony_ciTEST(WsiTests, GetPhysicalDeviceXcbPresentNoICDSupport) { 3075db71995Sopenharmony_ci FrameworkEnvironment env{}; 3085db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 3095db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 3105db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 3115db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 3125db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 3135db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back("physical_device_0"); 3145db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 3155db71995Sopenharmony_ci 3165db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 3175db71995Sopenharmony_ci inst.create_info.add_extensions( 3185db71995Sopenharmony_ci {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 3195db71995Sopenharmony_ci inst.CheckCreate(); 3205db71995Sopenharmony_ci 3215db71995Sopenharmony_ci uint32_t driver_count = 1; 3225db71995Sopenharmony_ci VkPhysicalDevice physical_device; 3235db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device)); 3245db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 3255db71995Sopenharmony_ci 3265db71995Sopenharmony_ci DebugUtilsWrapper log{inst}; 3275db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 3285db71995Sopenharmony_ci auto res = env.vulkan_functions.vkGetPhysicalDeviceXcbPresentationSupportKHR(physical_device, 0, nullptr, 0); 3295db71995Sopenharmony_ci ASSERT_EQ(res, VK_FALSE); 3305db71995Sopenharmony_ci ASSERT_TRUE(log.find("ICD for selected physical device does not export vkGetPhysicalDeviceXcbPresentationSupportKHR!")); 3315db71995Sopenharmony_ci} 3325db71995Sopenharmony_ci 3335db71995Sopenharmony_ciTEST(WsiTests, GetPhysicalDeviceXcbPresentICDSupport) { 3345db71995Sopenharmony_ci FrameworkEnvironment env{}; 3355db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 3365db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 3375db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 3385db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 3395db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 3405db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back("physical_device_0"); 3415db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 3425db71995Sopenharmony_ci 3435db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 3445db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 3455db71995Sopenharmony_ci inst.CheckCreate(); 3465db71995Sopenharmony_ci 3475db71995Sopenharmony_ci uint32_t driver_count = 1; 3485db71995Sopenharmony_ci VkPhysicalDevice physical_device; 3495db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device)); 3505db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 3515db71995Sopenharmony_ci 3525db71995Sopenharmony_ci ASSERT_EQ(VK_TRUE, env.vulkan_functions.vkGetPhysicalDeviceXcbPresentationSupportKHR(physical_device, 0, nullptr, 0)); 3535db71995Sopenharmony_ci} 3545db71995Sopenharmony_ci 3555db71995Sopenharmony_ciTEST(WsiTests, XcbGetPhysicalDeviceSurfaceSupportKHR) { 3565db71995Sopenharmony_ci FrameworkEnvironment env{}; 3575db71995Sopenharmony_ci const uint32_t max_device_count = 4; 3585db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_device_count; ++icd) { 3595db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 3605db71995Sopenharmony_ci Extension second_ext{VK_KHR_XCB_SURFACE_EXTENSION_NAME}; 3615db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 3625db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 3635db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 3645db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 3655db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext}); 3665db71995Sopenharmony_ci std::string dev_name = "phys_dev_" + std::to_string(icd); 3675db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back(dev_name.c_str()); 3685db71995Sopenharmony_ci cur_icd.physical_devices.back().add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true}); 3695db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 3705db71995Sopenharmony_ci } 3715db71995Sopenharmony_ci 3725db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 3735db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME}); 3745db71995Sopenharmony_ci instance.CheckCreate(); 3755db71995Sopenharmony_ci 3765db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 3775db71995Sopenharmony_ci VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR}; 3785db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(instance.inst, &xcb_createInfo, nullptr, &surface)); 3795db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 3805db71995Sopenharmony_ci 3815db71995Sopenharmony_ci uint32_t device_count = max_device_count; 3825db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_device_count> phys_devs; 3835db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumeratePhysicalDevices(instance.inst, &device_count, phys_devs.data())); 3845db71995Sopenharmony_ci ASSERT_EQ(device_count, max_device_count); 3855db71995Sopenharmony_ci 3865db71995Sopenharmony_ci for (uint32_t pd = 0; pd < max_device_count; ++pd) { 3875db71995Sopenharmony_ci VkBool32 supported = VK_FALSE; 3885db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported)); 3895db71995Sopenharmony_ci } 3905db71995Sopenharmony_ci 3915db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr); 3925db71995Sopenharmony_ci} 3935db71995Sopenharmony_ci#endif 3945db71995Sopenharmony_ci 3955db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_XLIB_KHR) 3965db71995Sopenharmony_ci// When ICD doesn't support the extension, create instance should fail 3975db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceXLIBNoICDSupport) { 3985db71995Sopenharmony_ci FrameworkEnvironment env{}; 3995db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 4005db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 4015db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 4025db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 4035db71995Sopenharmony_ci 4045db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 4055db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 4065db71995Sopenharmony_ci inst.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 4075db71995Sopenharmony_ci 4085db71995Sopenharmony_ci InstWrapper inst2{env.vulkan_functions}; 4095db71995Sopenharmony_ci inst2.CheckCreate(); 4105db71995Sopenharmony_ci 4115db71995Sopenharmony_ci ASSERT_EQ(nullptr, env.vulkan_functions.vkGetInstanceProcAddr(inst2.inst, "vkCreateXlibSurfaceKHR")); 4125db71995Sopenharmony_ci} 4135db71995Sopenharmony_ci 4145db71995Sopenharmony_ci// When ICD doesn't support the surface creation, the loader should handle it 4155db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceXLIBNoICDCreateSupport) { 4165db71995Sopenharmony_ci FrameworkEnvironment env{}; 4175db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 4185db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 4195db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 4205db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 4215db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 4225db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 4235db71995Sopenharmony_ci 4245db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 4255db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 4265db71995Sopenharmony_ci inst.CheckCreate(); 4275db71995Sopenharmony_ci 4285db71995Sopenharmony_ci VkXlibSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR}; 4295db71995Sopenharmony_ci 4305db71995Sopenharmony_ci VkSurfaceKHR surface; 4315db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXlibSurfaceKHR(inst, &createInfo, nullptr, &surface)); 4325db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 4335db71995Sopenharmony_ci 4345db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr); 4355db71995Sopenharmony_ci} 4365db71995Sopenharmony_ci 4375db71995Sopenharmony_ci// When ICD does support the surface creation, the loader should delegat handle it to the ICD 4385db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceXLIBICDSupport) { 4395db71995Sopenharmony_ci FrameworkEnvironment env{}; 4405db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 4415db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 4425db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 4435db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 4445db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 4455db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 4465db71995Sopenharmony_ci 4475db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 4485db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 4495db71995Sopenharmony_ci inst.CheckCreate(); 4505db71995Sopenharmony_ci 4515db71995Sopenharmony_ci VkXlibSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR}; 4525db71995Sopenharmony_ci 4535db71995Sopenharmony_ci VkSurfaceKHR surface; 4545db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXlibSurfaceKHR(inst, &createInfo, nullptr, &surface)); 4555db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 4565db71995Sopenharmony_ci 4575db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr); 4585db71995Sopenharmony_ci} 4595db71995Sopenharmony_ci 4605db71995Sopenharmony_ci// Some drivers supporting vkCreateXlibSurfaceKHR, and at least one that doesn't 4615db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceXLIBMixedICDSupport) { 4625db71995Sopenharmony_ci FrameworkEnvironment env{}; 4635db71995Sopenharmony_ci for (uint32_t icd = 0; icd < 3; ++icd) { 4645db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 4655db71995Sopenharmony_ci Extension second_ext{VK_KHR_XLIB_SURFACE_EXTENSION_NAME}; 4665db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 4675db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 4685db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 4695db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext}); 4705db71995Sopenharmony_ci if (icd < 2) { 4715db71995Sopenharmony_ci // Only enable ICD for first two 4725db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 4735db71995Sopenharmony_ci } 4745db71995Sopenharmony_ci } 4755db71995Sopenharmony_ci 4765db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 4775db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 4785db71995Sopenharmony_ci instance.CheckCreate(); 4795db71995Sopenharmony_ci 4805db71995Sopenharmony_ci VkXlibSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR}; 4815db71995Sopenharmony_ci 4825db71995Sopenharmony_ci VkSurfaceKHR surface; 4835db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXlibSurfaceKHR(instance.inst, &createInfo, nullptr, &surface)); 4845db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 4855db71995Sopenharmony_ci 4865db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr); 4875db71995Sopenharmony_ci} 4885db71995Sopenharmony_ci 4895db71995Sopenharmony_ciTEST(WsiTests, GetPhysicalDeviceXlibPresentNoICDSupport) { 4905db71995Sopenharmony_ci FrameworkEnvironment env{}; 4915db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 4925db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 4935db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 4945db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 4955db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 4965db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back("physical_device_0"); 4975db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 4985db71995Sopenharmony_ci 4995db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 5005db71995Sopenharmony_ci inst.create_info.add_extensions( 5015db71995Sopenharmony_ci {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 5025db71995Sopenharmony_ci inst.CheckCreate(); 5035db71995Sopenharmony_ci 5045db71995Sopenharmony_ci uint32_t driver_count = 1; 5055db71995Sopenharmony_ci VkPhysicalDevice physical_device; 5065db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device)); 5075db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 5085db71995Sopenharmony_ci 5095db71995Sopenharmony_ci DebugUtilsWrapper log{inst}; 5105db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 5115db71995Sopenharmony_ci auto res = env.vulkan_functions.vkGetPhysicalDeviceXlibPresentationSupportKHR(physical_device, 0, nullptr, 0); 5125db71995Sopenharmony_ci ASSERT_EQ(res, VK_FALSE); 5135db71995Sopenharmony_ci ASSERT_TRUE(log.find("ICD for selected physical device does not export vkGetPhysicalDeviceXlibPresentationSupportKHR!")); 5145db71995Sopenharmony_ci} 5155db71995Sopenharmony_ci 5165db71995Sopenharmony_ciTEST(WsiTests, GetPhysicalDeviceXlibPresentICDSupport) { 5175db71995Sopenharmony_ci FrameworkEnvironment env{}; 5185db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 5195db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 5205db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 5215db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 5225db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 5235db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back("physical_device_0"); 5245db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 5255db71995Sopenharmony_ci 5265db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 5275db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 5285db71995Sopenharmony_ci inst.CheckCreate(); 5295db71995Sopenharmony_ci 5305db71995Sopenharmony_ci uint32_t driver_count = 1; 5315db71995Sopenharmony_ci VkPhysicalDevice physical_device; 5325db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device)); 5335db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 5345db71995Sopenharmony_ci 5355db71995Sopenharmony_ci ASSERT_EQ(VK_TRUE, env.vulkan_functions.vkGetPhysicalDeviceXlibPresentationSupportKHR(physical_device, 0, nullptr, 0)); 5365db71995Sopenharmony_ci} 5375db71995Sopenharmony_ci 5385db71995Sopenharmony_ciTEST(WsiTests, XlibGetPhysicalDeviceSurfaceSupportKHR) { 5395db71995Sopenharmony_ci FrameworkEnvironment env{}; 5405db71995Sopenharmony_ci const uint32_t max_device_count = 4; 5415db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_device_count; ++icd) { 5425db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 5435db71995Sopenharmony_ci Extension second_ext{VK_KHR_XLIB_SURFACE_EXTENSION_NAME}; 5445db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 5455db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 5465db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 5475db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 5485db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext}); 5495db71995Sopenharmony_ci std::string dev_name = "phys_dev_" + std::to_string(icd); 5505db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back(dev_name.c_str()); 5515db71995Sopenharmony_ci cur_icd.physical_devices.back().add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true}); 5525db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 5535db71995Sopenharmony_ci } 5545db71995Sopenharmony_ci 5555db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 5565db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME}); 5575db71995Sopenharmony_ci instance.CheckCreate(); 5585db71995Sopenharmony_ci 5595db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 5605db71995Sopenharmony_ci VkXlibSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR}; 5615db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXlibSurfaceKHR(instance.inst, &createInfo, nullptr, &surface)); 5625db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 5635db71995Sopenharmony_ci 5645db71995Sopenharmony_ci uint32_t device_count = max_device_count; 5655db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_device_count> phys_devs; 5665db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumeratePhysicalDevices(instance.inst, &device_count, phys_devs.data())); 5675db71995Sopenharmony_ci ASSERT_EQ(device_count, max_device_count); 5685db71995Sopenharmony_ci 5695db71995Sopenharmony_ci for (uint32_t pd = 0; pd < max_device_count; ++pd) { 5705db71995Sopenharmony_ci VkBool32 supported = VK_FALSE; 5715db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported)); 5725db71995Sopenharmony_ci } 5735db71995Sopenharmony_ci 5745db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr); 5755db71995Sopenharmony_ci} 5765db71995Sopenharmony_ci#endif 5775db71995Sopenharmony_ci 5785db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_WAYLAND_KHR) 5795db71995Sopenharmony_ci// When ICD doesn't support the extension, create instance should fail 5805db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceWaylandNoICDSupport) { 5815db71995Sopenharmony_ci FrameworkEnvironment env{}; 5825db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 5835db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 5845db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 5855db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 5865db71995Sopenharmony_ci 5875db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 5885db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 5895db71995Sopenharmony_ci inst.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT); 5905db71995Sopenharmony_ci 5915db71995Sopenharmony_ci InstWrapper inst2{env.vulkan_functions}; 5925db71995Sopenharmony_ci inst2.CheckCreate(); 5935db71995Sopenharmony_ci 5945db71995Sopenharmony_ci ASSERT_EQ(nullptr, env.vulkan_functions.vkGetInstanceProcAddr(inst2.inst, "vkCreateWaylandSurfaceKHR")); 5955db71995Sopenharmony_ci} 5965db71995Sopenharmony_ci 5975db71995Sopenharmony_ci// When ICD doesn't support the surface creation, the loader should handle it 5985db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceWaylandNoICDCreateSupport) { 5995db71995Sopenharmony_ci FrameworkEnvironment env{}; 6005db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 6015db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 6025db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 6035db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 6045db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 6055db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 6065db71995Sopenharmony_ci 6075db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 6085db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 6095db71995Sopenharmony_ci inst.CheckCreate(); 6105db71995Sopenharmony_ci 6115db71995Sopenharmony_ci VkWaylandSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR}; 6125db71995Sopenharmony_ci 6135db71995Sopenharmony_ci VkSurfaceKHR surface; 6145db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(inst, &createInfo, nullptr, &surface)); 6155db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 6165db71995Sopenharmony_ci 6175db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr); 6185db71995Sopenharmony_ci} 6195db71995Sopenharmony_ci 6205db71995Sopenharmony_ci// When ICD does support the surface creation, the loader should delegat handle it to the ICD 6215db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceWaylandICDSupport) { 6225db71995Sopenharmony_ci FrameworkEnvironment env{}; 6235db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 6245db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 6255db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 6265db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 6275db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 6285db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 6295db71995Sopenharmony_ci 6305db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 6315db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 6325db71995Sopenharmony_ci inst.CheckCreate(); 6335db71995Sopenharmony_ci 6345db71995Sopenharmony_ci VkWaylandSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR}; 6355db71995Sopenharmony_ci 6365db71995Sopenharmony_ci VkSurfaceKHR surface; 6375db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(inst, &createInfo, nullptr, &surface)); 6385db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 6395db71995Sopenharmony_ci 6405db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr); 6415db71995Sopenharmony_ci} 6425db71995Sopenharmony_ci 6435db71995Sopenharmony_ci// Some drivers supporting vkCreateWaylandSurfaceKHR, and at least one that doesn't 6445db71995Sopenharmony_ciTEST(WsiTests, CreateSurfaceWaylandMixedICDSupport) { 6455db71995Sopenharmony_ci FrameworkEnvironment env{}; 6465db71995Sopenharmony_ci for (uint32_t icd = 0; icd < 3; ++icd) { 6475db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 6485db71995Sopenharmony_ci Extension second_ext{VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}; 6495db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 6505db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 6515db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 6525db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext}); 6535db71995Sopenharmony_ci if (icd < 2) { 6545db71995Sopenharmony_ci // Only enable ICD for first two 6555db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 6565db71995Sopenharmony_ci } 6575db71995Sopenharmony_ci } 6585db71995Sopenharmony_ci 6595db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 6605db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 6615db71995Sopenharmony_ci instance.CheckCreate(); 6625db71995Sopenharmony_ci 6635db71995Sopenharmony_ci VkWaylandSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR}; 6645db71995Sopenharmony_ci 6655db71995Sopenharmony_ci VkSurfaceKHR surface; 6665db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(instance.inst, &createInfo, nullptr, &surface)); 6675db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 6685db71995Sopenharmony_ci 6695db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr); 6705db71995Sopenharmony_ci} 6715db71995Sopenharmony_ci 6725db71995Sopenharmony_ciTEST(WsiTests, GetPhysicalDeviceWaylandPresentNoICDSupport) { 6735db71995Sopenharmony_ci FrameworkEnvironment env{}; 6745db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 6755db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 6765db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 6775db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 6785db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 6795db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back("physical_device_0"); 6805db71995Sopenharmony_ci cur_icd.enable_icd_wsi = false; 6815db71995Sopenharmony_ci 6825db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 6835db71995Sopenharmony_ci inst.create_info.add_extensions( 6845db71995Sopenharmony_ci {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME}); 6855db71995Sopenharmony_ci inst.CheckCreate(); 6865db71995Sopenharmony_ci 6875db71995Sopenharmony_ci uint32_t driver_count = 1; 6885db71995Sopenharmony_ci VkPhysicalDevice physical_device; 6895db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device)); 6905db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 6915db71995Sopenharmony_ci 6925db71995Sopenharmony_ci DebugUtilsWrapper log{inst}; 6935db71995Sopenharmony_ci CreateDebugUtilsMessenger(log); 6945db71995Sopenharmony_ci auto res = env.vulkan_functions.vkGetPhysicalDeviceWaylandPresentationSupportKHR(physical_device, 0, nullptr); 6955db71995Sopenharmony_ci ASSERT_EQ(res, VK_FALSE); 6965db71995Sopenharmony_ci ASSERT_TRUE(log.find("ICD for selected physical device does not export vkGetPhysicalDeviceWaylandPresentationSupportKHR!")); 6975db71995Sopenharmony_ci} 6985db71995Sopenharmony_ci 6995db71995Sopenharmony_ciTEST(WsiTests, GetPhysicalDeviceWaylandPresentICDSupport) { 7005db71995Sopenharmony_ci FrameworkEnvironment env{}; 7015db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 7025db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(0); 7035db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 7045db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME}); 7055db71995Sopenharmony_ci cur_icd.add_instance_extension({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 7065db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back("physical_device_0"); 7075db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 7085db71995Sopenharmony_ci 7095db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 7105db71995Sopenharmony_ci inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 7115db71995Sopenharmony_ci inst.CheckCreate(); 7125db71995Sopenharmony_ci 7135db71995Sopenharmony_ci uint32_t driver_count = 1; 7145db71995Sopenharmony_ci VkPhysicalDevice physical_device; 7155db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device)); 7165db71995Sopenharmony_ci ASSERT_EQ(driver_count, 1U); 7175db71995Sopenharmony_ci 7185db71995Sopenharmony_ci ASSERT_EQ(VK_TRUE, env.vulkan_functions.vkGetPhysicalDeviceWaylandPresentationSupportKHR(physical_device, 0, nullptr)); 7195db71995Sopenharmony_ci} 7205db71995Sopenharmony_ci 7215db71995Sopenharmony_ciTEST(WsiTests, WaylandGetPhysicalDeviceSurfaceSupportKHR) { 7225db71995Sopenharmony_ci FrameworkEnvironment env{}; 7235db71995Sopenharmony_ci const uint32_t max_device_count = 4; 7245db71995Sopenharmony_ci for (uint32_t icd = 0; icd < max_device_count; ++icd) { 7255db71995Sopenharmony_ci Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME}; 7265db71995Sopenharmony_ci Extension second_ext{VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}; 7275db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)); 7285db71995Sopenharmony_ci auto& cur_icd = env.get_test_icd(icd); 7295db71995Sopenharmony_ci cur_icd.icd_api_version = VK_API_VERSION_1_0; 7305db71995Sopenharmony_ci cur_icd.set_min_icd_interface_version(5); 7315db71995Sopenharmony_ci cur_icd.add_instance_extensions({first_ext, second_ext}); 7325db71995Sopenharmony_ci std::string dev_name = "phys_dev_" + std::to_string(icd); 7335db71995Sopenharmony_ci cur_icd.physical_devices.emplace_back(dev_name.c_str()); 7345db71995Sopenharmony_ci cur_icd.physical_devices.back().add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true}); 7355db71995Sopenharmony_ci cur_icd.enable_icd_wsi = true; 7365db71995Sopenharmony_ci } 7375db71995Sopenharmony_ci 7385db71995Sopenharmony_ci InstWrapper instance(env.vulkan_functions); 7395db71995Sopenharmony_ci instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME}); 7405db71995Sopenharmony_ci instance.CheckCreate(); 7415db71995Sopenharmony_ci 7425db71995Sopenharmony_ci VkSurfaceKHR surface{VK_NULL_HANDLE}; 7435db71995Sopenharmony_ci VkWaylandSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR}; 7445db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(instance.inst, &createInfo, nullptr, &surface)); 7455db71995Sopenharmony_ci ASSERT_TRUE(surface != VK_NULL_HANDLE); 7465db71995Sopenharmony_ci 7475db71995Sopenharmony_ci uint32_t device_count = max_device_count; 7485db71995Sopenharmony_ci std::array<VkPhysicalDevice, max_device_count> phys_devs; 7495db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumeratePhysicalDevices(instance.inst, &device_count, phys_devs.data())); 7505db71995Sopenharmony_ci ASSERT_EQ(device_count, max_device_count); 7515db71995Sopenharmony_ci 7525db71995Sopenharmony_ci for (uint32_t pd = 0; pd < max_device_count; ++pd) { 7535db71995Sopenharmony_ci VkBool32 supported = VK_FALSE; 7545db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported)); 7555db71995Sopenharmony_ci } 7565db71995Sopenharmony_ci 7575db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr); 7585db71995Sopenharmony_ci} 7595db71995Sopenharmony_ci#endif 7605db71995Sopenharmony_ci 7615db71995Sopenharmony_ciTEST(WsiTests, ForgetEnableSurfaceExtensions) { 7625db71995Sopenharmony_ci FrameworkEnvironment env{}; 7635db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)) 7645db71995Sopenharmony_ci .setup_WSI() 7655db71995Sopenharmony_ci .add_physical_device(PhysicalDevice{}.add_extension("VK_KHR_swapchain").finish()); 7665db71995Sopenharmony_ci 7675db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 7685db71995Sopenharmony_ci inst.create_info.add_extension("VK_KHR_surface"); 7695db71995Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(inst.CheckCreate()); 7705db71995Sopenharmony_ci 7715db71995Sopenharmony_ci VkSurfaceKHR surface{}; 7725db71995Sopenharmony_ci ASSERT_EQ(VK_ERROR_EXTENSION_NOT_PRESENT, create_surface(inst, surface)); 7735db71995Sopenharmony_ci} 7745db71995Sopenharmony_ci 7755db71995Sopenharmony_ciTEST(WsiTests, SwapchainFunctional) { 7765db71995Sopenharmony_ci FrameworkEnvironment env{}; 7775db71995Sopenharmony_ci env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)) 7785db71995Sopenharmony_ci .setup_WSI() 7795db71995Sopenharmony_ci .add_physical_device(PhysicalDevice{}.add_extension("VK_KHR_swapchain").finish()); 7805db71995Sopenharmony_ci 7815db71995Sopenharmony_ci InstWrapper inst{env.vulkan_functions}; 7825db71995Sopenharmony_ci inst.create_info.setup_WSI(); 7835db71995Sopenharmony_ci inst.CheckCreate(); 7845db71995Sopenharmony_ci VkSurfaceKHR surface{}; 7855db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, create_surface(inst, surface)); 7865db71995Sopenharmony_ci VkPhysicalDevice phys_dev = inst.GetPhysDev(); 7875db71995Sopenharmony_ci 7885db71995Sopenharmony_ci { // Use GDPA to get functions 7895db71995Sopenharmony_ci DeviceWrapper dev{inst}; 7905db71995Sopenharmony_ci dev.create_info.add_extension("VK_KHR_swapchain"); 7915db71995Sopenharmony_ci 7925db71995Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(dev.CheckCreate(phys_dev)); 7935db71995Sopenharmony_ci 7945db71995Sopenharmony_ci VkSwapchainKHR swapchain{}; 7955db71995Sopenharmony_ci VkSwapchainCreateInfoKHR swap_create_info{}; 7965db71995Sopenharmony_ci swap_create_info.surface = surface; 7975db71995Sopenharmony_ci DeviceFunctions funcs{*inst.functions, dev}; 7985db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, funcs.vkCreateSwapchainKHR(dev, &swap_create_info, nullptr, &swapchain)); 7995db71995Sopenharmony_ci uint32_t count = 0; 8005db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, funcs.vkGetSwapchainImagesKHR(dev, swapchain, &count, nullptr)); 8015db71995Sopenharmony_ci ASSERT_GT(count, 0U); 8025db71995Sopenharmony_ci std::array<VkImage, 16> images; 8035db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, funcs.vkGetSwapchainImagesKHR(dev, swapchain, &count, images.data())); 8045db71995Sopenharmony_ci funcs.vkDestroySwapchainKHR(dev, swapchain, nullptr); 8055db71995Sopenharmony_ci } 8065db71995Sopenharmony_ci { // Use GIPA gotten functions 8075db71995Sopenharmony_ci DeviceWrapper dev{inst}; 8085db71995Sopenharmony_ci dev.create_info.add_extension("VK_KHR_swapchain"); 8095db71995Sopenharmony_ci 8105db71995Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(dev.CheckCreate(phys_dev)); 8115db71995Sopenharmony_ci 8125db71995Sopenharmony_ci PFN_vkCreateSwapchainKHR inst_CreateSwapchainKHR = inst.load("vkCreateSwapchainKHR"); 8135db71995Sopenharmony_ci PFN_vkGetSwapchainImagesKHR inst_GetSwapchainImagesKHR = inst.load("vkGetSwapchainImagesKHR"); 8145db71995Sopenharmony_ci PFN_vkDestroySwapchainKHR inst_DestroySwapchainKHR = inst.load("vkDestroySwapchainKHR"); 8155db71995Sopenharmony_ci ASSERT_TRUE(nullptr != inst_CreateSwapchainKHR); 8165db71995Sopenharmony_ci ASSERT_TRUE(nullptr != inst_GetSwapchainImagesKHR); 8175db71995Sopenharmony_ci ASSERT_TRUE(nullptr != inst_DestroySwapchainKHR); 8185db71995Sopenharmony_ci 8195db71995Sopenharmony_ci VkSwapchainKHR swapchain{}; 8205db71995Sopenharmony_ci VkSwapchainCreateInfoKHR swap_create_info{}; 8215db71995Sopenharmony_ci swap_create_info.surface = surface; 8225db71995Sopenharmony_ci 8235db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst_CreateSwapchainKHR(dev, &swap_create_info, nullptr, &swapchain)); 8245db71995Sopenharmony_ci uint32_t count = 0; 8255db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst_GetSwapchainImagesKHR(dev, swapchain, &count, nullptr)); 8265db71995Sopenharmony_ci ASSERT_GT(count, 0U); 8275db71995Sopenharmony_ci std::array<VkImage, 16> images; 8285db71995Sopenharmony_ci ASSERT_EQ(VK_SUCCESS, inst_GetSwapchainImagesKHR(dev, swapchain, &count, images.data())); 8295db71995Sopenharmony_ci inst_DestroySwapchainKHR(dev, swapchain, nullptr); 8305db71995Sopenharmony_ci } 8315db71995Sopenharmony_ci { // forget to enable the extension 8325db71995Sopenharmony_ci DeviceWrapper dev{inst}; 8335db71995Sopenharmony_ci ASSERT_NO_FATAL_FAILURE(dev.CheckCreate(phys_dev)); 8345db71995Sopenharmony_ci 8355db71995Sopenharmony_ci DeviceFunctions funcs{*inst.functions, dev}; 8365db71995Sopenharmony_ci ASSERT_EQ(funcs.vkCreateSwapchainKHR, nullptr); 8375db71995Sopenharmony_ci ASSERT_EQ(funcs.vkGetSwapchainImagesKHR, nullptr); 8385db71995Sopenharmony_ci ASSERT_EQ(funcs.vkDestroySwapchainKHR, nullptr); 8395db71995Sopenharmony_ci } 8405db71995Sopenharmony_ci { // forget to set the surface 8415db71995Sopenharmony_ci DeviceWrapper dev{inst}; 8425db71995Sopenharmony_ci dev.create_info.add_extension("VK_KHR_swapchain"); 8435db71995Sopenharmony_ci 8445db71995Sopenharmony_ci dev.CheckCreate(phys_dev); 8455db71995Sopenharmony_ci 8465db71995Sopenharmony_ci VkSwapchainKHR swapchain{}; 8475db71995Sopenharmony_ci VkSwapchainCreateInfoKHR swap_create_info{}; 8485db71995Sopenharmony_ci DeviceFunctions funcs{*inst.functions, dev}; 8495db71995Sopenharmony_ci ASSERT_DEATH(funcs.vkCreateSwapchainKHR(dev, &swap_create_info, nullptr, &swapchain), ""); 8505db71995Sopenharmony_ci } 8515db71995Sopenharmony_ci env.vulkan_functions.vkDestroySurfaceKHR(inst.inst, surface, nullptr); 8525db71995Sopenharmony_ci} 853