blob: bf162e2f3c56ed0202ee8005754b9ddce38c35d5 [file] [log] [blame]
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001/*
Shannon McPhersoncfb16b52021-01-04 14:24:40 -07002 * Copyright (c) 2015-2021 The Khronos Group Inc.
3 * Copyright (c) 2015-2021 Valve Corporation
4 * Copyright (c) 2015-2021 LunarG, Inc.
5 * Copyright (c) 2015-2021 Google, Inc.
6 * Modifications Copyright (C) 2020-2021 Advanced Micro Devices, Inc. All rights reserved.
Tobias Hectorcf26efe2019-07-23 12:18:52 +01007 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Author: Chia-I Wu <olvaffe@gmail.com>
15 * Author: Chris Forbes <chrisf@ijw.co.nz>
16 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
17 * Author: Mark Lobodzinski <mark@lunarg.com>
18 * Author: Mike Stroyan <mike@LunarG.com>
19 * Author: Tobin Ehlis <tobine@google.com>
20 * Author: Tony Barbour <tony@LunarG.com>
21 * Author: Cody Northrop <cnorthrop@google.com>
22 * Author: Dave Houlton <daveh@lunarg.com>
23 * Author: Jeremy Kniager <jeremyk@lunarg.com>
24 * Author: Shannon McPherson <shannon@lunarg.com>
25 * Author: John Zulauf <jzulauf@lunarg.com>
26 * Author: Tobias Hector <tobias.hector@amd.com>
27 */
28
29#include "cast_utils.h"
30#include "layer_validation_tests.h"
31
32TEST_F(VkLayerTest, ImagelessFramebufferRenderPassBeginImageViewMismatchTests) {
33 TEST_DESCRIPTION(
34 "Begin a renderPass where the image views specified do not match the parameters used to create the framebuffer and render "
35 "pass.");
36
37 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
38 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
39 } else {
40 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
41 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
42 return;
43 }
44
Mark Lobodzinski09ce9c42020-03-06 10:02:44 -070045 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
Tobias Hectorcf26efe2019-07-23 12:18:52 +010046 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
47
48 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
49 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
50 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
51 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
52 } else {
53 printf("%s test requires VK_KHR_imageless_framebuffer, not available. Skipping.\n", kSkipPrefix);
54 return;
55 }
56
57 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
58 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
59 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
60 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
61 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
62 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
63
64 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
65
66 uint32_t attachmentWidth = 512;
67 uint32_t attachmentHeight = 512;
68 VkFormat attachmentFormats[2] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM};
69 VkFormat framebufferAttachmentFormats[3] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM};
70
71 // Create a renderPass with a single attachment
72 VkAttachmentDescription attachmentDescription = {};
73 attachmentDescription.format = attachmentFormats[0];
74 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
75 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
76 VkAttachmentReference attachmentReference = {};
77 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
78 VkSubpassDescription subpassDescription = {};
79 subpassDescription.colorAttachmentCount = 1;
80 subpassDescription.pColorAttachments = &attachmentReference;
81 VkRenderPassCreateInfo renderPassCreateInfo = {};
82 renderPassCreateInfo.subpassCount = 1;
83 renderPassCreateInfo.pSubpasses = &subpassDescription;
84 renderPassCreateInfo.attachmentCount = 1;
85 renderPassCreateInfo.pAttachments = &attachmentDescription;
86 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
87 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -060088 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +010089
90 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
91 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
Mark Lobodzinski50885992019-12-03 14:44:22 -070092 framebufferAttachmentImageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
sfricke-samsungab73ad62021-01-17 09:05:54 -080093 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Tobias Hectorcf26efe2019-07-23 12:18:52 +010094 framebufferAttachmentImageInfo.width = attachmentWidth;
95 framebufferAttachmentImageInfo.height = attachmentHeight;
96 framebufferAttachmentImageInfo.layerCount = 1;
97 framebufferAttachmentImageInfo.viewFormatCount = 2;
98 framebufferAttachmentImageInfo.pViewFormats = framebufferAttachmentFormats;
99 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
100 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
101 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
102 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
103 VkFramebufferCreateInfo framebufferCreateInfo = {};
104 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
105 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
106 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
107 framebufferCreateInfo.width = attachmentWidth;
108 framebufferCreateInfo.height = attachmentHeight;
109 framebufferCreateInfo.layers = 1;
110 framebufferCreateInfo.attachmentCount = 1;
111 framebufferCreateInfo.pAttachments = nullptr;
112 framebufferCreateInfo.renderPass = renderPass;
113 VkFramebuffer framebuffer;
114
115 VkImageFormatListCreateInfoKHR imageFormatListCreateInfo = {};
116 imageFormatListCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR;
117 imageFormatListCreateInfo.viewFormatCount = 2;
118 imageFormatListCreateInfo.pViewFormats = attachmentFormats;
119 VkImageCreateInfo imageCreateInfo = {};
120 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
121 imageCreateInfo.pNext = &imageFormatListCreateInfo;
122 imageCreateInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
sfricke-samsungab73ad62021-01-17 09:05:54 -0800123 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100124 imageCreateInfo.extent.width = attachmentWidth;
125 imageCreateInfo.extent.height = attachmentHeight;
126 imageCreateInfo.extent.depth = 1;
127 imageCreateInfo.arrayLayers = 1;
128 imageCreateInfo.mipLevels = 10;
129 imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
130 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
131 imageCreateInfo.format = attachmentFormats[0];
132
133 VkImageObj imageObject(m_device);
134 imageObject.init(&imageCreateInfo);
135 VkImage image = imageObject.image();
136
sfricke-samsungab73ad62021-01-17 09:05:54 -0800137 // Only use the subset without the TRANSFER bit
138 VkImageViewUsageCreateInfo image_view_usage_create_info = {};
139 image_view_usage_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO;
140 image_view_usage_create_info.pNext = nullptr;
141 image_view_usage_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
142
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100143 VkImageViewCreateInfo imageViewCreateInfo = {};
144 imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
145 imageViewCreateInfo.image = image;
146 imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
147 imageViewCreateInfo.format = attachmentFormats[0];
148 imageViewCreateInfo.subresourceRange.layerCount = 1;
149 imageViewCreateInfo.subresourceRange.levelCount = 1;
150 imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
sfricke-samsungab73ad62021-01-17 09:05:54 -0800151
152 // Has subset of usage flags
153 VkImageView imageViewSubset;
154 imageViewCreateInfo.pNext = &image_view_usage_create_info;
155 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, NULL, &imageViewSubset);
156 imageViewCreateInfo.pNext = nullptr;
157
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100158 VkImageView imageView;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600159 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, NULL, &imageView);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100160
161 VkRenderPassAttachmentBeginInfoKHR renderPassAttachmentBeginInfo = {};
162 renderPassAttachmentBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO_KHR;
163 renderPassAttachmentBeginInfo.pNext = nullptr;
164 renderPassAttachmentBeginInfo.attachmentCount = 1;
165 renderPassAttachmentBeginInfo.pAttachments = &imageView;
166 VkRenderPassBeginInfo renderPassBeginInfo = {};
167 renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
168 renderPassBeginInfo.pNext = &renderPassAttachmentBeginInfo;
169 renderPassBeginInfo.renderPass = renderPass;
170 renderPassBeginInfo.renderArea.extent.width = attachmentWidth;
171 renderPassBeginInfo.renderArea.extent.height = attachmentHeight;
172
Mark Lobodzinski50885992019-12-03 14:44:22 -0700173 // Positive test first
174 VkCommandBufferBeginInfo cmd_begin_info = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
175 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, nullptr};
176 framebufferCreateInfo.pAttachments = nullptr;
177 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
178 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
179 renderPassBeginInfo.framebuffer = framebuffer;
180 vk::BeginCommandBuffer(m_commandBuffer->handle(), &cmd_begin_info);
181 m_errorMonitor->ExpectSuccess();
182 vk::CmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
183 m_errorMonitor->VerifyNotFound();
184 vk::ResetCommandBuffer(m_commandBuffer->handle(), 0);
185 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
186
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100187 // Imageless framebuffer creation bit not present
188 framebufferCreateInfo.pAttachments = &imageView;
189 framebufferCreateInfo.flags = 0;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600190 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100191 renderPassBeginInfo.framebuffer = framebuffer;
192 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
193 "VUID-VkRenderPassBeginInfo-framebuffer-03207", "VUID-VkRenderPassBeginInfo-framebuffer-03207");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600194 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100195 framebufferCreateInfo.pAttachments = nullptr;
196 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
197
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600198 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100199 renderPassAttachmentBeginInfo.attachmentCount = 2;
200 renderPassBeginInfo.framebuffer = framebuffer;
201 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
202 "VUID-VkRenderPassBeginInfo-framebuffer-03208", "VUID-VkRenderPassBeginInfo-framebuffer-03208");
203 renderPassAttachmentBeginInfo.attachmentCount = 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600204 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100205
206 // Mismatched number of attachments
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600207 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100208 renderPassAttachmentBeginInfo.attachmentCount = 2;
209 renderPassBeginInfo.framebuffer = framebuffer;
210 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
211 "VUID-VkRenderPassBeginInfo-framebuffer-03208", "VUID-VkRenderPassBeginInfo-framebuffer-03208");
212 renderPassAttachmentBeginInfo.attachmentCount = 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600213 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100214
215 // Mismatched flags
216 framebufferAttachmentImageInfo.flags = 0;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600217 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100218 renderPassBeginInfo.framebuffer = framebuffer;
219 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
220 "VUID-VkRenderPassBeginInfo-framebuffer-03209", "VUID-VkRenderPassBeginInfo-framebuffer-03209");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600221 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100222 framebufferAttachmentImageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
223
224 // Mismatched usage
225 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600226 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100227 renderPassBeginInfo.framebuffer = framebuffer;
228 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
Shannon McPherson57255a62020-12-23 16:00:54 -0700229 "VUID-VkRenderPassBeginInfo-framebuffer-04627", "VUID-VkRenderPassBeginInfo-framebuffer-04627");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600230 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
sfricke-samsungab73ad62021-01-17 09:05:54 -0800231 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
232
233 // Mismatched usage because VkImageViewUsageCreateInfo restricted to TRANSFER
234 renderPassAttachmentBeginInfo.pAttachments = &imageViewSubset;
235 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
236 renderPassBeginInfo.framebuffer = framebuffer;
237 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
238 "VUID-VkRenderPassBeginInfo-framebuffer-04627", "VUID-VkRenderPassBeginInfo-framebuffer-04627");
239 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
240 renderPassAttachmentBeginInfo.pAttachments = &imageView;
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100241
242 // Mismatched width
243 framebufferAttachmentImageInfo.width += 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600244 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100245 renderPassBeginInfo.framebuffer = framebuffer;
246 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
247 "VUID-VkRenderPassBeginInfo-framebuffer-03211", "VUID-VkRenderPassBeginInfo-framebuffer-03211");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600248 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100249 framebufferAttachmentImageInfo.width -= 1;
250
251 // Mismatched height
252 framebufferAttachmentImageInfo.height += 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600253 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100254 renderPassBeginInfo.framebuffer = framebuffer;
255 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
256 "VUID-VkRenderPassBeginInfo-framebuffer-03212", "VUID-VkRenderPassBeginInfo-framebuffer-03212");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600257 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100258 framebufferAttachmentImageInfo.height -= 1;
259
260 // Mismatched layer count
261 framebufferAttachmentImageInfo.layerCount += 1;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600262 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100263 renderPassBeginInfo.framebuffer = framebuffer;
264 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
265 "VUID-VkRenderPassBeginInfo-framebuffer-03213", "VUID-VkRenderPassBeginInfo-framebuffer-03213");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600266 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100267 framebufferAttachmentImageInfo.layerCount -= 1;
268
269 // Mismatched view format count
270 framebufferAttachmentImageInfo.viewFormatCount = 3;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600271 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100272 renderPassBeginInfo.framebuffer = framebuffer;
273 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
274 "VUID-VkRenderPassBeginInfo-framebuffer-03214", "VUID-VkRenderPassBeginInfo-framebuffer-03214");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600275 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100276 framebufferAttachmentImageInfo.viewFormatCount = 2;
277
278 // Mismatched format lists
279 framebufferAttachmentFormats[1] = VK_FORMAT_B8G8R8A8_SRGB;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600280 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100281 renderPassBeginInfo.framebuffer = framebuffer;
282 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
283 "VUID-VkRenderPassBeginInfo-framebuffer-03215", "VUID-VkRenderPassBeginInfo-framebuffer-03215");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600284 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100285 framebufferAttachmentFormats[1] = VK_FORMAT_B8G8R8A8_UNORM;
286
287 // Mismatched formats
288 VkImageView imageView2;
289 imageViewCreateInfo.format = attachmentFormats[1];
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600290 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100291 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600292 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100293 renderPassBeginInfo.framebuffer = framebuffer;
294 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
295 "VUID-VkRenderPassBeginInfo-framebuffer-03216", "VUID-VkRenderPassBeginInfo-framebuffer-03216");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600296 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
297 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100298 renderPassAttachmentBeginInfo.pAttachments = &imageView;
299 imageViewCreateInfo.format = attachmentFormats[0];
300
301 // Mismatched sample counts
302 imageCreateInfo.samples = VK_SAMPLE_COUNT_4_BIT;
303 imageCreateInfo.mipLevels = 1;
304 VkImageObj imageObject2(m_device);
305 imageObject2.init(&imageCreateInfo);
306 imageViewCreateInfo.image = imageObject2.image();
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600307 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100308 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600309 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100310 renderPassBeginInfo.framebuffer = framebuffer;
311 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
312 "VUID-VkRenderPassBeginInfo-framebuffer-03217", "VUID-VkRenderPassBeginInfo-framebuffer-03217");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600313 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
314 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100315 renderPassAttachmentBeginInfo.pAttachments = &imageView;
316 imageViewCreateInfo.image = imageObject.image();
317 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
318 imageCreateInfo.mipLevels = 10;
319
320 // Mismatched level counts
321 imageViewCreateInfo.subresourceRange.levelCount = 2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600322 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100323 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600324 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100325 renderPassBeginInfo.framebuffer = framebuffer;
326 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
Mike Schuchardt65847d92019-12-20 13:50:47 -0800327 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03218",
328 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03218");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600329 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
330 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100331 renderPassAttachmentBeginInfo.pAttachments = &imageView;
332 imageViewCreateInfo.subresourceRange.levelCount = 1;
333
334 // Non-identity component swizzle
335 imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_A;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600336 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100337 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600338 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100339 renderPassBeginInfo.framebuffer = framebuffer;
340 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
Mike Schuchardt65847d92019-12-20 13:50:47 -0800341 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03219",
342 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03219");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600343 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
344 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100345 renderPassAttachmentBeginInfo.pAttachments = &imageView;
346 imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
347
Tony-LunarGc327f812021-01-26 15:55:35 -0700348 imageViewCreateInfo.subresourceRange.baseMipLevel = 1;
349 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, nullptr, &imageView2);
350 renderPassAttachmentBeginInfo.pAttachments = &imageView2;
351 framebufferAttachmentImageInfo.height = framebufferAttachmentImageInfo.height / 2;
352 framebufferAttachmentImageInfo.width = framebufferAttachmentImageInfo.width / 2;
353 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
354 renderPassBeginInfo.framebuffer = framebuffer;
355 vk::BeginCommandBuffer(m_commandBuffer->handle(), &cmd_begin_info);
356 m_errorMonitor->ExpectSuccess();
357 vk::CmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
358 m_errorMonitor->VerifyNotFound();
359 vk::ResetCommandBuffer(m_commandBuffer->handle(), 0);
360 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
361 vk::DestroyImageView(m_device->device(), imageView2, nullptr);
362 renderPassAttachmentBeginInfo.pAttachments = &imageView;
363 imageViewCreateInfo.subresourceRange.baseMipLevel = 0;
364 framebufferAttachmentImageInfo.height = framebufferAttachmentImageInfo.height * 2;
365 framebufferAttachmentImageInfo.width = framebufferAttachmentImageInfo.width * 2;
366
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600367 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600368 vk::DestroyImageView(m_device->device(), imageView, nullptr);
sfricke-samsungab73ad62021-01-17 09:05:54 -0800369 vk::DestroyImageView(m_device->device(), imageViewSubset, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100370}
371
372TEST_F(VkLayerTest, ImagelessFramebufferFeatureEnableTest) {
373 TEST_DESCRIPTION("Use imageless framebuffer functionality without enabling the feature");
374
375 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
376 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
377 } else {
378 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
379 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
380 return;
381 }
Mark Lobodzinski09ce9c42020-03-06 10:02:44 -0700382 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100383
384 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
385 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
386 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
387 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
388 } else {
389 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
390 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
391 return;
392 }
393
394 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
395
396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
397
398 uint32_t attachmentWidth = 512;
399 uint32_t attachmentHeight = 512;
400 VkFormat attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
401
402 // Create a renderPass with a single attachment
403 VkAttachmentDescription attachmentDescription = {};
404 attachmentDescription.format = attachmentFormat;
405 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
406 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
407 VkAttachmentReference attachmentReference = {};
408 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
409 VkSubpassDescription subpassDescription = {};
410 subpassDescription.colorAttachmentCount = 1;
411 subpassDescription.pColorAttachments = &attachmentReference;
412 VkRenderPassCreateInfo renderPassCreateInfo = {};
413 renderPassCreateInfo.subpassCount = 1;
414 renderPassCreateInfo.pSubpasses = &subpassDescription;
415 renderPassCreateInfo.attachmentCount = 1;
416 renderPassCreateInfo.pAttachments = &attachmentDescription;
417 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
418 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600419 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100420
421 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
422 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
423 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
424 framebufferAttachmentImageInfo.width = attachmentWidth;
425 framebufferAttachmentImageInfo.height = attachmentHeight;
426 framebufferAttachmentImageInfo.layerCount = 1;
427 framebufferAttachmentImageInfo.viewFormatCount = 1;
428 framebufferAttachmentImageInfo.pViewFormats = &attachmentFormat;
429 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
430 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
431 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
432 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
433 VkFramebufferCreateInfo framebufferCreateInfo = {};
434 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
435 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
436 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
437 framebufferCreateInfo.width = attachmentWidth;
438 framebufferCreateInfo.height = attachmentHeight;
439 framebufferCreateInfo.layers = 1;
440 framebufferCreateInfo.renderPass = renderPass;
441 framebufferCreateInfo.attachmentCount = 1;
442 VkFramebuffer framebuffer = VK_NULL_HANDLE;
443
444 // Imageless framebuffer creation bit not present
Mark Lobodzinski20310782020-02-28 14:25:17 -0700445 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03189");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600446 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100447 m_errorMonitor->VerifyFound();
448
449 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600450 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100451 }
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600452 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100453}
454
455TEST_F(VkLayerTest, ImagelessFramebufferCreationTests) {
456 TEST_DESCRIPTION("Create an imageless framebuffer in various invalid ways");
457
458 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
459 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
460 } else {
461 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
462 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
463 return;
464 }
Mark Lobodzinski09ce9c42020-03-06 10:02:44 -0700465 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100466 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
467
468 bool multiviewSupported = rp2Supported;
469 if (!rp2Supported) {
470 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MULTIVIEW_EXTENSION_NAME)) {
471 m_device_extension_names.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
472 multiviewSupported = true;
473 }
474 }
475
476 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
477 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
478 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
479 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
480 } else {
481 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
482 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
483 return;
484 }
485
486 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
487 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
488 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
489 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
490 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
491 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
492 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
493
494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
495
496 uint32_t attachmentWidth = 512;
497 uint32_t attachmentHeight = 512;
498 VkFormat attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
499
500 // Create a renderPass with a single attachment
501 VkAttachmentDescription attachmentDescription = {};
502 attachmentDescription.format = attachmentFormat;
503 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
504 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
505 VkAttachmentReference attachmentReference = {};
506 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
507 VkSubpassDescription subpassDescription = {};
508 subpassDescription.colorAttachmentCount = 1;
509 subpassDescription.pColorAttachments = &attachmentReference;
510 VkRenderPassCreateInfo renderPassCreateInfo = {};
511 renderPassCreateInfo.subpassCount = 1;
512 renderPassCreateInfo.pSubpasses = &subpassDescription;
513 renderPassCreateInfo.attachmentCount = 1;
514 renderPassCreateInfo.pAttachments = &attachmentDescription;
515 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
516 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600517 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100518
519 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
520 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
521 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
522 framebufferAttachmentImageInfo.width = attachmentWidth;
523 framebufferAttachmentImageInfo.height = attachmentHeight;
524 framebufferAttachmentImageInfo.layerCount = 1;
525 framebufferAttachmentImageInfo.viewFormatCount = 1;
526 framebufferAttachmentImageInfo.pViewFormats = &attachmentFormat;
527 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
528 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
529 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
530 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
531 VkFramebufferCreateInfo framebufferCreateInfo = {};
532 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
533 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
534 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
535 framebufferCreateInfo.width = attachmentWidth;
536 framebufferCreateInfo.height = attachmentHeight;
537 framebufferCreateInfo.layers = 1;
538 framebufferCreateInfo.renderPass = renderPass;
539 framebufferCreateInfo.attachmentCount = 1;
540 VkFramebuffer framebuffer = VK_NULL_HANDLE;
541
542 // Attachments info not present
543 framebufferCreateInfo.pNext = nullptr;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700544 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03190");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600545 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100546 m_errorMonitor->VerifyFound();
547 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600548 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100549 }
550 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
551
552 // Mismatched attachment counts
553 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 2;
554 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[2] = {framebufferAttachmentImageInfo,
555 framebufferAttachmentImageInfo};
556 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700557 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03191");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600558 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100559 m_errorMonitor->VerifyFound();
560 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600561 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100562 }
563 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
564 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
565
566 // Mismatched format list
567 attachmentFormat = VK_FORMAT_B8G8R8A8_UNORM;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700568 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03205");
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 attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
575
576 // Mismatched format list
577 attachmentFormat = VK_FORMAT_B8G8R8A8_UNORM;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700578 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03205");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600579 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100580 m_errorMonitor->VerifyFound();
581 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600582 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100583 }
584 attachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
585
586 // Mismatched layer count, multiview disabled
587 framebufferCreateInfo.layers = 2;
588 const char* mismatchedLayersNoMultiviewVuid =
Tobias Hector04f2ab22020-12-01 10:59:33 +0000589 multiviewSupported ? "VUID-VkFramebufferCreateInfo-renderPass-04546" : "VUID-VkFramebufferCreateInfo-flags-04547";
Mark Lobodzinski20310782020-02-28 14:25:17 -0700590 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, mismatchedLayersNoMultiviewVuid);
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600591 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100592 m_errorMonitor->VerifyFound();
593 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600594 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100595 }
596 framebufferCreateInfo.layers = 1;
597
598 // Mismatched width
599 framebufferCreateInfo.width += 1;
Tobias Hector04f2ab22020-12-01 10:59:33 +0000600 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-04541");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600601 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100602 m_errorMonitor->VerifyFound();
603 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600604 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100605 }
606 framebufferCreateInfo.width -= 1;
607
608 // Mismatched height
609 framebufferCreateInfo.height += 1;
Tobias Hector04f2ab22020-12-01 10:59:33 +0000610 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-04542");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600611 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100612 m_errorMonitor->VerifyFound();
613 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600614 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100615 }
616 framebufferCreateInfo.height -= 1;
617
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600618 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100619}
620
621TEST_F(VkLayerTest, ImagelessFramebufferAttachmentImageUsageMismatchTests) {
622 TEST_DESCRIPTION("Create an imageless framebuffer with mismatched attachment image usage");
623
624 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
625 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
626 } else {
627 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
628 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
629 return;
630 }
Mark Lobodzinski09ce9c42020-03-06 10:02:44 -0700631 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100632
633 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
634 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
635 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
636 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
637 } else {
638 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
639 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
640 return;
641 }
642
643 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
644 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
645 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
646 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
647 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
648 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
649 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
650
651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
652
653 uint32_t attachmentWidth = 512;
654 uint32_t attachmentHeight = 512;
655 VkFormat colorAndInputAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
656 VkFormat depthStencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
657
658 VkAttachmentDescription attachmentDescriptions[4] = {};
659 // Color attachment
660 attachmentDescriptions[0].format = colorAndInputAttachmentFormat;
661 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
662 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
663 // Color resolve attachment
664 attachmentDescriptions[1].format = colorAndInputAttachmentFormat;
665 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
666 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
667 // Depth stencil attachment
668 attachmentDescriptions[2].format = depthStencilAttachmentFormat;
669 attachmentDescriptions[2].samples = VK_SAMPLE_COUNT_4_BIT;
670 attachmentDescriptions[2].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
671 // Input attachment
672 attachmentDescriptions[3].format = colorAndInputAttachmentFormat;
673 attachmentDescriptions[3].samples = VK_SAMPLE_COUNT_1_BIT;
674 attachmentDescriptions[3].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
675
676 VkAttachmentReference colorAttachmentReference = {};
677 colorAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
678 colorAttachmentReference.attachment = 0;
679 VkAttachmentReference colorResolveAttachmentReference = {};
680 colorResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
681 colorResolveAttachmentReference.attachment = 1;
682 VkAttachmentReference depthStencilAttachmentReference = {};
683 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
684 depthStencilAttachmentReference.attachment = 2;
685 VkAttachmentReference inputAttachmentReference = {};
686 inputAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
687 inputAttachmentReference.attachment = 3;
688 VkSubpassDescription subpassDescription = {};
689 subpassDescription.colorAttachmentCount = 1;
690 subpassDescription.pColorAttachments = &colorAttachmentReference;
691 subpassDescription.pResolveAttachments = &colorResolveAttachmentReference;
692 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
693 subpassDescription.inputAttachmentCount = 1;
694 subpassDescription.pInputAttachments = &inputAttachmentReference;
695
696 VkRenderPassCreateInfo renderPassCreateInfo = {};
697 renderPassCreateInfo.attachmentCount = 4;
698 renderPassCreateInfo.subpassCount = 1;
699 renderPassCreateInfo.pSubpasses = &subpassDescription;
700 renderPassCreateInfo.pAttachments = attachmentDescriptions;
701 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
702 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600703 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100704
705 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[4] = {};
706 // Color attachment
707 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
708 framebufferAttachmentImageInfos[0].width = attachmentWidth;
709 framebufferAttachmentImageInfos[0].height = attachmentHeight;
710 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
711 framebufferAttachmentImageInfos[0].layerCount = 1;
712 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
713 framebufferAttachmentImageInfos[0].pViewFormats = &colorAndInputAttachmentFormat;
714 // Color resolve attachment
715 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
716 framebufferAttachmentImageInfos[1].width = attachmentWidth;
717 framebufferAttachmentImageInfos[1].height = attachmentHeight;
718 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
719 framebufferAttachmentImageInfos[1].layerCount = 1;
720 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
721 framebufferAttachmentImageInfos[1].pViewFormats = &colorAndInputAttachmentFormat;
722 // Depth stencil attachment
723 framebufferAttachmentImageInfos[2].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
724 framebufferAttachmentImageInfos[2].width = attachmentWidth;
725 framebufferAttachmentImageInfos[2].height = attachmentHeight;
726 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
727 framebufferAttachmentImageInfos[2].layerCount = 1;
728 framebufferAttachmentImageInfos[2].viewFormatCount = 1;
729 framebufferAttachmentImageInfos[2].pViewFormats = &depthStencilAttachmentFormat;
730 // Input attachment
731 framebufferAttachmentImageInfos[3].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
732 framebufferAttachmentImageInfos[3].width = attachmentWidth;
733 framebufferAttachmentImageInfos[3].height = attachmentHeight;
734 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
735 framebufferAttachmentImageInfos[3].layerCount = 1;
736 framebufferAttachmentImageInfos[3].viewFormatCount = 1;
737 framebufferAttachmentImageInfos[3].pViewFormats = &colorAndInputAttachmentFormat;
738 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
739 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
740 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 4;
741 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
742 VkFramebufferCreateInfo framebufferCreateInfo = {};
743 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
744 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
745 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
746 framebufferCreateInfo.width = attachmentWidth;
747 framebufferCreateInfo.height = attachmentHeight;
748 framebufferCreateInfo.layers = 1;
749 framebufferCreateInfo.renderPass = renderPass;
750 framebufferCreateInfo.attachmentCount = 4;
751 VkFramebuffer framebuffer = VK_NULL_HANDLE;
752
753 // Color attachment, mismatched usage
754 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700755 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03201");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600756 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100757 m_errorMonitor->VerifyFound();
758 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600759 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100760 }
761 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
762
763 // Color resolve attachment, mismatched usage
764 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700765 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03201");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600766 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100767 m_errorMonitor->VerifyFound();
768 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600769 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100770 }
771 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
772
773 // Depth stencil attachment, mismatched usage
774 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700775 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03202");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600776 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100777 m_errorMonitor->VerifyFound();
778 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600779 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100780 }
781 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
782
783 // Color attachment, mismatched usage
784 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700785 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03204");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600786 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100787 m_errorMonitor->VerifyFound();
788 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600789 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100790 }
791 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
792
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600793 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100794}
795
796TEST_F(VkLayerTest, ImagelessFramebufferAttachmentMultiviewImageLayerCountMismatchTests) {
797 TEST_DESCRIPTION("Create an imageless framebuffer against a multiview-enabled render pass with mismatched layer counts");
798
799 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
800 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
801 } else {
802 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
803 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
804 return;
805 }
Mark Lobodzinski09ce9c42020-03-06 10:02:44 -0700806 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100807
808 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MULTIVIEW_EXTENSION_NAME)) {
809 m_device_extension_names.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
810 } else {
811 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix, VK_KHR_MULTIVIEW_EXTENSION_NAME);
812 return;
813 }
814
815 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
816 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
817 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
818 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
819 } else {
820 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
821 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
822 return;
823 }
824
825 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
826 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
827 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
828 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
829 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
830 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
831 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
832
833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
834
835 uint32_t attachmentWidth = 512;
836 uint32_t attachmentHeight = 512;
837 VkFormat colorAndInputAttachmentFormat = VK_FORMAT_R8G8B8A8_UNORM;
838 VkFormat depthStencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
839
840 VkAttachmentDescription attachmentDescriptions[4] = {};
841 // Color attachment
842 attachmentDescriptions[0].format = colorAndInputAttachmentFormat;
843 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
844 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
845 // Color resolve attachment
846 attachmentDescriptions[1].format = colorAndInputAttachmentFormat;
847 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
848 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
849 // Depth stencil attachment
850 attachmentDescriptions[2].format = depthStencilAttachmentFormat;
851 attachmentDescriptions[2].samples = VK_SAMPLE_COUNT_4_BIT;
852 attachmentDescriptions[2].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
853 // Input attachment
854 attachmentDescriptions[3].format = colorAndInputAttachmentFormat;
855 attachmentDescriptions[3].samples = VK_SAMPLE_COUNT_1_BIT;
856 attachmentDescriptions[3].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
857
858 VkAttachmentReference colorAttachmentReference = {};
859 colorAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
860 colorAttachmentReference.attachment = 0;
861 VkAttachmentReference colorResolveAttachmentReference = {};
862 colorResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
863 colorResolveAttachmentReference.attachment = 1;
864 VkAttachmentReference depthStencilAttachmentReference = {};
865 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
866 depthStencilAttachmentReference.attachment = 2;
867 VkAttachmentReference inputAttachmentReference = {};
868 inputAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
869 inputAttachmentReference.attachment = 3;
870 VkSubpassDescription subpassDescription = {};
871 subpassDescription.colorAttachmentCount = 1;
872 subpassDescription.pColorAttachments = &colorAttachmentReference;
873 subpassDescription.pResolveAttachments = &colorResolveAttachmentReference;
874 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
875 subpassDescription.inputAttachmentCount = 1;
876 subpassDescription.pInputAttachments = &inputAttachmentReference;
877
878 uint32_t viewMask = 0x3u;
879 VkRenderPassMultiviewCreateInfo renderPassMultiviewCreateInfo = {};
880 renderPassMultiviewCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO;
881 renderPassMultiviewCreateInfo.subpassCount = 1;
882 renderPassMultiviewCreateInfo.pViewMasks = &viewMask;
883 VkRenderPassCreateInfo renderPassCreateInfo = {};
884 renderPassCreateInfo.pNext = &renderPassMultiviewCreateInfo;
885 renderPassCreateInfo.attachmentCount = 4;
886 renderPassCreateInfo.subpassCount = 1;
887 renderPassCreateInfo.pSubpasses = &subpassDescription;
888 renderPassCreateInfo.pAttachments = attachmentDescriptions;
889 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
890 VkRenderPass renderPass;
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600891 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100892
893 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[4] = {};
894 // Color attachment
895 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
896 framebufferAttachmentImageInfos[0].width = attachmentWidth;
897 framebufferAttachmentImageInfos[0].height = attachmentHeight;
898 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
899 framebufferAttachmentImageInfos[0].layerCount = 2;
900 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
901 framebufferAttachmentImageInfos[0].pViewFormats = &colorAndInputAttachmentFormat;
902 // Color resolve attachment
903 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
904 framebufferAttachmentImageInfos[1].width = attachmentWidth;
905 framebufferAttachmentImageInfos[1].height = attachmentHeight;
906 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
907 framebufferAttachmentImageInfos[1].layerCount = 2;
908 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
909 framebufferAttachmentImageInfos[1].pViewFormats = &colorAndInputAttachmentFormat;
910 // Depth stencil attachment
911 framebufferAttachmentImageInfos[2].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
912 framebufferAttachmentImageInfos[2].width = attachmentWidth;
913 framebufferAttachmentImageInfos[2].height = attachmentHeight;
914 framebufferAttachmentImageInfos[2].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
915 framebufferAttachmentImageInfos[2].layerCount = 2;
916 framebufferAttachmentImageInfos[2].viewFormatCount = 1;
917 framebufferAttachmentImageInfos[2].pViewFormats = &depthStencilAttachmentFormat;
918 // Input attachment
919 framebufferAttachmentImageInfos[3].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
920 framebufferAttachmentImageInfos[3].width = attachmentWidth;
921 framebufferAttachmentImageInfos[3].height = attachmentHeight;
922 framebufferAttachmentImageInfos[3].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
923 framebufferAttachmentImageInfos[3].layerCount = 2;
924 framebufferAttachmentImageInfos[3].viewFormatCount = 1;
925 framebufferAttachmentImageInfos[3].pViewFormats = &colorAndInputAttachmentFormat;
926 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
927 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
928 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 4;
929 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
930 VkFramebufferCreateInfo framebufferCreateInfo = {};
931 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
932 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
933 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
934 framebufferCreateInfo.width = attachmentWidth;
935 framebufferCreateInfo.height = attachmentHeight;
936 framebufferCreateInfo.layers = 1;
937 framebufferCreateInfo.renderPass = renderPass;
938 framebufferCreateInfo.attachmentCount = 4;
939 VkFramebuffer framebuffer = VK_NULL_HANDLE;
940
941 // Color attachment, mismatched layer count
942 framebufferAttachmentImageInfos[0].layerCount = 1;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700943 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600944 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100945 m_errorMonitor->VerifyFound();
946 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600947 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100948 }
949 framebufferAttachmentImageInfos[0].layerCount = 2;
950
951 // Color resolve attachment, mismatched layer count
952 framebufferAttachmentImageInfos[1].layerCount = 1;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700953 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600954 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100955 m_errorMonitor->VerifyFound();
956 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600957 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100958 }
959 framebufferAttachmentImageInfos[1].layerCount = 2;
960
961 // Depth stencil attachment, mismatched layer count
962 framebufferAttachmentImageInfos[2].layerCount = 1;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700963 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600964 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100965 m_errorMonitor->VerifyFound();
966 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600967 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100968 }
969 framebufferAttachmentImageInfos[2].layerCount = 2;
970
971 // Input attachment, mismatched layer count
972 framebufferAttachmentImageInfos[3].layerCount = 1;
Mark Lobodzinski20310782020-02-28 14:25:17 -0700973 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600974 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100975 m_errorMonitor->VerifyFound();
976 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600977 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100978 }
979 framebufferAttachmentImageInfos[3].layerCount = 2;
980
Mark Lobodzinski993b43e2019-09-27 14:54:40 -0600981 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100982}
983
984TEST_F(VkLayerTest, ImagelessFramebufferDepthStencilResolveAttachmentTests) {
985 TEST_DESCRIPTION(
986 "Create an imageless framebuffer against a render pass using depth stencil resolve, with mismatched information");
987
988 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
989 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
990 } else {
991 printf("%s Did not find required instance extension %s; skipped.\n", kSkipPrefix,
992 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
993 return;
994 }
Mark Lobodzinski09ce9c42020-03-06 10:02:44 -0700995 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
Tobias Hectorcf26efe2019-07-23 12:18:52 +0100996
997 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
998 if (!rp2Supported) {
999 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
1000 return;
1001 }
1002
1003 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME)) {
1004 m_device_extension_names.push_back(VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
1005 } else {
1006 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
1007 VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME);
1008 return;
1009 }
1010
1011 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
1012 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
1013 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
1014 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
1015 } else {
1016 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
1017 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
1018 return;
1019 }
1020
1021 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
1022 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
1023 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
1024 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
1025 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
1026 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
1027 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1028
1029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1030
1031 uint32_t attachmentWidth = 512;
1032 uint32_t attachmentHeight = 512;
sfricke-samsung31bdb2d2020-05-24 00:19:06 -07001033 VkFormat attachmentFormat = FindSupportedDepthStencilFormat(gpu());
1034 if (attachmentFormat == VK_FORMAT_UNDEFINED) {
1035 printf("%s Did not find a supported depth stencil format; skipped.\n", kSkipPrefix);
1036 return;
1037 }
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001038
1039 VkAttachmentDescription2KHR attachmentDescriptions[2] = {};
1040 // Depth/stencil attachment
1041 attachmentDescriptions[0].sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR;
1042 attachmentDescriptions[0].format = attachmentFormat;
1043 attachmentDescriptions[0].samples = VK_SAMPLE_COUNT_4_BIT;
1044 attachmentDescriptions[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
1045 // Depth/stencil resolve attachment
1046 attachmentDescriptions[1].sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR;
1047 attachmentDescriptions[1].format = attachmentFormat;
1048 attachmentDescriptions[1].samples = VK_SAMPLE_COUNT_1_BIT;
1049 attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
1050
1051 VkAttachmentReference2KHR depthStencilAttachmentReference = {};
1052 depthStencilAttachmentReference.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR;
1053 depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
1054 depthStencilAttachmentReference.attachment = 0;
1055 VkAttachmentReference2KHR depthStencilResolveAttachmentReference = {};
1056 depthStencilResolveAttachmentReference.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR;
1057 depthStencilResolveAttachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
1058 depthStencilResolveAttachmentReference.attachment = 1;
1059 VkSubpassDescriptionDepthStencilResolveKHR subpassDescriptionDepthStencilResolve = {};
1060 subpassDescriptionDepthStencilResolve.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE_KHR;
1061 subpassDescriptionDepthStencilResolve.pDepthStencilResolveAttachment = &depthStencilResolveAttachmentReference;
1062 subpassDescriptionDepthStencilResolve.depthResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR;
1063 subpassDescriptionDepthStencilResolve.stencilResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT_KHR;
1064 VkSubpassDescription2KHR subpassDescription = {};
1065 subpassDescription.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR;
1066 subpassDescription.pNext = &subpassDescriptionDepthStencilResolve;
1067 subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference;
1068 subpassDescription.viewMask = 0x3u;
1069
1070 VkRenderPassCreateInfo2KHR renderPassCreateInfo = {};
1071 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR;
1072 renderPassCreateInfo.pNext = nullptr;
1073 renderPassCreateInfo.attachmentCount = 2;
1074 renderPassCreateInfo.subpassCount = 1;
1075 renderPassCreateInfo.pSubpasses = &subpassDescription;
1076 renderPassCreateInfo.pAttachments = attachmentDescriptions;
1077 VkRenderPass renderPass;
1078 PFN_vkCreateRenderPass2KHR vkCreateRenderPass2KHR =
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001079 (PFN_vkCreateRenderPass2KHR)vk::GetDeviceProcAddr(m_device->device(), "vkCreateRenderPass2KHR");
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001080 vkCreateRenderPass2KHR(m_device->device(), &renderPassCreateInfo, nullptr, &renderPass);
1081
1082 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfos[2] = {};
1083 // Depth/stencil attachment
1084 framebufferAttachmentImageInfos[0].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
1085 framebufferAttachmentImageInfos[0].width = attachmentWidth;
1086 framebufferAttachmentImageInfos[0].height = attachmentHeight;
1087 framebufferAttachmentImageInfos[0].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1088 framebufferAttachmentImageInfos[0].layerCount = 2;
1089 framebufferAttachmentImageInfos[0].viewFormatCount = 1;
1090 framebufferAttachmentImageInfos[0].pViewFormats = &attachmentFormat;
1091 // Depth/stencil resolve attachment
1092 framebufferAttachmentImageInfos[1].sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
1093 framebufferAttachmentImageInfos[1].width = attachmentWidth;
1094 framebufferAttachmentImageInfos[1].height = attachmentHeight;
1095 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1096 framebufferAttachmentImageInfos[1].layerCount = 2;
1097 framebufferAttachmentImageInfos[1].viewFormatCount = 1;
1098 framebufferAttachmentImageInfos[1].pViewFormats = &attachmentFormat;
1099 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
1100 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
1101 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 2;
1102 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = framebufferAttachmentImageInfos;
1103 VkFramebufferCreateInfo framebufferCreateInfo = {};
1104 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
1105 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
1106 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
1107 framebufferCreateInfo.width = attachmentWidth;
1108 framebufferCreateInfo.height = attachmentHeight;
1109 framebufferCreateInfo.layers = 1;
1110 framebufferCreateInfo.renderPass = renderPass;
1111 framebufferCreateInfo.attachmentCount = 2;
sfricke-samsung7aecc352020-04-23 22:49:47 -07001112 framebufferCreateInfo.pAttachments = nullptr;
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001113 VkFramebuffer framebuffer = VK_NULL_HANDLE;
1114
1115 // Color attachment, mismatched layer count
1116 framebufferAttachmentImageInfos[0].layerCount = 1;
Mark Lobodzinski20310782020-02-28 14:25:17 -07001117 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001118 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001119 m_errorMonitor->VerifyFound();
1120 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001121 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001122 }
1123 framebufferAttachmentImageInfos[0].layerCount = 2;
1124
1125 // Depth resolve attachment, mismatched image usage
1126 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinski20310782020-02-28 14:25:17 -07001127 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-03203");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001128 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001129 m_errorMonitor->VerifyFound();
1130 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001131 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001132 }
1133 framebufferAttachmentImageInfos[1].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1134
1135 // Depth resolve attachment, mismatched layer count
1136 framebufferAttachmentImageInfos[1].layerCount = 1;
Mark Lobodzinski20310782020-02-28 14:25:17 -07001137 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-renderPass-03198");
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001138 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001139 m_errorMonitor->VerifyFound();
1140 if (framebuffer != VK_NULL_HANDLE) {
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001141 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001142 }
1143 framebufferAttachmentImageInfos[1].layerCount = 2;
1144
Mark Lobodzinski993b43e2019-09-27 14:54:40 -06001145 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
Tobias Hectorcf26efe2019-07-23 12:18:52 +01001146}
sfricke-samsungc65e62b2020-11-01 08:48:24 -08001147
Tobias Hector04f2ab22020-12-01 10:59:33 +00001148TEST_F(VkLayerTest, InvalidFragmentShadingRateImagelessFramebufferUsage) {
1149 TEST_DESCRIPTION("Specify a fragment shading rate attachment without the correct usage");
1150
1151 // Enable KHR_fragment_shading_rate and all of its required extensions
1152 bool fsr_extensions = InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1153 if (fsr_extensions) {
1154 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1155 }
1156 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
1157
1158 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
1159 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE2_EXTENSION_NAME);
1160 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MULTIVIEW_EXTENSION_NAME);
1161 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
1162 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1163 if (fsr_extensions) {
1164 m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
1165 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
1166 m_device_extension_names.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
1167 m_device_extension_names.push_back(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
1168 m_device_extension_names.push_back(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1169 } else {
1170 printf("%s requires VK_KHR_fragment_shading_rate.\n", kSkipPrefix);
1171 return;
1172 }
1173
1174 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
1175 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
1176 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
1177 } else {
1178 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
1179 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
1180 return;
1181 }
1182
1183 PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR =
1184 (PFN_vkGetPhysicalDeviceProperties2KHR)vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceProperties2KHR");
1185 ASSERT_TRUE(vkGetPhysicalDeviceProperties2KHR != nullptr);
1186 VkPhysicalDeviceFragmentShadingRatePropertiesKHR fsr_properties =
Mark Lobodzinski07d0a612020-12-30 15:42:31 -07001187 LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>();
1188 VkPhysicalDeviceProperties2KHR properties2 = LvlInitStruct<VkPhysicalDeviceProperties2KHR>(&fsr_properties);
Tobias Hector04f2ab22020-12-01 10:59:33 +00001189 vkGetPhysicalDeviceProperties2KHR(gpu(), &properties2);
1190
1191 PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR =
1192 (PFN_vkGetPhysicalDeviceFeatures2KHR)vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceFeatures2KHR");
1193 ASSERT_TRUE(vkGetPhysicalDeviceFeatures2KHR != nullptr);
Mark Lobodzinski07d0a612020-12-30 15:42:31 -07001194 VkPhysicalDeviceImagelessFramebufferFeatures if_features = LvlInitStruct<VkPhysicalDeviceImagelessFramebufferFeatures>();
Tobias Hector04f2ab22020-12-01 10:59:33 +00001195 VkPhysicalDeviceFragmentShadingRateFeaturesKHR fsr_features =
Mark Lobodzinski07d0a612020-12-30 15:42:31 -07001196 LvlInitStruct<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(&if_features);
1197 VkPhysicalDeviceFeatures2KHR features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>(&fsr_features);
Tobias Hector04f2ab22020-12-01 10:59:33 +00001198 vkGetPhysicalDeviceFeatures2KHR(gpu(), &features2);
1199
1200 if (fsr_features.attachmentFragmentShadingRate != VK_TRUE) {
1201 printf("%s requires attachmentFragmentShadingRate feature.\n", kSkipPrefix);
1202 return;
1203 }
1204
1205 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1206
1207 VkAttachmentReference2 attach = {};
1208 attach.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2;
1209 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
1210 attach.attachment = 0;
1211
1212 VkFragmentShadingRateAttachmentInfoKHR fsr_attachment = {};
1213 fsr_attachment.sType = VK_STRUCTURE_TYPE_FRAGMENT_SHADING_RATE_ATTACHMENT_INFO_KHR;
1214 fsr_attachment.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize;
1215 fsr_attachment.pFragmentShadingRateAttachment = &attach;
1216
1217 // Create a renderPass with a single fsr attachment
1218 VkSubpassDescription2 subpass = {};
1219 subpass.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2;
1220 subpass.pNext = &fsr_attachment;
1221
1222 VkAttachmentDescription2 attach_desc = {};
1223 attach_desc.format = VK_FORMAT_R8_UINT;
1224 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
1225 attach_desc.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
1226 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
1227
1228 VkRenderPassCreateInfo2 rpci = {};
1229 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2;
1230 rpci.subpassCount = 1;
1231 rpci.pSubpasses = &subpass;
1232 rpci.attachmentCount = 1;
1233 rpci.pAttachments = &attach_desc;
1234
1235 VkRenderPass rp;
1236
1237 PFN_vkCreateRenderPass2KHR vkCreateRenderPass2KHR =
1238 (PFN_vkCreateRenderPass2KHR)vk::GetDeviceProcAddr(m_device->device(), "vkCreateRenderPass2KHR");
1239 VkResult err = vkCreateRenderPass2KHR(m_device->device(), &rpci, NULL, &rp);
1240 ASSERT_VK_SUCCESS(err);
1241
1242 VkFormat viewFormat = VK_FORMAT_R8_UINT;
1243 VkFramebufferAttachmentImageInfo fbai_info = {};
1244 fbai_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO;
1245 fbai_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1246 fbai_info.width = 1;
1247 fbai_info.height = 1;
1248 fbai_info.layerCount = 1;
1249 fbai_info.viewFormatCount = 1;
1250 fbai_info.pViewFormats = &viewFormat;
1251
1252 VkFramebufferAttachmentsCreateInfo fba_info = {};
1253 fba_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO;
1254 fba_info.attachmentImageInfoCount = 1;
1255 fba_info.pAttachmentImageInfos = &fbai_info;
1256
1257 VkFramebufferCreateInfo fb_info = {};
1258 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
1259 fb_info.pNext = &fba_info;
1260 fb_info.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT;
1261 fb_info.renderPass = rp;
1262 fb_info.attachmentCount = 1;
1263 fb_info.pAttachments = NULL;
1264 fb_info.width = fsr_properties.minFragmentShadingRateAttachmentTexelSize.width;
1265 fb_info.height = fsr_properties.minFragmentShadingRateAttachmentTexelSize.height;
1266 fb_info.layers = 1;
1267
1268 VkFramebuffer fb;
1269 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-04549");
1270 err = vk::CreateFramebuffer(device(), &fb_info, NULL, &fb);
1271 m_errorMonitor->VerifyFound();
1272 if (err == VK_SUCCESS) {
1273 vk::DestroyFramebuffer(m_device->device(), fb, NULL);
1274 }
1275 vk::DestroyRenderPass(m_device->device(), rp, NULL);
1276}
1277
1278TEST_F(VkLayerTest, InvalidFragmentShadingRateImagelessFramebufferDimensions) {
1279 TEST_DESCRIPTION("Specify a fragment shading rate attachment without the correct usage");
1280
1281 // Enable KHR_fragment_shading_rate and all of its required extensions
1282 bool fsr_extensions = InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1283 if (fsr_extensions) {
1284 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1285 }
1286 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
1287
1288 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
1289 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE2_EXTENSION_NAME);
1290 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MULTIVIEW_EXTENSION_NAME);
1291 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
1292 fsr_extensions = fsr_extensions && DeviceExtensionSupported(gpu(), nullptr, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1293 if (fsr_extensions) {
1294 m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
1295 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
1296 m_device_extension_names.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
1297 m_device_extension_names.push_back(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
1298 m_device_extension_names.push_back(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1299 } else {
1300 printf("%s requires VK_KHR_fragment_shading_rate.\n", kSkipPrefix);
1301 return;
1302 }
1303
1304 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
1305 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
1306 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
1307 } else {
1308 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
1309 VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
1310 return;
1311 }
1312
1313 PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR =
1314 (PFN_vkGetPhysicalDeviceProperties2KHR)vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceProperties2KHR");
1315 ASSERT_TRUE(vkGetPhysicalDeviceProperties2KHR != nullptr);
1316 VkPhysicalDeviceFragmentShadingRatePropertiesKHR fsr_properties =
Mark Lobodzinski07d0a612020-12-30 15:42:31 -07001317 LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>();
1318 VkPhysicalDeviceProperties2KHR properties2 = LvlInitStruct<VkPhysicalDeviceProperties2KHR>(&fsr_properties);
Tobias Hector04f2ab22020-12-01 10:59:33 +00001319 vkGetPhysicalDeviceProperties2KHR(gpu(), &properties2);
1320
1321 PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR =
1322 (PFN_vkGetPhysicalDeviceFeatures2KHR)vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceFeatures2KHR");
1323 ASSERT_TRUE(vkGetPhysicalDeviceFeatures2KHR != nullptr);
Mark Lobodzinski07d0a612020-12-30 15:42:31 -07001324 VkPhysicalDeviceImagelessFramebufferFeatures if_features = LvlInitStruct<VkPhysicalDeviceImagelessFramebufferFeatures>();
Tobias Hector04f2ab22020-12-01 10:59:33 +00001325 VkPhysicalDeviceFragmentShadingRateFeaturesKHR fsr_features =
Mark Lobodzinski07d0a612020-12-30 15:42:31 -07001326 LvlInitStruct<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(&if_features);
1327 VkPhysicalDeviceFeatures2KHR features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>(&fsr_features);
Tobias Hector04f2ab22020-12-01 10:59:33 +00001328 vkGetPhysicalDeviceFeatures2KHR(gpu(), &features2);
1329
1330 if (fsr_features.attachmentFragmentShadingRate != VK_TRUE) {
1331 printf("%s requires attachmentFragmentShadingRate feature.\n", kSkipPrefix);
1332 return;
1333 }
1334
1335 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1336
1337 VkAttachmentReference2 attach = {};
1338 attach.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2;
1339 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
1340 attach.attachment = 0;
1341
1342 VkFragmentShadingRateAttachmentInfoKHR fsr_attachment = {};
1343 fsr_attachment.sType = VK_STRUCTURE_TYPE_FRAGMENT_SHADING_RATE_ATTACHMENT_INFO_KHR;
1344 fsr_attachment.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize;
1345 fsr_attachment.pFragmentShadingRateAttachment = &attach;
1346
1347 // Create a renderPass with a single fsr attachment
1348 VkSubpassDescription2 subpass = {};
1349 subpass.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2;
1350 subpass.pNext = &fsr_attachment;
1351
1352 VkAttachmentDescription2 attach_desc = {};
1353 attach_desc.format = VK_FORMAT_R8_UINT;
1354 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
1355 attach_desc.initialLayout = VK_IMAGE_LAYOUT_GENERAL;
1356 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
1357
1358 VkRenderPassCreateInfo2 rpci = {};
1359 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2;
1360 rpci.subpassCount = 1;
1361 rpci.pSubpasses = &subpass;
1362 rpci.attachmentCount = 1;
1363 rpci.pAttachments = &attach_desc;
1364
1365 VkRenderPass rp;
1366
1367 PFN_vkCreateRenderPass2KHR vkCreateRenderPass2KHR =
1368 (PFN_vkCreateRenderPass2KHR)vk::GetDeviceProcAddr(m_device->device(), "vkCreateRenderPass2KHR");
1369 VkResult err = vkCreateRenderPass2KHR(m_device->device(), &rpci, NULL, &rp);
1370 ASSERT_VK_SUCCESS(err);
1371
1372 VkFormat viewFormat = VK_FORMAT_R8_UINT;
1373 VkFramebufferAttachmentImageInfo fbai_info = {};
1374 fbai_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO;
1375 fbai_info.usage = VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR;
1376 fbai_info.width = 1;
1377 fbai_info.height = 1;
1378 fbai_info.layerCount = 1;
1379 fbai_info.viewFormatCount = 1;
1380 fbai_info.pViewFormats = &viewFormat;
1381
1382 VkFramebufferAttachmentsCreateInfo fba_info = {};
1383 fba_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO;
1384 fba_info.attachmentImageInfoCount = 1;
1385 fba_info.pAttachmentImageInfos = &fbai_info;
1386
1387 VkFramebufferCreateInfo fb_info = {};
1388 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
1389 fb_info.pNext = &fba_info;
1390 fb_info.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT;
1391 fb_info.renderPass = rp;
1392 fb_info.attachmentCount = 1;
1393 fb_info.pAttachments = NULL;
1394 fb_info.width = fsr_properties.minFragmentShadingRateAttachmentTexelSize.width;
1395 fb_info.height = fsr_properties.minFragmentShadingRateAttachmentTexelSize.height;
1396 fb_info.layers = 1;
1397
1398 VkFramebuffer fb;
1399
1400 fb_info.width = fsr_properties.minFragmentShadingRateAttachmentTexelSize.width * 2;
1401 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-04543");
1402 err = vk::CreateFramebuffer(device(), &fb_info, NULL, &fb);
1403 m_errorMonitor->VerifyFound();
1404 if (err == VK_SUCCESS) {
1405 vk::DestroyFramebuffer(m_device->device(), fb, NULL);
1406 }
1407 fb_info.width = fsr_properties.minFragmentShadingRateAttachmentTexelSize.width;
1408
1409 fb_info.height = fsr_properties.minFragmentShadingRateAttachmentTexelSize.height * 2;
1410 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-04544");
1411 err = vk::CreateFramebuffer(device(), &fb_info, NULL, &fb);
1412 m_errorMonitor->VerifyFound();
1413 if (err == VK_SUCCESS) {
1414 vk::DestroyFramebuffer(m_device->device(), fb, NULL);
1415 }
1416 fb_info.height = fsr_properties.minFragmentShadingRateAttachmentTexelSize.height;
1417
1418 fbai_info.layerCount = 2;
1419 fb_info.layers = 3;
1420 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-04545");
1421 err = vk::CreateFramebuffer(device(), &fb_info, NULL, &fb);
1422 m_errorMonitor->VerifyFound();
1423 if (err == VK_SUCCESS) {
1424 vk::DestroyFramebuffer(m_device->device(), fb, NULL);
1425 }
1426 fb_info.layers = 1;
1427 fbai_info.layerCount = 1;
1428
1429 vk::DestroyRenderPass(m_device->device(), rp, NULL);
1430
1431 if (fsr_properties.layeredShadingRateAttachments == VK_TRUE) {
1432 subpass.viewMask = 0x4;
1433 err = vkCreateRenderPass2KHR(m_device->device(), &rpci, NULL, &rp);
1434 ASSERT_VK_SUCCESS(err);
1435 subpass.viewMask = 0;
1436
1437 fbai_info.layerCount = 2;
1438 fb_info.renderPass = rp;
1439 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, kVUIDUndefined);
1440 err = vk::CreateFramebuffer(device(), &fb_info, NULL, &fb);
1441 m_errorMonitor->VerifyFound();
1442 if (err == VK_SUCCESS) {
1443 vk::DestroyFramebuffer(m_device->device(), fb, NULL);
1444 }
1445 fbai_info.layerCount = 1;
1446
1447 vk::DestroyRenderPass(m_device->device(), rp, NULL);
1448 }
1449}
1450
sfricke-samsungc65e62b2020-11-01 08:48:24 -08001451TEST_F(VkLayerTest, ImagelessFramebufferRenderPassBeginImageView3D) {
1452 TEST_DESCRIPTION("Misuse of VK_IMAGE_VIEW_TYPE_3D.");
1453
1454 if (InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
1455 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1456 } else {
1457 printf("%s Did not find required device extension %s; skipped.\n", kSkipPrefix,
1458 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1459 return;
1460 }
1461
1462 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
1463 bool rp2Supported = CheckCreateRenderPass2Support(this, m_device_extension_names);
1464
1465 if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
1466 m_device_extension_names.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME);
1467 m_device_extension_names.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
1468 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
1469 } else {
1470 printf("%s test requires VK_KHR_imageless_framebuffer, not available. Skipping.\n", kSkipPrefix);
1471 return;
1472 }
1473
1474 VkPhysicalDeviceImagelessFramebufferFeaturesKHR physicalDeviceImagelessFramebufferFeatures = {};
1475 physicalDeviceImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES_KHR;
1476 physicalDeviceImagelessFramebufferFeatures.imagelessFramebuffer = VK_TRUE;
1477 VkPhysicalDeviceFeatures2 physicalDeviceFeatures2 = {};
1478 physicalDeviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
1479 physicalDeviceFeatures2.pNext = &physicalDeviceImagelessFramebufferFeatures;
1480
1481 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &physicalDeviceFeatures2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1482 uint32_t attachmentWidth = 512;
1483 uint32_t attachmentHeight = 512;
1484 VkFormat attachmentFormats[1] = {VK_FORMAT_R8G8B8A8_UNORM};
1485 VkFormat framebufferAttachmentFormats[1] = {VK_FORMAT_R8G8B8A8_UNORM};
1486
1487 // Create a renderPass with a single attachment
1488 VkAttachmentDescription attachmentDescription = {};
1489 attachmentDescription.format = attachmentFormats[0];
1490 attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
1491 attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
1492 VkAttachmentReference attachmentReference = {};
1493 attachmentReference.layout = VK_IMAGE_LAYOUT_GENERAL;
1494 VkSubpassDescription subpassDescription = {};
1495 subpassDescription.colorAttachmentCount = 1;
1496 subpassDescription.pColorAttachments = &attachmentReference;
1497 VkRenderPassCreateInfo renderPassCreateInfo = {};
1498 renderPassCreateInfo.subpassCount = 1;
1499 renderPassCreateInfo.pSubpasses = &subpassDescription;
1500 renderPassCreateInfo.attachmentCount = 1;
1501 renderPassCreateInfo.pAttachments = &attachmentDescription;
1502 renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
1503 VkRenderPass renderPass;
1504 vk::CreateRenderPass(m_device->device(), &renderPassCreateInfo, NULL, &renderPass);
1505
1506 // Create Attachments
1507 VkImageCreateInfo imageCreateInfo = {};
1508 imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1509 imageCreateInfo.pNext = nullptr;
1510 imageCreateInfo.flags = 0;
1511 imageCreateInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1512 imageCreateInfo.extent.width = attachmentWidth;
1513 imageCreateInfo.extent.height = attachmentHeight;
1514 imageCreateInfo.extent.depth = 1;
1515 imageCreateInfo.arrayLayers = 1;
1516 imageCreateInfo.mipLevels = 1;
1517 imageCreateInfo.imageType = VK_IMAGE_TYPE_3D;
1518 imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
1519 imageCreateInfo.format = attachmentFormats[0];
1520
1521 VkImageObj image3D(m_device);
1522 image3D.init(&imageCreateInfo);
1523
1524 VkImageViewCreateInfo imageViewCreateInfo = {};
1525 imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1526 imageViewCreateInfo.image = image3D.handle();
1527 imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_3D;
1528 imageViewCreateInfo.format = attachmentFormats[0];
1529 imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1530 imageViewCreateInfo.subresourceRange.baseMipLevel = 0;
1531 imageViewCreateInfo.subresourceRange.levelCount = 1;
1532 imageViewCreateInfo.subresourceRange.baseArrayLayer = 0;
1533 imageViewCreateInfo.subresourceRange.layerCount = 1;
1534 VkImageView imageView3D;
1535 vk::CreateImageView(m_device->device(), &imageViewCreateInfo, NULL, &imageView3D);
1536
1537 VkFramebufferAttachmentImageInfoKHR framebufferAttachmentImageInfo = {};
1538 framebufferAttachmentImageInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENT_IMAGE_INFO_KHR;
1539 framebufferAttachmentImageInfo.flags = 0;
1540 framebufferAttachmentImageInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1541 framebufferAttachmentImageInfo.width = attachmentWidth;
1542 framebufferAttachmentImageInfo.height = attachmentHeight;
1543 framebufferAttachmentImageInfo.layerCount = 1;
1544 framebufferAttachmentImageInfo.viewFormatCount = 1;
1545 framebufferAttachmentImageInfo.pViewFormats = framebufferAttachmentFormats;
1546 VkFramebufferAttachmentsCreateInfoKHR framebufferAttachmentsCreateInfo = {};
1547 framebufferAttachmentsCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_ATTACHMENTS_CREATE_INFO_KHR;
1548 framebufferAttachmentsCreateInfo.attachmentImageInfoCount = 1;
1549 framebufferAttachmentsCreateInfo.pAttachmentImageInfos = &framebufferAttachmentImageInfo;
1550
1551 VkFramebuffer framebuffer;
1552 VkFramebufferCreateInfo framebufferCreateInfo = {};
1553 framebufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
1554 framebufferCreateInfo.width = attachmentWidth;
1555 framebufferCreateInfo.height = attachmentHeight;
1556 framebufferCreateInfo.layers = 1;
1557 framebufferCreateInfo.attachmentCount = 1;
1558 framebufferCreateInfo.renderPass = renderPass;
1559
1560 // Try to use 3D Image View without imageless flag
1561 framebufferCreateInfo.pNext = nullptr;
1562 framebufferCreateInfo.flags = 0;
1563 framebufferCreateInfo.pAttachments = &imageView3D;
1564 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-flags-04113");
1565 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
1566 m_errorMonitor->VerifyFound();
1567
1568 framebufferCreateInfo.pNext = &framebufferAttachmentsCreateInfo;
1569 framebufferCreateInfo.flags = VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR;
1570 framebufferCreateInfo.pAttachments = nullptr;
1571 m_errorMonitor->ExpectSuccess();
1572 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
1573 m_errorMonitor->VerifyNotFound();
1574
1575 VkRenderPassAttachmentBeginInfoKHR renderPassAttachmentBeginInfo = {};
1576 renderPassAttachmentBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO_KHR;
1577 renderPassAttachmentBeginInfo.pNext = nullptr;
1578 renderPassAttachmentBeginInfo.attachmentCount = 1;
1579 renderPassAttachmentBeginInfo.pAttachments = &imageView3D;
1580 VkRenderPassBeginInfo renderPassBeginInfo = {};
1581 renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
1582 renderPassBeginInfo.pNext = &renderPassAttachmentBeginInfo;
1583 renderPassBeginInfo.renderPass = renderPass;
1584 renderPassBeginInfo.renderArea.extent.width = attachmentWidth;
1585 renderPassBeginInfo.renderArea.extent.height = attachmentHeight;
1586 renderPassBeginInfo.framebuffer = framebuffer;
1587
1588 // Try to use 3D Image View with imageless flag
1589 TestRenderPassBegin(m_errorMonitor, m_device->device(), m_commandBuffer->handle(), &renderPassBeginInfo, rp2Supported,
1590 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-04114",
1591 "VUID-VkRenderPassAttachmentBeginInfo-pAttachments-04114");
1592
1593 vk::DestroyRenderPass(m_device->device(), renderPass, nullptr);
1594 vk::DestroyFramebuffer(m_device->device(), framebuffer, nullptr);
1595 vk::DestroyImageView(m_device->device(), imageView3D, nullptr);
1596}
ziga-lunarg91a90642021-07-29 13:25:07 +02001597
1598TEST_F(VkLayerTest, FramebufferAttachmentImageInfoPNext) {
1599 TEST_DESCRIPTION("Begin render pass with missing framebuffer attachment");
1600
1601 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
1602 if (!DeviceExtensionSupported(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME)) {
1603 printf("%s test requires VK_KHR_imageless_framebuffer, not available. Skipping.\n", kSkipPrefix);
1604 return;
1605 }
1606 m_device_extension_names.push_back(VK_KHR_IMAGELESS_FRAMEBUFFER_EXTENSION_NAME);
1607 ASSERT_NO_FATAL_FAILURE(InitState());
1608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1609
1610 VkFormat attachment_format = VK_FORMAT_R8G8B8A8_UNORM;
1611 VkFramebufferAttachmentImageInfo fb_fdm = LvlInitStruct<VkFramebufferAttachmentImageInfo>();
1612 fb_fdm.pNext = &fb_fdm;
1613 fb_fdm.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1614 fb_fdm.width = 64;
1615 fb_fdm.height = 64;
1616 fb_fdm.layerCount = 1;
1617 fb_fdm.viewFormatCount = 1;
1618 fb_fdm.pViewFormats = &attachment_format;
1619
1620 VkFramebufferAttachmentsCreateInfo fb_aci_fdm = LvlInitStruct<VkFramebufferAttachmentsCreateInfo>();
1621 fb_aci_fdm.attachmentImageInfoCount = 1;
1622 fb_aci_fdm.pAttachmentImageInfos = &fb_fdm;
1623
1624 VkFramebufferCreateInfo framebufferCreateInfo = LvlInitStruct<VkFramebufferCreateInfo>(&fb_aci_fdm);
1625 framebufferCreateInfo.width = 64;
1626 framebufferCreateInfo.height = 64;
1627 framebufferCreateInfo.layers = 1;
1628 framebufferCreateInfo.renderPass = m_renderPass;
1629 framebufferCreateInfo.attachmentCount = static_cast<uint32_t>(m_framebuffer_attachments.size());
1630 framebufferCreateInfo.pAttachments = m_framebuffer_attachments.data();
1631
1632 VkFramebuffer framebuffer;
1633 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferAttachmentImageInfo-pNext-pNext");
1634 vk::CreateFramebuffer(m_device->device(), &framebufferCreateInfo, nullptr, &framebuffer);
1635 m_errorMonitor->VerifyFound();
1636}
ziga-lunarg69bbdef2021-08-01 17:52:16 +02001637
1638TEST_F(VkLayerTest, DescriptorUpdateTemplateEntryWithInlineUniformBlock) {
1639 TEST_DESCRIPTION("Test VkDescriptorUpdateTemplateEntry with descriptor type VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT");
1640
1641 // GPDDP2 needed for push descriptors support below
1642 bool gpdp2_support = InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
1643 VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION);
1644 if (gpdp2_support) {
1645 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1646 }
Nathaniel Cesariob3f17dc2021-08-17 12:52:22 -06001647 ASSERT_NO_FATAL_FAILURE(InitFramework());
ziga-lunarg69bbdef2021-08-01 17:52:16 +02001648 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME)) {
1649 printf("%s Descriptor Update Template Extensions not supported, skipped.\n", kSkipPrefix);
1650 return;
Nathaniel Cesariob3f17dc2021-08-17 12:52:22 -06001651 } else {
1652 m_device_extension_names.push_back(VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME);
1653 }
1654 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME)) {
1655 printf("%s %s not supported, skipped.\n", kSkipPrefix, VK_KHR_MAINTENANCE1_EXTENSION_NAME);
1656 return;
1657 } else {
1658 m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
ziga-lunarg69bbdef2021-08-01 17:52:16 +02001659 }
1660 if (!DeviceExtensionSupported(gpu(), nullptr, VK_EXT_INLINE_UNIFORM_BLOCK_EXTENSION_NAME)) {
1661 printf("%s %s not supported, skipped.\n", kSkipPrefix, VK_EXT_INLINE_UNIFORM_BLOCK_EXTENSION_NAME);
1662 return;
Nathaniel Cesariob3f17dc2021-08-17 12:52:22 -06001663 } else {
1664 m_device_extension_names.push_back(VK_EXT_INLINE_UNIFORM_BLOCK_EXTENSION_NAME);
ziga-lunarg69bbdef2021-08-01 17:52:16 +02001665 }
ziga-lunarg69bbdef2021-08-01 17:52:16 +02001666
1667 // Note: Includes workaround for some implementations which incorrectly return 0 maxPushDescriptors
1668 bool push_descriptor_support = gpdp2_support &&
1669 DeviceExtensionSupported(gpu(), nullptr, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME) &&
1670 (GetPushDescriptorProperties(instance(), gpu()).maxPushDescriptors > 0);
1671 if (push_descriptor_support) {
1672 m_device_extension_names.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
1673 } else {
1674 printf("%s Push Descriptor Extension not supported, push descriptor cases skipped.\n", kSkipPrefix);
1675 }
1676
1677 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1678
1679 std::vector<VkDescriptorSetLayoutBinding> ds_bindings = {
1680 {0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_ALL, nullptr}};
1681 OneOffDescriptorSet descriptor_set(m_device, ds_bindings);
1682
1683 // Create a buffer to be used for invalid updates
1684 VkBufferCreateInfo buff_ci = LvlInitStruct<VkBufferCreateInfo>();
1685 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1686 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
1687 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1688 VkBufferObj buffer;
1689 buffer.init(*m_device, buff_ci);
1690
1691 // Relying on the "return nullptr for non-enabled extensions
1692 auto vkCreateDescriptorUpdateTemplateKHR =
1693 (PFN_vkCreateDescriptorUpdateTemplateKHR)vk::GetDeviceProcAddr(m_device->device(), "vkCreateDescriptorUpdateTemplateKHR");
1694 auto vkDestroyDescriptorUpdateTemplateKHR =
1695 (PFN_vkDestroyDescriptorUpdateTemplateKHR)vk::GetDeviceProcAddr(m_device->device(), "vkDestroyDescriptorUpdateTemplateKHR");
1696 auto vkUpdateDescriptorSetWithTemplateKHR =
1697 (PFN_vkUpdateDescriptorSetWithTemplateKHR)vk::GetDeviceProcAddr(m_device->device(), "vkUpdateDescriptorSetWithTemplateKHR");
1698
1699 ASSERT_NE(vkCreateDescriptorUpdateTemplateKHR, nullptr);
1700 ASSERT_NE(vkDestroyDescriptorUpdateTemplateKHR, nullptr);
1701 ASSERT_NE(vkUpdateDescriptorSetWithTemplateKHR, nullptr);
1702
1703 struct SimpleTemplateData {
1704 VkDescriptorBufferInfo buff_info;
1705 };
1706
1707 VkDescriptorUpdateTemplateEntry update_template_entry = {};
1708 update_template_entry.dstBinding = 0;
1709 update_template_entry.dstArrayElement = 2;
1710 update_template_entry.descriptorCount = 1;
1711 update_template_entry.descriptorType = VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT;
1712 update_template_entry.offset = offsetof(SimpleTemplateData, buff_info);
1713 update_template_entry.stride = sizeof(SimpleTemplateData);
1714
1715 auto update_template_ci = LvlInitStruct<VkDescriptorUpdateTemplateCreateInfoKHR>();
1716 update_template_ci.descriptorUpdateEntryCount = 1;
1717 update_template_ci.pDescriptorUpdateEntries = &update_template_entry;
1718 update_template_ci.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET;
1719 update_template_ci.descriptorSetLayout = descriptor_set.layout_.handle();
1720
1721 VkDescriptorUpdateTemplate update_template = VK_NULL_HANDLE;
1722 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDescriptorUpdateTemplateEntry-descriptor-02226");
1723 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkDescriptorUpdateTemplateEntry-descriptor-02227");
1724 vkCreateDescriptorUpdateTemplateKHR(m_device->device(), &update_template_ci, nullptr, &update_template);
1725 m_errorMonitor->VerifyFound();
1726}
ziga-lunargf1ea8fb2021-08-05 22:54:52 +02001727
1728TEST_F(VkLayerTest, RenderPassCreateFragmentDensityMapReferenceToInvalidAttachment) {
1729 TEST_DESCRIPTION(
1730 "Test creating a framebuffer with fragment density map reference to an attachment with layer count different from 1");
1731
1732 if (!InstanceExtensionSupported(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) {
1733 return;
1734 }
1735 m_instance_extension_names.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
1736
1737 ASSERT_NO_FATAL_FAILURE(InitFramework());
1738 if (!DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME)) {
1739 printf("%s %s extension not supported skipped.\n", kSkipPrefix, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1740 return;
1741 }
1742 m_device_extension_names.push_back(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1743 VkPhysicalDeviceFragmentDensityMapFeaturesEXT fdm_features = LvlInitStruct<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>();
1744 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&fdm_features);
1745 fdm_features.fragmentDensityMap = true;
1746
1747 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, 0));
1748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1749
1750 VkAttachmentReference ref;
1751 ref.attachment = 0;
1752 ref.layout = VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT;
1753 VkRenderPassFragmentDensityMapCreateInfoEXT rpfdmi = LvlInitStruct<VkRenderPassFragmentDensityMapCreateInfoEXT>();
1754 rpfdmi.fragmentDensityMapAttachment = ref;
1755
1756 VkAttachmentDescription attach = {};
1757 attach.format = VK_FORMAT_R8G8_UNORM;
1758 attach.samples = VK_SAMPLE_COUNT_1_BIT;
1759 attach.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
1760 attach.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
1761 attach.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1762 attach.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
1763 attach.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
1764 attach.finalLayout = VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT;
1765
1766 VkSubpassDescription subpass = {};
1767 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
1768 subpass.inputAttachmentCount = 1;
1769 subpass.pInputAttachments = &ref;
1770
1771 VkRenderPassCreateInfo rpci = LvlInitStruct<VkRenderPassCreateInfo>(&rpfdmi);
1772 rpci.attachmentCount = 1;
1773 rpci.pAttachments = &attach;
1774 rpci.subpassCount = 1;
1775 rpci.pSubpasses = &subpass;
1776
1777 VkRenderPass renderPass;
1778 vk::CreateRenderPass(device(), &rpci, nullptr, &renderPass);
1779
1780 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1781 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1782 image_create_info.format = VK_FORMAT_R8G8_UNORM;
1783 image_create_info.extent.width = 32;
1784 image_create_info.extent.height = 32;
1785 image_create_info.extent.depth = 1;
1786 image_create_info.mipLevels = 1;
1787 image_create_info.arrayLayers = 4;
1788 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1789 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1790 image_create_info.usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
1791 image_create_info.flags = 0;
1792
1793 VkImageObj image(m_device);
1794 image.Init(image_create_info);
1795 VkImageView imageView = image.targetView(VK_FORMAT_R8G8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 4);
1796
1797 VkFramebufferCreateInfo fb_info = LvlInitStruct<VkFramebufferCreateInfo>();
1798 fb_info.renderPass = renderPass;
1799 fb_info.attachmentCount = 1;
1800 fb_info.pAttachments = &imageView;
1801 fb_info.width = 32;
1802 fb_info.height = 32;
1803 fb_info.layers = 1;
1804
1805 VkFramebuffer framebuffer;
1806 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkFramebufferCreateInfo-pAttachments-02744");
1807 vk::CreateFramebuffer(device(), &fb_info, nullptr, &framebuffer);
1808 m_errorMonitor->VerifyFound();
1809}