blob: bfccb18fdf04dd6aec23be952eff8fef2cad043c [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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
John Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
John Bauman66b8ab22014-05-06 15:57:45 -04008//
Nicolas Capens0bac2852016-05-07 06:09:58 -04009// 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.
John Bauman66b8ab22014-05-06 15:57:45 -040014
15#ifndef sw_VertexProgram_hpp
16#define sw_VertexProgram_hpp
17
18#include "VertexRoutine.hpp"
19#include "ShaderCore.hpp"
20
Nicolas Capens708c24b2017-10-26 13:07:10 -040021#include "SamplerCore.hpp"
22#include "Renderer/Stream.hpp"
23#include "Common/Types.hpp"
John Bauman66b8ab22014-05-06 15:57:45 -040024
Ben Claytond951f192019-02-11 20:59:19 +000025#include <unordered_map>
26
John Bauman66b8ab22014-05-06 15:57:45 -040027namespace sw
28{
29 struct Stream;
30 class VertexShader;
John Bauman66b8ab22014-05-06 15:57:45 -040031
32 class VertexProgram : public VertexRoutine, public ShaderCore
33 {
34 public:
35 VertexProgram(const VertexProcessor::State &state, const VertexShader *vertexShader);
36
37 virtual ~VertexProgram();
38
39 private:
Nicolas Capens7551ac62016-01-20 17:11:53 -050040 const VertexShader *const shader;
41
Alexis Hetu329747c2018-04-09 13:47:34 -040042 RegisterArray<NUM_TEMPORARY_REGISTERS> r; // Temporary registers
Nicolas Capens7551ac62016-01-20 17:11:53 -050043 Vector4f a0;
Ben Claytond951f192019-02-11 20:59:19 +000044 Array<Int> aL; // loop counter register
Nicolas Capens7551ac62016-01-20 17:11:53 -050045 Vector4f p0;
46
Ben Claytond951f192019-02-11 20:59:19 +000047 Array<Int> increment;
48 Array<Int> iteration;
Nicolas Capens7551ac62016-01-20 17:11:53 -050049
50 Int loopDepth;
51 Int stackIndex; // FIXME: Inc/decrement callStack
Ben Claytond951f192019-02-11 20:59:19 +000052 Array<UInt> callStack;
Nicolas Capens7551ac62016-01-20 17:11:53 -050053
54 Int enableIndex;
Alexis Hetu48d47a42019-01-10 14:04:26 -050055 Array<Int4, MAX_SHADER_ENABLE_STACK_SIZE> enableStack;
Nicolas Capens7551ac62016-01-20 17:11:53 -050056 Int4 enableBreak;
57 Int4 enableContinue;
58 Int4 enableLeave;
59
60 Int instanceID;
Alexis Hetu877ddfc2017-07-25 17:48:00 -040061 Int4 vertexID;
Nicolas Capens7551ac62016-01-20 17:11:53 -050062
John Bauman66b8ab22014-05-06 15:57:45 -040063 typedef Shader::DestinationParameter Dst;
64 typedef Shader::SourceParameter Src;
65 typedef Shader::Control Control;
66 typedef Shader::Usage Usage;
67
Alexis Hetu877ddfc2017-07-25 17:48:00 -040068 void pipeline(UInt &index) override;
69 void program(UInt &index);
Nicolas Capensb4fb3672016-01-15 17:02:41 -050070 void passThrough();
John Bauman66b8ab22014-05-06 15:57:45 -040071
Nicolas Capensc2534f42016-04-04 11:13:24 -040072 Vector4f fetchRegister(const Src &src, unsigned int offset = 0);
Nicolas Capensb4fb3672016-01-15 17:02:41 -050073 Vector4f readConstant(const Src &src, unsigned int offset = 0);
Alexis Hetu2c2a7b22015-10-27 16:12:11 -040074 RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index);
Nicolas Capens4b743732018-05-28 13:22:07 -040075 RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index, Int &offset);
76 Int relativeAddress(const Shader::Relative &rel, int bufferIndex = -1);
77 Int4 dynamicAddress(const Shader::Relative &rel);
Nicolas Capensb4fb3672016-01-15 17:02:41 -050078 Int4 enableMask(const Shader::Instruction *instruction);
John Bauman66b8ab22014-05-06 15:57:45 -040079
Nicolas Capensb4fb3672016-01-15 17:02:41 -050080 void M3X2(Vector4f &dst, Vector4f &src0, Src &src1);
81 void M3X3(Vector4f &dst, Vector4f &src0, Src &src1);
82 void M3X4(Vector4f &dst, Vector4f &src0, Src &src1);
83 void M4X3(Vector4f &dst, Vector4f &src0, Src &src1);
84 void M4X4(Vector4f &dst, Vector4f &src0, Src &src1);
85 void BREAK();
86 void BREAKC(Vector4f &src0, Vector4f &src1, Control);
87 void BREAKP(const Src &predicateRegister);
88 void BREAK(Int4 &condition);
89 void CONTINUE();
John Bauman66b8ab22014-05-06 15:57:45 -040090 void TEST();
Nicolas Capens6e8ec332018-11-06 11:56:21 -050091 void SCALAR();
Nicolas Capensb4fb3672016-01-15 17:02:41 -050092 void CALL(int labelIndex, int callSiteIndex);
93 void CALLNZ(int labelIndex, int callSiteIndex, const Src &src);
94 void CALLNZb(int labelIndex, int callSiteIndex, const Src &boolRegister);
95 void CALLNZp(int labelIndex, int callSiteIndex, const Src &predicateRegister);
96 void ELSE();
97 void ENDIF();
98 void ENDLOOP();
99 void ENDREP();
100 void ENDWHILE();
Alexis Hetu9aa83a92016-05-02 17:34:46 -0400101 void ENDSWITCH();
Nicolas Capensb4fb3672016-01-15 17:02:41 -0500102 void IF(const Src &src);
103 void IFb(const Src &boolRegister);
104 void IFp(const Src &predicateRegister);
105 void IFC(Vector4f &src0, Vector4f &src1, Control);
106 void IF(Int4 &condition);
John Bauman66b8ab22014-05-06 15:57:45 -0400107 void LABEL(int labelIndex);
Nicolas Capensb4fb3672016-01-15 17:02:41 -0500108 void LOOP(const Src &integerRegister);
109 void REP(const Src &integerRegister);
110 void WHILE(const Src &temporaryRegister);
Alexis Hetu9aa83a92016-05-02 17:34:46 -0400111 void SWITCH();
Nicolas Capensb4fb3672016-01-15 17:02:41 -0500112 void RET();
113 void LEAVE();
Nicolas Capensb4fb3672016-01-15 17:02:41 -0500114 void TEX(Vector4f &dst, Vector4f &src, const Src&);
Nicolas Capensa0b57832017-11-07 13:07:53 -0500115 void TEXOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset);
116 void TEXLOD(Vector4f &dst, Vector4f &src, const Src&, Float4 &lod);
117 void TEXLODOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset, Float4 &lod);
118 void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Float4 &lod);
119 void TEXELFETCHOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &offset, Float4 &lod);
120 void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &dsx, Vector4f &dsy);
121 void TEXGRADOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &dsx, Vector4f &dsy, Vector4f &offset);
Nicolas Capensb4fb3672016-01-15 17:02:41 -0500122 void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&);
John Bauman66b8ab22014-05-06 15:57:45 -0400123
Nicolas Capensa0b57832017-11-07 13:07:53 -0500124 Vector4f sampleTexture(const Src &s, Vector4f &uvwq, Float4 &lod, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
125 Vector4f sampleTexture(int sampler, Vector4f &uvwq, Float4 &lod, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function);
John Bauman66b8ab22014-05-06 15:57:45 -0400126
Ben Clayton0a608182019-02-19 18:50:29 +0000127 int ifDepth = 0;
128 int loopRepDepth = 0;
129 int currentLabel = -1;
Nicolas Capens6e8ec332018-11-06 11:56:21 -0500130 bool scalar = false;
John Bauman66b8ab22014-05-06 15:57:45 -0400131
Ben Claytond951f192019-02-11 20:59:19 +0000132 std::vector<BasicBlock*> ifFalseBlock;
133 std::vector<BasicBlock*> loopRepTestBlock;
134 std::vector<BasicBlock*> loopRepEndBlock;
135 std::vector<BasicBlock*> labelBlock;
136 std::unordered_map<unsigned int, std::vector<BasicBlock*>> callRetBlock; // label -> list of call sites
Nicolas Capensc8b67a42016-09-25 15:02:52 -0400137 BasicBlock *returnBlock;
Ben Claytond951f192019-02-11 20:59:19 +0000138 std::vector<bool> isConditionalIf;
Nicolas Capens2f490f02018-11-01 16:53:36 -0400139 std::vector<Int4> restoreContinue;
John Bauman66b8ab22014-05-06 15:57:45 -0400140 };
141}
142
143#endif // sw_VertexProgram_hpp