Mesa (master): i965: implement OPCODE_NRM3/NRM4

Brian Paul brianp at kemper.freedesktop.org
Thu Jan 1 21:06:59 UTC 2009


Module: Mesa
Branch: master
Commit: 131ac5b465d1f676ca2e592e4fecfcbc14b23b49
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=131ac5b465d1f676ca2e592e4fecfcbc14b23b49

Author: Brian Paul <brianp at vmware.com>
Date:   Wed Dec 31 16:49:58 2008 -0700

i965: implement OPCODE_NRM3/NRM4

---

 src/mesa/drivers/dri/i965/brw_vs_emit.c |   36 ++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c
index ebd8a17..10f3e28 100644
--- a/src/mesa/drivers/dri/i965/brw_vs_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c
@@ -591,6 +591,31 @@ static void emit_lit_noalias( struct brw_vs_compile *c,
 }
 
 
+/** 3 or 4-component vector normalization */
+static void emit_nrm( struct brw_vs_compile *c, 
+                      struct brw_reg dst,
+                      struct brw_reg arg0,
+                      int num_comps)
+{
+   struct brw_compile *p = &c->func;
+   struct brw_reg tmp = get_tmp(c);
+
+   /* tmp = dot(arg0, arg0) */
+   if (num_comps == 3)
+      brw_DP3(p, tmp, arg0, arg0);
+   else
+      brw_DP4(p, tmp, arg0, arg0);
+
+   /* tmp = 1 / tmp */
+   emit_math1(c, BRW_MATH_FUNCTION_RSQ, tmp, tmp, BRW_MATH_PRECISION_FULL);
+
+   /* dst = arg0 * tmp */
+   brw_MUL(p, dst, arg0, tmp);
+
+   release_tmp(c, tmp);
+}
+
+
 /* TODO: relative addressing!
  */
 static struct brw_reg get_reg( struct brw_vs_compile *c,
@@ -1019,6 +1044,12 @@ void brw_vs_emit(struct brw_vs_compile *c )
       case OPCODE_DPH:
 	 brw_DPH(p, dst, args[0], args[1]);
 	 break;
+      case OPCODE_NRM3:
+	 emit_nrm(c, dst, args[0], 3);
+	 break;
+      case OPCODE_NRM4:
+	 emit_nrm(c, dst, args[0], 4);
+	 break;
       case OPCODE_DST:
 	 unalias2(c, dst, args[0], args[1], emit_dst_noalias); 
 	 break;
@@ -1145,11 +1176,10 @@ void brw_vs_emit(struct brw_vs_compile *c )
          /* no-op instructions */
 	 break;
       default:
-	 _mesa_printf("Unsupported opcode %i (%s) in vertex shader\n",
-		      inst->Opcode, inst->Opcode < MAX_OPCODE ?
+	 _mesa_problem(NULL, "Unsupported opcode %i (%s) in vertex shader",
+                       inst->Opcode, inst->Opcode < MAX_OPCODE ?
 				    _mesa_opcode_string(inst->Opcode) :
 				    "unknown");
-	 break;
       }
 
       if ((inst->DstReg.File == PROGRAM_OUTPUT)




More information about the mesa-commit mailing list