glsl: Add support for new fma built-in in ARB_gpu_shader5.
authorMatt Turner <mattst88@gmail.com>
Wed, 24 Apr 2013 00:19:06 +0000 (17:19 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 27 Aug 2013 22:03:30 +0000 (15:03 -0700)
v2: Add constant folding support.
Reviewed-by: Paul Berry <stereotype441@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/ir.cpp
src/glsl/ir.h
src/glsl/ir_constant_expression.cpp
src/glsl/ir_validate.cpp
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 99dceacf85f43ceae700ed17228f4ca6d7629807..c6d96d8da0307a4fceaf99481f70f68b341b2512 100644 (file)
@@ -515,6 +515,7 @@ static const char *const operator_strs[] = {
    "bfm",
    "ubo_load",
    "vector_extract",
+   "fma",
    "lrp",
    "bfi",
    "bitfield_extract",
index 62e3b27ca92bee8066dbf2c701bf86c531770b35..b45e6cbd8315dc8329a51cd11b1ff66ca4905241 100644 (file)
@@ -1169,6 +1169,13 @@ enum ir_expression_operation {
     */
    ir_last_binop = ir_binop_vector_extract,
 
+   /**
+    * \name Fused floating-point multiply-add, part of ARB_gpu_shader5.
+    */
+   /*@{*/
+   ir_triop_fma,
+   /*@}*/
+
    ir_triop_lrp,
 
    /**
index 0a725b45bc47f8cb2051caedfe4e1e09dea5983d..bf019b95577d3ca946136f7e2794d69fc3acd3ae 100644 (file)
@@ -1375,6 +1375,17 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
       break;
    }
 
+   case ir_triop_fma:
+      assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
+      assert(op[1]->type->base_type == GLSL_TYPE_FLOAT);
+      assert(op[2]->type->base_type == GLSL_TYPE_FLOAT);
+
+      for (unsigned c = 0; c < components; c++) {
+         data.f[c] = op[0]->value.f[c] * op[1]->value.f[c]
+                                       + op[2]->value.f[c];
+      }
+      break;
+
    case ir_triop_lrp: {
       assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
       assert(op[1]->type->base_type == GLSL_TYPE_FLOAT);
index ce96f6855a7211195b51e83afab1f3d4f3ed278c..37f26febe550c1a884512888af08622f51fe4293 100644 (file)
@@ -522,6 +522,7 @@ ir_validate::visit_leave(ir_expression *ir)
              && ir->operands[1]->type->is_integer());
       break;
 
+   case ir_triop_fma:
    case ir_triop_lrp:
       assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
       assert(ir->operands[0]->type == ir->operands[1]->type);
index f612f41baff0dd6be897ac6772ce6aadf5cee616..340a4497fdd3f3b86982670a4c7a2a30e55ec490 100644 (file)
@@ -1492,6 +1492,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
 
    case ir_binop_vector_extract:
    case ir_binop_bfm:
+   case ir_triop_fma:
    case ir_triop_bfi:
    case ir_triop_bitfield_extract:
    case ir_triop_vector_insert:
index 4e29e4500e95add444f93790677bd3706bc53cd4..37779d4e5e4031caac4923c0c32d030547061b54 100644 (file)
@@ -1972,6 +1972,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
    case ir_unop_find_msb:
    case ir_unop_find_lsb:
    case ir_binop_bfm:
+   case ir_triop_fma:
    case ir_triop_bfi:
    case ir_triop_bitfield_extract:
    case ir_quadop_bitfield_insert: