[Mesa-dev] [PATCH 1/6] mesa, gallium: renumber shader indices according to their placement in pipeline

Marek Olšák maraeo at gmail.com
Thu Jun 13 05:25:42 PDT 2013


See my explanation in mtypes.h.
---
 src/gallium/include/pipe/p_defines.h       |    7 ++++---
 src/glsl/linker.cpp                        |   16 ++++++++--------
 src/mesa/drivers/dri/i965/brw_shader.cpp   |    8 ++------
 src/mesa/main/mtypes.h                     |    8 ++++++--
 src/mesa/main/shaderobj.h                  |    4 ++--
 src/mesa/main/uniform_query.cpp            |    2 +-
 src/mesa/program/ir_to_mesa.cpp            |   10 +++-------
 src/mesa/program/program.h                 |    2 +-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |   10 +++-------
 9 files changed, 30 insertions(+), 37 deletions(-)

diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 8af1a84..216cd2f 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -352,11 +352,12 @@ enum pipe_flush_flags {
 
 
 /**
- * Shaders
+ * Shaders.
+ * These must have the same values as Mesa's MESA_SHADER_*.
  */
 #define PIPE_SHADER_VERTEX   0
-#define PIPE_SHADER_FRAGMENT 1
-#define PIPE_SHADER_GEOMETRY 2
+#define PIPE_SHADER_GEOMETRY 1
+#define PIPE_SHADER_FRAGMENT 2
 #define PIPE_SHADER_COMPUTE  3
 #define PIPE_SHADER_TYPES    4
 
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index cd8d680..0f167e6 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -1514,31 +1514,31 @@ static bool
 check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
 {
    static const char *const shader_names[MESA_SHADER_TYPES] = {
-      "vertex", "fragment", "geometry"
+      "vertex", "geometry", "fragment"
    };
 
    const unsigned max_samplers[MESA_SHADER_TYPES] = {
       ctx->Const.VertexProgram.MaxTextureImageUnits,
-      ctx->Const.FragmentProgram.MaxTextureImageUnits,
-      ctx->Const.GeometryProgram.MaxTextureImageUnits
+      ctx->Const.GeometryProgram.MaxTextureImageUnits,
+      ctx->Const.FragmentProgram.MaxTextureImageUnits
    };
 
    const unsigned max_default_uniform_components[MESA_SHADER_TYPES] = {
       ctx->Const.VertexProgram.MaxUniformComponents,
-      ctx->Const.FragmentProgram.MaxUniformComponents,
-      ctx->Const.GeometryProgram.MaxUniformComponents
+      ctx->Const.GeometryProgram.MaxUniformComponents,
+      ctx->Const.FragmentProgram.MaxUniformComponents
    };
 
    const unsigned max_combined_uniform_components[MESA_SHADER_TYPES] = {
       ctx->Const.VertexProgram.MaxCombinedUniformComponents,
-      ctx->Const.FragmentProgram.MaxCombinedUniformComponents,
-      ctx->Const.GeometryProgram.MaxCombinedUniformComponents
+      ctx->Const.GeometryProgram.MaxCombinedUniformComponents,
+      ctx->Const.FragmentProgram.MaxCombinedUniformComponents
    };
 
    const unsigned max_uniform_blocks[MESA_SHADER_TYPES] = {
       ctx->Const.VertexProgram.MaxUniformBlocks,
-      ctx->Const.FragmentProgram.MaxUniformBlocks,
       ctx->Const.GeometryProgram.MaxUniformBlocks,
+      ctx->Const.FragmentProgram.MaxUniformBlocks
    };
 
    for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index 03e4329..5c8f449 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -119,17 +119,13 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
    for (stage = 0; stage < ARRAY_SIZE(shProg->_LinkedShaders); stage++) {
       struct brw_shader *shader =
 	 (struct brw_shader *)shProg->_LinkedShaders[stage];
-      static const GLenum targets[] = {
-	 GL_VERTEX_PROGRAM_ARB,
-	 GL_FRAGMENT_PROGRAM_ARB,
-	 GL_GEOMETRY_PROGRAM_NV
-      };
 
       if (!shader)
 	 continue;
 
       struct gl_program *prog =
-	 ctx->Driver.NewProgram(ctx, targets[stage], shader->base.Name);
+	 ctx->Driver.NewProgram(ctx, _mesa_program_index_to_target(stage),
+                                shader->base.Name);
       if (!prog)
 	return false;
       prog->Parameters = _mesa_new_parameter_list();
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index cd8650c..750e333 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2175,12 +2175,16 @@ struct gl_shader
 /**
  * Shader stages. Note that these will become 5 with tessellation.
  * These MUST have the same values as gallium's PIPE_SHADER_*
+ *
+ * The order must match how shaders are ordered in the pipeline.
+ * The GLSL linker assumes that if i<j, then the j-th shader is
+ * executed later than the i-th shader.
  */
 typedef enum
 {
    MESA_SHADER_VERTEX = 0,
-   MESA_SHADER_FRAGMENT = 1,
-   MESA_SHADER_GEOMETRY = 2,
+   MESA_SHADER_GEOMETRY = 1,
+   MESA_SHADER_FRAGMENT = 2,
    MESA_SHADER_TYPES = 3
 } gl_shader_type;
 
diff --git a/src/mesa/main/shaderobj.h b/src/mesa/main/shaderobj.h
index 5ce85cf..de1c9fc 100644
--- a/src/mesa/main/shaderobj.h
+++ b/src/mesa/main/shaderobj.h
@@ -123,8 +123,8 @@ _mesa_shader_index_to_type(GLuint i)
 {
    static const GLenum enums[MESA_SHADER_TYPES] = {
       GL_VERTEX_SHADER,
-      GL_FRAGMENT_SHADER,
-      GL_GEOMETRY_SHADER ,
+      GL_GEOMETRY_SHADER,
+      GL_FRAGMENT_SHADER
    };
    if (i >= MESA_SHADER_TYPES)
       return 0;
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index 296f80f..be2f0e4 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -435,7 +435,7 @@ static void
 log_program_parameters(const struct gl_shader_program *shProg)
 {
    static const char *stages[] = {
-      "vertex", "fragment", "geometry"
+      "vertex", "geometry", "fragment"
    };
 
    assert(Elements(stages) == MESA_SHADER_TYPES);
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index a5b6699..2093b6b 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -3077,12 +3077,6 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       linked_prog = get_mesa_program(ctx, prog, prog->_LinkedShaders[i]);
 
       if (linked_prog) {
-	 static const GLenum targets[] = {
-	    GL_VERTEX_PROGRAM_ARB,
-	    GL_FRAGMENT_PROGRAM_ARB,
-	    GL_GEOMETRY_PROGRAM_NV
-	 };
-
 	 if (i == MESA_SHADER_VERTEX) {
             ((struct gl_vertex_program *)linked_prog)->UsesClipDistance
                = prog->Vert.UsesClipDistance;
@@ -3090,7 +3084,9 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
 
 	 _mesa_reference_program(ctx, &prog->_LinkedShaders[i]->Program,
 				 linked_prog);
-         if (!ctx->Driver.ProgramStringNotify(ctx, targets[i], linked_prog)) {
+         if (!ctx->Driver.ProgramStringNotify(ctx,
+                                              _mesa_program_index_to_target(i),
+                                              linked_prog)) {
             return GL_FALSE;
          }
       }
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index ecda59b..f289838 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -205,8 +205,8 @@ _mesa_program_index_to_target(GLuint i)
 {
    static const GLenum enums[MESA_SHADER_TYPES] = {
       GL_VERTEX_PROGRAM_ARB,
-      GL_FRAGMENT_PROGRAM_ARB,
       GL_GEOMETRY_PROGRAM_NV,
+      GL_FRAGMENT_PROGRAM_ARB
    };
    if(i >= MESA_SHADER_TYPES)
       return 0;
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index d6796d7..2c74dc2 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5275,15 +5275,11 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       linked_prog = get_mesa_program(ctx, prog, prog->_LinkedShaders[i]);
 
       if (linked_prog) {
-	 static const GLenum targets[] = {
-	    GL_VERTEX_PROGRAM_ARB,
-	    GL_FRAGMENT_PROGRAM_ARB,
-	    GL_GEOMETRY_PROGRAM_NV
-	 };
-
 	 _mesa_reference_program(ctx, &prog->_LinkedShaders[i]->Program,
 				 linked_prog);
-         if (!ctx->Driver.ProgramStringNotify(ctx, targets[i], linked_prog)) {
+         if (!ctx->Driver.ProgramStringNotify(ctx,
+                                              _mesa_program_index_to_target(i),
+                                              linked_prog)) {
 	    _mesa_reference_program(ctx, &prog->_LinkedShaders[i]->Program,
 				    NULL);
             _mesa_reference_program(ctx, &linked_prog, NULL);
-- 
1.7.10.4



More information about the mesa-dev mailing list