blob: e8d0a8fc8489da27af87bf2a64fd04047ffe5943 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +00002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
Olli Etuaho0f684632017-07-13 12:42:15 +03006// Symbol table for parsing. The design principles and most of the functionality are documented in
7// the header file.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00008//
9
apatrick@chromium.orge057c5d2012-01-26 19:18:24 +000010#if defined(_MSC_VER)
Jamie Madilld7b1ab52016-12-12 14:42:19 -050011#pragma warning(disable : 4718)
apatrick@chromium.orge057c5d2012-01-26 19:18:24 +000012#endif
13
Geoff Lang17732822013-08-29 13:46:49 -040014#include "compiler/translator/SymbolTable.h"
Olli Etuaho01d0ad02017-01-22 14:51:23 -080015
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020016#include <algorithm>
17#include <set>
18
Olli Etuaho29bda812018-01-26 17:37:36 +020019#include "angle_gl.h"
Olli Etuaho2d8e4322018-01-22 14:12:46 +020020#include "compiler/translator/ImmutableString.h"
Olli Etuaho01d0ad02017-01-22 14:51:23 -080021#include "compiler/translator/IntermNode.h"
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020022#include "compiler/translator/StaticType.h"
kbr@chromium.org476541f2011-10-27 21:14:51 +000023
Jamie Madill45bcc782016-11-07 13:58:48 -050024namespace sh
25{
26
Olli Etuahodd21ecf2018-01-10 12:42:09 +020027class TSymbolTable::TSymbolTableLevel
28{
29 public:
30 TSymbolTableLevel() : mGlobalInvariant(false) {}
Olli Etuahodd21ecf2018-01-10 12:42:09 +020031
32 bool insert(TSymbol *symbol);
33
34 // Insert a function using its unmangled name as the key.
Olli Etuahob92f92a2018-02-15 19:14:59 +020035 void insertUnmangled(TFunction *function);
Olli Etuahodd21ecf2018-01-10 12:42:09 +020036
Olli Etuahofbb1c792018-01-19 16:26:59 +020037 TSymbol *find(const ImmutableString &name) const;
Olli Etuahodd21ecf2018-01-10 12:42:09 +020038
Olli Etuahodefe3932018-02-13 11:56:09 +020039 void addInvariantVarying(const ImmutableString &name) { mInvariantVaryings.insert(name); }
Olli Etuahodd21ecf2018-01-10 12:42:09 +020040
Olli Etuahodefe3932018-02-13 11:56:09 +020041 bool isVaryingInvariant(const ImmutableString &name)
Olli Etuahodd21ecf2018-01-10 12:42:09 +020042 {
43 return (mGlobalInvariant || mInvariantVaryings.count(name) > 0);
44 }
45
46 void setGlobalInvariant(bool invariant) { mGlobalInvariant = invariant; }
47
Olli Etuahodd21ecf2018-01-10 12:42:09 +020048 private:
Olli Etuahofbb1c792018-01-19 16:26:59 +020049 using tLevel = TUnorderedMap<ImmutableString,
50 TSymbol *,
51 ImmutableString::FowlerNollVoHash<sizeof(size_t)>>;
Olli Etuahodd21ecf2018-01-10 12:42:09 +020052 using tLevelPair = const tLevel::value_type;
53 using tInsertResult = std::pair<tLevel::iterator, bool>;
54
55 tLevel level;
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020056
Olli Etuahodefe3932018-02-13 11:56:09 +020057 std::set<ImmutableString> mInvariantVaryings;
Olli Etuahodd21ecf2018-01-10 12:42:09 +020058 bool mGlobalInvariant;
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020059};
60
61class TSymbolTable::TSymbolTableBuiltInLevel
62{
63 public:
64 TSymbolTableBuiltInLevel() = default;
65
Olli Etuaho065aa862018-02-22 15:30:27 +020066 void insert(const TSymbol *symbol);
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020067 const TSymbol *find(const ImmutableString &name) const;
68
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020069 private:
70 using tLevel = TUnorderedMap<ImmutableString,
71 const TSymbol *,
72 ImmutableString::FowlerNollVoHash<sizeof(size_t)>>;
73 using tLevelPair = const tLevel::value_type;
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020074 tLevel mLevel;
Olli Etuahodd21ecf2018-01-10 12:42:09 +020075};
76
Olli Etuahodd21ecf2018-01-10 12:42:09 +020077bool TSymbolTable::TSymbolTableLevel::insert(TSymbol *symbol)
Jamie Madillbfa91f42014-06-05 15:45:18 -040078{
Jamie Madillbfa91f42014-06-05 15:45:18 -040079 // returning true means symbol was added to the table
Nicolas Capensadfffe42014-06-17 02:13:36 -040080 tInsertResult result = level.insert(tLevelPair(symbol->getMangledName(), symbol));
Jamie Madillbfa91f42014-06-05 15:45:18 -040081 return result.second;
82}
83
Olli Etuahob92f92a2018-02-15 19:14:59 +020084void TSymbolTable::TSymbolTableLevel::insertUnmangled(TFunction *function)
Olli Etuahob2983c92015-03-18 14:02:46 +020085{
Olli Etuahob92f92a2018-02-15 19:14:59 +020086 level.insert(tLevelPair(function->name(), function));
Olli Etuahob2983c92015-03-18 14:02:46 +020087}
88
Olli Etuahofbb1c792018-01-19 16:26:59 +020089TSymbol *TSymbolTable::TSymbolTableLevel::find(const ImmutableString &name) const
Jamie Madillbfa91f42014-06-05 15:45:18 -040090{
91 tLevel::const_iterator it = level.find(name);
92 if (it == level.end())
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020093 return nullptr;
Jamie Madillbfa91f42014-06-05 15:45:18 -040094 else
95 return (*it).second;
96}
97
Olli Etuaho065aa862018-02-22 15:30:27 +020098void TSymbolTable::TSymbolTableBuiltInLevel::insert(const TSymbol *symbol)
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +020099{
Olli Etuaho065aa862018-02-22 15:30:27 +0200100 mLevel.insert(tLevelPair(symbol->getMangledName(), symbol));
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200101}
102
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200103const TSymbol *TSymbolTable::TSymbolTableBuiltInLevel::find(const ImmutableString &name) const
104{
105 tLevel::const_iterator it = mLevel.find(name);
106 if (it == mLevel.end())
107 return nullptr;
108 else
109 return (*it).second;
110}
111
Olli Etuaho065aa862018-02-22 15:30:27 +0200112TSymbolTable::TSymbolTable()
113 : mUniqueIdCounter(0), mUserDefinedUniqueIdsStart(-1), mShaderType(GL_FRAGMENT_SHADER)
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200114{
115}
116
117TSymbolTable::~TSymbolTable() = default;
118
Olli Etuaho437664b2018-02-28 15:38:14 +0200119bool TSymbolTable::isEmpty() const
120{
121 return mTable.empty();
122}
123
124bool TSymbolTable::atGlobalLevel() const
125{
126 return mTable.size() == 1u;
127}
128
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200129void TSymbolTable::pushBuiltInLevel()
130{
131 mBuiltInTable.push_back(
132 std::unique_ptr<TSymbolTableBuiltInLevel>(new TSymbolTableBuiltInLevel));
133}
134
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200135void TSymbolTable::push()
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000136{
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200137 mTable.push_back(std::unique_ptr<TSymbolTableLevel>(new TSymbolTableLevel));
138 mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel));
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200139}
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000140
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200141void TSymbolTable::pop()
142{
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200143 mTable.pop_back();
144 mPrecisionStack.pop_back();
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200145}
146
Olli Etuaho7c8567a2018-02-20 15:44:07 +0200147const TFunction *TSymbolTable::markFunctionHasPrototypeDeclaration(
Olli Etuahofbb1c792018-01-19 16:26:59 +0200148 const ImmutableString &mangledName,
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200149 bool *hadPrototypeDeclarationOut)
150{
151 TFunction *function = findUserDefinedFunction(mangledName);
152 *hadPrototypeDeclarationOut = function->hasPrototypeDeclaration();
153 function->setHasPrototypeDeclaration();
154 return function;
155}
156
Olli Etuaho7c8567a2018-02-20 15:44:07 +0200157const TFunction *TSymbolTable::setFunctionParameterNamesFromDefinition(const TFunction *function,
158 bool *wasDefinedOut)
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200159{
160 TFunction *firstDeclaration = findUserDefinedFunction(function->getMangledName());
161 ASSERT(firstDeclaration);
162 // Note: 'firstDeclaration' could be 'function' if this is the first time we've seen function as
163 // it would have just been put in the symbol table. Otherwise, we're looking up an earlier
164 // occurance.
165 if (function != firstDeclaration)
166 {
Olli Etuaho029e8ca2018-02-16 14:06:49 +0200167 // The previous declaration should have the same parameters as the function definition
168 // (parameter names may differ).
169 firstDeclaration->shareParameters(*function);
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200170 }
171
172 *wasDefinedOut = firstDeclaration->isDefined();
173 firstDeclaration->setDefined();
174 return firstDeclaration;
175}
176
Olli Etuahofbb1c792018-01-19 16:26:59 +0200177const TSymbol *TSymbolTable::find(const ImmutableString &name, int shaderVersion) const
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200178{
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200179 int userDefinedLevel = static_cast<int>(mTable.size()) - 1;
180 while (userDefinedLevel >= 0)
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000181 {
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200182 const TSymbol *symbol = mTable[userDefinedLevel]->find(name);
183 if (symbol)
184 {
185 return symbol;
186 }
187 userDefinedLevel--;
188 }
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000189
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200190 return findBuiltIn(name, shaderVersion, false);
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000191}
192
Olli Etuahofbb1c792018-01-19 16:26:59 +0200193TFunction *TSymbolTable::findUserDefinedFunction(const ImmutableString &name) const
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200194{
195 // User-defined functions are always declared at the global level.
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200196 ASSERT(!mTable.empty());
197 return static_cast<TFunction *>(mTable[0]->find(name));
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200198}
199
Olli Etuahofbb1c792018-01-19 16:26:59 +0200200const TSymbol *TSymbolTable::findGlobal(const ImmutableString &name) const
Zhenyao Mod7490962016-11-09 15:49:51 -0800201{
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200202 ASSERT(!mTable.empty());
203 return mTable[0]->find(name);
Zhenyao Mod7490962016-11-09 15:49:51 -0800204}
205
Olli Etuahofbb1c792018-01-19 16:26:59 +0200206const TSymbol *TSymbolTable::findBuiltIn(const ImmutableString &name, int shaderVersion) const
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000207{
Olli Etuaho977ee7e2017-07-21 11:38:27 +0300208 return findBuiltIn(name, shaderVersion, false);
209}
210
Olli Etuahofbb1c792018-01-19 16:26:59 +0200211const TSymbol *TSymbolTable::findBuiltIn(const ImmutableString &name,
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200212 int shaderVersion,
213 bool includeGLSLBuiltins) const
Olli Etuaho977ee7e2017-07-21 11:38:27 +0300214{
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000215 for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--)
216 {
Olli Etuaho977ee7e2017-07-21 11:38:27 +0300217 if (level == GLSL_BUILTINS && !includeGLSLBuiltins)
218 level--;
Martin Radeve93d24e2016-07-28 12:06:05 +0300219 if (level == ESSL3_1_BUILTINS && shaderVersion != 310)
220 level--;
221 if (level == ESSL3_BUILTINS && shaderVersion < 300)
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700222 level--;
223 if (level == ESSL1_BUILTINS && shaderVersion != 100)
224 level--;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000225
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200226 const TSymbol *symbol = mBuiltInTable[level]->find(name);
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000227
228 if (symbol)
229 return symbol;
230 }
231
Olli Etuaho977ee7e2017-07-21 11:38:27 +0300232 return nullptr;
shannonwoods@chromium.org96e7ba12013-05-30 00:02:41 +0000233}
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400234
Nicolas Capensf3cc4ae2015-02-23 13:51:25 -0500235
Olli Etuaho437664b2018-02-28 15:38:14 +0200236bool TSymbolTable::declare(TSymbol *symbol)
Olli Etuaho0f684632017-07-13 12:42:15 +0300237{
Olli Etuaho437664b2018-02-28 15:38:14 +0200238 ASSERT(!mTable.empty());
239 ASSERT(symbol->symbolType() == SymbolType::UserDefined);
240 ASSERT(!symbol->isFunction());
241 return mTable.back()->insert(symbol);
Jiawei Shaod8105a02017-08-08 09:54:36 +0800242}
243
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200244void TSymbolTable::declareUserDefinedFunction(TFunction *function, bool insertUnmangledName)
245{
Olli Etuaho437664b2018-02-28 15:38:14 +0200246 ASSERT(!mTable.empty());
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200247 if (insertUnmangledName)
248 {
249 // Insert the unmangled name to detect potential future redefinition as a variable.
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200250 mTable[0]->insertUnmangled(function);
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200251 }
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200252 mTable[0]->insert(function);
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200253}
254
Olli Etuaho437664b2018-02-28 15:38:14 +0200255void TSymbolTable::insertVariable(ESymbolLevel level,
256 const ImmutableString &name,
257 const TType *type)
Olli Etuaho0f684632017-07-13 12:42:15 +0300258{
Olli Etuahob60d30f2018-01-16 12:31:06 +0200259 ASSERT(type->isRealized());
Olli Etuaho437664b2018-02-28 15:38:14 +0200260 TVariable *var = new TVariable(this, name, type, SymbolType::BuiltIn);
261 insertBuiltIn(level, var);
Olli Etuaho0f684632017-07-13 12:42:15 +0300262}
263
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200264void TSymbolTable::insertVariableExt(ESymbolLevel level,
265 TExtension ext,
266 const ImmutableString &name,
267 const TType *type)
Olli Etuaho0f684632017-07-13 12:42:15 +0300268{
Olli Etuahob60d30f2018-01-16 12:31:06 +0200269 ASSERT(type->isRealized());
Olli Etuahofbb1c792018-01-19 16:26:59 +0200270 TVariable *var = new TVariable(this, name, type, SymbolType::BuiltIn, ext);
Olli Etuaho437664b2018-02-28 15:38:14 +0200271 insertBuiltIn(level, var);
Olli Etuaho0f684632017-07-13 12:42:15 +0300272}
273
Olli Etuaho437664b2018-02-28 15:38:14 +0200274void TSymbolTable::insertBuiltIn(ESymbolLevel level, const TSymbol *symbol)
Olli Etuaho195be942017-12-04 23:40:14 +0200275{
Olli Etuaho437664b2018-02-28 15:38:14 +0200276 ASSERT(symbol);
277 ASSERT(level <= LAST_BUILTIN_LEVEL);
Olli Etuaho195be942017-12-04 23:40:14 +0200278
Olli Etuaho437664b2018-02-28 15:38:14 +0200279 mBuiltInTable[level]->insert(symbol);
Olli Etuaho0f684632017-07-13 12:42:15 +0300280}
281
Olli Etuaho29bda812018-01-26 17:37:36 +0200282template <TPrecision precision>
Olli Etuaho437664b2018-02-28 15:38:14 +0200283void TSymbolTable::insertConstInt(ESymbolLevel level, const ImmutableString &name, int value)
Olli Etuaho29bda812018-01-26 17:37:36 +0200284{
285 TVariable *constant = new TVariable(
286 this, name, StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn);
287 TConstantUnion *unionArray = new TConstantUnion[1];
288 unionArray[0].setIConst(value);
289 constant->shareConstPointer(unionArray);
Olli Etuaho437664b2018-02-28 15:38:14 +0200290 insertBuiltIn(level, constant);
Olli Etuaho29bda812018-01-26 17:37:36 +0200291}
292
293template <TPrecision precision>
Olli Etuaho437664b2018-02-28 15:38:14 +0200294void TSymbolTable::insertConstIntExt(ESymbolLevel level,
Olli Etuaho29bda812018-01-26 17:37:36 +0200295 TExtension ext,
296 const ImmutableString &name,
297 int value)
298{
299 TVariable *constant = new TVariable(
300 this, name, StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn, ext);
301 TConstantUnion *unionArray = new TConstantUnion[1];
302 unionArray[0].setIConst(value);
303 constant->shareConstPointer(unionArray);
Olli Etuaho437664b2018-02-28 15:38:14 +0200304 insertBuiltIn(level, constant);
Olli Etuaho29bda812018-01-26 17:37:36 +0200305}
306
307template <TPrecision precision>
Olli Etuaho437664b2018-02-28 15:38:14 +0200308void TSymbolTable::insertConstIvec3(ESymbolLevel level,
Olli Etuaho29bda812018-01-26 17:37:36 +0200309 const ImmutableString &name,
310 const std::array<int, 3> &values)
311{
312 TVariable *constantIvec3 = new TVariable(
313 this, name, StaticType::Get<EbtInt, precision, EvqConst, 3, 1>(), SymbolType::BuiltIn);
314
315 TConstantUnion *unionArray = new TConstantUnion[3];
316 for (size_t index = 0u; index < 3u; ++index)
317 {
318 unionArray[index].setIConst(values[index]);
319 }
320 constantIvec3->shareConstPointer(unionArray);
321
Olli Etuaho437664b2018-02-28 15:38:14 +0200322 insertBuiltIn(level, constantIvec3);
Olli Etuaho29bda812018-01-26 17:37:36 +0200323}
324
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200325void TSymbolTable::setDefaultPrecision(TBasicType type, TPrecision prec)
326{
327 int indexOfLastElement = static_cast<int>(mPrecisionStack.size()) - 1;
328 // Uses map operator [], overwrites the current value
329 (*mPrecisionStack[indexOfLastElement])[type] = prec;
330}
331
Zhenyao Moe740add2014-07-18 17:01:01 -0700332TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700333{
334 if (!SupportsPrecision(type))
335 return EbpUndefined;
336
337 // unsigned integers use the same precision as signed
338 TBasicType baseType = (type == EbtUInt) ? EbtInt : type;
339
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200340 int level = static_cast<int>(mPrecisionStack.size()) - 1;
341 ASSERT(level >= 0); // Just to be safe. Should not happen.
Olli Etuaho183d7e22015-11-20 15:59:09 +0200342 // If we dont find anything we return this. Some types don't have predefined default precision.
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700343 TPrecision prec = EbpUndefined;
344 while (level >= 0)
345 {
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200346 PrecisionStackLevel::iterator it = mPrecisionStack[level]->find(baseType);
347 if (it != mPrecisionStack[level]->end())
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700348 {
349 prec = (*it).second;
350 break;
351 }
352 level--;
353 }
354 return prec;
355}
Jamie Madill45bcc782016-11-07 13:58:48 -0500356
Olli Etuahodefe3932018-02-13 11:56:09 +0200357void TSymbolTable::addInvariantVarying(const ImmutableString &originalName)
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200358{
359 ASSERT(atGlobalLevel());
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200360 mTable.back()->addInvariantVarying(originalName);
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200361}
362
Olli Etuahodefe3932018-02-13 11:56:09 +0200363bool TSymbolTable::isVaryingInvariant(const ImmutableString &originalName) const
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200364{
365 ASSERT(atGlobalLevel());
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200366 return mTable.back()->isVaryingInvariant(originalName);
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200367}
368
369void TSymbolTable::setGlobalInvariant(bool invariant)
370{
371 ASSERT(atGlobalLevel());
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200372 mTable.back()->setGlobalInvariant(invariant);
Olli Etuahodd21ecf2018-01-10 12:42:09 +0200373}
374
Olli Etuaho5d69db12017-11-24 16:51:15 +0200375void TSymbolTable::markBuiltInInitializationFinished()
376{
377 mUserDefinedUniqueIdsStart = mUniqueIdCounter;
378}
379
380void TSymbolTable::clearCompilationResults()
381{
382 mUniqueIdCounter = mUserDefinedUniqueIdsStart;
383
384 // User-defined scopes should have already been cleared when the compilation finished.
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200385 ASSERT(mTable.size() == 0u);
Olli Etuaho5d69db12017-11-24 16:51:15 +0200386}
387
388int TSymbolTable::nextUniqueIdValue()
389{
390 ASSERT(mUniqueIdCounter < std::numeric_limits<int>::max());
391 return ++mUniqueIdCounter;
392}
393
Olli Etuaho29bda812018-01-26 17:37:36 +0200394void TSymbolTable::initializeBuiltIns(sh::GLenum type,
395 ShShaderSpec spec,
396 const ShBuiltInResources &resources)
397{
Olli Etuaho065aa862018-02-22 15:30:27 +0200398 mShaderType = type;
399
Olli Etuaho29bda812018-01-26 17:37:36 +0200400 ASSERT(isEmpty());
Olli Etuahoe5fe7aa2018-01-29 12:06:11 +0200401 pushBuiltInLevel(); // COMMON_BUILTINS
402 pushBuiltInLevel(); // ESSL1_BUILTINS
403 pushBuiltInLevel(); // ESSL3_BUILTINS
404 pushBuiltInLevel(); // ESSL3_1_BUILTINS
405 pushBuiltInLevel(); // GLSL_BUILTINS
406
407 // We need just one precision stack level for predefined precisions.
408 mPrecisionStack.push_back(std::unique_ptr<PrecisionStackLevel>(new PrecisionStackLevel));
Olli Etuaho29bda812018-01-26 17:37:36 +0200409
410 switch (type)
411 {
412 case GL_FRAGMENT_SHADER:
413 setDefaultPrecision(EbtInt, EbpMedium);
414 break;
415 case GL_VERTEX_SHADER:
416 case GL_COMPUTE_SHADER:
417 case GL_GEOMETRY_SHADER_EXT:
418 setDefaultPrecision(EbtInt, EbpHigh);
419 setDefaultPrecision(EbtFloat, EbpHigh);
420 break;
421 default:
422 UNREACHABLE();
423 }
424 // Set defaults for sampler types that have default precision, even those that are
425 // only available if an extension exists.
426 // New sampler types in ESSL3 don't have default precision. ESSL1 types do.
427 initSamplerDefaultPrecision(EbtSampler2D);
428 initSamplerDefaultPrecision(EbtSamplerCube);
429 // SamplerExternalOES is specified in the extension to have default precision.
430 initSamplerDefaultPrecision(EbtSamplerExternalOES);
431 // SamplerExternal2DY2YEXT is specified in the extension to have default precision.
432 initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT);
433 // It isn't specified whether Sampler2DRect has default precision.
434 initSamplerDefaultPrecision(EbtSampler2DRect);
435
436 setDefaultPrecision(EbtAtomicCounter, EbpHigh);
437
Olli Etuaho140152e2018-02-08 14:46:44 +0200438 insertBuiltInFunctions(type);
Olli Etuaho140152e2018-02-08 14:46:44 +0200439 mUniqueIdCounter = kLastStaticBuiltInId + 1;
440
Olli Etuaho29bda812018-01-26 17:37:36 +0200441 initializeBuiltInVariables(type, spec, resources);
442 markBuiltInInitializationFinished();
443}
444
445void TSymbolTable::initSamplerDefaultPrecision(TBasicType samplerType)
446{
447 ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
448 setDefaultPrecision(samplerType, EbpLow);
449}
450
Olli Etuaho29bda812018-01-26 17:37:36 +0200451
452void TSymbolTable::initializeBuiltInVariables(sh::GLenum type,
453 ShShaderSpec spec,
454 const ShBuiltInResources &resources)
455{
456 const TSourceLoc zeroSourceLoc = {0, 0, 0, 0};
457
458 //
459 // Depth range in window coordinates
460 //
461 TFieldList *fields = new TFieldList();
462 auto highpFloat1 = new TType(EbtFloat, EbpHigh, EvqGlobal, 1);
463 TField *near = new TField(highpFloat1, ImmutableString("near"), zeroSourceLoc);
464 TField *far = new TField(highpFloat1, ImmutableString("far"), zeroSourceLoc);
465 TField *diff = new TField(highpFloat1, ImmutableString("diff"), zeroSourceLoc);
466 fields->push_back(near);
467 fields->push_back(far);
468 fields->push_back(diff);
469 TStructure *depthRangeStruct = new TStructure(this, ImmutableString("gl_DepthRangeParameters"),
470 fields, SymbolType::BuiltIn);
Olli Etuaho437664b2018-02-28 15:38:14 +0200471 insertBuiltIn(COMMON_BUILTINS, depthRangeStruct);
Olli Etuaho29bda812018-01-26 17:37:36 +0200472 TType *depthRangeType = new TType(depthRangeStruct);
473 depthRangeType->setQualifier(EvqUniform);
474 depthRangeType->realize();
475 insertVariable(COMMON_BUILTINS, ImmutableString("gl_DepthRange"), depthRangeType);
476
477 //
478 // Implementation dependent built-in constants.
479 //
480 insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexAttribs"),
481 resources.MaxVertexAttribs);
482 insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexUniformVectors"),
483 resources.MaxVertexUniformVectors);
484 insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxVertexTextureImageUnits"),
485 resources.MaxVertexTextureImageUnits);
486 insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxCombinedTextureImageUnits"),
487 resources.MaxCombinedTextureImageUnits);
488 insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxTextureImageUnits"),
489 resources.MaxTextureImageUnits);
490 insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxFragmentUniformVectors"),
491 resources.MaxFragmentUniformVectors);
492
493 insertConstInt<EbpMedium>(ESSL1_BUILTINS, ImmutableString("gl_MaxVaryingVectors"),
494 resources.MaxVaryingVectors);
495
496 insertConstInt<EbpMedium>(COMMON_BUILTINS, ImmutableString("gl_MaxDrawBuffers"),
497 resources.MaxDrawBuffers);
Olli Etuaho7c8567a2018-02-20 15:44:07 +0200498 insertConstIntExt<EbpMedium>(COMMON_BUILTINS, TExtension::EXT_blend_func_extended,
499 ImmutableString("gl_MaxDualSourceDrawBuffersEXT"),
500 resources.MaxDualSourceDrawBuffers);
Olli Etuaho29bda812018-01-26 17:37:36 +0200501
502 insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxVertexOutputVectors"),
503 resources.MaxVertexOutputVectors);
504 insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxFragmentInputVectors"),
505 resources.MaxFragmentInputVectors);
506 insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MinProgramTexelOffset"),
507 resources.MinProgramTexelOffset);
508 insertConstInt<EbpMedium>(ESSL3_BUILTINS, ImmutableString("gl_MaxProgramTexelOffset"),
509 resources.MaxProgramTexelOffset);
510
511 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxImageUnits"),
512 resources.MaxImageUnits);
513 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexImageUniforms"),
514 resources.MaxVertexImageUniforms);
515 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxFragmentImageUniforms"),
516 resources.MaxFragmentImageUniforms);
517 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeImageUniforms"),
518 resources.MaxComputeImageUniforms);
519 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxCombinedImageUniforms"),
520 resources.MaxCombinedImageUniforms);
521
522 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS,
523 ImmutableString("gl_MaxCombinedShaderOutputResources"),
524 resources.MaxCombinedShaderOutputResources);
525
526 insertConstIvec3<EbpHigh>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeWorkGroupCount"),
527 resources.MaxComputeWorkGroupCount);
528 insertConstIvec3<EbpHigh>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeWorkGroupSize"),
529 resources.MaxComputeWorkGroupSize);
530 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeUniformComponents"),
531 resources.MaxComputeUniformComponents);
532 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeTextureImageUnits"),
533 resources.MaxComputeTextureImageUnits);
534
535 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxComputeAtomicCounters"),
536 resources.MaxComputeAtomicCounters);
537 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS,
538 ImmutableString("gl_MaxComputeAtomicCounterBuffers"),
539 resources.MaxComputeAtomicCounterBuffers);
540
541 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexAtomicCounters"),
542 resources.MaxVertexAtomicCounters);
543 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxFragmentAtomicCounters"),
544 resources.MaxFragmentAtomicCounters);
545 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxCombinedAtomicCounters"),
546 resources.MaxCombinedAtomicCounters);
547 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxAtomicCounterBindings"),
548 resources.MaxAtomicCounterBindings);
549
550 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxVertexAtomicCounterBuffers"),
551 resources.MaxVertexAtomicCounterBuffers);
552 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS,
553 ImmutableString("gl_MaxFragmentAtomicCounterBuffers"),
554 resources.MaxFragmentAtomicCounterBuffers);
555 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS,
556 ImmutableString("gl_MaxCombinedAtomicCounterBuffers"),
557 resources.MaxCombinedAtomicCounterBuffers);
558 insertConstInt<EbpMedium>(ESSL3_1_BUILTINS, ImmutableString("gl_MaxAtomicCounterBufferSize"),
559 resources.MaxAtomicCounterBufferSize);
560
Olli Etuaho29bda812018-01-26 17:37:36 +0200561 {
562 TExtension ext = TExtension::EXT_geometry_shader;
563 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
564 ImmutableString("gl_MaxGeometryInputComponents"),
565 resources.MaxGeometryInputComponents);
566 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
567 ImmutableString("gl_MaxGeometryOutputComponents"),
568 resources.MaxGeometryOutputComponents);
569 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
570 ImmutableString("gl_MaxGeometryImageUniforms"),
571 resources.MaxGeometryImageUniforms);
572 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
573 ImmutableString("gl_MaxGeometryTextureImageUnits"),
574 resources.MaxGeometryTextureImageUnits);
575 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
576 ImmutableString("gl_MaxGeometryOutputVertices"),
577 resources.MaxGeometryOutputVertices);
578 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
579 ImmutableString("gl_MaxGeometryTotalOutputComponents"),
580 resources.MaxGeometryTotalOutputComponents);
581 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
582 ImmutableString("gl_MaxGeometryUniformComponents"),
583 resources.MaxGeometryUniformComponents);
584 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
585 ImmutableString("gl_MaxGeometryAtomicCounters"),
586 resources.MaxGeometryAtomicCounters);
587 insertConstIntExt<EbpMedium>(ESSL3_1_BUILTINS, ext,
588 ImmutableString("gl_MaxGeometryAtomicCounterBuffers"),
589 resources.MaxGeometryAtomicCounterBuffers);
590 }
591
592 //
593 // Insert some special built-in variables that are not in
594 // the built-in header files.
595 //
596
597 if (resources.OVR_multiview && type != GL_COMPUTE_SHADER)
598 {
599 const TType *viewIDType = StaticType::Get<EbtUInt, EbpHigh, EvqViewIDOVR, 1, 1>();
600 insertVariableExt(ESSL3_BUILTINS, TExtension::OVR_multiview,
601 ImmutableString("gl_ViewID_OVR"), viewIDType);
602
603 // ESSL 1.00 doesn't have unsigned integers, so gl_ViewID_OVR is a signed integer in ESSL
604 // 1.00. This is specified in the WEBGL_multiview spec.
605 const TType *viewIDIntType = StaticType::Get<EbtInt, EbpHigh, EvqViewIDOVR, 1, 1>();
606 insertVariableExt(ESSL1_BUILTINS, TExtension::OVR_multiview,
607 ImmutableString("gl_ViewID_OVR"), viewIDIntType);
608 }
609
610 const TType *positionType = StaticType::Get<EbtFloat, EbpHigh, EvqPosition, 4, 1>();
611 const TType *primitiveIDType = StaticType::Get<EbtInt, EbpHigh, EvqPrimitiveID, 1, 1>();
612 const TType *layerType = StaticType::Get<EbtInt, EbpHigh, EvqLayer, 1, 1>();
613
614 switch (type)
615 {
616 case GL_FRAGMENT_SHADER:
617 {
618 const TType *fragCoordType = StaticType::Get<EbtFloat, EbpMedium, EvqFragCoord, 4, 1>();
619 insertVariable(COMMON_BUILTINS, ImmutableString("gl_FragCoord"), fragCoordType);
620 const TType *frontFacingType = StaticType::GetQualified<EbtBool, EvqFrontFacing>();
621 insertVariable(COMMON_BUILTINS, ImmutableString("gl_FrontFacing"), frontFacingType);
622 const TType *pointCoordType =
623 StaticType::Get<EbtFloat, EbpMedium, EvqPointCoord, 2, 1>();
624 insertVariable(COMMON_BUILTINS, ImmutableString("gl_PointCoord"), pointCoordType);
625
626 const TType *fragColorType = StaticType::Get<EbtFloat, EbpMedium, EvqFragColor, 4, 1>();
627 insertVariable(ESSL1_BUILTINS, ImmutableString("gl_FragColor"), fragColorType);
628
629 TType *fragDataType = new TType(EbtFloat, EbpMedium, EvqFragData, 4);
630 if (spec != SH_WEBGL2_SPEC && spec != SH_WEBGL3_SPEC)
631 {
632 fragDataType->makeArray(resources.MaxDrawBuffers);
633 }
634 else
635 {
636 fragDataType->makeArray(1u);
637 }
638 fragDataType->realize();
639 insertVariable(ESSL1_BUILTINS, ImmutableString("gl_FragData"), fragDataType);
640
641 if (resources.EXT_blend_func_extended)
642 {
643 const TType *secondaryFragColorType =
644 StaticType::Get<EbtFloat, EbpMedium, EvqSecondaryFragColorEXT, 4, 1>();
645 insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_blend_func_extended,
646 ImmutableString("gl_SecondaryFragColorEXT"),
647 secondaryFragColorType);
648 TType *secondaryFragDataType =
649 new TType(EbtFloat, EbpMedium, EvqSecondaryFragDataEXT, 4, 1);
650 secondaryFragDataType->makeArray(resources.MaxDualSourceDrawBuffers);
651 secondaryFragDataType->realize();
652 insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_blend_func_extended,
653 ImmutableString("gl_SecondaryFragDataEXT"),
654 secondaryFragDataType);
655 }
656
657 if (resources.EXT_frag_depth)
658 {
659 TType *fragDepthEXTType =
660 new TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium,
661 EvqFragDepthEXT, 1);
662 fragDepthEXTType->realize();
663 insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_frag_depth,
664 ImmutableString("gl_FragDepthEXT"), fragDepthEXTType);
665 }
666
667 const TType *fragDepthType = StaticType::Get<EbtFloat, EbpHigh, EvqFragDepth, 1, 1>();
668 insertVariable(ESSL3_BUILTINS, ImmutableString("gl_FragDepth"), fragDepthType);
669
670 const TType *lastFragColorType =
671 StaticType::Get<EbtFloat, EbpMedium, EvqLastFragColor, 4, 1>();
672
673 if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch)
674 {
675 TType *lastFragDataType = new TType(EbtFloat, EbpMedium, EvqLastFragData, 4, 1);
676 lastFragDataType->makeArray(resources.MaxDrawBuffers);
677 lastFragDataType->realize();
678
679 if (resources.EXT_shader_framebuffer_fetch)
680 {
681 insertVariableExt(ESSL1_BUILTINS, TExtension::EXT_shader_framebuffer_fetch,
682 ImmutableString("gl_LastFragData"), lastFragDataType);
683 }
684 else if (resources.NV_shader_framebuffer_fetch)
685 {
686 insertVariableExt(ESSL1_BUILTINS, TExtension::NV_shader_framebuffer_fetch,
687 ImmutableString("gl_LastFragColor"), lastFragColorType);
688 insertVariableExt(ESSL1_BUILTINS, TExtension::NV_shader_framebuffer_fetch,
689 ImmutableString("gl_LastFragData"), lastFragDataType);
690 }
691 }
692 else if (resources.ARM_shader_framebuffer_fetch)
693 {
694 insertVariableExt(ESSL1_BUILTINS, TExtension::ARM_shader_framebuffer_fetch,
695 ImmutableString("gl_LastFragColorARM"), lastFragColorType);
696 }
697
698 if (resources.EXT_geometry_shader)
699 {
700 TExtension extension = TExtension::EXT_geometry_shader;
701 insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveID"),
702 primitiveIDType);
703 insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Layer"),
704 layerType);
705 }
706
707 break;
708 }
709 case GL_VERTEX_SHADER:
710 {
711 insertVariable(COMMON_BUILTINS, ImmutableString("gl_Position"), positionType);
712 const TType *pointSizeType = StaticType::Get<EbtFloat, EbpMedium, EvqPointSize, 1, 1>();
713 insertVariable(COMMON_BUILTINS, ImmutableString("gl_PointSize"), pointSizeType);
714 const TType *instanceIDType = StaticType::Get<EbtInt, EbpHigh, EvqInstanceID, 1, 1>();
715 insertVariable(ESSL3_BUILTINS, ImmutableString("gl_InstanceID"), instanceIDType);
716 const TType *vertexIDType = StaticType::Get<EbtInt, EbpHigh, EvqVertexID, 1, 1>();
717 insertVariable(ESSL3_BUILTINS, ImmutableString("gl_VertexID"), vertexIDType);
718
719 // For internal use by ANGLE - not exposed to the parser.
720 const TType *viewportIndexType =
721 StaticType::Get<EbtInt, EbpHigh, EvqViewportIndex, 1, 1>();
722 insertVariable(GLSL_BUILTINS, ImmutableString("gl_ViewportIndex"), viewportIndexType);
723 // gl_Layer exists in other shader stages in ESSL, but not in vertex shader so far.
724 insertVariable(GLSL_BUILTINS, ImmutableString("gl_Layer"), layerType);
725 break;
726 }
727 case GL_COMPUTE_SHADER:
728 {
729 const TType *numWorkGroupsType =
730 StaticType::Get<EbtUInt, EbpUndefined, EvqNumWorkGroups, 3, 1>();
731 insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_NumWorkGroups"),
732 numWorkGroupsType);
733 const TType *workGroupSizeType =
734 StaticType::Get<EbtUInt, EbpUndefined, EvqWorkGroupSize, 3, 1>();
735 insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_WorkGroupSize"),
736 workGroupSizeType);
737 const TType *workGroupIDType =
738 StaticType::Get<EbtUInt, EbpUndefined, EvqWorkGroupID, 3, 1>();
739 insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_WorkGroupID"), workGroupIDType);
740 const TType *localInvocationIDType =
741 StaticType::Get<EbtUInt, EbpUndefined, EvqLocalInvocationID, 3, 1>();
742 insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_LocalInvocationID"),
743 localInvocationIDType);
744 const TType *globalInvocationIDType =
745 StaticType::Get<EbtUInt, EbpUndefined, EvqGlobalInvocationID, 3, 1>();
746 insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_GlobalInvocationID"),
747 globalInvocationIDType);
748 const TType *localInvocationIndexType =
749 StaticType::Get<EbtUInt, EbpUndefined, EvqLocalInvocationIndex, 1, 1>();
750 insertVariable(ESSL3_1_BUILTINS, ImmutableString("gl_LocalInvocationIndex"),
751 localInvocationIndexType);
752 break;
753 }
754
755 case GL_GEOMETRY_SHADER_EXT:
756 {
757 TExtension extension = TExtension::EXT_geometry_shader;
758
759 // Add built-in interface block gl_PerVertex and the built-in array gl_in.
760 // TODO(jiawei.shao@intel.com): implement GL_EXT_geometry_point_size.
761 TFieldList *glPerVertexFieldList = new TFieldList();
762 TField *glPositionField =
763 new TField(new TType(*positionType), ImmutableString("gl_Position"), zeroSourceLoc);
764 glPerVertexFieldList->push_back(glPositionField);
765
766 const ImmutableString glPerVertexString("gl_PerVertex");
767 TInterfaceBlock *glPerVertexInBlock =
768 new TInterfaceBlock(this, glPerVertexString, glPerVertexFieldList,
769 TLayoutQualifier::Create(), SymbolType::BuiltIn, extension);
Olli Etuaho437664b2018-02-28 15:38:14 +0200770 insertBuiltIn(ESSL3_1_BUILTINS, glPerVertexInBlock);
Olli Etuaho29bda812018-01-26 17:37:36 +0200771
772 // The array size of gl_in is undefined until we get a valid input primitive
773 // declaration.
774 TType *glInType =
775 new TType(glPerVertexInBlock, EvqPerVertexIn, TLayoutQualifier::Create());
776 glInType->makeArray(0u);
777 glInType->realize();
778 insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_in"), glInType);
779
780 TInterfaceBlock *glPerVertexOutBlock =
781 new TInterfaceBlock(this, glPerVertexString, glPerVertexFieldList,
782 TLayoutQualifier::Create(), SymbolType::BuiltIn);
783 TType *glPositionInBlockType = new TType(EbtFloat, EbpHigh, EvqPosition, 4);
784 glPositionInBlockType->setInterfaceBlock(glPerVertexOutBlock);
785 glPositionInBlockType->realize();
786 insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Position"),
787 glPositionInBlockType);
788
789 const TType *primitiveIDInType =
790 StaticType::Get<EbtInt, EbpHigh, EvqPrimitiveIDIn, 1, 1>();
791 insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveIDIn"),
792 primitiveIDInType);
793 const TType *invocationIDType =
794 StaticType::Get<EbtInt, EbpHigh, EvqInvocationID, 1, 1>();
795 insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_InvocationID"),
796 invocationIDType);
797 insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_PrimitiveID"),
798 primitiveIDType);
799 insertVariableExt(ESSL3_1_BUILTINS, extension, ImmutableString("gl_Layer"), layerType);
800
801 break;
802 }
803 default:
804 UNREACHABLE();
805 }
806}
807
Jamie Madill45bcc782016-11-07 13:58:48 -0500808} // namespace sh