Assume border color is always in linear space.
authorJarkko Pöyry <jpoyry@google.com>
Fri, 1 May 2015 18:15:21 +0000 (11:15 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Fri, 1 May 2015 18:35:40 +0000 (11:35 -0700)
Bug: 20755158
Change-Id: I18e048e1537ef5b02020d139eb58a498ab917722

framework/common/tcuTexLookupVerifier.cpp
framework/common/tcuTexture.cpp
framework/common/tcuTextureUtil.cpp
modules/gles31/functional/es31fTextureBorderClampTests.cpp

index e7d7ccb..4a70168 100644 (file)
@@ -65,14 +65,13 @@ template<>
 inline Vector<float, 4> lookup (const ConstPixelBufferAccess& access, const Sampler& sampler, int i, int j, int k)
 {
        // Specialization for float lookups: sRGB conversion is performed as specified in format.
-       Vec4 p;
-
        if (coordsInBounds(access, i, j, k))
-               p = access.getPixel(i, j, k);
+       {
+               const Vec4 p = access.getPixel(i, j, k);
+               return isSRGB(access.getFormat()) ? sRGBToLinear(p) : p;
+       }
        else
-               p = sampleTextureBorder<float>(access.getFormat(), sampler);
-
-       return isSRGB(access.getFormat()) ? sRGBToLinear(p) : p;
+               return sampleTextureBorder<float>(access.getFormat(), sampler);
 }
 
 static inline bool isColorValid (const LookupPrecision& prec, const Vec4& ref, const Vec4& result)
index 713cc4c..6fb69f0 100644 (file)
@@ -1249,10 +1249,7 @@ static inline Vec4 lookupBorder (const tcu::TextureFormat& format, const tcu::Sa
        const bool                                              isPureUnsignedInteger   = channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
 
        if (isFloat || isFixed)
-       {
-               const Vec4 p = sampleTextureBorder<float>(format, sampler);
-               return isSRGB(format) ? sRGBToLinear(p) : p;
-       }
+               return sampleTextureBorder<float>(format, sampler);
        else if (isPureInteger)
                return sampleTextureBorder<deInt32>(format, sampler).cast<float>();
        else if (isPureUnsignedInteger)
index df7c20c..0de34c6 100644 (file)
@@ -1348,7 +1348,7 @@ static tcu::Vec4 getTextureBorderColorFloat (const TextureFormat& format, const
                }
        }
 
-       return isSRGB(format) ? sRGBToLinear(result) : result;
+       return result;
 }
 
 static tcu::IVec4 getTextureBorderColorInt (const TextureFormat& format, const Sampler& sampler)
index 92324a5..74eedb7 100644 (file)
@@ -417,6 +417,25 @@ rr::GenericVec4 mapToFormatColorRepresentable (const tcu::TextureFormat& texForm
        de::ArrayBuffer<deUint8, 4>     buffer                  (texFormat.getPixelSize());
        tcu::PixelBufferAccess          access                  (texFormat, tcu::IVec3(1, 1, 1), buffer.getPtr());
 
+       if (tcu::isSRGB(texFormat))
+       {
+               DE_ASSERT(texFormat.type == tcu::TextureFormat::UNORM_INT8);
+
+               // make sure border color (in linear space) can be converted to 8-bit sRGB space without
+               // significant loss.
+               const tcu::Vec4         sRGB            = tcu::linearToSRGB(normalizedRange);
+               const tcu::IVec4        sRGB8           = tcu::IVec4(tcu::floatToU8(sRGB[0]),
+                                                                                                        tcu::floatToU8(sRGB[1]),
+                                                                                                        tcu::floatToU8(sRGB[2]),
+                                                                                                        tcu::floatToU8(sRGB[3]));
+               const tcu::Vec4         linearized      = tcu::sRGBToLinear(tcu::Vec4(sRGB8[0] / 255.0f,
+                                                                                                                                         sRGB8[1] / 255.0f,
+                                                                                                                                         sRGB8[2] / 255.0f,
+                                                                                                                                         sRGB8[3] / 255.0f));
+
+               return rr::GenericVec4(tcu::select(linearized, tcu::Vec4(0.0f), channelMask));
+       }
+
        switch (tcu::getTextureChannelClass(texFormat.type))
        {
                case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT: