Implement tcu::clear{Depth|Stencil} using tcu::clear.
authorJarkko Pöyry <jpoyry@google.com>
Tue, 21 Apr 2015 02:05:26 +0000 (19:05 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Tue, 21 Apr 2015 20:26:54 +0000 (13:26 -0700)
- Remove duplicated code in clear*.
- Add fillRow() sanity checks.

Change-Id: I81dc8be98c38691ad95fc0cfc659d6a75a24fde8

framework/common/tcuTextureUtil.cpp

index a959ee2..8ca4d87 100644 (file)
@@ -458,10 +458,12 @@ enum
 
 inline void fillRow (const PixelBufferAccess& dst, int y, int z, int pixelSize, const deUint8* pixel)
 {
-       deUint8*        dstPtr  = (deUint8*)dst.getDataPtr() + z*dst.getSlicePitch() + y*dst.getRowPitch();
+       DE_ASSERT(dst.getPixelPitch() == pixelSize); // only tightly packed
+
+       deUint8*        dstPtr  = (deUint8*)dst.getPixelPtr(0, y, z);
        int                     width   = dst.getWidth();
 
-       if (pixelSize == 8 && deIsAlignedPtr(dstPtr, pixelSize) && deIsAlignedPtr(dstPtr, pixelSize))
+       if (pixelSize == 8 && deIsAlignedPtr(dstPtr, pixelSize))
        {
                deUint64 val;
                memcpy(&val, pixel, sizeof(val));
@@ -469,7 +471,7 @@ inline void fillRow (const PixelBufferAccess& dst, int y, int z, int pixelSize,
                for (int i = 0; i < width; i++)
                        ((deUint64*)dstPtr)[i] = val;
        }
-       else if (pixelSize == 4 && deIsAlignedPtr(dstPtr, pixelSize) && deIsAlignedPtr(dstPtr, pixelSize))
+       else if (pixelSize == 4 && deIsAlignedPtr(dstPtr, pixelSize))
        {
                deUint32 val;
                memcpy(&val, pixel, sizeof(val));
@@ -554,64 +556,16 @@ void clear (const PixelBufferAccess& access, const UVec4& color)
 
 void clearDepth (const PixelBufferAccess& access, float depth)
 {
-       const int       pixelSize                               = access.getFormat().getPixelSize();
-       const int       pixelPitch                              = access.getPixelPitch();
-       const bool      rowPixelsTightlyPacked  = (pixelSize == pixelPitch);
+       DE_ASSERT(access.getFormat().order == TextureFormat::DS || access.getFormat().order == TextureFormat::D);
 
-       if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD &&
-               pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE && rowPixelsTightlyPacked)
-       {
-               // Convert to destination format.
-               union
-               {
-                       deUint8         u8[CLEAR_OPTIMIZE_MAX_PIXEL_SIZE];
-                       deUint64        u64; // Forces 64-bit alignment.
-               } pixel;
-               DE_STATIC_ASSERT(sizeof(pixel) == CLEAR_OPTIMIZE_MAX_PIXEL_SIZE);
-               PixelBufferAccess(access.getFormat(), 1, 1, 1, 0, 0, &pixel.u8[0]).setPixDepth(depth, 0, 0);
-
-               for (int z = 0; z < access.getDepth(); z++)
-                       for (int y = 0; y < access.getHeight(); y++)
-                               fillRow(access, y, z, pixelSize, &pixel.u8[0]);
-       }
-       else
-       {
-               for (int z = 0; z < access.getDepth(); z++)
-                       for (int y = 0; y < access.getHeight(); y++)
-                               for (int x = 0; x < access.getWidth(); x++)
-                                       access.setPixDepth(depth, x, y, z);
-       }
+       clear(getEffectiveDepthStencilAccess(access, Sampler::MODE_DEPTH), tcu::Vec4(depth, 0.0f, 0.0f, 0.0f));
 }
 
 void clearStencil (const PixelBufferAccess& access, int stencil)
 {
-       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 && rowPixelsTightlyPacked)
-       {
-               // Convert to destination format.
-               union
-               {
-                       deUint8         u8[CLEAR_OPTIMIZE_MAX_PIXEL_SIZE];
-                       deUint64        u64; // Forces 64-bit alignment.
-               } pixel;
-               DE_STATIC_ASSERT(sizeof(pixel) == CLEAR_OPTIMIZE_MAX_PIXEL_SIZE);
-               PixelBufferAccess(access.getFormat(), 1, 1, 1, 0, 0, &pixel.u8[0]).setPixStencil(stencil, 0, 0);
+       DE_ASSERT(access.getFormat().order == TextureFormat::DS || access.getFormat().order == TextureFormat::S);
 
-               for (int z = 0; z < access.getDepth(); z++)
-                       for (int y = 0; y < access.getHeight(); y++)
-                               fillRow(access, y, z, pixelSize, &pixel.u8[0]);
-       }
-       else
-       {
-               for (int z = 0; z < access.getDepth(); z++)
-                       for (int y = 0; y < access.getHeight(); y++)
-                               for (int x = 0; x < access.getWidth(); x++)
-                                       access.setPixStencil(stencil, x, y, z);
-       }
+       clear(getEffectiveDepthStencilAccess(access, Sampler::MODE_STENCIL), tcu::UVec4(stencil, 0u, 0u, 0u));
 }
 
 static void fillWithComponentGradients1D (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal)