blob: 80be51c3c577c55e262e6a560fc79da1c8d44e62 [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{
89 const char *vertAttribs[] = {
90 "vertex.position",
91 "vertex.weight",
92 "vertex.normal",
93 "vertex.color.primary",
94 "vertex.color.secondary",
95 "vertex.fogcoord",
96 "vertex.(six)",
97 "vertex.(seven)",
98 "vertex.texcoord[0]",
99 "vertex.texcoord[1]",
100 "vertex.texcoord[2]",
101 "vertex.texcoord[3]",
102 "vertex.texcoord[4]",
103 "vertex.texcoord[5]",
104 "vertex.texcoord[6]",
Markus Amslerd7878502008-03-17 12:11:11 +0100105 "vertex.texcoord[7]",
106 "vertex.attrib[0]",
107 "vertex.attrib[1]",
108 "vertex.attrib[2]",
109 "vertex.attrib[3]",
110 "vertex.attrib[4]",
111 "vertex.attrib[5]",
112 "vertex.attrib[6]",
113 "vertex.attrib[7]",
114 "vertex.attrib[8]",
115 "vertex.attrib[9]",
116 "vertex.attrib[10]",
117 "vertex.attrib[11]",
118 "vertex.attrib[12]",
119 "vertex.attrib[13]",
120 "vertex.attrib[14]",
121 "vertex.attrib[15]"
Brian501ee872007-02-17 09:15:00 -0700122 };
123 const char *fragAttribs[] = {
124 "fragment.position",
125 "fragment.color.primary",
126 "fragment.color.secondary",
127 "fragment.fogcoord",
128 "fragment.texcoord[0]",
129 "fragment.texcoord[1]",
130 "fragment.texcoord[2]",
131 "fragment.texcoord[3]",
132 "fragment.texcoord[4]",
133 "fragment.texcoord[5]",
134 "fragment.texcoord[6]",
135 "fragment.texcoord[7]",
136 "fragment.varying[0]",
137 "fragment.varying[1]",
138 "fragment.varying[2]",
139 "fragment.varying[3]",
140 "fragment.varying[4]",
141 "fragment.varying[5]",
142 "fragment.varying[6]",
143 "fragment.varying[7]"
144 };
145
146 if (progType == GL_VERTEX_PROGRAM_ARB) {
147 assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0]));
148 return vertAttribs[index];
149 }
150 else {
151 assert(index < sizeof(fragAttribs) / sizeof(fragAttribs[0]));
152 return fragAttribs[index];
153 }
154}
155
156
157/**
158 * Return ARB_v/f_prog-style output attrib string.
159 */
160static const char *
161arb_output_attrib_string(GLint index, GLenum progType)
162{
163 const char *vertResults[] = {
164 "result.position",
165 "result.color.primary",
166 "result.color.secondary",
167 "result.fogcoord",
168 "result.texcoord[0]",
169 "result.texcoord[1]",
170 "result.texcoord[2]",
171 "result.texcoord[3]",
172 "result.texcoord[4]",
173 "result.texcoord[5]",
174 "result.texcoord[6]",
175 "result.texcoord[7]",
176 "result.varying[0]",
177 "result.varying[1]",
178 "result.varying[2]",
179 "result.varying[3]",
180 "result.varying[4]",
181 "result.varying[5]",
182 "result.varying[6]",
183 "result.varying[7]"
184 };
185 const char *fragResults[] = {
186 "result.color",
187 "result.depth"
188 };
189
190 if (progType == GL_VERTEX_PROGRAM_ARB) {
191 assert(index < sizeof(vertResults) / sizeof(vertResults[0]));
192 return vertResults[index];
193 }
194 else {
195 assert(index < sizeof(fragResults) / sizeof(fragResults[0]));
196 return fragResults[index];
197 }
198}
199
200
201/**
202 * Return string representation of the given register.
203 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
204 * by the ARB/NV program languages so we've taken some liberties here.
205 * \param file the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
206 * \param index number of the register in the register file
207 * \param mode the output format/mode/style
208 * \param prog pointer to containing program
209 */
210static const char *
211reg_string(enum register_file f, GLint index, gl_prog_print_mode mode,
Zack Rusin19659a52008-06-12 14:19:10 -0400212 GLboolean relAddr, const struct gl_program *prog)
Brian501ee872007-02-17 09:15:00 -0700213{
214 static char str[100];
Brian Paulf88a9012009-02-17 15:57:00 -0700215 const char *addr = relAddr ? "ADDR+" : "";
Brian501ee872007-02-17 09:15:00 -0700216
217 str[0] = 0;
218
219 switch (mode) {
220 case PROG_PRINT_DEBUG:
Brian Paulf88a9012009-02-17 15:57:00 -0700221 _mesa_sprintf(str, "%s[%s%d]", file_string(f, mode), addr, index);
Brian501ee872007-02-17 09:15:00 -0700222 break;
223
224 case PROG_PRINT_ARB:
225 switch (f) {
226 case PROGRAM_INPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000227 _mesa_sprintf(str, "%s", arb_input_attrib_string(index, prog->Target));
Brian501ee872007-02-17 09:15:00 -0700228 break;
229 case PROGRAM_OUTPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000230 _mesa_sprintf(str, "%s", arb_output_attrib_string(index, prog->Target));
Brian501ee872007-02-17 09:15:00 -0700231 break;
232 case PROGRAM_TEMPORARY:
José Fonseca98a053c2009-02-11 13:52:11 +0000233 _mesa_sprintf(str, "temp%d", index);
Brian501ee872007-02-17 09:15:00 -0700234 break;
235 case PROGRAM_ENV_PARAM:
Brian Paulf88a9012009-02-17 15:57:00 -0700236 _mesa_sprintf(str, "program.env[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700237 break;
238 case PROGRAM_LOCAL_PARAM:
Brian Paulf88a9012009-02-17 15:57:00 -0700239 _mesa_sprintf(str, "program.local[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700240 break;
241 case PROGRAM_VARYING: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700242 _mesa_sprintf(str, "varying[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700243 break;
244 case PROGRAM_CONSTANT: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700245 _mesa_sprintf(str, "constant[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700246 break;
247 case PROGRAM_UNIFORM: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700248 _mesa_sprintf(str, "uniform[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700249 break;
250 case PROGRAM_STATE_VAR:
251 {
252 struct gl_program_parameter *param
253 = prog->Parameters->Parameters + index;
Brian Paul9a644402008-09-04 15:05:03 -0600254 char *state = _mesa_program_state_string(param->StateIndexes);
José Fonseca98a053c2009-02-11 13:52:11 +0000255 _mesa_sprintf(str, state);
Brian Paul9a644402008-09-04 15:05:03 -0600256 _mesa_free(state);
Brian501ee872007-02-17 09:15:00 -0700257 }
258 break;
259 case PROGRAM_ADDRESS:
José Fonseca98a053c2009-02-11 13:52:11 +0000260 _mesa_sprintf(str, "A%d", index);
Brian501ee872007-02-17 09:15:00 -0700261 break;
262 default:
263 _mesa_problem(NULL, "bad file in reg_string()");
264 }
265 break;
266
267 case PROG_PRINT_NV:
268 switch (f) {
269 case PROGRAM_INPUT:
270 if (prog->Target == GL_VERTEX_PROGRAM_ARB)
José Fonseca98a053c2009-02-11 13:52:11 +0000271 _mesa_sprintf(str, "v[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700272 else
José Fonseca98a053c2009-02-11 13:52:11 +0000273 _mesa_sprintf(str, "f[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700274 break;
275 case PROGRAM_OUTPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000276 _mesa_sprintf(str, "o[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700277 break;
278 case PROGRAM_TEMPORARY:
José Fonseca98a053c2009-02-11 13:52:11 +0000279 _mesa_sprintf(str, "R%d", index);
Brian501ee872007-02-17 09:15:00 -0700280 break;
281 case PROGRAM_ENV_PARAM:
José Fonseca98a053c2009-02-11 13:52:11 +0000282 _mesa_sprintf(str, "c[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700283 break;
284 case PROGRAM_VARYING: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700285 _mesa_sprintf(str, "varying[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700286 break;
287 case PROGRAM_UNIFORM: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700288 _mesa_sprintf(str, "uniform[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700289 break;
290 case PROGRAM_CONSTANT: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700291 _mesa_sprintf(str, "constant[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700292 break;
293 case PROGRAM_STATE_VAR: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700294 _mesa_sprintf(str, "state[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700295 break;
296 default:
297 _mesa_problem(NULL, "bad file in reg_string()");
298 }
299 break;
300
301 default:
302 _mesa_problem(NULL, "bad mode in reg_string()");
303 }
304
305 return str;
306}
307
308
309/**
Brian00cdc0a2006-12-14 15:01:06 -0700310 * Return a string representation of the given swizzle word.
311 * If extended is true, use extended (comma-separated) format.
Brian3a281532006-12-16 12:51:34 -0700312 * \param swizzle the swizzle field
313 * \param negateBase 4-bit negation vector
314 * \param extended if true, also allow 0, 1 values
Brian00cdc0a2006-12-14 15:01:06 -0700315 */
Brian059376c2007-02-22 17:45:32 -0700316const char *
317_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended)
Brian00cdc0a2006-12-14 15:01:06 -0700318{
Brian Paul74a19b02008-07-18 19:46:19 -0600319 static const char swz[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
Brian00cdc0a2006-12-14 15:01:06 -0700320 static char s[20];
321 GLuint i = 0;
322
323 if (!extended && swizzle == SWIZZLE_NOOP && negateBase == 0)
324 return ""; /* no swizzle/negation */
325
326 if (!extended)
327 s[i++] = '.';
328
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600329 if (negateBase & NEGATE_X)
Brian00cdc0a2006-12-14 15:01:06 -0700330 s[i++] = '-';
331 s[i++] = swz[GET_SWZ(swizzle, 0)];
332
333 if (extended) {
334 s[i++] = ',';
335 }
336
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600337 if (negateBase & NEGATE_Y)
Brian00cdc0a2006-12-14 15:01:06 -0700338 s[i++] = '-';
339 s[i++] = swz[GET_SWZ(swizzle, 1)];
340
341 if (extended) {
342 s[i++] = ',';
343 }
344
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600345 if (negateBase & NEGATE_Z)
Brian00cdc0a2006-12-14 15:01:06 -0700346 s[i++] = '-';
347 s[i++] = swz[GET_SWZ(swizzle, 2)];
348
349 if (extended) {
350 s[i++] = ',';
351 }
352
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600353 if (negateBase & NEGATE_W)
Brian00cdc0a2006-12-14 15:01:06 -0700354 s[i++] = '-';
355 s[i++] = swz[GET_SWZ(swizzle, 3)];
356
357 s[i] = 0;
358 return s;
359}
360
361
Brian Paul511733b2008-07-02 12:40:03 -0600362void
363_mesa_print_swizzle(GLuint swizzle)
364{
365 if (swizzle == SWIZZLE_XYZW) {
366 _mesa_printf(".xyzw\n");
367 }
368 else {
Michal Krolf9c574d2008-07-15 11:44:47 +0200369 const char *s = _mesa_swizzle_string(swizzle, 0, 0);
Brian Paul511733b2008-07-02 12:40:03 -0600370 _mesa_printf("%s\n", s);
371 }
372}
373
374
Brian Paul610c2462008-11-13 16:37:52 -0700375const char *
376_mesa_writemask_string(GLuint writeMask)
Brian00cdc0a2006-12-14 15:01:06 -0700377{
378 static char s[10];
379 GLuint i = 0;
380
381 if (writeMask == WRITEMASK_XYZW)
382 return "";
383
384 s[i++] = '.';
385 if (writeMask & WRITEMASK_X)
386 s[i++] = 'x';
387 if (writeMask & WRITEMASK_Y)
388 s[i++] = 'y';
389 if (writeMask & WRITEMASK_Z)
390 s[i++] = 'z';
391 if (writeMask & WRITEMASK_W)
392 s[i++] = 'w';
393
394 s[i] = 0;
395 return s;
396}
397
Brian3a281532006-12-16 12:51:34 -0700398
Briand7508612007-03-28 11:01:09 -0600399const char *
400_mesa_condcode_string(GLuint condcode)
Brian3a281532006-12-16 12:51:34 -0700401{
402 switch (condcode) {
403 case COND_GT: return "GT";
404 case COND_EQ: return "EQ";
405 case COND_LT: return "LT";
406 case COND_UN: return "UN";
407 case COND_GE: return "GE";
408 case COND_LE: return "LE";
409 case COND_NE: return "NE";
410 case COND_TR: return "TR";
411 case COND_FL: return "FL";
412 default: return "cond???";
413 }
414}
415
416
Brian00cdc0a2006-12-14 15:01:06 -0700417static void
Brian Pauld0038932009-01-22 10:34:43 -0700418fprint_dst_reg(FILE * f,
419 const struct prog_dst_register *dstReg,
420 gl_prog_print_mode mode,
421 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700422{
Brian Pauld0038932009-01-22 10:34:43 -0700423 _mesa_fprintf(f, "%s%s",
424 reg_string((enum register_file) dstReg->File,
425 dstReg->Index, mode, dstReg->RelAddr, prog),
426 _mesa_writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700427
Brian1936b252007-03-22 09:04:18 -0600428 if (dstReg->CondMask != COND_TR) {
Brian Pauld0038932009-01-22 10:34:43 -0700429 _mesa_fprintf(f, " (%s.%s)",
430 _mesa_condcode_string(dstReg->CondMask),
431 _mesa_swizzle_string(dstReg->CondSwizzle,
432 GL_FALSE, GL_FALSE));
Brian1936b252007-03-22 09:04:18 -0600433 }
434
Brian501ee872007-02-17 09:15:00 -0700435#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700436 _mesa_fprintf(f, "%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700437 file_string((enum register_file) dstReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700438 dstReg->Index,
Brian Paul610c2462008-11-13 16:37:52 -0700439 _mesa_writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700440#endif
Brian00cdc0a2006-12-14 15:01:06 -0700441}
442
Brian Pauld0038932009-01-22 10:34:43 -0700443
Brian00cdc0a2006-12-14 15:01:06 -0700444static void
Brian Pauld0038932009-01-22 10:34:43 -0700445fprint_src_reg(FILE *f,
446 const struct prog_src_register *srcReg,
447 gl_prog_print_mode mode,
448 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700449{
Brian Pauld0038932009-01-22 10:34:43 -0700450 _mesa_fprintf(f, "%s%s",
451 reg_string((enum register_file) srcReg->File,
452 srcReg->Index, mode, srcReg->RelAddr, prog),
453 _mesa_swizzle_string(srcReg->Swizzle,
454 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700455#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700456 _mesa_fprintf(f, "%s[%d]%s",
457 file_string((enum register_file) srcReg->File, mode),
458 srcReg->Index,
459 _mesa_swizzle_string(srcReg->Swizzle,
460 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700461#endif
Brian00cdc0a2006-12-14 15:01:06 -0700462}
463
Brian Pauld0038932009-01-22 10:34:43 -0700464
Brian00cdc0a2006-12-14 15:01:06 -0700465static void
Brian Pauld0038932009-01-22 10:34:43 -0700466fprint_comment(FILE *f, const struct prog_instruction *inst)
Brian00cdc0a2006-12-14 15:01:06 -0700467{
468 if (inst->Comment)
Brian Pauld0038932009-01-22 10:34:43 -0700469 _mesa_fprintf(f, "; # %s\n", inst->Comment);
Brian00cdc0a2006-12-14 15:01:06 -0700470 else
Brian Pauld0038932009-01-22 10:34:43 -0700471 _mesa_fprintf(f, ";\n");
Brian00cdc0a2006-12-14 15:01:06 -0700472}
473
474
Brian501ee872007-02-17 09:15:00 -0700475static void
Brian Pauld0038932009-01-22 10:34:43 -0700476fprint_alu_instruction(FILE *f,
477 const struct prog_instruction *inst,
478 const char *opcode_string, GLuint numRegs,
479 gl_prog_print_mode mode,
480 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700481{
482 GLuint j;
483
Brian Pauld0038932009-01-22 10:34:43 -0700484 _mesa_fprintf(f, "%s", opcode_string);
Brianb50280e2006-12-18 16:21:58 -0700485 if (inst->CondUpdate)
Brian Pauld0038932009-01-22 10:34:43 -0700486 _mesa_fprintf(f, ".C");
Brian00cdc0a2006-12-14 15:01:06 -0700487
488 /* frag prog only */
489 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700490 _mesa_fprintf(f, "_SAT");
Brian00cdc0a2006-12-14 15:01:06 -0700491
Brian Pauld0038932009-01-22 10:34:43 -0700492 _mesa_fprintf(f, " ");
Brian00cdc0a2006-12-14 15:01:06 -0700493 if (inst->DstReg.File != PROGRAM_UNDEFINED) {
Brian Pauld0038932009-01-22 10:34:43 -0700494 fprint_dst_reg(f, &inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700495 }
496 else {
Brian Pauld0038932009-01-22 10:34:43 -0700497 _mesa_fprintf(f, " ???");
Brian00cdc0a2006-12-14 15:01:06 -0700498 }
499
500 if (numRegs > 0)
Brian Pauld0038932009-01-22 10:34:43 -0700501 _mesa_fprintf(f, ", ");
Brian00cdc0a2006-12-14 15:01:06 -0700502
503 for (j = 0; j < numRegs; j++) {
Brian Pauld0038932009-01-22 10:34:43 -0700504 fprint_src_reg(f, inst->SrcReg + j, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700505 if (j + 1 < numRegs)
Brian Pauld0038932009-01-22 10:34:43 -0700506 _mesa_fprintf(f, ", ");
Brian00cdc0a2006-12-14 15:01:06 -0700507 }
508
Brian Pauld0038932009-01-22 10:34:43 -0700509 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700510}
511
512
Brian501ee872007-02-17 09:15:00 -0700513void
Brian0020d102007-02-23 11:43:44 -0700514_mesa_print_alu_instruction(const struct prog_instruction *inst,
515 const char *opcode_string, GLuint numRegs)
516{
Brian Pauld0038932009-01-22 10:34:43 -0700517 fprint_alu_instruction(stdout, inst, opcode_string,
518 numRegs, PROG_PRINT_DEBUG, NULL);
Brian501ee872007-02-17 09:15:00 -0700519}
520
521
Brian00cdc0a2006-12-14 15:01:06 -0700522/**
523 * Print a single vertex/fragment program instruction.
524 */
Brian Pauld0038932009-01-22 10:34:43 -0700525static GLint
526_mesa_fprint_instruction_opt(FILE *f,
527 const struct prog_instruction *inst,
528 GLint indent,
Brian501ee872007-02-17 09:15:00 -0700529 gl_prog_print_mode mode,
530 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700531{
Brian7b300532007-02-22 09:08:36 -0700532 GLint i;
Brian5db088d2007-02-05 14:58:15 -0700533
534 if (inst->Opcode == OPCODE_ELSE ||
535 inst->Opcode == OPCODE_ENDIF ||
536 inst->Opcode == OPCODE_ENDLOOP ||
537 inst->Opcode == OPCODE_ENDSUB) {
538 indent -= 3;
539 }
Brian5db088d2007-02-05 14:58:15 -0700540 for (i = 0; i < indent; i++) {
Brian Pauld0038932009-01-22 10:34:43 -0700541 _mesa_fprintf(f, " ");
Brian5db088d2007-02-05 14:58:15 -0700542 }
543
Brian00cdc0a2006-12-14 15:01:06 -0700544 switch (inst->Opcode) {
545 case OPCODE_PRINT:
Brian Pauld0038932009-01-22 10:34:43 -0700546 _mesa_fprintf(f, "PRINT '%s'", inst->Data);
Brian00cdc0a2006-12-14 15:01:06 -0700547 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
Brian Pauld0038932009-01-22 10:34:43 -0700548 _mesa_fprintf(f, ", ");
549 _mesa_fprintf(f, "%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700550 file_string((enum register_file) inst->SrcReg[0].File,
551 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700552 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700553 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
554 inst->SrcReg[0].NegateBase, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700555 }
556 if (inst->Comment)
Brian Pauld0038932009-01-22 10:34:43 -0700557 _mesa_fprintf(f, " # %s", inst->Comment);
558 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700559 break;
560 case OPCODE_SWZ:
Brian Pauld0038932009-01-22 10:34:43 -0700561 _mesa_fprintf(f, "SWZ");
Brian00cdc0a2006-12-14 15:01:06 -0700562 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700563 _mesa_fprintf(f, "_SAT");
564 _mesa_fprintf(f, " ");
565 fprint_dst_reg(f, &inst->DstReg, mode, prog);
566 _mesa_fprintf(f, ", %s[%d], %s",
Brian501ee872007-02-17 09:15:00 -0700567 file_string((enum register_file) inst->SrcReg[0].File,
568 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700569 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700570 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
571 inst->SrcReg[0].NegateBase, GL_TRUE));
Brian Pauld0038932009-01-22 10:34:43 -0700572 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700573 break;
574 case OPCODE_TEX:
575 case OPCODE_TXP:
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600576 case OPCODE_TXL:
Brian00cdc0a2006-12-14 15:01:06 -0700577 case OPCODE_TXB:
Brian Pauld0038932009-01-22 10:34:43 -0700578 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
Brian00cdc0a2006-12-14 15:01:06 -0700579 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700580 _mesa_fprintf(f, "_SAT");
581 _mesa_fprintf(f, " ");
582 fprint_dst_reg(f, &inst->DstReg, mode, prog);
583 _mesa_fprintf(f, ", ");
584 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
585 _mesa_fprintf(f, ", texture[%d], ", inst->TexSrcUnit);
Brian00cdc0a2006-12-14 15:01:06 -0700586 switch (inst->TexSrcTarget) {
Brian Pauld0038932009-01-22 10:34:43 -0700587 case TEXTURE_1D_INDEX: _mesa_fprintf(f, "1D"); break;
588 case TEXTURE_2D_INDEX: _mesa_fprintf(f, "2D"); break;
589 case TEXTURE_3D_INDEX: _mesa_fprintf(f, "3D"); break;
590 case TEXTURE_CUBE_INDEX: _mesa_fprintf(f, "CUBE"); break;
591 case TEXTURE_RECT_INDEX: _mesa_fprintf(f, "RECT"); break;
Brian00cdc0a2006-12-14 15:01:06 -0700592 default:
593 ;
594 }
Brian Paul44e018c2009-02-20 13:42:08 -0700595 if (inst->TexShadow)
596 _mesa_fprintf(f, " SHADOW");
Brian Pauld0038932009-01-22 10:34:43 -0700597 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700598 break;
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600599
600 case OPCODE_KIL:
Brian Pauld0038932009-01-22 10:34:43 -0700601 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
602 _mesa_fprintf(f, " ");
603 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
604 fprint_comment(f, inst);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600605 break;
606 case OPCODE_KIL_NV:
Brian Pauld0038932009-01-22 10:34:43 -0700607 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
608 _mesa_fprintf(f, " ");
609 _mesa_fprintf(f, "%s.%s",
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600610 _mesa_condcode_string(inst->DstReg.CondMask),
611 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
612 GL_FALSE, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700613 fprint_comment(f, inst);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600614 break;
615
Brian00cdc0a2006-12-14 15:01:06 -0700616 case OPCODE_ARL:
Brian Pauld0038932009-01-22 10:34:43 -0700617 _mesa_fprintf(f, "ARL ");
618 fprint_dst_reg(f, &inst->DstReg, mode, prog);
619 _mesa_fprintf(f, ", ");
620 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
621 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700622 break;
623 case OPCODE_BRA:
Brian Pauld0038932009-01-22 10:34:43 -0700624 _mesa_fprintf(f, "BRA %d (%s%s)",
Brian3a281532006-12-16 12:51:34 -0700625 inst->BranchTarget,
Briand7508612007-03-28 11:01:09 -0600626 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700627 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700628 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700629 break;
Brian5ae49cf2007-01-20 09:27:40 -0700630 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600631 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
632 /* Use ordinary register */
Brian Pauld0038932009-01-22 10:34:43 -0700633 _mesa_fprintf(f, "IF ");
634 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
635 _mesa_fprintf(f, "; ");
Brian63556fa2007-03-23 14:47:46 -0600636 }
637 else {
638 /* Use cond codes */
Brian Pauld0038932009-01-22 10:34:43 -0700639 _mesa_fprintf(f, "IF (%s%s);",
Briand7508612007-03-28 11:01:09 -0600640 _mesa_condcode_string(inst->DstReg.CondMask),
Brian63556fa2007-03-23 14:47:46 -0600641 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
642 0, GL_FALSE));
643 }
Brian Pauld0038932009-01-22 10:34:43 -0700644 _mesa_fprintf(f, " # (if false, goto %d)", inst->BranchTarget);
645 fprint_comment(f, inst);
Brian5db088d2007-02-05 14:58:15 -0700646 return indent + 3;
647 case OPCODE_ELSE:
Brian Pauld0038932009-01-22 10:34:43 -0700648 _mesa_fprintf(f, "ELSE; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700649 return indent + 3;
650 case OPCODE_ENDIF:
Brian Pauld0038932009-01-22 10:34:43 -0700651 _mesa_fprintf(f, "ENDIF;\n");
Brian5db088d2007-02-05 14:58:15 -0700652 break;
653 case OPCODE_BGNLOOP:
Brian Pauld0038932009-01-22 10:34:43 -0700654 _mesa_fprintf(f, "BGNLOOP; # (end at %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700655 return indent + 3;
656 case OPCODE_ENDLOOP:
Brian Pauld0038932009-01-22 10:34:43 -0700657 _mesa_fprintf(f, "ENDLOOP; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700658 break;
659 case OPCODE_BRK:
Brianf22ed092007-02-06 22:31:19 -0700660 case OPCODE_CONT:
Brian Pauld0038932009-01-22 10:34:43 -0700661 _mesa_fprintf(f, "%s (%s%s); # (goto %d)",
Brian81767ee2007-03-23 17:45:53 -0600662 _mesa_opcode_string(inst->Opcode),
Briand7508612007-03-28 11:01:09 -0600663 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700664 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
Brian2755c792007-02-05 18:01:02 -0700665 inst->BranchTarget);
Brian Pauld0038932009-01-22 10:34:43 -0700666 fprint_comment(f, inst);
Brian5ae49cf2007-01-20 09:27:40 -0700667 break;
Brian63556fa2007-03-23 14:47:46 -0600668
Brian5db088d2007-02-05 14:58:15 -0700669 case OPCODE_BGNSUB:
Brianf407cad2007-03-27 14:53:17 -0600670 if (mode == PROG_PRINT_NV) {
Brian Pauld0038932009-01-22 10:34:43 -0700671 _mesa_fprintf(f, "%s:\n", inst->Comment); /* comment is label */
Brianf407cad2007-03-27 14:53:17 -0600672 return indent;
673 }
674 else {
Brian Pauld0038932009-01-22 10:34:43 -0700675 _mesa_fprintf(f, "BGNSUB");
676 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600677 return indent + 3;
678 }
Brian5db088d2007-02-05 14:58:15 -0700679 case OPCODE_ENDSUB:
Brianf407cad2007-03-27 14:53:17 -0600680 if (mode == PROG_PRINT_DEBUG) {
Brian Pauld0038932009-01-22 10:34:43 -0700681 _mesa_fprintf(f, "ENDSUB");
682 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600683 }
684 break;
685 case OPCODE_CAL:
686 if (mode == PROG_PRINT_NV) {
Brian Pauld0038932009-01-22 10:34:43 -0700687 _mesa_fprintf(f, "CAL %s; # (goto %d)\n", inst->Comment, inst->BranchTarget);
Brianf407cad2007-03-27 14:53:17 -0600688 }
689 else {
Brian Pauld0038932009-01-22 10:34:43 -0700690 _mesa_fprintf(f, "CAL %u", inst->BranchTarget);
691 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600692 }
693 break;
694 case OPCODE_RET:
Brian Pauld0038932009-01-22 10:34:43 -0700695 _mesa_fprintf(f, "RET (%s%s)",
Briand7508612007-03-28 11:01:09 -0600696 _mesa_condcode_string(inst->DstReg.CondMask),
697 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700698 fprint_comment(f, inst);
Brian5ae49cf2007-01-20 09:27:40 -0700699 break;
Brianf407cad2007-03-27 14:53:17 -0600700
Brian00cdc0a2006-12-14 15:01:06 -0700701 case OPCODE_END:
Brian Pauld0038932009-01-22 10:34:43 -0700702 _mesa_fprintf(f, "END\n");
Brian00cdc0a2006-12-14 15:01:06 -0700703 break;
Brian3a281532006-12-16 12:51:34 -0700704 case OPCODE_NOP:
Brian059376c2007-02-22 17:45:32 -0700705 if (mode == PROG_PRINT_DEBUG) {
Brian Pauld0038932009-01-22 10:34:43 -0700706 _mesa_fprintf(f, "NOP");
707 fprint_comment(f, inst);
Brian059376c2007-02-22 17:45:32 -0700708 }
709 else if (inst->Comment) {
710 /* ARB/NV extensions don't have NOP instruction */
Brian Pauld0038932009-01-22 10:34:43 -0700711 _mesa_fprintf(f, "# %s\n", inst->Comment);
Brian059376c2007-02-22 17:45:32 -0700712 }
Brian3a281532006-12-16 12:51:34 -0700713 break;
Brian00cdc0a2006-12-14 15:01:06 -0700714 /* XXX may need other special-case instructions */
715 default:
716 /* typical alu instruction */
Brian Pauld0038932009-01-22 10:34:43 -0700717 fprint_alu_instruction(f, inst,
718 _mesa_opcode_string(inst->Opcode),
719 _mesa_num_inst_src_regs(inst->Opcode),
720 mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700721 break;
722 }
Brian5db088d2007-02-05 14:58:15 -0700723 return indent;
Brian00cdc0a2006-12-14 15:01:06 -0700724}
725
726
Brian Pauld0038932009-01-22 10:34:43 -0700727GLint
728_mesa_print_instruction_opt(const struct prog_instruction *inst,
729 GLint indent,
730 gl_prog_print_mode mode,
731 const struct gl_program *prog)
732{
733 return _mesa_fprint_instruction_opt(stdout, inst, indent, mode, prog);
734}
735
736
737void
738_mesa_print_instruction(const struct prog_instruction *inst)
739{
740 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
741 _mesa_fprint_instruction_opt(stdout, inst, 0, PROG_PRINT_DEBUG, NULL);
742}
743
744
745
746/**
747 * Print program, with options.
748 */
Brian Pauld2eff332009-02-02 12:24:41 -0700749void
Brian Pauld0038932009-01-22 10:34:43 -0700750_mesa_fprint_program_opt(FILE *f,
751 const struct gl_program *prog,
752 gl_prog_print_mode mode,
753 GLboolean lineNumbers)
754{
755 GLuint i, indent = 0;
756
757 switch (prog->Target) {
758 case GL_VERTEX_PROGRAM_ARB:
759 if (mode == PROG_PRINT_ARB)
760 _mesa_fprintf(f, "!!ARBvp1.0\n");
761 else if (mode == PROG_PRINT_NV)
762 _mesa_fprintf(f, "!!VP1.0\n");
763 else
764 _mesa_fprintf(f, "# Vertex Program/Shader\n");
765 break;
766 case GL_FRAGMENT_PROGRAM_ARB:
767 case GL_FRAGMENT_PROGRAM_NV:
768 if (mode == PROG_PRINT_ARB)
769 _mesa_fprintf(f, "!!ARBfp1.0\n");
770 else if (mode == PROG_PRINT_NV)
771 _mesa_fprintf(f, "!!FP1.0\n");
772 else
773 _mesa_fprintf(f, "# Fragment Program/Shader\n");
774 break;
775 }
776
777 for (i = 0; i < prog->NumInstructions; i++) {
778 if (lineNumbers)
779 _mesa_fprintf(f, "%3d: ", i);
780 indent = _mesa_fprint_instruction_opt(f, prog->Instructions + i,
781 indent, mode, prog);
782 }
783}
784
785
Brian00cdc0a2006-12-14 15:01:06 -0700786/**
Brian501ee872007-02-17 09:15:00 -0700787 * Print program to stdout, default options.
Brian00cdc0a2006-12-14 15:01:06 -0700788 */
789void
790_mesa_print_program(const struct gl_program *prog)
791{
Brian Pauld0038932009-01-22 10:34:43 -0700792 _mesa_fprint_program_opt(stdout, prog, PROG_PRINT_DEBUG, GL_TRUE);
Brian501ee872007-02-17 09:15:00 -0700793}
794
795
796/**
Brian Pauld0038932009-01-22 10:34:43 -0700797 * Print all of a program's parameters/fields to given file.
Brian501ee872007-02-17 09:15:00 -0700798 */
Brian Pauld0038932009-01-22 10:34:43 -0700799static void
800_mesa_fprint_program_parameters(FILE *f,
801 GLcontext *ctx,
802 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700803{
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600804 GLuint i;
805
Brian Pauld0038932009-01-22 10:34:43 -0700806 _mesa_fprintf(f, "InputsRead: 0x%x\n", prog->InputsRead);
807 _mesa_fprintf(f, "OutputsWritten: 0x%x\n", prog->OutputsWritten);
808 _mesa_fprintf(f, "NumInstructions=%d\n", prog->NumInstructions);
809 _mesa_fprintf(f, "NumTemporaries=%d\n", prog->NumTemporaries);
810 _mesa_fprintf(f, "NumParameters=%d\n", prog->NumParameters);
811 _mesa_fprintf(f, "NumAttributes=%d\n", prog->NumAttributes);
812 _mesa_fprintf(f, "NumAddressRegs=%d\n", prog->NumAddressRegs);
813 _mesa_fprintf(f, "Samplers=[ ");
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600814 for (i = 0; i < MAX_SAMPLERS; i++) {
Brian Pauld0038932009-01-22 10:34:43 -0700815 _mesa_fprintf(f, "%d ", prog->SamplerUnits[i]);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600816 }
Brian Pauld0038932009-01-22 10:34:43 -0700817 _mesa_fprintf(f, "]\n");
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600818
Brian00cdc0a2006-12-14 15:01:06 -0700819 _mesa_load_state_parameters(ctx, prog->Parameters);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600820
Brian00cdc0a2006-12-14 15:01:06 -0700821#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700822 _mesa_fprintf(f, "Local Params:\n");
Brian00cdc0a2006-12-14 15:01:06 -0700823 for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
824 const GLfloat *p = prog->LocalParams[i];
Brian Pauld0038932009-01-22 10:34:43 -0700825 _mesa_fprintf(f, "%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
Brian00cdc0a2006-12-14 15:01:06 -0700826 }
827#endif
Brian83ca3ff2006-12-20 17:17:38 -0700828 _mesa_print_parameter_list(prog->Parameters);
829}
Brian00cdc0a2006-12-14 15:01:06 -0700830
Brian83ca3ff2006-12-20 17:17:38 -0700831
Brian Pauld0038932009-01-22 10:34:43 -0700832/**
833 * Print all of a program's parameters/fields to stdout.
834 */
Brian83ca3ff2006-12-20 17:17:38 -0700835void
Brian Pauld0038932009-01-22 10:34:43 -0700836_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
837{
838 _mesa_fprint_program_parameters(stdout, ctx, prog);
839}
840
841
842/**
843 * Print a program parameter list to given file.
844 */
845static void
846_mesa_fprint_parameter_list(FILE *f,
847 const struct gl_program_parameter_list *list)
Brian83ca3ff2006-12-20 17:17:38 -0700848{
Brian501ee872007-02-17 09:15:00 -0700849 const gl_prog_print_mode mode = PROG_PRINT_DEBUG;
Brian83ca3ff2006-12-20 17:17:38 -0700850 GLuint i;
Brian501ee872007-02-17 09:15:00 -0700851
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600852 if (!list)
853 return;
854
Brian Pauld0038932009-01-22 10:34:43 -0700855 _mesa_fprintf(f, "param list %p\n", (void *) list);
Brian83ca3ff2006-12-20 17:17:38 -0700856 for (i = 0; i < list->NumParameters; i++){
857 struct gl_program_parameter *param = list->Parameters + i;
858 const GLfloat *v = list->ParameterValues[i];
Brian Pauld0038932009-01-22 10:34:43 -0700859 _mesa_fprintf(f, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
Brian83ca3ff2006-12-20 17:17:38 -0700860 i, param->Size,
Brian501ee872007-02-17 09:15:00 -0700861 file_string(list->Parameters[i].Type, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700862 param->Name, v[0], v[1], v[2], v[3]);
Brian Paulf490ec92008-11-24 09:04:52 -0700863 if (param->Flags & PROG_PARAM_BIT_CENTROID)
Brian Pauld0038932009-01-22 10:34:43 -0700864 _mesa_fprintf(f, " Centroid");
Brian Paulf490ec92008-11-24 09:04:52 -0700865 if (param->Flags & PROG_PARAM_BIT_INVARIANT)
Brian Pauld0038932009-01-22 10:34:43 -0700866 _mesa_fprintf(f, " Invariant");
Brian Paulf490ec92008-11-24 09:04:52 -0700867 if (param->Flags & PROG_PARAM_BIT_FLAT)
Brian Pauld0038932009-01-22 10:34:43 -0700868 _mesa_fprintf(f, " Flat");
Brian Paulf490ec92008-11-24 09:04:52 -0700869 if (param->Flags & PROG_PARAM_BIT_LINEAR)
Brian Pauld0038932009-01-22 10:34:43 -0700870 _mesa_fprintf(f, " Linear");
871 _mesa_fprintf(f, "\n");
Brian00cdc0a2006-12-14 15:01:06 -0700872 }
873}
Brian Pauld0038932009-01-22 10:34:43 -0700874
875
876/**
877 * Print a program parameter list to stdout.
878 */
879void
880_mesa_print_parameter_list(const struct gl_program_parameter_list *list)
881{
882 _mesa_fprint_parameter_list(stdout, list);
883}
884
885
886/**
887 * Write shader and associated info to a file.
888 */
889void
890_mesa_write_shader_to_file(const struct gl_shader *shader)
891{
892 const char *type;
893 char filename[100];
894 FILE *f;
895
896 if (shader->Type == GL_FRAGMENT_SHADER)
897 type = "frag";
898 else
899 type = "vert";
900
José Fonseca98a053c2009-02-11 13:52:11 +0000901 _mesa_snprintf(filename, strlen(filename), "shader_%u.%s", shader->Name, type);
Brian Pauld0038932009-01-22 10:34:43 -0700902 f = fopen(filename, "w");
903 if (!f) {
904 fprintf(stderr, "Unable to open %s for writing\n", filename);
905 return;
906 }
907
908 fprintf(f, "/* Shader %u source */\n", shader->Name);
909 fputs(shader->Source, f);
910 fprintf(f, "\n");
911
912 fprintf(f, "/* Compile status: %s */\n",
913 shader->CompileStatus ? "ok" : "fail");
914 if (!shader->CompileStatus) {
915 fprintf(f, "/* Log Info: */\n");
916 fputs(shader->InfoLog, f);
917 }
918 else {
919 fprintf(f, "/* GPU code */\n");
Brian Paul6ce0c6e2009-02-06 10:20:33 -0700920 fprintf(f, "/*\n");
Brian Pauld0038932009-01-22 10:34:43 -0700921 _mesa_fprint_program_opt(f, shader->Program, PROG_PRINT_DEBUG, GL_TRUE);
Brian Paul6ce0c6e2009-02-06 10:20:33 -0700922 fprintf(f, "*/\n");
Brian Pauld0038932009-01-22 10:34:43 -0700923 }
924
925 fclose(f);
926}
927
928