OSDN Git Service

Update to June 11 2013 code drop.
[android-x86/external-swiftshader.git] / src / Shader / VertexRoutine.hpp
1 // SwiftShader Software Renderer
2 //
3 // Copyright(c) 2005-2013 TransGaming Inc.
4 //
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,
6 // transcribed, stored in a retrieval system, translated into any human or computer
7 // language by any means, or disclosed to third parties without the explicit written
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
9 // or implied, including but not limited to any patent rights, are granted to you.
10 //
11
12 #ifndef sw_VertexRoutine_hpp
13 #define sw_VertexRoutine_hpp
14
15 #include "Renderer/Color.hpp"
16 #include "Renderer/VertexProcessor.hpp"
17 #include "ShaderCore.hpp"
18 #include "VertexShader.hpp"
19
20 namespace sw
21 {
22         class VertexRoutine
23         {
24         protected:
25                 struct Registers
26                 {
27                         Registers(const VertexShader *shader) :
28                                 r(shader && shader->dynamicallyIndexedTemporaries),
29                                 v(shader && shader->dynamicallyIndexedInput),
30                                 o(shader && shader->dynamicallyIndexedOutput)
31                         {
32                                 loopDepth = -1;
33                                 enableStack[0] = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
34                                 
35                                 if(shader && shader->containsBreakInstruction())
36                                 {
37                                         enableBreak = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
38                                 }
39
40                                 if(shader && shader->containsContinueInstruction())
41                                 {
42                                         enableContinue = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
43                                 }
44
45                                 if(shader && shader->containsLeaveInstruction())
46                                 {
47                                         enableLeave = Int4(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
48                                 }
49                         }
50
51                         Pointer<Byte> data;
52                         Pointer<Byte> constants;
53
54                         Int clipFlags;
55
56                         RegisterArray<16> v;
57                         RegisterArray<4096> r;
58                         RegisterArray<12> o;
59                         Vector4f a0;
60                         Array<Int, 4> aL;
61                         Vector4f p0;
62
63                         Array<Int, 4> increment;
64                         Array<Int, 4> iteration;
65
66                         Int loopDepth;
67                         Int stackIndex;   // FIXME: Inc/decrement callStack
68                         Array<UInt, 16> callStack;
69
70                         Int enableIndex;
71                         Array<Int4, 1 + 24> enableStack;
72                         Int4 enableBreak;
73                         Int4 enableContinue;
74                         Int4 enableLeave;
75                 };
76
77         public:
78                 VertexRoutine(const VertexProcessor::State &state, const VertexShader *shader);
79
80                 virtual ~VertexRoutine();
81
82                 void generate();
83                 Routine *getRoutine();
84
85         protected:
86                 const VertexProcessor::State &state;
87                 const VertexShader *const shader;
88
89         private:                
90                 virtual void pipeline(Registers &r) = 0;
91
92                 typedef VertexProcessor::State::Input Stream;
93                 
94                 Vector4f readStream(Registers &r, Pointer<Byte> &buffer, UInt &stride, const Stream &stream, const UInt &index);
95                 void readInput(Registers &r, UInt &index);
96                 void computeClipFlags(Registers &r);
97                 void postTransform(Registers &r);
98                 void writeCache(Pointer<Byte> &cacheLine, Registers &r);
99                 void writeVertex(Pointer<Byte> &vertex, Pointer<Byte> &cacheLine);
100
101                 Routine *routine;
102         };
103 }
104
105 #endif   // sw_VertexRoutine_hpp