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 debug_vp_inst(GLint num
, struct vp_instruction
*vp
)
52 for (a
=0; a
<num
; a
++) {
53 switch (vp
[a
].Opcode
) {
55 fprintf(stderr
, "VP_OPCODE_MOV"); break;
58 fprintf(stderr
, "VP_OPCODE_LIT"); break;
61 fprintf(stderr
, "VP_OPCODE_RCP"); break;
64 fprintf(stderr
, "VP_OPCODE_RSQ"); break;
67 fprintf(stderr
, "VP_OPCODE_EXP"); break;
70 fprintf(stderr
, "VP_OPCODE_LOG"); break;
73 fprintf(stderr
, "VP_OPCODE_MUL"); break;
76 fprintf(stderr
, "VP_OPCODE_ADD"); break;
79 fprintf(stderr
, "VP_OPCODE_DP3"); break;
82 fprintf(stderr
, "VP_OPCODE_DP4"); break;
85 fprintf(stderr
, "VP_OPCODE_DST"); break;
88 fprintf(stderr
, "VP_OPCODE_MIN"); break;
91 fprintf(stderr
, "VP_OPCODE_MAX"); break;
94 fprintf(stderr
, "VP_OPCODE_SLT"); break;
97 fprintf(stderr
, "VP_OPCODE_SGE"); break;
100 fprintf(stderr
, "VP_OPCODE_MAD"); break;
103 fprintf(stderr
, "VP_OPCODE_ARL"); break;
106 fprintf(stderr
, "VP_OPCODE_DPH"); break;
109 fprintf(stderr
, "VP_OPCODE_RCC"); break;
112 fprintf(stderr
, "VP_OPCODE_SUB"); break;
115 fprintf(stderr
, "VP_OPCODE_ABS"); break;
118 fprintf(stderr
, "VP_OPCODE_FLR"); break;
121 fprintf(stderr
, "VP_OPCODE_FRC"); break;
124 fprintf(stderr
, "VP_OPCODE_EX2"); break;
127 fprintf(stderr
, "VP_OPCODE_LG2"); break;
130 fprintf(stderr
, "VP_OPCODE_POW"); break;
133 fprintf(stderr
, "VP_OPCODE_XPD"); break;
136 fprintf(stderr
, "VP_OPCODE_SWZ"); break;
139 fprintf(stderr
, "VP_OPCODE_END"); break;
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]);
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]);
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]);
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]);
166 fprintf(stderr
, "\n");
172 _mesa_parse_arb_vertex_program(GLcontext
* ctx
, GLenum target
,
173 const GLubyte
* str
, GLsizei len
,
174 struct vertex_program
*program
)
177 struct arb_program ap
;
180 /* set the program target before parsing */
181 ap
.Base
.Target
= GL_VERTEX_PROGRAM_ARB
;
183 retval
= _mesa_parse_arb_program(ctx
, str
, len
, &ap
);
185 /* Parse error. Allocate a dummy program and return */
188 program
->Instructions
= (struct vp_instruction
*) _mesa_malloc (
189 sizeof(struct vp_instruction
) );
190 program
->Instructions
[0].Opcode
= VP_OPCODE_END
;
194 /* copy the relvant contents of the arb_program struct into the
195 * fragment_program struct
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
;
204 program
->IsPositionInvariant
= ap
.HintPositionInvariant
;
205 program
->InputsRead
= ap
.InputsRead
;
206 program
->OutputsWritten
= ap
.OutputsWritten
;
207 program
->Parameters
= ap
.Parameters
;
209 program
->Instructions
= ap
.VPInstructions
;
212 debug_vp_inst(ap
.Base
.NumInstructions
, ap
.VPInstructions
);
214 (void) debug_vp_inst
;