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