blob: 0ec13a415c4fe34fd0b02e3ee955d62eaf0dfc2f [file] [log] [blame]
Brian00cdc0a2006-12-14 15:01:06 -07001/*
2 * Mesa 3-D graphics library
Brian Paulf4361542008-11-11 10:47:10 -07003 * Version: 7.3
Brian00cdc0a2006-12-14 15:01:06 -07004 *
Brian Paulf4361542008-11-11 10:47:10 -07005 * Copyright (C) 1999-2008 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
Brian Paulbbd28712008-09-18 12:26:54 -060031#include "main/glheader.h"
32#include "main/context.h"
33#include "main/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";
Brian Paulbc7d2c42009-01-07 18:44:41 -070074 case PROGRAM_UNDEFINED:
75 return "UNDEFINED";
Brian00cdc0a2006-12-14 15:01:06 -070076 default:
77 return "Unknown program file!";
78 }
79}
80
81
82/**
Brian501ee872007-02-17 09:15:00 -070083 * Return ARB_v/f_prog-style input attrib string.
84 */
85static const char *
86arb_input_attrib_string(GLint index, GLenum progType)
87{
88 const char *vertAttribs[] = {
89 "vertex.position",
90 "vertex.weight",
91 "vertex.normal",
92 "vertex.color.primary",
93 "vertex.color.secondary",
94 "vertex.fogcoord",
95 "vertex.(six)",
96 "vertex.(seven)",
97 "vertex.texcoord[0]",
98 "vertex.texcoord[1]",
99 "vertex.texcoord[2]",
100 "vertex.texcoord[3]",
101 "vertex.texcoord[4]",
102 "vertex.texcoord[5]",
103 "vertex.texcoord[6]",
Markus Amslerd7878502008-03-17 12:11:11 +0100104 "vertex.texcoord[7]",
105 "vertex.attrib[0]",
106 "vertex.attrib[1]",
107 "vertex.attrib[2]",
108 "vertex.attrib[3]",
109 "vertex.attrib[4]",
110 "vertex.attrib[5]",
111 "vertex.attrib[6]",
112 "vertex.attrib[7]",
113 "vertex.attrib[8]",
114 "vertex.attrib[9]",
115 "vertex.attrib[10]",
116 "vertex.attrib[11]",
117 "vertex.attrib[12]",
118 "vertex.attrib[13]",
119 "vertex.attrib[14]",
120 "vertex.attrib[15]"
Brian501ee872007-02-17 09:15:00 -0700121 };
122 const char *fragAttribs[] = {
123 "fragment.position",
124 "fragment.color.primary",
125 "fragment.color.secondary",
126 "fragment.fogcoord",
127 "fragment.texcoord[0]",
128 "fragment.texcoord[1]",
129 "fragment.texcoord[2]",
130 "fragment.texcoord[3]",
131 "fragment.texcoord[4]",
132 "fragment.texcoord[5]",
133 "fragment.texcoord[6]",
134 "fragment.texcoord[7]",
135 "fragment.varying[0]",
136 "fragment.varying[1]",
137 "fragment.varying[2]",
138 "fragment.varying[3]",
139 "fragment.varying[4]",
140 "fragment.varying[5]",
141 "fragment.varying[6]",
142 "fragment.varying[7]"
143 };
144
145 if (progType == GL_VERTEX_PROGRAM_ARB) {
146 assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0]));
147 return vertAttribs[index];
148 }
149 else {
150 assert(index < sizeof(fragAttribs) / sizeof(fragAttribs[0]));
151 return fragAttribs[index];
152 }
153}
154
155
156/**
157 * Return ARB_v/f_prog-style output attrib string.
158 */
159static const char *
160arb_output_attrib_string(GLint index, GLenum progType)
161{
162 const char *vertResults[] = {
163 "result.position",
164 "result.color.primary",
165 "result.color.secondary",
166 "result.fogcoord",
167 "result.texcoord[0]",
168 "result.texcoord[1]",
169 "result.texcoord[2]",
170 "result.texcoord[3]",
171 "result.texcoord[4]",
172 "result.texcoord[5]",
173 "result.texcoord[6]",
174 "result.texcoord[7]",
175 "result.varying[0]",
176 "result.varying[1]",
177 "result.varying[2]",
178 "result.varying[3]",
179 "result.varying[4]",
180 "result.varying[5]",
181 "result.varying[6]",
182 "result.varying[7]"
183 };
184 const char *fragResults[] = {
185 "result.color",
186 "result.depth"
187 };
188
189 if (progType == GL_VERTEX_PROGRAM_ARB) {
190 assert(index < sizeof(vertResults) / sizeof(vertResults[0]));
191 return vertResults[index];
192 }
193 else {
194 assert(index < sizeof(fragResults) / sizeof(fragResults[0]));
195 return fragResults[index];
196 }
197}
198
199
200/**
201 * Return string representation of the given register.
202 * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined
203 * by the ARB/NV program languages so we've taken some liberties here.
204 * \param file the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc)
205 * \param index number of the register in the register file
206 * \param mode the output format/mode/style
207 * \param prog pointer to containing program
208 */
209static const char *
210reg_string(enum register_file f, GLint index, gl_prog_print_mode mode,
Zack Rusin19659a52008-06-12 14:19:10 -0400211 GLboolean relAddr, const struct gl_program *prog)
Brian501ee872007-02-17 09:15:00 -0700212{
213 static char str[100];
214
215 str[0] = 0;
216
217 switch (mode) {
218 case PROG_PRINT_DEBUG:
Zack Rusin74964ff2008-06-10 16:59:44 -0400219 if (relAddr)
Brian Paul557fde92008-11-12 11:12:10 -0700220 sprintf(str, "%s[ADDR+%d]", file_string(f, mode), index);
Zack Rusin74964ff2008-06-10 16:59:44 -0400221 else
222 sprintf(str, "%s[%d]", file_string(f, mode), index);
Brian501ee872007-02-17 09:15:00 -0700223 break;
224
225 case PROG_PRINT_ARB:
226 switch (f) {
227 case PROGRAM_INPUT:
228 sprintf(str, "%s", arb_input_attrib_string(index, prog->Target));
229 break;
230 case PROGRAM_OUTPUT:
231 sprintf(str, "%s", arb_output_attrib_string(index, prog->Target));
232 break;
233 case PROGRAM_TEMPORARY:
234 sprintf(str, "temp%d", index);
235 break;
236 case PROGRAM_ENV_PARAM:
237 sprintf(str, "program.env[%d]", index);
238 break;
239 case PROGRAM_LOCAL_PARAM:
240 sprintf(str, "program.local[%d]", index);
241 break;
242 case PROGRAM_VARYING: /* extension */
243 sprintf(str, "varying[%d]", index);
244 break;
245 case PROGRAM_CONSTANT: /* extension */
246 sprintf(str, "constant[%d]", index);
247 break;
248 case PROGRAM_UNIFORM: /* extension */
249 sprintf(str, "uniform[%d]", index);
250 break;
251 case PROGRAM_STATE_VAR:
252 {
253 struct gl_program_parameter *param
254 = prog->Parameters->Parameters + index;
255 sprintf(str, _mesa_program_state_string(param->StateIndexes));
256 }
257 break;
258 case PROGRAM_ADDRESS:
259 sprintf(str, "A%d", index);
260 break;
261 default:
262 _mesa_problem(NULL, "bad file in reg_string()");
263 }
264 break;
265
266 case PROG_PRINT_NV:
267 switch (f) {
268 case PROGRAM_INPUT:
269 if (prog->Target == GL_VERTEX_PROGRAM_ARB)
270 sprintf(str, "v[%d]", index);
271 else
272 sprintf(str, "f[%d]", index);
273 break;
274 case PROGRAM_OUTPUT:
275 sprintf(str, "o[%d]", index);
276 break;
277 case PROGRAM_TEMPORARY:
278 sprintf(str, "R%d", index);
279 break;
280 case PROGRAM_ENV_PARAM:
281 sprintf(str, "c[%d]", index);
282 break;
283 case PROGRAM_VARYING: /* extension */
284 sprintf(str, "varying[%d]", index);
285 break;
286 case PROGRAM_UNIFORM: /* extension */
287 sprintf(str, "uniform[%d]", index);
288 break;
289 case PROGRAM_CONSTANT: /* extension */
290 sprintf(str, "constant[%d]", index);
291 break;
292 case PROGRAM_STATE_VAR: /* extension */
293 sprintf(str, "state[%d]", index);
294 break;
295 default:
296 _mesa_problem(NULL, "bad file in reg_string()");
297 }
298 break;
299
300 default:
301 _mesa_problem(NULL, "bad mode in reg_string()");
302 }
303
304 return str;
305}
306
307
308/**
Brian00cdc0a2006-12-14 15:01:06 -0700309 * Return a string representation of the given swizzle word.
310 * If extended is true, use extended (comma-separated) format.
Brian3a281532006-12-16 12:51:34 -0700311 * \param swizzle the swizzle field
312 * \param negateBase 4-bit negation vector
313 * \param extended if true, also allow 0, 1 values
Brian00cdc0a2006-12-14 15:01:06 -0700314 */
Brian059376c2007-02-22 17:45:32 -0700315const char *
316_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended)
Brian00cdc0a2006-12-14 15:01:06 -0700317{
Brian Paul74a19b02008-07-18 19:46:19 -0600318 static const char swz[] = "xyzw01!?"; /* See SWIZZLE_x definitions */
Brian00cdc0a2006-12-14 15:01:06 -0700319 static char s[20];
320 GLuint i = 0;
321
322 if (!extended && swizzle == SWIZZLE_NOOP && negateBase == 0)
323 return ""; /* no swizzle/negation */
324
325 if (!extended)
326 s[i++] = '.';
327
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600328 if (negateBase & NEGATE_X)
Brian00cdc0a2006-12-14 15:01:06 -0700329 s[i++] = '-';
330 s[i++] = swz[GET_SWZ(swizzle, 0)];
331
332 if (extended) {
333 s[i++] = ',';
334 }
335
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600336 if (negateBase & NEGATE_Y)
Brian00cdc0a2006-12-14 15:01:06 -0700337 s[i++] = '-';
338 s[i++] = swz[GET_SWZ(swizzle, 1)];
339
340 if (extended) {
341 s[i++] = ',';
342 }
343
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600344 if (negateBase & NEGATE_Z)
Brian00cdc0a2006-12-14 15:01:06 -0700345 s[i++] = '-';
346 s[i++] = swz[GET_SWZ(swizzle, 2)];
347
348 if (extended) {
349 s[i++] = ',';
350 }
351
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600352 if (negateBase & NEGATE_W)
Brian00cdc0a2006-12-14 15:01:06 -0700353 s[i++] = '-';
354 s[i++] = swz[GET_SWZ(swizzle, 3)];
355
356 s[i] = 0;
357 return s;
358}
359
360
Brian Paul610c2462008-11-13 16:37:52 -0700361const char *
362_mesa_writemask_string(GLuint writeMask)
Brian00cdc0a2006-12-14 15:01:06 -0700363{
364 static char s[10];
365 GLuint i = 0;
366
367 if (writeMask == WRITEMASK_XYZW)
368 return "";
369
370 s[i++] = '.';
371 if (writeMask & WRITEMASK_X)
372 s[i++] = 'x';
373 if (writeMask & WRITEMASK_Y)
374 s[i++] = 'y';
375 if (writeMask & WRITEMASK_Z)
376 s[i++] = 'z';
377 if (writeMask & WRITEMASK_W)
378 s[i++] = 'w';
379
380 s[i] = 0;
381 return s;
382}
383
Brian3a281532006-12-16 12:51:34 -0700384
Briand7508612007-03-28 11:01:09 -0600385const char *
386_mesa_condcode_string(GLuint condcode)
Brian3a281532006-12-16 12:51:34 -0700387{
388 switch (condcode) {
389 case COND_GT: return "GT";
390 case COND_EQ: return "EQ";
391 case COND_LT: return "LT";
392 case COND_UN: return "UN";
393 case COND_GE: return "GE";
394 case COND_LE: return "LE";
395 case COND_NE: return "NE";
396 case COND_TR: return "TR";
397 case COND_FL: return "FL";
398 default: return "cond???";
399 }
400}
401
402
Brian00cdc0a2006-12-14 15:01:06 -0700403static void
Brian501ee872007-02-17 09:15:00 -0700404print_dst_reg(const struct prog_dst_register *dstReg, gl_prog_print_mode mode,
405 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700406{
Brian501ee872007-02-17 09:15:00 -0700407 _mesa_printf("%s%s",
408 reg_string((enum register_file) dstReg->File,
Brian Paulf4361542008-11-11 10:47:10 -0700409 dstReg->Index, mode, dstReg->RelAddr, prog),
Brian Paul610c2462008-11-13 16:37:52 -0700410 _mesa_writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700411
Brian1936b252007-03-22 09:04:18 -0600412 if (dstReg->CondMask != COND_TR) {
413 _mesa_printf(" (%s.%s)",
Briand7508612007-03-28 11:01:09 -0600414 _mesa_condcode_string(dstReg->CondMask),
Brian1936b252007-03-22 09:04:18 -0600415 _mesa_swizzle_string(dstReg->CondSwizzle, GL_FALSE, GL_FALSE));
416 }
417
Brian501ee872007-02-17 09:15:00 -0700418#if 0
419 _mesa_printf("%s[%d]%s",
420 file_string((enum register_file) dstReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700421 dstReg->Index,
Brian Paul610c2462008-11-13 16:37:52 -0700422 _mesa_writemask_string(dstReg->WriteMask));
Brian501ee872007-02-17 09:15:00 -0700423#endif
Brian00cdc0a2006-12-14 15:01:06 -0700424}
425
426static void
Brian501ee872007-02-17 09:15:00 -0700427print_src_reg(const struct prog_src_register *srcReg, gl_prog_print_mode mode,
428 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700429{
Brian501ee872007-02-17 09:15:00 -0700430 _mesa_printf("%s%s",
431 reg_string((enum register_file) srcReg->File,
Zack Rusin74964ff2008-06-10 16:59:44 -0400432 srcReg->Index, mode, srcReg->RelAddr, prog),
Brian059376c2007-02-22 17:45:32 -0700433 _mesa_swizzle_string(srcReg->Swizzle,
Zack Rusin74964ff2008-06-10 16:59:44 -0400434 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700435#if 0
Brian00cdc0a2006-12-14 15:01:06 -0700436 _mesa_printf("%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700437 file_string((enum register_file) srcReg->File, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700438 srcReg->Index,
Brian059376c2007-02-22 17:45:32 -0700439 _mesa_swizzle_string(srcReg->Swizzle,
Brian00cdc0a2006-12-14 15:01:06 -0700440 srcReg->NegateBase, GL_FALSE));
Brian501ee872007-02-17 09:15:00 -0700441#endif
Brian00cdc0a2006-12-14 15:01:06 -0700442}
443
444static void
445print_comment(const struct prog_instruction *inst)
446{
447 if (inst->Comment)
448 _mesa_printf("; # %s\n", inst->Comment);
449 else
450 _mesa_printf(";\n");
451}
452
453
Brian501ee872007-02-17 09:15:00 -0700454static void
455print_alu_instruction(const struct prog_instruction *inst,
Brian0020d102007-02-23 11:43:44 -0700456 const char *opcode_string, GLuint numRegs,
Brian501ee872007-02-17 09:15:00 -0700457 gl_prog_print_mode mode,
458 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700459{
460 GLuint j;
461
462 _mesa_printf("%s", opcode_string);
Brianb50280e2006-12-18 16:21:58 -0700463 if (inst->CondUpdate)
464 _mesa_printf(".C");
Brian00cdc0a2006-12-14 15:01:06 -0700465
466 /* frag prog only */
467 if (inst->SaturateMode == SATURATE_ZERO_ONE)
468 _mesa_printf("_SAT");
469
Brian501ee872007-02-17 09:15:00 -0700470 _mesa_printf(" ");
Brian00cdc0a2006-12-14 15:01:06 -0700471 if (inst->DstReg.File != PROGRAM_UNDEFINED) {
Brian501ee872007-02-17 09:15:00 -0700472 print_dst_reg(&inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700473 }
474 else {
475 _mesa_printf(" ???");
476 }
477
478 if (numRegs > 0)
479 _mesa_printf(", ");
480
481 for (j = 0; j < numRegs; j++) {
Brian501ee872007-02-17 09:15:00 -0700482 print_src_reg(inst->SrcReg + j, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700483 if (j + 1 < numRegs)
484 _mesa_printf(", ");
485 }
486
Brian00cdc0a2006-12-14 15:01:06 -0700487 print_comment(inst);
488}
489
490
Brian501ee872007-02-17 09:15:00 -0700491void
Brian0020d102007-02-23 11:43:44 -0700492_mesa_print_alu_instruction(const struct prog_instruction *inst,
493 const char *opcode_string, GLuint numRegs)
494{
495 print_alu_instruction(inst, opcode_string, numRegs, PROG_PRINT_DEBUG, NULL);
496}
497
498
499void
Brian501ee872007-02-17 09:15:00 -0700500_mesa_print_instruction(const struct prog_instruction *inst)
501{
502 /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
503 _mesa_print_instruction_opt(inst, 0, PROG_PRINT_DEBUG, NULL);
504}
505
506
Brian00cdc0a2006-12-14 15:01:06 -0700507/**
508 * Print a single vertex/fragment program instruction.
509 */
Brian5db088d2007-02-05 14:58:15 -0700510GLint
Brian501ee872007-02-17 09:15:00 -0700511_mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent,
512 gl_prog_print_mode mode,
513 const struct gl_program *prog)
Brian00cdc0a2006-12-14 15:01:06 -0700514{
Brian7b300532007-02-22 09:08:36 -0700515 GLint i;
Brian5db088d2007-02-05 14:58:15 -0700516
517 if (inst->Opcode == OPCODE_ELSE ||
518 inst->Opcode == OPCODE_ENDIF ||
519 inst->Opcode == OPCODE_ENDLOOP ||
520 inst->Opcode == OPCODE_ENDSUB) {
521 indent -= 3;
522 }
Brian5db088d2007-02-05 14:58:15 -0700523 for (i = 0; i < indent; i++) {
524 _mesa_printf(" ");
525 }
526
Brian00cdc0a2006-12-14 15:01:06 -0700527 switch (inst->Opcode) {
528 case OPCODE_PRINT:
529 _mesa_printf("PRINT '%s'", inst->Data);
530 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
531 _mesa_printf(", ");
532 _mesa_printf("%s[%d]%s",
Brian501ee872007-02-17 09:15:00 -0700533 file_string((enum register_file) inst->SrcReg[0].File,
534 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700535 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700536 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
537 inst->SrcReg[0].NegateBase, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700538 }
539 if (inst->Comment)
540 _mesa_printf(" # %s", inst->Comment);
541 print_comment(inst);
542 break;
543 case OPCODE_SWZ:
544 _mesa_printf("SWZ");
545 if (inst->SaturateMode == SATURATE_ZERO_ONE)
546 _mesa_printf("_SAT");
Brian501ee872007-02-17 09:15:00 -0700547 _mesa_printf(" ");
548 print_dst_reg(&inst->DstReg, mode, prog);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600549 _mesa_printf(", %s[%d], %s",
Brian501ee872007-02-17 09:15:00 -0700550 file_string((enum register_file) inst->SrcReg[0].File,
551 mode),
Brian00cdc0a2006-12-14 15:01:06 -0700552 inst->SrcReg[0].Index,
Brian059376c2007-02-22 17:45:32 -0700553 _mesa_swizzle_string(inst->SrcReg[0].Swizzle,
554 inst->SrcReg[0].NegateBase, GL_TRUE));
Brian00cdc0a2006-12-14 15:01:06 -0700555 print_comment(inst);
556 break;
557 case OPCODE_TEX:
558 case OPCODE_TXP:
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600559 case OPCODE_TXL:
Brian00cdc0a2006-12-14 15:01:06 -0700560 case OPCODE_TXB:
561 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
562 if (inst->SaturateMode == SATURATE_ZERO_ONE)
563 _mesa_printf("_SAT");
Brian501ee872007-02-17 09:15:00 -0700564 _mesa_printf(" ");
565 print_dst_reg(&inst->DstReg, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700566 _mesa_printf(", ");
Brian501ee872007-02-17 09:15:00 -0700567 print_src_reg(&inst->SrcReg[0], mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700568 _mesa_printf(", texture[%d], ", inst->TexSrcUnit);
569 switch (inst->TexSrcTarget) {
570 case TEXTURE_1D_INDEX: _mesa_printf("1D"); break;
571 case TEXTURE_2D_INDEX: _mesa_printf("2D"); break;
572 case TEXTURE_3D_INDEX: _mesa_printf("3D"); break;
573 case TEXTURE_CUBE_INDEX: _mesa_printf("CUBE"); break;
574 case TEXTURE_RECT_INDEX: _mesa_printf("RECT"); break;
575 default:
576 ;
577 }
578 print_comment(inst);
579 break;
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600580
581 case OPCODE_KIL:
582 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
583 _mesa_printf(" ");
584 print_src_reg(&inst->SrcReg[0], mode, prog);
585 print_comment(inst);
586 break;
587 case OPCODE_KIL_NV:
588 _mesa_printf("%s", _mesa_opcode_string(inst->Opcode));
589 _mesa_printf(" ");
590 _mesa_printf("%s.%s",
591 _mesa_condcode_string(inst->DstReg.CondMask),
592 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
593 GL_FALSE, GL_FALSE));
594 print_comment(inst);
595 break;
596
Brian00cdc0a2006-12-14 15:01:06 -0700597 case OPCODE_ARL:
Zack Rusin74964ff2008-06-10 16:59:44 -0400598 _mesa_printf("ARL ");
599 print_dst_reg(&inst->DstReg, mode, prog);
600 _mesa_printf(", ");
Brian501ee872007-02-17 09:15:00 -0700601 print_src_reg(&inst->SrcReg[0], mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700602 print_comment(inst);
603 break;
604 case OPCODE_BRA:
Briand7508612007-03-28 11:01:09 -0600605 _mesa_printf("BRA %d (%s%s)",
Brian3a281532006-12-16 12:51:34 -0700606 inst->BranchTarget,
Briand7508612007-03-28 11:01:09 -0600607 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700608 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian00cdc0a2006-12-14 15:01:06 -0700609 print_comment(inst);
610 break;
Brian5ae49cf2007-01-20 09:27:40 -0700611 case OPCODE_IF:
Brian63556fa2007-03-23 14:47:46 -0600612 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
613 /* Use ordinary register */
614 _mesa_printf("IF ");
615 print_src_reg(&inst->SrcReg[0], mode, prog);
616 _mesa_printf("; ");
617 }
618 else {
619 /* Use cond codes */
620 _mesa_printf("IF (%s%s);",
Briand7508612007-03-28 11:01:09 -0600621 _mesa_condcode_string(inst->DstReg.CondMask),
Brian63556fa2007-03-23 14:47:46 -0600622 _mesa_swizzle_string(inst->DstReg.CondSwizzle,
623 0, GL_FALSE));
624 }
625 _mesa_printf(" # (if false, goto %d)", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700626 print_comment(inst);
627 return indent + 3;
628 case OPCODE_ELSE:
Brian501ee872007-02-17 09:15:00 -0700629 _mesa_printf("ELSE; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700630 return indent + 3;
631 case OPCODE_ENDIF:
Brian501ee872007-02-17 09:15:00 -0700632 _mesa_printf("ENDIF;\n");
Brian5db088d2007-02-05 14:58:15 -0700633 break;
634 case OPCODE_BGNLOOP:
Brian501ee872007-02-17 09:15:00 -0700635 _mesa_printf("BGNLOOP; # (end at %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700636 return indent + 3;
637 case OPCODE_ENDLOOP:
Brian501ee872007-02-17 09:15:00 -0700638 _mesa_printf("ENDLOOP; # (goto %d)\n", inst->BranchTarget);
Brian5db088d2007-02-05 14:58:15 -0700639 break;
640 case OPCODE_BRK:
Brianf22ed092007-02-06 22:31:19 -0700641 case OPCODE_CONT:
Brian81767ee2007-03-23 17:45:53 -0600642 _mesa_printf("%s (%s%s); # (goto %d)",
643 _mesa_opcode_string(inst->Opcode),
Briand7508612007-03-28 11:01:09 -0600644 _mesa_condcode_string(inst->DstReg.CondMask),
Brian059376c2007-02-22 17:45:32 -0700645 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
Brian2755c792007-02-05 18:01:02 -0700646 inst->BranchTarget);
Brian5ae49cf2007-01-20 09:27:40 -0700647 print_comment(inst);
648 break;
Brian63556fa2007-03-23 14:47:46 -0600649
Brian5db088d2007-02-05 14:58:15 -0700650 case OPCODE_BGNSUB:
Brianf407cad2007-03-27 14:53:17 -0600651 if (mode == PROG_PRINT_NV) {
652 _mesa_printf("%s:\n", inst->Comment); /* comment is label */
653 return indent;
654 }
655 else {
656 _mesa_printf("BGNSUB");
657 print_comment(inst);
658 return indent + 3;
659 }
Brian5db088d2007-02-05 14:58:15 -0700660 case OPCODE_ENDSUB:
Brianf407cad2007-03-27 14:53:17 -0600661 if (mode == PROG_PRINT_DEBUG) {
662 _mesa_printf("ENDSUB");
663 print_comment(inst);
664 }
665 break;
666 case OPCODE_CAL:
667 if (mode == PROG_PRINT_NV) {
Briand7508612007-03-28 11:01:09 -0600668 _mesa_printf("CAL %s; # (goto %d)\n", inst->Comment, inst->BranchTarget);
Brianf407cad2007-03-27 14:53:17 -0600669 }
670 else {
671 _mesa_printf("CAL %u", inst->BranchTarget);
672 print_comment(inst);
673 }
674 break;
675 case OPCODE_RET:
Briand7508612007-03-28 11:01:09 -0600676 _mesa_printf("RET (%s%s)",
677 _mesa_condcode_string(inst->DstReg.CondMask),
678 _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
Brian5db088d2007-02-05 14:58:15 -0700679 print_comment(inst);
Brian5ae49cf2007-01-20 09:27:40 -0700680 break;
Brianf407cad2007-03-27 14:53:17 -0600681
Brian00cdc0a2006-12-14 15:01:06 -0700682 case OPCODE_END:
Brian501ee872007-02-17 09:15:00 -0700683 _mesa_printf("END\n");
Brian00cdc0a2006-12-14 15:01:06 -0700684 break;
Brian3a281532006-12-16 12:51:34 -0700685 case OPCODE_NOP:
Brian059376c2007-02-22 17:45:32 -0700686 if (mode == PROG_PRINT_DEBUG) {
687 _mesa_printf("NOP");
688 print_comment(inst);
689 }
690 else if (inst->Comment) {
691 /* ARB/NV extensions don't have NOP instruction */
692 _mesa_printf("# %s\n", inst->Comment);
693 }
Brian3a281532006-12-16 12:51:34 -0700694 break;
Brian00cdc0a2006-12-14 15:01:06 -0700695 /* XXX may need other special-case instructions */
696 default:
697 /* typical alu instruction */
Brian501ee872007-02-17 09:15:00 -0700698 print_alu_instruction(inst,
699 _mesa_opcode_string(inst->Opcode),
700 _mesa_num_inst_src_regs(inst->Opcode),
701 mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700702 break;
703 }
Brian5db088d2007-02-05 14:58:15 -0700704 return indent;
Brian00cdc0a2006-12-14 15:01:06 -0700705}
706
707
708/**
Brian501ee872007-02-17 09:15:00 -0700709 * Print program to stdout, default options.
Brian00cdc0a2006-12-14 15:01:06 -0700710 */
711void
712_mesa_print_program(const struct gl_program *prog)
713{
Brian9449a4d2007-02-17 09:41:59 -0700714 _mesa_print_program_opt(prog, PROG_PRINT_DEBUG, GL_TRUE);
Brian501ee872007-02-17 09:15:00 -0700715}
716
717
718/**
719 * Print program, with options.
720 */
721void
722_mesa_print_program_opt(const struct gl_program *prog,
723 gl_prog_print_mode mode,
724 GLboolean lineNumbers)
725{
Brian5db088d2007-02-05 14:58:15 -0700726 GLuint i, indent = 0;
Brian501ee872007-02-17 09:15:00 -0700727
728 switch (prog->Target) {
729 case GL_VERTEX_PROGRAM_ARB:
730 if (mode == PROG_PRINT_ARB)
731 _mesa_printf("!!ARBvp1.0\n");
732 else if (mode == PROG_PRINT_NV)
733 _mesa_printf("!!VP1.0\n");
734 else
735 _mesa_printf("# Vertex Program/Shader\n");
736 break;
737 case GL_FRAGMENT_PROGRAM_ARB:
738 case GL_FRAGMENT_PROGRAM_NV:
739 if (mode == PROG_PRINT_ARB)
740 _mesa_printf("!!ARBfp1.0\n");
741 else if (mode == PROG_PRINT_NV)
742 _mesa_printf("!!FP1.0\n");
743 else
744 _mesa_printf("# Fragment Program/Shader\n");
745 break;
746 }
747
Brian00cdc0a2006-12-14 15:01:06 -0700748 for (i = 0; i < prog->NumInstructions; i++) {
Brian501ee872007-02-17 09:15:00 -0700749 if (lineNumbers)
750 _mesa_printf("%3d: ", i);
751 indent = _mesa_print_instruction_opt(prog->Instructions + i,
752 indent, mode, prog);
Brian00cdc0a2006-12-14 15:01:06 -0700753 }
754}
755
756
757/**
758 * Print all of a program's parameters.
759 */
760void
761_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
762{
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600763 GLuint i;
764
Brian00cdc0a2006-12-14 15:01:06 -0700765 _mesa_printf("InputsRead: 0x%x\n", prog->InputsRead);
766 _mesa_printf("OutputsWritten: 0x%x\n", prog->OutputsWritten);
767 _mesa_printf("NumInstructions=%d\n", prog->NumInstructions);
768 _mesa_printf("NumTemporaries=%d\n", prog->NumTemporaries);
769 _mesa_printf("NumParameters=%d\n", prog->NumParameters);
770 _mesa_printf("NumAttributes=%d\n", prog->NumAttributes);
771 _mesa_printf("NumAddressRegs=%d\n", prog->NumAddressRegs);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600772 _mesa_printf("Samplers=[ ");
773 for (i = 0; i < MAX_SAMPLERS; i++) {
774 _mesa_printf("%d ", prog->SamplerUnits[i]);
775 }
776 _mesa_printf("]\n");
777
Brian00cdc0a2006-12-14 15:01:06 -0700778 _mesa_load_state_parameters(ctx, prog->Parameters);
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600779
Brian00cdc0a2006-12-14 15:01:06 -0700780#if 0
781 _mesa_printf("Local Params:\n");
782 for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){
783 const GLfloat *p = prog->LocalParams[i];
784 _mesa_printf("%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]);
785 }
786#endif
Brian83ca3ff2006-12-20 17:17:38 -0700787 _mesa_print_parameter_list(prog->Parameters);
788}
Brian00cdc0a2006-12-14 15:01:06 -0700789
Brian83ca3ff2006-12-20 17:17:38 -0700790
791void
792_mesa_print_parameter_list(const struct gl_program_parameter_list *list)
793{
Brian501ee872007-02-17 09:15:00 -0700794 const gl_prog_print_mode mode = PROG_PRINT_DEBUG;
Brian83ca3ff2006-12-20 17:17:38 -0700795 GLuint i;
Brian501ee872007-02-17 09:15:00 -0700796
Brian Paul4b6b0fd2008-05-18 15:41:01 -0600797 if (!list)
798 return;
799
Brian83ca3ff2006-12-20 17:17:38 -0700800 _mesa_printf("param list %p\n", (void *) list);
801 for (i = 0; i < list->NumParameters; i++){
802 struct gl_program_parameter *param = list->Parameters + i;
803 const GLfloat *v = list->ParameterValues[i];
Brian Paul777a5c42008-11-24 08:43:38 -0700804 _mesa_printf("param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}",
Brian83ca3ff2006-12-20 17:17:38 -0700805 i, param->Size,
Brian501ee872007-02-17 09:15:00 -0700806 file_string(list->Parameters[i].Type, mode),
Brian00cdc0a2006-12-14 15:01:06 -0700807 param->Name, v[0], v[1], v[2], v[3]);
Brian Paulf490ec92008-11-24 09:04:52 -0700808 if (param->Flags & PROG_PARAM_BIT_CENTROID)
Brian Paul777a5c42008-11-24 08:43:38 -0700809 _mesa_printf(" Centroid");
Brian Paulf490ec92008-11-24 09:04:52 -0700810 if (param->Flags & PROG_PARAM_BIT_INVARIANT)
Brian Paul777a5c42008-11-24 08:43:38 -0700811 _mesa_printf(" Invariant");
Brian Paulf490ec92008-11-24 09:04:52 -0700812 if (param->Flags & PROG_PARAM_BIT_FLAT)
Brian Paul777a5c42008-11-24 08:43:38 -0700813 _mesa_printf(" Flat");
Brian Paulf490ec92008-11-24 09:04:52 -0700814 if (param->Flags & PROG_PARAM_BIT_LINEAR)
Brian Paul777a5c42008-11-24 08:43:38 -0700815 _mesa_printf(" Linear");
816 _mesa_printf("\n");
Brian00cdc0a2006-12-14 15:01:06 -0700817 }
818}