• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef sw_SetupProcessor_hpp
16 #define sw_SetupProcessor_hpp
17 
18 #include "Context.hpp"
19 #include "RoutineCache.hpp"
20 #include "Shader/VertexShader.hpp"
21 #include "Shader/PixelShader.hpp"
22 #include "Common/Types.hpp"
23 
24 namespace sw
25 {
26 	struct Primitive;
27 	struct Triangle;
28 	struct Polygon;
29 	struct Vertex;
30 	struct DrawCall;
31 	struct DrawData;
32 
33 	class SetupProcessor
34 	{
35 	public:
36 		struct States
37 		{
38 			unsigned int computeHash();
39 
40 			bool isDrawPoint               : 1;
41 			bool isDrawLine                : 1;
42 			bool isDrawTriangle            : 1;
43 			bool isDrawSolidTriangle       : 1;
44 			bool interpolateZ              : 1;
45 			bool interpolateW              : 1;
46 			bool perspective               : 1;
47 			bool pointSprite               : 1;
48 			unsigned int positionRegister  : BITS(VERTEX_OUTPUT_LAST);
49 			unsigned int pointSizeRegister : BITS(VERTEX_OUTPUT_LAST);
50 			CullMode cullMode              : BITS(CULL_LAST);
51 			bool twoSidedStencil           : 1;
52 			bool slopeDepthBias            : 1;
53 			bool vFace                     : 1;
54 			unsigned int multiSample       : 3;   // 1, 2 or 4
55 			bool rasterizerDiscard         : 1;
56 
57 			struct Gradient
58 			{
59 				unsigned char attribute : BITS(VERTEX_OUTPUT_LAST);
60 				bool flat               : 1;
61 				bool wrap               : 1;
62 			};
63 
64 			union
65 			{
66 				struct
67 				{
68 					Gradient color[2][4];
69 					Gradient texture[8][4];
70 					Gradient fog;
71 				};
72 
73 				Gradient gradient[MAX_FRAGMENT_INPUTS][4];
74 			};
75 		};
76 
77 		struct State : States
78 		{
79 			State(int i = 0);
80 
81 			bool operator==(const State &states) const;
82 
83 			unsigned int hash;
84 		};
85 
86 		typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw);
87 
88 		SetupProcessor(Context *context);
89 
90 		~SetupProcessor();
91 
92 	protected:
93 		State update() const;
94 		Routine *routine(const State &state);
95 
96 		void setRoutineCacheSize(int cacheSize);
97 
98 		float depthBias;
99 		float slopeDepthBias;
100 
101 	private:
102 		Context *const context;
103 
104 		RoutineCache<State> *routineCache;
105 	};
106 }
107 
108 #endif   // sw_SetupProcessor_hpp
109