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 _mesa_printf("%s[%d].%c%c%c%c ", file_string
[vp
[a
].SrcReg
[0].File
], vp
[a
].SrcReg
[0].Index
,
119 swz
[GET_SWZ(vp
[a
].SrcReg
[0].Swizzle
, 0)],
120 swz
[GET_SWZ(vp
[a
].SrcReg
[0].Swizzle
, 1)],
121 swz
[GET_SWZ(vp
[a
].SrcReg
[0].Swizzle
, 2)],
122 swz
[GET_SWZ(vp
[a
].SrcReg
[0].Swizzle
, 3)]);
124 _mesa_printf("%s[%d] ", file_string
[vp
[a
].SrcReg
[0].File
], vp
[a
].SrcReg
[0].Index
);
127 if (vp
[a
].SrcReg
[1].File
!= 0xf) {
128 if (vp
[a
].SrcReg
[1].Swizzle
!= SWIZZLE_NOOP
)
129 _mesa_printf("%s[%d].%c%c%c%c ", file_string
[vp
[a
].SrcReg
[1].File
], vp
[a
].SrcReg
[1].Index
,
130 swz
[GET_SWZ(vp
[a
].SrcReg
[1].Swizzle
, 0)],
131 swz
[GET_SWZ(vp
[a
].SrcReg
[1].Swizzle
, 1)],
132 swz
[GET_SWZ(vp
[a
].SrcReg
[1].Swizzle
, 2)],
133 swz
[GET_SWZ(vp
[a
].SrcReg
[1].Swizzle
, 3)]);
135 _mesa_printf("%s[%d] ", file_string
[vp
[a
].SrcReg
[1].File
], vp
[a
].SrcReg
[1].Index
);
138 if (vp
[a
].SrcReg
[2].File
!= 0xf) {
139 if (vp
[a
].SrcReg
[2].Swizzle
!= SWIZZLE_NOOP
)
140 _mesa_printf("%s[%d].%c%c%c%c ", file_string
[vp
[a
].SrcReg
[2].File
], vp
[a
].SrcReg
[2].Index
,
141 swz
[GET_SWZ(vp
[a
].SrcReg
[2].Swizzle
, 0)],
142 swz
[GET_SWZ(vp
[a
].SrcReg
[2].Swizzle
, 1)],
143 swz
[GET_SWZ(vp
[a
].SrcReg
[2].Swizzle
, 2)],
144 swz
[GET_SWZ(vp
[a
].SrcReg
[2].Swizzle
, 3)]);
146 _mesa_printf("%s[%d] ", file_string
[vp
[a
].SrcReg
[2].File
], vp
[a
].SrcReg
[2].Index
);
155 _mesa_parse_arb_vertex_program(GLcontext
* ctx
, GLenum target
,
156 const GLubyte
* str
, GLsizei len
,
157 struct vertex_program
*program
)
160 struct arb_program ap
;
163 /* set the program target before parsing */
164 ap
.Base
.Target
= GL_VERTEX_PROGRAM_ARB
;
166 retval
= _mesa_parse_arb_program(ctx
, str
, len
, &ap
);
168 /* Parse error. Allocate a dummy program and return */
171 program
->Instructions
= (struct vp_instruction
*)
172 _mesa_malloc ( sizeof(struct vp_instruction
) );
173 program
->Instructions
[0].Opcode
= VP_OPCODE_END
;
177 /* copy the relvant contents of the arb_program struct into the
178 * fragment_program struct
180 program
->Base
.String
= ap
.Base
.String
;
181 program
->Base
.NumInstructions
= ap
.Base
.NumInstructions
;
182 program
->Base
.NumTemporaries
= ap
.Base
.NumTemporaries
;
183 program
->Base
.NumParameters
= ap
.Base
.NumParameters
;
184 program
->Base
.NumAttributes
= ap
.Base
.NumAttributes
;
185 program
->Base
.NumAddressRegs
= ap
.Base
.NumAddressRegs
;
187 program
->IsPositionInvariant
= ap
.HintPositionInvariant
;
188 program
->InputsRead
= ap
.InputsRead
;
189 program
->OutputsWritten
= ap
.OutputsWritten
;
190 program
->Parameters
= ap
.Parameters
;
192 program
->Instructions
= ap
.VPInstructions
;
195 _mesa_debug_vp_inst(ap
.Base
.NumInstructions
, ap
.VPInstructions
);