Add support for UNORM_SHORT_1555 format; fix bugs
authorPyry Haulos <phaulos@google.com>
Thu, 3 Dec 2015 00:37:01 +0000 (16:37 -0800)
committerPyry Haulos <phaulos@google.com>
Thu, 3 Dec 2015 00:40:05 +0000 (16:40 -0800)
Change-Id: Ia1a5354872fb355c27f312cc320357079810ea6f

framework/common/tcuTexture.cpp
framework/common/tcuTexture.hpp
framework/common/tcuTextureUtil.cpp
modules/internal/ditTextureFormatTests.cpp

index 4dca727..0fd15bc 100644 (file)
@@ -260,7 +260,7 @@ inline deUint32 convertSatRteUint24 (float f)
 int getChannelSize (TextureFormat::ChannelType type)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (type)
        {
@@ -324,7 +324,7 @@ int getNumUsedChannels (TextureFormat::ChannelOrder order)
 inline float channelToFloat (const deUint8* value, TextureFormat::ChannelType type)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (type)
        {
@@ -354,7 +354,7 @@ inline float channelToFloat (const deUint8* value, TextureFormat::ChannelType ty
 inline int channelToInt (const deUint8* value, TextureFormat::ChannelType type)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (type)
        {
@@ -384,7 +384,7 @@ inline int channelToInt (const deUint8* value, TextureFormat::ChannelType type)
 void floatToChannel (deUint8* dst, float src, TextureFormat::ChannelType type)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (type)
        {
@@ -441,7 +441,7 @@ static inline deUint32 convertSatUint24 (S src)
 void intToChannel (deUint8* dst, int src, TextureFormat::ChannelType type)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (type)
        {
@@ -606,6 +606,9 @@ bool isValid (TextureFormat format)
                case TextureFormat::UNSIGNED_SHORT_5551:
                        return format.order == TextureFormat::RGBA || format.order == TextureFormat::BGRA;
 
+               case TextureFormat::UNORM_SHORT_1555:
+                       return format.order == TextureFormat::ARGB;
+
                case TextureFormat::UNORM_INT_101010:
                        return format.order == TextureFormat::RGB;
 
@@ -650,7 +653,7 @@ bool isValid (TextureFormat format)
                        return 0u;
        }
 
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 }
 
 /** Get pixel size in bytes. */
@@ -662,7 +665,7 @@ int getPixelSize (TextureFormat format)
        DE_ASSERT(isValid(format));
 
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (type)
        {
@@ -674,6 +677,7 @@ int getPixelSize (TextureFormat format)
                case TextureFormat::UNORM_SHORT_555:
                case TextureFormat::UNORM_SHORT_4444:
                case TextureFormat::UNORM_SHORT_5551:
+               case TextureFormat::UNORM_SHORT_1555:
                case TextureFormat::UNSIGNED_SHORT_565:
                case TextureFormat::UNSIGNED_SHORT_4444:
                case TextureFormat::UNSIGNED_SHORT_5551:
@@ -947,20 +951,24 @@ Vec4 ConstPixelBufferAccess::getPixel (int x, int y, int z) const
        {
                case TextureFormat::UNORM_BYTE_44:                              return                    Vec4(UN8 (4,   4), UN8 ( 0,  4), 0.0f, 1.0f);
                case TextureFormat::UNSIGNED_BYTE_44:                   return                   UVec4(UI8 (4,   4), UI8 ( 0,  4), 0u, 1u).cast<float>();
-               case TextureFormat::UNORM_SHORT_565:                    return swizzleRB( Vec4(UN16(11,  5), UN16( 5,  6), UN16( 0,  5), 1.0f), TextureFormat::RGB, m_format.order);
-               case TextureFormat::UNSIGNED_SHORT_565:                 return swizzleRB(UVec4(UI16(11,  5), UI16( 5,  6), UI16( 0,  5), 1u), TextureFormat::RGB, m_format.order).cast<float>();
-               case TextureFormat::UNORM_SHORT_555:                    return swizzleRB( Vec4(UN16(10,  5), UN16( 5,  5), UN16( 0,  5), 1.0f), TextureFormat::RGB, m_format.order);
-               case TextureFormat::UNORM_SHORT_4444:                   return swizzleRB( Vec4(UN16(12,  4), UN16( 8,  4), UN16( 4,  4), UN16( 0, 4)), TextureFormat::RGBA, m_format.order);
-               case TextureFormat::UNSIGNED_SHORT_4444:                return swizzleRB(UVec4(UI16(12,  4), UI16( 8,  4), UI16( 4,  4), UI16( 0, 4)), TextureFormat::RGBA, m_format.order).cast<float>();
-               case TextureFormat::UNORM_SHORT_5551:                   return swizzleRB( Vec4(UN16(11,  5), UN16( 6,  5), UN16( 1,  5), UN16( 0, 1)), TextureFormat::RGBA, m_format.order);
-               case TextureFormat::UNSIGNED_SHORT_5551:                return swizzleRB(UVec4(UI16(11,  5), UI16( 6,  5), UI16( 1,  5), UI16( 0, 1)), TextureFormat::RGBA, m_format.order).cast<float>();
+               case TextureFormat::UNORM_SHORT_565:                    return swizzleRB( Vec4(UN16(11,  5), UN16( 5,  6), UN16( 0,  5), 1.0f), m_format.order, TextureFormat::RGB);
+               case TextureFormat::UNSIGNED_SHORT_565:                 return swizzleRB(UVec4(UI16(11,  5), UI16( 5,  6), UI16( 0,  5), 1u), m_format.order, TextureFormat::RGB).cast<float>();
+               case TextureFormat::UNORM_SHORT_555:                    return swizzleRB( Vec4(UN16(10,  5), UN16( 5,  5), UN16( 0,  5), 1.0f), m_format.order, TextureFormat::RGB);
+               case TextureFormat::UNORM_SHORT_4444:                   return swizzleRB( Vec4(UN16(12,  4), UN16( 8,  4), UN16( 4,  4), UN16( 0, 4)), m_format.order, TextureFormat::RGBA);
+               case TextureFormat::UNSIGNED_SHORT_4444:                return swizzleRB(UVec4(UI16(12,  4), UI16( 8,  4), UI16( 4,  4), UI16( 0, 4)), m_format.order, TextureFormat::RGBA).cast<float>();
+               case TextureFormat::UNORM_SHORT_5551:                   return swizzleRB( Vec4(UN16(11,  5), UN16( 6,  5), UN16( 1,  5), UN16( 0, 1)), m_format.order, TextureFormat::RGBA);
+               case TextureFormat::UNSIGNED_SHORT_5551:                return swizzleRB(UVec4(UI16(11,  5), UI16( 6,  5), UI16( 1,  5), UI16( 0, 1)), m_format.order, TextureFormat::RGBA).cast<float>();
                case TextureFormat::UNORM_INT_101010:                   return                    Vec4(UN32(22, 10), UN32(12, 10), UN32( 2, 10), 1.0f);
-               case TextureFormat::UNORM_INT_1010102_REV:              return swizzleRB( Vec4(UN32( 0, 10), UN32(10, 10), UN32(20, 10), UN32(30, 2)), TextureFormat::RGBA, m_format.order);
-               case TextureFormat::SNORM_INT_1010102_REV:              return swizzleRB( Vec4(SN32( 0, 10), SN32(10, 10), SN32(20, 10), SN32(30, 2)), TextureFormat::RGBA, m_format.order);
-               case TextureFormat::UNSIGNED_INT_1010102_REV:   return swizzleRB( UVec4(UI32(0, 10), UI32(10, 10), UI32(20, 10), UI32(30, 2)), TextureFormat::RGBA, m_format.order).cast<float>();
-               case TextureFormat::SIGNED_INT_1010102_REV:             return swizzleRB( UVec4(SI32(0, 10), SI32(10, 10), SI32(20, 10), SI32(30, 2)), TextureFormat::RGBA, m_format.order).cast<float>();
+               case TextureFormat::UNORM_INT_1010102_REV:              return swizzleRB( Vec4(UN32( 0, 10), UN32(10, 10), UN32(20, 10), UN32(30, 2)), m_format.order, TextureFormat::RGBA);
+               case TextureFormat::SNORM_INT_1010102_REV:              return swizzleRB( Vec4(SN32( 0, 10), SN32(10, 10), SN32(20, 10), SN32(30, 2)), m_format.order, TextureFormat::RGBA);
+               case TextureFormat::UNSIGNED_INT_1010102_REV:   return swizzleRB( UVec4(UI32(0, 10), UI32(10, 10), UI32(20, 10), UI32(30, 2)), m_format.order, TextureFormat::RGBA).cast<float>();
+               case TextureFormat::SIGNED_INT_1010102_REV:             return swizzleRB( UVec4(SI32(0, 10), SI32(10, 10), SI32(20, 10), SI32(30, 2)), m_format.order, TextureFormat::RGBA).cast<float>();
                case TextureFormat::UNSIGNED_INT_999_E5_REV:    return unpackRGB999E5(*((const deUint32*)pixelPtr));
 
+               case TextureFormat::UNORM_SHORT_1555:
+                       DE_ASSERT(m_format.order == TextureFormat::ARGB);
+                       return Vec4(UN16(15, 1), UN16(10, 5), UN16(5, 5), UN16(0, 5)).swizzle(1,2,3,0); // ARGB -> RGBA
+
                case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:
                        return Vec4(Float11(UI32(0, 11)).asFloat(), Float11(UI32(11, 11)).asFloat(), Float10(UI32(22, 10)).asFloat(), 1.0f);
 
@@ -1039,17 +1047,21 @@ IVec4 ConstPixelBufferAccess::getPixelInt (int x, int y, int z) const
                case TextureFormat::UNSIGNED_BYTE_44:                   // Fall-through
                case TextureFormat::UNORM_BYTE_44:                              return                   UVec4(U8 ( 4,  4), U8 ( 0,  4), 0u, 1u).cast<int>();
                case TextureFormat::UNSIGNED_SHORT_565:                 // Fall-through
-               case TextureFormat::UNORM_SHORT_565:                    return swizzleRB(UVec4(U16(11,  5), U16( 5,  6), U16( 0,  5), 1).cast<int>(), TextureFormat::RGB, m_format.order);
-               case TextureFormat::UNORM_SHORT_555:                    return swizzleRB(UVec4(U16(10,  5), U16( 5,  5), U16( 0,  5), 1).cast<int>(), TextureFormat::RGB, m_format.order);
+               case TextureFormat::UNORM_SHORT_565:                    return swizzleRB(UVec4(U16(11,  5), U16( 5,  6), U16( 0,  5), 1).cast<int>(), m_format.order, TextureFormat::RGB);
+               case TextureFormat::UNORM_SHORT_555:                    return swizzleRB(UVec4(U16(10,  5), U16( 5,  5), U16( 0,  5), 1).cast<int>(), m_format.order, TextureFormat::RGB);
                case TextureFormat::UNSIGNED_SHORT_4444:                // Fall-through
-               case TextureFormat::UNORM_SHORT_4444:                   return swizzleRB(UVec4(U16(12,  4), U16( 8,  4), U16( 4,  4), U16( 0, 4)).cast<int>(), TextureFormat::RGBA, m_format.order);
+               case TextureFormat::UNORM_SHORT_4444:                   return swizzleRB(UVec4(U16(12,  4), U16( 8,  4), U16( 4,  4), U16( 0, 4)).cast<int>(), m_format.order, TextureFormat::RGBA);
                case TextureFormat::UNSIGNED_SHORT_5551:                // Fall-through
-               case TextureFormat::UNORM_SHORT_5551:                   return swizzleRB(UVec4(U16(11,  5), U16( 6,  5), U16( 1,  5), U16( 0, 1)).cast<int>(), TextureFormat::RGBA, m_format.order);
+               case TextureFormat::UNORM_SHORT_5551:                   return swizzleRB(UVec4(U16(11,  5), U16( 6,  5), U16( 1,  5), U16( 0, 1)).cast<int>(), m_format.order, TextureFormat::RGBA);
                case TextureFormat::UNORM_INT_101010:                   return                   UVec4(U32(22, 10), U32(12, 10), U32( 2, 10), 1).cast<int>();
                case TextureFormat::UNORM_INT_1010102_REV:              // Fall-through
-               case TextureFormat::UNSIGNED_INT_1010102_REV:   return swizzleRB(UVec4(U32( 0, 10), U32(10, 10), U32(20, 10), U32(30, 2)), TextureFormat::RGBA, m_format.order).cast<int>();
+               case TextureFormat::UNSIGNED_INT_1010102_REV:   return swizzleRB(UVec4(U32( 0, 10), U32(10, 10), U32(20, 10), U32(30, 2)), m_format.order, TextureFormat::RGBA).cast<int>();
                case TextureFormat::SNORM_INT_1010102_REV:              // Fall-through
-               case TextureFormat::SIGNED_INT_1010102_REV:             return swizzleRB(IVec4(S32( 0, 10), S32(10, 10), S32(20, 10), S32(30, 2)), TextureFormat::RGBA, m_format.order);
+               case TextureFormat::SIGNED_INT_1010102_REV:             return swizzleRB(IVec4(S32( 0, 10), S32(10, 10), S32(20, 10), S32(30, 2)), m_format.order, TextureFormat::RGBA);
+
+               case TextureFormat::UNORM_SHORT_1555:
+                       DE_ASSERT(m_format.order == TextureFormat::ARGB);
+                       return UVec4(U16(15, 1), U16(10, 5), U16(5, 5), U16(0, 5)).cast<int>().swizzle(1,2,3,0); // ARGB -> RGBA
 
                default:
                        break; // To generic path.
@@ -1210,77 +1222,84 @@ void PixelBufferAccess::setPixel (const Vec4& color, int x, int y, int z) const
 
                case TextureFormat::UNORM_SHORT_565:
                {
-                       const Vec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGB);
+                       const Vec4 swizzled = swizzleRB(color, TextureFormat::RGB, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PN(swizzled[0], 11, 5) | PN(swizzled[1], 5, 6) | PN(swizzled[2], 0, 5));
                        break;
                }
 
                case TextureFormat::UNSIGNED_SHORT_565:
                {
-                       const UVec4 swizzled = swizzleRB(color.cast<deUint32>(), m_format.order, TextureFormat::RGB);
+                       const UVec4 swizzled = swizzleRB(color.cast<deUint32>(), TextureFormat::RGB, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PU(swizzled[0], 11, 5) | PU(swizzled[1], 5, 6) | PU(swizzled[2], 0, 5));
                        break;
                }
 
                case TextureFormat::UNORM_SHORT_555:
                {
-                       const Vec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGB);
+                       const Vec4 swizzled = swizzleRB(color, TextureFormat::RGB, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PN(swizzled[0], 10, 5) | PN(swizzled[1], 5, 5) | PN(swizzled[2], 0, 5));
                        break;
                }
 
                case TextureFormat::UNORM_SHORT_4444:
                {
-                       const Vec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGBA);
+                       const Vec4 swizzled = swizzleRB(color, TextureFormat::RGBA, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PN(swizzled[0], 12, 4) | PN(swizzled[1], 8, 4) | PN(swizzled[2], 4, 4) | PN(swizzled[3], 0, 4));
                        break;
                }
 
                case TextureFormat::UNSIGNED_SHORT_4444:
                {
-                       const UVec4 swizzled = swizzleRB(color.cast<deUint32>(), m_format.order, TextureFormat::RGBA);
+                       const UVec4 swizzled = swizzleRB(color.cast<deUint32>(), TextureFormat::RGBA, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PU(swizzled[0], 12, 4) | PU(swizzled[1], 8, 4) | PU(swizzled[2], 4, 4) | PU(swizzled[3], 0, 4));
                        break;
                }
 
                case TextureFormat::UNORM_SHORT_5551:
                {
-                       const Vec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGBA);
+                       const Vec4 swizzled = swizzleRB(color, TextureFormat::RGBA, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PN(swizzled[0], 11, 5) | PN(swizzled[1], 6, 5) | PN(swizzled[2], 1, 5) | PN(swizzled[3], 0, 1));
                        break;
                }
 
+               case TextureFormat::UNORM_SHORT_1555:
+               {
+                       const Vec4 swizzled = color.swizzle(3,0,1,2); // RGBA -> ARGB
+                       *((deUint16*)pixelPtr) = (deUint16)(PN(swizzled[0], 15, 1) | PN(swizzled[1], 10, 5) | PN(swizzled[2], 5, 5) | PN(swizzled[3], 0, 5));
+                       break;
+               }
+
                case TextureFormat::UNSIGNED_SHORT_5551:
                {
-                       const UVec4 swizzled = swizzleRB(color.cast<deUint32>(), m_format.order, TextureFormat::RGBA);
+                       const UVec4 swizzled = swizzleRB(color.cast<deUint32>(), TextureFormat::RGBA, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PU(swizzled[0], 11, 5) | PU(swizzled[1], 6, 5) | PU(swizzled[2], 1, 5) | PU(swizzled[3], 0, 1));
                        break;
                }
 
                case TextureFormat::UNORM_INT_1010102_REV:
                {
-                       const Vec4 u = swizzleRB(color, m_format.order, TextureFormat::RGBA);
+                       const Vec4 u = swizzleRB(color, TextureFormat::RGBA, m_format.order);
                        *((deUint32*)pixelPtr) = PN(u[0], 0, 10) | PN(u[1], 10, 10) | PN(u[2], 20, 10) | PN(u[3], 30, 2);
                        break;
                }
 
                case TextureFormat::SNORM_INT_1010102_REV:
                {
-                       const Vec4 u = swizzleRB(color, m_format.order, TextureFormat::RGBA);
+                       const Vec4 u = swizzleRB(color, TextureFormat::RGBA, m_format.order);
                        *((deUint32*)pixelPtr) = PS(u[0], 0, 10) | PS(u[1], 10, 10) | PS(u[2], 20, 10) | PS(u[3], 30, 2);
                        break;
                }
 
                case TextureFormat::UNSIGNED_INT_1010102_REV:
                {
-                       const UVec4 u = swizzleRB(color.cast<deUint32>(), m_format.order, TextureFormat::RGBA);
+                       const UVec4 u = swizzleRB(color.cast<deUint32>(), TextureFormat::RGBA, m_format.order);
                        *((deUint32*)pixelPtr) = PU(u[0], 0, 10) | PU(u[1], 10, 10) | PU(u[2], 20, 10) | PU(u[3], 30, 2);
                        break;
                }
 
                case TextureFormat::SIGNED_INT_1010102_REV:
                {
-                       const IVec4 u = swizzleRB(color.cast<deInt32>(), m_format.order, TextureFormat::RGBA);
+                       const IVec4 u = swizzleRB(color.cast<deInt32>(), TextureFormat::RGBA, m_format.order);
                        *((deUint32*)pixelPtr) = PI(u[0], 0, 10) | PI(u[1], 10, 10) | PI(u[2], 20, 10) | PI(u[3], 30, 2);
                        break;
                }
@@ -1352,14 +1371,14 @@ void PixelBufferAccess::setPixel (const IVec4& color, int x, int y, int z) const
                case TextureFormat::UNORM_SHORT_565:
                case TextureFormat::UNSIGNED_SHORT_565:
                {
-                       const IVec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGB);
+                       const IVec4 swizzled = swizzleRB(color, TextureFormat::RGB, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PU(swizzled[0], 11, 5) | PU(swizzled[1], 5, 6) | PU(swizzled[2], 0, 5));
                        break;
                }
 
                case TextureFormat::UNORM_SHORT_555:
                {
-                       const IVec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGB);
+                       const IVec4 swizzled = swizzleRB(color, TextureFormat::RGB, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PU(swizzled[0], 10, 5) | PU(swizzled[1], 5, 5) | PU(swizzled[2], 0, 5));
                        break;
                }
@@ -1367,7 +1386,7 @@ void PixelBufferAccess::setPixel (const IVec4& color, int x, int y, int z) const
                case TextureFormat::UNORM_SHORT_4444:
                case TextureFormat::UNSIGNED_SHORT_4444:
                {
-                       const IVec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGBA);
+                       const IVec4 swizzled = swizzleRB(color, TextureFormat::RGBA, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PU(swizzled[0], 12, 4) | PU(swizzled[1], 8, 4) | PU(swizzled[2], 4, 4) | PU(swizzled[3], 0, 4));
                        break;
                }
@@ -1375,15 +1394,22 @@ void PixelBufferAccess::setPixel (const IVec4& color, int x, int y, int z) const
                case TextureFormat::UNORM_SHORT_5551:
                case TextureFormat::UNSIGNED_SHORT_5551:
                {
-                       const IVec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGBA);
+                       const IVec4 swizzled = swizzleRB(color, TextureFormat::RGBA, m_format.order);
                        *((deUint16*)pixelPtr) = (deUint16)(PU(swizzled[0], 11, 5) | PU(swizzled[1], 6, 5) | PU(swizzled[2], 1, 5) | PU(swizzled[3], 0, 1));
                        break;
                }
 
+               case TextureFormat::UNORM_SHORT_1555:
+               {
+                       const IVec4 swizzled = color.swizzle(3,0,1,2); // RGBA -> ARGB
+                       *((deUint16*)pixelPtr) = (deUint16)(PU(swizzled[0], 15, 1) | PU(swizzled[1], 10, 5) | PU(swizzled[2], 5, 5) | PU(swizzled[3], 0, 5));
+                       break;
+               }
+
                case TextureFormat::UNORM_INT_1010102_REV:
                case TextureFormat::UNSIGNED_INT_1010102_REV:
                {
-                       const IVec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGBA);
+                       const IVec4 swizzled = swizzleRB(color, TextureFormat::RGBA, m_format.order);
                        *((deUint32*)pixelPtr) = PU(swizzled[0],  0, 10) | PU(swizzled[1], 10, 10) | PU(swizzled[2], 20, 10) | PU(swizzled[3], 30, 2);
                        break;
                }
@@ -1391,7 +1417,7 @@ void PixelBufferAccess::setPixel (const IVec4& color, int x, int y, int z) const
                case TextureFormat::SNORM_INT_1010102_REV:
                case TextureFormat::SIGNED_INT_1010102_REV:
                {
-                       const IVec4 swizzled = swizzleRB(color, m_format.order, TextureFormat::RGBA);
+                       const IVec4 swizzled = swizzleRB(color, TextureFormat::RGBA, m_format.order);
                        *((deUint32*)pixelPtr) = PI(swizzled[0],  0, 10) | PI(swizzled[1], 10, 10) | PI(swizzled[2], 20, 10) | PI(swizzled[3], 30, 2);
                        break;
                }
@@ -3752,6 +3778,7 @@ std::ostream& operator<< (std::ostream& str, TextureFormat::ChannelType type)
                "UNORM_SHORT_555",
                "UNORM_SHORT_4444",
                "UNORM_SHORT_5551",
+               "UNORM_SHORT_1555",
                "UNORM_INT_101010",
                "SNORM_INT_1010102_REV",
                "UNORM_INT_1010102_REV",
index fb4d229..43dcb57 100644 (file)
@@ -83,6 +83,7 @@ public:
                UNORM_SHORT_555,
                UNORM_SHORT_4444,
                UNORM_SHORT_5551,
+               UNORM_SHORT_1555,
                UNORM_INT_101010,
                SNORM_INT_1010102_REV,
                UNORM_INT_1010102_REV,
index d130cc3..7556259 100644 (file)
@@ -115,7 +115,7 @@ bool isSRGB (TextureFormat format)
 bool isCombinedDepthStencilType (TextureFormat::ChannelType type)
 {
        // make sure to update this if type table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        return  type == TextureFormat::UNSIGNED_INT_16_8_8                      ||
                        type == TextureFormat::UNSIGNED_INT_24_8                        ||
@@ -157,7 +157,7 @@ bool hasDepthComponent (TextureFormat::ChannelOrder order)
 TextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (channelType)
        {
@@ -173,6 +173,7 @@ TextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelTy
                case TextureFormat::UNORM_SHORT_555:                            return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
                case TextureFormat::UNORM_SHORT_4444:                           return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
                case TextureFormat::UNORM_SHORT_5551:                           return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
+               case TextureFormat::UNORM_SHORT_1555:                           return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT;
                case TextureFormat::UNSIGNED_BYTE_44:                           return TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
                case TextureFormat::UNSIGNED_SHORT_565:                         return TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
                case TextureFormat::UNSIGNED_SHORT_4444:                        return TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
@@ -196,9 +197,11 @@ TextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelTy
                case TextureFormat::UNSIGNED_INT32:                                     return TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
                case TextureFormat::HALF_FLOAT:                                         return TEXTURECHANNELCLASS_FLOATING_POINT;
                case TextureFormat::FLOAT:                                                      return TEXTURECHANNELCLASS_FLOATING_POINT;
-               case TextureFormat::FLOAT64:                                                    return TEXTURECHANNELCLASS_FLOATING_POINT;
+               case TextureFormat::FLOAT64:                                            return TEXTURECHANNELCLASS_FLOATING_POINT;
                case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:        return TEXTURECHANNELCLASS_LAST;                                        //!< packed float32-pad24-uint8
-               default:                                                                                        return TEXTURECHANNELCLASS_LAST;
+               default:
+                       DE_FATAL("Unknown channel type");
+                       return TEXTURECHANNELCLASS_LAST;
        }
 }
 
@@ -339,7 +342,7 @@ ConstPixelBufferAccess flipYAccess (const ConstPixelBufferAccess& access)
 static Vec2 getFloatChannelValueRange (TextureFormat::ChannelType channelType)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        float cMin = 0.0f;
        float cMax = 0.0f;
@@ -362,6 +365,7 @@ static Vec2 getFloatChannelValueRange (TextureFormat::ChannelType channelType)
                case TextureFormat::UNORM_SHORT_555:
                case TextureFormat::UNORM_SHORT_4444:
                case TextureFormat::UNORM_SHORT_5551:
+               case TextureFormat::UNORM_SHORT_1555:
                case TextureFormat::UNORM_INT_101010:
                case TextureFormat::UNORM_INT_1010102_REV:                      cMin = 0.0f;                    cMax = 1.0f;                    break;
 
@@ -378,6 +382,8 @@ static Vec2 getFloatChannelValueRange (TextureFormat::ChannelType channelType)
                case TextureFormat::FLOAT64:                                            cMin = -1e5f;                   cMax = 1e5f;                    break;
                case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:       cMin = 0.0f;                    cMax = 1e4f;                    break;
                case TextureFormat::UNSIGNED_INT_999_E5_REV:            cMin = 0.0f;                    cMax = 1e5f;                    break;
+               case TextureFormat::UNSIGNED_BYTE_44:                           cMin = 0.0f;                    cMax = 15.f;                    break;
+               case TextureFormat::UNSIGNED_SHORT_4444:                        cMin = 0.0f;                    cMax = 15.f;                    break;
 
                default:
                        DE_ASSERT(false);
@@ -397,11 +403,16 @@ static Vec2 getFloatChannelValueRange (TextureFormat::ChannelType channelType)
 TextureFormatInfo getTextureFormatInfo (const TextureFormat& format)
 {
        // Special cases.
-       if (format == TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT_1010102_REV))
-               return TextureFormatInfo(Vec4(      0.0f,                   0.0f,                   0.0f,                0.0f),
-                                                                Vec4(   1023.0f,                1023.0f,                1023.0f,                3.0f),
+       if (format.type == TextureFormat::UNSIGNED_INT_1010102_REV)
+               return TextureFormatInfo(Vec4(       0.0f,                  0.0f,                   0.0f,                0.0f),
+                                                                Vec4(    1023.0f,               1023.0f,                1023.0f,                3.0f),
+                                                                Vec4(1.0f/1023.f,      1.0f/1023.0f,   1.0f/1023.0f,   1.0f/3.0f),
+                                                                Vec4(       0.0f,                  0.0f,                   0.0f,                0.0f));
+       if (format.type == TextureFormat::SIGNED_INT_1010102_REV)
+               return TextureFormatInfo(Vec4(    -512.0f,               -512.0f,                -512.0f,               -2.0f),
+                                                                Vec4(     511.0f,                511.0f,                 511.0f,                1.0f),
                                                                 Vec4(1.0f/1023.f,      1.0f/1023.0f,   1.0f/1023.0f,   1.0f/3.0f),
-                                                                Vec4(      0.0f,                   0.0f,                   0.0f,                0.0f));
+                                                                Vec4(       0.5f,                  0.5f,                   0.5f,                0.5f));
        else if (format.order == TextureFormat::D || format.order == TextureFormat::DS)
                return TextureFormatInfo(Vec4(0.0f,     0.0f,   0.0f,   0.0f),
                                                                 Vec4(1.0f,     1.0f,   1.0f,   0.0f),
@@ -412,6 +423,16 @@ TextureFormatInfo getTextureFormatInfo (const TextureFormat& format)
                                                                 Vec4(1.0f, 1.0f, 1.0f, 1.5f),
                                                                 Vec4(1.0f, 1.0f, 1.0f, 1.0f),
                                                                 Vec4(0.0f, 0.0f, 0.0f, 0.0f));
+       else if (format.type == TextureFormat::UNSIGNED_SHORT_5551)
+               return TextureFormatInfo(Vec4(     0.0f,                  0.0f,           0.0f, 0.0f),
+                                                                Vec4(    31.0f,                 31.0f,          31.0f, 1.0f),
+                                                                Vec4(1.0f/31.f,        1.0f/31.0f,     1.0f/31.0f,     1.0f),
+                                                                Vec4(     0.0f,                  0.0f,           0.0f, 0.0f));
+       else if (format.type == TextureFormat::UNSIGNED_SHORT_565)
+               return TextureFormatInfo(Vec4(     0.0f,                  0.0f,           0.0f, 0.0f),
+                                                                Vec4(    31.0f,                 63.0f,          31.0f, 0.0f),
+                                                                Vec4(1.0f/31.f,        1.0f/63.0f,     1.0f/31.0f,     1.0f),
+                                                                Vec4(     0.0f,                  0.0f,           0.0f, 0.0f));
 
        const Vec2                                              cRange          = getFloatChannelValueRange(format.type);
        const TextureSwizzle::Channel*  map                     = getChannelReadSwizzle(format.order).components;
@@ -483,7 +504,7 @@ UVec4 getFormatMaxUintValue (const TextureFormat& format)
 static IVec4 getChannelBitDepth (TextureFormat::ChannelType channelType)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (channelType)
        {
@@ -499,6 +520,7 @@ static IVec4 getChannelBitDepth (TextureFormat::ChannelType channelType)
                case TextureFormat::UNORM_SHORT_4444:                           return IVec4(4);
                case TextureFormat::UNORM_SHORT_555:                            return IVec4(5,5,5,0);
                case TextureFormat::UNORM_SHORT_5551:                           return IVec4(5,5,5,1);
+               case TextureFormat::UNORM_SHORT_1555:                           return IVec4(1,5,5,5);
                case TextureFormat::UNSIGNED_BYTE_44:                           return IVec4(4,4,0,0);
                case TextureFormat::UNSIGNED_SHORT_565:                         return IVec4(5,6,5,0);
                case TextureFormat::UNSIGNED_SHORT_4444:                        return IVec4(4);
@@ -549,7 +571,7 @@ IVec4 getTextureFormatBitDepth (const TextureFormat& format)
 static IVec4 getChannelMantissaBitDepth (TextureFormat::ChannelType channelType)
 {
        // make sure this table is updated if format table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        switch (channelType)
        {
@@ -565,6 +587,7 @@ static IVec4 getChannelMantissaBitDepth (TextureFormat::ChannelType channelType)
                case TextureFormat::UNORM_SHORT_4444:
                case TextureFormat::UNORM_SHORT_555:
                case TextureFormat::UNORM_SHORT_5551:
+               case TextureFormat::UNORM_SHORT_1555:
                case TextureFormat::UNSIGNED_BYTE_44:
                case TextureFormat::UNSIGNED_SHORT_565:
                case TextureFormat::UNSIGNED_SHORT_4444:
@@ -1223,7 +1246,7 @@ template <typename AccessType>
 static AccessType toSamplerAccess (const AccessType& baseAccess, Sampler::DepthStencilMode mode)
 {
        // make sure to update this if type table is updated
-       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 37);
+       DE_STATIC_ASSERT(TextureFormat::CHANNELTYPE_LAST == 38);
 
        if (!isCombinedDepthStencilType(baseAccess.getFormat().type))
                return baseAccess;
@@ -1492,6 +1515,8 @@ static const TextureSwizzle& getBorderColorReadSwizzle (TextureFormat::ChannelOr
                case TextureFormat::sRG:                swizzle = &RG;          break;
                case TextureFormat::sRGB:               swizzle = &RGB;         break;
                case TextureFormat::sRGBA:              swizzle = &RGBA;        break;
+               case TextureFormat::sBGR:               swizzle = &RGB;         break;
+               case TextureFormat::sBGRA:              swizzle = &RGBA;        break;
                case TextureFormat::D:                  swizzle = &D;           break;
                case TextureFormat::S:                  swizzle = &S;           break;
 
index a7afdb1..6cfa441 100644 (file)
@@ -426,6 +426,26 @@ static const deUint32 s_unsignedShort5551FloatRef[] =
        0x41d80000, 0x40e00000, 0x41c80000, 0x00000000,
 };
 
+static const deUint8 s_unormShort1555In[] =
+{
+       0xf8, 0xc5, 0x1f, 0x6c,
+       0xf0, 0x2f, 0xf2, 0x95,
+};
+static const deUint32 s_unormShort1555FloatRef[] =
+{
+       0x3f800000, 0x3f0c6319, 0x3ef7bdef, 0x3f46318c,
+       0x00000000, 0x3f5ef7be, 0x00000000, 0x3f800000,
+       0x00000000, 0x3eb5ad6b, 0x3f800000, 0x3f042108,
+       0x3f800000, 0x3e25294a, 0x3ef7bdef, 0x3f14a529,
+};
+static const deUint32 s_unormShort1555IntRef[] =
+{
+       0x00000001, 0x00000011, 0x0000000f, 0x00000018,
+       0x00000000, 0x0000001b, 0x00000000, 0x0000001f,
+       0x00000000, 0x0000000b, 0x0000001f, 0x00000010,
+       0x00000001, 0x00000005, 0x0000000f, 0x00000012,
+};
+
 static const deUint8 s_unormInt101010In[] =
 {
        0x81, 0xb3, 0x67, 0x51,
@@ -1032,6 +1052,7 @@ static const struct
        { s_unormShort555In,                    DE_LENGTH_OF_ARRAY(s_unormShort555In),                          s_unormShort555FloatRef,                        s_unormShort555IntRef,                  s_unormShort555IntRef,                  },
        { s_unormShort4444In,                   DE_LENGTH_OF_ARRAY(s_unormShort4444In),                         s_unormShort4444FloatRef,                       s_unormShort4444IntRef,                 s_unormShort4444IntRef,                 },
        { s_unormShort5551In,                   DE_LENGTH_OF_ARRAY(s_unormShort5551In),                         s_unormShort5551FloatRef,                       s_unormShort5551IntRef,                 s_unormShort5551IntRef,                 },
+       { s_unormShort1555In,                   DE_LENGTH_OF_ARRAY(s_unormShort1555In),                         s_unormShort1555FloatRef,                       s_unormShort1555IntRef,                 s_unormShort1555IntRef,                 },
        { s_unormInt101010In,                   DE_LENGTH_OF_ARRAY(s_unormInt101010In),                         s_unormInt101010FloatRef,                       s_unormInt101010IntRef,                 s_unormInt101010IntRef                  },
 
        // \note Same input data & int reference used for {U,S}NORM_INT_1010102_REV
@@ -1353,6 +1374,19 @@ protected:
                }
        }
 
+       void verifyInfoQueries (void)
+       {
+               const tcu::TextureChannelClass  chnClass        = tcu::getTextureChannelClass(m_format.type);
+               const tcu::TextureFormatInfo    fmtInfo         = tcu::getTextureFormatInfo(m_format);
+
+               if (tcu::isCombinedDepthStencilType(m_format.type))
+                       TCU_CHECK(chnClass == tcu::TEXTURECHANNELCLASS_LAST);
+               else
+                       TCU_CHECK(de::inBounds(chnClass, (tcu::TextureChannelClass)0, tcu::TEXTURECHANNELCLASS_LAST));
+
+               DE_UNREF(fmtInfo);
+       }
+
        const TextureFormat             m_format;
 };
 
@@ -1375,6 +1409,8 @@ public:
 
                m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
 
+               verifyInfoQueries();
+
                verifyRead(inputAccess);
 
                // \todo [2015-10-12 pyry] Handle lossy conversion with *NORM_INT32
@@ -1408,6 +1444,8 @@ public:
 
                m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
 
+               verifyInfoQueries();
+
                verifyRead(inputDepthAccess);
 
                m_testCtx.getLog() << TestLog::Message << "Copying with getPixel() -> setPixel()" << TestLog::EndMessage;
@@ -1444,6 +1482,8 @@ public:
 
                m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
 
+               verifyInfoQueries();
+
                verifyRead(inputStencilAccess);
 
                m_testCtx.getLog() << TestLog::Message << "Copying with getPixel() -> setPixel()" << TestLog::EndMessage;
@@ -1482,6 +1522,8 @@ public:
 
                m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
 
+               verifyInfoQueries();
+
                verifyRead(inputDepthAccess);
                verifyRead(inputStencilAccess);