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