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"
41 #include "nvprogram.h"
42 #include "nvvertparse.h"
43 #include "nvvertprog.h"
45 #include "arbprogparse.h"
49 * XXX this is probably redundant. We've already got code like this
50 * in the nvvertparse.c file. Combine/clean-up someday.
52 void _mesa_debug_vp_inst(GLint num
, struct vp_instruction
*vp
)
55 static const char *opcode_string
[] = {
63 "END", /* Placeholder */
77 "PRINT", /* Mesa only */
88 static const char *file_string
[] = {
100 static const char swz
[] = "xyzw01??";
102 for (a
=0; a
<num
; a
++) {
103 _mesa_printf("%s", opcode_string
[vp
[a
].Opcode
]);
105 if (vp
[a
].DstReg
.File
!= 0xf) {
106 if (vp
[a
].DstReg
.WriteMask
!= 0xf)
107 _mesa_printf(" %s[%d].%s%s%s%s ", file_string
[vp
[a
].DstReg
.File
], vp
[a
].DstReg
.Index
,
108 GET_BIT(vp
[a
].DstReg
.WriteMask
, 0) ? "x" : "",
109 GET_BIT(vp
[a
].DstReg
.WriteMask
, 1) ? "y" : "",
110 GET_BIT(vp
[a
].DstReg
.WriteMask
, 2) ? "z" : "",
111 GET_BIT(vp
[a
].DstReg
.WriteMask
, 3) ? "w" : "");
113 _mesa_printf(" %s[%d] ", file_string
[vp
[a
].DstReg
.File
], vp
[a
].DstReg
.Index
);
116 if (vp
[a
].SrcReg
[0].File
!= 0xf) {
117 if (vp
[a
].SrcReg
[0].Swizzle
!= SWIZZLE_NOOP
||
118 vp
[a
].SrcReg
[0].Negate
)
119 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string
[vp
[a
].SrcReg
[0].File
], vp
[a
].SrcReg
[0].Index
,
120 vp
[a
].SrcReg
[0].Negate
? "-" : "",
121 swz
[GET_SWZ(vp
[a
].SrcReg
[0].Swizzle
, 0)],
122 swz
[GET_SWZ(vp
[a
].SrcReg
[0].Swizzle
, 1)],
123 swz
[GET_SWZ(vp
[a
].SrcReg
[0].Swizzle
, 2)],
124 swz
[GET_SWZ(vp
[a
].SrcReg
[0].Swizzle
, 3)]);
126 _mesa_printf("%s[%d] ", file_string
[vp
[a
].SrcReg
[0].File
], vp
[a
].SrcReg
[0].Index
);
129 if (vp
[a
].SrcReg
[1].File
!= 0xf) {
130 if (vp
[a
].SrcReg
[1].Swizzle
!= SWIZZLE_NOOP
||
131 vp
[a
].SrcReg
[1].Negate
)
132 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string
[vp
[a
].SrcReg
[1].File
], vp
[a
].SrcReg
[1].Index
,
133 vp
[a
].SrcReg
[1].Negate
? "-" : "",
134 swz
[GET_SWZ(vp
[a
].SrcReg
[1].Swizzle
, 0)],
135 swz
[GET_SWZ(vp
[a
].SrcReg
[1].Swizzle
, 1)],
136 swz
[GET_SWZ(vp
[a
].SrcReg
[1].Swizzle
, 2)],
137 swz
[GET_SWZ(vp
[a
].SrcReg
[1].Swizzle
, 3)]);
139 _mesa_printf("%s[%d] ", file_string
[vp
[a
].SrcReg
[1].File
], vp
[a
].SrcReg
[1].Index
);
142 if (vp
[a
].SrcReg
[2].File
!= 0xf) {
143 if (vp
[a
].SrcReg
[2].Swizzle
!= SWIZZLE_NOOP
||
144 vp
[a
].SrcReg
[2].Negate
)
145 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string
[vp
[a
].SrcReg
[2].File
], vp
[a
].SrcReg
[2].Index
,
146 vp
[a
].SrcReg
[2].Negate
? "-" : "",
147 swz
[GET_SWZ(vp
[a
].SrcReg
[2].Swizzle
, 0)],
148 swz
[GET_SWZ(vp
[a
].SrcReg
[2].Swizzle
, 1)],
149 swz
[GET_SWZ(vp
[a
].SrcReg
[2].Swizzle
, 2)],
150 swz
[GET_SWZ(vp
[a
].SrcReg
[2].Swizzle
, 3)]);
152 _mesa_printf("%s[%d] ", file_string
[vp
[a
].SrcReg
[2].File
], vp
[a
].SrcReg
[2].Index
);
161 _mesa_parse_arb_vertex_program(GLcontext
* ctx
, GLenum target
,
162 const GLubyte
* str
, GLsizei len
,
163 struct vertex_program
*program
)
166 struct arb_program ap
;
169 /* set the program target before parsing */
170 ap
.Base
.Target
= GL_VERTEX_PROGRAM_ARB
;
172 retval
= _mesa_parse_arb_program(ctx
, str
, len
, &ap
);
174 /* Parse error. Allocate a dummy program and return */
177 program
->Instructions
= (struct vp_instruction
*)
178 _mesa_malloc ( sizeof(struct vp_instruction
) );
179 program
->Instructions
[0].Opcode
= VP_OPCODE_END
;
183 /* copy the relvant contents of the arb_program struct into the
184 * fragment_program struct
186 program
->Base
.String
= ap
.Base
.String
;
187 program
->Base
.NumInstructions
= ap
.Base
.NumInstructions
;
188 program
->Base
.NumTemporaries
= ap
.Base
.NumTemporaries
;
189 program
->Base
.NumParameters
= ap
.Base
.NumParameters
;
190 program
->Base
.NumAttributes
= ap
.Base
.NumAttributes
;
191 program
->Base
.NumAddressRegs
= ap
.Base
.NumAddressRegs
;
193 program
->IsPositionInvariant
= ap
.HintPositionInvariant
;
194 program
->InputsRead
= ap
.InputsRead
;
195 program
->OutputsWritten
= ap
.OutputsWritten
;
196 program
->Parameters
= ap
.Parameters
;
198 program
->Instructions
= ap
.VPInstructions
;
201 _mesa_debug_vp_inst(ap
.Base
.NumInstructions
, ap
.VPInstructions
);