Commit 9996b8e6 by zmo@google.com

Rollback r942.

MapLongVariableNames inherits from TIntermTraverser, and TIntermTraverser uses ANGLE's memory allocator, thus the memory is released per compilation. Our design is for MapLongVariableNames to be a singleton across all compilations, thus, this is not working. BUG= TEST= TBR=kbr Review URL: https://codereview.appspot.com/5556053 git-svn-id: https://angleproject.googlecode.com/svn/trunk@949 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 2678b34b
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 948
#define BUILD_REVISION 949
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -89,15 +89,12 @@ TShHandleBase::~TShHandleBase() {
TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec)
: shaderType(type),
shaderSpec(spec),
builtInFunctionEmulator(type),
longNameMapper(NULL)
builtInFunctionEmulator(type)
{
}
TCompiler::~TCompiler()
{
if (longNameMapper)
longNameMapper->Release();
}
bool TCompiler::Init(const ShBuiltInResources& resources)
......@@ -249,9 +246,8 @@ void TCompiler::collectAttribsUniforms(TIntermNode* root)
void TCompiler::mapLongVariableNames(TIntermNode* root)
{
if (longNameMapper == NULL)
longNameMapper = MapLongVariableNames::GetInstance();
root->traverse(longNameMapper);
MapLongVariableNames map(varyingLongNameMap);
root->traverse(&map);
}
int TCompiler::getMappedNameMaxLength() const
......
......@@ -8,51 +8,26 @@
namespace {
TString mapLongName(int id, const TString& name, bool global)
TString mapLongName(int id, const TString& name, bool isVarying)
{
ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE);
TStringStream stream;
stream << "webgl_";
if (global)
stream << "g";
if (isVarying)
stream << "v";
stream << id << "_";
stream << name.substr(0, MAX_SHORTENED_IDENTIFIER_SIZE - stream.str().size());
return stream.str();
}
MapLongVariableNames* gMapLongVariableNamesInstance = NULL;
} // anonymous namespace
MapLongVariableNames::MapLongVariableNames()
: refCount(0)
{
}
MapLongVariableNames::~MapLongVariableNames()
MapLongVariableNames::MapLongVariableNames(
std::map<std::string, std::string>& varyingLongNameMap)
: mVaryingLongNameMap(varyingLongNameMap)
{
}
// 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)
{
ASSERT(symbol != NULL);
......@@ -64,7 +39,7 @@ void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
case EvqInvariantVaryingOut:
case EvqUniform:
symbol->setSymbol(
mapLongGlobalName(symbol->getSymbol()));
mapVaryingLongName(symbol->getSymbol()));
break;
default:
symbol->setSymbol(
......@@ -81,15 +56,15 @@ bool MapLongVariableNames::visitLoop(Visit, TIntermLoop* node)
return true;
}
TString MapLongVariableNames::mapLongGlobalName(const TString& name)
TString MapLongVariableNames::mapVaryingLongName(const TString& name)
{
std::map<std::string, std::string>::const_iterator it = longGlobalNameMap.find(name.c_str());
if (it != longGlobalNameMap.end())
std::map<std::string, std::string>::const_iterator it = mVaryingLongNameMap.find(name.c_str());
if (it != mVaryingLongNameMap.end())
return (*it).second.c_str();
int id = longGlobalNameMap.size();
int id = mVaryingLongNameMap.size();
TString mappedName = mapLongName(id, name, true);
longGlobalNameMap.insert(
mVaryingLongNameMap.insert(
std::map<std::string, std::string>::value_type(name.c_str(), mappedName.c_str()));
return mappedName;
}
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -15,30 +15,19 @@
// This size does not include '\0' in the end.
#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
// longer than MAX_SHORTENED_IDENTIFIER_SIZE to MAX_SHORTENED_IDENTIFIER_SIZE.
class MapLongVariableNames : public TIntermTraverser {
public:
static MapLongVariableNames* GetInstance();
void Release();
MapLongVariableNames(std::map<std::string, std::string>& varyingLongNameMap);
virtual void visitSymbol(TIntermSymbol*);
virtual bool visitLoop(Visit, TIntermLoop*);
private:
MapLongVariableNames();
virtual ~MapLongVariableNames();
TString mapLongGlobalName(const TString& name);
TString mapVaryingLongName(const TString& name);
// Pair of long global varibale name <originalName, mappedName>.
std::map<std::string, std::string> longGlobalNameMap;
size_t refCount;
std::map<std::string, std::string>& mVaryingLongNameMap;
};
#endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_
......@@ -22,7 +22,6 @@
#include "compiler/SymbolTable.h"
#include "compiler/VariableInfo.h"
class MapLongVariableNames;
class TCompiler;
//
......@@ -101,8 +100,8 @@ private:
TVariableInfoList attribs; // Active attributes in the compiled shader.
TVariableInfoList uniforms; // Active uniforms in the compiled shader.
// Local instance of the ref-counted singleton.
MapLongVariableNames* longNameMapper;
// Pair of long varying varibale name <originalName, mappedName>.
std::map<std::string, std::string> 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