summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2010-05-03 17:26:14 -0700
committerEric Anholt <[email protected]>2010-06-24 15:05:19 -0700
commitb7abce770fe9bb09a6f435d35c1a4afd134fa855 (patch)
tree73d2e6e46f15c3a18d42da1cdb489912299d1825
parent34195832669f0eb7c4a80997cc524f8d10319307 (diff)
ir_to_mesa: Print out the ir along with the Mesa IR.
Ideally this would be hooked up by ir_print_visitor dumping into a string that we could include as prog_instruction->Comment when in debug mode, and not try keeping ir_instruction trees around after conversion to Mesa. The ir_print_visitor isn't set up to do that for us today.
-rw-r--r--ir_to_mesa.cpp46
-rw-r--r--ir_to_mesa.h6
-rw-r--r--mesa/shader/prog_print.c2
3 files changed, 40 insertions, 14 deletions
diff --git a/ir_to_mesa.cpp b/ir_to_mesa.cpp
index 11665a93e78..fc0649c60ee 100644
--- a/ir_to_mesa.cpp
+++ b/ir_to_mesa.cpp
@@ -68,6 +68,7 @@ ir_to_mesa_emit_op3(struct mbtree *tree, enum prog_opcode op,
inst->src_reg[0] = src0;
inst->src_reg[1] = src1;
inst->src_reg[2] = src2;
+ inst->ir = tree->ir;
tree->v->instructions.push_tail(inst);
@@ -94,15 +95,20 @@ ir_to_mesa_emit_op1(struct mbtree *tree, enum prog_opcode op,
}
struct mbtree *
-ir_to_mesa_visitor::create_tree(int op, struct mbtree *left, struct mbtree *right)
+ir_to_mesa_visitor::create_tree(int op,
+ ir_instruction *ir,
+ struct mbtree *left, struct mbtree *right)
{
struct mbtree *tree = (struct mbtree *)calloc(sizeof(struct mbtree), 1);
+ assert(ir);
+
tree->op = op;
tree->left = left;
tree->right = right;
tree->v = this;
tree->src_reg.swizzle = SWIZZLE_XYZW;
+ tree->ir = ir;
return tree;
}
@@ -249,31 +255,34 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
switch (ir->operation) {
case ir_binop_add:
- this->result = this->create_tree(MB_TERM_add_vec4_vec4, op[0], op[1]);
+ this->result = this->create_tree(MB_TERM_add_vec4_vec4, ir, op[0], op[1]);
break;
case ir_binop_sub:
- this->result = this->create_tree(MB_TERM_sub_vec4_vec4, op[0], op[1]);
+ this->result = this->create_tree(MB_TERM_sub_vec4_vec4, ir, op[0], op[1]);
break;
case ir_binop_mul:
- this->result = this->create_tree(MB_TERM_mul_vec4_vec4, op[0], op[1]);
+ this->result = this->create_tree(MB_TERM_mul_vec4_vec4, ir, op[0], op[1]);
break;
case ir_binop_div:
- this->result = this->create_tree(MB_TERM_div_vec4_vec4, op[0], op[1]);
+ this->result = this->create_tree(MB_TERM_div_vec4_vec4, ir, op[0], op[1]);
break;
case ir_binop_dot:
if (ir->operands[0]->type == vec4_type) {
assert(ir->operands[1]->type == vec4_type);
- this->result = this->create_tree(MB_TERM_dp4_vec4_vec4, op[0], op[1]);
+ this->result = this->create_tree(MB_TERM_dp4_vec4_vec4,
+ ir, op[0], op[1]);
} else if (ir->operands[0]->type == vec3_type) {
assert(ir->operands[1]->type == vec3_type);
- this->result = this->create_tree(MB_TERM_dp3_vec4_vec4, op[0], op[1]);
+ this->result = this->create_tree(MB_TERM_dp3_vec4_vec4,
+ ir, op[0], op[1]);
} else if (ir->operands[0]->type == vec2_type) {
assert(ir->operands[1]->type == vec2_type);
- this->result = this->create_tree(MB_TERM_dp2_vec4_vec4, op[0], op[1]);
+ this->result = this->create_tree(MB_TERM_dp2_vec4_vec4,
+ ir, op[0], op[1]);
}
break;
case ir_unop_sqrt:
- this->result = this->create_tree(MB_TERM_sqrt_vec4, op[0], op[1]);
+ this->result = this->create_tree(MB_TERM_sqrt_vec4, ir, op[0], op[1]);
break;
default:
break;
@@ -299,7 +308,7 @@ ir_to_mesa_visitor::visit(ir_swizzle *ir)
ir->val->accept(this);
assert(this->result);
- tree = this->create_tree(MB_TERM_swizzle_vec4, this->result, NULL);
+ tree = this->create_tree(MB_TERM_swizzle_vec4, ir, this->result, NULL);
for (i = 0; i < 4; i++) {
if (i < ir->type->vector_elements) {
@@ -391,7 +400,9 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir)
assert(strcmp(var->name, "gl_TexCoord") == 0);
asprintf(&name, "fragment.texcoord[%d]", index->value.i[0]);
- tree = this->create_tree(MB_TERM_reference_vec4, NULL, NULL);
+ tree = this->create_tree(MB_TERM_reference_vec4, ir, NULL, NULL);
+ tree->src_reg.file = PROGRAM_INPUT;
+ tree->src_reg.index = FRAG_ATTRIB_TEX0 + index->value.i[0];
tree->reg_name = name;
/* If the type is smaller than a vec4, replicate the last channel out. */
@@ -421,7 +432,7 @@ ir_to_mesa_visitor::visit(ir_assignment *ir)
assert(!ir->condition);
- t = this->create_tree(MB_TERM_assign, l, r);
+ t = this->create_tree(MB_TERM_assign, ir, l, r);
mono_burg_label(t, NULL);
reduce(t, MB_NTERM_stmt);
}
@@ -434,7 +445,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir)
assert(!ir->type->is_matrix());
- tree = this->create_tree(MB_TERM_reference_vec4, NULL, NULL);
+ tree = this->create_tree(MB_TERM_reference_vec4, ir, NULL, NULL);
assert(ir->type->base_type == GLSL_TYPE_FLOAT);
@@ -503,6 +514,7 @@ do_ir_to_mesa(exec_list *instructions)
{
ir_to_mesa_visitor v;
struct prog_instruction *mesa_instructions, *mesa_inst;
+ ir_instruction *last_ir = NULL;
visit_exec_list(instructions, &v);
@@ -518,6 +530,14 @@ do_ir_to_mesa(exec_list *instructions)
mesa_inst = mesa_instructions;
foreach_iter(exec_list_iterator, iter, v.instructions) {
ir_to_mesa_instruction *inst = (ir_to_mesa_instruction *)iter.get();
+
+ if (last_ir != inst->ir) {
+ ir_print_visitor print;
+ inst->ir->accept(&print);
+ printf("\n");
+ last_ir = inst->ir;
+ }
+
mesa_inst->Opcode = inst->op;
mesa_inst->DstReg.File = inst->dst_reg.file;
mesa_inst->DstReg.Index = inst->dst_reg.index;
diff --git a/ir_to_mesa.h b/ir_to_mesa.h
index e4c6940a338..d9482264d46 100644
--- a/ir_to_mesa.h
+++ b/ir_to_mesa.h
@@ -54,6 +54,8 @@ public:
enum prog_opcode op;
ir_to_mesa_dst_reg dst_reg;
ir_to_mesa_src_reg src_reg[3];
+ /** Pointer to the ir source this tree came from for debugging */
+ ir_instruction *ir;
};
struct mbtree {
@@ -63,6 +65,9 @@ struct mbtree {
uint16_t op;
class ir_to_mesa_visitor *v;
+ /** Pointer to the ir source this tree came from for debugging */
+ ir_instruction *ir;
+
/**
* This is the representation of this tree node's results as a
* source register for its consumer.
@@ -102,6 +107,7 @@ public:
void get_temp_for_var(ir_variable *var, struct mbtree *tree);
struct mbtree *create_tree(int op,
+ ir_instruction *ir,
struct mbtree *left,
struct mbtree *right);
diff --git a/mesa/shader/prog_print.c b/mesa/shader/prog_print.c
index 9ac090b2617..3f1cb48e4bf 100644
--- a/mesa/shader/prog_print.c
+++ b/mesa/shader/prog_print.c
@@ -833,7 +833,7 @@ void
_mesa_print_instruction(const struct prog_instruction *inst)
{
/* note: 4th param should be ignored for PROG_PRINT_DEBUG */
- _mesa_fprint_instruction_opt(stderr, inst, 0, PROG_PRINT_DEBUG, NULL);
+ _mesa_fprint_instruction_opt(stdout, inst, 0, PROG_PRINT_DEBUG, NULL);
}
#if 0