blob: 4c84f9db7e3852dd2da0cbf245bbd4ee27d94ad8 [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"
Zhenyao Mo550c6002014-02-26 15:40:48 -080011#include "compiler/translator/LoopInfo.h"
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000012
Jamie Madill45bcc782016-11-07 13:58:48 -050013namespace sh
14{
15
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000016class TInfoSinkBase;
17
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000018// Traverses intermediate tree to ensure that the shader does not exceed the
19// minimum functionality mandated in GLSL 1.0 spec, Appendix A.
Zhenyao Mo550c6002014-02-26 15:40:48 -080020class ValidateLimitations : public TIntermTraverser
21{
22 public:
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020023 ValidateLimitations(sh::GLenum shaderType, TInfoSinkBase *sink);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000024
25 int numErrors() const { return mNumErrors; }
26
Corentin Walleze5a1f272015-08-21 02:58:25 +020027 bool visitBinary(Visit, TIntermBinary *) override;
28 bool visitUnary(Visit, TIntermUnary *) override;
29 bool visitAggregate(Visit, TIntermAggregate *) override;
30 bool visitLoop(Visit, TIntermLoop *) override;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000031
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020032 static bool IsLimitedForLoop(TIntermLoop *node);
33
Zhenyao Mo550c6002014-02-26 15:40:48 -080034 private:
35 void error(TSourceLoc loc, const char *reason, const char *token);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000036
37 bool withinLoopBody() const;
Zhenyao Mo550c6002014-02-26 15:40:48 -080038 bool isLoopIndex(TIntermSymbol *symbol);
39 bool validateLoopType(TIntermLoop *node);
40
41 bool validateForLoopHeader(TIntermLoop *node);
42 // If valid, return the index symbol id; Otherwise, return -1.
43 int validateForLoopInit(TIntermLoop *node);
44 bool validateForLoopCond(TIntermLoop *node, int indexSymbolId);
45 bool validateForLoopExpr(TIntermLoop *node, int indexSymbolId);
46
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000047 // Returns true if none of the loop indices is used as the argument to
48 // the given function out or inout parameter.
Zhenyao Mo550c6002014-02-26 15:40:48 -080049 bool validateFunctionCall(TIntermAggregate *node);
50 bool validateOperation(TIntermOperator *node, TIntermNode *operand);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000051
52 // Returns true if indexing does not exceed the minimum functionality
53 // mandated in GLSL 1.0 spec, Appendix A, Section 5.
Zhenyao Mo550c6002014-02-26 15:40:48 -080054 bool isConstExpr(TIntermNode *node);
55 bool isConstIndexExpr(TIntermNode *node);
56 bool validateIndexing(TIntermBinary *node);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000057
Jamie Madill183bde52014-07-02 15:31:19 -040058 sh::GLenum mShaderType;
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020059 TInfoSinkBase *mSink;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000060 int mNumErrors;
61 TLoopStack mLoopStack;
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020062 bool mValidateIndexing;
63 bool mValidateInnerLoops;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000064};
65
Jamie Madill45bcc782016-11-07 13:58:48 -050066} // namespace sh
67
Geoff Lang0a73dd82014-11-19 16:18:08 -050068#endif // COMPILER_TRANSLATOR_VALIDATELIMITATIONS_H_