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
:
78 return "Unknown program file!";
84 * Return ARB_v/f_prog-style input attrib string.
87 arb_input_attrib_string(GLint index
, GLenum progType
)
90 * These strings should match the VERT_ATTRIB_x and FRAG_ATTRIB_x tokens.
92 const char *vertAttribs
[] = {
96 "vertex.color.primary",
97 "vertex.color.secondary",
101 "vertex.texcoord[0]",
102 "vertex.texcoord[1]",
103 "vertex.texcoord[2]",
104 "vertex.texcoord[3]",
105 "vertex.texcoord[4]",
106 "vertex.texcoord[5]",
107 "vertex.texcoord[6]",
108 "vertex.texcoord[7]",
126 const char *fragAttribs
[] = {
128 "fragment.color.primary",
129 "fragment.color.secondary",
131 "fragment.texcoord[0]",
132 "fragment.texcoord[1]",
133 "fragment.texcoord[2]",
134 "fragment.texcoord[3]",
135 "fragment.texcoord[4]",
136 "fragment.texcoord[5]",
137 "fragment.texcoord[6]",
138 "fragment.texcoord[7]",
139 "fragment.varying[0]",
140 "fragment.varying[1]",
141 "fragment.varying[2]",
142 "fragment.varying[3]",
143 "fragment.varying[4]",
144 "fragment.varying[5]",
145 "fragment.varying[6]",
146 "fragment.varying[7]"
149 if (progType
== GL_VERTEX_PROGRAM_ARB
) {
150 assert(index
< sizeof(vertAttribs
) / sizeof(vertAttribs
[0]));
151 return vertAttribs
[index
];
154 assert(index
< sizeof(fragAttribs
) / sizeof(fragAttribs
[0]));
155 return fragAttribs
[index
];
161 * Return ARB_v/f_prog-style output attrib string.
164 arb_output_attrib_string(GLint index
, GLenum progType
)
167 * These strings should match the VERT_RESULT_x and FRAG_RESULT_x tokens.
169 const char *vertResults
[] = {
171 "result.color.primary",
172 "result.color.secondary",
174 "result.texcoord[0]",
175 "result.texcoord[1]",
176 "result.texcoord[2]",
177 "result.texcoord[3]",
178 "result.texcoord[4]",
179 "result.texcoord[5]",
180 "result.texcoord[6]",
181 "result.texcoord[7]",
191 const char *fragResults
[] = {
193 "result.color(half)",
201 if (progType
== GL_VERTEX_PROGRAM_ARB
) {
202 assert(index
< sizeof(vertResults
) / sizeof(vertResults
[0]));
203 return vertResults
[index
];
206 assert(index
< sizeof(fragResults
) / sizeof(fragResults
[0]));
207 return fragResults
[index
];
213 * Return string representation of the given register.
214 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
215 * by the ARB/NV program languages so we've taken some liberties here.
216 * \param file the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
217 * \param index number of the register in the register file
218 * \param mode the output format/mode/style
219 * \param prog pointer to containing program
222 reg_string(gl_register_file f
, GLint index
, gl_prog_print_mode mode
,
223 GLboolean relAddr
, const struct gl_program
*prog
)
225 static char str
[100];
226 const char *addr
= relAddr
? "ADDR+" : "";
231 case PROG_PRINT_DEBUG
:
232 _mesa_sprintf(str
, "%s[%s%d]", file_string(f
, mode
), addr
, index
);
238 _mesa_sprintf(str
, "%s", arb_input_attrib_string(index
, prog
->Target
));
241 _mesa_sprintf(str
, "%s", arb_output_attrib_string(index
, prog
->Target
));
243 case PROGRAM_TEMPORARY
:
244 _mesa_sprintf(str
, "temp%d", index
);
246 case PROGRAM_ENV_PARAM
:
247 _mesa_sprintf(str
, "program.env[%s%d]", addr
, index
);
249 case PROGRAM_LOCAL_PARAM
:
250 _mesa_sprintf(str
, "program.local[%s%d]", addr
, index
);
252 case PROGRAM_VARYING
: /* extension */
253 _mesa_sprintf(str
, "varying[%s%d]", addr
, index
);
255 case PROGRAM_CONSTANT
: /* extension */
256 _mesa_sprintf(str
, "constant[%s%d]", addr
, index
);
258 case PROGRAM_UNIFORM
: /* extension */
259 _mesa_sprintf(str
, "uniform[%s%d]", addr
, index
);
261 case PROGRAM_STATE_VAR
:
263 struct gl_program_parameter
*param
264 = prog
->Parameters
->Parameters
+ index
;
265 char *state
= _mesa_program_state_string(param
->StateIndexes
);
266 _mesa_sprintf(str
, state
);
270 case PROGRAM_ADDRESS
:
271 _mesa_sprintf(str
, "A%d", index
);
274 _mesa_problem(NULL
, "bad file in reg_string()");
281 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
)
282 _mesa_sprintf(str
, "v[%d]", index
);
284 _mesa_sprintf(str
, "f[%d]", index
);
287 _mesa_sprintf(str
, "o[%d]", index
);
289 case PROGRAM_TEMPORARY
:
290 _mesa_sprintf(str
, "R%d", index
);
292 case PROGRAM_ENV_PARAM
:
293 _mesa_sprintf(str
, "c[%d]", index
);
295 case PROGRAM_VARYING
: /* extension */
296 _mesa_sprintf(str
, "varying[%s%d]", addr
, index
);
298 case PROGRAM_UNIFORM
: /* extension */
299 _mesa_sprintf(str
, "uniform[%s%d]", addr
, index
);
301 case PROGRAM_CONSTANT
: /* extension */
302 _mesa_sprintf(str
, "constant[%s%d]", addr
, index
);
304 case PROGRAM_STATE_VAR
: /* extension */
305 _mesa_sprintf(str
, "state[%s%d]", addr
, index
);
308 _mesa_problem(NULL
, "bad file in reg_string()");
313 _mesa_problem(NULL
, "bad mode in reg_string()");
321 * Return a string representation of the given swizzle word.
322 * If extended is true, use extended (comma-separated) format.
323 * \param swizzle the swizzle field
324 * \param negateBase 4-bit negation vector
325 * \param extended if true, also allow 0, 1 values
328 _mesa_swizzle_string(GLuint swizzle
, GLuint negateBase
, GLboolean extended
)
330 static const char swz
[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
334 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateBase
== 0)
335 return ""; /* no swizzle/negation */
340 if (negateBase
& NEGATE_X
)
342 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
348 if (negateBase
& NEGATE_Y
)
350 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
356 if (negateBase
& NEGATE_Z
)
358 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
364 if (negateBase
& NEGATE_W
)
366 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
374 _mesa_print_swizzle(GLuint swizzle
)
376 if (swizzle
== SWIZZLE_XYZW
) {
377 _mesa_printf(".xyzw\n");
380 const char *s
= _mesa_swizzle_string(swizzle
, 0, 0);
381 _mesa_printf("%s\n", s
);
387 _mesa_writemask_string(GLuint writeMask
)
392 if (writeMask
== WRITEMASK_XYZW
)
396 if (writeMask
& WRITEMASK_X
)
398 if (writeMask
& WRITEMASK_Y
)
400 if (writeMask
& WRITEMASK_Z
)
402 if (writeMask
& WRITEMASK_W
)
411 _mesa_condcode_string(GLuint condcode
)
414 case COND_GT
: return "GT";
415 case COND_EQ
: return "EQ";
416 case COND_LT
: return "LT";
417 case COND_UN
: return "UN";
418 case COND_GE
: return "GE";
419 case COND_LE
: return "LE";
420 case COND_NE
: return "NE";
421 case COND_TR
: return "TR";
422 case COND_FL
: return "FL";
423 default: return "cond???";
429 fprint_dst_reg(FILE * f
,
430 const struct prog_dst_register
*dstReg
,
431 gl_prog_print_mode mode
,
432 const struct gl_program
*prog
)
434 _mesa_fprintf(f
, "%s%s",
435 reg_string((gl_register_file
) dstReg
->File
,
436 dstReg
->Index
, mode
, dstReg
->RelAddr
, prog
),
437 _mesa_writemask_string(dstReg
->WriteMask
));
439 if (dstReg
->CondMask
!= COND_TR
) {
440 _mesa_fprintf(f
, " (%s.%s)",
441 _mesa_condcode_string(dstReg
->CondMask
),
442 _mesa_swizzle_string(dstReg
->CondSwizzle
,
443 GL_FALSE
, GL_FALSE
));
447 _mesa_fprintf(f
, "%s[%d]%s",
448 file_string((gl_register_file
) dstReg
->File
, mode
),
450 _mesa_writemask_string(dstReg
->WriteMask
));
456 fprint_src_reg(FILE *f
,
457 const struct prog_src_register
*srcReg
,
458 gl_prog_print_mode mode
,
459 const struct gl_program
*prog
)
461 const char *abs
= srcReg
->Abs
? "|" : "";
463 _mesa_fprintf(f
, "%s%s%s%s",
465 reg_string((gl_register_file
) srcReg
->File
,
466 srcReg
->Index
, mode
, srcReg
->RelAddr
, prog
),
467 _mesa_swizzle_string(srcReg
->Swizzle
,
468 srcReg
->NegateBase
, GL_FALSE
),
471 _mesa_fprintf(f
, "%s[%d]%s",
472 file_string((gl_register_file
) srcReg
->File
, mode
),
474 _mesa_swizzle_string(srcReg
->Swizzle
,
475 srcReg
->NegateBase
, GL_FALSE
));
481 fprint_comment(FILE *f
, const struct prog_instruction
*inst
)
484 _mesa_fprintf(f
, "; # %s\n", inst
->Comment
);
486 _mesa_fprintf(f
, ";\n");
491 fprint_alu_instruction(FILE *f
,
492 const struct prog_instruction
*inst
,
493 const char *opcode_string
, GLuint numRegs
,
494 gl_prog_print_mode mode
,
495 const struct gl_program
*prog
)
499 _mesa_fprintf(f
, "%s", opcode_string
);
500 if (inst
->CondUpdate
)
501 _mesa_fprintf(f
, ".C");
504 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
505 _mesa_fprintf(f
, "_SAT");
507 _mesa_fprintf(f
, " ");
508 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
509 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
512 _mesa_fprintf(f
, " ???");
516 _mesa_fprintf(f
, ", ");
518 for (j
= 0; j
< numRegs
; j
++) {
519 fprint_src_reg(f
, inst
->SrcReg
+ j
, mode
, prog
);
521 _mesa_fprintf(f
, ", ");
524 fprint_comment(f
, inst
);
529 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
530 const char *opcode_string
, GLuint numRegs
)
532 fprint_alu_instruction(stdout
, inst
, opcode_string
,
533 numRegs
, PROG_PRINT_DEBUG
, NULL
);
538 * Print a single vertex/fragment program instruction.
541 _mesa_fprint_instruction_opt(FILE *f
,
542 const struct prog_instruction
*inst
,
544 gl_prog_print_mode mode
,
545 const struct gl_program
*prog
)
549 if (inst
->Opcode
== OPCODE_ELSE
||
550 inst
->Opcode
== OPCODE_ENDIF
||
551 inst
->Opcode
== OPCODE_ENDLOOP
||
552 inst
->Opcode
== OPCODE_ENDSUB
) {
555 for (i
= 0; i
< indent
; i
++) {
556 _mesa_fprintf(f
, " ");
559 switch (inst
->Opcode
) {
561 _mesa_fprintf(f
, "PRINT '%s'", inst
->Data
);
562 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
563 _mesa_fprintf(f
, ", ");
564 _mesa_fprintf(f
, "%s[%d]%s",
565 file_string((gl_register_file
) inst
->SrcReg
[0].File
,
567 inst
->SrcReg
[0].Index
,
568 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
569 inst
->SrcReg
[0].NegateBase
, GL_FALSE
));
572 _mesa_fprintf(f
, " # %s", inst
->Comment
);
573 fprint_comment(f
, inst
);
576 _mesa_fprintf(f
, "SWZ");
577 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
578 _mesa_fprintf(f
, "_SAT");
579 _mesa_fprintf(f
, " ");
580 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
581 _mesa_fprintf(f
, ", %s[%d], %s",
582 file_string((gl_register_file
) inst
->SrcReg
[0].File
,
584 inst
->SrcReg
[0].Index
,
585 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
586 inst
->SrcReg
[0].NegateBase
, GL_TRUE
));
587 fprint_comment(f
, inst
);
593 _mesa_fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
594 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
595 _mesa_fprintf(f
, "_SAT");
596 _mesa_fprintf(f
, " ");
597 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
598 _mesa_fprintf(f
, ", ");
599 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
600 _mesa_fprintf(f
, ", texture[%d], ", inst
->TexSrcUnit
);
601 switch (inst
->TexSrcTarget
) {
602 case TEXTURE_1D_INDEX
: _mesa_fprintf(f
, "1D"); break;
603 case TEXTURE_2D_INDEX
: _mesa_fprintf(f
, "2D"); break;
604 case TEXTURE_3D_INDEX
: _mesa_fprintf(f
, "3D"); break;
605 case TEXTURE_CUBE_INDEX
: _mesa_fprintf(f
, "CUBE"); break;
606 case TEXTURE_RECT_INDEX
: _mesa_fprintf(f
, "RECT"); break;
611 _mesa_fprintf(f
, " SHADOW");
612 fprint_comment(f
, inst
);
616 _mesa_fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
617 _mesa_fprintf(f
, " ");
618 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
619 fprint_comment(f
, inst
);
622 _mesa_fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
623 _mesa_fprintf(f
, " ");
624 _mesa_fprintf(f
, "%s.%s",
625 _mesa_condcode_string(inst
->DstReg
.CondMask
),
626 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
627 GL_FALSE
, GL_FALSE
));
628 fprint_comment(f
, inst
);
632 _mesa_fprintf(f
, "ARL ");
633 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
634 _mesa_fprintf(f
, ", ");
635 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
636 fprint_comment(f
, inst
);
639 _mesa_fprintf(f
, "BRA %d (%s%s)",
641 _mesa_condcode_string(inst
->DstReg
.CondMask
),
642 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
643 fprint_comment(f
, inst
);
646 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
647 /* Use ordinary register */
648 _mesa_fprintf(f
, "IF ");
649 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
650 _mesa_fprintf(f
, "; ");
654 _mesa_fprintf(f
, "IF (%s%s);",
655 _mesa_condcode_string(inst
->DstReg
.CondMask
),
656 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
659 _mesa_fprintf(f
, " # (if false, goto %d)", inst
->BranchTarget
);
660 fprint_comment(f
, inst
);
663 _mesa_fprintf(f
, "ELSE; # (goto %d)\n", inst
->BranchTarget
);
666 _mesa_fprintf(f
, "ENDIF;\n");
669 _mesa_fprintf(f
, "BGNLOOP; # (end at %d)\n", inst
->BranchTarget
);
672 _mesa_fprintf(f
, "ENDLOOP; # (goto %d)\n", inst
->BranchTarget
);
676 _mesa_fprintf(f
, "%s (%s%s); # (goto %d)",
677 _mesa_opcode_string(inst
->Opcode
),
678 _mesa_condcode_string(inst
->DstReg
.CondMask
),
679 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
),
681 fprint_comment(f
, inst
);
685 if (mode
== PROG_PRINT_NV
) {
686 _mesa_fprintf(f
, "%s:\n", inst
->Comment
); /* comment is label */
690 _mesa_fprintf(f
, "BGNSUB");
691 fprint_comment(f
, inst
);
695 if (mode
== PROG_PRINT_DEBUG
) {
696 _mesa_fprintf(f
, "ENDSUB");
697 fprint_comment(f
, inst
);
701 if (mode
== PROG_PRINT_NV
) {
702 _mesa_fprintf(f
, "CAL %s; # (goto %d)\n", inst
->Comment
, inst
->BranchTarget
);
705 _mesa_fprintf(f
, "CAL %u", inst
->BranchTarget
);
706 fprint_comment(f
, inst
);
710 _mesa_fprintf(f
, "RET (%s%s)",
711 _mesa_condcode_string(inst
->DstReg
.CondMask
),
712 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
713 fprint_comment(f
, inst
);
717 _mesa_fprintf(f
, "END\n");
720 if (mode
== PROG_PRINT_DEBUG
) {
721 _mesa_fprintf(f
, "NOP");
722 fprint_comment(f
, inst
);
724 else if (inst
->Comment
) {
725 /* ARB/NV extensions don't have NOP instruction */
726 _mesa_fprintf(f
, "# %s\n", inst
->Comment
);
729 /* XXX may need other special-case instructions */
731 if (inst
->Opcode
< MAX_OPCODE
) {
732 /* typical alu instruction */
733 fprint_alu_instruction(f
, inst
,
734 _mesa_opcode_string(inst
->Opcode
),
735 _mesa_num_inst_src_regs(inst
->Opcode
),
739 _mesa_fprintf(f
, "Other opcode %d\n", inst
->Opcode
);
748 _mesa_print_instruction_opt(const struct prog_instruction
*inst
,
750 gl_prog_print_mode mode
,
751 const struct gl_program
*prog
)
753 return _mesa_fprint_instruction_opt(stdout
, inst
, indent
, mode
, prog
);
758 _mesa_print_instruction(const struct prog_instruction
*inst
)
760 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
761 _mesa_fprint_instruction_opt(stdout
, inst
, 0, PROG_PRINT_DEBUG
, NULL
);
767 * Print program, with options.
770 _mesa_fprint_program_opt(FILE *f
,
771 const struct gl_program
*prog
,
772 gl_prog_print_mode mode
,
773 GLboolean lineNumbers
)
775 GLuint i
, indent
= 0;
777 switch (prog
->Target
) {
778 case GL_VERTEX_PROGRAM_ARB
:
779 if (mode
== PROG_PRINT_ARB
)
780 _mesa_fprintf(f
, "!!ARBvp1.0\n");
781 else if (mode
== PROG_PRINT_NV
)
782 _mesa_fprintf(f
, "!!VP1.0\n");
784 _mesa_fprintf(f
, "# Vertex Program/Shader\n");
786 case GL_FRAGMENT_PROGRAM_ARB
:
787 case GL_FRAGMENT_PROGRAM_NV
:
788 if (mode
== PROG_PRINT_ARB
)
789 _mesa_fprintf(f
, "!!ARBfp1.0\n");
790 else if (mode
== PROG_PRINT_NV
)
791 _mesa_fprintf(f
, "!!FP1.0\n");
793 _mesa_fprintf(f
, "# Fragment Program/Shader\n");
797 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
799 _mesa_fprintf(f
, "%3d: ", i
);
800 indent
= _mesa_fprint_instruction_opt(f
, prog
->Instructions
+ i
,
807 * Print program to stdout, default options.
810 _mesa_print_program(const struct gl_program
*prog
)
812 _mesa_fprint_program_opt(stdout
, prog
, PROG_PRINT_DEBUG
, GL_TRUE
);
817 * Print all of a program's parameters/fields to given file.
820 _mesa_fprint_program_parameters(FILE *f
,
822 const struct gl_program
*prog
)
826 _mesa_fprintf(f
, "InputsRead: 0x%x\n", prog
->InputsRead
);
827 _mesa_fprintf(f
, "OutputsWritten: 0x%x\n", prog
->OutputsWritten
);
828 _mesa_fprintf(f
, "NumInstructions=%d\n", prog
->NumInstructions
);
829 _mesa_fprintf(f
, "NumTemporaries=%d\n", prog
->NumTemporaries
);
830 _mesa_fprintf(f
, "NumParameters=%d\n", prog
->NumParameters
);
831 _mesa_fprintf(f
, "NumAttributes=%d\n", prog
->NumAttributes
);
832 _mesa_fprintf(f
, "NumAddressRegs=%d\n", prog
->NumAddressRegs
);
833 _mesa_fprintf(f
, "Samplers=[ ");
834 for (i
= 0; i
< MAX_SAMPLERS
; i
++) {
835 _mesa_fprintf(f
, "%d ", prog
->SamplerUnits
[i
]);
837 _mesa_fprintf(f
, "]\n");
839 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
842 _mesa_fprintf(f
, "Local Params:\n");
843 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
844 const GLfloat
*p
= prog
->LocalParams
[i
];
845 _mesa_fprintf(f
, "%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
848 _mesa_print_parameter_list(prog
->Parameters
);
853 * Print all of a program's parameters/fields to stdout.
856 _mesa_print_program_parameters(GLcontext
*ctx
, const struct gl_program
*prog
)
858 _mesa_fprint_program_parameters(stdout
, ctx
, prog
);
863 * Print a program parameter list to given file.
866 _mesa_fprint_parameter_list(FILE *f
,
867 const struct gl_program_parameter_list
*list
)
869 const gl_prog_print_mode mode
= PROG_PRINT_DEBUG
;
875 _mesa_fprintf(f
, "param list %p\n", (void *) list
);
876 for (i
= 0; i
< list
->NumParameters
; i
++){
877 struct gl_program_parameter
*param
= list
->Parameters
+ i
;
878 const GLfloat
*v
= list
->ParameterValues
[i
];
879 _mesa_fprintf(f
, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
881 file_string(list
->Parameters
[i
].Type
, mode
),
882 param
->Name
, v
[0], v
[1], v
[2], v
[3]);
883 if (param
->Flags
& PROG_PARAM_BIT_CENTROID
)
884 _mesa_fprintf(f
, " Centroid");
885 if (param
->Flags
& PROG_PARAM_BIT_INVARIANT
)
886 _mesa_fprintf(f
, " Invariant");
887 if (param
->Flags
& PROG_PARAM_BIT_FLAT
)
888 _mesa_fprintf(f
, " Flat");
889 if (param
->Flags
& PROG_PARAM_BIT_LINEAR
)
890 _mesa_fprintf(f
, " Linear");
891 _mesa_fprintf(f
, "\n");
897 * Print a program parameter list to stdout.
900 _mesa_print_parameter_list(const struct gl_program_parameter_list
*list
)
902 _mesa_fprint_parameter_list(stdout
, list
);
907 * Write shader and associated info to a file.
910 _mesa_write_shader_to_file(const struct gl_shader
*shader
)
916 if (shader
->Type
== GL_FRAGMENT_SHADER
)
921 _mesa_snprintf(filename
, strlen(filename
), "shader_%u.%s", shader
->Name
, type
);
922 f
= fopen(filename
, "w");
924 fprintf(stderr
, "Unable to open %s for writing\n", filename
);
928 fprintf(f
, "/* Shader %u source */\n", shader
->Name
);
929 fputs(shader
->Source
, f
);
932 fprintf(f
, "/* Compile status: %s */\n",
933 shader
->CompileStatus
? "ok" : "fail");
934 if (!shader
->CompileStatus
) {
935 fprintf(f
, "/* Log Info: */\n");
936 fputs(shader
->InfoLog
, f
);
939 fprintf(f
, "/* GPU code */\n");
941 _mesa_fprint_program_opt(f
, shader
->Program
, PROG_PRINT_DEBUG
, GL_TRUE
);