Commit 72fc5547 by Olli Etuaho Committed by Commit Bot

Add a ShaderCompileTreeTest base class to use in compiler tests

The test class provides facilities for parsing test shader source into an AST and determining compile status. Compilation flags change for some of the tests, but this should only have a minor effect on code coverage - mostly affecting non-core parts such as intermediate output. BUG=angleproject:1673 TEST=angle_unittests Change-Id: I7d0900ef490e021272a27c4b0c938bfee02abf39 Reviewed-on: https://chromium-review.googlesource.com/422367Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent fc5aef40
......@@ -96,6 +96,8 @@
'<(angle_path)/src/tests/test_utils/compiler_test.h',
'<(angle_path)/src/tests/test_utils/ConstantFoldingTest.h',
'<(angle_path)/src/tests/test_utils/ConstantFoldingTest.cpp',
'<(angle_path)/src/tests/test_utils/ShaderCompileTreeTest.h',
'<(angle_path)/src/tests/test_utils/ShaderCompileTreeTest.cpp',
],
# TODO(jmadill): should probably call this windows sources
'angle_unittests_hlsl_sources':
......
......@@ -32,7 +32,7 @@ TEST_F(ConstantFoldingTest, FoldIntegerAdd)
" const int i = 1124 + 5;\n"
" my_Int = i;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_FALSE(constantFoundInAST(1124));
ASSERT_FALSE(constantFoundInAST(5));
ASSERT_TRUE(constantFoundInAST(1129));
......@@ -48,7 +48,7 @@ TEST_F(ConstantFoldingTest, FoldIntegerSub)
" const int i = 1124 - 5;\n"
" my_Int = i;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_FALSE(constantFoundInAST(1124));
ASSERT_FALSE(constantFoundInAST(5));
ASSERT_TRUE(constantFoundInAST(1119));
......@@ -64,7 +64,7 @@ TEST_F(ConstantFoldingTest, FoldIntegerMul)
" const int i = 1124 * 5;\n"
" my_Int = i;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_FALSE(constantFoundInAST(1124));
ASSERT_FALSE(constantFoundInAST(5));
ASSERT_TRUE(constantFoundInAST(5620));
......@@ -80,7 +80,7 @@ TEST_F(ConstantFoldingTest, FoldIntegerDiv)
" const int i = 1124 / 5;\n"
" my_Int = i;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_FALSE(constantFoundInAST(1124));
ASSERT_FALSE(constantFoundInAST(5));
// Rounding mode of division is undefined in the spec but ANGLE can be expected to round down.
......@@ -97,7 +97,7 @@ TEST_F(ConstantFoldingTest, FoldIntegerModulus)
" const int i = 1124 % 5;\n"
" my_Int = i;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_FALSE(constantFoundInAST(1124));
ASSERT_FALSE(constantFoundInAST(5));
ASSERT_TRUE(constantFoundInAST(4));
......@@ -113,7 +113,7 @@ TEST_F(ConstantFoldingTest, FoldVectorCrossProduct)
" const vec3 v3 = cross(vec3(1.0f, 1.0f, 1.0f), vec3(1.0f, -1.0f, 1.0f));\n"
" my_Vec3 = v3;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
std::vector<float> input1(3, 1.0f);
ASSERT_FALSE(constantVectorFoundInAST(input1));
std::vector<float> input2;
......@@ -145,7 +145,7 @@ TEST_F(ConstantFoldingTest, Fold2x2MatrixInverse)
" mat2 m = m2 * mat2(i);\n"
" my_Vec = m[0];\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float inputElements[] =
{
2.0f, 3.0f,
......@@ -177,7 +177,7 @@ TEST_F(ConstantFoldingTest, Fold3x3MatrixInverse)
" mat3 m = m3 * mat3(i);\n"
" my_Vec = m3[0];\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float inputElements[] =
{
11.0f, 13.0f, 19.0f,
......@@ -213,7 +213,7 @@ TEST_F(ConstantFoldingTest, Fold4x4MatrixInverse)
" mat4 m = m4 * mat4(i);\n"
" my_Vec = m[0];\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float inputElements[] =
{
29.0f, 31.0f, 37.0f, 41.0f,
......@@ -250,7 +250,7 @@ TEST_F(ConstantFoldingTest, Fold2x2MatrixDeterminant)
" 5.0f, 7.0f));\n"
" my_Float = f;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float inputElements[] =
{
2.0f, 3.0f,
......@@ -274,7 +274,7 @@ TEST_F(ConstantFoldingTest, Fold3x3MatrixDeterminant)
" 37.0f, 41.0f, 43.0f));\n"
" my_Float = f;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float inputElements[] =
{
11.0f, 13.0f, 19.0f,
......@@ -300,7 +300,7 @@ TEST_F(ConstantFoldingTest, Fold4x4MatrixDeterminant)
" 79.0f, 83.0f, 89.0f, 97.0f));\n"
" my_Float = f;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float inputElements[] =
{
29.0f, 31.0f, 37.0f, 41.0f,
......@@ -329,7 +329,7 @@ TEST_F(ConstantFoldingTest, Fold3x3MatrixTranspose)
" mat3 m = m3 * mat3(i);\n"
" my_Vec = m[0];\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float inputElements[] =
{
11.0f, 13.0f, 19.0f,
......@@ -363,7 +363,7 @@ TEST_F(ConstantFoldingTest, ParseWrappedHexIntLiteral)
" const int i = 0xFFFFFFFF;\n"
" my_Vec = vec4(i * inInt);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(-1));
}
......@@ -382,7 +382,7 @@ TEST_F(ConstantFoldingTest, ParseWrappedDecimalIntLiteral)
" const int i = 3000000000;\n"
" my_Vec = vec4(i * inInt);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(-1294967296));
}
......@@ -401,7 +401,7 @@ TEST_F(ConstantFoldingTest, ParseMaxUintLiteral)
" const uint i = 0xFFFFFFFFu;\n"
" my_Vec = vec4(i * inInt);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0xFFFFFFFFu));
}
......@@ -420,7 +420,7 @@ TEST_F(ConstantFoldingTest, FoldUnaryMinusOnUintLiteral)
" const uint i = -1u;\n"
" my_Vec = vec4(i * inInt);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0xFFFFFFFFu));
}
......@@ -435,7 +435,7 @@ TEST_F(ConstantFoldingTest, FoldMat2ConstructorTakingMat2)
" mat2 m = cm * mult;\n"
" gl_FragColor = vec4(m[0], m[1]);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float outputElements[] =
{
0.0f, 1.0f,
......@@ -456,7 +456,7 @@ TEST_F(ConstantFoldingTest, FoldMat2ConstructorTakingScalar)
" mat2 m = cm * mult;\n"
" gl_FragColor = vec4(m[0], m[1]);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float outputElements[] =
{
3.0f, 0.0f,
......@@ -477,7 +477,7 @@ TEST_F(ConstantFoldingTest, FoldMat2ConstructorTakingMix)
" mat2 m = cm * mult;\n"
" gl_FragColor = vec4(m[0], m[1]);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float outputElements[] =
{
-1.0, 0.0f,
......@@ -498,7 +498,7 @@ TEST_F(ConstantFoldingTest, FoldMat2ConstructorTakingMat3)
" mat2 m = cm * mult;\n"
" gl_FragColor = vec4(m[0], m[1]);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float outputElements[] =
{
0.0f, 1.0f,
......@@ -523,7 +523,7 @@ TEST_F(ConstantFoldingTest, FoldMat4x3ConstructorTakingMat3x2)
" mat4x3 m = cm * mult;\n"
" my_FragColor = vec4(m[0], m[1][0]);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float outputElements[] =
{
1.0f, 2.0f, 0.0f,
......@@ -547,7 +547,7 @@ TEST_F(ConstantFoldingTest, FoldMat2ConstructorTakingVec4)
" mat2 m = cm * mult;\n"
" gl_FragColor = vec4(m[0], m[1]);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float outputElements[] =
{
0.0f, 1.0f,
......@@ -576,7 +576,7 @@ TEST_F(ConstantFoldingTest, FoldNestedDifferentStructEqualityComparison)
" const S s2 = S(nested(0.0), 3.0);\n"
" gl_FragColor = (s1 == s2 ? 1.0 : 0.5) * mult;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0.5f));
}
......@@ -600,7 +600,7 @@ TEST_F(ConstantFoldingTest, FoldNestedIdenticalStructEqualityComparison)
" const S s2 = S(nested(0.0), 2.0, 3);\n"
" gl_FragColor = (s1 == s2 ? 1.0 : 0.5) * mult;\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(1.0f));
}
......@@ -615,7 +615,7 @@ TEST_F(ConstantFoldingTest, FoldNonSquareMatrixIndexing)
"{\n"
" my_FragColor = mat3x4(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)[1];\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
float outputElements[] = {4.0f, 5.0f, 6.0f, 7.0f};
std::vector<float> result(outputElements, outputElements + 4);
ASSERT_TRUE(constantVectorFoundInAST(result));
......@@ -633,7 +633,7 @@ TEST_F(ConstantFoldingTest, FoldNonSquareOuterProduct)
" mat3x2 prod = outerProduct(vec2(2.0, 3.0), vec3(5.0, 7.0, 11.0));\n"
" my_FragColor = vec4(prod[0].x);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
// clang-format off
float outputElements[] =
{
......@@ -658,7 +658,7 @@ TEST_F(ConstantFoldingTest, FoldBitShiftLeftDifferentSignedness)
" uint u = 0xffffffffu << 31;\n"
" my_FragColor = vec4(u);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0x80000000u));
}
......@@ -674,7 +674,7 @@ TEST_F(ConstantFoldingTest, FoldBitShiftRightDifferentSignedness)
" uint u = 0xffffffffu >> 30;\n"
" my_FragColor = vec4(u);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0x3u));
}
......@@ -692,7 +692,7 @@ TEST_F(ConstantFoldingTest, FoldBitShiftRightExtendSignBit)
" uint u = uint(i);"
" my_FragColor = vec4(u);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
// The bits of the operand are 0x8fffe000 = 1000 1111 1111 1111 1110 0000 0000 0000
// After shifting, they become 1111 1110 0011 1111 1111 1111 1000 0000 = 0xfe3fff80
ASSERT_TRUE(constantFoundInAST(0xfe3fff80u));
......@@ -713,7 +713,7 @@ TEST_F(ConstantFoldingTest, FoldBitShiftLeftInterpretedAsBitPattern)
" uint u = uint(i);"
" my_FragColor = vec4(u);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0xfffffff8u));
}
......@@ -732,7 +732,7 @@ TEST_F(ConstantFoldingTest, FoldDivideMinimumIntegerByMinusOne)
" int i = 0x80000000 / (-1);\n"
" my_FragColor = vec4(i);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0x7fffffff) || constantFoundInAST(-0x7fffffff - 1));
}
......@@ -752,7 +752,7 @@ TEST_F(ConstantFoldingTest, FoldUnsignedIntegerAddOverflow)
" uint u = 0xffffffffu + 43u;\n"
" my_FragColor = vec4(u);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(42u));
}
......@@ -772,7 +772,7 @@ TEST_F(ConstantFoldingTest, FoldSignedIntegerAddOverflow)
" int i = 0x7fffffff + 4;\n"
" my_FragColor = vec4(i);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(-0x7ffffffd));
}
......@@ -792,7 +792,7 @@ TEST_F(ConstantFoldingTest, FoldUnsignedIntegerDiffOverflow)
" uint u = 0u - 5u;\n"
" my_FragColor = vec4(u);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0xfffffffbu));
}
......@@ -812,7 +812,7 @@ TEST_F(ConstantFoldingTest, FoldSignedIntegerDiffOverflow)
" int i = -0x7fffffff - 7;\n"
" my_FragColor = vec4(i);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0x7ffffffa));
}
......@@ -832,7 +832,7 @@ TEST_F(ConstantFoldingTest, FoldUnsignedIntegerMultiplyOverflow)
" uint u = 0xffffffffu * 10u;\n"
" my_FragColor = vec4(u);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(0xfffffff6u));
}
......@@ -852,7 +852,7 @@ TEST_F(ConstantFoldingTest, FoldSignedIntegerMultiplyOverflow)
" int i = 0x7fffffff * 42;\n"
" my_FragColor = vec4(i);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(-42));
}
......@@ -873,7 +873,7 @@ TEST_F(ConstantFoldingTest, FoldMinimumSignedIntegerNegation)
" int i = -0x80000000;\n"
" my_FragColor = vec4(i);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
// Negating the minimum signed integer overflows the positive range, so it wraps back to itself.
ASSERT_TRUE(constantFoundInAST(-0x7fffffff - 1));
}
......@@ -891,7 +891,7 @@ TEST_F(ConstantFoldingTest, FoldMinimumSignedIntegerRightShift)
" int j = (0x80000000 >> 7);\n"
" my_FragColor = vec4(i, j, i, j);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(-0x40000000));
ASSERT_TRUE(constantFoundInAST(-0x01000000));
}
......@@ -909,7 +909,7 @@ TEST_F(ConstantFoldingTest, FoldShiftByZero)
" int j = (73 << 0);\n"
" my_FragColor = vec4(i, j, i, j);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(3));
ASSERT_TRUE(constantFoundInAST(73));
}
......@@ -931,7 +931,7 @@ TEST_F(ConstantFoldingTest, FoldIsInfOutOfRangeFloatLiteral)
" bool b = isinf(1.0e2048);\n"
" my_FragColor = vec4(b);\n"
"}\n";
compile(shaderString);
compileAssumeSuccess(shaderString);
ASSERT_TRUE(constantFoundInAST(true));
}
......
......@@ -11,142 +11,77 @@
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh;
class MalformedShaderTest : public testing::Test
class MalformedShaderTest : public ShaderCompileTreeTest
{
public:
MalformedShaderTest() : mExtraCompileOptions(0) {}
protected:
virtual void SetUp()
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
virtual void TearDown()
{
delete mTranslator;
}
// Return true when compilation succeeds
bool compile(const std::string& shaderString)
{
const char *shaderStrings[] = { shaderString.c_str() };
bool compilationSuccess =
mTranslator->compile(shaderStrings, 1, SH_INTERMEDIATE_TREE | mExtraCompileOptions);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return compilationSuccess;
}
bool hasWarning() const
{
return mInfoLog.find("WARNING: ") != std::string::npos;
}
MalformedShaderTest() {}
protected:
std::string mInfoLog;
TranslatorESSL *mTranslator;
ShCompileOptions mExtraCompileOptions;
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
};
class MalformedVertexShaderTest : public MalformedShaderTest
class MalformedVertexShaderTest : public ShaderCompileTreeTest
{
public:
MalformedVertexShaderTest() {}
protected:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
};
class MalformedWebGL2ShaderTest : public MalformedShaderTest
class MalformedWebGL2ShaderTest : public ShaderCompileTreeTest
{
public:
MalformedWebGL2ShaderTest() {}
protected:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_WEBGL2_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_WEBGL2_SPEC; }
};
class MalformedWebGL1ShaderTest : public MalformedShaderTest
class MalformedWebGL1ShaderTest : public ShaderCompileTreeTest
{
public:
MalformedWebGL1ShaderTest() {}
protected:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_WEBGL_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_WEBGL_SPEC; }
};
class MalformedVertexShaderGLES31Test : public MalformedShaderTest
class MalformedVertexShaderGLES31Test : public ShaderCompileTreeTest
{
public:
MalformedVertexShaderGLES31Test() {}
private:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
class MalformedFragmentShaderGLES31Test : public MalformedShaderTest
class MalformedFragmentShaderGLES31Test : public ShaderCompileTreeTest
{
public:
MalformedFragmentShaderGLES31Test() {}
private:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
class MalformedComputeShaderTest : public MalformedShaderTest
class MalformedComputeShaderTest : public ShaderCompileTreeTest
{
public:
MalformedComputeShaderTest() {}
private:
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
::GLenum getShaderType() const override { return GL_COMPUTE_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
// This is a test for a bug that used to exist in ANGLE:
......
......@@ -13,45 +13,22 @@
#include "compiler/translator/TranslatorESSL.h"
#include "GLSLANG/ShaderLang.h"
#include "tests/test_utils/compiler_test.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh;
class QualificationVertexShaderTestESSL31 : public testing::Test
class QualificationVertexShaderTestESSL31 : public ShaderCompileTreeTest
{
public:
QualificationVertexShaderTestESSL31() {}
protected:
virtual void SetUp()
{
ShBuiltInResources resources;
InitBuiltInResources(&resources);
mTranslator = new TranslatorESSL(GL_VERTEX_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
virtual void TearDown() { delete mTranslator; }
// Return true when compilation succeeds
bool compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslator->compileTreeForTesting(shaderStrings, 1,
SH_INTERMEDIATE_TREE | SH_VARIABLES);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return mASTRoot != nullptr;
}
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
const TIntermSymbol *findSymbolInAST(const TString &symbolName, TBasicType basicType)
{
return FindSymbolNode(mASTRoot, symbolName, basicType);
}
protected:
TranslatorESSL *mTranslator;
TIntermNode *mASTRoot;
std::string mInfoLog;
};
// GLSL ES 3.10 has relaxed checks on qualifier order. Any order is correct.
......
......@@ -7,49 +7,37 @@
// OpenGL ES 3.1 removes the strict order of qualifiers imposed by the grammar.
// This file contains tests for invalid order and usage of qualifiers.
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh;
class QualificationOrderShaderTest : public testing::Test
class QualificationOrderFragmentShaderTest : public ShaderCompileTreeTest
{
public:
QualificationOrderShaderTest() {}
QualificationOrderFragmentShaderTest() {}
protected:
virtual void SetUp() {}
virtual void TearDown() {}
// Return true when compilation succeeds
bool compile(const std::string &shaderString, ::GLenum shaderType, ShShaderSpec spec)
void initResources(ShBuiltInResources *resources) override
{
ShBuiltInResources resources;
InitBuiltInResources(&resources);
resources.MaxDrawBuffers = (spec == SH_GLES2_SPEC) ? 1 : 8;
TranslatorESSL *translator = new TranslatorESSL(shaderType, spec);
EXPECT_TRUE(translator->Init(resources));
resources->MaxDrawBuffers = (getShaderSpec() == SH_GLES2_SPEC) ? 1 : 8;
}
const char *shaderStrings[] = {shaderString.c_str()};
bool compilationSuccess = translator->compile(shaderStrings, 1, SH_INTERMEDIATE_TREE);
TInfoSink &infoSink = translator->getInfoSink();
mInfoLog = infoSink.info.c_str();
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
delete translator;
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
return compilationSuccess;
}
class QualificationOrderVertexShaderTest : public QualificationOrderFragmentShaderTest
{
public:
QualificationOrderVertexShaderTest() {}
protected:
std::string mInfoLog;
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
};
// Repeating centroid qualifier is invalid.
TEST_F(QualificationOrderShaderTest, RepeatingCentroid)
TEST_F(QualificationOrderFragmentShaderTest, RepeatingCentroid)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -58,14 +46,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingCentroid)
"void main() {\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Repeating uniform storage qualifiers is invalid.
TEST_F(QualificationOrderShaderTest, RepeatingUniforms)
TEST_F(QualificationOrderFragmentShaderTest, RepeatingUniforms)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -74,14 +62,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingUniforms)
"void main() {\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Repeating varying storage qualifiers is invalid.
TEST_F(QualificationOrderShaderTest, RepeatingVaryings)
TEST_F(QualificationOrderFragmentShaderTest, RepeatingVaryings)
{
const std::string &shaderString =
"precision mediump float;\n"
......@@ -89,14 +77,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingVaryings)
"void main() {\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Layout qualifier should be before the storage qualifiers.
TEST_F(QualificationOrderShaderTest, WrongOrderQualifiers)
TEST_F(QualificationOrderFragmentShaderTest, WrongOrderQualifiers)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -105,14 +93,14 @@ TEST_F(QualificationOrderShaderTest, WrongOrderQualifiers)
"void main() {\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_1_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Centroid out is the correct order. Out centroid is incorrect.
TEST_F(QualificationOrderShaderTest, WrongOrderCentroidOut)
TEST_F(QualificationOrderVertexShaderTest, WrongOrderCentroidOut)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -124,14 +112,14 @@ TEST_F(QualificationOrderShaderTest, WrongOrderCentroidOut)
"gl_Position = uv;\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Centroid in is the correct order. In centroid is incorrect.
TEST_F(QualificationOrderShaderTest, WrongOrderCentroidIn)
TEST_F(QualificationOrderFragmentShaderTest, WrongOrderCentroidIn)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -142,14 +130,14 @@ TEST_F(QualificationOrderShaderTest, WrongOrderCentroidIn)
"colorOUT = colorIN;\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Type cannot be before the storage qualifier.
TEST_F(QualificationOrderShaderTest, WrongOrderTypeStorage)
TEST_F(QualificationOrderFragmentShaderTest, WrongOrderTypeStorage)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -160,14 +148,14 @@ TEST_F(QualificationOrderShaderTest, WrongOrderTypeStorage)
"colorOUT = colorIN;\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have two conflicting storage qualifiers.
TEST_F(QualificationOrderShaderTest, RepeatingDifferentStorageQualifiers)
TEST_F(QualificationOrderFragmentShaderTest, RepeatingDifferentStorageQualifiers)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -178,14 +166,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingDifferentStorageQualifiers)
"colorOUT = colorIN;\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have two different layout qualifiers.
TEST_F(QualificationOrderShaderTest, RepeatingLayoutQualifiers)
TEST_F(QualificationOrderFragmentShaderTest, RepeatingLayoutQualifiers)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -196,14 +184,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingLayoutQualifiers)
"colorOUT = colorIN;\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have repeating invariant qualifiers.
TEST_F(QualificationOrderShaderTest, RepeatingInvariantQualifiers)
TEST_F(QualificationOrderFragmentShaderTest, RepeatingInvariantQualifiers)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -214,14 +202,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingInvariantQualifiers)
"colorOUT = colorIN;\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have repeating storage qualifiers.
TEST_F(QualificationOrderShaderTest, RepeatingAttributes)
TEST_F(QualificationOrderVertexShaderTest, RepeatingAttributes)
{
const std::string &shaderString =
"precision mediump float;\n"
......@@ -230,14 +218,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingAttributes)
"gl_Position = positionIN;\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Wrong order for invariant varying. It should be 'invariant varying', not 'varying invariant'.
TEST_F(QualificationOrderShaderTest, VaryingInvariantWrongOrder)
TEST_F(QualificationOrderVertexShaderTest, VaryingInvariantWrongOrder)
{
const std::string &shaderString =
"precision mediump float;\n"
......@@ -248,42 +236,45 @@ TEST_F(QualificationOrderShaderTest, VaryingInvariantWrongOrder)
"dataOUT = 0.5 * dataOUT + vec4(0.5);\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have repeating storage qualifiers.
TEST_F(QualificationOrderShaderTest, AttributeVaryingMix)
TEST_F(QualificationOrderVertexShaderTest, AttributeVaryingMix)
{
const std::string &shaderString1 =
const std::string &shaderString =
"precision mediump float;\n"
"attribute varying vec4 positionIN;\n"
"void main() {\n"
"gl_Position = positionIN;\n"
"}\n";
const std::string &shaderString2 =
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have repeating storage qualifiers.
TEST_F(QualificationOrderVertexShaderTest, VaryingAttributeMix)
{
const std::string &shaderString =
"precision mediump float;\n"
"varying attribute vec4 positionIN;\n"
"void main() {\n"
"gl_Position = positionIN;\n"
"}\n";
if (compile(shaderString1, GL_VERTEX_SHADER, SH_GLES3_SPEC))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
if (compile(shaderString2, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have repeating interpolation qualifiers.
TEST_F(QualificationOrderShaderTest, RepeatingInterpolationQualifiers)
TEST_F(QualificationOrderVertexShaderTest, RepeatingInterpolationQualifiers)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -295,7 +286,7 @@ TEST_F(QualificationOrderShaderTest, RepeatingInterpolationQualifiers)
"dataOUT = 0.5 * dataOUT + vec4(0.5);\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
......@@ -303,7 +294,7 @@ TEST_F(QualificationOrderShaderTest, RepeatingInterpolationQualifiers)
// Wrong order for the interpolation and storage qualifier. The correct order is interpolation
// qualifier and then storage qualifier.
TEST_F(QualificationOrderShaderTest, WrongOrderInterpolationStorageQualifiers)
TEST_F(QualificationOrderVertexShaderTest, WrongOrderInterpolationStorageQualifiers)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -315,14 +306,14 @@ TEST_F(QualificationOrderShaderTest, WrongOrderInterpolationStorageQualifiers)
"dataOUT = 0.5 * dataOUT + vec4(0.5);\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// The correct order is invariant, interpolation, storage.
TEST_F(QualificationOrderShaderTest, WrongOrderInvariantInterpolationStorageQualifiers)
TEST_F(QualificationOrderVertexShaderTest, WrongOrderInvariantInterpolationStorageQualifiers)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -334,14 +325,14 @@ TEST_F(QualificationOrderShaderTest, WrongOrderInvariantInterpolationStorageQual
"dataOUT = 0.5 * dataOUT + vec4(0.5);\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// The invariant qualifer has to be before the storage qualifiers.
TEST_F(QualificationOrderShaderTest, WrongOrderInvariantNotFirst)
TEST_F(QualificationOrderVertexShaderTest, WrongOrderInvariantNotFirst)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -353,14 +344,14 @@ TEST_F(QualificationOrderShaderTest, WrongOrderInvariantNotFirst)
"dataOUT = 0.5 * dataOUT + vec4(0.5);\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// The precision qualifier is after the storage qualifiers.
TEST_F(QualificationOrderShaderTest, WrongOrderPrecision)
TEST_F(QualificationOrderVertexShaderTest, WrongOrderPrecision)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -372,14 +363,14 @@ TEST_F(QualificationOrderShaderTest, WrongOrderPrecision)
"dataOUT = 0.5 * dataOUT + vec4(0.5);\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have multiple declarations of the 'in' storage qualifier.
TEST_F(QualificationOrderShaderTest, RepeatingInQualifier)
TEST_F(QualificationOrderVertexShaderTest, RepeatingInQualifier)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -389,14 +380,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingInQualifier)
"gl_Position = positionIN;\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// A variable cannot have multiple declarations of the 'attribute' storage qualifier.
TEST_F(QualificationOrderShaderTest, RepeatingAttributeQualifier)
TEST_F(QualificationOrderVertexShaderTest, RepeatingAttributeQualifier)
{
const std::string &shaderString =
"precision mediump float;\n"
......@@ -405,14 +396,14 @@ TEST_F(QualificationOrderShaderTest, RepeatingAttributeQualifier)
"gl_Position = positionIN;\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Vertex input cannot be qualified with invariant.
TEST_F(QualificationOrderShaderTest, InvariantVertexInput)
TEST_F(QualificationOrderVertexShaderTest, InvariantVertexInput)
{
const std::string &shaderString =
"precision mediump float;\n"
......@@ -421,14 +412,14 @@ TEST_F(QualificationOrderShaderTest, InvariantVertexInput)
"gl_Position = positionIN;\n"
"}\n";
if (compile(shaderString, GL_VERTEX_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Cannot have a function parameter with the invariant qualifier.
TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersInvariant)
TEST_F(QualificationOrderFragmentShaderTest, InvalidFunctionParametersInvariant)
{
const std::string &shaderString =
"precision lowp float;\n"
......@@ -441,14 +432,14 @@ TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersInvariant)
" gl_FragColor = vec4(foo0(value));\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure" << mInfoLog;
}
}
// Cannot have a function parameter with the attribute qualifier.
TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersAttribute)
TEST_F(QualificationOrderFragmentShaderTest, InvalidFunctionParametersAttribute)
{
const std::string &shaderString =
"precision lowp float;\n"
......@@ -461,14 +452,14 @@ TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersAttribute)
" gl_FragColor = vec4(foo0(value));\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure" << mInfoLog;
}
}
// Cannot have a function parameter with the varying qualifier.
TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersVarying)
TEST_F(QualificationOrderFragmentShaderTest, InvalidFunctionParametersVarying)
{
const std::string &shaderString =
"precision lowp float;\n"
......@@ -481,14 +472,14 @@ TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersVarying)
" gl_FragColor = vec4(foo0(value));\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure" << mInfoLog;
}
}
// Cannot have a function parameter with the layout qualifier
TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersLayout)
TEST_F(QualificationOrderFragmentShaderTest, InvalidFunctionParametersLayout)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -503,14 +494,14 @@ TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersLayout)
" colorOUT = vec4(foo0(value));\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure" << mInfoLog;
}
}
// Cannot have a function parameter with the centroid qualifier
TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersCentroidIn)
TEST_F(QualificationOrderFragmentShaderTest, InvalidFunctionParametersCentroidIn)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -525,14 +516,14 @@ TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersCentroidIn)
" colorOUT = vec4(foo0(value));\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure" << mInfoLog;
}
}
// Cannot have a function parameter with the flat qualifier
TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersFlatIn)
TEST_F(QualificationOrderFragmentShaderTest, InvalidFunctionParametersFlatIn)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -547,7 +538,7 @@ TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersFlatIn)
" colorOUT = vec4(foo0(value));\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure" << mInfoLog;
}
......@@ -555,7 +546,7 @@ TEST_F(QualificationOrderShaderTest, InvalidFunctionParametersFlatIn)
// Output layout location qualifier can't appear more than once within a declaration.
// GLSL ES 3.00.6 section 4.3.8.2 Output Layout Qualifiers.
TEST_F(QualificationOrderShaderTest, TwoOutputLocations)
TEST_F(QualificationOrderFragmentShaderTest, TwoOutputLocations)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -564,7 +555,7 @@ TEST_F(QualificationOrderShaderTest, TwoOutputLocations)
"void main() {\n"
"}\n";
if (compile(shaderString, GL_FRAGMENT_SHADER, SH_GLES3_SPEC))
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
......
......@@ -10,8 +10,8 @@
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/TranslatorESSL.h"
#include "tests/test_utils/compiler_test.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
using namespace sh;
......@@ -111,39 +111,20 @@ void CheckImageDeclaration(TIntermNode *astRoot,
} // namespace
class ShaderImageTest : public testing::Test
class ShaderImageTest : public ShaderCompileTreeTest
{
public:
ShaderImageTest() {}
protected:
virtual void SetUp()
void SetUp() override
{
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
mTranslator = new sh::TranslatorESSL(GL_COMPUTE_SHADER, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
}
virtual void TearDown() { delete mTranslator; }
// Return true when compilation succeeds
bool compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslator->compileTreeForTesting(shaderStrings, 1,
SH_INTERMEDIATE_TREE | SH_VARIABLES);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return mASTRoot != nullptr;
ShaderCompileTreeTest::SetUp();
mExtraCompileOptions |= SH_VARIABLES;
}
protected:
std::string mTranslatedCode;
std::string mInfoLog;
sh::TranslatorESSL *mTranslator;
TIntermNode *mASTRoot;
::GLenum getShaderType() const override { return GL_COMPUTE_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
};
// Test that an image2D is properly parsed and exported as a uniform.
......@@ -161,7 +142,7 @@ TEST_F(ShaderImageTest, Image2DDeclaration)
FAIL() << "Shader compilation failed" << mInfoLog;
}
CheckExportedImageUniform(mTranslator->getUniforms(), 0, GL_IMAGE_2D, "myImage");
CheckExportedImageUniform(getUniforms(), 0, GL_IMAGE_2D, "myImage");
CheckImageDeclaration(mASTRoot, "myImage", EbtImage2D, EiifRGBA32F, true, false, false, false,
false);
}
......@@ -181,7 +162,7 @@ TEST_F(ShaderImageTest, Image3DDeclaration)
FAIL() << "Shader compilation failed" << mInfoLog;
}
CheckExportedImageUniform(mTranslator->getUniforms(), 0, GL_UNSIGNED_INT_IMAGE_3D, "myImage");
CheckExportedImageUniform(getUniforms(), 0, GL_UNSIGNED_INT_IMAGE_3D, "myImage");
CheckImageDeclaration(mASTRoot, "myImage", EbtUImage3D, EiifRGBA32UI, true, true, false, false,
false);
}
......
......@@ -15,42 +15,6 @@
using namespace sh;
void ConstantFoldingTest::SetUp()
{
allocator.push();
SetGlobalPoolAllocator(&allocator);
ShBuiltInResources resources;
InitBuiltInResources(&resources);
mTranslatorESSL = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_SPEC);
ASSERT_TRUE(mTranslatorESSL->Init(resources));
}
void ConstantFoldingTest::TearDown()
{
delete mTranslatorESSL;
SetGlobalPoolAllocator(NULL);
allocator.pop();
}
void ConstantFoldingTest::compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslatorESSL->compileTreeForTesting(shaderStrings, 1, SH_OBJECT_CODE);
if (!mASTRoot)
{
TInfoSink &infoSink = mTranslatorESSL->getInfoSink();
FAIL() << "Shader compilation into ESSL failed " << infoSink.info.c_str();
}
}
bool ConstantFoldingTest::hasWarning()
{
TInfoSink &infoSink = mTranslatorESSL->getInfoSink();
return infoSink.info.str().find("WARNING:") != std::string::npos;
}
void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpression)
{
std::stringstream shaderStream;
......@@ -61,5 +25,5 @@ void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpres
"{\n"
<< " my_FragColor = " << floatExpression << ";\n"
<< "}\n";
compile(shaderStream.str());
compileAssumeSuccess(shaderStream.str());
}
......@@ -14,8 +14,7 @@
#include "common/mathutil.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/PoolAlloc.h"
#include "gtest/gtest.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
namespace sh
{
......@@ -132,20 +131,14 @@ class ConstantFinder : public TIntermTraverser
bool mFound;
};
class ConstantFoldingTest : public testing::Test
class ConstantFoldingTest : public ShaderCompileTreeTest
{
public:
ConstantFoldingTest() {}
protected:
void SetUp() override;
void TearDown() override;
void compile(const std::string &shaderString);
// Must be called after compile()
bool hasWarning();
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
template <typename T>
bool constantFoundInAST(T constant)
......@@ -176,12 +169,6 @@ class ConstantFoldingTest : public testing::Test
mASTRoot->traverse(&finder);
return finder.found();
}
private:
TranslatorESSL *mTranslatorESSL;
TIntermNode *mASTRoot;
TPoolAllocator allocator;
};
class ConstantFoldingExpressionTest : public ConstantFoldingTest
......
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderCompileTreeTest.cpp:
// Test that shader validation results in the correct compile status.
//
#include "tests/test_utils/ShaderCompileTreeTest.h"
#include "compiler/translator/TranslatorESSL.h"
using namespace sh;
void ShaderCompileTreeTest::SetUp()
{
mAllocator.push();
SetGlobalPoolAllocator(&mAllocator);
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
initResources(&resources);
mTranslator = new TranslatorESSL(getShaderType(), getShaderSpec());
ASSERT_TRUE(mTranslator->Init(resources));
}
void ShaderCompileTreeTest::TearDown()
{
delete mTranslator;
SetGlobalPoolAllocator(nullptr);
mAllocator.pop();
}
bool ShaderCompileTreeTest::compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
mASTRoot = mTranslator->compileTreeForTesting(shaderStrings, 1, mExtraCompileOptions);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return mASTRoot != nullptr;
}
void ShaderCompileTreeTest::compileAssumeSuccess(const std::string &shaderString)
{
if (!compile(shaderString))
{
FAIL() << "Shader compilation into ESSL failed, log:\n" << mInfoLog;
}
}
bool ShaderCompileTreeTest::hasWarning() const
{
return mInfoLog.find("WARNING: ") != std::string::npos;
}
const std::vector<sh::Uniform> ShaderCompileTreeTest::getUniforms()
{
ASSERT(mExtraCompileOptions & SH_VARIABLES);
return mTranslator->getUniforms();
}
\ No newline at end of file
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderCompileTreeTest.h:
// Test that shader validation results in the correct compile status.
//
#ifndef TESTS_TEST_UTILS_SHADER_COMPILE_TREE_TEST_H_
#define TESTS_TEST_UTILS_SHADER_COMPILE_TREE_TEST_H_
#include "angle_gl.h"
#include "compiler/translator/PoolAlloc.h"
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
namespace sh
{
class TIntermBlock;
class TranslatorESSL;
class ShaderCompileTreeTest : public testing::Test
{
public:
ShaderCompileTreeTest() : mExtraCompileOptions(0) {}
protected:
void SetUp() override;
void TearDown() override;
// Return true when compilation succeeds
bool compile(const std::string &shaderString);
void compileAssumeSuccess(const std::string &shaderString);
bool hasWarning() const;
const std::vector<sh::Uniform> getUniforms();
virtual void initResources(ShBuiltInResources *resources) {}
virtual ::GLenum getShaderType() const = 0;
virtual ShShaderSpec getShaderSpec() const = 0;
std::string mInfoLog;
ShCompileOptions mExtraCompileOptions;
TIntermBlock *mASTRoot;
private:
TranslatorESSL *mTranslator;
TPoolAllocator mAllocator;
};
} // namespace sh
#endif // TESTS_TEST_UTILS_SHADER_COMPILE_TREE_TEST_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment