mesa: renumber shader indices according to their placement in pipeline
authorMarek Olšák <maraeo@gmail.com>
Wed, 12 Jun 2013 15:15:46 +0000 (17:15 +0200)
committerMarek Olšák <maraeo@gmail.com>
Tue, 2 Jul 2013 15:02:14 +0000 (17:02 +0200)
See my explanation in mtypes.h.

v2: don't do this in gallium
v3: also updated the comment at the gl_shader_type definition

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/linker.cpp
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/main/mtypes.h
src/mesa/main/shaderobj.h
src/mesa/program/ir_to_mesa.cpp
src/mesa/program/program.h
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index c168e47e0c81ffc061336929ca9ec4f0031f5ddf..61405ea71b87590dbe152398af3ec8c45ca8f356 100644 (file)
@@ -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++) {
index 12986cc403d137bce48e3e907ba6711aa198e39d..584b4c23f7d6abfd249ee0c9f474c28a97b8549c 100644 (file)
@@ -117,17 +117,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();
index 1f62e2c9c9e087cb2d3caf48813c97744f10370d..9ca456173302ed3e11758cf832a7274a642ffe4e 100644 (file)
@@ -2173,13 +2173,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;
 
index 5ce85cfdeba052f89ee15c0ba328bdccd9b215ee..de1c9fcaf1e24c3038c1cb03f2589b69613c9eb2 100644 (file)
@@ -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;
index 35a9b8437dc38704be77da93f92199eb6bbf990a..4af1c8241d82bfa27e169df2f3973b271ecbbd32 100644 (file)
@@ -3073,12 +3073,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;
@@ -3086,7 +3080,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;
          }
       }
index ecda59b58845d5f27334db2366b9900560eb0f81..f28983894600ebbd3c3dc67140d03619657d06dd 100644 (file)
@@ -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;
index 7d18c252190aa841f946bc9beac605c493ea2a3a..80393cff7f8e6277120c6bef0805fb5c8a830f4a 100644 (file)
@@ -221,11 +221,6 @@ struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
    struct gl_context *shareCtx = share ? share->ctx : NULL;
    struct dd_function_table funcs;
 
-   /* Sanity checks */
-   STATIC_ASSERT(MESA_SHADER_VERTEX == PIPE_SHADER_VERTEX);
-   STATIC_ASSERT(MESA_SHADER_FRAGMENT == PIPE_SHADER_FRAGMENT);
-   STATIC_ASSERT(MESA_SHADER_GEOMETRY == PIPE_SHADER_GEOMETRY);
-
    memset(&funcs, 0, sizeof(funcs));
    st_init_driver_functions(&funcs);
 
index 83e8e2e969681a547af826a88c9b4fc5b49d0a74..c0ec06a18a1091871380c3be9f36a88405043998 100644 (file)
@@ -68,7 +68,7 @@ void st_init_limits(struct st_context *st)
 {
    struct pipe_screen *screen = st->pipe->screen;
    struct gl_constants *c = &st->ctx->Const;
-   gl_shader_type sh;
+   unsigned sh;
    boolean can_ubo = TRUE;
 
    c->MaxTextureLevels
@@ -149,23 +149,25 @@ void st_init_limits(struct st_context *st)
       can_ubo = FALSE;
    }
 
-   for (sh = 0; sh < MESA_SHADER_TYPES; ++sh) {
-      struct gl_shader_compiler_options *options =
-         &st->ctx->ShaderCompilerOptions[sh];
+   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->FragmentProgram;
+         options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_FRAGMENT];
          break;
       case PIPE_SHADER_VERTEX:
          pc = &c->VertexProgram;
+         options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX];
          break;
       case PIPE_SHADER_GEOMETRY:
          pc = &c->GeometryProgram;
+         options = &st->ctx->ShaderCompilerOptions[MESA_SHADER_GEOMETRY];
          break;
       default:
-         assert(0);
+         /* compute shader, etc. */
          continue;
       }
 
index 32bc2b37b10ccfdc5d982ccdc1c4e3435151483a..64e0a8a46ebc5c93a1784217c6ae0329f8359090 100644 (file)
@@ -5271,15 +5271,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);