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