[Mesa-dev] [PATCH 2/2] add MESA_GLSL option to require that #extension directives come before any variable or function declarations, etc (reworked)

Kevin Rogovin kevin.rogovin at intel.com
Tue Dec 3 04:47:05 PST 2013


Add an additional bit flag, GLSL_EXTENSION_STRICT for 
gl_context#Shader#Flags to require that #extension 
directives must come before variable or function
declarations. The flag is set to on if MESA_GLSL has
the option extension_strict_ordering in it.

---
 src/glsl/glsl_parser_extras.cpp | 7 ++++---
 src/mesa/main/mtypes.h          | 8 +++++++-
 src/mesa/main/shaderapi.c       | 2 ++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 7ac6798..b74cc83 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -1517,11 +1517,12 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
       new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);
    const char *source = shader->Source;
 
-   if (1) {
+
+   if (ctx->Shader.Flags&GLSL_EXTENSION_STRICT) {
+      state->ext_directive_list = NULL;
+   } else {
       state->ext_directive_list = &extension_directive_list;
       init_glcpp_extension_directive_list(state->ext_directive_list);
-   } else {
-      state->ext_directive_list = NULL;
    }
 
    state->error = glcpp_preprocess(state, &source, &state->info_log,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b4b432f..28cb5f9 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2652,7 +2652,13 @@ struct gl_shader_program
 #define GLSL_USE_PROG 0x80  /**< Log glUseProgram calls */
 #define GLSL_REPORT_ERRORS 0x100  /**< Print compilation errors */
 #define GLSL_DUMP_ON_ERROR 0x200 /**< Dump shaders to stderr on compile error */
-
+/**
+ * In GLSL sources, follow specifications 
+ * with respect to #extension ordering, i.e.
+ * such directives must come before function
+ * declarations, variable declarations, etc.
+ */
+#define GLSL_EXTENSION_STRICT 0x400 
 
 /**
  * Context state for GLSL vertex/fragment shaders.
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 1d9aac3..c9a86e9 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -92,6 +92,8 @@ get_shader_flags(void)
          flags |= GLSL_USE_PROG;
       if (strstr(env, "errors"))
          flags |= GLSL_REPORT_ERRORS;
+      if (strstr(env, "extension_strict_ordering"))
+         flags |= GLSL_EXTENSION_STRICT;
    }
 
    return flags;
-- 
1.8.1.2



More information about the mesa-dev mailing list