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 | |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 7 | #include "compiler/translator/Cache.h" |
Jamie Madill | d4a3a31 | 2014-06-25 16:04:56 -0400 | [diff] [blame] | 8 | #include "compiler/translator/Compiler.h" |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 9 | #include "compiler/translator/CallDAG.h" |
Olli Etuaho | 3d932d8 | 2016-04-12 11:10:30 +0300 | [diff] [blame] | 10 | #include "compiler/translator/DeferGlobalInitializers.h" |
Zhenyao Mo | 4e94fea | 2016-08-09 14:31:37 -0700 | [diff] [blame] | 11 | #include "compiler/translator/EmulateGLFragColorBroadcast.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 12 | #include "compiler/translator/ForLoopUnroll.h" |
| 13 | #include "compiler/translator/Initialize.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 14 | #include "compiler/translator/InitializeParseContext.h" |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 15 | #include "compiler/translator/InitializeVariables.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 16 | #include "compiler/translator/ParseContext.h" |
Olli Etuaho | c683311 | 2015-04-22 15:15:54 +0300 | [diff] [blame] | 17 | #include "compiler/translator/PruneEmptyDeclarations.h" |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 18 | #include "compiler/translator/RegenerateStructNames.h" |
Olli Etuaho | 5c407bb | 2015-06-01 12:20:39 +0300 | [diff] [blame] | 19 | #include "compiler/translator/RemovePow.h" |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 20 | #include "compiler/translator/RewriteDoWhile.h" |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 21 | #include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h" |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 22 | #include "compiler/translator/UnfoldShortCircuitAST.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 23 | #include "compiler/translator/ValidateLimitations.h" |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 24 | #include "compiler/translator/ValidateMaxParameters.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 25 | #include "compiler/translator/ValidateOutputs.h" |
| 26 | #include "compiler/translator/VariablePacker.h" |
shannon.woods@transgaming.com | da1ed36 | 2013-01-25 21:54:57 +0000 | [diff] [blame] | 27 | #include "third_party/compiler/ArrayBoundsClamper.h" |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 28 | #include "angle_gl.h" |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 29 | #include "common/utilities.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 30 | |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 31 | bool IsWebGLBasedSpec(ShShaderSpec spec) |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 32 | { |
Qiankun Miao | c2c5fc4 | 2016-08-31 15:24:22 +0800 | [diff] [blame] | 33 | 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] | 34 | } |
| 35 | |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 36 | bool IsGLSL130OrNewer(ShShaderOutput output) |
| 37 | { |
| 38 | return (output == SH_GLSL_130_OUTPUT || |
Geoff Lang | 8273e00 | 2015-06-15 13:40:19 -0700 | [diff] [blame] | 39 | output == SH_GLSL_140_OUTPUT || |
| 40 | output == SH_GLSL_150_CORE_OUTPUT || |
| 41 | output == SH_GLSL_330_CORE_OUTPUT || |
| 42 | output == SH_GLSL_400_CORE_OUTPUT || |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 43 | output == SH_GLSL_410_CORE_OUTPUT || |
Geoff Lang | 8273e00 | 2015-06-15 13:40:19 -0700 | [diff] [blame] | 44 | output == SH_GLSL_420_CORE_OUTPUT || |
| 45 | output == SH_GLSL_430_CORE_OUTPUT || |
| 46 | output == SH_GLSL_440_CORE_OUTPUT || |
| 47 | output == SH_GLSL_450_CORE_OUTPUT); |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 50 | size_t GetGlobalMaxTokenSize(ShShaderSpec spec) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 51 | { |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 52 | // WebGL defines a max token legnth of 256, while ES2 leaves max token |
| 53 | // size undefined. ES3 defines a max size of 1024 characters. |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 54 | switch (spec) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 55 | { |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 56 | case SH_WEBGL_SPEC: |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 57 | return 256; |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 58 | default: |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 59 | return 1024; |
| 60 | } |
| 61 | } |
| 62 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 63 | namespace { |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 64 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 65 | class TScopedPoolAllocator |
| 66 | { |
| 67 | public: |
| 68 | TScopedPoolAllocator(TPoolAllocator* allocator) : mAllocator(allocator) |
| 69 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 70 | mAllocator->push(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 71 | SetGlobalPoolAllocator(mAllocator); |
| 72 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 73 | ~TScopedPoolAllocator() |
| 74 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 75 | SetGlobalPoolAllocator(NULL); |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 76 | mAllocator->pop(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 79 | private: |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 80 | TPoolAllocator* mAllocator; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 81 | }; |
| 82 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 83 | class TScopedSymbolTableLevel |
| 84 | { |
| 85 | public: |
| 86 | TScopedSymbolTableLevel(TSymbolTable* table) : mTable(table) |
| 87 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 88 | ASSERT(mTable->atBuiltInLevel()); |
| 89 | mTable->push(); |
| 90 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 91 | ~TScopedSymbolTableLevel() |
| 92 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 93 | while (!mTable->atBuiltInLevel()) |
| 94 | mTable->pop(); |
| 95 | } |
| 96 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 97 | private: |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 98 | TSymbolTable* mTable; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 99 | }; |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 100 | |
| 101 | int MapSpecToShaderVersion(ShShaderSpec spec) |
| 102 | { |
| 103 | switch (spec) |
| 104 | { |
| 105 | case SH_GLES2_SPEC: |
| 106 | case SH_WEBGL_SPEC: |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 107 | return 100; |
| 108 | case SH_GLES3_SPEC: |
| 109 | case SH_WEBGL2_SPEC: |
| 110 | return 300; |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 111 | case SH_GLES3_1_SPEC: |
| 112 | case SH_WEBGL3_SPEC: |
| 113 | return 310; |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 114 | default: |
| 115 | UNREACHABLE(); |
| 116 | return 0; |
| 117 | } |
| 118 | } |
| 119 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 120 | } // namespace |
| 121 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 122 | TShHandleBase::TShHandleBase() |
| 123 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 124 | allocator.push(); |
| 125 | SetGlobalPoolAllocator(&allocator); |
| 126 | } |
| 127 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 128 | TShHandleBase::~TShHandleBase() |
| 129 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 130 | SetGlobalPoolAllocator(NULL); |
| 131 | allocator.popAll(); |
| 132 | } |
| 133 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 134 | TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output) |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 135 | : variablesCollected(false), |
| 136 | shaderType(type), |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 137 | shaderSpec(spec), |
Jamie Madill | 68fe74a | 2014-05-27 12:56:01 -0400 | [diff] [blame] | 138 | outputType(output), |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 139 | maxUniformVectors(0), |
| 140 | maxExpressionComplexity(0), |
| 141 | maxCallStackDepth(0), |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 142 | maxFunctionParameters(0), |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 143 | fragmentPrecisionHigh(false), |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 144 | clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC), |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 145 | builtInFunctionEmulator(), |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 146 | mSourcePath(NULL), |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 147 | mComputeShaderLocalSizeDeclared(false), |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 148 | mTemporaryIndex(0) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 149 | { |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 150 | mComputeShaderLocalSize.fill(1); |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | TCompiler::~TCompiler() |
| 154 | { |
| 155 | } |
| 156 | |
Olli Etuaho | 5d91dda | 2015-06-18 15:47:46 +0300 | [diff] [blame] | 157 | bool TCompiler::shouldRunLoopAndIndexingValidation(int compileOptions) const |
| 158 | { |
| 159 | // If compiling an ESSL 1.00 shader for WebGL, or if its been requested through the API, |
| 160 | // validate loop and indexing as well (to verify that the shader only uses minimal functionality |
| 161 | // of ESSL 1.00 as in Appendix A of the spec). |
| 162 | return (IsWebGLBasedSpec(shaderSpec) && shaderVersion == 100) || |
| 163 | (compileOptions & SH_VALIDATE_LOOP_INDEXING); |
| 164 | } |
| 165 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 166 | bool TCompiler::Init(const ShBuiltInResources& resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 167 | { |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 168 | shaderVersion = 100; |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 169 | maxUniformVectors = (shaderType == GL_VERTEX_SHADER) ? |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 170 | resources.MaxVertexUniformVectors : |
| 171 | resources.MaxFragmentUniformVectors; |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 172 | maxExpressionComplexity = resources.MaxExpressionComplexity; |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 173 | maxCallStackDepth = resources.MaxCallStackDepth; |
| 174 | maxFunctionParameters = resources.MaxFunctionParameters; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 175 | |
| 176 | SetGlobalPoolAllocator(&allocator); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 177 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 178 | // Generate built-in symbol table. |
| 179 | if (!InitBuiltInSymbolTable(resources)) |
| 180 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 181 | InitExtensionBehavior(resources, extensionBehavior); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 182 | fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 183 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 184 | arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy); |
| 185 | clampingStrategy = resources.ArrayIndexClampingStrategy; |
| 186 | |
daniel@transgaming.com | c23f461 | 2012-11-28 19:42:57 +0000 | [diff] [blame] | 187 | hashFunction = resources.HashFunction; |
| 188 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 189 | return true; |
| 190 | } |
| 191 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 192 | TIntermNode *TCompiler::compileTreeForTesting(const char* const shaderStrings[], |
| 193 | size_t numStrings, int compileOptions) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 194 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 195 | return compileTreeImpl(shaderStrings, numStrings, compileOptions); |
| 196 | } |
| 197 | |
Olli Etuaho | a7b6db7 | 2015-08-19 14:26:30 +0300 | [diff] [blame] | 198 | TIntermNode *TCompiler::compileTreeImpl(const char *const shaderStrings[], |
| 199 | size_t numStrings, |
| 200 | const int compileOptions) |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 201 | { |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 202 | clearResults(); |
| 203 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 204 | ASSERT(numStrings > 0); |
| 205 | ASSERT(GetGlobalPoolAllocator()); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 206 | |
David Yen | 0fbd128 | 2015-02-02 14:46:09 -0800 | [diff] [blame] | 207 | // Reset the extension behavior for each compilation unit. |
| 208 | ResetExtensionBehavior(extensionBehavior); |
| 209 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 210 | // 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] | 211 | size_t firstSource = 0; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 212 | if (compileOptions & SH_SOURCE_PATH) |
| 213 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 214 | mSourcePath = shaderStrings[0]; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 215 | ++firstSource; |
| 216 | } |
| 217 | |
Olli Etuaho | f119a26 | 2016-08-19 15:54:22 +0300 | [diff] [blame] | 218 | TParseContext parseContext(symbolTable, extensionBehavior, shaderType, shaderSpec, |
Olli Etuaho | e1a94c6 | 2015-11-16 17:35:25 +0200 | [diff] [blame] | 219 | compileOptions, true, infoSink, getResources()); |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 220 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 221 | parseContext.setFragmentPrecisionHighOnESSL1(fragmentPrecisionHigh); |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 222 | SetGlobalParseContext(&parseContext); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 223 | |
| 224 | // We preserve symbols at the built-in level from compile-to-compile. |
| 225 | // Start pushing the user-defined symbols at global level. |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 226 | TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 227 | |
| 228 | // Parse shader. |
| 229 | bool success = |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 230 | (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], nullptr, &parseContext) == 0) && |
| 231 | (parseContext.getTreeRoot() != nullptr); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 232 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 233 | shaderVersion = parseContext.getShaderVersion(); |
Zhenyao Mo | db9b40b | 2014-10-29 15:00:04 -0700 | [diff] [blame] | 234 | if (success && MapSpecToShaderVersion(shaderSpec) < shaderVersion) |
| 235 | { |
| 236 | infoSink.info.prefix(EPrefixError); |
| 237 | infoSink.info << "unsupported shader version"; |
| 238 | success = false; |
| 239 | } |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 240 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 241 | TIntermNode *root = nullptr; |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 242 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 243 | if (success) |
| 244 | { |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 245 | mPragma = parseContext.pragma(); |
Kenneth Russell | 8bad46d | 2016-07-01 19:52:52 -0700 | [diff] [blame] | 246 | symbolTable.setGlobalInvariant(mPragma.stdgl.invariantAll); |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 247 | |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 248 | mComputeShaderLocalSizeDeclared = parseContext.isComputeShaderLocalSizeDeclared(); |
| 249 | mComputeShaderLocalSize = parseContext.getComputeShaderLocalSize(); |
| 250 | |
Jamie Madill | 6e06b1f | 2015-05-14 10:01:17 -0400 | [diff] [blame] | 251 | root = parseContext.getTreeRoot(); |
Olli Etuaho | f119a26 | 2016-08-19 15:54:22 +0300 | [diff] [blame] | 252 | root = TIntermediate::PostProcess(root); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 253 | |
Olli Etuaho | a699668 | 2015-10-12 14:32:30 +0300 | [diff] [blame] | 254 | // Highp might have been auto-enabled based on shader version |
| 255 | fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh(); |
| 256 | |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 257 | // Disallow expressions deemed too complex. |
| 258 | if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY)) |
| 259 | success = limitExpressionComplexity(root); |
| 260 | |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 261 | // Create the function DAG and check there is no recursion |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 262 | if (success) |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 263 | success = initCallDag(root); |
| 264 | |
| 265 | if (success && (compileOptions & SH_LIMIT_CALL_STACK_DEPTH)) |
| 266 | success = checkCallDepth(); |
| 267 | |
| 268 | // Checks which functions are used and if "main" exists |
| 269 | if (success) |
| 270 | { |
| 271 | functionMetadata.clear(); |
| 272 | functionMetadata.resize(mCallDag.size()); |
| 273 | success = tagUsedFunctions(); |
| 274 | } |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 275 | |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 276 | if (success && !(compileOptions & SH_DONT_PRUNE_UNUSED_FUNCTIONS)) |
| 277 | success = pruneUnusedFunctions(root); |
| 278 | |
Olli Etuaho | c683311 | 2015-04-22 15:15:54 +0300 | [diff] [blame] | 279 | // Prune empty declarations to work around driver bugs and to keep declaration output simple. |
| 280 | if (success) |
| 281 | PruneEmptyDeclarations(root); |
| 282 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 283 | if (success && shaderVersion == 300 && shaderType == GL_FRAGMENT_SHADER) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 284 | success = validateOutputs(root); |
| 285 | |
Olli Etuaho | 5d91dda | 2015-06-18 15:47:46 +0300 | [diff] [blame] | 286 | if (success && shouldRunLoopAndIndexingValidation(compileOptions)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 287 | success = validateLimitations(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 288 | |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 289 | // Unroll for-loop markup needs to happen after validateLimitations pass. |
| 290 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX)) |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 291 | { |
Olli Etuaho | 8a76dcc | 2015-12-10 20:25:12 +0200 | [diff] [blame] | 292 | ForLoopUnrollMarker marker(ForLoopUnrollMarker::kIntegerIndex, |
| 293 | shouldRunLoopAndIndexingValidation(compileOptions)); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 294 | root->traverse(&marker); |
| 295 | } |
| 296 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX)) |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 297 | { |
Olli Etuaho | 8a76dcc | 2015-12-10 20:25:12 +0200 | [diff] [blame] | 298 | ForLoopUnrollMarker marker(ForLoopUnrollMarker::kSamplerArrayIndex, |
| 299 | shouldRunLoopAndIndexingValidation(compileOptions)); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 300 | root->traverse(&marker); |
| 301 | if (marker.samplerArrayIndexIsFloatLoopIndex()) |
| 302 | { |
| 303 | infoSink.info.prefix(EPrefixError); |
| 304 | infoSink.info << "sampler array index is float loop index"; |
| 305 | success = false; |
| 306 | } |
| 307 | } |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 308 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 309 | // Built-in function emulation needs to happen after validateLimitations pass. |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 310 | if (success) |
| 311 | { |
Jamie Madill | 438dbcf | 2016-06-17 14:20:05 -0400 | [diff] [blame] | 312 | // TODO(jmadill): Remove global pool allocator. |
| 313 | GetGlobalPoolAllocator()->lock(); |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 314 | initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions); |
Jamie Madill | 438dbcf | 2016-06-17 14:20:05 -0400 | [diff] [blame] | 315 | GetGlobalPoolAllocator()->unlock(); |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 316 | builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(root); |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 317 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 318 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 319 | // Clamping uniform array bounds needs to happen after validateLimitations pass. |
| 320 | if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS)) |
| 321 | arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root); |
| 322 | |
Ian Ewell | 924b7de | 2016-01-21 13:54:28 -0500 | [diff] [blame] | 323 | // gl_Position is always written in compatibility output mode |
| 324 | if (success && shaderType == GL_VERTEX_SHADER && |
| 325 | ((compileOptions & SH_INIT_GL_POSITION) || |
| 326 | (outputType == SH_GLSL_COMPATIBILITY_OUTPUT))) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 327 | initializeGLPosition(root); |
Zhenyao Mo | ac44cd2 | 2013-09-23 14:57:09 -0400 | [diff] [blame] | 328 | |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 329 | // This pass might emit short circuits so keep it before the short circuit unfolding |
| 330 | if (success && (compileOptions & SH_REWRITE_DO_WHILE_LOOPS)) |
| 331 | RewriteDoWhile(root, getTemporaryIndex()); |
| 332 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 333 | if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT)) |
| 334 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 335 | UnfoldShortCircuitAST unfoldShortCircuit; |
| 336 | root->traverse(&unfoldShortCircuit); |
| 337 | unfoldShortCircuit.updateTree(); |
| 338 | } |
| 339 | |
Olli Etuaho | 5c407bb | 2015-06-01 12:20:39 +0300 | [diff] [blame] | 340 | if (success && (compileOptions & SH_REMOVE_POW_WITH_CONSTANT_EXPONENT)) |
| 341 | { |
| 342 | RemovePow(root); |
| 343 | } |
| 344 | |
Olli Etuaho | 4dfe809 | 2015-08-21 17:44:35 +0300 | [diff] [blame] | 345 | if (success && shouldCollectVariables(compileOptions)) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 346 | { |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 347 | collectVariables(root); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 348 | if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) |
| 349 | { |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 350 | success = enforcePackingRestrictions(); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 351 | if (!success) |
| 352 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 353 | infoSink.info.prefix(EPrefixError); |
| 354 | infoSink.info << "too many uniforms"; |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 357 | if (success && (compileOptions & SH_INIT_OUTPUT_VARIABLES)) |
| 358 | { |
Olli Etuaho | 27776e3 | 2016-07-22 14:00:56 +0300 | [diff] [blame] | 359 | initializeOutputVariables(root); |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 360 | } |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 361 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 362 | |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 363 | if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS)) |
| 364 | { |
Zhenyao Mo | daf5657 | 2014-08-06 16:18:30 -0700 | [diff] [blame] | 365 | ScalarizeVecAndMatConstructorArgs scalarizer( |
| 366 | shaderType, fragmentPrecisionHigh); |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 367 | root->traverse(&scalarizer); |
| 368 | } |
| 369 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 370 | if (success && (compileOptions & SH_REGENERATE_STRUCT_NAMES)) |
| 371 | { |
| 372 | RegenerateStructNames gen(symbolTable, shaderVersion); |
| 373 | root->traverse(&gen); |
| 374 | } |
Olli Etuaho | 3d932d8 | 2016-04-12 11:10:30 +0300 | [diff] [blame] | 375 | |
Zhenyao Mo | 4e94fea | 2016-08-09 14:31:37 -0700 | [diff] [blame] | 376 | if (success && shaderType == GL_FRAGMENT_SHADER && shaderVersion == 100 && |
| 377 | compileResources.EXT_draw_buffers && compileResources.MaxDrawBuffers > 1 && |
| 378 | IsExtensionEnabled(extensionBehavior, "GL_EXT_draw_buffers")) |
| 379 | { |
| 380 | EmulateGLFragColorBroadcast(root, compileResources.MaxDrawBuffers, &outputVariables); |
| 381 | } |
| 382 | |
Olli Etuaho | 3d932d8 | 2016-04-12 11:10:30 +0300 | [diff] [blame] | 383 | if (success) |
| 384 | { |
| 385 | DeferGlobalInitializers(root); |
| 386 | } |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 389 | SetGlobalParseContext(NULL); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 390 | if (success) |
| 391 | return root; |
| 392 | |
| 393 | return NULL; |
| 394 | } |
| 395 | |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 396 | bool TCompiler::compile(const char *const shaderStrings[], size_t numStrings, int compileOptionsIn) |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 397 | { |
| 398 | if (numStrings == 0) |
| 399 | return true; |
| 400 | |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 401 | int compileOptions = compileOptionsIn; |
| 402 | |
| 403 | // Apply key workarounds. |
| 404 | if (shouldFlattenPragmaStdglInvariantAll()) |
| 405 | { |
| 406 | // This should be harmless to do in all cases, but for the moment, do it only conditionally. |
| 407 | compileOptions |= SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL; |
| 408 | } |
| 409 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 410 | TScopedPoolAllocator scopedAlloc(&allocator); |
| 411 | TIntermNode *root = compileTreeImpl(shaderStrings, numStrings, compileOptions); |
| 412 | |
| 413 | if (root) |
| 414 | { |
| 415 | if (compileOptions & SH_INTERMEDIATE_TREE) |
| 416 | TIntermediate::outputTree(root, infoSink.info); |
| 417 | |
| 418 | if (compileOptions & SH_OBJECT_CODE) |
| 419 | translate(root, compileOptions); |
| 420 | |
| 421 | // The IntermNode tree doesn't need to be deleted here, since the |
| 422 | // memory will be freed in a big chunk by the PoolAllocator. |
| 423 | return true; |
| 424 | } |
| 425 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 428 | bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 429 | { |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 430 | compileResources = resources; |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 431 | setResourceString(); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 432 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 433 | assert(symbolTable.isEmpty()); |
| 434 | symbolTable.push(); // COMMON_BUILTINS |
| 435 | symbolTable.push(); // ESSL1_BUILTINS |
| 436 | symbolTable.push(); // ESSL3_BUILTINS |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 437 | symbolTable.push(); // ESSL3_1_BUILTINS |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 438 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 439 | TPublicType integer; |
Martin Radev | 4a9cd80 | 2016-09-01 16:51:51 +0300 | [diff] [blame] | 440 | integer.setBasicType(EbtInt); |
| 441 | integer.initializeSizeForScalarTypes(); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 442 | integer.array = false; |
| 443 | |
| 444 | TPublicType floatingPoint; |
Martin Radev | 4a9cd80 | 2016-09-01 16:51:51 +0300 | [diff] [blame] | 445 | floatingPoint.setBasicType(EbtFloat); |
| 446 | floatingPoint.initializeSizeForScalarTypes(); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 447 | floatingPoint.array = false; |
| 448 | |
| 449 | switch(shaderType) |
| 450 | { |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 451 | case GL_FRAGMENT_SHADER: |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 452 | symbolTable.setDefaultPrecision(integer, EbpMedium); |
| 453 | break; |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 454 | case GL_VERTEX_SHADER: |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 455 | symbolTable.setDefaultPrecision(integer, EbpHigh); |
| 456 | symbolTable.setDefaultPrecision(floatingPoint, EbpHigh); |
| 457 | break; |
Martin Radev | 802abe0 | 2016-08-04 17:48:32 +0300 | [diff] [blame] | 458 | case GL_COMPUTE_SHADER: |
| 459 | symbolTable.setDefaultPrecision(integer, EbpHigh); |
| 460 | symbolTable.setDefaultPrecision(floatingPoint, EbpHigh); |
| 461 | break; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 462 | default: |
| 463 | assert(false && "Language not supported"); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 464 | } |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 465 | // 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] | 466 | // only available if an extension exists. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 467 | // New sampler types in ESSL3 don't have default precision. ESSL1 types do. |
| 468 | initSamplerDefaultPrecision(EbtSampler2D); |
| 469 | initSamplerDefaultPrecision(EbtSamplerCube); |
| 470 | // SamplerExternalOES is specified in the extension to have default precision. |
| 471 | initSamplerDefaultPrecision(EbtSamplerExternalOES); |
| 472 | // It isn't specified whether Sampler2DRect has default precision. |
| 473 | initSamplerDefaultPrecision(EbtSampler2DRect); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 474 | |
Jamie Madill | 1b45214 | 2013-07-12 14:51:11 -0400 | [diff] [blame] | 475 | InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 476 | |
| 477 | IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable); |
| 478 | |
| 479 | return true; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 482 | void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType) |
| 483 | { |
| 484 | ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd); |
| 485 | TPublicType sampler; |
Martin Radev | 4a9cd80 | 2016-09-01 16:51:51 +0300 | [diff] [blame] | 486 | sampler.initializeSizeForScalarTypes(); |
| 487 | sampler.setBasicType(samplerType); |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 488 | sampler.array = false; |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 489 | symbolTable.setDefaultPrecision(sampler, EbpLow); |
| 490 | } |
| 491 | |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 492 | void TCompiler::setResourceString() |
| 493 | { |
| 494 | std::ostringstream strstream; |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 495 | |
| 496 | // clang-format off |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 497 | strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs |
| 498 | << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors |
| 499 | << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors |
| 500 | << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits |
| 501 | << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits |
| 502 | << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits |
| 503 | << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors |
| 504 | << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers |
| 505 | << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives |
| 506 | << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 507 | << ":OES_EGL_image_external_essl3:" << compileResources.OES_EGL_image_external_essl3 |
| 508 | << ":NV_EGL_stream_consumer_external:" << compileResources.NV_EGL_stream_consumer_external |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 509 | << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle |
| 510 | << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers |
| 511 | << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh |
| 512 | << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity |
| 513 | << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 514 | << ":MaxFunctionParameters:" << compileResources.MaxFunctionParameters |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 515 | << ":EXT_blend_func_extended:" << compileResources.EXT_blend_func_extended |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 516 | << ":EXT_frag_depth:" << compileResources.EXT_frag_depth |
| 517 | << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod |
Erik Dahlström | ea7a212 | 2014-11-17 16:15:57 +0100 | [diff] [blame] | 518 | << ":EXT_shader_framebuffer_fetch:" << compileResources.EXT_shader_framebuffer_fetch |
| 519 | << ":NV_shader_framebuffer_fetch:" << compileResources.NV_shader_framebuffer_fetch |
| 520 | << ":ARM_shader_framebuffer_fetch:" << compileResources.ARM_shader_framebuffer_fetch |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 521 | << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors |
| 522 | << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors |
| 523 | << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset |
Olli Etuaho | e61209a | 2014-09-26 12:01:17 +0300 | [diff] [blame] | 524 | << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 525 | << ":MaxDualSourceDrawBuffers:" << compileResources.MaxDualSourceDrawBuffers |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 526 | << ":NV_draw_buffers:" << compileResources.NV_draw_buffers |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 527 | << ":WEBGL_debug_shader_precision:" << compileResources.WEBGL_debug_shader_precision |
| 528 | << ":MaxImageUnits:" << compileResources.MaxImageUnits |
| 529 | << ":MaxVertexImageUniforms:" << compileResources.MaxVertexImageUniforms |
| 530 | << ":MaxFragmentImageUniforms:" << compileResources.MaxFragmentImageUniforms |
| 531 | << ":MaxComputeImageUniforms:" << compileResources.MaxComputeImageUniforms |
| 532 | << ":MaxCombinedImageUniforms:" << compileResources.MaxCombinedImageUniforms |
| 533 | << ":MaxCombinedShaderOutputResources:" << compileResources.MaxCombinedShaderOutputResources |
| 534 | << ":MaxComputeWorkGroupCountX:" << compileResources.MaxComputeWorkGroupCount[0] |
| 535 | << ":MaxComputeWorkGroupCountY:" << compileResources.MaxComputeWorkGroupCount[1] |
| 536 | << ":MaxComputeWorkGroupCountZ:" << compileResources.MaxComputeWorkGroupCount[2] |
| 537 | << ":MaxComputeWorkGroupSizeX:" << compileResources.MaxComputeWorkGroupSize[0] |
| 538 | << ":MaxComputeWorkGroupSizeY:" << compileResources.MaxComputeWorkGroupSize[1] |
| 539 | << ":MaxComputeWorkGroupSizeZ:" << compileResources.MaxComputeWorkGroupSize[2] |
| 540 | << ":MaxComputeUniformComponents:" << compileResources.MaxComputeUniformComponents |
| 541 | << ":MaxComputeTextureImageUnits:" << compileResources.MaxComputeTextureImageUnits |
| 542 | << ":MaxComputeAtomicCounters:" << compileResources.MaxComputeAtomicCounters |
| 543 | << ":MaxComputeAtomicCounterBuffers:" << compileResources.MaxComputeAtomicCounterBuffers |
| 544 | << ":MaxVertexAtomicCounters:" << compileResources.MaxVertexAtomicCounters |
| 545 | << ":MaxFragmentAtomicCounters:" << compileResources.MaxFragmentAtomicCounters |
| 546 | << ":MaxCombinedAtomicCounters:" << compileResources.MaxCombinedAtomicCounters |
| 547 | << ":MaxAtomicCounterBindings:" << compileResources.MaxAtomicCounterBindings |
| 548 | << ":MaxVertexAtomicCounterBuffers:" << compileResources.MaxVertexAtomicCounterBuffers |
| 549 | << ":MaxFragmentAtomicCounterBuffers:" << compileResources.MaxFragmentAtomicCounterBuffers |
| 550 | << ":MaxCombinedAtomicCounterBuffers:" << compileResources.MaxCombinedAtomicCounterBuffers |
| 551 | << ":MaxAtomicCounterBufferSize:" << compileResources.MaxAtomicCounterBufferSize; |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 552 | // clang-format on |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 553 | |
| 554 | builtInResourcesString = strstream.str(); |
| 555 | } |
| 556 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 557 | void TCompiler::clearResults() |
| 558 | { |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 559 | arrayBoundsClamper.Cleanup(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 560 | infoSink.info.erase(); |
| 561 | infoSink.obj.erase(); |
| 562 | infoSink.debug.erase(); |
| 563 | |
Jamie Madill | ed27c72 | 2014-07-02 15:31:23 -0400 | [diff] [blame] | 564 | attributes.clear(); |
| 565 | outputVariables.clear(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 566 | uniforms.clear(); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 567 | expandedUniforms.clear(); |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 568 | varyings.clear(); |
Jamie Madill | ed27c72 | 2014-07-02 15:31:23 -0400 | [diff] [blame] | 569 | interfaceBlocks.clear(); |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 570 | variablesCollected = false; |
zmo@google.com | a3b4ab4 | 2011-09-16 00:53:26 +0000 | [diff] [blame] | 571 | |
| 572 | builtInFunctionEmulator.Cleanup(); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 573 | |
| 574 | nameMap.clear(); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 575 | |
| 576 | mSourcePath = NULL; |
Corentin Wallez | d4b5054 | 2015-09-28 12:19:26 -0700 | [diff] [blame] | 577 | mTemporaryIndex = 0; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 580 | bool TCompiler::initCallDag(TIntermNode *root) |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 581 | { |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 582 | mCallDag.clear(); |
| 583 | |
| 584 | switch (mCallDag.init(root, &infoSink.info)) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 585 | { |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 586 | case CallDAG::INITDAG_SUCCESS: |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 587 | return true; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 588 | case CallDAG::INITDAG_RECURSION: |
| 589 | infoSink.info.prefix(EPrefixError); |
| 590 | infoSink.info << "Function recursion detected"; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 591 | return false; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 592 | case CallDAG::INITDAG_UNDEFINED: |
| 593 | infoSink.info.prefix(EPrefixError); |
| 594 | infoSink.info << "Unimplemented function detected"; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 595 | return false; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | UNREACHABLE(); |
| 599 | return true; |
| 600 | } |
| 601 | |
| 602 | bool TCompiler::checkCallDepth() |
| 603 | { |
| 604 | std::vector<int> depths(mCallDag.size()); |
| 605 | |
| 606 | for (size_t i = 0; i < mCallDag.size(); i++) |
| 607 | { |
| 608 | int depth = 0; |
| 609 | auto &record = mCallDag.getRecordFromIndex(i); |
| 610 | |
| 611 | for (auto &calleeIndex : record.callees) |
| 612 | { |
| 613 | depth = std::max(depth, depths[calleeIndex] + 1); |
| 614 | } |
| 615 | |
| 616 | depths[i] = depth; |
| 617 | |
| 618 | if (depth >= maxCallStackDepth) |
| 619 | { |
| 620 | // Trace back the function chain to have a meaningful info log. |
| 621 | infoSink.info.prefix(EPrefixError); |
| 622 | infoSink.info << "Call stack too deep (larger than " << maxCallStackDepth |
| 623 | << ") with the following call chain: " << record.name; |
| 624 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 625 | int currentFunction = static_cast<int>(i); |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 626 | int currentDepth = depth; |
| 627 | |
| 628 | while (currentFunction != -1) |
| 629 | { |
| 630 | infoSink.info << " -> " << mCallDag.getRecordFromIndex(currentFunction).name; |
| 631 | |
| 632 | int nextFunction = -1; |
| 633 | for (auto& calleeIndex : mCallDag.getRecordFromIndex(currentFunction).callees) |
| 634 | { |
| 635 | if (depths[calleeIndex] == currentDepth - 1) |
| 636 | { |
| 637 | currentDepth--; |
| 638 | nextFunction = calleeIndex; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | currentFunction = nextFunction; |
| 643 | } |
| 644 | |
| 645 | return false; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | return true; |
| 650 | } |
| 651 | |
| 652 | bool TCompiler::tagUsedFunctions() |
| 653 | { |
| 654 | // 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] | 655 | for (size_t i = mCallDag.size(); i-- > 0;) |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 656 | { |
| 657 | if (mCallDag.getRecordFromIndex(i).name == "main(") |
| 658 | { |
| 659 | internalTagUsedFunction(i); |
| 660 | return true; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | infoSink.info.prefix(EPrefixError); |
Olli Etuaho | 792a41d | 2015-12-15 12:39:16 +0200 | [diff] [blame] | 665 | infoSink.info << "Missing main()\n"; |
Corentin Wallez | 71d147f | 2015-02-11 11:15:24 -0800 | [diff] [blame] | 666 | return false; |
| 667 | } |
| 668 | |
| 669 | void TCompiler::internalTagUsedFunction(size_t index) |
| 670 | { |
| 671 | if (functionMetadata[index].used) |
| 672 | { |
| 673 | return; |
| 674 | } |
| 675 | |
| 676 | functionMetadata[index].used = true; |
| 677 | |
| 678 | for (int calleeIndex : mCallDag.getRecordFromIndex(index).callees) |
| 679 | { |
| 680 | internalTagUsedFunction(calleeIndex); |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 684 | // A predicate for the stl that returns if a top-level node is unused |
| 685 | class TCompiler::UnusedPredicate |
| 686 | { |
| 687 | public: |
| 688 | UnusedPredicate(const CallDAG *callDag, const std::vector<FunctionMetadata> *metadatas) |
| 689 | : mCallDag(callDag), |
| 690 | mMetadatas(metadatas) |
| 691 | { |
| 692 | } |
| 693 | |
| 694 | bool operator ()(TIntermNode *node) |
| 695 | { |
| 696 | const TIntermAggregate *asAggregate = node->getAsAggregate(); |
| 697 | |
| 698 | if (asAggregate == nullptr) |
| 699 | { |
| 700 | return false; |
| 701 | } |
| 702 | |
| 703 | if (!(asAggregate->getOp() == EOpFunction || asAggregate->getOp() == EOpPrototype)) |
| 704 | { |
| 705 | return false; |
| 706 | } |
| 707 | |
| 708 | size_t callDagIndex = mCallDag->findIndex(asAggregate); |
| 709 | if (callDagIndex == CallDAG::InvalidIndex) |
| 710 | { |
| 711 | // This happens only for unimplemented prototypes which are thus unused |
| 712 | ASSERT(asAggregate->getOp() == EOpPrototype); |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | ASSERT(callDagIndex < mMetadatas->size()); |
| 717 | return !(*mMetadatas)[callDagIndex].used; |
| 718 | } |
| 719 | |
| 720 | private: |
| 721 | const CallDAG *mCallDag; |
| 722 | const std::vector<FunctionMetadata> *mMetadatas; |
| 723 | }; |
| 724 | |
| 725 | bool TCompiler::pruneUnusedFunctions(TIntermNode *root) |
| 726 | { |
| 727 | TIntermAggregate *rootNode = root->getAsAggregate(); |
| 728 | ASSERT(rootNode != nullptr); |
| 729 | |
| 730 | UnusedPredicate isUnused(&mCallDag, &functionMetadata); |
| 731 | TIntermSequence *sequence = rootNode->getSequence(); |
Corentin Wallez | b081e78 | 2015-07-20 05:40:04 -0700 | [diff] [blame] | 732 | |
| 733 | if (!sequence->empty()) |
| 734 | { |
| 735 | sequence->erase(std::remove_if(sequence->begin(), sequence->end(), isUnused), sequence->end()); |
| 736 | } |
Corentin Wallez | a094a8a | 2015-04-07 11:53:06 -0700 | [diff] [blame] | 737 | |
| 738 | return true; |
| 739 | } |
| 740 | |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 741 | bool TCompiler::validateOutputs(TIntermNode* root) |
| 742 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 743 | ValidateOutputs validateOutputs(getExtensionBehavior(), compileResources.MaxDrawBuffers); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 744 | root->traverse(&validateOutputs); |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 745 | return (validateOutputs.validateAndCountErrors(infoSink.info) == 0); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 746 | } |
| 747 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 748 | bool TCompiler::validateLimitations(TIntermNode* root) |
| 749 | { |
Olli Etuaho | 8a76dcc | 2015-12-10 20:25:12 +0200 | [diff] [blame] | 750 | ValidateLimitations validate(shaderType, &infoSink.info); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 751 | root->traverse(&validate); |
| 752 | return validate.numErrors() == 0; |
| 753 | } |
| 754 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 755 | bool TCompiler::limitExpressionComplexity(TIntermNode* root) |
| 756 | { |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 757 | TMaxDepthTraverser traverser(maxExpressionComplexity+1); |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 758 | root->traverse(&traverser); |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 759 | |
| 760 | if (traverser.getMaxDepth() > maxExpressionComplexity) |
| 761 | { |
| 762 | infoSink.info << "Expression too complex."; |
| 763 | return false; |
| 764 | } |
| 765 | |
Olli Etuaho | 19d1dc9 | 2016-03-08 17:18:46 +0200 | [diff] [blame] | 766 | if (!ValidateMaxParameters::validate(root, maxFunctionParameters)) |
| 767 | { |
| 768 | infoSink.info << "Function has too many parameters."; |
| 769 | return false; |
| 770 | } |
| 771 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 772 | return true; |
| 773 | } |
| 774 | |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 775 | void TCompiler::collectVariables(TIntermNode* root) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 776 | { |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 777 | if (!variablesCollected) |
| 778 | { |
| 779 | sh::CollectVariables collect(&attributes, &outputVariables, &uniforms, &varyings, |
| 780 | &interfaceBlocks, hashFunction, symbolTable, extensionBehavior); |
| 781 | root->traverse(&collect); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 782 | |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 783 | // This is for enforcePackingRestriction(). |
| 784 | sh::ExpandUniforms(uniforms, &expandedUniforms); |
| 785 | variablesCollected = true; |
| 786 | } |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 787 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 788 | |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 789 | bool TCompiler::enforcePackingRestrictions() |
| 790 | { |
| 791 | VariablePacker packer; |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 792 | return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms); |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 795 | void TCompiler::initializeGLPosition(TIntermNode* root) |
| 796 | { |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 797 | InitVariableList list; |
| 798 | sh::ShaderVariable var(GL_FLOAT_VEC4, 0); |
| 799 | var.name = "gl_Position"; |
| 800 | list.push_back(var); |
| 801 | InitializeVariables(root, list); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 802 | } |
| 803 | |
Olli Etuaho | 27776e3 | 2016-07-22 14:00:56 +0300 | [diff] [blame] | 804 | void TCompiler::initializeOutputVariables(TIntermNode *root) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 805 | { |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 806 | InitVariableList list; |
| 807 | if (shaderType == GL_VERTEX_SHADER) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 808 | { |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 809 | for (auto var : varyings) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 810 | { |
Zhenyao Mo | f931268 | 2016-07-22 12:51:31 -0700 | [diff] [blame] | 811 | list.push_back(var); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 812 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 813 | } |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 814 | else |
| 815 | { |
| 816 | ASSERT(shaderType == GL_FRAGMENT_SHADER); |
| 817 | for (auto var : outputVariables) |
| 818 | { |
| 819 | list.push_back(var); |
| 820 | } |
| 821 | } |
| 822 | InitializeVariables(root, list); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 823 | } |
| 824 | |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 825 | const TExtensionBehavior& TCompiler::getExtensionBehavior() const |
| 826 | { |
| 827 | return extensionBehavior; |
| 828 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 829 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 830 | const char *TCompiler::getSourcePath() const |
| 831 | { |
| 832 | return mSourcePath; |
| 833 | } |
| 834 | |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 835 | const ShBuiltInResources& TCompiler::getResources() const |
| 836 | { |
| 837 | return compileResources; |
| 838 | } |
| 839 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 840 | const ArrayBoundsClamper& TCompiler::getArrayBoundsClamper() const |
| 841 | { |
| 842 | return arrayBoundsClamper; |
| 843 | } |
| 844 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 845 | ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const |
| 846 | { |
| 847 | return clampingStrategy; |
| 848 | } |
| 849 | |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 850 | const BuiltInFunctionEmulator& TCompiler::getBuiltInFunctionEmulator() const |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 851 | { |
| 852 | return builtInFunctionEmulator; |
| 853 | } |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 854 | |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 855 | void TCompiler::writePragma(int compileOptions) |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 856 | { |
Kenneth Russell | bccc65d | 2016-07-19 16:48:43 -0700 | [diff] [blame] | 857 | if (!(compileOptions & SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL)) |
| 858 | { |
| 859 | TInfoSinkBase &sink = infoSink.obj; |
| 860 | if (mPragma.stdgl.invariantAll) |
| 861 | sink << "#pragma STDGL invariant(all)\n"; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | bool TCompiler::isVaryingDefined(const char *varyingName) |
| 866 | { |
| 867 | ASSERT(variablesCollected); |
| 868 | for (size_t ii = 0; ii < varyings.size(); ++ii) |
| 869 | { |
| 870 | if (varyings[ii].name == varyingName) |
| 871 | { |
| 872 | return true; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | return false; |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 877 | } |