Mesa (master): glsl: Generate ir_binop_vector_extract for indexing of vectors

Ian Romanick idr at kemper.freedesktop.org
Mon May 13 19:06:53 UTC 2013


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Mar 15 18:08:22 2013 -0700

glsl: Generate ir_binop_vector_extract for indexing of vectors

Now ir_dereference_array of a vector will never occur in the RHS of an
expression.

v2: Add back the { } around the if-statement body to make it more
readable.  Suggested by Eric.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/ast_array_index.cpp |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/glsl/ast_array_index.cpp b/src/glsl/ast_array_index.cpp
index 862f64c..4baeb6f 100644
--- a/src/glsl/ast_array_index.cpp
+++ b/src/glsl/ast_array_index.cpp
@@ -31,8 +31,6 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
 			     ir_rvalue *array, ir_rvalue *idx,
 			     YYLTYPE &loc, YYLTYPE &idx_loc)
 {
-   ir_rvalue *result = new(mem_ctx) ir_dereference_array(array, idx);
-
    if (!array->type->is_error()
        && !array->type->is_array()
        && !array->type->is_matrix()
@@ -40,7 +38,6 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
       _mesa_glsl_error(& idx_loc, state,
 		       "cannot dereference non-array / non-matrix / "
 		       "non-vector");
-      result->type = glsl_type::error_type;
    }
 
    if (!idx->type->is_error()) {
@@ -174,5 +171,20 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
       }
    }
 
-   return result;
+   /* After performing all of the error checking, generate the IR for the
+    * expression.
+    */
+   if (array->type->is_array()
+       || array->type->is_matrix()) {
+      return new(mem_ctx) ir_dereference_array(array, idx);
+   } else if (array->type->is_vector()) {
+      return new(mem_ctx) ir_expression(ir_binop_vector_extract, array, idx);
+   } else if (array->type->is_error()) {
+      return array;
+   } else {
+      ir_rvalue *result = new(mem_ctx) ir_dereference_array(array, idx);
+      result->type = glsl_type::error_type;
+
+      return result;
+   }
 }




More information about the mesa-commit mailing list