blob: 666e38ff5c884be73e9e3085dffd5045de16d3a5 [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
13class TInfoSinkBase;
14
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000015// Traverses intermediate tree to ensure that the shader does not exceed the
16// minimum functionality mandated in GLSL 1.0 spec, Appendix A.
Zhenyao Mo550c6002014-02-26 15:40:48 -080017class ValidateLimitations : public TIntermTraverser
18{
19 public:
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020020 ValidateLimitations(sh::GLenum shaderType, TInfoSinkBase *sink);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000021
22 int numErrors() const { return mNumErrors; }
23
Corentin Walleze5a1f272015-08-21 02:58:25 +020024 bool visitBinary(Visit, TIntermBinary *) override;
25 bool visitUnary(Visit, TIntermUnary *) override;
26 bool visitAggregate(Visit, TIntermAggregate *) override;
27 bool visitLoop(Visit, TIntermLoop *) override;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000028
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020029 static bool IsLimitedForLoop(TIntermLoop *node);
30
Zhenyao Mo550c6002014-02-26 15:40:48 -080031 private:
32 void error(TSourceLoc loc, const char *reason, const char *token);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000033
34 bool withinLoopBody() const;
Zhenyao Mo550c6002014-02-26 15:40:48 -080035 bool isLoopIndex(TIntermSymbol *symbol);
36 bool validateLoopType(TIntermLoop *node);
37
38 bool validateForLoopHeader(TIntermLoop *node);
39 // If valid, return the index symbol id; Otherwise, return -1.
40 int validateForLoopInit(TIntermLoop *node);
41 bool validateForLoopCond(TIntermLoop *node, int indexSymbolId);
42 bool validateForLoopExpr(TIntermLoop *node, int indexSymbolId);
43
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000044 // Returns true if none of the loop indices is used as the argument to
45 // the given function out or inout parameter.
Zhenyao Mo550c6002014-02-26 15:40:48 -080046 bool validateFunctionCall(TIntermAggregate *node);
47 bool validateOperation(TIntermOperator *node, TIntermNode *operand);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000048
49 // Returns true if indexing does not exceed the minimum functionality
50 // mandated in GLSL 1.0 spec, Appendix A, Section 5.
Zhenyao Mo550c6002014-02-26 15:40:48 -080051 bool isConstExpr(TIntermNode *node);
52 bool isConstIndexExpr(TIntermNode *node);
53 bool validateIndexing(TIntermBinary *node);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000054
Jamie Madill183bde52014-07-02 15:31:19 -040055 sh::GLenum mShaderType;
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020056 TInfoSinkBase *mSink;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000057 int mNumErrors;
58 TLoopStack mLoopStack;
Olli Etuaho8a76dcc2015-12-10 20:25:12 +020059 bool mValidateIndexing;
60 bool mValidateInnerLoops;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000061};
62
Geoff Lang0a73dd82014-11-19 16:18:08 -050063#endif // COMPILER_TRANSLATOR_VALIDATELIMITATIONS_H_