Merge branch 'master' of git+ssh://git.freedesktop.org/git/mesa/mesa into gallium-0.2
[mesa.git] / src / mesa / shader / prog_print.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
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
31 #include "main/glheader.h"
32 #include "main/context.h"
33 #include "main/imports.h"
34 #include "prog_instruction.h"
35 #include "prog_parameter.h"
36 #include "prog_print.h"
37 #include "prog_statevars.h"
38
39
40
41 /**
42 * Return string name for given program/register file.
43 */
44 static const char *
45 file_string(enum register_file f, gl_prog_print_mode mode)
46 {
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";
72 case PROGRAM_SAMPLER:
73 return "SAMPLER";
74 default:
75 return "Unknown program file!";
76 }
77 }
78
79
80 /**
81 * Return ARB_v/f_prog-style input attrib string.
82 */
83 static const char *
84 arb_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]",
102 "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]"
119 };
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 */
157 static const char *
158 arb_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 */
207 static const char *
208 reg_string(enum register_file f, GLint index, gl_prog_print_mode mode,
209 GLboolean relAddr, const struct gl_program *prog)
210 {
211 static char str[100];
212
213 str[0] = 0;
214
215 switch (mode) {
216 case PROG_PRINT_DEBUG:
217 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);
221 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;
253 sprintf(str, _mesa_program_state_string(param->StateIndexes));
254 }
255 break;
256 case PROGRAM_ADDRESS:
257 sprintf(str, "A%d", index);
258 break;
259 default:
260 _mesa_problem(NULL, "bad file in reg_string()");
261 }
262 break;
263
264 case PROG_PRINT_NV:
265 switch (f) {
266 case PROGRAM_INPUT:
267 if (prog->Target == GL_VERTEX_PROGRAM_ARB)
268 sprintf(str, "v[%d]", index);
269 else
270 sprintf(str, "f[%d]", index);
271 break;
272 case PROGRAM_OUTPUT:
273 sprintf(str, "o[%d]", index);
274 break;
275 case PROGRAM_TEMPORARY:
276 sprintf(str, "R%d", index);
277 break;
278 case PROGRAM_ENV_PARAM:
279 sprintf(str, "c[%d]", index);
280 break;
281 case PROGRAM_VARYING: /* extension */
282 sprintf(str, "varying[%d]", index);
283 break;
284 case PROGRAM_UNIFORM: /* extension */
285 sprintf(str, "uniform[%d]", index);
286 break;
287 case PROGRAM_CONSTANT: /* extension */
288 sprintf(str, "constant[%d]", index);
289 break;
290 case PROGRAM_STATE_VAR: /* extension */
291 sprintf(str, "state[%d]", index);
292 break;
293 default:
294 _mesa_problem(NULL, "bad file in reg_string()");
295 }
296 break;
297
298 default:
299 _mesa_problem(NULL, "bad mode in reg_string()");
300 }
301
302 return str;
303 }
304
305
306 /**
307 * Return a string representation of the given swizzle word.
308 * If extended is true, use extended (comma-separated) format.
309 * \param swizzle the swizzle field
310 * \param negateBase 4-bit negation vector
311 * \param extended if true, also allow 0, 1 values
312 */
313 const char *
314 _mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended)
315 {
316 static const char swz[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
317 static char s[20];
318 GLuint i = 0;
319
320 if (!extended && swizzle == SWIZZLE_NOOP && negateBase == 0)
321 return ""; /* no swizzle/negation */
322
323 if (!extended)
324 s[i++] = '.';
325
326 if (negateBase & NEGATE_X)
327 s[i++] = '-';
328 s[i++] = swz[GET_SWZ(swizzle, 0)];
329
330 if (extended) {
331 s[i++] = ',';
332 }
333
334 if (negateBase & NEGATE_Y)
335 s[i++] = '-';
336 s[i++] = swz[GET_SWZ(swizzle, 1)];
337
338 if (extended) {
339 s[i++] = ',';
340 }
341
342 if (negateBase & NEGATE_Z)
343 s[i++] = '-';
344 s[i++] = swz[GET_SWZ(swizzle, 2)];
345
346 if (extended) {
347 s[i++] = ',';
348 }
349
350 if (negateBase & NEGATE_W)
351 s[i++] = '-';
352 s[i++] = swz[GET_SWZ(swizzle, 3)];
353
354 s[i] = 0;
355 return s;
356 }
357
358
359 void
360 _mesa_print_swizzle(GLuint swizzle)
361 {
362 if (swizzle == SWIZZLE_XYZW) {
363 _mesa_printf(".xyzw\n");
364 }
365 else {
366 const char *s = _mesa_swizzle_string(swizzle, 0, 0);
367 _mesa_printf("%s\n", s);
368 }
369 }
370
371
372 static const char *
373 writemask_string(GLuint writeMask)
374 {
375 static char s[10];
376 GLuint i = 0;
377
378 if (writeMask == WRITEMASK_XYZW)
379 return "";
380
381 s[i++] = '.';
382 if (writeMask & WRITEMASK_X)
383 s[i++] = 'x';
384 if (writeMask & WRITEMASK_Y)
385 s[i++] = 'y';
386 if (writeMask & WRITEMASK_Z)
387 s[i++] = 'z';
388 if (writeMask & WRITEMASK_W)
389 s[i++] = 'w';
390
391 s[i] = 0;
392 return s;
393 }
394
395
396 const char *
397 _mesa_condcode_string(GLuint condcode)
398 {
399 switch (condcode) {
400 case COND_GT: return "GT";
401 case COND_EQ: return "EQ";
402 case COND_LT: return "LT";
403 case COND_UN: return "UN";
404 case COND_GE: return "GE";
405 case COND_LE: return "LE";
406 case COND_NE: return "NE";
407 case COND_TR: return "TR";
408 case COND_FL: return "FL";
409 default: return "cond???";
410 }
411 }
412
413
414 static void
415 print_dst_reg(const struct prog_dst_register *dstReg, gl_prog_print_mode mode,
416 const struct gl_program *prog)
417 {
418 _mesa_printf("%s%s",
419 reg_string((enum register_file) dstReg->File,
420 dstReg->Index, mode, GL_FALSE, prog),
421 writemask_string(dstReg->WriteMask));
422
423 if (dstReg->CondMask != COND_TR) {
424 _mesa_printf(" (%s.%s)",
425 _mesa_condcode_string(dstReg->CondMask),
426 _mesa_swizzle_string(dstReg->CondSwizzle, GL_FALSE, GL_FALSE));
427 }
428
429 #if 0
430 _mesa_printf("%s[%d]%s",
431 file_string((enum register_file) dstReg->File, mode),
432 dstReg->Index,
433 writemask_string(dstReg->WriteMask));
434 #endif
435 }
436
437 static void
438 print_src_reg(const struct prog_src_register *srcReg, gl_prog_print_mode mode,
439 const struct gl_program *prog)
440 {
441 _mesa_printf("%s%s",
442 reg_string((enum register_file) srcReg->File,
443 srcReg->Index, mode, srcReg->RelAddr, prog),
444 _mesa_swizzle_string(srcReg->Swizzle,
445 srcReg->NegateBase, GL_FALSE));
446 #if 0
447 _mesa_printf("%s[%d]%s",
448 file_string((enum register_file) srcReg->File, mode),
449 srcReg->Index,
450 _mesa_swizzle_string(srcReg->Swizzle,
451 srcReg->NegateBase, GL_FALSE));
452 #endif
453 }
454
455 static void
456 print_comment(const struct prog_instruction *inst)
457 {
458 if (inst->Comment)
459 _mesa_printf("; # %s\n", inst->Comment);
460 else
461 _mesa_printf(";\n");
462 }
463
464
465 static void
466 print_alu_instruction(const struct prog_instruction *inst,
467 const char *opcode_string, GLuint numRegs,
468 gl_prog_print_mode mode,
469 const struct gl_program *prog)
470 {
471 GLuint j;
472
473 _mesa_printf("%s", opcode_string);
474 if (inst->CondUpdate)
475 _mesa_printf(".C");
476
477 /* frag prog only */
478 if (inst->SaturateMode == SATURATE_ZERO_ONE)
479 _mesa_printf("_SAT");
480
481 _mesa_printf(" ");
482 if (inst->DstReg.File != PROGRAM_UNDEFINED) {
483 print_dst_reg(&inst->DstReg, mode, prog);
484 }
485 else {
486 _mesa_printf(" ???");
487 }
488
489 if (numRegs > 0)
490 _mesa_printf(", ");
491
492 for (j = 0; j < numRegs; j++) {
493 print_src_reg(inst->SrcReg + j, mode, prog);
494 if (j + 1 < numRegs)
495 _mesa_printf(", ");
496 }
497
498 print_comment(inst);
499 }
500
501
502 void
503 _mesa_print_alu_instruction(const struct prog_instruction *inst,
504 const char *opcode_string, GLuint numRegs)
505 {
506 print_alu_instruction(inst, opcode_string, numRegs, PROG_PRINT_DEBUG, NULL);
507 }
508
509
510 void
511 _mesa_print_instruction(const struct prog_instruction *inst)
512 {
513 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
514 _mesa_print_instruction_opt(inst, 0, PROG_PRINT_DEBUG, NULL);
515 }
516
517
518 /**
519 * Print a single vertex/fragment program instruction.
520 */
521 GLint
522 _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent,
523 gl_prog_print_mode mode,
524 const struct gl_program *prog)
525 {
526 GLint i;
527
528 if (inst->Opcode == OPCODE_ELSE ||
529 inst->Opcode == OPCODE_ENDIF ||
530 inst->Opcode == OPCODE_ENDLOOP ||
531 inst->Opcode == OPCODE_ENDSUB) {
532 indent -= 3;
533 }
534 for (i = 0; i < indent; i++) {
535 _mesa_printf(" ");
536 }
537
538 switch (inst->Opcode) {
539 case OPCODE_PRINT:
540 _mesa_printf("PRINT '%s'", inst->Data);
541 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
542 _mesa_printf(", ");
543 _mesa_printf("%s[%d]%s",
544 file_string((enum register_file) inst->SrcReg[0].File,
545 mode),
546 inst->SrcReg[0].Index,
547 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
548 inst->SrcReg[0].NegateBase, GL_FALSE));
549 }
550 if (inst->Comment)
551 _mesa_printf(" # %s", inst->Comment);
552 print_comment(inst);
553 break;
554 case OPCODE_SWZ:
555 _mesa_printf("SWZ");
556 if (inst->SaturateMode == SATURATE_ZERO_ONE)
557 _mesa_printf("_SAT");
558 _mesa_printf(" ");
559 print_dst_reg(&inst->DstReg, mode, prog);
560 _mesa_printf(", %s[%d], %s",
561 file_string((enum register_file) inst->SrcReg[0].File,
562 mode),
563 inst->SrcReg[0].Index,
564 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
565 inst->SrcReg[0].NegateBase, GL_TRUE));
566 print_comment(inst);
567 break;
568 case OPCODE_TEX:
569 case OPCODE_TXP:
570 case OPCODE_TXL:
571 case OPCODE_TXB:
572 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
573 if (inst->SaturateMode == SATURATE_ZERO_ONE)
574 _mesa_printf("_SAT");
575 _mesa_printf(" ");
576 print_dst_reg(&inst->DstReg, mode, prog);
577 _mesa_printf(", ");
578 print_src_reg(&inst->SrcReg[0], mode, prog);
579 _mesa_printf(", texture[%d], ", inst->TexSrcUnit);
580 switch (inst->TexSrcTarget) {
581 case TEXTURE_1D_INDEX: _mesa_printf("1D"); break;
582 case TEXTURE_2D_INDEX: _mesa_printf("2D"); break;
583 case TEXTURE_3D_INDEX: _mesa_printf("3D"); break;
584 case TEXTURE_CUBE_INDEX: _mesa_printf("CUBE"); break;
585 case TEXTURE_RECT_INDEX: _mesa_printf("RECT"); break;
586 default:
587 ;
588 }
589 print_comment(inst);
590 break;
591
592 case OPCODE_KIL:
593 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
594 _mesa_printf(" ");
595 print_src_reg(&inst->SrcReg[0], mode, prog);
596 print_comment(inst);
597 break;
598 case OPCODE_KIL_NV:
599 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
600 _mesa_printf(" ");
601 _mesa_printf("%s.%s",
602 _mesa_condcode_string(inst->DstReg.CondMask),
603 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
604 GL_FALSE, GL_FALSE));
605 print_comment(inst);
606 break;
607
608 case OPCODE_ARL:
609 _mesa_printf("ARL ");
610 print_dst_reg(&inst->DstReg, mode, prog);
611 _mesa_printf(", ");
612 print_src_reg(&inst->SrcReg[0], mode, prog);
613 print_comment(inst);
614 break;
615 case OPCODE_BRA:
616 _mesa_printf("BRA %d (%s%s)",
617 inst->BranchTarget,
618 _mesa_condcode_string(inst->DstReg.CondMask),
619 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
620 print_comment(inst);
621 break;
622 case OPCODE_IF:
623 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
624 /* Use ordinary register */
625 _mesa_printf("IF ");
626 print_src_reg(&inst->SrcReg[0], mode, prog);
627 _mesa_printf("; ");
628 }
629 else {
630 /* Use cond codes */
631 _mesa_printf("IF (%s%s);",
632 _mesa_condcode_string(inst->DstReg.CondMask),
633 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
634 0, GL_FALSE));
635 }
636 _mesa_printf(" # (if false, goto %d)", inst->BranchTarget);
637 print_comment(inst);
638 return indent + 3;
639 case OPCODE_ELSE:
640 _mesa_printf("ELSE; # (goto %d)\n", inst->BranchTarget);
641 return indent + 3;
642 case OPCODE_ENDIF:
643 _mesa_printf("ENDIF;\n");
644 break;
645 case OPCODE_BGNLOOP:
646 _mesa_printf("BGNLOOP; # (end at %d)\n", inst->BranchTarget);
647 return indent + 3;
648 case OPCODE_ENDLOOP:
649 _mesa_printf("ENDLOOP; # (goto %d)\n", inst->BranchTarget);
650 break;
651 case OPCODE_BRK:
652 case OPCODE_CONT:
653 _mesa_printf("%s (%s%s); # (goto %d)",
654 _mesa_opcode_string(inst->Opcode),
655 _mesa_condcode_string(inst->DstReg.CondMask),
656 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
657 inst->BranchTarget);
658 print_comment(inst);
659 break;
660
661 case OPCODE_BGNSUB:
662 if (mode == PROG_PRINT_NV) {
663 _mesa_printf("%s:\n", inst->Comment); /* comment is label */
664 return indent;
665 }
666 else {
667 _mesa_printf("BGNSUB");
668 print_comment(inst);
669 return indent + 3;
670 }
671 case OPCODE_ENDSUB:
672 if (mode == PROG_PRINT_DEBUG) {
673 _mesa_printf("ENDSUB");
674 print_comment(inst);
675 }
676 break;
677 case OPCODE_CAL:
678 if (mode == PROG_PRINT_NV) {
679 _mesa_printf("CAL %s; # (goto %d)\n", inst->Comment, inst->BranchTarget);
680 }
681 else {
682 _mesa_printf("CAL %u", inst->BranchTarget);
683 print_comment(inst);
684 }
685 break;
686 case OPCODE_RET:
687 _mesa_printf("RET (%s%s)",
688 _mesa_condcode_string(inst->DstReg.CondMask),
689 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
690 print_comment(inst);
691 break;
692
693 case OPCODE_END:
694 _mesa_printf("END\n");
695 break;
696 case OPCODE_NOP:
697 if (mode == PROG_PRINT_DEBUG) {
698 _mesa_printf("NOP");
699 print_comment(inst);
700 }
701 else if (inst->Comment) {
702 /* ARB/NV extensions don't have NOP instruction */
703 _mesa_printf("# %s\n", inst->Comment);
704 }
705 break;
706 /* XXX may need other special-case instructions */
707 default:
708 /* typical alu instruction */
709 print_alu_instruction(inst,
710 _mesa_opcode_string(inst->Opcode),
711 _mesa_num_inst_src_regs(inst->Opcode),
712 mode, prog);
713 break;
714 }
715 return indent;
716 }
717
718
719 /**
720 * Print program to stdout, default options.
721 */
722 void
723 _mesa_print_program(const struct gl_program *prog)
724 {
725 _mesa_print_program_opt(prog, PROG_PRINT_DEBUG, GL_TRUE);
726 }
727
728
729 /**
730 * Print program, with options.
731 */
732 void
733 _mesa_print_program_opt(const struct gl_program *prog,
734 gl_prog_print_mode mode,
735 GLboolean lineNumbers)
736 {
737 GLuint i, indent = 0;
738
739 switch (prog->Target) {
740 case GL_VERTEX_PROGRAM_ARB:
741 if (mode == PROG_PRINT_ARB)
742 _mesa_printf("!!ARBvp1.0\n");
743 else if (mode == PROG_PRINT_NV)
744 _mesa_printf("!!VP1.0\n");
745 else
746 _mesa_printf("# Vertex Program/Shader\n");
747 break;
748 case GL_FRAGMENT_PROGRAM_ARB:
749 case GL_FRAGMENT_PROGRAM_NV:
750 if (mode == PROG_PRINT_ARB)
751 _mesa_printf("!!ARBfp1.0\n");
752 else if (mode == PROG_PRINT_NV)
753 _mesa_printf("!!FP1.0\n");
754 else
755 _mesa_printf("# Fragment Program/Shader\n");
756 break;
757 }
758
759 for (i = 0; i < prog->NumInstructions; i++) {
760 if (lineNumbers)
761 _mesa_printf("%3d: ", i);
762 indent = _mesa_print_instruction_opt(prog->Instructions + i,
763 indent, mode, prog);
764 }
765 }
766
767
768 /**
769 * Print all of a program's parameters.
770 */
771 void
772 _mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
773 {
774 GLuint i;
775
776 _mesa_printf("InputsRead: 0x%x\n", prog->InputsRead);
777 _mesa_printf("OutputsWritten: 0x%x\n", prog->OutputsWritten);
778 _mesa_printf("NumInstructions=%d\n", prog->NumInstructions);
779 _mesa_printf("NumTemporaries=%d\n", prog->NumTemporaries);
780 _mesa_printf("NumParameters=%d\n", prog->NumParameters);
781 _mesa_printf("NumAttributes=%d\n", prog->NumAttributes);
782 _mesa_printf("NumAddressRegs=%d\n", prog->NumAddressRegs);
783 _mesa_printf("Samplers=[ ");
784 for (i = 0; i < MAX_SAMPLERS; i++) {
785 _mesa_printf("%d ", prog->SamplerUnits[i]);
786 }
787 _mesa_printf("]\n");
788
789 _mesa_load_state_parameters(ctx, prog->Parameters);
790
791 #if 0
792 _mesa_printf("Local Params:\n");
793 for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
794 const GLfloat *p = prog->LocalParams[i];
795 _mesa_printf("%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
796 }
797 #endif
798 _mesa_print_parameter_list(prog->Parameters);
799 }
800
801
802 void
803 _mesa_print_parameter_list(const struct gl_program_parameter_list *list)
804 {
805 const gl_prog_print_mode mode = PROG_PRINT_DEBUG;
806 GLuint i;
807
808 if (!list)
809 return;
810
811 _mesa_printf("param list %p\n", (void *) list);
812 for (i = 0; i < list->NumParameters; i++){
813 struct gl_program_parameter *param = list->Parameters + i;
814 const GLfloat *v = list->ParameterValues[i];
815 _mesa_printf("param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g};\n",
816 i, param->Size,
817 file_string(list->Parameters[i].Type, mode),
818 param->Name, v[0], v[1], v[2], v[3]);
819 }
820 }