Commit 24c08c4e by zmo@google.com

Fix the bug that long varying varibales are mapped into different names in fragment/vertex shaders.

ANGLEBUG=144 TEST=the same long varying variable name in fragment/vertex shaders map to the same shortened name if using the same translator. Review URL: http://codereview.appspot.com/4547063 git-svn-id: https://angleproject.googlecode.com/svn/trunk@660 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c4ee4272
#define MAJOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 659
#define BUILD_REVISION 660
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -207,7 +207,7 @@ void TCompiler::collectAttribsUniforms(TIntermNode* root)
void TCompiler::mapLongVariableNames(TIntermNode* root)
{
MapLongVariableNames map;
MapLongVariableNames map(varyingLongNameMap);
root->traverse(&map);
}
......
......@@ -8,22 +8,44 @@
namespace {
TString mapLongName(int id, const TString& name)
TString mapLongName(int id, const TString& name, bool isVarying)
{
ASSERT(name.size() > MAX_IDENTIFIER_NAME_SIZE);
TStringStream stream;
stream << "webgl_" << id << "_";
stream << "webgl_";
if (isVarying)
stream << "v";
stream << id << "_";
stream << name.substr(0, MAX_IDENTIFIER_NAME_SIZE - stream.str().size());
return stream.str();
}
} // anonymous namespace
MapLongVariableNames::MapLongVariableNames(
TMap<TString, TString>& varyingLongNameMap)
: mVaryingLongNameMap(varyingLongNameMap)
{
}
void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
{
ASSERT(symbol != NULL);
if (symbol->getSymbol().size() > MAX_IDENTIFIER_NAME_SIZE)
symbol->setSymbol(mapLongName(symbol->getId(), symbol->getSymbol()));
if (symbol->getSymbol().size() > MAX_IDENTIFIER_NAME_SIZE) {
switch (symbol->getQualifier()) {
case EvqVaryingIn:
case EvqVaryingOut:
case EvqInvariantVaryingIn:
case EvqInvariantVaryingOut:
symbol->setSymbol(
mapVaryingLongName(symbol->getSymbol()));
break;
default:
symbol->setSymbol(
mapLongName(symbol->getId(), symbol->getSymbol(), false));
break;
};
}
}
void MapLongVariableNames::visitConstantUnion(TIntermConstantUnion*)
......@@ -59,3 +81,16 @@ bool MapLongVariableNames::visitBranch(Visit, TIntermBranch*)
{
return true;
}
TString MapLongVariableNames::mapVaryingLongName(const TString& name)
{
TMap<TString, TString>::const_iterator it = mVaryingLongNameMap.find(name);
if (it != mVaryingLongNameMap.end())
return (*it).second;
int id = mVaryingLongNameMap.size();
TString mappedName = mapLongName(id, name, true);
mVaryingLongNameMap.insert(
TMap<TString, TString>::value_type(name, mappedName));
return mappedName;
}
......@@ -19,7 +19,7 @@
// longer than MAX_IDENTIFIER_NAME_SIZE to MAX_IDENTIFIER_NAME_SIZE.
class MapLongVariableNames : public TIntermTraverser {
public:
MapLongVariableNames() { }
MapLongVariableNames(TMap<TString, TString>& varyingLongNameMap);
virtual void visitSymbol(TIntermSymbol*);
virtual void visitConstantUnion(TIntermConstantUnion*);
......@@ -29,6 +29,11 @@ public:
virtual bool visitAggregate(Visit, TIntermAggregate*);
virtual bool visitLoop(Visit, TIntermLoop*);
virtual bool visitBranch(Visit, TIntermBranch*);
private:
TString mapVaryingLongName(const TString& name);
TMap<TString, TString>& mVaryingLongNameMap;
};
#endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_
......@@ -90,6 +90,9 @@ private:
TInfoSink infoSink; // Output sink.
TVariableInfoList attribs; // Active attributes in the compiled shader.
TVariableInfoList uniforms; // Active uniforms in the compiled shader.
// Pair of long varying varibale name <originalName, mappedName>.
TMap<TString, TString> varyingLongNameMap;
};
//
......
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