uint*t -> u_int*t changes
[mesa.git] / src / mesa / shader / arbvertparse.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.2
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #define DEBUG_VP 0
26
27 /**
28 * \file arbvertparse.c
29 * ARB_vertex_program parser.
30 * \author Karl Rasche
31 */
32
33 #include "glheader.h"
34 #include "context.h"
35 #include "arbvertparse.h"
36 #include "hash.h"
37 #include "imports.h"
38 #include "macros.h"
39 #include "mtypes.h"
40 #include "nvprogram.h"
41 #include "nvvertparse.h"
42 #include "nvvertprog.h"
43
44 #include "arbprogparse.h"
45
46
47 static GLvoid
48 debug_vp_inst(GLint num, struct vp_instruction *vp)
49 {
50 GLint a;
51
52 for (a=0; a<num; a++) {
53 switch (vp[a].Opcode) {
54 case VP_OPCODE_MOV:
55 fprintf(stderr, "VP_OPCODE_MOV"); break;
56
57 case VP_OPCODE_LIT:
58 fprintf(stderr, "VP_OPCODE_LIT"); break;
59
60 case VP_OPCODE_RCP:
61 fprintf(stderr, "VP_OPCODE_RCP"); break;
62
63 case VP_OPCODE_RSQ:
64 fprintf(stderr, "VP_OPCODE_RSQ"); break;
65
66 case VP_OPCODE_EXP:
67 fprintf(stderr, "VP_OPCODE_EXP"); break;
68
69 case VP_OPCODE_LOG:
70 fprintf(stderr, "VP_OPCODE_LOG"); break;
71
72 case VP_OPCODE_MUL:
73 fprintf(stderr, "VP_OPCODE_MUL"); break;
74
75 case VP_OPCODE_ADD:
76 fprintf(stderr, "VP_OPCODE_ADD"); break;
77
78 case VP_OPCODE_DP3:
79 fprintf(stderr, "VP_OPCODE_DP3"); break;
80
81 case VP_OPCODE_DP4:
82 fprintf(stderr, "VP_OPCODE_DP4"); break;
83
84 case VP_OPCODE_DST:
85 fprintf(stderr, "VP_OPCODE_DST"); break;
86
87 case VP_OPCODE_MIN:
88 fprintf(stderr, "VP_OPCODE_MIN"); break;
89
90 case VP_OPCODE_MAX:
91 fprintf(stderr, "VP_OPCODE_MAX"); break;
92
93 case VP_OPCODE_SLT:
94 fprintf(stderr, "VP_OPCODE_SLT"); break;
95
96 case VP_OPCODE_SGE:
97 fprintf(stderr, "VP_OPCODE_SGE"); break;
98
99 case VP_OPCODE_MAD:
100 fprintf(stderr, "VP_OPCODE_MAD"); break;
101
102 case VP_OPCODE_ARL:
103 fprintf(stderr, "VP_OPCODE_ARL"); break;
104
105 case VP_OPCODE_DPH:
106 fprintf(stderr, "VP_OPCODE_DPH"); break;
107
108 case VP_OPCODE_RCC:
109 fprintf(stderr, "VP_OPCODE_RCC"); break;
110
111 case VP_OPCODE_SUB:
112 fprintf(stderr, "VP_OPCODE_SUB"); break;
113
114 case VP_OPCODE_ABS:
115 fprintf(stderr, "VP_OPCODE_ABS"); break;
116
117 case VP_OPCODE_FLR:
118 fprintf(stderr, "VP_OPCODE_FLR"); break;
119
120 case VP_OPCODE_FRC:
121 fprintf(stderr, "VP_OPCODE_FRC"); break;
122
123 case VP_OPCODE_EX2:
124 fprintf(stderr, "VP_OPCODE_EX2"); break;
125
126 case VP_OPCODE_LG2:
127 fprintf(stderr, "VP_OPCODE_LG2"); break;
128
129 case VP_OPCODE_POW:
130 fprintf(stderr, "VP_OPCODE_POW"); break;
131
132 case VP_OPCODE_XPD:
133 fprintf(stderr, "VP_OPCODE_XPD"); break;
134
135 case VP_OPCODE_SWZ:
136 fprintf(stderr, "VP_OPCODE_SWZ"); break;
137
138 case VP_OPCODE_END:
139 fprintf(stderr, "VP_OPCODE_END"); break;
140 }
141
142 fprintf(stderr, " D(0x%x:%d:%d%d%d%d) ", vp[a].DstReg.File, vp[a].DstReg.Index,
143 vp[a].DstReg.WriteMask[0],
144 vp[a].DstReg.WriteMask[1],
145 vp[a].DstReg.WriteMask[2],
146 vp[a].DstReg.WriteMask[3]);
147
148 fprintf(stderr, "S1(0x%x:%d:%d%d%d%d) ", vp[a].SrcReg[0].File, vp[a].SrcReg[0].Index,
149 vp[a].SrcReg[0].Swizzle[0],
150 vp[a].SrcReg[0].Swizzle[1],
151 vp[a].SrcReg[0].Swizzle[2],
152 vp[a].SrcReg[0].Swizzle[3]);
153
154 fprintf(stderr, "S2(0x%x:%d:%d%d%d%d) ", vp[a].SrcReg[1].File, vp[a].SrcReg[1].Index,
155 vp[a].SrcReg[1].Swizzle[0],
156 vp[a].SrcReg[1].Swizzle[1],
157 vp[a].SrcReg[1].Swizzle[2],
158 vp[a].SrcReg[1].Swizzle[3]);
159
160 fprintf(stderr, "S3(0x%x:%d:%d%d%d%d)", vp[a].SrcReg[2].File, vp[a].SrcReg[2].Index,
161 vp[a].SrcReg[2].Swizzle[0],
162 vp[a].SrcReg[2].Swizzle[1],
163 vp[a].SrcReg[2].Swizzle[2],
164 vp[a].SrcReg[2].Swizzle[3]);
165
166 fprintf(stderr, "\n");
167 }
168 }
169
170
171 void
172 _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target,
173 const GLubyte * str, GLsizei len,
174 struct vertex_program *program)
175 {
176 GLuint retval;
177 struct arb_program ap;
178 (void) target;
179
180 /* set the program target before parsing */
181 ap.Base.Target = GL_VERTEX_PROGRAM_ARB;
182
183 retval = _mesa_parse_arb_program(ctx, str, len, &ap);
184
185 /* Parse error. Allocate a dummy program and return */
186 if (retval)
187 {
188 program->Instructions = (struct vp_instruction *) _mesa_malloc (
189 sizeof(struct vp_instruction) );
190 program->Instructions[0].Opcode = VP_OPCODE_END;
191 return;
192 }
193
194 /* copy the relvant contents of the arb_program struct into the
195 * fragment_program struct
196 */
197 program->Base.String = ap.Base.String;
198 program->Base.NumInstructions = ap.Base.NumInstructions;
199 program->Base.NumTemporaries = ap.Base.NumTemporaries;
200 program->Base.NumParameters = ap.Base.NumParameters;
201 program->Base.NumAttributes = ap.Base.NumAttributes;
202 program->Base.NumAddressRegs = ap.Base.NumAddressRegs;
203
204 program->IsPositionInvariant = ap.HintPositionInvariant;
205 program->InputsRead = ap.InputsRead;
206 program->OutputsWritten = ap.OutputsWritten;
207 program->Parameters = ap.Parameters;
208
209 program->Instructions = ap.VPInstructions;
210
211 #if DEBUG_VP
212 debug_vp_inst(ap.Base.NumInstructions, ap.VPInstructions);
213 #else
214 (void) debug_vp_inst;
215 #endif
216
217 }