• 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 "Pipeline/VertexShader.hpp"
21 #include "Pipeline/PixelShader.hpp"
22 #include "System/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 interpolateZ              : 1;
44 			bool interpolateW              : 1;
45 			bool perspective               : 1;
46 			unsigned int positionRegister  : BITS(VERTEX_OUTPUT_LAST);
47 			unsigned int pointSizeRegister : BITS(VERTEX_OUTPUT_LAST);
48 			CullMode cullMode              : BITS(CULL_LAST);
49 			bool twoSidedStencil           : 1;
50 			bool slopeDepthBias            : 1;
51 			bool vFace                     : 1;
52 			unsigned int multiSample       : 3;   // 1, 2 or 4
53 			bool rasterizerDiscard         : 1;
54 
55 			struct Gradient
56 			{
57 				unsigned char attribute : BITS(VERTEX_OUTPUT_LAST);
58 				bool flat               : 1;
59 				bool wrap               : 1;
60 			};
61 
62 			Gradient gradient[MAX_FRAGMENT_INPUTS][4];
63 		};
64 
65 		struct State : States
66 		{
67 			State(int i = 0);
68 
69 			bool operator==(const State &states) const;
70 
71 			unsigned int hash;
72 		};
73 
74 		typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw);
75 
76 		SetupProcessor(Context *context);
77 
78 		~SetupProcessor();
79 
80 	protected:
81 		State update() const;
82 		Routine *routine(const State &state);
83 
84 		void setRoutineCacheSize(int cacheSize);
85 
86 	private:
87 		Context *const context;
88 
89 		RoutineCache<State> *routineCache;
90 	};
91 }
92 
93 #endif   // sw_SetupProcessor_hpp
94