1 /*
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
TEST_F(VkLayerTest,ImagelessFramebufferRenderPassBeginImageViewMismatchTests)31 TEST_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;
87 vkCreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
88
89 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
90 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
91 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
92 framebufferAttachmentImageInfo.width = attachmentWidth;
93 framebufferAttachmentImageInfo.height = attachmentHeight;
94 framebufferAttachmentImageInfo.layerCount = 1;
95 framebufferAttachmentImageInfo.viewFormatCount = 2;
96 framebufferAttachmentImageInfo.pViewFormats = framebufferAttachmentFormats;
97 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
98 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
99 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
100 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
101 VkFramebufferCreateInfo framebufferCreateInfo = {};
102 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
103 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
104 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
105 framebufferCreateInfo.width = attachmentWidth;
106 framebufferCreateInfo.height = attachmentHeight;
107 framebufferCreateInfo.layers = 1;
108 framebufferCreateInfo.attachmentCount = 1;
109 framebufferCreateInfo.pAttachments = nullptr;
110 framebufferCreateInfo.renderPass = renderPass;
111 VkFramebuffer framebuffer;
112
113 VkImageFormatListCreateInfoKHR imageFormatListCreateInfo = {};
114 imageFormatListCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR;
115 imageFormatListCreateInfo.viewFormatCount = 2;
116 imageFormatListCreateInfo.pViewFormats = attachmentFormats;
117 VkImageCreateInfo imageCreateInfo = {};
118 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
119 imageCreateInfo.pNext = &imageFormatListCreateInfo;
120 imageCreateInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
121 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
122 imageCreateInfo.extent.width = attachmentWidth;
123 imageCreateInfo.extent.height = attachmentHeight;
124 imageCreateInfo.extent.depth = 1;
125 imageCreateInfo.arrayLayers = 1;
126 imageCreateInfo.mipLevels = 10;
127 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
128 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
129 imageCreateInfo.format = attachmentFormats[0];
130
131 VkImageObj imageObject(m_device);
132 imageObject.init(&imageCreateInfo);
133 VkImage image = imageObject.image();
134
135 VkImageViewCreateInfo imageViewCreateInfo = {};
136 imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
137 imageViewCreateInfo.image = image;
138 imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
139 imageViewCreateInfo.format = attachmentFormats[0];
140 imageViewCreateInfo.subresourceRange.layerCount = 1;
141 imageViewCreateInfo.subresourceRange.levelCount = 1;
142 imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
143 VkImageView imageView;
144 vkCreateImageView(m_device->device(), &imageViewCreateInfo, NULL, &imageView);
145
146 VkRenderPassAttachmentBeginInfoKHR renderPassAttachmentBeginInfo = {};
147 renderPassAttachmentBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO_KHR;
148 renderPassAttachmentBeginInfo.pNext = nullptr;
149 renderPassAttachmentBeginInfo.attachmentCount = 1;
150 renderPassAttachmentBeginInfo.pAttachments = &imageView;
151 VkRenderPassBeginInfo renderPassBeginInfo = {};
152 renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
153 renderPassBeginInfo.pNext = &renderPassAttachmentBeginInfo;
154 renderPassBeginInfo.renderPass = renderPass;
155 renderPassBeginInfo.renderArea.extent.width = attachmentWidth;
156 renderPassBeginInfo.renderArea.extent.height = attachmentHeight;
157
158 // Imageless framebuffer creation bit not present
159 framebufferCreateInfo.pAttachments = &imageView;
160 framebufferCreateInfo.flags = 0;
161 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
162 renderPassBeginInfo.framebuffer = framebuffer;
163 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
164 "VUID-VkRenderPassBeginInfo-framebuffer-03207", "VUID-VkRenderPassBeginInfo-framebuffer-03207");
165 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
166 framebufferCreateInfo.pAttachments = nullptr;
167 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
168
169 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
170 renderPassAttachmentBeginInfo.attachmentCount = 2;
171 renderPassBeginInfo.framebuffer = framebuffer;
172 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
173 "VUID-VkRenderPassBeginInfo-framebuffer-03208", "VUID-VkRenderPassBeginInfo-framebuffer-03208");
174 renderPassAttachmentBeginInfo.attachmentCount = 1;
175 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
176
177 // Mismatched number of attachments
178 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
179 renderPassAttachmentBeginInfo.attachmentCount = 2;
180 renderPassBeginInfo.framebuffer = framebuffer;
181 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
182 "VUID-VkRenderPassBeginInfo-framebuffer-03208", "VUID-VkRenderPassBeginInfo-framebuffer-03208");
183 renderPassAttachmentBeginInfo.attachmentCount = 1;
184 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
185
186 // Mismatched flags
187 framebufferAttachmentImageInfo.flags = 0;
188 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
189 renderPassBeginInfo.framebuffer = framebuffer;
190 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
191 "VUID-VkRenderPassBeginInfo-framebuffer-03209", "VUID-VkRenderPassBeginInfo-framebuffer-03209");
192 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
193 framebufferAttachmentImageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
194
195 // Mismatched usage
196 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
197 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
198 renderPassBeginInfo.framebuffer = framebuffer;
199 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
200 "VUID-VkRenderPassBeginInfo-framebuffer-03210", "VUID-VkRenderPassBeginInfo-framebuffer-03210");
201 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
202 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
203
204 // Mismatched width
205 framebufferAttachmentImageInfo.width += 1;
206 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
207 renderPassBeginInfo.framebuffer = framebuffer;
208 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
209 "VUID-VkRenderPassBeginInfo-framebuffer-03211", "VUID-VkRenderPassBeginInfo-framebuffer-03211");
210 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
211 framebufferAttachmentImageInfo.width -= 1;
212
213 // Mismatched height
214 framebufferAttachmentImageInfo.height += 1;
215 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
216 renderPassBeginInfo.framebuffer = framebuffer;
217 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
218 "VUID-VkRenderPassBeginInfo-framebuffer-03212", "VUID-VkRenderPassBeginInfo-framebuffer-03212");
219 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
220 framebufferAttachmentImageInfo.height -= 1;
221
222 // Mismatched layer count
223 framebufferAttachmentImageInfo.layerCount += 1;
224 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
225 renderPassBeginInfo.framebuffer = framebuffer;
226 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
227 "VUID-VkRenderPassBeginInfo-framebuffer-03213", "VUID-VkRenderPassBeginInfo-framebuffer-03213");
228 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
229 framebufferAttachmentImageInfo.layerCount -= 1;
230
231 // Mismatched view format count
232 framebufferAttachmentImageInfo.viewFormatCount = 3;
233 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
234 renderPassBeginInfo.framebuffer = framebuffer;
235 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
236 "VUID-VkRenderPassBeginInfo-framebuffer-03214", "VUID-VkRenderPassBeginInfo-framebuffer-03214");
237 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
238 framebufferAttachmentImageInfo.viewFormatCount = 2;
239
240 // Mismatched format lists
241 framebufferAttachmentFormats[1] = VK_FORMAT_B8G8R8A8_SRGB;
242 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
243 renderPassBeginInfo.framebuffer = framebuffer;
244 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
245 "VUID-VkRenderPassBeginInfo-framebuffer-03215", "VUID-VkRenderPassBeginInfo-framebuffer-03215");
246 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
247 framebufferAttachmentFormats[1] = VK_FORMAT_B8G8R8A8_UNORM;
248
249 // Mismatched formats
250 VkImageView imageView2;
251 imageViewCreateInfo.format = attachmentFormats[1];
252 vkCreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
253 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
254 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
255 renderPassBeginInfo.framebuffer = framebuffer;
256 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
257 "VUID-VkRenderPassBeginInfo-framebuffer-03216", "VUID-VkRenderPassBeginInfo-framebuffer-03216");
258 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
259 vkDestroyImageView(m_device->device(), imageView2, nullptr);
260 renderPassAttachmentBeginInfo.pAttachments = &imageView;
261 imageViewCreateInfo.format = attachmentFormats[0];
262
263 // Mismatched sample counts
264 imageCreateInfo.samples = VK_SAMPLE_COUNT_4_BIT;
265 imageCreateInfo.mipLevels = 1;
266 VkImageObj imageObject2(m_device);
267 imageObject2.init(&imageCreateInfo);
268 imageViewCreateInfo.image = imageObject2.image();
269 vkCreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
270 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
271 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
272 renderPassBeginInfo.framebuffer = framebuffer;
273 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
274 "VUID-VkRenderPassBeginInfo-framebuffer-03217", "VUID-VkRenderPassBeginInfo-framebuffer-03217");
275 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
276 vkDestroyImageView(m_device->device(), imageView2, nullptr);
277 renderPassAttachmentBeginInfo.pAttachments = &imageView;
278 imageViewCreateInfo.image = imageObject.image();
279 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
280 imageCreateInfo.mipLevels = 10;
281
282 // Mismatched level counts
283 imageViewCreateInfo.subresourceRange.levelCount = 2;
284 vkCreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
285 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
286 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
287 renderPassBeginInfo.framebuffer = framebuffer;
288 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
289 "VUID-VkRenderPassAttachmentBeginInfoKHR-pAttachments-03218",
290 "VUID-VkRenderPassAttachmentBeginInfoKHR-pAttachments-03218");
291 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
292 vkDestroyImageView(m_device->device(), imageView2, nullptr);
293 renderPassAttachmentBeginInfo.pAttachments = &imageView;
294 imageViewCreateInfo.subresourceRange.levelCount = 1;
295
296 // Non-identity component swizzle
297 imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_A;
298 vkCreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
299 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
300 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
301 renderPassBeginInfo.framebuffer = framebuffer;
302 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
303 "VUID-VkRenderPassAttachmentBeginInfoKHR-pAttachments-03219",
304 "VUID-VkRenderPassAttachmentBeginInfoKHR-pAttachments-03219");
305 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
306 vkDestroyImageView(m_device->device(), imageView2, nullptr);
307 renderPassAttachmentBeginInfo.pAttachments = &imageView;
308 imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
309
310 vkDestroyRenderPass(m_device->device(), renderPass, nullptr);
311 // vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
312 vkDestroyImageView(m_device->device(), imageView, nullptr);
313 }
314
TEST_F(VkLayerTest,ImagelessFramebufferFeatureEnableTest)315 TEST_F(VkLayerTest, ImagelessFramebufferFeatureEnableTest) {
316 TEST_DESCRIPTION("Use imageless framebuffer functionality without enabling the feature");
317
318 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
319 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
320 } else {
321 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
322 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
323 return;
324 }
325 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
326
327 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
328 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
329 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
330 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
331 } else {
332 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
333 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
334 return;
335 }
336
337 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
338
339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
340
341 uint32_t attachmentWidth = 512;
342 uint32_t attachmentHeight = 512;
343 VkFormat attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
344
345 // Create a renderPass with a single attachment
346 VkAttachmentDescription attachmentDescription = {};
347 attachmentDescription.format = attachmentFormat;
348 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
349 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
350 VkAttachmentReference attachmentReference = {};
351 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
352 VkSubpassDescription subpassDescription = {};
353 subpassDescription.colorAttachmentCount = 1;
354 subpassDescription.pColorAttachments = &attachmentReference;
355 VkRenderPassCreateInfo renderPassCreateInfo = {};
356 renderPassCreateInfo.subpassCount = 1;
357 renderPassCreateInfo.pSubpasses = &subpassDescription;
358 renderPassCreateInfo.attachmentCount = 1;
359 renderPassCreateInfo.pAttachments = &attachmentDescription;
360 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
361 VkRenderPass renderPass;
362 vkCreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
363
364 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
365 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
366 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
367 framebufferAttachmentImageInfo.width = attachmentWidth;
368 framebufferAttachmentImageInfo.height = attachmentHeight;
369 framebufferAttachmentImageInfo.layerCount = 1;
370 framebufferAttachmentImageInfo.viewFormatCount = 1;
371 framebufferAttachmentImageInfo.pViewFormats = &attachmentFormat;
372 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
373 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
374 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
375 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
376 VkFramebufferCreateInfo framebufferCreateInfo = {};
377 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
378 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
379 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
380 framebufferCreateInfo.width = attachmentWidth;
381 framebufferCreateInfo.height = attachmentHeight;
382 framebufferCreateInfo.layers = 1;
383 framebufferCreateInfo.renderPass = renderPass;
384 framebufferCreateInfo.attachmentCount = 1;
385 VkFramebuffer framebuffer = VK_NULL_HANDLE;
386
387 // Imageless framebuffer creation bit not present
388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03189");
389 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
390 m_errorMonitor->VerifyFound();
391
392 if (framebuffer != VK_NULL_HANDLE) {
393 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
394 }
395 vkDestroyRenderPass(m_device->device(), renderPass, nullptr);
396 }
397
TEST_F(VkLayerTest,ImagelessFramebufferCreationTests)398 TEST_F(VkLayerTest, ImagelessFramebufferCreationTests) {
399 TEST_DESCRIPTION("Create an imageless framebuffer in various invalid ways");
400
401 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
402 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
403 } else {
404 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
405 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
406 return;
407 }
408 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
409 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
410
411 bool multiviewSupported = rp2Supported;
412 if (!rp2Supported) {
413 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MULTIVIEW_EXTENSION_NAME)) {
414 m_device_extension_names.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
415 multiviewSupported = true;
416 }
417 }
418
419 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
420 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
421 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
422 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
423 } else {
424 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
425 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
426 return;
427 }
428
429 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
430 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
431 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
432 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
433 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
434 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
435 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
436
437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
438
439 uint32_t attachmentWidth = 512;
440 uint32_t attachmentHeight = 512;
441 VkFormat attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
442
443 // Create a renderPass with a single attachment
444 VkAttachmentDescription attachmentDescription = {};
445 attachmentDescription.format = attachmentFormat;
446 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
447 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
448 VkAttachmentReference attachmentReference = {};
449 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
450 VkSubpassDescription subpassDescription = {};
451 subpassDescription.colorAttachmentCount = 1;
452 subpassDescription.pColorAttachments = &attachmentReference;
453 VkRenderPassCreateInfo renderPassCreateInfo = {};
454 renderPassCreateInfo.subpassCount = 1;
455 renderPassCreateInfo.pSubpasses = &subpassDescription;
456 renderPassCreateInfo.attachmentCount = 1;
457 renderPassCreateInfo.pAttachments = &attachmentDescription;
458 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
459 VkRenderPass renderPass;
460 vkCreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
461
462 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
463 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
464 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
465 framebufferAttachmentImageInfo.width = attachmentWidth;
466 framebufferAttachmentImageInfo.height = attachmentHeight;
467 framebufferAttachmentImageInfo.layerCount = 1;
468 framebufferAttachmentImageInfo.viewFormatCount = 1;
469 framebufferAttachmentImageInfo.pViewFormats = &attachmentFormat;
470 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
471 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
472 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
473 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
474 VkFramebufferCreateInfo framebufferCreateInfo = {};
475 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
476 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
477 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
478 framebufferCreateInfo.width = attachmentWidth;
479 framebufferCreateInfo.height = attachmentHeight;
480 framebufferCreateInfo.layers = 1;
481 framebufferCreateInfo.renderPass = renderPass;
482 framebufferCreateInfo.attachmentCount = 1;
483 VkFramebuffer framebuffer = VK_NULL_HANDLE;
484
485 // Attachments info not present
486 framebufferCreateInfo.pNext = nullptr;
487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03190");
488 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
489 m_errorMonitor->VerifyFound();
490 if (framebuffer != VK_NULL_HANDLE) {
491 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
492 }
493 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
494
495 // Mismatched attachment counts
496 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 2;
497 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[2] = {framebufferAttachmentImageInfo,
498 framebufferAttachmentImageInfo};
499 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03191");
501 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
502 m_errorMonitor->VerifyFound();
503 if (framebuffer != VK_NULL_HANDLE) {
504 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
505 }
506 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
507 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
508
509 // Mismatched format list
510 attachmentFormat = VK_FORMAT_B8G8R8A8_UNORM;
511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03205");
512 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
513 m_errorMonitor->VerifyFound();
514 if (framebuffer != VK_NULL_HANDLE) {
515 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
516 }
517 attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
518
519 // Mismatched format list
520 attachmentFormat = VK_FORMAT_B8G8R8A8_UNORM;
521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03205");
522 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
523 m_errorMonitor->VerifyFound();
524 if (framebuffer != VK_NULL_HANDLE) {
525 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
526 }
527 attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
528
529 // Mismatched layer count, multiview disabled
530 framebufferCreateInfo.layers = 2;
531 const char* mismatchedLayersNoMultiviewVuid =
532 multiviewSupported ? "VUID-VkFramebufferCreateInfo-renderPass-03199" : "VUID-VkFramebufferCreateInfo-flags-03200";
533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, mismatchedLayersNoMultiviewVuid);
534 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
535 m_errorMonitor->VerifyFound();
536 if (framebuffer != VK_NULL_HANDLE) {
537 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
538 }
539 framebufferCreateInfo.layers = 1;
540
541 // Mismatched width
542 framebufferCreateInfo.width += 1;
543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03192");
544 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
545 m_errorMonitor->VerifyFound();
546 if (framebuffer != VK_NULL_HANDLE) {
547 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
548 }
549 framebufferCreateInfo.width -= 1;
550
551 // Mismatched height
552 framebufferCreateInfo.height += 1;
553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03193");
554 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
555 m_errorMonitor->VerifyFound();
556 if (framebuffer != VK_NULL_HANDLE) {
557 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
558 }
559 framebufferCreateInfo.height -= 1;
560
561 vkDestroyRenderPass(m_device->device(), renderPass, nullptr);
562 }
563
TEST_F(VkLayerTest,ImagelessFramebufferAttachmentImageUsageMismatchTests)564 TEST_F(VkLayerTest, ImagelessFramebufferAttachmentImageUsageMismatchTests) {
565 TEST_DESCRIPTION("Create an imageless framebuffer with mismatched attachment image usage");
566
567 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
568 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
569 } else {
570 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
571 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
572 return;
573 }
574 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
575
576 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
577 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
578 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
579 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
580 } else {
581 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
582 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
583 return;
584 }
585
586 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
587 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
588 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
589 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
590 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
591 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
592 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
593
594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
595
596 uint32_t attachmentWidth = 512;
597 uint32_t attachmentHeight = 512;
598 VkFormat colorAndInputAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
599 VkFormat depthStencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
600
601 VkAttachmentDescription attachmentDescriptions[4] = {};
602 // Color attachment
603 attachmentDescriptions[0].format = colorAndInputAttachmentFormat;
604 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
605 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
606 // Color resolve attachment
607 attachmentDescriptions[1].format = colorAndInputAttachmentFormat;
608 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
609 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
610 // Depth stencil attachment
611 attachmentDescriptions[2].format = depthStencilAttachmentFormat;
612 attachmentDescriptions[2].samples = VK_SAMPLE_COUNT_4_BIT;
613 attachmentDescriptions[2].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
614 // Input attachment
615 attachmentDescriptions[3].format = colorAndInputAttachmentFormat;
616 attachmentDescriptions[3].samples = VK_SAMPLE_COUNT_1_BIT;
617 attachmentDescriptions[3].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
618
619 VkAttachmentReference colorAttachmentReference = {};
620 colorAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
621 colorAttachmentReference.attachment = 0;
622 VkAttachmentReference colorResolveAttachmentReference = {};
623 colorResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
624 colorResolveAttachmentReference.attachment = 1;
625 VkAttachmentReference depthStencilAttachmentReference = {};
626 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
627 depthStencilAttachmentReference.attachment = 2;
628 VkAttachmentReference inputAttachmentReference = {};
629 inputAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
630 inputAttachmentReference.attachment = 3;
631 VkSubpassDescription subpassDescription = {};
632 subpassDescription.colorAttachmentCount = 1;
633 subpassDescription.pColorAttachments = &colorAttachmentReference;
634 subpassDescription.pResolveAttachments = &colorResolveAttachmentReference;
635 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
636 subpassDescription.inputAttachmentCount = 1;
637 subpassDescription.pInputAttachments = &inputAttachmentReference;
638
639 VkRenderPassCreateInfo renderPassCreateInfo = {};
640 renderPassCreateInfo.attachmentCount = 4;
641 renderPassCreateInfo.subpassCount = 1;
642 renderPassCreateInfo.pSubpasses = &subpassDescription;
643 renderPassCreateInfo.pAttachments = attachmentDescriptions;
644 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
645 VkRenderPass renderPass;
646 vkCreateRenderPass(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
647
648 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[4] = {};
649 // Color attachment
650 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
651 framebufferAttachmentImageInfos[0].width = attachmentWidth;
652 framebufferAttachmentImageInfos[0].height = attachmentHeight;
653 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
654 framebufferAttachmentImageInfos[0].layerCount = 1;
655 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
656 framebufferAttachmentImageInfos[0].pViewFormats = &colorAndInputAttachmentFormat;
657 // Color resolve attachment
658 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
659 framebufferAttachmentImageInfos[1].width = attachmentWidth;
660 framebufferAttachmentImageInfos[1].height = attachmentHeight;
661 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
662 framebufferAttachmentImageInfos[1].layerCount = 1;
663 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
664 framebufferAttachmentImageInfos[1].pViewFormats = &colorAndInputAttachmentFormat;
665 // Depth stencil attachment
666 framebufferAttachmentImageInfos[2].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
667 framebufferAttachmentImageInfos[2].width = attachmentWidth;
668 framebufferAttachmentImageInfos[2].height = attachmentHeight;
669 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
670 framebufferAttachmentImageInfos[2].layerCount = 1;
671 framebufferAttachmentImageInfos[2].viewFormatCount = 1;
672 framebufferAttachmentImageInfos[2].pViewFormats = &depthStencilAttachmentFormat;
673 // Input attachment
674 framebufferAttachmentImageInfos[3].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
675 framebufferAttachmentImageInfos[3].width = attachmentWidth;
676 framebufferAttachmentImageInfos[3].height = attachmentHeight;
677 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
678 framebufferAttachmentImageInfos[3].layerCount = 1;
679 framebufferAttachmentImageInfos[3].viewFormatCount = 1;
680 framebufferAttachmentImageInfos[3].pViewFormats = &colorAndInputAttachmentFormat;
681 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
682 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
683 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 4;
684 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
685 VkFramebufferCreateInfo framebufferCreateInfo = {};
686 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
687 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
688 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
689 framebufferCreateInfo.width = attachmentWidth;
690 framebufferCreateInfo.height = attachmentHeight;
691 framebufferCreateInfo.layers = 1;
692 framebufferCreateInfo.renderPass = renderPass;
693 framebufferCreateInfo.attachmentCount = 4;
694 VkFramebuffer framebuffer = VK_NULL_HANDLE;
695
696 // Color attachment, mismatched usage
697 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03201");
699 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
700 m_errorMonitor->VerifyFound();
701 if (framebuffer != VK_NULL_HANDLE) {
702 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
703 }
704 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
705
706 // Color resolve attachment, mismatched usage
707 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03201");
709 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
710 m_errorMonitor->VerifyFound();
711 if (framebuffer != VK_NULL_HANDLE) {
712 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
713 }
714 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
715
716 // Depth stencil attachment, mismatched usage
717 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03202");
719 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
720 m_errorMonitor->VerifyFound();
721 if (framebuffer != VK_NULL_HANDLE) {
722 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
723 }
724 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
725
726 // Color attachment, mismatched usage
727 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03204");
729 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
730 m_errorMonitor->VerifyFound();
731 if (framebuffer != VK_NULL_HANDLE) {
732 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
733 }
734 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
735
736 vkDestroyRenderPass(m_device->device(), renderPass, nullptr);
737 }
738
TEST_F(VkLayerTest,ImagelessFramebufferAttachmentMultiviewImageLayerCountMismatchTests)739 TEST_F(VkLayerTest, ImagelessFramebufferAttachmentMultiviewImageLayerCountMismatchTests) {
740 TEST_DESCRIPTION("Create an imageless framebuffer against a multiview-enabled render pass with mismatched layer counts");
741
742 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
743 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
744 } else {
745 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
746 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
747 return;
748 }
749 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
750
751 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MULTIVIEW_EXTENSION_NAME)) {
752 m_device_extension_names.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
753 } else {
754 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix, VK_KHR_MULTIVIEW_EXTENSION_NAME);
755 return;
756 }
757
758 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
759 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
760 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
761 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
762 } else {
763 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
764 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
765 return;
766 }
767
768 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
769 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
770 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
771 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
772 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
773 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
774 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
775
776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
777
778 uint32_t attachmentWidth = 512;
779 uint32_t attachmentHeight = 512;
780 VkFormat colorAndInputAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
781 VkFormat depthStencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
782
783 VkAttachmentDescription attachmentDescriptions[4] = {};
784 // Color attachment
785 attachmentDescriptions[0].format = colorAndInputAttachmentFormat;
786 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
787 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
788 // Color resolve attachment
789 attachmentDescriptions[1].format = colorAndInputAttachmentFormat;
790 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
791 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
792 // Depth stencil attachment
793 attachmentDescriptions[2].format = depthStencilAttachmentFormat;
794 attachmentDescriptions[2].samples = VK_SAMPLE_COUNT_4_BIT;
795 attachmentDescriptions[2].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
796 // Input attachment
797 attachmentDescriptions[3].format = colorAndInputAttachmentFormat;
798 attachmentDescriptions[3].samples = VK_SAMPLE_COUNT_1_BIT;
799 attachmentDescriptions[3].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
800
801 VkAttachmentReference colorAttachmentReference = {};
802 colorAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
803 colorAttachmentReference.attachment = 0;
804 VkAttachmentReference colorResolveAttachmentReference = {};
805 colorResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
806 colorResolveAttachmentReference.attachment = 1;
807 VkAttachmentReference depthStencilAttachmentReference = {};
808 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
809 depthStencilAttachmentReference.attachment = 2;
810 VkAttachmentReference inputAttachmentReference = {};
811 inputAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
812 inputAttachmentReference.attachment = 3;
813 VkSubpassDescription subpassDescription = {};
814 subpassDescription.colorAttachmentCount = 1;
815 subpassDescription.pColorAttachments = &colorAttachmentReference;
816 subpassDescription.pResolveAttachments = &colorResolveAttachmentReference;
817 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
818 subpassDescription.inputAttachmentCount = 1;
819 subpassDescription.pInputAttachments = &inputAttachmentReference;
820
821 uint32_t viewMask = 0x3u;
822 VkRenderPassMultiviewCreateInfo renderPassMultiviewCreateInfo = {};
823 renderPassMultiviewCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO;
824 renderPassMultiviewCreateInfo.subpassCount = 1;
825 renderPassMultiviewCreateInfo.pViewMasks = &viewMask;
826 VkRenderPassCreateInfo renderPassCreateInfo = {};
827 renderPassCreateInfo.pNext = &renderPassMultiviewCreateInfo;
828 renderPassCreateInfo.attachmentCount = 4;
829 renderPassCreateInfo.subpassCount = 1;
830 renderPassCreateInfo.pSubpasses = &subpassDescription;
831 renderPassCreateInfo.pAttachments = attachmentDescriptions;
832 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
833 VkRenderPass renderPass;
834 vkCreateRenderPass(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
835
836 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[4] = {};
837 // Color attachment
838 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
839 framebufferAttachmentImageInfos[0].width = attachmentWidth;
840 framebufferAttachmentImageInfos[0].height = attachmentHeight;
841 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
842 framebufferAttachmentImageInfos[0].layerCount = 2;
843 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
844 framebufferAttachmentImageInfos[0].pViewFormats = &colorAndInputAttachmentFormat;
845 // Color resolve attachment
846 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
847 framebufferAttachmentImageInfos[1].width = attachmentWidth;
848 framebufferAttachmentImageInfos[1].height = attachmentHeight;
849 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
850 framebufferAttachmentImageInfos[1].layerCount = 2;
851 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
852 framebufferAttachmentImageInfos[1].pViewFormats = &colorAndInputAttachmentFormat;
853 // Depth stencil attachment
854 framebufferAttachmentImageInfos[2].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
855 framebufferAttachmentImageInfos[2].width = attachmentWidth;
856 framebufferAttachmentImageInfos[2].height = attachmentHeight;
857 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
858 framebufferAttachmentImageInfos[2].layerCount = 2;
859 framebufferAttachmentImageInfos[2].viewFormatCount = 1;
860 framebufferAttachmentImageInfos[2].pViewFormats = &depthStencilAttachmentFormat;
861 // Input attachment
862 framebufferAttachmentImageInfos[3].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
863 framebufferAttachmentImageInfos[3].width = attachmentWidth;
864 framebufferAttachmentImageInfos[3].height = attachmentHeight;
865 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
866 framebufferAttachmentImageInfos[3].layerCount = 2;
867 framebufferAttachmentImageInfos[3].viewFormatCount = 1;
868 framebufferAttachmentImageInfos[3].pViewFormats = &colorAndInputAttachmentFormat;
869 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
870 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
871 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 4;
872 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
873 VkFramebufferCreateInfo framebufferCreateInfo = {};
874 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
875 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
876 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
877 framebufferCreateInfo.width = attachmentWidth;
878 framebufferCreateInfo.height = attachmentHeight;
879 framebufferCreateInfo.layers = 1;
880 framebufferCreateInfo.renderPass = renderPass;
881 framebufferCreateInfo.attachmentCount = 4;
882 VkFramebuffer framebuffer = VK_NULL_HANDLE;
883
884 // Color attachment, mismatched layer count
885 framebufferAttachmentImageInfos[0].layerCount = 1;
886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
887 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
888 m_errorMonitor->VerifyFound();
889 if (framebuffer != VK_NULL_HANDLE) {
890 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
891 }
892 framebufferAttachmentImageInfos[0].layerCount = 2;
893
894 // Color resolve attachment, mismatched layer count
895 framebufferAttachmentImageInfos[1].layerCount = 1;
896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
897 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
898 m_errorMonitor->VerifyFound();
899 if (framebuffer != VK_NULL_HANDLE) {
900 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
901 }
902 framebufferAttachmentImageInfos[1].layerCount = 2;
903
904 // Depth stencil attachment, mismatched layer count
905 framebufferAttachmentImageInfos[2].layerCount = 1;
906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
907 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
908 m_errorMonitor->VerifyFound();
909 if (framebuffer != VK_NULL_HANDLE) {
910 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
911 }
912 framebufferAttachmentImageInfos[2].layerCount = 2;
913
914 // Input attachment, mismatched layer count
915 framebufferAttachmentImageInfos[3].layerCount = 1;
916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
917 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
918 m_errorMonitor->VerifyFound();
919 if (framebuffer != VK_NULL_HANDLE) {
920 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
921 }
922 framebufferAttachmentImageInfos[3].layerCount = 2;
923
924 vkDestroyRenderPass(m_device->device(), renderPass, nullptr);
925 }
926
TEST_F(VkLayerTest,ImagelessFramebufferDepthStencilResolveAttachmentTests)927 TEST_F(VkLayerTest, ImagelessFramebufferDepthStencilResolveAttachmentTests) {
928 TEST_DESCRIPTION(
929 "Create an imageless framebuffer against a render pass using depth stencil resolve, with mismatched information");
930
931 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
932 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
933 } else {
934 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
935 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
936 return;
937 }
938 ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
939
940 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
941 if (!rp2Supported) {
942 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
943 return;
944 }
945
946 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME)) {
947 m_device_extension_names.push_back(VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
948 } else {
949 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
950 VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
951 return;
952 }
953
954 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
955 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
956 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
957 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
958 } else {
959 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
960 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
961 return;
962 }
963
964 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
965 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
966 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
967 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
968 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
969 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
970 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
971
972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
973
974 uint32_t attachmentWidth = 512;
975 uint32_t attachmentHeight = 512;
976 VkFormat attachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
977
978 VkAttachmentDescription2KHR attachmentDescriptions[2] = {};
979 // Depth/stencil attachment
980 attachmentDescriptions[0].sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR;
981 attachmentDescriptions[0].format = attachmentFormat;
982 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
983 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
984 // Depth/stencil resolve attachment
985 attachmentDescriptions[1].sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR;
986 attachmentDescriptions[1].format = attachmentFormat;
987 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
988 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
989
990 VkAttachmentReference2KHR depthStencilAttachmentReference = {};
991 depthStencilAttachmentReference.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR;
992 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
993 depthStencilAttachmentReference.attachment = 0;
994 VkAttachmentReference2KHR depthStencilResolveAttachmentReference = {};
995 depthStencilResolveAttachmentReference.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR;
996 depthStencilResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
997 depthStencilResolveAttachmentReference.attachment = 1;
998 VkSubpassDescriptionDepthStencilResolveKHR subpassDescriptionDepthStencilResolve = {};
999 subpassDescriptionDepthStencilResolve.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR;
1000 subpassDescriptionDepthStencilResolve.pDepthStencilResolveAttachment = &depthStencilResolveAttachmentReference;
1001 subpassDescriptionDepthStencilResolve.depthResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR;
1002 subpassDescriptionDepthStencilResolve.stencilResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR;
1003 VkSubpassDescription2KHR subpassDescription = {};
1004 subpassDescription.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR;
1005 subpassDescription.pNext = &subpassDescriptionDepthStencilResolve;
1006 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
1007 subpassDescription.viewMask = 0x3u;
1008
1009 VkRenderPassCreateInfo2KHR renderPassCreateInfo = {};
1010 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR;
1011 renderPassCreateInfo.pNext = nullptr;
1012 renderPassCreateInfo.attachmentCount = 2;
1013 renderPassCreateInfo.subpassCount = 1;
1014 renderPassCreateInfo.pSubpasses = &subpassDescription;
1015 renderPassCreateInfo.pAttachments = attachmentDescriptions;
1016 VkRenderPass renderPass;
1017 PFN_vkCreateRenderPass2KHR vkCreateRenderPass2KHR =
1018 (PFN_vkCreateRenderPass2KHR)vkGetDeviceProcAddr(m_device->device(), "vkCreateRenderPass2KHR");
1019 vkCreateRenderPass2KHR(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
1020
1021 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[2] = {};
1022 // Depth/stencil attachment
1023 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
1024 framebufferAttachmentImageInfos[0].width = attachmentWidth;
1025 framebufferAttachmentImageInfos[0].height = attachmentHeight;
1026 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1027 framebufferAttachmentImageInfos[0].layerCount = 2;
1028 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
1029 framebufferAttachmentImageInfos[0].pViewFormats = &attachmentFormat;
1030 // Depth/stencil resolve attachment
1031 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
1032 framebufferAttachmentImageInfos[1].width = attachmentWidth;
1033 framebufferAttachmentImageInfos[1].height = attachmentHeight;
1034 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1035 framebufferAttachmentImageInfos[1].layerCount = 2;
1036 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
1037 framebufferAttachmentImageInfos[1].pViewFormats = &attachmentFormat;
1038 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
1039 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
1040 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 2;
1041 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
1042 VkFramebufferCreateInfo framebufferCreateInfo = {};
1043 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
1044 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
1045 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
1046 framebufferCreateInfo.width = attachmentWidth;
1047 framebufferCreateInfo.height = attachmentHeight;
1048 framebufferCreateInfo.layers = 1;
1049 framebufferCreateInfo.renderPass = renderPass;
1050 framebufferCreateInfo.attachmentCount = 2;
1051 VkFramebuffer framebuffer = VK_NULL_HANDLE;
1052
1053 // Color attachment, mismatched layer count
1054 framebufferAttachmentImageInfos[0].layerCount = 1;
1055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
1056 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
1057 m_errorMonitor->VerifyFound();
1058 if (framebuffer != VK_NULL_HANDLE) {
1059 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
1060 }
1061 framebufferAttachmentImageInfos[0].layerCount = 2;
1062
1063 // Depth resolve attachment, mismatched image usage
1064 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-flags-03203");
1066 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
1067 m_errorMonitor->VerifyFound();
1068 if (framebuffer != VK_NULL_HANDLE) {
1069 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
1070 }
1071 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1072
1073 // Depth resolve attachment, mismatched layer count
1074 framebufferAttachmentImageInfos[1].layerCount = 1;
1075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VUID-VkFramebufferCreateInfo-renderPass-03198");
1076 vkCreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
1077 m_errorMonitor->VerifyFound();
1078 if (framebuffer != VK_NULL_HANDLE) {
1079 vkDestroyFramebuffer(m_device->device(), framebuffer, nullptr);
1080 }
1081 framebufferAttachmentImageInfos[1].layerCount = 2;
1082
1083 vkDestroyRenderPass(m_device->device(), renderPass, nullptr);
1084 }
1085