blob: 9cb79b40fdf70a974f237c33992080e38af78c78 [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"
Olli Etuaho78ed6cd2017-08-09 16:19:00 +030017#include "compiler/translator/CollectVariables.h"
Martin Radev69056a12017-05-18 11:14:50 +030018#include "compiler/translator/DeclareAndInitBuiltinsForInstancedMultiview.h"
Olli Etuaho3d932d82016-04-12 11:10:30 +030019#include "compiler/translator/DeferGlobalInitializers.h"
Zhenyao Mo4e94fea2016-08-09 14:31:37 -070020#include "compiler/translator/EmulateGLFragColorBroadcast.h"
Jamie Madilld5696192016-10-06 11:09:24 -040021#include "compiler/translator/EmulatePrecision.h"
Geoff Lang17732822013-08-29 13:46:49 -040022#include "compiler/translator/Initialize.h"
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080023#include "compiler/translator/InitializeVariables.h"
Olli Etuaho9733cee2017-05-11 19:14:35 +030024#include "compiler/translator/IntermNodePatternMatcher.h"
Olli Etuahocccf2b02017-07-05 14:50:54 +030025#include "compiler/translator/IsASTDepthBelowLimit.h"
26#include "compiler/translator/OutputTree.h"
Jamie Madill6b9cb252013-10-17 10:45:47 -040027#include "compiler/translator/ParseContext.h"
Olli Etuaho87c35882017-10-19 15:19:38 +030028#include "compiler/translator/PruneNoOps.h"
Zhenyao Moe740add2014-07-18 17:01:01 -070029#include "compiler/translator/RegenerateStructNames.h"
Olli Etuahobb5a7e22017-08-30 13:03:12 +030030#include "compiler/translator/RemoveArrayLengthMethod.h"
Olli Etuahoc1f14fb2017-10-28 19:17:23 +030031#include "compiler/translator/RemoveEmptySwitchStatements.h"
Qiankun Miao705a9192016-08-29 10:05:27 +080032#include "compiler/translator/RemoveInvariantDeclaration.h"
Olli Etuaho923ecef2017-10-11 12:01:38 +030033#include "compiler/translator/RemoveNoOpCasesFromEndOfSwitchStatements.h"
Olli Etuaho5c407bb2015-06-01 12:20:39 +030034#include "compiler/translator/RemovePow.h"
Corentin Wallezd4b50542015-09-28 12:19:26 -070035#include "compiler/translator/RewriteDoWhile.h"
Zhenyao Mocd68fe72014-07-11 10:45:44 -070036#include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h"
Olli Etuaho9733cee2017-05-11 19:14:35 +030037#include "compiler/translator/SeparateDeclarations.h"
38#include "compiler/translator/SimplifyLoopConditions.h"
Olli Etuahobb5a7e22017-08-30 13:03:12 +030039#include "compiler/translator/SplitSequenceOperator.h"
Zhenyao Mo7cab38b2013-10-15 12:59:30 -070040#include "compiler/translator/UnfoldShortCircuitAST.h"
Qin Jiajia7835b522016-10-08 11:20:17 +080041#include "compiler/translator/UseInterfaceBlockFields.h"
Geoff Lang17732822013-08-29 13:46:49 -040042#include "compiler/translator/ValidateLimitations.h"
Olli Etuaho19d1dc92016-03-08 17:18:46 +020043#include "compiler/translator/ValidateMaxParameters.h"
Geoff Lang17732822013-08-29 13:46:49 -040044#include "compiler/translator/ValidateOutputs.h"
Jiawei Shao4cc89e22017-08-31 14:25:54 +080045#include "compiler/translator/ValidateVaryingLocations.h"
Geoff Lang17732822013-08-29 13:46:49 -040046#include "compiler/translator/VariablePacker.h"
Olli Etuaho661fc482017-10-16 12:17:05 +030047#include "compiler/translator/VectorizeVectorScalarArithmetic.h"
shannon.woods@transgaming.comda1ed362013-01-25 21:54:57 +000048#include "third_party/compiler/ArrayBoundsClamper.h"
Corentin Wallez28b65282016-06-16 07:24:50 -070049
Jamie Madillacb4b812016-11-07 13:50:29 -050050namespace sh
51{
52
Corentin Wallez28b65282016-06-16 07:24:50 -070053namespace
54{
55
56#if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
57void DumpFuzzerCase(char const *const *shaderStrings,
58 size_t numStrings,
59 uint32_t type,
60 uint32_t spec,
61 uint32_t output,
62 uint64_t options)
63{
64 static int fileIndex = 0;
65
66 std::ostringstream o;
67 o << "corpus/" << fileIndex++ << ".sample";
68 std::string s = o.str();
69
70 // Must match the input format of the fuzzer
71 FILE *f = fopen(s.c_str(), "w");
72 fwrite(&type, sizeof(type), 1, f);
73 fwrite(&spec, sizeof(spec), 1, f);
74 fwrite(&output, sizeof(output), 1, f);
75 fwrite(&options, sizeof(options), 1, f);
76
77 char zero[128 - 20] = {0};
78 fwrite(&zero, 128 - 20, 1, f);
79
80 for (size_t i = 0; i < numStrings; i++)
81 {
82 fwrite(shaderStrings[i], sizeof(char), strlen(shaderStrings[i]), f);
83 }
84 fwrite(&zero, 1, 1, f);
85
86 fclose(f);
87}
88#endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
89} // anonymous namespace
90
Jamie Madill5508f392014-02-20 13:31:36 -050091bool IsWebGLBasedSpec(ShShaderSpec spec)
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000092{
Qiankun Miaoc2c5fc42016-08-31 15:24:22 +080093 return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000094}
95
Qingqing Dengad0d0792015-04-08 14:25:06 -070096bool IsGLSL130OrNewer(ShShaderOutput output)
97{
Jamie Madillacb4b812016-11-07 13:50:29 -050098 return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT ||
99 output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT ||
100 output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT ||
101 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);
Qingqing Dengad0d0792015-04-08 14:25:06 -0700103}
104
Qiankun Miao705a9192016-08-29 10:05:27 +0800105bool IsGLSL420OrNewer(ShShaderOutput output)
106{
Jamie Madillacb4b812016-11-07 13:50:29 -0500107 return (output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT ||
108 output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT);
Qiankun Miao705a9192016-08-29 10:05:27 +0800109}
110
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800111bool IsGLSL410OrOlder(ShShaderOutput output)
112{
113 return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT ||
114 output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT ||
115 output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT);
116}
117
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000118bool RemoveInvariant(sh::GLenum shaderType,
119 int shaderVersion,
120 ShShaderOutput outputType,
121 ShCompileOptions compileOptions)
122{
123 if ((compileOptions & SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT) == 0 &&
124 shaderType == GL_FRAGMENT_SHADER && IsGLSL420OrNewer(outputType))
125 return true;
126
127 if ((compileOptions & SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3) != 0 &&
Qiankun Miao41f9f672016-11-16 17:04:36 +0800128 shaderVersion >= 300 && shaderType == GL_VERTEX_SHADER)
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000129 return true;
130
131 return false;
132}
133
Zhenyao Mo7faf1a12014-04-25 18:03:56 -0700134size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
Jamie Madill88f6e942014-02-19 10:27:53 -0500135{
He Yunchao29ab9ff2015-08-06 16:58:30 +0800136 // WebGL defines a max token length of 256, while ES2 leaves max token
Jamie Madill88f6e942014-02-19 10:27:53 -0500137 // size undefined. ES3 defines a max size of 1024 characters.
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700138 switch (spec)
Jamie Madill88f6e942014-02-19 10:27:53 -0500139 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500140 case SH_WEBGL_SPEC:
141 return 256;
142 default:
143 return 1024;
Jamie Madill88f6e942014-02-19 10:27:53 -0500144 }
145}
146
Shao77891c02017-06-23 16:30:17 +0800147int GetMaxUniformVectorsForShaderType(GLenum shaderType, const ShBuiltInResources &resources)
148{
149 switch (shaderType)
150 {
151 case GL_VERTEX_SHADER:
152 return resources.MaxVertexUniformVectors;
153 case GL_FRAGMENT_SHADER:
154 return resources.MaxFragmentUniformVectors;
Shaob5cc1192017-07-06 10:47:20 +0800155
156 // TODO (jiawei.shao@intel.com): check if we need finer-grained component counting
Shao77891c02017-06-23 16:30:17 +0800157 case GL_COMPUTE_SHADER:
Shao77891c02017-06-23 16:30:17 +0800158 return resources.MaxComputeUniformComponents / 4;
Shaob5cc1192017-07-06 10:47:20 +0800159 case GL_GEOMETRY_SHADER_OES:
160 return resources.MaxGeometryUniformComponents / 4;
Shao77891c02017-06-23 16:30:17 +0800161 default:
Shaob5cc1192017-07-06 10:47:20 +0800162 UNREACHABLE();
Shao77891c02017-06-23 16:30:17 +0800163 return -1;
164 }
165}
166
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500167namespace
168{
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700169
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800170class TScopedPoolAllocator
171{
172 public:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500173 TScopedPoolAllocator(TPoolAllocator *allocator) : mAllocator(allocator)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800174 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400175 mAllocator->push();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000176 SetGlobalPoolAllocator(mAllocator);
177 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800178 ~TScopedPoolAllocator()
179 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800180 SetGlobalPoolAllocator(nullptr);
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400181 mAllocator->pop();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000182 }
183
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800184 private:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500185 TPoolAllocator *mAllocator;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400186};
187
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800188class TScopedSymbolTableLevel
189{
190 public:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500191 TScopedSymbolTableLevel(TSymbolTable *table) : mTable(table)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800192 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400193 ASSERT(mTable->atBuiltInLevel());
194 mTable->push();
195 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800196 ~TScopedSymbolTableLevel()
197 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400198 while (!mTable->atBuiltInLevel())
199 mTable->pop();
200 }
201
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800202 private:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500203 TSymbolTable *mTable;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000204};
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700205
206int MapSpecToShaderVersion(ShShaderSpec spec)
207{
208 switch (spec)
209 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500210 case SH_GLES2_SPEC:
211 case SH_WEBGL_SPEC:
212 return 100;
213 case SH_GLES3_SPEC:
214 case SH_WEBGL2_SPEC:
215 return 300;
216 case SH_GLES3_1_SPEC:
217 case SH_WEBGL3_SPEC:
218 return 310;
219 default:
220 UNREACHABLE();
221 return 0;
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700222 }
223}
224
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000225} // namespace
226
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800227TShHandleBase::TShHandleBase()
228{
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000229 allocator.push();
230 SetGlobalPoolAllocator(&allocator);
231}
232
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800233TShHandleBase::~TShHandleBase()
234{
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800235 SetGlobalPoolAllocator(nullptr);
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000236 allocator.popAll();
237}
238
Jamie Madill183bde52014-07-02 15:31:19 -0400239TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700240 : variablesCollected(false),
Olli Etuahob12040c2017-06-27 14:20:45 +0300241 mGLPositionInitialized(false),
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700242 shaderType(type),
zmo@google.comf420c422011-09-12 18:27:59 +0000243 shaderSpec(spec),
Jamie Madill68fe74a2014-05-27 12:56:01 -0400244 outputType(output),
Jamie Madilleb1a0102013-07-08 13:31:38 -0400245 maxUniformVectors(0),
246 maxExpressionComplexity(0),
247 maxCallStackDepth(0),
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200248 maxFunctionParameters(0),
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000249 fragmentPrecisionHigh(false),
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000250 clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC),
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200251 builtInFunctionEmulator(),
Olli Etuaho77ba4082016-12-16 12:01:18 +0000252 mDiagnostics(infoSink.info),
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800253 mSourcePath(nullptr),
Shaob5cc1192017-07-06 10:47:20 +0800254 mComputeShaderLocalSizeDeclared(false),
255 mGeometryShaderMaxVertices(-1),
256 mGeometryShaderInvocations(0),
257 mGeometryShaderInputPrimitiveType(EptUndefined),
258 mGeometryShaderOutputPrimitiveType(EptUndefined)
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000259{
Martin Radev802abe02016-08-04 17:48:32 +0300260 mComputeShaderLocalSize.fill(1);
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000261}
262
263TCompiler::~TCompiler()
264{
265}
266
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800267bool TCompiler::shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptions) const
Olli Etuaho5d91dda2015-06-18 15:47:46 +0300268{
269 // If compiling an ESSL 1.00 shader for WebGL, or if its been requested through the API,
270 // validate loop and indexing as well (to verify that the shader only uses minimal functionality
271 // of ESSL 1.00 as in Appendix A of the spec).
272 return (IsWebGLBasedSpec(shaderSpec) && shaderVersion == 100) ||
273 (compileOptions & SH_VALIDATE_LOOP_INDEXING);
274}
275
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500276bool TCompiler::Init(const ShBuiltInResources &resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000277{
Shao77891c02017-06-23 16:30:17 +0800278 shaderVersion = 100;
279
280 maxUniformVectors = GetMaxUniformVectorsForShaderType(shaderType, resources);
281
Jamie Madilleb1a0102013-07-08 13:31:38 -0400282 maxExpressionComplexity = resources.MaxExpressionComplexity;
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200283 maxCallStackDepth = resources.MaxCallStackDepth;
284 maxFunctionParameters = resources.MaxFunctionParameters;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400285
286 SetGlobalPoolAllocator(&allocator);
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000287
alokp@chromium.org07620a52010-09-23 17:53:56 +0000288 // Generate built-in symbol table.
289 if (!InitBuiltInSymbolTable(resources))
290 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000291 InitExtensionBehavior(resources, extensionBehavior);
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000292 fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000293
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000294 arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy);
295 clampingStrategy = resources.ArrayIndexClampingStrategy;
296
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000297 hashFunction = resources.HashFunction;
298
alokp@chromium.org07620a52010-09-23 17:53:56 +0000299 return true;
300}
301
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100302TIntermBlock *TCompiler::compileTreeForTesting(const char *const shaderStrings[],
303 size_t numStrings,
304 ShCompileOptions compileOptions)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000305{
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200306 return compileTreeImpl(shaderStrings, numStrings, compileOptions);
307}
308
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100309TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
310 size_t numStrings,
311 const ShCompileOptions compileOptions)
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200312{
alokp@chromium.org07620a52010-09-23 17:53:56 +0000313 clearResults();
314
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200315 ASSERT(numStrings > 0);
316 ASSERT(GetGlobalPoolAllocator());
alokp@chromium.org07620a52010-09-23 17:53:56 +0000317
David Yen0fbd1282015-02-02 14:46:09 -0800318 // Reset the extension behavior for each compilation unit.
319 ResetExtensionBehavior(extensionBehavior);
320
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000321 // First string is path of source file if flag is set. The actual source follows.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000322 size_t firstSource = 0;
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000323 if (compileOptions & SH_SOURCE_PATH)
324 {
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200325 mSourcePath = shaderStrings[0];
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000326 ++firstSource;
327 }
328
Olli Etuahof119a262016-08-19 15:54:22 +0300329 TParseContext parseContext(symbolTable, extensionBehavior, shaderType, shaderSpec,
Olli Etuaho77ba4082016-12-16 12:01:18 +0000330 compileOptions, true, &mDiagnostics, getResources());
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200331
Olli Etuahoa6996682015-10-12 14:32:30 +0300332 parseContext.setFragmentPrecisionHighOnESSL1(fragmentPrecisionHigh);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000333
334 // We preserve symbols at the built-in level from compile-to-compile.
335 // Start pushing the user-defined symbols at global level.
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400336 TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000337
338 // Parse shader.
Olli Etuahod10cf692017-11-02 11:06:14 +0200339 if (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr,
340 &parseContext) != 0)
341 {
342 return nullptr;
343 }
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000344
Olli Etuahod10cf692017-11-02 11:06:14 +0200345 if (parseContext.getTreeRoot() == nullptr)
346 {
347 return nullptr;
348 }
349
350 setASTMetadata(parseContext);
351
352 if (MapSpecToShaderVersion(shaderSpec) < shaderVersion)
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700353 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000354 mDiagnostics.globalError("unsupported shader version");
Olli Etuahod10cf692017-11-02 11:06:14 +0200355 return nullptr;
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700356 }
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000357
Olli Etuahod10cf692017-11-02 11:06:14 +0200358 TIntermBlock *root = parseContext.getTreeRoot();
359 if (!checkAndSimplifyAST(root, parseContext, compileOptions))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800360 {
Olli Etuahod10cf692017-11-02 11:06:14 +0200361 return nullptr;
362 }
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700363
Olli Etuahod10cf692017-11-02 11:06:14 +0200364 return root;
365}
Martin Radev802abe02016-08-04 17:48:32 +0300366
Olli Etuahod10cf692017-11-02 11:06:14 +0200367void TCompiler::setASTMetadata(const TParseContext &parseContext)
368{
369 shaderVersion = parseContext.getShaderVersion();
Olli Etuaho09b04a22016-12-15 13:30:26 +0000370
Olli Etuahod10cf692017-11-02 11:06:14 +0200371 mPragma = parseContext.pragma();
372 symbolTable.setGlobalInvariant(mPragma.stdgl.invariantAll);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000373
Olli Etuahod10cf692017-11-02 11:06:14 +0200374 mComputeShaderLocalSizeDeclared = parseContext.isComputeShaderLocalSizeDeclared();
375 mComputeShaderLocalSize = parseContext.getComputeShaderLocalSize();
Olli Etuahoa6996682015-10-12 14:32:30 +0300376
Olli Etuahod10cf692017-11-02 11:06:14 +0200377 mNumViews = parseContext.getNumViews();
378
379 // Highp might have been auto-enabled based on shader version
380 fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh();
381
382 if (shaderType == GL_GEOMETRY_SHADER_OES)
383 {
384 mGeometryShaderInputPrimitiveType = parseContext.getGeometryShaderInputPrimitiveType();
385 mGeometryShaderOutputPrimitiveType = parseContext.getGeometryShaderOutputPrimitiveType();
386 mGeometryShaderMaxVertices = parseContext.getGeometryShaderMaxVertices();
387 mGeometryShaderInvocations = parseContext.getGeometryShaderInvocations();
388 }
389}
390
391bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
392 const TParseContext &parseContext,
393 ShCompileOptions compileOptions)
394{
395 // Disallow expressions deemed too complex.
396 if ((compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY) && !limitExpressionComplexity(root))
397 {
398 return false;
399 }
400
401 // We prune no-ops to work around driver bugs and to keep AST processing and output simple.
402 // The following kinds of no-ops are pruned:
403 // 1. Empty declarations "int;".
404 // 2. Literal statements: "1.0;". The ESSL output doesn't define a default precision
405 // for float, so float literal statements would end up with no precision which is
406 // invalid ESSL.
407 // After this empty declarations are not allowed in the AST.
408 PruneNoOps(root);
409
410 // In case the last case inside a switch statement is a certain type of no-op, GLSL
411 // compilers in drivers may not accept it. In this case we clean up the dead code from the
412 // end of switch statements. This is also required because PruneNoOps may have left switch
413 // statements that only contained an empty declaration inside the final case in an invalid
414 // state. Relies on that PruneNoOps has already been run.
415 RemoveNoOpCasesFromEndOfSwitchStatements(root, &symbolTable);
416
417 // Remove empty switch statements - this makes output simpler.
418 RemoveEmptySwitchStatements(root);
419
420 // Create the function DAG and check there is no recursion
421 if (!initCallDag(root))
422 {
423 return false;
424 }
425
426 if ((compileOptions & SH_LIMIT_CALL_STACK_DEPTH) && !checkCallDepth())
427 {
428 return false;
429 }
430
431 // Checks which functions are used and if "main" exists
432 functionMetadata.clear();
433 functionMetadata.resize(mCallDag.size());
434 if (!tagUsedFunctions())
435 {
436 return false;
437 }
438
439 if (!(compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS))
440 {
441 pruneUnusedFunctions(root);
442 }
443
444 if (shaderVersion >= 310 && !ValidateVaryingLocations(root, &mDiagnostics, shaderType))
445 {
446 return false;
447 }
448
449 if (shaderVersion >= 300 && shaderType == GL_FRAGMENT_SHADER &&
450 !ValidateOutputs(root, getExtensionBehavior(), compileResources.MaxDrawBuffers,
451 &mDiagnostics))
452 {
453 return false;
454 }
455
456 if (shouldRunLoopAndIndexingValidation(compileOptions) &&
457 !ValidateLimitations(root, shaderType, &symbolTable, shaderVersion, &mDiagnostics))
458 {
459 return false;
460 }
461
462 // Fail compilation if precision emulation not supported.
463 if (getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision &&
464 !EmulatePrecision::SupportedInLanguage(outputType))
465 {
466 mDiagnostics.globalError("Precision emulation not supported for this output type.");
467 return false;
468 }
469
470 // Built-in function emulation needs to happen after validateLimitations pass.
471 // TODO(jmadill): Remove global pool allocator.
472 GetGlobalPoolAllocator()->lock();
473 initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions);
474 GetGlobalPoolAllocator()->unlock();
475 builtInFunctionEmulator.markBuiltInFunctionsForEmulation(root);
476
477 // Clamping uniform array bounds needs to happen after validateLimitations pass.
478 if (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS)
479 {
480 arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root);
481 }
482
483 if ((compileOptions & SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW) &&
484 parseContext.isExtensionEnabled(TExtension::OVR_multiview) &&
485 getShaderType() != GL_COMPUTE_SHADER)
486 {
487 DeclareAndInitBuiltinsForInstancedMultiview(root, mNumViews, shaderType, compileOptions,
488 outputType, &symbolTable);
489 }
490
491 // This pass might emit short circuits so keep it before the short circuit unfolding
492 if (compileOptions & SH_REWRITE_DO_WHILE_LOOPS)
493 RewriteDoWhile(root, &symbolTable);
494
495 if (compileOptions & SH_ADD_AND_TRUE_TO_LOOP_CONDITION)
496 sh::AddAndTrueToLoopCondition(root);
497
498 if (compileOptions & SH_UNFOLD_SHORT_CIRCUIT)
499 {
500 UnfoldShortCircuitAST unfoldShortCircuit;
501 root->traverse(&unfoldShortCircuit);
502 unfoldShortCircuit.updateTree();
503 }
504
505 if (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT)
506 {
507 RemovePow(root);
508 }
509
510 if (shouldCollectVariables(compileOptions))
511 {
512 ASSERT(!variablesCollected);
513 CollectVariables(root, &attributes, &outputVariables, &uniforms, &inputVaryings,
514 &outputVaryings, &uniformBlocks, &shaderStorageBlocks, &inBlocks,
515 hashFunction, &symbolTable, shaderVersion, shaderType, extensionBehavior);
516 collectInterfaceBlocks();
517 variablesCollected = true;
518 if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS)
Shaob5cc1192017-07-06 10:47:20 +0800519 {
Olli Etuahod10cf692017-11-02 11:06:14 +0200520 useAllMembersInUnusedStandardAndSharedBlocks(root);
Shaob5cc1192017-07-06 10:47:20 +0800521 }
Olli Etuahod10cf692017-11-02 11:06:14 +0200522 if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800523 {
Olli Etuahod10cf692017-11-02 11:06:14 +0200524 // Returns true if, after applying the packing rules in the GLSL ES 1.00.17 spec
525 // Appendix A, section 7, the shader does not use too many uniforms.
526 if (!CheckVariablesInPackingLimits(maxUniformVectors, uniforms))
Jamie Madilld5696192016-10-06 11:09:24 -0400527 {
Olli Etuahod10cf692017-11-02 11:06:14 +0200528 mDiagnostics.globalError("too many uniforms");
529 return false;
Jamie Madilld5696192016-10-06 11:09:24 -0400530 }
531 }
Olli Etuahod10cf692017-11-02 11:06:14 +0200532 if (compileOptions & SH_INIT_OUTPUT_VARIABLES)
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200533 {
Olli Etuahod10cf692017-11-02 11:06:14 +0200534 initializeOutputVariables(root);
Olli Etuahoab918822017-07-14 17:03:42 +0300535 }
alokp@chromium.org07620a52010-09-23 17:53:56 +0000536 }
537
Olli Etuahod10cf692017-11-02 11:06:14 +0200538 // gl_Position is always written in compatibility output mode.
539 // It may have been already initialized among other output variables, in that case we don't
540 // need to initialize it twice.
541 if (shaderType == GL_VERTEX_SHADER && !mGLPositionInitialized &&
542 ((compileOptions & SH_INIT_GL_POSITION) || (outputType == SH_GLSL_COMPATIBILITY_OUTPUT)))
543 {
544 initializeGLPosition(root);
545 mGLPositionInitialized = true;
546 }
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200547
Olli Etuahod10cf692017-11-02 11:06:14 +0200548 // Removing invariant declarations must be done after collecting variables.
549 // Otherwise, built-in invariant declarations don't apply.
550 if (RemoveInvariant(shaderType, shaderVersion, outputType, compileOptions))
551 {
552 sh::RemoveInvariantDeclaration(root);
553 }
554
555 if (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS)
556 {
557 ScalarizeVecAndMatConstructorArgs(root, shaderType, fragmentPrecisionHigh, &symbolTable);
558 }
559
560 if (compileOptions & SH_REGENERATE_STRUCT_NAMES)
561 {
562 RegenerateStructNames gen(&symbolTable, shaderVersion);
563 root->traverse(&gen);
564 }
565
566 if (shaderType == GL_FRAGMENT_SHADER && shaderVersion == 100 &&
567 compileResources.EXT_draw_buffers && compileResources.MaxDrawBuffers > 1 &&
568 IsExtensionEnabled(extensionBehavior, TExtension::EXT_draw_buffers))
569 {
570 EmulateGLFragColorBroadcast(root, compileResources.MaxDrawBuffers, &outputVariables,
571 &symbolTable, shaderVersion);
572 }
573
574 DeferGlobalInitializers(root, needToInitializeGlobalsInAST(), &symbolTable);
575
576 // Split multi declarations and remove calls to array length().
577 // Note that SimplifyLoopConditions needs to be run before any other AST transformations
578 // that may need to generate new statements from loop conditions or loop expressions.
579 SimplifyLoopConditions(
580 root,
581 IntermNodePatternMatcher::kMultiDeclaration | IntermNodePatternMatcher::kArrayLengthMethod,
582 &getSymbolTable(), getShaderVersion());
583
584 // Note that separate declarations need to be run before other AST transformations that
585 // generate new statements from expressions.
586 SeparateDeclarations(root);
587
588 SplitSequenceOperator(root, IntermNodePatternMatcher::kArrayLengthMethod, &getSymbolTable(),
589 getShaderVersion());
590
591 RemoveArrayLengthMethod(root);
592
593 if ((compileOptions & SH_INITIALIZE_UNINITIALIZED_LOCALS) && getOutputType())
594 {
595 // Initialize uninitialized local variables.
596 // In some cases initializing can generate extra statements in the parent block, such as
597 // when initializing nameless structs or initializing arrays in ESSL 1.00. In that case
598 // we need to first simplify loop conditions. We've already separated declarations
599 // earlier, which is also required. If we don't follow the Appendix A limitations, loop
600 // init statements can declare arrays or nameless structs and have multiple
601 // declarations.
602
603 if (!shouldRunLoopAndIndexingValidation(compileOptions))
604 {
605 SimplifyLoopConditions(root,
606 IntermNodePatternMatcher::kArrayDeclaration |
607 IntermNodePatternMatcher::kNamelessStructDeclaration,
608 &getSymbolTable(), getShaderVersion());
609 }
Olli Etuaho661fc482017-10-16 12:17:05 +0300610
Olli Etuahod10cf692017-11-02 11:06:14 +0200611 InitializeUninitializedLocals(root, getShaderVersion());
612 }
613
614 if (getShaderType() == GL_VERTEX_SHADER && (compileOptions & SH_CLAMP_POINT_SIZE))
615 {
616 ClampPointSize(root, compileResources.MaxPointSize, &getSymbolTable());
617 }
618
Olli Etuaho661fc482017-10-16 12:17:05 +0300619 if (compileOptions & SH_REWRITE_VECTOR_SCALAR_ARITHMETIC)
620 {
621 VectorizeVectorScalarArithmetic(root, &getSymbolTable());
622 }
623
Olli Etuahod10cf692017-11-02 11:06:14 +0200624 return true;
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200625}
626
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800627bool TCompiler::compile(const char *const shaderStrings[],
628 size_t numStrings,
629 ShCompileOptions compileOptionsIn)
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200630{
Corentin Wallez28b65282016-06-16 07:24:50 -0700631#if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
632 DumpFuzzerCase(shaderStrings, numStrings, shaderType, shaderSpec, outputType, compileOptionsIn);
633#endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
634
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200635 if (numStrings == 0)
636 return true;
637
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800638 ShCompileOptions compileOptions = compileOptionsIn;
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700639
640 // Apply key workarounds.
641 if (shouldFlattenPragmaStdglInvariantAll())
642 {
643 // This should be harmless to do in all cases, but for the moment, do it only conditionally.
644 compileOptions |= SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL;
645 }
646
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200647 TScopedPoolAllocator scopedAlloc(&allocator);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100648 TIntermBlock *root = compileTreeImpl(shaderStrings, numStrings, compileOptions);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200649
650 if (root)
651 {
652 if (compileOptions & SH_INTERMEDIATE_TREE)
Olli Etuahocccf2b02017-07-05 14:50:54 +0300653 OutputTree(root, infoSink.info);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200654
655 if (compileOptions & SH_OBJECT_CODE)
Olli Etuaho89a69a02017-10-23 12:20:45 +0300656 {
657 PerformanceDiagnostics perfDiagnostics(&mDiagnostics);
658 translate(root, compileOptions, &perfDiagnostics);
659 }
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200660
661 // The IntermNode tree doesn't need to be deleted here, since the
662 // memory will be freed in a big chunk by the PoolAllocator.
663 return true;
664 }
665 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000666}
667
Nicolas Capens49a88872013-06-20 09:54:03 -0400668bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000669{
Olli Etuaho28cb0362016-11-22 15:42:37 +0000670 if (resources.MaxDrawBuffers < 1)
671 {
672 return false;
673 }
674 if (resources.EXT_blend_func_extended && resources.MaxDualSourceDrawBuffers < 1)
675 {
676 return false;
677 }
678
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +0000679 compileResources = resources;
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400680 setResourceString();
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000681
Olli Etuaho977ee7e2017-07-21 11:38:27 +0300682 ASSERT(symbolTable.isEmpty());
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500683 symbolTable.push(); // COMMON_BUILTINS
684 symbolTable.push(); // ESSL1_BUILTINS
685 symbolTable.push(); // ESSL3_BUILTINS
686 symbolTable.push(); // ESSL3_1_BUILTINS
Olli Etuaho977ee7e2017-07-21 11:38:27 +0300687 symbolTable.push(); // GLSL_BUILTINS
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000688
Jamie Madillacb4b812016-11-07 13:50:29 -0500689 switch (shaderType)
Nicolas Capens49a88872013-06-20 09:54:03 -0400690 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500691 case GL_FRAGMENT_SHADER:
Olli Etuahocce89652017-06-19 16:04:09 +0300692 symbolTable.setDefaultPrecision(EbtInt, EbpMedium);
Jamie Madillacb4b812016-11-07 13:50:29 -0500693 break;
694 case GL_VERTEX_SHADER:
Jamie Madillacb4b812016-11-07 13:50:29 -0500695 case GL_COMPUTE_SHADER:
Shaob5cc1192017-07-06 10:47:20 +0800696 case GL_GEOMETRY_SHADER_OES:
Olli Etuahocce89652017-06-19 16:04:09 +0300697 symbolTable.setDefaultPrecision(EbtInt, EbpHigh);
698 symbolTable.setDefaultPrecision(EbtFloat, EbpHigh);
Jamie Madillacb4b812016-11-07 13:50:29 -0500699 break;
700 default:
Shaob5cc1192017-07-06 10:47:20 +0800701 UNREACHABLE();
Nicolas Capens49a88872013-06-20 09:54:03 -0400702 }
Olli Etuaho183d7e22015-11-20 15:59:09 +0200703 // Set defaults for sampler types that have default precision, even those that are
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400704 // only available if an extension exists.
Olli Etuaho183d7e22015-11-20 15:59:09 +0200705 // New sampler types in ESSL3 don't have default precision. ESSL1 types do.
706 initSamplerDefaultPrecision(EbtSampler2D);
707 initSamplerDefaultPrecision(EbtSamplerCube);
708 // SamplerExternalOES is specified in the extension to have default precision.
709 initSamplerDefaultPrecision(EbtSamplerExternalOES);
Andrei Volykhina5527072017-03-22 16:46:30 +0300710 // SamplerExternal2DY2YEXT is specified in the extension to have default precision.
711 initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT);
Olli Etuaho183d7e22015-11-20 15:59:09 +0200712 // It isn't specified whether Sampler2DRect has default precision.
713 initSamplerDefaultPrecision(EbtSampler2DRect);
Nicolas Capens49a88872013-06-20 09:54:03 -0400714
Olli Etuahocce89652017-06-19 16:04:09 +0300715 symbolTable.setDefaultPrecision(EbtAtomicCounter, EbpHigh);
jchen104cdac9e2017-05-08 11:01:20 +0800716
Jamie Madill1b452142013-07-12 14:51:11 -0400717 InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
Nicolas Capens49a88872013-06-20 09:54:03 -0400718
719 IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
720
721 return true;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000722}
723
Olli Etuaho183d7e22015-11-20 15:59:09 +0200724void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
725{
726 ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
Olli Etuahocce89652017-06-19 16:04:09 +0300727 symbolTable.setDefaultPrecision(samplerType, EbpLow);
Olli Etuaho183d7e22015-11-20 15:59:09 +0200728}
729
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400730void TCompiler::setResourceString()
731{
732 std::ostringstream strstream;
Geoff Langb66a9092016-05-16 15:59:14 -0400733
734 // clang-format off
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400735 strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs
Jamie Madillacb4b812016-11-07 13:50:29 -0500736 << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors
737 << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors
738 << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits
739 << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits
740 << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits
741 << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors
742 << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers
743 << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives
744 << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external
745 << ":OES_EGL_image_external_essl3:" << compileResources.OES_EGL_image_external_essl3
746 << ":NV_EGL_stream_consumer_external:" << compileResources.NV_EGL_stream_consumer_external
747 << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle
748 << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers
749 << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh
750 << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity
751 << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth
752 << ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters
753 << ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended
754 << ":EXT_frag_depth:" << compileResources.EXT_frag_depth
755 << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod
756 << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch
757 << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch
758 << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch
Martin Radev318f9aa2017-05-17 17:47:28 +0300759 << ":OVR_multiview:" << compileResources.OVR_multiview
Andrei Volykhina5527072017-03-22 16:46:30 +0300760 << ":EXT_YUV_target:" << compileResources.EXT_YUV_target
Shaob5cc1192017-07-06 10:47:20 +0800761 << ":OES_geometry_shader:" << compileResources.OES_geometry_shader
Jamie Madillacb4b812016-11-07 13:50:29 -0500762 << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
763 << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
764 << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
765 << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset
766 << ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers
Martin Radev318f9aa2017-05-17 17:47:28 +0300767 << ":MaxViewsOVR:" << compileResources.MaxViewsOVR
Jamie Madillacb4b812016-11-07 13:50:29 -0500768 << ":NV_draw_buffers:" << compileResources.NV_draw_buffers
769 << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision
Martin Radev84aa2dc2017-09-11 15:51:02 +0300770 << ":MinProgramTextureGatherOffset:" << compileResources.MinProgramTextureGatherOffset
771 << ":MaxProgramTextureGatherOffset:" << compileResources.MaxProgramTextureGatherOffset
Jamie Madillacb4b812016-11-07 13:50:29 -0500772 << ":MaxImageUnits:" << compileResources.MaxImageUnits
773 << ":MaxVertexImageUniforms:" << compileResources.MaxVertexImageUniforms
774 << ":MaxFragmentImageUniforms:" << compileResources.MaxFragmentImageUniforms
775 << ":MaxComputeImageUniforms:" << compileResources.MaxComputeImageUniforms
776 << ":MaxCombinedImageUniforms:" << compileResources.MaxCombinedImageUniforms
777 << ":MaxCombinedShaderOutputResources:" << compileResources.MaxCombinedShaderOutputResources
778 << ":MaxComputeWorkGroupCountX:" << compileResources.MaxComputeWorkGroupCount[0]
779 << ":MaxComputeWorkGroupCountY:" << compileResources.MaxComputeWorkGroupCount[1]
780 << ":MaxComputeWorkGroupCountZ:" << compileResources.MaxComputeWorkGroupCount[2]
781 << ":MaxComputeWorkGroupSizeX:" << compileResources.MaxComputeWorkGroupSize[0]
782 << ":MaxComputeWorkGroupSizeY:" << compileResources.MaxComputeWorkGroupSize[1]
783 << ":MaxComputeWorkGroupSizeZ:" << compileResources.MaxComputeWorkGroupSize[2]
784 << ":MaxComputeUniformComponents:" << compileResources.MaxComputeUniformComponents
785 << ":MaxComputeTextureImageUnits:" << compileResources.MaxComputeTextureImageUnits
786 << ":MaxComputeAtomicCounters:" << compileResources.MaxComputeAtomicCounters
787 << ":MaxComputeAtomicCounterBuffers:" << compileResources.MaxComputeAtomicCounterBuffers
788 << ":MaxVertexAtomicCounters:" << compileResources.MaxVertexAtomicCounters
789 << ":MaxFragmentAtomicCounters:" << compileResources.MaxFragmentAtomicCounters
790 << ":MaxCombinedAtomicCounters:" << compileResources.MaxCombinedAtomicCounters
791 << ":MaxAtomicCounterBindings:" << compileResources.MaxAtomicCounterBindings
792 << ":MaxVertexAtomicCounterBuffers:" << compileResources.MaxVertexAtomicCounterBuffers
793 << ":MaxFragmentAtomicCounterBuffers:" << compileResources.MaxFragmentAtomicCounterBuffers
794 << ":MaxCombinedAtomicCounterBuffers:" << compileResources.MaxCombinedAtomicCounterBuffers
Shaob5cc1192017-07-06 10:47:20 +0800795 << ":MaxAtomicCounterBufferSize:" << compileResources.MaxAtomicCounterBufferSize
Shaob5cc1192017-07-06 10:47:20 +0800796 << ":MaxGeometryUniformComponents:" << compileResources.MaxGeometryUniformComponents
Jiawei Shaod27f5c82017-08-23 09:38:08 +0800797 << ":MaxGeometryUniformBlocks:" << compileResources.MaxGeometryUniformBlocks
798 << ":MaxGeometryInputComponents:" << compileResources.MaxGeometryInputComponents
799 << ":MaxGeometryOutputComponents:" << compileResources.MaxGeometryOutputComponents
800 << ":MaxGeometryOutputVertices:" << compileResources.MaxGeometryOutputVertices
801 << ":MaxGeometryTotalOutputComponents:" << compileResources.MaxGeometryTotalOutputComponents
802 << ":MaxGeometryTextureImageUnits:" << compileResources.MaxGeometryTextureImageUnits
803 << ":MaxGeometryAtomicCounterBuffers:" << compileResources.MaxGeometryAtomicCounterBuffers
804 << ":MaxGeometryAtomicCounters:" << compileResources.MaxGeometryAtomicCounters
805 << ":MaxGeometryShaderStorageBlocks:" << compileResources.MaxGeometryShaderStorageBlocks
806 << ":MaxGeometryShaderInvocations:" << compileResources.MaxGeometryShaderInvocations
807 << ":MaxGeometryImageUniforms:" << compileResources.MaxGeometryImageUniforms;
Geoff Langb66a9092016-05-16 15:59:14 -0400808 // clang-format on
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400809
810 builtInResourcesString = strstream.str();
811}
812
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800813void TCompiler::collectInterfaceBlocks()
814{
815 ASSERT(interfaceBlocks.empty());
Jiawei Shaod8105a02017-08-08 09:54:36 +0800816 interfaceBlocks.reserve(uniformBlocks.size() + shaderStorageBlocks.size() + inBlocks.size());
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800817 interfaceBlocks.insert(interfaceBlocks.end(), uniformBlocks.begin(), uniformBlocks.end());
818 interfaceBlocks.insert(interfaceBlocks.end(), shaderStorageBlocks.begin(),
819 shaderStorageBlocks.end());
Jiawei Shaod8105a02017-08-08 09:54:36 +0800820 interfaceBlocks.insert(interfaceBlocks.end(), inBlocks.begin(), inBlocks.end());
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800821}
822
alokp@chromium.org07620a52010-09-23 17:53:56 +0000823void TCompiler::clearResults()
824{
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000825 arrayBoundsClamper.Cleanup();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000826 infoSink.info.erase();
827 infoSink.obj.erase();
828 infoSink.debug.erase();
Olli Etuaho77ba4082016-12-16 12:01:18 +0000829 mDiagnostics.resetErrorCount();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000830
Jamie Madilled27c722014-07-02 15:31:23 -0400831 attributes.clear();
832 outputVariables.clear();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000833 uniforms.clear();
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +0800834 inputVaryings.clear();
835 outputVaryings.clear();
Jamie Madilled27c722014-07-02 15:31:23 -0400836 interfaceBlocks.clear();
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800837 uniformBlocks.clear();
838 shaderStorageBlocks.clear();
Jiawei Shaod8105a02017-08-08 09:54:36 +0800839 inBlocks.clear();
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700840 variablesCollected = false;
Olli Etuahob12040c2017-06-27 14:20:45 +0300841 mGLPositionInitialized = false;
zmo@google.coma3b4ab42011-09-16 00:53:26 +0000842
Olli Etuaho09b04a22016-12-15 13:30:26 +0000843 mNumViews = -1;
844
Shaob5cc1192017-07-06 10:47:20 +0800845 mGeometryShaderInputPrimitiveType = EptUndefined;
846 mGeometryShaderOutputPrimitiveType = EptUndefined;
847 mGeometryShaderInvocations = 0;
848 mGeometryShaderMaxVertices = -1;
849
Olli Etuahodfa75e82017-01-23 09:43:06 -0800850 builtInFunctionEmulator.cleanup();
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +0000851
852 nameMap.clear();
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200853
Yunchao Hed7297bf2017-04-19 15:27:10 +0800854 mSourcePath = nullptr;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000855}
856
Corentin Wallez71d147f2015-02-11 11:15:24 -0800857bool TCompiler::initCallDag(TIntermNode *root)
zmo@google.comb1762df2011-07-30 02:04:23 +0000858{
Corentin Wallez71d147f2015-02-11 11:15:24 -0800859 mCallDag.clear();
860
Olli Etuaho77ba4082016-12-16 12:01:18 +0000861 switch (mCallDag.init(root, &mDiagnostics))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800862 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500863 case CallDAG::INITDAG_SUCCESS:
864 return true;
865 case CallDAG::INITDAG_RECURSION:
Jamie Madillacb4b812016-11-07 13:50:29 -0500866 case CallDAG::INITDAG_UNDEFINED:
Olli Etuaho77ba4082016-12-16 12:01:18 +0000867 // Error message has already been written out.
868 ASSERT(mDiagnostics.numErrors() > 0);
Jamie Madillacb4b812016-11-07 13:50:29 -0500869 return false;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800870 }
871
872 UNREACHABLE();
873 return true;
874}
875
876bool TCompiler::checkCallDepth()
877{
878 std::vector<int> depths(mCallDag.size());
879
880 for (size_t i = 0; i < mCallDag.size(); i++)
881 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500882 int depth = 0;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800883 auto &record = mCallDag.getRecordFromIndex(i);
884
885 for (auto &calleeIndex : record.callees)
886 {
887 depth = std::max(depth, depths[calleeIndex] + 1);
888 }
889
890 depths[i] = depth;
891
892 if (depth >= maxCallStackDepth)
893 {
894 // Trace back the function chain to have a meaningful info log.
Olli Etuaho77ba4082016-12-16 12:01:18 +0000895 std::stringstream errorStream;
896 errorStream << "Call stack too deep (larger than " << maxCallStackDepth
897 << ") with the following call chain: " << record.name;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800898
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700899 int currentFunction = static_cast<int>(i);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500900 int currentDepth = depth;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800901
902 while (currentFunction != -1)
903 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000904 errorStream << " -> " << mCallDag.getRecordFromIndex(currentFunction).name;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800905
906 int nextFunction = -1;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500907 for (auto &calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800908 {
909 if (depths[calleeIndex] == currentDepth - 1)
910 {
911 currentDepth--;
912 nextFunction = calleeIndex;
913 }
914 }
915
916 currentFunction = nextFunction;
917 }
918
Olli Etuaho77ba4082016-12-16 12:01:18 +0000919 std::string errorStr = errorStream.str();
920 mDiagnostics.globalError(errorStr.c_str());
921
Corentin Wallez71d147f2015-02-11 11:15:24 -0800922 return false;
923 }
924 }
925
926 return true;
927}
928
929bool TCompiler::tagUsedFunctions()
930{
931 // Search from main, starting from the end of the DAG as it usually is the root.
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700932 for (size_t i = mCallDag.size(); i-- > 0;)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800933 {
Olli Etuahoec9232b2017-03-27 17:01:37 +0300934 if (mCallDag.getRecordFromIndex(i).name == "main")
Corentin Wallez71d147f2015-02-11 11:15:24 -0800935 {
936 internalTagUsedFunction(i);
937 return true;
938 }
939 }
940
Olli Etuaho77ba4082016-12-16 12:01:18 +0000941 mDiagnostics.globalError("Missing main()");
Corentin Wallez71d147f2015-02-11 11:15:24 -0800942 return false;
943}
944
945void TCompiler::internalTagUsedFunction(size_t index)
946{
947 if (functionMetadata[index].used)
948 {
949 return;
950 }
951
952 functionMetadata[index].used = true;
953
954 for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees)
955 {
956 internalTagUsedFunction(calleeIndex);
zmo@google.comb1762df2011-07-30 02:04:23 +0000957 }
958}
959
Corentin Walleza094a8a2015-04-07 11:53:06 -0700960// A predicate for the stl that returns if a top-level node is unused
961class TCompiler::UnusedPredicate
962{
963 public:
964 UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas)
Jamie Madillacb4b812016-11-07 13:50:29 -0500965 : mCallDag(callDag), mMetadatas(metadatas)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700966 {
967 }
968
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500969 bool operator()(TIntermNode *node)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700970 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000971 const TIntermFunctionPrototype *asFunctionPrototype = node->getAsFunctionPrototypeNode();
972 const TIntermFunctionDefinition *asFunctionDefinition = node->getAsFunctionDefinition();
Corentin Walleza094a8a2015-04-07 11:53:06 -0700973
Olli Etuaho336b1472016-10-05 16:37:55 +0100974 const TFunctionSymbolInfo *functionInfo = nullptr;
975
Olli Etuaho16c745a2017-01-16 17:02:27 +0000976 if (asFunctionDefinition)
Olli Etuaho336b1472016-10-05 16:37:55 +0100977 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000978 functionInfo = asFunctionDefinition->getFunctionSymbolInfo();
Olli Etuaho336b1472016-10-05 16:37:55 +0100979 }
Olli Etuaho16c745a2017-01-16 17:02:27 +0000980 else if (asFunctionPrototype)
Olli Etuaho336b1472016-10-05 16:37:55 +0100981 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000982 functionInfo = asFunctionPrototype->getFunctionSymbolInfo();
Olli Etuaho336b1472016-10-05 16:37:55 +0100983 }
984 if (functionInfo == nullptr)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700985 {
986 return false;
987 }
988
Olli Etuaho336b1472016-10-05 16:37:55 +0100989 size_t callDagIndex = mCallDag->findIndex(functionInfo);
Corentin Walleza094a8a2015-04-07 11:53:06 -0700990 if (callDagIndex == CallDAG::InvalidIndex)
991 {
992 // This happens only for unimplemented prototypes which are thus unused
Olli Etuaho16c745a2017-01-16 17:02:27 +0000993 ASSERT(asFunctionPrototype);
Corentin Walleza094a8a2015-04-07 11:53:06 -0700994 return true;
995 }
996
997 ASSERT(callDagIndex < mMetadatas->size());
998 return !(*mMetadatas)[callDagIndex].used;
999 }
1000
1001 private:
1002 const CallDAG *mCallDag;
1003 const std::vector<FunctionMetadata> *mMetadatas;
1004};
1005
Olli Etuahod10cf692017-11-02 11:06:14 +02001006void TCompiler::pruneUnusedFunctions(TIntermBlock *root)
Corentin Walleza094a8a2015-04-07 11:53:06 -07001007{
Corentin Walleza094a8a2015-04-07 11:53:06 -07001008 UnusedPredicate isUnused(&mCallDag, &functionMetadata);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +01001009 TIntermSequence *sequence = root->getSequence();
Corentin Wallezb081e782015-07-20 05:40:04 -07001010
1011 if (!sequence->empty())
1012 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001013 sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused),
1014 sequence->end());
Corentin Wallezb081e782015-07-20 05:40:04 -07001015 }
Corentin Walleza094a8a2015-04-07 11:53:06 -07001016}
1017
Olli Etuahob4279202017-05-18 15:08:24 +03001018bool TCompiler::limitExpressionComplexity(TIntermBlock *root)
Jamie Madilleb1a0102013-07-08 13:31:38 -04001019{
Olli Etuahocccf2b02017-07-05 14:50:54 +03001020 if (!IsASTDepthBelowLimit(root, maxExpressionComplexity))
Jamie Madill6654bc92014-03-26 14:01:57 -04001021 {
Olli Etuaho77ba4082016-12-16 12:01:18 +00001022 mDiagnostics.globalError("Expression too complex.");
Jamie Madill6654bc92014-03-26 14:01:57 -04001023 return false;
1024 }
1025
Olli Etuahob4279202017-05-18 15:08:24 +03001026 if (!ValidateMaxParameters(root, maxFunctionParameters))
Olli Etuaho19d1dc92016-03-08 17:18:46 +02001027 {
Olli Etuaho77ba4082016-12-16 12:01:18 +00001028 mDiagnostics.globalError("Function has too many parameters.");
Olli Etuaho19d1dc92016-03-08 17:18:46 +02001029 return false;
1030 }
1031
Jamie Madilleb1a0102013-07-08 13:31:38 -04001032 return true;
1033}
1034
Corentin Wallez1df16022016-10-27 08:16:56 -04001035bool TCompiler::shouldCollectVariables(ShCompileOptions compileOptions)
1036{
1037 return (compileOptions & SH_VARIABLES) != 0;
1038}
1039
1040bool TCompiler::wereVariablesCollected() const
1041{
1042 return variablesCollected;
1043}
1044
Olli Etuaho9cbc07c2017-05-10 18:22:01 +03001045void TCompiler::initializeGLPosition(TIntermBlock *root)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001046{
Zhenyao Mo72111912016-07-20 17:45:56 -07001047 InitVariableList list;
Olli Etuahoe7c28572017-10-23 16:29:33 +03001048 sh::ShaderVariable var(GL_FLOAT_VEC4);
Zhenyao Mo72111912016-07-20 17:45:56 -07001049 var.name = "gl_Position";
1050 list.push_back(var);
Olli Etuahodaaff1c2017-07-05 18:03:26 +03001051 InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001052}
1053
Olli Etuaho9cbc07c2017-05-10 18:22:01 +03001054void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root)
Qin Jiajia7835b522016-10-08 11:20:17 +08001055{
1056 sh::InterfaceBlockList list;
1057
Jiajia Qin9b11ea42017-07-11 16:50:08 +08001058 for (auto block : uniformBlocks)
Qin Jiajia7835b522016-10-08 11:20:17 +08001059 {
1060 if (!block.staticUse &&
Qin Jiajiaca68d982017-09-18 16:41:56 +08001061 (block.layout == sh::BLOCKLAYOUT_STD140 || block.layout == sh::BLOCKLAYOUT_SHARED))
Qin Jiajia7835b522016-10-08 11:20:17 +08001062 {
1063 list.push_back(block);
1064 }
1065 }
1066
Zhenyao Mod7490962016-11-09 15:49:51 -08001067 sh::UseInterfaceBlockFields(root, list, symbolTable);
Qin Jiajia7835b522016-10-08 11:20:17 +08001068}
1069
Olli Etuaho9cbc07c2017-05-10 18:22:01 +03001070void TCompiler::initializeOutputVariables(TIntermBlock *root)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001071{
Zhenyao Mo72111912016-07-20 17:45:56 -07001072 InitVariableList list;
Jiawei Shaod27f5c82017-08-23 09:38:08 +08001073 if (shaderType == GL_VERTEX_SHADER || shaderType == GL_GEOMETRY_SHADER_OES)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001074 {
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001075 for (auto var : outputVaryings)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001076 {
Zhenyao Mof9312682016-07-22 12:51:31 -07001077 list.push_back(var);
Olli Etuahob12040c2017-06-27 14:20:45 +03001078 if (var.name == "gl_Position")
1079 {
1080 ASSERT(!mGLPositionInitialized);
1081 mGLPositionInitialized = true;
1082 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001083 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001084 }
Zhenyao Mo72111912016-07-20 17:45:56 -07001085 else
1086 {
1087 ASSERT(shaderType == GL_FRAGMENT_SHADER);
1088 for (auto var : outputVariables)
1089 {
1090 list.push_back(var);
1091 }
1092 }
Olli Etuahodaaff1c2017-07-05 18:03:26 +03001093 InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001094}
1095
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001096const TExtensionBehavior &TCompiler::getExtensionBehavior() const
zmo@google.com5601ea02011-06-10 18:23:25 +00001097{
1098 return extensionBehavior;
1099}
zmo@google.com32e97312011-08-24 01:03:11 +00001100
Olli Etuahoa3a5cc62015-02-13 13:12:22 +02001101const char *TCompiler::getSourcePath() const
1102{
1103 return mSourcePath;
1104}
1105
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001106const ShBuiltInResources &TCompiler::getResources() const
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +00001107{
1108 return compileResources;
1109}
1110
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001111const ArrayBoundsClamper &TCompiler::getArrayBoundsClamper() const
daniel@transgaming.com4167cc92013-01-11 04:11:53 +00001112{
1113 return arrayBoundsClamper;
1114}
1115
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +00001116ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const
1117{
1118 return clampingStrategy;
1119}
1120
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001121const BuiltInFunctionEmulator &TCompiler::getBuiltInFunctionEmulator() const
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +00001122{
1123 return builtInFunctionEmulator;
1124}
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001125
Qiankun Miao7ebb97f2016-09-08 18:01:50 +08001126void TCompiler::writePragma(ShCompileOptions compileOptions)
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001127{
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001128 if (!(compileOptions & SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL))
1129 {
1130 TInfoSinkBase &sink = infoSink.obj;
1131 if (mPragma.stdgl.invariantAll)
1132 sink << "#pragma STDGL invariant(all)\n";
1133 }
1134}
1135
1136bool TCompiler::isVaryingDefined(const char *varyingName)
1137{
1138 ASSERT(variablesCollected);
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001139 for (size_t ii = 0; ii < inputVaryings.size(); ++ii)
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001140 {
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001141 if (inputVaryings[ii].name == varyingName)
1142 {
1143 return true;
1144 }
1145 }
1146 for (size_t ii = 0; ii < outputVaryings.size(); ++ii)
1147 {
1148 if (outputVaryings[ii].name == varyingName)
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001149 {
1150 return true;
1151 }
1152 }
1153
1154 return false;
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001155}
Jamie Madillacb4b812016-11-07 13:50:29 -05001156
1157} // namespace sh