Merge vk-gl-cts/vulkan-cts-1.3.2 to vk-gl-cts/vulkan-cts-1.3.3
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / texture / vktTextureConversionTests.cpp
index 9892ba4..f286967 100644 (file)
@@ -32,6 +32,7 @@
 #include "tcuVectorUtil.hpp"
 #include "deSharedPtr.hpp"
 
+#include <cmath>
 #include <memory>
 
 namespace vkt
@@ -62,6 +63,7 @@ public:
        virtual tcu::TestStatus iterate                                         (void) override;
 
 protected:
+       tcu::IVec4                              computeColorDistance            () const;
        bool                                    verifyPixels                            (const tcu::PixelBufferAccess&  rendered,
                                                                                                                 const tcu::PixelBufferAccess&  reference,
                                                                                                                 const ReferenceParams&                 samplerParams,
@@ -78,6 +80,7 @@ private:
        tcu::Texture2D                          m_swTexture;
        TextureRenderer                         m_renderer;
 
+       const tcu::IVec4                        m_cd;
        const tcu::IVec4                        m_a;
        const tcu::IVec4                        m_b;
        const tcu::IVec4                        m_c;
@@ -96,10 +99,11 @@ SnormLinearClampInstance::SnormLinearClampInstance (vkt::Context& context, de::S
        , m_hwTexture   (TestTexture2DSp(new pipeline::TestTexture2D(m_inFormat, textureWidth, textureHeight)))
        , m_swTexture   (m_inFormat, textureWidth, textureHeight, 1)
        , m_renderer    (context, VK_SAMPLE_COUNT_1_BIT, m_params->width, m_params->height, 1u, makeComponentMappingRGBA(), VK_IMAGE_TYPE_2D, VK_IMAGE_VIEW_TYPE_2D, m_outFormat)
-       , m_a                   (lim(m_inFormat, 0),    lim(m_inFormat, 1)+2,   lim(m_inFormat, 2),             lim(m_inFormat, 3)+2)
-       , m_b                   (lim(m_inFormat, 0)+2,  lim(m_inFormat, 1),             lim(m_inFormat, 2)+2,   lim(m_inFormat, 3)      )
-       , m_c                   (lim(m_inFormat, 0)+1,  lim(m_inFormat, 1)+1,   lim(m_inFormat, 2)+1,   lim(m_inFormat, 3)+1)
-       , m_d                   (lim(m_inFormat, 0),    lim(m_inFormat, 1),             lim(m_inFormat, 2),             lim(m_inFormat, 3)      )
+       , m_cd                  (computeColorDistance())
+       , m_a                   (lim(m_inFormat, 0),                    lim(m_inFormat, 1)+m_cd[1]*2,   lim(m_inFormat, 2),                             lim(m_inFormat, 3)+m_cd[3]*2)
+       , m_b                   (lim(m_inFormat, 0)+m_cd[0]*2,  lim(m_inFormat, 1),                             lim(m_inFormat, 2)+m_cd[2]*2,   lim(m_inFormat, 3)                      )
+       , m_c                   (lim(m_inFormat, 0)+m_cd[0]*1,  lim(m_inFormat, 1)+m_cd[1]*1,   lim(m_inFormat, 2)+m_cd[2]*1,   lim(m_inFormat, 3)+m_cd[3]*1)
+       , m_d                   (lim(m_inFormat, 0),                    lim(m_inFormat, 1),                             lim(m_inFormat, 2),                             lim(m_inFormat, 3)                      )
 {
        tcu::IVec4 data[textureWidth * textureHeight] =
        {
@@ -135,6 +139,17 @@ int SnormLinearClampInstance::lim (const tcu::TextureFormat& format, int channel
        return channelBits[channelIdx] ? (-deIntMaxValue32(channelBits[channelIdx])) : (-1);
 }
 
+tcu::IVec4 SnormLinearClampInstance::computeColorDistance () const
+{
+       return tcu::IVec4
+       (
+               static_cast<int>(std::floor(static_cast<float>(-lim(m_inFormat, 0)) / 127.0f)),
+               static_cast<int>(std::floor(static_cast<float>(-lim(m_inFormat, 0)) / 127.0f)),
+               static_cast<int>(std::floor(static_cast<float>(-lim(m_inFormat, 0)) / 127.0f)),
+               static_cast<int>(std::floor(static_cast<float>(-lim(m_inFormat, 0)) / 127.0f))
+       );
+}
+
 bool SnormLinearClampInstance::verifyPixels    (const tcu::PixelBufferAccess& rendered, const tcu::PixelBufferAccess& reference, const ReferenceParams& samplerParams, const std::vector<float>& texCoords) const
 {
        tcu::LodPrecision                               lodPrec;
@@ -144,6 +159,7 @@ bool SnormLinearClampInstance::verifyPixels (const tcu::PixelBufferAccess& rende
        const int                                               width                   (m_renderer.getRenderWidth());
        const int                                               height                  (m_renderer.getRenderHeight());
 
+       const tcu::IVec4                                colorDistance   (computeColorDistance());
        std::unique_ptr<deUint8[]>              errorMaskData   (new deUint8[width * height * 4 * 4]);
        tcu::PixelBufferAccess                  errorMask               (mapVkFormat(m_outFormat), width, height, 1, errorMaskData.get());
 
@@ -154,10 +170,10 @@ bool SnormLinearClampInstance::verifyPixels       (const tcu::PixelBufferAccess& rende
        lookupPrec.uvwBits                              = tcu::IVec3(5,5,0);
        lookupPrec.coordBits                    = tcu::IVec3(20,20,0);
        lookupPrec.colorMask                    = tcu::BVec4(nuc >= 1, nuc >= 2, nuc >=3, nuc >= 4);
-       lookupPrec.colorThreshold               = tcu::Vec4(0.9f/float(-lim(m_inFormat, 0)),
-                                                                                               0.9f/float(-lim(m_inFormat, 1)),
-                                                                                               0.9f/float(-lim(m_inFormat, 2)),
-                                                                                               0.9f/float(-lim(m_inFormat, 3)));
+       lookupPrec.colorThreshold               = tcu::Vec4(0.9f/float(colorDistance[0]),
+                                                                                               0.9f/float(colorDistance[1]),
+                                                                                               0.9f/float(colorDistance[2]),
+                                                                                               0.9f/float(colorDistance[3]));
 
        const int numFailedPixels               = glu::TextureTestUtil::computeTextureLookupDiff(rendered, reference, errorMask,
                                                                                                                                                                         m_swTexture, texCoords.data(), samplerParams,