blob: 1c21be9e2604f6c2ef83ff4f3087da758c3370ff [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");
292 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06062");
Tony-LunarGbbd2ab92021-12-02 08:31:24 -0700293 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfo-multiview-06066");
294 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfo-pColorAttachmentFormats-06064");
Aaron Haganaca50442021-12-07 22:26:29 -0500295 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
296 m_errorMonitor->VerifyFound();
297
Aaron Hagan80034ea2021-12-23 11:24:09 -0500298 create_info.pColorBlendState = nullptr;
299 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
300 pipeline_rendering_info.viewMask = 0x0;
301 pipeline_rendering_info.colorAttachmentCount = 1;
302 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06054");
303 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
304 m_errorMonitor->VerifyFound();
Aaron Haganb54466d2022-02-18 15:02:54 -0500305
306 auto ds_ci = LvlInitStruct<VkPipelineDepthStencilStateCreateInfo>();
307 ds_ci.flags = VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_ARM;
308 color_blend_state_create_info.flags = VK_PIPELINE_COLOR_BLEND_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_BIT_ARM;
309 create_info.pColorBlendState = &color_blend_state_create_info;
310 create_info.pDepthStencilState = &ds_ci;
311 create_info.renderPass = VK_NULL_HANDLE;
312 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
313 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06482");
314 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06483");
315 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
316 m_errorMonitor->VerifyFound();
stusmith15f24a82021-12-24 15:21:19 +0000317}
318
319TEST_F(VkLayerTest, DynamicRenderingWithMismatchingViewMask) {
320 TEST_DESCRIPTION("Draw with Dynamic Rendering and a mismatching viewMask");
321
322 SetTargetApiVersion(VK_API_VERSION_1_1);
323
324 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
325
326 ASSERT_NO_FATAL_FAILURE(InitFramework());
327
328 if (!AreRequestedExtensionsEnabled()) {
329 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
330 return;
331 }
332
333 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
334 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
335 return;
336 }
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()) {
421 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
422 return;
423 }
424
425 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
426 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
427 return;
428 }
429
430 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
431 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
432 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
433 if (!dynamic_rendering_features.dynamicRendering) {
434 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
435 return;
436 }
437
438 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
439
440 char const *fsSource = R"glsl(
441 #version 450
442 layout(location=0) out vec4 color;
443 void main() {
444 color = vec4(1.0f);
445 }
446 )glsl";
447
448 VkViewport viewport = {0, 0, 16, 16, 0, 1};
449 VkRect2D scissor = {{0, 0}, {16, 16}};
450 m_viewports.push_back(viewport);
451 m_scissors.push_back(scissor);
452
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800453 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
454 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000455
456 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
457 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
458 const VkPipelineLayoutObj pl(m_device, {&dsl});
459
460 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
461
462 VkPipelineObj pipe1(m_device);
463 pipe1.AddShader(&vs);
464 pipe1.AddShader(&fs);
465 pipe1.AddDefaultColorAttachment();
466 pipe1.SetViewport(m_viewports);
467 pipe1.SetScissor(m_scissors);
468
469 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
470 pipeline_rendering_info.colorAttachmentCount = 1;
471 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
472
473 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
474 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
475 create_info1.pNext = &pipeline_rendering_info;
476
477 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
478
479 VkPipelineObj pipe2(m_device);
480 pipe2.AddShader(&vs);
481 pipe2.AddShader(&fs);
482 pipe2.AddDefaultColorAttachment();
483 pipe2.SetViewport(m_viewports);
484 pipe2.SetScissor(m_scissors);
485
486 pipeline_rendering_info.colorAttachmentCount = 0;
487 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
488 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D16_UNORM;
489
490 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
491 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
492 create_info2.pNext = &pipeline_rendering_info;
493
494 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
495
496 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
497 ASSERT_TRUE(depthStencilFormat != 0);
498
499 bool testStencil = false;
500 VkFormat stencilFormat = VK_FORMAT_UNDEFINED;
501
502 if (ImageFormatIsSupported(gpu(), VK_FORMAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
503 stencilFormat = VK_FORMAT_S8_UINT;
504 testStencil = true;
505 } else if ((depthStencilFormat != VK_FORMAT_D16_UNORM_S8_UINT) &&
506 ImageFormatIsSupported(gpu(), VK_FORMAT_D16_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
507 stencilFormat = VK_FORMAT_D16_UNORM_S8_UINT;
508 testStencil = true;
509 } else if ((depthStencilFormat != VK_FORMAT_D24_UNORM_S8_UINT) &&
510 ImageFormatIsSupported(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
511 stencilFormat = VK_FORMAT_D24_UNORM_S8_UINT;
512 testStencil = true;
513 } else if ((depthStencilFormat != VK_FORMAT_D32_SFLOAT_S8_UINT) &&
514 ImageFormatIsSupported(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
515 stencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
516 testStencil = true;
517 }
518
519 VkPipelineObj pipe3(m_device);
520
521 if (testStencil) {
522 pipe3.AddShader(&vs);
523 pipe3.AddShader(&fs);
524 pipe3.AddDefaultColorAttachment();
525 pipe3.SetViewport(m_viewports);
526 pipe3.SetScissor(m_scissors);
527
528 pipeline_rendering_info.colorAttachmentCount = 0;
529 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
530 pipeline_rendering_info.stencilAttachmentFormat = stencilFormat;
531
532 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
533 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
534 create_info3.pNext = &pipeline_rendering_info;
535
536 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
537 }
538
539 VkImageObj colorImage(m_device);
540 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
541 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT);
542
543 VkImageObj depthStencilImage(m_device);
544 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
545 VkImageView depthStencilImageView =
546 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
547
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800548 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000549 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
550 color_attachment.imageView = colorImageView;
551
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800552 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000553 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
554 depth_stencil_attachment.imageView = depthStencilImageView;
555
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800556 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000557 m_commandBuffer->begin();
558
559 // Mismatching color attachment count
560 m_commandBuffer->BeginRendering(begin_rendering_info);
561 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
562 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06179");
563 m_commandBuffer->Draw(1, 1, 0, 0);
564 m_errorMonitor->VerifyFound();
565 m_commandBuffer->EndRendering();
566
567 // Mismatching color formats
568 begin_rendering_info.colorAttachmentCount = 1;
569 begin_rendering_info.pColorAttachments = &color_attachment;
570 m_commandBuffer->BeginRendering(begin_rendering_info);
571 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
572 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06180");
573 m_commandBuffer->Draw(1, 1, 0, 0);
574 m_errorMonitor->VerifyFound();
575 m_commandBuffer->EndRendering();
576
577 // Mismatching depth format
578 begin_rendering_info.colorAttachmentCount = 0;
579 begin_rendering_info.pColorAttachments = nullptr;
580 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
581 m_commandBuffer->BeginRendering(begin_rendering_info);
582 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
583 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06181");
584 m_commandBuffer->Draw(1, 1, 0, 0);
585 m_errorMonitor->VerifyFound();
586 m_commandBuffer->EndRendering();
587
588 // Mismatching stencil format
589 if (testStencil) {
590 begin_rendering_info.pDepthAttachment = nullptr;
591 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
592 m_commandBuffer->BeginRendering(begin_rendering_info);
593 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
594 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06182");
595 m_commandBuffer->Draw(1, 1, 0, 0);
596 m_errorMonitor->VerifyFound();
597 m_commandBuffer->EndRendering();
598 }
599
600 m_commandBuffer->end();
601}
602
603TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachmentSamples) {
604 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color/depth/stencil sample counts");
605
606 SetTargetApiVersion(VK_API_VERSION_1_1);
607
608 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
609
610 ASSERT_NO_FATAL_FAILURE(InitFramework());
611
612 if (!AreRequestedExtensionsEnabled()) {
613 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
614 return;
615 }
616
617 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
618 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
619 return;
620 }
621
622 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
623 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
624 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
625 if (!dynamic_rendering_features.dynamicRendering) {
626 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
627 return;
628 }
629
630 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
631
632 char const *fsSource = R"glsl(
633 #version 450
634 layout(location=0) out vec4 color;
635 void main() {
636 color = vec4(1.0f);
637 }
638 )glsl";
639
640 VkViewport viewport = {0, 0, 16, 16, 0, 1};
641 VkRect2D scissor = {{0, 0}, {16, 16}};
642 m_viewports.push_back(viewport);
643 m_scissors.push_back(scissor);
644
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800645 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
646 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000647
648 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
649 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
650 const VkPipelineLayoutObj pl(m_device, {&dsl});
651
652 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
653
654
655 VkPipelineObj pipe1(m_device);
656 pipe1.AddShader(&vs);
657 pipe1.AddShader(&fs);
658 pipe1.AddDefaultColorAttachment();
659 pipe1.SetViewport(m_viewports);
660 pipe1.SetScissor(m_scissors);
661
662 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
663 pipeline_rendering_info.colorAttachmentCount = 1;
664 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
665
666 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
667 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
668 create_info1.pNext = &pipeline_rendering_info;
669
670 auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>();
671 multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT;
672 create_info1.pMultisampleState = &multisample_state_create_info;
673
674 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
675
676
677 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
678 ASSERT_TRUE(depthStencilFormat != 0);
679
680
681 VkPipelineObj pipe2(m_device);
682 pipe2.AddShader(&vs);
683 pipe2.AddShader(&fs);
684 pipe2.AddDefaultColorAttachment();
685 pipe2.SetViewport(m_viewports);
686 pipe2.SetScissor(m_scissors);
687
688 pipeline_rendering_info.colorAttachmentCount = 0;
689 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
690 pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat;
691
692 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
693 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
694 create_info2.pNext = &pipeline_rendering_info;
695
696 create_info2.pMultisampleState = &multisample_state_create_info;
697
698 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
699
700
701 VkPipelineObj pipe3(m_device);
702
703 pipe3.AddShader(&vs);
704 pipe3.AddShader(&fs);
705 pipe3.AddDefaultColorAttachment();
706 pipe3.SetViewport(m_viewports);
707 pipe3.SetScissor(m_scissors);
708
709 pipeline_rendering_info.colorAttachmentCount = 0;
710 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
711 pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat;
712
713 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
714 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
715 create_info3.pNext = &pipeline_rendering_info;
716
717 create_info3.pMultisampleState = &multisample_state_create_info;
718
719 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
720
721
722 VkImageObj colorImage(m_device);
723 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
724 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM);
725
726 VkImageObj depthStencilImage(m_device);
727 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
728 VkImageView depthStencilImageView =
729 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
730
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800731 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000732 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
733 color_attachment.imageView = colorImageView;
734
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800735 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000736 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
737 depth_stencil_attachment.imageView = depthStencilImageView;
738
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800739 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000740 m_commandBuffer->begin();
741
742 // Mismatching color samples
743 begin_rendering_info.colorAttachmentCount = 1;
744 begin_rendering_info.pColorAttachments = &color_attachment;
745 m_commandBuffer->BeginRendering(begin_rendering_info);
746 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
747 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06188");
748 m_commandBuffer->Draw(1, 1, 0, 0);
749 m_errorMonitor->VerifyFound();
750 m_commandBuffer->EndRendering();
751
752 // Mismatching depth samples
753 begin_rendering_info.colorAttachmentCount = 0;
754 begin_rendering_info.pColorAttachments = nullptr;
755 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
756 m_commandBuffer->BeginRendering(begin_rendering_info);
757 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
758 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189");
759 m_commandBuffer->Draw(1, 1, 0, 0);
760 m_errorMonitor->VerifyFound();
761 m_commandBuffer->EndRendering();
762
763 // Mismatching stencil samples
764 begin_rendering_info.pDepthAttachment = nullptr;
765 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
766 m_commandBuffer->BeginRendering(begin_rendering_info);
767 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
768 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190");
769 m_commandBuffer->Draw(1, 1, 0, 0);
770 m_errorMonitor->VerifyFound();
771 m_commandBuffer->EndRendering();
772
773 m_commandBuffer->end();
774}
775
776TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingMixedAttachmentSamples) {
777 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching mixed color/depth/stencil sample counts");
778
779 SetTargetApiVersion(VK_API_VERSION_1_1);
780
781 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
782
783 ASSERT_NO_FATAL_FAILURE(InitFramework());
784
785 if (!AreRequestedExtensionsEnabled()) {
786 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
787 return;
788 }
789
790 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
791 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
792 return;
793 }
794
795 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
796 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
797 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
798 if (!dynamic_rendering_features.dynamicRendering) {
799 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
800 return;
801 }
802
803 bool amd_samples = false;
804 if (DeviceExtensionSupported(gpu(), nullptr, VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME)) {
805 m_device_extension_names.push_back(VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME);
806 amd_samples = true;
807 }
808
809 bool nv_samples = false;
810 if (DeviceExtensionSupported(gpu(), nullptr, VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME)) {
811 m_device_extension_names.push_back(VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME);
812 nv_samples = true;
813 }
814
815 if (!amd_samples && !nv_samples) {
816 printf("%s Test requires either VK_AMD_mixed_attachment_samples or VK_NV_framebuffer_mixed_samples, skipping\n",
817 kSkipPrefix);
818 return;
819 }
820
821 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
822
823 char const *fsSource = R"glsl(
824 #version 450
825 layout(location=0) out vec4 color;
826 void main() {
827 color = vec4(1.0f);
828 }
829 )glsl";
830
831 VkViewport viewport = {0, 0, 16, 16, 0, 1};
832 VkRect2D scissor = {{0, 0}, {16, 16}};
833 m_viewports.push_back(viewport);
834 m_scissors.push_back(scissor);
835
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800836 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
837 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000838
839 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
840 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
841 const VkPipelineLayoutObj pl(m_device, {&dsl});
842
843 VkSampleCountFlagBits counts = {VK_SAMPLE_COUNT_2_BIT};
844 auto samples_info = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
845
846 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(&samples_info);
847
848 VkPipelineObj pipe1(m_device);
849 pipe1.AddShader(&vs);
850 pipe1.AddShader(&fs);
851 pipe1.AddDefaultColorAttachment();
852 pipe1.SetViewport(m_viewports);
853 pipe1.SetScissor(m_scissors);
854
855 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
856 pipeline_rendering_info.colorAttachmentCount = 1;
857 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
858
859 samples_info.colorAttachmentCount = 1;
860 samples_info.pColorAttachmentSamples = &counts;
861
862 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
863 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
864 create_info1.pNext = &pipeline_rendering_info;
865
Aaron Haganb54466d2022-02-18 15:02:54 -0500866 samples_info.colorAttachmentCount = 2;
867 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06063");
868 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
869 m_errorMonitor->VerifyFound();
870
871 samples_info.colorAttachmentCount = 1;
stusmith15f24a82021-12-24 15:21:19 +0000872 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
873
874 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
875 ASSERT_TRUE(depthStencilFormat != 0);
876
877 VkPipelineObj pipe2(m_device);
878 pipe2.AddShader(&vs);
879 pipe2.AddShader(&fs);
880 pipe2.AddDefaultColorAttachment();
881 pipe2.SetViewport(m_viewports);
882 pipe2.SetScissor(m_scissors);
883
884 pipeline_rendering_info.colorAttachmentCount = 0;
885 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
886 pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat;
887
888 samples_info.colorAttachmentCount = 0;
889 samples_info.pColorAttachmentSamples = nullptr;
890 samples_info.depthStencilAttachmentSamples = counts;
891
892 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
893 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
894 create_info2.pNext = &pipeline_rendering_info;
895
896 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
897
898 VkPipelineObj pipe3(m_device);
899
900 pipe3.AddShader(&vs);
901 pipe3.AddShader(&fs);
902 pipe3.AddDefaultColorAttachment();
903 pipe3.SetViewport(m_viewports);
904 pipe3.SetScissor(m_scissors);
905
906 pipeline_rendering_info.colorAttachmentCount = 0;
907 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
908 pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat;
909
910 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
911 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
912 create_info3.pNext = &pipeline_rendering_info;
913
914 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
915
916 VkImageObj colorImage(m_device);
917 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
918 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM);
919
920 VkImageObj depthStencilImage(m_device);
921 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
922 VkImageView depthStencilImageView =
923 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
924
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800925 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000926 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
927 color_attachment.imageView = colorImageView;
928
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800929 VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000930 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
931 depth_stencil_attachment.imageView = depthStencilImageView;
932
sfricke-samsung6fc3e322022-02-15 22:41:29 -0800933 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
stusmith15f24a82021-12-24 15:21:19 +0000934 m_commandBuffer->begin();
935
936 // Mismatching color samples
937 begin_rendering_info.colorAttachmentCount = 1;
938 begin_rendering_info.pColorAttachments = &color_attachment;
939 m_commandBuffer->BeginRendering(begin_rendering_info);
940 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
941 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06185");
942 m_commandBuffer->Draw(1, 1, 0, 0);
943 m_errorMonitor->VerifyFound();
944 m_commandBuffer->EndRendering();
945
946 // Mismatching depth samples
947 begin_rendering_info.colorAttachmentCount = 0;
948 begin_rendering_info.pColorAttachments = nullptr;
949 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
950 m_commandBuffer->BeginRendering(begin_rendering_info);
951 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
952 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06186");
953 m_commandBuffer->Draw(1, 1, 0, 0);
954 m_errorMonitor->VerifyFound();
955 m_commandBuffer->EndRendering();
956
957 // Mismatching stencil samples
958 begin_rendering_info.pDepthAttachment = nullptr;
959 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
960 m_commandBuffer->BeginRendering(begin_rendering_info);
961 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
962 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06187");
963 m_commandBuffer->Draw(1, 1, 0, 0);
964 m_errorMonitor->VerifyFound();
965 m_commandBuffer->EndRendering();
966
967 m_commandBuffer->end();
968}
Aaron Hagan80034ea2021-12-23 11:24:09 -0500969
970TEST_F(VkLayerTest, DynamicRenderingAttachmentInfo) {
971 TEST_DESCRIPTION("AttachmentInfo Dynamic Rendering Tests.");
972
973 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
974 if (version < VK_API_VERSION_1_2) {
975 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
976 return;
977 }
978
979 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
980
981 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
982
983 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
984 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
985 return;
986 }
987
988 if (!AreRequestedExtensionsEnabled()) {
989 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
990 return;
991 }
992
993 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
994 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
995 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
996 if (!dynamic_rendering_features.dynamicRendering) {
997 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
998 return;
999 }
1000
1001 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
1002
1003 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
1004 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
1005
1006 VkPipelineObj pipe(m_device);
1007 pipe.AddShader(&vs);
1008 pipe.AddShader(&fs);
1009 pipe.AddDefaultColorAttachment();
1010
1011 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
1012 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
1013 const VkPipelineLayoutObj pl(m_device, {&dsl});
1014
1015 VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1016 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1017 pipeline_rendering_info.depthAttachmentFormat = depth_format;
1018
1019 auto pipeline_create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
1020 pipe.InitGraphicsPipelineCreateInfo(&pipeline_create_info);
1021 pipeline_create_info.pNext = &pipeline_rendering_info;
1022
1023 VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &pipeline_create_info);
1024 ASSERT_VK_SUCCESS(err);
1025
1026 VkImageObj image(m_device);
1027 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1028 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1029 image_create_info.format = depth_format;
1030 image_create_info.extent = {64, 64, 4};
1031 image_create_info.mipLevels = 1;
1032 image_create_info.arrayLayers = 1;
1033 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1034 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1035 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1036 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1037
1038 image.Init(image_create_info);
1039 ASSERT_TRUE(image.initialized());
1040
1041 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1042 nullptr,
1043 0,
1044 image.handle(),
1045 VK_IMAGE_VIEW_TYPE_2D,
1046 depth_format,
1047 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1048 VK_COMPONENT_SWIZZLE_IDENTITY},
1049 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1050
1051 VkImageView depth_image_view;
1052 err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view);
1053 ASSERT_VK_SUCCESS(err);
1054
1055 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1056 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1057 depth_attachment.imageView = depth_image_view;
1058 depth_attachment.resolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT;
1059 depth_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1060
1061 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1062 begin_rendering_info.pDepthAttachment = &depth_attachment;
1063 begin_rendering_info.viewMask = 0x4;
1064
1065 VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map =
1066 LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>();
1067 fragment_density_map.imageView = depth_image_view;
1068 begin_rendering_info.pNext = &fragment_density_map;
1069
1070 m_commandBuffer->begin();
1071 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-multiview-06127");
1072 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-viewMask-06069");
Jeremy Gebben09c1a072022-02-08 09:42:47 -07001073 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06107");
1074 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06108");
1075 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06116");
Aaron Hagan80034ea2021-12-23 11:24:09 -05001076 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06129");
Jeremy Gebben09c1a072022-02-08 09:42:47 -07001077 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06145");
1078 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06146");
Aaron Hagan80034ea2021-12-23 11:24:09 -05001079 m_commandBuffer->BeginRendering(begin_rendering_info);
1080 m_errorMonitor->VerifyFound();
1081}
Aaron Haganb54466d2022-02-18 15:02:54 -05001082
1083TEST_F(VkLayerTest, DynamicRenderingBufferBeginInfoLegacy) {
1084 TEST_DESCRIPTION("VkCommandBufferBeginInfo Dynamic Rendering Tests.");
1085
1086 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
1087 if (version < VK_API_VERSION_1_2) {
1088 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
1089 return;
1090 }
1091
1092 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1093
1094 ASSERT_NO_FATAL_FAILURE(Init(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1095
1096 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
1097 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
1098 return;
1099 }
1100
1101 if (!AreRequestedExtensionsEnabled()) {
1102 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1103 return;
1104 }
1105
1106 auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
1107 cmd_buffer_inheritance_rendering_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
1108
1109 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
1110 cmd_buffer_inheritance_info.pNext = &cmd_buffer_inheritance_rendering_info;
1111 cmd_buffer_inheritance_info.renderPass = VK_NULL_HANDLE;
1112
1113 auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
1114 cmd_buffer_allocate_info.commandPool = m_commandPool->handle();
1115 cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
1116 cmd_buffer_allocate_info.commandBufferCount = 0x1;
1117
1118 VkCommandBuffer secondary_cmd_buffer;
1119 VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer);
1120 ASSERT_VK_SUCCESS(err);
1121
1122 // Invalid RenderPass
1123 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-00053");
1124 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
1125 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1126 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
1127 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
1128 m_errorMonitor->VerifyFound();
1129
1130 // Valid RenderPass
1131 VkAttachmentDescription attach[] = {
1132 {0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
1133 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
1134 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
1135 };
1136 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
1137
1138 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
1139 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, &subpass, 0, nullptr};
1140
1141 vk_testing::RenderPass rp1;
1142 rp1.init(*m_device, rpci);
1143
1144 cmd_buffer_inheritance_info.renderPass = rp1.handle();
1145 cmd_buffer_inheritance_info.subpass = 0x5;
1146 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-00054");
1147 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
1148 m_errorMonitor->VerifyFound();
1149}
1150
1151TEST_F(VkLayerTest, DynamicRenderingSecondaryCommandBuffer) {
1152 TEST_DESCRIPTION("VkCommandBufferBeginInfo Dynamic Rendering Tests.");
1153
1154 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_3);
1155 if (version < VK_API_VERSION_1_3) {
1156 printf("%s At least Vulkan version 1.3 is required, skipping test.\n", kSkipPrefix);
1157 return;
1158 }
1159
1160 ASSERT_NO_FATAL_FAILURE(Init());
1161
1162 if (DeviceValidationVersion() < VK_API_VERSION_1_3) {
1163 printf("%s At least Vulkan version 1.3 is required for device, skipping test\n", kSkipPrefix);
1164 return;
1165 }
1166
1167 VkCommandBufferObj cb(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1168
1169 // Force the failure by not setting the Renderpass and Framebuffer fields
1170 VkCommandBufferInheritanceInfo cmd_buf_hinfo = LvlInitStruct<VkCommandBufferInheritanceInfo>();
1171 cmd_buf_hinfo.renderPass = VkRenderPass(0x1);
1172 VkCommandBufferBeginInfo cmd_buf_info = LvlInitStruct<VkCommandBufferBeginInfo>();
1173 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1174 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
1175
1176 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06000");
1177 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1178 m_errorMonitor->VerifyFound();
1179
1180 // Valid RenderPass
1181 VkAttachmentDescription attach[] = {
1182 {0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
1183 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
1184 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
1185 };
1186 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
1187
1188 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
1189 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, &subpass, 0, nullptr};
1190
1191 vk_testing::RenderPass rp1;
1192 rp1.init(*m_device, rpci);
1193
1194 cmd_buf_hinfo.renderPass = rp1.handle();
1195 cmd_buf_hinfo.subpass = 0x5;
1196 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06001");
1197 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1198 m_errorMonitor->VerifyFound();
1199
1200 cmd_buf_hinfo.renderPass = VK_NULL_HANDLE;
1201 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06002");
1202 vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info);
1203 m_errorMonitor->VerifyFound();
ziga-lunarg6c8f1622022-03-14 20:14:04 +01001204}
1205
1206TEST_F(VkLayerTest, TestDynamicRenderingPipelineMissingFlags) {
1207 TEST_DESCRIPTION("Test dynamic rendering with pipeline missing flags.");
1208
1209 SetTargetApiVersion(VK_API_VERSION_1_1);
1210 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1211 AddRequiredExtensions(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1212 AddRequiredExtensions(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1213
1214 ASSERT_NO_FATAL_FAILURE(InitFramework());
1215
1216 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
1217 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
1218 return;
1219 }
1220
1221 if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
1222 printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
1223 return;
1224 }
1225 bool fragment_density = DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
1226 bool shading_rate = DeviceExtensionSupported(gpu(), nullptr, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
1227
1228 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>();
1229 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
1230 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
1231 if (dynamic_rendering_features.dynamicRendering == VK_FALSE) {
1232 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
1233 return;
1234 }
1235
1236 auto fsr_properties = LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>();
1237
1238 auto phys_dev_props_2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fsr_properties);
1239 vk::GetPhysicalDeviceProperties2(gpu(), &phys_dev_props_2);
1240
1241 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
1242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1243
1244 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
1245 ASSERT_TRUE(depthStencilFormat != 0);
1246
1247 VkImageObj image(m_device);
1248 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1249 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1250 image_create_info.format = depthStencilFormat;
1251 image_create_info.extent = {64, 64, 1};
1252 image_create_info.mipLevels = 1;
1253 image_create_info.arrayLayers = 1;
1254 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1255 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1256 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1257 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1258
1259 image.Init(image_create_info);
1260 ASSERT_TRUE(image.initialized());
1261
1262 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1263 nullptr,
1264 0,
1265 image.handle(),
1266 VK_IMAGE_VIEW_TYPE_2D,
1267 depthStencilFormat,
1268 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1269 VK_COMPONENT_SWIZZLE_IDENTITY},
1270 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1271
1272 vk_testing::ImageView depth_image_view;
1273 depth_image_view.init(*m_device, ivci);
1274
1275 VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1276 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1277
1278 if (shading_rate) {
1279 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-imageView-06183");
1280 VkRenderingFragmentShadingRateAttachmentInfoKHR fragment_shading_rate =
1281 LvlInitStruct<VkRenderingFragmentShadingRateAttachmentInfoKHR>();
1282 fragment_shading_rate.imageView = depth_image_view.handle();
1283 fragment_shading_rate.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
1284 fragment_shading_rate.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize;
1285
1286 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_shading_rate);
1287 begin_rendering_info.colorAttachmentCount = 1;
1288 begin_rendering_info.pColorAttachments = &color_attachment;
1289
1290 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
1291
1292 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1293 pipeline_rendering_info.colorAttachmentCount = 1;
1294 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
1295
1296 CreatePipelineHelper pipe(*this);
1297 pipe.InitInfo();
1298 pipe.gp_ci_.pNext = &pipeline_rendering_info;
1299 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
1300 pipe.InitState();
1301 pipe.CreateGraphicsPipeline();
1302
1303 m_commandBuffer->begin();
1304 m_commandBuffer->BeginRendering(begin_rendering_info);
1305 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
1306 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
1307 m_commandBuffer->EndRendering();
1308 m_commandBuffer->end();
1309
1310 m_errorMonitor->VerifyFound();
1311 }
1312
1313 if (fragment_density) {
1314 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-imageView-06184");
1315 VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map =
1316 LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>();
1317 fragment_density_map.imageView = depth_image_view.handle();
1318
1319 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_density_map);
1320 begin_rendering_info.colorAttachmentCount = 1;
1321 begin_rendering_info.pColorAttachments = &color_attachment;
1322
1323 VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
1324
1325 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1326 pipeline_rendering_info.colorAttachmentCount = 1;
1327 pipeline_rendering_info.pColorAttachmentFormats = &color_format;
1328
1329 CreatePipelineHelper pipe(*this);
1330 pipe.InitInfo();
1331 pipe.gp_ci_.pNext = &pipeline_rendering_info;
1332 pipe.gp_ci_.renderPass = VK_NULL_HANDLE;
1333 pipe.InitState();
1334 pipe.CreateGraphicsPipeline();
1335
1336 m_commandBuffer->begin();
1337 m_commandBuffer->BeginRendering(begin_rendering_info);
1338 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
1339 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
1340 m_commandBuffer->EndRendering();
1341 m_commandBuffer->end();
1342
1343 m_errorMonitor->VerifyFound();
1344 }
1345}