v3d: Handle the line width intrinsics
[mesa.git] / src / broadcom / compiler / vir_dump.c
1 /*
2 * Copyright © 2016-2017 Broadcom
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "broadcom/common/v3d_device_info.h"
25 #include "v3d_compiler.h"
26
27 /* Prints a human-readable description of the uniform reference. */
28 void
29 vir_dump_uniform(enum quniform_contents contents,
30 uint32_t data)
31 {
32 static const char *quniform_names[] = {
33 [QUNIFORM_ALPHA_REF] = "alpha_ref",
34 [QUNIFORM_LINE_WIDTH] = "line_width",
35 [QUNIFORM_AA_LINE_WIDTH] = "aa_line_width",
36 [QUNIFORM_VIEWPORT_X_SCALE] = "vp_x_scale",
37 [QUNIFORM_VIEWPORT_Y_SCALE] = "vp_y_scale",
38 [QUNIFORM_VIEWPORT_Z_OFFSET] = "vp_z_offset",
39 [QUNIFORM_VIEWPORT_Z_SCALE] = "vp_z_scale",
40 [QUNIFORM_SHARED_OFFSET] = "shared_offset",
41 };
42
43 switch (contents) {
44 case QUNIFORM_CONSTANT:
45 fprintf(stderr, "0x%08x / %f", data, uif(data));
46 break;
47
48 case QUNIFORM_UNIFORM:
49 fprintf(stderr, "push[%d]", data);
50 break;
51
52 case QUNIFORM_TEXTURE_CONFIG_P1:
53 fprintf(stderr, "tex[%d].p1", data);
54 break;
55
56 case QUNIFORM_TMU_CONFIG_P0:
57 fprintf(stderr, "tex[%d].p0 | 0x%x",
58 v3d_unit_data_get_unit(data),
59 v3d_unit_data_get_offset(data));
60 break;
61
62 case QUNIFORM_TMU_CONFIG_P1:
63 fprintf(stderr, "tex[%d].p1 | 0x%x",
64 v3d_unit_data_get_unit(data),
65 v3d_unit_data_get_offset(data));
66 break;
67
68 case QUNIFORM_IMAGE_TMU_CONFIG_P0:
69 fprintf(stderr, "img[%d].p0 | 0x%x",
70 v3d_unit_data_get_unit(data),
71 v3d_unit_data_get_offset(data));
72 break;
73
74 case QUNIFORM_TEXTURE_WIDTH:
75 fprintf(stderr, "tex[%d].width", data);
76 break;
77 case QUNIFORM_TEXTURE_HEIGHT:
78 fprintf(stderr, "tex[%d].height", data);
79 break;
80 case QUNIFORM_TEXTURE_DEPTH:
81 fprintf(stderr, "tex[%d].depth", data);
82 break;
83 case QUNIFORM_TEXTURE_ARRAY_SIZE:
84 fprintf(stderr, "tex[%d].array_size", data);
85 break;
86 case QUNIFORM_TEXTURE_LEVELS:
87 fprintf(stderr, "tex[%d].levels", data);
88 break;
89
90 case QUNIFORM_IMAGE_WIDTH:
91 fprintf(stderr, "img[%d].width", data);
92 break;
93 case QUNIFORM_IMAGE_HEIGHT:
94 fprintf(stderr, "img[%d].height", data);
95 break;
96 case QUNIFORM_IMAGE_DEPTH:
97 fprintf(stderr, "img[%d].depth", data);
98 break;
99 case QUNIFORM_IMAGE_ARRAY_SIZE:
100 fprintf(stderr, "img[%d].array_size", data);
101 break;
102
103 case QUNIFORM_SPILL_OFFSET:
104 fprintf(stderr, "spill_offset");
105 break;
106
107 case QUNIFORM_SPILL_SIZE_PER_THREAD:
108 fprintf(stderr, "spill_size_per_thread");
109 break;
110
111 case QUNIFORM_UBO_ADDR:
112 fprintf(stderr, "ubo[%d]+0x%x",
113 v3d_unit_data_get_unit(data),
114 v3d_unit_data_get_offset(data));
115 break;
116
117 case QUNIFORM_SSBO_OFFSET:
118 fprintf(stderr, "ssbo[%d]", data);
119 break;
120
121 case QUNIFORM_GET_BUFFER_SIZE:
122 fprintf(stderr, "ssbo_size[%d]", data);
123 break;
124
125 case QUNIFORM_NUM_WORK_GROUPS:
126 fprintf(stderr, "num_wg.%c", data < 3 ? "xyz"[data] : '?');
127 break;
128
129 default:
130 if (quniform_contents_is_texture_p0(contents)) {
131 fprintf(stderr, "tex[%d].p0: 0x%08x",
132 contents - QUNIFORM_TEXTURE_CONFIG_P0_0,
133 data);
134 } else if (contents < ARRAY_SIZE(quniform_names) &&
135 quniform_names[contents]) {
136 fprintf(stderr, "%s",
137 quniform_names[contents]);
138 } else {
139 fprintf(stderr, "%d / 0x%08x", contents, data);
140 }
141 }
142 }
143
144 static void
145 vir_print_reg(struct v3d_compile *c, const struct qinst *inst,
146 struct qreg reg)
147 {
148 switch (reg.file) {
149
150 case QFILE_NULL:
151 fprintf(stderr, "null");
152 break;
153
154 case QFILE_LOAD_IMM:
155 fprintf(stderr, "0x%08x (%f)", reg.index, uif(reg.index));
156 break;
157
158 case QFILE_REG:
159 fprintf(stderr, "rf%d", reg.index);
160 break;
161
162 case QFILE_MAGIC:
163 fprintf(stderr, "%s", v3d_qpu_magic_waddr_name(reg.index));
164 break;
165
166 case QFILE_SMALL_IMM: {
167 uint32_t unpacked;
168 bool ok = v3d_qpu_small_imm_unpack(c->devinfo,
169 inst->qpu.raddr_b,
170 &unpacked);
171 assert(ok); (void) ok;
172
173 if ((int)inst->qpu.raddr_b >= -16 &&
174 (int)inst->qpu.raddr_b <= 15)
175 fprintf(stderr, "%d", unpacked);
176 else
177 fprintf(stderr, "%f", uif(unpacked));
178 break;
179 }
180
181 case QFILE_VPM:
182 fprintf(stderr, "vpm%d.%d",
183 reg.index / 4, reg.index % 4);
184 break;
185
186 case QFILE_TEMP:
187 fprintf(stderr, "t%d", reg.index);
188 break;
189 }
190 }
191
192 static void
193 vir_dump_sig_addr(const struct v3d_device_info *devinfo,
194 const struct v3d_qpu_instr *instr)
195 {
196 if (devinfo->ver < 41)
197 return;
198
199 if (!instr->sig_magic)
200 fprintf(stderr, ".rf%d", instr->sig_addr);
201 else {
202 const char *name = v3d_qpu_magic_waddr_name(instr->sig_addr);
203 if (name)
204 fprintf(stderr, ".%s", name);
205 else
206 fprintf(stderr, ".UNKNOWN%d", instr->sig_addr);
207 }
208 }
209
210 static void
211 vir_dump_sig(struct v3d_compile *c, struct qinst *inst)
212 {
213 struct v3d_qpu_sig *sig = &inst->qpu.sig;
214
215 if (sig->thrsw)
216 fprintf(stderr, "; thrsw");
217 if (sig->ldvary) {
218 fprintf(stderr, "; ldvary");
219 vir_dump_sig_addr(c->devinfo, &inst->qpu);
220 }
221 if (sig->ldvpm)
222 fprintf(stderr, "; ldvpm");
223 if (sig->ldtmu) {
224 fprintf(stderr, "; ldtmu");
225 vir_dump_sig_addr(c->devinfo, &inst->qpu);
226 }
227 if (sig->ldtlb) {
228 fprintf(stderr, "; ldtlb");
229 vir_dump_sig_addr(c->devinfo, &inst->qpu);
230 }
231 if (sig->ldtlbu) {
232 fprintf(stderr, "; ldtlbu");
233 vir_dump_sig_addr(c->devinfo, &inst->qpu);
234 }
235 if (sig->ldunif)
236 fprintf(stderr, "; ldunif");
237 if (sig->ldunifrf) {
238 fprintf(stderr, "; ldunifrf");
239 vir_dump_sig_addr(c->devinfo, &inst->qpu);
240 }
241 if (sig->ldunifa)
242 fprintf(stderr, "; ldunifa");
243 if (sig->ldunifarf) {
244 fprintf(stderr, "; ldunifarf");
245 vir_dump_sig_addr(c->devinfo, &inst->qpu);
246 }
247 if (sig->wrtmuc)
248 fprintf(stderr, "; wrtmuc");
249 }
250
251 static void
252 vir_dump_alu(struct v3d_compile *c, struct qinst *inst)
253 {
254 struct v3d_qpu_instr *instr = &inst->qpu;
255 int nsrc = vir_get_nsrc(inst);
256 enum v3d_qpu_input_unpack unpack[2];
257
258 if (inst->qpu.alu.add.op != V3D_QPU_A_NOP) {
259 fprintf(stderr, "%s", v3d_qpu_add_op_name(instr->alu.add.op));
260 fprintf(stderr, "%s", v3d_qpu_cond_name(instr->flags.ac));
261 fprintf(stderr, "%s", v3d_qpu_pf_name(instr->flags.apf));
262 fprintf(stderr, "%s", v3d_qpu_uf_name(instr->flags.auf));
263 fprintf(stderr, " ");
264
265 vir_print_reg(c, inst, inst->dst);
266 fprintf(stderr, "%s", v3d_qpu_pack_name(instr->alu.add.output_pack));
267
268 unpack[0] = instr->alu.add.a_unpack;
269 unpack[1] = instr->alu.add.b_unpack;
270 } else {
271 fprintf(stderr, "%s", v3d_qpu_mul_op_name(instr->alu.mul.op));
272 fprintf(stderr, "%s", v3d_qpu_cond_name(instr->flags.mc));
273 fprintf(stderr, "%s", v3d_qpu_pf_name(instr->flags.mpf));
274 fprintf(stderr, "%s", v3d_qpu_uf_name(instr->flags.muf));
275 fprintf(stderr, " ");
276
277 vir_print_reg(c, inst, inst->dst);
278 fprintf(stderr, "%s", v3d_qpu_pack_name(instr->alu.mul.output_pack));
279
280 unpack[0] = instr->alu.mul.a_unpack;
281 unpack[1] = instr->alu.mul.b_unpack;
282 }
283
284 for (int i = 0; i < nsrc; i++) {
285 fprintf(stderr, ", ");
286 vir_print_reg(c, inst, inst->src[i]);
287 fprintf(stderr, "%s", v3d_qpu_unpack_name(unpack[i]));
288 }
289
290 vir_dump_sig(c, inst);
291 }
292
293 void
294 vir_dump_inst(struct v3d_compile *c, struct qinst *inst)
295 {
296 struct v3d_qpu_instr *instr = &inst->qpu;
297
298 switch (inst->qpu.type) {
299 case V3D_QPU_INSTR_TYPE_ALU:
300 vir_dump_alu(c, inst);
301 break;
302 case V3D_QPU_INSTR_TYPE_BRANCH:
303 fprintf(stderr, "b");
304 if (instr->branch.ub)
305 fprintf(stderr, "u");
306
307 fprintf(stderr, "%s",
308 v3d_qpu_branch_cond_name(instr->branch.cond));
309 fprintf(stderr, "%s", v3d_qpu_msfign_name(instr->branch.msfign));
310
311 switch (instr->branch.bdi) {
312 case V3D_QPU_BRANCH_DEST_ABS:
313 fprintf(stderr, " zero_addr+0x%08x", instr->branch.offset);
314 break;
315
316 case V3D_QPU_BRANCH_DEST_REL:
317 fprintf(stderr, " %d", instr->branch.offset);
318 break;
319
320 case V3D_QPU_BRANCH_DEST_LINK_REG:
321 fprintf(stderr, " lri");
322 break;
323
324 case V3D_QPU_BRANCH_DEST_REGFILE:
325 fprintf(stderr, " rf%d", instr->branch.raddr_a);
326 break;
327 }
328
329 if (instr->branch.ub) {
330 switch (instr->branch.bdu) {
331 case V3D_QPU_BRANCH_DEST_ABS:
332 fprintf(stderr, ", a:unif");
333 break;
334
335 case V3D_QPU_BRANCH_DEST_REL:
336 fprintf(stderr, ", r:unif");
337 break;
338
339 case V3D_QPU_BRANCH_DEST_LINK_REG:
340 fprintf(stderr, ", lri");
341 break;
342
343 case V3D_QPU_BRANCH_DEST_REGFILE:
344 fprintf(stderr, ", rf%d", instr->branch.raddr_a);
345 break;
346 }
347 }
348 break;
349 }
350
351 if (vir_has_uniform(inst)) {
352 fprintf(stderr, " (");
353 vir_dump_uniform(c->uniform_contents[inst->uniform],
354 c->uniform_data[inst->uniform]);
355 fprintf(stderr, ")");
356 }
357 }
358
359 void
360 vir_dump(struct v3d_compile *c)
361 {
362 int ip = 0;
363 int pressure = 0;
364
365 vir_for_each_block(block, c) {
366 fprintf(stderr, "BLOCK %d:\n", block->index);
367 vir_for_each_inst(inst, block) {
368 if (c->live_intervals_valid) {
369 for (int i = 0; i < c->num_temps; i++) {
370 if (c->temp_start[i] == ip)
371 pressure++;
372 }
373
374 fprintf(stderr, "P%4d ", pressure);
375
376 bool first = true;
377
378 for (int i = 0; i < c->num_temps; i++) {
379 if (c->temp_start[i] != ip)
380 continue;
381
382 if (first) {
383 first = false;
384 } else {
385 fprintf(stderr, ", ");
386 }
387 if (BITSET_TEST(c->spillable, i))
388 fprintf(stderr, "S%4d", i);
389 else
390 fprintf(stderr, "U%4d", i);
391 }
392
393 if (first)
394 fprintf(stderr, " ");
395 else
396 fprintf(stderr, " ");
397 }
398
399 if (c->live_intervals_valid) {
400 bool first = true;
401
402 for (int i = 0; i < c->num_temps; i++) {
403 if (c->temp_end[i] != ip)
404 continue;
405
406 if (first) {
407 first = false;
408 } else {
409 fprintf(stderr, ", ");
410 }
411 fprintf(stderr, "E%4d", i);
412 pressure--;
413 }
414
415 if (first)
416 fprintf(stderr, " ");
417 else
418 fprintf(stderr, " ");
419 }
420
421 vir_dump_inst(c, inst);
422 fprintf(stderr, "\n");
423 ip++;
424 }
425 if (block->successors[1]) {
426 fprintf(stderr, "-> BLOCK %d, %d\n",
427 block->successors[0]->index,
428 block->successors[1]->index);
429 } else if (block->successors[0]) {
430 fprintf(stderr, "-> BLOCK %d\n",
431 block->successors[0]->index);
432 }
433 }
434 }