blob: b6e256eae813b25919d334dcedba6dd62a238753 [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 Etuahoc6833112015-04-22 15:15:54 +030028#include "compiler/translator/PruneEmptyDeclarations.h"
Zhenyao Moe740add2014-07-18 17:01:01 -070029#include "compiler/translator/RegenerateStructNames.h"
Qiankun Miao705a9192016-08-29 10:05:27 +080030#include "compiler/translator/RemoveInvariantDeclaration.h"
Olli Etuaho5c407bb2015-06-01 12:20:39 +030031#include "compiler/translator/RemovePow.h"
Corentin Wallezd4b50542015-09-28 12:19:26 -070032#include "compiler/translator/RewriteDoWhile.h"
Zhenyao Mocd68fe72014-07-11 10:45:44 -070033#include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h"
Olli Etuaho9733cee2017-05-11 19:14:35 +030034#include "compiler/translator/SeparateDeclarations.h"
35#include "compiler/translator/SimplifyLoopConditions.h"
Zhenyao Mo7cab38b2013-10-15 12:59:30 -070036#include "compiler/translator/UnfoldShortCircuitAST.h"
Qin Jiajia7835b522016-10-08 11:20:17 +080037#include "compiler/translator/UseInterfaceBlockFields.h"
Geoff Lang17732822013-08-29 13:46:49 -040038#include "compiler/translator/ValidateLimitations.h"
Olli Etuaho19d1dc92016-03-08 17:18:46 +020039#include "compiler/translator/ValidateMaxParameters.h"
Olli Etuaho09b04a22016-12-15 13:30:26 +000040#include "compiler/translator/ValidateMultiviewWebGL.h"
Geoff Lang17732822013-08-29 13:46:49 -040041#include "compiler/translator/ValidateOutputs.h"
42#include "compiler/translator/VariablePacker.h"
shannon.woods@transgaming.comda1ed362013-01-25 21:54:57 +000043#include "third_party/compiler/ArrayBoundsClamper.h"
Corentin Wallez28b65282016-06-16 07:24:50 -070044
Jamie Madillacb4b812016-11-07 13:50:29 -050045namespace sh
46{
47
Corentin Wallez28b65282016-06-16 07:24:50 -070048namespace
49{
50
51#if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
52void DumpFuzzerCase(char const *const *shaderStrings,
53 size_t numStrings,
54 uint32_t type,
55 uint32_t spec,
56 uint32_t output,
57 uint64_t options)
58{
59 static int fileIndex = 0;
60
61 std::ostringstream o;
62 o << "corpus/" << fileIndex++ << ".sample";
63 std::string s = o.str();
64
65 // Must match the input format of the fuzzer
66 FILE *f = fopen(s.c_str(), "w");
67 fwrite(&type, sizeof(type), 1, f);
68 fwrite(&spec, sizeof(spec), 1, f);
69 fwrite(&output, sizeof(output), 1, f);
70 fwrite(&options, sizeof(options), 1, f);
71
72 char zero[128 - 20] = {0};
73 fwrite(&zero, 128 - 20, 1, f);
74
75 for (size_t i = 0; i < numStrings; i++)
76 {
77 fwrite(shaderStrings[i], sizeof(char), strlen(shaderStrings[i]), f);
78 }
79 fwrite(&zero, 1, 1, f);
80
81 fclose(f);
82}
83#endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
84} // anonymous namespace
85
Jamie Madill5508f392014-02-20 13:31:36 -050086bool IsWebGLBasedSpec(ShShaderSpec spec)
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000087{
Qiankun Miaoc2c5fc42016-08-31 15:24:22 +080088 return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +000089}
90
Qingqing Dengad0d0792015-04-08 14:25:06 -070091bool IsGLSL130OrNewer(ShShaderOutput output)
92{
Jamie Madillacb4b812016-11-07 13:50:29 -050093 return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT ||
94 output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT ||
95 output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT ||
96 output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT ||
97 output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT);
Qingqing Dengad0d0792015-04-08 14:25:06 -070098}
99
Qiankun Miao705a9192016-08-29 10:05:27 +0800100bool IsGLSL420OrNewer(ShShaderOutput output)
101{
Jamie Madillacb4b812016-11-07 13:50:29 -0500102 return (output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT ||
103 output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT);
Qiankun Miao705a9192016-08-29 10:05:27 +0800104}
105
Zhenyao Mob7bf7422016-11-08 14:44:05 -0800106bool IsGLSL410OrOlder(ShShaderOutput output)
107{
108 return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT ||
109 output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT ||
110 output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT);
111}
112
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000113bool RemoveInvariant(sh::GLenum shaderType,
114 int shaderVersion,
115 ShShaderOutput outputType,
116 ShCompileOptions compileOptions)
117{
118 if ((compileOptions & SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT) == 0 &&
119 shaderType == GL_FRAGMENT_SHADER && IsGLSL420OrNewer(outputType))
120 return true;
121
122 if ((compileOptions & SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3) != 0 &&
Qiankun Miao41f9f672016-11-16 17:04:36 +0800123 shaderVersion >= 300 && shaderType == GL_VERTEX_SHADER)
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000124 return true;
125
126 return false;
127}
128
Zhenyao Mo7faf1a12014-04-25 18:03:56 -0700129size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
Jamie Madill88f6e942014-02-19 10:27:53 -0500130{
He Yunchao29ab9ff2015-08-06 16:58:30 +0800131 // WebGL defines a max token length of 256, while ES2 leaves max token
Jamie Madill88f6e942014-02-19 10:27:53 -0500132 // size undefined. ES3 defines a max size of 1024 characters.
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700133 switch (spec)
Jamie Madill88f6e942014-02-19 10:27:53 -0500134 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500135 case SH_WEBGL_SPEC:
136 return 256;
137 default:
138 return 1024;
Jamie Madill88f6e942014-02-19 10:27:53 -0500139 }
140}
141
Shao77891c02017-06-23 16:30:17 +0800142int GetMaxUniformVectorsForShaderType(GLenum shaderType, const ShBuiltInResources &resources)
143{
144 switch (shaderType)
145 {
146 case GL_VERTEX_SHADER:
147 return resources.MaxVertexUniformVectors;
148 case GL_FRAGMENT_SHADER:
149 return resources.MaxFragmentUniformVectors;
Shaob5cc1192017-07-06 10:47:20 +0800150
151 // TODO (jiawei.shao@intel.com): check if we need finer-grained component counting
Shao77891c02017-06-23 16:30:17 +0800152 case GL_COMPUTE_SHADER:
Shao77891c02017-06-23 16:30:17 +0800153 return resources.MaxComputeUniformComponents / 4;
Shaob5cc1192017-07-06 10:47:20 +0800154 case GL_GEOMETRY_SHADER_OES:
155 return resources.MaxGeometryUniformComponents / 4;
Shao77891c02017-06-23 16:30:17 +0800156 default:
Shaob5cc1192017-07-06 10:47:20 +0800157 UNREACHABLE();
Shao77891c02017-06-23 16:30:17 +0800158 return -1;
159 }
160}
161
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500162namespace
163{
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700164
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800165class TScopedPoolAllocator
166{
167 public:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500168 TScopedPoolAllocator(TPoolAllocator *allocator) : mAllocator(allocator)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800169 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400170 mAllocator->push();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000171 SetGlobalPoolAllocator(mAllocator);
172 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800173 ~TScopedPoolAllocator()
174 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800175 SetGlobalPoolAllocator(nullptr);
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400176 mAllocator->pop();
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000177 }
178
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800179 private:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500180 TPoolAllocator *mAllocator;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400181};
182
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800183class TScopedSymbolTableLevel
184{
185 public:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500186 TScopedSymbolTableLevel(TSymbolTable *table) : mTable(table)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800187 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400188 ASSERT(mTable->atBuiltInLevel());
189 mTable->push();
190 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800191 ~TScopedSymbolTableLevel()
192 {
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400193 while (!mTable->atBuiltInLevel())
194 mTable->pop();
195 }
196
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800197 private:
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500198 TSymbolTable *mTable;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000199};
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700200
201int MapSpecToShaderVersion(ShShaderSpec spec)
202{
203 switch (spec)
204 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500205 case SH_GLES2_SPEC:
206 case SH_WEBGL_SPEC:
207 return 100;
208 case SH_GLES3_SPEC:
209 case SH_WEBGL2_SPEC:
210 return 300;
211 case SH_GLES3_1_SPEC:
212 case SH_WEBGL3_SPEC:
213 return 310;
214 default:
215 UNREACHABLE();
216 return 0;
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700217 }
218}
219
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000220} // namespace
221
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800222TShHandleBase::TShHandleBase()
223{
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000224 allocator.push();
225 SetGlobalPoolAllocator(&allocator);
226}
227
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800228TShHandleBase::~TShHandleBase()
229{
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800230 SetGlobalPoolAllocator(nullptr);
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000231 allocator.popAll();
232}
233
Jamie Madill183bde52014-07-02 15:31:19 -0400234TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700235 : variablesCollected(false),
Olli Etuahob12040c2017-06-27 14:20:45 +0300236 mGLPositionInitialized(false),
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700237 shaderType(type),
zmo@google.comf420c422011-09-12 18:27:59 +0000238 shaderSpec(spec),
Jamie Madill68fe74a2014-05-27 12:56:01 -0400239 outputType(output),
Jamie Madilleb1a0102013-07-08 13:31:38 -0400240 maxUniformVectors(0),
241 maxExpressionComplexity(0),
242 maxCallStackDepth(0),
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200243 maxFunctionParameters(0),
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000244 fragmentPrecisionHigh(false),
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000245 clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC),
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200246 builtInFunctionEmulator(),
Olli Etuaho77ba4082016-12-16 12:01:18 +0000247 mDiagnostics(infoSink.info),
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800248 mSourcePath(nullptr),
Shaob5cc1192017-07-06 10:47:20 +0800249 mComputeShaderLocalSizeDeclared(false),
250 mGeometryShaderMaxVertices(-1),
251 mGeometryShaderInvocations(0),
252 mGeometryShaderInputPrimitiveType(EptUndefined),
253 mGeometryShaderOutputPrimitiveType(EptUndefined)
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000254{
Martin Radev802abe02016-08-04 17:48:32 +0300255 mComputeShaderLocalSize.fill(1);
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000256}
257
258TCompiler::~TCompiler()
259{
260}
261
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800262bool TCompiler::shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptions) const
Olli Etuaho5d91dda2015-06-18 15:47:46 +0300263{
264 // If compiling an ESSL 1.00 shader for WebGL, or if its been requested through the API,
265 // validate loop and indexing as well (to verify that the shader only uses minimal functionality
266 // of ESSL 1.00 as in Appendix A of the spec).
267 return (IsWebGLBasedSpec(shaderSpec) && shaderVersion == 100) ||
268 (compileOptions & SH_VALIDATE_LOOP_INDEXING);
269}
270
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500271bool TCompiler::Init(const ShBuiltInResources &resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000272{
Shao77891c02017-06-23 16:30:17 +0800273 shaderVersion = 100;
274
275 maxUniformVectors = GetMaxUniformVectorsForShaderType(shaderType, resources);
276
Jamie Madilleb1a0102013-07-08 13:31:38 -0400277 maxExpressionComplexity = resources.MaxExpressionComplexity;
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200278 maxCallStackDepth = resources.MaxCallStackDepth;
279 maxFunctionParameters = resources.MaxFunctionParameters;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400280
281 SetGlobalPoolAllocator(&allocator);
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000282
alokp@chromium.org07620a52010-09-23 17:53:56 +0000283 // Generate built-in symbol table.
284 if (!InitBuiltInSymbolTable(resources))
285 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000286 InitExtensionBehavior(resources, extensionBehavior);
shannon.woods%transgaming.com@gtempaccount.comcbb6b6a2013-04-13 03:27:47 +0000287 fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
alokp@chromium.orgbafcbaa2010-11-23 19:07:43 +0000288
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000289 arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy);
290 clampingStrategy = resources.ArrayIndexClampingStrategy;
291
daniel@transgaming.comc23f4612012-11-28 19:42:57 +0000292 hashFunction = resources.HashFunction;
293
alokp@chromium.org07620a52010-09-23 17:53:56 +0000294 return true;
295}
296
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100297TIntermBlock *TCompiler::compileTreeForTesting(const char *const shaderStrings[],
298 size_t numStrings,
299 ShCompileOptions compileOptions)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000300{
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200301 return compileTreeImpl(shaderStrings, numStrings, compileOptions);
302}
303
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100304TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
305 size_t numStrings,
306 const ShCompileOptions compileOptions)
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200307{
alokp@chromium.org07620a52010-09-23 17:53:56 +0000308 clearResults();
309
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200310 ASSERT(numStrings > 0);
311 ASSERT(GetGlobalPoolAllocator());
alokp@chromium.org07620a52010-09-23 17:53:56 +0000312
David Yen0fbd1282015-02-02 14:46:09 -0800313 // Reset the extension behavior for each compilation unit.
314 ResetExtensionBehavior(extensionBehavior);
315
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000316 // First string is path of source file if flag is set. The actual source follows.
shannon.woods@transgaming.comd64b3da2013-02-28 23:19:26 +0000317 size_t firstSource = 0;
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000318 if (compileOptions & SH_SOURCE_PATH)
319 {
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200320 mSourcePath = shaderStrings[0];
apatrick@chromium.org0f4cefe2011-01-26 19:30:57 +0000321 ++firstSource;
322 }
323
Olli Etuahof119a262016-08-19 15:54:22 +0300324 TParseContext parseContext(symbolTable, extensionBehavior, shaderType, shaderSpec,
Olli Etuaho77ba4082016-12-16 12:01:18 +0000325 compileOptions, true, &mDiagnostics, getResources());
Olli Etuaho853dc1a2014-11-06 17:25:48 +0200326
Olli Etuahoa6996682015-10-12 14:32:30 +0300327 parseContext.setFragmentPrecisionHighOnESSL1(fragmentPrecisionHigh);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000328
329 // We preserve symbols at the built-in level from compile-to-compile.
330 // Start pushing the user-defined symbols at global level.
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400331 TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000332
333 // Parse shader.
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500334 bool success = (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr,
335 &parseContext) == 0) &&
336 (parseContext.getTreeRoot() != nullptr);
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000337
shannon.woods%transgaming.com@gtempaccount.com5524db02013-04-13 03:38:16 +0000338 shaderVersion = parseContext.getShaderVersion();
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700339 if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion)
340 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000341 mDiagnostics.globalError("unsupported shader version");
Zhenyao Modb9b40b2014-10-29 15:00:04 -0700342 success = false;
343 }
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +0000344
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100345 TIntermBlock *root = nullptr;
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200346
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800347 if (success)
348 {
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700349 mPragma = parseContext.pragma();
Kenneth Russell8bad46d2016-07-01 19:52:52 -0700350 symbolTable.setGlobalInvariant(mPragma.stdgl.invariantAll);
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700351
Martin Radev802abe02016-08-04 17:48:32 +0300352 mComputeShaderLocalSizeDeclared = parseContext.isComputeShaderLocalSizeDeclared();
353 mComputeShaderLocalSize = parseContext.getComputeShaderLocalSize();
354
Olli Etuaho09b04a22016-12-15 13:30:26 +0000355 mNumViews = parseContext.getNumViews();
356
Jamie Madill6e06b1f2015-05-14 10:01:17 -0400357 root = parseContext.getTreeRoot();
alokp@chromium.orgb59a7782010-11-24 18:38:33 +0000358
Olli Etuahoa6996682015-10-12 14:32:30 +0300359 // Highp might have been auto-enabled based on shader version
360 fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh();
361
Olli Etuaho09b04a22016-12-15 13:30:26 +0000362 if (success && (IsWebGLBasedSpec(shaderSpec) &&
363 IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview") &&
364 IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview2")))
365 {
366 // Can't enable both extensions at the same time.
367 mDiagnostics.globalError("Can't enable both OVR_multiview and OVR_multiview2");
368 success = false;
369 }
370
Shaob5cc1192017-07-06 10:47:20 +0800371 if (success && shaderType == GL_GEOMETRY_SHADER_OES)
372 {
373 mGeometryShaderInputPrimitiveType = parseContext.getGeometryShaderInputPrimitiveType();
374 mGeometryShaderOutputPrimitiveType =
375 parseContext.getGeometryShaderOutputPrimitiveType();
376 mGeometryShaderMaxVertices = parseContext.getGeometryShaderMaxVertices();
377 mGeometryShaderInvocations = parseContext.getGeometryShaderInvocations();
378 }
379
Jamie Madill6654bc92014-03-26 14:01:57 -0400380 // Disallow expressions deemed too complex.
381 if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY))
382 success = limitExpressionComplexity(root);
383
Corentin Wallez71d147f2015-02-11 11:15:24 -0800384 // Create the function DAG and check there is no recursion
zmo@google.comb1762df2011-07-30 02:04:23 +0000385 if (success)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800386 success = initCallDag(root);
387
388 if (success && (compileOptions & SH_LIMIT_CALL_STACK_DEPTH))
389 success = checkCallDepth();
390
391 // Checks which functions are used and if "main" exists
392 if (success)
393 {
394 functionMetadata.clear();
395 functionMetadata.resize(mCallDag.size());
396 success = tagUsedFunctions();
397 }
zmo@google.comb1762df2011-07-30 02:04:23 +0000398
Corentin Walleza094a8a2015-04-07 11:53:06 -0700399 if (success && !(compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS))
400 success = pruneUnusedFunctions(root);
401
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500402 // Prune empty declarations to work around driver bugs and to keep declaration output
403 // simple.
Olli Etuahoc6833112015-04-22 15:15:54 +0300404 if (success)
405 PruneEmptyDeclarations(root);
406
Andrei Volykhin73fa4b82017-05-05 18:45:06 +0300407 if (success && shaderVersion >= 300 && shaderType == GL_FRAGMENT_SHADER)
Olli Etuaho12b0b392017-05-30 13:22:31 +0300408 {
409 success = ValidateOutputs(root, getExtensionBehavior(), compileResources.MaxDrawBuffers,
410 &mDiagnostics);
411 }
Jamie Madill05a80ce2013-06-20 11:55:49 -0400412
Olli Etuaho5d91dda2015-06-18 15:47:46 +0300413 if (success && shouldRunLoopAndIndexingValidation(compileOptions))
Olli Etuaho9ec79392017-03-31 23:04:23 +0300414 success =
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300415 ValidateLimitations(root, shaderType, &symbolTable, shaderVersion, &mDiagnostics);
alokp@chromium.org07620a52010-09-23 17:53:56 +0000416
Olli Etuaho09b04a22016-12-15 13:30:26 +0000417 bool multiview2 = IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview2");
418 if (success && compileResources.OVR_multiview && IsWebGLBasedSpec(shaderSpec) &&
419 (IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview") || multiview2))
Olli Etuaho01d0ad02017-01-22 14:51:23 -0800420 success = ValidateMultiviewWebGL(root, shaderType, symbolTable, shaderVersion,
421 multiview2, &mDiagnostics);
Olli Etuaho09b04a22016-12-15 13:30:26 +0000422
Jamie Madilld5696192016-10-06 11:09:24 -0400423 // Fail compilation if precision emulation not supported.
424 if (success && getResources().WEBGL_debug_shader_precision &&
425 getPragma().debugShaderPrecision)
426 {
427 if (!EmulatePrecision::SupportedInLanguage(outputType))
428 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000429 mDiagnostics.globalError("Precision emulation not supported for this output type.");
Jamie Madilld5696192016-10-06 11:09:24 -0400430 success = false;
431 }
432 }
433
zmo@google.com32e97312011-08-24 01:03:11 +0000434 // Built-in function emulation needs to happen after validateLimitations pass.
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200435 if (success)
436 {
Jamie Madill438dbcf2016-06-17 14:20:05 -0400437 // TODO(jmadill): Remove global pool allocator.
438 GetGlobalPoolAllocator()->lock();
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200439 initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions);
Jamie Madill438dbcf2016-06-17 14:20:05 -0400440 GetGlobalPoolAllocator()->unlock();
Olli Etuahodfa75e82017-01-23 09:43:06 -0800441 builtInFunctionEmulator.markBuiltInFunctionsForEmulation(root);
Olli Etuaho8efc5ad2015-03-03 17:21:10 +0200442 }
zmo@google.com32e97312011-08-24 01:03:11 +0000443
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000444 // Clamping uniform array bounds needs to happen after validateLimitations pass.
445 if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS))
446 arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root);
447
Martin Radev69056a12017-05-18 11:14:50 +0300448 if (success && (compileOptions & SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW) &&
Martin Radev7ef89a42017-07-05 14:23:06 +0300449 parseContext.isMultiviewExtensionEnabled() && getShaderType() != GL_COMPUTE_SHADER)
Martin Radev69056a12017-05-18 11:14:50 +0300450 {
Martin Radevc39a19a2017-07-07 18:52:09 +0300451 DeclareAndInitBuiltinsForInstancedMultiview(root, mNumViews, shaderType, compileOptions,
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300452 outputType, &symbolTable);
Martin Radev69056a12017-05-18 11:14:50 +0300453 }
454
Corentin Wallezd4b50542015-09-28 12:19:26 -0700455 // This pass might emit short circuits so keep it before the short circuit unfolding
456 if (success && (compileOptions & SH_REWRITE_DO_WHILE_LOOPS))
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300457 RewriteDoWhile(root, &symbolTable);
Corentin Wallezd4b50542015-09-28 12:19:26 -0700458
Qiankun Miao09cfac62016-09-06 17:25:16 +0800459 if (success && (compileOptions & SH_ADD_AND_TRUE_TO_LOOP_CONDITION))
460 sh::AddAndTrueToLoopCondition(root);
461
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800462 if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT))
463 {
Zhenyao Mo7cab38b2013-10-15 12:59:30 -0700464 UnfoldShortCircuitAST unfoldShortCircuit;
465 root->traverse(&unfoldShortCircuit);
466 unfoldShortCircuit.updateTree();
467 }
468
Olli Etuaho5c407bb2015-06-01 12:20:39 +0300469 if (success && (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT))
470 {
471 RemovePow(root);
472 }
473
Olli Etuaho4dfe8092015-08-21 17:44:35 +0300474 if (success && shouldCollectVariables(compileOptions))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800475 {
Olli Etuaho19515012017-06-26 18:00:17 +0300476 ASSERT(!variablesCollected);
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +0800477 CollectVariables(root, &attributes, &outputVariables, &uniforms, &inputVaryings,
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800478 &outputVaryings, &uniformBlocks, &shaderStorageBlocks, hashFunction,
479 &symbolTable, shaderVersion, extensionBehavior);
480 collectInterfaceBlocks();
Olli Etuaho19515012017-06-26 18:00:17 +0300481 variablesCollected = true;
Qin Jiajia7835b522016-10-08 11:20:17 +0800482 if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS)
483 {
484 useAllMembersInUnusedStandardAndSharedBlocks(root);
485 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800486 if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS)
487 {
Olli Etuaho19515012017-06-26 18:00:17 +0300488 // Returns true if, after applying the packing rules in the GLSL ES 1.00.17 spec
489 // Appendix A, section 7, the shader does not use too many uniforms.
Olli Etuahod7487b12017-08-09 15:45:13 +0300490 success = CheckVariablesInPackingLimits(maxUniformVectors, uniforms);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800491 if (!success)
492 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000493 mDiagnostics.globalError("too many uniforms");
gman@chromium.org8d804792012-10-17 21:33:48 +0000494 }
495 }
Zhenyao Mo72111912016-07-20 17:45:56 -0700496 if (success && (compileOptions & SH_INIT_OUTPUT_VARIABLES))
497 {
Olli Etuaho27776e32016-07-22 14:00:56 +0300498 initializeOutputVariables(root);
Zhenyao Mo72111912016-07-20 17:45:56 -0700499 }
gman@chromium.org8d804792012-10-17 21:33:48 +0000500 }
zmo@google.comfd747b82011-04-23 01:30:07 +0000501
Olli Etuahob12040c2017-06-27 14:20:45 +0300502 // gl_Position is always written in compatibility output mode.
503 // It may have been already initialized among other output variables, in that case we don't
504 // need to initialize it twice.
505 if (success && shaderType == GL_VERTEX_SHADER && !mGLPositionInitialized &&
506 ((compileOptions & SH_INIT_GL_POSITION) ||
507 (outputType == SH_GLSL_COMPATIBILITY_OUTPUT)))
508 {
509 initializeGLPosition(root);
510 mGLPositionInitialized = true;
511 }
512
Yuly Novikov817232e2017-02-22 18:36:10 -0500513 // Removing invariant declarations must be done after collecting variables.
514 // Otherwise, built-in invariant declarations don't apply.
515 if (success && RemoveInvariant(shaderType, shaderVersion, outputType, compileOptions))
516 sh::RemoveInvariantDeclaration(root);
517
Zhenyao Mocd68fe72014-07-11 10:45:44 -0700518 if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS))
519 {
Olli Etuahob990b552016-10-27 12:29:17 +0100520 ScalarizeVecAndMatConstructorArgs(root, shaderType, fragmentPrecisionHigh,
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300521 &symbolTable);
Zhenyao Mocd68fe72014-07-11 10:45:44 -0700522 }
523
Zhenyao Moe740add2014-07-18 17:01:01 -0700524 if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES))
525 {
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300526 RegenerateStructNames gen(&symbolTable, shaderVersion);
Zhenyao Moe740add2014-07-18 17:01:01 -0700527 root->traverse(&gen);
528 }
Olli Etuaho3d932d82016-04-12 11:10:30 +0300529
Zhenyao Mo4e94fea2016-08-09 14:31:37 -0700530 if (success && shaderType == GL_FRAGMENT_SHADER && shaderVersion == 100 &&
531 compileResources.EXT_draw_buffers && compileResources.MaxDrawBuffers > 1 &&
532 IsExtensionEnabled(extensionBehavior, "GL_EXT_draw_buffers"))
533 {
Olli Etuahodaaff1c2017-07-05 18:03:26 +0300534 EmulateGLFragColorBroadcast(root, compileResources.MaxDrawBuffers, &outputVariables,
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300535 &symbolTable, shaderVersion);
Zhenyao Mo4e94fea2016-08-09 14:31:37 -0700536 }
537
Olli Etuaho3d932d82016-04-12 11:10:30 +0300538 if (success)
539 {
Olli Etuaho0ffc4412017-05-19 14:18:55 +0300540 DeferGlobalInitializers(root, needToInitializeGlobalsInAST());
Olli Etuaho3d932d82016-04-12 11:10:30 +0300541 }
Olli Etuaho9733cee2017-05-11 19:14:35 +0300542
543 if (success && (compileOptions & SH_INITIALIZE_UNINITIALIZED_LOCALS) && getOutputType())
544 {
545 // Initialize uninitialized local variables.
546 // In some cases initializing can generate extra statements in the parent block, such as
547 // when initializing nameless structs or initializing arrays in ESSL 1.00. In that case
548 // we need to first simplify loop conditions and separate declarations. If we don't
549 // follow the Appendix A limitations, loop init statements can declare arrays or
550 // nameless structs and have multiple declarations.
551
552 if (!shouldRunLoopAndIndexingValidation(compileOptions))
553 {
554 SimplifyLoopConditions(root,
555 IntermNodePatternMatcher::kMultiDeclaration |
556 IntermNodePatternMatcher::kArrayDeclaration |
557 IntermNodePatternMatcher::kNamelessStructDeclaration,
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300558 &getSymbolTable(), getShaderVersion());
Olli Etuaho9733cee2017-05-11 19:14:35 +0300559 }
560 // We only really need to separate array declarations and nameless struct declarations,
561 // but it's simpler to just use the regular SeparateDeclarations.
562 SeparateDeclarations(root);
563 InitializeUninitializedLocals(root, getShaderVersion());
564 }
Olli Etuahoab918822017-07-14 17:03:42 +0300565
566 if (success && getShaderType() == GL_VERTEX_SHADER &&
567 (compileOptions & SH_CLAMP_POINT_SIZE))
568 {
569 ClampPointSize(root, compileResources.MaxPointSize, &getSymbolTable());
570 }
alokp@chromium.org07620a52010-09-23 17:53:56 +0000571 }
572
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200573 if (success)
574 return root;
575
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800576 return nullptr;
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200577}
578
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800579bool TCompiler::compile(const char *const shaderStrings[],
580 size_t numStrings,
581 ShCompileOptions compileOptionsIn)
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200582{
Corentin Wallez28b65282016-06-16 07:24:50 -0700583#if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
584 DumpFuzzerCase(shaderStrings, numStrings, shaderType, shaderSpec, outputType, compileOptionsIn);
585#endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT)
586
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200587 if (numStrings == 0)
588 return true;
589
Qiankun Miao7ebb97f2016-09-08 18:01:50 +0800590 ShCompileOptions compileOptions = compileOptionsIn;
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700591
592 // Apply key workarounds.
593 if (shouldFlattenPragmaStdglInvariantAll())
594 {
595 // This should be harmless to do in all cases, but for the moment, do it only conditionally.
596 compileOptions |= SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL;
597 }
598
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200599 TScopedPoolAllocator scopedAlloc(&allocator);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100600 TIntermBlock *root = compileTreeImpl(shaderStrings, numStrings, compileOptions);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200601
602 if (root)
603 {
604 if (compileOptions & SH_INTERMEDIATE_TREE)
Olli Etuahocccf2b02017-07-05 14:50:54 +0300605 OutputTree(root, infoSink.info);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200606
607 if (compileOptions & SH_OBJECT_CODE)
608 translate(root, compileOptions);
609
610 // The IntermNode tree doesn't need to be deleted here, since the
611 // memory will be freed in a big chunk by the PoolAllocator.
612 return true;
613 }
614 return false;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000615}
616
Nicolas Capens49a88872013-06-20 09:54:03 -0400617bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
alokp@chromium.org07620a52010-09-23 17:53:56 +0000618{
Olli Etuaho28cb0362016-11-22 15:42:37 +0000619 if (resources.MaxDrawBuffers < 1)
620 {
621 return false;
622 }
623 if (resources.EXT_blend_func_extended && resources.MaxDualSourceDrawBuffers < 1)
624 {
625 return false;
626 }
627
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +0000628 compileResources = resources;
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400629 setResourceString();
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000630
Nicolas Capens49a88872013-06-20 09:54:03 -0400631 assert(symbolTable.isEmpty());
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500632 symbolTable.push(); // COMMON_BUILTINS
633 symbolTable.push(); // ESSL1_BUILTINS
634 symbolTable.push(); // ESSL3_BUILTINS
635 symbolTable.push(); // ESSL3_1_BUILTINS
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000636
Jamie Madillacb4b812016-11-07 13:50:29 -0500637 switch (shaderType)
Nicolas Capens49a88872013-06-20 09:54:03 -0400638 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500639 case GL_FRAGMENT_SHADER:
Olli Etuahocce89652017-06-19 16:04:09 +0300640 symbolTable.setDefaultPrecision(EbtInt, EbpMedium);
Jamie Madillacb4b812016-11-07 13:50:29 -0500641 break;
642 case GL_VERTEX_SHADER:
Jamie Madillacb4b812016-11-07 13:50:29 -0500643 case GL_COMPUTE_SHADER:
Shaob5cc1192017-07-06 10:47:20 +0800644 case GL_GEOMETRY_SHADER_OES:
Olli Etuahocce89652017-06-19 16:04:09 +0300645 symbolTable.setDefaultPrecision(EbtInt, EbpHigh);
646 symbolTable.setDefaultPrecision(EbtFloat, EbpHigh);
Jamie Madillacb4b812016-11-07 13:50:29 -0500647 break;
648 default:
Shaob5cc1192017-07-06 10:47:20 +0800649 UNREACHABLE();
Nicolas Capens49a88872013-06-20 09:54:03 -0400650 }
Olli Etuaho183d7e22015-11-20 15:59:09 +0200651 // Set defaults for sampler types that have default precision, even those that are
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400652 // only available if an extension exists.
Olli Etuaho183d7e22015-11-20 15:59:09 +0200653 // New sampler types in ESSL3 don't have default precision. ESSL1 types do.
654 initSamplerDefaultPrecision(EbtSampler2D);
655 initSamplerDefaultPrecision(EbtSamplerCube);
656 // SamplerExternalOES is specified in the extension to have default precision.
657 initSamplerDefaultPrecision(EbtSamplerExternalOES);
Andrei Volykhina5527072017-03-22 16:46:30 +0300658 // SamplerExternal2DY2YEXT is specified in the extension to have default precision.
659 initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT);
Olli Etuaho183d7e22015-11-20 15:59:09 +0200660 // It isn't specified whether Sampler2DRect has default precision.
661 initSamplerDefaultPrecision(EbtSampler2DRect);
Nicolas Capens49a88872013-06-20 09:54:03 -0400662
Olli Etuahocce89652017-06-19 16:04:09 +0300663 symbolTable.setDefaultPrecision(EbtAtomicCounter, EbpHigh);
jchen104cdac9e2017-05-08 11:01:20 +0800664
Jamie Madill1b452142013-07-12 14:51:11 -0400665 InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
Nicolas Capens49a88872013-06-20 09:54:03 -0400666
667 IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
668
669 return true;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000670}
671
Olli Etuaho183d7e22015-11-20 15:59:09 +0200672void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
673{
674 ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
Olli Etuahocce89652017-06-19 16:04:09 +0300675 symbolTable.setDefaultPrecision(samplerType, EbpLow);
Olli Etuaho183d7e22015-11-20 15:59:09 +0200676}
677
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400678void TCompiler::setResourceString()
679{
680 std::ostringstream strstream;
Geoff Langb66a9092016-05-16 15:59:14 -0400681
682 // clang-format off
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400683 strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs
Jamie Madillacb4b812016-11-07 13:50:29 -0500684 << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors
685 << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors
686 << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits
687 << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits
688 << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits
689 << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors
690 << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers
691 << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives
692 << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external
693 << ":OES_EGL_image_external_essl3:" << compileResources.OES_EGL_image_external_essl3
694 << ":NV_EGL_stream_consumer_external:" << compileResources.NV_EGL_stream_consumer_external
695 << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle
696 << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers
697 << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh
698 << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity
699 << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth
700 << ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters
701 << ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended
702 << ":EXT_frag_depth:" << compileResources.EXT_frag_depth
703 << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod
704 << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch
705 << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch
706 << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch
Martin Radev318f9aa2017-05-17 17:47:28 +0300707 << ":OVR_multiview:" << compileResources.OVR_multiview
Andrei Volykhina5527072017-03-22 16:46:30 +0300708 << ":EXT_YUV_target:" << compileResources.EXT_YUV_target
Shaob5cc1192017-07-06 10:47:20 +0800709 << ":OES_geometry_shader:" << compileResources.OES_geometry_shader
Jamie Madillacb4b812016-11-07 13:50:29 -0500710 << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
711 << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
712 << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
713 << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset
714 << ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers
Martin Radev318f9aa2017-05-17 17:47:28 +0300715 << ":MaxViewsOVR:" << compileResources.MaxViewsOVR
Jamie Madillacb4b812016-11-07 13:50:29 -0500716 << ":NV_draw_buffers:" << compileResources.NV_draw_buffers
717 << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision
718 << ":MaxImageUnits:" << compileResources.MaxImageUnits
719 << ":MaxVertexImageUniforms:" << compileResources.MaxVertexImageUniforms
720 << ":MaxFragmentImageUniforms:" << compileResources.MaxFragmentImageUniforms
721 << ":MaxComputeImageUniforms:" << compileResources.MaxComputeImageUniforms
722 << ":MaxCombinedImageUniforms:" << compileResources.MaxCombinedImageUniforms
723 << ":MaxCombinedShaderOutputResources:" << compileResources.MaxCombinedShaderOutputResources
724 << ":MaxComputeWorkGroupCountX:" << compileResources.MaxComputeWorkGroupCount[0]
725 << ":MaxComputeWorkGroupCountY:" << compileResources.MaxComputeWorkGroupCount[1]
726 << ":MaxComputeWorkGroupCountZ:" << compileResources.MaxComputeWorkGroupCount[2]
727 << ":MaxComputeWorkGroupSizeX:" << compileResources.MaxComputeWorkGroupSize[0]
728 << ":MaxComputeWorkGroupSizeY:" << compileResources.MaxComputeWorkGroupSize[1]
729 << ":MaxComputeWorkGroupSizeZ:" << compileResources.MaxComputeWorkGroupSize[2]
730 << ":MaxComputeUniformComponents:" << compileResources.MaxComputeUniformComponents
731 << ":MaxComputeTextureImageUnits:" << compileResources.MaxComputeTextureImageUnits
732 << ":MaxComputeAtomicCounters:" << compileResources.MaxComputeAtomicCounters
733 << ":MaxComputeAtomicCounterBuffers:" << compileResources.MaxComputeAtomicCounterBuffers
734 << ":MaxVertexAtomicCounters:" << compileResources.MaxVertexAtomicCounters
735 << ":MaxFragmentAtomicCounters:" << compileResources.MaxFragmentAtomicCounters
736 << ":MaxCombinedAtomicCounters:" << compileResources.MaxCombinedAtomicCounters
737 << ":MaxAtomicCounterBindings:" << compileResources.MaxAtomicCounterBindings
738 << ":MaxVertexAtomicCounterBuffers:" << compileResources.MaxVertexAtomicCounterBuffers
739 << ":MaxFragmentAtomicCounterBuffers:" << compileResources.MaxFragmentAtomicCounterBuffers
740 << ":MaxCombinedAtomicCounterBuffers:" << compileResources.MaxCombinedAtomicCounterBuffers
Shaob5cc1192017-07-06 10:47:20 +0800741 << ":MaxAtomicCounterBufferSize:" << compileResources.MaxAtomicCounterBufferSize
742 << ":MaxGeometryOutputVertices:" << compileResources.MaxGeometryOutputVertices
743 << ":MaxGeometryUniformComponents:" << compileResources.MaxGeometryUniformComponents
744 << ":MaxGeometryShaderInvocations:" << compileResources.MaxGeometryShaderInvocations;
Geoff Langb66a9092016-05-16 15:59:14 -0400745 // clang-format on
Shannon Woods2d76e5f2014-05-16 17:46:41 -0400746
747 builtInResourcesString = strstream.str();
748}
749
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800750void TCompiler::collectInterfaceBlocks()
751{
752 ASSERT(interfaceBlocks.empty());
753 interfaceBlocks.reserve(uniformBlocks.size() + shaderStorageBlocks.size());
754 interfaceBlocks.insert(interfaceBlocks.end(), uniformBlocks.begin(), uniformBlocks.end());
755 interfaceBlocks.insert(interfaceBlocks.end(), shaderStorageBlocks.begin(),
756 shaderStorageBlocks.end());
757}
758
alokp@chromium.org07620a52010-09-23 17:53:56 +0000759void TCompiler::clearResults()
760{
daniel@transgaming.com4167cc92013-01-11 04:11:53 +0000761 arrayBoundsClamper.Cleanup();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000762 infoSink.info.erase();
763 infoSink.obj.erase();
764 infoSink.debug.erase();
Olli Etuaho77ba4082016-12-16 12:01:18 +0000765 mDiagnostics.resetErrorCount();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000766
Jamie Madilled27c722014-07-02 15:31:23 -0400767 attributes.clear();
768 outputVariables.clear();
alokp@chromium.org07620a52010-09-23 17:53:56 +0000769 uniforms.clear();
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +0800770 inputVaryings.clear();
771 outputVaryings.clear();
Jamie Madilled27c722014-07-02 15:31:23 -0400772 interfaceBlocks.clear();
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800773 uniformBlocks.clear();
774 shaderStorageBlocks.clear();
Kenneth Russellbccc65d2016-07-19 16:48:43 -0700775 variablesCollected = false;
Olli Etuahob12040c2017-06-27 14:20:45 +0300776 mGLPositionInitialized = false;
zmo@google.coma3b4ab42011-09-16 00:53:26 +0000777
Olli Etuaho09b04a22016-12-15 13:30:26 +0000778 mNumViews = -1;
779
Shaob5cc1192017-07-06 10:47:20 +0800780 mGeometryShaderInputPrimitiveType = EptUndefined;
781 mGeometryShaderOutputPrimitiveType = EptUndefined;
782 mGeometryShaderInvocations = 0;
783 mGeometryShaderMaxVertices = -1;
784
Olli Etuahodfa75e82017-01-23 09:43:06 -0800785 builtInFunctionEmulator.cleanup();
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +0000786
787 nameMap.clear();
Olli Etuahoa3a5cc62015-02-13 13:12:22 +0200788
Yunchao Hed7297bf2017-04-19 15:27:10 +0800789 mSourcePath = nullptr;
alokp@chromium.org07620a52010-09-23 17:53:56 +0000790}
791
Corentin Wallez71d147f2015-02-11 11:15:24 -0800792bool TCompiler::initCallDag(TIntermNode *root)
zmo@google.comb1762df2011-07-30 02:04:23 +0000793{
Corentin Wallez71d147f2015-02-11 11:15:24 -0800794 mCallDag.clear();
795
Olli Etuaho77ba4082016-12-16 12:01:18 +0000796 switch (mCallDag.init(root, &mDiagnostics))
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800797 {
Jamie Madillacb4b812016-11-07 13:50:29 -0500798 case CallDAG::INITDAG_SUCCESS:
799 return true;
800 case CallDAG::INITDAG_RECURSION:
Jamie Madillacb4b812016-11-07 13:50:29 -0500801 case CallDAG::INITDAG_UNDEFINED:
Olli Etuaho77ba4082016-12-16 12:01:18 +0000802 // Error message has already been written out.
803 ASSERT(mDiagnostics.numErrors() > 0);
Jamie Madillacb4b812016-11-07 13:50:29 -0500804 return false;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800805 }
806
807 UNREACHABLE();
808 return true;
809}
810
811bool TCompiler::checkCallDepth()
812{
813 std::vector<int> depths(mCallDag.size());
814
815 for (size_t i = 0; i < mCallDag.size(); i++)
816 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500817 int depth = 0;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800818 auto &record = mCallDag.getRecordFromIndex(i);
819
820 for (auto &calleeIndex : record.callees)
821 {
822 depth = std::max(depth, depths[calleeIndex] + 1);
823 }
824
825 depths[i] = depth;
826
827 if (depth >= maxCallStackDepth)
828 {
829 // Trace back the function chain to have a meaningful info log.
Olli Etuaho77ba4082016-12-16 12:01:18 +0000830 std::stringstream errorStream;
831 errorStream << "Call stack too deep (larger than " << maxCallStackDepth
832 << ") with the following call chain: " << record.name;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800833
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700834 int currentFunction = static_cast<int>(i);
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500835 int currentDepth = depth;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800836
837 while (currentFunction != -1)
838 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000839 errorStream << " -> " << mCallDag.getRecordFromIndex(currentFunction).name;
Corentin Wallez71d147f2015-02-11 11:15:24 -0800840
841 int nextFunction = -1;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500842 for (auto &calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800843 {
844 if (depths[calleeIndex] == currentDepth - 1)
845 {
846 currentDepth--;
847 nextFunction = calleeIndex;
848 }
849 }
850
851 currentFunction = nextFunction;
852 }
853
Olli Etuaho77ba4082016-12-16 12:01:18 +0000854 std::string errorStr = errorStream.str();
855 mDiagnostics.globalError(errorStr.c_str());
856
Corentin Wallez71d147f2015-02-11 11:15:24 -0800857 return false;
858 }
859 }
860
861 return true;
862}
863
864bool TCompiler::tagUsedFunctions()
865{
866 // Search from main, starting from the end of the DAG as it usually is the root.
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700867 for (size_t i = mCallDag.size(); i-- > 0;)
Corentin Wallez71d147f2015-02-11 11:15:24 -0800868 {
Olli Etuahoec9232b2017-03-27 17:01:37 +0300869 if (mCallDag.getRecordFromIndex(i).name == "main")
Corentin Wallez71d147f2015-02-11 11:15:24 -0800870 {
871 internalTagUsedFunction(i);
872 return true;
873 }
874 }
875
Olli Etuaho77ba4082016-12-16 12:01:18 +0000876 mDiagnostics.globalError("Missing main()");
Corentin Wallez71d147f2015-02-11 11:15:24 -0800877 return false;
878}
879
880void TCompiler::internalTagUsedFunction(size_t index)
881{
882 if (functionMetadata[index].used)
883 {
884 return;
885 }
886
887 functionMetadata[index].used = true;
888
889 for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees)
890 {
891 internalTagUsedFunction(calleeIndex);
zmo@google.comb1762df2011-07-30 02:04:23 +0000892 }
893}
894
Corentin Walleza094a8a2015-04-07 11:53:06 -0700895// A predicate for the stl that returns if a top-level node is unused
896class TCompiler::UnusedPredicate
897{
898 public:
899 UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas)
Jamie Madillacb4b812016-11-07 13:50:29 -0500900 : mCallDag(callDag), mMetadatas(metadatas)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700901 {
902 }
903
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500904 bool operator()(TIntermNode *node)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700905 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000906 const TIntermFunctionPrototype *asFunctionPrototype = node->getAsFunctionPrototypeNode();
907 const TIntermFunctionDefinition *asFunctionDefinition = node->getAsFunctionDefinition();
Corentin Walleza094a8a2015-04-07 11:53:06 -0700908
Olli Etuaho336b1472016-10-05 16:37:55 +0100909 const TFunctionSymbolInfo *functionInfo = nullptr;
910
Olli Etuaho16c745a2017-01-16 17:02:27 +0000911 if (asFunctionDefinition)
Olli Etuaho336b1472016-10-05 16:37:55 +0100912 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000913 functionInfo = asFunctionDefinition->getFunctionSymbolInfo();
Olli Etuaho336b1472016-10-05 16:37:55 +0100914 }
Olli Etuaho16c745a2017-01-16 17:02:27 +0000915 else if (asFunctionPrototype)
Olli Etuaho336b1472016-10-05 16:37:55 +0100916 {
Olli Etuaho16c745a2017-01-16 17:02:27 +0000917 functionInfo = asFunctionPrototype->getFunctionSymbolInfo();
Olli Etuaho336b1472016-10-05 16:37:55 +0100918 }
919 if (functionInfo == nullptr)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700920 {
921 return false;
922 }
923
Olli Etuaho336b1472016-10-05 16:37:55 +0100924 size_t callDagIndex = mCallDag->findIndex(functionInfo);
Corentin Walleza094a8a2015-04-07 11:53:06 -0700925 if (callDagIndex == CallDAG::InvalidIndex)
926 {
927 // This happens only for unimplemented prototypes which are thus unused
Olli Etuaho16c745a2017-01-16 17:02:27 +0000928 ASSERT(asFunctionPrototype);
Corentin Walleza094a8a2015-04-07 11:53:06 -0700929 return true;
930 }
931
932 ASSERT(callDagIndex < mMetadatas->size());
933 return !(*mMetadatas)[callDagIndex].used;
934 }
935
936 private:
937 const CallDAG *mCallDag;
938 const std::vector<FunctionMetadata> *mMetadatas;
939};
940
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100941bool TCompiler::pruneUnusedFunctions(TIntermBlock *root)
Corentin Walleza094a8a2015-04-07 11:53:06 -0700942{
Corentin Walleza094a8a2015-04-07 11:53:06 -0700943 UnusedPredicate isUnused(&mCallDag, &functionMetadata);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +0100944 TIntermSequence *sequence = root->getSequence();
Corentin Wallezb081e782015-07-20 05:40:04 -0700945
946 if (!sequence->empty())
947 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500948 sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused),
949 sequence->end());
Corentin Wallezb081e782015-07-20 05:40:04 -0700950 }
Corentin Walleza094a8a2015-04-07 11:53:06 -0700951
952 return true;
953}
954
Olli Etuahob4279202017-05-18 15:08:24 +0300955bool TCompiler::limitExpressionComplexity(TIntermBlock *root)
Jamie Madilleb1a0102013-07-08 13:31:38 -0400956{
Olli Etuahocccf2b02017-07-05 14:50:54 +0300957 if (!IsASTDepthBelowLimit(root, maxExpressionComplexity))
Jamie Madill6654bc92014-03-26 14:01:57 -0400958 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000959 mDiagnostics.globalError("Expression too complex.");
Jamie Madill6654bc92014-03-26 14:01:57 -0400960 return false;
961 }
962
Olli Etuahob4279202017-05-18 15:08:24 +0300963 if (!ValidateMaxParameters(root, maxFunctionParameters))
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200964 {
Olli Etuaho77ba4082016-12-16 12:01:18 +0000965 mDiagnostics.globalError("Function has too many parameters.");
Olli Etuaho19d1dc92016-03-08 17:18:46 +0200966 return false;
967 }
968
Jamie Madilleb1a0102013-07-08 13:31:38 -0400969 return true;
970}
971
Corentin Wallez1df16022016-10-27 08:16:56 -0400972bool TCompiler::shouldCollectVariables(ShCompileOptions compileOptions)
973{
974 return (compileOptions & SH_VARIABLES) != 0;
975}
976
977bool TCompiler::wereVariablesCollected() const
978{
979 return variablesCollected;
980}
981
Olli Etuaho9cbc07c2017-05-10 18:22:01 +0300982void TCompiler::initializeGLPosition(TIntermBlock *root)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800983{
Zhenyao Mo72111912016-07-20 17:45:56 -0700984 InitVariableList list;
985 sh::ShaderVariable var(GL_FLOAT_VEC4, 0);
986 var.name = "gl_Position";
987 list.push_back(var);
Olli Etuahodaaff1c2017-07-05 18:03:26 +0300988 InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -0800989}
990
Olli Etuaho9cbc07c2017-05-10 18:22:01 +0300991void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root)
Qin Jiajia7835b522016-10-08 11:20:17 +0800992{
993 sh::InterfaceBlockList list;
994
Jiajia Qin9b11ea42017-07-11 16:50:08 +0800995 for (auto block : uniformBlocks)
Qin Jiajia7835b522016-10-08 11:20:17 +0800996 {
997 if (!block.staticUse &&
998 (block.layout == sh::BLOCKLAYOUT_STANDARD || block.layout == sh::BLOCKLAYOUT_SHARED))
999 {
1000 list.push_back(block);
1001 }
1002 }
1003
Zhenyao Mod7490962016-11-09 15:49:51 -08001004 sh::UseInterfaceBlockFields(root, list, symbolTable);
Qin Jiajia7835b522016-10-08 11:20:17 +08001005}
1006
Olli Etuaho9cbc07c2017-05-10 18:22:01 +03001007void TCompiler::initializeOutputVariables(TIntermBlock *root)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001008{
Zhenyao Mo72111912016-07-20 17:45:56 -07001009 InitVariableList list;
1010 if (shaderType == GL_VERTEX_SHADER)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001011 {
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001012 for (auto var : outputVaryings)
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001013 {
Zhenyao Mof9312682016-07-22 12:51:31 -07001014 list.push_back(var);
Olli Etuahob12040c2017-06-27 14:20:45 +03001015 if (var.name == "gl_Position")
1016 {
1017 ASSERT(!mGLPositionInitialized);
1018 mGLPositionInitialized = true;
1019 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001020 }
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001021 }
Zhenyao Mo72111912016-07-20 17:45:56 -07001022 else
1023 {
1024 ASSERT(shaderType == GL_FRAGMENT_SHADER);
1025 for (auto var : outputVariables)
1026 {
1027 list.push_back(var);
1028 }
1029 }
Olli Etuahodaaff1c2017-07-05 18:03:26 +03001030 InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior);
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001031}
1032
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001033const TExtensionBehavior &TCompiler::getExtensionBehavior() const
zmo@google.com5601ea02011-06-10 18:23:25 +00001034{
1035 return extensionBehavior;
1036}
zmo@google.com32e97312011-08-24 01:03:11 +00001037
Olli Etuahoa3a5cc62015-02-13 13:12:22 +02001038const char *TCompiler::getSourcePath() const
1039{
1040 return mSourcePath;
1041}
1042
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001043const ShBuiltInResources &TCompiler::getResources() const
shannon.woods%transgaming.com@gtempaccount.com18b4c4b2013-04-13 03:31:40 +00001044{
1045 return compileResources;
1046}
1047
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001048const ArrayBoundsClamper &TCompiler::getArrayBoundsClamper() const
daniel@transgaming.com4167cc92013-01-11 04:11:53 +00001049{
1050 return arrayBoundsClamper;
1051}
1052
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +00001053ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const
1054{
1055 return clampingStrategy;
1056}
1057
Jamie Madilld7b1ab52016-12-12 14:42:19 -05001058const BuiltInFunctionEmulator &TCompiler::getBuiltInFunctionEmulator() const
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +00001059{
1060 return builtInFunctionEmulator;
1061}
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001062
Qiankun Miao7ebb97f2016-09-08 18:01:50 +08001063void TCompiler::writePragma(ShCompileOptions compileOptions)
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001064{
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001065 if (!(compileOptions & SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL))
1066 {
1067 TInfoSinkBase &sink = infoSink.obj;
1068 if (mPragma.stdgl.invariantAll)
1069 sink << "#pragma STDGL invariant(all)\n";
1070 }
1071}
1072
1073bool TCompiler::isVaryingDefined(const char *varyingName)
1074{
1075 ASSERT(variablesCollected);
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001076 for (size_t ii = 0; ii < inputVaryings.size(); ++ii)
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001077 {
Jiawei-Shaodf7d7c92017-07-31 09:34:04 +08001078 if (inputVaryings[ii].name == varyingName)
1079 {
1080 return true;
1081 }
1082 }
1083 for (size_t ii = 0; ii < outputVaryings.size(); ++ii)
1084 {
1085 if (outputVaryings[ii].name == varyingName)
Kenneth Russellbccc65d2016-07-19 16:48:43 -07001086 {
1087 return true;
1088 }
1089 }
1090
1091 return false;
Zhenyao Mo94ac7b72014-10-15 18:22:08 -07001092}
Jamie Madillacb4b812016-11-07 13:50:29 -05001093
1094} // namespace sh