blob: 9967f2978de819be589ee71a45020ab56a256c51 [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:
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.
Vinson Lee1eee1ba2009-03-17 09:34:30 -0600216 * \param f the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
Brian501ee872007-02-17 09:15:00 -0700217 * \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 *
Brian Paulb4026d92009-03-07 12:02:52 -0700222reg_string(gl_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 *
Brian Paul7db7ff82009-04-14 22:14:30 -0600328_mesa_swizzle_string(GLuint swizzle, GLuint negateMask, 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
Brian Paul7db7ff82009-04-14 22:14:30 -0600334 if (!extended && swizzle == SWIZZLE_NOOP && negateMask == 0)
Brian00cdc0a2006-12-14 15:01:06 -0700335 return ""; /* no swizzle/negation */
336
337 if (!extended)
338 s[i++] = '.';
339
Brian Paul7db7ff82009-04-14 22:14:30 -0600340 if (negateMask & 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 Paul7db7ff82009-04-14 22:14:30 -0600348 if (negateMask & 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 Paul7db7ff82009-04-14 22:14:30 -0600356 if (negateMask & 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 Paul7db7ff82009-04-14 22:14:30 -0600364 if (negateMask & 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",
Brian Paulb4026d92009-03-07 12:02:52 -0700435 reg_string((gl_register_file) dstReg->File,
Brian Pauld0038932009-01-22 10:34:43 -0700436 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",
Brian Paulb4026d92009-03-07 12:02:52 -0700448 file_string((gl_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 Paulf787baf2009-03-05 17:14:05 -0700461 const char *abs = srcReg->Abs ? "|" : "";
462
463 _mesa_fprintf(f, "%s%s%s%s",
464 abs,
Brian Paulb4026d92009-03-07 12:02:52 -0700465 reg_string((gl_register_file) srcReg->File,
Brian Pauld0038932009-01-22 10:34:43 -0700466 srcReg->Index, mode, srcReg->RelAddr, prog),
467 _mesa_swizzle_string(srcReg->Swizzle,
Brian Paul7db7ff82009-04-14 22:14:30 -0600468 srcReg->Negate, GL_FALSE),
Brian Paulf787baf2009-03-05 17:14:05 -0700469 abs);
Brian501ee872007-02-17 09:15:00 -0700470#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700471 _mesa_fprintf(f, "%s[%d]%s",
Brian Paulb4026d92009-03-07 12:02:52 -0700472 file_string((gl_register_file) srcReg->File, mode),
Brian Pauld0038932009-01-22 10:34:43 -0700473 srcReg->Index,
474 _mesa_swizzle_string(srcReg->Swizzle,
Brian Paul7db7ff82009-04-14 22:14:30 -0600475 srcReg->Negate, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700476#endif
Brian00cdc0a2006-12-14 15:01:06 -0700477}
478
Brian Pauld0038932009-01-22 10:34:43 -0700479
Brian00cdc0a2006-12-14 15:01:06 -0700480static void
Brian Pauld0038932009-01-22 10:34:43 -0700481fprint_comment(FILE *f, const struct prog_instruction *inst)
Brian00cdc0a2006-12-14 15:01:06 -0700482{
483 if (inst->Comment)
Brian Pauld0038932009-01-22 10:34:43 -0700484 _mesa_fprintf(f, "; # %s\n", inst->Comment);
Brian00cdc0a2006-12-14 15:01:06 -0700485 else
Brian Pauld0038932009-01-22 10:34:43 -0700486 _mesa_fprintf(f, ";\n");
Brian00cdc0a2006-12-14 15:01:06 -0700487}
488
489
Brian501ee872007-02-17 09:15:00 -0700490static void
Brian Pauld0038932009-01-22 10:34:43 -0700491fprint_alu_instruction(FILE *f,
492 const struct prog_instruction *inst,
493 const char *opcode_string, GLuint numRegs,
494 gl_prog_print_mode mode,
495 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700496{
497 GLuint j;
498
Brian Pauld0038932009-01-22 10:34:43 -0700499 _mesa_fprintf(f, "%s", opcode_string);
Brianb50280e2006-12-18 16:21:58 -0700500 if (inst->CondUpdate)
Brian Pauld0038932009-01-22 10:34:43 -0700501 _mesa_fprintf(f, ".C");
Brian00cdc0a2006-12-14 15:01:06 -0700502
503 /* frag prog only */
504 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700505 _mesa_fprintf(f, "_SAT");
Brian00cdc0a2006-12-14 15:01:06 -0700506
Brian Pauld0038932009-01-22 10:34:43 -0700507 _mesa_fprintf(f, " ");
Brian00cdc0a2006-12-14 15:01:06 -0700508 if (inst->DstReg.File != PROGRAM_UNDEFINED) {
Brian Pauld0038932009-01-22 10:34:43 -0700509 fprint_dst_reg(f, &inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700510 }
511 else {
Brian Pauld0038932009-01-22 10:34:43 -0700512 _mesa_fprintf(f, " ???");
Brian00cdc0a2006-12-14 15:01:06 -0700513 }
514
515 if (numRegs > 0)
Brian Pauld0038932009-01-22 10:34:43 -0700516 _mesa_fprintf(f, ", ");
Brian00cdc0a2006-12-14 15:01:06 -0700517
518 for (j = 0; j < numRegs; j++) {
Brian Pauld0038932009-01-22 10:34:43 -0700519 fprint_src_reg(f, inst->SrcReg + j, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700520 if (j + 1 < numRegs)
Brian Pauld0038932009-01-22 10:34:43 -0700521 _mesa_fprintf(f, ", ");
Brian00cdc0a2006-12-14 15:01:06 -0700522 }
523
Brian Pauld0038932009-01-22 10:34:43 -0700524 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700525}
526
527
Brian501ee872007-02-17 09:15:00 -0700528void
Brian0020d102007-02-23 11:43:44 -0700529_mesa_print_alu_instruction(const struct prog_instruction *inst,
530 const char *opcode_string, GLuint numRegs)
531{
Brian Pauld0038932009-01-22 10:34:43 -0700532 fprint_alu_instruction(stdout, inst, opcode_string,
533 numRegs, PROG_PRINT_DEBUG, NULL);
Brian501ee872007-02-17 09:15:00 -0700534}
535
536
Brian00cdc0a2006-12-14 15:01:06 -0700537/**
538 * Print a single vertex/fragment program instruction.
539 */
Brian Pauld0038932009-01-22 10:34:43 -0700540static GLint
541_mesa_fprint_instruction_opt(FILE *f,
542 const struct prog_instruction *inst,
543 GLint indent,
Brian501ee872007-02-17 09:15:00 -0700544 gl_prog_print_mode mode,
545 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700546{
Brian7b300532007-02-22 09:08:36 -0700547 GLint i;
Brian5db088d2007-02-05 14:58:15 -0700548
549 if (inst->Opcode == OPCODE_ELSE ||
550 inst->Opcode == OPCODE_ENDIF ||
551 inst->Opcode == OPCODE_ENDLOOP ||
552 inst->Opcode == OPCODE_ENDSUB) {
553 indent -= 3;
554 }
Brian5db088d2007-02-05 14:58:15 -0700555 for (i = 0; i < indent; i++) {
Brian Pauld0038932009-01-22 10:34:43 -0700556 _mesa_fprintf(f, " ");
Brian5db088d2007-02-05 14:58:15 -0700557 }
558
Brian00cdc0a2006-12-14 15:01:06 -0700559 switch (inst->Opcode) {
560 case OPCODE_PRINT:
Brian Pauld0038932009-01-22 10:34:43 -0700561 _mesa_fprintf(f, "PRINT '%s'", inst->Data);
Brian00cdc0a2006-12-14 15:01:06 -0700562 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
Brian Pauld0038932009-01-22 10:34:43 -0700563 _mesa_fprintf(f, ", ");
564 _mesa_fprintf(f, "%s[%d]%s",
Brian Paulb4026d92009-03-07 12:02:52 -0700565 file_string((gl_register_file) inst->SrcReg[0].File,
Brian501ee872007-02-17 09:15:00 -0700566 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700567 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700568 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
Brian Paul7db7ff82009-04-14 22:14:30 -0600569 inst->SrcReg[0].Negate, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700570 }
571 if (inst->Comment)
Brian Pauld0038932009-01-22 10:34:43 -0700572 _mesa_fprintf(f, " # %s", inst->Comment);
573 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700574 break;
575 case OPCODE_SWZ:
Brian Pauld0038932009-01-22 10:34:43 -0700576 _mesa_fprintf(f, "SWZ");
Brian00cdc0a2006-12-14 15:01:06 -0700577 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700578 _mesa_fprintf(f, "_SAT");
579 _mesa_fprintf(f, " ");
580 fprint_dst_reg(f, &inst->DstReg, mode, prog);
581 _mesa_fprintf(f, ", %s[%d], %s",
Brian Paulb4026d92009-03-07 12:02:52 -0700582 file_string((gl_register_file) inst->SrcReg[0].File,
Brian501ee872007-02-17 09:15:00 -0700583 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700584 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700585 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
Brian Paul7db7ff82009-04-14 22:14:30 -0600586 inst->SrcReg[0].Negate, GL_TRUE));
Brian Pauld0038932009-01-22 10:34:43 -0700587 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700588 break;
589 case OPCODE_TEX:
590 case OPCODE_TXP:
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600591 case OPCODE_TXL:
Brian00cdc0a2006-12-14 15:01:06 -0700592 case OPCODE_TXB:
Brian Pauld0038932009-01-22 10:34:43 -0700593 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
Brian00cdc0a2006-12-14 15:01:06 -0700594 if (inst->SaturateMode == SATURATE_ZERO_ONE)
Brian Pauld0038932009-01-22 10:34:43 -0700595 _mesa_fprintf(f, "_SAT");
596 _mesa_fprintf(f, " ");
597 fprint_dst_reg(f, &inst->DstReg, mode, prog);
598 _mesa_fprintf(f, ", ");
599 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
600 _mesa_fprintf(f, ", texture[%d], ", inst->TexSrcUnit);
Brian00cdc0a2006-12-14 15:01:06 -0700601 switch (inst->TexSrcTarget) {
Brian Pauld0038932009-01-22 10:34:43 -0700602 case TEXTURE_1D_INDEX: _mesa_fprintf(f, "1D"); break;
603 case TEXTURE_2D_INDEX: _mesa_fprintf(f, "2D"); break;
604 case TEXTURE_3D_INDEX: _mesa_fprintf(f, "3D"); break;
605 case TEXTURE_CUBE_INDEX: _mesa_fprintf(f, "CUBE"); break;
606 case TEXTURE_RECT_INDEX: _mesa_fprintf(f, "RECT"); break;
Brian00cdc0a2006-12-14 15:01:06 -0700607 default:
608 ;
609 }
Brian Paul44e018c2009-02-20 13:42:08 -0700610 if (inst->TexShadow)
611 _mesa_fprintf(f, " SHADOW");
Brian Pauld0038932009-01-22 10:34:43 -0700612 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700613 break;
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600614
615 case OPCODE_KIL:
Brian Pauld0038932009-01-22 10:34:43 -0700616 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
617 _mesa_fprintf(f, " ");
618 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
619 fprint_comment(f, inst);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600620 break;
621 case OPCODE_KIL_NV:
Brian Pauld0038932009-01-22 10:34:43 -0700622 _mesa_fprintf(f, "%s", _mesa_opcode_string(inst->Opcode));
623 _mesa_fprintf(f, " ");
624 _mesa_fprintf(f, "%s.%s",
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600625 _mesa_condcode_string(inst->DstReg.CondMask),
626 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
627 GL_FALSE, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700628 fprint_comment(f, inst);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600629 break;
630
Brian00cdc0a2006-12-14 15:01:06 -0700631 case OPCODE_ARL:
Brian Pauld0038932009-01-22 10:34:43 -0700632 _mesa_fprintf(f, "ARL ");
633 fprint_dst_reg(f, &inst->DstReg, mode, prog);
634 _mesa_fprintf(f, ", ");
635 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
636 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700637 break;
638 case OPCODE_BRA:
Brian Pauld0038932009-01-22 10:34:43 -0700639 _mesa_fprintf(f, "BRA %d (%s%s)",
Brian3a281532006-12-16 12:51:34 -0700640 inst->BranchTarget,
Briand7508612007-03-28 11:01:09 -0600641 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700642 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700643 fprint_comment(f, inst);
Brian00cdc0a2006-12-14 15:01:06 -0700644 break;
Brian5ae49cf2007-01-20 09:27:40 -0700645 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600646 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
647 /* Use ordinary register */
Brian Pauld0038932009-01-22 10:34:43 -0700648 _mesa_fprintf(f, "IF ");
649 fprint_src_reg(f, &inst->SrcReg[0], mode, prog);
650 _mesa_fprintf(f, "; ");
Brian63556fa2007-03-23 14:47:46 -0600651 }
652 else {
653 /* Use cond codes */
Brian Pauld0038932009-01-22 10:34:43 -0700654 _mesa_fprintf(f, "IF (%s%s);",
Briand7508612007-03-28 11:01:09 -0600655 _mesa_condcode_string(inst->DstReg.CondMask),
Brian63556fa2007-03-23 14:47:46 -0600656 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
657 0, GL_FALSE));
658 }
Brian Pauld0038932009-01-22 10:34:43 -0700659 _mesa_fprintf(f, " # (if false, goto %d)", inst->BranchTarget);
660 fprint_comment(f, inst);
Brian5db088d2007-02-05 14:58:15 -0700661 return indent + 3;
662 case OPCODE_ELSE:
Brian Pauld0038932009-01-22 10:34:43 -0700663 _mesa_fprintf(f, "ELSE; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700664 return indent + 3;
665 case OPCODE_ENDIF:
Brian Pauld0038932009-01-22 10:34:43 -0700666 _mesa_fprintf(f, "ENDIF;\n");
Brian5db088d2007-02-05 14:58:15 -0700667 break;
668 case OPCODE_BGNLOOP:
Brian Pauld0038932009-01-22 10:34:43 -0700669 _mesa_fprintf(f, "BGNLOOP; # (end at %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700670 return indent + 3;
671 case OPCODE_ENDLOOP:
Brian Pauld0038932009-01-22 10:34:43 -0700672 _mesa_fprintf(f, "ENDLOOP; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700673 break;
674 case OPCODE_BRK:
Brianf22ed092007-02-06 22:31:19 -0700675 case OPCODE_CONT:
Brian Pauld0038932009-01-22 10:34:43 -0700676 _mesa_fprintf(f, "%s (%s%s); # (goto %d)",
Brian81767ee2007-03-23 17:45:53 -0600677 _mesa_opcode_string(inst->Opcode),
Briand7508612007-03-28 11:01:09 -0600678 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700679 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
Brian2755c792007-02-05 18:01:02 -0700680 inst->BranchTarget);
Brian Pauld0038932009-01-22 10:34:43 -0700681 fprint_comment(f, inst);
Brian5ae49cf2007-01-20 09:27:40 -0700682 break;
Brian63556fa2007-03-23 14:47:46 -0600683
Brian5db088d2007-02-05 14:58:15 -0700684 case OPCODE_BGNSUB:
Brianf407cad2007-03-27 14:53:17 -0600685 if (mode == PROG_PRINT_NV) {
Brian Pauld0038932009-01-22 10:34:43 -0700686 _mesa_fprintf(f, "%s:\n", inst->Comment); /* comment is label */
Brianf407cad2007-03-27 14:53:17 -0600687 return indent;
688 }
689 else {
Brian Pauld0038932009-01-22 10:34:43 -0700690 _mesa_fprintf(f, "BGNSUB");
691 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600692 return indent + 3;
693 }
Brian5db088d2007-02-05 14:58:15 -0700694 case OPCODE_ENDSUB:
Brianf407cad2007-03-27 14:53:17 -0600695 if (mode == PROG_PRINT_DEBUG) {
Brian Pauld0038932009-01-22 10:34:43 -0700696 _mesa_fprintf(f, "ENDSUB");
697 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600698 }
699 break;
700 case OPCODE_CAL:
701 if (mode == PROG_PRINT_NV) {
Brian Pauld0038932009-01-22 10:34:43 -0700702 _mesa_fprintf(f, "CAL %s; # (goto %d)\n", inst->Comment, inst->BranchTarget);
Brianf407cad2007-03-27 14:53:17 -0600703 }
704 else {
Brian Pauld0038932009-01-22 10:34:43 -0700705 _mesa_fprintf(f, "CAL %u", inst->BranchTarget);
706 fprint_comment(f, inst);
Brianf407cad2007-03-27 14:53:17 -0600707 }
708 break;
709 case OPCODE_RET:
Brian Pauld0038932009-01-22 10:34:43 -0700710 _mesa_fprintf(f, "RET (%s%s)",
Briand7508612007-03-28 11:01:09 -0600711 _mesa_condcode_string(inst->DstReg.CondMask),
712 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian Pauld0038932009-01-22 10:34:43 -0700713 fprint_comment(f, inst);
Brian5ae49cf2007-01-20 09:27:40 -0700714 break;
Brianf407cad2007-03-27 14:53:17 -0600715
Brian00cdc0a2006-12-14 15:01:06 -0700716 case OPCODE_END:
Brian Pauld0038932009-01-22 10:34:43 -0700717 _mesa_fprintf(f, "END\n");
Brian00cdc0a2006-12-14 15:01:06 -0700718 break;
Brian3a281532006-12-16 12:51:34 -0700719 case OPCODE_NOP:
Brian059376c2007-02-22 17:45:32 -0700720 if (mode == PROG_PRINT_DEBUG) {
Brian Pauld0038932009-01-22 10:34:43 -0700721 _mesa_fprintf(f, "NOP");
722 fprint_comment(f, inst);
Brian059376c2007-02-22 17:45:32 -0700723 }
724 else if (inst->Comment) {
725 /* ARB/NV extensions don't have NOP instruction */
Brian Pauld0038932009-01-22 10:34:43 -0700726 _mesa_fprintf(f, "# %s\n", inst->Comment);
Brian059376c2007-02-22 17:45:32 -0700727 }
Brian3a281532006-12-16 12:51:34 -0700728 break;
Brian00cdc0a2006-12-14 15:01:06 -0700729 /* XXX may need other special-case instructions */
730 default:
Brian Paulf787baf2009-03-05 17:14:05 -0700731 if (inst->Opcode < MAX_OPCODE) {
732 /* typical alu instruction */
733 fprint_alu_instruction(f, inst,
734 _mesa_opcode_string(inst->Opcode),
735 _mesa_num_inst_src_regs(inst->Opcode),
736 mode, prog);
737 }
738 else {
739 _mesa_fprintf(f, "Other opcode %d\n", inst->Opcode);
740 }
Brian00cdc0a2006-12-14 15:01:06 -0700741 break;
742 }
Brian5db088d2007-02-05 14:58:15 -0700743 return indent;
Brian00cdc0a2006-12-14 15:01:06 -0700744}
745
746
Brian Pauld0038932009-01-22 10:34:43 -0700747GLint
748_mesa_print_instruction_opt(const struct prog_instruction *inst,
749 GLint indent,
750 gl_prog_print_mode mode,
751 const struct gl_program *prog)
752{
753 return _mesa_fprint_instruction_opt(stdout, inst, indent, mode, prog);
754}
755
756
757void
758_mesa_print_instruction(const struct prog_instruction *inst)
759{
760 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
761 _mesa_fprint_instruction_opt(stdout, inst, 0, PROG_PRINT_DEBUG, NULL);
762}
763
764
765
766/**
767 * Print program, with options.
768 */
Brian Pauld2eff332009-02-02 12:24:41 -0700769void
Brian Pauld0038932009-01-22 10:34:43 -0700770_mesa_fprint_program_opt(FILE *f,
771 const struct gl_program *prog,
772 gl_prog_print_mode mode,
773 GLboolean lineNumbers)
774{
775 GLuint i, indent = 0;
776
777 switch (prog->Target) {
778 case GL_VERTEX_PROGRAM_ARB:
779 if (mode == PROG_PRINT_ARB)
780 _mesa_fprintf(f, "!!ARBvp1.0\n");
781 else if (mode == PROG_PRINT_NV)
782 _mesa_fprintf(f, "!!VP1.0\n");
783 else
784 _mesa_fprintf(f, "# Vertex Program/Shader\n");
785 break;
786 case GL_FRAGMENT_PROGRAM_ARB:
787 case GL_FRAGMENT_PROGRAM_NV:
788 if (mode == PROG_PRINT_ARB)
789 _mesa_fprintf(f, "!!ARBfp1.0\n");
790 else if (mode == PROG_PRINT_NV)
791 _mesa_fprintf(f, "!!FP1.0\n");
792 else
793 _mesa_fprintf(f, "# Fragment Program/Shader\n");
794 break;
795 }
796
797 for (i = 0; i < prog->NumInstructions; i++) {
798 if (lineNumbers)
799 _mesa_fprintf(f, "%3d: ", i);
800 indent = _mesa_fprint_instruction_opt(f, prog->Instructions + i,
801 indent, mode, prog);
802 }
803}
804
805
Brian00cdc0a2006-12-14 15:01:06 -0700806/**
Brian501ee872007-02-17 09:15:00 -0700807 * Print program to stdout, default options.
Brian00cdc0a2006-12-14 15:01:06 -0700808 */
809void
810_mesa_print_program(const struct gl_program *prog)
811{
Brian Pauld0038932009-01-22 10:34:43 -0700812 _mesa_fprint_program_opt(stdout, prog, PROG_PRINT_DEBUG, GL_TRUE);
Brian501ee872007-02-17 09:15:00 -0700813}
814
815
816/**
Brian Pauld0038932009-01-22 10:34:43 -0700817 * Print all of a program's parameters/fields to given file.
Brian501ee872007-02-17 09:15:00 -0700818 */
Brian Pauld0038932009-01-22 10:34:43 -0700819static void
820_mesa_fprint_program_parameters(FILE *f,
821 GLcontext *ctx,
822 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700823{
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600824 GLuint i;
825
Brian Pauld0038932009-01-22 10:34:43 -0700826 _mesa_fprintf(f, "InputsRead: 0x%x\n", prog->InputsRead);
827 _mesa_fprintf(f, "OutputsWritten: 0x%x\n", prog->OutputsWritten);
828 _mesa_fprintf(f, "NumInstructions=%d\n", prog->NumInstructions);
829 _mesa_fprintf(f, "NumTemporaries=%d\n", prog->NumTemporaries);
830 _mesa_fprintf(f, "NumParameters=%d\n", prog->NumParameters);
831 _mesa_fprintf(f, "NumAttributes=%d\n", prog->NumAttributes);
832 _mesa_fprintf(f, "NumAddressRegs=%d\n", prog->NumAddressRegs);
833 _mesa_fprintf(f, "Samplers=[ ");
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600834 for (i = 0; i < MAX_SAMPLERS; i++) {
Brian Pauld0038932009-01-22 10:34:43 -0700835 _mesa_fprintf(f, "%d ", prog->SamplerUnits[i]);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600836 }
Brian Pauld0038932009-01-22 10:34:43 -0700837 _mesa_fprintf(f, "]\n");
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600838
Brian00cdc0a2006-12-14 15:01:06 -0700839 _mesa_load_state_parameters(ctx, prog->Parameters);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600840
Brian00cdc0a2006-12-14 15:01:06 -0700841#if 0
Brian Pauld0038932009-01-22 10:34:43 -0700842 _mesa_fprintf(f, "Local Params:\n");
Brian00cdc0a2006-12-14 15:01:06 -0700843 for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
844 const GLfloat *p = prog->LocalParams[i];
Brian Pauld0038932009-01-22 10:34:43 -0700845 _mesa_fprintf(f, "%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
Brian00cdc0a2006-12-14 15:01:06 -0700846 }
847#endif
Brian83ca3ff2006-12-20 17:17:38 -0700848 _mesa_print_parameter_list(prog->Parameters);
849}
Brian00cdc0a2006-12-14 15:01:06 -0700850
Brian83ca3ff2006-12-20 17:17:38 -0700851
Brian Pauld0038932009-01-22 10:34:43 -0700852/**
853 * Print all of a program's parameters/fields to stdout.
854 */
Brian83ca3ff2006-12-20 17:17:38 -0700855void
Brian Pauld0038932009-01-22 10:34:43 -0700856_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
857{
858 _mesa_fprint_program_parameters(stdout, ctx, prog);
859}
860
861
862/**
863 * Print a program parameter list to given file.
864 */
865static void
866_mesa_fprint_parameter_list(FILE *f,
867 const struct gl_program_parameter_list *list)
Brian83ca3ff2006-12-20 17:17:38 -0700868{
Brian501ee872007-02-17 09:15:00 -0700869 const gl_prog_print_mode mode = PROG_PRINT_DEBUG;
Brian83ca3ff2006-12-20 17:17:38 -0700870 GLuint i;
Brian501ee872007-02-17 09:15:00 -0700871
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600872 if (!list)
873 return;
874
Brian Pauld0038932009-01-22 10:34:43 -0700875 _mesa_fprintf(f, "param list %p\n", (void *) list);
Brian Paulac1fc3f2009-04-21 14:44:03 -0600876 _mesa_fprintf(f, "dirty state flags: 0x%x\n", list->StateFlags);
Brian83ca3ff2006-12-20 17:17:38 -0700877 for (i = 0; i < list->NumParameters; i++){
878 struct gl_program_parameter *param = list->Parameters + i;
879 const GLfloat *v = list->ParameterValues[i];
Brian Pauld0038932009-01-22 10:34:43 -0700880 _mesa_fprintf(f, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
Brian83ca3ff2006-12-20 17:17:38 -0700881 i, param->Size,
Brian501ee872007-02-17 09:15:00 -0700882 file_string(list->Parameters[i].Type, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700883 param->Name, v[0], v[1], v[2], v[3]);
Brian Paulf490ec92008-11-24 09:04:52 -0700884 if (param->Flags & PROG_PARAM_BIT_CENTROID)
Brian Pauld0038932009-01-22 10:34:43 -0700885 _mesa_fprintf(f, " Centroid");
Brian Paulf490ec92008-11-24 09:04:52 -0700886 if (param->Flags & PROG_PARAM_BIT_INVARIANT)
Brian Pauld0038932009-01-22 10:34:43 -0700887 _mesa_fprintf(f, " Invariant");
Brian Paulf490ec92008-11-24 09:04:52 -0700888 if (param->Flags & PROG_PARAM_BIT_FLAT)
Brian Pauld0038932009-01-22 10:34:43 -0700889 _mesa_fprintf(f, " Flat");
Brian Paulf490ec92008-11-24 09:04:52 -0700890 if (param->Flags & PROG_PARAM_BIT_LINEAR)
Brian Pauld0038932009-01-22 10:34:43 -0700891 _mesa_fprintf(f, " Linear");
892 _mesa_fprintf(f, "\n");
Brian00cdc0a2006-12-14 15:01:06 -0700893 }
894}
Brian Pauld0038932009-01-22 10:34:43 -0700895
896
897/**
898 * Print a program parameter list to stdout.
899 */
900void
901_mesa_print_parameter_list(const struct gl_program_parameter_list *list)
902{
903 _mesa_fprint_parameter_list(stdout, list);
904}
905
906
907/**
908 * Write shader and associated info to a file.
909 */
910void
911_mesa_write_shader_to_file(const struct gl_shader *shader)
912{
913 const char *type;
914 char filename[100];
915 FILE *f;
916
917 if (shader->Type == GL_FRAGMENT_SHADER)
918 type = "frag";
919 else
920 type = "vert";
921
Brian Paul3c1ce2d2009-03-10 10:16:37 -0600922 _mesa_snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type);
Brian Pauld0038932009-01-22 10:34:43 -0700923 f = fopen(filename, "w");
924 if (!f) {
925 fprintf(stderr, "Unable to open %s for writing\n", filename);
926 return;
927 }
928
929 fprintf(f, "/* Shader %u source */\n", shader->Name);
930 fputs(shader->Source, f);
931 fprintf(f, "\n");
932
933 fprintf(f, "/* Compile status: %s */\n",
934 shader->CompileStatus ? "ok" : "fail");
935 if (!shader->CompileStatus) {
936 fprintf(f, "/* Log Info: */\n");
937 fputs(shader->InfoLog, f);
938 }
939 else {
940 fprintf(f, "/* GPU code */\n");
Brian Paul6ce0c6e2009-02-06 10:20:33 -0700941 fprintf(f, "/*\n");
Brian Pauld0038932009-01-22 10:34:43 -0700942 _mesa_fprint_program_opt(f, shader->Program, PROG_PRINT_DEBUG, GL_TRUE);
Brian Paul6ce0c6e2009-02-06 10:20:33 -0700943 fprintf(f, "*/\n");
Brian Pauld0038932009-01-22 10:34:43 -0700944 }
945
946 fclose(f);
947}
948
949