[Mesa-dev] [PATCH 1/2] mesa: Allow overriding GLSL version with environment varirable

Chad Versace chad at chad-versace.us
Tue Sep 27 15:28:19 PDT 2011


Override the context's GLSL version if the environment variable
MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".

MESA_GLSL_VERSION_OVERRIDE has the same behavior as INTEL_GLSL_VERSION,
except that it applies to all drivers, not just Intel's. Since the former
supercedes the latter, this patch disables the latter.

CC: Dave Airlie <airlied at gmail.com>
Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 docs/envvars.html                             |    4 ++++
 src/mesa/drivers/dri/intel/intel_extensions.c |    3 ++-
 src/mesa/drivers/dri/r600/r600_context.c      |    1 +
 src/mesa/main/context.c                       |    1 +
 src/mesa/main/version.c                       |   24 ++++++++++++++++++++++++
 src/mesa/main/version.h                       |    2 ++
 src/mesa/state_tracker/st_extensions.c        |    1 +
 7 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/docs/envvars.html b/docs/envvars.html
index 6402ec5..8c5c6ab 100644
--- a/docs/envvars.html
+++ b/docs/envvars.html
@@ -62,6 +62,10 @@ This is a work-around for that.
 glGetString(GL_VERSION). Valid values are point-separated version numbers,
 such as "3.0". Mesa will not really implement all the features of the given
 version if it's higher than what's normally reported.
+<li>MESA_GLSL_VERSION_OVERRIDE - changes the value returned by
+glGetString(GL_SHADING_LANGUAGE_VERSION). Valid values are integers, such as
+"130".  Mesa will not really implement all the features of the given language version
+if it's higher than what's normally reported. (for developers only)
 <li>MESA_GLSL - <a href="shading.html#envvars">shading language compiler options</a>
 </ul>
 
diff --git a/src/mesa/drivers/dri/intel/intel_extensions.c b/src/mesa/drivers/dri/intel/intel_extensions.c
index 6ccd5b3..e9a36eb 100644
--- a/src/mesa/drivers/dri/intel/intel_extensions.c
+++ b/src/mesa/drivers/dri/intel/intel_extensions.c
@@ -112,7 +112,8 @@ intelInitExtensions(struct gl_context *ctx)
    ctx->Extensions.OES_EGL_image = true;
 #endif
 
-   ctx->Const.GLSLVersion = get_glsl_version();
+   ctx->Const.GLSLVersion = 120;
+   _mesa_override_glsl_version(ctx);
 
    if (intel->gen >= 5)
       ctx->Extensions.EXT_timer_query = true;
diff --git a/src/mesa/drivers/dri/r600/r600_context.c b/src/mesa/drivers/dri/r600/r600_context.c
index 247d551..3e296ef 100644
--- a/src/mesa/drivers/dri/r600/r600_context.c
+++ b/src/mesa/drivers/dri/r600/r600_context.c
@@ -173,6 +173,7 @@ static void r600InitConstValues(struct gl_context *ctx, radeonScreenPtr screen)
     }
 
         ctx->Const.GLSLVersion = 120;
+        _mesa_override_glsl_version(ctx);
 
 	ctx->Const.MaxTextureImageUnits = 16;
 	/* 8 per clause on r6xx, 16 on r7xx
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index b20063c..2532c47 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -627,6 +627,7 @@ _mesa_init_constants(struct gl_context *ctx)
    /* Shading language version */
    if (ctx->API == API_OPENGL) {
       ctx->Const.GLSLVersion = 120;
+      _mesa_override_glsl_version(ctx);
    }
    else if (ctx->API == API_OPENGLES2) {
       ctx->Const.GLSLVersion = 100;
diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index a5deeab..b06262e 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -52,6 +52,30 @@ override_version(struct gl_context *ctx, GLuint *major, GLuint *minor)
 }
 
 /**
+ * Override the context's GLSL version if the environment variable
+ * MESA_GLSL_VERSION_OVERRIDE is set. Valid values for
+ * MESA_GLSL_VERSION_OVERRIDE are integers, such as "130".
+ */
+void
+_mesa_override_glsl_version(struct gl_context *ctx)
+{
+   const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
+   const char *version;
+   int n;
+
+   version = getenv(env_var);
+   if (!version) {
+      return;
+   }
+
+   n = sscanf(version, "%d", &ctx->Const.GLSLVersion);
+   if (n != 1) {
+      fprintf(stderr, "error: invalid value for %s: %s\n", env_var, version);
+      return;
+   }
+}
+
+/**
  * Examine enabled GL extensions to determine GL version.
  * Return major and minor version numbers.
  */
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index 0a0512c..32e141f 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -56,5 +56,7 @@ struct gl_context;
 extern void
 _mesa_compute_version(struct gl_context *ctx);
 
+extern void
+_mesa_override_glsl_version(struct gl_context *ctx);
 
 #endif /* VERSION_H */
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index ef284ad..5506db6 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -216,6 +216,7 @@ void st_init_limits(struct st_context *st)
       c->MaxProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MAX_TEXEL_OFFSET);
 
       c->GLSLVersion = 120;
+      _mesa_override_glsl_version(c);
       c->UniformBooleanTrue = ~0;
    }
 }
-- 
1.7.6.2



More information about the mesa-dev mailing list