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