[Mesa-dev] [PATCH 1/2] st/mesa: simplify shader limit initialization code

Brian Paul brianp at vmware.com
Thu Jan 9 11:21:09 PST 2014


Make use of the new gl_constants::Program[] array.
---
 src/mesa/state_tracker/st_extensions.c     |   31 ++++++++--------------------
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   20 +-----------------
 src/mesa/state_tracker/st_program.h        |   18 ++++++++++++++++
 3 files changed, 28 insertions(+), 41 deletions(-)

diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index c17601a..cc63b36 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -38,6 +38,8 @@
 #include "st_context.h"
 #include "st_extensions.h"
 #include "st_format.h"
+#include "st_program.h"
+
 
 static unsigned _min(unsigned a, unsigned b)
 {
@@ -68,8 +70,8 @@ void st_init_limits(struct st_context *st)
 {
    struct pipe_screen *screen = st->pipe->screen;
    struct gl_constants *c = &st->ctx->Const;
-   unsigned sh;
    boolean can_ubo = TRUE;
+   int i;
 
    c->MaxTextureLevels
       = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
@@ -149,27 +151,12 @@ void st_init_limits(struct st_context *st)
       can_ubo = FALSE;
    }
 
-   for (sh = 0; sh < PIPE_SHADER_TYPES; ++sh) {
-      struct gl_shader_compiler_options *options;
-      struct gl_program_constants *pc;
-
-      switch (sh) {
-      case PIPE_SHADER_FRAGMENT:
-         pc = &c->Program[MESA_SHADER_FRAGMENT];
-         options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
-         break;
-      case PIPE_SHADER_VERTEX:
-         pc = &c->Program[MESA_SHADER_VERTEX];
-         options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX];
-         break;
-      case PIPE_SHADER_GEOMETRY:
-         pc = &c->Program[MESA_SHADER_GEOMETRY];
-         options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_GEOMETRY];
-         break;
-      default:
-         /* compute shader, etc. */
-         continue;
-      }
+   /* Note: we only loop over the currently supported gallium shader types */
+   for (i = MESA_SHADER_VERTEX; i <= MESA_SHADER_FRAGMENT; i++) {
+      unsigned sh = st_shader_stage_to_ptarget(i);
+      struct gl_shader_compiler_options *options =
+         &st->ctx->ShaderCompilerOptions[i];
+      struct gl_program_constants *pc = &c->Program[i];
 
       pc->MaxTextureImageUnits =
          _min(screen->get_shader_param(screen, sh,
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 73c39eb..d16f1fb 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5023,24 +5023,6 @@ out:
 }
 /* ----------------------------- End TGSI code ------------------------------ */
 
-
-static unsigned
-shader_stage_to_ptarget(gl_shader_stage stage)
-{
-   switch (stage) {
-   case MESA_SHADER_VERTEX:
-      return PIPE_SHADER_VERTEX;
-   case MESA_SHADER_FRAGMENT:
-      return PIPE_SHADER_FRAGMENT;
-   case MESA_SHADER_GEOMETRY:
-      return PIPE_SHADER_GEOMETRY;
-   }
-
-   assert(!"should not be reached");
-   return PIPE_SHADER_VERTEX;
-}
-
-
 /**
  * Convert a shader's GLSL IR into a Mesa gl_program, although without 
  * generating Mesa IR.
@@ -5057,7 +5039,7 @@ get_mesa_program(struct gl_context *ctx,
    struct gl_shader_compiler_options *options =
          &ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(shader->Type)];
    struct pipe_screen *pscreen = ctx->st->pipe->screen;
-   unsigned ptarget = shader_stage_to_ptarget(shader->Stage);
+   unsigned ptarget = st_shader_stage_to_ptarget(shader->Stage);
 
    validate_ir_tree(shader->ir);
 
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index c764dc9..8b2f170 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -319,4 +319,22 @@ extern void
 st_print_current_vertex_program(void);
 
 
+/** Convert MESA_SHADER_x to PIPE_SHADER_x */
+static INLINE unsigned
+st_shader_stage_to_ptarget(gl_shader_stage stage)
+{
+   switch (stage) {
+   case MESA_SHADER_VERTEX:
+      return PIPE_SHADER_VERTEX;
+   case MESA_SHADER_FRAGMENT:
+      return PIPE_SHADER_FRAGMENT;
+   case MESA_SHADER_GEOMETRY:
+      return PIPE_SHADER_GEOMETRY;
+   }
+
+   assert(!"should not be reached");
+   return PIPE_SHADER_VERTEX;
+}
+
+
 #endif
-- 
1.7.10.4



More information about the mesa-dev mailing list