[Mesa-dev] [PATCH 3/9] mesa: Use gl_shader_program::_LinkedShaders instead of FragmentProgram

Ian Romanick idr at freedesktop.org
Tue Oct 4 13:44:06 PDT 2011


From: Ian Romanick <ian.d.romanick at intel.com>

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/drivers/dri/i965/brw_fs.cpp       |    8 +++++---
 src/mesa/drivers/dri/i965/brw_fs.h         |    3 ++-
 src/mesa/drivers/dri/i965/brw_wm.c         |    2 +-
 src/mesa/main/context.c                    |    3 +--
 src/mesa/main/mtypes.h                     |    1 -
 src/mesa/main/shaderapi.c                  |    9 +++++----
 src/mesa/main/shaderobj.c                  |    2 --
 src/mesa/main/state.c                      |    6 ++++--
 src/mesa/main/texstate.c                   |   10 +++++-----
 src/mesa/main/uniforms.c                   |   12 +++++++-----
 src/mesa/program/ir_to_mesa.cpp            |    6 ++----
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |    4 ++--
 src/mesa/state_tracker/st_program.c        |    4 ++--
 13 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 2000180..4086f89 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -1827,12 +1827,14 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
 {
    struct brw_context *brw = brw_context(ctx);
    struct brw_wm_prog_key key;
-   struct gl_fragment_program *fp = prog->FragmentProgram;
-   struct brw_fragment_program *bfp = brw_fragment_program(fp);
 
-   if (!fp)
+   if (!prog->_LinkedShaders[MESA_SHADER_FRAGMENT])
       return true;
 
+   struct gl_fragment_program *fp = (struct gl_fragment_program *)
+      prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
+   struct brw_fragment_program *bfp = brw_fragment_program(fp);
+
    memset(&key, 0, sizeof(key));
 
    if (fp->UsesKill)
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 56181a3..4035186 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -347,7 +347,8 @@ public:
       this->c = c;
       this->p = &c->func;
       this->brw = p->brw;
-      this->fp = prog->FragmentProgram;
+      this->fp = (struct gl_fragment_program *)
+	 prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
       this->prog = prog;
       this->intel = &brw->intel;
       this->ctx = &intel->ctx;
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index f746b31..8b86840 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -224,7 +224,7 @@ bool do_wm_prog(struct brw_context *brw,
 
    brw_init_compile(brw, &c->func, c);
 
-   if (prog && prog->FragmentProgram) {
+   if (prog && prog->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
       if (!brw_wm_fs_emit(brw, c, prog))
 	 return false;
    } else {
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 6ef394f..fc52e8c 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1860,8 +1860,7 @@ _mesa_valid_to_render(struct gl_context *ctx, const char *where)
 	    break;
 
 	 case GL_FRAGMENT_SHADER:
-	    _mesa_append_uniforms_to_file(sh,
-					  &shProg[i]->FragmentProgram->Base);
+	    _mesa_append_uniforms_to_file(sh, sh->Program);
 	    break;
 	 }
       }
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 8f97373..6e50017 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2173,7 +2173,6 @@ struct gl_shader_program
    } Vert;
 
    /* post-link info: */
-   struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */
    struct gl_uniform_list *Uniforms;
    struct gl_program_parameter_list *Varying;
    GLboolean LinkStatus;   /**< GL_LINK_STATUS */
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index c70fda1..1583520 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -811,8 +811,9 @@ print_shader_info(const struct gl_shader_program *shProg)
    if (shProg->_LinkedShaders[MESA_SHADER_VERTEX])
       printf("  vert prog %u\n",
 	     shProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program->Id);
-   if (shProg->FragmentProgram)
-      printf("  frag prog %u\n", shProg->FragmentProgram->Base.Id);
+   if (shProg->_LinkedShaders[MESA_SHADER_FRAGMENT])
+      printf("  frag prog %u\n",
+	     shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program->Id);
    if (shProg->_LinkedShaders[MESA_SHADER_GEOMETRY])
       printf("  geom prog %u\n",
 	     shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->Program->Id);
@@ -967,7 +968,7 @@ validate_shader_program(const struct gl_shader_program *shProg,
 {
    const struct gl_shader *vs = shProg->_LinkedShaders[MESA_SHADER_VERTEX];
    const struct gl_shader *gs = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY];
-   const struct gl_fragment_program *fp = shProg->FragmentProgram;
+   const struct gl_shader *fs = shProg->_LinkedShaders[MESA_SHADER_FRAGMENT];
 
    if (!shProg->LinkStatus) {
       return GL_FALSE;
@@ -999,7 +1000,7 @@ validate_shader_program(const struct gl_shader_program *shProg,
    if (gs && !validate_samplers(gs->Program, errMsg)) {
       return GL_FALSE;
    }
-   if (fp && !validate_samplers(&fp->Base, errMsg)) {
+   if (fs && !validate_samplers(fs->Program, errMsg)) {
       return GL_FALSE;
    }
 
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index bebf736..ccf7efd 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -275,8 +275,6 @@ void
 _mesa_clear_shader_program_data(struct gl_context *ctx,
                                 struct gl_shader_program *shProg)
 {
-   _mesa_reference_fragprog(ctx, &shProg->FragmentProgram, NULL);
-
    if (shProg->Uniforms) {
       _mesa_free_uniform_list(shProg->Uniforms);
       shProg->Uniforms = NULL;
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 80502e5..bbe90a3 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -246,10 +246,12 @@ update_program(struct gl_context *ctx)
     * come up, or matter.
     */
 
-   if (fsProg && fsProg->LinkStatus && fsProg->FragmentProgram) {
+   if (fsProg && fsProg->LinkStatus
+       && fsProg->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
       /* Use GLSL fragment shader */
       _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current,
-                               fsProg->FragmentProgram);
+			       (struct gl_fragment_program *)
+			       fsProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
    }
    else if (ctx->FragmentProgram._Enabled) {
       /* Use user-defined fragment program */
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index ee99e50..9f14d8a 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -489,7 +489,7 @@ static void
 update_texture_state( struct gl_context *ctx )
 {
    GLuint unit;
-   struct gl_fragment_program *fprog = NULL;
+   struct gl_program *fprog = NULL;
    struct gl_program *vprog = NULL;
    GLbitfield enabledFragUnits = 0x0;
 
@@ -505,10 +505,10 @@ update_texture_state( struct gl_context *ctx )
 
    if (ctx->Shader.CurrentFragmentProgram &&
        ctx->Shader.CurrentFragmentProgram->LinkStatus) {
-      fprog = ctx->Shader.CurrentFragmentProgram->FragmentProgram;
+      fprog = ctx->Shader.CurrentFragmentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
    }
    else if (ctx->FragmentProgram._Enabled) {
-      fprog = ctx->FragmentProgram.Current;
+      fprog = &ctx->FragmentProgram.Current->Base;
    }
 
    /* FINISHME: Geometry shader texture accesses should also be considered
@@ -544,7 +544,7 @@ update_texture_state( struct gl_context *ctx )
       }
 
       if (fprog) {
-         enabledFragTargets |= fprog->Base.TexturesUsed[unit];
+         enabledFragTargets |= fprog->TexturesUsed[unit];
       }
       else {
          /* fixed-function fragment program */
@@ -611,7 +611,7 @@ update_texture_state( struct gl_context *ctx )
    if (fprog) {
       const GLuint coordMask = (1 << MAX_TEXTURE_COORD_UNITS) - 1;
       ctx->Texture._EnabledCoordUnits
-         = (fprog->Base.InputsRead >> FRAG_ATTRIB_TEX0) & coordMask;
+         = (fprog->InputsRead >> FRAG_ATTRIB_TEX0) & coordMask;
    }
    else {
       ctx->Texture._EnabledCoordUnits = enabledFragUnits;
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 1e395f7..7bdeec7 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -185,7 +185,7 @@ find_uniform_parameter_pos(struct gl_shader_program *shProg, GLint index,
    else {
       pos = shProg->Uniforms->Uniforms[index].FragPos;
       if (pos >= 0) {
-         prog = &shProg->FragmentProgram->Base;
+         prog = shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
       }
       else {
          pos = shProg->Uniforms->Uniforms[index].GeomPos;
@@ -921,11 +921,12 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
       }
    }
 
-   if (shProg->FragmentProgram) {
+   if (shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
       /* convert uniform location to program parameter index */
       GLint index = uniform->FragPos;
       if (index >= 0) {
-         set_program_uniform(ctx, &shProg->FragmentProgram->Base,
+         set_program_uniform(ctx,
+			     shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program,
                              index, offset, type, count, elems, values);
       }
    }
@@ -1069,11 +1070,12 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
       }
    }
 
-   if (shProg->FragmentProgram) {
+   if (shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
       /* convert uniform location to program parameter index */
       GLint index = uniform->FragPos;
       if (index >= 0) {
-         set_program_uniform_matrix(ctx, &shProg->FragmentProgram->Base,
+         set_program_uniform_matrix(ctx,
+				    shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program,
                                     index, offset,
                                     count, rows, cols, transpose, values);
       }
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index ddc4ab8..b9b7b1a 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -3300,8 +3300,8 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
                                                  linked_prog);
             break;
          case GL_FRAGMENT_SHADER:
-            _mesa_reference_fragprog(ctx, &prog->FragmentProgram,
-                                     (struct gl_fragment_program *)linked_prog);
+            _mesa_reference_program(ctx, &prog->_LinkedShaders[i]->Program,
+				    linked_prog);
             ok = ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
                                                  linked_prog);
             break;
@@ -3427,8 +3427,6 @@ _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       }
    }
 
-   _mesa_reference_fragprog(ctx, &prog->FragmentProgram, NULL);
-
    if (prog->LinkStatus) {
       link_shaders(ctx, prog);
    }
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 56bc7f8..80a5930 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -5193,8 +5193,8 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
             }
             break;
          case GL_FRAGMENT_SHADER:
-            _mesa_reference_fragprog(ctx, &prog->FragmentProgram,
-                                     (struct gl_fragment_program *)linked_prog);
+            _mesa_reference_program(ctx, &prog->_LinkedShaders[i]->Program,
+				    linked_prog);
             ok = ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
                                                  linked_prog);
             if (!ok) {
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index ba99808..4162bb9 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1155,8 +1155,8 @@ destroy_shader_program_variants_cb(GLuint key, void *data, void *userData)
 
          destroy_program_variants(st,
                                   shProg->_LinkedShaders[MESA_SHADER_VERTEX]->Program);
-         destroy_program_variants(st, (struct gl_program *)
-                                  shProg->FragmentProgram);
+         destroy_program_variants(st,
+                                  shProg->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
          destroy_program_variants(st,
                                   shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->Program);
       }
-- 
1.7.6



More information about the mesa-dev mailing list