10b0cf73532a003ef8e092df6de13c233f22e056
[mesa.git] / src / gallium / drivers / r300 / r300_debug.c
1 /*
2 * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #include "r300_debug.h"
24
25 static char* r500_fs_swiz[] = {
26 " R",
27 " G",
28 " B",
29 " A",
30 " 0",
31 ".5",
32 " 1",
33 " U",
34 };
35
36 static char* r500_fs_op_rgb[] = {
37 "MAD",
38 "DP3",
39 "DP4",
40 "D2A",
41 "MIN",
42 "MAX",
43 "---",
44 "CND",
45 "CMP",
46 "FRC",
47 "SOP",
48 "MDH",
49 "MDV",
50 };
51
52 static char* r500_fs_op_alpha[] = {
53 "MAD",
54 " DP",
55 "MIN",
56 "MAX",
57 "---",
58 "CND",
59 "CMP",
60 "FRC",
61 "EX2",
62 "LN2",
63 "RCP",
64 "RSQ",
65 "SIN",
66 "COS",
67 "MDH",
68 "MDV",
69 };
70
71 static char* r500_fs_mask[] = {
72 "NONE",
73 "R ",
74 " G ",
75 "RG ",
76 " B ",
77 "R B ",
78 " GB ",
79 "RGB ",
80 " A",
81 "R A",
82 " G A",
83 "RG A",
84 " BA",
85 "R BA",
86 " GBA",
87 "RGBA",
88 };
89
90 static char* r500_fs_tex[] = {
91 " NOP",
92 " LD",
93 "TEXKILL",
94 " PROJ",
95 "LODBIAS",
96 " LOD",
97 " DXDY",
98 };
99
100 void r500_fs_dump(struct r500_fragment_shader* fs)
101 {
102 int i;
103 uint32_t inst;
104
105 for (i = 0; i < fs->instruction_count; i++) {
106 inst = fs->instructions[i].inst0;
107 debug_printf("%d: 0: CMN_INST 0x%08x:", i, inst);
108 switch (inst & 0x3) {
109 case R500_INST_TYPE_ALU:
110 debug_printf("ALU ");
111 break;
112 case R500_INST_TYPE_OUT:
113 debug_printf("OUT ");
114 break;
115 case R500_INST_TYPE_FC:
116 debug_printf("FC ");
117 break;
118 case R500_INST_TYPE_TEX:
119 debug_printf("TEX ");
120 break;
121 }
122 debug_printf("%s %s %s %s ",
123 inst & R500_INST_TEX_SEM_WAIT ? "TEX_WAIT" : "",
124 inst & R500_INST_LAST ? "LAST" : "",
125 inst & R500_INST_NOP ? "NOP" : "",
126 inst & R500_INST_ALU_WAIT ? "ALU_WAIT" : "");
127 debug_printf("wmask: %s omask: %s\n",
128 r500_fs_mask[(inst >> 11) & 0xf],
129 r500_fs_mask[(inst >> 15) & 0xf]);
130 switch (inst & 0x3) {
131 case R500_INST_TYPE_ALU:
132 case R500_INST_TYPE_OUT:
133 inst = fs->instructions[i].inst1;
134 debug_printf(" 1: RGB_ADDR 0x%08x:", inst);
135 debug_printf("Addr0: %d%c, Addr1: %d%c, "
136 "Addr2: %d%c, srcp:%d\n",
137 inst & 0xff, (inst & (1 << 8)) ? 'c' : 't',
138 (inst >> 10) & 0xff, (inst & (1 << 18)) ? 'c' : 't',
139 (inst >> 20) & 0xff, (inst & (1 << 28)) ? 'c' : 't',
140 (inst >> 30));
141
142 inst = fs->instructions[i].inst2;
143 debug_printf(" 2: ALPHA_ADDR 0x%08x:", inst);
144 debug_printf("Addr0: %d%c, Addr1: %d%c, "
145 "Addr2: %d%c, srcp:%d\n",
146 inst & 0xff, (inst & (1 << 8)) ? 'c' : 't',
147 (inst >> 10) & 0xff, (inst & (1 << 18)) ? 'c' : 't',
148 (inst >> 20) & 0xff, (inst & (1 << 28)) ? 'c' : 't',
149 (inst >> 30));
150
151 inst = fs->instructions[i].inst3;
152 debug_printf(" 3: RGB_INST 0x%08x:", inst);
153 debug_printf("rgb_A_src:%d %s/%s/%s %d "
154 "rgb_B_src:%d %s/%s/%s %d\n",
155 inst & 0x3, r500_fs_swiz[(inst >> 2) & 0x7],
156 r500_fs_swiz[(inst >> 5) & 0x7],
157 r500_fs_swiz[(inst >> 8) & 0x7],
158 (inst >> 11) & 0x3, (inst >> 13) & 0x3,
159 r500_fs_swiz[(inst >> 15) & 0x7],
160 r500_fs_swiz[(inst >> 18) & 0x7],
161 r500_fs_swiz[(inst >> 21) & 0x7],
162 (inst >> 24) & 0x3);
163
164 inst = fs->instructions[i].inst4;
165 debug_printf(" 4: ALPHA_INST 0x%08x:", inst);
166 debug_printf("%s dest:%d%s alp_A_src:%d %s %d "
167 "alp_B_src:%d %s %d w:%d\n",
168 r500_fs_op_alpha[inst & 0xf], (inst >> 4) & 0x7f,
169 inst & (1<<11) ? "(rel)":"", (inst >> 12) & 0x3,
170 r500_fs_swiz[(inst >> 14) & 0x7], (inst >> 17) & 0x3,
171 (inst >> 19) & 0x3, r500_fs_swiz[(inst >> 21) & 0x7],
172 (inst >> 24) & 0x3, (inst >> 31) & 0x1);
173
174 inst = fs->instructions[i].inst5;
175 debug_printf(" 5: RGBA_INST 0x%08x:", inst);
176 debug_printf("%s dest:%d%s rgb_C_src:%d %s/%s/%s %d "
177 "alp_C_src:%d %s %d\n",
178 r500_fs_op_rgb[inst & 0xf], (inst >> 4) & 0x7f,
179 inst & (1 << 11) ? "(rel)":"", (inst >> 12) & 0x3,
180 r500_fs_swiz[(inst >> 14) & 0x7],
181 r500_fs_swiz[(inst >> 17) & 0x7],
182 r500_fs_swiz[(inst >> 20) & 0x7],
183 (inst >> 23) & 0x3, (inst >> 25) & 0x3,
184 r500_fs_swiz[(inst >> 27) & 0x7], (inst >> 30) & 0x3);
185 break;
186 case R500_INST_TYPE_FC:
187 /* XXX don't even bother yet */
188 break;
189 case R500_INST_TYPE_TEX:
190 inst = fs->instructions[i].inst1;
191 debug_printf(" 1: TEX_INST 0x%08x: id: %d "
192 "op:%s, %s, %s %s\n",
193 inst, (inst >> 16) & 0xf,
194 r500_fs_tex[(inst >> 22) & 0x7],
195 (inst & (1 << 25)) ? "ACQ" : "",
196 (inst & (1 << 26)) ? "IGNUNC" : "",
197 (inst & (1 << 27)) ? "UNSCALED" : "SCALED");
198
199 inst = fs->instructions[i].inst2;
200 debug_printf(" 2: TEX_ADDR 0x%08x: "
201 "src: %d%s %s/%s/%s/%s dst: %d%s %s/%s/%s/%s\n",
202 inst, inst & 0x7f, inst & (1 << 7) ? "(rel)" : "",
203 r500_fs_swiz[(inst >> 8) & 0x3],
204 r500_fs_swiz[(inst >> 10) & 0x3],
205 r500_fs_swiz[(inst >> 12) & 0x3],
206 r500_fs_swiz[(inst >> 14) & 0x3],
207 (inst >> 16) & 0x7f, inst & (1 << 23) ? "(rel)" : "",
208 r500_fs_swiz[(inst >> 24) & 0x3],
209 r500_fs_swiz[(inst >> 26) & 0x3],
210 r500_fs_swiz[(inst >> 28) & 0x3],
211 r500_fs_swiz[(inst >> 30) & 0x3]);
212
213 inst = fs->instructions[i].inst3;
214 debug_printf(" 3: TEX_DXDY 0x%08x\n", inst);
215 break;
216 }
217 }
218 }