2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
28 * Print vertex/fragment programs - for debugging.
32 #include "main/glheader.h"
33 #include "main/context.h"
34 #include "main/imports.h"
35 #include "prog_instruction.h"
36 #include "prog_parameter.h"
37 #include "prog_print.h"
38 #include "prog_statevars.h"
43 * Return string name for given program/register file.
46 file_string(gl_register_file f
, gl_prog_print_mode mode
)
49 case PROGRAM_TEMPORARY
:
51 case PROGRAM_LOCAL_PARAM
:
53 case PROGRAM_ENV_PARAM
:
55 case PROGRAM_STATE_VAR
:
61 case PROGRAM_NAMED_PARAM
:
63 case PROGRAM_CONSTANT
:
69 case PROGRAM_WRITE_ONLY
:
75 case PROGRAM_UNDEFINED
:
80 _mesa_snprintf(s
, sizeof(s
), "FILE%u", f
);
88 * Return ARB_v/f_prog-style input attrib string.
91 arb_input_attrib_string(GLint index
, GLenum progType
)
94 * These strings should match the VERT_ATTRIB_x and FRAG_ATTRIB_x tokens.
96 const char *vertAttribs
[] = {
100 "vertex.color.primary",
101 "vertex.color.secondary",
105 "vertex.texcoord[0]",
106 "vertex.texcoord[1]",
107 "vertex.texcoord[2]",
108 "vertex.texcoord[3]",
109 "vertex.texcoord[4]",
110 "vertex.texcoord[5]",
111 "vertex.texcoord[6]",
112 "vertex.texcoord[7]",
130 const char *fragAttribs
[] = {
132 "fragment.color.primary",
133 "fragment.color.secondary",
135 "fragment.texcoord[0]",
136 "fragment.texcoord[1]",
137 "fragment.texcoord[2]",
138 "fragment.texcoord[3]",
139 "fragment.texcoord[4]",
140 "fragment.texcoord[5]",
141 "fragment.texcoord[6]",
142 "fragment.texcoord[7]",
143 "fragment.varying[0]",
144 "fragment.varying[1]",
145 "fragment.varying[2]",
146 "fragment.varying[3]",
147 "fragment.varying[4]",
148 "fragment.varying[5]",
149 "fragment.varying[6]",
150 "fragment.varying[7]"
153 if (progType
== GL_VERTEX_PROGRAM_ARB
) {
154 assert(index
< sizeof(vertAttribs
) / sizeof(vertAttribs
[0]));
155 return vertAttribs
[index
];
158 assert(index
< sizeof(fragAttribs
) / sizeof(fragAttribs
[0]));
159 return fragAttribs
[index
];
165 * Return ARB_v/f_prog-style output attrib string.
168 arb_output_attrib_string(GLint index
, GLenum progType
)
171 * These strings should match the VERT_RESULT_x and FRAG_RESULT_x tokens.
173 const char *vertResults
[] = {
175 "result.color.primary",
176 "result.color.secondary",
178 "result.texcoord[0]",
179 "result.texcoord[1]",
180 "result.texcoord[2]",
181 "result.texcoord[3]",
182 "result.texcoord[4]",
183 "result.texcoord[5]",
184 "result.texcoord[6]",
185 "result.texcoord[7]",
195 const char *fragResults
[] = {
197 "result.color(half)",
205 if (progType
== GL_VERTEX_PROGRAM_ARB
) {
206 assert(index
< sizeof(vertResults
) / sizeof(vertResults
[0]));
207 return vertResults
[index
];
210 assert(index
< sizeof(fragResults
) / sizeof(fragResults
[0]));
211 return fragResults
[index
];
217 * Return string representation of the given register.
218 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
219 * by the ARB/NV program languages so we've taken some liberties here.
220 * \param f the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
221 * \param index number of the register in the register file
222 * \param mode the output format/mode/style
223 * \param prog pointer to containing program
226 reg_string(gl_register_file f
, GLint index
, gl_prog_print_mode mode
,
227 GLboolean relAddr
, const struct gl_program
*prog
)
229 static char str
[100];
230 const char *addr
= relAddr
? "ADDR+" : "";
235 case PROG_PRINT_DEBUG
:
236 _mesa_sprintf(str
, "%s[%s%d]", file_string(f
, mode
), addr
, index
);
242 _mesa_sprintf(str
, "%s", arb_input_attrib_string(index
, prog
->Target
));
245 _mesa_sprintf(str
, "%s", arb_output_attrib_string(index
, prog
->Target
));
247 case PROGRAM_TEMPORARY
:
248 _mesa_sprintf(str
, "temp%d", index
);
250 case PROGRAM_ENV_PARAM
:
251 _mesa_sprintf(str
, "program.env[%s%d]", addr
, index
);
253 case PROGRAM_LOCAL_PARAM
:
254 _mesa_sprintf(str
, "program.local[%s%d]", addr
, index
);
256 case PROGRAM_VARYING
: /* extension */
257 _mesa_sprintf(str
, "varying[%s%d]", addr
, index
);
259 case PROGRAM_CONSTANT
: /* extension */
260 _mesa_sprintf(str
, "constant[%s%d]", addr
, index
);
262 case PROGRAM_UNIFORM
: /* extension */
263 _mesa_sprintf(str
, "uniform[%s%d]", addr
, index
);
265 case PROGRAM_STATE_VAR
:
267 struct gl_program_parameter
*param
268 = prog
->Parameters
->Parameters
+ index
;
269 char *state
= _mesa_program_state_string(param
->StateIndexes
);
270 _mesa_sprintf(str
, state
);
274 case PROGRAM_ADDRESS
:
275 _mesa_sprintf(str
, "A%d", index
);
278 _mesa_problem(NULL
, "bad file in reg_string()");
285 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
)
286 _mesa_sprintf(str
, "v[%d]", index
);
288 _mesa_sprintf(str
, "f[%d]", index
);
291 _mesa_sprintf(str
, "o[%d]", index
);
293 case PROGRAM_TEMPORARY
:
294 _mesa_sprintf(str
, "R%d", index
);
296 case PROGRAM_ENV_PARAM
:
297 _mesa_sprintf(str
, "c[%d]", index
);
299 case PROGRAM_VARYING
: /* extension */
300 _mesa_sprintf(str
, "varying[%s%d]", addr
, index
);
302 case PROGRAM_UNIFORM
: /* extension */
303 _mesa_sprintf(str
, "uniform[%s%d]", addr
, index
);
305 case PROGRAM_CONSTANT
: /* extension */
306 _mesa_sprintf(str
, "constant[%s%d]", addr
, index
);
308 case PROGRAM_STATE_VAR
: /* extension */
309 _mesa_sprintf(str
, "state[%s%d]", addr
, index
);
312 _mesa_problem(NULL
, "bad file in reg_string()");
317 _mesa_problem(NULL
, "bad mode in reg_string()");
325 * Return a string representation of the given swizzle word.
326 * If extended is true, use extended (comma-separated) format.
327 * \param swizzle the swizzle field
328 * \param negateBase 4-bit negation vector
329 * \param extended if true, also allow 0, 1 values
332 _mesa_swizzle_string(GLuint swizzle
, GLuint negateMask
, GLboolean extended
)
334 static const char swz
[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
338 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateMask
== 0)
339 return ""; /* no swizzle/negation */
344 if (negateMask
& NEGATE_X
)
346 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
352 if (negateMask
& NEGATE_Y
)
354 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
360 if (negateMask
& NEGATE_Z
)
362 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
368 if (negateMask
& NEGATE_W
)
370 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
378 _mesa_print_swizzle(GLuint swizzle
)
380 if (swizzle
== SWIZZLE_XYZW
) {
381 _mesa_printf(".xyzw\n");
384 const char *s
= _mesa_swizzle_string(swizzle
, 0, 0);
385 _mesa_printf("%s\n", s
);
391 _mesa_writemask_string(GLuint writeMask
)
396 if (writeMask
== WRITEMASK_XYZW
)
400 if (writeMask
& WRITEMASK_X
)
402 if (writeMask
& WRITEMASK_Y
)
404 if (writeMask
& WRITEMASK_Z
)
406 if (writeMask
& WRITEMASK_W
)
415 _mesa_condcode_string(GLuint condcode
)
418 case COND_GT
: return "GT";
419 case COND_EQ
: return "EQ";
420 case COND_LT
: return "LT";
421 case COND_UN
: return "UN";
422 case COND_GE
: return "GE";
423 case COND_LE
: return "LE";
424 case COND_NE
: return "NE";
425 case COND_TR
: return "TR";
426 case COND_FL
: return "FL";
427 default: return "cond???";
433 fprint_dst_reg(FILE * f
,
434 const struct prog_dst_register
*dstReg
,
435 gl_prog_print_mode mode
,
436 const struct gl_program
*prog
)
438 _mesa_fprintf(f
, "%s%s",
439 reg_string((gl_register_file
) dstReg
->File
,
440 dstReg
->Index
, mode
, dstReg
->RelAddr
, prog
),
441 _mesa_writemask_string(dstReg
->WriteMask
));
443 if (dstReg
->CondMask
!= COND_TR
) {
444 _mesa_fprintf(f
, " (%s.%s)",
445 _mesa_condcode_string(dstReg
->CondMask
),
446 _mesa_swizzle_string(dstReg
->CondSwizzle
,
447 GL_FALSE
, GL_FALSE
));
451 _mesa_fprintf(f
, "%s[%d]%s",
452 file_string((gl_register_file
) dstReg
->File
, mode
),
454 _mesa_writemask_string(dstReg
->WriteMask
));
460 fprint_src_reg(FILE *f
,
461 const struct prog_src_register
*srcReg
,
462 gl_prog_print_mode mode
,
463 const struct gl_program
*prog
)
465 const char *abs
= srcReg
->Abs
? "|" : "";
467 _mesa_fprintf(f
, "%s%s%s%s",
469 reg_string((gl_register_file
) srcReg
->File
,
470 srcReg
->Index
, mode
, srcReg
->RelAddr
, prog
),
471 _mesa_swizzle_string(srcReg
->Swizzle
,
472 srcReg
->Negate
, GL_FALSE
),
475 _mesa_fprintf(f
, "%s[%d]%s",
476 file_string((gl_register_file
) srcReg
->File
, mode
),
478 _mesa_swizzle_string(srcReg
->Swizzle
,
479 srcReg
->Negate
, GL_FALSE
));
485 fprint_comment(FILE *f
, const struct prog_instruction
*inst
)
488 _mesa_fprintf(f
, "; # %s\n", inst
->Comment
);
490 _mesa_fprintf(f
, ";\n");
495 fprint_alu_instruction(FILE *f
,
496 const struct prog_instruction
*inst
,
497 const char *opcode_string
, GLuint numRegs
,
498 gl_prog_print_mode mode
,
499 const struct gl_program
*prog
)
503 _mesa_fprintf(f
, "%s", opcode_string
);
504 if (inst
->CondUpdate
)
505 _mesa_fprintf(f
, ".C");
508 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
509 _mesa_fprintf(f
, "_SAT");
511 _mesa_fprintf(f
, " ");
512 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
513 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
516 _mesa_fprintf(f
, " ???");
520 _mesa_fprintf(f
, ", ");
522 for (j
= 0; j
< numRegs
; j
++) {
523 fprint_src_reg(f
, inst
->SrcReg
+ j
, mode
, prog
);
525 _mesa_fprintf(f
, ", ");
528 fprint_comment(f
, inst
);
533 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
534 const char *opcode_string
, GLuint numRegs
)
536 fprint_alu_instruction(stdout
, inst
, opcode_string
,
537 numRegs
, PROG_PRINT_DEBUG
, NULL
);
542 * Print a single vertex/fragment program instruction.
545 _mesa_fprint_instruction_opt(FILE *f
,
546 const struct prog_instruction
*inst
,
548 gl_prog_print_mode mode
,
549 const struct gl_program
*prog
)
553 if (inst
->Opcode
== OPCODE_ELSE
||
554 inst
->Opcode
== OPCODE_ENDIF
||
555 inst
->Opcode
== OPCODE_ENDLOOP
||
556 inst
->Opcode
== OPCODE_ENDSUB
) {
559 for (i
= 0; i
< indent
; i
++) {
560 _mesa_fprintf(f
, " ");
563 switch (inst
->Opcode
) {
565 _mesa_fprintf(f
, "PRINT '%s'", inst
->Data
);
566 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
567 _mesa_fprintf(f
, ", ");
568 _mesa_fprintf(f
, "%s[%d]%s",
569 file_string((gl_register_file
) inst
->SrcReg
[0].File
,
571 inst
->SrcReg
[0].Index
,
572 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
573 inst
->SrcReg
[0].Negate
, GL_FALSE
));
576 _mesa_fprintf(f
, " # %s", inst
->Comment
);
577 fprint_comment(f
, inst
);
580 _mesa_fprintf(f
, "SWZ");
581 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
582 _mesa_fprintf(f
, "_SAT");
583 _mesa_fprintf(f
, " ");
584 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
585 _mesa_fprintf(f
, ", %s[%d], %s",
586 file_string((gl_register_file
) inst
->SrcReg
[0].File
,
588 inst
->SrcReg
[0].Index
,
589 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
590 inst
->SrcReg
[0].Negate
, GL_TRUE
));
591 fprint_comment(f
, inst
);
597 _mesa_fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
598 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
599 _mesa_fprintf(f
, "_SAT");
600 _mesa_fprintf(f
, " ");
601 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
602 _mesa_fprintf(f
, ", ");
603 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
604 _mesa_fprintf(f
, ", texture[%d], ", inst
->TexSrcUnit
);
605 switch (inst
->TexSrcTarget
) {
606 case TEXTURE_1D_INDEX
: _mesa_fprintf(f
, "1D"); break;
607 case TEXTURE_2D_INDEX
: _mesa_fprintf(f
, "2D"); break;
608 case TEXTURE_3D_INDEX
: _mesa_fprintf(f
, "3D"); break;
609 case TEXTURE_CUBE_INDEX
: _mesa_fprintf(f
, "CUBE"); break;
610 case TEXTURE_RECT_INDEX
: _mesa_fprintf(f
, "RECT"); break;
615 _mesa_fprintf(f
, " SHADOW");
616 fprint_comment(f
, inst
);
620 _mesa_fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
621 _mesa_fprintf(f
, " ");
622 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
623 fprint_comment(f
, inst
);
626 _mesa_fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
627 _mesa_fprintf(f
, " ");
628 _mesa_fprintf(f
, "%s.%s",
629 _mesa_condcode_string(inst
->DstReg
.CondMask
),
630 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
631 GL_FALSE
, GL_FALSE
));
632 fprint_comment(f
, inst
);
636 _mesa_fprintf(f
, "ARL ");
637 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
638 _mesa_fprintf(f
, ", ");
639 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
640 fprint_comment(f
, inst
);
643 _mesa_fprintf(f
, "BRA %d (%s%s)",
645 _mesa_condcode_string(inst
->DstReg
.CondMask
),
646 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
647 fprint_comment(f
, inst
);
650 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
651 /* Use ordinary register */
652 _mesa_fprintf(f
, "IF ");
653 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
654 _mesa_fprintf(f
, "; ");
658 _mesa_fprintf(f
, "IF (%s%s);",
659 _mesa_condcode_string(inst
->DstReg
.CondMask
),
660 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
663 _mesa_fprintf(f
, " # (if false, goto %d)", inst
->BranchTarget
);
664 fprint_comment(f
, inst
);
667 _mesa_fprintf(f
, "ELSE; # (goto %d)\n", inst
->BranchTarget
);
670 _mesa_fprintf(f
, "ENDIF;\n");
673 _mesa_fprintf(f
, "BGNLOOP; # (end at %d)\n", inst
->BranchTarget
);
676 _mesa_fprintf(f
, "ENDLOOP; # (goto %d)\n", inst
->BranchTarget
);
680 _mesa_fprintf(f
, "%s (%s%s); # (goto %d)",
681 _mesa_opcode_string(inst
->Opcode
),
682 _mesa_condcode_string(inst
->DstReg
.CondMask
),
683 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
),
685 fprint_comment(f
, inst
);
689 if (mode
== PROG_PRINT_NV
) {
690 _mesa_fprintf(f
, "%s:\n", inst
->Comment
); /* comment is label */
694 _mesa_fprintf(f
, "BGNSUB");
695 fprint_comment(f
, inst
);
699 if (mode
== PROG_PRINT_DEBUG
) {
700 _mesa_fprintf(f
, "ENDSUB");
701 fprint_comment(f
, inst
);
705 if (mode
== PROG_PRINT_NV
) {
706 _mesa_fprintf(f
, "CAL %s; # (goto %d)\n", inst
->Comment
, inst
->BranchTarget
);
709 _mesa_fprintf(f
, "CAL %u", inst
->BranchTarget
);
710 fprint_comment(f
, inst
);
714 _mesa_fprintf(f
, "RET (%s%s)",
715 _mesa_condcode_string(inst
->DstReg
.CondMask
),
716 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
717 fprint_comment(f
, inst
);
721 _mesa_fprintf(f
, "END\n");
724 if (mode
== PROG_PRINT_DEBUG
) {
725 _mesa_fprintf(f
, "NOP");
726 fprint_comment(f
, inst
);
728 else if (inst
->Comment
) {
729 /* ARB/NV extensions don't have NOP instruction */
730 _mesa_fprintf(f
, "# %s\n", inst
->Comment
);
733 /* XXX may need other special-case instructions */
735 if (inst
->Opcode
< MAX_OPCODE
) {
736 /* typical alu instruction */
737 fprint_alu_instruction(f
, inst
,
738 _mesa_opcode_string(inst
->Opcode
),
739 _mesa_num_inst_src_regs(inst
->Opcode
),
743 fprint_alu_instruction(f
, inst
,
744 _mesa_opcode_string(inst
->Opcode
),
745 3/*_mesa_num_inst_src_regs(inst->Opcode)*/,
755 _mesa_print_instruction_opt(const struct prog_instruction
*inst
,
757 gl_prog_print_mode mode
,
758 const struct gl_program
*prog
)
760 return _mesa_fprint_instruction_opt(stdout
, inst
, indent
, mode
, prog
);
765 _mesa_print_instruction(const struct prog_instruction
*inst
)
767 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
768 _mesa_fprint_instruction_opt(stdout
, inst
, 0, PROG_PRINT_DEBUG
, NULL
);
774 * Print program, with options.
777 _mesa_fprint_program_opt(FILE *f
,
778 const struct gl_program
*prog
,
779 gl_prog_print_mode mode
,
780 GLboolean lineNumbers
)
782 GLuint i
, indent
= 0;
784 switch (prog
->Target
) {
785 case GL_VERTEX_PROGRAM_ARB
:
786 if (mode
== PROG_PRINT_ARB
)
787 _mesa_fprintf(f
, "!!ARBvp1.0\n");
788 else if (mode
== PROG_PRINT_NV
)
789 _mesa_fprintf(f
, "!!VP1.0\n");
791 _mesa_fprintf(f
, "# Vertex Program/Shader\n");
793 case GL_FRAGMENT_PROGRAM_ARB
:
794 case GL_FRAGMENT_PROGRAM_NV
:
795 if (mode
== PROG_PRINT_ARB
)
796 _mesa_fprintf(f
, "!!ARBfp1.0\n");
797 else if (mode
== PROG_PRINT_NV
)
798 _mesa_fprintf(f
, "!!FP1.0\n");
800 _mesa_fprintf(f
, "# Fragment Program/Shader\n");
804 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
806 _mesa_fprintf(f
, "%3d: ", i
);
807 indent
= _mesa_fprint_instruction_opt(f
, prog
->Instructions
+ i
,
814 * Print program to stdout, default options.
817 _mesa_print_program(const struct gl_program
*prog
)
819 _mesa_fprint_program_opt(stdout
, prog
, PROG_PRINT_DEBUG
, GL_TRUE
);
824 * Print all of a program's parameters/fields to given file.
827 _mesa_fprint_program_parameters(FILE *f
,
829 const struct gl_program
*prog
)
833 _mesa_fprintf(f
, "InputsRead: 0x%x\n", prog
->InputsRead
);
834 _mesa_fprintf(f
, "OutputsWritten: 0x%x\n", prog
->OutputsWritten
);
835 _mesa_fprintf(f
, "NumInstructions=%d\n", prog
->NumInstructions
);
836 _mesa_fprintf(f
, "NumTemporaries=%d\n", prog
->NumTemporaries
);
837 _mesa_fprintf(f
, "NumParameters=%d\n", prog
->NumParameters
);
838 _mesa_fprintf(f
, "NumAttributes=%d\n", prog
->NumAttributes
);
839 _mesa_fprintf(f
, "NumAddressRegs=%d\n", prog
->NumAddressRegs
);
840 _mesa_fprintf(f
, "Samplers=[ ");
841 for (i
= 0; i
< MAX_SAMPLERS
; i
++) {
842 _mesa_fprintf(f
, "%d ", prog
->SamplerUnits
[i
]);
844 _mesa_fprintf(f
, "]\n");
846 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
849 _mesa_fprintf(f
, "Local Params:\n");
850 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
851 const GLfloat
*p
= prog
->LocalParams
[i
];
852 _mesa_fprintf(f
, "%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
855 _mesa_print_parameter_list(prog
->Parameters
);
860 * Print all of a program's parameters/fields to stdout.
863 _mesa_print_program_parameters(GLcontext
*ctx
, const struct gl_program
*prog
)
865 _mesa_fprint_program_parameters(stdout
, ctx
, prog
);
870 * Print a program parameter list to given file.
873 _mesa_fprint_parameter_list(FILE *f
,
874 const struct gl_program_parameter_list
*list
)
876 const gl_prog_print_mode mode
= PROG_PRINT_DEBUG
;
882 _mesa_fprintf(f
, "param list %p\n", (void *) list
);
883 _mesa_fprintf(f
, "dirty state flags: 0x%x\n", list
->StateFlags
);
884 for (i
= 0; i
< list
->NumParameters
; i
++){
885 struct gl_program_parameter
*param
= list
->Parameters
+ i
;
886 const GLfloat
*v
= list
->ParameterValues
[i
];
887 _mesa_fprintf(f
, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
889 file_string(list
->Parameters
[i
].Type
, mode
),
890 param
->Name
, v
[0], v
[1], v
[2], v
[3]);
891 if (param
->Flags
& PROG_PARAM_BIT_CENTROID
)
892 _mesa_fprintf(f
, " Centroid");
893 if (param
->Flags
& PROG_PARAM_BIT_INVARIANT
)
894 _mesa_fprintf(f
, " Invariant");
895 if (param
->Flags
& PROG_PARAM_BIT_FLAT
)
896 _mesa_fprintf(f
, " Flat");
897 if (param
->Flags
& PROG_PARAM_BIT_LINEAR
)
898 _mesa_fprintf(f
, " Linear");
899 _mesa_fprintf(f
, "\n");
905 * Print a program parameter list to stdout.
908 _mesa_print_parameter_list(const struct gl_program_parameter_list
*list
)
910 _mesa_fprint_parameter_list(stdout
, list
);
915 * Write shader and associated info to a file.
918 _mesa_write_shader_to_file(const struct gl_shader
*shader
)
924 if (shader
->Type
== GL_FRAGMENT_SHADER
)
929 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
930 f
= fopen(filename
, "w");
932 fprintf(stderr
, "Unable to open %s for writing\n", filename
);
936 fprintf(f
, "/* Shader %u source */\n", shader
->Name
);
937 fputs(shader
->Source
, f
);
940 fprintf(f
, "/* Compile status: %s */\n",
941 shader
->CompileStatus
? "ok" : "fail");
942 if (!shader
->CompileStatus
) {
943 fprintf(f
, "/* Log Info: */\n");
944 fputs(shader
->InfoLog
, f
);
947 fprintf(f
, "/* GPU code */\n");
949 _mesa_fprint_program_opt(f
, shader
->Program
, PROG_PRINT_DEBUG
, GL_TRUE
);
951 fprintf(f
, "/* Parameters / constants */\n");
953 _mesa_fprint_parameter_list(f
, shader
->Program
->Parameters
);