blob: 2747480834eb5f8bf9938b036963340a3435a66f [file] [log] [blame]
Brian00cdc0a2006-12-14 15:01:06 -07001/*
2 * Mesa 3-D graphics library
Brian Paulf4361542008-11-11 10:47:10 -07003 * Version: 7.3
Brian00cdc0a2006-12-14 15:01:06 -07004 *
Brian Paulf4361542008-11-11 10:47:10 -07005 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
Brian Pauld0038932009-01-22 10:34:43 -07006 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
Brian00cdc0a2006-12-14 15:01:06 -07007 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26/**
27 * \file prog_print.c
28 * Print vertex/fragment programs - for debugging.
29 * \author Brian Paul
30 */
31
Brian Paulbbd28712008-09-18 12:26:54 -060032#include "main/glheader.h"
33#include "main/context.h"
34#include "main/imports.h"
Brian00cdc0a2006-12-14 15:01:06 -070035#include "prog_instruction.h"
36#include "prog_parameter.h"
37#include "prog_print.h"
38#include "prog_statevars.h"
39
40
Brian501ee872007-02-17 09:15:00 -070041
Brian00cdc0a2006-12-14 15:01:06 -070042/**
43 * Return string name for given program/register file.
44 */
45static const char *
Brian501ee872007-02-17 09:15:00 -070046file_string(enum register_file f, gl_prog_print_mode mode)
Brian00cdc0a2006-12-14 15:01:06 -070047{
48 switch (f) {
49 case PROGRAM_TEMPORARY:
50 return "TEMP";
51 case PROGRAM_LOCAL_PARAM:
52 return "LOCAL";
53 case PROGRAM_ENV_PARAM:
54 return "ENV";
55 case PROGRAM_STATE_VAR:
56 return "STATE";
57 case PROGRAM_INPUT:
58 return "INPUT";
59 case PROGRAM_OUTPUT:
60 return "OUTPUT";
61 case PROGRAM_NAMED_PARAM:
62 return "NAMED";
63 case PROGRAM_CONSTANT:
64 return "CONST";
65 case PROGRAM_UNIFORM:
66 return "UNIFORM";
67 case PROGRAM_VARYING:
68 return "VARYING";
69 case PROGRAM_WRITE_ONLY:
70 return "WRITE_ONLY";
71 case PROGRAM_ADDRESS:
72 return "ADDR";
Brianb2ab6932007-01-05 16:01:43 -070073 case PROGRAM_SAMPLER:
74 return "SAMPLER";
Brian Paulbc7d2c42009-01-07 18:44:41 -070075 case PROGRAM_UNDEFINED:
76 return "UNDEFINED";
Brian00cdc0a2006-12-14 15:01:06 -070077 default:
78 return "Unknown program file!";
79 }
80}
81
82
83/**
Brian501ee872007-02-17 09:15:00 -070084 * Return ARB_v/f_prog-style input attrib string.
85 */
86static const char *
87arb_input_attrib_string(GLint index, GLenum progType)
88{
Brian Paula0709372009-02-27 13:44:42 -070089 /*
90 * These strings should match the VERT_ATTRIB_x and FRAG_ATTRIB_x tokens.
91 */
Brian501ee872007-02-17 09:15:00 -070092 const char *vertAttribs[] = {
93 "vertex.position",
94 "vertex.weight",
95 "vertex.normal",
96 "vertex.color.primary",
97 "vertex.color.secondary",
98 "vertex.fogcoord",
99 "vertex.(six)",
100 "vertex.(seven)",
101 "vertex.texcoord[0]",
102 "vertex.texcoord[1]",
103 "vertex.texcoord[2]",
104 "vertex.texcoord[3]",
105 "vertex.texcoord[4]",
106 "vertex.texcoord[5]",
107 "vertex.texcoord[6]",
Markus Amslerd7878502008-03-17 12:11:11 +0100108 "vertex.texcoord[7]",
109 "vertex.attrib[0]",
110 "vertex.attrib[1]",
111 "vertex.attrib[2]",
112 "vertex.attrib[3]",
113 "vertex.attrib[4]",
114 "vertex.attrib[5]",
115 "vertex.attrib[6]",
116 "vertex.attrib[7]",
117 "vertex.attrib[8]",
118 "vertex.attrib[9]",
119 "vertex.attrib[10]",
120 "vertex.attrib[11]",
121 "vertex.attrib[12]",
122 "vertex.attrib[13]",
123 "vertex.attrib[14]",
124 "vertex.attrib[15]"
Brian501ee872007-02-17 09:15:00 -0700125 };
126 const char *fragAttribs[] = {
127 "fragment.position",
128 "fragment.color.primary",
129 "fragment.color.secondary",
130 "fragment.fogcoord",
131 "fragment.texcoord[0]",
132 "fragment.texcoord[1]",
133 "fragment.texcoord[2]",
134 "fragment.texcoord[3]",
135 "fragment.texcoord[4]",
136 "fragment.texcoord[5]",
137 "fragment.texcoord[6]",
138 "fragment.texcoord[7]",
139 "fragment.varying[0]",
140 "fragment.varying[1]",
141 "fragment.varying[2]",
142 "fragment.varying[3]",
143 "fragment.varying[4]",
144 "fragment.varying[5]",
145 "fragment.varying[6]",
146 "fragment.varying[7]"
147 };
148
149 if (progType == GL_VERTEX_PROGRAM_ARB) {
150 assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0]));
151 return vertAttribs[index];
152 }
153 else {
154 assert(index < sizeof(fragAttribs) / sizeof(fragAttribs[0]));
155 return fragAttribs[index];
156 }
157}
158
159
160/**
161 * Return ARB_v/f_prog-style output attrib string.
162 */
163static const char *
164arb_output_attrib_string(GLint index, GLenum progType)
165{
Brian Paula0709372009-02-27 13:44:42 -0700166 /*
167 * These strings should match the VERT_RESULT_x and FRAG_RESULT_x tokens.
168 */
Brian501ee872007-02-17 09:15:00 -0700169 const char *vertResults[] = {
170 "result.position",
171 "result.color.primary",
172 "result.color.secondary",
173 "result.fogcoord",
174 "result.texcoord[0]",
175 "result.texcoord[1]",
176 "result.texcoord[2]",
177 "result.texcoord[3]",
178 "result.texcoord[4]",
179 "result.texcoord[5]",
180 "result.texcoord[6]",
181 "result.texcoord[7]",
182 "result.varying[0]",
183 "result.varying[1]",
184 "result.varying[2]",
185 "result.varying[3]",
186 "result.varying[4]",
187 "result.varying[5]",
188 "result.varying[6]",
189 "result.varying[7]"
190 };
191 const char *fragResults[] = {
192 "result.color",
Brian Paula0709372009-02-27 13:44:42 -0700193 "result.color(half)",
194 "result.depth",
195 "result.color[0]",
196 "result.color[1]",
197 "result.color[2]",
198 "result.color[3]"
Brian501ee872007-02-17 09:15:00 -0700199 };
200
201 if (progType == GL_VERTEX_PROGRAM_ARB) {
202 assert(index < sizeof(vertResults) / sizeof(vertResults[0]));
203 return vertResults[index];
204 }
205 else {
206 assert(index < sizeof(fragResults) / sizeof(fragResults[0]));
207 return fragResults[index];
208 }
209}
210
211
212/**
213 * Return string representation of the given register.
214 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
215 * by the ARB/NV program languages so we've taken some liberties here.
216 * \param file the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
217 * \param index number of the register in the register file
218 * \param mode the output format/mode/style
219 * \param prog pointer to containing program
220 */
221static const char *
222reg_string(enum register_file f, GLint index, gl_prog_print_mode mode,
Zack Rusin19659a52008-06-12 14:19:10 -0400223 GLboolean relAddr, const struct gl_program *prog)
Brian501ee872007-02-17 09:15:00 -0700224{
225 static char str[100];
Brian Paulf88a9012009-02-17 15:57:00 -0700226 const char *addr = relAddr ? "ADDR+" : "";
Brian501ee872007-02-17 09:15:00 -0700227
228 str[0] = 0;
229
230 switch (mode) {
231 case PROG_PRINT_DEBUG:
Brian Paulf88a9012009-02-17 15:57:00 -0700232 _mesa_sprintf(str, "%s[%s%d]", file_string(f, mode), addr, index);
Brian501ee872007-02-17 09:15:00 -0700233 break;
234
235 case PROG_PRINT_ARB:
236 switch (f) {
237 case PROGRAM_INPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000238 _mesa_sprintf(str, "%s", arb_input_attrib_string(index, prog->Target));
Brian501ee872007-02-17 09:15:00 -0700239 break;
240 case PROGRAM_OUTPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000241 _mesa_sprintf(str, "%s", arb_output_attrib_string(index, prog->Target));
Brian501ee872007-02-17 09:15:00 -0700242 break;
243 case PROGRAM_TEMPORARY:
José Fonseca98a053c2009-02-11 13:52:11 +0000244 _mesa_sprintf(str, "temp%d", index);
Brian501ee872007-02-17 09:15:00 -0700245 break;
246 case PROGRAM_ENV_PARAM:
Brian Paulf88a9012009-02-17 15:57:00 -0700247 _mesa_sprintf(str, "program.env[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700248 break;
249 case PROGRAM_LOCAL_PARAM:
Brian Paulf88a9012009-02-17 15:57:00 -0700250 _mesa_sprintf(str, "program.local[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700251 break;
252 case PROGRAM_VARYING: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700253 _mesa_sprintf(str, "varying[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700254 break;
255 case PROGRAM_CONSTANT: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700256 _mesa_sprintf(str, "constant[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700257 break;
258 case PROGRAM_UNIFORM: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700259 _mesa_sprintf(str, "uniform[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700260 break;
261 case PROGRAM_STATE_VAR:
262 {
263 struct gl_program_parameter *param
264 = prog->Parameters->Parameters + index;
Brian Paul9a644402008-09-04 15:05:03 -0600265 char *state = _mesa_program_state_string(param->StateIndexes);
José Fonseca98a053c2009-02-11 13:52:11 +0000266 _mesa_sprintf(str, state);
Brian Paul9a644402008-09-04 15:05:03 -0600267 _mesa_free(state);
Brian501ee872007-02-17 09:15:00 -0700268 }
269 break;
270 case PROGRAM_ADDRESS:
José Fonseca98a053c2009-02-11 13:52:11 +0000271 _mesa_sprintf(str, "A%d", index);
Brian501ee872007-02-17 09:15:00 -0700272 break;
273 default:
274 _mesa_problem(NULL, "bad file in reg_string()");
275 }
276 break;
277
278 case PROG_PRINT_NV:
279 switch (f) {
280 case PROGRAM_INPUT:
281 if (prog->Target == GL_VERTEX_PROGRAM_ARB)
José Fonseca98a053c2009-02-11 13:52:11 +0000282 _mesa_sprintf(str, "v[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700283 else
José Fonseca98a053c2009-02-11 13:52:11 +0000284 _mesa_sprintf(str, "f[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700285 break;
286 case PROGRAM_OUTPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000287 _mesa_sprintf(str, "o[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700288 break;
289 case PROGRAM_TEMPORARY:
José Fonseca98a053c2009-02-11 13:52:11 +0000290 _mesa_sprintf(str, "R%d", index);
Brian501ee872007-02-17 09:15:00 -0700291 break;
292 case PROGRAM_ENV_PARAM:
José Fonseca98a053c2009-02-11 13:52:11 +0000293 _mesa_sprintf(str, "c[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700294 break;
295 case PROGRAM_VARYING: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700296 _mesa_sprintf(str, "varying[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700297 break;
298 case PROGRAM_UNIFORM: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700299 _mesa_sprintf(str, "uniform[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700300 break;
301 case PROGRAM_CONSTANT: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700302 _mesa_sprintf(str, "constant[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700303 break;
304 case PROGRAM_STATE_VAR: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700305 _mesa_sprintf(str, "state[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700306 break;
307 default:
308 _mesa_problem(NULL, "bad file in reg_string()");
309 }
310 break;
311
312 default:
313 _mesa_problem(NULL, "bad mode in reg_string()");
314 }
315
316 return str;
317}
318
319
320/**
Brian00cdc0a2006-12-14 15:01:06 -0700321 * Return a string representation of the given swizzle word.
322 * If extended is true, use extended (comma-separated) format.
Brian3a281532006-12-16 12:51:34 -0700323 * \param swizzle the swizzle field
324 * \param negateBase 4-bit negation vector
325 * \param extended if true, also allow 0, 1 values
Brian00cdc0a2006-12-14 15:01:06 -0700326 */
Brian059376c2007-02-22 17:45:32 -0700327const char *
328_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended)
Brian00cdc0a2006-12-14 15:01:06 -0700329{
Brian Paul74a19b02008-07-18 19:46:19 -0600330 static const char swz[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
Brian00cdc0a2006-12-14 15:01:06 -0700331 static char s[20];
332 GLuint i = 0;
333
334 if (!extended && swizzle == SWIZZLE_NOOP && negateBase == 0)
335 return ""; /* no swizzle/negation */
336
337 if (!extended)
338 s[i++] = '.';
339
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600340 if (negateBase & NEGATE_X)
Brian00cdc0a2006-12-14 15:01:06 -0700341 s[i++] = '-';
342 s[i++] = swz[GET_SWZ(swizzle, 0)];
343
344 if (extended) {
345 s[i++] = ',';
346 }
347
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600348 if (negateBase & NEGATE_Y)
Brian00cdc0a2006-12-14 15:01:06 -0700349 s[i++] = '-';
350 s[i++] = swz[GET_SWZ(swizzle, 1)];
351
352 if (extended) {
353 s[i++] = ',';
354 }
355
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600356 if (negateBase & NEGATE_Z)
Brian00cdc0a2006-12-14 15:01:06 -0700357 s[i++] = '-';
358 s[i++] = swz[GET_SWZ(swizzle, 2)];
359
360 if (extended) {
361 s[i++] = ',';
362 }
363
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600364 if (negateBase & NEGATE_W)
Brian00cdc0a2006-12-14 15:01:06 -0700365 s[i++] = '-';
366 s[i++] = swz[GET_SWZ(swizzle, 3)];
367
368 s[i] = 0;
369 return s;
370}
371
372
Brian Paul511733b2008-07-02 12:40:03 -0600373void
374_mesa_print_swizzle(GLuint swizzle)
375{
376 if (swizzle == SWIZZLE_XYZW) {
377 _mesa_printf(".xyzw\n");
378 }
379 else {
Michal Krolf9c574d2008-07-15 11:44:47 +0200380 const char *s = _mesa_swizzle_string(swizzle, 0, 0);
Brian Paul511733b2008-07-02 12:40:03 -0600381 _mesa_printf("%s\n", s);
382 }
383}
384
385
Brian Paul610c2462008-11-13 16:37:52 -0700386const char *
387_mesa_writemask_string(GLuint writeMask)
Brian00cdc0a2006-12-14 15:01:06 -0700388{
389 static char s[10];
390 GLuint i = 0;
391
392 if (writeMask == WRITEMASK_XYZW)
393 return "";
394
395 s[i++] = '.';
396 if (writeMask & WRITEMASK_X)
397 s[i++] = 'x';
398 if (writeMask & WRITEMASK_Y)
399 s[i++] = 'y';
400 if (writeMask & WRITEMASK_Z)
401 s[i++] = 'z';
402 if (writeMask & WRITEMASK_W)
403 s[i++] = 'w';
404
405 s[i] = 0;
406 return s;
407}
408
Brian3a281532006-12-16 12:51:34 -0700409
Briand7508612007-03-28 11:01:09 -0600410const char *
411_mesa_condcode_string(GLuint condcode)
Brian3a281532006-12-16 12:51:34 -0700412{
413 switch (condcode) {
414 case COND_GT: return "GT";
415 case COND_EQ: return "EQ";
416 case COND_LT: return "LT";
417 case COND_UN: return "UN";
418 case COND_GE: return "GE";
419 case COND_LE: return "LE";
420 case COND_NE: return "NE";
421 case COND_TR: return "TR";
422 case COND_FL: return "FL";
423 default: return "cond???";
424 }
425}
426
427
Brian00cdc0a2006-12-14 15:01:06 -0700428static void
Brian Pauld0038932009-01-22 10:34:43 -0700429fprint_dst_reg(FILE * f,
430 const struct prog_dst_register *dstReg,
431 gl_prog_print_mode mode,
432 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700433{
Brian Pauld0038932009-01-22 10:34:43 -0700434 _mesa_fprintf(f, "%s%s",
435 reg_string((enum register_file) dstReg->File,
436 dstReg->Index, mode, dstReg->RelAddr, prog),
437 _mesa_writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700438
Brian1936b252007-03-22 09:04:18 -0600439 if (dstReg->CondMask != COND_TR) {
Brian Pauld0038932009-01-22 10:34:43 -0700440 _mesa_fprintf(f, " (%s.%s)",
441 _mesa_condcode_string(dstReg->CondMask),
442 _mesa_swizzle_string(dstReg->CondSwizzle,
443 GL_FALSE, GL_FALSE));
Brian1936b252007-03-22 09:04:18 -0600444 }
445
Brian501ee872007-02-17 09:15:00 -0700446#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700447 _mesa_fprintf(f, "%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700448 file_string((enum register_file) dstReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700449 dstReg->Index,
Brian Paul610c2462008-11-13 16:37:52 -0700450 _mesa_writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700451#endif
Brian00cdc0a2006-12-14 15:01:06 -0700452}
453
Brian Pauld0038932009-01-22 10:34:43 -0700454
Brian00cdc0a2006-12-14 15:01:06 -0700455static void
Brian Pauld0038932009-01-22 10:34:43 -0700456fprint_src_reg(FILE *f,
457 const struct prog_src_register *srcReg,
458 gl_prog_print_mode mode,
459 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700460{
Brian Pauld0038932009-01-22 10:34:43 -0700461 _mesa_fprintf(f, "%s%s",
462 reg_string((enum register_file) srcReg->File,
463 srcReg->Index, mode, srcReg->RelAddr, prog),
464 _mesa_swizzle_string(srcReg->Swizzle,
465 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700466#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700467 _mesa_fprintf(f, "%s[%d]%s",
468 file_string((enum register_file) srcReg->File, mode),
469 srcReg->Index,
470 _mesa_swizzle_string(srcReg->Swizzle,
471 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700472#endif
Brian00cdc0a2006-12-14 15:01:06 -0700473}
474
Brian Pauld0038932009-01-22 10:34:43 -0700475
Brian00cdc0a2006-12-14 15:01:06 -0700476static void
Brian Pauld0038932009-01-22 10:34:43 -0700477fprint_comment(FILE *f, const struct prog_instruction *inst)
Brian00cdc0a2006-12-14 15:01:06 -0700478{
479 if (inst->Comment)
Brian Pauld0038932009-01-22 10:34:43 -0700480 _mesa_fprintf(f, "; # %s\n", inst->Comment);
Brian00cdc0a2006-12-14 15:01:06 -0700481 else
Brian Pauld0038932009-01-22 10:34:43 -0700482 _mesa_fprintf(f, ";\n");
Brian00cdc0a2006-12-14 15:01:06 -0700483}
484
485
Brian501ee872007-02-17 09:15:00 -0700486static void
Brian Pauld0038932009-01-22 10:34:43 -0700487fprint_alu_instruction(FILE *f,
488 const struct prog_instruction *inst,
489 const char *opcode_string, GLuint numRegs,
490 gl_prog_print_mode mode,
491 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700492{
493 GLuint j;
494
Brian Pauld0038932009-01-22 10:34:43 -0700495 _mesa_fprintf(f, "%s", opcode_string);
Brianb50280e2006-12-18 16:21:58 -0700496 if (inst->CondUpdate)
Brian Pauld0038932009-01-22 10:34:43 -0700497 _mesa_fprintf(f, ".C");
Brian00cdc0a2006-12-14 15:01:06 -0700498
499 /* frag prog only */
500 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700501 _mesa_fprintf(f, "_SAT");
Brian00cdc0a2006-12-14 15:01:06 -0700502
Brian Pauld0038932009-01-22 10:34:43 -0700503 _mesa_fprintf(f, " ");
Brian00cdc0a2006-12-14 15:01:06 -0700504 if (inst->DstReg.File != PROGRAM_UNDEFINED) {
Brian Pauld0038932009-01-22 10:34:43 -0700505 fprint_dst_reg(f, &inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700506 }
507 else {
Brian Pauld0038932009-01-22 10:34:43 -0700508 _mesa_fprintf(f, " ???");
Brian00cdc0a2006-12-14 15:01:06 -0700509 }
510
511 if (numRegs > 0)
Brian Pauld0038932009-01-22 10:34:43 -0700512 _mesa_fprintf(f, ", ");
Brian00cdc0a2006-12-14 15:01:06 -0700513
514 for (j = 0; j < numRegs; j++) {
Brian Pauld0038932009-01-22 10:34:43 -0700515 fprint_src_reg(f, inst->SrcReg + j, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700516 if (j + 1 < numRegs)
Brian Pauld0038932009-01-22 10:34:43 -0700517 _mesa_fprintf(f, ", ");
Brian00cdc0a2006-12-14 15:01:06 -0700518 }
519
Brian Pauld0038932009-01-22 10:34:43 -0700520 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700521}
522
523
Brian501ee872007-02-17 09:15:00 -0700524void
Brian0020d102007-02-23 11:43:44 -0700525_mesa_print_alu_instruction(const struct prog_instruction *inst,
526 const char *opcode_string, GLuint numRegs)
527{
Brian Pauld0038932009-01-22 10:34:43 -0700528 fprint_alu_instruction(stdout, inst, opcode_string,
529 numRegs, PROG_PRINT_DEBUG, NULL);
Brian501ee872007-02-17 09:15:00 -0700530}
531
532
Brian00cdc0a2006-12-14 15:01:06 -0700533/**
534 * Print a single vertex/fragment program instruction.
535 */
Brian Pauld0038932009-01-22 10:34:43 -0700536static GLint
537_mesa_fprint_instruction_opt(FILE *f,
538 const struct prog_instruction *inst,
539 GLint indent,
Brian501ee872007-02-17 09:15:00 -0700540 gl_prog_print_mode mode,
541 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700542{
Brian7b300532007-02-22 09:08:36 -0700543 GLint i;
Brian5db088d2007-02-05 14:58:15 -0700544
545 if (inst->Opcode == OPCODE_ELSE ||
546 inst->Opcode == OPCODE_ENDIF ||
547 inst->Opcode == OPCODE_ENDLOOP ||
548 inst->Opcode == OPCODE_ENDSUB) {
549 indent -= 3;
550 }
Brian5db088d2007-02-05 14:58:15 -0700551 for (i = 0; i < indent; i++) {
Brian Pauld0038932009-01-22 10:34:43 -0700552 _mesa_fprintf(f, " ");
Brian5db088d2007-02-05 14:58:15 -0700553 }
554
Brian00cdc0a2006-12-14 15:01:06 -0700555 switch (inst->Opcode) {
556 case OPCODE_PRINT:
Brian Pauld0038932009-01-22 10:34:43 -0700557 _mesa_fprintf(f, "PRINT '%s'", inst->Data);
Brian00cdc0a2006-12-14 15:01:06 -0700558 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
Brian Pauld0038932009-01-22 10:34:43 -0700559 _mesa_fprintf(f, ", ");
560 _mesa_fprintf(f, "%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700561 file_string((enum register_file) inst->SrcReg[0].File,
562 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700563 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700564 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
565 inst->SrcReg[0].NegateBase, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700566 }
567 if (inst->Comment)
Brian Pauld0038932009-01-22 10:34:43 -0700568 _mesa_fprintf(f, " # %s", inst->Comment);
569 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700570 break;
571 case OPCODE_SWZ:
Brian Pauld0038932009-01-22 10:34:43 -0700572 _mesa_fprintf(f, "SWZ");
Brian00cdc0a2006-12-14 15:01:06 -0700573 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700574 _mesa_fprintf(f, "_SAT");
575 _mesa_fprintf(f, " ");
576 fprint_dst_reg(f, &inst->DstReg, mode, prog);
577 _mesa_fprintf(f, ", %s[%d], %s",
Brian501ee872007-02-17 09:15:00 -0700578 file_string((enum register_file) inst->SrcReg[0].File,
579 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700580 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700581 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
582 inst->SrcReg[0].NegateBase, GL_TRUE));
Brian Pauld0038932009-01-22 10:34:43 -0700583 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700584 break;
585 case OPCODE_TEX:
586 case OPCODE_TXP:
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600587 case OPCODE_TXL:
Brian00cdc0a2006-12-14 15:01:06 -0700588 case OPCODE_TXB:
Brian Pauld0038932009-01-22 10:34:43 -0700589 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
Brian00cdc0a2006-12-14 15:01:06 -0700590 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700591 _mesa_fprintf(f, "_SAT");
592 _mesa_fprintf(f, " ");
593 fprint_dst_reg(f, &inst->DstReg, mode, prog);
594 _mesa_fprintf(f, ", ");
595 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
596 _mesa_fprintf(f, ", texture[%d], ", inst->TexSrcUnit);
Brian00cdc0a2006-12-14 15:01:06 -0700597 switch (inst->TexSrcTarget) {
Brian Pauld0038932009-01-22 10:34:43 -0700598 case TEXTURE_1D_INDEX: _mesa_fprintf(f, "1D"); break;
599 case TEXTURE_2D_INDEX: _mesa_fprintf(f, "2D"); break;
600 case TEXTURE_3D_INDEX: _mesa_fprintf(f, "3D"); break;
601 case TEXTURE_CUBE_INDEX: _mesa_fprintf(f, "CUBE"); break;
602 case TEXTURE_RECT_INDEX: _mesa_fprintf(f, "RECT"); break;
Brian00cdc0a2006-12-14 15:01:06 -0700603 default:
604 ;
605 }
Brian Paul44e018c2009-02-20 13:42:08 -0700606 if (inst->TexShadow)
607 _mesa_fprintf(f, " SHADOW");
Brian Pauld0038932009-01-22 10:34:43 -0700608 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700609 break;
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600610
611 case OPCODE_KIL:
Brian Pauld0038932009-01-22 10:34:43 -0700612 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
613 _mesa_fprintf(f, " ");
614 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
615 fprint_comment(f, inst);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600616 break;
617 case OPCODE_KIL_NV:
Brian Pauld0038932009-01-22 10:34:43 -0700618 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
619 _mesa_fprintf(f, " ");
620 _mesa_fprintf(f, "%s.%s",
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600621 _mesa_condcode_string(inst->DstReg.CondMask),
622 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
623 GL_FALSE, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700624 fprint_comment(f, inst);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600625 break;
626
Brian00cdc0a2006-12-14 15:01:06 -0700627 case OPCODE_ARL:
Brian Pauld0038932009-01-22 10:34:43 -0700628 _mesa_fprintf(f, "ARL ");
629 fprint_dst_reg(f, &inst->DstReg, mode, prog);
630 _mesa_fprintf(f, ", ");
631 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
632 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700633 break;
634 case OPCODE_BRA:
Brian Pauld0038932009-01-22 10:34:43 -0700635 _mesa_fprintf(f, "BRA %d (%s%s)",
Brian3a281532006-12-16 12:51:34 -0700636 inst->BranchTarget,
Briand7508612007-03-28 11:01:09 -0600637 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700638 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700639 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700640 break;
Brian5ae49cf2007-01-20 09:27:40 -0700641 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600642 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
643 /* Use ordinary register */
Brian Pauld0038932009-01-22 10:34:43 -0700644 _mesa_fprintf(f, "IF ");
645 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
646 _mesa_fprintf(f, "; ");
Brian63556fa2007-03-23 14:47:46 -0600647 }
648 else {
649 /* Use cond codes */
Brian Pauld0038932009-01-22 10:34:43 -0700650 _mesa_fprintf(f, "IF (%s%s);",
Briand7508612007-03-28 11:01:09 -0600651 _mesa_condcode_string(inst->DstReg.CondMask),
Brian63556fa2007-03-23 14:47:46 -0600652 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
653 0, GL_FALSE));
654 }
Brian Pauld0038932009-01-22 10:34:43 -0700655 _mesa_fprintf(f, " # (if false, goto %d)", inst->BranchTarget);
656 fprint_comment(f, inst);
Brian5db088d2007-02-05 14:58:15 -0700657 return indent + 3;
658 case OPCODE_ELSE:
Brian Pauld0038932009-01-22 10:34:43 -0700659 _mesa_fprintf(f, "ELSE; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700660 return indent + 3;
661 case OPCODE_ENDIF:
Brian Pauld0038932009-01-22 10:34:43 -0700662 _mesa_fprintf(f, "ENDIF;\n");
Brian5db088d2007-02-05 14:58:15 -0700663 break;
664 case OPCODE_BGNLOOP:
Brian Pauld0038932009-01-22 10:34:43 -0700665 _mesa_fprintf(f, "BGNLOOP; # (end at %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700666 return indent + 3;
667 case OPCODE_ENDLOOP:
Brian Pauld0038932009-01-22 10:34:43 -0700668 _mesa_fprintf(f, "ENDLOOP; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700669 break;
670 case OPCODE_BRK:
Brianf22ed092007-02-06 22:31:19 -0700671 case OPCODE_CONT:
Brian Pauld0038932009-01-22 10:34:43 -0700672 _mesa_fprintf(f, "%s (%s%s); # (goto %d)",
Brian81767ee2007-03-23 17:45:53 -0600673 _mesa_opcode_string(inst->Opcode),
Briand7508612007-03-28 11:01:09 -0600674 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700675 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
Brian2755c792007-02-05 18:01:02 -0700676 inst->BranchTarget);
Brian Pauld0038932009-01-22 10:34:43 -0700677 fprint_comment(f, inst);
Brian5ae49cf2007-01-20 09:27:40 -0700678 break;
Brian63556fa2007-03-23 14:47:46 -0600679
Brian5db088d2007-02-05 14:58:15 -0700680 case OPCODE_BGNSUB:
Brianf407cad2007-03-27 14:53:17 -0600681 if (mode == PROG_PRINT_NV) {
Brian Pauld0038932009-01-22 10:34:43 -0700682 _mesa_fprintf(f, "%s:\n", inst->Comment); /* comment is label */
Brianf407cad2007-03-27 14:53:17 -0600683 return indent;
684 }
685 else {
Brian Pauld0038932009-01-22 10:34:43 -0700686 _mesa_fprintf(f, "BGNSUB");
687 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600688 return indent + 3;
689 }
Brian5db088d2007-02-05 14:58:15 -0700690 case OPCODE_ENDSUB:
Brianf407cad2007-03-27 14:53:17 -0600691 if (mode == PROG_PRINT_DEBUG) {
Brian Pauld0038932009-01-22 10:34:43 -0700692 _mesa_fprintf(f, "ENDSUB");
693 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600694 }
695 break;
696 case OPCODE_CAL:
697 if (mode == PROG_PRINT_NV) {
Brian Pauld0038932009-01-22 10:34:43 -0700698 _mesa_fprintf(f, "CAL %s; # (goto %d)\n", inst->Comment, inst->BranchTarget);
Brianf407cad2007-03-27 14:53:17 -0600699 }
700 else {
Brian Pauld0038932009-01-22 10:34:43 -0700701 _mesa_fprintf(f, "CAL %u", inst->BranchTarget);
702 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600703 }
704 break;
705 case OPCODE_RET:
Brian Pauld0038932009-01-22 10:34:43 -0700706 _mesa_fprintf(f, "RET (%s%s)",
Briand7508612007-03-28 11:01:09 -0600707 _mesa_condcode_string(inst->DstReg.CondMask),
708 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700709 fprint_comment(f, inst);
Brian5ae49cf2007-01-20 09:27:40 -0700710 break;
Brianf407cad2007-03-27 14:53:17 -0600711
Brian00cdc0a2006-12-14 15:01:06 -0700712 case OPCODE_END:
Brian Pauld0038932009-01-22 10:34:43 -0700713 _mesa_fprintf(f, "END\n");
Brian00cdc0a2006-12-14 15:01:06 -0700714 break;
Brian3a281532006-12-16 12:51:34 -0700715 case OPCODE_NOP:
Brian059376c2007-02-22 17:45:32 -0700716 if (mode == PROG_PRINT_DEBUG) {
Brian Pauld0038932009-01-22 10:34:43 -0700717 _mesa_fprintf(f, "NOP");
718 fprint_comment(f, inst);
Brian059376c2007-02-22 17:45:32 -0700719 }
720 else if (inst->Comment) {
721 /* ARB/NV extensions don't have NOP instruction */
Brian Pauld0038932009-01-22 10:34:43 -0700722 _mesa_fprintf(f, "# %s\n", inst->Comment);
Brian059376c2007-02-22 17:45:32 -0700723 }
Brian3a281532006-12-16 12:51:34 -0700724 break;
Brian00cdc0a2006-12-14 15:01:06 -0700725 /* XXX may need other special-case instructions */
726 default:
727 /* typical alu instruction */
Brian Pauld0038932009-01-22 10:34:43 -0700728 fprint_alu_instruction(f, inst,
729 _mesa_opcode_string(inst->Opcode),
730 _mesa_num_inst_src_regs(inst->Opcode),
731 mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700732 break;
733 }
Brian5db088d2007-02-05 14:58:15 -0700734 return indent;
Brian00cdc0a2006-12-14 15:01:06 -0700735}
736
737
Brian Pauld0038932009-01-22 10:34:43 -0700738GLint
739_mesa_print_instruction_opt(const struct prog_instruction *inst,
740 GLint indent,
741 gl_prog_print_mode mode,
742 const struct gl_program *prog)
743{
744 return _mesa_fprint_instruction_opt(stdout, inst, indent, mode, prog);
745}
746
747
748void
749_mesa_print_instruction(const struct prog_instruction *inst)
750{
751 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
752 _mesa_fprint_instruction_opt(stdout, inst, 0, PROG_PRINT_DEBUG, NULL);
753}
754
755
756
757/**
758 * Print program, with options.
759 */
Brian Pauld2eff332009-02-02 12:24:41 -0700760void
Brian Pauld0038932009-01-22 10:34:43 -0700761_mesa_fprint_program_opt(FILE *f,
762 const struct gl_program *prog,
763 gl_prog_print_mode mode,
764 GLboolean lineNumbers)
765{
766 GLuint i, indent = 0;
767
768 switch (prog->Target) {
769 case GL_VERTEX_PROGRAM_ARB:
770 if (mode == PROG_PRINT_ARB)
771 _mesa_fprintf(f, "!!ARBvp1.0\n");
772 else if (mode == PROG_PRINT_NV)
773 _mesa_fprintf(f, "!!VP1.0\n");
774 else
775 _mesa_fprintf(f, "# Vertex Program/Shader\n");
776 break;
777 case GL_FRAGMENT_PROGRAM_ARB:
778 case GL_FRAGMENT_PROGRAM_NV:
779 if (mode == PROG_PRINT_ARB)
780 _mesa_fprintf(f, "!!ARBfp1.0\n");
781 else if (mode == PROG_PRINT_NV)
782 _mesa_fprintf(f, "!!FP1.0\n");
783 else
784 _mesa_fprintf(f, "# Fragment Program/Shader\n");
785 break;
786 }
787
788 for (i = 0; i < prog->NumInstructions; i++) {
789 if (lineNumbers)
790 _mesa_fprintf(f, "%3d: ", i);
791 indent = _mesa_fprint_instruction_opt(f, prog->Instructions + i,
792 indent, mode, prog);
793 }
794}
795
796
Brian00cdc0a2006-12-14 15:01:06 -0700797/**
Brian501ee872007-02-17 09:15:00 -0700798 * Print program to stdout, default options.
Brian00cdc0a2006-12-14 15:01:06 -0700799 */
800void
801_mesa_print_program(const struct gl_program *prog)
802{
Brian Pauld0038932009-01-22 10:34:43 -0700803 _mesa_fprint_program_opt(stdout, prog, PROG_PRINT_DEBUG, GL_TRUE);
Brian501ee872007-02-17 09:15:00 -0700804}
805
806
807/**
Brian Pauld0038932009-01-22 10:34:43 -0700808 * Print all of a program's parameters/fields to given file.
Brian501ee872007-02-17 09:15:00 -0700809 */
Brian Pauld0038932009-01-22 10:34:43 -0700810static void
811_mesa_fprint_program_parameters(FILE *f,
812 GLcontext *ctx,
813 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700814{
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600815 GLuint i;
816
Brian Pauld0038932009-01-22 10:34:43 -0700817 _mesa_fprintf(f, "InputsRead: 0x%x\n", prog->InputsRead);
818 _mesa_fprintf(f, "OutputsWritten: 0x%x\n", prog->OutputsWritten);
819 _mesa_fprintf(f, "NumInstructions=%d\n", prog->NumInstructions);
820 _mesa_fprintf(f, "NumTemporaries=%d\n", prog->NumTemporaries);
821 _mesa_fprintf(f, "NumParameters=%d\n", prog->NumParameters);
822 _mesa_fprintf(f, "NumAttributes=%d\n", prog->NumAttributes);
823 _mesa_fprintf(f, "NumAddressRegs=%d\n", prog->NumAddressRegs);
824 _mesa_fprintf(f, "Samplers=[ ");
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600825 for (i = 0; i < MAX_SAMPLERS; i++) {
Brian Pauld0038932009-01-22 10:34:43 -0700826 _mesa_fprintf(f, "%d ", prog->SamplerUnits[i]);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600827 }
Brian Pauld0038932009-01-22 10:34:43 -0700828 _mesa_fprintf(f, "]\n");
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600829
Brian00cdc0a2006-12-14 15:01:06 -0700830 _mesa_load_state_parameters(ctx, prog->Parameters);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600831
Brian00cdc0a2006-12-14 15:01:06 -0700832#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700833 _mesa_fprintf(f, "Local Params:\n");
Brian00cdc0a2006-12-14 15:01:06 -0700834 for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
835 const GLfloat *p = prog->LocalParams[i];
Brian Pauld0038932009-01-22 10:34:43 -0700836 _mesa_fprintf(f, "%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
Brian00cdc0a2006-12-14 15:01:06 -0700837 }
838#endif
Brian83ca3ff2006-12-20 17:17:38 -0700839 _mesa_print_parameter_list(prog->Parameters);
840}
Brian00cdc0a2006-12-14 15:01:06 -0700841
Brian83ca3ff2006-12-20 17:17:38 -0700842
Brian Pauld0038932009-01-22 10:34:43 -0700843/**
844 * Print all of a program's parameters/fields to stdout.
845 */
Brian83ca3ff2006-12-20 17:17:38 -0700846void
Brian Pauld0038932009-01-22 10:34:43 -0700847_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
848{
849 _mesa_fprint_program_parameters(stdout, ctx, prog);
850}
851
852
853/**
854 * Print a program parameter list to given file.
855 */
856static void
857_mesa_fprint_parameter_list(FILE *f,
858 const struct gl_program_parameter_list *list)
Brian83ca3ff2006-12-20 17:17:38 -0700859{
Brian501ee872007-02-17 09:15:00 -0700860 const gl_prog_print_mode mode = PROG_PRINT_DEBUG;
Brian83ca3ff2006-12-20 17:17:38 -0700861 GLuint i;
Brian501ee872007-02-17 09:15:00 -0700862
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600863 if (!list)
864 return;
865
Brian Pauld0038932009-01-22 10:34:43 -0700866 _mesa_fprintf(f, "param list %p\n", (void *) list);
Brian83ca3ff2006-12-20 17:17:38 -0700867 for (i = 0; i < list->NumParameters; i++){
868 struct gl_program_parameter *param = list->Parameters + i;
869 const GLfloat *v = list->ParameterValues[i];
Brian Pauld0038932009-01-22 10:34:43 -0700870 _mesa_fprintf(f, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
Brian83ca3ff2006-12-20 17:17:38 -0700871 i, param->Size,
Brian501ee872007-02-17 09:15:00 -0700872 file_string(list->Parameters[i].Type, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700873 param->Name, v[0], v[1], v[2], v[3]);
Brian Paulf490ec92008-11-24 09:04:52 -0700874 if (param->Flags & PROG_PARAM_BIT_CENTROID)
Brian Pauld0038932009-01-22 10:34:43 -0700875 _mesa_fprintf(f, " Centroid");
Brian Paulf490ec92008-11-24 09:04:52 -0700876 if (param->Flags & PROG_PARAM_BIT_INVARIANT)
Brian Pauld0038932009-01-22 10:34:43 -0700877 _mesa_fprintf(f, " Invariant");
Brian Paulf490ec92008-11-24 09:04:52 -0700878 if (param->Flags & PROG_PARAM_BIT_FLAT)
Brian Pauld0038932009-01-22 10:34:43 -0700879 _mesa_fprintf(f, " Flat");
Brian Paulf490ec92008-11-24 09:04:52 -0700880 if (param->Flags & PROG_PARAM_BIT_LINEAR)
Brian Pauld0038932009-01-22 10:34:43 -0700881 _mesa_fprintf(f, " Linear");
882 _mesa_fprintf(f, "\n");
Brian00cdc0a2006-12-14 15:01:06 -0700883 }
884}
Brian Pauld0038932009-01-22 10:34:43 -0700885
886
887/**
888 * Print a program parameter list to stdout.
889 */
890void
891_mesa_print_parameter_list(const struct gl_program_parameter_list *list)
892{
893 _mesa_fprint_parameter_list(stdout, list);
894}
895
896
897/**
898 * Write shader and associated info to a file.
899 */
900void
901_mesa_write_shader_to_file(const struct gl_shader *shader)
902{
903 const char *type;
904 char filename[100];
905 FILE *f;
906
907 if (shader->Type == GL_FRAGMENT_SHADER)
908 type = "frag";
909 else
910 type = "vert";
911
José Fonseca98a053c2009-02-11 13:52:11 +0000912 _mesa_snprintf(filename, strlen(filename), "shader_%u.%s", shader->Name, type);
Brian Pauld0038932009-01-22 10:34:43 -0700913 f = fopen(filename, "w");
914 if (!f) {
915 fprintf(stderr, "Unable to open %s for writing\n", filename);
916 return;
917 }
918
919 fprintf(f, "/* Shader %u source */\n", shader->Name);
920 fputs(shader->Source, f);
921 fprintf(f, "\n");
922
923 fprintf(f, "/* Compile status: %s */\n",
924 shader->CompileStatus ? "ok" : "fail");
925 if (!shader->CompileStatus) {
926 fprintf(f, "/* Log Info: */\n");
927 fputs(shader->InfoLog, f);
928 }
929 else {
930 fprintf(f, "/* GPU code */\n");
Brian Paul6ce0c6e2009-02-06 10:20:33 -0700931 fprintf(f, "/*\n");
Brian Pauld0038932009-01-22 10:34:43 -0700932 _mesa_fprint_program_opt(f, shader->Program, PROG_PRINT_DEBUG, GL_TRUE);
Brian Paul6ce0c6e2009-02-06 10:20:33 -0700933 fprintf(f, "*/\n");
Brian Pauld0038932009-01-22 10:34:43 -0700934 }
935
936 fclose(f);
937}
938
939