Support not tightly packed pixel buffer accesses in tcuTextureUtil.
authorJarkko Pöyry <jpoyry@google.com>
Wed, 1 Apr 2015 22:42:35 +0000 (15:42 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Tue, 21 Apr 2015 00:24:38 +0000 (17:24 -0700)
- Fix assumptions that pixel size == pixel stride.
- Remove copyRawPixels. It was only useful for format reinterpreting
  data copies but there was not code using it for that.

Change-Id: I2743c5f197d7cf2bc4ef76e3ebe8b9dd6577c28e

framework/common/tcuCompressedTexture.cpp
framework/common/tcuTexture.hpp
framework/common/tcuTextureUtil.cpp
framework/common/tcuTextureUtil.hpp

index 0ea7f95..c911576 100644 (file)
@@ -2605,7 +2605,7 @@ void decompress (const PixelBufferAccess& dst, CompressedTexFormat fmt, const de
 
                decompressBlock(fmt, blockAccess, blockPtr, params);
 
-               copyRawPixels(getSubregion(dst, dstPixelPos.x(), dstPixelPos.y(), dstPixelPos.z(), copySize.x(), copySize.y(), copySize.z()), getSubregion(blockAccess, 0, 0, 0, copySize.x(), copySize.y(), copySize.z()));
+               copy(getSubregion(dst, dstPixelPos.x(), dstPixelPos.y(), dstPixelPos.z(), copySize.x(), copySize.y(), copySize.z()), getSubregion(blockAccess, 0, 0, 0, copySize.x(), copySize.y(), copySize.z()));
        }
 }
 
index 8b788c9..2fb0d6a 100644 (file)
@@ -289,12 +289,16 @@ public:
        int                                             getWidth                                        (void) const    { return m_size.x();                            }
        int                                             getHeight                                       (void) const    { return m_size.y();                            }
        int                                             getDepth                                        (void) const    { return m_size.z();                            }
+       int                                             getPixelPitch                           (void) const    { return m_pitch.x();                           }
        int                                             getRowPitch                                     (void) const    { return m_pitch.y();                           }
        int                                             getSlicePitch                           (void) const    { return m_pitch.z();                           }
+       const IVec3&                    getPitch                                        (void) const    { return m_pitch;                                       }
 
        const void*                             getDataPtr                                      (void) const    { return m_data;                                        }
        int                                             getDataSize                                     (void) const    { return m_size.z()*m_pitch.z();        }
 
+       const void*                             getPixelPtr                                     (int x, int y, int z = 0) const { return (const deUint8*)m_data + x * m_pitch.x() + y * m_pitch.y() + z * m_pitch.z(); }
+
        Vec4                                    getPixel                                        (int x, int y, int z = 0) const;
        IVec4                                   getPixelInt                                     (int x, int y, int z = 0) const;
        UVec4                                   getPixelUint                            (int x, int y, int z = 0) const { return getPixelInt(x, y, z).cast<deUint32>(); }
@@ -343,6 +347,7 @@ public:
                                                PixelBufferAccess       (const TextureFormat& format, const IVec3& size, const IVec3& pitch, void* data);
 
        void*                           getDataPtr                      (void) const { return m_data; }
+       void*                           getPixelPtr                     (int x, int y, int z = 0) const { return (deUint8*)m_data + x * m_pitch.x() + y * m_pitch.y() + z * m_pitch.z(); }
 
        void                            setPixels                       (const void* buf, int bufSize) const;
        void                            setPixel                        (const tcu::Vec4& color, int x, int y, int z = 0) const;
index cf5475f..e83eef8 100644 (file)
@@ -138,8 +138,8 @@ ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x
        DE_ASSERT(de::inBounds(z, 0, access.getDepth()));
        DE_ASSERT(de::inRange(z+depth, z+1, access.getDepth()));
 
-       return ConstPixelBufferAccess(access.getFormat(), width, height, depth, access.getRowPitch(), access.getSlicePitch(),
-                                                                 (const deUint8*)access.getDataPtr() + access.getFormat().getPixelSize()*x + access.getRowPitch()*y + access.getSlicePitch()*z);
+       return ConstPixelBufferAccess(access.getFormat(), tcu::IVec3(width, height, depth), access.getPitch(),
+                                                                 (const deUint8*)access.getDataPtr() + access.getPixelPitch()*x + access.getRowPitch()*y + access.getSlicePitch()*z);
 }
 
 /*--------------------------------------------------------------------*//*!
@@ -164,8 +164,8 @@ PixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, i
        DE_ASSERT(de::inBounds(z, 0, access.getDepth()));
        DE_ASSERT(de::inRange(z+depth, z+1, access.getDepth()));
 
-       return PixelBufferAccess(access.getFormat(), width, height, depth, access.getRowPitch(), access.getSlicePitch(),
-                                                        (deUint8*)access.getDataPtr() + access.getFormat().getPixelSize()*x + access.getRowPitch()*y + access.getSlicePitch()*z);
+       return PixelBufferAccess(access.getFormat(), tcu::IVec3(width, height, depth), access.getPitch(),
+                                                        (deUint8*)access.getDataPtr() + access.getPixelPitch()*x + access.getRowPitch()*y + access.getSlicePitch()*z);
 }
 
 /*--------------------------------------------------------------------*//*!
@@ -203,11 +203,11 @@ ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x
  *//*--------------------------------------------------------------------*/
 PixelBufferAccess flipYAccess (const PixelBufferAccess& access)
 {
-       const int       rowPitch                = access.getRowPitch();
-       const int       offsetToLast    = rowPitch*(access.getHeight()-1);
+       const int                       rowPitch                = access.getRowPitch();
+       const int                       offsetToLast    = rowPitch*(access.getHeight()-1);
+       const tcu::IVec3        pitch                   (access.getPixelPitch(), -rowPitch, access.getSlicePitch());
 
-       return PixelBufferAccess(access.getFormat(), access.getWidth(), access.getHeight(), access.getDepth(),
-                                                        -rowPitch, access.getSlicePitch(), (deUint8*)access.getDataPtr() + offsetToLast);
+       return PixelBufferAccess(access.getFormat(), access.getSize(), pitch, (deUint8*)access.getDataPtr() + offsetToLast);
 }
 
 /*--------------------------------------------------------------------*//*!
@@ -217,11 +217,11 @@ PixelBufferAccess flipYAccess (const PixelBufferAccess& access)
  *//*--------------------------------------------------------------------*/
 ConstPixelBufferAccess flipYAccess (const ConstPixelBufferAccess& access)
 {
-       const int       rowPitch                = access.getRowPitch();
-       const int       offsetToLast    = rowPitch*(access.getHeight()-1);
+       const int                       rowPitch                = access.getRowPitch();
+       const int                       offsetToLast    = rowPitch*(access.getHeight()-1);
+       const tcu::IVec3        pitch                   (access.getPixelPitch(), -rowPitch, access.getSlicePitch());
 
-       return ConstPixelBufferAccess(access.getFormat(), access.getWidth(), access.getHeight(), access.getDepth(),
-                                                                 -rowPitch, access.getSlicePitch(), (const deUint8*)access.getDataPtr() + offsetToLast);
+       return ConstPixelBufferAccess(access.getFormat(), access.getSize(), pitch, (deUint8*)access.getDataPtr() + offsetToLast);
 }
 
 static Vec2 getChannelValueRange (TextureFormat::ChannelType channelType)
@@ -469,9 +469,12 @@ inline void fillRow (const PixelBufferAccess& dst, int y, int z, int pixelSize,
 
 void clear (const PixelBufferAccess& access, const Vec4& color)
 {
-       int pixelSize = access.getFormat().getPixelSize();
+       const int       pixelSize                               = access.getFormat().getPixelSize();
+       const int       pixelPitch                              = access.getPixelPitch();
+       const bool      rowPixelsTightlyPacked  = (pixelSize == pixelPitch);
+
        if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD &&
-               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE)
+               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE && rowPixelsTightlyPacked)
        {
                // Convert to destination format.
                union
@@ -497,9 +500,12 @@ void clear (const PixelBufferAccess& access, const Vec4& color)
 
 void clear (const PixelBufferAccess& access, const IVec4& color)
 {
-       int pixelSize = access.getFormat().getPixelSize();
+       const int       pixelSize                               = access.getFormat().getPixelSize();
+       const int       pixelPitch                              = access.getPixelPitch();
+       const bool      rowPixelsTightlyPacked  = (pixelSize == pixelPitch);
+
        if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD &&
-               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE)
+               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE && rowPixelsTightlyPacked)
        {
                // Convert to destination format.
                union
@@ -530,9 +536,12 @@ void clear (const PixelBufferAccess& access, const UVec4& color)
 
 void clearDepth (const PixelBufferAccess& access, float depth)
 {
-       int pixelSize = access.getFormat().getPixelSize();
+       const int       pixelSize                               = access.getFormat().getPixelSize();
+       const int       pixelPitch                              = access.getPixelPitch();
+       const bool      rowPixelsTightlyPacked  = (pixelSize == pixelPitch);
+
        if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD &&
-               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE)
+               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE && rowPixelsTightlyPacked)
        {
                // Convert to destination format.
                union
@@ -558,9 +567,12 @@ void clearDepth (const PixelBufferAccess& access, float depth)
 
 void clearStencil (const PixelBufferAccess& access, int stencil)
 {
-       int pixelSize = access.getFormat().getPixelSize();
+       const int       pixelSize                               = access.getFormat().getPixelSize();
+       const int       pixelPitch                              = access.getPixelPitch();
+       const bool      rowPixelsTightlyPacked  = (pixelSize == pixelPitch);
+
        if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD &&
-               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE)
+               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE && rowPixelsTightlyPacked)
        {
                // Convert to destination format.
                union
@@ -779,22 +791,33 @@ void fillWithMetaballs (const PixelBufferAccess& dst, int numBalls, deUint32 see
 
 void copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src)
 {
-       int             width           = dst.getWidth();
-       int             height          = dst.getHeight();
-       int             depth           = dst.getDepth();
+       DE_ASSERT(src.getSize() == dst.getSize());
+
+       const int       width                           = dst.getWidth();
+       const int       height                          = dst.getHeight();
+       const int       depth                           = dst.getDepth();
 
-       DE_ASSERT(src.getWidth() == width && src.getHeight() == height && src.getDepth() == depth);
+       const int       srcPixelSize            = src.getFormat().getPixelSize();
+       const int       dstPixelSize            = dst.getFormat().getPixelSize();
+       const int       srcPixelPitch           = src.getPixelPitch();
+       const int       dstPixelPitch           = dst.getPixelPitch();
+       const bool      srcTightlyPacked        = (srcPixelSize == srcPixelPitch);
+       const bool      dstTightlyPacked        = (dstPixelSize == dstPixelPitch);
 
-       if (src.getFormat() == dst.getFormat())
+       if (src.getFormat() == dst.getFormat() && srcTightlyPacked && dstTightlyPacked)
        {
                // Fast-path for matching formats.
-               int pixelSize = src.getFormat().getPixelSize();
-
                for (int z = 0; z < depth; z++)
                for (int y = 0; y < height; y++)
-                       deMemcpy((deUint8*)dst.getDataPtr()                     + z*dst.getSlicePitch() + y*dst.getRowPitch(),
-                                        (const deUint8*)src.getDataPtr()       + z*src.getSlicePitch() + y*src.getRowPitch(),
-                                        pixelSize*width);
+                       deMemcpy(dst.getPixelPtr(0, y, z), src.getPixelPtr(0, y, z), srcPixelSize*width);
+       }
+       else if (src.getFormat() == dst.getFormat())
+       {
+               // Bit-exact copy for matching formats.
+               for (int z = 0; z < depth; z++)
+               for (int y = 0; y < height; y++)
+               for (int x = 0; x < width; x++)
+                       deMemcpy(dst.getPixelPtr(x, y, z), src.getPixelPtr(x, y, z), srcPixelSize);
        }
        else
        {
@@ -935,30 +958,6 @@ int getCubeArrayFaceIndex (CubeFace face)
        }
 }
 
-void copyRawPixels (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src)
-{
-       DE_ASSERT(dst.getFormat().getPixelSize() == src.getFormat().getPixelSize());
-       DE_ASSERT(dst.getWidth() == src.getWidth());
-       DE_ASSERT(dst.getHeight() == src.getHeight());
-       DE_ASSERT(dst.getDepth() == src.getDepth());
-
-       const int pixelSize = dst.getFormat().getPixelSize();
-
-       for (int z = 0; z < dst.getDepth(); z++)
-       for (int y = 0; y < dst.getHeight(); y++)
-       {
-               const deUint8* const    srcPtr  = (const deUint8*)src.getDataPtr()
-                                                                               + src.getRowPitch() * y
-                                                                               + src.getSlicePitch() * z;
-
-               deUint8* const                  dstPtr  = (deUint8*)dst.getDataPtr()
-                                                                               + dst.getRowPitch() * y
-                                                                               + dst.getSlicePitch() * z;
-
-               deMemcpy(dstPtr, srcPtr, dst.getWidth() * pixelSize);
-       }
-}
-
 deUint32 packRGB999E5 (const tcu::Vec4& color)
 {
        const int       mBits   = 9;
index 643a567..db9fec9 100644 (file)
@@ -95,11 +95,10 @@ void        fillWithRepeatableGradient              (const PixelBufferAccess& access, const Vec4& c
 void   fillWithMetaballs                               (const PixelBufferAccess& access, int numMetaballs, deUint32 seed);
 void   fillWithRGBAQuads                               (const PixelBufferAccess& access);
 
+//! Copies contents of src to dst. If formats of dst and src are equal, a bit-exact copy is made.
 void   copy                                                    (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src);
-void   scale                                                   (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter);
 
-// Copy raw pixel data between buffers. Both buffers must have same pixel size.
-void   copyRawPixels                                   (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src);
+void   scale                                                   (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter);
 
 void   estimatePixelValueRange                 (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal);
 void   computePixelScaleBias                   (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias);