blob: d1bf0e6510bfcbfd6c504bd586c80f1e870cf059 [file] [log] [blame]
alokp@chromium.orgb59a7782010-11-24 18:38:33 +00001//
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 Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_VALIDATELIMITATIONS_H_
8#define COMPILER_TRANSLATOR_VALIDATELIMITATIONS_H_
9
Jamie Madillb1a85f42014-08-19 15:23:24 -040010#include "compiler/translator/IntermNode.h"
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000011
Jamie Madill45bcc782016-11-07 13:58:48 -050012namespace sh
13{
14
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000015class TInfoSinkBase;
16
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000017// Traverses intermediate tree to ensure that the shader does not exceed the
18// minimum functionality mandated in GLSL 1.0 spec, Appendix A.
Zhenyao Mo550c6002014-02-26 15:40:48 -080019class ValidateLimitations : public TIntermTraverser
20{
21 public:
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020022 ValidateLimitations(sh::GLenum shaderType, TInfoSinkBase *sink);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000023
24 int numErrors() const { return mNumErrors; }
25
Corentin Walleze5a1f272015-08-21 02:58:25 +020026 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.orgb59a7782010-11-24 18:38:33 +000030
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020031 static bool IsLimitedForLoop(TIntermLoop *node);
32
Zhenyao Mo550c6002014-02-26 15:40:48 -080033 private:
34 void error(TSourceLoc loc, const char *reason, const char *token);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000035
36 bool withinLoopBody() const;
Zhenyao Mo550c6002014-02-26 15:40:48 -080037 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.orgb59a7782010-11-24 18:38:33 +000046 // Returns true if none of the loop indices is used as the argument to
47 // the given function out or inout parameter.
Zhenyao Mo550c6002014-02-26 15:40:48 -080048 bool validateFunctionCall(TIntermAggregate *node);
49 bool validateOperation(TIntermOperator *node, TIntermNode *operand);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000050
51 // Returns true if indexing does not exceed the minimum functionality
52 // mandated in GLSL 1.0 spec, Appendix A, Section 5.
Zhenyao Mo550c6002014-02-26 15:40:48 -080053 bool isConstExpr(TIntermNode *node);
54 bool isConstIndexExpr(TIntermNode *node);
55 bool validateIndexing(TIntermBinary *node);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000056
Jamie Madill183bde52014-07-02 15:31:19 -040057 sh::GLenum mShaderType;
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020058 TInfoSinkBase *mSink;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000059 int mNumErrors;
Corentin Wallez1b896c62016-11-16 13:10:44 -050060 std::vector<int> mLoopSymbolIds;
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020061 bool mValidateIndexing;
62 bool mValidateInnerLoops;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000063};
64
Jamie Madill45bcc782016-11-07 13:58:48 -050065} // namespace sh
66
Jamie Madilld7b1ab52016-12-12 14:42:19 -050067#endif // COMPILER_TRANSLATOR_VALIDATELIMITATIONS_H_