glsl: move stream layout max validation
authorTimothy Arceri <timothy.arceri@collabora.com>
Sat, 14 Nov 2015 03:32:38 +0000 (14:32 +1100)
committerTimothy Arceri <t_arceri@yahoo.com.au>
Fri, 20 Nov 2015 20:27:21 +0000 (07:27 +1100)
This validation is moved later so we can validate the
max value when compile time constant support is added in a
later patch.

Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/glsl/ast_to_hir.cpp
src/glsl/ast_type.cpp

index 7104aa0a633231845d0960aaa7376b3950ccaa29..bb0db7992e58e1e2afc7e3e61034e5b9d501018f 100644 (file)
@@ -2521,6 +2521,21 @@ process_qualifier_constant(struct _mesa_glsl_parse_state *state,
    return true;
 }
 
+static bool
+validate_stream_qualifier(YYLTYPE *loc, struct _mesa_glsl_parse_state *state,
+                          unsigned stream)
+{
+   if (stream >= state->ctx->Const.MaxVertexStreams) {
+      _mesa_glsl_error(loc, state,
+                       "invalid stream specified %d is larger than "
+                       "MAX_VERTEX_STREAMS - 1 (%d).",
+                       stream, state->ctx->Const.MaxVertexStreams - 1);
+      return false;
+   }
+
+   return true;
+}
+
 static bool
 validate_binding_qualifier(struct _mesa_glsl_parse_state *state,
                            YYLTYPE *loc,
@@ -3036,7 +3051,8 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual,
        qual->flags.q.out && qual->flags.q.stream) {
       unsigned qual_stream;
       if (process_qualifier_constant(state, loc, "stream", qual->stream,
-                                     &qual_stream)) {
+                                     &qual_stream) &&
+          validate_stream_qualifier(loc, state, qual_stream)) {
          var->data.stream = qual_stream;
       }
    }
@@ -6517,7 +6533,8 @@ ast_interface_block::hir(exec_list *instructions,
 
    unsigned qual_stream;
    if (!process_qualifier_constant(state, &loc, "stream", this->layout.stream,
-                                   &qual_stream)) {
+                                   &qual_stream) ||
+       !validate_stream_qualifier(&loc, state, qual_stream)) {
       /* If the stream qualifier is invalid it doesn't make sense to continue
        * on and try to compare stream layouts on member variables against it
        * so just return early.
index 79134c1989379b794346a5accce8bd67d6717eaf..b107051e32c5df45a00ad2e1b78a64ace7f91e60 100644 (file)
@@ -190,20 +190,6 @@ ast_type_qualifier::merge_qualifier(YYLTYPE *loc,
 
    if (state->stage == MESA_SHADER_GEOMETRY &&
        state->has_explicit_attrib_stream()) {
-      if (q.flags.q.stream && q.stream >= state->ctx->Const.MaxVertexStreams) {
-         _mesa_glsl_error(loc, state,
-                          "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
-                          "(%d > %d)",
-                          q.stream, state->ctx->Const.MaxVertexStreams - 1);
-      }
-      if (this->flags.q.explicit_stream &&
-          this->stream >= state->ctx->Const.MaxVertexStreams) {
-         _mesa_glsl_error(loc, state,
-                          "`stream' value is larger than MAX_VERTEX_STREAMS - 1 "
-                          "(%d > %d)",
-                          this->stream, state->ctx->Const.MaxVertexStreams - 1);
-      }
-
       if (!this->flags.q.explicit_stream) {
          if (q.flags.q.stream) {
             this->flags.q.stream = 1;