2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 * \file arbvertparse.c
29 * ARB_vertex_program parser.
35 #include "arbvertparse.h"
40 #include "nvprogram.h"
41 #include "nvvertparse.h"
42 #include "nvvertprog.h"
44 #include "arbprogparse.h"
48 * XXX this is probably redundant. We've already got code like this
49 * in the nvvertparse.c file. Combine/clean-up someday.
52 debug_vp_inst(GLint num
, struct vp_instruction
*vp
)
56 for (a
=0; a
<num
; a
++) {
57 switch (vp
[a
].Opcode
) {
59 fprintf(stderr
, "VP_OPCODE_MOV"); break;
62 fprintf(stderr
, "VP_OPCODE_LIT"); break;
65 fprintf(stderr
, "VP_OPCODE_RCP"); break;
68 fprintf(stderr
, "VP_OPCODE_RSQ"); break;
71 fprintf(stderr
, "VP_OPCODE_EXP"); break;
74 fprintf(stderr
, "VP_OPCODE_LOG"); break;
77 fprintf(stderr
, "VP_OPCODE_MUL"); break;
80 fprintf(stderr
, "VP_OPCODE_ADD"); break;
83 fprintf(stderr
, "VP_OPCODE_DP3"); break;
86 fprintf(stderr
, "VP_OPCODE_DP4"); break;
89 fprintf(stderr
, "VP_OPCODE_DST"); break;
92 fprintf(stderr
, "VP_OPCODE_MIN"); break;
95 fprintf(stderr
, "VP_OPCODE_MAX"); break;
98 fprintf(stderr
, "VP_OPCODE_SLT"); break;
101 fprintf(stderr
, "VP_OPCODE_SGE"); break;
104 fprintf(stderr
, "VP_OPCODE_MAD"); break;
107 fprintf(stderr
, "VP_OPCODE_ARL"); break;
110 fprintf(stderr
, "VP_OPCODE_DPH"); break;
113 fprintf(stderr
, "VP_OPCODE_RCC"); break;
116 fprintf(stderr
, "VP_OPCODE_SUB"); break;
119 fprintf(stderr
, "VP_OPCODE_ABS"); break;
122 fprintf(stderr
, "VP_OPCODE_FLR"); break;
125 fprintf(stderr
, "VP_OPCODE_FRC"); break;
128 fprintf(stderr
, "VP_OPCODE_EX2"); break;
131 fprintf(stderr
, "VP_OPCODE_LG2"); break;
134 fprintf(stderr
, "VP_OPCODE_POW"); break;
137 fprintf(stderr
, "VP_OPCODE_XPD"); break;
140 fprintf(stderr
, "VP_OPCODE_SWZ"); break;
142 case VP_OPCODE_PRINT
:
143 fprintf(stderr
, "VP_OPCODE_PRINT"); break;
146 fprintf(stderr
, "VP_OPCODE_END"); break;
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]);
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]);
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]);
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]);
173 fprintf(stderr
, "\n");
179 _mesa_parse_arb_vertex_program(GLcontext
* ctx
, GLenum target
,
180 const GLubyte
* str
, GLsizei len
,
181 struct vertex_program
*program
)
184 struct arb_program ap
;
187 /* set the program target before parsing */
188 ap
.Base
.Target
= GL_VERTEX_PROGRAM_ARB
;
190 retval
= _mesa_parse_arb_program(ctx
, str
, len
, &ap
);
192 /* Parse error. Allocate a dummy program and return */
195 program
->Instructions
= (struct vp_instruction
*)
196 _mesa_malloc ( sizeof(struct vp_instruction
) );
197 program
->Instructions
[0].Opcode
= VP_OPCODE_END
;
201 /* copy the relvant contents of the arb_program struct into the
202 * fragment_program struct
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
;
211 program
->IsPositionInvariant
= ap
.HintPositionInvariant
;
212 program
->InputsRead
= ap
.InputsRead
;
213 program
->OutputsWritten
= ap
.OutputsWritten
;
214 program
->Parameters
= ap
.Parameters
;
216 program
->Instructions
= ap
.VPInstructions
;
219 debug_vp_inst(ap
.Base
.NumInstructions
, ap
.VPInstructions
);
221 (void) debug_vp_inst
;