blob: 59cccb565ffb6f7fec663c417b309314f3afd34a [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:
Jamie Madill183bde52014-07-02 15:31:19 -040020 ValidateLimitations(sh::GLenum shaderType, TInfoSinkBase &sink);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000021
22 int numErrors() const { return mNumErrors; }
23
Zhenyao Mo550c6002014-02-26 15:40:48 -080024 virtual bool visitBinary(Visit, TIntermBinary *);
25 virtual bool visitUnary(Visit, TIntermUnary *);
26 virtual bool visitAggregate(Visit, TIntermAggregate *);
27 virtual bool visitLoop(Visit, TIntermLoop *);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000028
Zhenyao Mo550c6002014-02-26 15:40:48 -080029 private:
30 void error(TSourceLoc loc, const char *reason, const char *token);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000031
32 bool withinLoopBody() const;
Zhenyao Mo550c6002014-02-26 15:40:48 -080033 bool isLoopIndex(TIntermSymbol *symbol);
34 bool validateLoopType(TIntermLoop *node);
35
36 bool validateForLoopHeader(TIntermLoop *node);
37 // If valid, return the index symbol id; Otherwise, return -1.
38 int validateForLoopInit(TIntermLoop *node);
39 bool validateForLoopCond(TIntermLoop *node, int indexSymbolId);
40 bool validateForLoopExpr(TIntermLoop *node, int indexSymbolId);
41
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000042 // Returns true if none of the loop indices is used as the argument to
43 // the given function out or inout parameter.
Zhenyao Mo550c6002014-02-26 15:40:48 -080044 bool validateFunctionCall(TIntermAggregate *node);
45 bool validateOperation(TIntermOperator *node, TIntermNode *operand);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000046
47 // Returns true if indexing does not exceed the minimum functionality
48 // mandated in GLSL 1.0 spec, Appendix A, Section 5.
Zhenyao Mo550c6002014-02-26 15:40:48 -080049 bool isConstExpr(TIntermNode *node);
50 bool isConstIndexExpr(TIntermNode *node);
51 bool validateIndexing(TIntermBinary *node);
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000052
Jamie Madill183bde52014-07-02 15:31:19 -040053 sh::GLenum mShaderType;
Zhenyao Mo550c6002014-02-26 15:40:48 -080054 TInfoSinkBase &mSink;
alokp@chromium.orgb59a7782010-11-24 18:38:33 +000055 int mNumErrors;
56 TLoopStack mLoopStack;
57};
58
Geoff Lang0a73dd82014-11-19 16:18:08 -050059#endif // COMPILER_TRANSLATOR_VALIDATELIMITATIONS_H_