2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Print vertex/fragment programs - for debugging.
36 #include "prog_instruction.h"
37 #include "prog_parameter.h"
38 #include "prog_print.h"
39 #include "prog_statevars.h"
43 * Return string name for given program/register file.
46 program_file_string(enum 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
:
74 return "Unknown program file!";
80 * Return a string representation of the given swizzle word.
81 * If extended is true, use extended (comma-separated) format.
84 swizzle_string(GLuint swizzle
, GLuint negateBase
, GLboolean extended
)
86 static const char swz
[] = "xyzw01";
90 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateBase
== 0)
91 return ""; /* no swizzle/negation */
98 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
104 if (negateBase
& 0x2)
106 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
112 if (negateBase
& 0x4)
114 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
120 if (negateBase
& 0x8)
122 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
130 writemask_string(GLuint writeMask
)
135 if (writeMask
== WRITEMASK_XYZW
)
139 if (writeMask
& WRITEMASK_X
)
141 if (writeMask
& WRITEMASK_Y
)
143 if (writeMask
& WRITEMASK_Z
)
145 if (writeMask
& WRITEMASK_W
)
153 print_dst_reg(const struct prog_dst_register
*dstReg
)
155 _mesa_printf(" %s[%d]%s",
156 program_file_string((enum register_file
) dstReg
->File
),
158 writemask_string(dstReg
->WriteMask
));
162 print_src_reg(const struct prog_src_register
*srcReg
)
164 _mesa_printf("%s[%d]%s",
165 program_file_string((enum register_file
) srcReg
->File
),
167 swizzle_string(srcReg
->Swizzle
,
168 srcReg
->NegateBase
, GL_FALSE
));
172 print_comment(const struct prog_instruction
*inst
)
175 _mesa_printf("; # %s\n", inst
->Comment
);
182 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
183 const char *opcode_string
,
188 _mesa_printf("%s", opcode_string
);
191 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
192 _mesa_printf("_SAT");
194 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
195 _mesa_printf(" %s[%d]%s",
196 program_file_string((enum register_file
) inst
->DstReg
.File
),
198 writemask_string(inst
->DstReg
.WriteMask
));
201 _mesa_printf(" ???");
207 for (j
= 0; j
< numRegs
; j
++) {
208 print_src_reg(inst
->SrcReg
+ j
);
214 _mesa_printf(" # %s", inst
->Comment
);
221 * Print a single vertex/fragment program instruction.
224 _mesa_print_instruction(const struct prog_instruction
*inst
)
226 switch (inst
->Opcode
) {
228 _mesa_printf("PRINT '%s'", inst
->Data
);
229 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
231 _mesa_printf("%s[%d]%s",
232 program_file_string((enum register_file
) inst
->SrcReg
[0].File
),
233 inst
->SrcReg
[0].Index
,
234 swizzle_string(inst
->SrcReg
[0].Swizzle
,
235 inst
->SrcReg
[0].NegateBase
, GL_FALSE
));
238 _mesa_printf(" # %s", inst
->Comment
);
243 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
244 _mesa_printf("_SAT");
245 print_dst_reg(&inst
->DstReg
);
246 _mesa_printf("%s[%d], %s",
247 program_file_string((enum register_file
) inst
->SrcReg
[0].File
),
248 inst
->SrcReg
[0].Index
,
249 swizzle_string(inst
->SrcReg
[0].Swizzle
,
250 inst
->SrcReg
[0].NegateBase
, GL_TRUE
));
256 _mesa_printf("%s", _mesa_opcode_string(inst
->Opcode
));
257 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
258 _mesa_printf("_SAT");
260 print_dst_reg(&inst
->DstReg
);
262 print_src_reg(&inst
->SrcReg
[0]);
263 _mesa_printf(", texture[%d], ", inst
->TexSrcUnit
);
264 switch (inst
->TexSrcTarget
) {
265 case TEXTURE_1D_INDEX
: _mesa_printf("1D"); break;
266 case TEXTURE_2D_INDEX
: _mesa_printf("2D"); break;
267 case TEXTURE_3D_INDEX
: _mesa_printf("3D"); break;
268 case TEXTURE_CUBE_INDEX
: _mesa_printf("CUBE"); break;
269 case TEXTURE_RECT_INDEX
: _mesa_printf("RECT"); break;
276 _mesa_printf("ARL addr.x, ");
277 print_src_reg(&inst
->SrcReg
[0]);
281 _mesa_printf("BRA %u", inst
->BranchTarget
);
285 _mesa_printf("CAL %u", inst
->BranchTarget
);
292 /* XXX may need other special-case instructions */
294 /* typical alu instruction */
295 _mesa_print_alu_instruction(inst
,
296 _mesa_opcode_string(inst
->Opcode
),
297 _mesa_num_inst_src_regs(inst
->Opcode
));
304 * Print a vertx/fragment program to stdout.
305 * XXX this function could be greatly improved.
308 _mesa_print_program(const struct gl_program
*prog
)
311 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
312 _mesa_printf("%3d: ", i
);
313 _mesa_print_instruction(prog
->Instructions
+ i
);
319 * Print all of a program's parameters.
322 _mesa_print_program_parameters(GLcontext
*ctx
, const struct gl_program
*prog
)
326 _mesa_printf("InputsRead: 0x%x\n", prog
->InputsRead
);
327 _mesa_printf("OutputsWritten: 0x%x\n", prog
->OutputsWritten
);
328 _mesa_printf("NumInstructions=%d\n", prog
->NumInstructions
);
329 _mesa_printf("NumTemporaries=%d\n", prog
->NumTemporaries
);
330 _mesa_printf("NumParameters=%d\n", prog
->NumParameters
);
331 _mesa_printf("NumAttributes=%d\n", prog
->NumAttributes
);
332 _mesa_printf("NumAddressRegs=%d\n", prog
->NumAddressRegs
);
334 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
337 _mesa_printf("Local Params:\n");
338 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
339 const GLfloat
*p
= prog
->LocalParams
[i
];
340 _mesa_printf("%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
344 for (i
= 0; i
< prog
->Parameters
->NumParameters
; i
++){
345 struct gl_program_parameter
*param
= prog
->Parameters
->Parameters
+ i
;
346 const GLfloat
*v
= prog
->Parameters
->ParameterValues
[i
];
347 _mesa_printf("param[%d] %s %s = {%.3f, %.3f, %.3f, %.3f};\n",
349 program_file_string(prog
->Parameters
->Parameters
[i
].Type
),
350 param
->Name
, v
[0], v
[1], v
[2], v
[3]);