Commit e7c2857d by Olli Etuaho Committed by Commit Bot

Clean up direct access of ShaderVariable::arraySize

This change is pure refactoring. It's intended to help with adding support for arrays of arrays. BUG=angleproject:2125 TEST=angle_unittests Change-Id: I82881a98c3c476fd6666a551ce6be255ae0de4cf Reviewed-on: https://chromium-review.googlesource.com/733127Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 940c48b2
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented every time the API changes. // It is incremented every time the API changes.
#define ANGLE_SH_VERSION 183 #define ANGLE_SH_VERSION 184
enum ShShaderSpec enum ShShaderSpec
{ {
......
...@@ -59,6 +59,7 @@ enum class BlockType ...@@ -59,6 +59,7 @@ enum class BlockType
struct ShaderVariable struct ShaderVariable
{ {
ShaderVariable(); ShaderVariable();
ShaderVariable(GLenum typeIn);
ShaderVariable(GLenum typeIn, unsigned int arraySizeIn); ShaderVariable(GLenum typeIn, unsigned int arraySizeIn);
~ShaderVariable(); ~ShaderVariable();
ShaderVariable(const ShaderVariable &other); ShaderVariable(const ShaderVariable &other);
......
...@@ -353,34 +353,27 @@ void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol) ...@@ -353,34 +353,27 @@ void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol)
info.name = kName; info.name = kName;
info.mappedName = kName; info.mappedName = kName;
info.type = GL_NONE; info.type = GL_NONE;
info.arraySize = 0;
info.precision = GL_NONE; info.precision = GL_NONE;
info.staticUse = true; info.staticUse = true;
ShaderVariable nearInfo; ShaderVariable nearInfo(GL_FLOAT);
const char kNearName[] = "near"; const char kNearName[] = "near";
nearInfo.name = kNearName; nearInfo.name = kNearName;
nearInfo.mappedName = kNearName; nearInfo.mappedName = kNearName;
nearInfo.type = GL_FLOAT;
nearInfo.arraySize = 0;
nearInfo.precision = GL_HIGH_FLOAT; nearInfo.precision = GL_HIGH_FLOAT;
nearInfo.staticUse = true; nearInfo.staticUse = true;
ShaderVariable farInfo; ShaderVariable farInfo(GL_FLOAT);
const char kFarName[] = "far"; const char kFarName[] = "far";
farInfo.name = kFarName; farInfo.name = kFarName;
farInfo.mappedName = kFarName; farInfo.mappedName = kFarName;
farInfo.type = GL_FLOAT;
farInfo.arraySize = 0;
farInfo.precision = GL_HIGH_FLOAT; farInfo.precision = GL_HIGH_FLOAT;
farInfo.staticUse = true; farInfo.staticUse = true;
ShaderVariable diffInfo; ShaderVariable diffInfo(GL_FLOAT);
const char kDiffName[] = "diff"; const char kDiffName[] = "diff";
diffInfo.name = kDiffName; diffInfo.name = kDiffName;
diffInfo.mappedName = kDiffName; diffInfo.mappedName = kDiffName;
diffInfo.type = GL_FLOAT;
diffInfo.arraySize = 0;
diffInfo.precision = GL_HIGH_FLOAT; diffInfo.precision = GL_HIGH_FLOAT;
diffInfo.staticUse = true; diffInfo.staticUse = true;
...@@ -447,7 +440,6 @@ void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol) ...@@ -447,7 +440,6 @@ void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol)
info.name = kName; info.name = kName;
info.mappedName = kName; info.mappedName = kName;
info.type = GL_INT; info.type = GL_INT;
info.arraySize = 0;
info.precision = GL_HIGH_INT; // Defined by spec. info.precision = GL_HIGH_INT; // Defined by spec.
info.staticUse = true; info.staticUse = true;
info.location = -1; info.location = -1;
......
...@@ -1020,7 +1020,7 @@ bool TCompiler::wereVariablesCollected() const ...@@ -1020,7 +1020,7 @@ bool TCompiler::wereVariablesCollected() const
void TCompiler::initializeGLPosition(TIntermBlock *root) void TCompiler::initializeGLPosition(TIntermBlock *root)
{ {
InitVariableList list; InitVariableList list;
sh::ShaderVariable var(GL_FLOAT_VEC4, 0); sh::ShaderVariable var(GL_FLOAT_VEC4);
var.name = "gl_Position"; var.name = "gl_Position";
list.push_back(var); list.push_back(var);
InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior); InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior);
......
...@@ -34,9 +34,15 @@ ShaderVariable::ShaderVariable() : type(0), precision(0), arraySize(0), staticUs ...@@ -34,9 +34,15 @@ ShaderVariable::ShaderVariable() : type(0), precision(0), arraySize(0), staticUs
{ {
} }
ShaderVariable::ShaderVariable(GLenum typeIn)
: type(typeIn), precision(0), arraySize(0), staticUse(false)
{
}
ShaderVariable::ShaderVariable(GLenum typeIn, unsigned int arraySizeIn) ShaderVariable::ShaderVariable(GLenum typeIn, unsigned int arraySizeIn)
: type(typeIn), precision(0), arraySize(arraySizeIn), staticUse(false) : type(typeIn), precision(0), arraySize(arraySizeIn), staticUse(false)
{ {
ASSERT(arraySizeIn != 0);
} }
ShaderVariable::~ShaderVariable() ShaderVariable::~ShaderVariable()
......
...@@ -88,7 +88,7 @@ class CollectVariablesTest : public testing::Test ...@@ -88,7 +88,7 @@ class CollectVariablesTest : public testing::Test
foundDiff = true; foundDiff = true;
} }
EXPECT_EQ(0u, field.arraySize); EXPECT_FALSE(field.isArray());
EXPECT_FALSE(field.isStruct()); EXPECT_FALSE(field.isStruct());
EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, field.precision); EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, field.precision);
EXPECT_TRUE(field.staticUse); EXPECT_TRUE(field.staticUse);
...@@ -243,7 +243,7 @@ TEST_F(CollectFragmentVariablesTest, SimpleOutputVar) ...@@ -243,7 +243,7 @@ TEST_F(CollectFragmentVariablesTest, SimpleOutputVar)
const OutputVariable &outputVariable = outputVariables[0]; const OutputVariable &outputVariable = outputVariables[0];
EXPECT_EQ(0u, outputVariable.arraySize); EXPECT_FALSE(outputVariable.isArray());
EXPECT_EQ(-1, outputVariable.location); EXPECT_EQ(-1, outputVariable.location);
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable.precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable.precision);
EXPECT_TRUE(outputVariable.staticUse); EXPECT_TRUE(outputVariable.staticUse);
...@@ -268,7 +268,7 @@ TEST_F(CollectFragmentVariablesTest, LocationOutputVar) ...@@ -268,7 +268,7 @@ TEST_F(CollectFragmentVariablesTest, LocationOutputVar)
const OutputVariable &outputVariable = outputVariables[0]; const OutputVariable &outputVariable = outputVariables[0];
EXPECT_EQ(0u, outputVariable.arraySize); EXPECT_FALSE(outputVariable.isArray());
EXPECT_EQ(5, outputVariable.location); EXPECT_EQ(5, outputVariable.location);
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable.precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable.precision);
EXPECT_TRUE(outputVariable.staticUse); EXPECT_TRUE(outputVariable.staticUse);
...@@ -292,7 +292,7 @@ TEST_F(CollectVertexVariablesTest, LocationAttribute) ...@@ -292,7 +292,7 @@ TEST_F(CollectVertexVariablesTest, LocationAttribute)
const Attribute &attribute = attributes[0]; const Attribute &attribute = attributes[0];
EXPECT_EQ(0u, attribute.arraySize); EXPECT_FALSE(attribute.isArray());
EXPECT_EQ(5, attribute.location); EXPECT_EQ(5, attribute.location);
EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, attribute.precision); EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, attribute.precision);
EXPECT_TRUE(attribute.staticUse); EXPECT_TRUE(attribute.staticUse);
...@@ -535,7 +535,7 @@ TEST_F(CollectVertexVariablesTest, VaryingInterpolation) ...@@ -535,7 +535,7 @@ TEST_F(CollectVertexVariablesTest, VaryingInterpolation)
varying = &varyings[1]; varying = &varyings[1];
} }
EXPECT_EQ(0u, varying->arraySize); EXPECT_FALSE(varying->isArray());
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, varying->precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, varying->precision);
EXPECT_TRUE(varying->staticUse); EXPECT_TRUE(varying->staticUse);
EXPECT_GLENUM_EQ(GL_FLOAT, varying->type); EXPECT_GLENUM_EQ(GL_FLOAT, varying->type);
...@@ -581,7 +581,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragColor) ...@@ -581,7 +581,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragColor)
const OutputVariable *outputVariable = nullptr; const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragColorShader, 0u, "gl_FragColor", &outputVariable); validateOutputVariableForShader(fragColorShader, 0u, "gl_FragColor", &outputVariable);
ASSERT_NE(outputVariable, nullptr); ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize); EXPECT_FALSE(outputVariable->isArray());
EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type); EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type);
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision);
} }
...@@ -630,7 +630,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragDepthMediump) ...@@ -630,7 +630,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragDepthMediump)
const OutputVariable *outputVariable = nullptr; const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragDepthShader, 0u, "gl_FragDepthEXT", &outputVariable); validateOutputVariableForShader(fragDepthShader, 0u, "gl_FragDepthEXT", &outputVariable);
ASSERT_NE(outputVariable, nullptr); ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize); EXPECT_FALSE(outputVariable->isArray());
EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type); EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type);
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision);
} }
...@@ -653,7 +653,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragDepthHighp) ...@@ -653,7 +653,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1FragDepthHighp)
const OutputVariable *outputVariable = nullptr; const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragDepthHighShader, 0u, "gl_FragDepthEXT", &outputVariable); validateOutputVariableForShader(fragDepthHighShader, 0u, "gl_FragDepthEXT", &outputVariable);
ASSERT_NE(outputVariable, nullptr); ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize); EXPECT_FALSE(outputVariable->isArray());
EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type); EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type);
EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, outputVariable->precision); EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, outputVariable->precision);
} }
...@@ -676,7 +676,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL3FragDepthHighp) ...@@ -676,7 +676,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL3FragDepthHighp)
const OutputVariable *outputVariable = nullptr; const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(fragDepthHighShader, 0u, "gl_FragDepth", &outputVariable); validateOutputVariableForShader(fragDepthHighShader, 0u, "gl_FragDepth", &outputVariable);
ASSERT_NE(outputVariable, nullptr); ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize); EXPECT_FALSE(outputVariable->isArray());
EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type); EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type);
EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, outputVariable->precision); EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, outputVariable->precision);
} }
...@@ -704,7 +704,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1EXTBlendFuncExtendedSecondary ...@@ -704,7 +704,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1EXTBlendFuncExtendedSecondary
const OutputVariable *outputVariable = nullptr; const OutputVariable *outputVariable = nullptr;
validateOutputVariableForShader(secondaryFragColorShader, 0u, "gl_FragColor", &outputVariable); validateOutputVariableForShader(secondaryFragColorShader, 0u, "gl_FragColor", &outputVariable);
ASSERT_NE(outputVariable, nullptr); ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize); EXPECT_FALSE(outputVariable->isArray());
EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type); EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type);
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision);
...@@ -712,7 +712,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1EXTBlendFuncExtendedSecondary ...@@ -712,7 +712,7 @@ TEST_F(CollectFragmentVariablesTest, OutputVarESSL1EXTBlendFuncExtendedSecondary
validateOutputVariableForShader(secondaryFragColorShader, 1u, "gl_SecondaryFragColorEXT", validateOutputVariableForShader(secondaryFragColorShader, 1u, "gl_SecondaryFragColorEXT",
&outputVariable); &outputVariable);
ASSERT_NE(outputVariable, nullptr); ASSERT_NE(outputVariable, nullptr);
EXPECT_EQ(0u, outputVariable->arraySize); EXPECT_FALSE(outputVariable->isArray());
EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type); EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type);
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision);
} }
...@@ -831,7 +831,7 @@ TEST_F(CollectHashedVertexVariablesTest, StructUniform) ...@@ -831,7 +831,7 @@ TEST_F(CollectHashedVertexVariablesTest, StructUniform)
const Uniform &uniform = uniforms[0]; const Uniform &uniform = uniforms[0];
EXPECT_EQ(0u, uniform.arraySize); EXPECT_FALSE(uniform.isArray());
EXPECT_EQ("u", uniform.name); EXPECT_EQ("u", uniform.name);
EXPECT_EQ("webgl_1", uniform.mappedName); EXPECT_EQ("webgl_1", uniform.mappedName);
EXPECT_TRUE(uniform.staticUse); EXPECT_TRUE(uniform.staticUse);
...@@ -868,14 +868,14 @@ TEST_F(CollectFragmentVariablesTest, MultiDeclaration) ...@@ -868,14 +868,14 @@ TEST_F(CollectFragmentVariablesTest, MultiDeclaration)
ASSERT_EQ(2u, uniforms.size()); ASSERT_EQ(2u, uniforms.size());
const Uniform &uniform = uniforms[0]; const Uniform &uniform = uniforms[0];
EXPECT_EQ(0u, uniform.arraySize); EXPECT_FALSE(uniform.isArray());
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniform.precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniform.precision);
EXPECT_TRUE(uniform.staticUse); EXPECT_TRUE(uniform.staticUse);
EXPECT_GLENUM_EQ(GL_FLOAT, uniform.type); EXPECT_GLENUM_EQ(GL_FLOAT, uniform.type);
EXPECT_EQ("uA", uniform.name); EXPECT_EQ("uA", uniform.name);
const Uniform &uniformB = uniforms[1]; const Uniform &uniformB = uniforms[1];
EXPECT_EQ(0u, uniformB.arraySize); EXPECT_FALSE(uniformB.isArray());
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniformB.precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniformB.precision);
EXPECT_TRUE(uniformB.staticUse); EXPECT_TRUE(uniformB.staticUse);
EXPECT_GLENUM_EQ(GL_FLOAT, uniformB.type); EXPECT_GLENUM_EQ(GL_FLOAT, uniformB.type);
...@@ -901,7 +901,7 @@ TEST_F(CollectFragmentVariablesTest, EmptyDeclarator) ...@@ -901,7 +901,7 @@ TEST_F(CollectFragmentVariablesTest, EmptyDeclarator)
ASSERT_EQ(1u, uniforms.size()); ASSERT_EQ(1u, uniforms.size());
const Uniform &uniformB = uniforms[0]; const Uniform &uniformB = uniforms[0];
EXPECT_EQ(0u, uniformB.arraySize); EXPECT_FALSE(uniformB.isArray());
EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniformB.precision); EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniformB.precision);
EXPECT_TRUE(uniformB.staticUse); EXPECT_TRUE(uniformB.staticUse);
EXPECT_GLENUM_EQ(GL_FLOAT, uniformB.type); EXPECT_GLENUM_EQ(GL_FLOAT, uniformB.type);
......
...@@ -26,13 +26,13 @@ TEST(ShaderVariableTest, FindInfoByMappedName) ...@@ -26,13 +26,13 @@ TEST(ShaderVariableTest, FindInfoByMappedName)
// }; // };
// B uni[2]; // B uni[2];
ShaderVariable uni; ShaderVariable uni;
uni.arraySize = 2; uni.setArraySize(2);
uni.name = "uni"; uni.name = "uni";
uni.mappedName = "m_uni"; uni.mappedName = "m_uni";
uni.structName = "B"; uni.structName = "B";
{ {
ShaderVariable a; ShaderVariable a;
a.arraySize = 3; a.setArraySize(3);
a.name = "a"; a.name = "a";
a.mappedName = "m_a"; a.mappedName = "m_a";
a.structName = "A"; a.structName = "A";
...@@ -42,7 +42,7 @@ TEST(ShaderVariableTest, FindInfoByMappedName) ...@@ -42,7 +42,7 @@ TEST(ShaderVariableTest, FindInfoByMappedName)
x.mappedName = "m_x"; x.mappedName = "m_x";
a.fields.push_back(x); a.fields.push_back(x);
ShaderVariable y(GL_FLOAT_VEC3, 0); ShaderVariable y(GL_FLOAT_VEC3);
y.name = "y"; y.name = "y";
y.mappedName = "m_y"; y.mappedName = "m_y";
a.fields.push_back(y); a.fields.push_back(y);
...@@ -94,17 +94,16 @@ TEST(ShaderVariableTest, IsSameUniformWithDifferentFieldOrder) ...@@ -94,17 +94,16 @@ TEST(ShaderVariableTest, IsSameUniformWithDifferentFieldOrder)
// }; // };
// uniform A uni; // uniform A uni;
Uniform vx_a; Uniform vx_a;
vx_a.arraySize = 0;
vx_a.name = "uni"; vx_a.name = "uni";
vx_a.mappedName = "m_uni"; vx_a.mappedName = "m_uni";
vx_a.structName = "A"; vx_a.structName = "A";
{ {
ShaderVariable x(GL_FLOAT, 0); ShaderVariable x(GL_FLOAT);
x.name = "x"; x.name = "x";
x.mappedName = "m_x"; x.mappedName = "m_x";
vx_a.fields.push_back(x); vx_a.fields.push_back(x);
ShaderVariable y(GL_FLOAT, 0); ShaderVariable y(GL_FLOAT);
y.name = "y"; y.name = "y";
y.mappedName = "m_y"; y.mappedName = "m_y";
vx_a.fields.push_back(y); vx_a.fields.push_back(y);
...@@ -116,17 +115,16 @@ TEST(ShaderVariableTest, IsSameUniformWithDifferentFieldOrder) ...@@ -116,17 +115,16 @@ TEST(ShaderVariableTest, IsSameUniformWithDifferentFieldOrder)
// }; // };
// uniform A uni; // uniform A uni;
Uniform fx_a; Uniform fx_a;
fx_a.arraySize = 0;
fx_a.name = "uni"; fx_a.name = "uni";
fx_a.mappedName = "m_uni"; fx_a.mappedName = "m_uni";
fx_a.structName = "A"; fx_a.structName = "A";
{ {
ShaderVariable y(GL_FLOAT, 0); ShaderVariable y(GL_FLOAT);
y.name = "y"; y.name = "y";
y.mappedName = "m_y"; y.mappedName = "m_y";
fx_a.fields.push_back(y); fx_a.fields.push_back(y);
ShaderVariable x(GL_FLOAT, 0); ShaderVariable x(GL_FLOAT);
x.name = "x"; x.name = "x";
x.mappedName = "m_x"; x.mappedName = "m_x";
fx_a.fields.push_back(x); fx_a.fields.push_back(x);
...@@ -143,17 +141,16 @@ TEST(ShaderVariableTest, IsSameUniformWithDifferentStructNames) ...@@ -143,17 +141,16 @@ TEST(ShaderVariableTest, IsSameUniformWithDifferentStructNames)
// }; // };
// uniform A uni; // uniform A uni;
Uniform vx_a; Uniform vx_a;
vx_a.arraySize = 0;
vx_a.name = "uni"; vx_a.name = "uni";
vx_a.mappedName = "m_uni"; vx_a.mappedName = "m_uni";
vx_a.structName = "A"; vx_a.structName = "A";
{ {
ShaderVariable x(GL_FLOAT, 0); ShaderVariable x(GL_FLOAT);
x.name = "x"; x.name = "x";
x.mappedName = "m_x"; x.mappedName = "m_x";
vx_a.fields.push_back(x); vx_a.fields.push_back(x);
ShaderVariable y(GL_FLOAT, 0); ShaderVariable y(GL_FLOAT);
y.name = "y"; y.name = "y";
y.mappedName = "m_y"; y.mappedName = "m_y";
vx_a.fields.push_back(y); vx_a.fields.push_back(y);
...@@ -165,16 +162,15 @@ TEST(ShaderVariableTest, IsSameUniformWithDifferentStructNames) ...@@ -165,16 +162,15 @@ TEST(ShaderVariableTest, IsSameUniformWithDifferentStructNames)
// }; // };
// uniform B uni; // uniform B uni;
Uniform fx_a; Uniform fx_a;
fx_a.arraySize = 0;
fx_a.name = "uni"; fx_a.name = "uni";
fx_a.mappedName = "m_uni"; fx_a.mappedName = "m_uni";
{ {
ShaderVariable x(GL_FLOAT, 0); ShaderVariable x(GL_FLOAT);
x.name = "x"; x.name = "x";
x.mappedName = "m_x"; x.mappedName = "m_x";
fx_a.fields.push_back(x); fx_a.fields.push_back(x);
ShaderVariable y(GL_FLOAT, 0); ShaderVariable y(GL_FLOAT);
y.name = "y"; y.name = "y";
y.mappedName = "m_y"; y.mappedName = "m_y";
fx_a.fields.push_back(y); fx_a.fields.push_back(y);
...@@ -195,7 +191,6 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentInvariance) ...@@ -195,7 +191,6 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentInvariance)
// invariant varying float vary; // invariant varying float vary;
Varying vx; Varying vx;
vx.type = GL_FLOAT; vx.type = GL_FLOAT;
vx.arraySize = 0;
vx.precision = GL_MEDIUM_FLOAT; vx.precision = GL_MEDIUM_FLOAT;
vx.name = "vary"; vx.name = "vary";
vx.mappedName = "m_vary"; vx.mappedName = "m_vary";
...@@ -205,7 +200,6 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentInvariance) ...@@ -205,7 +200,6 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentInvariance)
// varying float vary; // varying float vary;
Varying fx; Varying fx;
fx.type = GL_FLOAT; fx.type = GL_FLOAT;
fx.arraySize = 0;
fx.precision = GL_MEDIUM_FLOAT; fx.precision = GL_MEDIUM_FLOAT;
fx.name = "vary"; fx.name = "vary";
fx.mappedName = "m_vary"; fx.mappedName = "m_vary";
...@@ -428,7 +422,6 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentName) ...@@ -428,7 +422,6 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentName)
// Varying float vary1; // Varying float vary1;
Varying vx; Varying vx;
vx.type = GL_FLOAT; vx.type = GL_FLOAT;
vx.arraySize = 0;
vx.precision = GL_MEDIUM_FLOAT; vx.precision = GL_MEDIUM_FLOAT;
vx.name = "vary1"; vx.name = "vary1";
vx.mappedName = "m_vary1"; vx.mappedName = "m_vary1";
...@@ -438,7 +431,6 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentName) ...@@ -438,7 +431,6 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentName)
// Varying float vary2; // Varying float vary2;
Varying fx; Varying fx;
fx.type = GL_FLOAT; fx.type = GL_FLOAT;
fx.arraySize = 0;
fx.precision = GL_MEDIUM_FLOAT; fx.precision = GL_MEDIUM_FLOAT;
fx.name = "vary2"; fx.name = "vary2";
fx.mappedName = "m_vary2"; fx.mappedName = "m_vary2";
......
...@@ -60,6 +60,17 @@ static sh::GLenum types[] = { ...@@ -60,6 +60,17 @@ static sh::GLenum types[] = {
static sh::GLenum nonSqMatTypes[] = {GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4, GL_FLOAT_MAT3x2, static sh::GLenum nonSqMatTypes[] = {GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4, GL_FLOAT_MAT3x2,
GL_FLOAT_MAT3x4, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3}; GL_FLOAT_MAT3x4, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3};
// Creates either a single variable or an array variable depending on numVars.
sh::ShaderVariable CreateShaderVariable(sh::GLenum type, int numVars)
{
ASSERT(numVars != 0);
if (numVars == 1)
{
return sh::ShaderVariable(type);
}
return sh::ShaderVariable(type, numVars);
}
} // anonymous namespace } // anonymous namespace
TEST(VariablePacking, Pack) TEST(VariablePacking, Pack)
...@@ -76,18 +87,18 @@ TEST(VariablePacking, Pack) ...@@ -76,18 +87,18 @@ TEST(VariablePacking, Pack)
int num_components_per_row = sh::GetTypePackingComponentsPerRow(type); int num_components_per_row = sh::GetTypePackingComponentsPerRow(type);
// Check 1 of the type. // Check 1 of the type.
vars.clear(); vars.clear();
vars.push_back(sh::ShaderVariable(type, 0)); vars.push_back(sh::ShaderVariable(type));
EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars)); EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
// Check exactly the right amount of 1 type as an array. // Check exactly the right amount of 1 type as an array.
int num_vars = kMaxRows / num_rows; int num_vars = kMaxRows / num_rows;
vars.clear(); vars.clear();
vars.push_back(sh::ShaderVariable(type, num_vars == 1 ? 0 : num_vars)); vars.push_back(CreateShaderVariable(type, num_vars));
EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars)); EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
// test too many // test too many
vars.clear(); vars.clear();
vars.push_back(sh::ShaderVariable(type, num_vars == 0 ? 0 : (num_vars + 1))); vars.push_back(CreateShaderVariable(type, num_vars + 1));
EXPECT_FALSE(CheckVariablesInPackingLimits(kMaxRows, vars)); EXPECT_FALSE(CheckVariablesInPackingLimits(kMaxRows, vars));
// Check exactly the right amount of 1 type as individual vars. // Check exactly the right amount of 1 type as individual vars.
...@@ -96,26 +107,26 @@ TEST(VariablePacking, Pack) ...@@ -96,26 +107,26 @@ TEST(VariablePacking, Pack)
vars.clear(); vars.clear();
for (int ii = 0; ii < num_vars; ++ii) for (int ii = 0; ii < num_vars; ++ii)
{ {
vars.push_back(sh::ShaderVariable(type, 0)); vars.push_back(sh::ShaderVariable(type));
} }
EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars)); EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
// Check 1 too many. // Check 1 too many.
vars.push_back(sh::ShaderVariable(type, 0)); vars.push_back(sh::ShaderVariable(type));
EXPECT_FALSE(CheckVariablesInPackingLimits(kMaxRows, vars)); EXPECT_FALSE(CheckVariablesInPackingLimits(kMaxRows, vars));
} }
// Test example from GLSL ES 3.0 spec chapter 11. // Test example from GLSL ES 3.0 spec chapter 11.
vars.clear(); vars.clear();
vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC4, 0)); vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC4));
vars.push_back(sh::ShaderVariable(GL_FLOAT_MAT3, 0)); vars.push_back(sh::ShaderVariable(GL_FLOAT_MAT3));
vars.push_back(sh::ShaderVariable(GL_FLOAT_MAT3, 0)); vars.push_back(sh::ShaderVariable(GL_FLOAT_MAT3));
vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 6)); vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 6));
vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 4)); vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 4));
vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 0)); vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2));
vars.push_back(sh::ShaderVariable(GL_FLOAT, 3)); vars.push_back(sh::ShaderVariable(GL_FLOAT, 3));
vars.push_back(sh::ShaderVariable(GL_FLOAT, 2)); vars.push_back(sh::ShaderVariable(GL_FLOAT, 2));
vars.push_back(sh::ShaderVariable(GL_FLOAT, 0)); vars.push_back(sh::ShaderVariable(GL_FLOAT));
EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars)); EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
} }
...@@ -158,21 +169,21 @@ TEST(VariablePacking, NonSquareMats) ...@@ -158,21 +169,21 @@ TEST(VariablePacking, NonSquareMats)
int squareSize = std::max(rows, cols); int squareSize = std::max(rows, cols);
std::vector<sh::ShaderVariable> vars; std::vector<sh::ShaderVariable> vars;
vars.push_back(sh::ShaderVariable(type, 0)); vars.push_back(sh::ShaderVariable(type));
// Fill columns // Fill columns
for (int row = 0; row < squareSize; row++) for (int row = 0; row < squareSize; row++)
{ {
for (int col = squareSize; col < 4; ++col) for (int col = squareSize; col < 4; ++col)
{ {
vars.push_back(sh::ShaderVariable(GL_FLOAT, 0)); vars.push_back(sh::ShaderVariable(GL_FLOAT));
} }
} }
EXPECT_TRUE(CheckVariablesInPackingLimits(squareSize, vars)); EXPECT_TRUE(CheckVariablesInPackingLimits(squareSize, vars));
// and one scalar and packing should fail // and one scalar and packing should fail
vars.push_back(sh::ShaderVariable(GL_FLOAT, 0)); vars.push_back(sh::ShaderVariable(GL_FLOAT));
EXPECT_FALSE(CheckVariablesInPackingLimits(squareSize, vars)); EXPECT_FALSE(CheckVariablesInPackingLimits(squareSize, vars));
} }
} }
...@@ -218,22 +229,22 @@ TEST(VariablePacking, Struct) ...@@ -218,22 +229,22 @@ TEST(VariablePacking, Struct)
// Test example from GLSL ES 3.0 spec chapter 11, but with structs // Test example from GLSL ES 3.0 spec chapter 11, but with structs
std::vector<sh::ShaderVariable> vars; std::vector<sh::ShaderVariable> vars;
vars.push_back(sh::ShaderVariable(GL_NONE, 0)); vars.push_back(sh::ShaderVariable(GL_NONE));
sh::ShaderVariable &parentStruct = vars[0]; sh::ShaderVariable &parentStruct = vars[0];
parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC4, 0)); parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC4));
parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_MAT3, 0)); parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_MAT3));
parentStruct.fields.push_back(sh::ShaderVariable(GL_NONE, 0)); parentStruct.fields.push_back(sh::ShaderVariable(GL_NONE));
sh::ShaderVariable &innerStruct = parentStruct.fields.back(); sh::ShaderVariable &innerStruct = parentStruct.fields.back();
innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_MAT3, 0)); innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_MAT3));
innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 6)); innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 6));
innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 4)); innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 4));
parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 0)); parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2));
parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT, 3)); parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT, 3));
parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT, 2)); parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT, 2));
parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT, 0)); parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT));
EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars)); EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
} }
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