blob: 0443862020af92c28edc740e168c2c580476e3dc [file] [log] [blame]
Brian Paul8f442862003-08-06 19:22:37 +00001/*
2 * Mesa 3-D graphics library
Brian Paul193d2112004-02-12 21:57:29 +00003 * Version: 6.1
Brian Paul8f442862003-08-06 19:22:37 +00004 *
Brian Paul193d2112004-02-12 21:57:29 +00005 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
Brian Paul8f442862003-08-06 19:22:37 +00006 *
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
Karl Rasche1c27a1e2003-11-19 13:15:13 +000025#define DEBUG_FP 0
Brian Paul8f442862003-08-06 19:22:37 +000026
27/**
28 * \file arbfragparse.c
29 * ARB_fragment_program parser.
Karl Rasche1c27a1e2003-11-19 13:15:13 +000030 * \author Karl Rasche
Brian Paul8f442862003-08-06 19:22:37 +000031 */
32
33#include "glheader.h"
34#include "context.h"
35#include "imports.h"
36#include "macros.h"
37#include "mtypes.h"
Karl Rasche1c27a1e2003-11-19 13:15:13 +000038#include "arbparse.h"
Brian Paul8f442862003-08-06 19:22:37 +000039#include "arbfragparse.h"
40
Keith Whitwell3abf7462004-01-23 14:46:27 +000041void
42_mesa_debug_fp_inst(GLint num, struct fp_instruction *fp)
Karl Rasche1c27a1e2003-11-19 13:15:13 +000043{
44 GLint a;
45
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);
49
50 for (a=0; a<num; a++) {
51 switch (fp[a].Opcode) {
52 case FP_OPCODE_END:
53 fprintf(stderr, "FP_OPCODE_END"); break;
54
55 case FP_OPCODE_ABS:
56 fprintf(stderr, "FP_OPCODE_ABS"); break;
57
58 case FP_OPCODE_ADD:
59 fprintf(stderr, "FP_OPCODE_ADD"); break;
60
61 case FP_OPCODE_CMP:
62 fprintf(stderr, "FP_OPCODE_CMP"); break;
63
64 case FP_OPCODE_COS:
65 fprintf(stderr, "FP_OPCODE_COS"); break;
66
67 case FP_OPCODE_DP3:
68 fprintf(stderr, "FP_OPCODE_DP3"); break;
69
70 case FP_OPCODE_DP4:
71 fprintf(stderr, "FP_OPCODE_DP4"); break;
72
73 case FP_OPCODE_DPH:
74 fprintf(stderr, "FP_OPCODE_DPH"); break;
75
76 case FP_OPCODE_DST:
77 fprintf(stderr, "FP_OPCODE_DST"); break;
78
79 case FP_OPCODE_EX2:
80 fprintf(stderr, "FP_OPCODE_EX2"); break;
81
82 case FP_OPCODE_FLR:
83 fprintf(stderr, "FP_OPCODE_FLR"); break;
84
85 case FP_OPCODE_FRC:
86 fprintf(stderr, "FP_OPCODE_FRC"); break;
87
88 case FP_OPCODE_KIL:
89 fprintf(stderr, "FP_OPCODE_KIL"); break;
90
91 case FP_OPCODE_LG2:
92 fprintf(stderr, "FP_OPCODE_LG2"); break;
93
94 case FP_OPCODE_LIT:
95 fprintf(stderr, "FP_OPCODE_LIT"); break;
96
97 case FP_OPCODE_LRP:
98 fprintf(stderr, "FP_OPCODE_LRP"); break;
99
100 case FP_OPCODE_MAD:
101 fprintf(stderr, "FP_OPCODE_MAD"); break;
102
103 case FP_OPCODE_MAX:
104 fprintf(stderr, "FP_OPCODE_MAX"); break;
105
106 case FP_OPCODE_MIN:
107 fprintf(stderr, "FP_OPCODE_MIN"); break;
108
109 case FP_OPCODE_MOV:
110 fprintf(stderr, "FP_OPCODE_MOV"); break;
111
112 case FP_OPCODE_MUL:
113 fprintf(stderr, "FP_OPCODE_MUL"); break;
114
115 case FP_OPCODE_POW:
116 fprintf(stderr, "FP_OPCODE_POW"); break;
117
118 case FP_OPCODE_RCP:
119 fprintf(stderr, "FP_OPCODE_RCP"); break;
120
121 case FP_OPCODE_RSQ:
122 fprintf(stderr, "FP_OPCODE_RSQ"); break;
123
124 case FP_OPCODE_SCS:
125 fprintf(stderr, "FP_OPCODE_SCS"); break;
126
127 case FP_OPCODE_SIN:
128 fprintf(stderr, "FP_OPCODE_SIN"); break;
129
130 case FP_OPCODE_SLT:
131 fprintf(stderr, "FP_OPCODE_SLT"); break;
132
133 case FP_OPCODE_SUB:
134 fprintf(stderr, "FP_OPCODE_SUB"); break;
135
136 case FP_OPCODE_SWZ:
137 fprintf(stderr, "FP_OPCODE_SWZ"); break;
138
139 case FP_OPCODE_TEX:
140 fprintf(stderr, "FP_OPCODE_TEX"); break;
141
142 case FP_OPCODE_TXB:
143 fprintf(stderr, "FP_OPCODE_TXB"); break;
144
145 case FP_OPCODE_TXP:
146 fprintf(stderr, "FP_OPCODE_TXP"); break;
147
148 case FP_OPCODE_X2D:
149 fprintf(stderr, "FP_OPCODE_XPD"); break;
Brian Paulba254c02003-11-21 16:38:56 +0000150
151 default:
152 _mesa_warning(NULL, "Bad opcode in debug_fg_inst()");
Karl Rasche1c27a1e2003-11-19 13:15:13 +0000153 }
154
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]);
159
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]);
165
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]);
171
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]);
177
178 fprintf(stderr, "\n");
179 }
180}
Brian Paul8f442862003-08-06 19:22:37 +0000181
182void
183_mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target,
184 const GLubyte * str, GLsizei len,
185 struct fragment_program *program)
186{
Karl Rasche79e0dad2003-11-23 19:29:18 +0000187 GLuint a, retval;
Karl Rasche1c27a1e2003-11-19 13:15:13 +0000188 struct arb_program ap;
189
190 retval = _mesa_parse_arb_program(ctx, str, len, &ap);
Brian Paul8f442862003-08-06 19:22:37 +0000191
Karl Rasche1c27a1e2003-11-19 13:15:13 +0000192 /* copy the relvant contents of the arb_program struct into the
193 * fragment_program struct
194 */
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;
200
Karl Rasche1c27a1e2003-11-19 13:15:13 +0000201 program->InputsRead = ap.InputsRead;
202 program->OutputsWritten = ap.OutputsWritten;
Karl Rasche79e0dad2003-11-23 19:29:18 +0000203 for (a=0; a<MAX_TEXTURE_IMAGE_UNITS; a++)
204 program->TexturesUsed[a] = ap.TexturesUsed[a];
Karl Rasche1c27a1e2003-11-19 13:15:13 +0000205 program->NumAluInstructions = ap.NumAluInstructions;
206 program->NumTexInstructions = ap.NumTexInstructions;
207 program->NumTexIndirections = ap.NumTexIndirections;
208 program->Parameters = ap.Parameters;
Karl Rasche4eebfa12003-11-23 17:54:39 +0000209
210 /* XXX: Parse error. Cleanup things and return */
211 if (retval)
212 {
213 program->Instructions = (struct fp_instruction *) _mesa_malloc (
Brian Paul193d2112004-02-12 21:57:29 +0000214 sizeof(struct fp_instruction) );
Karl Rasche4eebfa12003-11-23 17:54:39 +0000215 program->Instructions[0].Opcode = FP_OPCODE_END;
216 return;
217 }
218
219 /* XXX: Eh.. we parsed something that wasn't a fragment program. doh! */
Brian Paul193d2112004-02-12 21:57:29 +0000220 if (ap.Base.Target != GL_FRAGMENT_PROGRAM_ARB)
Karl Rasche4eebfa12003-11-23 17:54:39 +0000221 {
222 program->Instructions = (struct fp_instruction *) _mesa_malloc (
Brian Paul193d2112004-02-12 21:57:29 +0000223 sizeof(struct fp_instruction) );
Karl Rasche4eebfa12003-11-23 17:54:39 +0000224 program->Instructions[0].Opcode = FP_OPCODE_END;
225
226 _mesa_error (ctx, GL_INVALID_OPERATION, "Parsed a non-fragment program as a fragment program");
Brian Paul193d2112004-02-12 21:57:29 +0000227 return;
Karl Rasche4eebfa12003-11-23 17:54:39 +0000228 }
229
230#if DEBUG_FP
Keith Whitwell3abf7462004-01-23 14:46:27 +0000231 _mesa_debug_fp_inst(ap.Base.NumInstructions, ap.FPInstructions);
Karl Rasche4eebfa12003-11-23 17:54:39 +0000232#endif
233
234 program->Instructions = ap.FPInstructions;
Brian Paul8f442862003-08-06 19:22:37 +0000235}