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 _mesa_register_file_name(gl_register_file f
)
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]",
279 _mesa_register_file_name(f
), addr
, index
);
281 int offset
= strlen(str
);
282 const char *addr2
= relAddr2
? "ADDR+" : "";
283 sprintf(str
+offset
, "[%s%d]", addr2
, index2
);
290 sprintf(str
, "%s", arb_input_attrib_string(index
, prog
->Target
));
293 sprintf(str
, "%s", arb_output_attrib_string(index
, prog
->Target
));
295 case PROGRAM_TEMPORARY
:
296 sprintf(str
, "temp%d", index
);
298 case PROGRAM_ENV_PARAM
:
299 sprintf(str
, "program.env[%s%d]", addr
, index
);
301 case PROGRAM_LOCAL_PARAM
:
302 sprintf(str
, "program.local[%s%d]", addr
, index
);
304 case PROGRAM_VARYING
: /* extension */
305 sprintf(str
, "varying[%s%d]", addr
, index
);
307 case PROGRAM_CONSTANT
: /* extension */
308 sprintf(str
, "constant[%s%d]", addr
, index
);
310 case PROGRAM_UNIFORM
: /* extension */
311 sprintf(str
, "uniform[%s%d]", addr
, index
);
313 case PROGRAM_STATE_VAR
:
315 struct gl_program_parameter
*param
316 = prog
->Parameters
->Parameters
+ index
;
317 char *state
= _mesa_program_state_string(param
->StateIndexes
);
318 sprintf(str
, "%s", state
);
322 case PROGRAM_ADDRESS
:
323 sprintf(str
, "A%d", index
);
326 _mesa_problem(NULL
, "bad file in reg_string()");
333 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
)
334 sprintf(str
, "v[%d]", index
);
336 sprintf(str
, "f[%d]", index
);
339 sprintf(str
, "o[%d]", index
);
341 case PROGRAM_TEMPORARY
:
342 sprintf(str
, "R%d", index
);
344 case PROGRAM_ENV_PARAM
:
345 sprintf(str
, "c[%d]", index
);
347 case PROGRAM_VARYING
: /* extension */
348 sprintf(str
, "varying[%s%d]", addr
, index
);
350 case PROGRAM_UNIFORM
: /* extension */
351 sprintf(str
, "uniform[%s%d]", addr
, index
);
353 case PROGRAM_CONSTANT
: /* extension */
354 sprintf(str
, "constant[%s%d]", addr
, index
);
356 case PROGRAM_STATE_VAR
: /* extension */
357 sprintf(str
, "state[%s%d]", addr
, index
);
360 _mesa_problem(NULL
, "bad file in reg_string()");
365 _mesa_problem(NULL
, "bad mode in reg_string()");
373 * Return a string representation of the given swizzle word.
374 * If extended is true, use extended (comma-separated) format.
375 * \param swizzle the swizzle field
376 * \param negateBase 4-bit negation vector
377 * \param extended if true, also allow 0, 1 values
380 _mesa_swizzle_string(GLuint swizzle
, GLuint negateMask
, GLboolean extended
)
382 static const char swz
[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
386 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateMask
== 0)
387 return ""; /* no swizzle/negation */
392 if (negateMask
& NEGATE_X
)
394 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
400 if (negateMask
& NEGATE_Y
)
402 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
408 if (negateMask
& NEGATE_Z
)
410 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
416 if (negateMask
& NEGATE_W
)
418 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
426 _mesa_print_swizzle(GLuint swizzle
)
428 if (swizzle
== SWIZZLE_XYZW
) {
432 const char *s
= _mesa_swizzle_string(swizzle
, 0, 0);
439 _mesa_writemask_string(GLuint writeMask
)
444 if (writeMask
== WRITEMASK_XYZW
)
448 if (writeMask
& WRITEMASK_X
)
450 if (writeMask
& WRITEMASK_Y
)
452 if (writeMask
& WRITEMASK_Z
)
454 if (writeMask
& WRITEMASK_W
)
463 _mesa_condcode_string(GLuint condcode
)
466 case COND_GT
: return "GT";
467 case COND_EQ
: return "EQ";
468 case COND_LT
: return "LT";
469 case COND_UN
: return "UN";
470 case COND_GE
: return "GE";
471 case COND_LE
: return "LE";
472 case COND_NE
: return "NE";
473 case COND_TR
: return "TR";
474 case COND_FL
: return "FL";
475 default: return "cond???";
481 fprint_dst_reg(FILE * f
,
482 const struct prog_dst_register
*dstReg
,
483 gl_prog_print_mode mode
,
484 const struct gl_program
*prog
)
487 reg_string((gl_register_file
) dstReg
->File
,
488 dstReg
->Index
, mode
, dstReg
->RelAddr
, prog
,
489 GL_FALSE
, GL_FALSE
, 0),
490 _mesa_writemask_string(dstReg
->WriteMask
));
492 if (dstReg
->CondMask
!= COND_TR
) {
493 fprintf(f
, " (%s.%s)",
494 _mesa_condcode_string(dstReg
->CondMask
),
495 _mesa_swizzle_string(dstReg
->CondSwizzle
,
496 GL_FALSE
, GL_FALSE
));
500 fprintf(f
, "%s[%d]%s",
501 _mesa_register_file_name((gl_register_file
) dstReg
->File
),
503 _mesa_writemask_string(dstReg
->WriteMask
));
509 fprint_src_reg(FILE *f
,
510 const struct prog_src_register
*srcReg
,
511 gl_prog_print_mode mode
,
512 const struct gl_program
*prog
)
514 const char *abs
= srcReg
->Abs
? "|" : "";
516 fprintf(f
, "%s%s%s%s",
518 reg_string((gl_register_file
) srcReg
->File
,
519 srcReg
->Index
, mode
, srcReg
->RelAddr
, prog
,
520 srcReg
->HasIndex2
, srcReg
->RelAddr2
, srcReg
->Index2
),
521 _mesa_swizzle_string(srcReg
->Swizzle
,
522 srcReg
->Negate
, GL_FALSE
),
525 fprintf(f
, "%s[%d]%s",
526 _mesa_register_file_name((gl_register_file
) srcReg
->File
),
528 _mesa_swizzle_string(srcReg
->Swizzle
,
529 srcReg
->Negate
, GL_FALSE
));
535 fprint_comment(FILE *f
, const struct prog_instruction
*inst
)
538 fprintf(f
, "; # %s\n", inst
->Comment
);
545 _mesa_fprint_alu_instruction(FILE *f
,
546 const struct prog_instruction
*inst
,
547 const char *opcode_string
, GLuint numRegs
,
548 gl_prog_print_mode mode
,
549 const struct gl_program
*prog
)
553 fprintf(f
, "%s", opcode_string
);
554 if (inst
->CondUpdate
)
558 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
562 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
563 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
572 for (j
= 0; j
< numRegs
; j
++) {
573 fprint_src_reg(f
, inst
->SrcReg
+ j
, mode
, prog
);
578 fprint_comment(f
, inst
);
583 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
584 const char *opcode_string
, GLuint numRegs
)
586 _mesa_fprint_alu_instruction(stderr
, inst
, opcode_string
,
587 numRegs
, PROG_PRINT_DEBUG
, NULL
);
592 * Print a single vertex/fragment program instruction.
595 _mesa_fprint_instruction_opt(FILE *f
,
596 const struct prog_instruction
*inst
,
598 gl_prog_print_mode mode
,
599 const struct gl_program
*prog
)
603 if (inst
->Opcode
== OPCODE_ELSE
||
604 inst
->Opcode
== OPCODE_ENDIF
||
605 inst
->Opcode
== OPCODE_ENDLOOP
||
606 inst
->Opcode
== OPCODE_ENDSUB
) {
609 for (i
= 0; i
< indent
; i
++) {
613 switch (inst
->Opcode
) {
615 fprintf(f
, "PRINT '%s'", (char *) inst
->Data
);
616 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
618 fprintf(f
, "%s[%d]%s",
619 _mesa_register_file_name((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 _mesa_register_file_name((gl_register_file
) inst
->SrcReg
[0].File
),
636 inst
->SrcReg
[0].Index
,
637 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
638 inst
->SrcReg
[0].Negate
, GL_TRUE
));
639 fprint_comment(f
, inst
);
645 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
646 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
649 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
651 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
652 fprintf(f
, ", texture[%d], ", inst
->TexSrcUnit
);
653 switch (inst
->TexSrcTarget
) {
654 case TEXTURE_1D_INDEX
: fprintf(f
, "1D"); break;
655 case TEXTURE_2D_INDEX
: fprintf(f
, "2D"); break;
656 case TEXTURE_3D_INDEX
: fprintf(f
, "3D"); break;
657 case TEXTURE_CUBE_INDEX
: fprintf(f
, "CUBE"); break;
658 case TEXTURE_RECT_INDEX
: fprintf(f
, "RECT"); break;
659 case TEXTURE_1D_ARRAY_INDEX
: fprintf(f
, "1D_ARRAY"); break;
660 case TEXTURE_2D_ARRAY_INDEX
: fprintf(f
, "2D_ARRAY"); break;
665 fprintf(f
, " SHADOW");
666 fprint_comment(f
, inst
);
670 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
672 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
673 fprint_comment(f
, inst
);
676 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
679 _mesa_condcode_string(inst
->DstReg
.CondMask
),
680 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
681 GL_FALSE
, GL_FALSE
));
682 fprint_comment(f
, inst
);
687 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
689 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
690 fprint_comment(f
, inst
);
693 fprintf(f
, "BRA %d (%s%s)",
695 _mesa_condcode_string(inst
->DstReg
.CondMask
),
696 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
697 fprint_comment(f
, inst
);
700 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
701 /* Use ordinary register */
703 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
708 fprintf(f
, "IF (%s%s);",
709 _mesa_condcode_string(inst
->DstReg
.CondMask
),
710 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
713 fprintf(f
, " # (if false, goto %d)", inst
->BranchTarget
);
714 fprint_comment(f
, inst
);
717 fprintf(f
, "ELSE; # (goto %d)\n", inst
->BranchTarget
);
720 fprintf(f
, "ENDIF;\n");
723 fprintf(f
, "BGNLOOP; # (end at %d)\n", inst
->BranchTarget
);
726 fprintf(f
, "ENDLOOP; # (goto %d)\n", inst
->BranchTarget
);
730 fprintf(f
, "%s (%s%s); # (goto %d)",
731 _mesa_opcode_string(inst
->Opcode
),
732 _mesa_condcode_string(inst
->DstReg
.CondMask
),
733 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
),
735 fprint_comment(f
, inst
);
739 if (mode
== PROG_PRINT_NV
) {
740 fprintf(f
, "%s:\n", inst
->Comment
); /* comment is label */
744 fprintf(f
, "BGNSUB");
745 fprint_comment(f
, inst
);
749 if (mode
== PROG_PRINT_DEBUG
) {
750 fprintf(f
, "ENDSUB");
751 fprint_comment(f
, inst
);
755 if (mode
== PROG_PRINT_NV
) {
756 fprintf(f
, "CAL %s; # (goto %d)\n", inst
->Comment
, inst
->BranchTarget
);
759 fprintf(f
, "CAL %u", inst
->BranchTarget
);
760 fprint_comment(f
, inst
);
764 fprintf(f
, "RET (%s%s)",
765 _mesa_condcode_string(inst
->DstReg
.CondMask
),
766 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
767 fprint_comment(f
, inst
);
774 if (mode
== PROG_PRINT_DEBUG
) {
776 fprint_comment(f
, inst
);
778 else if (inst
->Comment
) {
779 /* ARB/NV extensions don't have NOP instruction */
780 fprintf(f
, "# %s\n", inst
->Comment
);
783 case OPCODE_EMIT_VERTEX
:
784 fprintf(f
, "EMIT_VERTEX\n");
786 case OPCODE_END_PRIMITIVE
:
787 fprintf(f
, "END_PRIMITIVE\n");
789 /* XXX may need other special-case instructions */
791 if (inst
->Opcode
< MAX_OPCODE
) {
792 /* typical alu instruction */
793 _mesa_fprint_alu_instruction(f
, inst
,
794 _mesa_opcode_string(inst
->Opcode
),
795 _mesa_num_inst_src_regs(inst
->Opcode
),
799 _mesa_fprint_alu_instruction(f
, inst
,
800 _mesa_opcode_string(inst
->Opcode
),
801 3/*_mesa_num_inst_src_regs(inst->Opcode)*/,
811 _mesa_print_instruction_opt(const struct prog_instruction
*inst
,
813 gl_prog_print_mode mode
,
814 const struct gl_program
*prog
)
816 return _mesa_fprint_instruction_opt(stderr
, inst
, indent
, mode
, prog
);
821 _mesa_print_instruction(const struct prog_instruction
*inst
)
823 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
824 _mesa_fprint_instruction_opt(stderr
, inst
, 0, PROG_PRINT_DEBUG
, NULL
);
830 * Print program, with options.
833 _mesa_fprint_program_opt(FILE *f
,
834 const struct gl_program
*prog
,
835 gl_prog_print_mode mode
,
836 GLboolean lineNumbers
)
838 GLuint i
, indent
= 0;
840 switch (prog
->Target
) {
841 case GL_VERTEX_PROGRAM_ARB
:
842 if (mode
== PROG_PRINT_ARB
)
843 fprintf(f
, "!!ARBvp1.0\n");
844 else if (mode
== PROG_PRINT_NV
)
845 fprintf(f
, "!!VP1.0\n");
847 fprintf(f
, "# Vertex Program/Shader %u\n", prog
->Id
);
849 case GL_FRAGMENT_PROGRAM_ARB
:
850 case GL_FRAGMENT_PROGRAM_NV
:
851 if (mode
== PROG_PRINT_ARB
)
852 fprintf(f
, "!!ARBfp1.0\n");
853 else if (mode
== PROG_PRINT_NV
)
854 fprintf(f
, "!!FP1.0\n");
856 fprintf(f
, "# Fragment Program/Shader %u\n", prog
->Id
);
858 case MESA_GEOMETRY_PROGRAM
:
859 fprintf(f
, "# Geometry Shader\n");
862 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
864 fprintf(f
, "%3d: ", i
);
865 indent
= _mesa_fprint_instruction_opt(f
, prog
->Instructions
+ i
,
872 * Print program to stderr, default options.
875 _mesa_print_program(const struct gl_program
*prog
)
877 _mesa_fprint_program_opt(stderr
, prog
, PROG_PRINT_DEBUG
, GL_TRUE
);
882 * Return binary representation of 64-bit value (as a string).
883 * Insert a comma to separate each group of 8 bits.
884 * Note we return a pointer to local static storage so this is not
886 * XXX move to imports.[ch] if useful elsewhere.
889 binary(GLbitfield64 val
)
893 for (i
= 63; i
>= 0; --i
) {
894 if (val
& (BITFIELD64_BIT(i
)))
896 else if (len
> 0 || i
== 0)
898 if (len
> 0 && ((i
-1) % 8) == 7)
907 * Print all of a program's parameters/fields to given file.
910 _mesa_fprint_program_parameters(FILE *f
,
911 struct gl_context
*ctx
,
912 const struct gl_program
*prog
)
916 fprintf(f
, "InputsRead: 0x%x (0b%s)\n",
917 prog
->InputsRead
, binary(prog
->InputsRead
));
918 fprintf(f
, "OutputsWritten: 0x%llx (0b%s)\n",
919 (unsigned long long)prog
->OutputsWritten
,
920 binary(prog
->OutputsWritten
));
921 fprintf(f
, "NumInstructions=%d\n", prog
->NumInstructions
);
922 fprintf(f
, "NumTemporaries=%d\n", prog
->NumTemporaries
);
923 fprintf(f
, "NumParameters=%d\n", prog
->NumParameters
);
924 fprintf(f
, "NumAttributes=%d\n", prog
->NumAttributes
);
925 fprintf(f
, "NumAddressRegs=%d\n", prog
->NumAddressRegs
);
926 fprintf(f
, "IndirectRegisterFiles: 0x%x (0b%s)\n",
927 prog
->IndirectRegisterFiles
, binary(prog
->IndirectRegisterFiles
));
928 fprintf(f
, "SamplersUsed: 0x%x (0b%s)\n",
929 prog
->SamplersUsed
, binary(prog
->SamplersUsed
));
930 fprintf(f
, "Samplers=[ ");
931 for (i
= 0; i
< MAX_SAMPLERS
; i
++) {
932 fprintf(f
, "%d ", prog
->SamplerUnits
[i
]);
936 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
939 fprintf(f
, "Local Params:\n");
940 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
941 const GLfloat
*p
= prog
->LocalParams
[i
];
942 fprintf(f
, "%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
945 _mesa_print_parameter_list(prog
->Parameters
);
950 * Print all of a program's parameters/fields to stderr.
953 _mesa_print_program_parameters(struct gl_context
*ctx
, const struct gl_program
*prog
)
955 _mesa_fprint_program_parameters(stderr
, ctx
, prog
);
960 * Print a program parameter list to given file.
963 _mesa_fprint_parameter_list(FILE *f
,
964 const struct gl_program_parameter_list
*list
)
972 fprintf(f
, "param list %p\n", (void *) list
);
973 fprintf(f
, "dirty state flags: 0x%x\n", list
->StateFlags
);
974 for (i
= 0; i
< list
->NumParameters
; i
++){
975 struct gl_program_parameter
*param
= list
->Parameters
+ i
;
976 const GLfloat
*v
= list
->ParameterValues
[i
];
977 fprintf(f
, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
979 _mesa_register_file_name(list
->Parameters
[i
].Type
),
980 param
->Name
, v
[0], v
[1], v
[2], v
[3]);
981 if (param
->Flags
& PROG_PARAM_BIT_CENTROID
)
982 fprintf(f
, " Centroid");
983 if (param
->Flags
& PROG_PARAM_BIT_INVARIANT
)
984 fprintf(f
, " Invariant");
985 if (param
->Flags
& PROG_PARAM_BIT_FLAT
)
987 if (param
->Flags
& PROG_PARAM_BIT_LINEAR
)
988 fprintf(f
, " Linear");
995 * Print a program parameter list to stderr.
998 _mesa_print_parameter_list(const struct gl_program_parameter_list
*list
)
1000 _mesa_fprint_parameter_list(stderr
, list
);
1005 * Write shader and associated info to a file.
1008 _mesa_write_shader_to_file(const struct gl_shader
*shader
)
1014 if (shader
->Type
== GL_FRAGMENT_SHADER
)
1016 else if (shader
->Type
== GL_VERTEX_SHADER
)
1021 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
1022 f
= fopen(filename
, "w");
1024 fprintf(stderr
, "Unable to open %s for writing\n", filename
);
1028 fprintf(f
, "/* Shader %u source, checksum %u */\n", shader
->Name
, shader
->SourceChecksum
);
1029 fputs(shader
->Source
, f
);
1032 fprintf(f
, "/* Compile status: %s */\n",
1033 shader
->CompileStatus
? "ok" : "fail");
1034 fprintf(f
, "/* Log Info: */\n");
1035 if (shader
->InfoLog
) {
1036 fputs(shader
->InfoLog
, f
);
1038 if (shader
->CompileStatus
&& shader
->Program
) {
1039 fprintf(f
, "/* GPU code */\n");
1041 _mesa_fprint_program_opt(f
, shader
->Program
, PROG_PRINT_DEBUG
, GL_TRUE
);
1043 fprintf(f
, "/* Parameters / constants */\n");
1045 _mesa_fprint_parameter_list(f
, shader
->Program
->Parameters
);
1054 * Append the shader's uniform info/values to the shader log file.
1055 * The log file will typically have been created by the
1056 * _mesa_write_shader_to_file function.
1059 _mesa_append_uniforms_to_file(const struct gl_shader
*shader
,
1060 const struct gl_program
*prog
)
1066 if (shader
->Type
== GL_FRAGMENT_SHADER
)
1071 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
1072 f
= fopen(filename
, "a"); /* append */
1074 fprintf(stderr
, "Unable to open %s for appending\n", filename
);
1078 fprintf(f
, "/* First-draw parameters / constants */\n");
1080 _mesa_fprint_parameter_list(f
, prog
->Parameters
);