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