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 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 177 | // The previous declaration should have the same parameters as the function definition |
| 178 | // (parameter names may differ). |
| 179 | firstDeclaration->shareParameters(*function); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 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 | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 594 | size_t paramCount = 1; |
| 595 | TConstParameter *params = new TConstParameter[5]; |
| 596 | new (params) TConstParameter(ptype1); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 597 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 598 | if (ptype2) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 599 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 600 | new (params + 1) TConstParameter(ptype2); |
| 601 | paramCount = 2; |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 602 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 603 | if (ptype3) |
| 604 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 605 | new (params + 2) TConstParameter(ptype3); |
| 606 | paramCount = 3; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 607 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 608 | if (ptype4) |
| 609 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 610 | new (params + 3) TConstParameter(ptype4); |
| 611 | paramCount = 4; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 612 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 613 | if (ptype5) |
| 614 | { |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 615 | new (params + 4) TConstParameter(ptype5); |
| 616 | paramCount = 5; |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 617 | } |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 618 | TFunction *function = |
| 619 | new TFunction(this, ImmutableString(name), ext, params, paramCount, rvalue, op, false); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 620 | |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 621 | ASSERT(hasUnmangledBuiltInAtLevel(name, level)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 622 | insert(level, function); |
| 623 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 626 | void TSymbolTable::insertBuiltInOp(ESymbolLevel level, |
| 627 | TOperator op, |
| 628 | const TType *rvalue, |
| 629 | const TType *ptype1, |
| 630 | const TType *ptype2, |
| 631 | const TType *ptype3, |
| 632 | const TType *ptype4, |
| 633 | const TType *ptype5) |
| 634 | { |
| 635 | const char *name = GetOperatorString(op); |
| 636 | ASSERT(strlen(name) > 0); |
| 637 | insertUnmangledBuiltInName(name, level); |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 638 | insertBuiltIn(level, op, TExtension::UNDEFINED, rvalue, name, ptype1, ptype2, ptype3, ptype4, |
| 639 | ptype5); |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void TSymbolTable::insertBuiltInOp(ESymbolLevel level, |
| 643 | TOperator op, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 644 | TExtension ext, |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 645 | const TType *rvalue, |
| 646 | const TType *ptype1, |
| 647 | const TType *ptype2, |
| 648 | const TType *ptype3, |
| 649 | const TType *ptype4, |
| 650 | const TType *ptype5) |
| 651 | { |
| 652 | const char *name = GetOperatorString(op); |
| 653 | insertUnmangledBuiltInName(name, level); |
| 654 | insertBuiltIn(level, op, ext, rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5); |
| 655 | } |
| 656 | |
Martin Radev | d7c5b0a | 2016-07-27 14:04:43 +0300 | [diff] [blame] | 657 | void TSymbolTable::insertBuiltInFunctionNoParameters(ESymbolLevel level, |
| 658 | TOperator op, |
| 659 | const TType *rvalue, |
| 660 | const char *name) |
| 661 | { |
| 662 | insertUnmangledBuiltInName(name, level); |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 663 | insert(level, new TFunction(this, ImmutableString(name), TExtension::UNDEFINED, nullptr, 0, |
| 664 | rvalue, op, false)); |
Martin Radev | d7c5b0a | 2016-07-27 14:04:43 +0300 | [diff] [blame] | 665 | } |
| 666 | |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 667 | void TSymbolTable::insertBuiltInFunctionNoParametersExt(ESymbolLevel level, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 668 | TExtension ext, |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 669 | TOperator op, |
| 670 | const TType *rvalue, |
| 671 | const char *name) |
| 672 | { |
| 673 | insertUnmangledBuiltInName(name, level); |
Olli Etuaho | 029e8ca | 2018-02-16 14:06:49 +0200 | [diff] [blame^] | 674 | insert(level, new TFunction(this, ImmutableString(name), ext, nullptr, 0, rvalue, op, false)); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 675 | } |
| 676 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 677 | void TSymbolTable::setDefaultPrecision(TBasicType type, TPrecision prec) |
| 678 | { |
| 679 | int indexOfLastElement = static_cast<int>(mPrecisionStack.size()) - 1; |
| 680 | // Uses map operator [], overwrites the current value |
| 681 | (*mPrecisionStack[indexOfLastElement])[type] = prec; |
| 682 | } |
| 683 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 684 | TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 685 | { |
| 686 | if (!SupportsPrecision(type)) |
| 687 | return EbpUndefined; |
| 688 | |
| 689 | // unsigned integers use the same precision as signed |
| 690 | TBasicType baseType = (type == EbtUInt) ? EbtInt : type; |
| 691 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 692 | int level = static_cast<int>(mPrecisionStack.size()) - 1; |
| 693 | ASSERT(level >= 0); // Just to be safe. Should not happen. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 694 | // 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] | 695 | TPrecision prec = EbpUndefined; |
| 696 | while (level >= 0) |
| 697 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 698 | PrecisionStackLevel::iterator it = mPrecisionStack[level]->find(baseType); |
| 699 | if (it != mPrecisionStack[level]->end()) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 700 | { |
| 701 | prec = (*it).second; |
| 702 | break; |
| 703 | } |
| 704 | level--; |
| 705 | } |
| 706 | return prec; |
| 707 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 708 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 709 | void TSymbolTable::addInvariantVarying(const ImmutableString &originalName) |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 710 | { |
| 711 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 712 | mTable.back()->addInvariantVarying(originalName); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 713 | } |
| 714 | |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 715 | bool TSymbolTable::isVaryingInvariant(const ImmutableString &originalName) const |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 716 | { |
| 717 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 718 | return mTable.back()->isVaryingInvariant(originalName); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | void TSymbolTable::setGlobalInvariant(bool invariant) |
| 722 | { |
| 723 | ASSERT(atGlobalLevel()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 724 | mTable.back()->setGlobalInvariant(invariant); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 725 | } |
| 726 | |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 727 | void TSymbolTable::insertUnmangledBuiltInName(const char *name, ESymbolLevel level) |
| 728 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 729 | ASSERT(level >= 0 && level <= LAST_BUILTIN_LEVEL); |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 730 | ASSERT(mUserDefinedUniqueIdsStart == -1); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 731 | mBuiltInTable[level]->insertUnmangledBuiltInName(name); |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | bool TSymbolTable::hasUnmangledBuiltInAtLevel(const char *name, ESymbolLevel level) |
| 735 | { |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 736 | ASSERT(level >= 0 && level <= LAST_BUILTIN_LEVEL); |
| 737 | return mBuiltInTable[level]->hasUnmangledBuiltIn(name); |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | bool TSymbolTable::hasUnmangledBuiltInForShaderVersion(const char *name, int shaderVersion) |
| 741 | { |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 742 | for (int level = LAST_BUILTIN_LEVEL; level >= 0; --level) |
| 743 | { |
| 744 | if (level == ESSL3_1_BUILTINS && shaderVersion != 310) |
| 745 | { |
| 746 | --level; |
| 747 | } |
| 748 | if (level == ESSL3_BUILTINS && shaderVersion < 300) |
| 749 | { |
| 750 | --level; |
| 751 | } |
| 752 | if (level == ESSL1_BUILTINS && shaderVersion != 100) |
| 753 | { |
| 754 | --level; |
| 755 | } |
| 756 | |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 757 | if (mBuiltInTable[level]->hasUnmangledBuiltIn(name)) |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 758 | { |
| 759 | return true; |
| 760 | } |
| 761 | } |
| 762 | return false; |
| 763 | } |
| 764 | |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 765 | void TSymbolTable::markBuiltInInitializationFinished() |
| 766 | { |
| 767 | mUserDefinedUniqueIdsStart = mUniqueIdCounter; |
| 768 | } |
| 769 | |
| 770 | void TSymbolTable::clearCompilationResults() |
| 771 | { |
| 772 | mUniqueIdCounter = mUserDefinedUniqueIdsStart; |
| 773 | |
| 774 | // User-defined scopes should have already been cleared when the compilation finished. |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 775 | ASSERT(mTable.size() == 0u); |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | int TSymbolTable::nextUniqueIdValue() |
| 779 | { |
| 780 | ASSERT(mUniqueIdCounter < std::numeric_limits<int>::max()); |
| 781 | return ++mUniqueIdCounter; |
| 782 | } |
| 783 | |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 784 | void TSymbolTable::initializeBuiltIns(sh::GLenum type, |
| 785 | ShShaderSpec spec, |
| 786 | const ShBuiltInResources &resources) |
| 787 | { |
| 788 | ASSERT(isEmpty()); |
Olli Etuaho | e5fe7aa | 2018-01-29 12:06:11 +0200 | [diff] [blame] | 789 | pushBuiltInLevel(); // COMMON_BUILTINS |
| 790 | pushBuiltInLevel(); // ESSL1_BUILTINS |
| 791 | pushBuiltInLevel(); // ESSL3_BUILTINS |
| 792 | pushBuiltInLevel(); // ESSL3_1_BUILTINS |
| 793 | pushBuiltInLevel(); // GLSL_BUILTINS |
| 794 | |
| 795 | // We need just one precision stack level for predefined precisions. |
| 796 | mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel)); |
Olli Etuaho | 29bda81 | 2018-01-26 17:37:36 +0200 | [diff] [blame] | 797 | |
| 798 | switch (type) |
| 799 | { |
| 800 | case GL_FRAGMENT_SHADER: |
| 801 | setDefaultPrecision(EbtInt, EbpMedium); |
| 802 | break; |
| 803 | case GL_VERTEX_SHADER: |
| 804 | case GL_COMPUTE_SHADER: |
| 805 | case GL_GEOMETRY_SHADER_EXT: |
| 806 | setDefaultPrecision(EbtInt, EbpHigh); |
| 807 | setDefaultPrecision(EbtFloat, EbpHigh); |
| 808 | break; |
| 809 | default: |
| 810 | UNREACHABLE(); |
| 811 | } |
| 812 | // Set defaults for sampler types that have default precision, even those that are |
| 813 | // only available if an extension exists. |
| 814 | // New sampler types in ESSL3 don't have default precision. ESSL1 types do. |
| 815 | initSamplerDefaultPrecision(EbtSampler2D); |
| 816 | initSamplerDefaultPrecision(EbtSamplerCube); |
| 817 | // SamplerExternalOES is specified in the extension to have default precision. |
| 818 | initSamplerDefaultPrecision(EbtSamplerExternalOES); |
| 819 | // SamplerExternal2DY2YEXT is specified in the extension to have default precision. |
| 820 | initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT); |
| 821 | // It isn't specified whether Sampler2DRect has default precision. |
| 822 | initSamplerDefaultPrecision(EbtSampler2DRect); |
| 823 | |
| 824 | setDefaultPrecision(EbtAtomicCounter, EbpHigh); |
| 825 | |
| 826 | initializeBuiltInFunctions(type, spec, resources); |
| 827 | initializeBuiltInVariables(type, spec, resources); |
| 828 | markBuiltInInitializationFinished(); |
| 829 | } |
| 830 | |
| 831 | void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType) |
| 832 | { |
| 833 | ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd); |
| 834 | setDefaultPrecision(samplerType, EbpLow); |
| 835 | } |
| 836 | |
| 837 | void TSymbolTable::initializeBuiltInFunctions(sh::GLenum type, |
| 838 | ShShaderSpec spec, |
| 839 | const ShBuiltInResources &resources) |
| 840 | { |
| 841 | const TType *voidType = StaticType::GetBasic<EbtVoid>(); |
| 842 | const TType *float1 = StaticType::GetBasic<EbtFloat>(); |
| 843 | const TType *float2 = StaticType::GetBasic<EbtFloat, 2>(); |
| 844 | const TType *float3 = StaticType::GetBasic<EbtFloat, 3>(); |
| 845 | const TType *float4 = StaticType::GetBasic<EbtFloat, 4>(); |
| 846 | const TType *int1 = StaticType::GetBasic<EbtInt>(); |
| 847 | const TType *int2 = StaticType::GetBasic<EbtInt, 2>(); |
| 848 | const TType *int3 = StaticType::GetBasic<EbtInt, 3>(); |
| 849 | const TType *uint1 = StaticType::GetBasic<EbtUInt>(); |
| 850 | const TType *bool1 = StaticType::GetBasic<EbtBool>(); |
| 851 | const TType *genType = StaticType::GetBasic<EbtGenType>(); |
| 852 | const TType *genIType = StaticType::GetBasic<EbtGenIType>(); |
| 853 | const TType *genUType = StaticType::GetBasic<EbtGenUType>(); |
| 854 | const TType *genBType = StaticType::GetBasic<EbtGenBType>(); |
| 855 | |
| 856 | // |
| 857 | // Angle and Trigonometric Functions. |
| 858 | // |
| 859 | insertBuiltInOp(COMMON_BUILTINS, EOpRadians, genType, genType); |
| 860 | insertBuiltInOp(COMMON_BUILTINS, EOpDegrees, genType, genType); |
| 861 | insertBuiltInOp(COMMON_BUILTINS, EOpSin, genType, genType); |
| 862 | insertBuiltInOp(COMMON_BUILTINS, EOpCos, genType, genType); |
| 863 | insertBuiltInOp(COMMON_BUILTINS, EOpTan, genType, genType); |
| 864 | insertBuiltInOp(COMMON_BUILTINS, EOpAsin, genType, genType); |
| 865 | insertBuiltInOp(COMMON_BUILTINS, EOpAcos, genType, genType); |
| 866 | insertBuiltInOp(COMMON_BUILTINS, EOpAtan, genType, genType, genType); |
| 867 | insertBuiltInOp(COMMON_BUILTINS, EOpAtan, genType, genType); |
| 868 | insertBuiltInOp(ESSL3_BUILTINS, EOpSinh, genType, genType); |
| 869 | insertBuiltInOp(ESSL3_BUILTINS, EOpCosh, genType, genType); |
| 870 | insertBuiltInOp(ESSL3_BUILTINS, EOpTanh, genType, genType); |
| 871 | insertBuiltInOp(ESSL3_BUILTINS, EOpAsinh, genType, genType); |
| 872 | insertBuiltInOp(ESSL3_BUILTINS, EOpAcosh, genType, genType); |
| 873 | insertBuiltInOp(ESSL3_BUILTINS, EOpAtanh, genType, genType); |
| 874 | |
| 875 | // |
| 876 | // Exponential Functions. |
| 877 | // |
| 878 | insertBuiltInOp(COMMON_BUILTINS, EOpPow, genType, genType, genType); |
| 879 | insertBuiltInOp(COMMON_BUILTINS, EOpExp, genType, genType); |
| 880 | insertBuiltInOp(COMMON_BUILTINS, EOpLog, genType, genType); |
| 881 | insertBuiltInOp(COMMON_BUILTINS, EOpExp2, genType, genType); |
| 882 | insertBuiltInOp(COMMON_BUILTINS, EOpLog2, genType, genType); |
| 883 | insertBuiltInOp(COMMON_BUILTINS, EOpSqrt, genType, genType); |
| 884 | insertBuiltInOp(COMMON_BUILTINS, EOpInverseSqrt, genType, genType); |
| 885 | |
| 886 | // |
| 887 | // Common Functions. |
| 888 | // |
| 889 | insertBuiltInOp(COMMON_BUILTINS, EOpAbs, genType, genType); |
| 890 | insertBuiltInOp(ESSL3_BUILTINS, EOpAbs, genIType, genIType); |
| 891 | insertBuiltInOp(COMMON_BUILTINS, EOpSign, genType, genType); |
| 892 | insertBuiltInOp(ESSL3_BUILTINS, EOpSign, genIType, genIType); |
| 893 | insertBuiltInOp(COMMON_BUILTINS, EOpFloor, genType, genType); |
| 894 | insertBuiltInOp(ESSL3_BUILTINS, EOpTrunc, genType, genType); |
| 895 | insertBuiltInOp(ESSL3_BUILTINS, EOpRound, genType, genType); |
| 896 | insertBuiltInOp(ESSL3_BUILTINS, EOpRoundEven, genType, genType); |
| 897 | insertBuiltInOp(COMMON_BUILTINS, EOpCeil, genType, genType); |
| 898 | insertBuiltInOp(COMMON_BUILTINS, EOpFract, genType, genType); |
| 899 | insertBuiltInOp(COMMON_BUILTINS, EOpMod, genType, genType, float1); |
| 900 | insertBuiltInOp(COMMON_BUILTINS, EOpMod, genType, genType, genType); |
| 901 | insertBuiltInOp(COMMON_BUILTINS, EOpMin, genType, genType, float1); |
| 902 | insertBuiltInOp(COMMON_BUILTINS, EOpMin, genType, genType, genType); |
| 903 | insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genIType, genIType, genIType); |
| 904 | insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genIType, genIType, int1); |
| 905 | insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genUType, genUType, genUType); |
| 906 | insertBuiltInOp(ESSL3_BUILTINS, EOpMin, genUType, genUType, uint1); |
| 907 | insertBuiltInOp(COMMON_BUILTINS, EOpMax, genType, genType, float1); |
| 908 | insertBuiltInOp(COMMON_BUILTINS, EOpMax, genType, genType, genType); |
| 909 | insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genIType, genIType, genIType); |
| 910 | insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genIType, genIType, int1); |
| 911 | insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genUType, genUType, genUType); |
| 912 | insertBuiltInOp(ESSL3_BUILTINS, EOpMax, genUType, genUType, uint1); |
| 913 | insertBuiltInOp(COMMON_BUILTINS, EOpClamp, genType, genType, float1, float1); |
| 914 | insertBuiltInOp(COMMON_BUILTINS, EOpClamp, genType, genType, genType, genType); |
| 915 | insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genIType, genIType, int1, int1); |
| 916 | insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genIType, genIType, genIType, genIType); |
| 917 | insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genUType, genUType, uint1, uint1); |
| 918 | insertBuiltInOp(ESSL3_BUILTINS, EOpClamp, genUType, genUType, genUType, genUType); |
| 919 | insertBuiltInOp(COMMON_BUILTINS, EOpMix, genType, genType, genType, float1); |
| 920 | insertBuiltInOp(COMMON_BUILTINS, EOpMix, genType, genType, genType, genType); |
| 921 | insertBuiltInOp(ESSL3_BUILTINS, EOpMix, genType, genType, genType, genBType); |
| 922 | insertBuiltInOp(COMMON_BUILTINS, EOpStep, genType, genType, genType); |
| 923 | insertBuiltInOp(COMMON_BUILTINS, EOpStep, genType, float1, genType); |
| 924 | insertBuiltInOp(COMMON_BUILTINS, EOpSmoothStep, genType, genType, genType, genType); |
| 925 | insertBuiltInOp(COMMON_BUILTINS, EOpSmoothStep, genType, float1, float1, genType); |
| 926 | |
| 927 | const TType *outGenType = StaticType::GetQualified<EbtGenType, EvqOut>(); |
| 928 | const TType *outGenIType = StaticType::GetQualified<EbtGenIType, EvqOut>(); |
| 929 | |
| 930 | insertBuiltInOp(ESSL3_BUILTINS, EOpModf, genType, genType, outGenType); |
| 931 | |
| 932 | insertBuiltInOp(ESSL3_BUILTINS, EOpIsNan, genBType, genType); |
| 933 | insertBuiltInOp(ESSL3_BUILTINS, EOpIsInf, genBType, genType); |
| 934 | insertBuiltInOp(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, genType); |
| 935 | insertBuiltInOp(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, genType); |
| 936 | insertBuiltInOp(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, genIType); |
| 937 | insertBuiltInOp(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, genUType); |
| 938 | |
| 939 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFrexp, genType, genType, outGenIType); |
| 940 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpLdexp, genType, genType, genIType); |
| 941 | |
| 942 | insertBuiltInOp(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, float2); |
| 943 | insertBuiltInOp(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, float2); |
| 944 | insertBuiltInOp(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, float2); |
| 945 | insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, uint1); |
| 946 | insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, uint1); |
| 947 | insertBuiltInOp(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, uint1); |
| 948 | |
| 949 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpPackUnorm4x8, uint1, float4); |
| 950 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpPackSnorm4x8, uint1, float4); |
| 951 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUnpackUnorm4x8, float4, uint1); |
| 952 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUnpackSnorm4x8, float4, uint1); |
| 953 | |
| 954 | // |
| 955 | // Geometric Functions. |
| 956 | // |
| 957 | insertBuiltInOp(COMMON_BUILTINS, EOpLength, float1, genType); |
| 958 | insertBuiltInOp(COMMON_BUILTINS, EOpDistance, float1, genType, genType); |
| 959 | insertBuiltInOp(COMMON_BUILTINS, EOpDot, float1, genType, genType); |
| 960 | insertBuiltInOp(COMMON_BUILTINS, EOpCross, float3, float3, float3); |
| 961 | insertBuiltInOp(COMMON_BUILTINS, EOpNormalize, genType, genType); |
| 962 | insertBuiltInOp(COMMON_BUILTINS, EOpFaceforward, genType, genType, genType, genType); |
| 963 | insertBuiltInOp(COMMON_BUILTINS, EOpReflect, genType, genType, genType); |
| 964 | insertBuiltInOp(COMMON_BUILTINS, EOpRefract, genType, genType, genType, float1); |
| 965 | |
| 966 | const TType *mat2 = StaticType::GetBasic<EbtFloat, 2, 2>(); |
| 967 | const TType *mat3 = StaticType::GetBasic<EbtFloat, 3, 3>(); |
| 968 | const TType *mat4 = StaticType::GetBasic<EbtFloat, 4, 4>(); |
| 969 | const TType *mat2x3 = StaticType::GetBasic<EbtFloat, 2, 3>(); |
| 970 | const TType *mat3x2 = StaticType::GetBasic<EbtFloat, 3, 2>(); |
| 971 | const TType *mat2x4 = StaticType::GetBasic<EbtFloat, 2, 4>(); |
| 972 | const TType *mat4x2 = StaticType::GetBasic<EbtFloat, 4, 2>(); |
| 973 | const TType *mat3x4 = StaticType::GetBasic<EbtFloat, 3, 4>(); |
| 974 | const TType *mat4x3 = StaticType::GetBasic<EbtFloat, 4, 3>(); |
| 975 | |
| 976 | // |
| 977 | // Matrix Functions. |
| 978 | // |
| 979 | insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat2, mat2, mat2); |
| 980 | insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat3, mat3, mat3); |
| 981 | insertBuiltInOp(COMMON_BUILTINS, EOpMulMatrixComponentWise, mat4, mat4, mat4); |
| 982 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat2x3, mat2x3, mat2x3); |
| 983 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat3x2, mat3x2, mat3x2); |
| 984 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat2x4, mat2x4, mat2x4); |
| 985 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat4x2, mat4x2, mat4x2); |
| 986 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat3x4, mat3x4, mat3x4); |
| 987 | insertBuiltInOp(ESSL3_BUILTINS, EOpMulMatrixComponentWise, mat4x3, mat4x3, mat4x3); |
| 988 | |
| 989 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2, float2, float2); |
| 990 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3, float3, float3); |
| 991 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4, float4, float4); |
| 992 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, float3, float2); |
| 993 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, float2, float3); |
| 994 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, float4, float2); |
| 995 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, float2, float4); |
| 996 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, float4, float3); |
| 997 | insertBuiltInOp(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, float3, float4); |
| 998 | |
| 999 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2, mat2); |
| 1000 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3, mat3); |
| 1001 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4, mat4); |
| 1002 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2x3, mat3x2); |
| 1003 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3x2, mat2x3); |
| 1004 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat2x4, mat4x2); |
| 1005 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4x2, mat2x4); |
| 1006 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat3x4, mat4x3); |
| 1007 | insertBuiltInOp(ESSL3_BUILTINS, EOpTranspose, mat4x3, mat3x4); |
| 1008 | |
| 1009 | insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat2); |
| 1010 | insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat3); |
| 1011 | insertBuiltInOp(ESSL3_BUILTINS, EOpDeterminant, float1, mat4); |
| 1012 | |
| 1013 | insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat2, mat2); |
| 1014 | insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat3, mat3); |
| 1015 | insertBuiltInOp(ESSL3_BUILTINS, EOpInverse, mat4, mat4); |
| 1016 | |
| 1017 | const TType *vec = StaticType::GetBasic<EbtVec>(); |
| 1018 | const TType *ivec = StaticType::GetBasic<EbtIVec>(); |
| 1019 | const TType *uvec = StaticType::GetBasic<EbtUVec>(); |
| 1020 | const TType *bvec = StaticType::GetBasic<EbtBVec>(); |
| 1021 | |
| 1022 | // |
| 1023 | // Vector relational functions. |
| 1024 | // |
| 1025 | insertBuiltInOp(COMMON_BUILTINS, EOpLessThanComponentWise, bvec, vec, vec); |
| 1026 | insertBuiltInOp(COMMON_BUILTINS, EOpLessThanComponentWise, bvec, ivec, ivec); |
| 1027 | insertBuiltInOp(ESSL3_BUILTINS, EOpLessThanComponentWise, bvec, uvec, uvec); |
| 1028 | insertBuiltInOp(COMMON_BUILTINS, EOpLessThanEqualComponentWise, bvec, vec, vec); |
| 1029 | insertBuiltInOp(COMMON_BUILTINS, EOpLessThanEqualComponentWise, bvec, ivec, ivec); |
| 1030 | insertBuiltInOp(ESSL3_BUILTINS, EOpLessThanEqualComponentWise, bvec, uvec, uvec); |
| 1031 | insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanComponentWise, bvec, vec, vec); |
| 1032 | insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanComponentWise, bvec, ivec, ivec); |
| 1033 | insertBuiltInOp(ESSL3_BUILTINS, EOpGreaterThanComponentWise, bvec, uvec, uvec); |
| 1034 | insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, vec, vec); |
| 1035 | insertBuiltInOp(COMMON_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, ivec, ivec); |
| 1036 | insertBuiltInOp(ESSL3_BUILTINS, EOpGreaterThanEqualComponentWise, bvec, uvec, uvec); |
| 1037 | insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, vec, vec); |
| 1038 | insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, ivec, ivec); |
| 1039 | insertBuiltInOp(ESSL3_BUILTINS, EOpEqualComponentWise, bvec, uvec, uvec); |
| 1040 | insertBuiltInOp(COMMON_BUILTINS, EOpEqualComponentWise, bvec, bvec, bvec); |
| 1041 | insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, vec, vec); |
| 1042 | insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, ivec, ivec); |
| 1043 | insertBuiltInOp(ESSL3_BUILTINS, EOpNotEqualComponentWise, bvec, uvec, uvec); |
| 1044 | insertBuiltInOp(COMMON_BUILTINS, EOpNotEqualComponentWise, bvec, bvec, bvec); |
| 1045 | insertBuiltInOp(COMMON_BUILTINS, EOpAny, bool1, bvec); |
| 1046 | insertBuiltInOp(COMMON_BUILTINS, EOpAll, bool1, bvec); |
| 1047 | insertBuiltInOp(COMMON_BUILTINS, EOpLogicalNotComponentWise, bvec, bvec); |
| 1048 | |
| 1049 | // |
| 1050 | // Integer functions |
| 1051 | // |
| 1052 | const TType *outGenUType = StaticType::GetQualified<EbtGenUType, EvqOut>(); |
| 1053 | |
| 1054 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldExtract, genIType, genIType, int1, int1); |
| 1055 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldExtract, genUType, genUType, int1, int1); |
| 1056 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldInsert, genIType, genIType, genIType, int1, int1); |
| 1057 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldInsert, genUType, genUType, genUType, int1, int1); |
| 1058 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldReverse, genIType, genIType); |
| 1059 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitfieldReverse, genUType, genUType); |
| 1060 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitCount, genIType, genIType); |
| 1061 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpBitCount, genIType, genUType); |
| 1062 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFindLSB, genIType, genIType); |
| 1063 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFindLSB, genIType, genUType); |
| 1064 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFindMSB, genIType, genIType); |
| 1065 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpFindMSB, genIType, genUType); |
| 1066 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUaddCarry, genUType, genUType, genUType, outGenUType); |
| 1067 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUsubBorrow, genUType, genUType, genUType, outGenUType); |
| 1068 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpUmulExtended, voidType, genUType, genUType, outGenUType, |
| 1069 | outGenUType); |
| 1070 | insertBuiltInOp(ESSL3_1_BUILTINS, EOpImulExtended, voidType, genIType, genIType, outGenIType, |
| 1071 | outGenIType); |
| 1072 | |
| 1073 | const TType *sampler2D = StaticType::GetBasic<EbtSampler2D>(); |
| 1074 | const TType *samplerCube = StaticType::GetBasic<EbtSamplerCube>(); |
| 1075 | |
| 1076 | // |
| 1077 | // Texture Functions for GLSL ES 1.0 |
| 1078 | // |
| 1079 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2); |
| 1080 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3); |
| 1081 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4); |
| 1082 | insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3); |
| 1083 | |
| 1084 | if (resources.OES_EGL_image_external || resources.NV_EGL_stream_consumer_external) |
| 1085 | { |
| 1086 | const TType *samplerExternalOES = StaticType::GetBasic<EbtSamplerExternalOES>(); |
| 1087 | |
| 1088 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2); |
| 1089 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3); |
| 1090 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4); |
| 1091 | } |
| 1092 | |
| 1093 | if (resources.ARB_texture_rectangle) |
| 1094 | { |
| 1095 | const TType *sampler2DRect = StaticType::GetBasic<EbtSampler2DRect>(); |
| 1096 | |
| 1097 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2); |
| 1098 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3); |
| 1099 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4); |
| 1100 | } |
| 1101 | |
| 1102 | if (resources.EXT_shader_texture_lod) |
| 1103 | { |
| 1104 | /* The *Grad* variants are new to both vertex and fragment shaders; the fragment |
| 1105 | * shader specific pieces are added separately below. |
| 1106 | */ |
| 1107 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1108 | "texture2DGradEXT", sampler2D, float2, float2, float2); |
| 1109 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1110 | "texture2DProjGradEXT", sampler2D, float3, float2, float2); |
| 1111 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1112 | "texture2DProjGradEXT", sampler2D, float4, float2, float2); |
| 1113 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1114 | "textureCubeGradEXT", samplerCube, float3, float3, float3); |
| 1115 | } |
| 1116 | |
| 1117 | if (type == GL_FRAGMENT_SHADER) |
| 1118 | { |
| 1119 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1); |
| 1120 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1); |
| 1121 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1); |
| 1122 | insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1); |
| 1123 | |
| 1124 | if (resources.OES_standard_derivatives) |
| 1125 | { |
| 1126 | insertBuiltInOp(ESSL1_BUILTINS, EOpDFdx, TExtension::OES_standard_derivatives, genType, |
| 1127 | genType); |
| 1128 | insertBuiltInOp(ESSL1_BUILTINS, EOpDFdy, TExtension::OES_standard_derivatives, genType, |
| 1129 | genType); |
| 1130 | insertBuiltInOp(ESSL1_BUILTINS, EOpFwidth, TExtension::OES_standard_derivatives, |
| 1131 | genType, genType); |
| 1132 | } |
| 1133 | |
| 1134 | if (resources.EXT_shader_texture_lod) |
| 1135 | { |
| 1136 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1137 | "texture2DLodEXT", sampler2D, float2, float1); |
| 1138 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1139 | "texture2DProjLodEXT", sampler2D, float3, float1); |
| 1140 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1141 | "texture2DProjLodEXT", sampler2D, float4, float1); |
| 1142 | insertBuiltIn(ESSL1_BUILTINS, TExtension::EXT_shader_texture_lod, float4, |
| 1143 | "textureCubeLodEXT", samplerCube, float3, float1); |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | if (type == GL_VERTEX_SHADER) |
| 1148 | { |
| 1149 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1); |
| 1150 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1); |
| 1151 | insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1); |
| 1152 | insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1); |
| 1153 | } |
| 1154 | |
| 1155 | const TType *gvec4 = StaticType::GetBasic<EbtGVec4>(); |
| 1156 | |
| 1157 | const TType *gsampler2D = StaticType::GetBasic<EbtGSampler2D>(); |
| 1158 | const TType *gsamplerCube = StaticType::GetBasic<EbtGSamplerCube>(); |
| 1159 | const TType *gsampler3D = StaticType::GetBasic<EbtGSampler3D>(); |
| 1160 | const TType *gsampler2DArray = StaticType::GetBasic<EbtGSampler2DArray>(); |
| 1161 | const TType *gsampler2DMS = StaticType::GetBasic<EbtGSampler2DMS>(); |
| 1162 | |
| 1163 | // |
| 1164 | // Texture Functions for GLSL ES 3.0 |
| 1165 | // |
| 1166 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2); |
| 1167 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3); |
| 1168 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3); |
| 1169 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3); |
| 1170 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3); |
| 1171 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4); |
| 1172 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4); |
| 1173 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1); |
| 1174 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1); |
| 1175 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1); |
| 1176 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1); |
| 1177 | |
| 1178 | if (resources.OES_EGL_image_external_essl3) |
| 1179 | { |
| 1180 | const TType *samplerExternalOES = StaticType::GetBasic<EbtSamplerExternalOES>(); |
| 1181 | |
| 1182 | insertBuiltIn(ESSL3_BUILTINS, float4, "texture", samplerExternalOES, float2); |
| 1183 | insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES, float3); |
| 1184 | insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES, float4); |
| 1185 | } |
| 1186 | |
| 1187 | if (resources.EXT_YUV_target) |
| 1188 | { |
| 1189 | const TType *samplerExternal2DY2YEXT = StaticType::GetBasic<EbtSamplerExternal2DY2YEXT>(); |
| 1190 | |
| 1191 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "texture", |
| 1192 | samplerExternal2DY2YEXT, float2); |
| 1193 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "textureProj", |
| 1194 | samplerExternal2DY2YEXT, float3); |
| 1195 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "textureProj", |
| 1196 | samplerExternal2DY2YEXT, float4); |
| 1197 | |
| 1198 | const TType *yuvCscStandardEXT = StaticType::GetBasic<EbtYuvCscStandardEXT>(); |
| 1199 | |
| 1200 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float3, "rgb_2_yuv", float3, |
| 1201 | yuvCscStandardEXT); |
| 1202 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float3, "yuv_2_rgb", float3, |
| 1203 | yuvCscStandardEXT); |
| 1204 | } |
| 1205 | |
| 1206 | if (type == GL_FRAGMENT_SHADER) |
| 1207 | { |
| 1208 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1); |
| 1209 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1); |
| 1210 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1); |
| 1211 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1); |
| 1212 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1); |
| 1213 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1); |
| 1214 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1); |
| 1215 | |
| 1216 | if (resources.OES_EGL_image_external_essl3) |
| 1217 | { |
| 1218 | const TType *samplerExternalOES = StaticType::GetBasic<EbtSamplerExternalOES>(); |
| 1219 | |
| 1220 | insertBuiltIn(ESSL3_BUILTINS, float4, "texture", samplerExternalOES, float2, float1); |
| 1221 | insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES, float3, |
| 1222 | float1); |
| 1223 | insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES, float4, |
| 1224 | float1); |
| 1225 | } |
| 1226 | |
| 1227 | if (resources.EXT_YUV_target) |
| 1228 | { |
| 1229 | const TType *samplerExternal2DY2YEXT = |
| 1230 | StaticType::GetBasic<EbtSamplerExternal2DY2YEXT>(); |
| 1231 | |
| 1232 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "texture", |
| 1233 | samplerExternal2DY2YEXT, float2, float1); |
| 1234 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "textureProj", |
| 1235 | samplerExternal2DY2YEXT, float3, float1); |
| 1236 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "textureProj", |
| 1237 | samplerExternal2DY2YEXT, float4, float1); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | const TType *sampler2DShadow = StaticType::GetBasic<EbtSampler2DShadow>(); |
| 1242 | const TType *samplerCubeShadow = StaticType::GetBasic<EbtSamplerCubeShadow>(); |
| 1243 | const TType *sampler2DArrayShadow = StaticType::GetBasic<EbtSampler2DArrayShadow>(); |
| 1244 | |
| 1245 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3); |
| 1246 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4); |
| 1247 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4); |
| 1248 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4); |
| 1249 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1); |
| 1250 | |
| 1251 | if (type == GL_FRAGMENT_SHADER) |
| 1252 | { |
| 1253 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1); |
| 1254 | insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1); |
| 1255 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1); |
| 1256 | } |
| 1257 | |
| 1258 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1); |
| 1259 | insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1); |
| 1260 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1); |
| 1261 | insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1); |
| 1262 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1); |
| 1263 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1); |
| 1264 | insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1); |
| 1265 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2DMS); |
| 1266 | |
| 1267 | if (resources.OES_EGL_image_external_essl3) |
| 1268 | { |
| 1269 | const TType *samplerExternalOES = StaticType::GetBasic<EbtSamplerExternalOES>(); |
| 1270 | |
| 1271 | insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerExternalOES, int1); |
| 1272 | } |
| 1273 | |
| 1274 | if (resources.EXT_YUV_target) |
| 1275 | { |
| 1276 | const TType *samplerExternal2DY2YEXT = StaticType::GetBasic<EbtSamplerExternal2DY2YEXT>(); |
| 1277 | |
| 1278 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, int2, "textureSize", |
| 1279 | samplerExternal2DY2YEXT, int1); |
| 1280 | } |
| 1281 | |
| 1282 | if (type == GL_FRAGMENT_SHADER) |
| 1283 | { |
| 1284 | insertBuiltInOp(ESSL3_BUILTINS, EOpDFdx, genType, genType); |
| 1285 | insertBuiltInOp(ESSL3_BUILTINS, EOpDFdy, genType, genType); |
| 1286 | insertBuiltInOp(ESSL3_BUILTINS, EOpFwidth, genType, genType); |
| 1287 | } |
| 1288 | |
| 1289 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2); |
| 1290 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3); |
| 1291 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2); |
| 1292 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2); |
| 1293 | |
| 1294 | if (type == GL_FRAGMENT_SHADER) |
| 1295 | { |
| 1296 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1); |
| 1297 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1); |
| 1298 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, |
| 1299 | float1); |
| 1300 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, |
| 1301 | float1); |
| 1302 | } |
| 1303 | |
| 1304 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2); |
| 1305 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2); |
| 1306 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3); |
| 1307 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2); |
| 1308 | |
| 1309 | if (type == GL_FRAGMENT_SHADER) |
| 1310 | { |
| 1311 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1); |
| 1312 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1); |
| 1313 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1); |
| 1314 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, |
| 1315 | float1); |
| 1316 | } |
| 1317 | |
| 1318 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2); |
| 1319 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3); |
| 1320 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, |
| 1321 | int2); |
| 1322 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2); |
| 1323 | |
| 1324 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1); |
| 1325 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1); |
| 1326 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1); |
| 1327 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1); |
| 1328 | |
| 1329 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2); |
| 1330 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2); |
| 1331 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3); |
| 1332 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, |
| 1333 | int2); |
| 1334 | |
| 1335 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1); |
| 1336 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1); |
| 1337 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1); |
| 1338 | |
| 1339 | if (resources.OES_EGL_image_external_essl3) |
| 1340 | { |
| 1341 | const TType *samplerExternalOES = StaticType::GetBasic<EbtSamplerExternalOES>(); |
| 1342 | |
| 1343 | insertBuiltIn(ESSL3_BUILTINS, float4, "texelFetch", samplerExternalOES, int2, int1); |
| 1344 | } |
| 1345 | |
| 1346 | if (resources.EXT_YUV_target) |
| 1347 | { |
| 1348 | const TType *samplerExternal2DY2YEXT = StaticType::GetBasic<EbtSamplerExternal2DY2YEXT>(); |
| 1349 | |
| 1350 | insertBuiltIn(ESSL3_BUILTINS, TExtension::EXT_YUV_target, float4, "texelFetch", |
| 1351 | samplerExternal2DY2YEXT, int2, int1); |
| 1352 | } |
| 1353 | |
| 1354 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2); |
| 1355 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3); |
| 1356 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2); |
| 1357 | |
| 1358 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2); |
| 1359 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3); |
| 1360 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3); |
| 1361 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2); |
| 1362 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3); |
| 1363 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2); |
| 1364 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, |
| 1365 | float2); |
| 1366 | |
| 1367 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, |
| 1368 | int2); |
| 1369 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, |
| 1370 | int3); |
| 1371 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, |
| 1372 | float2, int2); |
| 1373 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, |
| 1374 | float2, int2); |
| 1375 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, |
| 1376 | float2, int2); |
| 1377 | |
| 1378 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2); |
| 1379 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2); |
| 1380 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3); |
| 1381 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, |
| 1382 | float2); |
| 1383 | |
| 1384 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, |
| 1385 | float2, int2); |
| 1386 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, |
| 1387 | float2, int2); |
| 1388 | insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, |
| 1389 | float3, int3); |
| 1390 | insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, |
| 1391 | float2, int2); |
| 1392 | |
| 1393 | const TType *atomicCounter = StaticType::GetBasic<EbtAtomicCounter>(); |
| 1394 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicCounter", atomicCounter); |
| 1395 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicCounterIncrement", atomicCounter); |
| 1396 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicCounterDecrement", atomicCounter); |
| 1397 | |
| 1398 | // Insert all atomic memory functions |
| 1399 | const TType *int1InOut = StaticType::GetQualified<EbtInt, EvqInOut>(); |
| 1400 | const TType *uint1InOut = StaticType::GetQualified<EbtUInt, EvqInOut>(); |
| 1401 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicAdd", uint1InOut, uint1); |
| 1402 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicAdd", int1InOut, int1); |
| 1403 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicMin", uint1InOut, uint1); |
| 1404 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicMin", int1InOut, int1); |
| 1405 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicMax", uint1InOut, uint1); |
| 1406 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicMax", int1InOut, int1); |
| 1407 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicAnd", uint1InOut, uint1); |
| 1408 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicAnd", int1InOut, int1); |
| 1409 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicOr", uint1InOut, uint1); |
| 1410 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicOr", int1InOut, int1); |
| 1411 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicXor", uint1InOut, uint1); |
| 1412 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicXor", int1InOut, int1); |
| 1413 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicExchange", uint1InOut, uint1); |
| 1414 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicExchange", int1InOut, int1); |
| 1415 | insertBuiltIn(ESSL3_1_BUILTINS, uint1, "atomicCompSwap", uint1InOut, uint1, uint1); |
| 1416 | insertBuiltIn(ESSL3_1_BUILTINS, int1, "atomicCompSwap", int1InOut, int1, int1); |
| 1417 | |
| 1418 | const TType *gimage2D = StaticType::GetBasic<EbtGImage2D>(); |
| 1419 | const TType *gimage3D = StaticType::GetBasic<EbtGImage3D>(); |
| 1420 | const TType *gimage2DArray = StaticType::GetBasic<EbtGImage2DArray>(); |
| 1421 | const TType *gimageCube = StaticType::GetBasic<EbtGImageCube>(); |
| 1422 | |
| 1423 | insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage2D, int2, gvec4); |
| 1424 | insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage3D, int3, gvec4); |
| 1425 | insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage2DArray, int3, gvec4); |
| 1426 | insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimageCube, int3, gvec4); |
| 1427 | |
| 1428 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage2D, int2); |
| 1429 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage3D, int3); |
| 1430 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage2DArray, int3); |
| 1431 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimageCube, int3); |
| 1432 | |
| 1433 | insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimage2D); |
| 1434 | insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage3D); |
| 1435 | insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage2DArray); |
| 1436 | insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimageCube); |
| 1437 | |
| 1438 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrier, voidType, |
| 1439 | "memoryBarrier"); |
| 1440 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierAtomicCounter, voidType, |
| 1441 | "memoryBarrierAtomicCounter"); |
| 1442 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierBuffer, voidType, |
| 1443 | "memoryBarrierBuffer"); |
| 1444 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierImage, voidType, |
| 1445 | "memoryBarrierImage"); |
| 1446 | |
| 1447 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "texelFetch", gsampler2DMS, int2, int1); |
| 1448 | |
| 1449 | // Insert all variations of textureGather. |
| 1450 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsampler2D, float2); |
| 1451 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsampler2D, float2, int1); |
| 1452 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsampler2DArray, float3); |
| 1453 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsampler2DArray, float3, int1); |
| 1454 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsamplerCube, float3); |
| 1455 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGather", gsamplerCube, float3, int1); |
| 1456 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", sampler2DShadow, float2); |
| 1457 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", sampler2DShadow, float2, float1); |
| 1458 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", sampler2DArrayShadow, float3); |
| 1459 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", sampler2DArrayShadow, float3, float1); |
| 1460 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", samplerCubeShadow, float3); |
| 1461 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGather", samplerCubeShadow, float3, float1); |
| 1462 | |
| 1463 | // Insert all variations of textureGatherOffset. |
| 1464 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGatherOffset", gsampler2D, float2, int2); |
| 1465 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGatherOffset", gsampler2D, float2, int2, int1); |
| 1466 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGatherOffset", gsampler2DArray, float3, int2); |
| 1467 | insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "textureGatherOffset", gsampler2DArray, float3, int2, |
| 1468 | int1); |
| 1469 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGatherOffset", sampler2DShadow, float2, float1, |
| 1470 | int2); |
| 1471 | insertBuiltIn(ESSL3_1_BUILTINS, float4, "textureGatherOffset", sampler2DArrayShadow, float3, |
| 1472 | float1, int2); |
| 1473 | |
| 1474 | if (type == GL_COMPUTE_SHADER) |
| 1475 | { |
| 1476 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpBarrier, voidType, "barrier"); |
| 1477 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpMemoryBarrierShared, voidType, |
| 1478 | "memoryBarrierShared"); |
| 1479 | insertBuiltInFunctionNoParameters(ESSL3_1_BUILTINS, EOpGroupMemoryBarrier, voidType, |
| 1480 | "groupMemoryBarrier"); |
| 1481 | } |
| 1482 | |
| 1483 | if (type == GL_GEOMETRY_SHADER_EXT) |
| 1484 | { |
| 1485 | TExtension extension = TExtension::EXT_geometry_shader; |
| 1486 | insertBuiltInFunctionNoParametersExt(ESSL3_1_BUILTINS, extension, EOpEmitVertex, voidType, |
| 1487 | "EmitVertex"); |
| 1488 | insertBuiltInFunctionNoParametersExt(ESSL3_1_BUILTINS, extension, EOpEndPrimitive, voidType, |
| 1489 | "EndPrimitive"); |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | void TSymbolTable::initializeBuiltInVariables(sh::GLenum type, |
| 1494 | ShShaderSpec spec, |
| 1495 | const ShBuiltInResources &resources) |
| 1496 | { |
| 1497 | const TSourceLoc zeroSourceLoc = {0, 0, 0, 0}; |
| 1498 | |
| 1499 | // |
| 1500 | // Depth range in window coordinates |
| 1501 | // |
| 1502 | TFieldList *fields = new TFieldList(); |
| 1503 | auto highpFloat1 = new TType(EbtFloat, EbpHigh, EvqGlobal, 1); |
| 1504 | TField *near = new TField(highpFloat1, ImmutableString("near"), zeroSourceLoc); |
| 1505 | TField *far = new TField(highpFloat1, ImmutableString("far"), zeroSourceLoc); |
| 1506 | TField *diff = new TField(highpFloat1, ImmutableString("diff"), zeroSourceLoc); |
| 1507 | fields->push_back(near); |
| 1508 | fields->push_back(far); |
| 1509 | fields->push_back(diff); |
| 1510 | TStructure *depthRangeStruct = new TStructure(this, ImmutableString("gl_DepthRangeParameters"), |
| 1511 | fields, SymbolType::BuiltIn); |
| 1512 | insertStructType(COMMON_BUILTINS, depthRangeStruct); |
| 1513 | TType *depthRangeType = new TType(depthRangeStruct); |
| 1514 | depthRangeType->setQualifier(EvqUniform); |
| 1515 | depthRangeType->realize(); |
| 1516 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_DepthRange"), depthRangeType); |
| 1517 | |
| 1518 | // |
| 1519 | // Implementation dependent built-in constants. |
| 1520 | // |
| 1521 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexAttribs"), |
| 1522 | resources.MaxVertexAttribs); |
| 1523 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexUniformVectors"), |
| 1524 | resources.MaxVertexUniformVectors); |
| 1525 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexTextureImageUnits"), |
| 1526 | resources.MaxVertexTextureImageUnits); |
| 1527 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxCombinedTextureImageUnits"), |
| 1528 | resources.MaxCombinedTextureImageUnits); |
| 1529 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxTextureImageUnits"), |
| 1530 | resources.MaxTextureImageUnits); |
| 1531 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxFragmentUniformVectors"), |
| 1532 | resources.MaxFragmentUniformVectors); |
| 1533 | |
| 1534 | insertConstInt<EbpMedium>(ESSL1_BUILTINS, ImmutableString("gl_MaxVaryingVectors"), |
| 1535 | resources.MaxVaryingVectors); |
| 1536 | |
| 1537 | insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxDrawBuffers"), |
| 1538 | resources.MaxDrawBuffers); |
| 1539 | if (resources.EXT_blend_func_extended) |
| 1540 | { |
| 1541 | insertConstIntExt<EbpMedium>(COMMON_BUILTINS, TExtension::EXT_blend_func_extended, |
| 1542 | ImmutableString("gl_MaxDualSourceDrawBuffersEXT"), |
| 1543 | resources.MaxDualSourceDrawBuffers); |
| 1544 | } |
| 1545 | |
| 1546 | insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxVertexOutputVectors"), |
| 1547 | resources.MaxVertexOutputVectors); |
| 1548 | insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxFragmentInputVectors"), |
| 1549 | resources.MaxFragmentInputVectors); |
| 1550 | insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MinProgramTexelOffset"), |
| 1551 | resources.MinProgramTexelOffset); |
| 1552 | insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxProgramTexelOffset"), |
| 1553 | resources.MaxProgramTexelOffset); |
| 1554 | |
| 1555 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxImageUnits"), |
| 1556 | resources.MaxImageUnits); |
| 1557 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexImageUniforms"), |
| 1558 | resources.MaxVertexImageUniforms); |
| 1559 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxFragmentImageUniforms"), |
| 1560 | resources.MaxFragmentImageUniforms); |
| 1561 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeImageUniforms"), |
| 1562 | resources.MaxComputeImageUniforms); |
| 1563 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxCombinedImageUniforms"), |
| 1564 | resources.MaxCombinedImageUniforms); |
| 1565 | |
| 1566 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, |
| 1567 | ImmutableString("gl_MaxCombinedShaderOutputResources"), |
| 1568 | resources.MaxCombinedShaderOutputResources); |
| 1569 | |
| 1570 | insertConstIvec3<EbpHigh>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeWorkGroupCount"), |
| 1571 | resources.MaxComputeWorkGroupCount); |
| 1572 | insertConstIvec3<EbpHigh>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeWorkGroupSize"), |
| 1573 | resources.MaxComputeWorkGroupSize); |
| 1574 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeUniformComponents"), |
| 1575 | resources.MaxComputeUniformComponents); |
| 1576 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeTextureImageUnits"), |
| 1577 | resources.MaxComputeTextureImageUnits); |
| 1578 | |
| 1579 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeAtomicCounters"), |
| 1580 | resources.MaxComputeAtomicCounters); |
| 1581 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, |
| 1582 | ImmutableString("gl_MaxComputeAtomicCounterBuffers"), |
| 1583 | resources.MaxComputeAtomicCounterBuffers); |
| 1584 | |
| 1585 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexAtomicCounters"), |
| 1586 | resources.MaxVertexAtomicCounters); |
| 1587 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxFragmentAtomicCounters"), |
| 1588 | resources.MaxFragmentAtomicCounters); |
| 1589 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxCombinedAtomicCounters"), |
| 1590 | resources.MaxCombinedAtomicCounters); |
| 1591 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxAtomicCounterBindings"), |
| 1592 | resources.MaxAtomicCounterBindings); |
| 1593 | |
| 1594 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexAtomicCounterBuffers"), |
| 1595 | resources.MaxVertexAtomicCounterBuffers); |
| 1596 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, |
| 1597 | ImmutableString("gl_MaxFragmentAtomicCounterBuffers"), |
| 1598 | resources.MaxFragmentAtomicCounterBuffers); |
| 1599 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, |
| 1600 | ImmutableString("gl_MaxCombinedAtomicCounterBuffers"), |
| 1601 | resources.MaxCombinedAtomicCounterBuffers); |
| 1602 | insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxAtomicCounterBufferSize"), |
| 1603 | resources.MaxAtomicCounterBufferSize); |
| 1604 | |
| 1605 | if (resources.EXT_geometry_shader) |
| 1606 | { |
| 1607 | TExtension ext = TExtension::EXT_geometry_shader; |
| 1608 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1609 | ImmutableString("gl_MaxGeometryInputComponents"), |
| 1610 | resources.MaxGeometryInputComponents); |
| 1611 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1612 | ImmutableString("gl_MaxGeometryOutputComponents"), |
| 1613 | resources.MaxGeometryOutputComponents); |
| 1614 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1615 | ImmutableString("gl_MaxGeometryImageUniforms"), |
| 1616 | resources.MaxGeometryImageUniforms); |
| 1617 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1618 | ImmutableString("gl_MaxGeometryTextureImageUnits"), |
| 1619 | resources.MaxGeometryTextureImageUnits); |
| 1620 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1621 | ImmutableString("gl_MaxGeometryOutputVertices"), |
| 1622 | resources.MaxGeometryOutputVertices); |
| 1623 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1624 | ImmutableString("gl_MaxGeometryTotalOutputComponents"), |
| 1625 | resources.MaxGeometryTotalOutputComponents); |
| 1626 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1627 | ImmutableString("gl_MaxGeometryUniformComponents"), |
| 1628 | resources.MaxGeometryUniformComponents); |
| 1629 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1630 | ImmutableString("gl_MaxGeometryAtomicCounters"), |
| 1631 | resources.MaxGeometryAtomicCounters); |
| 1632 | insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext, |
| 1633 | ImmutableString("gl_MaxGeometryAtomicCounterBuffers"), |
| 1634 | resources.MaxGeometryAtomicCounterBuffers); |
| 1635 | } |
| 1636 | |
| 1637 | // |
| 1638 | // Insert some special built-in variables that are not in |
| 1639 | // the built-in header files. |
| 1640 | // |
| 1641 | |
| 1642 | if (resources.OVR_multiview && type != GL_COMPUTE_SHADER) |
| 1643 | { |
| 1644 | const TType *viewIDType = StaticType::Get<EbtUInt, EbpHigh, EvqViewIDOVR, 1, 1>(); |
| 1645 | insertVariableExt(ESSL3_BUILTINS, TExtension::OVR_multiview, |
| 1646 | ImmutableString("gl_ViewID_OVR"), viewIDType); |
| 1647 | |
| 1648 | // ESSL 1.00 doesn't have unsigned integers, so gl_ViewID_OVR is a signed integer in ESSL |
| 1649 | // 1.00. This is specified in the WEBGL_multiview spec. |
| 1650 | const TType *viewIDIntType = StaticType::Get<EbtInt, EbpHigh, EvqViewIDOVR, 1, 1>(); |
| 1651 | insertVariableExt(ESSL1_BUILTINS, TExtension::OVR_multiview, |
| 1652 | ImmutableString("gl_ViewID_OVR"), viewIDIntType); |
| 1653 | } |
| 1654 | |
| 1655 | const TType *positionType = StaticType::Get<EbtFloat, EbpHigh, EvqPosition, 4, 1>(); |
| 1656 | const TType *primitiveIDType = StaticType::Get<EbtInt, EbpHigh, EvqPrimitiveID, 1, 1>(); |
| 1657 | const TType *layerType = StaticType::Get<EbtInt, EbpHigh, EvqLayer, 1, 1>(); |
| 1658 | |
| 1659 | switch (type) |
| 1660 | { |
| 1661 | case GL_FRAGMENT_SHADER: |
| 1662 | { |
| 1663 | const TType *fragCoordType = StaticType::Get<EbtFloat, EbpMedium, EvqFragCoord, 4, 1>(); |
| 1664 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_FragCoord"), fragCoordType); |
| 1665 | const TType *frontFacingType = StaticType::GetQualified<EbtBool, EvqFrontFacing>(); |
| 1666 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_FrontFacing"), frontFacingType); |
| 1667 | const TType *pointCoordType = |
| 1668 | StaticType::Get<EbtFloat, EbpMedium, EvqPointCoord, 2, 1>(); |
| 1669 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_PointCoord"), pointCoordType); |
| 1670 | |
| 1671 | const TType *fragColorType = StaticType::Get<EbtFloat, EbpMedium, EvqFragColor, 4, 1>(); |
| 1672 | insertVariable(ESSL1_BUILTINS, ImmutableString("gl_FragColor"), fragColorType); |
| 1673 | |
| 1674 | TType *fragDataType = new TType(EbtFloat, EbpMedium, EvqFragData, 4); |
| 1675 | if (spec != SH_WEBGL2_SPEC && spec != SH_WEBGL3_SPEC) |
| 1676 | { |
| 1677 | fragDataType->makeArray(resources.MaxDrawBuffers); |
| 1678 | } |
| 1679 | else |
| 1680 | { |
| 1681 | fragDataType->makeArray(1u); |
| 1682 | } |
| 1683 | fragDataType->realize(); |
| 1684 | insertVariable(ESSL1_BUILTINS, ImmutableString("gl_FragData"), fragDataType); |
| 1685 | |
| 1686 | if (resources.EXT_blend_func_extended) |
| 1687 | { |
| 1688 | const TType *secondaryFragColorType = |
| 1689 | StaticType::Get<EbtFloat, EbpMedium, EvqSecondaryFragColorEXT, 4, 1>(); |
| 1690 | insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_blend_func_extended, |
| 1691 | ImmutableString("gl_SecondaryFragColorEXT"), |
| 1692 | secondaryFragColorType); |
| 1693 | TType *secondaryFragDataType = |
| 1694 | new TType(EbtFloat, EbpMedium, EvqSecondaryFragDataEXT, 4, 1); |
| 1695 | secondaryFragDataType->makeArray(resources.MaxDualSourceDrawBuffers); |
| 1696 | secondaryFragDataType->realize(); |
| 1697 | insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_blend_func_extended, |
| 1698 | ImmutableString("gl_SecondaryFragDataEXT"), |
| 1699 | secondaryFragDataType); |
| 1700 | } |
| 1701 | |
| 1702 | if (resources.EXT_frag_depth) |
| 1703 | { |
| 1704 | TType *fragDepthEXTType = |
| 1705 | new TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, |
| 1706 | EvqFragDepthEXT, 1); |
| 1707 | fragDepthEXTType->realize(); |
| 1708 | insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_frag_depth, |
| 1709 | ImmutableString("gl_FragDepthEXT"), fragDepthEXTType); |
| 1710 | } |
| 1711 | |
| 1712 | const TType *fragDepthType = StaticType::Get<EbtFloat, EbpHigh, EvqFragDepth, 1, 1>(); |
| 1713 | insertVariable(ESSL3_BUILTINS, ImmutableString("gl_FragDepth"), fragDepthType); |
| 1714 | |
| 1715 | const TType *lastFragColorType = |
| 1716 | StaticType::Get<EbtFloat, EbpMedium, EvqLastFragColor, 4, 1>(); |
| 1717 | |
| 1718 | if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch) |
| 1719 | { |
| 1720 | TType *lastFragDataType = new TType(EbtFloat, EbpMedium, EvqLastFragData, 4, 1); |
| 1721 | lastFragDataType->makeArray(resources.MaxDrawBuffers); |
| 1722 | lastFragDataType->realize(); |
| 1723 | |
| 1724 | if (resources.EXT_shader_framebuffer_fetch) |
| 1725 | { |
| 1726 | insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_shader_framebuffer_fetch, |
| 1727 | ImmutableString("gl_LastFragData"), lastFragDataType); |
| 1728 | } |
| 1729 | else if (resources.NV_shader_framebuffer_fetch) |
| 1730 | { |
| 1731 | insertVariableExt(ESSL1_BUILTINS, TExtension::NV_shader_framebuffer_fetch, |
| 1732 | ImmutableString("gl_LastFragColor"), lastFragColorType); |
| 1733 | insertVariableExt(ESSL1_BUILTINS, TExtension::NV_shader_framebuffer_fetch, |
| 1734 | ImmutableString("gl_LastFragData"), lastFragDataType); |
| 1735 | } |
| 1736 | } |
| 1737 | else if (resources.ARM_shader_framebuffer_fetch) |
| 1738 | { |
| 1739 | insertVariableExt(ESSL1_BUILTINS, TExtension::ARM_shader_framebuffer_fetch, |
| 1740 | ImmutableString("gl_LastFragColorARM"), lastFragColorType); |
| 1741 | } |
| 1742 | |
| 1743 | if (resources.EXT_geometry_shader) |
| 1744 | { |
| 1745 | TExtension extension = TExtension::EXT_geometry_shader; |
| 1746 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveID"), |
| 1747 | primitiveIDType); |
| 1748 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Layer"), |
| 1749 | layerType); |
| 1750 | } |
| 1751 | |
| 1752 | break; |
| 1753 | } |
| 1754 | case GL_VERTEX_SHADER: |
| 1755 | { |
| 1756 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_Position"), positionType); |
| 1757 | const TType *pointSizeType = StaticType::Get<EbtFloat, EbpMedium, EvqPointSize, 1, 1>(); |
| 1758 | insertVariable(COMMON_BUILTINS, ImmutableString("gl_PointSize"), pointSizeType); |
| 1759 | const TType *instanceIDType = StaticType::Get<EbtInt, EbpHigh, EvqInstanceID, 1, 1>(); |
| 1760 | insertVariable(ESSL3_BUILTINS, ImmutableString("gl_InstanceID"), instanceIDType); |
| 1761 | const TType *vertexIDType = StaticType::Get<EbtInt, EbpHigh, EvqVertexID, 1, 1>(); |
| 1762 | insertVariable(ESSL3_BUILTINS, ImmutableString("gl_VertexID"), vertexIDType); |
| 1763 | |
| 1764 | // For internal use by ANGLE - not exposed to the parser. |
| 1765 | const TType *viewportIndexType = |
| 1766 | StaticType::Get<EbtInt, EbpHigh, EvqViewportIndex, 1, 1>(); |
| 1767 | insertVariable(GLSL_BUILTINS, ImmutableString("gl_ViewportIndex"), viewportIndexType); |
| 1768 | // gl_Layer exists in other shader stages in ESSL, but not in vertex shader so far. |
| 1769 | insertVariable(GLSL_BUILTINS, ImmutableString("gl_Layer"), layerType); |
| 1770 | break; |
| 1771 | } |
| 1772 | case GL_COMPUTE_SHADER: |
| 1773 | { |
| 1774 | const TType *numWorkGroupsType = |
| 1775 | StaticType::Get<EbtUInt, EbpUndefined, EvqNumWorkGroups, 3, 1>(); |
| 1776 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_NumWorkGroups"), |
| 1777 | numWorkGroupsType); |
| 1778 | const TType *workGroupSizeType = |
| 1779 | StaticType::Get<EbtUInt, EbpUndefined, EvqWorkGroupSize, 3, 1>(); |
| 1780 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_WorkGroupSize"), |
| 1781 | workGroupSizeType); |
| 1782 | const TType *workGroupIDType = |
| 1783 | StaticType::Get<EbtUInt, EbpUndefined, EvqWorkGroupID, 3, 1>(); |
| 1784 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_WorkGroupID"), workGroupIDType); |
| 1785 | const TType *localInvocationIDType = |
| 1786 | StaticType::Get<EbtUInt, EbpUndefined, EvqLocalInvocationID, 3, 1>(); |
| 1787 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_LocalInvocationID"), |
| 1788 | localInvocationIDType); |
| 1789 | const TType *globalInvocationIDType = |
| 1790 | StaticType::Get<EbtUInt, EbpUndefined, EvqGlobalInvocationID, 3, 1>(); |
| 1791 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_GlobalInvocationID"), |
| 1792 | globalInvocationIDType); |
| 1793 | const TType *localInvocationIndexType = |
| 1794 | StaticType::Get<EbtUInt, EbpUndefined, EvqLocalInvocationIndex, 1, 1>(); |
| 1795 | insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_LocalInvocationIndex"), |
| 1796 | localInvocationIndexType); |
| 1797 | break; |
| 1798 | } |
| 1799 | |
| 1800 | case GL_GEOMETRY_SHADER_EXT: |
| 1801 | { |
| 1802 | TExtension extension = TExtension::EXT_geometry_shader; |
| 1803 | |
| 1804 | // Add built-in interface block gl_PerVertex and the built-in array gl_in. |
| 1805 | // TODO(jiawei.shao@intel.com): implement GL_EXT_geometry_point_size. |
| 1806 | TFieldList *glPerVertexFieldList = new TFieldList(); |
| 1807 | TField *glPositionField = |
| 1808 | new TField(new TType(*positionType), ImmutableString("gl_Position"), zeroSourceLoc); |
| 1809 | glPerVertexFieldList->push_back(glPositionField); |
| 1810 | |
| 1811 | const ImmutableString glPerVertexString("gl_PerVertex"); |
| 1812 | TInterfaceBlock *glPerVertexInBlock = |
| 1813 | new TInterfaceBlock(this, glPerVertexString, glPerVertexFieldList, |
| 1814 | TLayoutQualifier::Create(), SymbolType::BuiltIn, extension); |
| 1815 | insertInterfaceBlock(ESSL3_1_BUILTINS, glPerVertexInBlock); |
| 1816 | |
| 1817 | // The array size of gl_in is undefined until we get a valid input primitive |
| 1818 | // declaration. |
| 1819 | TType *glInType = |
| 1820 | new TType(glPerVertexInBlock, EvqPerVertexIn, TLayoutQualifier::Create()); |
| 1821 | glInType->makeArray(0u); |
| 1822 | glInType->realize(); |
| 1823 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_in"), glInType); |
| 1824 | |
| 1825 | TInterfaceBlock *glPerVertexOutBlock = |
| 1826 | new TInterfaceBlock(this, glPerVertexString, glPerVertexFieldList, |
| 1827 | TLayoutQualifier::Create(), SymbolType::BuiltIn); |
| 1828 | TType *glPositionInBlockType = new TType(EbtFloat, EbpHigh, EvqPosition, 4); |
| 1829 | glPositionInBlockType->setInterfaceBlock(glPerVertexOutBlock); |
| 1830 | glPositionInBlockType->realize(); |
| 1831 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Position"), |
| 1832 | glPositionInBlockType); |
| 1833 | |
| 1834 | const TType *primitiveIDInType = |
| 1835 | StaticType::Get<EbtInt, EbpHigh, EvqPrimitiveIDIn, 1, 1>(); |
| 1836 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveIDIn"), |
| 1837 | primitiveIDInType); |
| 1838 | const TType *invocationIDType = |
| 1839 | StaticType::Get<EbtInt, EbpHigh, EvqInvocationID, 1, 1>(); |
| 1840 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_InvocationID"), |
| 1841 | invocationIDType); |
| 1842 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveID"), |
| 1843 | primitiveIDType); |
| 1844 | insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Layer"), layerType); |
| 1845 | |
| 1846 | break; |
| 1847 | } |
| 1848 | default: |
| 1849 | UNREACHABLE(); |
| 1850 | } |
| 1851 | } |
| 1852 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 1853 | } // namespace sh |