[Mesa-dev] [PATCH 1/4] st/mesa: add PIPE_CAP_GLSL_FEATURE_LEVEL, cleanup st_extensions.c

Marek Olšák maraeo at gmail.com
Tue Jan 24 16:39:41 PST 2012


---
 src/gallium/docs/source/screen.rst       |    3 ++
 src/gallium/drivers/softpipe/sp_screen.c |    2 +
 src/gallium/include/pipe/p_defines.h     |    3 +-
 src/mesa/state_tracker/st_extensions.c   |   49 +++++++++++++++++-------------
 4 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst
index 8161c64..2af9f74 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -94,6 +94,9 @@ The integer capabilities:
   the vertex colors are never clamped. This is the default for DX10 hardware.
   If both clamped and unclamped CAPs are supported, the clamping can be
   controlled through pipe_rasterizer_state.
+* ``PIPE_CAP_GLSL_FEATURE_LEVEL``: Whether the driver supports features
+  equivalent to a specific GLSL version. E.g. for GLSL 1.3, report 130.
+
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
index 37bbc43..6cafeaf 100644
--- a/src/gallium/drivers/softpipe/sp_screen.c
+++ b/src/gallium/drivers/softpipe/sp_screen.c
@@ -132,6 +132,8 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: /* draw module */
    case PIPE_CAP_VERTEX_COLOR_CLAMPED: /* draw module */
       return 1;
+   case PIPE_CAP_GLSL_FEATURE_LEVEL:
+      return 130;
    default:
       return 0;
    }
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 2cd11f9..000be3d 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -487,7 +487,8 @@ enum pipe_cap {
    PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS = 58, /* temporary */
    PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS = 59, /* temporary */
    PIPE_CAP_VERTEX_COLOR_UNCLAMPED = 60,
-   PIPE_CAP_VERTEX_COLOR_CLAMPED = 61
+   PIPE_CAP_VERTEX_COLOR_CLAMPED = 61,
+   PIPE_CAP_GLSL_FEATURE_LEVEL = 62,
 };
 
 /**
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index 809d6c1..f0e357a 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -258,10 +258,7 @@ void st_init_extensions(struct st_context *st)
 {
    struct pipe_screen *screen = st->pipe->screen;
    struct gl_context *ctx = st->ctx;
-   int i;
-
-   ctx->Const.GLSLVersion = 120;
-   _mesa_override_glsl_version(st->ctx);
+   int i, glsl_feature_level;
 
    /*
     * Extensions that are supported by all Gallium drivers:
@@ -330,6 +327,33 @@ void st_init_extensions(struct st_context *st)
    ctx->Extensions.OES_draw_texture = GL_TRUE;
 #endif
 
+   /* Figure out GLSL support. */
+   glsl_feature_level = screen->get_param(screen, PIPE_CAP_GLSL_FEATURE_LEVEL);
+
+   if (glsl_feature_level >= 130) {
+      ctx->Const.GLSLVersion = 130;
+   } else {
+      ctx->Const.GLSLVersion = 120;
+   }
+
+   _mesa_override_glsl_version(st->ctx);
+
+   if (ctx->Const.GLSLVersion >= 130) {
+      ctx->Const.NativeIntegers = GL_TRUE;
+      ctx->Const.MaxClipPlanes = 8;
+
+      /* Extensions that only depend on GLSL 1.3. */
+      ctx->Extensions.ARB_conservative_depth = GL_TRUE;
+   } else {
+      /* Optional integer support for GLSL 1.2. */
+      if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
+                                   PIPE_SHADER_CAP_INTEGERS) &&
+          screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
+                                   PIPE_SHADER_CAP_INTEGERS)) {
+         ctx->Const.NativeIntegers = GL_TRUE;
+      }
+   }
+
    /*
     * Extensions that depend on the driver/hardware:
     */
@@ -579,23 +603,6 @@ void st_init_extensions(struct st_context *st)
 #endif
    }
 
-   if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
-                                PIPE_SHADER_CAP_INTEGERS) &&
-       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;
-      ctx->Const.MaxClipPlanes = 8;
-   }
-
    ctx->Extensions.NV_primitive_restart = GL_TRUE;
    if (!screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART)) {
       st->sw_primitive_restart = GL_TRUE;
-- 
1.7.5.4



More information about the mesa-dev mailing list