blob: 8b7cb0e35bc0fa23573d208fda9858588fc95826 [file] [log] [blame]
alokp@chromium.org07620a52010-09-23 17:53:56 +00001//
Jamie Madill88f6e942014-02-19 10:27:53 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
alokp@chromium.org07620a52010-09-23 17:53:56 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Corentin Wallez8b28a8b2016-09-15 19:47:56 -04007#include "compiler/translator/Compiler.h"
8
9#include <sstream>
10
11#include "angle_gl.h"
12#include "common/utilities.h"
Qiankun Miao09cfac62016-09-06 17:25:16 +080013#include "compiler/translator/AddAndTrueToLoopCondition.h"
Dmitry Skiba01971112015-07-10 14:54:00 -040014#include "compiler/translator/Cache.h"
Corentin Wallez71d147f2015-02-11 11:15:24 -080015#include "compiler/translator/CallDAG.h"
Olli Etuahoab918822017-07-14 17:03:42 +030016#include "compiler/translator/ClampPointSize.h"
Martin Radev69056a12017-05-18 11:14:50 +030017#include "compiler/translator/DeclareAndInitBuiltinsForInstancedMultiview.h"
Olli Etuaho3d932d82016-04-12 11:10:30 +030018#include "compiler/translator/DeferGlobalInitializers.h"
Zhenyao Mo4e94fea2016-08-09 14:31:37 -070019#include "compiler/translator/EmulateGLFragColorBroadcast.h"
Jamie Madilld5696192016-10-06 11:09:24 -040020#include "compiler/translator/EmulatePrecision.h"
Geoff Lang17732822013-08-29 13:46:49 -040021#include "compiler/translator/Initialize.h"
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080022#include "compiler/translator/InitializeVariables.h"
Olli Etuaho9733cee2017-05-11 19:14:35 +030023#include "compiler/translator/IntermNodePatternMatcher.h"
Olli Etuahocccf2b02017-07-05 14:50:54 +030024#include "compiler/translator/IsASTDepthBelowLimit.h"
25#include "compiler/translator/OutputTree.h"
Jamie Madill6b9cb252013-10-17 10:45:47 -040026#include "compiler/translator/ParseContext.h"
Olli Etuahoc6833112015-04-22 15:15:54 +030027#include "compiler/translator/PruneEmptyDeclarations.h"
Zhenyao Moe740add2014-07-18 17:01:01 -070028#include "compiler/translator/RegenerateStructNames.h"
Qiankun Miao705a9192016-08-29 10:05:27 +080029#include "compiler/translator/RemoveInvariantDeclaration.h"
Olli Etuaho5c407bb2015-06-01 12:20:39 +030030#include "compiler/translator/RemovePow.h"
Corentin Wallezd4b50542015-09-28 12:19:26 -070031#include "compiler/translator/RewriteDoWhile.h"
Zhenyao Mocd68fe72014-07-11 10:45:44 -070032#include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h"
Olli Etuaho9733cee2017-05-11 19:14:35 +030033#include "compiler/translator/SeparateDeclarations.h"
34#include "compiler/translator/SimplifyLoopConditions.h"
Zhenyao Mo7cab38b2013-10-15 12:59:30 -070035#include "compiler/translator/UnfoldShortCircuitAST.h"
Qin Jiajia7835b522016-10-08 11:20:17 +080036#include "compiler/translator/UseInterfaceBlockFields.h"
Geoff Lang17732822013-08-29 13:46:49 -040037#include "compiler/translator/ValidateLimitations.h"
Olli Etuaho19d1dc92016-03-08 17:18:46 +020038#include "compiler/translator/ValidateMaxParameters.h"
Olli Etuaho09b04a22016-12-15 13:30:26 +000039#include "compiler/translator/ValidateMultiviewWebGL.h"
Geoff Lang17732822013-08-29 13:46:49 -040040#include "compiler/translator/ValidateOutputs.h"
41#include "compiler/translator/VariablePacker.h"
shannon.woods@transgaming.comda1ed362013-01-25 21:54:57 +000042#include "third_party/compiler/ArrayBoundsClamper.h"
Corentin Wallez28b65282016-06-16 07:24:50 -070043
Jamie Madillacb4b812016-11-07 13:50:29 -050044namespace sh
45{
46
Corentin Wallez28b65282016-06-16 07:24:50 -070047namespace
48{
49
50#if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
51void DumpFuzzerCase(char const *const *shaderStrings,
52 size_t numStrings,
53 uint32_t type,
54 uint32_t spec,
55 uint32_t output,
56 uint64_t options)
57{
58 static int fileIndex = 0;
59
60 std::ostringstream o;
61 o << "corpus/" << fileIndex++ << ".sample";
62 std::string s = o.str();
63
64 // Must match the input format of the fuzzer
65 FILE *f = fopen(s.c_str(), "w");
66 fwrite(&type, sizeof(type), 1, f);
67 fwrite(&spec, sizeof(spec), 1, f);
68 fwrite(&output, sizeof(output), 1, f);
69 fwrite(&options, sizeof(options), 1, f);
70
71 char zero[128 - 20] = {0};
72 fwrite(&zero, 128 - 20, 1, f);
73
74 for (size_t i = 0; i < numStrings; i++)
75 {
76 fwrite(shaderStrings[i], sizeof(char), strlen(shaderStrings[i]), f);
77 }
78 fwrite(&zero, 1, 1, f);
79
80 fclose(f);
81}
82#endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
83} // anonymous namespace
84
Jamie Madill5508f392014-02-20 13:31:36 -050085bool IsWebGLBasedSpec(ShShaderSpec spec)
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000086{
Qiankun Miaoc2c5fc42016-08-31 15:24:22 +080087 return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000088}
89
Qingqing Dengad0d0792015-04-08 14:25:06 -070090bool IsGLSL130OrNewer(ShShaderOutput output)
91{
Jamie Madillacb4b812016-11-07 13:50:29 -050092 return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT ||
93 output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT ||
94 output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT ||
95 output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT ||
96 output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT);
Qingqing Dengad0d0792015-04-08 14:25:06 -070097}
98
Qiankun Miao705a9192016-08-29 10:05:27 +080099bool IsGLSL420OrNewer(ShShaderOutput output)
100{
Jamie Madillacb4b812016-11-07 13:50:29 -0500101 return (output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT ||
102 output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT);
Qiankun Miao705a9192016-08-29 10:05:27 +0800103}
104
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800105bool IsGLSL410OrOlder(ShShaderOutput output)
106{
107 return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT ||
108 output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT ||
109 output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT);
110}
111
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000112bool RemoveInvariant(sh::GLenum shaderType,
113 int shaderVersion,
114 ShShaderOutput outputType,
115 ShCompileOptions compileOptions)
116{
117 if ((compileOptions & SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT) == 0 &&
118 shaderType == GL_FRAGMENT_SHADER && IsGLSL420OrNewer(outputType))
119 return true;
120
121 if ((compileOptions & SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3) != 0 &&
Qiankun Miao41f9f672016-11-16 17:04:36 +0800122 shaderVersion >= 300 && shaderType == GL_VERTEX_SHADER)
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000123 return true;
124
125 return false;
126}
127
Zhenyao Mo7faf1a12014-04-25 18:03:56 -0700128size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
Jamie Madill88f6e942014-02-19 10:27:53 -0500129{
He Yunchao29ab9ff2015-08-06 16:58:30 +0800130 // WebGL defines a max token length of 256, while ES2 leaves max token
Jamie Madill88f6e942014-02-19 10:27:53 -0500131 // size undefined. ES3 defines a max size of 1024 characters.
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700132 switch (spec)
Jamie Madill88f6e942014-02-19 10:27:53 -0500133 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500134 case SH_WEBGL_SPEC:
135 return 256;
136 default:
137 return 1024;
Jamie Madill88f6e942014-02-19 10:27:53 -0500138 }
139}
140
Shao77891c02017-06-23 16:30:17 +0800141int GetMaxUniformVectorsForShaderType(GLenum shaderType, const ShBuiltInResources &resources)
142{
143 switch (shaderType)
144 {
145 case GL_VERTEX_SHADER:
146 return resources.MaxVertexUniformVectors;
147 case GL_FRAGMENT_SHADER:
148 return resources.MaxFragmentUniformVectors;
Shaob5cc1192017-07-06 10:47:20 +0800149
150 // TODO (jiawei.shao@intel.com): check if we need finer-grained component counting
Shao77891c02017-06-23 16:30:17 +0800151 case GL_COMPUTE_SHADER:
Shao77891c02017-06-23 16:30:17 +0800152 return resources.MaxComputeUniformComponents / 4;
Shaob5cc1192017-07-06 10:47:20 +0800153 case GL_GEOMETRY_SHADER_OES:
154 return resources.MaxGeometryUniformComponents / 4;
Shao77891c02017-06-23 16:30:17 +0800155 default:
Shaob5cc1192017-07-06 10:47:20 +0800156 UNREACHABLE();
Shao77891c02017-06-23 16:30:17 +0800157 return -1;
158 }
159}
160
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500161namespace
162{
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700163
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800164class TScopedPoolAllocator
165{
166 public:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500167 TScopedPoolAllocator(TPoolAllocator *allocator) : mAllocator(allocator)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800168 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400169 mAllocator->push();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000170 SetGlobalPoolAllocator(mAllocator);
171 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800172 ~TScopedPoolAllocator()
173 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800174 SetGlobalPoolAllocator(nullptr);
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400175 mAllocator->pop();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000176 }
177
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800178 private:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500179 TPoolAllocator *mAllocator;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400180};
181
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800182class TScopedSymbolTableLevel
183{
184 public:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500185 TScopedSymbolTableLevel(TSymbolTable *table) : mTable(table)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800186 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400187 ASSERT(mTable->atBuiltInLevel());
188 mTable->push();
189 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800190 ~TScopedSymbolTableLevel()
191 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400192 while (!mTable->atBuiltInLevel())
193 mTable->pop();
194 }
195
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800196 private:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500197 TSymbolTable *mTable;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000198};
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700199
200int MapSpecToShaderVersion(ShShaderSpec spec)
201{
202 switch (spec)
203 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500204 case SH_GLES2_SPEC:
205 case SH_WEBGL_SPEC:
206 return 100;
207 case SH_GLES3_SPEC:
208 case SH_WEBGL2_SPEC:
209 return 300;
210 case SH_GLES3_1_SPEC:
211 case SH_WEBGL3_SPEC:
212 return 310;
213 default:
214 UNREACHABLE();
215 return 0;
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700216 }
217}
218
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000219} // namespace
220
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800221TShHandleBase::TShHandleBase()
222{
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000223 allocator.push();
224 SetGlobalPoolAllocator(&allocator);
225}
226
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800227TShHandleBase::~TShHandleBase()
228{
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800229 SetGlobalPoolAllocator(nullptr);
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000230 allocator.popAll();
231}
232
Jamie Madill183bde52014-07-02 15:31:19 -0400233TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700234 : variablesCollected(false),
Olli Etuahob12040c2017-06-27 14:20:45 +0300235 mGLPositionInitialized(false),
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700236 shaderType(type),
zmo@google.comf420c422011-09-12 18:27:59 +0000237 shaderSpec(spec),
Jamie Madill68fe74a2014-05-27 12:56:01 -0400238 outputType(output),
Jamie Madilleb1a0102013-07-08 13:31:38 -0400239 maxUniformVectors(0),
240 maxExpressionComplexity(0),
241 maxCallStackDepth(0),
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200242 maxFunctionParameters(0),
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000243 fragmentPrecisionHigh(false),
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000244 clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC),
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200245 builtInFunctionEmulator(),
Olli Etuaho77ba4082016-12-16 12:01:18 +0000246 mDiagnostics(infoSink.info),
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800247 mSourcePath(nullptr),
Shaob5cc1192017-07-06 10:47:20 +0800248 mComputeShaderLocalSizeDeclared(false),
249 mGeometryShaderMaxVertices(-1),
250 mGeometryShaderInvocations(0),
251 mGeometryShaderInputPrimitiveType(EptUndefined),
252 mGeometryShaderOutputPrimitiveType(EptUndefined)
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000253{
Martin Radev802abe02016-08-04 17:48:32 +0300254 mComputeShaderLocalSize.fill(1);
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000255}
256
257TCompiler::~TCompiler()
258{
259}
260
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800261bool TCompiler::shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptions) const
Olli Etuaho5d91dda2015-06-18 15:47:46 +0300262{
263 // If compiling an ESSL 1.00 shader for WebGL, or if its been requested through the API,
264 // validate loop and indexing as well (to verify that the shader only uses minimal functionality
265 // of ESSL 1.00 as in Appendix A of the spec).
266 return (IsWebGLBasedSpec(shaderSpec) && shaderVersion == 100) ||
267 (compileOptions & SH_VALIDATE_LOOP_INDEXING);
268}
269
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500270bool TCompiler::Init(const ShBuiltInResources &resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000271{
Shao77891c02017-06-23 16:30:17 +0800272 shaderVersion = 100;
273
274 maxUniformVectors = GetMaxUniformVectorsForShaderType(shaderType, resources);
275
Jamie Madilleb1a0102013-07-08 13:31:38 -0400276 maxExpressionComplexity = resources.MaxExpressionComplexity;
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200277 maxCallStackDepth = resources.MaxCallStackDepth;
278 maxFunctionParameters = resources.MaxFunctionParameters;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400279
280 SetGlobalPoolAllocator(&allocator);
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000281
alokp@chromium.org07620a52010-09-23 17:53:56 +0000282 // Generate built-in symbol table.
283 if (!InitBuiltInSymbolTable(resources))
284 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000285 InitExtensionBehavior(resources, extensionBehavior);
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000286 fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000287
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000288 arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy);
289 clampingStrategy = resources.ArrayIndexClampingStrategy;
290
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000291 hashFunction = resources.HashFunction;
292
alokp@chromium.org07620a52010-09-23 17:53:56 +0000293 return true;
294}
295
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100296TIntermBlock *TCompiler::compileTreeForTesting(const char *const shaderStrings[],
297 size_t numStrings,
298 ShCompileOptions compileOptions)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000299{
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200300 return compileTreeImpl(shaderStrings, numStrings, compileOptions);
301}
302
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100303TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
304 size_t numStrings,
305 const ShCompileOptions compileOptions)
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200306{
alokp@chromium.org07620a52010-09-23 17:53:56 +0000307 clearResults();
308
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200309 ASSERT(numStrings > 0);
310 ASSERT(GetGlobalPoolAllocator());
alokp@chromium.org07620a52010-09-23 17:53:56 +0000311
David Yen0fbd1282015-02-02 14:46:09 -0800312 // Reset the extension behavior for each compilation unit.
313 ResetExtensionBehavior(extensionBehavior);
314
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000315 // First string is path of source file if flag is set. The actual source follows.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000316 size_t firstSource = 0;
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000317 if (compileOptions & SH_SOURCE_PATH)
318 {
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200319 mSourcePath = shaderStrings[0];
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000320 ++firstSource;
321 }
322
Olli Etuahof119a262016-08-19 15:54:22 +0300323 TParseContext parseContext(symbolTable, extensionBehavior, shaderType, shaderSpec,
Olli Etuaho77ba4082016-12-16 12:01:18 +0000324 compileOptions, true, &mDiagnostics, getResources());
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200325
Olli Etuahoa6996682015-10-12 14:32:30 +0300326 parseContext.setFragmentPrecisionHighOnESSL1(fragmentPrecisionHigh);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000327
328 // We preserve symbols at the built-in level from compile-to-compile.
329 // Start pushing the user-defined symbols at global level.
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400330 TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000331
332 // Parse shader.
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500333 bool success = (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr,
334 &parseContext) == 0) &&
335 (parseContext.getTreeRoot() != nullptr);
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000336
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000337 shaderVersion = parseContext.getShaderVersion();
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700338 if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion)
339 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000340 mDiagnostics.globalError("unsupported shader version");
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700341 success = false;
342 }
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000343
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100344 TIntermBlock *root = nullptr;
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200345
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800346 if (success)
347 {
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700348 mPragma = parseContext.pragma();
Kenneth Russell8bad46d2016-07-01 19:52:52 -0700349 symbolTable.setGlobalInvariant(mPragma.stdgl.invariantAll);
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700350
Martin Radev802abe02016-08-04 17:48:32 +0300351 mComputeShaderLocalSizeDeclared = parseContext.isComputeShaderLocalSizeDeclared();
352 mComputeShaderLocalSize = parseContext.getComputeShaderLocalSize();
353
Olli Etuaho09b04a22016-12-15 13:30:26 +0000354 mNumViews = parseContext.getNumViews();
355
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400356 root = parseContext.getTreeRoot();
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000357
Olli Etuahoa6996682015-10-12 14:32:30 +0300358 // Highp might have been auto-enabled based on shader version
359 fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh();
360
Olli Etuaho09b04a22016-12-15 13:30:26 +0000361 if (success && (IsWebGLBasedSpec(shaderSpec) &&
362 IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview") &&
363 IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview2")))
364 {
365 // Can't enable both extensions at the same time.
366 mDiagnostics.globalError("Can't enable both OVR_multiview and OVR_multiview2");
367 success = false;
368 }
369
Shaob5cc1192017-07-06 10:47:20 +0800370 if (success && shaderType == GL_GEOMETRY_SHADER_OES)
371 {
372 mGeometryShaderInputPrimitiveType = parseContext.getGeometryShaderInputPrimitiveType();
373 mGeometryShaderOutputPrimitiveType =
374 parseContext.getGeometryShaderOutputPrimitiveType();
375 mGeometryShaderMaxVertices = parseContext.getGeometryShaderMaxVertices();
376 mGeometryShaderInvocations = parseContext.getGeometryShaderInvocations();
377 }
378
Jamie Madill6654bc92014-03-26 14:01:57 -0400379 // Disallow expressions deemed too complex.
380 if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY))
381 success = limitExpressionComplexity(root);
382
Corentin Wallez71d147f2015-02-11 11:15:24 -0800383 // Create the function DAG and check there is no recursion
zmo@google.comb1762df2011-07-30 02:04:23 +0000384 if (success)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800385 success = initCallDag(root);
386
387 if (success && (compileOptions & SH_LIMIT_CALL_STACK_DEPTH))
388 success = checkCallDepth();
389
390 // Checks which functions are used and if "main" exists
391 if (success)
392 {
393 functionMetadata.clear();
394 functionMetadata.resize(mCallDag.size());
395 success = tagUsedFunctions();
396 }
zmo@google.comb1762df2011-07-30 02:04:23 +0000397
Corentin Walleza094a8a2015-04-07 11:53:06 -0700398 if (success && !(compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS))
399 success = pruneUnusedFunctions(root);
400
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500401 // Prune empty declarations to work around driver bugs and to keep declaration output
402 // simple.
Olli Etuahoc6833112015-04-22 15:15:54 +0300403 if (success)
404 PruneEmptyDeclarations(root);
405
Andrei Volykhin73fa4b82017-05-05 18:45:06 +0300406 if (success && shaderVersion >= 300 && shaderType == GL_FRAGMENT_SHADER)
Olli Etuaho12b0b392017-05-30 13:22:31 +0300407 {
408 success = ValidateOutputs(root, getExtensionBehavior(), compileResources.MaxDrawBuffers,
409 &mDiagnostics);
410 }
Jamie Madill05a80ce2013-06-20 11:55:49 -0400411
Olli Etuaho5d91dda2015-06-18 15:47:46 +0300412 if (success && shouldRunLoopAndIndexingValidation(compileOptions))
Olli Etuaho9ec79392017-03-31 23:04:23 +0300413 success =
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300414 ValidateLimitations(root, shaderType, &symbolTable, shaderVersion, &mDiagnostics);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000415
Olli Etuaho09b04a22016-12-15 13:30:26 +0000416 bool multiview2 = IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview2");
417 if (success && compileResources.OVR_multiview && IsWebGLBasedSpec(shaderSpec) &&
418 (IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview") || multiview2))
Olli Etuaho01d0ad02017-01-22 14:51:23 -0800419 success = ValidateMultiviewWebGL(root, shaderType, symbolTable, shaderVersion,
420 multiview2, &mDiagnostics);
Olli Etuaho09b04a22016-12-15 13:30:26 +0000421
Jamie Madilld5696192016-10-06 11:09:24 -0400422 // Fail compilation if precision emulation not supported.
423 if (success && getResources().WEBGL_debug_shader_precision &&
424 getPragma().debugShaderPrecision)
425 {
426 if (!EmulatePrecision::SupportedInLanguage(outputType))
427 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000428 mDiagnostics.globalError("Precision emulation not supported for this output type.");
Jamie Madilld5696192016-10-06 11:09:24 -0400429 success = false;
430 }
431 }
432
zmo@google.com32e97312011-08-24 01:03:11 +0000433 // Built-in function emulation needs to happen after validateLimitations pass.
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200434 if (success)
435 {
Jamie Madill438dbcf2016-06-17 14:20:05 -0400436 // TODO(jmadill): Remove global pool allocator.
437 GetGlobalPoolAllocator()->lock();
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200438 initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions);
Jamie Madill438dbcf2016-06-17 14:20:05 -0400439 GetGlobalPoolAllocator()->unlock();
Olli Etuahodfa75e82017-01-23 09:43:06 -0800440 builtInFunctionEmulator.markBuiltInFunctionsForEmulation(root);
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200441 }
zmo@google.com32e97312011-08-24 01:03:11 +0000442
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000443 // Clamping uniform array bounds needs to happen after validateLimitations pass.
444 if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS))
445 arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root);
446
Martin Radev69056a12017-05-18 11:14:50 +0300447 if (success && (compileOptions & SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW) &&
Martin Radev7ef89a42017-07-05 14:23:06 +0300448 parseContext.isMultiviewExtensionEnabled() && getShaderType() != GL_COMPUTE_SHADER)
Martin Radev69056a12017-05-18 11:14:50 +0300449 {
Martin Radevc39a19a2017-07-07 18:52:09 +0300450 DeclareAndInitBuiltinsForInstancedMultiview(root, mNumViews, shaderType, compileOptions,
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300451 outputType, &symbolTable);
Martin Radev69056a12017-05-18 11:14:50 +0300452 }
453
Corentin Wallezd4b50542015-09-28 12:19:26 -0700454 // This pass might emit short circuits so keep it before the short circuit unfolding
455 if (success && (compileOptions & SH_REWRITE_DO_WHILE_LOOPS))
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300456 RewriteDoWhile(root, &symbolTable);
Corentin Wallezd4b50542015-09-28 12:19:26 -0700457
Qiankun Miao09cfac62016-09-06 17:25:16 +0800458 if (success && (compileOptions & SH_ADD_AND_TRUE_TO_LOOP_CONDITION))
459 sh::AddAndTrueToLoopCondition(root);
460
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800461 if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT))
462 {
Zhenyao Mo7cab38b2013-10-15 12:59:30 -0700463 UnfoldShortCircuitAST unfoldShortCircuit;
464 root->traverse(&unfoldShortCircuit);
465 unfoldShortCircuit.updateTree();
466 }
467
Olli Etuaho5c407bb2015-06-01 12:20:39 +0300468 if (success && (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT))
469 {
470 RemovePow(root);
471 }
472
Olli Etuaho4dfe8092015-08-21 17:44:35 +0300473 if (success && shouldCollectVariables(compileOptions))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800474 {
Olli Etuaho19515012017-06-26 18:00:17 +0300475 ASSERT(!variablesCollected);
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +0800476 CollectVariables(root, &attributes, &outputVariables, &uniforms, &inputVaryings,
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800477 &outputVaryings, &uniformBlocks, &shaderStorageBlocks, hashFunction,
478 &symbolTable, shaderVersion, extensionBehavior);
479 collectInterfaceBlocks();
Olli Etuaho19515012017-06-26 18:00:17 +0300480 variablesCollected = true;
Qin Jiajia7835b522016-10-08 11:20:17 +0800481 if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS)
482 {
483 useAllMembersInUnusedStandardAndSharedBlocks(root);
484 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800485 if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS)
486 {
Olli Etuaho19515012017-06-26 18:00:17 +0300487 // Returns true if, after applying the packing rules in the GLSL ES 1.00.17 spec
488 // Appendix A, section 7, the shader does not use too many uniforms.
Olli Etuahod7487b12017-08-09 15:45:13 +0300489 success = CheckVariablesInPackingLimits(maxUniformVectors, uniforms);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800490 if (!success)
491 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000492 mDiagnostics.globalError("too many uniforms");
gman@chromium.org8d804792012-10-17 21:33:48 +0000493 }
494 }
Zhenyao Mo72111912016-07-20 17:45:56 -0700495 if (success && (compileOptions & SH_INIT_OUTPUT_VARIABLES))
496 {
Olli Etuaho27776e32016-07-22 14:00:56 +0300497 initializeOutputVariables(root);
Zhenyao Mo72111912016-07-20 17:45:56 -0700498 }
gman@chromium.org8d804792012-10-17 21:33:48 +0000499 }
zmo@google.comfd747b82011-04-23 01:30:07 +0000500
Olli Etuahob12040c2017-06-27 14:20:45 +0300501 // gl_Position is always written in compatibility output mode.
502 // It may have been already initialized among other output variables, in that case we don't
503 // need to initialize it twice.
504 if (success && shaderType == GL_VERTEX_SHADER && !mGLPositionInitialized &&
505 ((compileOptions & SH_INIT_GL_POSITION) ||
506 (outputType == SH_GLSL_COMPATIBILITY_OUTPUT)))
507 {
508 initializeGLPosition(root);
509 mGLPositionInitialized = true;
510 }
511
Yuly Novikov817232e2017-02-22 18:36:10 -0500512 // Removing invariant declarations must be done after collecting variables.
513 // Otherwise, built-in invariant declarations don't apply.
514 if (success && RemoveInvariant(shaderType, shaderVersion, outputType, compileOptions))
515 sh::RemoveInvariantDeclaration(root);
516
Zhenyao Mocd68fe72014-07-11 10:45:44 -0700517 if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS))
518 {
Olli Etuahob990b552016-10-27 12:29:17 +0100519 ScalarizeVecAndMatConstructorArgs(root, shaderType, fragmentPrecisionHigh,
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300520 &symbolTable);
Zhenyao Mocd68fe72014-07-11 10:45:44 -0700521 }
522
Zhenyao Moe740add2014-07-18 17:01:01 -0700523 if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES))
524 {
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300525 RegenerateStructNames gen(&symbolTable, shaderVersion);
Zhenyao Moe740add2014-07-18 17:01:01 -0700526 root->traverse(&gen);
527 }
Olli Etuaho3d932d82016-04-12 11:10:30 +0300528
Zhenyao Mo4e94fea2016-08-09 14:31:37 -0700529 if (success && shaderType == GL_FRAGMENT_SHADER && shaderVersion == 100 &&
530 compileResources.EXT_draw_buffers && compileResources.MaxDrawBuffers > 1 &&
531 IsExtensionEnabled(extensionBehavior, "GL_EXT_draw_buffers"))
532 {
Olli Etuahodaaff1c2017-07-05 18:03:26 +0300533 EmulateGLFragColorBroadcast(root, compileResources.MaxDrawBuffers, &outputVariables,
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300534 &symbolTable, shaderVersion);
Zhenyao Mo4e94fea2016-08-09 14:31:37 -0700535 }
536
Olli Etuaho3d932d82016-04-12 11:10:30 +0300537 if (success)
538 {
Olli Etuaho0ffc4412017-05-19 14:18:55 +0300539 DeferGlobalInitializers(root, needToInitializeGlobalsInAST());
Olli Etuaho3d932d82016-04-12 11:10:30 +0300540 }
Olli Etuaho9733cee2017-05-11 19:14:35 +0300541
542 if (success && (compileOptions & SH_INITIALIZE_UNINITIALIZED_LOCALS) && getOutputType())
543 {
544 // Initialize uninitialized local variables.
545 // In some cases initializing can generate extra statements in the parent block, such as
546 // when initializing nameless structs or initializing arrays in ESSL 1.00. In that case
547 // we need to first simplify loop conditions and separate declarations. If we don't
548 // follow the Appendix A limitations, loop init statements can declare arrays or
549 // nameless structs and have multiple declarations.
550
551 if (!shouldRunLoopAndIndexingValidation(compileOptions))
552 {
553 SimplifyLoopConditions(root,
554 IntermNodePatternMatcher::kMultiDeclaration |
555 IntermNodePatternMatcher::kArrayDeclaration |
556 IntermNodePatternMatcher::kNamelessStructDeclaration,
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300557 &getSymbolTable(), getShaderVersion());
Olli Etuaho9733cee2017-05-11 19:14:35 +0300558 }
559 // We only really need to separate array declarations and nameless struct declarations,
560 // but it's simpler to just use the regular SeparateDeclarations.
561 SeparateDeclarations(root);
562 InitializeUninitializedLocals(root, getShaderVersion());
563 }
Olli Etuahoab918822017-07-14 17:03:42 +0300564
565 if (success && getShaderType() == GL_VERTEX_SHADER &&
566 (compileOptions & SH_CLAMP_POINT_SIZE))
567 {
568 ClampPointSize(root, compileResources.MaxPointSize, &getSymbolTable());
569 }
alokp@chromium.org07620a52010-09-23 17:53:56 +0000570 }
571
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200572 if (success)
573 return root;
574
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800575 return nullptr;
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200576}
577
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800578bool TCompiler::compile(const char *const shaderStrings[],
579 size_t numStrings,
580 ShCompileOptions compileOptionsIn)
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200581{
Corentin Wallez28b65282016-06-16 07:24:50 -0700582#if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
583 DumpFuzzerCase(shaderStrings, numStrings, shaderType, shaderSpec, outputType, compileOptionsIn);
584#endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
585
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200586 if (numStrings == 0)
587 return true;
588
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800589 ShCompileOptions compileOptions = compileOptionsIn;
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700590
591 // Apply key workarounds.
592 if (shouldFlattenPragmaStdglInvariantAll())
593 {
594 // This should be harmless to do in all cases, but for the moment, do it only conditionally.
595 compileOptions |= SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL;
596 }
597
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200598 TScopedPoolAllocator scopedAlloc(&allocator);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100599 TIntermBlock *root = compileTreeImpl(shaderStrings, numStrings, compileOptions);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200600
601 if (root)
602 {
603 if (compileOptions & SH_INTERMEDIATE_TREE)
Olli Etuahocccf2b02017-07-05 14:50:54 +0300604 OutputTree(root, infoSink.info);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200605
606 if (compileOptions & SH_OBJECT_CODE)
607 translate(root, compileOptions);
608
609 // The IntermNode tree doesn't need to be deleted here, since the
610 // memory will be freed in a big chunk by the PoolAllocator.
611 return true;
612 }
613 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000614}
615
Nicolas Capens49a88872013-06-20 09:54:03 -0400616bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000617{
Olli Etuaho28cb0362016-11-22 15:42:37 +0000618 if (resources.MaxDrawBuffers < 1)
619 {
620 return false;
621 }
622 if (resources.EXT_blend_func_extended && resources.MaxDualSourceDrawBuffers < 1)
623 {
624 return false;
625 }
626
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +0000627 compileResources = resources;
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400628 setResourceString();
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000629
Nicolas Capens49a88872013-06-20 09:54:03 -0400630 assert(symbolTable.isEmpty());
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500631 symbolTable.push(); // COMMON_BUILTINS
632 symbolTable.push(); // ESSL1_BUILTINS
633 symbolTable.push(); // ESSL3_BUILTINS
634 symbolTable.push(); // ESSL3_1_BUILTINS
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000635
Jamie Madillacb4b812016-11-07 13:50:29 -0500636 switch (shaderType)
Nicolas Capens49a88872013-06-20 09:54:03 -0400637 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500638 case GL_FRAGMENT_SHADER:
Olli Etuahocce89652017-06-19 16:04:09 +0300639 symbolTable.setDefaultPrecision(EbtInt, EbpMedium);
Jamie Madillacb4b812016-11-07 13:50:29 -0500640 break;
641 case GL_VERTEX_SHADER:
Jamie Madillacb4b812016-11-07 13:50:29 -0500642 case GL_COMPUTE_SHADER:
Shaob5cc1192017-07-06 10:47:20 +0800643 case GL_GEOMETRY_SHADER_OES:
Olli Etuahocce89652017-06-19 16:04:09 +0300644 symbolTable.setDefaultPrecision(EbtInt, EbpHigh);
645 symbolTable.setDefaultPrecision(EbtFloat, EbpHigh);
Jamie Madillacb4b812016-11-07 13:50:29 -0500646 break;
647 default:
Shaob5cc1192017-07-06 10:47:20 +0800648 UNREACHABLE();
Nicolas Capens49a88872013-06-20 09:54:03 -0400649 }
Olli Etuaho183d7e22015-11-20 15:59:09 +0200650 // Set defaults for sampler types that have default precision, even those that are
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400651 // only available if an extension exists.
Olli Etuaho183d7e22015-11-20 15:59:09 +0200652 // New sampler types in ESSL3 don't have default precision. ESSL1 types do.
653 initSamplerDefaultPrecision(EbtSampler2D);
654 initSamplerDefaultPrecision(EbtSamplerCube);
655 // SamplerExternalOES is specified in the extension to have default precision.
656 initSamplerDefaultPrecision(EbtSamplerExternalOES);
Andrei Volykhina5527072017-03-22 16:46:30 +0300657 // SamplerExternal2DY2YEXT is specified in the extension to have default precision.
658 initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT);
Olli Etuaho183d7e22015-11-20 15:59:09 +0200659 // It isn't specified whether Sampler2DRect has default precision.
660 initSamplerDefaultPrecision(EbtSampler2DRect);
Nicolas Capens49a88872013-06-20 09:54:03 -0400661
Olli Etuahocce89652017-06-19 16:04:09 +0300662 symbolTable.setDefaultPrecision(EbtAtomicCounter, EbpHigh);
jchen104cdac9e2017-05-08 11:01:20 +0800663
Jamie Madill1b452142013-07-12 14:51:11 -0400664 InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
Nicolas Capens49a88872013-06-20 09:54:03 -0400665
666 IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
667
668 return true;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000669}
670
Olli Etuaho183d7e22015-11-20 15:59:09 +0200671void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
672{
673 ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
Olli Etuahocce89652017-06-19 16:04:09 +0300674 symbolTable.setDefaultPrecision(samplerType, EbpLow);
Olli Etuaho183d7e22015-11-20 15:59:09 +0200675}
676
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400677void TCompiler::setResourceString()
678{
679 std::ostringstream strstream;
Geoff Langb66a9092016-05-16 15:59:14 -0400680
681 // clang-format off
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400682 strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs
Jamie Madillacb4b812016-11-07 13:50:29 -0500683 << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors
684 << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors
685 << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits
686 << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits
687 << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits
688 << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors
689 << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers
690 << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives
691 << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external
692 << ":OES_EGL_image_external_essl3:" << compileResources.OES_EGL_image_external_essl3
693 << ":NV_EGL_stream_consumer_external:" << compileResources.NV_EGL_stream_consumer_external
694 << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle
695 << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers
696 << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh
697 << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity
698 << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth
699 << ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters
700 << ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended
701 << ":EXT_frag_depth:" << compileResources.EXT_frag_depth
702 << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod
703 << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch
704 << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch
705 << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch
Martin Radev318f9aa2017-05-17 17:47:28 +0300706 << ":OVR_multiview:" << compileResources.OVR_multiview
Andrei Volykhina5527072017-03-22 16:46:30 +0300707 << ":EXT_YUV_target:" << compileResources.EXT_YUV_target
Shaob5cc1192017-07-06 10:47:20 +0800708 << ":OES_geometry_shader:" << compileResources.OES_geometry_shader
Jamie Madillacb4b812016-11-07 13:50:29 -0500709 << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
710 << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
711 << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
712 << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset
713 << ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers
Martin Radev318f9aa2017-05-17 17:47:28 +0300714 << ":MaxViewsOVR:" << compileResources.MaxViewsOVR
Jamie Madillacb4b812016-11-07 13:50:29 -0500715 << ":NV_draw_buffers:" << compileResources.NV_draw_buffers
716 << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision
717 << ":MaxImageUnits:" << compileResources.MaxImageUnits
718 << ":MaxVertexImageUniforms:" << compileResources.MaxVertexImageUniforms
719 << ":MaxFragmentImageUniforms:" << compileResources.MaxFragmentImageUniforms
720 << ":MaxComputeImageUniforms:" << compileResources.MaxComputeImageUniforms
721 << ":MaxCombinedImageUniforms:" << compileResources.MaxCombinedImageUniforms
722 << ":MaxCombinedShaderOutputResources:" << compileResources.MaxCombinedShaderOutputResources
723 << ":MaxComputeWorkGroupCountX:" << compileResources.MaxComputeWorkGroupCount[0]
724 << ":MaxComputeWorkGroupCountY:" << compileResources.MaxComputeWorkGroupCount[1]
725 << ":MaxComputeWorkGroupCountZ:" << compileResources.MaxComputeWorkGroupCount[2]
726 << ":MaxComputeWorkGroupSizeX:" << compileResources.MaxComputeWorkGroupSize[0]
727 << ":MaxComputeWorkGroupSizeY:" << compileResources.MaxComputeWorkGroupSize[1]
728 << ":MaxComputeWorkGroupSizeZ:" << compileResources.MaxComputeWorkGroupSize[2]
729 << ":MaxComputeUniformComponents:" << compileResources.MaxComputeUniformComponents
730 << ":MaxComputeTextureImageUnits:" << compileResources.MaxComputeTextureImageUnits
731 << ":MaxComputeAtomicCounters:" << compileResources.MaxComputeAtomicCounters
732 << ":MaxComputeAtomicCounterBuffers:" << compileResources.MaxComputeAtomicCounterBuffers
733 << ":MaxVertexAtomicCounters:" << compileResources.MaxVertexAtomicCounters
734 << ":MaxFragmentAtomicCounters:" << compileResources.MaxFragmentAtomicCounters
735 << ":MaxCombinedAtomicCounters:" << compileResources.MaxCombinedAtomicCounters
736 << ":MaxAtomicCounterBindings:" << compileResources.MaxAtomicCounterBindings
737 << ":MaxVertexAtomicCounterBuffers:" << compileResources.MaxVertexAtomicCounterBuffers
738 << ":MaxFragmentAtomicCounterBuffers:" << compileResources.MaxFragmentAtomicCounterBuffers
739 << ":MaxCombinedAtomicCounterBuffers:" << compileResources.MaxCombinedAtomicCounterBuffers
Shaob5cc1192017-07-06 10:47:20 +0800740 << ":MaxAtomicCounterBufferSize:" << compileResources.MaxAtomicCounterBufferSize
741 << ":MaxGeometryOutputVertices:" << compileResources.MaxGeometryOutputVertices
742 << ":MaxGeometryUniformComponents:" << compileResources.MaxGeometryUniformComponents
743 << ":MaxGeometryShaderInvocations:" << compileResources.MaxGeometryShaderInvocations;
Geoff Langb66a9092016-05-16 15:59:14 -0400744 // clang-format on
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400745
746 builtInResourcesString = strstream.str();
747}
748
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800749void TCompiler::collectInterfaceBlocks()
750{
751 ASSERT(interfaceBlocks.empty());
752 interfaceBlocks.reserve(uniformBlocks.size() + shaderStorageBlocks.size());
753 interfaceBlocks.insert(interfaceBlocks.end(), uniformBlocks.begin(), uniformBlocks.end());
754 interfaceBlocks.insert(interfaceBlocks.end(), shaderStorageBlocks.begin(),
755 shaderStorageBlocks.end());
756}
757
alokp@chromium.org07620a52010-09-23 17:53:56 +0000758void TCompiler::clearResults()
759{
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000760 arrayBoundsClamper.Cleanup();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000761 infoSink.info.erase();
762 infoSink.obj.erase();
763 infoSink.debug.erase();
Olli Etuaho77ba4082016-12-16 12:01:18 +0000764 mDiagnostics.resetErrorCount();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000765
Jamie Madilled27c722014-07-02 15:31:23 -0400766 attributes.clear();
767 outputVariables.clear();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000768 uniforms.clear();
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +0800769 inputVaryings.clear();
770 outputVaryings.clear();
Jamie Madilled27c722014-07-02 15:31:23 -0400771 interfaceBlocks.clear();
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800772 uniformBlocks.clear();
773 shaderStorageBlocks.clear();
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700774 variablesCollected = false;
Olli Etuahob12040c2017-06-27 14:20:45 +0300775 mGLPositionInitialized = false;
zmo@google.coma3b4ab42011-09-16 00:53:26 +0000776
Olli Etuaho09b04a22016-12-15 13:30:26 +0000777 mNumViews = -1;
778
Shaob5cc1192017-07-06 10:47:20 +0800779 mGeometryShaderInputPrimitiveType = EptUndefined;
780 mGeometryShaderOutputPrimitiveType = EptUndefined;
781 mGeometryShaderInvocations = 0;
782 mGeometryShaderMaxVertices = -1;
783
Olli Etuahodfa75e82017-01-23 09:43:06 -0800784 builtInFunctionEmulator.cleanup();
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +0000785
786 nameMap.clear();
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200787
Yunchao Hed7297bf2017-04-19 15:27:10 +0800788 mSourcePath = nullptr;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000789}
790
Corentin Wallez71d147f2015-02-11 11:15:24 -0800791bool TCompiler::initCallDag(TIntermNode *root)
zmo@google.comb1762df2011-07-30 02:04:23 +0000792{
Corentin Wallez71d147f2015-02-11 11:15:24 -0800793 mCallDag.clear();
794
Olli Etuaho77ba4082016-12-16 12:01:18 +0000795 switch (mCallDag.init(root, &mDiagnostics))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800796 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500797 case CallDAG::INITDAG_SUCCESS:
798 return true;
799 case CallDAG::INITDAG_RECURSION:
Jamie Madillacb4b812016-11-07 13:50:29 -0500800 case CallDAG::INITDAG_UNDEFINED:
Olli Etuaho77ba4082016-12-16 12:01:18 +0000801 // Error message has already been written out.
802 ASSERT(mDiagnostics.numErrors() > 0);
Jamie Madillacb4b812016-11-07 13:50:29 -0500803 return false;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800804 }
805
806 UNREACHABLE();
807 return true;
808}
809
810bool TCompiler::checkCallDepth()
811{
812 std::vector<int> depths(mCallDag.size());
813
814 for (size_t i = 0; i < mCallDag.size(); i++)
815 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500816 int depth = 0;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800817 auto &record = mCallDag.getRecordFromIndex(i);
818
819 for (auto &calleeIndex : record.callees)
820 {
821 depth = std::max(depth, depths[calleeIndex] + 1);
822 }
823
824 depths[i] = depth;
825
826 if (depth >= maxCallStackDepth)
827 {
828 // Trace back the function chain to have a meaningful info log.
Olli Etuaho77ba4082016-12-16 12:01:18 +0000829 std::stringstream errorStream;
830 errorStream << "Call stack too deep (larger than " << maxCallStackDepth
831 << ") with the following call chain: " << record.name;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800832
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700833 int currentFunction = static_cast<int>(i);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500834 int currentDepth = depth;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800835
836 while (currentFunction != -1)
837 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000838 errorStream << " -> " << mCallDag.getRecordFromIndex(currentFunction).name;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800839
840 int nextFunction = -1;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500841 for (auto &calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800842 {
843 if (depths[calleeIndex] == currentDepth - 1)
844 {
845 currentDepth--;
846 nextFunction = calleeIndex;
847 }
848 }
849
850 currentFunction = nextFunction;
851 }
852
Olli Etuaho77ba4082016-12-16 12:01:18 +0000853 std::string errorStr = errorStream.str();
854 mDiagnostics.globalError(errorStr.c_str());
855
Corentin Wallez71d147f2015-02-11 11:15:24 -0800856 return false;
857 }
858 }
859
860 return true;
861}
862
863bool TCompiler::tagUsedFunctions()
864{
865 // Search from main, starting from the end of the DAG as it usually is the root.
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700866 for (size_t i = mCallDag.size(); i-- > 0;)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800867 {
Olli Etuahoec9232b2017-03-27 17:01:37 +0300868 if (mCallDag.getRecordFromIndex(i).name == "main")
Corentin Wallez71d147f2015-02-11 11:15:24 -0800869 {
870 internalTagUsedFunction(i);
871 return true;
872 }
873 }
874
Olli Etuaho77ba4082016-12-16 12:01:18 +0000875 mDiagnostics.globalError("Missing main()");
Corentin Wallez71d147f2015-02-11 11:15:24 -0800876 return false;
877}
878
879void TCompiler::internalTagUsedFunction(size_t index)
880{
881 if (functionMetadata[index].used)
882 {
883 return;
884 }
885
886 functionMetadata[index].used = true;
887
888 for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees)
889 {
890 internalTagUsedFunction(calleeIndex);
zmo@google.comb1762df2011-07-30 02:04:23 +0000891 }
892}
893
Corentin Walleza094a8a2015-04-07 11:53:06 -0700894// A predicate for the stl that returns if a top-level node is unused
895class TCompiler::UnusedPredicate
896{
897 public:
898 UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas)
Jamie Madillacb4b812016-11-07 13:50:29 -0500899 : mCallDag(callDag), mMetadatas(metadatas)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700900 {
901 }
902
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500903 bool operator()(TIntermNode *node)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700904 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000905 const TIntermFunctionPrototype *asFunctionPrototype = node->getAsFunctionPrototypeNode();
906 const TIntermFunctionDefinition *asFunctionDefinition = node->getAsFunctionDefinition();
Corentin Walleza094a8a2015-04-07 11:53:06 -0700907
Olli Etuaho336b1472016-10-05 16:37:55 +0100908 const TFunctionSymbolInfo *functionInfo = nullptr;
909
Olli Etuaho16c745a2017-01-16 17:02:27 +0000910 if (asFunctionDefinition)
Olli Etuaho336b1472016-10-05 16:37:55 +0100911 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000912 functionInfo = asFunctionDefinition->getFunctionSymbolInfo();
Olli Etuaho336b1472016-10-05 16:37:55 +0100913 }
Olli Etuaho16c745a2017-01-16 17:02:27 +0000914 else if (asFunctionPrototype)
Olli Etuaho336b1472016-10-05 16:37:55 +0100915 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000916 functionInfo = asFunctionPrototype->getFunctionSymbolInfo();
Olli Etuaho336b1472016-10-05 16:37:55 +0100917 }
918 if (functionInfo == nullptr)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700919 {
920 return false;
921 }
922
Olli Etuaho336b1472016-10-05 16:37:55 +0100923 size_t callDagIndex = mCallDag->findIndex(functionInfo);
Corentin Walleza094a8a2015-04-07 11:53:06 -0700924 if (callDagIndex == CallDAG::InvalidIndex)
925 {
926 // This happens only for unimplemented prototypes which are thus unused
Olli Etuaho16c745a2017-01-16 17:02:27 +0000927 ASSERT(asFunctionPrototype);
Corentin Walleza094a8a2015-04-07 11:53:06 -0700928 return true;
929 }
930
931 ASSERT(callDagIndex < mMetadatas->size());
932 return !(*mMetadatas)[callDagIndex].used;
933 }
934
935 private:
936 const CallDAG *mCallDag;
937 const std::vector<FunctionMetadata> *mMetadatas;
938};
939
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100940bool TCompiler::pruneUnusedFunctions(TIntermBlock *root)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700941{
Corentin Walleza094a8a2015-04-07 11:53:06 -0700942 UnusedPredicate isUnused(&mCallDag, &functionMetadata);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100943 TIntermSequence *sequence = root->getSequence();
Corentin Wallezb081e782015-07-20 05:40:04 -0700944
945 if (!sequence->empty())
946 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500947 sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused),
948 sequence->end());
Corentin Wallezb081e782015-07-20 05:40:04 -0700949 }
Corentin Walleza094a8a2015-04-07 11:53:06 -0700950
951 return true;
952}
953
Olli Etuahob4279202017-05-18 15:08:24 +0300954bool TCompiler::limitExpressionComplexity(TIntermBlock *root)
Jamie Madilleb1a0102013-07-08 13:31:38 -0400955{
Olli Etuahocccf2b02017-07-05 14:50:54 +0300956 if (!IsASTDepthBelowLimit(root, maxExpressionComplexity))
Jamie Madill6654bc92014-03-26 14:01:57 -0400957 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000958 mDiagnostics.globalError("Expression too complex.");
Jamie Madill6654bc92014-03-26 14:01:57 -0400959 return false;
960 }
961
Olli Etuahob4279202017-05-18 15:08:24 +0300962 if (!ValidateMaxParameters(root, maxFunctionParameters))
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200963 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000964 mDiagnostics.globalError("Function has too many parameters.");
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200965 return false;
966 }
967
Jamie Madilleb1a0102013-07-08 13:31:38 -0400968 return true;
969}
970
Corentin Wallez1df16022016-10-27 08:16:56 -0400971bool TCompiler::shouldCollectVariables(ShCompileOptions compileOptions)
972{
973 return (compileOptions & SH_VARIABLES) != 0;
974}
975
976bool TCompiler::wereVariablesCollected() const
977{
978 return variablesCollected;
979}
980
Olli Etuaho9cbc07c2017-05-10 18:22:01 +0300981void TCompiler::initializeGLPosition(TIntermBlock *root)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800982{
Zhenyao Mo72111912016-07-20 17:45:56 -0700983 InitVariableList list;
984 sh::ShaderVariable var(GL_FLOAT_VEC4, 0);
985 var.name = "gl_Position";
986 list.push_back(var);
Olli Etuahodaaff1c2017-07-05 18:03:26 +0300987 InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800988}
989
Olli Etuaho9cbc07c2017-05-10 18:22:01 +0300990void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root)
Qin Jiajia7835b522016-10-08 11:20:17 +0800991{
992 sh::InterfaceBlockList list;
993
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800994 for (auto block : uniformBlocks)
Qin Jiajia7835b522016-10-08 11:20:17 +0800995 {
996 if (!block.staticUse &&
997 (block.layout == sh::BLOCKLAYOUT_STANDARD || block.layout == sh::BLOCKLAYOUT_SHARED))
998 {
999 list.push_back(block);
1000 }
1001 }
1002
Zhenyao Mod7490962016-11-09 15:49:51 -08001003 sh::UseInterfaceBlockFields(root, list, symbolTable);
Qin Jiajia7835b522016-10-08 11:20:17 +08001004}
1005
Olli Etuaho9cbc07c2017-05-10 18:22:01 +03001006void TCompiler::initializeOutputVariables(TIntermBlock *root)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001007{
Zhenyao Mo72111912016-07-20 17:45:56 -07001008 InitVariableList list;
1009 if (shaderType == GL_VERTEX_SHADER)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001010 {
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001011 for (auto var : outputVaryings)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001012 {
Zhenyao Mof9312682016-07-22 12:51:31 -07001013 list.push_back(var);
Olli Etuahob12040c2017-06-27 14:20:45 +03001014 if (var.name == "gl_Position")
1015 {
1016 ASSERT(!mGLPositionInitialized);
1017 mGLPositionInitialized = true;
1018 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001019 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001020 }
Zhenyao Mo72111912016-07-20 17:45:56 -07001021 else
1022 {
1023 ASSERT(shaderType == GL_FRAGMENT_SHADER);
1024 for (auto var : outputVariables)
1025 {
1026 list.push_back(var);
1027 }
1028 }
Olli Etuahodaaff1c2017-07-05 18:03:26 +03001029 InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001030}
1031
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001032const TExtensionBehavior &TCompiler::getExtensionBehavior() const
zmo@google.com5601ea02011-06-10 18:23:25 +00001033{
1034 return extensionBehavior;
1035}
zmo@google.com32e97312011-08-24 01:03:11 +00001036
Olli Etuahoa3a5cc62015-02-13 13:12:22 +02001037const char *TCompiler::getSourcePath() const
1038{
1039 return mSourcePath;
1040}
1041
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001042const ShBuiltInResources &TCompiler::getResources() const
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +00001043{
1044 return compileResources;
1045}
1046
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001047const ArrayBoundsClamper &TCompiler::getArrayBoundsClamper() const
daniel@transgaming.com4167cc92013-01-11 04:11:53 +00001048{
1049 return arrayBoundsClamper;
1050}
1051
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +00001052ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const
1053{
1054 return clampingStrategy;
1055}
1056
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001057const BuiltInFunctionEmulator &TCompiler::getBuiltInFunctionEmulator() const
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +00001058{
1059 return builtInFunctionEmulator;
1060}
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001061
Qiankun Miao7ebb97f2016-09-08 18:01:50 +08001062void TCompiler::writePragma(ShCompileOptions compileOptions)
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001063{
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001064 if (!(compileOptions & SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL))
1065 {
1066 TInfoSinkBase &sink = infoSink.obj;
1067 if (mPragma.stdgl.invariantAll)
1068 sink << "#pragma STDGL invariant(all)\n";
1069 }
1070}
1071
1072bool TCompiler::isVaryingDefined(const char *varyingName)
1073{
1074 ASSERT(variablesCollected);
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001075 for (size_t ii = 0; ii < inputVaryings.size(); ++ii)
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001076 {
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001077 if (inputVaryings[ii].name == varyingName)
1078 {
1079 return true;
1080 }
1081 }
1082 for (size_t ii = 0; ii < outputVaryings.size(); ++ii)
1083 {
1084 if (outputVaryings[ii].name == varyingName)
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001085 {
1086 return true;
1087 }
1088 }
1089
1090 return false;
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001091}
Jamie Madillacb4b812016-11-07 13:50:29 -05001092
1093} // namespace sh