Fix sync problems in conditional_rendering.draw_clear tests
authorRicardo Garcia <rgarcia@igalia.com>
Wed, 16 Dec 2020 11:06:59 +0000 (12:06 +0100)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 7 Jan 2021 13:48:24 +0000 (13:48 +0000)
* Invalidate results buffer allocations before attempting to read data.

* Fix synchronization of m_conditionalRenderingBuffer instead of
  m_resultBuffer before verifying its contents.

* Check for vertexPipelineStoresAndAtomics when needed.

* Split update_with_rendering tests in two render passes so
  buffer synchronization works properly and passes validation.

Affected tests:
dEQP-VK.conditional_rendering.draw_clear.*

Components: Vulkan
VK-GL-CTS issue: 2703

Change-Id: I2ae26e19e37c323bdbf94cade419fe5be3ed4f5c

external/vulkancts/modules/vulkan/conditional_rendering/vktConditionalDrawAndClearTests.cpp

index beaaae3..9113482 100644 (file)
@@ -794,6 +794,8 @@ tcu::TestStatus ConditionalRenderingClearAttachmentsTestInstance::iterate (void)
 
        submitCommandsAndWait(m_vkd, m_device, m_queue, *m_cmdBufferPrimary);
 
+       invalidateMappedMemoryRange(m_vkd, m_device, m_resultBuffer->getBoundMemory().getMemory(), m_resultBuffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
+
        tcu::ConstPixelBufferAccess                                     result(mapVkFormat(m_testParams.m_testDepth ? VK_FORMAT_D32_SFLOAT : VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), m_resultBuffer->getBoundMemory().getHostPtr());
 
        std::vector<float>                                                      referenceData((m_testParams.m_testDepth ? 1 : 4) * WIDTH * HEIGHT, 0);
@@ -978,6 +980,8 @@ tcu::TestStatus ConditionalRenderingDrawTestInstance::iterate (void)
 
        submitCommandsAndWait(m_vkd, m_device, m_queue, *m_cmdBufferPrimary);
 
+       invalidateMappedMemoryRange(m_vkd, m_device, m_resultBuffer->getBoundMemory().getMemory(), m_resultBuffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
+
        tcu::ConstPixelBufferAccess                     result(mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), m_resultBuffer->getBoundMemory().getHostPtr());
 
        std::vector<float>                                      referenceData(4 * WIDTH * HEIGHT, 0.5f);
@@ -1230,9 +1234,13 @@ tcu::TestStatus ConditionalRenderingUpdateBufferWithDrawTestInstance::iterate (v
 
        draw();
 
+       endRenderPass(m_vkd, *m_cmdBufferPrimary);
+
        bufferMemoryBarrier(m_conditionalRenderingBuffer->object(), m_conditionalRenderingBufferOffset, sizeof(deUint32), VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT,
                                                VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT);
 
+       beginRenderPass(m_vkd, *m_cmdBufferPrimary, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT));
+
        m_vkd.cmdBindPipeline(*m_cmdBufferPrimary, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineDraw);
        m_vkd.cmdBindDescriptorSets(*m_cmdBufferPrimary, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0, 1, &(*m_descriptorSet), 0, DE_NULL);
 
@@ -1261,7 +1269,7 @@ tcu::TestStatus ConditionalRenderingUpdateBufferWithDrawTestInstance::iterate (v
                vk::VK_ACCESS_HOST_READ_BIT,
                VK_QUEUE_FAMILY_IGNORED,
                VK_QUEUE_FAMILY_IGNORED,
-               m_conditionalRenderingBuffer->object(),
+               m_resultBuffer->object(),
                0u,
                VK_WHOLE_SIZE
        };
@@ -1272,6 +1280,8 @@ tcu::TestStatus ConditionalRenderingUpdateBufferWithDrawTestInstance::iterate (v
 
        submitCommandsAndWait(m_vkd, m_device, m_queue, *m_cmdBufferPrimary);
 
+       invalidateMappedMemoryRange(m_vkd, m_device, m_resultBuffer->getBoundMemory().getMemory(), m_resultBuffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
+
        tcu::ConstPixelBufferAccess                     result(mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), m_resultBuffer->getBoundMemory().getHostPtr());
 
        std::vector<float>                                      referenceData(4 * WIDTH * HEIGHT, 0.0f);
@@ -1279,8 +1289,6 @@ tcu::TestStatus ConditionalRenderingUpdateBufferWithDrawTestInstance::iterate (v
 
        m_testParams ? prepareReferenceImageOneColor(reference, tcu::Vec4(0,1,0,1)) : prepareReferenceImageOneColor(reference, clearColorInitial);
 
-       invalidateMappedMemoryRange(m_vkd, m_device, m_conditionalRenderingBuffer->getBoundMemory().getMemory(), m_conditionalRenderingBuffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
-
        if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Comparison", "Comparison", reference, result, tcu::Vec4(0.01f), tcu::COMPARE_LOG_ON_ERROR))
                return tcu::TestStatus::fail("Fail");
 
@@ -1413,6 +1421,15 @@ void checkFan (Context& context)
        }
 }
 
+void checkFanAndVertexStores (Context& context)
+{
+       checkFan(context);
+
+       const auto& features = context.getDeviceFeatures();
+       if (!features.vertexPipelineStoresAndAtomics)
+               TCU_THROW(NotSupportedError, "Vertex pipeline stores and atomics not supported");
+}
+
 } // unnamed namespace
 
 ConditionalRenderingDrawAndClearTests::ConditionalRenderingDrawAndClearTests (tcu::TestContext &testCtx)
@@ -1443,8 +1460,8 @@ void ConditionalRenderingDrawAndClearTests::init (void)
        for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(drawTestGrid); testNdx++)
                draw->addChild(new InstanceFactory1WithSupport<ConditionalRenderingDrawTestInstance, DrawTestParams, FunctionSupport0, AddProgramsDraw>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, "case_" + de::toString(testNdx), "Draw test.", AddProgramsDraw(), drawTestGrid[testNdx], checkFan));
 
-       draw->addChild(new InstanceFactory1WithSupport<ConditionalRenderingUpdateBufferWithDrawTestInstance, bool, FunctionSupport0, AddProgramsUpdateBufferUsingRendering>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, "update_with_rendering_no_discard", "Draw test.", AddProgramsUpdateBufferUsingRendering(), true, checkFan));
-       draw->addChild(new InstanceFactory1WithSupport<ConditionalRenderingUpdateBufferWithDrawTestInstance, bool, FunctionSupport0, AddProgramsUpdateBufferUsingRendering>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, "update_with_rendering_discard", "Draw test.", AddProgramsUpdateBufferUsingRendering(), false, checkFan));
+       draw->addChild(new InstanceFactory1WithSupport<ConditionalRenderingUpdateBufferWithDrawTestInstance, bool, FunctionSupport0, AddProgramsUpdateBufferUsingRendering>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, "update_with_rendering_no_discard", "Draw test.", AddProgramsUpdateBufferUsingRendering(), true, checkFanAndVertexStores));
+       draw->addChild(new InstanceFactory1WithSupport<ConditionalRenderingUpdateBufferWithDrawTestInstance, bool, FunctionSupport0, AddProgramsUpdateBufferUsingRendering>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, "update_with_rendering_discard", "Draw test.", AddProgramsUpdateBufferUsingRendering(), false, checkFanAndVertexStores));
 
        clear->addChild(color);
        clear->addChild(depth);