blob: b45a7497c2d8b2ef882f8b13af3e8df0baf03979 [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()) {
33 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
Aaron Haganb54466d2022-02-18 15:02:54 -050034 return;
35 }
36
Aaron Haganaca50442021-12-07 22:26:29 -050037 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
38 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
39 return;
40 }
sfricke-samsungae54c1e2022-01-21 05:35:21 -080041
Nathaniel Cesarioa06135e2022-03-02 21:22:30 -070042 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
43 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
44 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
45 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
46 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
Aaron Haganaca50442021-12-07 22:26:29 -050047 return;
48 }
49
ziga-lunargf54cb2a2022-03-11 02:54:27 +010050 features2.features.variableMultisampleRate = VK_FALSE;
51
Nathaniel Cesarioa06135e2022-03-02 21:22:30 -070052 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
53
Aaron Haganaca50442021-12-07 22:26:29 -050054 VkPhysicalDeviceMultiviewProperties multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
55 VkPhysicalDeviceProperties2 pd_props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&multiview_props);
56 vk::GetPhysicalDeviceProperties2(gpu(), &pd_props2);
57
58 if (multiview_props.maxMultiviewViewCount == 32) {
59 printf("%s VUID is not testable as maxMultiviewViewCount is 32, skipping test\n", kSkipPrefix);
60 return;
61 }
62
63 VkFormat color_format = VK_FORMAT_D32_SFLOAT;
64
65 auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
66 cmd_buffer_inheritance_rendering_info.colorAttachmentCount = 1;
67 cmd_buffer_inheritance_rendering_info.pColorAttachmentFormats = &color_format;
68 cmd_buffer_inheritance_rendering_info.depthAttachmentFormat = VK_FORMAT_R8G8B8_UNORM;
69 cmd_buffer_inheritance_rendering_info.stencilAttachmentFormat = VK_FORMAT_R8G8B8_SNORM;
70 cmd_buffer_inheritance_rendering_info.viewMask = 1 << multiview_props.maxMultiviewViewCount;
71
72 auto sample_count_info_amd = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
73 sample_count_info_amd.pNext = &cmd_buffer_inheritance_rendering_info;
74 sample_count_info_amd.colorAttachmentCount = 2;
sfricke-samsungae54c1e2022-01-21 05:35:21 -080075
Aaron Haganaca50442021-12-07 22:26:29 -050076 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
77 cmd_buffer_inheritance_info.pNext = &sample_count_info_amd;
78
79 auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
80 cmd_buffer_allocate_info.commandPool = m_commandPool->handle();
81 cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
82 cmd_buffer_allocate_info.commandBufferCount = 0x1;
83
84 VkCommandBuffer secondary_cmd_buffer;
85 VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer);
86 ASSERT_VK_SUCCESS(err);
87 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06003");
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070088 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-colorAttachmentCount-06004");
89 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-variableMultisampleRate-06005");
90 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06007");
91 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-multiview-06008");
92 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-viewMask-06009");
Aaron Haganaca50442021-12-07 22:26:29 -050093 m_errorMonitor->SetDesiredFailureMsg(kErrorBit,
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070094 "VUID-VkCommandBufferInheritanceRenderingInfo-stencilAttachmentFormat-06199");
Aaron Haganaca50442021-12-07 22:26:29 -050095 m_errorMonitor->SetDesiredFailureMsg(kErrorBit,
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070096 "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06200");
Aaron Haganaca50442021-12-07 22:26:29 -050097 m_errorMonitor->SetDesiredFailureMsg(kErrorBit,
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070098 "VUID-VkCommandBufferInheritanceRenderingInfo-pColorAttachmentFormats-06006");
ziga-lunargf54cb2a2022-03-11 02:54:27 +010099 m_errorMonitor->SetAllowedFailureMsg("VUID-VkAttachmentSampleCountInfoAMD-pColorAttachmentSamples-parameter");
Aaron Haganaca50442021-12-07 22:26:29 -0500100
101 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
102 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
103 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
104 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
105 m_errorMonitor->VerifyFound();
106}
107
Aaron Haganb54466d2022-02-18 15:02:54 -0500108TEST_F(VkLayerTest, DynamicRenderingCommandDraw) {
Aaron Haganaca50442021-12-07 22:26:29 -0500109 TEST_DESCRIPTION("vkCmdDraw* Dynamic Rendering Tests.");
110
111 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
112 if (version < VK_API_VERSION_1_2) {
113 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
114 return;
115 }
116
117 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
118
119 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
120
121 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
122 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
123 return;
124 }
125
126 if (!AreRequestedExtensionsEnabled()) {
127 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
128 return;
129 }
130
131 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
132 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
133 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
134 if (!dynamic_rendering_features.dynamicRendering) {
135 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
136 return;
137 }
138
139 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
140
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800141 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
142 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
Aaron Haganaca50442021-12-07 22:26:29 -0500143
144 VkPipelineObj pipe(m_device);
145 pipe.AddShader(&vs);
146 pipe.AddShader(&fs);
147 pipe.AddDefaultColorAttachment();
148
149 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
150 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
151 const VkPipelineLayoutObj pl(m_device, {&dsl});
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800152
Aaron Haganaca50442021-12-07 22:26:29 -0500153 VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
154 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
Aaron Hagan80034ea2021-12-23 11:24:09 -0500155 pipeline_rendering_info.depthAttachmentFormat = depth_format;
156 pipeline_rendering_info.stencilAttachmentFormat = depth_format;
Aaron Haganaca50442021-12-07 22:26:29 -0500157
158 auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>();
159 multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT;
160
161 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
162 pipe.InitGraphicsPipelineCreateInfo(&create_info);
163 create_info.pMultisampleState = &multisample_state_create_info;
164 create_info.renderPass = VkRenderPass(0x1);
165 create_info.pNext = &pipeline_rendering_info;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800166
Aaron Haganaca50442021-12-07 22:26:29 -0500167 VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
168 ASSERT_VK_SUCCESS(err);
169
170 VkViewport viewport = {0, 0, 16, 16, 0, 1};
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800171 VkRect2D scissor = {{0, 0}, {16, 16}};
Aaron Haganaca50442021-12-07 22:26:29 -0500172
173 VkImageObj image(m_device);
174 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0);
175 ASSERT_TRUE(image.initialized());
176
177 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
178 nullptr,
179 0,
180 image.handle(),
181 VK_IMAGE_VIEW_TYPE_2D,
182 depth_format,
183 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
184 VK_COMPONENT_SWIZZLE_IDENTITY},
185 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
186
187 VkImageView depth_image_view;
188 err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view);
189 ASSERT_VK_SUCCESS(err);
190
191 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
192 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
193 depth_attachment.imageView = depth_image_view;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800194
Aaron Haganaca50442021-12-07 22:26:29 -0500195 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
196 begin_rendering_info.pDepthAttachment = &depth_attachment;
197 begin_rendering_info.pStencilAttachment = &depth_attachment;
198
199 m_commandBuffer->begin();
200 m_commandBuffer->BeginRendering(begin_rendering_info);
201 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
202 vk::CmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
203 vk::CmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
204 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189");
205 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190");
206 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
207 m_errorMonitor->VerifyFound();
208 m_commandBuffer->EndRendering();
209 m_commandBuffer->end();
210}
211
212TEST_F(VkLayerTest, DynamicRenderingGraphicsPipelineCreateInfo) {
213 TEST_DESCRIPTION("Test graphics pipeline creation with dynamic rendering.");
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800214
Aaron Haganaca50442021-12-07 22:26:29 -0500215 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
216 if (version < VK_API_VERSION_1_2) {
217 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
218 return;
219 }
220
221 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
222
223 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
224
225 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
226 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
227 return;
228 }
229
230 if (!AreRequestedExtensionsEnabled()) {
231 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
232 return;
233 }
234
235 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
236 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
237 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
238 if (!dynamic_rendering_features.dynamicRendering) {
239 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
240 return;
241 }
242
243 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
244
245 const VkPipelineLayoutObj pl(m_device);
246 VkPipelineObj pipe(m_device);
247
248 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
249
250 auto color_blend_state_create_info = LvlInitStruct<VkPipelineColorBlendStateCreateInfo>();
251 color_blend_state_create_info.attachmentCount = 1;
252 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
253
254 VkFormat color_format[2] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_D32_SFLOAT_S8_UINT};
255
256 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
257 pipeline_rendering_info.colorAttachmentCount = 2;
258 pipeline_rendering_info.pColorAttachmentFormats = &color_format[0];
259 pipeline_rendering_info.viewMask = 0x2;
Aaron Hagan80034ea2021-12-23 11:24:09 -0500260 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
Aaron Haganaca50442021-12-07 22:26:29 -0500261
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800262 auto pipeline_tessellation_state_info = LvlInitStruct<VkPipelineTessellationStateCreateInfo>();
Aaron Haganaca50442021-12-07 22:26:29 -0500263 pipeline_tessellation_state_info.patchControlPoints = 1;
264
265 auto pipeline_input_assembly_state_info = LvlInitStruct<VkPipelineInputAssemblyStateCreateInfo>();
266 pipeline_input_assembly_state_info.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
267
268 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
Aaron Hagan80034ea2021-12-23 11:24:09 -0500269
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800270 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
271 VkShaderObj gs(this, bindStateGeomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT);
272 VkShaderObj te(this, bindStateTeshaderText, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
273 VkShaderObj tc(this, bindStateTscShaderText, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
Aaron Hagan80034ea2021-12-23 11:24:09 -0500274 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
275
Aaron Haganaca50442021-12-07 22:26:29 -0500276 pipe.AddShader(&vs);
277 pipe.AddShader(&gs);
278 pipe.AddShader(&te);
279 pipe.AddShader(&tc);
Aaron Hagan80034ea2021-12-23 11:24:09 -0500280 pipe.AddShader(&fs);
Aaron Haganaca50442021-12-07 22:26:29 -0500281 pipe.InitGraphicsPipelineCreateInfo(&create_info);
282 create_info.pColorBlendState = &color_blend_state_create_info;
283 create_info.pNext = &pipeline_rendering_info;
284 create_info.pTessellationState = &pipeline_tessellation_state_info;
285 create_info.pInputAssemblyState = &pipeline_input_assembly_state_info;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800286
Aaron Hagan80034ea2021-12-23 11:24:09 -0500287 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06053");
Aaron Haganaca50442021-12-07 22:26:29 -0500288 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06055");
289 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06057");
290 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06058");
291 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06060");
Tony-LunarGbbd2ab92021-12-02 08:31:24 -0700292 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfo-multiview-06066");
293 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfo-pColorAttachmentFormats-06064");
Aaron Haganaca50442021-12-07 22:26:29 -0500294 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
295 m_errorMonitor->VerifyFound();
296
Aaron Hagan80034ea2021-12-23 11:24:09 -0500297 create_info.pColorBlendState = nullptr;
298 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
299 pipeline_rendering_info.viewMask = 0x0;
300 pipeline_rendering_info.colorAttachmentCount = 1;
301 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06054");
302 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
303 m_errorMonitor->VerifyFound();
Aaron Haganb54466d2022-02-18 15:02:54 -0500304
ziga-lunarg5e671602022-03-17 19:06:55 +0100305 color_format[0] = VK_FORMAT_D32_SFLOAT_S8_UINT;
306 color_blend_attachment_state.blendEnable = VK_TRUE;
307 create_info.pColorBlendState = &color_blend_state_create_info;
308 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06062");
309 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfo-pColorAttachmentFormats-06064");
310 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
311 m_errorMonitor->VerifyFound();
312 color_format[0] = VK_FORMAT_R8G8B8A8_UNORM;
313
Aaron Haganb54466d2022-02-18 15:02:54 -0500314 auto ds_ci = LvlInitStruct<VkPipelineDepthStencilStateCreateInfo>();
315 ds_ci.flags = VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_ARM;
316 color_blend_state_create_info.flags = VK_PIPELINE_COLOR_BLEND_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_BIT_ARM;
317 create_info.pColorBlendState = &color_blend_state_create_info;
318 create_info.pDepthStencilState = &ds_ci;
319 create_info.renderPass = VK_NULL_HANDLE;
320 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
321 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06482");
322 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06483");
323 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
324 m_errorMonitor->VerifyFound();
stusmith15f24a82021-12-24 15:21:19 +0000325}
326
327TEST_F(VkLayerTest, DynamicRenderingWithMismatchingViewMask) {
328 TEST_DESCRIPTION("Draw with Dynamic Rendering and a mismatching viewMask");
329
330 SetTargetApiVersion(VK_API_VERSION_1_1);
331
332 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
333
334 ASSERT_NO_FATAL_FAILURE(InitFramework());
335
336 if (!AreRequestedExtensionsEnabled()) {
337 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
338 return;
339 }
340
341 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
342 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
343 return;
344 }
345
346 auto multiview_features = LvlInitStruct<VkPhysicalDeviceMultiviewFeatures>();
347 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(&multiview_features);
348 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
349 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
350 if (!dynamic_rendering_features.dynamicRendering) {
351 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
352 return;
353 }
354 if (!multiview_features.multiview) {
355 printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix);
356 return;
357 }
358
359 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
360
361 char const *fsSource = R"glsl(
362 #version 450
363 layout(location=0) out vec4 color;
364 void main() {
365 color = vec4(1.0f);
366 }
367 )glsl";
368
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800369 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
370 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000371
372 VkPipelineObj pipe(m_device);
373 pipe.AddShader(&vs);
374 pipe.AddShader(&fs);
375 pipe.AddDefaultColorAttachment();
376
377 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
378 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
379 const VkPipelineLayoutObj pl(m_device, {&dsl});
380
381 VkFormat color_formats = {VK_FORMAT_R8G8B8A8_UNORM};
382 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
383 pipeline_rendering_info.colorAttachmentCount = 1;
384 pipeline_rendering_info.pColorAttachmentFormats = &color_formats;
385 pipeline_rendering_info.viewMask = 1;
386
387 VkViewport viewport = {0, 0, 16, 16, 0, 1};
388 VkRect2D scissor = {{0, 0}, {16, 16}};
389 m_viewports.push_back(viewport);
390 m_scissors.push_back(scissor);
391 pipe.SetViewport(m_viewports);
392 pipe.SetScissor(m_scissors);
393
394 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
395 pipe.InitGraphicsPipelineCreateInfo(&create_info);
396 create_info.pNext = &pipeline_rendering_info;
397
398 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
399
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800400 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000401 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
402
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800403 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000404 begin_rendering_info.colorAttachmentCount = 1;
405 begin_rendering_info.pColorAttachments = &color_attachment;
406 begin_rendering_info.viewMask = 2;
407 begin_rendering_info.layerCount = 1;
408
409 m_commandBuffer->begin();
410 m_commandBuffer->BeginRendering(begin_rendering_info);
411 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
412 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-viewMask-06178");
413 m_commandBuffer->Draw(1, 1, 0, 0);
414 m_errorMonitor->VerifyFound();
415 m_commandBuffer->EndRendering();
416 m_commandBuffer->end();
417}
418
419TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachments) {
420 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color attachment counts and depth/stencil formats");
421
422 SetTargetApiVersion(VK_API_VERSION_1_1);
423
424 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
425
426 ASSERT_NO_FATAL_FAILURE(InitFramework());
427
428 if (!AreRequestedExtensionsEnabled()) {
429 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
430 return;
431 }
432
433 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
434 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
435 return;
436 }
437
438 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
439 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
440 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
441 if (!dynamic_rendering_features.dynamicRendering) {
442 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
443 return;
444 }
445
446 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
447
448 char const *fsSource = R"glsl(
449 #version 450
450 layout(location=0) out vec4 color;
451 void main() {
452 color = vec4(1.0f);
453 }
454 )glsl";
455
456 VkViewport viewport = {0, 0, 16, 16, 0, 1};
457 VkRect2D scissor = {{0, 0}, {16, 16}};
458 m_viewports.push_back(viewport);
459 m_scissors.push_back(scissor);
460
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800461 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
462 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000463
464 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
465 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
466 const VkPipelineLayoutObj pl(m_device, {&dsl});
467
468 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
469
470 VkPipelineObj pipe1(m_device);
471 pipe1.AddShader(&vs);
472 pipe1.AddShader(&fs);
473 pipe1.AddDefaultColorAttachment();
474 pipe1.SetViewport(m_viewports);
475 pipe1.SetScissor(m_scissors);
476
477 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
478 pipeline_rendering_info.colorAttachmentCount = 1;
479 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
480
481 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
482 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
483 create_info1.pNext = &pipeline_rendering_info;
484
485 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
486
487 VkPipelineObj pipe2(m_device);
488 pipe2.AddShader(&vs);
489 pipe2.AddShader(&fs);
490 pipe2.AddDefaultColorAttachment();
491 pipe2.SetViewport(m_viewports);
492 pipe2.SetScissor(m_scissors);
493
494 pipeline_rendering_info.colorAttachmentCount = 0;
495 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
496 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D16_UNORM;
497
498 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
499 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
500 create_info2.pNext = &pipeline_rendering_info;
501
502 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
503
504 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
505 ASSERT_TRUE(depthStencilFormat != 0);
506
507 bool testStencil = false;
508 VkFormat stencilFormat = VK_FORMAT_UNDEFINED;
509
510 if (ImageFormatIsSupported(gpu(), VK_FORMAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
511 stencilFormat = VK_FORMAT_S8_UINT;
512 testStencil = true;
513 } else if ((depthStencilFormat != VK_FORMAT_D16_UNORM_S8_UINT) &&
514 ImageFormatIsSupported(gpu(), VK_FORMAT_D16_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
515 stencilFormat = VK_FORMAT_D16_UNORM_S8_UINT;
516 testStencil = true;
517 } else if ((depthStencilFormat != VK_FORMAT_D24_UNORM_S8_UINT) &&
518 ImageFormatIsSupported(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
519 stencilFormat = VK_FORMAT_D24_UNORM_S8_UINT;
520 testStencil = true;
521 } else if ((depthStencilFormat != VK_FORMAT_D32_SFLOAT_S8_UINT) &&
522 ImageFormatIsSupported(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
523 stencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
524 testStencil = true;
525 }
526
527 VkPipelineObj pipe3(m_device);
528
529 if (testStencil) {
530 pipe3.AddShader(&vs);
531 pipe3.AddShader(&fs);
532 pipe3.AddDefaultColorAttachment();
533 pipe3.SetViewport(m_viewports);
534 pipe3.SetScissor(m_scissors);
535
536 pipeline_rendering_info.colorAttachmentCount = 0;
537 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
538 pipeline_rendering_info.stencilAttachmentFormat = stencilFormat;
539
540 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
541 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
542 create_info3.pNext = &pipeline_rendering_info;
543
544 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
545 }
546
547 VkImageObj colorImage(m_device);
548 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
549 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT);
550
551 VkImageObj depthStencilImage(m_device);
552 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
553 VkImageView depthStencilImageView =
554 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
555
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800556 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000557 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
558 color_attachment.imageView = colorImageView;
559
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800560 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000561 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
562 depth_stencil_attachment.imageView = depthStencilImageView;
563
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800564 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000565 m_commandBuffer->begin();
566
567 // Mismatching color attachment count
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-06179");
571 m_commandBuffer->Draw(1, 1, 0, 0);
572 m_errorMonitor->VerifyFound();
573 m_commandBuffer->EndRendering();
574
575 // Mismatching color formats
576 begin_rendering_info.colorAttachmentCount = 1;
577 begin_rendering_info.pColorAttachments = &color_attachment;
578 m_commandBuffer->BeginRendering(begin_rendering_info);
579 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
580 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06180");
581 m_commandBuffer->Draw(1, 1, 0, 0);
582 m_errorMonitor->VerifyFound();
583 m_commandBuffer->EndRendering();
584
585 // Mismatching depth format
586 begin_rendering_info.colorAttachmentCount = 0;
587 begin_rendering_info.pColorAttachments = nullptr;
588 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
589 m_commandBuffer->BeginRendering(begin_rendering_info);
590 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
591 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06181");
592 m_commandBuffer->Draw(1, 1, 0, 0);
593 m_errorMonitor->VerifyFound();
594 m_commandBuffer->EndRendering();
595
596 // Mismatching stencil format
597 if (testStencil) {
598 begin_rendering_info.pDepthAttachment = nullptr;
599 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
600 m_commandBuffer->BeginRendering(begin_rendering_info);
601 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
602 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06182");
603 m_commandBuffer->Draw(1, 1, 0, 0);
604 m_errorMonitor->VerifyFound();
605 m_commandBuffer->EndRendering();
606 }
607
608 m_commandBuffer->end();
609}
610
611TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachmentSamples) {
612 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color/depth/stencil sample counts");
613
614 SetTargetApiVersion(VK_API_VERSION_1_1);
615
616 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
617
618 ASSERT_NO_FATAL_FAILURE(InitFramework());
619
620 if (!AreRequestedExtensionsEnabled()) {
621 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
622 return;
623 }
624
625 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
626 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
627 return;
628 }
629
630 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
631 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
632 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
633 if (!dynamic_rendering_features.dynamicRendering) {
634 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
635 return;
636 }
637
638 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
639
640 char const *fsSource = R"glsl(
641 #version 450
642 layout(location=0) out vec4 color;
643 void main() {
644 color = vec4(1.0f);
645 }
646 )glsl";
647
648 VkViewport viewport = {0, 0, 16, 16, 0, 1};
649 VkRect2D scissor = {{0, 0}, {16, 16}};
650 m_viewports.push_back(viewport);
651 m_scissors.push_back(scissor);
652
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800653 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
654 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000655
656 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
657 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
658 const VkPipelineLayoutObj pl(m_device, {&dsl});
659
660 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
661
662
663 VkPipelineObj pipe1(m_device);
664 pipe1.AddShader(&vs);
665 pipe1.AddShader(&fs);
666 pipe1.AddDefaultColorAttachment();
667 pipe1.SetViewport(m_viewports);
668 pipe1.SetScissor(m_scissors);
669
670 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
671 pipeline_rendering_info.colorAttachmentCount = 1;
672 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
673
674 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
675 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
676 create_info1.pNext = &pipeline_rendering_info;
677
678 auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>();
679 multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT;
680 create_info1.pMultisampleState = &multisample_state_create_info;
681
682 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
683
684
685 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
686 ASSERT_TRUE(depthStencilFormat != 0);
687
688
689 VkPipelineObj pipe2(m_device);
690 pipe2.AddShader(&vs);
691 pipe2.AddShader(&fs);
692 pipe2.AddDefaultColorAttachment();
693 pipe2.SetViewport(m_viewports);
694 pipe2.SetScissor(m_scissors);
695
696 pipeline_rendering_info.colorAttachmentCount = 0;
697 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
698 pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat;
699
700 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
701 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
702 create_info2.pNext = &pipeline_rendering_info;
703
704 create_info2.pMultisampleState = &multisample_state_create_info;
705
706 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
707
708
709 VkPipelineObj pipe3(m_device);
710
711 pipe3.AddShader(&vs);
712 pipe3.AddShader(&fs);
713 pipe3.AddDefaultColorAttachment();
714 pipe3.SetViewport(m_viewports);
715 pipe3.SetScissor(m_scissors);
716
717 pipeline_rendering_info.colorAttachmentCount = 0;
718 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
719 pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat;
720
721 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
722 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
723 create_info3.pNext = &pipeline_rendering_info;
724
725 create_info3.pMultisampleState = &multisample_state_create_info;
726
727 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
728
729
730 VkImageObj colorImage(m_device);
731 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
732 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM);
733
734 VkImageObj depthStencilImage(m_device);
735 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
736 VkImageView depthStencilImageView =
737 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
738
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800739 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000740 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
741 color_attachment.imageView = colorImageView;
742
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800743 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000744 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
745 depth_stencil_attachment.imageView = depthStencilImageView;
746
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800747 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000748 m_commandBuffer->begin();
749
750 // Mismatching color samples
751 begin_rendering_info.colorAttachmentCount = 1;
752 begin_rendering_info.pColorAttachments = &color_attachment;
753 m_commandBuffer->BeginRendering(begin_rendering_info);
754 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
755 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06188");
756 m_commandBuffer->Draw(1, 1, 0, 0);
757 m_errorMonitor->VerifyFound();
758 m_commandBuffer->EndRendering();
759
760 // Mismatching depth samples
761 begin_rendering_info.colorAttachmentCount = 0;
762 begin_rendering_info.pColorAttachments = nullptr;
763 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
764 m_commandBuffer->BeginRendering(begin_rendering_info);
765 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
766 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189");
767 m_commandBuffer->Draw(1, 1, 0, 0);
768 m_errorMonitor->VerifyFound();
769 m_commandBuffer->EndRendering();
770
771 // Mismatching stencil samples
772 begin_rendering_info.pDepthAttachment = nullptr;
773 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
774 m_commandBuffer->BeginRendering(begin_rendering_info);
775 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
776 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190");
777 m_commandBuffer->Draw(1, 1, 0, 0);
778 m_errorMonitor->VerifyFound();
779 m_commandBuffer->EndRendering();
780
781 m_commandBuffer->end();
782}
783
784TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingMixedAttachmentSamples) {
785 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching mixed color/depth/stencil sample counts");
786
787 SetTargetApiVersion(VK_API_VERSION_1_1);
788
789 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
790
791 ASSERT_NO_FATAL_FAILURE(InitFramework());
792
793 if (!AreRequestedExtensionsEnabled()) {
794 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
795 return;
796 }
797
798 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
799 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
800 return;
801 }
802
803 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
804 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
805 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
806 if (!dynamic_rendering_features.dynamicRendering) {
807 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
808 return;
809 }
810
811 bool amd_samples = false;
812 if (DeviceExtensionSupported(gpu(), nullptr, VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME)) {
813 m_device_extension_names.push_back(VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME);
814 amd_samples = true;
815 }
816
817 bool nv_samples = false;
818 if (DeviceExtensionSupported(gpu(), nullptr, VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME)) {
819 m_device_extension_names.push_back(VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME);
820 nv_samples = true;
821 }
822
823 if (!amd_samples && !nv_samples) {
824 printf("%s Test requires either VK_AMD_mixed_attachment_samples or VK_NV_framebuffer_mixed_samples, skipping\n",
825 kSkipPrefix);
826 return;
827 }
828
829 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
830
831 char const *fsSource = R"glsl(
832 #version 450
833 layout(location=0) out vec4 color;
834 void main() {
835 color = vec4(1.0f);
836 }
837 )glsl";
838
839 VkViewport viewport = {0, 0, 16, 16, 0, 1};
840 VkRect2D scissor = {{0, 0}, {16, 16}};
841 m_viewports.push_back(viewport);
842 m_scissors.push_back(scissor);
843
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800844 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
845 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000846
847 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
848 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
849 const VkPipelineLayoutObj pl(m_device, {&dsl});
850
851 VkSampleCountFlagBits counts = {VK_SAMPLE_COUNT_2_BIT};
852 auto samples_info = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
853
854 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(&samples_info);
855
856 VkPipelineObj pipe1(m_device);
857 pipe1.AddShader(&vs);
858 pipe1.AddShader(&fs);
859 pipe1.AddDefaultColorAttachment();
860 pipe1.SetViewport(m_viewports);
861 pipe1.SetScissor(m_scissors);
862
863 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
864 pipeline_rendering_info.colorAttachmentCount = 1;
865 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
866
867 samples_info.colorAttachmentCount = 1;
868 samples_info.pColorAttachmentSamples = &counts;
869
870 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
871 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
872 create_info1.pNext = &pipeline_rendering_info;
873
Aaron Haganb54466d2022-02-18 15:02:54 -0500874 samples_info.colorAttachmentCount = 2;
875 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06063");
876 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
877 m_errorMonitor->VerifyFound();
878
879 samples_info.colorAttachmentCount = 1;
stusmith15f24a82021-12-24 15:21:19 +0000880 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
881
882 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
883 ASSERT_TRUE(depthStencilFormat != 0);
884
885 VkPipelineObj pipe2(m_device);
886 pipe2.AddShader(&vs);
887 pipe2.AddShader(&fs);
888 pipe2.AddDefaultColorAttachment();
889 pipe2.SetViewport(m_viewports);
890 pipe2.SetScissor(m_scissors);
891
892 pipeline_rendering_info.colorAttachmentCount = 0;
893 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
894 pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat;
895
896 samples_info.colorAttachmentCount = 0;
897 samples_info.pColorAttachmentSamples = nullptr;
898 samples_info.depthStencilAttachmentSamples = counts;
899
900 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
901 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
902 create_info2.pNext = &pipeline_rendering_info;
903
904 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
905
906 VkPipelineObj pipe3(m_device);
907
908 pipe3.AddShader(&vs);
909 pipe3.AddShader(&fs);
910 pipe3.AddDefaultColorAttachment();
911 pipe3.SetViewport(m_viewports);
912 pipe3.SetScissor(m_scissors);
913
914 pipeline_rendering_info.colorAttachmentCount = 0;
915 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
916 pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat;
917
918 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
919 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
920 create_info3.pNext = &pipeline_rendering_info;
921
922 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
923
924 VkImageObj colorImage(m_device);
925 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
926 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM);
927
928 VkImageObj depthStencilImage(m_device);
929 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
930 VkImageView depthStencilImageView =
931 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
932
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800933 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000934 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
935 color_attachment.imageView = colorImageView;
936
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800937 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000938 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
939 depth_stencil_attachment.imageView = depthStencilImageView;
940
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800941 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000942 m_commandBuffer->begin();
943
944 // Mismatching color samples
945 begin_rendering_info.colorAttachmentCount = 1;
946 begin_rendering_info.pColorAttachments = &color_attachment;
947 m_commandBuffer->BeginRendering(begin_rendering_info);
948 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
949 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06185");
950 m_commandBuffer->Draw(1, 1, 0, 0);
951 m_errorMonitor->VerifyFound();
952 m_commandBuffer->EndRendering();
953
954 // Mismatching depth samples
955 begin_rendering_info.colorAttachmentCount = 0;
956 begin_rendering_info.pColorAttachments = nullptr;
957 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
958 m_commandBuffer->BeginRendering(begin_rendering_info);
959 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
960 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06186");
961 m_commandBuffer->Draw(1, 1, 0, 0);
962 m_errorMonitor->VerifyFound();
963 m_commandBuffer->EndRendering();
964
965 // Mismatching stencil samples
966 begin_rendering_info.pDepthAttachment = nullptr;
967 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
968 m_commandBuffer->BeginRendering(begin_rendering_info);
969 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
970 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06187");
971 m_commandBuffer->Draw(1, 1, 0, 0);
972 m_errorMonitor->VerifyFound();
973 m_commandBuffer->EndRendering();
974
975 m_commandBuffer->end();
976}
Aaron Hagan80034ea2021-12-23 11:24:09 -0500977
978TEST_F(VkLayerTest, DynamicRenderingAttachmentInfo) {
979 TEST_DESCRIPTION("AttachmentInfo Dynamic Rendering Tests.");
980
981 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
982 if (version < VK_API_VERSION_1_2) {
983 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
984 return;
985 }
986
987 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
988
989 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
990
991 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
992 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
993 return;
994 }
995
996 if (!AreRequestedExtensionsEnabled()) {
997 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
998 return;
999 }
1000
1001 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
1002 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1003 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1004 if (!dynamic_rendering_features.dynamicRendering) {
1005 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1006 return;
1007 }
1008
1009 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1010
1011 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
1012 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
1013
1014 VkPipelineObj pipe(m_device);
1015 pipe.AddShader(&vs);
1016 pipe.AddShader(&fs);
1017 pipe.AddDefaultColorAttachment();
1018
1019 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
1020 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
1021 const VkPipelineLayoutObj pl(m_device, {&dsl});
1022
1023 VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1024 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1025 pipeline_rendering_info.depthAttachmentFormat = depth_format;
1026
1027 auto pipeline_create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
1028 pipe.InitGraphicsPipelineCreateInfo(&pipeline_create_info);
1029 pipeline_create_info.pNext = &pipeline_rendering_info;
1030
1031 VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &pipeline_create_info);
1032 ASSERT_VK_SUCCESS(err);
1033
1034 VkImageObj image(m_device);
1035 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1036 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1037 image_create_info.format = depth_format;
1038 image_create_info.extent = {64, 64, 4};
1039 image_create_info.mipLevels = 1;
1040 image_create_info.arrayLayers = 1;
1041 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1042 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1043 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1044 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1045
1046 image.Init(image_create_info);
1047 ASSERT_TRUE(image.initialized());
1048
1049 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1050 nullptr,
1051 0,
1052 image.handle(),
1053 VK_IMAGE_VIEW_TYPE_2D,
1054 depth_format,
1055 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1056 VK_COMPONENT_SWIZZLE_IDENTITY},
1057 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1058
1059 VkImageView depth_image_view;
1060 err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view);
1061 ASSERT_VK_SUCCESS(err);
1062
1063 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1064 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1065 depth_attachment.imageView = depth_image_view;
1066 depth_attachment.resolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT;
1067 depth_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1068
1069 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1070 begin_rendering_info.pDepthAttachment = &depth_attachment;
1071 begin_rendering_info.viewMask = 0x4;
1072
1073 VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map =
1074 LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>();
1075 fragment_density_map.imageView = depth_image_view;
1076 begin_rendering_info.pNext = &fragment_density_map;
1077
1078 m_commandBuffer->begin();
1079 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-multiview-06127");
Jeremy Gebben09c1a072022-02-08 09:42:47 -07001080 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06107");
1081 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06108");
1082 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06116");
Aaron Hagan80034ea2021-12-23 11:24:09 -05001083 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06129");
Jeremy Gebben09c1a072022-02-08 09:42:47 -07001084 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06145");
1085 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06146");
Aaron Hagan80034ea2021-12-23 11:24:09 -05001086 m_commandBuffer->BeginRendering(begin_rendering_info);
1087 m_errorMonitor->VerifyFound();
1088}
Aaron Haganb54466d2022-02-18 15:02:54 -05001089
1090TEST_F(VkLayerTest, DynamicRenderingBufferBeginInfoLegacy) {
1091 TEST_DESCRIPTION("VkCommandBufferBeginInfo Dynamic Rendering Tests.");
1092
1093 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
1094 if (version < VK_API_VERSION_1_2) {
1095 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
1096 return;
1097 }
1098
1099 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1100
1101 ASSERT_NO_FATAL_FAILURE(Init(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1102
1103 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
1104 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
1105 return;
1106 }
1107
1108 if (!AreRequestedExtensionsEnabled()) {
1109 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1110 return;
1111 }
1112
1113 auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
1114 cmd_buffer_inheritance_rendering_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
1115
1116 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
1117 cmd_buffer_inheritance_info.pNext = &cmd_buffer_inheritance_rendering_info;
1118 cmd_buffer_inheritance_info.renderPass = VK_NULL_HANDLE;
1119
1120 auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
1121 cmd_buffer_allocate_info.commandPool = m_commandPool->handle();
1122 cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
1123 cmd_buffer_allocate_info.commandBufferCount = 0x1;
1124
1125 VkCommandBuffer secondary_cmd_buffer;
1126 VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer);
1127 ASSERT_VK_SUCCESS(err);
1128
1129 // Invalid RenderPass
1130 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-00053");
1131 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
1132 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1133 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
1134 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
1135 m_errorMonitor->VerifyFound();
1136
1137 // Valid RenderPass
1138 VkAttachmentDescription attach[] = {
1139 {0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
1140 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
1141 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
1142 };
1143 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
1144
1145 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
1146 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, &subpass, 0, nullptr};
1147
1148 vk_testing::RenderPass rp1;
1149 rp1.init(*m_device, rpci);
1150
1151 cmd_buffer_inheritance_info.renderPass = rp1.handle();
1152 cmd_buffer_inheritance_info.subpass = 0x5;
1153 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-00054");
1154 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
1155 m_errorMonitor->VerifyFound();
1156}
1157
1158TEST_F(VkLayerTest, DynamicRenderingSecondaryCommandBuffer) {
1159 TEST_DESCRIPTION("VkCommandBufferBeginInfo Dynamic Rendering Tests.");
1160
1161 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_3);
1162 if (version < VK_API_VERSION_1_3) {
1163 printf("%s At least Vulkan version 1.3 is required, skipping test.\n", kSkipPrefix);
1164 return;
1165 }
1166
1167 ASSERT_NO_FATAL_FAILURE(Init());
1168
1169 if (DeviceValidationVersion() < VK_API_VERSION_1_3) {
1170 printf("%s At least Vulkan version 1.3 is required for device, skipping test\n", kSkipPrefix);
1171 return;
1172 }
1173
1174 VkCommandBufferObj cb(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1175
1176 // Force the failure by not setting the Renderpass and Framebuffer fields
1177 VkCommandBufferInheritanceInfo cmd_buf_hinfo = LvlInitStruct<VkCommandBufferInheritanceInfo>();
1178 cmd_buf_hinfo.renderPass = VkRenderPass(0x1);
1179 VkCommandBufferBeginInfo cmd_buf_info = LvlInitStruct<VkCommandBufferBeginInfo>();
1180 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1181 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
1182
1183 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06000");
1184 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1185 m_errorMonitor->VerifyFound();
1186
1187 // Valid RenderPass
1188 VkAttachmentDescription attach[] = {
1189 {0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
1190 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
1191 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
1192 };
1193 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
1194
1195 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
1196 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, &subpass, 0, nullptr};
1197
1198 vk_testing::RenderPass rp1;
1199 rp1.init(*m_device, rpci);
1200
1201 cmd_buf_hinfo.renderPass = rp1.handle();
1202 cmd_buf_hinfo.subpass = 0x5;
1203 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06001");
1204 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1205 m_errorMonitor->VerifyFound();
1206
1207 cmd_buf_hinfo.renderPass = VK_NULL_HANDLE;
1208 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06002");
1209 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1210 m_errorMonitor->VerifyFound();
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001211}
1212
ziga-lunarge1607252022-03-14 18:34:39 +01001213TEST_F(VkLayerTest, DynamicRenderingDepthFormatAndResolveMode) {
1214 TEST_DESCRIPTION("Test VkRenderingAttachmentInfo imageView with depth format.");
1215
1216 SetTargetApiVersion(VK_API_VERSION_1_1);
1217 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1218 ASSERT_NO_FATAL_FAILURE(InitFramework());
1219
1220 if (DeviceValidationVersion() != VK_API_VERSION_1_1) {
1221 printf("%s Vulkan version 1.1 is required for device, skipping test\n", kSkipPrefix);
1222 return;
1223 }
1224 if (!AreRequestedExtensionsEnabled()) {
1225 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1226 return;
1227 }
1228
1229 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1230 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1231 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1232 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1233 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1234 return;
1235 }
1236
1237 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1238
1239 auto depth_stencil_props =
1240 LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1241 auto props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&depth_stencil_props);
1242 vk::GetPhysicalDeviceProperties2(gpu(), &props2);
1243
1244 if ((depth_stencil_props.supportedDepthResolveModes & VK_RESOLVE_MODE_AVERAGE_BIT) == 0) {
1245 printf("%s Required depth resolve mode not supported, skipping.\n", kSkipPrefix);
1246 return;
1247 }
1248
1249 VkFormat depth_format = FindSupportedDepthStencilFormat(gpu());
1250 if (depth_format == VK_FORMAT_UNDEFINED) {
1251 printf("%s No Depth + Stencil format found, skipping.\n", kSkipPrefix);
1252 return;
1253 }
1254
1255 VkImageObj image(m_device);
1256 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1257 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1258 image_create_info.format = depth_format;
1259 image_create_info.extent = {64, 64, 1};
1260 image_create_info.mipLevels = 1;
1261 image_create_info.arrayLayers = 1;
1262 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1263 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1264 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1265 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1266
1267 image.Init(image_create_info);
1268 ASSERT_TRUE(image.initialized());
1269
1270 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1271 nullptr,
1272 0,
1273 image.handle(),
1274 VK_IMAGE_VIEW_TYPE_2D,
1275 depth_format,
1276 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1277 VK_COMPONENT_SWIZZLE_IDENTITY},
1278 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1279
1280 vk_testing::ImageView depth_image_view;
1281 depth_image_view.init(*m_device, ivci);
1282
1283 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1284 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
1285 depth_attachment.imageView = depth_image_view.handle();
1286 depth_attachment.resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
1287 depth_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_GENERAL;
1288
1289 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
ziga-lunargaa97cbb2022-03-18 19:06:35 +01001290 begin_rendering_info.layerCount = 1;
ziga-lunarge1607252022-03-14 18:34:39 +01001291 begin_rendering_info.pDepthAttachment = &depth_attachment;
1292
1293 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06131");
1294
1295 m_commandBuffer->begin();
1296 m_commandBuffer->BeginRendering(begin_rendering_info);
1297 m_commandBuffer->end();
1298
1299 m_errorMonitor->VerifyFound();
1300}
1301
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001302TEST_F(VkLayerTest, TestDynamicRenderingPipelineMissingFlags) {
1303 TEST_DESCRIPTION("Test dynamic rendering with pipeline missing flags.");
1304
1305 SetTargetApiVersion(VK_API_VERSION_1_1);
1306 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1307 AddRequiredExtensions(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1308 AddRequiredExtensions(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1309
1310 ASSERT_NO_FATAL_FAILURE(InitFramework());
1311
1312 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
1313 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
1314 return;
1315 }
1316
1317 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1318 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1319 return;
1320 }
1321 bool fragment_density = DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1322 bool shading_rate = DeviceExtensionSupported(gpu(), nullptr, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1323
1324 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1325 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1326 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1327 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1328 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1329 return;
1330 }
1331
1332 auto fsr_properties = LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>();
1333
1334 auto phys_dev_props_2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fsr_properties);
1335 vk::GetPhysicalDeviceProperties2(gpu(), &phys_dev_props_2);
1336
1337 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1339
1340 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
1341 ASSERT_TRUE(depthStencilFormat != 0);
1342
1343 VkImageObj image(m_device);
1344 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1345 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1346 image_create_info.format = depthStencilFormat;
1347 image_create_info.extent = {64, 64, 1};
1348 image_create_info.mipLevels = 1;
1349 image_create_info.arrayLayers = 1;
1350 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1351 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1352 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1353 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1354
1355 image.Init(image_create_info);
1356 ASSERT_TRUE(image.initialized());
1357
1358 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1359 nullptr,
1360 0,
1361 image.handle(),
1362 VK_IMAGE_VIEW_TYPE_2D,
1363 depthStencilFormat,
1364 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1365 VK_COMPONENT_SWIZZLE_IDENTITY},
1366 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1367
1368 vk_testing::ImageView depth_image_view;
1369 depth_image_view.init(*m_device, ivci);
1370
1371 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1372 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1373
1374 if (shading_rate) {
1375 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-imageView-06183");
1376 VkRenderingFragmentShadingRateAttachmentInfoKHR fragment_shading_rate =
1377 LvlInitStruct<VkRenderingFragmentShadingRateAttachmentInfoKHR>();
1378 fragment_shading_rate.imageView = depth_image_view.handle();
1379 fragment_shading_rate.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
1380 fragment_shading_rate.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize;
1381
1382 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_shading_rate);
ziga-lunargaa97cbb2022-03-18 19:06:35 +01001383 begin_rendering_info.layerCount = 1;
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001384 begin_rendering_info.colorAttachmentCount = 1;
1385 begin_rendering_info.pColorAttachments = &color_attachment;
1386
1387 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
1388
1389 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1390 pipeline_rendering_info.colorAttachmentCount = 1;
1391 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
1392
1393 CreatePipelineHelper pipe(*this);
1394 pipe.InitInfo();
1395 pipe.gp_ci_.pNext = &pipeline_rendering_info;
1396 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
1397 pipe.InitState();
1398 pipe.CreateGraphicsPipeline();
1399
1400 m_commandBuffer->begin();
1401 m_commandBuffer->BeginRendering(begin_rendering_info);
1402 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
1403 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
1404 m_commandBuffer->EndRendering();
1405 m_commandBuffer->end();
1406
1407 m_errorMonitor->VerifyFound();
1408 }
1409
1410 if (fragment_density) {
1411 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-imageView-06184");
1412 VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map =
1413 LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>();
1414 fragment_density_map.imageView = depth_image_view.handle();
1415
1416 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_density_map);
ziga-lunargaa97cbb2022-03-18 19:06:35 +01001417 begin_rendering_info.layerCount = 1;
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001418 begin_rendering_info.colorAttachmentCount = 1;
1419 begin_rendering_info.pColorAttachments = &color_attachment;
1420
1421 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
1422
1423 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1424 pipeline_rendering_info.colorAttachmentCount = 1;
1425 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
1426
1427 CreatePipelineHelper pipe(*this);
1428 pipe.InitInfo();
1429 pipe.gp_ci_.pNext = &pipeline_rendering_info;
1430 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
1431 pipe.InitState();
1432 pipe.CreateGraphicsPipeline();
1433
1434 m_commandBuffer->begin();
1435 m_commandBuffer->BeginRendering(begin_rendering_info);
1436 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
1437 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
1438 m_commandBuffer->EndRendering();
1439 m_commandBuffer->end();
1440
1441 m_errorMonitor->VerifyFound();
1442 }
1443}
ziga-lunargbc6d8ad2022-03-18 13:04:20 +01001444
ziga-lunarg2c9067e2022-03-18 18:33:52 +01001445TEST_F(VkLayerTest, DynamicRenderingLayerCount) {
1446 TEST_DESCRIPTION("Test dynamic rendering with viewMask 0 and invalid layer count.");
1447
1448 SetTargetApiVersion(VK_API_VERSION_1_1);
1449 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1450
1451 ASSERT_NO_FATAL_FAILURE(InitFramework());
1452
1453 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
1454 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
1455 return;
1456 }
1457
1458 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1459 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1460 return;
1461 }
1462
1463 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1464 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1465 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1466 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1467 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1468 return;
1469 }
1470
1471 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1472
1473 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1474
1475 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-viewMask-06069");
1476 m_commandBuffer->begin();
1477 m_commandBuffer->BeginRendering(begin_rendering_info);
1478 m_commandBuffer->end();
1479 m_errorMonitor->VerifyFound();
1480}
1481
ziga-lunargbc6d8ad2022-03-18 13:04:20 +01001482TEST_F(VkLayerTest, TestRenderingInfoMismatchedSamples) {
1483 TEST_DESCRIPTION("Test beginning rendering with mismatched sample counts.");
1484
1485 SetTargetApiVersion(VK_API_VERSION_1_1);
1486 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1487
1488 ASSERT_NO_FATAL_FAILURE(InitFramework());
1489
1490 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
1491 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
1492 return;
1493 }
1494
1495 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1496 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1497 return;
1498 }
1499
1500 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1501 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1502 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1503 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1504 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1505 return;
1506 }
1507
1508 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1509
1510 VkImageCreateInfo image_ci = LvlInitStruct<VkImageCreateInfo>();
1511 image_ci.imageType = VK_IMAGE_TYPE_2D;
1512 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
1513 image_ci.extent.width = 64;
1514 image_ci.extent.height = 64;
1515 image_ci.extent.depth = 1;
1516 image_ci.mipLevels = 1;
1517 image_ci.arrayLayers = 1;
1518 image_ci.samples = VK_SAMPLE_COUNT_2_BIT;
1519 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
1520 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1521
1522 VkImageObj color_image(m_device);
1523 color_image.init(&image_ci);
1524
1525 VkImageViewCreateInfo civ_ci = LvlInitStruct<VkImageViewCreateInfo>();
1526 civ_ci.image = color_image.handle();
1527 civ_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1528 civ_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
1529 civ_ci.subresourceRange.layerCount = 1;
1530 civ_ci.subresourceRange.baseMipLevel = 0;
1531 civ_ci.subresourceRange.levelCount = 1;
1532 civ_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1533
1534 vk_testing::ImageView color_image_view;
1535 color_image_view.init(*m_device, civ_ci);
1536
1537 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1538 color_attachment.imageView = color_image_view.handle();
1539 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1540 color_attachment.resolveMode = VK_RESOLVE_MODE_NONE;
1541
1542 const VkFormat depth_format = FindSupportedDepthOnlyFormat(gpu());
1543 if (depth_format == VK_FORMAT_UNDEFINED) {
1544 printf("%s requires a depth only format, skipping.\n", kSkipPrefix);
1545 return;
1546 }
1547
1548 VkImageObj depth_image(m_device);
1549 depth_image.Init(64, 64, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
1550
1551 VkImageViewCreateInfo div_ci = LvlInitStruct<VkImageViewCreateInfo>();
1552 div_ci.image = depth_image.handle();
1553 div_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1554 div_ci.format = depth_format;
1555 div_ci.subresourceRange.layerCount = 1;
1556 div_ci.subresourceRange.baseMipLevel = 0;
1557 div_ci.subresourceRange.levelCount = 1;
1558 div_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
1559
1560 vk_testing::ImageView depth_image_view;
1561 depth_image_view.init(*m_device, div_ci);
1562
1563 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1564 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
1565 depth_attachment.imageView = depth_image_view.handle();
1566 depth_attachment.resolveMode = VK_RESOLVE_MODE_NONE;
1567
1568 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
ziga-lunargaa97cbb2022-03-18 19:06:35 +01001569 begin_rendering_info.layerCount = 1;
ziga-lunargbc6d8ad2022-03-18 13:04:20 +01001570 begin_rendering_info.colorAttachmentCount = 1;
1571 begin_rendering_info.pColorAttachments = &color_attachment;
1572 begin_rendering_info.pDepthAttachment = &depth_attachment;
1573
1574 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06070");
1575 m_commandBuffer->BeginRendering(begin_rendering_info);
1576 m_errorMonitor->VerifyFound();
1577}
ziga-lunargec0ac1c2022-03-18 19:25:17 +01001578
ziga-lunarg7e7138c2022-03-18 19:02:31 +01001579TEST_F(VkLayerTest, TestDeviceGroupRenderPassBeginInfo) {
1580 TEST_DESCRIPTION("Test render area of DeviceGroupRenderPassBeginInfo.");
1581
1582 SetTargetApiVersion(VK_API_VERSION_1_1);
1583 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1584
1585 ASSERT_NO_FATAL_FAILURE(InitFramework());
1586
1587 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
1588 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
1589 return;
1590 }
1591
1592 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1593 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1594 return;
1595 }
1596
1597 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1598 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1599 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1600 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1601 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1602 return;
1603 }
1604
1605 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1606
1607 VkRect2D render_area = {};
1608 render_area.offset.x = 0;
1609 render_area.offset.y = 0;
1610 render_area.extent.width = 32;
1611 render_area.extent.height = 32;
1612
1613 auto device_group_render_pass_begin_info = LvlInitStruct<VkDeviceGroupRenderPassBeginInfo>();
1614 device_group_render_pass_begin_info.deviceRenderAreaCount = 1;
1615 device_group_render_pass_begin_info.pDeviceRenderAreas = &render_area;
1616
1617 VkImageObj colorImage(m_device);
1618 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
1619 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT);
1620
1621 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1622 color_attachment.imageView = colorImageView;
1623 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1624
1625 auto begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&device_group_render_pass_begin_info);
1626 begin_rendering_info.colorAttachmentCount = 1;
1627 begin_rendering_info.pColorAttachments = &color_attachment;
1628
1629 m_commandBuffer->begin();
1630
1631 m_errorMonitor->ExpectSuccess();
1632 m_commandBuffer->BeginRendering(begin_rendering_info);
1633 m_errorMonitor->VerifyNotFound();
1634
1635 render_area.offset.x = 1;
1636 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06083");
1637 m_commandBuffer->BeginRendering(begin_rendering_info);
1638 m_errorMonitor->VerifyFound();
1639
1640 render_area.offset.x = 0;
1641 render_area.offset.y = 16;
1642 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06084");
1643 m_commandBuffer->BeginRendering(begin_rendering_info);
1644 m_errorMonitor->VerifyFound();
1645
1646 m_commandBuffer->end();
1647}
1648
ziga-lunargec0ac1c2022-03-18 19:25:17 +01001649TEST_F(VkLayerTest, BeginRenderingInvalidDepthAttachmentFormat) {
1650 TEST_DESCRIPTION("Test begin rendering with a depth attachment that has an invalid format");
1651
1652 SetTargetApiVersion(VK_API_VERSION_1_3);
1653 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1654
1655 ASSERT_NO_FATAL_FAILURE(InitFramework());
1656
1657 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
1658 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
1659 return;
1660 }
1661
1662 if (!AreRequestedExtensionsEnabled()) {
1663 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1664 return;
1665 }
1666
1667 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1668 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1669 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1670 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1671 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1672 return;
1673 }
1674
1675 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1676
1677 VkFormat stencil_format = FindSupportedStencilOnlyFormat(gpu());
1678 if (stencil_format == VK_FORMAT_UNDEFINED) {
1679 printf("%s requires a stencil only format format.\n", kSkipPrefix);
1680 return;
1681 }
1682
1683 VkImageObj image(m_device);
1684 image.Init(32, 32, 1, stencil_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
1685 VkImageView image_view = image.targetView(stencil_format, VK_IMAGE_ASPECT_STENCIL_BIT);
1686
1687 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1688 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
1689 depth_attachment.imageView = image_view;
1690
1691 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1692 begin_rendering_info.pDepthAttachment = &depth_attachment;
1693
1694 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pDepthAttachment-06547");
1695 m_commandBuffer->BeginRendering(begin_rendering_info);
1696 m_errorMonitor->VerifyFound();
1697}