alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 1 | // |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 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 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 7 | #include "compiler/translator/BuiltInFunctionEmulator.h" |
Jamie Madill | d4a3a31 | 2014-06-25 16:04:56 -0400 | [diff] [blame] | 8 | #include "compiler/translator/Compiler.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 9 | #include "compiler/translator/DetectCallDepth.h" |
| 10 | #include "compiler/translator/ForLoopUnroll.h" |
| 11 | #include "compiler/translator/Initialize.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 12 | #include "compiler/translator/InitializeParseContext.h" |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 13 | #include "compiler/translator/InitializeVariables.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 14 | #include "compiler/translator/ParseContext.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 15 | #include "compiler/translator/RenameFunction.h" |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 16 | #include "compiler/translator/ScalarizeVecAndMatConstructorArgs.h" |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 17 | #include "compiler/translator/UnfoldShortCircuitAST.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 18 | #include "compiler/translator/ValidateLimitations.h" |
| 19 | #include "compiler/translator/ValidateOutputs.h" |
| 20 | #include "compiler/translator/VariablePacker.h" |
| 21 | #include "compiler/translator/depgraph/DependencyGraph.h" |
| 22 | #include "compiler/translator/depgraph/DependencyGraphOutput.h" |
| 23 | #include "compiler/translator/timing/RestrictFragmentShaderTiming.h" |
| 24 | #include "compiler/translator/timing/RestrictVertexShaderTiming.h" |
shannon.woods@transgaming.com | da1ed36 | 2013-01-25 21:54:57 +0000 | [diff] [blame] | 25 | #include "third_party/compiler/ArrayBoundsClamper.h" |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 26 | #include "angle_gl.h" |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 27 | #include "common/utilities.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 28 | |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 29 | bool IsWebGLBasedSpec(ShShaderSpec spec) |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 30 | { |
| 31 | return spec == SH_WEBGL_SPEC || spec == SH_CSS_SHADERS_SPEC; |
| 32 | } |
| 33 | |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 34 | size_t GetGlobalMaxTokenSize(ShShaderSpec spec) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 35 | { |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 36 | // WebGL defines a max token legnth of 256, while ES2 leaves max token |
| 37 | // size undefined. ES3 defines a max size of 1024 characters. |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 38 | if (IsWebGLBasedSpec(spec)) |
Jamie Madill | 88f6e94 | 2014-02-19 10:27:53 -0500 | [diff] [blame] | 39 | { |
| 40 | return 256; |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | return 1024; |
| 45 | } |
| 46 | } |
| 47 | |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 48 | namespace { |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 49 | class TScopedPoolAllocator |
| 50 | { |
| 51 | public: |
| 52 | TScopedPoolAllocator(TPoolAllocator* allocator) : mAllocator(allocator) |
| 53 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 54 | mAllocator->push(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 55 | SetGlobalPoolAllocator(mAllocator); |
| 56 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 57 | ~TScopedPoolAllocator() |
| 58 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 59 | SetGlobalPoolAllocator(NULL); |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 60 | mAllocator->pop(); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 63 | private: |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 64 | TPoolAllocator* mAllocator; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 67 | class TScopedSymbolTableLevel |
| 68 | { |
| 69 | public: |
| 70 | TScopedSymbolTableLevel(TSymbolTable* table) : mTable(table) |
| 71 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 72 | ASSERT(mTable->atBuiltInLevel()); |
| 73 | mTable->push(); |
| 74 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 75 | ~TScopedSymbolTableLevel() |
| 76 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 77 | while (!mTable->atBuiltInLevel()) |
| 78 | mTable->pop(); |
| 79 | } |
| 80 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 81 | private: |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 82 | TSymbolTable* mTable; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 83 | }; |
| 84 | } // namespace |
| 85 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 86 | TShHandleBase::TShHandleBase() |
| 87 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 88 | allocator.push(); |
| 89 | SetGlobalPoolAllocator(&allocator); |
| 90 | } |
| 91 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 92 | TShHandleBase::~TShHandleBase() |
| 93 | { |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 94 | SetGlobalPoolAllocator(NULL); |
| 95 | allocator.popAll(); |
| 96 | } |
| 97 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 98 | TCompiler::TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 99 | : shaderType(type), |
zmo@google.com | f420c42 | 2011-09-12 18:27:59 +0000 | [diff] [blame] | 100 | shaderSpec(spec), |
Jamie Madill | 68fe74a | 2014-05-27 12:56:01 -0400 | [diff] [blame] | 101 | outputType(output), |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 102 | maxUniformVectors(0), |
| 103 | maxExpressionComplexity(0), |
| 104 | maxCallStackDepth(0), |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 105 | fragmentPrecisionHigh(false), |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 106 | clampingStrategy(SH_CLAMP_WITH_CLAMP_INTRINSIC), |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame] | 107 | builtInFunctionEmulator(type) |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 108 | { |
| 109 | } |
| 110 | |
| 111 | TCompiler::~TCompiler() |
| 112 | { |
| 113 | } |
| 114 | |
| 115 | bool TCompiler::Init(const ShBuiltInResources& resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 116 | { |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 117 | shaderVersion = 100; |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 118 | maxUniformVectors = (shaderType == GL_VERTEX_SHADER) ? |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 119 | resources.MaxVertexUniformVectors : |
| 120 | resources.MaxFragmentUniformVectors; |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 121 | maxExpressionComplexity = resources.MaxExpressionComplexity; |
| 122 | maxCallStackDepth = resources.MaxCallStackDepth; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 123 | |
| 124 | SetGlobalPoolAllocator(&allocator); |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 125 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 126 | // Generate built-in symbol table. |
| 127 | if (!InitBuiltInSymbolTable(resources)) |
| 128 | return false; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 129 | InitExtensionBehavior(resources, extensionBehavior); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 130 | fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1; |
alokp@chromium.org | bafcbaa | 2010-11-23 19:07:43 +0000 | [diff] [blame] | 131 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 132 | arrayBoundsClamper.SetClampingStrategy(resources.ArrayIndexClampingStrategy); |
| 133 | clampingStrategy = resources.ArrayIndexClampingStrategy; |
| 134 | |
daniel@transgaming.com | c23f461 | 2012-11-28 19:42:57 +0000 | [diff] [blame] | 135 | hashFunction = resources.HashFunction; |
| 136 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 137 | return true; |
| 138 | } |
| 139 | |
| 140 | bool TCompiler::compile(const char* const shaderStrings[], |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 141 | size_t numStrings, |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 142 | int compileOptions) |
| 143 | { |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 144 | TScopedPoolAllocator scopedAlloc(&allocator); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 145 | clearResults(); |
| 146 | |
| 147 | if (numStrings == 0) |
| 148 | return true; |
| 149 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 150 | // If compiling for WebGL, validate loop and indexing as well. |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 151 | if (IsWebGLBasedSpec(shaderSpec)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 152 | compileOptions |= SH_VALIDATE_LOOP_INDEXING; |
alokp@chromium.org | 1f29954 | 2010-11-12 15:50:23 +0000 | [diff] [blame] | 153 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 154 | // First string is path of source file if flag is set. The actual source follows. |
| 155 | const char* sourcePath = NULL; |
shannon.woods@transgaming.com | d64b3da | 2013-02-28 23:19:26 +0000 | [diff] [blame] | 156 | size_t firstSource = 0; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 157 | if (compileOptions & SH_SOURCE_PATH) |
| 158 | { |
| 159 | sourcePath = shaderStrings[0]; |
| 160 | ++firstSource; |
| 161 | } |
| 162 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 163 | TIntermediate intermediate(infoSink); |
| 164 | TParseContext parseContext(symbolTable, extensionBehavior, intermediate, |
zmo@google.com | dc4b4f8 | 2011-06-17 00:42:53 +0000 | [diff] [blame] | 165 | shaderType, shaderSpec, compileOptions, true, |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 166 | sourcePath, infoSink); |
shannon.woods%transgaming.com@gtempaccount.com | cbb6b6a | 2013-04-13 03:27:47 +0000 | [diff] [blame] | 167 | parseContext.fragmentPrecisionHigh = fragmentPrecisionHigh; |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 168 | SetGlobalParseContext(&parseContext); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 169 | |
| 170 | // We preserve symbols at the built-in level from compile-to-compile. |
| 171 | // Start pushing the user-defined symbols at global level. |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 172 | TScopedSymbolTableLevel scopedSymbolLevel(&symbolTable); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 173 | |
| 174 | // Parse shader. |
| 175 | bool success = |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 176 | (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) && |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 177 | (parseContext.treeRoot != NULL); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 178 | |
shannon.woods%transgaming.com@gtempaccount.com | 5524db0 | 2013-04-13 03:38:16 +0000 | [diff] [blame] | 179 | shaderVersion = parseContext.getShaderVersion(); |
shannon.woods%transgaming.com@gtempaccount.com | 0bbed38 | 2013-04-13 03:38:07 +0000 | [diff] [blame] | 180 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 181 | if (success) |
| 182 | { |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 183 | TIntermNode* root = parseContext.treeRoot; |
| 184 | success = intermediate.postProcess(root); |
| 185 | |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 186 | // Disallow expressions deemed too complex. |
| 187 | if (success && (compileOptions & SH_LIMIT_EXPRESSION_COMPLEXITY)) |
| 188 | success = limitExpressionComplexity(root); |
| 189 | |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 190 | if (success) |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 191 | success = detectCallDepth(root, infoSink, (compileOptions & SH_LIMIT_CALL_STACK_DEPTH) != 0); |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 192 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 193 | if (success && shaderVersion == 300 && shaderType == GL_FRAGMENT_SHADER) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 194 | success = validateOutputs(root); |
| 195 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 196 | if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING)) |
| 197 | success = validateLimitations(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 198 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 199 | if (success && (compileOptions & SH_TIMING_RESTRICTIONS)) |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 200 | success = enforceTimingRestrictions(root, (compileOptions & SH_DEPENDENCY_GRAPH) != 0); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 201 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 202 | if (success && shaderSpec == SH_CSS_SHADERS_SPEC) |
| 203 | rewriteCSSShader(root); |
| 204 | |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 205 | // Unroll for-loop markup needs to happen after validateLimitations pass. |
| 206 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX)) |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 207 | { |
| 208 | ForLoopUnrollMarker marker(ForLoopUnrollMarker::kIntegerIndex); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 209 | root->traverse(&marker); |
| 210 | } |
| 211 | if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX)) |
Zhenyao Mo | 3cdfcce | 2014-03-07 13:00:08 -0800 | [diff] [blame] | 212 | { |
| 213 | ForLoopUnrollMarker marker(ForLoopUnrollMarker::kSamplerArrayIndex); |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 214 | root->traverse(&marker); |
| 215 | if (marker.samplerArrayIndexIsFloatLoopIndex()) |
| 216 | { |
| 217 | infoSink.info.prefix(EPrefixError); |
| 218 | infoSink.info << "sampler array index is float loop index"; |
| 219 | success = false; |
| 220 | } |
| 221 | } |
zmo@google.com | 0c6bb7a | 2011-08-17 19:39:58 +0000 | [diff] [blame] | 222 | |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 223 | // Built-in function emulation needs to happen after validateLimitations pass. |
| 224 | if (success && (compileOptions & SH_EMULATE_BUILT_IN_FUNCTIONS)) |
| 225 | builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(root); |
| 226 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 227 | // Clamping uniform array bounds needs to happen after validateLimitations pass. |
| 228 | if (success && (compileOptions & SH_CLAMP_INDIRECT_ARRAY_BOUNDS)) |
| 229 | arrayBoundsClamper.MarkIndirectArrayBoundsForClamping(root); |
| 230 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 231 | if (success && shaderType == GL_VERTEX_SHADER && (compileOptions & SH_INIT_GL_POSITION)) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 232 | initializeGLPosition(root); |
Zhenyao Mo | ac44cd2 | 2013-09-23 14:57:09 -0400 | [diff] [blame] | 233 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 234 | if (success && (compileOptions & SH_UNFOLD_SHORT_CIRCUIT)) |
| 235 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 236 | UnfoldShortCircuitAST unfoldShortCircuit; |
| 237 | root->traverse(&unfoldShortCircuit); |
| 238 | unfoldShortCircuit.updateTree(); |
| 239 | } |
| 240 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 241 | if (success && (compileOptions & SH_VARIABLES)) |
| 242 | { |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 243 | collectVariables(root); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 244 | if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) |
| 245 | { |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 246 | success = enforcePackingRestrictions(); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 247 | if (!success) |
| 248 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 249 | infoSink.info.prefix(EPrefixError); |
| 250 | infoSink.info << "too many uniforms"; |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 251 | } |
| 252 | } |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 253 | if (success && shaderType == GL_VERTEX_SHADER && |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 254 | (compileOptions & SH_INIT_VARYINGS_WITHOUT_STATIC_USE)) |
| 255 | initializeVaryingsWithoutStaticUse(root); |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 256 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 257 | |
Zhenyao Mo | cd68fe7 | 2014-07-11 10:45:44 -0700 | [diff] [blame] | 258 | if (success && (compileOptions & SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS)) |
| 259 | { |
| 260 | ScalarizeVecAndMatConstructorArgs scalarizer; |
| 261 | root->traverse(&scalarizer); |
| 262 | } |
| 263 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 264 | if (success && (compileOptions & SH_INTERMEDIATE_TREE)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 265 | intermediate.outputTree(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 266 | |
alokp@chromium.org | 4888ceb | 2010-10-01 21:13:12 +0000 | [diff] [blame] | 267 | if (success && (compileOptions & SH_OBJECT_CODE)) |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 268 | translate(root); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | // Cleanup memory. |
| 272 | intermediate.remove(parseContext.treeRoot); |
Zhenyao Mo | 7faf1a1 | 2014-04-25 18:03:56 -0700 | [diff] [blame] | 273 | SetGlobalParseContext(NULL); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 274 | return success; |
| 275 | } |
| 276 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 277 | bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 278 | { |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 279 | compileResources = resources; |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 280 | setResourceString(); |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 281 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 282 | assert(symbolTable.isEmpty()); |
| 283 | symbolTable.push(); // COMMON_BUILTINS |
| 284 | symbolTable.push(); // ESSL1_BUILTINS |
| 285 | symbolTable.push(); // ESSL3_BUILTINS |
shannonwoods@chromium.org | 2ac0be9 | 2013-05-30 00:02:27 +0000 | [diff] [blame] | 286 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 287 | TPublicType integer; |
| 288 | integer.type = EbtInt; |
| 289 | integer.primarySize = 1; |
| 290 | integer.secondarySize = 1; |
| 291 | integer.array = false; |
| 292 | |
| 293 | TPublicType floatingPoint; |
| 294 | floatingPoint.type = EbtFloat; |
| 295 | floatingPoint.primarySize = 1; |
| 296 | floatingPoint.secondarySize = 1; |
| 297 | floatingPoint.array = false; |
| 298 | |
Zhenyao Mo | a5a1dfc | 2013-09-23 14:57:03 -0400 | [diff] [blame] | 299 | TPublicType sampler; |
| 300 | sampler.primarySize = 1; |
| 301 | sampler.secondarySize = 1; |
| 302 | sampler.array = false; |
| 303 | |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 304 | switch(shaderType) |
| 305 | { |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 306 | case GL_FRAGMENT_SHADER: |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 307 | symbolTable.setDefaultPrecision(integer, EbpMedium); |
| 308 | break; |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 309 | case GL_VERTEX_SHADER: |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 310 | symbolTable.setDefaultPrecision(integer, EbpHigh); |
| 311 | symbolTable.setDefaultPrecision(floatingPoint, EbpHigh); |
| 312 | break; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 313 | default: |
| 314 | assert(false && "Language not supported"); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 315 | } |
Zhenyao Mo | a5a1dfc | 2013-09-23 14:57:03 -0400 | [diff] [blame] | 316 | // We set defaults for all the sampler types, even those that are |
| 317 | // only available if an extension exists. |
| 318 | for (int samplerType = EbtGuardSamplerBegin + 1; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 319 | samplerType < EbtGuardSamplerEnd; ++samplerType) |
| 320 | { |
Zhenyao Mo | a5a1dfc | 2013-09-23 14:57:03 -0400 | [diff] [blame] | 321 | sampler.type = static_cast<TBasicType>(samplerType); |
| 322 | symbolTable.setDefaultPrecision(sampler, EbpLow); |
| 323 | } |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 324 | |
Jamie Madill | 1b45214 | 2013-07-12 14:51:11 -0400 | [diff] [blame] | 325 | InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 326 | |
| 327 | IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable); |
| 328 | |
| 329 | return true; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Shannon Woods | 2d76e5f | 2014-05-16 17:46:41 -0400 | [diff] [blame] | 332 | void TCompiler::setResourceString() |
| 333 | { |
| 334 | std::ostringstream strstream; |
| 335 | strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs |
| 336 | << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors |
| 337 | << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors |
| 338 | << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits |
| 339 | << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits |
| 340 | << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits |
| 341 | << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors |
| 342 | << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers |
| 343 | << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives |
| 344 | << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external |
| 345 | << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle |
| 346 | << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers |
| 347 | << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh |
| 348 | << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity |
| 349 | << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth |
| 350 | << ":EXT_frag_depth:" << compileResources.EXT_frag_depth |
| 351 | << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod |
| 352 | << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors |
| 353 | << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors |
| 354 | << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset |
| 355 | << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset; |
| 356 | |
| 357 | builtInResourcesString = strstream.str(); |
| 358 | } |
| 359 | |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 360 | void TCompiler::clearResults() |
| 361 | { |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 362 | arrayBoundsClamper.Cleanup(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 363 | infoSink.info.erase(); |
| 364 | infoSink.obj.erase(); |
| 365 | infoSink.debug.erase(); |
| 366 | |
Jamie Madill | ed27c72 | 2014-07-02 15:31:23 -0400 | [diff] [blame] | 367 | attributes.clear(); |
| 368 | outputVariables.clear(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 369 | uniforms.clear(); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 370 | expandedUniforms.clear(); |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 371 | varyings.clear(); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 372 | expandedVaryings.clear(); |
Jamie Madill | ed27c72 | 2014-07-02 15:31:23 -0400 | [diff] [blame] | 373 | interfaceBlocks.clear(); |
zmo@google.com | a3b4ab4 | 2011-09-16 00:53:26 +0000 | [diff] [blame] | 374 | |
| 375 | builtInFunctionEmulator.Cleanup(); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 376 | |
| 377 | nameMap.clear(); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 380 | bool TCompiler::detectCallDepth(TIntermNode* root, TInfoSink& infoSink, bool limitCallStackDepth) |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 381 | { |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 382 | DetectCallDepth detect(infoSink, limitCallStackDepth, maxCallStackDepth); |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 383 | root->traverse(&detect); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 384 | switch (detect.detectCallDepth()) |
| 385 | { |
| 386 | case DetectCallDepth::kErrorNone: |
| 387 | return true; |
| 388 | case DetectCallDepth::kErrorMissingMain: |
| 389 | infoSink.info.prefix(EPrefixError); |
| 390 | infoSink.info << "Missing main()"; |
| 391 | return false; |
| 392 | case DetectCallDepth::kErrorRecursion: |
| 393 | infoSink.info.prefix(EPrefixError); |
| 394 | infoSink.info << "Function recursion detected"; |
| 395 | return false; |
| 396 | case DetectCallDepth::kErrorMaxDepthExceeded: |
| 397 | infoSink.info.prefix(EPrefixError); |
| 398 | infoSink.info << "Function call stack too deep"; |
| 399 | return false; |
| 400 | default: |
| 401 | UNREACHABLE(); |
| 402 | return false; |
zmo@google.com | b1762df | 2011-07-30 02:04:23 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 406 | bool TCompiler::validateOutputs(TIntermNode* root) |
| 407 | { |
| 408 | ValidateOutputs validateOutputs(infoSink.info, compileResources.MaxDrawBuffers); |
| 409 | root->traverse(&validateOutputs); |
| 410 | return (validateOutputs.numErrors() == 0); |
| 411 | } |
| 412 | |
maxvujovic@gmail.com | 430f5e0 | 2012-06-08 17:47:59 +0000 | [diff] [blame] | 413 | void TCompiler::rewriteCSSShader(TIntermNode* root) |
| 414 | { |
| 415 | RenameFunction renamer("main(", "css_main("); |
| 416 | root->traverse(&renamer); |
| 417 | } |
| 418 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 419 | bool TCompiler::validateLimitations(TIntermNode* root) |
| 420 | { |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 421 | ValidateLimitations validate(shaderType, infoSink.info); |
| 422 | root->traverse(&validate); |
| 423 | return validate.numErrors() == 0; |
| 424 | } |
| 425 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 426 | bool TCompiler::enforceTimingRestrictions(TIntermNode* root, bool outputGraph) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 427 | { |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 428 | if (shaderSpec != SH_WEBGL_SPEC) |
| 429 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 430 | infoSink.info << "Timing restrictions must be enforced under the WebGL spec."; |
| 431 | return false; |
| 432 | } |
| 433 | |
Jamie Madill | 183bde5 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 434 | if (shaderType == GL_FRAGMENT_SHADER) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 435 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 436 | TDependencyGraph graph(root); |
| 437 | |
| 438 | // Output any errors first. |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 439 | bool success = enforceFragmentShaderTimingRestrictions(graph); |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 440 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 441 | // Then, output the dependency graph. |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 442 | if (outputGraph) |
| 443 | { |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 444 | TDependencyGraphOutput output(infoSink.info); |
| 445 | output.outputAllSpanningTrees(graph); |
| 446 | } |
Jamie Madill | 5508f39 | 2014-02-20 13:31:36 -0500 | [diff] [blame] | 447 | |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 448 | return success; |
| 449 | } |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 450 | else |
| 451 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 452 | return enforceVertexShaderTimingRestrictions(root); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 456 | bool TCompiler::limitExpressionComplexity(TIntermNode* root) |
| 457 | { |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 458 | TMaxDepthTraverser traverser(maxExpressionComplexity+1); |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 459 | root->traverse(&traverser); |
Jamie Madill | 6654bc9 | 2014-03-26 14:01:57 -0400 | [diff] [blame] | 460 | |
| 461 | if (traverser.getMaxDepth() > maxExpressionComplexity) |
| 462 | { |
| 463 | infoSink.info << "Expression too complex."; |
| 464 | return false; |
| 465 | } |
| 466 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 467 | TDependencyGraph graph(root); |
| 468 | |
| 469 | for (TFunctionCallVector::const_iterator iter = graph.beginUserDefinedFunctionCalls(); |
| 470 | iter != graph.endUserDefinedFunctionCalls(); |
| 471 | ++iter) |
| 472 | { |
| 473 | TGraphFunctionCall* samplerSymbol = *iter; |
| 474 | TDependencyGraphTraverser graphTraverser; |
| 475 | samplerSymbol->traverse(&graphTraverser); |
| 476 | } |
| 477 | |
Jamie Madill | eb1a010 | 2013-07-08 13:31:38 -0400 | [diff] [blame] | 478 | return true; |
| 479 | } |
| 480 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 481 | bool TCompiler::enforceFragmentShaderTimingRestrictions(const TDependencyGraph& graph) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 482 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 483 | RestrictFragmentShaderTiming restrictor(infoSink.info); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 484 | restrictor.enforceRestrictions(graph); |
| 485 | return restrictor.numErrors() == 0; |
| 486 | } |
| 487 | |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 488 | bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root) |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 489 | { |
maxvujovic@gmail.com | 77222c9 | 2012-06-04 21:06:05 +0000 | [diff] [blame] | 490 | RestrictVertexShaderTiming restrictor(infoSink.info); |
maxvujovic@gmail.com | 66ebd01 | 2012-05-30 22:18:11 +0000 | [diff] [blame] | 491 | restrictor.enforceRestrictions(root); |
| 492 | return restrictor.numErrors() == 0; |
| 493 | } |
| 494 | |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 495 | void TCompiler::collectVariables(TIntermNode* root) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 496 | { |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 497 | CollectVariables collect(&attributes, |
| 498 | &outputVariables, |
| 499 | &uniforms, |
| 500 | &varyings, |
| 501 | &interfaceBlocks, |
| 502 | hashFunction); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 503 | root->traverse(&collect); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 504 | |
| 505 | // For backwards compatiblity with ShGetVariableInfo, expand struct |
| 506 | // uniforms and varyings into separate variables for each field. |
| 507 | ExpandVariables(uniforms, &expandedUniforms); |
| 508 | ExpandVariables(varyings, &expandedVaryings); |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 509 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 510 | |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 511 | bool TCompiler::enforcePackingRestrictions() |
| 512 | { |
| 513 | VariablePacker packer; |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 514 | return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms); |
gman@chromium.org | 8d80479 | 2012-10-17 21:33:48 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 517 | void TCompiler::initializeGLPosition(TIntermNode* root) |
| 518 | { |
| 519 | InitializeVariables::InitVariableInfoList variables; |
| 520 | InitializeVariables::InitVariableInfo var( |
| 521 | "gl_Position", TType(EbtFloat, EbpUndefined, EvqPosition, 4)); |
| 522 | variables.push_back(var); |
| 523 | InitializeVariables initializer(variables); |
| 524 | root->traverse(&initializer); |
| 525 | } |
| 526 | |
| 527 | void TCompiler::initializeVaryingsWithoutStaticUse(TIntermNode* root) |
| 528 | { |
| 529 | InitializeVariables::InitVariableInfoList variables; |
| 530 | for (size_t ii = 0; ii < varyings.size(); ++ii) |
| 531 | { |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 532 | const sh::Varying& varying = varyings[ii]; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 533 | if (varying.staticUse) |
| 534 | continue; |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 535 | unsigned char primarySize = static_cast<unsigned char>(gl::VariableColumnCount(varying.type)); |
| 536 | unsigned char secondarySize = static_cast<unsigned char>(gl::VariableRowCount(varying.type)); |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 537 | TType type(EbtFloat, EbpUndefined, EvqVaryingOut, primarySize, secondarySize, varying.isArray()); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 538 | TString name = varying.name.c_str(); |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 539 | if (varying.isArray()) |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 540 | { |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 541 | type.setArraySize(varying.arraySize); |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 542 | name = name.substr(0, name.find_first_of('[')); |
| 543 | } |
| 544 | |
| 545 | InitializeVariables::InitVariableInfo var(name, type); |
| 546 | variables.push_back(var); |
| 547 | } |
| 548 | InitializeVariables initializer(variables); |
| 549 | root->traverse(&initializer); |
| 550 | } |
| 551 | |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 552 | const TExtensionBehavior& TCompiler::getExtensionBehavior() const |
| 553 | { |
| 554 | return extensionBehavior; |
| 555 | } |
zmo@google.com | 32e9731 | 2011-08-24 01:03:11 +0000 | [diff] [blame] | 556 | |
shannon.woods%transgaming.com@gtempaccount.com | 18b4c4b | 2013-04-13 03:31:40 +0000 | [diff] [blame] | 557 | const ShBuiltInResources& TCompiler::getResources() const |
| 558 | { |
| 559 | return compileResources; |
| 560 | } |
| 561 | |
daniel@transgaming.com | 4167cc9 | 2013-01-11 04:11:53 +0000 | [diff] [blame] | 562 | const ArrayBoundsClamper& TCompiler::getArrayBoundsClamper() const |
| 563 | { |
| 564 | return arrayBoundsClamper; |
| 565 | } |
| 566 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 567 | ShArrayIndexClampingStrategy TCompiler::getArrayIndexClampingStrategy() const |
| 568 | { |
| 569 | return clampingStrategy; |
| 570 | } |
| 571 | |
| 572 | const BuiltInFunctionEmulator& TCompiler::getBuiltInFunctionEmulator() const |
| 573 | { |
| 574 | return builtInFunctionEmulator; |
| 575 | } |