Handle stencil textures as one-channel int textures.
authorJarkko Pöyry <jpoyry@google.com>
Wed, 1 Apr 2015 19:30:42 +0000 (12:30 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Fri, 24 Apr 2015 02:14:19 +0000 (19:14 -0700)
- Make sampling from stencil texture return stencil value in R channel.
  This makes stencil textures behave as in GL.
- Fix tests assuming component w is always stencil.

Change-Id: Ibc12949435330e0ac52a469b2fe8f3eab57d9e67

framework/common/tcuTexture.cpp
framework/common/tcuTextureUtil.hpp
modules/gles2/functional/es2fDepthStencilClearTests.cpp
modules/gles3/functional/es3fDepthStencilClearTests.cpp
modules/gles31/functional/es31fStencilTexturingTests.cpp

index a2d0f456dfc0760782f746df48ddb84fc61e2555..eafb5c1939ab158f0cc34abfd279efa5077fcbc9 100644 (file)
@@ -404,7 +404,7 @@ const TextureSwizzle& getChannelReadSwizzle (TextureFormat::ChannelOrder order)
        static const TextureSwizzle BGRA        = {{ TextureSwizzle::CHANNEL_2,         TextureSwizzle::CHANNEL_1,              TextureSwizzle::CHANNEL_0,              TextureSwizzle::CHANNEL_3       }};
        static const TextureSwizzle ARGB        = {{ TextureSwizzle::CHANNEL_1,         TextureSwizzle::CHANNEL_2,              TextureSwizzle::CHANNEL_3,              TextureSwizzle::CHANNEL_0       }};
        static const TextureSwizzle D           = {{ TextureSwizzle::CHANNEL_0,         TextureSwizzle::CHANNEL_ZERO,   TextureSwizzle::CHANNEL_ZERO,   TextureSwizzle::CHANNEL_ONE     }};
-       static const TextureSwizzle S           = {{ TextureSwizzle::CHANNEL_ZERO,      TextureSwizzle::CHANNEL_ZERO,   TextureSwizzle::CHANNEL_ZERO,   TextureSwizzle::CHANNEL_0       }};
+       static const TextureSwizzle S           = {{ TextureSwizzle::CHANNEL_0,         TextureSwizzle::CHANNEL_ZERO,   TextureSwizzle::CHANNEL_ZERO,   TextureSwizzle::CHANNEL_ONE     }};
        static const TextureSwizzle DS          = {{ TextureSwizzle::CHANNEL_0,         TextureSwizzle::CHANNEL_ZERO,   TextureSwizzle::CHANNEL_ZERO,   TextureSwizzle::CHANNEL_1       }};
 
        switch (order)
@@ -451,7 +451,7 @@ const TextureSwizzle& getChannelWriteSwizzle (TextureFormat::ChannelOrder order)
        static const TextureSwizzle BGRA        = {{ TextureSwizzle::CHANNEL_2,         TextureSwizzle::CHANNEL_1,              TextureSwizzle::CHANNEL_0,              TextureSwizzle::CHANNEL_3               }};
        static const TextureSwizzle ARGB        = {{ TextureSwizzle::CHANNEL_3,         TextureSwizzle::CHANNEL_0,              TextureSwizzle::CHANNEL_1,              TextureSwizzle::CHANNEL_2               }};
        static const TextureSwizzle D           = {{ TextureSwizzle::CHANNEL_0,         TextureSwizzle::CHANNEL_LAST,   TextureSwizzle::CHANNEL_LAST,   TextureSwizzle::CHANNEL_LAST    }};
-       static const TextureSwizzle S           = {{ TextureSwizzle::CHANNEL_3,         TextureSwizzle::CHANNEL_LAST,   TextureSwizzle::CHANNEL_LAST,   TextureSwizzle::CHANNEL_LAST    }};
+       static const TextureSwizzle S           = {{ TextureSwizzle::CHANNEL_0,         TextureSwizzle::CHANNEL_LAST,   TextureSwizzle::CHANNEL_LAST,   TextureSwizzle::CHANNEL_LAST    }};
        static const TextureSwizzle DS          = {{ TextureSwizzle::CHANNEL_0,         TextureSwizzle::CHANNEL_3,              TextureSwizzle::CHANNEL_LAST,   TextureSwizzle::CHANNEL_LAST    }};
 
        switch (order)
index b5989d0d1e382acbc6656e687964eeec712b766d..6df944593025eb83cee304a87e5a7a54bd7d1675 100644 (file)
@@ -39,11 +39,12 @@ ConstPixelBufferAccess      getSubregion                            (const ConstPixelBufferAccess& access, in
 PixelBufferAccess              flipYAccess                                     (const PixelBufferAccess& access);
 ConstPixelBufferAccess flipYAccess                                     (const ConstPixelBufferAccess& access);
 
+bool                                   isCombinedDepthStencilType      (TextureFormat::ChannelType type);
+
 // sRGB - linear conversion.
 Vec4                                   sRGBToLinear                            (const Vec4& cs);
 Vec4                                   linearToSRGB                            (const Vec4& cl);
 bool                                   isSRGB                                          (TextureFormat format);
-bool                                   isCombinedDepthStencilType      (TextureFormat::ChannelType type);
 
 /*--------------------------------------------------------------------*//*!
  * \brief Color channel storage type
index 030a062d2c2887fae4b90003b87bb393e7ce1973..f1671dd0b395ed1c6856df9746d813909ea8138e 100644 (file)
@@ -428,13 +428,13 @@ void DepthStencilClearCase::renderReference (tcu::Surface& dst, const vector<Cle
                                        continue;
 
                                for (int x = clearRect.x(); x < clearRect.x()+clearRect.z(); x++)
-                                       rowAccess.setPixel(Vec4(de::clamp(clear->clearDepth, 0.0f, 1.0f)), x, 0);
+                                       rowAccess.setPixDepth(de::clamp(clear->clearDepth, 0.0f, 1.0f), x, 0);
                        }
 
                        // Map to colors.
                        for (int x = 0; x < dst.getWidth(); x++)
                        {
-                               float           depth           = rowAccess.getPixel(x, 0).x();
+                               float           depth           = rowAccess.getPixDepth(x, 0);
                                float           step            = deFloatFloor(depth * (float)DEPTH_STEPS) / (float)(DEPTH_STEPS-1);
                                tcu::RGBA       oldColor        = dst.getPixel(x, y);
                                tcu::RGBA       newColor        = tcu::RGBA(oldColor.getRed(), oldColor.getGreen(), deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255), oldColor.getAlpha());
@@ -473,16 +473,16 @@ void DepthStencilClearCase::renderReference (tcu::Surface& dst, const vector<Cle
 
                                for (int x = clearRect.x(); x < clearRect.x()+clearRect.z(); x++)
                                {
-                                       deUint32        oldVal  = rowAccess.getPixelUint(x, 0).w();
+                                       deUint32        oldVal  = rowAccess.getPixStencil(x, 0);
                                        deUint32        newVal  = ((oldVal & ~clear->stencilMask) | (clear->clearStencil & clear->stencilMask)) & bufMask;
-                                       rowAccess.setPixel(tcu::UVec4(newVal), x, 0);
+                                       rowAccess.setPixStencil(newVal, x, 0);
                                }
                        }
 
                        // Map to colors.
                        for (int x = 0; x < dst.getWidth(); x++)
                        {
-                               deUint32        stencil         = rowAccess.getPixelUint(x, 0).w();
+                               deUint32        stencil         = rowAccess.getPixStencil(x, 0);
                                float           step            = (float)(stencil / ((1u<<stencilBits) / (deUint32)STENCIL_STEPS)) / (float)(STENCIL_STEPS-1);
                                tcu::RGBA       oldColor        = dst.getPixel(x, y);
                                tcu::RGBA       newColor        = tcu::RGBA(oldColor.getRed(), deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255), oldColor.getBlue(), oldColor.getAlpha());
index a7b773d36b750fb8d349863d84291805fd23ca59..112757bad69270e3f73700cf5e8741058a620497 100644 (file)
@@ -431,13 +431,13 @@ void DepthStencilClearCase::renderReference (tcu::Surface& dst, const vector<Cle
                                        continue;
 
                                for (int x = clearRect.x(); x < clearRect.x()+clearRect.z(); x++)
-                                       rowAccess.setPixel(Vec4(de::clamp(clear->clearDepth, 0.0f, 1.0f)), x, 0);
+                                       rowAccess.setPixDepth(de::clamp(clear->clearDepth, 0.0f, 1.0f), x, 0);
                        }
 
                        // Map to colors.
                        for (int x = 0; x < dst.getWidth(); x++)
                        {
-                               float           depth           = rowAccess.getPixel(x, 0).x();
+                               float           depth           = rowAccess.getPixDepth(x, 0);
                                float           step            = deFloatFloor(depth * (float)DEPTH_STEPS) / (float)(DEPTH_STEPS-1);
                                tcu::RGBA       oldColor        = dst.getPixel(x, y);
                                tcu::RGBA       newColor        = tcu::RGBA(oldColor.getRed(), oldColor.getGreen(), deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255), oldColor.getAlpha());
@@ -476,16 +476,16 @@ void DepthStencilClearCase::renderReference (tcu::Surface& dst, const vector<Cle
 
                                for (int x = clearRect.x(); x < clearRect.x()+clearRect.z(); x++)
                                {
-                                       deUint32        oldVal  = rowAccess.getPixelUint(x, 0).w();
+                                       deUint32        oldVal  = rowAccess.getPixStencil(x, 0);
                                        deUint32        newVal  = ((oldVal & ~clear->stencilMask) | (clear->clearStencil & clear->stencilMask)) & bufMask;
-                                       rowAccess.setPixel(tcu::UVec4(newVal), x, 0);
+                                       rowAccess.setPixStencil(newVal, x, 0);
                                }
                        }
 
                        // Map to colors.
                        for (int x = 0; x < dst.getWidth(); x++)
                        {
-                               deUint32        stencil         = rowAccess.getPixelUint(x, 0).w();
+                               deUint32        stencil         = rowAccess.getPixStencil(x, 0);
                                float           step            = (float)(stencil / ((1u<<stencilBits) / (deUint32)STENCIL_STEPS)) / (float)(STENCIL_STEPS-1);
                                tcu::RGBA       oldColor        = dst.getPixel(x, y);
                                tcu::RGBA       newColor        = tcu::RGBA(oldColor.getRed(), deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255), oldColor.getBlue(), oldColor.getAlpha());
index 83b232646916fd13804e81a4ce25007b9dfaae75..11339926e7268a8f93d359d46cc8ed62b2ce3ce2 100644 (file)
@@ -163,12 +163,13 @@ static void drawTestPattern (const glu::RenderContext& renderCtx, int width, int
 
 static void renderTestPatternReference (const tcu::PixelBufferAccess& dst)
 {
-       const int               stencilBits             = tcu::getTextureFormatBitDepth(dst.getFormat()).w();
+       const int               stencilBits             = tcu::getTextureFormatBitDepth(tcu::getEffectiveDepthStencilAccess(dst, tcu::Sampler::MODE_STENCIL).getFormat()).x();
        const deUint32  stencilMask             = (1u<<stencilBits)-1u;
        vector<IVec4>   rects;
 
        DE_ASSERT(dst.getFormat().order == TextureFormat::S || dst.getFormat().order == TextureFormat::DS);
 
+       // clear depth and stencil
        tcu::clear(dst, IVec4(0));
 
        genTestRects(rects, dst.getWidth(), dst.getHeight());
@@ -385,8 +386,7 @@ static void blitStencilToColorCube (const glu::RenderContext& renderCtx, deUint3
 static inline tcu::ConstPixelBufferAccess stencilToRedAccess (const tcu::ConstPixelBufferAccess& access)
 {
        DE_ASSERT(access.getFormat() == TextureFormat(TextureFormat::S, TextureFormat::UNSIGNED_INT8));
-       return tcu::ConstPixelBufferAccess(TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT8),
-                                                                          access.getWidth(), access.getHeight(), access.getDepth(), access.getRowPitch(), access.getSlicePitch(), access.getDataPtr());
+       return tcu::ConstPixelBufferAccess(TextureFormat(TextureFormat::R, TextureFormat::UNSIGNED_INT8), access.getSize(), access.getPitch(), access.getDataPtr());
 }
 
 static bool compareStencilToRed (tcu::TestLog& log, const tcu::ConstPixelBufferAccess& stencilRef, const tcu::ConstPixelBufferAccess& result)
@@ -595,7 +595,7 @@ public:
                        if (levelNdx == ptrnLevel)
                                renderTestPatternReference(levelAccess);
                        else
-                               tcu::clear(levelAccess, IVec4(0, 0, 0, levelNdx));
+                               tcu::clearStencil(levelAccess, levelNdx);
                }
 
                gl.bindTexture(GL_TEXTURE_2D_ARRAY, *depthStencilTex);
@@ -681,7 +681,7 @@ public:
                        const int                               stencilVal      = 42*faceNdx;
 
                        texData.allocLevel(face, 0);
-                       tcu::clear(texData.getLevelFace(0, face), IVec4(0, 0, 0, stencilVal));
+                       tcu::clearStencil(texData.getLevelFace(0, face), stencilVal);
                }
 
                gls::TextureTestUtil::computeQuadTexCoordCube(texCoord, tcu::CUBEFACE_NEGATIVE_X, Vec2(-1.5f, -1.3f), Vec2(1.3f, 1.4f));
@@ -845,7 +845,7 @@ public:
                                gl.scissor(x, y, clearW, clearH);
                                gl.clear(GL_STENCIL_BUFFER_BIT);
 
-                               tcu::clear(tcu::getSubregion(reference.getAccess(), x, y, clearW, clearH), IVec4(0, 0, 0, stencil));
+                               tcu::clearStencil(tcu::getSubregion(reference.getAccess(), x, y, clearW, clearH), stencil);
                        }
                }