blob: 9a9a0a67189260d58d06d7f6fc82df69284b4afa [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_VertexShader_hpp
16#define sw_VertexShader_hpp
17
18#include "Shader.hpp"
Nicolas Capensec0936c2016-05-18 12:32:02 -040019#include "Main/Config.hpp"
John Bauman66b8ab22014-05-06 15:57:45 -040020
21namespace sw
22{
23 class VertexShader : public Shader
24 {
25 public:
Alexis Hetub7508b82016-09-22 15:36:45 -040026 enum AttribType : unsigned char
27 {
28 ATTRIBTYPE_FLOAT,
29 ATTRIBTYPE_INT,
30 ATTRIBTYPE_UINT,
31
32 ATTRIBTYPE_LAST = ATTRIBTYPE_UINT
33 };
34
John Bauman66b8ab22014-05-06 15:57:45 -040035 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 Capens6abe1cb2016-01-15 23:30:50 -050041 bool containsTextureSampling() const;
42
Alexis Hetub7508b82016-09-22 15:36:45 -040043 void setInput(int inputIdx, const Semantic& semantic, AttribType attribType = ATTRIBTYPE_FLOAT);
Alexis Hetu02ad0aa2016-08-02 11:18:14 -040044 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 Hetu877ddfc2017-07-25 17:48:00 -040048 void declareVertexId() { vertexIdDeclared = true; }
John Bauman66b8ab22014-05-06 15:57:45 -040049
Alexis Hetu02ad0aa2016-08-02 11:18:14 -040050 const Semantic& getInput(int inputIdx) const;
51 const Semantic& getOutput(int outputIdx, int component) const;
Alexis Hetub7508b82016-09-22 15:36:45 -040052 AttribType getAttribType(int inputIndex) const;
Alexis Hetu02ad0aa2016-08-02 11:18:14 -040053 int getPositionRegister() const { return positionRegister; }
54 int getPointSizeRegister() const { return pointSizeRegister; }
55 bool isInstanceIdDeclared() const { return instanceIdDeclared; }
Alexis Hetu877ddfc2017-07-25 17:48:00 -040056 bool isVertexIdDeclared() const { return vertexIdDeclared; }
John Bauman66b8ab22014-05-06 15:57:45 -040057
58 private:
Alexis Hetu02ad0aa2016-08-02 11:18:14 -040059 void analyze();
John Bauman66b8ab22014-05-06 15:57:45 -040060 void analyzeInput();
61 void analyzeOutput();
Nicolas Capens6abe1cb2016-01-15 23:30:50 -050062 void analyzeTextureSampling();
John Bauman66b8ab22014-05-06 15:57:45 -040063
Alexis Hetu02ad0aa2016-08-02 11:18:14 -040064 Semantic input[MAX_VERTEX_INPUTS];
65 Semantic output[MAX_VERTEX_OUTPUTS][4];
66
Alexis Hetub7508b82016-09-22 15:36:45 -040067 AttribType attribType[MAX_VERTEX_INPUTS];
68
Alexis Hetu02ad0aa2016-08-02 11:18:14 -040069 int positionRegister;
70 int pointSizeRegister;
71
72 bool instanceIdDeclared;
Alexis Hetu877ddfc2017-07-25 17:48:00 -040073 bool vertexIdDeclared;
Nicolas Capens6abe1cb2016-01-15 23:30:50 -050074 bool textureSampling;
John Bauman66b8ab22014-05-06 15:57:45 -040075 };
76}
77
78#endif // sw_VertexShader_hpp