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
,
269 GLboolean hasIndex2
, GLboolean relAddr2
, GLint index2
)
271 static char str
[100];
272 const char *addr
= relAddr
? "ADDR+" : "";
277 case PROG_PRINT_DEBUG
:
278 sprintf(str
, "%s[%s%d]", file_string(f
, mode
), addr
, index
);
280 int offset
= strlen(str
);
281 const char *addr2
= relAddr2
? "ADDR+" : "";
282 sprintf(str
+offset
, "[%s%d]", addr2
, index2
);
289 sprintf(str
, "%s", arb_input_attrib_string(index
, prog
->Target
));
292 sprintf(str
, "%s", arb_output_attrib_string(index
, prog
->Target
));
294 case PROGRAM_TEMPORARY
:
295 sprintf(str
, "temp%d", index
);
297 case PROGRAM_ENV_PARAM
:
298 sprintf(str
, "program.env[%s%d]", addr
, index
);
300 case PROGRAM_LOCAL_PARAM
:
301 sprintf(str
, "program.local[%s%d]", addr
, index
);
303 case PROGRAM_VARYING
: /* extension */
304 sprintf(str
, "varying[%s%d]", addr
, index
);
306 case PROGRAM_CONSTANT
: /* extension */
307 sprintf(str
, "constant[%s%d]", addr
, index
);
309 case PROGRAM_UNIFORM
: /* extension */
310 sprintf(str
, "uniform[%s%d]", addr
, index
);
312 case PROGRAM_STATE_VAR
:
314 struct gl_program_parameter
*param
315 = prog
->Parameters
->Parameters
+ index
;
316 char *state
= _mesa_program_state_string(param
->StateIndexes
);
317 sprintf(str
, "%s", state
);
321 case PROGRAM_ADDRESS
:
322 sprintf(str
, "A%d", index
);
325 _mesa_problem(NULL
, "bad file in reg_string()");
332 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
)
333 sprintf(str
, "v[%d]", index
);
335 sprintf(str
, "f[%d]", index
);
338 sprintf(str
, "o[%d]", index
);
340 case PROGRAM_TEMPORARY
:
341 sprintf(str
, "R%d", index
);
343 case PROGRAM_ENV_PARAM
:
344 sprintf(str
, "c[%d]", index
);
346 case PROGRAM_VARYING
: /* extension */
347 sprintf(str
, "varying[%s%d]", addr
, index
);
349 case PROGRAM_UNIFORM
: /* extension */
350 sprintf(str
, "uniform[%s%d]", addr
, index
);
352 case PROGRAM_CONSTANT
: /* extension */
353 sprintf(str
, "constant[%s%d]", addr
, index
);
355 case PROGRAM_STATE_VAR
: /* extension */
356 sprintf(str
, "state[%s%d]", addr
, index
);
359 _mesa_problem(NULL
, "bad file in reg_string()");
364 _mesa_problem(NULL
, "bad mode in reg_string()");
372 * Return a string representation of the given swizzle word.
373 * If extended is true, use extended (comma-separated) format.
374 * \param swizzle the swizzle field
375 * \param negateBase 4-bit negation vector
376 * \param extended if true, also allow 0, 1 values
379 _mesa_swizzle_string(GLuint swizzle
, GLuint negateMask
, GLboolean extended
)
381 static const char swz
[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
385 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateMask
== 0)
386 return ""; /* no swizzle/negation */
391 if (negateMask
& NEGATE_X
)
393 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
399 if (negateMask
& NEGATE_Y
)
401 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
407 if (negateMask
& NEGATE_Z
)
409 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
415 if (negateMask
& NEGATE_W
)
417 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
425 _mesa_print_swizzle(GLuint swizzle
)
427 if (swizzle
== SWIZZLE_XYZW
) {
431 const char *s
= _mesa_swizzle_string(swizzle
, 0, 0);
438 _mesa_writemask_string(GLuint writeMask
)
443 if (writeMask
== WRITEMASK_XYZW
)
447 if (writeMask
& WRITEMASK_X
)
449 if (writeMask
& WRITEMASK_Y
)
451 if (writeMask
& WRITEMASK_Z
)
453 if (writeMask
& WRITEMASK_W
)
462 _mesa_condcode_string(GLuint condcode
)
465 case COND_GT
: return "GT";
466 case COND_EQ
: return "EQ";
467 case COND_LT
: return "LT";
468 case COND_UN
: return "UN";
469 case COND_GE
: return "GE";
470 case COND_LE
: return "LE";
471 case COND_NE
: return "NE";
472 case COND_TR
: return "TR";
473 case COND_FL
: return "FL";
474 default: return "cond???";
480 fprint_dst_reg(FILE * f
,
481 const struct prog_dst_register
*dstReg
,
482 gl_prog_print_mode mode
,
483 const struct gl_program
*prog
)
486 reg_string((gl_register_file
) dstReg
->File
,
487 dstReg
->Index
, mode
, dstReg
->RelAddr
, prog
,
488 GL_FALSE
, GL_FALSE
, 0),
489 _mesa_writemask_string(dstReg
->WriteMask
));
491 if (dstReg
->CondMask
!= COND_TR
) {
492 fprintf(f
, " (%s.%s)",
493 _mesa_condcode_string(dstReg
->CondMask
),
494 _mesa_swizzle_string(dstReg
->CondSwizzle
,
495 GL_FALSE
, GL_FALSE
));
499 fprintf(f
, "%s[%d]%s",
500 file_string((gl_register_file
) dstReg
->File
, mode
),
502 _mesa_writemask_string(dstReg
->WriteMask
));
508 fprint_src_reg(FILE *f
,
509 const struct prog_src_register
*srcReg
,
510 gl_prog_print_mode mode
,
511 const struct gl_program
*prog
)
513 const char *abs
= srcReg
->Abs
? "|" : "";
515 fprintf(f
, "%s%s%s%s",
517 reg_string((gl_register_file
) srcReg
->File
,
518 srcReg
->Index
, mode
, srcReg
->RelAddr
, prog
,
519 srcReg
->HasIndex2
, srcReg
->RelAddr2
, srcReg
->Index2
),
520 _mesa_swizzle_string(srcReg
->Swizzle
,
521 srcReg
->Negate
, GL_FALSE
),
524 fprintf(f
, "%s[%d]%s",
525 file_string((gl_register_file
) srcReg
->File
, mode
),
527 _mesa_swizzle_string(srcReg
->Swizzle
,
528 srcReg
->Negate
, GL_FALSE
));
534 fprint_comment(FILE *f
, const struct prog_instruction
*inst
)
537 fprintf(f
, "; # %s\n", inst
->Comment
);
544 _mesa_fprint_alu_instruction(FILE *f
,
545 const struct prog_instruction
*inst
,
546 const char *opcode_string
, GLuint numRegs
,
547 gl_prog_print_mode mode
,
548 const struct gl_program
*prog
)
552 fprintf(f
, "%s", opcode_string
);
553 if (inst
->CondUpdate
)
557 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
561 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
562 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
571 for (j
= 0; j
< numRegs
; j
++) {
572 fprint_src_reg(f
, inst
->SrcReg
+ j
, mode
, prog
);
577 fprint_comment(f
, inst
);
582 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
583 const char *opcode_string
, GLuint numRegs
)
585 _mesa_fprint_alu_instruction(stderr
, inst
, opcode_string
,
586 numRegs
, PROG_PRINT_DEBUG
, NULL
);
591 * Print a single vertex/fragment program instruction.
594 _mesa_fprint_instruction_opt(FILE *f
,
595 const struct prog_instruction
*inst
,
597 gl_prog_print_mode mode
,
598 const struct gl_program
*prog
)
602 if (inst
->Opcode
== OPCODE_ELSE
||
603 inst
->Opcode
== OPCODE_ENDIF
||
604 inst
->Opcode
== OPCODE_ENDLOOP
||
605 inst
->Opcode
== OPCODE_ENDSUB
) {
608 for (i
= 0; i
< indent
; i
++) {
612 switch (inst
->Opcode
) {
614 fprintf(f
, "PRINT '%s'", (char *) inst
->Data
);
615 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
617 fprintf(f
, "%s[%d]%s",
618 file_string((gl_register_file
) inst
->SrcReg
[0].File
,
620 inst
->SrcReg
[0].Index
,
621 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
622 inst
->SrcReg
[0].Negate
, GL_FALSE
));
625 fprintf(f
, " # %s", inst
->Comment
);
626 fprint_comment(f
, inst
);
630 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
633 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
634 fprintf(f
, ", %s[%d], %s",
635 file_string((gl_register_file
) inst
->SrcReg
[0].File
,
637 inst
->SrcReg
[0].Index
,
638 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
639 inst
->SrcReg
[0].Negate
, GL_TRUE
));
640 fprint_comment(f
, inst
);
646 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
647 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
650 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
652 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
653 fprintf(f
, ", texture[%d], ", inst
->TexSrcUnit
);
654 switch (inst
->TexSrcTarget
) {
655 case TEXTURE_1D_INDEX
: fprintf(f
, "1D"); break;
656 case TEXTURE_2D_INDEX
: fprintf(f
, "2D"); break;
657 case TEXTURE_3D_INDEX
: fprintf(f
, "3D"); break;
658 case TEXTURE_CUBE_INDEX
: fprintf(f
, "CUBE"); break;
659 case TEXTURE_RECT_INDEX
: fprintf(f
, "RECT"); break;
660 case TEXTURE_1D_ARRAY_INDEX
: fprintf(f
, "1D_ARRAY"); break;
661 case TEXTURE_2D_ARRAY_INDEX
: fprintf(f
, "2D_ARRAY"); break;
666 fprintf(f
, " SHADOW");
667 fprint_comment(f
, inst
);
671 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
673 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
674 fprint_comment(f
, inst
);
677 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
680 _mesa_condcode_string(inst
->DstReg
.CondMask
),
681 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
682 GL_FALSE
, GL_FALSE
));
683 fprint_comment(f
, inst
);
688 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
690 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
691 fprint_comment(f
, inst
);
694 fprintf(f
, "BRA %d (%s%s)",
696 _mesa_condcode_string(inst
->DstReg
.CondMask
),
697 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
698 fprint_comment(f
, inst
);
701 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
702 /* Use ordinary register */
704 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
709 fprintf(f
, "IF (%s%s);",
710 _mesa_condcode_string(inst
->DstReg
.CondMask
),
711 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
714 fprintf(f
, " # (if false, goto %d)", inst
->BranchTarget
);
715 fprint_comment(f
, inst
);
718 fprintf(f
, "ELSE; # (goto %d)\n", inst
->BranchTarget
);
721 fprintf(f
, "ENDIF;\n");
724 fprintf(f
, "BGNLOOP; # (end at %d)\n", inst
->BranchTarget
);
727 fprintf(f
, "ENDLOOP; # (goto %d)\n", inst
->BranchTarget
);
731 fprintf(f
, "%s (%s%s); # (goto %d)",
732 _mesa_opcode_string(inst
->Opcode
),
733 _mesa_condcode_string(inst
->DstReg
.CondMask
),
734 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
),
736 fprint_comment(f
, inst
);
740 if (mode
== PROG_PRINT_NV
) {
741 fprintf(f
, "%s:\n", inst
->Comment
); /* comment is label */
745 fprintf(f
, "BGNSUB");
746 fprint_comment(f
, inst
);
750 if (mode
== PROG_PRINT_DEBUG
) {
751 fprintf(f
, "ENDSUB");
752 fprint_comment(f
, inst
);
756 if (mode
== PROG_PRINT_NV
) {
757 fprintf(f
, "CAL %s; # (goto %d)\n", inst
->Comment
, inst
->BranchTarget
);
760 fprintf(f
, "CAL %u", inst
->BranchTarget
);
761 fprint_comment(f
, inst
);
765 fprintf(f
, "RET (%s%s)",
766 _mesa_condcode_string(inst
->DstReg
.CondMask
),
767 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
768 fprint_comment(f
, inst
);
775 if (mode
== PROG_PRINT_DEBUG
) {
777 fprint_comment(f
, inst
);
779 else if (inst
->Comment
) {
780 /* ARB/NV extensions don't have NOP instruction */
781 fprintf(f
, "# %s\n", inst
->Comment
);
784 case OPCODE_EMIT_VERTEX
:
785 fprintf(f
, "EMIT_VERTEX\n");
787 case OPCODE_END_PRIMITIVE
:
788 fprintf(f
, "END_PRIMITIVE\n");
790 /* XXX may need other special-case instructions */
792 if (inst
->Opcode
< MAX_OPCODE
) {
793 /* typical alu instruction */
794 _mesa_fprint_alu_instruction(f
, inst
,
795 _mesa_opcode_string(inst
->Opcode
),
796 _mesa_num_inst_src_regs(inst
->Opcode
),
800 _mesa_fprint_alu_instruction(f
, inst
,
801 _mesa_opcode_string(inst
->Opcode
),
802 3/*_mesa_num_inst_src_regs(inst->Opcode)*/,
812 _mesa_print_instruction_opt(const struct prog_instruction
*inst
,
814 gl_prog_print_mode mode
,
815 const struct gl_program
*prog
)
817 return _mesa_fprint_instruction_opt(stderr
, inst
, indent
, mode
, prog
);
822 _mesa_print_instruction(const struct prog_instruction
*inst
)
824 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
825 _mesa_fprint_instruction_opt(stderr
, inst
, 0, PROG_PRINT_DEBUG
, NULL
);
831 * Print program, with options.
834 _mesa_fprint_program_opt(FILE *f
,
835 const struct gl_program
*prog
,
836 gl_prog_print_mode mode
,
837 GLboolean lineNumbers
)
839 GLuint i
, indent
= 0;
841 switch (prog
->Target
) {
842 case GL_VERTEX_PROGRAM_ARB
:
843 if (mode
== PROG_PRINT_ARB
)
844 fprintf(f
, "!!ARBvp1.0\n");
845 else if (mode
== PROG_PRINT_NV
)
846 fprintf(f
, "!!VP1.0\n");
848 fprintf(f
, "# Vertex Program/Shader %u\n", prog
->Id
);
850 case GL_FRAGMENT_PROGRAM_ARB
:
851 case GL_FRAGMENT_PROGRAM_NV
:
852 if (mode
== PROG_PRINT_ARB
)
853 fprintf(f
, "!!ARBfp1.0\n");
854 else if (mode
== PROG_PRINT_NV
)
855 fprintf(f
, "!!FP1.0\n");
857 fprintf(f
, "# Fragment Program/Shader %u\n", prog
->Id
);
859 case MESA_GEOMETRY_PROGRAM
:
860 fprintf(f
, "# Geometry Shader\n");
863 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
865 fprintf(f
, "%3d: ", i
);
866 indent
= _mesa_fprint_instruction_opt(f
, prog
->Instructions
+ i
,
873 * Print program to stderr, default options.
876 _mesa_print_program(const struct gl_program
*prog
)
878 _mesa_fprint_program_opt(stderr
, prog
, PROG_PRINT_DEBUG
, GL_TRUE
);
883 * Return binary representation of 64-bit value (as a string).
884 * Insert a comma to separate each group of 8 bits.
885 * Note we return a pointer to local static storage so this is not
887 * XXX move to imports.[ch] if useful elsewhere.
890 binary(GLbitfield64 val
)
894 for (i
= 63; i
>= 0; --i
) {
895 if (val
& (BITFIELD64_BIT(i
)))
897 else if (len
> 0 || i
== 0)
899 if (len
> 0 && ((i
-1) % 8) == 7)
908 * Print all of a program's parameters/fields to given file.
911 _mesa_fprint_program_parameters(FILE *f
,
912 struct gl_context
*ctx
,
913 const struct gl_program
*prog
)
917 fprintf(f
, "InputsRead: 0x%x (0b%s)\n",
918 prog
->InputsRead
, binary(prog
->InputsRead
));
919 fprintf(f
, "OutputsWritten: 0x%llx (0b%s)\n",
920 (unsigned long long)prog
->OutputsWritten
,
921 binary(prog
->OutputsWritten
));
922 fprintf(f
, "NumInstructions=%d\n", prog
->NumInstructions
);
923 fprintf(f
, "NumTemporaries=%d\n", prog
->NumTemporaries
);
924 fprintf(f
, "NumParameters=%d\n", prog
->NumParameters
);
925 fprintf(f
, "NumAttributes=%d\n", prog
->NumAttributes
);
926 fprintf(f
, "NumAddressRegs=%d\n", prog
->NumAddressRegs
);
927 fprintf(f
, "IndirectRegisterFiles: 0x%x (0b%s)\n",
928 prog
->IndirectRegisterFiles
, binary(prog
->IndirectRegisterFiles
));
929 fprintf(f
, "SamplersUsed: 0x%x (0b%s)\n",
930 prog
->SamplersUsed
, binary(prog
->SamplersUsed
));
931 fprintf(f
, "Samplers=[ ");
932 for (i
= 0; i
< MAX_SAMPLERS
; i
++) {
933 fprintf(f
, "%d ", prog
->SamplerUnits
[i
]);
937 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
940 fprintf(f
, "Local Params:\n");
941 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
942 const GLfloat
*p
= prog
->LocalParams
[i
];
943 fprintf(f
, "%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
946 _mesa_print_parameter_list(prog
->Parameters
);
951 * Print all of a program's parameters/fields to stderr.
954 _mesa_print_program_parameters(struct gl_context
*ctx
, const struct gl_program
*prog
)
956 _mesa_fprint_program_parameters(stderr
, ctx
, prog
);
961 * Print a program parameter list to given file.
964 _mesa_fprint_parameter_list(FILE *f
,
965 const struct gl_program_parameter_list
*list
)
967 const gl_prog_print_mode mode
= PROG_PRINT_DEBUG
;
974 fprintf(f
, "param list %p\n", (void *) list
);
975 fprintf(f
, "dirty state flags: 0x%x\n", list
->StateFlags
);
976 for (i
= 0; i
< list
->NumParameters
; i
++){
977 struct gl_program_parameter
*param
= list
->Parameters
+ i
;
978 const GLfloat
*v
= list
->ParameterValues
[i
];
979 fprintf(f
, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
981 file_string(list
->Parameters
[i
].Type
, mode
),
982 param
->Name
, v
[0], v
[1], v
[2], v
[3]);
983 if (param
->Flags
& PROG_PARAM_BIT_CENTROID
)
984 fprintf(f
, " Centroid");
985 if (param
->Flags
& PROG_PARAM_BIT_INVARIANT
)
986 fprintf(f
, " Invariant");
987 if (param
->Flags
& PROG_PARAM_BIT_FLAT
)
989 if (param
->Flags
& PROG_PARAM_BIT_LINEAR
)
990 fprintf(f
, " Linear");
997 * Print a program parameter list to stderr.
1000 _mesa_print_parameter_list(const struct gl_program_parameter_list
*list
)
1002 _mesa_fprint_parameter_list(stderr
, list
);
1007 * Write shader and associated info to a file.
1010 _mesa_write_shader_to_file(const struct gl_shader
*shader
)
1016 if (shader
->Type
== GL_FRAGMENT_SHADER
)
1018 else if (shader
->Type
== GL_VERTEX_SHADER
)
1023 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
1024 f
= fopen(filename
, "w");
1026 fprintf(stderr
, "Unable to open %s for writing\n", filename
);
1030 fprintf(f
, "/* Shader %u source, checksum %u */\n", shader
->Name
, shader
->SourceChecksum
);
1031 fputs(shader
->Source
, f
);
1034 fprintf(f
, "/* Compile status: %s */\n",
1035 shader
->CompileStatus
? "ok" : "fail");
1036 fprintf(f
, "/* Log Info: */\n");
1037 if (shader
->InfoLog
) {
1038 fputs(shader
->InfoLog
, f
);
1040 if (shader
->CompileStatus
&& shader
->Program
) {
1041 fprintf(f
, "/* GPU code */\n");
1043 _mesa_fprint_program_opt(f
, shader
->Program
, PROG_PRINT_DEBUG
, GL_TRUE
);
1045 fprintf(f
, "/* Parameters / constants */\n");
1047 _mesa_fprint_parameter_list(f
, shader
->Program
->Parameters
);
1056 * Append the shader's uniform info/values to the shader log file.
1057 * The log file will typically have been created by the
1058 * _mesa_write_shader_to_file function.
1061 _mesa_append_uniforms_to_file(const struct gl_shader
*shader
,
1062 const struct gl_program
*prog
)
1068 if (shader
->Type
== GL_FRAGMENT_SHADER
)
1073 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
1074 f
= fopen(filename
, "a"); /* append */
1076 fprintf(stderr
, "Unable to open %s for appending\n", filename
);
1080 fprintf(f
, "/* First-draw parameters / constants */\n");
1082 _mesa_fprint_parameter_list(f
, prog
->Parameters
);