diff --git a/include/GLSLANG/ShaderLang.h b/include/GLSLANG/ShaderLang.h index 255a52a16..314768693 100644 --- a/include/GLSLANG/ShaderLang.h +++ b/include/GLSLANG/ShaderLang.h @@ -168,16 +168,15 @@ typedef enum { SH_VARIABLES = 0x0008, SH_LINE_DIRECTIVES = 0x0010, SH_SOURCE_PATH = 0x0020, - SH_MAP_LONG_VARIABLE_NAMES = 0x0040, - SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX = 0x0080, + SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX = 0x0040, // If a sampler array index happens to be a loop index, // 1) if its type is integer, unroll the loop. // 2) if its type is float, fail the shader compile. // This is to work around a mac driver bug. - SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX = 0x0100, + SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX = 0x0080, // This is needed only as a workaround for certain OpenGL driver bugs. - SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0200, + SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0100, // This is an experimental flag to enforce restrictions that aim to prevent // timing attacks. @@ -185,7 +184,7 @@ typedef enum { // texture information via the timing channel. // To use this flag, you must compile the shader under the WebGL spec // (using the SH_WEBGL_SPEC flag). - SH_TIMING_RESTRICTIONS = 0x0400, + SH_TIMING_RESTRICTIONS = 0x0200, // This flag prints the dependency graph that is used to enforce timing // restrictions on fragment shaders. @@ -193,7 +192,7 @@ typedef enum { // - The shader spec is SH_WEBGL_SPEC. // - The compile options contain the SH_TIMING_RESTRICTIONS flag. // - The shader type is SH_FRAGMENT_SHADER. - SH_DEPENDENCY_GRAPH = 0x0800, + SH_DEPENDENCY_GRAPH = 0x0400, // Enforce the GLSL 1.017 Appendix A section 7 packing restrictions. // This flag only enforces (and can only enforce) the packing @@ -201,7 +200,7 @@ typedef enum { // shaders. ShCheckVariablesWithinPackingLimits() lets embedders // enforce the packing restrictions for varying variables during // program link time. - SH_ENFORCE_PACKING_RESTRICTIONS = 0x1000, + SH_ENFORCE_PACKING_RESTRICTIONS = 0x0800, // This flag ensures all indirect (expression-based) array indexing // is clamped to the bounds of the array. This ensures, for example, @@ -209,32 +208,32 @@ typedef enum { // vec234, or mat234 type. The ShArrayIndexClampingStrategy enum, // specified in the ShBuiltInResources when constructing the // compiler, selects the strategy for the clamping implementation. - SH_CLAMP_INDIRECT_ARRAY_BOUNDS = 0x2000, + SH_CLAMP_INDIRECT_ARRAY_BOUNDS = 0x1000, // This flag limits the complexity of an expression. - SH_LIMIT_EXPRESSION_COMPLEXITY = 0x4000, + SH_LIMIT_EXPRESSION_COMPLEXITY = 0x2000, // This flag limits the depth of the call stack. - SH_LIMIT_CALL_STACK_DEPTH = 0x8000, + SH_LIMIT_CALL_STACK_DEPTH = 0x4000, // This flag initializes gl_Position to vec4(0,0,0,0) at the // beginning of the vertex shader's main(), and has no effect in the // fragment shader. It is intended as a workaround for drivers which // incorrectly fail to link programs if gl_Position is not written. - SH_INIT_GL_POSITION = 0x10000, + SH_INIT_GL_POSITION = 0x8000, // This flag replaces // "a && b" with "a ? b : false", // "a || b" with "a ? true : b". // This is to work around a MacOSX driver bug that |b| is executed // independent of |a|'s value. - SH_UNFOLD_SHORT_CIRCUIT = 0x20000, + SH_UNFOLD_SHORT_CIRCUIT = 0x10000, // This flag initializes varyings without static use in vertex shader // at the beginning of main(), and has no effects in the fragment shader. // It is intended as a workaround for drivers which incorrectly optimize // out such varyings and cause a link failure. - SH_INIT_VARYINGS_WITHOUT_STATIC_USE = 0x40000, + SH_INIT_VARYINGS_WITHOUT_STATIC_USE = 0x20000, } ShCompileOptions; // Defines alternate strategies for implementing array index clamping. diff --git a/samples/translator/translator.cpp b/samples/translator/translator.cpp index a22a17909..f80e76413 100644 --- a/samples/translator/translator.cpp +++ b/samples/translator/translator.cpp @@ -81,7 +81,6 @@ int main(int argc, char* argv[]) if (argv[0][0] == '-') { switch (argv[0][1]) { case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break; - case 'm': compileOptions |= SH_MAP_LONG_VARIABLE_NAMES; break; case 'o': compileOptions |= SH_OBJECT_CODE; break; case 'u': compileOptions |= SH_VARIABLES; break; case 'l': compileOptions |= SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX; break; @@ -174,12 +173,12 @@ int main(int argc, char* argv[]) } if (compiled && (compileOptions & SH_VARIABLES)) { LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); - PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES, (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) != 0); + PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES); LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); printf("\n\n"); LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE UNIFORMS"); - PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS, (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) != 0); + PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS); LogMsg("END", "COMPILER", numCompiles, "ACTIVE UNIFORMS"); printf("\n\n"); } @@ -280,7 +279,7 @@ void LogMsg(const char* msg, const char* name, const int num, const char* logNam printf("#### %s %s %d %s ####\n", msg, name, num, logName); } -void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType, bool mapLongVariableNames) +void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType) { size_t nameSize = 0; switch (varType) { @@ -295,13 +294,6 @@ void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType, bool mapLongV if (nameSize <= 1) return; char* name = new char[nameSize]; - char* mappedName = NULL; - if (mapLongVariableNames) { - size_t mappedNameSize = 0; - ShGetInfo(compiler, SH_MAPPED_NAME_MAX_LENGTH, &mappedNameSize); - mappedName = new char[mappedNameSize]; - } - size_t activeVars = 0; int size = 0; ShDataType type = SH_NONE; @@ -312,10 +304,10 @@ void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType, bool mapLongV for (size_t i = 0; i < activeVars; ++i) { switch (varType) { case SH_ACTIVE_ATTRIBUTES: - ShGetVariableInfo(compiler, SH_ACTIVE_ATTRIBUTES, static_cast(i), NULL, &size, &type, &precision, &staticUse, name, mappedName); + ShGetVariableInfo(compiler, SH_ACTIVE_ATTRIBUTES, static_cast(i), NULL, &size, &type, &precision, &staticUse, name, NULL); break; case SH_ACTIVE_UNIFORMS: - ShGetVariableInfo(compiler, SH_ACTIVE_UNIFORMS, static_cast(i), NULL, &size, &type, &precision, &staticUse, name, mappedName); + ShGetVariableInfo(compiler, SH_ACTIVE_UNIFORMS, static_cast(i), NULL, &size, &type, &precision, &staticUse, name, NULL); break; default: assert(0); } @@ -350,14 +342,9 @@ void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType, bool mapLongV case SH_SAMPLER_EXTERNAL_OES: typeName = "GL_SAMPLER_EXTERNAL_OES"; break; default: assert(0); } - printf("%lu: name:%s type:%s size:%d", i, name, typeName, size); - if (mapLongVariableNames) - printf(" mapped name:%s", mappedName); - printf("\n"); + printf("%lu: name:%s type:%s size:%d\n", i, name, typeName, size); } delete [] name; - if (mappedName) - delete [] mappedName; } static bool ReadShaderSource(const char* fileName, ShaderSource& source) { diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp index 9b920a238..a42ef6205 100644 --- a/src/compiler/translator/Compiler.cpp +++ b/src/compiler/translator/Compiler.cpp @@ -10,7 +10,6 @@ #include "compiler/translator/Initialize.h" #include "compiler/translator/InitializeParseContext.h" #include "compiler/translator/InitializeVariables.h" -#include "compiler/translator/MapLongVariableNames.h" #include "compiler/translator/ParseContext.h" #include "compiler/translator/RenameFunction.h" #include "compiler/translator/ShHandle.h" @@ -104,13 +103,10 @@ TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec) clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC), builtInFunctionEmulator(type) { - longNameMap = LongNameMap::GetInstance(); } TCompiler::~TCompiler() { - ASSERT(longNameMap); - longNameMap->Release(); } bool TCompiler::Init(const ShBuiltInResources& resources) @@ -201,13 +197,13 @@ bool TCompiler::compile(const char* const shaderStrings[], // Unroll for-loop markup needs to happen after validateLimitations pass. if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX)) - { - ForLoopUnrollMarker marker(ForLoopUnrollMarker::kIntegerIndex); + { + ForLoopUnrollMarker marker(ForLoopUnrollMarker::kIntegerIndex); root->traverse(&marker); } if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX)) - { - ForLoopUnrollMarker marker(ForLoopUnrollMarker::kSamplerArrayIndex); + { + ForLoopUnrollMarker marker(ForLoopUnrollMarker::kSamplerArrayIndex); root->traverse(&marker); if (marker.samplerArrayIndexIsFloatLoopIndex()) { @@ -229,13 +225,6 @@ bool TCompiler::compile(const char* const shaderStrings[], if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY)) success = limitExpressionComplexity(root); - // Call mapLongVariableNames() before collectAttribsUniforms() so in - // collectAttribsUniforms() we already have the mapped symbol names and - // we could composite mapped and original variable names. - // Also, if we hash all the names, then no need to do this for long names. - if (success && (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) && hashFunction == NULL) - mapLongVariableNames(root); - if (success && shaderType == SH_VERTEX_SHADER && (compileOptions & SH_INIT_GL_POSITION)) initializeGLPosition(root); @@ -535,18 +524,6 @@ void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root) root->traverse(&initializer); } -void TCompiler::mapLongVariableNames(TIntermNode* root) -{ - ASSERT(longNameMap); - MapLongVariableNames map(longNameMap); - root->traverse(&map); -} - -int TCompiler::getMappedNameMaxLength() const -{ - return MAX_SHORTENED_IDENTIFIER_SIZE + 1; -} - const TExtensionBehavior& TCompiler::getExtensionBehavior() const { return extensionBehavior; diff --git a/src/compiler/translator/MapLongVariableNames.cpp b/src/compiler/translator/MapLongVariableNames.cpp deleted file mode 100644 index ef629c26b..000000000 --- a/src/compiler/translator/MapLongVariableNames.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// -// 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 -// found in the LICENSE file. -// - -#include "compiler/translator/MapLongVariableNames.h" - -namespace { - -TString mapLongName(size_t id, const TString& name, bool isGlobal) -{ - ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE); - TStringStream stream; - stream << "webgl_"; - if (isGlobal) - stream << "g"; - stream << id; - if (name[0] != '_') - stream << "_"; - stream << name.substr(0, MAX_SHORTENED_IDENTIFIER_SIZE - stream.str().size()); - return stream.str(); -} - -LongNameMap* gLongNameMapInstance = NULL; - -} // anonymous namespace - -LongNameMap::LongNameMap() - : refCount(0) -{ -} - -LongNameMap::~LongNameMap() -{ -} - -// static -LongNameMap* LongNameMap::GetInstance() -{ - if (gLongNameMapInstance == NULL) - gLongNameMapInstance = new LongNameMap; - gLongNameMapInstance->refCount++; - return gLongNameMapInstance; -} - -void LongNameMap::Release() -{ - ASSERT(gLongNameMapInstance == this); - ASSERT(refCount > 0); - refCount--; - if (refCount == 0) { - delete gLongNameMapInstance; - gLongNameMapInstance = NULL; - } -} - -const char* LongNameMap::Find(const char* originalName) const -{ - std::map::const_iterator it = mLongNameMap.find( - originalName); - if (it != mLongNameMap.end()) - return (*it).second.c_str(); - return NULL; -} - -void LongNameMap::Insert(const char* originalName, const char* mappedName) -{ - mLongNameMap.insert(std::map::value_type( - originalName, mappedName)); -} - -size_t LongNameMap::Size() const -{ - return mLongNameMap.size(); -} - -MapLongVariableNames::MapLongVariableNames(LongNameMap* globalMap) -{ - ASSERT(globalMap); - mGlobalMap = globalMap; -} - -void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol) -{ - ASSERT(symbol != NULL); - if (symbol->getSymbol().size() > MAX_SHORTENED_IDENTIFIER_SIZE) { - switch (symbol->getQualifier()) { - case EvqVaryingIn: - case EvqVaryingOut: - case EvqInvariantVaryingIn: - case EvqInvariantVaryingOut: - case EvqUniform: - symbol->setSymbol( - mapGlobalLongName(symbol->getSymbol())); - break; - default: - symbol->setSymbol( - mapLongName(symbol->getId(), symbol->getSymbol(), false)); - break; - }; - } -} - -TString MapLongVariableNames::mapGlobalLongName(const TString& name) -{ - ASSERT(mGlobalMap); - const char* mappedName = mGlobalMap->Find(name.c_str()); - if (mappedName != NULL) - return mappedName; - size_t id = mGlobalMap->Size(); - TString rt = mapLongName(id, name, true); - mGlobalMap->Insert(name.c_str(), rt.c_str()); - return rt; -} diff --git a/src/compiler/translator/MapLongVariableNames.h b/src/compiler/translator/MapLongVariableNames.h deleted file mode 100644 index 3b085a368..000000000 --- a/src/compiler/translator/MapLongVariableNames.h +++ /dev/null @@ -1,58 +0,0 @@ -// -// 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 -// found in the LICENSE file. -// - -#ifndef COMPILER_MAP_LONG_VARIABLE_NAMES_H_ -#define COMPILER_MAP_LONG_VARIABLE_NAMES_H_ - -#include "GLSLANG/ShaderLang.h" - -#include "compiler/translator/intermediate.h" -#include "compiler/translator/VariableInfo.h" - -// This size does not include '\0' in the end. -#define MAX_SHORTENED_IDENTIFIER_SIZE 32 - -// This is a ref-counted singleton. GetInstance() returns a pointer to the -// singleton, and after use, call Release(). GetInstance() and Release() should -// be paired. -class LongNameMap { -public: - static LongNameMap* GetInstance(); - void Release(); - - // Return the mapped name if is in the map; - // otherwise, return NULL. - const char* Find(const char* originalName) const; - - // Insert a pair into the map. - void Insert(const char* originalName, const char* mappedName); - - // Return the number of entries in the map. - size_t Size() const; - -private: - LongNameMap(); - ~LongNameMap(); - - size_t refCount; - std::map mLongNameMap; -}; - -// 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: - MapLongVariableNames(LongNameMap* globalMap); - - virtual void visitSymbol(TIntermSymbol*); - -private: - TString mapGlobalLongName(const TString& name); - - LongNameMap* mGlobalMap; -}; - -#endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_ diff --git a/src/compiler/translator/ShHandle.h b/src/compiler/translator/ShHandle.h index e34971d65..5991c5eec 100644 --- a/src/compiler/translator/ShHandle.h +++ b/src/compiler/translator/ShHandle.h @@ -24,7 +24,6 @@ #include "compiler/translator/VariableInfo.h" #include "third_party/compiler/ArrayBoundsClamper.h" -class LongNameMap; class TCompiler; class TDependencyGraph; class TranslatorHLSL; @@ -72,7 +71,6 @@ public: const TVariableInfoList& getAttribs() const { return attribs; } const TVariableInfoList& getUniforms() const { return uniforms; } const TVariableInfoList& getVaryings() const { return varyings; } - int getMappedNameMaxLength() const; ShHashFunction64 getHashFunction() const { return hashFunction; } NameMap& getNameMap() { return nameMap; } @@ -96,8 +94,6 @@ protected: bool validateLimitations(TIntermNode* root); // Collect info for all attribs, uniforms, varyings. void collectVariables(TIntermNode* root); - // Map long variable names into shorter ones. - void mapLongVariableNames(TIntermNode* root); // Translate to object code. virtual void translate(TIntermNode* root) = 0; // Returns true if, after applying the packing rules in the GLSL 1.017 spec @@ -159,9 +155,6 @@ private: TVariableInfoList uniforms; // Active uniforms in the compiled shader. TVariableInfoList varyings; // Varyings in the compiled shader. - // Cached copy of the ref-counted singleton. - LongNameMap* longNameMap; - // name hashing. ShHashFunction64 hashFunction; NameMap nameMap; diff --git a/src/compiler/translator/VariableInfo.cpp b/src/compiler/translator/VariableInfo.cpp index fdaef2973..2d2113448 100644 --- a/src/compiler/translator/VariableInfo.cpp +++ b/src/compiler/translator/VariableInfo.cpp @@ -354,9 +354,9 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node) if (mHashFunction == NULL) processedSymbol = variable->getSymbol(); else - processedSymbol = TIntermTraverser::hash(variable->getOriginalSymbol(), mHashFunction); + processedSymbol = TIntermTraverser::hash(variable->getSymbol(), mHashFunction); getVariableInfo(variable->getType(), - variable->getOriginalSymbol(), + variable->getSymbol(), processedSymbol, *infoList, mHashFunction); diff --git a/src/compiler/translator/intermediate.h b/src/compiler/translator/intermediate.h index 041eb86ea..db3481c35 100644 --- a/src/compiler/translator/intermediate.h +++ b/src/compiler/translator/intermediate.h @@ -368,7 +368,7 @@ public: // per process globalpoolallocator, then it causes increased memory usage per compile // it is essential to use "symbol = sym" to assign to symbol TIntermSymbol(int i, const TString& sym, const TType& t) : - TIntermTyped(t), id(i) { symbol = sym; originalSymbol = sym; } + TIntermTyped(t), id(i) { symbol = sym; } virtual bool hasSideEffects() const { return false; } @@ -376,9 +376,6 @@ public: const TString& getSymbol() const { return symbol; } void setId(int newId) { id = newId; } - void setSymbol(const TString& sym) { symbol = sym; } - - const TString& getOriginalSymbol() const { return originalSymbol; } virtual void traverse(TIntermTraverser*); virtual TIntermSymbol* getAsSymbolNode() { return this; } @@ -387,7 +384,6 @@ public: protected: int id; TString symbol; - TString originalSymbol; }; class TIntermConstantUnion : public TIntermTyped {