Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / panfrost / bifrost / bi_print.c
1 /*
2 * Copyright (C) 2019 Connor Abbott <cwabbott0@gmail.com>
3 * Copyright (C) 2019 Lyude Paul <thatslyude@gmail.com>
4 * Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
5 * Copyright (C) 2019-2020 Collabora, Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
27 #include "bi_print.h"
28 #include "bi_print_common.h"
29
30 const char *
31 bi_class_name(enum bi_class cl)
32 {
33 switch (cl) {
34 case BI_ADD: return "add";
35 case BI_ATEST: return "atest";
36 case BI_BRANCH: return "branch";
37 case BI_CMP: return "cmp";
38 case BI_BLEND: return "blend";
39 case BI_BITWISE: return "bitwise";
40 case BI_COMBINE: return "combine";
41 case BI_CONVERT: return "convert";
42 case BI_CSEL: return "csel";
43 case BI_DISCARD: return "discard";
44 case BI_FMA: return "fma";
45 case BI_FMOV: return "fmov";
46 case BI_FREXP: return "frexp";
47 case BI_IMATH: return "imath";
48 case BI_LOAD: return "load";
49 case BI_LOAD_UNIFORM: return "load_uniform";
50 case BI_LOAD_ATTR: return "load_attr";
51 case BI_LOAD_VAR: return "load_var";
52 case BI_LOAD_VAR_ADDRESS: return "load_var_address";
53 case BI_MINMAX: return "minmax";
54 case BI_MOV: return "mov";
55 case BI_SELECT: return "select";
56 case BI_STORE: return "store";
57 case BI_STORE_VAR: return "store_var";
58 case BI_SPECIAL: return "special";
59 case BI_TABLE: return "table";
60 case BI_TEX: return "tex";
61 case BI_ROUND: return "round";
62 case BI_IMUL: return "imul";
63 default: return "unknown_class";
64 }
65 }
66
67 static bool
68 bi_print_dest_index(FILE *fp, bi_instruction *ins, unsigned index)
69 {
70 if (!index)
71 fprintf(fp, "_");
72 else if (index & BIR_INDEX_REGISTER)
73 fprintf(fp, "br%u", index & ~BIR_INDEX_REGISTER);
74 else if (index & PAN_IS_REG)
75 fprintf(fp, "r%u", index >> 1);
76 else if (!(index & BIR_SPECIAL))
77 fprintf(fp, "%u", (index >> 1) - 1);
78 else
79 return false;
80
81 return true;
82 }
83
84 static void
85 bi_print_index(FILE *fp, bi_instruction *ins, unsigned index, unsigned s)
86 {
87 if (bi_print_dest_index(fp, ins, index))
88 return;
89
90 if (index & BIR_INDEX_UNIFORM)
91 fprintf(fp, "u%u", index & ~BIR_INDEX_UNIFORM);
92 else if (index & BIR_INDEX_CONSTANT)
93 fprintf(fp, "#0x%" PRIx64, bi_get_immediate(ins, s));
94 else if (index & BIR_INDEX_ZERO)
95 fprintf(fp, "#0");
96 else
97 fprintf(fp, "#err");
98 }
99
100 static void
101 bi_print_src(FILE *fp, bi_instruction *ins, unsigned s)
102 {
103 unsigned src = ins->src[s];
104 bool mods = bi_has_source_mods(ins);
105 bool abs = ins->src_abs[s] && mods;
106 bool neg = ins->src_neg[s] && mods;
107
108 if (neg)
109 fprintf(fp, "-");
110
111 if (abs)
112 fprintf(fp, "abs(");
113
114 if (ins->type == BI_BITWISE && ins->bitwise.src_invert[s])
115 fprintf(fp, "~");
116
117 bi_print_index(fp, ins, src, s);
118
119 if (abs)
120 fprintf(fp, ")");
121 }
122
123 static void
124 bi_print_swizzle(bi_instruction *ins, unsigned src, FILE *fp)
125 {
126 fprintf(fp, ".");
127
128 for (unsigned u = 0; u < bi_get_component_count(ins, src); ++u) {
129 assert(ins->swizzle[src][u] < 4);
130 fputc("xyzw"[ins->swizzle[src][u]], fp);
131 }
132 }
133
134 static const char *
135 bi_bitwise_op_name(enum bi_bitwise_op op)
136 {
137 switch (op) {
138 case BI_BITWISE_AND: return "and";
139 case BI_BITWISE_OR: return "or";
140 case BI_BITWISE_XOR: return "xor";
141 default: return "invalid";
142 }
143 }
144
145 static const char *
146 bi_imath_op_name(enum bi_imath_op op)
147 {
148 switch (op) {
149 case BI_IMATH_ADD: return "iadd";
150 case BI_IMATH_SUB: return "isub";
151 default: return "invalid";
152 }
153 }
154
155 const char *
156 bi_table_op_name(enum bi_table_op op)
157 {
158 switch (op) {
159 case BI_TABLE_LOG2_U_OVER_U_1_LOW: return "log2.help";
160 default: return "invalid";
161 }
162 }
163
164 const char *
165 bi_special_op_name(enum bi_special_op op)
166 {
167 switch (op) {
168 case BI_SPECIAL_FRCP: return "frcp";
169 case BI_SPECIAL_FRSQ: return "frsq";
170 case BI_SPECIAL_EXP2_LOW: return "exp2_low";
171 default: return "invalid";
172 }
173 }
174
175 const char *
176 bi_reduce_op_name(enum bi_reduce_op op)
177 {
178 switch (op) {
179 case BI_REDUCE_ADD_FREXPM: return "add_frexpm";
180 default: return "invalid";
181 }
182 }
183
184 const char *
185 bi_frexp_op_name(enum bi_frexp_op op)
186 {
187 switch (op) {
188 case BI_FREXPE_LOG: return "frexpe_log";
189 default: return "invalid";
190 }
191 }
192
193 const char *
194 bi_tex_op_name(enum bi_tex_op op)
195 {
196 switch (op) {
197 case BI_TEX_NORMAL: return "normal";
198 case BI_TEX_COMPACT: return "compact";
199 case BI_TEX_DUAL: return "dual";
200 default: return "invalid";
201 }
202 }
203
204 static void
205 bi_print_load_vary(struct bi_load_vary *load, FILE *fp)
206 {
207 fprintf(fp, "%s", bi_interp_mode_name(load->interp_mode));
208
209 if (load->reuse)
210 fprintf(fp, ".reuse");
211
212 if (load->flat)
213 fprintf(fp, ".flat");
214 }
215
216 const char *
217 bi_cond_name(enum bi_cond cond)
218 {
219 switch (cond) {
220 case BI_COND_ALWAYS: return "always";
221 case BI_COND_LT: return "lt";
222 case BI_COND_LE: return "le";
223 case BI_COND_GE: return "ge";
224 case BI_COND_GT: return "gt";
225 case BI_COND_EQ: return "eq";
226 case BI_COND_NE: return "ne";
227 default: return "invalid";
228 }
229 }
230
231 static void
232 bi_print_texture(struct bi_texture *tex, FILE *fp)
233 {
234 fprintf(fp, " - texture %u, sampler %u",
235 tex->texture_index, tex->sampler_index);
236 }
237
238 void
239 bi_print_instruction(bi_instruction *ins, FILE *fp)
240 {
241 if (ins->type == BI_MINMAX)
242 fprintf(fp, "%s", ins->op.minmax == BI_MINMAX_MIN ? "min" : "max");
243 else if (ins->type == BI_BITWISE)
244 fprintf(fp, "%s", bi_bitwise_op_name(ins->op.bitwise));
245 else if (ins->type == BI_IMATH)
246 fprintf(fp, "%s", bi_imath_op_name(ins->op.imath));
247 else if (ins->type == BI_SPECIAL)
248 fprintf(fp, "%s", bi_special_op_name(ins->op.special));
249 else if (ins->type == BI_TABLE)
250 fprintf(fp, "%s", bi_table_op_name(ins->op.table));
251 else if (ins->type == BI_REDUCE_FMA)
252 fprintf(fp, "%s", bi_reduce_op_name(ins->op.reduce));
253 else if (ins->type == BI_FREXP)
254 fprintf(fp, "%s", bi_frexp_op_name(ins->op.frexp));
255 else
256 fprintf(fp, "%s", bi_class_name(ins->type));
257
258 if ((ins->type == BI_ADD || ins->type == BI_FMA) && ins->op.mscale)
259 fprintf(fp, ".mscale");
260
261 if (ins->type == BI_MINMAX)
262 fprintf(fp, "%s", bi_minmax_mode_name(ins->minmax));
263 else if (ins->type == BI_LOAD_VAR)
264 bi_print_load_vary(&ins->load_vary, fp);
265 else if (ins->type == BI_BLEND)
266 fprintf(fp, ".loc%u", ins->blend_location);
267 else if (ins->type == BI_TEX) {
268 fprintf(fp, ".%s", bi_tex_op_name(ins->op.texture));
269 } else if (ins->type == BI_BITWISE)
270 fprintf(fp, ".%cshift", ins->bitwise.rshift ? 'r' : 'l');
271
272 if (bi_class_props[ins->type] & BI_CONDITIONAL)
273 fprintf(fp, ".%s", bi_cond_name(ins->cond));
274
275 if (ins->vector_channels)
276 fprintf(fp, ".v%u", ins->vector_channels);
277
278 if (ins->dest)
279 pan_print_alu_type(ins->dest_type, fp);
280
281 if (bi_has_outmod(ins))
282 fprintf(fp, "%s", bi_output_mod_name(ins->outmod));
283
284 if (bi_class_props[ins->type] & BI_ROUNDMODE)
285 fprintf(fp, "%s", bi_round_mode_name(ins->roundmode));
286
287 fprintf(fp, " ");
288 ASSERTED bool succ = bi_print_dest_index(fp, ins, ins->dest);
289 assert(succ);
290
291 if (ins->dest_offset)
292 fprintf(fp, "+%u", ins->dest_offset);
293
294 fprintf(fp, ", ");
295
296 bi_foreach_src(ins, s) {
297 bi_print_src(fp, ins, s);
298
299 if (ins->src[s] && !(ins->src[s] & (BIR_INDEX_CONSTANT | BIR_INDEX_ZERO))) {
300 pan_print_alu_type(ins->src_types[s], fp);
301 bi_print_swizzle(ins, s, fp);
302 }
303
304 if (s < BIR_SRC_COUNT)
305 fprintf(fp, ", ");
306 }
307
308 if (ins->type == BI_BRANCH) {
309 if (ins->branch_target) {
310 fprintf(fp, "-> block%u", ins->branch_target->base.name);
311 } else {
312 fprintf(fp, "-> void");
313 }
314 } else if (ins->type == BI_TEX) {
315 bi_print_texture(&ins->texture, fp);
316 }
317
318 fprintf(fp, "\n");
319 }
320
321 void
322 bi_print_ports(bi_registers *regs, FILE *fp)
323 {
324 for (unsigned i = 0; i < 2; ++i) {
325 if (regs->enabled[i])
326 fprintf(fp, "port %u: %u\n", i, regs->port[i]);
327 }
328
329 if (regs->write_fma || regs->write_add) {
330 fprintf(fp, "port 2 (%s): %u\n",
331 regs->write_add ? "ADD" : "FMA",
332 regs->port[2]);
333 }
334
335 if ((regs->write_fma && regs->write_add) || regs->read_port3) {
336 fprintf(fp, "port 3 (%s): %u\n",
337 regs->read_port3 ? "read" : "FMA",
338 regs->port[3]);
339 }
340 }
341
342 void
343 bi_print_bundle(bi_bundle *bundle, FILE *fp)
344 {
345 bi_instruction *ins[2] = { bundle->fma, bundle->add };
346
347 for (unsigned i = 0; i < 2; ++i) {
348 if (ins[i])
349 bi_print_instruction(ins[i], fp);
350 else
351 fprintf(fp, "nop\n");
352 }
353 }
354
355 void
356 bi_print_clause(bi_clause *clause, FILE *fp)
357 {
358 fprintf(fp, "\tid(%u)", clause->scoreboard_id);
359
360 if (clause->dependencies) {
361 fprintf(fp, ", wait(");
362
363 for (unsigned i = 0; i < 8; ++i) {
364 if (clause->dependencies & (1 << i))
365 fprintf(fp, "%u ", i);
366 }
367
368 fprintf(fp, ")");
369 }
370
371 if (!clause->back_to_back)
372 fprintf(fp, " nbb %s", clause->branch_conditional ? "branch-cond" : "branch-uncond");
373
374 if (clause->data_register_write_barrier)
375 fprintf(fp, " drwb");
376
377 fprintf(fp, "\n");
378
379 for (unsigned i = 0; i < clause->bundle_count; ++i)
380 bi_print_bundle(&clause->bundles[i], fp);
381
382 if (clause->constant_count) {
383 for (unsigned i = 0; i < clause->constant_count; ++i)
384 fprintf(fp, "%" PRIx64 " ", clause->constants[i]);
385
386 if (clause->branch_constant)
387 fprintf(fp, "*");
388
389 fprintf(fp, "\n");
390 }
391 }
392
393 void
394 bi_print_block(bi_block *block, FILE *fp)
395 {
396 fprintf(fp, "block%u {\n", block->base.name);
397
398 if (block->scheduled) {
399 bi_foreach_clause_in_block(block, clause)
400 bi_print_clause(clause, fp);
401 } else {
402 bi_foreach_instr_in_block(block, ins)
403 bi_print_instruction(ins, fp);
404 }
405
406 fprintf(fp, "}");
407
408 if (block->base.successors[0]) {
409 fprintf(fp, " -> ");
410
411 pan_foreach_successor((&block->base), succ)
412 fprintf(fp, "block%u ", succ->name);
413 }
414
415 if (block->base.predecessors->entries) {
416 fprintf(fp, " from");
417
418 bi_foreach_predecessor(block, pred)
419 fprintf(fp, " block%u", pred->base.name);
420 }
421
422 fprintf(fp, "\n\n");
423 }
424
425 void
426 bi_print_shader(bi_context *ctx, FILE *fp)
427 {
428 bi_foreach_block(ctx, block)
429 bi_print_block((bi_block *) block, fp);
430 }