1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef sw_VertexProgram_hpp
16 #define sw_VertexProgram_hpp
18 #include "VertexRoutine.hpp"
19 #include "ShaderCore.hpp"
20 #include "SamplerCore.hpp"
30 class VertexProgram : public VertexRoutine, public ShaderCore
33 VertexProgram(const VertexProcessor::State &state, const VertexShader *vertexShader);
35 virtual ~VertexProgram();
38 const VertexShader *const shader;
40 RegisterArray<4096> r; // Temporary registers
45 Array<Int, 4> increment;
46 Array<Int, 4> iteration;
49 Int stackIndex; // FIXME: Inc/decrement callStack
50 Array<UInt, 16> callStack;
53 Array<Int4, 1 + 24> enableStack;
61 typedef Shader::DestinationParameter Dst;
62 typedef Shader::SourceParameter Src;
63 typedef Shader::Control Control;
64 typedef Shader::Usage Usage;
66 void pipeline(UInt &index) override;
67 void program(UInt &index);
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::Parameter &var, int bufferIndex = -1);
75 Int4 enableMask(const Shader::Instruction *instruction);
77 void M3X2(Vector4f &dst, Vector4f &src0, Src &src1);
78 void M3X3(Vector4f &dst, Vector4f &src0, Src &src1);
79 void M3X4(Vector4f &dst, Vector4f &src0, Src &src1);
80 void M4X3(Vector4f &dst, Vector4f &src0, Src &src1);
81 void M4X4(Vector4f &dst, Vector4f &src0, Src &src1);
83 void BREAKC(Vector4f &src0, Vector4f &src1, Control);
84 void BREAKP(const Src &predicateRegister);
85 void BREAK(Int4 &condition);
88 void CALL(int labelIndex, int callSiteIndex);
89 void CALLNZ(int labelIndex, int callSiteIndex, const Src &src);
90 void CALLNZb(int labelIndex, int callSiteIndex, const Src &boolRegister);
91 void CALLNZp(int labelIndex, int callSiteIndex, const Src &predicateRegister);
98 void IF(const Src &src);
99 void IFb(const Src &boolRegister);
100 void IFp(const Src &predicateRegister);
101 void IFC(Vector4f &src0, Vector4f &src1, Control);
102 void IF(Int4 &condition);
103 void LABEL(int labelIndex);
104 void LOOP(const Src &integerRegister);
105 void REP(const Src &integerRegister);
106 void WHILE(const Src &temporaryRegister);
110 void TEXLDL(Vector4f &dst, Vector4f &src, const Src&);
111 void TEX(Vector4f &dst, Vector4f &src, const Src&);
112 void TEXOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2);
113 void TEXLDL(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2);
114 void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&);
115 void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2);
116 void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3);
117 void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, Vector4f &src4);
118 void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&);
120 void sampleTexture(Vector4f &c, const Src &s, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
122 SamplerCore *sampler[VERTEX_TEXTURE_IMAGE_UNITS];
130 BasicBlock *ifFalseBlock[24 + 24];
131 BasicBlock *loopRepTestBlock[4];
132 BasicBlock *loopRepEndBlock[4];
133 BasicBlock *labelBlock[2048];
134 std::vector<BasicBlock*> callRetBlock[2048];
135 BasicBlock *returnBlock;
136 bool isConditionalIf[24 + 24];
140 #endif // sw_VertexProgram_hpp