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 arbfragparse.c
29 * ARB_fragment_program parser.
39 #include "arbprogparse.h"
40 #include "arbfragparse.h"
43 _mesa_debug_fp_inst(GLint num
, struct fp_instruction
*fp
)
47 /* fprintf(stderr, "PROGRAM_OUTPUT: 0x%x\n", PROGRAM_OUTPUT); */
48 /* fprintf(stderr, "PROGRAM_INPUT: 0x%x\n", PROGRAM_INPUT); */
49 /* fprintf(stderr, "PROGRAM_TEMPORARY: 0x%x\n", PROGRAM_TEMPORARY); */
51 for (a
=0; a
<num
; a
++) {
52 switch (fp
[a
].Opcode
) {
54 fprintf(stderr
, "FP_OPCODE_END"); break;
57 fprintf(stderr
, "FP_OPCODE_ABS"); break;
60 fprintf(stderr
, "FP_OPCODE_ADD"); break;
63 fprintf(stderr
, "FP_OPCODE_CMP"); break;
66 fprintf(stderr
, "FP_OPCODE_COS"); break;
69 fprintf(stderr
, "FP_OPCODE_DP3"); break;
72 fprintf(stderr
, "FP_OPCODE_DP4"); break;
75 fprintf(stderr
, "FP_OPCODE_DPH"); break;
78 fprintf(stderr
, "FP_OPCODE_DST"); break;
81 fprintf(stderr
, "FP_OPCODE_EX2"); break;
84 fprintf(stderr
, "FP_OPCODE_FLR"); break;
87 fprintf(stderr
, "FP_OPCODE_FRC"); break;
90 fprintf(stderr
, "FP_OPCODE_KIL"); break;
93 fprintf(stderr
, "FP_OPCODE_LG2"); break;
96 fprintf(stderr
, "FP_OPCODE_LIT"); break;
99 fprintf(stderr
, "FP_OPCODE_LRP"); break;
102 fprintf(stderr
, "FP_OPCODE_MAD"); break;
105 fprintf(stderr
, "FP_OPCODE_MAX"); break;
108 fprintf(stderr
, "FP_OPCODE_MIN"); break;
111 fprintf(stderr
, "FP_OPCODE_MOV"); break;
114 fprintf(stderr
, "FP_OPCODE_MUL"); break;
117 fprintf(stderr
, "FP_OPCODE_POW"); break;
120 fprintf(stderr
, "FP_OPCODE_RCP"); break;
123 fprintf(stderr
, "FP_OPCODE_RSQ"); break;
126 fprintf(stderr
, "FP_OPCODE_SCS"); break;
129 fprintf(stderr
, "FP_OPCODE_SIN"); break;
132 fprintf(stderr
, "FP_OPCODE_SLT"); break;
135 fprintf(stderr
, "FP_OPCODE_SUB"); break;
138 fprintf(stderr
, "FP_OPCODE_SWZ"); break;
141 fprintf(stderr
, "FP_OPCODE_TEX"); break;
144 fprintf(stderr
, "FP_OPCODE_TXB"); break;
147 fprintf(stderr
, "FP_OPCODE_TXP"); break;
150 fprintf(stderr
, "FP_OPCODE_XPD"); break;
153 _mesa_warning(NULL
, "Bad opcode in debug_fg_inst()");
156 fprintf(stderr
, " D(0x%x:%d:%d%d%d%d) ",
157 fp
[a
].DstReg
.File
, fp
[a
].DstReg
.Index
,
158 GET_BIT(fp
[a
].DstReg
.WriteMask
, 0),
159 GET_BIT(fp
[a
].DstReg
.WriteMask
, 1),
160 GET_BIT(fp
[a
].DstReg
.WriteMask
, 2),
161 GET_BIT(fp
[a
].DstReg
.WriteMask
, 3));
163 fprintf(stderr
, "S1(0x%x:%d:%d%d%d%d) ", fp
[a
].SrcReg
[0].File
, fp
[a
].SrcReg
[0].Index
,
164 GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 0),
165 GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 1),
166 GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 2),
167 GET_SWZ(fp
[a
].SrcReg
[0].Swizzle
, 3));
169 fprintf(stderr
, "S2(0x%x:%d:%d%d%d%d) ", fp
[a
].SrcReg
[1].File
, fp
[a
].SrcReg
[1].Index
,
170 GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 0),
171 GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 1),
172 GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 2),
173 GET_SWZ(fp
[a
].SrcReg
[1].Swizzle
, 3));
175 fprintf(stderr
, "S3(0x%x:%d:%d%d%d%d)", fp
[a
].SrcReg
[2].File
, fp
[a
].SrcReg
[2].Index
,
176 GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 0),
177 GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 1),
178 GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 2),
179 GET_SWZ(fp
[a
].SrcReg
[2].Swizzle
, 3));
181 fprintf(stderr
, "\n");
186 _mesa_parse_arb_fragment_program(GLcontext
* ctx
, GLenum target
,
187 const GLubyte
* str
, GLsizei len
,
188 struct fragment_program
*program
)
191 struct arb_program ap
;
194 /* set the program target before parsing */
195 ap
.Base
.Target
= GL_FRAGMENT_PROGRAM_ARB
;
197 retval
= _mesa_parse_arb_program(ctx
, str
, len
, &ap
);
199 /* XXX: Parse error. Cleanup things and return */
202 program
->Instructions
= (struct fp_instruction
*) _mesa_malloc (
203 sizeof(struct fp_instruction
) );
204 program
->Instructions
[0].Opcode
= FP_OPCODE_END
;
208 /* copy the relvant contents of the arb_program struct into the
209 * fragment_program struct
211 program
->Base
.String
= ap
.Base
.String
;
212 program
->Base
.NumInstructions
= ap
.Base
.NumInstructions
;
213 program
->Base
.NumTemporaries
= ap
.Base
.NumTemporaries
;
214 program
->Base
.NumParameters
= ap
.Base
.NumParameters
;
215 program
->Base
.NumAttributes
= ap
.Base
.NumAttributes
;
216 program
->Base
.NumAddressRegs
= ap
.Base
.NumAddressRegs
;
218 program
->InputsRead
= ap
.InputsRead
;
219 program
->OutputsWritten
= ap
.OutputsWritten
;
220 for (a
=0; a
<MAX_TEXTURE_IMAGE_UNITS
; a
++)
221 program
->TexturesUsed
[a
] = ap
.TexturesUsed
[a
];
222 program
->NumAluInstructions
= ap
.NumAluInstructions
;
223 program
->NumTexInstructions
= ap
.NumTexInstructions
;
224 program
->NumTexIndirections
= ap
.NumTexIndirections
;
225 program
->Parameters
= ap
.Parameters
;
226 program
->FogOption
= ap
.FogOption
;
229 _mesa_debug_fp_inst(ap
.Base
.NumInstructions
, ap
.FPInstructions
);
232 program
->Instructions
= ap
.FPInstructions
;