glsl: add a mechanism to allow #extension directives in the middle of shaders
authorMarek Olšák <marek.olsak@amd.com>
Tue, 8 Jul 2014 18:20:22 +0000 (20:20 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 17 Jul 2014 23:58:58 +0000 (01:58 +0200)
This is needed to make Unigine Heaven 4.0 and Unigine Valley 1.0 work
with sample shading.

Also, if this is disabled, the error message at least makes sense now.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/glsl_parser.yy
src/glsl/glsl_parser_extras.cpp
src/glsl/glsl_parser_extras.h
src/mesa/main/mtypes.h

index b9897498ff7fc8071e51b109dff158f385fcccce..4c871633f0e31396f8069be8f745c66c3e570192 100644 (file)
@@ -376,6 +376,14 @@ external_declaration_list:
       if ($2 != NULL)
          state->translation_unit.push_tail(& $2->link);
    }
+   | external_declaration_list extension_statement {
+      if (!state->allow_extension_directive_midshader) {
+         _mesa_glsl_error(& @2, state,
+                          "#extension directive is not allowed "
+                          "in the middle of a shader");
+         YYERROR;
+      }
+   }
    ;
 
 variable_identifier:
index b327c2b4319b3ab5bb77266837726f0ba489dc51..890123ad1cf435cc300bf4341183806bb107735e 100644 (file)
@@ -210,6 +210,8 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
    this->early_fragment_tests = false;
    memset(this->atomic_counter_offsets, 0,
           sizeof(this->atomic_counter_offsets));
+   this->allow_extension_directive_midshader =
+      ctx->Const.AllowGLSLExtensionDirectiveMidShader;
 }
 
 /**
index 6df41d442de0a5a945a747311650f9c94a99a19b..ce66e2fa45b087e362964282dee9a766f1843c79 100644 (file)
@@ -493,6 +493,8 @@ struct _mesa_glsl_parse_state {
 
    /** Atomic counter offsets by binding */
    unsigned atomic_counter_offsets[MAX_COMBINED_ATOMIC_BUFFERS];
+
+   bool allow_extension_directive_midshader;
 };
 
 # define YYLLOC_DEFAULT(Current, Rhs, N)                       \
index b699021adbd56f06d02c6446f827160e2909afb1..91d9172f9c146b092a56d33b5c9bc43200214465 100644 (file)
@@ -3362,6 +3362,11 @@ struct gl_constants
     */
    GLuint ForceGLSLVersion;
 
+   /**
+    * Allow GLSL #extension directives in the middle of shaders.
+    */
+   GLboolean AllowGLSLExtensionDirectiveMidShader;
+
    /**
     * Does the driver support real 32-bit integers?  (Otherwise, integers are
     * simulated via floats.)