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