Merge branch 'nouveau-import'
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm_debug.c
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 #include "program.h"
36 #include "shader/arbprogparse.h"
37 #include "shader/program_instruction.h"
38
39
40 void brw_wm_print_value( struct brw_wm_compile *c,
41 struct brw_wm_value *value )
42 {
43 assert(value);
44 if (c->state >= PASS2_DONE)
45 brw_print_reg(value->hw_reg);
46 else if( value == &c->undef_value )
47 _mesa_printf("undef");
48 else if( value - c->vreg >= 0 &&
49 value - c->vreg < BRW_WM_MAX_VREG)
50 _mesa_printf("r%d", value - c->vreg);
51 else if (value - c->creg >= 0 &&
52 value - c->creg < BRW_WM_MAX_PARAM)
53 _mesa_printf("c%d", value - c->creg);
54 else if (value - c->payload.input_interp >= 0 &&
55 value - c->payload.input_interp < FRAG_ATTRIB_MAX)
56 _mesa_printf("i%d", value - c->payload.input_interp);
57 else if (value - c->payload.depth >= 0 &&
58 value - c->payload.depth < FRAG_ATTRIB_MAX)
59 _mesa_printf("d%d", value - c->payload.depth);
60 else
61 _mesa_printf("?");
62 }
63
64 void brw_wm_print_ref( struct brw_wm_compile *c,
65 struct brw_wm_ref *ref )
66 {
67 struct brw_reg hw_reg = ref->hw_reg;
68
69 if (ref->unspill_reg)
70 _mesa_printf("UNSPILL(%x)/", ref->value->spill_slot);
71
72 if (c->state >= PASS2_DONE)
73 brw_print_reg(ref->hw_reg);
74 else {
75 _mesa_printf("%s", hw_reg.negate ? "-" : "");
76 _mesa_printf("%s", hw_reg.abs ? "abs/" : "");
77 brw_wm_print_value(c, ref->value);
78 if ((hw_reg.nr&1) || hw_reg.subnr) {
79 _mesa_printf("->%d.%d", (hw_reg.nr&1), hw_reg.subnr);
80 }
81 }
82 }
83
84 void brw_wm_print_insn( struct brw_wm_compile *c,
85 struct brw_wm_instruction *inst )
86 {
87 GLuint i, arg;
88 GLuint nr_args = brw_wm_nr_args(inst->opcode);
89
90 _mesa_printf("[");
91 for (i = 0; i < 4; i++) {
92 if (inst->dst[i]) {
93 brw_wm_print_value(c, inst->dst[i]);
94 if (inst->dst[i]->spill_slot)
95 _mesa_printf("/SPILL(%x)",inst->dst[i]->spill_slot);
96 }
97 else
98 _mesa_printf("#");
99 if (i < 3)
100 _mesa_printf(",");
101 }
102 _mesa_printf("]");
103
104 if (inst->writemask != WRITEMASK_XYZW)
105 _mesa_printf(".%s%s%s%s",
106 GET_BIT(inst->writemask, 0) ? "x" : "",
107 GET_BIT(inst->writemask, 1) ? "y" : "",
108 GET_BIT(inst->writemask, 2) ? "z" : "",
109 GET_BIT(inst->writemask, 3) ? "w" : "");
110
111 switch (inst->opcode) {
112 case WM_PIXELXY:
113 _mesa_printf(" = PIXELXY");
114 break;
115 case WM_DELTAXY:
116 _mesa_printf(" = DELTAXY");
117 break;
118 case WM_PIXELW:
119 _mesa_printf(" = PIXELW");
120 break;
121 case WM_WPOSXY:
122 _mesa_printf(" = WPOSXY");
123 break;
124 case WM_PINTERP:
125 _mesa_printf(" = PINTERP");
126 break;
127 case WM_LINTERP:
128 _mesa_printf(" = LINTERP");
129 break;
130 case WM_CINTERP:
131 _mesa_printf(" = CINTERP");
132 break;
133 case WM_FB_WRITE:
134 _mesa_printf(" = FB_WRITE");
135 break;
136 default:
137 _mesa_printf(" = %s", _mesa_opcode_string(inst->opcode));
138 break;
139 }
140
141 if (inst->saturate)
142 _mesa_printf("_SAT");
143
144 for (arg = 0; arg < nr_args; arg++) {
145
146 _mesa_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 _mesa_printf("%%");
154
155 if (i < 3)
156 _mesa_printf(",");
157 else
158 _mesa_printf("]");
159 }
160 }
161 _mesa_printf("\n");
162 }
163
164 void brw_wm_print_program( struct brw_wm_compile *c,
165 const char *stage )
166 {
167 GLuint insn;
168
169 _mesa_printf("\n\n\n%s:\n", stage);
170 for (insn = 0; insn < c->nr_insns; insn++)
171 brw_wm_print_insn(c, &c->instruction[insn]);
172 _mesa_printf("\n\n\n");
173 }
174