Fix LAYOUT_UNDEFINED transitions in descriptor_indexing tests
authorJeff Bolz <jbolz@nvidia.com>
Fri, 18 Oct 2019 17:05:46 +0000 (12:05 -0500)
committerJeff Bolz <jbolz@nvidia.com>
Fri, 18 Oct 2019 20:50:35 +0000 (15:50 -0500)
Commit 7b7ba4e0 caused the UNDEFINED->COLOR layout transition to be applied four
times, corrupting 3/4 of the image. Change the tests to do the layout transition
once, right after the framebuffer is created.

VK-GL-CTS Issue: 2064
Components: Vulkan
Affects: dEQP-VK.descriptor_indexing.*

Change-Id: Ie599ba76ba75af6fee1f4163bd96ea2bd6e4c145

external/vulkancts/modules/vulkan/descriptor_indexing/vktDescriptorSetsIndexingTests.cpp

index de3ca6138b391f454e43a9af3f739bc491796817..91e204a285c9efd1bf83848b25c66c59a5c52c70 100644 (file)
@@ -752,7 +752,8 @@ Move<VkRenderPass> CommonDescriptorInstance::createRenderPass               (const IterateCom
        DE_UNREF(variables);
        if ((m_testParams.stageFlags & VK_SHADER_STAGE_VERTEX_BIT) || (m_testParams.stageFlags & VK_SHADER_STAGE_FRAGMENT_BIT))
        {
-               return vk::makeRenderPass(m_vki, m_vkd, m_colorFormat);
+               // Use VK_ATTACHMENT_LOAD_OP_LOAD to make the utility function select initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
+               return vk::makeRenderPass(m_vki, m_vkd, m_colorFormat, VK_FORMAT_UNDEFINED, VK_ATTACHMENT_LOAD_OP_LOAD);
        }
        return Move<VkRenderPass>();
 }
@@ -1201,6 +1202,66 @@ void CommonDescriptorInstance::iterateCommandBegin                                       (IterateCommonVariables&
 
        vk::beginCommandBuffer                          (m_vki, *variables.commandBuffer);
 
+       // Clear color attachment, and transition it to VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
+       if ((m_testParams.stageFlags & VK_SHADER_STAGE_VERTEX_BIT) || (m_testParams.stageFlags & VK_SHADER_STAGE_FRAGMENT_BIT))
+       {
+               const VkImageMemoryBarrier preImageBarrier =
+               {
+                       VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                         // VkStructureType              sType
+                       DE_NULL,                                                                                        // const void*                  pNext
+                       0u,                                                                                                     // VkAccessFlags                srcAccessMask
+                       VK_ACCESS_TRANSFER_WRITE_BIT,                                           // VkAccessFlags                dstAccessMask
+                       VK_IMAGE_LAYOUT_UNDEFINED,                                                      // VkImageLayout                oldLayout
+                       VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                           // VkImageLayout                newLayout
+                       VK_QUEUE_FAMILY_IGNORED,                                                        // uint32_t                             srcQueueFamilyIndex
+                       VK_QUEUE_FAMILY_IGNORED,                                                        // uint32_t                             dstQueueFamilyIndex
+                       *variables.frameBuffer->image->image,                           // VkImage                              image
+                       {
+                               VK_IMAGE_ASPECT_COLOR_BIT,                              // VkImageAspectFlags   aspectMask
+                               0u,                                                                             // uint32_t                             baseMipLevel
+                               VK_REMAINING_MIP_LEVELS,                                // uint32_t                             mipLevels,
+                               0u,                                                                             // uint32_t                             baseArray
+                               VK_REMAINING_ARRAY_LAYERS,                              // uint32_t                             arraySize
+                       }
+               };
+
+               m_vki.cmdPipelineBarrier(*variables.commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
+                                                               (VkDependencyFlags)0,
+                                                               0, (const VkMemoryBarrier*)DE_NULL,
+                                                               0, (const VkBufferMemoryBarrier*)DE_NULL,
+                                                               1, &preImageBarrier);
+
+               const VkClearColorValue clearColorValue         = makeClearValueColor(m_clearColor).color;
+               m_vki.cmdClearColorImage(*variables.commandBuffer, *variables.frameBuffer->image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColorValue, 1, &preImageBarrier.subresourceRange);
+
+               const VkImageMemoryBarrier postImageBarrier =
+               {
+                       VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                         // VkStructureType              sType
+                       DE_NULL,                                                                                        // const void*                  pNext
+                       VK_ACCESS_TRANSFER_WRITE_BIT,                                           // VkAccessFlags                srcAccessMask
+                       VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                           // VkAccessFlags                dstAccessMask
+                       VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                           // VkImageLayout                oldLayout
+                       VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,                       // VkImageLayout                newLayout
+                       VK_QUEUE_FAMILY_IGNORED,                                                        // uint32_t                             srcQueueFamilyIndex
+                       VK_QUEUE_FAMILY_IGNORED,                                                        // uint32_t                             dstQueueFamilyIndex
+                       *variables.frameBuffer->image->image,                           // VkImage                              image
+                       {
+                               VK_IMAGE_ASPECT_COLOR_BIT,                              // VkImageAspectFlags   aspectMask
+                               0u,                                                                             // uint32_t                             baseMipLevel
+                               VK_REMAINING_MIP_LEVELS,                                // uint32_t                             mipLevels,
+                               0u,                                                                             // uint32_t                             baseArray
+                               VK_REMAINING_ARRAY_LAYERS,                              // uint32_t                             arraySize
+                       }
+               };
+
+               m_vki.cmdPipelineBarrier(*variables.commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+                                                               (VkDependencyFlags)0,
+                                                               0, (const VkMemoryBarrier*)DE_NULL,
+                                                               0, (const VkBufferMemoryBarrier*)DE_NULL,
+                                                               1, &postImageBarrier);
+
+       }
+
        if (m_testParams.calculateInLoop)
        {
                deRandom rnd;
@@ -2296,7 +2357,7 @@ Move<VkRenderPass> InputAttachmentInstance::createRenderPass              (const IterateComm
                VK_ATTACHMENT_STORE_OP_STORE,                           // VkAttachmentStoreOp                          storeOp;
                VK_ATTACHMENT_LOAD_OP_DONT_CARE,                        // VkAttachmentLoadOp                           stencilLoadOp;
                VK_ATTACHMENT_STORE_OP_DONT_CARE,                       // VkAttachmentStoreOp                          stencilStoreOp;
-               VK_IMAGE_LAYOUT_UNDEFINED,                                      // VkImageLayout                                        initialLayout;
+               VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                                        initialLayout;
                VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                                        finalLayout;
        };
        const VkAttachmentReference             colorAttachmentRef =