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 | |
| 61 | class TSymbolTable::TSymbolTableBuiltInLevel |
| 62 | { |
| 63 | public: |
| 64 | TSymbolTableBuiltInLevel() = default; |
| 65 | |
| 66 | bool insert(const TSymbol *symbol); |
| 67 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 68 | const TSymbol *find(const ImmutableString &name) const; |
| 69 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 70 | void insertUnmangledBuiltIn(const char *name, TExtension ext); |
| 71 | const UnmangledBuiltIn *getUnmangledBuiltIn(const ImmutableString &name) const; |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | using tLevel = TUnorderedMap<ImmutableString, |
| 75 | const TSymbol *, |
| 76 | ImmutableString::FowlerNollVoHash<sizeof(size_t)>>; |
| 77 | using tLevelPair = const tLevel::value_type; |
| 78 | using tInsertResult = std::pair<tLevel::iterator, bool>; |
| 79 | |
| 80 | tLevel mLevel; |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 81 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 82 | std::map<ImmutableString, UnmangledBuiltIn> mUnmangledBuiltIns; |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 85 | bool TSymbolTable::TSymbolTableLevel::insert(TSymbol *symbol) |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 86 | { |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 87 | // returning true means symbol was added to the table |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 88 | tInsertResult result = level.insert(tLevelPair(symbol->getMangledName(), symbol)); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 89 | return result.second; |
| 90 | } |
| 91 | |
Olli Etuaho | b92f92a | 2018-02-15 19:14:59 +0200 | [diff] [blame] | 92 | void TSymbolTable::TSymbolTableLevel::insertUnmangled(TFunction *function) |
Olli Etuaho | b2983c9 | 2015-03-18 14:02:46 +0200 | [diff] [blame] | 93 | { |
Olli Etuaho | b92f92a | 2018-02-15 19:14:59 +0200 | [diff] [blame] | 94 | level.insert(tLevelPair(function->name(), function)); |
Olli Etuaho | b2983c9 | 2015-03-18 14:02:46 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 97 | TSymbol *TSymbolTable::TSymbolTableLevel::find(const ImmutableString &name) const |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 98 | { |
| 99 | tLevel::const_iterator it = level.find(name); |
| 100 | if (it == level.end()) |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 101 | return nullptr; |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 102 | else |
| 103 | return (*it).second; |
| 104 | } |
| 105 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 106 | bool TSymbolTable::TSymbolTableBuiltInLevel::insert(const TSymbol *symbol) |
| 107 | { |
| 108 | // returning true means symbol was added to the table |
| 109 | tInsertResult result = mLevel.insert(tLevelPair(symbol->getMangledName(), symbol)); |
| 110 | return result.second; |
| 111 | } |
| 112 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 113 | const TSymbol *TSymbolTable::TSymbolTableBuiltInLevel::find(const ImmutableString &name) const |
| 114 | { |
| 115 | tLevel::const_iterator it = mLevel.find(name); |
| 116 | if (it == mLevel.end()) |
| 117 | return nullptr; |
| 118 | else |
| 119 | return (*it).second; |
| 120 | } |
| 121 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 122 | void TSymbolTable::TSymbolTableBuiltInLevel::insertUnmangledBuiltIn(const char *name, |
| 123 | TExtension ext) |
Olli Etuaho | 342b83d | 2018-01-10 13:24:01 +0200 | [diff] [blame] | 124 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 125 | ImmutableString immName(name); |
| 126 | if (ext == TExtension::UNDEFINED || |
| 127 | mUnmangledBuiltIns.find(immName) == mUnmangledBuiltIns.end()) |
| 128 | { |
| 129 | mUnmangledBuiltIns[immName] = UnmangledBuiltIn(ext); |
| 130 | } |
Olli Etuaho | 342b83d | 2018-01-10 13:24:01 +0200 | [diff] [blame] | 131 | } |
| 132 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 133 | const UnmangledBuiltIn *TSymbolTable::TSymbolTableBuiltInLevel::getUnmangledBuiltIn( |
| 134 | const ImmutableString &name) const |
Olli Etuaho | 342b83d | 2018-01-10 13:24:01 +0200 | [diff] [blame] | 135 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 136 | auto it = mUnmangledBuiltIns.find(ImmutableString(name)); |
| 137 | if (it == mUnmangledBuiltIns.end()) |
| 138 | { |
| 139 | return nullptr; |
| 140 | } |
| 141 | return &(it->second); |
Olli Etuaho | 342b83d | 2018-01-10 13:24:01 +0200 | [diff] [blame] | 142 | } |
| 143 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 144 | TSymbolTable::TSymbolTable() : mUniqueIdCounter(0), mUserDefinedUniqueIdsStart(-1) |
| 145 | { |
| 146 | } |
| 147 | |
| 148 | TSymbolTable::~TSymbolTable() = default; |
| 149 | |
| 150 | void TSymbolTable::pushBuiltInLevel() |
| 151 | { |
| 152 | mBuiltInTable.push_back( |
| 153 | std::unique_ptr<TSymbolTableBuiltInLevel>(new TSymbolTableBuiltInLevel)); |
| 154 | } |
| 155 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 156 | void TSymbolTable::push() |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 157 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 158 | mTable.push_back(std::unique_ptr<TSymbolTableLevel>(new TSymbolTableLevel)); |
| 159 | mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel)); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 160 | } |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 161 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 162 | void TSymbolTable::pop() |
| 163 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 164 | mTable.pop_back(); |
| 165 | mPrecisionStack.pop_back(); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 166 | } |
| 167 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 168 | const TFunction *TSymbolTable::markFunctionHasPrototypeDeclaration( |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 169 | const ImmutableString &mangledName, |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 170 | bool *hadPrototypeDeclarationOut) |
| 171 | { |
| 172 | TFunction *function = findUserDefinedFunction(mangledName); |
| 173 | *hadPrototypeDeclarationOut = function->hasPrototypeDeclaration(); |
| 174 | function->setHasPrototypeDeclaration(); |
| 175 | return function; |
| 176 | } |
| 177 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 178 | const TFunction *TSymbolTable::setFunctionParameterNamesFromDefinition(const TFunction *function, |
| 179 | bool *wasDefinedOut) |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 180 | { |
| 181 | TFunction *firstDeclaration = findUserDefinedFunction(function->getMangledName()); |
| 182 | ASSERT(firstDeclaration); |
| 183 | // Note: 'firstDeclaration' could be 'function' if this is the first time we've seen function as |
| 184 | // it would have just been put in the symbol table. Otherwise, we're looking up an earlier |
| 185 | // occurance. |
| 186 | if (function != firstDeclaration) |
| 187 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 188 | // The previous declaration should have the same parameters as the function definition |
| 189 | // (parameter names may differ). |
| 190 | firstDeclaration->shareParameters(*function); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | *wasDefinedOut = firstDeclaration->isDefined(); |
| 194 | firstDeclaration->setDefined(); |
| 195 | return firstDeclaration; |
| 196 | } |
| 197 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 198 | const TSymbol *TSymbolTable::find(const ImmutableString &name, int shaderVersion) const |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 199 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 200 | int userDefinedLevel = static_cast<int>(mTable.size()) - 1; |
| 201 | while (userDefinedLevel >= 0) |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 202 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 203 | const TSymbol *symbol = mTable[userDefinedLevel]->find(name); |
| 204 | if (symbol) |
| 205 | { |
| 206 | return symbol; |
| 207 | } |
| 208 | userDefinedLevel--; |
| 209 | } |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 210 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 211 | return findBuiltIn(name, shaderVersion, false); |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 214 | TFunction *TSymbolTable::findUserDefinedFunction(const ImmutableString &name) const |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 215 | { |
| 216 | // User-defined functions are always declared at the global level. |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 217 | ASSERT(!mTable.empty()); |
| 218 | return static_cast<TFunction *>(mTable[0]->find(name)); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 221 | const TSymbol *TSymbolTable::findGlobal(const ImmutableString &name) const |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 222 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 223 | ASSERT(!mTable.empty()); |
| 224 | return mTable[0]->find(name); |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 227 | const TSymbol *TSymbolTable::findBuiltIn(const ImmutableString &name, int shaderVersion) const |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 228 | { |
Olli Etuaho | 977ee7e | 2017-07-21 11:38:27 +0300 | [diff] [blame] | 229 | return findBuiltIn(name, shaderVersion, false); |
| 230 | } |
| 231 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 232 | const TSymbol *TSymbolTable::findBuiltIn(const ImmutableString &name, |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 233 | int shaderVersion, |
| 234 | bool includeGLSLBuiltins) const |
Olli Etuaho | 977ee7e | 2017-07-21 11:38:27 +0300 | [diff] [blame] | 235 | { |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 236 | for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--) |
| 237 | { |
Olli Etuaho | 977ee7e | 2017-07-21 11:38:27 +0300 | [diff] [blame] | 238 | if (level == GLSL_BUILTINS && !includeGLSLBuiltins) |
| 239 | level--; |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 240 | if (level == ESSL3_1_BUILTINS && shaderVersion != 310) |
| 241 | level--; |
| 242 | if (level == ESSL3_BUILTINS && shaderVersion < 300) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 243 | level--; |
| 244 | if (level == ESSL1_BUILTINS && shaderVersion != 100) |
| 245 | level--; |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 246 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 247 | const TSymbol *symbol = mBuiltInTable[level]->find(name); |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 248 | |
| 249 | if (symbol) |
| 250 | return symbol; |
| 251 | } |
| 252 | |
Olli Etuaho | 977ee7e | 2017-07-21 11:38:27 +0300 | [diff] [blame] | 253 | return nullptr; |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 254 | } |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 255 | |
Kai Ninomiya | 030017a | 2017-12-06 14:06:53 -0800 | [diff] [blame] | 256 | constexpr bool IsGenType(const TType *type) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 257 | { |
| 258 | if (type) |
| 259 | { |
| 260 | TBasicType basicType = type->getBasicType(); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 261 | return basicType == EbtGenType || basicType == EbtGenIType || basicType == EbtGenUType || |
| 262 | basicType == EbtGenBType; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | return false; |
| 266 | } |
| 267 | |
Kai Ninomiya | 030017a | 2017-12-06 14:06:53 -0800 | [diff] [blame] | 268 | constexpr bool IsVecType(const TType *type) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 269 | { |
| 270 | if (type) |
| 271 | { |
| 272 | TBasicType basicType = type->getBasicType(); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 273 | return basicType == EbtVec || basicType == EbtIVec || basicType == EbtUVec || |
| 274 | basicType == EbtBVec; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | return false; |
| 278 | } |
| 279 | |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 280 | constexpr const TType *SpecificType(const TType *type, int size) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 281 | { |
| 282 | ASSERT(size >= 1 && size <= 4); |
| 283 | |
| 284 | if (!type) |
| 285 | { |
| 286 | return nullptr; |
| 287 | } |
| 288 | |
| 289 | ASSERT(!IsVecType(type)); |
| 290 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 291 | switch (type->getBasicType()) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 292 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 293 | case EbtGenType: |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 294 | return StaticType::GetForVec<EbtFloat>(type->getQualifier(), |
| 295 | static_cast<unsigned char>(size)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 296 | case EbtGenIType: |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 297 | return StaticType::GetForVec<EbtInt>(type->getQualifier(), |
| 298 | static_cast<unsigned char>(size)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 299 | case EbtGenUType: |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 300 | return StaticType::GetForVec<EbtUInt>(type->getQualifier(), |
| 301 | static_cast<unsigned char>(size)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 302 | case EbtGenBType: |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 303 | return StaticType::GetForVec<EbtBool>(type->getQualifier(), |
| 304 | static_cast<unsigned char>(size)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 305 | default: |
| 306 | return type; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 310 | constexpr const TType *VectorType(const TType *type, int size) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 311 | { |
| 312 | ASSERT(size >= 2 && size <= 4); |
| 313 | |
| 314 | if (!type) |
| 315 | { |
| 316 | return nullptr; |
| 317 | } |
| 318 | |
| 319 | ASSERT(!IsGenType(type)); |
| 320 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 321 | switch (type->getBasicType()) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 322 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 323 | case EbtVec: |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 324 | return StaticType::GetForVecMat<EbtFloat>(static_cast<unsigned char>(size)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 325 | case EbtIVec: |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 326 | return StaticType::GetForVecMat<EbtInt>(static_cast<unsigned char>(size)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 327 | case EbtUVec: |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 328 | return StaticType::GetForVecMat<EbtUInt>(static_cast<unsigned char>(size)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 329 | case EbtBVec: |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 330 | return StaticType::GetForVecMat<EbtBool>(static_cast<unsigned char>(size)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 331 | default: |
| 332 | return type; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 336 | bool TSymbolTable::declareVariable(TVariable *variable) |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 337 | { |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 338 | ASSERT(variable->symbolType() == SymbolType::UserDefined); |
| 339 | return insertVariable(currentLevel(), variable); |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 340 | } |
| 341 | |
Olli Etuaho | 035419f | 2017-11-28 14:27:15 +0200 | [diff] [blame] | 342 | bool TSymbolTable::declareStructType(TStructure *str) |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 343 | { |
| 344 | return insertStructType(currentLevel(), str); |
| 345 | } |
| 346 | |
Olli Etuaho | 378c3a5 | 2017-12-04 11:32:13 +0200 | [diff] [blame] | 347 | bool TSymbolTable::declareInterfaceBlock(TInterfaceBlock *interfaceBlock) |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 348 | { |
Olli Etuaho | 378c3a5 | 2017-12-04 11:32:13 +0200 | [diff] [blame] | 349 | return insert(currentLevel(), interfaceBlock); |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 350 | } |
| 351 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 352 | void TSymbolTable::declareUserDefinedFunction(TFunction *function, bool insertUnmangledName) |
| 353 | { |
| 354 | ASSERT(currentLevel() >= GLOBAL_LEVEL); |
| 355 | if (insertUnmangledName) |
| 356 | { |
| 357 | // Insert the unmangled name to detect potential future redefinition as a variable. |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 358 | mTable[0]->insertUnmangled(function); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 359 | } |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 360 | mTable[0]->insert(function); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 363 | TVariable *TSymbolTable::insertVariable(ESymbolLevel level, |
| 364 | const ImmutableString &name, |
| 365 | const TType *type) |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 366 | { |
Olli Etuaho | 9d4d7f0 | 2017-12-07 17:11:41 +0100 | [diff] [blame] | 367 | ASSERT(level <= LAST_BUILTIN_LEVEL); |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 368 | ASSERT(type->isRealized()); |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 369 | return insertVariable(level, name, type, SymbolType::BuiltIn); |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 370 | } |
| 371 | |
Olli Etuaho | 9d4d7f0 | 2017-12-07 17:11:41 +0100 | [diff] [blame] | 372 | TVariable *TSymbolTable::insertVariable(ESymbolLevel level, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 373 | const ImmutableString &name, |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 374 | const TType *type, |
Olli Etuaho | 9d4d7f0 | 2017-12-07 17:11:41 +0100 | [diff] [blame] | 375 | SymbolType symbolType) |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 376 | { |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 377 | ASSERT(level > LAST_BUILTIN_LEVEL || type->isRealized()); |
Olli Etuaho | 9d4d7f0 | 2017-12-07 17:11:41 +0100 | [diff] [blame] | 378 | TVariable *var = new TVariable(this, name, type, symbolType); |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 379 | if (insert(level, var)) |
| 380 | { |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 381 | return var; |
| 382 | } |
| 383 | return nullptr; |
| 384 | } |
| 385 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 386 | void TSymbolTable::insertVariableExt(ESymbolLevel level, |
| 387 | TExtension ext, |
| 388 | const ImmutableString &name, |
| 389 | const TType *type) |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 390 | { |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 391 | ASSERT(level <= LAST_BUILTIN_LEVEL); |
| 392 | ASSERT(type->isRealized()); |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 393 | TVariable *var = new TVariable(this, name, type, SymbolType::BuiltIn, ext); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 394 | bool inserted = insert(level, var); |
| 395 | UNUSED_VARIABLE(inserted); |
| 396 | ASSERT(inserted); |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 397 | } |
| 398 | |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 399 | bool TSymbolTable::insertVariable(ESymbolLevel level, TVariable *variable) |
| 400 | { |
| 401 | ASSERT(variable); |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 402 | ASSERT(level > LAST_BUILTIN_LEVEL || variable->getType().isRealized()); |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 403 | return insert(level, variable); |
| 404 | } |
| 405 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 406 | bool TSymbolTable::insert(ESymbolLevel level, TSymbol *symbol) |
| 407 | { |
| 408 | ASSERT(level > LAST_BUILTIN_LEVEL || mUserDefinedUniqueIdsStart == -1); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 409 | if (level <= LAST_BUILTIN_LEVEL) |
| 410 | { |
| 411 | return mBuiltInTable[level]->insert(symbol); |
| 412 | } |
| 413 | else |
| 414 | { |
| 415 | return mTable[level - LAST_BUILTIN_LEVEL - 1]->insert(symbol); |
| 416 | } |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Olli Etuaho | 035419f | 2017-11-28 14:27:15 +0200 | [diff] [blame] | 419 | bool TSymbolTable::insertStructType(ESymbolLevel level, TStructure *str) |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 420 | { |
Olli Etuaho | 035419f | 2017-11-28 14:27:15 +0200 | [diff] [blame] | 421 | ASSERT(str); |
Olli Etuaho | 378c3a5 | 2017-12-04 11:32:13 +0200 | [diff] [blame] | 422 | return insert(level, str); |
| 423 | } |
| 424 | |
| 425 | bool TSymbolTable::insertInterfaceBlock(ESymbolLevel level, TInterfaceBlock *interfaceBlock) |
| 426 | { |
| 427 | ASSERT(interfaceBlock); |
| 428 | return insert(level, interfaceBlock); |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 429 | } |
| 430 | |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 431 | template <TPrecision precision> |
| 432 | bool TSymbolTable::insertConstInt(ESymbolLevel level, const ImmutableString &name, int value) |
| 433 | { |
| 434 | TVariable *constant = new TVariable( |
| 435 | this, name, StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn); |
| 436 | TConstantUnion *unionArray = new TConstantUnion[1]; |
| 437 | unionArray[0].setIConst(value); |
| 438 | constant->shareConstPointer(unionArray); |
| 439 | return insert(level, constant); |
| 440 | } |
| 441 | |
| 442 | template <TPrecision precision> |
| 443 | bool TSymbolTable::insertConstIntExt(ESymbolLevel level, |
| 444 | TExtension ext, |
| 445 | const ImmutableString &name, |
| 446 | int value) |
| 447 | { |
| 448 | TVariable *constant = new TVariable( |
| 449 | this, name, StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn, ext); |
| 450 | TConstantUnion *unionArray = new TConstantUnion[1]; |
| 451 | unionArray[0].setIConst(value); |
| 452 | constant->shareConstPointer(unionArray); |
| 453 | return insert(level, constant); |
| 454 | } |
| 455 | |
| 456 | template <TPrecision precision> |
| 457 | bool TSymbolTable::insertConstIvec3(ESymbolLevel level, |
| 458 | const ImmutableString &name, |
| 459 | const std::array<int, 3> &values) |
| 460 | { |
| 461 | TVariable *constantIvec3 = new TVariable( |
| 462 | this, name, StaticType::Get<EbtInt, precision, EvqConst, 3, 1>(), SymbolType::BuiltIn); |
| 463 | |
| 464 | TConstantUnion *unionArray = new TConstantUnion[3]; |
| 465 | for (size_t index = 0u; index < 3u; ++index) |
| 466 | { |
| 467 | unionArray[index].setIConst(values[index]); |
| 468 | } |
| 469 | constantIvec3->shareConstPointer(unionArray); |
| 470 | |
| 471 | return insert(level, constantIvec3); |
| 472 | } |
| 473 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 474 | void TSymbolTable::insertBuiltIn(ESymbolLevel level, |
| 475 | TOperator op, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 476 | TExtension ext, |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 477 | const TType *rvalue, |
| 478 | const char *name, |
| 479 | const TType *ptype1, |
| 480 | const TType *ptype2, |
| 481 | const TType *ptype3, |
| 482 | const TType *ptype4, |
| 483 | const TType *ptype5) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 484 | { |
| 485 | if (ptype1->getBasicType() == EbtGSampler2D) |
| 486 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 487 | insertUnmangledBuiltIn(name, ext, level); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 488 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 489 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name, |
| 490 | StaticType::GetBasic<EbtSampler2D>(), ptype2, ptype3, ptype4, ptype5); |
| 491 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name, |
| 492 | StaticType::GetBasic<EbtISampler2D>(), ptype2, ptype3, ptype4, ptype5); |
| 493 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name, |
| 494 | StaticType::GetBasic<EbtUSampler2D>(), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 495 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 496 | else if (ptype1->getBasicType() == EbtGSampler3D) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 497 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 498 | insertUnmangledBuiltIn(name, ext, level); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 499 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 500 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name, |
| 501 | StaticType::GetBasic<EbtSampler3D>(), ptype2, ptype3, ptype4, ptype5); |
| 502 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name, |
| 503 | StaticType::GetBasic<EbtISampler3D>(), ptype2, ptype3, ptype4, ptype5); |
| 504 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name, |
| 505 | StaticType::GetBasic<EbtUSampler3D>(), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 506 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 507 | else if (ptype1->getBasicType() == EbtGSamplerCube) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 508 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 509 | insertUnmangledBuiltIn(name, ext, level); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 510 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 511 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name, |
| 512 | StaticType::GetBasic<EbtSamplerCube>(), ptype2, ptype3, ptype4, ptype5); |
| 513 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name, |
| 514 | StaticType::GetBasic<EbtISamplerCube>(), ptype2, ptype3, ptype4, ptype5); |
| 515 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name, |
| 516 | StaticType::GetBasic<EbtUSamplerCube>(), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 517 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 518 | else if (ptype1->getBasicType() == EbtGSampler2DArray) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 519 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 520 | insertUnmangledBuiltIn(name, ext, level); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 521 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 522 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name, |
| 523 | StaticType::GetBasic<EbtSampler2DArray>(), ptype2, ptype3, ptype4, |
| 524 | ptype5); |
| 525 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name, |
| 526 | StaticType::GetBasic<EbtISampler2DArray>(), ptype2, ptype3, ptype4, |
| 527 | ptype5); |
| 528 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name, |
| 529 | StaticType::GetBasic<EbtUSampler2DArray>(), ptype2, ptype3, ptype4, |
| 530 | ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 531 | } |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 532 | else if (ptype1->getBasicType() == EbtGSampler2DMS) |
| 533 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 534 | insertUnmangledBuiltIn(name, ext, level); |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 535 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 536 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name, |
| 537 | StaticType::GetBasic<EbtSampler2DMS>(), ptype2, ptype3, ptype4, ptype5); |
| 538 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name, |
| 539 | StaticType::GetBasic<EbtISampler2DMS>(), ptype2, ptype3, ptype4, ptype5); |
| 540 | insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name, |
| 541 | StaticType::GetBasic<EbtUSampler2DMS>(), ptype2, ptype3, ptype4, ptype5); |
JiangYizhou | 4021932 | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 542 | } |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 543 | else if (IsGImage(ptype1->getBasicType())) |
| 544 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 545 | insertUnmangledBuiltIn(name, ext, level); |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 546 | |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 547 | const TType *floatType = StaticType::GetBasic<EbtFloat, 4>(); |
| 548 | const TType *intType = StaticType::GetBasic<EbtInt, 4>(); |
| 549 | const TType *unsignedType = StaticType::GetBasic<EbtUInt, 4>(); |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 550 | |
Kai Ninomiya | 614dd0f | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 551 | const TType *floatImage = StaticType::GetForFloatImage(ptype1->getBasicType()); |
| 552 | const TType *intImage = StaticType::GetForIntImage(ptype1->getBasicType()); |
| 553 | const TType *unsignedImage = StaticType::GetForUintImage(ptype1->getBasicType()); |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 554 | |
| 555 | // GLSL ES 3.10, Revision 4, 8.12 Image Functions |
| 556 | if (rvalue->getBasicType() == EbtGVec4) |
| 557 | { |
| 558 | // imageLoad |
| 559 | insertBuiltIn(level, floatType, name, floatImage, ptype2, ptype3, ptype4, ptype5); |
| 560 | insertBuiltIn(level, intType, name, intImage, ptype2, ptype3, ptype4, ptype5); |
| 561 | insertBuiltIn(level, unsignedType, name, unsignedImage, ptype2, ptype3, ptype4, ptype5); |
| 562 | } |
| 563 | else if (rvalue->getBasicType() == EbtVoid) |
| 564 | { |
| 565 | // imageStore |
| 566 | insertBuiltIn(level, rvalue, name, floatImage, ptype2, floatType, ptype4, ptype5); |
| 567 | insertBuiltIn(level, rvalue, name, intImage, ptype2, intType, ptype4, ptype5); |
| 568 | insertBuiltIn(level, rvalue, name, unsignedImage, ptype2, unsignedType, ptype4, ptype5); |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | // imageSize |
| 573 | insertBuiltIn(level, rvalue, name, floatImage, ptype2, ptype3, ptype4, ptype5); |
| 574 | insertBuiltIn(level, rvalue, name, intImage, ptype2, ptype3, ptype4, ptype5); |
| 575 | insertBuiltIn(level, rvalue, name, unsignedImage, ptype2, ptype3, ptype4, ptype5); |
| 576 | } |
| 577 | } |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 578 | else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3) || |
| 579 | IsGenType(ptype4)) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 580 | { |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 581 | ASSERT(!ptype5); |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 582 | insertUnmangledBuiltIn(name, ext, level); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 583 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 1), name, SpecificType(ptype1, 1), |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 584 | SpecificType(ptype2, 1), SpecificType(ptype3, 1), SpecificType(ptype4, 1)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 585 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 2), name, SpecificType(ptype1, 2), |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 586 | SpecificType(ptype2, 2), SpecificType(ptype3, 2), SpecificType(ptype4, 2)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 587 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 3), name, SpecificType(ptype1, 3), |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 588 | SpecificType(ptype2, 3), SpecificType(ptype3, 3), SpecificType(ptype4, 3)); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 589 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 4), name, SpecificType(ptype1, 4), |
Olli Etuaho | 9250cb2 | 2017-01-21 10:51:27 +0000 | [diff] [blame] | 590 | SpecificType(ptype2, 4), SpecificType(ptype3, 4), SpecificType(ptype4, 4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 591 | } |
| 592 | else if (IsVecType(rvalue) || IsVecType(ptype1) || IsVecType(ptype2) || IsVecType(ptype3)) |
| 593 | { |
| 594 | ASSERT(!ptype4 && !ptype5); |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 595 | insertUnmangledBuiltIn(name, ext, level); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 596 | insertBuiltIn(level, op, ext, VectorType(rvalue, 2), name, VectorType(ptype1, 2), |
| 597 | VectorType(ptype2, 2), VectorType(ptype3, 2)); |
| 598 | insertBuiltIn(level, op, ext, VectorType(rvalue, 3), name, VectorType(ptype1, 3), |
| 599 | VectorType(ptype2, 3), VectorType(ptype3, 3)); |
| 600 | insertBuiltIn(level, op, ext, VectorType(rvalue, 4), name, VectorType(ptype1, 4), |
| 601 | VectorType(ptype2, 4), VectorType(ptype3, 4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 602 | } |
| 603 | else |
| 604 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 605 | size_t paramCount = 1; |
| 606 | TConstParameter *params = new TConstParameter[5]; |
| 607 | new (params) TConstParameter(ptype1); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 608 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 609 | if (ptype2) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 610 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 611 | new (params + 1) TConstParameter(ptype2); |
| 612 | paramCount = 2; |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 613 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 614 | if (ptype3) |
| 615 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 616 | new (params + 2) TConstParameter(ptype3); |
| 617 | paramCount = 3; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 618 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 619 | if (ptype4) |
| 620 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 621 | new (params + 3) TConstParameter(ptype4); |
| 622 | paramCount = 4; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 623 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 624 | if (ptype5) |
| 625 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 626 | new (params + 4) TConstParameter(ptype5); |
| 627 | paramCount = 5; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 628 | } |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 629 | TFunction *function = |
| 630 | new TFunction(this, ImmutableString(name), ext, params, paramCount, rvalue, op, false); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 631 | |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 632 | ASSERT(hasUnmangledBuiltInAtLevel(name, level)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 633 | insert(level, function); |
| 634 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 637 | void TSymbolTable::insertBuiltInOp(ESymbolLevel level, |
| 638 | TOperator op, |
| 639 | const TType *rvalue, |
| 640 | const TType *ptype1, |
| 641 | const TType *ptype2, |
| 642 | const TType *ptype3, |
| 643 | const TType *ptype4, |
| 644 | const TType *ptype5) |
| 645 | { |
| 646 | const char *name = GetOperatorString(op); |
| 647 | ASSERT(strlen(name) > 0); |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 648 | insertUnmangledBuiltIn(name, TExtension::UNDEFINED, level); |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 649 | insertBuiltIn(level, op, TExtension::UNDEFINED, rvalue, name, ptype1, ptype2, ptype3, ptype4, |
| 650 | ptype5); |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | void TSymbolTable::insertBuiltInOp(ESymbolLevel level, |
| 654 | TOperator op, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 655 | TExtension ext, |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 656 | const TType *rvalue, |
| 657 | const TType *ptype1, |
| 658 | const TType *ptype2, |
| 659 | const TType *ptype3, |
| 660 | const TType *ptype4, |
| 661 | const TType *ptype5) |
| 662 | { |
| 663 | const char *name = GetOperatorString(op); |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 664 | insertUnmangledBuiltIn(name, ext, level); |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 665 | insertBuiltIn(level, op, ext, rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5); |
| 666 | } |
| 667 | |
Martin Radev | d7c5b0a | 2016-07-27 14:04:43 +0300 | [diff] [blame] | 668 | void TSymbolTable::insertBuiltInFunctionNoParameters(ESymbolLevel level, |
| 669 | TOperator op, |
| 670 | const TType *rvalue, |
| 671 | const char *name) |
| 672 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 673 | insertUnmangledBuiltIn(name, TExtension::UNDEFINED, level); |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 674 | insert(level, new TFunction(this, ImmutableString(name), TExtension::UNDEFINED, nullptr, 0, |
| 675 | rvalue, op, false)); |
Martin Radev | d7c5b0a | 2016-07-27 14:04:43 +0300 | [diff] [blame] | 676 | } |
| 677 | |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 678 | void TSymbolTable::insertBuiltInFunctionNoParametersExt(ESymbolLevel level, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 679 | TExtension ext, |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 680 | TOperator op, |
| 681 | const TType *rvalue, |
| 682 | const char *name) |
| 683 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 684 | insertUnmangledBuiltIn(name, ext, level); |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame] | 685 | insert(level, new TFunction(this, ImmutableString(name), ext, nullptr, 0, rvalue, op, false)); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 686 | } |
| 687 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 688 | void TSymbolTable::setDefaultPrecision(TBasicType type, TPrecision prec) |
| 689 | { |
| 690 | int indexOfLastElement = static_cast<int>(mPrecisionStack.size()) - 1; |
| 691 | // Uses map operator [], overwrites the current value |
| 692 | (*mPrecisionStack[indexOfLastElement])[type] = prec; |
| 693 | } |
| 694 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 695 | TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 696 | { |
| 697 | if (!SupportsPrecision(type)) |
| 698 | return EbpUndefined; |
| 699 | |
| 700 | // unsigned integers use the same precision as signed |
| 701 | TBasicType baseType = (type == EbtUInt) ? EbtInt : type; |
| 702 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 703 | int level = static_cast<int>(mPrecisionStack.size()) - 1; |
| 704 | ASSERT(level >= 0); // Just to be safe. Should not happen. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 705 | // 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] | 706 | TPrecision prec = EbpUndefined; |
| 707 | while (level >= 0) |
| 708 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 709 | PrecisionStackLevel::iterator it = mPrecisionStack[level]->find(baseType); |
| 710 | if (it != mPrecisionStack[level]->end()) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 711 | { |
| 712 | prec = (*it).second; |
| 713 | break; |
| 714 | } |
| 715 | level--; |
| 716 | } |
| 717 | return prec; |
| 718 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 719 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 720 | void TSymbolTable::addInvariantVarying(const ImmutableString &originalName) |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 721 | { |
| 722 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 723 | mTable.back()->addInvariantVarying(originalName); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 724 | } |
| 725 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 726 | bool TSymbolTable::isVaryingInvariant(const ImmutableString &originalName) const |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 727 | { |
| 728 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 729 | return mTable.back()->isVaryingInvariant(originalName); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | void TSymbolTable::setGlobalInvariant(bool invariant) |
| 733 | { |
| 734 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 735 | mTable.back()->setGlobalInvariant(invariant); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 736 | } |
| 737 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 738 | void TSymbolTable::insertUnmangledBuiltIn(const char *name, TExtension ext, ESymbolLevel level) |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 739 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 740 | ASSERT(level >= 0 && level <= LAST_BUILTIN_LEVEL); |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 741 | ASSERT(mUserDefinedUniqueIdsStart == -1); |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 742 | mBuiltInTable[level]->insertUnmangledBuiltIn(name, ext); |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | bool TSymbolTable::hasUnmangledBuiltInAtLevel(const char *name, ESymbolLevel level) |
| 746 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 747 | ASSERT(level >= 0 && level <= LAST_BUILTIN_LEVEL); |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 748 | return mBuiltInTable[level]->getUnmangledBuiltIn(ImmutableString(name)) != nullptr; |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 749 | } |
| 750 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 751 | const UnmangledBuiltIn *TSymbolTable::getUnmangledBuiltInForShaderVersion( |
| 752 | const ImmutableString &name, |
| 753 | int shaderVersion) |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 754 | { |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 755 | for (int level = LAST_BUILTIN_LEVEL; level >= 0; --level) |
| 756 | { |
| 757 | if (level == ESSL3_1_BUILTINS && shaderVersion != 310) |
| 758 | { |
| 759 | --level; |
| 760 | } |
| 761 | if (level == ESSL3_BUILTINS && shaderVersion < 300) |
| 762 | { |
| 763 | --level; |
| 764 | } |
| 765 | if (level == ESSL1_BUILTINS && shaderVersion != 100) |
| 766 | { |
| 767 | --level; |
| 768 | } |
| 769 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 770 | const UnmangledBuiltIn *builtIn = mBuiltInTable[level]->getUnmangledBuiltIn(name); |
| 771 | if (builtIn != nullptr) |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 772 | { |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 773 | return builtIn; |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 774 | } |
| 775 | } |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 776 | return nullptr; |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 777 | } |
| 778 | |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 779 | void TSymbolTable::markBuiltInInitializationFinished() |
| 780 | { |
| 781 | mUserDefinedUniqueIdsStart = mUniqueIdCounter; |
| 782 | } |
| 783 | |
| 784 | void TSymbolTable::clearCompilationResults() |
| 785 | { |
| 786 | mUniqueIdCounter = mUserDefinedUniqueIdsStart; |
| 787 | |
| 788 | // User-defined scopes should have already been cleared when the compilation finished. |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 789 | ASSERT(mTable.size() == 0u); |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | int TSymbolTable::nextUniqueIdValue() |
| 793 | { |
| 794 | ASSERT(mUniqueIdCounter < std::numeric_limits<int>::max()); |
| 795 | return ++mUniqueIdCounter; |
| 796 | } |
| 797 | |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 798 | void TSymbolTable::initializeBuiltIns(sh::GLenum type, |
| 799 | ShShaderSpec spec, |
| 800 | const ShBuiltInResources &resources) |
| 801 | { |
| 802 | ASSERT(isEmpty()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 803 | pushBuiltInLevel(); // COMMON_BUILTINS |
| 804 | pushBuiltInLevel(); // ESSL1_BUILTINS |
| 805 | pushBuiltInLevel(); // ESSL3_BUILTINS |
| 806 | pushBuiltInLevel(); // ESSL3_1_BUILTINS |
| 807 | pushBuiltInLevel(); // GLSL_BUILTINS |
| 808 | |
| 809 | // We need just one precision stack level for predefined precisions. |
| 810 | mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel)); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 811 | |
| 812 | switch (type) |
| 813 | { |
| 814 | case GL_FRAGMENT_SHADER: |
| 815 | setDefaultPrecision(EbtInt, EbpMedium); |
| 816 | break; |
| 817 | case GL_VERTEX_SHADER: |
| 818 | case GL_COMPUTE_SHADER: |
| 819 | case GL_GEOMETRY_SHADER_EXT: |
| 820 | setDefaultPrecision(EbtInt, EbpHigh); |
| 821 | setDefaultPrecision(EbtFloat, EbpHigh); |
| 822 | break; |
| 823 | default: |
| 824 | UNREACHABLE(); |
| 825 | } |
| 826 | // Set defaults for sampler types that have default precision, even those that are |
| 827 | // only available if an extension exists. |
| 828 | // New sampler types in ESSL3 don't have default precision. ESSL1 types do. |
| 829 | initSamplerDefaultPrecision(EbtSampler2D); |
| 830 | initSamplerDefaultPrecision(EbtSamplerCube); |
| 831 | // SamplerExternalOES is specified in the extension to have default precision. |
| 832 | initSamplerDefaultPrecision(EbtSamplerExternalOES); |
| 833 | // SamplerExternal2DY2YEXT is specified in the extension to have default precision. |
| 834 | initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT); |
| 835 | // It isn't specified whether Sampler2DRect has default precision. |
| 836 | initSamplerDefaultPrecision(EbtSampler2DRect); |
| 837 | |
| 838 | setDefaultPrecision(EbtAtomicCounter, EbpHigh); |
| 839 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 840 | initializeBuiltInFunctions(type); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 841 | initializeBuiltInVariables(type, spec, resources); |
| 842 | markBuiltInInitializationFinished(); |
| 843 | } |
| 844 | |
| 845 | void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType) |
| 846 | { |
| 847 | ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd); |
| 848 | setDefaultPrecision(samplerType, EbpLow); |
| 849 | } |
| 850 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 851 | void TSymbolTable::initializeBuiltInFunctions(sh::GLenum type) |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 852 | { |
| 853 | const TType *voidType = StaticType::GetBasic<EbtVoid>(); |
| 854 | const TType *float1 = StaticType::GetBasic<EbtFloat>(); |
| 855 | const TType *float2 = StaticType::GetBasic<EbtFloat, 2>(); |
| 856 | const TType *float3 = StaticType::GetBasic<EbtFloat, 3>(); |
| 857 | const TType *float4 = StaticType::GetBasic<EbtFloat, 4>(); |
| 858 | const TType *int1 = StaticType::GetBasic<EbtInt>(); |
| 859 | const TType *int2 = StaticType::GetBasic<EbtInt, 2>(); |
| 860 | const TType *int3 = StaticType::GetBasic<EbtInt, 3>(); |
| 861 | const TType *uint1 = StaticType::GetBasic<EbtUInt>(); |
| 862 | const TType *bool1 = StaticType::GetBasic<EbtBool>(); |
| 863 | const TType *genType = StaticType::GetBasic<EbtGenType>(); |
| 864 | const TType *genIType = StaticType::GetBasic<EbtGenIType>(); |
| 865 | const TType *genUType = StaticType::GetBasic<EbtGenUType>(); |
| 866 | const TType *genBType = StaticType::GetBasic<EbtGenBType>(); |
| 867 | |
| 868 | // |
| 869 | // Angle and Trigonometric Functions. |
| 870 | // |
| 871 | insertBuiltInOp(COMMON_BUILTINS, EOpRadians, genType, genType); |
| 872 | insertBuiltInOp(COMMON_BUILTINS, EOpDegrees, genType, genType); |
| 873 | insertBuiltInOp(COMMON_BUILTINS, EOpSin, genType, genType); |
| 874 | insertBuiltInOp(COMMON_BUILTINS, EOpCos, genType, genType); |
| 875 | insertBuiltInOp(COMMON_BUILTINS, EOpTan, genType, genType); |
| 876 | insertBuiltInOp(COMMON_BUILTINS, EOpAsin, genType, genType); |
| 877 | insertBuiltInOp(COMMON_BUILTINS, EOpAcos, genType, genType); |
| 878 | insertBuiltInOp(COMMON_BUILTINS, EOpAtan, genType, genType, genType); |
| 879 | insertBuiltInOp(COMMON_BUILTINS, EOpAtan, genType, genType); |
| 880 | insertBuiltInOp(ESSL3_BUILTINS, EOpSinh, genType, genType); |
| 881 | insertBuiltInOp(ESSL3_BUILTINS, EOpCosh, genType, genType); |
| 882 | insertBuiltInOp(ESSL3_BUILTINS, EOpTanh, genType, genType); |
| 883 | insertBuiltInOp(ESSL3_BUILTINS, EOpAsinh, genType, genType); |
| 884 | insertBuiltInOp(ESSL3_BUILTINS, EOpAcosh, genType, genType); |
| 885 | insertBuiltInOp(ESSL3_BUILTINS, EOpAtanh, genType, genType); |
| 886 | |
| 887 | // |
| 888 | // Exponential Functions. |
| 889 | // |
| 890 | insertBuiltInOp(COMMON_BUILTINS, EOpPow, genType, genType, genType); |
| 891 | insertBuiltInOp(COMMON_BUILTINS, EOpExp, genType, genType); |
| 892 | insertBuiltInOp(COMMON_BUILTINS, EOpLog, genType, genType); |
| 893 | insertBuiltInOp(COMMON_BUILTINS, EOpExp2, genType, genType); |
| 894 | insertBuiltInOp(COMMON_BUILTINS, EOpLog2, genType, genType); |
| 895 | insertBuiltInOp(COMMON_BUILTINS, EOpSqrt, genType, genType); |
| 896 | insertBuiltInOp(COMMON_BUILTINS, EOpInverseSqrt, genType, genType); |
| 897 | |
| 898 | // |
| 899 | // Common Functions. |
| 900 | // |
| 901 | insertBuiltInOp(COMMON_BUILTINS, EOpAbs, genType, genType); |
| 902 | insertBuiltInOp(ESSL3_BUILTINS, EOpAbs, genIType, genIType); |
| 903 | insertBuiltInOp(COMMON_BUILTINS, EOpSign, genType, genType); |
| 904 | insertBuiltInOp(ESSL3_BUILTINS, EOpSign, genIType, genIType); |
| 905 | insertBuiltInOp(COMMON_BUILTINS, EOpFloor, genType, genType); |
| 906 | insertBuiltInOp(ESSL3_BUILTINS, EOpTrunc, genType, genType); |
| 907 | insertBuiltInOp(ESSL3_BUILTINS, EOpRound, genType, genType); |
| 908 | insertBuiltInOp(ESSL3_BUILTINS, EOpRoundEven, genType, genType); |
| 909 | insertBuiltInOp(COMMON_BUILTINS, EOpCeil, genType, genType); |
| 910 | insertBuiltInOp(COMMON_BUILTINS, EOpFract, genType, genType); |
| 911 | insertBuiltInOp(COMMON_BUILTINS, EOpMod, genType, genType, float1); |
| 912 | insertBuiltInOp(COMMON_BUILTINS, EOpMod, genType, genType, genType); |
| 913 | insertBuiltInOp(COMMON_BUILTINS, EOpMin, genType, genType, float1); |
| 914 | insertBuiltInOp(COMMON_BUILTINS, EOpMin, genType, genType, genType); |
| 915 | insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genIType, genIType, genIType); |
| 916 | insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genIType, genIType, int1); |
| 917 | insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genUType, genUType, genUType); |
| 918 | insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genUType, genUType, uint1); |
| 919 | insertBuiltInOp(COMMON_BUILTINS, EOpMax, genType, genType, float1); |
| 920 | insertBuiltInOp(COMMON_BUILTINS, EOpMax, genType, genType, genType); |
| 921 | insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genIType, genIType, genIType); |
| 922 | insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genIType, genIType, int1); |
| 923 | insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genUType, genUType, genUType); |
| 924 | insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genUType, genUType, uint1); |
| 925 | insertBuiltInOp(COMMON_BUILTINS, EOpClamp, genType, genType, float1, float1); |
| 926 | insertBuiltInOp(COMMON_BUILTINS, EOpClamp, genType, genType, genType, genType); |
| 927 | insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genIType, genIType, int1, int1); |
| 928 | insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genIType, genIType, genIType, genIType); |
| 929 | insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genUType, genUType, uint1, uint1); |
| 930 | insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genUType, genUType, genUType, genUType); |
| 931 | insertBuiltInOp(COMMON_BUILTINS, EOpMix, genType, genType, genType, float1); |
| 932 | insertBuiltInOp(COMMON_BUILTINS, EOpMix, genType, genType, genType, genType); |
| 933 | insertBuiltInOp(ESSL3_BUILTINS, EOpMix, genType, genType, genType, genBType); |
| 934 | insertBuiltInOp(COMMON_BUILTINS, EOpStep, genType, genType, genType); |
| 935 | insertBuiltInOp(COMMON_BUILTINS, EOpStep, genType, float1, genType); |
| 936 | insertBuiltInOp(COMMON_BUILTINS, EOpSmoothStep, genType, genType, genType, genType); |
| 937 | insertBuiltInOp(COMMON_BUILTINS, EOpSmoothStep, genType, float1, float1, genType); |
| 938 | |
| 939 | const TType *outGenType = StaticType::GetQualified<EbtGenType, EvqOut>(); |
| 940 | const TType *outGenIType = StaticType::GetQualified<EbtGenIType, EvqOut>(); |
| 941 | |
| 942 | insertBuiltInOp(ESSL3_BUILTINS, EOpModf, genType, genType, outGenType); |
| 943 | |
| 944 | insertBuiltInOp(ESSL3_BUILTINS, EOpIsNan, genBType, genType); |
| 945 | insertBuiltInOp(ESSL3_BUILTINS, EOpIsInf, genBType, genType); |
| 946 | insertBuiltInOp(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, genType); |
| 947 | insertBuiltInOp(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, genType); |
| 948 | insertBuiltInOp(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, genIType); |
| 949 | insertBuiltInOp(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, genUType); |
| 950 | |
| 951 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFrexp, genType, genType, outGenIType); |
| 952 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpLdexp, genType, genType, genIType); |
| 953 | |
| 954 | insertBuiltInOp(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, float2); |
| 955 | insertBuiltInOp(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, float2); |
| 956 | insertBuiltInOp(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, float2); |
| 957 | insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, uint1); |
| 958 | insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, uint1); |
| 959 | insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, uint1); |
| 960 | |
| 961 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpPackUnorm4x8, uint1, float4); |
| 962 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpPackSnorm4x8, uint1, float4); |
| 963 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUnpackUnorm4x8, float4, uint1); |
| 964 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUnpackSnorm4x8, float4, uint1); |
| 965 | |
| 966 | // |
| 967 | // Geometric Functions. |
| 968 | // |
| 969 | insertBuiltInOp(COMMON_BUILTINS, EOpLength, float1, genType); |
| 970 | insertBuiltInOp(COMMON_BUILTINS, EOpDistance, float1, genType, genType); |
| 971 | insertBuiltInOp(COMMON_BUILTINS, EOpDot, float1, genType, genType); |
| 972 | insertBuiltInOp(COMMON_BUILTINS, EOpCross, float3, float3, float3); |
| 973 | insertBuiltInOp(COMMON_BUILTINS, EOpNormalize, genType, genType); |
| 974 | insertBuiltInOp(COMMON_BUILTINS, EOpFaceforward, genType, genType, genType, genType); |
| 975 | insertBuiltInOp(COMMON_BUILTINS, EOpReflect, genType, genType, genType); |
| 976 | insertBuiltInOp(COMMON_BUILTINS, EOpRefract, genType, genType, genType, float1); |
| 977 | |
| 978 | const TType *mat2 = StaticType::GetBasic<EbtFloat, 2, 2>(); |
| 979 | const TType *mat3 = StaticType::GetBasic<EbtFloat, 3, 3>(); |
| 980 | const TType *mat4 = StaticType::GetBasic<EbtFloat, 4, 4>(); |
| 981 | const TType *mat2x3 = StaticType::GetBasic<EbtFloat, 2, 3>(); |
| 982 | const TType *mat3x2 = StaticType::GetBasic<EbtFloat, 3, 2>(); |
| 983 | const TType *mat2x4 = StaticType::GetBasic<EbtFloat, 2, 4>(); |
| 984 | const TType *mat4x2 = StaticType::GetBasic<EbtFloat, 4, 2>(); |
| 985 | const TType *mat3x4 = StaticType::GetBasic<EbtFloat, 3, 4>(); |
| 986 | const TType *mat4x3 = StaticType::GetBasic<EbtFloat, 4, 3>(); |
| 987 | |
| 988 | // |
| 989 | // Matrix Functions. |
| 990 | // |
| 991 | insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat2, mat2, mat2); |
| 992 | insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat3, mat3, mat3); |
| 993 | insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat4, mat4, mat4); |
| 994 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat2x3, mat2x3, mat2x3); |
| 995 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat3x2, mat3x2, mat3x2); |
| 996 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat2x4, mat2x4, mat2x4); |
| 997 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat4x2, mat4x2, mat4x2); |
| 998 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat3x4, mat3x4, mat3x4); |
| 999 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat4x3, mat4x3, mat4x3); |
| 1000 | |
| 1001 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2, float2, float2); |
| 1002 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3, float3, float3); |
| 1003 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4, float4, float4); |
| 1004 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, float3, float2); |
| 1005 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, float2, float3); |
| 1006 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, float4, float2); |
| 1007 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, float2, float4); |
| 1008 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, float4, float3); |
| 1009 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, float3, float4); |
| 1010 | |
| 1011 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2, mat2); |
| 1012 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3, mat3); |
| 1013 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4, mat4); |
| 1014 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2x3, mat3x2); |
| 1015 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3x2, mat2x3); |
| 1016 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2x4, mat4x2); |
| 1017 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4x2, mat2x4); |
| 1018 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3x4, mat4x3); |
| 1019 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4x3, mat3x4); |
| 1020 | |
| 1021 | insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat2); |
| 1022 | insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat3); |
| 1023 | insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat4); |
| 1024 | |
| 1025 | insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat2, mat2); |
| 1026 | insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat3, mat3); |
| 1027 | insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat4, mat4); |
| 1028 | |
| 1029 | const TType *vec = StaticType::GetBasic<EbtVec>(); |
| 1030 | const TType *ivec = StaticType::GetBasic<EbtIVec>(); |
| 1031 | const TType *uvec = StaticType::GetBasic<EbtUVec>(); |
| 1032 | const TType *bvec = StaticType::GetBasic<EbtBVec>(); |
| 1033 | |
| 1034 | // |
| 1035 | // Vector relational functions. |
| 1036 | // |
| 1037 | insertBuiltInOp(COMMON_BUILTINS, EOpLessThanComponentWise, bvec, vec, vec); |
| 1038 | insertBuiltInOp(COMMON_BUILTINS, EOpLessThanComponentWise, bvec, ivec, ivec); |
| 1039 | insertBuiltInOp(ESSL3_BUILTINS, EOpLessThanComponentWise, bvec, uvec, uvec); |
| 1040 | insertBuiltInOp(COMMON_BUILTINS, EOpLessThanEqualComponentWise, bvec, vec, vec); |
| 1041 | insertBuiltInOp(COMMON_BUILTINS, EOpLessThanEqualComponentWise, bvec, ivec, ivec); |
| 1042 | insertBuiltInOp(ESSL3_BUILTINS, EOpLessThanEqualComponentWise, bvec, uvec, uvec); |
| 1043 | insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanComponentWise, bvec, vec, vec); |
| 1044 | insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanComponentWise, bvec, ivec, ivec); |
| 1045 | insertBuiltInOp(ESSL3_BUILTINS, EOpGreaterThanComponentWise, bvec, uvec, uvec); |
| 1046 | insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, vec, vec); |
| 1047 | insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, ivec, ivec); |
| 1048 | insertBuiltInOp(ESSL3_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, uvec, uvec); |
| 1049 | insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, vec, vec); |
| 1050 | insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, ivec, ivec); |
| 1051 | insertBuiltInOp(ESSL3_BUILTINS, EOpEqualComponentWise, bvec, uvec, uvec); |
| 1052 | insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, bvec, bvec); |
| 1053 | insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, vec, vec); |
| 1054 | insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, ivec, ivec); |
| 1055 | insertBuiltInOp(ESSL3_BUILTINS, EOpNotEqualComponentWise, bvec, uvec, uvec); |
| 1056 | insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, bvec, bvec); |
| 1057 | insertBuiltInOp(COMMON_BUILTINS, EOpAny, bool1, bvec); |
| 1058 | insertBuiltInOp(COMMON_BUILTINS, EOpAll, bool1, bvec); |
| 1059 | insertBuiltInOp(COMMON_BUILTINS, EOpLogicalNotComponentWise, bvec, bvec); |
| 1060 | |
| 1061 | // |
| 1062 | // Integer functions |
| 1063 | // |
| 1064 | const TType *outGenUType = StaticType::GetQualified<EbtGenUType, EvqOut>(); |
| 1065 | |
| 1066 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldExtract, genIType, genIType, int1, int1); |
| 1067 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldExtract, genUType, genUType, int1, int1); |
| 1068 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldInsert, genIType, genIType, genIType, int1, int1); |
| 1069 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldInsert, genUType, genUType, genUType, int1, int1); |
| 1070 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldReverse, genIType, genIType); |
| 1071 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldReverse, genUType, genUType); |
| 1072 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitCount, genIType, genIType); |
| 1073 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitCount, genIType, genUType); |
| 1074 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFindLSB, genIType, genIType); |
| 1075 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFindLSB, genIType, genUType); |
| 1076 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFindMSB, genIType, genIType); |
| 1077 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFindMSB, genIType, genUType); |
| 1078 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUaddCarry, genUType, genUType, genUType, outGenUType); |
| 1079 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUsubBorrow, genUType, genUType, genUType, outGenUType); |
| 1080 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUmulExtended, voidType, genUType, genUType, outGenUType, |
| 1081 | outGenUType); |
| 1082 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpImulExtended, voidType, genIType, genIType, outGenIType, |
| 1083 | outGenIType); |
| 1084 | |
| 1085 | const TType *sampler2D = StaticType::GetBasic<EbtSampler2D>(); |
| 1086 | const TType *samplerCube = StaticType::GetBasic<EbtSamplerCube>(); |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1087 | const TType *samplerExternalOES = StaticType::GetBasic<EbtSamplerExternalOES>(); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1088 | |
| 1089 | // |
| 1090 | // Texture Functions for GLSL ES 1.0 |
| 1091 | // |
| 1092 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2); |
| 1093 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3); |
| 1094 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4); |
| 1095 | insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3); |
| 1096 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1097 | // These are extension functions from OES_EGL_image_external and |
| 1098 | // NV_EGL_stream_consumer_external. We don't have a way to mark a built-in with two alternative |
| 1099 | // extensions, so these are marked with none. This is fine, since these functions overload core |
| 1100 | // function names and the functions require a samplerExternalOES parameter, which can only be |
| 1101 | // created if one of the extensions is enabled. |
| 1102 | // TODO(oetuaho): Consider implementing a cleaner solution. |
| 1103 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2); |
| 1104 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3); |
| 1105 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1106 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1107 | // Note that ARB_texture_rectangle extension directive defaults to enabled in case the extension |
| 1108 | // is supported. The symbols are still conditional on the extension. |
| 1109 | const TType *sampler2DRect = StaticType::GetBasic<EbtSampler2DRect>(); |
| 1110 | insertBuiltIn(ESSL1_BUILTINS, TExtension::ARB_texture_rectangle, float4, "texture2DRect", |
| 1111 | sampler2DRect, float2); |
| 1112 | insertBuiltIn(ESSL1_BUILTINS, TExtension::ARB_texture_rectangle, float4, "texture2DRectProj", |
| 1113 | sampler2DRect, float3); |
| 1114 | insertBuiltIn(ESSL1_BUILTINS, TExtension::ARB_texture_rectangle, float4, "texture2DRectProj", |
| 1115 | sampler2DRect, float4); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1116 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1117 | /* The *Grad* variants are new to both vertex and fragment shaders; the fragment |
| 1118 | * shader specific pieces are added separately below. |
| 1119 | */ |
| 1120 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, "texture2DGradEXT", |
| 1121 | sampler2D, float2, float2, float2); |
| 1122 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1123 | "texture2DProjGradEXT", sampler2D, float3, float2, float2); |
| 1124 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1125 | "texture2DProjGradEXT", sampler2D, float4, float2, float2); |
| 1126 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, "textureCubeGradEXT", |
| 1127 | samplerCube, float3, float3, float3); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1128 | |
| 1129 | if (type == GL_FRAGMENT_SHADER) |
| 1130 | { |
| 1131 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1); |
| 1132 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1); |
| 1133 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1); |
| 1134 | insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1); |
| 1135 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1136 | insertBuiltInOp(ESSL1_BUILTINS, EOpDFdx, TExtension::OES_standard_derivatives, genType, |
| 1137 | genType); |
| 1138 | insertBuiltInOp(ESSL1_BUILTINS, EOpDFdy, TExtension::OES_standard_derivatives, genType, |
| 1139 | genType); |
| 1140 | insertBuiltInOp(ESSL1_BUILTINS, EOpFwidth, TExtension::OES_standard_derivatives, genType, |
| 1141 | genType); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1142 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1143 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, "texture2DLodEXT", |
| 1144 | sampler2D, float2, float1); |
| 1145 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1146 | "texture2DProjLodEXT", sampler2D, float3, float1); |
| 1147 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1148 | "texture2DProjLodEXT", sampler2D, float4, float1); |
| 1149 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1150 | "textureCubeLodEXT", samplerCube, float3, float1); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | if (type == GL_VERTEX_SHADER) |
| 1154 | { |
| 1155 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1); |
| 1156 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1); |
| 1157 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1); |
| 1158 | insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1); |
| 1159 | } |
| 1160 | |
| 1161 | const TType *gvec4 = StaticType::GetBasic<EbtGVec4>(); |
| 1162 | |
| 1163 | const TType *gsampler2D = StaticType::GetBasic<EbtGSampler2D>(); |
| 1164 | const TType *gsamplerCube = StaticType::GetBasic<EbtGSamplerCube>(); |
| 1165 | const TType *gsampler3D = StaticType::GetBasic<EbtGSampler3D>(); |
| 1166 | const TType *gsampler2DArray = StaticType::GetBasic<EbtGSampler2DArray>(); |
| 1167 | const TType *gsampler2DMS = StaticType::GetBasic<EbtGSampler2DMS>(); |
| 1168 | |
| 1169 | // |
| 1170 | // Texture Functions for GLSL ES 3.0 |
| 1171 | // |
| 1172 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2); |
| 1173 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3); |
| 1174 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3); |
| 1175 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3); |
| 1176 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3); |
| 1177 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4); |
| 1178 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4); |
| 1179 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1); |
| 1180 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1); |
| 1181 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1); |
| 1182 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1); |
| 1183 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1184 | insertBuiltIn(ESSL3_BUILTINS, TExtension::OES_EGL_image_external_essl3, float4, "texture", |
| 1185 | samplerExternalOES, float2); |
| 1186 | insertBuiltIn(ESSL3_BUILTINS, TExtension::OES_EGL_image_external_essl3, float4, "textureProj", |
| 1187 | samplerExternalOES, float3); |
| 1188 | insertBuiltIn(ESSL3_BUILTINS, TExtension::OES_EGL_image_external_essl3, float4, "textureProj", |
| 1189 | samplerExternalOES, float4); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1190 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1191 | const TType *samplerExternal2DY2YEXT = StaticType::GetBasic<EbtSamplerExternal2DY2YEXT>(); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1192 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1193 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "texture", |
| 1194 | samplerExternal2DY2YEXT, float2); |
| 1195 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "textureProj", |
| 1196 | samplerExternal2DY2YEXT, float3); |
| 1197 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "textureProj", |
| 1198 | samplerExternal2DY2YEXT, float4); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1199 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1200 | const TType *yuvCscStandardEXT = StaticType::GetBasic<EbtYuvCscStandardEXT>(); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1201 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1202 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float3, "rgb_2_yuv", float3, |
| 1203 | yuvCscStandardEXT); |
| 1204 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float3, "yuv_2_rgb", float3, |
| 1205 | yuvCscStandardEXT); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1206 | |
| 1207 | if (type == GL_FRAGMENT_SHADER) |
| 1208 | { |
| 1209 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1); |
| 1210 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1); |
| 1211 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1); |
| 1212 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1); |
| 1213 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1); |
| 1214 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1); |
| 1215 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1); |
| 1216 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1217 | insertBuiltIn(ESSL3_BUILTINS, TExtension::OES_EGL_image_external_essl3, float4, "texture", |
| 1218 | samplerExternalOES, float2, float1); |
| 1219 | insertBuiltIn(ESSL3_BUILTINS, TExtension::OES_EGL_image_external_essl3, float4, |
| 1220 | "textureProj", samplerExternalOES, float3, float1); |
| 1221 | insertBuiltIn(ESSL3_BUILTINS, TExtension::OES_EGL_image_external_essl3, float4, |
| 1222 | "textureProj", samplerExternalOES, float4, float1); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1223 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1224 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "texture", |
| 1225 | samplerExternal2DY2YEXT, float2, float1); |
| 1226 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "textureProj", |
| 1227 | samplerExternal2DY2YEXT, float3, float1); |
| 1228 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "textureProj", |
| 1229 | samplerExternal2DY2YEXT, float4, float1); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | const TType *sampler2DShadow = StaticType::GetBasic<EbtSampler2DShadow>(); |
| 1233 | const TType *samplerCubeShadow = StaticType::GetBasic<EbtSamplerCubeShadow>(); |
| 1234 | const TType *sampler2DArrayShadow = StaticType::GetBasic<EbtSampler2DArrayShadow>(); |
| 1235 | |
| 1236 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3); |
| 1237 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4); |
| 1238 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4); |
| 1239 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4); |
| 1240 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1); |
| 1241 | |
| 1242 | if (type == GL_FRAGMENT_SHADER) |
| 1243 | { |
| 1244 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1); |
| 1245 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1); |
| 1246 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1); |
| 1247 | } |
| 1248 | |
| 1249 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1); |
| 1250 | insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1); |
| 1251 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1); |
| 1252 | insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1); |
| 1253 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1); |
| 1254 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1); |
| 1255 | insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1); |
| 1256 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2DMS); |
| 1257 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1258 | insertBuiltIn(ESSL3_BUILTINS, TExtension::OES_EGL_image_external_essl3, int2, "textureSize", |
| 1259 | samplerExternalOES, int1); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1260 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1261 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, int2, "textureSize", |
| 1262 | samplerExternal2DY2YEXT, int1); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1263 | |
| 1264 | if (type == GL_FRAGMENT_SHADER) |
| 1265 | { |
| 1266 | insertBuiltInOp(ESSL3_BUILTINS, EOpDFdx, genType, genType); |
| 1267 | insertBuiltInOp(ESSL3_BUILTINS, EOpDFdy, genType, genType); |
| 1268 | insertBuiltInOp(ESSL3_BUILTINS, EOpFwidth, genType, genType); |
| 1269 | } |
| 1270 | |
| 1271 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2); |
| 1272 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3); |
| 1273 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2); |
| 1274 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2); |
| 1275 | |
| 1276 | if (type == GL_FRAGMENT_SHADER) |
| 1277 | { |
| 1278 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1); |
| 1279 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1); |
| 1280 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, |
| 1281 | float1); |
| 1282 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, |
| 1283 | float1); |
| 1284 | } |
| 1285 | |
| 1286 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2); |
| 1287 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2); |
| 1288 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3); |
| 1289 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2); |
| 1290 | |
| 1291 | if (type == GL_FRAGMENT_SHADER) |
| 1292 | { |
| 1293 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1); |
| 1294 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1); |
| 1295 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1); |
| 1296 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, |
| 1297 | float1); |
| 1298 | } |
| 1299 | |
| 1300 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2); |
| 1301 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3); |
| 1302 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, |
| 1303 | int2); |
| 1304 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2); |
| 1305 | |
| 1306 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1); |
| 1307 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1); |
| 1308 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1); |
| 1309 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1); |
| 1310 | |
| 1311 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2); |
| 1312 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2); |
| 1313 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3); |
| 1314 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, |
| 1315 | int2); |
| 1316 | |
| 1317 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1); |
| 1318 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1); |
| 1319 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1); |
| 1320 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1321 | insertBuiltIn(ESSL3_BUILTINS, TExtension::OES_EGL_image_external_essl3, float4, "texelFetch", |
| 1322 | samplerExternalOES, int2, int1); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1323 | |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1324 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "texelFetch", |
| 1325 | samplerExternal2DY2YEXT, int2, int1); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1326 | |
| 1327 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2); |
| 1328 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3); |
| 1329 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2); |
| 1330 | |
| 1331 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2); |
| 1332 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3); |
| 1333 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3); |
| 1334 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2); |
| 1335 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3); |
| 1336 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2); |
| 1337 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, |
| 1338 | float2); |
| 1339 | |
| 1340 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, |
| 1341 | int2); |
| 1342 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, |
| 1343 | int3); |
| 1344 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, |
| 1345 | float2, int2); |
| 1346 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, |
| 1347 | float2, int2); |
| 1348 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, |
| 1349 | float2, int2); |
| 1350 | |
| 1351 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2); |
| 1352 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2); |
| 1353 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3); |
| 1354 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, |
| 1355 | float2); |
| 1356 | |
| 1357 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, |
| 1358 | float2, int2); |
| 1359 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, |
| 1360 | float2, int2); |
| 1361 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, |
| 1362 | float3, int3); |
| 1363 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, |
| 1364 | float2, int2); |
| 1365 | |
| 1366 | const TType *atomicCounter = StaticType::GetBasic<EbtAtomicCounter>(); |
| 1367 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicCounter", atomicCounter); |
| 1368 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicCounterIncrement", atomicCounter); |
| 1369 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicCounterDecrement", atomicCounter); |
| 1370 | |
| 1371 | // Insert all atomic memory functions |
| 1372 | const TType *int1InOut = StaticType::GetQualified<EbtInt, EvqInOut>(); |
| 1373 | const TType *uint1InOut = StaticType::GetQualified<EbtUInt, EvqInOut>(); |
| 1374 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicAdd", uint1InOut, uint1); |
| 1375 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicAdd", int1InOut, int1); |
| 1376 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicMin", uint1InOut, uint1); |
| 1377 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicMin", int1InOut, int1); |
| 1378 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicMax", uint1InOut, uint1); |
| 1379 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicMax", int1InOut, int1); |
| 1380 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicAnd", uint1InOut, uint1); |
| 1381 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicAnd", int1InOut, int1); |
| 1382 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicOr", uint1InOut, uint1); |
| 1383 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicOr", int1InOut, int1); |
| 1384 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicXor", uint1InOut, uint1); |
| 1385 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicXor", int1InOut, int1); |
| 1386 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicExchange", uint1InOut, uint1); |
| 1387 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicExchange", int1InOut, int1); |
| 1388 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicCompSwap", uint1InOut, uint1, uint1); |
| 1389 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicCompSwap", int1InOut, int1, int1); |
| 1390 | |
| 1391 | const TType *gimage2D = StaticType::GetBasic<EbtGImage2D>(); |
| 1392 | const TType *gimage3D = StaticType::GetBasic<EbtGImage3D>(); |
| 1393 | const TType *gimage2DArray = StaticType::GetBasic<EbtGImage2DArray>(); |
| 1394 | const TType *gimageCube = StaticType::GetBasic<EbtGImageCube>(); |
| 1395 | |
| 1396 | insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage2D, int2, gvec4); |
| 1397 | insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage3D, int3, gvec4); |
| 1398 | insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage2DArray, int3, gvec4); |
| 1399 | insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimageCube, int3, gvec4); |
| 1400 | |
| 1401 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage2D, int2); |
| 1402 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage3D, int3); |
| 1403 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage2DArray, int3); |
| 1404 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimageCube, int3); |
| 1405 | |
| 1406 | insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimage2D); |
| 1407 | insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage3D); |
| 1408 | insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage2DArray); |
| 1409 | insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimageCube); |
| 1410 | |
| 1411 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrier, voidType, |
| 1412 | "memoryBarrier"); |
| 1413 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierAtomicCounter, voidType, |
| 1414 | "memoryBarrierAtomicCounter"); |
| 1415 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierBuffer, voidType, |
| 1416 | "memoryBarrierBuffer"); |
| 1417 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierImage, voidType, |
| 1418 | "memoryBarrierImage"); |
| 1419 | |
| 1420 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "texelFetch", gsampler2DMS, int2, int1); |
| 1421 | |
| 1422 | // Insert all variations of textureGather. |
| 1423 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsampler2D, float2); |
| 1424 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsampler2D, float2, int1); |
| 1425 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsampler2DArray, float3); |
| 1426 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsampler2DArray, float3, int1); |
| 1427 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsamplerCube, float3); |
| 1428 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsamplerCube, float3, int1); |
| 1429 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", sampler2DShadow, float2); |
| 1430 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", sampler2DShadow, float2, float1); |
| 1431 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", sampler2DArrayShadow, float3); |
| 1432 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", sampler2DArrayShadow, float3, float1); |
| 1433 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", samplerCubeShadow, float3); |
| 1434 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", samplerCubeShadow, float3, float1); |
| 1435 | |
| 1436 | // Insert all variations of textureGatherOffset. |
| 1437 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGatherOffset", gsampler2D, float2, int2); |
| 1438 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGatherOffset", gsampler2D, float2, int2, int1); |
| 1439 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGatherOffset", gsampler2DArray, float3, int2); |
| 1440 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGatherOffset", gsampler2DArray, float3, int2, |
| 1441 | int1); |
| 1442 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGatherOffset", sampler2DShadow, float2, float1, |
| 1443 | int2); |
| 1444 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGatherOffset", sampler2DArrayShadow, float3, |
| 1445 | float1, int2); |
| 1446 | |
| 1447 | if (type == GL_COMPUTE_SHADER) |
| 1448 | { |
| 1449 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpBarrier, voidType, "barrier"); |
| 1450 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierShared, voidType, |
| 1451 | "memoryBarrierShared"); |
| 1452 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpGroupMemoryBarrier, voidType, |
| 1453 | "groupMemoryBarrier"); |
| 1454 | } |
| 1455 | |
| 1456 | if (type == GL_GEOMETRY_SHADER_EXT) |
| 1457 | { |
| 1458 | TExtension extension = TExtension::EXT_geometry_shader; |
| 1459 | insertBuiltInFunctionNoParametersExt(ESSL3_1_BUILTINS, extension, EOpEmitVertex, voidType, |
| 1460 | "EmitVertex"); |
| 1461 | insertBuiltInFunctionNoParametersExt(ESSL3_1_BUILTINS, extension, EOpEndPrimitive, voidType, |
| 1462 | "EndPrimitive"); |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | void TSymbolTable::initializeBuiltInVariables(sh::GLenum type, |
| 1467 | ShShaderSpec spec, |
| 1468 | const ShBuiltInResources &resources) |
| 1469 | { |
| 1470 | const TSourceLoc zeroSourceLoc = {0, 0, 0, 0}; |
| 1471 | |
| 1472 | // |
| 1473 | // Depth range in window coordinates |
| 1474 | // |
| 1475 | TFieldList *fields = new TFieldList(); |
| 1476 | auto highpFloat1 = new TType(EbtFloat, EbpHigh, EvqGlobal, 1); |
| 1477 | TField *near = new TField(highpFloat1, ImmutableString("near"), zeroSourceLoc); |
| 1478 | TField *far = new TField(highpFloat1, ImmutableString("far"), zeroSourceLoc); |
| 1479 | TField *diff = new TField(highpFloat1, ImmutableString("diff"), zeroSourceLoc); |
| 1480 | fields->push_back(near); |
| 1481 | fields->push_back(far); |
| 1482 | fields->push_back(diff); |
| 1483 | TStructure *depthRangeStruct = new TStructure(this, ImmutableString("gl_DepthRangeParameters"), |
| 1484 | fields, SymbolType::BuiltIn); |
| 1485 | insertStructType(COMMON_BUILTINS, depthRangeStruct); |
| 1486 | TType *depthRangeType = new TType(depthRangeStruct); |
| 1487 | depthRangeType->setQualifier(EvqUniform); |
| 1488 | depthRangeType->realize(); |
| 1489 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_DepthRange"), depthRangeType); |
| 1490 | |
| 1491 | // |
| 1492 | // Implementation dependent built-in constants. |
| 1493 | // |
| 1494 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexAttribs"), |
| 1495 | resources.MaxVertexAttribs); |
| 1496 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexUniformVectors"), |
| 1497 | resources.MaxVertexUniformVectors); |
| 1498 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexTextureImageUnits"), |
| 1499 | resources.MaxVertexTextureImageUnits); |
| 1500 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxCombinedTextureImageUnits"), |
| 1501 | resources.MaxCombinedTextureImageUnits); |
| 1502 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxTextureImageUnits"), |
| 1503 | resources.MaxTextureImageUnits); |
| 1504 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxFragmentUniformVectors"), |
| 1505 | resources.MaxFragmentUniformVectors); |
| 1506 | |
| 1507 | insertConstInt<EbpMedium>(ESSL1_BUILTINS, ImmutableString("gl_MaxVaryingVectors"), |
| 1508 | resources.MaxVaryingVectors); |
| 1509 | |
| 1510 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxDrawBuffers"), |
| 1511 | resources.MaxDrawBuffers); |
Olli Etuaho | 7c8567a | 2018-02-20 15:44:07 +0200 | [diff] [blame^] | 1512 | insertConstIntExt<EbpMedium>(COMMON_BUILTINS, TExtension::EXT_blend_func_extended, |
| 1513 | ImmutableString("gl_MaxDualSourceDrawBuffersEXT"), |
| 1514 | resources.MaxDualSourceDrawBuffers); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1515 | |
| 1516 | insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxVertexOutputVectors"), |
| 1517 | resources.MaxVertexOutputVectors); |
| 1518 | insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxFragmentInputVectors"), |
| 1519 | resources.MaxFragmentInputVectors); |
| 1520 | insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MinProgramTexelOffset"), |
| 1521 | resources.MinProgramTexelOffset); |
| 1522 | insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxProgramTexelOffset"), |
| 1523 | resources.MaxProgramTexelOffset); |
| 1524 | |
| 1525 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxImageUnits"), |
| 1526 | resources.MaxImageUnits); |
| 1527 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexImageUniforms"), |
| 1528 | resources.MaxVertexImageUniforms); |
| 1529 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxFragmentImageUniforms"), |
| 1530 | resources.MaxFragmentImageUniforms); |
| 1531 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeImageUniforms"), |
| 1532 | resources.MaxComputeImageUniforms); |
| 1533 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxCombinedImageUniforms"), |
| 1534 | resources.MaxCombinedImageUniforms); |
| 1535 | |
| 1536 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, |
| 1537 | ImmutableString("gl_MaxCombinedShaderOutputResources"), |
| 1538 | resources.MaxCombinedShaderOutputResources); |
| 1539 | |
| 1540 | insertConstIvec3<EbpHigh>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeWorkGroupCount"), |
| 1541 | resources.MaxComputeWorkGroupCount); |
| 1542 | insertConstIvec3<EbpHigh>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeWorkGroupSize"), |
| 1543 | resources.MaxComputeWorkGroupSize); |
| 1544 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeUniformComponents"), |
| 1545 | resources.MaxComputeUniformComponents); |
| 1546 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeTextureImageUnits"), |
| 1547 | resources.MaxComputeTextureImageUnits); |
| 1548 | |
| 1549 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeAtomicCounters"), |
| 1550 | resources.MaxComputeAtomicCounters); |
| 1551 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, |
| 1552 | ImmutableString("gl_MaxComputeAtomicCounterBuffers"), |
| 1553 | resources.MaxComputeAtomicCounterBuffers); |
| 1554 | |
| 1555 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexAtomicCounters"), |
| 1556 | resources.MaxVertexAtomicCounters); |
| 1557 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxFragmentAtomicCounters"), |
| 1558 | resources.MaxFragmentAtomicCounters); |
| 1559 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxCombinedAtomicCounters"), |
| 1560 | resources.MaxCombinedAtomicCounters); |
| 1561 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxAtomicCounterBindings"), |
| 1562 | resources.MaxAtomicCounterBindings); |
| 1563 | |
| 1564 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexAtomicCounterBuffers"), |
| 1565 | resources.MaxVertexAtomicCounterBuffers); |
| 1566 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, |
| 1567 | ImmutableString("gl_MaxFragmentAtomicCounterBuffers"), |
| 1568 | resources.MaxFragmentAtomicCounterBuffers); |
| 1569 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, |
| 1570 | ImmutableString("gl_MaxCombinedAtomicCounterBuffers"), |
| 1571 | resources.MaxCombinedAtomicCounterBuffers); |
| 1572 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxAtomicCounterBufferSize"), |
| 1573 | resources.MaxAtomicCounterBufferSize); |
| 1574 | |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 1575 | { |
| 1576 | TExtension ext = TExtension::EXT_geometry_shader; |
| 1577 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1578 | ImmutableString("gl_MaxGeometryInputComponents"), |
| 1579 | resources.MaxGeometryInputComponents); |
| 1580 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1581 | ImmutableString("gl_MaxGeometryOutputComponents"), |
| 1582 | resources.MaxGeometryOutputComponents); |
| 1583 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1584 | ImmutableString("gl_MaxGeometryImageUniforms"), |
| 1585 | resources.MaxGeometryImageUniforms); |
| 1586 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1587 | ImmutableString("gl_MaxGeometryTextureImageUnits"), |
| 1588 | resources.MaxGeometryTextureImageUnits); |
| 1589 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1590 | ImmutableString("gl_MaxGeometryOutputVertices"), |
| 1591 | resources.MaxGeometryOutputVertices); |
| 1592 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1593 | ImmutableString("gl_MaxGeometryTotalOutputComponents"), |
| 1594 | resources.MaxGeometryTotalOutputComponents); |
| 1595 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1596 | ImmutableString("gl_MaxGeometryUniformComponents"), |
| 1597 | resources.MaxGeometryUniformComponents); |
| 1598 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1599 | ImmutableString("gl_MaxGeometryAtomicCounters"), |
| 1600 | resources.MaxGeometryAtomicCounters); |
| 1601 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1602 | ImmutableString("gl_MaxGeometryAtomicCounterBuffers"), |
| 1603 | resources.MaxGeometryAtomicCounterBuffers); |
| 1604 | } |
| 1605 | |
| 1606 | // |
| 1607 | // Insert some special built-in variables that are not in |
| 1608 | // the built-in header files. |
| 1609 | // |
| 1610 | |
| 1611 | if (resources.OVR_multiview && type != GL_COMPUTE_SHADER) |
| 1612 | { |
| 1613 | const TType *viewIDType = StaticType::Get<EbtUInt, EbpHigh, EvqViewIDOVR, 1, 1>(); |
| 1614 | insertVariableExt(ESSL3_BUILTINS, TExtension::OVR_multiview, |
| 1615 | ImmutableString("gl_ViewID_OVR"), viewIDType); |
| 1616 | |
| 1617 | // ESSL 1.00 doesn't have unsigned integers, so gl_ViewID_OVR is a signed integer in ESSL |
| 1618 | // 1.00. This is specified in the WEBGL_multiview spec. |
| 1619 | const TType *viewIDIntType = StaticType::Get<EbtInt, EbpHigh, EvqViewIDOVR, 1, 1>(); |
| 1620 | insertVariableExt(ESSL1_BUILTINS, TExtension::OVR_multiview, |
| 1621 | ImmutableString("gl_ViewID_OVR"), viewIDIntType); |
| 1622 | } |
| 1623 | |
| 1624 | const TType *positionType = StaticType::Get<EbtFloat, EbpHigh, EvqPosition, 4, 1>(); |
| 1625 | const TType *primitiveIDType = StaticType::Get<EbtInt, EbpHigh, EvqPrimitiveID, 1, 1>(); |
| 1626 | const TType *layerType = StaticType::Get<EbtInt, EbpHigh, EvqLayer, 1, 1>(); |
| 1627 | |
| 1628 | switch (type) |
| 1629 | { |
| 1630 | case GL_FRAGMENT_SHADER: |
| 1631 | { |
| 1632 | const TType *fragCoordType = StaticType::Get<EbtFloat, EbpMedium, EvqFragCoord, 4, 1>(); |
| 1633 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_FragCoord"), fragCoordType); |
| 1634 | const TType *frontFacingType = StaticType::GetQualified<EbtBool, EvqFrontFacing>(); |
| 1635 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_FrontFacing"), frontFacingType); |
| 1636 | const TType *pointCoordType = |
| 1637 | StaticType::Get<EbtFloat, EbpMedium, EvqPointCoord, 2, 1>(); |
| 1638 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_PointCoord"), pointCoordType); |
| 1639 | |
| 1640 | const TType *fragColorType = StaticType::Get<EbtFloat, EbpMedium, EvqFragColor, 4, 1>(); |
| 1641 | insertVariable(ESSL1_BUILTINS, ImmutableString("gl_FragColor"), fragColorType); |
| 1642 | |
| 1643 | TType *fragDataType = new TType(EbtFloat, EbpMedium, EvqFragData, 4); |
| 1644 | if (spec != SH_WEBGL2_SPEC && spec != SH_WEBGL3_SPEC) |
| 1645 | { |
| 1646 | fragDataType->makeArray(resources.MaxDrawBuffers); |
| 1647 | } |
| 1648 | else |
| 1649 | { |
| 1650 | fragDataType->makeArray(1u); |
| 1651 | } |
| 1652 | fragDataType->realize(); |
| 1653 | insertVariable(ESSL1_BUILTINS, ImmutableString("gl_FragData"), fragDataType); |
| 1654 | |
| 1655 | if (resources.EXT_blend_func_extended) |
| 1656 | { |
| 1657 | const TType *secondaryFragColorType = |
| 1658 | StaticType::Get<EbtFloat, EbpMedium, EvqSecondaryFragColorEXT, 4, 1>(); |
| 1659 | insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_blend_func_extended, |
| 1660 | ImmutableString("gl_SecondaryFragColorEXT"), |
| 1661 | secondaryFragColorType); |
| 1662 | TType *secondaryFragDataType = |
| 1663 | new TType(EbtFloat, EbpMedium, EvqSecondaryFragDataEXT, 4, 1); |
| 1664 | secondaryFragDataType->makeArray(resources.MaxDualSourceDrawBuffers); |
| 1665 | secondaryFragDataType->realize(); |
| 1666 | insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_blend_func_extended, |
| 1667 | ImmutableString("gl_SecondaryFragDataEXT"), |
| 1668 | secondaryFragDataType); |
| 1669 | } |
| 1670 | |
| 1671 | if (resources.EXT_frag_depth) |
| 1672 | { |
| 1673 | TType *fragDepthEXTType = |
| 1674 | new TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, |
| 1675 | EvqFragDepthEXT, 1); |
| 1676 | fragDepthEXTType->realize(); |
| 1677 | insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_frag_depth, |
| 1678 | ImmutableString("gl_FragDepthEXT"), fragDepthEXTType); |
| 1679 | } |
| 1680 | |
| 1681 | const TType *fragDepthType = StaticType::Get<EbtFloat, EbpHigh, EvqFragDepth, 1, 1>(); |
| 1682 | insertVariable(ESSL3_BUILTINS, ImmutableString("gl_FragDepth"), fragDepthType); |
| 1683 | |
| 1684 | const TType *lastFragColorType = |
| 1685 | StaticType::Get<EbtFloat, EbpMedium, EvqLastFragColor, 4, 1>(); |
| 1686 | |
| 1687 | if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch) |
| 1688 | { |
| 1689 | TType *lastFragDataType = new TType(EbtFloat, EbpMedium, EvqLastFragData, 4, 1); |
| 1690 | lastFragDataType->makeArray(resources.MaxDrawBuffers); |
| 1691 | lastFragDataType->realize(); |
| 1692 | |
| 1693 | if (resources.EXT_shader_framebuffer_fetch) |
| 1694 | { |
| 1695 | insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_shader_framebuffer_fetch, |
| 1696 | ImmutableString("gl_LastFragData"), lastFragDataType); |
| 1697 | } |
| 1698 | else if (resources.NV_shader_framebuffer_fetch) |
| 1699 | { |
| 1700 | insertVariableExt(ESSL1_BUILTINS, TExtension::NV_shader_framebuffer_fetch, |
| 1701 | ImmutableString("gl_LastFragColor"), lastFragColorType); |
| 1702 | insertVariableExt(ESSL1_BUILTINS, TExtension::NV_shader_framebuffer_fetch, |
| 1703 | ImmutableString("gl_LastFragData"), lastFragDataType); |
| 1704 | } |
| 1705 | } |
| 1706 | else if (resources.ARM_shader_framebuffer_fetch) |
| 1707 | { |
| 1708 | insertVariableExt(ESSL1_BUILTINS, TExtension::ARM_shader_framebuffer_fetch, |
| 1709 | ImmutableString("gl_LastFragColorARM"), lastFragColorType); |
| 1710 | } |
| 1711 | |
| 1712 | if (resources.EXT_geometry_shader) |
| 1713 | { |
| 1714 | TExtension extension = TExtension::EXT_geometry_shader; |
| 1715 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveID"), |
| 1716 | primitiveIDType); |
| 1717 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Layer"), |
| 1718 | layerType); |
| 1719 | } |
| 1720 | |
| 1721 | break; |
| 1722 | } |
| 1723 | case GL_VERTEX_SHADER: |
| 1724 | { |
| 1725 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_Position"), positionType); |
| 1726 | const TType *pointSizeType = StaticType::Get<EbtFloat, EbpMedium, EvqPointSize, 1, 1>(); |
| 1727 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_PointSize"), pointSizeType); |
| 1728 | const TType *instanceIDType = StaticType::Get<EbtInt, EbpHigh, EvqInstanceID, 1, 1>(); |
| 1729 | insertVariable(ESSL3_BUILTINS, ImmutableString("gl_InstanceID"), instanceIDType); |
| 1730 | const TType *vertexIDType = StaticType::Get<EbtInt, EbpHigh, EvqVertexID, 1, 1>(); |
| 1731 | insertVariable(ESSL3_BUILTINS, ImmutableString("gl_VertexID"), vertexIDType); |
| 1732 | |
| 1733 | // For internal use by ANGLE - not exposed to the parser. |
| 1734 | const TType *viewportIndexType = |
| 1735 | StaticType::Get<EbtInt, EbpHigh, EvqViewportIndex, 1, 1>(); |
| 1736 | insertVariable(GLSL_BUILTINS, ImmutableString("gl_ViewportIndex"), viewportIndexType); |
| 1737 | // gl_Layer exists in other shader stages in ESSL, but not in vertex shader so far. |
| 1738 | insertVariable(GLSL_BUILTINS, ImmutableString("gl_Layer"), layerType); |
| 1739 | break; |
| 1740 | } |
| 1741 | case GL_COMPUTE_SHADER: |
| 1742 | { |
| 1743 | const TType *numWorkGroupsType = |
| 1744 | StaticType::Get<EbtUInt, EbpUndefined, EvqNumWorkGroups, 3, 1>(); |
| 1745 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_NumWorkGroups"), |
| 1746 | numWorkGroupsType); |
| 1747 | const TType *workGroupSizeType = |
| 1748 | StaticType::Get<EbtUInt, EbpUndefined, EvqWorkGroupSize, 3, 1>(); |
| 1749 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_WorkGroupSize"), |
| 1750 | workGroupSizeType); |
| 1751 | const TType *workGroupIDType = |
| 1752 | StaticType::Get<EbtUInt, EbpUndefined, EvqWorkGroupID, 3, 1>(); |
| 1753 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_WorkGroupID"), workGroupIDType); |
| 1754 | const TType *localInvocationIDType = |
| 1755 | StaticType::Get<EbtUInt, EbpUndefined, EvqLocalInvocationID, 3, 1>(); |
| 1756 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_LocalInvocationID"), |
| 1757 | localInvocationIDType); |
| 1758 | const TType *globalInvocationIDType = |
| 1759 | StaticType::Get<EbtUInt, EbpUndefined, EvqGlobalInvocationID, 3, 1>(); |
| 1760 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_GlobalInvocationID"), |
| 1761 | globalInvocationIDType); |
| 1762 | const TType *localInvocationIndexType = |
| 1763 | StaticType::Get<EbtUInt, EbpUndefined, EvqLocalInvocationIndex, 1, 1>(); |
| 1764 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_LocalInvocationIndex"), |
| 1765 | localInvocationIndexType); |
| 1766 | break; |
| 1767 | } |
| 1768 | |
| 1769 | case GL_GEOMETRY_SHADER_EXT: |
| 1770 | { |
| 1771 | TExtension extension = TExtension::EXT_geometry_shader; |
| 1772 | |
| 1773 | // Add built-in interface block gl_PerVertex and the built-in array gl_in. |
| 1774 | // TODO(jiawei.shao@intel.com): implement GL_EXT_geometry_point_size. |
| 1775 | TFieldList *glPerVertexFieldList = new TFieldList(); |
| 1776 | TField *glPositionField = |
| 1777 | new TField(new TType(*positionType), ImmutableString("gl_Position"), zeroSourceLoc); |
| 1778 | glPerVertexFieldList->push_back(glPositionField); |
| 1779 | |
| 1780 | const ImmutableString glPerVertexString("gl_PerVertex"); |
| 1781 | TInterfaceBlock *glPerVertexInBlock = |
| 1782 | new TInterfaceBlock(this, glPerVertexString, glPerVertexFieldList, |
| 1783 | TLayoutQualifier::Create(), SymbolType::BuiltIn, extension); |
| 1784 | insertInterfaceBlock(ESSL3_1_BUILTINS, glPerVertexInBlock); |
| 1785 | |
| 1786 | // The array size of gl_in is undefined until we get a valid input primitive |
| 1787 | // declaration. |
| 1788 | TType *glInType = |
| 1789 | new TType(glPerVertexInBlock, EvqPerVertexIn, TLayoutQualifier::Create()); |
| 1790 | glInType->makeArray(0u); |
| 1791 | glInType->realize(); |
| 1792 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_in"), glInType); |
| 1793 | |
| 1794 | TInterfaceBlock *glPerVertexOutBlock = |
| 1795 | new TInterfaceBlock(this, glPerVertexString, glPerVertexFieldList, |
| 1796 | TLayoutQualifier::Create(), SymbolType::BuiltIn); |
| 1797 | TType *glPositionInBlockType = new TType(EbtFloat, EbpHigh, EvqPosition, 4); |
| 1798 | glPositionInBlockType->setInterfaceBlock(glPerVertexOutBlock); |
| 1799 | glPositionInBlockType->realize(); |
| 1800 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Position"), |
| 1801 | glPositionInBlockType); |
| 1802 | |
| 1803 | const TType *primitiveIDInType = |
| 1804 | StaticType::Get<EbtInt, EbpHigh, EvqPrimitiveIDIn, 1, 1>(); |
| 1805 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveIDIn"), |
| 1806 | primitiveIDInType); |
| 1807 | const TType *invocationIDType = |
| 1808 | StaticType::Get<EbtInt, EbpHigh, EvqInvocationID, 1, 1>(); |
| 1809 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_InvocationID"), |
| 1810 | invocationIDType); |
| 1811 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveID"), |
| 1812 | primitiveIDType); |
| 1813 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Layer"), layerType); |
| 1814 | |
| 1815 | break; |
| 1816 | } |
| 1817 | default: |
| 1818 | UNREACHABLE(); |
| 1819 | } |
| 1820 | } |
| 1821 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 1822 | } // namespace sh |