Commit 4625d27b by zmo@google.com

Long name mapping needs to be consistent between vertex/fragment shaders.

For example: varying variables, uniforms. This CL makes MapLongVariableNames a ref-counted singleton and therefore, the map is shared by all shaders. Also, function/variable names changes from Varying to Global because uniforms also need to be consistent, not just varying variables. ANGLEBUG=279 TEST=webgl conformance tests, especially invalid-passed-params.html and glsl-long-variable-names.html Review URL: http://codereview.appspot.com/5539046 git-svn-id: https://angleproject.googlecode.com/svn/trunk@942 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent f289ee8d
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 941 #define BUILD_REVISION 942
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
// //
// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -89,12 +89,15 @@ TShHandleBase::~TShHandleBase() { ...@@ -89,12 +89,15 @@ TShHandleBase::~TShHandleBase() {
TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec) TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec)
: shaderType(type), : shaderType(type),
shaderSpec(spec), shaderSpec(spec),
builtInFunctionEmulator(type) builtInFunctionEmulator(type),
longNameMapper(NULL)
{ {
} }
TCompiler::~TCompiler() TCompiler::~TCompiler()
{ {
if (longNameMapper)
longNameMapper->Release();
} }
bool TCompiler::Init(const ShBuiltInResources& resources) bool TCompiler::Init(const ShBuiltInResources& resources)
...@@ -246,8 +249,9 @@ void TCompiler::collectAttribsUniforms(TIntermNode* root) ...@@ -246,8 +249,9 @@ void TCompiler::collectAttribsUniforms(TIntermNode* root)
void TCompiler::mapLongVariableNames(TIntermNode* root) void TCompiler::mapLongVariableNames(TIntermNode* root)
{ {
MapLongVariableNames map(varyingLongNameMap); if (longNameMapper == NULL)
root->traverse(&map); longNameMapper = MapLongVariableNames::GetInstance();
root->traverse(longNameMapper);
} }
int TCompiler::getMappedNameMaxLength() const int TCompiler::getMappedNameMaxLength() const
......
...@@ -8,26 +8,51 @@ ...@@ -8,26 +8,51 @@
namespace { namespace {
TString mapLongName(int id, const TString& name, bool isVarying) TString mapLongName(int id, const TString& name, bool global)
{ {
ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE); ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE);
TStringStream stream; TStringStream stream;
stream << "webgl_"; stream << "webgl_";
if (isVarying) if (global)
stream << "v"; stream << "g";
stream << id << "_"; stream << id << "_";
stream << name.substr(0, MAX_SHORTENED_IDENTIFIER_SIZE - stream.str().size()); stream << name.substr(0, MAX_SHORTENED_IDENTIFIER_SIZE - stream.str().size());
return stream.str(); return stream.str();
} }
MapLongVariableNames* gMapLongVariableNamesInstance = NULL;
} // anonymous namespace } // anonymous namespace
MapLongVariableNames::MapLongVariableNames( MapLongVariableNames::MapLongVariableNames()
std::map<std::string, std::string>& varyingLongNameMap) : refCount(0)
: mVaryingLongNameMap(varyingLongNameMap) {
}
MapLongVariableNames::~MapLongVariableNames()
{ {
} }
// static
MapLongVariableNames* MapLongVariableNames::GetInstance()
{
if (gMapLongVariableNamesInstance == NULL)
gMapLongVariableNamesInstance = new MapLongVariableNames;
gMapLongVariableNamesInstance->refCount++;
return gMapLongVariableNamesInstance;
}
void MapLongVariableNames::Release()
{
ASSERT(gMapLongVariableNamesInstance == this);
ASSERT(refCount > 0);
refCount--;
if (refCount == 0) {
delete gMapLongVariableNamesInstance;
gMapLongVariableNamesInstance = NULL;
}
}
void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol) void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
{ {
ASSERT(symbol != NULL); ASSERT(symbol != NULL);
...@@ -39,7 +64,7 @@ void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol) ...@@ -39,7 +64,7 @@ void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
case EvqInvariantVaryingOut: case EvqInvariantVaryingOut:
case EvqUniform: case EvqUniform:
symbol->setSymbol( symbol->setSymbol(
mapVaryingLongName(symbol->getSymbol())); mapLongGlobalName(symbol->getSymbol()));
break; break;
default: default:
symbol->setSymbol( symbol->setSymbol(
...@@ -56,15 +81,15 @@ bool MapLongVariableNames::visitLoop(Visit, TIntermLoop* node) ...@@ -56,15 +81,15 @@ bool MapLongVariableNames::visitLoop(Visit, TIntermLoop* node)
return true; return true;
} }
TString MapLongVariableNames::mapVaryingLongName(const TString& name) TString MapLongVariableNames::mapLongGlobalName(const TString& name)
{ {
std::map<std::string, std::string>::const_iterator it = mVaryingLongNameMap.find(name.c_str()); std::map<std::string, std::string>::const_iterator it = longGlobalNameMap.find(name.c_str());
if (it != mVaryingLongNameMap.end()) if (it != longGlobalNameMap.end())
return (*it).second.c_str(); return (*it).second.c_str();
int id = mVaryingLongNameMap.size(); int id = longGlobalNameMap.size();
TString mappedName = mapLongName(id, name, true); TString mappedName = mapLongName(id, name, true);
mVaryingLongNameMap.insert( longGlobalNameMap.insert(
std::map<std::string, std::string>::value_type(name.c_str(), mappedName.c_str())); std::map<std::string, std::string>::value_type(name.c_str(), mappedName.c_str()));
return mappedName; return mappedName;
} }
// //
// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -15,19 +15,30 @@ ...@@ -15,19 +15,30 @@
// This size does not include '\0' in the end. // This size does not include '\0' in the end.
#define MAX_SHORTENED_IDENTIFIER_SIZE 32 #define MAX_SHORTENED_IDENTIFIER_SIZE 32
// MapLongVariableNames is implemented as a ref-counted singleton. The first
// call of GetInstance() will create an instance and return it; latter calls
// will return the same instance, with ref-count increased. Release() will
// reduce the ref-count, and when no more reference, release the instance.
// Traverses intermediate tree to map attributes and uniforms names that are // Traverses intermediate tree to map attributes and uniforms names that are
// longer than MAX_SHORTENED_IDENTIFIER_SIZE to MAX_SHORTENED_IDENTIFIER_SIZE. // longer than MAX_SHORTENED_IDENTIFIER_SIZE to MAX_SHORTENED_IDENTIFIER_SIZE.
class MapLongVariableNames : public TIntermTraverser { class MapLongVariableNames : public TIntermTraverser {
public: public:
MapLongVariableNames(std::map<std::string, std::string>& varyingLongNameMap); static MapLongVariableNames* GetInstance();
void Release();
virtual void visitSymbol(TIntermSymbol*); virtual void visitSymbol(TIntermSymbol*);
virtual bool visitLoop(Visit, TIntermLoop*); virtual bool visitLoop(Visit, TIntermLoop*);
private: private:
TString mapVaryingLongName(const TString& name); MapLongVariableNames();
virtual ~MapLongVariableNames();
TString mapLongGlobalName(const TString& name);
std::map<std::string, std::string>& mVaryingLongNameMap; // Pair of long global varibale name <originalName, mappedName>.
std::map<std::string, std::string> longGlobalNameMap;
size_t refCount;
}; };
#endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_ #endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "compiler/SymbolTable.h" #include "compiler/SymbolTable.h"
#include "compiler/VariableInfo.h" #include "compiler/VariableInfo.h"
class MapLongVariableNames;
class TCompiler; class TCompiler;
// //
...@@ -100,8 +101,8 @@ private: ...@@ -100,8 +101,8 @@ private:
TVariableInfoList attribs; // Active attributes in the compiled shader. TVariableInfoList attribs; // Active attributes in the compiled shader.
TVariableInfoList uniforms; // Active uniforms in the compiled shader. TVariableInfoList uniforms; // Active uniforms in the compiled shader.
// Pair of long varying varibale name <originalName, mappedName>. // Local instance of the ref-counted singleton.
std::map<std::string, std::string> varyingLongNameMap; MapLongVariableNames* longNameMapper;
}; };
// //
......
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