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