Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef sw_VertexProgram_hpp |
| 16 | #define sw_VertexProgram_hpp |
| 17 | |
| 18 | #include "VertexRoutine.hpp" |
| 19 | #include "ShaderCore.hpp" |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 20 | #include "SamplerCore.hpp" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 21 | |
| 22 | #include "Stream.hpp" |
| 23 | #include "Types.hpp" |
| 24 | |
| 25 | namespace sw |
| 26 | { |
| 27 | struct Stream; |
| 28 | class VertexShader; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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: |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 38 | const VertexShader *const shader; |
| 39 | |
| 40 | RegisterArray<4096> 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 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 60 | typedef Shader::DestinationParameter Dst; |
| 61 | typedef Shader::SourceParameter Src; |
| 62 | typedef Shader::Control Control; |
| 63 | typedef Shader::Usage Usage; |
| 64 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 65 | void pipeline() override; |
| 66 | void program(); |
| 67 | void passThrough(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 68 | |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 69 | Vector4f fetchRegister(const Src &src, unsigned int offset = 0); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 70 | Vector4f readConstant(const Src &src, unsigned int offset = 0); |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 71 | RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index); |
| 72 | RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index, Int& offset); |
| 73 | Int relativeAddress(const Shader::Parameter &var, int bufferIndex = -1); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 74 | Int4 enableMask(const Shader::Instruction *instruction); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 75 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 76 | void M3X2(Vector4f &dst, Vector4f &src0, Src &src1); |
| 77 | void M3X3(Vector4f &dst, Vector4f &src0, Src &src1); |
| 78 | void M3X4(Vector4f &dst, Vector4f &src0, Src &src1); |
| 79 | void M4X3(Vector4f &dst, Vector4f &src0, Src &src1); |
| 80 | void M4X4(Vector4f &dst, Vector4f &src0, Src &src1); |
| 81 | void BREAK(); |
| 82 | void BREAKC(Vector4f &src0, Vector4f &src1, Control); |
| 83 | void BREAKP(const Src &predicateRegister); |
| 84 | void BREAK(Int4 &condition); |
| 85 | void CONTINUE(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 86 | void TEST(); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 87 | void CALL(int labelIndex, int callSiteIndex); |
| 88 | void CALLNZ(int labelIndex, int callSiteIndex, const Src &src); |
| 89 | void CALLNZb(int labelIndex, int callSiteIndex, const Src &boolRegister); |
| 90 | void CALLNZp(int labelIndex, int callSiteIndex, const Src &predicateRegister); |
| 91 | void ELSE(); |
| 92 | void ENDIF(); |
| 93 | void ENDLOOP(); |
| 94 | void ENDREP(); |
| 95 | void ENDWHILE(); |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 96 | void ENDSWITCH(); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 97 | void IF(const Src &src); |
| 98 | void IFb(const Src &boolRegister); |
| 99 | void IFp(const Src &predicateRegister); |
| 100 | void IFC(Vector4f &src0, Vector4f &src1, Control); |
| 101 | void IF(Int4 &condition); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 102 | void LABEL(int labelIndex); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 103 | void LOOP(const Src &integerRegister); |
| 104 | void REP(const Src &integerRegister); |
| 105 | void WHILE(const Src &temporaryRegister); |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 106 | void SWITCH(); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 107 | void RET(); |
| 108 | void LEAVE(); |
| 109 | void TEXLDL(Vector4f &dst, Vector4f &src, const Src&); |
| 110 | void TEX(Vector4f &dst, Vector4f &src, const Src&); |
Meng-Lin Wu | 2337a19 | 2016-06-01 13:54:07 -0400 | [diff] [blame] | 111 | void TEXOFFSET(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 112 | void TEXLDL(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2); |
Meng-Lin Wu | 9d62c48 | 2016-06-14 11:11:25 -0400 | [diff] [blame] | 113 | void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 114 | void TEXELFETCH(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 115 | void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3); |
| 116 | void TEXGRAD(Vector4f &dst, Vector4f &src, const Src&, Vector4f &src2, Vector4f &src3, Vector4f &src4); |
| 117 | void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 118 | |
Nicolas Capens | a3c16e4 | 2016-06-15 16:45:53 -0400 | [diff] [blame] | 119 | void sampleTexture(Vector4f &c, const Src &s, Vector4f &uvwq, Vector4f &dsx, Vector4f &dsy, Vector4f &offset, SamplerFunction function); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 120 | |
Alexis Hetu | 0b65c5e | 2015-03-31 11:48:57 -0400 | [diff] [blame] | 121 | SamplerCore *sampler[VERTEX_TEXTURE_IMAGE_UNITS]; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 122 | |
| 123 | int ifDepth; |
| 124 | int loopRepDepth; |
| 125 | int breakDepth; |
| 126 | int currentLabel; |
| 127 | bool whileTest; |
| 128 | |
Nicolas Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 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; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 135 | bool isConditionalIf[24 + 24]; |
| 136 | }; |
| 137 | } |
| 138 | |
| 139 | #endif // sw_VertexProgram_hpp |