alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 1 | // |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Corentin Wallez | 8b28a8b | 2016-09-15 19:47:56 -0400 | [diff] [blame] | 7 | #include "compiler/translator/Compiler.h" |
| 8 | |
| 9 | #include <sstream> |
| 10 | |
| 11 | #include "angle_gl.h" |
| 12 | #include "common/utilities.h" |
Qiankun Miao | 09cfac6 | 2016-09-06 17:25:16 +0800 | [diff] [blame] | 13 | #include "compiler/translator/AddAndTrueToLoopCondition.h" |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 14 | #include "compiler/translator/Cache.h" |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 15 | #include "compiler/translator/CallDAG.h" |
Olli Etuaho | ab91882 | 2017-07-14 17:03:42 +0300 | [diff] [blame] | 16 | #include "compiler/translator/ClampPointSize.h" |
Martin Radev | 69056a1 | 2017-05-18 11:14:50 +0300 | [diff] [blame] | 17 | #include "compiler/translator/DeclareAndInitBuiltinsForInstancedMultiview.h" |
Olli Etuaho | 3d932d8 | 2016-04-12 11:10:30 +0300 | [diff] [blame] | 18 | #include "compiler/translator/DeferGlobalInitializers.h" |
Zhenyao Mo | 4e94fea | 2016-08-09 14:31:37 -0700 | [diff] [blame] | 19 | #include "compiler/translator/EmulateGLFragColorBroadcast.h" |
Jamie Madill | d569619 | 2016-10-06 11:09:24 -0400 | [diff] [blame] | 20 | #include "compiler/translator/EmulatePrecision.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 21 | #include "compiler/translator/Initialize.h" |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 22 | #include "compiler/translator/InitializeVariables.h" |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 23 | #include "compiler/translator/IntermNodePatternMatcher.h" |
Olli Etuaho | cccf2b0 | 2017-07-05 14:50:54 +0300 | [diff] [blame] | 24 | #include "compiler/translator/IsASTDepthBelowLimit.h" |
| 25 | #include "compiler/translator/OutputTree.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 26 | #include "compiler/translator/ParseContext.h" |
Olli Etuaho | c683311 | 2015-04-22 15:15:54 +0300 | [diff] [blame] | 27 | #include "compiler/translator/PruneEmptyDeclarations.h" |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 28 | #include "compiler/translator/RegenerateStructNames.h" |
Qiankun Miao | 705a919 | 2016-08-29 10:05:27 +0800 | [diff] [blame] | 29 | #include "compiler/translator/RemoveInvariantDeclaration.h" |
Olli Etuaho | 5c407bb | 2015-06-01 12:20:39 +0300 | [diff] [blame] | 30 | #include "compiler/translator/RemovePow.h" |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 31 | #include "compiler/translator/RewriteDoWhile.h" |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 32 | #include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h" |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 33 | #include "compiler/translator/SeparateDeclarations.h" |
| 34 | #include "compiler/translator/SimplifyLoopConditions.h" |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 35 | #include "compiler/translator/UnfoldShortCircuitAST.h" |
Qin Jiajia | 7835b52 | 2016-10-08 11:20:17 +0800 | [diff] [blame] | 36 | #include "compiler/translator/UseInterfaceBlockFields.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 37 | #include "compiler/translator/ValidateLimitations.h" |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 38 | #include "compiler/translator/ValidateMaxParameters.h" |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 39 | #include "compiler/translator/ValidateMultiviewWebGL.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 40 | #include "compiler/translator/ValidateOutputs.h" |
| 41 | #include "compiler/translator/VariablePacker.h" |
shannon.woods@transgaming.com | da1ed36 | 2013-01-25 21:54:57 +0000 | [diff] [blame] | 42 | #include "third_party/compiler/ArrayBoundsClamper.h" |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 43 | |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 44 | namespace sh |
| 45 | { |
| 46 | |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 47 | namespace |
| 48 | { |
| 49 | |
| 50 | #if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT) |
| 51 | void DumpFuzzerCase(char const *const *shaderStrings, |
| 52 | size_t numStrings, |
| 53 | uint32_t type, |
| 54 | uint32_t spec, |
| 55 | uint32_t output, |
| 56 | uint64_t options) |
| 57 | { |
| 58 | static int fileIndex = 0; |
| 59 | |
| 60 | std::ostringstream o; |
| 61 | o << "corpus/" << fileIndex++ << ".sample"; |
| 62 | std::string s = o.str(); |
| 63 | |
| 64 | // Must match the input format of the fuzzer |
| 65 | FILE *f = fopen(s.c_str(), "w"); |
| 66 | fwrite(&type, sizeof(type), 1, f); |
| 67 | fwrite(&spec, sizeof(spec), 1, f); |
| 68 | fwrite(&output, sizeof(output), 1, f); |
| 69 | fwrite(&options, sizeof(options), 1, f); |
| 70 | |
| 71 | char zero[128 - 20] = {0}; |
| 72 | fwrite(&zero, 128 - 20, 1, f); |
| 73 | |
| 74 | for (size_t i = 0; i < numStrings; i++) |
| 75 | { |
| 76 | fwrite(shaderStrings[i], sizeof(char), strlen(shaderStrings[i]), f); |
| 77 | } |
| 78 | fwrite(&zero, 1, 1, f); |
| 79 | |
| 80 | fclose(f); |
| 81 | } |
| 82 | #endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT) |
| 83 | } // anonymous namespace |
| 84 | |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 85 | bool IsWebGLBasedSpec(ShShaderSpec spec) |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 86 | { |
Qiankun Miao | c2c5fc4 | 2016-08-31 15:24:22 +0800 | [diff] [blame] | 87 | return (spec == SH_WEBGL_SPEC || spec == SH_WEBGL2_SPEC || spec == SH_WEBGL3_SPEC); |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 90 | bool IsGLSL130OrNewer(ShShaderOutput output) |
| 91 | { |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 92 | return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT || |
| 93 | output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT || |
| 94 | output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT || |
| 95 | output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT || |
| 96 | output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT); |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Qiankun Miao | 705a919 | 2016-08-29 10:05:27 +0800 | [diff] [blame] | 99 | bool IsGLSL420OrNewer(ShShaderOutput output) |
| 100 | { |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 101 | return (output == SH_GLSL_420_CORE_OUTPUT || output == SH_GLSL_430_CORE_OUTPUT || |
| 102 | output == SH_GLSL_440_CORE_OUTPUT || output == SH_GLSL_450_CORE_OUTPUT); |
Qiankun Miao | 705a919 | 2016-08-29 10:05:27 +0800 | [diff] [blame] | 103 | } |
| 104 | |
Zhenyao Mo | b7bf742 | 2016-11-08 14:44:05 -0800 | [diff] [blame] | 105 | bool IsGLSL410OrOlder(ShShaderOutput output) |
| 106 | { |
| 107 | return (output == SH_GLSL_130_OUTPUT || output == SH_GLSL_140_OUTPUT || |
| 108 | output == SH_GLSL_150_CORE_OUTPUT || output == SH_GLSL_330_CORE_OUTPUT || |
| 109 | output == SH_GLSL_400_CORE_OUTPUT || output == SH_GLSL_410_CORE_OUTPUT); |
| 110 | } |
| 111 | |
Qiankun Miao | 89dd8f3 | 2016-11-09 12:59:30 +0000 | [diff] [blame] | 112 | bool RemoveInvariant(sh::GLenum shaderType, |
| 113 | int shaderVersion, |
| 114 | ShShaderOutput outputType, |
| 115 | ShCompileOptions compileOptions) |
| 116 | { |
| 117 | if ((compileOptions & SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT) == 0 && |
| 118 | shaderType == GL_FRAGMENT_SHADER && IsGLSL420OrNewer(outputType)) |
| 119 | return true; |
| 120 | |
| 121 | if ((compileOptions & SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3) != 0 && |
Qiankun Miao | 41f9f67 | 2016-11-16 17:04:36 +0800 | [diff] [blame] | 122 | shaderVersion >= 300 && shaderType == GL_VERTEX_SHADER) |
Qiankun Miao | 89dd8f3 | 2016-11-09 12:59:30 +0000 | [diff] [blame] | 123 | return true; |
| 124 | |
| 125 | return false; |
| 126 | } |
| 127 | |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 128 | size_t GetGlobalMaxTokenSize(ShShaderSpec spec) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 129 | { |
He Yunchao | 29ab9ff | 2015-08-06 16:58:30 +0800 | [diff] [blame] | 130 | // WebGL defines a max token length of 256, while ES2 leaves max token |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 131 | // size undefined. ES3 defines a max size of 1024 characters. |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 132 | switch (spec) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 133 | { |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 134 | case SH_WEBGL_SPEC: |
| 135 | return 256; |
| 136 | default: |
| 137 | return 1024; |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Shao | 77891c0 | 2017-06-23 16:30:17 +0800 | [diff] [blame] | 141 | int GetMaxUniformVectorsForShaderType(GLenum shaderType, const ShBuiltInResources &resources) |
| 142 | { |
| 143 | switch (shaderType) |
| 144 | { |
| 145 | case GL_VERTEX_SHADER: |
| 146 | return resources.MaxVertexUniformVectors; |
| 147 | case GL_FRAGMENT_SHADER: |
| 148 | return resources.MaxFragmentUniformVectors; |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 149 | |
| 150 | // TODO (jiawei.shao@intel.com): check if we need finer-grained component counting |
Shao | 77891c0 | 2017-06-23 16:30:17 +0800 | [diff] [blame] | 151 | case GL_COMPUTE_SHADER: |
Shao | 77891c0 | 2017-06-23 16:30:17 +0800 | [diff] [blame] | 152 | return resources.MaxComputeUniformComponents / 4; |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 153 | case GL_GEOMETRY_SHADER_OES: |
| 154 | return resources.MaxGeometryUniformComponents / 4; |
Shao | 77891c0 | 2017-06-23 16:30:17 +0800 | [diff] [blame] | 155 | default: |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 156 | UNREACHABLE(); |
Shao | 77891c0 | 2017-06-23 16:30:17 +0800 | [diff] [blame] | 157 | return -1; |
| 158 | } |
| 159 | } |
| 160 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 161 | namespace |
| 162 | { |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 163 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 164 | class TScopedPoolAllocator |
| 165 | { |
| 166 | public: |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 167 | TScopedPoolAllocator(TPoolAllocator *allocator) : mAllocator(allocator) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 168 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 169 | mAllocator->push(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 170 | SetGlobalPoolAllocator(mAllocator); |
| 171 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 172 | ~TScopedPoolAllocator() |
| 173 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 174 | SetGlobalPoolAllocator(nullptr); |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 175 | mAllocator->pop(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 178 | private: |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 179 | TPoolAllocator *mAllocator; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 180 | }; |
| 181 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 182 | class TScopedSymbolTableLevel |
| 183 | { |
| 184 | public: |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 185 | TScopedSymbolTableLevel(TSymbolTable *table) : mTable(table) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 186 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 187 | ASSERT(mTable->atBuiltInLevel()); |
| 188 | mTable->push(); |
| 189 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 190 | ~TScopedSymbolTableLevel() |
| 191 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 192 | while (!mTable->atBuiltInLevel()) |
| 193 | mTable->pop(); |
| 194 | } |
| 195 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 196 | private: |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 197 | TSymbolTable *mTable; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 198 | }; |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 199 | |
| 200 | int MapSpecToShaderVersion(ShShaderSpec spec) |
| 201 | { |
| 202 | switch (spec) |
| 203 | { |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 204 | case SH_GLES2_SPEC: |
| 205 | case SH_WEBGL_SPEC: |
| 206 | return 100; |
| 207 | case SH_GLES3_SPEC: |
| 208 | case SH_WEBGL2_SPEC: |
| 209 | return 300; |
| 210 | case SH_GLES3_1_SPEC: |
| 211 | case SH_WEBGL3_SPEC: |
| 212 | return 310; |
| 213 | default: |
| 214 | UNREACHABLE(); |
| 215 | return 0; |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 219 | } // namespace |
| 220 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 221 | TShHandleBase::TShHandleBase() |
| 222 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 223 | allocator.push(); |
| 224 | SetGlobalPoolAllocator(&allocator); |
| 225 | } |
| 226 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 227 | TShHandleBase::~TShHandleBase() |
| 228 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 229 | SetGlobalPoolAllocator(nullptr); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 230 | allocator.popAll(); |
| 231 | } |
| 232 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 233 | TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output) |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 234 | : variablesCollected(false), |
Olli Etuaho | b12040c | 2017-06-27 14:20:45 +0300 | [diff] [blame] | 235 | mGLPositionInitialized(false), |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 236 | shaderType(type), |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 237 | shaderSpec(spec), |
Jamie Madill | 68fe74a | 2014-05-27 12:56:01 -0400 | [diff] [blame] | 238 | outputType(output), |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 239 | maxUniformVectors(0), |
| 240 | maxExpressionComplexity(0), |
| 241 | maxCallStackDepth(0), |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 242 | maxFunctionParameters(0), |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 243 | fragmentPrecisionHigh(false), |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 244 | clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC), |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 245 | builtInFunctionEmulator(), |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 246 | mDiagnostics(infoSink.info), |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 247 | mSourcePath(nullptr), |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 248 | mComputeShaderLocalSizeDeclared(false), |
| 249 | mGeometryShaderMaxVertices(-1), |
| 250 | mGeometryShaderInvocations(0), |
| 251 | mGeometryShaderInputPrimitiveType(EptUndefined), |
| 252 | mGeometryShaderOutputPrimitiveType(EptUndefined) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 253 | { |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 254 | mComputeShaderLocalSize.fill(1); |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | TCompiler::~TCompiler() |
| 258 | { |
| 259 | } |
| 260 | |
Qiankun Miao | 7ebb97f | 2016-09-08 18:01:50 +0800 | [diff] [blame] | 261 | bool TCompiler::shouldRunLoopAndIndexingValidation(ShCompileOptions compileOptions) const |
Olli Etuaho | 5d91dda | 2015-06-18 15:47:46 +0300 | [diff] [blame] | 262 | { |
| 263 | // If compiling an ESSL 1.00 shader for WebGL, or if its been requested through the API, |
| 264 | // validate loop and indexing as well (to verify that the shader only uses minimal functionality |
| 265 | // of ESSL 1.00 as in Appendix A of the spec). |
| 266 | return (IsWebGLBasedSpec(shaderSpec) && shaderVersion == 100) || |
| 267 | (compileOptions & SH_VALIDATE_LOOP_INDEXING); |
| 268 | } |
| 269 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 270 | bool TCompiler::Init(const ShBuiltInResources &resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 271 | { |
Shao | 77891c0 | 2017-06-23 16:30:17 +0800 | [diff] [blame] | 272 | shaderVersion = 100; |
| 273 | |
| 274 | maxUniformVectors = GetMaxUniformVectorsForShaderType(shaderType, resources); |
| 275 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 276 | maxExpressionComplexity = resources.MaxExpressionComplexity; |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 277 | maxCallStackDepth = resources.MaxCallStackDepth; |
| 278 | maxFunctionParameters = resources.MaxFunctionParameters; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 279 | |
| 280 | SetGlobalPoolAllocator(&allocator); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 281 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 282 | // Generate built-in symbol table. |
| 283 | if (!InitBuiltInSymbolTable(resources)) |
| 284 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 285 | InitExtensionBehavior(resources, extensionBehavior); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 286 | fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 287 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 288 | arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy); |
| 289 | clampingStrategy = resources.ArrayIndexClampingStrategy; |
| 290 | |
daniel@transgaming.com | c23f461 | 2012-11-28 19:42:57 +0000 | [diff] [blame] | 291 | hashFunction = resources.HashFunction; |
| 292 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 293 | return true; |
| 294 | } |
| 295 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 296 | TIntermBlock *TCompiler::compileTreeForTesting(const char *const shaderStrings[], |
| 297 | size_t numStrings, |
| 298 | ShCompileOptions compileOptions) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 299 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 300 | return compileTreeImpl(shaderStrings, numStrings, compileOptions); |
| 301 | } |
| 302 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 303 | TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], |
| 304 | size_t numStrings, |
| 305 | const ShCompileOptions compileOptions) |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 306 | { |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 307 | clearResults(); |
| 308 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 309 | ASSERT(numStrings > 0); |
| 310 | ASSERT(GetGlobalPoolAllocator()); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 311 | |
David Yen | 0fbd128 | 2015-02-02 14:46:09 -0800 | [diff] [blame] | 312 | // Reset the extension behavior for each compilation unit. |
| 313 | ResetExtensionBehavior(extensionBehavior); |
| 314 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 315 | // First string is path of source file if flag is set. The actual source follows. |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 316 | size_t firstSource = 0; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 317 | if (compileOptions & SH_SOURCE_PATH) |
| 318 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 319 | mSourcePath = shaderStrings[0]; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 320 | ++firstSource; |
| 321 | } |
| 322 | |
Olli Etuaho | f119a26 | 2016-08-19 15:54:22 +0300 | [diff] [blame] | 323 | TParseContext parseContext(symbolTable, extensionBehavior, shaderType, shaderSpec, |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 324 | compileOptions, true, &mDiagnostics, getResources()); |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 325 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 326 | parseContext.setFragmentPrecisionHighOnESSL1(fragmentPrecisionHigh); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 327 | |
| 328 | // We preserve symbols at the built-in level from compile-to-compile. |
| 329 | // Start pushing the user-defined symbols at global level. |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 330 | TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 331 | |
| 332 | // Parse shader. |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 333 | bool success = (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr, |
| 334 | &parseContext) == 0) && |
| 335 | (parseContext.getTreeRoot() != nullptr); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 336 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 337 | shaderVersion = parseContext.getShaderVersion(); |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 338 | if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion) |
| 339 | { |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 340 | mDiagnostics.globalError("unsupported shader version"); |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 341 | success = false; |
| 342 | } |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 343 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 344 | TIntermBlock *root = nullptr; |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 345 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 346 | if (success) |
| 347 | { |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 348 | mPragma = parseContext.pragma(); |
Kenneth Russell | 8bad46d | 2016-07-01 19:52:52 -0700 | [diff] [blame] | 349 | symbolTable.setGlobalInvariant(mPragma.stdgl.invariantAll); |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 350 | |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 351 | mComputeShaderLocalSizeDeclared = parseContext.isComputeShaderLocalSizeDeclared(); |
| 352 | mComputeShaderLocalSize = parseContext.getComputeShaderLocalSize(); |
| 353 | |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 354 | mNumViews = parseContext.getNumViews(); |
| 355 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 356 | root = parseContext.getTreeRoot(); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 357 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 358 | // Highp might have been auto-enabled based on shader version |
| 359 | fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh(); |
| 360 | |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 361 | if (success && (IsWebGLBasedSpec(shaderSpec) && |
| 362 | IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview") && |
| 363 | IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview2"))) |
| 364 | { |
| 365 | // Can't enable both extensions at the same time. |
| 366 | mDiagnostics.globalError("Can't enable both OVR_multiview and OVR_multiview2"); |
| 367 | success = false; |
| 368 | } |
| 369 | |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 370 | if (success && shaderType == GL_GEOMETRY_SHADER_OES) |
| 371 | { |
| 372 | mGeometryShaderInputPrimitiveType = parseContext.getGeometryShaderInputPrimitiveType(); |
| 373 | mGeometryShaderOutputPrimitiveType = |
| 374 | parseContext.getGeometryShaderOutputPrimitiveType(); |
| 375 | mGeometryShaderMaxVertices = parseContext.getGeometryShaderMaxVertices(); |
| 376 | mGeometryShaderInvocations = parseContext.getGeometryShaderInvocations(); |
| 377 | } |
| 378 | |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 379 | // Disallow expressions deemed too complex. |
| 380 | if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY)) |
| 381 | success = limitExpressionComplexity(root); |
| 382 | |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 383 | // Create the function DAG and check there is no recursion |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 384 | if (success) |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 385 | success = initCallDag(root); |
| 386 | |
| 387 | if (success && (compileOptions & SH_LIMIT_CALL_STACK_DEPTH)) |
| 388 | success = checkCallDepth(); |
| 389 | |
| 390 | // Checks which functions are used and if "main" exists |
| 391 | if (success) |
| 392 | { |
| 393 | functionMetadata.clear(); |
| 394 | functionMetadata.resize(mCallDag.size()); |
| 395 | success = tagUsedFunctions(); |
| 396 | } |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 397 | |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 398 | if (success && !(compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS)) |
| 399 | success = pruneUnusedFunctions(root); |
| 400 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 401 | // Prune empty declarations to work around driver bugs and to keep declaration output |
| 402 | // simple. |
Olli Etuaho | c683311 | 2015-04-22 15:15:54 +0300 | [diff] [blame] | 403 | if (success) |
| 404 | PruneEmptyDeclarations(root); |
| 405 | |
Andrei Volykhin | 73fa4b8 | 2017-05-05 18:45:06 +0300 | [diff] [blame] | 406 | if (success && shaderVersion >= 300 && shaderType == GL_FRAGMENT_SHADER) |
Olli Etuaho | 12b0b39 | 2017-05-30 13:22:31 +0300 | [diff] [blame] | 407 | { |
| 408 | success = ValidateOutputs(root, getExtensionBehavior(), compileResources.MaxDrawBuffers, |
| 409 | &mDiagnostics); |
| 410 | } |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 411 | |
Olli Etuaho | 5d91dda | 2015-06-18 15:47:46 +0300 | [diff] [blame] | 412 | if (success && shouldRunLoopAndIndexingValidation(compileOptions)) |
Olli Etuaho | 9ec7939 | 2017-03-31 23:04:23 +0300 | [diff] [blame] | 413 | success = |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 414 | ValidateLimitations(root, shaderType, &symbolTable, shaderVersion, &mDiagnostics); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 415 | |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 416 | bool multiview2 = IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview2"); |
| 417 | if (success && compileResources.OVR_multiview && IsWebGLBasedSpec(shaderSpec) && |
| 418 | (IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview") || multiview2)) |
Olli Etuaho | 01d0ad0 | 2017-01-22 14:51:23 -0800 | [diff] [blame] | 419 | success = ValidateMultiviewWebGL(root, shaderType, symbolTable, shaderVersion, |
| 420 | multiview2, &mDiagnostics); |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 421 | |
Jamie Madill | d569619 | 2016-10-06 11:09:24 -0400 | [diff] [blame] | 422 | // Fail compilation if precision emulation not supported. |
| 423 | if (success && getResources().WEBGL_debug_shader_precision && |
| 424 | getPragma().debugShaderPrecision) |
| 425 | { |
| 426 | if (!EmulatePrecision::SupportedInLanguage(outputType)) |
| 427 | { |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 428 | mDiagnostics.globalError("Precision emulation not supported for this output type."); |
Jamie Madill | d569619 | 2016-10-06 11:09:24 -0400 | [diff] [blame] | 429 | success = false; |
| 430 | } |
| 431 | } |
| 432 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 433 | // Built-in function emulation needs to happen after validateLimitations pass. |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 434 | if (success) |
| 435 | { |
Jamie Madill | 438dbcf | 2016-06-17 14:20:05 -0400 | [diff] [blame] | 436 | // TODO(jmadill): Remove global pool allocator. |
| 437 | GetGlobalPoolAllocator()->lock(); |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 438 | initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions); |
Jamie Madill | 438dbcf | 2016-06-17 14:20:05 -0400 | [diff] [blame] | 439 | GetGlobalPoolAllocator()->unlock(); |
Olli Etuaho | dfa75e8 | 2017-01-23 09:43:06 -0800 | [diff] [blame] | 440 | builtInFunctionEmulator.markBuiltInFunctionsForEmulation(root); |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 441 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 442 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 443 | // Clamping uniform array bounds needs to happen after validateLimitations pass. |
| 444 | if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS)) |
| 445 | arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root); |
| 446 | |
Martin Radev | 69056a1 | 2017-05-18 11:14:50 +0300 | [diff] [blame] | 447 | if (success && (compileOptions & SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW) && |
Martin Radev | 7ef89a4 | 2017-07-05 14:23:06 +0300 | [diff] [blame] | 448 | parseContext.isMultiviewExtensionEnabled() && getShaderType() != GL_COMPUTE_SHADER) |
Martin Radev | 69056a1 | 2017-05-18 11:14:50 +0300 | [diff] [blame] | 449 | { |
Martin Radev | c39a19a | 2017-07-07 18:52:09 +0300 | [diff] [blame] | 450 | DeclareAndInitBuiltinsForInstancedMultiview(root, mNumViews, shaderType, compileOptions, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 451 | outputType, &symbolTable); |
Martin Radev | 69056a1 | 2017-05-18 11:14:50 +0300 | [diff] [blame] | 452 | } |
| 453 | |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 454 | // This pass might emit short circuits so keep it before the short circuit unfolding |
| 455 | if (success && (compileOptions & SH_REWRITE_DO_WHILE_LOOPS)) |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 456 | RewriteDoWhile(root, &symbolTable); |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 457 | |
Qiankun Miao | 09cfac6 | 2016-09-06 17:25:16 +0800 | [diff] [blame] | 458 | if (success && (compileOptions & SH_ADD_AND_TRUE_TO_LOOP_CONDITION)) |
| 459 | sh::AddAndTrueToLoopCondition(root); |
| 460 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 461 | if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT)) |
| 462 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 463 | UnfoldShortCircuitAST unfoldShortCircuit; |
| 464 | root->traverse(&unfoldShortCircuit); |
| 465 | unfoldShortCircuit.updateTree(); |
| 466 | } |
| 467 | |
Olli Etuaho | 5c407bb | 2015-06-01 12:20:39 +0300 | [diff] [blame] | 468 | if (success && (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT)) |
| 469 | { |
| 470 | RemovePow(root); |
| 471 | } |
| 472 | |
Olli Etuaho | 4dfe809 | 2015-08-21 17:44:35 +0300 | [diff] [blame] | 473 | if (success && shouldCollectVariables(compileOptions)) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 474 | { |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 475 | ASSERT(!variablesCollected); |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 476 | CollectVariables(root, &attributes, &outputVariables, &uniforms, &inputVaryings, |
| 477 | &outputVaryings, &interfaceBlocks, hashFunction, &symbolTable, |
| 478 | shaderVersion, extensionBehavior); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 479 | variablesCollected = true; |
Qin Jiajia | 7835b52 | 2016-10-08 11:20:17 +0800 | [diff] [blame] | 480 | if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS) |
| 481 | { |
| 482 | useAllMembersInUnusedStandardAndSharedBlocks(root); |
| 483 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 484 | if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) |
| 485 | { |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 486 | std::vector<sh::ShaderVariable> expandedUniforms; |
| 487 | sh::ExpandUniforms(uniforms, &expandedUniforms); |
| 488 | VariablePacker packer; |
| 489 | // Returns true if, after applying the packing rules in the GLSL ES 1.00.17 spec |
| 490 | // Appendix A, section 7, the shader does not use too many uniforms. |
| 491 | success = |
| 492 | packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 493 | if (!success) |
| 494 | { |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 495 | mDiagnostics.globalError("too many uniforms"); |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 496 | } |
| 497 | } |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 498 | if (success && (compileOptions & SH_INIT_OUTPUT_VARIABLES)) |
| 499 | { |
Olli Etuaho | 27776e3 | 2016-07-22 14:00:56 +0300 | [diff] [blame] | 500 | initializeOutputVariables(root); |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 501 | } |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 502 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 503 | |
Olli Etuaho | b12040c | 2017-06-27 14:20:45 +0300 | [diff] [blame] | 504 | // gl_Position is always written in compatibility output mode. |
| 505 | // It may have been already initialized among other output variables, in that case we don't |
| 506 | // need to initialize it twice. |
| 507 | if (success && shaderType == GL_VERTEX_SHADER && !mGLPositionInitialized && |
| 508 | ((compileOptions & SH_INIT_GL_POSITION) || |
| 509 | (outputType == SH_GLSL_COMPATIBILITY_OUTPUT))) |
| 510 | { |
| 511 | initializeGLPosition(root); |
| 512 | mGLPositionInitialized = true; |
| 513 | } |
| 514 | |
Yuly Novikov | 817232e | 2017-02-22 18:36:10 -0500 | [diff] [blame] | 515 | // Removing invariant declarations must be done after collecting variables. |
| 516 | // Otherwise, built-in invariant declarations don't apply. |
| 517 | if (success && RemoveInvariant(shaderType, shaderVersion, outputType, compileOptions)) |
| 518 | sh::RemoveInvariantDeclaration(root); |
| 519 | |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 520 | if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS)) |
| 521 | { |
Olli Etuaho | b990b55 | 2016-10-27 12:29:17 +0100 | [diff] [blame] | 522 | ScalarizeVecAndMatConstructorArgs(root, shaderType, fragmentPrecisionHigh, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 523 | &symbolTable); |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 526 | if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES)) |
| 527 | { |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 528 | RegenerateStructNames gen(&symbolTable, shaderVersion); |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 529 | root->traverse(&gen); |
| 530 | } |
Olli Etuaho | 3d932d8 | 2016-04-12 11:10:30 +0300 | [diff] [blame] | 531 | |
Zhenyao Mo | 4e94fea | 2016-08-09 14:31:37 -0700 | [diff] [blame] | 532 | if (success && shaderType == GL_FRAGMENT_SHADER && shaderVersion == 100 && |
| 533 | compileResources.EXT_draw_buffers && compileResources.MaxDrawBuffers > 1 && |
| 534 | IsExtensionEnabled(extensionBehavior, "GL_EXT_draw_buffers")) |
| 535 | { |
Olli Etuaho | daaff1c | 2017-07-05 18:03:26 +0300 | [diff] [blame] | 536 | EmulateGLFragColorBroadcast(root, compileResources.MaxDrawBuffers, &outputVariables, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 537 | &symbolTable, shaderVersion); |
Zhenyao Mo | 4e94fea | 2016-08-09 14:31:37 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Olli Etuaho | 3d932d8 | 2016-04-12 11:10:30 +0300 | [diff] [blame] | 540 | if (success) |
| 541 | { |
Olli Etuaho | 0ffc441 | 2017-05-19 14:18:55 +0300 | [diff] [blame] | 542 | DeferGlobalInitializers(root, needToInitializeGlobalsInAST()); |
Olli Etuaho | 3d932d8 | 2016-04-12 11:10:30 +0300 | [diff] [blame] | 543 | } |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 544 | |
| 545 | if (success && (compileOptions & SH_INITIALIZE_UNINITIALIZED_LOCALS) && getOutputType()) |
| 546 | { |
| 547 | // Initialize uninitialized local variables. |
| 548 | // In some cases initializing can generate extra statements in the parent block, such as |
| 549 | // when initializing nameless structs or initializing arrays in ESSL 1.00. In that case |
| 550 | // we need to first simplify loop conditions and separate declarations. If we don't |
| 551 | // follow the Appendix A limitations, loop init statements can declare arrays or |
| 552 | // nameless structs and have multiple declarations. |
| 553 | |
| 554 | if (!shouldRunLoopAndIndexingValidation(compileOptions)) |
| 555 | { |
| 556 | SimplifyLoopConditions(root, |
| 557 | IntermNodePatternMatcher::kMultiDeclaration | |
| 558 | IntermNodePatternMatcher::kArrayDeclaration | |
| 559 | IntermNodePatternMatcher::kNamelessStructDeclaration, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 560 | &getSymbolTable(), getShaderVersion()); |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 561 | } |
| 562 | // We only really need to separate array declarations and nameless struct declarations, |
| 563 | // but it's simpler to just use the regular SeparateDeclarations. |
| 564 | SeparateDeclarations(root); |
| 565 | InitializeUninitializedLocals(root, getShaderVersion()); |
| 566 | } |
Olli Etuaho | ab91882 | 2017-07-14 17:03:42 +0300 | [diff] [blame] | 567 | |
| 568 | if (success && getShaderType() == GL_VERTEX_SHADER && |
| 569 | (compileOptions & SH_CLAMP_POINT_SIZE)) |
| 570 | { |
| 571 | ClampPointSize(root, compileResources.MaxPointSize, &getSymbolTable()); |
| 572 | } |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 575 | if (success) |
| 576 | return root; |
| 577 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 578 | return nullptr; |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 579 | } |
| 580 | |
Qiankun Miao | 7ebb97f | 2016-09-08 18:01:50 +0800 | [diff] [blame] | 581 | bool TCompiler::compile(const char *const shaderStrings[], |
| 582 | size_t numStrings, |
| 583 | ShCompileOptions compileOptionsIn) |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 584 | { |
Corentin Wallez | 28b6528 | 2016-06-16 07:24:50 -0700 | [diff] [blame] | 585 | #if defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT) |
| 586 | DumpFuzzerCase(shaderStrings, numStrings, shaderType, shaderSpec, outputType, compileOptionsIn); |
| 587 | #endif // defined(ANGLE_ENABLE_FUZZER_CORPUS_OUTPUT) |
| 588 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 589 | if (numStrings == 0) |
| 590 | return true; |
| 591 | |
Qiankun Miao | 7ebb97f | 2016-09-08 18:01:50 +0800 | [diff] [blame] | 592 | ShCompileOptions compileOptions = compileOptionsIn; |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 593 | |
| 594 | // Apply key workarounds. |
| 595 | if (shouldFlattenPragmaStdglInvariantAll()) |
| 596 | { |
| 597 | // This should be harmless to do in all cases, but for the moment, do it only conditionally. |
| 598 | compileOptions |= SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL; |
| 599 | } |
| 600 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 601 | TScopedPoolAllocator scopedAlloc(&allocator); |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 602 | TIntermBlock *root = compileTreeImpl(shaderStrings, numStrings, compileOptions); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 603 | |
| 604 | if (root) |
| 605 | { |
| 606 | if (compileOptions & SH_INTERMEDIATE_TREE) |
Olli Etuaho | cccf2b0 | 2017-07-05 14:50:54 +0300 | [diff] [blame] | 607 | OutputTree(root, infoSink.info); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 608 | |
| 609 | if (compileOptions & SH_OBJECT_CODE) |
| 610 | translate(root, compileOptions); |
| 611 | |
| 612 | // The IntermNode tree doesn't need to be deleted here, since the |
| 613 | // memory will be freed in a big chunk by the PoolAllocator. |
| 614 | return true; |
| 615 | } |
| 616 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 619 | bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 620 | { |
Olli Etuaho | 28cb036 | 2016-11-22 15:42:37 +0000 | [diff] [blame] | 621 | if (resources.MaxDrawBuffers < 1) |
| 622 | { |
| 623 | return false; |
| 624 | } |
| 625 | if (resources.EXT_blend_func_extended && resources.MaxDualSourceDrawBuffers < 1) |
| 626 | { |
| 627 | return false; |
| 628 | } |
| 629 | |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 630 | compileResources = resources; |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 631 | setResourceString(); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 632 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 633 | assert(symbolTable.isEmpty()); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 634 | symbolTable.push(); // COMMON_BUILTINS |
| 635 | symbolTable.push(); // ESSL1_BUILTINS |
| 636 | symbolTable.push(); // ESSL3_BUILTINS |
| 637 | symbolTable.push(); // ESSL3_1_BUILTINS |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 638 | |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 639 | switch (shaderType) |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 640 | { |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 641 | case GL_FRAGMENT_SHADER: |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 642 | symbolTable.setDefaultPrecision(EbtInt, EbpMedium); |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 643 | break; |
| 644 | case GL_VERTEX_SHADER: |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 645 | case GL_COMPUTE_SHADER: |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 646 | case GL_GEOMETRY_SHADER_OES: |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 647 | symbolTable.setDefaultPrecision(EbtInt, EbpHigh); |
| 648 | symbolTable.setDefaultPrecision(EbtFloat, EbpHigh); |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 649 | break; |
| 650 | default: |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 651 | UNREACHABLE(); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 652 | } |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 653 | // Set defaults for sampler types that have default precision, even those that are |
Zhenyao Mo | a5a1dfc | 2013-09-23 14:57:03 -0400 | [diff] [blame] | 654 | // only available if an extension exists. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 655 | // New sampler types in ESSL3 don't have default precision. ESSL1 types do. |
| 656 | initSamplerDefaultPrecision(EbtSampler2D); |
| 657 | initSamplerDefaultPrecision(EbtSamplerCube); |
| 658 | // SamplerExternalOES is specified in the extension to have default precision. |
| 659 | initSamplerDefaultPrecision(EbtSamplerExternalOES); |
Andrei Volykhin | a552707 | 2017-03-22 16:46:30 +0300 | [diff] [blame] | 660 | // SamplerExternal2DY2YEXT is specified in the extension to have default precision. |
| 661 | initSamplerDefaultPrecision(EbtSamplerExternal2DY2YEXT); |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 662 | // It isn't specified whether Sampler2DRect has default precision. |
| 663 | initSamplerDefaultPrecision(EbtSampler2DRect); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 664 | |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 665 | symbolTable.setDefaultPrecision(EbtAtomicCounter, EbpHigh); |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 666 | |
Jamie Madill | 1b45214 | 2013-07-12 14:51:11 -0400 | [diff] [blame] | 667 | InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 668 | |
| 669 | IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable); |
| 670 | |
| 671 | return true; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 674 | void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType) |
| 675 | { |
| 676 | ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd); |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 677 | symbolTable.setDefaultPrecision(samplerType, EbpLow); |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 678 | } |
| 679 | |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 680 | void TCompiler::setResourceString() |
| 681 | { |
| 682 | std::ostringstream strstream; |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 683 | |
| 684 | // clang-format off |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 685 | strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 686 | << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors |
| 687 | << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors |
| 688 | << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits |
| 689 | << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits |
| 690 | << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits |
| 691 | << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors |
| 692 | << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers |
| 693 | << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives |
| 694 | << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external |
| 695 | << ":OES_EGL_image_external_essl3:" << compileResources.OES_EGL_image_external_essl3 |
| 696 | << ":NV_EGL_stream_consumer_external:" << compileResources.NV_EGL_stream_consumer_external |
| 697 | << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle |
| 698 | << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers |
| 699 | << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh |
| 700 | << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity |
| 701 | << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth |
| 702 | << ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters |
| 703 | << ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended |
| 704 | << ":EXT_frag_depth:" << compileResources.EXT_frag_depth |
| 705 | << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod |
| 706 | << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch |
| 707 | << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch |
| 708 | << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch |
Martin Radev | 318f9aa | 2017-05-17 17:47:28 +0300 | [diff] [blame] | 709 | << ":OVR_multiview:" << compileResources.OVR_multiview |
Andrei Volykhin | a552707 | 2017-03-22 16:46:30 +0300 | [diff] [blame] | 710 | << ":EXT_YUV_target:" << compileResources.EXT_YUV_target |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 711 | << ":OES_geometry_shader:" << compileResources.OES_geometry_shader |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 712 | << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors |
| 713 | << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors |
| 714 | << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset |
| 715 | << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset |
| 716 | << ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers |
Martin Radev | 318f9aa | 2017-05-17 17:47:28 +0300 | [diff] [blame] | 717 | << ":MaxViewsOVR:" << compileResources.MaxViewsOVR |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 718 | << ":NV_draw_buffers:" << compileResources.NV_draw_buffers |
| 719 | << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision |
| 720 | << ":MaxImageUnits:" << compileResources.MaxImageUnits |
| 721 | << ":MaxVertexImageUniforms:" << compileResources.MaxVertexImageUniforms |
| 722 | << ":MaxFragmentImageUniforms:" << compileResources.MaxFragmentImageUniforms |
| 723 | << ":MaxComputeImageUniforms:" << compileResources.MaxComputeImageUniforms |
| 724 | << ":MaxCombinedImageUniforms:" << compileResources.MaxCombinedImageUniforms |
| 725 | << ":MaxCombinedShaderOutputResources:" << compileResources.MaxCombinedShaderOutputResources |
| 726 | << ":MaxComputeWorkGroupCountX:" << compileResources.MaxComputeWorkGroupCount[0] |
| 727 | << ":MaxComputeWorkGroupCountY:" << compileResources.MaxComputeWorkGroupCount[1] |
| 728 | << ":MaxComputeWorkGroupCountZ:" << compileResources.MaxComputeWorkGroupCount[2] |
| 729 | << ":MaxComputeWorkGroupSizeX:" << compileResources.MaxComputeWorkGroupSize[0] |
| 730 | << ":MaxComputeWorkGroupSizeY:" << compileResources.MaxComputeWorkGroupSize[1] |
| 731 | << ":MaxComputeWorkGroupSizeZ:" << compileResources.MaxComputeWorkGroupSize[2] |
| 732 | << ":MaxComputeUniformComponents:" << compileResources.MaxComputeUniformComponents |
| 733 | << ":MaxComputeTextureImageUnits:" << compileResources.MaxComputeTextureImageUnits |
| 734 | << ":MaxComputeAtomicCounters:" << compileResources.MaxComputeAtomicCounters |
| 735 | << ":MaxComputeAtomicCounterBuffers:" << compileResources.MaxComputeAtomicCounterBuffers |
| 736 | << ":MaxVertexAtomicCounters:" << compileResources.MaxVertexAtomicCounters |
| 737 | << ":MaxFragmentAtomicCounters:" << compileResources.MaxFragmentAtomicCounters |
| 738 | << ":MaxCombinedAtomicCounters:" << compileResources.MaxCombinedAtomicCounters |
| 739 | << ":MaxAtomicCounterBindings:" << compileResources.MaxAtomicCounterBindings |
| 740 | << ":MaxVertexAtomicCounterBuffers:" << compileResources.MaxVertexAtomicCounterBuffers |
| 741 | << ":MaxFragmentAtomicCounterBuffers:" << compileResources.MaxFragmentAtomicCounterBuffers |
| 742 | << ":MaxCombinedAtomicCounterBuffers:" << compileResources.MaxCombinedAtomicCounterBuffers |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 743 | << ":MaxAtomicCounterBufferSize:" << compileResources.MaxAtomicCounterBufferSize |
| 744 | << ":MaxGeometryOutputVertices:" << compileResources.MaxGeometryOutputVertices |
| 745 | << ":MaxGeometryUniformComponents:" << compileResources.MaxGeometryUniformComponents |
| 746 | << ":MaxGeometryShaderInvocations:" << compileResources.MaxGeometryShaderInvocations; |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 747 | // clang-format on |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 748 | |
| 749 | builtInResourcesString = strstream.str(); |
| 750 | } |
| 751 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 752 | void TCompiler::clearResults() |
| 753 | { |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 754 | arrayBoundsClamper.Cleanup(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 755 | infoSink.info.erase(); |
| 756 | infoSink.obj.erase(); |
| 757 | infoSink.debug.erase(); |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 758 | mDiagnostics.resetErrorCount(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 759 | |
Jamie Madill | ed27c72 | 2014-07-02 15:31:23 -0400 | [diff] [blame] | 760 | attributes.clear(); |
| 761 | outputVariables.clear(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 762 | uniforms.clear(); |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 763 | inputVaryings.clear(); |
| 764 | outputVaryings.clear(); |
Jamie Madill | ed27c72 | 2014-07-02 15:31:23 -0400 | [diff] [blame] | 765 | interfaceBlocks.clear(); |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 766 | variablesCollected = false; |
Olli Etuaho | b12040c | 2017-06-27 14:20:45 +0300 | [diff] [blame] | 767 | mGLPositionInitialized = false; |
zmo@google.com | a3b4ab4 | 2011-09-16 00:53:26 +0000 | [diff] [blame] | 768 | |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 769 | mNumViews = -1; |
| 770 | |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 771 | mGeometryShaderInputPrimitiveType = EptUndefined; |
| 772 | mGeometryShaderOutputPrimitiveType = EptUndefined; |
| 773 | mGeometryShaderInvocations = 0; |
| 774 | mGeometryShaderMaxVertices = -1; |
| 775 | |
Olli Etuaho | dfa75e8 | 2017-01-23 09:43:06 -0800 | [diff] [blame] | 776 | builtInFunctionEmulator.cleanup(); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 777 | |
| 778 | nameMap.clear(); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 779 | |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 780 | mSourcePath = nullptr; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 783 | bool TCompiler::initCallDag(TIntermNode *root) |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 784 | { |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 785 | mCallDag.clear(); |
| 786 | |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 787 | switch (mCallDag.init(root, &mDiagnostics)) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 788 | { |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 789 | case CallDAG::INITDAG_SUCCESS: |
| 790 | return true; |
| 791 | case CallDAG::INITDAG_RECURSION: |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 792 | case CallDAG::INITDAG_UNDEFINED: |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 793 | // Error message has already been written out. |
| 794 | ASSERT(mDiagnostics.numErrors() > 0); |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 795 | return false; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | UNREACHABLE(); |
| 799 | return true; |
| 800 | } |
| 801 | |
| 802 | bool TCompiler::checkCallDepth() |
| 803 | { |
| 804 | std::vector<int> depths(mCallDag.size()); |
| 805 | |
| 806 | for (size_t i = 0; i < mCallDag.size(); i++) |
| 807 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 808 | int depth = 0; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 809 | auto &record = mCallDag.getRecordFromIndex(i); |
| 810 | |
| 811 | for (auto &calleeIndex : record.callees) |
| 812 | { |
| 813 | depth = std::max(depth, depths[calleeIndex] + 1); |
| 814 | } |
| 815 | |
| 816 | depths[i] = depth; |
| 817 | |
| 818 | if (depth >= maxCallStackDepth) |
| 819 | { |
| 820 | // Trace back the function chain to have a meaningful info log. |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 821 | std::stringstream errorStream; |
| 822 | errorStream << "Call stack too deep (larger than " << maxCallStackDepth |
| 823 | << ") with the following call chain: " << record.name; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 824 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 825 | int currentFunction = static_cast<int>(i); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 826 | int currentDepth = depth; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 827 | |
| 828 | while (currentFunction != -1) |
| 829 | { |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 830 | errorStream << " -> " << mCallDag.getRecordFromIndex(currentFunction).name; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 831 | |
| 832 | int nextFunction = -1; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 833 | for (auto &calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees) |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 834 | { |
| 835 | if (depths[calleeIndex] == currentDepth - 1) |
| 836 | { |
| 837 | currentDepth--; |
| 838 | nextFunction = calleeIndex; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | currentFunction = nextFunction; |
| 843 | } |
| 844 | |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 845 | std::string errorStr = errorStream.str(); |
| 846 | mDiagnostics.globalError(errorStr.c_str()); |
| 847 | |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 848 | return false; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | return true; |
| 853 | } |
| 854 | |
| 855 | bool TCompiler::tagUsedFunctions() |
| 856 | { |
| 857 | // Search from main, starting from the end of the DAG as it usually is the root. |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 858 | for (size_t i = mCallDag.size(); i-- > 0;) |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 859 | { |
Olli Etuaho | ec9232b | 2017-03-27 17:01:37 +0300 | [diff] [blame] | 860 | if (mCallDag.getRecordFromIndex(i).name == "main") |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 861 | { |
| 862 | internalTagUsedFunction(i); |
| 863 | return true; |
| 864 | } |
| 865 | } |
| 866 | |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 867 | mDiagnostics.globalError("Missing main()"); |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 868 | return false; |
| 869 | } |
| 870 | |
| 871 | void TCompiler::internalTagUsedFunction(size_t index) |
| 872 | { |
| 873 | if (functionMetadata[index].used) |
| 874 | { |
| 875 | return; |
| 876 | } |
| 877 | |
| 878 | functionMetadata[index].used = true; |
| 879 | |
| 880 | for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees) |
| 881 | { |
| 882 | internalTagUsedFunction(calleeIndex); |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 886 | // A predicate for the stl that returns if a top-level node is unused |
| 887 | class TCompiler::UnusedPredicate |
| 888 | { |
| 889 | public: |
| 890 | UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas) |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 891 | : mCallDag(callDag), mMetadatas(metadatas) |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 892 | { |
| 893 | } |
| 894 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 895 | bool operator()(TIntermNode *node) |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 896 | { |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 897 | const TIntermFunctionPrototype *asFunctionPrototype = node->getAsFunctionPrototypeNode(); |
| 898 | const TIntermFunctionDefinition *asFunctionDefinition = node->getAsFunctionDefinition(); |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 899 | |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 900 | const TFunctionSymbolInfo *functionInfo = nullptr; |
| 901 | |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 902 | if (asFunctionDefinition) |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 903 | { |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 904 | functionInfo = asFunctionDefinition->getFunctionSymbolInfo(); |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 905 | } |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 906 | else if (asFunctionPrototype) |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 907 | { |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 908 | functionInfo = asFunctionPrototype->getFunctionSymbolInfo(); |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 909 | } |
| 910 | if (functionInfo == nullptr) |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 911 | { |
| 912 | return false; |
| 913 | } |
| 914 | |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 915 | size_t callDagIndex = mCallDag->findIndex(functionInfo); |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 916 | if (callDagIndex == CallDAG::InvalidIndex) |
| 917 | { |
| 918 | // This happens only for unimplemented prototypes which are thus unused |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 919 | ASSERT(asFunctionPrototype); |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 920 | return true; |
| 921 | } |
| 922 | |
| 923 | ASSERT(callDagIndex < mMetadatas->size()); |
| 924 | return !(*mMetadatas)[callDagIndex].used; |
| 925 | } |
| 926 | |
| 927 | private: |
| 928 | const CallDAG *mCallDag; |
| 929 | const std::vector<FunctionMetadata> *mMetadatas; |
| 930 | }; |
| 931 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 932 | bool TCompiler::pruneUnusedFunctions(TIntermBlock *root) |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 933 | { |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 934 | UnusedPredicate isUnused(&mCallDag, &functionMetadata); |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 935 | TIntermSequence *sequence = root->getSequence(); |
Corentin Wallez | b081e78 | 2015-07-20 05:40:04 -0700 | [diff] [blame] | 936 | |
| 937 | if (!sequence->empty()) |
| 938 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 939 | sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused), |
| 940 | sequence->end()); |
Corentin Wallez | b081e78 | 2015-07-20 05:40:04 -0700 | [diff] [blame] | 941 | } |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 942 | |
| 943 | return true; |
| 944 | } |
| 945 | |
Olli Etuaho | b427920 | 2017-05-18 15:08:24 +0300 | [diff] [blame] | 946 | bool TCompiler::limitExpressionComplexity(TIntermBlock *root) |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 947 | { |
Olli Etuaho | cccf2b0 | 2017-07-05 14:50:54 +0300 | [diff] [blame] | 948 | if (!IsASTDepthBelowLimit(root, maxExpressionComplexity)) |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 949 | { |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 950 | mDiagnostics.globalError("Expression too complex."); |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 951 | return false; |
| 952 | } |
| 953 | |
Olli Etuaho | b427920 | 2017-05-18 15:08:24 +0300 | [diff] [blame] | 954 | if (!ValidateMaxParameters(root, maxFunctionParameters)) |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 955 | { |
Olli Etuaho | 77ba408 | 2016-12-16 12:01:18 +0000 | [diff] [blame] | 956 | mDiagnostics.globalError("Function has too many parameters."); |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 957 | return false; |
| 958 | } |
| 959 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 960 | return true; |
| 961 | } |
| 962 | |
Corentin Wallez | 1df1602 | 2016-10-27 08:16:56 -0400 | [diff] [blame] | 963 | bool TCompiler::shouldCollectVariables(ShCompileOptions compileOptions) |
| 964 | { |
| 965 | return (compileOptions & SH_VARIABLES) != 0; |
| 966 | } |
| 967 | |
| 968 | bool TCompiler::wereVariablesCollected() const |
| 969 | { |
| 970 | return variablesCollected; |
| 971 | } |
| 972 | |
Olli Etuaho | 9cbc07c | 2017-05-10 18:22:01 +0300 | [diff] [blame] | 973 | void TCompiler::initializeGLPosition(TIntermBlock *root) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 974 | { |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 975 | InitVariableList list; |
| 976 | sh::ShaderVariable var(GL_FLOAT_VEC4, 0); |
| 977 | var.name = "gl_Position"; |
| 978 | list.push_back(var); |
Olli Etuaho | daaff1c | 2017-07-05 18:03:26 +0300 | [diff] [blame] | 979 | InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 980 | } |
| 981 | |
Olli Etuaho | 9cbc07c | 2017-05-10 18:22:01 +0300 | [diff] [blame] | 982 | void TCompiler::useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root) |
Qin Jiajia | 7835b52 | 2016-10-08 11:20:17 +0800 | [diff] [blame] | 983 | { |
| 984 | sh::InterfaceBlockList list; |
| 985 | |
| 986 | for (auto block : interfaceBlocks) |
| 987 | { |
| 988 | if (!block.staticUse && |
| 989 | (block.layout == sh::BLOCKLAYOUT_STANDARD || block.layout == sh::BLOCKLAYOUT_SHARED)) |
| 990 | { |
| 991 | list.push_back(block); |
| 992 | } |
| 993 | } |
| 994 | |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 995 | sh::UseInterfaceBlockFields(root, list, symbolTable); |
Qin Jiajia | 7835b52 | 2016-10-08 11:20:17 +0800 | [diff] [blame] | 996 | } |
| 997 | |
Olli Etuaho | 9cbc07c | 2017-05-10 18:22:01 +0300 | [diff] [blame] | 998 | void TCompiler::initializeOutputVariables(TIntermBlock *root) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 999 | { |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 1000 | InitVariableList list; |
| 1001 | if (shaderType == GL_VERTEX_SHADER) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 1002 | { |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 1003 | for (auto var : outputVaryings) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 1004 | { |
Zhenyao Mo | f931268 | 2016-07-22 12:51:31 -0700 | [diff] [blame] | 1005 | list.push_back(var); |
Olli Etuaho | b12040c | 2017-06-27 14:20:45 +0300 | [diff] [blame] | 1006 | if (var.name == "gl_Position") |
| 1007 | { |
| 1008 | ASSERT(!mGLPositionInitialized); |
| 1009 | mGLPositionInitialized = true; |
| 1010 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 1011 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 1012 | } |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 1013 | else |
| 1014 | { |
| 1015 | ASSERT(shaderType == GL_FRAGMENT_SHADER); |
| 1016 | for (auto var : outputVariables) |
| 1017 | { |
| 1018 | list.push_back(var); |
| 1019 | } |
| 1020 | } |
Olli Etuaho | daaff1c | 2017-07-05 18:03:26 +0300 | [diff] [blame] | 1021 | InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 1024 | const TExtensionBehavior &TCompiler::getExtensionBehavior() const |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 1025 | { |
| 1026 | return extensionBehavior; |
| 1027 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 1028 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 1029 | const char *TCompiler::getSourcePath() const |
| 1030 | { |
| 1031 | return mSourcePath; |
| 1032 | } |
| 1033 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 1034 | const ShBuiltInResources &TCompiler::getResources() const |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 1035 | { |
| 1036 | return compileResources; |
| 1037 | } |
| 1038 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 1039 | const ArrayBoundsClamper &TCompiler::getArrayBoundsClamper() const |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 1040 | { |
| 1041 | return arrayBoundsClamper; |
| 1042 | } |
| 1043 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 1044 | ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const |
| 1045 | { |
| 1046 | return clampingStrategy; |
| 1047 | } |
| 1048 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 1049 | const BuiltInFunctionEmulator &TCompiler::getBuiltInFunctionEmulator() const |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 1050 | { |
| 1051 | return builtInFunctionEmulator; |
| 1052 | } |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 1053 | |
Qiankun Miao | 7ebb97f | 2016-09-08 18:01:50 +0800 | [diff] [blame] | 1054 | void TCompiler::writePragma(ShCompileOptions compileOptions) |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 1055 | { |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 1056 | if (!(compileOptions & SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL)) |
| 1057 | { |
| 1058 | TInfoSinkBase &sink = infoSink.obj; |
| 1059 | if (mPragma.stdgl.invariantAll) |
| 1060 | sink << "#pragma STDGL invariant(all)\n"; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | bool TCompiler::isVaryingDefined(const char *varyingName) |
| 1065 | { |
| 1066 | ASSERT(variablesCollected); |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 1067 | for (size_t ii = 0; ii < inputVaryings.size(); ++ii) |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 1068 | { |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 1069 | if (inputVaryings[ii].name == varyingName) |
| 1070 | { |
| 1071 | return true; |
| 1072 | } |
| 1073 | } |
| 1074 | for (size_t ii = 0; ii < outputVaryings.size(); ++ii) |
| 1075 | { |
| 1076 | if (outputVaryings[ii].name == varyingName) |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 1077 | { |
| 1078 | return true; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | return false; |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 1083 | } |
Jamie Madill | acb4b81 | 2016-11-07 13:50:29 -0500 | [diff] [blame] | 1084 | |
| 1085 | } // namespace sh |