alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 1 | // |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 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 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 7 | #include "compiler/BuiltInFunctionEmulator.h" |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 8 | #include "compiler/DetectRecursion.h" |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 9 | #include "compiler/ForLoopUnroll.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 10 | #include "compiler/Initialize.h" |
alokp@chromium.org | 8b851c6 | 2012-06-15 16:25:11 +0000 | [diff] [blame] | 11 | #include "compiler/InitializeParseContext.h" |
zmo@google.com | b9f64aa | 2012-01-20 00:35:15 +0000 | [diff] [blame] | 12 | #include "compiler/MapLongVariableNames.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 13 | #include "compiler/ParseHelper.h" |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 14 | #include "compiler/RenameFunction.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 15 | #include "compiler/ShHandle.h" |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 16 | #include "compiler/ValidateLimitations.h" |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 17 | #include "compiler/VariablePacker.h" |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 18 | #include "compiler/depgraph/DependencyGraph.h" |
| 19 | #include "compiler/depgraph/DependencyGraphOutput.h" |
| 20 | #include "compiler/timing/RestrictFragmentShaderTiming.h" |
| 21 | #include "compiler/timing/RestrictVertexShaderTiming.h" |
shannon.woods@transgaming.com | da1ed36 | 2013-01-25 21:54:57 +0000 | [diff] [blame] | 22 | #include "third_party/compiler/ArrayBoundsClamper.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 23 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 24 | bool isWebGLBasedSpec(ShShaderSpec spec) |
| 25 | { |
| 26 | return spec == SH_WEBGL_SPEC || spec == SH_CSS_SHADERS_SPEC; |
| 27 | } |
| 28 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 29 | namespace { |
| 30 | bool InitializeSymbolTable( |
| 31 | const TBuiltInStrings& builtInStrings, |
| 32 | ShShaderType type, ShShaderSpec spec, const ShBuiltInResources& resources, |
| 33 | TInfoSink& infoSink, TSymbolTable& symbolTable) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 34 | { |
| 35 | TIntermediate intermediate(infoSink); |
| 36 | TExtensionBehavior extBehavior; |
zmo@google.com | 09c323a | 2011-08-12 18:22:25 +0000 | [diff] [blame] | 37 | InitExtensionBehavior(resources, extBehavior); |
zmo@google.com | dc4b4f8 | 2011-06-17 00:42:53 +0000 | [diff] [blame] | 38 | // The builtins deliberately don't specify precisions for the function |
| 39 | // arguments and return types. For that reason we don't try to check them. |
| 40 | TParseContext parseContext(symbolTable, extBehavior, intermediate, type, spec, 0, false, NULL, infoSink); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 41 | parseContext.fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 42 | |
| 43 | GlobalParseContext = &parseContext; |
| 44 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 45 | assert(symbolTable.isEmpty()); |
| 46 | // |
| 47 | // Parse the built-ins. This should only happen once per |
| 48 | // language symbol table. |
| 49 | // |
| 50 | // Push the symbol table to give it an initial scope. This |
| 51 | // push should not have a corresponding pop, so that built-ins |
| 52 | // are preserved, and the test for an empty table fails. |
| 53 | // |
| 54 | symbolTable.push(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 55 | |
| 56 | for (TBuiltInStrings::const_iterator i = builtInStrings.begin(); i != builtInStrings.end(); ++i) |
| 57 | { |
alokp@chromium.org | 570bfc7 | 2010-09-24 17:19:25 +0000 | [diff] [blame] | 58 | const char* builtInShaders = i->c_str(); |
| 59 | int builtInLengths = static_cast<int>(i->size()); |
| 60 | if (builtInLengths <= 0) |
| 61 | continue; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 62 | |
alokp@chromium.org | 044a5cf | 2010-11-12 15:42:16 +0000 | [diff] [blame] | 63 | if (PaParseStrings(1, &builtInShaders, &builtInLengths, &parseContext) != 0) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 64 | { |
| 65 | infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins"); |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 70 | IdentifyBuiltIns(type, spec, resources, symbolTable); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 71 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 72 | return true; |
| 73 | } |
| 74 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 75 | class TScopedPoolAllocator { |
| 76 | public: |
| 77 | TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop) |
| 78 | : mAllocator(allocator), mPushPopAllocator(pushPop) { |
| 79 | if (mPushPopAllocator) mAllocator->push(); |
| 80 | SetGlobalPoolAllocator(mAllocator); |
| 81 | } |
| 82 | ~TScopedPoolAllocator() { |
| 83 | SetGlobalPoolAllocator(NULL); |
| 84 | if (mPushPopAllocator) mAllocator->pop(); |
| 85 | } |
| 86 | |
| 87 | private: |
| 88 | TPoolAllocator* mAllocator; |
| 89 | bool mPushPopAllocator; |
| 90 | }; |
| 91 | } // namespace |
| 92 | |
| 93 | TShHandleBase::TShHandleBase() { |
| 94 | allocator.push(); |
| 95 | SetGlobalPoolAllocator(&allocator); |
| 96 | } |
| 97 | |
| 98 | TShHandleBase::~TShHandleBase() { |
| 99 | SetGlobalPoolAllocator(NULL); |
| 100 | allocator.popAll(); |
| 101 | } |
| 102 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 103 | TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec) |
| 104 | : shaderType(type), |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 105 | shaderSpec(spec), |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 106 | fragmentPrecisionHigh(false), |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 107 | clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC), |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame] | 108 | builtInFunctionEmulator(type) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 109 | { |
zmo@google.com | b9f64aa | 2012-01-20 00:35:15 +0000 | [diff] [blame] | 110 | longNameMap = LongNameMap::GetInstance(); |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | TCompiler::~TCompiler() |
| 114 | { |
zmo@google.com | b9f64aa | 2012-01-20 00:35:15 +0000 | [diff] [blame] | 115 | ASSERT(longNameMap); |
| 116 | longNameMap->Release(); |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | bool TCompiler::Init(const ShBuiltInResources& resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 120 | { |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 121 | shaderVersion = 100; |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 122 | maxUniformVectors = (shaderType == SH_VERTEX_SHADER) ? |
| 123 | resources.MaxVertexUniformVectors : |
| 124 | resources.MaxFragmentUniformVectors; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 125 | TScopedPoolAllocator scopedAlloc(&allocator, false); |
| 126 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 127 | // Generate built-in symbol table. |
| 128 | if (!InitBuiltInSymbolTable(resources)) |
| 129 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 130 | InitExtensionBehavior(resources, extensionBehavior); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 131 | fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 132 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 133 | arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy); |
| 134 | clampingStrategy = resources.ArrayIndexClampingStrategy; |
| 135 | |
daniel@transgaming.com | c23f461 | 2012-11-28 19:42:57 +0000 | [diff] [blame] | 136 | hashFunction = resources.HashFunction; |
| 137 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 138 | return true; |
| 139 | } |
| 140 | |
| 141 | bool TCompiler::compile(const char* const shaderStrings[], |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 142 | size_t numStrings, |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 143 | int compileOptions) |
| 144 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 145 | TScopedPoolAllocator scopedAlloc(&allocator, true); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 146 | clearResults(); |
| 147 | |
| 148 | if (numStrings == 0) |
| 149 | return true; |
| 150 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 151 | // If compiling for WebGL, validate loop and indexing as well. |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 152 | if (isWebGLBasedSpec(shaderSpec)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 153 | compileOptions |= SH_VALIDATE_LOOP_INDEXING; |
alokp@chromium.org | 1f29954 | 2010-11-12 15:50:23 +0000 | [diff] [blame] | 154 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 155 | // First string is path of source file if flag is set. The actual source follows. |
| 156 | const char* sourcePath = NULL; |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 157 | size_t firstSource = 0; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 158 | if (compileOptions & SH_SOURCE_PATH) |
| 159 | { |
| 160 | sourcePath = shaderStrings[0]; |
| 161 | ++firstSource; |
| 162 | } |
| 163 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 164 | TIntermediate intermediate(infoSink); |
| 165 | TParseContext parseContext(symbolTable, extensionBehavior, intermediate, |
zmo@google.com | dc4b4f8 | 2011-06-17 00:42:53 +0000 | [diff] [blame] | 166 | shaderType, shaderSpec, compileOptions, true, |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 167 | sourcePath, infoSink); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 168 | parseContext.fragmentPrecisionHigh = fragmentPrecisionHigh; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 169 | GlobalParseContext = &parseContext; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 170 | |
| 171 | // We preserve symbols at the built-in level from compile-to-compile. |
| 172 | // Start pushing the user-defined symbols at global level. |
| 173 | symbolTable.push(); |
| 174 | if (!symbolTable.atGlobalLevel()) |
| 175 | infoSink.info.message(EPrefixInternalError, "Wrong symbol table level"); |
| 176 | |
| 177 | // Parse shader. |
| 178 | bool success = |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 179 | (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) && |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 180 | (parseContext.treeRoot != NULL); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 181 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 182 | shaderVersion = parseContext.getShaderVersion(); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 183 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 184 | if (success) { |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 185 | TIntermNode* root = parseContext.treeRoot; |
| 186 | success = intermediate.postProcess(root); |
| 187 | |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 188 | if (success) |
| 189 | success = detectRecursion(root); |
| 190 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 191 | if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING)) |
| 192 | success = validateLimitations(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 193 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 194 | if (success && (compileOptions & SH_TIMING_RESTRICTIONS)) |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 195 | success = enforceTimingRestrictions(root, (compileOptions & SH_DEPENDENCY_GRAPH) != 0); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 196 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 197 | if (success && shaderSpec == SH_CSS_SHADERS_SPEC) |
| 198 | rewriteCSSShader(root); |
| 199 | |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 200 | // Unroll for-loop markup needs to happen after validateLimitations pass. |
| 201 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX)) |
| 202 | ForLoopUnroll::MarkForLoopsWithIntegerIndicesForUnrolling(root); |
| 203 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 204 | // Built-in function emulation needs to happen after validateLimitations pass. |
| 205 | if (success && (compileOptions & SH_EMULATE_BUILT_IN_FUNCTIONS)) |
| 206 | builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(root); |
| 207 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 208 | // Clamping uniform array bounds needs to happen after validateLimitations pass. |
| 209 | if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS)) |
| 210 | arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root); |
| 211 | |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 212 | // Call mapLongVariableNames() before collectAttribsUniforms() so in |
| 213 | // collectAttribsUniforms() we already have the mapped symbol names and |
| 214 | // we could composite mapped and original variable names. |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 215 | // Also, if we hash all the names, then no need to do this for long names. |
| 216 | if (success && (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) && hashFunction == NULL) |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 217 | mapLongVariableNames(root); |
| 218 | |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 219 | if (success && (compileOptions & SH_ATTRIBUTES_UNIFORMS)) { |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 220 | collectAttribsUniforms(root); |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 221 | if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) { |
| 222 | success = enforcePackingRestrictions(); |
| 223 | if (!success) { |
| 224 | infoSink.info.message(EPrefixError, "too many uniforms"); |
| 225 | } |
| 226 | } |
| 227 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 228 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 229 | if (success && (compileOptions & SH_INTERMEDIATE_TREE)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 230 | intermediate.outputTree(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 231 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 232 | if (success && (compileOptions & SH_OBJECT_CODE)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 233 | translate(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | // Cleanup memory. |
| 237 | intermediate.remove(parseContext.treeRoot); |
| 238 | // Ensure symbol table is returned to the built-in level, |
| 239 | // throwing away all but the built-ins. |
| 240 | while (!symbolTable.atBuiltInLevel()) |
| 241 | symbolTable.pop(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 242 | |
| 243 | return success; |
| 244 | } |
| 245 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 246 | bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources& resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 247 | { |
| 248 | TBuiltIns builtIns; |
| 249 | |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 250 | compileResources = resources; |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 251 | builtIns.initialize(shaderType, shaderSpec, resources); |
| 252 | return InitializeSymbolTable(builtIns.getBuiltInStrings(), |
| 253 | shaderType, shaderSpec, resources, infoSink, symbolTable); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | void TCompiler::clearResults() |
| 257 | { |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 258 | arrayBoundsClamper.Cleanup(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 259 | infoSink.info.erase(); |
| 260 | infoSink.obj.erase(); |
| 261 | infoSink.debug.erase(); |
| 262 | |
| 263 | attribs.clear(); |
| 264 | uniforms.clear(); |
zmo@google.com | a3b4ab4 | 2011-09-16 00:53:26 +0000 | [diff] [blame] | 265 | |
| 266 | builtInFunctionEmulator.Cleanup(); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 267 | |
| 268 | nameMap.clear(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 269 | } |
| 270 | |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 271 | bool TCompiler::detectRecursion(TIntermNode* root) |
| 272 | { |
| 273 | DetectRecursion detect; |
| 274 | root->traverse(&detect); |
| 275 | switch (detect.detectRecursion()) { |
| 276 | case DetectRecursion::kErrorNone: |
| 277 | return true; |
| 278 | case DetectRecursion::kErrorMissingMain: |
| 279 | infoSink.info.message(EPrefixError, "Missing main()"); |
| 280 | return false; |
| 281 | case DetectRecursion::kErrorRecursion: |
| 282 | infoSink.info.message(EPrefixError, "Function recursion detected"); |
| 283 | return false; |
| 284 | default: |
| 285 | UNREACHABLE(); |
| 286 | return false; |
| 287 | } |
| 288 | } |
| 289 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 290 | void TCompiler::rewriteCSSShader(TIntermNode* root) |
| 291 | { |
| 292 | RenameFunction renamer("main(", "css_main("); |
| 293 | root->traverse(&renamer); |
| 294 | } |
| 295 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 296 | bool TCompiler::validateLimitations(TIntermNode* root) { |
| 297 | ValidateLimitations validate(shaderType, infoSink.info); |
| 298 | root->traverse(&validate); |
| 299 | return validate.numErrors() == 0; |
| 300 | } |
| 301 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 302 | bool TCompiler::enforceTimingRestrictions(TIntermNode* root, bool outputGraph) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 303 | { |
| 304 | if (shaderSpec != SH_WEBGL_SPEC) { |
| 305 | infoSink.info << "Timing restrictions must be enforced under the WebGL spec."; |
| 306 | return false; |
| 307 | } |
| 308 | |
| 309 | if (shaderType == SH_FRAGMENT_SHADER) { |
| 310 | TDependencyGraph graph(root); |
| 311 | |
| 312 | // Output any errors first. |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 313 | bool success = enforceFragmentShaderTimingRestrictions(graph); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 314 | |
| 315 | // Then, output the dependency graph. |
| 316 | if (outputGraph) { |
| 317 | TDependencyGraphOutput output(infoSink.info); |
| 318 | output.outputAllSpanningTrees(graph); |
| 319 | } |
| 320 | |
| 321 | return success; |
| 322 | } |
| 323 | else { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 324 | return enforceVertexShaderTimingRestrictions(root); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 328 | bool TCompiler::enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 329 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 330 | RestrictFragmentShaderTiming restrictor(infoSink.info); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 331 | restrictor.enforceRestrictions(graph); |
| 332 | return restrictor.numErrors() == 0; |
| 333 | } |
| 334 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 335 | bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 336 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 337 | RestrictVertexShaderTiming restrictor(infoSink.info); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 338 | restrictor.enforceRestrictions(root); |
| 339 | return restrictor.numErrors() == 0; |
| 340 | } |
| 341 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 342 | void TCompiler::collectAttribsUniforms(TIntermNode* root) |
| 343 | { |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 344 | CollectAttribsUniforms collect(attribs, uniforms, hashFunction); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 345 | root->traverse(&collect); |
| 346 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 347 | |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 348 | bool TCompiler::enforcePackingRestrictions() |
| 349 | { |
| 350 | VariablePacker packer; |
| 351 | return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, uniforms); |
| 352 | } |
| 353 | |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 354 | void TCompiler::mapLongVariableNames(TIntermNode* root) |
| 355 | { |
zmo@google.com | b9f64aa | 2012-01-20 00:35:15 +0000 | [diff] [blame] | 356 | ASSERT(longNameMap); |
| 357 | MapLongVariableNames map(longNameMap); |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame] | 358 | root->traverse(&map); |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | int TCompiler::getMappedNameMaxLength() const |
| 362 | { |
kbr@chromium.org | 2215211 | 2011-10-26 01:18:28 +0000 | [diff] [blame] | 363 | return MAX_SHORTENED_IDENTIFIER_SIZE + 1; |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 364 | } |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 365 | |
| 366 | const TExtensionBehavior& TCompiler::getExtensionBehavior() const |
| 367 | { |
| 368 | return extensionBehavior; |
| 369 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 370 | |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 371 | const ShBuiltInResources& TCompiler::getResources() const |
| 372 | { |
| 373 | return compileResources; |
| 374 | } |
| 375 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 376 | const ArrayBoundsClamper& TCompiler::getArrayBoundsClamper() const |
| 377 | { |
| 378 | return arrayBoundsClamper; |
| 379 | } |
| 380 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 381 | ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const |
| 382 | { |
| 383 | return clampingStrategy; |
| 384 | } |
| 385 | |
| 386 | const BuiltInFunctionEmulator& TCompiler::getBuiltInFunctionEmulator() const |
| 387 | { |
| 388 | return builtInFunctionEmulator; |
| 389 | } |