i965/vs: Abort on unsupported opcodes rather than failing.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vec4_emit.cpp
index 9e4efd0933ab40c33598198b51dafea4dd2491a5..a2a5975c6b22320fcb8d124fb72a72d5891541bb 100644 (file)
  */
 
 #include "brw_vec4.h"
-#include "glsl/ir_print_visitor.h"
 
 extern "C" {
 #include "brw_eu.h"
 #include "main/macros.h"
+#include "program/prog_print.h"
+#include "program/prog_parameter.h"
 };
 
-using namespace brw;
-
 namespace brw {
 
-int
-vec4_visitor::setup_attributes(int payload_reg)
-{
-   int nr_attributes;
-   int attribute_map[VERT_ATTRIB_MAX + 1];
-
-   nr_attributes = 0;
-   for (int i = 0; i < VERT_ATTRIB_MAX; i++) {
-      if (prog_data->inputs_read & BITFIELD64_BIT(i)) {
-        attribute_map[i] = payload_reg + nr_attributes;
-        nr_attributes++;
-      }
-   }
-
-   /* VertexID is stored by the VF as the last vertex element, but we
-    * don't represent it with a flag in inputs_read, so we call it
-    * VERT_ATTRIB_MAX.
-    */
-   if (prog_data->uses_vertexid) {
-      attribute_map[VERT_ATTRIB_MAX] = payload_reg + nr_attributes;
-      nr_attributes++;
-   }
-
-   foreach_list(node, &this->instructions) {
-      vec4_instruction *inst = (vec4_instruction *)node;
-
-      /* We have to support ATTR as a destination for GL_FIXED fixup. */
-      if (inst->dst.file == ATTR) {
-        int grf = attribute_map[inst->dst.reg + inst->dst.reg_offset];
-
-        struct brw_reg reg = brw_vec8_grf(grf, 0);
-        reg.dw1.bits.writemask = inst->dst.writemask;
-
-        inst->dst.file = HW_REG;
-        inst->dst.fixed_hw_reg = reg;
-      }
-
-      for (int i = 0; i < 3; i++) {
-        if (inst->src[i].file != ATTR)
-           continue;
-
-        int grf = attribute_map[inst->src[i].reg + inst->src[i].reg_offset];
-
-        struct brw_reg reg = brw_vec8_grf(grf, 0);
-        reg.dw1.bits.swizzle = inst->src[i].swizzle;
-         reg.type = inst->src[i].type;
-        if (inst->src[i].abs)
-           reg = brw_abs(reg);
-        if (inst->src[i].negate)
-           reg = negate(reg);
-
-        inst->src[i].file = HW_REG;
-        inst->src[i].fixed_hw_reg = reg;
-      }
-   }
-
-   /* The BSpec says we always have to read at least one thing from
-    * the VF, and it appears that the hardware wedges otherwise.
-    */
-   if (nr_attributes == 0)
-      nr_attributes = 1;
-
-   prog_data->urb_read_length = (nr_attributes + 1) / 2;
-
-   unsigned vue_entries = MAX2(nr_attributes, c->prog_data.vue_map.num_slots);
-
-   if (intel->gen == 6)
-      c->prog_data.urb_entry_size = ALIGN(vue_entries, 8) / 8;
-   else
-      c->prog_data.urb_entry_size = ALIGN(vue_entries, 4) / 4;
-
-   return payload_reg + nr_attributes;
-}
-
-int
-vec4_visitor::setup_uniforms(int reg)
-{
-   /* The pre-gen6 VS requires that some push constants get loaded no
-    * matter what, or the GPU would hang.
-    */
-   if (intel->gen < 6 && this->uniforms == 0) {
-      this->uniform_vector_size[this->uniforms] = 1;
-
-      for (unsigned int i = 0; i < 4; i++) {
-        unsigned int slot = this->uniforms * 4 + i;
-        static float zero = 0.0;
-        c->prog_data.param[slot] = &zero;
-      }
-
-      this->uniforms++;
-      reg++;
-   } else {
-      reg += ALIGN(uniforms, 2) / 2;
-   }
-
-   c->prog_data.nr_params = this->uniforms * 4;
-
-   c->prog_data.curb_read_length = reg - 1;
-   c->prog_data.uses_new_param_layout = true;
-
-   return reg;
-}
-
-void
-vec4_visitor::setup_payload(void)
-{
-   int reg = 0;
-
-   /* The payload always contains important data in g0, which contains
-    * the URB handles that are passed on to the URB write at the end
-    * of the thread.  So, we always start push constants at g1.
-    */
-   reg++;
-
-   reg = setup_uniforms(reg);
-
-   reg = setup_attributes(reg);
-
-   this->first_non_payload_grf = reg;
-}
-
 struct brw_reg
 vec4_instruction::get_dst(void)
 {
@@ -521,7 +399,6 @@ vec4_visitor::generate_oword_dual_block_offsets(struct brw_reg m1,
 
    brw_MOV(p, m1_0, index_0);
 
-   brw_set_predicate_inverse(p, true);
    if (index.file == BRW_IMMEDIATE_VALUE) {
       index_4.dw1.ud += second_vertex_offset;
       brw_MOV(p, m1_4, index_4);
@@ -763,74 +640,29 @@ vec4_visitor::generate_vs_instruction(vec4_instruction *instruction,
       break;
 
    default:
-      if (inst->opcode < (int)ARRAY_SIZE(brw_opcodes)) {
-        fail("unsupported opcode in `%s' in VS\n",
-             brw_opcodes[inst->opcode].name);
+      if (inst->opcode < (int) ARRAY_SIZE(opcode_descs)) {
+         _mesa_problem(ctx, "Unsupported opcode in `%s' in VS\n",
+                       opcode_descs[inst->opcode].name);
       } else {
-        fail("Unsupported opcode %d in VS", inst->opcode);
+         _mesa_problem(ctx, "Unsupported opcode %d in VS", inst->opcode);
       }
+      abort();
    }
 }
 
-bool
-vec4_visitor::run()
-{
-   if (c->key.userclip_active && !c->key.uses_clip_distance)
-      setup_uniform_clipplane_values();
-
-   /* Generate VS IR for main().  (the visitor only descends into
-    * functions called "main").
-    */
-   visit_instructions(shader->ir);
-
-   emit_urb_writes();
-
-   /* Before any optimization, push array accesses out to scratch
-    * space where we need them to be.  This pass may allocate new
-    * virtual GRFs, so we want to do it early.  It also makes sure
-    * that we have reladdr computations available for CSE, since we'll
-    * often do repeated subexpressions for those.
-    */
-   move_grf_array_access_to_scratch();
-   move_uniform_array_access_to_pull_constants();
-   pack_uniform_registers();
-   move_push_constants_to_pull_constants();
-
-   bool progress;
-   do {
-      progress = false;
-      progress = dead_code_eliminate() || progress;
-      progress = opt_copy_propagation() || progress;
-      progress = opt_algebraic() || progress;
-      progress = opt_compute_to_mrf() || progress;
-   } while (progress);
-
-
-   if (failed)
-      return false;
-
-   setup_payload();
-   reg_allocate();
-
-   if (failed)
-      return false;
-
-   brw_set_access_mode(p, BRW_ALIGN_16);
-
-   generate_code();
-
-   return !failed;
-}
-
 void
 vec4_visitor::generate_code()
 {
-   int last_native_inst = 0;
+   int last_native_insn_offset = 0;
    const char *last_annotation_string = NULL;
-   ir_instruction *last_annotation_ir = NULL;
+   const void *last_annotation_ir = NULL;
 
    if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
-      printf("Native code for vertex shader %d:\n", prog->Name);
+      if (shader) {
+         printf("Native code for vertex shader %d:\n", prog->Name);
+      } else {
+         printf("Native code for vertex program %d:\n", c->vp->program.Base.Id);
+      }
    }
 
    foreach_list(node, &this->instructions) {
@@ -842,7 +674,15 @@ vec4_visitor::generate_code()
            last_annotation_ir = inst->ir;
            if (last_annotation_ir) {
               printf("   ");
-              last_annotation_ir->print();
+               if (shader) {
+                  ((ir_instruction *) last_annotation_ir)->print();
+               } else {
+                  const prog_instruction *vpi;
+                  vpi = (const prog_instruction *) inst->ir;
+                  printf("%d: ", (int)(vpi - vp->Base.Instructions));
+                  _mesa_fprint_instruction_opt(stdout, vpi, 0,
+                                               PROG_PRINT_DEBUG, NULL);
+               }
               printf("\n");
            }
         }
@@ -921,6 +761,10 @@ vec4_visitor::generate_code()
         brw_SEL(p, dst, src[0], src[1]);
         break;
 
+      case BRW_OPCODE_DPH:
+        brw_DPH(p, dst, src[0], src[1]);
+        break;
+
       case BRW_OPCODE_DP4:
         brw_DP4(p, dst, src[0], src[1]);
         break;
@@ -978,19 +822,11 @@ vec4_visitor::generate_code()
       }
 
       if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
-        for (unsigned int i = last_native_inst; i < p->nr_insn; i++) {
-           if (0) {
-              printf("0x%08x 0x%08x 0x%08x 0x%08x ",
-                     ((uint32_t *)&p->store[i])[3],
-                     ((uint32_t *)&p->store[i])[2],
-                     ((uint32_t *)&p->store[i])[1],
-                     ((uint32_t *)&p->store[i])[0]);
-           }
-           brw_disasm(stdout, &p->store[i], intel->gen);
-        }
+        brw_dump_compile(p, stdout,
+                         last_native_insn_offset, p->next_insn_offset);
       }
 
-      last_native_inst = p->nr_insn;
+      last_native_insn_offset = p->next_insn_offset;
    }
 
    if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
@@ -1004,71 +840,9 @@ vec4_visitor::generate_code()
     * which is often something we want to debug.  So this is here in
     * case you're doing that.
     */
-   if (0) {
-      if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
-        for (unsigned int i = 0; i < p->nr_insn; i++) {
-           printf("0x%08x 0x%08x 0x%08x 0x%08x ",
-                  ((uint32_t *)&p->store[i])[3],
-                  ((uint32_t *)&p->store[i])[2],
-                  ((uint32_t *)&p->store[i])[1],
-                  ((uint32_t *)&p->store[i])[0]);
-           brw_disasm(stdout, &p->store[i], intel->gen);
-        }
-      }
-   }
-}
-
-extern "C" {
-
-bool
-brw_vs_emit(struct gl_shader_program *prog, struct brw_vs_compile *c)
-{
-   struct intel_context *intel = &c->func.brw->intel;
-   bool start_busy = false;
-   float start_time = 0;
-
-   if (!prog)
-      return false;
-
-   if (unlikely(INTEL_DEBUG & DEBUG_PERF)) {
-      start_busy = (intel->batch.last_bo &&
-                    drm_intel_bo_busy(intel->batch.last_bo));
-      start_time = get_time();
-   }
-
-   struct brw_shader *shader =
-     (brw_shader *) prog->_LinkedShaders[MESA_SHADER_VERTEX];
-   if (!shader)
-      return false;
-
-   if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
-      printf("GLSL IR for native vertex shader %d:\n", prog->Name);
-      _mesa_print_ir(shader->ir, NULL);
-      printf("\n\n");
-   }
-
-   if (unlikely(INTEL_DEBUG & DEBUG_PERF)) {
-      if (shader->compiled_once) {
-         perf_debug("Recompiling vertex shader for program %d\n", prog->Name);
-      }
-      if (start_busy && !drm_intel_bo_busy(intel->batch.last_bo)) {
-         perf_debug("VS compile took %.03f ms and stalled the GPU\n",
-                    (get_time() - start_time) * 1000);
-      }
-   }
-
-   vec4_visitor v(c, prog, shader);
-   if (!v.run()) {
-      prog->LinkStatus = false;
-      ralloc_strcat(&prog->InfoLog, v.fail_msg);
-      return false;
+   if (0 && unlikely(INTEL_DEBUG & DEBUG_VS)) {
+      brw_dump_compile(p, stdout, 0, p->next_insn_offset);
    }
-
-   shader->compiled_once = true;
-
-   return true;
 }
 
-} /* extern "C" */
-
 } /* namespace brw */