2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 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.
39 #include "nvprogram.h"
40 #include "nvvertparse.h"
41 #include "nvvertprog.h"
47 debug_vp_inst(GLint num
, struct vp_instruction
*vp
)
51 for (a
=0; a
<num
; a
++) {
52 switch (vp
[a
].Opcode
) {
54 fprintf(stderr
, "VP_OPCODE_MOV"); break;
57 fprintf(stderr
, "VP_OPCODE_LIT"); break;
60 fprintf(stderr
, "VP_OPCODE_RCP"); break;
63 fprintf(stderr
, "VP_OPCODE_RSQ"); break;
66 fprintf(stderr
, "VP_OPCODE_EXP"); break;
69 fprintf(stderr
, "VP_OPCODE_LOG"); break;
72 fprintf(stderr
, "VP_OPCODE_MUL"); break;
75 fprintf(stderr
, "VP_OPCODE_ADD"); break;
78 fprintf(stderr
, "VP_OPCODE_DP3"); break;
81 fprintf(stderr
, "VP_OPCODE_DP4"); break;
84 fprintf(stderr
, "VP_OPCODE_DST"); break;
87 fprintf(stderr
, "VP_OPCODE_MIN"); break;
90 fprintf(stderr
, "VP_OPCODE_MAX"); break;
93 fprintf(stderr
, "VP_OPCODE_SLT"); break;
96 fprintf(stderr
, "VP_OPCODE_SGE"); break;
99 fprintf(stderr
, "VP_OPCODE_MAD"); break;
102 fprintf(stderr
, "VP_OPCODE_ARL"); break;
105 fprintf(stderr
, "VP_OPCODE_DPH"); break;
108 fprintf(stderr
, "VP_OPCODE_RCC"); break;
111 fprintf(stderr
, "VP_OPCODE_SUB"); break;
114 fprintf(stderr
, "VP_OPCODE_ABS"); break;
117 fprintf(stderr
, "VP_OPCODE_FLR"); break;
120 fprintf(stderr
, "VP_OPCODE_FRC"); break;
123 fprintf(stderr
, "VP_OPCODE_EX2"); break;
126 fprintf(stderr
, "VP_OPCODE_LG2"); break;
129 fprintf(stderr
, "VP_OPCODE_POW"); break;
132 fprintf(stderr
, "VP_OPCODE_XPD"); break;
135 fprintf(stderr
, "VP_OPCODE_SWZ"); break;
138 fprintf(stderr
, "VP_OPCODE_END"); break;
141 fprintf(stderr
, " D(0x%x:%d:%d%d%d%d) ", vp
[a
].DstReg
.File
, vp
[a
].DstReg
.Index
,
142 vp
[a
].DstReg
.WriteMask
[0],
143 vp
[a
].DstReg
.WriteMask
[1],
144 vp
[a
].DstReg
.WriteMask
[2],
145 vp
[a
].DstReg
.WriteMask
[3]);
147 fprintf(stderr
, "S1(0x%x:%d:%d%d%d%d) ", vp
[a
].SrcReg
[0].File
, vp
[a
].SrcReg
[0].Index
,
148 vp
[a
].SrcReg
[0].Swizzle
[0],
149 vp
[a
].SrcReg
[0].Swizzle
[1],
150 vp
[a
].SrcReg
[0].Swizzle
[2],
151 vp
[a
].SrcReg
[0].Swizzle
[3]);
153 fprintf(stderr
, "S2(0x%x:%d:%d%d%d%d) ", vp
[a
].SrcReg
[1].File
, vp
[a
].SrcReg
[1].Index
,
154 vp
[a
].SrcReg
[1].Swizzle
[0],
155 vp
[a
].SrcReg
[1].Swizzle
[1],
156 vp
[a
].SrcReg
[1].Swizzle
[2],
157 vp
[a
].SrcReg
[1].Swizzle
[3]);
159 fprintf(stderr
, "S3(0x%x:%d:%d%d%d%d)", vp
[a
].SrcReg
[2].File
, vp
[a
].SrcReg
[2].Index
,
160 vp
[a
].SrcReg
[2].Swizzle
[0],
161 vp
[a
].SrcReg
[2].Swizzle
[1],
162 vp
[a
].SrcReg
[2].Swizzle
[2],
163 vp
[a
].SrcReg
[2].Swizzle
[3]);
165 fprintf(stderr
, "\n");
171 _mesa_parse_arb_vertex_program(GLcontext
* ctx
, GLenum target
,
172 const GLubyte
* str
, GLsizei len
,
173 struct vertex_program
*program
)
176 struct arb_program ap
;
178 retval
= _mesa_parse_arb_program(ctx
, str
, len
, &ap
);
180 /* XXX: Parse error. Cleanup things and return */
186 /* XXX: Eh.. we parsed something that wasn't a vertex program. doh! */
187 if (ap
.type
!= GL_VERTEX_PROGRAM_ARB
)
193 debug_vp_inst(ap
.Base
.NumInstructions
, ap
.VPInstructions
);
196 /* copy the relvant contents of the arb_program struct into the
197 * fragment_program struct
199 program
->Base
.NumInstructions
= ap
.Base
.NumInstructions
;
200 program
->Base
.NumTemporaries
= ap
.Base
.NumTemporaries
;
201 program
->Base
.NumParameters
= ap
.Base
.NumParameters
;
202 program
->Base
.NumAttributes
= ap
.Base
.NumAttributes
;
203 program
->Base
.NumAddressRegs
= ap
.Base
.NumAddressRegs
;
205 program
->Instructions
= ap
.VPInstructions
;
206 program
->IsPositionInvariant
= ap
.HintPositionInvariant
;
207 program
->InputsRead
= ap
.InputsRead
;
208 program
->OutputsWritten
= ap
.OutputsWritten
;
209 program
->Parameters
= ap
.Parameters
;