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.
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:
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
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
28 #include "bi_print_common.h"
31 bi_class_name(enum bi_class 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";
68 bi_print_dest_index(FILE *fp
, bi_instruction
*ins
, unsigned index
)
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);
85 bi_print_index(FILE *fp
, bi_instruction
*ins
, unsigned index
, unsigned s
)
87 if (bi_print_dest_index(fp
, ins
, index
))
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
)
101 bi_print_src(FILE *fp
, bi_instruction
*ins
, unsigned s
)
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
;
114 if (ins
->type
== BI_BITWISE
&& ins
->bitwise
.src_invert
[s
])
117 bi_print_index(fp
, ins
, src
, s
);
124 bi_print_swizzle(bi_instruction
*ins
, unsigned src
, FILE *fp
)
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
);
135 bi_bitwise_op_name(enum bi_bitwise_op 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";
146 bi_imath_op_name(enum bi_imath_op op
)
149 case BI_IMATH_ADD
: return "iadd";
150 case BI_IMATH_SUB
: return "isub";
151 default: return "invalid";
156 bi_table_op_name(enum bi_table_op op
)
159 case BI_TABLE_LOG2_U_OVER_U_1_LOW
: return "log2.help";
160 default: return "invalid";
165 bi_special_op_name(enum bi_special_op 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";
176 bi_reduce_op_name(enum bi_reduce_op op
)
179 case BI_REDUCE_ADD_FREXPM
: return "add_frexpm";
180 default: return "invalid";
185 bi_frexp_op_name(enum bi_frexp_op op
)
188 case BI_FREXPE_LOG
: return "frexpe_log";
189 default: return "invalid";
194 bi_tex_op_name(enum bi_tex_op 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";
205 bi_print_load_vary(struct bi_load_vary
*load
, FILE *fp
)
207 fprintf(fp
, "%s", bi_interp_mode_name(load
->interp_mode
));
210 fprintf(fp
, ".reuse");
213 fprintf(fp
, ".flat");
217 bi_cond_name(enum bi_cond 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";
232 bi_print_texture(struct bi_texture
*tex
, FILE *fp
)
234 fprintf(fp
, " - texture %u, sampler %u",
235 tex
->texture_index
, tex
->sampler_index
);
239 bi_print_instruction(bi_instruction
*ins
, FILE *fp
)
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
));
256 fprintf(fp
, "%s", bi_class_name(ins
->type
));
258 if ((ins
->type
== BI_ADD
|| ins
->type
== BI_FMA
) && ins
->op
.mscale
)
259 fprintf(fp
, ".mscale");
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');
272 if (bi_class_props
[ins
->type
] & BI_CONDITIONAL
)
273 fprintf(fp
, ".%s", bi_cond_name(ins
->cond
));
275 if (ins
->vector_channels
)
276 fprintf(fp
, ".v%u", ins
->vector_channels
);
279 pan_print_alu_type(ins
->dest_type
, fp
);
281 if (bi_has_outmod(ins
))
282 fprintf(fp
, "%s", bi_output_mod_name(ins
->outmod
));
284 if (bi_class_props
[ins
->type
] & BI_ROUNDMODE
)
285 fprintf(fp
, "%s", bi_round_mode_name(ins
->roundmode
));
288 bool succ
= bi_print_dest_index(fp
, ins
, ins
->dest
);
291 if (ins
->dest_offset
)
292 fprintf(fp
, "+%u", ins
->dest_offset
);
296 bi_foreach_src(ins
, s
) {
297 bi_print_src(fp
, ins
, s
);
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
);
304 if (s
< BIR_SRC_COUNT
)
308 if (ins
->type
== BI_BRANCH
) {
309 if (ins
->branch_target
) {
310 fprintf(fp
, "-> block%u", ins
->branch_target
->base
.name
);
312 fprintf(fp
, "-> void");
314 } else if (ins
->type
== BI_TEX
) {
315 bi_print_texture(&ins
->texture
, fp
);
322 bi_print_ports(bi_registers
*regs
, FILE *fp
)
324 for (unsigned i
= 0; i
< 2; ++i
) {
325 if (regs
->enabled
[i
])
326 fprintf(fp
, "port %u: %u\n", i
, regs
->port
[i
]);
329 if (regs
->write_fma
|| regs
->write_add
) {
330 fprintf(fp
, "port 2 (%s): %u\n",
331 regs
->write_add
? "ADD" : "FMA",
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",
343 bi_print_bundle(bi_bundle
*bundle
, FILE *fp
)
345 bi_instruction
*ins
[2] = { bundle
->fma
, bundle
->add
};
347 for (unsigned i
= 0; i
< 2; ++i
) {
349 bi_print_instruction(ins
[i
], fp
);
351 fprintf(fp
, "nop\n");
356 bi_print_clause(bi_clause
*clause
, FILE *fp
)
358 fprintf(fp
, "\tid(%u)", clause
->scoreboard_id
);
360 if (clause
->dependencies
) {
361 fprintf(fp
, ", wait(");
363 for (unsigned i
= 0; i
< 8; ++i
) {
364 if (clause
->dependencies
& (1 << i
))
365 fprintf(fp
, "%u ", i
);
371 if (!clause
->back_to_back
)
372 fprintf(fp
, " nbb %s", clause
->branch_conditional
? "branch-cond" : "branch-uncond");
374 if (clause
->data_register_write_barrier
)
375 fprintf(fp
, " drwb");
379 for (unsigned i
= 0; i
< clause
->bundle_count
; ++i
)
380 bi_print_bundle(&clause
->bundles
[i
], fp
);
382 if (clause
->constant_count
) {
383 for (unsigned i
= 0; i
< clause
->constant_count
; ++i
)
384 fprintf(fp
, "%" PRIx64
" ", clause
->constants
[i
]);
386 if (clause
->branch_constant
)
394 bi_print_block(bi_block
*block
, FILE *fp
)
396 fprintf(fp
, "block%u {\n", block
->base
.name
);
398 if (block
->scheduled
) {
399 bi_foreach_clause_in_block(block
, clause
)
400 bi_print_clause(clause
, fp
);
402 bi_foreach_instr_in_block(block
, ins
)
403 bi_print_instruction(ins
, fp
);
408 if (block
->base
.successors
[0]) {
411 pan_foreach_successor((&block
->base
), succ
)
412 fprintf(fp
, "block%u ", succ
->name
);
415 if (block
->base
.predecessors
->entries
) {
416 fprintf(fp
, " from");
418 bi_foreach_predecessor(block
, pred
)
419 fprintf(fp
, " block%u", pred
->base
.name
);
426 bi_print_shader(bi_context
*ctx
, FILE *fp
)
428 bi_foreach_block(ctx
, block
)
429 bi_print_block((bi_block
*) block
, fp
);