From 590654f3cc9b77c50c1842aeeb6434358307b492 Mon Sep 17 00:00:00 2001 From: Kyle Griffiths Date: Fri, 17 Apr 2020 12:26:54 +0100 Subject: [PATCH] Allow RTZ rounding in spv_assembly*writes_two_buffers* tests Because the tests perform an add operation, mismatch of the CPU and GPU rounding modes can cause the tests to incorrectly fail. This change modifies the verification to allow up to 1 ULP difference between the output and the expected result, which covers the maximum difference between RNE and RTZ rounding modes. Components: Vulkan Affects: dEQP-VK.spirv_assembly.instruction.graphics* VK-GL-CTS issue: 2320 Change-Id: Ic76942add1382c23885118f806ac593cc730eb73 (cherry picked from commit 49c720ff8c7b0bc397aeae7c9ee7e3e9c40b12f3) --- .../vktSpvAsmGraphicsShaderTestUtil.cpp | 48 ++++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmGraphicsShaderTestUtil.cpp b/external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmGraphicsShaderTestUtil.cpp index 698aabd..63e24e5 100644 --- a/external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmGraphicsShaderTestUtil.cpp +++ b/external/vulkancts/modules/vulkan/spirv_assembly/vktSpvAsmGraphicsShaderTestUtil.cpp @@ -4649,31 +4649,43 @@ TestStatus runAndVerifyDefaultPipeline (Context& context, InstanceContext instan if (deMemCmp(&expectedBytes.front(), outResourceMemories[outputNdx]->getHostPtr(), expectedBytes.size())) { - // Some *variable_pointers* tests store counters in buffer - // whose value may vary if the same vertex shader may be executed for multiple times - // in this case the output value can be expected value + non-negative integer N - if (instance.customizedStages == VK_SHADER_STAGE_VERTEX_BIT) + const size_t numExpectedEntries = expectedBytes.size() / sizeof(float); + float* expectedFloats = reinterpret_cast(&expectedBytes.front()); + float* outputFloats = reinterpret_cast(outResourceMemories[outputNdx]->getHostPtr()); + float diff = 0.0f; + deUint32 bitDiff = 0; + + for (size_t expectedNdx = 0; expectedNdx < numExpectedEntries; ++expectedNdx) { - const size_t numExpectedEntries = expectedBytes.size() / sizeof(float); - const float* expectedFloats = reinterpret_cast(&expectedBytes.front()); - const float* outputFloats = reinterpret_cast(outResourceMemories[outputNdx]->getHostPtr()); - float diff = 0.0f; + // RTZ and RNE can introduce a difference of a single ULP + // The RTZ output will always be either equal or lower than the RNE expected, + // so perform a bitwise subtractraction and check for the ULP difference + bitDiff = *reinterpret_cast(&expectedFloats[expectedNdx]) - *reinterpret_cast(&outputFloats[expectedNdx]); - for (size_t expectedNdx = 0; expectedNdx < numExpectedEntries; ++expectedNdx) + // Allow a maximum of 1 ULP difference to account for RTZ rounding + if (bitDiff & (~0x1)) { - if (deFloatIsInf(outputFloats[expectedNdx]) || deFloatIsNaN(outputFloats[expectedNdx])) - return tcu::TestStatus::fail("Value returned is invalid"); + // Note: RTZ/RNE rounding leniency isn't applied for the checks below: + + // Some *variable_pointers* tests store counters in buffer + // whose value may vary if the same vertex shader may be executed for multiple times + // in this case the output value can be expected value + non-negative integer N + if (instance.customizedStages == VK_SHADER_STAGE_VERTEX_BIT) + { + if (deFloatIsInf(outputFloats[expectedNdx]) || deFloatIsNaN(outputFloats[expectedNdx])) + return tcu::TestStatus::fail("Value returned is invalid"); - diff = outputFloats[expectedNdx] - expectedFloats[expectedNdx]; + diff = outputFloats[expectedNdx] - expectedFloats[expectedNdx]; - if ((diff < 0.0f) || (deFloatFloor(diff) != diff)) - return tcu::TestStatus::fail("Value returned should be equal to expected value plus non-negative integer"); + if ((diff < 0.0f) || (deFloatFloor(diff) != diff)) + return tcu::TestStatus::fail("Value returned should be equal to expected value plus non-negative integer"); + } + else + { + return tcu::TestStatus::fail("Resource returned should be equal to expected, allowing for RTZ/RNE rounding"); + } } } - else - { - return tcu::TestStatus::fail("Resource returned doesn't match bitwisely with expected"); - } } } -- 2.7.4