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. |
Tony-LunarG | 4c25337 | 2022-01-18 13:51:07 -0700 | [diff] [blame] | 7 | * Modifications Copyright (C) 2021-2022 ARM, Inc. All rights reserved. |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 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 | |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 20 | TEST_F(VkLayerTest, DynamicRenderingCommandBufferInheritanceRenderingInfo) { |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 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); |
Nathaniel Cesario | a06135e | 2022-03-02 21:22:30 -0700 | [diff] [blame] | 30 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 31 | |
Nathaniel Cesario | a06135e | 2022-03-02 21:22:30 -0700 | [diff] [blame] | 32 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 33 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 36 | if (DeviceValidationVersion() < VK_API_VERSION_1_2) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 37 | GTEST_SKIP() << "At least Vulkan version 1.2 is required"; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 38 | } |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 39 | |
Nathaniel Cesario | a06135e | 2022-03-02 21:22:30 -0700 | [diff] [blame] | 40 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 41 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 42 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 43 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 44 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 45 | return; |
| 46 | } |
| 47 | |
ziga-lunarg | f54cb2a | 2022-03-11 02:54:27 +0100 | [diff] [blame] | 48 | features2.features.variableMultisampleRate = VK_FALSE; |
| 49 | |
Nathaniel Cesario | a06135e | 2022-03-02 21:22:30 -0700 | [diff] [blame] | 50 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)); |
| 51 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 52 | VkPhysicalDeviceMultiviewProperties multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>(); |
| 53 | VkPhysicalDeviceProperties2 pd_props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&multiview_props); |
| 54 | vk::GetPhysicalDeviceProperties2(gpu(), &pd_props2); |
| 55 | |
| 56 | if (multiview_props.maxMultiviewViewCount == 32) { |
| 57 | printf("%s VUID is not testable as maxMultiviewViewCount is 32, skipping test\n", kSkipPrefix); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | VkFormat color_format = VK_FORMAT_D32_SFLOAT; |
| 62 | |
| 63 | auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>(); |
| 64 | cmd_buffer_inheritance_rendering_info.colorAttachmentCount = 1; |
| 65 | cmd_buffer_inheritance_rendering_info.pColorAttachmentFormats = &color_format; |
| 66 | cmd_buffer_inheritance_rendering_info.depthAttachmentFormat = VK_FORMAT_R8G8B8_UNORM; |
| 67 | cmd_buffer_inheritance_rendering_info.stencilAttachmentFormat = VK_FORMAT_R8G8B8_SNORM; |
| 68 | cmd_buffer_inheritance_rendering_info.viewMask = 1 << multiview_props.maxMultiviewViewCount; |
| 69 | |
| 70 | auto sample_count_info_amd = LvlInitStruct<VkAttachmentSampleCountInfoAMD>(); |
| 71 | sample_count_info_amd.pNext = &cmd_buffer_inheritance_rendering_info; |
| 72 | sample_count_info_amd.colorAttachmentCount = 2; |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 73 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 74 | auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>(); |
| 75 | cmd_buffer_inheritance_info.pNext = &sample_count_info_amd; |
| 76 | |
| 77 | auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>(); |
| 78 | cmd_buffer_allocate_info.commandPool = m_commandPool->handle(); |
| 79 | cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
| 80 | cmd_buffer_allocate_info.commandBufferCount = 0x1; |
| 81 | |
| 82 | VkCommandBuffer secondary_cmd_buffer; |
| 83 | VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer); |
| 84 | ASSERT_VK_SUCCESS(err); |
| 85 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06003"); |
Tony-LunarG | bbd2ab9 | 2021-12-02 08:31:24 -0700 | [diff] [blame] | 86 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-colorAttachmentCount-06004"); |
| 87 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-variableMultisampleRate-06005"); |
| 88 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06007"); |
| 89 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-multiview-06008"); |
| 90 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-viewMask-06009"); |
ziga-lunarg | 813fa01 | 2022-04-09 14:09:57 +0200 | [diff] [blame] | 91 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-stencilAttachmentFormat-06199"); |
| 92 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06200"); |
| 93 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-pColorAttachmentFormats-06006"); |
| 94 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferInheritanceRenderingInfo-depthAttachmentFormat-06540"); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 95 | |
| 96 | VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>(); |
| 97 | cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
| 98 | cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info; |
| 99 | vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info); |
| 100 | m_errorMonitor->VerifyFound(); |
| 101 | } |
| 102 | |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 103 | TEST_F(VkLayerTest, DynamicRenderingCommandDraw) { |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 104 | TEST_DESCRIPTION("vkCmdDraw* Dynamic Rendering Tests."); |
| 105 | |
| 106 | uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2); |
| 107 | if (version < VK_API_VERSION_1_2) { |
| 108 | printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 113 | |
| 114 | ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); |
| 115 | |
| 116 | if (DeviceValidationVersion() < VK_API_VERSION_1_2) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 117 | GTEST_SKIP() << "At least Vulkan version 1.2 is required"; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 121 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 125 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 126 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 127 | if (!dynamic_rendering_features.dynamicRendering) { |
| 128 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 133 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 134 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 135 | VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 136 | |
| 137 | VkPipelineObj pipe(m_device); |
| 138 | pipe.AddShader(&vs); |
| 139 | pipe.AddShader(&fs); |
| 140 | pipe.AddDefaultColorAttachment(); |
| 141 | |
| 142 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 143 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 144 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 145 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 146 | VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 147 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 148 | pipeline_rendering_info.depthAttachmentFormat = depth_format; |
| 149 | pipeline_rendering_info.stencilAttachmentFormat = depth_format; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 150 | |
| 151 | auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>(); |
| 152 | multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT; |
| 153 | |
| 154 | auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 155 | pipe.InitGraphicsPipelineCreateInfo(&create_info); |
| 156 | create_info.pMultisampleState = &multisample_state_create_info; |
| 157 | create_info.renderPass = VkRenderPass(0x1); |
| 158 | create_info.pNext = &pipeline_rendering_info; |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 159 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 160 | VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info); |
| 161 | ASSERT_VK_SUCCESS(err); |
| 162 | |
| 163 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 164 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 165 | |
| 166 | VkImageObj image(m_device); |
| 167 | image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_LINEAR, 0); |
| 168 | ASSERT_TRUE(image.initialized()); |
| 169 | |
| 170 | VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, |
| 171 | nullptr, |
| 172 | 0, |
| 173 | image.handle(), |
| 174 | VK_IMAGE_VIEW_TYPE_2D, |
| 175 | depth_format, |
| 176 | {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, |
| 177 | VK_COMPONENT_SWIZZLE_IDENTITY}, |
| 178 | {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}}; |
| 179 | |
| 180 | VkImageView depth_image_view; |
| 181 | err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view); |
| 182 | ASSERT_VK_SUCCESS(err); |
| 183 | |
| 184 | VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 185 | depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL; |
| 186 | depth_attachment.imageView = depth_image_view; |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 187 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 188 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
| 189 | begin_rendering_info.pDepthAttachment = &depth_attachment; |
| 190 | begin_rendering_info.pStencilAttachment = &depth_attachment; |
| 191 | |
| 192 | m_commandBuffer->begin(); |
| 193 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 194 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 195 | vk::CmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport); |
| 196 | vk::CmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor); |
| 197 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189"); |
| 198 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190"); |
| 199 | vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0); |
| 200 | m_errorMonitor->VerifyFound(); |
| 201 | m_commandBuffer->EndRendering(); |
| 202 | m_commandBuffer->end(); |
| 203 | } |
| 204 | |
| 205 | TEST_F(VkLayerTest, DynamicRenderingGraphicsPipelineCreateInfo) { |
| 206 | TEST_DESCRIPTION("Test graphics pipeline creation with dynamic rendering."); |
Nathaniel Cesario | 72f2955 | 2022-03-24 05:11:11 -0600 | [diff] [blame] | 207 | m_errorMonitor->ExpectSuccess(); |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 208 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 209 | uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2); |
| 210 | if (version < VK_API_VERSION_1_2) { |
| 211 | printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 216 | |
| 217 | ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); |
| 218 | |
| 219 | if (DeviceValidationVersion() < VK_API_VERSION_1_2) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 220 | GTEST_SKIP() << "At least Vulkan version 1.2 is required"; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 224 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 228 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 229 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 230 | if (!dynamic_rendering_features.dynamicRendering) { |
| 231 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 236 | |
| 237 | const VkPipelineLayoutObj pl(m_device); |
| 238 | VkPipelineObj pipe(m_device); |
| 239 | |
| 240 | VkPipelineColorBlendAttachmentState color_blend_attachment_state = {}; |
| 241 | |
| 242 | auto color_blend_state_create_info = LvlInitStruct<VkPipelineColorBlendStateCreateInfo>(); |
| 243 | color_blend_state_create_info.attachmentCount = 1; |
| 244 | color_blend_state_create_info.pAttachments = &color_blend_attachment_state; |
| 245 | |
| 246 | VkFormat color_format[2] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_D32_SFLOAT_S8_UINT}; |
| 247 | |
| 248 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 249 | pipeline_rendering_info.colorAttachmentCount = 2; |
| 250 | pipeline_rendering_info.pColorAttachmentFormats = &color_format[0]; |
| 251 | pipeline_rendering_info.viewMask = 0x2; |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 252 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 253 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 254 | auto pipeline_tessellation_state_info = LvlInitStruct<VkPipelineTessellationStateCreateInfo>(); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 255 | pipeline_tessellation_state_info.patchControlPoints = 1; |
| 256 | |
| 257 | auto pipeline_input_assembly_state_info = LvlInitStruct<VkPipelineInputAssemblyStateCreateInfo>(); |
| 258 | pipeline_input_assembly_state_info.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
| 259 | |
| 260 | auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 261 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 262 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 263 | VkShaderObj gs(this, bindStateGeomShaderText, VK_SHADER_STAGE_GEOMETRY_BIT); |
| 264 | VkShaderObj te(this, bindStateTeshaderText, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); |
| 265 | VkShaderObj tc(this, bindStateTscShaderText, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 266 | VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT); |
| 267 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 268 | pipe.AddShader(&vs); |
| 269 | pipe.AddShader(&gs); |
| 270 | pipe.AddShader(&te); |
| 271 | pipe.AddShader(&tc); |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 272 | pipe.AddShader(&fs); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 273 | pipe.InitGraphicsPipelineCreateInfo(&create_info); |
Nathaniel Cesario | 72f2955 | 2022-03-24 05:11:11 -0600 | [diff] [blame] | 274 | m_errorMonitor->VerifyNotFound(); |
| 275 | |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 276 | create_info.pColorBlendState = &color_blend_state_create_info; |
| 277 | create_info.pNext = &pipeline_rendering_info; |
| 278 | create_info.pTessellationState = &pipeline_tessellation_state_info; |
| 279 | create_info.pInputAssemblyState = &pipeline_input_assembly_state_info; |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 280 | |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 281 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06053"); |
Nathaniel Cesario | 72f2955 | 2022-03-24 05:11:11 -0600 | [diff] [blame] | 282 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06581"); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 283 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06055"); |
| 284 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06057"); |
| 285 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06058"); |
| 286 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06060"); |
Nathaniel Cesario | a611857 | 2022-03-24 04:48:33 -0600 | [diff] [blame] | 287 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-multiview-06577"); |
Aaron Hagan | aca5044 | 2021-12-07 22:26:29 -0500 | [diff] [blame] | 288 | pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info); |
| 289 | m_errorMonitor->VerifyFound(); |
| 290 | |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 291 | create_info.pColorBlendState = nullptr; |
| 292 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED; |
| 293 | pipeline_rendering_info.viewMask = 0x0; |
| 294 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 295 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06054"); |
| 296 | pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info); |
| 297 | m_errorMonitor->VerifyFound(); |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 298 | |
ziga-lunarg | 5e67160 | 2022-03-17 19:06:55 +0100 | [diff] [blame] | 299 | color_format[0] = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 300 | color_blend_attachment_state.blendEnable = VK_TRUE; |
| 301 | create_info.pColorBlendState = &color_blend_state_create_info; |
Nathaniel Cesario | 72f2955 | 2022-03-24 05:11:11 -0600 | [diff] [blame] | 302 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06581"); |
ziga-lunarg | 5e67160 | 2022-03-17 19:06:55 +0100 | [diff] [blame] | 303 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06062"); |
ziga-lunarg | 5e67160 | 2022-03-17 19:06:55 +0100 | [diff] [blame] | 304 | pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info); |
| 305 | m_errorMonitor->VerifyFound(); |
| 306 | color_format[0] = VK_FORMAT_R8G8B8A8_UNORM; |
| 307 | |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 308 | auto ds_ci = LvlInitStruct<VkPipelineDepthStencilStateCreateInfo>(); |
| 309 | ds_ci.flags = VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_ARM; |
| 310 | color_blend_state_create_info.flags = VK_PIPELINE_COLOR_BLEND_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_BIT_ARM; |
| 311 | create_info.pColorBlendState = &color_blend_state_create_info; |
| 312 | create_info.pDepthStencilState = &ds_ci; |
| 313 | create_info.renderPass = VK_NULL_HANDLE; |
| 314 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 315 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06482"); |
| 316 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-flags-06483"); |
| 317 | pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info); |
| 318 | m_errorMonitor->VerifyFound(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | TEST_F(VkLayerTest, DynamicRenderingWithMismatchingViewMask) { |
| 322 | TEST_DESCRIPTION("Draw with Dynamic Rendering and a mismatching viewMask"); |
| 323 | |
| 324 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 325 | |
| 326 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 327 | |
| 328 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 329 | |
| 330 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 331 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 335 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | auto multiview_features = LvlInitStruct<VkPhysicalDeviceMultiviewFeatures>(); |
| 339 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(&multiview_features); |
| 340 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 341 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 342 | if (!dynamic_rendering_features.dynamicRendering) { |
| 343 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 344 | return; |
| 345 | } |
| 346 | if (!multiview_features.multiview) { |
| 347 | printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 352 | |
| 353 | char const *fsSource = R"glsl( |
| 354 | #version 450 |
| 355 | layout(location=0) out vec4 color; |
| 356 | void main() { |
| 357 | color = vec4(1.0f); |
| 358 | } |
| 359 | )glsl"; |
| 360 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 361 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 362 | VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 363 | |
| 364 | VkPipelineObj pipe(m_device); |
| 365 | pipe.AddShader(&vs); |
| 366 | pipe.AddShader(&fs); |
| 367 | pipe.AddDefaultColorAttachment(); |
| 368 | |
| 369 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 370 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 371 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 372 | |
| 373 | VkFormat color_formats = {VK_FORMAT_R8G8B8A8_UNORM}; |
| 374 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 375 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 376 | pipeline_rendering_info.pColorAttachmentFormats = &color_formats; |
| 377 | pipeline_rendering_info.viewMask = 1; |
| 378 | |
| 379 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
| 380 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
| 381 | m_viewports.push_back(viewport); |
| 382 | m_scissors.push_back(scissor); |
| 383 | pipe.SetViewport(m_viewports); |
| 384 | pipe.SetScissor(m_scissors); |
| 385 | |
| 386 | auto create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 387 | pipe.InitGraphicsPipelineCreateInfo(&create_info); |
| 388 | create_info.pNext = &pipeline_rendering_info; |
| 389 | |
| 390 | pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info); |
| 391 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 392 | VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 393 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 394 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 395 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 396 | begin_rendering_info.colorAttachmentCount = 1; |
| 397 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 398 | begin_rendering_info.viewMask = 2; |
| 399 | begin_rendering_info.layerCount = 1; |
| 400 | |
| 401 | m_commandBuffer->begin(); |
| 402 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 403 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 404 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-viewMask-06178"); |
| 405 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 406 | m_errorMonitor->VerifyFound(); |
| 407 | m_commandBuffer->EndRendering(); |
| 408 | m_commandBuffer->end(); |
| 409 | } |
| 410 | |
| 411 | TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachments) { |
| 412 | TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color attachment counts and depth/stencil formats"); |
| 413 | |
| 414 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 415 | |
| 416 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 417 | |
| 418 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 419 | |
| 420 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 421 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 425 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 429 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 430 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 431 | if (!dynamic_rendering_features.dynamicRendering) { |
| 432 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 437 | |
| 438 | char const *fsSource = R"glsl( |
| 439 | #version 450 |
| 440 | layout(location=0) out vec4 color; |
| 441 | void main() { |
| 442 | color = vec4(1.0f); |
| 443 | } |
| 444 | )glsl"; |
| 445 | |
| 446 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
| 447 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
| 448 | m_viewports.push_back(viewport); |
| 449 | m_scissors.push_back(scissor); |
| 450 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 451 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 452 | VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 453 | |
| 454 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 455 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 456 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 457 | |
| 458 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 459 | |
| 460 | VkPipelineObj pipe1(m_device); |
| 461 | pipe1.AddShader(&vs); |
| 462 | pipe1.AddShader(&fs); |
| 463 | pipe1.AddDefaultColorAttachment(); |
| 464 | pipe1.SetViewport(m_viewports); |
| 465 | pipe1.SetScissor(m_scissors); |
| 466 | |
| 467 | VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM}; |
| 468 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 469 | pipeline_rendering_info.pColorAttachmentFormats = color_formats; |
| 470 | |
| 471 | auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 472 | pipe1.InitGraphicsPipelineCreateInfo(&create_info1); |
| 473 | create_info1.pNext = &pipeline_rendering_info; |
| 474 | |
| 475 | pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1); |
| 476 | |
| 477 | VkPipelineObj pipe2(m_device); |
| 478 | pipe2.AddShader(&vs); |
| 479 | pipe2.AddShader(&fs); |
| 480 | pipe2.AddDefaultColorAttachment(); |
| 481 | pipe2.SetViewport(m_viewports); |
| 482 | pipe2.SetScissor(m_scissors); |
| 483 | |
| 484 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 485 | pipeline_rendering_info.pColorAttachmentFormats = nullptr; |
| 486 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_D16_UNORM; |
| 487 | |
| 488 | auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 489 | pipe2.InitGraphicsPipelineCreateInfo(&create_info2); |
| 490 | create_info2.pNext = &pipeline_rendering_info; |
| 491 | |
| 492 | pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2); |
| 493 | |
| 494 | VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu()); |
| 495 | ASSERT_TRUE(depthStencilFormat != 0); |
| 496 | |
| 497 | bool testStencil = false; |
| 498 | VkFormat stencilFormat = VK_FORMAT_UNDEFINED; |
| 499 | |
| 500 | if (ImageFormatIsSupported(gpu(), VK_FORMAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 501 | stencilFormat = VK_FORMAT_S8_UINT; |
| 502 | testStencil = true; |
| 503 | } else if ((depthStencilFormat != VK_FORMAT_D16_UNORM_S8_UINT) && |
| 504 | ImageFormatIsSupported(gpu(), VK_FORMAT_D16_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 505 | stencilFormat = VK_FORMAT_D16_UNORM_S8_UINT; |
| 506 | testStencil = true; |
| 507 | } else if ((depthStencilFormat != VK_FORMAT_D24_UNORM_S8_UINT) && |
| 508 | ImageFormatIsSupported(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 509 | stencilFormat = VK_FORMAT_D24_UNORM_S8_UINT; |
| 510 | testStencil = true; |
| 511 | } else if ((depthStencilFormat != VK_FORMAT_D32_SFLOAT_S8_UINT) && |
| 512 | ImageFormatIsSupported(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 513 | stencilFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 514 | testStencil = true; |
| 515 | } |
| 516 | |
| 517 | VkPipelineObj pipe3(m_device); |
| 518 | |
| 519 | if (testStencil) { |
| 520 | pipe3.AddShader(&vs); |
| 521 | pipe3.AddShader(&fs); |
| 522 | pipe3.AddDefaultColorAttachment(); |
| 523 | pipe3.SetViewport(m_viewports); |
| 524 | pipe3.SetScissor(m_scissors); |
| 525 | |
| 526 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 527 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED; |
| 528 | pipeline_rendering_info.stencilAttachmentFormat = stencilFormat; |
| 529 | |
| 530 | auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 531 | pipe3.InitGraphicsPipelineCreateInfo(&create_info3); |
| 532 | create_info3.pNext = &pipeline_rendering_info; |
| 533 | |
| 534 | pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3); |
| 535 | } |
| 536 | |
| 537 | VkImageObj colorImage(m_device); |
| 538 | colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 539 | VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT); |
| 540 | |
| 541 | VkImageObj depthStencilImage(m_device); |
| 542 | depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); |
| 543 | VkImageView depthStencilImageView = |
| 544 | depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 545 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 546 | VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 547 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 548 | color_attachment.imageView = colorImageView; |
| 549 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 550 | VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 551 | depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 552 | depth_stencil_attachment.imageView = depthStencilImageView; |
| 553 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 554 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 555 | m_commandBuffer->begin(); |
| 556 | |
| 557 | // Mismatching color attachment count |
| 558 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 559 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle()); |
| 560 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06179"); |
| 561 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 562 | m_errorMonitor->VerifyFound(); |
| 563 | m_commandBuffer->EndRendering(); |
| 564 | |
| 565 | // Mismatching color formats |
| 566 | begin_rendering_info.colorAttachmentCount = 1; |
| 567 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 568 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 569 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle()); |
| 570 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06180"); |
| 571 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 572 | m_errorMonitor->VerifyFound(); |
| 573 | m_commandBuffer->EndRendering(); |
| 574 | |
| 575 | // Mismatching depth format |
| 576 | begin_rendering_info.colorAttachmentCount = 0; |
| 577 | begin_rendering_info.pColorAttachments = nullptr; |
| 578 | begin_rendering_info.pDepthAttachment = &depth_stencil_attachment; |
| 579 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 580 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle()); |
| 581 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06181"); |
| 582 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 583 | m_errorMonitor->VerifyFound(); |
| 584 | m_commandBuffer->EndRendering(); |
| 585 | |
| 586 | // Mismatching stencil format |
| 587 | if (testStencil) { |
| 588 | begin_rendering_info.pDepthAttachment = nullptr; |
| 589 | begin_rendering_info.pStencilAttachment = &depth_stencil_attachment; |
| 590 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 591 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle()); |
| 592 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06182"); |
| 593 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 594 | m_errorMonitor->VerifyFound(); |
| 595 | m_commandBuffer->EndRendering(); |
| 596 | } |
| 597 | |
| 598 | m_commandBuffer->end(); |
| 599 | } |
| 600 | |
| 601 | TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingAttachmentSamples) { |
| 602 | TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching color/depth/stencil sample counts"); |
| 603 | |
| 604 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 605 | |
| 606 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 607 | |
| 608 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 609 | |
| 610 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 611 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 615 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 619 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 620 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 621 | if (!dynamic_rendering_features.dynamicRendering) { |
| 622 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 623 | return; |
| 624 | } |
| 625 | |
| 626 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 627 | |
| 628 | char const *fsSource = R"glsl( |
| 629 | #version 450 |
| 630 | layout(location=0) out vec4 color; |
| 631 | void main() { |
| 632 | color = vec4(1.0f); |
| 633 | } |
| 634 | )glsl"; |
| 635 | |
| 636 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
| 637 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
| 638 | m_viewports.push_back(viewport); |
| 639 | m_scissors.push_back(scissor); |
| 640 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 641 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 642 | VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 643 | |
| 644 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 645 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 646 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 647 | |
| 648 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 649 | |
| 650 | |
| 651 | VkPipelineObj pipe1(m_device); |
| 652 | pipe1.AddShader(&vs); |
| 653 | pipe1.AddShader(&fs); |
| 654 | pipe1.AddDefaultColorAttachment(); |
| 655 | pipe1.SetViewport(m_viewports); |
| 656 | pipe1.SetScissor(m_scissors); |
| 657 | |
| 658 | VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM}; |
| 659 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 660 | pipeline_rendering_info.pColorAttachmentFormats = color_formats; |
| 661 | |
| 662 | auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 663 | pipe1.InitGraphicsPipelineCreateInfo(&create_info1); |
| 664 | create_info1.pNext = &pipeline_rendering_info; |
| 665 | |
| 666 | auto multisample_state_create_info = LvlInitStruct<VkPipelineMultisampleStateCreateInfo>(); |
| 667 | multisample_state_create_info.rasterizationSamples = VK_SAMPLE_COUNT_2_BIT; |
| 668 | create_info1.pMultisampleState = &multisample_state_create_info; |
| 669 | |
| 670 | pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1); |
| 671 | |
| 672 | |
| 673 | VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu()); |
| 674 | ASSERT_TRUE(depthStencilFormat != 0); |
| 675 | |
| 676 | |
| 677 | VkPipelineObj pipe2(m_device); |
| 678 | pipe2.AddShader(&vs); |
| 679 | pipe2.AddShader(&fs); |
| 680 | pipe2.AddDefaultColorAttachment(); |
| 681 | pipe2.SetViewport(m_viewports); |
| 682 | pipe2.SetScissor(m_scissors); |
| 683 | |
| 684 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 685 | pipeline_rendering_info.pColorAttachmentFormats = nullptr; |
| 686 | pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat; |
| 687 | |
| 688 | auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 689 | pipe2.InitGraphicsPipelineCreateInfo(&create_info2); |
| 690 | create_info2.pNext = &pipeline_rendering_info; |
| 691 | |
| 692 | create_info2.pMultisampleState = &multisample_state_create_info; |
| 693 | |
| 694 | pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2); |
| 695 | |
| 696 | |
| 697 | VkPipelineObj pipe3(m_device); |
| 698 | |
| 699 | pipe3.AddShader(&vs); |
| 700 | pipe3.AddShader(&fs); |
| 701 | pipe3.AddDefaultColorAttachment(); |
| 702 | pipe3.SetViewport(m_viewports); |
| 703 | pipe3.SetScissor(m_scissors); |
| 704 | |
| 705 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 706 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED; |
| 707 | pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat; |
| 708 | |
| 709 | auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 710 | pipe3.InitGraphicsPipelineCreateInfo(&create_info3); |
| 711 | create_info3.pNext = &pipeline_rendering_info; |
| 712 | |
| 713 | create_info3.pMultisampleState = &multisample_state_create_info; |
| 714 | |
| 715 | pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3); |
| 716 | |
| 717 | |
| 718 | VkImageObj colorImage(m_device); |
| 719 | colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 720 | VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM); |
| 721 | |
| 722 | VkImageObj depthStencilImage(m_device); |
| 723 | depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); |
| 724 | VkImageView depthStencilImageView = |
| 725 | depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 726 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 727 | VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 728 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 729 | color_attachment.imageView = colorImageView; |
| 730 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 731 | VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 732 | depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 733 | depth_stencil_attachment.imageView = depthStencilImageView; |
| 734 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 735 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 736 | m_commandBuffer->begin(); |
| 737 | |
| 738 | // Mismatching color samples |
| 739 | begin_rendering_info.colorAttachmentCount = 1; |
| 740 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 741 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 742 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle()); |
| 743 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06188"); |
| 744 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 745 | m_errorMonitor->VerifyFound(); |
| 746 | m_commandBuffer->EndRendering(); |
| 747 | |
| 748 | // Mismatching depth samples |
| 749 | begin_rendering_info.colorAttachmentCount = 0; |
| 750 | begin_rendering_info.pColorAttachments = nullptr; |
| 751 | begin_rendering_info.pDepthAttachment = &depth_stencil_attachment; |
| 752 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 753 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle()); |
| 754 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06189"); |
| 755 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 756 | m_errorMonitor->VerifyFound(); |
| 757 | m_commandBuffer->EndRendering(); |
| 758 | |
| 759 | // Mismatching stencil samples |
| 760 | begin_rendering_info.pDepthAttachment = nullptr; |
| 761 | begin_rendering_info.pStencilAttachment = &depth_stencil_attachment; |
| 762 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 763 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle()); |
| 764 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06190"); |
| 765 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 766 | m_errorMonitor->VerifyFound(); |
| 767 | m_commandBuffer->EndRendering(); |
| 768 | |
| 769 | m_commandBuffer->end(); |
| 770 | } |
| 771 | |
| 772 | TEST_F(VkLayerTest, DynamicRenderingWithMistmatchingMixedAttachmentSamples) { |
| 773 | TEST_DESCRIPTION("Draw with Dynamic Rendering with mismatching mixed color/depth/stencil sample counts"); |
| 774 | |
| 775 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 776 | |
| 777 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 778 | |
| 779 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 780 | |
| 781 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 782 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 786 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 790 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 791 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 792 | if (!dynamic_rendering_features.dynamicRendering) { |
| 793 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 794 | return; |
| 795 | } |
| 796 | |
| 797 | bool amd_samples = false; |
| 798 | if (DeviceExtensionSupported(gpu(), nullptr, VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME)) { |
| 799 | m_device_extension_names.push_back(VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME); |
| 800 | amd_samples = true; |
| 801 | } |
| 802 | |
| 803 | bool nv_samples = false; |
| 804 | if (DeviceExtensionSupported(gpu(), nullptr, VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME)) { |
| 805 | m_device_extension_names.push_back(VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME); |
| 806 | nv_samples = true; |
| 807 | } |
| 808 | |
| 809 | if (!amd_samples && !nv_samples) { |
| 810 | printf("%s Test requires either VK_AMD_mixed_attachment_samples or VK_NV_framebuffer_mixed_samples, skipping\n", |
| 811 | kSkipPrefix); |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 816 | |
| 817 | char const *fsSource = R"glsl( |
| 818 | #version 450 |
| 819 | layout(location=0) out vec4 color; |
| 820 | void main() { |
| 821 | color = vec4(1.0f); |
| 822 | } |
| 823 | )glsl"; |
| 824 | |
| 825 | VkViewport viewport = {0, 0, 16, 16, 0, 1}; |
| 826 | VkRect2D scissor = {{0, 0}, {16, 16}}; |
| 827 | m_viewports.push_back(viewport); |
| 828 | m_scissors.push_back(scissor); |
| 829 | |
sfricke-samsung | ae54c1e | 2022-01-21 05:35:21 -0800 | [diff] [blame] | 830 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 831 | VkShaderObj fs(this, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 832 | |
| 833 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 834 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 835 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 836 | |
| 837 | VkSampleCountFlagBits counts = {VK_SAMPLE_COUNT_2_BIT}; |
| 838 | auto samples_info = LvlInitStruct<VkAttachmentSampleCountInfoAMD>(); |
| 839 | |
| 840 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(&samples_info); |
| 841 | |
| 842 | VkPipelineObj pipe1(m_device); |
| 843 | pipe1.AddShader(&vs); |
| 844 | pipe1.AddShader(&fs); |
| 845 | pipe1.AddDefaultColorAttachment(); |
| 846 | pipe1.SetViewport(m_viewports); |
| 847 | pipe1.SetScissor(m_scissors); |
| 848 | |
| 849 | VkFormat color_formats[] = {VK_FORMAT_R8G8B8A8_UNORM}; |
| 850 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 851 | pipeline_rendering_info.pColorAttachmentFormats = color_formats; |
| 852 | |
| 853 | samples_info.colorAttachmentCount = 1; |
| 854 | samples_info.pColorAttachmentSamples = &counts; |
| 855 | |
| 856 | auto create_info1 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 857 | pipe1.InitGraphicsPipelineCreateInfo(&create_info1); |
| 858 | create_info1.pNext = &pipeline_rendering_info; |
| 859 | |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 860 | samples_info.colorAttachmentCount = 2; |
| 861 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkGraphicsPipelineCreateInfo-renderPass-06063"); |
| 862 | pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1); |
| 863 | m_errorMonitor->VerifyFound(); |
| 864 | |
| 865 | samples_info.colorAttachmentCount = 1; |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 866 | pipe1.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info1); |
| 867 | |
| 868 | VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu()); |
| 869 | ASSERT_TRUE(depthStencilFormat != 0); |
| 870 | |
| 871 | VkPipelineObj pipe2(m_device); |
| 872 | pipe2.AddShader(&vs); |
| 873 | pipe2.AddShader(&fs); |
| 874 | pipe2.AddDefaultColorAttachment(); |
| 875 | pipe2.SetViewport(m_viewports); |
| 876 | pipe2.SetScissor(m_scissors); |
| 877 | |
| 878 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 879 | pipeline_rendering_info.pColorAttachmentFormats = nullptr; |
| 880 | pipeline_rendering_info.depthAttachmentFormat = depthStencilFormat; |
| 881 | |
| 882 | samples_info.colorAttachmentCount = 0; |
| 883 | samples_info.pColorAttachmentSamples = nullptr; |
| 884 | samples_info.depthStencilAttachmentSamples = counts; |
| 885 | |
| 886 | auto create_info2 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 887 | pipe2.InitGraphicsPipelineCreateInfo(&create_info2); |
| 888 | create_info2.pNext = &pipeline_rendering_info; |
| 889 | |
| 890 | pipe2.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info2); |
| 891 | |
| 892 | VkPipelineObj pipe3(m_device); |
| 893 | |
| 894 | pipe3.AddShader(&vs); |
| 895 | pipe3.AddShader(&fs); |
| 896 | pipe3.AddDefaultColorAttachment(); |
| 897 | pipe3.SetViewport(m_viewports); |
| 898 | pipe3.SetScissor(m_scissors); |
| 899 | |
| 900 | pipeline_rendering_info.colorAttachmentCount = 0; |
| 901 | pipeline_rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED; |
| 902 | pipeline_rendering_info.stencilAttachmentFormat = depthStencilFormat; |
| 903 | |
| 904 | auto create_info3 = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 905 | pipe3.InitGraphicsPipelineCreateInfo(&create_info3); |
| 906 | create_info3.pNext = &pipeline_rendering_info; |
| 907 | |
| 908 | pipe3.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &create_info3); |
| 909 | |
| 910 | VkImageObj colorImage(m_device); |
| 911 | colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 912 | VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UNORM); |
| 913 | |
| 914 | VkImageObj depthStencilImage(m_device); |
| 915 | depthStencilImage.Init(32, 32, 1, depthStencilFormat, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); |
| 916 | VkImageView depthStencilImageView = |
| 917 | depthStencilImage.targetView(depthStencilFormat, VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 918 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 919 | VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 920 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 921 | color_attachment.imageView = colorImageView; |
| 922 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 923 | VkRenderingAttachmentInfoKHR depth_stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 924 | depth_stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 925 | depth_stencil_attachment.imageView = depthStencilImageView; |
| 926 | |
sfricke-samsung | 6fc3e32 | 2022-02-15 22:41:29 -0800 | [diff] [blame] | 927 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
stusmith | 15f24a8 | 2021-12-24 15:21:19 +0000 | [diff] [blame] | 928 | m_commandBuffer->begin(); |
| 929 | |
| 930 | // Mismatching color samples |
| 931 | begin_rendering_info.colorAttachmentCount = 1; |
| 932 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 933 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 934 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe1.handle()); |
| 935 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-colorAttachmentCount-06185"); |
| 936 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 937 | m_errorMonitor->VerifyFound(); |
| 938 | m_commandBuffer->EndRendering(); |
| 939 | |
| 940 | // Mismatching depth samples |
| 941 | begin_rendering_info.colorAttachmentCount = 0; |
| 942 | begin_rendering_info.pColorAttachments = nullptr; |
| 943 | begin_rendering_info.pDepthAttachment = &depth_stencil_attachment; |
| 944 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 945 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe2.handle()); |
| 946 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pDepthAttachment-06186"); |
| 947 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 948 | m_errorMonitor->VerifyFound(); |
| 949 | m_commandBuffer->EndRendering(); |
| 950 | |
| 951 | // Mismatching stencil samples |
| 952 | begin_rendering_info.pDepthAttachment = nullptr; |
| 953 | begin_rendering_info.pStencilAttachment = &depth_stencil_attachment; |
| 954 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 955 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe3.handle()); |
| 956 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-pStencilAttachment-06187"); |
| 957 | m_commandBuffer->Draw(1, 1, 0, 0); |
| 958 | m_errorMonitor->VerifyFound(); |
| 959 | m_commandBuffer->EndRendering(); |
| 960 | |
| 961 | m_commandBuffer->end(); |
| 962 | } |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 963 | |
| 964 | TEST_F(VkLayerTest, DynamicRenderingAttachmentInfo) { |
| 965 | TEST_DESCRIPTION("AttachmentInfo Dynamic Rendering Tests."); |
| 966 | |
| 967 | uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2); |
| 968 | if (version < VK_API_VERSION_1_2) { |
| 969 | printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix); |
| 970 | return; |
| 971 | } |
| 972 | |
| 973 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 974 | |
| 975 | ASSERT_NO_FATAL_FAILURE(InitFramework(m_errorMonitor)); |
| 976 | |
| 977 | if (DeviceValidationVersion() < VK_API_VERSION_1_2) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 978 | GTEST_SKIP() << "At least Vulkan version 1.2 is required"; |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 982 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 986 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 987 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 988 | if (!dynamic_rendering_features.dynamicRendering) { |
| 989 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 990 | return; |
| 991 | } |
| 992 | |
| 993 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 994 | |
| 995 | VkShaderObj vs(this, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT); |
| 996 | VkShaderObj fs(this, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT); |
| 997 | |
| 998 | VkPipelineObj pipe(m_device); |
| 999 | pipe.AddShader(&vs); |
| 1000 | pipe.AddShader(&fs); |
| 1001 | pipe.AddDefaultColorAttachment(); |
| 1002 | |
| 1003 | VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr}; |
| 1004 | const VkDescriptorSetLayoutObj dsl(m_device, {dslb}); |
| 1005 | const VkPipelineLayoutObj pl(m_device, {&dsl}); |
| 1006 | |
| 1007 | VkFormat depth_format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 1008 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 1009 | pipeline_rendering_info.depthAttachmentFormat = depth_format; |
| 1010 | |
| 1011 | auto pipeline_create_info = LvlInitStruct<VkGraphicsPipelineCreateInfo>(); |
| 1012 | pipe.InitGraphicsPipelineCreateInfo(&pipeline_create_info); |
| 1013 | pipeline_create_info.pNext = &pipeline_rendering_info; |
| 1014 | |
| 1015 | VkResult err = pipe.CreateVKPipeline(pl.handle(), VK_NULL_HANDLE, &pipeline_create_info); |
| 1016 | ASSERT_VK_SUCCESS(err); |
| 1017 | |
| 1018 | VkImageObj image(m_device); |
| 1019 | VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>(); |
| 1020 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1021 | image_create_info.format = depth_format; |
| 1022 | image_create_info.extent = {64, 64, 4}; |
| 1023 | image_create_info.mipLevels = 1; |
| 1024 | image_create_info.arrayLayers = 1; |
| 1025 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 1026 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 1027 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 1028 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1029 | |
| 1030 | image.Init(image_create_info); |
| 1031 | ASSERT_TRUE(image.initialized()); |
| 1032 | |
| 1033 | VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, |
| 1034 | nullptr, |
| 1035 | 0, |
| 1036 | image.handle(), |
| 1037 | VK_IMAGE_VIEW_TYPE_2D, |
| 1038 | depth_format, |
| 1039 | {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, |
| 1040 | VK_COMPONENT_SWIZZLE_IDENTITY}, |
| 1041 | {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}}; |
| 1042 | |
| 1043 | VkImageView depth_image_view; |
| 1044 | err = vk::CreateImageView(m_device->device(), &ivci, nullptr, &depth_image_view); |
| 1045 | ASSERT_VK_SUCCESS(err); |
| 1046 | |
| 1047 | VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 1048 | depth_attachment.imageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; |
| 1049 | depth_attachment.imageView = depth_image_view; |
| 1050 | depth_attachment.resolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT; |
| 1051 | depth_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; |
| 1052 | |
| 1053 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
| 1054 | begin_rendering_info.pDepthAttachment = &depth_attachment; |
| 1055 | begin_rendering_info.viewMask = 0x4; |
| 1056 | |
| 1057 | VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map = |
| 1058 | LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>(); |
| 1059 | fragment_density_map.imageView = depth_image_view; |
| 1060 | begin_rendering_info.pNext = &fragment_density_map; |
| 1061 | |
| 1062 | m_commandBuffer->begin(); |
| 1063 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-multiview-06127"); |
Jeremy Gebben | 09c1a07 | 2022-02-08 09:42:47 -0700 | [diff] [blame] | 1064 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06107"); |
| 1065 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06108"); |
| 1066 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06116"); |
Jeremy Gebben | 09c1a07 | 2022-02-08 09:42:47 -0700 | [diff] [blame] | 1067 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06145"); |
| 1068 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06146"); |
Aaron Hagan | 80034ea | 2021-12-23 11:24:09 -0500 | [diff] [blame] | 1069 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1070 | m_errorMonitor->VerifyFound(); |
| 1071 | } |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 1072 | |
| 1073 | TEST_F(VkLayerTest, DynamicRenderingBufferBeginInfoLegacy) { |
| 1074 | TEST_DESCRIPTION("VkCommandBufferBeginInfo Dynamic Rendering Tests."); |
| 1075 | |
| 1076 | uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_2); |
| 1077 | if (version < VK_API_VERSION_1_2) { |
| 1078 | printf("%s At least Vulkan version 1.2 is required, skipping test.\n", kSkipPrefix); |
| 1079 | return; |
| 1080 | } |
| 1081 | |
| 1082 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1083 | |
| 1084 | ASSERT_NO_FATAL_FAILURE(Init(nullptr, nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)); |
| 1085 | |
| 1086 | if (DeviceValidationVersion() < VK_API_VERSION_1_2) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1087 | GTEST_SKIP() << "At least Vulkan version 1.2 is required"; |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 1091 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | auto cmd_buffer_inheritance_rendering_info = LvlInitStruct<VkCommandBufferInheritanceRenderingInfoKHR>(); |
| 1095 | cmd_buffer_inheritance_rendering_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 1096 | |
| 1097 | auto cmd_buffer_inheritance_info = LvlInitStruct<VkCommandBufferInheritanceInfo>(); |
| 1098 | cmd_buffer_inheritance_info.pNext = &cmd_buffer_inheritance_rendering_info; |
| 1099 | cmd_buffer_inheritance_info.renderPass = VK_NULL_HANDLE; |
| 1100 | |
| 1101 | auto cmd_buffer_allocate_info = LvlInitStruct<VkCommandBufferAllocateInfo>(); |
| 1102 | cmd_buffer_allocate_info.commandPool = m_commandPool->handle(); |
| 1103 | cmd_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
| 1104 | cmd_buffer_allocate_info.commandBufferCount = 0x1; |
| 1105 | |
| 1106 | VkCommandBuffer secondary_cmd_buffer; |
| 1107 | VkResult err = vk::AllocateCommandBuffers(m_device->device(), &cmd_buffer_allocate_info, &secondary_cmd_buffer); |
| 1108 | ASSERT_VK_SUCCESS(err); |
| 1109 | |
| 1110 | // Invalid RenderPass |
| 1111 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-00053"); |
| 1112 | VkCommandBufferBeginInfo cmd_buffer_begin_info = LvlInitStruct<VkCommandBufferBeginInfo>(); |
| 1113 | cmd_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
| 1114 | cmd_buffer_begin_info.pInheritanceInfo = &cmd_buffer_inheritance_info; |
| 1115 | vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info); |
| 1116 | m_errorMonitor->VerifyFound(); |
| 1117 | |
| 1118 | // Valid RenderPass |
| 1119 | VkAttachmentDescription attach[] = { |
| 1120 | {0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 1121 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED, |
| 1122 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, |
| 1123 | }; |
| 1124 | VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}; |
| 1125 | |
| 1126 | VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr}; |
| 1127 | VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, &subpass, 0, nullptr}; |
| 1128 | |
| 1129 | vk_testing::RenderPass rp1; |
| 1130 | rp1.init(*m_device, rpci); |
| 1131 | |
| 1132 | cmd_buffer_inheritance_info.renderPass = rp1.handle(); |
| 1133 | cmd_buffer_inheritance_info.subpass = 0x5; |
| 1134 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-00054"); |
| 1135 | vk::BeginCommandBuffer(secondary_cmd_buffer, &cmd_buffer_begin_info); |
| 1136 | m_errorMonitor->VerifyFound(); |
| 1137 | } |
| 1138 | |
| 1139 | TEST_F(VkLayerTest, DynamicRenderingSecondaryCommandBuffer) { |
| 1140 | TEST_DESCRIPTION("VkCommandBufferBeginInfo Dynamic Rendering Tests."); |
| 1141 | |
| 1142 | uint32_t version = SetTargetApiVersion(VK_API_VERSION_1_3); |
| 1143 | if (version < VK_API_VERSION_1_3) { |
| 1144 | printf("%s At least Vulkan version 1.3 is required, skipping test.\n", kSkipPrefix); |
| 1145 | return; |
| 1146 | } |
| 1147 | |
| 1148 | ASSERT_NO_FATAL_FAILURE(Init()); |
| 1149 | |
| 1150 | if (DeviceValidationVersion() < VK_API_VERSION_1_3) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1151 | GTEST_SKIP() << "At least Vulkan version 1.3 is required"; |
Aaron Hagan | b54466d | 2022-02-18 15:02:54 -0500 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | VkCommandBufferObj cb(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY); |
| 1155 | |
| 1156 | // Force the failure by not setting the Renderpass and Framebuffer fields |
| 1157 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = LvlInitStruct<VkCommandBufferInheritanceInfo>(); |
| 1158 | cmd_buf_hinfo.renderPass = VkRenderPass(0x1); |
| 1159 | VkCommandBufferBeginInfo cmd_buf_info = LvlInitStruct<VkCommandBufferBeginInfo>(); |
| 1160 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
| 1161 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
| 1162 | |
| 1163 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06000"); |
| 1164 | vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info); |
| 1165 | m_errorMonitor->VerifyFound(); |
| 1166 | |
| 1167 | // Valid RenderPass |
| 1168 | VkAttachmentDescription attach[] = { |
| 1169 | {0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 1170 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED, |
| 1171 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, |
| 1172 | }; |
| 1173 | VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}; |
| 1174 | |
| 1175 | VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr}; |
| 1176 | VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 1, &subpass, 0, nullptr}; |
| 1177 | |
| 1178 | vk_testing::RenderPass rp1; |
| 1179 | rp1.init(*m_device, rpci); |
| 1180 | |
| 1181 | cmd_buf_hinfo.renderPass = rp1.handle(); |
| 1182 | cmd_buf_hinfo.subpass = 0x5; |
| 1183 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06001"); |
| 1184 | vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info); |
| 1185 | m_errorMonitor->VerifyFound(); |
| 1186 | |
| 1187 | cmd_buf_hinfo.renderPass = VK_NULL_HANDLE; |
| 1188 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkCommandBufferBeginInfo-flags-06002"); |
| 1189 | vk::BeginCommandBuffer(cb.handle(), &cmd_buf_info); |
| 1190 | m_errorMonitor->VerifyFound(); |
ziga-lunarg | 6c8f162 | 2022-03-14 20:14:04 +0100 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | TEST_F(VkLayerTest, TestDynamicRenderingPipelineMissingFlags) { |
| 1194 | TEST_DESCRIPTION("Test dynamic rendering with pipeline missing flags."); |
| 1195 | |
| 1196 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 1197 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1198 | AddRequiredExtensions(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME); |
| 1199 | AddRequiredExtensions(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME); |
| 1200 | |
| 1201 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1202 | |
| 1203 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1204 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | 6c8f162 | 2022-03-14 20:14:04 +0100 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) { |
| 1208 | printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1209 | return; |
| 1210 | } |
| 1211 | bool fragment_density = DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME); |
| 1212 | bool shading_rate = DeviceExtensionSupported(gpu(), nullptr, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME); |
| 1213 | |
| 1214 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1215 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1216 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1217 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1218 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1219 | return; |
| 1220 | } |
| 1221 | |
| 1222 | auto fsr_properties = LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>(); |
| 1223 | |
| 1224 | auto phys_dev_props_2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fsr_properties); |
| 1225 | vk::GetPhysicalDeviceProperties2(gpu(), &phys_dev_props_2); |
| 1226 | |
| 1227 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)); |
| 1228 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1229 | |
| 1230 | VkFormat depthStencilFormat = FindSupportedDepthStencilFormat(gpu()); |
| 1231 | ASSERT_TRUE(depthStencilFormat != 0); |
| 1232 | |
| 1233 | VkImageObj image(m_device); |
| 1234 | VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>(); |
| 1235 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1236 | image_create_info.format = depthStencilFormat; |
| 1237 | image_create_info.extent = {64, 64, 1}; |
| 1238 | image_create_info.mipLevels = 1; |
| 1239 | image_create_info.arrayLayers = 1; |
| 1240 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 1241 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
ziga-lunarg | d3de6ce | 2022-03-18 21:14:57 +0100 | [diff] [blame] | 1242 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR; |
ziga-lunarg | 6c8f162 | 2022-03-14 20:14:04 +0100 | [diff] [blame] | 1243 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1244 | |
| 1245 | image.Init(image_create_info); |
| 1246 | ASSERT_TRUE(image.initialized()); |
| 1247 | |
| 1248 | VkImageViewCreateInfo ivci = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, |
| 1249 | nullptr, |
| 1250 | 0, |
| 1251 | image.handle(), |
| 1252 | VK_IMAGE_VIEW_TYPE_2D, |
| 1253 | depthStencilFormat, |
| 1254 | {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, |
| 1255 | VK_COMPONENT_SWIZZLE_IDENTITY}, |
| 1256 | {VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0, 1, 0, 1}}; |
| 1257 | |
| 1258 | vk_testing::ImageView depth_image_view; |
| 1259 | depth_image_view.init(*m_device, ivci); |
| 1260 | |
| 1261 | VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 1262 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 1263 | |
| 1264 | if (shading_rate) { |
| 1265 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-imageView-06183"); |
| 1266 | VkRenderingFragmentShadingRateAttachmentInfoKHR fragment_shading_rate = |
| 1267 | LvlInitStruct<VkRenderingFragmentShadingRateAttachmentInfoKHR>(); |
| 1268 | fragment_shading_rate.imageView = depth_image_view.handle(); |
| 1269 | fragment_shading_rate.imageLayout = VK_IMAGE_LAYOUT_GENERAL; |
| 1270 | fragment_shading_rate.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize; |
| 1271 | |
| 1272 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_shading_rate); |
ziga-lunarg | aa97cbb | 2022-03-18 19:06:35 +0100 | [diff] [blame] | 1273 | begin_rendering_info.layerCount = 1; |
ziga-lunarg | 6c8f162 | 2022-03-14 20:14:04 +0100 | [diff] [blame] | 1274 | begin_rendering_info.colorAttachmentCount = 1; |
| 1275 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 1276 | |
| 1277 | VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1278 | |
| 1279 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 1280 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 1281 | pipeline_rendering_info.pColorAttachmentFormats = &color_format; |
| 1282 | |
| 1283 | CreatePipelineHelper pipe(*this); |
| 1284 | pipe.InitInfo(); |
| 1285 | pipe.gp_ci_.pNext = &pipeline_rendering_info; |
| 1286 | pipe.gp_ci_.renderPass = VK_NULL_HANDLE; |
| 1287 | pipe.InitState(); |
| 1288 | pipe.CreateGraphicsPipeline(); |
| 1289 | |
| 1290 | m_commandBuffer->begin(); |
| 1291 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1292 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_); |
| 1293 | vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0); |
| 1294 | m_commandBuffer->EndRendering(); |
| 1295 | m_commandBuffer->end(); |
| 1296 | |
| 1297 | m_errorMonitor->VerifyFound(); |
| 1298 | } |
| 1299 | |
| 1300 | if (fragment_density) { |
| 1301 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDraw-imageView-06184"); |
| 1302 | VkRenderingFragmentDensityMapAttachmentInfoEXT fragment_density_map = |
| 1303 | LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>(); |
| 1304 | fragment_density_map.imageView = depth_image_view.handle(); |
| 1305 | |
| 1306 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_density_map); |
ziga-lunarg | aa97cbb | 2022-03-18 19:06:35 +0100 | [diff] [blame] | 1307 | begin_rendering_info.layerCount = 1; |
ziga-lunarg | 6c8f162 | 2022-03-14 20:14:04 +0100 | [diff] [blame] | 1308 | begin_rendering_info.colorAttachmentCount = 1; |
| 1309 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 1310 | |
| 1311 | VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1312 | |
| 1313 | auto pipeline_rendering_info = LvlInitStruct<VkPipelineRenderingCreateInfoKHR>(); |
| 1314 | pipeline_rendering_info.colorAttachmentCount = 1; |
| 1315 | pipeline_rendering_info.pColorAttachmentFormats = &color_format; |
| 1316 | |
| 1317 | CreatePipelineHelper pipe(*this); |
| 1318 | pipe.InitInfo(); |
| 1319 | pipe.gp_ci_.pNext = &pipeline_rendering_info; |
| 1320 | pipe.gp_ci_.renderPass = VK_NULL_HANDLE; |
| 1321 | pipe.InitState(); |
| 1322 | pipe.CreateGraphicsPipeline(); |
| 1323 | |
| 1324 | m_commandBuffer->begin(); |
| 1325 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1326 | vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_); |
| 1327 | vk::CmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0); |
| 1328 | m_commandBuffer->EndRendering(); |
| 1329 | m_commandBuffer->end(); |
| 1330 | |
| 1331 | m_errorMonitor->VerifyFound(); |
| 1332 | } |
| 1333 | } |
ziga-lunarg | bc6d8ad | 2022-03-18 13:04:20 +0100 | [diff] [blame] | 1334 | |
ziga-lunarg | 2c9067e | 2022-03-18 18:33:52 +0100 | [diff] [blame] | 1335 | TEST_F(VkLayerTest, DynamicRenderingLayerCount) { |
| 1336 | TEST_DESCRIPTION("Test dynamic rendering with viewMask 0 and invalid layer count."); |
| 1337 | |
| 1338 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 1339 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1340 | |
| 1341 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1342 | |
| 1343 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1344 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | 2c9067e | 2022-03-18 18:33:52 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) { |
| 1348 | printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1349 | return; |
| 1350 | } |
| 1351 | |
| 1352 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1353 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1354 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1355 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1356 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1357 | return; |
| 1358 | } |
| 1359 | |
| 1360 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 1361 | |
| 1362 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
| 1363 | |
| 1364 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-viewMask-06069"); |
| 1365 | m_commandBuffer->begin(); |
| 1366 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1367 | m_commandBuffer->end(); |
| 1368 | m_errorMonitor->VerifyFound(); |
| 1369 | } |
| 1370 | |
ziga-lunarg | bc6d8ad | 2022-03-18 13:04:20 +0100 | [diff] [blame] | 1371 | TEST_F(VkLayerTest, TestRenderingInfoMismatchedSamples) { |
| 1372 | TEST_DESCRIPTION("Test beginning rendering with mismatched sample counts."); |
| 1373 | |
| 1374 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 1375 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1376 | |
| 1377 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1378 | |
| 1379 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1380 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | bc6d8ad | 2022-03-18 13:04:20 +0100 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) { |
| 1384 | printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1385 | return; |
| 1386 | } |
| 1387 | |
| 1388 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1389 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1390 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1391 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1392 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1393 | return; |
| 1394 | } |
| 1395 | |
| 1396 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 1397 | |
| 1398 | VkImageCreateInfo image_ci = LvlInitStruct<VkImageCreateInfo>(); |
| 1399 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 1400 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1401 | image_ci.extent.width = 64; |
| 1402 | image_ci.extent.height = 64; |
| 1403 | image_ci.extent.depth = 1; |
| 1404 | image_ci.mipLevels = 1; |
| 1405 | image_ci.arrayLayers = 1; |
| 1406 | image_ci.samples = VK_SAMPLE_COUNT_2_BIT; |
| 1407 | image_ci.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 1408 | image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 1409 | |
| 1410 | VkImageObj color_image(m_device); |
| 1411 | color_image.init(&image_ci); |
| 1412 | |
| 1413 | VkImageViewCreateInfo civ_ci = LvlInitStruct<VkImageViewCreateInfo>(); |
| 1414 | civ_ci.image = color_image.handle(); |
| 1415 | civ_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 1416 | civ_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1417 | civ_ci.subresourceRange.layerCount = 1; |
| 1418 | civ_ci.subresourceRange.baseMipLevel = 0; |
| 1419 | civ_ci.subresourceRange.levelCount = 1; |
| 1420 | civ_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 1421 | |
| 1422 | vk_testing::ImageView color_image_view; |
| 1423 | color_image_view.init(*m_device, civ_ci); |
| 1424 | |
| 1425 | VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 1426 | color_attachment.imageView = color_image_view.handle(); |
| 1427 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 1428 | color_attachment.resolveMode = VK_RESOLVE_MODE_NONE; |
| 1429 | |
| 1430 | const VkFormat depth_format = FindSupportedDepthOnlyFormat(gpu()); |
| 1431 | if (depth_format == VK_FORMAT_UNDEFINED) { |
| 1432 | printf("%s requires a depth only format, skipping.\n", kSkipPrefix); |
| 1433 | return; |
| 1434 | } |
| 1435 | |
| 1436 | VkImageObj depth_image(m_device); |
| 1437 | depth_image.Init(64, 64, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL); |
| 1438 | |
| 1439 | VkImageViewCreateInfo div_ci = LvlInitStruct<VkImageViewCreateInfo>(); |
| 1440 | div_ci.image = depth_image.handle(); |
| 1441 | div_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 1442 | div_ci.format = depth_format; |
| 1443 | div_ci.subresourceRange.layerCount = 1; |
| 1444 | div_ci.subresourceRange.baseMipLevel = 0; |
| 1445 | div_ci.subresourceRange.levelCount = 1; |
| 1446 | div_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; |
| 1447 | |
| 1448 | vk_testing::ImageView depth_image_view; |
| 1449 | depth_image_view.init(*m_device, div_ci); |
| 1450 | |
| 1451 | VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 1452 | depth_attachment.imageLayout = VK_IMAGE_LAYOUT_GENERAL; |
| 1453 | depth_attachment.imageView = depth_image_view.handle(); |
| 1454 | depth_attachment.resolveMode = VK_RESOLVE_MODE_NONE; |
| 1455 | |
| 1456 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
ziga-lunarg | aa97cbb | 2022-03-18 19:06:35 +0100 | [diff] [blame] | 1457 | begin_rendering_info.layerCount = 1; |
ziga-lunarg | bc6d8ad | 2022-03-18 13:04:20 +0100 | [diff] [blame] | 1458 | begin_rendering_info.colorAttachmentCount = 1; |
| 1459 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 1460 | begin_rendering_info.pDepthAttachment = &depth_attachment; |
| 1461 | |
| 1462 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06070"); |
| 1463 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1464 | m_errorMonitor->VerifyFound(); |
| 1465 | } |
ziga-lunarg | ec0ac1c | 2022-03-18 19:25:17 +0100 | [diff] [blame] | 1466 | |
ziga-lunarg | b7fec14 | 2022-03-18 22:08:17 +0100 | [diff] [blame] | 1467 | TEST_F(VkLayerTest, TestBeginRenderingFragmentShadingRate) { |
| 1468 | TEST_DESCRIPTION("Test BeginRenderingInfo with FragmentShadingRateAttachment."); |
| 1469 | |
| 1470 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 1471 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1472 | AddRequiredExtensions(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME); |
| 1473 | |
| 1474 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1475 | |
| 1476 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1477 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | b7fec14 | 2022-03-18 22:08:17 +0100 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 1481 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
ziga-lunarg | b7fec14 | 2022-03-18 22:08:17 +0100 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1485 | auto features11 = LvlInitStruct<VkPhysicalDeviceVulkan11Features>(&dynamic_rendering_features); |
| 1486 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&features11); |
| 1487 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1488 | |
| 1489 | if (features11.multiview == VK_FALSE) { |
| 1490 | printf("%s Test requires (unsupported) multiview , skipping\n", kSkipPrefix); |
| 1491 | return; |
| 1492 | } |
| 1493 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1494 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1495 | return; |
| 1496 | } |
| 1497 | |
| 1498 | auto fsr_properties = LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>(); |
| 1499 | |
| 1500 | auto phys_dev_props_2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fsr_properties); |
| 1501 | vk::GetPhysicalDeviceProperties2(gpu(), &phys_dev_props_2); |
| 1502 | |
| 1503 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)); |
| 1504 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1505 | |
| 1506 | auto image_ci = LvlInitStruct<VkImageCreateInfo>(nullptr); |
| 1507 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 1508 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1509 | image_ci.extent.width = 32; |
| 1510 | image_ci.extent.height = 32; |
| 1511 | image_ci.extent.depth = 1; |
| 1512 | image_ci.mipLevels = 1; |
| 1513 | image_ci.arrayLayers = 2; |
| 1514 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1515 | image_ci.tiling = VK_IMAGE_TILING_OPTIMAL; |
ziga-lunarg | 6f7647f | 2022-04-18 20:10:04 +0200 | [diff] [blame] | 1516 | image_ci.usage = VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR; |
ziga-lunarg | b7fec14 | 2022-03-18 22:08:17 +0100 | [diff] [blame] | 1517 | |
| 1518 | VkImageObj image(m_device); |
| 1519 | image.init(&image_ci); |
| 1520 | VkImageView image_view = image.targetView(VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 2); |
| 1521 | |
| 1522 | VkRenderingFragmentShadingRateAttachmentInfoKHR fragment_shading_rate = |
| 1523 | LvlInitStruct<VkRenderingFragmentShadingRateAttachmentInfoKHR>(); |
| 1524 | fragment_shading_rate.imageView = image_view; |
| 1525 | fragment_shading_rate.imageLayout = VK_IMAGE_LAYOUT_GENERAL; |
| 1526 | fragment_shading_rate.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize; |
| 1527 | |
| 1528 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_shading_rate); |
| 1529 | begin_rendering_info.layerCount = 4; |
| 1530 | |
| 1531 | m_commandBuffer->begin(); |
| 1532 | |
| 1533 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06123"); |
| 1534 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1535 | m_errorMonitor->VerifyFound(); |
| 1536 | |
| 1537 | begin_rendering_info.viewMask = 0xF; |
| 1538 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-imageView-06124"); |
| 1539 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1540 | m_errorMonitor->VerifyFound(); |
| 1541 | |
| 1542 | m_commandBuffer->end(); |
| 1543 | |
| 1544 | } |
| 1545 | |
ziga-lunarg | 7e7138c | 2022-03-18 19:02:31 +0100 | [diff] [blame] | 1546 | TEST_F(VkLayerTest, TestDeviceGroupRenderPassBeginInfo) { |
| 1547 | TEST_DESCRIPTION("Test render area of DeviceGroupRenderPassBeginInfo."); |
| 1548 | |
| 1549 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 1550 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1551 | |
| 1552 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1553 | |
| 1554 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1555 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | 7e7138c | 2022-03-18 19:02:31 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) { |
| 1559 | printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1560 | return; |
| 1561 | } |
| 1562 | |
| 1563 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1564 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1565 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1566 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1567 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1568 | return; |
| 1569 | } |
| 1570 | |
| 1571 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)); |
| 1572 | |
| 1573 | VkRect2D render_area = {}; |
| 1574 | render_area.offset.x = 0; |
| 1575 | render_area.offset.y = 0; |
| 1576 | render_area.extent.width = 32; |
| 1577 | render_area.extent.height = 32; |
| 1578 | |
| 1579 | auto device_group_render_pass_begin_info = LvlInitStruct<VkDeviceGroupRenderPassBeginInfo>(); |
| 1580 | device_group_render_pass_begin_info.deviceRenderAreaCount = 1; |
| 1581 | device_group_render_pass_begin_info.pDeviceRenderAreas = &render_area; |
| 1582 | |
| 1583 | VkImageObj colorImage(m_device); |
| 1584 | colorImage.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 1585 | VkImageView colorImageView = colorImage.targetView(VK_FORMAT_R8G8B8A8_UINT); |
| 1586 | |
| 1587 | VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 1588 | color_attachment.imageView = colorImageView; |
| 1589 | color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 1590 | |
| 1591 | auto begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&device_group_render_pass_begin_info); |
ziga-lunarg | 1fec633 | 2022-03-20 14:39:54 +0100 | [diff] [blame] | 1592 | begin_rendering_info.layerCount = 1; |
ziga-lunarg | 7e7138c | 2022-03-18 19:02:31 +0100 | [diff] [blame] | 1593 | begin_rendering_info.colorAttachmentCount = 1; |
| 1594 | begin_rendering_info.pColorAttachments = &color_attachment; |
| 1595 | |
| 1596 | m_commandBuffer->begin(); |
| 1597 | |
| 1598 | m_errorMonitor->ExpectSuccess(); |
| 1599 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1600 | m_errorMonitor->VerifyNotFound(); |
| 1601 | |
| 1602 | render_area.offset.x = 1; |
| 1603 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06083"); |
| 1604 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1605 | m_errorMonitor->VerifyFound(); |
| 1606 | |
| 1607 | render_area.offset.x = 0; |
| 1608 | render_area.offset.y = 16; |
| 1609 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06084"); |
| 1610 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1611 | m_errorMonitor->VerifyFound(); |
| 1612 | |
| 1613 | m_commandBuffer->end(); |
| 1614 | } |
| 1615 | |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1616 | TEST_F(VkLayerTest, TestBeginRenderingInvalidFragmentShadingRateImage) { |
| 1617 | TEST_DESCRIPTION("Test BeginRendering with FragmentShadingRateAttachmentInfo with missing image usage bit."); |
| 1618 | |
| 1619 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 1620 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1621 | AddRequiredExtensions(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME); |
| 1622 | |
| 1623 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1624 | |
| 1625 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1626 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 1630 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1634 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1635 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1636 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1637 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1638 | return; |
| 1639 | } |
| 1640 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 1641 | |
| 1642 | auto fsr_properties = LvlInitStruct<VkPhysicalDeviceFragmentShadingRatePropertiesKHR>(); |
| 1643 | auto properties2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fsr_properties); |
| 1644 | vk::GetPhysicalDeviceProperties2(gpu(), &properties2); |
| 1645 | |
| 1646 | VkImageObj image(m_device); |
ziga-lunarg | d3de6ce | 2022-03-18 21:14:57 +0100 | [diff] [blame] | 1647 | image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, |
| 1648 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR); |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1649 | VkImageView image_view = image.targetView(VK_FORMAT_R8G8B8A8_UINT); |
| 1650 | |
ziga-lunarg | d3de6ce | 2022-03-18 21:14:57 +0100 | [diff] [blame] | 1651 | VkImageObj invalid_image(m_device); |
| 1652 | invalid_image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 1653 | VkImageView invalid_image_view = invalid_image.targetView(VK_FORMAT_R8G8B8A8_UINT); |
| 1654 | |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1655 | auto fragment_shading_rate = LvlInitStruct<VkRenderingFragmentShadingRateAttachmentInfoKHR>(); |
ziga-lunarg | d3de6ce | 2022-03-18 21:14:57 +0100 | [diff] [blame] | 1656 | fragment_shading_rate.imageView = invalid_image_view; |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1657 | fragment_shading_rate.imageLayout = VK_IMAGE_LAYOUT_GENERAL; |
| 1658 | fragment_shading_rate.shadingRateAttachmentTexelSize = fsr_properties.minFragmentShadingRateAttachmentTexelSize; |
| 1659 | |
| 1660 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_shading_rate); |
ziga-lunarg | d3de6ce | 2022-03-18 21:14:57 +0100 | [diff] [blame] | 1661 | begin_rendering_info.layerCount = 1; |
| 1662 | |
| 1663 | m_commandBuffer->begin(); |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1664 | |
| 1665 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06148"); |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1666 | m_commandBuffer->BeginRendering(begin_rendering_info); |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1667 | m_errorMonitor->VerifyFound(); |
ziga-lunarg | d3de6ce | 2022-03-18 21:14:57 +0100 | [diff] [blame] | 1668 | fragment_shading_rate.imageView = image_view; |
| 1669 | |
| 1670 | fragment_shading_rate.shadingRateAttachmentTexelSize.width = fsr_properties.minFragmentShadingRateAttachmentTexelSize.width + 1; |
| 1671 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06149"); |
| 1672 | if (fragment_shading_rate.shadingRateAttachmentTexelSize.width > |
| 1673 | fsr_properties.minFragmentShadingRateAttachmentTexelSize.width) { |
| 1674 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06150"); |
| 1675 | } |
| 1676 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1677 | m_errorMonitor->VerifyFound(); |
| 1678 | |
| 1679 | if (fsr_properties.minFragmentShadingRateAttachmentTexelSize.width > 1) { |
| 1680 | fragment_shading_rate.shadingRateAttachmentTexelSize.width = |
| 1681 | fsr_properties.minFragmentShadingRateAttachmentTexelSize.width / 2; |
| 1682 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06151"); |
| 1683 | if (fragment_shading_rate.shadingRateAttachmentTexelSize.height / |
| 1684 | fragment_shading_rate.shadingRateAttachmentTexelSize.width >= |
| 1685 | fsr_properties.maxFragmentShadingRateAttachmentTexelSizeAspectRatio) { |
| 1686 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06156"); |
| 1687 | } |
| 1688 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1689 | m_errorMonitor->VerifyFound(); |
| 1690 | } |
| 1691 | |
| 1692 | fragment_shading_rate.shadingRateAttachmentTexelSize.width = fsr_properties.minFragmentShadingRateAttachmentTexelSize.width; |
| 1693 | |
| 1694 | fragment_shading_rate.shadingRateAttachmentTexelSize.height = |
| 1695 | fsr_properties.minFragmentShadingRateAttachmentTexelSize.height + 1; |
| 1696 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06152"); |
| 1697 | if (fragment_shading_rate.shadingRateAttachmentTexelSize.height > |
| 1698 | fsr_properties.minFragmentShadingRateAttachmentTexelSize.height) { |
| 1699 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06153"); |
| 1700 | } |
| 1701 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1702 | m_errorMonitor->VerifyFound(); |
| 1703 | |
| 1704 | if (fsr_properties.minFragmentShadingRateAttachmentTexelSize.height > 1) { |
| 1705 | fragment_shading_rate.shadingRateAttachmentTexelSize.height = |
| 1706 | fsr_properties.minFragmentShadingRateAttachmentTexelSize.height / 2; |
| 1707 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06154"); |
| 1708 | if (fragment_shading_rate.shadingRateAttachmentTexelSize.width / |
| 1709 | fragment_shading_rate.shadingRateAttachmentTexelSize.height > |
| 1710 | fsr_properties.maxFragmentShadingRateAttachmentTexelSizeAspectRatio) { |
| 1711 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06155"); |
| 1712 | } |
| 1713 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1714 | m_errorMonitor->VerifyFound(); |
| 1715 | } |
| 1716 | |
| 1717 | m_commandBuffer->end(); |
ziga-lunarg | 184a20b | 2022-03-18 20:54:48 +0100 | [diff] [blame] | 1718 | } |
| 1719 | |
ziga-lunarg | ec0ac1c | 2022-03-18 19:25:17 +0100 | [diff] [blame] | 1720 | TEST_F(VkLayerTest, BeginRenderingInvalidDepthAttachmentFormat) { |
| 1721 | TEST_DESCRIPTION("Test begin rendering with a depth attachment that has an invalid format"); |
| 1722 | |
| 1723 | SetTargetApiVersion(VK_API_VERSION_1_3); |
| 1724 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1725 | |
| 1726 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1727 | |
| 1728 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1729 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | ec0ac1c | 2022-03-18 19:25:17 +0100 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 1733 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
ziga-lunarg | ec0ac1c | 2022-03-18 19:25:17 +0100 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1737 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1738 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1739 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1740 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1741 | return; |
| 1742 | } |
| 1743 | |
| 1744 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 1745 | |
| 1746 | VkFormat stencil_format = FindSupportedStencilOnlyFormat(gpu()); |
| 1747 | if (stencil_format == VK_FORMAT_UNDEFINED) { |
| 1748 | printf("%s requires a stencil only format format.\n", kSkipPrefix); |
| 1749 | return; |
| 1750 | } |
| 1751 | |
| 1752 | VkImageObj image(m_device); |
| 1753 | image.Init(32, 32, 1, stencil_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); |
| 1754 | VkImageView image_view = image.targetView(stencil_format, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 1755 | |
| 1756 | VkRenderingAttachmentInfoKHR depth_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 1757 | depth_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL; |
| 1758 | depth_attachment.imageView = image_view; |
| 1759 | |
| 1760 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
ziga-lunarg | 1fec633 | 2022-03-20 14:39:54 +0100 | [diff] [blame] | 1761 | begin_rendering_info.layerCount = 1; |
ziga-lunarg | ec0ac1c | 2022-03-18 19:25:17 +0100 | [diff] [blame] | 1762 | begin_rendering_info.pDepthAttachment = &depth_attachment; |
| 1763 | |
| 1764 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pDepthAttachment-06547"); |
| 1765 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1766 | m_errorMonitor->VerifyFound(); |
| 1767 | } |
ziga-lunarg | 4b5bb5b | 2022-03-20 00:49:04 +0100 | [diff] [blame] | 1768 | |
ziga-lunarg | 14a6978 | 2022-03-20 00:39:31 +0100 | [diff] [blame] | 1769 | TEST_F(VkLayerTest, TestFragmentDensityMapRenderArea) { |
| 1770 | TEST_DESCRIPTION("Validate VkRenderingFragmentDensityMapAttachmentInfo attachment image view extent."); |
| 1771 | |
| 1772 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 1773 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1774 | AddRequiredExtensions(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME); |
| 1775 | |
| 1776 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1777 | |
| 1778 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1779 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | 14a6978 | 2022-03-20 00:39:31 +0100 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | if (!DeviceExtensionSupported(gpu(), nullptr, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) { |
| 1783 | printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1784 | return; |
| 1785 | } |
| 1786 | |
| 1787 | if (!DeviceExtensionSupported(gpu(), nullptr, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME)) { |
| 1788 | printf("%s %s not supported, skipping test\n", kSkipPrefix, VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME); |
| 1789 | return; |
| 1790 | } |
| 1791 | |
| 1792 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1793 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1794 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1795 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1796 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1797 | return; |
| 1798 | } |
| 1799 | |
| 1800 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 1801 | |
| 1802 | auto fdm_props = LvlInitStruct<VkPhysicalDeviceFragmentDensityMapPropertiesEXT>(); |
| 1803 | auto props2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&fdm_props); |
| 1804 | vk::GetPhysicalDeviceProperties2(gpu(), &props2); |
| 1805 | |
| 1806 | VkImageObj image(m_device); |
| 1807 | image.Init(32, 32, 1, VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
| 1808 | VkImageView image_view = image.targetView(VK_FORMAT_R8G8B8A8_UINT, VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1); |
| 1809 | |
| 1810 | auto fragment_density_map = LvlInitStruct<VkRenderingFragmentDensityMapAttachmentInfoEXT>(); |
| 1811 | fragment_density_map.imageView = image_view; |
| 1812 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(&fragment_density_map); |
| 1813 | begin_rendering_info.layerCount = 1; |
| 1814 | begin_rendering_info.renderArea.extent.width = 64 * fdm_props.maxFragmentDensityTexelSize.width; |
| 1815 | begin_rendering_info.renderArea.extent.height = 32 * fdm_props.maxFragmentDensityTexelSize.height; |
| 1816 | |
| 1817 | m_commandBuffer->begin(); |
| 1818 | |
| 1819 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06112"); |
| 1820 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1821 | m_errorMonitor->VerifyFound(); |
| 1822 | |
| 1823 | begin_rendering_info.renderArea.extent.width = 32 * fdm_props.maxFragmentDensityTexelSize.width; |
| 1824 | begin_rendering_info.renderArea.extent.height = 64 * fdm_props.maxFragmentDensityTexelSize.height; |
| 1825 | |
| 1826 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06114"); |
| 1827 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1828 | m_errorMonitor->VerifyFound(); |
| 1829 | |
| 1830 | VkRect2D device_render_area = {}; |
| 1831 | device_render_area.extent.width = 64 * fdm_props.maxFragmentDensityTexelSize.width; |
| 1832 | device_render_area.extent.height = 32 * fdm_props.maxFragmentDensityTexelSize.height; |
| 1833 | auto device_group_render_pass_begin_info = LvlInitStruct<VkDeviceGroupRenderPassBeginInfo>(); |
| 1834 | device_group_render_pass_begin_info.deviceRenderAreaCount = 1; |
| 1835 | device_group_render_pass_begin_info.pDeviceRenderAreas = &device_render_area; |
| 1836 | fragment_density_map.pNext = &device_group_render_pass_begin_info; |
| 1837 | |
| 1838 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06113"); |
| 1839 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1840 | m_errorMonitor->VerifyFound(); |
| 1841 | |
| 1842 | device_render_area.extent.width = 32 * fdm_props.maxFragmentDensityTexelSize.width; |
| 1843 | device_render_area.extent.height = 64 * fdm_props.maxFragmentDensityTexelSize.height; |
| 1844 | |
| 1845 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pNext-06115"); |
| 1846 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1847 | m_errorMonitor->VerifyFound(); |
| 1848 | |
| 1849 | m_commandBuffer->end(); |
| 1850 | } |
| 1851 | |
ziga-lunarg | e7279ba | 2022-03-31 20:55:27 +0200 | [diff] [blame] | 1852 | TEST_F(VkLayerTest, TestBarrierWithDynamicRendering) { |
| 1853 | TEST_DESCRIPTION("Test setting buffer memory barrier when dynamic rendering is active."); |
| 1854 | |
| 1855 | SetTargetApiVersion(VK_API_VERSION_1_3); |
| 1856 | |
| 1857 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1858 | |
| 1859 | if (DeviceValidationVersion() < VK_API_VERSION_1_3) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1860 | GTEST_SKIP() << "At least Vulkan version 1.3 is required"; |
ziga-lunarg | e7279ba | 2022-03-31 20:55:27 +0200 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | auto vk13features = LvlInitStruct<VkPhysicalDeviceVulkan13Features>(); |
| 1864 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&vk13features); |
| 1865 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1866 | if (!vk13features.dynamicRendering) { |
| 1867 | printf("%s Test requires (unsupported) dynamicRendering, skipping\n", kSkipPrefix); |
| 1868 | return; |
| 1869 | } |
| 1870 | if (!vk13features.synchronization2) { |
| 1871 | printf("%s Test requires (unsupported) synchronization2, skipping\n", kSkipPrefix); |
| 1872 | return; |
| 1873 | } |
| 1874 | |
| 1875 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 1876 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1877 | |
| 1878 | PFN_vkCmdBeginRendering vkCmdBeginRendering = |
| 1879 | reinterpret_cast<PFN_vkCmdBeginRendering>(vk::GetDeviceProcAddr(m_device->device(), "vkCmdBeginRendering")); |
| 1880 | assert(vkCmdBeginRendering != nullptr); |
| 1881 | PFN_vkCmdEndRendering vkCmdEndRendering = |
| 1882 | reinterpret_cast<PFN_vkCmdEndRendering>(vk::GetDeviceProcAddr(m_device->device(), "vkCmdEndRendering")); |
| 1883 | assert(vkCmdEndRendering != nullptr); |
| 1884 | |
| 1885 | m_commandBuffer->begin(); |
| 1886 | |
| 1887 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
| 1888 | VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}, 0, 1}; |
| 1889 | begin_rendering_info.renderArea = clear_rect.rect; |
| 1890 | begin_rendering_info.layerCount = 1; |
| 1891 | |
| 1892 | vkCmdBeginRendering(m_commandBuffer->handle(), &begin_rendering_info); |
| 1893 | |
| 1894 | VkBufferObj buffer; |
| 1895 | VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1896 | buffer.init_as_src_and_dst(*m_device, 256, mem_reqs); |
| 1897 | |
| 1898 | auto buf_barrier = lvl_init_struct<VkBufferMemoryBarrier2KHR>(); |
| 1899 | buf_barrier.buffer = buffer.handle(); |
| 1900 | buf_barrier.offset = 0; |
| 1901 | buf_barrier.size = VK_WHOLE_SIZE; |
| 1902 | buf_barrier.srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 1903 | buf_barrier.dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 1904 | |
| 1905 | auto dependency_info = lvl_init_struct<VkDependencyInfoKHR>(); |
| 1906 | dependency_info.bufferMemoryBarrierCount = 1; |
| 1907 | dependency_info.pBufferMemoryBarriers = &buf_barrier; |
| 1908 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdPipelineBarrier2-None-06191"); |
| 1909 | vk::CmdPipelineBarrier2(m_commandBuffer->handle(), &dependency_info); |
| 1910 | m_errorMonitor->VerifyFound(); |
| 1911 | |
| 1912 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdPipelineBarrier-None-06191"); |
| 1913 | vk::CmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, |
| 1914 | nullptr, 0, nullptr, 0, nullptr); |
| 1915 | m_errorMonitor->VerifyFound(); |
| 1916 | |
| 1917 | vkCmdEndRendering(m_commandBuffer->handle()); |
| 1918 | m_commandBuffer->end(); |
| 1919 | } |
| 1920 | |
ziga-lunarg | 4b5bb5b | 2022-03-20 00:49:04 +0100 | [diff] [blame] | 1921 | TEST_F(VkLayerTest, BeginRenderingInvalidStencilAttachmentFormat) { |
| 1922 | TEST_DESCRIPTION("Test begin rendering with a stencil attachment that has an invalid format"); |
| 1923 | |
| 1924 | SetTargetApiVersion(VK_API_VERSION_1_3); |
| 1925 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1926 | |
| 1927 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1928 | |
| 1929 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1930 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | 4b5bb5b | 2022-03-20 00:49:04 +0100 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 1934 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
ziga-lunarg | 4b5bb5b | 2022-03-20 00:49:04 +0100 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeatures>(); |
| 1938 | VkPhysicalDeviceFeatures2 features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1939 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1940 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1941 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1942 | return; |
| 1943 | } |
| 1944 | |
| 1945 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 1946 | |
| 1947 | VkFormat depth_format = FindSupportedDepthOnlyFormat(gpu()); |
| 1948 | if (depth_format == VK_FORMAT_UNDEFINED) { |
| 1949 | printf("%s requires a stencil only format format.\n", kSkipPrefix); |
| 1950 | return; |
| 1951 | } |
| 1952 | |
| 1953 | VkImageObj image(m_device); |
| 1954 | image.Init(32, 32, 1, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); |
| 1955 | VkImageView image_view = image.targetView(depth_format, VK_IMAGE_ASPECT_DEPTH_BIT); |
| 1956 | |
| 1957 | VkRenderingAttachmentInfoKHR stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 1958 | stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL; |
| 1959 | stencil_attachment.imageView = image_view; |
| 1960 | |
| 1961 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
| 1962 | begin_rendering_info.layerCount = 1; |
| 1963 | begin_rendering_info.pStencilAttachment = &stencil_attachment; |
| 1964 | |
| 1965 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingInfo-pStencilAttachment-06548"); |
| 1966 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 1967 | m_errorMonitor->VerifyFound(); |
| 1968 | } |
ziga-lunarg | ce90b52 | 2022-04-27 23:59:46 +0200 | [diff] [blame] | 1969 | |
| 1970 | TEST_F(VkLayerTest, UseStencilAttachmentWithIntegerFormat) { |
| 1971 | TEST_DESCRIPTION("Use stencil attachment with integer format"); |
| 1972 | |
| 1973 | m_errorMonitor->ExpectSuccess(); |
| 1974 | |
| 1975 | SetTargetApiVersion(VK_API_VERSION_1_1); |
| 1976 | AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); |
| 1977 | ASSERT_NO_FATAL_FAILURE(InitFramework()); |
| 1978 | |
| 1979 | if (DeviceValidationVersion() < VK_API_VERSION_1_1) { |
sjfricke | bdd58dd | 2022-05-20 14:22:50 +0900 | [diff] [blame^] | 1980 | GTEST_SKIP() << "At least Vulkan version 1.1 is required"; |
ziga-lunarg | ce90b52 | 2022-04-27 23:59:46 +0200 | [diff] [blame] | 1981 | } |
| 1982 | if (!AreRequestedExtensionsEnabled()) { |
sjfricke | c935ec7 | 2022-05-19 15:26:10 +0900 | [diff] [blame] | 1983 | GTEST_SKIP() << RequestedExtensionsNotSupported() << " not supported"; |
ziga-lunarg | ce90b52 | 2022-04-27 23:59:46 +0200 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | auto dynamic_rendering_features = LvlInitStruct<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(); |
| 1987 | auto features2 = LvlInitStruct<VkPhysicalDeviceFeatures2>(&dynamic_rendering_features); |
| 1988 | vk::GetPhysicalDeviceFeatures2(gpu(), &features2); |
| 1989 | if (dynamic_rendering_features.dynamicRendering == VK_FALSE) { |
| 1990 | printf("%s Test requires (unsupported) dynamicRendering , skipping\n", kSkipPrefix); |
| 1991 | return; |
| 1992 | } |
| 1993 | |
| 1994 | ASSERT_NO_FATAL_FAILURE(InitState(nullptr, &features2)); |
| 1995 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1996 | |
| 1997 | if (ImageFormatIsSupported(gpu(), VK_FORMAT_S8_UINT, VK_IMAGE_TILING_OPTIMAL)) { |
| 1998 | printf("%s VK_FORMAT_S8_UINT format not supported, skipping test.\n", kSkipPrefix); |
| 1999 | return; |
| 2000 | } |
| 2001 | |
| 2002 | auto depth_stencil_resolve_properties = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>(); |
| 2003 | auto properties2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&depth_stencil_resolve_properties); |
| 2004 | vk::GetPhysicalDeviceProperties2(gpu(), &properties2); |
| 2005 | if (depth_stencil_resolve_properties.supportedStencilResolveModes & VK_RESOLVE_MODE_AVERAGE_BIT) { |
| 2006 | printf("%s VK_RESOLVE_MODE_AVERAGE_BIT not supported for VK_FORMAT_S8_UINT, skipping test.\n", kSkipPrefix); |
| 2007 | return; |
| 2008 | } |
| 2009 | |
| 2010 | VkImageCreateInfo image_create_info = LvlInitStruct<VkImageCreateInfo>(); |
| 2011 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2012 | image_create_info.format = VK_FORMAT_S8_UINT; |
| 2013 | image_create_info.extent = {32, 32, 1}; |
| 2014 | image_create_info.mipLevels = 1; |
| 2015 | image_create_info.arrayLayers = 1; |
| 2016 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 2017 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2018 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 2019 | VkImageObj image(m_device); |
| 2020 | image.Init(image_create_info); |
| 2021 | VkImageView image_view = image.targetView(VK_FORMAT_S8_UINT, VK_IMAGE_ASPECT_STENCIL_BIT); |
| 2022 | |
| 2023 | VkRenderingAttachmentInfoKHR stencil_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>(); |
| 2024 | stencil_attachment.imageView = image_view; |
| 2025 | stencil_attachment.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 2026 | stencil_attachment.resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT; |
| 2027 | stencil_attachment.resolveImageLayout = VK_IMAGE_LAYOUT_GENERAL; |
| 2028 | |
| 2029 | VkRenderingInfoKHR begin_rendering_info = LvlInitStruct<VkRenderingInfoKHR>(); |
| 2030 | begin_rendering_info.pStencilAttachment = &stencil_attachment; |
| 2031 | begin_rendering_info.layerCount = 1; |
| 2032 | |
| 2033 | m_commandBuffer->begin(); |
| 2034 | |
| 2035 | m_errorMonitor->VerifyNotFound(); |
| 2036 | |
| 2037 | m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-VkRenderingAttachmentInfo-imageView-06131"); |
| 2038 | m_commandBuffer->BeginRendering(begin_rendering_info); |
| 2039 | m_errorMonitor->VerifyFound(); |
| 2040 | |
| 2041 | m_commandBuffer->end(); |
| 2042 | } |