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