[Mesa-dev] [PATCH V2 08/12] glsl: add process_qualifier_constant() helper

Timothy Arceri t_arceri at yahoo.com.au
Sun Nov 8 14:34:37 PST 2015


From: Timothy Arceri <timothy.arceri at collabora.com>

This helper is similar to the function added as part of the
ast_layout_expression class but will be used when only the
ast_expression type is required for the qualifier.

ast_expression is used if qualifier can't have mulitple declorations
or if all but he newest qualifier is simply ignored.
---
 src/glsl/ast_to_hir.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 5643c86..21a956d 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2261,6 +2261,48 @@ validate_matrix_layout_for_type(struct _mesa_glsl_parse_state *state,
    }
 }
 
+bool
+process_qualifier_constant(struct _mesa_glsl_parse_state *state,
+                           YYLTYPE *loc,
+                           const char *qual_indentifier,
+                           ast_expression *const_expression,
+                           unsigned *value, int minimum_value)
+{
+   exec_list dummy_instructions;
+
+   if (const_expression == NULL) {
+      *value = 0;
+      return true;
+   }
+
+   ir_rvalue *const ir = const_expression->hir(&dummy_instructions, state);
+
+   ir_constant *const const_int = ir->constant_expression_value();
+   if (const_int == NULL || !const_int->type->is_integer()) {
+      _mesa_glsl_error(loc, state, "%s must be an integral constant "
+                       "expression", qual_indentifier);
+      return false;
+   }
+
+   assert(minimum_value >= 0);
+   if (const_int->value.i[0] < minimum_value) {
+      _mesa_glsl_error(loc, state, "%s layout qualifier is invalid (%d < %d)",
+                       qual_indentifier, const_int->value.i[0], minimum_value);
+      return false;
+   }
+
+   /* If the location is const (and we've verified that
+    * it is) then no instructions should have been emitted
+    * when we converted it to HIR. If they were emitted,
+    * then either the location isn't const after all, or
+    * we are emitting unnecessary instructions.
+    */
+   assert(dummy_instructions.is_empty());
+
+   *value = const_int->value.u[0];
+   return true;
+}
+
 static bool
 validate_binding_qualifier(struct _mesa_glsl_parse_state *state,
                            YYLTYPE *loc,
-- 
2.4.3



More information about the mesa-dev mailing list