Port Mesa to build on a P64 platform (e.g., Win64). P64 platforms
[mesa.git] / src / mesa / shader / arbfragparse.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_FP 0
26
27 /**
28 * \file arbfragparse.c
29 * ARB_fragment_program parser.
30 * \author Karl Rasche
31 */
32
33 #include "glheader.h"
34 #include "context.h"
35 #include "imports.h"
36 #include "macros.h"
37 #include "mtypes.h"
38 #include "program.h"
39 #include "arbprogparse.h"
40 #include "arbfragparse.h"
41
42 void
43 _mesa_debug_fp_inst(GLint num, struct fp_instruction *fp)
44 {
45 GLint a;
46
47 static const char *opcode_string[] = {
48 "ABS", /* ARB_f_p only */
49 "ADD",
50 "CMP", /* ARB_f_p only */
51 "COS",
52 "DDX", /* NV_f_p only */
53 "DDY", /* NV_f_p only */
54 "DP3",
55 "DP4",
56 "DPH", /* ARB_f_p only */
57 "DST",
58 "END", /* private opcode */
59 "EX2",
60 "FLR",
61 "FRC",
62 "KIL", /* ARB_f_p only */
63 "KIL_NV", /* NV_f_p only */
64 "LG2",
65 "LIT",
66 "LRP",
67 "MAD",
68 "MAX",
69 "MIN",
70 "MOV",
71 "MUL",
72 "PK2H", /* NV_f_p only */
73 "PK2US", /* NV_f_p only */
74 "PK4B", /* NV_f_p only */
75 "PK4UB", /* NV_f_p only */
76 "POW",
77 "PRINT", /* Mesa only */
78 "RCP",
79 "RFL", /* NV_f_p only */
80 "RSQ",
81 "SCS", /* ARB_f_p only */
82 "SEQ", /* NV_f_p only */
83 "SFL", /* NV_f_p only */
84 "SGE", /* NV_f_p only */
85 "SGT", /* NV_f_p only */
86 "SIN",
87 "SLE", /* NV_f_p only */
88 "SLT",
89 "SNE", /* NV_f_p only */
90 "STR", /* NV_f_p only */
91 "SUB",
92 "SWZ", /* ARB_f_p only */
93 "TEX",
94 "TXB", /* ARB_f_p only */
95 "TXD", /* NV_f_p only */
96 "TXP", /* ARB_f_p only */
97 "TXP_NV", /* NV_f_p only */
98 "UP2H", /* NV_f_p only */
99 "UP2US", /* NV_f_p only */
100 "UP4B", /* NV_f_p only */
101 "UP4UB", /* NV_f_p only */
102 "X2D", /* NV_f_p only - 2d mat mul */
103 "XPD", /* ARB_f_p only - cross product */
104 };
105
106 static const char *file_string[] = {
107 "TEMP",
108 "INPUT",
109 "OUTPUT",
110 "LOCAL",
111 "ENV",
112 "NAMED",
113 "STATE",
114 "WRITE_ONLY",
115 "ADDR"
116 };
117
118 static const char swz[] = "xyzw01??";
119
120 for (a=0; a<num; a++) {
121 _mesa_printf("%s", opcode_string[fp[a].Opcode]);
122
123 if (fp[a].Saturate)
124 _mesa_printf("_SAT");
125
126 if (fp[a].DstReg.File != 0xf) {
127 if (fp[a].DstReg.WriteMask != 0xf ||
128 fp[a].SrcReg[0].NegateBase)
129 _mesa_printf(" %s[%d].%s%s%s%s ", file_string[fp[a].DstReg.File], fp[a].DstReg.Index,
130 GET_BIT(fp[a].DstReg.WriteMask, 0) ? "x" : "",
131 GET_BIT(fp[a].DstReg.WriteMask, 1) ? "y" : "",
132 GET_BIT(fp[a].DstReg.WriteMask, 2) ? "z" : "",
133 GET_BIT(fp[a].DstReg.WriteMask, 3) ? "w" : "");
134 else
135 _mesa_printf(" %s[%d] ", file_string[fp[a].DstReg.File], fp[a].DstReg.Index);
136 }
137
138 if (fp[a].SrcReg[0].File != 0xf) {
139 if (fp[a].SrcReg[0].Swizzle != SWIZZLE_NOOP ||
140 fp[a].SrcReg[0].NegateBase)
141 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string[fp[a].SrcReg[0].File], fp[a].SrcReg[0].Index,
142 fp[a].SrcReg[0].NegateBase ? "-" : "",
143 swz[GET_SWZ(fp[a].SrcReg[0].Swizzle, 0)],
144 swz[GET_SWZ(fp[a].SrcReg[0].Swizzle, 1)],
145 swz[GET_SWZ(fp[a].SrcReg[0].Swizzle, 2)],
146 swz[GET_SWZ(fp[a].SrcReg[0].Swizzle, 3)]);
147 else
148 _mesa_printf("%s[%d] ", file_string[fp[a].SrcReg[0].File], fp[a].SrcReg[0].Index);
149 }
150
151 if (fp[a].SrcReg[1].File != 0xf) {
152 if (fp[a].SrcReg[1].Swizzle != SWIZZLE_NOOP ||
153 fp[a].SrcReg[1].NegateBase)
154 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string[fp[a].SrcReg[1].File], fp[a].SrcReg[1].Index,
155 fp[a].SrcReg[1].NegateBase ? "-" : "",
156 swz[GET_SWZ(fp[a].SrcReg[1].Swizzle, 0)],
157 swz[GET_SWZ(fp[a].SrcReg[1].Swizzle, 1)],
158 swz[GET_SWZ(fp[a].SrcReg[1].Swizzle, 2)],
159 swz[GET_SWZ(fp[a].SrcReg[1].Swizzle, 3)]);
160 else
161 _mesa_printf("%s[%d] ", file_string[fp[a].SrcReg[1].File], fp[a].SrcReg[1].Index);
162 }
163
164 if (fp[a].SrcReg[2].File != 0xf) {
165 if (fp[a].SrcReg[2].Swizzle != SWIZZLE_NOOP ||
166 fp[a].SrcReg[2].NegateBase)
167 _mesa_printf("%s[%d].%s%c%c%c%c ", file_string[fp[a].SrcReg[2].File], fp[a].SrcReg[2].Index,
168 fp[a].SrcReg[1].NegateBase ? "-" : "",
169 swz[GET_SWZ(fp[a].SrcReg[2].Swizzle, 0)],
170 swz[GET_SWZ(fp[a].SrcReg[2].Swizzle, 1)],
171 swz[GET_SWZ(fp[a].SrcReg[2].Swizzle, 2)],
172 swz[GET_SWZ(fp[a].SrcReg[2].Swizzle, 3)]);
173 else
174 _mesa_printf("%s[%d] ", file_string[fp[a].SrcReg[2].File], fp[a].SrcReg[2].Index);
175 }
176
177 _mesa_printf("\n");
178 }
179 }
180
181 void
182 _mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target,
183 const GLubyte * str, GLsizei len,
184 struct fragment_program *program)
185 {
186 GLuint a, retval;
187 struct arb_program ap;
188 (void) target;
189
190 /* set the program target before parsing */
191 ap.Base.Target = GL_FRAGMENT_PROGRAM_ARB;
192
193 retval = _mesa_parse_arb_program(ctx, str, len, &ap);
194
195 /* XXX: Parse error. Cleanup things and return */
196 if (retval)
197 {
198 program->Instructions = (struct fp_instruction *) _mesa_malloc (
199 sizeof(struct fp_instruction) );
200 program->Instructions[0].Opcode = FP_OPCODE_END;
201 return;
202 }
203
204 /* copy the relvant contents of the arb_program struct into the
205 * fragment_program struct
206 */
207 program->Base.String = ap.Base.String;
208 program->Base.NumInstructions = ap.Base.NumInstructions;
209 program->Base.NumTemporaries = ap.Base.NumTemporaries;
210 program->Base.NumParameters = ap.Base.NumParameters;
211 program->Base.NumAttributes = ap.Base.NumAttributes;
212 program->Base.NumAddressRegs = ap.Base.NumAddressRegs;
213
214 program->InputsRead = ap.InputsRead;
215 program->OutputsWritten = ap.OutputsWritten;
216 for (a=0; a<MAX_TEXTURE_IMAGE_UNITS; a++)
217 program->TexturesUsed[a] = ap.TexturesUsed[a];
218 program->NumAluInstructions = ap.NumAluInstructions;
219 program->NumTexInstructions = ap.NumTexInstructions;
220 program->NumTexIndirections = ap.NumTexIndirections;
221 program->Parameters = ap.Parameters;
222 program->FogOption = ap.FogOption;
223
224 #if DEBUG_FP
225 _mesa_debug_fp_inst(ap.Base.NumInstructions, ap.FPInstructions);
226 #endif
227
228 program->Instructions = ap.FPInstructions;
229 }