cosmetic 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 /**
48 * XXX this is probably redundant. We've already got code like this
49 * in the nvvertparse.c file. Combine/clean-up someday.
50 */
51 static GLvoid
52 debug_vp_inst(GLint num, struct vp_instruction *vp)
53 {
54 GLint a;
55
56 for (a=0; a<num; a++) {
57 switch (vp[a].Opcode) {
58 case VP_OPCODE_MOV:
59 fprintf(stderr, "VP_OPCODE_MOV"); break;
60
61 case VP_OPCODE_LIT:
62 fprintf(stderr, "VP_OPCODE_LIT"); break;
63
64 case VP_OPCODE_RCP:
65 fprintf(stderr, "VP_OPCODE_RCP"); break;
66
67 case VP_OPCODE_RSQ:
68 fprintf(stderr, "VP_OPCODE_RSQ"); break;
69
70 case VP_OPCODE_EXP:
71 fprintf(stderr, "VP_OPCODE_EXP"); break;
72
73 case VP_OPCODE_LOG:
74 fprintf(stderr, "VP_OPCODE_LOG"); break;
75
76 case VP_OPCODE_MUL:
77 fprintf(stderr, "VP_OPCODE_MUL"); break;
78
79 case VP_OPCODE_ADD:
80 fprintf(stderr, "VP_OPCODE_ADD"); break;
81
82 case VP_OPCODE_DP3:
83 fprintf(stderr, "VP_OPCODE_DP3"); break;
84
85 case VP_OPCODE_DP4:
86 fprintf(stderr, "VP_OPCODE_DP4"); break;
87
88 case VP_OPCODE_DST:
89 fprintf(stderr, "VP_OPCODE_DST"); break;
90
91 case VP_OPCODE_MIN:
92 fprintf(stderr, "VP_OPCODE_MIN"); break;
93
94 case VP_OPCODE_MAX:
95 fprintf(stderr, "VP_OPCODE_MAX"); break;
96
97 case VP_OPCODE_SLT:
98 fprintf(stderr, "VP_OPCODE_SLT"); break;
99
100 case VP_OPCODE_SGE:
101 fprintf(stderr, "VP_OPCODE_SGE"); break;
102
103 case VP_OPCODE_MAD:
104 fprintf(stderr, "VP_OPCODE_MAD"); break;
105
106 case VP_OPCODE_ARL:
107 fprintf(stderr, "VP_OPCODE_ARL"); break;
108
109 case VP_OPCODE_DPH:
110 fprintf(stderr, "VP_OPCODE_DPH"); break;
111
112 case VP_OPCODE_RCC:
113 fprintf(stderr, "VP_OPCODE_RCC"); break;
114
115 case VP_OPCODE_SUB:
116 fprintf(stderr, "VP_OPCODE_SUB"); break;
117
118 case VP_OPCODE_ABS:
119 fprintf(stderr, "VP_OPCODE_ABS"); break;
120
121 case VP_OPCODE_FLR:
122 fprintf(stderr, "VP_OPCODE_FLR"); break;
123
124 case VP_OPCODE_FRC:
125 fprintf(stderr, "VP_OPCODE_FRC"); break;
126
127 case VP_OPCODE_EX2:
128 fprintf(stderr, "VP_OPCODE_EX2"); break;
129
130 case VP_OPCODE_LG2:
131 fprintf(stderr, "VP_OPCODE_LG2"); break;
132
133 case VP_OPCODE_POW:
134 fprintf(stderr, "VP_OPCODE_POW"); break;
135
136 case VP_OPCODE_XPD:
137 fprintf(stderr, "VP_OPCODE_XPD"); break;
138
139 case VP_OPCODE_SWZ:
140 fprintf(stderr, "VP_OPCODE_SWZ"); break;
141
142 case VP_OPCODE_PRINT:
143 fprintf(stderr, "VP_OPCODE_PRINT"); break;
144
145 case VP_OPCODE_END:
146 fprintf(stderr, "VP_OPCODE_END"); break;
147 }
148
149 fprintf(stderr, " D(0x%x:%d:%d%d%d%d) ", vp[a].DstReg.File, vp[a].DstReg.Index,
150 vp[a].DstReg.WriteMask[0],
151 vp[a].DstReg.WriteMask[1],
152 vp[a].DstReg.WriteMask[2],
153 vp[a].DstReg.WriteMask[3]);
154
155 fprintf(stderr, "S1(0x%x:%d:%d%d%d%d) ", vp[a].SrcReg[0].File, vp[a].SrcReg[0].Index,
156 vp[a].SrcReg[0].Swizzle[0],
157 vp[a].SrcReg[0].Swizzle[1],
158 vp[a].SrcReg[0].Swizzle[2],
159 vp[a].SrcReg[0].Swizzle[3]);
160
161 fprintf(stderr, "S2(0x%x:%d:%d%d%d%d) ", vp[a].SrcReg[1].File, vp[a].SrcReg[1].Index,
162 vp[a].SrcReg[1].Swizzle[0],
163 vp[a].SrcReg[1].Swizzle[1],
164 vp[a].SrcReg[1].Swizzle[2],
165 vp[a].SrcReg[1].Swizzle[3]);
166
167 fprintf(stderr, "S3(0x%x:%d:%d%d%d%d)", vp[a].SrcReg[2].File, vp[a].SrcReg[2].Index,
168 vp[a].SrcReg[2].Swizzle[0],
169 vp[a].SrcReg[2].Swizzle[1],
170 vp[a].SrcReg[2].Swizzle[2],
171 vp[a].SrcReg[2].Swizzle[3]);
172
173 fprintf(stderr, "\n");
174 }
175 }
176
177
178 void
179 _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target,
180 const GLubyte * str, GLsizei len,
181 struct vertex_program *program)
182 {
183 GLuint retval;
184 struct arb_program ap;
185 (void) target;
186
187 /* set the program target before parsing */
188 ap.Base.Target = GL_VERTEX_PROGRAM_ARB;
189
190 retval = _mesa_parse_arb_program(ctx, str, len, &ap);
191
192 /* Parse error. Allocate a dummy program and return */
193 if (retval)
194 {
195 program->Instructions = (struct vp_instruction *)
196 _mesa_malloc ( sizeof(struct vp_instruction) );
197 program->Instructions[0].Opcode = VP_OPCODE_END;
198 return;
199 }
200
201 /* copy the relvant contents of the arb_program struct into the
202 * fragment_program struct
203 */
204 program->Base.String = ap.Base.String;
205 program->Base.NumInstructions = ap.Base.NumInstructions;
206 program->Base.NumTemporaries = ap.Base.NumTemporaries;
207 program->Base.NumParameters = ap.Base.NumParameters;
208 program->Base.NumAttributes = ap.Base.NumAttributes;
209 program->Base.NumAddressRegs = ap.Base.NumAddressRegs;
210
211 program->IsPositionInvariant = ap.HintPositionInvariant;
212 program->InputsRead = ap.InputsRead;
213 program->OutputsWritten = ap.OutputsWritten;
214 program->Parameters = ap.Parameters;
215
216 program->Instructions = ap.VPInstructions;
217
218 #if DEBUG_VP
219 debug_vp_inst(ap.Base.NumInstructions, ap.VPInstructions);
220 #else
221 (void) debug_vp_inst;
222 #endif
223
224 }