[Mesa-dev] [PATCH 02/12] glsl: Add ir_triop_vector_insert

Ian Romanick idr at freedesktop.org
Mon Apr 8 15:24:33 PDT 2013


From: Ian Romanick <ian.d.romanick at intel.com>

The new opcode is used to generate a new vector with a single field from
the source vector replaced.  This will eventually replace
ir_dereference_array of vectors in the LHS of assignments.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/ir.cpp                 |  1 +
 src/glsl/ir.h                   | 11 ++++++++++-
 src/glsl/ir_validate.cpp        |  9 +++++++++
 src/mesa/program/ir_to_mesa.cpp |  1 +
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index f4596db..336ff95 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -511,6 +511,7 @@ static const char *const operator_strs[] = {
    "ubo_load",
    "vector_extract",
    "lrp",
+   "vector_insert",
    "vector",
 };
 
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 4da54fc..7106cde 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1130,9 +1130,18 @@ enum ir_expression_operation {
    ir_triop_lrp,
 
    /**
+    * Generate a value with one field of a vector changed
+    *
+    * operand0 is the vector
+    * operand1 is the value to write into the vector result
+    * operand2 is the index in operand0 to be modified
+    */
+   ir_triop_vector_insert,
+
+   /**
     * A sentinel marking the last of the ternary operations.
     */
-   ir_last_triop = ir_triop_lrp,
+   ir_last_triop = ir_triop_vector_insert,
 
    ir_quadop_vector,
 
diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
index 83519cf..f304af4 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -480,6 +480,15 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[2]->type == ir->operands[0]->type || ir->operands[2]->type == glsl_type::float_type);
       break;
 
+   case ir_triop_vector_insert:
+      assert(ir->operands[0]->type->is_vector());
+      assert(ir->operands[1]->type->is_scalar());
+      assert(ir->operands[0]->type->base_type == ir->operands[1]->type->base_type);
+      assert(ir->operands[2]->type->is_scalar()
+	     && ir->operands[2]->type->is_integer());
+      assert(ir->type == ir->operands[0]->type);
+      break;
+
    case ir_quadop_vector:
       /* The vector operator collects some number of scalars and generates a
        * vector from them.
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 7d351c0..eb64347 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -1486,6 +1486,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
       break;
 
    case ir_binop_vector_extract:
+   case ir_triop_vector_insert:
    case ir_quadop_vector:
       /* This operation should have already been handled.
        */
-- 
1.8.1.4



More information about the mesa-dev mailing list