blob: cb6094b8b0963ba8729c48d2c2dc566e528a0299 [file] [log] [blame]
Aaron Haganaca50442021-12-07 22:26:29 -05001/*
stusmith15f24a82021-12-24 15:21:19 +00002 * Copyright (c) 2015-2022 The Khronos Group Inc.
3 * Copyright (c) 2015-2022 Valve Corporation
4 * Copyright (c) 2015-2022 LunarG, Inc.
5 * Copyright (c) 2015-2022 Google, Inc.
6 * Modifications Copyright (C) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.
Tony-LunarG4c253372022-01-18 13:51:07 -07007 * Modifications Copyright (C) 2021-2022 ARM, Inc. All rights reserved.
Aaron Haganaca50442021-12-07 22:26:29 -05008 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 */
16
17#include "cast_utils.h"
18#include "layer_validation_tests.h"
19
Aaron Haganb54466d2022-02-18 15:02:54 -050020TEST_F(VkLayerTest, DynamicRenderingCommandBufferInheritanceRenderingInfo) {
Aaron Haganaca50442021-12-07 22:26:29 -050021 TEST_DESCRIPTION("VkCommandBufferInheritanceRenderingInfoKHR Dynamic Rendering Tests.");
22
23 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
24 if (version < VK_API_VERSION_1_2) {
25 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
26 return;
27 }
sfricke-samsungae54c1e2022-01-21 05:35:21 -080028
Aaron Haganaca50442021-12-07 22:26:29 -050029 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
Nathaniel Cesarioa06135e2022-03-02 21:22:30 -070030 ASSERT_NO_FATAL_FAILURE(InitFramework());
Aaron Haganaca50442021-12-07 22:26:29 -050031
Nathaniel Cesarioa06135e2022-03-02 21:22:30 -070032 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +090033 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
Aaron Haganb54466d2022-02-18 15:02:54 -050034 }
35
Aaron Haganaca50442021-12-07 22:26:29 -050036 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
sjfrickebdd58dd2022-05-20 14:22:50 +090037 GTEST_SKIP() << "At least Vulkan version 1.2 is required";
Aaron Haganaca50442021-12-07 22:26:29 -050038 }
sfricke-samsungae54c1e2022-01-21 05:35:21 -080039
Nathaniel Cesarioa06135e2022-03-02 21:22:30 -070040 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
41 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
42 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
43 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
44 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
Aaron Haganaca50442021-12-07 22:26:29 -050045 return;
46 }
47
ziga-lunargf54cb2a2022-03-11 02:54:27 +010048 features2.features.variableMultisampleRate = VK_FALSE;
49
Nathaniel Cesarioa06135e2022-03-02 21:22:30 -070050 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
51
Aaron Haganaca50442021-12-07 22:26:29 -050052 VkPhysicalDeviceMultiviewProperties multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
53 VkPhysicalDeviceProperties2 pd_props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&multiview_props);
54 vk::GetPhysicalDeviceProperties2(gpu(), &pd_props2);
55
56 if (multiview_props.maxMultiviewViewCount == 32) {
57 printf("%s VUID is not testable as maxMultiviewViewCount is 32, skipping test\n", kSkipPrefix);
58 return;
59 }
60
61 VkFormat color_format = VK_FORMAT_D32_SFLOAT;
62
63 auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
64 cmd_buffer_inheritance_rendering_info.colorAttachmentCount = 1;
65 cmd_buffer_inheritance_rendering_info.pColorAttachmentFormats = &color_format;
66 cmd_buffer_inheritance_rendering_info.depthAttachmentFormat = VK_FORMAT_R8G8B8_UNORM;
67 cmd_buffer_inheritance_rendering_info.stencilAttachmentFormat = VK_FORMAT_R8G8B8_SNORM;
68 cmd_buffer_inheritance_rendering_info.viewMask = 1 << multiview_props.maxMultiviewViewCount;
69
70 auto sample_count_info_amd = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
71 sample_count_info_amd.pNext = &cmd_buffer_inheritance_rendering_info;
72 sample_count_info_amd.colorAttachmentCount = 2;
sfricke-samsungae54c1e2022-01-21 05:35:21 -080073
Aaron Haganaca50442021-12-07 22:26:29 -050074 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
75 cmd_buffer_inheritance_info.pNext = &sample_count_info_amd;
76
77 auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
78 cmd_buffer_allocate_info.commandPool = m_commandPool->handle();
79 cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
80 cmd_buffer_allocate_info.commandBufferCount = 0x1;
81
82 VkCommandBuffer secondary_cmd_buffer;
83 VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer);
84 ASSERT_VK_SUCCESS(err);
85 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06003");
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070086 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-colorAttachmentCount-06004");
87 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-variableMultisampleRate-06005");
88 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06007");
89 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-multiview-06008");
90 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-viewMask-06009");
ziga-lunarg813fa012022-04-09 14:09:57 +020091 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-stencilAttachmentFormat-06199");
92 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06200");
93 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-pColorAttachmentFormats-06006");
94 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06540");
Aaron Haganaca50442021-12-07 22:26:29 -050095
96 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
97 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
98 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
99 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
100 m_errorMonitor->VerifyFound();
101}
102
Aaron Haganb54466d2022-02-18 15:02:54 -0500103TEST_F(VkLayerTest, DynamicRenderingCommandDraw) {
Aaron Haganaca50442021-12-07 22:26:29 -0500104 TEST_DESCRIPTION("vkCmdDraw* Dynamic Rendering Tests.");
105
106 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
107 if (version < VK_API_VERSION_1_2) {
108 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
109 return;
110 }
111
112 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
113
114 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
115
116 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900117 GTEST_SKIP() << "At least Vulkan version 1.2 is required";
Aaron Haganaca50442021-12-07 22:26:29 -0500118 }
119
120 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +0900121 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
Aaron Haganaca50442021-12-07 22:26:29 -0500122 }
123
124 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
125 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
126 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
127 if (!dynamic_rendering_features.dynamicRendering) {
128 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
129 return;
130 }
131
132 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
133
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800134 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
135 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
Aaron Haganaca50442021-12-07 22:26:29 -0500136
137 VkPipelineObj pipe(m_device);
138 pipe.AddShader(&vs);
139 pipe.AddShader(&fs);
140 pipe.AddDefaultColorAttachment();
141
142 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
143 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
144 const VkPipelineLayoutObj pl(m_device, {&dsl});
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800145
Aaron Haganaca50442021-12-07 22:26:29 -0500146 VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
147 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
Aaron Hagan80034ea2021-12-23 11:24:09 -0500148 pipeline_rendering_info.depthAttachmentFormat = depth_format;
149 pipeline_rendering_info.stencilAttachmentFormat = depth_format;
Aaron Haganaca50442021-12-07 22:26:29 -0500150
151 auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>();
152 multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT;
153
154 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
155 pipe.InitGraphicsPipelineCreateInfo(&create_info);
156 create_info.pMultisampleState = &multisample_state_create_info;
157 create_info.renderPass = VkRenderPass(0x1);
158 create_info.pNext = &pipeline_rendering_info;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800159
Aaron Haganaca50442021-12-07 22:26:29 -0500160 VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
161 ASSERT_VK_SUCCESS(err);
162
163 VkViewport viewport = {0, 0, 16, 16, 0, 1};
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800164 VkRect2D scissor = {{0, 0}, {16, 16}};
Aaron Haganaca50442021-12-07 22:26:29 -0500165
166 VkImageObj image(m_device);
167 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0);
168 ASSERT_TRUE(image.initialized());
169
170 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
171 nullptr,
172 0,
173 image.handle(),
174 VK_IMAGE_VIEW_TYPE_2D,
175 depth_format,
176 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
177 VK_COMPONENT_SWIZZLE_IDENTITY},
178 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
179
180 VkImageView depth_image_view;
181 err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view);
182 ASSERT_VK_SUCCESS(err);
183
184 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
185 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
186 depth_attachment.imageView = depth_image_view;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800187
Aaron Haganaca50442021-12-07 22:26:29 -0500188 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
189 begin_rendering_info.pDepthAttachment = &depth_attachment;
190 begin_rendering_info.pStencilAttachment = &depth_attachment;
191
192 m_commandBuffer->begin();
193 m_commandBuffer->BeginRendering(begin_rendering_info);
194 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
195 vk::CmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
196 vk::CmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
197 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189");
198 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190");
199 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
200 m_errorMonitor->VerifyFound();
201 m_commandBuffer->EndRendering();
202 m_commandBuffer->end();
203}
204
205TEST_F(VkLayerTest, DynamicRenderingGraphicsPipelineCreateInfo) {
206 TEST_DESCRIPTION("Test graphics pipeline creation with dynamic rendering.");
Nathaniel Cesario72f29552022-03-24 05:11:11 -0600207 m_errorMonitor->ExpectSuccess();
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800208
Aaron Haganaca50442021-12-07 22:26:29 -0500209 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
210 if (version < VK_API_VERSION_1_2) {
211 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
212 return;
213 }
214
215 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
216
217 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
218
219 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900220 GTEST_SKIP() << "At least Vulkan version 1.2 is required";
Aaron Haganaca50442021-12-07 22:26:29 -0500221 }
222
223 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +0900224 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
Aaron Haganaca50442021-12-07 22:26:29 -0500225 }
226
227 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
228 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
229 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
230 if (!dynamic_rendering_features.dynamicRendering) {
231 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
232 return;
233 }
234
235 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
236
237 const VkPipelineLayoutObj pl(m_device);
238 VkPipelineObj pipe(m_device);
239
240 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
241
242 auto color_blend_state_create_info = LvlInitStruct<VkPipelineColorBlendStateCreateInfo>();
243 color_blend_state_create_info.attachmentCount = 1;
244 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
245
246 VkFormat color_format[2] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_D32_SFLOAT_S8_UINT};
247
248 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
249 pipeline_rendering_info.colorAttachmentCount = 2;
250 pipeline_rendering_info.pColorAttachmentFormats = &color_format[0];
251 pipeline_rendering_info.viewMask = 0x2;
Aaron Hagan80034ea2021-12-23 11:24:09 -0500252 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
Aaron Haganaca50442021-12-07 22:26:29 -0500253
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800254 auto pipeline_tessellation_state_info = LvlInitStruct<VkPipelineTessellationStateCreateInfo>();
Aaron Haganaca50442021-12-07 22:26:29 -0500255 pipeline_tessellation_state_info.patchControlPoints = 1;
256
257 auto pipeline_input_assembly_state_info = LvlInitStruct<VkPipelineInputAssemblyStateCreateInfo>();
258 pipeline_input_assembly_state_info.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
259
260 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
Aaron Hagan80034ea2021-12-23 11:24:09 -0500261
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800262 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
263 VkShaderObj gs(this, bindStateGeomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT);
264 VkShaderObj te(this, bindStateTeshaderText, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
265 VkShaderObj tc(this, bindStateTscShaderText, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
Aaron Hagan80034ea2021-12-23 11:24:09 -0500266 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
267
Aaron Haganaca50442021-12-07 22:26:29 -0500268 pipe.AddShader(&vs);
269 pipe.AddShader(&gs);
270 pipe.AddShader(&te);
271 pipe.AddShader(&tc);
Aaron Hagan80034ea2021-12-23 11:24:09 -0500272 pipe.AddShader(&fs);
Aaron Haganaca50442021-12-07 22:26:29 -0500273 pipe.InitGraphicsPipelineCreateInfo(&create_info);
Nathaniel Cesario72f29552022-03-24 05:11:11 -0600274 m_errorMonitor->VerifyNotFound();
275
Aaron Haganaca50442021-12-07 22:26:29 -0500276 create_info.pColorBlendState = &color_blend_state_create_info;
277 create_info.pNext = &pipeline_rendering_info;
278 create_info.pTessellationState = &pipeline_tessellation_state_info;
279 create_info.pInputAssemblyState = &pipeline_input_assembly_state_info;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800280
Aaron Hagan80034ea2021-12-23 11:24:09 -0500281 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06053");
Nathaniel Cesario72f29552022-03-24 05:11:11 -0600282 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06581");
Aaron Haganaca50442021-12-07 22:26:29 -0500283 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06055");
284 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06057");
285 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06058");
286 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06060");
Nathaniel Cesarioa6118572022-03-24 04:48:33 -0600287 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-multiview-06577");
Aaron Haganaca50442021-12-07 22:26:29 -0500288 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
289 m_errorMonitor->VerifyFound();
290
Aaron Hagan80034ea2021-12-23 11:24:09 -0500291 create_info.pColorBlendState = nullptr;
292 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
293 pipeline_rendering_info.viewMask = 0x0;
294 pipeline_rendering_info.colorAttachmentCount = 1;
295 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06054");
296 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
297 m_errorMonitor->VerifyFound();
Aaron Haganb54466d2022-02-18 15:02:54 -0500298
ziga-lunarg5e671602022-03-17 19:06:55 +0100299 color_format[0] = VK_FORMAT_D32_SFLOAT_S8_UINT;
300 color_blend_attachment_state.blendEnable = VK_TRUE;
301 create_info.pColorBlendState = &color_blend_state_create_info;
Nathaniel Cesario72f29552022-03-24 05:11:11 -0600302 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06581");
ziga-lunarg5e671602022-03-17 19:06:55 +0100303 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06062");
ziga-lunarg5e671602022-03-17 19:06:55 +0100304 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
305 m_errorMonitor->VerifyFound();
306 color_format[0] = VK_FORMAT_R8G8B8A8_UNORM;
307
Aaron Haganb54466d2022-02-18 15:02:54 -0500308 auto ds_ci = LvlInitStruct<VkPipelineDepthStencilStateCreateInfo>();
309 ds_ci.flags = VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_ARM;
310 color_blend_state_create_info.flags = VK_PIPELINE_COLOR_BLEND_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_BIT_ARM;
311 create_info.pColorBlendState = &color_blend_state_create_info;
312 create_info.pDepthStencilState = &ds_ci;
313 create_info.renderPass = VK_NULL_HANDLE;
314 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
315 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06482");
316 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06483");
317 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
318 m_errorMonitor->VerifyFound();
stusmith15f24a82021-12-24 15:21:19 +0000319}
320
321TEST_F(VkLayerTest, DynamicRenderingWithMismatchingViewMask) {
322 TEST_DESCRIPTION("Draw with Dynamic Rendering and a mismatching viewMask");
323
324 SetTargetApiVersion(VK_API_VERSION_1_1);
325
326 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
327
328 ASSERT_NO_FATAL_FAILURE(InitFramework());
329
330 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +0900331 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
stusmith15f24a82021-12-24 15:21:19 +0000332 }
333
334 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900335 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
stusmith15f24a82021-12-24 15:21:19 +0000336 }
337
338 auto multiview_features = LvlInitStruct<VkPhysicalDeviceMultiviewFeatures>();
339 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(&multiview_features);
340 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
341 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
342 if (!dynamic_rendering_features.dynamicRendering) {
343 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
344 return;
345 }
346 if (!multiview_features.multiview) {
347 printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix);
348 return;
349 }
350
351 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
352
353 char const *fsSource = R"glsl(
354 #version 450
355 layout(location=0) out vec4 color;
356 void main() {
357 color = vec4(1.0f);
358 }
359 )glsl";
360
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800361 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
362 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000363
364 VkPipelineObj pipe(m_device);
365 pipe.AddShader(&vs);
366 pipe.AddShader(&fs);
367 pipe.AddDefaultColorAttachment();
368
369 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
370 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
371 const VkPipelineLayoutObj pl(m_device, {&dsl});
372
373 VkFormat color_formats = {VK_FORMAT_R8G8B8A8_UNORM};
374 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
375 pipeline_rendering_info.colorAttachmentCount = 1;
376 pipeline_rendering_info.pColorAttachmentFormats = &color_formats;
377 pipeline_rendering_info.viewMask = 1;
378
379 VkViewport viewport = {0, 0, 16, 16, 0, 1};
380 VkRect2D scissor = {{0, 0}, {16, 16}};
381 m_viewports.push_back(viewport);
382 m_scissors.push_back(scissor);
383 pipe.SetViewport(m_viewports);
384 pipe.SetScissor(m_scissors);
385
386 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
387 pipe.InitGraphicsPipelineCreateInfo(&create_info);
388 create_info.pNext = &pipeline_rendering_info;
389
390 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
391
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800392 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000393 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
394
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800395 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000396 begin_rendering_info.colorAttachmentCount = 1;
397 begin_rendering_info.pColorAttachments = &color_attachment;
398 begin_rendering_info.viewMask = 2;
399 begin_rendering_info.layerCount = 1;
400
401 m_commandBuffer->begin();
402 m_commandBuffer->BeginRendering(begin_rendering_info);
403 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
404 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-viewMask-06178");
405 m_commandBuffer->Draw(1, 1, 0, 0);
406 m_errorMonitor->VerifyFound();
407 m_commandBuffer->EndRendering();
408 m_commandBuffer->end();
409}
410
411TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachments) {
412 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color attachment counts and depth/stencil formats");
413
414 SetTargetApiVersion(VK_API_VERSION_1_1);
415
416 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
417
418 ASSERT_NO_FATAL_FAILURE(InitFramework());
419
420 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +0900421 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
stusmith15f24a82021-12-24 15:21:19 +0000422 }
423
424 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900425 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
stusmith15f24a82021-12-24 15:21:19 +0000426 }
427
428 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
429 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
430 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
431 if (!dynamic_rendering_features.dynamicRendering) {
432 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
433 return;
434 }
435
436 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
437
438 char const *fsSource = R"glsl(
439 #version 450
440 layout(location=0) out vec4 color;
441 void main() {
442 color = vec4(1.0f);
443 }
444 )glsl";
445
446 VkViewport viewport = {0, 0, 16, 16, 0, 1};
447 VkRect2D scissor = {{0, 0}, {16, 16}};
448 m_viewports.push_back(viewport);
449 m_scissors.push_back(scissor);
450
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800451 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
452 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000453
454 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
455 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
456 const VkPipelineLayoutObj pl(m_device, {&dsl});
457
458 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
459
460 VkPipelineObj pipe1(m_device);
461 pipe1.AddShader(&vs);
462 pipe1.AddShader(&fs);
463 pipe1.AddDefaultColorAttachment();
464 pipe1.SetViewport(m_viewports);
465 pipe1.SetScissor(m_scissors);
466
467 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
468 pipeline_rendering_info.colorAttachmentCount = 1;
469 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
470
471 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
472 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
473 create_info1.pNext = &pipeline_rendering_info;
474
475 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
476
477 VkPipelineObj pipe2(m_device);
478 pipe2.AddShader(&vs);
479 pipe2.AddShader(&fs);
480 pipe2.AddDefaultColorAttachment();
481 pipe2.SetViewport(m_viewports);
482 pipe2.SetScissor(m_scissors);
483
484 pipeline_rendering_info.colorAttachmentCount = 0;
485 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
486 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D16_UNORM;
487
488 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
489 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
490 create_info2.pNext = &pipeline_rendering_info;
491
492 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
493
494 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
495 ASSERT_TRUE(depthStencilFormat != 0);
496
497 bool testStencil = false;
498 VkFormat stencilFormat = VK_FORMAT_UNDEFINED;
499
500 if (ImageFormatIsSupported(gpu(), VK_FORMAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
501 stencilFormat = VK_FORMAT_S8_UINT;
502 testStencil = true;
503 } else if ((depthStencilFormat != VK_FORMAT_D16_UNORM_S8_UINT) &&
504 ImageFormatIsSupported(gpu(), VK_FORMAT_D16_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
505 stencilFormat = VK_FORMAT_D16_UNORM_S8_UINT;
506 testStencil = true;
507 } else if ((depthStencilFormat != VK_FORMAT_D24_UNORM_S8_UINT) &&
508 ImageFormatIsSupported(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
509 stencilFormat = VK_FORMAT_D24_UNORM_S8_UINT;
510 testStencil = true;
511 } else if ((depthStencilFormat != VK_FORMAT_D32_SFLOAT_S8_UINT) &&
512 ImageFormatIsSupported(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
513 stencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
514 testStencil = true;
515 }
516
517 VkPipelineObj pipe3(m_device);
518
519 if (testStencil) {
520 pipe3.AddShader(&vs);
521 pipe3.AddShader(&fs);
522 pipe3.AddDefaultColorAttachment();
523 pipe3.SetViewport(m_viewports);
524 pipe3.SetScissor(m_scissors);
525
526 pipeline_rendering_info.colorAttachmentCount = 0;
527 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
528 pipeline_rendering_info.stencilAttachmentFormat = stencilFormat;
529
530 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
531 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
532 create_info3.pNext = &pipeline_rendering_info;
533
534 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
535 }
536
537 VkImageObj colorImage(m_device);
538 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
539 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT);
540
541 VkImageObj depthStencilImage(m_device);
542 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
543 VkImageView depthStencilImageView =
544 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
545
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800546 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000547 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
548 color_attachment.imageView = colorImageView;
549
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800550 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000551 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
552 depth_stencil_attachment.imageView = depthStencilImageView;
553
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800554 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000555 m_commandBuffer->begin();
556
557 // Mismatching color attachment count
558 m_commandBuffer->BeginRendering(begin_rendering_info);
559 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
560 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06179");
561 m_commandBuffer->Draw(1, 1, 0, 0);
562 m_errorMonitor->VerifyFound();
563 m_commandBuffer->EndRendering();
564
565 // Mismatching color formats
566 begin_rendering_info.colorAttachmentCount = 1;
567 begin_rendering_info.pColorAttachments = &color_attachment;
568 m_commandBuffer->BeginRendering(begin_rendering_info);
569 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
570 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06180");
571 m_commandBuffer->Draw(1, 1, 0, 0);
572 m_errorMonitor->VerifyFound();
573 m_commandBuffer->EndRendering();
574
575 // Mismatching depth format
576 begin_rendering_info.colorAttachmentCount = 0;
577 begin_rendering_info.pColorAttachments = nullptr;
578 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
579 m_commandBuffer->BeginRendering(begin_rendering_info);
580 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
581 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06181");
582 m_commandBuffer->Draw(1, 1, 0, 0);
583 m_errorMonitor->VerifyFound();
584 m_commandBuffer->EndRendering();
585
586 // Mismatching stencil format
587 if (testStencil) {
588 begin_rendering_info.pDepthAttachment = nullptr;
589 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
590 m_commandBuffer->BeginRendering(begin_rendering_info);
591 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
592 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06182");
593 m_commandBuffer->Draw(1, 1, 0, 0);
594 m_errorMonitor->VerifyFound();
595 m_commandBuffer->EndRendering();
596 }
597
598 m_commandBuffer->end();
599}
600
601TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachmentSamples) {
602 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color/depth/stencil sample counts");
603
604 SetTargetApiVersion(VK_API_VERSION_1_1);
605
606 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
607
608 ASSERT_NO_FATAL_FAILURE(InitFramework());
609
610 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +0900611 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
stusmith15f24a82021-12-24 15:21:19 +0000612 }
613
614 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900615 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
stusmith15f24a82021-12-24 15:21:19 +0000616 }
617
618 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
619 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
620 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
621 if (!dynamic_rendering_features.dynamicRendering) {
622 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
623 return;
624 }
625
626 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
627
628 char const *fsSource = R"glsl(
629 #version 450
630 layout(location=0) out vec4 color;
631 void main() {
632 color = vec4(1.0f);
633 }
634 )glsl";
635
636 VkViewport viewport = {0, 0, 16, 16, 0, 1};
637 VkRect2D scissor = {{0, 0}, {16, 16}};
638 m_viewports.push_back(viewport);
639 m_scissors.push_back(scissor);
640
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800641 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
642 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000643
644 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
645 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
646 const VkPipelineLayoutObj pl(m_device, {&dsl});
647
648 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
649
stusmith15f24a82021-12-24 15:21:19 +0000650 VkPipelineObj pipe1(m_device);
651 pipe1.AddShader(&vs);
652 pipe1.AddShader(&fs);
653 pipe1.AddDefaultColorAttachment();
654 pipe1.SetViewport(m_viewports);
655 pipe1.SetScissor(m_scissors);
656
657 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
658 pipeline_rendering_info.colorAttachmentCount = 1;
659 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
660
661 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
662 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
663 create_info1.pNext = &pipeline_rendering_info;
664
665 auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>();
666 multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT;
667 create_info1.pMultisampleState = &multisample_state_create_info;
668
669 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
670
stusmith15f24a82021-12-24 15:21:19 +0000671 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
672 ASSERT_TRUE(depthStencilFormat != 0);
673
stusmith15f24a82021-12-24 15:21:19 +0000674 VkPipelineObj pipe2(m_device);
675 pipe2.AddShader(&vs);
676 pipe2.AddShader(&fs);
677 pipe2.AddDefaultColorAttachment();
678 pipe2.SetViewport(m_viewports);
679 pipe2.SetScissor(m_scissors);
680
681 pipeline_rendering_info.colorAttachmentCount = 0;
682 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
683 pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat;
684
685 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
686 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
687 create_info2.pNext = &pipeline_rendering_info;
688
689 create_info2.pMultisampleState = &multisample_state_create_info;
690
691 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
692
stusmith15f24a82021-12-24 15:21:19 +0000693 VkPipelineObj pipe3(m_device);
694
695 pipe3.AddShader(&vs);
696 pipe3.AddShader(&fs);
697 pipe3.AddDefaultColorAttachment();
698 pipe3.SetViewport(m_viewports);
699 pipe3.SetScissor(m_scissors);
700
701 pipeline_rendering_info.colorAttachmentCount = 0;
702 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
703 pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat;
704
705 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
706 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
707 create_info3.pNext = &pipeline_rendering_info;
708
709 create_info3.pMultisampleState = &multisample_state_create_info;
710
711 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
712
stusmith15f24a82021-12-24 15:21:19 +0000713 VkImageObj colorImage(m_device);
714 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
715 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM);
716
717 VkImageObj depthStencilImage(m_device);
718 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
719 VkImageView depthStencilImageView =
720 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
721
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800722 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000723 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
724 color_attachment.imageView = colorImageView;
725
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800726 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000727 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
728 depth_stencil_attachment.imageView = depthStencilImageView;
729
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800730 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000731 m_commandBuffer->begin();
732
733 // Mismatching color samples
734 begin_rendering_info.colorAttachmentCount = 1;
735 begin_rendering_info.pColorAttachments = &color_attachment;
736 m_commandBuffer->BeginRendering(begin_rendering_info);
737 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
738 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06188");
739 m_commandBuffer->Draw(1, 1, 0, 0);
740 m_errorMonitor->VerifyFound();
741 m_commandBuffer->EndRendering();
742
743 // Mismatching depth samples
744 begin_rendering_info.colorAttachmentCount = 0;
745 begin_rendering_info.pColorAttachments = nullptr;
746 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
747 m_commandBuffer->BeginRendering(begin_rendering_info);
748 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
749 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189");
750 m_commandBuffer->Draw(1, 1, 0, 0);
751 m_errorMonitor->VerifyFound();
752 m_commandBuffer->EndRendering();
753
754 // Mismatching stencil samples
755 begin_rendering_info.pDepthAttachment = nullptr;
756 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
757 m_commandBuffer->BeginRendering(begin_rendering_info);
758 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
759 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190");
760 m_commandBuffer->Draw(1, 1, 0, 0);
761 m_errorMonitor->VerifyFound();
762 m_commandBuffer->EndRendering();
763
764 m_commandBuffer->end();
765}
766
767TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingMixedAttachmentSamples) {
768 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching mixed color/depth/stencil sample counts");
769
770 SetTargetApiVersion(VK_API_VERSION_1_1);
771
772 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
773
774 ASSERT_NO_FATAL_FAILURE(InitFramework());
775
776 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +0900777 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
stusmith15f24a82021-12-24 15:21:19 +0000778 }
779
780 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900781 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
stusmith15f24a82021-12-24 15:21:19 +0000782 }
783
784 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
785 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
786 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
787 if (!dynamic_rendering_features.dynamicRendering) {
788 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
789 return;
790 }
791
792 bool amd_samples = false;
793 if (DeviceExtensionSupported(gpu(), nullptr, VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME)) {
794 m_device_extension_names.push_back(VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME);
795 amd_samples = true;
796 }
797
798 bool nv_samples = false;
799 if (DeviceExtensionSupported(gpu(), nullptr, VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME)) {
800 m_device_extension_names.push_back(VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME);
801 nv_samples = true;
802 }
803
804 if (!amd_samples && !nv_samples) {
805 printf("%s Test requires either VK_AMD_mixed_attachment_samples or VK_NV_framebuffer_mixed_samples, skipping\n",
806 kSkipPrefix);
807 return;
808 }
809
810 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
811
812 char const *fsSource = R"glsl(
813 #version 450
814 layout(location=0) out vec4 color;
815 void main() {
816 color = vec4(1.0f);
817 }
818 )glsl";
819
820 VkViewport viewport = {0, 0, 16, 16, 0, 1};
821 VkRect2D scissor = {{0, 0}, {16, 16}};
822 m_viewports.push_back(viewport);
823 m_scissors.push_back(scissor);
824
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800825 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
826 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000827
828 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
829 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
830 const VkPipelineLayoutObj pl(m_device, {&dsl});
831
832 VkSampleCountFlagBits counts = {VK_SAMPLE_COUNT_2_BIT};
833 auto samples_info = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
834
835 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(&samples_info);
836
837 VkPipelineObj pipe1(m_device);
838 pipe1.AddShader(&vs);
839 pipe1.AddShader(&fs);
840 pipe1.AddDefaultColorAttachment();
841 pipe1.SetViewport(m_viewports);
842 pipe1.SetScissor(m_scissors);
843
844 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
845 pipeline_rendering_info.colorAttachmentCount = 1;
846 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
847
848 samples_info.colorAttachmentCount = 1;
849 samples_info.pColorAttachmentSamples = &counts;
850
851 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
852 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
853 create_info1.pNext = &pipeline_rendering_info;
854
Aaron Haganb54466d2022-02-18 15:02:54 -0500855 samples_info.colorAttachmentCount = 2;
856 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06063");
857 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
858 m_errorMonitor->VerifyFound();
859
860 samples_info.colorAttachmentCount = 1;
stusmith15f24a82021-12-24 15:21:19 +0000861 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
862
863 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
864 ASSERT_TRUE(depthStencilFormat != 0);
865
866 VkPipelineObj pipe2(m_device);
867 pipe2.AddShader(&vs);
868 pipe2.AddShader(&fs);
869 pipe2.AddDefaultColorAttachment();
870 pipe2.SetViewport(m_viewports);
871 pipe2.SetScissor(m_scissors);
872
873 pipeline_rendering_info.colorAttachmentCount = 0;
874 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
875 pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat;
876
877 samples_info.colorAttachmentCount = 0;
878 samples_info.pColorAttachmentSamples = nullptr;
879 samples_info.depthStencilAttachmentSamples = counts;
880
881 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
882 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
883 create_info2.pNext = &pipeline_rendering_info;
884
885 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
886
887 VkPipelineObj pipe3(m_device);
888
889 pipe3.AddShader(&vs);
890 pipe3.AddShader(&fs);
891 pipe3.AddDefaultColorAttachment();
892 pipe3.SetViewport(m_viewports);
893 pipe3.SetScissor(m_scissors);
894
895 pipeline_rendering_info.colorAttachmentCount = 0;
896 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
897 pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat;
898
899 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
900 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
901 create_info3.pNext = &pipeline_rendering_info;
902
903 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
904
905 VkImageObj colorImage(m_device);
906 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
907 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM);
908
909 VkImageObj depthStencilImage(m_device);
910 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
911 VkImageView depthStencilImageView =
912 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
913
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800914 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000915 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
916 color_attachment.imageView = colorImageView;
917
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800918 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000919 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
920 depth_stencil_attachment.imageView = depthStencilImageView;
921
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800922 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000923 m_commandBuffer->begin();
924
925 // Mismatching color samples
926 begin_rendering_info.colorAttachmentCount = 1;
927 begin_rendering_info.pColorAttachments = &color_attachment;
928 m_commandBuffer->BeginRendering(begin_rendering_info);
929 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
930 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06185");
931 m_commandBuffer->Draw(1, 1, 0, 0);
932 m_errorMonitor->VerifyFound();
933 m_commandBuffer->EndRendering();
934
935 // Mismatching depth samples
936 begin_rendering_info.colorAttachmentCount = 0;
937 begin_rendering_info.pColorAttachments = nullptr;
938 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
939 m_commandBuffer->BeginRendering(begin_rendering_info);
940 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
941 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06186");
942 m_commandBuffer->Draw(1, 1, 0, 0);
943 m_errorMonitor->VerifyFound();
944 m_commandBuffer->EndRendering();
945
946 // Mismatching stencil samples
947 begin_rendering_info.pDepthAttachment = nullptr;
948 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
949 m_commandBuffer->BeginRendering(begin_rendering_info);
950 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
951 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06187");
952 m_commandBuffer->Draw(1, 1, 0, 0);
953 m_errorMonitor->VerifyFound();
954 m_commandBuffer->EndRendering();
955
956 m_commandBuffer->end();
957}
Aaron Hagan80034ea2021-12-23 11:24:09 -0500958
959TEST_F(VkLayerTest, DynamicRenderingAttachmentInfo) {
960 TEST_DESCRIPTION("AttachmentInfo Dynamic Rendering Tests.");
961
962 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
963 if (version < VK_API_VERSION_1_2) {
964 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
965 return;
966 }
967
968 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
969
970 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
971
972 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
sjfrickebdd58dd2022-05-20 14:22:50 +0900973 GTEST_SKIP() << "At least Vulkan version 1.2 is required";
Aaron Hagan80034ea2021-12-23 11:24:09 -0500974 }
975
976 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +0900977 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
Aaron Hagan80034ea2021-12-23 11:24:09 -0500978 }
979
980 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
981 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
982 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
983 if (!dynamic_rendering_features.dynamicRendering) {
984 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
985 return;
986 }
987
988 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
989
990 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
991 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
992
993 VkPipelineObj pipe(m_device);
994 pipe.AddShader(&vs);
995 pipe.AddShader(&fs);
996 pipe.AddDefaultColorAttachment();
997
998 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
999 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
1000 const VkPipelineLayoutObj pl(m_device, {&dsl});
1001
1002 VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1003 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1004 pipeline_rendering_info.depthAttachmentFormat = depth_format;
1005
1006 auto pipeline_create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
1007 pipe.InitGraphicsPipelineCreateInfo(&pipeline_create_info);
1008 pipeline_create_info.pNext = &pipeline_rendering_info;
1009
1010 VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &pipeline_create_info);
1011 ASSERT_VK_SUCCESS(err);
1012
1013 VkImageObj image(m_device);
1014 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1015 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1016 image_create_info.format = depth_format;
1017 image_create_info.extent = {64, 64, 4};
1018 image_create_info.mipLevels = 1;
1019 image_create_info.arrayLayers = 1;
1020 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1021 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1022 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1023 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1024
1025 image.Init(image_create_info);
1026 ASSERT_TRUE(image.initialized());
1027
1028 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1029 nullptr,
1030 0,
1031 image.handle(),
1032 VK_IMAGE_VIEW_TYPE_2D,
1033 depth_format,
1034 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1035 VK_COMPONENT_SWIZZLE_IDENTITY},
1036 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1037
1038 VkImageView depth_image_view;
1039 err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view);
1040 ASSERT_VK_SUCCESS(err);
1041
1042 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1043 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1044 depth_attachment.imageView = depth_image_view;
1045 depth_attachment.resolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT;
1046 depth_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1047
1048 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1049 begin_rendering_info.pDepthAttachment = &depth_attachment;
1050 begin_rendering_info.viewMask = 0x4;
1051
1052 VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map =
1053 LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>();
1054 fragment_density_map.imageView = depth_image_view;
1055 begin_rendering_info.pNext = &fragment_density_map;
1056
1057 m_commandBuffer->begin();
1058 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-multiview-06127");
Jeremy Gebben09c1a072022-02-08 09:42:47 -07001059 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06107");
1060 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06108");
1061 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06116");
Jeremy Gebben09c1a072022-02-08 09:42:47 -07001062 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06145");
1063 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06146");
Aaron Hagan80034ea2021-12-23 11:24:09 -05001064 m_commandBuffer->BeginRendering(begin_rendering_info);
1065 m_errorMonitor->VerifyFound();
1066}
Aaron Haganb54466d2022-02-18 15:02:54 -05001067
1068TEST_F(VkLayerTest, DynamicRenderingBufferBeginInfoLegacy) {
1069 TEST_DESCRIPTION("VkCommandBufferBeginInfo Dynamic Rendering Tests.");
1070
1071 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
1072 if (version < VK_API_VERSION_1_2) {
1073 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
1074 return;
1075 }
1076
1077 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1078
1079 ASSERT_NO_FATAL_FAILURE(Init(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1080
1081 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001082 GTEST_SKIP() << "At least Vulkan version 1.2 is required";
Aaron Haganb54466d2022-02-18 15:02:54 -05001083 }
1084
1085 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +09001086 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
Aaron Haganb54466d2022-02-18 15:02:54 -05001087 }
1088
1089 auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
1090 cmd_buffer_inheritance_rendering_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
1091
1092 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
1093 cmd_buffer_inheritance_info.pNext = &cmd_buffer_inheritance_rendering_info;
1094 cmd_buffer_inheritance_info.renderPass = VK_NULL_HANDLE;
1095
1096 auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
1097 cmd_buffer_allocate_info.commandPool = m_commandPool->handle();
1098 cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
1099 cmd_buffer_allocate_info.commandBufferCount = 0x1;
1100
1101 VkCommandBuffer secondary_cmd_buffer;
1102 VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer);
1103 ASSERT_VK_SUCCESS(err);
1104
1105 // Invalid RenderPass
1106 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-00053");
1107 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
1108 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1109 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
1110 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
1111 m_errorMonitor->VerifyFound();
1112
1113 // Valid RenderPass
1114 VkAttachmentDescription attach[] = {
1115 {0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
1116 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
1117 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
1118 };
1119 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
1120
1121 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
1122 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, &subpass, 0, nullptr};
1123
1124 vk_testing::RenderPass rp1;
1125 rp1.init(*m_device, rpci);
1126
1127 cmd_buffer_inheritance_info.renderPass = rp1.handle();
1128 cmd_buffer_inheritance_info.subpass = 0x5;
1129 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-00054");
1130 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
1131 m_errorMonitor->VerifyFound();
1132}
1133
1134TEST_F(VkLayerTest, DynamicRenderingSecondaryCommandBuffer) {
1135 TEST_DESCRIPTION("VkCommandBufferBeginInfo Dynamic Rendering Tests.");
1136
1137 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_3);
1138 if (version < VK_API_VERSION_1_3) {
1139 printf("%s At least Vulkan version 1.3 is required, skipping test.\n", kSkipPrefix);
1140 return;
1141 }
1142
1143 ASSERT_NO_FATAL_FAILURE(Init());
1144
1145 if (DeviceValidationVersion() < VK_API_VERSION_1_3) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001146 GTEST_SKIP() << "At least Vulkan version 1.3 is required";
Aaron Haganb54466d2022-02-18 15:02:54 -05001147 }
1148
1149 VkCommandBufferObj cb(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1150
1151 // Force the failure by not setting the Renderpass and Framebuffer fields
1152 VkCommandBufferInheritanceInfo cmd_buf_hinfo = LvlInitStruct<VkCommandBufferInheritanceInfo>();
1153 cmd_buf_hinfo.renderPass = VkRenderPass(0x1);
1154 VkCommandBufferBeginInfo cmd_buf_info = LvlInitStruct<VkCommandBufferBeginInfo>();
1155 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1156 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
1157
1158 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06000");
1159 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1160 m_errorMonitor->VerifyFound();
1161
1162 // Valid RenderPass
1163 VkAttachmentDescription attach[] = {
1164 {0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
1165 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
1166 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
1167 };
1168 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
1169
1170 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
1171 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, &subpass, 0, nullptr};
1172
1173 vk_testing::RenderPass rp1;
1174 rp1.init(*m_device, rpci);
1175
1176 cmd_buf_hinfo.renderPass = rp1.handle();
1177 cmd_buf_hinfo.subpass = 0x5;
1178 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06001");
1179 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1180 m_errorMonitor->VerifyFound();
1181
1182 cmd_buf_hinfo.renderPass = VK_NULL_HANDLE;
1183 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06002");
1184 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1185 m_errorMonitor->VerifyFound();
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001186}
1187
ziga-lunarg1b46f192022-04-20 21:52:22 +02001188TEST_F(VkLayerTest, DynamicRenderingDepthFormatAndResolveMode) {
1189 TEST_DESCRIPTION("Test VkRenderingAttachmentInfo imageView with depth format.");
1190
1191 SetTargetApiVersion(VK_API_VERSION_1_1);
1192 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1193 ASSERT_NO_FATAL_FAILURE(InitFramework());
1194
1195 if (DeviceValidationVersion() != VK_API_VERSION_1_1) {
1196 printf("%s Vulkan version 1.1 is required for device, skipping test\n", kSkipPrefix);
1197 return;
1198 }
1199 if (!AreRequestedExtensionsEnabled()) {
1200 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1201 return;
1202 }
1203
1204 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1205 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1206 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1207 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1208 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1209 return;
1210 }
1211
1212 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1213
1214 auto depth_stencil_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1215 auto props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&depth_stencil_props);
1216 vk::GetPhysicalDeviceProperties2(gpu(), &props2);
1217
1218 if ((depth_stencil_props.supportedDepthResolveModes & VK_RESOLVE_MODE_AVERAGE_BIT) == 0) {
1219 printf("%s Required depth resolve mode not supported, skipping.\n", kSkipPrefix);
1220 return;
1221 }
1222
1223 VkFormat depth_format = FindSupportedDepthStencilFormat(gpu());
1224 if (depth_format == VK_FORMAT_UNDEFINED) {
1225 printf("%s No Depth + Stencil format found, skipping.\n", kSkipPrefix);
1226 return;
1227 }
1228
1229 VkImageObj image(m_device);
1230 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1231 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1232 image_create_info.format = depth_format;
1233 image_create_info.extent = {64, 64, 1};
1234 image_create_info.mipLevels = 1;
1235 image_create_info.arrayLayers = 1;
1236 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1237 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1238 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1239 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1240
1241 image.Init(image_create_info);
1242 ASSERT_TRUE(image.initialized());
1243
1244 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1245 nullptr,
1246 0,
1247 image.handle(),
1248 VK_IMAGE_VIEW_TYPE_2D,
1249 depth_format,
1250 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1251 VK_COMPONENT_SWIZZLE_IDENTITY},
1252 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1253
1254 vk_testing::ImageView depth_image_view;
1255 depth_image_view.init(*m_device, ivci);
1256
1257 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1258 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
1259 depth_attachment.imageView = depth_image_view.handle();
1260 depth_attachment.resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
1261 depth_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_GENERAL;
1262
1263 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1264 begin_rendering_info.layerCount = 1;
1265 begin_rendering_info.pDepthAttachment = &depth_attachment;
1266
1267 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06131");
1268
1269 m_commandBuffer->begin();
1270 m_commandBuffer->BeginRendering(begin_rendering_info);
1271 m_commandBuffer->end();
1272
1273 m_errorMonitor->VerifyFound();
1274}
1275
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001276TEST_F(VkLayerTest, TestDynamicRenderingPipelineMissingFlags) {
1277 TEST_DESCRIPTION("Test dynamic rendering with pipeline missing flags.");
1278
1279 SetTargetApiVersion(VK_API_VERSION_1_1);
1280 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1281 AddRequiredExtensions(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1282 AddRequiredExtensions(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1283
1284 ASSERT_NO_FATAL_FAILURE(InitFramework());
1285
1286 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001287 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001288 }
1289
1290 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1291 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1292 return;
1293 }
1294 bool fragment_density = DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1295 bool shading_rate = DeviceExtensionSupported(gpu(), nullptr, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1296
1297 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1298 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1299 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1300 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1301 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1302 return;
1303 }
1304
1305 auto fsr_properties = LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>();
1306
1307 auto phys_dev_props_2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fsr_properties);
1308 vk::GetPhysicalDeviceProperties2(gpu(), &phys_dev_props_2);
1309
1310 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1312
1313 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
1314 ASSERT_TRUE(depthStencilFormat != 0);
1315
1316 VkImageObj image(m_device);
1317 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1318 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1319 image_create_info.format = depthStencilFormat;
1320 image_create_info.extent = {64, 64, 1};
1321 image_create_info.mipLevels = 1;
1322 image_create_info.arrayLayers = 1;
1323 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1324 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
ziga-lunargd3de6ce2022-03-18 21:14:57 +01001325 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR;
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001326 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1327
1328 image.Init(image_create_info);
1329 ASSERT_TRUE(image.initialized());
1330
1331 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1332 nullptr,
1333 0,
1334 image.handle(),
1335 VK_IMAGE_VIEW_TYPE_2D,
1336 depthStencilFormat,
1337 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1338 VK_COMPONENT_SWIZZLE_IDENTITY},
1339 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1340
1341 vk_testing::ImageView depth_image_view;
1342 depth_image_view.init(*m_device, ivci);
1343
1344 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1345 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1346
1347 if (shading_rate) {
1348 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-imageView-06183");
1349 VkRenderingFragmentShadingRateAttachmentInfoKHR fragment_shading_rate =
1350 LvlInitStruct<VkRenderingFragmentShadingRateAttachmentInfoKHR>();
1351 fragment_shading_rate.imageView = depth_image_view.handle();
1352 fragment_shading_rate.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
1353 fragment_shading_rate.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize;
1354
1355 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_shading_rate);
ziga-lunargaa97cbb2022-03-18 19:06:35 +01001356 begin_rendering_info.layerCount = 1;
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001357 begin_rendering_info.colorAttachmentCount = 1;
1358 begin_rendering_info.pColorAttachments = &color_attachment;
1359
1360 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
1361
1362 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1363 pipeline_rendering_info.colorAttachmentCount = 1;
1364 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
1365
1366 CreatePipelineHelper pipe(*this);
1367 pipe.InitInfo();
1368 pipe.gp_ci_.pNext = &pipeline_rendering_info;
1369 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
1370 pipe.InitState();
1371 pipe.CreateGraphicsPipeline();
1372
1373 m_commandBuffer->begin();
1374 m_commandBuffer->BeginRendering(begin_rendering_info);
1375 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
1376 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
1377 m_commandBuffer->EndRendering();
1378 m_commandBuffer->end();
1379
1380 m_errorMonitor->VerifyFound();
1381 }
1382
1383 if (fragment_density) {
1384 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-imageView-06184");
1385 VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map =
1386 LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>();
1387 fragment_density_map.imageView = depth_image_view.handle();
1388
1389 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_density_map);
ziga-lunargaa97cbb2022-03-18 19:06:35 +01001390 begin_rendering_info.layerCount = 1;
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001391 begin_rendering_info.colorAttachmentCount = 1;
1392 begin_rendering_info.pColorAttachments = &color_attachment;
1393
1394 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
1395
1396 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1397 pipeline_rendering_info.colorAttachmentCount = 1;
1398 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
1399
1400 CreatePipelineHelper pipe(*this);
1401 pipe.InitInfo();
1402 pipe.gp_ci_.pNext = &pipeline_rendering_info;
1403 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
1404 pipe.InitState();
1405 pipe.CreateGraphicsPipeline();
1406
1407 m_commandBuffer->begin();
1408 m_commandBuffer->BeginRendering(begin_rendering_info);
1409 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
1410 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
1411 m_commandBuffer->EndRendering();
1412 m_commandBuffer->end();
1413
1414 m_errorMonitor->VerifyFound();
1415 }
1416}
ziga-lunargbc6d8ad2022-03-18 13:04:20 +01001417
ziga-lunarg2c9067e2022-03-18 18:33:52 +01001418TEST_F(VkLayerTest, DynamicRenderingLayerCount) {
1419 TEST_DESCRIPTION("Test dynamic rendering with viewMask 0 and invalid layer count.");
1420
1421 SetTargetApiVersion(VK_API_VERSION_1_1);
1422 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1423
1424 ASSERT_NO_FATAL_FAILURE(InitFramework());
1425
1426 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001427 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunarg2c9067e2022-03-18 18:33:52 +01001428 }
1429
1430 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1431 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1432 return;
1433 }
1434
1435 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1436 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1437 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1438 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1439 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1440 return;
1441 }
1442
1443 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1444
1445 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1446
1447 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-viewMask-06069");
1448 m_commandBuffer->begin();
1449 m_commandBuffer->BeginRendering(begin_rendering_info);
1450 m_commandBuffer->end();
1451 m_errorMonitor->VerifyFound();
1452}
1453
ziga-lunargbc6d8ad2022-03-18 13:04:20 +01001454TEST_F(VkLayerTest, TestRenderingInfoMismatchedSamples) {
1455 TEST_DESCRIPTION("Test beginning rendering with mismatched sample counts.");
1456
1457 SetTargetApiVersion(VK_API_VERSION_1_1);
1458 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1459
1460 ASSERT_NO_FATAL_FAILURE(InitFramework());
1461
1462 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001463 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunargbc6d8ad2022-03-18 13:04:20 +01001464 }
1465
1466 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1467 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1468 return;
1469 }
1470
1471 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1472 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1473 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1474 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1475 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1476 return;
1477 }
1478
1479 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1480
1481 VkImageCreateInfo image_ci = LvlInitStruct<VkImageCreateInfo>();
1482 image_ci.imageType = VK_IMAGE_TYPE_2D;
1483 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
1484 image_ci.extent.width = 64;
1485 image_ci.extent.height = 64;
1486 image_ci.extent.depth = 1;
1487 image_ci.mipLevels = 1;
1488 image_ci.arrayLayers = 1;
1489 image_ci.samples = VK_SAMPLE_COUNT_2_BIT;
1490 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
1491 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1492
1493 VkImageObj color_image(m_device);
1494 color_image.init(&image_ci);
1495
1496 VkImageViewCreateInfo civ_ci = LvlInitStruct<VkImageViewCreateInfo>();
1497 civ_ci.image = color_image.handle();
1498 civ_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1499 civ_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
1500 civ_ci.subresourceRange.layerCount = 1;
1501 civ_ci.subresourceRange.baseMipLevel = 0;
1502 civ_ci.subresourceRange.levelCount = 1;
1503 civ_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1504
1505 vk_testing::ImageView color_image_view;
1506 color_image_view.init(*m_device, civ_ci);
1507
1508 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1509 color_attachment.imageView = color_image_view.handle();
1510 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1511 color_attachment.resolveMode = VK_RESOLVE_MODE_NONE;
1512
1513 const VkFormat depth_format = FindSupportedDepthOnlyFormat(gpu());
1514 if (depth_format == VK_FORMAT_UNDEFINED) {
1515 printf("%s requires a depth only format, skipping.\n", kSkipPrefix);
1516 return;
1517 }
1518
1519 VkImageObj depth_image(m_device);
1520 depth_image.Init(64, 64, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
1521
1522 VkImageViewCreateInfo div_ci = LvlInitStruct<VkImageViewCreateInfo>();
1523 div_ci.image = depth_image.handle();
1524 div_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1525 div_ci.format = depth_format;
1526 div_ci.subresourceRange.layerCount = 1;
1527 div_ci.subresourceRange.baseMipLevel = 0;
1528 div_ci.subresourceRange.levelCount = 1;
1529 div_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1530
1531 vk_testing::ImageView depth_image_view;
1532 depth_image_view.init(*m_device, div_ci);
1533
1534 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1535 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
1536 depth_attachment.imageView = depth_image_view.handle();
1537 depth_attachment.resolveMode = VK_RESOLVE_MODE_NONE;
1538
1539 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
ziga-lunargaa97cbb2022-03-18 19:06:35 +01001540 begin_rendering_info.layerCount = 1;
ziga-lunargbc6d8ad2022-03-18 13:04:20 +01001541 begin_rendering_info.colorAttachmentCount = 1;
1542 begin_rendering_info.pColorAttachments = &color_attachment;
1543 begin_rendering_info.pDepthAttachment = &depth_attachment;
1544
1545 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06070");
1546 m_commandBuffer->BeginRendering(begin_rendering_info);
1547 m_errorMonitor->VerifyFound();
1548}
ziga-lunargec0ac1c2022-03-18 19:25:17 +01001549
ziga-lunargb7fec142022-03-18 22:08:17 +01001550TEST_F(VkLayerTest, TestBeginRenderingFragmentShadingRate) {
1551 TEST_DESCRIPTION("Test BeginRenderingInfo with FragmentShadingRateAttachment.");
1552
1553 SetTargetApiVersion(VK_API_VERSION_1_1);
1554 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1555 AddRequiredExtensions(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1556
1557 ASSERT_NO_FATAL_FAILURE(InitFramework());
1558
1559 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001560 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunargb7fec142022-03-18 22:08:17 +01001561 }
1562
1563 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +09001564 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
ziga-lunargb7fec142022-03-18 22:08:17 +01001565 }
1566
1567 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1568 auto features11 = LvlInitStruct<VkPhysicalDeviceVulkan11Features>(&dynamic_rendering_features);
1569 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&features11);
1570 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1571
1572 if (features11.multiview == VK_FALSE) {
1573 printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix);
1574 return;
1575 }
1576 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1577 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1578 return;
1579 }
1580
1581 auto fsr_properties = LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>();
1582
1583 auto phys_dev_props_2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fsr_properties);
1584 vk::GetPhysicalDeviceProperties2(gpu(), &phys_dev_props_2);
1585
1586 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1588
1589 auto image_ci = LvlInitStruct<VkImageCreateInfo>(nullptr);
1590 image_ci.imageType = VK_IMAGE_TYPE_2D;
1591 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
1592 image_ci.extent.width = 32;
1593 image_ci.extent.height = 32;
1594 image_ci.extent.depth = 1;
1595 image_ci.mipLevels = 1;
1596 image_ci.arrayLayers = 2;
1597 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
1598 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
ziga-lunarg6f7647f2022-04-18 20:10:04 +02001599 image_ci.usage = VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR;
ziga-lunargb7fec142022-03-18 22:08:17 +01001600
1601 VkImageObj image(m_device);
1602 image.init(&image_ci);
1603 VkImageView image_view = image.targetView(VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 2);
1604
1605 VkRenderingFragmentShadingRateAttachmentInfoKHR fragment_shading_rate =
1606 LvlInitStruct<VkRenderingFragmentShadingRateAttachmentInfoKHR>();
1607 fragment_shading_rate.imageView = image_view;
1608 fragment_shading_rate.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
1609 fragment_shading_rate.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize;
1610
1611 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_shading_rate);
1612 begin_rendering_info.layerCount = 4;
1613
1614 m_commandBuffer->begin();
1615
1616 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06123");
1617 m_commandBuffer->BeginRendering(begin_rendering_info);
1618 m_errorMonitor->VerifyFound();
1619
1620 begin_rendering_info.viewMask = 0xF;
1621 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06124");
1622 m_commandBuffer->BeginRendering(begin_rendering_info);
1623 m_errorMonitor->VerifyFound();
1624
1625 m_commandBuffer->end();
ziga-lunargb7fec142022-03-18 22:08:17 +01001626}
1627
ziga-lunarg7e7138c2022-03-18 19:02:31 +01001628TEST_F(VkLayerTest, TestDeviceGroupRenderPassBeginInfo) {
1629 TEST_DESCRIPTION("Test render area of DeviceGroupRenderPassBeginInfo.");
1630
1631 SetTargetApiVersion(VK_API_VERSION_1_1);
1632 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1633
1634 ASSERT_NO_FATAL_FAILURE(InitFramework());
1635
1636 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001637 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunarg7e7138c2022-03-18 19:02:31 +01001638 }
1639
1640 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1641 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1642 return;
1643 }
1644
1645 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1646 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1647 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1648 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1649 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1650 return;
1651 }
1652
1653 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1654
1655 VkRect2D render_area = {};
1656 render_area.offset.x = 0;
1657 render_area.offset.y = 0;
1658 render_area.extent.width = 32;
1659 render_area.extent.height = 32;
1660
1661 auto device_group_render_pass_begin_info = LvlInitStruct<VkDeviceGroupRenderPassBeginInfo>();
1662 device_group_render_pass_begin_info.deviceRenderAreaCount = 1;
1663 device_group_render_pass_begin_info.pDeviceRenderAreas = &render_area;
1664
1665 VkImageObj colorImage(m_device);
1666 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
1667 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT);
1668
1669 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1670 color_attachment.imageView = colorImageView;
1671 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1672
1673 auto begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&device_group_render_pass_begin_info);
ziga-lunarg1fec6332022-03-20 14:39:54 +01001674 begin_rendering_info.layerCount = 1;
ziga-lunarg7e7138c2022-03-18 19:02:31 +01001675 begin_rendering_info.colorAttachmentCount = 1;
1676 begin_rendering_info.pColorAttachments = &color_attachment;
1677
1678 m_commandBuffer->begin();
1679
1680 m_errorMonitor->ExpectSuccess();
1681 m_commandBuffer->BeginRendering(begin_rendering_info);
1682 m_errorMonitor->VerifyNotFound();
1683
1684 render_area.offset.x = 1;
1685 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06083");
1686 m_commandBuffer->BeginRendering(begin_rendering_info);
1687 m_errorMonitor->VerifyFound();
1688
1689 render_area.offset.x = 0;
1690 render_area.offset.y = 16;
1691 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06084");
1692 m_commandBuffer->BeginRendering(begin_rendering_info);
1693 m_errorMonitor->VerifyFound();
1694
1695 m_commandBuffer->end();
1696}
1697
ziga-lunarg184a20b2022-03-18 20:54:48 +01001698TEST_F(VkLayerTest, TestBeginRenderingInvalidFragmentShadingRateImage) {
1699 TEST_DESCRIPTION("Test BeginRendering with FragmentShadingRateAttachmentInfo with missing image usage bit.");
1700
1701 SetTargetApiVersion(VK_API_VERSION_1_1);
1702 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1703 AddRequiredExtensions(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1704
1705 ASSERT_NO_FATAL_FAILURE(InitFramework());
1706
1707 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001708 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunarg184a20b2022-03-18 20:54:48 +01001709 }
1710
1711 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +09001712 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
ziga-lunarg184a20b2022-03-18 20:54:48 +01001713 }
1714
1715 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1716 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1717 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1718 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1719 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1720 return;
1721 }
1722 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1723
1724 auto fsr_properties = LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>();
1725 auto properties2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fsr_properties);
1726 vk::GetPhysicalDeviceProperties2(gpu(), &properties2);
1727
1728 VkImageObj image(m_device);
ziga-lunargd3de6ce2022-03-18 21:14:57 +01001729 image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT,
1730 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR);
ziga-lunarg184a20b2022-03-18 20:54:48 +01001731 VkImageView image_view = image.targetView(VK_FORMAT_R8G8B8A8_UINT);
1732
ziga-lunargd3de6ce2022-03-18 21:14:57 +01001733 VkImageObj invalid_image(m_device);
1734 invalid_image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
1735 VkImageView invalid_image_view = invalid_image.targetView(VK_FORMAT_R8G8B8A8_UINT);
1736
ziga-lunarg184a20b2022-03-18 20:54:48 +01001737 auto fragment_shading_rate = LvlInitStruct<VkRenderingFragmentShadingRateAttachmentInfoKHR>();
ziga-lunargd3de6ce2022-03-18 21:14:57 +01001738 fragment_shading_rate.imageView = invalid_image_view;
ziga-lunarg184a20b2022-03-18 20:54:48 +01001739 fragment_shading_rate.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
1740 fragment_shading_rate.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize;
1741
1742 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_shading_rate);
ziga-lunargd3de6ce2022-03-18 21:14:57 +01001743 begin_rendering_info.layerCount = 1;
1744
1745 m_commandBuffer->begin();
ziga-lunarg184a20b2022-03-18 20:54:48 +01001746
1747 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06148");
ziga-lunarg184a20b2022-03-18 20:54:48 +01001748 m_commandBuffer->BeginRendering(begin_rendering_info);
ziga-lunarg184a20b2022-03-18 20:54:48 +01001749 m_errorMonitor->VerifyFound();
ziga-lunargd3de6ce2022-03-18 21:14:57 +01001750 fragment_shading_rate.imageView = image_view;
1751
1752 fragment_shading_rate.shadingRateAttachmentTexelSize.width = fsr_properties.minFragmentShadingRateAttachmentTexelSize.width + 1;
1753 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06149");
1754 if (fragment_shading_rate.shadingRateAttachmentTexelSize.width >
1755 fsr_properties.minFragmentShadingRateAttachmentTexelSize.width) {
1756 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06150");
1757 }
1758 m_commandBuffer->BeginRendering(begin_rendering_info);
1759 m_errorMonitor->VerifyFound();
1760
1761 if (fsr_properties.minFragmentShadingRateAttachmentTexelSize.width > 1) {
1762 fragment_shading_rate.shadingRateAttachmentTexelSize.width =
1763 fsr_properties.minFragmentShadingRateAttachmentTexelSize.width / 2;
1764 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06151");
1765 if (fragment_shading_rate.shadingRateAttachmentTexelSize.height /
1766 fragment_shading_rate.shadingRateAttachmentTexelSize.width >=
1767 fsr_properties.maxFragmentShadingRateAttachmentTexelSizeAspectRatio) {
1768 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06156");
1769 }
1770 m_commandBuffer->BeginRendering(begin_rendering_info);
1771 m_errorMonitor->VerifyFound();
1772 }
1773
1774 fragment_shading_rate.shadingRateAttachmentTexelSize.width = fsr_properties.minFragmentShadingRateAttachmentTexelSize.width;
1775
1776 fragment_shading_rate.shadingRateAttachmentTexelSize.height =
1777 fsr_properties.minFragmentShadingRateAttachmentTexelSize.height + 1;
1778 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06152");
1779 if (fragment_shading_rate.shadingRateAttachmentTexelSize.height >
1780 fsr_properties.minFragmentShadingRateAttachmentTexelSize.height) {
1781 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06153");
1782 }
1783 m_commandBuffer->BeginRendering(begin_rendering_info);
1784 m_errorMonitor->VerifyFound();
1785
1786 if (fsr_properties.minFragmentShadingRateAttachmentTexelSize.height > 1) {
1787 fragment_shading_rate.shadingRateAttachmentTexelSize.height =
1788 fsr_properties.minFragmentShadingRateAttachmentTexelSize.height / 2;
1789 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06154");
1790 if (fragment_shading_rate.shadingRateAttachmentTexelSize.width /
1791 fragment_shading_rate.shadingRateAttachmentTexelSize.height >
1792 fsr_properties.maxFragmentShadingRateAttachmentTexelSizeAspectRatio) {
1793 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06155");
1794 }
1795 m_commandBuffer->BeginRendering(begin_rendering_info);
1796 m_errorMonitor->VerifyFound();
1797 }
1798
1799 m_commandBuffer->end();
ziga-lunarg184a20b2022-03-18 20:54:48 +01001800}
1801
ziga-lunargec0ac1c2022-03-18 19:25:17 +01001802TEST_F(VkLayerTest, BeginRenderingInvalidDepthAttachmentFormat) {
1803 TEST_DESCRIPTION("Test begin rendering with a depth attachment that has an invalid format");
1804
1805 SetTargetApiVersion(VK_API_VERSION_1_3);
1806 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1807
1808 ASSERT_NO_FATAL_FAILURE(InitFramework());
1809
1810 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001811 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunargec0ac1c2022-03-18 19:25:17 +01001812 }
1813
1814 if (!AreRequestedExtensionsEnabled()) {
sjfrickec935ec72022-05-19 15:26:10 +09001815 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
ziga-lunargec0ac1c2022-03-18 19:25:17 +01001816 }
1817
1818 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1819 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1820 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1821 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1822 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1823 return;
1824 }
1825
1826 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1827
1828 VkFormat stencil_format = FindSupportedStencilOnlyFormat(gpu());
1829 if (stencil_format == VK_FORMAT_UNDEFINED) {
1830 printf("%s requires a stencil only format format.\n", kSkipPrefix);
1831 return;
1832 }
1833
1834 VkImageObj image(m_device);
1835 image.Init(32, 32, 1, stencil_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
1836 VkImageView image_view = image.targetView(stencil_format, VK_IMAGE_ASPECT_STENCIL_BIT);
1837
1838 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1839 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
1840 depth_attachment.imageView = image_view;
1841
1842 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
ziga-lunarg1fec6332022-03-20 14:39:54 +01001843 begin_rendering_info.layerCount = 1;
ziga-lunargec0ac1c2022-03-18 19:25:17 +01001844 begin_rendering_info.pDepthAttachment = &depth_attachment;
1845
1846 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pDepthAttachment-06547");
1847 m_commandBuffer->BeginRendering(begin_rendering_info);
1848 m_errorMonitor->VerifyFound();
1849}
ziga-lunarg4b5bb5b2022-03-20 00:49:04 +01001850
ziga-lunarg14a69782022-03-20 00:39:31 +01001851TEST_F(VkLayerTest, TestFragmentDensityMapRenderArea) {
1852 TEST_DESCRIPTION("Validate VkRenderingFragmentDensityMapAttachmentInfo attachment image view extent.");
1853
1854 SetTargetApiVersion(VK_API_VERSION_1_1);
1855 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1856 AddRequiredExtensions(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1857
1858 ASSERT_NO_FATAL_FAILURE(InitFramework());
1859
1860 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001861 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
ziga-lunarg14a69782022-03-20 00:39:31 +01001862 }
1863
1864 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1865 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1866 return;
1867 }
1868
1869 if (!DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME)) {
1870 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1871 return;
1872 }
1873
1874 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1875 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1876 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1877 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1878 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1879 return;
1880 }
1881
1882 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1883
1884 auto fdm_props = LvlInitStruct<VkPhysicalDeviceFragmentDensityMapPropertiesEXT>();
1885 auto props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fdm_props);
1886 vk::GetPhysicalDeviceProperties2(gpu(), &props2);
1887
1888 VkImageObj image(m_device);
1889 image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
1890 VkImageView image_view = image.targetView(VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1);
1891
1892 auto fragment_density_map = LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>();
1893 fragment_density_map.imageView = image_view;
1894 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_density_map);
1895 begin_rendering_info.layerCount = 1;
1896 begin_rendering_info.renderArea.extent.width = 64 * fdm_props.maxFragmentDensityTexelSize.width;
1897 begin_rendering_info.renderArea.extent.height = 32 * fdm_props.maxFragmentDensityTexelSize.height;
1898
1899 m_commandBuffer->begin();
1900
1901 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06112");
1902 m_commandBuffer->BeginRendering(begin_rendering_info);
1903 m_errorMonitor->VerifyFound();
1904
1905 begin_rendering_info.renderArea.extent.width = 32 * fdm_props.maxFragmentDensityTexelSize.width;
1906 begin_rendering_info.renderArea.extent.height = 64 * fdm_props.maxFragmentDensityTexelSize.height;
1907
1908 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06114");
1909 m_commandBuffer->BeginRendering(begin_rendering_info);
1910 m_errorMonitor->VerifyFound();
1911
1912 VkRect2D device_render_area = {};
1913 device_render_area.extent.width = 64 * fdm_props.maxFragmentDensityTexelSize.width;
1914 device_render_area.extent.height = 32 * fdm_props.maxFragmentDensityTexelSize.height;
1915 auto device_group_render_pass_begin_info = LvlInitStruct<VkDeviceGroupRenderPassBeginInfo>();
1916 device_group_render_pass_begin_info.deviceRenderAreaCount = 1;
1917 device_group_render_pass_begin_info.pDeviceRenderAreas = &device_render_area;
1918 fragment_density_map.pNext = &device_group_render_pass_begin_info;
1919
1920 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06113");
1921 m_commandBuffer->BeginRendering(begin_rendering_info);
1922 m_errorMonitor->VerifyFound();
1923
1924 device_render_area.extent.width = 32 * fdm_props.maxFragmentDensityTexelSize.width;
1925 device_render_area.extent.height = 64 * fdm_props.maxFragmentDensityTexelSize.height;
1926
1927 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06115");
1928 m_commandBuffer->BeginRendering(begin_rendering_info);
1929 m_errorMonitor->VerifyFound();
1930
1931 m_commandBuffer->end();
1932}
1933
ziga-lunarge7279ba2022-03-31 20:55:27 +02001934TEST_F(VkLayerTest, TestBarrierWithDynamicRendering) {
1935 TEST_DESCRIPTION("Test setting buffer memory barrier when dynamic rendering is active.");
1936
1937 SetTargetApiVersion(VK_API_VERSION_1_3);
1938
1939 ASSERT_NO_FATAL_FAILURE(InitFramework());
1940
1941 if (DeviceValidationVersion() < VK_API_VERSION_1_3) {
sjfrickebdd58dd2022-05-20 14:22:50 +09001942 GTEST_SKIP() << "At least Vulkan version 1.3 is required";
ziga-lunarge7279ba2022-03-31 20:55:27 +02001943 }
1944
1945 auto vk13features = LvlInitStruct<VkPhysicalDeviceVulkan13Features>();
1946 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&vk13features);
1947 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1948 if (!vk13features.dynamicRendering) {
1949 printf("%s Test requires (unsupported) dynamicRendering, skipping\n", kSkipPrefix);
1950 return;
1951 }
1952 if (!vk13features.synchronization2) {
1953 printf("%s Test requires (unsupported) synchronization2, skipping\n", kSkipPrefix);
1954 return;
1955 }
1956
1957 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1959
1960 PFN_vkCmdBeginRendering vkCmdBeginRendering =
1961 reinterpret_cast<PFN_vkCmdBeginRendering>(vk::GetDeviceProcAddr(m_device->device(), "vkCmdBeginRendering"));
1962 assert(vkCmdBeginRendering != nullptr);
1963 PFN_vkCmdEndRendering vkCmdEndRendering =
1964 reinterpret_cast<PFN_vkCmdEndRendering>(vk::GetDeviceProcAddr(m_device->device(), "vkCmdEndRendering"));
1965 assert(vkCmdEndRendering != nullptr);
1966
1967 m_commandBuffer->begin();
1968
1969 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1970 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}, 0, 1};
1971 begin_rendering_info.renderArea = clear_rect.rect;
1972 begin_rendering_info.layerCount = 1;
1973
1974 vkCmdBeginRendering(m_commandBuffer->handle(), &begin_rendering_info);
1975
1976 VkBufferObj buffer;
1977 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1978 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
1979
1980 auto buf_barrier = lvl_init_struct<VkBufferMemoryBarrier2KHR>();
1981 buf_barrier.buffer = buffer.handle();
1982 buf_barrier.offset = 0;
1983 buf_barrier.size = VK_WHOLE_SIZE;
1984 buf_barrier.srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1985 buf_barrier.dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
1986
1987 auto dependency_info = lvl_init_struct<VkDependencyInfoKHR>();
1988 dependency_info.bufferMemoryBarrierCount = 1;
1989 dependency_info.pBufferMemoryBarriers = &buf_barrier;
1990 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdPipelineBarrier2-None-06191");
1991 vk::CmdPipelineBarrier2(m_commandBuffer->handle(), &dependency_info);
1992 m_errorMonitor->VerifyFound();
1993
1994 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdPipelineBarrier-None-06191");
1995 vk::CmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0,
1996 nullptr, 0, nullptr, 0, nullptr);
1997 m_errorMonitor->VerifyFound();
1998
1999 vkCmdEndRendering(m_commandBuffer->handle());
2000 m_commandBuffer->end();
2001}
2002
ziga-lunargce90b522022-04-27 23:59:46 +02002003TEST_F(VkLayerTest, UseStencilAttachmentWithIntegerFormat) {
2004 TEST_DESCRIPTION("Use stencil attachment with integer format");
2005
2006 m_errorMonitor->ExpectSuccess();
2007
2008 SetTargetApiVersion(VK_API_VERSION_1_1);
2009 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2010 ASSERT_NO_FATAL_FAILURE(InitFramework());
2011
2012 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
ziga-lunarg5e0a2452022-04-20 19:29:37 +02002013 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2014 return;
ziga-lunargce90b522022-04-27 23:59:46 +02002015 }
2016 if (!AreRequestedExtensionsEnabled()) {
ziga-lunarg5e0a2452022-04-20 19:29:37 +02002017 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2018 return;
ziga-lunargce90b522022-04-27 23:59:46 +02002019 }
2020
2021 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
2022 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2023 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2024 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2025 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2026 return;
2027 }
2028
2029 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2031
2032 if (ImageFormatIsSupported(gpu(), VK_FORMAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
2033 printf("%s VK_FORMAT_S8_UINT format not supported, skipping test.\n", kSkipPrefix);
2034 return;
2035 }
2036
2037 auto depth_stencil_resolve_properties = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
2038 auto properties2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&depth_stencil_resolve_properties);
2039 vk::GetPhysicalDeviceProperties2(gpu(), &properties2);
2040 if (depth_stencil_resolve_properties.supportedStencilResolveModes & VK_RESOLVE_MODE_AVERAGE_BIT) {
2041 printf("%s VK_RESOLVE_MODE_AVERAGE_BIT not supported for VK_FORMAT_S8_UINT, skipping test.\n", kSkipPrefix);
2042 return;
2043 }
2044
2045 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
2046 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2047 image_create_info.format = VK_FORMAT_S8_UINT;
2048 image_create_info.extent = {32, 32, 1};
2049 image_create_info.mipLevels = 1;
2050 image_create_info.arrayLayers = 1;
2051 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
2052 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2053 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2054 VkImageObj image(m_device);
2055 image.Init(image_create_info);
2056 VkImageView image_view = image.targetView(VK_FORMAT_S8_UINT, VK_IMAGE_ASPECT_STENCIL_BIT);
2057
2058 VkRenderingAttachmentInfoKHR stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2059 stencil_attachment.imageView = image_view;
2060 stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2061 stencil_attachment.resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
2062 stencil_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_GENERAL;
2063
2064 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
2065 begin_rendering_info.pStencilAttachment = &stencil_attachment;
2066 begin_rendering_info.layerCount = 1;
2067
2068 m_commandBuffer->begin();
2069
2070 m_errorMonitor->VerifyNotFound();
2071
ziga-lunarg5e0a2452022-04-20 19:29:37 +02002072 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06131");
ziga-lunargce90b522022-04-27 23:59:46 +02002073 m_commandBuffer->BeginRendering(begin_rendering_info);
2074 m_errorMonitor->VerifyFound();
2075
2076 m_commandBuffer->end();
2077}
ziga-lunarg5e0a2452022-04-20 19:29:37 +02002078
2079TEST_F(VkLayerTest, BeginRenderingInvalidStencilAttachmentFormat) {
2080 TEST_DESCRIPTION("Test begin rendering with a stencil attachment that has an invalid format");
2081
2082 SetTargetApiVersion(VK_API_VERSION_1_3);
2083 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2084
2085 ASSERT_NO_FATAL_FAILURE(InitFramework());
2086
2087 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2088 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
2089 }
2090
2091 if (!AreRequestedExtensionsEnabled()) {
2092 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
2093 }
2094
2095 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2096 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2097 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2098 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2099 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2100 return;
2101 }
2102
2103 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2104
2105 VkFormat depth_format = FindSupportedDepthOnlyFormat(gpu());
2106 if (depth_format == VK_FORMAT_UNDEFINED) {
2107 printf("%s requires a stencil only format format.\n", kSkipPrefix);
2108 return;
2109 }
2110
2111 VkImageObj image(m_device);
2112 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
2113 VkImageView image_view = image.targetView(depth_format, VK_IMAGE_ASPECT_DEPTH_BIT);
2114
2115 VkRenderingAttachmentInfoKHR stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2116 stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL;
2117 stencil_attachment.imageView = image_view;
2118
2119 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
2120 begin_rendering_info.layerCount = 1;
2121 begin_rendering_info.pStencilAttachment = &stencil_attachment;
2122
2123 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pStencilAttachment-06548");
2124 m_commandBuffer->BeginRendering(begin_rendering_info);
2125 m_errorMonitor->VerifyFound();
2126}
2127
2128TEST_F(VkLayerTest, TestInheritanceRenderingInfoStencilAttachmentFormat) {
2129 TEST_DESCRIPTION("Test begin rendering with a stencil attachment that has an invalid format");
2130
2131 SetTargetApiVersion(VK_API_VERSION_1_3);
2132 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2133
2134 ASSERT_NO_FATAL_FAILURE(InitFramework());
2135
2136 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2137 GTEST_SKIP() << "At least Vulkan version 1.1 is required";
2138 }
2139
2140 if (!AreRequestedExtensionsEnabled()) {
2141 GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported";
2142 }
2143
2144 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2145 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2146 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2147 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2148 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2149 return;
2150 }
2151
2152 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2153
2154 VkFormat depth_format = FindSupportedDepthOnlyFormat(gpu());
2155 if (depth_format == VK_FORMAT_UNDEFINED) {
2156 printf("%s requires a stencil only format format.\n", kSkipPrefix);
2157 return;
2158 }
2159
2160 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
2161
2162 auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
2163 cmd_buffer_inheritance_rendering_info.colorAttachmentCount = 1;
2164 cmd_buffer_inheritance_rendering_info.pColorAttachmentFormats = &color_format;
2165 cmd_buffer_inheritance_rendering_info.depthAttachmentFormat = depth_format;
2166 cmd_buffer_inheritance_rendering_info.stencilAttachmentFormat = depth_format;
2167 cmd_buffer_inheritance_rendering_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
2168
2169 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
2170 cmd_buffer_inheritance_info.pNext = &cmd_buffer_inheritance_rendering_info;
2171 cmd_buffer_inheritance_info.renderPass = VK_NULL_HANDLE;
2172
2173 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
2174 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
2175 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
2176
2177 auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
2178 cmd_buffer_allocate_info.commandPool = m_commandPool->handle();
2179 cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
2180 cmd_buffer_allocate_info.commandBufferCount = 1;
2181
2182 VkCommandBuffer secondary_cmd_buffer;
2183 VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer);
2184
2185 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-stencilAttachmentFormat-06541");
2186 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
2187 m_errorMonitor->VerifyFound();
2188}
ziga-lunargeb4a69c2022-04-20 21:52:00 +02002189
2190TEST_F(VkLayerTest, CreateGraphicsPipelineWithInvalidAttachmentSampleCount) {
2191 TEST_DESCRIPTION("Create pipeline with fragment shader that uses samples, but multisample state not begin set");
2192
2193 SetTargetApiVersion(VK_API_VERSION_1_3);
2194 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2195 AddRequiredExtensions(VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME);
2196
2197 ASSERT_NO_FATAL_FAILURE(InitFramework());
2198
2199 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2200 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2201 return;
2202 }
2203
2204 if (!AreRequestedExtensionsEnabled()) {
2205 printf("%s Extension %s or %s not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
2206 VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME);
2207 return;
2208 }
2209
2210 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2211 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2212 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2213 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2214 printf("%s Test requires (unsupported) dynamicRendering, skipping\n", kSkipPrefix);
2215 return;
2216 }
2217
2218 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2219 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
2220
2221 auto sample_count_info_amd = LvlInitStruct<VkAttachmentSampleCountInfoNV>();
2222 sample_count_info_amd.colorAttachmentCount = 1;
2223 sample_count_info_amd.depthStencilAttachmentSamples = static_cast<VkSampleCountFlagBits>(0x00000400);
2224
2225 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(&sample_count_info_amd);
2226 pipeline_rendering_info.colorAttachmentCount = 1;
2227 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
2228
2229 CreatePipelineHelper pipe(*this);
2230 pipe.InitInfo();
2231 pipe.gp_ci_.pNext = &pipeline_rendering_info;
2232 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
2233 pipe.InitState();
2234
2235 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-depthStencilAttachmentSamples-06593");
2236 pipe.CreateGraphicsPipeline();
2237 m_errorMonitor->VerifyFound();
2238}
ziga-lunargd680bf22022-04-20 22:01:00 +02002239
2240TEST_F(VkLayerTest, CreatePipelineUsingDynamicRenderingWithoutFeature) {
2241 TEST_DESCRIPTION("Create graphcis pipeline that uses dynamic rendering, but feature is not enabled");
2242
2243 SetTargetApiVersion(VK_API_VERSION_1_3);
2244 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2245 AddRequiredExtensions(VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME);
2246
2247 ASSERT_NO_FATAL_FAILURE(InitFramework());
2248
2249 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2250 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2251 return;
2252 }
2253
2254 if (!AreRequestedExtensionsEnabled()) {
2255 printf("%s Extension %s or %s not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
2256 VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME);
2257 return;
2258 }
2259
2260 ASSERT_NO_FATAL_FAILURE(InitState());
2261
2262 CreatePipelineHelper pipe(*this);
2263 pipe.InitInfo();
2264 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
2265 pipe.InitState();
2266
2267 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-dynamicRendering-06576");
2268 pipe.CreateGraphicsPipeline();
2269 m_errorMonitor->VerifyFound();
2270}
ziga-lunargf20d7952022-04-20 22:11:40 +02002271
2272TEST_F(VkLayerTest, CreateGraphicsPipelineWithMissingMultisampleState) {
2273 TEST_DESCRIPTION("Create pipeline with fragment shader that uses samples, but multisample state not begin set");
2274
2275 SetTargetApiVersion(VK_API_VERSION_1_1);
2276 ASSERT_NO_FATAL_FAILURE(InitFramework());
2277
2278 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2279 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2280 return;
2281 }
2282
2283 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2284 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2285 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2286 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2287 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2288 return;
2289 }
2290
2291 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2292
2293 CreatePipelineHelper pipe(*this);
2294 pipe.InitInfo();
2295 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
2296 pipe.gp_ci_.pMultisampleState = nullptr;
2297 pipe.InitState();
2298
2299 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-pMultisampleState-06630");
2300 pipe.CreateGraphicsPipeline();
2301 m_errorMonitor->VerifyFound();
2302}
ziga-lunarg6ed1dad2022-04-20 23:14:53 +02002303
2304TEST_F(VkLayerTest, DynamicRenderingAreaGreaterThanAttachmentExtent) {
2305 TEST_DESCRIPTION("Begin dynamic rendering with render area greater than extent of attachments");
2306
2307 SetTargetApiVersion(VK_API_VERSION_1_0);
2308 AddRequiredExtensions(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
2309 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2310 ASSERT_NO_FATAL_FAILURE(InitFramework());
2311
2312 if (DeviceValidationVersion() != VK_API_VERSION_1_0) {
2313 printf("%s Tests requires Vulkan 1.0, skipping test\n", kSkipPrefix);
2314 return;
2315 }
2316 if (!AreRequestedExtensionsEnabled()) {
2317 printf("%s Extension %s not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2318 return;
2319 }
2320
ziga-lunarga51287c2022-04-20 23:24:37 +02002321 auto vkGetPhysicalDeviceFeatures2KHR = reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures2KHR>(
2322 vk::GetInstanceProcAddr(instance(), "vkGetPhysicalDeviceFeatures2KHR"));
ziga-lunarg6ed1dad2022-04-20 23:14:53 +02002323 ASSERT_TRUE(vkGetPhysicalDeviceFeatures2KHR != nullptr);
2324
2325 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2326 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2KHR>(&dynamic_rendering_features);
2327 vkGetPhysicalDeviceFeatures2KHR(gpu(), &features2);
2328 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2329 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2330 return;
2331 }
2332
2333 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2334
2335 VkImageObj colorImage(m_device);
2336 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
2337 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT);
2338
ziga-lunarga51287c2022-04-20 23:24:37 +02002339 auto color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
ziga-lunarg6ed1dad2022-04-20 23:14:53 +02002340 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2341 color_attachment.imageView = colorImageView;
2342
ziga-lunarga51287c2022-04-20 23:24:37 +02002343 auto begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
ziga-lunarg6ed1dad2022-04-20 23:14:53 +02002344 begin_rendering_info.layerCount = 1;
2345 begin_rendering_info.colorAttachmentCount = 1;
2346 begin_rendering_info.pColorAttachments = &color_attachment;
2347 begin_rendering_info.renderArea.extent.width = 64;
2348 begin_rendering_info.renderArea.extent.height = 32;
2349
2350 m_commandBuffer->begin();
2351
2352 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06075");
2353 m_commandBuffer->BeginRendering(begin_rendering_info);
2354 m_errorMonitor->VerifyFound();
2355
2356 begin_rendering_info.renderArea.extent.width = 32;
2357 begin_rendering_info.renderArea.extent.height = 64;
2358
2359 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06076");
2360 m_commandBuffer->BeginRendering(begin_rendering_info);
2361 m_errorMonitor->VerifyFound();
2362
2363 const VkFormat ds_format = FindSupportedDepthStencilFormat(gpu());
2364 if (ds_format != VK_FORMAT_UNDEFINED) {
2365 VkImageObj depthImage(m_device);
2366 depthImage.Init(32, 32, 1, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
2367 VkImageView depthImageView = depthImage.targetView(ds_format, VK_IMAGE_ASPECT_DEPTH_BIT);
2368
2369 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2370 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
2371 depth_attachment.imageView = depthImageView;
2372
2373 begin_rendering_info.colorAttachmentCount = 0;
2374 begin_rendering_info.pDepthAttachment = &depth_attachment;
2375
2376 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06076");
2377 m_commandBuffer->BeginRendering(begin_rendering_info);
2378 m_errorMonitor->VerifyFound();
2379 }
2380
2381 m_commandBuffer->end();
2382}
ziga-lunarga51287c2022-04-20 23:24:37 +02002383
2384TEST_F(VkLayerTest, DynamicRenderingDeviceGroupAreaGreaterThanAttachmentExtent) {
2385 TEST_DESCRIPTION("Begin dynamic rendering with device group with render area greater than extent of attachments");
2386
2387 SetTargetApiVersion(VK_API_VERSION_1_1);
2388 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2389 ASSERT_NO_FATAL_FAILURE(InitFramework());
2390
2391 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2392 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2393 return;
2394 }
2395 if (!AreRequestedExtensionsEnabled()) {
2396 printf("%s Extension %s not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2397 return;
2398 }
2399
2400 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2401 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2402 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2403 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2404 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2405 return;
2406 }
2407
2408 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2409
2410 VkImageObj colorImage(m_device);
2411 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
2412 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT);
2413
2414 auto color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2415 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2416 color_attachment.imageView = colorImageView;
2417
2418 auto begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
2419 begin_rendering_info.layerCount = 1;
2420 begin_rendering_info.colorAttachmentCount = 1;
2421 begin_rendering_info.pColorAttachments = &color_attachment;
2422 begin_rendering_info.renderArea.extent.width = 64;
2423 begin_rendering_info.renderArea.extent.height = 32;
2424
2425 m_commandBuffer->begin();
2426
2427 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06079");
2428 m_commandBuffer->BeginRendering(begin_rendering_info);
2429 m_errorMonitor->VerifyFound();
2430
2431 begin_rendering_info.renderArea.extent.width = 32;
2432 begin_rendering_info.renderArea.extent.height = 64;
2433
2434 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06080");
2435 m_commandBuffer->BeginRendering(begin_rendering_info);
2436 m_errorMonitor->VerifyFound();
2437
2438 const VkFormat ds_format = FindSupportedDepthStencilFormat(gpu());
2439 if (ds_format != VK_FORMAT_UNDEFINED) {
2440 VkImageObj depthImage(m_device);
2441 depthImage.Init(32, 32, 1, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
2442 VkImageView depthImageView = depthImage.targetView(ds_format, VK_IMAGE_ASPECT_DEPTH_BIT);
2443
2444 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2445 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
2446 depth_attachment.imageView = depthImageView;
2447
2448 begin_rendering_info.colorAttachmentCount = 0;
2449 begin_rendering_info.pDepthAttachment = &depth_attachment;
2450
2451 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06080");
2452 m_commandBuffer->BeginRendering(begin_rendering_info);
2453 m_errorMonitor->VerifyFound();
2454 }
2455
2456 m_commandBuffer->end();
2457}
ziga-lunargd4105c12022-04-21 13:54:20 +02002458
2459TEST_F(VkLayerTest, SecondaryCommandBufferIncompatibleRenderPass) {
2460 TEST_DESCRIPTION("Execute secondary command buffers within render pass instance with incompatible render pass");
2461
2462 SetTargetApiVersion(VK_API_VERSION_1_1);
2463 ASSERT_NO_FATAL_FAILURE(InitFramework());
2464
2465 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2466 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2467 return;
2468 }
2469
2470 ASSERT_NO_FATAL_FAILURE(InitState());
2471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2472
2473 auto render_pass_ci = LvlInitStruct<VkRenderPassCreateInfo>();
2474
2475 vk_testing::RenderPass render_pass;
2476 render_pass.init(*m_device, render_pass_ci);
2477
2478 VkCommandBufferObj cb(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2479 VkCommandBuffer secondary_handle = cb.handle();
2480
2481 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
2482 cmd_buffer_inheritance_info.renderPass = render_pass.handle();
2483 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
2484 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
2485 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
2486
2487 cb.begin(&cmd_buffer_begin_info);
2488 cb.end();
2489
2490 m_commandBuffer->begin();
2491 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
2492
2493 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdExecuteCommands-pBeginInfo-06020");
2494 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdExecuteCommands-pInheritanceInfo-00098");
2495 vk::CmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_handle);
2496 m_errorMonitor->VerifyFound();
2497
2498 m_commandBuffer->EndRenderPass();
2499 m_commandBuffer->end();
2500}
ziga-lunarg590e0292022-04-21 14:07:22 +02002501
2502TEST_F(VkLayerTest, SecondaryCommandBufferIncompatibleSubpass) {
2503 TEST_DESCRIPTION("Execute secondary command buffers with different subpass");
2504
2505 SetTargetApiVersion(VK_API_VERSION_1_1);
2506 ASSERT_NO_FATAL_FAILURE(InitFramework());
2507
2508 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2509 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2510 return;
2511 }
2512
2513 ASSERT_NO_FATAL_FAILURE(InitState());
2514
2515 VkSubpassDescription subpasses[2] = {};
2516
2517 auto render_pass_ci = LvlInitStruct<VkRenderPassCreateInfo>();
2518 render_pass_ci.subpassCount = 2;
2519 render_pass_ci.pSubpasses = subpasses;
2520
2521 vk_testing::RenderPass render_pass;
2522 render_pass.init(*m_device, render_pass_ci);
2523
2524 auto framebuffer_ci = LvlInitStruct<VkFramebufferCreateInfo>();
2525 framebuffer_ci.renderPass = render_pass.handle();
2526 framebuffer_ci.width = 32;
2527 framebuffer_ci.height = 32;
2528
2529 vk_testing::Framebuffer framebuffer;
2530 framebuffer.init(*m_device, framebuffer_ci);
2531
2532 VkCommandBufferObj cb(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2533 VkCommandBuffer secondary_handle = cb.handle();
2534
2535 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
2536 cmd_buffer_inheritance_info.renderPass = render_pass.handle();
2537 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
2538 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
2539 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
2540
2541 cb.begin(&cmd_buffer_begin_info);
2542 cb.end();
2543
2544 auto render_pass_begin_info = LvlInitStruct<VkRenderPassBeginInfo>();
2545 render_pass_begin_info.renderPass = render_pass.handle();
2546 render_pass_begin_info.renderArea.extent = {32, 32};
2547 render_pass_begin_info.framebuffer = framebuffer.handle();
2548
2549 m_commandBuffer->begin();
2550 m_commandBuffer->BeginRenderPass(render_pass_begin_info, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
2551 vk::CmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
2552
2553 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdExecuteCommands-pCommandBuffers-00097");
2554 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdExecuteCommands-pCommandBuffers-06019");
2555 vk::CmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_handle);
2556 m_errorMonitor->VerifyFound();
2557
2558 m_commandBuffer->EndRenderPass();
2559 m_commandBuffer->end();
2560}
ziga-lunarg343193b2022-04-21 14:15:17 +02002561
2562TEST_F(VkLayerTest, SecondaryCommandBufferInvalidContents) {
2563 TEST_DESCRIPTION("Execute secondary command buffers within active render pass that was not begun with VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS");
2564
2565 SetTargetApiVersion(VK_API_VERSION_1_1);
2566 ASSERT_NO_FATAL_FAILURE(InitFramework());
2567
2568 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2569 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2570 return;
2571 }
2572
2573 ASSERT_NO_FATAL_FAILURE(InitState());
2574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2575
2576 auto render_pass_ci = LvlInitStruct<VkRenderPassCreateInfo>();
2577
2578 VkCommandBufferObj cb(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2579 VkCommandBuffer secondary_handle = cb.handle();
2580
2581 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
2582 cmd_buffer_inheritance_info.renderPass = m_renderPass;
2583 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
2584 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
2585 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
2586
2587 cb.begin(&cmd_buffer_begin_info);
2588 cb.end();
2589
2590 m_commandBuffer->begin();
2591 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
2592
2593 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdExecuteCommands-contents-00095");
2594 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdExecuteCommands-contents-06018");
2595 vk::CmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_handle);
2596 m_errorMonitor->VerifyFound();
2597
2598 m_commandBuffer->EndRenderPass();
2599 m_commandBuffer->end();
2600}
ziga-lunarg9104e0a2022-04-21 16:45:09 +02002601
2602TEST_F(VkLayerTest, BindPipelineWithIncompatibleRenderingInfoDepthFormat) {
2603 TEST_DESCRIPTION("Bind pipeline that has RenderingInfo DepthFormat incompatible with previously used pipeline");
2604
2605 SetTargetApiVersion(VK_API_VERSION_1_1);
2606 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2607 ASSERT_NO_FATAL_FAILURE(InitFramework());
2608
2609 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2610 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2611 return;
2612 }
2613 if (!AreRequestedExtensionsEnabled()) {
2614 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2615 return;
2616 }
2617
2618 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2619 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2620 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2621 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2622 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2623 return;
2624 }
2625
2626 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2628
2629 m_errorMonitor->ExpectSuccess();
2630
2631 std::vector<VkFormat> depth_formats;
2632 const VkFormat ds_formats[] = {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
2633 for (uint32_t i = 0; i < size(ds_formats); ++i) {
2634 VkFormatProperties format_props;
2635 vk::GetPhysicalDeviceFormatProperties(gpu(), ds_formats[i], &format_props);
2636
2637 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
2638 depth_formats.push_back(ds_formats[i]);
2639 }
2640 }
2641
2642 if (depth_formats.size() < 2) {
2643 printf("%s Test requires 2 depth formats, skipping test.\n", kSkipPrefix);
2644 return;
2645 }
2646
2647 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
2648 pipeline_rendering_info.depthAttachmentFormat = depth_formats[0];
2649
2650 auto ds_ci = LvlInitStruct<VkPipelineDepthStencilStateCreateInfo>();
2651
2652 CreatePipelineHelper pipe1(*this);
2653 pipe1.InitInfo();
2654 pipe1.gp_ci_.pNext = &pipeline_rendering_info;
2655 pipe1.gp_ci_.renderPass = VK_NULL_HANDLE;
2656 pipe1.InitState();
2657 pipe1.ds_ci_ = ds_ci;
2658 pipe1.CreateGraphicsPipeline();
2659
2660 pipeline_rendering_info.depthAttachmentFormat = depth_formats[1];
2661
2662 CreatePipelineHelper pipe2(*this);
2663 pipe2.InitInfo();
2664 pipe2.gp_ci_.pNext = &pipeline_rendering_info;
2665 pipe2.gp_ci_.renderPass = VK_NULL_HANDLE;
2666 pipe2.InitState();
2667 pipe2.ds_ci_ = ds_ci;
2668 pipe2.CreateGraphicsPipeline();
2669
2670 VkImageObj image(m_device);
2671 image.Init(32, 32, 1, depth_formats[0], VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0);
2672 VkImageView depth_image_view = image.targetView(depth_formats[0], VK_IMAGE_ASPECT_DEPTH_BIT);
2673
2674 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2675 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
2676 depth_attachment.imageView = depth_image_view;
2677
2678 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
2679 begin_rendering_info.layerCount = 1;
2680 begin_rendering_info.pDepthAttachment = &depth_attachment;
2681
2682 m_commandBuffer->begin();
2683 m_commandBuffer->BeginRendering(begin_rendering_info);
2684
2685 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.pipeline_);
2686 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2687
2688 m_errorMonitor->VerifyNotFound();
2689
2690 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBindPipeline-pipeline-06197");
2691 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.pipeline_);
2692 m_errorMonitor->VerifyFound();
2693
2694 m_commandBuffer->EndRendering();
2695 m_commandBuffer->end();
2696}
ziga-lunarg1ac9b672022-04-21 17:55:28 +02002697
2698TEST_F(VkLayerTest, BindPipelineWithIncompatibleRenderingInfoColorAttachments) {
2699 TEST_DESCRIPTION("Bind pipeline that has RenderingInfo color attachment incompatible with previously used pipeline");
2700
2701 SetTargetApiVersion(VK_API_VERSION_1_1);
2702 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2703 ASSERT_NO_FATAL_FAILURE(InitFramework());
2704
2705 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2706 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2707 return;
2708 }
2709 if (!AreRequestedExtensionsEnabled()) {
2710 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2711 return;
2712 }
2713
2714 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2715 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2716 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2717 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2718 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2719 return;
2720 }
2721
2722 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2724
2725 m_errorMonitor->ExpectSuccess();
2726
2727 VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
2728 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
2729 pipeline_rendering_info.colorAttachmentCount = 1;
2730 pipeline_rendering_info.pColorAttachmentFormats = &format;
2731
2732 CreatePipelineHelper pipe1(*this);
2733 pipe1.InitInfo();
2734 pipe1.gp_ci_.pNext = &pipeline_rendering_info;
2735 pipe1.gp_ci_.renderPass = VK_NULL_HANDLE;
2736 pipe1.InitState();
2737 pipe1.CreateGraphicsPipeline();
2738
2739 format = VK_FORMAT_B8G8R8A8_UNORM;
2740
2741 CreatePipelineHelper pipe2(*this);
2742 pipe2.InitInfo();
2743 pipe2.gp_ci_.pNext = &pipeline_rendering_info;
2744 pipe2.gp_ci_.renderPass = VK_NULL_HANDLE;
2745 pipe2.InitState();
2746 pipe2.CreateGraphicsPipeline();
2747
2748 VkImageObj image(m_device);
2749 image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0);
2750 VkImageView image_view = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2751
2752 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2753 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2754 color_attachment.imageView = image_view;
2755
2756 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
2757 begin_rendering_info.layerCount = 1;
2758 begin_rendering_info.colorAttachmentCount = 1;
2759 begin_rendering_info.pColorAttachments = &color_attachment;
2760
2761 m_commandBuffer->begin();
2762 m_commandBuffer->BeginRendering(begin_rendering_info);
2763
2764 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.pipeline_);
2765 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2766
2767 m_errorMonitor->VerifyNotFound();
2768
2769 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBindPipeline-pipeline-06196");
2770 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.pipeline_);
2771 m_errorMonitor->VerifyFound();
2772
2773 m_commandBuffer->EndRendering();
2774 m_commandBuffer->end();
2775}
ziga-lunargacd79322022-04-21 18:36:34 +02002776
2777TEST_F(VkLayerTest, BindPipelineWithIncompatibleRenderingInfoColorAttachmentCount) {
2778 TEST_DESCRIPTION("Bind pipeline that has RenderingInfo color attachment count incompatible with previously used pipeline");
2779
2780 SetTargetApiVersion(VK_API_VERSION_1_1);
2781 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2782 ASSERT_NO_FATAL_FAILURE(InitFramework());
2783
2784 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2785 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2786 return;
2787 }
2788 if (!AreRequestedExtensionsEnabled()) {
2789 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2790 return;
2791 }
2792
2793 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2794 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2795 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2796 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2797 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2798 return;
2799 }
2800
2801 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2802 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2803
2804 m_errorMonitor->ExpectSuccess();
2805
2806 VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
2807 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
2808 pipeline_rendering_info.colorAttachmentCount = 1;
2809 pipeline_rendering_info.pColorAttachmentFormats = &format;
2810
2811 CreatePipelineHelper pipe1(*this);
2812 pipe1.InitInfo();
2813 pipe1.gp_ci_.pNext = &pipeline_rendering_info;
2814 pipe1.gp_ci_.renderPass = VK_NULL_HANDLE;
2815 pipe1.InitState();
2816 pipe1.CreateGraphicsPipeline();
2817
2818 pipeline_rendering_info.colorAttachmentCount = 0;
2819
2820 CreatePipelineHelper pipe2(*this);
2821 pipe2.InitInfo();
2822 pipe2.gp_ci_.pNext = &pipeline_rendering_info;
2823 pipe2.gp_ci_.renderPass = VK_NULL_HANDLE;
2824 pipe2.InitState();
2825 pipe2.CreateGraphicsPipeline();
2826
2827 VkImageObj image(m_device);
2828 image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0);
2829 VkImageView image_view = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2830
2831 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2832 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2833 color_attachment.imageView = image_view;
2834
2835 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
2836 begin_rendering_info.layerCount = 1;
2837 begin_rendering_info.colorAttachmentCount = 1;
2838 begin_rendering_info.pColorAttachments = &color_attachment;
2839
2840 m_commandBuffer->begin();
2841 m_commandBuffer->BeginRendering(begin_rendering_info);
2842
2843 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.pipeline_);
2844 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2845
2846 m_errorMonitor->VerifyNotFound();
2847
2848 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBindPipeline-pipeline-06195");
2849 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.pipeline_);
2850 m_errorMonitor->VerifyFound();
2851
2852 m_commandBuffer->EndRendering();
2853 m_commandBuffer->end();
ziga-lunarge3f11282022-04-21 18:39:55 +02002854}
2855
2856TEST_F(VkLayerTest, BindPipelineWithIncompatibleRenderingInfoStencilFormat) {
2857 TEST_DESCRIPTION("Bind pipeline that has RenderingInfo StencilFormat incompatible with previously used pipeline");
2858
2859 SetTargetApiVersion(VK_API_VERSION_1_1);
2860 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2861 ASSERT_NO_FATAL_FAILURE(InitFramework());
2862
2863 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2864 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2865 return;
2866 }
2867 if (!AreRequestedExtensionsEnabled()) {
2868 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2869 return;
2870 }
2871
2872 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2873 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
2874 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2875 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2876 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2877 return;
2878 }
2879
2880 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2882
2883 m_errorMonitor->ExpectSuccess();
2884
2885 std::vector<VkFormat> stencil_formats;
2886 const VkFormat ds_formats[] = {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
2887 for (uint32_t i = 0; i < size(ds_formats); ++i) {
2888 VkFormatProperties format_props;
2889 vk::GetPhysicalDeviceFormatProperties(gpu(), ds_formats[i], &format_props);
2890
2891 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
2892 stencil_formats.push_back(ds_formats[i]);
2893 }
2894 }
2895
2896 if (stencil_formats.size() < 2) {
2897 printf("%s Test requires 2 stencil formats, skipping test.\n", kSkipPrefix);
2898 return;
2899 }
2900
2901 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
2902 pipeline_rendering_info.stencilAttachmentFormat = stencil_formats[0];
2903
2904 auto ds_ci = LvlInitStruct<VkPipelineDepthStencilStateCreateInfo>();
2905
2906 CreatePipelineHelper pipe1(*this);
2907 pipe1.InitInfo();
2908 pipe1.gp_ci_.pNext = &pipeline_rendering_info;
2909 pipe1.gp_ci_.renderPass = VK_NULL_HANDLE;
2910 pipe1.InitState();
2911 pipe1.ds_ci_ = ds_ci;
2912 pipe1.CreateGraphicsPipeline();
2913
2914 pipeline_rendering_info.stencilAttachmentFormat = stencil_formats[1];
2915
2916 CreatePipelineHelper pipe2(*this);
2917 pipe2.InitInfo();
2918 pipe2.gp_ci_.pNext = &pipeline_rendering_info;
2919 pipe2.gp_ci_.renderPass = VK_NULL_HANDLE;
2920 pipe2.InitState();
2921 pipe2.ds_ci_ = ds_ci;
2922 pipe2.CreateGraphicsPipeline();
2923
2924 VkImageObj image(m_device);
2925 image.Init(32, 32, 1, stencil_formats[0], VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0);
2926 VkImageView stencil_image_view = image.targetView(stencil_formats[0], VK_IMAGE_ASPECT_DEPTH_BIT);
2927
2928 VkRenderingAttachmentInfoKHR stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
2929 stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL;
2930 stencil_attachment.imageView = stencil_image_view;
2931
2932 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
2933 begin_rendering_info.layerCount = 1;
2934 begin_rendering_info.pStencilAttachment = &stencil_attachment;
2935
2936 m_commandBuffer->begin();
2937 m_commandBuffer->BeginRendering(begin_rendering_info);
2938
2939 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.pipeline_);
2940 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2941
2942 m_errorMonitor->VerifyNotFound();
2943
2944 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdBindPipeline-pipeline-06194");
2945 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.pipeline_);
2946 m_errorMonitor->VerifyFound();
2947
2948 m_commandBuffer->EndRendering();
2949 m_commandBuffer->end();
2950}
ziga-lunarg155ed452022-04-21 23:54:06 +02002951
2952TEST_F(VkLayerTest, DynamicRenderingWithInvalidShaderLayerBuiltIn) {
2953 TEST_DESCRIPTION("Create invalid pipeline that writes to Layer built-in");
2954
2955 SetTargetApiVersion(VK_API_VERSION_1_1);
2956 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2957 ASSERT_NO_FATAL_FAILURE(InitFramework());
2958
2959 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
2960 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
2961 return;
2962 }
2963 if (!AreRequestedExtensionsEnabled()) {
2964 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
2965 return;
2966 }
2967
2968 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
2969 auto multiview_features = LvlInitStruct<VkPhysicalDeviceMultiviewFeatures>(&dynamic_rendering_features);
2970 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&multiview_features);
2971 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
2972 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
2973 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
2974 return;
2975 }
2976 if (multiview_features.multiview == VK_FALSE) {
2977 printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix);
2978 return;
2979 }
2980 if (multiview_features.multiviewGeometryShader == VK_FALSE) {
2981 printf("%s Test requires (unsupported) multiviewGeometryShader , skipping\n", kSkipPrefix);
2982 return;
2983 }
2984
2985 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
2986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2987
2988 static char const *gsSource = R"glsl(
2989 #version 450
2990 layout (triangles) in;
2991 layout (triangle_strip) out;
2992 layout (max_vertices = 1) out;
2993 void main() {
2994 gl_Position = vec4(1.0, 0.5, 0.5, 0.0);
2995 EmitVertex();
2996 gl_Layer = 4;
2997 }
2998 )glsl";
2999
3000 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
3001 VkShaderObj gs(this, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT);
3002
3003 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
3004
3005 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
3006 pipeline_rendering_info.colorAttachmentCount = 1;
3007 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
3008 pipeline_rendering_info.viewMask = 0x1;
3009
3010 CreatePipelineHelper pipe(*this);
3011 pipe.InitInfo();
3012 pipe.shader_stages_ = {vs.GetStageCreateInfo(), gs.GetStageCreateInfo(), pipe.fs_->GetStageCreateInfo()};
3013 pipe.gp_ci_.pNext = &pipeline_rendering_info;
3014 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
3015 pipe.InitState();
3016 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06059");
3017 pipe.CreateGraphicsPipeline();
3018 m_errorMonitor->VerifyFound();
3019}
ziga-lunarg6feb4632022-04-22 00:20:21 +02003020
3021TEST_F(VkLayerTest, DynamicRenderingWithInputAttachmentCapability) {
3022 TEST_DESCRIPTION("Create invalid pipeline that uses InputAttachment capability");
3023
3024 SetTargetApiVersion(VK_API_VERSION_1_1);
3025 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
3026 ASSERT_NO_FATAL_FAILURE(InitFramework());
3027
3028 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
3029 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
3030 return;
3031 }
3032 if (!AreRequestedExtensionsEnabled()) {
3033 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
3034 return;
3035 }
3036
3037 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
3038 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
3039 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
3040 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
3041 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
3042 return;
3043 }
3044
3045 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
3046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3047
3048 const std::string fsSource = R"(
3049 OpCapability Shader
3050 OpCapability InputAttachment
3051 %1 = OpExtInstImport "GLSL.std.450"
3052 OpMemoryModel Logical GLSL450
3053 OpEntryPoint Fragment %main "main"
3054 OpExecutionMode %main OriginUpperLeft
3055
3056 ; Debug Information
3057 OpSource GLSL 450
3058 OpName %main "main" ; id %4
3059
3060 ; Types, variables and constants
3061 %void = OpTypeVoid
3062 %3 = OpTypeFunction %void
3063
3064 ; Function main
3065 %main = OpFunction %void None %3
3066 %5 = OpLabel
3067 OpReturn
3068 OpFunctionEnd
3069 )";
3070
3071 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, SPV_ENV_VULKAN_1_0, SPV_SOURCE_ASM);
3072
3073 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
3074
3075 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
3076 pipeline_rendering_info.colorAttachmentCount = 1;
3077 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
3078
3079 CreatePipelineHelper pipe(*this);
3080 pipe.InitInfo();
3081 pipe.shader_stages_ = {pipe.vs_->GetStageCreateInfo(), fs.GetStageCreateInfo()};
3082 pipe.gp_ci_.pNext = &pipeline_rendering_info;
3083 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
3084 pipe.InitState();
3085 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06061");
3086 pipe.CreateGraphicsPipeline();
3087 m_errorMonitor->VerifyFound();
3088}
ziga-lunarga62b6ce2022-04-22 14:33:47 +02003089
3090TEST_F(VkLayerTest, InvalidRenderingInfoColorAttachmentFormat) {
3091 TEST_DESCRIPTION("Create pipeline with invalid color attachment format");
3092
3093 SetTargetApiVersion(VK_API_VERSION_1_1);
3094 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
3095 ASSERT_NO_FATAL_FAILURE(InitFramework());
3096
3097 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
3098 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
3099 return;
3100 }
3101 if (!AreRequestedExtensionsEnabled()) {
3102 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
3103 return;
3104 }
3105
3106 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
3107 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
3108 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
3109 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
3110 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
3111 return;
3112 }
3113
3114 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
3115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3116
3117 VkFormat color_format = VK_FORMAT_MAX_ENUM;
3118
3119 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
3120 pipeline_rendering_info.colorAttachmentCount = 1;
3121 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
3122
3123 CreatePipelineHelper pipe(*this);
3124 pipe.InitInfo();
3125 pipe.gp_ci_.pNext = &pipeline_rendering_info;
3126 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
3127 pipe.InitState();
3128 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06579");
3129 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06580");
3130 pipe.CreateGraphicsPipeline();
3131 m_errorMonitor->VerifyFound();
3132}
ziga-lunargf7fb9202022-04-22 17:19:10 +02003133
3134TEST_F(VkLayerTest, InvalidDynamicRenderingLibraryViewMask) {
3135 TEST_DESCRIPTION("Create pipeline with invalid view mask");
3136
3137 SetTargetApiVersion(VK_API_VERSION_1_1);
3138 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
3139 AddRequiredExtensions(VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME);
3140 ASSERT_NO_FATAL_FAILURE(InitFramework());
3141
3142 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
3143 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
3144 return;
3145 }
3146 if (!AreRequestedExtensionsEnabled()) {
3147 printf("%s %s or %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
3148 VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME);
3149 return;
3150 }
3151
3152 auto multiview_features = LvlInitStruct<VkPhysicalDeviceMultiviewFeatures>();
3153 auto library_features = LvlInitStruct<VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT>(&multiview_features);
3154 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(&library_features);
3155 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
3156 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
3157 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
3158 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
3159 return;
3160 }
3161 if (library_features.graphicsPipelineLibrary == VK_FALSE) {
3162 printf("%s Test requires (unsupported) graphicsPipelineLibrary , skipping\n", kSkipPrefix);
3163 return;
3164 }
3165 if (multiview_features.multiview == VK_FALSE) {
3166 printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix);
3167 return;
3168 }
3169
3170 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
3171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3172
3173 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
3174
3175 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
3176 pipeline_rendering_info.colorAttachmentCount = 1;
3177 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
3178
3179 auto graphics_library_create_info = LvlInitStruct<VkGraphicsPipelineLibraryCreateInfoEXT>(&pipeline_rendering_info);
3180 graphics_library_create_info.flags = VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT;
3181 auto library_create_info = LvlInitStruct<VkPipelineLibraryCreateInfoKHR>(&graphics_library_create_info);
3182
3183 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
3184 auto color_blend_state_create_info = LvlInitStruct<VkPipelineColorBlendStateCreateInfo>();
3185 color_blend_state_create_info.attachmentCount = 1;
3186 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
3187
3188 m_errorMonitor->ExpectSuccess();
3189 CreatePipelineHelper lib(*this);
3190 lib.cb_ci_ = color_blend_state_create_info;
3191 lib.InitInfo();
3192 lib.gp_ci_.pNext = &library_create_info;
3193 lib.gp_ci_.renderPass = VK_NULL_HANDLE;
3194 lib.InitState();
3195 lib.CreateGraphicsPipeline();
3196 m_errorMonitor->VerifyNotFound();
3197
3198 graphics_library_create_info.flags = VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT;
3199 library_create_info.libraryCount = 1;
3200 library_create_info.pLibraries = &lib.pipeline_;
3201 pipeline_rendering_info.viewMask = 0x1;
3202
3203 CreatePipelineHelper pipe(*this);
3204 pipe.InitInfo();
3205 pipe.gp_ci_.pNext = &library_create_info;
3206 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
3207 pipe.InitState();
3208 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06626");
3209 pipe.CreateGraphicsPipeline();
3210 m_errorMonitor->VerifyFound();
3211}
ziga-lunarge151ca62022-04-22 17:40:51 +02003212
3213TEST_F(VkLayerTest, InvalidAttachmentSampleCount) {
3214 TEST_DESCRIPTION("Create pipeline with invalid color attachment samples");
3215
3216 SetTargetApiVersion(VK_API_VERSION_1_1);
3217 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
3218 ASSERT_NO_FATAL_FAILURE(InitFramework());
3219
3220 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
3221 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
3222 return;
3223 }
3224 if (!AreRequestedExtensionsEnabled()) {
3225 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
3226 return;
3227 }
3228
3229 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
3230 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
3231 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
3232 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
3233 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
3234 return;
3235 }
3236
3237 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
3238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3239
3240 VkSampleCountFlagBits color_attachment_samples = VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM;
3241
3242 auto samples_info = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
3243 samples_info.colorAttachmentCount = 1;
3244 samples_info.pColorAttachmentSamples = &color_attachment_samples;
3245 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(&samples_info);
3246
3247 CreatePipelineHelper pipe(*this);
3248 pipe.InitInfo();
3249 pipe.gp_ci_.pNext = &pipeline_rendering_info;
3250 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
3251 pipe.InitState();
3252 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-pColorAttachmentSamples-06592");
3253 pipe.CreateGraphicsPipeline();
3254 m_errorMonitor->VerifyFound();
3255}