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