• 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_VertexProgram_hpp
16 #define sw_VertexProgram_hpp
17 
18 #include "VertexRoutine.hpp"
19 #include "ShaderCore.hpp"
20 
21 #include "SamplerCore.hpp"
22 #include "Renderer/Stream.hpp"
23 #include "Common/Types.hpp"
24 
25 namespace sw
26 {
27 	struct Stream;
28 	class VertexShader;
29 
30 	class VertexProgram : public VertexRoutine, public ShaderCore
31 	{
32 	public:
33 		VertexProgram(const VertexProcessor::State &state, const VertexShader *vertexShader);
34 
35 		virtual ~VertexProgram();
36 
37 	private:
38 		const VertexShader *const shader;
39 
40 		RegisterArray<NUM_TEMPORARY_REGISTERS> r;   // Temporary registers
41 		Vector4f a0;
42 		Array<Int, MAX_SHADER_NESTED_LOOPS> aL;
43 		Vector4f p0;
44 
45 		Array<Int, MAX_SHADER_NESTED_LOOPS> increment;
46 		Array<Int, MAX_SHADER_NESTED_LOOPS> iteration;
47 
48 		Int loopDepth;
49 		Int stackIndex;   // FIXME: Inc/decrement callStack
50 		Array<UInt, MAX_SHADER_CALL_STACK_SIZE> callStack;
51 
52 		Int enableIndex;
53 		Array<Int4, MAX_SHADER_ENABLE_STACK_SIZE> enableStack;
54 		Int4 enableBreak;
55 		Int4 enableContinue;
56 		Int4 enableLeave;
57 
58 		Int instanceID;
59 		Int4 vertexID;
60 
61 		typedef Shader::DestinationParameter Dst;
62 		typedef Shader::SourceParameter Src;
63 		typedef Shader::Control Control;
64 		typedef Shader::Usage Usage;
65 
66 		void pipeline(UInt &index) override;
67 		void program(UInt &index);
68 		void passThrough();
69 
70 		Vector4f fetchRegister(const Src &src, unsigned int offset = 0);
71 		Vector4f readConstant(const Src &src, unsigned int offset = 0);
72 		RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index);
73 		RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index, Int &offset);
74 		Int relativeAddress(const Shader::Relative &rel, int bufferIndex = -1);
75 		Int4 dynamicAddress(const Shader::Relative &rel);
76 		Int4 enableMask(const Shader::Instruction *instruction);
77 
78 		void M3X2(Vector4f &dst, Vector4f &src0, Src &src1);
79 		void M3X3(Vector4f &dst, Vector4f &src0, Src &src1);
80 		void M3X4(Vector4f &dst, Vector4f &src0, Src &src1);
81 		void M4X3(Vector4f &dst, Vector4f &src0, Src &src1);
82 		void M4X4(Vector4f &dst, Vector4f &src0, Src &src1);
83 		void BREAK();
84 		void BREAKC(Vector4f &src0, Vector4f &src1, Control);
85 		void BREAKP(const Src &predicateRegister);
86 		void BREAK(Int4 &condition);
87 		void CONTINUE();
88 		void TEST();
89 		void SCALAR();
90 		void CALL(int labelIndex, int callSiteIndex);
91 		void CALLNZ(int labelIndex, int callSiteIndex, const Src &src);
92 		void CALLNZb(int labelIndex, int callSiteIndex, const Src &boolRegister);
93 		void CALLNZp(int labelIndex, int callSiteIndex, const Src &predicateRegister);
94 		void ELSE();
95 		void ENDIF();
96 		void ENDLOOP();
97 		void ENDREP();
98 		void ENDWHILE();
99 		void ENDSWITCH();
100 		void IF(const Src &src);
101 		void IFb(const Src &boolRegister);
102 		void IFp(const Src &predicateRegister);
103 		void IFC(Vector4f &src0, Vector4f &src1, Control);
104 		void IF(Int4 &condition);
105 		void LABEL(int labelIndex);
106 		void LOOP(const Src &integerRegister);
107 		void REP(const Src &integerRegister);
108 		void WHILE(const Src &temporaryRegister);
109 		void SWITCH();
110 		void RET();
111 		void LEAVE();
112 		void TEX(Vector4f &dst, Vector4f &src, const Src&);
113 		void TEXOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset);
114 		void TEXLOD(Vector4f &dst, Vector4f &src, const Src&, Float4 &lod);
115 		void TEXLODOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset, Float4 &lod);
116 		void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Float4 &lod);
117 		void TEXELFETCHOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset, Float4 &lod);
118 		void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &dsx, Vector4f &dsy);
119 		void TEXGRADOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &dsx, Vector4f &dsy, Vector4f &offset);
120 		void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&);
121 
122 		Vector4f sampleTexture(const Src &s, Vector4f &uvwq, Float4 &lod, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
123 		Vector4f sampleTexture(int sampler, Vector4f &uvwq, Float4 &lod, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
124 
125 		BoundedIndex<MAX_SHADER_NESTED_IFS> ifDepth = 0;
126 		BoundedIndex<MAX_SHADER_NESTED_LOOPS> loopRepDepth = 0;
127 		BoundedIndex<MAX_SHADER_CALL_SITES> currentLabel = -1;
128 		bool scalar = false;
129 
130 		BasicBlock *ifFalseBlock[MAX_SHADER_NESTED_IFS];
131 		BasicBlock *loopRepTestBlock[MAX_SHADER_NESTED_LOOPS];
132 		BasicBlock *loopRepEndBlock[MAX_SHADER_NESTED_LOOPS];
133 		BasicBlock *labelBlock[MAX_SHADER_CALL_SITES];
134 		std::vector<BasicBlock*> callRetBlock[MAX_SHADER_CALL_SITES];
135 		BasicBlock *returnBlock;
136 		bool isConditionalIf[MAX_SHADER_NESTED_IFS];
137 		std::vector<Int4> restoreContinue;
138 	};
139 }
140 
141 #endif   // sw_VertexProgram_hpp
142