| 1 |
/* |
| 2 |
* Copyright (C) 2019 Connor Abbott <[email protected]> |
| 3 |
* Copyright (C) 2019 Lyude Paul <[email protected]> |
| 4 |
* Copyright (C) 2019 Ryan Houdek <[email protected]> |
| 5 |
* Copyright (C) 2019-2020 Collabora, Ltd. |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "bi_print_common.h" |
| 10 |
#include "compiler.h" |
| 11 |
|
| 12 |
static const char * |
| 13 |
bi_reg_op_name(enum bifrost_reg_op op) |
| 14 |
{ |
| 15 |
switch (op) { |
| 16 |
case BIFROST_OP_IDLE: |
| 17 |
return "idle"; |
| 18 |
case BIFROST_OP_READ: |
| 19 |
return "read"; |
| 20 |
case BIFROST_OP_WRITE: |
| 21 |
return "write"; |
| 22 |
case BIFROST_OP_WRITE_LO: |
| 23 |
return "write lo"; |
| 24 |
case BIFROST_OP_WRITE_HI: |
| 25 |
return "write hi"; |
| 26 |
default: |
| 27 |
return "invalid"; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
static void |
| 32 |
print_debug_info(const struct nir_instr_debug_info *di, FILE *w) |
| 33 |
{ |
| 34 |
fprintf(w, "0x%08x", di->spirv_offset); |
| 35 |
|
| 36 |
if (di->filename) |
| 37 |
fprintf(w, " %s:%u:%u", di->filename, di->line, di->column); |
| 38 |
|
| 39 |
if (di->nir_line) |
| 40 |
fprintf(w, " nir:%u", di->nir_line); |
| 41 |
} |
| 42 |
|
| 43 |
void |
| 44 |
bi_print_instr(const bi_instr *I, FILE *w) |
| 45 |
{ |
| 46 |
const struct nir_instr_debug_info *debug_info = I->debug_info; |
| 47 |
if (debug_info) { |
| 48 |
fprintf(w, " // "); |
| 49 |
print_debug_info(debug_info, w); |
| 50 |
fprintf(w, "\n"); |
| 51 |
} |
| 52 |
|
| 53 |
bi_print_instr_impl(I, w); |
| 54 |
} |
| 55 |
|
| 56 |
void |
| 57 |
bi_print_slots(bi_registers *regs, FILE *fp) |
| 58 |
{ |
| 59 |
for (unsigned i = 0; i < 2; ++i) { |
| 60 |
if (regs->enabled[i]) |
| 61 |
fprintf(fp, "slot %u: %u\n", i, regs->slot[i]); |
| 62 |
} |
| 63 |
|
| 64 |
if (regs->slot23.slot2) { |
| 65 |
fprintf(fp, "slot 2 (%s%s): %u\n", bi_reg_op_name(regs->slot23.slot2), |
| 66 |
regs->slot23.slot2 >= BIFROST_OP_WRITE ? " FMA" : "", |
| 67 |
regs->slot[2]); |
| 68 |
} |
| 69 |
|
| 70 |
if (regs->slot23.slot3) { |
| 71 |
fprintf(fp, "slot 3 (%s %s): %u\n", bi_reg_op_name(regs->slot23.slot3), |
| 72 |
regs->slot23.slot3_fma ? "FMA" : "ADD", regs->slot[3]); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
struct printer { |
| 77 |
FILE *w; |
| 78 |
|
| 79 |
struct nir_instr_debug_info last_debug_info; |
| 80 |
}; |
| 81 |
|
| 82 |
static void |
| 83 |
print_instr(const bi_instr *I, struct printer *p) |
| 84 |
{ |
| 85 |
const struct nir_instr_debug_info *debug_info = I->debug_info; |
| 86 |
if (debug_info) { |
| 87 |
bool changed = p->last_debug_info.spirv_offset != debug_info->spirv_offset; |
| 88 |
changed |= p->last_debug_info.nir_line != debug_info->nir_line; |
| 89 |
|
| 90 |
if (changed && debug_info->spirv_offset) { |
| 91 |
fprintf(p->w, " // "); |
| 92 |
print_debug_info(debug_info, p->w); |
| 93 |
fprintf(p->w, "\n"); |
| 94 |
} |
| 95 |
|
| 96 |
p->last_debug_info = *debug_info; |
| 97 |
} |
| 98 |
|
| 99 |
bi_print_instr_impl(I, p->w); |
| 100 |
} |
| 101 |
|
| 102 |
static void |
| 103 |
print_tuple(bi_tuple *tuple, struct printer *p) |
| 104 |
{ |
| 105 |
bi_instr *ins[2] = {tuple->fma, tuple->add}; |
| 106 |
|
| 107 |
for (unsigned i = 0; i < 2; ++i) { |
| 108 |
fprintf(p->w, (i == 0) ? "\t* " : "\t+ "); |
| 109 |
|
| 110 |
if (ins[i]) |
| 111 |
print_instr(ins[i], p); |
| 112 |
else |
| 113 |
fprintf(p->w, "NOP\n"); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
static void |
| 118 |
print_clause(bi_clause *clause, struct printer *p) |
| 119 |
{ |
| 120 |
fprintf(p->w, "id(%u)", clause->scoreboard_id); |
| 121 |
|
| 122 |
if (clause->dependencies) { |
| 123 |
fprintf(p->w, " wait("); |
| 124 |
|
| 125 |
for (unsigned i = 0; i < 8; ++i) { |
| 126 |
if (clause->dependencies & (1 << i)) |
| 127 |
fprintf(p->w, "%u ", i); |
| 128 |
} |
| 129 |
|
| 130 |
fprintf(p->w, ")"); |
| 131 |
} |
| 132 |
|
| 133 |
fprintf(p->w, " %s", bi_flow_control_name(clause->flow_control)); |
| 134 |
|
| 135 |
if (!clause->next_clause_prefetch) |
| 136 |
fprintf(p->w, " no_prefetch"); |
| 137 |
|
| 138 |
if (clause->staging_barrier) |
| 139 |
fprintf(p->w, " osrb"); |
| 140 |
|
| 141 |
if (clause->td) |
| 142 |
fprintf(p->w, " td"); |
| 143 |
|
| 144 |
if (clause->pcrel_idx != ~0) |
| 145 |
fprintf(p->w, " pcrel(%u)", clause->pcrel_idx); |
| 146 |
|
| 147 |
fprintf(p->w, "\n"); |
| 148 |
|
| 149 |
for (unsigned i = 0; i < clause->tuple_count; ++i) |
| 150 |
print_tuple(&clause->tuples[i], p); |
| 151 |
|
| 152 |
if (clause->constant_count) { |
| 153 |
for (unsigned i = 0; i < clause->constant_count; ++i) |
| 154 |
fprintf(p->w, "%" PRIx64 " ", clause->constants[i]); |
| 155 |
|
| 156 |
if (clause->branch_constant) |
| 157 |
fprintf(p->w, "*"); |
| 158 |
|
| 159 |
fprintf(p->w, "\n"); |
| 160 |
} |
| 161 |
|
| 162 |
fprintf(p->w, "\n"); |
| 163 |
} |
| 164 |
|
| 165 |
static void |
| 166 |
print_scoreboard_line(unsigned slot, const char *name, uint64_t mask, |
| 167 |
FILE *fp) |
| 168 |
{ |
| 169 |
if (!mask) |
| 170 |
return; |
| 171 |
|
| 172 |
fprintf(fp, "slot %u %s:", slot, name); |
| 173 |
|
| 174 |
u_foreach_bit64(reg, mask) |
| 175 |
fprintf(fp, " r%" PRId64, reg); |
| 176 |
|
| 177 |
fprintf(fp, "\n"); |
| 178 |
} |
| 179 |
|
| 180 |
static void |
| 181 |
print_scoreboard(struct bi_scoreboard_state *state, FILE *fp) |
| 182 |
{ |
| 183 |
for (unsigned i = 0; i < BI_NUM_SLOTS; ++i) { |
| 184 |
print_scoreboard_line(i, "reads", state->read[i], fp); |
| 185 |
print_scoreboard_line(i, "writes", state->write[i], fp); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
static void |
| 190 |
print_block(bi_block *block, FILE *fp) |
| 191 |
{ |
| 192 |
if (block->scheduled) { |
| 193 |
print_scoreboard(&block->scoreboard_in, fp); |
| 194 |
fprintf(fp, "\n"); |
| 195 |
} |
| 196 |
|
| 197 |
fprintf(fp, "block%u {\n", block->index); |
| 198 |
|
| 199 |
struct printer printer = {.w = fp}; |
| 200 |
|
| 201 |
if (block->scheduled) { |
| 202 |
bi_foreach_clause_in_block(block, clause) |
| 203 |
print_clause(clause, &printer); |
| 204 |
} else { |
| 205 |
bi_foreach_instr_in_block(block, ins) |
| 206 |
print_instr((bi_instr *)ins, &printer); |
| 207 |
} |
| 208 |
|
| 209 |
fprintf(fp, "}"); |
| 210 |
|
| 211 |
if (block->successors[0]) { |
| 212 |
fprintf(fp, " -> "); |
| 213 |
|
| 214 |
bi_foreach_successor((block), succ) |
| 215 |
fprintf(fp, "block%u ", succ->index); |
| 216 |
} |
| 217 |
|
| 218 |
if (bi_num_predecessors(block)) { |
| 219 |
fprintf(fp, " from"); |
| 220 |
|
| 221 |
bi_foreach_predecessor(block, pred) |
| 222 |
fprintf(fp, " block%u", (*pred)->index); |
| 223 |
} |
| 224 |
|
| 225 |
if (block->scheduled) { |
| 226 |
fprintf(fp, "\n"); |
| 227 |
print_scoreboard(&block->scoreboard_out, fp); |
| 228 |
} |
| 229 |
|
| 230 |
fprintf(fp, "\n\n"); |
| 231 |
} |
| 232 |
|
| 233 |
void |
| 234 |
bi_print_shader(bi_context *ctx, FILE *fp) |
| 235 |
{ |
| 236 |
bi_foreach_block(ctx, block) |
| 237 |
print_block(block, fp); |
| 238 |
} |