blob: cef0288a9c9432dc22ca09eadfd5aa4e0357c720 [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 *
Brian Paulb4026d92009-03-07 12:02:52 -070046file_string(gl_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:
Brian Paul7c2fe422009-05-11 09:38:32 -060078 {
79 static char s[20];
80 _mesa_snprintf(s, sizeof(s), "FILE%u", f);
81 return s;
82 }
Brian00cdc0a2006-12-14 15:01:06 -070083 }
84}
85
86
87/**
Brian501ee872007-02-17 09:15:00 -070088 * Return ARB_v/f_prog-style input attrib string.
89 */
90static const char *
91arb_input_attrib_string(GLint index, GLenum progType)
92{
Brian Paula0709372009-02-27 13:44:42 -070093 /*
94 * These strings should match the VERT_ATTRIB_x and FRAG_ATTRIB_x tokens.
95 */
Brian501ee872007-02-17 09:15:00 -070096 const char *vertAttribs[] = {
97 "vertex.position",
98 "vertex.weight",
99 "vertex.normal",
100 "vertex.color.primary",
101 "vertex.color.secondary",
102 "vertex.fogcoord",
103 "vertex.(six)",
104 "vertex.(seven)",
105 "vertex.texcoord[0]",
106 "vertex.texcoord[1]",
107 "vertex.texcoord[2]",
108 "vertex.texcoord[3]",
109 "vertex.texcoord[4]",
110 "vertex.texcoord[5]",
111 "vertex.texcoord[6]",
Markus Amslerd7878502008-03-17 12:11:11 +0100112 "vertex.texcoord[7]",
113 "vertex.attrib[0]",
114 "vertex.attrib[1]",
115 "vertex.attrib[2]",
116 "vertex.attrib[3]",
117 "vertex.attrib[4]",
118 "vertex.attrib[5]",
119 "vertex.attrib[6]",
120 "vertex.attrib[7]",
121 "vertex.attrib[8]",
122 "vertex.attrib[9]",
123 "vertex.attrib[10]",
124 "vertex.attrib[11]",
125 "vertex.attrib[12]",
126 "vertex.attrib[13]",
127 "vertex.attrib[14]",
128 "vertex.attrib[15]"
Brian501ee872007-02-17 09:15:00 -0700129 };
130 const char *fragAttribs[] = {
131 "fragment.position",
132 "fragment.color.primary",
133 "fragment.color.secondary",
134 "fragment.fogcoord",
135 "fragment.texcoord[0]",
136 "fragment.texcoord[1]",
137 "fragment.texcoord[2]",
138 "fragment.texcoord[3]",
139 "fragment.texcoord[4]",
140 "fragment.texcoord[5]",
141 "fragment.texcoord[6]",
142 "fragment.texcoord[7]",
143 "fragment.varying[0]",
144 "fragment.varying[1]",
145 "fragment.varying[2]",
146 "fragment.varying[3]",
147 "fragment.varying[4]",
148 "fragment.varying[5]",
149 "fragment.varying[6]",
150 "fragment.varying[7]"
151 };
152
153 if (progType == GL_VERTEX_PROGRAM_ARB) {
154 assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0]));
155 return vertAttribs[index];
156 }
157 else {
158 assert(index < sizeof(fragAttribs) / sizeof(fragAttribs[0]));
159 return fragAttribs[index];
160 }
161}
162
163
164/**
165 * Return ARB_v/f_prog-style output attrib string.
166 */
167static const char *
168arb_output_attrib_string(GLint index, GLenum progType)
169{
Brian Paula0709372009-02-27 13:44:42 -0700170 /*
171 * These strings should match the VERT_RESULT_x and FRAG_RESULT_x tokens.
172 */
Brian501ee872007-02-17 09:15:00 -0700173 const char *vertResults[] = {
174 "result.position",
175 "result.color.primary",
176 "result.color.secondary",
177 "result.fogcoord",
178 "result.texcoord[0]",
179 "result.texcoord[1]",
180 "result.texcoord[2]",
181 "result.texcoord[3]",
182 "result.texcoord[4]",
183 "result.texcoord[5]",
184 "result.texcoord[6]",
185 "result.texcoord[7]",
186 "result.varying[0]",
187 "result.varying[1]",
188 "result.varying[2]",
189 "result.varying[3]",
190 "result.varying[4]",
191 "result.varying[5]",
192 "result.varying[6]",
193 "result.varying[7]"
194 };
195 const char *fragResults[] = {
196 "result.color",
Brian Paula0709372009-02-27 13:44:42 -0700197 "result.color(half)",
198 "result.depth",
199 "result.color[0]",
200 "result.color[1]",
201 "result.color[2]",
202 "result.color[3]"
Brian501ee872007-02-17 09:15:00 -0700203 };
204
205 if (progType == GL_VERTEX_PROGRAM_ARB) {
206 assert(index < sizeof(vertResults) / sizeof(vertResults[0]));
207 return vertResults[index];
208 }
209 else {
210 assert(index < sizeof(fragResults) / sizeof(fragResults[0]));
211 return fragResults[index];
212 }
213}
214
215
216/**
217 * Return string representation of the given register.
218 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
219 * by the ARB/NV program languages so we've taken some liberties here.
Vinson Lee1eee1ba2009-03-17 09:34:30 -0600220 * \param f the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
Brian501ee872007-02-17 09:15:00 -0700221 * \param index number of the register in the register file
222 * \param mode the output format/mode/style
223 * \param prog pointer to containing program
224 */
225static const char *
Brian Paulb4026d92009-03-07 12:02:52 -0700226reg_string(gl_register_file f, GLint index, gl_prog_print_mode mode,
Zack Rusin19659a52008-06-12 14:19:10 -0400227 GLboolean relAddr, const struct gl_program *prog)
Brian501ee872007-02-17 09:15:00 -0700228{
229 static char str[100];
Brian Paulf88a9012009-02-17 15:57:00 -0700230 const char *addr = relAddr ? "ADDR+" : "";
Brian501ee872007-02-17 09:15:00 -0700231
232 str[0] = 0;
233
234 switch (mode) {
235 case PROG_PRINT_DEBUG:
Brian Paulf88a9012009-02-17 15:57:00 -0700236 _mesa_sprintf(str, "%s[%s%d]", file_string(f, mode), addr, index);
Brian501ee872007-02-17 09:15:00 -0700237 break;
238
239 case PROG_PRINT_ARB:
240 switch (f) {
241 case PROGRAM_INPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000242 _mesa_sprintf(str, "%s", arb_input_attrib_string(index, prog->Target));
Brian501ee872007-02-17 09:15:00 -0700243 break;
244 case PROGRAM_OUTPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000245 _mesa_sprintf(str, "%s", arb_output_attrib_string(index, prog->Target));
Brian501ee872007-02-17 09:15:00 -0700246 break;
247 case PROGRAM_TEMPORARY:
José Fonseca98a053c2009-02-11 13:52:11 +0000248 _mesa_sprintf(str, "temp%d", index);
Brian501ee872007-02-17 09:15:00 -0700249 break;
250 case PROGRAM_ENV_PARAM:
Brian Paulf88a9012009-02-17 15:57:00 -0700251 _mesa_sprintf(str, "program.env[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700252 break;
253 case PROGRAM_LOCAL_PARAM:
Brian Paulf88a9012009-02-17 15:57:00 -0700254 _mesa_sprintf(str, "program.local[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700255 break;
256 case PROGRAM_VARYING: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700257 _mesa_sprintf(str, "varying[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700258 break;
259 case PROGRAM_CONSTANT: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700260 _mesa_sprintf(str, "constant[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700261 break;
262 case PROGRAM_UNIFORM: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700263 _mesa_sprintf(str, "uniform[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700264 break;
265 case PROGRAM_STATE_VAR:
266 {
267 struct gl_program_parameter *param
268 = prog->Parameters->Parameters + index;
Brian Paul9a644402008-09-04 15:05:03 -0600269 char *state = _mesa_program_state_string(param->StateIndexes);
José Fonseca98a053c2009-02-11 13:52:11 +0000270 _mesa_sprintf(str, state);
Brian Paul9a644402008-09-04 15:05:03 -0600271 _mesa_free(state);
Brian501ee872007-02-17 09:15:00 -0700272 }
273 break;
274 case PROGRAM_ADDRESS:
José Fonseca98a053c2009-02-11 13:52:11 +0000275 _mesa_sprintf(str, "A%d", index);
Brian501ee872007-02-17 09:15:00 -0700276 break;
277 default:
278 _mesa_problem(NULL, "bad file in reg_string()");
279 }
280 break;
281
282 case PROG_PRINT_NV:
283 switch (f) {
284 case PROGRAM_INPUT:
285 if (prog->Target == GL_VERTEX_PROGRAM_ARB)
José Fonseca98a053c2009-02-11 13:52:11 +0000286 _mesa_sprintf(str, "v[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700287 else
José Fonseca98a053c2009-02-11 13:52:11 +0000288 _mesa_sprintf(str, "f[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700289 break;
290 case PROGRAM_OUTPUT:
José Fonseca98a053c2009-02-11 13:52:11 +0000291 _mesa_sprintf(str, "o[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700292 break;
293 case PROGRAM_TEMPORARY:
José Fonseca98a053c2009-02-11 13:52:11 +0000294 _mesa_sprintf(str, "R%d", index);
Brian501ee872007-02-17 09:15:00 -0700295 break;
296 case PROGRAM_ENV_PARAM:
José Fonseca98a053c2009-02-11 13:52:11 +0000297 _mesa_sprintf(str, "c[%d]", index);
Brian501ee872007-02-17 09:15:00 -0700298 break;
299 case PROGRAM_VARYING: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700300 _mesa_sprintf(str, "varying[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700301 break;
302 case PROGRAM_UNIFORM: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700303 _mesa_sprintf(str, "uniform[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700304 break;
305 case PROGRAM_CONSTANT: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700306 _mesa_sprintf(str, "constant[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700307 break;
308 case PROGRAM_STATE_VAR: /* extension */
Brian Paulf88a9012009-02-17 15:57:00 -0700309 _mesa_sprintf(str, "state[%s%d]", addr, index);
Brian501ee872007-02-17 09:15:00 -0700310 break;
311 default:
312 _mesa_problem(NULL, "bad file in reg_string()");
313 }
314 break;
315
316 default:
317 _mesa_problem(NULL, "bad mode in reg_string()");
318 }
319
320 return str;
321}
322
323
324/**
Brian00cdc0a2006-12-14 15:01:06 -0700325 * Return a string representation of the given swizzle word.
326 * If extended is true, use extended (comma-separated) format.
Brian3a281532006-12-16 12:51:34 -0700327 * \param swizzle the swizzle field
328 * \param negateBase 4-bit negation vector
329 * \param extended if true, also allow 0, 1 values
Brian00cdc0a2006-12-14 15:01:06 -0700330 */
Brian059376c2007-02-22 17:45:32 -0700331const char *
Brian Paul7db7ff82009-04-14 22:14:30 -0600332_mesa_swizzle_string(GLuint swizzle, GLuint negateMask, GLboolean extended)
Brian00cdc0a2006-12-14 15:01:06 -0700333{
Brian Paul74a19b02008-07-18 19:46:19 -0600334 static const char swz[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
Brian00cdc0a2006-12-14 15:01:06 -0700335 static char s[20];
336 GLuint i = 0;
337
Brian Paul7db7ff82009-04-14 22:14:30 -0600338 if (!extended && swizzle == SWIZZLE_NOOP && negateMask == 0)
Brian00cdc0a2006-12-14 15:01:06 -0700339 return ""; /* no swizzle/negation */
340
341 if (!extended)
342 s[i++] = '.';
343
Brian Paul7db7ff82009-04-14 22:14:30 -0600344 if (negateMask & NEGATE_X)
Brian00cdc0a2006-12-14 15:01:06 -0700345 s[i++] = '-';
346 s[i++] = swz[GET_SWZ(swizzle, 0)];
347
348 if (extended) {
349 s[i++] = ',';
350 }
351
Brian Paul7db7ff82009-04-14 22:14:30 -0600352 if (negateMask & NEGATE_Y)
Brian00cdc0a2006-12-14 15:01:06 -0700353 s[i++] = '-';
354 s[i++] = swz[GET_SWZ(swizzle, 1)];
355
356 if (extended) {
357 s[i++] = ',';
358 }
359
Brian Paul7db7ff82009-04-14 22:14:30 -0600360 if (negateMask & NEGATE_Z)
Brian00cdc0a2006-12-14 15:01:06 -0700361 s[i++] = '-';
362 s[i++] = swz[GET_SWZ(swizzle, 2)];
363
364 if (extended) {
365 s[i++] = ',';
366 }
367
Brian Paul7db7ff82009-04-14 22:14:30 -0600368 if (negateMask & NEGATE_W)
Brian00cdc0a2006-12-14 15:01:06 -0700369 s[i++] = '-';
370 s[i++] = swz[GET_SWZ(swizzle, 3)];
371
372 s[i] = 0;
373 return s;
374}
375
376
Brian Paul511733b2008-07-02 12:40:03 -0600377void
378_mesa_print_swizzle(GLuint swizzle)
379{
380 if (swizzle == SWIZZLE_XYZW) {
381 _mesa_printf(".xyzw\n");
382 }
383 else {
Michal Krolf9c574d2008-07-15 11:44:47 +0200384 const char *s = _mesa_swizzle_string(swizzle, 0, 0);
Brian Paul511733b2008-07-02 12:40:03 -0600385 _mesa_printf("%s\n", s);
386 }
387}
388
389
Brian Paul610c2462008-11-13 16:37:52 -0700390const char *
391_mesa_writemask_string(GLuint writeMask)
Brian00cdc0a2006-12-14 15:01:06 -0700392{
393 static char s[10];
394 GLuint i = 0;
395
396 if (writeMask == WRITEMASK_XYZW)
397 return "";
398
399 s[i++] = '.';
400 if (writeMask & WRITEMASK_X)
401 s[i++] = 'x';
402 if (writeMask & WRITEMASK_Y)
403 s[i++] = 'y';
404 if (writeMask & WRITEMASK_Z)
405 s[i++] = 'z';
406 if (writeMask & WRITEMASK_W)
407 s[i++] = 'w';
408
409 s[i] = 0;
410 return s;
411}
412
Brian3a281532006-12-16 12:51:34 -0700413
Briand7508612007-03-28 11:01:09 -0600414const char *
415_mesa_condcode_string(GLuint condcode)
Brian3a281532006-12-16 12:51:34 -0700416{
417 switch (condcode) {
418 case COND_GT: return "GT";
419 case COND_EQ: return "EQ";
420 case COND_LT: return "LT";
421 case COND_UN: return "UN";
422 case COND_GE: return "GE";
423 case COND_LE: return "LE";
424 case COND_NE: return "NE";
425 case COND_TR: return "TR";
426 case COND_FL: return "FL";
427 default: return "cond???";
428 }
429}
430
431
Brian00cdc0a2006-12-14 15:01:06 -0700432static void
Brian Pauld0038932009-01-22 10:34:43 -0700433fprint_dst_reg(FILE * f,
434 const struct prog_dst_register *dstReg,
435 gl_prog_print_mode mode,
436 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700437{
Brian Pauld0038932009-01-22 10:34:43 -0700438 _mesa_fprintf(f, "%s%s",
Brian Paulb4026d92009-03-07 12:02:52 -0700439 reg_string((gl_register_file) dstReg->File,
Brian Pauld0038932009-01-22 10:34:43 -0700440 dstReg->Index, mode, dstReg->RelAddr, prog),
441 _mesa_writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700442
Brian1936b252007-03-22 09:04:18 -0600443 if (dstReg->CondMask != COND_TR) {
Brian Pauld0038932009-01-22 10:34:43 -0700444 _mesa_fprintf(f, " (%s.%s)",
445 _mesa_condcode_string(dstReg->CondMask),
446 _mesa_swizzle_string(dstReg->CondSwizzle,
447 GL_FALSE, GL_FALSE));
Brian1936b252007-03-22 09:04:18 -0600448 }
449
Brian501ee872007-02-17 09:15:00 -0700450#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700451 _mesa_fprintf(f, "%s[%d]%s",
Brian Paulb4026d92009-03-07 12:02:52 -0700452 file_string((gl_register_file) dstReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700453 dstReg->Index,
Brian Paul610c2462008-11-13 16:37:52 -0700454 _mesa_writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700455#endif
Brian00cdc0a2006-12-14 15:01:06 -0700456}
457
Brian Pauld0038932009-01-22 10:34:43 -0700458
Brian00cdc0a2006-12-14 15:01:06 -0700459static void
Brian Pauld0038932009-01-22 10:34:43 -0700460fprint_src_reg(FILE *f,
461 const struct prog_src_register *srcReg,
462 gl_prog_print_mode mode,
463 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700464{
Brian Paulf787baf2009-03-05 17:14:05 -0700465 const char *abs = srcReg->Abs ? "|" : "";
466
467 _mesa_fprintf(f, "%s%s%s%s",
468 abs,
Brian Paulb4026d92009-03-07 12:02:52 -0700469 reg_string((gl_register_file) srcReg->File,
Brian Pauld0038932009-01-22 10:34:43 -0700470 srcReg->Index, mode, srcReg->RelAddr, prog),
471 _mesa_swizzle_string(srcReg->Swizzle,
Brian Paul7db7ff82009-04-14 22:14:30 -0600472 srcReg->Negate, GL_FALSE),
Brian Paulf787baf2009-03-05 17:14:05 -0700473 abs);
Brian501ee872007-02-17 09:15:00 -0700474#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700475 _mesa_fprintf(f, "%s[%d]%s",
Brian Paulb4026d92009-03-07 12:02:52 -0700476 file_string((gl_register_file) srcReg->File, mode),
Brian Pauld0038932009-01-22 10:34:43 -0700477 srcReg->Index,
478 _mesa_swizzle_string(srcReg->Swizzle,
Brian Paul7db7ff82009-04-14 22:14:30 -0600479 srcReg->Negate, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700480#endif
Brian00cdc0a2006-12-14 15:01:06 -0700481}
482
Brian Pauld0038932009-01-22 10:34:43 -0700483
Brian00cdc0a2006-12-14 15:01:06 -0700484static void
Brian Pauld0038932009-01-22 10:34:43 -0700485fprint_comment(FILE *f, const struct prog_instruction *inst)
Brian00cdc0a2006-12-14 15:01:06 -0700486{
487 if (inst->Comment)
Brian Pauld0038932009-01-22 10:34:43 -0700488 _mesa_fprintf(f, "; # %s\n", inst->Comment);
Brian00cdc0a2006-12-14 15:01:06 -0700489 else
Brian Pauld0038932009-01-22 10:34:43 -0700490 _mesa_fprintf(f, ";\n");
Brian00cdc0a2006-12-14 15:01:06 -0700491}
492
493
Brian501ee872007-02-17 09:15:00 -0700494static void
Brian Pauld0038932009-01-22 10:34:43 -0700495fprint_alu_instruction(FILE *f,
496 const struct prog_instruction *inst,
497 const char *opcode_string, GLuint numRegs,
498 gl_prog_print_mode mode,
499 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700500{
501 GLuint j;
502
Brian Pauld0038932009-01-22 10:34:43 -0700503 _mesa_fprintf(f, "%s", opcode_string);
Brianb50280e2006-12-18 16:21:58 -0700504 if (inst->CondUpdate)
Brian Pauld0038932009-01-22 10:34:43 -0700505 _mesa_fprintf(f, ".C");
Brian00cdc0a2006-12-14 15:01:06 -0700506
507 /* frag prog only */
508 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700509 _mesa_fprintf(f, "_SAT");
Brian00cdc0a2006-12-14 15:01:06 -0700510
Brian Pauld0038932009-01-22 10:34:43 -0700511 _mesa_fprintf(f, " ");
Brian00cdc0a2006-12-14 15:01:06 -0700512 if (inst->DstReg.File != PROGRAM_UNDEFINED) {
Brian Pauld0038932009-01-22 10:34:43 -0700513 fprint_dst_reg(f, &inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700514 }
515 else {
Brian Pauld0038932009-01-22 10:34:43 -0700516 _mesa_fprintf(f, " ???");
Brian00cdc0a2006-12-14 15:01:06 -0700517 }
518
519 if (numRegs > 0)
Brian Pauld0038932009-01-22 10:34:43 -0700520 _mesa_fprintf(f, ", ");
Brian00cdc0a2006-12-14 15:01:06 -0700521
522 for (j = 0; j < numRegs; j++) {
Brian Pauld0038932009-01-22 10:34:43 -0700523 fprint_src_reg(f, inst->SrcReg + j, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700524 if (j + 1 < numRegs)
Brian Pauld0038932009-01-22 10:34:43 -0700525 _mesa_fprintf(f, ", ");
Brian00cdc0a2006-12-14 15:01:06 -0700526 }
527
Brian Pauld0038932009-01-22 10:34:43 -0700528 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700529}
530
531
Brian501ee872007-02-17 09:15:00 -0700532void
Brian0020d102007-02-23 11:43:44 -0700533_mesa_print_alu_instruction(const struct prog_instruction *inst,
534 const char *opcode_string, GLuint numRegs)
535{
Brian Pauld0038932009-01-22 10:34:43 -0700536 fprint_alu_instruction(stdout, inst, opcode_string,
537 numRegs, PROG_PRINT_DEBUG, NULL);
Brian501ee872007-02-17 09:15:00 -0700538}
539
540
Brian00cdc0a2006-12-14 15:01:06 -0700541/**
542 * Print a single vertex/fragment program instruction.
543 */
Nicolai Hähnle2237d132009-07-23 22:09:11 +0200544GLint
Brian Pauld0038932009-01-22 10:34:43 -0700545_mesa_fprint_instruction_opt(FILE *f,
546 const struct prog_instruction *inst,
547 GLint indent,
Brian501ee872007-02-17 09:15:00 -0700548 gl_prog_print_mode mode,
549 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700550{
Brian7b300532007-02-22 09:08:36 -0700551 GLint i;
Brian5db088d2007-02-05 14:58:15 -0700552
553 if (inst->Opcode == OPCODE_ELSE ||
554 inst->Opcode == OPCODE_ENDIF ||
555 inst->Opcode == OPCODE_ENDLOOP ||
556 inst->Opcode == OPCODE_ENDSUB) {
557 indent -= 3;
558 }
Brian5db088d2007-02-05 14:58:15 -0700559 for (i = 0; i < indent; i++) {
Brian Pauld0038932009-01-22 10:34:43 -0700560 _mesa_fprintf(f, " ");
Brian5db088d2007-02-05 14:58:15 -0700561 }
562
Brian00cdc0a2006-12-14 15:01:06 -0700563 switch (inst->Opcode) {
564 case OPCODE_PRINT:
Brian Pauld0038932009-01-22 10:34:43 -0700565 _mesa_fprintf(f, "PRINT '%s'", inst->Data);
Brian00cdc0a2006-12-14 15:01:06 -0700566 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
Brian Pauld0038932009-01-22 10:34:43 -0700567 _mesa_fprintf(f, ", ");
568 _mesa_fprintf(f, "%s[%d]%s",
Brian Paulb4026d92009-03-07 12:02:52 -0700569 file_string((gl_register_file) inst->SrcReg[0].File,
Brian501ee872007-02-17 09:15:00 -0700570 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700571 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700572 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
Brian Paul7db7ff82009-04-14 22:14:30 -0600573 inst->SrcReg[0].Negate, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700574 }
575 if (inst->Comment)
Brian Pauld0038932009-01-22 10:34:43 -0700576 _mesa_fprintf(f, " # %s", inst->Comment);
577 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700578 break;
579 case OPCODE_SWZ:
Brian Pauld0038932009-01-22 10:34:43 -0700580 _mesa_fprintf(f, "SWZ");
Brian00cdc0a2006-12-14 15:01:06 -0700581 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700582 _mesa_fprintf(f, "_SAT");
583 _mesa_fprintf(f, " ");
584 fprint_dst_reg(f, &inst->DstReg, mode, prog);
585 _mesa_fprintf(f, ", %s[%d], %s",
Brian Paulb4026d92009-03-07 12:02:52 -0700586 file_string((gl_register_file) inst->SrcReg[0].File,
Brian501ee872007-02-17 09:15:00 -0700587 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700588 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700589 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
Brian Paul7db7ff82009-04-14 22:14:30 -0600590 inst->SrcReg[0].Negate, GL_TRUE));
Brian Pauld0038932009-01-22 10:34:43 -0700591 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700592 break;
593 case OPCODE_TEX:
594 case OPCODE_TXP:
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600595 case OPCODE_TXL:
Brian00cdc0a2006-12-14 15:01:06 -0700596 case OPCODE_TXB:
Brian Pauld0038932009-01-22 10:34:43 -0700597 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
Brian00cdc0a2006-12-14 15:01:06 -0700598 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700599 _mesa_fprintf(f, "_SAT");
600 _mesa_fprintf(f, " ");
601 fprint_dst_reg(f, &inst->DstReg, mode, prog);
602 _mesa_fprintf(f, ", ");
603 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
604 _mesa_fprintf(f, ", texture[%d], ", inst->TexSrcUnit);
Brian00cdc0a2006-12-14 15:01:06 -0700605 switch (inst->TexSrcTarget) {
Brian Pauld0038932009-01-22 10:34:43 -0700606 case TEXTURE_1D_INDEX: _mesa_fprintf(f, "1D"); break;
607 case TEXTURE_2D_INDEX: _mesa_fprintf(f, "2D"); break;
608 case TEXTURE_3D_INDEX: _mesa_fprintf(f, "3D"); break;
609 case TEXTURE_CUBE_INDEX: _mesa_fprintf(f, "CUBE"); break;
610 case TEXTURE_RECT_INDEX: _mesa_fprintf(f, "RECT"); break;
Brian00cdc0a2006-12-14 15:01:06 -0700611 default:
612 ;
613 }
Brian Paul44e018c2009-02-20 13:42:08 -0700614 if (inst->TexShadow)
615 _mesa_fprintf(f, " SHADOW");
Brian Pauld0038932009-01-22 10:34:43 -0700616 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700617 break;
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600618
619 case OPCODE_KIL:
Brian Pauld0038932009-01-22 10:34:43 -0700620 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
621 _mesa_fprintf(f, " ");
622 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
623 fprint_comment(f, inst);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600624 break;
625 case OPCODE_KIL_NV:
Brian Pauld0038932009-01-22 10:34:43 -0700626 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
627 _mesa_fprintf(f, " ");
628 _mesa_fprintf(f, "%s.%s",
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600629 _mesa_condcode_string(inst->DstReg.CondMask),
630 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
631 GL_FALSE, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700632 fprint_comment(f, inst);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600633 break;
634
Brian00cdc0a2006-12-14 15:01:06 -0700635 case OPCODE_ARL:
Brian Pauld0038932009-01-22 10:34:43 -0700636 _mesa_fprintf(f, "ARL ");
637 fprint_dst_reg(f, &inst->DstReg, mode, prog);
638 _mesa_fprintf(f, ", ");
639 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
640 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700641 break;
642 case OPCODE_BRA:
Brian Pauld0038932009-01-22 10:34:43 -0700643 _mesa_fprintf(f, "BRA %d (%s%s)",
Brian3a281532006-12-16 12:51:34 -0700644 inst->BranchTarget,
Briand7508612007-03-28 11:01:09 -0600645 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700646 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700647 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700648 break;
Brian5ae49cf2007-01-20 09:27:40 -0700649 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600650 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
651 /* Use ordinary register */
Brian Pauld0038932009-01-22 10:34:43 -0700652 _mesa_fprintf(f, "IF ");
653 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
654 _mesa_fprintf(f, "; ");
Brian63556fa2007-03-23 14:47:46 -0600655 }
656 else {
657 /* Use cond codes */
Brian Pauld0038932009-01-22 10:34:43 -0700658 _mesa_fprintf(f, "IF (%s%s);",
Briand7508612007-03-28 11:01:09 -0600659 _mesa_condcode_string(inst->DstReg.CondMask),
Brian63556fa2007-03-23 14:47:46 -0600660 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
661 0, GL_FALSE));
662 }
Brian Pauld0038932009-01-22 10:34:43 -0700663 _mesa_fprintf(f, " # (if false, goto %d)", inst->BranchTarget);
664 fprint_comment(f, inst);
Brian5db088d2007-02-05 14:58:15 -0700665 return indent + 3;
666 case OPCODE_ELSE:
Brian Pauld0038932009-01-22 10:34:43 -0700667 _mesa_fprintf(f, "ELSE; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700668 return indent + 3;
669 case OPCODE_ENDIF:
Brian Pauld0038932009-01-22 10:34:43 -0700670 _mesa_fprintf(f, "ENDIF;\n");
Brian5db088d2007-02-05 14:58:15 -0700671 break;
672 case OPCODE_BGNLOOP:
Brian Pauld0038932009-01-22 10:34:43 -0700673 _mesa_fprintf(f, "BGNLOOP; # (end at %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700674 return indent + 3;
675 case OPCODE_ENDLOOP:
Brian Pauld0038932009-01-22 10:34:43 -0700676 _mesa_fprintf(f, "ENDLOOP; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700677 break;
678 case OPCODE_BRK:
Brianf22ed092007-02-06 22:31:19 -0700679 case OPCODE_CONT:
Brian Pauld0038932009-01-22 10:34:43 -0700680 _mesa_fprintf(f, "%s (%s%s); # (goto %d)",
Brian81767ee2007-03-23 17:45:53 -0600681 _mesa_opcode_string(inst->Opcode),
Briand7508612007-03-28 11:01:09 -0600682 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700683 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
Brian2755c792007-02-05 18:01:02 -0700684 inst->BranchTarget);
Brian Pauld0038932009-01-22 10:34:43 -0700685 fprint_comment(f, inst);
Brian5ae49cf2007-01-20 09:27:40 -0700686 break;
Brian63556fa2007-03-23 14:47:46 -0600687
Brian5db088d2007-02-05 14:58:15 -0700688 case OPCODE_BGNSUB:
Brianf407cad2007-03-27 14:53:17 -0600689 if (mode == PROG_PRINT_NV) {
Brian Pauld0038932009-01-22 10:34:43 -0700690 _mesa_fprintf(f, "%s:\n", inst->Comment); /* comment is label */
Brianf407cad2007-03-27 14:53:17 -0600691 return indent;
692 }
693 else {
Brian Pauld0038932009-01-22 10:34:43 -0700694 _mesa_fprintf(f, "BGNSUB");
695 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600696 return indent + 3;
697 }
Brian5db088d2007-02-05 14:58:15 -0700698 case OPCODE_ENDSUB:
Brianf407cad2007-03-27 14:53:17 -0600699 if (mode == PROG_PRINT_DEBUG) {
Brian Pauld0038932009-01-22 10:34:43 -0700700 _mesa_fprintf(f, "ENDSUB");
701 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600702 }
703 break;
704 case OPCODE_CAL:
705 if (mode == PROG_PRINT_NV) {
Brian Pauld0038932009-01-22 10:34:43 -0700706 _mesa_fprintf(f, "CAL %s; # (goto %d)\n", inst->Comment, inst->BranchTarget);
Brianf407cad2007-03-27 14:53:17 -0600707 }
708 else {
Brian Pauld0038932009-01-22 10:34:43 -0700709 _mesa_fprintf(f, "CAL %u", inst->BranchTarget);
710 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600711 }
712 break;
713 case OPCODE_RET:
Brian Pauld0038932009-01-22 10:34:43 -0700714 _mesa_fprintf(f, "RET (%s%s)",
Briand7508612007-03-28 11:01:09 -0600715 _mesa_condcode_string(inst->DstReg.CondMask),
716 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700717 fprint_comment(f, inst);
Brian5ae49cf2007-01-20 09:27:40 -0700718 break;
Brianf407cad2007-03-27 14:53:17 -0600719
Brian00cdc0a2006-12-14 15:01:06 -0700720 case OPCODE_END:
Brian Pauld0038932009-01-22 10:34:43 -0700721 _mesa_fprintf(f, "END\n");
Brian00cdc0a2006-12-14 15:01:06 -0700722 break;
Brian3a281532006-12-16 12:51:34 -0700723 case OPCODE_NOP:
Brian059376c2007-02-22 17:45:32 -0700724 if (mode == PROG_PRINT_DEBUG) {
Brian Pauld0038932009-01-22 10:34:43 -0700725 _mesa_fprintf(f, "NOP");
726 fprint_comment(f, inst);
Brian059376c2007-02-22 17:45:32 -0700727 }
728 else if (inst->Comment) {
729 /* ARB/NV extensions don't have NOP instruction */
Brian Pauld0038932009-01-22 10:34:43 -0700730 _mesa_fprintf(f, "# %s\n", inst->Comment);
Brian059376c2007-02-22 17:45:32 -0700731 }
Brian3a281532006-12-16 12:51:34 -0700732 break;
Brian00cdc0a2006-12-14 15:01:06 -0700733 /* XXX may need other special-case instructions */
734 default:
Brian Paulf787baf2009-03-05 17:14:05 -0700735 if (inst->Opcode < MAX_OPCODE) {
736 /* typical alu instruction */
737 fprint_alu_instruction(f, inst,
738 _mesa_opcode_string(inst->Opcode),
739 _mesa_num_inst_src_regs(inst->Opcode),
740 mode, prog);
741 }
742 else {
Brian Paul7c2fe422009-05-11 09:38:32 -0600743 fprint_alu_instruction(f, inst,
744 _mesa_opcode_string(inst->Opcode),
745 3/*_mesa_num_inst_src_regs(inst->Opcode)*/,
746 mode, prog);
Brian Paulf787baf2009-03-05 17:14:05 -0700747 }
Brian00cdc0a2006-12-14 15:01:06 -0700748 break;
749 }
Brian5db088d2007-02-05 14:58:15 -0700750 return indent;
Brian00cdc0a2006-12-14 15:01:06 -0700751}
752
753
Brian Pauld0038932009-01-22 10:34:43 -0700754GLint
755_mesa_print_instruction_opt(const struct prog_instruction *inst,
756 GLint indent,
757 gl_prog_print_mode mode,
758 const struct gl_program *prog)
759{
760 return _mesa_fprint_instruction_opt(stdout, inst, indent, mode, prog);
761}
762
763
764void
765_mesa_print_instruction(const struct prog_instruction *inst)
766{
767 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
768 _mesa_fprint_instruction_opt(stdout, inst, 0, PROG_PRINT_DEBUG, NULL);
769}
770
771
772
773/**
774 * Print program, with options.
775 */
Brian Pauld2eff332009-02-02 12:24:41 -0700776void
Brian Pauld0038932009-01-22 10:34:43 -0700777_mesa_fprint_program_opt(FILE *f,
778 const struct gl_program *prog,
779 gl_prog_print_mode mode,
780 GLboolean lineNumbers)
781{
782 GLuint i, indent = 0;
783
784 switch (prog->Target) {
785 case GL_VERTEX_PROGRAM_ARB:
786 if (mode == PROG_PRINT_ARB)
787 _mesa_fprintf(f, "!!ARBvp1.0\n");
788 else if (mode == PROG_PRINT_NV)
789 _mesa_fprintf(f, "!!VP1.0\n");
790 else
791 _mesa_fprintf(f, "# Vertex Program/Shader\n");
792 break;
793 case GL_FRAGMENT_PROGRAM_ARB:
794 case GL_FRAGMENT_PROGRAM_NV:
795 if (mode == PROG_PRINT_ARB)
796 _mesa_fprintf(f, "!!ARBfp1.0\n");
797 else if (mode == PROG_PRINT_NV)
798 _mesa_fprintf(f, "!!FP1.0\n");
799 else
800 _mesa_fprintf(f, "# Fragment Program/Shader\n");
801 break;
802 }
803
804 for (i = 0; i < prog->NumInstructions; i++) {
805 if (lineNumbers)
806 _mesa_fprintf(f, "%3d: ", i);
807 indent = _mesa_fprint_instruction_opt(f, prog->Instructions + i,
808 indent, mode, prog);
809 }
810}
811
812
Brian00cdc0a2006-12-14 15:01:06 -0700813/**
Brian501ee872007-02-17 09:15:00 -0700814 * Print program to stdout, default options.
Brian00cdc0a2006-12-14 15:01:06 -0700815 */
816void
817_mesa_print_program(const struct gl_program *prog)
818{
Brian Pauld0038932009-01-22 10:34:43 -0700819 _mesa_fprint_program_opt(stdout, prog, PROG_PRINT_DEBUG, GL_TRUE);
Brian501ee872007-02-17 09:15:00 -0700820}
821
822
823/**
Brian Pauld0038932009-01-22 10:34:43 -0700824 * Print all of a program's parameters/fields to given file.
Brian501ee872007-02-17 09:15:00 -0700825 */
Brian Pauld0038932009-01-22 10:34:43 -0700826static void
827_mesa_fprint_program_parameters(FILE *f,
828 GLcontext *ctx,
829 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700830{
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600831 GLuint i;
832
Brian Pauld0038932009-01-22 10:34:43 -0700833 _mesa_fprintf(f, "InputsRead: 0x%x\n", prog->InputsRead);
834 _mesa_fprintf(f, "OutputsWritten: 0x%x\n", prog->OutputsWritten);
835 _mesa_fprintf(f, "NumInstructions=%d\n", prog->NumInstructions);
836 _mesa_fprintf(f, "NumTemporaries=%d\n", prog->NumTemporaries);
837 _mesa_fprintf(f, "NumParameters=%d\n", prog->NumParameters);
838 _mesa_fprintf(f, "NumAttributes=%d\n", prog->NumAttributes);
839 _mesa_fprintf(f, "NumAddressRegs=%d\n", prog->NumAddressRegs);
840 _mesa_fprintf(f, "Samplers=[ ");
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600841 for (i = 0; i < MAX_SAMPLERS; i++) {
Brian Pauld0038932009-01-22 10:34:43 -0700842 _mesa_fprintf(f, "%d ", prog->SamplerUnits[i]);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600843 }
Brian Pauld0038932009-01-22 10:34:43 -0700844 _mesa_fprintf(f, "]\n");
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600845
Brian00cdc0a2006-12-14 15:01:06 -0700846 _mesa_load_state_parameters(ctx, prog->Parameters);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600847
Brian00cdc0a2006-12-14 15:01:06 -0700848#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700849 _mesa_fprintf(f, "Local Params:\n");
Brian00cdc0a2006-12-14 15:01:06 -0700850 for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
851 const GLfloat *p = prog->LocalParams[i];
Brian Pauld0038932009-01-22 10:34:43 -0700852 _mesa_fprintf(f, "%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
Brian00cdc0a2006-12-14 15:01:06 -0700853 }
854#endif
Brian83ca3ff2006-12-20 17:17:38 -0700855 _mesa_print_parameter_list(prog->Parameters);
856}
Brian00cdc0a2006-12-14 15:01:06 -0700857
Brian83ca3ff2006-12-20 17:17:38 -0700858
Brian Pauld0038932009-01-22 10:34:43 -0700859/**
860 * Print all of a program's parameters/fields to stdout.
861 */
Brian83ca3ff2006-12-20 17:17:38 -0700862void
Brian Pauld0038932009-01-22 10:34:43 -0700863_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
864{
865 _mesa_fprint_program_parameters(stdout, ctx, prog);
866}
867
868
869/**
870 * Print a program parameter list to given file.
871 */
872static void
873_mesa_fprint_parameter_list(FILE *f,
874 const struct gl_program_parameter_list *list)
Brian83ca3ff2006-12-20 17:17:38 -0700875{
Brian501ee872007-02-17 09:15:00 -0700876 const gl_prog_print_mode mode = PROG_PRINT_DEBUG;
Brian83ca3ff2006-12-20 17:17:38 -0700877 GLuint i;
Brian501ee872007-02-17 09:15:00 -0700878
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600879 if (!list)
880 return;
881
Brian Pauld0038932009-01-22 10:34:43 -0700882 _mesa_fprintf(f, "param list %p\n", (void *) list);
Brian Paulac1fc3f2009-04-21 14:44:03 -0600883 _mesa_fprintf(f, "dirty state flags: 0x%x\n", list->StateFlags);
Brian83ca3ff2006-12-20 17:17:38 -0700884 for (i = 0; i < list->NumParameters; i++){
885 struct gl_program_parameter *param = list->Parameters + i;
886 const GLfloat *v = list->ParameterValues[i];
Brian Pauld0038932009-01-22 10:34:43 -0700887 _mesa_fprintf(f, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
Brian83ca3ff2006-12-20 17:17:38 -0700888 i, param->Size,
Brian501ee872007-02-17 09:15:00 -0700889 file_string(list->Parameters[i].Type, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700890 param->Name, v[0], v[1], v[2], v[3]);
Brian Paulf490ec92008-11-24 09:04:52 -0700891 if (param->Flags & PROG_PARAM_BIT_CENTROID)
Brian Pauld0038932009-01-22 10:34:43 -0700892 _mesa_fprintf(f, " Centroid");
Brian Paulf490ec92008-11-24 09:04:52 -0700893 if (param->Flags & PROG_PARAM_BIT_INVARIANT)
Brian Pauld0038932009-01-22 10:34:43 -0700894 _mesa_fprintf(f, " Invariant");
Brian Paulf490ec92008-11-24 09:04:52 -0700895 if (param->Flags & PROG_PARAM_BIT_FLAT)
Brian Pauld0038932009-01-22 10:34:43 -0700896 _mesa_fprintf(f, " Flat");
Brian Paulf490ec92008-11-24 09:04:52 -0700897 if (param->Flags & PROG_PARAM_BIT_LINEAR)
Brian Pauld0038932009-01-22 10:34:43 -0700898 _mesa_fprintf(f, " Linear");
899 _mesa_fprintf(f, "\n");
Brian00cdc0a2006-12-14 15:01:06 -0700900 }
901}
Brian Pauld0038932009-01-22 10:34:43 -0700902
903
904/**
905 * Print a program parameter list to stdout.
906 */
907void
908_mesa_print_parameter_list(const struct gl_program_parameter_list *list)
909{
910 _mesa_fprint_parameter_list(stdout, list);
911}
912
913
914/**
915 * Write shader and associated info to a file.
916 */
917void
918_mesa_write_shader_to_file(const struct gl_shader *shader)
919{
920 const char *type;
921 char filename[100];
922 FILE *f;
923
924 if (shader->Type == GL_FRAGMENT_SHADER)
925 type = "frag";
926 else
927 type = "vert";
928
Brian Paul3c1ce2d2009-03-10 10:16:37 -0600929 _mesa_snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type);
Brian Pauld0038932009-01-22 10:34:43 -0700930 f = fopen(filename, "w");
931 if (!f) {
932 fprintf(stderr, "Unable to open %s for writing\n", filename);
933 return;
934 }
935
936 fprintf(f, "/* Shader %u source */\n", shader->Name);
937 fputs(shader->Source, f);
938 fprintf(f, "\n");
939
940 fprintf(f, "/* Compile status: %s */\n",
941 shader->CompileStatus ? "ok" : "fail");
942 if (!shader->CompileStatus) {
943 fprintf(f, "/* Log Info: */\n");
944 fputs(shader->InfoLog, f);
945 }
946 else {
947 fprintf(f, "/* GPU code */\n");
Brian Paul6ce0c6e2009-02-06 10:20:33 -0700948 fprintf(f, "/*\n");
Brian Pauld0038932009-01-22 10:34:43 -0700949 _mesa_fprint_program_opt(f, shader->Program, PROG_PRINT_DEBUG, GL_TRUE);
Brian Paul6ce0c6e2009-02-06 10:20:33 -0700950 fprintf(f, "*/\n");
Brian Paulf95c0c02009-05-04 11:14:35 -0600951 fprintf(f, "/* Parameters / constants */\n");
952 fprintf(f, "/*\n");
953 _mesa_fprint_parameter_list(f, shader->Program->Parameters);
954 fprintf(f, "*/\n");
Brian Pauld0038932009-01-22 10:34:43 -0700955 }
956
957 fclose(f);
958}
959
960