• 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 "Memset.hpp"
20 #include "RoutineCache.hpp"
21 #include "System/Types.hpp"
22 #include <Pipeline/SpirvShader.hpp>
23 
24 #include <memory>
25 
26 namespace sw {
27 
28 struct Primitive;
29 struct Triangle;
30 struct Polygon;
31 struct DrawData;
32 
33 using SetupFunction = FunctionT<int(const vk::Device *device, Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw)>;
34 
35 class SetupProcessor
36 {
37 public:
38 	struct States : Memset<States>
39 	{
Statessw::SetupProcessor::States40 		States()
41 		    : Memset(this, 0)
42 		{}
43 
44 		uint32_t computeHash();
45 
46 		bool isDrawPoint : 1;
47 		bool isDrawLine : 1;
48 		bool isDrawTriangle : 1;
49 		bool fixedPointDepthBuffer : 1;
50 		bool applyConstantDepthBias : 1;
51 		bool applySlopeDepthBias : 1;
52 		bool applyDepthBiasClamp : 1;
53 		bool interpolateZ : 1;
54 		bool interpolateW : 1;
55 		VkFrontFace frontFace : BITS(VK_FRONT_FACE_MAX_ENUM);
56 		VkCullModeFlags cullMode : BITS(VK_CULL_MODE_FLAG_BITS_MAX_ENUM);
57 		unsigned int multiSampleCount : 3;  // 1, 2 or 4
58 		bool enableMultiSampling : 1;
59 		bool rasterizerDiscard : 1;
60 		unsigned int numClipDistances : 4;  // [0 - 8]
61 		unsigned int numCullDistances : 4;  // [0 - 8]
62 
63 		SpirvShader::InterfaceComponent gradient[MAX_INTERFACE_COMPONENTS];
64 	};
65 
66 	struct State : States
67 	{
68 		bool operator==(const State &states) const;
69 
70 		uint32_t hash;
71 	};
72 
73 	using RoutineType = SetupFunction::RoutineType;
74 
75 	SetupProcessor();
76 
77 	State update(const vk::GraphicsState &pipelineState, const sw::SpirvShader *fragmentShader, const sw::SpirvShader *vertexShader, const vk::Attachments &attachments) const;
78 	RoutineType routine(const State &state);
79 
80 	void setRoutineCacheSize(int cacheSize);
81 
82 private:
83 	using RoutineCacheType = RoutineCache<State, SetupFunction::CFunctionType>;
84 	std::unique_ptr<RoutineCacheType> routineCache;
85 };
86 
87 }  // namespace sw
88 
89 namespace std {
90 
91 template<>
92 struct hash<sw::SetupProcessor::State>
93 {
operator ()std::hash94 	uint64_t operator()(const sw::SetupProcessor::State &state) const
95 	{
96 		return state.hash;
97 	}
98 };
99 
100 }  // namespace std
101 
102 #endif  // sw_SetupProcessor_hpp
103