i965/fs: Make compile failure more verbose with INTEL_DEBUG=wm.
authorEric Anholt <eric@anholt.net>
Sun, 13 Mar 2011 20:43:05 +0000 (13:43 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 24 Mar 2011 18:31:36 +0000 (11:31 -0700)
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp

index cdc9926c81cf322325eabee8ce8d24158cd6d752..ecc4d482b60a8952963ec4a61f63e6be9d75a67d 100644 (file)
@@ -177,6 +177,23 @@ type_size(const struct glsl_type *type)
    }
 }
 
+void
+fs_visitor::fail(const char *format, ...)
+{
+   if (!failed) {
+      failed = true;
+
+      if (INTEL_DEBUG & DEBUG_WM) {
+        fprintf(stderr, "FS compile failed: ");
+
+        va_list va;
+        va_start(va, format);
+        vfprintf(stderr, format, va);
+        va_end(va);
+      }
+   }
+}
+
 /**
  * Returns how many MRFs an FS opcode will write over.
  *
@@ -391,8 +408,7 @@ fs_visitor::setup_builtin_uniform_values(ir_variable *ir)
    }
 
    if (!statevar->name) {
-      this->fail = true;
-      printf("Failed to find builtin uniform `%s'\n", ir->name);
+      fail("Failed to find builtin uniform `%s'\n", ir->name);
       return;
    }
 
@@ -503,7 +519,7 @@ fs_visitor::emit_general_interpolation(ir_variable *ir)
    if (ir->type->is_array()) {
       array_elements = ir->type->length;
       if (array_elements == 0) {
-        this->fail = true;
+        fail("dereferenced array '%s' has length 0\n", ir->name);
       }
       type = ir->type->fields.array;
    } else {
@@ -821,9 +837,8 @@ fs_visitor::visit(ir_expression *ir)
       ir->operands[operand]->accept(this);
       if (this->result.file == BAD_FILE) {
         ir_print_visitor v;
-        printf("Failed to get tree for expression operand:\n");
+        fail("Failed to get tree for expression operand:\n");
         ir->operands[operand]->accept(&v);
-        this->fail = true;
       }
       op[operand] = this->result;
 
@@ -1634,7 +1649,7 @@ fs_visitor::emit_bool_to_cond_code(ir_rvalue *ir)
 
       default:
         assert(!"not reached");
-        this->fail = true;
+        fail("bad cond code\n");
         break;
       }
       return;
@@ -1724,7 +1739,7 @@ fs_visitor::emit_if_gen6(ir_if *ir)
         assert(!"not reached");
         inst = emit(BRW_OPCODE_IF, reg_null_d, op[0], fs_reg(0));
         inst->conditional_mod = BRW_CONDITIONAL_NZ;
-        this->fail = true;
+        fail("bad condition\n");
         return;
       }
       return;
@@ -3631,7 +3646,7 @@ fs_visitor::generate_code()
         } else {
            _mesa_problem(ctx, "Unsupported opcode %d in FS", inst->opcode);
         }
-        this->fail = true;
+        fail("unsupported opcode in FS\n");
       }
 
       if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
@@ -3762,18 +3777,18 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c)
         v.assign_regs_trivial();
       else {
         while (!v.assign_regs()) {
-           if (v.fail)
+           if (v.failed)
               break;
         }
       }
    }
 
-   if (!v.fail)
+   if (!v.failed)
       v.generate_code();
 
-   assert(!v.fail); /* FINISHME: Cleanly fail, tested at link time, etc. */
+   assert(!v.failed); /* FINISHME: Cleanly fail, tested at link time, etc. */
 
-   if (v.fail)
+   if (v.failed)
       return GL_FALSE;
 
    c->prog_data.total_grf = v.grf_used;
index 6551247559f2d6a48c22773e42fcf6bf3bdb197e..e48bf40e3e4392beeb5293a30e6c6989c26d55f1 100644 (file)
@@ -364,7 +364,7 @@ public:
       this->ctx = &intel->ctx;
       this->mem_ctx = ralloc_context(NULL);
       this->shader = shader;
-      this->fail = false;
+      this->failed = false;
       this->variable_ht = hash_table_ctor(0,
                                          hash_table_pointer_hash,
                                          hash_table_pointer_compare);
@@ -476,6 +476,7 @@ public:
    bool remove_duplicate_mrf_writes();
    bool virtual_grf_interferes(int a, int b);
    void schedule_instructions();
+   void fail(const char *msg, ...);
 
    void generate_code();
    void generate_fb_write(fs_inst *inst);
@@ -549,7 +550,7 @@ public:
    ir_instruction *base_ir;
    /** @} */
 
-   bool fail;
+   bool failed;
 
    /* Result of last visit() method. */
    fs_reg result;
index f0277423170cd41cbe4c3db82725ae8efc64e45d..479a91436a781e493fcde37e75f3c6131124855a 100644 (file)
@@ -119,8 +119,7 @@ fs_visitor::assign_regs()
       }
       if (i == class_count) {
         if (this->virtual_grf_sizes[r] >= base_reg_count) {
-           fprintf(stderr, "Object too large to register allocate.\n");
-           this->fail = true;
+           fail("Object too large to register allocate.\n");
         }
 
         class_sizes[class_count++] = this->virtual_grf_sizes[r];
@@ -226,8 +225,11 @@ fs_visitor::assign_regs()
        * loop back into here to try again.
        */
       int reg = choose_spill_reg(g);
-      if (reg == -1 || intel->gen >= 6) {
-        this->fail = true;
+
+      if (reg == -1) {
+        fail("no register to spill\n");
+      } else if (intel->gen >= 6) {
+        fail("no spilling support on gen6 yet\n");
       } else {
         spill_reg(reg);
       }