blob: 09bf15f004559f73d527ec82b2d3bbca13fc2a72 [file] [log] [blame]
Brian00cdc0a2006-12-14 15:01:06 -07001/*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
Brian5db088d2007-02-05 14:58:15 -07005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Brian00cdc0a2006-12-14 15:01:06 -07006 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25/**
26 * \file prog_print.c
27 * Print vertex/fragment programs - for debugging.
28 * \author Brian Paul
29 */
30
31#include "glheader.h"
32#include "context.h"
33#include "imports.h"
Brian00cdc0a2006-12-14 15:01:06 -070034#include "prog_instruction.h"
35#include "prog_parameter.h"
36#include "prog_print.h"
37#include "prog_statevars.h"
38
39
Brian501ee872007-02-17 09:15:00 -070040
Brian00cdc0a2006-12-14 15:01:06 -070041/**
42 * Return string name for given program/register file.
43 */
44static const char *
Brian501ee872007-02-17 09:15:00 -070045file_string(enum register_file f, gl_prog_print_mode mode)
Brian00cdc0a2006-12-14 15:01:06 -070046{
47 switch (f) {
48 case PROGRAM_TEMPORARY:
49 return "TEMP";
50 case PROGRAM_LOCAL_PARAM:
51 return "LOCAL";
52 case PROGRAM_ENV_PARAM:
53 return "ENV";
54 case PROGRAM_STATE_VAR:
55 return "STATE";
56 case PROGRAM_INPUT:
57 return "INPUT";
58 case PROGRAM_OUTPUT:
59 return "OUTPUT";
60 case PROGRAM_NAMED_PARAM:
61 return "NAMED";
62 case PROGRAM_CONSTANT:
63 return "CONST";
64 case PROGRAM_UNIFORM:
65 return "UNIFORM";
66 case PROGRAM_VARYING:
67 return "VARYING";
68 case PROGRAM_WRITE_ONLY:
69 return "WRITE_ONLY";
70 case PROGRAM_ADDRESS:
71 return "ADDR";
Brianb2ab6932007-01-05 16:01:43 -070072 case PROGRAM_SAMPLER:
73 return "SAMPLER";
Brian00cdc0a2006-12-14 15:01:06 -070074 default:
75 return "Unknown program file!";
76 }
77}
78
79
80/**
Brian501ee872007-02-17 09:15:00 -070081 * Return ARB_v/f_prog-style input attrib string.
82 */
83static const char *
84arb_input_attrib_string(GLint index, GLenum progType)
85{
86 const char *vertAttribs[] = {
87 "vertex.position",
88 "vertex.weight",
89 "vertex.normal",
90 "vertex.color.primary",
91 "vertex.color.secondary",
92 "vertex.fogcoord",
93 "vertex.(six)",
94 "vertex.(seven)",
95 "vertex.texcoord[0]",
96 "vertex.texcoord[1]",
97 "vertex.texcoord[2]",
98 "vertex.texcoord[3]",
99 "vertex.texcoord[4]",
100 "vertex.texcoord[5]",
101 "vertex.texcoord[6]",
Markus Amslerd7878502008-03-17 12:11:11 +0100102 "vertex.texcoord[7]",
103 "vertex.attrib[0]",
104 "vertex.attrib[1]",
105 "vertex.attrib[2]",
106 "vertex.attrib[3]",
107 "vertex.attrib[4]",
108 "vertex.attrib[5]",
109 "vertex.attrib[6]",
110 "vertex.attrib[7]",
111 "vertex.attrib[8]",
112 "vertex.attrib[9]",
113 "vertex.attrib[10]",
114 "vertex.attrib[11]",
115 "vertex.attrib[12]",
116 "vertex.attrib[13]",
117 "vertex.attrib[14]",
118 "vertex.attrib[15]"
Brian501ee872007-02-17 09:15:00 -0700119 };
120 const char *fragAttribs[] = {
121 "fragment.position",
122 "fragment.color.primary",
123 "fragment.color.secondary",
124 "fragment.fogcoord",
125 "fragment.texcoord[0]",
126 "fragment.texcoord[1]",
127 "fragment.texcoord[2]",
128 "fragment.texcoord[3]",
129 "fragment.texcoord[4]",
130 "fragment.texcoord[5]",
131 "fragment.texcoord[6]",
132 "fragment.texcoord[7]",
133 "fragment.varying[0]",
134 "fragment.varying[1]",
135 "fragment.varying[2]",
136 "fragment.varying[3]",
137 "fragment.varying[4]",
138 "fragment.varying[5]",
139 "fragment.varying[6]",
140 "fragment.varying[7]"
141 };
142
143 if (progType == GL_VERTEX_PROGRAM_ARB) {
144 assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0]));
145 return vertAttribs[index];
146 }
147 else {
148 assert(index < sizeof(fragAttribs) / sizeof(fragAttribs[0]));
149 return fragAttribs[index];
150 }
151}
152
153
154/**
155 * Return ARB_v/f_prog-style output attrib string.
156 */
157static const char *
158arb_output_attrib_string(GLint index, GLenum progType)
159{
160 const char *vertResults[] = {
161 "result.position",
162 "result.color.primary",
163 "result.color.secondary",
164 "result.fogcoord",
165 "result.texcoord[0]",
166 "result.texcoord[1]",
167 "result.texcoord[2]",
168 "result.texcoord[3]",
169 "result.texcoord[4]",
170 "result.texcoord[5]",
171 "result.texcoord[6]",
172 "result.texcoord[7]",
173 "result.varying[0]",
174 "result.varying[1]",
175 "result.varying[2]",
176 "result.varying[3]",
177 "result.varying[4]",
178 "result.varying[5]",
179 "result.varying[6]",
180 "result.varying[7]"
181 };
182 const char *fragResults[] = {
183 "result.color",
184 "result.depth"
185 };
186
187 if (progType == GL_VERTEX_PROGRAM_ARB) {
188 assert(index < sizeof(vertResults) / sizeof(vertResults[0]));
189 return vertResults[index];
190 }
191 else {
192 assert(index < sizeof(fragResults) / sizeof(fragResults[0]));
193 return fragResults[index];
194 }
195}
196
197
198/**
199 * Return string representation of the given register.
200 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
201 * by the ARB/NV program languages so we've taken some liberties here.
202 * \param file the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
203 * \param index number of the register in the register file
204 * \param mode the output format/mode/style
205 * \param prog pointer to containing program
206 */
207static const char *
208reg_string(enum register_file f, GLint index, gl_prog_print_mode mode,
Zack Rusin74964ff2008-06-10 16:59:44 -0400209 GLint relAddr, const struct gl_program *prog)
Brian501ee872007-02-17 09:15:00 -0700210{
211 static char str[100];
212
213 str[0] = 0;
214
215 switch (mode) {
216 case PROG_PRINT_DEBUG:
Zack Rusin74964ff2008-06-10 16:59:44 -0400217 if (relAddr)
218 sprintf(str, "%s[ADDR%s%d]", file_string(f, mode), (index > 0) ? "+" : "", index);
219 else
220 sprintf(str, "%s[%d]", file_string(f, mode), index);
Brian501ee872007-02-17 09:15:00 -0700221 break;
222
223 case PROG_PRINT_ARB:
224 switch (f) {
225 case PROGRAM_INPUT:
226 sprintf(str, "%s", arb_input_attrib_string(index, prog->Target));
227 break;
228 case PROGRAM_OUTPUT:
229 sprintf(str, "%s", arb_output_attrib_string(index, prog->Target));
230 break;
231 case PROGRAM_TEMPORARY:
232 sprintf(str, "temp%d", index);
233 break;
234 case PROGRAM_ENV_PARAM:
235 sprintf(str, "program.env[%d]", index);
236 break;
237 case PROGRAM_LOCAL_PARAM:
238 sprintf(str, "program.local[%d]", index);
239 break;
240 case PROGRAM_VARYING: /* extension */
241 sprintf(str, "varying[%d]", index);
242 break;
243 case PROGRAM_CONSTANT: /* extension */
244 sprintf(str, "constant[%d]", index);
245 break;
246 case PROGRAM_UNIFORM: /* extension */
247 sprintf(str, "uniform[%d]", index);
248 break;
249 case PROGRAM_STATE_VAR:
250 {
251 struct gl_program_parameter *param
252 = prog->Parameters->Parameters + index;
253 sprintf(str, _mesa_program_state_string(param->StateIndexes));
254 }
255 break;
256 case PROGRAM_ADDRESS:
257 sprintf(str, "A%d", index);
258 break;
259 default:
260 _mesa_problem(NULL, "bad file in reg_string()");
261 }
262 break;
263
264 case PROG_PRINT_NV:
265 switch (f) {
266 case PROGRAM_INPUT:
267 if (prog->Target == GL_VERTEX_PROGRAM_ARB)
268 sprintf(str, "v[%d]", index);
269 else
270 sprintf(str, "f[%d]", index);
271 break;
272 case PROGRAM_OUTPUT:
273 sprintf(str, "o[%d]", index);
274 break;
275 case PROGRAM_TEMPORARY:
276 sprintf(str, "R%d", index);
277 break;
278 case PROGRAM_ENV_PARAM:
279 sprintf(str, "c[%d]", index);
280 break;
281 case PROGRAM_VARYING: /* extension */
282 sprintf(str, "varying[%d]", index);
283 break;
284 case PROGRAM_UNIFORM: /* extension */
285 sprintf(str, "uniform[%d]", index);
286 break;
287 case PROGRAM_CONSTANT: /* extension */
288 sprintf(str, "constant[%d]", index);
289 break;
290 case PROGRAM_STATE_VAR: /* extension */
291 sprintf(str, "state[%d]", index);
292 break;
293 default:
294 _mesa_problem(NULL, "bad file in reg_string()");
295 }
296 break;
297
298 default:
299 _mesa_problem(NULL, "bad mode in reg_string()");
300 }
301
302 return str;
303}
304
305
306/**
Brian00cdc0a2006-12-14 15:01:06 -0700307 * Return a string representation of the given swizzle word.
308 * If extended is true, use extended (comma-separated) format.
Brian3a281532006-12-16 12:51:34 -0700309 * \param swizzle the swizzle field
310 * \param negateBase 4-bit negation vector
311 * \param extended if true, also allow 0, 1 values
Brian00cdc0a2006-12-14 15:01:06 -0700312 */
Brian059376c2007-02-22 17:45:32 -0700313const char *
314_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended)
Brian00cdc0a2006-12-14 15:01:06 -0700315{
Brianb63c1002007-01-31 16:34:54 -0700316 static const char swz[] = "xyzw01?!";
Brian00cdc0a2006-12-14 15:01:06 -0700317 static char s[20];
318 GLuint i = 0;
319
320 if (!extended && swizzle == SWIZZLE_NOOP && negateBase == 0)
321 return ""; /* no swizzle/negation */
322
323 if (!extended)
324 s[i++] = '.';
325
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600326 if (negateBase & NEGATE_X)
Brian00cdc0a2006-12-14 15:01:06 -0700327 s[i++] = '-';
328 s[i++] = swz[GET_SWZ(swizzle, 0)];
329
330 if (extended) {
331 s[i++] = ',';
332 }
333
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600334 if (negateBase & NEGATE_Y)
Brian00cdc0a2006-12-14 15:01:06 -0700335 s[i++] = '-';
336 s[i++] = swz[GET_SWZ(swizzle, 1)];
337
338 if (extended) {
339 s[i++] = ',';
340 }
341
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600342 if (negateBase & NEGATE_Z)
Brian00cdc0a2006-12-14 15:01:06 -0700343 s[i++] = '-';
344 s[i++] = swz[GET_SWZ(swizzle, 2)];
345
346 if (extended) {
347 s[i++] = ',';
348 }
349
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600350 if (negateBase & NEGATE_W)
Brian00cdc0a2006-12-14 15:01:06 -0700351 s[i++] = '-';
352 s[i++] = swz[GET_SWZ(swizzle, 3)];
353
354 s[i] = 0;
355 return s;
356}
357
358
359static const char *
360writemask_string(GLuint writeMask)
361{
362 static char s[10];
363 GLuint i = 0;
364
365 if (writeMask == WRITEMASK_XYZW)
366 return "";
367
368 s[i++] = '.';
369 if (writeMask & WRITEMASK_X)
370 s[i++] = 'x';
371 if (writeMask & WRITEMASK_Y)
372 s[i++] = 'y';
373 if (writeMask & WRITEMASK_Z)
374 s[i++] = 'z';
375 if (writeMask & WRITEMASK_W)
376 s[i++] = 'w';
377
378 s[i] = 0;
379 return s;
380}
381
Brian3a281532006-12-16 12:51:34 -0700382
Briand7508612007-03-28 11:01:09 -0600383const char *
384_mesa_condcode_string(GLuint condcode)
Brian3a281532006-12-16 12:51:34 -0700385{
386 switch (condcode) {
387 case COND_GT: return "GT";
388 case COND_EQ: return "EQ";
389 case COND_LT: return "LT";
390 case COND_UN: return "UN";
391 case COND_GE: return "GE";
392 case COND_LE: return "LE";
393 case COND_NE: return "NE";
394 case COND_TR: return "TR";
395 case COND_FL: return "FL";
396 default: return "cond???";
397 }
398}
399
400
Brian00cdc0a2006-12-14 15:01:06 -0700401static void
Brian501ee872007-02-17 09:15:00 -0700402print_dst_reg(const struct prog_dst_register *dstReg, gl_prog_print_mode mode,
403 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700404{
Brian501ee872007-02-17 09:15:00 -0700405 _mesa_printf("%s%s",
406 reg_string((enum register_file) dstReg->File,
Zack Rusin74964ff2008-06-10 16:59:44 -0400407 dstReg->Index, mode, GL_FALSE, prog),
Brian501ee872007-02-17 09:15:00 -0700408 writemask_string(dstReg->WriteMask));
409
Brian1936b252007-03-22 09:04:18 -0600410 if (dstReg->CondMask != COND_TR) {
411 _mesa_printf(" (%s.%s)",
Briand7508612007-03-28 11:01:09 -0600412 _mesa_condcode_string(dstReg->CondMask),
Brian1936b252007-03-22 09:04:18 -0600413 _mesa_swizzle_string(dstReg->CondSwizzle, GL_FALSE, GL_FALSE));
414 }
415
Brian501ee872007-02-17 09:15:00 -0700416#if 0
417 _mesa_printf("%s[%d]%s",
418 file_string((enum register_file) dstReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700419 dstReg->Index,
420 writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700421#endif
Brian00cdc0a2006-12-14 15:01:06 -0700422}
423
424static void
Brian501ee872007-02-17 09:15:00 -0700425print_src_reg(const struct prog_src_register *srcReg, gl_prog_print_mode mode,
426 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700427{
Brian501ee872007-02-17 09:15:00 -0700428 _mesa_printf("%s%s",
429 reg_string((enum register_file) srcReg->File,
Zack Rusin74964ff2008-06-10 16:59:44 -0400430 srcReg->Index, mode, srcReg->RelAddr, prog),
Brian059376c2007-02-22 17:45:32 -0700431 _mesa_swizzle_string(srcReg->Swizzle,
Zack Rusin74964ff2008-06-10 16:59:44 -0400432 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700433#if 0
Brian00cdc0a2006-12-14 15:01:06 -0700434 _mesa_printf("%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700435 file_string((enum register_file) srcReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700436 srcReg->Index,
Brian059376c2007-02-22 17:45:32 -0700437 _mesa_swizzle_string(srcReg->Swizzle,
Brian00cdc0a2006-12-14 15:01:06 -0700438 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700439#endif
Brian00cdc0a2006-12-14 15:01:06 -0700440}
441
442static void
443print_comment(const struct prog_instruction *inst)
444{
445 if (inst->Comment)
446 _mesa_printf("; # %s\n", inst->Comment);
447 else
448 _mesa_printf(";\n");
449}
450
451
Brian501ee872007-02-17 09:15:00 -0700452static void
453print_alu_instruction(const struct prog_instruction *inst,
Brian0020d102007-02-23 11:43:44 -0700454 const char *opcode_string, GLuint numRegs,
Brian501ee872007-02-17 09:15:00 -0700455 gl_prog_print_mode mode,
456 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700457{
458 GLuint j;
459
460 _mesa_printf("%s", opcode_string);
Brianb50280e2006-12-18 16:21:58 -0700461 if (inst->CondUpdate)
462 _mesa_printf(".C");
Brian00cdc0a2006-12-14 15:01:06 -0700463
464 /* frag prog only */
465 if (inst->SaturateMode == SATURATE_ZERO_ONE)
466 _mesa_printf("_SAT");
467
Brian501ee872007-02-17 09:15:00 -0700468 _mesa_printf(" ");
Brian00cdc0a2006-12-14 15:01:06 -0700469 if (inst->DstReg.File != PROGRAM_UNDEFINED) {
Brian501ee872007-02-17 09:15:00 -0700470 print_dst_reg(&inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700471 }
472 else {
473 _mesa_printf(" ???");
474 }
475
476 if (numRegs > 0)
477 _mesa_printf(", ");
478
479 for (j = 0; j < numRegs; j++) {
Brian501ee872007-02-17 09:15:00 -0700480 print_src_reg(inst->SrcReg + j, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700481 if (j + 1 < numRegs)
482 _mesa_printf(", ");
483 }
484
Brian00cdc0a2006-12-14 15:01:06 -0700485 print_comment(inst);
486}
487
488
Brian501ee872007-02-17 09:15:00 -0700489void
Brian0020d102007-02-23 11:43:44 -0700490_mesa_print_alu_instruction(const struct prog_instruction *inst,
491 const char *opcode_string, GLuint numRegs)
492{
493 print_alu_instruction(inst, opcode_string, numRegs, PROG_PRINT_DEBUG, NULL);
494}
495
496
497void
Brian501ee872007-02-17 09:15:00 -0700498_mesa_print_instruction(const struct prog_instruction *inst)
499{
500 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
501 _mesa_print_instruction_opt(inst, 0, PROG_PRINT_DEBUG, NULL);
502}
503
504
Brian00cdc0a2006-12-14 15:01:06 -0700505/**
506 * Print a single vertex/fragment program instruction.
507 */
Brian5db088d2007-02-05 14:58:15 -0700508GLint
Brian501ee872007-02-17 09:15:00 -0700509_mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent,
510 gl_prog_print_mode mode,
511 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700512{
Brian7b300532007-02-22 09:08:36 -0700513 GLint i;
Brian5db088d2007-02-05 14:58:15 -0700514
515 if (inst->Opcode == OPCODE_ELSE ||
516 inst->Opcode == OPCODE_ENDIF ||
517 inst->Opcode == OPCODE_ENDLOOP ||
518 inst->Opcode == OPCODE_ENDSUB) {
519 indent -= 3;
520 }
Brian5db088d2007-02-05 14:58:15 -0700521 for (i = 0; i < indent; i++) {
522 _mesa_printf(" ");
523 }
524
Brian00cdc0a2006-12-14 15:01:06 -0700525 switch (inst->Opcode) {
526 case OPCODE_PRINT:
527 _mesa_printf("PRINT '%s'", inst->Data);
528 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
529 _mesa_printf(", ");
530 _mesa_printf("%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700531 file_string((enum register_file) inst->SrcReg[0].File,
532 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700533 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700534 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
535 inst->SrcReg[0].NegateBase, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700536 }
537 if (inst->Comment)
538 _mesa_printf(" # %s", inst->Comment);
539 print_comment(inst);
540 break;
541 case OPCODE_SWZ:
542 _mesa_printf("SWZ");
543 if (inst->SaturateMode == SATURATE_ZERO_ONE)
544 _mesa_printf("_SAT");
Brian501ee872007-02-17 09:15:00 -0700545 _mesa_printf(" ");
546 print_dst_reg(&inst->DstReg, mode, prog);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600547 _mesa_printf(", %s[%d], %s",
Brian501ee872007-02-17 09:15:00 -0700548 file_string((enum register_file) inst->SrcReg[0].File,
549 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700550 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700551 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
552 inst->SrcReg[0].NegateBase, GL_TRUE));
Brian00cdc0a2006-12-14 15:01:06 -0700553 print_comment(inst);
554 break;
555 case OPCODE_TEX:
556 case OPCODE_TXP:
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600557 case OPCODE_TXL:
Brian00cdc0a2006-12-14 15:01:06 -0700558 case OPCODE_TXB:
559 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
560 if (inst->SaturateMode == SATURATE_ZERO_ONE)
561 _mesa_printf("_SAT");
Brian501ee872007-02-17 09:15:00 -0700562 _mesa_printf(" ");
563 print_dst_reg(&inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700564 _mesa_printf(", ");
Brian501ee872007-02-17 09:15:00 -0700565 print_src_reg(&inst->SrcReg[0], mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700566 _mesa_printf(", texture[%d], ", inst->TexSrcUnit);
567 switch (inst->TexSrcTarget) {
568 case TEXTURE_1D_INDEX: _mesa_printf("1D"); break;
569 case TEXTURE_2D_INDEX: _mesa_printf("2D"); break;
570 case TEXTURE_3D_INDEX: _mesa_printf("3D"); break;
571 case TEXTURE_CUBE_INDEX: _mesa_printf("CUBE"); break;
572 case TEXTURE_RECT_INDEX: _mesa_printf("RECT"); break;
573 default:
574 ;
575 }
576 print_comment(inst);
577 break;
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600578
579 case OPCODE_KIL:
580 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
581 _mesa_printf(" ");
582 print_src_reg(&inst->SrcReg[0], mode, prog);
583 print_comment(inst);
584 break;
585 case OPCODE_KIL_NV:
586 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
587 _mesa_printf(" ");
588 _mesa_printf("%s.%s",
589 _mesa_condcode_string(inst->DstReg.CondMask),
590 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
591 GL_FALSE, GL_FALSE));
592 print_comment(inst);
593 break;
594
Brian00cdc0a2006-12-14 15:01:06 -0700595 case OPCODE_ARL:
Zack Rusin74964ff2008-06-10 16:59:44 -0400596 _mesa_printf("ARL ");
597 print_dst_reg(&inst->DstReg, mode, prog);
598 _mesa_printf(", ");
Brian501ee872007-02-17 09:15:00 -0700599 print_src_reg(&inst->SrcReg[0], mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700600 print_comment(inst);
601 break;
602 case OPCODE_BRA:
Briand7508612007-03-28 11:01:09 -0600603 _mesa_printf("BRA %d (%s%s)",
Brian3a281532006-12-16 12:51:34 -0700604 inst->BranchTarget,
Briand7508612007-03-28 11:01:09 -0600605 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700606 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700607 print_comment(inst);
608 break;
Brian5ae49cf2007-01-20 09:27:40 -0700609 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600610 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
611 /* Use ordinary register */
612 _mesa_printf("IF ");
613 print_src_reg(&inst->SrcReg[0], mode, prog);
614 _mesa_printf("; ");
615 }
616 else {
617 /* Use cond codes */
618 _mesa_printf("IF (%s%s);",
Briand7508612007-03-28 11:01:09 -0600619 _mesa_condcode_string(inst->DstReg.CondMask),
Brian63556fa2007-03-23 14:47:46 -0600620 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
621 0, GL_FALSE));
622 }
623 _mesa_printf(" # (if false, goto %d)", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700624 print_comment(inst);
625 return indent + 3;
626 case OPCODE_ELSE:
Brian501ee872007-02-17 09:15:00 -0700627 _mesa_printf("ELSE; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700628 return indent + 3;
629 case OPCODE_ENDIF:
Brian501ee872007-02-17 09:15:00 -0700630 _mesa_printf("ENDIF;\n");
Brian5db088d2007-02-05 14:58:15 -0700631 break;
632 case OPCODE_BGNLOOP:
Brian501ee872007-02-17 09:15:00 -0700633 _mesa_printf("BGNLOOP; # (end at %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700634 return indent + 3;
635 case OPCODE_ENDLOOP:
Brian501ee872007-02-17 09:15:00 -0700636 _mesa_printf("ENDLOOP; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700637 break;
638 case OPCODE_BRK:
Brianf22ed092007-02-06 22:31:19 -0700639 case OPCODE_CONT:
Brian81767ee2007-03-23 17:45:53 -0600640 _mesa_printf("%s (%s%s); # (goto %d)",
641 _mesa_opcode_string(inst->Opcode),
Briand7508612007-03-28 11:01:09 -0600642 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700643 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
Brian2755c792007-02-05 18:01:02 -0700644 inst->BranchTarget);
Brian5ae49cf2007-01-20 09:27:40 -0700645 print_comment(inst);
646 break;
Brian63556fa2007-03-23 14:47:46 -0600647
Brian5db088d2007-02-05 14:58:15 -0700648 case OPCODE_BGNSUB:
Brianf407cad2007-03-27 14:53:17 -0600649 if (mode == PROG_PRINT_NV) {
650 _mesa_printf("%s:\n", inst->Comment); /* comment is label */
651 return indent;
652 }
653 else {
654 _mesa_printf("BGNSUB");
655 print_comment(inst);
656 return indent + 3;
657 }
Brian5db088d2007-02-05 14:58:15 -0700658 case OPCODE_ENDSUB:
Brianf407cad2007-03-27 14:53:17 -0600659 if (mode == PROG_PRINT_DEBUG) {
660 _mesa_printf("ENDSUB");
661 print_comment(inst);
662 }
663 break;
664 case OPCODE_CAL:
665 if (mode == PROG_PRINT_NV) {
Briand7508612007-03-28 11:01:09 -0600666 _mesa_printf("CAL %s; # (goto %d)\n", inst->Comment, inst->BranchTarget);
Brianf407cad2007-03-27 14:53:17 -0600667 }
668 else {
669 _mesa_printf("CAL %u", inst->BranchTarget);
670 print_comment(inst);
671 }
672 break;
673 case OPCODE_RET:
Briand7508612007-03-28 11:01:09 -0600674 _mesa_printf("RET (%s%s)",
675 _mesa_condcode_string(inst->DstReg.CondMask),
676 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian5db088d2007-02-05 14:58:15 -0700677 print_comment(inst);
Brian5ae49cf2007-01-20 09:27:40 -0700678 break;
Brianf407cad2007-03-27 14:53:17 -0600679
Brian00cdc0a2006-12-14 15:01:06 -0700680 case OPCODE_END:
Brian501ee872007-02-17 09:15:00 -0700681 _mesa_printf("END\n");
Brian00cdc0a2006-12-14 15:01:06 -0700682 break;
Brian3a281532006-12-16 12:51:34 -0700683 case OPCODE_NOP:
Brian059376c2007-02-22 17:45:32 -0700684 if (mode == PROG_PRINT_DEBUG) {
685 _mesa_printf("NOP");
686 print_comment(inst);
687 }
688 else if (inst->Comment) {
689 /* ARB/NV extensions don't have NOP instruction */
690 _mesa_printf("# %s\n", inst->Comment);
691 }
Brian3a281532006-12-16 12:51:34 -0700692 break;
Brian00cdc0a2006-12-14 15:01:06 -0700693 /* XXX may need other special-case instructions */
694 default:
695 /* typical alu instruction */
Brian501ee872007-02-17 09:15:00 -0700696 print_alu_instruction(inst,
697 _mesa_opcode_string(inst->Opcode),
698 _mesa_num_inst_src_regs(inst->Opcode),
699 mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700700 break;
701 }
Brian5db088d2007-02-05 14:58:15 -0700702 return indent;
Brian00cdc0a2006-12-14 15:01:06 -0700703}
704
705
706/**
Brian501ee872007-02-17 09:15:00 -0700707 * Print program to stdout, default options.
Brian00cdc0a2006-12-14 15:01:06 -0700708 */
709void
710_mesa_print_program(const struct gl_program *prog)
711{
Brian9449a4d2007-02-17 09:41:59 -0700712 _mesa_print_program_opt(prog, PROG_PRINT_DEBUG, GL_TRUE);
Brian501ee872007-02-17 09:15:00 -0700713}
714
715
716/**
717 * Print program, with options.
718 */
719void
720_mesa_print_program_opt(const struct gl_program *prog,
721 gl_prog_print_mode mode,
722 GLboolean lineNumbers)
723{
Brian5db088d2007-02-05 14:58:15 -0700724 GLuint i, indent = 0;
Brian501ee872007-02-17 09:15:00 -0700725
726 switch (prog->Target) {
727 case GL_VERTEX_PROGRAM_ARB:
728 if (mode == PROG_PRINT_ARB)
729 _mesa_printf("!!ARBvp1.0\n");
730 else if (mode == PROG_PRINT_NV)
731 _mesa_printf("!!VP1.0\n");
732 else
733 _mesa_printf("# Vertex Program/Shader\n");
734 break;
735 case GL_FRAGMENT_PROGRAM_ARB:
736 case GL_FRAGMENT_PROGRAM_NV:
737 if (mode == PROG_PRINT_ARB)
738 _mesa_printf("!!ARBfp1.0\n");
739 else if (mode == PROG_PRINT_NV)
740 _mesa_printf("!!FP1.0\n");
741 else
742 _mesa_printf("# Fragment Program/Shader\n");
743 break;
744 }
745
Brian00cdc0a2006-12-14 15:01:06 -0700746 for (i = 0; i < prog->NumInstructions; i++) {
Brian501ee872007-02-17 09:15:00 -0700747 if (lineNumbers)
748 _mesa_printf("%3d: ", i);
749 indent = _mesa_print_instruction_opt(prog->Instructions + i,
750 indent, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700751 }
752}
753
754
755/**
756 * Print all of a program's parameters.
757 */
758void
759_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
760{
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600761 GLuint i;
762
Brian00cdc0a2006-12-14 15:01:06 -0700763 _mesa_printf("InputsRead: 0x%x\n", prog->InputsRead);
764 _mesa_printf("OutputsWritten: 0x%x\n", prog->OutputsWritten);
765 _mesa_printf("NumInstructions=%d\n", prog->NumInstructions);
766 _mesa_printf("NumTemporaries=%d\n", prog->NumTemporaries);
767 _mesa_printf("NumParameters=%d\n", prog->NumParameters);
768 _mesa_printf("NumAttributes=%d\n", prog->NumAttributes);
769 _mesa_printf("NumAddressRegs=%d\n", prog->NumAddressRegs);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600770 _mesa_printf("Samplers=[ ");
771 for (i = 0; i < MAX_SAMPLERS; i++) {
772 _mesa_printf("%d ", prog->SamplerUnits[i]);
773 }
774 _mesa_printf("]\n");
775
Brian00cdc0a2006-12-14 15:01:06 -0700776 _mesa_load_state_parameters(ctx, prog->Parameters);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600777
Brian00cdc0a2006-12-14 15:01:06 -0700778#if 0
779 _mesa_printf("Local Params:\n");
780 for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
781 const GLfloat *p = prog->LocalParams[i];
782 _mesa_printf("%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
783 }
784#endif
Brian83ca3ff2006-12-20 17:17:38 -0700785 _mesa_print_parameter_list(prog->Parameters);
786}
Brian00cdc0a2006-12-14 15:01:06 -0700787
Brian83ca3ff2006-12-20 17:17:38 -0700788
789void
790_mesa_print_parameter_list(const struct gl_program_parameter_list *list)
791{
Brian501ee872007-02-17 09:15:00 -0700792 const gl_prog_print_mode mode = PROG_PRINT_DEBUG;
Brian83ca3ff2006-12-20 17:17:38 -0700793 GLuint i;
Brian501ee872007-02-17 09:15:00 -0700794
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600795 if (!list)
796 return;
797
Brian83ca3ff2006-12-20 17:17:38 -0700798 _mesa_printf("param list %p\n", (void *) list);
799 for (i = 0; i < list->NumParameters; i++){
800 struct gl_program_parameter *param = list->Parameters + i;
801 const GLfloat *v = list->ParameterValues[i];
Brianc5e6bf62007-02-07 16:09:13 -0700802 _mesa_printf("param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g};\n",
Brian83ca3ff2006-12-20 17:17:38 -0700803 i, param->Size,
Brian501ee872007-02-17 09:15:00 -0700804 file_string(list->Parameters[i].Type, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700805 param->Name, v[0], v[1], v[2], v[3]);
806 }
807}