[Mesa-dev] [PATCH 8/8] glsl: Don't early-out for error-type inputs

Ian Romanick idr at freedesktop.org
Mon Apr 1 11:25:24 PDT 2013


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

Check the type of the array operand and the index operand before doing
other checks.  This simplifies the code a bit now (eliminating the
error_emitted parameter), and enables some later functional changes.

The shader

uniform float x[6];
uniform sampler2D s;
void main() { gl_Position.x = xx[s + 1]; }

still generates (only) the two expected errors:

0:3(33): error: `xx' undeclared
0:3(39): error: Operands to arithmetic operators must be numeric

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/ast.h               |  3 +--
 src/glsl/ast_array_index.cpp | 19 +++++++++----------
 src/glsl/ast_to_hir.cpp      |  4 +---
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/glsl/ast.h b/src/glsl/ast.h
index 41254cc..7300271 100644
--- a/src/glsl/ast.h
+++ b/src/glsl/ast.h
@@ -858,8 +858,7 @@ extern ir_rvalue *
 _mesa_ast_array_index_to_hir(void *mem_ctx,
 			     struct _mesa_glsl_parse_state *state,
 			     ir_rvalue *array, ir_rvalue *idx,
-			     YYLTYPE &loc, YYLTYPE &idx_loc,
-			     bool error_emitted);
+			     YYLTYPE &loc, YYLTYPE &idx_loc);
 
 void
 emit_function(_mesa_glsl_parse_state *state, ir_function *f);
diff --git a/src/glsl/ast_array_index.cpp b/src/glsl/ast_array_index.cpp
index c7ebcbd..862f64c 100644
--- a/src/glsl/ast_array_index.cpp
+++ b/src/glsl/ast_array_index.cpp
@@ -29,15 +29,12 @@ ir_rvalue *
 _mesa_ast_array_index_to_hir(void *mem_ctx,
 			     struct _mesa_glsl_parse_state *state,
 			     ir_rvalue *array, ir_rvalue *idx,
-			     YYLTYPE &loc, YYLTYPE &idx_loc,
-			     bool error_emitted)
+			     YYLTYPE &loc, YYLTYPE &idx_loc)
 {
    ir_rvalue *result = new(mem_ctx) ir_dereference_array(array, idx);
 
-   if (error_emitted)
-      return result;
-
-   if (!array->type->is_array()
+   if (!array->type->is_error()
+       && !array->type->is_array()
        && !array->type->is_matrix()
        && !array->type->is_vector()) {
       _mesa_glsl_error(& idx_loc, state,
@@ -46,10 +43,12 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
       result->type = glsl_type::error_type;
    }
 
-   if (!idx->type->is_integer()) {
-      _mesa_glsl_error(& idx_loc, state, "array index must be integer type");
-   } else if (!idx->type->is_scalar()) {
-      _mesa_glsl_error(& idx_loc, state, "array index must be scalar");
+   if (!idx->type->is_error()) {
+      if (!idx->type->is_integer()) {
+	 _mesa_glsl_error(& idx_loc, state, "array index must be integer type");
+      } else if (!idx->type->is_scalar()) {
+	 _mesa_glsl_error(& idx_loc, state, "array index must be scalar");
+      }
    }
 
    /* If the array index is a constant expression and the array has a
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index e9fa4a8..a0ec71c 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1514,10 +1514,8 @@ ast_expression::hir(exec_list *instructions,
       op[0] = subexpressions[0]->hir(instructions, state);
       op[1] = subexpressions[1]->hir(instructions, state);
 
-      error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
-
       result = _mesa_ast_array_index_to_hir(ctx, state, op[0], op[1],
-					    loc, index_loc, error_emitted);
+					    loc, index_loc);
 
       if (result->type->is_error())
 	 error_emitted = true;
-- 
1.8.1.4



More information about the mesa-dev mailing list