1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/ValidateLimitations.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +// 1.5 +// Copyright (c) 2010 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +#include "GLSLANG/ShaderLang.h" 1.11 +#include "compiler/intermediate.h" 1.12 + 1.13 +class TInfoSinkBase; 1.14 + 1.15 +struct TLoopInfo { 1.16 + struct TIndex { 1.17 + int id; // symbol id. 1.18 + } index; 1.19 + TIntermLoop* loop; 1.20 +}; 1.21 +typedef TVector<TLoopInfo> TLoopStack; 1.22 + 1.23 +// Traverses intermediate tree to ensure that the shader does not exceed the 1.24 +// minimum functionality mandated in GLSL 1.0 spec, Appendix A. 1.25 +class ValidateLimitations : public TIntermTraverser { 1.26 +public: 1.27 + ValidateLimitations(ShShaderType shaderType, TInfoSinkBase& sink); 1.28 + 1.29 + int numErrors() const { return mNumErrors; } 1.30 + 1.31 + virtual bool visitBinary(Visit, TIntermBinary*); 1.32 + virtual bool visitUnary(Visit, TIntermUnary*); 1.33 + virtual bool visitAggregate(Visit, TIntermAggregate*); 1.34 + virtual bool visitLoop(Visit, TIntermLoop*); 1.35 + 1.36 +private: 1.37 + void error(TSourceLoc loc, const char *reason, const char* token); 1.38 + 1.39 + bool withinLoopBody() const; 1.40 + bool isLoopIndex(const TIntermSymbol* symbol) const; 1.41 + bool validateLoopType(TIntermLoop* node); 1.42 + bool validateForLoopHeader(TIntermLoop* node, TLoopInfo* info); 1.43 + bool validateForLoopInit(TIntermLoop* node, TLoopInfo* info); 1.44 + bool validateForLoopCond(TIntermLoop* node, TLoopInfo* info); 1.45 + bool validateForLoopExpr(TIntermLoop* node, TLoopInfo* info); 1.46 + // Returns true if none of the loop indices is used as the argument to 1.47 + // the given function out or inout parameter. 1.48 + bool validateFunctionCall(TIntermAggregate* node); 1.49 + bool validateOperation(TIntermOperator* node, TIntermNode* operand); 1.50 + 1.51 + // Returns true if indexing does not exceed the minimum functionality 1.52 + // mandated in GLSL 1.0 spec, Appendix A, Section 5. 1.53 + bool isConstExpr(TIntermNode* node); 1.54 + bool isConstIndexExpr(TIntermNode* node); 1.55 + bool validateIndexing(TIntermBinary* node); 1.56 + 1.57 + ShShaderType mShaderType; 1.58 + TInfoSinkBase& mSink; 1.59 + int mNumErrors; 1.60 + TLoopStack mLoopStack; 1.61 +}; 1.62 +