blob: 42570711caca11fc3a6bfbc3c9363dcd3fb97203 [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
20TEST_F(VkLayerTest, CommandBufferInheritanceRenderingInfoKHR) {
21 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);
30
31 VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>();
32 ASSERT_NO_FATAL_FAILURE(Init(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
33
34 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
35 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
36 return;
37 }
sfricke-samsungae54c1e2022-01-21 05:35:21 -080038
Aaron Haganaca50442021-12-07 22:26:29 -050039 if (!AreRequestedExtensionsEnabled()) {
40 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
41 return;
42 }
43
44 VkPhysicalDeviceMultiviewProperties multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
45 VkPhysicalDeviceProperties2 pd_props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&multiview_props);
46 vk::GetPhysicalDeviceProperties2(gpu(), &pd_props2);
47
48 if (multiview_props.maxMultiviewViewCount == 32) {
49 printf("%s VUID is not testable as maxMultiviewViewCount is 32, skipping test\n", kSkipPrefix);
50 return;
51 }
52
53 VkFormat color_format = VK_FORMAT_D32_SFLOAT;
54
55 auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>();
56 cmd_buffer_inheritance_rendering_info.colorAttachmentCount = 1;
57 cmd_buffer_inheritance_rendering_info.pColorAttachmentFormats = &color_format;
58 cmd_buffer_inheritance_rendering_info.depthAttachmentFormat = VK_FORMAT_R8G8B8_UNORM;
59 cmd_buffer_inheritance_rendering_info.stencilAttachmentFormat = VK_FORMAT_R8G8B8_SNORM;
60 cmd_buffer_inheritance_rendering_info.viewMask = 1 << multiview_props.maxMultiviewViewCount;
61
62 auto sample_count_info_amd = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
63 sample_count_info_amd.pNext = &cmd_buffer_inheritance_rendering_info;
64 sample_count_info_amd.colorAttachmentCount = 2;
sfricke-samsungae54c1e2022-01-21 05:35:21 -080065
Aaron Haganaca50442021-12-07 22:26:29 -050066 auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>();
67 cmd_buffer_inheritance_info.pNext = &sample_count_info_amd;
68
69 auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>();
70 cmd_buffer_allocate_info.commandPool = m_commandPool->handle();
71 cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
72 cmd_buffer_allocate_info.commandBufferCount = 0x1;
73
74 VkCommandBuffer secondary_cmd_buffer;
75 VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer);
76 ASSERT_VK_SUCCESS(err);
77 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06003");
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070078 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-colorAttachmentCount-06004");
79 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-variableMultisampleRate-06005");
80 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06007");
81 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-multiview-06008");
82 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-viewMask-06009");
Aaron Haganaca50442021-12-07 22:26:29 -050083 m_errorMonitor->SetDesiredFailureMsg(kErrorBit,
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070084 "VUID-VkCommandBufferInheritanceRenderingInfo-stencilAttachmentFormat-06199");
Aaron Haganaca50442021-12-07 22:26:29 -050085 m_errorMonitor->SetDesiredFailureMsg(kErrorBit,
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070086 "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06200");
Aaron Haganaca50442021-12-07 22:26:29 -050087 m_errorMonitor->SetDesiredFailureMsg(kErrorBit,
Tony-LunarGbbd2ab92021-12-02 08:31:24 -070088 "VUID-VkCommandBufferInheritanceRenderingInfo-pColorAttachmentFormats-06006");
Aaron Haganaca50442021-12-07 22:26:29 -050089
90 VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>();
91 cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
92 cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info;
93 vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info);
94 m_errorMonitor->VerifyFound();
95}
96
97TEST_F(VkLayerTest, CommandDrawDynamicRendering) {
98 TEST_DESCRIPTION("vkCmdDraw* Dynamic Rendering Tests.");
99
100 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
101 if (version < VK_API_VERSION_1_2) {
102 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
103 return;
104 }
105
106 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
107
108 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
109
110 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
111 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
112 return;
113 }
114
115 if (!AreRequestedExtensionsEnabled()) {
116 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
117 return;
118 }
119
120 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
121 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
122 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
123 if (!dynamic_rendering_features.dynamicRendering) {
124 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
125 return;
126 }
127
128 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
129
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800130 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
131 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
Aaron Haganaca50442021-12-07 22:26:29 -0500132
133 VkPipelineObj pipe(m_device);
134 pipe.AddShader(&vs);
135 pipe.AddShader(&fs);
136 pipe.AddDefaultColorAttachment();
137
138 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
139 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
140 const VkPipelineLayoutObj pl(m_device, {&dsl});
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800141
Aaron Haganaca50442021-12-07 22:26:29 -0500142 VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
143 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
Aaron Hagan80034ea2021-12-23 11:24:09 -0500144 pipeline_rendering_info.depthAttachmentFormat = depth_format;
145 pipeline_rendering_info.stencilAttachmentFormat = depth_format;
Aaron Haganaca50442021-12-07 22:26:29 -0500146
147 auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>();
148 multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT;
149
150 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
151 pipe.InitGraphicsPipelineCreateInfo(&create_info);
152 create_info.pMultisampleState = &multisample_state_create_info;
153 create_info.renderPass = VkRenderPass(0x1);
154 create_info.pNext = &pipeline_rendering_info;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800155
Aaron Haganaca50442021-12-07 22:26:29 -0500156 VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
157 ASSERT_VK_SUCCESS(err);
158
159 VkViewport viewport = {0, 0, 16, 16, 0, 1};
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800160 VkRect2D scissor = {{0, 0}, {16, 16}};
Aaron Haganaca50442021-12-07 22:26:29 -0500161
162 VkImageObj image(m_device);
163 image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0);
164 ASSERT_TRUE(image.initialized());
165
166 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
167 nullptr,
168 0,
169 image.handle(),
170 VK_IMAGE_VIEW_TYPE_2D,
171 depth_format,
172 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
173 VK_COMPONENT_SWIZZLE_IDENTITY},
174 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
175
176 VkImageView depth_image_view;
177 err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view);
178 ASSERT_VK_SUCCESS(err);
179
180 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
181 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
182 depth_attachment.imageView = depth_image_view;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800183
Aaron Haganaca50442021-12-07 22:26:29 -0500184 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
185 begin_rendering_info.pDepthAttachment = &depth_attachment;
186 begin_rendering_info.pStencilAttachment = &depth_attachment;
187
188 m_commandBuffer->begin();
189 m_commandBuffer->BeginRendering(begin_rendering_info);
190 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
191 vk::CmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
192 vk::CmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
193 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189");
194 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190");
195 vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
196 m_errorMonitor->VerifyFound();
197 m_commandBuffer->EndRendering();
198 m_commandBuffer->end();
199}
200
201TEST_F(VkLayerTest, DynamicRenderingGraphicsPipelineCreateInfo) {
202 TEST_DESCRIPTION("Test graphics pipeline creation with dynamic rendering.");
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800203
Aaron Haganaca50442021-12-07 22:26:29 -0500204 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
205 if (version < VK_API_VERSION_1_2) {
206 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
207 return;
208 }
209
210 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
211
212 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
213
214 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
215 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
216 return;
217 }
218
219 if (!AreRequestedExtensionsEnabled()) {
220 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
221 return;
222 }
223
224 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
225 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
226 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
227 if (!dynamic_rendering_features.dynamicRendering) {
228 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
229 return;
230 }
231
232 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
233
234 const VkPipelineLayoutObj pl(m_device);
235 VkPipelineObj pipe(m_device);
236
237 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
238
239 auto color_blend_state_create_info = LvlInitStruct<VkPipelineColorBlendStateCreateInfo>();
240 color_blend_state_create_info.attachmentCount = 1;
241 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
242
243 VkFormat color_format[2] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_D32_SFLOAT_S8_UINT};
244
245 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
246 pipeline_rendering_info.colorAttachmentCount = 2;
247 pipeline_rendering_info.pColorAttachmentFormats = &color_format[0];
248 pipeline_rendering_info.viewMask = 0x2;
Aaron Hagan80034ea2021-12-23 11:24:09 -0500249 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
Aaron Haganaca50442021-12-07 22:26:29 -0500250
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800251 auto pipeline_tessellation_state_info = LvlInitStruct<VkPipelineTessellationStateCreateInfo>();
Aaron Haganaca50442021-12-07 22:26:29 -0500252 pipeline_tessellation_state_info.patchControlPoints = 1;
253
254 auto pipeline_input_assembly_state_info = LvlInitStruct<VkPipelineInputAssemblyStateCreateInfo>();
255 pipeline_input_assembly_state_info.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
256
257 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
Aaron Hagan80034ea2021-12-23 11:24:09 -0500258
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800259 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
260 VkShaderObj gs(this, bindStateGeomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT);
261 VkShaderObj te(this, bindStateTeshaderText, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
262 VkShaderObj tc(this, bindStateTscShaderText, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
Aaron Hagan80034ea2021-12-23 11:24:09 -0500263 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
264
Aaron Haganaca50442021-12-07 22:26:29 -0500265 pipe.AddShader(&vs);
266 pipe.AddShader(&gs);
267 pipe.AddShader(&te);
268 pipe.AddShader(&tc);
Aaron Hagan80034ea2021-12-23 11:24:09 -0500269 pipe.AddShader(&fs);
Aaron Haganaca50442021-12-07 22:26:29 -0500270 pipe.InitGraphicsPipelineCreateInfo(&create_info);
271 create_info.pColorBlendState = &color_blend_state_create_info;
272 create_info.pNext = &pipeline_rendering_info;
273 create_info.pTessellationState = &pipeline_tessellation_state_info;
274 create_info.pInputAssemblyState = &pipeline_input_assembly_state_info;
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800275
Aaron Hagan80034ea2021-12-23 11:24:09 -0500276 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06053");
Aaron Haganaca50442021-12-07 22:26:29 -0500277 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06055");
278 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06057");
279 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06058");
280 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06060");
281 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06062");
Tony-LunarGbbd2ab92021-12-02 08:31:24 -0700282 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfo-multiview-06066");
283 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfo-pColorAttachmentFormats-06064");
Aaron Haganaca50442021-12-07 22:26:29 -0500284 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
285 m_errorMonitor->VerifyFound();
286
Aaron Hagan80034ea2021-12-23 11:24:09 -0500287 create_info.pColorBlendState = nullptr;
288 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
289 pipeline_rendering_info.viewMask = 0x0;
290 pipeline_rendering_info.colorAttachmentCount = 1;
291 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06054");
292 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
293 m_errorMonitor->VerifyFound();
stusmith15f24a82021-12-24 15:21:19 +0000294}
295
296TEST_F(VkLayerTest, DynamicRenderingWithMismatchingViewMask) {
297 TEST_DESCRIPTION("Draw with Dynamic Rendering and a mismatching viewMask");
298
299 SetTargetApiVersion(VK_API_VERSION_1_1);
300
301 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
302
303 ASSERT_NO_FATAL_FAILURE(InitFramework());
304
305 if (!AreRequestedExtensionsEnabled()) {
306 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
307 return;
308 }
309
310 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
311 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
312 return;
313 }
314
315 auto multiview_features = LvlInitStruct<VkPhysicalDeviceMultiviewFeatures>();
316 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(&multiview_features);
317 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
318 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
319 if (!dynamic_rendering_features.dynamicRendering) {
320 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
321 return;
322 }
323 if (!multiview_features.multiview) {
324 printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix);
325 return;
326 }
327
328 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
329
330 char const *fsSource = R"glsl(
331 #version 450
332 layout(location=0) out vec4 color;
333 void main() {
334 color = vec4(1.0f);
335 }
336 )glsl";
337
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800338 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
339 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000340
341 VkPipelineObj pipe(m_device);
342 pipe.AddShader(&vs);
343 pipe.AddShader(&fs);
344 pipe.AddDefaultColorAttachment();
345
346 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
347 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
348 const VkPipelineLayoutObj pl(m_device, {&dsl});
349
350 VkFormat color_formats = {VK_FORMAT_R8G8B8A8_UNORM};
351 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
352 pipeline_rendering_info.colorAttachmentCount = 1;
353 pipeline_rendering_info.pColorAttachmentFormats = &color_formats;
354 pipeline_rendering_info.viewMask = 1;
355
356 VkViewport viewport = {0, 0, 16, 16, 0, 1};
357 VkRect2D scissor = {{0, 0}, {16, 16}};
358 m_viewports.push_back(viewport);
359 m_scissors.push_back(scissor);
360 pipe.SetViewport(m_viewports);
361 pipe.SetScissor(m_scissors);
362
363 auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
364 pipe.InitGraphicsPipelineCreateInfo(&create_info);
365 create_info.pNext = &pipeline_rendering_info;
366
367 pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info);
368
369 VkRenderingAttachmentInfoKHR color_attachment = {};
370 color_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
371 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
372
373 VkRenderingInfoKHR begin_rendering_info = {};
374 begin_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR;
375 begin_rendering_info.colorAttachmentCount = 1;
376 begin_rendering_info.pColorAttachments = &color_attachment;
377 begin_rendering_info.viewMask = 2;
378 begin_rendering_info.layerCount = 1;
379
380 m_commandBuffer->begin();
381 m_commandBuffer->BeginRendering(begin_rendering_info);
382 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
383 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-viewMask-06178");
384 m_commandBuffer->Draw(1, 1, 0, 0);
385 m_errorMonitor->VerifyFound();
386 m_commandBuffer->EndRendering();
387 m_commandBuffer->end();
388}
389
390TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachments) {
391 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color attachment counts and depth/stencil formats");
392
393 SetTargetApiVersion(VK_API_VERSION_1_1);
394
395 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
396
397 ASSERT_NO_FATAL_FAILURE(InitFramework());
398
399 if (!AreRequestedExtensionsEnabled()) {
400 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
401 return;
402 }
403
404 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
405 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
406 return;
407 }
408
409 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
410 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
411 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
412 if (!dynamic_rendering_features.dynamicRendering) {
413 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
414 return;
415 }
416
417 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
418
419 char const *fsSource = R"glsl(
420 #version 450
421 layout(location=0) out vec4 color;
422 void main() {
423 color = vec4(1.0f);
424 }
425 )glsl";
426
427 VkViewport viewport = {0, 0, 16, 16, 0, 1};
428 VkRect2D scissor = {{0, 0}, {16, 16}};
429 m_viewports.push_back(viewport);
430 m_scissors.push_back(scissor);
431
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800432 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
433 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000434
435 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
436 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
437 const VkPipelineLayoutObj pl(m_device, {&dsl});
438
439 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
440
441 VkPipelineObj pipe1(m_device);
442 pipe1.AddShader(&vs);
443 pipe1.AddShader(&fs);
444 pipe1.AddDefaultColorAttachment();
445 pipe1.SetViewport(m_viewports);
446 pipe1.SetScissor(m_scissors);
447
448 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
449 pipeline_rendering_info.colorAttachmentCount = 1;
450 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
451
452 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
453 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
454 create_info1.pNext = &pipeline_rendering_info;
455
456 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
457
458 VkPipelineObj pipe2(m_device);
459 pipe2.AddShader(&vs);
460 pipe2.AddShader(&fs);
461 pipe2.AddDefaultColorAttachment();
462 pipe2.SetViewport(m_viewports);
463 pipe2.SetScissor(m_scissors);
464
465 pipeline_rendering_info.colorAttachmentCount = 0;
466 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
467 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D16_UNORM;
468
469 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
470 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
471 create_info2.pNext = &pipeline_rendering_info;
472
473 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
474
475 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
476 ASSERT_TRUE(depthStencilFormat != 0);
477
478 bool testStencil = false;
479 VkFormat stencilFormat = VK_FORMAT_UNDEFINED;
480
481 if (ImageFormatIsSupported(gpu(), VK_FORMAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
482 stencilFormat = VK_FORMAT_S8_UINT;
483 testStencil = true;
484 } else if ((depthStencilFormat != VK_FORMAT_D16_UNORM_S8_UINT) &&
485 ImageFormatIsSupported(gpu(), VK_FORMAT_D16_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
486 stencilFormat = VK_FORMAT_D16_UNORM_S8_UINT;
487 testStencil = true;
488 } else if ((depthStencilFormat != VK_FORMAT_D24_UNORM_S8_UINT) &&
489 ImageFormatIsSupported(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
490 stencilFormat = VK_FORMAT_D24_UNORM_S8_UINT;
491 testStencil = true;
492 } else if ((depthStencilFormat != VK_FORMAT_D32_SFLOAT_S8_UINT) &&
493 ImageFormatIsSupported(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) {
494 stencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
495 testStencil = true;
496 }
497
498 VkPipelineObj pipe3(m_device);
499
500 if (testStencil) {
501 pipe3.AddShader(&vs);
502 pipe3.AddShader(&fs);
503 pipe3.AddDefaultColorAttachment();
504 pipe3.SetViewport(m_viewports);
505 pipe3.SetScissor(m_scissors);
506
507 pipeline_rendering_info.colorAttachmentCount = 0;
508 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
509 pipeline_rendering_info.stencilAttachmentFormat = stencilFormat;
510
511 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
512 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
513 create_info3.pNext = &pipeline_rendering_info;
514
515 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
516 }
517
518 VkImageObj colorImage(m_device);
519 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
520 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT);
521
522 VkImageObj depthStencilImage(m_device);
523 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
524 VkImageView depthStencilImageView =
525 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
526
527 VkRenderingAttachmentInfoKHR color_attachment = {};
528 color_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
529 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
530 color_attachment.imageView = colorImageView;
531
532 VkRenderingAttachmentInfoKHR depth_stencil_attachment = {};
533 depth_stencil_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
534 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
535 depth_stencil_attachment.imageView = depthStencilImageView;
536
537 VkRenderingInfoKHR begin_rendering_info = {};
538 begin_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR;
539
540 m_commandBuffer->begin();
541
542 // Mismatching color attachment count
543 m_commandBuffer->BeginRendering(begin_rendering_info);
544 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
545 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06179");
546 m_commandBuffer->Draw(1, 1, 0, 0);
547 m_errorMonitor->VerifyFound();
548 m_commandBuffer->EndRendering();
549
550 // Mismatching color formats
551 begin_rendering_info.colorAttachmentCount = 1;
552 begin_rendering_info.pColorAttachments = &color_attachment;
553 m_commandBuffer->BeginRendering(begin_rendering_info);
554 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
555 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06180");
556 m_commandBuffer->Draw(1, 1, 0, 0);
557 m_errorMonitor->VerifyFound();
558 m_commandBuffer->EndRendering();
559
560 // Mismatching depth format
561 begin_rendering_info.colorAttachmentCount = 0;
562 begin_rendering_info.pColorAttachments = nullptr;
563 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
564 m_commandBuffer->BeginRendering(begin_rendering_info);
565 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
566 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06181");
567 m_commandBuffer->Draw(1, 1, 0, 0);
568 m_errorMonitor->VerifyFound();
569 m_commandBuffer->EndRendering();
570
571 // Mismatching stencil format
572 if (testStencil) {
573 begin_rendering_info.pDepthAttachment = nullptr;
574 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
575 m_commandBuffer->BeginRendering(begin_rendering_info);
576 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
577 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06182");
578 m_commandBuffer->Draw(1, 1, 0, 0);
579 m_errorMonitor->VerifyFound();
580 m_commandBuffer->EndRendering();
581 }
582
583 m_commandBuffer->end();
584}
585
586TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachmentSamples) {
587 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color/depth/stencil sample counts");
588
589 SetTargetApiVersion(VK_API_VERSION_1_1);
590
591 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
592
593 ASSERT_NO_FATAL_FAILURE(InitFramework());
594
595 if (!AreRequestedExtensionsEnabled()) {
596 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
597 return;
598 }
599
600 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
601 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
602 return;
603 }
604
605 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
606 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
607 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
608 if (!dynamic_rendering_features.dynamicRendering) {
609 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
610 return;
611 }
612
613 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
614
615 char const *fsSource = R"glsl(
616 #version 450
617 layout(location=0) out vec4 color;
618 void main() {
619 color = vec4(1.0f);
620 }
621 )glsl";
622
623 VkViewport viewport = {0, 0, 16, 16, 0, 1};
624 VkRect2D scissor = {{0, 0}, {16, 16}};
625 m_viewports.push_back(viewport);
626 m_scissors.push_back(scissor);
627
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800628 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
629 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000630
631 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
632 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
633 const VkPipelineLayoutObj pl(m_device, {&dsl});
634
635 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
636
637
638 VkPipelineObj pipe1(m_device);
639 pipe1.AddShader(&vs);
640 pipe1.AddShader(&fs);
641 pipe1.AddDefaultColorAttachment();
642 pipe1.SetViewport(m_viewports);
643 pipe1.SetScissor(m_scissors);
644
645 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
646 pipeline_rendering_info.colorAttachmentCount = 1;
647 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
648
649 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
650 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
651 create_info1.pNext = &pipeline_rendering_info;
652
653 auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>();
654 multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT;
655 create_info1.pMultisampleState = &multisample_state_create_info;
656
657 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
658
659
660 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
661 ASSERT_TRUE(depthStencilFormat != 0);
662
663
664 VkPipelineObj pipe2(m_device);
665 pipe2.AddShader(&vs);
666 pipe2.AddShader(&fs);
667 pipe2.AddDefaultColorAttachment();
668 pipe2.SetViewport(m_viewports);
669 pipe2.SetScissor(m_scissors);
670
671 pipeline_rendering_info.colorAttachmentCount = 0;
672 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
673 pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat;
674
675 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
676 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
677 create_info2.pNext = &pipeline_rendering_info;
678
679 create_info2.pMultisampleState = &multisample_state_create_info;
680
681 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
682
683
684 VkPipelineObj pipe3(m_device);
685
686 pipe3.AddShader(&vs);
687 pipe3.AddShader(&fs);
688 pipe3.AddDefaultColorAttachment();
689 pipe3.SetViewport(m_viewports);
690 pipe3.SetScissor(m_scissors);
691
692 pipeline_rendering_info.colorAttachmentCount = 0;
693 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
694 pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat;
695
696 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
697 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
698 create_info3.pNext = &pipeline_rendering_info;
699
700 create_info3.pMultisampleState = &multisample_state_create_info;
701
702 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
703
704
705 VkImageObj colorImage(m_device);
706 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
707 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM);
708
709 VkImageObj depthStencilImage(m_device);
710 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
711 VkImageView depthStencilImageView =
712 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
713
714 VkRenderingAttachmentInfoKHR color_attachment = {};
715 color_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
716 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
717 color_attachment.imageView = colorImageView;
718
719 VkRenderingAttachmentInfoKHR depth_stencil_attachment = {};
720 depth_stencil_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
721 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
722 depth_stencil_attachment.imageView = depthStencilImageView;
723
724 VkRenderingInfoKHR begin_rendering_info = {};
725 begin_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR;
726
727 m_commandBuffer->begin();
728
729 // Mismatching color samples
730 begin_rendering_info.colorAttachmentCount = 1;
731 begin_rendering_info.pColorAttachments = &color_attachment;
732 m_commandBuffer->BeginRendering(begin_rendering_info);
733 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
734 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06188");
735 m_commandBuffer->Draw(1, 1, 0, 0);
736 m_errorMonitor->VerifyFound();
737 m_commandBuffer->EndRendering();
738
739 // Mismatching depth samples
740 begin_rendering_info.colorAttachmentCount = 0;
741 begin_rendering_info.pColorAttachments = nullptr;
742 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
743 m_commandBuffer->BeginRendering(begin_rendering_info);
744 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
745 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189");
746 m_commandBuffer->Draw(1, 1, 0, 0);
747 m_errorMonitor->VerifyFound();
748 m_commandBuffer->EndRendering();
749
750 // Mismatching stencil samples
751 begin_rendering_info.pDepthAttachment = nullptr;
752 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
753 m_commandBuffer->BeginRendering(begin_rendering_info);
754 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
755 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190");
756 m_commandBuffer->Draw(1, 1, 0, 0);
757 m_errorMonitor->VerifyFound();
758 m_commandBuffer->EndRendering();
759
760 m_commandBuffer->end();
761}
762
763TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingMixedAttachmentSamples) {
764 TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching mixed color/depth/stencil sample counts");
765
766 SetTargetApiVersion(VK_API_VERSION_1_1);
767
768 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
769
770 ASSERT_NO_FATAL_FAILURE(InitFramework());
771
772 if (!AreRequestedExtensionsEnabled()) {
773 printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
774 return;
775 }
776
777 if (DeviceValidationVersion() < VK_API_VERSION_1_1) {
778 printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix);
779 return;
780 }
781
782 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
783 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
784 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
785 if (!dynamic_rendering_features.dynamicRendering) {
786 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
787 return;
788 }
789
790 bool amd_samples = false;
791 if (DeviceExtensionSupported(gpu(), nullptr, VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME)) {
792 m_device_extension_names.push_back(VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME);
793 amd_samples = true;
794 }
795
796 bool nv_samples = false;
797 if (DeviceExtensionSupported(gpu(), nullptr, VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME)) {
798 m_device_extension_names.push_back(VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME);
799 nv_samples = true;
800 }
801
802 if (!amd_samples && !nv_samples) {
803 printf("%s Test requires either VK_AMD_mixed_attachment_samples or VK_NV_framebuffer_mixed_samples, skipping\n",
804 kSkipPrefix);
805 return;
806 }
807
808 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
809
810 char const *fsSource = R"glsl(
811 #version 450
812 layout(location=0) out vec4 color;
813 void main() {
814 color = vec4(1.0f);
815 }
816 )glsl";
817
818 VkViewport viewport = {0, 0, 16, 16, 0, 1};
819 VkRect2D scissor = {{0, 0}, {16, 16}};
820 m_viewports.push_back(viewport);
821 m_scissors.push_back(scissor);
822
sfricke-samsungae54c1e2022-01-21 05:35:21 -0800823 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
824 VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT);
stusmith15f24a82021-12-24 15:21:19 +0000825
826 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
827 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
828 const VkPipelineLayoutObj pl(m_device, {&dsl});
829
830 VkSampleCountFlagBits counts = {VK_SAMPLE_COUNT_2_BIT};
831 auto samples_info = LvlInitStruct<VkAttachmentSampleCountInfoAMD>();
832
833 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(&samples_info);
834
835 VkPipelineObj pipe1(m_device);
836 pipe1.AddShader(&vs);
837 pipe1.AddShader(&fs);
838 pipe1.AddDefaultColorAttachment();
839 pipe1.SetViewport(m_viewports);
840 pipe1.SetScissor(m_scissors);
841
842 VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM};
843 pipeline_rendering_info.colorAttachmentCount = 1;
844 pipeline_rendering_info.pColorAttachmentFormats = color_formats;
845
846 samples_info.colorAttachmentCount = 1;
847 samples_info.pColorAttachmentSamples = &counts;
848
849 auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
850 pipe1.InitGraphicsPipelineCreateInfo(&create_info1);
851 create_info1.pNext = &pipeline_rendering_info;
852
853 pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1);
854
855 VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu());
856 ASSERT_TRUE(depthStencilFormat != 0);
857
858 VkPipelineObj pipe2(m_device);
859 pipe2.AddShader(&vs);
860 pipe2.AddShader(&fs);
861 pipe2.AddDefaultColorAttachment();
862 pipe2.SetViewport(m_viewports);
863 pipe2.SetScissor(m_scissors);
864
865 pipeline_rendering_info.colorAttachmentCount = 0;
866 pipeline_rendering_info.pColorAttachmentFormats = nullptr;
867 pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat;
868
869 samples_info.colorAttachmentCount = 0;
870 samples_info.pColorAttachmentSamples = nullptr;
871 samples_info.depthStencilAttachmentSamples = counts;
872
873 auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
874 pipe2.InitGraphicsPipelineCreateInfo(&create_info2);
875 create_info2.pNext = &pipeline_rendering_info;
876
877 pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2);
878
879 VkPipelineObj pipe3(m_device);
880
881 pipe3.AddShader(&vs);
882 pipe3.AddShader(&fs);
883 pipe3.AddDefaultColorAttachment();
884 pipe3.SetViewport(m_viewports);
885 pipe3.SetScissor(m_scissors);
886
887 pipeline_rendering_info.colorAttachmentCount = 0;
888 pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
889 pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat;
890
891 auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
892 pipe3.InitGraphicsPipelineCreateInfo(&create_info3);
893 create_info3.pNext = &pipeline_rendering_info;
894
895 pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3);
896
897 VkImageObj colorImage(m_device);
898 colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
899 VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM);
900
901 VkImageObj depthStencilImage(m_device);
902 depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
903 VkImageView depthStencilImageView =
904 depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT);
905
906 VkRenderingAttachmentInfoKHR color_attachment = {};
907 color_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
908 color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
909 color_attachment.imageView = colorImageView;
910
911 VkRenderingAttachmentInfoKHR depth_stencil_attachment = {};
912 depth_stencil_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR;
913 depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
914 depth_stencil_attachment.imageView = depthStencilImageView;
915
916 VkRenderingInfoKHR begin_rendering_info = {};
917 begin_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR;
918
919 m_commandBuffer->begin();
920
921 // Mismatching color samples
922 begin_rendering_info.colorAttachmentCount = 1;
923 begin_rendering_info.pColorAttachments = &color_attachment;
924 m_commandBuffer->BeginRendering(begin_rendering_info);
925 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle());
926 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06185");
927 m_commandBuffer->Draw(1, 1, 0, 0);
928 m_errorMonitor->VerifyFound();
929 m_commandBuffer->EndRendering();
930
931 // Mismatching depth samples
932 begin_rendering_info.colorAttachmentCount = 0;
933 begin_rendering_info.pColorAttachments = nullptr;
934 begin_rendering_info.pDepthAttachment = &depth_stencil_attachment;
935 m_commandBuffer->BeginRendering(begin_rendering_info);
936 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle());
937 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06186");
938 m_commandBuffer->Draw(1, 1, 0, 0);
939 m_errorMonitor->VerifyFound();
940 m_commandBuffer->EndRendering();
941
942 // Mismatching stencil samples
943 begin_rendering_info.pDepthAttachment = nullptr;
944 begin_rendering_info.pStencilAttachment = &depth_stencil_attachment;
945 m_commandBuffer->BeginRendering(begin_rendering_info);
946 vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle());
947 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06187");
948 m_commandBuffer->Draw(1, 1, 0, 0);
949 m_errorMonitor->VerifyFound();
950 m_commandBuffer->EndRendering();
951
952 m_commandBuffer->end();
953}
Aaron Hagan80034ea2021-12-23 11:24:09 -0500954
955TEST_F(VkLayerTest, DynamicRenderingAttachmentInfo) {
956 TEST_DESCRIPTION("AttachmentInfo Dynamic Rendering Tests.");
957
958 uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2);
959 if (version < VK_API_VERSION_1_2) {
960 printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix);
961 return;
962 }
963
964 AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
965
966 ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor));
967
968 if (DeviceValidationVersion() < VK_API_VERSION_1_2) {
969 printf("%s At least Vulkan version 1.2 is required for device, skipping test\n", kSkipPrefix);
970 return;
971 }
972
973 if (!AreRequestedExtensionsEnabled()) {
974 printf("%s %s is not supported; skipping\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
975 return;
976 }
977
978 auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>();
979 auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features);
980 vk::GetPhysicalDeviceFeatures2(gpu(), &features2);
981 if (!dynamic_rendering_features.dynamicRendering) {
982 printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix);
983 return;
984 }
985
986 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2));
987
988 VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT);
989 VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT);
990
991 VkPipelineObj pipe(m_device);
992 pipe.AddShader(&vs);
993 pipe.AddShader(&fs);
994 pipe.AddDefaultColorAttachment();
995
996 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
997 const VkDescriptorSetLayoutObj dsl(m_device, {dslb});
998 const VkPipelineLayoutObj pl(m_device, {&dsl});
999
1000 VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1001 auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>();
1002 pipeline_rendering_info.depthAttachmentFormat = depth_format;
1003
1004 auto pipeline_create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>();
1005 pipe.InitGraphicsPipelineCreateInfo(&pipeline_create_info);
1006 pipeline_create_info.pNext = &pipeline_rendering_info;
1007
1008 VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &pipeline_create_info);
1009 ASSERT_VK_SUCCESS(err);
1010
1011 VkImageObj image(m_device);
1012 VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>();
1013 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1014 image_create_info.format = depth_format;
1015 image_create_info.extent = {64, 64, 4};
1016 image_create_info.mipLevels = 1;
1017 image_create_info.arrayLayers = 1;
1018 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1019 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1020 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1021 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1022
1023 image.Init(image_create_info);
1024 ASSERT_TRUE(image.initialized());
1025
1026 VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1027 nullptr,
1028 0,
1029 image.handle(),
1030 VK_IMAGE_VIEW_TYPE_2D,
1031 depth_format,
1032 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
1033 VK_COMPONENT_SWIZZLE_IDENTITY},
1034 {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}};
1035
1036 VkImageView depth_image_view;
1037 err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view);
1038 ASSERT_VK_SUCCESS(err);
1039
1040 VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
1041 depth_attachment.imageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1042 depth_attachment.imageView = depth_image_view;
1043 depth_attachment.resolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT;
1044 depth_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1045
1046 VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>();
1047 begin_rendering_info.pDepthAttachment = &depth_attachment;
1048 begin_rendering_info.viewMask = 0x4;
1049
1050 VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map =
1051 LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>();
1052 fragment_density_map.imageView = depth_image_view;
1053 begin_rendering_info.pNext = &fragment_density_map;
1054
1055 m_commandBuffer->begin();
1056 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-multiview-06127");
1057 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-viewMask-06069");
Jeremy Gebben09c1a072022-02-08 09:42:47 -07001058 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06107");
1059 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06108");
1060 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06116");
Aaron Hagan80034ea2021-12-23 11:24:09 -05001061 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06129");
Jeremy Gebben09c1a072022-02-08 09:42:47 -07001062 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06145");
1063 m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06146");
Aaron Hagan80034ea2021-12-23 11:24:09 -05001064 m_commandBuffer->BeginRendering(begin_rendering_info);
1065 m_errorMonitor->VerifyFound();
1066}