1/*
2 Copyright (C) Intel Corp.  2006.  All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28  * Authors:
29  *   Keith Whitwell <keith@tungstengraphics.com>
30  */
31
32
33#include "brw_context.h"
34#include "brw_wm.h"
35
36
37void brw_wm_print_value( struct brw_wm_compile *c,
38		       struct brw_wm_value *value )
39{
40   assert(value);
41   if (c->state >= PASS2_DONE)
42      brw_print_reg(value->hw_reg);
43   else if( value == &c->undef_value )
44      printf("undef");
45   else if( value - c->vreg >= 0 &&
46	    value - c->vreg < BRW_WM_MAX_VREG)
47      printf("r%ld", (long) (value - c->vreg));
48   else if (value - c->creg >= 0 &&
49	    value - c->creg < BRW_WM_MAX_PARAM)
50      printf("c%ld", (long) (value - c->creg));
51   else if (value - c->payload.input_interp >= 0 &&
52	    value - c->payload.input_interp < FRAG_ATTRIB_MAX)
53      printf("i%ld", (long) (value - c->payload.input_interp));
54   else if (value - c->payload.depth >= 0 &&
55	    value - c->payload.depth < FRAG_ATTRIB_MAX)
56      printf("d%ld", (long) (value - c->payload.depth));
57   else
58      printf("?");
59}
60
61void brw_wm_print_ref( struct brw_wm_compile *c,
62		       struct brw_wm_ref *ref )
63{
64   struct brw_reg hw_reg = ref->hw_reg;
65
66   if (ref->unspill_reg)
67      printf("UNSPILL(%x)/", ref->value->spill_slot);
68
69   if (c->state >= PASS2_DONE)
70      brw_print_reg(ref->hw_reg);
71   else {
72      printf("%s", hw_reg.negate ? "-" : "");
73      printf("%s", hw_reg.abs ? "abs/" : "");
74      brw_wm_print_value(c, ref->value);
75      if ((hw_reg.nr&1) || hw_reg.subnr) {
76	 printf("->%d.%d", (hw_reg.nr&1), hw_reg.subnr);
77      }
78   }
79}
80
81void brw_wm_print_insn( struct brw_wm_compile *c,
82			struct brw_wm_instruction *inst )
83{
84   GLuint i, arg;
85   GLuint nr_args = brw_wm_nr_args(inst->opcode);
86
87   printf("[");
88   for (i = 0; i < 4; i++) {
89      if (inst->dst[i]) {
90	 brw_wm_print_value(c, inst->dst[i]);
91	 if (inst->dst[i]->spill_slot)
92	    printf("/SPILL(%x)",inst->dst[i]->spill_slot);
93      }
94      else
95	 printf("#");
96      if (i < 3)
97	 printf(",");
98   }
99   printf("]");
100
101   if (inst->writemask != WRITEMASK_XYZW)
102      printf(".%s%s%s%s",
103		   GET_BIT(inst->writemask, 0) ? "x" : "",
104		   GET_BIT(inst->writemask, 1) ? "y" : "",
105		   GET_BIT(inst->writemask, 2) ? "z" : "",
106		   GET_BIT(inst->writemask, 3) ? "w" : "");
107
108   switch (inst->opcode) {
109   case WM_PIXELXY:
110      printf(" = PIXELXY");
111      break;
112   case WM_DELTAXY:
113      printf(" = DELTAXY");
114      break;
115   case WM_PIXELW:
116      printf(" = PIXELW");
117      break;
118   case WM_WPOSXY:
119      printf(" = WPOSXY");
120      break;
121   case WM_PINTERP:
122      printf(" = PINTERP");
123      break;
124   case WM_LINTERP:
125      printf(" = LINTERP");
126      break;
127   case WM_CINTERP:
128      printf(" = CINTERP");
129      break;
130   case WM_FB_WRITE:
131      printf(" = FB_WRITE");
132      break;
133   case WM_FRONTFACING:
134      printf(" = FRONTFACING");
135      break;
136   default:
137      printf(" = %s", _mesa_opcode_string(inst->opcode));
138      break;
139   }
140
141   if (inst->saturate)
142      printf("_SAT");
143
144   for (arg = 0; arg < nr_args; arg++) {
145
146      printf(" [");
147
148      for (i = 0; i < 4; i++) {
149	 if (inst->src[arg][i]) {
150	    brw_wm_print_ref(c, inst->src[arg][i]);
151	 }
152	 else
153	    printf("%%");
154
155	 if (i < 3)
156	    printf(",");
157	 else
158	    printf("]");
159      }
160   }
161   printf("\n");
162}
163
164void brw_wm_print_program( struct brw_wm_compile *c,
165			   const char *stage )
166{
167   GLuint insn;
168
169   printf("%s:\n", stage);
170   for (insn = 0; insn < c->nr_insns; insn++)
171      brw_wm_print_insn(c, &c->instruction[insn]);
172   printf("\n");
173}
174
175