[Mesa-dev] [PATCH 5/5] mesa: compute the GLSL version in the core

Marek Olšák maraeo at gmail.com
Sun Jan 22 15:36:35 PST 2012


I think the CAP-based approach is the way to expose GLSL 1.3 for st/mesa.
The later GLSL versions can be easily derived from exposed extensions,
it's just GLSL 1.3 that is tricky. Comments welcome.
---
 src/mesa/drivers/dri/intel/intel_extensions.c  |    9 +--
 src/mesa/drivers/dri/intel/intel_screen.c      |    2 +-
 src/mesa/drivers/dri/nouveau/nouveau_context.c |    2 +-
 src/mesa/drivers/dri/r200/r200_context.c       |    2 +-
 src/mesa/drivers/dri/radeon/radeon_context.c   |    2 +-
 src/mesa/main/context.c                        |   14 +----
 src/mesa/main/mtypes.h                         |    9 +++
 src/mesa/main/version.c                        |   76 ++++++++++++++++++++++--
 src/mesa/main/version.h                        |    5 +-
 src/mesa/state_tracker/st_extensions.c         |   40 ++++++-------
 src/mesa/state_tracker/st_manager.c            |    2 +-
 11 files changed, 109 insertions(+), 54 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_extensions.c b/src/mesa/drivers/dri/intel/intel_extensions.c
index 0ce452f..f9caeee 100644
--- a/src/mesa/drivers/dri/intel/intel_extensions.c
+++ b/src/mesa/drivers/dri/intel/intel_extensions.c
@@ -90,11 +90,10 @@ intelInitExtensions(struct gl_context *ctx)
    ctx->Extensions.OES_EGL_image = true;
 #endif
 
-   if (intel->gen >= 6)
-      ctx->Const.GLSLVersion = 130;
-   else
-      ctx->Const.GLSLVersion = 120;
-   _mesa_override_glsl_version(ctx);
+   if (intel->gen >= 6) {
+      ctx->Const.NativeIntegerResources = GL_TRUE;
+      ctx->Const.ShadowCubeSamplers = GL_TRUE;
+   }
 
    if (intel->gen == 6 ||
        (intel->gen == 7 && intel->intelScreen->kernel_has_gen7_sol_reset))
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index 094ff56..d51d59c 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -563,7 +563,7 @@ intelCreateContext(gl_api api,
       struct gl_context *ctx =
 	 (struct gl_context *) driContextPriv->driverPrivate;
 
-      _mesa_compute_version(ctx);
+      _mesa_validate_feature_support(ctx);
       if (ctx->VersionMajor > major_version
 	  || (ctx->VersionMajor == major_version
 	      && ctx->VersionMinor >= minor_version)) {
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c
index 0cb918e..039d952 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_context.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c
@@ -82,7 +82,7 @@ nouveau_context_create(gl_api api,
 	nctx->dri_context = dri_ctx;
 	dri_ctx->driverPrivate = ctx;
 
-	_mesa_compute_version(ctx);
+	_mesa_validate_feature_support(ctx);
 	if (ctx->VersionMajor < major_version
 	    || (ctx->VersionMajor == major_version
 		&& ctx->VersionMinor < minor_version)) {
diff --git a/src/mesa/drivers/dri/r200/r200_context.c b/src/mesa/drivers/dri/r200/r200_context.c
index 244973e..4f3b7ff 100644
--- a/src/mesa/drivers/dri/r200/r200_context.c
+++ b/src/mesa/drivers/dri/r200/r200_context.c
@@ -453,7 +453,7 @@ GLboolean r200CreateContext( gl_api api,
       TCL_FALLBACK(rmesa->radeon.glCtx, R200_TCL_FALLBACK_TCL_DISABLE, 1);
    }
 
-   _mesa_compute_version(ctx);
+   _mesa_validate_feature_support(ctx);
    if (ctx->VersionMajor < major_version
        || (ctx->VersionMajor == major_version
 	   && ctx->VersionMinor < minor_version)) {
diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c
index 9881d00..1fbac45 100644
--- a/src/mesa/drivers/dri/radeon/radeon_context.c
+++ b/src/mesa/drivers/dri/radeon/radeon_context.c
@@ -401,7 +401,7 @@ r100CreateContext( gl_api api,
 /*       _tnl_need_dlist_norm_lengths( ctx, GL_FALSE ); */
    }
 
-   _mesa_compute_version(ctx);
+   _mesa_validate_feature_support(ctx);
    if (ctx->VersionMajor < major_version
        || (ctx->VersionMajor == major_version
 	   && ctx->VersionMinor < minor_version)) {
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index f39cab5..7e3bdcf 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -624,18 +624,6 @@ _mesa_init_constants(struct gl_context *ctx)
    ctx->Const.MaxGeometryTotalOutputComponents = MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS;
 #endif
 
-   /* 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;
-   }
-   else if (ctx->API == API_OPENGLES) {
-      ctx->Const.GLSLVersion = 0; /* GLSL not supported */
-   }
-
    /* GL_ARB_framebuffer_object */
    ctx->Const.MaxSamples = 0;
 
@@ -1507,7 +1495,7 @@ _mesa_make_current( struct gl_context *newCtx,
       }
 
       if (newCtx->FirstTimeCurrent) {
-         _mesa_compute_version(newCtx);
+         _mesa_validate_feature_support(newCtx);
 
          newCtx->Extensions.String = _mesa_make_extension_string(newCtx);
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 2ff6085..1d2a265 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2814,6 +2814,15 @@ struct gl_constants
    GLboolean NativeIntegers;
 
    /**
+    * Does the driver support integer vertex attribs, textures,
+    * and colorbuffers?
+    */
+   GLboolean NativeIntegerResources;
+
+   /** Whether shadow cube samplers are supported. */
+   GLboolean ShadowCubeSamplers;
+
+   /**
     * If the driver supports real 32-bit integers, what integer value should be
     * used for boolean true in uniform uploads?  (Usually 1 or ~0.)
     */
diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c
index fc6e17c..b4e9d28 100644
--- a/src/mesa/main/version.c
+++ b/src/mesa/main/version.c
@@ -56,8 +56,8 @@ override_version(struct gl_context *ctx, GLuint *major, GLuint *minor)
  * 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)
+static void
+override_glsl_version(struct gl_context *ctx)
 {
    const char *env_var = "MESA_GLSL_VERSION_OVERRIDE";
    const char *version;
@@ -75,12 +75,45 @@ _mesa_override_glsl_version(struct gl_context *ctx)
    }
 }
 
+static void
+compute_glsl_version_opengl(struct gl_context *ctx)
+{
+   if (ctx->Extensions.ARB_shading_language_100 &&
+       ctx->Extensions.ARB_shader_objects &&
+       ctx->Extensions.ARB_vertex_shader &&
+       ctx->Extensions.ARB_fragment_shader) {
+      ctx->Const.GLSLVersion = 120;
+   }
+
+   if (ctx->Const.GLSLVersion >= 120 &&
+       ctx->Const.MaxClipPlanes >= 8 &&
+       ctx->Const.NativeIntegers &&
+       ctx->Const.NativeIntegerResources &&
+       ctx->Const.ShadowCubeSamplers &&
+       ctx->Extensions.ARB_shader_texture_lod &&
+       ctx->Extensions.EXT_texture_array) {
+      ctx->Const.GLSLVersion = 130;
+   }
+
+   if (ctx->Const.GLSLVersion >= 130 &&
+       ctx->Extensions.ARB_draw_instanced &&
+       ctx->Extensions.ARB_texture_buffer_object &&
+       ctx->Extensions.ARB_uniform_buffer_object &&
+       ctx->Extensions.NV_texture_rectangle) {
+      ctx->Const.GLSLVersion = 140;
+   }
+
+   /* And we could go on...  */
+
+   override_glsl_version(ctx);
+}
+
 /**
  * Examine enabled GL extensions to determine GL version.
  * Return major and minor version numbers.
  */
 static void
-compute_version(struct gl_context *ctx)
+compute_version_opengl(struct gl_context *ctx)
 {
    GLuint major, minor;
    static const int max = 100;
@@ -298,15 +331,15 @@ compute_version_es2(struct gl_context *ctx)
  * This should only be called once as part of context initialization
  * or to perform version check for GLX_ARB_create_context_profile.
  */
-void
-_mesa_compute_version(struct gl_context *ctx)
+static void
+compute_version(struct gl_context *ctx)
 {
    if (ctx->VersionMajor)
       return;
 
    switch (ctx->API) {
    case API_OPENGL:
-      compute_version(ctx);
+      compute_version_opengl(ctx);
       break;
    case API_OPENGLES:
       compute_version_es1(ctx);
@@ -315,5 +348,36 @@ _mesa_compute_version(struct gl_context *ctx)
       compute_version_es2(ctx);
       break;
    }
+}
 
+static void
+compute_glsl_version(struct gl_context *ctx)
+{
+   switch (ctx->API) {
+   case API_OPENGL:
+      compute_glsl_version_opengl(ctx);
+      break;
+   case API_OPENGLES:
+      ctx->Const.GLSLVersion = 0; /* GLSL not supported */
+      break;
+   case API_OPENGLES2:
+      ctx->Const.GLSLVersion = 100;
+      break;
+   }
+}
+
+void
+_mesa_validate_feature_support(struct gl_context *ctx)
+{
+   compute_glsl_version(ctx);
+   compute_version(ctx);
+
+   /* XXX disable the extensions which do not meet requirements of their
+    * specifications. */
+
+   /* Extensions that depend on the versions *only*:
+    */
+   if (ctx->Const.GLSLVersion >= 130) {
+      ctx->Extensions.ARB_conservative_depth = GL_TRUE;
+   }
 }
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index 8723c1f..dbf9cd3 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -43,9 +43,6 @@ struct gl_context;
 
 
 extern void
-_mesa_compute_version(struct gl_context *ctx);
-
-extern void
-_mesa_override_glsl_version(struct gl_context *ctx);
+_mesa_validate_feature_support(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 6c8a491..9e34272 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -260,9 +260,6 @@ void st_init_extensions(struct st_context *st)
    struct gl_context *ctx = st->ctx;
    int i;
 
-   ctx->Const.GLSLVersion = 120;
-   _mesa_override_glsl_version(st->ctx);
-
    /*
     * Extensions that are supported by all Gallium drivers:
     */
@@ -584,16 +581,15 @@ void st_init_extensions(struct st_context *st)
        screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
                                 PIPE_SHADER_CAP_INTEGERS)) {
       ctx->Const.NativeIntegers = GL_TRUE;
-   }
 
-   if (ctx->Const.NativeIntegers)
-      ctx->Const.GLSLVersion = 130;
-
-   /* Extensions that only depend on the GLSL version:
-    */
-   if (ctx->Const.GLSLVersion >= 130) {
-      ctx->Extensions.ARB_conservative_depth = GL_TRUE;
+      /* XXX maybe add caps for these. */
       ctx->Const.MaxClipPlanes = 8;
+      ctx->Const.ShadowCubeSamplers = GL_TRUE;
+
+      /* These extensions require native integers: */
+      if (screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT)) {
+         ctx->Extensions.ARB_shader_stencil_export = GL_TRUE;
+      }
    }
 
    ctx->Extensions.NV_primitive_restart = GL_TRUE;
@@ -634,10 +630,6 @@ void st_init_extensions(struct st_context *st)
       ctx->Extensions.ARB_color_buffer_float = GL_TRUE;
    }
 
-   if (screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT)) {
-      ctx->Extensions.ARB_shader_stencil_export = GL_TRUE;
-   }
-
    if (screen->get_param(screen, PIPE_CAP_TGSI_INSTANCEID)) {
       ctx->Extensions.ARB_draw_instanced = GL_TRUE;
    }
@@ -713,11 +705,17 @@ void st_init_extensions(struct st_context *st)
       }
    }
 
-   if (ctx->Const.NativeIntegers &&
-       screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_UINT, PIPE_TEXTURE_2D, 0,
-                                   PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET) &&
-       screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_SINT, PIPE_TEXTURE_2D, 0,
-                                   PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET))
+   if (screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_UINT,
+                                   PIPE_TEXTURE_2D, 0,
+                                   PIPE_BIND_VERTEX_BUFFER |
+                                   PIPE_BIND_SAMPLER_VIEW |
+                                   PIPE_BIND_RENDER_TARGET) &&
+       screen->is_format_supported(screen, PIPE_FORMAT_R32G32B32A32_SINT,
+                                   PIPE_TEXTURE_2D, 0,
+                                   PIPE_BIND_VERTEX_BUFFER |
+                                   PIPE_BIND_SAMPLER_VIEW |
+                                   PIPE_BIND_RENDER_TARGET)) {
+      ctx->Const.NativeIntegerResources = GL_TRUE;
       ctx->Extensions.EXT_texture_integer = GL_TRUE;
-
+   }
 }
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index 63920a3..82612b1 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -644,7 +644,7 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
 
    /* need to perform version check */
    if (attribs->major > 1 || attribs->minor > 0) {
-      _mesa_compute_version(st->ctx);
+      _mesa_validate_feature_support(st->ctx);
 
       /* Is the actual version less than the requested version?  Mesa can't
        * yet enforce the added restrictions of a forward-looking context, so
-- 
1.7.5.4



More information about the mesa-dev mailing list