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.
34 #include "prog_instruction.h"
35 #include "prog_parameter.h"
36 #include "prog_print.h"
37 #include "prog_statevars.h"
41 * Return string name for given program/register file.
44 program_file_string(enum register_file f
)
47 case PROGRAM_TEMPORARY
:
49 case PROGRAM_LOCAL_PARAM
:
51 case PROGRAM_ENV_PARAM
:
53 case PROGRAM_STATE_VAR
:
59 case PROGRAM_NAMED_PARAM
:
61 case PROGRAM_CONSTANT
:
67 case PROGRAM_WRITE_ONLY
:
72 return "Unknown program file!";
78 * Return a string representation of the given swizzle word.
79 * If extended is true, use extended (comma-separated) format.
82 swizzle_string(GLuint swizzle
, GLuint negateBase
, GLboolean extended
)
84 static const char swz
[] = "xyzw01";
88 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateBase
== 0)
89 return ""; /* no swizzle/negation */
96 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
102 if (negateBase
& 0x2)
104 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
110 if (negateBase
& 0x4)
112 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
118 if (negateBase
& 0x8)
120 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
128 writemask_string(GLuint writeMask
)
133 if (writeMask
== WRITEMASK_XYZW
)
137 if (writeMask
& WRITEMASK_X
)
139 if (writeMask
& WRITEMASK_Y
)
141 if (writeMask
& WRITEMASK_Z
)
143 if (writeMask
& WRITEMASK_W
)
151 print_dst_reg(const struct prog_dst_register
*dstReg
)
153 _mesa_printf(" %s[%d]%s",
154 program_file_string((enum register_file
) dstReg
->File
),
156 writemask_string(dstReg
->WriteMask
));
160 print_src_reg(const struct prog_src_register
*srcReg
)
162 _mesa_printf("%s[%d]%s",
163 program_file_string((enum register_file
) srcReg
->File
),
165 swizzle_string(srcReg
->Swizzle
,
166 srcReg
->NegateBase
, GL_FALSE
));
170 print_comment(const struct prog_instruction
*inst
)
173 _mesa_printf("; # %s\n", inst
->Comment
);
180 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
181 const char *opcode_string
,
186 _mesa_printf("%s", opcode_string
);
189 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
190 _mesa_printf("_SAT");
192 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
193 _mesa_printf(" %s[%d]%s",
194 program_file_string((enum register_file
) inst
->DstReg
.File
),
196 writemask_string(inst
->DstReg
.WriteMask
));
199 _mesa_printf(" ???");
205 for (j
= 0; j
< numRegs
; j
++) {
206 print_src_reg(inst
->SrcReg
+ j
);
212 _mesa_printf(" # %s", inst
->Comment
);
219 * Print a single vertex/fragment program instruction.
222 _mesa_print_instruction(const struct prog_instruction
*inst
)
224 switch (inst
->Opcode
) {
226 _mesa_printf("PRINT '%s'", inst
->Data
);
227 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
229 _mesa_printf("%s[%d]%s",
230 program_file_string((enum register_file
) inst
->SrcReg
[0].File
),
231 inst
->SrcReg
[0].Index
,
232 swizzle_string(inst
->SrcReg
[0].Swizzle
,
233 inst
->SrcReg
[0].NegateBase
, GL_FALSE
));
236 _mesa_printf(" # %s", inst
->Comment
);
241 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
242 _mesa_printf("_SAT");
243 print_dst_reg(&inst
->DstReg
);
244 _mesa_printf("%s[%d], %s",
245 program_file_string((enum register_file
) inst
->SrcReg
[0].File
),
246 inst
->SrcReg
[0].Index
,
247 swizzle_string(inst
->SrcReg
[0].Swizzle
,
248 inst
->SrcReg
[0].NegateBase
, GL_TRUE
));
254 _mesa_printf("%s", _mesa_opcode_string(inst
->Opcode
));
255 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
256 _mesa_printf("_SAT");
258 print_dst_reg(&inst
->DstReg
);
260 print_src_reg(&inst
->SrcReg
[0]);
261 _mesa_printf(", texture[%d], ", inst
->TexSrcUnit
);
262 switch (inst
->TexSrcTarget
) {
263 case TEXTURE_1D_INDEX
: _mesa_printf("1D"); break;
264 case TEXTURE_2D_INDEX
: _mesa_printf("2D"); break;
265 case TEXTURE_3D_INDEX
: _mesa_printf("3D"); break;
266 case TEXTURE_CUBE_INDEX
: _mesa_printf("CUBE"); break;
267 case TEXTURE_RECT_INDEX
: _mesa_printf("RECT"); break;
274 _mesa_printf("ARL addr.x, ");
275 print_src_reg(&inst
->SrcReg
[0]);
279 _mesa_printf("BRA %u", inst
->BranchTarget
);
283 _mesa_printf("CAL %u", inst
->BranchTarget
);
290 /* XXX may need other special-case instructions */
292 /* typical alu instruction */
293 _mesa_print_alu_instruction(inst
,
294 _mesa_opcode_string(inst
->Opcode
),
295 _mesa_num_inst_src_regs(inst
->Opcode
));
302 * Print a vertx/fragment program to stdout.
303 * XXX this function could be greatly improved.
306 _mesa_print_program(const struct gl_program
*prog
)
309 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
310 _mesa_printf("%3d: ", i
);
311 _mesa_print_instruction(prog
->Instructions
+ i
);
317 * Print all of a program's parameters.
320 _mesa_print_program_parameters(GLcontext
*ctx
, const struct gl_program
*prog
)
324 _mesa_printf("InputsRead: 0x%x\n", prog
->InputsRead
);
325 _mesa_printf("OutputsWritten: 0x%x\n", prog
->OutputsWritten
);
326 _mesa_printf("NumInstructions=%d\n", prog
->NumInstructions
);
327 _mesa_printf("NumTemporaries=%d\n", prog
->NumTemporaries
);
328 _mesa_printf("NumParameters=%d\n", prog
->NumParameters
);
329 _mesa_printf("NumAttributes=%d\n", prog
->NumAttributes
);
330 _mesa_printf("NumAddressRegs=%d\n", prog
->NumAddressRegs
);
332 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
335 _mesa_printf("Local Params:\n");
336 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
337 const GLfloat
*p
= prog
->LocalParams
[i
];
338 _mesa_printf("%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
342 for (i
= 0; i
< prog
->Parameters
->NumParameters
; i
++){
343 struct gl_program_parameter
*param
= prog
->Parameters
->Parameters
+ i
;
344 const GLfloat
*v
= prog
->Parameters
->ParameterValues
[i
];
345 _mesa_printf("param[%d] %s %s = {%.3f, %.3f, %.3f, %.3f};\n",
347 program_file_string(prog
->Parameters
->Parameters
[i
].Type
),
348 param
->Name
, v
[0], v
[1], v
[2], v
[3]);