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