blob: ec260f18a9ff3c0eab701af4e2b64b338c98130f [file] [log] [blame]
Brian00cdc0a2006-12-14 15:01:06 -07001/*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
Brian5db088d2007-02-05 14:58:15 -07005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Brian00cdc0a2006-12-14 15:01:06 -07006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25/**
26 * \file prog_print.c
27 * Print vertex/fragment programs - for debugging.
28 * \author Brian Paul
29 */
30
José Fonseca101d1a62008-07-23 21:06:01 +090031#include "main/glheader.h"
32#include "main/context.h"
33#include "main/imports.h"
Brian00cdc0a2006-12-14 15:01:06 -070034#include "prog_instruction.h"
35#include "prog_parameter.h"
36#include "prog_print.h"
37#include "prog_statevars.h"
38
39
Brian501ee872007-02-17 09:15:00 -070040
Brian00cdc0a2006-12-14 15:01:06 -070041/**
42 * Return string name for given program/register file.
43 */
44static const char *
Brian501ee872007-02-17 09:15:00 -070045file_string(enum register_file f, gl_prog_print_mode mode)
Brian00cdc0a2006-12-14 15:01:06 -070046{
47 switch (f) {
48 case PROGRAM_TEMPORARY:
49 return "TEMP";
50 case PROGRAM_LOCAL_PARAM:
51 return "LOCAL";
52 case PROGRAM_ENV_PARAM:
53 return "ENV";
54 case PROGRAM_STATE_VAR:
55 return "STATE";
56 case PROGRAM_INPUT:
57 return "INPUT";
58 case PROGRAM_OUTPUT:
59 return "OUTPUT";
60 case PROGRAM_NAMED_PARAM:
61 return "NAMED";
62 case PROGRAM_CONSTANT:
63 return "CONST";
64 case PROGRAM_UNIFORM:
65 return "UNIFORM";
66 case PROGRAM_VARYING:
67 return "VARYING";
68 case PROGRAM_WRITE_ONLY:
69 return "WRITE_ONLY";
70 case PROGRAM_ADDRESS:
71 return "ADDR";
Brianb2ab6932007-01-05 16:01:43 -070072 case PROGRAM_SAMPLER:
73 return "SAMPLER";
Brian00cdc0a2006-12-14 15:01:06 -070074 default:
75 return "Unknown program file!";
76 }
77}
78
79
80/**
Brian501ee872007-02-17 09:15:00 -070081 * Return ARB_v/f_prog-style input attrib string.
82 */
83static const char *
84arb_input_attrib_string(GLint index, GLenum progType)
85{
86 const char *vertAttribs[] = {
87 "vertex.position",
88 "vertex.weight",
89 "vertex.normal",
90 "vertex.color.primary",
91 "vertex.color.secondary",
92 "vertex.fogcoord",
93 "vertex.(six)",
94 "vertex.(seven)",
95 "vertex.texcoord[0]",
96 "vertex.texcoord[1]",
97 "vertex.texcoord[2]",
98 "vertex.texcoord[3]",
99 "vertex.texcoord[4]",
100 "vertex.texcoord[5]",
101 "vertex.texcoord[6]",
Brian Paula0bfeb02008-05-18 15:46:58 -0600102 "vertex.texcoord[7]",
103 "vertex.attrib[0]",
104 "vertex.attrib[1]",
105 "vertex.attrib[2]",
106 "vertex.attrib[3]",
107 "vertex.attrib[4]",
108 "vertex.attrib[5]",
109 "vertex.attrib[6]",
110 "vertex.attrib[7]",
111 "vertex.attrib[8]",
112 "vertex.attrib[9]",
113 "vertex.attrib[10]",
114 "vertex.attrib[11]",
115 "vertex.attrib[12]",
116 "vertex.attrib[13]",
117 "vertex.attrib[14]",
118 "vertex.attrib[15]"
Brian501ee872007-02-17 09:15:00 -0700119 };
120 const char *fragAttribs[] = {
121 "fragment.position",
122 "fragment.color.primary",
123 "fragment.color.secondary",
124 "fragment.fogcoord",
125 "fragment.texcoord[0]",
126 "fragment.texcoord[1]",
127 "fragment.texcoord[2]",
128 "fragment.texcoord[3]",
129 "fragment.texcoord[4]",
130 "fragment.texcoord[5]",
131 "fragment.texcoord[6]",
132 "fragment.texcoord[7]",
133 "fragment.varying[0]",
134 "fragment.varying[1]",
135 "fragment.varying[2]",
136 "fragment.varying[3]",
137 "fragment.varying[4]",
138 "fragment.varying[5]",
139 "fragment.varying[6]",
140 "fragment.varying[7]"
141 };
142
143 if (progType == GL_VERTEX_PROGRAM_ARB) {
144 assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0]));
145 return vertAttribs[index];
146 }
147 else {
148 assert(index < sizeof(fragAttribs) / sizeof(fragAttribs[0]));
149 return fragAttribs[index];
150 }
151}
152
153
154/**
155 * Return ARB_v/f_prog-style output attrib string.
156 */
157static const char *
158arb_output_attrib_string(GLint index, GLenum progType)
159{
160 const char *vertResults[] = {
161 "result.position",
162 "result.color.primary",
163 "result.color.secondary",
164 "result.fogcoord",
165 "result.texcoord[0]",
166 "result.texcoord[1]",
167 "result.texcoord[2]",
168 "result.texcoord[3]",
169 "result.texcoord[4]",
170 "result.texcoord[5]",
171 "result.texcoord[6]",
172 "result.texcoord[7]",
173 "result.varying[0]",
174 "result.varying[1]",
175 "result.varying[2]",
176 "result.varying[3]",
177 "result.varying[4]",
178 "result.varying[5]",
179 "result.varying[6]",
180 "result.varying[7]"
181 };
182 const char *fragResults[] = {
183 "result.color",
184 "result.depth"
185 };
186
187 if (progType == GL_VERTEX_PROGRAM_ARB) {
188 assert(index < sizeof(vertResults) / sizeof(vertResults[0]));
189 return vertResults[index];
190 }
191 else {
192 assert(index < sizeof(fragResults) / sizeof(fragResults[0]));
193 return fragResults[index];
194 }
195}
196
197
198/**
199 * Return string representation of the given register.
200 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
201 * by the ARB/NV program languages so we've taken some liberties here.
202 * \param file the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
203 * \param index number of the register in the register file
204 * \param mode the output format/mode/style
205 * \param prog pointer to containing program
206 */
207static const char *
208reg_string(enum register_file f, GLint index, gl_prog_print_mode mode,
Zack Rusin494c40d2008-06-12 14:19:10 -0400209 GLboolean relAddr, const struct gl_program *prog)
Brian501ee872007-02-17 09:15:00 -0700210{
211 static char str[100];
212
213 str[0] = 0;
214
215 switch (mode) {
216 case PROG_PRINT_DEBUG:
Zack Rusin68ef8e82008-06-10 16:59:44 -0400217 if (relAddr)
218 sprintf(str, "%s[ADDR%s%d]", file_string(f, mode), (index > 0) ? "+" : "", index);
219 else
220 sprintf(str, "%s[%d]", file_string(f, mode), index);
Brian501ee872007-02-17 09:15:00 -0700221 break;
222
223 case PROG_PRINT_ARB:
224 switch (f) {
225 case PROGRAM_INPUT:
226 sprintf(str, "%s", arb_input_attrib_string(index, prog->Target));
227 break;
228 case PROGRAM_OUTPUT:
229 sprintf(str, "%s", arb_output_attrib_string(index, prog->Target));
230 break;
231 case PROGRAM_TEMPORARY:
232 sprintf(str, "temp%d", index);
233 break;
234 case PROGRAM_ENV_PARAM:
235 sprintf(str, "program.env[%d]", index);
236 break;
237 case PROGRAM_LOCAL_PARAM:
238 sprintf(str, "program.local[%d]", index);
239 break;
240 case PROGRAM_VARYING: /* extension */
241 sprintf(str, "varying[%d]", index);
242 break;
243 case PROGRAM_CONSTANT: /* extension */
244 sprintf(str, "constant[%d]", index);
245 break;
246 case PROGRAM_UNIFORM: /* extension */
247 sprintf(str, "uniform[%d]", index);
248 break;
249 case PROGRAM_STATE_VAR:
250 {
251 struct gl_program_parameter *param
252 = prog->Parameters->Parameters + index;
Brian Paul9a644402008-09-04 15:05:03 -0600253 char *state = _mesa_program_state_string(param->StateIndexes);
254 sprintf(str, state);
255 _mesa_free(state);
Brian501ee872007-02-17 09:15:00 -0700256 }
257 break;
258 case PROGRAM_ADDRESS:
259 sprintf(str, "A%d", index);
260 break;
261 default:
262 _mesa_problem(NULL, "bad file in reg_string()");
263 }
264 break;
265
266 case PROG_PRINT_NV:
267 switch (f) {
268 case PROGRAM_INPUT:
269 if (prog->Target == GL_VERTEX_PROGRAM_ARB)
270 sprintf(str, "v[%d]", index);
271 else
272 sprintf(str, "f[%d]", index);
273 break;
274 case PROGRAM_OUTPUT:
275 sprintf(str, "o[%d]", index);
276 break;
277 case PROGRAM_TEMPORARY:
278 sprintf(str, "R%d", index);
279 break;
280 case PROGRAM_ENV_PARAM:
281 sprintf(str, "c[%d]", index);
282 break;
283 case PROGRAM_VARYING: /* extension */
284 sprintf(str, "varying[%d]", index);
285 break;
286 case PROGRAM_UNIFORM: /* extension */
287 sprintf(str, "uniform[%d]", index);
288 break;
289 case PROGRAM_CONSTANT: /* extension */
290 sprintf(str, "constant[%d]", index);
291 break;
292 case PROGRAM_STATE_VAR: /* extension */
293 sprintf(str, "state[%d]", index);
294 break;
295 default:
296 _mesa_problem(NULL, "bad file in reg_string()");
297 }
298 break;
299
300 default:
301 _mesa_problem(NULL, "bad mode in reg_string()");
302 }
303
304 return str;
305}
306
307
308/**
Brian00cdc0a2006-12-14 15:01:06 -0700309 * Return a string representation of the given swizzle word.
310 * If extended is true, use extended (comma-separated) format.
Brian3a281532006-12-16 12:51:34 -0700311 * \param swizzle the swizzle field
312 * \param negateBase 4-bit negation vector
313 * \param extended if true, also allow 0, 1 values
Brian00cdc0a2006-12-14 15:01:06 -0700314 */
Brian059376c2007-02-22 17:45:32 -0700315const char *
316_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended)
Brian00cdc0a2006-12-14 15:01:06 -0700317{
Brian Paul72e57b52008-07-18 19:46:19 -0600318 static const char swz[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
Brian00cdc0a2006-12-14 15:01:06 -0700319 static char s[20];
320 GLuint i = 0;
321
322 if (!extended && swizzle == SWIZZLE_NOOP && negateBase == 0)
323 return ""; /* no swizzle/negation */
324
325 if (!extended)
326 s[i++] = '.';
327
Brian5ea37f52008-01-16 16:43:50 -0700328 if (negateBase & NEGATE_X)
Brian00cdc0a2006-12-14 15:01:06 -0700329 s[i++] = '-';
330 s[i++] = swz[GET_SWZ(swizzle, 0)];
331
332 if (extended) {
333 s[i++] = ',';
334 }
335
Brian5ea37f52008-01-16 16:43:50 -0700336 if (negateBase & NEGATE_Y)
Brian00cdc0a2006-12-14 15:01:06 -0700337 s[i++] = '-';
338 s[i++] = swz[GET_SWZ(swizzle, 1)];
339
340 if (extended) {
341 s[i++] = ',';
342 }
343
Brian5ea37f52008-01-16 16:43:50 -0700344 if (negateBase & NEGATE_Z)
Brian00cdc0a2006-12-14 15:01:06 -0700345 s[i++] = '-';
346 s[i++] = swz[GET_SWZ(swizzle, 2)];
347
348 if (extended) {
349 s[i++] = ',';
350 }
351
Brian5ea37f52008-01-16 16:43:50 -0700352 if (negateBase & NEGATE_W)
Brian00cdc0a2006-12-14 15:01:06 -0700353 s[i++] = '-';
354 s[i++] = swz[GET_SWZ(swizzle, 3)];
355
356 s[i] = 0;
357 return s;
358}
359
360
Brian Paul511733b2008-07-02 12:40:03 -0600361void
362_mesa_print_swizzle(GLuint swizzle)
363{
364 if (swizzle == SWIZZLE_XYZW) {
365 _mesa_printf(".xyzw\n");
366 }
367 else {
Michal Krolf9c574d2008-07-15 11:44:47 +0200368 const char *s = _mesa_swizzle_string(swizzle, 0, 0);
Brian Paul511733b2008-07-02 12:40:03 -0600369 _mesa_printf("%s\n", s);
370 }
371}
372
373
Brian00cdc0a2006-12-14 15:01:06 -0700374static const char *
375writemask_string(GLuint writeMask)
376{
377 static char s[10];
378 GLuint i = 0;
379
380 if (writeMask == WRITEMASK_XYZW)
381 return "";
382
383 s[i++] = '.';
384 if (writeMask & WRITEMASK_X)
385 s[i++] = 'x';
386 if (writeMask & WRITEMASK_Y)
387 s[i++] = 'y';
388 if (writeMask & WRITEMASK_Z)
389 s[i++] = 'z';
390 if (writeMask & WRITEMASK_W)
391 s[i++] = 'w';
392
393 s[i] = 0;
394 return s;
395}
396
Brian3a281532006-12-16 12:51:34 -0700397
Briand7508612007-03-28 11:01:09 -0600398const char *
399_mesa_condcode_string(GLuint condcode)
Brian3a281532006-12-16 12:51:34 -0700400{
401 switch (condcode) {
402 case COND_GT: return "GT";
403 case COND_EQ: return "EQ";
404 case COND_LT: return "LT";
405 case COND_UN: return "UN";
406 case COND_GE: return "GE";
407 case COND_LE: return "LE";
408 case COND_NE: return "NE";
409 case COND_TR: return "TR";
410 case COND_FL: return "FL";
411 default: return "cond???";
412 }
413}
414
415
Brian00cdc0a2006-12-14 15:01:06 -0700416static void
Brian501ee872007-02-17 09:15:00 -0700417print_dst_reg(const struct prog_dst_register *dstReg, gl_prog_print_mode mode,
418 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700419{
Brian501ee872007-02-17 09:15:00 -0700420 _mesa_printf("%s%s",
421 reg_string((enum register_file) dstReg->File,
Zack Rusin68ef8e82008-06-10 16:59:44 -0400422 dstReg->Index, mode, GL_FALSE, prog),
Brian501ee872007-02-17 09:15:00 -0700423 writemask_string(dstReg->WriteMask));
424
Brian1936b252007-03-22 09:04:18 -0600425 if (dstReg->CondMask != COND_TR) {
426 _mesa_printf(" (%s.%s)",
Briand7508612007-03-28 11:01:09 -0600427 _mesa_condcode_string(dstReg->CondMask),
Brian1936b252007-03-22 09:04:18 -0600428 _mesa_swizzle_string(dstReg->CondSwizzle, GL_FALSE, GL_FALSE));
429 }
430
Brian501ee872007-02-17 09:15:00 -0700431#if 0
432 _mesa_printf("%s[%d]%s",
433 file_string((enum register_file) dstReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700434 dstReg->Index,
435 writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700436#endif
Brian00cdc0a2006-12-14 15:01:06 -0700437}
438
439static void
Brian501ee872007-02-17 09:15:00 -0700440print_src_reg(const struct prog_src_register *srcReg, gl_prog_print_mode mode,
441 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700442{
Brian501ee872007-02-17 09:15:00 -0700443 _mesa_printf("%s%s",
444 reg_string((enum register_file) srcReg->File,
Zack Rusin68ef8e82008-06-10 16:59:44 -0400445 srcReg->Index, mode, srcReg->RelAddr, prog),
Brian059376c2007-02-22 17:45:32 -0700446 _mesa_swizzle_string(srcReg->Swizzle,
Zack Rusin68ef8e82008-06-10 16:59:44 -0400447 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700448#if 0
Brian00cdc0a2006-12-14 15:01:06 -0700449 _mesa_printf("%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700450 file_string((enum register_file) srcReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700451 srcReg->Index,
Brian059376c2007-02-22 17:45:32 -0700452 _mesa_swizzle_string(srcReg->Swizzle,
Brian00cdc0a2006-12-14 15:01:06 -0700453 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700454#endif
Brian00cdc0a2006-12-14 15:01:06 -0700455}
456
457static void
458print_comment(const struct prog_instruction *inst)
459{
460 if (inst->Comment)
461 _mesa_printf("; # %s\n", inst->Comment);
462 else
463 _mesa_printf(";\n");
464}
465
466
Brian501ee872007-02-17 09:15:00 -0700467static void
468print_alu_instruction(const struct prog_instruction *inst,
Brian0020d102007-02-23 11:43:44 -0700469 const char *opcode_string, GLuint numRegs,
Brian501ee872007-02-17 09:15:00 -0700470 gl_prog_print_mode mode,
471 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700472{
473 GLuint j;
474
475 _mesa_printf("%s", opcode_string);
Brianb50280e2006-12-18 16:21:58 -0700476 if (inst->CondUpdate)
477 _mesa_printf(".C");
Brian00cdc0a2006-12-14 15:01:06 -0700478
479 /* frag prog only */
480 if (inst->SaturateMode == SATURATE_ZERO_ONE)
481 _mesa_printf("_SAT");
482
Brian501ee872007-02-17 09:15:00 -0700483 _mesa_printf(" ");
Brian00cdc0a2006-12-14 15:01:06 -0700484 if (inst->DstReg.File != PROGRAM_UNDEFINED) {
Brian501ee872007-02-17 09:15:00 -0700485 print_dst_reg(&inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700486 }
487 else {
488 _mesa_printf(" ???");
489 }
490
491 if (numRegs > 0)
492 _mesa_printf(", ");
493
494 for (j = 0; j < numRegs; j++) {
Brian501ee872007-02-17 09:15:00 -0700495 print_src_reg(inst->SrcReg + j, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700496 if (j + 1 < numRegs)
497 _mesa_printf(", ");
498 }
499
Brian00cdc0a2006-12-14 15:01:06 -0700500 print_comment(inst);
501}
502
503
Brian501ee872007-02-17 09:15:00 -0700504void
Brian0020d102007-02-23 11:43:44 -0700505_mesa_print_alu_instruction(const struct prog_instruction *inst,
506 const char *opcode_string, GLuint numRegs)
507{
508 print_alu_instruction(inst, opcode_string, numRegs, PROG_PRINT_DEBUG, NULL);
509}
510
511
512void
Brian501ee872007-02-17 09:15:00 -0700513_mesa_print_instruction(const struct prog_instruction *inst)
514{
515 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
516 _mesa_print_instruction_opt(inst, 0, PROG_PRINT_DEBUG, NULL);
517}
518
519
Brian00cdc0a2006-12-14 15:01:06 -0700520/**
521 * Print a single vertex/fragment program instruction.
522 */
Brian5db088d2007-02-05 14:58:15 -0700523GLint
Brian501ee872007-02-17 09:15:00 -0700524_mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent,
525 gl_prog_print_mode mode,
526 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700527{
Brian7b300532007-02-22 09:08:36 -0700528 GLint i;
Brian5db088d2007-02-05 14:58:15 -0700529
530 if (inst->Opcode == OPCODE_ELSE ||
531 inst->Opcode == OPCODE_ENDIF ||
532 inst->Opcode == OPCODE_ENDLOOP ||
533 inst->Opcode == OPCODE_ENDSUB) {
534 indent -= 3;
535 }
Brian5db088d2007-02-05 14:58:15 -0700536 for (i = 0; i < indent; i++) {
537 _mesa_printf(" ");
538 }
539
Brian00cdc0a2006-12-14 15:01:06 -0700540 switch (inst->Opcode) {
541 case OPCODE_PRINT:
542 _mesa_printf("PRINT '%s'", inst->Data);
543 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
544 _mesa_printf(", ");
545 _mesa_printf("%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700546 file_string((enum register_file) inst->SrcReg[0].File,
547 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700548 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700549 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
550 inst->SrcReg[0].NegateBase, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700551 }
552 if (inst->Comment)
553 _mesa_printf(" # %s", inst->Comment);
554 print_comment(inst);
555 break;
556 case OPCODE_SWZ:
557 _mesa_printf("SWZ");
558 if (inst->SaturateMode == SATURATE_ZERO_ONE)
559 _mesa_printf("_SAT");
Brian501ee872007-02-17 09:15:00 -0700560 _mesa_printf(" ");
561 print_dst_reg(&inst->DstReg, mode, prog);
Brianc1b2b972007-10-30 18:24:54 -0600562 _mesa_printf(", %s[%d], %s",
Brian501ee872007-02-17 09:15:00 -0700563 file_string((enum register_file) inst->SrcReg[0].File,
564 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700565 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700566 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
567 inst->SrcReg[0].NegateBase, GL_TRUE));
Brian00cdc0a2006-12-14 15:01:06 -0700568 print_comment(inst);
569 break;
570 case OPCODE_TEX:
571 case OPCODE_TXP:
Brianc1b2b972007-10-30 18:24:54 -0600572 case OPCODE_TXL:
Brian00cdc0a2006-12-14 15:01:06 -0700573 case OPCODE_TXB:
574 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
575 if (inst->SaturateMode == SATURATE_ZERO_ONE)
576 _mesa_printf("_SAT");
Brian501ee872007-02-17 09:15:00 -0700577 _mesa_printf(" ");
578 print_dst_reg(&inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700579 _mesa_printf(", ");
Brian501ee872007-02-17 09:15:00 -0700580 print_src_reg(&inst->SrcReg[0], mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700581 _mesa_printf(", texture[%d], ", inst->TexSrcUnit);
582 switch (inst->TexSrcTarget) {
583 case TEXTURE_1D_INDEX: _mesa_printf("1D"); break;
584 case TEXTURE_2D_INDEX: _mesa_printf("2D"); break;
585 case TEXTURE_3D_INDEX: _mesa_printf("3D"); break;
586 case TEXTURE_CUBE_INDEX: _mesa_printf("CUBE"); break;
587 case TEXTURE_RECT_INDEX: _mesa_printf("RECT"); break;
588 default:
589 ;
590 }
591 print_comment(inst);
592 break;
Brianc1b2b972007-10-30 18:24:54 -0600593
594 case OPCODE_KIL:
595 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
596 _mesa_printf(" ");
597 print_src_reg(&inst->SrcReg[0], mode, prog);
598 print_comment(inst);
599 break;
600 case OPCODE_KIL_NV:
601 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
602 _mesa_printf(" ");
603 _mesa_printf("%s.%s",
604 _mesa_condcode_string(inst->DstReg.CondMask),
605 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
606 GL_FALSE, GL_FALSE));
607 print_comment(inst);
608 break;
609
Brian00cdc0a2006-12-14 15:01:06 -0700610 case OPCODE_ARL:
Zack Rusin68ef8e82008-06-10 16:59:44 -0400611 _mesa_printf("ARL ");
612 print_dst_reg(&inst->DstReg, mode, prog);
613 _mesa_printf(", ");
Brian501ee872007-02-17 09:15:00 -0700614 print_src_reg(&inst->SrcReg[0], mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700615 print_comment(inst);
616 break;
617 case OPCODE_BRA:
Briand7508612007-03-28 11:01:09 -0600618 _mesa_printf("BRA %d (%s%s)",
Brian3a281532006-12-16 12:51:34 -0700619 inst->BranchTarget,
Briand7508612007-03-28 11:01:09 -0600620 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700621 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700622 print_comment(inst);
623 break;
Brian5ae49cf2007-01-20 09:27:40 -0700624 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600625 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
626 /* Use ordinary register */
627 _mesa_printf("IF ");
628 print_src_reg(&inst->SrcReg[0], mode, prog);
629 _mesa_printf("; ");
630 }
631 else {
632 /* Use cond codes */
633 _mesa_printf("IF (%s%s);",
Briand7508612007-03-28 11:01:09 -0600634 _mesa_condcode_string(inst->DstReg.CondMask),
Brian63556fa2007-03-23 14:47:46 -0600635 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
636 0, GL_FALSE));
637 }
638 _mesa_printf(" # (if false, goto %d)", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700639 print_comment(inst);
640 return indent + 3;
641 case OPCODE_ELSE:
Brian501ee872007-02-17 09:15:00 -0700642 _mesa_printf("ELSE; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700643 return indent + 3;
644 case OPCODE_ENDIF:
Brian501ee872007-02-17 09:15:00 -0700645 _mesa_printf("ENDIF;\n");
Brian5db088d2007-02-05 14:58:15 -0700646 break;
647 case OPCODE_BGNLOOP:
Brian501ee872007-02-17 09:15:00 -0700648 _mesa_printf("BGNLOOP; # (end at %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700649 return indent + 3;
650 case OPCODE_ENDLOOP:
Brian501ee872007-02-17 09:15:00 -0700651 _mesa_printf("ENDLOOP; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700652 break;
653 case OPCODE_BRK:
Brianf22ed092007-02-06 22:31:19 -0700654 case OPCODE_CONT:
Brian81767ee2007-03-23 17:45:53 -0600655 _mesa_printf("%s (%s%s); # (goto %d)",
656 _mesa_opcode_string(inst->Opcode),
Briand7508612007-03-28 11:01:09 -0600657 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700658 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
Brian2755c792007-02-05 18:01:02 -0700659 inst->BranchTarget);
Brian5ae49cf2007-01-20 09:27:40 -0700660 print_comment(inst);
661 break;
Brian63556fa2007-03-23 14:47:46 -0600662
Brian5db088d2007-02-05 14:58:15 -0700663 case OPCODE_BGNSUB:
Brianf407cad2007-03-27 14:53:17 -0600664 if (mode == PROG_PRINT_NV) {
665 _mesa_printf("%s:\n", inst->Comment); /* comment is label */
666 return indent;
667 }
668 else {
669 _mesa_printf("BGNSUB");
670 print_comment(inst);
671 return indent + 3;
672 }
Brian5db088d2007-02-05 14:58:15 -0700673 case OPCODE_ENDSUB:
Brianf407cad2007-03-27 14:53:17 -0600674 if (mode == PROG_PRINT_DEBUG) {
675 _mesa_printf("ENDSUB");
676 print_comment(inst);
677 }
678 break;
679 case OPCODE_CAL:
680 if (mode == PROG_PRINT_NV) {
Briand7508612007-03-28 11:01:09 -0600681 _mesa_printf("CAL %s; # (goto %d)\n", inst->Comment, inst->BranchTarget);
Brianf407cad2007-03-27 14:53:17 -0600682 }
683 else {
684 _mesa_printf("CAL %u", inst->BranchTarget);
685 print_comment(inst);
686 }
687 break;
688 case OPCODE_RET:
Briand7508612007-03-28 11:01:09 -0600689 _mesa_printf("RET (%s%s)",
690 _mesa_condcode_string(inst->DstReg.CondMask),
691 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian5db088d2007-02-05 14:58:15 -0700692 print_comment(inst);
Brian5ae49cf2007-01-20 09:27:40 -0700693 break;
Brianf407cad2007-03-27 14:53:17 -0600694
Brian00cdc0a2006-12-14 15:01:06 -0700695 case OPCODE_END:
Brian501ee872007-02-17 09:15:00 -0700696 _mesa_printf("END\n");
Brian00cdc0a2006-12-14 15:01:06 -0700697 break;
Brian3a281532006-12-16 12:51:34 -0700698 case OPCODE_NOP:
Brian059376c2007-02-22 17:45:32 -0700699 if (mode == PROG_PRINT_DEBUG) {
700 _mesa_printf("NOP");
701 print_comment(inst);
702 }
703 else if (inst->Comment) {
704 /* ARB/NV extensions don't have NOP instruction */
705 _mesa_printf("# %s\n", inst->Comment);
706 }
Brian3a281532006-12-16 12:51:34 -0700707 break;
Brian00cdc0a2006-12-14 15:01:06 -0700708 /* XXX may need other special-case instructions */
709 default:
710 /* typical alu instruction */
Brian501ee872007-02-17 09:15:00 -0700711 print_alu_instruction(inst,
712 _mesa_opcode_string(inst->Opcode),
713 _mesa_num_inst_src_regs(inst->Opcode),
714 mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700715 break;
716 }
Brian5db088d2007-02-05 14:58:15 -0700717 return indent;
Brian00cdc0a2006-12-14 15:01:06 -0700718}
719
720
721/**
Brian501ee872007-02-17 09:15:00 -0700722 * Print program to stdout, default options.
Brian00cdc0a2006-12-14 15:01:06 -0700723 */
724void
725_mesa_print_program(const struct gl_program *prog)
726{
Brian9449a4d2007-02-17 09:41:59 -0700727 _mesa_print_program_opt(prog, PROG_PRINT_DEBUG, GL_TRUE);
Brian501ee872007-02-17 09:15:00 -0700728}
729
730
731/**
732 * Print program, with options.
733 */
734void
735_mesa_print_program_opt(const struct gl_program *prog,
736 gl_prog_print_mode mode,
737 GLboolean lineNumbers)
738{
Brian5db088d2007-02-05 14:58:15 -0700739 GLuint i, indent = 0;
Brian501ee872007-02-17 09:15:00 -0700740
741 switch (prog->Target) {
742 case GL_VERTEX_PROGRAM_ARB:
743 if (mode == PROG_PRINT_ARB)
744 _mesa_printf("!!ARBvp1.0\n");
745 else if (mode == PROG_PRINT_NV)
746 _mesa_printf("!!VP1.0\n");
747 else
748 _mesa_printf("# Vertex Program/Shader\n");
749 break;
750 case GL_FRAGMENT_PROGRAM_ARB:
751 case GL_FRAGMENT_PROGRAM_NV:
752 if (mode == PROG_PRINT_ARB)
753 _mesa_printf("!!ARBfp1.0\n");
754 else if (mode == PROG_PRINT_NV)
755 _mesa_printf("!!FP1.0\n");
756 else
757 _mesa_printf("# Fragment Program/Shader\n");
758 break;
759 }
760
Brian00cdc0a2006-12-14 15:01:06 -0700761 for (i = 0; i < prog->NumInstructions; i++) {
Brian501ee872007-02-17 09:15:00 -0700762 if (lineNumbers)
763 _mesa_printf("%3d: ", i);
764 indent = _mesa_print_instruction_opt(prog->Instructions + i,
765 indent, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700766 }
767}
768
769
770/**
771 * Print all of a program's parameters.
772 */
773void
774_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
775{
Brian8fed2462007-10-26 19:19:09 -0600776 GLuint i;
777
Brian00cdc0a2006-12-14 15:01:06 -0700778 _mesa_printf("InputsRead: 0x%x\n", prog->InputsRead);
779 _mesa_printf("OutputsWritten: 0x%x\n", prog->OutputsWritten);
780 _mesa_printf("NumInstructions=%d\n", prog->NumInstructions);
781 _mesa_printf("NumTemporaries=%d\n", prog->NumTemporaries);
782 _mesa_printf("NumParameters=%d\n", prog->NumParameters);
783 _mesa_printf("NumAttributes=%d\n", prog->NumAttributes);
784 _mesa_printf("NumAddressRegs=%d\n", prog->NumAddressRegs);
Brian8fed2462007-10-26 19:19:09 -0600785 _mesa_printf("Samplers=[ ");
786 for (i = 0; i < MAX_SAMPLERS; i++) {
787 _mesa_printf("%d ", prog->SamplerUnits[i]);
788 }
789 _mesa_printf("]\n");
Brian Paula0bfeb02008-05-18 15:46:58 -0600790
Brian00cdc0a2006-12-14 15:01:06 -0700791 _mesa_load_state_parameters(ctx, prog->Parameters);
Brian Paula0bfeb02008-05-18 15:46:58 -0600792
Brian00cdc0a2006-12-14 15:01:06 -0700793#if 0
794 _mesa_printf("Local Params:\n");
795 for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
796 const GLfloat *p = prog->LocalParams[i];
797 _mesa_printf("%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
798 }
799#endif
Brian83ca3ff2006-12-20 17:17:38 -0700800 _mesa_print_parameter_list(prog->Parameters);
801}
Brian00cdc0a2006-12-14 15:01:06 -0700802
Brian83ca3ff2006-12-20 17:17:38 -0700803
804void
805_mesa_print_parameter_list(const struct gl_program_parameter_list *list)
806{
Brian501ee872007-02-17 09:15:00 -0700807 const gl_prog_print_mode mode = PROG_PRINT_DEBUG;
Brian83ca3ff2006-12-20 17:17:38 -0700808 GLuint i;
Brian501ee872007-02-17 09:15:00 -0700809
Brian82349352007-10-30 11:14:33 -0600810 if (!list)
811 return;
812
Brian83ca3ff2006-12-20 17:17:38 -0700813 _mesa_printf("param list %p\n", (void *) list);
814 for (i = 0; i < list->NumParameters; i++){
815 struct gl_program_parameter *param = list->Parameters + i;
816 const GLfloat *v = list->ParameterValues[i];
Brianc5e6bf62007-02-07 16:09:13 -0700817 _mesa_printf("param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g};\n",
Brian83ca3ff2006-12-20 17:17:38 -0700818 i, param->Size,
Brian501ee872007-02-17 09:15:00 -0700819 file_string(list->Parameters[i].Type, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700820 param->Name, v[0], v[1], v[2], v[3]);
821 }
822}