daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 6 | // Symbol table for parsing. The design principles and most of the functionality are documented in |
| 7 | // the header file. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 8 | // |
| 9 | |
apatrick@chromium.org | e057c5d | 2012-01-26 19:18:24 +0000 | [diff] [blame] | 10 | #if defined(_MSC_VER) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 11 | #pragma warning(disable : 4718) |
apatrick@chromium.org | e057c5d | 2012-01-26 19:18:24 +0000 | [diff] [blame] | 12 | #endif |
| 13 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 14 | #include "compiler/translator/SymbolTable.h" |
Olli Etuaho | 01d0ad0 | 2017-01-22 14:51:23 -0800 | [diff] [blame] | 15 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 16 | #include <algorithm> |
| 17 | #include <set> |
| 18 | |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 19 | #include "angle_gl.h" |
Olli Etuaho | 2d8e432 | 2018-01-22 14:12:46 +0200 | [diff] [blame] | 20 | #include "compiler/translator/ImmutableString.h" |
Olli Etuaho | 01d0ad0 | 2017-01-22 14:51:23 -0800 | [diff] [blame] | 21 | #include "compiler/translator/IntermNode.h" |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 22 | #include "compiler/translator/StaticType.h" |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 23 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 24 | namespace sh |
| 25 | { |
| 26 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 27 | class TSymbolTable::TSymbolTableLevel |
| 28 | { |
| 29 | public: |
| 30 | TSymbolTableLevel() : mGlobalInvariant(false) {} |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 31 | |
| 32 | bool insert(TSymbol *symbol); |
| 33 | |
| 34 | // Insert a function using its unmangled name as the key. |
Olli Etuaho | b92f92a | 2018-02-15 19:14:59 +0200 | [diff] [blame] | 35 | void insertUnmangled(TFunction *function); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 36 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 37 | TSymbol *find(const ImmutableString &name) const; |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 38 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 39 | void addInvariantVarying(const ImmutableString &name) { mInvariantVaryings.insert(name); } |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 40 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 41 | bool isVaryingInvariant(const ImmutableString &name) |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 42 | { |
| 43 | return (mGlobalInvariant || mInvariantVaryings.count(name) > 0); |
| 44 | } |
| 45 | |
| 46 | void setGlobalInvariant(bool invariant) { mGlobalInvariant = invariant; } |
| 47 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 48 | private: |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 49 | using tLevel = TUnorderedMap<ImmutableString, |
| 50 | TSymbol *, |
| 51 | ImmutableString::FowlerNollVoHash<sizeof(size_t)>>; |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 52 | using tLevelPair = const tLevel::value_type; |
| 53 | using tInsertResult = std::pair<tLevel::iterator, bool>; |
| 54 | |
| 55 | tLevel level; |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 56 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 57 | std::set<ImmutableString> mInvariantVaryings; |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 58 | bool mGlobalInvariant; |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 59 | }; |
| 60 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 61 | bool TSymbolTable::TSymbolTableLevel::insert(TSymbol *symbol) |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 62 | { |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 63 | // returning true means symbol was added to the table |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 64 | tInsertResult result = level.insert(tLevelPair(symbol->getMangledName(), symbol)); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 65 | return result.second; |
| 66 | } |
| 67 | |
Olli Etuaho | b92f92a | 2018-02-15 19:14:59 +0200 | [diff] [blame] | 68 | void TSymbolTable::TSymbolTableLevel::insertUnmangled(TFunction *function) |
Olli Etuaho | b2983c9 | 2015-03-18 14:02:46 +0200 | [diff] [blame] | 69 | { |
Olli Etuaho | b92f92a | 2018-02-15 19:14:59 +0200 | [diff] [blame] | 70 | level.insert(tLevelPair(function->name(), function)); |
Olli Etuaho | b2983c9 | 2015-03-18 14:02:46 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 73 | TSymbol *TSymbolTable::TSymbolTableLevel::find(const ImmutableString &name) const |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 74 | { |
| 75 | tLevel::const_iterator it = level.find(name); |
| 76 | if (it == level.end()) |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 77 | return nullptr; |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 78 | else |
| 79 | return (*it).second; |
| 80 | } |
| 81 | |
Olli Etuaho | 94bbed1 | 2018-03-20 14:44:53 +0200 | [diff] [blame^] | 82 | TSymbolTable::TSymbolTable() |
| 83 | : mUniqueIdCounter(0), mShaderType(GL_FRAGMENT_SHADER), mGlInVariableWithArraySize(nullptr) |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 84 | { |
| 85 | } |
| 86 | |
| 87 | TSymbolTable::~TSymbolTable() = default; |
| 88 | |
Olli Etuaho | 437664b | 2018-02-28 15:38:14 +0200 | [diff] [blame] | 89 | bool TSymbolTable::isEmpty() const |
| 90 | { |
| 91 | return mTable.empty(); |
| 92 | } |
| 93 | |
| 94 | bool TSymbolTable::atGlobalLevel() const |
| 95 | { |
| 96 | return mTable.size() == 1u; |
| 97 | } |
| 98 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 99 | void TSymbolTable::push() |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 100 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 101 | mTable.push_back(std::unique_ptr<TSymbolTableLevel>(new TSymbolTableLevel)); |
| 102 | mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel)); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 103 | } |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 104 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 105 | void TSymbolTable::pop() |
| 106 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 107 | mTable.pop_back(); |
| 108 | mPrecisionStack.pop_back(); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame] | 111 | const TFunction *TSymbolTable::markFunctionHasPrototypeDeclaration( |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 112 | const ImmutableString &mangledName, |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 113 | bool *hadPrototypeDeclarationOut) |
| 114 | { |
| 115 | TFunction *function = findUserDefinedFunction(mangledName); |
| 116 | *hadPrototypeDeclarationOut = function->hasPrototypeDeclaration(); |
| 117 | function->setHasPrototypeDeclaration(); |
| 118 | return function; |
| 119 | } |
| 120 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame] | 121 | const TFunction *TSymbolTable::setFunctionParameterNamesFromDefinition(const TFunction *function, |
| 122 | bool *wasDefinedOut) |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 123 | { |
| 124 | TFunction *firstDeclaration = findUserDefinedFunction(function->getMangledName()); |
| 125 | ASSERT(firstDeclaration); |
| 126 | // Note: 'firstDeclaration' could be 'function' if this is the first time we've seen function as |
| 127 | // it would have just been put in the symbol table. Otherwise, we're looking up an earlier |
| 128 | // occurance. |
| 129 | if (function != firstDeclaration) |
| 130 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 131 | // The previous declaration should have the same parameters as the function definition |
| 132 | // (parameter names may differ). |
| 133 | firstDeclaration->shareParameters(*function); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | *wasDefinedOut = firstDeclaration->isDefined(); |
| 137 | firstDeclaration->setDefined(); |
| 138 | return firstDeclaration; |
| 139 | } |
| 140 | |
Olli Etuaho | 94bbed1 | 2018-03-20 14:44:53 +0200 | [diff] [blame^] | 141 | bool TSymbolTable::setGlInArraySize(unsigned int inputArraySize) |
| 142 | { |
| 143 | if (mGlInVariableWithArraySize) |
| 144 | { |
| 145 | return mGlInVariableWithArraySize->getType().getOutermostArraySize() == inputArraySize; |
| 146 | } |
| 147 | const TInterfaceBlock *glPerVertex = mVar_gl_PerVertex; |
| 148 | TType *glInType = new TType(glPerVertex, EvqPerVertexIn, TLayoutQualifier::Create()); |
| 149 | glInType->makeArray(inputArraySize); |
| 150 | mGlInVariableWithArraySize = |
| 151 | new TVariable(this, ImmutableString("gl_in"), glInType, SymbolType::BuiltIn, |
| 152 | TExtension::EXT_geometry_shader); |
| 153 | return true; |
| 154 | } |
| 155 | |
| 156 | TVariable *TSymbolTable::getGlInVariableWithArraySize() const |
| 157 | { |
| 158 | return mGlInVariableWithArraySize; |
| 159 | } |
| 160 | |
| 161 | void TSymbolTable::markStaticWrite(const TVariable &variable) |
| 162 | { |
| 163 | int id = variable.uniqueId().get(); |
| 164 | auto iter = mVariableMetadata.find(id); |
| 165 | if (iter == mVariableMetadata.end()) |
| 166 | { |
| 167 | iter = mVariableMetadata.insert(std::make_pair(id, VariableMetadata())).first; |
| 168 | } |
| 169 | iter->second.staticWrite = true; |
| 170 | } |
| 171 | |
| 172 | void TSymbolTable::markStaticRead(const TVariable &variable) |
| 173 | { |
| 174 | int id = variable.uniqueId().get(); |
| 175 | auto iter = mVariableMetadata.find(id); |
| 176 | if (iter == mVariableMetadata.end()) |
| 177 | { |
| 178 | iter = mVariableMetadata.insert(std::make_pair(id, VariableMetadata())).first; |
| 179 | } |
| 180 | iter->second.staticRead = true; |
| 181 | } |
| 182 | |
| 183 | bool TSymbolTable::isStaticallyUsed(const TVariable &variable) const |
| 184 | { |
| 185 | ASSERT(!variable.getConstPointer()); |
| 186 | int id = variable.uniqueId().get(); |
| 187 | auto iter = mVariableMetadata.find(id); |
| 188 | return iter != mVariableMetadata.end(); |
| 189 | } |
| 190 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 191 | const TSymbol *TSymbolTable::find(const ImmutableString &name, int shaderVersion) const |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 192 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 193 | int userDefinedLevel = static_cast<int>(mTable.size()) - 1; |
| 194 | while (userDefinedLevel >= 0) |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 195 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 196 | const TSymbol *symbol = mTable[userDefinedLevel]->find(name); |
| 197 | if (symbol) |
| 198 | { |
| 199 | return symbol; |
| 200 | } |
| 201 | userDefinedLevel--; |
| 202 | } |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 203 | |
Olli Etuaho | 115b2c4 | 2018-03-15 17:46:29 +0200 | [diff] [blame] | 204 | return findBuiltIn(name, shaderVersion); |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 207 | TFunction *TSymbolTable::findUserDefinedFunction(const ImmutableString &name) const |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 208 | { |
| 209 | // User-defined functions are always declared at the global level. |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 210 | ASSERT(!mTable.empty()); |
| 211 | return static_cast<TFunction *>(mTable[0]->find(name)); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 214 | const TSymbol *TSymbolTable::findGlobal(const ImmutableString &name) const |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 215 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 216 | ASSERT(!mTable.empty()); |
| 217 | return mTable[0]->find(name); |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Olli Etuaho | 437664b | 2018-02-28 15:38:14 +0200 | [diff] [blame] | 220 | bool TSymbolTable::declare(TSymbol *symbol) |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 221 | { |
Olli Etuaho | 437664b | 2018-02-28 15:38:14 +0200 | [diff] [blame] | 222 | ASSERT(!mTable.empty()); |
| 223 | ASSERT(symbol->symbolType() == SymbolType::UserDefined); |
| 224 | ASSERT(!symbol->isFunction()); |
| 225 | return mTable.back()->insert(symbol); |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 226 | } |
| 227 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 228 | void TSymbolTable::declareUserDefinedFunction(TFunction *function, bool insertUnmangledName) |
| 229 | { |
Olli Etuaho | 437664b | 2018-02-28 15:38:14 +0200 | [diff] [blame] | 230 | ASSERT(!mTable.empty()); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 231 | if (insertUnmangledName) |
| 232 | { |
| 233 | // Insert the unmangled name to detect potential future redefinition as a variable. |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 234 | mTable[0]->insertUnmangled(function); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 235 | } |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 236 | mTable[0]->insert(function); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 237 | } |
| 238 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 239 | void TSymbolTable::setDefaultPrecision(TBasicType type, TPrecision prec) |
| 240 | { |
| 241 | int indexOfLastElement = static_cast<int>(mPrecisionStack.size()) - 1; |
| 242 | // Uses map operator [], overwrites the current value |
| 243 | (*mPrecisionStack[indexOfLastElement])[type] = prec; |
| 244 | } |
| 245 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 246 | TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 247 | { |
| 248 | if (!SupportsPrecision(type)) |
| 249 | return EbpUndefined; |
| 250 | |
| 251 | // unsigned integers use the same precision as signed |
| 252 | TBasicType baseType = (type == EbtUInt) ? EbtInt : type; |
| 253 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 254 | int level = static_cast<int>(mPrecisionStack.size()) - 1; |
| 255 | ASSERT(level >= 0); // Just to be safe. Should not happen. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 256 | // If we dont find anything we return this. Some types don't have predefined default precision. |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 257 | TPrecision prec = EbpUndefined; |
| 258 | while (level >= 0) |
| 259 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 260 | PrecisionStackLevel::iterator it = mPrecisionStack[level]->find(baseType); |
| 261 | if (it != mPrecisionStack[level]->end()) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 262 | { |
| 263 | prec = (*it).second; |
| 264 | break; |
| 265 | } |
| 266 | level--; |
| 267 | } |
| 268 | return prec; |
| 269 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 270 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 271 | void TSymbolTable::addInvariantVarying(const ImmutableString &originalName) |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 272 | { |
| 273 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 274 | mTable.back()->addInvariantVarying(originalName); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 277 | bool TSymbolTable::isVaryingInvariant(const ImmutableString &originalName) const |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 278 | { |
| 279 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 280 | return mTable.back()->isVaryingInvariant(originalName); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void TSymbolTable::setGlobalInvariant(bool invariant) |
| 284 | { |
| 285 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 286 | mTable.back()->setGlobalInvariant(invariant); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 287 | } |
| 288 | |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 289 | void TSymbolTable::clearCompilationResults() |
| 290 | { |
Olli Etuaho | 391bda2 | 2018-02-23 11:43:14 +0200 | [diff] [blame] | 291 | mUniqueIdCounter = kLastBuiltInId + 1; |
Olli Etuaho | 94bbed1 | 2018-03-20 14:44:53 +0200 | [diff] [blame^] | 292 | mVariableMetadata.clear(); |
| 293 | mGlInVariableWithArraySize = nullptr; |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 294 | |
| 295 | // User-defined scopes should have already been cleared when the compilation finished. |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 296 | ASSERT(mTable.size() == 0u); |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | int TSymbolTable::nextUniqueIdValue() |
| 300 | { |
| 301 | ASSERT(mUniqueIdCounter < std::numeric_limits<int>::max()); |
| 302 | return ++mUniqueIdCounter; |
| 303 | } |
| 304 | |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 305 | void TSymbolTable::initializeBuiltIns(sh::GLenum type, |
| 306 | ShShaderSpec spec, |
| 307 | const ShBuiltInResources &resources) |
| 308 | { |
Olli Etuaho | 065aa86 | 2018-02-22 15:30:27 +0200 | [diff] [blame] | 309 | mShaderType = type; |
Olli Etuaho | b391ec4 | 2018-03-12 17:04:59 +0200 | [diff] [blame] | 310 | mResources = resources; |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 311 | |
| 312 | // We need just one precision stack level for predefined precisions. |
| 313 | mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel)); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 314 | |
| 315 | switch (type) |
| 316 | { |
| 317 | case GL_FRAGMENT_SHADER: |
| 318 | setDefaultPrecision(EbtInt, EbpMedium); |
| 319 | break; |
| 320 | case GL_VERTEX_SHADER: |
| 321 | case GL_COMPUTE_SHADER: |
| 322 | case GL_GEOMETRY_SHADER_EXT: |
| 323 | setDefaultPrecision(EbtInt, EbpHigh); |
| 324 | setDefaultPrecision(EbtFloat, EbpHigh); |
| 325 | break; |
| 326 | default: |
| 327 | UNREACHABLE(); |
| 328 | } |
| 329 | // Set defaults for sampler types that have default precision, even those that are |
| 330 | // only available if an extension exists. |
| 331 | // New sampler types in ESSL3 don't have default precision. ESSL1 types do. |
| 332 | initSamplerDefaultPrecision(EbtSampler2D); |
| 333 | initSamplerDefaultPrecision(EbtSamplerCube); |
| 334 | // SamplerExternalOES is specified in the extension to have default precision. |
| 335 | initSamplerDefaultPrecision(EbtSamplerExternalOES); |
| 336 | // SamplerExternal2DY2YEXT is specified in the extension to have default precision. |
| 337 | initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT); |
| 338 | // It isn't specified whether Sampler2DRect has default precision. |
| 339 | initSamplerDefaultPrecision(EbtSampler2DRect); |
| 340 | |
| 341 | setDefaultPrecision(EbtAtomicCounter, EbpHigh); |
| 342 | |
Olli Etuaho | b391ec4 | 2018-03-12 17:04:59 +0200 | [diff] [blame] | 343 | initializeBuiltInVariables(type, spec, resources); |
Olli Etuaho | 391bda2 | 2018-02-23 11:43:14 +0200 | [diff] [blame] | 344 | mUniqueIdCounter = kLastBuiltInId + 1; |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType) |
| 348 | { |
Olli Etuaho | e600c0a | 2018-03-02 11:23:29 +0200 | [diff] [blame] | 349 | ASSERT(samplerType >= EbtGuardSamplerBegin && samplerType <= EbtGuardSamplerEnd); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 350 | setDefaultPrecision(samplerType, EbpLow); |
| 351 | } |
| 352 | |
Olli Etuaho | 94bbed1 | 2018-03-20 14:44:53 +0200 | [diff] [blame^] | 353 | TSymbolTable::VariableMetadata::VariableMetadata() : staticRead(false), staticWrite(false) |
| 354 | { |
| 355 | } |
| 356 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 357 | } // namespace sh |