1 /*
2 * Copyright (c) 2021-2022 The Khronos Group Inc.
3 * Copyright (c) 2021-2022 Valve Corporation
4 * Copyright (c) 2021-2022 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials are
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice(s) and this permission notice shall be included in
14 * all copies or substantial portions of the Materials.
15 *
16 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 *
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23 * USE OR OTHER DEALINGS IN THE MATERIALS.
24 *
25 * Author: Charles Giessen <charles@lunarg.com>
26 */
27
28 #include "test_environment.h"
29
30 class WsiTests : public ::testing::Test {};
31
32 #if defined(VK_USE_PLATFORM_WIN32_KHR)
33
34 // When ICD doesn't support the extension, create instance should fail
TEST(WsiTests,CreateSurfaceWin32NoICDSupport)35 TEST(WsiTests, CreateSurfaceWin32NoICDSupport) {
36 FrameworkEnvironment env{};
37 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
38 auto& cur_icd = env.get_test_icd(0);
39 cur_icd.set_min_icd_interface_version(5);
40 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
41
42 InstWrapper inst{env.vulkan_functions};
43 inst.create_info.add_extensions({VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
44 inst.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT);
45
46 InstWrapper inst2{env.vulkan_functions};
47 inst2.CheckCreate();
48
49 ASSERT_EQ(nullptr, env.vulkan_functions.vkGetInstanceProcAddr(inst2.inst, "vkCreateWin32SurfaceKHR"));
50 }
51
52 // When ICD doesn't support the surface creation, the loader should handle it
TEST(WsiTests,CreateSurfaceWin32NoICDCreateSupport)53 TEST(WsiTests, CreateSurfaceWin32NoICDCreateSupport) {
54 FrameworkEnvironment env{};
55 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
56 auto& cur_icd = env.get_test_icd(0);
57 cur_icd.set_min_icd_interface_version(5);
58 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
59 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
60 cur_icd.add_instance_extension({VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
61 cur_icd.enable_icd_wsi = false;
62
63 InstWrapper inst{env.vulkan_functions};
64 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
65 inst.CheckCreate();
66
67 VkSurfaceKHR surface{VK_NULL_HANDLE};
68 VkWin32SurfaceCreateInfoKHR surf_create_info{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
69 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWin32SurfaceKHR(inst, &surf_create_info, nullptr, &surface));
70 ASSERT_TRUE(surface != VK_NULL_HANDLE);
71 // ASSERT_EQ(cur_icd.is_using_icd_wsi, UsingICDProvidedWSI::not_using);
72
73 env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr);
74 }
75
76 // When ICD does support the surface creation, the loader should delegat handle it to the ICD
TEST(WsiTests,CreateSurfaceWin32ICDSupport)77 TEST(WsiTests, CreateSurfaceWin32ICDSupport) {
78 FrameworkEnvironment env{};
79 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
80 auto& cur_icd = env.get_test_icd(0);
81 cur_icd.set_min_icd_interface_version(5);
82 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
83 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
84 cur_icd.add_instance_extension({VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
85 cur_icd.enable_icd_wsi = true;
86
87 InstWrapper inst{env.vulkan_functions};
88 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
89 inst.CheckCreate();
90
91 VkSurfaceKHR surface{VK_NULL_HANDLE};
92 VkWin32SurfaceCreateInfoKHR surf_create_info{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
93 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWin32SurfaceKHR(inst, &surf_create_info, nullptr, &surface));
94 ASSERT_TRUE(surface != VK_NULL_HANDLE);
95 // ASSERT_EQ(cur_icd.is_using_icd_wsi, UsingICDProvidedWSI::not_using);
96
97 env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr);
98 }
99
100 // Some drivers supporting vkCreateWin32SurfaceKHR, and at least one that doesn't
TEST(WsiTests,CreateSurfaceWin32MixedICDSupport)101 TEST(WsiTests, CreateSurfaceWin32MixedICDSupport) {
102 FrameworkEnvironment env{};
103 for (uint32_t icd = 0; icd < 3; ++icd) {
104 Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
105 Extension second_ext{VK_KHR_WIN32_SURFACE_EXTENSION_NAME};
106 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
107 auto& cur_icd = env.get_test_icd(icd);
108 cur_icd.icd_api_version = VK_API_VERSION_1_0;
109 cur_icd.add_instance_extensions({first_ext, second_ext});
110 if (icd < 2) {
111 // Only enable ICD for first two
112 cur_icd.enable_icd_wsi = true;
113 }
114 }
115
116 InstWrapper instance(env.vulkan_functions);
117 instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
118 instance.CheckCreate();
119
120 VkSurfaceKHR surface{VK_NULL_HANDLE};
121 VkWin32SurfaceCreateInfoKHR surf_create_info{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
122 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWin32SurfaceKHR(instance.inst, &surf_create_info, nullptr, &surface));
123 ASSERT_TRUE(surface != VK_NULL_HANDLE);
124 // ASSERT_EQ(cur_icd.is_using_icd_wsi, UsingICDProvidedWSI::not_using);
125
126 env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
127 }
128
TEST(WsiTests,GetPhysicalDeviceWin32PresentNoICDSupport)129 TEST(WsiTests, GetPhysicalDeviceWin32PresentNoICDSupport) {
130 FrameworkEnvironment env{};
131 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
132 auto& cur_icd = env.get_test_icd(0);
133 cur_icd.set_min_icd_interface_version(5);
134 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
135 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
136 cur_icd.add_instance_extension({VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
137 cur_icd.physical_devices.emplace_back("physical_device_0");
138 cur_icd.enable_icd_wsi = false;
139
140 InstWrapper inst{env.vulkan_functions};
141 inst.create_info.add_extensions(
142 {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME});
143 inst.CheckCreate();
144
145 uint32_t driver_count = 1;
146 VkPhysicalDevice physical_device;
147 ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device));
148 ASSERT_EQ(driver_count, 1U);
149
150 DebugUtilsWrapper log{inst};
151 CreateDebugUtilsMessenger(log);
152 auto res = env.vulkan_functions.vkGetPhysicalDeviceWin32PresentationSupportKHR(physical_device, 0);
153 ASSERT_EQ(res, VK_FALSE);
154 ASSERT_TRUE(log.find("ICD for selected physical device does not export vkGetPhysicalDeviceWin32PresentationSupportKHR!"));
155 }
156
TEST(WsiTests,GetPhysicalDeviceWin32PresentICDSupport)157 TEST(WsiTests, GetPhysicalDeviceWin32PresentICDSupport) {
158 FrameworkEnvironment env{};
159 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
160 auto& cur_icd = env.get_test_icd(0);
161 cur_icd.set_min_icd_interface_version(5);
162 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
163 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
164 cur_icd.add_instance_extension({VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
165 cur_icd.physical_devices.emplace_back("physical_device_0");
166 cur_icd.enable_icd_wsi = true;
167
168 InstWrapper inst{env.vulkan_functions};
169 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
170 inst.CheckCreate();
171
172 uint32_t driver_count = 1;
173 VkPhysicalDevice physical_device;
174 ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device));
175 ASSERT_EQ(driver_count, 1U);
176
177 ASSERT_EQ(VK_TRUE, env.vulkan_functions.vkGetPhysicalDeviceWin32PresentationSupportKHR(physical_device, 0));
178 }
179
TEST(WsiTests,Win32GetPhysicalDeviceSurfaceSupportKHR)180 TEST(WsiTests, Win32GetPhysicalDeviceSurfaceSupportKHR) {
181 FrameworkEnvironment env{};
182 const uint32_t max_device_count = 4;
183 for (uint32_t icd = 0; icd < max_device_count; ++icd) {
184 Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
185 Extension second_ext{VK_KHR_WIN32_SURFACE_EXTENSION_NAME};
186 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
187 auto& cur_icd = env.get_test_icd(icd);
188 cur_icd.icd_api_version = VK_API_VERSION_1_0;
189 cur_icd.set_min_icd_interface_version(5);
190 cur_icd.add_instance_extensions({first_ext, second_ext});
191 std::string dev_name = "phys_dev_" + std::to_string(icd);
192 cur_icd.physical_devices.emplace_back(dev_name.c_str());
193 cur_icd.physical_devices.back().add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true});
194 cur_icd.enable_icd_wsi = true;
195 }
196
197 InstWrapper instance(env.vulkan_functions);
198 instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME});
199 instance.CheckCreate();
200
201 VkSurfaceKHR surface{VK_NULL_HANDLE};
202 VkWin32SurfaceCreateInfoKHR surf_create_info{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
203 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWin32SurfaceKHR(instance.inst, &surf_create_info, nullptr, &surface));
204 ASSERT_TRUE(surface != VK_NULL_HANDLE);
205 // ASSERT_EQ(driver.is_using_icd_wsi, UsingICDProvidedWSI::not_using);
206
207 uint32_t device_count = max_device_count;
208 std::array<VkPhysicalDevice, max_device_count> phys_devs;
209 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumeratePhysicalDevices(instance.inst, &device_count, phys_devs.data()));
210 ASSERT_EQ(device_count, max_device_count);
211
212 for (uint32_t pd = 0; pd < max_device_count; ++pd) {
213 VkBool32 supported = VK_FALSE;
214 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported));
215 }
216
217 env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
218 }
219 #endif
220
221 #if defined(VK_USE_PLATFORM_XCB_KHR)
222 // When ICD doesn't support the extension, create instance should fail
TEST(WsiTests,CreateSurfaceXCBNoICDSupport)223 TEST(WsiTests, CreateSurfaceXCBNoICDSupport) {
224 FrameworkEnvironment env{};
225 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
226 auto& cur_icd = env.get_test_icd(0);
227 cur_icd.set_min_icd_interface_version(5);
228 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
229 cur_icd.enable_icd_wsi = false;
230
231 InstWrapper inst{env.vulkan_functions};
232 inst.create_info.add_extensions({VK_KHR_XCB_SURFACE_EXTENSION_NAME});
233 inst.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT);
234
235 InstWrapper inst2{env.vulkan_functions};
236 inst2.CheckCreate();
237
238 ASSERT_EQ(nullptr, env.vulkan_functions.vkGetInstanceProcAddr(inst2.inst, "vkCreateXcbSurfaceKHR"));
239 }
240
241 // When ICD doesn't support the surface creation, the loader should handle it
TEST(WsiTests,CreateSurfaceXCBNoICDCreateSupport)242 TEST(WsiTests, CreateSurfaceXCBNoICDCreateSupport) {
243 FrameworkEnvironment env{};
244 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
245 auto& cur_icd = env.get_test_icd(0);
246 cur_icd.set_min_icd_interface_version(5);
247 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
248 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
249 cur_icd.add_instance_extension({VK_KHR_XCB_SURFACE_EXTENSION_NAME});
250 cur_icd.enable_icd_wsi = false;
251
252 InstWrapper inst{env.vulkan_functions};
253 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME});
254 inst.CheckCreate();
255
256 VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
257
258 VkSurfaceKHR surface{VK_NULL_HANDLE};
259 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(inst, &xcb_createInfo, nullptr, &surface));
260 ASSERT_TRUE(surface != VK_NULL_HANDLE);
261
262 env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr);
263 }
264
265 // When ICD does support the surface creation, the loader should delegat handle it to the ICD
TEST(WsiTests,CreateSurfaceXCBICDSupport)266 TEST(WsiTests, CreateSurfaceXCBICDSupport) {
267 FrameworkEnvironment env{};
268 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
269 auto& cur_icd = env.get_test_icd(0);
270 cur_icd.set_min_icd_interface_version(5);
271 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
272 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
273 cur_icd.add_instance_extension({VK_KHR_XCB_SURFACE_EXTENSION_NAME});
274 cur_icd.enable_icd_wsi = true;
275
276 InstWrapper inst{env.vulkan_functions};
277 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME});
278 inst.CheckCreate();
279
280 VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
281
282 VkSurfaceKHR surface{VK_NULL_HANDLE};
283 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(inst, &xcb_createInfo, nullptr, &surface));
284 ASSERT_TRUE(surface != VK_NULL_HANDLE);
285
286 env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr);
287 }
288
289 // Some drivers supporting vkCreateXcbSurfaceKHR, and at least one that doesn't
TEST(WsiTests,CreateSurfaceXCBMixedICDSupport)290 TEST(WsiTests, CreateSurfaceXCBMixedICDSupport) {
291 FrameworkEnvironment env{};
292 for (uint32_t icd = 0; icd < 3; ++icd) {
293 Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
294 Extension second_ext{VK_KHR_XCB_SURFACE_EXTENSION_NAME};
295 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
296 auto& cur_icd = env.get_test_icd(icd);
297 cur_icd.icd_api_version = VK_API_VERSION_1_0;
298 cur_icd.add_instance_extensions({first_ext, second_ext});
299 if (icd < 2) {
300 // Only enable ICD for first two
301 cur_icd.enable_icd_wsi = true;
302 }
303 }
304
305 InstWrapper instance(env.vulkan_functions);
306 instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME});
307 instance.CheckCreate();
308
309 VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
310
311 VkSurfaceKHR surface{VK_NULL_HANDLE};
312 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(instance.inst, &xcb_createInfo, nullptr, &surface));
313 ASSERT_TRUE(surface != VK_NULL_HANDLE);
314
315 env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
316 }
317
TEST(WsiTests,GetPhysicalDeviceXcbPresentNoICDSupport)318 TEST(WsiTests, GetPhysicalDeviceXcbPresentNoICDSupport) {
319 FrameworkEnvironment env{};
320 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
321 auto& cur_icd = env.get_test_icd(0);
322 cur_icd.set_min_icd_interface_version(5);
323 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
324 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
325 cur_icd.add_instance_extension({VK_KHR_XCB_SURFACE_EXTENSION_NAME});
326 cur_icd.physical_devices.emplace_back("physical_device_0");
327 cur_icd.enable_icd_wsi = false;
328
329 InstWrapper inst{env.vulkan_functions};
330 inst.create_info.add_extensions(
331 {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME});
332 inst.CheckCreate();
333
334 uint32_t driver_count = 1;
335 VkPhysicalDevice physical_device;
336 ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device));
337 ASSERT_EQ(driver_count, 1U);
338
339 DebugUtilsWrapper log{inst};
340 CreateDebugUtilsMessenger(log);
341 auto res = env.vulkan_functions.vkGetPhysicalDeviceXcbPresentationSupportKHR(physical_device, 0, nullptr, 0);
342 ASSERT_EQ(res, VK_FALSE);
343 ASSERT_TRUE(log.find("ICD for selected physical device does not export vkGetPhysicalDeviceXcbPresentationSupportKHR!"));
344 }
345
TEST(WsiTests,GetPhysicalDeviceXcbPresentICDSupport)346 TEST(WsiTests, GetPhysicalDeviceXcbPresentICDSupport) {
347 FrameworkEnvironment env{};
348 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
349 auto& cur_icd = env.get_test_icd(0);
350 cur_icd.set_min_icd_interface_version(5);
351 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
352 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
353 cur_icd.add_instance_extension({VK_KHR_XCB_SURFACE_EXTENSION_NAME});
354 cur_icd.physical_devices.emplace_back("physical_device_0");
355 cur_icd.enable_icd_wsi = true;
356
357 InstWrapper inst{env.vulkan_functions};
358 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME});
359 inst.CheckCreate();
360
361 uint32_t driver_count = 1;
362 VkPhysicalDevice physical_device;
363 ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device));
364 ASSERT_EQ(driver_count, 1U);
365
366 ASSERT_EQ(VK_TRUE, env.vulkan_functions.vkGetPhysicalDeviceXcbPresentationSupportKHR(physical_device, 0, nullptr, 0));
367 }
368
TEST(WsiTests,XcbGetPhysicalDeviceSurfaceSupportKHR)369 TEST(WsiTests, XcbGetPhysicalDeviceSurfaceSupportKHR) {
370 FrameworkEnvironment env{};
371 const uint32_t max_device_count = 4;
372 for (uint32_t icd = 0; icd < max_device_count; ++icd) {
373 Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
374 Extension second_ext{VK_KHR_XCB_SURFACE_EXTENSION_NAME};
375 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
376 auto& cur_icd = env.get_test_icd(icd);
377 cur_icd.icd_api_version = VK_API_VERSION_1_0;
378 cur_icd.set_min_icd_interface_version(5);
379 cur_icd.add_instance_extensions({first_ext, second_ext});
380 std::string dev_name = "phys_dev_" + std::to_string(icd);
381 cur_icd.physical_devices.emplace_back(dev_name.c_str());
382 cur_icd.physical_devices.back().add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true});
383 cur_icd.enable_icd_wsi = true;
384 }
385
386 InstWrapper instance(env.vulkan_functions);
387 instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME});
388 instance.CheckCreate();
389
390 VkSurfaceKHR surface{VK_NULL_HANDLE};
391 VkXcbSurfaceCreateInfoKHR xcb_createInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
392 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXcbSurfaceKHR(instance.inst, &xcb_createInfo, nullptr, &surface));
393 ASSERT_TRUE(surface != VK_NULL_HANDLE);
394 // ASSERT_EQ(cur_icd.is_using_icd_wsi, UsingICDProvidedWSI::not_using);
395
396 uint32_t device_count = max_device_count;
397 std::array<VkPhysicalDevice, max_device_count> phys_devs;
398 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumeratePhysicalDevices(instance.inst, &device_count, phys_devs.data()));
399 ASSERT_EQ(device_count, max_device_count);
400
401 for (uint32_t pd = 0; pd < max_device_count; ++pd) {
402 VkBool32 supported = VK_FALSE;
403 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported));
404 }
405
406 env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
407 }
408 #endif
409
410 #if defined(VK_USE_PLATFORM_XLIB_KHR)
411 // When ICD doesn't support the extension, create instance should fail
TEST(WsiTests,CreateSurfaceXLIBNoICDSupport)412 TEST(WsiTests, CreateSurfaceXLIBNoICDSupport) {
413 FrameworkEnvironment env{};
414 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
415 auto& cur_icd = env.get_test_icd(0);
416 cur_icd.set_min_icd_interface_version(5);
417 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
418 cur_icd.enable_icd_wsi = false;
419
420 InstWrapper inst{env.vulkan_functions};
421 inst.create_info.add_extensions({VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
422 inst.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT);
423
424 InstWrapper inst2{env.vulkan_functions};
425 inst2.CheckCreate();
426
427 ASSERT_EQ(nullptr, env.vulkan_functions.vkGetInstanceProcAddr(inst2.inst, "vkCreateXlibSurfaceKHR"));
428 }
429
430 // When ICD doesn't support the surface creation, the loader should handle it
TEST(WsiTests,CreateSurfaceXLIBNoICDCreateSupport)431 TEST(WsiTests, CreateSurfaceXLIBNoICDCreateSupport) {
432 FrameworkEnvironment env{};
433 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
434 auto& cur_icd = env.get_test_icd(0);
435 cur_icd.set_min_icd_interface_version(5);
436 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
437 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
438 cur_icd.add_instance_extension({VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
439 cur_icd.enable_icd_wsi = false;
440
441 InstWrapper inst{env.vulkan_functions};
442 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
443 inst.CheckCreate();
444
445 VkXlibSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
446
447 VkSurfaceKHR surface;
448 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXlibSurfaceKHR(inst, &createInfo, nullptr, &surface));
449 ASSERT_TRUE(surface != VK_NULL_HANDLE);
450
451 env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr);
452 }
453
454 // When ICD does support the surface creation, the loader should delegat handle it to the ICD
TEST(WsiTests,CreateSurfaceXLIBICDSupport)455 TEST(WsiTests, CreateSurfaceXLIBICDSupport) {
456 FrameworkEnvironment env{};
457 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
458 auto& cur_icd = env.get_test_icd(0);
459 cur_icd.set_min_icd_interface_version(5);
460 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
461 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
462 cur_icd.add_instance_extension({VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
463 cur_icd.enable_icd_wsi = true;
464
465 InstWrapper inst{env.vulkan_functions};
466 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
467 inst.CheckCreate();
468
469 VkXlibSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
470
471 VkSurfaceKHR surface;
472 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXlibSurfaceKHR(inst, &createInfo, nullptr, &surface));
473 ASSERT_TRUE(surface != VK_NULL_HANDLE);
474
475 env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr);
476 }
477
478 // Some drivers supporting vkCreateXlibSurfaceKHR, and at least one that doesn't
TEST(WsiTests,CreateSurfaceXLIBMixedICDSupport)479 TEST(WsiTests, CreateSurfaceXLIBMixedICDSupport) {
480 FrameworkEnvironment env{};
481 for (uint32_t icd = 0; icd < 3; ++icd) {
482 Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
483 Extension second_ext{VK_KHR_XLIB_SURFACE_EXTENSION_NAME};
484 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
485 auto& cur_icd = env.get_test_icd(icd);
486 cur_icd.icd_api_version = VK_API_VERSION_1_0;
487 cur_icd.add_instance_extensions({first_ext, second_ext});
488 if (icd < 2) {
489 // Only enable ICD for first two
490 cur_icd.enable_icd_wsi = true;
491 }
492 }
493
494 InstWrapper instance(env.vulkan_functions);
495 instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
496 instance.CheckCreate();
497
498 VkXlibSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
499
500 VkSurfaceKHR surface;
501 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXlibSurfaceKHR(instance.inst, &createInfo, nullptr, &surface));
502 ASSERT_TRUE(surface != VK_NULL_HANDLE);
503
504 env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
505 }
506
TEST(WsiTests,GetPhysicalDeviceXlibPresentNoICDSupport)507 TEST(WsiTests, GetPhysicalDeviceXlibPresentNoICDSupport) {
508 FrameworkEnvironment env{};
509 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
510 auto& cur_icd = env.get_test_icd(0);
511 cur_icd.set_min_icd_interface_version(5);
512 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
513 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
514 cur_icd.add_instance_extension({VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
515 cur_icd.physical_devices.emplace_back("physical_device_0");
516 cur_icd.enable_icd_wsi = false;
517
518 InstWrapper inst{env.vulkan_functions};
519 inst.create_info.add_extensions(
520 {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME});
521 inst.CheckCreate();
522
523 uint32_t driver_count = 1;
524 VkPhysicalDevice physical_device;
525 ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device));
526 ASSERT_EQ(driver_count, 1U);
527
528 DebugUtilsWrapper log{inst};
529 CreateDebugUtilsMessenger(log);
530 auto res = env.vulkan_functions.vkGetPhysicalDeviceXlibPresentationSupportKHR(physical_device, 0, nullptr, 0);
531 ASSERT_EQ(res, VK_FALSE);
532 ASSERT_TRUE(log.find("ICD for selected physical device does not export vkGetPhysicalDeviceXlibPresentationSupportKHR!"));
533 }
534
TEST(WsiTests,GetPhysicalDeviceXlibPresentICDSupport)535 TEST(WsiTests, GetPhysicalDeviceXlibPresentICDSupport) {
536 FrameworkEnvironment env{};
537 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
538 auto& cur_icd = env.get_test_icd(0);
539 cur_icd.set_min_icd_interface_version(5);
540 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
541 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
542 cur_icd.add_instance_extension({VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
543 cur_icd.physical_devices.emplace_back("physical_device_0");
544 cur_icd.enable_icd_wsi = true;
545
546 InstWrapper inst{env.vulkan_functions};
547 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
548 inst.CheckCreate();
549
550 uint32_t driver_count = 1;
551 VkPhysicalDevice physical_device;
552 ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device));
553 ASSERT_EQ(driver_count, 1U);
554
555 ASSERT_EQ(VK_TRUE, env.vulkan_functions.vkGetPhysicalDeviceXlibPresentationSupportKHR(physical_device, 0, nullptr, 0));
556 }
557
TEST(WsiTests,XlibGetPhysicalDeviceSurfaceSupportKHR)558 TEST(WsiTests, XlibGetPhysicalDeviceSurfaceSupportKHR) {
559 FrameworkEnvironment env{};
560 const uint32_t max_device_count = 4;
561 for (uint32_t icd = 0; icd < max_device_count; ++icd) {
562 Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
563 Extension second_ext{VK_KHR_XLIB_SURFACE_EXTENSION_NAME};
564 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
565 auto& cur_icd = env.get_test_icd(icd);
566 cur_icd.icd_api_version = VK_API_VERSION_1_0;
567 cur_icd.set_min_icd_interface_version(5);
568 cur_icd.add_instance_extensions({first_ext, second_ext});
569 std::string dev_name = "phys_dev_" + std::to_string(icd);
570 cur_icd.physical_devices.emplace_back(dev_name.c_str());
571 cur_icd.physical_devices.back().add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true});
572 cur_icd.enable_icd_wsi = true;
573 }
574
575 InstWrapper instance(env.vulkan_functions);
576 instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME});
577 instance.CheckCreate();
578
579 VkSurfaceKHR surface{VK_NULL_HANDLE};
580 VkXlibSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
581 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateXlibSurfaceKHR(instance.inst, &createInfo, nullptr, &surface));
582 ASSERT_TRUE(surface != VK_NULL_HANDLE);
583 // ASSERT_EQ(driver.is_using_icd_wsi, UsingICDProvidedWSI::not_using);
584
585 uint32_t device_count = max_device_count;
586 std::array<VkPhysicalDevice, max_device_count> phys_devs;
587 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumeratePhysicalDevices(instance.inst, &device_count, phys_devs.data()));
588 ASSERT_EQ(device_count, max_device_count);
589
590 for (uint32_t pd = 0; pd < max_device_count; ++pd) {
591 VkBool32 supported = VK_FALSE;
592 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported));
593 }
594
595 env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
596 }
597 #endif
598
599 #if defined(VK_USE_PLATFORM_WAYLAND_KHR)
600 // When ICD doesn't support the extension, create instance should fail
TEST(WsiTests,CreateSurfaceWaylandNoICDSupport)601 TEST(WsiTests, CreateSurfaceWaylandNoICDSupport) {
602 FrameworkEnvironment env{};
603 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
604 auto& cur_icd = env.get_test_icd(0);
605 cur_icd.set_min_icd_interface_version(5);
606 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
607 cur_icd.enable_icd_wsi = false;
608
609 InstWrapper inst{env.vulkan_functions};
610 inst.create_info.add_extensions({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
611 inst.CheckCreate(VK_ERROR_EXTENSION_NOT_PRESENT);
612
613 InstWrapper inst2{env.vulkan_functions};
614 inst2.CheckCreate();
615
616 ASSERT_EQ(nullptr, env.vulkan_functions.vkGetInstanceProcAddr(inst2.inst, "vkCreateWaylandSurfaceKHR"));
617 }
618
619 // When ICD doesn't support the surface creation, the loader should handle it
TEST(WsiTests,CreateSurfaceWaylandNoICDCreateSupport)620 TEST(WsiTests, CreateSurfaceWaylandNoICDCreateSupport) {
621 FrameworkEnvironment env{};
622 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
623 auto& cur_icd = env.get_test_icd(0);
624 cur_icd.set_min_icd_interface_version(5);
625 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
626 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
627 cur_icd.add_instance_extension({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
628 cur_icd.enable_icd_wsi = false;
629
630 InstWrapper inst{env.vulkan_functions};
631 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
632 inst.CheckCreate();
633
634 VkWaylandSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
635
636 VkSurfaceKHR surface;
637 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(inst, &createInfo, nullptr, &surface));
638 ASSERT_TRUE(surface != VK_NULL_HANDLE);
639
640 env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr);
641 }
642
643 // When ICD does support the surface creation, the loader should delegat handle it to the ICD
TEST(WsiTests,CreateSurfaceWaylandICDSupport)644 TEST(WsiTests, CreateSurfaceWaylandICDSupport) {
645 FrameworkEnvironment env{};
646 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
647 auto& cur_icd = env.get_test_icd(0);
648 cur_icd.set_min_icd_interface_version(5);
649 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
650 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
651 cur_icd.add_instance_extension({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
652 cur_icd.enable_icd_wsi = true;
653
654 InstWrapper inst{env.vulkan_functions};
655 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
656 inst.CheckCreate();
657
658 VkWaylandSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
659
660 VkSurfaceKHR surface;
661 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(inst, &createInfo, nullptr, &surface));
662 ASSERT_TRUE(surface != VK_NULL_HANDLE);
663
664 env.vulkan_functions.vkDestroySurfaceKHR(inst, surface, nullptr);
665 }
666
667 // Some drivers supporting vkCreateWaylandSurfaceKHR, and at least one that doesn't
TEST(WsiTests,CreateSurfaceWaylandMixedICDSupport)668 TEST(WsiTests, CreateSurfaceWaylandMixedICDSupport) {
669 FrameworkEnvironment env{};
670 for (uint32_t icd = 0; icd < 3; ++icd) {
671 Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
672 Extension second_ext{VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME};
673 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
674 auto& cur_icd = env.get_test_icd(icd);
675 cur_icd.icd_api_version = VK_API_VERSION_1_0;
676 cur_icd.add_instance_extensions({first_ext, second_ext});
677 if (icd < 2) {
678 // Only enable ICD for first two
679 cur_icd.enable_icd_wsi = true;
680 }
681 }
682
683 InstWrapper instance(env.vulkan_functions);
684 instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
685 instance.CheckCreate();
686
687 VkWaylandSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
688
689 VkSurfaceKHR surface;
690 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(instance.inst, &createInfo, nullptr, &surface));
691 ASSERT_TRUE(surface != VK_NULL_HANDLE);
692
693 env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
694 }
695
TEST(WsiTests,GetPhysicalDeviceWaylandPresentNoICDSupport)696 TEST(WsiTests, GetPhysicalDeviceWaylandPresentNoICDSupport) {
697 FrameworkEnvironment env{};
698 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
699 auto& cur_icd = env.get_test_icd(0);
700 cur_icd.set_min_icd_interface_version(5);
701 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
702 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
703 cur_icd.add_instance_extension({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
704 cur_icd.physical_devices.emplace_back("physical_device_0");
705 cur_icd.enable_icd_wsi = false;
706
707 InstWrapper inst{env.vulkan_functions};
708 inst.create_info.add_extensions(
709 {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME});
710 inst.CheckCreate();
711
712 uint32_t driver_count = 1;
713 VkPhysicalDevice physical_device;
714 ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device));
715 ASSERT_EQ(driver_count, 1U);
716
717 DebugUtilsWrapper log{inst};
718 CreateDebugUtilsMessenger(log);
719 auto res = env.vulkan_functions.vkGetPhysicalDeviceWaylandPresentationSupportKHR(physical_device, 0, nullptr);
720 ASSERT_EQ(res, VK_FALSE);
721 ASSERT_TRUE(log.find("ICD for selected physical device does not export vkGetPhysicalDeviceWaylandPresentationSupportKHR!"));
722 }
723
TEST(WsiTests,GetPhysicalDeviceWaylandPresentICDSupport)724 TEST(WsiTests, GetPhysicalDeviceWaylandPresentICDSupport) {
725 FrameworkEnvironment env{};
726 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
727 auto& cur_icd = env.get_test_icd(0);
728 cur_icd.set_min_icd_interface_version(5);
729 cur_icd.set_icd_api_version(VK_API_VERSION_1_0);
730 cur_icd.add_instance_extension({VK_KHR_SURFACE_EXTENSION_NAME});
731 cur_icd.add_instance_extension({VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
732 cur_icd.physical_devices.emplace_back("physical_device_0");
733 cur_icd.enable_icd_wsi = true;
734
735 InstWrapper inst{env.vulkan_functions};
736 inst.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
737 inst.CheckCreate();
738
739 uint32_t driver_count = 1;
740 VkPhysicalDevice physical_device;
741 ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDevices(inst, &driver_count, &physical_device));
742 ASSERT_EQ(driver_count, 1U);
743
744 ASSERT_EQ(VK_TRUE, env.vulkan_functions.vkGetPhysicalDeviceWaylandPresentationSupportKHR(physical_device, 0, nullptr));
745 }
746
TEST(WsiTests,WaylandGetPhysicalDeviceSurfaceSupportKHR)747 TEST(WsiTests, WaylandGetPhysicalDeviceSurfaceSupportKHR) {
748 FrameworkEnvironment env{};
749 const uint32_t max_device_count = 4;
750 for (uint32_t icd = 0; icd < max_device_count; ++icd) {
751 Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
752 Extension second_ext{VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME};
753 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
754 auto& cur_icd = env.get_test_icd(icd);
755 cur_icd.icd_api_version = VK_API_VERSION_1_0;
756 cur_icd.set_min_icd_interface_version(5);
757 cur_icd.add_instance_extensions({first_ext, second_ext});
758 std::string dev_name = "phys_dev_" + std::to_string(icd);
759 cur_icd.physical_devices.emplace_back(dev_name.c_str());
760 cur_icd.physical_devices.back().add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, true});
761 cur_icd.enable_icd_wsi = true;
762 }
763
764 InstWrapper instance(env.vulkan_functions);
765 instance.create_info.add_extensions({VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME});
766 instance.CheckCreate();
767
768 VkSurfaceKHR surface{VK_NULL_HANDLE};
769 VkWaylandSurfaceCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
770 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkCreateWaylandSurfaceKHR(instance.inst, &createInfo, nullptr, &surface));
771 ASSERT_TRUE(surface != VK_NULL_HANDLE);
772 // ASSERT_EQ(cur_icd.is_using_icd_wsi, UsingICDProvidedWSI::not_using);
773
774 uint32_t device_count = max_device_count;
775 std::array<VkPhysicalDevice, max_device_count> phys_devs;
776 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumeratePhysicalDevices(instance.inst, &device_count, phys_devs.data()));
777 ASSERT_EQ(device_count, max_device_count);
778
779 for (uint32_t pd = 0; pd < max_device_count; ++pd) {
780 VkBool32 supported = VK_FALSE;
781 ASSERT_EQ(VK_SUCCESS, env.vulkan_functions.vkGetPhysicalDeviceSurfaceSupportKHR(phys_devs[pd], 0, surface, &supported));
782 }
783
784 env.vulkan_functions.vkDestroySurfaceKHR(instance.inst, surface, nullptr);
785 }
786 #endif
787