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