blob: 113228c6f57f95df980acfcd071266841456e0d6 [file] [log] [blame]
sfricke-samsung459cb602021-07-26 22:19:58 -07001/*
Jeremy Gebben4a8881f2022-01-10 17:04:30 -07002 * Copyright (c) 2015-2022 The Khronos Group Inc.
3 * Copyright (c) 2015-2022 Valve Corporation
4 * Copyright (c) 2015-2022 LunarG, Inc.
5 * Copyright (c) 2015-2022 Google, Inc.
sfricke-samsung459cb602021-07-26 22:19:58 -07006 * Modifications Copyright (C) 2020-2021 Advanced Micro Devices, Inc. All rights reserved.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Author: Chia-I Wu <olvaffe@gmail.com>
15 * Author: Chris Forbes <chrisf@ijw.co.nz>
16 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
17 * Author: Mark Lobodzinski <mark@lunarg.com>
18 * Author: Mike Stroyan <mike@LunarG.com>
19 * Author: Tobin Ehlis <tobine@google.com>
20 * Author: Tony Barbour <tony@LunarG.com>
21 * Author: Cody Northrop <cnorthrop@google.com>
22 * Author: Dave Houlton <daveh@lunarg.com>
23 * Author: Jeremy Kniager <jeremyk@lunarg.com>
24 * Author: Shannon McPherson <shannon@lunarg.com>
25 * Author: John Zulauf <jzulauf@lunarg.com>
26 * Author: Tobias Hector <tobias.hector@amd.com>
27 */
28
29#include "layer_validation_tests.h"
ziga-lunargf2628fa2021-10-03 01:42:57 +020030#include "core_validation_error_enums.h"
sfricke-samsung459cb602021-07-26 22:19:58 -070031
arno-lunargba391312022-09-08 13:23:28 +020032TEST_F(VkLayerTest, InitSwapchainPotentiallyIncompatibleFlag) {
33 TEST_DESCRIPTION("Initialize swapchain with potentially incompatible flags");
34
35 SetTargetApiVersion(VK_API_VERSION_1_1);
36
37 AddRequiredExtensions(VK_KHR_SURFACE_PROTECTED_CAPABILITIES_EXTENSION_NAME);
38 AddSurfaceExtension();
39
40 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
41 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
42 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
43 }
44 if (!AreRequiredExtensionsEnabled()) {
45 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
46 }
47
48 ASSERT_NO_FATAL_FAILURE(InitState());
49
50 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
51 if (!InitSurface()) {
52 GTEST_SKIP() << "Cannot create surface, skipping test";
53 }
54 InitSwapchainInfo();
55
56 VkSwapchainCreateInfoKHR swapchain_ci = LvlInitStruct<VkSwapchainCreateInfoKHR>();
57 swapchain_ci.surface = m_surface;
58 swapchain_ci.minImageCount = m_surface_capabilities.minImageCount;
59 swapchain_ci.imageFormat = m_surface_formats[0].format;
60 swapchain_ci.imageColorSpace = m_surface_formats[0].colorSpace;
61 swapchain_ci.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
62 swapchain_ci.imageArrayLayers = 1;
63 swapchain_ci.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
64 swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
65 swapchain_ci.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
66 swapchain_ci.compositeAlpha = m_surface_composite_alpha;
67 swapchain_ci.presentMode = m_surface_non_shared_present_mode;
68 swapchain_ci.clipped = VK_FALSE;
69 swapchain_ci.oldSwapchain = 0;
70
71 // "protected" flag support is device defined
72 {
73 swapchain_ci.flags = VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR;
74
75 PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR vkGetPhysicalDeviceSurfaceCapabilities2KHR =
76 reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR>(
77 vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceSurfaceCapabilities2KHR"));
78 ASSERT_TRUE(vkGetPhysicalDeviceSurfaceCapabilities2KHR != nullptr);
79
80 // Get surface protected capabilities
81 VkPhysicalDeviceSurfaceInfo2KHR surface_info = LvlInitStruct<VkPhysicalDeviceSurfaceInfo2KHR>();
82 surface_info.surface = swapchain_ci.surface;
83 VkSurfaceProtectedCapabilitiesKHR surface_protected_capabilities = LvlInitStruct<VkSurfaceProtectedCapabilitiesKHR>();
84 VkSurfaceCapabilities2KHR surface_capabilities = LvlInitStruct<VkSurfaceCapabilities2KHR>();
85 surface_capabilities.pNext = &surface_protected_capabilities;
86 vkGetPhysicalDeviceSurfaceCapabilities2KHR(gpu(), &surface_info, &surface_capabilities);
87
88 // Create swapchain, monitor potential validation error
89 if (!surface_protected_capabilities.supportsProtected) {
90 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-flags-03187");
91 }
92
93 vk::CreateSwapchainKHR(device(), &swapchain_ci, nullptr, &m_swapchain);
94
95 if (!surface_protected_capabilities.supportsProtected) {
96 m_errorMonitor->VerifyFound();
97 m_swapchain = VK_NULL_HANDLE; // swapchain was not created, so prevent destroy
98 } else {
99 vk::DestroySwapchainKHR(device(), m_swapchain, nullptr);
100 m_swapchain = VK_NULL_HANDLE;
101 }
102 }
103
104 // "split instance bind regions" not supported when there is only one device
105 {
106 swapchain_ci.flags = VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR;
107
108 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-physicalDeviceCount-01429");
109 vk::CreateSwapchainKHR(device(), &swapchain_ci, nullptr, &m_swapchain);
110 m_errorMonitor->VerifyFound();
111 m_swapchain = VK_NULL_HANDLE; // swapchain was not created, so prevent destroy
112 }
113}
114
sfricke-samsung459cb602021-07-26 22:19:58 -0700115TEST_F(VkLayerTest, BindImageMemorySwapchain) {
116 TEST_DESCRIPTION("Invalid bind image with a swapchain");
117 SetTargetApiVersion(VK_API_VERSION_1_1);
118
sjfrickea83fbb92022-07-01 13:57:27 +0900119 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700120 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
121
122 if (IsPlatform(kGalaxyS10)) {
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600123 GTEST_SKIP() << "This test should not run on Galaxy S10";
124 }
125 if (IsPlatform(kMockICD)) {
126 GTEST_SKIP() << "This test appears to leave the image created a swapchain in a weird state that leads to 00378 when it "
127 "shouldn't. Requires further investigation.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700128 }
129
sjfrickea83fbb92022-07-01 13:57:27 +0900130 if (!AreRequiredExtensionsEnabled()) {
131 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700132 }
133
134 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900135 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
sfricke-samsung459cb602021-07-26 22:19:58 -0700136 }
137
138 ASSERT_NO_FATAL_FAILURE(InitState());
139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
140 if (!InitSwapchain(VK_IMAGE_USAGE_TRANSFER_SRC_BIT)) {
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600141 GTEST_SKIP() << "Cannot create surface or swapchain, skipping BindSwapchainImageMemory test";
sfricke-samsung459cb602021-07-26 22:19:58 -0700142 }
143
144 auto image_create_info = LvlInitStruct<VkImageCreateInfo>();
145 image_create_info.imageType = VK_IMAGE_TYPE_2D;
146 image_create_info.format = m_surface_formats[0].format;
147 image_create_info.extent.width = m_surface_capabilities.minImageExtent.width;
148 image_create_info.extent.height = m_surface_capabilities.minImageExtent.height;
149 image_create_info.extent.depth = 1;
150 image_create_info.mipLevels = 1;
151 image_create_info.arrayLayers = 1;
152 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
153 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
154 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
155 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
156 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
157
158 auto image_swapchain_create_info = LvlInitStruct<VkImageSwapchainCreateInfoKHR>();
159 image_swapchain_create_info.swapchain = m_swapchain;
160 image_create_info.pNext = &image_swapchain_create_info;
161
162 VkImage image_from_swapchain;
163 VkResult err = vk::CreateImage(device(), &image_create_info, NULL, &image_from_swapchain);
164 ASSERT_VK_SUCCESS(err);
165
166 VkMemoryRequirements mem_reqs = {};
167 vk::GetImageMemoryRequirements(device(), image_from_swapchain, &mem_reqs);
168
169 auto alloc_info = LvlInitStruct<VkMemoryAllocateInfo>();
170 alloc_info.memoryTypeIndex = 0;
171 alloc_info.allocationSize = mem_reqs.size;
sjfrickeafb5b2a2022-09-01 15:11:09 +0900172 if (alloc_info.allocationSize == 0) {
173 GTEST_SKIP() << "Driver seems to not be returning an valid allocation size and need to end test";
174 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700175
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600176 vk_testing::DeviceMemory mem;
sfricke-samsung459cb602021-07-26 22:19:58 -0700177 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, 0);
Jeremy Gebbendd2c1472021-09-01 11:02:33 -0600178 // some devices don't give us good memory requirements for the swapchain image
179 if (pass) {
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600180 mem.init(*m_device, alloc_info);
181 ASSERT_TRUE(mem.initialized());
Jeremy Gebbendd2c1472021-09-01 11:02:33 -0600182 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700183
184 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
185 bind_info.image = image_from_swapchain;
186 bind_info.memory = VK_NULL_HANDLE;
187 bind_info.memoryOffset = 0;
188
Nathaniel Cesarioe81f04e2022-07-15 15:17:16 -0600189 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindImageMemoryInfo-image-01630");
190 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindImageMemoryInfo-pNext-01632");
191 vk::BindImageMemory2(m_device->device(), 1, &bind_info);
192 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -0700193
194 auto bind_swapchain_info = LvlInitStruct<VkBindImageMemorySwapchainInfoKHR>();
195 bind_swapchain_info.swapchain = VK_NULL_HANDLE;
196 bind_swapchain_info.imageIndex = 0;
197 bind_info.pNext = &bind_swapchain_info;
198
Nathaniel Cesarioe81f04e2022-07-15 15:17:16 -0600199 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "UNASSIGNED-GeneralParameterError-RequiredParameter");
200 vk::BindImageMemory2(m_device->device(), 1, &bind_info);
201 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -0700202
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600203 bind_info.memory = mem.handle();
sfricke-samsung459cb602021-07-26 22:19:58 -0700204 bind_swapchain_info.swapchain = m_swapchain;
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600205 bind_swapchain_info.imageIndex = std::numeric_limits<uint32_t>::max();
sfricke-samsung459cb602021-07-26 22:19:58 -0700206
Nathaniel Cesarioe81f04e2022-07-15 15:17:16 -0600207 if (mem.initialized()) {
208 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindImageMemoryInfo-pNext-01631");
209 }
210 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkBindImageMemorySwapchainInfoKHR-imageIndex-01644");
211 vk::BindImageMemory2(m_device->device(), 1, &bind_info);
212 m_errorMonitor->VerifyFound();
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600213
214 bind_info.memory = VK_NULL_HANDLE;
215 bind_swapchain_info.imageIndex = 0;
sfricke-samsung459cb602021-07-26 22:19:58 -0700216 vk::BindImageMemory2(m_device->device(), 1, &bind_info);
sfricke-samsung459cb602021-07-26 22:19:58 -0700217
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600218 vk::DestroyImage(m_device->device(), image_from_swapchain, nullptr);
sfricke-samsung459cb602021-07-26 22:19:58 -0700219}
220
221TEST_F(VkLayerTest, ValidSwapchainImage) {
222 TEST_DESCRIPTION("Swapchain images with invalid parameters");
223 const char *vuid = "VUID-VkImageSwapchainCreateInfoKHR-swapchain-00995";
224
sjfrickea83fbb92022-07-01 13:57:27 +0900225 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700226
227 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
228
229 if (IsPlatform(kGalaxyS10)) {
230 printf("%s This test should not run on Galaxy S10\n", kSkipPrefix);
231 return;
232 }
233
sjfrickea83fbb92022-07-01 13:57:27 +0900234 if (!AreRequiredExtensionsEnabled()) {
235 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700236 }
237
238 ASSERT_NO_FATAL_FAILURE(InitState());
239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
240 if (!InitSwapchain()) {
241 printf("%s Cannot create surface or swapchain, skipping test\n", kSkipPrefix);
242 return;
243 }
244
245 VkImage image;
sfricke-samsung34c103f2021-12-31 02:04:18 -0600246 VkImageSwapchainCreateInfoKHR image_swapchain_create_info = LvlInitStruct<VkImageSwapchainCreateInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700247 image_swapchain_create_info.swapchain = m_swapchain;
248
sfricke-samsung34c103f2021-12-31 02:04:18 -0600249 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>(&image_swapchain_create_info);
sfricke-samsung459cb602021-07-26 22:19:58 -0700250 image_create_info.flags = 0;
251 image_create_info.imageType = VK_IMAGE_TYPE_2D;
252 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
253 image_create_info.extent.width = 64;
254 image_create_info.extent.height = 64;
255 image_create_info.extent.depth = 1;
256 image_create_info.mipLevels = 1;
257 image_create_info.arrayLayers = 1;
258 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
259 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
260 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
261 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
262 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
263 VkImageCreateInfo good_create_info = image_create_info;
264
265 // imageType
266 image_create_info = good_create_info;
267 image_create_info.imageType = VK_IMAGE_TYPE_3D;
268 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, vuid);
269 vk::CreateImage(device(), &image_create_info, NULL, &image);
270 m_errorMonitor->VerifyFound();
271
272 // mipLevels
273 image_create_info = good_create_info;
274 image_create_info.mipLevels = 2;
275 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, vuid);
276 vk::CreateImage(device(), &image_create_info, NULL, &image);
277 m_errorMonitor->VerifyFound();
278
279 // samples
280 image_create_info = good_create_info;
281 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
282 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, vuid);
283 vk::CreateImage(device(), &image_create_info, NULL, &image);
284 m_errorMonitor->VerifyFound();
285
286 // tiling
287 image_create_info = good_create_info;
288 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
289 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, vuid);
290 vk::CreateImage(device(), &image_create_info, NULL, &image);
291 m_errorMonitor->VerifyFound();
292
293 // initialLayout
294 image_create_info = good_create_info;
295 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
296 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, vuid);
297 vk::CreateImage(device(), &image_create_info, NULL, &image);
298 m_errorMonitor->VerifyFound();
299
300 // flags
301 if (m_device->phy().features().sparseBinding) {
302 image_create_info = good_create_info;
303 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
304 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, vuid);
305 vk::CreateImage(device(), &image_create_info, NULL, &image);
306 m_errorMonitor->VerifyFound();
307 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700308}
309
310TEST_F(VkLayerTest, TransferImageToSwapchainWithInvalidLayoutDeviceGroup) {
311 TEST_DESCRIPTION("Transfer an image to a swapchain's image with a invalid layout between device group");
312
313#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600314 GTEST_SKIP() << "According to valid usage, VkBindImageMemoryInfo-memory should be NULL. But Android will crash if memory is "
315 "NULL, skipping test";
sfricke-samsung459cb602021-07-26 22:19:58 -0700316#endif
317
318 SetTargetApiVersion(VK_API_VERSION_1_2);
319
sjfrickea83fbb92022-07-01 13:57:27 +0900320 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700321 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
322
sjfrickea83fbb92022-07-01 13:57:27 +0900323 if (!AreRequiredExtensionsEnabled()) {
324 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700325 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700326 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900327 GTEST_SKIP() << "At least Vulkan version 1.2 is required";
sfricke-samsung459cb602021-07-26 22:19:58 -0700328 }
329
330 if (IsDriver(VK_DRIVER_ID_MESA_RADV)) {
331 // Seeing the same crash as the Android comment above
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600332 GTEST_SKIP() << "This test should not be run on the RADV driver";
sfricke-samsung459cb602021-07-26 22:19:58 -0700333 }
334
335 uint32_t physical_device_group_count = 0;
336 vk::EnumeratePhysicalDeviceGroups(instance(), &physical_device_group_count, nullptr);
337
338 if (physical_device_group_count == 0) {
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600339 GTEST_SKIP() << "physical_device_group_count is 0, skipping test";
sfricke-samsung459cb602021-07-26 22:19:58 -0700340 }
341
342 std::vector<VkPhysicalDeviceGroupProperties> physical_device_group(physical_device_group_count,
343 {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
344 vk::EnumeratePhysicalDeviceGroups(instance(), &physical_device_group_count, physical_device_group.data());
sfricke-samsung34c103f2021-12-31 02:04:18 -0600345 VkDeviceGroupDeviceCreateInfo create_device_pnext = LvlInitStruct<VkDeviceGroupDeviceCreateInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700346 create_device_pnext.physicalDeviceCount = physical_device_group[0].physicalDeviceCount;
347 create_device_pnext.pPhysicalDevices = physical_device_group[0].physicalDevices;
348 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &create_device_pnext));
349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
350 if (!InitSwapchain(VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
351 printf("%s Cannot create surface or swapchain, skipping test\n", kSkipPrefix);
352 return;
353 }
354
355 auto image_create_info = LvlInitStruct<VkImageCreateInfo>();
356 image_create_info.imageType = VK_IMAGE_TYPE_2D;
357 image_create_info.format = m_surface_formats[0].format;
358 image_create_info.extent.width = m_surface_capabilities.minImageExtent.width;
359 image_create_info.extent.height = m_surface_capabilities.minImageExtent.height;
360 image_create_info.extent.depth = 1;
361 image_create_info.mipLevels = 1;
362 image_create_info.arrayLayers = 1;
363 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
364 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
365 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
366 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
367 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
368
369 VkImageObj src_Image(m_device);
370 src_Image.init(&image_create_info);
371
372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
373
374 auto image_swapchain_create_info = LvlInitStruct<VkImageSwapchainCreateInfoKHR>();
375 image_swapchain_create_info.swapchain = m_swapchain;
376 image_create_info.pNext = &image_swapchain_create_info;
377
paul-lunarg2e0b19c2022-07-12 16:17:15 -0600378 vk_testing::Image peer_image(*m_device, image_create_info, vk_testing::no_mem);
sfricke-samsung459cb602021-07-26 22:19:58 -0700379
380 auto bind_devicegroup_info = LvlInitStruct<VkBindImageMemoryDeviceGroupInfo>();
ziga-lunarg2402b5c2022-04-20 11:43:08 +0200381 bind_devicegroup_info.deviceIndexCount = 1;
382 std::array<uint32_t, 1> deviceIndices = {{0}};
sfricke-samsung459cb602021-07-26 22:19:58 -0700383 bind_devicegroup_info.pDeviceIndices = deviceIndices.data();
384 bind_devicegroup_info.splitInstanceBindRegionCount = 0;
385 bind_devicegroup_info.pSplitInstanceBindRegions = nullptr;
386
387 auto bind_swapchain_info = LvlInitStruct<VkBindImageMemorySwapchainInfoKHR>(&bind_devicegroup_info);
388 bind_swapchain_info.swapchain = m_swapchain;
389 bind_swapchain_info.imageIndex = 0;
390
391 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>(&bind_swapchain_info);
paul-lunarg3d38daa2022-07-12 15:16:46 -0600392 bind_info.image = peer_image.handle();
sfricke-samsung459cb602021-07-26 22:19:58 -0700393 bind_info.memory = VK_NULL_HANDLE;
394 bind_info.memoryOffset = 0;
sfricke-samsung459cb602021-07-26 22:19:58 -0700395 vk::BindImageMemory2(m_device->device(), 1, &bind_info);
396
397 uint32_t swapchain_images_count = 0;
398 vk::GetSwapchainImagesKHR(device(), m_swapchain, &swapchain_images_count, nullptr);
399 std::vector<VkImage> swapchain_images;
400 swapchain_images.resize(swapchain_images_count);
401 vk::GetSwapchainImagesKHR(device(), m_swapchain, &swapchain_images_count, swapchain_images.data());
402
403 m_commandBuffer->begin();
404
405 VkImageCopy copy_region = {};
406 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
407 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
408 copy_region.srcSubresource.mipLevel = 0;
409 copy_region.dstSubresource.mipLevel = 0;
410 copy_region.srcSubresource.baseArrayLayer = 0;
411 copy_region.dstSubresource.baseArrayLayer = 0;
412 copy_region.srcSubresource.layerCount = 1;
413 copy_region.dstSubresource.layerCount = 1;
414 copy_region.srcOffset = {0, 0, 0};
415 copy_region.dstOffset = {0, 0, 0};
416 copy_region.extent = {10, 10, 1};
paul-lunarg3d38daa2022-07-12 15:16:46 -0600417 vk::CmdCopyImage(m_commandBuffer->handle(), src_Image.handle(), VK_IMAGE_LAYOUT_GENERAL, peer_image.handle(),
sfricke-samsung459cb602021-07-26 22:19:58 -0700418 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
419
420 m_commandBuffer->end();
421
sfricke-samsung34c103f2021-12-31 02:04:18 -0600422 VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700423 submit_info.commandBufferCount = 1;
424 submit_info.pCommandBuffers = &m_commandBuffer->handle();
425
Jeremy Gebben4a8881f2022-01-10 17:04:30 -0700426 // Even though both peer_image and swapchain_images[0] use the same memory and are in an invalid layout,
427 // only peer_image is referenced by the command buffer so there should only be one error reported.
sfricke-samsung459cb602021-07-26 22:19:58 -0700428 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout");
429 vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
430 m_errorMonitor->VerifyFound();
431
Nathaniel Cesario079b1b92022-07-06 15:56:26 -0600432 // peer_image is a presentable image and controlled by the implementation
sfricke-samsung459cb602021-07-26 22:19:58 -0700433}
434
435TEST_F(VkLayerTest, ValidSwapchainImageParams) {
436 TEST_DESCRIPTION("Swapchain with invalid implied image creation parameters");
437 const char *vuid = "VUID-VkSwapchainCreateInfoKHR-imageFormat-01778";
438
sjfrickea83fbb92022-07-01 13:57:27 +0900439 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700440
sjfricked700bc02022-05-30 16:35:06 +0900441 AddRequiredExtensions(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME);
sfricke-samsung459cb602021-07-26 22:19:58 -0700442 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
sjfricked700bc02022-05-30 16:35:06 +0900443 if (!AreRequiredExtensionsEnabled()) {
444 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
445 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700446
sfricke-samsung34c103f2021-12-31 02:04:18 -0600447 VkDeviceGroupDeviceCreateInfo device_group_ci = LvlInitStruct<VkDeviceGroupDeviceCreateInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700448 device_group_ci.physicalDeviceCount = 1;
449 VkPhysicalDevice pdev = gpu();
450 device_group_ci.pPhysicalDevices = &pdev;
451 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &device_group_ci));
452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
453 if (!InitSurface()) {
arno-lunargba391312022-09-08 13:23:28 +0200454 GTEST_SKIP() << "Cannot create surface, skipping test";
sfricke-samsung459cb602021-07-26 22:19:58 -0700455 }
456 InitSwapchainInfo();
457
sfricke-samsung34c103f2021-12-31 02:04:18 -0600458 VkSwapchainCreateInfoKHR good_create_info = LvlInitStruct<VkSwapchainCreateInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700459 good_create_info.surface = m_surface;
460 good_create_info.minImageCount = m_surface_capabilities.minImageCount;
461 good_create_info.imageFormat = m_surface_formats[0].format;
462 good_create_info.imageColorSpace = m_surface_formats[0].colorSpace;
463 good_create_info.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
464 good_create_info.imageArrayLayers = 1;
465 good_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
466 good_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
467 good_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
468 good_create_info.compositeAlpha = m_surface_composite_alpha;
469 good_create_info.presentMode = m_surface_non_shared_present_mode;
470 good_create_info.clipped = VK_FALSE;
471 good_create_info.oldSwapchain = 0;
472
473 VkSwapchainCreateInfoKHR create_info_bad_usage = good_create_info;
474 bool found_bad_usage = false;
475 // Trying to find format+usage combination supported by surface, but not supported by image.
476 const std::array<VkImageUsageFlags, 5> kImageUsageFlags = {{
477 VK_IMAGE_USAGE_SAMPLED_BIT,
478 VK_IMAGE_USAGE_STORAGE_BIT,
479 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
480 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
481 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT,
482 }};
483
484 for (uint32_t i = 0; i < kImageUsageFlags.size() && !found_bad_usage; ++i) {
485 if ((m_surface_capabilities.supportedUsageFlags & kImageUsageFlags[i]) != 0) {
486 for (size_t j = 0; j < m_surface_formats.size(); ++j) {
487 VkImageFormatProperties image_format_properties = {};
488 VkResult image_format_properties_result = vk::GetPhysicalDeviceImageFormatProperties(
489 m_device->phy().handle(), m_surface_formats[j].format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
490 kImageUsageFlags[i], 0, &image_format_properties);
491
492 if (image_format_properties_result != VK_SUCCESS) {
493 create_info_bad_usage.imageFormat = m_surface_formats[j].format;
494 create_info_bad_usage.imageUsage = kImageUsageFlags[i];
495 found_bad_usage = true;
496 break;
497 }
498 }
499 }
500 }
501 VkBool32 supported;
502 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), m_device->graphics_queue_node_index_, m_surface, &supported);
503 if (!supported) {
504 printf("%s Graphics queue does not support present, skipping test\n", kSkipPrefix);
505 return;
506 }
507
508 if (found_bad_usage) {
509 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, vuid);
510 vk::CreateSwapchainKHR(device(), &create_info_bad_usage, nullptr, &m_swapchain);
511 m_errorMonitor->VerifyFound();
512 } else {
513 printf(
514 "%s could not find imageFormat and imageUsage values, supported by "
515 "surface but unsupported by image, skipping test\n",
516 kSkipPrefix);
517 }
518 vk::DestroySwapchainKHR(device(), m_swapchain, nullptr);
519
520 VkImageFormatProperties props;
521 VkResult res = vk::GetPhysicalDeviceImageFormatProperties(gpu(), good_create_info.imageFormat, VK_IMAGE_TYPE_2D,
522 VK_IMAGE_TILING_OPTIMAL, good_create_info.imageUsage,
523 VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT, &props);
524 if (res != VK_SUCCESS) {
525 printf("%s Swapchain image format does not support SPLIT_INSTANCE_BIND_REGIONS, skipping test\n", kSkipPrefix);
526 return;
527 }
528
529 VkSwapchainCreateInfoKHR create_info_bad_flags = good_create_info;
530 create_info_bad_flags.flags = VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR;
531 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-physicalDeviceCount-01429");
532 vk::CreateSwapchainKHR(device(), &create_info_bad_flags, nullptr, &m_swapchain);
533 m_errorMonitor->VerifyFound();
paul-lunarg15939c92022-07-12 14:32:07 -0600534
535 // No valid swapchain
536 m_swapchain = VK_NULL_HANDLE;
sfricke-samsung459cb602021-07-26 22:19:58 -0700537}
538
539TEST_F(VkLayerTest, SwapchainAcquireImageNoSync) {
540 TEST_DESCRIPTION("Test vkAcquireNextImageKHR with VK_NULL_HANDLE semaphore and fence");
541
sjfrickea83fbb92022-07-01 13:57:27 +0900542 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700543
544 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
545
sjfrickea83fbb92022-07-01 13:57:27 +0900546 if (!AreRequiredExtensionsEnabled()) {
547 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700548 }
549
550 ASSERT_NO_FATAL_FAILURE(InitState());
551 ASSERT_TRUE(InitSwapchain());
552
553 {
554 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkAcquireNextImageKHR-semaphore-01780");
555 uint32_t dummy;
556 vk::AcquireNextImageKHR(device(), m_swapchain, UINT64_MAX, VK_NULL_HANDLE, VK_NULL_HANDLE, &dummy);
557 m_errorMonitor->VerifyFound();
558 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700559}
560
561TEST_F(VkLayerTest, SwapchainAcquireImageNoSync2KHR) {
562 TEST_DESCRIPTION("Test vkAcquireNextImage2KHR with VK_NULL_HANDLE semaphore and fence");
563 SetTargetApiVersion(VK_API_VERSION_1_1);
564
565 bool extension_dependency_satisfied = false;
566 if (InstanceExtensionSupported(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME)) {
567 m_instance_extension_names.push_back(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME);
568 extension_dependency_satisfied = true;
569 }
sjfrickea83fbb92022-07-01 13:57:27 +0900570 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700571
572 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
573
574 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900575 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
sfricke-samsung459cb602021-07-26 22:19:58 -0700576 }
577
578 if (extension_dependency_satisfied && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DEVICE_GROUP_EXTENSION_NAME)) {
579 m_device_extension_names.push_back(VK_KHR_DEVICE_GROUP_EXTENSION_NAME);
sfricke-samsung459cb602021-07-26 22:19:58 -0700580 }
581
sjfrickea83fbb92022-07-01 13:57:27 +0900582 if (!AreRequiredExtensionsEnabled()) {
583 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700584 }
585
586 ASSERT_NO_FATAL_FAILURE(InitState());
587 ASSERT_TRUE(InitSwapchain());
588
589 {
590 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkAcquireNextImageInfoKHR-semaphore-01782");
sfricke-samsung34c103f2021-12-31 02:04:18 -0600591 VkAcquireNextImageInfoKHR acquire_info = LvlInitStruct<VkAcquireNextImageInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700592 acquire_info.swapchain = m_swapchain;
593 acquire_info.timeout = UINT64_MAX;
594 acquire_info.semaphore = VK_NULL_HANDLE;
595 acquire_info.fence = VK_NULL_HANDLE;
596 acquire_info.deviceMask = 0x1;
597
598 uint32_t dummy;
599 vk::AcquireNextImage2KHR(device(), &acquire_info, &dummy);
600 m_errorMonitor->VerifyFound();
601 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700602}
603
604TEST_F(VkLayerTest, SwapchainAcquireImageNoBinarySemaphore) {
605 TEST_DESCRIPTION("Test vkAcquireNextImageKHR with non-binary semaphore");
606
sjfrickea83fbb92022-07-01 13:57:27 +0900607 AddSurfaceExtension();
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600608 AddRequiredExtensions(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
609 AddRequiredExtensions(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
610 ASSERT_NO_FATAL_FAILURE(InitFramework());
611 if (!AreRequiredExtensionsEnabled()) {
612 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700613 }
614
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600615 auto timeline_semaphore_features = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreFeatures>();
616 auto features2 = GetPhysicalDeviceFeatures2(timeline_semaphore_features);
617 if (!timeline_semaphore_features.timelineSemaphore) {
618 GTEST_SKIP() << "timelineSemaphore feature not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700619 }
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600620
621 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
622 GetPhysicalDeviceProperties2(timeline_semaphore_props);
623 if (timeline_semaphore_props.maxTimelineSemaphoreValueDifference == 0) {
624 // If using MockICD and devsim the value might be zero'ed and cause false errors
625 GTEST_SKIP() << "maxTimelineSemaphoreValueDifference is 0";
626 }
627 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
sfricke-samsung459cb602021-07-26 22:19:58 -0700628 ASSERT_TRUE(InitSwapchain());
629
sfricke-samsung34c103f2021-12-31 02:04:18 -0600630 VkSemaphoreTypeCreateInfoKHR semaphore_type_create_info = LvlInitStruct<VkSemaphoreTypeCreateInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700631 semaphore_type_create_info.semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE_KHR;
632
sfricke-samsung34c103f2021-12-31 02:04:18 -0600633 VkSemaphoreCreateInfo semaphore_create_info = LvlInitStruct<VkSemaphoreCreateInfo>(&semaphore_type_create_info);
sfricke-samsung459cb602021-07-26 22:19:58 -0700634
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600635 vk_testing::Semaphore semaphore(*m_device, semaphore_create_info);
sfricke-samsung459cb602021-07-26 22:19:58 -0700636
637 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkAcquireNextImageKHR-semaphore-03265");
638 uint32_t image_i;
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600639 vk::AcquireNextImageKHR(device(), m_swapchain, UINT64_MAX, semaphore.handle(), VK_NULL_HANDLE, &image_i);
sfricke-samsung459cb602021-07-26 22:19:58 -0700640 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -0700641}
642
643TEST_F(VkLayerTest, SwapchainAcquireImageNoBinarySemaphore2KHR) {
644 TEST_DESCRIPTION("Test vkAcquireNextImage2KHR with non-binary semaphore");
645
646 TEST_DESCRIPTION("Test vkAcquireNextImage2KHR with VK_NULL_HANDLE semaphore and fence");
647 SetTargetApiVersion(VK_API_VERSION_1_1);
sjfrickea83fbb92022-07-01 13:57:27 +0900648 AddSurfaceExtension();
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600649 AddRequiredExtensions(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME);
650 AddRequiredExtensions(VK_KHR_DEVICE_GROUP_EXTENSION_NAME);
651 AddRequiredExtensions(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
652 AddRequiredExtensions(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
653 ASSERT_NO_FATAL_FAILURE(InitFramework());
654 if (!AreRequiredExtensionsEnabled()) {
655 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
656 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700657
658 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900659 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
sfricke-samsung459cb602021-07-26 22:19:58 -0700660 }
661
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600662 auto timeline_semaphore_features = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreFeatures>();
663 auto features2 = GetPhysicalDeviceFeatures2(timeline_semaphore_features);
664 if (!timeline_semaphore_features.timelineSemaphore) {
665 GTEST_SKIP() << "timelineSemaphore not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700666 }
667
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600668 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
669 GetPhysicalDeviceProperties2(timeline_semaphore_props);
670 if (timeline_semaphore_props.maxTimelineSemaphoreValueDifference == 0) {
671 // If using MockICD and devsim the value might be zero'ed and cause false errors
672 GTEST_SKIP() << "maxTimelineSemaphoreValueDifference is 0";
sfricke-samsung459cb602021-07-26 22:19:58 -0700673 }
674
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -0600675 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
sfricke-samsung459cb602021-07-26 22:19:58 -0700676
677 ASSERT_TRUE(InitSwapchain());
678
sfricke-samsung34c103f2021-12-31 02:04:18 -0600679 VkSemaphoreTypeCreateInfoKHR semaphore_type_create_info = LvlInitStruct<VkSemaphoreTypeCreateInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700680 semaphore_type_create_info.semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE_KHR;
681
sfricke-samsung34c103f2021-12-31 02:04:18 -0600682 VkSemaphoreCreateInfo semaphore_create_info = LvlInitStruct<VkSemaphoreCreateInfo>(&semaphore_type_create_info);
sfricke-samsung459cb602021-07-26 22:19:58 -0700683
684 VkSemaphore semaphore;
685 ASSERT_VK_SUCCESS(vk::CreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
686
sfricke-samsung34c103f2021-12-31 02:04:18 -0600687 VkAcquireNextImageInfoKHR acquire_info = LvlInitStruct<VkAcquireNextImageInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700688 acquire_info.swapchain = m_swapchain;
689 acquire_info.timeout = UINT64_MAX;
690 acquire_info.semaphore = semaphore;
691 acquire_info.deviceMask = 0x1;
692
693 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkAcquireNextImageInfoKHR-semaphore-03266");
694 uint32_t image_i;
695 vk::AcquireNextImage2KHR(device(), &acquire_info, &image_i);
696 m_errorMonitor->VerifyFound();
697
698 vk::DestroySemaphore(m_device->device(), semaphore, nullptr);
sfricke-samsung459cb602021-07-26 22:19:58 -0700699}
700
701TEST_F(VkLayerTest, SwapchainAcquireTooManyImages) {
702 TEST_DESCRIPTION("Acquiring invalid amount of images from the swapchain.");
703
sjfrickea83fbb92022-07-01 13:57:27 +0900704 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700705 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
sjfrickea83fbb92022-07-01 13:57:27 +0900706 if (!AreRequiredExtensionsEnabled()) {
707 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
708 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700709 ASSERT_NO_FATAL_FAILURE(InitState());
sfricke-samsungca162082022-02-10 08:53:41 -0800710 if (IsPlatform(kMockICD) || DeviceSimulation()) {
sjfricke11b24692022-06-21 20:49:53 +0900711 GTEST_SKIP() << "Test not supported by MockICD, will throw a std::bad_alloc sometimes";
sfricke-samsungca162082022-02-10 08:53:41 -0800712 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700713 ASSERT_TRUE(InitSwapchain());
714 uint32_t image_count;
715 ASSERT_VK_SUCCESS(vk::GetSwapchainImagesKHR(device(), m_swapchain, &image_count, nullptr));
716 VkSurfaceCapabilitiesKHR caps;
717 ASSERT_VK_SUCCESS(vk::GetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), m_surface, &caps));
718
719 const uint32_t acquirable_count = image_count - caps.minImageCount + 1;
720 std::vector<VkFenceObj> fences(acquirable_count);
721 for (uint32_t i = 0; i < acquirable_count; ++i) {
722 fences[i].init(*m_device, VkFenceObj::create_info());
723 uint32_t image_i;
724 const auto res = vk::AcquireNextImageKHR(device(), m_swapchain, UINT64_MAX, VK_NULL_HANDLE, fences[i].handle(), &image_i);
725 ASSERT_TRUE(res == VK_SUCCESS || res == VK_SUBOPTIMAL_KHR);
726 }
727 VkFenceObj error_fence;
728 error_fence.init(*m_device, VkFenceObj::create_info());
729
730 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkAcquireNextImageKHR-swapchain-01802");
731 uint32_t image_i;
732 vk::AcquireNextImageKHR(device(), m_swapchain, UINT64_MAX, VK_NULL_HANDLE, error_fence.handle(), &image_i);
733 m_errorMonitor->VerifyFound();
734
735 // Cleanup
736 vk::WaitForFences(device(), fences.size(), MakeVkHandles<VkFence>(fences).data(), VK_TRUE, UINT64_MAX);
sfricke-samsung459cb602021-07-26 22:19:58 -0700737}
738
739TEST_F(VkLayerTest, GetSwapchainImageAndTryDestroy) {
740 TEST_DESCRIPTION("Try destroying a swapchain presentable image with vkDestroyImage");
741
sjfrickea83fbb92022-07-01 13:57:27 +0900742 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700743 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
sjfrickea83fbb92022-07-01 13:57:27 +0900744 if (!AreRequiredExtensionsEnabled()) {
745 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
746 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700747 ASSERT_NO_FATAL_FAILURE(InitState());
748 ASSERT_TRUE(InitSwapchain());
749 uint32_t image_count;
750 std::vector<VkImage> images;
751 ASSERT_VK_SUCCESS(vk::GetSwapchainImagesKHR(device(), m_swapchain, &image_count, nullptr));
752 images.resize(image_count, VK_NULL_HANDLE);
753 ASSERT_VK_SUCCESS(vk::GetSwapchainImagesKHR(device(), m_swapchain, &image_count, images.data()));
754
755 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkDestroyImage-image-04882");
756 vk::DestroyImage(device(), images.at(0), nullptr);
757 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -0700758}
759
Jeremy Gebben73904222021-10-21 15:46:25 -0600760TEST_F(VkLayerTest, SwapchainNotSupported) {
761 TEST_DESCRIPTION("Test creating a swapchain when GetPhysicalDeviceSurfaceSupportKHR returns VK_FALSE");
sfricke-samsung459cb602021-07-26 22:19:58 -0700762
sjfrickea83fbb92022-07-01 13:57:27 +0900763 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700764
765#ifdef VK_USE_PLATFORM_ANDROID_KHR
766 // in "issue" section of VK_KHR_android_surface it talks how querying support is not needed on Android
767 // The validation layers currently don't validate this VUID for Android surfaces
768 if (std::find(instance_extensions_.begin(), instance_extensions_.end(), VK_KHR_ANDROID_SURFACE_EXTENSION_NAME) !=
769 instance_extensions_.end()) {
770 printf("%s Test does not run on Android Surface, skipping test\n", kSkipPrefix);
771 return;
772 }
773#endif
774
775 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
776
sjfrickea83fbb92022-07-01 13:57:27 +0900777 if (!AreRequiredExtensionsEnabled()) {
778 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700779 }
780
sfricke-samsung459cb602021-07-26 22:19:58 -0700781 if (!InitSurface()) {
782 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
783 return;
784 }
785 InitSwapchainInfo();
786
Jeremy Gebben73904222021-10-21 15:46:25 -0600787 std::vector<VkQueueFamilyProperties> queue_families;
788 uint32_t count = 0;
789 vk::GetPhysicalDeviceQueueFamilyProperties(gpu(), &count, nullptr);
790 queue_families.resize(count);
791 vk::GetPhysicalDeviceQueueFamilyProperties(gpu(), &count, queue_families.data());
792
793 bool found = false;
794 uint32_t qfi = 0;
795 for (uint32_t i = 0; i < queue_families.size(); i++) {
796 VkBool32 supported = VK_FALSE;
797 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), i, m_surface, &supported);
798 if (!supported) {
799 found = true;
800 qfi = i;
801 break;
802 }
803 }
Jeremy Gebben73904222021-10-21 15:46:25 -0600804
805 if (!found) {
806 printf("%s All queues support surface present, skipping test\n", kSkipPrefix);
807 return;
808 }
809 float queue_priority = 1.0f;
810 auto queue_create_info = LvlInitStruct<VkDeviceQueueCreateInfo>();
811 queue_create_info.queueFamilyIndex = qfi;
812 queue_create_info.queueCount = 1;
813 queue_create_info.pQueuePriorities = &queue_priority;
814
815 auto device_create_info = LvlInitStruct<VkDeviceCreateInfo>();
816 device_create_info.queueCreateInfoCount = 1;
817 device_create_info.pQueueCreateInfos = &queue_create_info;
818 device_create_info.enabledExtensionCount = m_device_extension_names.size();
819 device_create_info.ppEnabledExtensionNames = m_device_extension_names.data();
820
821 vk_testing::Device test_device(gpu());
822 test_device.init(device_create_info);
823
824 // try creating a swapchain, using surface info queried from the default device
sfricke-samsung34c103f2021-12-31 02:04:18 -0600825 VkSwapchainCreateInfoKHR swapchain_create_info = LvlInitStruct<VkSwapchainCreateInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700826 swapchain_create_info.flags = 0;
827 swapchain_create_info.surface = m_surface;
828 swapchain_create_info.minImageCount = m_surface_capabilities.minImageCount;
829 swapchain_create_info.imageFormat = m_surface_formats[0].format;
830 swapchain_create_info.imageColorSpace = m_surface_formats[0].colorSpace;
831 swapchain_create_info.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
832 swapchain_create_info.imageArrayLayers = 1;
833 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
834 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
835 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
836 swapchain_create_info.compositeAlpha = m_surface_composite_alpha;
837 swapchain_create_info.presentMode = m_surface_non_shared_present_mode;
838 swapchain_create_info.clipped = VK_FALSE;
839 swapchain_create_info.oldSwapchain = 0;
840
sfricke-samsung459cb602021-07-26 22:19:58 -0700841 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-surface-01270");
Jeremy Gebben73904222021-10-21 15:46:25 -0600842 vk::CreateSwapchainKHR(test_device.handle(), &swapchain_create_info, nullptr, &m_swapchain);
sfricke-samsung459cb602021-07-26 22:19:58 -0700843 m_errorMonitor->VerifyFound();
844}
845
846TEST_F(VkLayerTest, SwapchainAcquireTooManyImages2KHR) {
847 TEST_DESCRIPTION("Acquiring invalid amount of images from the swapchain via vkAcquireNextImage2KHR.");
848 SetTargetApiVersion(VK_API_VERSION_1_1);
849
850 bool extension_dependency_satisfied = false;
851 if (InstanceExtensionSupported(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME)) {
852 m_instance_extension_names.push_back(VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME);
853 extension_dependency_satisfied = true;
854 }
855
sjfrickea83fbb92022-07-01 13:57:27 +0900856 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -0700857 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
858
sjfrickebdd58dd2022-05-20 14:22:50 +0900859 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
860 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
861 }
862
sfricke-samsung459cb602021-07-26 22:19:58 -0700863 if (extension_dependency_satisfied && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DEVICE_GROUP_EXTENSION_NAME)) {
864 m_device_extension_names.push_back(VK_KHR_DEVICE_GROUP_EXTENSION_NAME);
sfricke-samsung459cb602021-07-26 22:19:58 -0700865 }
866
sjfrickea83fbb92022-07-01 13:57:27 +0900867 if (!AreRequiredExtensionsEnabled()) {
868 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
869 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700870 ASSERT_NO_FATAL_FAILURE(InitState());
sfricke-samsungca162082022-02-10 08:53:41 -0800871 if (IsPlatform(kMockICD) || DeviceSimulation()) {
sjfricke11b24692022-06-21 20:49:53 +0900872 GTEST_SKIP() << "Test not supported by MockICD, will throw a std::bad_alloc sometimes";
sfricke-samsungca162082022-02-10 08:53:41 -0800873 }
sfricke-samsung459cb602021-07-26 22:19:58 -0700874 ASSERT_TRUE(InitSwapchain());
875 uint32_t image_count;
876 ASSERT_VK_SUCCESS(vk::GetSwapchainImagesKHR(device(), m_swapchain, &image_count, nullptr));
877 VkSurfaceCapabilitiesKHR caps;
878 ASSERT_VK_SUCCESS(vk::GetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), m_surface, &caps));
879
880 const uint32_t acquirable_count = image_count - caps.minImageCount + 1;
881 std::vector<VkFenceObj> fences(acquirable_count);
882 for (uint32_t i = 0; i < acquirable_count; ++i) {
883 fences[i].init(*m_device, VkFenceObj::create_info());
884 uint32_t image_i;
885 const auto res = vk::AcquireNextImageKHR(device(), m_swapchain, UINT64_MAX, VK_NULL_HANDLE, fences[i].handle(), &image_i);
886 ASSERT_TRUE(res == VK_SUCCESS || res == VK_SUBOPTIMAL_KHR);
887 }
888 VkFenceObj error_fence;
889 error_fence.init(*m_device, VkFenceObj::create_info());
890
891 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkAcquireNextImage2KHR-swapchain-01803");
sfricke-samsung34c103f2021-12-31 02:04:18 -0600892 VkAcquireNextImageInfoKHR acquire_info = LvlInitStruct<VkAcquireNextImageInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700893 acquire_info.swapchain = m_swapchain;
894 acquire_info.timeout = UINT64_MAX;
895 acquire_info.fence = error_fence.handle();
896 acquire_info.deviceMask = 0x1;
897
898 uint32_t image_i;
899 vk::AcquireNextImage2KHR(device(), &acquire_info, &image_i);
900 m_errorMonitor->VerifyFound();
901
902 // Cleanup
903 vk::WaitForFences(device(), fences.size(), MakeVkHandles<VkFence>(fences).data(), VK_TRUE, UINT64_MAX);
sfricke-samsung459cb602021-07-26 22:19:58 -0700904}
905
906TEST_F(VkLayerTest, InvalidSwapchainImageFormatList) {
907 TEST_DESCRIPTION("Test VK_KHR_image_format_list and VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR with swapchains");
908
sjfrickea83fbb92022-07-01 13:57:27 +0900909 AddSurfaceExtension();
sjfricked700bc02022-05-30 16:35:06 +0900910 AddRequiredExtensions(VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME);
911 AddRequiredExtensions(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
sfricke-samsung459cb602021-07-26 22:19:58 -0700912 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
913
sjfrickea83fbb92022-07-01 13:57:27 +0900914 if (!AreRequiredExtensionsEnabled()) {
915 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -0700916 }
sjfricked700bc02022-05-30 16:35:06 +0900917 if (!AreRequiredExtensionsEnabled()) {
918 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
sfricke-samsung459cb602021-07-26 22:19:58 -0700919 }
920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922 if (!InitSurface()) {
923 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
924 return;
925 }
926 InitSwapchainInfo();
927
928 VkBool32 supported;
929 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), m_device->graphics_queue_node_index_, m_surface, &supported);
930 if (!supported) {
931 printf("%s Graphics queue does not support present, skipping test\n", kSkipPrefix);
932 return;
933 }
934
935 // To make test use, assume a common surface format
936 VkSurfaceFormatKHR valid_surface_format{VK_FORMAT_UNDEFINED, VK_COLOR_SPACE_MAX_ENUM_KHR};
937 VkSurfaceFormatKHR other_surface_format{VK_FORMAT_UNDEFINED, VK_COLOR_SPACE_MAX_ENUM_KHR};
938 for (VkSurfaceFormatKHR surface_format : m_surface_formats) {
939 if (surface_format.format == VK_FORMAT_B8G8R8A8_UNORM) {
940 valid_surface_format = surface_format;
941 break;
942 } else {
943 other_surface_format = surface_format;
944 }
945 }
946 if (valid_surface_format.format == VK_FORMAT_UNDEFINED) {
947 printf("%s Test requires VK_FORMAT_B8G8R8A8_UNORM as a supported surface format, skipping test\n", kSkipPrefix);
948 return;
949 }
950
951 // Use sampled formats that will always be supported
952 // Last format is not compatible with the rest
953 const VkFormat formats[4] = {VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_SNORM, VK_FORMAT_R8G8B8A8_UINT, VK_FORMAT_R8_UNORM};
sfricke-samsung34c103f2021-12-31 02:04:18 -0600954 VkImageFormatListCreateInfo format_list = LvlInitStruct<VkImageFormatListCreateInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -0700955 format_list.viewFormatCount = 3; // first 3 are compatible
956 format_list.pViewFormats = formats;
957
sfricke-samsung34c103f2021-12-31 02:04:18 -0600958 VkSwapchainCreateInfoKHR swapchain_create_info = LvlInitStruct<VkSwapchainCreateInfoKHR>(&format_list);
sfricke-samsung459cb602021-07-26 22:19:58 -0700959 swapchain_create_info.flags = 0;
960 swapchain_create_info.surface = m_surface;
961 swapchain_create_info.minImageCount = m_surface_capabilities.minImageCount;
962 swapchain_create_info.imageFormat = valid_surface_format.format;
963 swapchain_create_info.imageColorSpace = valid_surface_format.colorSpace;
964 swapchain_create_info.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
965 swapchain_create_info.imageArrayLayers = 1;
966 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
967 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
968 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
969 swapchain_create_info.compositeAlpha = m_surface_composite_alpha;
970 swapchain_create_info.presentMode = m_surface_non_shared_present_mode;
971 swapchain_create_info.clipped = VK_FALSE;
972 swapchain_create_info.oldSwapchain = 0;
973
974 // No mutable flag
975 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-flags-04100");
976 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
977 m_errorMonitor->VerifyFound();
978 swapchain_create_info.flags = VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR;
979
980 // Last format is not compatible
981 format_list.viewFormatCount = 4;
982 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-pNext-04099");
983 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
984 m_errorMonitor->VerifyFound();
985
986 // viewFormatCount of 0
987 format_list.viewFormatCount = 0;
988 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-flags-03168");
989 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
990 m_errorMonitor->VerifyFound();
991 format_list.viewFormatCount = 3; // valid
992
993 // missing pNext
994 swapchain_create_info.pNext = nullptr;
995 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-flags-03168");
996 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
997 m_errorMonitor->VerifyFound();
998 swapchain_create_info.pNext = &format_list;
999
1000 // Another surface format is available and is not in list of viewFormats
1001 if (other_surface_format.format != VK_FORMAT_UNDEFINED) {
1002 swapchain_create_info.imageFormat = other_surface_format.format;
1003 swapchain_create_info.imageColorSpace = other_surface_format.colorSpace;
1004 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-flags-03168");
1005 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
1006 m_errorMonitor->VerifyFound();
1007 swapchain_create_info.imageFormat = valid_surface_format.format;
1008 swapchain_create_info.imageColorSpace = valid_surface_format.colorSpace;
1009 }
1010
sfricke-samsung459cb602021-07-26 22:19:58 -07001011 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
sfricke-samsung459cb602021-07-26 22:19:58 -07001012}
1013
1014TEST_F(VkLayerTest, SwapchainMinImageCountNonShared) {
1015 TEST_DESCRIPTION("Use invalid minImageCount for non shared swapchain creation");
sjfrickea83fbb92022-07-01 13:57:27 +09001016 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -07001017
1018 ASSERT_NO_FATAL_FAILURE(InitFramework());
1019
sjfrickea83fbb92022-07-01 13:57:27 +09001020 if (!AreRequiredExtensionsEnabled()) {
1021 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -07001022 }
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025 if (!InitSurface()) {
1026 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
1027 return;
1028 }
1029 InitSwapchainInfo();
1030 if (m_surface_capabilities.minImageCount <= 1) {
1031 printf("%s minImageCount is not at least 2, skipping test\n", kSkipPrefix);
1032 return;
1033 }
1034
1035 VkBool32 supported;
1036 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), m_device->graphics_queue_node_index_, m_surface, &supported);
1037 if (!supported) {
1038 printf("%s Graphics queue does not support present, skipping test\n", kSkipPrefix);
1039 return;
1040 }
1041
1042 VkSwapchainCreateInfoKHR swapchain_create_info = LvlInitStruct<VkSwapchainCreateInfoKHR>();
1043 swapchain_create_info.surface = m_surface;
1044 swapchain_create_info.minImageCount = 1; // invalid
1045 swapchain_create_info.imageFormat = m_surface_formats[0].format;
1046 swapchain_create_info.imageColorSpace = m_surface_formats[0].colorSpace;
1047 swapchain_create_info.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
1048 swapchain_create_info.imageArrayLayers = 1;
1049 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1050 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1051 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
1052 swapchain_create_info.compositeAlpha = m_surface_composite_alpha;
1053 swapchain_create_info.presentMode = m_surface_non_shared_present_mode;
1054 swapchain_create_info.clipped = VK_FALSE;
1055 swapchain_create_info.oldSwapchain = 0;
1056
1057 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-minImageCount-01271");
1058 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
1059 m_errorMonitor->VerifyFound();
1060
1061 // Sanity check
1062 swapchain_create_info.minImageCount = m_surface_capabilities.minImageCount;
sfricke-samsung459cb602021-07-26 22:19:58 -07001063 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
sfricke-samsung459cb602021-07-26 22:19:58 -07001064}
1065
1066TEST_F(VkLayerTest, SwapchainMinImageCountShared) {
1067 TEST_DESCRIPTION("Use invalid minImageCount for shared swapchain creation");
1068 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
1069 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1070 } else {
1071 printf("%s Extension %s not supported by device; skipped.\n", kSkipPrefix,
1072 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1073 return;
1074 }
1075 if (InstanceExtensionSupported(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME)) {
1076 m_instance_extension_names.push_back(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
1077 } else {
1078 printf("%s Extension %s not supported by device; skipped.\n", kSkipPrefix,
1079 VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
1080 return;
1081 }
sjfrickea83fbb92022-07-01 13:57:27 +09001082 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -07001083 ASSERT_NO_FATAL_FAILURE(InitFramework());
1084 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME)) {
1085 m_device_extension_names.push_back(VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME);
1086 } else {
1087 printf("%s Extension %s not supported by device; skipped.\n", kSkipPrefix, VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME);
1088 return;
1089 }
sjfrickea83fbb92022-07-01 13:57:27 +09001090 if (!AreRequiredExtensionsEnabled()) {
1091 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -07001092 }
1093
1094 ASSERT_NO_FATAL_FAILURE(InitState());
1095 if (!InitSurface()) {
1096 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
1097 return;
1098 }
1099 InitSwapchainInfo();
1100
1101 VkBool32 supported;
1102 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), m_device->graphics_queue_node_index_, m_surface, &supported);
1103 if (!supported) {
1104 printf("%s Graphics queue does not support present, skipping test\n", kSkipPrefix);
1105 return;
1106 }
1107
1108 VkPresentModeKHR shared_present_mode = m_surface_non_shared_present_mode;
1109 for (size_t i = 0; i < m_surface_present_modes.size(); i++) {
1110 const VkPresentModeKHR present_mode = m_surface_present_modes[i];
1111 if ((present_mode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR) ||
1112 (present_mode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR)) {
1113 shared_present_mode = present_mode;
1114 break;
1115 }
1116 }
1117 if (shared_present_mode == m_surface_non_shared_present_mode) {
1118 printf("%s Cannot find supported shared present mode, skipping test\n", kSkipPrefix);
1119 return;
1120 }
1121
1122 PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR vkGetPhysicalDeviceSurfaceCapabilities2KHR =
1123 (PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR)vk::GetInstanceProcAddr(instance(),
1124 "vkGetPhysicalDeviceSurfaceCapabilities2KHR");
1125 ASSERT_TRUE(vkGetPhysicalDeviceSurfaceCapabilities2KHR != nullptr);
1126
1127 VkSharedPresentSurfaceCapabilitiesKHR shared_present_capabilities = LvlInitStruct<VkSharedPresentSurfaceCapabilitiesKHR>();
1128 VkSurfaceCapabilities2KHR capabilities = LvlInitStruct<VkSurfaceCapabilities2KHR>(&shared_present_capabilities);
1129 VkPhysicalDeviceSurfaceInfo2KHR surface_info = LvlInitStruct<VkPhysicalDeviceSurfaceInfo2KHR>();
1130 surface_info.surface = m_surface;
1131 vkGetPhysicalDeviceSurfaceCapabilities2KHR(gpu(), &surface_info, &capabilities);
1132
1133 // This was recently added to CTS, but some drivers might not correctly advertise the flag
1134 if ((shared_present_capabilities.sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0) {
1135 printf("%s Driver was suppose to support VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, skipping test\n", kSkipPrefix);
1136 return;
1137 }
1138
1139 VkSwapchainCreateInfoKHR swapchain_create_info = LvlInitStruct<VkSwapchainCreateInfoKHR>();
1140 swapchain_create_info.surface = m_surface;
1141 swapchain_create_info.minImageCount = 2; // invalid
1142 swapchain_create_info.imageFormat = m_surface_formats[0].format;
1143 swapchain_create_info.imageColorSpace = m_surface_formats[0].colorSpace;
1144 swapchain_create_info.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
1145 swapchain_create_info.imageArrayLayers = 1;
1146 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; // implementations must support
1147 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1148 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
1149 swapchain_create_info.compositeAlpha = m_surface_composite_alpha;
1150 swapchain_create_info.presentMode = shared_present_mode;
1151 swapchain_create_info.clipped = VK_FALSE;
1152 swapchain_create_info.oldSwapchain = 0;
1153
1154 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-minImageCount-01383");
1155 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
1156 m_errorMonitor->VerifyFound();
1157
1158 // Sanity check
1159 swapchain_create_info.minImageCount = 1;
sfricke-samsung459cb602021-07-26 22:19:58 -07001160 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
sfricke-samsung459cb602021-07-26 22:19:58 -07001161}
1162
1163TEST_F(VkLayerTest, SwapchainInvalidUsageNonShared) {
1164 TEST_DESCRIPTION("Use invalid imageUsage for non-shared swapchain creation");
sjfrickea83fbb92022-07-01 13:57:27 +09001165 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -07001166
1167 ASSERT_NO_FATAL_FAILURE(InitFramework());
1168
sjfrickea83fbb92022-07-01 13:57:27 +09001169 if (!AreRequiredExtensionsEnabled()) {
1170 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -07001171 }
1172
1173 ASSERT_NO_FATAL_FAILURE(InitState());
1174 if (!InitSurface()) {
1175 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
1176 return;
1177 }
1178 InitSwapchainInfo();
1179
1180 VkBool32 supported;
1181 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), m_device->graphics_queue_node_index_, m_surface, &supported);
1182 if (!supported) {
1183 printf("%s Graphics queue does not support present, skipping test\n", kSkipPrefix);
1184 return;
1185 }
1186
1187 // No implementation should support depth/stencil for swapchain
1188 if ((m_surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0) {
1189 printf("%s Test has supported usage already the test is using, skipping test\n", kSkipPrefix);
1190 return;
1191 }
1192
1193 VkSwapchainCreateInfoKHR swapchain_create_info = LvlInitStruct<VkSwapchainCreateInfoKHR>();
1194 swapchain_create_info.surface = m_surface;
1195 swapchain_create_info.minImageCount = m_surface_capabilities.minImageCount;
1196 swapchain_create_info.imageFormat = m_surface_formats[0].format;
1197 swapchain_create_info.imageColorSpace = m_surface_formats[0].colorSpace;
1198 swapchain_create_info.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
1199 swapchain_create_info.imageArrayLayers = 1;
1200 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1201 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1202 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
1203 swapchain_create_info.compositeAlpha = m_surface_composite_alpha;
1204 swapchain_create_info.presentMode = m_surface_non_shared_present_mode;
1205 swapchain_create_info.clipped = VK_FALSE;
1206 swapchain_create_info.oldSwapchain = 0;
1207
1208 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-imageUsage-01276");
1209 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
1210 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -07001211}
1212
1213TEST_F(VkLayerTest, SwapchainInvalidUsageShared) {
1214 TEST_DESCRIPTION("Use invalid imageUsage for shared swapchain creation");
1215 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
1216 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1217 } else {
1218 printf("%s Extension %s not supported by device; skipped.\n", kSkipPrefix,
1219 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1220 return;
1221 }
1222 if (InstanceExtensionSupported(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME)) {
1223 m_instance_extension_names.push_back(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
1224 } else {
1225 printf("%s Extension %s not supported by device; skipped.\n", kSkipPrefix,
1226 VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
1227 return;
1228 }
sjfrickea83fbb92022-07-01 13:57:27 +09001229 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -07001230
1231 ASSERT_NO_FATAL_FAILURE(InitFramework());
1232 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME)) {
1233 m_device_extension_names.push_back(VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME);
1234 } else {
1235 printf("%s Extension %s not supported by device; skipped.\n", kSkipPrefix, VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME);
1236 return;
1237 }
sjfrickea83fbb92022-07-01 13:57:27 +09001238 if (!AreRequiredExtensionsEnabled()) {
1239 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -07001240 }
1241
1242 ASSERT_NO_FATAL_FAILURE(InitState());
1243 if (!InitSurface()) {
1244 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
1245 return;
1246 }
1247 InitSwapchainInfo();
1248
1249 VkBool32 supported;
1250 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), m_device->graphics_queue_node_index_, m_surface, &supported);
1251 if (!supported) {
1252 printf("%s Graphics queue does not support present, skipping test\n", kSkipPrefix);
1253 return;
1254 }
1255
1256 VkPresentModeKHR shared_present_mode = m_surface_non_shared_present_mode;
1257 for (size_t i = 0; i < m_surface_present_modes.size(); i++) {
1258 const VkPresentModeKHR present_mode = m_surface_present_modes[i];
1259 if ((present_mode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR) ||
1260 (present_mode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR)) {
1261 shared_present_mode = present_mode;
1262 break;
1263 }
1264 }
1265 if (shared_present_mode == m_surface_non_shared_present_mode) {
1266 printf("%s Cannot find supported shared present mode, skipping test\n", kSkipPrefix);
1267 return;
1268 }
1269
1270 PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR vkGetPhysicalDeviceSurfaceCapabilities2KHR =
1271 (PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR)vk::GetInstanceProcAddr(instance(),
1272 "vkGetPhysicalDeviceSurfaceCapabilities2KHR");
1273 ASSERT_TRUE(vkGetPhysicalDeviceSurfaceCapabilities2KHR != nullptr);
1274
1275 VkSharedPresentSurfaceCapabilitiesKHR shared_present_capabilities = LvlInitStruct<VkSharedPresentSurfaceCapabilitiesKHR>();
1276 VkSurfaceCapabilities2KHR capabilities = LvlInitStruct<VkSurfaceCapabilities2KHR>(&shared_present_capabilities);
1277 VkPhysicalDeviceSurfaceInfo2KHR surface_info = LvlInitStruct<VkPhysicalDeviceSurfaceInfo2KHR>();
1278 surface_info.surface = m_surface;
1279 vkGetPhysicalDeviceSurfaceCapabilities2KHR(gpu(), &surface_info, &capabilities);
1280
1281 // No implementation should support depth/stencil for swapchain
1282 if ((shared_present_capabilities.sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0) {
1283 printf("%s Test has supported usage already the test is using, skipping test\n", kSkipPrefix);
1284 return;
1285 }
1286
1287 VkSwapchainCreateInfoKHR swapchain_create_info = LvlInitStruct<VkSwapchainCreateInfoKHR>();
1288 swapchain_create_info.surface = m_surface;
1289 swapchain_create_info.minImageCount = 1;
1290 swapchain_create_info.imageFormat = m_surface_formats[0].format;
1291 swapchain_create_info.imageColorSpace = m_surface_formats[0].colorSpace;
1292 swapchain_create_info.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
1293 swapchain_create_info.imageArrayLayers = 1;
1294 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1295 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
1296 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
1297 swapchain_create_info.compositeAlpha = m_surface_composite_alpha;
1298 swapchain_create_info.presentMode = shared_present_mode;
1299 swapchain_create_info.clipped = VK_FALSE;
1300 swapchain_create_info.oldSwapchain = 0;
1301
1302 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-imageUsage-01384");
1303 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &m_swapchain);
1304 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -07001305}
1306
1307TEST_F(VkLayerTest, InvalidDeviceMask) {
1308 TEST_DESCRIPTION("Invalid deviceMask.");
1309 SetTargetApiVersion(VK_API_VERSION_1_1);
1310
sjfrickea83fbb92022-07-01 13:57:27 +09001311 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -07001312
1313 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
1314
sjfrickea83fbb92022-07-01 13:57:27 +09001315 if (!AreRequiredExtensionsEnabled()) {
1316 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -07001317 }
1318
1319 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001320 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
sfricke-samsung459cb602021-07-26 22:19:58 -07001321 }
1322 uint32_t physical_device_group_count = 0;
1323 vk::EnumeratePhysicalDeviceGroups(instance(), &physical_device_group_count, nullptr);
1324
1325 if (physical_device_group_count == 0) {
1326 printf("%s physical_device_group_count is 0, skipping test\n", kSkipPrefix);
1327 return;
1328 }
1329
1330 std::vector<VkPhysicalDeviceGroupProperties> physical_device_group(physical_device_group_count,
1331 {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
1332 vk::EnumeratePhysicalDeviceGroups(instance(), &physical_device_group_count, physical_device_group.data());
sfricke-samsung34c103f2021-12-31 02:04:18 -06001333 VkDeviceGroupDeviceCreateInfo create_device_pnext = LvlInitStruct<VkDeviceGroupDeviceCreateInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -07001334 create_device_pnext.physicalDeviceCount = physical_device_group[0].physicalDeviceCount;
1335 create_device_pnext.pPhysicalDevices = physical_device_group[0].physicalDevices;
1336 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &create_device_pnext, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1337 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1338
1339 if (!InitSwapchain()) {
1340 printf("%s Cannot create surface or swapchain, skipping VkAcquireNextImageInfoKHR test\n", kSkipPrefix);
sjfrickea83fbb92022-07-01 13:57:27 +09001341 return;
sfricke-samsung459cb602021-07-26 22:19:58 -07001342 }
1343
1344 // Test VkMemoryAllocateFlagsInfo
sfricke-samsung34c103f2021-12-31 02:04:18 -06001345 VkMemoryAllocateFlagsInfo alloc_flags_info = LvlInitStruct<VkMemoryAllocateFlagsInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -07001346 alloc_flags_info.flags = VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT;
1347 alloc_flags_info.deviceMask = 0xFFFFFFFF;
sfricke-samsung34c103f2021-12-31 02:04:18 -06001348 VkMemoryAllocateInfo alloc_info = LvlInitStruct<VkMemoryAllocateInfo>(&alloc_flags_info);
sfricke-samsung459cb602021-07-26 22:19:58 -07001349 alloc_info.memoryTypeIndex = 0;
1350 alloc_info.allocationSize = 1024;
1351
1352 VkDeviceMemory mem;
1353 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkMemoryAllocateFlagsInfo-deviceMask-00675");
1354 vk::AllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1355 m_errorMonitor->VerifyFound();
1356
1357 alloc_flags_info.deviceMask = 0;
1358 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkMemoryAllocateFlagsInfo-deviceMask-00676");
1359 vk::AllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1360 m_errorMonitor->VerifyFound();
1361
1362 uint32_t pdev_group_count = 0;
sfricke-samsung459cb602021-07-26 22:19:58 -07001363 VkResult err = vk::EnumeratePhysicalDeviceGroups(instance(), &pdev_group_count, nullptr);
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001364 // TODO: initialization can be removed once https://github.com/KhronosGroup/Vulkan-ValidationLayers/pull/4138 merges
1365 std::vector<VkPhysicalDeviceGroupProperties> group_props(pdev_group_count,
1366 {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
sfricke-samsung459cb602021-07-26 22:19:58 -07001367 err = vk::EnumeratePhysicalDeviceGroups(instance(), &pdev_group_count, &group_props[0]);
1368
1369 auto tgt = gpu();
1370 bool test_run = false;
1371 for (uint32_t i = 0; i < pdev_group_count; i++) {
1372 if ((group_props[i].physicalDeviceCount > 1) && !test_run) {
1373 for (uint32_t j = 0; j < group_props[i].physicalDeviceCount; j++) {
1374 if (tgt == group_props[i].physicalDevices[j]) {
1375 void *data;
1376 VkDeviceMemory mi_mem;
1377 alloc_flags_info.deviceMask = 3;
1378 err = vk::AllocateMemory(m_device->device(), &alloc_info, NULL, &mi_mem);
1379 if (VK_SUCCESS == err) {
1380 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkMapMemory-memory-00683");
1381 vk::MapMemory(m_device->device(), mi_mem, 0, 1024, 0, &data);
1382 m_errorMonitor->VerifyFound();
1383 vk::FreeMemory(m_device->device(), mi_mem, nullptr);
1384 }
1385 test_run = true;
1386 break;
1387 }
1388 }
1389 }
1390 }
1391
1392 // Test VkDeviceGroupCommandBufferBeginInfo
sfricke-samsung34c103f2021-12-31 02:04:18 -06001393 VkDeviceGroupCommandBufferBeginInfo dev_grp_cmd_buf_info = LvlInitStruct<VkDeviceGroupCommandBufferBeginInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -07001394 dev_grp_cmd_buf_info.deviceMask = 0xFFFFFFFF;
sfricke-samsung34c103f2021-12-31 02:04:18 -06001395 VkCommandBufferBeginInfo cmd_buf_info = LvlInitStruct<VkCommandBufferBeginInfo>(&dev_grp_cmd_buf_info);
sfricke-samsung459cb602021-07-26 22:19:58 -07001396
1397 m_commandBuffer->reset();
1398 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupCommandBufferBeginInfo-deviceMask-00106");
1399 vk::BeginCommandBuffer(m_commandBuffer->handle(), &cmd_buf_info);
1400 m_errorMonitor->VerifyFound();
1401
1402 dev_grp_cmd_buf_info.deviceMask = 0;
1403 m_commandBuffer->reset();
1404 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupCommandBufferBeginInfo-deviceMask-00107");
1405 vk::BeginCommandBuffer(m_commandBuffer->handle(), &cmd_buf_info);
1406 m_errorMonitor->VerifyFound();
1407
1408 // Test VkDeviceGroupRenderPassBeginInfo
1409 dev_grp_cmd_buf_info.deviceMask = 0x00000001;
1410 m_commandBuffer->reset();
1411 vk::BeginCommandBuffer(m_commandBuffer->handle(), &cmd_buf_info);
1412
sfricke-samsung34c103f2021-12-31 02:04:18 -06001413 VkDeviceGroupRenderPassBeginInfo dev_grp_rp_info = LvlInitStruct<VkDeviceGroupRenderPassBeginInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -07001414 dev_grp_rp_info.deviceMask = 0xFFFFFFFF;
1415 m_renderPassBeginInfo.pNext = &dev_grp_rp_info;
1416
1417 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupRenderPassBeginInfo-deviceMask-00905");
1418 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupRenderPassBeginInfo-deviceMask-00907");
1419 vk::CmdBeginRenderPass(m_commandBuffer->handle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1420 m_errorMonitor->VerifyFound();
1421
1422 dev_grp_rp_info.deviceMask = 0;
1423 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupRenderPassBeginInfo-deviceMask-00906");
1424 vk::CmdBeginRenderPass(m_commandBuffer->handle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1425 m_errorMonitor->VerifyFound();
1426
1427 dev_grp_rp_info.deviceMask = 0x00000001;
1428 dev_grp_rp_info.deviceRenderAreaCount = physical_device_group[0].physicalDeviceCount + 1;
1429 std::vector<VkRect2D> device_render_areas(dev_grp_rp_info.deviceRenderAreaCount, m_renderPassBeginInfo.renderArea);
1430 dev_grp_rp_info.pDeviceRenderAreas = device_render_areas.data();
1431
1432 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupRenderPassBeginInfo-deviceRenderAreaCount-00908");
1433 vk::CmdBeginRenderPass(m_commandBuffer->handle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1434 m_errorMonitor->VerifyFound();
1435
1436 // Test vk::CmdSetDeviceMask()
1437 vk::CmdSetDeviceMask(m_commandBuffer->handle(), 0x00000001);
1438
1439 dev_grp_rp_info.deviceRenderAreaCount = physical_device_group[0].physicalDeviceCount;
1440 vk::CmdBeginRenderPass(m_commandBuffer->handle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1441 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdSetDeviceMask-deviceMask-00108");
1442 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdSetDeviceMask-deviceMask-00110");
1443 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdSetDeviceMask-deviceMask-00111");
1444 vk::CmdSetDeviceMask(m_commandBuffer->handle(), 0xFFFFFFFF);
1445 m_errorMonitor->VerifyFound();
1446
1447 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdSetDeviceMask-deviceMask-00109");
1448 vk::CmdSetDeviceMask(m_commandBuffer->handle(), 0);
1449 m_errorMonitor->VerifyFound();
1450
sfricke-samsung34c103f2021-12-31 02:04:18 -06001451 VkSemaphoreCreateInfo semaphore_create_info = LvlInitStruct<VkSemaphoreCreateInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -07001452 VkSemaphore semaphore;
1453 ASSERT_VK_SUCCESS(vk::CreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
1454 VkSemaphore semaphore2;
1455 ASSERT_VK_SUCCESS(vk::CreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2));
sfricke-samsung34c103f2021-12-31 02:04:18 -06001456 VkFenceCreateInfo fence_create_info = LvlInitStruct<VkFenceCreateInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -07001457 VkFence fence;
1458 ASSERT_VK_SUCCESS(vk::CreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
1459
sjfrickea83fbb92022-07-01 13:57:27 +09001460 // Test VkAcquireNextImageInfoKHR
1461 uint32_t imageIndex;
1462 VkAcquireNextImageInfoKHR acquire_next_image_info = LvlInitStruct<VkAcquireNextImageInfoKHR>();
1463 acquire_next_image_info.semaphore = semaphore;
1464 acquire_next_image_info.swapchain = m_swapchain;
1465 acquire_next_image_info.fence = fence;
1466 acquire_next_image_info.deviceMask = 0xFFFFFFFF;
sfricke-samsung459cb602021-07-26 22:19:58 -07001467
sjfrickea83fbb92022-07-01 13:57:27 +09001468 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkAcquireNextImageInfoKHR-deviceMask-01290");
1469 vk::AcquireNextImage2KHR(m_device->device(), &acquire_next_image_info, &imageIndex);
1470 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -07001471
sjfrickea83fbb92022-07-01 13:57:27 +09001472 vk::WaitForFences(m_device->device(), 1, &fence, VK_TRUE, std::numeric_limits<int>::max());
1473 vk::ResetFences(m_device->device(), 1, &fence);
sfricke-samsung459cb602021-07-26 22:19:58 -07001474
sjfrickea83fbb92022-07-01 13:57:27 +09001475 acquire_next_image_info.semaphore = semaphore2;
1476 acquire_next_image_info.deviceMask = 0;
sfricke-samsung459cb602021-07-26 22:19:58 -07001477
sjfrickea83fbb92022-07-01 13:57:27 +09001478 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkAcquireNextImageInfoKHR-deviceMask-01291");
1479 vk::AcquireNextImage2KHR(m_device->device(), &acquire_next_image_info, &imageIndex);
1480 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -07001481
1482 // Test VkDeviceGroupSubmitInfo
sfricke-samsung34c103f2021-12-31 02:04:18 -06001483 VkDeviceGroupSubmitInfo device_group_submit_info = LvlInitStruct<VkDeviceGroupSubmitInfo>();
sfricke-samsung459cb602021-07-26 22:19:58 -07001484 device_group_submit_info.commandBufferCount = 1;
1485 std::array<uint32_t, 1> command_buffer_device_masks = {{0xFFFFFFFF}};
1486 device_group_submit_info.pCommandBufferDeviceMasks = command_buffer_device_masks.data();
1487
sfricke-samsung34c103f2021-12-31 02:04:18 -06001488 VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>(&device_group_submit_info);
sfricke-samsung459cb602021-07-26 22:19:58 -07001489 submit_info.commandBufferCount = 1;
1490 submit_info.pCommandBuffers = &m_commandBuffer->handle();
1491
1492 m_commandBuffer->reset();
1493 vk::BeginCommandBuffer(m_commandBuffer->handle(), &cmd_buf_info);
1494 vk::EndCommandBuffer(m_commandBuffer->handle());
1495 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupSubmitInfo-pCommandBufferDeviceMasks-00086");
1496 vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1497 m_errorMonitor->VerifyFound();
1498 vk::QueueWaitIdle(m_device->m_queue);
1499
1500 vk::WaitForFences(m_device->device(), 1, &fence, VK_TRUE, std::numeric_limits<int>::max());
1501 vk::DestroyFence(m_device->device(), fence, nullptr);
1502 vk::DestroySemaphore(m_device->device(), semaphore, nullptr);
1503 vk::DestroySemaphore(m_device->device(), semaphore2, nullptr);
1504}
1505
1506TEST_F(VkLayerTest, DisplayPlaneSurface) {
1507 TEST_DESCRIPTION("Create and use VkDisplayKHR objects to test VkDisplaySurfaceCreateInfoKHR.");
1508
sjfrickea83fbb92022-07-01 13:57:27 +09001509 AddSurfaceExtension();
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001510 AddRequiredExtensions(VK_KHR_DISPLAY_EXTENSION_NAME);
sfricke-samsung459cb602021-07-26 22:19:58 -07001511 ASSERT_NO_FATAL_FAILURE(Init());
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001512 if (!AreRequiredExtensionsEnabled()) {
1513 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
1514 }
sfricke-samsung459cb602021-07-26 22:19:58 -07001515
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001516 if (!InitSurface()) {
1517 GTEST_SKIP() << "Failed to create surface. Skipping.";
sfricke-samsung459cb602021-07-26 22:19:58 -07001518 }
1519
1520 // Load all VK_KHR_display functions
1521 PFN_vkCreateDisplayModeKHR vkCreateDisplayModeKHR =
1522 (PFN_vkCreateDisplayModeKHR)vk::GetInstanceProcAddr(instance(), "vkCreateDisplayModeKHR");
1523 PFN_vkCreateDisplayPlaneSurfaceKHR vkCreateDisplayPlaneSurfaceKHR =
1524 (PFN_vkCreateDisplayPlaneSurfaceKHR)vk::GetInstanceProcAddr(instance(), "vkCreateDisplayPlaneSurfaceKHR");
1525 PFN_vkGetDisplayPlaneSupportedDisplaysKHR vkGetDisplayPlaneSupportedDisplaysKHR =
1526 (PFN_vkGetDisplayPlaneSupportedDisplaysKHR)vk::GetInstanceProcAddr(instance(), "vkGetDisplayPlaneSupportedDisplaysKHR");
1527 PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR vkGetPhysicalDeviceDisplayPlanePropertiesKHR =
1528 (PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR)vk::GetInstanceProcAddr(instance(),
1529 "vkGetPhysicalDeviceDisplayPlanePropertiesKHR");
1530 PFN_vkGetDisplayModePropertiesKHR vkGetDisplayModePropertiesKHR =
1531 (PFN_vkGetDisplayModePropertiesKHR)vk::GetInstanceProcAddr(instance(), "vkGetDisplayModePropertiesKHR");
1532 PFN_vkGetDisplayPlaneCapabilitiesKHR vkGetDisplayPlaneCapabilitiesKHR =
1533 (PFN_vkGetDisplayPlaneCapabilitiesKHR)vk::GetInstanceProcAddr(instance(), "vkGetDisplayPlaneCapabilitiesKHR");
1534 ASSERT_TRUE(vkCreateDisplayModeKHR != nullptr);
1535 ASSERT_TRUE(vkCreateDisplayPlaneSurfaceKHR != nullptr);
1536 ASSERT_TRUE(vkGetDisplayPlaneSupportedDisplaysKHR != nullptr);
1537 ASSERT_TRUE(vkGetPhysicalDeviceDisplayPlanePropertiesKHR != nullptr);
1538 ASSERT_TRUE(vkGetDisplayModePropertiesKHR != nullptr);
1539 ASSERT_TRUE(vkGetDisplayPlaneCapabilitiesKHR != nullptr);
1540
1541 uint32_t plane_prop_count = 0;
1542 vkGetPhysicalDeviceDisplayPlanePropertiesKHR(gpu(), &plane_prop_count, nullptr);
1543 if (plane_prop_count == 0) {
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001544 GTEST_SKIP() << "Test requires at least 1 supported display plane property. Skipping.";
sfricke-samsung459cb602021-07-26 22:19:58 -07001545 }
1546 std::vector<VkDisplayPlanePropertiesKHR> display_plane_props(plane_prop_count);
1547 vkGetPhysicalDeviceDisplayPlanePropertiesKHR(gpu(), &plane_prop_count, display_plane_props.data());
1548 // using plane 0 for rest of test
1549 VkDisplayKHR current_display = display_plane_props[0].currentDisplay;
1550 if (current_display == VK_NULL_HANDLE) {
1551 printf("%s VkDisplayPlanePropertiesKHR[0].currentDisplay is not attached to device. Skipping.\n", kSkipPrefix);
1552 return;
1553 }
1554
1555 uint32_t mode_prop_count = 0;
1556 vkGetDisplayModePropertiesKHR(gpu(), current_display, &mode_prop_count, nullptr);
1557 if (plane_prop_count == 0) {
1558 printf("%s test requires at least 1 supported display mode property. Skipping.\n", kSkipPrefix);
1559 return;
1560 }
1561 std::vector<VkDisplayModePropertiesKHR> display_mode_props(mode_prop_count);
1562 vkGetDisplayModePropertiesKHR(gpu(), current_display, &mode_prop_count, display_mode_props.data());
1563
1564 uint32_t plane_count;
1565 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetDisplayPlaneSupportedDisplaysKHR-planeIndex-01249");
1566 vkGetDisplayPlaneSupportedDisplaysKHR(gpu(), plane_prop_count, &plane_count, nullptr);
1567 m_errorMonitor->VerifyFound();
1568 ASSERT_VK_SUCCESS(vkGetDisplayPlaneSupportedDisplaysKHR(gpu(), 0, &plane_count, nullptr));
1569 if (plane_count == 0) {
1570 printf("%s test requires at least 1 supported display plane. Skipping.\n", kSkipPrefix);
1571 return;
1572 }
1573 std::vector<VkDisplayKHR> supported_displays(plane_count);
1574 plane_count = 1;
1575 ASSERT_VK_SUCCESS(vkGetDisplayPlaneSupportedDisplaysKHR(gpu(), 0, &plane_count, supported_displays.data()));
1576 if (supported_displays[0] != current_display) {
1577 printf("%s Current VkDisplayKHR used is not supported. Skipping.\n", kSkipPrefix);
1578 return;
1579 }
1580
1581 VkDisplayModeKHR display_mode;
1582 VkDisplayModeParametersKHR display_mode_parameters = {{0, 0}, 0};
1583 VkDisplayModeCreateInfoKHR display_mode_info = {VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR, nullptr, 0,
1584 display_mode_parameters};
1585 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplayModeParametersKHR-width-01990");
1586 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplayModeParametersKHR-height-01991");
1587 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplayModeParametersKHR-refreshRate-01992");
1588 vkCreateDisplayModeKHR(gpu(), current_display, &display_mode_info, nullptr, &display_mode);
1589 m_errorMonitor->VerifyFound();
1590 // Use the first good parameter queried
1591 display_mode_info.parameters = display_mode_props[0].parameters;
1592 VkResult result = vkCreateDisplayModeKHR(gpu(), current_display, &display_mode_info, nullptr, &display_mode);
1593 if (result != VK_SUCCESS) {
1594 printf("%s test failed to create a display mode with vkCreateDisplayModeKHR. Skipping.\n", kSkipPrefix);
1595 return;
1596 }
1597
1598 VkDisplayPlaneCapabilitiesKHR plane_capabilities;
1599 ASSERT_VK_SUCCESS(vkGetDisplayPlaneCapabilitiesKHR(gpu(), display_mode, 0, &plane_capabilities));
1600
1601 VkSurfaceKHR surface;
sfricke-samsung34c103f2021-12-31 02:04:18 -06001602 VkDisplaySurfaceCreateInfoKHR display_surface_info = LvlInitStruct<VkDisplaySurfaceCreateInfoKHR>();
sfricke-samsung459cb602021-07-26 22:19:58 -07001603 display_surface_info.flags = 0;
1604 display_surface_info.displayMode = display_mode;
1605 display_surface_info.planeIndex = 0;
1606 display_surface_info.planeStackIndex = 0;
1607 display_surface_info.transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
1608 display_surface_info.imageExtent = {8, 8};
1609 display_surface_info.globalAlpha = 1.0f;
1610
1611 // Test if the device doesn't support the bits
1612 if ((plane_capabilities.supportedAlpha & VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR) == 0) {
1613 display_surface_info.alphaMode = VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR;
1614 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplaySurfaceCreateInfoKHR-alphaMode-01255");
1615 vkCreateDisplayPlaneSurfaceKHR(instance(), &display_surface_info, nullptr, &surface);
1616 m_errorMonitor->VerifyFound();
1617 }
1618 if ((plane_capabilities.supportedAlpha & VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR) == 0) {
1619 display_surface_info.alphaMode = VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR;
1620 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplaySurfaceCreateInfoKHR-alphaMode-01255");
1621 vkCreateDisplayPlaneSurfaceKHR(instance(), &display_surface_info, nullptr, &surface);
1622 m_errorMonitor->VerifyFound();
1623 }
1624
1625 display_surface_info.globalAlpha = 2.0f;
1626 display_surface_info.alphaMode = VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR;
1627 if ((plane_capabilities.supportedAlpha & VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR) == 0) {
1628 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplaySurfaceCreateInfoKHR-alphaMode-01255");
1629 }
1630 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplaySurfaceCreateInfoKHR-alphaMode-01254");
1631 vkCreateDisplayPlaneSurfaceKHR(instance(), &display_surface_info, nullptr, &surface);
1632 m_errorMonitor->VerifyFound();
1633
1634 display_surface_info.alphaMode = VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR;
1635 display_surface_info.planeIndex = plane_prop_count;
1636 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplaySurfaceCreateInfoKHR-planeIndex-01252");
1637 vkCreateDisplayPlaneSurfaceKHR(instance(), &display_surface_info, nullptr, &surface);
1638 m_errorMonitor->VerifyFound();
1639 display_surface_info.planeIndex = 0; // restore to good value
1640
1641 uint32_t bad_size = m_device->phy().properties().limits.maxImageDimension2D + 1;
1642 display_surface_info.imageExtent = {bad_size, bad_size};
1643 // one for height and width
1644 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplaySurfaceCreateInfoKHR-width-01256");
1645 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplaySurfaceCreateInfoKHR-width-01256");
1646 vkCreateDisplayPlaneSurfaceKHR(instance(), &display_surface_info, nullptr, &surface);
1647 m_errorMonitor->VerifyFound();
1648}
1649
1650TEST_F(VkLayerTest, WarningSwapchainCreateInfoPreTransform) {
1651 TEST_DESCRIPTION("Print warning when preTransform doesn't match curretTransform");
1652
sjfrickea83fbb92022-07-01 13:57:27 +09001653 AddSurfaceExtension();
sfricke-samsung459cb602021-07-26 22:19:58 -07001654
1655 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
1656
sjfrickea83fbb92022-07-01 13:57:27 +09001657 if (!AreRequiredExtensionsEnabled()) {
1658 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
sfricke-samsung459cb602021-07-26 22:19:58 -07001659 }
1660
1661 ASSERT_NO_FATAL_FAILURE(InitState());
1662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1663
1664 m_errorMonitor->SetDesiredFailureMsg(kPerformanceWarningBit, "UNASSIGNED-CoreValidation-SwapchainPreTransform");
1665 m_errorMonitor->SetUnexpectedError("VUID-VkSwapchainCreateInfoKHR-preTransform-01279");
1666 InitSwapchain(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR);
1667 m_errorMonitor->VerifyFound();
sfricke-samsung459cb602021-07-26 22:19:58 -07001668}
ziga-lunarg3b615b62021-08-01 12:29:36 +02001669
ziga-lunarg607821a2021-08-01 14:27:59 +02001670TEST_F(VkLayerTest, DeviceGroupSubmitInfoSemaphoreCount) {
1671 TEST_DESCRIPTION("Test semaphoreCounts in DeviceGroupSubmitInfo");
1672
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001673 SetTargetApiVersion(VK_API_VERSION_1_1);
1674 AddRequiredExtensions(VK_KHR_DEVICE_GROUP_EXTENSION_NAME);
1675 ASSERT_NO_FATAL_FAILURE(InitFramework());
1676 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
1677 GTEST_SKIP() << "Vulkan >= 1.1 required";
ziga-lunarg607821a2021-08-01 14:27:59 +02001678 }
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001679 if (!AreRequiredExtensionsEnabled()) {
1680 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
ziga-lunarg607821a2021-08-01 14:27:59 +02001681 }
ziga-lunarg607821a2021-08-01 14:27:59 +02001682
1683 uint32_t physical_device_group_count = 0;
1684 vk::EnumeratePhysicalDeviceGroups(instance(), &physical_device_group_count, nullptr);
1685
1686 if (physical_device_group_count == 0) {
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001687 GTEST_SKIP() << "physical_device_group_count is 0, skipping test";
ziga-lunarg607821a2021-08-01 14:27:59 +02001688 }
1689
1690 std::vector<VkPhysicalDeviceGroupProperties> physical_device_group(physical_device_group_count,
1691 {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
1692 vk::EnumeratePhysicalDeviceGroups(instance(), &physical_device_group_count, physical_device_group.data());
1693 VkDeviceGroupDeviceCreateInfo create_device_pnext = LvlInitStruct<VkDeviceGroupDeviceCreateInfo>();
1694 create_device_pnext.physicalDeviceCount = physical_device_group[0].physicalDeviceCount;
1695 create_device_pnext.pPhysicalDevices = physical_device_group[0].physicalDevices;
1696 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &create_device_pnext, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1697
1698 VkDeviceGroupCommandBufferBeginInfo dev_grp_cmd_buf_info = LvlInitStruct<VkDeviceGroupCommandBufferBeginInfo>();
ziga-lunarg93fba132021-10-02 14:14:46 +02001699 dev_grp_cmd_buf_info.deviceMask = 0x1;
ziga-lunarg607821a2021-08-01 14:27:59 +02001700 VkCommandBufferBeginInfo cmd_buf_info = LvlInitStruct<VkCommandBufferBeginInfo>(&dev_grp_cmd_buf_info);
1701
1702 VkSemaphoreCreateInfo semaphore_create_info = LvlInitStruct<VkSemaphoreCreateInfo>();
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001703 vk_testing::Semaphore semaphore(*m_device, semaphore_create_info);
1704 ASSERT_TRUE(semaphore.initialized());
ziga-lunarg607821a2021-08-01 14:27:59 +02001705
1706 VkDeviceGroupSubmitInfo device_group_submit_info = LvlInitStruct<VkDeviceGroupSubmitInfo>();
1707 device_group_submit_info.commandBufferCount = 1;
1708 uint32_t command_buffer_device_masks = 0;
1709 device_group_submit_info.pCommandBufferDeviceMasks = &command_buffer_device_masks;
1710
1711 VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>(&device_group_submit_info);
1712 submit_info.commandBufferCount = 1;
1713 submit_info.pCommandBuffers = &m_commandBuffer->handle();
1714 submit_info.signalSemaphoreCount = 1;
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001715 submit_info.pSignalSemaphores = &semaphore.handle();
ziga-lunarg607821a2021-08-01 14:27:59 +02001716
1717 m_commandBuffer->reset();
1718 vk::BeginCommandBuffer(m_commandBuffer->handle(), &cmd_buf_info);
1719 vk::EndCommandBuffer(m_commandBuffer->handle());
1720 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupSubmitInfo-signalSemaphoreCount-00084");
1721 vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1722 m_errorMonitor->VerifyFound();
1723 vk::QueueWaitIdle(m_device->m_queue);
1724
1725 VkSubmitInfo signal_submit_info = LvlInitStruct<VkSubmitInfo>();
1726 signal_submit_info.signalSemaphoreCount = 1;
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001727 signal_submit_info.pSignalSemaphores = &semaphore.handle();
ziga-lunarg607821a2021-08-01 14:27:59 +02001728 vk::QueueSubmit(m_device->m_queue, 1, &signal_submit_info, VK_NULL_HANDLE);
1729
1730 VkPipelineStageFlags waitMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1731 submit_info.pWaitDstStageMask = &waitMask;
1732 submit_info.waitSemaphoreCount = 1;
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001733 submit_info.pWaitSemaphores = &semaphore.handle();
ziga-lunarg607821a2021-08-01 14:27:59 +02001734 submit_info.signalSemaphoreCount = 0;
1735 submit_info.pSignalSemaphores = nullptr;
1736 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupSubmitInfo-waitSemaphoreCount-00082");
1737 vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1738 m_errorMonitor->VerifyFound();
1739
1740 submit_info.waitSemaphoreCount = 0;
1741 submit_info.commandBufferCount = 0;
1742 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDeviceGroupSubmitInfo-commandBufferCount-00083");
1743 vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1744 m_errorMonitor->VerifyFound();
1745
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001746 // Need to wait for semaphore to not be in use before destroying it
1747 vk::QueueWaitIdle(m_device->m_queue);
ziga-lunarg607821a2021-08-01 14:27:59 +02001748}
1749
ziga-lunarg8e400fd2021-08-01 22:27:06 +02001750TEST_F(VkLayerTest, SwapchainAcquireImageWithSignaledSemaphore) {
1751 TEST_DESCRIPTION("Test vkAcquireNextImageKHR with signaled semaphore");
1752 SetTargetApiVersion(VK_API_VERSION_1_1);
1753
sjfrickea83fbb92022-07-01 13:57:27 +09001754 AddSurfaceExtension();
ziga-lunarg8e400fd2021-08-01 22:27:06 +02001755
1756 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
1757
1758 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001759 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunarg8e400fd2021-08-01 22:27:06 +02001760 }
ziga-lunarg8e400fd2021-08-01 22:27:06 +02001761 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DEVICE_GROUP_EXTENSION_NAME)) {
1762 m_device_extension_names.push_back(VK_KHR_DEVICE_GROUP_EXTENSION_NAME);
ziga-lunarg8e400fd2021-08-01 22:27:06 +02001763 }
1764
sjfrickea83fbb92022-07-01 13:57:27 +09001765 if (!AreRequiredExtensionsEnabled()) {
1766 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
ziga-lunarg8e400fd2021-08-01 22:27:06 +02001767 }
1768
1769 ASSERT_NO_FATAL_FAILURE(InitState());
1770 ASSERT_TRUE(InitSwapchain());
1771
1772 VkSemaphoreCreateInfo semaphore_create_info = LvlInitStruct<VkSemaphoreCreateInfo>();
1773 VkSemaphore semaphore;
1774 ASSERT_VK_SUCCESS(vk::CreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
1775
1776 VkSubmitInfo submit_info = LvlInitStruct<VkSubmitInfo>();
1777 submit_info.signalSemaphoreCount = 1;
1778 submit_info.pSignalSemaphores = &semaphore;
1779 vk::QueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1780 vk::QueueWaitIdle(m_device->m_queue);
1781
1782 VkAcquireNextImageInfoKHR acquire_info = LvlInitStruct<VkAcquireNextImageInfoKHR>();
1783 acquire_info.swapchain = m_swapchain;
1784 acquire_info.timeout = std::numeric_limits<uint64_t>::max();
1785 acquire_info.semaphore = semaphore;
1786 acquire_info.fence = VK_NULL_HANDLE;
1787 acquire_info.deviceMask = 0x1;
1788
1789 uint32_t dummy;
1790 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkAcquireNextImageKHR-semaphore-01286");
1791 vk::AcquireNextImageKHR(device(), m_swapchain, std::numeric_limits<uint64_t>::max(), semaphore, VK_NULL_HANDLE, &dummy);
1792 m_errorMonitor->VerifyFound();
1793 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkAcquireNextImageInfoKHR-semaphore-01288");
1794 vk::AcquireNextImage2KHR(device(), &acquire_info, &dummy);
1795 m_errorMonitor->VerifyFound();
1796
1797 vk::DestroySemaphore(device(), semaphore, nullptr);
ziga-lunarg8e400fd2021-08-01 22:27:06 +02001798}
1799
ziga-lunarg3b615b62021-08-01 12:29:36 +02001800TEST_F(VkLayerTest, DisplayPresentInfoSrcRect) {
1801 TEST_DESCRIPTION("Test layout tracking on imageless framebuffers");
sjfrickea83fbb92022-07-01 13:57:27 +09001802 AddSurfaceExtension();
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001803 AddRequiredExtensions(VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME);
1804 ASSERT_NO_FATAL_FAILURE(InitFramework());
1805 if (!AreRequiredExtensionsEnabled()) {
1806 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
ziga-lunarg3b615b62021-08-01 12:29:36 +02001807 }
ziga-lunarg3b615b62021-08-01 12:29:36 +02001808 ASSERT_NO_FATAL_FAILURE(InitState());
1809 if (!InitSwapchain(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) {
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001810 GTEST_SKIP() << "Cannot create surface or swapchain, skipping test";
ziga-lunarg3b615b62021-08-01 12:29:36 +02001811 }
1812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1813
1814 uint32_t current_buffer;
sfricke-samsung34c103f2021-12-31 02:04:18 -06001815 VkSemaphoreCreateInfo semaphore_create_info = LvlInitStruct<VkSemaphoreCreateInfo>();
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001816 vk_testing::Semaphore image_acquired(*m_device, semaphore_create_info);
1817 ASSERT_TRUE(image_acquired.initialized());
1818 vk::AcquireNextImageKHR(device(), m_swapchain, std::numeric_limits<uint64_t>::max(), image_acquired.handle(), VK_NULL_HANDLE,
ziga-lunarg42087ad2022-03-21 20:28:44 +01001819 &current_buffer);
ziga-lunarg3b615b62021-08-01 12:29:36 +02001820
1821 m_commandBuffer->begin();
1822 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
1823 m_commandBuffer->EndRenderPass();
1824 m_commandBuffer->end();
1825
ziga-lunarg3b615b62021-08-01 12:29:36 +02001826 uint32_t swapchain_width = m_surface_capabilities.minImageExtent.width;
1827 uint32_t swapchain_height = m_surface_capabilities.minImageExtent.height;
1828
1829 VkDisplayPresentInfoKHR display_present_info = LvlInitStruct<VkDisplayPresentInfoKHR>();
1830 display_present_info.srcRect.extent.width = swapchain_width + 1; // Invalid
1831 display_present_info.srcRect.extent.height = swapchain_height;
1832 display_present_info.dstRect.extent.width = swapchain_width;
1833 display_present_info.dstRect.extent.height = swapchain_height;
1834
1835 VkPresentInfoKHR present = LvlInitStruct<VkPresentInfoKHR>(&display_present_info);
ziga-lunarg42087ad2022-03-21 20:28:44 +01001836 present.waitSemaphoreCount = 1;
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06001837 present.pWaitSemaphores = &image_acquired.handle();
ziga-lunarg3b615b62021-08-01 12:29:36 +02001838 present.pSwapchains = &m_swapchain;
1839 present.pImageIndices = &current_buffer;
1840 present.swapchainCount = 1;
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001841 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDisplayPresentInfoKHR-srcRect-01257");
1842 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPresentInfoKHR-pImageIndices-01296");
ziga-lunarg3b615b62021-08-01 12:29:36 +02001843 vk::QueuePresentKHR(m_device->m_queue, &present);
Nathaniel Cesario079b1b92022-07-06 15:56:26 -06001844 m_errorMonitor->VerifyFound();
ziga-lunarg3b615b62021-08-01 12:29:36 +02001845}
Tony-LunarG2334f332021-07-14 15:40:02 -06001846
1847TEST_F(VkLayerTest, PresentIdWait) {
1848 TEST_DESCRIPTION("Test present wait extension");
arno1689b372022-08-25 19:34:15 +02001849 SetTargetApiVersion(VK_API_VERSION_1_1);
sjfrickea83fbb92022-07-01 13:57:27 +09001850 AddSurfaceExtension();
Tony-LunarG2334f332021-07-14 15:40:02 -06001851 auto present_id_features = LvlInitStruct<VkPhysicalDevicePresentIdFeaturesKHR>();
1852 auto present_wait_features = LvlInitStruct<VkPhysicalDevicePresentWaitFeaturesKHR>(&present_id_features);
1853 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>(&present_wait_features);
1854 m_device_extension_names.push_back(VK_KHR_PRESENT_WAIT_EXTENSION_NAME);
1855 m_device_extension_names.push_back(VK_KHR_PRESENT_ID_EXTENSION_NAME);
1856 m_device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1857 bool retval = InitFrameworkAndRetrieveFeatures(features2);
1858 if (!retval) {
1859 printf("%s Error initializing extensions or retrieving features, skipping test\n", kSkipPrefix);
1860 return;
1861 }
1862 if (!present_id_features.presentId || !present_wait_features.presentWait) {
1863 printf("%s presentWait feature is not available, skipping test\n", kSkipPrefix);
1864 return;
1865 }
1866
1867 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
arno1689b372022-08-25 19:34:15 +02001868 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
arno-lunarg28838122022-08-26 17:09:02 +02001869 GTEST_SKIP() << "At least Vulkan version 1.1 is required, skipping test.";
arno1689b372022-08-25 19:34:15 +02001870 }
1871
Tony-LunarG2334f332021-07-14 15:40:02 -06001872 ASSERT_TRUE(InitSwapchain());
1873 VkSurfaceKHR surface2;
1874 VkSwapchainKHR swapchain2;
1875 InitSurface(m_width, m_height, surface2);
1876 InitSwapchain(surface2, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, swapchain2);
1877
1878 auto vkWaitForPresentKHR = (PFN_vkWaitForPresentKHR)vk::GetDeviceProcAddr(m_device->device(), "vkWaitForPresentKHR");
1879 assert(vkWaitForPresentKHR != nullptr);
1880
1881 uint32_t image_count, image_count2;
1882 vk::GetSwapchainImagesKHR(device(), m_swapchain, &image_count, nullptr);
1883 vk::GetSwapchainImagesKHR(device(), swapchain2, &image_count2, nullptr);
1884 std::vector<VkImage> images(image_count);
1885 std::vector<VkImage> images2(image_count2);
1886 vk::GetSwapchainImagesKHR(device(), m_swapchain, &image_count, images.data());
1887 vk::GetSwapchainImagesKHR(device(), swapchain2, &image_count2, images2.data());
1888
1889 uint32_t image_indices[2];
1890 VkFenceObj fence, fence2;
1891 fence.init(*m_device, VkFenceObj::create_info());
1892 fence2.init(*m_device, VkFenceObj::create_info());
1893 VkFence fence_handles[2];
1894 fence_handles[0] = fence.handle();
1895 fence_handles[1] = fence2.handle();
1896
1897 vk::AcquireNextImageKHR(device(), m_swapchain, UINT64_MAX, VK_NULL_HANDLE, fence_handles[0], &image_indices[0]);
1898 vk::AcquireNextImageKHR(device(), swapchain2, UINT64_MAX, VK_NULL_HANDLE, fence_handles[1], &image_indices[1]);
1899 vk::WaitForFences(device(), 2, fence_handles, true, UINT64_MAX);
1900 SetImageLayout(m_device, VK_IMAGE_ASPECT_COLOR_BIT, images[image_indices[0]], VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
1901 SetImageLayout(m_device, VK_IMAGE_ASPECT_COLOR_BIT, images2[image_indices[1]], VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
1902
1903 VkSwapchainKHR swap_chains[2] = {m_swapchain, swapchain2};
1904 uint64_t present_ids[2] = {};
1905 present_ids[0] = 4; // Try setting 3 later
1906 VkPresentIdKHR present_id = LvlInitStruct<VkPresentIdKHR>();
1907 present_id.swapchainCount = 2;
1908 present_id.pPresentIds = present_ids;
1909 VkPresentInfoKHR present = LvlInitStruct<VkPresentInfoKHR>(&present_id);
1910 present.pSwapchains = swap_chains;
1911 present.pImageIndices = image_indices;
1912 present.swapchainCount = 2;
1913
1914 // Submit a clean present to establish presentIds
1915 vk::QueuePresentKHR(m_device->m_queue, &present);
1916
1917 vk::ResetFences(device(), 2, fence_handles);
1918 vk::AcquireNextImageKHR(device(), m_swapchain, UINT64_MAX, VK_NULL_HANDLE, fence_handles[0], &image_indices[0]);
1919 vk::AcquireNextImageKHR(device(), swapchain2, UINT64_MAX, VK_NULL_HANDLE, fence_handles[1], &image_indices[1]);
1920 vk::WaitForFences(device(), 2, fence_handles, true, UINT64_MAX);
1921 SetImageLayout(m_device, VK_IMAGE_ASPECT_COLOR_BIT, images[image_indices[0]], VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
1922 SetImageLayout(m_device, VK_IMAGE_ASPECT_COLOR_BIT, images2[image_indices[1]], VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
1923
1924 // presentIds[0] = 3 (smaller than 4), presentIds[1] = 5 (wait for this after swapchain 2 is retired)
1925 present_ids[0] = 3;
1926 present_ids[1] = 5;
1927 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPresentIdKHR-presentIds-04999");
1928 vk::QueuePresentKHR(m_device->m_queue, &present);
1929 m_errorMonitor->VerifyFound();
1930
1931 // Errors should prevent previous and future vkQueuePresents from actually happening so ok to re-use images
1932 present_id.swapchainCount = 0;
1933 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPresentIdKHR-swapchainCount-arraylength");
1934 vk::QueuePresentKHR(m_device->m_queue, &present);
1935 m_errorMonitor->VerifyFound();
1936
1937 present_id.swapchainCount = 1;
1938 present_ids[0] = 5;
1939 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPresentIdKHR-swapchainCount-04998");
1940 vk::QueuePresentKHR(m_device->m_queue, &present);
1941 m_errorMonitor->VerifyFound();
1942
1943 VkSwapchainKHR swapchain3;
1944 // Retire swapchain2
1945 InitSwapchain(surface2, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, swapchain3, swapchain2);
1946 present_id.swapchainCount = 2;
1947 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkWaitForPresentKHR-swapchain-04997");
1948 vkWaitForPresentKHR(device(), swapchain2, 5, UINT64_MAX);
1949 m_errorMonitor->VerifyFound();
1950
Tony-LunarG2334f332021-07-14 15:40:02 -06001951 vk::DestroySwapchainKHR(m_device->device(), swapchain2, nullptr);
1952 vk::DestroySwapchainKHR(m_device->device(), swapchain3, nullptr);
1953 vk::DestroySurfaceKHR(instance(), surface2, nullptr);
1954}
1955
1956TEST_F(VkLayerTest, PresentIdWaitFeatures) {
1957 TEST_DESCRIPTION("Test present wait extension");
arno1689b372022-08-25 19:34:15 +02001958 SetTargetApiVersion(VK_API_VERSION_1_1);
sjfrickea83fbb92022-07-01 13:57:27 +09001959 AddSurfaceExtension();
Tony-LunarG2334f332021-07-14 15:40:02 -06001960 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>();
1961 m_device_extension_names.push_back(VK_KHR_PRESENT_WAIT_EXTENSION_NAME);
1962 m_device_extension_names.push_back(VK_KHR_PRESENT_ID_EXTENSION_NAME);
1963 m_device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1964 bool retval = InitFrameworkAndRetrieveFeatures(features2);
1965 if (!retval) {
1966 printf("%s Error initializing extensions or retrieving features, skipping test\n", kSkipPrefix);
1967 return;
1968 }
1969
1970 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
arno1689b372022-08-25 19:34:15 +02001971 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
arno-lunarg28838122022-08-26 17:09:02 +02001972 GTEST_SKIP() << "At least Vulkan version 1.1 is required, skipping test.";
arno1689b372022-08-25 19:34:15 +02001973 }
1974
Tony-LunarG2334f332021-07-14 15:40:02 -06001975 ASSERT_TRUE(InitSwapchain());
1976
1977 auto vkWaitForPresentKHR = (PFN_vkWaitForPresentKHR)vk::GetDeviceProcAddr(m_device->device(), "vkWaitForPresentKHR");
1978 assert(vkWaitForPresentKHR != nullptr);
1979
1980 uint32_t image_count;
1981 vk::GetSwapchainImagesKHR(device(), m_swapchain, &image_count, nullptr);
1982 std::vector<VkImage> images(image_count);
1983 vk::GetSwapchainImagesKHR(device(), m_swapchain, &image_count, images.data());
1984
1985 uint32_t image_index;
1986 VkFenceObj fence;
1987 fence.init(*m_device, VkFenceObj::create_info());
1988 vk::AcquireNextImageKHR(device(), m_swapchain, UINT64_MAX, VK_NULL_HANDLE, fence.handle(), &image_index);
1989 vk::WaitForFences(device(), 1, &fence.handle(), true, UINT64_MAX);
1990
1991 SetImageLayout(m_device, VK_IMAGE_ASPECT_COLOR_BIT, images[image_index], VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
1992
1993 uint64_t present_id_index = 1;
1994 VkPresentIdKHR present_id = LvlInitStruct<VkPresentIdKHR>();
1995 present_id.swapchainCount = 1;
1996 present_id.pPresentIds = &present_id_index;
1997
1998 VkPresentInfoKHR present = LvlInitStruct<VkPresentInfoKHR>(&present_id);
1999 present.pSwapchains = &m_swapchain;
2000 present.pImageIndices = &image_index;
2001 present.swapchainCount = 1;
2002
Tony-LunarGd0686042021-08-13 15:20:38 -06002003 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPresentInfoKHR-pNext-06235");
Tony-LunarG2334f332021-07-14 15:40:02 -06002004 vk::QueuePresentKHR(m_device->m_queue, &present);
2005 m_errorMonitor->VerifyFound();
2006
Tony-LunarGd0686042021-08-13 15:20:38 -06002007 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkWaitForPresentKHR-presentWait-06234");
Tony-LunarG2334f332021-07-14 15:40:02 -06002008 vkWaitForPresentKHR(device(), m_swapchain, 1, UINT64_MAX);
2009 m_errorMonitor->VerifyFound();
Tony-LunarG2334f332021-07-14 15:40:02 -06002010}
ziga-lunarg97e1a872021-08-07 20:10:52 +02002011
2012TEST_F(VkLayerTest, GetSwapchainImagesCountButNotImages) {
2013 TEST_DESCRIPTION("Test for getting swapchain images count and presenting before getting swapchain images.");
sjfrickea83fbb92022-07-01 13:57:27 +09002014 AddSurfaceExtension();
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06002015 ASSERT_NO_FATAL_FAILURE(InitFramework());
sjfrickea83fbb92022-07-01 13:57:27 +09002016 if (!AreRequiredExtensionsEnabled()) {
2017 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
2018 }
ziga-lunarg97e1a872021-08-07 20:10:52 +02002019 ASSERT_NO_FATAL_FAILURE(InitState());
2020 ASSERT_TRUE(InitSurface());
2021
2022 VkBool32 supported;
2023 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), m_device->graphics_queue_node_index_, m_surface, &supported);
2024 if (!supported) {
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06002025 GTEST_SKIP() << "Graphics queue does not support present, skipping test";
ziga-lunarg97e1a872021-08-07 20:10:52 +02002026 }
2027 InitSwapchainInfo();
2028
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06002029 VkImageFormatProperties img_format_props;
2030 vk::GetPhysicalDeviceImageFormatProperties(gpu(), m_surface_formats[0].format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
2031 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &img_format_props);
2032 VkExtent2D img_ext = {std::min(m_surface_capabilities.maxImageExtent.width, img_format_props.maxExtent.width),
2033 std::min(m_surface_capabilities.maxImageExtent.height, img_format_props.maxExtent.height)};
2034
ziga-lunarg97e1a872021-08-07 20:10:52 +02002035 VkSwapchainCreateInfoKHR swapchain_info = LvlInitStruct<VkSwapchainCreateInfoKHR>();
2036 swapchain_info.surface = m_surface;
2037 swapchain_info.minImageCount = m_surface_capabilities.minImageCount;
2038 swapchain_info.imageFormat = m_surface_formats[0].format;
2039 swapchain_info.imageColorSpace = m_surface_formats[0].colorSpace;
Nathaniel Cesario0d50bcf2022-06-21 10:30:04 -06002040 swapchain_info.imageExtent = img_ext;
ziga-lunarg97e1a872021-08-07 20:10:52 +02002041 swapchain_info.imageArrayLayers = 1;
2042 swapchain_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
2043 swapchain_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2044 swapchain_info.queueFamilyIndexCount = 0;
2045 swapchain_info.pQueueFamilyIndices = nullptr;
2046 swapchain_info.preTransform = m_surface_capabilities.currentTransform;
sjfrickea83fbb92022-07-01 13:57:27 +09002047 swapchain_info.compositeAlpha = m_surface_composite_alpha;
ziga-lunarg97e1a872021-08-07 20:10:52 +02002048 swapchain_info.presentMode = m_surface_present_modes[0];
2049 swapchain_info.clipped = VK_FALSE;
2050
2051 vk::CreateSwapchainKHR(device(), &swapchain_info, nullptr, &m_swapchain);
2052
2053 uint32_t imageCount;
2054 vk::GetSwapchainImagesKHR(device(), m_swapchain, &imageCount, nullptr);
2055
2056 const uint32_t image_index = 0;
2057 VkPresentInfoKHR present_info = LvlInitStruct<VkPresentInfoKHR>();
2058 present_info.pImageIndices = &image_index;
2059 present_info.pSwapchains = &m_swapchain;
2060 present_info.swapchainCount = 1;
2061 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPresentInfoKHR-pImageIndices-01296");
2062 vk::QueuePresentKHR(m_device->m_queue, &present_info);
2063 m_errorMonitor->VerifyFound();
2064}
ziga-lunarg131472c2021-08-28 23:45:15 +02002065
ziga-lunarg925af8f2021-08-25 21:34:29 +02002066TEST_F(VkLayerTest, TestSurfaceSupportByPhysicalDevice) {
2067 TEST_DESCRIPTION("Test if physical device supports surface.");
2068 SetTargetApiVersion(VK_API_VERSION_1_1);
sjfrickea83fbb92022-07-01 13:57:27 +09002069 AddSurfaceExtension();
ziga-lunarg925af8f2021-08-25 21:34:29 +02002070
2071 bool get_surface_capabilities2 = false;
2072 bool swapchain = false;
2073 bool display_surface_counter = false;
2074
2075 if (InstanceExtensionSupported(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME)) {
2076 m_instance_extension_names.push_back(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
2077 get_surface_capabilities2 = true;
2078 }
2079
2080 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
2081 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09002082 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunarg925af8f2021-08-25 21:34:29 +02002083 }
2084
2085 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) {
2086 m_device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
2087 swapchain = true;
2088 }
2089
2090#ifdef VK_USE_PLATFORM_WIN32_KHR
2091 bool full_screen_exclusive = false;
2092 if (get_surface_capabilities2 && swapchain &&
2093 DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME)) {
2094 m_device_extension_names.push_back(VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME);
2095 full_screen_exclusive = true;
2096 }
2097#endif
2098
2099 if (DeviceExtensionSupported(gpu(), nullptr, VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME)) {
2100 m_device_extension_names.push_back(VK_KHR_DISPLAY_EXTENSION_NAME);
2101 m_device_extension_names.push_back(VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME);
2102 display_surface_counter = true;
2103 }
2104
2105 ASSERT_NO_FATAL_FAILURE(InitState());
2106 if (!InitSurface()) {
2107 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
2108 return;
2109 }
2110
2111 uint32_t queueFamilyPropertyCount;
2112 vk::GetPhysicalDeviceQueueFamilyProperties(gpu(), &queueFamilyPropertyCount, nullptr);
2113
2114 VkBool32 supported = VK_FALSE;
2115 for (uint32_t i = 0; i < queueFamilyPropertyCount; ++i) {
2116 vk::GetPhysicalDeviceSurfaceSupportKHR(gpu(), i, m_surface, &supported);
2117 if (supported) {
2118 break;
2119 }
2120 }
2121 if (supported) {
Petr Kraus89749bc2022-03-06 02:40:08 +01002122 printf("%s Physical device supports present, skipping\n", kSkipPrefix);
ziga-lunarg925af8f2021-08-25 21:34:29 +02002123 return;
2124 }
2125
2126#ifdef VK_USE_PLATFORM_WIN32_KHR
2127 if (full_screen_exclusive) {
2128 VkPhysicalDeviceSurfaceInfo2KHR surface_info = LvlInitStruct<VkPhysicalDeviceSurfaceInfo2KHR>();
2129 surface_info.surface = m_surface;
2130 VkDeviceGroupPresentModeFlagsKHR flags = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
2131
2132 PFN_vkGetDeviceGroupSurfacePresentModes2EXT vkGetDeviceGroupSurfacePresentModes2EXT =
2133 reinterpret_cast<PFN_vkGetDeviceGroupSurfacePresentModes2EXT>(
2134 vk::GetInstanceProcAddr(instance(), "vkGetDeviceGroupSurfacePresentModes2EXT"));
2135
2136 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetDeviceGroupSurfacePresentModes2EXT-pSurfaceInfo-06213");
2137 vkGetDeviceGroupSurfacePresentModes2EXT(device(), &surface_info, &flags);
2138 m_errorMonitor->VerifyFound();
2139
2140 PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT vkGetPhysicalDeviceSurfacePresentModes2EXT =
2141 (PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT)vk::GetInstanceProcAddr(instance(),
2142 "vkGetPhysicalDeviceSurfacePresentModes2EXT");
2143
2144 uint32_t count;
2145 vkGetPhysicalDeviceSurfacePresentModes2EXT(gpu(), &surface_info, &count, nullptr);
2146 }
2147#endif
2148
2149 if (swapchain) {
2150 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetDeviceGroupSurfacePresentModesKHR-surface-06212");
2151 VkDeviceGroupPresentModeFlagsKHR flags = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
2152 vk::GetDeviceGroupSurfacePresentModesKHR(device(), m_surface, &flags);
2153 m_errorMonitor->VerifyFound();
2154
2155 uint32_t count;
2156 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetPhysicalDevicePresentRectanglesKHR-surface-06211");
2157 vk::GetPhysicalDevicePresentRectanglesKHR(gpu(), m_surface, &count, nullptr);
2158 m_errorMonitor->VerifyFound();
2159 }
2160
2161 if (display_surface_counter) {
2162 PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT vkGetPhysicalDeviceSurfaceCapabilities2EXT =
2163 (PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT)vk::GetInstanceProcAddr(instance(),
2164 "vkGetPhysicalDeviceSurfaceCapabilities2EXT");
2165
2166 VkSurfaceCapabilities2EXT capabilities = LvlInitStruct<VkSurfaceCapabilities2EXT>();
2167
Mike Schuchardt81a0c6b2021-09-09 09:37:02 -07002168 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetPhysicalDeviceSurfaceCapabilities2EXT-surface-06211");
ziga-lunarg925af8f2021-08-25 21:34:29 +02002169 vkGetPhysicalDeviceSurfaceCapabilities2EXT(gpu(), m_surface, &capabilities);
2170 m_errorMonitor->VerifyFound();
2171 }
2172
2173 if (get_surface_capabilities2) {
2174 PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR vkGetPhysicalDeviceSurfaceCapabilities2KHR =
2175 (PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR)vk::GetInstanceProcAddr(instance(),
2176 "vkGetPhysicalDeviceSurfaceCapabilities2KHR");
2177
2178 VkPhysicalDeviceSurfaceInfo2KHR surface_info = LvlInitStruct<VkPhysicalDeviceSurfaceInfo2KHR>();
2179 surface_info.surface = m_surface;
2180 VkSurfaceCapabilities2KHR capabilities = LvlInitStruct<VkSurfaceCapabilities2KHR>();
2181
2182 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetPhysicalDeviceSurfaceCapabilities2KHR-pSurfaceInfo-06210");
2183 vkGetPhysicalDeviceSurfaceCapabilities2KHR(gpu(), &surface_info, &capabilities);
2184 m_errorMonitor->VerifyFound();
2185 }
2186
2187 {
2188 VkSurfaceCapabilitiesKHR capabilities;
2189 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetPhysicalDeviceSurfaceCapabilitiesKHR-surface-06211");
2190 vk::GetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), m_surface, &capabilities);
2191 m_errorMonitor->VerifyFound();
2192 }
2193
2194 if (get_surface_capabilities2) {
2195 PFN_vkGetPhysicalDeviceSurfaceFormats2KHR vkGetPhysicalDeviceSurfaceFormats2KHR =
2196 (PFN_vkGetPhysicalDeviceSurfaceFormats2KHR)vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceSurfaceFormats2KHR");
2197
2198 VkPhysicalDeviceSurfaceInfo2KHR surface_info = LvlInitStruct<VkPhysicalDeviceSurfaceInfo2KHR>();
2199 surface_info.surface = m_surface;
2200 uint32_t count;
2201 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetPhysicalDeviceSurfaceFormats2KHR-pSurfaceInfo-06210");
2202 vkGetPhysicalDeviceSurfaceFormats2KHR(gpu(), &surface_info, &count, nullptr);
2203 m_errorMonitor->VerifyFound();
2204 }
2205
2206 {
2207 uint32_t count;
2208 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkGetPhysicalDeviceSurfaceFormatsKHR-surface-06211");
2209 vk::GetPhysicalDeviceSurfaceFormatsKHR(gpu(), m_surface, &count, nullptr);
2210 m_errorMonitor->VerifyFound();
2211 }
2212
2213 {
2214 uint32_t count;
2215 vk::GetPhysicalDeviceSurfacePresentModesKHR(gpu(), m_surface, &count, nullptr);
2216 }
2217}
2218
Nathaniel Cesario1c9bacb2021-09-23 14:40:27 -06002219#ifdef VVL_TESTS_ENABLE_EXCLUSIVE_FULLSCREEN
ziga-lunarg131472c2021-08-28 23:45:15 +02002220TEST_F(VkLayerTest, TestvkAcquireFullScreenExclusiveModeEXT) {
2221 TEST_DESCRIPTION("Test vkAcquireFullScreenExclusiveModeEXT.");
2222
2223 SetTargetApiVersion(VK_API_VERSION_1_2);
2224#ifndef VK_USE_PLATFORM_WIN32_KHR
2225 printf("%s Test not supported on platform, skipping test\n", kSkipPrefix);
2226#else
sjfrickea83fbb92022-07-01 13:57:27 +09002227 AddSurfaceExtension();
ziga-lunarg131472c2021-08-28 23:45:15 +02002228 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
2229 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
2230 } else {
2231 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix,
2232 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
2233 return;
2234 }
2235 if (InstanceExtensionSupported(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME)) {
2236 m_instance_extension_names.push_back(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
2237 } else {
2238 printf("%s Extension %s not supported by device; skipped.\n", kSkipPrefix,
2239 VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
2240 return;
2241 }
2242 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
sjfrickea83fbb92022-07-01 13:57:27 +09002243 if (!AreRequiredExtensionsEnabled()) {
2244 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
ziga-lunarg131472c2021-08-28 23:45:15 +02002245 }
2246 if (DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME)) {
2247 m_device_extension_names.push_back(VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME);
2248 } else {
2249 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME);
2250 return;
2251 }
2252
2253 ASSERT_NO_FATAL_FAILURE(InitState());
2254 if (!InitSurface()) {
2255 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
2256 return;
2257 }
2258 InitSwapchainInfo();
2259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2260 if (!InitSwapchain()) {
2261 printf("%s Cannot create surface or swapchain, skipping test\n", kSkipPrefix);
2262 return;
2263 }
2264
2265 auto vkAcquireFullScreenExclusiveModeEXT = reinterpret_cast<PFN_vkAcquireFullScreenExclusiveModeEXT>(
2266 vk::GetInstanceProcAddr(instance(), "vkAcquireFullScreenExclusiveModeEXT"));
2267
2268 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkAcquireFullScreenExclusiveModeEXT-swapchain-02675");
2269 vkAcquireFullScreenExclusiveModeEXT(device(), m_swapchain);
2270 m_errorMonitor->VerifyFound();
2271
2272 const POINT pt_zero = {0, 0};
2273
2274 VkSurfaceFullScreenExclusiveWin32InfoEXT surface_full_screen_exlusive_info_win32 =
2275 LvlInitStruct<VkSurfaceFullScreenExclusiveWin32InfoEXT>();
2276 surface_full_screen_exlusive_info_win32.hmonitor = MonitorFromPoint(pt_zero, MONITOR_DEFAULTTOPRIMARY);
2277
2278 VkSurfaceFullScreenExclusiveInfoEXT surface_full_screen_exlusive_info =
2279 LvlInitStruct<VkSurfaceFullScreenExclusiveInfoEXT>(&surface_full_screen_exlusive_info_win32);
2280 surface_full_screen_exlusive_info.fullScreenExclusive = VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT;
2281
2282 VkSwapchainCreateInfoKHR swapchain_create_info = LvlInitStruct<VkSwapchainCreateInfoKHR>(&surface_full_screen_exlusive_info);
2283 swapchain_create_info.flags = 0;
2284 swapchain_create_info.surface = m_surface;
2285 swapchain_create_info.minImageCount = m_surface_capabilities.minImageCount;
2286 swapchain_create_info.imageFormat = m_surface_formats[0].format;
2287 swapchain_create_info.imageColorSpace = m_surface_formats[0].colorSpace;
2288 swapchain_create_info.imageExtent = {m_surface_capabilities.minImageExtent.width, m_surface_capabilities.minImageExtent.height};
2289 swapchain_create_info.imageArrayLayers = 1;
2290 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
2291 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2292 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
2293 swapchain_create_info.compositeAlpha = m_surface_composite_alpha;
2294 swapchain_create_info.presentMode = m_surface_non_shared_present_mode;
2295 swapchain_create_info.clipped = VK_FALSE;
2296 swapchain_create_info.oldSwapchain = m_swapchain;
2297
2298 VkSwapchainKHR swapchain_one, swapchain_two;
2299 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &swapchain_one);
2300 swapchain_create_info.oldSwapchain = swapchain_one;
2301 vk::CreateSwapchainKHR(device(), &swapchain_create_info, nullptr, &swapchain_two);
2302
2303 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkAcquireFullScreenExclusiveModeEXT-swapchain-02674");
2304 vkAcquireFullScreenExclusiveModeEXT(device(), swapchain_one);
2305 m_errorMonitor->VerifyFound();
2306
2307 vk::DestroySwapchainKHR(device(), swapchain_one, nullptr);
2308 vk::DestroySwapchainKHR(device(), swapchain_two, nullptr);
2309#endif
2310}
Nathaniel Cesario1c9bacb2021-09-23 14:40:27 -06002311#endif
ziga-lunargcf2a2d02021-12-30 12:23:08 +01002312
2313TEST_F(VkLayerTest, TestCreatingWin32Surface) {
2314 TEST_DESCRIPTION("Test creating win32 surface with invalid hwnd");
2315
2316#ifndef VK_USE_PLATFORM_WIN32_KHR
2317 printf("%s test not supported on platform, skipping test.\n", kSkipPrefix);
2318#else
sjfrickea83fbb92022-07-01 13:57:27 +09002319 AddSurfaceExtension();
ziga-lunargcf2a2d02021-12-30 12:23:08 +01002320 ASSERT_NO_FATAL_FAILURE(Init());
2321
2322 VkWin32SurfaceCreateInfoKHR surface_create_info = LvlInitStruct<VkWin32SurfaceCreateInfoKHR>();
2323 surface_create_info.hinstance = GetModuleHandle(0);
2324 surface_create_info.hwnd = NULL; // Invalid
2325
2326 VkSurfaceKHR surface;
2327 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkWin32SurfaceCreateInfoKHR-hwnd-01308");
2328 vk::CreateWin32SurfaceKHR(instance(), &surface_create_info, nullptr, &surface);
2329 m_errorMonitor->VerifyFound();
2330#endif
2331}
ziga-lunarg8a11d5f2022-03-13 14:19:02 +01002332
ziga-lunarg31463b62022-03-21 22:34:26 +01002333TEST_F(VkLayerTest, UseSwapchainImageBeforeWait) {
2334 TEST_DESCRIPTION("Test using a swapchain image that was acquired but not waited on.");
2335
sjfrickea83fbb92022-07-01 13:57:27 +09002336 AddSurfaceExtension();
ziga-lunarg31463b62022-03-21 22:34:26 +01002337
2338 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
2339
sjfrickea83fbb92022-07-01 13:57:27 +09002340 if (!AreRequiredExtensionsEnabled()) {
2341 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
ziga-lunarg31463b62022-03-21 22:34:26 +01002342 }
2343
2344 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
2345 if (!InitSwapchain()) {
2346 printf("%s Cannot create surface or swapchain, skipping test\n", kSkipPrefix);
2347 return;
2348 }
2349
2350 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPresentInfoKHR-pImageIndices-01296");
2351
2352 VkSemaphoreCreateInfo semaphore_create_info = LvlInitStruct<VkSemaphoreCreateInfo>();
2353 VkSemaphore acquire_semaphore;
2354 ASSERT_VK_SUCCESS(vk::CreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &acquire_semaphore));
2355
2356 uint32_t swapchain_images_count = 0;
2357 vk::GetSwapchainImagesKHR(device(), m_swapchain, &swapchain_images_count, nullptr);
2358 std::vector<VkImage> swapchain_images;
2359 swapchain_images.resize(swapchain_images_count);
2360 vk::GetSwapchainImagesKHR(device(), m_swapchain, &swapchain_images_count, swapchain_images.data());
2361
2362 uint32_t image_index = 0;
2363 vk::AcquireNextImageKHR(device(), m_swapchain, std::numeric_limits<uint64_t>::max(), acquire_semaphore, VK_NULL_HANDLE,
2364 &image_index);
2365
2366 VkPresentInfoKHR present = LvlInitStruct<VkPresentInfoKHR>();
2367 present.waitSemaphoreCount = 0; // Invalid, acquire_semaphore should be waited on
2368 present.swapchainCount = 1;
2369 present.pSwapchains = &m_swapchain;
2370 present.pImageIndices = &image_index;
2371 vk::QueuePresentKHR(m_device->m_queue, &present);
2372
2373 vk::QueueWaitIdle(m_device->m_queue);
2374 m_errorMonitor->VerifyFound();
2375
2376 vk::DestroySemaphore(device(), acquire_semaphore, nullptr);
ziga-lunarg31463b62022-03-21 22:34:26 +01002377}
2378
ziga-lunarg8a11d5f2022-03-13 14:19:02 +01002379TEST_F(VkLayerTest, TestCreatingSwapchainWithInvalidExtent) {
2380 TEST_DESCRIPTION("Create swapchain with extent greater than maxImageExtent of SurfaceCapabilities");
2381
sjfrickea83fbb92022-07-01 13:57:27 +09002382 AddSurfaceExtension();
ziga-lunarg8a11d5f2022-03-13 14:19:02 +01002383
2384 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
2385
sjfrickea83fbb92022-07-01 13:57:27 +09002386 if (!AreRequiredExtensionsEnabled()) {
2387 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported.";
ziga-lunarg8a11d5f2022-03-13 14:19:02 +01002388 }
2389 if (!InitSurface()) {
2390 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
2391 return;
2392 }
2393 ASSERT_NO_FATAL_FAILURE(InitState());
2394 InitSwapchainInfo();
2395
2396 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkSwapchainCreateInfoKHR-imageExtent-01274");
2397
2398 VkSurfaceCapabilitiesKHR surface_capabilities;
2399 vk::GetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), m_surface, &surface_capabilities);
2400
2401 VkSwapchainCreateInfoKHR swapchain_ci = LvlInitStruct<VkSwapchainCreateInfoKHR>();
2402 swapchain_ci.surface = m_surface;
2403 swapchain_ci.minImageCount = m_surface_capabilities.minImageCount;
2404 swapchain_ci.imageFormat = m_surface_formats[0].format;
2405 swapchain_ci.imageColorSpace = m_surface_formats[0].colorSpace;
2406 swapchain_ci.imageExtent.width = surface_capabilities.maxImageExtent.width + 1;
2407 swapchain_ci.imageExtent.height = surface_capabilities.maxImageExtent.height;
2408 swapchain_ci.imageArrayLayers = 1;
2409 swapchain_ci.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
2410 swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
2411 swapchain_ci.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
2412 swapchain_ci.compositeAlpha = m_surface_composite_alpha;
2413 swapchain_ci.presentMode = m_surface_non_shared_present_mode;
2414 swapchain_ci.clipped = VK_FALSE;
2415 swapchain_ci.oldSwapchain = 0;
2416
2417 VkSwapchainKHR swapchain;
2418 vk::CreateSwapchainKHR(device(), &swapchain_ci, nullptr, &swapchain);
2419
2420 m_errorMonitor->VerifyFound();
2421}
Younggwan Kima0571b12021-12-21 09:50:40 +00002422
2423TEST_F(VkLayerTest, TestSurfaceQueryImageCompressionControlWithoutExtension) {
2424 TEST_DESCRIPTION("Test querying surface image compression control without extension.");
2425 SetTargetApiVersion(VK_API_VERSION_1_1);
sjfrickea83fbb92022-07-01 13:57:27 +09002426 AddSurfaceExtension();
Younggwan Kima0571b12021-12-21 09:50:40 +00002427
sjfricked700bc02022-05-30 16:35:06 +09002428 AddRequiredExtensions(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
Younggwan Kima0571b12021-12-21 09:50:40 +00002429 AddRequiredExtensions(VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME);
2430
2431 auto image_compression_control = LvlInitStruct<VkPhysicalDeviceImageCompressionControlFeaturesEXT>();
2432 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&image_compression_control);
2433
2434 ASSERT_NO_FATAL_FAILURE(InitFrameworkAndRetrieveFeatures(features2));
sjfricked700bc02022-05-30 16:35:06 +09002435 if (!AreRequiredExtensionsEnabled()) {
2436 GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
2437 }
Younggwan Kima0571b12021-12-21 09:50:40 +00002438
2439 if (image_compression_control.imageCompressionControl) {
2440 // disable imageCompressionControl feature;
2441 image_compression_control.imageCompressionControl = VK_FALSE;
2442 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2443 } else {
2444 ASSERT_NO_FATAL_FAILURE(InitState());
2445 }
2446
2447 if (!InitSurface()) {
2448 printf("%s Cannot create surface, skipping test\n", kSkipPrefix);
2449 return;
2450 }
2451
2452 PFN_vkGetPhysicalDeviceSurfaceFormats2KHR vkGetPhysicalDeviceSurfaceFormats2KHR =
2453 reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceFormats2KHR>(vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceSurfaceFormats2KHR"));
2454
2455 auto compression_properties = LvlInitStruct<VkImageCompressionPropertiesEXT>();
2456 auto surface_info = LvlInitStruct<VkPhysicalDeviceSurfaceInfo2KHR>(&compression_properties);
2457 surface_info.surface = m_surface;
2458 uint32_t count;
2459
2460 // get compression control properties even of VK_EXT_image_compression_control extension is disabled(or is not supported).
2461 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPhysicalDeviceSurfaceInfo2KHR-pNext-pNext");
2462 vkGetPhysicalDeviceSurfaceFormats2KHR(gpu(), &surface_info, &count, nullptr);
2463 m_errorMonitor->VerifyFound();
2464}