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