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_SYSTEM_VALUE
:
77 case PROGRAM_UNDEFINED
:
82 _mesa_snprintf(s
, sizeof(s
), "FILE%u", f
);
90 * Return ARB_v/f_prog-style input attrib string.
93 arb_input_attrib_string(GLint index
, GLenum progType
)
96 * These strings should match the VERT_ATTRIB_x and FRAG_ATTRIB_x tokens.
98 const char *vertAttribs
[] = {
102 "vertex.color.primary",
103 "vertex.color.secondary",
107 "vertex.texcoord[0]",
108 "vertex.texcoord[1]",
109 "vertex.texcoord[2]",
110 "vertex.texcoord[3]",
111 "vertex.texcoord[4]",
112 "vertex.texcoord[5]",
113 "vertex.texcoord[6]",
114 "vertex.texcoord[7]",
132 const char *fragAttribs
[] = {
134 "fragment.color.primary",
135 "fragment.color.secondary",
137 "fragment.texcoord[0]",
138 "fragment.texcoord[1]",
139 "fragment.texcoord[2]",
140 "fragment.texcoord[3]",
141 "fragment.texcoord[4]",
142 "fragment.texcoord[5]",
143 "fragment.texcoord[6]",
144 "fragment.texcoord[7]",
145 "fragment.varying[0]",
146 "fragment.varying[1]",
147 "fragment.varying[2]",
148 "fragment.varying[3]",
149 "fragment.varying[4]",
150 "fragment.varying[5]",
151 "fragment.varying[6]",
152 "fragment.varying[7]"
156 assert(strcmp(vertAttribs
[VERT_ATTRIB_TEX0
], "vertex.texcoord[0]") == 0);
157 assert(strcmp(vertAttribs
[VERT_ATTRIB_GENERIC15
], "vertex.attrib[15]") == 0);
159 if (progType
== GL_VERTEX_PROGRAM_ARB
) {
160 assert(index
< sizeof(vertAttribs
) / sizeof(vertAttribs
[0]));
161 return vertAttribs
[index
];
164 assert(index
< sizeof(fragAttribs
) / sizeof(fragAttribs
[0]));
165 return fragAttribs
[index
];
171 * Print a vertex program's InputsRead field in human-readable format.
175 _mesa_print_vp_inputs(GLbitfield inputs
)
177 printf("VP Inputs 0x%x: \n", inputs
);
179 GLint attr
= _mesa_ffs(inputs
) - 1;
180 const char *name
= arb_input_attrib_string(attr
,
181 GL_VERTEX_PROGRAM_ARB
);
182 printf(" %d: %s\n", attr
, name
);
183 inputs
&= ~(1 << attr
);
189 * Print a fragment program's InputsRead field in human-readable format.
193 _mesa_print_fp_inputs(GLbitfield inputs
)
195 printf("FP Inputs 0x%x: \n", inputs
);
197 GLint attr
= _mesa_ffs(inputs
) - 1;
198 const char *name
= arb_input_attrib_string(attr
,
199 GL_FRAGMENT_PROGRAM_ARB
);
200 printf(" %d: %s\n", attr
, name
);
201 inputs
&= ~(1 << attr
);
208 * Return ARB_v/f_prog-style output attrib string.
211 arb_output_attrib_string(GLint index
, GLenum progType
)
214 * These strings should match the VERT_RESULT_x and FRAG_RESULT_x tokens.
216 const char *vertResults
[] = {
218 "result.color.primary",
219 "result.color.secondary",
221 "result.texcoord[0]",
222 "result.texcoord[1]",
223 "result.texcoord[2]",
224 "result.texcoord[3]",
225 "result.texcoord[4]",
226 "result.texcoord[5]",
227 "result.texcoord[6]",
228 "result.texcoord[7]",
238 const char *fragResults
[] = {
240 "result.color(half)",
248 if (progType
== GL_VERTEX_PROGRAM_ARB
) {
249 assert(index
< sizeof(vertResults
) / sizeof(vertResults
[0]));
250 return vertResults
[index
];
253 assert(index
< sizeof(fragResults
) / sizeof(fragResults
[0]));
254 return fragResults
[index
];
260 * Return string representation of the given register.
261 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
262 * by the ARB/NV program languages so we've taken some liberties here.
263 * \param f the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
264 * \param index number of the register in the register file
265 * \param mode the output format/mode/style
266 * \param prog pointer to containing program
269 reg_string(gl_register_file f
, GLint index
, gl_prog_print_mode mode
,
270 GLboolean relAddr
, const struct gl_program
*prog
,
271 GLboolean hasIndex2
, GLboolean relAddr2
, GLint index2
)
273 static char str
[100];
274 const char *addr
= relAddr
? "ADDR+" : "";
279 case PROG_PRINT_DEBUG
:
280 sprintf(str
, "%s[%s%d]",
281 _mesa_register_file_name(f
), addr
, index
);
283 int offset
= strlen(str
);
284 const char *addr2
= relAddr2
? "ADDR+" : "";
285 sprintf(str
+offset
, "[%s%d]", addr2
, index2
);
292 sprintf(str
, "%s", arb_input_attrib_string(index
, prog
->Target
));
295 sprintf(str
, "%s", arb_output_attrib_string(index
, prog
->Target
));
297 case PROGRAM_TEMPORARY
:
298 sprintf(str
, "temp%d", index
);
300 case PROGRAM_ENV_PARAM
:
301 sprintf(str
, "program.env[%s%d]", addr
, index
);
303 case PROGRAM_LOCAL_PARAM
:
304 sprintf(str
, "program.local[%s%d]", addr
, index
);
306 case PROGRAM_VARYING
: /* extension */
307 sprintf(str
, "varying[%s%d]", addr
, index
);
309 case PROGRAM_CONSTANT
: /* extension */
310 sprintf(str
, "constant[%s%d]", addr
, index
);
312 case PROGRAM_UNIFORM
: /* extension */
313 sprintf(str
, "uniform[%s%d]", addr
, index
);
315 case PROGRAM_SYSTEM_VALUE
:
316 sprintf(str
, "sysvalue[%s%d]", addr
, index
);
318 case PROGRAM_STATE_VAR
:
320 struct gl_program_parameter
*param
321 = prog
->Parameters
->Parameters
+ index
;
322 char *state
= _mesa_program_state_string(param
->StateIndexes
);
323 sprintf(str
, "%s", state
);
327 case PROGRAM_ADDRESS
:
328 sprintf(str
, "A%d", index
);
331 _mesa_problem(NULL
, "bad file in reg_string()");
338 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
)
339 sprintf(str
, "v[%d]", index
);
341 sprintf(str
, "f[%d]", index
);
344 sprintf(str
, "o[%d]", index
);
346 case PROGRAM_TEMPORARY
:
347 sprintf(str
, "R%d", index
);
349 case PROGRAM_ENV_PARAM
:
350 sprintf(str
, "c[%d]", index
);
352 case PROGRAM_VARYING
: /* extension */
353 sprintf(str
, "varying[%s%d]", addr
, index
);
355 case PROGRAM_UNIFORM
: /* extension */
356 sprintf(str
, "uniform[%s%d]", addr
, index
);
358 case PROGRAM_CONSTANT
: /* extension */
359 sprintf(str
, "constant[%s%d]", addr
, index
);
361 case PROGRAM_STATE_VAR
: /* extension */
362 sprintf(str
, "state[%s%d]", addr
, index
);
365 _mesa_problem(NULL
, "bad file in reg_string()");
370 _mesa_problem(NULL
, "bad mode in reg_string()");
378 * Return a string representation of the given swizzle word.
379 * If extended is true, use extended (comma-separated) format.
380 * \param swizzle the swizzle field
381 * \param negateBase 4-bit negation vector
382 * \param extended if true, also allow 0, 1 values
385 _mesa_swizzle_string(GLuint swizzle
, GLuint negateMask
, GLboolean extended
)
387 static const char swz
[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
391 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateMask
== 0)
392 return ""; /* no swizzle/negation */
397 if (negateMask
& NEGATE_X
)
399 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
405 if (negateMask
& NEGATE_Y
)
407 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
413 if (negateMask
& NEGATE_Z
)
415 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
421 if (negateMask
& NEGATE_W
)
423 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
431 _mesa_print_swizzle(GLuint swizzle
)
433 if (swizzle
== SWIZZLE_XYZW
) {
437 const char *s
= _mesa_swizzle_string(swizzle
, 0, 0);
444 _mesa_writemask_string(GLuint writeMask
)
449 if (writeMask
== WRITEMASK_XYZW
)
453 if (writeMask
& WRITEMASK_X
)
455 if (writeMask
& WRITEMASK_Y
)
457 if (writeMask
& WRITEMASK_Z
)
459 if (writeMask
& WRITEMASK_W
)
468 _mesa_condcode_string(GLuint condcode
)
471 case COND_GT
: return "GT";
472 case COND_EQ
: return "EQ";
473 case COND_LT
: return "LT";
474 case COND_UN
: return "UN";
475 case COND_GE
: return "GE";
476 case COND_LE
: return "LE";
477 case COND_NE
: return "NE";
478 case COND_TR
: return "TR";
479 case COND_FL
: return "FL";
480 default: return "cond???";
486 fprint_dst_reg(FILE * f
,
487 const struct prog_dst_register
*dstReg
,
488 gl_prog_print_mode mode
,
489 const struct gl_program
*prog
)
492 reg_string((gl_register_file
) dstReg
->File
,
493 dstReg
->Index
, mode
, dstReg
->RelAddr
, prog
,
494 GL_FALSE
, GL_FALSE
, 0),
495 _mesa_writemask_string(dstReg
->WriteMask
));
497 if (dstReg
->CondMask
!= COND_TR
) {
498 fprintf(f
, " (%s.%s)",
499 _mesa_condcode_string(dstReg
->CondMask
),
500 _mesa_swizzle_string(dstReg
->CondSwizzle
,
501 GL_FALSE
, GL_FALSE
));
505 fprintf(f
, "%s[%d]%s",
506 _mesa_register_file_name((gl_register_file
) dstReg
->File
),
508 _mesa_writemask_string(dstReg
->WriteMask
));
514 fprint_src_reg(FILE *f
,
515 const struct prog_src_register
*srcReg
,
516 gl_prog_print_mode mode
,
517 const struct gl_program
*prog
)
519 const char *abs
= srcReg
->Abs
? "|" : "";
521 fprintf(f
, "%s%s%s%s",
523 reg_string((gl_register_file
) srcReg
->File
,
524 srcReg
->Index
, mode
, srcReg
->RelAddr
, prog
,
525 srcReg
->HasIndex2
, srcReg
->RelAddr2
, srcReg
->Index2
),
526 _mesa_swizzle_string(srcReg
->Swizzle
,
527 srcReg
->Negate
, GL_FALSE
),
530 fprintf(f
, "%s[%d]%s",
531 _mesa_register_file_name((gl_register_file
) srcReg
->File
),
533 _mesa_swizzle_string(srcReg
->Swizzle
,
534 srcReg
->Negate
, GL_FALSE
));
540 fprint_comment(FILE *f
, const struct prog_instruction
*inst
)
543 fprintf(f
, "; # %s\n", inst
->Comment
);
550 _mesa_fprint_alu_instruction(FILE *f
,
551 const struct prog_instruction
*inst
,
552 const char *opcode_string
, GLuint numRegs
,
553 gl_prog_print_mode mode
,
554 const struct gl_program
*prog
)
558 fprintf(f
, "%s", opcode_string
);
559 if (inst
->CondUpdate
)
563 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
567 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
568 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
577 for (j
= 0; j
< numRegs
; j
++) {
578 fprint_src_reg(f
, inst
->SrcReg
+ j
, mode
, prog
);
583 fprint_comment(f
, inst
);
588 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
589 const char *opcode_string
, GLuint numRegs
)
591 _mesa_fprint_alu_instruction(stderr
, inst
, opcode_string
,
592 numRegs
, PROG_PRINT_DEBUG
, NULL
);
597 * Print a single vertex/fragment program instruction.
600 _mesa_fprint_instruction_opt(FILE *f
,
601 const struct prog_instruction
*inst
,
603 gl_prog_print_mode mode
,
604 const struct gl_program
*prog
)
608 if (inst
->Opcode
== OPCODE_ELSE
||
609 inst
->Opcode
== OPCODE_ENDIF
||
610 inst
->Opcode
== OPCODE_ENDLOOP
||
611 inst
->Opcode
== OPCODE_ENDSUB
) {
614 for (i
= 0; i
< indent
; i
++) {
618 switch (inst
->Opcode
) {
620 fprintf(f
, "PRINT '%s'", (char *) inst
->Data
);
621 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
623 fprintf(f
, "%s[%d]%s",
624 _mesa_register_file_name((gl_register_file
) inst
->SrcReg
[0].File
),
625 inst
->SrcReg
[0].Index
,
626 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
627 inst
->SrcReg
[0].Negate
, GL_FALSE
));
630 fprintf(f
, " # %s", inst
->Comment
);
631 fprint_comment(f
, inst
);
635 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
638 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
639 fprintf(f
, ", %s[%d], %s",
640 _mesa_register_file_name((gl_register_file
) inst
->SrcReg
[0].File
),
641 inst
->SrcReg
[0].Index
,
642 _mesa_swizzle_string(inst
->SrcReg
[0].Swizzle
,
643 inst
->SrcReg
[0].Negate
, GL_TRUE
));
644 fprint_comment(f
, inst
);
651 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
652 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
655 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
657 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
658 if (inst
->Opcode
== OPCODE_TXD
) {
660 fprint_src_reg(f
, &inst
->SrcReg
[1], mode
, prog
);
662 fprint_src_reg(f
, &inst
->SrcReg
[2], mode
, prog
);
664 fprintf(f
, ", texture[%d], ", inst
->TexSrcUnit
);
665 switch (inst
->TexSrcTarget
) {
666 case TEXTURE_1D_INDEX
: fprintf(f
, "1D"); break;
667 case TEXTURE_2D_INDEX
: fprintf(f
, "2D"); break;
668 case TEXTURE_3D_INDEX
: fprintf(f
, "3D"); break;
669 case TEXTURE_CUBE_INDEX
: fprintf(f
, "CUBE"); break;
670 case TEXTURE_RECT_INDEX
: fprintf(f
, "RECT"); break;
671 case TEXTURE_1D_ARRAY_INDEX
: fprintf(f
, "1D_ARRAY"); break;
672 case TEXTURE_2D_ARRAY_INDEX
: fprintf(f
, "2D_ARRAY"); break;
677 fprintf(f
, " SHADOW");
678 fprint_comment(f
, inst
);
682 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
684 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
685 fprint_comment(f
, inst
);
688 fprintf(f
, "%s", _mesa_opcode_string(inst
->Opcode
));
691 _mesa_condcode_string(inst
->DstReg
.CondMask
),
692 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
693 GL_FALSE
, GL_FALSE
));
694 fprint_comment(f
, inst
);
699 fprint_dst_reg(f
, &inst
->DstReg
, mode
, prog
);
701 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
702 fprint_comment(f
, inst
);
705 fprintf(f
, "BRA %d (%s%s)",
707 _mesa_condcode_string(inst
->DstReg
.CondMask
),
708 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
709 fprint_comment(f
, inst
);
712 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
713 /* Use ordinary register */
715 fprint_src_reg(f
, &inst
->SrcReg
[0], mode
, prog
);
720 fprintf(f
, "IF (%s%s);",
721 _mesa_condcode_string(inst
->DstReg
.CondMask
),
722 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
,
725 fprintf(f
, " # (if false, goto %d)", inst
->BranchTarget
);
726 fprint_comment(f
, inst
);
729 fprintf(f
, "ELSE; # (goto %d)\n", inst
->BranchTarget
);
732 fprintf(f
, "ENDIF;\n");
735 fprintf(f
, "BGNLOOP; # (end at %d)\n", inst
->BranchTarget
);
738 fprintf(f
, "ENDLOOP; # (goto %d)\n", inst
->BranchTarget
);
742 fprintf(f
, "%s (%s%s); # (goto %d)",
743 _mesa_opcode_string(inst
->Opcode
),
744 _mesa_condcode_string(inst
->DstReg
.CondMask
),
745 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
),
747 fprint_comment(f
, inst
);
751 if (mode
== PROG_PRINT_NV
) {
752 fprintf(f
, "%s:\n", inst
->Comment
); /* comment is label */
756 fprintf(f
, "BGNSUB");
757 fprint_comment(f
, inst
);
761 if (mode
== PROG_PRINT_DEBUG
) {
762 fprintf(f
, "ENDSUB");
763 fprint_comment(f
, inst
);
767 if (mode
== PROG_PRINT_NV
) {
768 fprintf(f
, "CAL %s; # (goto %d)\n", inst
->Comment
, inst
->BranchTarget
);
771 fprintf(f
, "CAL %u", inst
->BranchTarget
);
772 fprint_comment(f
, inst
);
776 fprintf(f
, "RET (%s%s)",
777 _mesa_condcode_string(inst
->DstReg
.CondMask
),
778 _mesa_swizzle_string(inst
->DstReg
.CondSwizzle
, 0, GL_FALSE
));
779 fprint_comment(f
, inst
);
786 if (mode
== PROG_PRINT_DEBUG
) {
788 fprint_comment(f
, inst
);
790 else if (inst
->Comment
) {
791 /* ARB/NV extensions don't have NOP instruction */
792 fprintf(f
, "# %s\n", inst
->Comment
);
795 case OPCODE_EMIT_VERTEX
:
796 fprintf(f
, "EMIT_VERTEX\n");
798 case OPCODE_END_PRIMITIVE
:
799 fprintf(f
, "END_PRIMITIVE\n");
801 /* XXX may need other special-case instructions */
803 if (inst
->Opcode
< MAX_OPCODE
) {
804 /* typical alu instruction */
805 _mesa_fprint_alu_instruction(f
, inst
,
806 _mesa_opcode_string(inst
->Opcode
),
807 _mesa_num_inst_src_regs(inst
->Opcode
),
811 _mesa_fprint_alu_instruction(f
, inst
,
812 _mesa_opcode_string(inst
->Opcode
),
813 3/*_mesa_num_inst_src_regs(inst->Opcode)*/,
823 _mesa_print_instruction_opt(const struct prog_instruction
*inst
,
825 gl_prog_print_mode mode
,
826 const struct gl_program
*prog
)
828 return _mesa_fprint_instruction_opt(stderr
, inst
, indent
, mode
, prog
);
833 _mesa_print_instruction(const struct prog_instruction
*inst
)
835 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
836 _mesa_fprint_instruction_opt(stderr
, inst
, 0, PROG_PRINT_DEBUG
, NULL
);
842 * Print program, with options.
845 _mesa_fprint_program_opt(FILE *f
,
846 const struct gl_program
*prog
,
847 gl_prog_print_mode mode
,
848 GLboolean lineNumbers
)
850 GLuint i
, indent
= 0;
852 switch (prog
->Target
) {
853 case GL_VERTEX_PROGRAM_ARB
:
854 if (mode
== PROG_PRINT_ARB
)
855 fprintf(f
, "!!ARBvp1.0\n");
856 else if (mode
== PROG_PRINT_NV
)
857 fprintf(f
, "!!VP1.0\n");
859 fprintf(f
, "# Vertex Program/Shader %u\n", prog
->Id
);
861 case GL_FRAGMENT_PROGRAM_ARB
:
862 case GL_FRAGMENT_PROGRAM_NV
:
863 if (mode
== PROG_PRINT_ARB
)
864 fprintf(f
, "!!ARBfp1.0\n");
865 else if (mode
== PROG_PRINT_NV
)
866 fprintf(f
, "!!FP1.0\n");
868 fprintf(f
, "# Fragment Program/Shader %u\n", prog
->Id
);
870 case MESA_GEOMETRY_PROGRAM
:
871 fprintf(f
, "# Geometry Shader\n");
874 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
876 fprintf(f
, "%3d: ", i
);
877 indent
= _mesa_fprint_instruction_opt(f
, prog
->Instructions
+ i
,
884 * Print program to stderr, default options.
887 _mesa_print_program(const struct gl_program
*prog
)
889 _mesa_fprint_program_opt(stderr
, prog
, PROG_PRINT_DEBUG
, GL_TRUE
);
894 * Return binary representation of 64-bit value (as a string).
895 * Insert a comma to separate each group of 8 bits.
896 * Note we return a pointer to local static storage so this is not
898 * XXX move to imports.[ch] if useful elsewhere.
901 binary(GLbitfield64 val
)
905 for (i
= 63; i
>= 0; --i
) {
906 if (val
& (BITFIELD64_BIT(i
)))
908 else if (len
> 0 || i
== 0)
910 if (len
> 0 && ((i
-1) % 8) == 7)
919 * Print all of a program's parameters/fields to given file.
922 _mesa_fprint_program_parameters(FILE *f
,
923 struct gl_context
*ctx
,
924 const struct gl_program
*prog
)
928 fprintf(f
, "InputsRead: 0x%x (0b%s)\n",
929 prog
->InputsRead
, binary(prog
->InputsRead
));
930 fprintf(f
, "OutputsWritten: 0x%llx (0b%s)\n",
931 (unsigned long long)prog
->OutputsWritten
,
932 binary(prog
->OutputsWritten
));
933 fprintf(f
, "NumInstructions=%d\n", prog
->NumInstructions
);
934 fprintf(f
, "NumTemporaries=%d\n", prog
->NumTemporaries
);
935 fprintf(f
, "NumParameters=%d\n", prog
->NumParameters
);
936 fprintf(f
, "NumAttributes=%d\n", prog
->NumAttributes
);
937 fprintf(f
, "NumAddressRegs=%d\n", prog
->NumAddressRegs
);
938 fprintf(f
, "IndirectRegisterFiles: 0x%x (0b%s)\n",
939 prog
->IndirectRegisterFiles
, binary(prog
->IndirectRegisterFiles
));
940 fprintf(f
, "SamplersUsed: 0x%x (0b%s)\n",
941 prog
->SamplersUsed
, binary(prog
->SamplersUsed
));
942 fprintf(f
, "Samplers=[ ");
943 for (i
= 0; i
< MAX_SAMPLERS
; i
++) {
944 fprintf(f
, "%d ", prog
->SamplerUnits
[i
]);
948 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
951 fprintf(f
, "Local Params:\n");
952 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
953 const GLfloat
*p
= prog
->LocalParams
[i
];
954 fprintf(f
, "%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
957 _mesa_print_parameter_list(prog
->Parameters
);
962 * Print all of a program's parameters/fields to stderr.
965 _mesa_print_program_parameters(struct gl_context
*ctx
, const struct gl_program
*prog
)
967 _mesa_fprint_program_parameters(stderr
, ctx
, prog
);
972 * Print a program parameter list to given file.
975 _mesa_fprint_parameter_list(FILE *f
,
976 const struct gl_program_parameter_list
*list
)
984 fprintf(f
, "param list %p\n", (void *) list
);
985 fprintf(f
, "dirty state flags: 0x%x\n", list
->StateFlags
);
986 for (i
= 0; i
< list
->NumParameters
; i
++){
987 struct gl_program_parameter
*param
= list
->Parameters
+ i
;
988 const GLfloat
*v
= list
->ParameterValues
[i
];
989 fprintf(f
, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
991 _mesa_register_file_name(list
->Parameters
[i
].Type
),
992 param
->Name
, v
[0], v
[1], v
[2], v
[3]);
993 if (param
->Flags
& PROG_PARAM_BIT_CENTROID
)
994 fprintf(f
, " Centroid");
995 if (param
->Flags
& PROG_PARAM_BIT_INVARIANT
)
996 fprintf(f
, " Invariant");
997 if (param
->Flags
& PROG_PARAM_BIT_FLAT
)
999 if (param
->Flags
& PROG_PARAM_BIT_LINEAR
)
1000 fprintf(f
, " Linear");
1007 * Print a program parameter list to stderr.
1010 _mesa_print_parameter_list(const struct gl_program_parameter_list
*list
)
1012 _mesa_fprint_parameter_list(stderr
, list
);
1017 * Write shader and associated info to a file.
1020 _mesa_write_shader_to_file(const struct gl_shader
*shader
)
1026 if (shader
->Type
== GL_FRAGMENT_SHADER
)
1028 else if (shader
->Type
== GL_VERTEX_SHADER
)
1033 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
1034 f
= fopen(filename
, "w");
1036 fprintf(stderr
, "Unable to open %s for writing\n", filename
);
1040 fprintf(f
, "/* Shader %u source, checksum %u */\n", shader
->Name
, shader
->SourceChecksum
);
1041 fputs(shader
->Source
, f
);
1044 fprintf(f
, "/* Compile status: %s */\n",
1045 shader
->CompileStatus
? "ok" : "fail");
1046 fprintf(f
, "/* Log Info: */\n");
1047 if (shader
->InfoLog
) {
1048 fputs(shader
->InfoLog
, f
);
1050 if (shader
->CompileStatus
&& shader
->Program
) {
1051 fprintf(f
, "/* GPU code */\n");
1053 _mesa_fprint_program_opt(f
, shader
->Program
, PROG_PRINT_DEBUG
, GL_TRUE
);
1055 fprintf(f
, "/* Parameters / constants */\n");
1057 _mesa_fprint_parameter_list(f
, shader
->Program
->Parameters
);
1066 * Append the shader's uniform info/values to the shader log file.
1067 * The log file will typically have been created by the
1068 * _mesa_write_shader_to_file function.
1071 _mesa_append_uniforms_to_file(const struct gl_shader
*shader
,
1072 const struct gl_program
*prog
)
1078 if (shader
->Type
== GL_FRAGMENT_SHADER
)
1083 _mesa_snprintf(filename
, sizeof(filename
), "shader_%u.%s", shader
->Name
, type
);
1084 f
= fopen(filename
, "a"); /* append */
1086 fprintf(stderr
, "Unable to open %s for appending\n", filename
);
1090 fprintf(f
, "/* First-draw parameters / constants */\n");
1092 _mesa_fprint_parameter_list(f
, prog
->Parameters
);