Remove duplicated texture derivative functions.
authorJarkko Pöyry <jpoyry@google.com>
Thu, 2 Jul 2015 01:45:31 +0000 (18:45 -0700)
committerJarkko Pöyry <jpoyry@google.com>
Mon, 6 Jul 2015 16:10:12 +0000 (09:10 -0700)
Change-Id: I66c4288fe92475d1463c0a97bceb6b456c4a9603

modules/gles2/functional/es2fShaderTextureFunctionTests.cpp
modules/gles3/functional/es3fShaderTextureFunctionTests.cpp
modules/glshared/glsTextureTestUtil.cpp
modules/glshared/glsTextureTestUtil.hpp

index 4f2366e..b926401 100644 (file)
@@ -24,6 +24,7 @@
 #include "es2fShaderTextureFunctionTests.hpp"
 #include "glsShaderRenderCase.hpp"
 #include "glsShaderLibrary.hpp"
+#include "glsTextureTestUtil.hpp"
 #include "gluTexture.hpp"
 #include "gluTextureUtil.hpp"
 #include "tcuTextureUtil.hpp"
@@ -181,12 +182,6 @@ using tcu::IVec2;
 using tcu::IVec3;
 using tcu::IVec4;
 
-inline float computeLodFromDerivates (float dudx, float dvdx, float dudy, float dvdy)
-{
-       float p = de::max(deFloatSqrt(dudx*dudx + dvdx*dvdx), deFloatSqrt(dudy*dudy + dvdy*dvdy));
-       return deFloatLog2(p);
-}
-
 typedef void (*TexEvalFunc) (gls::ShaderEvalContext& c, const TexLookupParams& lookupParams);
 
 inline Vec4 texture2D          (const gls::ShaderEvalContext& c, float s, float t, float lod)                  { return c.textures[0].tex2D->sample(c.textures[0].sampler, s, t, lod);                 }
@@ -356,7 +351,7 @@ void ShaderTextureFunctionCase::initTexture (void)
                        // Compute LOD.
                        float dudx = (m_lookupSpec.maxCoord[0]-m_lookupSpec.minCoord[0])*proj*(float)m_textureSpec.width        / (float)viewportSize[0];
                        float dvdy = (m_lookupSpec.maxCoord[1]-m_lookupSpec.minCoord[1])*proj*(float)m_textureSpec.height       / (float)viewportSize[1];
-                       m_lookupParams.lod = computeLodFromDerivates(dudx, 0.0f, 0.0f, dvdy);
+                       m_lookupParams.lod = gls::TextureTestUtil::computeLodFromDerivates(gls::TextureTestUtil::LODMODE_EXACT, dudx, 0.0f, 0.0f, dvdy);
 
                        // Append to texture list.
                        m_textures.push_back(gls::TextureBinding(m_texture2D, m_textureSpec.sampler));
@@ -402,7 +397,7 @@ void ShaderTextureFunctionCase::initTexture (void)
                        float                                           dudx    = (c10.s - c00.s)*(float)m_textureSpec.width    / (float)viewportSize[0];
                        float                                           dvdy    = (c01.t - c00.t)*(float)m_textureSpec.height   / (float)viewportSize[1];
 
-                       m_lookupParams.lod = computeLodFromDerivates(dudx, 0.0f, 0.0f, dvdy);
+                       m_lookupParams.lod = gls::TextureTestUtil::computeLodFromDerivates(gls::TextureTestUtil::LODMODE_EXACT, dudx, 0.0f, 0.0f, dvdy);
 
                        m_textures.push_back(gls::TextureBinding(m_textureCube, m_textureSpec.sampler));
                        break;
index b447370..c6e6735 100644 (file)
@@ -24,6 +24,7 @@
 #include "es3fShaderTextureFunctionTests.hpp"
 #include "glsShaderRenderCase.hpp"
 #include "glsShaderLibrary.hpp"
+#include "glsTextureTestUtil.hpp"
 #include "gluTexture.hpp"
 #include "gluTextureUtil.hpp"
 #include "gluPixelTransfer.hpp"
@@ -50,6 +51,8 @@ namespace Functional
 namespace
 {
 
+using gls::TextureTestUtil::computeLodFromDerivates;
+
 enum Function
 {
        FUNCTION_TEXTURE = 0,           //!< texture(), textureOffset()
@@ -237,86 +240,20 @@ using tcu::IVec2;
 using tcu::IVec3;
 using tcu::IVec4;
 
-enum LodMode
-{
-       LODMODE_EXACT = 0,
-       LODMODE_MIN_BOUND,
-       LODMODE_MAX_BOUND,
-
-       LODMODE_LAST
-};
-
-static const LodMode DEFAULT_LOD_MODE = LODMODE_EXACT;
-
-inline float computeLodFromDerivates (float dudx, float dvdx, float dudy, float dvdy)
-{
-       const LodMode   mode    = DEFAULT_LOD_MODE;
-       float                   p;
-
-       switch (mode)
-       {
-               case LODMODE_EXACT:
-                       p = de::max(deFloatSqrt(dudx*dudx + dvdx*dvdx), deFloatSqrt(dudy*dudy + dvdy*dvdy));
-                       break;
-
-               case LODMODE_MIN_BOUND:
-               case LODMODE_MAX_BOUND:
-               {
-                       float mu = de::max(deFloatAbs(dudx), deFloatAbs(dudy));
-                       float mv = de::max(deFloatAbs(dvdx), deFloatAbs(dvdy));
-
-                       p = mode == LODMODE_MIN_BOUND ? de::max(mu, mv) : mu + mv;
-                       break;
-               }
-
-               default:
-                       DE_ASSERT(DE_FALSE);
-       }
-
-       return deFloatLog2(p);
-}
-
-inline float computeLodFromDerivates (float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy)
-{
-       const LodMode   mode    = DEFAULT_LOD_MODE;
-       float                   p;
-
-       switch (mode)
-       {
-               case LODMODE_EXACT:
-                       p = de::max(deFloatSqrt(dudx*dudx + dvdx*dvdx + dwdx*dwdx), deFloatSqrt(dudy*dudy + dvdy*dvdy + dwdy*dwdy));
-                       break;
-
-               case LODMODE_MIN_BOUND:
-               case LODMODE_MAX_BOUND:
-               {
-                       float mu = de::max(deFloatAbs(dudx), deFloatAbs(dudy));
-                       float mv = de::max(deFloatAbs(dvdx), deFloatAbs(dvdy));
-                       float mw = de::max(deFloatAbs(dwdx), deFloatAbs(dwdy));
-
-                       p = mode == LODMODE_MIN_BOUND ? de::max(de::max(mu, mv), mw) : (mu + mv + mw);
-                       break;
-               }
-
-               default:
-                       DE_ASSERT(DE_FALSE);
-       }
-
-       return deFloatLog2(p);
-}
+static const gls::TextureTestUtil::LodMode DEFAULT_LOD_MODE = gls::TextureTestUtil::LODMODE_EXACT;
 
 inline float computeLodFromGrad2D (const gls::ShaderEvalContext& c)
 {
        float w = (float)c.textures[0].tex2D->getWidth();
        float h = (float)c.textures[0].tex2D->getHeight();
-       return computeLodFromDerivates(c.in[1].x()*w, c.in[1].y()*h, c.in[2].x()*w, c.in[2].y()*h);
+       return computeLodFromDerivates(DEFAULT_LOD_MODE, c.in[1].x()*w, c.in[1].y()*h, c.in[2].x()*w, c.in[2].y()*h);
 }
 
 inline float computeLodFromGrad2DArray (const gls::ShaderEvalContext& c)
 {
        float w = (float)c.textures[0].tex2DArray->getWidth();
        float h = (float)c.textures[0].tex2DArray->getHeight();
-       return computeLodFromDerivates(c.in[1].x()*w, c.in[1].y()*h, c.in[2].x()*w, c.in[2].y()*h);
+       return computeLodFromDerivates(DEFAULT_LOD_MODE, c.in[1].x()*w, c.in[1].y()*h, c.in[2].x()*w, c.in[2].y()*h);
 }
 
 inline float computeLodFromGrad3D (const gls::ShaderEvalContext& c)
@@ -324,7 +261,7 @@ inline float computeLodFromGrad3D (const gls::ShaderEvalContext& c)
        float w = (float)c.textures[0].tex3D->getWidth();
        float h = (float)c.textures[0].tex3D->getHeight();
        float d = (float)c.textures[0].tex3D->getDepth();
-       return computeLodFromDerivates(c.in[1].x()*w, c.in[1].y()*h, c.in[1].z()*d, c.in[2].x()*w, c.in[2].y()*h, c.in[2].z()*d);
+       return computeLodFromDerivates(DEFAULT_LOD_MODE, c.in[1].x()*w, c.in[1].y()*h, c.in[1].z()*d, c.in[2].x()*w, c.in[2].y()*h, c.in[2].z()*d);
 }
 
 inline float computeLodFromGradCube (const gls::ShaderEvalContext& c)
@@ -334,7 +271,7 @@ inline float computeLodFromGradCube (const gls::ShaderEvalContext& c)
        float d = (float)c.textures[0].texCube->getSize();
        float s = d/(2.0f*m);
        float t = d/(2.0f*m);
-       return computeLodFromDerivates(c.in[1].x()*s, c.in[1].y()*t, c.in[2].x()*s, c.in[2].y()*t);
+       return computeLodFromDerivates(DEFAULT_LOD_MODE, c.in[1].x()*s, c.in[1].y()*t, c.in[2].x()*s, c.in[2].y()*t);
 }
 
 typedef void (*TexEvalFunc) (gls::ShaderEvalContext& c, const TexLookupParams& lookupParams);
@@ -660,7 +597,7 @@ void ShaderTextureFunctionCase::initTexture (void)
                        // Compute LOD.
                        float dudx = (m_lookupSpec.maxCoord[0]-m_lookupSpec.minCoord[0])*proj*(float)m_textureSpec.width        / (float)viewportSize[0];
                        float dvdy = (m_lookupSpec.maxCoord[1]-m_lookupSpec.minCoord[1])*proj*(float)m_textureSpec.height       / (float)viewportSize[1];
-                       m_lookupParams.lod = computeLodFromDerivates(dudx, 0.0f, 0.0f, dvdy);
+                       m_lookupParams.lod = computeLodFromDerivates(DEFAULT_LOD_MODE, dudx, 0.0f, 0.0f, dvdy);
 
                        // Append to texture list.
                        m_textures.push_back(gls::TextureBinding(m_texture2D, m_textureSpec.sampler));
@@ -719,7 +656,7 @@ void ShaderTextureFunctionCase::initTexture (void)
                        float                                           dudx    = (c10.s - c00.s)*(float)m_textureSpec.width    / (float)viewportSize[0];
                        float                                           dvdy    = (c01.t - c00.t)*(float)m_textureSpec.height   / (float)viewportSize[1];
 
-                       m_lookupParams.lod = computeLodFromDerivates(dudx, 0.0f, 0.0f, dvdy);
+                       m_lookupParams.lod = computeLodFromDerivates(DEFAULT_LOD_MODE, dudx, 0.0f, 0.0f, dvdy);
 
                        m_textures.push_back(gls::TextureBinding(m_textureCube, m_textureSpec.sampler));
                        break;
@@ -754,7 +691,7 @@ void ShaderTextureFunctionCase::initTexture (void)
                        // Compute LOD.
                        float dudx = (m_lookupSpec.maxCoord[0]-m_lookupSpec.minCoord[0])*proj*(float)m_textureSpec.width        / (float)viewportSize[0];
                        float dvdy = (m_lookupSpec.maxCoord[1]-m_lookupSpec.minCoord[1])*proj*(float)m_textureSpec.height       / (float)viewportSize[1];
-                       m_lookupParams.lod = computeLodFromDerivates(dudx, 0.0f, 0.0f, dvdy);
+                       m_lookupParams.lod = computeLodFromDerivates(DEFAULT_LOD_MODE, dudx, 0.0f, 0.0f, dvdy);
 
                        // Append to texture list.
                        m_textures.push_back(gls::TextureBinding(m_texture2DArray, m_textureSpec.sampler));
@@ -786,7 +723,7 @@ void ShaderTextureFunctionCase::initTexture (void)
                        float dvdy = (m_lookupSpec.maxCoord[1]-m_lookupSpec.minCoord[1])*proj*(float)m_textureSpec.height               / (float)viewportSize[1];
                        float dwdx = (m_lookupSpec.maxCoord[2]-m_lookupSpec.minCoord[2])*0.5f*proj*(float)m_textureSpec.depth   / (float)viewportSize[0];
                        float dwdy = (m_lookupSpec.maxCoord[2]-m_lookupSpec.minCoord[2])*0.5f*proj*(float)m_textureSpec.depth   / (float)viewportSize[1];
-                       m_lookupParams.lod = computeLodFromDerivates(dudx, 0.0f, dwdx, 0.0f, dvdy, dwdy);
+                       m_lookupParams.lod = computeLodFromDerivates(DEFAULT_LOD_MODE, dudx, 0.0f, dwdx, 0.0f, dvdy, dwdy);
 
                        // Append to texture list.
                        m_textures.push_back(gls::TextureBinding(m_texture3D, m_textureSpec.sampler));
index ab91da9..b24dda4 100644 (file)
@@ -213,7 +213,7 @@ SurfaceAccess::SurfaceAccess (const SurfaceAccess& parent, int x, int y, int wid
 
 // 1D lookup LOD computation.
 
-inline float computeLodFromDerivates (LodMode mode, float dudx, float dudy)
+float computeLodFromDerivates (LodMode mode, float dudx, float dudy)
 {
        float p = 0.0f;
        switch (mode)
@@ -244,7 +244,7 @@ static float computeNonProjectedTriLod (LodMode mode, const tcu::IVec2& dstSize,
 
 // 2D lookup LOD computation.
 
-inline float computeLodFromDerivates (LodMode mode, float dudx, float dvdx, float dudy, float dvdy)
+float computeLodFromDerivates (LodMode mode, float dudx, float dvdx, float dudy, float dvdy)
 {
        float p = 0.0f;
        switch (mode)
@@ -284,7 +284,7 @@ static float computeNonProjectedTriLod (LodMode mode, const tcu::IVec2& dstSize,
 
 // 3D lookup LOD computation.
 
-inline float computeLodFromDerivates (LodMode mode, float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy)
+float computeLodFromDerivates (LodMode mode, float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy)
 {
        float p = 0.0f;
        switch (mode)
index a94f1ab..3a4354b 100644 (file)
@@ -357,6 +357,10 @@ void                       sampleTexture                           (const SurfaceAccess& dst, const tcu::TextureCubeArrayVi
 void                   sampleTexture                           (const SurfaceAccess& dst, const tcu::Texture1DView&            src, const float* texCoord, const ReferenceParams& params);
 void                   sampleTexture                           (const SurfaceAccess& dst, const tcu::Texture1DArrayView&       src, const float* texCoord, const ReferenceParams& params);
 
+float                  computeLodFromDerivates         (LodMode mode, float dudx, float dudy);
+float                  computeLodFromDerivates         (LodMode mode, float dudx, float dvdx, float dudy, float dvdy);
+float                  computeLodFromDerivates         (LodMode mode, float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy);
+
 void                   computeQuadTexCoord1D                   (std::vector<float>& dst, float left, float right);
 void                   computeQuadTexCoord1DArray              (std::vector<float>& dst, int layerNdx, float left, float right);
 void                   computeQuadTexCoord2D                   (std::vector<float>& dst, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);