Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / gallium / drivers / 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 #include "tgsi/tgsi_info.h"
33
34 #include "brw_context.h"
35 #include "brw_wm.h"
36
37 static void print_writemask( unsigned writemask )
38 {
39 if (writemask != BRW_WRITEMASK_XYZW)
40 debug_printf(".%s%s%s%s",
41 (writemask & BRW_WRITEMASK_X) ? "x" : "",
42 (writemask & BRW_WRITEMASK_Y) ? "y" : "",
43 (writemask & BRW_WRITEMASK_Z) ? "z" : "",
44 (writemask & BRW_WRITEMASK_W) ? "w" : "");
45 }
46
47 static void print_swizzle( unsigned swizzle )
48 {
49 char *swz = "xyzw";
50 if (swizzle != BRW_SWIZZLE_XYZW)
51 debug_printf(".%c%c%c%c",
52 swz[BRW_GET_SWZ(swizzle, X)],
53 swz[BRW_GET_SWZ(swizzle, Y)],
54 swz[BRW_GET_SWZ(swizzle, Z)],
55 swz[BRW_GET_SWZ(swizzle, W)]);
56 }
57
58 static void print_opcode( unsigned opcode )
59 {
60 switch (opcode) {
61 case WM_PIXELXY:
62 debug_printf("PIXELXY");
63 break;
64 case WM_DELTAXY:
65 debug_printf("DELTAXY");
66 break;
67 case WM_PIXELW:
68 debug_printf("PIXELW");
69 break;
70 case WM_WPOSXY:
71 debug_printf("WPOSXY");
72 break;
73 case WM_PINTERP:
74 debug_printf("PINTERP");
75 break;
76 case WM_LINTERP:
77 debug_printf("LINTERP");
78 break;
79 case WM_CINTERP:
80 debug_printf("CINTERP");
81 break;
82 case WM_FB_WRITE:
83 debug_printf("FB_WRITE");
84 break;
85 case WM_FRONTFACING:
86 debug_printf("FRONTFACING");
87 break;
88 default:
89 debug_printf("%s", tgsi_get_opcode_info(opcode)->mnemonic);
90 break;
91 }
92 }
93
94 void brw_wm_print_value( struct brw_wm_compile *c,
95 struct brw_wm_value *value )
96 {
97 assert(value);
98 if (c->state >= PASS2_DONE)
99 brw_print_reg(value->hw_reg);
100 else if( value == &c->undef_value )
101 debug_printf("undef");
102 else if( value - c->vreg >= 0 &&
103 value - c->vreg < BRW_WM_MAX_VREG)
104 debug_printf("r%ld", (long) (value - c->vreg));
105 else if (value - c->creg >= 0 &&
106 value - c->creg < BRW_WM_MAX_PARAM)
107 debug_printf("c%ld", (long) (value - c->creg));
108 else if (value - c->payload.input_interp >= 0 &&
109 value - c->payload.input_interp < PIPE_MAX_SHADER_INPUTS)
110 debug_printf("i%ld", (long) (value - c->payload.input_interp));
111 else if (value - c->payload.depth >= 0 &&
112 value - c->payload.depth < PIPE_MAX_SHADER_INPUTS)
113 debug_printf("d%ld", (long) (value - c->payload.depth));
114 else
115 debug_printf("?");
116 }
117
118 void brw_wm_print_ref( struct brw_wm_compile *c,
119 struct brw_wm_ref *ref )
120 {
121 struct brw_reg hw_reg = ref->hw_reg;
122
123 if (ref->unspill_reg)
124 debug_printf("UNSPILL(%x)/", ref->value->spill_slot);
125
126 if (c->state >= PASS2_DONE)
127 brw_print_reg(ref->hw_reg);
128 else {
129 debug_printf("%s", hw_reg.negate ? "-" : "");
130 debug_printf("%s", hw_reg.abs ? "abs/" : "");
131 brw_wm_print_value(c, ref->value);
132 if ((hw_reg.nr&1) || hw_reg.subnr) {
133 debug_printf("->%d.%d", (hw_reg.nr&1), hw_reg.subnr);
134 }
135 }
136 }
137
138 void brw_wm_print_insn( struct brw_wm_compile *c,
139 struct brw_wm_instruction *inst )
140 {
141 GLuint i, arg;
142 GLuint nr_args = brw_wm_nr_args(inst->opcode);
143
144 debug_printf("[");
145 for (i = 0; i < 4; i++) {
146 if (inst->dst[i]) {
147 brw_wm_print_value(c, inst->dst[i]);
148 if (inst->dst[i]->spill_slot)
149 debug_printf("/SPILL(%x)",inst->dst[i]->spill_slot);
150 }
151 else
152 debug_printf("#");
153 if (i < 3)
154 debug_printf(",");
155 }
156 debug_printf("]");
157 print_writemask(inst->writemask);
158
159 debug_printf(" = ");
160 print_opcode(inst->opcode);
161
162 if (inst->saturate)
163 debug_printf("_SAT");
164
165 for (arg = 0; arg < nr_args; arg++) {
166
167 debug_printf(" [");
168
169 for (i = 0; i < 4; i++) {
170 if (inst->src[arg][i]) {
171 brw_wm_print_ref(c, inst->src[arg][i]);
172 }
173 else
174 debug_printf("%%");
175
176 if (i < 3)
177 debug_printf(",");
178 else
179 debug_printf("]");
180 }
181 }
182 debug_printf("\n");
183 }
184
185 void brw_wm_print_program( struct brw_wm_compile *c,
186 const char *stage )
187 {
188 GLuint insn;
189
190 debug_printf("%s:\n", stage);
191 for (insn = 0; insn < c->nr_insns; insn++)
192 brw_wm_print_insn(c, &c->instruction[insn]);
193 debug_printf("\n");
194 }
195
196 static const char *file_strings[TGSI_FILE_COUNT+1] = {
197 "NULL",
198 "CONST",
199 "IN",
200 "OUT",
201 "TEMP",
202 "SAMPLER",
203 "ADDR",
204 "IMM",
205 "PRED",
206 "SV",
207 "PAYLOAD"
208 };
209
210 static void brw_wm_print_fp_insn( struct brw_wm_compile *c,
211 struct brw_fp_instruction *inst )
212 {
213 GLuint i;
214 GLuint nr_args = brw_wm_nr_args(inst->opcode);
215
216 print_opcode(inst->opcode);
217 if (inst->dst.saturate)
218 debug_printf("_SAT");
219 debug_printf(" ");
220
221 if (inst->dst.indirect)
222 debug_printf("[");
223
224 debug_printf("%s[%d]",
225 file_strings[inst->dst.file],
226 inst->dst.index );
227 print_writemask(inst->dst.writemask);
228
229 if (inst->dst.indirect)
230 debug_printf("]");
231
232 debug_printf(nr_args ? ", " : "\n");
233
234 for (i = 0; i < nr_args; i++) {
235 debug_printf("%s%s%s[%d]%s",
236 inst->src[i].negate ? "-" : "",
237 inst->src[i].abs ? "ABS(" : "",
238 file_strings[inst->src[i].file],
239 inst->src[i].index,
240 inst->src[i].abs ? ")" : "");
241 print_swizzle(inst->src[i].swizzle);
242 debug_printf("%s", i == nr_args - 1 ? "\n" : ", ");
243 }
244 }
245
246
247 void brw_wm_print_fp_program( struct brw_wm_compile *c,
248 const char *stage )
249 {
250 GLuint insn;
251
252 debug_printf("%s:\n", stage);
253 for (insn = 0; insn < c->nr_fp_insns; insn++)
254 brw_wm_print_fp_insn(c, &c->fp_instructions[insn]);
255 debug_printf("\n");
256 }
257