Allow rounding error when reading back Z buffer
authorIago Toral Quiroga <itoral@igalia.com>
Mon, 22 Nov 2021 07:29:50 +0000 (08:29 +0100)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Fri, 7 Jan 2022 18:00:28 +0000 (13:00 -0500)
The early fragment test produces Z values <= 0.5 and uses a shader
to write 0.75 that it expects to be ignored due to early fragment
tests, which it verifies by reading back the Z buffer and testing
that all values are <= 0.5.

On our platform, we observe that on storing 0.5 we retrieve
0.500008, which makes us fail the test incorrectly. Fix this
by adding a small room for rounding error, like we do for
other verification paths in these tests.

While we are doing this, lower the tolerance admited for
the late fragment test case as well.

Components: Vulkan
VK-GL-CTS Issue: 3340
Affects:
dEQP-VK.fragment_operations.early_fragment.discard_early_fragment_tests_depth
dEQP-VK.fragment_operations.early_fragment.discard_no_early_fragment_tests_depth

Change-Id: I8e1782b81d0e74a4a5af3e3cac40c9679f543ac6

external/vulkancts/modules/vulkan/fragment_ops/vktFragmentOperationsEarlyFragmentTests.cpp

index f92f1bb..644ff4d 100644 (file)
@@ -755,10 +755,12 @@ tcu::TestStatus EarlyFragmentDiscardTestInstance::iterate (void)
                        int             stencilValue    = (m_testMode == MODE_STENCIL) ? dsPixelAccess.getPixStencil(x, y, z) : 0;
 
                        // Depth test should write to the depth buffer even when there is a discard in the fragment shader,
-                       // when early fragment tests are enabled.
+                       // when early fragment tests are enabled. We allow some tolerance to account for precision error
+                       // on depth writes.
                        if (m_testMode == MODE_DEPTH)
                        {
-                               if (m_useEarlyTests && ((x + y) < 31) && depthValue >= 0.5f)
+                               float tolerance = 0.0001f;
+                               if (m_useEarlyTests && ((x + y) < 31) && depthValue >= 0.50 + tolerance)
                                {
                                        std::ostringstream error;
                                        error << "Rendered depth value [ "<< x << ", " << y << ", " << z << "] is not correct: " << depthValue << " >= 0.5f";
@@ -766,7 +768,7 @@ tcu::TestStatus EarlyFragmentDiscardTestInstance::iterate (void)
                                }
                                // When early fragment tests are disabled, the depth test happens after the fragment shader, but as we are discarding
                                // all fragments, the stored value in the depth buffer should be the clear one (0.5f).
-                               if (!m_useEarlyTests && deAbs(depthValue - 0.5f) > 0.01f)
+                               if (!m_useEarlyTests && deAbs(depthValue - 0.5f) > tolerance)
                                {
                                        std::ostringstream error;
                                        error << "Rendered depth value [ "<< x << ", " << y << ", " << z << "] is not correct: " << depthValue << " != 0.5f";