• 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_VertexRoutine_hpp
16 #define sw_VertexRoutine_hpp
17 
18 #include "ShaderCore.hpp"
19 #include "SpirvShader.hpp"
20 #include "Device/VertexProcessor.hpp"
21 
22 namespace vk {
23 class PipelineLayout;
24 }
25 
26 namespace sw {
27 
28 class VertexRoutinePrototype : public VertexRoutineFunction
29 {
30 public:
VertexRoutinePrototype()31 	VertexRoutinePrototype()
32 	    : vertex(Arg<0>())
33 	    , batch(Arg<1>())
34 	    , task(Arg<2>())
35 	    , data(Arg<3>())
36 	{}
~VertexRoutinePrototype()37 	virtual ~VertexRoutinePrototype() {}
38 
39 protected:
40 	Pointer<Byte> vertex;
41 	Pointer<UInt> batch;
42 	Pointer<Byte> task;
43 	Pointer<Byte> data;
44 };
45 
46 class VertexRoutine : public VertexRoutinePrototype
47 {
48 public:
49 	VertexRoutine(
50 	    const VertexProcessor::State &state,
51 	    vk::PipelineLayout const *pipelineLayout,
52 	    SpirvShader const *spirvShader);
53 	virtual ~VertexRoutine();
54 
55 	void generate();
56 
57 protected:
58 	Pointer<Byte> constants;
59 
60 	Int clipFlags;
61 	Int cullMask;
62 
63 	SpirvRoutine routine;
64 
65 	const VertexProcessor::State &state;
66 	SpirvShader const *const spirvShader;
67 
68 private:
69 	virtual void program(Pointer<UInt> &batch, UInt &vertexCount) = 0;
70 
71 	typedef VertexProcessor::State::Input Stream;
72 
73 	Vector4f readStream(Pointer<Byte> &buffer, UInt &stride, const Stream &stream, Pointer<UInt> &batch,
74 	                    bool robustBufferAccess, UInt &robustnessSize, Int baseVertex);
75 	void readInput(Pointer<UInt> &batch);
76 	void computeClipFlags();
77 	void computeCullMask();
78 	void writeCache(Pointer<Byte> &vertexCache, Pointer<UInt> &tagCache, Pointer<UInt> &batch);
79 	void writeVertex(const Pointer<Byte> &vertex, Pointer<Byte> &cacheEntry);
80 };
81 
82 }  // namespace sw
83 
84 #endif  // sw_VertexRoutine_hpp
85