Fix validation problems with renderpass tests
authorRicardo Garcia <rgarcia@igalia.com>
Mon, 13 Apr 2020 10:17:42 +0000 (12:17 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Mon, 20 Apr 2020 07:57:05 +0000 (03:57 -0400)
This commit fixes several problems found while running the set of
renderpass tests with an up-to-date version of the validation layers.

* Stencil aspects of some images were not being properly transitioned to
  the expected layout used later in some tests.

* Fixed reported interface mismatch between vertex and geometry shaders.

* Invalid flush size for the vertex buffer in some tests, caused by not
  properly honoring nonCoherentAtomSize.

* In the same case as above, the allocation offset was being rounded up
  to the nearest multiple of nonCoherentAtomSize instead of being
  rounded down, which means some vertices could be left unflushed.

In addition, de::roundUp and de::roundDown are introduced by the commit
as they are somewhat frequent operations in some tests, but only updates
the affected renderpass tests to use them.

Affected tests:
dEQP-VK.renderpass.*

Components: Framework, Vulkan
VK-GL-CTS issue: 2307

Change-Id: Ic78b2fe4707c4ddb0ade91d85e124190e94a1ed2

external/vulkancts/modules/vulkan/renderpass/vktRenderPassSubpassDependencyTests.cpp
external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp
framework/delibs/decpp/deDefs.hpp

index b4c91d2..24002d9 100644 (file)
@@ -1455,6 +1455,39 @@ tcu::TestStatus SubpassDependencyTestInstance::iterateInternal (void)
 
        beginCommandBuffer(vkd, *commandBuffer);
 
+       // Transition stencil aspects to the final layout directly.
+       if (isDepthStencilFormat(m_format))
+       {
+               const VkImageSubresourceRange imageSubresourceRange =
+               {
+                       VK_IMAGE_ASPECT_STENCIL_BIT,    // VkImageAspectFlags   aspectMask
+                       0u,                                                             // uint32_t                             baseMipLevel
+                       1u,                                                             // uint32_t                             levelCount
+                       0u,                                                             // uint32_t                             baseArrayLayer
+                       1u                                                              // uint32_t                             layerCount
+               };
+
+               VkImageMemoryBarrier barrier =
+               {
+                       VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                         // VkStructureType                      sType
+                       DE_NULL,                                                                                        // const void*                          pNext
+                       0u,                                                                                                     // VkAccessFlags                        srcAccessMask
+                       VK_ACCESS_TRANSFER_READ_BIT,                                            // VkAccessFlags                        dstAccessMask
+                       VK_IMAGE_LAYOUT_UNDEFINED,                                                      // VkImageLayout                        oldLayout
+                       VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,        // VkImageLayout                        newLayout
+                       VK_QUEUE_FAMILY_IGNORED,                                                        // uint32_t                                     srcQueueFamilyIndex
+                       VK_QUEUE_FAMILY_IGNORED,                                                        // uint32_t                                     dstQueueFamilyIndex
+                       DE_NULL,                                                                                        // VkImage                                      image
+                       imageSubresourceRange                                                           // VkImageSubresourceRange      subresourceRange
+               };
+
+               for (deUint32 attachmentNdx = 0; attachmentNdx < attachmentCount; ++attachmentNdx)
+               {
+                       barrier.image = **m_images[attachmentNdx];
+                       vkd.cmdPipelineBarrier(*commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, DE_NULL, 0u, DE_NULL, 1u, &barrier);
+               }
+       }
+
        // Begin render pass
        {
                VkRect2D                                        renderArea                      =
@@ -2968,6 +3001,9 @@ struct SubpassSelfDependencyBackwardsPrograms
                dst.glslSources.add("vert") << glu::VertexSource(
                                "#version 450\n"
                                "layout(location = 0) in highp vec4 position;\n"
+                               "out gl_PerVertex {\n"
+                               "    vec4 gl_Position;\n"
+                               "};\n"
                                "void main (void)\n"
                                "{\n"
                                "    gl_Position = position;\n"
index 85c036d..d6dce0c 100644 (file)
@@ -1580,8 +1580,8 @@ void uploadBufferData (const DeviceInterface&     vk,
                                           VkDeviceSize                         nonCoherentAtomSize)
 {
        // Expand the range to flush to account for the nonCoherentAtomSize
-       VkDeviceSize roundedOffset = (VkDeviceSize)deAlignSize(deUint32(memory.getOffset()), deUint32(nonCoherentAtomSize));
-       VkDeviceSize roundedSize = (VkDeviceSize)deAlignSize(deUint32(memory.getOffset() + size - roundedOffset), deUint32(nonCoherentAtomSize));
+       const VkDeviceSize roundedOffset        = de::roundDown(memory.getOffset(), nonCoherentAtomSize);
+       const VkDeviceSize roundedSize          = de::roundUp(memory.getOffset() - roundedOffset + static_cast<VkDeviceSize>(size), nonCoherentAtomSize);
 
        const VkMappedMemoryRange range =
        {
@@ -2112,13 +2112,16 @@ public:
                        m_pipelineLayout                = createPipelineLayout(vk, device, &pipelineLayoutParams);
                        m_pipeline                              = createSubpassPipeline(vk, device, renderPass, *m_vertexShaderModule, *m_fragmentShaderModule, *m_pipelineLayout, m_renderInfo);
 
-                       m_vertexBuffer                  = createBuffer(vk, device, 0u, (VkDeviceSize)renderQuad.getVertexDataSize(), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE, 1u, &queueFamilyIndex);
+                       // Round up the vertex buffer size to honor nonCoherentAtomSize.
+                       const auto      properties                      = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
+                       const auto      vertexBufferSize        = de::roundUp(static_cast<VkDeviceSize>(renderQuad.getVertexDataSize()), properties.limits.nonCoherentAtomSize);
+
+                       m_vertexBuffer                  = createBuffer(vk, device, 0u, vertexBufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE, 1u, &queueFamilyIndex);
                        m_vertexBufferMemory    = allocateBuffer(vki, vk, physDevice, device, *m_vertexBuffer, MemoryRequirement::HostVisible, allocator, allocationKind);
 
                        bindBufferMemory(vk, device, *m_vertexBuffer, m_vertexBufferMemory->getMemory(), m_vertexBufferMemory->getOffset());
 
-                       const vk::VkPhysicalDeviceProperties properties = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
-                       uploadBufferData(vk, device, *m_vertexBufferMemory, renderQuad.getVertexDataSize(), renderQuad.getVertexPointer(), properties.limits.nonCoherentAtomSize);
+                       uploadBufferData(vk, device, *m_vertexBufferMemory, static_cast<size_t>(vertexBufferSize), renderQuad.getVertexPointer(), properties.limits.nonCoherentAtomSize);
 
                        if (renderInfo.getInputAttachmentCount() > 0)
                        {
index 9c47636..895b489 100644 (file)
@@ -62,6 +62,12 @@ template<typename T> inline T                leftSetMask             (T n)           { const T tlen = T(sizeof(T)
 //! Return T with high n bits reset
 template<typename T> inline T          leftZeroMask    (T n)           { return T(~leftSetMask(n)); }
 
+//! Round x up to a multiple of y.
+template<typename T> inline T          roundUp                 (T x, T y)      { DE_ASSERT(y != T(0)); const T mod = x % y; return x + ((mod == T(0)) ? T(0) : (y - mod)); }
+
+//! Round x down to a multiple of y.
+template<typename T> inline T          roundDown               (T x, T y)      { DE_ASSERT(y != T(0)); return (x / y) * y; }
+
 //! Helper for DE_CHECK() macros.
 void throwRuntimeError (const char* message, const char* expr, const char* file, int line);