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 "arbfragparse.h"
42 _mesa_debug_fp_inst(GLint num
, struct fp_instruction
*fp
)
46 fprintf(stderr
, "PROGRAM_OUTPUT: 0x%x\n", PROGRAM_OUTPUT
);
47 fprintf(stderr
, "PROGRAM_INPUT: 0x%x\n", PROGRAM_INPUT
);
48 fprintf(stderr
, "PROGRAM_TEMPORARY: 0x%x\n", PROGRAM_TEMPORARY
);
50 for (a
=0; a
<num
; a
++) {
51 switch (fp
[a
].Opcode
) {
53 fprintf(stderr
, "FP_OPCODE_END"); break;
56 fprintf(stderr
, "FP_OPCODE_ABS"); break;
59 fprintf(stderr
, "FP_OPCODE_ADD"); break;
62 fprintf(stderr
, "FP_OPCODE_CMP"); break;
65 fprintf(stderr
, "FP_OPCODE_COS"); break;
68 fprintf(stderr
, "FP_OPCODE_DP3"); break;
71 fprintf(stderr
, "FP_OPCODE_DP4"); break;
74 fprintf(stderr
, "FP_OPCODE_DPH"); break;
77 fprintf(stderr
, "FP_OPCODE_DST"); break;
80 fprintf(stderr
, "FP_OPCODE_EX2"); break;
83 fprintf(stderr
, "FP_OPCODE_FLR"); break;
86 fprintf(stderr
, "FP_OPCODE_FRC"); break;
89 fprintf(stderr
, "FP_OPCODE_KIL"); break;
92 fprintf(stderr
, "FP_OPCODE_LG2"); break;
95 fprintf(stderr
, "FP_OPCODE_LIT"); break;
98 fprintf(stderr
, "FP_OPCODE_LRP"); break;
101 fprintf(stderr
, "FP_OPCODE_MAD"); break;
104 fprintf(stderr
, "FP_OPCODE_MAX"); break;
107 fprintf(stderr
, "FP_OPCODE_MIN"); break;
110 fprintf(stderr
, "FP_OPCODE_MOV"); break;
113 fprintf(stderr
, "FP_OPCODE_MUL"); break;
116 fprintf(stderr
, "FP_OPCODE_POW"); break;
119 fprintf(stderr
, "FP_OPCODE_RCP"); break;
122 fprintf(stderr
, "FP_OPCODE_RSQ"); break;
125 fprintf(stderr
, "FP_OPCODE_SCS"); break;
128 fprintf(stderr
, "FP_OPCODE_SIN"); break;
131 fprintf(stderr
, "FP_OPCODE_SLT"); break;
134 fprintf(stderr
, "FP_OPCODE_SUB"); break;
137 fprintf(stderr
, "FP_OPCODE_SWZ"); break;
140 fprintf(stderr
, "FP_OPCODE_TEX"); break;
143 fprintf(stderr
, "FP_OPCODE_TXB"); break;
146 fprintf(stderr
, "FP_OPCODE_TXP"); break;
149 fprintf(stderr
, "FP_OPCODE_XPD"); break;
152 _mesa_warning(NULL
, "Bad opcode in debug_fg_inst()");
155 fprintf(stderr
, " D(0x%x:%d:%d%d%d%d) ",
156 fp
[a
].DstReg
.File
, fp
[a
].DstReg
.Index
,
157 fp
[a
].DstReg
.WriteMask
[0], fp
[a
].DstReg
.WriteMask
[1],
158 fp
[a
].DstReg
.WriteMask
[2], fp
[a
].DstReg
.WriteMask
[3]);
160 fprintf(stderr
, "S1(0x%x:%d:%d%d%d%d) ", fp
[a
].SrcReg
[0].File
, fp
[a
].SrcReg
[0].Index
,
161 fp
[a
].SrcReg
[0].Swizzle
[0],
162 fp
[a
].SrcReg
[0].Swizzle
[1],
163 fp
[a
].SrcReg
[0].Swizzle
[2],
164 fp
[a
].SrcReg
[0].Swizzle
[3]);
166 fprintf(stderr
, "S2(0x%x:%d:%d%d%d%d) ", fp
[a
].SrcReg
[1].File
, fp
[a
].SrcReg
[1].Index
,
167 fp
[a
].SrcReg
[1].Swizzle
[0],
168 fp
[a
].SrcReg
[1].Swizzle
[1],
169 fp
[a
].SrcReg
[1].Swizzle
[2],
170 fp
[a
].SrcReg
[1].Swizzle
[3]);
172 fprintf(stderr
, "S3(0x%x:%d:%d%d%d%d)", fp
[a
].SrcReg
[2].File
, fp
[a
].SrcReg
[2].Index
,
173 fp
[a
].SrcReg
[2].Swizzle
[0],
174 fp
[a
].SrcReg
[2].Swizzle
[1],
175 fp
[a
].SrcReg
[2].Swizzle
[2],
176 fp
[a
].SrcReg
[2].Swizzle
[3]);
178 fprintf(stderr
, "\n");
183 _mesa_parse_arb_fragment_program(GLcontext
* ctx
, GLenum target
,
184 const GLubyte
* str
, GLsizei len
,
185 struct fragment_program
*program
)
188 struct arb_program ap
;
190 retval
= _mesa_parse_arb_program(ctx
, str
, len
, &ap
);
192 /* copy the relvant contents of the arb_program struct into the
193 * fragment_program struct
195 program
->Base
.NumInstructions
= ap
.Base
.NumInstructions
;
196 program
->Base
.NumTemporaries
= ap
.Base
.NumTemporaries
;
197 program
->Base
.NumParameters
= ap
.Base
.NumParameters
;
198 program
->Base
.NumAttributes
= ap
.Base
.NumAttributes
;
199 program
->Base
.NumAddressRegs
= ap
.Base
.NumAddressRegs
;
201 program
->InputsRead
= ap
.InputsRead
;
202 program
->OutputsWritten
= ap
.OutputsWritten
;
203 for (a
=0; a
<MAX_TEXTURE_IMAGE_UNITS
; a
++)
204 program
->TexturesUsed
[a
] = ap
.TexturesUsed
[a
];
205 program
->NumAluInstructions
= ap
.NumAluInstructions
;
206 program
->NumTexInstructions
= ap
.NumTexInstructions
;
207 program
->NumTexIndirections
= ap
.NumTexIndirections
;
208 program
->Parameters
= ap
.Parameters
;
210 /* XXX: Parse error. Cleanup things and return */
213 program
->Instructions
= (struct fp_instruction
*) _mesa_malloc (
214 sizeof(struct fp_instruction
) );
215 program
->Instructions
[0].Opcode
= FP_OPCODE_END
;
219 /* XXX: Eh.. we parsed something that wasn't a fragment program. doh! */
220 if (ap
.Base
.Target
!= GL_FRAGMENT_PROGRAM_ARB
)
222 program
->Instructions
= (struct fp_instruction
*) _mesa_malloc (
223 sizeof(struct fp_instruction
) );
224 program
->Instructions
[0].Opcode
= FP_OPCODE_END
;
226 _mesa_error (ctx
, GL_INVALID_OPERATION
, "Parsed a non-fragment program as a fragment program");
231 _mesa_debug_fp_inst(ap
.Base
.NumInstructions
, ap
.FPInstructions
);
234 program
->Instructions
= ap
.FPInstructions
;