blob: 3e7e0dec53f766955a7418867727d2ddcb14e554 [file] [log] [blame]
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001/*
2 * Copyright (c) 2015-2019 The Khronos Group Inc.
3 * Copyright (c) 2015-2019 Valve Corporation
4 * Copyright (c) 2015-2019 LunarG, Inc.
5 * Copyright (c) 2015-2019 Google, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
20 * Author: Cody Northrop <cnorthrop@google.com>
21 * Author: Dave Houlton <daveh@lunarg.com>
22 * Author: Jeremy Kniager <jeremyk@lunarg.com>
23 * Author: Shannon McPherson <shannon@lunarg.com>
24 * Author: John Zulauf <jzulauf@lunarg.com>
25 * Author: Tobias Hector <tobias.hector@amd.com>
26 */
27
28#include "cast_utils.h"
29#include "layer_validation_tests.h"
30
31TEST_F(VkLayerTest, ImagelessFramebufferRenderPassBeginImageViewMismatchTests) {
32 TEST_DESCRIPTION(
33 "Begin a renderPass where the image views specified do not match the parameters used to create the framebuffer and render "
34 "pass.");
35
36 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
37 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
38 } else {
39 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
40 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
41 return;
42 }
43
44 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
45 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
46
47 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
48 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
49 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
50 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
51 } else {
52 printf("%s test requires VK_KHR_imageless_framebuffer, not available. Skipping.\n", kSkipPrefix);
53 return;
54 }
55
56 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
57 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
58 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
59 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
60 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
61 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
62
63 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
64
65 uint32_t attachmentWidth = 512;
66 uint32_t attachmentHeight = 512;
67 VkFormat attachmentFormats[2] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM};
68 VkFormat framebufferAttachmentFormats[3] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM};
69
70 // Create a renderPass with a single attachment
71 VkAttachmentDescription attachmentDescription = {};
72 attachmentDescription.format = attachmentFormats[0];
73 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
74 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
75 VkAttachmentReference attachmentReference = {};
76 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
77 VkSubpassDescription subpassDescription = {};
78 subpassDescription.colorAttachmentCount = 1;
79 subpassDescription.pColorAttachments = &attachmentReference;
80 VkRenderPassCreateInfo renderPassCreateInfo = {};
81 renderPassCreateInfo.subpassCount = 1;
82 renderPassCreateInfo.pSubpasses = &subpassDescription;
83 renderPassCreateInfo.attachmentCount = 1;
84 renderPassCreateInfo.pAttachments = &attachmentDescription;
85 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
86 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -060087 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +010088
89 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
90 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
Mark Lobodzinski50885992019-12-03 14:44:22 -070091 framebufferAttachmentImageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
Tobias Hectorcf26efe2019-07-23 12:18:52 +010092 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
93 framebufferAttachmentImageInfo.width = attachmentWidth;
94 framebufferAttachmentImageInfo.height = attachmentHeight;
95 framebufferAttachmentImageInfo.layerCount = 1;
96 framebufferAttachmentImageInfo.viewFormatCount = 2;
97 framebufferAttachmentImageInfo.pViewFormats = framebufferAttachmentFormats;
98 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
99 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
100 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
101 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
102 VkFramebufferCreateInfo framebufferCreateInfo = {};
103 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
104 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
105 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
106 framebufferCreateInfo.width = attachmentWidth;
107 framebufferCreateInfo.height = attachmentHeight;
108 framebufferCreateInfo.layers = 1;
109 framebufferCreateInfo.attachmentCount = 1;
110 framebufferCreateInfo.pAttachments = nullptr;
111 framebufferCreateInfo.renderPass = renderPass;
112 VkFramebuffer framebuffer;
113
114 VkImageFormatListCreateInfoKHR imageFormatListCreateInfo = {};
115 imageFormatListCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR;
116 imageFormatListCreateInfo.viewFormatCount = 2;
117 imageFormatListCreateInfo.pViewFormats = attachmentFormats;
118 VkImageCreateInfo imageCreateInfo = {};
119 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
120 imageCreateInfo.pNext = &imageFormatListCreateInfo;
121 imageCreateInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
122 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
123 imageCreateInfo.extent.width = attachmentWidth;
124 imageCreateInfo.extent.height = attachmentHeight;
125 imageCreateInfo.extent.depth = 1;
126 imageCreateInfo.arrayLayers = 1;
127 imageCreateInfo.mipLevels = 10;
128 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
129 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
130 imageCreateInfo.format = attachmentFormats[0];
131
132 VkImageObj imageObject(m_device);
133 imageObject.init(&imageCreateInfo);
134 VkImage image = imageObject.image();
135
136 VkImageViewCreateInfo imageViewCreateInfo = {};
137 imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
138 imageViewCreateInfo.image = image;
139 imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
140 imageViewCreateInfo.format = attachmentFormats[0];
141 imageViewCreateInfo.subresourceRange.layerCount = 1;
142 imageViewCreateInfo.subresourceRange.levelCount = 1;
143 imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
144 VkImageView imageView;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600145 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, NULL, &imageView);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100146
147 VkRenderPassAttachmentBeginInfoKHR renderPassAttachmentBeginInfo = {};
148 renderPassAttachmentBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO_KHR;
149 renderPassAttachmentBeginInfo.pNext = nullptr;
150 renderPassAttachmentBeginInfo.attachmentCount = 1;
151 renderPassAttachmentBeginInfo.pAttachments = &imageView;
152 VkRenderPassBeginInfo renderPassBeginInfo = {};
153 renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
154 renderPassBeginInfo.pNext = &renderPassAttachmentBeginInfo;
155 renderPassBeginInfo.renderPass = renderPass;
156 renderPassBeginInfo.renderArea.extent.width = attachmentWidth;
157 renderPassBeginInfo.renderArea.extent.height = attachmentHeight;
158
Mark Lobodzinski50885992019-12-03 14:44:22 -0700159 // Positive test first
160 VkCommandBufferBeginInfo cmd_begin_info = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
161 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, nullptr};
162 framebufferCreateInfo.pAttachments = nullptr;
163 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
164 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
165 renderPassBeginInfo.framebuffer = framebuffer;
166 vk::BeginCommandBuffer(m_commandBuffer->handle(), &cmd_begin_info);
167 m_errorMonitor->ExpectSuccess();
168 vk::CmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
169 m_errorMonitor->VerifyNotFound();
170 vk::ResetCommandBuffer(m_commandBuffer->handle(), 0);
171 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
172
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100173 // Imageless framebuffer creation bit not present
174 framebufferCreateInfo.pAttachments = &imageView;
175 framebufferCreateInfo.flags = 0;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600176 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100177 renderPassBeginInfo.framebuffer = framebuffer;
178 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
179 "VUID-VkRenderPassBeginInfo-framebuffer-03207", "VUID-VkRenderPassBeginInfo-framebuffer-03207");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600180 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100181 framebufferCreateInfo.pAttachments = nullptr;
182 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
183
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600184 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100185 renderPassAttachmentBeginInfo.attachmentCount = 2;
186 renderPassBeginInfo.framebuffer = framebuffer;
187 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
188 "VUID-VkRenderPassBeginInfo-framebuffer-03208", "VUID-VkRenderPassBeginInfo-framebuffer-03208");
189 renderPassAttachmentBeginInfo.attachmentCount = 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600190 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100191
192 // Mismatched number of attachments
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600193 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100194 renderPassAttachmentBeginInfo.attachmentCount = 2;
195 renderPassBeginInfo.framebuffer = framebuffer;
196 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
197 "VUID-VkRenderPassBeginInfo-framebuffer-03208", "VUID-VkRenderPassBeginInfo-framebuffer-03208");
198 renderPassAttachmentBeginInfo.attachmentCount = 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600199 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100200
201 // Mismatched flags
202 framebufferAttachmentImageInfo.flags = 0;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600203 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100204 renderPassBeginInfo.framebuffer = framebuffer;
205 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
206 "VUID-VkRenderPassBeginInfo-framebuffer-03209", "VUID-VkRenderPassBeginInfo-framebuffer-03209");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600207 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100208 framebufferAttachmentImageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
209
210 // Mismatched usage
211 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600212 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100213 renderPassBeginInfo.framebuffer = framebuffer;
214 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
215 "VUID-VkRenderPassBeginInfo-framebuffer-03210", "VUID-VkRenderPassBeginInfo-framebuffer-03210");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600216 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100217 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
218
219 // Mismatched width
220 framebufferAttachmentImageInfo.width += 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600221 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100222 renderPassBeginInfo.framebuffer = framebuffer;
223 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
224 "VUID-VkRenderPassBeginInfo-framebuffer-03211", "VUID-VkRenderPassBeginInfo-framebuffer-03211");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600225 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100226 framebufferAttachmentImageInfo.width -= 1;
227
228 // Mismatched height
229 framebufferAttachmentImageInfo.height += 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600230 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100231 renderPassBeginInfo.framebuffer = framebuffer;
232 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
233 "VUID-VkRenderPassBeginInfo-framebuffer-03212", "VUID-VkRenderPassBeginInfo-framebuffer-03212");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600234 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100235 framebufferAttachmentImageInfo.height -= 1;
236
237 // Mismatched layer count
238 framebufferAttachmentImageInfo.layerCount += 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600239 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100240 renderPassBeginInfo.framebuffer = framebuffer;
241 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
242 "VUID-VkRenderPassBeginInfo-framebuffer-03213", "VUID-VkRenderPassBeginInfo-framebuffer-03213");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600243 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100244 framebufferAttachmentImageInfo.layerCount -= 1;
245
246 // Mismatched view format count
247 framebufferAttachmentImageInfo.viewFormatCount = 3;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600248 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100249 renderPassBeginInfo.framebuffer = framebuffer;
250 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
251 "VUID-VkRenderPassBeginInfo-framebuffer-03214", "VUID-VkRenderPassBeginInfo-framebuffer-03214");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600252 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100253 framebufferAttachmentImageInfo.viewFormatCount = 2;
254
255 // Mismatched format lists
256 framebufferAttachmentFormats[1] = VK_FORMAT_B8G8R8A8_SRGB;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600257 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100258 renderPassBeginInfo.framebuffer = framebuffer;
259 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
260 "VUID-VkRenderPassBeginInfo-framebuffer-03215", "VUID-VkRenderPassBeginInfo-framebuffer-03215");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600261 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100262 framebufferAttachmentFormats[1] = VK_FORMAT_B8G8R8A8_UNORM;
263
264 // Mismatched formats
265 VkImageView imageView2;
266 imageViewCreateInfo.format = attachmentFormats[1];
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600267 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100268 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600269 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100270 renderPassBeginInfo.framebuffer = framebuffer;
271 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
272 "VUID-VkRenderPassBeginInfo-framebuffer-03216", "VUID-VkRenderPassBeginInfo-framebuffer-03216");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600273 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
274 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100275 renderPassAttachmentBeginInfo.pAttachments = &imageView;
276 imageViewCreateInfo.format = attachmentFormats[0];
277
278 // Mismatched sample counts
279 imageCreateInfo.samples = VK_SAMPLE_COUNT_4_BIT;
280 imageCreateInfo.mipLevels = 1;
281 VkImageObj imageObject2(m_device);
282 imageObject2.init(&imageCreateInfo);
283 imageViewCreateInfo.image = imageObject2.image();
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600284 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100285 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600286 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100287 renderPassBeginInfo.framebuffer = framebuffer;
288 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
289 "VUID-VkRenderPassBeginInfo-framebuffer-03217", "VUID-VkRenderPassBeginInfo-framebuffer-03217");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600290 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
291 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100292 renderPassAttachmentBeginInfo.pAttachments = &imageView;
293 imageViewCreateInfo.image = imageObject.image();
294 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
295 imageCreateInfo.mipLevels = 10;
296
297 // Mismatched level counts
298 imageViewCreateInfo.subresourceRange.levelCount = 2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600299 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100300 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600301 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100302 renderPassBeginInfo.framebuffer = framebuffer;
303 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
Mike Schuchardt65847d92019-12-20 13:50:47 -0800304 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03218",
305 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03218");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600306 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
307 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100308 renderPassAttachmentBeginInfo.pAttachments = &imageView;
309 imageViewCreateInfo.subresourceRange.levelCount = 1;
310
311 // Non-identity component swizzle
312 imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_A;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600313 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100314 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600315 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100316 renderPassBeginInfo.framebuffer = framebuffer;
317 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
Mike Schuchardt65847d92019-12-20 13:50:47 -0800318 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03219",
319 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03219");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600320 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
321 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100322 renderPassAttachmentBeginInfo.pAttachments = &imageView;
323 imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
324
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600325 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100326 // vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600327 vk::DestroyImageView(m_device->device(), imageView, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100328}
329
330TEST_F(VkLayerTest, ImagelessFramebufferFeatureEnableTest) {
331 TEST_DESCRIPTION("Use imageless framebuffer functionality without enabling the feature");
332
333 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
334 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
335 } else {
336 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
337 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
338 return;
339 }
340 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
341
342 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
343 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
344 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
345 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
346 } else {
347 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
348 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
349 return;
350 }
351
352 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
353
354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
355
356 uint32_t attachmentWidth = 512;
357 uint32_t attachmentHeight = 512;
358 VkFormat attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
359
360 // Create a renderPass with a single attachment
361 VkAttachmentDescription attachmentDescription = {};
362 attachmentDescription.format = attachmentFormat;
363 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
364 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
365 VkAttachmentReference attachmentReference = {};
366 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
367 VkSubpassDescription subpassDescription = {};
368 subpassDescription.colorAttachmentCount = 1;
369 subpassDescription.pColorAttachments = &attachmentReference;
370 VkRenderPassCreateInfo renderPassCreateInfo = {};
371 renderPassCreateInfo.subpassCount = 1;
372 renderPassCreateInfo.pSubpasses = &subpassDescription;
373 renderPassCreateInfo.attachmentCount = 1;
374 renderPassCreateInfo.pAttachments = &attachmentDescription;
375 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
376 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600377 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100378
379 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
380 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
381 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
382 framebufferAttachmentImageInfo.width = attachmentWidth;
383 framebufferAttachmentImageInfo.height = attachmentHeight;
384 framebufferAttachmentImageInfo.layerCount = 1;
385 framebufferAttachmentImageInfo.viewFormatCount = 1;
386 framebufferAttachmentImageInfo.pViewFormats = &attachmentFormat;
387 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
388 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
389 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
390 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
391 VkFramebufferCreateInfo framebufferCreateInfo = {};
392 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
393 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
394 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
395 framebufferCreateInfo.width = attachmentWidth;
396 framebufferCreateInfo.height = attachmentHeight;
397 framebufferCreateInfo.layers = 1;
398 framebufferCreateInfo.renderPass = renderPass;
399 framebufferCreateInfo.attachmentCount = 1;
400 VkFramebuffer framebuffer = VK_NULL_HANDLE;
401
402 // Imageless framebuffer creation bit not present
403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03189");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600404 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100405 m_errorMonitor->VerifyFound();
406
407 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600408 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100409 }
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600410 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100411}
412
413TEST_F(VkLayerTest, ImagelessFramebufferCreationTests) {
414 TEST_DESCRIPTION("Create an imageless framebuffer in various invalid ways");
415
416 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
417 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
418 } else {
419 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
420 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
421 return;
422 }
423 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
424 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
425
426 bool multiviewSupported = rp2Supported;
427 if (!rp2Supported) {
428 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MULTIVIEW_EXTENSION_NAME)) {
429 m_device_extension_names.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
430 multiviewSupported = true;
431 }
432 }
433
434 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
435 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
436 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
437 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
438 } else {
439 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
440 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
441 return;
442 }
443
444 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
445 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
446 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
447 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
448 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
449 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
450 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
451
452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
453
454 uint32_t attachmentWidth = 512;
455 uint32_t attachmentHeight = 512;
456 VkFormat attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
457
458 // Create a renderPass with a single attachment
459 VkAttachmentDescription attachmentDescription = {};
460 attachmentDescription.format = attachmentFormat;
461 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
462 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
463 VkAttachmentReference attachmentReference = {};
464 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
465 VkSubpassDescription subpassDescription = {};
466 subpassDescription.colorAttachmentCount = 1;
467 subpassDescription.pColorAttachments = &attachmentReference;
468 VkRenderPassCreateInfo renderPassCreateInfo = {};
469 renderPassCreateInfo.subpassCount = 1;
470 renderPassCreateInfo.pSubpasses = &subpassDescription;
471 renderPassCreateInfo.attachmentCount = 1;
472 renderPassCreateInfo.pAttachments = &attachmentDescription;
473 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
474 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600475 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100476
477 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
478 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
479 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
480 framebufferAttachmentImageInfo.width = attachmentWidth;
481 framebufferAttachmentImageInfo.height = attachmentHeight;
482 framebufferAttachmentImageInfo.layerCount = 1;
483 framebufferAttachmentImageInfo.viewFormatCount = 1;
484 framebufferAttachmentImageInfo.pViewFormats = &attachmentFormat;
485 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
486 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
487 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
488 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
489 VkFramebufferCreateInfo framebufferCreateInfo = {};
490 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
491 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
492 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
493 framebufferCreateInfo.width = attachmentWidth;
494 framebufferCreateInfo.height = attachmentHeight;
495 framebufferCreateInfo.layers = 1;
496 framebufferCreateInfo.renderPass = renderPass;
497 framebufferCreateInfo.attachmentCount = 1;
498 VkFramebuffer framebuffer = VK_NULL_HANDLE;
499
500 // Attachments info not present
501 framebufferCreateInfo.pNext = nullptr;
502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03190");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600503 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100504 m_errorMonitor->VerifyFound();
505 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600506 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100507 }
508 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
509
510 // Mismatched attachment counts
511 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 2;
512 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[2] = {framebufferAttachmentImageInfo,
513 framebufferAttachmentImageInfo};
514 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03191");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600516 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100517 m_errorMonitor->VerifyFound();
518 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600519 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100520 }
521 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
522 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
523
524 // Mismatched format list
525 attachmentFormat = VK_FORMAT_B8G8R8A8_UNORM;
526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03205");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600527 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100528 m_errorMonitor->VerifyFound();
529 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600530 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100531 }
532 attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
533
534 // Mismatched format list
535 attachmentFormat = VK_FORMAT_B8G8R8A8_UNORM;
536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03205");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600537 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100538 m_errorMonitor->VerifyFound();
539 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600540 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100541 }
542 attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
543
544 // Mismatched layer count, multiview disabled
545 framebufferCreateInfo.layers = 2;
546 const char* mismatchedLayersNoMultiviewVuid =
Shannon McPherson3cc90bc2019-08-13 11:28:22 -0600547 multiviewSupported ? "VUID-VkFramebufferCreateInfo-renderPass-03199" : "VUID-VkFramebufferCreateInfo-flags-03200";
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, mismatchedLayersNoMultiviewVuid);
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600549 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100550 m_errorMonitor->VerifyFound();
551 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600552 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100553 }
554 framebufferCreateInfo.layers = 1;
555
556 // Mismatched width
557 framebufferCreateInfo.width += 1;
558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03192");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600559 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100560 m_errorMonitor->VerifyFound();
561 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600562 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100563 }
564 framebufferCreateInfo.width -= 1;
565
566 // Mismatched height
567 framebufferCreateInfo.height += 1;
568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03193");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600569 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100570 m_errorMonitor->VerifyFound();
571 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600572 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100573 }
574 framebufferCreateInfo.height -= 1;
575
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600576 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100577}
578
579TEST_F(VkLayerTest, ImagelessFramebufferAttachmentImageUsageMismatchTests) {
580 TEST_DESCRIPTION("Create an imageless framebuffer with mismatched attachment image usage");
581
582 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
583 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
584 } else {
585 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
586 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
587 return;
588 }
589 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
590
591 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
592 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
593 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
594 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
595 } else {
596 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
597 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
598 return;
599 }
600
601 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
602 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
603 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
604 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
605 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
606 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
607 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
608
609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
610
611 uint32_t attachmentWidth = 512;
612 uint32_t attachmentHeight = 512;
613 VkFormat colorAndInputAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
614 VkFormat depthStencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
615
616 VkAttachmentDescription attachmentDescriptions[4] = {};
617 // Color attachment
618 attachmentDescriptions[0].format = colorAndInputAttachmentFormat;
619 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
620 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
621 // Color resolve attachment
622 attachmentDescriptions[1].format = colorAndInputAttachmentFormat;
623 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
624 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
625 // Depth stencil attachment
626 attachmentDescriptions[2].format = depthStencilAttachmentFormat;
627 attachmentDescriptions[2].samples = VK_SAMPLE_COUNT_4_BIT;
628 attachmentDescriptions[2].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
629 // Input attachment
630 attachmentDescriptions[3].format = colorAndInputAttachmentFormat;
631 attachmentDescriptions[3].samples = VK_SAMPLE_COUNT_1_BIT;
632 attachmentDescriptions[3].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
633
634 VkAttachmentReference colorAttachmentReference = {};
635 colorAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
636 colorAttachmentReference.attachment = 0;
637 VkAttachmentReference colorResolveAttachmentReference = {};
638 colorResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
639 colorResolveAttachmentReference.attachment = 1;
640 VkAttachmentReference depthStencilAttachmentReference = {};
641 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
642 depthStencilAttachmentReference.attachment = 2;
643 VkAttachmentReference inputAttachmentReference = {};
644 inputAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
645 inputAttachmentReference.attachment = 3;
646 VkSubpassDescription subpassDescription = {};
647 subpassDescription.colorAttachmentCount = 1;
648 subpassDescription.pColorAttachments = &colorAttachmentReference;
649 subpassDescription.pResolveAttachments = &colorResolveAttachmentReference;
650 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
651 subpassDescription.inputAttachmentCount = 1;
652 subpassDescription.pInputAttachments = &inputAttachmentReference;
653
654 VkRenderPassCreateInfo renderPassCreateInfo = {};
655 renderPassCreateInfo.attachmentCount = 4;
656 renderPassCreateInfo.subpassCount = 1;
657 renderPassCreateInfo.pSubpasses = &subpassDescription;
658 renderPassCreateInfo.pAttachments = attachmentDescriptions;
659 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
660 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600661 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100662
663 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[4] = {};
664 // Color attachment
665 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
666 framebufferAttachmentImageInfos[0].width = attachmentWidth;
667 framebufferAttachmentImageInfos[0].height = attachmentHeight;
668 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
669 framebufferAttachmentImageInfos[0].layerCount = 1;
670 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
671 framebufferAttachmentImageInfos[0].pViewFormats = &colorAndInputAttachmentFormat;
672 // Color resolve attachment
673 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
674 framebufferAttachmentImageInfos[1].width = attachmentWidth;
675 framebufferAttachmentImageInfos[1].height = attachmentHeight;
676 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
677 framebufferAttachmentImageInfos[1].layerCount = 1;
678 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
679 framebufferAttachmentImageInfos[1].pViewFormats = &colorAndInputAttachmentFormat;
680 // Depth stencil attachment
681 framebufferAttachmentImageInfos[2].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
682 framebufferAttachmentImageInfos[2].width = attachmentWidth;
683 framebufferAttachmentImageInfos[2].height = attachmentHeight;
684 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
685 framebufferAttachmentImageInfos[2].layerCount = 1;
686 framebufferAttachmentImageInfos[2].viewFormatCount = 1;
687 framebufferAttachmentImageInfos[2].pViewFormats = &depthStencilAttachmentFormat;
688 // Input attachment
689 framebufferAttachmentImageInfos[3].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
690 framebufferAttachmentImageInfos[3].width = attachmentWidth;
691 framebufferAttachmentImageInfos[3].height = attachmentHeight;
692 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
693 framebufferAttachmentImageInfos[3].layerCount = 1;
694 framebufferAttachmentImageInfos[3].viewFormatCount = 1;
695 framebufferAttachmentImageInfos[3].pViewFormats = &colorAndInputAttachmentFormat;
696 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
697 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
698 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 4;
699 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
700 VkFramebufferCreateInfo framebufferCreateInfo = {};
701 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
702 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
703 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
704 framebufferCreateInfo.width = attachmentWidth;
705 framebufferCreateInfo.height = attachmentHeight;
706 framebufferCreateInfo.layers = 1;
707 framebufferCreateInfo.renderPass = renderPass;
708 framebufferCreateInfo.attachmentCount = 4;
709 VkFramebuffer framebuffer = VK_NULL_HANDLE;
710
711 // Color attachment, mismatched usage
712 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03201");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600714 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100715 m_errorMonitor->VerifyFound();
716 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600717 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100718 }
719 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
720
721 // Color resolve attachment, mismatched usage
722 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03201");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600724 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100725 m_errorMonitor->VerifyFound();
726 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600727 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100728 }
729 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
730
731 // Depth stencil attachment, mismatched usage
732 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03202");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600734 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100735 m_errorMonitor->VerifyFound();
736 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600737 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100738 }
739 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
740
741 // Color attachment, mismatched usage
742 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03204");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600744 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100745 m_errorMonitor->VerifyFound();
746 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600747 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100748 }
749 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
750
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600751 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100752}
753
754TEST_F(VkLayerTest, ImagelessFramebufferAttachmentMultiviewImageLayerCountMismatchTests) {
755 TEST_DESCRIPTION("Create an imageless framebuffer against a multiview-enabled render pass with mismatched layer counts");
756
757 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
758 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
759 } else {
760 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
761 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
762 return;
763 }
764 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
765
766 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MULTIVIEW_EXTENSION_NAME)) {
767 m_device_extension_names.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
768 } else {
769 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix, VK_KHR_MULTIVIEW_EXTENSION_NAME);
770 return;
771 }
772
773 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
774 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
775 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
776 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
777 } else {
778 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
779 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
780 return;
781 }
782
783 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
784 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
785 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
786 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
787 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
788 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
789 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
790
791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
792
793 uint32_t attachmentWidth = 512;
794 uint32_t attachmentHeight = 512;
795 VkFormat colorAndInputAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
796 VkFormat depthStencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
797
798 VkAttachmentDescription attachmentDescriptions[4] = {};
799 // Color attachment
800 attachmentDescriptions[0].format = colorAndInputAttachmentFormat;
801 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
802 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
803 // Color resolve attachment
804 attachmentDescriptions[1].format = colorAndInputAttachmentFormat;
805 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
806 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
807 // Depth stencil attachment
808 attachmentDescriptions[2].format = depthStencilAttachmentFormat;
809 attachmentDescriptions[2].samples = VK_SAMPLE_COUNT_4_BIT;
810 attachmentDescriptions[2].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
811 // Input attachment
812 attachmentDescriptions[3].format = colorAndInputAttachmentFormat;
813 attachmentDescriptions[3].samples = VK_SAMPLE_COUNT_1_BIT;
814 attachmentDescriptions[3].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
815
816 VkAttachmentReference colorAttachmentReference = {};
817 colorAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
818 colorAttachmentReference.attachment = 0;
819 VkAttachmentReference colorResolveAttachmentReference = {};
820 colorResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
821 colorResolveAttachmentReference.attachment = 1;
822 VkAttachmentReference depthStencilAttachmentReference = {};
823 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
824 depthStencilAttachmentReference.attachment = 2;
825 VkAttachmentReference inputAttachmentReference = {};
826 inputAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
827 inputAttachmentReference.attachment = 3;
828 VkSubpassDescription subpassDescription = {};
829 subpassDescription.colorAttachmentCount = 1;
830 subpassDescription.pColorAttachments = &colorAttachmentReference;
831 subpassDescription.pResolveAttachments = &colorResolveAttachmentReference;
832 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
833 subpassDescription.inputAttachmentCount = 1;
834 subpassDescription.pInputAttachments = &inputAttachmentReference;
835
836 uint32_t viewMask = 0x3u;
837 VkRenderPassMultiviewCreateInfo renderPassMultiviewCreateInfo = {};
838 renderPassMultiviewCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO;
839 renderPassMultiviewCreateInfo.subpassCount = 1;
840 renderPassMultiviewCreateInfo.pViewMasks = &viewMask;
841 VkRenderPassCreateInfo renderPassCreateInfo = {};
842 renderPassCreateInfo.pNext = &renderPassMultiviewCreateInfo;
843 renderPassCreateInfo.attachmentCount = 4;
844 renderPassCreateInfo.subpassCount = 1;
845 renderPassCreateInfo.pSubpasses = &subpassDescription;
846 renderPassCreateInfo.pAttachments = attachmentDescriptions;
847 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
848 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600849 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100850
851 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[4] = {};
852 // Color attachment
853 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
854 framebufferAttachmentImageInfos[0].width = attachmentWidth;
855 framebufferAttachmentImageInfos[0].height = attachmentHeight;
856 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
857 framebufferAttachmentImageInfos[0].layerCount = 2;
858 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
859 framebufferAttachmentImageInfos[0].pViewFormats = &colorAndInputAttachmentFormat;
860 // Color resolve attachment
861 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
862 framebufferAttachmentImageInfos[1].width = attachmentWidth;
863 framebufferAttachmentImageInfos[1].height = attachmentHeight;
864 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
865 framebufferAttachmentImageInfos[1].layerCount = 2;
866 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
867 framebufferAttachmentImageInfos[1].pViewFormats = &colorAndInputAttachmentFormat;
868 // Depth stencil attachment
869 framebufferAttachmentImageInfos[2].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
870 framebufferAttachmentImageInfos[2].width = attachmentWidth;
871 framebufferAttachmentImageInfos[2].height = attachmentHeight;
872 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
873 framebufferAttachmentImageInfos[2].layerCount = 2;
874 framebufferAttachmentImageInfos[2].viewFormatCount = 1;
875 framebufferAttachmentImageInfos[2].pViewFormats = &depthStencilAttachmentFormat;
876 // Input attachment
877 framebufferAttachmentImageInfos[3].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
878 framebufferAttachmentImageInfos[3].width = attachmentWidth;
879 framebufferAttachmentImageInfos[3].height = attachmentHeight;
880 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
881 framebufferAttachmentImageInfos[3].layerCount = 2;
882 framebufferAttachmentImageInfos[3].viewFormatCount = 1;
883 framebufferAttachmentImageInfos[3].pViewFormats = &colorAndInputAttachmentFormat;
884 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
885 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
886 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 4;
887 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
888 VkFramebufferCreateInfo framebufferCreateInfo = {};
889 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
890 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
891 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
892 framebufferCreateInfo.width = attachmentWidth;
893 framebufferCreateInfo.height = attachmentHeight;
894 framebufferCreateInfo.layers = 1;
895 framebufferCreateInfo.renderPass = renderPass;
896 framebufferCreateInfo.attachmentCount = 4;
897 VkFramebuffer framebuffer = VK_NULL_HANDLE;
898
899 // Color attachment, mismatched layer count
900 framebufferAttachmentImageInfos[0].layerCount = 1;
901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600902 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100903 m_errorMonitor->VerifyFound();
904 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600905 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100906 }
907 framebufferAttachmentImageInfos[0].layerCount = 2;
908
909 // Color resolve attachment, mismatched layer count
910 framebufferAttachmentImageInfos[1].layerCount = 1;
911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600912 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100913 m_errorMonitor->VerifyFound();
914 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600915 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100916 }
917 framebufferAttachmentImageInfos[1].layerCount = 2;
918
919 // Depth stencil attachment, mismatched layer count
920 framebufferAttachmentImageInfos[2].layerCount = 1;
921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600922 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100923 m_errorMonitor->VerifyFound();
924 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600925 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100926 }
927 framebufferAttachmentImageInfos[2].layerCount = 2;
928
929 // Input attachment, mismatched layer count
930 framebufferAttachmentImageInfos[3].layerCount = 1;
931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600932 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100933 m_errorMonitor->VerifyFound();
934 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600935 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100936 }
937 framebufferAttachmentImageInfos[3].layerCount = 2;
938
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600939 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100940}
941
942TEST_F(VkLayerTest, ImagelessFramebufferDepthStencilResolveAttachmentTests) {
943 TEST_DESCRIPTION(
944 "Create an imageless framebuffer against a render pass using depth stencil resolve, with mismatched information");
945
946 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
947 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
948 } else {
949 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
950 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
951 return;
952 }
953 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
954
955 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
956 if (!rp2Supported) {
957 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
958 return;
959 }
960
961 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME)) {
962 m_device_extension_names.push_back(VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
963 } else {
964 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
965 VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
966 return;
967 }
968
969 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
970 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
971 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
972 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
973 } else {
974 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
975 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
976 return;
977 }
978
979 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
980 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
981 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
982 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
983 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
984 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
985 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
986
987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
988
989 uint32_t attachmentWidth = 512;
990 uint32_t attachmentHeight = 512;
991 VkFormat attachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
992
993 VkAttachmentDescription2KHR attachmentDescriptions[2] = {};
994 // Depth/stencil attachment
995 attachmentDescriptions[0].sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR;
996 attachmentDescriptions[0].format = attachmentFormat;
997 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
998 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
999 // Depth/stencil resolve attachment
1000 attachmentDescriptions[1].sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR;
1001 attachmentDescriptions[1].format = attachmentFormat;
1002 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
1003 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
1004
1005 VkAttachmentReference2KHR depthStencilAttachmentReference = {};
1006 depthStencilAttachmentReference.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR;
1007 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
1008 depthStencilAttachmentReference.attachment = 0;
1009 VkAttachmentReference2KHR depthStencilResolveAttachmentReference = {};
1010 depthStencilResolveAttachmentReference.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR;
1011 depthStencilResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
1012 depthStencilResolveAttachmentReference.attachment = 1;
1013 VkSubpassDescriptionDepthStencilResolveKHR subpassDescriptionDepthStencilResolve = {};
1014 subpassDescriptionDepthStencilResolve.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR;
1015 subpassDescriptionDepthStencilResolve.pDepthStencilResolveAttachment = &depthStencilResolveAttachmentReference;
1016 subpassDescriptionDepthStencilResolve.depthResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR;
1017 subpassDescriptionDepthStencilResolve.stencilResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR;
1018 VkSubpassDescription2KHR subpassDescription = {};
1019 subpassDescription.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR;
1020 subpassDescription.pNext = &subpassDescriptionDepthStencilResolve;
1021 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
1022 subpassDescription.viewMask = 0x3u;
1023
1024 VkRenderPassCreateInfo2KHR renderPassCreateInfo = {};
1025 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR;
1026 renderPassCreateInfo.pNext = nullptr;
1027 renderPassCreateInfo.attachmentCount = 2;
1028 renderPassCreateInfo.subpassCount = 1;
1029 renderPassCreateInfo.pSubpasses = &subpassDescription;
1030 renderPassCreateInfo.pAttachments = attachmentDescriptions;
1031 VkRenderPass renderPass;
1032 PFN_vkCreateRenderPass2KHR vkCreateRenderPass2KHR =
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001033 (PFN_vkCreateRenderPass2KHR)vk::GetDeviceProcAddr(m_device->device(), "vkCreateRenderPass2KHR");
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001034 vkCreateRenderPass2KHR(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
1035
1036 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[2] = {};
1037 // Depth/stencil attachment
1038 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
1039 framebufferAttachmentImageInfos[0].width = attachmentWidth;
1040 framebufferAttachmentImageInfos[0].height = attachmentHeight;
1041 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1042 framebufferAttachmentImageInfos[0].layerCount = 2;
1043 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
1044 framebufferAttachmentImageInfos[0].pViewFormats = &attachmentFormat;
1045 // Depth/stencil resolve attachment
1046 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
1047 framebufferAttachmentImageInfos[1].width = attachmentWidth;
1048 framebufferAttachmentImageInfos[1].height = attachmentHeight;
1049 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1050 framebufferAttachmentImageInfos[1].layerCount = 2;
1051 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
1052 framebufferAttachmentImageInfos[1].pViewFormats = &attachmentFormat;
1053 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
1054 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
1055 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 2;
1056 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
1057 VkFramebufferCreateInfo framebufferCreateInfo = {};
1058 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
1059 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
1060 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
1061 framebufferCreateInfo.width = attachmentWidth;
1062 framebufferCreateInfo.height = attachmentHeight;
1063 framebufferCreateInfo.layers = 1;
1064 framebufferCreateInfo.renderPass = renderPass;
1065 framebufferCreateInfo.attachmentCount = 2;
1066 VkFramebuffer framebuffer = VK_NULL_HANDLE;
1067
1068 // Color attachment, mismatched layer count
1069 framebufferAttachmentImageInfos[0].layerCount = 1;
1070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001071 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001072 m_errorMonitor->VerifyFound();
1073 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001074 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001075 }
1076 framebufferAttachmentImageInfos[0].layerCount = 2;
1077
1078 // Depth resolve attachment, mismatched image usage
1079 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03203");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001081 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001082 m_errorMonitor->VerifyFound();
1083 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001084 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001085 }
1086 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1087
1088 // Depth resolve attachment, mismatched layer count
1089 framebufferAttachmentImageInfos[1].layerCount = 1;
1090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001091 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001092 m_errorMonitor->VerifyFound();
1093 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001094 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001095 }
1096 framebufferAttachmentImageInfos[1].layerCount = 2;
1097
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001098 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001099}