blob: 3c4199c6611198997326d387f787bcd7467558a3 [file] [log] [blame]
Nicolas Capens68a82382018-10-02 13:16:55 -04001// 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
25namespace 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, 4> aL;
43 Vector4f p0;
44
45 Array<Int, 4> increment;
46 Array<Int, 4> iteration;
47
48 Int loopDepth;
49 Int stackIndex; // FIXME: Inc/decrement callStack
50 Array<UInt, 16> callStack;
51
52 Int enableIndex;
53 Array<Int4, 1 + 24> 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 CALL(int labelIndex, int callSiteIndex);
90 void CALLNZ(int labelIndex, int callSiteIndex, const Src &src);
91 void CALLNZb(int labelIndex, int callSiteIndex, const Src &boolRegister);
92 void CALLNZp(int labelIndex, int callSiteIndex, const Src &predicateRegister);
93 void ELSE();
94 void ENDIF();
95 void ENDLOOP();
96 void ENDREP();
97 void ENDWHILE();
98 void ENDSWITCH();
99 void IF(const Src &src);
100 void IFb(const Src &boolRegister);
101 void IFp(const Src &predicateRegister);
102 void IFC(Vector4f &src0, Vector4f &src1, Control);
103 void IF(Int4 &condition);
104 void LABEL(int labelIndex);
105 void LOOP(const Src &integerRegister);
106 void REP(const Src &integerRegister);
107 void WHILE(const Src &temporaryRegister);
108 void SWITCH();
109 void RET();
110 void LEAVE();
111 void TEX(Vector4f &dst, Vector4f &src, const Src&);
112 void TEXOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset);
113 void TEXLOD(Vector4f &dst, Vector4f &src, const Src&, Float4 &lod);
114 void TEXLODOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset, Float4 &lod);
115 void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Float4 &lod);
116 void TEXELFETCHOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset, Float4 &lod);
117 void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &dsx, Vector4f &dsy);
118 void TEXGRADOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &dsx, Vector4f &dsy, Vector4f &offset);
119 void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&);
120
121 Vector4f sampleTexture(const Src &s, Vector4f &uvwq, Float4 &lod, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
122 Vector4f sampleTexture(int sampler, Vector4f &uvwq, Float4 &lod, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
123
124 int ifDepth;
125 int loopRepDepth;
126 int currentLabel;
127 bool whileTest;
128
129 BasicBlock *ifFalseBlock[24 + 24];
130 BasicBlock *loopRepTestBlock[4];
131 BasicBlock *loopRepEndBlock[4];
132 BasicBlock *labelBlock[2048];
133 std::vector<BasicBlock*> callRetBlock[2048];
134 BasicBlock *returnBlock;
135 bool isConditionalIf[24 + 24];
136 };
137}
138
139#endif // sw_VertexProgram_hpp