Add missing barrier in ssbo layout tests
authorIago Toral Quiroga <itoral@igalia.com>
Fri, 24 Mar 2017 11:51:08 +0000 (12:51 +0100)
committerIago Toral Quiroga <itoral@igalia.com>
Fri, 31 Mar 2017 07:50:09 +0000 (09:50 +0200)
The tests map storage buffers written by compute shaders
to verify results. Add a barrier before host access to
these buffers.

Components: Vulkan
VK-GL-CTS issue: 326

Affected tests:
dEQP-VK.ssbo.layout.*

Change-Id: I760969e6a572c0f79a6ff2b41721445016a8bba4

external/vulkancts/modules/vulkan/ssbo/vktSSBOLayoutCase.cpp

index e4a18e8a4504c383036daf270442352f41d4574d..c4e17a3744f970f078cb6d88f43548689bd55893 100644 (file)
@@ -1953,8 +1953,8 @@ tcu::TestStatus SSBOLayoutCaseInstance::iterate (void)
        vector<BlockDataPtr>  mappedBlockPtrs;
 
        // Upload base buffers
+       const std::vector<int> bufferSizes      = computeBufferSizes(m_interface, m_refLayout);
        {
-               const std::vector<int>                  bufferSizes             = computeBufferSizes(m_interface, m_refLayout);
                std::vector<void*>                              mapPtrs;
                std::vector<BlockLocation>              blockLocations  (numBlocks);
 
@@ -2136,6 +2136,50 @@ tcu::TestStatus SSBOLayoutCaseInstance::iterate (void)
 
        vk.cmdDispatch(*cmdBuffer, 1, 1, 1);
 
+       // Add barriers for shader writes to storage buffers before host access
+       std::vector<vk::VkBufferMemoryBarrier> barriers;
+       if (m_bufferMode == SSBOLayoutCase::BUFFERMODE_PER_BLOCK)
+       {
+               for (int blockNdx = 0; blockNdx < numBlocks; blockNdx++)
+               {
+                       const vk::VkBufferMemoryBarrier barrier =
+                       {
+                               vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
+                               DE_NULL,
+                               vk::VK_ACCESS_SHADER_WRITE_BIT,
+                               vk::VK_ACCESS_HOST_READ_BIT,
+                               VK_QUEUE_FAMILY_IGNORED,
+                               VK_QUEUE_FAMILY_IGNORED,
+                               static_cast<vk::VkBuffer>(*m_uniformBuffers[blockNdx]),
+                               0u,
+                               static_cast<vk::VkDeviceSize>(bufferSizes[blockNdx])
+                       };
+                       barriers.push_back(barrier);
+               }
+       }
+       else
+       {
+               vk::VkDeviceSize totalSize      = 0;
+               for (size_t bufferNdx = 0; bufferNdx < bufferSizes.size(); bufferNdx++)
+                       totalSize += bufferSizes[bufferNdx];
+
+               const vk::VkBufferMemoryBarrier barrier =
+               {
+                       vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
+                       DE_NULL,
+                       vk::VK_ACCESS_SHADER_WRITE_BIT,
+                       vk::VK_ACCESS_HOST_READ_BIT,
+                       VK_QUEUE_FAMILY_IGNORED,
+                       VK_QUEUE_FAMILY_IGNORED,
+                       static_cast<vk::VkBuffer>(*m_uniformBuffers[0]),
+                       0u,
+                       totalSize
+               };
+               barriers.push_back(barrier);
+       }
+       vk.cmdPipelineBarrier(*cmdBuffer, vk::VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, vk::VK_PIPELINE_STAGE_HOST_BIT, (vk::VkDependencyFlags)0,
+                                                 0u, DE_NULL, static_cast<deUint32>(barriers.size()), &barriers[0], 0u, DE_NULL);
+
        VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
 
        const vk::VkFenceCreateInfo     fenceParams =