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" |
| 20 | |
Nicolas Capens | 708c24b | 2017-10-26 13:07:10 -0400 | [diff] [blame] | 21 | #include "SamplerCore.hpp" |
| 22 | #include "Renderer/Stream.hpp" |
| 23 | #include "Common/Types.hpp" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 24 | |
Ben Clayton | d951f19 | 2019-02-11 20:59:19 +0000 | [diff] [blame] | 25 | #include <unordered_map> |
| 26 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 27 | namespace sw |
| 28 | { |
| 29 | struct Stream; |
| 30 | class VertexShader; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 31 | |
| 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 Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 40 | const VertexShader *const shader; |
| 41 | |
Alexis Hetu | 329747c | 2018-04-09 13:47:34 -0400 | [diff] [blame] | 42 | RegisterArray<NUM_TEMPORARY_REGISTERS> r; // Temporary registers |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 43 | Vector4f a0; |
Ben Clayton | d951f19 | 2019-02-11 20:59:19 +0000 | [diff] [blame] | 44 | Array<Int> aL; // loop counter register |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 45 | Vector4f p0; |
| 46 | |
Ben Clayton | d951f19 | 2019-02-11 20:59:19 +0000 | [diff] [blame] | 47 | Array<Int> increment; |
| 48 | Array<Int> iteration; |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 49 | |
| 50 | Int loopDepth; |
| 51 | Int stackIndex; // FIXME: Inc/decrement callStack |
Ben Clayton | d951f19 | 2019-02-11 20:59:19 +0000 | [diff] [blame] | 52 | Array<UInt> callStack; |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 53 | |
| 54 | Int enableIndex; |
Alexis Hetu | 48d47a4 | 2019-01-10 14:04:26 -0500 | [diff] [blame] | 55 | Array<Int4, MAX_SHADER_ENABLE_STACK_SIZE> enableStack; |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 56 | Int4 enableBreak; |
| 57 | Int4 enableContinue; |
| 58 | Int4 enableLeave; |
| 59 | |
| 60 | Int instanceID; |
Alexis Hetu | 877ddfc | 2017-07-25 17:48:00 -0400 | [diff] [blame] | 61 | Int4 vertexID; |
Nicolas Capens | 7551ac6 | 2016-01-20 17:11:53 -0500 | [diff] [blame] | 62 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 63 | typedef Shader::DestinationParameter Dst; |
| 64 | typedef Shader::SourceParameter Src; |
| 65 | typedef Shader::Control Control; |
| 66 | typedef Shader::Usage Usage; |
| 67 | |
Alexis Hetu | 877ddfc | 2017-07-25 17:48:00 -0400 | [diff] [blame] | 68 | void pipeline(UInt &index) override; |
| 69 | void program(UInt &index); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 70 | void passThrough(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 71 | |
Nicolas Capens | c2534f4 | 2016-04-04 11:13:24 -0400 | [diff] [blame] | 72 | Vector4f fetchRegister(const Src &src, unsigned int offset = 0); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 73 | Vector4f readConstant(const Src &src, unsigned int offset = 0); |
Alexis Hetu | 2c2a7b2 | 2015-10-27 16:12:11 -0400 | [diff] [blame] | 74 | RValue<Pointer<Byte>> uniformAddress(int bufferIndex, unsigned int index); |
Nicolas Capens | 4b74373 | 2018-05-28 13:22:07 -0400 | [diff] [blame] | 75 | 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 Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 78 | Int4 enableMask(const Shader::Instruction *instruction); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 79 | |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 80 | 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 90 | void TEST(); |
Nicolas Capens | 6e8ec33 | 2018-11-06 11:56:21 -0500 | [diff] [blame] | 91 | void SCALAR(); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 92 | 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 Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 101 | void ENDSWITCH(); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 102 | 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 107 | void LABEL(int labelIndex); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 108 | void LOOP(const Src &integerRegister); |
| 109 | void REP(const Src &integerRegister); |
| 110 | void WHILE(const Src &temporaryRegister); |
Alexis Hetu | 9aa83a9 | 2016-05-02 17:34:46 -0400 | [diff] [blame] | 111 | void SWITCH(); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 112 | void RET(); |
| 113 | void LEAVE(); |
Nicolas Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 114 | void TEX(Vector4f &dst, Vector4f &src, const Src&); |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 115 | 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 Capens | b4fb367 | 2016-01-15 17:02:41 -0500 | [diff] [blame] | 122 | void TEXSIZE(Vector4f &dst, Float4 &lod, const Src&); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 123 | |
Nicolas Capens | a0b5783 | 2017-11-07 13:07:53 -0500 | [diff] [blame] | 124 | 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 Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 126 | |
Ben Clayton | 0a60818 | 2019-02-19 18:50:29 +0000 | [diff] [blame] | 127 | int ifDepth = 0; |
| 128 | int loopRepDepth = 0; |
| 129 | int currentLabel = -1; |
Nicolas Capens | 6e8ec33 | 2018-11-06 11:56:21 -0500 | [diff] [blame] | 130 | bool scalar = false; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 131 | |
Ben Clayton | d951f19 | 2019-02-11 20:59:19 +0000 | [diff] [blame] | 132 | 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 Capens | c8b67a4 | 2016-09-25 15:02:52 -0400 | [diff] [blame] | 137 | BasicBlock *returnBlock; |
Ben Clayton | d951f19 | 2019-02-11 20:59:19 +0000 | [diff] [blame] | 138 | std::vector<bool> isConditionalIf; |
Nicolas Capens | 2f490f0 | 2018-11-01 16:53:36 -0400 | [diff] [blame] | 139 | std::vector<Int4> restoreContinue; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 140 | }; |
| 141 | } |
| 142 | |
| 143 | #endif // sw_VertexProgram_hpp |