/src/skia/third_party/externals/swiftshader/src/OpenGL/compiler/ValidateLimitations.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include "Compiler.h" |
16 | | #include "intermediate.h" |
17 | | |
18 | | class TInfoSinkBase; |
19 | | |
20 | | struct TLoopInfo { |
21 | | struct TIndex { |
22 | | int id; // symbol id. |
23 | | } index; |
24 | | TIntermLoop* loop; |
25 | | }; |
26 | | typedef TVector<TLoopInfo> TLoopStack; |
27 | | |
28 | | // Traverses intermediate tree to ensure that the shader does not exceed the |
29 | | // minimum functionality mandated in GLSL 1.0 spec, Appendix A. |
30 | | class ValidateLimitations : public TIntermTraverser { |
31 | | public: |
32 | | ValidateLimitations(GLenum shaderType, TInfoSinkBase& sink); |
33 | | |
34 | 0 | int numErrors() const { return mNumErrors; } |
35 | | |
36 | | virtual bool visitBinary(Visit, TIntermBinary*); |
37 | | virtual bool visitUnary(Visit, TIntermUnary*); |
38 | | virtual bool visitAggregate(Visit, TIntermAggregate*); |
39 | | virtual bool visitLoop(Visit, TIntermLoop*); |
40 | | |
41 | | private: |
42 | | void error(TSourceLoc loc, const char *reason, const char* token); |
43 | | |
44 | | bool withinLoopBody() const; |
45 | | bool isLoopIndex(const TIntermSymbol* symbol) const; |
46 | | bool validateLoopType(TIntermLoop* node); |
47 | | bool validateForLoopHeader(TIntermLoop* node, TLoopInfo* info); |
48 | | bool validateForLoopInit(TIntermLoop* node, TLoopInfo* info); |
49 | | bool validateForLoopCond(TIntermLoop* node, TLoopInfo* info); |
50 | | bool validateForLoopExpr(TIntermLoop* node, TLoopInfo* info); |
51 | | // Returns true if none of the loop indices is used as the argument to |
52 | | // the given function out or inout parameter. |
53 | | bool validateFunctionCall(TIntermAggregate* node); |
54 | | bool validateOperation(TIntermOperator* node, TIntermNode* operand); |
55 | | |
56 | | // Returns true if indexing does not exceed the minimum functionality |
57 | | // mandated in GLSL 1.0 spec, Appendix A, Section 5. |
58 | | bool isConstExpr(TIntermNode* node); |
59 | | bool isConstIndexExpr(TIntermNode* node); |
60 | | bool validateIndexing(TIntermBinary* node); |
61 | | |
62 | | GLenum mShaderType; |
63 | | TInfoSinkBase& mSink; |
64 | | int mNumErrors; |
65 | | TLoopStack mLoopStack; |
66 | | }; |
67 | | |