#include <stdio.h>
#include <err.h>
+#include "main/mtypes.h"
#include "compiler/glsl/glsl_to_nir.h"
#include "compiler/nir_types.h"
#include "main/imports.h"
#include "compiler/nir/nir_builder.h"
#include "util/half_float.h"
#include "util/register_allocate.h"
+#include "util/u_debug.h"
#include "util/u_dynarray.h"
#include "util/list.h"
#include "main/mtypes.h"
#include "disassemble.h"
+static const struct debug_named_value debug_options[] = {
+ {"msgs", MIDGARD_DBG_MSGS, "Print debug messages"},
+ {"shaders", MIDGARD_DBG_SHADERS, "Dump shaders in NIR and MIR"},
+ DEBUG_NAMED_VALUE_END
+};
+
+DEBUG_GET_ONCE_FLAGS_OPTION(midgard_debug, "MIDGARD_MESA_DEBUG", debug_options, 0)
+
+int midgard_debug = 0;
+
+#define DBG(fmt, ...) \
+ do { if (midgard_debug & MIDGARD_DBG_MSGS) \
+ fprintf(stderr, "%s:%d: "fmt, \
+ __FUNCTION__, __LINE__, ##__VA_ARGS__); } while (0)
+
/* Instruction arguments represented as block-local SSA indices, rather than
* registers. Negative values mean unused. */
}
default:
- printf("Unhandled ALU op %s\n", nir_op_infos[instr->op].name);
+ DBG("Unhandled ALU op %s\n", nir_op_infos[instr->op].name);
assert(0);
return;
}
/* XXX */
if (!entry) {
- printf("WARNING: Unknown uniform %d\n", offset);
+ DBG("WARNING: Unknown uniform %d\n", offset);
break;
}
emit_mir_instruction(ctx, fmul);
} else {
- printf("Unknown input in blend shader\n");
+ DBG("Unknown input in blend shader\n");
assert(0);
}
} else if (ctx->stage == MESA_SHADER_VERTEX) {
ins.load_store.mask = (1 << instr->num_components) - 1;
emit_mir_instruction(ctx, ins);
} else {
- printf("Unknown load\n");
+ DBG("Unknown load\n");
assert(0);
}
void *entry = _mesa_hash_table_u64_search(ctx->varying_nir_to_mdg, offset + 1);
if (!entry) {
- printf("WARNING: skipping varying\n");
+ DBG("WARNING: skipping varying\n");
break;
}
_mesa_hash_table_u64_insert(ctx->ssa_varyings, reg + 1, (void *) ((uintptr_t) (offset + 1)));
}
} else {
- printf("Unknown store\n");
+ DBG("Unknown store\n");
assert(0);
}
return TEXTURE_CUBE;
default:
- printf("Unknown sampler dim type\n");
+ DBG("Unknown sampler dim type\n");
assert(0);
return 0;
}
}
default: {
- printf("Unknown source type\n");
+ DBG("Unknown source type\n");
//assert(0);
break;
}
br.branch.target_break = ctx->current_loop;
emit_mir_instruction(ctx, br);
- printf("break..\n");
+ DBG("break..\n");
break;
}
default:
- printf("Unknown jump type %d\n", instr->type);
+ DBG("Unknown jump type %d\n", instr->type);
break;
}
}
break;
default:
- printf("Unhandled instruction type\n");
+ DBG("Unhandled instruction type\n");
break;
}
}
return REGISTER_UNUSED;
default:
- printf("Unknown SSA register alias %d\n", reg);
+ DBG("Unknown SSA register alias %d\n", reg);
assert(0);
return 31;
}
ins->ssa_args.src1 = find_or_allocate_temp(ctx, ins->ssa_args.src1);
ins->ssa_args.dest = find_or_allocate_temp(ctx, ins->ssa_args.dest);
}
-
- print_mir_block(block);
+ if (midgard_debug & MIDGARD_DBG_SHADERS)
+ print_mir_block(block);
}
/* Let's actually do register allocation */
ra_set_select_reg_callback(g, midgard_ra_select_callback, NULL);
if (!ra_allocate(g)) {
- printf("Error allocating registers\n");
+ DBG("Error allocating registers\n");
assert(0);
}
/* ERRATA (?): In a bundle ending in a fragment writeout, the register dependencies of r0 cannot be written within this bundle (discovered in -bshading:shading=phong) */
if (register_dep_mask & written_mask) {
- printf("ERRATA WORKAROUND: Breakup for writeout dependency masks %X vs %X (common %X)\n", register_dep_mask, written_mask, register_dep_mask & written_mask);
+ DBG("ERRATA WORKAROUND: Breakup for writeout dependency masks %X vs %X (common %X)\n", register_dep_mask, written_mask, register_dep_mask & written_mask);
break;
}
}
default:
- printf("Unknown midgard instruction type\n");
+ DBG("Unknown midgard instruction type\n");
assert(0);
break;
}
case midgard_alu_op_fcsel:
case midgard_alu_op_icsel:
case midgard_alu_op_isub:
- printf("Missed non-commutative flip (%s)\n", alu_opcode_names[op]);
+ DBG("Missed non-commutative flip (%s)\n", alu_opcode_names[op]);
break;
/* These ops are commutative and Just Flip */
/* We don't know how to handle these with a constant */
if (src->abs || src->negate || src->half || src->rep_low || src->rep_high) {
- printf("Bailing inline constant...\n");
+ DBG("Bailing inline constant...\n");
continue;
}
* now that we can allocate a block number for them */
list_for_each_entry_from(struct midgard_block, block, start_block, &ctx->blocks, link) {
- print_mir_block(block);
+ if (midgard_debug & MIDGARD_DBG_SHADERS)
+ print_mir_block(block);
mir_foreach_instr_in_block(block, ins) {
if (ins->type != TAG_ALU_4) continue;
if (!ins->compact_branch) continue;
{
struct util_dynarray *compiled = &program->compiled;
+ midgard_debug = debug_get_option_midgard_debug();
+
compiler_context ictx = {
.nir = nir,
.stage = nir->info.stage,
optimise_nir(nir);
- nir_print_shader(nir, stdout);
+ if (midgard_debug & MIDGARD_DBG_SHADERS) {
+ nir_print_shader(nir, stdout);
+ }
/* Assign counts, now that we're sure (post-optimisation) */
program->uniform_count = nir->num_uniforms;
program->blend_patch_offset = ctx->blend_constant_offset;
- disassemble_midgard(program->compiled.data, program->compiled.size);
+ if (midgard_debug & MIDGARD_DBG_SHADERS)
+ disassemble_midgard(program->compiled.data, program->compiled.size);
return 0;
}