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_VertexShader_hpp |
| 16 | #define sw_VertexShader_hpp |
| 17 | |
| 18 | #include "Shader.hpp" |
Nicolas Capens | ec0936c | 2016-05-18 12:32:02 -0400 | [diff] [blame] | 19 | #include "Main/Config.hpp" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 20 | |
| 21 | namespace sw |
| 22 | { |
| 23 | class VertexShader : public Shader |
| 24 | { |
| 25 | public: |
Alexis Hetu | b7508b8 | 2016-09-22 15:36:45 -0400 | [diff] [blame] | 26 | enum AttribType : unsigned char |
| 27 | { |
| 28 | ATTRIBTYPE_FLOAT, |
| 29 | ATTRIBTYPE_INT, |
| 30 | ATTRIBTYPE_UINT, |
| 31 | |
| 32 | ATTRIBTYPE_LAST = ATTRIBTYPE_UINT |
| 33 | }; |
| 34 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 35 | explicit VertexShader(const VertexShader *vs = 0); |
| 36 | explicit VertexShader(const unsigned long *token); |
| 37 | |
| 38 | virtual ~VertexShader(); |
| 39 | |
| 40 | static int validate(const unsigned long *const token); // Returns number of instructions if valid |
Nicolas Capens | 6abe1cb | 2016-01-15 23:30:50 -0500 | [diff] [blame] | 41 | bool containsTextureSampling() const; |
| 42 | |
Alexis Hetu | b7508b8 | 2016-09-22 15:36:45 -0400 | [diff] [blame] | 43 | void setInput(int inputIdx, const Semantic& semantic, AttribType attribType = ATTRIBTYPE_FLOAT); |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 44 | void setOutput(int outputIdx, int nbComponents, const Semantic& semantic); |
| 45 | void setPositionRegister(int posReg); |
| 46 | void setPointSizeRegister(int ptSizeReg); |
| 47 | void declareInstanceId() { instanceIdDeclared = true; } |
Alexis Hetu | 877ddfc | 2017-07-25 17:48:00 -0400 | [diff] [blame] | 48 | void declareVertexId() { vertexIdDeclared = true; } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 49 | |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 50 | const Semantic& getInput(int inputIdx) const; |
| 51 | const Semantic& getOutput(int outputIdx, int component) const; |
Alexis Hetu | b7508b8 | 2016-09-22 15:36:45 -0400 | [diff] [blame] | 52 | AttribType getAttribType(int inputIndex) const; |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 53 | int getPositionRegister() const { return positionRegister; } |
| 54 | int getPointSizeRegister() const { return pointSizeRegister; } |
| 55 | bool isInstanceIdDeclared() const { return instanceIdDeclared; } |
Alexis Hetu | 877ddfc | 2017-07-25 17:48:00 -0400 | [diff] [blame] | 56 | bool isVertexIdDeclared() const { return vertexIdDeclared; } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 57 | |
| 58 | private: |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 59 | void analyze(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 60 | void analyzeInput(); |
| 61 | void analyzeOutput(); |
Nicolas Capens | 6abe1cb | 2016-01-15 23:30:50 -0500 | [diff] [blame] | 62 | void analyzeTextureSampling(); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 63 | |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 64 | Semantic input[MAX_VERTEX_INPUTS]; |
| 65 | Semantic output[MAX_VERTEX_OUTPUTS][4]; |
| 66 | |
Alexis Hetu | b7508b8 | 2016-09-22 15:36:45 -0400 | [diff] [blame] | 67 | AttribType attribType[MAX_VERTEX_INPUTS]; |
| 68 | |
Alexis Hetu | 02ad0aa | 2016-08-02 11:18:14 -0400 | [diff] [blame] | 69 | int positionRegister; |
| 70 | int pointSizeRegister; |
| 71 | |
| 72 | bool instanceIdDeclared; |
Alexis Hetu | 877ddfc | 2017-07-25 17:48:00 -0400 | [diff] [blame] | 73 | bool vertexIdDeclared; |
Nicolas Capens | 6abe1cb | 2016-01-15 23:30:50 -0500 | [diff] [blame] | 74 | bool textureSampling; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 75 | }; |
| 76 | } |
| 77 | |
| 78 | #endif // sw_VertexShader_hpp |