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