Merge branch 'origin' into glsl-compiler-1
[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
36
37 void 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 _mesa_printf("undef");
45 else if( value - c->vreg >= 0 &&
46 value - c->vreg < BRW_WM_MAX_VREG)
47 _mesa_printf("r%d", value - c->vreg);
48 else if (value - c->creg >= 0 &&
49 value - c->creg < BRW_WM_MAX_PARAM)
50 _mesa_printf("c%d", value - c->creg);
51 else if (value - c->payload.input_interp >= 0 &&
52 value - c->payload.input_interp < FRAG_ATTRIB_MAX)
53 _mesa_printf("i%d", value - c->payload.input_interp);
54 else if (value - c->payload.depth >= 0 &&
55 value - c->payload.depth < FRAG_ATTRIB_MAX)
56 _mesa_printf("d%d", value - c->payload.depth);
57 else
58 _mesa_printf("?");
59 }
60
61 void 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 _mesa_printf("UNSPILL(%x)/", ref->value->spill_slot);
68
69 if (c->state >= PASS2_DONE)
70 brw_print_reg(ref->hw_reg);
71 else {
72 _mesa_printf("%s", hw_reg.negate ? "-" : "");
73 _mesa_printf("%s", hw_reg.abs ? "abs/" : "");
74 brw_wm_print_value(c, ref->value);
75 if ((hw_reg.nr&1) || hw_reg.subnr) {
76 _mesa_printf("->%d.%d", (hw_reg.nr&1), hw_reg.subnr);
77 }
78 }
79 }
80
81 void 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 _mesa_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 _mesa_printf("/SPILL(%x)",inst->dst[i]->spill_slot);
93 }
94 else
95 _mesa_printf("#");
96 if (i < 3)
97 _mesa_printf(",");
98 }
99 _mesa_printf("]");
100
101 if (inst->writemask != WRITEMASK_XYZW)
102 _mesa_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 _mesa_printf(" = PIXELXY");
111 break;
112 case WM_DELTAXY:
113 _mesa_printf(" = DELTAXY");
114 break;
115 case WM_PIXELW:
116 _mesa_printf(" = PIXELW");
117 break;
118 case WM_WPOSXY:
119 _mesa_printf(" = WPOSXY");
120 break;
121 case WM_PINTERP:
122 _mesa_printf(" = PINTERP");
123 break;
124 case WM_LINTERP:
125 _mesa_printf(" = LINTERP");
126 break;
127 case WM_CINTERP:
128 _mesa_printf(" = CINTERP");
129 break;
130 case WM_FB_WRITE:
131 _mesa_printf(" = FB_WRITE");
132 break;
133 default:
134 _mesa_printf(" = %s", _mesa_opcode_string(inst->opcode));
135 break;
136 }
137
138 if (inst->saturate)
139 _mesa_printf("_SAT");
140
141 for (arg = 0; arg < nr_args; arg++) {
142
143 _mesa_printf(" [");
144
145 for (i = 0; i < 4; i++) {
146 if (inst->src[arg][i]) {
147 brw_wm_print_ref(c, inst->src[arg][i]);
148 }
149 else
150 _mesa_printf("%%");
151
152 if (i < 3)
153 _mesa_printf(",");
154 else
155 _mesa_printf("]");
156 }
157 }
158 _mesa_printf("\n");
159 }
160
161 void brw_wm_print_program( struct brw_wm_compile *c,
162 const char *stage )
163 {
164 GLuint insn;
165
166 _mesa_printf("\n\n\n%s:\n", stage);
167 for (insn = 0; insn < c->nr_insns; insn++)
168 brw_wm_print_insn(c, &c->instruction[insn]);
169 _mesa_printf("\n\n\n");
170 }
171