[Mesa-dev] [PATCH 1/2] glsl: Refactor #version validation to be more future-proof.

Kenneth Graunke kenneth at whitecape.org
Thu Jul 26 15:54:24 PDT 2012


The previous implementation required a flag in _mesa_glsl_parse_state
and line of code to initialize it for every version of the shading
language we intend to support.  As we look to add 150, 330, 400, 410,
420, and beyond, this gets rather unwieldy.

This patch retains the switch statement (to reject, say, #version 111),
but removes all the bits.  Code to check for ctx->API == API_OPENGL_CORE
could easily be added to the 110 and 120 cases to reject those.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/glsl_parser.yy         | 22 ++++++++++++++--------
 src/glsl/glsl_parser_extras.cpp | 14 --------------
 src/glsl/glsl_parser_extras.h   | 17 -----------------
 3 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 3373375..71ccb9d 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -259,19 +259,25 @@ version_statement:
 	   switch ($2) {
 	   case 100:
 	      state->es_shader = true;
-	      supported = state->Const.GLSL_100ES;
+	      supported = state->ctx->API == API_OPENGLES2 ||
+		          state->ctx->Extensions.ARB_ES2_compatibility;
 	      break;
 	   case 110:
-	      supported = state->Const.GLSL_110;
-	      break;
 	   case 120:
-	      supported = state->Const.GLSL_120;
-	      break;
+	      /* FINISHME: Once the OpenGL 3.0 'forward compatible' context or
+	       * the OpenGL 3.2 Core context is supported, this logic will need
+	       * change.  Older versions of GLSL are no longer supported
+	       * outside the compatibility contexts of 3.x.
+	       */
 	   case 130:
-	      supported = state->Const.GLSL_130;
-	      break;
 	   case 140:
-	      supported = state->Const.GLSL_140;
+	   case 150:
+	   case 330:
+	   case 400:
+	   case 410:
+	   case 420:
+	      supported = state->ctx->API == API_OPENGL &&
+			  ((unsigned) $2) <= state->ctx->Const.GLSLVersion;
 	      break;
 	   default:
 	      supported = false;
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index d9ee406..50fe676 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -84,20 +84,6 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
 
    this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
 
-   /* Note: Once the OpenGL 3.0 'forward compatible' context or the OpenGL 3.2
-    * Core context is supported, this logic will need change.  Older versions of
-    * GLSL are no longer supported outside the compatibility contexts of 3.x.
-    */
-   this->Const.GLSL_100ES = (ctx->API == API_OPENGLES2)
-      || ctx->Extensions.ARB_ES2_compatibility;
-   this->Const.GLSL_110 = (ctx->API == API_OPENGL);
-   this->Const.GLSL_120 = (ctx->API == API_OPENGL)
-      && (ctx->Const.GLSLVersion >= 120);
-   this->Const.GLSL_130 = (ctx->API == API_OPENGL)
-      && (ctx->Const.GLSLVersion >= 130);
-   this->Const.GLSL_140 = (ctx->API == API_OPENGL)
-      && (ctx->Const.GLSLVersion >= 140);
-
    const unsigned lowest_version =
       (ctx->API == API_OPENGLES2) || ctx->Extensions.ARB_ES2_compatibility
       ? 100 : 110;
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index d97217e..f444a24 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -118,23 +118,6 @@ struct _mesa_glsl_parse_state {
 
       /* ARB_draw_buffers */
       unsigned MaxDrawBuffers;
-
-      /**
-       * Set of GLSL versions supported by the current context
-       *
-       * Knowing that version X is supported doesn't mean that versions before
-       * X are also supported.  Version 1.00 is only supported in an ES2
-       * context or when GL_ARB_ES2_compatibility is supported.  In an OpenGL
-       * 3.0 "forward compatible" context, GLSL 1.10 and 1.20 are \b not
-       * supported.
-       */
-      /*@{*/
-      unsigned GLSL_100ES:1;
-      unsigned GLSL_110:1;
-      unsigned GLSL_120:1;
-      unsigned GLSL_130:1;
-      unsigned GLSL_140:1;
-      /*@}*/
    } Const;
 
    /**
-- 
1.7.11.3



More information about the mesa-dev mailing list