Move ShaderVariables to common shared source.
Also move the block layout encoding utilities to the common folder.
The combined changes allow us to include the shader and block code
into both libGLESv2 and the translator separately. This in turn
fixes the Chromium component build, where we were calling internal
translator functions directly from libGLESv2.
BUG=angle:568
Change-Id: Ibcfa2c936a7c737ad515c10bd24061ff39ee5747
Reviewed-on: https://chromium-review.googlesource.com/192891
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index 1c51968..5ab101a 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -50,14 +50,14 @@
return subscript;
}
-void GetInputLayoutFromShader(const std::vector<sh::Attribute> &shaderAttributes, VertexFormat inputLayout[MAX_VERTEX_ATTRIBS])
+void GetInputLayoutFromShader(const std::vector<gl::Attribute> &shaderAttributes, VertexFormat inputLayout[MAX_VERTEX_ATTRIBS])
{
size_t layoutIndex = 0;
for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); attributeIndex++)
{
ASSERT(layoutIndex < MAX_VERTEX_ATTRIBS);
- const sh::Attribute &shaderAttr = shaderAttributes[attributeIndex];
+ const gl::Attribute &shaderAttr = shaderAttributes[attributeIndex];
if (shaderAttr.type != GL_NONE)
{
@@ -479,7 +479,7 @@
const int components = UniformComponentCount(targetUniformType);
const GLenum targetBoolType = UniformBoolVectorType(targetUniformType);
- Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
+ LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
targetUniform->dirty = true;
int elementCount = targetUniform->elementCount();
@@ -623,7 +623,7 @@
return false;
}
- Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
+ LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
targetUniform->dirty = true;
if (targetUniform->type != targetUniformType)
@@ -710,7 +710,7 @@
return false;
}
- Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
+ LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
targetUniform->dirty = true;
int elementCount = targetUniform->elementCount();
@@ -799,7 +799,7 @@
return false;
}
- Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
+ LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
// sized queries -- ensure the provided buffer is large enough
if (bufSize)
@@ -909,7 +909,7 @@
// Retrieve sampler uniform values
for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
{
- Uniform *targetUniform = mUniforms[uniformIndex];
+ LinkedUniform *targetUniform = mUniforms[uniformIndex];
if (targetUniform->dirty)
{
@@ -1008,17 +1008,17 @@
bool ProgramBinary::linkVaryings(InfoLog &infoLog, FragmentShader *fragmentShader, VertexShader *vertexShader)
{
- std::vector<sh::Varying> &fragmentVaryings = fragmentShader->getVaryings();
- std::vector<sh::Varying> &vertexVaryings = vertexShader->getVaryings();
+ std::vector<gl::Varying> &fragmentVaryings = fragmentShader->getVaryings();
+ std::vector<gl::Varying> &vertexVaryings = vertexShader->getVaryings();
for (size_t fragVaryingIndex = 0; fragVaryingIndex < fragmentVaryings.size(); fragVaryingIndex++)
{
- sh::Varying *input = &fragmentVaryings[fragVaryingIndex];
+ gl::Varying *input = &fragmentVaryings[fragVaryingIndex];
bool matched = false;
for (size_t vertVaryingIndex = 0; vertVaryingIndex < vertexVaryings.size(); vertVaryingIndex++)
{
- sh::Varying *output = &vertexVaryings[vertVaryingIndex];
+ gl::Varying *output = &vertexVaryings[vertVaryingIndex];
if (output->name == input->name)
{
if (!linkValidateVariables(infoLog, output->name, *input, *output))
@@ -1153,9 +1153,9 @@
stream.read(&matrixStride);
stream.read(&isRowMajorMatrix);
- const sh::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix);
+ const gl::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix);
- mUniforms[i] = new Uniform(type, precision, name, arraySize, blockIndex, blockInfo);
+ mUniforms[i] = new LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo);
stream.read(&mUniforms[i]->psRegisterIndex);
stream.read(&mUniforms[i]->vsRegisterIndex);
@@ -1355,7 +1355,7 @@
stream.write(mUniforms.size());
for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); ++uniformIndex)
{
- const Uniform &uniform = *mUniforms[uniformIndex];
+ const LinkedUniform &uniform = *mUniforms[uniformIndex];
stream.write(uniform.type);
stream.write(uniform.precision);
@@ -1527,7 +1527,7 @@
mVertexWorkarounds = vertexShader->getD3DWorkarounds();
// Map the varyings to the register file
- const sh::ShaderVariable *packing[IMPLEMENTATION_MAX_VARYING_VECTORS][4] = {NULL};
+ const gl::ShaderVariable *packing[IMPLEMENTATION_MAX_VARYING_VECTORS][4] = {NULL};
int registers = mDynamicHLSL->packVaryings(infoLog, packing, fragmentShader, vertexShader, transformFeedbackVaryings);
if (registers < 0)
@@ -1564,9 +1564,9 @@
// special case for gl_DepthRange, the only built-in uniform (also a struct)
if (vertexShader->usesDepthRange() || fragmentShader->usesDepthRange())
{
- mUniforms.push_back(new Uniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.near", 0, -1, sh::BlockMemberInfo::defaultBlockInfo));
- mUniforms.push_back(new Uniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.far", 0, -1, sh::BlockMemberInfo::defaultBlockInfo));
- mUniforms.push_back(new Uniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, sh::BlockMemberInfo::defaultBlockInfo));
+ mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.near", 0, -1, gl::BlockMemberInfo::defaultBlockInfo));
+ mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.far", 0, -1, gl::BlockMemberInfo::defaultBlockInfo));
+ mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, gl::BlockMemberInfo::defaultBlockInfo));
}
if (!linkUniformBlocks(infoLog, vertexShader->getInterfaceBlocks(), fragmentShader->getInterfaceBlocks()))
@@ -1625,12 +1625,12 @@
bool ProgramBinary::linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader)
{
unsigned int usedLocations = 0;
- const std::vector<sh::Attribute> &activeAttributes = vertexShader->activeAttributes();
+ const std::vector<gl::Attribute> &activeAttributes = vertexShader->activeAttributes();
// Link attributes that have a binding location
for (unsigned int attributeIndex = 0; attributeIndex < activeAttributes.size(); attributeIndex++)
{
- const sh::Attribute &attribute = activeAttributes[attributeIndex];
+ const gl::Attribute &attribute = activeAttributes[attributeIndex];
const int location = attribute.location == -1 ? attributeBindings.getAttributeBinding(attribute.name) : attribute.location;
mShaderAttributes[attributeIndex] = attribute;
@@ -1649,7 +1649,7 @@
for (int row = 0; row < rows; row++)
{
const int rowLocation = location + row;
- sh::ShaderVariable &linkedAttribute = mLinkedAttribute[rowLocation];
+ gl::ShaderVariable &linkedAttribute = mLinkedAttribute[rowLocation];
// In GLSL 3.00, attribute aliasing produces a link error
// In GLSL 1.00, attribute aliasing is allowed
@@ -1671,7 +1671,7 @@
// Link attributes that don't have a binding location
for (unsigned int attributeIndex = 0; attributeIndex < activeAttributes.size(); attributeIndex++)
{
- const sh::Attribute &attribute = activeAttributes[attributeIndex];
+ const gl::Attribute &attribute = activeAttributes[attributeIndex];
const int location = attribute.location == -1 ? attributeBindings.getAttributeBinding(attribute.name) : attribute.location;
if (location == -1) // Not set by glBindAttribLocation or by location layout qualifier
@@ -1706,7 +1706,7 @@
return true;
}
-bool ProgramBinary::linkValidateVariablesBase(InfoLog &infoLog, const std::string &variableName, const sh::ShaderVariable &vertexVariable, const sh::ShaderVariable &fragmentVariable, bool validatePrecision)
+bool ProgramBinary::linkValidateVariablesBase(InfoLog &infoLog, const std::string &variableName, const gl::ShaderVariable &vertexVariable, const gl::ShaderVariable &fragmentVariable, bool validatePrecision)
{
if (vertexVariable.type != fragmentVariable.type)
{
@@ -1758,14 +1758,14 @@
return true;
}
-bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform)
+bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &uniformName, const gl::Uniform &vertexUniform, const gl::Uniform &fragmentUniform)
{
if (!linkValidateVariablesBase(infoLog, uniformName, vertexUniform, fragmentUniform, true))
{
return false;
}
- if (!linkValidateFields<sh::Uniform>(infoLog, uniformName, vertexUniform, fragmentUniform))
+ if (!linkValidateFields<gl::Uniform>(infoLog, uniformName, vertexUniform, fragmentUniform))
{
return false;
}
@@ -1773,7 +1773,7 @@
return true;
}
-bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying)
+bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &varyingName, const gl::Varying &vertexVarying, const gl::Varying &fragmentVarying)
{
if (!linkValidateVariablesBase(infoLog, varyingName, vertexVarying, fragmentVarying, false))
{
@@ -1786,7 +1786,7 @@
return false;
}
- if (!linkValidateFields<sh::Varying>(infoLog, varyingName, vertexVarying, fragmentVarying))
+ if (!linkValidateFields<gl::Varying>(infoLog, varyingName, vertexVarying, fragmentVarying))
{
return false;
}
@@ -1794,7 +1794,7 @@
return true;
}
-bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform)
+bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &uniformName, const gl::InterfaceBlockField &vertexUniform, const gl::InterfaceBlockField &fragmentUniform)
{
if (!linkValidateVariablesBase(infoLog, uniformName, vertexUniform, fragmentUniform, true))
{
@@ -1807,7 +1807,7 @@
return false;
}
- if (!linkValidateFields<sh::InterfaceBlockField>(infoLog, uniformName, vertexUniform, fragmentUniform))
+ if (!linkValidateFields<gl::InterfaceBlockField>(infoLog, uniformName, vertexUniform, fragmentUniform))
{
return false;
}
@@ -1815,25 +1815,25 @@
return true;
}
-bool ProgramBinary::linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform> &vertexUniforms, const std::vector<sh::Uniform> &fragmentUniforms)
+bool ProgramBinary::linkUniforms(InfoLog &infoLog, const std::vector<gl::Uniform> &vertexUniforms, const std::vector<gl::Uniform> &fragmentUniforms)
{
// Check that uniforms defined in the vertex and fragment shaders are identical
- typedef std::map<std::string, const sh::Uniform*> UniformMap;
+ typedef std::map<std::string, const gl::Uniform*> UniformMap;
UniformMap linkedUniforms;
for (unsigned int vertexUniformIndex = 0; vertexUniformIndex < vertexUniforms.size(); vertexUniformIndex++)
{
- const sh::Uniform &vertexUniform = vertexUniforms[vertexUniformIndex];
+ const gl::Uniform &vertexUniform = vertexUniforms[vertexUniformIndex];
linkedUniforms[vertexUniform.name] = &vertexUniform;
}
for (unsigned int fragmentUniformIndex = 0; fragmentUniformIndex < fragmentUniforms.size(); fragmentUniformIndex++)
{
- const sh::Uniform &fragmentUniform = fragmentUniforms[fragmentUniformIndex];
+ const gl::Uniform &fragmentUniform = fragmentUniforms[fragmentUniformIndex];
UniformMap::const_iterator entry = linkedUniforms.find(fragmentUniform.name);
if (entry != linkedUniforms.end())
{
- const sh::Uniform &vertexUniform = *entry->second;
+ const gl::Uniform &vertexUniform = *entry->second;
const std::string &uniformName = "uniform '" + vertexUniform.name + "'";
if (!linkValidateVariables(infoLog, uniformName, vertexUniform, fragmentUniform))
{
@@ -1863,7 +1863,7 @@
return true;
}
-int totalRegisterCount(const sh::Uniform &uniform)
+int totalRegisterCount(const gl::Uniform &uniform)
{
int registerCount = 0;
@@ -1912,7 +1912,7 @@
return TEXTURE_2D;
}
-bool ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog)
+bool ProgramBinary::defineUniform(GLenum shader, const gl::Uniform &constant, InfoLog &infoLog)
{
if (constant.isStruct())
{
@@ -1924,9 +1924,9 @@
{
for (size_t fieldIndex = 0; fieldIndex < constant.fields.size(); fieldIndex++)
{
- const sh::Uniform &field = constant.fields[fieldIndex];
+ const gl::Uniform &field = constant.fields[fieldIndex];
const std::string &uniformName = constant.name + ArrayString(elementIndex) + "." + field.name;
- sh::Uniform fieldUniform(field.type, field.precision, uniformName.c_str(), field.arraySize,
+ gl::Uniform fieldUniform(field.type, field.precision, uniformName.c_str(), field.arraySize,
elementRegisterIndex, field.elementIndex);
fieldUniform.fields = field.fields;
@@ -1942,10 +1942,10 @@
{
for (size_t fieldIndex = 0; fieldIndex < constant.fields.size(); fieldIndex++)
{
- const sh::Uniform &field = constant.fields[fieldIndex];
+ const gl::Uniform &field = constant.fields[fieldIndex];
const std::string &uniformName = constant.name + "." + field.name;
- sh::Uniform fieldUniform(field.type, field.precision, uniformName.c_str(), field.arraySize,
+ gl::Uniform fieldUniform(field.type, field.precision, uniformName.c_str(), field.arraySize,
field.registerIndex, field.elementIndex);
fieldUniform.fields = field.fields;
@@ -2003,7 +2003,7 @@
while (samplerIndex < constant.registerIndex + constant.arraySize);
}
- Uniform *uniform = NULL;
+ LinkedUniform *uniform = NULL;
GLint location = getUniformLocation(constant.name);
if (location >= 0) // Previously defined, type and precision must match
@@ -2012,7 +2012,7 @@
}
else
{
- uniform = new Uniform(constant.type, constant.precision, constant.name, constant.arraySize, -1, sh::BlockMemberInfo::defaultBlockInfo);
+ uniform = new LinkedUniform(constant.type, constant.precision, constant.name, constant.arraySize, -1, gl::BlockMemberInfo::defaultBlockInfo);
uniform->registerElement = constant.elementIndex;
}
@@ -2065,7 +2065,7 @@
return true;
}
-bool ProgramBinary::areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, const sh::InterfaceBlock &fragmentInterfaceBlock)
+bool ProgramBinary::areMatchingInterfaceBlocks(InfoLog &infoLog, const gl::InterfaceBlock &vertexInterfaceBlock, const gl::InterfaceBlock &fragmentInterfaceBlock)
{
const char* blockName = vertexInterfaceBlock.name.c_str();
@@ -2091,8 +2091,8 @@
const unsigned int numBlockMembers = vertexInterfaceBlock.fields.size();
for (unsigned int blockMemberIndex = 0; blockMemberIndex < numBlockMembers; blockMemberIndex++)
{
- const sh::InterfaceBlockField &vertexMember = vertexInterfaceBlock.fields[blockMemberIndex];
- const sh::InterfaceBlockField &fragmentMember = fragmentInterfaceBlock.fields[blockMemberIndex];
+ const gl::InterfaceBlockField &vertexMember = vertexInterfaceBlock.fields[blockMemberIndex];
+ const gl::InterfaceBlockField &fragmentMember = fragmentInterfaceBlock.fields[blockMemberIndex];
if (vertexMember.name != fragmentMember.name)
{
@@ -2111,25 +2111,26 @@
return true;
}
-bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const sh::ActiveInterfaceBlocks &vertexInterfaceBlocks, const sh::ActiveInterfaceBlocks &fragmentInterfaceBlocks)
+bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const std::vector<gl::InterfaceBlock> &vertexInterfaceBlocks,
+ const std::vector<gl::InterfaceBlock> &fragmentInterfaceBlocks)
{
// Check that interface blocks defined in the vertex and fragment shaders are identical
- typedef std::map<std::string, const sh::InterfaceBlock*> UniformBlockMap;
+ typedef std::map<std::string, const gl::InterfaceBlock*> UniformBlockMap;
UniformBlockMap linkedUniformBlocks;
for (unsigned int blockIndex = 0; blockIndex < vertexInterfaceBlocks.size(); blockIndex++)
{
- const sh::InterfaceBlock &vertexInterfaceBlock = vertexInterfaceBlocks[blockIndex];
+ const gl::InterfaceBlock &vertexInterfaceBlock = vertexInterfaceBlocks[blockIndex];
linkedUniformBlocks[vertexInterfaceBlock.name] = &vertexInterfaceBlock;
}
for (unsigned int blockIndex = 0; blockIndex < fragmentInterfaceBlocks.size(); blockIndex++)
{
- const sh::InterfaceBlock &fragmentInterfaceBlock = fragmentInterfaceBlocks[blockIndex];
+ const gl::InterfaceBlock &fragmentInterfaceBlock = fragmentInterfaceBlocks[blockIndex];
UniformBlockMap::const_iterator entry = linkedUniformBlocks.find(fragmentInterfaceBlock.name);
if (entry != linkedUniformBlocks.end())
{
- const sh::InterfaceBlock &vertexInterfaceBlock = *entry->second;
+ const gl::InterfaceBlock &vertexInterfaceBlock = *entry->second;
if (!areMatchingInterfaceBlocks(infoLog, vertexInterfaceBlock, fragmentInterfaceBlock))
{
return false;
@@ -2214,11 +2215,11 @@
return true;
}
-void ProgramBinary::defineUniformBlockMembers(const std::vector<sh::InterfaceBlockField> &fields, const std::string &prefix, int blockIndex, BlockInfoItr *blockInfoItr, std::vector<unsigned int> *blockUniformIndexes)
+void ProgramBinary::defineUniformBlockMembers(const std::vector<gl::InterfaceBlockField> &fields, const std::string &prefix, int blockIndex, BlockInfoItr *blockInfoItr, std::vector<unsigned int> *blockUniformIndexes)
{
for (unsigned int uniformIndex = 0; uniformIndex < fields.size(); uniformIndex++)
{
- const sh::InterfaceBlockField &field = fields[uniformIndex];
+ const gl::InterfaceBlockField &field = fields[uniformIndex];
const std::string &fieldName = (prefix.empty() ? field.name : prefix + "." + field.name);
if (!field.fields.empty())
@@ -2238,8 +2239,8 @@
}
else
{
- Uniform *newUniform = new Uniform(field.type, field.precision, fieldName, field.arraySize,
- blockIndex, **blockInfoItr);
+ LinkedUniform *newUniform = new LinkedUniform(field.type, field.precision, fieldName, field.arraySize,
+ blockIndex, **blockInfoItr);
// add to uniform list, but not index, since uniform block uniforms have no location
blockUniformIndexes->push_back(mUniforms.size());
@@ -2249,7 +2250,7 @@
}
}
-bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, GLenum shader, const sh::InterfaceBlock &interfaceBlock)
+bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, GLenum shader, const gl::InterfaceBlock &interfaceBlock)
{
// create uniform block entries if they do not exist
if (getUniformBlockIndex(interfaceBlock.name) == GL_INVALID_INDEX)
@@ -2456,7 +2457,7 @@
GLint ProgramBinary::getActiveUniformi(GLuint index, GLenum pname) const
{
- const gl::Uniform& uniform = *mUniforms[index];
+ const gl::LinkedUniform& uniform = *mUniforms[index];
switch (pname)
{
@@ -2719,7 +2720,7 @@
unsigned int fragmentRegisters = 0;
for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
{
- const Uniform &uniform = *mUniforms[uniformIndex];
+ const LinkedUniform &uniform = *mUniforms[uniformIndex];
if (!IsSampler(uniform.type))
{