alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | #include "GLSLANG/ShaderLang.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 8 | #include "compiler/translator/intermediate.h" |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame^] | 9 | #include "compiler/translator/LoopInfo.h" |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 10 | |
| 11 | class TInfoSinkBase; |
| 12 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 13 | // Traverses intermediate tree to ensure that the shader does not exceed the |
| 14 | // minimum functionality mandated in GLSL 1.0 spec, Appendix A. |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame^] | 15 | class ValidateLimitations : public TIntermTraverser |
| 16 | { |
| 17 | public: |
| 18 | ValidateLimitations(ShShaderType shaderType, TInfoSinkBase &sink); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 19 | |
| 20 | int numErrors() const { return mNumErrors; } |
| 21 | |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame^] | 22 | virtual bool visitBinary(Visit, TIntermBinary *); |
| 23 | virtual bool visitUnary(Visit, TIntermUnary *); |
| 24 | virtual bool visitAggregate(Visit, TIntermAggregate *); |
| 25 | virtual bool visitLoop(Visit, TIntermLoop *); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 26 | |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame^] | 27 | private: |
| 28 | void error(TSourceLoc loc, const char *reason, const char *token); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 29 | |
| 30 | bool withinLoopBody() const; |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame^] | 31 | bool isLoopIndex(TIntermSymbol *symbol); |
| 32 | bool validateLoopType(TIntermLoop *node); |
| 33 | |
| 34 | bool validateForLoopHeader(TIntermLoop *node); |
| 35 | // If valid, return the index symbol id; Otherwise, return -1. |
| 36 | int validateForLoopInit(TIntermLoop *node); |
| 37 | bool validateForLoopCond(TIntermLoop *node, int indexSymbolId); |
| 38 | bool validateForLoopExpr(TIntermLoop *node, int indexSymbolId); |
| 39 | |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 40 | // Returns true if none of the loop indices is used as the argument to |
| 41 | // the given function out or inout parameter. |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame^] | 42 | bool validateFunctionCall(TIntermAggregate *node); |
| 43 | bool validateOperation(TIntermOperator *node, TIntermNode *operand); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 44 | |
| 45 | // Returns true if indexing does not exceed the minimum functionality |
| 46 | // mandated in GLSL 1.0 spec, Appendix A, Section 5. |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame^] | 47 | bool isConstExpr(TIntermNode *node); |
| 48 | bool isConstIndexExpr(TIntermNode *node); |
| 49 | bool validateIndexing(TIntermBinary *node); |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 50 | |
| 51 | ShShaderType mShaderType; |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame^] | 52 | TInfoSinkBase &mSink; |
alokp@chromium.org | b59a778 | 2010-11-24 18:38:33 +0000 | [diff] [blame] | 53 | int mNumErrors; |
| 54 | TLoopStack mLoopStack; |
| 55 | }; |
| 56 | |