Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 1 | /* |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 2 | * 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. |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 7 | * Modifications Copyright (C) 2021 ARM, Inc. All rights reserved. |
| 8 | * |
| 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 | |
| 20 | TEST_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-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 28 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 29 | 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-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 38 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 39 | 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-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 65 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 66 | 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"); |
| 78 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfoKHR-colorAttachmentCount-06004"); |
| 79 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfoKHR-variableMultisampleRate-06005"); |
| 80 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfoKHR-depthAttachmentFormat-06007"); |
| 81 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfoKHR-multiview-06008"); |
| 82 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfoKHR-viewMask-06009"); |
| 83 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, |
| 84 | "VUID-VkCommandBufferInheritanceRenderingInfoKHR-stencilAttachmentFormat-06199"); |
| 85 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, |
| 86 | "VUID-VkCommandBufferInheritanceRenderingInfoKHR-depthAttachmentFormat-06200"); |
| 87 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, |
| 88 | "VUID-VkCommandBufferInheritanceRenderingInfoKHR-pColorAttachmentFormats-06006"); |
| 89 | |
| 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 | |
| 97 | TEST_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-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 130 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 131 | VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 132 | |
| 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-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 141 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 142 | VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 143 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 144 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 145 | pipeline_rendering_info.stencilAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 146 | |
| 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-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 155 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 156 | 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-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 160 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 161 | |
| 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-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 183 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 184 | 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 | |
| 201 | TEST_F(VkLayerTest, DynamicRenderingGraphicsPipelineCreateInfo) { |
| 202 | TEST_DESCRIPTION("Test graphics pipeline creation with dynamic rendering."); |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 203 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 204 | 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; |
| 249 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 250 | auto pipeline_tessellation_state_info = LvlInitStruct<VkPipelineTessellationStateCreateInfo>(); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 251 | pipeline_tessellation_state_info.patchControlPoints = 1; |
| 252 | |
| 253 | auto pipeline_input_assembly_state_info = LvlInitStruct<VkPipelineInputAssemblyStateCreateInfo>(); |
| 254 | pipeline_input_assembly_state_info.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
| 255 | |
| 256 | auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 257 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 258 | VkShaderObj gs(this, bindStateGeomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT); |
| 259 | VkShaderObj te(this, bindStateTeshaderText, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); |
| 260 | VkShaderObj tc(this, bindStateTscShaderText, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 261 | pipe.AddShader(&vs); |
| 262 | pipe.AddShader(&gs); |
| 263 | pipe.AddShader(&te); |
| 264 | pipe.AddShader(&tc); |
| 265 | pipe.InitGraphicsPipelineCreateInfo(&create_info); |
| 266 | create_info.pColorBlendState = &color_blend_state_create_info; |
| 267 | create_info.pNext = &pipeline_rendering_info; |
| 268 | create_info.pTessellationState = &pipeline_tessellation_state_info; |
| 269 | create_info.pInputAssemblyState = &pipeline_input_assembly_state_info; |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 270 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 271 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06055"); |
| 272 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06057"); |
| 273 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06058"); |
| 274 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06060"); |
| 275 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06062"); |
| 276 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfoKHR-multiview-06066"); |
| 277 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkPipelineRenderingCreateInfoKHR-pColorAttachmentFormats-06064"); |
| 278 | pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info); |
| 279 | m_errorMonitor->VerifyFound(); |
| 280 | |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | TEST_F(VkLayerTest, DynamicRenderingWithMismatchingViewMask) { |
| 284 | TEST_DESCRIPTION("Draw with Dynamic Rendering and a mismatching viewMask"); |
| 285 | |
| 286 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 287 | |
| 288 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 289 | |
| 290 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 291 | |
| 292 | if (!AreRequestedExtensionsEnabled()) { |
| 293 | printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
| 298 | printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix); |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | auto multiview_features = LvlInitStruct<VkPhysicalDeviceMultiviewFeatures>(); |
| 303 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(&multiview_features); |
| 304 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 305 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 306 | if (!dynamic_rendering_features.dynamicRendering) { |
| 307 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 308 | return; |
| 309 | } |
| 310 | if (!multiview_features.multiview) { |
| 311 | printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix); |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 316 | |
| 317 | char const *fsSource = R"glsl( |
| 318 | #version 450 |
| 319 | layout(location=0) out vec4 color; |
| 320 | void main() { |
| 321 | color = vec4(1.0f); |
| 322 | } |
| 323 | )glsl"; |
| 324 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 325 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 326 | VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 327 | |
| 328 | VkPipelineObj pipe(m_device); |
| 329 | pipe.AddShader(&vs); |
| 330 | pipe.AddShader(&fs); |
| 331 | pipe.AddDefaultColorAttachment(); |
| 332 | |
| 333 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 334 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 335 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 336 | |
| 337 | VkFormat color_formats = {VK_FORMAT_R8G8B8A8_UNORM}; |
| 338 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 339 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 340 | pipeline_rendering_info.pColorAttachmentFormats = &color_formats; |
| 341 | pipeline_rendering_info.viewMask = 1; |
| 342 | |
| 343 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
| 344 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
| 345 | m_viewports.push_back(viewport); |
| 346 | m_scissors.push_back(scissor); |
| 347 | pipe.SetViewport(m_viewports); |
| 348 | pipe.SetScissor(m_scissors); |
| 349 | |
| 350 | auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 351 | pipe.InitGraphicsPipelineCreateInfo(&create_info); |
| 352 | create_info.pNext = &pipeline_rendering_info; |
| 353 | |
| 354 | pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info); |
| 355 | |
| 356 | VkRenderingAttachmentInfoKHR color_attachment = {}; |
| 357 | color_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR; |
| 358 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 359 | |
| 360 | VkRenderingInfoKHR begin_rendering_info = {}; |
| 361 | begin_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR; |
| 362 | begin_rendering_info.colorAttachmentCount = 1; |
| 363 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 364 | begin_rendering_info.viewMask = 2; |
| 365 | begin_rendering_info.layerCount = 1; |
| 366 | |
| 367 | m_commandBuffer->begin(); |
| 368 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 369 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 370 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-viewMask-06178"); |
| 371 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 372 | m_errorMonitor->VerifyFound(); |
| 373 | m_commandBuffer->EndRendering(); |
| 374 | m_commandBuffer->end(); |
| 375 | } |
| 376 | |
| 377 | TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachments) { |
| 378 | TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color attachment counts and depth/stencil formats"); |
| 379 | |
| 380 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 381 | |
| 382 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 383 | |
| 384 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 385 | |
| 386 | if (!AreRequestedExtensionsEnabled()) { |
| 387 | printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
| 392 | printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix); |
| 393 | return; |
| 394 | } |
| 395 | |
| 396 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 397 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 398 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 399 | if (!dynamic_rendering_features.dynamicRendering) { |
| 400 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 401 | return; |
| 402 | } |
| 403 | |
| 404 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 405 | |
| 406 | char const *fsSource = R"glsl( |
| 407 | #version 450 |
| 408 | layout(location=0) out vec4 color; |
| 409 | void main() { |
| 410 | color = vec4(1.0f); |
| 411 | } |
| 412 | )glsl"; |
| 413 | |
| 414 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
| 415 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
| 416 | m_viewports.push_back(viewport); |
| 417 | m_scissors.push_back(scissor); |
| 418 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 419 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 420 | VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 421 | |
| 422 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 423 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 424 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 425 | |
| 426 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 427 | |
| 428 | VkPipelineObj pipe1(m_device); |
| 429 | pipe1.AddShader(&vs); |
| 430 | pipe1.AddShader(&fs); |
| 431 | pipe1.AddDefaultColorAttachment(); |
| 432 | pipe1.SetViewport(m_viewports); |
| 433 | pipe1.SetScissor(m_scissors); |
| 434 | |
| 435 | VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM}; |
| 436 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 437 | pipeline_rendering_info.pColorAttachmentFormats = color_formats; |
| 438 | |
| 439 | auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 440 | pipe1.InitGraphicsPipelineCreateInfo(&create_info1); |
| 441 | create_info1.pNext = &pipeline_rendering_info; |
| 442 | |
| 443 | pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1); |
| 444 | |
| 445 | VkPipelineObj pipe2(m_device); |
| 446 | pipe2.AddShader(&vs); |
| 447 | pipe2.AddShader(&fs); |
| 448 | pipe2.AddDefaultColorAttachment(); |
| 449 | pipe2.SetViewport(m_viewports); |
| 450 | pipe2.SetScissor(m_scissors); |
| 451 | |
| 452 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 453 | pipeline_rendering_info.pColorAttachmentFormats = nullptr; |
| 454 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D16_UNORM; |
| 455 | |
| 456 | auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 457 | pipe2.InitGraphicsPipelineCreateInfo(&create_info2); |
| 458 | create_info2.pNext = &pipeline_rendering_info; |
| 459 | |
| 460 | pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2); |
| 461 | |
| 462 | VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu()); |
| 463 | ASSERT_TRUE(depthStencilFormat != 0); |
| 464 | |
| 465 | bool testStencil = false; |
| 466 | VkFormat stencilFormat = VK_FORMAT_UNDEFINED; |
| 467 | |
| 468 | if (ImageFormatIsSupported(gpu(), VK_FORMAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 469 | stencilFormat = VK_FORMAT_S8_UINT; |
| 470 | testStencil = true; |
| 471 | } else if ((depthStencilFormat != VK_FORMAT_D16_UNORM_S8_UINT) && |
| 472 | ImageFormatIsSupported(gpu(), VK_FORMAT_D16_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 473 | stencilFormat = VK_FORMAT_D16_UNORM_S8_UINT; |
| 474 | testStencil = true; |
| 475 | } else if ((depthStencilFormat != VK_FORMAT_D24_UNORM_S8_UINT) && |
| 476 | ImageFormatIsSupported(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 477 | stencilFormat = VK_FORMAT_D24_UNORM_S8_UINT; |
| 478 | testStencil = true; |
| 479 | } else if ((depthStencilFormat != VK_FORMAT_D32_SFLOAT_S8_UINT) && |
| 480 | ImageFormatIsSupported(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 481 | stencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 482 | testStencil = true; |
| 483 | } |
| 484 | |
| 485 | VkPipelineObj pipe3(m_device); |
| 486 | |
| 487 | if (testStencil) { |
| 488 | pipe3.AddShader(&vs); |
| 489 | pipe3.AddShader(&fs); |
| 490 | pipe3.AddDefaultColorAttachment(); |
| 491 | pipe3.SetViewport(m_viewports); |
| 492 | pipe3.SetScissor(m_scissors); |
| 493 | |
| 494 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 495 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED; |
| 496 | pipeline_rendering_info.stencilAttachmentFormat = stencilFormat; |
| 497 | |
| 498 | auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 499 | pipe3.InitGraphicsPipelineCreateInfo(&create_info3); |
| 500 | create_info3.pNext = &pipeline_rendering_info; |
| 501 | |
| 502 | pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3); |
| 503 | } |
| 504 | |
| 505 | VkImageObj colorImage(m_device); |
| 506 | colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 507 | VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT); |
| 508 | |
| 509 | VkImageObj depthStencilImage(m_device); |
| 510 | depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); |
| 511 | VkImageView depthStencilImageView = |
| 512 | depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 513 | |
| 514 | VkRenderingAttachmentInfoKHR color_attachment = {}; |
| 515 | color_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR; |
| 516 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 517 | color_attachment.imageView = colorImageView; |
| 518 | |
| 519 | VkRenderingAttachmentInfoKHR depth_stencil_attachment = {}; |
| 520 | depth_stencil_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR; |
| 521 | depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 522 | depth_stencil_attachment.imageView = depthStencilImageView; |
| 523 | |
| 524 | VkRenderingInfoKHR begin_rendering_info = {}; |
| 525 | begin_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR; |
| 526 | |
| 527 | m_commandBuffer->begin(); |
| 528 | |
| 529 | // Mismatching color attachment count |
| 530 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 531 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle()); |
| 532 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06179"); |
| 533 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 534 | m_errorMonitor->VerifyFound(); |
| 535 | m_commandBuffer->EndRendering(); |
| 536 | |
| 537 | // Mismatching color formats |
| 538 | begin_rendering_info.colorAttachmentCount = 1; |
| 539 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 540 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 541 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle()); |
| 542 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06180"); |
| 543 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 544 | m_errorMonitor->VerifyFound(); |
| 545 | m_commandBuffer->EndRendering(); |
| 546 | |
| 547 | // Mismatching depth format |
| 548 | begin_rendering_info.colorAttachmentCount = 0; |
| 549 | begin_rendering_info.pColorAttachments = nullptr; |
| 550 | begin_rendering_info.pDepthAttachment = &depth_stencil_attachment; |
| 551 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 552 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle()); |
| 553 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06181"); |
| 554 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 555 | m_errorMonitor->VerifyFound(); |
| 556 | m_commandBuffer->EndRendering(); |
| 557 | |
| 558 | // Mismatching stencil format |
| 559 | if (testStencil) { |
| 560 | begin_rendering_info.pDepthAttachment = nullptr; |
| 561 | begin_rendering_info.pStencilAttachment = &depth_stencil_attachment; |
| 562 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 563 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle()); |
| 564 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06182"); |
| 565 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 566 | m_errorMonitor->VerifyFound(); |
| 567 | m_commandBuffer->EndRendering(); |
| 568 | } |
| 569 | |
| 570 | m_commandBuffer->end(); |
| 571 | } |
| 572 | |
| 573 | TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachmentSamples) { |
| 574 | TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color/depth/stencil sample counts"); |
| 575 | |
| 576 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 577 | |
| 578 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 579 | |
| 580 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 581 | |
| 582 | if (!AreRequestedExtensionsEnabled()) { |
| 583 | printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
| 588 | printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix); |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 593 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 594 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 595 | if (!dynamic_rendering_features.dynamicRendering) { |
| 596 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 601 | |
| 602 | char const *fsSource = R"glsl( |
| 603 | #version 450 |
| 604 | layout(location=0) out vec4 color; |
| 605 | void main() { |
| 606 | color = vec4(1.0f); |
| 607 | } |
| 608 | )glsl"; |
| 609 | |
| 610 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
| 611 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
| 612 | m_viewports.push_back(viewport); |
| 613 | m_scissors.push_back(scissor); |
| 614 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 615 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 616 | VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 617 | |
| 618 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 619 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 620 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 621 | |
| 622 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 623 | |
| 624 | |
| 625 | VkPipelineObj pipe1(m_device); |
| 626 | pipe1.AddShader(&vs); |
| 627 | pipe1.AddShader(&fs); |
| 628 | pipe1.AddDefaultColorAttachment(); |
| 629 | pipe1.SetViewport(m_viewports); |
| 630 | pipe1.SetScissor(m_scissors); |
| 631 | |
| 632 | VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM}; |
| 633 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 634 | pipeline_rendering_info.pColorAttachmentFormats = color_formats; |
| 635 | |
| 636 | auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 637 | pipe1.InitGraphicsPipelineCreateInfo(&create_info1); |
| 638 | create_info1.pNext = &pipeline_rendering_info; |
| 639 | |
| 640 | auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>(); |
| 641 | multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT; |
| 642 | create_info1.pMultisampleState = &multisample_state_create_info; |
| 643 | |
| 644 | pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1); |
| 645 | |
| 646 | |
| 647 | VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu()); |
| 648 | ASSERT_TRUE(depthStencilFormat != 0); |
| 649 | |
| 650 | |
| 651 | VkPipelineObj pipe2(m_device); |
| 652 | pipe2.AddShader(&vs); |
| 653 | pipe2.AddShader(&fs); |
| 654 | pipe2.AddDefaultColorAttachment(); |
| 655 | pipe2.SetViewport(m_viewports); |
| 656 | pipe2.SetScissor(m_scissors); |
| 657 | |
| 658 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 659 | pipeline_rendering_info.pColorAttachmentFormats = nullptr; |
| 660 | pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat; |
| 661 | |
| 662 | auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 663 | pipe2.InitGraphicsPipelineCreateInfo(&create_info2); |
| 664 | create_info2.pNext = &pipeline_rendering_info; |
| 665 | |
| 666 | create_info2.pMultisampleState = &multisample_state_create_info; |
| 667 | |
| 668 | pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2); |
| 669 | |
| 670 | |
| 671 | VkPipelineObj pipe3(m_device); |
| 672 | |
| 673 | pipe3.AddShader(&vs); |
| 674 | pipe3.AddShader(&fs); |
| 675 | pipe3.AddDefaultColorAttachment(); |
| 676 | pipe3.SetViewport(m_viewports); |
| 677 | pipe3.SetScissor(m_scissors); |
| 678 | |
| 679 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 680 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED; |
| 681 | pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat; |
| 682 | |
| 683 | auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 684 | pipe3.InitGraphicsPipelineCreateInfo(&create_info3); |
| 685 | create_info3.pNext = &pipeline_rendering_info; |
| 686 | |
| 687 | create_info3.pMultisampleState = &multisample_state_create_info; |
| 688 | |
| 689 | pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3); |
| 690 | |
| 691 | |
| 692 | VkImageObj colorImage(m_device); |
| 693 | colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 694 | VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM); |
| 695 | |
| 696 | VkImageObj depthStencilImage(m_device); |
| 697 | depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); |
| 698 | VkImageView depthStencilImageView = |
| 699 | depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 700 | |
| 701 | VkRenderingAttachmentInfoKHR color_attachment = {}; |
| 702 | color_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR; |
| 703 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 704 | color_attachment.imageView = colorImageView; |
| 705 | |
| 706 | VkRenderingAttachmentInfoKHR depth_stencil_attachment = {}; |
| 707 | depth_stencil_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR; |
| 708 | depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 709 | depth_stencil_attachment.imageView = depthStencilImageView; |
| 710 | |
| 711 | VkRenderingInfoKHR begin_rendering_info = {}; |
| 712 | begin_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR; |
| 713 | |
| 714 | m_commandBuffer->begin(); |
| 715 | |
| 716 | // Mismatching color samples |
| 717 | begin_rendering_info.colorAttachmentCount = 1; |
| 718 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 719 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 720 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle()); |
| 721 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06188"); |
| 722 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 723 | m_errorMonitor->VerifyFound(); |
| 724 | m_commandBuffer->EndRendering(); |
| 725 | |
| 726 | // Mismatching depth samples |
| 727 | begin_rendering_info.colorAttachmentCount = 0; |
| 728 | begin_rendering_info.pColorAttachments = nullptr; |
| 729 | begin_rendering_info.pDepthAttachment = &depth_stencil_attachment; |
| 730 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 731 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle()); |
| 732 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189"); |
| 733 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 734 | m_errorMonitor->VerifyFound(); |
| 735 | m_commandBuffer->EndRendering(); |
| 736 | |
| 737 | // Mismatching stencil samples |
| 738 | begin_rendering_info.pDepthAttachment = nullptr; |
| 739 | begin_rendering_info.pStencilAttachment = &depth_stencil_attachment; |
| 740 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 741 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle()); |
| 742 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190"); |
| 743 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 744 | m_errorMonitor->VerifyFound(); |
| 745 | m_commandBuffer->EndRendering(); |
| 746 | |
| 747 | m_commandBuffer->end(); |
| 748 | } |
| 749 | |
| 750 | TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingMixedAttachmentSamples) { |
| 751 | TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching mixed color/depth/stencil sample counts"); |
| 752 | |
| 753 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 754 | |
| 755 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 756 | |
| 757 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 758 | |
| 759 | if (!AreRequestedExtensionsEnabled()) { |
| 760 | printf("%s %s Extension not supported, skipping tests\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 761 | return; |
| 762 | } |
| 763 | |
| 764 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
| 765 | printf("%s Tests requires Vulkan 1.1+, skipping test\n", kSkipPrefix); |
| 766 | return; |
| 767 | } |
| 768 | |
| 769 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 770 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 771 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 772 | if (!dynamic_rendering_features.dynamicRendering) { |
| 773 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 774 | return; |
| 775 | } |
| 776 | |
| 777 | bool amd_samples = false; |
| 778 | if (DeviceExtensionSupported(gpu(), nullptr, VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME)) { |
| 779 | m_device_extension_names.push_back(VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME); |
| 780 | amd_samples = true; |
| 781 | } |
| 782 | |
| 783 | bool nv_samples = false; |
| 784 | if (DeviceExtensionSupported(gpu(), nullptr, VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME)) { |
| 785 | m_device_extension_names.push_back(VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME); |
| 786 | nv_samples = true; |
| 787 | } |
| 788 | |
| 789 | if (!amd_samples && !nv_samples) { |
| 790 | printf("%s Test requires either VK_AMD_mixed_attachment_samples or VK_NV_framebuffer_mixed_samples, skipping\n", |
| 791 | kSkipPrefix); |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 796 | |
| 797 | char const *fsSource = R"glsl( |
| 798 | #version 450 |
| 799 | layout(location=0) out vec4 color; |
| 800 | void main() { |
| 801 | color = vec4(1.0f); |
| 802 | } |
| 803 | )glsl"; |
| 804 | |
| 805 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
| 806 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
| 807 | m_viewports.push_back(viewport); |
| 808 | m_scissors.push_back(scissor); |
| 809 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame^] | 810 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 811 | VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 812 | |
| 813 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 814 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 815 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 816 | |
| 817 | VkSampleCountFlagBits counts = {VK_SAMPLE_COUNT_2_BIT}; |
| 818 | auto samples_info = LvlInitStruct<VkAttachmentSampleCountInfoAMD>(); |
| 819 | |
| 820 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(&samples_info); |
| 821 | |
| 822 | VkPipelineObj pipe1(m_device); |
| 823 | pipe1.AddShader(&vs); |
| 824 | pipe1.AddShader(&fs); |
| 825 | pipe1.AddDefaultColorAttachment(); |
| 826 | pipe1.SetViewport(m_viewports); |
| 827 | pipe1.SetScissor(m_scissors); |
| 828 | |
| 829 | VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM}; |
| 830 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 831 | pipeline_rendering_info.pColorAttachmentFormats = color_formats; |
| 832 | |
| 833 | samples_info.colorAttachmentCount = 1; |
| 834 | samples_info.pColorAttachmentSamples = &counts; |
| 835 | |
| 836 | auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 837 | pipe1.InitGraphicsPipelineCreateInfo(&create_info1); |
| 838 | create_info1.pNext = &pipeline_rendering_info; |
| 839 | |
| 840 | pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1); |
| 841 | |
| 842 | VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu()); |
| 843 | ASSERT_TRUE(depthStencilFormat != 0); |
| 844 | |
| 845 | VkPipelineObj pipe2(m_device); |
| 846 | pipe2.AddShader(&vs); |
| 847 | pipe2.AddShader(&fs); |
| 848 | pipe2.AddDefaultColorAttachment(); |
| 849 | pipe2.SetViewport(m_viewports); |
| 850 | pipe2.SetScissor(m_scissors); |
| 851 | |
| 852 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 853 | pipeline_rendering_info.pColorAttachmentFormats = nullptr; |
| 854 | pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat; |
| 855 | |
| 856 | samples_info.colorAttachmentCount = 0; |
| 857 | samples_info.pColorAttachmentSamples = nullptr; |
| 858 | samples_info.depthStencilAttachmentSamples = counts; |
| 859 | |
| 860 | auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 861 | pipe2.InitGraphicsPipelineCreateInfo(&create_info2); |
| 862 | create_info2.pNext = &pipeline_rendering_info; |
| 863 | |
| 864 | pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2); |
| 865 | |
| 866 | VkPipelineObj pipe3(m_device); |
| 867 | |
| 868 | pipe3.AddShader(&vs); |
| 869 | pipe3.AddShader(&fs); |
| 870 | pipe3.AddDefaultColorAttachment(); |
| 871 | pipe3.SetViewport(m_viewports); |
| 872 | pipe3.SetScissor(m_scissors); |
| 873 | |
| 874 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 875 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED; |
| 876 | pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat; |
| 877 | |
| 878 | auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 879 | pipe3.InitGraphicsPipelineCreateInfo(&create_info3); |
| 880 | create_info3.pNext = &pipeline_rendering_info; |
| 881 | |
| 882 | pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3); |
| 883 | |
| 884 | VkImageObj colorImage(m_device); |
| 885 | colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 886 | VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM); |
| 887 | |
| 888 | VkImageObj depthStencilImage(m_device); |
| 889 | depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); |
| 890 | VkImageView depthStencilImageView = |
| 891 | depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 892 | |
| 893 | VkRenderingAttachmentInfoKHR color_attachment = {}; |
| 894 | color_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR; |
| 895 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 896 | color_attachment.imageView = colorImageView; |
| 897 | |
| 898 | VkRenderingAttachmentInfoKHR depth_stencil_attachment = {}; |
| 899 | depth_stencil_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR; |
| 900 | depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 901 | depth_stencil_attachment.imageView = depthStencilImageView; |
| 902 | |
| 903 | VkRenderingInfoKHR begin_rendering_info = {}; |
| 904 | begin_rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR; |
| 905 | |
| 906 | m_commandBuffer->begin(); |
| 907 | |
| 908 | // Mismatching color samples |
| 909 | begin_rendering_info.colorAttachmentCount = 1; |
| 910 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 911 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 912 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle()); |
| 913 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06185"); |
| 914 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 915 | m_errorMonitor->VerifyFound(); |
| 916 | m_commandBuffer->EndRendering(); |
| 917 | |
| 918 | // Mismatching depth samples |
| 919 | begin_rendering_info.colorAttachmentCount = 0; |
| 920 | begin_rendering_info.pColorAttachments = nullptr; |
| 921 | begin_rendering_info.pDepthAttachment = &depth_stencil_attachment; |
| 922 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 923 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle()); |
| 924 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06186"); |
| 925 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 926 | m_errorMonitor->VerifyFound(); |
| 927 | m_commandBuffer->EndRendering(); |
| 928 | |
| 929 | // Mismatching stencil samples |
| 930 | begin_rendering_info.pDepthAttachment = nullptr; |
| 931 | begin_rendering_info.pStencilAttachment = &depth_stencil_attachment; |
| 932 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 933 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle()); |
| 934 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06187"); |
| 935 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 936 | m_errorMonitor->VerifyFound(); |
| 937 | m_commandBuffer->EndRendering(); |
| 938 | |
| 939 | m_commandBuffer->end(); |
| 940 | } |