Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / r600 / r700_shader.h
1 /*
2  * Copyright (C) 2008-2009  Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  */
21
22 /*
23  * Authors:
24  *   Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
25  */
26
27
28 #ifndef __R700_SHADER_H__
29 #define __R700_SHADER_H__
30
31 #include "main/mtypes.h"
32
33 #include "r700_shaderinst.h"
34
35
36 void r700ShaderInit(struct gl_context * ctx);
37
38 typedef enum R700ShaderType
39 {
40     R700_SHADER_FS      = 0x0,
41     R700_SHADER_ES      = 0x1,
42     R700_SHADER_GS      = 0x2,
43     R700_SHADER_VS      = 0x3,
44     R700_SHADER_PS      = 0x4,
45     R700_SHADER_INVALID = 0x5,
46 } R700ShaderType;
47
48 typedef struct TypedShaderList 
49 {
50         R700ShaderInstruction * pHead;
51         R700ShaderInstruction * pTail;
52         GLuint  uNumOfNode;
53 } TypedShaderList;
54
55 typedef struct RealRegister 
56 {
57     GLuint uAddr;
58     GLuint uValue;
59 } RealRegister;
60
61 typedef struct InstDeps
62 {
63     GLint nDstDep;
64     GLint nSrcDeps[3];
65 } InstDeps;
66
67 typedef struct R700_Shader 
68 {
69         R700ShaderType   Type;
70
71     GLubyte*  pProgram;
72
73     GLboolean bBinaryShader;
74     GLboolean bFetchShaderRequired;
75     GLboolean bNeedsAssembly;
76     GLboolean bLinksDirty;
77
78     GLuint  uShaderBinaryDWORDSize; // in DWORDS
79     GLuint  nRegs;      
80     GLuint  nParamExports;   // VS_ EXPORT_COUNT (1 based, the actual register is 0 based!)
81     GLuint  nMemExports; 
82     GLuint  resource;     // VS and PS _RESOURCE
83     GLuint  exportMode;   // VS and PS _EXPORT_MODE
84
85     GLboolean  depthIsImported;             
86
87     // Vertex program exports
88     GLboolean  positionVectorIsExported;          
89
90     GLboolean  miscVectorIsExported;               
91     GLboolean  renderTargetArrayIndexIsExported;  
92
93     GLboolean  ccDist0VectorIsExported;  
94     GLboolean  ccDist1VectorIsExported;  
95
96     // Pixel program exports
97     GLboolean  depthIsExported;             
98     GLboolean  stencilRefIsExported;        
99     GLboolean  coverageToMaskIsExported;    
100     GLboolean  maskIsExported;              
101
102     GLboolean  killIsUsed;                  
103
104     GLuint  uStartAddr;
105     GLuint  uCFOffset;
106     GLuint  uEndOfCF;
107     GLuint  uEndOfALU;
108     GLuint  uEndOfFetch;
109     GLuint  uStackSize;
110     GLuint  uMaxCallDepth;
111
112     TypedShaderList * plstCFInstructions_active;
113         TypedShaderList lstCFInstructions;
114         TypedShaderList lstALUInstructions;
115         TypedShaderList lstTEXInstructions;
116         TypedShaderList lstVTXInstructions;
117
118     RealRegister RegStartAddr;
119     RealRegister RegCFOffset;
120     RealRegister RegEndCF;
121     RealRegister RegEndALU;
122     RealRegister egEndFetcg;
123
124         // -------- constants
125         GLfloat   ConstantArray[SQ_ALU_CONSTANT_PS_COUNT * 4];
126         
127         GLboolean bSurfAllocated;
128 } R700_Shader;
129
130 //Internal
131 void AddInstToList(TypedShaderList * plstCFInstructions, R700ShaderInstruction * pInst);
132 void TakeInstOutFromList(TypedShaderList * plstCFInstructions, R700ShaderInstruction * pInst);
133 void ResolveLinks(R700_Shader *pShader);
134 void Assemble(R700_Shader *pShader);
135
136 //Interface
137 void Init_R700_Shader(R700_Shader * pShader);
138 void AddCFInstruction(R700_Shader *pShader, R700ControlFlowInstruction *pCFInst);
139 void AddVTXInstruction(R700_Shader *pShader, R700VertexInstruction *pVTXInst);
140 void AddTEXInstruction(R700_Shader *pShader, R700TextureInstruction *pTEXInst);
141 void AddALUInstruction(R700_Shader *pShader, R700ALUInstruction *pALUInst);
142 void SetActiveCFlist(R700_Shader *pShader, TypedShaderList * plstCF);
143
144 void LoadProgram(R700_Shader *pShader);
145 void UpdateShaderRegisters(R700_Shader *pShader);
146 void DeleteInstructions(R700_Shader *pShader);
147 void DebugPrint(void);
148 void cleanup_vfetch_shaderinst(R700_Shader *pShader);
149
150 void Clean_Up_Shader(R700_Shader *pShader);
151
152 #endif /*__R700_SHADER_H__*/
153