• 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_VertexProcessor_hpp
16 #define sw_VertexProcessor_hpp
17 
18 #include "Context.hpp"
19 #include "Memset.hpp"
20 #include "RoutineCache.hpp"
21 #include "Vertex.hpp"
22 #include "Pipeline/SpirvShader.hpp"
23 
24 namespace sw {
25 
26 struct DrawData;
27 
28 // Basic direct mapped vertex cache.
29 struct VertexCache
30 {
31 	static constexpr uint32_t SIZE = 64;            // TODO: Variable size?
32 	static constexpr uint32_t TAG_MASK = SIZE - 1;  // Size must be power of 2.
33 
34 	void clear();
35 
36 	Vertex vertex[SIZE];
37 	uint32_t tag[SIZE];
38 
39 	// Identifier of the draw call for the cache data. If this cache is
40 	// used with a different draw call, then the cache should be invalidated
41 	// before use.
42 	int drawCall = -1;
43 };
44 
45 struct VertexTask
46 {
47 	unsigned int vertexCount;
48 	unsigned int primitiveStart;
49 	VertexCache vertexCache;
50 };
51 
52 using VertexRoutineFunction = FunctionT<void(Vertex *output, unsigned int *batch, VertexTask *vertextask, DrawData *draw)>;
53 
54 class VertexProcessor
55 {
56 public:
57 	struct States : Memset<States>
58 	{
Statessw::VertexProcessor::States59 		States()
60 		    : Memset(this, 0)
61 		{}
62 
63 		uint32_t computeHash();
64 
65 		uint64_t shaderID;
66 
67 		struct Input
68 		{
operator boolsw::VertexProcessor::States::Input69 			operator bool() const  // Returns true if stream contains data
70 			{
71 				return format != VK_FORMAT_UNDEFINED;
72 			}
73 
74 			VkFormat format;  // TODO(b/148016460): Could be restricted to VK_FORMAT_END_RANGE
75 			unsigned int attribType : BITS(SpirvShader::ATTRIBTYPE_LAST);
76 		};
77 
78 		Input input[MAX_INTERFACE_COMPONENTS / 4];
79 		bool robustBufferAccess : 1;
80 		bool isPoint : 1;
81 	};
82 
83 	struct State : States
84 	{
85 		bool operator==(const State &state) const;
86 
87 		uint32_t hash;
88 	};
89 
90 	using RoutineType = VertexRoutineFunction::RoutineType;
91 
92 	VertexProcessor();
93 
94 	virtual ~VertexProcessor();
95 
96 protected:
97 	const State update(const sw::Context *context);
98 	RoutineType routine(const State &state, vk::PipelineLayout const *pipelineLayout,
99 	                    SpirvShader const *vertexShader, const vk::DescriptorSet::Bindings &descriptorSets);
100 
101 	void setRoutineCacheSize(int cacheSize);
102 
103 private:
104 	using RoutineCacheType = RoutineCacheT<State, VertexRoutineFunction::CFunctionType>;
105 	RoutineCacheType *routineCache;
106 };
107 
108 }  // namespace sw
109 
110 #endif  // sw_VertexProcessor_hpp
111