Port Mesa to build on a P64 platform (e.g., Win64). P64 platforms
[mesa.git] / src / mesa / shader / arbvertparse.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.2
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 #define DEBUG_VP 0
26
27 /**
28 * \file arbvertparse.c
29 * ARB_vertex_program parser.
30 * \author Karl Rasche
31 */
32
33 #include "glheader.h"
34 #include "context.h"
35 #include "arbvertparse.h"
36 #include "hash.h"
37 #include "imports.h"
38 #include "macros.h"
39 #include "mtypes.h"
40 #include "program.h"
41 #include "nvprogram.h"
42 #include "nvvertparse.h"
43 #include "nvvertprog.h"
44
45 #include "arbprogparse.h"
46
47
48 /**
49 * XXX this is probably redundant. We've already got code like this
50 * in the nvvertparse.c file. Combine/clean-up someday.
51 */
52 void _mesa_debug_vp_inst(GLint num, struct vp_instruction *vp)
53 {
54 GLint a;
55 static const char *opcode_string[] = {
56 "ABS",
57 "ADD",
58 "ARL",
59 "DP3",
60 "DP4",
61 "DPH",
62 "DST",
63 "END", /* Placeholder */
64 "EX2", /* ARB only */
65 "EXP",
66 "FLR", /* ARB */
67 "FRC", /* ARB */
68 "LG2", /* ARB only */
69 "LIT",
70 "LOG",
71 "MAD",
72 "MAX",
73 "MIN",
74 "MOV",
75 "MUL",
76 "POW", /* ARB only */
77 "PRINT", /* Mesa only */
78 "RCC",
79 "RCP",
80 "RSQ",
81 "SGE",
82 "SLT",
83 "SUB",
84 "SWZ", /* ARB only */
85 "XPD" /* ARB only */
86 };
87
88 static const char *file_string[] = {
89 "TEMP",
90 "INPUT",
91 "OUTPUT",
92 "LOCAL",
93 "ENV",
94 "NAMED",
95 "STATE",
96 "WRITE_ONLY",
97 "ADDR"
98 };
99
100 static const char swz[] = "xyzw01??";
101
102 for (a=0; a<num; a++) {
103 _mesa_printf("%s", opcode_string[vp[a].Opcode]);
104
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" : "");
112 else
113 _mesa_printf(" %s[%d] ", file_string[vp[a].DstReg.File], vp[a].DstReg.Index);
114 }
115
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)]);
125 else
126 _mesa_printf("%s[%d] ", file_string[vp[a].SrcReg[0].File], vp[a].SrcReg[0].Index);
127 }
128
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)]);
138 else
139 _mesa_printf("%s[%d] ", file_string[vp[a].SrcReg[1].File], vp[a].SrcReg[1].Index);
140 }
141
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)]);
151 else
152 _mesa_printf("%s[%d] ", file_string[vp[a].SrcReg[2].File], vp[a].SrcReg[2].Index);
153 }
154
155 _mesa_printf("\n");
156 }
157 }
158
159
160 void
161 _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target,
162 const GLubyte * str, GLsizei len,
163 struct vertex_program *program)
164 {
165 GLuint retval;
166 struct arb_program ap;
167 (void) target;
168
169 /* set the program target before parsing */
170 ap.Base.Target = GL_VERTEX_PROGRAM_ARB;
171
172 retval = _mesa_parse_arb_program(ctx, str, len, &ap);
173
174 /* Parse error. Allocate a dummy program and return */
175 if (retval)
176 {
177 program->Instructions = (struct vp_instruction *)
178 _mesa_malloc ( sizeof(struct vp_instruction) );
179 program->Instructions[0].Opcode = VP_OPCODE_END;
180 return;
181 }
182
183 /* copy the relvant contents of the arb_program struct into the
184 * fragment_program struct
185 */
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;
192
193 program->IsPositionInvariant = ap.HintPositionInvariant;
194 program->InputsRead = ap.InputsRead;
195 program->OutputsWritten = ap.OutputsWritten;
196 program->Parameters = ap.Parameters;
197
198 program->Instructions = ap.VPInstructions;
199
200 #if DEBUG_VP
201 _mesa_debug_vp_inst(ap.Base.NumInstructions, ap.VPInstructions);
202 #endif
203
204 }