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]"
154 assert(strcmp(vertAttribs
[VERT_ATTRIB_TEX0
], "vertex.texcoord[0]") == 0);
155 assert(strcmp(vertAttribs
[VERT_ATTRIB_GENERIC15
], "vertex.attrib[15]") == 0);
157 if (progType
== GL_VERTEX_PROGRAM_ARB
) {
158 assert(index
< sizeof(vertAttribs
) / sizeof(vertAttribs
[0]));
159 return vertAttribs
[index
];
162 assert(index
< sizeof(fragAttribs
) / sizeof(fragAttribs
[0]));
163 return fragAttribs
[index
];
169 * Print a vertex program's InputsRead field in human-readable format.
173 _mesa_print_vp_inputs(GLbitfield inputs
)
175 printf("VP Inputs 0x%x: \n", inputs
);
177 GLint attr
= _mesa_ffs(inputs
) - 1;
178 const char *name
= arb_input_attrib_string(attr
,
179 GL_VERTEX_PROGRAM_ARB
);
180 printf(" %d: %s\n", attr
, name
);
181 inputs
&= ~(1 << attr
);
187 * Print a fragment program's InputsRead field in human-readable format.
191 _mesa_print_fp_inputs(GLbitfield inputs
)
193 printf("FP Inputs 0x%x: \n", inputs
);
195 GLint attr
= _mesa_ffs(inputs
) - 1;
196 const char *name
= arb_input_attrib_string(attr
,
197 GL_FRAGMENT_PROGRAM_ARB
);
198 printf(" %d: %s\n", attr
, name
);
199 inputs
&= ~(1 << attr
);
206 * Return ARB_v/f_prog-style output attrib string.
209 arb_output_attrib_string(GLint index
, GLenum progType
)
212 * These strings should match the VERT_RESULT_x and FRAG_RESULT_x tokens.
214 const char *vertResults
[] = {
216 "result.color.primary",
217 "result.color.secondary",
219 "result.texcoord[0]",
220 "result.texcoord[1]",
221 "result.texcoord[2]",
222 "result.texcoord[3]",
223 "result.texcoord[4]",
224 "result.texcoord[5]",
225 "result.texcoord[6]",
226 "result.texcoord[7]",
236 const char *fragResults
[] = {
238 "result.color(half)",
246 if (progType
== GL_VERTEX_PROGRAM_ARB
) {
247 assert(index
< sizeof(vertResults
) / sizeof(vertResults
[0]));
248 return vertResults
[index
];
251 assert(index
< sizeof(fragResults
) / sizeof(fragResults
[0]));
252 return fragResults
[index
];
258 * Return string representation of the given register.
259 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
260 * by the ARB/NV program languages so we've taken some liberties here.
261 * \param f the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
262 * \param index number of the register in the register file
263 * \param mode the output format/mode/style
264 * \param prog pointer to containing program
267 reg_string(gl_register_file f
, GLint index
, gl_prog_print_mode mode
,
268 GLboolean relAddr
, const struct gl_program
*prog
)
270 static char str
[100];
271 const char *addr
= relAddr
? "ADDR+" : "";
276 case PROG_PRINT_DEBUG
:
277 sprintf(str
, "%s[%s%d]", file_string(f
, mode
), addr
, index
);
283 sprintf(str
, "%s", arb_input_attrib_string(index
, prog
->Target
));
286 sprintf(str
, "%s", arb_output_attrib_string(index
, prog
->Target
));
288 case PROGRAM_TEMPORARY
:
289 sprintf(str
, "temp%d", index
);
291 case PROGRAM_ENV_PARAM
:
292 sprintf(str
, "program.env[%s%d]", addr
, index
);
294 case PROGRAM_LOCAL_PARAM
:
295 sprintf(str
, "program.local[%s%d]", addr
, index
);
297 case PROGRAM_VARYING
: /* extension */
298 sprintf(str
, "varying[%s%d]", addr
, index
);
300 case PROGRAM_CONSTANT
: /* extension */
301 sprintf(str
, "constant[%s%d]", addr
, index
);
303 case PROGRAM_UNIFORM
: /* extension */
304 sprintf(str
, "uniform[%s%d]", addr
, index
);
306 case PROGRAM_STATE_VAR
:
308 struct gl_program_parameter
*param
309 = prog
->Parameters
->Parameters
+ index
;
310 char *state
= _mesa_program_state_string(param
->StateIndexes
);
311 sprintf(str
, "%s", state
);
315 case PROGRAM_ADDRESS
:
316 sprintf(str
, "A%d", index
);
319 _mesa_problem(NULL
, "bad file in reg_string()");
326 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
)
327 sprintf(str
, "v[%d]", index
);
329 sprintf(str
, "f[%d]", index
);
332 sprintf(str
, "o[%d]", index
);
334 case PROGRAM_TEMPORARY
:
335 sprintf(str
, "R%d", index
);
337 case PROGRAM_ENV_PARAM
:
338 sprintf(str
, "c[%d]", index
);
340 case PROGRAM_VARYING
: /* extension */
341 sprintf(str
, "varying[%s%d]", addr
, index
);
343 case PROGRAM_UNIFORM
: /* extension */
344 sprintf(str
, "uniform[%s%d]", addr
, index
);
346 case PROGRAM_CONSTANT
: /* extension */
347 sprintf(str
, "constant[%s%d]", addr
, index
);
349 case PROGRAM_STATE_VAR
: /* extension */
350 sprintf(str
, "state[%s%d]", addr
, index
);
353 _mesa_problem(NULL
, "bad file in reg_string()");
358 _mesa_problem(NULL
, "bad mode in reg_string()");
366 * Return a string representation of the given swizzle word.
367 * If extended is true, use extended (comma-separated) format.
368 * \param swizzle the swizzle field
369 * \param negateBase 4-bit negation vector
370 * \param extended if true, also allow 0, 1 values
373 _mesa_swizzle_string(GLuint swizzle
, GLuint negateMask
, GLboolean extended
)
375 static const char swz
[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
379 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateMask
== 0)
380 return ""; /* no swizzle/negation */
385 if (negateMask
& NEGATE_X
)
387 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
393 if (negateMask
& NEGATE_Y
)
395 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
401 if (negateMask
& NEGATE_Z
)
403 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
409 if (negateMask
& NEGATE_W
)
411 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
419 _mesa_print_swizzle(GLuint swizzle
)
421 if (swizzle
== SWIZZLE_XYZW
) {
425 const char *s
= _mesa_swizzle_string(swizzle
, 0, 0);
432 _mesa_writemask_string(GLuint writeMask
)
437 if (writeMask
== WRITEMASK_XYZW
)
441 if (writeMask
& WRITEMASK_X
)
443 if (writeMask
& WRITEMASK_Y
)
445 if (writeMask
& WRITEMASK_Z
)
447 if (writeMask
& WRITEMASK_W
)
456 _mesa_condcode_string(GLuint condcode
)
459 case COND_GT
: return "GT";
460 case COND_EQ
: return "EQ";
461 case COND_LT
: return "LT";
462 case COND_UN
: return "UN";
463 case COND_GE
: return "GE";
464 case COND_LE
: return "LE";
465 case COND_NE
: return "NE";
466 case COND_TR
: return "TR";
467 case COND_FL
: return "FL";
468 default: return "cond???";
474 fprint_dst_reg(FILE * f
,
475 const struct prog_dst_register
*dstReg
,
476 gl_prog_print_mode mode
,
477 const struct gl_program
*prog
)
480 reg_string((gl_register_file
) dstReg
->File
,
481 dstReg
->Index
, mode
, dstReg
->RelAddr
, prog
),
482 _mesa_writemask_string(dstReg
->WriteMask
));
484 if (dstReg
->CondMask
!= COND_TR
) {
485 fprintf(f
, " (%s.%s)",
486 _mesa_condcode_string(dstReg
->CondMask
),
487 _mesa_swizzle_string(dstReg
->CondSwizzle
,
488 GL_FALSE
, GL_FALSE
));
492 fprintf(f
, "%s[%d]%s",
493 file_string((gl_register_file
) dstReg
->File
, mode
),
495 _mesa_writemask_string(dstReg
->WriteMask
));
501 fprint_src_reg(FILE *f
,
502 const struct prog_src_register
*srcReg
,
503 gl_prog_print_mode mode
,
504 const struct gl_program
*prog
)
506 const char *abs
= srcReg
->Abs
? "|" : "";
508 fprintf(f
, "%s%s%s%s",
510 reg_string((gl_register_file
) srcReg
->File
,
511 srcReg
->Index
, mode
, srcReg
->RelAddr
, prog
),
512 _mesa_swizzle_string(srcReg
->Swizzle
,
513 srcReg
->Negate
, GL_FALSE
),
516 fprintf(f
, "%s[%d]%s",
517 file_string((gl_register_file
) srcReg
->File
, mode
),
519 _mesa_swizzle_string(srcReg
->Swizzle
,
520 srcReg
->Negate
, GL_FALSE
));
526 fprint_comment(FILE *f
, const struct prog_instruction
*inst
)
529 fprintf(f
, "; # %s\n", inst
->Comment
);
536 fprint_alu_instruction(FILE *f
,
537 const struct prog_instruction
*inst
,
538 const char *opcode_string
, GLuint numRegs
,
539 gl_prog_print_mode mode
,
540 const struct gl_program
*prog
)
544 fprintf(f
, "%s", opcode_string
);
545 if (inst
->CondUpdate
)
549 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
553 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
554 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
563 for (j
= 0; j
< numRegs
; j
++) {
564 fprint_src_reg(f
, inst
->SrcReg
+ j
, mode
, prog
);
569 fprint_comment(f
, inst
);
574 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
575 const char *opcode_string
, GLuint numRegs
)
577 fprint_alu_instruction(stderr
, inst
, opcode_string
,
578 numRegs
, PROG_PRINT_DEBUG
, NULL
);
583 * Print a single vertex/fragment program instruction.
586 _mesa_fprint_instruction_opt(FILE *f
,
587 const struct prog_instruction
*inst
,
589 gl_prog_print_mode mode
,
590 const struct gl_program
*prog
)
594 if (inst
->Opcode
== OPCODE_ELSE
||
595 inst
->Opcode
== OPCODE_ENDIF
||
596 inst
->Opcode
== OPCODE_ENDLOOP
||
597 inst
->Opcode
== OPCODE_ENDSUB
) {
600 for (i
= 0; i
< indent
; i
++) {
604 switch (inst
->Opcode
) {
606 fprintf(f
, "PRINT '%s'", (char *) inst
->Data
);
607 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
609 fprintf(f
, "%s[%d]%s",
610 file_string((gl_register_file
) inst
->SrcReg
[0].File
,
612 inst
->SrcReg
[0].Index
,
613 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
614 inst
->SrcReg
[0].Negate
, GL_FALSE
));
617 fprintf(f
, " # %s", inst
->Comment
);
618 fprint_comment(f
, inst
);
622 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
625 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
626 fprintf(f
, ", %s[%d], %s",
627 file_string((gl_register_file
) inst
->SrcReg
[0].File
,
629 inst
->SrcReg
[0].Index
,
630 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
631 inst
->SrcReg
[0].Negate
, GL_TRUE
));
632 fprint_comment(f
, inst
);
638 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
639 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
642 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
644 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
645 fprintf(f
, ", texture[%d], ", inst
->TexSrcUnit
);
646 switch (inst
->TexSrcTarget
) {
647 case TEXTURE_1D_INDEX
: fprintf(f
, "1D"); break;
648 case TEXTURE_2D_INDEX
: fprintf(f
, "2D"); break;
649 case TEXTURE_3D_INDEX
: fprintf(f
, "3D"); break;
650 case TEXTURE_CUBE_INDEX
: fprintf(f
, "CUBE"); break;
651 case TEXTURE_RECT_INDEX
: fprintf(f
, "RECT"); break;
652 case TEXTURE_1D_ARRAY_INDEX
: fprintf(f
, "1D_ARRAY"); break;
653 case TEXTURE_2D_ARRAY_INDEX
: fprintf(f
, "2D_ARRAY"); break;
658 fprintf(f
, " SHADOW");
659 fprint_comment(f
, inst
);
663 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
665 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
666 fprint_comment(f
, inst
);
669 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
672 _mesa_condcode_string(inst
->DstReg
.CondMask
),
673 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
674 GL_FALSE
, GL_FALSE
));
675 fprint_comment(f
, inst
);
680 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
682 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
683 fprint_comment(f
, inst
);
686 fprintf(f
, "BRA %d (%s%s)",
688 _mesa_condcode_string(inst
->DstReg
.CondMask
),
689 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
690 fprint_comment(f
, inst
);
693 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
694 /* Use ordinary register */
696 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
701 fprintf(f
, "IF (%s%s);",
702 _mesa_condcode_string(inst
->DstReg
.CondMask
),
703 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
706 fprintf(f
, " # (if false, goto %d)", inst
->BranchTarget
);
707 fprint_comment(f
, inst
);
710 fprintf(f
, "ELSE; # (goto %d)\n", inst
->BranchTarget
);
713 fprintf(f
, "ENDIF;\n");
716 fprintf(f
, "BGNLOOP; # (end at %d)\n", inst
->BranchTarget
);
719 fprintf(f
, "ENDLOOP; # (goto %d)\n", inst
->BranchTarget
);
723 fprintf(f
, "%s (%s%s); # (goto %d)",
724 _mesa_opcode_string(inst
->Opcode
),
725 _mesa_condcode_string(inst
->DstReg
.CondMask
),
726 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
),
728 fprint_comment(f
, inst
);
732 if (mode
== PROG_PRINT_NV
) {
733 fprintf(f
, "%s:\n", inst
->Comment
); /* comment is label */
737 fprintf(f
, "BGNSUB");
738 fprint_comment(f
, inst
);
742 if (mode
== PROG_PRINT_DEBUG
) {
743 fprintf(f
, "ENDSUB");
744 fprint_comment(f
, inst
);
748 if (mode
== PROG_PRINT_NV
) {
749 fprintf(f
, "CAL %s; # (goto %d)\n", inst
->Comment
, inst
->BranchTarget
);
752 fprintf(f
, "CAL %u", inst
->BranchTarget
);
753 fprint_comment(f
, inst
);
757 fprintf(f
, "RET (%s%s)",
758 _mesa_condcode_string(inst
->DstReg
.CondMask
),
759 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
760 fprint_comment(f
, inst
);
767 if (mode
== PROG_PRINT_DEBUG
) {
769 fprint_comment(f
, inst
);
771 else if (inst
->Comment
) {
772 /* ARB/NV extensions don't have NOP instruction */
773 fprintf(f
, "# %s\n", inst
->Comment
);
776 /* XXX may need other special-case instructions */
778 if (inst
->Opcode
< MAX_OPCODE
) {
779 /* typical alu instruction */
780 fprint_alu_instruction(f
, inst
,
781 _mesa_opcode_string(inst
->Opcode
),
782 _mesa_num_inst_src_regs(inst
->Opcode
),
786 fprint_alu_instruction(f
, inst
,
787 _mesa_opcode_string(inst
->Opcode
),
788 3/*_mesa_num_inst_src_regs(inst->Opcode)*/,
798 _mesa_print_instruction_opt(const struct prog_instruction
*inst
,
800 gl_prog_print_mode mode
,
801 const struct gl_program
*prog
)
803 return _mesa_fprint_instruction_opt(stderr
, inst
, indent
, mode
, prog
);
808 _mesa_print_instruction(const struct prog_instruction
*inst
)
810 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
811 _mesa_fprint_instruction_opt(stderr
, inst
, 0, PROG_PRINT_DEBUG
, NULL
);
817 * Print program, with options.
820 _mesa_fprint_program_opt(FILE *f
,
821 const struct gl_program
*prog
,
822 gl_prog_print_mode mode
,
823 GLboolean lineNumbers
)
825 GLuint i
, indent
= 0;
827 switch (prog
->Target
) {
828 case GL_VERTEX_PROGRAM_ARB
:
829 if (mode
== PROG_PRINT_ARB
)
830 fprintf(f
, "!!ARBvp1.0\n");
831 else if (mode
== PROG_PRINT_NV
)
832 fprintf(f
, "!!VP1.0\n");
834 fprintf(f
, "# Vertex Program/Shader %u\n", prog
->Id
);
836 case GL_FRAGMENT_PROGRAM_ARB
:
837 case GL_FRAGMENT_PROGRAM_NV
:
838 if (mode
== PROG_PRINT_ARB
)
839 fprintf(f
, "!!ARBfp1.0\n");
840 else if (mode
== PROG_PRINT_NV
)
841 fprintf(f
, "!!FP1.0\n");
843 fprintf(f
, "# Fragment Program/Shader %u\n", prog
->Id
);
847 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
849 fprintf(f
, "%3d: ", i
);
850 indent
= _mesa_fprint_instruction_opt(f
, prog
->Instructions
+ i
,
857 * Print program to stderr, default options.
860 _mesa_print_program(const struct gl_program
*prog
)
862 _mesa_fprint_program_opt(stderr
, prog
, PROG_PRINT_DEBUG
, GL_TRUE
);
867 * Return binary representation of 64-bit value (as a string).
868 * Insert a comma to separate each group of 8 bits.
869 * Note we return a pointer to local static storage so this is not
871 * XXX move to imports.[ch] if useful elsewhere.
874 binary(GLbitfield64 val
)
878 for (i
= 63; i
>= 0; --i
) {
879 if (val
& (BITFIELD64_BIT(i
)))
881 else if (len
> 0 || i
== 0)
883 if (len
> 0 && ((i
-1) % 8) == 7)
892 * Print all of a program's parameters/fields to given file.
895 _mesa_fprint_program_parameters(FILE *f
,
897 const struct gl_program
*prog
)
901 fprintf(f
, "InputsRead: 0x%x (0b%s)\n",
902 prog
->InputsRead
, binary(prog
->InputsRead
));
903 fprintf(f
, "OutputsWritten: 0x%llx (0b%s)\n",
904 prog
->OutputsWritten
, binary(prog
->OutputsWritten
));
905 fprintf(f
, "NumInstructions=%d\n", prog
->NumInstructions
);
906 fprintf(f
, "NumTemporaries=%d\n", prog
->NumTemporaries
);
907 fprintf(f
, "NumParameters=%d\n", prog
->NumParameters
);
908 fprintf(f
, "NumAttributes=%d\n", prog
->NumAttributes
);
909 fprintf(f
, "NumAddressRegs=%d\n", prog
->NumAddressRegs
);
910 fprintf(f
, "SamplersUsed: 0x%x (0b%s)\n",
911 prog
->SamplersUsed
, binary(prog
->SamplersUsed
));
912 fprintf(f
, "Samplers=[ ");
913 for (i
= 0; i
< MAX_SAMPLERS
; i
++) {
914 fprintf(f
, "%d ", prog
->SamplerUnits
[i
]);
918 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
921 fprintf(f
, "Local Params:\n");
922 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
923 const GLfloat
*p
= prog
->LocalParams
[i
];
924 fprintf(f
, "%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
927 _mesa_print_parameter_list(prog
->Parameters
);
932 * Print all of a program's parameters/fields to stderr.
935 _mesa_print_program_parameters(GLcontext
*ctx
, const struct gl_program
*prog
)
937 _mesa_fprint_program_parameters(stderr
, ctx
, prog
);
942 * Print a program parameter list to given file.
945 _mesa_fprint_parameter_list(FILE *f
,
946 const struct gl_program_parameter_list
*list
)
948 const gl_prog_print_mode mode
= PROG_PRINT_DEBUG
;
955 fprintf(f
, "param list %p\n", (void *) list
);
956 fprintf(f
, "dirty state flags: 0x%x\n", list
->StateFlags
);
957 for (i
= 0; i
< list
->NumParameters
; i
++){
958 struct gl_program_parameter
*param
= list
->Parameters
+ i
;
959 const GLfloat
*v
= list
->ParameterValues
[i
];
960 fprintf(f
, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
962 file_string(list
->Parameters
[i
].Type
, mode
),
963 param
->Name
, v
[0], v
[1], v
[2], v
[3]);
964 if (param
->Flags
& PROG_PARAM_BIT_CENTROID
)
965 fprintf(f
, " Centroid");
966 if (param
->Flags
& PROG_PARAM_BIT_INVARIANT
)
967 fprintf(f
, " Invariant");
968 if (param
->Flags
& PROG_PARAM_BIT_FLAT
)
970 if (param
->Flags
& PROG_PARAM_BIT_LINEAR
)
971 fprintf(f
, " Linear");
978 * Print a program parameter list to stderr.
981 _mesa_print_parameter_list(const struct gl_program_parameter_list
*list
)
983 _mesa_fprint_parameter_list(stderr
, list
);
988 * Write shader and associated info to a file.
991 _mesa_write_shader_to_file(const struct gl_shader
*shader
)
997 if (shader
->Type
== GL_FRAGMENT_SHADER
)
1002 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
1003 f
= fopen(filename
, "w");
1005 fprintf(stderr
, "Unable to open %s for writing\n", filename
);
1009 fprintf(f
, "/* Shader %u source, checksum %u */\n", shader
->Name
, shader
->SourceChecksum
);
1010 fputs(shader
->Source
, f
);
1013 fprintf(f
, "/* Compile status: %s */\n",
1014 shader
->CompileStatus
? "ok" : "fail");
1015 if (!shader
->CompileStatus
) {
1016 fprintf(f
, "/* Log Info: */\n");
1017 fputs(shader
->InfoLog
, f
);
1020 fprintf(f
, "/* GPU code */\n");
1022 _mesa_fprint_program_opt(f
, shader
->Program
, PROG_PRINT_DEBUG
, GL_TRUE
);
1024 fprintf(f
, "/* Parameters / constants */\n");
1026 _mesa_fprint_parameter_list(f
, shader
->Program
->Parameters
);
1035 * Append the shader's uniform info/values to the shader log file.
1036 * The log file will typically have been created by the
1037 * _mesa_write_shader_to_file function.
1040 _mesa_append_uniforms_to_file(const struct gl_shader
*shader
,
1041 const struct gl_program
*prog
)
1047 if (shader
->Type
== GL_FRAGMENT_SHADER
)
1052 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
1053 f
= fopen(filename
, "a"); /* append */
1055 fprintf(stderr
, "Unable to open %s for appending\n", filename
);
1059 fprintf(f
, "/* First-draw parameters / constants */\n");
1061 _mesa_fprint_parameter_list(f
, prog
->Parameters
);